1 /****************************************************************************** 2 * 3 * Copyright 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 <unordered_map> 28 29 #include "avdt_api.h" 30 #include "avdt_defs.h" 31 #include "avdtc_api.h" 32 #include "bt_common.h" 33 #include "btm_api.h" 34 #include "l2c_api.h" 35 #include "osi/include/alarm.h" 36 #include "osi/include/fixed_queue.h" 37 38 #ifndef AVDT_DEBUG 39 #define AVDT_DEBUG FALSE 40 #endif 41 42 /***************************************************************************** 43 * constants 44 ****************************************************************************/ 45 46 /* channel types */ 47 enum { 48 AVDT_CHAN_SIG, /* signaling channel */ 49 AVDT_CHAN_MEDIA, /* media channel */ 50 AVDT_CHAN_REPORT, /* reporting channel */ 51 AVDT_CHAN_NUM_TYPES 52 }; 53 54 /* protocol service capabilities of this AVDTP implementation */ 55 #define AVDT_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT) 56 #define AVDT_LEG_PSC (AVDT_PSC_TRANS | AVDT_PSC_REPORT) 57 58 /* initiator/acceptor signaling roles */ 59 #define AVDT_CLOSE_ACP 0 60 #define AVDT_CLOSE_INT 1 61 #define AVDT_OPEN_ACP 2 62 #define AVDT_OPEN_INT 3 63 64 /* states for avdt_scb_verify */ 65 #define AVDT_VERIFY_OPEN 0 66 #define AVDT_VERIFY_STREAMING 1 67 #define AVDT_VERIFY_SUSPEND 2 68 #define AVDT_VERIFY_START 3 69 70 /* to distinguish CCB events from SCB events */ 71 #define AVDT_CCB_MKR 0x80 72 73 /* offset where AVDTP signaling message content starts; 74 * use the size of a start header since it's the largest possible 75 * layout of signaling message in a buffer is: 76 * 77 * | BT_HDR | SCB handles | L2CAP + HCI header | AVDTP header | data ... | 78 * 79 * Note that we "hide" the scb handles at the top of the message buffer. 80 */ 81 #define AVDT_MSG_OFFSET (L2CAP_MIN_OFFSET + AVDT_NUM_SEPS + AVDT_LEN_TYPE_START) 82 83 /* scb transport channel connect timeout value (in milliseconds) */ 84 #define AVDT_SCB_TC_CONN_TIMEOUT_MS (10 * 1000) 85 86 /* scb transport channel disconnect timeout value (in milliseconds) */ 87 #define AVDT_SCB_TC_DISC_TIMEOUT_MS (10 * 1000) 88 89 /* maximum number of command retransmissions */ 90 #ifndef AVDT_RET_MAX 91 #define AVDT_RET_MAX 1 92 #endif 93 94 /* ccb state machine states */ 95 enum { 96 AVDT_CCB_IDLE_ST, 97 AVDT_CCB_OPENING_ST, 98 AVDT_CCB_OPEN_ST, 99 AVDT_CCB_CLOSING_ST 100 }; 101 102 /* state machine action enumeration list */ 103 enum : uint8_t { 104 AVDT_CCB_CHAN_OPEN, 105 AVDT_CCB_CHAN_CLOSE, 106 AVDT_CCB_CHK_CLOSE, 107 AVDT_CCB_HDL_DISCOVER_CMD, 108 AVDT_CCB_HDL_DISCOVER_RSP, 109 AVDT_CCB_HDL_GETCAP_CMD, 110 AVDT_CCB_HDL_GETCAP_RSP, 111 AVDT_CCB_HDL_START_CMD, 112 AVDT_CCB_HDL_START_RSP, 113 AVDT_CCB_HDL_SUSPEND_CMD, 114 AVDT_CCB_HDL_SUSPEND_RSP, 115 AVDT_CCB_SND_DISCOVER_CMD, 116 AVDT_CCB_SND_DISCOVER_RSP, 117 AVDT_CCB_SND_GETCAP_CMD, 118 AVDT_CCB_SND_GETCAP_RSP, 119 AVDT_CCB_SND_START_CMD, 120 AVDT_CCB_SND_START_RSP, 121 AVDT_CCB_SND_SUSPEND_CMD, 122 AVDT_CCB_SND_SUSPEND_RSP, 123 AVDT_CCB_CLEAR_CMDS, 124 AVDT_CCB_CMD_FAIL, 125 AVDT_CCB_FREE_CMD, 126 AVDT_CCB_CONG_STATE, 127 AVDT_CCB_RET_CMD, 128 AVDT_CCB_SND_CMD, 129 AVDT_CCB_SND_MSG, 130 AVDT_CCB_SET_RECONN, 131 AVDT_CCB_CLR_RECONN, 132 AVDT_CCB_CHK_RECONN, 133 AVDT_CCB_CHK_TIMER, 134 AVDT_CCB_SET_CONN, 135 AVDT_CCB_SET_DISCONN, 136 AVDT_CCB_DO_DISCONN, 137 AVDT_CCB_LL_CLOSED, 138 AVDT_CCB_LL_OPENED, 139 AVDT_CCB_DEALLOC, 140 AVDT_CCB_NUM_ACTIONS 141 }; 142 143 #define AVDT_CCB_IGNORE AVDT_CCB_NUM_ACTIONS 144 145 /* ccb state machine events */ 146 enum { 147 AVDT_CCB_API_DISCOVER_REQ_EVT, 148 AVDT_CCB_API_GETCAP_REQ_EVT, 149 AVDT_CCB_API_START_REQ_EVT, 150 AVDT_CCB_API_SUSPEND_REQ_EVT, 151 AVDT_CCB_API_DISCOVER_RSP_EVT, 152 AVDT_CCB_API_GETCAP_RSP_EVT, 153 AVDT_CCB_API_START_RSP_EVT, 154 AVDT_CCB_API_SUSPEND_RSP_EVT, 155 AVDT_CCB_API_CONNECT_REQ_EVT, 156 AVDT_CCB_API_DISCONNECT_REQ_EVT, 157 AVDT_CCB_MSG_DISCOVER_CMD_EVT, 158 AVDT_CCB_MSG_GETCAP_CMD_EVT, 159 AVDT_CCB_MSG_START_CMD_EVT, 160 AVDT_CCB_MSG_SUSPEND_CMD_EVT, 161 AVDT_CCB_MSG_DISCOVER_RSP_EVT, 162 AVDT_CCB_MSG_GETCAP_RSP_EVT, 163 AVDT_CCB_MSG_START_RSP_EVT, 164 AVDT_CCB_MSG_SUSPEND_RSP_EVT, 165 AVDT_CCB_RCVRSP_EVT, 166 AVDT_CCB_SENDMSG_EVT, 167 AVDT_CCB_RET_TOUT_EVT, 168 AVDT_CCB_RSP_TOUT_EVT, 169 AVDT_CCB_IDLE_TOUT_EVT, 170 AVDT_CCB_UL_OPEN_EVT, 171 AVDT_CCB_UL_CLOSE_EVT, 172 AVDT_CCB_LL_OPEN_EVT, 173 AVDT_CCB_LL_CLOSE_EVT, 174 AVDT_CCB_LL_CONG_EVT 175 }; 176 177 /* scb state machine states; these state values are private to this module so 178 * the scb state cannot be read or set by actions functions 179 */ 180 enum { 181 AVDT_SCB_IDLE_ST, 182 AVDT_SCB_CONF_ST, 183 AVDT_SCB_OPENING_ST, 184 AVDT_SCB_OPEN_ST, 185 AVDT_SCB_STREAM_ST, 186 AVDT_SCB_CLOSING_ST 187 }; 188 189 /* state machine action enumeration list */ 190 enum { 191 AVDT_SCB_HDL_ABORT_CMD, 192 AVDT_SCB_HDL_ABORT_RSP, 193 AVDT_SCB_HDL_CLOSE_CMD, 194 AVDT_SCB_HDL_CLOSE_RSP, 195 AVDT_SCB_HDL_GETCONFIG_CMD, 196 AVDT_SCB_HDL_GETCONFIG_RSP, 197 AVDT_SCB_HDL_OPEN_CMD, 198 AVDT_SCB_HDL_OPEN_REJ, 199 AVDT_SCB_HDL_OPEN_RSP, 200 AVDT_SCB_HDL_PKT, 201 AVDT_SCB_DROP_PKT, 202 AVDT_SCB_HDL_RECONFIG_CMD, 203 AVDT_SCB_HDL_RECONFIG_RSP, 204 AVDT_SCB_HDL_SECURITY_CMD, 205 AVDT_SCB_HDL_SECURITY_RSP, 206 AVDT_SCB_HDL_SETCONFIG_CMD, 207 AVDT_SCB_HDL_SETCONFIG_REJ, 208 AVDT_SCB_HDL_SETCONFIG_RSP, 209 AVDT_SCB_HDL_START_CMD, 210 AVDT_SCB_HDL_START_RSP, 211 AVDT_SCB_HDL_SUSPEND_CMD, 212 AVDT_SCB_HDL_SUSPEND_RSP, 213 AVDT_SCB_HDL_TC_CLOSE, 214 AVDT_SCB_HDL_TC_CLOSE_STO, 215 AVDT_SCB_HDL_TC_OPEN, 216 AVDT_SCB_HDL_TC_OPEN_STO, 217 AVDT_SCB_SND_DELAY_RPT_REQ, 218 AVDT_SCB_HDL_DELAY_RPT_CMD, 219 AVDT_SCB_HDL_DELAY_RPT_RSP, 220 AVDT_SCB_HDL_WRITE_REQ, 221 AVDT_SCB_SND_ABORT_REQ, 222 AVDT_SCB_SND_ABORT_RSP, 223 AVDT_SCB_SND_CLOSE_REQ, 224 AVDT_SCB_SND_STREAM_CLOSE, 225 AVDT_SCB_SND_CLOSE_RSP, 226 AVDT_SCB_SND_GETCONFIG_REQ, 227 AVDT_SCB_SND_GETCONFIG_RSP, 228 AVDT_SCB_SND_OPEN_REQ, 229 AVDT_SCB_SND_OPEN_RSP, 230 AVDT_SCB_SND_RECONFIG_REQ, 231 AVDT_SCB_SND_RECONFIG_RSP, 232 AVDT_SCB_SND_SECURITY_REQ, 233 AVDT_SCB_SND_SECURITY_RSP, 234 AVDT_SCB_SND_SETCONFIG_REQ, 235 AVDT_SCB_SND_SETCONFIG_REJ, 236 AVDT_SCB_SND_SETCONFIG_RSP, 237 AVDT_SCB_SND_SNK_DELAY_RPT_REQ, 238 AVDT_SCB_SND_TC_CLOSE, 239 AVDT_SCB_CB_ERR, 240 AVDT_SCB_CONG_STATE, 241 AVDT_SCB_REJ_STATE, 242 AVDT_SCB_REJ_IN_USE, 243 AVDT_SCB_REJ_NOT_IN_USE, 244 AVDT_SCB_SET_REMOVE, 245 AVDT_SCB_FREE_PKT, 246 AVDT_SCB_CLR_PKT, 247 AVDT_SCB_CHK_SND_PKT, 248 AVDT_SCB_TC_TIMER, 249 AVDT_SCB_CLR_VARS, 250 AVDT_SCB_DEALLOC, 251 AVDT_SCB_NUM_ACTIONS 252 }; 253 254 #define AVDT_SCB_IGNORE AVDT_SCB_NUM_ACTIONS 255 256 /* scb state machine events */ 257 enum { 258 AVDT_SCB_API_REMOVE_EVT, 259 AVDT_SCB_API_WRITE_REQ_EVT, 260 AVDT_SCB_API_GETCONFIG_REQ_EVT, 261 AVDT_SCB_API_DELAY_RPT_REQ_EVT, 262 AVDT_SCB_API_SETCONFIG_REQ_EVT, 263 AVDT_SCB_API_OPEN_REQ_EVT, 264 AVDT_SCB_API_CLOSE_REQ_EVT, 265 AVDT_SCB_API_RECONFIG_REQ_EVT, 266 AVDT_SCB_API_SECURITY_REQ_EVT, 267 AVDT_SCB_API_ABORT_REQ_EVT, 268 AVDT_SCB_API_GETCONFIG_RSP_EVT, 269 AVDT_SCB_API_SETCONFIG_RSP_EVT, 270 AVDT_SCB_API_SETCONFIG_REJ_EVT, 271 AVDT_SCB_API_OPEN_RSP_EVT, 272 AVDT_SCB_API_CLOSE_RSP_EVT, 273 AVDT_SCB_API_RECONFIG_RSP_EVT, 274 AVDT_SCB_API_SECURITY_RSP_EVT, 275 AVDT_SCB_API_ABORT_RSP_EVT, 276 AVDT_SCB_MSG_SETCONFIG_CMD_EVT, 277 AVDT_SCB_MSG_GETCONFIG_CMD_EVT, 278 AVDT_SCB_MSG_OPEN_CMD_EVT, 279 AVDT_SCB_MSG_START_CMD_EVT, 280 AVDT_SCB_MSG_SUSPEND_CMD_EVT, 281 AVDT_SCB_MSG_CLOSE_CMD_EVT, 282 AVDT_SCB_MSG_ABORT_CMD_EVT, 283 AVDT_SCB_MSG_RECONFIG_CMD_EVT, 284 AVDT_SCB_MSG_SECURITY_CMD_EVT, 285 AVDT_SCB_MSG_DELAY_RPT_CMD_EVT, 286 AVDT_SCB_MSG_DELAY_RPT_RSP_EVT, 287 AVDT_SCB_MSG_SETCONFIG_RSP_EVT, 288 AVDT_SCB_MSG_GETCONFIG_RSP_EVT, 289 AVDT_SCB_MSG_OPEN_RSP_EVT, 290 AVDT_SCB_MSG_START_RSP_EVT, 291 AVDT_SCB_MSG_SUSPEND_RSP_EVT, 292 AVDT_SCB_MSG_CLOSE_RSP_EVT, 293 AVDT_SCB_MSG_ABORT_RSP_EVT, 294 AVDT_SCB_MSG_RECONFIG_RSP_EVT, 295 AVDT_SCB_MSG_SECURITY_RSP_EVT, 296 AVDT_SCB_MSG_SETCONFIG_REJ_EVT, 297 AVDT_SCB_MSG_OPEN_REJ_EVT, 298 AVDT_SCB_MSG_START_REJ_EVT, 299 AVDT_SCB_MSG_SUSPEND_REJ_EVT, 300 AVDT_SCB_TC_TOUT_EVT, 301 AVDT_SCB_TC_OPEN_EVT, 302 AVDT_SCB_TC_CLOSE_EVT, 303 AVDT_SCB_TC_CONG_EVT, 304 AVDT_SCB_TC_DATA_EVT, 305 AVDT_SCB_CC_CLOSE_EVT 306 }; 307 308 /* adaption layer number of stream routing table entries */ 309 /* 2 channels(1 media, 1 report) for each SEP and one for signalling */ 310 #define AVDT_NUM_RT_TBL (AVDT_NUM_SEPS * AVDT_CHAN_NUM_TYPES + 1) 311 312 /* adaption layer number of transport channel table entries - moved to target.h 313 #define AVDT_NUM_TC_TBL (AVDT_NUM_SEPS + AVDT_NUM_LINKS) */ 314 315 /* "states" used in transport channel table */ 316 #define AVDT_AD_ST_UNUSED 0 /* Unused - unallocated */ 317 #define AVDT_AD_ST_IDLE 1 /* No connection */ 318 #define AVDT_AD_ST_ACP 2 /* Waiting to accept a connection */ 319 #define AVDT_AD_ST_CONN 4 /* Waiting for connection confirm */ 320 #define AVDT_AD_ST_CFG 5 /* Waiting for configuration complete */ 321 #define AVDT_AD_ST_OPEN 6 /* Channel opened */ 322 #define AVDT_AD_ST_SEC_INT 7 /* Security process as INT */ 323 #define AVDT_AD_ST_SEC_ACP 8 /* Security process as ACP */ 324 325 /* Configuration flags. AvdtpTransportChannel.cfg_flags */ 326 #define AVDT_L2C_CFG_CONN_INT (1 << 2) 327 #define AVDT_L2C_CFG_CONN_ACP (1 << 3) 328 329 /***************************************************************************** 330 * data types 331 ****************************************************************************/ 332 333 /* msg union of all message parameter types */ 334 typedef union { 335 tAVDT_EVT_HDR hdr; 336 tAVDT_EVT_HDR single; 337 tAVDT_SETCONFIG config_cmd; 338 tAVDT_CONFIG reconfig_cmd; 339 tAVDT_MULTI multi; 340 tAVDT_SECURITY security_cmd; 341 tAVDT_DISCOVER discover_rsp; 342 tAVDT_CONFIG svccap; 343 tAVDT_SECURITY security_rsp; 344 tAVDT_DELAY_RPT delay_rpt_cmd; 345 } tAVDT_MSG; 346 347 /* data type for AVDT_CCB_API_DISCOVER_REQ_EVT */ 348 typedef struct { 349 tAVDT_CTRL_CBACK* p_cback; 350 tAVDT_SEP_INFO* p_sep_info; 351 uint8_t num_seps; 352 } tAVDT_CCB_API_DISCOVER; 353 354 /* data type for AVDT_CCB_API_GETCAP_REQ_EVT */ 355 typedef struct { 356 tAVDT_EVT_HDR single; 357 tAVDT_CTRL_CBACK* p_cback; 358 AvdtpSepConfig* p_cfg; 359 } tAVDT_CCB_API_GETCAP; 360 361 /* data type for AVDT_CCB_API_CONNECT_REQ_EVT */ 362 typedef struct { 363 tAVDT_CTRL_CBACK* p_cback; 364 } tAVDT_CCB_API_CONNECT; 365 366 /* data type for AVDT_CCB_API_DISCONNECT_REQ_EVT */ 367 typedef struct { tAVDT_CTRL_CBACK* p_cback; } tAVDT_CCB_API_DISCONNECT; 368 369 /* union associated with ccb state machine events */ 370 typedef union { 371 tAVDT_CCB_API_DISCOVER discover; 372 tAVDT_CCB_API_GETCAP getcap; 373 tAVDT_CCB_API_CONNECT connect; 374 tAVDT_CCB_API_DISCONNECT disconnect; 375 tAVDT_MSG msg; 376 bool llcong; 377 uint8_t err_code; 378 } tAVDT_CCB_EVT; 379 380 /* type for AVDT_SCB_API_WRITE_REQ_EVT */ 381 typedef struct { 382 BT_HDR* p_buf; 383 uint32_t time_stamp; 384 uint8_t m_pt; 385 tAVDT_DATA_OPT_MASK opt; 386 } tAVDT_SCB_APIWRITE; 387 388 /* type for AVDT_SCB_TC_CLOSE_EVT */ 389 typedef struct { 390 uint8_t old_tc_state; /* channel state before closed */ 391 uint8_t tcid; /* TCID */ 392 uint8_t type; /* channel type */ 393 } tAVDT_SCB_TC_CLOSE; 394 395 /* type for scb event data */ 396 typedef union { 397 tAVDT_MSG msg; 398 tAVDT_SCB_APIWRITE apiwrite; 399 tAVDT_DELAY_RPT apidelay; 400 tAVDT_OPEN open; 401 tAVDT_SCB_TC_CLOSE close; 402 bool llcong; 403 BT_HDR* p_pkt; 404 } tAVDT_SCB_EVT; 405 406 class AvdtpCcb; 407 408 /** 409 * AVDTP Stream Control Block. 410 */ 411 class AvdtpScb { 412 public: AvdtpScb()413 AvdtpScb() 414 : transport_channel_timer(nullptr), 415 p_pkt(nullptr), 416 p_ccb(nullptr), 417 media_seq(0), 418 allocated(false), 419 in_use(false), 420 role(0), 421 remove(false), 422 state(0), 423 peer_seid(0), 424 curr_evt(0), 425 cong(false), 426 close_code(0), 427 scb_handle_(0) {} 428 429 /** 430 * Allocate the entry for usage. 431 * Previous state will be reset and initialized. 432 * 433 * @param p_avdtp_ccb the AvdtCcb entry to use 434 * @param avdtp_stream_config the stream config to use 435 */ 436 void Allocate(AvdtpCcb* p_avdtp_ccb, 437 const AvdtpStreamConfig& avdtp_stream_config); 438 439 /** 440 * Recycle the entry by resetting it, mark it as allocated and keeping 441 * the following state: 442 * - stream_config 443 * - p_ccb 444 */ Recycle()445 void Recycle() { 446 AvdtpStreamConfig stream_config_saved = stream_config; 447 AvdtpCcb* p_ccb_saved = p_ccb; 448 Allocate(p_ccb_saved, stream_config_saved); 449 } 450 451 /** 452 * Reset all the state. 453 * 454 * @param scb_handle the AVDTP SCB handle to use 455 */ Reset(uint8_t scb_handle)456 void Reset(uint8_t scb_handle) { 457 stream_config.Reset(); 458 curr_cfg.Reset(); 459 req_cfg.Reset(); 460 461 alarm_free(transport_channel_timer); 462 transport_channel_timer = nullptr; 463 464 p_pkt = nullptr; 465 p_ccb = nullptr; 466 media_seq = 0; 467 allocated = false; 468 in_use = false; 469 role = 0; 470 remove = false; 471 state = 0; 472 peer_seid = 0; 473 curr_evt = 0; 474 cong = false; 475 close_code = 0; 476 scb_handle_ = scb_handle; 477 } 478 479 /** 480 * Get the AVDTP SCB handle for this entry. 481 */ ScbHandle()482 uint8_t ScbHandle() const { return scb_handle_; } 483 484 AvdtpStreamConfig stream_config; // Stream configuration 485 AvdtpSepConfig curr_cfg; // Current configuration 486 AvdtpSepConfig req_cfg; // Requested configuration 487 alarm_t* transport_channel_timer; // Transport channel connect timer 488 BT_HDR* p_pkt; // Packet waiting to be sent 489 AvdtpCcb* p_ccb; // CCB associated with this SCB 490 uint16_t media_seq; // Media packet sequence number 491 bool allocated; // True if the SCB is allocated 492 bool in_use; // True if used by peer 493 uint8_t role; // Initiator/acceptor role in current procedure 494 bool remove; // True if the SCB is marked for removal 495 uint8_t state; // State machine state 496 uint8_t peer_seid; // SEID of peer stream 497 uint8_t curr_evt; // current event; set only by the state machine 498 bool cong; // True if the media transport channel is congested 499 uint8_t close_code; // Error code received in close response 500 bool curr_stream; // True if the SCB is the current stream, False otherwise 501 502 private: 503 uint8_t scb_handle_; // Unique handle for this AvdtpScb entry 504 }; 505 506 /** 507 * AVDTP Channel Control Block. 508 */ 509 class AvdtpCcb { 510 public: AvdtpCcb()511 AvdtpCcb() 512 : peer_addr(RawAddress::kEmpty), 513 scb{}, 514 idle_ccb_timer(nullptr), 515 ret_ccb_timer(nullptr), 516 rsp_ccb_timer(nullptr), 517 cmd_q(nullptr), 518 rsp_q(nullptr), 519 proc_cback(nullptr), 520 p_conn_cback(nullptr), 521 p_proc_data(nullptr), 522 p_curr_cmd(nullptr), 523 p_curr_msg(nullptr), 524 p_rx_msg(nullptr), 525 allocated(false), 526 state(0), 527 ll_opened(false), 528 proc_busy(false), 529 proc_param(0), 530 cong(false), 531 label(0), 532 reconn(false), 533 ret_count(0), 534 bta_av_scb_index_(0) {} 535 536 /** 537 * Allocate the entry for usage. 538 * 539 * NOTE: The corresponding AvdtpScb entries are allocated independently. 540 * @param peer_address the peer address 541 */ 542 void Allocate(const RawAddress& peer_address); 543 544 /** 545 * Reset all the state. 546 * 547 * @param bta_av_scb_index the BTA AV SCB index to use 548 */ Reset(uint8_t bta_av_scb_index)549 void Reset(uint8_t bta_av_scb_index) { 550 bta_av_scb_index_ = bta_av_scb_index; 551 ResetCcb(); 552 for (size_t i = 0; i < AVDT_NUM_SEPS; i++) { 553 scb[i].Reset(0); 554 } 555 } 556 557 /** 558 * Reset only the Channel Control Block state without the Stream 559 * Control Block entries. The bta_av_scb_index_ is also preserved. 560 */ ResetCcb()561 void ResetCcb() { 562 peer_addr = RawAddress::kEmpty; 563 564 alarm_free(idle_ccb_timer); 565 idle_ccb_timer = nullptr; 566 567 alarm_free(ret_ccb_timer); 568 ret_ccb_timer = nullptr; 569 570 alarm_free(rsp_ccb_timer); 571 rsp_ccb_timer = nullptr; 572 573 fixed_queue_free(cmd_q, nullptr); 574 cmd_q = nullptr; 575 576 fixed_queue_free(rsp_q, nullptr); 577 rsp_q = nullptr; 578 579 proc_cback = nullptr; 580 p_conn_cback = nullptr; 581 p_proc_data = nullptr; 582 p_curr_cmd = nullptr; 583 p_curr_msg = nullptr; 584 p_rx_msg = nullptr; 585 allocated = false; 586 state = 0; 587 ll_opened = false; 588 proc_busy = false; 589 proc_param = 0; 590 cong = false; 591 label = 0; 592 reconn = false; 593 ret_count = 0; 594 } 595 596 /** 597 * Get the corresponding BTA AV stream control block index for this entry. 598 */ BtaAvScbIndex()599 uint8_t BtaAvScbIndex() const { return bta_av_scb_index_; } 600 601 RawAddress peer_addr; // Bluetooth address of peer 602 AvdtpScb scb[AVDT_NUM_SEPS]; // The AVDTP stream control blocks 603 604 /* 605 * NOTE: idle_ccb_timer, ret_ccb_timer and rsp_ccb_timer are mutually 606 * exclusive - no more than one timer should be running at the same time. 607 */ 608 alarm_t* idle_ccb_timer; // Idle CCB timer entry 609 alarm_t* ret_ccb_timer; // Ret CCB timer entry 610 alarm_t* rsp_ccb_timer; // Rsp CCB timer entry 611 fixed_queue_t* cmd_q; // Queue for outgoing command messages 612 fixed_queue_t* rsp_q; // Queue for outgoing response and reject messages 613 tAVDT_CTRL_CBACK* proc_cback; // Procedure callback function 614 tAVDT_CTRL_CBACK* p_conn_cback; // Connection/disconnection callback function 615 void* p_proc_data; // Pointer to data storage for procedure 616 BT_HDR* p_curr_cmd; // Current command being sent awaiting response 617 BT_HDR* p_curr_msg; // Current message being sent 618 BT_HDR* p_rx_msg; // Current message being received 619 bool allocated; // Whether ccb is allocated 620 uint8_t state; // The CCB state machine state 621 bool ll_opened; // True if LL is opened 622 bool proc_busy; // True when a discover or get capabilities procedure in 623 // progress 624 uint8_t proc_param; // Procedure parameter; either SEID for get capabilities 625 // or number of SEPS for discover 626 bool cong; // True if the signaling channel is congested 627 uint8_t label; // Message header "label" (sequence number) 628 bool reconn; // If true, reinitiate connection after transitioning from 629 // CLOSING to IDLE state 630 uint8_t ret_count; // Command retransmission count 631 632 private: 633 // The corresponding BTA AV stream control block index for this entry 634 uint8_t bta_av_scb_index_; 635 }; 636 637 /** 638 * AVDTP transport channel entry. 639 * Used in the transport channel table in the adaptation layer. 640 */ 641 class AvdtpTransportChannel { 642 public: AvdtpTransportChannel()643 AvdtpTransportChannel() 644 : peer_mtu(0), 645 my_mtu(0), 646 lcid(0), 647 tcid(0), 648 ccb_idx(0), 649 state(0), 650 cfg_flags(0) {} 651 Reset()652 void Reset() { 653 peer_mtu = 0; 654 my_mtu = 0; 655 lcid = 0; 656 tcid = 0; 657 ccb_idx = 0; 658 state = 0; 659 cfg_flags = 0; 660 } 661 662 uint16_t peer_mtu; // L2CAP MTU of the peer device 663 uint16_t my_mtu; // Our MTU for this channel 664 uint16_t lcid; 665 uint8_t tcid; // Transport channel ID 666 uint8_t ccb_idx; // Channel control block for with this transport channel 667 uint8_t state; // Transport channel state 668 uint8_t cfg_flags; // L2CAP configuration flags 669 }; 670 671 /** 672 * AVDTP stream routing entry. 673 * Used in the routing table in the adaption layer. 674 */ 675 class AvdtpRoutingEntry { 676 public: AvdtpRoutingEntry()677 AvdtpRoutingEntry() : lcid(0), scb_hdl(0) {} 678 Reset()679 void Reset() { 680 lcid = 0; 681 scb_hdl = 0; 682 } 683 684 uint16_t lcid; // L2CAP LCID of the associated transport channel 685 uint8_t scb_hdl; // Stream control block for this transport channel 686 }; 687 688 /** 689 * AVDTP adaption layer control block. 690 */ 691 class AvdtpAdaptationLayer { 692 public: AvdtpAdaptationLayer()693 AvdtpAdaptationLayer() {} 694 Reset()695 void Reset() { 696 for (size_t i = 0; i < AVDT_NUM_LINKS; i++) { 697 for (size_t j = 0; j < AVDT_NUM_RT_TBL; j++) { 698 rt_tbl[i][j].Reset(); 699 } 700 } 701 for (size_t i = 0; i < AVDT_NUM_TC_TBL; i++) { 702 tc_tbl[i].Reset(); 703 } 704 lcid_tbl.clear(); 705 } 706 707 /** 708 * Lookup AvdtpScb entry for a transport channel. 709 * 710 * @param tc the transport channel 711 * @return the corresponding AvdtpScb entry or null of the transport 712 * channel is invalid. 713 */ 714 AvdtpScb* LookupAvdtpScb(const AvdtpTransportChannel& tc); 715 716 AvdtpRoutingEntry rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL]; 717 AvdtpTransportChannel tc_tbl[AVDT_NUM_TC_TBL]; 718 719 std::unordered_map<uint16_t, uint8_t> lcid_tbl; // Map LCID to tc_tbl index 720 }; 721 722 /** 723 * Types for action functions. 724 */ 725 typedef void (*tAVDT_CCB_ACTION)(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 726 typedef void (*tAVDT_SCB_ACTION)(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 727 728 /** 729 * Control block for AVDTP. 730 */ 731 class AvdtpCb { 732 public: AvdtpCb()733 AvdtpCb() 734 : p_conf_cback(nullptr), 735 p_ccb_act(nullptr), 736 p_scb_act(nullptr), 737 p_conn_cback(nullptr), 738 trace_level_(0) {} 739 Reset()740 void Reset() { 741 rcb.Reset(); 742 for (size_t i = 0; i < AVDT_NUM_LINKS; i++) { 743 ccb[i].Reset(i); 744 } 745 ad.Reset(); 746 p_conf_cback = nullptr; 747 p_ccb_act = nullptr; 748 p_scb_act = nullptr; 749 p_conn_cback = nullptr; 750 trace_level_ = 0; 751 } 752 753 AvdtpRcb rcb; // Registration control block 754 AvdtpCcb ccb[AVDT_NUM_LINKS]; // Channel control blocks 755 AvdtpAdaptationLayer ad; // Adaption layer control block 756 tAVDTC_CTRL_CBACK* p_conf_cback; // Conformance callback function 757 const tAVDT_CCB_ACTION* p_ccb_act; // Pointer to CCB action functions 758 const tAVDT_SCB_ACTION* p_scb_act; // Pointer to SCB action functions 759 tAVDT_CTRL_CBACK* p_conn_cback; // Connection callback function 760 761 /** 762 * Compute the SCB handle for a given AvdtpScb entry. 763 * 764 * @param p_scb the entry to use 765 * @return the computed SCB handle or 0 if the entry is invalid. 766 */ ComputeScbHandle(const AvdtpScb * p_scb)767 uint8_t ComputeScbHandle(const AvdtpScb* p_scb) const { 768 uint8_t scb_handle = 0; 769 770 // Find the entry and in the process compute the unique index 771 // TODO: This mechanism is sub-efficient and should be refactored. 772 for (size_t i = 0; i < AVDT_NUM_LINKS; i++) { 773 for (size_t j = 0; j < AVDT_NUM_SEPS; j++) { 774 scb_handle++; 775 if (&ccb[i].scb[j] == p_scb) { 776 return scb_handle; 777 } 778 } 779 } 780 return 0; // Not found 781 } 782 783 /** 784 * Get the current trace level used for logging. 785 * 786 * @return the current trace level 787 */ TraceLevel()788 uint8_t TraceLevel() const { return trace_level_; } 789 790 /** 791 * Set the current trace level used for logging. 792 * 793 * @param trace_level the trace level to set. Should be in the range [1, 6]. 794 */ SetTraceLevel(uint8_t trace_level)795 void SetTraceLevel(uint8_t trace_level) { trace_level_ = trace_level; } 796 797 private: 798 uint8_t trace_level_; /* trace level */ 799 }; 800 801 /***************************************************************************** 802 * function declarations 803 ****************************************************************************/ 804 805 /* CCB function declarations */ 806 extern void avdt_ccb_init(void); 807 extern void avdt_ccb_event(AvdtpCcb* p_ccb, uint8_t event, 808 tAVDT_CCB_EVT* p_data); 809 extern AvdtpCcb* avdt_ccb_by_bd(const RawAddress& bd_addr); 810 extern AvdtpCcb* avdt_ccb_alloc(const RawAddress& bd_addr); 811 extern AvdtpCcb* avdt_ccb_alloc_by_channel_index(const RawAddress& bd_addr, 812 uint8_t channel_index); 813 extern void avdt_ccb_dealloc(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 814 extern uint8_t avdt_ccb_to_idx(AvdtpCcb* p_ccb); 815 extern AvdtpCcb* avdt_ccb_by_idx(uint8_t idx); 816 817 /* CCB action functions */ 818 extern void avdt_ccb_chan_open(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 819 extern void avdt_ccb_chan_close(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 820 extern void avdt_ccb_chk_close(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 821 extern void avdt_ccb_hdl_discover_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 822 extern void avdt_ccb_hdl_discover_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 823 extern void avdt_ccb_hdl_getcap_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 824 extern void avdt_ccb_hdl_getcap_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 825 extern void avdt_ccb_hdl_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 826 extern void avdt_ccb_hdl_start_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 827 extern void avdt_ccb_hdl_suspend_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 828 extern void avdt_ccb_hdl_suspend_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 829 extern void avdt_ccb_snd_discover_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 830 extern void avdt_ccb_snd_discover_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 831 extern void avdt_ccb_snd_getcap_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 832 extern void avdt_ccb_snd_getcap_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 833 extern void avdt_ccb_snd_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 834 extern void avdt_ccb_snd_start_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 835 extern void avdt_ccb_snd_suspend_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 836 extern void avdt_ccb_snd_suspend_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 837 extern void avdt_ccb_clear_cmds(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 838 extern void avdt_ccb_cmd_fail(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 839 extern void avdt_ccb_free_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 840 extern void avdt_ccb_cong_state(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 841 extern void avdt_ccb_ret_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 842 extern void avdt_ccb_snd_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 843 extern void avdt_ccb_snd_msg(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 844 extern void avdt_ccb_set_reconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 845 extern void avdt_ccb_clr_reconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 846 extern void avdt_ccb_chk_reconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 847 extern void avdt_ccb_chk_timer(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 848 extern void avdt_ccb_set_conn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 849 extern void avdt_ccb_set_disconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 850 extern void avdt_ccb_do_disconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 851 extern void avdt_ccb_ll_closed(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 852 extern void avdt_ccb_ll_opened(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data); 853 854 /* SCB function prototypes */ 855 extern void avdt_scb_event(AvdtpScb* p_scb, uint8_t event, 856 tAVDT_SCB_EVT* p_data); 857 extern void avdt_scb_init(void); 858 extern AvdtpScb* avdt_scb_alloc(uint8_t peer_id, 859 const AvdtpStreamConfig& avdtp_stream_config); 860 extern void avdt_scb_dealloc(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 861 extern uint8_t avdt_scb_to_hdl(AvdtpScb* p_scb); 862 extern AvdtpScb* avdt_scb_by_hdl(uint8_t hdl); 863 extern uint8_t avdt_scb_verify(AvdtpCcb* p_ccb, uint8_t state, uint8_t* p_seid, 864 uint16_t num_seid, uint8_t* p_err_code); 865 extern void avdt_scb_peer_seid_list(tAVDT_MULTI* p_multi); 866 extern uint32_t avdt_scb_gen_ssrc(AvdtpScb* p_scb); 867 868 /* SCB action functions */ 869 extern void avdt_scb_hdl_abort_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 870 extern void avdt_scb_hdl_abort_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 871 extern void avdt_scb_hdl_close_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 872 extern void avdt_scb_hdl_close_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 873 extern void avdt_scb_hdl_getconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 874 extern void avdt_scb_hdl_getconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 875 extern void avdt_scb_hdl_open_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 876 extern void avdt_scb_hdl_open_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 877 extern void avdt_scb_hdl_open_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 878 extern void avdt_scb_hdl_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 879 extern void avdt_scb_drop_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 880 extern void avdt_scb_hdl_reconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 881 extern void avdt_scb_hdl_reconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 882 extern void avdt_scb_hdl_security_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 883 extern void avdt_scb_hdl_security_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 884 extern void avdt_scb_hdl_setconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 885 extern void avdt_scb_hdl_setconfig_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 886 extern void avdt_scb_hdl_setconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 887 extern void avdt_scb_hdl_start_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 888 extern void avdt_scb_hdl_start_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 889 extern void avdt_scb_hdl_suspend_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 890 extern void avdt_scb_hdl_suspend_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 891 extern void avdt_scb_snd_delay_rpt_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 892 extern void avdt_scb_hdl_delay_rpt_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 893 extern void avdt_scb_hdl_delay_rpt_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 894 extern void avdt_scb_hdl_tc_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 895 extern void avdt_scb_hdl_tc_open(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 896 extern void avdt_scb_hdl_tc_close_sto(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 897 extern void avdt_scb_hdl_tc_open_sto(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 898 extern void avdt_scb_hdl_write_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 899 extern void avdt_scb_snd_abort_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 900 extern void avdt_scb_snd_abort_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 901 extern void avdt_scb_snd_close_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 902 extern void avdt_scb_snd_stream_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 903 extern void avdt_scb_snd_close_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 904 extern void avdt_scb_snd_getconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 905 extern void avdt_scb_snd_getconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 906 extern void avdt_scb_snd_open_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 907 extern void avdt_scb_snd_open_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 908 extern void avdt_scb_snd_reconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 909 extern void avdt_scb_snd_reconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 910 extern void avdt_scb_snd_security_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 911 extern void avdt_scb_snd_security_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 912 extern void avdt_scb_snd_setconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 913 extern void avdt_scb_snd_setconfig_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 914 extern void avdt_scb_snd_setconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 915 extern void avdt_scb_snd_snk_delay_rpt_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 916 extern void avdt_scb_snd_tc_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 917 extern void avdt_scb_cb_err(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 918 extern void avdt_scb_cong_state(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 919 extern void avdt_scb_rej_state(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 920 extern void avdt_scb_rej_in_use(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 921 extern void avdt_scb_rej_not_in_use(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 922 extern void avdt_scb_set_remove(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 923 extern void avdt_scb_free_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 924 extern void avdt_scb_chk_snd_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 925 extern void avdt_scb_clr_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 926 extern void avdt_scb_transport_channel_timer(AvdtpScb* p_scb, 927 tAVDT_SCB_EVT* p_data); 928 extern void avdt_scb_clr_vars(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data); 929 930 /* msg function declarations */ 931 extern bool avdt_msg_send(AvdtpCcb* p_ccb, BT_HDR* p_msg); 932 extern void avdt_msg_send_cmd(AvdtpCcb* p_ccb, void* p_scb, uint8_t sig_id, 933 tAVDT_MSG* p_params); 934 extern void avdt_msg_send_rsp(AvdtpCcb* p_ccb, uint8_t sig_id, 935 tAVDT_MSG* p_params); 936 extern void avdt_msg_send_rej(AvdtpCcb* p_ccb, uint8_t sig_id, 937 tAVDT_MSG* p_params); 938 extern void avdt_msg_send_grej(AvdtpCcb* p_ccb, uint8_t sig_id, 939 tAVDT_MSG* p_params); 940 extern void avdt_msg_ind(AvdtpCcb* p_ccb, BT_HDR* p_buf); 941 942 /* adaption layer function declarations */ 943 extern void avdt_ad_init(void); 944 extern uint8_t avdt_ad_type_to_tcid(uint8_t type, AvdtpScb* p_scb); 945 extern AvdtpTransportChannel* avdt_ad_tc_tbl_by_st(uint8_t type, 946 AvdtpCcb* p_ccb, 947 uint8_t state); 948 extern AvdtpTransportChannel* avdt_ad_tc_tbl_by_lcid(uint16_t lcid); 949 extern AvdtpTransportChannel* avdt_ad_tc_tbl_alloc(AvdtpCcb* p_ccb); 950 extern uint8_t avdt_ad_tc_tbl_to_idx(AvdtpTransportChannel* p_tbl); 951 extern void avdt_ad_tc_close_ind(AvdtpTransportChannel* p_tbl); 952 extern void avdt_ad_tc_open_ind(AvdtpTransportChannel* p_tbl); 953 extern void avdt_ad_tc_cong_ind(AvdtpTransportChannel* p_tbl, 954 bool is_congested); 955 extern void avdt_ad_tc_data_ind(AvdtpTransportChannel* p_tbl, BT_HDR* p_buf); 956 extern AvdtpTransportChannel* avdt_ad_tc_tbl_by_type(uint8_t type, 957 AvdtpCcb* p_ccb, 958 AvdtpScb* p_scb); 959 extern uint8_t avdt_ad_write_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb, 960 BT_HDR* p_buf); 961 extern void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb, 962 uint8_t role); 963 extern void avdt_ad_close_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb); 964 965 extern void avdt_ccb_idle_ccb_timer_timeout(void* data); 966 extern void avdt_ccb_ret_ccb_timer_timeout(void* data); 967 extern void avdt_ccb_rsp_ccb_timer_timeout(void* data); 968 extern void avdt_scb_transport_channel_timer_timeout(void* data); 969 970 /***************************************************************************** 971 * macros 972 ****************************************************************************/ 973 974 /* we store the scb and the label in the layer_specific field of the 975 * current cmd 976 */ 977 #define AVDT_BLD_LAYERSPEC(ls, msg, label) ls = (((label) << 4) | (msg)) 978 979 #define AVDT_LAYERSPEC_LABEL(ls) ((uint8_t)((ls) >> 4)) 980 981 #define AVDT_LAYERSPEC_MSG(ls) ((uint8_t)((ls)&0x000F)) 982 983 /***************************************************************************** 984 * global data 985 ****************************************************************************/ 986 987 /****************************************************************************** 988 * Main Control Block 989 ******************************************************************************/ 990 extern AvdtpCb avdtp_cb; 991 992 /* L2CAP callback registration structure */ 993 extern const tL2CAP_APPL_INFO avdt_l2c_appl; 994 995 /* reject message event lookup table */ 996 extern const uint8_t avdt_msg_rej_2_evt[]; 997 998 void avdt_l2c_disconnect(uint16_t lcid); 999 1000 constexpr uint16_t kAvdtpMtu = 1024; 1001 1002 #endif /* AVDT_INT_H */ 1003