xref: /btstack/example/hfp_ag_demo.c (revision 17ae5bc4f48b8b6c46a2a11fb6395ec461fe225d)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 #define __BTSTACK_FILE__ "hfp_ag_demo.c"
39 
40 /*
41  * hfp_ag_demo.c
42  */
43 
44 // *****************************************************************************
45 /* EXAMPLE_START(hfp_ag_demo): HFP Audio Gateway (AG) Demo
46  *
47  * @text This HFP Audio Gateway example demonstrates how to receive
48  * an output from a remote HFP Hands-Free (HF) unit, and,
49  * if HAVE_BTSTACK_STDIN is defined, how to control the HFP HF.
50  */
51 // *****************************************************************************
52 
53 
54 #include <stdint.h>
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <string.h>
58 
59 #include "btstack.h"
60 #include "sco_demo_util.h"
61 #ifdef HAVE_BTSTACK_STDIN
62 #include "btstack_stdin.h"
63 #endif
64 
65 uint8_t hfp_service_buffer[150];
66 const uint8_t    rfcomm_channel_nr = 1;
67 const char hfp_ag_service_name[] = "BTstack HFP AG Test";
68 
69 static bd_addr_t device_addr;
70 static const char * device_addr_string = "00:15:83:5F:9D:46";
71 
72 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH
73 static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC};
74 #else
75 static uint8_t codecs[] = {HFP_CODEC_CVSD};
76 #endif
77 
78 static uint8_t negotiated_codec = HFP_CODEC_CVSD;
79 
80 static hci_con_handle_t acl_handle = -1;
81 static hci_con_handle_t sco_handle;
82 static int memory_1_enabled = 1;
83 static btstack_packet_callback_registration_t hci_event_callback_registration;
84 
85 static int ag_indicators_nr = 7;
86 static hfp_ag_indicator_t ag_indicators[] = {
87     // index, name, min range, max range, status, mandatory, enabled, status changed
88     {1, "service",   0, 1, 1, 0, 0, 0},
89     {2, "call",      0, 1, 0, 1, 1, 0},
90     {3, "callsetup", 0, 3, 0, 1, 1, 0},
91     {4, "battchg",   0, 5, 3, 0, 0, 0},
92     {5, "signal",    0, 5, 5, 0, 1, 0},
93     {6, "roam",      0, 1, 0, 0, 1, 0},
94     {7, "callheld",  0, 2, 0, 1, 1, 0}
95 };
96 
97 static int call_hold_services_nr = 5;
98 static const char* call_hold_services[] = {"1", "1x", "2", "2x", "3"};
99 
100 static int hf_indicators_nr = 2;
101 static hfp_generic_status_indicator_t hf_indicators[] = {
102     {1, 1},
103     {2, 1},
104 };
105 
106 #define INQUIRY_INTERVAL 5
107 
108 enum STATE {INIT, W4_INQUIRY_MODE_COMPLETE, ACTIVE} ;
109 enum STATE state = INIT;
110 
111 static void dump_supported_codecs(void){
112     unsigned int i;
113     int mSBC_skipped = 0;
114     printf("Supported codecs: ");
115     for (i = 0; i < sizeof(codecs); i++){
116         switch(codecs[i]){
117             case HFP_CODEC_CVSD:
118                 printf("CVSD");
119                 break;
120             case HFP_CODEC_MSBC:
121                 if (hci_extended_sco_link_supported()){
122                     printf(", mSBC");
123                 } else {
124                     mSBC_skipped = 1;
125                 }
126                 break;
127         }
128     }
129     printf("\n");
130     if (mSBC_skipped){
131         printf("mSBC codec disabled because eSCO not supported by local controller.\n");
132     }
133 }
134 
135 #ifdef HAVE_BTSTACK_STDIN
136 // Testig User Interface
137 static void show_usage(void){
138     bd_addr_t iut_address;
139     gap_local_bd_addr(iut_address);
140 
141     printf("\n--- Bluetooth HFP Audiogateway (AG) unit Test Console %s ---\n", bd_addr_to_str(iut_address));
142     printf("\n");
143 
144     printf("a - establish HFP connection to PTS module %s\n", bd_addr_to_str(device_addr));
145     // printf("A - release HFP connection to PTS module\n");
146 
147     printf("b - establish AUDIO connection          | B - release AUDIO connection\n");
148     printf("c - simulate incoming call from 1234567 | C - simulate call from 1234567 dropped\n");
149     printf("d - report AG failure\n");
150     printf("e - answer call on AG                   | E - reject call on AG\n");
151     printf("r - disable in-band ring tone           | R - enable in-band ring tone\n");
152     printf("f - Disable cellular network            | F - Enable cellular network\n");
153     printf("g - Set signal strength to 0            | G - Set signal strength to 5\n");
154     printf("h - Disable roaming                     | H - Enable roaming\n");
155     printf("i - Set battery level to 3              | I - Set battery level to 5\n");
156     printf("j - Answering call on remote side\n");
157     printf("k - Clear memory #1                     | K - Set memory #1\n");
158     printf("l - Clear last number                   | L - Set last number\n");
159     printf("m - simulate incoming call from 7654321\n");
160     // printf("M - simulate call from 7654321 dropped\n");
161     printf("n - Disable Voice Regocnition           | N - Enable Voice Recognition\n");
162     printf("o - Set speaker volume to 0  (minimum)  | O - Set speaker volume to 9  (default)\n");
163     printf("p - Set speaker volume to 12 (higher)   | P - Set speaker volume to 15 (maximum)\n");
164     printf("q - Set microphone gain to 0  (minimum) | Q - Set microphone gain to 9  (default)\n");
165     printf("s - Set microphone gain to 12 (higher)  | S - Set microphone gain to 15 (maximum)\n");
166     printf("t - terminate connection\n");
167     printf("u - join held call\n");
168     printf("v - discover nearby HF units\n");
169     printf("w - put incoming call on hold (Response and Hold)\n");
170     printf("x - accept held incoming call (Response and Hold)\n");
171     printf("X - reject held incoming call (Response and Hold)\n");
172     printf("---\n");
173 }
174 
175 static void stdin_process(char cmd){
176     switch (cmd){
177         case 'a':
178             log_info("USER:\'%c\'", cmd);
179             printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr));
180             hfp_ag_establish_service_level_connection(device_addr);
181             break;
182         case 'A':
183             log_info("USER:\'%c\'", cmd);
184             printf("Release HFP service level connection.\n");
185             hfp_ag_release_service_level_connection(acl_handle);
186             break;
187         case 'Z':
188             log_info("USER:\'%c\'", cmd);
189             printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr));
190             hfp_ag_release_service_level_connection(acl_handle);
191             break;
192         case 'b':
193             log_info("USER:\'%c\'", cmd);
194             printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr));
195             hfp_ag_establish_audio_connection(acl_handle);
196             break;
197         case 'B':
198             log_info("USER:\'%c\'", cmd);
199             printf("Release Audio connection.\n");
200             hfp_ag_release_audio_connection(acl_handle);
201             break;
202         case 'c':
203             log_info("USER:\'%c\'", cmd);
204             printf("Simulate incoming call from 1234567\n");
205             hfp_ag_set_clip(129, "1234567");
206             hfp_ag_incoming_call();
207             break;
208         case 'm':
209             log_info("USER:\'%c\'", cmd);
210             printf("Simulate incoming call from 7654321\n");
211             hfp_ag_set_clip(129, "7654321");
212             hfp_ag_incoming_call();
213             break;
214         case 'C':
215             log_info("USER:\'%c\'", cmd);
216             printf("Simulate terminate call\n");
217             hfp_ag_call_dropped();
218             break;
219         case 'd':
220             log_info("USER:\'%c\'", cmd);
221             printf("Report AG failure\n");
222             hfp_ag_report_extended_audio_gateway_error_result_code(acl_handle, HFP_CME_ERROR_AG_FAILURE);
223             break;
224         case 'e':
225             log_info("USER:\'%c\'", cmd);
226             printf("Answer call on AG\n");
227             hfp_ag_answer_incoming_call();
228             break;
229         case 'E':
230             log_info("USER:\'%c\'", cmd);
231             printf("Reject call on AG\n");
232             hfp_ag_terminate_call();
233             break;
234         case 'f':
235             log_info("USER:\'%c\'", cmd);
236             printf("Disable cellular network\n");
237             hfp_ag_set_registration_status(0);
238             break;
239         case 'F':
240             log_info("USER:\'%c\'", cmd);
241             printf("Enable cellular network\n");
242             hfp_ag_set_registration_status(1);
243             break;
244         case 'g':
245             log_info("USER:\'%c\'", cmd);
246             printf("Set signal strength to 0\n");
247             hfp_ag_set_signal_strength(0);
248             break;
249         case 'G':
250             log_info("USER:\'%c\'", cmd);
251             printf("Set signal strength to 5\n");
252             hfp_ag_set_signal_strength(5);
253             break;
254         case 'h':
255             log_info("USER:\'%c\'", cmd);
256             printf("Disable roaming\n");
257             hfp_ag_set_roaming_status(0);
258             break;
259         case 'H':
260             log_info("USER:\'%c\'", cmd);
261             printf("Enable roaming\n");
262             hfp_ag_set_roaming_status(1);
263             break;
264         case 'i':
265             log_info("USER:\'%c\'", cmd);
266             printf("Set battery level to 3\n");
267             hfp_ag_set_battery_level(3);
268             break;
269         case 'I':
270             log_info("USER:\'%c\'", cmd);
271             printf("Set battery level to 5\n");
272             hfp_ag_set_battery_level(5);
273             break;
274         case 'j':
275             log_info("USER:\'%c\'", cmd);
276             printf("Answering call on remote side\n");
277             hfp_ag_outgoing_call_established();
278             break;
279         case 'r':
280             log_info("USER:\'%c\'", cmd);
281             printf("Disable in-band ring tone\n");
282             hfp_ag_set_use_in_band_ring_tone(0);
283             break;
284         case 'k':
285             log_info("USER:\'%c\'", cmd);
286             printf("Memory 1 cleared\n");
287             memory_1_enabled = 0;
288             break;
289         case 'K':
290             log_info("USER:\'%c\'", cmd);
291             printf("Memory 1 set\n");
292             memory_1_enabled = 1;
293             break;
294         case 'l':
295             log_info("USER:\'%c\'", cmd);
296             printf("Last dialed number cleared\n");
297             hfp_ag_clear_last_dialed_number();
298             break;
299         case 'L':
300             log_info("USER:\'%c\'", cmd);
301             printf("Outgoing call connected, ringing\n");
302             hfp_ag_outgoing_call_ringing();
303             break;
304         case 'n':
305             log_info("USER:\'%c\'", cmd);
306             printf("Disable Voice Recognition\n");
307             hfp_ag_activate_voice_recognition(acl_handle, 0);
308             break;
309         case 'N':
310             log_info("USER:\'%c\'", cmd);
311             printf("Enable Voice Recognition\n");
312             hfp_ag_activate_voice_recognition(acl_handle, 1);
313             break;
314         case 'o':
315             log_info("USER:\'%c\'", cmd);
316             printf("Set speaker gain to 0 (minimum)\n");
317             hfp_ag_set_speaker_gain(acl_handle, 0);
318             break;
319         case 'O':
320             log_info("USER:\'%c\'", cmd);
321             printf("Set speaker gain to 9 (default)\n");
322             hfp_ag_set_speaker_gain(acl_handle, 9);
323             break;
324         case 'p':
325             log_info("USER:\'%c\'", cmd);
326             printf("Set speaker gain to 12 (higher)\n");
327             hfp_ag_set_speaker_gain(acl_handle, 12);
328             break;
329         case 'P':
330             log_info("USER:\'%c\'", cmd);
331             printf("Set speaker gain to 15 (maximum)\n");
332             hfp_ag_set_speaker_gain(acl_handle, 15);
333             break;
334         case 'q':
335             log_info("USER:\'%c\'", cmd);
336             printf("Set microphone gain to 0\n");
337             hfp_ag_set_microphone_gain(acl_handle, 0);
338             break;
339         case 'Q':
340             log_info("USER:\'%c\'", cmd);
341             printf("Set microphone gain to 9\n");
342             hfp_ag_set_microphone_gain(acl_handle, 9);
343             break;
344         case 's':
345             log_info("USER:\'%c\'", cmd);
346             printf("Set microphone gain to 12\n");
347             hfp_ag_set_microphone_gain(acl_handle, 12);
348             break;
349         case 'S':
350             log_info("USER:\'%c\'", cmd);
351             printf("Set microphone gain to 15\n");
352             hfp_ag_set_microphone_gain(acl_handle, 15);
353             break;
354         case 'R':
355             log_info("USER:\'%c\'", cmd);
356             printf("Enable in-band ring tone\n");
357             hfp_ag_set_use_in_band_ring_tone(1);
358             break;
359         case 't':
360             log_info("USER:\'%c\'", cmd);
361             printf("Terminate HCI connection. 0x%2x\n", acl_handle);
362             gap_disconnect(acl_handle);
363             break;
364         case 'u':
365             log_info("USER:\'%c\'", cmd);
366             printf("Join held call\n");
367             hfp_ag_join_held_call();
368             break;
369         case 'v':
370             printf("Start scanning...\n");
371             gap_inquiry_start(INQUIRY_INTERVAL);
372             break;
373         case 'w':
374             log_info("USER:\'%c\'", cmd);
375             printf("AG: Put incoming call on hold (Response and Hold)\n");
376             hfp_ag_hold_incoming_call();
377             break;
378         case 'x':
379             log_info("USER:\'%c\'", cmd);
380             printf("AG: Accept held incoming call (Response and Hold)\n");
381             hfp_ag_accept_held_incoming_call();
382             break;
383         case 'X':
384             log_info("USER:\'%c\'", cmd);
385             printf("AG: Reject held incoming call (Response and Hold)\n");
386             hfp_ag_reject_held_incoming_call();
387             break;
388         default:
389             show_usage();
390             break;
391     }
392 }
393 #endif
394 
395 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
396     UNUSED(channel);
397     bd_addr_t addr;
398     switch (packet_type){
399         case HCI_EVENT_PACKET:
400             switch (event[0]){
401                 case GAP_EVENT_INQUIRY_RESULT:
402                     gap_event_inquiry_result_get_bd_addr(event, addr);
403                     // print info
404                     printf("Device found: %s ",  bd_addr_to_str(addr));
405                     printf("with COD: 0x%06x, ", (unsigned int) gap_event_inquiry_result_get_class_of_device(event));
406                     if (gap_event_inquiry_result_get_rssi_available(event)){
407                         printf(", rssi %d dBm", (int8_t) gap_event_inquiry_result_get_rssi(event));
408                     }
409                     if (gap_event_inquiry_result_get_name_available(event)){
410                         char name_buffer[240];
411                         int name_len = gap_event_inquiry_result_get_name_len(event);
412                         memcpy(name_buffer, gap_event_inquiry_result_get_name(event), name_len);
413                         name_buffer[name_len] = 0;
414                         printf(", name '%s'", name_buffer);
415                     }
416                     printf("\n");
417                     break;
418                 case GAP_EVENT_INQUIRY_COMPLETE:
419                     printf("Inquiry scan complete.\n");
420                     break;
421                 case HCI_EVENT_SCO_CAN_SEND_NOW:
422                     sco_demo_send(sco_handle);
423                     break;
424                 case HCI_EVENT_COMMAND_COMPLETE:
425                     if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){
426                         dump_supported_codecs();
427                     }
428                     break;
429                 default:
430                     break;
431             }
432 
433             if (event[0] != HCI_EVENT_HFP_META) return;
434 
435             if (event[3]
436                 && event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
437                 && event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG
438                 && event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){
439                 printf("ERROR, status: %u\n", event[3]);
440                 return;
441             }
442 
443             switch (event[2]) {
444                 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
445                     acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
446                     hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr);
447                     printf("Service level connection established from %s.\n", bd_addr_to_str(device_addr));
448                     dump_supported_codecs();
449                    break;
450                 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
451                     printf("Service level connection released.\n");
452                     sco_handle = 0;
453                     break;
454                 case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
455                     if (hfp_subevent_audio_connection_established_get_status(event)){
456                         printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
457                         sco_handle = 0;
458                     } else {
459                         sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
460                         printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
461                         negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event);
462                         switch (negotiated_codec){
463                             case 0x01:
464                                 printf("Using CVSD codec.\n");
465                                 break;
466                             case 0x02:
467                                 printf("Using mSBC codec.\n");
468                                 break;
469                             default:
470                                 printf("Using unknown codec 0x%02x.\n", negotiated_codec);
471                                 break;
472                         }
473                         sco_demo_set_codec(negotiated_codec);
474                         hci_request_sco_can_send_now_event();
475                     }
476                     break;
477                 case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
478                     printf("Audio connection released\n");
479                     sco_handle = 0;
480                     sco_demo_close();
481                     break;
482                 case HFP_SUBEVENT_START_RINGINIG:
483                     printf("Start Ringing\n");
484                     break;
485                 case HFP_SUBEVENT_STOP_RINGINIG:
486                     printf("Stop Ringing\n");
487                     break;
488                 case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER:
489                     printf("Outgoing call '%s'\n", hfp_subevent_place_call_with_number_get_number(event));
490                     // validate number
491                     if ( strcmp("1234567", hfp_subevent_place_call_with_number_get_number(event)) == 0
492                       || strcmp("7654321", hfp_subevent_place_call_with_number_get_number(event)) == 0
493                       || (memory_1_enabled && strcmp(">1", hfp_subevent_place_call_with_number_get_number(event)) == 0)){
494                         printf("Dialstring valid: accept call\n");
495                         hfp_ag_outgoing_call_accepted();
496                     } else {
497                         printf("Dialstring invalid: reject call\n");
498                         hfp_ag_outgoing_call_rejected();
499                     }
500                     break;
501 
502                 case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
503                     printf("Attach number to voice tag. Sending '1234567\n");
504                     hfp_ag_send_phone_number_for_voice_tag(acl_handle, "1234567");
505                     break;
506                 case HFP_SUBEVENT_TRANSMIT_DTMF_CODES:
507                     printf("Send DTMF Codes: '%s'\n", hfp_subevent_transmit_dtmf_codes_get_dtmf(event));
508                     hfp_ag_send_dtmf_code_done(acl_handle);
509                     break;
510                 case HFP_SUBEVENT_CALL_ANSWERED:
511                     printf("Call answered by HF\n");
512                     break;
513                 default:
514                     printf("Event not handled %u\n", event[2]);
515                     break;
516             }
517             break;
518         case HCI_SCO_DATA_PACKET:
519             sco_demo_receive(event, event_size);
520             break;
521         default:
522             break;
523     }
524 }
525 
526 static hfp_phone_number_t subscriber_number = {
527     129, "225577"
528 };
529 
530 /* @section Main Application Setup
531  *
532  * @text Listing MainConfiguration shows main application code.
533  * To run a HFP AG service you need to initialize the SDP, and to create and register HFP AG record with it.
534  * The packet_handler is used for sending commands to the HFP HF. It also receives the HFP HF's answers.
535  * The stdin_process callback allows for sending commands to the HFP HF.
536  * At the end the Bluetooth stack is started.
537  */
538 
539 /* LISTING_START(MainConfiguration): Setup HFP Audio Gateway */
540 
541 int btstack_main(int argc, const char * argv[]);
542 int btstack_main(int argc, const char * argv[]){
543     (void)argc;
544     (void)argv;
545 
546     sco_demo_init();
547 
548     // register for HCI events
549     hci_event_callback_registration.callback = &packet_handler;
550     hci_add_event_handler(&hci_event_callback_registration);
551     hci_register_sco_packet_handler(&packet_handler);
552 
553     gap_discoverable_control(1);
554 
555     // L2CAP
556     l2cap_init();
557 
558     uint16_t supported_features                   =
559         (1<<HFP_AGSF_ESCO_S4)                     |
560         (1<<HFP_AGSF_HF_INDICATORS)               |
561         (1<<HFP_AGSF_CODEC_NEGOTIATION)           |
562         (1<<HFP_AGSF_EXTENDED_ERROR_RESULT_CODES) |
563         (1<<HFP_AGSF_ENHANCED_CALL_CONTROL)       |
564         (1<<HFP_AGSF_ENHANCED_CALL_STATUS)        |
565         (1<<HFP_AGSF_ABILITY_TO_REJECT_A_CALL)    |
566         (1<<HFP_AGSF_IN_BAND_RING_TONE)           |
567         (1<<HFP_AGSF_VOICE_RECOGNITION_FUNCTION)  |
568         (1<<HFP_AGSF_THREE_WAY_CALLING);
569     int wide_band_speech = 1;
570 
571     // HFP
572     rfcomm_init();
573     hfp_ag_init(rfcomm_channel_nr);
574     hfp_ag_init_supported_features(supported_features);
575     hfp_ag_init_codecs(sizeof(codecs), codecs);
576     hfp_ag_init_ag_indicators(ag_indicators_nr, ag_indicators);
577     hfp_ag_init_hf_indicators(hf_indicators_nr, hf_indicators);
578     hfp_ag_init_call_hold_services(call_hold_services_nr, call_hold_services);
579     hfp_ag_set_subcriber_number_information(&subscriber_number, 1);
580     hfp_ag_register_packet_handler(&packet_handler);
581     hci_register_sco_packet_handler(&packet_handler);
582 
583     // SDP Server
584     sdp_init();
585     memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer));
586     hfp_ag_create_sdp_record( hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_ag_service_name, 0, supported_features, wide_band_speech);
587     printf("SDP service record size: %u\n", de_get_len( hfp_service_buffer));
588     sdp_register_service(hfp_service_buffer);
589 
590     // parse humand readable Bluetooth address
591     sscanf_bd_addr(device_addr_string, device_addr);
592 
593 #ifdef HAVE_BTSTACK_STDIN
594     btstack_stdin_setup(stdin_process);
595 #endif
596     // turn on!
597     hci_power_control(HCI_POWER_ON);
598     return 0;
599 }
600 /* LISTING_END */
601 /* EXAMPLE_END */
602