l2cap.h revision 1.13 1 1.13 rmind /* $NetBSD: l2cap.h,v 1.13 2014/05/20 18:25:54 rmind Exp $ */
2 1.1 gdamore
3 1.1 gdamore /*-
4 1.1 gdamore * Copyright (c) 2005 Iain Hibbert.
5 1.1 gdamore * Copyright (c) 2006 Itronix Inc.
6 1.1 gdamore * All rights reserved.
7 1.1 gdamore *
8 1.1 gdamore * Redistribution and use in source and binary forms, with or without
9 1.1 gdamore * modification, are permitted provided that the following conditions
10 1.1 gdamore * are met:
11 1.1 gdamore * 1. Redistributions of source code must retain the above copyright
12 1.1 gdamore * notice, this list of conditions and the following disclaimer.
13 1.1 gdamore * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 gdamore * notice, this list of conditions and the following disclaimer in the
15 1.1 gdamore * documentation and/or other materials provided with the distribution.
16 1.1 gdamore * 3. The name of Itronix Inc. may not be used to endorse
17 1.1 gdamore * or promote products derived from this software without specific
18 1.1 gdamore * prior written permission.
19 1.1 gdamore *
20 1.1 gdamore * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
21 1.1 gdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 gdamore * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 gdamore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
24 1.1 gdamore * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 1.1 gdamore * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 1.1 gdamore * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 1.1 gdamore * ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 gdamore * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 gdamore * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 gdamore * POSSIBILITY OF SUCH DAMAGE.
31 1.1 gdamore */
32 1.1 gdamore /*-
33 1.1 gdamore * Copyright (c) Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
34 1.1 gdamore * All rights reserved.
35 1.1 gdamore *
36 1.1 gdamore * Redistribution and use in source and binary forms, with or without
37 1.1 gdamore * modification, are permitted provided that the following conditions
38 1.1 gdamore * are met:
39 1.1 gdamore * 1. Redistributions of source code must retain the above copyright
40 1.1 gdamore * notice, this list of conditions and the following disclaimer.
41 1.1 gdamore * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 gdamore * notice, this list of conditions and the following disclaimer in the
43 1.1 gdamore * documentation and/or other materials provided with the distribution.
44 1.1 gdamore *
45 1.1 gdamore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 1.1 gdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 1.1 gdamore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 1.1 gdamore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 1.1 gdamore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 1.1 gdamore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 1.1 gdamore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 1.1 gdamore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 1.1 gdamore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 1.1 gdamore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 1.1 gdamore * SUCH DAMAGE.
56 1.1 gdamore *
57 1.13 rmind * $Id: l2cap.h,v 1.13 2014/05/20 18:25:54 rmind Exp $
58 1.1 gdamore * $FreeBSD: src/sys/netgraph/bluetooth/include/l2cap.h,v 1.4 2005/08/31 18:13:23 emax Exp $
59 1.1 gdamore */
60 1.1 gdamore
61 1.1 gdamore /*
62 1.1 gdamore * This file contains everything that application needs to know about
63 1.1 gdamore * Link Layer Control and Adaptation Protocol (L2CAP). All information
64 1.1 gdamore * was obtained from Bluetooth Specification Books (v1.1 and up)
65 1.1 gdamore *
66 1.1 gdamore * This file can be included by both kernel and userland applications.
67 1.1 gdamore */
68 1.1 gdamore
69 1.1 gdamore #ifndef _NETBT_L2CAP_H_
70 1.1 gdamore #define _NETBT_L2CAP_H_
71 1.1 gdamore
72 1.2 plunky #include <sys/types.h>
73 1.2 plunky
74 1.1 gdamore /**************************************************************************
75 1.1 gdamore **************************************************************************
76 1.1 gdamore ** Common defines and types (L2CAP)
77 1.1 gdamore **************************************************************************
78 1.1 gdamore **************************************************************************/
79 1.1 gdamore
80 1.1 gdamore /*
81 1.1 gdamore * Channel IDs are assigned per machine. So the total number of channels that
82 1.1 gdamore * a machine can have open at the same time is 0xffff - 0x0040 = 0xffbf (65471).
83 1.1 gdamore * This number does not depend on number of HCI connections.
84 1.1 gdamore */
85 1.1 gdamore
86 1.1 gdamore #define L2CAP_NULL_CID 0x0000 /* DO NOT USE THIS CID */
87 1.1 gdamore #define L2CAP_SIGNAL_CID 0x0001 /* signaling channel ID */
88 1.1 gdamore #define L2CAP_CLT_CID 0x0002 /* connectionless channel ID */
89 1.1 gdamore /* 0x0003 - 0x003f Reserved */
90 1.1 gdamore #define L2CAP_FIRST_CID 0x0040 /* dynamically alloc. (start) */
91 1.1 gdamore #define L2CAP_LAST_CID 0xffff /* dynamically alloc. (end) */
92 1.1 gdamore
93 1.1 gdamore /* L2CAP MTU */
94 1.1 gdamore #define L2CAP_MTU_MINIMUM 48
95 1.1 gdamore #define L2CAP_MTU_DEFAULT 672
96 1.1 gdamore #define L2CAP_MTU_MAXIMUM 0xffff
97 1.1 gdamore
98 1.1 gdamore /* L2CAP flush and link timeouts */
99 1.1 gdamore #define L2CAP_FLUSH_TIMO_DEFAULT 0xffff /* always retransmit */
100 1.1 gdamore #define L2CAP_LINK_TIMO_DEFAULT 0xffff
101 1.1 gdamore
102 1.1 gdamore /* L2CAP Command Reject reasons */
103 1.1 gdamore #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000
104 1.1 gdamore #define L2CAP_REJ_MTU_EXCEEDED 0x0001
105 1.1 gdamore #define L2CAP_REJ_INVALID_CID 0x0002
106 1.1 gdamore /* 0x0003 - 0xffff - reserved for future use */
107 1.1 gdamore
108 1.1 gdamore /* Protocol/Service Multiplexor (PSM) values */
109 1.1 gdamore #define L2CAP_PSM_ANY 0x0000 /* Any/Invalid PSM */
110 1.1 gdamore #define L2CAP_PSM_SDP 0x0001 /* Service Discovery Protocol */
111 1.1 gdamore #define L2CAP_PSM_RFCOMM 0x0003 /* RFCOMM protocol */
112 1.1 gdamore #define L2CAP_PSM_TCP 0x0005 /* Telephony Control Protocol */
113 1.1 gdamore #define L2CAP_PSM_TCS 0x0007 /* TCS cordless */
114 1.1 gdamore #define L2CAP_PSM_BNEP 0x000f /* Bluetooth Network */
115 1.1 gdamore /* Encapsulation Protocol*/
116 1.1 gdamore #define L2CAP_PSM_HID_CNTL 0x0011 /* HID Control */
117 1.1 gdamore #define L2CAP_PSM_HID_INTR 0x0013 /* HID Interrupt */
118 1.1 gdamore #define L2CAP_PSM_ESDP 0x0015 /* Extended Service */
119 1.1 gdamore /* Discovery Profile */
120 1.1 gdamore #define L2CAP_PSM_AVCTP 0x0017 /* Audio/Visual Control */
121 1.1 gdamore /* Transport Protocol */
122 1.1 gdamore #define L2CAP_PSM_AVDTP 0x0019 /* Audio/Visual Distribution */
123 1.1 gdamore /* Transport Protocol */
124 1.1 gdamore /* 0x0019 - 0x1000 - reserved for future use */
125 1.1 gdamore
126 1.1 gdamore #define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001)
127 1.1 gdamore
128 1.1 gdamore /* L2CAP Connection response command result codes */
129 1.1 gdamore #define L2CAP_SUCCESS 0x0000
130 1.1 gdamore #define L2CAP_PENDING 0x0001
131 1.1 gdamore #define L2CAP_PSM_NOT_SUPPORTED 0x0002
132 1.1 gdamore #define L2CAP_SECURITY_BLOCK 0x0003
133 1.1 gdamore #define L2CAP_NO_RESOURCES 0x0004
134 1.1 gdamore #define L2CAP_TIMEOUT 0xeeee
135 1.1 gdamore #define L2CAP_UNKNOWN 0xffff
136 1.1 gdamore /* 0x0005 - 0xffff - reserved for future use */
137 1.1 gdamore
138 1.1 gdamore /* L2CAP Connection response status codes */
139 1.1 gdamore #define L2CAP_NO_INFO 0x0000
140 1.1 gdamore #define L2CAP_AUTH_PENDING 0x0001
141 1.1 gdamore #define L2CAP_AUTZ_PENDING 0x0002
142 1.1 gdamore /* 0x0003 - 0xffff - reserved for future use */
143 1.1 gdamore
144 1.1 gdamore /* L2CAP Configuration response result codes */
145 1.1 gdamore #define L2CAP_UNACCEPTABLE_PARAMS 0x0001
146 1.1 gdamore #define L2CAP_REJECT 0x0002
147 1.1 gdamore #define L2CAP_UNKNOWN_OPTION 0x0003
148 1.1 gdamore /* 0x0003 - 0xffff - reserved for future use */
149 1.1 gdamore
150 1.1 gdamore /* L2CAP Configuration options */
151 1.1 gdamore #define L2CAP_OPT_CFLAG_BIT 0x0001
152 1.1 gdamore #define L2CAP_OPT_CFLAG(flags) ((flags) & L2CAP_OPT_CFLAG_BIT)
153 1.1 gdamore #define L2CAP_OPT_HINT_BIT 0x80
154 1.1 gdamore #define L2CAP_OPT_HINT(type) ((type) & L2CAP_OPT_HINT_BIT)
155 1.1 gdamore #define L2CAP_OPT_HINT_MASK 0x7f
156 1.1 gdamore #define L2CAP_OPT_MTU 0x01
157 1.1 gdamore #define L2CAP_OPT_MTU_SIZE sizeof(uint16_t)
158 1.1 gdamore #define L2CAP_OPT_FLUSH_TIMO 0x02
159 1.1 gdamore #define L2CAP_OPT_FLUSH_TIMO_SIZE sizeof(uint16_t)
160 1.1 gdamore #define L2CAP_OPT_QOS 0x03
161 1.1 gdamore #define L2CAP_OPT_QOS_SIZE sizeof(l2cap_qos_t)
162 1.1 gdamore #define L2CAP_OPT_RFC 0x04
163 1.1 gdamore #define L2CAP_OPT_RFC_SIZE sizeof(l2cap_rfc_t)
164 1.1 gdamore /* 0x05 - 0xff - reserved for future use */
165 1.1 gdamore
166 1.1 gdamore /* L2CAP Information request type codes */
167 1.1 gdamore #define L2CAP_CONNLESS_MTU 0x0001
168 1.1 gdamore #define L2CAP_EXTENDED_FEATURES 0x0002
169 1.10 plunky #define L2CAP_FIXED_CHANNELS 0x0003
170 1.10 plunky /* 0x0004 - 0xffff - reserved for future use */
171 1.1 gdamore
172 1.1 gdamore /* L2CAP Information response codes */
173 1.1 gdamore #define L2CAP_NOT_SUPPORTED 0x0001
174 1.1 gdamore /* 0x0002 - 0xffff - reserved for future use */
175 1.1 gdamore
176 1.1 gdamore /* L2CAP Quality of Service option */
177 1.1 gdamore typedef struct {
178 1.1 gdamore uint8_t flags; /* reserved for future use */
179 1.1 gdamore uint8_t service_type; /* service type */
180 1.1 gdamore uint32_t token_rate; /* bytes per second */
181 1.1 gdamore uint32_t token_bucket_size; /* bytes */
182 1.1 gdamore uint32_t peak_bandwidth; /* bytes per second */
183 1.1 gdamore uint32_t latency; /* microseconds */
184 1.1 gdamore uint32_t delay_variation; /* microseconds */
185 1.8 gmcgarry } __packed l2cap_qos_t;
186 1.1 gdamore
187 1.1 gdamore /* L2CAP QoS type */
188 1.1 gdamore #define L2CAP_QOS_NO_TRAFFIC 0x00
189 1.1 gdamore #define L2CAP_QOS_BEST_EFFORT 0x01 /* (default) */
190 1.1 gdamore #define L2CAP_QOS_GUARANTEED 0x02
191 1.1 gdamore /* 0x03 - 0xff - reserved for future use */
192 1.1 gdamore
193 1.1 gdamore /* L2CAP Retransmission & Flow Control option */
194 1.1 gdamore typedef struct {
195 1.1 gdamore uint8_t mode; /* RFC mode */
196 1.1 gdamore uint8_t window_size; /* bytes */
197 1.1 gdamore uint8_t max_transmit; /* max retransmissions */
198 1.1 gdamore uint16_t retransmit_timo; /* milliseconds */
199 1.1 gdamore uint16_t monitor_timo; /* milliseconds */
200 1.1 gdamore uint16_t max_pdu_size; /* bytes */
201 1.8 gmcgarry } __packed l2cap_rfc_t;
202 1.1 gdamore
203 1.1 gdamore /* L2CAP RFC mode */
204 1.1 gdamore #define L2CAP_RFC_BASIC 0x00 /* (default) */
205 1.1 gdamore #define L2CAP_RFC_RETRANSMIT 0x01
206 1.1 gdamore #define L2CAP_RFC_FLOW 0x02
207 1.1 gdamore /* 0x03 - 0xff - reserved for future use */
208 1.1 gdamore
209 1.1 gdamore /**************************************************************************
210 1.1 gdamore **************************************************************************
211 1.1 gdamore ** Link level defines, headers and types
212 1.1 gdamore **************************************************************************
213 1.1 gdamore **************************************************************************/
214 1.1 gdamore
215 1.1 gdamore /* L2CAP header */
216 1.1 gdamore typedef struct {
217 1.1 gdamore uint16_t length; /* payload size */
218 1.1 gdamore uint16_t dcid; /* destination channel ID */
219 1.8 gmcgarry } __packed l2cap_hdr_t;
220 1.1 gdamore
221 1.1 gdamore /* L2CAP ConnectionLess Traffic (dcid == L2CAP_CLT_CID) */
222 1.1 gdamore typedef struct {
223 1.1 gdamore uint16_t psm; /* Protocol/Service Multiplexor */
224 1.8 gmcgarry } __packed l2cap_clt_hdr_t;
225 1.1 gdamore
226 1.1 gdamore #define L2CAP_CLT_MTU_MAXIMUM \
227 1.1 gdamore (L2CAP_MTU_MAXIMUM - sizeof(l2cap_clt_hdr_t))
228 1.1 gdamore
229 1.1 gdamore /* L2CAP Command header (dcid == L2CAP_SIGNAL_CID) */
230 1.1 gdamore typedef struct {
231 1.1 gdamore uint8_t code; /* command OpCode */
232 1.1 gdamore uint8_t ident; /* identifier to match request and response */
233 1.1 gdamore uint16_t length; /* command parameters length */
234 1.8 gmcgarry } __packed l2cap_cmd_hdr_t;
235 1.1 gdamore
236 1.1 gdamore /* L2CAP Command Reject */
237 1.1 gdamore #define L2CAP_COMMAND_REJ 0x01
238 1.1 gdamore typedef struct {
239 1.1 gdamore uint16_t reason; /* reason to reject command */
240 1.1 gdamore uint16_t data[2];/* optional data */
241 1.8 gmcgarry } __packed l2cap_cmd_rej_cp;
242 1.1 gdamore
243 1.1 gdamore /* L2CAP Connection Request */
244 1.1 gdamore #define L2CAP_CONNECT_REQ 0x02
245 1.1 gdamore typedef struct {
246 1.1 gdamore uint16_t psm; /* Protocol/Service Multiplexor (PSM) */
247 1.1 gdamore uint16_t scid; /* source channel ID */
248 1.8 gmcgarry } __packed l2cap_con_req_cp;
249 1.1 gdamore
250 1.1 gdamore /* L2CAP Connection Response */
251 1.1 gdamore #define L2CAP_CONNECT_RSP 0x03
252 1.1 gdamore typedef struct {
253 1.1 gdamore uint16_t dcid; /* destination channel ID */
254 1.1 gdamore uint16_t scid; /* source channel ID */
255 1.1 gdamore uint16_t result; /* 0x00 - success */
256 1.1 gdamore uint16_t status; /* more info if result != 0x00 */
257 1.8 gmcgarry } __packed l2cap_con_rsp_cp;
258 1.1 gdamore
259 1.1 gdamore /* L2CAP Configuration Request */
260 1.1 gdamore #define L2CAP_CONFIG_REQ 0x04
261 1.1 gdamore typedef struct {
262 1.1 gdamore uint16_t dcid; /* destination channel ID */
263 1.1 gdamore uint16_t flags; /* flags */
264 1.1 gdamore /* uint8_t options[] -- options */
265 1.8 gmcgarry } __packed l2cap_cfg_req_cp;
266 1.1 gdamore
267 1.1 gdamore /* L2CAP Configuration Response */
268 1.1 gdamore #define L2CAP_CONFIG_RSP 0x05
269 1.1 gdamore typedef struct {
270 1.1 gdamore uint16_t scid; /* source channel ID */
271 1.1 gdamore uint16_t flags; /* flags */
272 1.1 gdamore uint16_t result; /* 0x00 - success */
273 1.1 gdamore /* uint8_t options[] -- options */
274 1.8 gmcgarry } __packed l2cap_cfg_rsp_cp;
275 1.1 gdamore
276 1.1 gdamore /* L2CAP configuration option */
277 1.1 gdamore typedef struct {
278 1.1 gdamore uint8_t type;
279 1.1 gdamore uint8_t length;
280 1.1 gdamore /* uint8_t value[] -- option value (depends on type) */
281 1.8 gmcgarry } __packed l2cap_cfg_opt_t;
282 1.1 gdamore
283 1.1 gdamore /* L2CAP configuration option value */
284 1.1 gdamore typedef union {
285 1.1 gdamore uint16_t mtu; /* L2CAP_OPT_MTU */
286 1.1 gdamore uint16_t flush_timo; /* L2CAP_OPT_FLUSH_TIMO */
287 1.1 gdamore l2cap_qos_t qos; /* L2CAP_OPT_QOS */
288 1.1 gdamore l2cap_rfc_t rfc; /* L2CAP_OPT_RFC */
289 1.1 gdamore } l2cap_cfg_opt_val_t;
290 1.1 gdamore
291 1.1 gdamore /* L2CAP Disconnect Request */
292 1.1 gdamore #define L2CAP_DISCONNECT_REQ 0x06
293 1.1 gdamore typedef struct {
294 1.1 gdamore uint16_t dcid; /* destination channel ID */
295 1.1 gdamore uint16_t scid; /* source channel ID */
296 1.8 gmcgarry } __packed l2cap_discon_req_cp;
297 1.1 gdamore
298 1.1 gdamore /* L2CAP Disconnect Response */
299 1.1 gdamore #define L2CAP_DISCONNECT_RSP 0x07
300 1.1 gdamore typedef l2cap_discon_req_cp l2cap_discon_rsp_cp;
301 1.1 gdamore
302 1.1 gdamore /* L2CAP Echo Request */
303 1.1 gdamore #define L2CAP_ECHO_REQ 0x08
304 1.1 gdamore /* No command parameters, only optional data */
305 1.1 gdamore
306 1.1 gdamore /* L2CAP Echo Response */
307 1.1 gdamore #define L2CAP_ECHO_RSP 0x09
308 1.1 gdamore #define L2CAP_MAX_ECHO_SIZE \
309 1.1 gdamore (L2CAP_MTU_MAXIMUM - sizeof(l2cap_cmd_hdr_t))
310 1.1 gdamore /* No command parameters, only optional data */
311 1.1 gdamore
312 1.1 gdamore /* L2CAP Information Request */
313 1.1 gdamore #define L2CAP_INFO_REQ 0x0a
314 1.1 gdamore typedef struct {
315 1.1 gdamore uint16_t type; /* requested information type */
316 1.8 gmcgarry } __packed l2cap_info_req_cp;
317 1.1 gdamore
318 1.1 gdamore /* L2CAP Information Response */
319 1.1 gdamore #define L2CAP_INFO_RSP 0x0b
320 1.1 gdamore typedef struct {
321 1.1 gdamore uint16_t type; /* requested information type */
322 1.1 gdamore uint16_t result; /* 0x00 - success */
323 1.1 gdamore /* uint8_t info[] -- info data (depends on type)
324 1.1 gdamore */
325 1.8 gmcgarry } __packed l2cap_info_rsp_cp;
326 1.1 gdamore
327 1.1 gdamore
328 1.1 gdamore /**************************************************************************
329 1.1 gdamore **************************************************************************
330 1.1 gdamore ** L2CAP Socket Definitions
331 1.1 gdamore **************************************************************************
332 1.1 gdamore **************************************************************************/
333 1.1 gdamore
334 1.5 plunky /* Socket options */
335 1.5 plunky #define SO_L2CAP_IMTU 1 /* incoming MTU */
336 1.5 plunky #define SO_L2CAP_OMTU 2 /* outgoing MTU */
337 1.5 plunky #define SO_L2CAP_IQOS 3 /* incoming QoS */
338 1.5 plunky #define SO_L2CAP_OQOS 4 /* outgoing QoS */
339 1.5 plunky #define SO_L2CAP_FLUSH 5 /* flush timeout */
340 1.5 plunky #define SO_L2CAP_LM 6 /* link mode */
341 1.5 plunky
342 1.5 plunky /* L2CAP link mode flags */
343 1.5 plunky #define L2CAP_LM_AUTH (1<<0) /* want authentication */
344 1.5 plunky #define L2CAP_LM_ENCRYPT (1<<1) /* want encryption */
345 1.5 plunky #define L2CAP_LM_SECURE (1<<2) /* want secured link */
346 1.1 gdamore
347 1.1 gdamore #ifdef _KERNEL
348 1.1 gdamore
349 1.1 gdamore LIST_HEAD(l2cap_channel_list, l2cap_channel);
350 1.1 gdamore
351 1.1 gdamore /* global variables */
352 1.1 gdamore extern struct l2cap_channel_list l2cap_active_list;
353 1.1 gdamore extern struct l2cap_channel_list l2cap_listen_list;
354 1.1 gdamore extern struct pool l2cap_pdu_pool;
355 1.1 gdamore extern struct pool l2cap_req_pool;
356 1.1 gdamore extern const l2cap_qos_t l2cap_default_qos;
357 1.1 gdamore
358 1.1 gdamore /* sysctl variables */
359 1.1 gdamore extern int l2cap_response_timeout;
360 1.1 gdamore extern int l2cap_response_extended_timeout;
361 1.1 gdamore extern int l2cap_sendspace, l2cap_recvspace;
362 1.1 gdamore
363 1.1 gdamore /*
364 1.1 gdamore * L2CAP Channel
365 1.1 gdamore */
366 1.1 gdamore struct l2cap_channel {
367 1.1 gdamore struct hci_link *lc_link; /* ACL connection (down) */
368 1.1 gdamore uint16_t lc_state; /* channel state */
369 1.1 gdamore uint16_t lc_flags; /* channel flags */
370 1.5 plunky uint8_t lc_ident; /* cached request id */
371 1.1 gdamore
372 1.1 gdamore uint16_t lc_lcid; /* local channel ID */
373 1.1 gdamore struct sockaddr_bt lc_laddr; /* local address */
374 1.1 gdamore
375 1.1 gdamore uint16_t lc_rcid; /* remote channel ID */
376 1.1 gdamore struct sockaddr_bt lc_raddr; /* remote address */
377 1.1 gdamore
378 1.5 plunky int lc_mode; /* link mode */
379 1.1 gdamore uint16_t lc_imtu; /* incoming mtu */
380 1.1 gdamore uint16_t lc_omtu; /* outgoing mtu */
381 1.1 gdamore uint16_t lc_flush; /* flush timeout */
382 1.1 gdamore l2cap_qos_t lc_iqos; /* incoming QoS flow control */
383 1.1 gdamore l2cap_qos_t lc_oqos; /* outgoing Qos flow control */
384 1.1 gdamore
385 1.1 gdamore uint8_t lc_pending; /* num of pending PDUs */
386 1.1 gdamore MBUFQ_HEAD() lc_txq; /* transmit queue */
387 1.1 gdamore
388 1.1 gdamore const struct btproto *lc_proto; /* upper layer callbacks */
389 1.1 gdamore void *lc_upper; /* upper layer argument */
390 1.1 gdamore
391 1.1 gdamore LIST_ENTRY(l2cap_channel)lc_ncid; /* next channel (ascending CID) */
392 1.1 gdamore };
393 1.1 gdamore
394 1.4 plunky /* l2cap_channel state */
395 1.5 plunky #define L2CAP_CLOSED 0 /* closed */
396 1.5 plunky #define L2CAP_WAIT_SEND_CONNECT_REQ 1 /* waiting to send connect request */
397 1.5 plunky #define L2CAP_WAIT_RECV_CONNECT_RSP 2 /* waiting to recv connect response */
398 1.5 plunky #define L2CAP_WAIT_SEND_CONNECT_RSP 3 /* waiting to send connect response */
399 1.5 plunky #define L2CAP_WAIT_CONFIG 4 /* waiting for configuration */
400 1.5 plunky #define L2CAP_OPEN 5 /* user data transfer state */
401 1.5 plunky #define L2CAP_WAIT_DISCONNECT 6 /* have sent disconnect request */
402 1.1 gdamore
403 1.1 gdamore /* l2cap_channel flags */
404 1.1 gdamore #define L2CAP_SHUTDOWN (1<<0) /* channel is closing */
405 1.4 plunky #define L2CAP_WAIT_CONFIG_REQ (1<<1) /* waiting for config request */
406 1.4 plunky #define L2CAP_WAIT_CONFIG_RSP (1<<2) /* waiting for config response */
407 1.1 gdamore
408 1.1 gdamore /*
409 1.1 gdamore * L2CAP Request
410 1.1 gdamore */
411 1.1 gdamore struct l2cap_req {
412 1.1 gdamore struct hci_link *lr_link; /* ACL connection */
413 1.1 gdamore struct l2cap_channel *lr_chan; /* channel pointer */
414 1.1 gdamore uint8_t lr_code; /* request code */
415 1.1 gdamore uint8_t lr_id; /* request id */
416 1.6 plunky callout_t lr_rtx; /* response timer */
417 1.1 gdamore TAILQ_ENTRY(l2cap_req) lr_next; /* next request on link */
418 1.1 gdamore };
419 1.1 gdamore
420 1.1 gdamore /*
421 1.1 gdamore * L2CAP Protocol Data Unit
422 1.1 gdamore */
423 1.1 gdamore struct l2cap_pdu {
424 1.1 gdamore struct l2cap_channel *lp_chan; /* PDU owner */
425 1.1 gdamore MBUFQ_HEAD() lp_data; /* PDU data */
426 1.1 gdamore TAILQ_ENTRY(l2cap_pdu) lp_next; /* next PDU on link */
427 1.1 gdamore int lp_pending; /* # of fragments pending */
428 1.1 gdamore };
429 1.1 gdamore
430 1.1 gdamore /*
431 1.1 gdamore * L2CAP function prototypes
432 1.1 gdamore */
433 1.1 gdamore
434 1.1 gdamore struct socket;
435 1.7 plunky struct sockopt;
436 1.1 gdamore struct mbuf;
437 1.1 gdamore
438 1.1 gdamore /* l2cap_lower.c */
439 1.1 gdamore void l2cap_close(struct l2cap_channel *, int);
440 1.1 gdamore void l2cap_recv_frame(struct mbuf *, struct hci_link *);
441 1.1 gdamore int l2cap_start(struct l2cap_channel *);
442 1.1 gdamore
443 1.1 gdamore /* l2cap_misc.c */
444 1.5 plunky int l2cap_setmode(struct l2cap_channel *);
445 1.1 gdamore int l2cap_cid_alloc(struct l2cap_channel *);
446 1.1 gdamore struct l2cap_channel *l2cap_cid_lookup(uint16_t);
447 1.1 gdamore int l2cap_request_alloc(struct l2cap_channel *, uint8_t);
448 1.1 gdamore struct l2cap_req *l2cap_request_lookup(struct hci_link *, uint8_t);
449 1.1 gdamore void l2cap_request_free(struct l2cap_req *);
450 1.1 gdamore void l2cap_rtx(void *);
451 1.9 pooka void l2cap_init(void);
452 1.1 gdamore
453 1.1 gdamore /* l2cap_signal.c */
454 1.1 gdamore void l2cap_recv_signal(struct mbuf *, struct hci_link *);
455 1.1 gdamore int l2cap_send_connect_req(struct l2cap_channel *);
456 1.1 gdamore int l2cap_send_config_req(struct l2cap_channel *);
457 1.1 gdamore int l2cap_send_disconnect_req(struct l2cap_channel *);
458 1.5 plunky int l2cap_send_connect_rsp(struct hci_link *, uint8_t, uint16_t, uint16_t, uint16_t);
459 1.1 gdamore
460 1.1 gdamore /* l2cap_socket.c */
461 1.7 plunky int l2cap_ctloutput(int, struct socket *, struct sockopt *);
462 1.1 gdamore
463 1.1 gdamore /* l2cap_upper.c */
464 1.13 rmind int l2cap_attach_pcb(struct l2cap_channel **, const struct btproto *, void *);
465 1.1 gdamore int l2cap_bind(struct l2cap_channel *, struct sockaddr_bt *);
466 1.1 gdamore int l2cap_sockaddr(struct l2cap_channel *, struct sockaddr_bt *);
467 1.1 gdamore int l2cap_connect(struct l2cap_channel *, struct sockaddr_bt *);
468 1.1 gdamore int l2cap_peeraddr(struct l2cap_channel *, struct sockaddr_bt *);
469 1.1 gdamore int l2cap_disconnect(struct l2cap_channel *, int);
470 1.13 rmind void l2cap_detach_pcb(struct l2cap_channel **);
471 1.1 gdamore int l2cap_listen(struct l2cap_channel *);
472 1.1 gdamore int l2cap_send(struct l2cap_channel *, struct mbuf *);
473 1.7 plunky int l2cap_setopt(struct l2cap_channel *, const struct sockopt *);
474 1.7 plunky int l2cap_getopt(struct l2cap_channel *, struct sockopt *);
475 1.1 gdamore
476 1.1 gdamore #endif /* _KERNEL */
477 1.1 gdamore
478 1.1 gdamore #endif /* _NETBT_L2CAP_H_ */
479