1fffdd288SMatthias Ringwald 2fffdd288SMatthias Ringwald /* 3fffdd288SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 4fffdd288SMatthias Ringwald * 5fffdd288SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 6fffdd288SMatthias Ringwald * modification, are permitted provided that the following conditions 7fffdd288SMatthias Ringwald * are met: 8fffdd288SMatthias Ringwald * 9fffdd288SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 10fffdd288SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 11fffdd288SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 12fffdd288SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 13fffdd288SMatthias Ringwald * documentation and/or other materials provided with the distribution. 14fffdd288SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 15fffdd288SMatthias Ringwald * contributors may be used to endorse or promote products derived 16fffdd288SMatthias Ringwald * from this software without specific prior written permission. 17fffdd288SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 18fffdd288SMatthias Ringwald * personal benefit and not for any commercial purpose or for 19fffdd288SMatthias Ringwald * monetary gain. 20fffdd288SMatthias Ringwald * 21fffdd288SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 22fffdd288SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23fffdd288SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24fffdd288SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 25fffdd288SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26fffdd288SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27fffdd288SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28fffdd288SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29fffdd288SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30fffdd288SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 31fffdd288SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32fffdd288SMatthias Ringwald * SUCH DAMAGE. 33fffdd288SMatthias Ringwald * 34fffdd288SMatthias Ringwald * Please inquire about commercial licensing options at 35fffdd288SMatthias Ringwald * [email protected] 36fffdd288SMatthias Ringwald * 37fffdd288SMatthias Ringwald */ 38fffdd288SMatthias Ringwald 39fffdd288SMatthias Ringwald /* 40fffdd288SMatthias Ringwald * hfp_hs_demo.c 41fffdd288SMatthias Ringwald */ 42fffdd288SMatthias Ringwald 43fffdd288SMatthias Ringwald // ***************************************************************************** 44fffdd288SMatthias Ringwald /* EXAMPLE_START(hfp_hs_demo): HFP Hands-Free (HF) Demo 45fffdd288SMatthias Ringwald * 46fffdd288SMatthias Ringwald * @text This HFP Hands-Free example demonstrates how to receive 47fffdd288SMatthias Ringwald * an output from a remote HFP audio gateway (AG), and, 48d0755cd6SMatthias Ringwald * if HAVE_POSIX_STDIN is defined, how to control the HFP AG. 49fffdd288SMatthias Ringwald */ 50fffdd288SMatthias Ringwald // ***************************************************************************** 51fffdd288SMatthias Ringwald 52fffdd288SMatthias Ringwald 53fffdd288SMatthias Ringwald #include "btstack_config.h" 54fffdd288SMatthias Ringwald 55fffdd288SMatthias Ringwald #include <stdint.h> 56fffdd288SMatthias Ringwald #include <stdio.h> 57fffdd288SMatthias Ringwald #include <stdlib.h> 58fffdd288SMatthias Ringwald #include <string.h> 594af4141bSMatthias Ringwald #include <unistd.h> 60fffdd288SMatthias Ringwald 61fffdd288SMatthias Ringwald #include "btstack.h" 62fcb08cdbSMilanka Ringwald 63185c8cd4SMatthias Ringwald #include "sco_demo_util.h" 64d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 65fffdd288SMatthias Ringwald #include "stdin_support.h" 664af4141bSMatthias Ringwald #endif 67fffdd288SMatthias Ringwald 68fffdd288SMatthias Ringwald uint8_t hfp_service_buffer[150]; 69fffdd288SMatthias Ringwald const uint8_t rfcomm_channel_nr = 1; 70fffdd288SMatthias Ringwald const char hfp_hf_service_name[] = "BTstack HFP HF Demo"; 71fffdd288SMatthias Ringwald 72d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 73185c8cd4SMatthias Ringwald static bd_addr_t device_addr = {0x80,0xbe,0x05,0xd5,0x28,0x48}; 74185c8cd4SMatthias Ringwald // 80:BE:05:D5:28:48 75fffdd288SMatthias Ringwald // prototypes 7635833313SMatthias Ringwald static void show_usage(void); 77fffdd288SMatthias Ringwald #endif 78c8626498SMilanka Ringwald static hci_con_handle_t acl_handle = -1; 79185c8cd4SMatthias Ringwald static hci_con_handle_t sco_handle; 80fffdd288SMatthias Ringwald static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; 81fffdd288SMatthias Ringwald static uint16_t indicators[1] = {0x01}; 8208d1a604SMilanka Ringwald static uint8_t negotiated_codec = HFP_CODEC_CVSD; 83*186bfbecSMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 84fffdd288SMatthias Ringwald char cmd; 85fffdd288SMatthias Ringwald 8608d1a604SMilanka Ringwald 87d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 88fffdd288SMatthias Ringwald 89fffdd288SMatthias Ringwald // Testig User Interface 90fffdd288SMatthias Ringwald static void show_usage(void){ 91fcb08cdbSMilanka Ringwald bd_addr_t iut_address; 92fcb08cdbSMilanka Ringwald gap_local_bd_addr(iut_address); 93fcb08cdbSMilanka Ringwald 94fcb08cdbSMilanka Ringwald printf("\n--- Bluetooth HFP Hands-Free (HF) unit Test Console %s ---\n", bd_addr_to_str(iut_address)); 95fffdd288SMatthias Ringwald printf("---\n"); 96fffdd288SMatthias Ringwald 97bdb44bd9SMatthias Ringwald printf("a - establish SLC connection to device %s\n", bd_addr_to_str(device_addr)); 98fffdd288SMatthias Ringwald printf("A - release SLC connection to device\n"); 99fffdd288SMatthias Ringwald 100fffdd288SMatthias Ringwald printf("b - establish Audio connection\n"); 101fffdd288SMatthias Ringwald printf("B - release Audio connection\n"); 102fffdd288SMatthias Ringwald 103fffdd288SMatthias Ringwald printf("c - disable registration status update for all AG indicators\n"); 104fffdd288SMatthias Ringwald printf("C - enable registration status update for all AG indicators\n"); 105fffdd288SMatthias Ringwald 106fffdd288SMatthias Ringwald printf("d - query network operator.\n"); 107fffdd288SMatthias Ringwald printf("D - set HFP AG registration status update for individual indicators (IIA)\n"); 108fffdd288SMatthias Ringwald 109fffdd288SMatthias Ringwald printf("e - disable reporting of the extended AG error result code\n"); 110fffdd288SMatthias Ringwald printf("E - enable reporting of the extended AG error result code\n"); 111fffdd288SMatthias Ringwald 112fffdd288SMatthias Ringwald printf("f - answer incoming call\n"); 113fffdd288SMatthias Ringwald printf("F - Hangup call\n"); 114fffdd288SMatthias Ringwald 115fffdd288SMatthias Ringwald printf("g - query network operator name\n"); 116fffdd288SMatthias Ringwald printf("G - reject incoming call\n"); 117fffdd288SMatthias Ringwald 118fffdd288SMatthias Ringwald printf("i - dial 1234567\n"); 119fffdd288SMatthias Ringwald printf("I - dial 7654321\n"); 120fffdd288SMatthias Ringwald 121fffdd288SMatthias Ringwald printf("j - dial #1\n"); 122fffdd288SMatthias Ringwald printf("J - dial #99\n"); 123fffdd288SMatthias Ringwald 124fffdd288SMatthias Ringwald printf("k - deactivate call waiting notification\n"); 125fffdd288SMatthias Ringwald printf("K - activate call waiting notification\n"); 126fffdd288SMatthias Ringwald 127fffdd288SMatthias Ringwald printf("l - deactivate calling line notification\n"); 128fffdd288SMatthias Ringwald printf("L - activate calling line notification\n"); 129fffdd288SMatthias Ringwald 130fffdd288SMatthias Ringwald printf("m - deactivate echo canceling and noise reduction\n"); 131fffdd288SMatthias Ringwald printf("M - activate echo canceling and noise reduction\n"); 132fffdd288SMatthias Ringwald 133fffdd288SMatthias Ringwald printf("n - deactivate voice recognition\n"); 134fffdd288SMatthias Ringwald printf("N - activate voice recognition\n"); 135fffdd288SMatthias Ringwald 136fffdd288SMatthias Ringwald printf("o - Set speaker volume to 0 (minimum)\n"); 137fffdd288SMatthias Ringwald printf("O - Set speaker volume to 9 (default)\n"); 138fffdd288SMatthias Ringwald printf("p - Set speaker volume to 12 (higher)\n"); 139fffdd288SMatthias Ringwald printf("P - Set speaker volume to 15 (maximum)\n"); 140fffdd288SMatthias Ringwald 141fffdd288SMatthias Ringwald printf("q - Set microphone gain to 0 (minimum)\n"); 142fffdd288SMatthias Ringwald printf("Q - Set microphone gain to 9 (default)\n"); 143fffdd288SMatthias Ringwald printf("s - Set microphone gain to 12 (higher)\n"); 144fffdd288SMatthias Ringwald printf("S - Set microphone gain to 15 (maximum)\n"); 145fffdd288SMatthias Ringwald 146fffdd288SMatthias Ringwald printf("t - terminate connection\n"); 147fffdd288SMatthias Ringwald 148fffdd288SMatthias Ringwald printf("u - send 'user busy' (TWC 0)\n"); 149fffdd288SMatthias Ringwald printf("U - end active call and accept other call' (TWC 1)\n"); 150fffdd288SMatthias Ringwald printf("v - Swap active call and hold/waiting call (TWC 2)\n"); 151fffdd288SMatthias Ringwald printf("V - Join held call (TWC 3)\n"); 152fffdd288SMatthias Ringwald printf("w - Connect calls (TWC 4)\n"); 153fffdd288SMatthias Ringwald printf("W - redial\n"); 154fffdd288SMatthias Ringwald 155fffdd288SMatthias Ringwald printf("0123456789#*-+ - send DTMF dial tones\n"); 156fffdd288SMatthias Ringwald 157fffdd288SMatthias Ringwald printf("x - request phone number for voice tag\n"); 158fffdd288SMatthias Ringwald printf("X - current call status (ECS)\n"); 159fffdd288SMatthias Ringwald printf("y - release call with index 2 (ECC)\n"); 160fffdd288SMatthias Ringwald printf("Y - private consulation with call 2(ECC)\n"); 161fffdd288SMatthias Ringwald 162fffdd288SMatthias Ringwald printf("[ - Query Response and Hold status (RHH ?)\n"); 163fffdd288SMatthias Ringwald printf("] - Place call in a response and held state(RHH 0)\n"); 164fffdd288SMatthias Ringwald printf("{ - Accept held call(RHH 1)\n"); 165fffdd288SMatthias Ringwald printf("} - Reject held call(RHH 2)\n"); 166fffdd288SMatthias Ringwald 167fffdd288SMatthias Ringwald printf("? - Query Subscriber Number (NUM)\n"); 168fffdd288SMatthias Ringwald 169fffdd288SMatthias Ringwald printf("! - Update HF indicator with assigned number 1 (HFI)\n"); 170fffdd288SMatthias Ringwald 171fffdd288SMatthias Ringwald printf("---\n"); 172fffdd288SMatthias Ringwald printf("Ctrl-c - exit\n"); 173fffdd288SMatthias Ringwald printf("---\n"); 174fffdd288SMatthias Ringwald } 175fffdd288SMatthias Ringwald 1764af4141bSMatthias Ringwald static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){ 177fffdd288SMatthias Ringwald read(ds->fd, &cmd, 1); 178fffdd288SMatthias Ringwald 179fffdd288SMatthias Ringwald if (cmd >= '0' && cmd <= '9'){ 180fffdd288SMatthias Ringwald printf("DTMF Code: %c\n", cmd); 181c8626498SMilanka Ringwald hfp_hf_send_dtmf_code(acl_handle, cmd); 1824af4141bSMatthias Ringwald return; 183fffdd288SMatthias Ringwald } 184fffdd288SMatthias Ringwald 185fffdd288SMatthias Ringwald switch (cmd){ 186fffdd288SMatthias Ringwald case '#': 187fffdd288SMatthias Ringwald case '-': 188fffdd288SMatthias Ringwald case '+': 189fffdd288SMatthias Ringwald case '*': 190fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 191fffdd288SMatthias Ringwald printf("DTMF Code: %c\n", cmd); 192c8626498SMilanka Ringwald hfp_hf_send_dtmf_code(acl_handle, cmd); 193fffdd288SMatthias Ringwald break; 194fffdd288SMatthias Ringwald case 'a': 195fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 196fffdd288SMatthias Ringwald printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 197fffdd288SMatthias Ringwald hfp_hf_establish_service_level_connection(device_addr); 198fffdd288SMatthias Ringwald break; 199fffdd288SMatthias Ringwald case 'A': 200fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 201fffdd288SMatthias Ringwald printf("Release Service level connection.\n"); 202c8626498SMilanka Ringwald hfp_hf_release_service_level_connection(acl_handle); 203fffdd288SMatthias Ringwald break; 204fffdd288SMatthias Ringwald case 'b': 205fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 206fffdd288SMatthias Ringwald printf("Establish Audio connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); 207c8626498SMilanka Ringwald hfp_hf_establish_audio_connection(acl_handle); 208fffdd288SMatthias Ringwald break; 209fffdd288SMatthias Ringwald case 'B': 210fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 211fffdd288SMatthias Ringwald printf("Release Audio service level connection.\n"); 212c8626498SMilanka Ringwald hfp_hf_release_audio_connection(acl_handle); 213fffdd288SMatthias Ringwald break; 214fffdd288SMatthias Ringwald case 'C': 215fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 216fffdd288SMatthias Ringwald printf("Enable registration status update for all AG indicators.\n"); 217c8626498SMilanka Ringwald hfp_hf_enable_status_update_for_all_ag_indicators(acl_handle); 218fffdd288SMatthias Ringwald case 'c': 219fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 220fffdd288SMatthias Ringwald printf("Disable registration status update for all AG indicators.\n"); 221c8626498SMilanka Ringwald hfp_hf_disable_status_update_for_all_ag_indicators(acl_handle); 222fffdd288SMatthias Ringwald break; 223fffdd288SMatthias Ringwald case 'D': 224fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 225fffdd288SMatthias Ringwald printf("Set HFP AG registration status update for individual indicators (0111111).\n"); 226c8626498SMilanka Ringwald hfp_hf_set_status_update_for_individual_ag_indicators(acl_handle, 63); 227fffdd288SMatthias Ringwald break; 228fffdd288SMatthias Ringwald case 'd': 229fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 230fffdd288SMatthias Ringwald printf("Query network operator.\n"); 231c8626498SMilanka Ringwald hfp_hf_query_operator_selection(acl_handle); 232fffdd288SMatthias Ringwald break; 233fffdd288SMatthias Ringwald case 'E': 234fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 235fffdd288SMatthias Ringwald printf("Enable reporting of the extended AG error result code.\n"); 236c8626498SMilanka Ringwald hfp_hf_enable_report_extended_audio_gateway_error_result_code(acl_handle); 237fffdd288SMatthias Ringwald break; 238fffdd288SMatthias Ringwald case 'e': 239fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 240fffdd288SMatthias Ringwald printf("Disable reporting of the extended AG error result code.\n"); 241c8626498SMilanka Ringwald hfp_hf_disable_report_extended_audio_gateway_error_result_code(acl_handle); 242fffdd288SMatthias Ringwald break; 243fffdd288SMatthias Ringwald case 'f': 244fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 245fffdd288SMatthias Ringwald printf("Answer incoming call.\n"); 246c8626498SMilanka Ringwald hfp_hf_answer_incoming_call(acl_handle); 247fffdd288SMatthias Ringwald break; 248fffdd288SMatthias Ringwald case 'F': 249fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 250fffdd288SMatthias Ringwald printf("Hangup call.\n"); 251c8626498SMilanka Ringwald hfp_hf_terminate_call(acl_handle); 252fffdd288SMatthias Ringwald break; 253fffdd288SMatthias Ringwald case 'G': 254fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 255fffdd288SMatthias Ringwald printf("Reject incoming call.\n"); 256c8626498SMilanka Ringwald hfp_hf_reject_incoming_call(acl_handle); 257fffdd288SMatthias Ringwald break; 258fffdd288SMatthias Ringwald case 'g': 259fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 260fffdd288SMatthias Ringwald printf("Query operator.\n"); 261c8626498SMilanka Ringwald hfp_hf_query_operator_selection(acl_handle); 262fffdd288SMatthias Ringwald break; 263fffdd288SMatthias Ringwald case 't': 264fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 265fffdd288SMatthias Ringwald printf("Terminate HCI connection.\n"); 266c8626498SMilanka Ringwald gap_disconnect(acl_handle); 267fffdd288SMatthias Ringwald break; 268fffdd288SMatthias Ringwald case 'i': 269fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 270fffdd288SMatthias Ringwald printf("Dial 1234567\n"); 271c8626498SMilanka Ringwald hfp_hf_dial_number(acl_handle, "1234567"); 272fffdd288SMatthias Ringwald break; 273fffdd288SMatthias Ringwald case 'I': 274fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 275fffdd288SMatthias Ringwald printf("Dial 7654321\n"); 276c8626498SMilanka Ringwald hfp_hf_dial_number(acl_handle, "7654321"); 277fffdd288SMatthias Ringwald break; 278fffdd288SMatthias Ringwald case 'j': 279fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 280fffdd288SMatthias Ringwald printf("Dial #1\n"); 281c8626498SMilanka Ringwald hfp_hf_dial_memory(acl_handle,1); 282fffdd288SMatthias Ringwald break; 283fffdd288SMatthias Ringwald case 'J': 284fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 285fffdd288SMatthias Ringwald printf("Dial #99\n"); 286c8626498SMilanka Ringwald hfp_hf_dial_memory(acl_handle,99); 287fffdd288SMatthias Ringwald break; 288fffdd288SMatthias Ringwald case 'k': 289fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 290fffdd288SMatthias Ringwald printf("Deactivate call waiting notification\n"); 291c8626498SMilanka Ringwald hfp_hf_deactivate_call_waiting_notification(acl_handle); 292fffdd288SMatthias Ringwald break; 293fffdd288SMatthias Ringwald case 'K': 294fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 295fffdd288SMatthias Ringwald printf("Activate call waiting notification\n"); 296c8626498SMilanka Ringwald hfp_hf_activate_call_waiting_notification(acl_handle); 297fffdd288SMatthias Ringwald break; 298fffdd288SMatthias Ringwald case 'l': 299fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 300fffdd288SMatthias Ringwald printf("Deactivate calling line notification\n"); 301c8626498SMilanka Ringwald hfp_hf_deactivate_calling_line_notification(acl_handle); 302fffdd288SMatthias Ringwald break; 303fffdd288SMatthias Ringwald case 'L': 304fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 305fffdd288SMatthias Ringwald printf("Activate calling line notification\n"); 306c8626498SMilanka Ringwald hfp_hf_activate_calling_line_notification(acl_handle); 307fffdd288SMatthias Ringwald break; 308fffdd288SMatthias Ringwald case 'm': 309fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 310fffdd288SMatthias Ringwald printf("Deactivate echo canceling and noise reduction\n"); 311c8626498SMilanka Ringwald hfp_hf_deactivate_echo_canceling_and_noise_reduction(acl_handle); 312fffdd288SMatthias Ringwald break; 313fffdd288SMatthias Ringwald case 'M': 314fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 315fffdd288SMatthias Ringwald printf("Activate echo canceling and noise reduction\n"); 316c8626498SMilanka Ringwald hfp_hf_activate_echo_canceling_and_noise_reduction(acl_handle); 317fffdd288SMatthias Ringwald break; 318fffdd288SMatthias Ringwald case 'n': 319fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 320fffdd288SMatthias Ringwald printf("Deactivate voice recognition\n"); 321c8626498SMilanka Ringwald hfp_hf_deactivate_voice_recognition_notification(acl_handle); 322fffdd288SMatthias Ringwald break; 323fffdd288SMatthias Ringwald case 'N': 324fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 32508d1a604SMilanka Ringwald printf("Activate voice recognition %s\n", bd_addr_to_str(device_addr)); 326c8626498SMilanka Ringwald hfp_hf_activate_voice_recognition_notification(acl_handle); 327fffdd288SMatthias Ringwald break; 328fffdd288SMatthias Ringwald case 'o': 329fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 330fffdd288SMatthias Ringwald printf("Set speaker gain to 0 (minimum)\n"); 331c8626498SMilanka Ringwald hfp_hf_set_speaker_gain(acl_handle, 0); 332fffdd288SMatthias Ringwald break; 333fffdd288SMatthias Ringwald case 'O': 334fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 335fffdd288SMatthias Ringwald printf("Set speaker gain to 9 (default)\n"); 336c8626498SMilanka Ringwald hfp_hf_set_speaker_gain(acl_handle, 9); 337fffdd288SMatthias Ringwald break; 338fffdd288SMatthias Ringwald case 'p': 339fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 340fffdd288SMatthias Ringwald printf("Set speaker gain to 12 (higher)\n"); 341c8626498SMilanka Ringwald hfp_hf_set_speaker_gain(acl_handle, 12); 342fffdd288SMatthias Ringwald break; 343fffdd288SMatthias Ringwald case 'P': 344fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 345fffdd288SMatthias Ringwald printf("Set speaker gain to 15 (maximum)\n"); 346c8626498SMilanka Ringwald hfp_hf_set_speaker_gain(acl_handle, 15); 347fffdd288SMatthias Ringwald break; 348fffdd288SMatthias Ringwald case 'q': 349fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 350fffdd288SMatthias Ringwald printf("Set microphone gain to 0\n"); 351c8626498SMilanka Ringwald hfp_hf_set_microphone_gain(acl_handle, 0); 352fffdd288SMatthias Ringwald break; 353fffdd288SMatthias Ringwald case 'Q': 354fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 355fffdd288SMatthias Ringwald printf("Set microphone gain to 9\n"); 356c8626498SMilanka Ringwald hfp_hf_set_microphone_gain(acl_handle, 9); 357fffdd288SMatthias Ringwald break; 358fffdd288SMatthias Ringwald case 's': 359fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 360fffdd288SMatthias Ringwald printf("Set microphone gain to 12\n"); 361c8626498SMilanka Ringwald hfp_hf_set_microphone_gain(acl_handle, 12); 362fffdd288SMatthias Ringwald break; 363fffdd288SMatthias Ringwald case 'S': 364fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 365fffdd288SMatthias Ringwald printf("Set microphone gain to 15\n"); 366c8626498SMilanka Ringwald hfp_hf_set_microphone_gain(acl_handle, 15); 367fffdd288SMatthias Ringwald break; 368fffdd288SMatthias Ringwald case 'u': 369fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 370fffdd288SMatthias Ringwald printf("Send 'user busy' (Three-Way Call 0)\n"); 371c8626498SMilanka Ringwald hfp_hf_user_busy(acl_handle); 372fffdd288SMatthias Ringwald break; 373fffdd288SMatthias Ringwald case 'U': 374fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 375fffdd288SMatthias Ringwald printf("End active call and accept waiting/held call (Three-Way Call 1)\n"); 376c8626498SMilanka Ringwald hfp_hf_end_active_and_accept_other(acl_handle); 377fffdd288SMatthias Ringwald break; 378fffdd288SMatthias Ringwald case 'v': 379fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 380fffdd288SMatthias Ringwald printf("Swap active call and hold/waiting call (Three-Way Call 2)\n"); 381c8626498SMilanka Ringwald hfp_hf_swap_calls(acl_handle); 382fffdd288SMatthias Ringwald break; 383fffdd288SMatthias Ringwald case 'V': 384fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 385fffdd288SMatthias Ringwald printf("Join hold call (Three-Way Call 3)\n"); 386c8626498SMilanka Ringwald hfp_hf_join_held_call(acl_handle); 387fffdd288SMatthias Ringwald break; 388fffdd288SMatthias Ringwald case 'w': 389fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 390fffdd288SMatthias Ringwald printf("Connect calls (Three-Way Call 4)\n"); 391c8626498SMilanka Ringwald hfp_hf_connect_calls(acl_handle); 392fffdd288SMatthias Ringwald break; 393fffdd288SMatthias Ringwald case 'W': 394fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 395fffdd288SMatthias Ringwald printf("Redial\n"); 396c8626498SMilanka Ringwald hfp_hf_redial_last_number(acl_handle); 397fffdd288SMatthias Ringwald break; 398fffdd288SMatthias Ringwald case 'x': 399fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 400fffdd288SMatthias Ringwald printf("Request phone number for voice tag\n"); 401c8626498SMilanka Ringwald hfp_hf_request_phone_number_for_voice_tag(acl_handle); 402fffdd288SMatthias Ringwald break; 403fffdd288SMatthias Ringwald case 'X': 404fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 405fffdd288SMatthias Ringwald printf("Query current call status\n"); 406c8626498SMilanka Ringwald hfp_hf_query_current_call_status(acl_handle); 407fffdd288SMatthias Ringwald break; 408fffdd288SMatthias Ringwald case 'y': 409fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 410fffdd288SMatthias Ringwald printf("Release call with index 2\n"); 411c8626498SMilanka Ringwald hfp_hf_release_call_with_index(acl_handle, 2); 412fffdd288SMatthias Ringwald break; 413fffdd288SMatthias Ringwald case 'Y': 414fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 415fffdd288SMatthias Ringwald printf("Private consulation with call 2\n"); 416c8626498SMilanka Ringwald hfp_hf_private_consultation_with_call(acl_handle, 2); 417fffdd288SMatthias Ringwald break; 418fffdd288SMatthias Ringwald case '[': 419fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 420fffdd288SMatthias Ringwald printf("Query Response and Hold status (RHH ?)\n"); 421c8626498SMilanka Ringwald hfp_hf_rrh_query_status(acl_handle); 422fffdd288SMatthias Ringwald break; 423fffdd288SMatthias Ringwald case ']': 424fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 425fffdd288SMatthias Ringwald printf("Place call in a response and held state (RHH 0)\n"); 426c8626498SMilanka Ringwald hfp_hf_rrh_hold_call(acl_handle); 427fffdd288SMatthias Ringwald break; 428fffdd288SMatthias Ringwald case '{': 429fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 430fffdd288SMatthias Ringwald printf("Accept held call (RHH 1)\n"); 431c8626498SMilanka Ringwald hfp_hf_rrh_accept_held_call(acl_handle); 432fffdd288SMatthias Ringwald break; 433fffdd288SMatthias Ringwald case '}': 434fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 435fffdd288SMatthias Ringwald printf("Reject held call (RHH 2)\n"); 436c8626498SMilanka Ringwald hfp_hf_rrh_reject_held_call(acl_handle); 437fffdd288SMatthias Ringwald break; 438fffdd288SMatthias Ringwald case '?': 439fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 440fffdd288SMatthias Ringwald printf("Query Subscriber Number\n"); 441c8626498SMilanka Ringwald hfp_hf_query_subscriber_number(acl_handle); 442fffdd288SMatthias Ringwald break; 443fffdd288SMatthias Ringwald case '!': 444fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 445fffdd288SMatthias Ringwald printf("Update HF indicator with assigned number 1 (HFI)\n"); 446c8626498SMilanka Ringwald hfp_hf_set_hf_indicator(acl_handle, 1, 1); 447fffdd288SMatthias Ringwald break; 448fffdd288SMatthias Ringwald 449fffdd288SMatthias Ringwald default: 450fffdd288SMatthias Ringwald show_usage(); 451fffdd288SMatthias Ringwald break; 452fffdd288SMatthias Ringwald } 453fffdd288SMatthias Ringwald } 454fffdd288SMatthias Ringwald #endif 455fffdd288SMatthias Ringwald 45613839019SMatthias Ringwald static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){ 457185c8cd4SMatthias Ringwald 45882aca432SMatthias Ringwald switch (packet_type){ 45982aca432SMatthias Ringwald 46082aca432SMatthias Ringwald case HCI_SCO_DATA_PACKET: 461fcb08cdbSMilanka Ringwald sco_demo_receive(event, event_size); 46282aca432SMatthias Ringwald break; 46382aca432SMatthias Ringwald 46482aca432SMatthias Ringwald case HCI_EVENT_PACKET: 46582aca432SMatthias Ringwald switch (event[0]){ 46682aca432SMatthias Ringwald case HCI_EVENT_SCO_CAN_SEND_NOW: 467185c8cd4SMatthias Ringwald sco_demo_send(sco_handle); 46882aca432SMatthias Ringwald break; 46982aca432SMatthias Ringwald 47082aca432SMatthias Ringwald case HCI_EVENT_HFP_META: 47182aca432SMatthias Ringwald switch (event[2]) { 47282aca432SMatthias Ringwald case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: 473c8626498SMilanka Ringwald acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event); 47408d1a604SMilanka Ringwald hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr); 47508d1a604SMilanka Ringwald printf("Service level connection established %s.\n\n", bd_addr_to_str(device_addr)); 47692bac129SMatthias Ringwald if (hci_extended_sco_link_supported()){ 47792bac129SMatthias Ringwald printf("Supported Codecs: CVSD, mSBC.\n"); 47892bac129SMatthias Ringwald } else { 47992bac129SMatthias Ringwald printf("Supported Codecs: CVSD. mSBC disabled, eSCO not supported by controller).\n"); 48092bac129SMatthias Ringwald } 48182aca432SMatthias Ringwald break; 48282aca432SMatthias Ringwald case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: 48382aca432SMatthias Ringwald printf("Service level connection released.\n\n"); 48482aca432SMatthias Ringwald break; 48582aca432SMatthias Ringwald case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED: 48682aca432SMatthias Ringwald if (hfp_subevent_audio_connection_established_get_status(event)){ 48782aca432SMatthias Ringwald sco_handle = 0; 48882aca432SMatthias Ringwald printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event)); 48982aca432SMatthias Ringwald } else { 49082aca432SMatthias Ringwald sco_handle = hfp_subevent_audio_connection_established_get_handle(event); 4918901a7c4SMatthias Ringwald printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 492d0c4aea6SMilanka Ringwald negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event); 493d0c4aea6SMilanka Ringwald printf("Using codec 0x%02x.\n", negotiated_codec); 494d0c4aea6SMilanka Ringwald sco_demo_set_codec(negotiated_codec); 49582aca432SMatthias Ringwald hci_request_sco_can_send_now_event(); 496185c8cd4SMatthias Ringwald } 49782aca432SMatthias Ringwald break; 49882aca432SMatthias Ringwald case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: 49982aca432SMatthias Ringwald sco_handle = 0; 50082aca432SMatthias Ringwald printf("Audio connection released\n"); 501fcb08cdbSMilanka Ringwald sco_demo_close(); 50282aca432SMatthias Ringwald break; 50382aca432SMatthias Ringwald case HFP_SUBEVENT_COMPLETE: 50482aca432SMatthias Ringwald switch (cmd){ 50582aca432SMatthias Ringwald case 'd': 50682aca432SMatthias Ringwald printf("HFP AG registration status update enabled.\n"); 50782aca432SMatthias Ringwald break; 50882aca432SMatthias Ringwald case 'e': 50982aca432SMatthias Ringwald printf("HFP AG registration status update for individual indicators set.\n"); 51082aca432SMatthias Ringwald default: 51182aca432SMatthias Ringwald break; 51282aca432SMatthias Ringwald } 51382aca432SMatthias Ringwald break; 51482aca432SMatthias Ringwald case HFP_SUBEVENT_AG_INDICATOR_STATUS_CHANGED: 51582aca432SMatthias Ringwald printf("AG_INDICATOR_STATUS_CHANGED, AG indicator '%s' (index: %d) to: %d\n", (const char*) &event[5], event[3], event[4]); 51682aca432SMatthias Ringwald break; 51782aca432SMatthias Ringwald case HFP_SUBEVENT_NETWORK_OPERATOR_CHANGED: 51882aca432SMatthias Ringwald printf("NETWORK_OPERATOR_CHANGED, operator mode: %d, format: %d, name: %s\n", event[3], event[4], (char *) &event[5]); 51982aca432SMatthias Ringwald break; 52082aca432SMatthias Ringwald case HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR: 52182aca432SMatthias Ringwald printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : %d\n", event[3]); 52282aca432SMatthias Ringwald break; 52382aca432SMatthias Ringwald case HFP_SUBEVENT_RING: 52482aca432SMatthias Ringwald printf("** Ring **\n"); 52582aca432SMatthias Ringwald break; 52682aca432SMatthias Ringwald case HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG: 52782aca432SMatthias Ringwald printf("Phone number for voice tag: %s\n", (const char *) &event[3]); 52882aca432SMatthias Ringwald break; 52982aca432SMatthias Ringwald case HFP_SUBEVENT_SPEAKER_VOLUME: 53082aca432SMatthias Ringwald printf("Speaker volume: %u\n", event[3]); 53182aca432SMatthias Ringwald break; 53282aca432SMatthias Ringwald case HFP_SUBEVENT_MICROPHONE_VOLUME: 53382aca432SMatthias Ringwald printf("Microphone volume: %u\n", event[3]); 53482aca432SMatthias Ringwald break; 53582aca432SMatthias Ringwald default: 53682aca432SMatthias Ringwald printf("event not handled %u\n", event[2]); 53782aca432SMatthias Ringwald break; 53882aca432SMatthias Ringwald } 53982aca432SMatthias Ringwald break; 54082aca432SMatthias Ringwald 54182aca432SMatthias Ringwald default: 54282aca432SMatthias Ringwald break; 54382aca432SMatthias Ringwald } 54482aca432SMatthias Ringwald break; 54582aca432SMatthias Ringwald 54682aca432SMatthias Ringwald default: 54782aca432SMatthias Ringwald break; 54882aca432SMatthias Ringwald } 54982aca432SMatthias Ringwald 550fffdd288SMatthias Ringwald if (event[0] != HCI_EVENT_HFP_META) return; 551fffdd288SMatthias Ringwald } 552fffdd288SMatthias Ringwald 553fffdd288SMatthias Ringwald /* @section Main Application Setup 554fffdd288SMatthias Ringwald * 555fffdd288SMatthias Ringwald * @text Listing MainConfiguration shows main application code. 556fffdd288SMatthias Ringwald * To run a HFP HF service you need to initialize the SDP, and to create and register HFP HF record with it. 557fffdd288SMatthias Ringwald * The packet_handler is used for sending commands to the HFP AG. It also receives the HFP AG's answers. 558fffdd288SMatthias Ringwald * The stdin_process callback allows for sending commands to the HFP AG. 559fffdd288SMatthias Ringwald * At the end the Bluetooth stack is started. 560fffdd288SMatthias Ringwald */ 561fffdd288SMatthias Ringwald 562fffdd288SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup HFP Hands-Free unit */ 563fffdd288SMatthias Ringwald int btstack_main(int argc, const char * argv[]); 564fffdd288SMatthias Ringwald int btstack_main(int argc, const char * argv[]){ 565185c8cd4SMatthias Ringwald 566a895b9f0SMatthias Ringwald sco_demo_init(); 567a895b9f0SMatthias Ringwald 568a895b9f0SMatthias Ringwald // register for HCI events 569a895b9f0SMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 570a895b9f0SMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 571a895b9f0SMatthias Ringwald hci_register_sco_packet_handler(&packet_handler); 572a895b9f0SMatthias Ringwald 573a895b9f0SMatthias Ringwald gap_discoverable_control(1); 574a895b9f0SMatthias Ringwald gap_set_class_of_device(0x200408); 575a895b9f0SMatthias Ringwald 576fffdd288SMatthias Ringwald // init L2CAP 577fffdd288SMatthias Ringwald l2cap_init(); 578fffdd288SMatthias Ringwald 5794f84bf36SMatthias Ringwald uint16_t hf_supported_features = 5804f84bf36SMatthias Ringwald (1<<HFP_HFSF_ESCO_S4) | 5814f84bf36SMatthias Ringwald (1<<HFP_HFSF_HF_INDICATORS) | 5824f84bf36SMatthias Ringwald (1<<HFP_HFSF_CODEC_NEGOTIATION) | 5834f84bf36SMatthias Ringwald (1<<HFP_HFSF_ENHANCED_CALL_STATUS) | 5844f84bf36SMatthias Ringwald (1<<HFP_HFSF_REMOTE_VOLUME_CONTROL); 5854f84bf36SMatthias Ringwald int wide_band_speech = 1; 5864f84bf36SMatthias Ringwald 587a895b9f0SMatthias Ringwald rfcomm_init(); 588fffdd288SMatthias Ringwald hfp_hf_init(rfcomm_channel_nr); 5894f84bf36SMatthias Ringwald hfp_hf_init_supported_features(hf_supported_features); 590fffdd288SMatthias Ringwald hfp_hf_init_hf_indicators(sizeof(indicators)/sizeof(uint16_t), indicators); 591fffdd288SMatthias Ringwald hfp_hf_init_codecs(sizeof(codecs), codecs); 592fffdd288SMatthias Ringwald 593fffdd288SMatthias Ringwald hfp_hf_register_packet_handler(packet_handler); 594185c8cd4SMatthias Ringwald hci_register_sco_packet_handler(&packet_handler); 595fffdd288SMatthias Ringwald 596a895b9f0SMatthias Ringwald sdp_init(); 597fffdd288SMatthias Ringwald memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer)); 5984f84bf36SMatthias Ringwald hfp_hf_create_sdp_record(hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_hf_service_name, hf_supported_features, wide_band_speech); 599fffdd288SMatthias Ringwald printf("SDP service record size: %u\n", de_get_len(hfp_service_buffer)); 600fffdd288SMatthias Ringwald sdp_register_service(hfp_service_buffer); 601a895b9f0SMatthias Ringwald 602fffdd288SMatthias Ringwald 603d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 604fffdd288SMatthias Ringwald btstack_stdin_setup(stdin_process); 605fffdd288SMatthias Ringwald #endif 606fffdd288SMatthias Ringwald // turn on! 607fffdd288SMatthias Ringwald hci_power_control(HCI_POWER_ON); 608fffdd288SMatthias Ringwald return 0; 609fffdd288SMatthias Ringwald } 610fffdd288SMatthias Ringwald /* LISTING_END */ 6112b6b8c15SMilanka Ringwald /* EXAMPLE_END */ 612