]>
Commit | Line | Data |
---|---|---|
be21871f | 1 | /* |
1da177e4 LT |
2 | BlueZ - Bluetooth protocol stack for Linux |
3 | Copyright (C) 2000-2001 Qualcomm Incorporated | |
ce5706bd | 4 | Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org> |
5d8868ff | 5 | Copyright (C) 2010 Google Inc. |
1da177e4 LT |
6 | |
7 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License version 2 as | |
11 | published by the Free Software Foundation; | |
12 | ||
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
14 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | |
16 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | |
be21871f AE |
17 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
18 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
19 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
1da177e4 LT |
20 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
21 | ||
be21871f AE |
22 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
23 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS | |
1da177e4 LT |
24 | SOFTWARE IS DISCLAIMED. |
25 | */ | |
26 | ||
27 | #ifndef __L2CAP_H | |
28 | #define __L2CAP_H | |
29 | ||
88843ab0 AE |
30 | #include <asm/unaligned.h> |
31 | ||
1da177e4 | 32 | /* L2CAP defaults */ |
47ec1dcd | 33 | #define L2CAP_DEFAULT_MTU 672 |
f2fcfcd6 | 34 | #define L2CAP_DEFAULT_MIN_MTU 48 |
47ec1dcd | 35 | #define L2CAP_DEFAULT_FLUSH_TO 0xffff |
1c2acffb | 36 | #define L2CAP_DEFAULT_TX_WINDOW 63 |
6327eb98 | 37 | #define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF |
e90bac06 | 38 | #define L2CAP_DEFAULT_MAX_TX 3 |
fa235562 | 39 | #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ |
e90bac06 | 40 | #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ |
db12d647 | 41 | #define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */ |
c1b4f43b | 42 | #define L2CAP_DEFAULT_ACK_TO 200 |
b62f328b | 43 | #define L2CAP_LE_DEFAULT_MTU 23 |
8f7975b1 AE |
44 | #define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF |
45 | #define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF | |
46 | #define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF | |
1da177e4 | 47 | |
4e8402a3 MH |
48 | #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ |
49 | #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ | |
1da177e4 LT |
50 | |
51 | /* L2CAP socket address */ | |
52 | struct sockaddr_l2 { | |
53 | sa_family_t l2_family; | |
8e036fc3 | 54 | __le16 l2_psm; |
1da177e4 | 55 | bdaddr_t l2_bdaddr; |
f29972de | 56 | __le16 l2_cid; |
1da177e4 LT |
57 | }; |
58 | ||
59 | /* L2CAP socket options */ | |
60 | #define L2CAP_OPTIONS 0x01 | |
61 | struct l2cap_options { | |
62 | __u16 omtu; | |
63 | __u16 imtu; | |
64 | __u16 flush_to; | |
65 | __u8 mode; | |
fcc203c3 | 66 | __u8 fcs; |
68d7f0ce | 67 | __u8 max_tx; |
14b5aa71 | 68 | __u16 txwin_size; |
1da177e4 LT |
69 | }; |
70 | ||
71 | #define L2CAP_CONNINFO 0x02 | |
72 | struct l2cap_conninfo { | |
73 | __u16 hci_handle; | |
74 | __u8 dev_class[3]; | |
75 | }; | |
76 | ||
77 | #define L2CAP_LM 0x03 | |
78 | #define L2CAP_LM_MASTER 0x0001 | |
79 | #define L2CAP_LM_AUTH 0x0002 | |
80 | #define L2CAP_LM_ENCRYPT 0x0004 | |
81 | #define L2CAP_LM_TRUSTED 0x0008 | |
82 | #define L2CAP_LM_RELIABLE 0x0010 | |
83 | #define L2CAP_LM_SECURE 0x0020 | |
84 | ||
85 | /* L2CAP command codes */ | |
47ec1dcd MH |
86 | #define L2CAP_COMMAND_REJ 0x01 |
87 | #define L2CAP_CONN_REQ 0x02 | |
88 | #define L2CAP_CONN_RSP 0x03 | |
89 | #define L2CAP_CONF_REQ 0x04 | |
90 | #define L2CAP_CONF_RSP 0x05 | |
91 | #define L2CAP_DISCONN_REQ 0x06 | |
92 | #define L2CAP_DISCONN_RSP 0x07 | |
93 | #define L2CAP_ECHO_REQ 0x08 | |
94 | #define L2CAP_ECHO_RSP 0x09 | |
95 | #define L2CAP_INFO_REQ 0x0a | |
96 | #define L2CAP_INFO_RSP 0x0b | |
3300d9a9 CT |
97 | #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 |
98 | #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 | |
47ec1dcd | 99 | |
a858393b | 100 | /* L2CAP extended feature mask */ |
47ec1dcd MH |
101 | #define L2CAP_FEAT_FLOWCTL 0x00000001 |
102 | #define L2CAP_FEAT_RETRANS 0x00000002 | |
a858393b | 103 | #define L2CAP_FEAT_BIDIR_QOS 0x00000004 |
47ec1dcd MH |
104 | #define L2CAP_FEAT_ERTM 0x00000008 |
105 | #define L2CAP_FEAT_STREAMING 0x00000010 | |
106 | #define L2CAP_FEAT_FCS 0x00000020 | |
a858393b | 107 | #define L2CAP_FEAT_EXT_FLOW 0x00000040 |
47ec1dcd | 108 | #define L2CAP_FEAT_FIXED_CHAN 0x00000080 |
a858393b AE |
109 | #define L2CAP_FEAT_EXT_WINDOW 0x00000100 |
110 | #define L2CAP_FEAT_UCD 0x00000200 | |
47ec1dcd MH |
111 | |
112 | /* L2CAP checksum option */ | |
113 | #define L2CAP_FCS_NONE 0x00 | |
114 | #define L2CAP_FCS_CRC16 0x01 | |
1da177e4 | 115 | |
1c2acffb | 116 | /* L2CAP Control Field bit masks */ |
57253fd8 AE |
117 | #define L2CAP_CTRL_SAR 0xC000 |
118 | #define L2CAP_CTRL_REQSEQ 0x3F00 | |
119 | #define L2CAP_CTRL_TXSEQ 0x007E | |
120 | #define L2CAP_CTRL_SUPERVISE 0x000C | |
121 | ||
122 | #define L2CAP_CTRL_RETRANS 0x0080 | |
123 | #define L2CAP_CTRL_FINAL 0x0080 | |
124 | #define L2CAP_CTRL_POLL 0x0010 | |
125 | #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ | |
126 | ||
127 | #define L2CAP_CTRL_TXSEQ_SHIFT 1 | |
128 | #define L2CAP_CTRL_SUPER_SHIFT 2 | |
129 | #define L2CAP_CTRL_REQSEQ_SHIFT 8 | |
130 | #define L2CAP_CTRL_SAR_SHIFT 14 | |
131 | ||
132 | /* L2CAP Extended Control Field bit mask */ | |
133 | #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 | |
134 | #define L2CAP_EXT_CTRL_SAR 0x00030000 | |
135 | #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 | |
136 | #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC | |
137 | ||
138 | #define L2CAP_EXT_CTRL_POLL 0x00040000 | |
139 | #define L2CAP_EXT_CTRL_FINAL 0x00000002 | |
140 | #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ | |
141 | ||
142 | #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 | |
143 | #define L2CAP_EXT_CTRL_SAR_SHIFT 16 | |
144 | #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 | |
145 | #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 | |
1c2acffb GP |
146 | |
147 | /* L2CAP Supervisory Function */ | |
ab784b73 AE |
148 | #define L2CAP_SUPER_RR 0x00 |
149 | #define L2CAP_SUPER_REJ 0x01 | |
150 | #define L2CAP_SUPER_RNR 0x02 | |
151 | #define L2CAP_SUPER_SREJ 0x03 | |
1c2acffb GP |
152 | |
153 | /* L2CAP Segmentation and Reassembly */ | |
7e0ef6ee AE |
154 | #define L2CAP_SAR_UNSEGMENTED 0x00 |
155 | #define L2CAP_SAR_START 0x01 | |
156 | #define L2CAP_SAR_END 0x02 | |
157 | #define L2CAP_SAR_CONTINUE 0x03 | |
1c2acffb | 158 | |
e2fd318e | 159 | /* L2CAP Command rej. reasons */ |
8d6765aa AE |
160 | #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 |
161 | #define L2CAP_REJ_MTU_EXCEEDED 0x0001 | |
162 | #define L2CAP_REJ_INVALID_CID 0x0002 | |
e2fd318e | 163 | |
1da177e4 LT |
164 | /* L2CAP structures */ |
165 | struct l2cap_hdr { | |
8e036fc3 AV |
166 | __le16 len; |
167 | __le16 cid; | |
66c853cc | 168 | } __packed; |
1da177e4 | 169 | #define L2CAP_HDR_SIZE 4 |
d43cb289 AE |
170 | #define L2CAP_ENH_HDR_SIZE 6 |
171 | #define L2CAP_EXT_HDR_SIZE 8 | |
172 | ||
173 | #define L2CAP_FCS_SIZE 2 | |
174 | #define L2CAP_SDULEN_SIZE 2 | |
175 | #define L2CAP_PSMLEN_SIZE 2 | |
1da177e4 LT |
176 | |
177 | struct l2cap_cmd_hdr { | |
178 | __u8 code; | |
179 | __u8 ident; | |
8e036fc3 | 180 | __le16 len; |
66c853cc | 181 | } __packed; |
1da177e4 LT |
182 | #define L2CAP_CMD_HDR_SIZE 4 |
183 | ||
e2fd318e IK |
184 | struct l2cap_cmd_rej_unk { |
185 | __le16 reason; | |
186 | } __packed; | |
187 | ||
188 | struct l2cap_cmd_rej_mtu { | |
8e036fc3 | 189 | __le16 reason; |
e2fd318e IK |
190 | __le16 max_mtu; |
191 | } __packed; | |
192 | ||
193 | struct l2cap_cmd_rej_cid { | |
194 | __le16 reason; | |
195 | __le16 scid; | |
196 | __le16 dcid; | |
66c853cc | 197 | } __packed; |
1da177e4 LT |
198 | |
199 | struct l2cap_conn_req { | |
8e036fc3 AV |
200 | __le16 psm; |
201 | __le16 scid; | |
66c853cc | 202 | } __packed; |
1da177e4 LT |
203 | |
204 | struct l2cap_conn_rsp { | |
8e036fc3 AV |
205 | __le16 dcid; |
206 | __le16 scid; | |
207 | __le16 result; | |
208 | __le16 status; | |
66c853cc | 209 | } __packed; |
1da177e4 | 210 | |
8db4dc46 GP |
211 | /* channel indentifier */ |
212 | #define L2CAP_CID_SIGNALING 0x0001 | |
213 | #define L2CAP_CID_CONN_LESS 0x0002 | |
acd7d370 VT |
214 | #define L2CAP_CID_LE_DATA 0x0004 |
215 | #define L2CAP_CID_LE_SIGNALING 0x0005 | |
216 | #define L2CAP_CID_SMP 0x0006 | |
8db4dc46 GP |
217 | #define L2CAP_CID_DYN_START 0x0040 |
218 | #define L2CAP_CID_DYN_END 0xffff | |
219 | ||
1da177e4 | 220 | /* connect result */ |
47ec1dcd MH |
221 | #define L2CAP_CR_SUCCESS 0x0000 |
222 | #define L2CAP_CR_PEND 0x0001 | |
223 | #define L2CAP_CR_BAD_PSM 0x0002 | |
224 | #define L2CAP_CR_SEC_BLOCK 0x0003 | |
225 | #define L2CAP_CR_NO_MEM 0x0004 | |
1da177e4 LT |
226 | |
227 | /* connect status */ | |
47ec1dcd MH |
228 | #define L2CAP_CS_NO_INFO 0x0000 |
229 | #define L2CAP_CS_AUTHEN_PEND 0x0001 | |
230 | #define L2CAP_CS_AUTHOR_PEND 0x0002 | |
1da177e4 LT |
231 | |
232 | struct l2cap_conf_req { | |
8e036fc3 AV |
233 | __le16 dcid; |
234 | __le16 flags; | |
1da177e4 | 235 | __u8 data[0]; |
66c853cc | 236 | } __packed; |
1da177e4 LT |
237 | |
238 | struct l2cap_conf_rsp { | |
8e036fc3 AV |
239 | __le16 scid; |
240 | __le16 flags; | |
241 | __le16 result; | |
1da177e4 | 242 | __u8 data[0]; |
66c853cc | 243 | } __packed; |
1da177e4 | 244 | |
5dee9e7c MH |
245 | #define L2CAP_CONF_SUCCESS 0x0000 |
246 | #define L2CAP_CONF_UNACCEPT 0x0001 | |
247 | #define L2CAP_CONF_REJECT 0x0002 | |
248 | #define L2CAP_CONF_UNKNOWN 0x0003 | |
0e8b207e | 249 | #define L2CAP_CONF_PENDING 0x0004 |
5a9e7057 | 250 | #define L2CAP_CONF_EFS_REJECT 0x0005 |
1da177e4 LT |
251 | |
252 | struct l2cap_conf_opt { | |
253 | __u8 type; | |
254 | __u8 len; | |
255 | __u8 val[0]; | |
66c853cc | 256 | } __packed; |
1da177e4 LT |
257 | #define L2CAP_CONF_OPT_SIZE 2 |
258 | ||
589d2746 | 259 | #define L2CAP_CONF_HINT 0x80 |
47ec1dcd | 260 | #define L2CAP_CONF_MASK 0x7f |
589d2746 | 261 | |
1da177e4 LT |
262 | #define L2CAP_CONF_MTU 0x01 |
263 | #define L2CAP_CONF_FLUSH_TO 0x02 | |
264 | #define L2CAP_CONF_QOS 0x03 | |
265 | #define L2CAP_CONF_RFC 0x04 | |
47ec1dcd | 266 | #define L2CAP_CONF_FCS 0x05 |
5a9e7057 | 267 | #define L2CAP_CONF_EFS 0x06 |
6327eb98 | 268 | #define L2CAP_CONF_EWS 0x07 |
1da177e4 LT |
269 | |
270 | #define L2CAP_CONF_MAX_SIZE 22 | |
271 | ||
6464f35f MH |
272 | struct l2cap_conf_rfc { |
273 | __u8 mode; | |
274 | __u8 txwin_size; | |
275 | __u8 max_transmit; | |
276 | __le16 retrans_timeout; | |
277 | __le16 monitor_timeout; | |
278 | __le16 max_pdu_size; | |
66c853cc | 279 | } __packed; |
6464f35f MH |
280 | |
281 | #define L2CAP_MODE_BASIC 0x00 | |
282 | #define L2CAP_MODE_RETRANS 0x01 | |
283 | #define L2CAP_MODE_FLOWCTL 0x02 | |
47ec1dcd | 284 | #define L2CAP_MODE_ERTM 0x03 |
c6b03cf9 | 285 | #define L2CAP_MODE_STREAMING 0x04 |
6464f35f | 286 | |
5a9e7057 AE |
287 | struct l2cap_conf_efs { |
288 | __u8 id; | |
289 | __u8 stype; | |
290 | __le16 msdu; | |
291 | __le32 sdu_itime; | |
292 | __le32 acc_lat; | |
293 | __le32 flush_to; | |
294 | } __packed; | |
295 | ||
8f7975b1 AE |
296 | #define L2CAP_SERV_NOTRAFIC 0x00 |
297 | #define L2CAP_SERV_BESTEFFORT 0x01 | |
298 | #define L2CAP_SERV_GUARANTEED 0x02 | |
299 | ||
300 | #define L2CAP_BESTEFFORT_ID 0x01 | |
301 | ||
1da177e4 | 302 | struct l2cap_disconn_req { |
8e036fc3 AV |
303 | __le16 dcid; |
304 | __le16 scid; | |
66c853cc | 305 | } __packed; |
1da177e4 LT |
306 | |
307 | struct l2cap_disconn_rsp { | |
8e036fc3 AV |
308 | __le16 dcid; |
309 | __le16 scid; | |
66c853cc | 310 | } __packed; |
1da177e4 LT |
311 | |
312 | struct l2cap_info_req { | |
8e036fc3 | 313 | __le16 type; |
66c853cc | 314 | } __packed; |
1da177e4 LT |
315 | |
316 | struct l2cap_info_rsp { | |
8e036fc3 AV |
317 | __le16 type; |
318 | __le16 result; | |
1da177e4 | 319 | __u8 data[0]; |
66c853cc | 320 | } __packed; |
1da177e4 LT |
321 | |
322 | /* info type */ | |
8d6765aa AE |
323 | #define L2CAP_IT_CL_MTU 0x0001 |
324 | #define L2CAP_IT_FEAT_MASK 0x0002 | |
325 | #define L2CAP_IT_FIXED_CHAN 0x0003 | |
1da177e4 LT |
326 | |
327 | /* info result */ | |
8d6765aa AE |
328 | #define L2CAP_IR_SUCCESS 0x0000 |
329 | #define L2CAP_IR_NOTSUPP 0x0001 | |
1da177e4 | 330 | |
de73115a CT |
331 | struct l2cap_conn_param_update_req { |
332 | __le16 min; | |
333 | __le16 max; | |
334 | __le16 latency; | |
335 | __le16 to_multiplier; | |
336 | } __packed; | |
337 | ||
338 | struct l2cap_conn_param_update_rsp { | |
339 | __le16 result; | |
340 | } __packed; | |
341 | ||
342 | /* Connection Parameters result */ | |
343 | #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 | |
344 | #define L2CAP_CONN_PARAM_REJECTED 0x0001 | |
345 | ||
48454079 | 346 | /* ----- L2CAP channels and connections ----- */ |
39d5a3ee | 347 | struct srej_list { |
fb45de7d | 348 | __u16 tx_seq; |
39d5a3ee GP |
349 | struct list_head list; |
350 | }; | |
351 | ||
48454079 GP |
352 | struct l2cap_chan { |
353 | struct sock *sk; | |
8c1d787b GP |
354 | |
355 | struct l2cap_conn *conn; | |
356 | ||
89bc500e GP |
357 | __u8 state; |
358 | ||
71ba0e56 GP |
359 | atomic_t refcnt; |
360 | ||
fe4128e0 GP |
361 | __le16 psm; |
362 | __u16 dcid; | |
363 | __u16 scid; | |
4343478f | 364 | |
0c1bc5c6 GP |
365 | __u16 imtu; |
366 | __u16 omtu; | |
367 | __u16 flush_to; | |
368 | __u8 mode; | |
715ec005 | 369 | __u8 chan_type; |
0c1bc5c6 GP |
370 | |
371 | __le16 sport; | |
372 | ||
4343478f | 373 | __u8 sec_level; |
4343478f | 374 | |
fc7f8a7e GP |
375 | __u8 ident; |
376 | ||
73ffa904 GP |
377 | __u8 conf_req[64]; |
378 | __u8 conf_len; | |
379 | __u8 num_conf_req; | |
380 | __u8 num_conf_rsp; | |
381 | ||
47d1ec61 GP |
382 | __u8 fcs; |
383 | ||
6327eb98 | 384 | __u16 tx_win; |
836be934 | 385 | __u16 tx_win_max; |
47d1ec61 GP |
386 | __u8 max_tx; |
387 | __u16 retrans_timeout; | |
388 | __u16 monitor_timeout; | |
389 | __u16 mps; | |
390 | ||
c1360a1c | 391 | unsigned long conf_state; |
e2ab4353 | 392 | unsigned long conn_state; |
d57b0e8b | 393 | unsigned long flags; |
525cd185 | 394 | |
fb45de7d AE |
395 | __u16 next_tx_seq; |
396 | __u16 expected_ack_seq; | |
397 | __u16 expected_tx_seq; | |
0b209fae | 398 | __u16 buffer_seq; |
fb45de7d AE |
399 | __u16 buffer_seq_srej; |
400 | __u16 srej_save_reqseq; | |
401 | __u16 frames_sent; | |
402 | __u16 unacked_frames; | |
6a026610 GP |
403 | __u8 retry_count; |
404 | __u8 num_acked; | |
6f61fd47 | 405 | __u16 sdu_len; |
6f61fd47 | 406 | struct sk_buff *sdu; |
84084a31 | 407 | struct sk_buff *sdu_last_frag; |
6f61fd47 | 408 | |
6327eb98 | 409 | __u16 remote_tx_win; |
2c03a7a4 GP |
410 | __u8 remote_max_tx; |
411 | __u16 remote_mps; | |
42e5c802 | 412 | |
5a9e7057 AE |
413 | __u8 local_id; |
414 | __u8 local_stype; | |
415 | __u16 local_msdu; | |
416 | __u32 local_sdu_itime; | |
417 | __u32 local_acc_lat; | |
418 | __u32 local_flush_to; | |
419 | ||
420 | __u8 remote_id; | |
421 | __u8 remote_stype; | |
422 | __u16 remote_msdu; | |
423 | __u32 remote_sdu_itime; | |
424 | __u32 remote_acc_lat; | |
425 | __u32 remote_flush_to; | |
426 | ||
ab07801d | 427 | struct timer_list chan_timer; |
e92c8e70 GP |
428 | struct timer_list retrans_timer; |
429 | struct timer_list monitor_timer; | |
430 | struct timer_list ack_timer; | |
58d35f87 GP |
431 | struct sk_buff *tx_send_head; |
432 | struct sk_buff_head tx_q; | |
f1c6775b | 433 | struct sk_buff_head srej_q; |
39d5a3ee | 434 | struct list_head srej_l; |
e92c8e70 | 435 | |
baa7e1fa | 436 | struct list_head list; |
23691d75 | 437 | struct list_head global_l; |
80808e43 GP |
438 | |
439 | void *data; | |
440 | struct l2cap_ops *ops; | |
441 | }; | |
442 | ||
443 | struct l2cap_ops { | |
444 | char *name; | |
445 | ||
446 | struct l2cap_chan *(*new_connection) (void *data); | |
23070494 | 447 | int (*recv) (void *data, struct sk_buff *skb); |
ba3bd0ee | 448 | void (*close) (void *data); |
89bc500e | 449 | void (*state_change) (void *data, int state); |
1da177e4 LT |
450 | }; |
451 | ||
452 | struct l2cap_conn { | |
453 | struct hci_conn *hcon; | |
454 | ||
455 | bdaddr_t *dst; | |
456 | bdaddr_t *src; | |
457 | ||
458 | unsigned int mtu; | |
459 | ||
4e8402a3 MH |
460 | __u32 feat_mask; |
461 | ||
462 | __u8 info_state; | |
463 | __u8 info_ident; | |
464 | ||
465 | struct timer_list info_timer; | |
466 | ||
1da177e4 LT |
467 | spinlock_t lock; |
468 | ||
469 | struct sk_buff *rx_skb; | |
470 | __u32 rx_len; | |
1da177e4 LT |
471 | __u8 tx_ident; |
472 | ||
2950f21a MH |
473 | __u8 disc_reason; |
474 | ||
5d3de7df | 475 | struct timer_list security_timer; |
1c1def09 | 476 | struct smp_chan *smp_chan; |
5d3de7df | 477 | |
baa7e1fa GP |
478 | struct list_head chan_l; |
479 | rwlock_t chan_lock; | |
1da177e4 LT |
480 | }; |
481 | ||
4e8402a3 | 482 | #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 |
984947dc MH |
483 | #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 |
484 | #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 | |
4e8402a3 | 485 | |
715ec005 GP |
486 | #define L2CAP_CHAN_RAW 1 |
487 | #define L2CAP_CHAN_CONN_LESS 2 | |
488 | #define L2CAP_CHAN_CONN_ORIENTED 3 | |
489 | ||
48454079 | 490 | /* ----- L2CAP socket info ----- */ |
1da177e4 LT |
491 | #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) |
492 | ||
493 | struct l2cap_pinfo { | |
494 | struct bt_sock bt; | |
48454079 | 495 | struct l2cap_chan *chan; |
e328140f | 496 | struct sk_buff *rx_busy_skb; |
1da177e4 LT |
497 | }; |
498 | ||
c1360a1c GP |
499 | enum { |
500 | CONF_REQ_SENT, | |
501 | CONF_INPUT_DONE, | |
502 | CONF_OUTPUT_DONE, | |
503 | CONF_MTU_DONE, | |
504 | CONF_MODE_DONE, | |
505 | CONF_CONNECT_PEND, | |
506 | CONF_NO_FCS_RECV, | |
507 | CONF_STATE2_DEVICE, | |
6327eb98 | 508 | CONF_EWS_RECV, |
0e8b207e AE |
509 | CONF_LOC_CONF_PEND, |
510 | CONF_REM_CONF_PEND, | |
c1360a1c | 511 | }; |
f2fcfcd6 GP |
512 | |
513 | #define L2CAP_CONF_MAX_CONF_REQ 2 | |
514 | #define L2CAP_CONF_MAX_CONF_RSP 2 | |
861d6882 | 515 | |
e2ab4353 | 516 | enum { |
e2ab4353 GP |
517 | CONN_SREJ_SENT, |
518 | CONN_WAIT_F, | |
519 | CONN_SREJ_ACT, | |
520 | CONN_SEND_PBIT, | |
521 | CONN_REMOTE_BUSY, | |
522 | CONN_LOCAL_BUSY, | |
523 | CONN_REJ_ACT, | |
524 | CONN_SEND_FBIT, | |
525 | CONN_RNR_SENT, | |
e2ab4353 | 526 | }; |
e90bac06 | 527 | |
d57b0e8b AE |
528 | /* Definitions for flags in l2cap_chan */ |
529 | enum { | |
43bd0f32 | 530 | FLAG_ROLE_SWITCH, |
15770b1a | 531 | FLAG_FORCE_ACTIVE, |
ecf61bdb | 532 | FLAG_FORCE_RELIABLE, |
d57b0e8b | 533 | FLAG_FLUSHABLE, |
6327eb98 | 534 | FLAG_EXT_CTRL, |
5a9e7057 | 535 | FLAG_EFS_ENABLE, |
d57b0e8b AE |
536 | }; |
537 | ||
c9b66675 GP |
538 | #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) |
539 | #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) | |
1a09bcb9 GP |
540 | #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \ |
541 | L2CAP_DEFAULT_RETRANS_TO); | |
542 | #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) | |
543 | #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \ | |
544 | L2CAP_DEFAULT_MONITOR_TO); | |
545 | #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) | |
546 | #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ | |
547 | L2CAP_DEFAULT_ACK_TO); | |
548 | #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) | |
c74e560c | 549 | |
836be934 AE |
550 | static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) |
551 | { | |
552 | int offset; | |
553 | ||
554 | offset = (seq1 - seq2) % (chan->tx_win_max + 1); | |
555 | if (offset < 0) | |
556 | offset += (chan->tx_win_max + 1); | |
557 | ||
558 | return offset; | |
559 | } | |
560 | ||
561 | static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) | |
562 | { | |
563 | return (seq + 1) % (chan->tx_win_max + 1); | |
564 | } | |
565 | ||
42e5c802 | 566 | static inline int l2cap_tx_window_full(struct l2cap_chan *ch) |
1c2acffb | 567 | { |
1c2acffb GP |
568 | int sub; |
569 | ||
42e5c802 | 570 | sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; |
1c2acffb GP |
571 | |
572 | if (sub < 0) | |
573 | sub += 64; | |
574 | ||
2c03a7a4 | 575 | return sub == ch->remote_tx_win; |
1c2acffb GP |
576 | } |
577 | ||
0b209fae AE |
578 | static inline __u16 __get_reqseq(struct l2cap_chan *chan, __u32 ctrl) |
579 | { | |
580 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
581 | return (ctrl & L2CAP_EXT_CTRL_REQSEQ) >> | |
582 | L2CAP_EXT_CTRL_REQSEQ_SHIFT; | |
583 | else | |
584 | return (ctrl & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT; | |
585 | } | |
586 | ||
587 | static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq) | |
588 | { | |
589 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
590 | return (reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT) & | |
591 | L2CAP_EXT_CTRL_REQSEQ; | |
592 | else | |
593 | return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ; | |
594 | } | |
fb45de7d AE |
595 | |
596 | static inline __u16 __get_txseq(struct l2cap_chan *chan, __u32 ctrl) | |
597 | { | |
598 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
599 | return (ctrl & L2CAP_EXT_CTRL_TXSEQ) >> | |
600 | L2CAP_EXT_CTRL_TXSEQ_SHIFT; | |
601 | else | |
602 | return (ctrl & L2CAP_CTRL_TXSEQ) >> L2CAP_CTRL_TXSEQ_SHIFT; | |
603 | } | |
604 | ||
605 | static inline __u32 __set_txseq(struct l2cap_chan *chan, __u32 txseq) | |
606 | { | |
607 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
608 | return (txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT) & | |
609 | L2CAP_EXT_CTRL_TXSEQ; | |
610 | else | |
611 | return (txseq << L2CAP_CTRL_TXSEQ_SHIFT) & L2CAP_CTRL_TXSEQ; | |
612 | } | |
613 | ||
793c2f1c AE |
614 | static inline bool __is_sframe(struct l2cap_chan *chan, __u32 ctrl) |
615 | { | |
616 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
617 | return ctrl & L2CAP_EXT_CTRL_FRAME_TYPE; | |
618 | else | |
619 | return ctrl & L2CAP_CTRL_FRAME_TYPE; | |
620 | } | |
621 | ||
622 | static inline __u32 __set_sframe(struct l2cap_chan *chan) | |
623 | { | |
624 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
625 | return L2CAP_EXT_CTRL_FRAME_TYPE; | |
626 | else | |
627 | return L2CAP_CTRL_FRAME_TYPE; | |
628 | } | |
629 | ||
7e0ef6ee AE |
630 | static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl) |
631 | { | |
632 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
633 | return (ctrl & L2CAP_EXT_CTRL_SAR) >> L2CAP_EXT_CTRL_SAR_SHIFT; | |
634 | else | |
635 | return (ctrl & L2CAP_CTRL_SAR) >> L2CAP_CTRL_SAR_SHIFT; | |
636 | } | |
637 | ||
638 | static inline __u32 __set_ctrl_sar(struct l2cap_chan *chan, __u32 sar) | |
639 | { | |
640 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
641 | return (sar << L2CAP_EXT_CTRL_SAR_SHIFT) & L2CAP_EXT_CTRL_SAR; | |
642 | else | |
643 | return (sar << L2CAP_CTRL_SAR_SHIFT) & L2CAP_CTRL_SAR; | |
644 | } | |
645 | ||
646 | static inline bool __is_sar_start(struct l2cap_chan *chan, __u32 ctrl) | |
647 | { | |
648 | return __get_ctrl_sar(chan, ctrl) == L2CAP_SAR_START; | |
649 | } | |
650 | ||
651 | static inline __u32 __get_sar_mask(struct l2cap_chan *chan) | |
652 | { | |
653 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
654 | return L2CAP_EXT_CTRL_SAR; | |
655 | else | |
656 | return L2CAP_CTRL_SAR; | |
657 | } | |
1da177e4 | 658 | |
ab784b73 AE |
659 | static inline __u8 __get_ctrl_super(struct l2cap_chan *chan, __u32 ctrl) |
660 | { | |
661 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
662 | return (ctrl & L2CAP_EXT_CTRL_SUPERVISE) >> | |
663 | L2CAP_EXT_CTRL_SUPER_SHIFT; | |
664 | else | |
665 | return (ctrl & L2CAP_CTRL_SUPERVISE) >> L2CAP_CTRL_SUPER_SHIFT; | |
666 | } | |
667 | ||
668 | static inline __u32 __set_ctrl_super(struct l2cap_chan *chan, __u32 super) | |
669 | { | |
670 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
671 | return (super << L2CAP_EXT_CTRL_SUPER_SHIFT) & | |
672 | L2CAP_EXT_CTRL_SUPERVISE; | |
673 | else | |
674 | return (super << L2CAP_CTRL_SUPER_SHIFT) & | |
675 | L2CAP_CTRL_SUPERVISE; | |
676 | } | |
677 | ||
03f6715d AE |
678 | static inline __u32 __set_ctrl_final(struct l2cap_chan *chan) |
679 | { | |
680 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
681 | return L2CAP_EXT_CTRL_FINAL; | |
682 | else | |
683 | return L2CAP_CTRL_FINAL; | |
684 | } | |
685 | ||
686 | static inline bool __is_ctrl_final(struct l2cap_chan *chan, __u32 ctrl) | |
687 | { | |
688 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
689 | return ctrl & L2CAP_EXT_CTRL_FINAL; | |
690 | else | |
691 | return ctrl & L2CAP_CTRL_FINAL; | |
692 | } | |
e3781735 AE |
693 | |
694 | static inline __u32 __set_ctrl_poll(struct l2cap_chan *chan) | |
695 | { | |
696 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
697 | return L2CAP_EXT_CTRL_POLL; | |
698 | else | |
699 | return L2CAP_CTRL_POLL; | |
700 | } | |
701 | ||
702 | static inline bool __is_ctrl_poll(struct l2cap_chan *chan, __u32 ctrl) | |
703 | { | |
704 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
705 | return ctrl & L2CAP_EXT_CTRL_POLL; | |
706 | else | |
707 | return ctrl & L2CAP_CTRL_POLL; | |
708 | } | |
88843ab0 AE |
709 | |
710 | static inline __u32 __get_control(struct l2cap_chan *chan, void *p) | |
711 | { | |
712 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
713 | return get_unaligned_le32(p); | |
714 | else | |
715 | return get_unaligned_le16(p); | |
716 | } | |
717 | ||
718 | static inline void __put_control(struct l2cap_chan *chan, __u32 control, | |
719 | void *p) | |
720 | { | |
721 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
722 | return put_unaligned_le32(control, p); | |
723 | else | |
724 | return put_unaligned_le16(control, p); | |
725 | } | |
726 | ||
727 | static inline __u8 __ctrl_size(struct l2cap_chan *chan) | |
728 | { | |
729 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
730 | return L2CAP_EXT_HDR_SIZE - L2CAP_HDR_SIZE; | |
731 | else | |
732 | return L2CAP_ENH_HDR_SIZE - L2CAP_HDR_SIZE; | |
733 | } | |
734 | ||
bb58f747 | 735 | extern int disable_ertm; |
bb58f747 GP |
736 | |
737 | int l2cap_init_sockets(void); | |
738 | void l2cap_cleanup_sockets(void); | |
739 | ||
8c1d787b | 740 | void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); |
dcba0dba | 741 | int __l2cap_wait_ack(struct sock *sk); |
68983259 | 742 | |
9e4425ff GP |
743 | int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); |
744 | int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); | |
745 | ||
23691d75 | 746 | struct l2cap_chan *l2cap_chan_create(struct sock *sk); |
0f852724 | 747 | void l2cap_chan_close(struct l2cap_chan *chan, int reason); |
23691d75 | 748 | void l2cap_chan_destroy(struct l2cap_chan *chan); |
77a74c7e | 749 | int l2cap_chan_connect(struct l2cap_chan *chan); |
9a91a04a | 750 | int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); |
e328140f | 751 | void l2cap_chan_busy(struct l2cap_chan *chan, int busy); |
bb58f747 | 752 | |
1da177e4 | 753 | #endif /* __L2CAP_H */ |