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