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