13deb3ec6SMatthias Ringwald /* 23deb3ec6SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 33deb3ec6SMatthias Ringwald * 43deb3ec6SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 53deb3ec6SMatthias Ringwald * modification, are permitted provided that the following conditions 63deb3ec6SMatthias Ringwald * are met: 73deb3ec6SMatthias Ringwald * 83deb3ec6SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 93deb3ec6SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 103deb3ec6SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 113deb3ec6SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 123deb3ec6SMatthias Ringwald * documentation and/or other materials provided with the distribution. 133deb3ec6SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 143deb3ec6SMatthias Ringwald * contributors may be used to endorse or promote products derived 153deb3ec6SMatthias Ringwald * from this software without specific prior written permission. 163deb3ec6SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 173deb3ec6SMatthias Ringwald * personal benefit and not for any commercial purpose or for 183deb3ec6SMatthias Ringwald * monetary gain. 193deb3ec6SMatthias Ringwald * 203deb3ec6SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 213deb3ec6SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 223deb3ec6SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24*2fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 253deb3ec6SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 263deb3ec6SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 273deb3ec6SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 283deb3ec6SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 293deb3ec6SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 303deb3ec6SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 313deb3ec6SMatthias Ringwald * SUCH DAMAGE. 323deb3ec6SMatthias Ringwald * 333deb3ec6SMatthias Ringwald * Please inquire about commercial licensing options at 343deb3ec6SMatthias Ringwald * [email protected] 353deb3ec6SMatthias Ringwald * 363deb3ec6SMatthias Ringwald */ 373deb3ec6SMatthias Ringwald 38fe5a6c4eSMilanka Ringwald /** 39fe5a6c4eSMilanka Ringwald * @title HSP Audio Gateway 40fe5a6c4eSMilanka Ringwald * 41fe5a6c4eSMilanka Ringwald */ 423deb3ec6SMatthias Ringwald 433deb3ec6SMatthias Ringwald #ifndef btstack_hsp_ag_h 443deb3ec6SMatthias Ringwald #define btstack_hsp_ag_h 453deb3ec6SMatthias Ringwald 463deb3ec6SMatthias Ringwald #include "hci.h" 47efda0b48SMatthias Ringwald #include "classic/sdp_client_rfcomm.h" 483deb3ec6SMatthias Ringwald 493deb3ec6SMatthias Ringwald #if defined __cplusplus 503deb3ec6SMatthias Ringwald extern "C" { 513deb3ec6SMatthias Ringwald #endif 523deb3ec6SMatthias Ringwald 53eda0480fSMatthias Ringwald /* API_START */ 54eda0480fSMatthias Ringwald 55eda0480fSMatthias Ringwald /** 56eda0480fSMatthias Ringwald * @brief Set up HSP AG. 57eda0480fSMatthias Ringwald * @param rfcomm_channel_nr 58eda0480fSMatthias Ringwald */ 593deb3ec6SMatthias Ringwald void hsp_ag_init(uint8_t rfcomm_channel_nr); 6066a048abSMatthias Ringwald 61eda0480fSMatthias Ringwald /** 62eda0480fSMatthias Ringwald * @brief Create HSP Audio Gateway (AG) SDP service record. 63eda0480fSMatthias Ringwald * @param service Empty buffer in which a new service record will be stored. 64eda0480fSMatthias Ringwald * @param service_record_handle 65eda0480fSMatthias Ringwald * @param rfcomm_channel_nr 66eda0480fSMatthias Ringwald * @param name 67eda0480fSMatthias Ringwald */ 68eda0480fSMatthias Ringwald void hsp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name); 69eda0480fSMatthias Ringwald 70eda0480fSMatthias Ringwald /** 71eda0480fSMatthias Ringwald * @brief Register packet handler to receive HSP AG events. 7213839019SMatthias Ringwald 7313839019SMatthias Ringwald * The HSP AG event has type HCI_EVENT_HSP_META with following subtypes: 7413839019SMatthias Ringwald * - HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE 7513839019SMatthias Ringwald * - HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE 7613839019SMatthias Ringwald * - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE 7713839019SMatthias Ringwald * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE 7813839019SMatthias Ringwald * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED 7913839019SMatthias Ringwald * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED 8013839019SMatthias Ringwald * - HSP_SUBEVENT_HS_COMMAND 8113839019SMatthias Ringwald * 82eda0480fSMatthias Ringwald * @param callback 83eda0480fSMatthias Ringwald */ 8413839019SMatthias Ringwald void hsp_ag_register_packet_handler(btstack_packet_handler_t callback); 8566a048abSMatthias Ringwald 86eda0480fSMatthias Ringwald /** 87fffdd288SMatthias Ringwald * @brief Connect to HSP Headset. 88eda0480fSMatthias Ringwald * 89eda0480fSMatthias Ringwald * Perform SDP query for an RFCOMM service on a remote device, 90fffdd288SMatthias Ringwald * and establish an RFCOMM connection if such service is found. Reception of the 91fffdd288SMatthias Ringwald * HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE with status 0 92fffdd288SMatthias Ringwald * indicates if the connection is successfully established. 93eda0480fSMatthias Ringwald * 94eda0480fSMatthias Ringwald * @param bd_addr 95eda0480fSMatthias Ringwald */ 963deb3ec6SMatthias Ringwald void hsp_ag_connect(bd_addr_t bd_addr); 9766a048abSMatthias Ringwald 98eda0480fSMatthias Ringwald /** 99fffdd288SMatthias Ringwald * @brief Disconnect from HSP Headset 100eda0480fSMatthias Ringwald * 101fffdd288SMatthias Ringwald * Reception of the HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE with status 0 102fffdd288SMatthias Ringwald * indicates if the connection is successfully released. 103eda0480fSMatthias Ringwald * @param bd_addr 104eda0480fSMatthias Ringwald */ 1053deb3ec6SMatthias Ringwald void hsp_ag_disconnect(void); 1063deb3ec6SMatthias Ringwald 107fffdd288SMatthias Ringwald 108fffdd288SMatthias Ringwald /** 109fffdd288SMatthias Ringwald * @brief Establish audio connection. 110fffdd288SMatthias Ringwald * 111fffdd288SMatthias Ringwald * Reception of the HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE with status 0 112fffdd288SMatthias Ringwald * indicates if the audio connection is successfully established. 113fffdd288SMatthias Ringwald * @param bd_addr 114fffdd288SMatthias Ringwald */ 115fffdd288SMatthias Ringwald void hsp_ag_establish_audio_connection(void); 116fffdd288SMatthias Ringwald 117fffdd288SMatthias Ringwald /** 118fffdd288SMatthias Ringwald * @brief Release audio connection. 119fffdd288SMatthias Ringwald * 120fffdd288SMatthias Ringwald * Reception of the HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE with status 0 121fffdd288SMatthias Ringwald * indicates if the connection is successfully released. 122fffdd288SMatthias Ringwald * @param bd_addr 123fffdd288SMatthias Ringwald */ 124fffdd288SMatthias Ringwald void hsp_ag_release_audio_connection(void); 125fffdd288SMatthias Ringwald 126eda0480fSMatthias Ringwald /** 127eda0480fSMatthias Ringwald * @brief Set microphone gain. 128eda0480fSMatthias Ringwald * @param gain Valid range: [0,15] 129eda0480fSMatthias Ringwald */ 1303deb3ec6SMatthias Ringwald void hsp_ag_set_microphone_gain(uint8_t gain); 13166a048abSMatthias Ringwald 132eda0480fSMatthias Ringwald /** 133eda0480fSMatthias Ringwald * @brief Set speaker gain. 134eda0480fSMatthias Ringwald * @param gain Valid range: [0,15] 135eda0480fSMatthias Ringwald */ 1363deb3ec6SMatthias Ringwald void hsp_ag_set_speaker_gain(uint8_t gain); 1373deb3ec6SMatthias Ringwald 138eda0480fSMatthias Ringwald /** 139eda0480fSMatthias Ringwald * @brief Start ringing because of incoming call. 140eda0480fSMatthias Ringwald */ 1413deb3ec6SMatthias Ringwald void hsp_ag_start_ringing(void); 14266a048abSMatthias Ringwald 143eda0480fSMatthias Ringwald /** 144eda0480fSMatthias Ringwald * @brief Stop ringing (e.g. call was terminated). 145eda0480fSMatthias Ringwald */ 1463deb3ec6SMatthias Ringwald void hsp_ag_stop_ringing(void); 1473deb3ec6SMatthias Ringwald 148eda0480fSMatthias Ringwald /** 149eda0480fSMatthias Ringwald * @brief Enable custom AT commands. 150eda0480fSMatthias Ringwald * 151eda0480fSMatthias Ringwald * Custom commands are disabled by default. 152eda0480fSMatthias Ringwald * When enabled, custom AT commands are received via the HSP_SUBEVENT_HS_COMMAND. 153eda0480fSMatthias Ringwald * @param enable 154eda0480fSMatthias Ringwald */ 15566a048abSMatthias Ringwald void hsp_ag_enable_custom_commands(int enable); 15666a048abSMatthias Ringwald 157eda0480fSMatthias Ringwald /** 158eda0480fSMatthias Ringwald * @brief Send a custom AT command to HSP Headset. 159eda0480fSMatthias Ringwald * 160eda0480fSMatthias Ringwald * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond 161eda0480fSMatthias Ringwald * with this function with the result to the custom command. 162eda0480fSMatthias Ringwald * @param result 163eda0480fSMatthias Ringwald */ 1643deb3ec6SMatthias Ringwald int hsp_ag_send_result(char * result); 1653deb3ec6SMatthias Ringwald 1663962dc20SMatthias Ringwald /** 1673962dc20SMatthias Ringwald * @brief Set packet types used for outgoing SCO connection requests 1683962dc20SMatthias Ringwald * @param common single packet_types: SCO_PACKET_TYPES_* 1693962dc20SMatthias Ringwald */ 1703962dc20SMatthias Ringwald void hsp_ag_set_sco_packet_types(uint16_t packet_types); 1713962dc20SMatthias Ringwald 172637244f1SMatthias Ringwald /** 173637244f1SMatthias Ringwald * @brief De-Init HSP AG 174637244f1SMatthias Ringwald */ 175637244f1SMatthias Ringwald void hsp_ag_deinit(void); 176637244f1SMatthias Ringwald 177637244f1SMatthias Ringwald /* API_END */ 178637244f1SMatthias Ringwald 1793deb3ec6SMatthias Ringwald #if defined __cplusplus 1803deb3ec6SMatthias Ringwald } 1813deb3ec6SMatthias Ringwald #endif 1823deb3ec6SMatthias Ringwald 1833deb3ec6SMatthias Ringwald #endif 184