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