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 uint8_t hfp_service_buffer[150]; 66 const uint8_t rfcomm_channel_nr = 1; 67 const char hfp_hf_service_name[] = "BTstack HFP HF Demo"; 68 69 #ifdef HAVE_BTSTACK_STDIN 70 static const char * device_addr_string = "00:1B:DC:08:0A:A5"; 71 #endif 72 73 static bd_addr_t device_addr; 74 75 #ifdef HAVE_BTSTACK_STDIN 76 // 80:BE:05:D5:28:48 77 // prototypes 78 static void show_usage(void); 79 #endif 80 static hci_con_handle_t acl_handle = -1; 81 static hci_con_handle_t sco_handle; 82 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 83 static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; 84 #else 85 static uint8_t codecs[] = {HFP_CODEC_CVSD}; 86 #endif 87 static uint16_t indicators[1] = {0x01}; 88 static uint8_t negotiated_codec = HFP_CODEC_CVSD; 89 static btstack_packet_callback_registration_t hci_event_callback_registration; 90 char cmd; 91 92 static void dump_supported_codecs(void){ 93 int i; 94 int mSBC_skipped = 0; 95 printf("Supported codecs: "); 96 for (i = 0; i < sizeof(codecs); i++){ 97 switch(codecs[i]){ 98 case HFP_CODEC_CVSD: 99 printf("CVSD"); 100 break; 101 case HFP_CODEC_MSBC: 102 if (hci_extended_sco_link_supported()){ 103 printf(", mSBC"); 104 } else { 105 mSBC_skipped = 1; 106 } 107 break; 108 } 109 } 110 printf("\n"); 111 if (mSBC_skipped){ 112 printf("mSBC codec disabled because eSCO not supported by local controller.\n"); 113 } 114 } 115 116 #ifdef HAVE_BTSTACK_STDIN 117 118 // Testig User Interface 119 static void show_usage(void){ 120 bd_addr_t iut_address; 121 gap_local_bd_addr(iut_address); 122 123 printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console %s ---\n", bd_addr_to_str(iut_address)); 124 printf("\n"); 125 printf("a - establish SLC to %s | ", bd_addr_to_str(device_addr)); 126 printf("A - release SLC connection to device\n"); 127 printf("b - establish Audio connection | B - release Audio connection\n"); 128 printf("d - query network operator | D - Enable HFP AG registration status update via bitmap(IIA)\n"); 129 printf("f - answer incoming call | F - Hangup call\n"); 130 printf("g - query network operator name | G - reject incoming call\n"); 131 printf("i - dial 1234567 | I - dial 7654321\n"); 132 printf("j - dial #1 | J - dial #99\n"); 133 printf("o - Set speaker volume to 0 (minimum) | O - Set speaker volume to 9 (default)\n"); 134 printf("p - Set speaker volume to 12 (higher) | P - Set speaker volume to 15 (maximum)\n"); 135 printf("q - Set microphone gain to 0 (minimum) | Q - Set microphone gain to 9 (default)\n"); 136 printf("s - Set microphone gain to 12 (higher) | S - Set microphone gain to 15 (maximum)\n"); 137 printf("t - terminate connection\n"); 138 printf("u - send 'user busy' (TWC 0)\n"); 139 printf("U - end active call and accept other call' (TWC 1)\n"); 140 printf("v - Swap active call call (TWC 2) | V - Join held call (TWC 3)\n"); 141 printf("w - Connect calls (TWC 4) | W - redial\n"); 142 printf("c/C - disable/enable registration status update for all AG indicators\n"); 143 printf("e/E - disable/enable reporting of the extended AG error result code\n"); 144 printf("k/K - deactivate/activate call waiting notification\n"); 145 printf("l/L - deactivate/activate calling line notification\n"); 146 printf("m/M - deactivate/activate echo canceling and noise reduction\n"); 147 printf("n/N - deactivate/activate voice recognition\n"); 148 printf("0123456789#*-+ - send DTMF dial tones\n"); 149 printf("x - request phone number for voice tag | X - current call status (ECS)\n"); 150 printf("y - release call with index 2 (ECC) | Y - private consulation with call 2(ECC)\n"); 151 printf("[ - Query Response and Hold status (RHH ?) | ] - Place call in a response and held state(RHH 0)\n"); 152 printf("{ - Accept held call(RHH 1) | } - Reject held call(RHH 2)\n"); 153 printf("? - Query Subscriber Number (NUM)\n"); 154 printf("! - Update HF indicator with assigned number 1 (HFI)\n"); 155 printf("---\n"); 156 printf("Ctrl-c - exit\n"); 157 printf("---\n"); 158 } 159 160 static void stdin_process(char c){ 161 cmd = c; // used in packet handler 162 163 if (cmd >= '0' && cmd <= '9'){ 164 printf("DTMF Code: %c\n", cmd); 165 hfp_hf_send_dtmf_code(acl_handle, cmd); 166 return; 167 } 168 169 switch (cmd){ 170 case '#': 171 case '-': 172 case '+': 173 case '*': 174 log_info("USER:\'%c\'", cmd); 175 printf("DTMF Code: %c\n", cmd); 176 hfp_hf_send_dtmf_code(acl_handle, cmd); 177 break; 178 case 'a': 179 log_info("USER:\'%c\'", cmd); 180 printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 181 hfp_hf_establish_service_level_connection(device_addr); 182 break; 183 case 'A': 184 log_info("USER:\'%c\'", cmd); 185 printf("Release Service level connection.\n"); 186 hfp_hf_release_service_level_connection(acl_handle); 187 break; 188 case 'b': 189 log_info("USER:\'%c\'", cmd); 190 printf("Establish Audio connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 191 hfp_hf_establish_audio_connection(acl_handle); 192 break; 193 case 'B': 194 log_info("USER:\'%c\'", cmd); 195 printf("Release Audio service level connection.\n"); 196 hfp_hf_release_audio_connection(acl_handle); 197 break; 198 case 'C': 199 log_info("USER:\'%c\'", cmd); 200 printf("Enable registration status update for all AG indicators.\n"); 201 hfp_hf_enable_status_update_for_all_ag_indicators(acl_handle); 202 break; 203 case 'c': 204 log_info("USER:\'%c\'", cmd); 205 printf("Disable registration status update for all AG indicators.\n"); 206 hfp_hf_disable_status_update_for_all_ag_indicators(acl_handle); 207 break; 208 case 'D': 209 log_info("USER:\'%c\'", cmd); 210 printf("Set HFP AG registration status update for individual indicators (0111111).\n"); 211 hfp_hf_set_status_update_for_individual_ag_indicators(acl_handle, 63); 212 break; 213 case 'd': 214 log_info("USER:\'%c\'", cmd); 215 printf("Query network operator.\n"); 216 hfp_hf_query_operator_selection(acl_handle); 217 break; 218 case 'E': 219 log_info("USER:\'%c\'", cmd); 220 printf("Enable reporting of the extended AG error result code.\n"); 221 hfp_hf_enable_report_extended_audio_gateway_error_result_code(acl_handle); 222 break; 223 case 'e': 224 log_info("USER:\'%c\'", cmd); 225 printf("Disable reporting of the extended AG error result code.\n"); 226 hfp_hf_disable_report_extended_audio_gateway_error_result_code(acl_handle); 227 break; 228 case 'f': 229 log_info("USER:\'%c\'", cmd); 230 printf("Answer incoming call.\n"); 231 hfp_hf_answer_incoming_call(acl_handle); 232 break; 233 case 'F': 234 log_info("USER:\'%c\'", cmd); 235 printf("Hangup call.\n"); 236 hfp_hf_terminate_call(acl_handle); 237 break; 238 case 'G': 239 log_info("USER:\'%c\'", cmd); 240 printf("Reject incoming call.\n"); 241 hfp_hf_reject_incoming_call(acl_handle); 242 break; 243 case 'g': 244 log_info("USER:\'%c\'", cmd); 245 printf("Query operator.\n"); 246 hfp_hf_query_operator_selection(acl_handle); 247 break; 248 case 't': 249 log_info("USER:\'%c\'", cmd); 250 printf("Terminate HCI connection.\n"); 251 gap_disconnect(acl_handle); 252 break; 253 case 'i': 254 log_info("USER:\'%c\'", cmd); 255 printf("Dial 1234567\n"); 256 hfp_hf_dial_number(acl_handle, "1234567"); 257 break; 258 case 'I': 259 log_info("USER:\'%c\'", cmd); 260 printf("Dial 7654321\n"); 261 hfp_hf_dial_number(acl_handle, "7654321"); 262 break; 263 case 'j': 264 log_info("USER:\'%c\'", cmd); 265 printf("Dial #1\n"); 266 hfp_hf_dial_memory(acl_handle,1); 267 break; 268 case 'J': 269 log_info("USER:\'%c\'", cmd); 270 printf("Dial #99\n"); 271 hfp_hf_dial_memory(acl_handle,99); 272 break; 273 case 'k': 274 log_info("USER:\'%c\'", cmd); 275 printf("Deactivate call waiting notification\n"); 276 hfp_hf_deactivate_call_waiting_notification(acl_handle); 277 break; 278 case 'K': 279 log_info("USER:\'%c\'", cmd); 280 printf("Activate call waiting notification\n"); 281 hfp_hf_activate_call_waiting_notification(acl_handle); 282 break; 283 case 'l': 284 log_info("USER:\'%c\'", cmd); 285 printf("Deactivate calling line notification\n"); 286 hfp_hf_deactivate_calling_line_notification(acl_handle); 287 break; 288 case 'L': 289 log_info("USER:\'%c\'", cmd); 290 printf("Activate calling line notification\n"); 291 hfp_hf_activate_calling_line_notification(acl_handle); 292 break; 293 case 'm': 294 log_info("USER:\'%c\'", cmd); 295 printf("Deactivate echo canceling and noise reduction\n"); 296 hfp_hf_deactivate_echo_canceling_and_noise_reduction(acl_handle); 297 break; 298 case 'M': 299 log_info("USER:\'%c\'", cmd); 300 printf("Activate echo canceling and noise reduction\n"); 301 hfp_hf_activate_echo_canceling_and_noise_reduction(acl_handle); 302 break; 303 case 'n': 304 log_info("USER:\'%c\'", cmd); 305 printf("Deactivate voice recognition\n"); 306 hfp_hf_deactivate_voice_recognition_notification(acl_handle); 307 break; 308 case 'N': 309 log_info("USER:\'%c\'", cmd); 310 printf("Activate voice recognition %s\n", bd_addr_to_str(device_addr)); 311 hfp_hf_activate_voice_recognition_notification(acl_handle); 312 break; 313 case 'o': 314 log_info("USER:\'%c\'", cmd); 315 printf("Set speaker gain to 0 (minimum)\n"); 316 hfp_hf_set_speaker_gain(acl_handle, 0); 317 break; 318 case 'O': 319 log_info("USER:\'%c\'", cmd); 320 printf("Set speaker gain to 9 (default)\n"); 321 hfp_hf_set_speaker_gain(acl_handle, 9); 322 break; 323 case 'p': 324 log_info("USER:\'%c\'", cmd); 325 printf("Set speaker gain to 12 (higher)\n"); 326 hfp_hf_set_speaker_gain(acl_handle, 12); 327 break; 328 case 'P': 329 log_info("USER:\'%c\'", cmd); 330 printf("Set speaker gain to 15 (maximum)\n"); 331 hfp_hf_set_speaker_gain(acl_handle, 15); 332 break; 333 case 'q': 334 log_info("USER:\'%c\'", cmd); 335 printf("Set microphone gain to 0\n"); 336 hfp_hf_set_microphone_gain(acl_handle, 0); 337 break; 338 case 'Q': 339 log_info("USER:\'%c\'", cmd); 340 printf("Set microphone gain to 9\n"); 341 hfp_hf_set_microphone_gain(acl_handle, 9); 342 break; 343 case 's': 344 log_info("USER:\'%c\'", cmd); 345 printf("Set microphone gain to 12\n"); 346 hfp_hf_set_microphone_gain(acl_handle, 12); 347 break; 348 case 'S': 349 log_info("USER:\'%c\'", cmd); 350 printf("Set microphone gain to 15\n"); 351 hfp_hf_set_microphone_gain(acl_handle, 15); 352 break; 353 case 'u': 354 log_info("USER:\'%c\'", cmd); 355 printf("Send 'user busy' (Three-Way Call 0)\n"); 356 hfp_hf_user_busy(acl_handle); 357 break; 358 case 'U': 359 log_info("USER:\'%c\'", cmd); 360 printf("End active call and accept waiting/held call (Three-Way Call 1)\n"); 361 hfp_hf_end_active_and_accept_other(acl_handle); 362 break; 363 case 'v': 364 log_info("USER:\'%c\'", cmd); 365 printf("Swap active call and hold/waiting call (Three-Way Call 2)\n"); 366 hfp_hf_swap_calls(acl_handle); 367 break; 368 case 'V': 369 log_info("USER:\'%c\'", cmd); 370 printf("Join hold call (Three-Way Call 3)\n"); 371 hfp_hf_join_held_call(acl_handle); 372 break; 373 case 'w': 374 log_info("USER:\'%c\'", cmd); 375 printf("Connect calls (Three-Way Call 4)\n"); 376 hfp_hf_connect_calls(acl_handle); 377 break; 378 case 'W': 379 log_info("USER:\'%c\'", cmd); 380 printf("Redial\n"); 381 hfp_hf_redial_last_number(acl_handle); 382 break; 383 case 'x': 384 log_info("USER:\'%c\'", cmd); 385 printf("Request phone number for voice tag\n"); 386 hfp_hf_request_phone_number_for_voice_tag(acl_handle); 387 break; 388 case 'X': 389 log_info("USER:\'%c\'", cmd); 390 printf("Query current call status\n"); 391 hfp_hf_query_current_call_status(acl_handle); 392 break; 393 case 'y': 394 log_info("USER:\'%c\'", cmd); 395 printf("Release call with index 2\n"); 396 hfp_hf_release_call_with_index(acl_handle, 2); 397 break; 398 case 'Y': 399 log_info("USER:\'%c\'", cmd); 400 printf("Private consulation with call 2\n"); 401 hfp_hf_private_consultation_with_call(acl_handle, 2); 402 break; 403 case '[': 404 log_info("USER:\'%c\'", cmd); 405 printf("Query Response and Hold status (RHH ?)\n"); 406 hfp_hf_rrh_query_status(acl_handle); 407 break; 408 case ']': 409 log_info("USER:\'%c\'", cmd); 410 printf("Place call in a response and held state (RHH 0)\n"); 411 hfp_hf_rrh_hold_call(acl_handle); 412 break; 413 case '{': 414 log_info("USER:\'%c\'", cmd); 415 printf("Accept held call (RHH 1)\n"); 416 hfp_hf_rrh_accept_held_call(acl_handle); 417 break; 418 case '}': 419 log_info("USER:\'%c\'", cmd); 420 printf("Reject held call (RHH 2)\n"); 421 hfp_hf_rrh_reject_held_call(acl_handle); 422 break; 423 case '?': 424 log_info("USER:\'%c\'", cmd); 425 printf("Query Subscriber Number\n"); 426 hfp_hf_query_subscriber_number(acl_handle); 427 break; 428 case '!': 429 log_info("USER:\'%c\'", cmd); 430 printf("Update HF indicator with assigned number 1 (HFI)\n"); 431 hfp_hf_set_hf_indicator(acl_handle, 1, 1); 432 break; 433 434 default: 435 show_usage(); 436 break; 437 } 438 } 439 #endif 440 441 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){ 442 UNUSED(channel); 443 444 switch (packet_type){ 445 446 case HCI_SCO_DATA_PACKET: 447 sco_demo_receive(event, event_size); 448 break; 449 450 case HCI_EVENT_PACKET: 451 switch (event[0]){ 452 case HCI_EVENT_SCO_CAN_SEND_NOW: 453 sco_demo_send(sco_handle); 454 break; 455 456 case HCI_EVENT_COMMAND_COMPLETE: 457 if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){ 458 dump_supported_codecs(); 459 } 460 break; 461 462 case HCI_EVENT_HFP_META: 463 switch (event[2]) { 464 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: 465 acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event); 466 hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr); 467 printf("Service level connection established %s.\n\n", bd_addr_to_str(device_addr)); 468 break; 469 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: 470 printf("Service level connection released.\n\n"); 471 break; 472 case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED: 473 if (hfp_subevent_audio_connection_established_get_status(event)){ 474 sco_handle = 0; 475 printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event)); 476 } else { 477 sco_handle = hfp_subevent_audio_connection_established_get_handle(event); 478 printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 479 negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event); 480 switch (negotiated_codec){ 481 case 0x01: 482 printf("Using CVSD codec.\n"); 483 break; 484 case 0x02: 485 printf("Using mSBC codec.\n"); 486 break; 487 default: 488 printf("Using unknown codec 0x%02x.\n", negotiated_codec); 489 break; 490 } 491 sco_demo_set_codec(negotiated_codec); 492 hci_request_sco_can_send_now_event(); 493 } 494 break; 495 case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: 496 sco_handle = 0; 497 printf("Audio connection released\n"); 498 sco_demo_close(); 499 break; 500 case HFP_SUBEVENT_COMPLETE: 501 switch (cmd){ 502 case 'd': 503 printf("HFP AG registration status update enabled.\n"); 504 break; 505 case 'e': 506 printf("HFP AG registration status update for individual indicators set.\n"); 507 break; 508 default: 509 break; 510 } 511 break; 512 case HFP_SUBEVENT_AG_INDICATOR_STATUS_CHANGED: 513 printf("AG_INDICATOR_STATUS_CHANGED, AG indicator '%s' (index: %d) to: %d\n", (const char*) &event[5], event[3], event[4]); 514 break; 515 case HFP_SUBEVENT_NETWORK_OPERATOR_CHANGED: 516 printf("NETWORK_OPERATOR_CHANGED, operator mode: %d, format: %d, name: %s\n", event[3], event[4], (char *) &event[5]); 517 break; 518 case HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR: 519 printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : %d\n", event[3]); 520 break; 521 case HFP_SUBEVENT_RING: 522 printf("** Ring **\n"); 523 break; 524 case HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG: 525 printf("Phone number for voice tag: %s\n", (const char *) &event[3]); 526 break; 527 case HFP_SUBEVENT_SPEAKER_VOLUME: 528 printf("Speaker volume: %u\n", event[3]); 529 break; 530 case HFP_SUBEVENT_MICROPHONE_VOLUME: 531 printf("Microphone volume: %u\n", event[3]); 532 break; 533 case HFP_SUBEVENT_CALLING_LINE_IDENTIFICATION_NOTIFICATION: 534 printf("Caller ID, number %s\n", hfp_subevent_calling_line_identification_notification_get_number(event)); 535 break; 536 default: 537 printf("event not handled %u\n", event[2]); 538 break; 539 } 540 break; 541 542 default: 543 break; 544 } 545 break; 546 547 default: 548 break; 549 } 550 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_CLI_PRESENTATION_CAPABILITY) | 584 (1<<HFP_HFSF_HF_INDICATORS) | 585 (1<<HFP_HFSF_CODEC_NEGOTIATION) | 586 (1<<HFP_HFSF_ENHANCED_CALL_STATUS) | 587 (1<<HFP_HFSF_REMOTE_VOLUME_CONTROL); 588 int wide_band_speech = 1; 589 590 rfcomm_init(); 591 hfp_hf_init(rfcomm_channel_nr); 592 hfp_hf_init_supported_features(hf_supported_features); 593 hfp_hf_init_hf_indicators(sizeof(indicators)/sizeof(uint16_t), indicators); 594 hfp_hf_init_codecs(sizeof(codecs), codecs); 595 596 hfp_hf_register_packet_handler(packet_handler); 597 hci_register_sco_packet_handler(&packet_handler); 598 599 sdp_init(); 600 memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer)); 601 hfp_hf_create_sdp_record(hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_hf_service_name, hf_supported_features, wide_band_speech); 602 printf("SDP service record size: %u\n", de_get_len(hfp_service_buffer)); 603 sdp_register_service(hfp_service_buffer); 604 605 #ifdef HAVE_BTSTACK_STDIN 606 // parse human readable Bluetooth address 607 sscanf_bd_addr(device_addr_string, device_addr); 608 btstack_stdin_setup(stdin_process); 609 #endif 610 // turn on! 611 hci_power_control(HCI_POWER_ON); 612 return 0; 613 } 614 /* LISTING_END */ 615 /* EXAMPLE_END */ 616