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 // HFP Audio Gateway (AG) unit 41 // 42 // ***************************************************************************** 43 44 45 #ifndef btstack_hfp_ag_h 46 #define btstack_hfp_ag_h 47 48 #include "hci.h" 49 #include "classic/sdp_query_rfcomm.h" 50 #include "classic/hfp.h" 51 #include "classic/hfp_gsm_model.h" 52 53 #if defined __cplusplus 54 extern "C" { 55 #endif 56 57 /* API_START */ 58 typedef struct { 59 uint8_t type; 60 const char * number; 61 } hfp_phone_number_t; 62 63 /** 64 * @brief Create HFP Audio Gateway (AG) SDP service record. 65 * @param service 66 * @param rfcomm_channel_nr 67 * @param name 68 * @param ability_to_reject_call 69 * @param suported_features 32-bit bitmap, see HFP_AGSF_* values in hfp.h 70 */ 71 void hfp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name, uint8_t ability_to_reject_call, uint16_t supported_features);; 72 73 /** 74 * @brief Set up HFP Audio Gateway (AG) device without additional supported features. 75 * @param rfcomm_channel_nr 76 */ 77 void hfp_ag_init(uint16_t rfcomm_channel_nr); 78 79 /** 80 * @brief Set codecs. 81 * @param codecs_nr 82 * @param codecs 83 */ 84 void hfp_ag_init_codecs(int codecs_nr, uint8_t * codecs); 85 86 /** 87 * @brief Set supported features. 88 * @param supported_features 32-bit bitmap, see HFP_AGSF_* values in hfp.h 89 */ 90 void hfp_ag_init_supported_features(uint32_t supported_features); 91 92 /** 93 * @brief Set AG indicators. 94 * @param indicators_nr 95 * @param indicators 96 */ 97 void hfp_ag_init_ag_indicators(int ag_indicators_nr, hfp_ag_indicator_t * ag_indicators); 98 99 /** 100 * @brief Set HF indicators. 101 * @param indicators_nr 102 * @param indicators 103 */ 104 void hfp_ag_init_hf_indicators(int hf_indicators_nr, hfp_generic_status_indicator_t * hf_indicators); 105 106 /** 107 * @brief Set Call Hold services. 108 * @param indicators_nr 109 * @param indicators 110 */ 111 void hfp_ag_init_call_hold_services(int call_hold_services_nr, const char * call_hold_services[]); 112 113 114 /** 115 * @brief Register callback for the HFP Audio Gateway (AG) client. 116 * @param callback 117 */ 118 void hfp_ag_register_packet_handler(hfp_callback_t callback); 119 120 /** 121 * @brief Enable in-band ring tone. 122 * @param use_in_band_ring_tone 123 */ 124 void hfp_ag_set_use_in_band_ring_tone(int use_in_band_ring_tone); 125 126 127 // actions used by local device / user 128 129 /** 130 * @brief Establish RFCOMM connection, and perform service level connection agreement: 131 * - exchange of supported features 132 * - report Audio Gateway (AG) indicators and their status 133 * - enable indicator status update in the AG 134 * - accept the information about available codecs in the Hands-Free (HF), if sent 135 * - report own information describing the call hold and multiparty services, if possible 136 * - report which HF indicators are enabled on the AG, if possible 137 * The status of SLC connection establishment is reported via 138 * HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED. 139 * 140 * @param bd_addr Bluetooth address of the HF 141 */ 142 void hfp_ag_establish_service_level_connection(bd_addr_t bd_addr); 143 144 /** 145 * @brief Release the RFCOMM channel and the audio connection between the HF and the AG. 146 * If the audio connection exists, it will be released. 147 * The status of releasing the SLC connection is reported via 148 * HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED. 149 * 150 * @param bd_addr Bluetooth address of the HF 151 */ 152 void hfp_ag_release_service_level_connection(bd_addr_t bd_addr); 153 154 /** 155 * @brief Establish audio connection. 156 * The status of Audio connection establishment is reported via is reported via 157 * HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE. 158 * @param bd_addr Bluetooth address of the HF 159 */ 160 void hfp_ag_establish_audio_connection(bd_addr_t bd_addr); 161 162 /** 163 * @brief Release audio connection. 164 * The status of releasing the Audio connection is reported via is reported via 165 * HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE. 166 * @param bd_addr Bluetooth address of the HF 167 */ 168 void hfp_ag_release_audio_connection(bd_addr_t bd_addr); 169 170 /** 171 * @brief Put the current call on hold, if it exists, and accept incoming call. 172 */ 173 void hfp_ag_answer_incoming_call(void); 174 175 /** 176 * @brief Join held call with active call. 177 */ 178 void hfp_ag_join_held_call(void); 179 180 /** 181 * @brief Reject incoming call, if exists, or terminate active call. 182 */ 183 void hfp_ag_terminate_call(void); 184 185 /* 186 * @brief Put incoming call on hold. 187 */ 188 void hfp_ag_hold_incoming_call(void); 189 190 /* 191 * @brief Accept the held incoming call. 192 */ 193 void hfp_ag_accept_held_incoming_call(void); 194 195 /* 196 * @brief Reject the held incoming call. 197 */ 198 void hfp_ag_reject_held_incoming_call(void); 199 200 /* 201 * @brief Set microphone gain. 202 * @param bd_addr Bluetooth address of the HF 203 * @param gain Valid range: [0,15] 204 */ 205 void hfp_ag_set_microphone_gain(bd_addr_t bd_addr, int gain); 206 207 /* 208 * @brief Set speaker gain. 209 * @param bd_addr Bluetooth address of the HF 210 * @param gain Valid range: [0,15] 211 */ 212 void hfp_ag_set_speaker_gain(bd_addr_t bd_addr, int gain); 213 214 /* 215 * @brief Set battery level. 216 * @param level Valid range: [0,5] 217 */ 218 void hfp_ag_set_battery_level(int level); 219 220 /* 221 * @brief Clear last dialed number. 222 */ 223 void hfp_ag_clear_last_dialed_number(void); 224 225 /* 226 * @brief Notify the HF that an incoming call is waiting 227 * during an ongoing call. The notification will be sent only if the HF has 228 * has previously enabled the "Call Waiting notification" in the AG. 229 * @param bd_addr Bluetooth address of the HF 230 */ 231 void hfp_ag_notify_incoming_call_waiting(bd_addr_t bd_addr); 232 233 // Voice Recognition 234 235 /* 236 * @brief Activate voice recognition. 237 * @param bd_addr Bluetooth address of the HF 238 * @param activate 239 */ 240 void hfp_ag_activate_voice_recognition(bd_addr_t bd_addr, int activate); 241 242 /* 243 * @brief Send a phone number back to the HF. 244 * @param bd_addr Bluetooth address of the HF 245 * @param phone_number 246 */ 247 void hfp_ag_send_phone_number_for_voice_tag(bd_addr_t bd_addr, const char * phone_number); 248 249 /* 250 * @brief Reject sending a phone number to the HF. 251 * @param bd_addr Bluetooth address of the HF 252 */ 253 void hfp_ag_reject_phone_number_for_voice_tag(bd_addr_t bd_addr); 254 255 /** 256 * @brief Store phone number with initiated call. 257 * @param type 258 * @param number 259 */ 260 void hfp_ag_set_clip(uint8_t type, const char * number); 261 262 263 // Cellular Actions 264 265 /** 266 * @brief Pass the accept incoming call event to the AG. 267 */ 268 void hfp_ag_incoming_call(void); 269 270 /** 271 * @brief Pass the reject outgoing call event to the AG. 272 */ 273 void hfp_ag_outgoing_call_rejected(void); 274 275 /** 276 * @brief Pass the accept outgoing call event to the AG. 277 */ 278 void hfp_ag_outgoing_call_accepted(void); 279 280 /** 281 * @brief Pass the outgoing call ringing event to the AG. 282 */ 283 void hfp_ag_outgoing_call_ringing(void); 284 285 /** 286 * @brief Pass the outgoing call established event to the AG. 287 */ 288 void hfp_ag_outgoing_call_established(void); 289 290 /** 291 * @brief Pass the call droped event to the AG. 292 */ 293 void hfp_ag_call_dropped(void); 294 295 /* 296 * @brief Set network registration status. 297 * @param status 0 - not registered, 1 - registered 298 */ 299 void hfp_ag_set_registration_status(int status); 300 301 /* 302 * @brief Set network signal strength. 303 * @param strength [0-5] 304 */ 305 void hfp_ag_set_signal_strength(int strength); 306 307 /* 308 * @brief Set roaming status. 309 * @param status 0 - no roaming, 1 - roaming active 310 */ 311 void hfp_ag_set_roaming_status(int status); 312 313 /* 314 * @brief Set subcriber number information, e.g. the phone number 315 * @param numbers 316 * @param numbers_count 317 */ 318 void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count); 319 320 /* 321 * @brief Called by cellular unit after a DTMF code was transmitted, so that the next one can be emitted. 322 * @param bd_addr Bluetooth address of the HF 323 */ 324 void hfp_ag_send_dtmf_code_done(bd_addr_t bd_addr); 325 326 /** 327 * @brief Report Extended Audio Gateway Error result codes in the AG. 328 * Whenever there is an error relating to the functionality of the AG as a 329 * result of AT command, the AG shall send +CME ERROR: 330 * - +CME ERROR: 0 - AG failure 331 * - +CME ERROR: 1 - no connection to phone 332 * - +CME ERROR: 3 - operation not allowed 333 * - +CME ERROR: 4 - operation not supported 334 * - +CME ERROR: 5 - PH-SIM PIN required 335 * - +CME ERROR: 10 - SIM not inserted 336 * - +CME ERROR: 11 - SIM PIN required 337 * - +CME ERROR: 12 - SIM PUK required 338 * - +CME ERROR: 13 - SIM failure 339 * - +CME ERROR: 14 - SIM busy 340 * - +CME ERROR: 16 - incorrect password 341 * - +CME ERROR: 17 - SIM PIN2 required 342 * - +CME ERROR: 18 - SIM PUK2 required 343 * - +CME ERROR: 20 - memory full 344 * - +CME ERROR: 21 - invalid index 345 * - +CME ERROR: 23 - memory failure 346 * - +CME ERROR: 24 - text string too long 347 * - +CME ERROR: 25 - invalid characters in text string 348 * - +CME ERROR: 26 - dial string too long 349 * - +CME ERROR: 27 - invalid characters in dial string 350 * - +CME ERROR: 30 - no network service 351 * - +CME ERROR: 31 - network Timeout. 352 * - +CME ERROR: 32 - network not allowed – Emergency calls only 353 * 354 * @param bd_addr Bluetooth address of the HF 355 * @param error 356 */ 357 void hfp_ag_report_extended_audio_gateway_error_result_code(bd_addr_t bd_addr, hfp_cme_error_t error); 358 359 /* API_END */ 360 361 362 #if defined __cplusplus 363 } 364 #endif 365 366 #endif