upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / include / net / bluetooth / l2cap.h
1 /* 
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
32 #define L2CAP_CONN_TIMEOUT      (HZ * 40)
33
34 /* L2CAP socket address */
35 struct sockaddr_l2 {
36         sa_family_t     l2_family;
37         unsigned short  l2_psm;
38         bdaddr_t        l2_bdaddr;
39 };
40
41 /* Socket options */
42 #define L2CAP_OPTIONS   0x01
43 struct l2cap_options {
44         __u16 omtu;
45         __u16 imtu;
46         __u16 flush_to;
47 };
48
49 #define L2CAP_CONNINFO  0x02
50 struct l2cap_conninfo {
51         __u16 hci_handle;
52 };
53
54 #define L2CAP_LM        0x03
55 #define L2CAP_LM_MASTER         0x0001
56 #define L2CAP_LM_AUTH           0x0002
57 #define L2CAP_LM_ENCRYPT        0x0004
58 #define L2CAP_LM_TRUSTED        0x0008
59 #define L2CAP_LM_RELIABLE       0x0010
60 #define L2CAP_LM_SECURE         0x0020
61
62 #define L2CAP_QOS       0x04
63 struct l2cap_qos {
64         __u16 service_type;
65         __u32 token_rate;
66         __u32 token_bucket_size;
67         __u32 peak_bandwidth;
68         __u32 latency;
69         __u32 delay_variation;
70 };
71
72 #define L2CAP_SERV_NO_TRAFFIC   0x00
73 #define L2CAP_SERV_BEST_EFFORT  0x01
74 #define L2CAP_SERV_GUARANTEED   0x02
75
76 /* L2CAP command codes */
77 #define L2CAP_COMMAND_REJ 0x01
78 #define L2CAP_CONN_REQ    0x02
79 #define L2CAP_CONN_RSP    0x03
80 #define L2CAP_CONF_REQ    0x04
81 #define L2CAP_CONF_RSP    0x05
82 #define L2CAP_DISCONN_REQ 0x06
83 #define L2CAP_DISCONN_RSP 0x07
84 #define L2CAP_ECHO_REQ    0x08
85 #define L2CAP_ECHO_RSP    0x09
86 #define L2CAP_INFO_REQ    0x0a
87 #define L2CAP_INFO_RSP    0x0b
88
89 /* L2CAP structures */
90 struct l2cap_hdr {
91         __u16      len;
92         __u16      cid;
93 } __attribute__ ((packed));
94 #define L2CAP_HDR_SIZE          4
95
96 struct l2cap_cmd_hdr {
97         __u8       code;
98         __u8       ident;
99         __u16      len;
100 } __attribute__ ((packed));
101 #define L2CAP_CMD_HDR_SIZE      4
102
103 struct l2cap_cmd_rej {
104         __u16      reason;
105 } __attribute__ ((packed));
106
107 struct l2cap_conn_req {
108         __u16      psm;
109         __u16      scid;
110 } __attribute__ ((packed));
111
112 struct l2cap_conn_rsp {
113         __u16      dcid;
114         __u16      scid;
115         __u16      result;
116         __u16      status;
117 } __attribute__ ((packed));
118
119 /* connect result */
120 #define L2CAP_CR_SUCCESS    0x0000
121 #define L2CAP_CR_PEND       0x0001
122 #define L2CAP_CR_BAD_PSM    0x0002
123 #define L2CAP_CR_SEC_BLOCK  0x0003
124 #define L2CAP_CR_NO_MEM     0x0004
125
126 /* connect status */
127 #define L2CAP_CS_NO_INFO      0x0000
128 #define L2CAP_CS_AUTHEN_PEND  0x0001
129 #define L2CAP_CS_AUTHOR_PEND  0x0002
130
131 struct l2cap_conf_req {
132         __u16      dcid;
133         __u16      flags;
134         __u8       data[0];
135 } __attribute__ ((packed));
136
137 struct l2cap_conf_rsp {
138         __u16      scid;
139         __u16      flags;
140         __u16      result;
141         __u8       data[0];
142 } __attribute__ ((packed));
143
144 #define L2CAP_CONF_SUCCESS      0x00
145 #define L2CAP_CONF_UNACCEPT     0x01
146
147 struct l2cap_conf_opt {
148         __u8       type;
149         __u8       len;
150         __u8       val[0];
151 } __attribute__ ((packed));
152 #define L2CAP_CONF_OPT_SIZE     2
153
154 #define L2CAP_CONF_MTU          0x01
155 #define L2CAP_CONF_FLUSH_TO     0x02
156 #define L2CAP_CONF_QOS          0x03
157
158 #define L2CAP_CONF_MAX_SIZE     22
159
160 struct l2cap_disconn_req {
161         __u16      dcid;
162         __u16      scid;
163 } __attribute__ ((packed));
164
165 struct l2cap_disconn_rsp {
166         __u16      dcid;
167         __u16      scid;
168 } __attribute__ ((packed));
169
170 struct l2cap_info_req {
171         __u16       type;
172         __u8        data[0];
173 } __attribute__ ((packed));
174
175 struct l2cap_info_rsp {
176         __u16       type;
177         __u16       result;
178         __u8        data[0];
179 } __attribute__ ((packed));
180
181 /* info type */
182 #define L2CAP_IT_CL_MTU     0x0001
183 #define L2CAP_IT_FEAT_MASK  0x0002
184
185 /* info result */
186 #define L2CAP_IR_SUCCESS    0x0000
187 #define L2CAP_IR_NOTSUPP    0x0001
188
189 /* ----- L2CAP connections ----- */
190 struct l2cap_chan_list {
191         struct sock     *head;
192         rwlock_t        lock;
193         long            num;
194 };
195
196 struct l2cap_conn {
197         struct hci_conn *hcon;
198
199         bdaddr_t        *dst;
200         bdaddr_t        *src;
201         
202         unsigned int    mtu;
203
204         spinlock_t      lock;
205         
206         struct sk_buff *rx_skb;
207         __u32           rx_len;
208         __u8            rx_ident;
209         __u8            tx_ident;
210
211         struct l2cap_chan_list chan_list;
212 };
213
214 /* ----- L2CAP channel and socket info ----- */
215 #define l2cap_pi(sk)   ((struct l2cap_pinfo *)sk->sk_protinfo)
216
217 struct l2cap_pinfo {
218         __u16           psm;
219         __u16           dcid;
220         __u16           scid;
221
222         __u16           imtu;
223         __u16           omtu;
224         __u16           flush_to;
225         
226         __u32           link_mode;
227
228         __u8            conf_state;
229         __u8            conf_retry;
230         __u16           conf_mtu;
231
232         __u8            ident;
233
234         __u16           sport;
235
236         struct l2cap_conn       *conn;
237         struct sock             *next_c;
238         struct sock             *prev_c;
239 };
240
241 #define L2CAP_CONF_REQ_SENT    0x01
242 #define L2CAP_CONF_INPUT_DONE  0x02
243 #define L2CAP_CONF_OUTPUT_DONE 0x04
244 #define L2CAP_CONF_MAX_RETRIES 2
245
246 void l2cap_load(void);
247
248 #endif /* __L2CAP_H */