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; |
2ea66482 | 370 | __u8 chan_policy; |
0c1bc5c6 GP |
371 | |
372 | __le16 sport; | |
373 | ||
4343478f | 374 | __u8 sec_level; |
4343478f | 375 | |
fc7f8a7e GP |
376 | __u8 ident; |
377 | ||
73ffa904 GP |
378 | __u8 conf_req[64]; |
379 | __u8 conf_len; | |
380 | __u8 num_conf_req; | |
381 | __u8 num_conf_rsp; | |
382 | ||
47d1ec61 GP |
383 | __u8 fcs; |
384 | ||
6327eb98 | 385 | __u16 tx_win; |
836be934 | 386 | __u16 tx_win_max; |
47d1ec61 GP |
387 | __u8 max_tx; |
388 | __u16 retrans_timeout; | |
389 | __u16 monitor_timeout; | |
390 | __u16 mps; | |
391 | ||
c1360a1c | 392 | unsigned long conf_state; |
e2ab4353 | 393 | unsigned long conn_state; |
d57b0e8b | 394 | unsigned long flags; |
525cd185 | 395 | |
fb45de7d AE |
396 | __u16 next_tx_seq; |
397 | __u16 expected_ack_seq; | |
398 | __u16 expected_tx_seq; | |
0b209fae | 399 | __u16 buffer_seq; |
fb45de7d AE |
400 | __u16 buffer_seq_srej; |
401 | __u16 srej_save_reqseq; | |
402 | __u16 frames_sent; | |
403 | __u16 unacked_frames; | |
6a026610 GP |
404 | __u8 retry_count; |
405 | __u8 num_acked; | |
6f61fd47 | 406 | __u16 sdu_len; |
6f61fd47 | 407 | struct sk_buff *sdu; |
84084a31 | 408 | struct sk_buff *sdu_last_frag; |
6f61fd47 | 409 | |
6327eb98 | 410 | __u16 remote_tx_win; |
2c03a7a4 GP |
411 | __u8 remote_max_tx; |
412 | __u16 remote_mps; | |
42e5c802 | 413 | |
5a9e7057 AE |
414 | __u8 local_id; |
415 | __u8 local_stype; | |
416 | __u16 local_msdu; | |
417 | __u32 local_sdu_itime; | |
418 | __u32 local_acc_lat; | |
419 | __u32 local_flush_to; | |
420 | ||
421 | __u8 remote_id; | |
422 | __u8 remote_stype; | |
423 | __u16 remote_msdu; | |
424 | __u32 remote_sdu_itime; | |
425 | __u32 remote_acc_lat; | |
426 | __u32 remote_flush_to; | |
427 | ||
ab07801d | 428 | struct timer_list chan_timer; |
e92c8e70 GP |
429 | struct timer_list retrans_timer; |
430 | struct timer_list monitor_timer; | |
431 | struct timer_list ack_timer; | |
58d35f87 GP |
432 | struct sk_buff *tx_send_head; |
433 | struct sk_buff_head tx_q; | |
f1c6775b | 434 | struct sk_buff_head srej_q; |
39d5a3ee | 435 | struct list_head srej_l; |
e92c8e70 | 436 | |
baa7e1fa | 437 | struct list_head list; |
23691d75 | 438 | struct list_head global_l; |
80808e43 GP |
439 | |
440 | void *data; | |
441 | struct l2cap_ops *ops; | |
442 | }; | |
443 | ||
444 | struct l2cap_ops { | |
445 | char *name; | |
446 | ||
447 | struct l2cap_chan *(*new_connection) (void *data); | |
23070494 | 448 | int (*recv) (void *data, struct sk_buff *skb); |
ba3bd0ee | 449 | void (*close) (void *data); |
89bc500e | 450 | void (*state_change) (void *data, int state); |
1da177e4 LT |
451 | }; |
452 | ||
453 | struct l2cap_conn { | |
454 | struct hci_conn *hcon; | |
73d80deb | 455 | struct hci_chan *hchan; |
1da177e4 LT |
456 | |
457 | bdaddr_t *dst; | |
458 | bdaddr_t *src; | |
459 | ||
460 | unsigned int mtu; | |
461 | ||
4e8402a3 MH |
462 | __u32 feat_mask; |
463 | ||
464 | __u8 info_state; | |
465 | __u8 info_ident; | |
466 | ||
467 | struct timer_list info_timer; | |
468 | ||
1da177e4 LT |
469 | spinlock_t lock; |
470 | ||
471 | struct sk_buff *rx_skb; | |
472 | __u32 rx_len; | |
1da177e4 LT |
473 | __u8 tx_ident; |
474 | ||
2950f21a MH |
475 | __u8 disc_reason; |
476 | ||
5d3de7df | 477 | struct timer_list security_timer; |
1c1def09 | 478 | struct smp_chan *smp_chan; |
5d3de7df | 479 | |
baa7e1fa GP |
480 | struct list_head chan_l; |
481 | rwlock_t chan_lock; | |
1da177e4 LT |
482 | }; |
483 | ||
4e8402a3 | 484 | #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 |
984947dc MH |
485 | #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 |
486 | #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 | |
4e8402a3 | 487 | |
715ec005 GP |
488 | #define L2CAP_CHAN_RAW 1 |
489 | #define L2CAP_CHAN_CONN_LESS 2 | |
490 | #define L2CAP_CHAN_CONN_ORIENTED 3 | |
491 | ||
48454079 | 492 | /* ----- L2CAP socket info ----- */ |
1da177e4 LT |
493 | #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) |
494 | ||
495 | struct l2cap_pinfo { | |
496 | struct bt_sock bt; | |
48454079 | 497 | struct l2cap_chan *chan; |
e328140f | 498 | struct sk_buff *rx_busy_skb; |
1da177e4 LT |
499 | }; |
500 | ||
c1360a1c GP |
501 | enum { |
502 | CONF_REQ_SENT, | |
503 | CONF_INPUT_DONE, | |
504 | CONF_OUTPUT_DONE, | |
505 | CONF_MTU_DONE, | |
506 | CONF_MODE_DONE, | |
507 | CONF_CONNECT_PEND, | |
508 | CONF_NO_FCS_RECV, | |
509 | CONF_STATE2_DEVICE, | |
6327eb98 | 510 | CONF_EWS_RECV, |
0e8b207e AE |
511 | CONF_LOC_CONF_PEND, |
512 | CONF_REM_CONF_PEND, | |
c1360a1c | 513 | }; |
f2fcfcd6 GP |
514 | |
515 | #define L2CAP_CONF_MAX_CONF_REQ 2 | |
516 | #define L2CAP_CONF_MAX_CONF_RSP 2 | |
861d6882 | 517 | |
e2ab4353 | 518 | enum { |
e2ab4353 GP |
519 | CONN_SREJ_SENT, |
520 | CONN_WAIT_F, | |
521 | CONN_SREJ_ACT, | |
522 | CONN_SEND_PBIT, | |
523 | CONN_REMOTE_BUSY, | |
524 | CONN_LOCAL_BUSY, | |
525 | CONN_REJ_ACT, | |
526 | CONN_SEND_FBIT, | |
527 | CONN_RNR_SENT, | |
e2ab4353 | 528 | }; |
e90bac06 | 529 | |
d57b0e8b AE |
530 | /* Definitions for flags in l2cap_chan */ |
531 | enum { | |
43bd0f32 | 532 | FLAG_ROLE_SWITCH, |
15770b1a | 533 | FLAG_FORCE_ACTIVE, |
ecf61bdb | 534 | FLAG_FORCE_RELIABLE, |
d57b0e8b | 535 | FLAG_FLUSHABLE, |
6327eb98 | 536 | FLAG_EXT_CTRL, |
5a9e7057 | 537 | FLAG_EFS_ENABLE, |
d57b0e8b AE |
538 | }; |
539 | ||
c9b66675 GP |
540 | #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) |
541 | #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) | |
1a09bcb9 GP |
542 | #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \ |
543 | L2CAP_DEFAULT_RETRANS_TO); | |
544 | #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) | |
545 | #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \ | |
546 | L2CAP_DEFAULT_MONITOR_TO); | |
547 | #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) | |
548 | #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ | |
549 | L2CAP_DEFAULT_ACK_TO); | |
550 | #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) | |
c74e560c | 551 | |
836be934 AE |
552 | static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) |
553 | { | |
554 | int offset; | |
555 | ||
556 | offset = (seq1 - seq2) % (chan->tx_win_max + 1); | |
557 | if (offset < 0) | |
558 | offset += (chan->tx_win_max + 1); | |
559 | ||
560 | return offset; | |
561 | } | |
562 | ||
563 | static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) | |
564 | { | |
565 | return (seq + 1) % (chan->tx_win_max + 1); | |
566 | } | |
567 | ||
42e5c802 | 568 | static inline int l2cap_tx_window_full(struct l2cap_chan *ch) |
1c2acffb | 569 | { |
1c2acffb GP |
570 | int sub; |
571 | ||
42e5c802 | 572 | sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; |
1c2acffb GP |
573 | |
574 | if (sub < 0) | |
575 | sub += 64; | |
576 | ||
2c03a7a4 | 577 | return sub == ch->remote_tx_win; |
1c2acffb GP |
578 | } |
579 | ||
0b209fae AE |
580 | static inline __u16 __get_reqseq(struct l2cap_chan *chan, __u32 ctrl) |
581 | { | |
582 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
583 | return (ctrl & L2CAP_EXT_CTRL_REQSEQ) >> | |
584 | L2CAP_EXT_CTRL_REQSEQ_SHIFT; | |
585 | else | |
586 | return (ctrl & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT; | |
587 | } | |
588 | ||
589 | static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq) | |
590 | { | |
591 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
592 | return (reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT) & | |
593 | L2CAP_EXT_CTRL_REQSEQ; | |
594 | else | |
595 | return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ; | |
596 | } | |
fb45de7d AE |
597 | |
598 | static inline __u16 __get_txseq(struct l2cap_chan *chan, __u32 ctrl) | |
599 | { | |
600 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
601 | return (ctrl & L2CAP_EXT_CTRL_TXSEQ) >> | |
602 | L2CAP_EXT_CTRL_TXSEQ_SHIFT; | |
603 | else | |
604 | return (ctrl & L2CAP_CTRL_TXSEQ) >> L2CAP_CTRL_TXSEQ_SHIFT; | |
605 | } | |
606 | ||
607 | static inline __u32 __set_txseq(struct l2cap_chan *chan, __u32 txseq) | |
608 | { | |
609 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
610 | return (txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT) & | |
611 | L2CAP_EXT_CTRL_TXSEQ; | |
612 | else | |
613 | return (txseq << L2CAP_CTRL_TXSEQ_SHIFT) & L2CAP_CTRL_TXSEQ; | |
614 | } | |
615 | ||
793c2f1c AE |
616 | static inline bool __is_sframe(struct l2cap_chan *chan, __u32 ctrl) |
617 | { | |
618 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
619 | return ctrl & L2CAP_EXT_CTRL_FRAME_TYPE; | |
620 | else | |
621 | return ctrl & L2CAP_CTRL_FRAME_TYPE; | |
622 | } | |
623 | ||
624 | static inline __u32 __set_sframe(struct l2cap_chan *chan) | |
625 | { | |
626 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
627 | return L2CAP_EXT_CTRL_FRAME_TYPE; | |
628 | else | |
629 | return L2CAP_CTRL_FRAME_TYPE; | |
630 | } | |
631 | ||
7e0ef6ee AE |
632 | static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl) |
633 | { | |
634 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
635 | return (ctrl & L2CAP_EXT_CTRL_SAR) >> L2CAP_EXT_CTRL_SAR_SHIFT; | |
636 | else | |
637 | return (ctrl & L2CAP_CTRL_SAR) >> L2CAP_CTRL_SAR_SHIFT; | |
638 | } | |
639 | ||
640 | static inline __u32 __set_ctrl_sar(struct l2cap_chan *chan, __u32 sar) | |
641 | { | |
642 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
643 | return (sar << L2CAP_EXT_CTRL_SAR_SHIFT) & L2CAP_EXT_CTRL_SAR; | |
644 | else | |
645 | return (sar << L2CAP_CTRL_SAR_SHIFT) & L2CAP_CTRL_SAR; | |
646 | } | |
647 | ||
648 | static inline bool __is_sar_start(struct l2cap_chan *chan, __u32 ctrl) | |
649 | { | |
650 | return __get_ctrl_sar(chan, ctrl) == L2CAP_SAR_START; | |
651 | } | |
652 | ||
653 | static inline __u32 __get_sar_mask(struct l2cap_chan *chan) | |
654 | { | |
655 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
656 | return L2CAP_EXT_CTRL_SAR; | |
657 | else | |
658 | return L2CAP_CTRL_SAR; | |
659 | } | |
1da177e4 | 660 | |
ab784b73 AE |
661 | static inline __u8 __get_ctrl_super(struct l2cap_chan *chan, __u32 ctrl) |
662 | { | |
663 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
664 | return (ctrl & L2CAP_EXT_CTRL_SUPERVISE) >> | |
665 | L2CAP_EXT_CTRL_SUPER_SHIFT; | |
666 | else | |
667 | return (ctrl & L2CAP_CTRL_SUPERVISE) >> L2CAP_CTRL_SUPER_SHIFT; | |
668 | } | |
669 | ||
670 | static inline __u32 __set_ctrl_super(struct l2cap_chan *chan, __u32 super) | |
671 | { | |
672 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
673 | return (super << L2CAP_EXT_CTRL_SUPER_SHIFT) & | |
674 | L2CAP_EXT_CTRL_SUPERVISE; | |
675 | else | |
676 | return (super << L2CAP_CTRL_SUPER_SHIFT) & | |
677 | L2CAP_CTRL_SUPERVISE; | |
678 | } | |
679 | ||
03f6715d AE |
680 | static inline __u32 __set_ctrl_final(struct l2cap_chan *chan) |
681 | { | |
682 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
683 | return L2CAP_EXT_CTRL_FINAL; | |
684 | else | |
685 | return L2CAP_CTRL_FINAL; | |
686 | } | |
687 | ||
688 | static inline bool __is_ctrl_final(struct l2cap_chan *chan, __u32 ctrl) | |
689 | { | |
690 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
691 | return ctrl & L2CAP_EXT_CTRL_FINAL; | |
692 | else | |
693 | return ctrl & L2CAP_CTRL_FINAL; | |
694 | } | |
e3781735 AE |
695 | |
696 | static inline __u32 __set_ctrl_poll(struct l2cap_chan *chan) | |
697 | { | |
698 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
699 | return L2CAP_EXT_CTRL_POLL; | |
700 | else | |
701 | return L2CAP_CTRL_POLL; | |
702 | } | |
703 | ||
704 | static inline bool __is_ctrl_poll(struct l2cap_chan *chan, __u32 ctrl) | |
705 | { | |
706 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
707 | return ctrl & L2CAP_EXT_CTRL_POLL; | |
708 | else | |
709 | return ctrl & L2CAP_CTRL_POLL; | |
710 | } | |
88843ab0 AE |
711 | |
712 | static inline __u32 __get_control(struct l2cap_chan *chan, void *p) | |
713 | { | |
714 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
715 | return get_unaligned_le32(p); | |
716 | else | |
717 | return get_unaligned_le16(p); | |
718 | } | |
719 | ||
720 | static inline void __put_control(struct l2cap_chan *chan, __u32 control, | |
721 | void *p) | |
722 | { | |
723 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
724 | return put_unaligned_le32(control, p); | |
725 | else | |
726 | return put_unaligned_le16(control, p); | |
727 | } | |
728 | ||
729 | static inline __u8 __ctrl_size(struct l2cap_chan *chan) | |
730 | { | |
731 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | |
732 | return L2CAP_EXT_HDR_SIZE - L2CAP_HDR_SIZE; | |
733 | else | |
734 | return L2CAP_ENH_HDR_SIZE - L2CAP_HDR_SIZE; | |
735 | } | |
736 | ||
bb58f747 | 737 | extern int disable_ertm; |
d7c4d11c | 738 | extern int enable_hs; |
bb58f747 GP |
739 | |
740 | int l2cap_init_sockets(void); | |
741 | void l2cap_cleanup_sockets(void); | |
742 | ||
8c1d787b | 743 | void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); |
dcba0dba | 744 | int __l2cap_wait_ack(struct sock *sk); |
68983259 | 745 | |
9e4425ff GP |
746 | int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); |
747 | int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); | |
748 | ||
23691d75 | 749 | struct l2cap_chan *l2cap_chan_create(struct sock *sk); |
0f852724 | 750 | void l2cap_chan_close(struct l2cap_chan *chan, int reason); |
23691d75 | 751 | void l2cap_chan_destroy(struct l2cap_chan *chan); |
77a74c7e | 752 | int l2cap_chan_connect(struct l2cap_chan *chan); |
5e59b791 LAD |
753 | int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, |
754 | u32 priority); | |
e328140f | 755 | void l2cap_chan_busy(struct l2cap_chan *chan, int busy); |
bb58f747 | 756 | |
1da177e4 | 757 | #endif /* __L2CAP_H */ |