1 /****************************************************************************** 2 * 3 * Copyright (C) 2002-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 file contains interfaces which are internal to AVDTP. 22 * 23 ******************************************************************************/ 24 #ifndef AVDT_INT_H 25 #define AVDT_INT_H 26 27 #include "stack/avdt_api.h" 28 #include "stack/avdtc_api.h" 29 #include "avdt_defs.h" 30 #include "stack/l2c_api.h" 31 #include "stack/btm_api.h" 32 #include "osi/fixed_queue.h" 33 34 #if (AVRC_INCLUDED == TRUE) 35 36 #ifndef AVDT_DEBUG 37 #define AVDT_DEBUG FALSE 38 #endif 39 40 /***************************************************************************** 41 ** constants 42 *****************************************************************************/ 43 44 /* channel types */ 45 enum { 46 AVDT_CHAN_SIG, /* signaling channel */ 47 AVDT_CHAN_MEDIA, /* media channel */ 48 #if AVDT_REPORTING == TRUE 49 AVDT_CHAN_REPORT, /* reporting channel */ 50 #endif 51 AVDT_CHAN_NUM_TYPES 52 }; 53 54 /* protocol service capabilities of this AVDTP implementation */ 55 /* for now multiplexing will be used only for fragmentation */ 56 #if ((AVDT_MULTIPLEXING == TRUE) && (AVDT_REPORTING == TRUE)) 57 #define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_MUX | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT) 58 #define AVDT_LEG_PSC (AVDT_PSC_TRANS | AVDT_PSC_MUX | AVDT_PSC_REPORT) 59 #else /* AVDT_MULTIPLEXING && AVDT_REPORTING */ 60 61 #if (AVDT_MULTIPLEXING == TRUE) 62 #define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_MUX | AVDT_PSC_DELAY_RPT) 63 #define AVDT_LEG_PSC (AVDT_PSC_TRANS | AVDT_PSC_MUX) 64 #else /* AVDT_MULTIPLEXING */ 65 66 #if (AVDT_REPORTING == TRUE) 67 #define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT) 68 #define AVDT_LEG_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT) 69 #else /* AVDT_REPORTING */ 70 #define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_DELAY_RPT) 71 #define AVDT_LEG_PSC (AVDT_PSC_TRANS) 72 #endif /* AVDT_REPORTING */ 73 74 #endif /* AVDT_MULTIPLEXING */ 75 76 #endif /* AVDT_MULTIPLEXING && AVDT_REPORTING */ 77 78 /* initiator/acceptor signaling roles */ 79 #define AVDT_CLOSE_ACP 0 80 #define AVDT_CLOSE_INT 1 81 #define AVDT_OPEN_ACP 2 82 #define AVDT_OPEN_INT 3 83 #define AVDT_CONF_ACP 4 84 #define AVDT_CONF_INT 5 85 86 /* states for avdt_scb_verify */ 87 #define AVDT_VERIFY_OPEN 0 88 #define AVDT_VERIFY_STREAMING 1 89 #define AVDT_VERIFY_SUSPEND 2 90 #define AVDT_VERIFY_START 3 91 92 /* to distinguish CCB events from SCB events */ 93 #define AVDT_CCB_MKR 0x80 94 95 /* offset where AVDTP signaling message header starts in message */ 96 #define AVDT_HDR_OFFSET (L2CAP_MIN_OFFSET + AVDT_NUM_SEPS) 97 98 /* offset where AVDTP signaling message content starts; 99 ** use the size of a start header since it's the largest possible 100 ** layout of signaling message in a buffer is: 101 ** 102 ** | BT_HDR | SCB handles | L2CAP + HCI header | AVDTP header | data ... | 103 ** 104 ** Note that we "hide" the scb handles at the top of the message buffer. 105 */ 106 #define AVDT_MSG_OFFSET (L2CAP_MIN_OFFSET + AVDT_NUM_SEPS + AVDT_LEN_TYPE_START) 107 108 /* scb transport channel connect timeout value */ 109 #define AVDT_SCB_TC_CONN_TOUT 10 110 111 /* scb transport channel disconnect timeout value */ 112 #define AVDT_SCB_TC_DISC_TOUT 10 113 114 /* scb transport delay reporting command timeout value */ 115 #define AVDT_SCB_TC_DELAY_RPT_TOUT 5 116 117 /* maximum number of command retransmissions */ 118 #ifndef AVDT_RET_MAX 119 #define AVDT_RET_MAX 1 120 #endif 121 122 123 /* ccb state machine states */ 124 enum { 125 AVDT_CCB_IDLE_ST, 126 AVDT_CCB_OPENING_ST, 127 AVDT_CCB_OPEN_ST, 128 AVDT_CCB_CLOSING_ST 129 }; 130 131 /* state machine action enumeration list */ 132 enum { 133 AVDT_CCB_CHAN_OPEN, 134 AVDT_CCB_CHAN_CLOSE, 135 AVDT_CCB_CHK_CLOSE, 136 AVDT_CCB_HDL_DISCOVER_CMD, 137 AVDT_CCB_HDL_DISCOVER_RSP, 138 AVDT_CCB_HDL_GETCAP_CMD, 139 AVDT_CCB_HDL_GETCAP_RSP, 140 AVDT_CCB_HDL_START_CMD, 141 AVDT_CCB_HDL_START_RSP, 142 AVDT_CCB_HDL_SUSPEND_CMD, 143 AVDT_CCB_HDL_SUSPEND_RSP, 144 AVDT_CCB_SND_DISCOVER_CMD, 145 AVDT_CCB_SND_DISCOVER_RSP, 146 AVDT_CCB_SND_GETCAP_CMD, 147 AVDT_CCB_SND_GETCAP_RSP, 148 AVDT_CCB_SND_START_CMD, 149 AVDT_CCB_SND_START_RSP, 150 AVDT_CCB_SND_SUSPEND_CMD, 151 AVDT_CCB_SND_SUSPEND_RSP, 152 AVDT_CCB_CLEAR_CMDS, 153 AVDT_CCB_CMD_FAIL, 154 AVDT_CCB_FREE_CMD, 155 AVDT_CCB_CONG_STATE, 156 AVDT_CCB_RET_CMD, 157 AVDT_CCB_SND_CMD, 158 AVDT_CCB_SND_MSG, 159 AVDT_CCB_SET_RECONN, 160 AVDT_CCB_CLR_RECONN, 161 AVDT_CCB_CHK_RECONN, 162 AVDT_CCB_CHK_TIMER, 163 AVDT_CCB_SET_CONN, 164 AVDT_CCB_SET_DISCONN, 165 AVDT_CCB_DO_DISCONN, 166 AVDT_CCB_LL_CLOSED, 167 AVDT_CCB_LL_OPENED, 168 AVDT_CCB_DEALLOC, 169 AVDT_CCB_NUM_ACTIONS 170 }; 171 172 #define AVDT_CCB_IGNORE AVDT_CCB_NUM_ACTIONS 173 174 /* ccb state machine events */ 175 enum { 176 AVDT_CCB_API_DISCOVER_REQ_EVT, 177 AVDT_CCB_API_GETCAP_REQ_EVT, 178 AVDT_CCB_API_START_REQ_EVT, 179 AVDT_CCB_API_SUSPEND_REQ_EVT, 180 AVDT_CCB_API_DISCOVER_RSP_EVT, 181 AVDT_CCB_API_GETCAP_RSP_EVT, 182 AVDT_CCB_API_START_RSP_EVT, 183 AVDT_CCB_API_SUSPEND_RSP_EVT, 184 AVDT_CCB_API_CONNECT_REQ_EVT, 185 AVDT_CCB_API_DISCONNECT_REQ_EVT, 186 AVDT_CCB_MSG_DISCOVER_CMD_EVT, 187 AVDT_CCB_MSG_GETCAP_CMD_EVT, 188 AVDT_CCB_MSG_START_CMD_EVT, 189 AVDT_CCB_MSG_SUSPEND_CMD_EVT, 190 AVDT_CCB_MSG_DISCOVER_RSP_EVT, 191 AVDT_CCB_MSG_GETCAP_RSP_EVT, 192 AVDT_CCB_MSG_START_RSP_EVT, 193 AVDT_CCB_MSG_SUSPEND_RSP_EVT, 194 AVDT_CCB_RCVRSP_EVT, 195 AVDT_CCB_SENDMSG_EVT, 196 AVDT_CCB_RET_TOUT_EVT, 197 AVDT_CCB_RSP_TOUT_EVT, 198 AVDT_CCB_IDLE_TOUT_EVT, 199 AVDT_CCB_UL_OPEN_EVT, 200 AVDT_CCB_UL_CLOSE_EVT, 201 AVDT_CCB_LL_OPEN_EVT, 202 AVDT_CCB_LL_CLOSE_EVT, 203 AVDT_CCB_LL_CONG_EVT 204 }; 205 206 207 /* scb state machine states; these state values are private to this module so 208 ** the scb state cannot be read or set by actions functions 209 */ 210 enum { 211 AVDT_SCB_IDLE_ST, 212 AVDT_SCB_CONF_ST, 213 AVDT_SCB_OPENING_ST, 214 AVDT_SCB_OPEN_ST, 215 AVDT_SCB_STREAM_ST, 216 AVDT_SCB_CLOSING_ST 217 }; 218 219 /* state machine action enumeration list */ 220 enum { 221 AVDT_SCB_HDL_ABORT_CMD, 222 AVDT_SCB_HDL_ABORT_RSP, 223 AVDT_SCB_HDL_CLOSE_CMD, 224 AVDT_SCB_HDL_CLOSE_RSP, 225 AVDT_SCB_HDL_GETCONFIG_CMD, 226 AVDT_SCB_HDL_GETCONFIG_RSP, 227 AVDT_SCB_HDL_OPEN_CMD, 228 AVDT_SCB_HDL_OPEN_REJ, 229 AVDT_SCB_HDL_OPEN_RSP, 230 AVDT_SCB_HDL_PKT, 231 AVDT_SCB_DROP_PKT, 232 AVDT_SCB_HDL_RECONFIG_CMD, 233 AVDT_SCB_HDL_RECONFIG_RSP, 234 AVDT_SCB_HDL_SECURITY_CMD, 235 AVDT_SCB_HDL_SECURITY_RSP, 236 AVDT_SCB_HDL_SETCONFIG_CMD, 237 AVDT_SCB_HDL_SETCONFIG_REJ, 238 AVDT_SCB_HDL_SETCONFIG_RSP, 239 AVDT_SCB_HDL_START_CMD, 240 AVDT_SCB_HDL_START_RSP, 241 AVDT_SCB_HDL_SUSPEND_CMD, 242 AVDT_SCB_HDL_SUSPEND_RSP, 243 AVDT_SCB_HDL_TC_CLOSE, 244 #if AVDT_REPORTING == TRUE 245 AVDT_SCB_HDL_TC_CLOSE_STO, 246 #endif 247 AVDT_SCB_HDL_TC_OPEN, 248 #if AVDT_REPORTING == TRUE 249 AVDT_SCB_HDL_TC_OPEN_STO, 250 #endif 251 AVDT_SCB_SND_DELAY_RPT_REQ, 252 AVDT_SCB_HDL_DELAY_RPT_CMD, 253 AVDT_SCB_HDL_DELAY_RPT_RSP, 254 AVDT_SCB_HDL_WRITE_REQ, 255 AVDT_SCB_SND_ABORT_REQ, 256 AVDT_SCB_SND_ABORT_RSP, 257 AVDT_SCB_SND_CLOSE_REQ, 258 AVDT_SCB_SND_STREAM_CLOSE, 259 AVDT_SCB_SND_CLOSE_RSP, 260 AVDT_SCB_SND_GETCONFIG_REQ, 261 AVDT_SCB_SND_GETCONFIG_RSP, 262 AVDT_SCB_SND_OPEN_REQ, 263 AVDT_SCB_SND_OPEN_RSP, 264 AVDT_SCB_SND_RECONFIG_REQ, 265 AVDT_SCB_SND_RECONFIG_RSP, 266 AVDT_SCB_SND_SECURITY_REQ, 267 AVDT_SCB_SND_SECURITY_RSP, 268 AVDT_SCB_SND_SETCONFIG_REQ, 269 AVDT_SCB_SND_SETCONFIG_REJ, 270 AVDT_SCB_SND_SETCONFIG_RSP, 271 AVDT_SCB_SND_TC_CLOSE, 272 AVDT_SCB_CB_ERR, 273 AVDT_SCB_CONG_STATE, 274 AVDT_SCB_REJ_STATE, 275 AVDT_SCB_REJ_IN_USE, 276 AVDT_SCB_REJ_NOT_IN_USE, 277 AVDT_SCB_SET_REMOVE, 278 AVDT_SCB_FREE_PKT, 279 AVDT_SCB_CLR_PKT, 280 AVDT_SCB_CHK_SND_PKT, 281 AVDT_SCB_TC_TIMER, 282 AVDT_SCB_CLR_VARS, 283 AVDT_SCB_DEALLOC, 284 AVDT_SCB_HDL_DELAY_RPT_TOUT, 285 AVDT_SCB_INIT_OPEN_REQ_EVT, 286 AVDT_SCB_SEND_DELAY_REPORT_CMD_EVT, 287 AVDT_SCB_NUM_ACTIONS 288 }; 289 290 #define AVDT_SCB_IGNORE AVDT_SCB_NUM_ACTIONS 291 292 /* scb state machine events */ 293 enum { 294 AVDT_SCB_API_REMOVE_EVT, 295 AVDT_SCB_API_WRITE_REQ_EVT, 296 AVDT_SCB_API_GETCONFIG_REQ_EVT, 297 AVDT_SCB_API_DELAY_RPT_REQ_EVT, 298 AVDT_SCB_API_SETCONFIG_REQ_EVT, 299 AVDT_SCB_API_OPEN_REQ_EVT, 300 AVDT_SCB_API_CLOSE_REQ_EVT, 301 AVDT_SCB_API_RECONFIG_REQ_EVT, 302 AVDT_SCB_API_SECURITY_REQ_EVT, 303 AVDT_SCB_API_ABORT_REQ_EVT, 304 AVDT_SCB_API_GETCONFIG_RSP_EVT, 305 AVDT_SCB_API_SETCONFIG_RSP_EVT, 306 AVDT_SCB_API_SETCONFIG_REJ_EVT, 307 AVDT_SCB_API_OPEN_RSP_EVT, 308 AVDT_SCB_API_CLOSE_RSP_EVT, 309 AVDT_SCB_API_RECONFIG_RSP_EVT, 310 AVDT_SCB_API_SECURITY_RSP_EVT, 311 AVDT_SCB_API_ABORT_RSP_EVT, 312 AVDT_SCB_MSG_SETCONFIG_CMD_EVT, 313 AVDT_SCB_MSG_GETCONFIG_CMD_EVT, 314 AVDT_SCB_MSG_OPEN_CMD_EVT, 315 AVDT_SCB_MSG_START_CMD_EVT, 316 AVDT_SCB_MSG_SUSPEND_CMD_EVT, 317 AVDT_SCB_MSG_CLOSE_CMD_EVT, 318 AVDT_SCB_MSG_ABORT_CMD_EVT, 319 AVDT_SCB_MSG_RECONFIG_CMD_EVT, 320 AVDT_SCB_MSG_SECURITY_CMD_EVT, 321 AVDT_SCB_MSG_DELAY_RPT_CMD_EVT, 322 AVDT_SCB_MSG_DELAY_RPT_RSP_EVT, 323 AVDT_SCB_MSG_SETCONFIG_RSP_EVT, 324 AVDT_SCB_MSG_GETCONFIG_RSP_EVT, 325 AVDT_SCB_MSG_OPEN_RSP_EVT, 326 AVDT_SCB_MSG_START_RSP_EVT, 327 AVDT_SCB_MSG_SUSPEND_RSP_EVT, 328 AVDT_SCB_MSG_CLOSE_RSP_EVT, 329 AVDT_SCB_MSG_ABORT_RSP_EVT, 330 AVDT_SCB_MSG_RECONFIG_RSP_EVT, 331 AVDT_SCB_MSG_SECURITY_RSP_EVT, 332 AVDT_SCB_MSG_SETCONFIG_REJ_EVT, 333 AVDT_SCB_MSG_OPEN_REJ_EVT, 334 AVDT_SCB_MSG_START_REJ_EVT, 335 AVDT_SCB_MSG_SUSPEND_REJ_EVT, 336 AVDT_SCB_TC_TOUT_EVT, 337 AVDT_SCB_TC_OPEN_EVT, 338 AVDT_SCB_TC_CLOSE_EVT, 339 AVDT_SCB_TC_CONG_EVT, 340 AVDT_SCB_TC_DATA_EVT, 341 AVDT_SCB_CC_CLOSE_EVT, 342 AVDT_SCB_DELAY_RPT_RSP_TOUT_EVT 343 }; 344 345 /* adaption layer number of stream routing table entries */ 346 #if AVDT_REPORTING == TRUE 347 /* 2 channels(1 media, 1 report) for each SEP and one for signalling */ 348 #define AVDT_NUM_RT_TBL ((AVDT_NUM_SEPS<<1) + 1) 349 #else 350 #define AVDT_NUM_RT_TBL (AVDT_NUM_SEPS + 1) 351 #endif 352 353 /* adaption layer number of transport channel table entries - moved to target.h 354 #define AVDT_NUM_TC_TBL (AVDT_NUM_SEPS + AVDT_NUM_LINKS) */ 355 356 /* "states" used in transport channel table */ 357 #define AVDT_AD_ST_UNUSED 0 /* Unused - unallocated */ 358 #define AVDT_AD_ST_IDLE 1 /* No connection */ 359 #define AVDT_AD_ST_ACP 2 /* Waiting to accept a connection */ 360 #define AVDT_AD_ST_INT 3 /* Initiating a connection */ 361 #define AVDT_AD_ST_CONN 4 /* Waiting for connection confirm */ 362 #define AVDT_AD_ST_CFG 5 /* Waiting for configuration complete */ 363 #define AVDT_AD_ST_OPEN 6 /* Channel opened */ 364 #define AVDT_AD_ST_SEC_INT 7 /* Security process as INT */ 365 #define AVDT_AD_ST_SEC_ACP 8 /* Security process as ACP */ 366 367 /* Configuration flags. tAVDT_TC_TBL.cfg_flags */ 368 #define AVDT_L2C_CFG_IND_DONE (1<<0) 369 #define AVDT_L2C_CFG_CFM_DONE (1<<1) 370 #define AVDT_L2C_CFG_CONN_INT (1<<2) 371 #define AVDT_L2C_CFG_CONN_ACP (1<<3) 372 373 374 /* result code for avdt_ad_write_req() (L2CA_DataWrite()) */ 375 #define AVDT_AD_FAILED L2CAP_DW_FAILED /* FALSE */ 376 #define AVDT_AD_SUCCESS L2CAP_DW_SUCCESS /* TRUE */ 377 #define AVDT_AD_CONGESTED L2CAP_DW_CONGESTED /* 2 */ 378 379 /***************************************************************************** 380 ** data types 381 *****************************************************************************/ 382 383 /* msg union of all message parameter types */ 384 typedef union { 385 tAVDT_EVT_HDR hdr; 386 tAVDT_EVT_HDR single; 387 tAVDT_SETCONFIG config_cmd; 388 tAVDT_CONFIG reconfig_cmd; 389 tAVDT_MULTI multi; 390 tAVDT_SECURITY security_cmd; 391 tAVDT_DISCOVER discover_rsp; 392 tAVDT_CONFIG svccap; 393 tAVDT_SECURITY security_rsp; 394 tAVDT_DELAY_RPT delay_rpt_cmd; 395 } tAVDT_MSG; 396 397 /* data type for AVDT_CCB_API_DISCOVER_REQ_EVT */ 398 typedef struct { 399 tAVDT_CTRL_CBACK *p_cback; 400 tAVDT_SEP_INFO *p_sep_info; 401 UINT8 num_seps; 402 } tAVDT_CCB_API_DISCOVER; 403 404 /* data type for AVDT_CCB_API_GETCAP_REQ_EVT */ 405 typedef struct { 406 tAVDT_EVT_HDR single; 407 tAVDT_CTRL_CBACK *p_cback; 408 tAVDT_CFG *p_cfg; 409 } tAVDT_CCB_API_GETCAP; 410 411 /* data type for AVDT_CCB_API_CONNECT_REQ_EVT */ 412 typedef struct { 413 tAVDT_CTRL_CBACK *p_cback; 414 UINT8 sec_mask; 415 } tAVDT_CCB_API_CONNECT; 416 417 /* data type for AVDT_CCB_API_DISCONNECT_REQ_EVT */ 418 typedef struct { 419 tAVDT_CTRL_CBACK *p_cback; 420 } tAVDT_CCB_API_DISCONNECT; 421 422 /* union associated with ccb state machine events */ 423 typedef union { 424 tAVDT_CCB_API_DISCOVER discover; 425 tAVDT_CCB_API_GETCAP getcap; 426 tAVDT_CCB_API_CONNECT connect; 427 tAVDT_CCB_API_DISCONNECT disconnect; 428 tAVDT_MSG msg; 429 BOOLEAN llcong; 430 UINT8 err_code; 431 } tAVDT_CCB_EVT; 432 433 /* channel control block type */ 434 typedef struct { 435 BD_ADDR peer_addr; /* BD address of peer */ 436 TIMER_LIST_ENT timer_entry; /* CCB timer list entry */ 437 fixed_queue_t *cmd_q; /* Queue for outgoing command messages */ 438 fixed_queue_t *rsp_q; /* Queue for outgoing response and reject messages */ 439 tAVDT_CTRL_CBACK *proc_cback; /* Procedure callback function */ 440 tAVDT_CTRL_CBACK *p_conn_cback; /* Connection/disconnection callback function */ 441 void *p_proc_data; /* Pointer to data storage for procedure */ 442 BT_HDR *p_curr_cmd; /* Current command being sent awaiting response */ 443 BT_HDR *p_curr_msg; /* Current message being sent */ 444 BT_HDR *p_rx_msg; /* Current message being received */ 445 BOOLEAN allocated; /* Whether ccb is allocated */ 446 UINT8 state; /* The CCB state machine state */ 447 BOOLEAN ll_opened; /* TRUE if LL is opened */ 448 BOOLEAN proc_busy; /* TRUE when a discover or get capabilities procedure in progress */ 449 UINT8 proc_param; /* Procedure parameter; either SEID for get capabilities or number of SEPS for discover */ 450 BOOLEAN cong; /* Whether signaling channel is congested */ 451 UINT8 label; /* Message header "label" (sequence number) */ 452 BOOLEAN reconn; /* If TRUE, reinitiate connection after transitioning from CLOSING to IDLE state */ 453 UINT8 ret_count; /* Command retransmission count */ 454 UINT8 disc_rsn; /* disconnection reason */ 455 } tAVDT_CCB; 456 457 /* type for action functions */ 458 typedef void (*tAVDT_CCB_ACTION)(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 459 460 /* type for AVDT_SCB_API_WRITE_REQ_EVT */ 461 typedef struct { 462 BT_HDR *p_buf; 463 UINT32 time_stamp; 464 #if AVDT_MULTIPLEXING == TRUE 465 fixed_queue_t *frag_q; /* Queue for outgoing media fragments. p_buf should be 0 */ 466 UINT8 *p_data; 467 UINT32 data_len; 468 #endif 469 UINT8 m_pt; 470 tAVDT_DATA_OPT_MASK opt; 471 } tAVDT_SCB_APIWRITE; 472 473 /* type for AVDT_SCB_TC_CLOSE_EVT */ 474 typedef struct { 475 UINT8 old_tc_state; /* channel state before closed */ 476 UINT8 tcid; /* TCID */ 477 UINT8 type; /* channel type */ 478 UINT8 disc_rsn; /* disconnection reason */ 479 } tAVDT_SCB_TC_CLOSE; 480 481 /* type for scb event data */ 482 typedef union { 483 tAVDT_MSG msg; 484 tAVDT_SCB_APIWRITE apiwrite; 485 tAVDT_DELAY_RPT apidelay; 486 tAVDT_OPEN open; 487 tAVDT_SCB_TC_CLOSE close; 488 BOOLEAN llcong; 489 BT_HDR *p_pkt; 490 } tAVDT_SCB_EVT; 491 492 /* stream control block type */ 493 typedef struct { 494 tAVDT_CS cs; /* stream creation struct */ 495 tAVDT_CFG curr_cfg; /* current configuration */ 496 tAVDT_CFG req_cfg; /* requested configuration */ 497 TIMER_LIST_ENT timer_entry; /* timer entry */ 498 BT_HDR *p_pkt; /* packet waiting to be sent */ 499 tAVDT_CCB *p_ccb; /* ccb associated with this scb */ 500 UINT16 media_seq; /* media packet sequence number */ 501 BOOLEAN allocated; /* whether scb is allocated or unused */ 502 BOOLEAN in_use; /* whether stream being used by peer */ 503 BOOLEAN sink_activated; /* A2DP Sink activated/de-activated from Application */ 504 UINT8 role; /* initiator/acceptor role in current procedure */ 505 BOOLEAN remove; /* whether CB is marked for removal */ 506 UINT8 state; /* state machine state */ 507 UINT8 peer_seid; /* SEID of peer stream */ 508 UINT8 curr_evt; /* current event; set only by state machine */ 509 BOOLEAN cong; /* Whether media transport channel is congested */ 510 UINT8 close_code; /* Error code received in close response */ 511 #if AVDT_MULTIPLEXING == TRUE 512 fixed_queue_t *frag_q; /* Queue for outgoing media fragments */ 513 UINT32 frag_off; /* length of already received media fragments */ 514 UINT32 frag_org_len; /* original length before fragmentation of receiving media packet */ 515 UINT8 *p_next_frag; /* next fragment to send */ 516 UINT8 *p_media_buf; /* buffer for media packet assigned by AVDT_SetMediaBuf */ 517 UINT32 media_buf_len; /* length of buffer for media packet assigned by AVDT_SetMediaBuf */ 518 #endif 519 } tAVDT_SCB; 520 521 /* type for action functions */ 522 typedef void (*tAVDT_SCB_ACTION)(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 523 524 /* adaption layer type for transport channel table */ 525 typedef struct { 526 UINT16 peer_mtu; /* L2CAP mtu of the peer device */ 527 UINT16 my_mtu; /* Our MTU for this channel */ 528 UINT16 my_flush_to; /* Our flush timeout for this channel */ 529 UINT16 lcid; 530 UINT8 tcid; /* transport channel id */ 531 UINT8 ccb_idx; /* channel control block associated with this tc */ 532 UINT8 state; /* transport channel state */ 533 UINT8 cfg_flags; /* L2CAP configuration flags */ 534 UINT8 id; 535 } tAVDT_TC_TBL; 536 537 /* adaption layer type for stream routing table */ 538 typedef struct { 539 UINT16 lcid; /* L2CAP LCID of the associated transport channel */ 540 UINT8 scb_hdl; /* stream control block associated with this tc */ 541 } tAVDT_RT_TBL; 542 543 544 /* adaption layer control block */ 545 typedef struct { 546 tAVDT_RT_TBL rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL]; 547 tAVDT_TC_TBL tc_tbl[AVDT_NUM_TC_TBL]; 548 UINT8 lcid_tbl[MAX_L2CAP_CHANNELS]; /* map LCID to tc_tbl index */ 549 } tAVDT_AD; 550 551 /* Control block for AVDT */ 552 typedef struct { 553 tAVDT_REG rcb; /* registration control block */ 554 tAVDT_CCB ccb[AVDT_NUM_LINKS]; /* channel control blocks */ 555 tAVDT_SCB scb[AVDT_NUM_SEPS]; /* stream control blocks */ 556 tAVDT_AD ad; /* adaption layer control block */ 557 tAVDTC_CTRL_CBACK *p_conf_cback; /* conformance callback function */ 558 tAVDT_CCB_ACTION *p_ccb_act; /* pointer to CCB action functions */ 559 tAVDT_SCB_ACTION *p_scb_act; /* pointer to SCB action functions */ 560 tAVDT_CTRL_CBACK *p_conn_cback; /* connection callback function */ 561 UINT8 trace_level; /* trace level */ 562 UINT16 delay_value; /* delay reporting value */ 563 } tAVDT_CB; 564 565 566 /***************************************************************************** 567 ** function declarations 568 *****************************************************************************/ 569 570 /* CCB function declarations */ 571 extern void avdt_ccb_init(void); 572 extern void avdt_ccb_event(tAVDT_CCB *p_ccb, UINT8 event, tAVDT_CCB_EVT *p_data); 573 extern tAVDT_CCB *avdt_ccb_by_bd(BD_ADDR bd_addr); 574 extern tAVDT_CCB *avdt_ccb_alloc(BD_ADDR bd_addr); 575 extern void avdt_ccb_dealloc(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 576 extern UINT8 avdt_ccb_to_idx(tAVDT_CCB *p_ccb); 577 extern tAVDT_CCB *avdt_ccb_by_idx(UINT8 idx); 578 579 /* CCB action functions */ 580 extern void avdt_ccb_chan_open(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 581 extern void avdt_ccb_chan_close(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 582 extern void avdt_ccb_chk_close(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 583 extern void avdt_ccb_hdl_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 584 extern void avdt_ccb_hdl_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 585 extern void avdt_ccb_hdl_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 586 extern void avdt_ccb_hdl_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 587 extern void avdt_ccb_hdl_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 588 extern void avdt_ccb_hdl_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 589 extern void avdt_ccb_hdl_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 590 extern void avdt_ccb_hdl_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 591 extern void avdt_ccb_snd_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 592 extern void avdt_ccb_snd_discover_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 593 extern void avdt_ccb_snd_getcap_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 594 extern void avdt_ccb_snd_getcap_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 595 extern void avdt_ccb_snd_start_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 596 extern void avdt_ccb_snd_start_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 597 extern void avdt_ccb_snd_suspend_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 598 extern void avdt_ccb_snd_suspend_rsp(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 599 extern void avdt_ccb_clear_cmds(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 600 extern void avdt_ccb_cmd_fail(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 601 extern void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 602 extern void avdt_ccb_cong_state(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 603 extern void avdt_ccb_ret_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 604 extern void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 605 extern void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 606 extern void avdt_ccb_set_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 607 extern void avdt_ccb_clr_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 608 extern void avdt_ccb_chk_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 609 extern void avdt_ccb_chk_timer(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 610 extern void avdt_ccb_set_conn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 611 extern void avdt_ccb_set_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 612 extern void avdt_ccb_do_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 613 extern void avdt_ccb_ll_closed(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 614 extern void avdt_ccb_ll_opened(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data); 615 616 /* SCB function prototypes */ 617 extern void avdt_scb_event(tAVDT_SCB *p_scb, UINT8 event, tAVDT_SCB_EVT *p_data); 618 extern void avdt_scb_init(void); 619 extern tAVDT_SCB *avdt_scb_alloc(tAVDT_CS *p_cs); 620 extern void avdt_scb_dealloc(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 621 extern UINT8 avdt_scb_to_hdl(tAVDT_SCB *p_scb); 622 extern tAVDT_SCB *avdt_scb_by_hdl(UINT8 hdl); 623 extern UINT8 avdt_scb_verify(tAVDT_CCB *p_ccb, UINT8 state, UINT8 *p_seid, UINT16 num_seid, UINT8 *p_err_code); 624 extern void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi); 625 extern UINT32 avdt_scb_gen_ssrc(tAVDT_SCB *p_scb); 626 627 /* SCB action functions */ 628 extern void avdt_scb_hdl_abort_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 629 extern void avdt_scb_hdl_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 630 extern void avdt_scb_hdl_close_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 631 extern void avdt_scb_hdl_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 632 extern void avdt_scb_hdl_getconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 633 extern void avdt_scb_hdl_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 634 extern void avdt_scb_hdl_open_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 635 extern void avdt_scb_hdl_open_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 636 extern void avdt_scb_hdl_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 637 extern void avdt_scb_hdl_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 638 extern void avdt_scb_drop_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 639 extern void avdt_scb_hdl_reconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 640 extern void avdt_scb_hdl_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 641 extern void avdt_scb_hdl_security_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 642 extern void avdt_scb_hdl_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 643 extern void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 644 extern void avdt_scb_hdl_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 645 extern void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 646 extern void avdt_scb_hdl_start_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 647 extern void avdt_scb_hdl_start_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 648 extern void avdt_scb_hdl_suspend_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 649 extern void avdt_scb_hdl_suspend_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 650 extern void avdt_scb_snd_delay_rpt_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 651 extern void avdt_scb_hdl_delay_rpt_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 652 extern void avdt_scb_hdl_delay_rpt_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 653 extern void avdt_scb_hdl_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 654 extern void avdt_scb_hdl_tc_open(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 655 extern void avdt_scb_hdl_tc_close_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 656 extern void avdt_scb_hdl_tc_open_sto(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 657 extern void avdt_scb_hdl_write_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 658 extern void avdt_scb_snd_abort_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 659 extern void avdt_scb_snd_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 660 extern void avdt_scb_snd_close_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 661 extern void avdt_scb_snd_stream_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 662 extern void avdt_scb_snd_close_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 663 extern void avdt_scb_snd_getconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 664 extern void avdt_scb_snd_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 665 extern void avdt_scb_snd_open_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 666 extern void avdt_scb_snd_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 667 extern void avdt_scb_snd_reconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 668 extern void avdt_scb_snd_reconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 669 extern void avdt_scb_snd_security_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 670 extern void avdt_scb_snd_security_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 671 extern void avdt_scb_snd_setconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 672 extern void avdt_scb_snd_setconfig_rej(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 673 extern void avdt_scb_snd_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 674 extern void avdt_scb_snd_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 675 extern void avdt_scb_cb_err(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 676 extern void avdt_scb_cong_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 677 extern void avdt_scb_rej_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 678 extern void avdt_scb_rej_in_use(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 679 extern void avdt_scb_rej_not_in_use(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 680 extern void avdt_scb_set_remove(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 681 extern void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 682 extern void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 683 extern void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 684 extern void avdt_scb_tc_timer(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 685 extern void avdt_scb_clr_vars(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 686 extern void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data, UINT32 *p_data_len, fixed_queue_t *pq); 687 extern void avdt_scb_hdl_delay_rpt_tout(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 688 extern void avdt_scb_init_open_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 689 extern void avdt_scb_send_delay_report_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data); 690 691 /* msg function declarations */ 692 extern BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg); 693 extern void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p_params); 694 extern void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params); 695 extern void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params); 696 extern void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params); 697 extern void avdt_msg_ind(tAVDT_CCB *p_ccb, BT_HDR *p_buf); 698 699 /* adaption layer function declarations */ 700 extern void avdt_ad_init(void); 701 extern UINT8 avdt_ad_type_to_tcid(UINT8 type, tAVDT_SCB *p_scb); 702 extern tAVDT_TC_TBL *avdt_ad_tc_tbl_by_st(UINT8 type, tAVDT_CCB *p_ccb, UINT8 state); 703 extern tAVDT_TC_TBL *avdt_ad_tc_tbl_by_lcid(UINT16 lcid); 704 extern tAVDT_TC_TBL *avdt_ad_tc_tbl_alloc(tAVDT_CCB *p_ccb); 705 extern UINT8 avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL *p_tbl); 706 extern void avdt_ad_tc_close_ind(tAVDT_TC_TBL *p_tbl, UINT16 reason); 707 extern void avdt_ad_tc_open_ind(tAVDT_TC_TBL *p_tbl); 708 extern void avdt_ad_tc_cong_ind(tAVDT_TC_TBL *p_tbl, BOOLEAN is_congested); 709 extern void avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf); 710 extern tAVDT_TC_TBL *avdt_ad_tc_tbl_by_type(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb); 711 extern UINT8 avdt_ad_write_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, BT_HDR *p_buf); 712 extern void avdt_ad_open_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, UINT8 role); 713 extern void avdt_ad_close_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb); 714 715 extern void avdt_process_timeout(TIMER_LIST_ENT *p_tle); 716 717 /***************************************************************************** 718 ** macros 719 *****************************************************************************/ 720 721 /* we store the scb and the label in the layer_specific field of the 722 ** current cmd 723 */ 724 #define AVDT_BLD_LAYERSPEC(ls, msg, label) \ 725 ls = (((label) << 4) | (msg)) 726 727 #define AVDT_LAYERSPEC_LABEL(ls) ((UINT8)((ls) >> 4)) 728 729 #define AVDT_LAYERSPEC_MSG(ls) ((UINT8)((ls) & 0x000F)) 730 731 /***************************************************************************** 732 ** global data 733 *****************************************************************************/ 734 #ifdef __cplusplus 735 extern "C" 736 { 737 #endif 738 739 /****************************************************************************** 740 ** Main Control Block 741 *******************************************************************************/ 742 #if AVDT_DYNAMIC_MEMORY == FALSE 743 extern tAVDT_CB avdt_cb; 744 #else 745 extern tAVDT_CB *avdt_cb_ptr; 746 #define avdt_cb (*avdt_cb_ptr) 747 #endif 748 749 750 /* L2CAP callback registration structure */ 751 extern const tL2CAP_APPL_INFO avdt_l2c_appl; 752 753 /* reject message event lookup table */ 754 extern const UINT8 avdt_msg_rej_2_evt[]; 755 #ifdef __cplusplus 756 } 757 #endif 758 759 #endif ///AVRC_INCLUDED == TRUE 760 761 #endif /* AVDT_INT_H */ 762