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[] = "HFP HF Demo"; 68 69 #ifdef HAVE_BTSTACK_STDIN 70 static const char * device_addr_string = "6C:72:E7:10:22:EE"; 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 = HCI_CON_HANDLE_INVALID; 81 static hci_con_handle_t sco_handle = HCI_CON_HANDLE_INVALID; 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 unsigned 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 } 157 158 static void stdin_process(char c){ 159 cmd = c; // used in packet handler 160 161 if (cmd >= '0' && cmd <= '9'){ 162 printf("DTMF Code: %c\n", cmd); 163 hfp_hf_send_dtmf_code(acl_handle, cmd); 164 return; 165 } 166 167 switch (cmd){ 168 case '#': 169 case '-': 170 case '+': 171 case '*': 172 log_info("USER:\'%c\'", cmd); 173 printf("DTMF Code: %c\n", cmd); 174 hfp_hf_send_dtmf_code(acl_handle, cmd); 175 break; 176 case 'a': 177 log_info("USER:\'%c\'", cmd); 178 printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 179 hfp_hf_establish_service_level_connection(device_addr); 180 break; 181 case 'A': 182 log_info("USER:\'%c\'", cmd); 183 printf("Release Service level connection.\n"); 184 hfp_hf_release_service_level_connection(acl_handle); 185 break; 186 case 'b': 187 log_info("USER:\'%c\'", cmd); 188 printf("Establish Audio connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 189 hfp_hf_establish_audio_connection(acl_handle); 190 break; 191 case 'B': 192 log_info("USER:\'%c\'", cmd); 193 printf("Release Audio service level connection.\n"); 194 hfp_hf_release_audio_connection(acl_handle); 195 break; 196 case 'C': 197 log_info("USER:\'%c\'", cmd); 198 printf("Enable registration status update for all AG indicators.\n"); 199 hfp_hf_enable_status_update_for_all_ag_indicators(acl_handle); 200 break; 201 case 'c': 202 log_info("USER:\'%c\'", cmd); 203 printf("Disable registration status update for all AG indicators.\n"); 204 hfp_hf_disable_status_update_for_all_ag_indicators(acl_handle); 205 break; 206 case 'D': 207 log_info("USER:\'%c\'", cmd); 208 printf("Set HFP AG registration status update for individual indicators (0111111).\n"); 209 hfp_hf_set_status_update_for_individual_ag_indicators(acl_handle, 63); 210 break; 211 case 'd': 212 log_info("USER:\'%c\'", cmd); 213 printf("Query network operator.\n"); 214 hfp_hf_query_operator_selection(acl_handle); 215 break; 216 case 'E': 217 log_info("USER:\'%c\'", cmd); 218 printf("Enable reporting of the extended AG error result code.\n"); 219 hfp_hf_enable_report_extended_audio_gateway_error_result_code(acl_handle); 220 break; 221 case 'e': 222 log_info("USER:\'%c\'", cmd); 223 printf("Disable reporting of the extended AG error result code.\n"); 224 hfp_hf_disable_report_extended_audio_gateway_error_result_code(acl_handle); 225 break; 226 case 'f': 227 log_info("USER:\'%c\'", cmd); 228 printf("Answer incoming call.\n"); 229 hfp_hf_answer_incoming_call(acl_handle); 230 break; 231 case 'F': 232 log_info("USER:\'%c\'", cmd); 233 printf("Hangup call.\n"); 234 hfp_hf_terminate_call(acl_handle); 235 break; 236 case 'G': 237 log_info("USER:\'%c\'", cmd); 238 printf("Reject incoming call.\n"); 239 hfp_hf_reject_incoming_call(acl_handle); 240 break; 241 case 'g': 242 log_info("USER:\'%c\'", cmd); 243 printf("Query operator.\n"); 244 hfp_hf_query_operator_selection(acl_handle); 245 break; 246 case 't': 247 log_info("USER:\'%c\'", cmd); 248 printf("Terminate HCI connection.\n"); 249 gap_disconnect(acl_handle); 250 break; 251 case 'i': 252 log_info("USER:\'%c\'", cmd); 253 printf("Dial 1234567\n"); 254 hfp_hf_dial_number(acl_handle, "1234567"); 255 break; 256 case 'I': 257 log_info("USER:\'%c\'", cmd); 258 printf("Dial 7654321\n"); 259 hfp_hf_dial_number(acl_handle, "7654321"); 260 break; 261 case 'j': 262 log_info("USER:\'%c\'", cmd); 263 printf("Dial #1\n"); 264 hfp_hf_dial_memory(acl_handle,1); 265 break; 266 case 'J': 267 log_info("USER:\'%c\'", cmd); 268 printf("Dial #99\n"); 269 hfp_hf_dial_memory(acl_handle,99); 270 break; 271 case 'k': 272 log_info("USER:\'%c\'", cmd); 273 printf("Deactivate call waiting notification\n"); 274 hfp_hf_deactivate_call_waiting_notification(acl_handle); 275 break; 276 case 'K': 277 log_info("USER:\'%c\'", cmd); 278 printf("Activate call waiting notification\n"); 279 hfp_hf_activate_call_waiting_notification(acl_handle); 280 break; 281 case 'l': 282 log_info("USER:\'%c\'", cmd); 283 printf("Deactivate calling line notification\n"); 284 hfp_hf_deactivate_calling_line_notification(acl_handle); 285 break; 286 case 'L': 287 log_info("USER:\'%c\'", cmd); 288 printf("Activate calling line notification\n"); 289 hfp_hf_activate_calling_line_notification(acl_handle); 290 break; 291 case 'm': 292 log_info("USER:\'%c\'", cmd); 293 printf("Deactivate echo canceling and noise reduction\n"); 294 hfp_hf_deactivate_echo_canceling_and_noise_reduction(acl_handle); 295 break; 296 case 'M': 297 log_info("USER:\'%c\'", cmd); 298 printf("Activate echo canceling and noise reduction\n"); 299 hfp_hf_activate_echo_canceling_and_noise_reduction(acl_handle); 300 break; 301 case 'n': 302 log_info("USER:\'%c\'", cmd); 303 printf("Deactivate voice recognition\n"); 304 hfp_hf_deactivate_voice_recognition_notification(acl_handle); 305 break; 306 case 'N': 307 log_info("USER:\'%c\'", cmd); 308 printf("Activate voice recognition %s\n", bd_addr_to_str(device_addr)); 309 hfp_hf_activate_voice_recognition_notification(acl_handle); 310 break; 311 case 'o': 312 log_info("USER:\'%c\'", cmd); 313 printf("Set speaker gain to 0 (minimum)\n"); 314 hfp_hf_set_speaker_gain(acl_handle, 0); 315 break; 316 case 'O': 317 log_info("USER:\'%c\'", cmd); 318 printf("Set speaker gain to 9 (default)\n"); 319 hfp_hf_set_speaker_gain(acl_handle, 9); 320 break; 321 case 'p': 322 log_info("USER:\'%c\'", cmd); 323 printf("Set speaker gain to 12 (higher)\n"); 324 hfp_hf_set_speaker_gain(acl_handle, 12); 325 break; 326 case 'P': 327 log_info("USER:\'%c\'", cmd); 328 printf("Set speaker gain to 15 (maximum)\n"); 329 hfp_hf_set_speaker_gain(acl_handle, 15); 330 break; 331 case 'q': 332 log_info("USER:\'%c\'", cmd); 333 printf("Set microphone gain to 0\n"); 334 hfp_hf_set_microphone_gain(acl_handle, 0); 335 break; 336 case 'Q': 337 log_info("USER:\'%c\'", cmd); 338 printf("Set microphone gain to 9\n"); 339 hfp_hf_set_microphone_gain(acl_handle, 9); 340 break; 341 case 's': 342 log_info("USER:\'%c\'", cmd); 343 printf("Set microphone gain to 12\n"); 344 hfp_hf_set_microphone_gain(acl_handle, 12); 345 break; 346 case 'S': 347 log_info("USER:\'%c\'", cmd); 348 printf("Set microphone gain to 15\n"); 349 hfp_hf_set_microphone_gain(acl_handle, 15); 350 break; 351 case 'u': 352 log_info("USER:\'%c\'", cmd); 353 printf("Send 'user busy' (Three-Way Call 0)\n"); 354 hfp_hf_user_busy(acl_handle); 355 break; 356 case 'U': 357 log_info("USER:\'%c\'", cmd); 358 printf("End active call and accept waiting/held call (Three-Way Call 1)\n"); 359 hfp_hf_end_active_and_accept_other(acl_handle); 360 break; 361 case 'v': 362 log_info("USER:\'%c\'", cmd); 363 printf("Swap active call and hold/waiting call (Three-Way Call 2)\n"); 364 hfp_hf_swap_calls(acl_handle); 365 break; 366 case 'V': 367 log_info("USER:\'%c\'", cmd); 368 printf("Join hold call (Three-Way Call 3)\n"); 369 hfp_hf_join_held_call(acl_handle); 370 break; 371 case 'w': 372 log_info("USER:\'%c\'", cmd); 373 printf("Connect calls (Three-Way Call 4)\n"); 374 hfp_hf_connect_calls(acl_handle); 375 break; 376 case 'W': 377 log_info("USER:\'%c\'", cmd); 378 printf("Redial\n"); 379 hfp_hf_redial_last_number(acl_handle); 380 break; 381 case 'x': 382 log_info("USER:\'%c\'", cmd); 383 printf("Request phone number for voice tag\n"); 384 hfp_hf_request_phone_number_for_voice_tag(acl_handle); 385 break; 386 case 'X': 387 log_info("USER:\'%c\'", cmd); 388 printf("Query current call status\n"); 389 hfp_hf_query_current_call_status(acl_handle); 390 break; 391 case 'y': 392 log_info("USER:\'%c\'", cmd); 393 printf("Release call with index 2\n"); 394 hfp_hf_release_call_with_index(acl_handle, 2); 395 break; 396 case 'Y': 397 log_info("USER:\'%c\'", cmd); 398 printf("Private consulation with call 2\n"); 399 hfp_hf_private_consultation_with_call(acl_handle, 2); 400 break; 401 case '[': 402 log_info("USER:\'%c\'", cmd); 403 printf("Query Response and Hold status (RHH ?)\n"); 404 hfp_hf_rrh_query_status(acl_handle); 405 break; 406 case ']': 407 log_info("USER:\'%c\'", cmd); 408 printf("Place call in a response and held state (RHH 0)\n"); 409 hfp_hf_rrh_hold_call(acl_handle); 410 break; 411 case '{': 412 log_info("USER:\'%c\'", cmd); 413 printf("Accept held call (RHH 1)\n"); 414 hfp_hf_rrh_accept_held_call(acl_handle); 415 break; 416 case '}': 417 log_info("USER:\'%c\'", cmd); 418 printf("Reject held call (RHH 2)\n"); 419 hfp_hf_rrh_reject_held_call(acl_handle); 420 break; 421 case '?': 422 log_info("USER:\'%c\'", cmd); 423 printf("Query Subscriber Number\n"); 424 hfp_hf_query_subscriber_number(acl_handle); 425 break; 426 case '!': 427 log_info("USER:\'%c\'", cmd); 428 printf("Update HF indicator with assigned number 1 (HFI)\n"); 429 hfp_hf_set_hf_indicator(acl_handle, 1, 1); 430 break; 431 default: 432 show_usage(); 433 break; 434 } 435 } 436 #endif 437 438 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){ 439 UNUSED(channel); 440 441 switch (packet_type){ 442 443 case HCI_SCO_DATA_PACKET: 444 if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break; 445 sco_demo_receive(event, event_size); 446 break; 447 448 case HCI_EVENT_PACKET: 449 switch (event[0]){ 450 case HCI_EVENT_SCO_CAN_SEND_NOW: 451 sco_demo_send(sco_handle); 452 break; 453 454 case HCI_EVENT_COMMAND_COMPLETE: 455 if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){ 456 dump_supported_codecs(); 457 } 458 break; 459 460 case HCI_EVENT_HFP_META: 461 switch (event[2]) { 462 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: 463 acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event); 464 hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr); 465 printf("Service level connection established %s.\n\n", bd_addr_to_str(device_addr)); 466 break; 467 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: 468 acl_handle = HCI_CON_HANDLE_INVALID; 469 printf("Service level connection released.\n\n"); 470 break; 471 case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED: 472 if (hfp_subevent_audio_connection_established_get_status(event)){ 473 printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event)); 474 } else { 475 sco_handle = hfp_subevent_audio_connection_established_get_handle(event); 476 printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 477 negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event); 478 switch (negotiated_codec){ 479 case 0x01: 480 printf("Using CVSD codec.\n"); 481 break; 482 case 0x02: 483 printf("Using mSBC codec.\n"); 484 break; 485 default: 486 printf("Using unknown codec 0x%02x.\n", negotiated_codec); 487 break; 488 } 489 sco_demo_set_codec(negotiated_codec); 490 hci_request_sco_can_send_now_event(); 491 } 492 break; 493 case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: 494 sco_handle = HCI_CON_HANDLE_INVALID; 495 printf("Audio connection released\n"); 496 sco_demo_close(); 497 break; 498 case HFP_SUBEVENT_COMPLETE: 499 switch (cmd){ 500 case 'd': 501 printf("HFP AG registration status update enabled.\n"); 502 break; 503 case 'e': 504 printf("HFP AG registration status update for individual indicators set.\n"); 505 break; 506 default: 507 break; 508 } 509 break; 510 case HFP_SUBEVENT_AG_INDICATOR_STATUS_CHANGED: 511 printf("AG_INDICATOR_STATUS_CHANGED, AG indicator (index: %d) to: %d of range [%d, %d], name '%s'\n", 512 hfp_subevent_ag_indicator_status_changed_get_indicator_index(event), 513 hfp_subevent_ag_indicator_status_changed_get_indicator_status(event), 514 hfp_subevent_ag_indicator_status_changed_get_indicator_min_range(event), 515 hfp_subevent_ag_indicator_status_changed_get_indicator_max_range(event), 516 (const char*) hfp_subevent_ag_indicator_status_changed_get_indicator_name(event)); 517 break; 518 case HFP_SUBEVENT_NETWORK_OPERATOR_CHANGED: 519 printf("NETWORK_OPERATOR_CHANGED, operator mode: %d, format: %d, name: %s\n", 520 hfp_subevent_network_operator_changed_get_network_operator_mode(event), 521 hfp_subevent_network_operator_changed_get_network_operator_format(event), 522 (char *) hfp_subevent_network_operator_changed_get_network_operator_name(event)); 523 break; 524 case HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR: 525 printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : %d\n", 526 hfp_subevent_extended_audio_gateway_error_get_error(event)); 527 break; 528 case HFP_SUBEVENT_RING: 529 printf("** Ring **\n"); 530 break; 531 case HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG: 532 printf("Phone number for voice tag: %s\n", 533 (const char *) hfp_subevent_number_for_voice_tag_get_number(event)); 534 break; 535 case HFP_SUBEVENT_SPEAKER_VOLUME: 536 printf("Speaker volume: status %u, gain %u\n", 537 hfp_subevent_speaker_volume_get_status(event), 538 hfp_subevent_speaker_volume_get_gain(event)); 539 break; 540 case HFP_SUBEVENT_MICROPHONE_VOLUME: 541 printf("Microphone volume: status %u, gain %u\n", 542 hfp_subevent_microphone_volume_get_status(event), 543 hfp_subevent_microphone_volume_get_gain(event)); 544 break; 545 case HFP_SUBEVENT_CALLING_LINE_IDENTIFICATION_NOTIFICATION: 546 printf("Caller ID, number %s\n", hfp_subevent_calling_line_identification_notification_get_number(event)); 547 break; 548 default: 549 printf("event not handled %u\n", event[2]); 550 break; 551 } 552 break; 553 554 default: 555 break; 556 } 557 break; 558 559 default: 560 break; 561 } 562 563 } 564 565 /* @section Main Application Setup 566 * 567 * @text Listing MainConfiguration shows main application code. 568 * To run a HFP HF service you need to initialize the SDP, and to create and register HFP HF record with it. 569 * The packet_handler is used for sending commands to the HFP AG. It also receives the HFP AG's answers. 570 * The stdin_process callback allows for sending commands to the HFP AG. 571 * At the end the Bluetooth stack is started. 572 */ 573 574 /* LISTING_START(MainConfiguration): Setup HFP Hands-Free unit */ 575 int btstack_main(int argc, const char * argv[]); 576 int btstack_main(int argc, const char * argv[]){ 577 (void)argc; 578 (void)argv; 579 580 sco_demo_init(); 581 582 gap_discoverable_control(1); 583 gap_set_class_of_device(0x200408); 584 gap_set_local_name("HFP HF Demo 00:00:00:00:00:00"); 585 586 // init L2CAP 587 l2cap_init(); 588 589 uint16_t hf_supported_features = 590 (1<<HFP_HFSF_ESCO_S4) | 591 (1<<HFP_HFSF_CLI_PRESENTATION_CAPABILITY) | 592 (1<<HFP_HFSF_HF_INDICATORS) | 593 (1<<HFP_HFSF_CODEC_NEGOTIATION) | 594 (1<<HFP_HFSF_ENHANCED_CALL_STATUS) | 595 (1<<HFP_HFSF_REMOTE_VOLUME_CONTROL); 596 int wide_band_speech = 1; 597 598 rfcomm_init(); 599 hfp_hf_init(rfcomm_channel_nr); 600 hfp_hf_init_supported_features(hf_supported_features); 601 hfp_hf_init_hf_indicators(sizeof(indicators)/sizeof(uint16_t), indicators); 602 hfp_hf_init_codecs(sizeof(codecs), codecs); 603 604 sdp_init(); 605 memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer)); 606 hfp_hf_create_sdp_record(hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_hf_service_name, hf_supported_features, wide_band_speech); 607 printf("SDP service record size: %u\n", de_get_len(hfp_service_buffer)); 608 sdp_register_service(hfp_service_buffer); 609 610 // register for HCI events and SCO packets 611 hci_event_callback_registration.callback = &packet_handler; 612 hci_add_event_handler(&hci_event_callback_registration); 613 hci_register_sco_packet_handler(&packet_handler); 614 hci_register_sco_packet_handler(&packet_handler); 615 616 // register for HFP events 617 hfp_hf_register_packet_handler(packet_handler); 618 619 #ifdef HAVE_BTSTACK_STDIN 620 // parse human readable Bluetooth address 621 sscanf_bd_addr(device_addr_string, device_addr); 622 btstack_stdin_setup(stdin_process); 623 #endif 624 // turn on! 625 hci_power_control(HCI_POWER_ON); 626 return 0; 627 } 628 /* LISTING_END */ 629 /* EXAMPLE_END */ 630