• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2000-2001  Qualcomm Incorporated
6  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
7  *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
8  *
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  */
25 
26 #ifndef __L2CAP_H
27 #define __L2CAP_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/socket.h>
34 
35 /* L2CAP defaults */
36 #define L2CAP_DEFAULT_MTU	672
37 #define L2CAP_DEFAULT_FLUSH_TO	0xFFFF
38 
39 /* L2CAP socket address */
40 struct sockaddr_l2 {
41 	sa_family_t	l2_family;
42 	unsigned short	l2_psm;
43 	bdaddr_t	l2_bdaddr;
44 	unsigned short	l2_cid;
45 };
46 
47 /* L2CAP socket options */
48 #define L2CAP_OPTIONS	0x01
49 struct l2cap_options {
50 	uint16_t	omtu;
51 	uint16_t	imtu;
52 	uint16_t	flush_to;
53 	uint8_t		mode;
54 	uint8_t		fcs;
55 	uint8_t		max_tx;
56 	uint16_t	txwin_size;
57 };
58 
59 #define L2CAP_CONNINFO	0x02
60 struct l2cap_conninfo {
61 	uint16_t	hci_handle;
62 	uint8_t		dev_class[3];
63 };
64 
65 #define L2CAP_LM	0x03
66 #define L2CAP_LM_MASTER		0x0001
67 #define L2CAP_LM_AUTH		0x0002
68 #define L2CAP_LM_ENCRYPT	0x0004
69 #define L2CAP_LM_TRUSTED	0x0008
70 #define L2CAP_LM_RELIABLE	0x0010
71 #define L2CAP_LM_SECURE		0x0020
72 #define L2CAP_LM_FLUSHABLE	0x0040
73 
74 /* L2CAP command codes */
75 #define L2CAP_COMMAND_REJ	0x01
76 #define L2CAP_CONN_REQ		0x02
77 #define L2CAP_CONN_RSP		0x03
78 #define L2CAP_CONF_REQ		0x04
79 #define L2CAP_CONF_RSP		0x05
80 #define L2CAP_DISCONN_REQ	0x06
81 #define L2CAP_DISCONN_RSP	0x07
82 #define L2CAP_ECHO_REQ		0x08
83 #define L2CAP_ECHO_RSP		0x09
84 #define L2CAP_INFO_REQ		0x0a
85 #define L2CAP_INFO_RSP		0x0b
86 
87 /* L2CAP structures */
88 typedef struct {
89 	uint16_t	len;
90 	uint16_t	cid;
91 } __attribute__ ((packed)) l2cap_hdr;
92 #define L2CAP_HDR_SIZE 4
93 
94 typedef struct {
95 	uint8_t		code;
96 	uint8_t		ident;
97 	uint16_t	len;
98 } __attribute__ ((packed)) l2cap_cmd_hdr;
99 #define L2CAP_CMD_HDR_SIZE 4
100 
101 typedef struct {
102 	uint16_t	reason;
103 } __attribute__ ((packed)) l2cap_cmd_rej;
104 #define L2CAP_CMD_REJ_SIZE 2
105 
106 typedef struct {
107 	uint16_t	psm;
108 	uint16_t	scid;
109 } __attribute__ ((packed)) l2cap_conn_req;
110 #define L2CAP_CONN_REQ_SIZE 4
111 
112 typedef struct {
113 	uint16_t	dcid;
114 	uint16_t	scid;
115 	uint16_t	result;
116 	uint16_t	status;
117 } __attribute__ ((packed)) l2cap_conn_rsp;
118 #define L2CAP_CONN_RSP_SIZE 8
119 
120 /* connect result */
121 #define L2CAP_CR_SUCCESS	0x0000
122 #define L2CAP_CR_PEND		0x0001
123 #define L2CAP_CR_BAD_PSM	0x0002
124 #define L2CAP_CR_SEC_BLOCK	0x0003
125 #define L2CAP_CR_NO_MEM		0x0004
126 
127 /* connect status */
128 #define L2CAP_CS_NO_INFO	0x0000
129 #define L2CAP_CS_AUTHEN_PEND	0x0001
130 #define L2CAP_CS_AUTHOR_PEND	0x0002
131 
132 typedef struct {
133 	uint16_t	dcid;
134 	uint16_t	flags;
135 	uint8_t		data[0];
136 } __attribute__ ((packed)) l2cap_conf_req;
137 #define L2CAP_CONF_REQ_SIZE 4
138 
139 typedef struct {
140 	uint16_t	scid;
141 	uint16_t	flags;
142 	uint16_t	result;
143 	uint8_t		data[0];
144 } __attribute__ ((packed)) l2cap_conf_rsp;
145 #define L2CAP_CONF_RSP_SIZE 6
146 
147 #define L2CAP_CONF_SUCCESS	0x0000
148 #define L2CAP_CONF_UNACCEPT	0x0001
149 #define L2CAP_CONF_REJECT	0x0002
150 #define L2CAP_CONF_UNKNOWN	0x0003
151 
152 typedef struct {
153 	uint8_t		type;
154 	uint8_t		len;
155 	uint8_t		val[0];
156 } __attribute__ ((packed)) l2cap_conf_opt;
157 #define L2CAP_CONF_OPT_SIZE 2
158 
159 #define L2CAP_CONF_MTU		0x01
160 #define L2CAP_CONF_FLUSH_TO	0x02
161 #define L2CAP_CONF_QOS		0x03
162 #define L2CAP_CONF_RFC		0x04
163 #define L2CAP_CONF_FCS		0x05
164 
165 #define L2CAP_CONF_MAX_SIZE	22
166 
167 #define L2CAP_MODE_BASIC	0x00
168 #define L2CAP_MODE_RETRANS	0x01
169 #define L2CAP_MODE_FLOWCTL	0x02
170 #define L2CAP_MODE_ERTM		0x03
171 #define L2CAP_MODE_STREAMING	0x04
172 
173 typedef struct {
174 	uint16_t	dcid;
175 	uint16_t	scid;
176 } __attribute__ ((packed)) l2cap_disconn_req;
177 #define L2CAP_DISCONN_REQ_SIZE 4
178 
179 typedef struct {
180 	uint16_t	dcid;
181 	uint16_t	scid;
182 } __attribute__ ((packed)) l2cap_disconn_rsp;
183 #define L2CAP_DISCONN_RSP_SIZE 4
184 
185 typedef struct {
186 	uint16_t	type;
187 } __attribute__ ((packed)) l2cap_info_req;
188 #define L2CAP_INFO_REQ_SIZE 2
189 
190 typedef struct {
191 	uint16_t	type;
192 	uint16_t	result;
193 	uint8_t		data[0];
194 } __attribute__ ((packed)) l2cap_info_rsp;
195 #define L2CAP_INFO_RSP_SIZE 4
196 
197 /* info type */
198 #define L2CAP_IT_CL_MTU		0x0001
199 #define L2CAP_IT_FEAT_MASK	0x0002
200 
201 /* info result */
202 #define L2CAP_IR_SUCCESS	0x0000
203 #define L2CAP_IR_NOTSUPP	0x0001
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif /* __L2CAP_H */
210