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