xref: /btstack/example/hfp_ag_demo.c (revision de804f9e40fa10b2ead91db28fa5571afa6ec08a)
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     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 
173     printf("---\n");
174     printf("Ctrl-c - exit\n");
175     printf("---\n");
176 }
177 
178 static void stdin_process(char cmd){
179     switch (cmd){
180         case 'a':
181             log_info("USER:\'%c\'", cmd);
182             printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr));
183             hfp_ag_establish_service_level_connection(device_addr);
184             break;
185         case 'A':
186             log_info("USER:\'%c\'", cmd);
187             printf("Release HFP service level connection.\n");
188             hfp_ag_release_service_level_connection(acl_handle);
189             break;
190         case 'Z':
191             log_info("USER:\'%c\'", cmd);
192             printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr));
193             hfp_ag_release_service_level_connection(acl_handle);
194             break;
195         case 'b':
196             log_info("USER:\'%c\'", cmd);
197             printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr));
198             hfp_ag_establish_audio_connection(acl_handle);
199             break;
200         case 'B':
201             log_info("USER:\'%c\'", cmd);
202             printf("Release Audio connection.\n");
203             hfp_ag_release_audio_connection(acl_handle);
204             break;
205         case 'c':
206             log_info("USER:\'%c\'", cmd);
207             printf("Simulate incoming call from 1234567\n");
208             hfp_ag_set_clip(129, "1234567");
209             hfp_ag_incoming_call();
210             break;
211         case 'm':
212             log_info("USER:\'%c\'", cmd);
213             printf("Simulate incoming call from 7654321\n");
214             hfp_ag_set_clip(129, "7654321");
215             hfp_ag_incoming_call();
216             break;
217         case 'C':
218             log_info("USER:\'%c\'", cmd);
219             printf("Simulate terminate call\n");
220             hfp_ag_call_dropped();
221             break;
222         case 'd':
223             log_info("USER:\'%c\'", cmd);
224             printf("Report AG failure\n");
225             hfp_ag_report_extended_audio_gateway_error_result_code(acl_handle, HFP_CME_ERROR_AG_FAILURE);
226             break;
227         case 'e':
228             log_info("USER:\'%c\'", cmd);
229             printf("Answer call on AG\n");
230             hfp_ag_answer_incoming_call();
231             break;
232         case 'E':
233             log_info("USER:\'%c\'", cmd);
234             printf("Reject call on AG\n");
235             hfp_ag_terminate_call();
236             break;
237         case 'f':
238             log_info("USER:\'%c\'", cmd);
239             printf("Disable cellular network\n");
240             hfp_ag_set_registration_status(0);
241             break;
242         case 'F':
243             log_info("USER:\'%c\'", cmd);
244             printf("Enable cellular network\n");
245             hfp_ag_set_registration_status(1);
246             break;
247         case 'g':
248             log_info("USER:\'%c\'", cmd);
249             printf("Set signal strength to 0\n");
250             hfp_ag_set_signal_strength(0);
251             break;
252         case 'G':
253             log_info("USER:\'%c\'", cmd);
254             printf("Set signal strength to 5\n");
255             hfp_ag_set_signal_strength(5);
256             break;
257         case 'h':
258             log_info("USER:\'%c\'", cmd);
259             printf("Disable roaming\n");
260             hfp_ag_set_roaming_status(0);
261             break;
262         case 'H':
263             log_info("USER:\'%c\'", cmd);
264             printf("Enable roaming\n");
265             hfp_ag_set_roaming_status(1);
266             break;
267         case 'i':
268             log_info("USER:\'%c\'", cmd);
269             printf("Set battery level to 3\n");
270             hfp_ag_set_battery_level(3);
271             break;
272         case 'I':
273             log_info("USER:\'%c\'", cmd);
274             printf("Set battery level to 5\n");
275             hfp_ag_set_battery_level(5);
276             break;
277         case 'j':
278             log_info("USER:\'%c\'", cmd);
279             printf("Answering call on remote side\n");
280             hfp_ag_outgoing_call_established();
281             break;
282         case 'r':
283             log_info("USER:\'%c\'", cmd);
284             printf("Disable in-band ring tone\n");
285             hfp_ag_set_use_in_band_ring_tone(0);
286             break;
287         case 'k':
288             log_info("USER:\'%c\'", cmd);
289             printf("Memory 1 cleared\n");
290             memory_1_enabled = 0;
291             break;
292         case 'K':
293             log_info("USER:\'%c\'", cmd);
294             printf("Memory 1 set\n");
295             memory_1_enabled = 1;
296             break;
297         case 'l':
298             log_info("USER:\'%c\'", cmd);
299             printf("Last dialed number cleared\n");
300             hfp_ag_clear_last_dialed_number();
301             break;
302         case 'L':
303             log_info("USER:\'%c\'", cmd);
304             printf("Outgoing call connected, ringing\n");
305             hfp_ag_outgoing_call_ringing();
306             break;
307         case 'n':
308             log_info("USER:\'%c\'", cmd);
309             printf("Disable Voice Recognition\n");
310             hfp_ag_activate_voice_recognition(acl_handle, 0);
311             break;
312         case 'N':
313             log_info("USER:\'%c\'", cmd);
314             printf("Enable Voice Recognition\n");
315             hfp_ag_activate_voice_recognition(acl_handle, 1);
316             break;
317         case 'o':
318             log_info("USER:\'%c\'", cmd);
319             printf("Set speaker gain to 0 (minimum)\n");
320             hfp_ag_set_speaker_gain(acl_handle, 0);
321             break;
322         case 'O':
323             log_info("USER:\'%c\'", cmd);
324             printf("Set speaker gain to 9 (default)\n");
325             hfp_ag_set_speaker_gain(acl_handle, 9);
326             break;
327         case 'p':
328             log_info("USER:\'%c\'", cmd);
329             printf("Set speaker gain to 12 (higher)\n");
330             hfp_ag_set_speaker_gain(acl_handle, 12);
331             break;
332         case 'P':
333             log_info("USER:\'%c\'", cmd);
334             printf("Set speaker gain to 15 (maximum)\n");
335             hfp_ag_set_speaker_gain(acl_handle, 15);
336             break;
337         case 'q':
338             log_info("USER:\'%c\'", cmd);
339             printf("Set microphone gain to 0\n");
340             hfp_ag_set_microphone_gain(acl_handle, 0);
341             break;
342         case 'Q':
343             log_info("USER:\'%c\'", cmd);
344             printf("Set microphone gain to 9\n");
345             hfp_ag_set_microphone_gain(acl_handle, 9);
346             break;
347         case 's':
348             log_info("USER:\'%c\'", cmd);
349             printf("Set microphone gain to 12\n");
350             hfp_ag_set_microphone_gain(acl_handle, 12);
351             break;
352         case 'S':
353             log_info("USER:\'%c\'", cmd);
354             printf("Set microphone gain to 15\n");
355             hfp_ag_set_microphone_gain(acl_handle, 15);
356             break;
357         case 'R':
358             log_info("USER:\'%c\'", cmd);
359             printf("Enable in-band ring tone\n");
360             hfp_ag_set_use_in_band_ring_tone(1);
361             break;
362         case 't':
363             log_info("USER:\'%c\'", cmd);
364             printf("Terminate HCI connection. 0x%2x\n", acl_handle);
365             gap_disconnect(acl_handle);
366             break;
367         case 'u':
368             log_info("USER:\'%c\'", cmd);
369             printf("Join held call\n");
370             hfp_ag_join_held_call();
371             break;
372         case 'v':
373             printf("Start scanning...\n");
374             gap_inquiry_start(INQUIRY_INTERVAL);
375             break;
376         case 'w':
377             log_info("USER:\'%c\'", cmd);
378             printf("AG: Put incoming call on hold (Response and Hold)\n");
379             hfp_ag_hold_incoming_call();
380             break;
381         case 'x':
382             log_info("USER:\'%c\'", cmd);
383             printf("AG: Accept held incoming call (Response and Hold)\n");
384             hfp_ag_accept_held_incoming_call();
385             break;
386         case 'X':
387             log_info("USER:\'%c\'", cmd);
388             printf("AG: Reject held incoming call (Response and Hold)\n");
389             hfp_ag_reject_held_incoming_call();
390             break;
391         default:
392             show_usage();
393             break;
394     }
395 }
396 #endif
397 
398 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
399     UNUSED(channel);
400     bd_addr_t addr;
401     switch (packet_type){
402         case HCI_EVENT_PACKET:
403             switch (event[0]){
404                 case GAP_EVENT_INQUIRY_RESULT:
405                     gap_event_inquiry_result_get_bd_addr(event, addr);
406                     // print info
407                     printf("Device found: %s ",  bd_addr_to_str(addr));
408                     printf("with COD: 0x%06x, ", (unsigned int) gap_event_inquiry_result_get_class_of_device(event));
409                     if (gap_event_inquiry_result_get_rssi_available(event)){
410                         printf(", rssi %d dBm", (int8_t) gap_event_inquiry_result_get_rssi(event));
411                     }
412                     if (gap_event_inquiry_result_get_name_available(event)){
413                         char name_buffer[240];
414                         int name_len = gap_event_inquiry_result_get_name_len(event);
415                         memcpy(name_buffer, gap_event_inquiry_result_get_name(event), name_len);
416                         name_buffer[name_len] = 0;
417                         printf(", name '%s'", name_buffer);
418                     }
419                     printf("\n");
420                     break;
421                 case GAP_EVENT_INQUIRY_COMPLETE:
422                     printf("Inquiry scan complete.\n");
423                     break;
424                 case HCI_EVENT_SCO_CAN_SEND_NOW:
425                     sco_demo_send(sco_handle);
426                     break;
427                 case HCI_EVENT_COMMAND_COMPLETE:
428                     if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){
429                         dump_supported_codecs();
430                     }
431                     break;
432                 default:
433                     break;
434             }
435 
436             if (event[0] != HCI_EVENT_HFP_META) return;
437 
438             if (event[3]
439                 && event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
440                 && event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG
441                 && event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){
442                 printf("ERROR, status: %u\n", event[3]);
443                 return;
444             }
445 
446             switch (event[2]) {
447                 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
448                     acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
449                     hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr);
450                     printf("Service level connection established from %s.\n", bd_addr_to_str(device_addr));
451                     dump_supported_codecs();
452                    break;
453                 case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
454                     printf("Service level connection released.\n");
455                     sco_handle = 0;
456                     break;
457                 case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
458                     if (hfp_subevent_audio_connection_established_get_status(event)){
459                         printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
460                         sco_handle = 0;
461                     } else {
462                         sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
463                         printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
464                         negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event);
465                         switch (negotiated_codec){
466                             case 0x01:
467                                 printf("Using CVSD codec.\n");
468                                 break;
469                             case 0x02:
470                                 printf("Using mSBC codec.\n");
471                                 break;
472                             default:
473                                 printf("Using unknown codec 0x%02x.\n", negotiated_codec);
474                                 break;
475                         }
476                         sco_demo_set_codec(negotiated_codec);
477                         hci_request_sco_can_send_now_event();
478                     }
479                     break;
480                 case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
481                     printf("Audio connection released\n");
482                     sco_handle = 0;
483                     sco_demo_close();
484                     break;
485                 case HFP_SUBEVENT_START_RINGINIG:
486                     printf("Start Ringing\n");
487                     break;
488                 case HFP_SUBEVENT_STOP_RINGINIG:
489                     printf("Stop Ringing\n");
490                     break;
491                 case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER:
492                     printf("Outgoing call '%s'\n", hfp_subevent_place_call_with_number_get_number(event));
493                     // validate number
494                     if ( strcmp("1234567", hfp_subevent_place_call_with_number_get_number(event)) == 0
495                       || strcmp("7654321", hfp_subevent_place_call_with_number_get_number(event)) == 0
496                       || (memory_1_enabled && strcmp(">1", hfp_subevent_place_call_with_number_get_number(event)) == 0)){
497                         printf("Dialstring valid: accept call\n");
498                         hfp_ag_outgoing_call_accepted();
499                     } else {
500                         printf("Dialstring invalid: reject call\n");
501                         hfp_ag_outgoing_call_rejected();
502                     }
503                     break;
504 
505                 case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
506                     printf("Attach number to voice tag. Sending '1234567\n");
507                     hfp_ag_send_phone_number_for_voice_tag(acl_handle, "1234567");
508                     break;
509                 case HFP_SUBEVENT_TRANSMIT_DTMF_CODES:
510                     printf("Send DTMF Codes: '%s'\n", hfp_subevent_transmit_dtmf_codes_get_dtmf(event));
511                     hfp_ag_send_dtmf_code_done(acl_handle);
512                     break;
513                 case HFP_SUBEVENT_CALL_ANSWERED:
514                     printf("Call answered by HF\n");
515                     break;
516                 default:
517                     printf("Event not handled %u\n", event[2]);
518                     break;
519             }
520             break;
521         case HCI_SCO_DATA_PACKET:
522             sco_demo_receive(event, event_size);
523             break;
524         default:
525             break;
526     }
527 }
528 
529 static hfp_phone_number_t subscriber_number = {
530     129, "225577"
531 };
532 
533 /* @section Main Application Setup
534  *
535  * @text Listing MainConfiguration shows main application code.
536  * To run a HFP AG service you need to initialize the SDP, and to create and register HFP AG record with it.
537  * The packet_handler is used for sending commands to the HFP HF. It also receives the HFP HF's answers.
538  * The stdin_process callback allows for sending commands to the HFP HF.
539  * At the end the Bluetooth stack is started.
540  */
541 
542 /* LISTING_START(MainConfiguration): Setup HFP Audio Gateway */
543 
544 int btstack_main(int argc, const char * argv[]);
545 int btstack_main(int argc, const char * argv[]){
546     (void)argc;
547     (void)argv;
548 
549     sco_demo_init();
550 
551     // register for HCI events
552     hci_event_callback_registration.callback = &packet_handler;
553     hci_add_event_handler(&hci_event_callback_registration);
554     hci_register_sco_packet_handler(&packet_handler);
555 
556     gap_discoverable_control(1);
557 
558     // L2CAP
559     l2cap_init();
560 
561     uint16_t supported_features                   =
562         (1<<HFP_AGSF_ESCO_S4)                     |
563         (1<<HFP_AGSF_HF_INDICATORS)               |
564         (1<<HFP_AGSF_CODEC_NEGOTIATION)           |
565         (1<<HFP_AGSF_EXTENDED_ERROR_RESULT_CODES) |
566         (1<<HFP_AGSF_ENHANCED_CALL_CONTROL)       |
567         (1<<HFP_AGSF_ENHANCED_CALL_STATUS)        |
568         (1<<HFP_AGSF_ABILITY_TO_REJECT_A_CALL)    |
569         (1<<HFP_AGSF_IN_BAND_RING_TONE)           |
570         (1<<HFP_AGSF_VOICE_RECOGNITION_FUNCTION)  |
571         (1<<HFP_AGSF_THREE_WAY_CALLING);
572     int wide_band_speech = 1;
573 
574     // HFP
575     rfcomm_init();
576     hfp_ag_init(rfcomm_channel_nr);
577     hfp_ag_init_supported_features(supported_features);
578     hfp_ag_init_codecs(sizeof(codecs), codecs);
579     hfp_ag_init_ag_indicators(ag_indicators_nr, ag_indicators);
580     hfp_ag_init_hf_indicators(hf_indicators_nr, hf_indicators);
581     hfp_ag_init_call_hold_services(call_hold_services_nr, call_hold_services);
582     hfp_ag_set_subcriber_number_information(&subscriber_number, 1);
583     hfp_ag_register_packet_handler(&packet_handler);
584     hci_register_sco_packet_handler(&packet_handler);
585 
586     // SDP Server
587     sdp_init();
588     memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer));
589     hfp_ag_create_sdp_record( hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_ag_service_name, 0, supported_features, wide_band_speech);
590     printf("SDP service record size: %u\n", de_get_len( hfp_service_buffer));
591     sdp_register_service(hfp_service_buffer);
592 
593     // parse humand readable Bluetooth address
594     sscanf_bd_addr(device_addr_string, device_addr);
595 
596 #ifdef HAVE_BTSTACK_STDIN
597     btstack_stdin_setup(stdin_process);
598 #endif
599     // turn on!
600     hci_power_control(HCI_POWER_ON);
601     return 0;
602 }
603 /* LISTING_END */
604 /* EXAMPLE_END */
605