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