1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /** 39 * @title HSP Audio Gateway 40 * 41 */ 42 43 #ifndef btstack_hsp_ag_h 44 #define btstack_hsp_ag_h 45 46 #include "hci.h" 47 #include "classic/sdp_client_rfcomm.h" 48 49 #if defined __cplusplus 50 extern "C" { 51 #endif 52 53 /* API_START */ 54 55 /** 56 * @brief Set up HSP AG. 57 * @param rfcomm_channel_nr 58 */ 59 void hsp_ag_init(uint8_t rfcomm_channel_nr); 60 61 /** 62 * @brief Create HSP Audio Gateway (AG) SDP service record. 63 * @param service Empty buffer in which a new service record will be stored. 64 * @param service_record_handle 65 * @param rfcomm_channel_nr 66 * @param name 67 */ 68 void hsp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name); 69 70 /** 71 * @brief Register packet handler to receive HSP AG events. 72 73 * The HSP AG event has type HCI_EVENT_HSP_META with following subtypes: 74 * - HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE 75 * - HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE 76 * - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE 77 * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE 78 * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED 79 * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED 80 * - HSP_SUBEVENT_HS_COMMAND 81 * 82 * @param callback 83 */ 84 void hsp_ag_register_packet_handler(btstack_packet_handler_t callback); 85 86 /** 87 * @brief Connect to HSP Headset. 88 * 89 * Perform SDP query for an RFCOMM service on a remote device, 90 * and establish an RFCOMM connection if such service is found. Reception of the 91 * HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE with status 0 92 * indicates if the connection is successfully established. 93 * 94 * @param bd_addr 95 */ 96 void hsp_ag_connect(bd_addr_t bd_addr); 97 98 /** 99 * @brief Disconnect from HSP Headset 100 * 101 * Reception of the HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE with status 0 102 * indicates if the connection is successfully released. 103 * @param bd_addr 104 */ 105 void hsp_ag_disconnect(void); 106 107 108 /** 109 * @brief Establish audio connection. 110 * 111 * Reception of the HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE with status 0 112 * indicates if the audio connection is successfully established. 113 * @param bd_addr 114 */ 115 void hsp_ag_establish_audio_connection(void); 116 117 /** 118 * @brief Release audio connection. 119 * 120 * Reception of the HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE with status 0 121 * indicates if the connection is successfully released. 122 * @param bd_addr 123 */ 124 void hsp_ag_release_audio_connection(void); 125 126 /** 127 * @brief Set microphone gain. 128 * @param gain Valid range: [0,15] 129 */ 130 void hsp_ag_set_microphone_gain(uint8_t gain); 131 132 /** 133 * @brief Set speaker gain. 134 * @param gain Valid range: [0,15] 135 */ 136 void hsp_ag_set_speaker_gain(uint8_t gain); 137 138 /** 139 * @brief Start ringing because of incoming call. 140 */ 141 void hsp_ag_start_ringing(void); 142 143 /** 144 * @brief Stop ringing (e.g. call was terminated). 145 */ 146 void hsp_ag_stop_ringing(void); 147 148 /** 149 * @brief Enable custom AT commands. 150 * 151 * Custom commands are disabled by default. 152 * When enabled, custom AT commands are received via the HSP_SUBEVENT_HS_COMMAND. 153 * @param enable 154 */ 155 void hsp_ag_enable_custom_commands(int enable); 156 157 /** 158 * @brief Send a custom AT command to HSP Headset. 159 * 160 * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond 161 * with this function with the result to the custom command. 162 * @param result 163 */ 164 int hsp_ag_send_result(char * result); 165 166 /** 167 * @brief Set packet types used for outgoing SCO connection requests 168 * @param common single packet_types: SCO_PACKET_TYPES_* 169 */ 170 void hsp_ag_set_sco_packet_types(uint16_t packet_types); 171 172 /** 173 * @brief De-Init HSP AG 174 */ 175 void hsp_ag_deinit(void); 176 177 /* API_END */ 178 179 #if defined __cplusplus 180 } 181 #endif 182 183 #endif 184