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