RSeries astromech firmware
l2c_api.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 1999-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 the L2CAP API definitions
22  *
23  ******************************************************************************/
24 #ifndef L2C_API_H
25 #define L2C_API_H
26 
27 #include <stdbool.h>
28 
31 
32 /*****************************************************************************
33 ** Constants
34 *****************************************************************************/
35 
36 /* Define the minimum offset that L2CAP needs in a buffer. This is made up of
37 ** HCI type(1), len(2), handle(2), L2CAP len(2) and CID(2) => 9
38 */
39 #define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */
40 
41 /* result code for L2CA_DataWrite() */
42 #define L2CAP_DW_FAILED false
43 #define L2CAP_DW_SUCCESS true
44 #define L2CAP_DW_CONGESTED 2
45 
46 
47 /*****************************************************************************
48 ** Type Definitions
49 *****************************************************************************/
50 
52 typedef struct {
53 #define L2CAP_FCR_BASIC_MODE 0x00
54 #define L2CAP_FCR_ERTM_MODE 0x03
55 #define L2CAP_FCR_STREAM_MODE 0x04
56 
57  UINT8 mode;
58 
59  UINT8 tx_win_sz;
60  UINT8 max_transmit;
61  UINT16 rtrans_tout;
62  UINT16 mon_tout;
63  UINT16 mps;
64 } tL2CAP_FCR_OPTS;
65 
66 /* Define a structure to hold the configuration parameters. Since the
67 ** parameters are optional, for each parameter there is a boolean to
68 ** use to signify its presence or absence.
69 */
71 typedef struct {
72  UINT16 result; /* Only used in confirm messages */
73  BOOLEAN mtu_present;
74  UINT16 mtu;
75  BOOLEAN qos_present;
76  FLOW_SPEC qos;
77  BOOLEAN flush_to_present;
78  UINT16 flush_to;
79  BOOLEAN fcr_present;
80  tL2CAP_FCR_OPTS fcr;
81  BOOLEAN fcs_present; /* Optionally bypasses FCS checks */
82  UINT8 fcs; /* '0' if desire is to bypass FCS, otherwise '1' */
83  BOOLEAN ext_flow_spec_present;
84  tHCI_EXT_FLOW_SPEC ext_flow_spec;
85  UINT16 flags; /* bit 0: 0-no continuation, 1-continuation */
86 } tL2CAP_CFG_INFO;
87 
88 
89 /*********************************
90 ** Callback Functions Prototypes
91 **********************************/
92 
93 /* Connection indication callback prototype. Parameters are
94 ** BD Address of remote
95 ** Local CID assigned to the connection
96 ** PSM that the remote wants to connect to
97 ** Identifier that the remote sent
98 */
100 
101 
102 /* Connection confirmation callback prototype. Parameters are
103 ** Local CID
104 ** Result - 0 = connected, non-zero means failure reason
105 */
107 
108 
109 /* Connection pending callback prototype. Parameters are
110 ** Local CID
111 */
112 typedef void (tL2CA_CONNECT_PND_CB) (UINT16);
113 
114 
115 /* Configuration indication callback prototype. Parameters are
116 ** Local CID assigned to the connection
117 ** Pointer to configuration info
118 */
119 typedef void (tL2CA_CONFIG_IND_CB) (UINT16, tL2CAP_CFG_INFO *);
120 
121 
122 /* Configuration confirm callback prototype. Parameters are
123 ** Local CID assigned to the connection
124 ** Pointer to configuration info
125 */
126 typedef void (tL2CA_CONFIG_CFM_CB) (UINT16, tL2CAP_CFG_INFO *);
127 
128 
129 /* Disconnect indication callback prototype. Parameters are
130 ** Local CID
131 ** Boolean whether upper layer should ack this
132 */
134 
135 
136 /* Disconnect confirm callback prototype. Parameters are
137 ** Local CID
138 ** Result
139 */
141 
142 
143 /* QOS Violation indication callback prototype. Parameters are
144 ** BD Address of violating device
145 */
147 
148 
149 /* Data received indication callback prototype. Parameters are
150 ** Local CID
151 ** Address of buffer
152 */
153 typedef void (tL2CA_DATA_IND_CB) (UINT16, BT_HDR *);
154 
155 
156 /* Congestion status callback protype. This callback is optional. If
157 ** an application tries to send data when the transmit queue is full,
158 ** the data will anyways be dropped. The parameter is:
159 ** Local CID
160 ** TRUE if congested, FALSE if uncongested
161 */
163 
164 
165 /* Transmit complete callback protype. This callback is optional. If
166 ** set, L2CAP will call it when packets are sent or flushed. If the
167 ** count is 0xFFFF, it means all packets are sent for that CID (eRTM
168 ** mode only). The parameters are:
169 ** Local CID
170 ** Number of SDUs sent or dropped
171 */
173 
174 
175 /* Define the structure that applications use to register with
176 ** L2CAP. This structure includes callback functions. All functions
177 ** MUST be provided, with the exception of the "connect pending"
178 ** callback and "congestion status" callback.
179 */
181 typedef struct {
182  tL2CA_CONNECT_IND_CB *pL2CA_ConnectInd_Cb;
183  tL2CA_CONNECT_CFM_CB *pL2CA_ConnectCfm_Cb;
184  tL2CA_CONNECT_PND_CB *pL2CA_ConnectPnd_Cb;
185  tL2CA_CONFIG_IND_CB *pL2CA_ConfigInd_Cb;
186  tL2CA_CONFIG_CFM_CB *pL2CA_ConfigCfm_Cb;
187  tL2CA_DISCONNECT_IND_CB *pL2CA_DisconnectInd_Cb;
188  tL2CA_DISCONNECT_CFM_CB *pL2CA_DisconnectCfm_Cb;
189  tL2CA_QOS_VIOLATION_IND_CB *pL2CA_QoSViolationInd_Cb;
190  tL2CA_DATA_IND_CB *pL2CA_DataInd_Cb;
191  tL2CA_CONGESTION_STATUS_CB *pL2CA_CongestionStatus_Cb;
192  tL2CA_TX_COMPLETE_CB *pL2CA_TxComplete_Cb;
193 
194 } tL2CAP_APPL_INFO;
195 
196 /* Define the structure that applications use to create or accept
197 ** connections with enhanced retransmission mode.
198 */
200 typedef struct {
201  UINT8 preferred_mode;
202  UINT8 allowed_modes;
203  UINT16 user_rx_buf_size;
204  UINT16 user_tx_buf_size;
205  UINT16 fcr_rx_buf_size;
206  UINT16 fcr_tx_buf_size;
207 
208 } tL2CAP_ERTM_INFO;
209 
210 #define L2CA_REGISTER(a,b,c) L2CA_Register(a,(tL2CAP_APPL_INFO *)b)
211 #define L2CA_DEREGISTER(a) L2CA_Deregister(a)
212 #define L2CA_CONNECT_REQ(a,b,c,d) L2CA_ErtmConnectReq(a,b,c)
213 #define L2CA_CONNECT_RSP(a,b,c,d,e,f,g) L2CA_ErtmConnectRsp(a,b,c,d,e,f)
214 #define L2CA_CONFIG_REQ(a,b) L2CA_ConfigReq(a,b)
215 #define L2CA_CONFIG_RSP(a,b) L2CA_ConfigRsp(a,b)
216 #define L2CA_DISCONNECT_REQ(a) L2CA_DisconnectReq(a)
217 #define L2CA_DISCONNECT_RSP(a) L2CA_DisconnectRsp(a)
218 #define L2CA_DATA_WRITE(a, b) L2CA_DataWrite(a, b)
219 
220 /*****************************************************************************
221 ** External Function Declarations
222 *****************************************************************************/
223 #ifdef __cplusplus
224 extern "C"
225 {
226 #endif
227 
228 /*******************************************************************************
229 **
230 ** Function L2CA_Register
231 **
232 ** Description Other layers call this function to register for L2CAP
233 ** services.
234 **
235 ** Returns PSM to use or zero if error. Typically, the PSM returned
236 ** is the same as was passed in, but for an outgoing-only
237 ** connection to a dynamic PSM, a "virtual" PSM is returned
238 ** and should be used in the calls to L2CA_ConnectReq() and
239 ** BTM_SetSecurityLevel().
240 **
241 *******************************************************************************/
242 extern UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info);
243 
244 /*******************************************************************************
245 **
246 ** Function L2CA_Deregister
247 **
248 ** Description Other layers call this function to deregister for L2CAP
249 ** services.
250 **
251 ** Returns void
252 **
253 *******************************************************************************/
254 extern void L2CA_Deregister (UINT16 psm);
255 
256 /*******************************************************************************
257 **
258 ** Function L2CA_ErtmConnectReq
259 **
260 ** Description Higher layers call this function to create an L2CAP connection
261 ** that needs to use Enhanced Retransmission Mode.
262 ** Note that the connection is not established at this time, but
263 ** connection establishment gets started. The callback function
264 ** will be invoked when connection establishes or fails.
265 **
266 ** Returns the CID of the connection, or 0 if it failed to start
267 **
268 *******************************************************************************/
269 extern UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr,
270  tL2CAP_ERTM_INFO *p_ertm_info);
271 
272 /*******************************************************************************
273 **
274 ** Function L2CA_ErtmConnectRsp
275 **
276 ** Description Higher layers call this function to accept an incoming
277 ** L2CAP connection, for which they had gotten an connect
278 ** indication callback, and for which the higher layer wants
279 ** to use Enhanced Retransmission Mode.
280 **
281 ** Returns TRUE for success, FALSE for failure
282 **
283 *******************************************************************************/
284 extern BOOLEAN L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
285  UINT16 result, UINT16 status,
286  tL2CAP_ERTM_INFO *p_ertm_info);
287 
288 /*******************************************************************************
289 **
290 ** Function L2CA_ConfigReq
291 **
292 ** Description Higher layers call this function to send configuration.
293 **
294 ** Returns TRUE if configuration sent, else FALSE
295 **
296 *******************************************************************************/
297 extern BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
298 
299 /*******************************************************************************
300 **
301 ** Function L2CA_ConfigRsp
302 **
303 ** Description Higher layers call this function to send a configuration
304 ** response.
305 **
306 ** Returns TRUE if configuration response sent, else FALSE
307 **
308 *******************************************************************************/
309 extern BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
310 
311 /*******************************************************************************
312 **
313 ** Function L2CA_DisconnectReq
314 **
315 ** Description Higher layers call this function to disconnect a channel.
316 **
317 ** Returns TRUE if disconnect sent, else FALSE
318 **
319 *******************************************************************************/
320 extern BOOLEAN L2CA_DisconnectReq (UINT16 cid);
321 
322 /*******************************************************************************
323 **
324 ** Function L2CA_DisconnectRsp
325 **
326 ** Description Higher layers call this function to acknowledge the
327 ** disconnection of a channel.
328 **
329 ** Returns void
330 **
331 *******************************************************************************/
332 extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid);
333 
334 /*******************************************************************************
335 **
336 ** Function L2CA_DataWrite
337 **
338 ** Description Higher layers call this function to write data.
339 **
340 ** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE
341 ** L2CAP_DW_CONGESTED, if data accepted and the channel is congested
342 ** L2CAP_DW_FAILED, if error
343 **
344 *******************************************************************************/
345 extern UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data);
346 
347 
348 #ifdef __cplusplus
349 }
350 #endif
351 
352 #endif /* L2C_API_H */
tL2CA_DISCONNECT_CFM_CB
void() tL2CA_DISCONNECT_CFM_CB(UINT16, UINT16)
Definition: l2c_api.h:140
BD_ADDR
uint8_t BD_ADDR[BD_ADDR_LEN]
Definition: bt_types.h:66
L2CA_ConfigRsp
BOOLEAN L2CA_ConfigRsp(UINT16 cid, tL2CAP_CFG_INFO *p_cfg)
tL2CA_QOS_VIOLATION_IND_CB
void() tL2CA_QOS_VIOLATION_IND_CB(BD_ADDR)
Definition: l2c_api.h:146
tL2CA_CONNECT_CFM_CB
void() tL2CA_CONNECT_CFM_CB(UINT16, UINT16)
Definition: l2c_api.h:106
L2CA_DataWrite
UINT8 L2CA_DataWrite(UINT16 cid, BT_HDR *p_data)
tL2CA_DATA_IND_CB
void() tL2CA_DATA_IND_CB(UINT16, BT_HDR *)
Definition: l2c_api.h:153
tL2CA_CONNECT_IND_CB
void() tL2CA_CONNECT_IND_CB(BD_ADDR, UINT16, UINT16, UINT8)
Definition: l2c_api.h:99
tL2CA_CONGESTION_STATUS_CB
void() tL2CA_CONGESTION_STATUS_CB(UINT16, BOOLEAN)
Definition: l2c_api.h:162
L2CA_ErtmConnectReq
UINT16 L2CA_ErtmConnectReq(UINT16 psm, BD_ADDR p_bd_addr, tL2CAP_ERTM_INFO *p_ertm_info)
UINT8
uint8_t UINT8
Definition: bt_types.h:25
tL2CA_CONNECT_PND_CB
void() tL2CA_CONNECT_PND_CB(UINT16)
Definition: l2c_api.h:112
tL2CA_DISCONNECT_IND_CB
void() tL2CA_DISCONNECT_IND_CB(UINT16, BOOLEAN)
Definition: l2c_api.h:133
BOOLEAN
bool BOOLEAN
Definition: bt_types.h:33
hcidefs.h
l2cdefs.h
tL2CA_CONFIG_CFM_CB
void() tL2CA_CONFIG_CFM_CB(UINT16, tL2CAP_CFG_INFO *)
Definition: l2c_api.h:126
tL2CA_CONFIG_IND_CB
void() tL2CA_CONFIG_IND_CB(UINT16, tL2CAP_CFG_INFO *)
Definition: l2c_api.h:119
L2CA_DisconnectRsp
BOOLEAN L2CA_DisconnectRsp(UINT16 cid)
L2CA_Deregister
void L2CA_Deregister(UINT16 psm)
L2CA_Register
UINT16 L2CA_Register(UINT16 psm, tL2CAP_APPL_INFO *p_cb_info)
L2CA_DisconnectReq
BOOLEAN L2CA_DisconnectReq(UINT16 cid)
tL2CA_TX_COMPLETE_CB
void() tL2CA_TX_COMPLETE_CB(UINT16, UINT16)
Definition: l2c_api.h:172
L2CA_ErtmConnectRsp
BOOLEAN L2CA_ErtmConnectRsp(BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result, UINT16 status, tL2CAP_ERTM_INFO *p_ertm_info)
L2CA_ConfigReq
BOOLEAN L2CA_ConfigReq(UINT16 cid, tL2CAP_CFG_INFO *p_cfg)
UINT16
uint16_t UINT16
Definition: bt_types.h:26