1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define __BTSTACK_FILE__ "hfp_ag_demo.c" 39 40 /* 41 * hfp_ag_demo.c 42 */ 43 44 // ***************************************************************************** 45 /* EXAMPLE_START(hfp_ag_demo): HFP Audio Gateway (AG) Demo 46 * 47 * @text This HFP Audio Gateway example demonstrates how to receive 48 * an output from a remote HFP Hands-Free (HF) unit, and, 49 * if HAVE_BTSTACK_STDIN is defined, how to control the HFP HF. 50 */ 51 // ***************************************************************************** 52 53 54 #include <stdint.h> 55 #include <stdio.h> 56 #include <stdlib.h> 57 #include <string.h> 58 #include <unistd.h> 59 60 #include "btstack.h" 61 #include "sco_demo_util.h" 62 #ifdef HAVE_BTSTACK_STDIN 63 #include "btstack_stdin.h" 64 #endif 65 66 uint8_t hfp_service_buffer[150]; 67 const uint8_t rfcomm_channel_nr = 1; 68 const char hfp_ag_service_name[] = "BTstack HFP AG Test"; 69 70 static bd_addr_t device_addr; 71 static const char * device_addr_string = "00:15:83:5F:9D:46"; 72 73 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 74 static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; 75 #else 76 static uint8_t codecs[] = {HFP_CODEC_CVSD}; 77 #endif 78 79 static uint8_t negotiated_codec = HFP_CODEC_CVSD; 80 81 static hci_con_handle_t acl_handle = -1; 82 static hci_con_handle_t sco_handle; 83 static int memory_1_enabled = 1; 84 static btstack_packet_callback_registration_t hci_event_callback_registration; 85 86 static int ag_indicators_nr = 7; 87 static hfp_ag_indicator_t ag_indicators[] = { 88 // index, name, min range, max range, status, mandatory, enabled, status changed 89 {1, "service", 0, 1, 1, 0, 0, 0}, 90 {2, "call", 0, 1, 0, 1, 1, 0}, 91 {3, "callsetup", 0, 3, 0, 1, 1, 0}, 92 {4, "battchg", 0, 5, 3, 0, 0, 0}, 93 {5, "signal", 0, 5, 5, 0, 1, 0}, 94 {6, "roam", 0, 1, 0, 0, 1, 0}, 95 {7, "callheld", 0, 2, 0, 1, 1, 0} 96 }; 97 98 static int call_hold_services_nr = 5; 99 static const char* call_hold_services[] = {"1", "1x", "2", "2x", "3"}; 100 101 static int hf_indicators_nr = 2; 102 static hfp_generic_status_indicator_t hf_indicators[] = { 103 {1, 1}, 104 {2, 1}, 105 }; 106 107 #define INQUIRY_INTERVAL 5 108 109 enum STATE {INIT, W4_INQUIRY_MODE_COMPLETE, ACTIVE} ; 110 enum STATE state = INIT; 111 112 static void dump_supported_codecs(void){ 113 int i; 114 int mSBC_skipped = 0; 115 printf("Supported codecs: "); 116 for (i = 0; i < sizeof(codecs); i++){ 117 switch(codecs[i]){ 118 case HFP_CODEC_CVSD: 119 printf("CVSD"); 120 break; 121 case HFP_CODEC_MSBC: 122 if (hci_extended_sco_link_supported()){ 123 printf(", mSBC"); 124 } else { 125 mSBC_skipped = 1; 126 } 127 break; 128 } 129 } 130 printf("\n"); 131 if (mSBC_skipped){ 132 printf("mSBC codec disabled because eSCO not supported by local controller.\n"); 133 } 134 } 135 136 #ifdef HAVE_BTSTACK_STDIN 137 // Testig User Interface 138 static void show_usage(void){ 139 bd_addr_t iut_address; 140 gap_local_bd_addr(iut_address); 141 142 printf("\n--- Bluetooth HFP Audiogateway (AG) unit Test Console %s ---\n", bd_addr_to_str(iut_address)); 143 printf("\n"); 144 145 printf("a - establish HFP connection to PTS module %s\n", bd_addr_to_str(device_addr)); 146 // printf("A - release HFP connection to PTS module\n"); 147 148 printf("b - establish AUDIO connection | B - release AUDIO connection\n"); 149 printf("c - simulate incoming call from 1234567 | C - simulate call from 1234567 dropped\n"); 150 printf("d - report AG failure\n"); 151 printf("e - answer call on AG | E - reject call on AG\n"); 152 printf("r - disable in-band ring tone | R - enable in-band ring tone\n"); 153 printf("f - Disable cellular network | F - Enable cellular network\n"); 154 printf("g - Set signal strength to 0 | G - Set signal strength to 5\n"); 155 printf("h - Disable roaming | H - Enable roaming\n"); 156 printf("i - Set battery level to 3 | I - Set battery level to 5\n"); 157 printf("j - Answering call on remote side\n"); 158 printf("k - Clear memory #1 | K - Set memory #1\n"); 159 printf("l - Clear last number | L - Set last number\n"); 160 printf("m - simulate incoming call from 7654321\n"); 161 // printf("M - simulate call from 7654321 dropped\n"); 162 printf("n - Disable Voice Regocnition | N - Enable Voice Recognition\n"); 163 printf("o - Set speaker volume to 0 (minimum) | O - Set speaker volume to 9 (default)\n"); 164 printf("p - Set speaker volume to 12 (higher) | P - Set speaker volume to 15 (maximum)\n"); 165 printf("q - Set microphone gain to 0 (minimum) | Q - Set microphone gain to 9 (default)\n"); 166 printf("s - Set microphone gain to 12 (higher) | S - Set microphone gain to 15 (maximum)\n"); 167 printf("t - terminate connection\n"); 168 printf("u - join held call\n"); 169 printf("v - discover nearby HF units\n"); 170 printf("w - put incoming call on hold (Response and Hold)\n"); 171 printf("x - accept held incoming call (Response and Hold)\n"); 172 printf("X - reject held incoming call (Response and Hold)\n"); 173 174 printf("---\n"); 175 printf("Ctrl-c - exit\n"); 176 printf("---\n"); 177 } 178 179 static void stdin_process(char cmd){ 180 switch (cmd){ 181 case 'a': 182 log_info("USER:\'%c\'", cmd); 183 printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr)); 184 hfp_ag_establish_service_level_connection(device_addr); 185 break; 186 case 'A': 187 log_info("USER:\'%c\'", cmd); 188 printf("Release HFP service level connection.\n"); 189 hfp_ag_release_service_level_connection(acl_handle); 190 break; 191 case 'Z': 192 log_info("USER:\'%c\'", cmd); 193 printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr)); 194 hfp_ag_release_service_level_connection(acl_handle); 195 break; 196 case 'b': 197 log_info("USER:\'%c\'", cmd); 198 printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr)); 199 hfp_ag_establish_audio_connection(acl_handle); 200 break; 201 case 'B': 202 log_info("USER:\'%c\'", cmd); 203 printf("Release Audio connection.\n"); 204 hfp_ag_release_audio_connection(acl_handle); 205 break; 206 case 'c': 207 log_info("USER:\'%c\'", cmd); 208 printf("Simulate incoming call from 1234567\n"); 209 hfp_ag_set_clip(129, "1234567"); 210 hfp_ag_incoming_call(); 211 break; 212 case 'm': 213 log_info("USER:\'%c\'", cmd); 214 printf("Simulate incoming call from 7654321\n"); 215 hfp_ag_set_clip(129, "7654321"); 216 hfp_ag_incoming_call(); 217 break; 218 case 'C': 219 log_info("USER:\'%c\'", cmd); 220 printf("Simulate terminate call\n"); 221 hfp_ag_call_dropped(); 222 break; 223 case 'd': 224 log_info("USER:\'%c\'", cmd); 225 printf("Report AG failure\n"); 226 hfp_ag_report_extended_audio_gateway_error_result_code(acl_handle, HFP_CME_ERROR_AG_FAILURE); 227 break; 228 case 'e': 229 log_info("USER:\'%c\'", cmd); 230 printf("Answer call on AG\n"); 231 hfp_ag_answer_incoming_call(); 232 break; 233 case 'E': 234 log_info("USER:\'%c\'", cmd); 235 printf("Reject call on AG\n"); 236 hfp_ag_terminate_call(); 237 break; 238 case 'f': 239 log_info("USER:\'%c\'", cmd); 240 printf("Disable cellular network\n"); 241 hfp_ag_set_registration_status(0); 242 break; 243 case 'F': 244 log_info("USER:\'%c\'", cmd); 245 printf("Enable cellular network\n"); 246 hfp_ag_set_registration_status(1); 247 break; 248 case 'g': 249 log_info("USER:\'%c\'", cmd); 250 printf("Set signal strength to 0\n"); 251 hfp_ag_set_signal_strength(0); 252 break; 253 case 'G': 254 log_info("USER:\'%c\'", cmd); 255 printf("Set signal strength to 5\n"); 256 hfp_ag_set_signal_strength(5); 257 break; 258 case 'h': 259 log_info("USER:\'%c\'", cmd); 260 printf("Disable roaming\n"); 261 hfp_ag_set_roaming_status(0); 262 break; 263 case 'H': 264 log_info("USER:\'%c\'", cmd); 265 printf("Enable roaming\n"); 266 hfp_ag_set_roaming_status(1); 267 break; 268 case 'i': 269 log_info("USER:\'%c\'", cmd); 270 printf("Set battery level to 3\n"); 271 hfp_ag_set_battery_level(3); 272 break; 273 case 'I': 274 log_info("USER:\'%c\'", cmd); 275 printf("Set battery level to 5\n"); 276 hfp_ag_set_battery_level(5); 277 break; 278 case 'j': 279 log_info("USER:\'%c\'", cmd); 280 printf("Answering call on remote side\n"); 281 hfp_ag_outgoing_call_established(); 282 break; 283 case 'r': 284 log_info("USER:\'%c\'", cmd); 285 printf("Disable in-band ring tone\n"); 286 hfp_ag_set_use_in_band_ring_tone(0); 287 break; 288 case 'k': 289 log_info("USER:\'%c\'", cmd); 290 printf("Memory 1 cleared\n"); 291 memory_1_enabled = 0; 292 break; 293 case 'K': 294 log_info("USER:\'%c\'", cmd); 295 printf("Memory 1 set\n"); 296 memory_1_enabled = 1; 297 break; 298 case 'l': 299 log_info("USER:\'%c\'", cmd); 300 printf("Last dialed number cleared\n"); 301 hfp_ag_clear_last_dialed_number(); 302 break; 303 case 'L': 304 log_info("USER:\'%c\'", cmd); 305 printf("Outgoing call connected, ringing\n"); 306 hfp_ag_outgoing_call_ringing(); 307 break; 308 case 'n': 309 log_info("USER:\'%c\'", cmd); 310 printf("Disable Voice Recognition\n"); 311 hfp_ag_activate_voice_recognition(acl_handle, 0); 312 break; 313 case 'N': 314 log_info("USER:\'%c\'", cmd); 315 printf("Enable Voice Recognition\n"); 316 hfp_ag_activate_voice_recognition(acl_handle, 1); 317 break; 318 case 'o': 319 log_info("USER:\'%c\'", cmd); 320 printf("Set speaker gain to 0 (minimum)\n"); 321 hfp_ag_set_speaker_gain(acl_handle, 0); 322 break; 323 case 'O': 324 log_info("USER:\'%c\'", cmd); 325 printf("Set speaker gain to 9 (default)\n"); 326 hfp_ag_set_speaker_gain(acl_handle, 9); 327 break; 328 case 'p': 329 log_info("USER:\'%c\'", cmd); 330 printf("Set speaker gain to 12 (higher)\n"); 331 hfp_ag_set_speaker_gain(acl_handle, 12); 332 break; 333 case 'P': 334 log_info("USER:\'%c\'", cmd); 335 printf("Set speaker gain to 15 (maximum)\n"); 336 hfp_ag_set_speaker_gain(acl_handle, 15); 337 break; 338 case 'q': 339 log_info("USER:\'%c\'", cmd); 340 printf("Set microphone gain to 0\n"); 341 hfp_ag_set_microphone_gain(acl_handle, 0); 342 break; 343 case 'Q': 344 log_info("USER:\'%c\'", cmd); 345 printf("Set microphone gain to 9\n"); 346 hfp_ag_set_microphone_gain(acl_handle, 9); 347 break; 348 case 's': 349 log_info("USER:\'%c\'", cmd); 350 printf("Set microphone gain to 12\n"); 351 hfp_ag_set_microphone_gain(acl_handle, 12); 352 break; 353 case 'S': 354 log_info("USER:\'%c\'", cmd); 355 printf("Set microphone gain to 15\n"); 356 hfp_ag_set_microphone_gain(acl_handle, 15); 357 break; 358 case 'R': 359 log_info("USER:\'%c\'", cmd); 360 printf("Enable in-band ring tone\n"); 361 hfp_ag_set_use_in_band_ring_tone(1); 362 break; 363 case 't': 364 log_info("USER:\'%c\'", cmd); 365 printf("Terminate HCI connection. 0x%2x\n", acl_handle); 366 gap_disconnect(acl_handle); 367 break; 368 case 'u': 369 log_info("USER:\'%c\'", cmd); 370 printf("Join held call\n"); 371 hfp_ag_join_held_call(); 372 break; 373 case 'v': 374 printf("Start scanning...\n"); 375 gap_inquiry_start(INQUIRY_INTERVAL); 376 break; 377 case 'w': 378 log_info("USER:\'%c\'", cmd); 379 printf("AG: Put incoming call on hold (Response and Hold)\n"); 380 hfp_ag_hold_incoming_call(); 381 break; 382 case 'x': 383 log_info("USER:\'%c\'", cmd); 384 printf("AG: Accept held incoming call (Response and Hold)\n"); 385 hfp_ag_accept_held_incoming_call(); 386 break; 387 case 'X': 388 log_info("USER:\'%c\'", cmd); 389 printf("AG: Reject held incoming call (Response and Hold)\n"); 390 hfp_ag_reject_held_incoming_call(); 391 break; 392 default: 393 show_usage(); 394 break; 395 } 396 } 397 #endif 398 399 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){ 400 UNUSED(channel); 401 bd_addr_t addr; 402 switch (packet_type){ 403 case HCI_EVENT_PACKET: 404 switch (event[0]){ 405 case GAP_EVENT_INQUIRY_RESULT: 406 gap_event_inquiry_result_get_bd_addr(event, addr); 407 // print info 408 printf("Device found: %s ", bd_addr_to_str(addr)); 409 printf("with COD: 0x%06x, ", (unsigned int) gap_event_inquiry_result_get_class_of_device(event)); 410 if (gap_event_inquiry_result_get_rssi_availabe(event)){ 411 printf(", rssi %d dBm", (int8_t) gap_event_inquiry_result_get_rssi(event)); 412 } 413 if (gap_event_inquiry_result_get_name_available(event)){ 414 char name_buffer[240]; 415 int name_len = gap_event_inquiry_result_get_name_len(event); 416 memcpy(name_buffer, gap_event_inquiry_result_get_name(event), name_len); 417 name_buffer[name_len] = 0; 418 printf(", name '%s'", name_buffer); 419 } 420 printf("\n"); 421 break; 422 case GAP_EVENT_INQUIRY_COMPLETE: 423 printf("Inquiry scan complete.\n"); 424 break; 425 case HCI_EVENT_SCO_CAN_SEND_NOW: 426 sco_demo_send(sco_handle); 427 break; 428 case HCI_EVENT_COMMAND_COMPLETE: 429 if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){ 430 dump_supported_codecs(); 431 } 432 break; 433 default: 434 break; 435 } 436 437 if (event[0] != HCI_EVENT_HFP_META) return; 438 439 if (event[3] 440 && event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER 441 && event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG 442 && event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){ 443 printf("ERROR, status: %u\n", event[3]); 444 return; 445 } 446 447 switch (event[2]) { 448 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: 449 acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event); 450 hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr); 451 printf("Service level connection established from %s.\n", bd_addr_to_str(device_addr)); 452 dump_supported_codecs(); 453 break; 454 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: 455 printf("Service level connection released.\n"); 456 sco_handle = 0; 457 break; 458 case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED: 459 if (hfp_subevent_audio_connection_established_get_status(event)){ 460 printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event)); 461 sco_handle = 0; 462 } else { 463 sco_handle = hfp_subevent_audio_connection_established_get_handle(event); 464 printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 465 negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event); 466 switch (negotiated_codec){ 467 case 0x01: 468 printf("Using CVSD codec.\n"); 469 break; 470 case 0x02: 471 printf("Using mSBC codec.\n"); 472 break; 473 default: 474 printf("Using unknown codec 0x%02x.\n", negotiated_codec); 475 break; 476 } 477 sco_demo_set_codec(negotiated_codec); 478 hci_request_sco_can_send_now_event(); 479 } 480 break; 481 case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: 482 printf("Audio connection released\n"); 483 sco_handle = 0; 484 sco_demo_close(); 485 break; 486 case HFP_SUBEVENT_START_RINGINIG: 487 printf("Start Ringing\n"); 488 break; 489 case HFP_SUBEVENT_STOP_RINGINIG: 490 printf("Stop Ringing\n"); 491 break; 492 case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER: 493 printf("Outgoing call '%s'\n", hfp_subevent_place_call_with_number_get_number(event)); 494 // validate number 495 if ( strcmp("1234567", hfp_subevent_place_call_with_number_get_number(event)) == 0 496 || strcmp("7654321", hfp_subevent_place_call_with_number_get_number(event)) == 0 497 || (memory_1_enabled && strcmp(">1", hfp_subevent_place_call_with_number_get_number(event)) == 0)){ 498 printf("Dialstring valid: accept call\n"); 499 hfp_ag_outgoing_call_accepted(); 500 } else { 501 printf("Dialstring invalid: reject call\n"); 502 hfp_ag_outgoing_call_rejected(); 503 } 504 break; 505 506 case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG: 507 printf("Attach number to voice tag. Sending '1234567\n"); 508 hfp_ag_send_phone_number_for_voice_tag(acl_handle, "1234567"); 509 break; 510 case HFP_SUBEVENT_TRANSMIT_DTMF_CODES: 511 printf("Send DTMF Codes: '%s'\n", hfp_subevent_transmit_dtmf_codes_get_dtmf(event)); 512 hfp_ag_send_dtmf_code_done(acl_handle); 513 break; 514 case HFP_SUBEVENT_CALL_ANSWERED: 515 printf("Call answered by HF\n"); 516 break; 517 default: 518 printf("Event not handled %u\n", event[2]); 519 break; 520 } 521 break; 522 case HCI_SCO_DATA_PACKET: 523 sco_demo_receive(event, event_size); 524 break; 525 default: 526 break; 527 } 528 } 529 530 static hfp_phone_number_t subscriber_number = { 531 129, "225577" 532 }; 533 534 /* @section Main Application Setup 535 * 536 * @text Listing MainConfiguration shows main application code. 537 * To run a HFP AG service you need to initialize the SDP, and to create and register HFP AG record with it. 538 * The packet_handler is used for sending commands to the HFP HF. It also receives the HFP HF's answers. 539 * The stdin_process callback allows for sending commands to the HFP HF. 540 * At the end the Bluetooth stack is started. 541 */ 542 543 /* LISTING_START(MainConfiguration): Setup HFP Audio Gateway */ 544 545 int btstack_main(int argc, const char * argv[]); 546 int btstack_main(int argc, const char * argv[]){ 547 (void)argc; 548 (void)argv; 549 550 sco_demo_init(); 551 552 // register for HCI events 553 hci_event_callback_registration.callback = &packet_handler; 554 hci_add_event_handler(&hci_event_callback_registration); 555 hci_register_sco_packet_handler(&packet_handler); 556 557 gap_discoverable_control(1); 558 559 // L2CAP 560 l2cap_init(); 561 562 uint16_t supported_features = 563 (1<<HFP_AGSF_ESCO_S4) | 564 (1<<HFP_AGSF_HF_INDICATORS) | 565 (1<<HFP_AGSF_CODEC_NEGOTIATION) | 566 (1<<HFP_AGSF_EXTENDED_ERROR_RESULT_CODES) | 567 (1<<HFP_AGSF_ENHANCED_CALL_CONTROL) | 568 (1<<HFP_AGSF_ENHANCED_CALL_STATUS) | 569 (1<<HFP_AGSF_ABILITY_TO_REJECT_A_CALL) | 570 (1<<HFP_AGSF_IN_BAND_RING_TONE) | 571 (1<<HFP_AGSF_VOICE_RECOGNITION_FUNCTION) | 572 (1<<HFP_AGSF_THREE_WAY_CALLING); 573 int wide_band_speech = 1; 574 575 // HFP 576 rfcomm_init(); 577 hfp_ag_init(rfcomm_channel_nr); 578 hfp_ag_init_supported_features(supported_features); 579 hfp_ag_init_codecs(sizeof(codecs), codecs); 580 hfp_ag_init_ag_indicators(ag_indicators_nr, ag_indicators); 581 hfp_ag_init_hf_indicators(hf_indicators_nr, hf_indicators); 582 hfp_ag_init_call_hold_services(call_hold_services_nr, call_hold_services); 583 hfp_ag_set_subcriber_number_information(&subscriber_number, 1); 584 hfp_ag_register_packet_handler(&packet_handler); 585 hci_register_sco_packet_handler(&packet_handler); 586 587 // SDP Server 588 sdp_init(); 589 memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer)); 590 hfp_ag_create_sdp_record( hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_ag_service_name, 0, supported_features, wide_band_speech); 591 printf("SDP service record size: %u\n", de_get_len( hfp_service_buffer)); 592 sdp_register_service(hfp_service_buffer); 593 594 // parse humand readable Bluetooth address 595 sscanf_bd_addr(device_addr_string, device_addr); 596 597 #ifdef HAVE_BTSTACK_STDIN 598 btstack_stdin_setup(stdin_process); 599 #endif 600 // turn on! 601 hci_power_control(HCI_POWER_ON); 602 return 0; 603 } 604 /* LISTING_END */ 605 /* EXAMPLE_END */ 606