1 2 /* 3 * Copyright (C) 2014 BlueKitchen GmbH 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of the copyright holders nor the names of 15 * contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 4. Any redistribution, use, or modification is done solely for 18 * personal benefit and not for any commercial purpose or for 19 * monetary gain. 20 * 21 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 25 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 31 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * Please inquire about commercial licensing options at 35 * [email protected] 36 * 37 */ 38 39 #define __BTSTACK_FILE__ "hfp_hf_demo.c" 40 41 /* 42 * hfp_hs_demo.c 43 */ 44 45 // ***************************************************************************** 46 /* EXAMPLE_START(hfp_hs_demo): HFP Hands-Free (HF) Demo 47 * 48 * @text This HFP Hands-Free example demonstrates how to receive 49 * an output from a remote HFP audio gateway (AG), and, 50 * if HAVE_BTSTACK_STDIN is defined, how to control the HFP AG. 51 */ 52 // ***************************************************************************** 53 54 55 #include "btstack_config.h" 56 57 #include <stdint.h> 58 #include <stdio.h> 59 #include <stdlib.h> 60 #include <string.h> 61 #include "btstack.h" 62 63 #include "sco_demo_util.h" 64 65 #ifdef HAVE_BTSTACK_STDIN 66 #include "btstack_stdin.h" 67 #endif 68 69 uint8_t hfp_service_buffer[150]; 70 const uint8_t rfcomm_channel_nr = 1; 71 const char hfp_hf_service_name[] = "BTstack HFP HF Demo"; 72 static bd_addr_t device_addr = {0x80,0xbe,0x05,0xd5,0x28,0x48}; 73 74 #ifdef HAVE_BTSTACK_STDIN 75 // 80:BE:05:D5:28:48 76 // prototypes 77 static void show_usage(void); 78 #endif 79 static hci_con_handle_t acl_handle = -1; 80 static hci_con_handle_t sco_handle; 81 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 82 static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; 83 #else 84 static uint8_t codecs[] = {HFP_CODEC_CVSD}; 85 #endif 86 static uint16_t indicators[1] = {0x01}; 87 static uint8_t negotiated_codec = HFP_CODEC_CVSD; 88 static btstack_packet_callback_registration_t hci_event_callback_registration; 89 char cmd; 90 91 static void dump_supported_codecs(void){ 92 int i; 93 int mSBC_skipped = 0; 94 printf("Supported codecs: "); 95 for (i = 0; i < sizeof(codecs); i++){ 96 switch(codecs[i]){ 97 case HFP_CODEC_CVSD: 98 printf("CVSD"); 99 break; 100 case HFP_CODEC_MSBC: 101 if (hci_extended_sco_link_supported()){ 102 printf(", mSBC"); 103 } else { 104 mSBC_skipped = 1; 105 } 106 break; 107 } 108 } 109 printf("\n"); 110 if (mSBC_skipped){ 111 printf("mSBC codec disabled because eSCO not supported by local controller.\n"); 112 } 113 } 114 115 #ifdef HAVE_BTSTACK_STDIN 116 117 // Testig User Interface 118 static void show_usage(void){ 119 bd_addr_t iut_address; 120 gap_local_bd_addr(iut_address); 121 122 printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console %s ---\n", bd_addr_to_str(iut_address)); 123 printf("\n"); 124 printf("a - establish SLC to %s | ", bd_addr_to_str(device_addr)); 125 printf("A - release SLC connection to device\n"); 126 printf("b - establish Audio connection | B - release Audio connection\n"); 127 printf("d - query network operator | D - Enable HFP AG registration status update via bitmap(IIA)\n"); 128 printf("f - answer incoming call | F - Hangup call\n"); 129 printf("g - query network operator name | G - reject incoming call\n"); 130 printf("i - dial 1234567 | I - dial 7654321\n"); 131 printf("j - dial #1 | J - dial #99\n"); 132 printf("o - Set speaker volume to 0 (minimum) | O - Set speaker volume to 9 (default)\n"); 133 printf("p - Set speaker volume to 12 (higher) | P - Set speaker volume to 15 (maximum)\n"); 134 printf("q - Set microphone gain to 0 (minimum) | Q - Set microphone gain to 9 (default)\n"); 135 printf("s - Set microphone gain to 12 (higher) | S - Set microphone gain to 15 (maximum)\n"); 136 printf("t - terminate connection\n"); 137 printf("u - send 'user busy' (TWC 0)\n"); 138 printf("U - end active call and accept other call' (TWC 1)\n"); 139 printf("v - Swap active call call (TWC 2) | V - Join held call (TWC 3)\n"); 140 printf("w - Connect calls (TWC 4) | W - redial\n"); 141 printf("c/C - disable/enable registration status update for all AG indicators\n"); 142 printf("e/E - disable/enable reporting of the extended AG error result code\n"); 143 printf("k/K - deactivate/activate call waiting notification\n"); 144 printf("l/L - deactivate/activate calling line notification\n"); 145 printf("m/M - deactivate/activate echo canceling and noise reduction\n"); 146 printf("n/N - deactivate/activate voice recognition\n"); 147 printf("0123456789#*-+ - send DTMF dial tones\n"); 148 printf("x - request phone number for voice tag | X - current call status (ECS)\n"); 149 printf("y - release call with index 2 (ECC) | Y - private consulation with call 2(ECC)\n"); 150 printf("[ - Query Response and Hold status (RHH ?) | ] - Place call in a response and held state(RHH 0)\n"); 151 printf("{ - Accept held call(RHH 1) | } - Reject held call(RHH 2)\n"); 152 printf("? - Query Subscriber Number (NUM)\n"); 153 printf("! - Update HF indicator with assigned number 1 (HFI)\n"); 154 printf("---\n"); 155 printf("Ctrl-c - exit\n"); 156 printf("---\n"); 157 } 158 159 static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){ 160 UNUSED(ds); 161 UNUSED(callback_type); 162 163 cmd = btstack_stdin_read(); 164 165 if (cmd >= '0' && cmd <= '9'){ 166 printf("DTMF Code: %c\n", cmd); 167 hfp_hf_send_dtmf_code(acl_handle, cmd); 168 return; 169 } 170 171 switch (cmd){ 172 case '#': 173 case '-': 174 case '+': 175 case '*': 176 log_info("USER:\'%c\'", cmd); 177 printf("DTMF Code: %c\n", cmd); 178 hfp_hf_send_dtmf_code(acl_handle, cmd); 179 break; 180 case 'a': 181 log_info("USER:\'%c\'", cmd); 182 printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 183 hfp_hf_establish_service_level_connection(device_addr); 184 break; 185 case 'A': 186 log_info("USER:\'%c\'", cmd); 187 printf("Release Service level connection.\n"); 188 hfp_hf_release_service_level_connection(acl_handle); 189 break; 190 case 'b': 191 log_info("USER:\'%c\'", cmd); 192 printf("Establish Audio connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 193 hfp_hf_establish_audio_connection(acl_handle); 194 break; 195 case 'B': 196 log_info("USER:\'%c\'", cmd); 197 printf("Release Audio service level connection.\n"); 198 hfp_hf_release_audio_connection(acl_handle); 199 break; 200 case 'C': 201 log_info("USER:\'%c\'", cmd); 202 printf("Enable registration status update for all AG indicators.\n"); 203 hfp_hf_enable_status_update_for_all_ag_indicators(acl_handle); 204 break; 205 case 'c': 206 log_info("USER:\'%c\'", cmd); 207 printf("Disable registration status update for all AG indicators.\n"); 208 hfp_hf_disable_status_update_for_all_ag_indicators(acl_handle); 209 break; 210 case 'D': 211 log_info("USER:\'%c\'", cmd); 212 printf("Set HFP AG registration status update for individual indicators (0111111).\n"); 213 hfp_hf_set_status_update_for_individual_ag_indicators(acl_handle, 63); 214 break; 215 case 'd': 216 log_info("USER:\'%c\'", cmd); 217 printf("Query network operator.\n"); 218 hfp_hf_query_operator_selection(acl_handle); 219 break; 220 case 'E': 221 log_info("USER:\'%c\'", cmd); 222 printf("Enable reporting of the extended AG error result code.\n"); 223 hfp_hf_enable_report_extended_audio_gateway_error_result_code(acl_handle); 224 break; 225 case 'e': 226 log_info("USER:\'%c\'", cmd); 227 printf("Disable reporting of the extended AG error result code.\n"); 228 hfp_hf_disable_report_extended_audio_gateway_error_result_code(acl_handle); 229 break; 230 case 'f': 231 log_info("USER:\'%c\'", cmd); 232 printf("Answer incoming call.\n"); 233 hfp_hf_answer_incoming_call(acl_handle); 234 break; 235 case 'F': 236 log_info("USER:\'%c\'", cmd); 237 printf("Hangup call.\n"); 238 hfp_hf_terminate_call(acl_handle); 239 break; 240 case 'G': 241 log_info("USER:\'%c\'", cmd); 242 printf("Reject incoming call.\n"); 243 hfp_hf_reject_incoming_call(acl_handle); 244 break; 245 case 'g': 246 log_info("USER:\'%c\'", cmd); 247 printf("Query operator.\n"); 248 hfp_hf_query_operator_selection(acl_handle); 249 break; 250 case 't': 251 log_info("USER:\'%c\'", cmd); 252 printf("Terminate HCI connection.\n"); 253 gap_disconnect(acl_handle); 254 break; 255 case 'i': 256 log_info("USER:\'%c\'", cmd); 257 printf("Dial 1234567\n"); 258 hfp_hf_dial_number(acl_handle, "1234567"); 259 break; 260 case 'I': 261 log_info("USER:\'%c\'", cmd); 262 printf("Dial 7654321\n"); 263 hfp_hf_dial_number(acl_handle, "7654321"); 264 break; 265 case 'j': 266 log_info("USER:\'%c\'", cmd); 267 printf("Dial #1\n"); 268 hfp_hf_dial_memory(acl_handle,1); 269 break; 270 case 'J': 271 log_info("USER:\'%c\'", cmd); 272 printf("Dial #99\n"); 273 hfp_hf_dial_memory(acl_handle,99); 274 break; 275 case 'k': 276 log_info("USER:\'%c\'", cmd); 277 printf("Deactivate call waiting notification\n"); 278 hfp_hf_deactivate_call_waiting_notification(acl_handle); 279 break; 280 case 'K': 281 log_info("USER:\'%c\'", cmd); 282 printf("Activate call waiting notification\n"); 283 hfp_hf_activate_call_waiting_notification(acl_handle); 284 break; 285 case 'l': 286 log_info("USER:\'%c\'", cmd); 287 printf("Deactivate calling line notification\n"); 288 hfp_hf_deactivate_calling_line_notification(acl_handle); 289 break; 290 case 'L': 291 log_info("USER:\'%c\'", cmd); 292 printf("Activate calling line notification\n"); 293 hfp_hf_activate_calling_line_notification(acl_handle); 294 break; 295 case 'm': 296 log_info("USER:\'%c\'", cmd); 297 printf("Deactivate echo canceling and noise reduction\n"); 298 hfp_hf_deactivate_echo_canceling_and_noise_reduction(acl_handle); 299 break; 300 case 'M': 301 log_info("USER:\'%c\'", cmd); 302 printf("Activate echo canceling and noise reduction\n"); 303 hfp_hf_activate_echo_canceling_and_noise_reduction(acl_handle); 304 break; 305 case 'n': 306 log_info("USER:\'%c\'", cmd); 307 printf("Deactivate voice recognition\n"); 308 hfp_hf_deactivate_voice_recognition_notification(acl_handle); 309 break; 310 case 'N': 311 log_info("USER:\'%c\'", cmd); 312 printf("Activate voice recognition %s\n", bd_addr_to_str(device_addr)); 313 hfp_hf_activate_voice_recognition_notification(acl_handle); 314 break; 315 case 'o': 316 log_info("USER:\'%c\'", cmd); 317 printf("Set speaker gain to 0 (minimum)\n"); 318 hfp_hf_set_speaker_gain(acl_handle, 0); 319 break; 320 case 'O': 321 log_info("USER:\'%c\'", cmd); 322 printf("Set speaker gain to 9 (default)\n"); 323 hfp_hf_set_speaker_gain(acl_handle, 9); 324 break; 325 case 'p': 326 log_info("USER:\'%c\'", cmd); 327 printf("Set speaker gain to 12 (higher)\n"); 328 hfp_hf_set_speaker_gain(acl_handle, 12); 329 break; 330 case 'P': 331 log_info("USER:\'%c\'", cmd); 332 printf("Set speaker gain to 15 (maximum)\n"); 333 hfp_hf_set_speaker_gain(acl_handle, 15); 334 break; 335 case 'q': 336 log_info("USER:\'%c\'", cmd); 337 printf("Set microphone gain to 0\n"); 338 hfp_hf_set_microphone_gain(acl_handle, 0); 339 break; 340 case 'Q': 341 log_info("USER:\'%c\'", cmd); 342 printf("Set microphone gain to 9\n"); 343 hfp_hf_set_microphone_gain(acl_handle, 9); 344 break; 345 case 's': 346 log_info("USER:\'%c\'", cmd); 347 printf("Set microphone gain to 12\n"); 348 hfp_hf_set_microphone_gain(acl_handle, 12); 349 break; 350 case 'S': 351 log_info("USER:\'%c\'", cmd); 352 printf("Set microphone gain to 15\n"); 353 hfp_hf_set_microphone_gain(acl_handle, 15); 354 break; 355 case 'u': 356 log_info("USER:\'%c\'", cmd); 357 printf("Send 'user busy' (Three-Way Call 0)\n"); 358 hfp_hf_user_busy(acl_handle); 359 break; 360 case 'U': 361 log_info("USER:\'%c\'", cmd); 362 printf("End active call and accept waiting/held call (Three-Way Call 1)\n"); 363 hfp_hf_end_active_and_accept_other(acl_handle); 364 break; 365 case 'v': 366 log_info("USER:\'%c\'", cmd); 367 printf("Swap active call and hold/waiting call (Three-Way Call 2)\n"); 368 hfp_hf_swap_calls(acl_handle); 369 break; 370 case 'V': 371 log_info("USER:\'%c\'", cmd); 372 printf("Join hold call (Three-Way Call 3)\n"); 373 hfp_hf_join_held_call(acl_handle); 374 break; 375 case 'w': 376 log_info("USER:\'%c\'", cmd); 377 printf("Connect calls (Three-Way Call 4)\n"); 378 hfp_hf_connect_calls(acl_handle); 379 break; 380 case 'W': 381 log_info("USER:\'%c\'", cmd); 382 printf("Redial\n"); 383 hfp_hf_redial_last_number(acl_handle); 384 break; 385 case 'x': 386 log_info("USER:\'%c\'", cmd); 387 printf("Request phone number for voice tag\n"); 388 hfp_hf_request_phone_number_for_voice_tag(acl_handle); 389 break; 390 case 'X': 391 log_info("USER:\'%c\'", cmd); 392 printf("Query current call status\n"); 393 hfp_hf_query_current_call_status(acl_handle); 394 break; 395 case 'y': 396 log_info("USER:\'%c\'", cmd); 397 printf("Release call with index 2\n"); 398 hfp_hf_release_call_with_index(acl_handle, 2); 399 break; 400 case 'Y': 401 log_info("USER:\'%c\'", cmd); 402 printf("Private consulation with call 2\n"); 403 hfp_hf_private_consultation_with_call(acl_handle, 2); 404 break; 405 case '[': 406 log_info("USER:\'%c\'", cmd); 407 printf("Query Response and Hold status (RHH ?)\n"); 408 hfp_hf_rrh_query_status(acl_handle); 409 break; 410 case ']': 411 log_info("USER:\'%c\'", cmd); 412 printf("Place call in a response and held state (RHH 0)\n"); 413 hfp_hf_rrh_hold_call(acl_handle); 414 break; 415 case '{': 416 log_info("USER:\'%c\'", cmd); 417 printf("Accept held call (RHH 1)\n"); 418 hfp_hf_rrh_accept_held_call(acl_handle); 419 break; 420 case '}': 421 log_info("USER:\'%c\'", cmd); 422 printf("Reject held call (RHH 2)\n"); 423 hfp_hf_rrh_reject_held_call(acl_handle); 424 break; 425 case '?': 426 log_info("USER:\'%c\'", cmd); 427 printf("Query Subscriber Number\n"); 428 hfp_hf_query_subscriber_number(acl_handle); 429 break; 430 case '!': 431 log_info("USER:\'%c\'", cmd); 432 printf("Update HF indicator with assigned number 1 (HFI)\n"); 433 hfp_hf_set_hf_indicator(acl_handle, 1, 1); 434 break; 435 436 default: 437 show_usage(); 438 break; 439 } 440 } 441 #endif 442 443 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){ 444 UNUSED(channel); 445 446 switch (packet_type){ 447 448 case HCI_SCO_DATA_PACKET: 449 sco_demo_receive(event, event_size); 450 break; 451 452 case HCI_EVENT_PACKET: 453 switch (event[0]){ 454 case HCI_EVENT_SCO_CAN_SEND_NOW: 455 sco_demo_send(sco_handle); 456 break; 457 458 case HCI_EVENT_COMMAND_COMPLETE: 459 if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){ 460 dump_supported_codecs(); 461 } 462 break; 463 464 case HCI_EVENT_HFP_META: 465 switch (event[2]) { 466 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: 467 acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event); 468 hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr); 469 printf("Service level connection established %s.\n\n", bd_addr_to_str(device_addr)); 470 break; 471 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: 472 printf("Service level connection released.\n\n"); 473 break; 474 case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED: 475 if (hfp_subevent_audio_connection_established_get_status(event)){ 476 sco_handle = 0; 477 printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event)); 478 } else { 479 sco_handle = hfp_subevent_audio_connection_established_get_handle(event); 480 printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 481 negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event); 482 switch (negotiated_codec){ 483 case 0x01: 484 printf("Using CVSD codec.\n"); 485 break; 486 case 0x02: 487 printf("Using mSBC codec.\n"); 488 break; 489 default: 490 printf("Using unknown codec 0x%02x.\n", negotiated_codec); 491 break; 492 } 493 sco_demo_set_codec(negotiated_codec); 494 hci_request_sco_can_send_now_event(); 495 } 496 break; 497 case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: 498 sco_handle = 0; 499 printf("Audio connection released\n"); 500 sco_demo_close(); 501 break; 502 case HFP_SUBEVENT_COMPLETE: 503 switch (cmd){ 504 case 'd': 505 printf("HFP AG registration status update enabled.\n"); 506 break; 507 case 'e': 508 printf("HFP AG registration status update for individual indicators set.\n"); 509 break; 510 default: 511 break; 512 } 513 break; 514 case HFP_SUBEVENT_AG_INDICATOR_STATUS_CHANGED: 515 printf("AG_INDICATOR_STATUS_CHANGED, AG indicator '%s' (index: %d) to: %d\n", (const char*) &event[5], event[3], event[4]); 516 break; 517 case HFP_SUBEVENT_NETWORK_OPERATOR_CHANGED: 518 printf("NETWORK_OPERATOR_CHANGED, operator mode: %d, format: %d, name: %s\n", event[3], event[4], (char *) &event[5]); 519 break; 520 case HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR: 521 printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : %d\n", event[3]); 522 break; 523 case HFP_SUBEVENT_RING: 524 printf("** Ring **\n"); 525 break; 526 case HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG: 527 printf("Phone number for voice tag: %s\n", (const char *) &event[3]); 528 break; 529 case HFP_SUBEVENT_SPEAKER_VOLUME: 530 printf("Speaker volume: %u\n", event[3]); 531 break; 532 case HFP_SUBEVENT_MICROPHONE_VOLUME: 533 printf("Microphone volume: %u\n", event[3]); 534 break; 535 default: 536 printf("event not handled %u\n", event[2]); 537 break; 538 } 539 break; 540 541 default: 542 break; 543 } 544 break; 545 546 default: 547 break; 548 } 549 550 if (event[0] != HCI_EVENT_HFP_META) return; 551 } 552 553 /* @section Main Application Setup 554 * 555 * @text Listing MainConfiguration shows main application code. 556 * To run a HFP HF service you need to initialize the SDP, and to create and register HFP HF record with it. 557 * The packet_handler is used for sending commands to the HFP AG. It also receives the HFP AG's answers. 558 * The stdin_process callback allows for sending commands to the HFP AG. 559 * At the end the Bluetooth stack is started. 560 */ 561 562 /* LISTING_START(MainConfiguration): Setup HFP Hands-Free unit */ 563 int btstack_main(int argc, const char * argv[]); 564 int btstack_main(int argc, const char * argv[]){ 565 (void)argc; 566 (void)argv; 567 568 sco_demo_init(); 569 570 // register for HCI events 571 hci_event_callback_registration.callback = &packet_handler; 572 hci_add_event_handler(&hci_event_callback_registration); 573 hci_register_sco_packet_handler(&packet_handler); 574 575 gap_discoverable_control(1); 576 gap_set_class_of_device(0x200408); 577 578 // init L2CAP 579 l2cap_init(); 580 581 uint16_t hf_supported_features = 582 (1<<HFP_HFSF_ESCO_S4) | 583 (1<<HFP_HFSF_HF_INDICATORS) | 584 (1<<HFP_HFSF_CODEC_NEGOTIATION) | 585 (1<<HFP_HFSF_ENHANCED_CALL_STATUS) | 586 (1<<HFP_HFSF_REMOTE_VOLUME_CONTROL); 587 int wide_band_speech = 1; 588 589 rfcomm_init(); 590 hfp_hf_init(rfcomm_channel_nr); 591 hfp_hf_init_supported_features(hf_supported_features); 592 hfp_hf_init_hf_indicators(sizeof(indicators)/sizeof(uint16_t), indicators); 593 hfp_hf_init_codecs(sizeof(codecs), codecs); 594 595 hfp_hf_register_packet_handler(packet_handler); 596 hci_register_sco_packet_handler(&packet_handler); 597 598 sdp_init(); 599 memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer)); 600 hfp_hf_create_sdp_record(hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_hf_service_name, hf_supported_features, wide_band_speech); 601 printf("SDP service record size: %u\n", de_get_len(hfp_service_buffer)); 602 sdp_register_service(hfp_service_buffer); 603 604 605 #ifdef HAVE_BTSTACK_STDIN 606 btstack_stdin_setup(stdin_process); 607 #endif 608 // turn on! 609 hci_power_control(HCI_POWER_ON); 610 return 0; 611 } 612 /* LISTING_END */ 613 /* EXAMPLE_END */ 614