1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_INCLUDE_BT_HF_H 18 #define ANDROID_INCLUDE_BT_HF_H 19 20 __BEGIN_DECLS 21 22 /* AT response code - OK/Error */ 23 typedef enum { 24 BTHF_AT_RESPONSE_ERROR = 0, 25 BTHF_AT_RESPONSE_OK 26 } bthf_at_response_t; 27 28 typedef enum { 29 BTHF_CONNECTION_STATE_DISCONNECTED = 0, 30 BTHF_CONNECTION_STATE_CONNECTING, 31 BTHF_CONNECTION_STATE_CONNECTED, 32 BTHF_CONNECTION_STATE_SLC_CONNECTED, 33 BTHF_CONNECTION_STATE_DISCONNECTING 34 } bthf_connection_state_t; 35 36 typedef enum { 37 BTHF_AUDIO_STATE_DISCONNECTED = 0, 38 BTHF_AUDIO_STATE_CONNECTING, 39 BTHF_AUDIO_STATE_CONNECTED, 40 BTHF_AUDIO_STATE_DISCONNECTING 41 } bthf_audio_state_t; 42 43 typedef enum { 44 BTHF_VR_STATE_STOPPED = 0, 45 BTHF_VR_STATE_STARTED 46 } bthf_vr_state_t; 47 48 typedef enum { 49 BTHF_VOLUME_TYPE_SPK = 0, 50 BTHF_VOLUME_TYPE_MIC 51 } bthf_volume_type_t; 52 53 /* Noise Reduction and Echo Cancellation */ 54 typedef enum 55 { 56 BTHF_NREC_STOP, 57 BTHF_NREC_START 58 } bthf_nrec_t; 59 60 /* WBS codec setting */ 61 typedef enum 62 { 63 BTHF_WBS_NONE, 64 BTHF_WBS_NO, 65 BTHF_WBS_YES 66 }bthf_wbs_config_t; 67 68 /* CHLD - Call held handling */ 69 typedef enum 70 { 71 BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call 72 BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call 73 BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call 74 BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference 75 } bthf_chld_type_t; 76 77 78 /* HF Indicators HFP 1.7 */ 79 typedef enum 80 { 81 BTHF_HF_IND_ENHANCED_DRIVER_SAFETY = 1, 82 BTHF_HF_IND_BATTERY_LEVEL_STATUS = 2, 83 } bthf_hf_ind_type_t; 84 85 typedef enum 86 { 87 BTHF_HF_IND_DISABLED = 0, 88 BTHF_HF_IND_ENABLED, 89 } bthf_hf_ind_status_t; 90 91 /** Callback for connection state change. 92 * state will have one of the values from BtHfConnectionState 93 */ 94 typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr); 95 96 /** Callback for audio connection state change. 97 * state will have one of the values from BtHfAudioState 98 */ 99 typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr); 100 101 /** Callback for VR connection state change. 102 * state will have one of the values from BtHfVRState 103 */ 104 typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr); 105 106 /** Callback for answer incoming call (ATA) 107 */ 108 typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr); 109 110 /** Callback for disconnect call (AT+CHUP) 111 */ 112 typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr); 113 114 /** Callback for disconnect call (AT+CHUP) 115 * type will denote Speaker/Mic gain (BtHfVolumeControl). 116 */ 117 typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr); 118 119 /** Callback for dialing an outgoing call 120 * If number is NULL, redial 121 */ 122 typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr); 123 124 /** Callback for sending DTMF tones 125 * tone contains the dtmf character to be sent 126 */ 127 typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr); 128 129 /** Callback for enabling/disabling noise reduction/echo cancellation 130 * value will be 1 to enable, 0 to disable 131 */ 132 typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr); 133 134 /** Callback for AT+BCS and event from BAC 135 * WBS enable, WBS disable 136 */ 137 typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr); 138 139 /** Callback for call hold handling (AT+CHLD) 140 * value will contain the call hold command (0, 1, 2, 3) 141 */ 142 typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr); 143 144 /** Callback for CNUM (subscriber number) 145 */ 146 typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr); 147 148 /** Callback for indicators (CIND) 149 */ 150 typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr); 151 152 /** Callback for operator selection (COPS) 153 */ 154 typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr); 155 156 /** Callback for call list (AT+CLCC) 157 */ 158 typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr); 159 160 /** Callback for unknown AT command recd from HF 161 * at_string will contain the unparsed AT string 162 */ 163 typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr); 164 165 /** Callback for keypressed (HSP) event. 166 */ 167 typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr); 168 169 /** Callback for BIND. Pass the remote HF Indicators supported. 170 */ 171 typedef void (* bthf_bind_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr); 172 173 /** Callback for BIEV. Pass the change in the Remote HF indicator values 174 */ 175 typedef void (* bthf_biev_cmd_callback)(bthf_hf_ind_type_t ind_id, int ind_value, 176 bt_bdaddr_t *bd_addr); 177 178 /** BT-HF callback structure. */ 179 typedef struct { 180 /** set to sizeof(BtHfCallbacks) */ 181 size_t size; 182 bthf_connection_state_callback connection_state_cb; 183 bthf_audio_state_callback audio_state_cb; 184 bthf_vr_cmd_callback vr_cmd_cb; 185 bthf_answer_call_cmd_callback answer_call_cmd_cb; 186 bthf_hangup_call_cmd_callback hangup_call_cmd_cb; 187 bthf_volume_cmd_callback volume_cmd_cb; 188 bthf_dial_call_cmd_callback dial_call_cmd_cb; 189 bthf_dtmf_cmd_callback dtmf_cmd_cb; 190 bthf_nrec_cmd_callback nrec_cmd_cb; 191 bthf_wbs_callback wbs_cb; 192 bthf_chld_cmd_callback chld_cmd_cb; 193 bthf_cnum_cmd_callback cnum_cmd_cb; 194 bthf_cind_cmd_callback cind_cmd_cb; 195 bthf_cops_cmd_callback cops_cmd_cb; 196 bthf_clcc_cmd_callback clcc_cmd_cb; 197 bthf_unknown_at_cmd_callback unknown_at_cmd_cb; 198 bthf_bind_cmd_callback bind_cb; 199 bthf_biev_cmd_callback biev_cb; 200 bthf_key_pressed_cmd_callback key_pressed_cmd_cb; 201 } bthf_callbacks_t; 202 203 /** Network Status */ 204 typedef enum 205 { 206 BTHF_NETWORK_STATE_NOT_AVAILABLE = 0, 207 BTHF_NETWORK_STATE_AVAILABLE 208 } bthf_network_state_t; 209 210 /** Service type */ 211 typedef enum 212 { 213 BTHF_SERVICE_TYPE_HOME = 0, 214 BTHF_SERVICE_TYPE_ROAMING 215 } bthf_service_type_t; 216 217 typedef enum { 218 BTHF_CALL_STATE_ACTIVE = 0, 219 BTHF_CALL_STATE_HELD, 220 BTHF_CALL_STATE_DIALING, 221 BTHF_CALL_STATE_ALERTING, 222 BTHF_CALL_STATE_INCOMING, 223 BTHF_CALL_STATE_WAITING, 224 BTHF_CALL_STATE_IDLE 225 } bthf_call_state_t; 226 227 typedef enum { 228 BTHF_CALL_DIRECTION_OUTGOING = 0, 229 BTHF_CALL_DIRECTION_INCOMING 230 } bthf_call_direction_t; 231 232 typedef enum { 233 BTHF_CALL_TYPE_VOICE = 0, 234 BTHF_CALL_TYPE_DATA, 235 BTHF_CALL_TYPE_FAX 236 } bthf_call_mode_t; 237 238 typedef enum { 239 BTHF_CALL_MPTY_TYPE_SINGLE = 0, 240 BTHF_CALL_MPTY_TYPE_MULTI 241 } bthf_call_mpty_type_t; 242 243 typedef enum { 244 BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81, 245 BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91 246 } bthf_call_addrtype_t; 247 /** Represents the standard BT-HF interface. */ 248 typedef struct { 249 250 /** set to sizeof(BtHfInterface) */ 251 size_t size; 252 /** 253 * Register the BtHf callbacks 254 */ 255 bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients); 256 257 /** connect to headset */ 258 bt_status_t (*connect)( bt_bdaddr_t *bd_addr ); 259 260 /** dis-connect from headset */ 261 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr ); 262 263 /** create an audio connection */ 264 bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr ); 265 266 /** close the audio connection */ 267 bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr ); 268 269 /** start voice recognition */ 270 bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr ); 271 272 /** stop voice recognition */ 273 bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr ); 274 275 /** volume control */ 276 bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr ); 277 278 /** Combined device status change notification */ 279 bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal, 280 int batt_chg); 281 282 /** Response for COPS command */ 283 bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr ); 284 285 /** Response for CIND command */ 286 bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state, 287 int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr ); 288 289 /** Pre-formatted AT response, typically in response to unknown AT cmd */ 290 bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr ); 291 292 /** ok/error response 293 * ERROR (0) 294 * OK (1) 295 */ 296 bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr ); 297 298 /** response for CLCC command 299 * Can be iteratively called for each call index 300 * Call index of 0 will be treated as NULL termination (Completes response) 301 */ 302 bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir, 303 bthf_call_state_t state, bthf_call_mode_t mode, 304 bthf_call_mpty_type_t mpty, const char *number, 305 bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr ); 306 307 /** notify of a call state change 308 * Each update notifies 309 * 1. Number of active/held/ringing calls 310 * 2. call_state: This denotes the state change that triggered this msg 311 * This will take one of the values from BtHfCallState 312 * 3. number & type: valid only for incoming & waiting call 313 */ 314 bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state, 315 const char *number, bthf_call_addrtype_t type); 316 317 /** Closes the interface. */ 318 void (*cleanup)( void ); 319 320 /** configureation for the SCO codec */ 321 bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config ); 322 323 /** Response for HF Indicator change (+BIND) */ 324 bt_status_t (*bind_response)(bthf_hf_ind_type_t ind_id, bthf_hf_ind_status_t ind_status, 325 bt_bdaddr_t *bd_addr); 326 } bthf_interface_t; 327 328 __END_DECLS 329 330 #endif /* ANDROID_INCLUDE_BT_HF_H */ 331