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 /* CHLD - Call held handling */ 61 typedef enum 62 { 63 BTHF_CHLD_TYPE_RELEASEHELD, // Terminate all held or set UDUB("busy") to a waiting call 64 BTHF_CHLD_TYPE_RELEASEACTIVE_ACCEPTHELD, // Terminate all active calls and accepts a waiting/held call 65 BTHF_CHLD_TYPE_HOLDACTIVE_ACCEPTHELD, // Hold all active calls and accepts a waiting/held call 66 BTHF_CHLD_TYPE_ADDHELDTOCONF, // Add all held calls to a conference 67 } bthf_chld_type_t; 68 69 /** Callback for connection state change. 70 * state will have one of the values from BtHfConnectionState 71 */ 72 typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr); 73 74 /** Callback for audio connection state change. 75 * state will have one of the values from BtHfAudioState 76 */ 77 typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr); 78 79 /** Callback for VR connection state change. 80 * state will have one of the values from BtHfVRState 81 */ 82 typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state); 83 84 /** Callback for answer incoming call (ATA) 85 */ 86 typedef void (* bthf_answer_call_cmd_callback)(); 87 88 /** Callback for disconnect call (AT+CHUP) 89 */ 90 typedef void (* bthf_hangup_call_cmd_callback)(); 91 92 /** Callback for disconnect call (AT+CHUP) 93 * type will denote Speaker/Mic gain (BtHfVolumeControl). 94 */ 95 typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume); 96 97 /** Callback for dialing an outgoing call 98 * If number is NULL, redial 99 */ 100 typedef void (* bthf_dial_call_cmd_callback)(char *number); 101 102 /** Callback for sending DTMF tones 103 * tone contains the dtmf character to be sent 104 */ 105 typedef void (* bthf_dtmf_cmd_callback)(char tone); 106 107 /** Callback for enabling/disabling noise reduction/echo cancellation 108 * value will be 1 to enable, 0 to disable 109 */ 110 typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec); 111 112 /** Callback for call hold handling (AT+CHLD) 113 * value will contain the call hold command (0, 1, 2, 3) 114 */ 115 typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld); 116 117 /** Callback for CNUM (subscriber number) 118 */ 119 typedef void (* bthf_cnum_cmd_callback)(); 120 121 /** Callback for indicators (CIND) 122 */ 123 typedef void (* bthf_cind_cmd_callback)(); 124 125 /** Callback for operator selection (COPS) 126 */ 127 typedef void (* bthf_cops_cmd_callback)(); 128 129 /** Callback for call list (AT+CLCC) 130 */ 131 typedef void (* bthf_clcc_cmd_callback) (); 132 133 /** Callback for unknown AT command recd from HF 134 * at_string will contain the unparsed AT string 135 */ 136 typedef void (* bthf_unknown_at_cmd_callback)(char *at_string); 137 138 /** Callback for keypressed (HSP) event. 139 */ 140 typedef void (* bthf_key_pressed_cmd_callback)(); 141 142 /** BT-HF callback structure. */ 143 typedef struct { 144 /** set to sizeof(BtHfCallbacks) */ 145 size_t size; 146 bthf_connection_state_callback connection_state_cb; 147 bthf_audio_state_callback audio_state_cb; 148 bthf_vr_cmd_callback vr_cmd_cb; 149 bthf_answer_call_cmd_callback answer_call_cmd_cb; 150 bthf_hangup_call_cmd_callback hangup_call_cmd_cb; 151 bthf_volume_cmd_callback volume_cmd_cb; 152 bthf_dial_call_cmd_callback dial_call_cmd_cb; 153 bthf_dtmf_cmd_callback dtmf_cmd_cb; 154 bthf_nrec_cmd_callback nrec_cmd_cb; 155 bthf_chld_cmd_callback chld_cmd_cb; 156 bthf_cnum_cmd_callback cnum_cmd_cb; 157 bthf_cind_cmd_callback cind_cmd_cb; 158 bthf_cops_cmd_callback cops_cmd_cb; 159 bthf_clcc_cmd_callback clcc_cmd_cb; 160 bthf_unknown_at_cmd_callback unknown_at_cmd_cb; 161 bthf_key_pressed_cmd_callback key_pressed_cmd_cb; 162 } bthf_callbacks_t; 163 164 /** Network Status */ 165 typedef enum 166 { 167 BTHF_NETWORK_STATE_NOT_AVAILABLE = 0, 168 BTHF_NETWORK_STATE_AVAILABLE 169 } bthf_network_state_t; 170 171 /** Service type */ 172 typedef enum 173 { 174 BTHF_SERVICE_TYPE_HOME = 0, 175 BTHF_SERVICE_TYPE_ROAMING 176 } bthf_service_type_t; 177 178 typedef enum { 179 BTHF_CALL_STATE_ACTIVE = 0, 180 BTHF_CALL_STATE_HELD, 181 BTHF_CALL_STATE_DIALING, 182 BTHF_CALL_STATE_ALERTING, 183 BTHF_CALL_STATE_INCOMING, 184 BTHF_CALL_STATE_WAITING, 185 BTHF_CALL_STATE_IDLE 186 } bthf_call_state_t; 187 188 typedef enum { 189 BTHF_CALL_DIRECTION_OUTGOING = 0, 190 BTHF_CALL_DIRECTION_INCOMING 191 } bthf_call_direction_t; 192 193 typedef enum { 194 BTHF_CALL_TYPE_VOICE = 0, 195 BTHF_CALL_TYPE_DATA, 196 BTHF_CALL_TYPE_FAX 197 } bthf_call_mode_t; 198 199 typedef enum { 200 BTHF_CALL_MPTY_TYPE_SINGLE = 0, 201 BTHF_CALL_MPTY_TYPE_MULTI 202 } bthf_call_mpty_type_t; 203 204 typedef enum { 205 BTHF_CALL_ADDRTYPE_UNKNOWN = 0x81, 206 BTHF_CALL_ADDRTYPE_INTERNATIONAL = 0x91 207 } bthf_call_addrtype_t; 208 /** Represents the standard BT-HF interface. */ 209 typedef struct { 210 211 /** set to sizeof(BtHfInterface) */ 212 size_t size; 213 /** 214 * Register the BtHf callbacks 215 */ 216 bt_status_t (*init)( bthf_callbacks_t* callbacks ); 217 218 /** connect to headset */ 219 bt_status_t (*connect)( bt_bdaddr_t *bd_addr ); 220 221 /** dis-connect from headset */ 222 bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr ); 223 224 /** create an audio connection */ 225 bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr ); 226 227 /** close the audio connection */ 228 bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr ); 229 230 /** start voice recognition */ 231 bt_status_t (*start_voice_recognition)(); 232 233 /** stop voice recognition */ 234 bt_status_t (*stop_voice_recognition)(); 235 236 /** volume control */ 237 bt_status_t (*volume_control) (bthf_volume_type_t type, int volume); 238 239 /** Combined device status change notification */ 240 bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal, 241 int batt_chg); 242 243 /** Response for COPS command */ 244 bt_status_t (*cops_response)(const char *cops); 245 246 /** Response for CIND command */ 247 bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state, 248 int signal, int roam, int batt_chg); 249 250 /** Pre-formatted AT response, typically in response to unknown AT cmd */ 251 bt_status_t (*formatted_at_response)(const char *rsp); 252 253 /** ok/error response 254 * ERROR (0) 255 * OK (1) 256 */ 257 bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code); 258 259 /** response for CLCC command 260 * Can be iteratively called for each call index 261 * Call index of 0 will be treated as NULL termination (Completes response) 262 */ 263 bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir, 264 bthf_call_state_t state, bthf_call_mode_t mode, 265 bthf_call_mpty_type_t mpty, const char *number, 266 bthf_call_addrtype_t type); 267 268 /** notify of a call state change 269 * Each update notifies 270 * 1. Number of active/held/ringing calls 271 * 2. call_state: This denotes the state change that triggered this msg 272 * This will take one of the values from BtHfCallState 273 * 3. number & type: valid only for incoming & waiting call 274 */ 275 bt_status_t (*phone_state_change) (int num_active, int num_held, bthf_call_state_t call_setup_state, 276 const char *number, bthf_call_addrtype_t type); 277 278 /** Closes the interface. */ 279 void (*cleanup)( void ); 280 } bthf_interface_t; 281 282 __END_DECLS 283 284 #endif /* ANDROID_INCLUDE_BT_HF_H */ 285