• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2003-2016 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 AVCTP.
22  *
23  ******************************************************************************/
24 #ifndef AVCT_INT_H
25 #define AVCT_INT_H
26 
27 #include "avct_api.h"
28 #include "avct_defs.h"
29 #include "bt_common.h"
30 #include "l2c_api.h"
31 #include "osi/include/fixed_queue.h"
32 
33 /*****************************************************************************
34  * constants
35  ****************************************************************************/
36 
37 /* lcb state machine events */
38 enum {
39   AVCT_LCB_UL_BIND_EVT,
40   AVCT_LCB_UL_UNBIND_EVT,
41   AVCT_LCB_UL_MSG_EVT,
42   AVCT_LCB_INT_CLOSE_EVT,
43   AVCT_LCB_LL_OPEN_EVT,
44   AVCT_LCB_LL_CLOSE_EVT,
45   AVCT_LCB_LL_MSG_EVT,
46   AVCT_LCB_LL_CONG_EVT
47 };
48 
49 /* "states" used for L2CAP channel */
50 #define AVCT_CH_IDLE 0 /* No connection */
51 #define AVCT_CH_CONN 1 /* Waiting for connection confirm */
52 #define AVCT_CH_CFG 2  /* Waiting for configuration complete */
53 #define AVCT_CH_OPEN 3 /* Channel opened */
54 
55 /* "no event" indicator used by ccb dealloc */
56 #define AVCT_NO_EVT 0xFF
57 
58 /*****************************************************************************
59  * data types
60  ****************************************************************************/
61 /* sub control block type - common data members for tAVCT_LCB and tAVCT_BCB */
62 typedef struct {
63   uint16_t peer_mtu;  /* peer l2c mtu */
64   uint16_t ch_result; /* L2CAP connection result value */
65   uint16_t ch_lcid;   /* L2CAP channel LCID */
66   uint8_t allocated;  /* 0, not allocated. index+1, otherwise. */
67   uint8_t state;      /* The state machine state */
68   uint8_t ch_state;   /* L2CAP channel state */
69 } tAVCT_SCB;
70 
71 /* link control block type */
72 typedef struct {
73   uint16_t peer_mtu;      /* peer l2c mtu */
74   uint16_t ch_result;     /* L2CAP connection result value */
75   uint16_t ch_lcid;       /* L2CAP channel LCID */
76   uint8_t allocated;      /* 0, not allocated. index+1, otherwise. */
77   uint8_t state;          /* The state machine state */
78   uint8_t ch_state;       /* L2CAP channel state */
79   BT_HDR* p_rx_msg;       /* Message being reassembled */
80   uint16_t conflict_lcid; /* L2CAP channel LCID */
81   RawAddress peer_addr;   /* BD address of peer */
82   fixed_queue_t* tx_q;    /* Transmit data buffer queue       */
83   bool cong;              /* true, if congested */
84 } tAVCT_LCB;
85 
86 /* browse control block type */
87 typedef struct {
88   uint16_t peer_mtu;  /* peer l2c mtu */
89   uint16_t ch_result; /* L2CAP connection result value */
90   uint16_t ch_lcid;   /* L2CAP channel LCID */
91   uint8_t allocated;  /* 0, not allocated. index+1, otherwise. */
92   uint8_t state;      /* The state machine state */
93   uint8_t ch_state;   /* L2CAP channel state */
94   BT_HDR* p_tx_msg;  /* Message to be sent - in case the browsing channel is not
95                         open when MsgReg is called */
96   uint8_t ch_close;  /* CCB index+1, if CCB initiated channel close */
97   RawAddress peer_addr; /* BD address of peer */
98 } tAVCT_BCB;
99 
100 #define AVCT_ALOC_LCB 0x01
101 #define AVCT_ALOC_BCB 0x02
102 /* connection control block */
103 typedef struct {
104   tAVCT_CC cc;       /* parameters from connection creation */
105   tAVCT_LCB* p_lcb;  /* Associated LCB */
106   tAVCT_BCB* p_bcb;  /* associated BCB */
107   bool ch_close;     /* Whether CCB initiated channel close */
108   uint8_t allocated; /* Whether LCB/BCB is allocated */
109 } tAVCT_CCB;
110 
111 /* data type associated with UL_MSG_EVT */
112 typedef struct {
113   BT_HDR* p_buf;
114   tAVCT_CCB* p_ccb;
115   uint8_t label;
116   uint8_t cr;
117 } tAVCT_UL_MSG;
118 
119 /* union associated with lcb state machine events */
120 typedef union {
121   tAVCT_UL_MSG ul_msg;
122   BT_HDR* p_buf;
123   tAVCT_CCB* p_ccb;
124   uint16_t result;
125   bool cong;
126   uint8_t err_code;
127 } tAVCT_LCB_EVT;
128 
129 /* Control block for AVCT */
130 typedef struct {
131   tAVCT_LCB lcb[AVCT_NUM_LINKS]; /* link control blocks */
132   tAVCT_BCB bcb[AVCT_NUM_LINKS]; /* browse control blocks */
133   tAVCT_CCB ccb[AVCT_NUM_CONN];  /* connection control blocks */
134   uint8_t trace_level;           /* trace level */
135 } tAVCT_CB;
136 
137 /*****************************************************************************
138  * function declarations
139  ****************************************************************************/
140 
141 /* LCB function declarations */
142 extern void avct_lcb_event(tAVCT_LCB* p_lcb, uint8_t event,
143                            tAVCT_LCB_EVT* p_data);
144 extern void avct_bcb_event(tAVCT_BCB* p_bcb, uint8_t event,
145                            tAVCT_LCB_EVT* p_data);
146 extern void avct_close_bcb(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
147 extern tAVCT_LCB* avct_lcb_by_bcb(tAVCT_BCB* p_bcb);
148 extern tAVCT_BCB* avct_bcb_by_lcb(tAVCT_LCB* p_lcb);
149 extern uint8_t avct_bcb_get_last_ccb_index(tAVCT_BCB* p_bcb,
150                                            tAVCT_CCB* p_ccb_last);
151 extern tAVCT_BCB* avct_bcb_by_lcid(uint16_t lcid);
152 extern tAVCT_LCB* avct_lcb_by_bd(const RawAddress& bd_addr);
153 extern tAVCT_LCB* avct_lcb_alloc(const RawAddress& bd_addr);
154 extern void avct_lcb_dealloc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
155 extern tAVCT_LCB* avct_lcb_by_lcid(uint16_t lcid);
156 extern tAVCT_CCB* avct_lcb_has_pid(tAVCT_LCB* p_lcb, uint16_t pid);
157 extern bool avct_lcb_last_ccb(tAVCT_LCB* p_lcb, tAVCT_CCB* p_ccb_last);
158 
159 /* LCB action functions */
160 extern void avct_lcb_chnl_open(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
161 extern void avct_lcb_unbind_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
162 extern void avct_lcb_open_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
163 extern void avct_lcb_open_fail(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
164 extern void avct_lcb_close_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
165 extern void avct_lcb_close_cfm(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
166 extern void avct_lcb_bind_conn(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
167 extern void avct_lcb_chk_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
168 extern void avct_lcb_chnl_disc(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
169 extern void avct_lcb_bind_fail(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
170 extern void avct_lcb_cong_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
171 extern void avct_lcb_discard_msg(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
172 extern void avct_lcb_send_msg(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
173 extern void avct_lcb_msg_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
174 extern void avct_lcb_free_msg_ind(tAVCT_LCB* p_lcb, tAVCT_LCB_EVT* p_data);
175 
176 /* BCB action functions */
177 typedef void (*tAVCT_BCB_ACTION)(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
178 extern void avct_bcb_chnl_open(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
179 extern void avct_bcb_unbind_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
180 extern void avct_bcb_open_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
181 extern void avct_bcb_open_fail(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
182 extern void avct_bcb_close_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
183 extern void avct_bcb_close_cfm(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
184 extern void avct_bcb_bind_conn(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
185 extern void avct_bcb_chk_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
186 extern void avct_bcb_chnl_disc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
187 extern void avct_bcb_bind_fail(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
188 extern void avct_bcb_cong_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
189 extern void avct_bcb_discard_msg(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
190 extern void avct_bcb_send_msg(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
191 extern void avct_bcb_msg_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
192 extern void avct_bcb_free_msg_ind(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
193 
194 extern void avct_bcb_dealloc(tAVCT_BCB* p_bcb, tAVCT_LCB_EVT* p_data);
195 
196 extern const tAVCT_BCB_ACTION avct_bcb_action[];
197 extern const uint8_t avct_lcb_pkt_type_len[];
198 
199 /* CCB function declarations */
200 extern tAVCT_CCB* avct_ccb_alloc(tAVCT_CC* p_cc);
201 extern void avct_ccb_dealloc(tAVCT_CCB* p_ccb, uint8_t event, uint16_t result,
202                              const RawAddress* bd_addr);
203 extern uint8_t avct_ccb_to_idx(tAVCT_CCB* p_ccb);
204 extern tAVCT_CCB* avct_ccb_by_idx(uint8_t idx);
205 
206 /*****************************************************************************
207  * global data
208  ****************************************************************************/
209 
210 /* Main control block */
211 extern tAVCT_CB avct_cb;
212 
213 /* L2CAP callback registration structure */
214 extern const tL2CAP_APPL_INFO avct_l2c_appl;
215 extern const tL2CAP_APPL_INFO avct_l2c_br_appl;
216 
217 void avct_l2c_disconnect(uint16_t lcid, uint16_t result);
218 void avct_l2c_br_disconnect(uint16_t lcid, uint16_t result);
219 
220 constexpr uint16_t kAvrcMtu = 512;
221 constexpr uint16_t kAvrcBrMtu = 1008;
222 
223 #endif /* AVCT_INT_H */
224