1 /****************************************************************************** 2 * 3 * Copyright (C) 2003-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This is the private interface file for the BTA audio gateway. 22 * 23 ******************************************************************************/ 24 #ifndef BTA_AG_INT_H 25 #define BTA_AG_INT_H 26 27 #include "bta_sys.h" 28 #include "bta_api.h" 29 #include "bta_ag_api.h" 30 #include "bta_ag_at.h" 31 32 /* Send RING & CLIP in one AT cmd */ 33 #ifndef BTA_AG_MULTI_RESULT_INCLUDED 34 #define BTA_AG_MULTI_RESULT_INCLUDED FALSE 35 #endif 36 37 /* Replace : in VGS and VGM for HSP */ 38 #ifndef BTA_HSP_RESULT_REPLACE_COLON 39 #define BTA_HSP_RESULT_REPLACE_COLON TRUE 40 #endif 41 42 /***************************************************************************** 43 ** Constants 44 *****************************************************************************/ 45 #define HFP_VERSION_1_1 0x0101 46 #define HFP_VERSION_1_5 0x0105 47 #define HFP_VERSION_1_6 0x0106 48 49 #define HSP_VERSION_1_0 0x0100 50 #define HSP_VERSION_1_2 0x0102 51 52 /* Number of SCBs (AG service instances that can be registered) */ 53 #ifndef BTA_AG_NUM_SCB 54 #define BTA_AG_NUM_SCB 2 55 #endif 56 57 /* Time to wait for retry in case of collision */ 58 #ifndef BTA_AG_COLLISION_TIMEOUT_MS 59 #define BTA_AG_COLLISION_TIMEOUT_MS (2 * 1000) /* 2 seconds */ 60 #endif 61 62 /* RFCOMM MTU SIZE */ 63 #define BTA_AG_MTU 256 64 65 /* Internal profile indexes */ 66 #define BTA_AG_HSP 0 /* index for HSP */ 67 #define BTA_AG_HFP 1 /* index for HFP */ 68 #define BTA_AG_NUM_IDX 2 /* number of profile indexes */ 69 70 /* profile role for connection */ 71 #define BTA_AG_ACP 0 /* accepted connection */ 72 #define BTA_AG_INT 1 /* initiating connection */ 73 74 /* feature mask that matches spec */ 75 #define BTA_AG_BSRF_FEAT_SPEC (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | \ 76 BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND | \ 77 BTA_AG_FEAT_VTAG | BTA_AG_FEAT_REJECT | \ 78 BTA_AG_FEAT_ECS | BTA_AG_FEAT_ECC | \ 79 BTA_AG_FEAT_EXTERR | BTA_AG_FEAT_CODEC | \ 80 BTA_AG_FEAT_VOIP) 81 82 #define BTA_AG_SDP_FEAT_SPEC (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | \ 83 BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND | \ 84 BTA_AG_FEAT_VTAG) 85 86 enum 87 { 88 /* these events are handled by the state machine */ 89 BTA_AG_API_REGISTER_EVT = BTA_SYS_EVT_START(BTA_ID_AG), 90 BTA_AG_API_DEREGISTER_EVT, 91 BTA_AG_API_OPEN_EVT, 92 BTA_AG_API_CLOSE_EVT, 93 BTA_AG_API_AUDIO_OPEN_EVT, 94 BTA_AG_API_AUDIO_CLOSE_EVT, 95 BTA_AG_API_RESULT_EVT, 96 BTA_AG_API_SETCODEC_EVT, 97 BTA_AG_RFC_OPEN_EVT, 98 BTA_AG_RFC_CLOSE_EVT, 99 BTA_AG_RFC_SRV_CLOSE_EVT, 100 BTA_AG_RFC_DATA_EVT, 101 BTA_AG_SCO_OPEN_EVT, 102 BTA_AG_SCO_CLOSE_EVT, 103 BTA_AG_DISC_ACP_RES_EVT, 104 BTA_AG_DISC_INT_RES_EVT, 105 BTA_AG_DISC_OK_EVT, 106 BTA_AG_DISC_FAIL_EVT, 107 BTA_AG_CI_RX_WRITE_EVT, 108 BTA_AG_RING_TIMEOUT_EVT, 109 BTA_AG_SVC_TIMEOUT_EVT, 110 BTA_AG_CI_SCO_DATA_EVT, 111 BTA_AG_CI_SLC_READY_EVT, 112 BTA_AG_MAX_EVT, 113 114 /* these events are handled outside of the state machine */ 115 BTA_AG_API_ENABLE_EVT, 116 BTA_AG_API_DISABLE_EVT 117 }; 118 119 /* Actions to perform after a SCO event */ 120 enum 121 { 122 BTA_AG_POST_SCO_NONE, /* no action */ 123 BTA_AG_POST_SCO_CLOSE_RFC, /* close RFCOMM channel after SCO closes */ 124 BTA_AG_POST_SCO_RING, /* send RING result code after SCO opens */ 125 BTA_AG_POST_SCO_CALL_CONN, /* send call indicators after SCO opens/closes */ 126 BTA_AG_POST_SCO_CALL_ORIG, /* send call indicators after SCO closes */ 127 BTA_AG_POST_SCO_CALL_END, /* send call indicators after SCO closes */ 128 BTA_AG_POST_SCO_CALL_END_INCALL /* send call indicators for end call & incoming call after SCO closes */ 129 }; 130 131 /* sco states */ 132 enum 133 { 134 BTA_AG_SCO_SHUTDOWN_ST, /* no sco listening, all sco connections closed */ 135 BTA_AG_SCO_LISTEN_ST, /* sco listening */ 136 #if (BTM_WBS_INCLUDED == TRUE ) 137 BTA_AG_SCO_CODEC_ST, /* sco codec negotiation */ 138 #endif 139 BTA_AG_SCO_OPENING_ST, /* sco connection opening */ 140 BTA_AG_SCO_OPEN_CL_ST, /* opening sco connection being closed */ 141 BTA_AG_SCO_OPEN_XFER_ST, /* opening sco connection being transferred */ 142 BTA_AG_SCO_OPEN_ST, /* sco open */ 143 BTA_AG_SCO_CLOSING_ST, /* sco closing */ 144 BTA_AG_SCO_CLOSE_OP_ST, /* closing sco being opened */ 145 BTA_AG_SCO_CLOSE_XFER_ST, /* closing sco being transferred */ 146 BTA_AG_SCO_SHUTTING_ST /* sco shutting down */ 147 }; 148 149 /***************************************************************************** 150 ** Data types 151 *****************************************************************************/ 152 153 /* data type for BTA_AG_API_ENABLE_EVT */ 154 typedef struct 155 { 156 BT_HDR hdr; 157 tBTA_AG_PARSE_MODE parse_mode; 158 tBTA_AG_CBACK *p_cback; 159 } tBTA_AG_API_ENABLE; 160 161 /* data type for BTA_AG_API_REGISTER_EVT */ 162 typedef struct 163 { 164 BT_HDR hdr; 165 char p_name[2][BTA_SERVICE_NAME_LEN+1]; 166 tBTA_SERVICE_MASK services; 167 tBTA_SEC sec_mask; 168 tBTA_AG_FEAT features; 169 UINT8 app_id; 170 } tBTA_AG_API_REGISTER; 171 172 /* data type for BTA_AG_API_OPEN_EVT */ 173 typedef struct 174 { 175 BT_HDR hdr; 176 BD_ADDR bd_addr; 177 tBTA_SERVICE_MASK services; 178 tBTA_SEC sec_mask; 179 } tBTA_AG_API_OPEN; 180 181 /* data type for BTA_AG_API_RESULT_EVT */ 182 typedef struct 183 { 184 BT_HDR hdr; 185 tBTA_AG_RES result; 186 tBTA_AG_RES_DATA data; 187 } tBTA_AG_API_RESULT; 188 189 /* data type for BTA_AG_API_SETCODEC_EVT */ 190 typedef struct 191 { 192 BT_HDR hdr; 193 tBTA_AG_PEER_CODEC codec; 194 } tBTA_AG_API_SETCODEC; 195 196 /* data type for BTA_AG_DISC_RESULT_EVT */ 197 typedef struct 198 { 199 BT_HDR hdr; 200 UINT16 status; 201 } tBTA_AG_DISC_RESULT; 202 203 /* data type for RFCOMM events */ 204 typedef struct 205 { 206 BT_HDR hdr; 207 UINT16 port_handle; 208 } tBTA_AG_RFC; 209 210 /* data type for BTA_AG_CI_RX_WRITE_EVT */ 211 typedef struct 212 { 213 BT_HDR hdr; 214 // char p_data[BTA_AG_MTU+1]; 215 } tBTA_AG_CI_RX_WRITE; 216 217 /* union of all event datatypes */ 218 typedef union 219 { 220 BT_HDR hdr; 221 tBTA_AG_API_ENABLE api_enable; 222 tBTA_AG_API_REGISTER api_register; 223 tBTA_AG_API_OPEN api_open; 224 tBTA_AG_API_RESULT api_result; 225 #if (BTM_WBS_INCLUDED == TRUE ) 226 tBTA_AG_API_SETCODEC api_setcodec; 227 #endif 228 tBTA_AG_DISC_RESULT disc_result; 229 tBTA_AG_RFC rfc; 230 tBTA_AG_CI_RX_WRITE ci_rx_write; 231 } tBTA_AG_DATA; 232 233 /* type for each profile */ 234 typedef struct 235 { 236 UINT32 sdp_handle; 237 UINT8 scn; 238 } tBTA_AG_PROFILE; 239 240 #if (BTM_WBS_INCLUDED == TRUE) 241 typedef enum 242 { 243 BTA_AG_SCO_MSBC_SETTINGS_T2 = 0, /* preferred/default when codec is mSBC */ 244 BTA_AG_SCO_MSBC_SETTINGS_T1, 245 } tBTA_AG_SCO_MSBC_SETTINGS; 246 #endif 247 248 /* type for each service control block */ 249 typedef struct 250 { 251 char clip[BTA_AG_AT_MAX_LEN+1]; /* number string used for CLIP */ 252 UINT16 serv_handle[BTA_AG_NUM_IDX]; /* RFCOMM server handles */ 253 tBTA_AG_AT_CB at_cb; /* AT command interpreter */ 254 BD_ADDR peer_addr; /* peer bd address */ 255 tSDP_DISCOVERY_DB *p_disc_db; /* pointer to discovery database */ 256 tBTA_SERVICE_MASK reg_services; /* services specified in register API */ 257 tBTA_SERVICE_MASK open_services; /* services specified in open API */ 258 UINT16 conn_handle; /* RFCOMM handle of connected service */ 259 tBTA_SEC serv_sec_mask; /* server security mask */ 260 tBTA_SEC cli_sec_mask; /* client security mask */ 261 tBTA_AG_FEAT features; /* features registered by application */ 262 tBTA_AG_PEER_FEAT peer_features; /* peer device features */ 263 UINT16 peer_version; /* profile version of peer device */ 264 UINT16 hsp_version; /* HSP profile version */ 265 UINT16 sco_idx; /* SCO handle */ 266 BOOLEAN in_use; /* scb in use */ 267 BOOLEAN dealloc; /* TRUE if service shutting down */ 268 BOOLEAN clip_enabled; /* set to TRUE if HF enables CLIP reporting */ 269 BOOLEAN ccwa_enabled; /* set to TRUE if HF enables CCWA reporting */ 270 BOOLEAN cmer_enabled; /* set to TRUE if HF enables CMER reporting */ 271 BOOLEAN cmee_enabled; /* set to TRUE if HF enables CME ERROR reporting */ 272 BOOLEAN inband_enabled; /* set to TRUE if inband ring enabled */ 273 BOOLEAN svc_conn; /* set to TRUE when service level connection up */ 274 UINT8 state; /* state machine state */ 275 UINT8 conn_service; /* connected service */ 276 UINT8 peer_scn; /* peer scn */ 277 UINT8 app_id; /* application id */ 278 UINT8 role; /* initiator/acceptor role */ 279 UINT8 post_sco; /* action to perform after sco event */ 280 UINT8 call_ind; /* CIEV call indicator value */ 281 UINT8 callsetup_ind; /* CIEV callsetup indicator value */ 282 UINT8 service_ind; /* CIEV service indicator value */ 283 UINT8 signal_ind; /* CIEV signal indicator value */ 284 UINT8 roam_ind; /* CIEV roam indicator value */ 285 UINT8 battchg_ind; /* CIEV battery charge indicator value */ 286 UINT8 callheld_ind; /* CIEV call held indicator value */ 287 BOOLEAN retry_with_sco_only; /* indicator to try with SCO only when eSCO fails */ 288 UINT32 bia_masked_out; /* indicators HF does not want us to send */ 289 alarm_t *collision_timer; 290 alarm_t *ring_timer; 291 #if (BTM_WBS_INCLUDED == TRUE) 292 alarm_t *codec_negotiation_timer; 293 tBTA_AG_PEER_CODEC peer_codecs; /* codecs for eSCO supported by the peer */ 294 tBTA_AG_PEER_CODEC sco_codec; /* codec to be used for eSCO connection */ 295 tBTA_AG_PEER_CODEC inuse_codec; /* codec being used for the current SCO connection */ 296 BOOLEAN codec_updated; /* set to TRUE whenever the app updates codec type */ 297 BOOLEAN codec_fallback; /* If sco nego fails for mSBC, fallback to CVSD */ 298 tBTA_AG_SCO_MSBC_SETTINGS codec_msbc_settings; /* settings to be used for the impending eSCO */ 299 #endif 300 301 } tBTA_AG_SCB; 302 303 /* type for sco data */ 304 typedef struct 305 { 306 tBTM_ESCO_CONN_REQ_EVT_DATA conn_data; /* SCO data for pending conn request */ 307 tBTA_AG_SCB *p_curr_scb; /* SCB associated with SCO connection */ 308 tBTA_AG_SCB *p_xfer_scb; /* SCB associated with SCO transfer */ 309 UINT16 cur_idx; /* SCO handle */ 310 UINT8 state; /* SCO state variable */ 311 BOOLEAN param_updated; /* if params were updated to non-default */ 312 tBTM_ESCO_PARAMS params; /* ESCO parameters */ 313 } tBTA_AG_SCO_CB; 314 315 316 /* type for AG control block */ 317 typedef struct 318 { 319 tBTA_AG_SCB scb[BTA_AG_NUM_SCB]; /* service control blocks */ 320 tBTA_AG_PROFILE profile[BTA_AG_NUM_IDX]; /* profile-specific data */ 321 tBTA_AG_SCO_CB sco; /* SCO data */ 322 tBTA_AG_CBACK *p_cback; /* application callback */ 323 tBTA_AG_PARSE_MODE parse_mode; /* parse/pass-through mode */ 324 } tBTA_AG_CB; 325 326 /***************************************************************************** 327 ** Global data 328 *****************************************************************************/ 329 330 /* constant lookup tables */ 331 extern const UINT16 bta_ag_uuid[BTA_AG_NUM_IDX]; 332 extern const UINT8 bta_ag_sec_id[BTA_AG_NUM_IDX]; 333 extern const tBTA_AG_AT_CMD *bta_ag_at_tbl[BTA_AG_NUM_IDX]; 334 335 /* control block declaration */ 336 #if BTA_DYNAMIC_MEMORY == FALSE 337 extern tBTA_AG_CB bta_ag_cb; 338 #else 339 extern tBTA_AG_CB *bta_ag_cb_ptr; 340 #define bta_ag_cb (*bta_ag_cb_ptr) 341 #endif 342 343 /* config struct */ 344 extern tBTA_AG_CFG *p_bta_ag_cfg; 345 346 /***************************************************************************** 347 ** Function prototypes 348 *****************************************************************************/ 349 350 /* main functions */ 351 extern void bta_ag_scb_dealloc(tBTA_AG_SCB *p_scb); 352 extern UINT16 bta_ag_scb_to_idx(tBTA_AG_SCB *p_scb); 353 extern tBTA_AG_SCB *bta_ag_scb_by_idx(UINT16 idx); 354 extern UINT8 bta_ag_service_to_idx(tBTA_SERVICE_MASK services); 355 extern UINT16 bta_ag_idx_by_bdaddr(BD_ADDR peer_addr); 356 extern BOOLEAN bta_ag_other_scb_open(tBTA_AG_SCB *p_curr_scb); 357 extern BOOLEAN bta_ag_scb_open(tBTA_AG_SCB *p_curr_scb); 358 extern tBTA_AG_SCB *bta_ag_get_other_idle_scb (tBTA_AG_SCB *p_curr_scb); 359 extern void bta_ag_sm_execute(tBTA_AG_SCB *p_scb, UINT16 event, tBTA_AG_DATA *p_data); 360 extern BOOLEAN bta_ag_hdl_event(BT_HDR *p_msg); 361 extern void bta_ag_collision_cback (tBTA_SYS_CONN_STATUS status, UINT8 id, 362 UINT8 app_id, BD_ADDR peer_addr); 363 extern void bta_ag_resume_open (tBTA_AG_SCB *p_scb); 364 365 /* SDP functions */ 366 extern BOOLEAN bta_ag_add_record(UINT16 service_uuid, char *p_service_name, UINT8 scn, 367 tBTA_AG_FEAT features, UINT32 sdp_handle); 368 extern void bta_ag_create_records(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 369 extern void bta_ag_del_records(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 370 extern BOOLEAN bta_ag_sdp_find_attr(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK service); 371 extern void bta_ag_do_disc(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK service); 372 extern void bta_ag_free_db(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 373 374 /* RFCOMM functions */ 375 extern void bta_ag_start_servers(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK services); 376 extern void bta_ag_close_servers(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK services); 377 extern BOOLEAN bta_ag_is_server_closed (tBTA_AG_SCB *p_scb); 378 extern void bta_ag_rfc_do_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 379 extern void bta_ag_rfc_do_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 380 381 /* SCO functions */ 382 extern BOOLEAN bta_ag_sco_is_open(tBTA_AG_SCB *p_scb); 383 extern BOOLEAN bta_ag_sco_is_opening(tBTA_AG_SCB *p_scb); 384 extern void bta_ag_sco_conn_rsp(tBTA_AG_SCB *p_scb, tBTM_ESCO_CONN_REQ_EVT_DATA *p_data); 385 386 /* AT command functions */ 387 extern void bta_ag_at_hsp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, 388 char *p_arg, INT16 int_arg); 389 extern void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type, 390 char *p_arg, INT16 int_arg); 391 extern void bta_ag_at_err_cback(tBTA_AG_SCB *p_scb, BOOLEAN unknown, char *p_arg); 392 extern BOOLEAN bta_ag_inband_enabled(tBTA_AG_SCB *p_scb); 393 extern void bta_ag_send_call_inds(tBTA_AG_SCB *p_scb, tBTA_AG_RES result); 394 395 /* Action functions */ 396 extern void bta_ag_register(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 397 extern void bta_ag_deregister(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 398 extern void bta_ag_start_dereg(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 399 extern void bta_ag_start_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 400 extern void bta_ag_start_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 401 extern void bta_ag_disc_int_res(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 402 extern void bta_ag_disc_acp_res(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 403 extern void bta_ag_disc_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 404 extern void bta_ag_open_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 405 extern void bta_ag_rfc_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 406 extern void bta_ag_rfc_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 407 extern void bta_ag_rfc_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 408 extern void bta_ag_rfc_acp_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 409 extern void bta_ag_rfc_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 410 extern void bta_ag_sco_listen(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 411 extern void bta_ag_sco_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 412 extern void bta_ag_sco_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 413 #if (BTM_WBS_INCLUDED == TRUE ) 414 extern void bta_ag_sco_codec_nego(tBTA_AG_SCB *p_scb, BOOLEAN result); 415 extern void bta_ag_codec_negotiate (tBTA_AG_SCB *p_scb); 416 #endif 417 extern void bta_ag_sco_shutdown(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 418 extern void bta_ag_sco_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 419 extern void bta_ag_sco_conn_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 420 extern void bta_ag_post_sco_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 421 extern void bta_ag_post_sco_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 422 extern void bta_ag_svc_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 423 extern void bta_ag_result(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 424 extern void bta_ag_setcodec(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 425 #if (BTM_WBS_INCLUDED == TRUE ) 426 extern void bta_ag_send_bcs(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 427 #endif 428 extern void bta_ag_send_ring(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 429 extern void bta_ag_ci_sco_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 430 extern void bta_ag_set_esco_param(BOOLEAN set_reset, tBTM_ESCO_PARAMS *param); 431 extern void bta_ag_ci_rx_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 432 extern void bta_ag_rcvd_slc_ready(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data); 433 #endif /* BTA_AG_INT_H */ 434