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