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 /* timer to monitor initial AVDT delay report as INT */
92 #define AVDT_INIT_DELAY_REPORT_TIMEOUT_MS (2 * 1000)
93
94 /* maximum number of command retransmissions */
95 #ifndef AVDT_RET_MAX
96 #define AVDT_RET_MAX 1
97 #endif
98
99 /* ccb state machine states */
100 enum { AVDT_CCB_IDLE_ST, AVDT_CCB_OPENING_ST, AVDT_CCB_OPEN_ST, AVDT_CCB_CLOSING_ST };
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 /* Adaptation 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 /* "states" used in transport channel table */
313 enum tTRANSPORT_CHANNEL_STATE : uint8_t {
314 AVDT_AD_ST_UNUSED = 0, /* Unused - unallocated */
315 AVDT_AD_ST_IDLE = 1, /* No connection */
316 AVDT_AD_ST_ACP = 2, /* Waiting to accept a connection */
317 AVDT_AD_ST_CONN = 4, /* Waiting for connection confirm */
318 AVDT_AD_ST_CFG = 5, /* Waiting for configuration complete */
319 AVDT_AD_ST_OPEN = 6, /* Channel opened */
320 };
321
tc_state_text(uint8_t state)322 inline std::string tc_state_text(uint8_t state) {
323 tTRANSPORT_CHANNEL_STATE state_ = static_cast<tTRANSPORT_CHANNEL_STATE>(state);
324 switch (state_) {
325 CASE_RETURN_TEXT(AVDT_AD_ST_UNUSED);
326 CASE_RETURN_TEXT(AVDT_AD_ST_IDLE);
327 CASE_RETURN_TEXT(AVDT_AD_ST_ACP);
328 CASE_RETURN_TEXT(AVDT_AD_ST_CONN);
329 CASE_RETURN_TEXT(AVDT_AD_ST_CFG);
330 CASE_RETURN_TEXT(AVDT_AD_ST_OPEN);
331 default:
332 RETURN_UNKNOWN_TYPE_STRING(tTRANSPORT_CHANNEL_STATE, state_);
333 }
334 }
335
tc_type_text(uint8_t type)336 inline std::string tc_type_text(uint8_t type) {
337 tTRANSPORT_CHANNEL_TYPE type_ = static_cast<tTRANSPORT_CHANNEL_TYPE>(type);
338 switch (type_) {
339 CASE_RETURN_TEXT(AVDT_CHAN_SIG);
340 CASE_RETURN_TEXT(AVDT_CHAN_MEDIA);
341 CASE_RETURN_TEXT(AVDT_CHAN_REPORT);
342 default:
343 RETURN_UNKNOWN_TYPE_STRING(tTRANSPORT_CHANNEL_TYPE, type_);
344 }
345 }
346
347 namespace std {
348 template <>
349 struct formatter<tTRANSPORT_CHANNEL_STATE> : enum_formatter<tTRANSPORT_CHANNEL_STATE> {};
350 template <>
351 struct formatter<tTRANSPORT_CHANNEL_TYPE> : enum_formatter<tTRANSPORT_CHANNEL_TYPE> {};
352 } // namespace std
353
354 /*****************************************************************************
355 * data types
356 ****************************************************************************/
357
358 /* msg union of all message parameter types */
359 typedef union {
360 tAVDT_EVT_HDR hdr;
361 tAVDT_EVT_HDR single;
362 tAVDT_SETCONFIG config_cmd;
363 tAVDT_CONFIG reconfig_cmd;
364 tAVDT_MULTI multi;
365 tAVDT_SECURITY security_cmd;
366 tAVDT_DISCOVER discover_rsp;
367 tAVDT_CONFIG svccap;
368 tAVDT_SECURITY security_rsp;
369 tAVDT_DELAY_RPT delay_rpt_cmd;
370 } tAVDT_MSG;
371
372 /* data type for AVDT_CCB_API_DISCOVER_REQ_EVT */
373 typedef struct {
374 tAVDT_CTRL_CBACK* p_cback;
375 tAVDT_SEP_INFO* p_sep_info;
376 uint8_t num_seps;
377 } tAVDT_CCB_API_DISCOVER;
378
379 /* data type for AVDT_CCB_API_GETCAP_REQ_EVT */
380 typedef struct {
381 tAVDT_EVT_HDR single;
382 tAVDT_CTRL_CBACK* p_cback;
383 AvdtpSepConfig* p_cfg;
384 } tAVDT_CCB_API_GETCAP;
385
386 /* data type for AVDT_CCB_API_CONNECT_REQ_EVT */
387 typedef struct {
388 tAVDT_CTRL_CBACK* p_cback;
389 } tAVDT_CCB_API_CONNECT;
390
391 /* data type for AVDT_CCB_API_DISCONNECT_REQ_EVT */
392 typedef struct {
393 tAVDT_CTRL_CBACK* p_cback;
394 } tAVDT_CCB_API_DISCONNECT;
395
396 /* union associated with ccb state machine events */
397 typedef union {
398 tAVDT_CCB_API_DISCOVER discover;
399 tAVDT_CCB_API_GETCAP getcap;
400 tAVDT_CCB_API_CONNECT connect;
401 tAVDT_CCB_API_DISCONNECT disconnect;
402 tAVDT_MSG msg;
403 bool llcong;
404 uint8_t err_code;
405 } tAVDT_CCB_EVT;
406
407 /* type for AVDT_SCB_API_WRITE_REQ_EVT */
408 typedef struct {
409 BT_HDR* p_buf;
410 uint32_t time_stamp;
411 uint8_t m_pt;
412 tAVDT_DATA_OPT_MASK opt;
413 } tAVDT_SCB_APIWRITE;
414
415 /* type for AVDT_SCB_TC_CLOSE_EVT */
416 typedef struct {
417 uint8_t old_tc_state; /* channel state before closed */
418 uint8_t tcid; /* TCID */
419 uint8_t type; /* channel type */
420 } tAVDT_SCB_TC_CLOSE;
421
422 /* type for scb event data */
423 typedef union {
424 tAVDT_MSG msg;
425 tAVDT_SCB_APIWRITE apiwrite;
426 tAVDT_DELAY_RPT apidelay;
427 tAVDT_OPEN open;
428 tAVDT_SCB_TC_CLOSE close;
429 bool llcong;
430 BT_HDR* p_pkt;
431 } tAVDT_SCB_EVT;
432
433 class AvdtpCcb;
434
435 /**
436 * AVDTP Stream Control Block.
437 */
438 class AvdtpScb {
439 public:
440 AvdtpScb()
441 : transport_channel_timer(nullptr),
442 init_delay_report_timer(nullptr),
443 p_pkt(nullptr),
444 p_ccb(nullptr),
445 media_seq(0),
446 allocated(false),
447 in_use(false),
448 role(0),
449 remove(false),
450 state(0),
451 peer_seid(0),
452 curr_evt(0),
453 cong(false),
454 close_code(0),
455 curr_stream(false),
456 scb_handle_(0) {}
457
458 /**
459 * Allocate the entry for usage.
460 * Previous state will be reset and initialized.
461 *
462 * @param p_avdtp_ccb the AvdtCcb entry to use
463 * @param avdtp_stream_config the stream config to use
464 */
465 void Allocate(AvdtpCcb* p_avdtp_ccb, const AvdtpStreamConfig& avdtp_stream_config);
466
467 /**
468 * Recycle the entry by resetting it, mark it as allocated and keeping
469 * the following state:
470 * - stream_config
471 * - p_ccb
472 */
473 void Recycle() {
474 AvdtpStreamConfig stream_config_saved = stream_config;
475 AvdtpCcb* p_ccb_saved = p_ccb;
476 Allocate(p_ccb_saved, stream_config_saved);
477 }
478
479 /**
480 * Reset all the state.
481 *
482 * @param scb_handle the AVDTP SCB handle to use
483 */
484 void Reset(uint8_t scb_handle) {
485 stream_config.Reset();
486 curr_cfg.Reset();
487 req_cfg.Reset();
488
489 alarm_free(transport_channel_timer);
490 transport_channel_timer = nullptr;
491
492 alarm_free(init_delay_report_timer);
493 init_delay_report_timer = nullptr;
494
495 p_pkt = nullptr;
496 p_ccb = nullptr;
497 media_seq = 0;
498 allocated = false;
499 in_use = false;
500 role = 0;
501 remove = false;
502 state = 0;
503 peer_seid = 0;
504 curr_evt = 0;
505 cong = false;
506 close_code = 0;
507 curr_stream = false;
508 scb_handle_ = scb_handle;
509 }
510
511 /**
512 * Get the AVDTP SCB handle for this entry.
513 */
514 uint8_t ScbHandle() const { return scb_handle_; }
515
516 AvdtpStreamConfig stream_config; // Stream configuration
517 AvdtpSepConfig curr_cfg; // Current configuration
518 AvdtpSepConfig req_cfg; // Requested configuration
519 alarm_t* transport_channel_timer; // Transport channel connect timer
520 alarm_t* init_delay_report_timer; // Timer to monitor initial AVDT delay report as INT
521 BT_HDR* p_pkt; // Packet waiting to be sent
522 AvdtpCcb* p_ccb; // CCB associated with this SCB
523 uint16_t media_seq; // Media packet sequence number
524 bool allocated; // True if the SCB is allocated
525 bool in_use; // True if used by peer
526 uint8_t role; // Initiator/acceptor role in current procedure
527 bool remove; // True if the SCB is marked for removal
528 uint8_t state; // State machine state
529 uint8_t peer_seid; // SEID of peer stream
530 uint8_t curr_evt; // current event; set only by the state machine
531 bool cong; // True if the media transport channel is congested
532 uint8_t close_code; // Error code received in close response
533 bool curr_stream; // True if the SCB is the current stream, False otherwise
534
535 private:
536 uint8_t scb_handle_; // Unique handle for this AvdtpScb entry
537 };
538
539 /**
540 * AVDTP Channel Control Block.
541 */
542 class AvdtpCcb {
543 public:
544 AvdtpCcb()
545 : peer_addr(RawAddress::kEmpty),
546 scb{},
547 idle_ccb_timer(nullptr),
548 ret_ccb_timer(nullptr),
549 rsp_ccb_timer(nullptr),
550 cmd_q(nullptr),
551 rsp_q(nullptr),
552 proc_cback(nullptr),
553 p_conn_cback(nullptr),
554 p_proc_data(nullptr),
555 p_curr_cmd(nullptr),
556 p_curr_msg(nullptr),
557 p_rx_msg(nullptr),
558 allocated(false),
559 state(0),
560 ll_opened(false),
561 proc_busy(false),
562 proc_param(0),
563 cong(false),
564 label(0),
565 reconn(false),
566 ret_count(0),
567 bta_av_scb_index_(0) {}
568
569 /**
570 * Allocate the entry for usage.
571 *
572 * NOTE: The corresponding AvdtpScb entries are allocated independently.
573 * @param peer_address the peer address
574 */
575 void Allocate(const RawAddress& peer_address);
576
577 /**
578 * Reset all the state.
579 *
580 * @param bta_av_scb_index the BTA AV SCB index to use
581 */
582 void Reset(uint8_t bta_av_scb_index) {
583 bta_av_scb_index_ = bta_av_scb_index;
584 ResetCcb();
585 for (size_t i = 0; i < AVDT_NUM_SEPS; i++) {
586 scb[i].Reset(0);
587 }
588 }
589
590 /**
591 * Reset only the Channel Control Block state without the Stream
592 * Control Block entries. The bta_av_scb_index_ is also preserved.
593 */
594 void ResetCcb() {
595 peer_addr = RawAddress::kEmpty;
596
597 alarm_free(idle_ccb_timer);
598 idle_ccb_timer = nullptr;
599
600 alarm_free(ret_ccb_timer);
601 ret_ccb_timer = nullptr;
602
603 alarm_free(rsp_ccb_timer);
604 rsp_ccb_timer = nullptr;
605
606 fixed_queue_free(cmd_q, nullptr);
607 cmd_q = nullptr;
608
609 fixed_queue_free(rsp_q, nullptr);
610 rsp_q = nullptr;
611
612 proc_cback = nullptr;
613 p_conn_cback = nullptr;
614 p_proc_data = nullptr;
615 p_curr_cmd = nullptr;
616 p_curr_msg = nullptr;
617 p_rx_msg = nullptr;
618 allocated = false;
619 state = 0;
620 ll_opened = false;
621 proc_busy = false;
622 proc_param = 0;
623 cong = false;
624 label = 0;
625 reconn = false;
626 ret_count = 0;
627 }
628
629 /**
630 * Get the corresponding BTA AV stream control block index for this entry.
631 */
632 uint8_t BtaAvScbIndex() const { return bta_av_scb_index_; }
633
634 RawAddress peer_addr; // Bluetooth address of peer
635 AvdtpScb scb[AVDT_NUM_SEPS]; // The AVDTP stream control blocks
636
637 /*
638 * NOTE: idle_ccb_timer, ret_ccb_timer and rsp_ccb_timer are mutually
639 * exclusive - no more than one timer should be running at the same time.
640 */
641 alarm_t* idle_ccb_timer; // Idle CCB timer entry
642 alarm_t* ret_ccb_timer; // Ret CCB timer entry
643 alarm_t* rsp_ccb_timer; // Rsp CCB timer entry
644 fixed_queue_t* cmd_q; // Queue for outgoing command messages
645 fixed_queue_t* rsp_q; // Queue for outgoing response and reject messages
646 tAVDT_CTRL_CBACK* proc_cback; // Procedure callback function
647 tAVDT_CTRL_CBACK* p_conn_cback; // Connection/disconnection callback function
648 void* p_proc_data; // Pointer to data storage for procedure
649 BT_HDR* p_curr_cmd; // Current command being sent awaiting response
650 BT_HDR* p_curr_msg; // Current message being sent
651 BT_HDR* p_rx_msg; // Current message being received
652 bool allocated; // Whether ccb is allocated
653 uint8_t state; // The CCB state machine state
654 bool ll_opened; // True if LL is opened
655 bool proc_busy; // True when a discover or get capabilities procedure in
656 // progress
657 uint8_t proc_param; // Procedure parameter; either SEID for get capabilities
658 // or number of SEPS for discover
659 bool cong; // True if the signaling channel is congested
660 uint8_t label; // Message header "label" (sequence number)
661 bool reconn; // If true, reinitiate connection after transitioning from
662 // CLOSING to IDLE state
663 uint8_t ret_count; // Command retransmission count
664
665 private:
666 // The corresponding BTA AV stream control block index for this entry
667 uint8_t bta_av_scb_index_;
668 };
669
670 /**
671 * AVDTP transport channel entry.
672 * Used in the transport channel table in the adaptation layer.
673 */
674 class AvdtpTransportChannel {
675 public:
676 AvdtpTransportChannel()
677 : peer_mtu(0),
678 my_mtu(0),
679 lcid(0),
680 tcid(0),
681 ccb_idx(0),
682 state(0),
683 role(tAVDT_ROLE::AVDT_UNKNOWN) {}
684
685 void Reset() {
686 peer_mtu = 0;
687 my_mtu = 0;
688 lcid = 0;
689 tcid = 0;
690 ccb_idx = 0;
691 state = 0;
692 role = tAVDT_ROLE::AVDT_UNKNOWN;
693 }
694
695 uint16_t peer_mtu; // L2CAP MTU of the peer device
696 uint16_t my_mtu; // Our MTU for this channel
697 uint16_t lcid;
698 uint8_t tcid; // Transport channel ID
699 uint8_t ccb_idx; // Channel control block for with this transport channel
700 uint8_t state; // Transport channel state
701 tAVDT_ROLE role; // Role for the establishment of the AVDTP signaling channel
702 };
703
704 /**
705 * AVDTP stream routing entry.
706 * Used in the routing table in the Adaptation layer.
707 */
708 class AvdtpRoutingEntry {
709 public:
710 AvdtpRoutingEntry() : lcid(0), scb_hdl(0) {}
711
712 void Reset() {
713 lcid = 0;
714 scb_hdl = 0;
715 }
716
717 uint16_t lcid; // L2CAP LCID of the associated transport channel
718 uint8_t scb_hdl; // Stream control block for this transport channel
719 };
720
721 /**
722 * AVDTP Adaptation layer control block.
723 */
724 class AvdtpAdaptationLayer {
725 public:
726 AvdtpAdaptationLayer() {}
727
728 void Reset() {
729 for (size_t i = 0; i < AVDT_NUM_LINKS; i++) {
730 for (size_t j = 0; j < AVDT_NUM_RT_TBL; j++) {
731 rt_tbl[i][j].Reset();
732 }
733 }
734 for (size_t i = 0; i < AVDT_NUM_TC_TBL; i++) {
735 tc_tbl[i].Reset();
736 }
737 lcid_tbl.clear();
738 }
739
740 /**
741 * Lookup AvdtpScb entry for a transport channel.
742 *
743 * @param tc the transport channel
744 * @return the corresponding AvdtpScb entry or null of the transport
745 * channel is invalid.
746 */
747 AvdtpScb* LookupAvdtpScb(const AvdtpTransportChannel& tc);
748
749 AvdtpRoutingEntry rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL];
750 AvdtpTransportChannel tc_tbl[AVDT_NUM_TC_TBL];
751
752 std::unordered_map<uint16_t, uint8_t> lcid_tbl; // Map LCID to tc_tbl index
753 };
754
755 /**
756 * Types for action functions.
757 */
758 typedef void (*tAVDT_CCB_ACTION)(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
759 typedef void (*tAVDT_SCB_ACTION)(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
760
761 /**
762 * Control block for AVDTP.
763 */
764 class AvdtpCb {
765 public:
766 AvdtpCb()
767 : p_conf_cback(nullptr), p_ccb_act(nullptr), p_scb_act(nullptr), p_conn_cback(nullptr) {}
768
769 void Reset() {
770 rcb.Reset();
771 for (size_t i = 0; i < AVDT_NUM_LINKS; i++) {
772 ccb[i].Reset(i);
773 }
774 ad.Reset();
775 p_conf_cback = nullptr;
776 p_ccb_act = nullptr;
777 p_scb_act = nullptr;
778 p_conn_cback = nullptr;
779 }
780
781 AvdtpRcb rcb; // Registration control block
782 AvdtpCcb ccb[AVDT_NUM_LINKS]; // Channel control blocks
783 AvdtpAdaptationLayer ad; // Adaptation layer control block
784 tAVDTC_CTRL_CBACK* p_conf_cback; // Conformance callback function
785 const tAVDT_CCB_ACTION* p_ccb_act; // Pointer to CCB action functions
786 const tAVDT_SCB_ACTION* p_scb_act; // Pointer to SCB action functions
787 tAVDT_CTRL_CBACK* p_conn_cback; // Connection callback function
788
789 /**
790 * Compute the SCB handle for a given AvdtpScb entry.
791 *
792 * @param p_scb the entry to use
793 * @return the computed SCB handle or 0 if the entry is invalid.
794 */
795 uint8_t ComputeScbHandle(const AvdtpScb* p_scb) const {
796 uint8_t scb_handle = 0;
797
798 // Find the entry and in the process compute the unique index
799 // TODO: This mechanism is sub-efficient and should be refactored.
800 for (size_t i = 0; i < AVDT_NUM_LINKS; i++) {
801 for (size_t j = 0; j < AVDT_NUM_SEPS; j++) {
802 scb_handle++;
803 if (&ccb[i].scb[j] == p_scb) {
804 return scb_handle;
805 }
806 }
807 }
808 return 0; // Not found
809 }
810 };
811
812 /*****************************************************************************
813 * function declarations
814 ****************************************************************************/
815
816 /* CCB function declarations */
817 void avdt_ccb_init(void);
818 void avdt_ccb_event(AvdtpCcb* p_ccb, uint8_t event, tAVDT_CCB_EVT* p_data);
819 AvdtpCcb* avdt_ccb_by_bd(const RawAddress& bd_addr);
820 AvdtpCcb* avdt_ccb_alloc(const RawAddress& bd_addr);
821 AvdtpCcb* avdt_ccb_alloc_by_channel_index(const RawAddress& bd_addr, uint8_t channel_index);
822 void avdt_ccb_dealloc(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
823 uint8_t avdt_ccb_to_idx(AvdtpCcb* p_ccb);
824 AvdtpCcb* avdt_ccb_by_idx(uint8_t idx);
825
826 /* CCB action functions */
827 void avdt_ccb_chan_open(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
828 void avdt_ccb_chan_close(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
829 void avdt_ccb_chk_close(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
830 void avdt_ccb_hdl_discover_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
831 void avdt_ccb_hdl_discover_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
832 void avdt_ccb_hdl_getcap_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
833 void avdt_ccb_hdl_getcap_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
834 void avdt_ccb_hdl_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
835 void avdt_ccb_hdl_start_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
836 void avdt_ccb_hdl_suspend_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
837 void avdt_ccb_hdl_suspend_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
838 void avdt_ccb_snd_discover_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
839 void avdt_ccb_snd_discover_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
840 void avdt_ccb_snd_getcap_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
841 void avdt_ccb_snd_getcap_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
842 void avdt_ccb_snd_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
843 void avdt_ccb_snd_start_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
844 void avdt_ccb_snd_suspend_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
845 void avdt_ccb_snd_suspend_rsp(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
846 void avdt_ccb_clear_cmds(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
847 void avdt_ccb_cmd_fail(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
848 void avdt_ccb_free_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
849 void avdt_ccb_cong_state(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
850 void avdt_ccb_ret_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
851 void avdt_ccb_snd_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
852 void avdt_ccb_snd_msg(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
853 void avdt_ccb_set_reconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
854 void avdt_ccb_clr_reconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
855 void avdt_ccb_chk_reconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
856 void avdt_ccb_chk_timer(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
857 void avdt_ccb_set_conn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
858 void avdt_ccb_set_disconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
859 void avdt_ccb_do_disconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
860 void avdt_ccb_ll_closed(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
861 void avdt_ccb_ll_opened(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data);
862
863 /* SCB function prototypes */
864 void avdt_scb_event(AvdtpScb* p_scb, uint8_t event, tAVDT_SCB_EVT* p_data);
865 void avdt_scb_init(void);
866 AvdtpScb* avdt_scb_alloc(uint8_t peer_id, const AvdtpStreamConfig& avdtp_stream_config);
867 void avdt_scb_dealloc(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
868 uint8_t avdt_scb_to_hdl(AvdtpScb* p_scb);
869 AvdtpScb* avdt_scb_by_hdl(uint8_t hdl);
870 uint8_t avdt_scb_verify(AvdtpCcb* p_ccb, uint8_t state, uint8_t* p_seid, uint16_t num_seid,
871 uint8_t* p_err_code);
872 void avdt_scb_peer_seid_list(tAVDT_MULTI* p_multi);
873 uint32_t avdt_scb_gen_ssrc(AvdtpScb* p_scb);
874
875 /* SCB action functions */
876 void avdt_scb_hdl_abort_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
877 void avdt_scb_hdl_abort_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
878 void avdt_scb_hdl_close_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
879 void avdt_scb_hdl_close_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
880 void avdt_scb_hdl_getconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
881 void avdt_scb_hdl_getconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
882 void avdt_scb_hdl_open_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
883 void avdt_scb_hdl_open_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
884 void avdt_scb_hdl_open_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
885 void avdt_scb_hdl_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
886 void avdt_scb_hdl_pkt_no_frag(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
887 void avdt_scb_drop_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
888 void avdt_scb_hdl_reconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
889 void avdt_scb_hdl_reconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
890 void avdt_scb_hdl_security_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
891 void avdt_scb_hdl_security_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
892 void avdt_scb_hdl_setconfig_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
893 void avdt_scb_hdl_setconfig_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
894 void avdt_scb_hdl_setconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
895 void avdt_scb_hdl_start_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
896 void avdt_scb_hdl_start_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
897 void avdt_scb_hdl_suspend_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
898 void avdt_scb_hdl_suspend_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
899 void avdt_scb_snd_delay_rpt_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
900 void avdt_scb_hdl_delay_rpt_cmd(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
901 void avdt_scb_hdl_delay_rpt_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
902 void avdt_scb_hdl_tc_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
903 void avdt_scb_hdl_tc_open(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
904 void avdt_scb_hdl_tc_close_sto(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
905 void avdt_scb_hdl_tc_open_sto(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
906 void avdt_scb_hdl_write_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
907 void avdt_scb_snd_abort_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
908 void avdt_scb_snd_abort_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
909 void avdt_scb_snd_close_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
910 void avdt_scb_snd_stream_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
911 void avdt_scb_snd_close_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
912 void avdt_scb_snd_getconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
913 void avdt_scb_snd_getconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
914 void avdt_scb_snd_open_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
915 void avdt_scb_snd_open_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
916 void avdt_scb_snd_reconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
917 void avdt_scb_snd_reconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
918 void avdt_scb_snd_security_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
919 void avdt_scb_snd_security_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
920 void avdt_scb_snd_setconfig_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
921 void avdt_scb_snd_setconfig_rej(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
922 void avdt_scb_snd_setconfig_rsp(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
923 void avdt_scb_snd_snk_delay_rpt_req(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
924 void avdt_scb_snd_tc_close(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
925 void avdt_scb_cb_err(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
926 void avdt_scb_cong_state(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
927 void avdt_scb_rej_state(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
928 void avdt_scb_rej_in_use(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
929 void avdt_scb_rej_not_in_use(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
930 void avdt_scb_set_remove(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
931 void avdt_scb_free_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
932 void avdt_scb_chk_snd_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
933 void avdt_scb_clr_pkt(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
934 void avdt_scb_transport_channel_timer(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
935 void avdt_scb_clr_vars(AvdtpScb* p_scb, tAVDT_SCB_EVT* p_data);
936
937 /* msg function declarations */
938 bool avdt_msg_send(AvdtpCcb* p_ccb, BT_HDR* p_msg);
939 void avdt_msg_send_cmd(AvdtpCcb* p_ccb, void* p_scb, uint8_t sig_id, tAVDT_MSG* p_params);
940 void avdt_msg_send_rsp(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params);
941 void avdt_msg_send_rej(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params);
942 void avdt_msg_send_grej(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params);
943 void avdt_msg_ind(AvdtpCcb* p_ccb, BT_HDR* p_buf);
944
945 /* Adaptation layer function declarations */
946 void avdt_ad_init(void);
947 uint8_t avdt_ad_type_to_tcid(uint8_t type, AvdtpScb* p_scb);
948 AvdtpTransportChannel* avdt_ad_tc_tbl_by_st(uint8_t type, AvdtpCcb* p_ccb, uint8_t state);
949 AvdtpTransportChannel* avdt_ad_tc_tbl_by_lcid(uint16_t lcid);
950 AvdtpTransportChannel* avdt_ad_tc_tbl_alloc(AvdtpCcb* p_ccb);
951 uint8_t avdt_ad_tc_tbl_to_idx(AvdtpTransportChannel* p_tbl);
952 void avdt_ad_tc_close_ind(AvdtpTransportChannel* p_tbl);
953 void avdt_ad_tc_open_ind(AvdtpTransportChannel* p_tbl);
954 void avdt_ad_tc_cong_ind(AvdtpTransportChannel* p_tbl, bool is_congested);
955 void avdt_ad_tc_data_ind(AvdtpTransportChannel* p_tbl, BT_HDR* p_buf);
956 AvdtpTransportChannel* avdt_ad_tc_tbl_by_type(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb);
957 tL2CAP_DW_RESULT avdt_ad_write_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb, BT_HDR* p_buf);
958 void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb, tAVDT_ROLE role);
959 void avdt_ad_close_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb);
960
961 void avdt_ccb_idle_ccb_timer_timeout(void* data);
962 void avdt_ccb_ret_ccb_timer_timeout(void* data);
963 void avdt_ccb_rsp_ccb_timer_timeout(void* data);
964 void avdt_scb_transport_channel_timer_timeout(void* data);
965 void avdt_init_delay_report_timer_timeout(void* data);
966
967 /*****************************************************************************
968 * macros
969 ****************************************************************************/
970
971 /* we store the scb and the label in the layer_specific field of the
972 * current cmd
973 */
974 #define AVDT_BLD_LAYERSPEC(ls, msg, label) ls = (((label) << 4) | (msg))
975
976 #define AVDT_LAYERSPEC_LABEL(ls) ((uint8_t)((ls) >> 4))
977
978 #define AVDT_LAYERSPEC_MSG(ls) ((uint8_t)((ls) & 0x000F))
979
980 /*****************************************************************************
981 * global data
982 ****************************************************************************/
983
984 /******************************************************************************
985 * Main Control Block
986 ******************************************************************************/
987 extern AvdtpCb avdtp_cb;
988
989 /* L2CAP callback registration structure */
990 extern const tL2CAP_APPL_INFO avdt_l2c_appl;
991
992 /* reject message event lookup table */
993 extern const uint8_t avdt_msg_rej_2_evt[];
994
995 constexpr uint16_t kAvdtpMtu = 1024;
996
997 #endif /* AVDT_INT_H */
998