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