1*fffdd288SMatthias Ringwald /* 2*fffdd288SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3*fffdd288SMatthias Ringwald * 4*fffdd288SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5*fffdd288SMatthias Ringwald * modification, are permitted provided that the following conditions 6*fffdd288SMatthias Ringwald * are met: 7*fffdd288SMatthias Ringwald * 8*fffdd288SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9*fffdd288SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10*fffdd288SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11*fffdd288SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12*fffdd288SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13*fffdd288SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14*fffdd288SMatthias Ringwald * contributors may be used to endorse or promote products derived 15*fffdd288SMatthias Ringwald * from this software without specific prior written permission. 16*fffdd288SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17*fffdd288SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18*fffdd288SMatthias Ringwald * monetary gain. 19*fffdd288SMatthias Ringwald * 20*fffdd288SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21*fffdd288SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*fffdd288SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*fffdd288SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24*fffdd288SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25*fffdd288SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26*fffdd288SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27*fffdd288SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28*fffdd288SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29*fffdd288SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30*fffdd288SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*fffdd288SMatthias Ringwald * SUCH DAMAGE. 32*fffdd288SMatthias Ringwald * 33*fffdd288SMatthias Ringwald * Please inquire about commercial licensing options at 34*fffdd288SMatthias Ringwald * [email protected] 35*fffdd288SMatthias Ringwald * 36*fffdd288SMatthias Ringwald */ 37*fffdd288SMatthias Ringwald 38*fffdd288SMatthias Ringwald /* 39*fffdd288SMatthias Ringwald * hsp_ag_demo.c 40*fffdd288SMatthias Ringwald */ 41*fffdd288SMatthias Ringwald 42*fffdd288SMatthias Ringwald // ***************************************************************************** 43*fffdd288SMatthias Ringwald /* EXAMPLE_START(hsp_ag_demo): HSP Audio Gateway Demo 44*fffdd288SMatthias Ringwald * 45*fffdd288SMatthias Ringwald * @text This example implements a HSP Audio Gateway device that sends and receives 46*fffdd288SMatthias Ringwald * audio signal over HCI SCO. It demonstrates how to receive 47*fffdd288SMatthias Ringwald * an output from a remote headset (HS), and, 48*fffdd288SMatthias Ringwald * if HAVE_STDIO is defined, how to control the HS. 49*fffdd288SMatthias Ringwald */ 50*fffdd288SMatthias Ringwald // ***************************************************************************** 51*fffdd288SMatthias Ringwald 52*fffdd288SMatthias Ringwald 53*fffdd288SMatthias Ringwald 54*fffdd288SMatthias Ringwald #include <stdint.h> 55*fffdd288SMatthias Ringwald #include <stdio.h> 56*fffdd288SMatthias Ringwald #include <stdlib.h> 57*fffdd288SMatthias Ringwald #include <string.h> 58*fffdd288SMatthias Ringwald #include <math.h> 59*fffdd288SMatthias Ringwald #include <unistd.h> 60*fffdd288SMatthias Ringwald 61*fffdd288SMatthias Ringwald #include "btstack.h" 62*fffdd288SMatthias Ringwald 63*fffdd288SMatthias Ringwald #define SCO_REPORT_PERIOD 255 64*fffdd288SMatthias Ringwald 65*fffdd288SMatthias Ringwald static uint8_t hsp_service_buffer[150]; 66*fffdd288SMatthias Ringwald static const uint8_t rfcomm_channel_nr = 1; 67*fffdd288SMatthias Ringwald static const char hsp_ag_service_name[] = "Audio Gateway Test"; 68*fffdd288SMatthias Ringwald static uint16_t sco_handle = 0; 69*fffdd288SMatthias Ringwald 70*fffdd288SMatthias Ringwald static char hs_cmd_buffer[100]; 71*fffdd288SMatthias Ringwald 72*fffdd288SMatthias Ringwald static bd_addr_t device_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF}; 73*fffdd288SMatthias Ringwald 74*fffdd288SMatthias Ringwald static int phase = 0; 75*fffdd288SMatthias Ringwald 76*fffdd288SMatthias Ringwald // input signal: pre-computed sine wave, 160 Hz 77*fffdd288SMatthias Ringwald static const uint8_t sine[] = { 78*fffdd288SMatthias Ringwald 0, 15, 31, 46, 61, 74, 86, 97, 107, 114, 79*fffdd288SMatthias Ringwald 120, 124, 126, 126, 124, 120, 114, 107, 97, 86, 80*fffdd288SMatthias Ringwald 74, 61, 46, 31, 15, 0, 241, 225, 210, 195, 81*fffdd288SMatthias Ringwald 182, 170, 159, 149, 142, 136, 132, 130, 130, 132, 82*fffdd288SMatthias Ringwald 136, 142, 149, 159, 170, 182, 195, 210, 225, 241, 83*fffdd288SMatthias Ringwald }; 84*fffdd288SMatthias Ringwald 85*fffdd288SMatthias Ringwald /* @section Audio Transfer Setup 86*fffdd288SMatthias Ringwald * 87*fffdd288SMatthias Ringwald * @text A pre-computed sine wave (160Hz) is used as the input audio signal. 160 Hz. 88*fffdd288SMatthias Ringwald * To send and receive an audio signal, HAVE_SCO_OVER_HCI has to be defined. 89*fffdd288SMatthias Ringwald * 90*fffdd288SMatthias Ringwald * Tested working setups: 91*fffdd288SMatthias Ringwald * - Ubuntu 14 64-bit, CC2564B connected via FTDI USB-2-UART adapter, 921600 baud 92*fffdd288SMatthias Ringwald * - Ubuntu 14 64-bit, CSR USB dongle 93*fffdd288SMatthias Ringwald * - OS X 10.11, CSR USB dongle 94*fffdd288SMatthias Ringwald * 95*fffdd288SMatthias Ringwald * Broken setups: 96*fffdd288SMatthias Ringwald * - OS X 10.11, CC2564B connected via FDTI USB-2-UART adapter, 921600 baud 97*fffdd288SMatthias Ringwald * - select(..) blocks > 400 ms -> num completed is received to late -> gaps between audio 98*fffdd288SMatthias Ringwald * - looks like bug in select->FTDI driver as it works correct on Linux 99*fffdd288SMatthias Ringwald * 100*fffdd288SMatthias Ringwald * SCO not routed over HCI yet: 101*fffdd288SMatthias Ringwald * - CSR UART dongle 102*fffdd288SMatthias Ringwald * - Broadcom USB dongle 103*fffdd288SMatthias Ringwald * - Broadcom UART chipset 104*fffdd288SMatthias Ringwald * - .. 105*fffdd288SMatthias Ringwald * 106*fffdd288SMatthias Ringwald */ 107*fffdd288SMatthias Ringwald 108*fffdd288SMatthias Ringwald 109*fffdd288SMatthias Ringwald static void show_usage(void){ 110*fffdd288SMatthias Ringwald bd_addr_t iut_address; 111*fffdd288SMatthias Ringwald gap_local_bd_addr(iut_address); 112*fffdd288SMatthias Ringwald 113*fffdd288SMatthias Ringwald printf("\n--- Bluetooth HSP Audio Gateway Test Console %s ---\n", bd_addr_to_str(iut_address)); 114*fffdd288SMatthias Ringwald 115*fffdd288SMatthias Ringwald printf("---\n"); 116*fffdd288SMatthias Ringwald printf("c - Connect to %s\n", bd_addr_to_str(device_addr)); 117*fffdd288SMatthias Ringwald printf("C - Disconnect\n"); 118*fffdd288SMatthias Ringwald printf("a - establish audio connection\n"); 119*fffdd288SMatthias Ringwald printf("A - release audio connection\n"); 120*fffdd288SMatthias Ringwald printf("m - set microphone gain 8\n"); 121*fffdd288SMatthias Ringwald printf("M - set microphone gain 15\n"); 122*fffdd288SMatthias Ringwald printf("o - set speaker gain 0\n"); 123*fffdd288SMatthias Ringwald printf("s - set speaker gain 8\n"); 124*fffdd288SMatthias Ringwald printf("S - set speaker gain 15\n"); 125*fffdd288SMatthias Ringwald printf("r - start ringing\n"); 126*fffdd288SMatthias Ringwald printf("t - stop ringing\n"); 127*fffdd288SMatthias Ringwald printf("---\n"); 128*fffdd288SMatthias Ringwald printf("Ctrl-c - exit\n"); 129*fffdd288SMatthias Ringwald printf("---\n"); 130*fffdd288SMatthias Ringwald } 131*fffdd288SMatthias Ringwald 132*fffdd288SMatthias Ringwald #ifdef HAVE_STDIO 133*fffdd288SMatthias Ringwald static int stdin_process(struct data_source *ds){ 134*fffdd288SMatthias Ringwald char buffer; 135*fffdd288SMatthias Ringwald read(ds->fd, &buffer, 1); 136*fffdd288SMatthias Ringwald 137*fffdd288SMatthias Ringwald switch (buffer){ 138*fffdd288SMatthias Ringwald case 'c': 139*fffdd288SMatthias Ringwald printf("Connect to %s\n", bd_addr_to_str(device_addr)); 140*fffdd288SMatthias Ringwald hsp_ag_connect(device_addr); 141*fffdd288SMatthias Ringwald break; 142*fffdd288SMatthias Ringwald case 'C': 143*fffdd288SMatthias Ringwald printf("Disconnect.\n"); 144*fffdd288SMatthias Ringwald hsp_ag_disconnect(); 145*fffdd288SMatthias Ringwald break; 146*fffdd288SMatthias Ringwald case 'a': 147*fffdd288SMatthias Ringwald printf("Establish audio connection\n"); 148*fffdd288SMatthias Ringwald hsp_ag_establish_audio_connection(); 149*fffdd288SMatthias Ringwald break; 150*fffdd288SMatthias Ringwald case 'A': 151*fffdd288SMatthias Ringwald printf("Release audio connection\n"); 152*fffdd288SMatthias Ringwald hsp_ag_release_audio_connection(); 153*fffdd288SMatthias Ringwald break; 154*fffdd288SMatthias Ringwald case 'm': 155*fffdd288SMatthias Ringwald printf("Setting microphone gain 8\n"); 156*fffdd288SMatthias Ringwald hsp_ag_set_microphone_gain(8); 157*fffdd288SMatthias Ringwald break; 158*fffdd288SMatthias Ringwald case 'M': 159*fffdd288SMatthias Ringwald printf("Setting microphone gain 15\n"); 160*fffdd288SMatthias Ringwald hsp_ag_set_microphone_gain(15); 161*fffdd288SMatthias Ringwald break; 162*fffdd288SMatthias Ringwald case 'o': 163*fffdd288SMatthias Ringwald printf("Setting speaker gain 0\n"); 164*fffdd288SMatthias Ringwald hsp_ag_set_speaker_gain(0); 165*fffdd288SMatthias Ringwald break; 166*fffdd288SMatthias Ringwald case 's': 167*fffdd288SMatthias Ringwald printf("Setting speaker gain 8\n"); 168*fffdd288SMatthias Ringwald hsp_ag_set_speaker_gain(8); 169*fffdd288SMatthias Ringwald break; 170*fffdd288SMatthias Ringwald case 'S': 171*fffdd288SMatthias Ringwald printf("Setting speaker gain 15\n"); 172*fffdd288SMatthias Ringwald hsp_ag_set_speaker_gain(15); 173*fffdd288SMatthias Ringwald break; 174*fffdd288SMatthias Ringwald case 'r': 175*fffdd288SMatthias Ringwald printf("Start ringing\n"); 176*fffdd288SMatthias Ringwald hsp_ag_start_ringing(); 177*fffdd288SMatthias Ringwald break; 178*fffdd288SMatthias Ringwald case 't': 179*fffdd288SMatthias Ringwald printf("Stop ringing\n"); 180*fffdd288SMatthias Ringwald hsp_ag_stop_ringing(); 181*fffdd288SMatthias Ringwald break; 182*fffdd288SMatthias Ringwald default: 183*fffdd288SMatthias Ringwald show_usage(); 184*fffdd288SMatthias Ringwald break; 185*fffdd288SMatthias Ringwald 186*fffdd288SMatthias Ringwald } 187*fffdd288SMatthias Ringwald return 0; 188*fffdd288SMatthias Ringwald } 189*fffdd288SMatthias Ringwald #endif 190*fffdd288SMatthias Ringwald 191*fffdd288SMatthias Ringwald static void try_send_sco(void){ 192*fffdd288SMatthias Ringwald return; 193*fffdd288SMatthias Ringwald if (!sco_handle) return; 194*fffdd288SMatthias Ringwald if (!hci_can_send_sco_packet_now()) { 195*fffdd288SMatthias Ringwald // printf("try_send_sco, cannot send now\n"); 196*fffdd288SMatthias Ringwald return; 197*fffdd288SMatthias Ringwald } 198*fffdd288SMatthias Ringwald 199*fffdd288SMatthias Ringwald const int sco_packet_length = hci_get_sco_packet_length(); 200*fffdd288SMatthias Ringwald const int sco_payload_length = sco_packet_length - 3; 201*fffdd288SMatthias Ringwald const int frames_per_packet = sco_payload_length; // for 8-bit data. for 16-bit data it's /2 202*fffdd288SMatthias Ringwald 203*fffdd288SMatthias Ringwald hci_reserve_packet_buffer(); 204*fffdd288SMatthias Ringwald uint8_t * sco_packet = hci_get_outgoing_packet_buffer(); 205*fffdd288SMatthias Ringwald // set handle + flags 206*fffdd288SMatthias Ringwald little_endian_store_16(sco_packet, 0, sco_handle); 207*fffdd288SMatthias Ringwald // set len 208*fffdd288SMatthias Ringwald sco_packet[2] = sco_payload_length; 209*fffdd288SMatthias Ringwald int i; 210*fffdd288SMatthias Ringwald for (i=0;i<frames_per_packet;i++){ 211*fffdd288SMatthias Ringwald sco_packet[3+i] = sine[phase]; 212*fffdd288SMatthias Ringwald phase++; 213*fffdd288SMatthias Ringwald if (phase >= sizeof(sine)) phase = 0; 214*fffdd288SMatthias Ringwald } 215*fffdd288SMatthias Ringwald hci_send_sco_packet_buffer(sco_packet_length); 216*fffdd288SMatthias Ringwald static int count = 0; 217*fffdd288SMatthias Ringwald count++; 218*fffdd288SMatthias Ringwald if ((count & SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count); 219*fffdd288SMatthias Ringwald } 220*fffdd288SMatthias Ringwald 221*fffdd288SMatthias Ringwald static void sco_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){ 222*fffdd288SMatthias Ringwald return; 223*fffdd288SMatthias Ringwald static int count = 0; 224*fffdd288SMatthias Ringwald count++; 225*fffdd288SMatthias Ringwald if ((count & SCO_REPORT_PERIOD)) return; 226*fffdd288SMatthias Ringwald printf("SCO packets %u\n", count); 227*fffdd288SMatthias Ringwald } 228*fffdd288SMatthias Ringwald 229*fffdd288SMatthias Ringwald static void packet_handler(uint8_t * event, uint16_t event_size){ 230*fffdd288SMatthias Ringwald switch (event[0]) { 231*fffdd288SMatthias Ringwald case BTSTACK_EVENT_STATE: 232*fffdd288SMatthias Ringwald if (event[2] != HCI_STATE_WORKING) break; 233*fffdd288SMatthias Ringwald printf("HCI_STATE_WORKING\n"); 234*fffdd288SMatthias Ringwald show_usage(); 235*fffdd288SMatthias Ringwald break; 236*fffdd288SMatthias Ringwald case HCI_EVENT_SCO_CAN_SEND_NOW: 237*fffdd288SMatthias Ringwald try_send_sco(); 238*fffdd288SMatthias Ringwald break; 239*fffdd288SMatthias Ringwald case HCI_EVENT_HSP_META: 240*fffdd288SMatthias Ringwald switch (event[2]) { 241*fffdd288SMatthias Ringwald case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE: 242*fffdd288SMatthias Ringwald if (event[3] == 0){ 243*fffdd288SMatthias Ringwald printf("RFCOMM connection established.\n"); 244*fffdd288SMatthias Ringwald } else { 245*fffdd288SMatthias Ringwald printf("RFCOMM connection establishement failed.\n"); 246*fffdd288SMatthias Ringwald } 247*fffdd288SMatthias Ringwald break; 248*fffdd288SMatthias Ringwald case HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE: 249*fffdd288SMatthias Ringwald if (event[3] == 0){ 250*fffdd288SMatthias Ringwald printf("RFCOMM disconnected.\n"); 251*fffdd288SMatthias Ringwald } else { 252*fffdd288SMatthias Ringwald printf("RFCOMM disconnection failed.\n"); 253*fffdd288SMatthias Ringwald } 254*fffdd288SMatthias Ringwald break; 255*fffdd288SMatthias Ringwald case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE: 256*fffdd288SMatthias Ringwald if (event[3] == 0){ 257*fffdd288SMatthias Ringwald sco_handle = little_endian_read_16(event, 4); 258*fffdd288SMatthias Ringwald printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); 259*fffdd288SMatthias Ringwald try_send_sco(); 260*fffdd288SMatthias Ringwald } else { 261*fffdd288SMatthias Ringwald printf("Audio connection establishment failed with status %u\n", event[3]); 262*fffdd288SMatthias Ringwald sco_handle = 0; 263*fffdd288SMatthias Ringwald } 264*fffdd288SMatthias Ringwald break; 265*fffdd288SMatthias Ringwald case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE: 266*fffdd288SMatthias Ringwald if (event[3] == 0){ 267*fffdd288SMatthias Ringwald printf("Audio connection released.\n\n"); 268*fffdd288SMatthias Ringwald sco_handle = 0; 269*fffdd288SMatthias Ringwald } else { 270*fffdd288SMatthias Ringwald printf("Audio connection releasing failed with status %u\n", event[3]); 271*fffdd288SMatthias Ringwald } 272*fffdd288SMatthias Ringwald break; 273*fffdd288SMatthias Ringwald case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED: 274*fffdd288SMatthias Ringwald printf("Received microphone gain change %d\n", event[3]); 275*fffdd288SMatthias Ringwald break; 276*fffdd288SMatthias Ringwald case HSP_SUBEVENT_SPEAKER_GAIN_CHANGED: 277*fffdd288SMatthias Ringwald printf("Received speaker gain change %d\n", event[3]); 278*fffdd288SMatthias Ringwald break; 279*fffdd288SMatthias Ringwald case HSP_SUBEVENT_HS_COMMAND:{ 280*fffdd288SMatthias Ringwald memset(hs_cmd_buffer, 0, sizeof(hs_cmd_buffer)); 281*fffdd288SMatthias Ringwald int size = event[3] <= sizeof(hs_cmd_buffer)? event[3] : sizeof(hs_cmd_buffer); 282*fffdd288SMatthias Ringwald memcpy(hs_cmd_buffer, &event[4], size - 1); 283*fffdd288SMatthias Ringwald printf("Received custom command: \"%s\". \nExit code or call hsp_ag_send_result.\n", hs_cmd_buffer); 284*fffdd288SMatthias Ringwald break; 285*fffdd288SMatthias Ringwald } 286*fffdd288SMatthias Ringwald default: 287*fffdd288SMatthias Ringwald printf("event not handled %u\n", event[2]); 288*fffdd288SMatthias Ringwald break; 289*fffdd288SMatthias Ringwald } 290*fffdd288SMatthias Ringwald break; 291*fffdd288SMatthias Ringwald default: 292*fffdd288SMatthias Ringwald break; 293*fffdd288SMatthias Ringwald } 294*fffdd288SMatthias Ringwald } 295*fffdd288SMatthias Ringwald 296*fffdd288SMatthias Ringwald /* @section Main Application Setup 297*fffdd288SMatthias Ringwald * 298*fffdd288SMatthias Ringwald * @text Listing MainConfiguration shows main application code. 299*fffdd288SMatthias Ringwald * To run a HSP Audio Gateway service you need to initialize the SDP, and to create and register HSP AG record with it. 300*fffdd288SMatthias Ringwald * In this example, the SCO over HCI is used to receive and send an audio signal. 301*fffdd288SMatthias Ringwald * 302*fffdd288SMatthias Ringwald * Two packet handlers are registered: 303*fffdd288SMatthias Ringwald * - The HCI SCO packet handler receives audio data. 304*fffdd288SMatthias Ringwald * - The HSP AG packet handler is used to trigger sending of audio data and commands to the HS. It also receives the AG's answers. 305*fffdd288SMatthias Ringwald * 306*fffdd288SMatthias Ringwald * The stdin_process callback allows for sending commands to the AG. 307*fffdd288SMatthias Ringwald * At the end the Bluetooth stack is started. 308*fffdd288SMatthias Ringwald */ 309*fffdd288SMatthias Ringwald 310*fffdd288SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup HSP Audio Gateway */ 311*fffdd288SMatthias Ringwald int btstack_main(int argc, const char * argv[]); 312*fffdd288SMatthias Ringwald int btstack_main(int argc, const char * argv[]){ 313*fffdd288SMatthias Ringwald 314*fffdd288SMatthias Ringwald hci_register_sco_packet_handler(&sco_packet_handler); 315*fffdd288SMatthias Ringwald 316*fffdd288SMatthias Ringwald l2cap_init(); 317*fffdd288SMatthias Ringwald 318*fffdd288SMatthias Ringwald sdp_init(); 319*fffdd288SMatthias Ringwald 320*fffdd288SMatthias Ringwald memset((uint8_t *)hsp_service_buffer, 0, sizeof(hsp_service_buffer)); 321*fffdd288SMatthias Ringwald hsp_ag_create_sdp_record(hsp_service_buffer, 0x10001, rfcomm_channel_nr, hsp_ag_service_name); 322*fffdd288SMatthias Ringwald printf("SDP service record size: %u\n", de_get_len(hsp_service_buffer)); 323*fffdd288SMatthias Ringwald sdp_register_service(hsp_service_buffer); 324*fffdd288SMatthias Ringwald 325*fffdd288SMatthias Ringwald rfcomm_init(); 326*fffdd288SMatthias Ringwald 327*fffdd288SMatthias Ringwald hsp_ag_init(rfcomm_channel_nr); 328*fffdd288SMatthias Ringwald hsp_ag_register_packet_handler(packet_handler); 329*fffdd288SMatthias Ringwald 330*fffdd288SMatthias Ringwald #ifdef HAVE_STDIO 331*fffdd288SMatthias Ringwald btstack_stdin_setup(stdin_process); 332*fffdd288SMatthias Ringwald #endif 333*fffdd288SMatthias Ringwald 334*fffdd288SMatthias Ringwald gap_set_local_name("BTstack HSP AG"); 335*fffdd288SMatthias Ringwald gap_discoverable_control(1); 336*fffdd288SMatthias Ringwald gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); 337*fffdd288SMatthias Ringwald hci_set_class_of_device(0x400204); 338*fffdd288SMatthias Ringwald 339*fffdd288SMatthias Ringwald // turn on! 340*fffdd288SMatthias Ringwald hci_power_control(HCI_POWER_ON); 341*fffdd288SMatthias Ringwald return 0; 342*fffdd288SMatthias Ringwald } 343*fffdd288SMatthias Ringwald /* LISTING_END */ 344