blob: be2147eff8ca81019fb0713763b87449b9bfb1de [file] [log] [blame]
Andrei Emeltchenkobe218712010-12-01 16:58:26 +02001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 BlueZ - Bluetooth protocol stack for Linux
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 Copyright (c) 2000-2001, 2010-2011 Code Aurora Forum. All rights reserved.
Gustavo F. Padovance5706b2010-07-13 11:57:11 -03004 Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org>
Gustavo F. Padovan5d8868f2010-07-16 16:18:39 -03005 Copyright (C) 2010 Google Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
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
Andrei Emeltchenkobe218712010-12-01 16:58:26 +020017 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
Andrei Emeltchenkobe218712010-12-01 16:58:26 +020022 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 SOFTWARE IS DISCLAIMED.
25*/
26
27#ifndef __L2CAP_H
28#define __L2CAP_H
29
30/* L2CAP defaults */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -070031#define L2CAP_DEFAULT_MTU 672
Gustavo F. Padovanf2fcfcd2009-07-04 15:06:24 -030032#define L2CAP_DEFAULT_MIN_MTU 48
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033#define L2CAP_DEFAULT_MAX_SDU_SIZE 0xffff
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -070034#define L2CAP_DEFAULT_FLUSH_TO 0xffff
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -030035#define L2CAP_DEFAULT_TX_WINDOW 63
Gustavo F. Padovane90bac02009-08-20 22:26:00 -030036#define L2CAP_DEFAULT_MAX_TX 3
Mat Martineaufa235562010-08-05 15:54:20 -070037#define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */
Gustavo F. Padovane90bac02009-08-20 22:26:00 -030038#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039#define L2CAP_DEFAULT_MAX_PDU_SIZE 1482 /* Sized for AMP or BR/EDR */
Gustavo F. Padovanc1b4f432010-05-01 16:15:39 -030040#define L2CAP_DEFAULT_ACK_TO 200
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */
42#define L2CAP_MAX_ERTM_QUEUED 5
43#define L2CAP_MIN_ERTM_QUEUED 2
44
45#define L2CAP_A2MP_DEFAULT_MTU 670
46
47#define L2CAP_TX_WIN_MAX_ENHANCED 0x3f
48#define L2CAP_TX_WIN_MAX_EXTENDED 0x3fff
Ville Tervob62f3282011-02-10 22:38:50 -030049#define L2CAP_LE_DEFAULT_MTU 23
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Marcel Holtmann4e8402a2007-10-20 13:37:56 +020051#define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */
52#define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053#define L2CAP_MOVE_TIMEOUT (2*HZ) /* 2 seconds */
54#define L2CAP_MOVE_ERTX_TIMEOUT (60*HZ) /* 60 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/* L2CAP socket address */
57struct sockaddr_l2 {
58 sa_family_t l2_family;
Al Viro8e036fc2007-07-29 00:16:36 -070059 __le16 l2_psm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 bdaddr_t l2_bdaddr;
Marcel Holtmannf29972d2009-02-12 05:07:45 +010061 __le16 l2_cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64/* L2CAP socket options */
65#define L2CAP_OPTIONS 0x01
66struct l2cap_options {
67 __u16 omtu;
68 __u16 imtu;
69 __u16 flush_to;
70 __u8 mode;
Gustavo F. Padovanfcc203c2009-08-20 22:26:02 -030071 __u8 fcs;
Gustavo F. Padovan68d7f0c2010-05-01 16:15:41 -030072 __u8 max_tx;
Gustavo F. Padovan14b5aa72010-05-01 16:15:40 -030073 __u16 txwin_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
76#define L2CAP_CONNINFO 0x02
77struct l2cap_conninfo {
78 __u16 hci_handle;
79 __u8 dev_class[3];
80};
81
82#define L2CAP_LM 0x03
83#define L2CAP_LM_MASTER 0x0001
84#define L2CAP_LM_AUTH 0x0002
85#define L2CAP_LM_ENCRYPT 0x0004
86#define L2CAP_LM_TRUSTED 0x0008
87#define L2CAP_LM_RELIABLE 0x0010
88#define L2CAP_LM_SECURE 0x0020
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089#define L2CAP_LM_FLUSHABLE 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/* L2CAP command codes */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092#define L2CAP_COMMAND_REJ 0x01
93#define L2CAP_CONN_REQ 0x02
94#define L2CAP_CONN_RSP 0x03
95#define L2CAP_CONF_REQ 0x04
96#define L2CAP_CONF_RSP 0x05
97#define L2CAP_DISCONN_REQ 0x06
98#define L2CAP_DISCONN_RSP 0x07
99#define L2CAP_ECHO_REQ 0x08
100#define L2CAP_ECHO_RSP 0x09
101#define L2CAP_INFO_REQ 0x0a
102#define L2CAP_INFO_RSP 0x0b
103#define L2CAP_CREATE_CHAN_REQ 0x0c
104#define L2CAP_CREATE_CHAN_RSP 0x0d
105#define L2CAP_MOVE_CHAN_REQ 0x0e
106#define L2CAP_MOVE_CHAN_RSP 0x0f
107#define L2CAP_MOVE_CHAN_CFM 0x10
108#define L2CAP_MOVE_CHAN_CFM_RSP 0x11
Claudio Takahasi3300d9a2011-02-11 19:28:54 -0200109#define L2CAP_CONN_PARAM_UPDATE_REQ 0x12
110#define L2CAP_CONN_PARAM_UPDATE_RSP 0x13
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700111
112/* L2CAP feature mask */
113#define L2CAP_FEAT_FLOWCTL 0x00000001
114#define L2CAP_FEAT_RETRANS 0x00000002
115#define L2CAP_FEAT_ERTM 0x00000008
116#define L2CAP_FEAT_STREAMING 0x00000010
117#define L2CAP_FEAT_FCS 0x00000020
118#define L2CAP_FEAT_FIXED_CHAN 0x00000080
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119#define L2CAP_FEAT_EXT_WINDOW 0x00000100
120#define L2CAP_FEAT_UCD 0x00000200
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700121
122/* L2CAP checksum option */
123#define L2CAP_FCS_NONE 0x00
124#define L2CAP_FCS_CRC16 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126/* L2CAP fixed channels */
127#define L2CAP_FC_L2CAP 0x02
128#define L2CAP_FC_A2MP 0x08
129
130/* L2CAP Control Field */
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300131#define L2CAP_CTRL_SAR 0xC000
132#define L2CAP_CTRL_REQSEQ 0x3F00
133#define L2CAP_CTRL_TXSEQ 0x007E
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300134#define L2CAP_CTRL_FINAL 0x0080
135#define L2CAP_CTRL_POLL 0x0010
136#define L2CAP_CTRL_SUPERVISE 0x000C
137#define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */
138
139#define L2CAP_CTRL_TXSEQ_SHIFT 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140#define L2CAP_CTRL_SUPERVISE_SHIFT 2
141#define L2CAP_CTRL_POLL_SHIFT 4
142#define L2CAP_CTRL_FINAL_SHIFT 7
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300143#define L2CAP_CTRL_REQSEQ_SHIFT 8
Gustavo F. Padovan8f171542009-08-20 22:26:03 -0300144#define L2CAP_CTRL_SAR_SHIFT 14
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300145
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146#define L2CAP_EXT_CTRL_SAR 0x00030000
147#define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC
148#define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000
149#define L2CAP_EXT_CTRL_FINAL 0x00000002
150#define L2CAP_EXT_CTRL_POLL 0x00040000
151#define L2CAP_EXT_CTRL_SUPERVISE 0x00030000
152#define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */
153
154#define L2CAP_EXT_CTRL_FINAL_SHIFT 1
155#define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2
156#define L2CAP_EXT_CTRL_SAR_SHIFT 16
157#define L2CAP_EXT_CTRL_SUPERVISE_SHIFT 16
158#define L2CAP_EXT_CTRL_POLL_SHIFT 18
159#define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18
160
161/* L2CAP Supervisory Frame Types */
162#define L2CAP_SFRAME_RR 0x00
163#define L2CAP_SFRAME_REJ 0x01
164#define L2CAP_SFRAME_RNR 0x02
165#define L2CAP_SFRAME_SREJ 0x03
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300166
167/* L2CAP Segmentation and Reassembly */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168#define L2CAP_SAR_UNSEGMENTED 0x00
169#define L2CAP_SAR_START 0x01
170#define L2CAP_SAR_END 0x02
171#define L2CAP_SAR_CONTINUE 0x03
172
173/* L2CAP ERTM / Streaming extra field lengths */
174#define L2CAP_SDULEN_SIZE 2
175#define L2CAP_FCS_SIZE 2
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/* L2CAP structures */
178struct l2cap_hdr {
Al Viro8e036fc2007-07-29 00:16:36 -0700179 __le16 len;
180 __le16 cid;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300181} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#define L2CAP_HDR_SIZE 4
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183#define L2CAP_ENHANCED_HDR_SIZE 6
184#define L2CAP_EXTENDED_HDR_SIZE 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186struct l2cap_cmd_hdr {
187 __u8 code;
188 __u8 ident;
Al Viro8e036fc2007-07-29 00:16:36 -0700189 __le16 len;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300190} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#define L2CAP_CMD_HDR_SIZE 4
192
193struct l2cap_cmd_rej {
Al Viro8e036fc2007-07-29 00:16:36 -0700194 __le16 reason;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300195} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197struct l2cap_conn_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700198 __le16 psm;
199 __le16 scid;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300200} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202struct l2cap_conn_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700203 __le16 dcid;
204 __le16 scid;
205 __le16 result;
206 __le16 status;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300207} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Gustavo F. Padovan8db4dc42009-04-20 01:31:05 -0300209/* channel indentifier */
210#define L2CAP_CID_SIGNALING 0x0001
211#define L2CAP_CID_CONN_LESS 0x0002
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212#define L2CAP_CID_A2MP 0x0003
Ville Tervoacd7d372011-02-10 22:38:49 -0300213#define L2CAP_CID_LE_DATA 0x0004
214#define L2CAP_CID_LE_SIGNALING 0x0005
215#define L2CAP_CID_SMP 0x0006
Gustavo F. Padovan8db4dc42009-04-20 01:31:05 -0300216#define L2CAP_CID_DYN_START 0x0040
217#define L2CAP_CID_DYN_END 0xffff
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/* connect result */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700220#define L2CAP_CR_SUCCESS 0x0000
221#define L2CAP_CR_PEND 0x0001
222#define L2CAP_CR_BAD_PSM 0x0002
223#define L2CAP_CR_SEC_BLOCK 0x0003
224#define L2CAP_CR_NO_MEM 0x0004
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226/* connect status */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700227#define L2CAP_CS_NO_INFO 0x0000
228#define L2CAP_CS_AUTHEN_PEND 0x0001
229#define L2CAP_CS_AUTHOR_PEND 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231struct l2cap_conf_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700232 __le16 dcid;
233 __le16 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 __u8 data[0];
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300235} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237struct l2cap_conf_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700238 __le16 scid;
239 __le16 flags;
240 __le16 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 __u8 data[0];
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300242} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Marcel Holtmann5dee9e72007-05-24 14:27:19 +0200244#define L2CAP_CONF_SUCCESS 0x0000
245#define L2CAP_CONF_UNACCEPT 0x0001
246#define L2CAP_CONF_REJECT 0x0002
247#define L2CAP_CONF_UNKNOWN 0x0003
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700248#define L2CAP_CONF_PENDING 0x0004
249#define L2CAP_CONF_FLOW_SPEC_REJECT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251struct l2cap_conf_opt {
252 __u8 type;
253 __u8 len;
254 __u8 val[0];
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300255} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define L2CAP_CONF_OPT_SIZE 2
257
Gustavo F. Padovan589d2742009-04-20 01:31:07 -0300258#define L2CAP_CONF_HINT 0x80
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700259#define L2CAP_CONF_MASK 0x7f
Gustavo F. Padovan589d2742009-04-20 01:31:07 -0300260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define L2CAP_CONF_MTU 0x01
262#define L2CAP_CONF_FLUSH_TO 0x02
263#define L2CAP_CONF_QOS 0x03
264#define L2CAP_CONF_RFC 0x04
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700265#define L2CAP_CONF_FCS 0x05
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266#define L2CAP_CONF_EXT_FS 0x06
267#define L2CAP_CONF_EXT_WINDOW 0x07
268
269/* QOS Service type */
270#define L2CAP_SERVICE_NO_TRAFFIC 0x00
271#define L2CAP_SERVICE_BEST_EFFORT 0x01
272#define L2CAP_SERVICE_GUARANTEED 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274#define L2CAP_CONF_MAX_SIZE 22
275
Marcel Holtmann6464f352007-10-20 13:39:51 +0200276struct l2cap_conf_rfc {
277 __u8 mode;
278 __u8 txwin_size;
279 __u8 max_transmit;
280 __le16 retrans_timeout;
281 __le16 monitor_timeout;
282 __le16 max_pdu_size;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300283} __packed;
Marcel Holtmann6464f352007-10-20 13:39:51 +0200284
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700285struct l2cap_conf_ext_fs {
286 __u8 id;
287 __u8 type;
288 __le16 max_sdu;
289 __le32 sdu_arr_time;
290 __le32 acc_latency;
291 __le32 flush_to;
292} __packed;
293
294struct l2cap_conf_prm {
295 __u8 fcs;
296 __le16 retrans_timeout;
297 __le16 monitor_timeout;
298 __le32 flush_to;
299};
300
Marcel Holtmann6464f352007-10-20 13:39:51 +0200301#define L2CAP_MODE_BASIC 0x00
302#define L2CAP_MODE_RETRANS 0x01
303#define L2CAP_MODE_FLOWCTL 0x02
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700304#define L2CAP_MODE_ERTM 0x03
Marcel Holtmannc6b03cf2009-05-02 22:31:10 -0700305#define L2CAP_MODE_STREAMING 0x04
Marcel Holtmann6464f352007-10-20 13:39:51 +0200306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307struct l2cap_disconn_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700308 __le16 dcid;
309 __le16 scid;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300310} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312struct l2cap_disconn_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700313 __le16 dcid;
314 __le16 scid;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300315} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317struct l2cap_info_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700318 __le16 type;
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300319} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321struct l2cap_info_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700322 __le16 type;
323 __le16 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 __u8 data[0];
Gustavo F. Padovan66c853c2010-07-19 02:00:13 -0300325} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700327struct l2cap_create_chan_req {
328 __le16 psm;
329 __le16 scid;
330 __u8 amp_id;
331} __attribute__ ((packed));
332
333struct l2cap_create_chan_rsp {
334 __le16 dcid;
335 __le16 scid;
336 __le16 result;
337 __le16 status;
338} __attribute__ ((packed));
339
340#define L2CAP_CREATE_CHAN_SUCCESS (0x0000)
341#define L2CAP_CREATE_CHAN_PENDING (0x0001)
342#define L2CAP_CREATE_CHAN_REFUSED_PSM (0x0002)
343#define L2CAP_CREATE_CHAN_REFUSED_SECURITY (0x0003)
344#define L2CAP_CREATE_CHAN_REFUSED_RESOURCES (0x0004)
345#define L2CAP_CREATE_CHAN_REFUSED_CONTROLLER (0x0005)
346
347#define L2CAP_CREATE_CHAN_STATUS_NONE (0x0000)
348#define L2CAP_CREATE_CHAN_STATUS_AUTHENTICATION (0x0001)
349#define L2CAP_CREATE_CHAN_STATUS_AUTHORIZATION (0x0002)
350
351struct l2cap_move_chan_req {
352 __le16 icid;
353 __u8 dest_amp_id;
354} __attribute__ ((packed));
355
356struct l2cap_move_chan_rsp {
357 __le16 icid;
358 __le16 result;
359} __attribute__ ((packed));
360
361#define L2CAP_MOVE_CHAN_SUCCESS (0x0000)
362#define L2CAP_MOVE_CHAN_PENDING (0x0001)
363#define L2CAP_MOVE_CHAN_REFUSED_CONTROLLER (0x0002)
364#define L2CAP_MOVE_CHAN_REFUSED_SAME_ID (0x0003)
365#define L2CAP_MOVE_CHAN_REFUSED_CONFIG (0x0004)
366#define L2CAP_MOVE_CHAN_REFUSED_COLLISION (0x0005)
367#define L2CAP_MOVE_CHAN_REFUSED_NOT_ALLOWED (0x0006)
368
369struct l2cap_move_chan_cfm {
370 __le16 icid;
371 __le16 result;
372} __attribute__ ((packed));
373
374#define L2CAP_MOVE_CHAN_CONFIRMED (0x0000)
375#define L2CAP_MOVE_CHAN_UNCONFIRMED (0x0001)
376
377struct l2cap_move_chan_cfm_rsp {
378 __le16 icid;
379} __attribute__ ((packed));
380
381struct l2cap_amp_signal_work {
382 struct work_struct work;
383 struct l2cap_cmd_hdr cmd;
384 struct l2cap_conn *conn;
385 struct sk_buff *skb;
386 u8 *data;
387};
388
389struct l2cap_resegment_work {
390 struct work_struct work;
391 struct sock *sk;
392};
393
394struct l2cap_logical_link_work {
395 struct work_struct work;
396 struct hci_chan *chan;
397 u8 status;
398};
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400/* info type */
401#define L2CAP_IT_CL_MTU 0x0001
402#define L2CAP_IT_FEAT_MASK 0x0002
Marcel Holtmanne1027a72009-02-09 09:18:02 +0100403#define L2CAP_IT_FIXED_CHAN 0x0003
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405/* info result */
406#define L2CAP_IR_SUCCESS 0x0000
407#define L2CAP_IR_NOTSUPP 0x0001
408
Claudio Takahaside731152011-02-11 19:28:55 -0200409struct l2cap_conn_param_update_req {
410 __le16 min;
411 __le16 max;
412 __le16 latency;
413 __le16 to_multiplier;
414} __packed;
415
416struct l2cap_conn_param_update_rsp {
417 __le16 result;
418} __packed;
419
420/* Connection Parameters result */
421#define L2CAP_CONN_PARAM_ACCEPTED 0x0000
422#define L2CAP_CONN_PARAM_REJECTED 0x0001
423
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700424/* ----- L2CAP connections ----- */
425struct l2cap_chan_list {
426 struct sock *head;
427 rwlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428};
429
430struct l2cap_conn {
431 struct hci_conn *hcon;
432
433 bdaddr_t *dst;
434 bdaddr_t *src;
435
436 unsigned int mtu;
437
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200438 __u32 feat_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439 __u8 fc_mask;
440 struct amp_mgr *mgr;
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200441
442 __u8 info_state;
443 __u8 info_ident;
444
445 struct timer_list info_timer;
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 spinlock_t lock;
448
449 struct sk_buff *rx_skb;
450 __u32 rx_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 __u8 tx_ident;
452
Marcel Holtmann2950f212009-02-12 14:02:50 +0100453 __u8 disc_reason;
454
Anderson Brigliac8e856e2011-06-09 18:50:45 -0300455 __u8 preq[7]; /* SMP Pairing Request */
456 __u8 prsp[7]; /* SMP Pairing Response */
457 __u8 prnd[16]; /* SMP Pairing Random */
458 __u8 pcnf[16]; /* SMP Pairing Confirm */
Anderson Briglia21b8a2b2011-06-09 18:50:46 -0300459 __u8 tk[16]; /* SMP Temporary Key */
Vinicius Costa Gomes397d9ae2011-06-14 13:37:42 -0300460 __u8 smp_key_size;
Anderson Brigliac8e856e2011-06-09 18:50:45 -0300461
Vinicius Costa Gomesb19d5ce2011-06-14 13:37:41 -0300462 struct timer_list security_timer;
463
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700464 struct l2cap_chan_list chan_list;
465};
466
467struct sock_del_list {
468 struct sock *sk;
469 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470};
471
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200472#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
Marcel Holtmann984947d2009-02-06 23:35:19 +0100473#define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04
474#define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200475
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700476/* ----- L2CAP channel and socket info ----- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700478#define TX_QUEUE(sk) (&l2cap_pi(sk)->tx_queue)
479#define SREJ_QUEUE(sk) (&l2cap_pi(sk)->srej_queue)
480
481struct l2cap_seq_list {
482 __u16 head;
483 __u16 tail;
484 __u16 size;
485 __u16 mask;
486 __u16 *list;
487};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489struct l2cap_pinfo {
490 struct bt_sock bt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491 __le16 psm;
492 __u16 dcid;
493 __u16 scid;
494
495 __u16 imtu;
496 __u16 omtu;
497 __u16 flush_to;
498 __u8 mode;
499 __u8 fixed_channel;
500 __u8 num_conf_req;
501 __u8 num_conf_rsp;
502
503 __u8 fcs;
504 __u8 sec_level;
505 __u8 role_switch;
506 __u8 force_reliable;
507 __u8 flushable;
508 __u8 force_active;
509
510 __u8 conf_req[64];
511 __u8 conf_len;
512 __u8 conf_ident;
513 __u16 conf_state;
514 __u8 conn_state;
515 __u8 tx_state;
516 __u8 rx_state;
517 __u8 reconf_state;
518
519 __u8 amp_id;
520 __u8 amp_move_id;
521 __u8 amp_move_state;
522 __u8 amp_move_role;
523 __u8 amp_move_cmd_ident;
524 __u16 amp_move_reqseq;
525 __u16 amp_move_event;
526
527 __u16 next_tx_seq;
528 __u16 expected_ack_seq;
529 __u16 expected_tx_seq;
530 __u16 buffer_seq;
531 __u16 srej_save_reqseq;
532 __u16 last_acked_seq;
533 __u32 frames_sent;
534 __u16 unacked_frames;
535 __u8 retry_count;
536 __u16 srej_queue_next;
537 __u16 sdu_len;
538 struct sk_buff *sdu;
539 struct sk_buff *sdu_last_frag;
540 atomic_t ertm_queued;
541
542 __u8 ident;
543
544 __u16 tx_win;
545 __u16 tx_win_max;
546 __u8 max_tx;
547 __u8 amp_pref;
548 __u16 remote_tx_win;
549 __u8 remote_max_tx;
550 __u8 extended_control;
551 __u16 retrans_timeout;
552 __u16 monitor_timeout;
553 __u16 remote_mps;
554 __u16 mps;
555
556 __le16 sport;
557
558 struct delayed_work retrans_work;
559 struct delayed_work monitor_work;
560 struct delayed_work ack_work;
561 struct work_struct tx_work;
562 struct sk_buff_head tx_queue;
563 struct sk_buff_head srej_queue;
564 struct l2cap_seq_list srej_list;
565 struct l2cap_seq_list retrans_list;
566 struct hci_conn *ampcon;
567 struct hci_chan *ampchan;
568 struct l2cap_conn *conn;
569 struct l2cap_conf_prm local_conf;
570 struct l2cap_conf_prm remote_conf;
571 struct l2cap_conf_ext_fs local_fs;
572 struct l2cap_conf_ext_fs remote_fs;
573 struct sock *next_c;
574 struct sock *prev_c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575};
576
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700577#define L2CAP_CONF_REQ_SENT 0x0001
578#define L2CAP_CONF_INPUT_DONE 0x0002
579#define L2CAP_CONF_OUTPUT_DONE 0x0004
580#define L2CAP_CONF_MTU_DONE 0x0008
581#define L2CAP_CONF_MODE_DONE 0x0010
582#define L2CAP_CONF_CONNECT_PEND 0x0020
583#define L2CAP_CONF_NO_FCS_RECV 0x0040
584#define L2CAP_CONF_STATE2_DEVICE 0x0080
585#define L2CAP_CONF_EXT_WIN_RECV 0x0100
586#define L2CAP_CONF_LOCKSTEP 0x0200
587#define L2CAP_CONF_LOCKSTEP_PEND 0x0400
588#define L2CAP_CONF_PEND_SENT 0x0800
589#define L2CAP_CONF_EFS_RECV 0x1000
Marcel Holtmann861d6882007-10-20 13:37:06 +0200590
Gustavo F. Padovanf2fcfcd2009-07-04 15:06:24 -0300591#define L2CAP_CONF_MAX_CONF_REQ 2
592#define L2CAP_CONF_MAX_CONF_RSP 2
593
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594#define L2CAP_RECONF_NONE 0x00
595#define L2CAP_RECONF_INT 0x01
596#define L2CAP_RECONF_ACC 0x02
Gustavo F. Padovane90bac02009-08-20 22:26:00 -0300597
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700598#define L2CAP_CONN_SREJ_ACT 0x01
599#define L2CAP_CONN_REJ_ACT 0x02
600#define L2CAP_CONN_REMOTE_BUSY 0x04
601#define L2CAP_CONN_LOCAL_BUSY 0x08
602#define L2CAP_CONN_SEND_FBIT 0x10
603#define L2CAP_CONN_SENT_RNR 0x20
Gustavo F. Padovanc74e5602009-08-20 22:25:58 -0300604
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700605#define L2CAP_SEQ_LIST_CLEAR 0xFFFF
606#define L2CAP_SEQ_LIST_TAIL 0x8000
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300607
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700608#define L2CAP_ERTM_TX_STATE_XMIT 0x01
609#define L2CAP_ERTM_TX_STATE_WAIT_F 0x02
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300610
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700611#define L2CAP_ERTM_RX_STATE_RECV 0x01
612#define L2CAP_ERTM_RX_STATE_SREJ_SENT 0x02
613#define L2CAP_ERTM_RX_STATE_AMP_MOVE 0x03
614#define L2CAP_ERTM_RX_STATE_WAIT_P_FLAG 0x04
615#define L2CAP_ERTM_RX_STATE_WAIT_P_FLAG_RECONFIGURE 0x05
616#define L2CAP_ERTM_RX_STATE_WAIT_F_FLAG 0x06
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300617
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700618#define L2CAP_ERTM_TXSEQ_EXPECTED 0x00
619#define L2CAP_ERTM_TXSEQ_EXPECTED_SREJ 0x01
620#define L2CAP_ERTM_TXSEQ_UNEXPECTED 0x02
621#define L2CAP_ERTM_TXSEQ_UNEXPECTED_SREJ 0x03
622#define L2CAP_ERTM_TXSEQ_DUPLICATE 0x04
623#define L2CAP_ERTM_TXSEQ_DUPLICATE_SREJ 0x05
624#define L2CAP_ERTM_TXSEQ_INVALID 0x06
625#define L2CAP_ERTM_TXSEQ_INVALID_IGNORE 0x07
Gustavo F. Padovan1c2acff2009-08-20 22:25:57 -0300626
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700627#define L2CAP_ERTM_EVENT_DATA_REQUEST 0x01
628#define L2CAP_ERTM_EVENT_LOCAL_BUSY_DETECTED 0x02
629#define L2CAP_ERTM_EVENT_LOCAL_BUSY_CLEAR 0x03
630#define L2CAP_ERTM_EVENT_RECV_REQSEQ_AND_FBIT 0x04
631#define L2CAP_ERTM_EVENT_RECV_FBIT 0x05
632#define L2CAP_ERTM_EVENT_RETRANS_TIMER_EXPIRES 0x06
633#define L2CAP_ERTM_EVENT_MONITOR_TIMER_EXPIRES 0x07
634#define L2CAP_ERTM_EVENT_EXPLICIT_POLL 0x08
635#define L2CAP_ERTM_EVENT_RECV_IFRAME 0x09
636#define L2CAP_ERTM_EVENT_RECV_RR 0x0a
637#define L2CAP_ERTM_EVENT_RECV_REJ 0x0b
638#define L2CAP_ERTM_EVENT_RECV_RNR 0x0c
639#define L2CAP_ERTM_EVENT_RECV_SREJ 0x0d
640#define L2CAP_ERTM_EVENT_RECV_FRAME 0x0e
641
642#define L2CAP_AMP_MOVE_NONE 0
643#define L2CAP_AMP_MOVE_INITIATOR 1
644#define L2CAP_AMP_MOVE_RESPONDER 2
645
646#define L2CAP_AMP_STATE_STABLE 0
647#define L2CAP_AMP_STATE_WAIT_CREATE 1
648#define L2CAP_AMP_STATE_WAIT_CREATE_RSP 2
649#define L2CAP_AMP_STATE_WAIT_MOVE 3
650#define L2CAP_AMP_STATE_WAIT_MOVE_RSP 4
651#define L2CAP_AMP_STATE_WAIT_MOVE_RSP_SUCCESS 5
652#define L2CAP_AMP_STATE_WAIT_MOVE_CONFIRM 6
653#define L2CAP_AMP_STATE_WAIT_MOVE_CONFIRM_RSP 7
654#define L2CAP_AMP_STATE_WAIT_LOGICAL_COMPLETE 8
655#define L2CAP_AMP_STATE_WAIT_LOGICAL_CONFIRM 9
656#define L2CAP_AMP_STATE_WAIT_LOCAL_BUSY 10
657#define L2CAP_AMP_STATE_WAIT_PREPARE 11
658#define L2CAP_AMP_STATE_RESEGMENT 12
659
660#define __delta_seq(x, y, pi) ((x) >= (y) ? (x) - (y) : \
661 (pi)->tx_win_max + 1 - (y) + (x))
662#define __next_seq(x, pi) ((x + 1) & ((pi)->tx_win_max))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Gustavo F. Padovanbb58f742011-02-03 20:50:35 -0200664extern int disable_ertm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700665extern const struct proto_ops l2cap_sock_ops;
666extern struct bt_sock_list l2cap_sk_list;
Gustavo F. Padovanbb58f742011-02-03 20:50:35 -0200667
668int l2cap_init_sockets(void);
669void l2cap_cleanup_sockets(void);
670
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671u8 l2cap_get_ident(struct l2cap_conn *conn);
672void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data);
673int l2cap_build_conf_req(struct sock *sk, void *data);
Gustavo F. Padovandcba0db2011-02-04 03:08:36 -0200674int __l2cap_wait_ack(struct sock *sk);
Gustavo F. Padovan68983252011-02-04 03:02:31 -0200675
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len);
677struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len);
678struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg,
679 size_t len, u16 sdulen, int reseg);
680int l2cap_segment_sdu(struct sock *sk, struct sk_buff_head* seg_queue,
681 struct msghdr *msg, size_t len, int reseg);
682int l2cap_resegment_queue(struct sock *sk, struct sk_buff_head *queue);
683void l2cap_do_send(struct sock *sk, struct sk_buff *skb);
684void l2cap_streaming_send(struct sock *sk);
685int l2cap_ertm_send(struct sock *sk);
686int l2cap_strm_tx(struct sock *sk, struct sk_buff_head *skbs);
687int l2cap_ertm_tx(struct sock *sk, struct bt_l2cap_control *control,
688 struct sk_buff_head *skbs, u8 event);
Gustavo F. Padovan9e4425f2011-04-18 18:38:43 -0300689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690void l2cap_sock_set_timer(struct sock *sk, long timeout);
691void l2cap_sock_clear_timer(struct sock *sk);
692void __l2cap_sock_close(struct sock *sk, int reason);
693void l2cap_sock_kill(struct sock *sk);
694void l2cap_sock_init(struct sock *sk, struct sock *parent);
695struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
696 int proto, gfp_t prio);
697void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err);
698void l2cap_chan_del(struct sock *sk, int err);
699int l2cap_do_connect(struct sock *sk);
700int l2cap_data_channel(struct sock *sk, struct sk_buff *skb);
701void l2cap_amp_move_init(struct sock *sk);
702void l2cap_ertm_destruct(struct sock *sk);
703void l2cap_ertm_shutdown(struct sock *sk);
704void l2cap_ertm_recv_done(struct sock *sk);
705
706void l2cap_fixed_channel_config(struct sock *sk, struct l2cap_options *opt);
707
708void l2cap_recv_deferred_frame(struct sock *sk, struct sk_buff *skb);
709
710void l2cap_amp_physical_complete(int result, u8 remote_id, u8 local_id,
711 struct sock *sk);
712
713void l2cap_amp_logical_complete(int result, struct hci_conn *ampcon,
714 struct hci_chan *ampchan, struct sock *sk);
715
716void l2cap_amp_logical_destroyed(struct hci_conn *ampcon);
Gustavo F. Padovanbb58f742011-02-03 20:50:35 -0200717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#endif /* __L2CAP_H */