blob: e919fca1072a7d096dd3b8743c4dada3a3dc9768 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23*/
24
25#ifndef __L2CAP_H
26#define __L2CAP_H
27
28/* L2CAP defaults */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -070029#define L2CAP_DEFAULT_MTU 672
30#define L2CAP_DEFAULT_FLUSH_TO 0xffff
31#define L2CAP_DEFAULT_RX_WINDOW 1
32#define L2CAP_DEFAULT_MAX_RECEIVE 1
33#define L2CAP_DEFAULT_RETRANS_TO 300 /* 300 milliseconds */
34#define L2CAP_DEFAULT_MONITOR_TO 1000 /* 1 second */
35#define L2CAP_DEFAULT_MAX_RX_APDU 0xfff7
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Marcel Holtmann4e8402a2007-10-20 13:37:56 +020037#define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */
38#define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/* L2CAP socket address */
41struct sockaddr_l2 {
42 sa_family_t l2_family;
Al Viro8e036fc2007-07-29 00:16:36 -070043 __le16 l2_psm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 bdaddr_t l2_bdaddr;
Marcel Holtmannf29972d2009-02-12 05:07:45 +010045 __le16 l2_cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
48/* L2CAP socket options */
49#define L2CAP_OPTIONS 0x01
50struct l2cap_options {
51 __u16 omtu;
52 __u16 imtu;
53 __u16 flush_to;
54 __u8 mode;
55};
56
57#define L2CAP_CONNINFO 0x02
58struct l2cap_conninfo {
59 __u16 hci_handle;
60 __u8 dev_class[3];
61};
62
63#define L2CAP_LM 0x03
64#define L2CAP_LM_MASTER 0x0001
65#define L2CAP_LM_AUTH 0x0002
66#define L2CAP_LM_ENCRYPT 0x0004
67#define L2CAP_LM_TRUSTED 0x0008
68#define L2CAP_LM_RELIABLE 0x0010
69#define L2CAP_LM_SECURE 0x0020
70
71/* L2CAP command codes */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -070072#define L2CAP_COMMAND_REJ 0x01
73#define L2CAP_CONN_REQ 0x02
74#define L2CAP_CONN_RSP 0x03
75#define L2CAP_CONF_REQ 0x04
76#define L2CAP_CONF_RSP 0x05
77#define L2CAP_DISCONN_REQ 0x06
78#define L2CAP_DISCONN_RSP 0x07
79#define L2CAP_ECHO_REQ 0x08
80#define L2CAP_ECHO_RSP 0x09
81#define L2CAP_INFO_REQ 0x0a
82#define L2CAP_INFO_RSP 0x0b
83
84/* L2CAP feature mask */
85#define L2CAP_FEAT_FLOWCTL 0x00000001
86#define L2CAP_FEAT_RETRANS 0x00000002
87#define L2CAP_FEAT_ERTM 0x00000008
88#define L2CAP_FEAT_STREAMING 0x00000010
89#define L2CAP_FEAT_FCS 0x00000020
90#define L2CAP_FEAT_FIXED_CHAN 0x00000080
91
92/* L2CAP checksum option */
93#define L2CAP_FCS_NONE 0x00
94#define L2CAP_FCS_CRC16 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/* L2CAP structures */
97struct l2cap_hdr {
Al Viro8e036fc2007-07-29 00:16:36 -070098 __le16 len;
99 __le16 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100} __attribute__ ((packed));
101#define L2CAP_HDR_SIZE 4
102
103struct l2cap_cmd_hdr {
104 __u8 code;
105 __u8 ident;
Al Viro8e036fc2007-07-29 00:16:36 -0700106 __le16 len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107} __attribute__ ((packed));
108#define L2CAP_CMD_HDR_SIZE 4
109
110struct l2cap_cmd_rej {
Al Viro8e036fc2007-07-29 00:16:36 -0700111 __le16 reason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112} __attribute__ ((packed));
113
114struct l2cap_conn_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700115 __le16 psm;
116 __le16 scid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117} __attribute__ ((packed));
118
119struct l2cap_conn_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700120 __le16 dcid;
121 __le16 scid;
122 __le16 result;
123 __le16 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124} __attribute__ ((packed));
125
Gustavo F. Padovan8db4dc42009-04-20 01:31:05 -0300126/* channel indentifier */
127#define L2CAP_CID_SIGNALING 0x0001
128#define L2CAP_CID_CONN_LESS 0x0002
129#define L2CAP_CID_DYN_START 0x0040
130#define L2CAP_CID_DYN_END 0xffff
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* connect result */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700133#define L2CAP_CR_SUCCESS 0x0000
134#define L2CAP_CR_PEND 0x0001
135#define L2CAP_CR_BAD_PSM 0x0002
136#define L2CAP_CR_SEC_BLOCK 0x0003
137#define L2CAP_CR_NO_MEM 0x0004
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139/* connect status */
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700140#define L2CAP_CS_NO_INFO 0x0000
141#define L2CAP_CS_AUTHEN_PEND 0x0001
142#define L2CAP_CS_AUTHOR_PEND 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144struct l2cap_conf_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700145 __le16 dcid;
146 __le16 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 __u8 data[0];
148} __attribute__ ((packed));
149
150struct l2cap_conf_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700151 __le16 scid;
152 __le16 flags;
153 __le16 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 __u8 data[0];
155} __attribute__ ((packed));
156
Marcel Holtmann5dee9e72007-05-24 14:27:19 +0200157#define L2CAP_CONF_SUCCESS 0x0000
158#define L2CAP_CONF_UNACCEPT 0x0001
159#define L2CAP_CONF_REJECT 0x0002
160#define L2CAP_CONF_UNKNOWN 0x0003
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162struct l2cap_conf_opt {
163 __u8 type;
164 __u8 len;
165 __u8 val[0];
166} __attribute__ ((packed));
167#define L2CAP_CONF_OPT_SIZE 2
168
Gustavo F. Padovan589d2742009-04-20 01:31:07 -0300169#define L2CAP_CONF_HINT 0x80
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700170#define L2CAP_CONF_MASK 0x7f
Gustavo F. Padovan589d2742009-04-20 01:31:07 -0300171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#define L2CAP_CONF_MTU 0x01
173#define L2CAP_CONF_FLUSH_TO 0x02
174#define L2CAP_CONF_QOS 0x03
175#define L2CAP_CONF_RFC 0x04
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700176#define L2CAP_CONF_FCS 0x05
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178#define L2CAP_CONF_MAX_SIZE 22
179
Marcel Holtmann6464f352007-10-20 13:39:51 +0200180struct l2cap_conf_rfc {
181 __u8 mode;
182 __u8 txwin_size;
183 __u8 max_transmit;
184 __le16 retrans_timeout;
185 __le16 monitor_timeout;
186 __le16 max_pdu_size;
187} __attribute__ ((packed));
188
189#define L2CAP_MODE_BASIC 0x00
190#define L2CAP_MODE_RETRANS 0x01
191#define L2CAP_MODE_FLOWCTL 0x02
Marcel Holtmann47ec1dcd2009-05-02 18:57:55 -0700192#define L2CAP_MODE_ERTM 0x03
193#define L2CAP_MODE_STREAM 0x04
Marcel Holtmann6464f352007-10-20 13:39:51 +0200194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195struct l2cap_disconn_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700196 __le16 dcid;
197 __le16 scid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198} __attribute__ ((packed));
199
200struct l2cap_disconn_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700201 __le16 dcid;
202 __le16 scid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203} __attribute__ ((packed));
204
205struct l2cap_info_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700206 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207} __attribute__ ((packed));
208
209struct l2cap_info_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700210 __le16 type;
211 __le16 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 __u8 data[0];
213} __attribute__ ((packed));
214
215/* info type */
216#define L2CAP_IT_CL_MTU 0x0001
217#define L2CAP_IT_FEAT_MASK 0x0002
Marcel Holtmanne1027a72009-02-09 09:18:02 +0100218#define L2CAP_IT_FIXED_CHAN 0x0003
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220/* info result */
221#define L2CAP_IR_SUCCESS 0x0000
222#define L2CAP_IR_NOTSUPP 0x0001
223
224/* ----- L2CAP connections ----- */
225struct l2cap_chan_list {
226 struct sock *head;
227 rwlock_t lock;
228 long num;
229};
230
231struct l2cap_conn {
232 struct hci_conn *hcon;
233
234 bdaddr_t *dst;
235 bdaddr_t *src;
236
237 unsigned int mtu;
238
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200239 __u32 feat_mask;
240
241 __u8 info_state;
242 __u8 info_ident;
243
244 struct timer_list info_timer;
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 spinlock_t lock;
247
248 struct sk_buff *rx_skb;
249 __u32 rx_len;
250 __u8 rx_ident;
251 __u8 tx_ident;
252
Marcel Holtmann2950f212009-02-12 14:02:50 +0100253 __u8 disc_reason;
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 struct l2cap_chan_list chan_list;
256};
257
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200258#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
Marcel Holtmann984947d2009-02-06 23:35:19 +0100259#define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04
260#define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262/* ----- L2CAP channel and socket info ----- */
263#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
264
265struct l2cap_pinfo {
266 struct bt_sock bt;
Al Viro8e036fc2007-07-29 00:16:36 -0700267 __le16 psm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 __u16 dcid;
269 __u16 scid;
270
271 __u16 imtu;
272 __u16 omtu;
273 __u16 flush_to;
Marcel Holtmann2af6b9d2009-01-15 21:58:38 +0100274 __u8 sec_level;
275 __u8 role_switch;
276 __u8 force_reliable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Marcel Holtmann5dee9e72007-05-24 14:27:19 +0200278 __u8 conf_req[64];
279 __u8 conf_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 __u8 conf_state;
281 __u8 conf_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 __u8 ident;
284
Al Viro8e036fc2007-07-29 00:16:36 -0700285 __le16 sport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 struct l2cap_conn *conn;
288 struct sock *next_c;
289 struct sock *prev_c;
290};
291
Marcel Holtmann861d6882007-10-20 13:37:06 +0200292#define L2CAP_CONF_REQ_SENT 0x01
293#define L2CAP_CONF_INPUT_DONE 0x02
294#define L2CAP_CONF_OUTPUT_DONE 0x04
Marcel Holtmann6a8d3012009-02-06 23:56:36 +0100295#define L2CAP_CONF_CONNECT_PEND 0x80
Marcel Holtmann861d6882007-10-20 13:37:06 +0200296
297#define L2CAP_CONF_MAX_RETRIES 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299void l2cap_load(void);
300
301#endif /* __L2CAP_H */