blob: e1ea64085c4fd5111a7e460b0f914621aa8edf33 [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 */
29#define L2CAP_DEFAULT_MTU 672
30#define L2CAP_DEFAULT_FLUSH_TO 0xFFFF
31
Marcel Holtmann4e8402a2007-10-20 13:37:56 +020032#define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */
33#define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/* L2CAP socket address */
36struct sockaddr_l2 {
37 sa_family_t l2_family;
Al Viro8e036fc2007-07-29 00:16:36 -070038 __le16 l2_psm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 bdaddr_t l2_bdaddr;
40};
41
42/* L2CAP socket options */
43#define L2CAP_OPTIONS 0x01
44struct l2cap_options {
45 __u16 omtu;
46 __u16 imtu;
47 __u16 flush_to;
48 __u8 mode;
49};
50
51#define L2CAP_CONNINFO 0x02
52struct l2cap_conninfo {
53 __u16 hci_handle;
54 __u8 dev_class[3];
55};
56
57#define L2CAP_LM 0x03
58#define L2CAP_LM_MASTER 0x0001
59#define L2CAP_LM_AUTH 0x0002
60#define L2CAP_LM_ENCRYPT 0x0004
61#define L2CAP_LM_TRUSTED 0x0008
62#define L2CAP_LM_RELIABLE 0x0010
63#define L2CAP_LM_SECURE 0x0020
64
65/* L2CAP command codes */
66#define L2CAP_COMMAND_REJ 0x01
67#define L2CAP_CONN_REQ 0x02
68#define L2CAP_CONN_RSP 0x03
69#define L2CAP_CONF_REQ 0x04
70#define L2CAP_CONF_RSP 0x05
71#define L2CAP_DISCONN_REQ 0x06
72#define L2CAP_DISCONN_RSP 0x07
73#define L2CAP_ECHO_REQ 0x08
74#define L2CAP_ECHO_RSP 0x09
75#define L2CAP_INFO_REQ 0x0a
76#define L2CAP_INFO_RSP 0x0b
77
78/* L2CAP structures */
79struct l2cap_hdr {
Al Viro8e036fc2007-07-29 00:16:36 -070080 __le16 len;
81 __le16 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082} __attribute__ ((packed));
83#define L2CAP_HDR_SIZE 4
84
85struct l2cap_cmd_hdr {
86 __u8 code;
87 __u8 ident;
Al Viro8e036fc2007-07-29 00:16:36 -070088 __le16 len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089} __attribute__ ((packed));
90#define L2CAP_CMD_HDR_SIZE 4
91
92struct l2cap_cmd_rej {
Al Viro8e036fc2007-07-29 00:16:36 -070093 __le16 reason;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094} __attribute__ ((packed));
95
96struct l2cap_conn_req {
Al Viro8e036fc2007-07-29 00:16:36 -070097 __le16 psm;
98 __le16 scid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099} __attribute__ ((packed));
100
101struct l2cap_conn_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700102 __le16 dcid;
103 __le16 scid;
104 __le16 result;
105 __le16 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106} __attribute__ ((packed));
107
108/* connect result */
109#define L2CAP_CR_SUCCESS 0x0000
110#define L2CAP_CR_PEND 0x0001
111#define L2CAP_CR_BAD_PSM 0x0002
112#define L2CAP_CR_SEC_BLOCK 0x0003
113#define L2CAP_CR_NO_MEM 0x0004
114
115/* connect status */
116#define L2CAP_CS_NO_INFO 0x0000
117#define L2CAP_CS_AUTHEN_PEND 0x0001
118#define L2CAP_CS_AUTHOR_PEND 0x0002
119
120struct l2cap_conf_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700121 __le16 dcid;
122 __le16 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 __u8 data[0];
124} __attribute__ ((packed));
125
126struct l2cap_conf_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700127 __le16 scid;
128 __le16 flags;
129 __le16 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 __u8 data[0];
131} __attribute__ ((packed));
132
Marcel Holtmann5dee9e72007-05-24 14:27:19 +0200133#define L2CAP_CONF_SUCCESS 0x0000
134#define L2CAP_CONF_UNACCEPT 0x0001
135#define L2CAP_CONF_REJECT 0x0002
136#define L2CAP_CONF_UNKNOWN 0x0003
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138struct l2cap_conf_opt {
139 __u8 type;
140 __u8 len;
141 __u8 val[0];
142} __attribute__ ((packed));
143#define L2CAP_CONF_OPT_SIZE 2
144
145#define L2CAP_CONF_MTU 0x01
146#define L2CAP_CONF_FLUSH_TO 0x02
147#define L2CAP_CONF_QOS 0x03
148#define L2CAP_CONF_RFC 0x04
149
150#define L2CAP_CONF_MAX_SIZE 22
151
152struct l2cap_disconn_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700153 __le16 dcid;
154 __le16 scid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155} __attribute__ ((packed));
156
157struct l2cap_disconn_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700158 __le16 dcid;
159 __le16 scid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160} __attribute__ ((packed));
161
162struct l2cap_info_req {
Al Viro8e036fc2007-07-29 00:16:36 -0700163 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164} __attribute__ ((packed));
165
166struct l2cap_info_rsp {
Al Viro8e036fc2007-07-29 00:16:36 -0700167 __le16 type;
168 __le16 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 __u8 data[0];
170} __attribute__ ((packed));
171
172/* info type */
173#define L2CAP_IT_CL_MTU 0x0001
174#define L2CAP_IT_FEAT_MASK 0x0002
175
176/* info result */
177#define L2CAP_IR_SUCCESS 0x0000
178#define L2CAP_IR_NOTSUPP 0x0001
179
180/* ----- L2CAP connections ----- */
181struct l2cap_chan_list {
182 struct sock *head;
183 rwlock_t lock;
184 long num;
185};
186
187struct l2cap_conn {
188 struct hci_conn *hcon;
189
190 bdaddr_t *dst;
191 bdaddr_t *src;
192
193 unsigned int mtu;
194
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200195 __u32 feat_mask;
196
197 __u8 info_state;
198 __u8 info_ident;
199
200 struct timer_list info_timer;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 spinlock_t lock;
203
204 struct sk_buff *rx_skb;
205 __u32 rx_len;
206 __u8 rx_ident;
207 __u8 tx_ident;
208
209 struct l2cap_chan_list chan_list;
210};
211
Marcel Holtmann4e8402a2007-10-20 13:37:56 +0200212#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
213#define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x02
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215/* ----- L2CAP channel and socket info ----- */
216#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
217
218struct l2cap_pinfo {
219 struct bt_sock bt;
Al Viro8e036fc2007-07-29 00:16:36 -0700220 __le16 psm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 __u16 dcid;
222 __u16 scid;
223
224 __u16 imtu;
225 __u16 omtu;
226 __u16 flush_to;
227
228 __u32 link_mode;
229
Marcel Holtmann5dee9e72007-05-24 14:27:19 +0200230 __u8 conf_req[64];
231 __u8 conf_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 __u8 conf_state;
233 __u8 conf_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 __u8 ident;
236
Al Viro8e036fc2007-07-29 00:16:36 -0700237 __le16 sport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 struct l2cap_conn *conn;
240 struct sock *next_c;
241 struct sock *prev_c;
242};
243
Marcel Holtmann861d6882007-10-20 13:37:06 +0200244#define L2CAP_CONF_REQ_SENT 0x01
245#define L2CAP_CONF_INPUT_DONE 0x02
246#define L2CAP_CONF_OUTPUT_DONE 0x04
247
248#define L2CAP_CONF_MAX_RETRIES 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250void l2cap_load(void);
251
252#endif /* __L2CAP_H */