1 /****************************************************************************** 2 * 3 * Copyright (C) 2004-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 advanced audio/video. 22 * 23 ******************************************************************************/ 24 #ifndef BTA_AV_INT_H 25 #define BTA_AV_INT_H 26 27 #include "avdt_api.h" 28 #include "bta_api.h" 29 #include "bta_av_api.h" 30 #include "bta_av_co.h" 31 #include "bta_sys.h" 32 #include "osi/include/list.h" 33 #include "stack/include/a2dp_api.h" 34 35 /***************************************************************************** 36 * Constants 37 ****************************************************************************/ 38 39 enum { 40 /* these events are handled by the AV main state machine */ 41 BTA_AV_API_DISABLE_EVT = BTA_SYS_EVT_START(BTA_ID_AV), 42 BTA_AV_API_REMOTE_CMD_EVT, 43 BTA_AV_API_VENDOR_CMD_EVT, 44 BTA_AV_API_VENDOR_RSP_EVT, 45 BTA_AV_API_META_RSP_EVT, 46 BTA_AV_API_RC_CLOSE_EVT, 47 BTA_AV_AVRC_OPEN_EVT, 48 BTA_AV_AVRC_MSG_EVT, 49 BTA_AV_AVRC_NONE_EVT, 50 51 /* these events are handled by the AV stream state machine */ 52 BTA_AV_API_OPEN_EVT, 53 BTA_AV_API_CLOSE_EVT, 54 BTA_AV_AP_START_EVT, /* the following 2 events must be in the same order as 55 the *API_*EVT */ 56 BTA_AV_AP_STOP_EVT, 57 BTA_AV_API_RECONFIG_EVT, 58 BTA_AV_API_PROTECT_REQ_EVT, 59 BTA_AV_API_PROTECT_RSP_EVT, 60 BTA_AV_API_RC_OPEN_EVT, 61 BTA_AV_SRC_DATA_READY_EVT, 62 BTA_AV_CI_SETCONFIG_OK_EVT, 63 BTA_AV_CI_SETCONFIG_FAIL_EVT, 64 BTA_AV_SDP_DISC_OK_EVT, 65 BTA_AV_SDP_DISC_FAIL_EVT, 66 BTA_AV_STR_DISC_OK_EVT, 67 BTA_AV_STR_DISC_FAIL_EVT, 68 BTA_AV_STR_GETCAP_OK_EVT, 69 BTA_AV_STR_GETCAP_FAIL_EVT, 70 BTA_AV_STR_OPEN_OK_EVT, 71 BTA_AV_STR_OPEN_FAIL_EVT, 72 BTA_AV_STR_START_OK_EVT, 73 BTA_AV_STR_START_FAIL_EVT, 74 BTA_AV_STR_CLOSE_EVT, 75 BTA_AV_STR_CONFIG_IND_EVT, 76 BTA_AV_STR_SECURITY_IND_EVT, 77 BTA_AV_STR_SECURITY_CFM_EVT, 78 BTA_AV_STR_WRITE_CFM_EVT, 79 BTA_AV_STR_SUSPEND_CFM_EVT, 80 BTA_AV_STR_RECONFIG_CFM_EVT, 81 BTA_AV_AVRC_TIMER_EVT, 82 BTA_AV_AVDT_CONNECT_EVT, 83 BTA_AV_AVDT_DISCONNECT_EVT, 84 BTA_AV_ROLE_CHANGE_EVT, 85 BTA_AV_AVDT_DELAY_RPT_EVT, 86 BTA_AV_ACP_CONNECT_EVT, 87 BTA_AV_API_OFFLOAD_START_EVT, 88 BTA_AV_API_OFFLOAD_START_RSP_EVT, 89 90 /* these events are handled outside of the state machine */ 91 BTA_AV_API_ENABLE_EVT, 92 BTA_AV_API_REGISTER_EVT, 93 BTA_AV_API_DEREGISTER_EVT, 94 BTA_AV_API_DISCONNECT_EVT, 95 BTA_AV_CI_SRC_DATA_READY_EVT, 96 BTA_AV_SIG_CHG_EVT, 97 BTA_AV_SIGNALLING_TIMER_EVT, 98 BTA_AV_SDP_AVRC_DISC_EVT, 99 BTA_AV_AVRC_CLOSE_EVT, 100 BTA_AV_AVRC_BROWSE_OPEN_EVT, 101 BTA_AV_AVRC_BROWSE_CLOSE_EVT, 102 BTA_AV_CONN_CHG_EVT, 103 BTA_AV_DEREG_COMP_EVT, 104 #if (AVDT_REPORTING == TRUE) 105 BTA_AV_AVDT_RPT_CONN_EVT, 106 #endif 107 BTA_AV_API_START_EVT, /* the following 2 events must be in the same order as 108 the *AP_*EVT */ 109 BTA_AV_API_STOP_EVT 110 }; 111 112 /* events for AV control block state machine */ 113 #define BTA_AV_FIRST_SM_EVT BTA_AV_API_DISABLE_EVT 114 #define BTA_AV_LAST_SM_EVT BTA_AV_AVRC_NONE_EVT 115 116 /* events for AV stream control block state machine */ 117 #define BTA_AV_FIRST_SSM_EVT BTA_AV_API_OPEN_EVT 118 119 /* events that do not go through state machine */ 120 #define BTA_AV_FIRST_NSM_EVT BTA_AV_API_ENABLE_EVT 121 #define BTA_AV_LAST_NSM_EVT BTA_AV_API_STOP_EVT 122 123 /* API events passed to both SSMs (by bta_av_api_to_ssm) */ 124 #define BTA_AV_FIRST_A2S_API_EVT BTA_AV_API_START_EVT 125 #define BTA_AV_FIRST_A2S_SSM_EVT BTA_AV_AP_START_EVT 126 127 #define BTA_AV_LAST_EVT BTA_AV_API_STOP_EVT 128 129 /* maximum number of SEPS in stream discovery results */ 130 #define BTA_AV_NUM_SEPS 32 131 132 /* initialization value for AVRC handle */ 133 #define BTA_AV_RC_HANDLE_NONE 0xFF 134 135 /* size of database for service discovery */ 136 #define BTA_AV_DISC_BUF_SIZE 1000 137 138 /* maximum length of AVDTP security data */ 139 #define BTA_AV_SECURITY_MAX_LEN 400 140 141 /* check number of buffers queued at L2CAP when this amount of buffers are 142 * queued to L2CAP */ 143 #define BTA_AV_QUEUE_DATA_CHK_NUM L2CAP_HIGH_PRI_MIN_XMIT_QUOTA 144 145 /* the number of ACL links with AVDT */ 146 #define BTA_AV_NUM_LINKS AVDT_NUM_LINKS 147 148 #define BTA_AV_BE_STREAM_TO_CO_ID(u32, p) \ 149 { \ 150 (u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + \ 151 (((uint32_t)(*(p))) << 16)); \ 152 (p) += 3; \ 153 } 154 155 /***************************************************************************** 156 * Data types 157 ****************************************************************************/ 158 159 /* function types for call-out functions */ 160 typedef bool (*tBTA_AV_CO_INIT)(btav_a2dp_codec_index_t codec_index, 161 tAVDT_CFG* p_cfg); 162 typedef void (*tBTA_AV_CO_DISC_RES)(tBTA_AV_HNDL hndl, uint8_t num_seps, 163 uint8_t num_snk, uint8_t num_src, 164 const RawAddress& addr, 165 uint16_t uuid_local); 166 typedef tA2DP_STATUS (*tBTA_AV_CO_GETCFG)(tBTA_AV_HNDL hndl, 167 uint8_t* p_codec_info, 168 uint8_t* p_sep_info_idx, uint8_t seid, 169 uint8_t* p_num_protect, 170 uint8_t* p_protect_info); 171 typedef void (*tBTA_AV_CO_SETCFG)(tBTA_AV_HNDL hndl, 172 const uint8_t* p_codec_info, uint8_t seid, 173 const RawAddress& addr, uint8_t num_protect, 174 const uint8_t* p_protect_info, 175 uint8_t t_local_sep, uint8_t avdt_handle); 176 typedef void (*tBTA_AV_CO_OPEN)(tBTA_AV_HNDL hndl, uint16_t mtu); 177 typedef void (*tBTA_AV_CO_CLOSE)(tBTA_AV_HNDL hndl); 178 typedef void (*tBTA_AV_CO_START)(tBTA_AV_HNDL hndl, uint8_t* p_codec_info, 179 bool* p_no_rtp_hdr); 180 typedef void (*tBTA_AV_CO_STOP)(tBTA_AV_HNDL hndl); 181 typedef void* (*tBTA_AV_CO_DATAPATH)(const uint8_t* p_codec_info, 182 uint32_t* p_timestamp); 183 typedef void (*tBTA_AV_CO_DELAY)(tBTA_AV_HNDL hndl, uint16_t delay); 184 typedef void (*tBTA_AV_CO_UPDATE_MTU)(tBTA_AV_HNDL hndl, uint16_t mtu); 185 186 /* the call-out functions for one stream */ 187 typedef struct { 188 tBTA_AV_CO_INIT init; 189 tBTA_AV_CO_DISC_RES disc_res; 190 tBTA_AV_CO_GETCFG getcfg; 191 tBTA_AV_CO_SETCFG setcfg; 192 tBTA_AV_CO_OPEN open; 193 tBTA_AV_CO_CLOSE close; 194 tBTA_AV_CO_START start; 195 tBTA_AV_CO_STOP stop; 196 tBTA_AV_CO_DATAPATH data; 197 tBTA_AV_CO_DELAY delay; 198 tBTA_AV_CO_UPDATE_MTU update_mtu; 199 } tBTA_AV_CO_FUNCTS; 200 201 /* data type for BTA_AV_API_ENABLE_EVT */ 202 typedef struct { 203 BT_HDR hdr; 204 tBTA_AV_CBACK* p_cback; 205 tBTA_AV_FEAT features; 206 tBTA_SEC sec_mask; 207 } tBTA_AV_API_ENABLE; 208 209 /* data type for BTA_AV_API_REGISTER_EVT */ 210 typedef struct { 211 BT_HDR hdr; 212 char p_service_name[BTA_SERVICE_NAME_LEN + 1]; 213 uint8_t app_id; 214 tBTA_AV_SINK_DATA_CBACK* p_app_sink_data_cback; 215 uint16_t service_uuid; 216 } tBTA_AV_API_REG; 217 218 enum { 219 BTA_AV_RS_NONE, /* straight API call */ 220 BTA_AV_RS_OK, /* the role switch result - successful */ 221 BTA_AV_RS_FAIL, /* the role switch result - failed */ 222 BTA_AV_RS_DONE /* the role switch is done - continue */ 223 }; 224 typedef uint8_t tBTA_AV_RS_RES; 225 /* data type for BTA_AV_API_OPEN_EVT */ 226 typedef struct { 227 BT_HDR hdr; 228 RawAddress bd_addr; 229 bool use_rc; 230 tBTA_SEC sec_mask; 231 tBTA_AV_RS_RES switch_res; 232 uint16_t uuid; /* uuid of initiator */ 233 } tBTA_AV_API_OPEN; 234 235 /* data type for BTA_AV_API_STOP_EVT */ 236 typedef struct { 237 BT_HDR hdr; 238 bool suspend; 239 bool flush; 240 bool reconfig_stop; // True if the stream is stopped for reconfiguration 241 } tBTA_AV_API_STOP; 242 243 /* data type for BTA_AV_API_DISCONNECT_EVT */ 244 typedef struct { 245 BT_HDR hdr; 246 RawAddress bd_addr; 247 } tBTA_AV_API_DISCNT; 248 249 /* data type for BTA_AV_API_PROTECT_REQ_EVT */ 250 typedef struct { 251 BT_HDR hdr; 252 uint8_t* p_data; 253 uint16_t len; 254 } tBTA_AV_API_PROTECT_REQ; 255 256 /* data type for BTA_AV_API_PROTECT_RSP_EVT */ 257 typedef struct { 258 BT_HDR hdr; 259 uint8_t* p_data; 260 uint16_t len; 261 uint8_t error_code; 262 } tBTA_AV_API_PROTECT_RSP; 263 264 /* data type for BTA_AV_API_REMOTE_CMD_EVT */ 265 typedef struct { 266 BT_HDR hdr; 267 tAVRC_MSG_PASS msg; 268 uint8_t label; 269 } tBTA_AV_API_REMOTE_CMD; 270 271 /* data type for BTA_AV_API_VENDOR_CMD_EVT and RSP */ 272 typedef struct { 273 BT_HDR hdr; 274 tAVRC_MSG_VENDOR msg; 275 uint8_t label; 276 } tBTA_AV_API_VENDOR; 277 278 /* data type for BTA_AV_API_RC_OPEN_EVT */ 279 typedef struct { BT_HDR hdr; } tBTA_AV_API_OPEN_RC; 280 281 /* data type for BTA_AV_API_RC_CLOSE_EVT */ 282 typedef struct { BT_HDR hdr; } tBTA_AV_API_CLOSE_RC; 283 284 /* data type for BTA_AV_API_META_RSP_EVT */ 285 typedef struct { 286 BT_HDR hdr; 287 bool is_rsp; 288 uint8_t label; 289 tBTA_AV_CODE rsp_code; 290 BT_HDR* p_pkt; 291 } tBTA_AV_API_META_RSP; 292 293 /* data type for BTA_AV_API_RECONFIG_EVT */ 294 typedef struct { 295 BT_HDR hdr; 296 uint8_t codec_info[AVDT_CODEC_SIZE]; /* codec configuration */ 297 uint8_t* p_protect_info; 298 uint8_t num_protect; 299 bool suspend; 300 uint8_t sep_info_idx; 301 } tBTA_AV_API_RCFG; 302 303 /* data type for BTA_AV_CI_SETCONFIG_OK_EVT and BTA_AV_CI_SETCONFIG_FAIL_EVT */ 304 typedef struct { 305 BT_HDR hdr; 306 tBTA_AV_HNDL hndl; 307 uint8_t err_code; 308 uint8_t category; 309 uint8_t num_seid; 310 uint8_t* p_seid; 311 bool recfg_needed; 312 uint8_t avdt_handle; /* local sep type for which this stream will be set up */ 313 } tBTA_AV_CI_SETCONFIG; 314 315 /* data type for all stream events from AVDTP */ 316 typedef struct { 317 BT_HDR hdr; 318 tAVDT_CFG cfg; /* configuration/capabilities parameters */ 319 tAVDT_CTRL msg; /* AVDTP callback message parameters */ 320 RawAddress bd_addr; /* bd address */ 321 uint8_t handle; 322 uint8_t avdt_event; 323 bool initiator; /* true, if local device initiates the SUSPEND */ 324 } tBTA_AV_STR_MSG; 325 326 /* data type for BTA_AV_AVRC_MSG_EVT */ 327 typedef struct { 328 BT_HDR hdr; 329 tAVRC_MSG msg; 330 uint8_t handle; 331 uint8_t label; 332 uint8_t opcode; 333 } tBTA_AV_RC_MSG; 334 335 /* data type for BTA_AV_AVRC_OPEN_EVT, BTA_AV_AVRC_CLOSE_EVT */ 336 typedef struct { 337 BT_HDR hdr; 338 RawAddress peer_addr; 339 uint8_t handle; 340 } tBTA_AV_RC_CONN_CHG; 341 342 /* data type for BTA_AV_CONN_CHG_EVT */ 343 typedef struct { 344 BT_HDR hdr; 345 RawAddress peer_addr; 346 bool is_up; 347 } tBTA_AV_CONN_CHG; 348 349 /* data type for BTA_AV_ROLE_CHANGE_EVT */ 350 typedef struct { 351 BT_HDR hdr; 352 uint8_t new_role; 353 uint8_t hci_status; 354 } tBTA_AV_ROLE_RES; 355 356 /* data type for BTA_AV_SDP_DISC_OK_EVT */ 357 typedef struct { 358 BT_HDR hdr; 359 uint16_t avdt_version; /* AVDTP protocol version */ 360 } tBTA_AV_SDP_RES; 361 362 /* data type for BTA_AV_API_OFFLOAD_RSP_EVT */ 363 typedef struct { 364 BT_HDR hdr; 365 tBTA_AV_STATUS status; 366 } tBTA_AV_API_STATUS_RSP; 367 368 /* type for SEP control block */ 369 typedef struct { 370 uint8_t av_handle; /* AVDTP handle */ 371 uint8_t tsep; /* SEP type of local SEP */ 372 uint8_t codec_info[AVDT_CODEC_SIZE]; /* Codec info */ 373 tBTA_AV_SINK_DATA_CBACK* 374 p_app_sink_data_cback; /* Sink application callback for media packets */ 375 } tBTA_AV_SEP; 376 377 /* initiator/acceptor role for adaption */ 378 #define BTA_AV_ROLE_AD_INT 0x00 /* initiator */ 379 #define BTA_AV_ROLE_AD_ACP 0x01 /* acceptor */ 380 381 /* initiator/acceptor signaling roles */ 382 #define BTA_AV_ROLE_START_ACP 0x00 383 #define BTA_AV_ROLE_START_INT 0x10 /* do not change this value */ 384 385 #define BTA_AV_ROLE_SUSPEND 0x20 /* suspending on start */ 386 #define BTA_AV_ROLE_SUSPEND_OPT 0x40 /* Suspend on Start option is set */ 387 388 /* union of all event datatypes */ 389 typedef union { 390 BT_HDR hdr; 391 tBTA_AV_API_ENABLE api_enable; 392 tBTA_AV_API_REG api_reg; 393 tBTA_AV_API_OPEN api_open; 394 tBTA_AV_API_STOP api_stop; 395 tBTA_AV_API_DISCNT api_discnt; 396 tBTA_AV_API_PROTECT_REQ api_protect_req; 397 tBTA_AV_API_PROTECT_RSP api_protect_rsp; 398 tBTA_AV_API_REMOTE_CMD api_remote_cmd; 399 tBTA_AV_API_VENDOR api_vendor; 400 tBTA_AV_API_RCFG api_reconfig; 401 tBTA_AV_CI_SETCONFIG ci_setconfig; 402 tBTA_AV_STR_MSG str_msg; 403 tBTA_AV_RC_MSG rc_msg; 404 tBTA_AV_RC_CONN_CHG rc_conn_chg; 405 tBTA_AV_CONN_CHG conn_chg; 406 tBTA_AV_ROLE_RES role_res; 407 tBTA_AV_SDP_RES sdp_res; 408 tBTA_AV_API_META_RSP api_meta_rsp; 409 tBTA_AV_API_STATUS_RSP api_status_rsp; 410 } tBTA_AV_DATA; 411 412 typedef union { 413 tBTA_AV_API_OPEN open; /* used only before open and role switch 414 is needed on another AV channel */ 415 } tBTA_AV_Q_INFO; 416 417 #define BTA_AV_Q_TAG_OPEN 0x01 /* after API_OPEN, before STR_OPENED */ 418 #define BTA_AV_Q_TAG_START 0x02 /* before start sending media packets */ 419 #define BTA_AV_Q_TAG_STREAM 0x03 /* during streaming */ 420 421 #define BTA_AV_WAIT_ACP_CAPS_ON 0x01 /* retriving the peer capabilities */ 422 #define BTA_AV_WAIT_ACP_CAPS_STARTED \ 423 0x02 /* started while retriving peer capabilities */ 424 #define BTA_AV_WAIT_ROLE_SW_RES_OPEN \ 425 0x04 /* waiting for role switch result after API_OPEN, before STR_OPENED */ 426 #define BTA_AV_WAIT_ROLE_SW_RES_START \ 427 0x08 /* waiting for role switch result before streaming */ 428 #define BTA_AV_WAIT_ROLE_SW_STARTED \ 429 0x10 /* started while waiting for role switch result */ 430 #define BTA_AV_WAIT_ROLE_SW_RETRY 0x20 /* set when retry on timeout */ 431 #define BTA_AV_WAIT_CHECK_RC \ 432 0x40 /* set when the timer is used by role switch */ 433 #define BTA_AV_WAIT_ROLE_SW_FAILED 0x80 /* role switch failed */ 434 435 #define BTA_AV_WAIT_ROLE_SW_BITS \ 436 (BTA_AV_WAIT_ROLE_SW_RES_OPEN | BTA_AV_WAIT_ROLE_SW_RES_START | \ 437 BTA_AV_WAIT_ROLE_SW_STARTED | BTA_AV_WAIT_ROLE_SW_RETRY) 438 439 /* Bitmap for collision, coll_mask */ 440 #define BTA_AV_COLL_INC_TMR \ 441 0x01 /* Timer is running for incoming L2C connection */ 442 #define BTA_AV_COLL_API_CALLED \ 443 0x02 /* API open was called while incoming timer is running */ 444 445 /* type for AV stream control block */ 446 typedef struct { 447 const tBTA_AV_ACT* p_act_tbl; /* the action table for stream state machine */ 448 const tBTA_AV_CO_FUNCTS* p_cos; /* the associated callout functions */ 449 bool sdp_discovery_started; /* variable to determine whether SDP is started */ 450 tBTA_AV_SEP seps[BTAV_A2DP_CODEC_INDEX_MAX]; 451 tAVDT_CFG* p_cap; /* buffer used for get capabilities */ 452 list_t* a2dp_list; /* used for audio channels only */ 453 tBTA_AV_Q_INFO q_info; 454 tAVDT_SEP_INFO sep_info[BTA_AV_NUM_SEPS]; /* stream discovery results */ 455 tAVDT_CFG cfg; /* local SEP configuration */ 456 alarm_t* avrc_ct_timer; /* delay timer for AVRC CT */ 457 RawAddress peer_addr; /* peer BD address */ 458 uint16_t l2c_cid; /* L2CAP channel ID */ 459 uint16_t stream_mtu; /* MTU of stream */ 460 uint16_t avdt_version; /* the avdt version of peer device */ 461 tBTA_SEC sec_mask; /* security mask */ 462 uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */ 463 bool cong; /* true if AVDTP congested */ 464 tBTA_AV_STATUS open_status; /* open failure status */ 465 tBTA_AV_CHNL chnl; /* the channel: audio/video */ 466 tBTA_AV_HNDL hndl; /* the handle: ((hdi + 1)|chnl) */ 467 uint16_t cur_psc_mask; /* Protocol service capabilities mask for current 468 connection */ 469 uint8_t avdt_handle; /* AVDTP handle */ 470 uint8_t hdi; /* the index to SCB[] */ 471 uint8_t num_seps; /* number of seps returned by stream discovery */ 472 uint8_t num_disc_snks; /* number of discovered snks */ 473 uint8_t num_disc_srcs; /* number of discovered srcs */ 474 uint8_t sep_info_idx; /* current index into sep_info */ 475 uint8_t sep_idx; /* current index into local seps[] */ 476 uint8_t rcfg_idx; /* reconfig requested index into sep_info */ 477 uint8_t state; /* state machine state */ 478 uint8_t avdt_label; /* AVDTP label */ 479 uint8_t app_id; /* application id */ 480 uint8_t num_recfg; /* number of reconfigure sent */ 481 uint8_t role; 482 uint8_t l2c_bufs; /* the number of buffers queued to L2CAP */ 483 uint8_t rc_handle; /* connected AVRCP handle */ 484 bool use_rc; /* true if AVRCP is allowed */ 485 bool started; /* true if stream started */ 486 A2dpCodecConfig* current_codec; /* The current A2DP codec */ 487 uint8_t 488 co_started; /* non-zero, if stream started from call-out perspective */ 489 bool recfg_sup; /* true if the first attempt to reconfigure the stream was 490 successfull, else False if command fails */ 491 bool suspend_sup; /* true if Suspend stream is supported, else false if 492 suspend command fails */ 493 bool deregistring; /* true if deregistering */ 494 bool sco_suspend; /* true if SUSPEND is issued automatically for SCO */ 495 uint8_t coll_mask; /* Mask to check incoming and outgoing collision */ 496 tBTA_AV_API_OPEN open_api; /* Saved OPEN api message */ 497 uint8_t wait; /* set 0x1, when getting Caps as ACP, set 0x2, when started */ 498 uint8_t q_tag; /* identify the associated q_info union member */ 499 bool no_rtp_hdr; /* true if add no RTP header*/ 500 uint16_t uuid_int; /*intended UUID of Initiator to connect to */ 501 bool offload_start_pending; 502 bool skip_sdp; /* Decides if sdp to be done prior to profile connection */ 503 } tBTA_AV_SCB; 504 505 #define BTA_AV_RC_ROLE_MASK 0x10 506 #define BTA_AV_RC_ROLE_INT 0x00 507 #define BTA_AV_RC_ROLE_ACP 0x10 508 509 #define BTA_AV_RC_CONN_MASK 0x20 510 511 /* type for AV RCP control block */ 512 /* index to this control block is the rc handle */ 513 typedef struct { 514 uint8_t status; 515 uint8_t handle; 516 uint8_t shdl; /* stream handle (hdi + 1) */ 517 uint8_t lidx; /* (index+1) to LCB */ 518 tBTA_AV_FEAT peer_features; /* peer features mask */ 519 } tBTA_AV_RCB; 520 #define BTA_AV_NUM_RCB (BTA_AV_NUM_STRS + 2) 521 522 enum { BTA_AV_LCB_FREE, BTA_AV_LCB_FIND }; 523 524 /* type for AV ACL Link control block */ 525 typedef struct { 526 RawAddress addr; /* peer BD address */ 527 uint8_t conn_msk; /* handle mask of connected stream handle */ 528 uint8_t lidx; /* index + 1 */ 529 } tBTA_AV_LCB; 530 531 /* type for stream state machine action functions */ 532 typedef void (*tBTA_AV_SACT)(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 533 534 /* type for AV control block */ 535 typedef struct { 536 tBTA_AV_SCB* p_scb[BTA_AV_NUM_STRS]; /* stream control block */ 537 tSDP_DISCOVERY_DB* p_disc_db; /* pointer to discovery database */ 538 tBTA_AV_CBACK* p_cback; /* application callback function */ 539 tBTA_AV_RCB rcb[BTA_AV_NUM_RCB]; /* RCB control block */ 540 tBTA_AV_LCB lcb[BTA_AV_NUM_LINKS + 1]; /* link control block */ 541 alarm_t* link_signalling_timer; 542 alarm_t* 543 accept_signalling_timer; /* timer to monitor signalling when accepting */ 544 uint32_t sdp_a2dp_handle; /* SDP record handle for audio src */ 545 uint32_t sdp_a2dp_snk_handle; /* SDP record handle for audio snk */ 546 uint32_t sdp_vdp_handle; /* SDP record handle for video src */ 547 tBTA_AV_FEAT features; /* features mask */ 548 tBTA_SEC sec_mask; /* security mask */ 549 tBTA_AV_HNDL handle; /* the handle for SDP activity */ 550 bool disabling; /* true if api disabled called */ 551 uint8_t 552 disc; /* (hdi+1) or (rc_handle|BTA_AV_CHNL_MSK) if p_disc_db is in use */ 553 uint8_t state; /* state machine state */ 554 uint8_t conn_rc; /* handle mask of connected RCP channels */ 555 uint8_t conn_audio; /* handle mask of connected audio channels */ 556 uint8_t conn_video; /* handle mask of connected video channels */ 557 uint8_t conn_lcb; /* index mask of used LCBs */ 558 uint8_t audio_open_cnt; /* number of connected audio channels */ 559 uint8_t reg_audio; /* handle mask of registered audio channels */ 560 uint8_t reg_video; /* handle mask of registered video channels */ 561 uint8_t rc_acp_handle; 562 uint8_t rc_acp_idx; /* (index + 1) to RCB */ 563 uint8_t rs_idx; /* (index + 1) to SCB for the one waiting for RS on open */ 564 bool sco_occupied; /* true if SCO is being used or call is in progress */ 565 uint8_t audio_streams; /* handle mask of streaming audio channels */ 566 uint8_t video_streams; /* handle mask of streaming video channels */ 567 } tBTA_AV_CB; 568 569 /***************************************************************************** 570 * Global data 571 ****************************************************************************/ 572 573 /* control block declaration */ 574 extern tBTA_AV_CB bta_av_cb; 575 576 /* config struct */ 577 extern tBTA_AV_CFG* p_bta_av_cfg; 578 extern const tBTA_AV_CFG bta_avk_cfg; 579 extern const tBTA_AV_CFG bta_av_cfg; 580 extern const tBTA_AV_CFG bta_av_cfg_compatibility; 581 582 /* rc id config struct */ 583 extern uint16_t* p_bta_av_rc_id; 584 extern uint16_t* p_bta_av_rc_id_ac; 585 586 extern const tBTA_AV_SACT bta_av_a2dp_action[]; 587 extern const tBTA_AV_CO_FUNCTS bta_av_a2dp_cos; 588 extern tAVDT_CTRL_CBACK* const bta_av_dt_cback[]; 589 extern void bta_av_sink_data_cback(uint8_t handle, BT_HDR* p_pkt, 590 uint32_t time_stamp, uint8_t m_pt); 591 592 /***************************************************************************** 593 * Function prototypes 594 ****************************************************************************/ 595 /* utility functions */ 596 extern tBTA_AV_SCB* bta_av_hndl_to_scb(uint16_t handle); 597 extern bool bta_av_chk_start(tBTA_AV_SCB* p_scb); 598 extern void bta_av_restore_switch(void); 599 extern uint16_t bta_av_chk_mtu(tBTA_AV_SCB* p_scb, uint16_t mtu); 600 extern void bta_av_conn_cback(uint8_t handle, const RawAddress* bd_addr, 601 uint8_t event, tAVDT_CTRL* p_data); 602 extern uint8_t bta_av_rc_create(tBTA_AV_CB* p_cb, uint8_t role, uint8_t shdl, 603 uint8_t lidx); 604 extern void bta_av_stream_chg(tBTA_AV_SCB* p_scb, bool started); 605 extern bool bta_av_is_scb_opening(tBTA_AV_SCB* p_scb); 606 extern bool bta_av_is_scb_incoming(tBTA_AV_SCB* p_scb); 607 extern void bta_av_set_scb_sst_init(tBTA_AV_SCB* p_scb); 608 extern bool bta_av_is_scb_init(tBTA_AV_SCB* p_scb); 609 extern void bta_av_set_scb_sst_incoming(tBTA_AV_SCB* p_scb); 610 extern tBTA_AV_LCB* bta_av_find_lcb(const RawAddress& addr, uint8_t op); 611 612 /* main functions */ 613 extern void bta_av_api_deregister(tBTA_AV_DATA* p_data); 614 extern void bta_av_dup_audio_buf(tBTA_AV_SCB* p_scb, BT_HDR* p_buf); 615 extern void bta_av_sm_execute(tBTA_AV_CB* p_cb, uint16_t event, 616 tBTA_AV_DATA* p_data); 617 extern void bta_av_ssm_execute(tBTA_AV_SCB* p_scb, uint16_t event, 618 tBTA_AV_DATA* p_data); 619 extern bool bta_av_hdl_event(BT_HDR* p_msg); 620 extern const char* bta_av_evt_code(uint16_t evt_code); 621 extern bool bta_av_switch_if_needed(tBTA_AV_SCB* p_scb); 622 extern bool bta_av_link_role_ok(tBTA_AV_SCB* p_scb, uint8_t bits); 623 extern bool bta_av_is_rcfg_sst(tBTA_AV_SCB* p_scb); 624 625 /* nsm action functions */ 626 extern void bta_av_api_disconnect(tBTA_AV_DATA* p_data); 627 extern void bta_av_sig_chg(tBTA_AV_DATA* p_data); 628 extern void bta_av_signalling_timer(tBTA_AV_DATA* p_data); 629 extern void bta_av_rc_disc_done(tBTA_AV_DATA* p_data); 630 extern void bta_av_rc_closed(tBTA_AV_DATA* p_data); 631 extern void bta_av_rc_browse_opened(tBTA_AV_DATA* p_data); 632 extern void bta_av_rc_browse_closed(tBTA_AV_DATA* p_data); 633 extern void bta_av_rc_disc(uint8_t disc); 634 extern void bta_av_conn_chg(tBTA_AV_DATA* p_data); 635 extern void bta_av_dereg_comp(tBTA_AV_DATA* p_data); 636 637 /* sm action functions */ 638 extern void bta_av_disable(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 639 extern void bta_av_rc_opened(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 640 extern void bta_av_rc_remote_cmd(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 641 extern void bta_av_rc_vendor_cmd(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 642 extern void bta_av_rc_vendor_rsp(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 643 extern void bta_av_rc_msg(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 644 extern void bta_av_rc_close(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 645 extern void bta_av_rc_meta_rsp(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 646 extern void bta_av_rc_free_rsp(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 647 extern void bta_av_rc_free_browse_msg(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data); 648 649 extern tBTA_AV_RCB* bta_av_get_rcb_by_shdl(uint8_t shdl); 650 extern void bta_av_del_rc(tBTA_AV_RCB* p_rcb); 651 652 /* ssm action functions */ 653 extern void bta_av_do_disc_a2dp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 654 extern void bta_av_cleanup(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 655 extern void bta_av_free_sdb(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 656 extern void bta_av_config_ind(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 657 extern void bta_av_disconnect_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 658 extern void bta_av_security_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 659 extern void bta_av_security_rsp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 660 extern void bta_av_setconfig_rsp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 661 extern void bta_av_str_opened(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 662 extern void bta_av_security_ind(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 663 extern void bta_av_security_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 664 extern void bta_av_do_close(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 665 extern void bta_av_connect_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 666 extern void bta_av_sdp_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 667 extern void bta_av_disc_results(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 668 extern void bta_av_disc_res_as_acp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 669 extern void bta_av_open_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 670 extern void bta_av_getcap_results(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 671 extern void bta_av_setconfig_rej(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 672 extern void bta_av_discover_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 673 extern void bta_av_conn_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 674 extern void bta_av_do_start(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 675 extern void bta_av_str_stopped(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 676 extern void bta_av_reconfig(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 677 extern void bta_av_data_path(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 678 extern void bta_av_start_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 679 extern void bta_av_start_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 680 extern void bta_av_str_closed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 681 extern void bta_av_clr_cong(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 682 extern void bta_av_suspend_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 683 extern void bta_av_rcfg_str_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 684 extern void bta_av_rcfg_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 685 extern void bta_av_rcfg_connect(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 686 extern void bta_av_rcfg_discntd(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 687 extern void bta_av_suspend_cont(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 688 extern void bta_av_rcfg_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 689 extern void bta_av_rcfg_open(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 690 extern void bta_av_security_rej(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 691 extern void bta_av_open_rc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 692 extern void bta_av_chk_2nd_start(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 693 extern void bta_av_save_caps(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 694 extern void bta_av_rej_conn(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 695 extern void bta_av_rej_conn(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 696 extern void bta_av_set_use_rc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 697 extern void bta_av_cco_close(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 698 extern void bta_av_switch_role(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 699 extern void bta_av_role_res(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 700 extern void bta_av_delay_co(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 701 extern void bta_av_open_at_inc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 702 extern void bta_av_offload_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 703 extern void bta_av_offload_rsp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data); 704 705 #endif /* BTA_AV_INT_H */ 706