1fffdd288SMatthias Ringwald /* 2fffdd288SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3fffdd288SMatthias Ringwald * 4fffdd288SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5fffdd288SMatthias Ringwald * modification, are permitted provided that the following conditions 6fffdd288SMatthias Ringwald * are met: 7fffdd288SMatthias Ringwald * 8fffdd288SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9fffdd288SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10fffdd288SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11fffdd288SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12fffdd288SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13fffdd288SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14fffdd288SMatthias Ringwald * contributors may be used to endorse or promote products derived 15fffdd288SMatthias Ringwald * from this software without specific prior written permission. 16fffdd288SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17fffdd288SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18fffdd288SMatthias Ringwald * monetary gain. 19fffdd288SMatthias Ringwald * 20fffdd288SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21fffdd288SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22fffdd288SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23fffdd288SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24fffdd288SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25fffdd288SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26fffdd288SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27fffdd288SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28fffdd288SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29fffdd288SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30fffdd288SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31fffdd288SMatthias Ringwald * SUCH DAMAGE. 32fffdd288SMatthias Ringwald * 33fffdd288SMatthias Ringwald * Please inquire about commercial licensing options at 34fffdd288SMatthias Ringwald * [email protected] 35fffdd288SMatthias Ringwald * 36fffdd288SMatthias Ringwald */ 37*ab2c6ae4SMatthias Ringwald 38*ab2c6ae4SMatthias Ringwald #define __BTSTACK_FILE__ "hfp_ag_demo.c" 39fffdd288SMatthias Ringwald 40fffdd288SMatthias Ringwald /* 41fffdd288SMatthias Ringwald * hfp_ag_demo.c 42fffdd288SMatthias Ringwald */ 43fffdd288SMatthias Ringwald 44fffdd288SMatthias Ringwald // ***************************************************************************** 45fffdd288SMatthias Ringwald /* EXAMPLE_START(hfp_ag_demo): HFP Audio Gateway (AG) Demo 46fffdd288SMatthias Ringwald * 47fffdd288SMatthias Ringwald * @text This HFP Audio Gateway example demonstrates how to receive 48fffdd288SMatthias Ringwald * an output from a remote HFP Hands-Free (HF) unit, and, 49d0755cd6SMatthias Ringwald * if HAVE_POSIX_STDIN is defined, how to control the HFP HF. 50fffdd288SMatthias Ringwald */ 51fffdd288SMatthias Ringwald // ***************************************************************************** 52fffdd288SMatthias Ringwald 53fffdd288SMatthias Ringwald 54fffdd288SMatthias Ringwald #include <stdint.h> 55fffdd288SMatthias Ringwald #include <stdio.h> 56fffdd288SMatthias Ringwald #include <stdlib.h> 57fffdd288SMatthias Ringwald #include <string.h> 58fffdd288SMatthias Ringwald #include <unistd.h> 59fffdd288SMatthias Ringwald 60fffdd288SMatthias Ringwald #include "btstack.h" 61185c8cd4SMatthias Ringwald #include "sco_demo_util.h" 62d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 63fffdd288SMatthias Ringwald #include "stdin_support.h" 644af4141bSMatthias Ringwald #endif 65fffdd288SMatthias Ringwald 66fffdd288SMatthias Ringwald uint8_t hfp_service_buffer[150]; 67fffdd288SMatthias Ringwald const uint8_t rfcomm_channel_nr = 1; 68fffdd288SMatthias Ringwald const char hfp_ag_service_name[] = "BTstack HFP AG Test"; 69fffdd288SMatthias Ringwald 700e62b7a5SMatthias Ringwald static bd_addr_t device_addr; 710e62b7a5SMatthias Ringwald static const char * device_addr_string = "00:15:83:5F:9D:46"; 72fffdd288SMatthias Ringwald 731bbecc2bSMatthias Ringwald #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 74fa5e2954SMatthias Ringwald static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; 751bbecc2bSMatthias Ringwald #else 761bbecc2bSMatthias Ringwald static uint8_t codecs[] = {HFP_CODEC_CVSD}; 771bbecc2bSMatthias Ringwald #endif 781bbecc2bSMatthias Ringwald 79220eb563SMilanka Ringwald static uint8_t negotiated_codec = HFP_CODEC_CVSD; 80220eb563SMilanka Ringwald 81d97d752dSMilanka Ringwald static hci_con_handle_t acl_handle = -1; 823cef842bSMatthias Ringwald static hci_con_handle_t sco_handle; 83fffdd288SMatthias Ringwald static int memory_1_enabled = 1; 84186bfbecSMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 85fffdd288SMatthias Ringwald 86fffdd288SMatthias Ringwald static int ag_indicators_nr = 7; 87fffdd288SMatthias Ringwald static hfp_ag_indicator_t ag_indicators[] = { 88fffdd288SMatthias Ringwald // index, name, min range, max range, status, mandatory, enabled, status changed 89fffdd288SMatthias Ringwald {1, "service", 0, 1, 1, 0, 0, 0}, 90fffdd288SMatthias Ringwald {2, "call", 0, 1, 0, 1, 1, 0}, 91fffdd288SMatthias Ringwald {3, "callsetup", 0, 3, 0, 1, 1, 0}, 92fffdd288SMatthias Ringwald {4, "battchg", 0, 5, 3, 0, 0, 0}, 93fffdd288SMatthias Ringwald {5, "signal", 0, 5, 5, 0, 1, 0}, 94fffdd288SMatthias Ringwald {6, "roam", 0, 1, 0, 0, 1, 0}, 95fffdd288SMatthias Ringwald {7, "callheld", 0, 2, 0, 1, 1, 0} 96fffdd288SMatthias Ringwald }; 97fffdd288SMatthias Ringwald 98fffdd288SMatthias Ringwald static int call_hold_services_nr = 5; 99fffdd288SMatthias Ringwald static const char* call_hold_services[] = {"1", "1x", "2", "2x", "3"}; 100fffdd288SMatthias Ringwald 101fffdd288SMatthias Ringwald static int hf_indicators_nr = 2; 102fffdd288SMatthias Ringwald static hfp_generic_status_indicator_t hf_indicators[] = { 103fffdd288SMatthias Ringwald {1, 1}, 104fffdd288SMatthias Ringwald {2, 1}, 105fffdd288SMatthias Ringwald }; 106fffdd288SMatthias Ringwald 107fffdd288SMatthias Ringwald char cmd; 108fffdd288SMatthias Ringwald 109fffdd288SMatthias Ringwald // GAP INQUIRY 110fffdd288SMatthias Ringwald 111fffdd288SMatthias Ringwald #define MAX_DEVICES 10 112fffdd288SMatthias Ringwald enum DEVICE_STATE { REMOTE_NAME_REQUEST, REMOTE_NAME_INQUIRED, REMOTE_NAME_FETCHED }; 113fffdd288SMatthias Ringwald struct device { 114fffdd288SMatthias Ringwald bd_addr_t address; 115fffdd288SMatthias Ringwald uint16_t clockOffset; 116fffdd288SMatthias Ringwald uint32_t classOfDevice; 117fffdd288SMatthias Ringwald uint8_t pageScanRepetitionMode; 118fffdd288SMatthias Ringwald uint8_t rssi; 119fffdd288SMatthias Ringwald enum DEVICE_STATE state; 120fffdd288SMatthias Ringwald }; 121fffdd288SMatthias Ringwald 122fffdd288SMatthias Ringwald #define INQUIRY_INTERVAL 5 123fffdd288SMatthias Ringwald struct device devices[MAX_DEVICES]; 124fffdd288SMatthias Ringwald int deviceCount = 0; 125fffdd288SMatthias Ringwald 126fffdd288SMatthias Ringwald 127fffdd288SMatthias Ringwald enum STATE {INIT, W4_INQUIRY_MODE_COMPLETE, ACTIVE} ; 128fffdd288SMatthias Ringwald enum STATE state = INIT; 129fffdd288SMatthias Ringwald 1303b9522a6SMatthias Ringwald static void dump_supported_codecs(void){ 131b3f76298SMilanka Ringwald int i; 132f9f7adeeSMatthias Ringwald int mSBC_skipped = 0; 133b3f76298SMilanka Ringwald printf("Supported codecs: "); 134b3f76298SMilanka Ringwald for (i = 0; i < sizeof(codecs); i++){ 135b3f76298SMilanka Ringwald switch(codecs[i]){ 136b3f76298SMilanka Ringwald case HFP_CODEC_CVSD: 137b3f76298SMilanka Ringwald printf("CVSD"); 138b3f76298SMilanka Ringwald break; 139b3f76298SMilanka Ringwald case HFP_CODEC_MSBC: 140f9f7adeeSMatthias Ringwald if (hci_extended_sco_link_supported()){ 1412308e108SMilanka Ringwald printf(", mSBC"); 142f9f7adeeSMatthias Ringwald } else { 143f9f7adeeSMatthias Ringwald mSBC_skipped = 1; 144f9f7adeeSMatthias Ringwald } 145b3f76298SMilanka Ringwald break; 146b3f76298SMilanka Ringwald } 147b3f76298SMilanka Ringwald } 148b3f76298SMilanka Ringwald printf("\n"); 149f9f7adeeSMatthias Ringwald if (mSBC_skipped){ 150f9f7adeeSMatthias Ringwald printf("mSBC codec disabled because eSCO not supported by local controller.\n"); 151f9f7adeeSMatthias Ringwald } 152b3f76298SMilanka Ringwald } 153fffdd288SMatthias Ringwald 154fffdd288SMatthias Ringwald static int getDeviceIndexForAddress( bd_addr_t addr){ 155fffdd288SMatthias Ringwald int j; 156fffdd288SMatthias Ringwald for (j=0; j< deviceCount; j++){ 157fffdd288SMatthias Ringwald if (bd_addr_cmp(addr, devices[j].address) == 0){ 158fffdd288SMatthias Ringwald return j; 159fffdd288SMatthias Ringwald } 160fffdd288SMatthias Ringwald } 161fffdd288SMatthias Ringwald return -1; 162fffdd288SMatthias Ringwald } 163fffdd288SMatthias Ringwald 164d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 165fffdd288SMatthias Ringwald static void start_scan(void){ 166fffdd288SMatthias Ringwald printf("Starting inquiry scan..\n"); 167fffdd288SMatthias Ringwald hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, INQUIRY_INTERVAL, 0); 168fffdd288SMatthias Ringwald } 169fffdd288SMatthias Ringwald #endif 170fffdd288SMatthias Ringwald 171fffdd288SMatthias Ringwald static int has_more_remote_name_requests(void){ 172fffdd288SMatthias Ringwald int i; 173fffdd288SMatthias Ringwald for (i=0;i<deviceCount;i++) { 174fffdd288SMatthias Ringwald if (devices[i].state == REMOTE_NAME_REQUEST) return 1; 175fffdd288SMatthias Ringwald } 176fffdd288SMatthias Ringwald return 0; 177fffdd288SMatthias Ringwald } 178fffdd288SMatthias Ringwald 179fffdd288SMatthias Ringwald static void do_next_remote_name_request(void){ 180fffdd288SMatthias Ringwald int i; 181fffdd288SMatthias Ringwald for (i=0;i<deviceCount;i++) { 182fffdd288SMatthias Ringwald // remote name request 183fffdd288SMatthias Ringwald if (devices[i].state == REMOTE_NAME_REQUEST){ 184fffdd288SMatthias Ringwald devices[i].state = REMOTE_NAME_INQUIRED; 185fffdd288SMatthias Ringwald printf("Get remote name of %s...\n", bd_addr_to_str(devices[i].address)); 186fffdd288SMatthias Ringwald hci_send_cmd(&hci_remote_name_request, devices[i].address, 187fffdd288SMatthias Ringwald devices[i].pageScanRepetitionMode, 0, devices[i].clockOffset | 0x8000); 188fffdd288SMatthias Ringwald return; 189fffdd288SMatthias Ringwald } 190fffdd288SMatthias Ringwald } 191fffdd288SMatthias Ringwald } 192fffdd288SMatthias Ringwald 193fffdd288SMatthias Ringwald static void continue_remote_names(void){ 194fffdd288SMatthias Ringwald // don't get remote names for testing 195fffdd288SMatthias Ringwald if (has_more_remote_name_requests()){ 196fffdd288SMatthias Ringwald do_next_remote_name_request(); 197fffdd288SMatthias Ringwald return; 198fffdd288SMatthias Ringwald } 199fffdd288SMatthias Ringwald // try to find PTS 200fffdd288SMatthias Ringwald int i; 201fffdd288SMatthias Ringwald for (i=0;i<deviceCount;i++){ 202fffdd288SMatthias Ringwald if (memcmp(devices[i].address, device_addr, 6) == 0){ 203fffdd288SMatthias Ringwald printf("Inquiry scan over, successfully found PTS at index %u\nReady to connect to it.\n", i); 204fffdd288SMatthias Ringwald return; 205fffdd288SMatthias Ringwald } 206fffdd288SMatthias Ringwald } 207fffdd288SMatthias Ringwald printf("Inquiry scan over but PTS not found :(\n"); 208fffdd288SMatthias Ringwald } 209fffdd288SMatthias Ringwald 210fffdd288SMatthias Ringwald static void inquiry_packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){ 2119ec2630cSMatthias Ringwald UNUSED(size); 2129ec2630cSMatthias Ringwald 213fffdd288SMatthias Ringwald bd_addr_t addr; 214fffdd288SMatthias Ringwald int i; 215fffdd288SMatthias Ringwald int numResponses; 216fffdd288SMatthias Ringwald int index; 217fffdd288SMatthias Ringwald 218fffdd288SMatthias Ringwald // printf("packet_handler: pt: 0x%02x, packet[0]: 0x%02x\n", packet_type, packet[0]); 219fffdd288SMatthias Ringwald if (packet_type != HCI_EVENT_PACKET) return; 220fffdd288SMatthias Ringwald 221fffdd288SMatthias Ringwald uint8_t event = packet[0]; 222fffdd288SMatthias Ringwald 223fffdd288SMatthias Ringwald switch(event){ 224fffdd288SMatthias Ringwald case HCI_EVENT_INQUIRY_RESULT: 225fffdd288SMatthias Ringwald case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:{ 226f8744deaSMilanka Ringwald numResponses = hci_event_inquiry_result_get_num_responses(packet); 227fffdd288SMatthias Ringwald int offset = 3; 228fffdd288SMatthias Ringwald for (i=0; i<numResponses && deviceCount < MAX_DEVICES;i++){ 229e64e0086SMatthias Ringwald reverse_bd_addr(&packet[offset], addr); 230fffdd288SMatthias Ringwald offset += 6; 231fffdd288SMatthias Ringwald index = getDeviceIndexForAddress(addr); 232fffdd288SMatthias Ringwald if (index >= 0) continue; // already in our list 233fffdd288SMatthias Ringwald memcpy(devices[deviceCount].address, addr, 6); 234fffdd288SMatthias Ringwald 235fffdd288SMatthias Ringwald devices[deviceCount].pageScanRepetitionMode = packet[offset]; 236fffdd288SMatthias Ringwald offset += 1; 237fffdd288SMatthias Ringwald 238fffdd288SMatthias Ringwald if (event == HCI_EVENT_INQUIRY_RESULT){ 239fffdd288SMatthias Ringwald offset += 2; // Reserved + Reserved 240fffdd288SMatthias Ringwald devices[deviceCount].classOfDevice = little_endian_read_24(packet, offset); 241fffdd288SMatthias Ringwald offset += 3; 242fffdd288SMatthias Ringwald devices[deviceCount].clockOffset = little_endian_read_16(packet, offset) & 0x7fff; 243fffdd288SMatthias Ringwald offset += 2; 244fffdd288SMatthias Ringwald devices[deviceCount].rssi = 0; 245fffdd288SMatthias Ringwald } else { 246fffdd288SMatthias Ringwald offset += 1; // Reserved 247fffdd288SMatthias Ringwald devices[deviceCount].classOfDevice = little_endian_read_24(packet, offset); 248fffdd288SMatthias Ringwald offset += 3; 249fffdd288SMatthias Ringwald devices[deviceCount].clockOffset = little_endian_read_16(packet, offset) & 0x7fff; 250fffdd288SMatthias Ringwald offset += 2; 251fffdd288SMatthias Ringwald devices[deviceCount].rssi = packet[offset]; 252fffdd288SMatthias Ringwald offset += 1; 253fffdd288SMatthias Ringwald } 254fffdd288SMatthias Ringwald devices[deviceCount].state = REMOTE_NAME_REQUEST; 255fffdd288SMatthias Ringwald printf("Device #%u found: %s with COD: 0x%06x, pageScan %d, clock offset 0x%04x, rssi 0x%02x\n", 256fffdd288SMatthias Ringwald deviceCount, bd_addr_to_str(addr), 257fffdd288SMatthias Ringwald devices[deviceCount].classOfDevice, devices[deviceCount].pageScanRepetitionMode, 258fffdd288SMatthias Ringwald devices[deviceCount].clockOffset, devices[deviceCount].rssi); 259fffdd288SMatthias Ringwald deviceCount++; 260fffdd288SMatthias Ringwald } 261fffdd288SMatthias Ringwald 262fffdd288SMatthias Ringwald break; 263fffdd288SMatthias Ringwald } 264fffdd288SMatthias Ringwald case HCI_EVENT_INQUIRY_COMPLETE: 265fffdd288SMatthias Ringwald for (i=0;i<deviceCount;i++) { 266fffdd288SMatthias Ringwald // retry remote name request 267fffdd288SMatthias Ringwald if (devices[i].state == REMOTE_NAME_INQUIRED) 268fffdd288SMatthias Ringwald devices[i].state = REMOTE_NAME_REQUEST; 269fffdd288SMatthias Ringwald } 270fffdd288SMatthias Ringwald continue_remote_names(); 271fffdd288SMatthias Ringwald break; 272fffdd288SMatthias Ringwald 273fffdd288SMatthias Ringwald case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: 274e64e0086SMatthias Ringwald reverse_bd_addr(&packet[3], addr); 275fffdd288SMatthias Ringwald index = getDeviceIndexForAddress(addr); 276fffdd288SMatthias Ringwald if (index >= 0) { 277fffdd288SMatthias Ringwald if (packet[2] == 0) { 278fffdd288SMatthias Ringwald printf("Name: '%s'\n", &packet[9]); 279fffdd288SMatthias Ringwald devices[index].state = REMOTE_NAME_FETCHED; 280fffdd288SMatthias Ringwald } else { 281fffdd288SMatthias Ringwald printf("Failed to get name: page timeout\n"); 282fffdd288SMatthias Ringwald } 283fffdd288SMatthias Ringwald } 284fffdd288SMatthias Ringwald continue_remote_names(); 285fffdd288SMatthias Ringwald break; 286fffdd288SMatthias Ringwald 287fffdd288SMatthias Ringwald default: 288fffdd288SMatthias Ringwald break; 289fffdd288SMatthias Ringwald } 290fffdd288SMatthias Ringwald } 291fffdd288SMatthias Ringwald // GAP INQUIRY END 292d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 293fffdd288SMatthias Ringwald 294fffdd288SMatthias Ringwald // prototypes 29535833313SMatthias Ringwald static void show_usage(void); 296fffdd288SMatthias Ringwald 297fffdd288SMatthias Ringwald // Testig User Interface 298fffdd288SMatthias Ringwald static void show_usage(void){ 299e64e0086SMatthias Ringwald bd_addr_t iut_address; 300e64e0086SMatthias Ringwald gap_local_bd_addr(iut_address); 301e64e0086SMatthias Ringwald 302e64e0086SMatthias Ringwald printf("\n--- Bluetooth HFP Audiogateway (AG) unit Test Console %s ---\n", bd_addr_to_str(iut_address)); 3038a7d93dcSMatthias Ringwald printf("\n"); 304fffdd288SMatthias Ringwald 305bdb44bd9SMatthias Ringwald printf("a - establish HFP connection to PTS module %s\n", bd_addr_to_str(device_addr)); 306fffdd288SMatthias Ringwald // printf("A - release HFP connection to PTS module\n"); 307fffdd288SMatthias Ringwald 3088a7d93dcSMatthias Ringwald printf("b - establish AUDIO connection | B - release AUDIO connection\n"); 3098a7d93dcSMatthias Ringwald printf("c - simulate incoming call from 1234567 | C - simulate call from 1234567 dropped\n"); 310fffdd288SMatthias Ringwald printf("d - report AG failure\n"); 3118a7d93dcSMatthias Ringwald printf("e - answer call on AG | E - reject call on AG\n"); 3128a7d93dcSMatthias Ringwald printf("r - disable in-band ring tone | R - enable in-band ring tone\n"); 3138a7d93dcSMatthias Ringwald printf("f - Disable cellular network | F - Enable cellular network\n"); 3148a7d93dcSMatthias Ringwald printf("g - Set signal strength to 0 | G - Set signal strength to 5\n"); 3158a7d93dcSMatthias Ringwald printf("h - Disable roaming | H - Enable roaming\n"); 3168a7d93dcSMatthias Ringwald printf("i - Set battery level to 3 | I - Set battery level to 5\n"); 317fffdd288SMatthias Ringwald printf("j - Answering call on remote side\n"); 3188a7d93dcSMatthias Ringwald printf("k - Clear memory #1 | K - Set memory #1\n"); 3198a7d93dcSMatthias Ringwald printf("l - Clear last number | L - Set last number\n"); 320fffdd288SMatthias Ringwald printf("m - simulate incoming call from 7654321\n"); 321fffdd288SMatthias Ringwald // printf("M - simulate call from 7654321 dropped\n"); 3228a7d93dcSMatthias Ringwald printf("n - Disable Voice Regocnition | N - Enable Voice Recognition\n"); 3238a7d93dcSMatthias Ringwald printf("o - Set speaker volume to 0 (minimum) | O - Set speaker volume to 9 (default)\n"); 3248a7d93dcSMatthias Ringwald printf("p - Set speaker volume to 12 (higher) | P - Set speaker volume to 15 (maximum)\n"); 3258a7d93dcSMatthias Ringwald printf("q - Set microphone gain to 0 (minimum) | Q - Set microphone gain to 9 (default)\n"); 3268a7d93dcSMatthias Ringwald printf("s - Set microphone gain to 12 (higher) | S - Set microphone gain to 15 (maximum)\n"); 327fffdd288SMatthias Ringwald printf("t - terminate connection\n"); 328fffdd288SMatthias Ringwald printf("u - join held call\n"); 329fffdd288SMatthias Ringwald printf("v - discover nearby HF units\n"); 330fffdd288SMatthias Ringwald printf("w - put incoming call on hold (Response and Hold)\n"); 331fffdd288SMatthias Ringwald printf("x - accept held incoming call (Response and Hold)\n"); 332fffdd288SMatthias Ringwald printf("X - reject held incoming call (Response and Hold)\n"); 333fffdd288SMatthias Ringwald 334fffdd288SMatthias Ringwald printf("---\n"); 335fffdd288SMatthias Ringwald printf("Ctrl-c - exit\n"); 336fffdd288SMatthias Ringwald printf("---\n"); 337fffdd288SMatthias Ringwald } 338fffdd288SMatthias Ringwald 3394af4141bSMatthias Ringwald static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){ 3409ec2630cSMatthias Ringwald UNUSED(ds); 3419ec2630cSMatthias Ringwald UNUSED(callback_type); 3429ec2630cSMatthias Ringwald 343a1dc4edbSMatthias Ringwald cmd = btstack_stdin_read(); 344fffdd288SMatthias Ringwald switch (cmd){ 345fffdd288SMatthias Ringwald case 'a': 346fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 347fffdd288SMatthias Ringwald printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr)); 348fffdd288SMatthias Ringwald hfp_ag_establish_service_level_connection(device_addr); 349fffdd288SMatthias Ringwald break; 350fffdd288SMatthias Ringwald case 'A': 351fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 352fffdd288SMatthias Ringwald printf("Release HFP service level connection.\n"); 353d97d752dSMilanka Ringwald hfp_ag_release_service_level_connection(acl_handle); 354fffdd288SMatthias Ringwald break; 355fffdd288SMatthias Ringwald case 'Z': 356fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 357fffdd288SMatthias Ringwald printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr)); 358d97d752dSMilanka Ringwald hfp_ag_release_service_level_connection(acl_handle); 359fffdd288SMatthias Ringwald break; 360fffdd288SMatthias Ringwald case 'b': 361fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 362fffdd288SMatthias Ringwald printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr)); 363d97d752dSMilanka Ringwald hfp_ag_establish_audio_connection(acl_handle); 364fffdd288SMatthias Ringwald break; 365fffdd288SMatthias Ringwald case 'B': 366fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 367fffdd288SMatthias Ringwald printf("Release Audio connection.\n"); 368d97d752dSMilanka Ringwald hfp_ag_release_audio_connection(acl_handle); 369fffdd288SMatthias Ringwald break; 370fffdd288SMatthias Ringwald case 'c': 371fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 372fffdd288SMatthias Ringwald printf("Simulate incoming call from 1234567\n"); 373fffdd288SMatthias Ringwald hfp_ag_set_clip(129, "1234567"); 374fffdd288SMatthias Ringwald hfp_ag_incoming_call(); 375fffdd288SMatthias Ringwald break; 376fffdd288SMatthias Ringwald case 'm': 377fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 378fffdd288SMatthias Ringwald printf("Simulate incoming call from 7654321\n"); 379fffdd288SMatthias Ringwald hfp_ag_set_clip(129, "7654321"); 380fffdd288SMatthias Ringwald hfp_ag_incoming_call(); 381fffdd288SMatthias Ringwald break; 382fffdd288SMatthias Ringwald case 'C': 383fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 384fffdd288SMatthias Ringwald printf("Simulate terminate call\n"); 385fffdd288SMatthias Ringwald hfp_ag_call_dropped(); 386fffdd288SMatthias Ringwald break; 387fffdd288SMatthias Ringwald case 'd': 388fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 389fffdd288SMatthias Ringwald printf("Report AG failure\n"); 390d97d752dSMilanka Ringwald hfp_ag_report_extended_audio_gateway_error_result_code(acl_handle, HFP_CME_ERROR_AG_FAILURE); 391fffdd288SMatthias Ringwald break; 392fffdd288SMatthias Ringwald case 'e': 393fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 394fffdd288SMatthias Ringwald printf("Answer call on AG\n"); 395fffdd288SMatthias Ringwald hfp_ag_answer_incoming_call(); 396fffdd288SMatthias Ringwald break; 397fffdd288SMatthias Ringwald case 'E': 398fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 399fffdd288SMatthias Ringwald printf("Reject call on AG\n"); 400fffdd288SMatthias Ringwald hfp_ag_terminate_call(); 401fffdd288SMatthias Ringwald break; 402fffdd288SMatthias Ringwald case 'f': 403fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 404fffdd288SMatthias Ringwald printf("Disable cellular network\n"); 405fffdd288SMatthias Ringwald hfp_ag_set_registration_status(0); 406fffdd288SMatthias Ringwald break; 407fffdd288SMatthias Ringwald case 'F': 408fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 409fffdd288SMatthias Ringwald printf("Enable cellular network\n"); 410fffdd288SMatthias Ringwald hfp_ag_set_registration_status(1); 411fffdd288SMatthias Ringwald break; 412fffdd288SMatthias Ringwald case 'g': 413fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 414fffdd288SMatthias Ringwald printf("Set signal strength to 0\n"); 415fffdd288SMatthias Ringwald hfp_ag_set_signal_strength(0); 416fffdd288SMatthias Ringwald break; 417fffdd288SMatthias Ringwald case 'G': 418fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 419fffdd288SMatthias Ringwald printf("Set signal strength to 5\n"); 420fffdd288SMatthias Ringwald hfp_ag_set_signal_strength(5); 421fffdd288SMatthias Ringwald break; 422fffdd288SMatthias Ringwald case 'h': 423fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 424fffdd288SMatthias Ringwald printf("Disable roaming\n"); 425fffdd288SMatthias Ringwald hfp_ag_set_roaming_status(0); 426fffdd288SMatthias Ringwald break; 427fffdd288SMatthias Ringwald case 'H': 428fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 429fffdd288SMatthias Ringwald printf("Enable roaming\n"); 430fffdd288SMatthias Ringwald hfp_ag_set_roaming_status(1); 431fffdd288SMatthias Ringwald break; 432fffdd288SMatthias Ringwald case 'i': 433fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 434fffdd288SMatthias Ringwald printf("Set battery level to 3\n"); 435fffdd288SMatthias Ringwald hfp_ag_set_battery_level(3); 436fffdd288SMatthias Ringwald break; 437fffdd288SMatthias Ringwald case 'I': 438fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 439fffdd288SMatthias Ringwald printf("Set battery level to 5\n"); 440fffdd288SMatthias Ringwald hfp_ag_set_battery_level(5); 441fffdd288SMatthias Ringwald break; 442fffdd288SMatthias Ringwald case 'j': 443fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 444fffdd288SMatthias Ringwald printf("Answering call on remote side\n"); 445fffdd288SMatthias Ringwald hfp_ag_outgoing_call_established(); 446fffdd288SMatthias Ringwald break; 447fffdd288SMatthias Ringwald case 'r': 448fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 449fffdd288SMatthias Ringwald printf("Disable in-band ring tone\n"); 450fffdd288SMatthias Ringwald hfp_ag_set_use_in_band_ring_tone(0); 451fffdd288SMatthias Ringwald break; 452fffdd288SMatthias Ringwald case 'k': 453fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 454fffdd288SMatthias Ringwald printf("Memory 1 cleared\n"); 455fffdd288SMatthias Ringwald memory_1_enabled = 0; 456fffdd288SMatthias Ringwald break; 457fffdd288SMatthias Ringwald case 'K': 458fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 459fffdd288SMatthias Ringwald printf("Memory 1 set\n"); 460fffdd288SMatthias Ringwald memory_1_enabled = 1; 461fffdd288SMatthias Ringwald break; 462fffdd288SMatthias Ringwald case 'l': 463fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 464fffdd288SMatthias Ringwald printf("Last dialed number cleared\n"); 465fffdd288SMatthias Ringwald hfp_ag_clear_last_dialed_number(); 466fffdd288SMatthias Ringwald break; 467fffdd288SMatthias Ringwald case 'L': 468fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 469fffdd288SMatthias Ringwald printf("Outgoing call connected, ringing\n"); 470fffdd288SMatthias Ringwald hfp_ag_outgoing_call_ringing(); 471fffdd288SMatthias Ringwald break; 472fffdd288SMatthias Ringwald case 'n': 473fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 474fffdd288SMatthias Ringwald printf("Disable Voice Recognition\n"); 475d97d752dSMilanka Ringwald hfp_ag_activate_voice_recognition(acl_handle, 0); 476fffdd288SMatthias Ringwald break; 477fffdd288SMatthias Ringwald case 'N': 478fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 479fffdd288SMatthias Ringwald printf("Enable Voice Recognition\n"); 480d97d752dSMilanka Ringwald hfp_ag_activate_voice_recognition(acl_handle, 1); 481fffdd288SMatthias Ringwald break; 482fffdd288SMatthias Ringwald case 'o': 483fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 484fffdd288SMatthias Ringwald printf("Set speaker gain to 0 (minimum)\n"); 485d97d752dSMilanka Ringwald hfp_ag_set_speaker_gain(acl_handle, 0); 486fffdd288SMatthias Ringwald break; 487fffdd288SMatthias Ringwald case 'O': 488fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 489fffdd288SMatthias Ringwald printf("Set speaker gain to 9 (default)\n"); 490d97d752dSMilanka Ringwald hfp_ag_set_speaker_gain(acl_handle, 9); 491fffdd288SMatthias Ringwald break; 492fffdd288SMatthias Ringwald case 'p': 493fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 494fffdd288SMatthias Ringwald printf("Set speaker gain to 12 (higher)\n"); 495d97d752dSMilanka Ringwald hfp_ag_set_speaker_gain(acl_handle, 12); 496fffdd288SMatthias Ringwald break; 497fffdd288SMatthias Ringwald case 'P': 498fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 499fffdd288SMatthias Ringwald printf("Set speaker gain to 15 (maximum)\n"); 500d97d752dSMilanka Ringwald hfp_ag_set_speaker_gain(acl_handle, 15); 501fffdd288SMatthias Ringwald break; 502fffdd288SMatthias Ringwald case 'q': 503fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 504fffdd288SMatthias Ringwald printf("Set microphone gain to 0\n"); 505d97d752dSMilanka Ringwald hfp_ag_set_microphone_gain(acl_handle, 0); 506fffdd288SMatthias Ringwald break; 507fffdd288SMatthias Ringwald case 'Q': 508fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 509fffdd288SMatthias Ringwald printf("Set microphone gain to 9\n"); 510d97d752dSMilanka Ringwald hfp_ag_set_microphone_gain(acl_handle, 9); 511fffdd288SMatthias Ringwald break; 512fffdd288SMatthias Ringwald case 's': 513fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 514fffdd288SMatthias Ringwald printf("Set microphone gain to 12\n"); 515d97d752dSMilanka Ringwald hfp_ag_set_microphone_gain(acl_handle, 12); 516fffdd288SMatthias Ringwald break; 517fffdd288SMatthias Ringwald case 'S': 518fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 519fffdd288SMatthias Ringwald printf("Set microphone gain to 15\n"); 520d97d752dSMilanka Ringwald hfp_ag_set_microphone_gain(acl_handle, 15); 521fffdd288SMatthias Ringwald break; 522fffdd288SMatthias Ringwald case 'R': 523fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 524fffdd288SMatthias Ringwald printf("Enable in-band ring tone\n"); 525fffdd288SMatthias Ringwald hfp_ag_set_use_in_band_ring_tone(1); 526fffdd288SMatthias Ringwald break; 527fffdd288SMatthias Ringwald case 't': 528fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 529d97d752dSMilanka Ringwald printf("Terminate HCI connection. 0x%2x\n", acl_handle); 530d97d752dSMilanka Ringwald gap_disconnect(acl_handle); 531fffdd288SMatthias Ringwald break; 532fffdd288SMatthias Ringwald case 'u': 533fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 534fffdd288SMatthias Ringwald printf("Join held call\n"); 535fffdd288SMatthias Ringwald hfp_ag_join_held_call(); 536fffdd288SMatthias Ringwald break; 537fffdd288SMatthias Ringwald case 'v': 538fffdd288SMatthias Ringwald start_scan(); 539fffdd288SMatthias Ringwald break; 540fffdd288SMatthias Ringwald case 'w': 541fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 542fffdd288SMatthias Ringwald printf("AG: Put incoming call on hold (Response and Hold)\n"); 543fffdd288SMatthias Ringwald hfp_ag_hold_incoming_call(); 544fffdd288SMatthias Ringwald break; 545fffdd288SMatthias Ringwald case 'x': 546fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 547fffdd288SMatthias Ringwald printf("AG: Accept held incoming call (Response and Hold)\n"); 548fffdd288SMatthias Ringwald hfp_ag_accept_held_incoming_call(); 549fffdd288SMatthias Ringwald break; 550fffdd288SMatthias Ringwald case 'X': 551fffdd288SMatthias Ringwald log_info("USER:\'%c\'", cmd); 552fffdd288SMatthias Ringwald printf("AG: Reject held incoming call (Response and Hold)\n"); 553fffdd288SMatthias Ringwald hfp_ag_reject_held_incoming_call(); 554fffdd288SMatthias Ringwald break; 555fffdd288SMatthias Ringwald default: 556fffdd288SMatthias Ringwald show_usage(); 557fffdd288SMatthias Ringwald break; 558fffdd288SMatthias Ringwald } 559fffdd288SMatthias Ringwald } 560fffdd288SMatthias Ringwald #endif 561fffdd288SMatthias Ringwald 56213839019SMatthias Ringwald static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){ 5639ec2630cSMatthias Ringwald UNUSED(channel); 5649ec2630cSMatthias Ringwald 5653cef842bSMatthias Ringwald switch (packet_type){ 5663cef842bSMatthias Ringwald case HCI_EVENT_PACKET: 567fffdd288SMatthias Ringwald switch (event[0]){ 568fffdd288SMatthias Ringwald case HCI_EVENT_INQUIRY_RESULT: 569fffdd288SMatthias Ringwald case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: 570fffdd288SMatthias Ringwald case HCI_EVENT_INQUIRY_COMPLETE: 571fffdd288SMatthias Ringwald case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: 572fffdd288SMatthias Ringwald inquiry_packet_handler(HCI_EVENT_PACKET, event, event_size); 573fffdd288SMatthias Ringwald break; 57413839019SMatthias Ringwald case HCI_EVENT_SCO_CAN_SEND_NOW: 575185c8cd4SMatthias Ringwald sco_demo_send(sco_handle); 57613839019SMatthias Ringwald break; 57792bac129SMatthias Ringwald case HCI_EVENT_COMMAND_COMPLETE: 57892bac129SMatthias Ringwald if (HCI_EVENT_IS_COMMAND_COMPLETE(event, hci_read_local_supported_features)){ 579f9f7adeeSMatthias Ringwald dump_supported_codecs(); 58092bac129SMatthias Ringwald } 58192bac129SMatthias Ringwald break; 582fffdd288SMatthias Ringwald default: 583fffdd288SMatthias Ringwald break; 584fffdd288SMatthias Ringwald } 585fffdd288SMatthias Ringwald 586fffdd288SMatthias Ringwald if (event[0] != HCI_EVENT_HFP_META) return; 587fffdd288SMatthias Ringwald 588fffdd288SMatthias Ringwald if (event[3] 589fffdd288SMatthias Ringwald && event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER 590fffdd288SMatthias Ringwald && event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG 591fffdd288SMatthias Ringwald && event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){ 592fffdd288SMatthias Ringwald printf("ERROR, status: %u\n", event[3]); 593fffdd288SMatthias Ringwald return; 594fffdd288SMatthias Ringwald } 595fffdd288SMatthias Ringwald 596fffdd288SMatthias Ringwald switch (event[2]) { 597fffdd288SMatthias Ringwald case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: 598d97d752dSMilanka Ringwald acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event); 59966c297f9SMilanka Ringwald hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr); 60066c297f9SMilanka Ringwald printf("Service level connection established from %s.\n", bd_addr_to_str(device_addr)); 601b3f76298SMilanka Ringwald dump_supported_codecs(); 602fffdd288SMatthias Ringwald break; 603fffdd288SMatthias Ringwald case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED: 604fffdd288SMatthias Ringwald printf("Service level connection released.\n"); 6053cef842bSMatthias Ringwald sco_handle = 0; 606fffdd288SMatthias Ringwald break; 607fffdd288SMatthias Ringwald case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED: 6083cef842bSMatthias Ringwald if (hfp_subevent_audio_connection_established_get_status(event)){ 6093cef842bSMatthias Ringwald printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event)); 6103cef842bSMatthias Ringwald sco_handle = 0; 6113cef842bSMatthias Ringwald } else { 6123cef842bSMatthias Ringwald sco_handle = hfp_subevent_audio_connection_established_get_handle(event); 6133cef842bSMatthias Ringwald printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 614d0c4aea6SMilanka Ringwald negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event); 615f9f7adeeSMatthias Ringwald switch (negotiated_codec){ 616f9f7adeeSMatthias Ringwald case 0x01: 617f9f7adeeSMatthias Ringwald printf("Using CVSD codec.\n"); 618f9f7adeeSMatthias Ringwald break; 619f9f7adeeSMatthias Ringwald case 0x02: 620f9f7adeeSMatthias Ringwald printf("Using mSBC codec.\n"); 621f9f7adeeSMatthias Ringwald break; 622f9f7adeeSMatthias Ringwald default: 623f9f7adeeSMatthias Ringwald printf("Using unknown codec 0x%02x.\n", negotiated_codec); 624f9f7adeeSMatthias Ringwald break; 625f9f7adeeSMatthias Ringwald } 626d0c4aea6SMilanka Ringwald sco_demo_set_codec(negotiated_codec); 6273cef842bSMatthias Ringwald hci_request_sco_can_send_now_event(); 6283cef842bSMatthias Ringwald } 629fffdd288SMatthias Ringwald break; 630fffdd288SMatthias Ringwald case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED: 631b038503dSMatthias Ringwald printf("Audio connection released\n"); 6323cef842bSMatthias Ringwald sco_handle = 0; 633b038503dSMatthias Ringwald sco_demo_close(); 634fffdd288SMatthias Ringwald break; 635fffdd288SMatthias Ringwald case HFP_SUBEVENT_START_RINGINIG: 636b038503dSMatthias Ringwald printf("Start Ringing\n"); 637fffdd288SMatthias Ringwald break; 638fffdd288SMatthias Ringwald case HFP_SUBEVENT_STOP_RINGINIG: 639b038503dSMatthias Ringwald printf("Stop Ringing\n"); 640fffdd288SMatthias Ringwald break; 641fffdd288SMatthias Ringwald case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER: 642b038503dSMatthias Ringwald printf("Outgoing call '%s'\n", hfp_subevent_place_call_with_number_get_number(event)); 643fffdd288SMatthias Ringwald // validate number 6440696953aSMilanka Ringwald if ( strcmp("1234567", hfp_subevent_place_call_with_number_get_number(event)) == 0 6450696953aSMilanka Ringwald || strcmp("7654321", hfp_subevent_place_call_with_number_get_number(event)) == 0 6460696953aSMilanka Ringwald || (memory_1_enabled && strcmp(">1", hfp_subevent_place_call_with_number_get_number(event)) == 0)){ 647fffdd288SMatthias Ringwald printf("Dialstring valid: accept call\n"); 648fffdd288SMatthias Ringwald hfp_ag_outgoing_call_accepted(); 649fffdd288SMatthias Ringwald } else { 650fffdd288SMatthias Ringwald printf("Dialstring invalid: reject call\n"); 651fffdd288SMatthias Ringwald hfp_ag_outgoing_call_rejected(); 652fffdd288SMatthias Ringwald } 653fffdd288SMatthias Ringwald break; 654fffdd288SMatthias Ringwald 655fffdd288SMatthias Ringwald case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG: 656b038503dSMatthias Ringwald printf("Attach number to voice tag. Sending '1234567\n"); 657d97d752dSMilanka Ringwald hfp_ag_send_phone_number_for_voice_tag(acl_handle, "1234567"); 658fffdd288SMatthias Ringwald break; 659fffdd288SMatthias Ringwald case HFP_SUBEVENT_TRANSMIT_DTMF_CODES: 660b038503dSMatthias Ringwald printf("Send DTMF Codes: '%s'\n", hfp_subevent_transmit_dtmf_codes_get_dtmf(event)); 661d97d752dSMilanka Ringwald hfp_ag_send_dtmf_code_done(acl_handle); 662fffdd288SMatthias Ringwald break; 6630696953aSMilanka Ringwald case HFP_SUBEVENT_CALL_ANSWERED: 664fffdd288SMatthias Ringwald printf("Call answered by HF\n"); 665fffdd288SMatthias Ringwald break; 666fffdd288SMatthias Ringwald default: 667fffdd288SMatthias Ringwald printf("Event not handled %u\n", event[2]); 668fffdd288SMatthias Ringwald break; 669fffdd288SMatthias Ringwald } 670185c8cd4SMatthias Ringwald case HCI_SCO_DATA_PACKET: 671185c8cd4SMatthias Ringwald sco_demo_receive(event, event_size); 672185c8cd4SMatthias Ringwald break; 67313839019SMatthias Ringwald default: 67413839019SMatthias Ringwald break; 67513839019SMatthias Ringwald } 676fffdd288SMatthias Ringwald } 677fffdd288SMatthias Ringwald 678fffdd288SMatthias Ringwald static hfp_phone_number_t subscriber_number = { 679fffdd288SMatthias Ringwald 129, "225577" 680fffdd288SMatthias Ringwald }; 681fffdd288SMatthias Ringwald 682fffdd288SMatthias Ringwald /* @section Main Application Setup 683fffdd288SMatthias Ringwald * 684fffdd288SMatthias Ringwald * @text Listing MainConfiguration shows main application code. 685fffdd288SMatthias Ringwald * To run a HFP AG service you need to initialize the SDP, and to create and register HFP AG record with it. 686fffdd288SMatthias Ringwald * The packet_handler is used for sending commands to the HFP HF. It also receives the HFP HF's answers. 687fffdd288SMatthias Ringwald * The stdin_process callback allows for sending commands to the HFP HF. 688fffdd288SMatthias Ringwald * At the end the Bluetooth stack is started. 689fffdd288SMatthias Ringwald */ 690fffdd288SMatthias Ringwald 691fffdd288SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup HFP Audio Gateway */ 692fffdd288SMatthias Ringwald 693fffdd288SMatthias Ringwald int btstack_main(int argc, const char * argv[]); 694fffdd288SMatthias Ringwald int btstack_main(int argc, const char * argv[]){ 6959ec2630cSMatthias Ringwald (void)argc; 6969ec2630cSMatthias Ringwald (void)argv; 697fffdd288SMatthias Ringwald 698185c8cd4SMatthias Ringwald sco_demo_init(); 699185c8cd4SMatthias Ringwald 700a895b9f0SMatthias Ringwald // register for HCI events 701a895b9f0SMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 702a895b9f0SMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 703a895b9f0SMatthias Ringwald hci_register_sco_packet_handler(&packet_handler); 704a895b9f0SMatthias Ringwald 705e64e0086SMatthias Ringwald gap_discoverable_control(1); 706e64e0086SMatthias Ringwald 707e64e0086SMatthias Ringwald // L2CAP 708e64e0086SMatthias Ringwald l2cap_init(); 709e64e0086SMatthias Ringwald 7104f84bf36SMatthias Ringwald uint16_t supported_features = 7114f84bf36SMatthias Ringwald (1<<HFP_AGSF_ESCO_S4) | 7124f84bf36SMatthias Ringwald (1<<HFP_AGSF_HF_INDICATORS) | 7134f84bf36SMatthias Ringwald (1<<HFP_AGSF_CODEC_NEGOTIATION) | 7144f84bf36SMatthias Ringwald (1<<HFP_AGSF_EXTENDED_ERROR_RESULT_CODES) | 7154f84bf36SMatthias Ringwald (1<<HFP_AGSF_ENHANCED_CALL_CONTROL) | 7164f84bf36SMatthias Ringwald (1<<HFP_AGSF_ENHANCED_CALL_STATUS) | 7174f84bf36SMatthias Ringwald (1<<HFP_AGSF_ABILITY_TO_REJECT_A_CALL) | 7184f84bf36SMatthias Ringwald (1<<HFP_AGSF_IN_BAND_RING_TONE) | 7194f84bf36SMatthias Ringwald (1<<HFP_AGSF_VOICE_RECOGNITION_FUNCTION) | 7204f84bf36SMatthias Ringwald (1<<HFP_AGSF_THREE_WAY_CALLING); 7214f84bf36SMatthias Ringwald int wide_band_speech = 1; 7224f84bf36SMatthias Ringwald 723e64e0086SMatthias Ringwald // HFP 724e64e0086SMatthias Ringwald rfcomm_init(); 725fffdd288SMatthias Ringwald hfp_ag_init(rfcomm_channel_nr); 7264f84bf36SMatthias Ringwald hfp_ag_init_supported_features(supported_features); 727fffdd288SMatthias Ringwald hfp_ag_init_codecs(sizeof(codecs), codecs); 728fffdd288SMatthias Ringwald hfp_ag_init_ag_indicators(ag_indicators_nr, ag_indicators); 729fffdd288SMatthias Ringwald hfp_ag_init_hf_indicators(hf_indicators_nr, hf_indicators); 730fffdd288SMatthias Ringwald hfp_ag_init_call_hold_services(call_hold_services_nr, call_hold_services); 731fffdd288SMatthias Ringwald hfp_ag_set_subcriber_number_information(&subscriber_number, 1); 7323cef842bSMatthias Ringwald hfp_ag_register_packet_handler(&packet_handler); 73313839019SMatthias Ringwald hci_register_sco_packet_handler(&packet_handler); 734fffdd288SMatthias Ringwald 735e64e0086SMatthias Ringwald // SDP Server 736e64e0086SMatthias Ringwald sdp_init(); 737fffdd288SMatthias Ringwald memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer)); 7384f84bf36SMatthias Ringwald hfp_ag_create_sdp_record( hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_ag_service_name, 0, supported_features, wide_band_speech); 739fffdd288SMatthias Ringwald printf("SDP service record size: %u\n", de_get_len( hfp_service_buffer)); 740fffdd288SMatthias Ringwald sdp_register_service(hfp_service_buffer); 741fffdd288SMatthias Ringwald 7420e62b7a5SMatthias Ringwald // parse humand readable Bluetooth address 7430e62b7a5SMatthias Ringwald sscanf_bd_addr(device_addr_string, device_addr); 7440e62b7a5SMatthias Ringwald 745d0755cd6SMatthias Ringwald #ifdef HAVE_POSIX_STDIN 746fffdd288SMatthias Ringwald btstack_stdin_setup(stdin_process); 747fffdd288SMatthias Ringwald #endif 748fffdd288SMatthias Ringwald // turn on! 749fffdd288SMatthias Ringwald hci_power_control(HCI_POWER_ON); 750fffdd288SMatthias Ringwald return 0; 751fffdd288SMatthias Ringwald } 752fffdd288SMatthias Ringwald /* LISTING_END */ 7532b6b8c15SMilanka Ringwald /* EXAMPLE_END */ 754