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 MATTHIAS 24 * RINGWALD 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 // 40 // HSP Audio Gateway 41 // 42 // ***************************************************************************** 43 44 45 #ifndef btstack_hsp_ag_h 46 #define btstack_hsp_ag_h 47 48 #include "hci.h" 49 #include "classic/sdp_client_rfcomm.h" 50 51 #if defined __cplusplus 52 extern "C" { 53 #endif 54 55 /* API_START */ 56 57 /** 58 * @brief Packet handler for HSP Audio Gateway (AG) events. 59 * 60 * The HSP AG event has type HCI_EVENT_HSP_META with following subtypes: 61 * - HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE 62 * - HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE 63 * - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE 64 * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE 65 * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED 66 * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED 67 * - HSP_SUBEVENT_HS_COMMAND 68 * 69 * @param event See include/btstack/hci_cmds.h 70 * @param event_size 71 */ 72 typedef void (*hsp_ag_callback_t)(uint8_t * event, uint16_t event_size); 73 74 /** 75 * @brief Set up HSP AG. 76 * @param rfcomm_channel_nr 77 */ 78 void hsp_ag_init(uint8_t rfcomm_channel_nr); 79 80 /** 81 * @brief Create HSP Audio Gateway (AG) SDP service record. 82 * @param service Empty buffer in which a new service record will be stored. 83 * @param service_record_handle 84 * @param rfcomm_channel_nr 85 * @param name 86 */ 87 void hsp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name); 88 89 /** 90 * @brief Register packet handler to receive HSP AG events. 91 * @param callback 92 */ 93 void hsp_ag_register_packet_handler(hsp_ag_callback_t callback); 94 95 /** 96 * @brief Connect to HSP Headset. 97 * 98 * Perform SDP query for an RFCOMM service on a remote device, 99 * and establish an RFCOMM connection if such service is found. Reception of the 100 * HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE with status 0 101 * indicates if the connection is successfully established. 102 * 103 * @param bd_addr 104 */ 105 void hsp_ag_connect(bd_addr_t bd_addr); 106 107 /** 108 * @brief Disconnect from HSP Headset 109 * 110 * Reception of the HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE with status 0 111 * indicates if the connection is successfully released. 112 * @param bd_addr 113 */ 114 void hsp_ag_disconnect(void); 115 116 117 /** 118 * @brief Establish audio connection. 119 * 120 * Reception of the HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE with status 0 121 * indicates if the audio connection is successfully established. 122 * @param bd_addr 123 */ 124 void hsp_ag_establish_audio_connection(void); 125 126 /** 127 * @brief Release audio connection. 128 * 129 * Reception of the HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE with status 0 130 * indicates if the connection is successfully released. 131 * @param bd_addr 132 */ 133 void hsp_ag_release_audio_connection(void); 134 135 /** 136 * @brief Set microphone gain. 137 * @param gain Valid range: [0,15] 138 */ 139 void hsp_ag_set_microphone_gain(uint8_t gain); 140 141 /** 142 * @brief Set speaker gain. 143 * @param gain Valid range: [0,15] 144 */ 145 void hsp_ag_set_speaker_gain(uint8_t gain); 146 147 /** 148 * @brief Start ringing because of incoming call. 149 */ 150 void hsp_ag_start_ringing(void); 151 152 /** 153 * @brief Stop ringing (e.g. call was terminated). 154 */ 155 void hsp_ag_stop_ringing(void); 156 157 /** 158 * @brief Enable custom AT commands. 159 * 160 * Custom commands are disabled by default. 161 * When enabled, custom AT commands are received via the HSP_SUBEVENT_HS_COMMAND. 162 * @param enable 163 */ 164 void hsp_ag_enable_custom_commands(int enable); 165 166 /** 167 * @brief Send a custom AT command to HSP Headset. 168 * 169 * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond 170 * with this function with the result to the custom command. 171 * @param result 172 */ 173 int hsp_ag_send_result(char * result); 174 175 /* API_END */ 176 177 #if defined __cplusplus 178 } 179 #endif 180 181 #endif