1 /* 2 * Copyright (C) 2012-2014 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 #pragma once 18 19 #include <bluetooth/log.h> 20 #include <raw_address.h> 21 22 typedef enum { 23 BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED = 0, 24 BTHF_CLIENT_CONNECTION_STATE_CONNECTING, 25 BTHF_CLIENT_CONNECTION_STATE_CONNECTED, 26 BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED, 27 BTHF_CLIENT_CONNECTION_STATE_DISCONNECTING 28 } bthf_client_connection_state_t; 29 30 typedef enum { 31 BTHF_CLIENT_AUDIO_STATE_DISCONNECTED = 0, 32 BTHF_CLIENT_AUDIO_STATE_CONNECTING, 33 BTHF_CLIENT_AUDIO_STATE_CONNECTED, 34 BTHF_CLIENT_AUDIO_STATE_CONNECTED_MSBC, 35 BTHF_CLIENT_AUDIO_STATE_CONNECTED_LC3, 36 } bthf_client_audio_state_t; 37 38 typedef enum { 39 BTHF_CLIENT_VR_STATE_STOPPED = 0, 40 BTHF_CLIENT_VR_STATE_STARTED 41 } bthf_client_vr_state_t; 42 43 typedef enum { 44 BTHF_CLIENT_VOLUME_TYPE_SPK = 0, 45 BTHF_CLIENT_VOLUME_TYPE_MIC 46 } bthf_client_volume_type_t; 47 48 typedef enum { 49 BTHF_CLIENT_NETWORK_STATE_NOT_AVAILABLE = 0, 50 BTHF_CLIENT_NETWORK_STATE_AVAILABLE 51 } bthf_client_network_state_t; 52 53 typedef enum { 54 BTHF_CLIENT_SERVICE_TYPE_HOME = 0, 55 BTHF_CLIENT_SERVICE_TYPE_ROAMING 56 } bthf_client_service_type_t; 57 58 typedef enum { 59 BTHF_CLIENT_CALL_STATE_ACTIVE = 0, 60 BTHF_CLIENT_CALL_STATE_HELD, 61 BTHF_CLIENT_CALL_STATE_DIALING, 62 BTHF_CLIENT_CALL_STATE_ALERTING, 63 BTHF_CLIENT_CALL_STATE_INCOMING, 64 BTHF_CLIENT_CALL_STATE_WAITING, 65 BTHF_CLIENT_CALL_STATE_HELD_BY_RESP_HOLD, 66 } bthf_client_call_state_t; 67 68 typedef enum { 69 BTHF_CLIENT_CALL_NO_CALLS_IN_PROGRESS = 0, 70 BTHF_CLIENT_CALL_CALLS_IN_PROGRESS 71 } bthf_client_call_t; 72 73 typedef enum { 74 BTHF_CLIENT_CALLSETUP_NONE = 0, 75 BTHF_CLIENT_CALLSETUP_INCOMING, 76 BTHF_CLIENT_CALLSETUP_OUTGOING, 77 BTHF_CLIENT_CALLSETUP_ALERTING 78 79 } bthf_client_callsetup_t; 80 81 typedef enum { 82 BTHF_CLIENT_CALLHELD_NONE = 0, 83 BTHF_CLIENT_CALLHELD_HOLD_AND_ACTIVE, 84 BTHF_CLIENT_CALLHELD_HOLD, 85 } bthf_client_callheld_t; 86 87 typedef enum { 88 BTHF_CLIENT_RESP_AND_HOLD_HELD = 0, 89 BTRH_CLIENT_RESP_AND_HOLD_ACCEPT, 90 BTRH_CLIENT_RESP_AND_HOLD_REJECT, 91 } bthf_client_resp_and_hold_t; 92 93 typedef enum { 94 BTHF_CLIENT_CALL_DIRECTION_OUTGOING = 0, 95 BTHF_CLIENT_CALL_DIRECTION_INCOMING 96 } bthf_client_call_direction_t; 97 98 typedef enum { 99 BTHF_CLIENT_CALL_MPTY_TYPE_SINGLE = 0, 100 BTHF_CLIENT_CALL_MPTY_TYPE_MULTI 101 } bthf_client_call_mpty_type_t; 102 103 typedef enum { 104 BTHF_CLIENT_CMD_COMPLETE_OK = 0, 105 BTHF_CLIENT_CMD_COMPLETE_ERROR, 106 BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_CARRIER, 107 BTHF_CLIENT_CMD_COMPLETE_ERROR_BUSY, 108 BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_ANSWER, 109 BTHF_CLIENT_CMD_COMPLETE_ERROR_DELAYED, 110 BTHF_CLIENT_CMD_COMPLETE_ERROR_REJECTLISTED, 111 BTHF_CLIENT_CMD_COMPLETE_ERROR_CME 112 } bthf_client_cmd_complete_t; 113 114 typedef enum { 115 BTHF_CLIENT_CALL_ACTION_CHLD_0 = 0, 116 BTHF_CLIENT_CALL_ACTION_CHLD_1, 117 BTHF_CLIENT_CALL_ACTION_CHLD_2, 118 BTHF_CLIENT_CALL_ACTION_CHLD_3, 119 BTHF_CLIENT_CALL_ACTION_CHLD_4, 120 BTHF_CLIENT_CALL_ACTION_CHLD_1x, 121 BTHF_CLIENT_CALL_ACTION_CHLD_2x, 122 BTHF_CLIENT_CALL_ACTION_ATA, 123 BTHF_CLIENT_CALL_ACTION_CHUP, 124 BTHF_CLIENT_CALL_ACTION_BTRH_0, 125 BTHF_CLIENT_CALL_ACTION_BTRH_1, 126 BTHF_CLIENT_CALL_ACTION_BTRH_2, 127 } bthf_client_call_action_t; 128 129 typedef enum { 130 BTHF_CLIENT_SERVICE_UNKNOWN = 0, 131 BTHF_CLIENT_SERVICE_VOICE, 132 BTHF_CLIENT_SERVICE_FAX 133 } bthf_client_subscriber_service_type_t; 134 135 typedef enum { 136 BTHF_CLIENT_IN_BAND_RINGTONE_NOT_PROVIDED = 0, 137 BTHF_CLIENT_IN_BAND_RINGTONE_PROVIDED, 138 } bthf_client_in_band_ring_state_t; 139 140 /* Peer features masks */ 141 #define BTHF_CLIENT_PEER_FEAT_3WAY 0x00000001 /* Three-way calling */ 142 #define BTHF_CLIENT_PEER_FEAT_ECNR \ 143 0x00000002 /* Echo cancellation and/or noise reduction */ 144 #define BTHF_CLIENT_PEER_FEAT_VREC 0x00000004 /* Voice recognition */ 145 #define BTHF_CLIENT_PEER_FEAT_INBAND 0x00000008 /* In-band ring tone */ 146 #define BTHF_CLIENT_PEER_FEAT_VTAG \ 147 0x00000010 /* Attach a phone number to a voice tag */ 148 #define BTHF_CLIENT_PEER_FEAT_REJECT \ 149 0x00000020 /* Ability to reject incoming call */ 150 #define BTHF_CLIENT_PEER_FEAT_ECS 0x00000040 /* Enhanced Call Status */ 151 #define BTHF_CLIENT_PEER_FEAT_ECC 0x00000080 /* Enhanced Call Control */ 152 #define BTHF_CLIENT_PEER_FEAT_EXTERR 0x00000100 /* Extended error codes */ 153 #define BTHF_CLIENT_PEER_FEAT_CODEC 0x00000200 /* Codec Negotiation */ 154 155 /* Peer call handling features masks */ 156 #define BTHF_CLIENT_CHLD_FEAT_REL \ 157 0x00000001 /* 0 Release waiting call or held calls */ 158 #define BTHF_CLIENT_CHLD_FEAT_REL_ACC \ 159 0x00000002 /* 1 Release active calls and accept other \ 160 (waiting or held) cal */ 161 #define BTHF_CLIENT_CHLD_FEAT_REL_X \ 162 0x00000004 /* 1x Release specified active call only */ 163 #define BTHF_CLIENT_CHLD_FEAT_HOLD_ACC \ 164 0x00000008 /* 2 Active calls on hold and accept other \ 165 (waiting or held) call */ 166 #define BTHF_CLIENT_CHLD_FEAT_PRIV_X \ 167 0x00000010 /* 2x Request private mode with specified \ 168 call (put the rest on hold) */ 169 #define BTHF_CLIENT_CHLD_FEAT_MERGE \ 170 0x00000020 /* 3 Add held call to multiparty */ 171 #define BTHF_CLIENT_CHLD_FEAT_MERGE_DETACH \ 172 0x00000040 /* 4 Connect two calls and leave \ 173 (disconnect from) multiparty */ 174 175 /** Callback for connection state change. 176 * state will have one of the values from BtHfConnectionState 177 * peer/chld_features are valid only for 178 * BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED state 179 */ 180 typedef void (*bthf_client_connection_state_callback)( 181 const RawAddress* bd_addr, bthf_client_connection_state_t state, 182 unsigned int peer_feat, unsigned int chld_feat); 183 184 /** Callback for audio connection state change. 185 * state will have one of the values from BtHfAudioState 186 */ 187 typedef void (*bthf_client_audio_state_callback)( 188 const RawAddress* bd_addr, bthf_client_audio_state_t state); 189 190 /** Callback for VR connection state change. 191 * state will have one of the values from BtHfVRState 192 */ 193 typedef void (*bthf_client_vr_cmd_callback)(const RawAddress* bd_addr, 194 bthf_client_vr_state_t state); 195 196 /** Callback for network state change 197 */ 198 typedef void (*bthf_client_network_state_callback)( 199 const RawAddress* bd_addr, bthf_client_network_state_t state); 200 201 /** Callback for network roaming status change 202 */ 203 typedef void (*bthf_client_network_roaming_callback)( 204 const RawAddress* bd_addr, bthf_client_service_type_t type); 205 206 /** Callback for signal strength indication 207 */ 208 typedef void (*bthf_client_network_signal_callback)(const RawAddress* bd_addr, 209 int signal_strength); 210 211 /** Callback for battery level indication 212 */ 213 typedef void (*bthf_client_battery_level_callback)(const RawAddress* bd_addr, 214 int battery_level); 215 216 /** Callback for current operator name 217 */ 218 typedef void (*bthf_client_current_operator_callback)(const RawAddress* bd_addr, 219 const char* name); 220 221 /** Callback for call indicator 222 */ 223 typedef void (*bthf_client_call_callback)(const RawAddress* bd_addr, 224 bthf_client_call_t call); 225 226 /** Callback for callsetup indicator 227 */ 228 typedef void (*bthf_client_callsetup_callback)( 229 const RawAddress* bd_addr, bthf_client_callsetup_t callsetup); 230 231 /** Callback for callheld indicator 232 */ 233 typedef void (*bthf_client_callheld_callback)(const RawAddress* bd_addr, 234 bthf_client_callheld_t callheld); 235 236 /** Callback for response and hold 237 */ 238 typedef void (*bthf_client_resp_and_hold_callback)( 239 const RawAddress* bd_addr, bthf_client_resp_and_hold_t resp_and_hold); 240 241 /** Callback for Calling Line Identification notification 242 * Will be called only when there is an incoming call and number is provided. 243 */ 244 typedef void (*bthf_client_clip_callback)(const RawAddress* bd_addr, 245 const char* number); 246 247 /** 248 * Callback for Call Waiting notification 249 */ 250 typedef void (*bthf_client_call_waiting_callback)(const RawAddress* bd_addr, 251 const char* number); 252 253 /** 254 * Callback for listing current calls. Can be called multiple time. 255 * If number is unknown NULL is passed. 256 */ 257 typedef void (*bthf_client_current_calls)(const RawAddress* bd_addr, int index, 258 bthf_client_call_direction_t dir, 259 bthf_client_call_state_t state, 260 bthf_client_call_mpty_type_t mpty, 261 const char* number); 262 263 /** Callback for audio volume change 264 */ 265 typedef void (*bthf_client_volume_change_callback)( 266 const RawAddress* bd_addr, bthf_client_volume_type_t type, int volume); 267 268 /** Callback for command complete event 269 * cme is valid only for BTHF_CLIENT_CMD_COMPLETE_ERROR_CME type 270 */ 271 typedef void (*bthf_client_cmd_complete_callback)( 272 const RawAddress* bd_addr, bthf_client_cmd_complete_t type, int cme); 273 274 /** Callback for subscriber information 275 */ 276 typedef void (*bthf_client_subscriber_info_callback)( 277 const RawAddress* bd_addr, const char* name, 278 bthf_client_subscriber_service_type_t type); 279 280 /** Callback for in-band ring tone settings 281 */ 282 typedef void (*bthf_client_in_band_ring_tone_callback)( 283 const RawAddress* bd_addr, bthf_client_in_band_ring_state_t state); 284 285 /** 286 * Callback for requested number from AG 287 */ 288 typedef void (*bthf_client_last_voice_tag_number_callback)( 289 const RawAddress* bd_addr, const char* number); 290 291 /** 292 * Callback for sending ring indication to app 293 */ 294 typedef void (*bthf_client_ring_indication_callback)(const RawAddress* bd_addr); 295 296 /** 297 * Callback for sending unknown (vendor specific) event 298 */ 299 typedef void (*bthf_client_unknown_event_callback)(const RawAddress* bd_addr, 300 const char* unknow_event); 301 302 /** BT-HF callback structure. */ 303 typedef struct { 304 /** set to sizeof(BtHfClientCallbacks) */ 305 size_t size; 306 bthf_client_connection_state_callback connection_state_cb; 307 bthf_client_audio_state_callback audio_state_cb; 308 bthf_client_vr_cmd_callback vr_cmd_cb; 309 bthf_client_network_state_callback network_state_cb; 310 bthf_client_network_roaming_callback network_roaming_cb; 311 bthf_client_network_signal_callback network_signal_cb; 312 bthf_client_battery_level_callback battery_level_cb; 313 bthf_client_current_operator_callback current_operator_cb; 314 bthf_client_call_callback call_cb; 315 bthf_client_callsetup_callback callsetup_cb; 316 bthf_client_callheld_callback callheld_cb; 317 bthf_client_resp_and_hold_callback resp_and_hold_cb; 318 bthf_client_clip_callback clip_cb; 319 bthf_client_call_waiting_callback call_waiting_cb; 320 bthf_client_current_calls current_calls_cb; 321 bthf_client_volume_change_callback volume_change_cb; 322 bthf_client_cmd_complete_callback cmd_complete_cb; 323 bthf_client_subscriber_info_callback subscriber_info_cb; 324 bthf_client_in_band_ring_tone_callback in_band_ring_tone_cb; 325 bthf_client_last_voice_tag_number_callback last_voice_tag_number_callback; 326 bthf_client_ring_indication_callback ring_indication_cb; 327 bthf_client_unknown_event_callback unknown_event_cb; 328 } bthf_client_callbacks_t; 329 330 /** Represents the standard BT-HF interface. */ 331 typedef struct { 332 /** set to sizeof(BtHfClientInterface) */ 333 size_t size; 334 /** 335 * Register the BtHf callbacks 336 */ 337 bt_status_t (*init)(bthf_client_callbacks_t* callbacks); 338 339 /** connect to audio gateway */ 340 bt_status_t (*connect)(const RawAddress* bd_addr); 341 342 /** disconnect from audio gateway */ 343 bt_status_t (*disconnect)(const RawAddress* bd_addr); 344 345 /** create an audio connection */ 346 bt_status_t (*connect_audio)(const RawAddress* bd_addr); 347 348 /** close the audio connection */ 349 bt_status_t (*disconnect_audio)(const RawAddress* bd_addr); 350 351 /** start voice recognition */ 352 bt_status_t (*start_voice_recognition)(const RawAddress* bd_addr); 353 354 /** stop voice recognition */ 355 bt_status_t (*stop_voice_recognition)(const RawAddress* bd_addr); 356 357 /** volume control */ 358 bt_status_t (*volume_control)(const RawAddress* bd_addr, 359 bthf_client_volume_type_t type, int volume); 360 361 /** place a call with number a number 362 * if number is NULL last called number is called (aka re-dial)*/ 363 bt_status_t (*dial)(const RawAddress* bd_addr, const char* number); 364 365 /** place a call with number specified by location (speed dial) */ 366 bt_status_t (*dial_memory)(const RawAddress* bd_addr, int location); 367 368 /** perform specified call related action 369 * idx is limited only for enhanced call control related action 370 */ 371 bt_status_t (*handle_call_action)(const RawAddress* bd_addr, 372 bthf_client_call_action_t action, int idx); 373 374 /** query list of current calls */ 375 bt_status_t (*query_current_calls)(const RawAddress* bd_addr); 376 377 /** query name of current selected operator */ 378 bt_status_t (*query_current_operator_name)(const RawAddress* bd_addr); 379 380 /** Retrieve subscriber information */ 381 bt_status_t (*retrieve_subscriber_info)(const RawAddress* bd_addr); 382 383 /** Send DTMF code*/ 384 bt_status_t (*send_dtmf)(const RawAddress* bd_addr, char code); 385 386 /** Request a phone number from AG corresponding to last voice tag recorded */ 387 bt_status_t (*request_last_voice_tag_number)(const RawAddress* bd_addr); 388 389 /** Closes the interface. */ 390 void (*cleanup)(void); 391 392 /** Send AT Command. */ 393 bt_status_t (*send_at_cmd)(const RawAddress* bd_addr, int cmd, int val1, 394 int val2, const char* arg); 395 396 /** Send hfp audio policy to remote */ 397 bt_status_t (*send_android_at)(const RawAddress* bd_addr, const char* arg); 398 } bthf_client_interface_t; 399 400 namespace fmt { 401 template <> 402 struct formatter<bthf_client_connection_state_t> 403 : enum_formatter<bthf_client_connection_state_t> {}; 404 } // namespace fmt 405