aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/bluetooth/rfcomm.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/bluetooth/rfcomm.h')
-rw-r--r--include/net/bluetooth/rfcomm.h353
1 files changed, 353 insertions, 0 deletions
diff --git a/include/net/bluetooth/rfcomm.h b/include/net/bluetooth/rfcomm.h
new file mode 100644
index 000000000000..13669bad00b3
--- /dev/null
+++ b/include/net/bluetooth/rfcomm.h
@@ -0,0 +1,353 @@
1/*
2 RFCOMM implementation for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
4 Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;
9
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21 SOFTWARE IS DISCLAIMED.
22*/
23
24#ifndef __RFCOMM_H
25#define __RFCOMM_H
26
27#define RFCOMM_PSM 3
28
29#define RFCOMM_CONN_TIMEOUT (HZ * 30)
30#define RFCOMM_DISC_TIMEOUT (HZ * 20)
31#define RFCOMM_AUTH_TIMEOUT (HZ * 25)
32
33#define RFCOMM_DEFAULT_MTU 127
34#define RFCOMM_DEFAULT_CREDITS 7
35
36#define RFCOMM_MAX_L2CAP_MTU 1024
37#define RFCOMM_MAX_CREDITS 40
38
39#define RFCOMM_SKB_HEAD_RESERVE 8
40#define RFCOMM_SKB_TAIL_RESERVE 2
41#define RFCOMM_SKB_RESERVE (RFCOMM_SKB_HEAD_RESERVE + RFCOMM_SKB_TAIL_RESERVE)
42
43#define RFCOMM_SABM 0x2f
44#define RFCOMM_DISC 0x43
45#define RFCOMM_UA 0x63
46#define RFCOMM_DM 0x0f
47#define RFCOMM_UIH 0xef
48
49#define RFCOMM_TEST 0x08
50#define RFCOMM_FCON 0x28
51#define RFCOMM_FCOFF 0x18
52#define RFCOMM_MSC 0x38
53#define RFCOMM_RPN 0x24
54#define RFCOMM_RLS 0x14
55#define RFCOMM_PN 0x20
56#define RFCOMM_NSC 0x04
57
58#define RFCOMM_V24_FC 0x02
59#define RFCOMM_V24_RTC 0x04
60#define RFCOMM_V24_RTR 0x08
61#define RFCOMM_V24_IC 0x40
62#define RFCOMM_V24_DV 0x80
63
64#define RFCOMM_RPN_BR_2400 0x0
65#define RFCOMM_RPN_BR_4800 0x1
66#define RFCOMM_RPN_BR_7200 0x2
67#define RFCOMM_RPN_BR_9600 0x3
68#define RFCOMM_RPN_BR_19200 0x4
69#define RFCOMM_RPN_BR_38400 0x5
70#define RFCOMM_RPN_BR_57600 0x6
71#define RFCOMM_RPN_BR_115200 0x7
72#define RFCOMM_RPN_BR_230400 0x8
73
74#define RFCOMM_RPN_DATA_5 0x0
75#define RFCOMM_RPN_DATA_6 0x1
76#define RFCOMM_RPN_DATA_7 0x2
77#define RFCOMM_RPN_DATA_8 0x3
78
79#define RFCOMM_RPN_STOP_1 0
80#define RFCOMM_RPN_STOP_15 1
81
82#define RFCOMM_RPN_PARITY_NONE 0x0
83#define RFCOMM_RPN_PARITY_ODD 0x4
84#define RFCOMM_RPN_PARITY_EVEN 0x5
85#define RFCOMM_RPN_PARITY_MARK 0x6
86#define RFCOMM_RPN_PARITY_SPACE 0x7
87
88#define RFCOMM_RPN_FLOW_NONE 0x00
89
90#define RFCOMM_RPN_XON_CHAR 0x11
91#define RFCOMM_RPN_XOFF_CHAR 0x13
92
93#define RFCOMM_RPN_PM_BITRATE 0x0001
94#define RFCOMM_RPN_PM_DATA 0x0002
95#define RFCOMM_RPN_PM_STOP 0x0004
96#define RFCOMM_RPN_PM_PARITY 0x0008
97#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
98#define RFCOMM_RPN_PM_XON 0x0020
99#define RFCOMM_RPN_PM_XOFF 0x0040
100#define RFCOMM_RPN_PM_FLOW 0x3F00
101
102#define RFCOMM_RPN_PM_ALL 0x3F7F
103
104struct rfcomm_hdr {
105 u8 addr;
106 u8 ctrl;
107 u8 len; // Actual size can be 2 bytes
108} __attribute__ ((packed));
109
110struct rfcomm_cmd {
111 u8 addr;
112 u8 ctrl;
113 u8 len;
114 u8 fcs;
115} __attribute__ ((packed));
116
117struct rfcomm_mcc {
118 u8 type;
119 u8 len;
120} __attribute__ ((packed));
121
122struct rfcomm_pn {
123 u8 dlci;
124 u8 flow_ctrl;
125 u8 priority;
126 u8 ack_timer;
127 u16 mtu;
128 u8 max_retrans;
129 u8 credits;
130} __attribute__ ((packed));
131
132struct rfcomm_rpn {
133 u8 dlci;
134 u8 bit_rate;
135 u8 line_settings;
136 u8 flow_ctrl;
137 u8 xon_char;
138 u8 xoff_char;
139 u16 param_mask;
140} __attribute__ ((packed));
141
142struct rfcomm_rls {
143 u8 dlci;
144 u8 status;
145} __attribute__ ((packed));
146
147struct rfcomm_msc {
148 u8 dlci;
149 u8 v24_sig;
150} __attribute__ ((packed));
151
152/* ---- Core structures, flags etc ---- */
153
154struct rfcomm_session {
155 struct list_head list;
156 struct socket *sock;
157 unsigned long state;
158 unsigned long flags;
159 atomic_t refcnt;
160 int initiator;
161
162 /* Default DLC parameters */
163 int cfc;
164 uint mtu;
165
166 struct list_head dlcs;
167};
168
169struct rfcomm_dlc {
170 struct list_head list;
171 struct rfcomm_session *session;
172 struct sk_buff_head tx_queue;
173 struct timer_list timer;
174
175 spinlock_t lock;
176 unsigned long state;
177 unsigned long flags;
178 atomic_t refcnt;
179 u8 dlci;
180 u8 addr;
181 u8 priority;
182 u8 v24_sig;
183 u8 mscex;
184
185 u32 link_mode;
186
187 uint mtu;
188 uint cfc;
189 uint rx_credits;
190 uint tx_credits;
191
192 void *owner;
193
194 void (*data_ready)(struct rfcomm_dlc *d, struct sk_buff *skb);
195 void (*state_change)(struct rfcomm_dlc *d, int err);
196 void (*modem_status)(struct rfcomm_dlc *d, u8 v24_sig);
197};
198
199/* DLC and session flags */
200#define RFCOMM_RX_THROTTLED 0
201#define RFCOMM_TX_THROTTLED 1
202#define RFCOMM_TIMED_OUT 2
203#define RFCOMM_MSC_PENDING 3
204#define RFCOMM_AUTH_PENDING 4
205#define RFCOMM_AUTH_ACCEPT 5
206#define RFCOMM_AUTH_REJECT 6
207
208/* Scheduling flags and events */
209#define RFCOMM_SCHED_STATE 0
210#define RFCOMM_SCHED_RX 1
211#define RFCOMM_SCHED_TX 2
212#define RFCOMM_SCHED_TIMEO 3
213#define RFCOMM_SCHED_AUTH 4
214#define RFCOMM_SCHED_WAKEUP 31
215
216/* MSC exchange flags */
217#define RFCOMM_MSCEX_TX 1
218#define RFCOMM_MSCEX_RX 2
219#define RFCOMM_MSCEX_OK (RFCOMM_MSCEX_TX + RFCOMM_MSCEX_RX)
220
221/* CFC states */
222#define RFCOMM_CFC_UNKNOWN -1
223#define RFCOMM_CFC_DISABLED 0
224#define RFCOMM_CFC_ENABLED RFCOMM_MAX_CREDITS
225
226/* ---- RFCOMM DLCs (channels) ---- */
227struct rfcomm_dlc *rfcomm_dlc_alloc(int prio);
228void rfcomm_dlc_free(struct rfcomm_dlc *d);
229int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel);
230int rfcomm_dlc_close(struct rfcomm_dlc *d, int reason);
231int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb);
232int rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig);
233int rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
234
235#define rfcomm_dlc_lock(d) spin_lock(&d->lock)
236#define rfcomm_dlc_unlock(d) spin_unlock(&d->lock)
237
238static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
239{
240 atomic_inc(&d->refcnt);
241}
242
243static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
244{
245 if (atomic_dec_and_test(&d->refcnt))
246 rfcomm_dlc_free(d);
247}
248
249extern void FASTCALL(__rfcomm_dlc_throttle(struct rfcomm_dlc *d));
250extern void FASTCALL(__rfcomm_dlc_unthrottle(struct rfcomm_dlc *d));
251
252static inline void rfcomm_dlc_throttle(struct rfcomm_dlc *d)
253{
254 if (!test_and_set_bit(RFCOMM_RX_THROTTLED, &d->flags))
255 __rfcomm_dlc_throttle(d);
256}
257
258static inline void rfcomm_dlc_unthrottle(struct rfcomm_dlc *d)
259{
260 if (test_and_clear_bit(RFCOMM_RX_THROTTLED, &d->flags))
261 __rfcomm_dlc_unthrottle(d);
262}
263
264/* ---- RFCOMM sessions ---- */
265void rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src, bdaddr_t *dst);
266
267static inline void rfcomm_session_hold(struct rfcomm_session *s)
268{
269 atomic_inc(&s->refcnt);
270}
271
272/* ---- RFCOMM chechsum ---- */
273extern u8 rfcomm_crc_table[];
274
275/* ---- RFCOMM sockets ---- */
276struct sockaddr_rc {
277 sa_family_t rc_family;
278 bdaddr_t rc_bdaddr;
279 u8 rc_channel;
280};
281
282#define RFCOMM_CONNINFO 0x02
283struct rfcomm_conninfo {
284 __u16 hci_handle;
285 __u8 dev_class[3];
286};
287
288#define RFCOMM_LM 0x03
289#define RFCOMM_LM_MASTER 0x0001
290#define RFCOMM_LM_AUTH 0x0002
291#define RFCOMM_LM_ENCRYPT 0x0004
292#define RFCOMM_LM_TRUSTED 0x0008
293#define RFCOMM_LM_RELIABLE 0x0010
294#define RFCOMM_LM_SECURE 0x0020
295
296#define rfcomm_pi(sk) ((struct rfcomm_pinfo *) sk)
297
298struct rfcomm_pinfo {
299 struct bt_sock bt;
300 struct rfcomm_dlc *dlc;
301 u8 channel;
302 u32 link_mode;
303};
304
305int rfcomm_init_sockets(void);
306void rfcomm_cleanup_sockets(void);
307
308int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc **d);
309
310/* ---- RFCOMM TTY ---- */
311#define RFCOMM_MAX_DEV 256
312
313#define RFCOMMCREATEDEV _IOW('R', 200, int)
314#define RFCOMMRELEASEDEV _IOW('R', 201, int)
315#define RFCOMMGETDEVLIST _IOR('R', 210, int)
316#define RFCOMMGETDEVINFO _IOR('R', 211, int)
317#define RFCOMMSTEALDLC _IOW('R', 220, int)
318
319#define RFCOMM_REUSE_DLC 0
320#define RFCOMM_RELEASE_ONHUP 1
321#define RFCOMM_HANGUP_NOW 2
322#define RFCOMM_TTY_ATTACHED 3
323
324struct rfcomm_dev_req {
325 s16 dev_id;
326 u32 flags;
327 bdaddr_t src;
328 bdaddr_t dst;
329 u8 channel;
330
331};
332
333struct rfcomm_dev_info {
334 s16 id;
335 u32 flags;
336 u16 state;
337 bdaddr_t src;
338 bdaddr_t dst;
339 u8 channel;
340};
341
342struct rfcomm_dev_list_req {
343 u16 dev_num;
344 struct rfcomm_dev_info dev_info[0];
345};
346
347int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
348int rfcomm_init_ttys(void);
349void rfcomm_cleanup_ttys(void);
350
351extern struct proc_dir_entry *proc_bt_rfcomm;
352
353#endif /* __RFCOMM_H */