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