1 /****************************************************************************** 2 * 3 * Copyright (c) 2014 The Android Open Source Project 4 * Copyright 2003-2012 Broadcom Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ******************************************************************************/ 19 20 /****************************************************************************** 21 * 22 * This is the public interface file for the handsfree (HF role) subsystem 23 * 24 ******************************************************************************/ 25 #ifndef BTA_HF_CLIENT_API_H 26 #define BTA_HF_CLIENT_API_H 27 28 #include <cstdint> 29 30 #include "bta_api.h" 31 #include "bta_hfp_api.h" 32 #include "types/raw_address.h" 33 34 /***************************************************************************** 35 * Constants and data types 36 ****************************************************************************/ 37 38 /* HFP peer (AG) features*/ 39 #define BTA_HF_CLIENT_PEER_FEAT_3WAY 0x00000001 /* Three-way calling */ 40 #define BTA_HF_CLIENT_PEER_FEAT_ECNR \ 41 0x00000002 /* Echo cancellation and/or noise reduction */ 42 #define BTA_HF_CLIENT_PEER_FEAT_VREC 0x00000004 /* Voice recognition */ 43 #define BTA_HF_CLIENT_PEER_INBAND 0x00000008 /* In-band ring tone */ 44 #define BTA_HF_CLIENT_PEER_VTAG \ 45 0x00000010 /* Attach a phone number to a voice tag */ 46 #define BTA_HF_CLIENT_PEER_REJECT \ 47 0x00000020 /* Ability to reject incoming call */ 48 #define BTA_HF_CLIENT_PEER_ECS 0x00000040 /* Enhanced Call Status */ 49 #define BTA_HF_CLIENT_PEER_ECC 0x00000080 /* Enhanced Call Control */ 50 #define BTA_HF_CLIENT_PEER_EXTERR 0x00000100 /* Extended error codes */ 51 #define BTA_HF_CLIENT_PEER_CODEC 0x00000200 /* Codec Negotiation */ 52 #define BTA_HF_CLIENT_PEER_HF_IND 0x00000400 /* HF Indicators */ 53 #define BTA_HF_CLIENT_PEER_ESCO_S4 0x00000800 /* ESCO S4 link setting */ 54 55 typedef uint16_t tBTA_HF_CLIENT_PEER_FEAT; 56 57 /* HFP HF features */ 58 #define BTA_HF_CLIENT_FEAT_ECNR \ 59 0x00000001 /* Echo cancellation and/or noise reduction */ 60 #define BTA_HF_CLIENT_FEAT_3WAY \ 61 0x00000002 /* Call waiting and three-way calling */ 62 #define BTA_HF_CLIENT_FEAT_CLI \ 63 0x00000004 /* Caller ID presentation capability */ 64 #define BTA_HF_CLIENT_FEAT_VREC 0x00000008 /* Voice recognition activation */ 65 #define BTA_HF_CLIENT_FEAT_VOL 0x00000010 /* Remote volume control */ 66 #define BTA_HF_CLIENT_FEAT_ECS 0x00000020 /* Enhanced Call Status */ 67 #define BTA_HF_CLIENT_FEAT_ECC 0x00000040 /* Enhanced Call Control */ 68 #define BTA_HF_CLIENT_FEAT_CODEC 0x00000080 /* Codec Negotiation */ 69 #define BTA_HF_CLIENT_FEAT_HF_IND 0x00000100 /* HF Indicators */ 70 #define BTA_HF_CLIENT_FEAT_ESCO_S4 0x00000200 /* ESCO S4 link setting */ 71 #define BTA_HF_CLIENT_FEAT_SWB 0x00000400 /* SWB feature (HFP 1.9) */ 72 73 /* FP SDP feature masks */ 74 #define BTA_HF_CLIENT_WBS_SUPPORT 0x0020 /* Supports WBS */ 75 #define BTA_HF_CLIENT_FEAT_SWB_SUPPORT 0x0100 /* Supports SWB */ 76 77 /* HFP HF extended call handling - masks not related to any spec */ 78 #define BTA_HF_CLIENT_CHLD_REL \ 79 0x00000001 /* 0 Release waiting call or held calls */ 80 #define BTA_HF_CLIENT_CHLD_REL_ACC \ 81 0x00000002 /* 1 Release active calls and accept other (waiting or held) cal \ 82 */ 83 #define BTA_HF_CLIENT_CHLD_REL_X 0x00000004 /* 1x Release x call*/ 84 #define BTA_HF_CLIENT_CHLD_HOLD_ACC \ 85 0x00000008 /* 2 Active calls on hold and accept other call */ 86 #define BTA_HF_CLIENT_CHLD_PRIV_X \ 87 0x00000010 /* 2x Active multiparty call on hold except call x */ 88 #define BTA_HF_CLIENT_CHLD_MERGE \ 89 0x00000020 /* 3 Add held call to multiparty \ 90 */ 91 #define BTA_HF_CLIENT_CHLD_MERGE_DETACH \ 92 0x00000040 /* 4 Add held call to multiparty */ 93 94 typedef uint16_t tBTA_HF_CLIENT_CHLD_FEAT; 95 96 /* HFP AG errors ot OK sent to HF Unit */ 97 #define BTA_HF_CLIENT_AT_RESULT_OK 0 98 #define BTA_HF_CLIENT_AT_RESULT_ERROR 1 99 #define BTA_HF_CLIENT_AT_RESULT_NO_CARRIER 2 100 #define BTA_HF_CLIENT_AT_RESULT_BUSY 3 101 #define BTA_HF_CLIENT_AT_RESULT_NO_ANSWER 4 102 #define BTA_HF_CLIENT_AT_RESULT_DELAY 5 103 #define BTA_HF_CLIENT_AT_RESULT_REJECTLISTED 6 104 #define BTA_HF_CLIENT_AT_RESULT_CME 7 105 106 typedef uint8_t tBTA_HF_CLIENT_AT_RESULT_TYPE; 107 108 /* HF Client callback events */ 109 #define BTA_HF_CLIENT_ENABLE_EVT 0 /* HF Client enabled */ 110 #define BTA_HF_CLIENT_REGISTER_EVT 1 /* HF Client registered */ 111 #define BTA_HF_CLIENT_OPEN_EVT 2 /* HF Client connection open */ 112 #define BTA_HF_CLIENT_CLOSE_EVT 3 /* HF Client connection closed */ 113 #define BTA_HF_CLIENT_CONN_EVT 4 /* Service level connection opened */ 114 #define BTA_HF_CLIENT_AUDIO_OPEN_EVT 5 /* Audio connection open */ 115 #define BTA_HF_CLIENT_AUDIO_MSBC_OPEN_EVT \ 116 6 /* Audio connection with mSBC codec open */ 117 #define BTA_HF_CLIENT_AUDIO_CLOSE_EVT 7 /* Audio connection closed */ 118 #define BTA_HF_CLIENT_SPK_EVT 8 /* Speaker volume changed */ 119 #define BTA_HF_CLIENT_MIC_EVT 9 /* Microphone volume changed */ 120 #define BTA_HF_CLIENT_IND_EVT 10 /* Indicator */ 121 #define BTA_HF_CLIENT_VOICE_REC_EVT \ 122 11 /* AG changed voice recognition setting */ 123 #define BTA_HF_CLIENT_OPERATOR_NAME_EVT 12 /* Operator name acquired */ 124 #define BTA_HF_CLIENT_CLIP_EVT 13 /* Calling line identification event */ 125 #define BTA_HF_CLIENT_CCWA_EVT 14 /* Call waiting notification */ 126 #define BTA_HF_CLIENT_AT_RESULT_EVT 15 /* Call waiting notification */ 127 #define BTA_HF_CLIENT_CLCC_EVT 16 /* current call event */ 128 #define BTA_HF_CLIENT_CNUM_EVT 17 /* subscriber information event */ 129 #define BTA_HF_CLIENT_BTRH_EVT 18 /* bluetooth response and hold event */ 130 #define BTA_HF_CLIENT_BSIR_EVT \ 131 19 /* in-band ring tone setting changed event \ 132 */ 133 #define BTA_HF_CLIENT_BINP_EVT 20 /* binp number event */ 134 #define BTA_HF_CLIENT_RING_INDICATION 21 /* HF Client ring indication */ 135 136 #define BTA_HF_CLIENT_UNKNOWN_EVT 22 /* Unknown or vendor specific Event */ 137 #define BTA_HF_CLIENT_AUDIO_LC3_OPEN_EVT \ 138 23 /* Audio connection with LC3 codec open */ 139 #define BTA_HF_CLIENT_DISABLE_EVT 30 /* HF Client disabled */ 140 141 typedef uint8_t tBTA_HF_CLIENT_EVT; 142 143 /* HF Client open status */ 144 #define BTA_HF_CLIENT_SUCCESS 0 /* Connection successfully opened */ 145 #define BTA_HF_CLIENT_FAIL_SDP 1 /* Open failed due to SDP */ 146 #define BTA_HF_CLIENT_FAIL_RFCOMM 2 /* Open failed due to RFCOMM */ 147 #define BTA_HF_CLIENT_FAIL_RESOURCES 3 /* out of resources failure */ 148 149 typedef uint8_t tBTA_HF_CLIENT_STATUS; 150 151 /* indicator type */ 152 #define BTA_HF_CLIENT_IND_BATTCH 0 /* Battery charge indicator */ 153 #define BTA_HF_CLIENT_IND_SIGNAL 1 /* Signal Strength indicator */ 154 #define BTA_HF_CLIENT_IND_SERVICE 2 /* Service availability indicator */ 155 #define BTA_HF_CLIENT_IND_CALL 3 /* Standard call status indicator*/ 156 #define BTA_HF_CLIENT_IND_ROAM 4 /* Roaming status indicator */ 157 #define BTA_HF_CLIENT_IND_CALLSETUP 5 /* Call setup status indicator */ 158 #define BTA_HF_CLIENT_IND_CALLHELD 6 /* Call hold status indicator */ 159 160 typedef uint8_t tBTA_HF_CLIENT_IND_TYPE; 161 162 /* AT commands */ 163 #define BTA_HF_CLIENT_AT_CMD_VTS 0 164 #define BTA_HF_CLIENT_AT_CMD_BTRH 1 165 #define BTA_HF_CLIENT_AT_CMD_CHUP 2 166 #define BTA_HF_CLIENT_AT_CMD_CHLD 3 167 #define BTA_HF_CLIENT_AT_CMD_BCC 4 168 #define BTA_HF_CLIENT_AT_CMD_CNUM 5 169 #define BTA_HF_CLIENT_AT_CMD_ATA 6 170 #define BTA_HF_CLIENT_AT_CMD_COPS 7 171 #define BTA_HF_CLIENT_AT_CMD_ATD 8 172 #define BTA_HF_CLIENT_AT_CMD_VGM 9 173 #define BTA_HF_CLIENT_AT_CMD_VGS 10 174 #define BTA_HF_CLIENT_AT_CMD_BVRA 11 175 #define BTA_HF_CLIENT_AT_CMD_CLCC 12 176 #define BTA_HF_CLIENT_AT_CMD_BINP 13 177 #define BTA_HF_CLIENT_AT_CMD_BLDN 14 178 #define BTA_HF_CLIENT_AT_CMD_NREC 15 179 #define BTA_HF_CLIENT_AT_CMD_VENDOR_SPECIFIC_CMD 16 180 #define BTA_HF_CLIENT_AT_CMD_BIEV 17 181 #define BTA_HF_CLIENT_AT_CMD_ANDROID 18 182 183 typedef uint8_t tBTA_HF_CLIENT_AT_CMD_TYPE; 184 185 /* data associated with BTA_HF_CLIENT_REGISTER_EVT */ 186 typedef struct { 187 RawAddress bd_addr; 188 tBTA_HF_CLIENT_STATUS status; 189 } tBTA_HF_CLIENT_REGISTER; 190 191 /* data associated with BTA_HF_CLIENT_OPEN_EVT */ 192 typedef struct { 193 RawAddress bd_addr; 194 uint16_t handle; // Handle for client control block 195 tBTA_HF_CLIENT_STATUS status; 196 } tBTA_HF_CLIENT_OPEN; 197 198 /* data associated with BTA_HF_CLIENT_CONN_EVT */ 199 typedef struct { 200 RawAddress bd_addr; 201 tBTA_HF_CLIENT_PEER_FEAT peer_feat; 202 tBTA_HF_CLIENT_CHLD_FEAT chld_feat; 203 } tBTA_HF_CLIENT_CONN; 204 205 /* data associated with BTA_HF_CLIENT_IND_EVT event */ 206 typedef struct { 207 RawAddress bd_addr; 208 tBTA_HF_CLIENT_IND_TYPE type; 209 uint16_t value; 210 } tBTA_HF_CLIENT_IND; 211 212 /* data associated with BTA_HF_CLIENT_OPERATOR_NAME_EVT */ 213 #define BTA_HF_CLIENT_OPERATOR_NAME_LEN 16 214 typedef struct { 215 RawAddress bd_addr; 216 char name[BTA_HF_CLIENT_OPERATOR_NAME_LEN + 1]; 217 } tBTA_HF_CLIENT_OPERATOR_NAME; 218 219 /* data associated with BTA_HF_CLIENT_CLIP_EVT and BTA_HF_CLIENT_CCWA_EVT*/ 220 #define BTA_HF_CLIENT_NUMBER_LEN 32 221 typedef struct { 222 RawAddress bd_addr; 223 char number[BTA_HF_CLIENT_NUMBER_LEN + 1]; 224 } tBTA_HF_CLIENT_NUMBER; 225 226 /* data associated with BTA_HF_CLIENT_AT_RESULT_EVT event */ 227 typedef struct { 228 RawAddress bd_addr; 229 tBTA_HF_CLIENT_AT_RESULT_TYPE type; 230 uint16_t cme; 231 } tBTA_HF_CLIENT_AT_RESULT; 232 233 /* data associated with BTA_HF_CLIENT_CLCC_EVT event */ 234 typedef struct { 235 RawAddress bd_addr; 236 uint32_t idx; 237 bool inc; 238 uint8_t status; 239 bool mpty; 240 bool number_present; 241 char number[BTA_HF_CLIENT_NUMBER_LEN + 1]; 242 } tBTA_HF_CLIENT_CLCC; 243 244 /* data associated with BTA_HF_CLIENT_CNUM_EVT event */ 245 typedef struct { 246 RawAddress bd_addr; 247 uint16_t service; 248 char number[BTA_HF_CLIENT_NUMBER_LEN + 1]; 249 } tBTA_HF_CLIENT_CNUM; 250 251 /* data associated with other events */ 252 typedef struct { 253 RawAddress bd_addr; 254 uint16_t value; 255 } tBTA_HF_CLIENT_VAL; 256 257 /* data associated with BTA_HF_CLIENT_UNKNOWN_EVT event */ 258 #define BTA_HF_CLIENT_UNKNOWN_EVENT_LEN 32 259 typedef struct { 260 RawAddress bd_addr; 261 char event_string[BTA_HF_CLIENT_UNKNOWN_EVENT_LEN + 1]; 262 } tBTA_HF_CLIENT_UNKNOWN; 263 264 /* union of data associated with AG callback */ 265 typedef union { 266 // Common BD ADDR field for all tyepdefs 267 RawAddress bd_addr; 268 tBTA_HF_CLIENT_REGISTER reg; 269 tBTA_HF_CLIENT_OPEN open; 270 tBTA_HF_CLIENT_CONN conn; 271 tBTA_HF_CLIENT_IND ind; 272 tBTA_HF_CLIENT_VAL val; 273 tBTA_HF_CLIENT_OPERATOR_NAME operator_name; 274 tBTA_HF_CLIENT_NUMBER number; 275 tBTA_HF_CLIENT_AT_RESULT result; 276 tBTA_HF_CLIENT_CLCC clcc; 277 tBTA_HF_CLIENT_CNUM cnum; 278 tBTA_HF_CLIENT_UNKNOWN unknown; 279 } tBTA_HF_CLIENT; 280 281 typedef uint32_t tBTA_HF_CLIENT_FEAT; 282 283 /* HF Client callback */ 284 typedef void(tBTA_HF_CLIENT_CBACK)(tBTA_HF_CLIENT_EVT event, 285 tBTA_HF_CLIENT* p_data); 286 287 /***************************************************************************** 288 * External Function Declarations 289 ****************************************************************************/ 290 291 /******************************************************************************* 292 * 293 * Function BTA_HfClientEnable 294 * 295 * Description Enable the HF CLient service. When the enable 296 * operation is complete the callback function will be 297 * called with a BTA_HF_CLIENT_ENABLE_EVT. This function must 298 * be called before other function in the HF CLient API are 299 * called. 300 * 301 * Returns BTA_SUCCESS if OK, BTA_FAILURE otherwise. 302 * 303 ******************************************************************************/ 304 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK* p_cback, 305 tBTA_HF_CLIENT_FEAT features, 306 const char* p_service_name); 307 308 /******************************************************************************* 309 * 310 * Function BTA_HfClientDisable 311 * 312 * Description Disable the HF Client service. 313 * 314 * Returns void 315 * 316 ******************************************************************************/ 317 void BTA_HfClientDisable(void); 318 319 /******************************************************************************* 320 * 321 * Function BTA_HfClientOpen 322 * 323 * Description Opens a connection to an audio gateway. 324 * When connection is open callback function is called 325 * with a BTA_HF_CLIENT_OPEN_EVT. Only the data connection is 326 * opened. The audio connection is not opened. The handle 327 * is stored in p_handle and should be used for subsequent 328 * calls to do any AT operations 329 * 330 * 331 * Returns bt_status_t 332 * 333 ******************************************************************************/ 334 bt_status_t BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle); 335 336 /******************************************************************************* 337 * 338 * Function BTA_HfClientClose 339 * 340 * Description Close the current connection to an audio gateway. 341 * Any current audio connection will also be closed 342 * 343 * 344 * Returns void 345 * 346 ******************************************************************************/ 347 void BTA_HfClientClose(uint16_t handle); 348 349 /******************************************************************************* 350 * 351 * Function BTA_HfCllientAudioOpen 352 * 353 * Description Opens an audio connection to the currently connected 354 * audio gateway 355 * 356 * 357 * Returns void 358 * 359 ******************************************************************************/ 360 void BTA_HfClientAudioOpen(uint16_t handle); 361 362 /******************************************************************************* 363 * 364 * Function BTA_HfClientAudioClose 365 * 366 * Description Close the currently active audio connection to an audio 367 * gateway. The data connection remains open 368 * 369 * 370 * Returns void 371 * 372 ******************************************************************************/ 373 void BTA_HfClientAudioClose(uint16_t handle); 374 375 /******************************************************************************* 376 * 377 * Function BTA_HfClientSendAT 378 * 379 * Description send AT command 380 * 381 * 382 * Returns void 383 * 384 ******************************************************************************/ 385 void BTA_HfClientSendAT(uint16_t handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, 386 uint32_t val1, uint32_t val2, const char* str); 387 388 /******************************************************************************* 389 * 390 * Function BTA_HfClientDumpStatistics 391 * 392 * Description Dump statistics about the various control blocks 393 * and other relevant connection statistics 394 * 395 * Returns Void 396 * 397 ******************************************************************************/ 398 void BTA_HfClientDumpStatistics(int fd); 399 400 /******************************************************************************* 401 * 402 * function get_default_hf_client_features 403 * 404 * description return the hf_client features. 405 * value can be override via system property 406 * 407 * returns int 408 * 409 ******************************************************************************/ 410 int get_default_hf_client_features(); 411 #endif /* BTA_HF_CLIENT_API_H */ 412