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