initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / net / bluetooth / rfcomm.h
blob819b06dfb08a0e7d9fc7b10a3e6eab256f217d3e
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>
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;
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.
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.
24 #ifndef __RFCOMM_H
25 #define __RFCOMM_H
27 #define RFCOMM_PSM 3
29 #define RFCOMM_CONN_TIMEOUT (HZ * 30)
30 #define RFCOMM_DISC_TIMEOUT (HZ * 20)
32 #define RFCOMM_DEFAULT_MTU 127
33 #define RFCOMM_DEFAULT_CREDITS 7
35 #define RFCOMM_MAX_L2CAP_MTU 1024
36 #define RFCOMM_MAX_CREDITS 40
38 #define RFCOMM_SKB_HEAD_RESERVE 8
39 #define RFCOMM_SKB_TAIL_RESERVE 2
40 #define RFCOMM_SKB_RESERVE (RFCOMM_SKB_HEAD_RESERVE + RFCOMM_SKB_TAIL_RESERVE)
42 #define RFCOMM_SABM 0x2f
43 #define RFCOMM_DISC 0x43
44 #define RFCOMM_UA 0x63
45 #define RFCOMM_DM 0x0f
46 #define RFCOMM_UIH 0xef
48 #define RFCOMM_TEST 0x08
49 #define RFCOMM_FCON 0x28
50 #define RFCOMM_FCOFF 0x18
51 #define RFCOMM_MSC 0x38
52 #define RFCOMM_RPN 0x24
53 #define RFCOMM_RLS 0x14
54 #define RFCOMM_PN 0x20
55 #define RFCOMM_NSC 0x04
57 #define RFCOMM_V24_FC 0x02
58 #define RFCOMM_V24_RTC 0x04
59 #define RFCOMM_V24_RTR 0x08
60 #define RFCOMM_V24_IC 0x40
61 #define RFCOMM_V24_DV 0x80
63 #define RFCOMM_RPN_BR_2400 0x0
64 #define RFCOMM_RPN_BR_4800 0x1
65 #define RFCOMM_RPN_BR_7200 0x2
66 #define RFCOMM_RPN_BR_9600 0x3
67 #define RFCOMM_RPN_BR_19200 0x4
68 #define RFCOMM_RPN_BR_38400 0x5
69 #define RFCOMM_RPN_BR_57600 0x6
70 #define RFCOMM_RPN_BR_115200 0x7
71 #define RFCOMM_RPN_BR_230400 0x8
73 #define RFCOMM_RPN_DATA_5 0x0
74 #define RFCOMM_RPN_DATA_6 0x1
75 #define RFCOMM_RPN_DATA_7 0x2
76 #define RFCOMM_RPN_DATA_8 0x3
78 #define RFCOMM_RPN_STOP_1 0
79 #define RFCOMM_RPN_STOP_15 1
81 #define RFCOMM_RPN_PARITY_NONE 0x0
82 #define RFCOMM_RPN_PARITY_ODD 0x4
83 #define RFCOMM_RPN_PARITY_EVEN 0x5
84 #define RFCOMM_RPN_PARITY_MARK 0x6
85 #define RFCOMM_RPN_PARITY_SPACE 0x7
87 #define RFCOMM_RPN_FLOW_NONE 0x00
89 #define RFCOMM_RPN_XON_CHAR 0x11
90 #define RFCOMM_RPN_XOFF_CHAR 0x13
92 #define RFCOMM_RPN_PM_BITRATE 0x0001
93 #define RFCOMM_RPN_PM_DATA 0x0002
94 #define RFCOMM_RPN_PM_STOP 0x0004
95 #define RFCOMM_RPN_PM_PARITY 0x0008
96 #define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
97 #define RFCOMM_RPN_PM_XON 0x0020
98 #define RFCOMM_RPN_PM_XOFF 0x0040
99 #define RFCOMM_RPN_PM_FLOW 0x3F00
101 #define RFCOMM_RPN_PM_ALL 0x3F7F
103 struct rfcomm_hdr {
104 u8 addr;
105 u8 ctrl;
106 u8 len; // Actual size can be 2 bytes
107 } __attribute__ ((packed));
109 struct rfcomm_cmd {
110 u8 addr;
111 u8 ctrl;
112 u8 len;
113 u8 fcs;
114 } __attribute__ ((packed));
116 struct rfcomm_mcc {
117 u8 type;
118 u8 len;
119 } __attribute__ ((packed));
121 struct rfcomm_pn {
122 u8 dlci;
123 u8 flow_ctrl;
124 u8 priority;
125 u8 ack_timer;
126 u16 mtu;
127 u8 max_retrans;
128 u8 credits;
129 } __attribute__ ((packed));
131 struct rfcomm_rpn {
132 u8 dlci;
133 u8 bit_rate;
134 u8 line_settings;
135 u8 flow_ctrl;
136 u8 xon_char;
137 u8 xoff_char;
138 u16 param_mask;
139 } __attribute__ ((packed));
141 struct rfcomm_rls {
142 u8 dlci;
143 u8 status;
144 } __attribute__ ((packed));
146 struct rfcomm_msc {
147 u8 dlci;
148 u8 v24_sig;
149 } __attribute__ ((packed));
151 /* ---- Core structures, flags etc ---- */
153 struct rfcomm_session {
154 struct list_head list;
155 struct socket *sock;
156 unsigned long state;
157 unsigned long flags;
158 atomic_t refcnt;
159 int initiator;
161 /* Default DLC parameters */
162 int cfc;
163 uint mtu;
165 struct list_head dlcs;
168 struct rfcomm_dlc {
169 struct list_head list;
170 struct rfcomm_session *session;
171 struct sk_buff_head tx_queue;
172 struct timer_list timer;
174 spinlock_t lock;
175 unsigned long state;
176 unsigned long flags;
177 atomic_t refcnt;
178 u8 dlci;
179 u8 addr;
180 u8 priority;
181 u8 v24_sig;
182 u8 mscex;
184 uint mtu;
185 uint cfc;
186 uint rx_credits;
187 uint tx_credits;
189 void *owner;
191 void (*data_ready)(struct rfcomm_dlc *d, struct sk_buff *skb);
192 void (*state_change)(struct rfcomm_dlc *d, int err);
193 void (*modem_status)(struct rfcomm_dlc *d, u8 v24_sig);
196 /* DLC and session flags */
197 #define RFCOMM_RX_THROTTLED 0
198 #define RFCOMM_TX_THROTTLED 1
199 #define RFCOMM_MSC_PENDING 2
200 #define RFCOMM_TIMED_OUT 3
202 /* Scheduling flags and events */
203 #define RFCOMM_SCHED_STATE 0
204 #define RFCOMM_SCHED_RX 1
205 #define RFCOMM_SCHED_TX 2
206 #define RFCOMM_SCHED_TIMEO 3
207 #define RFCOMM_SCHED_WAKEUP 31
209 /* MSC exchange flags */
210 #define RFCOMM_MSCEX_TX 1
211 #define RFCOMM_MSCEX_RX 2
212 #define RFCOMM_MSCEX_OK (RFCOMM_MSCEX_TX + RFCOMM_MSCEX_RX)
214 /* CFC states */
215 #define RFCOMM_CFC_UNKNOWN -1
216 #define RFCOMM_CFC_DISABLED 0
217 #define RFCOMM_CFC_ENABLED RFCOMM_MAX_CREDITS
219 extern struct task_struct *rfcomm_thread;
220 extern unsigned long rfcomm_event;
222 static inline void rfcomm_schedule(uint event)
224 if (!rfcomm_thread)
225 return;
226 //set_bit(event, &rfcomm_event);
227 set_bit(RFCOMM_SCHED_WAKEUP, &rfcomm_event);
228 wake_up_process(rfcomm_thread);
231 extern struct semaphore rfcomm_sem;
232 #define rfcomm_lock() down(&rfcomm_sem);
233 #define rfcomm_unlock() up(&rfcomm_sem);
235 /* ---- RFCOMM DLCs (channels) ---- */
236 struct rfcomm_dlc *rfcomm_dlc_alloc(int prio);
237 void rfcomm_dlc_free(struct rfcomm_dlc *d);
238 int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel);
239 int rfcomm_dlc_close(struct rfcomm_dlc *d, int reason);
240 int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb);
241 int rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig);
242 int rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
244 #define rfcomm_dlc_lock(d) spin_lock(&d->lock)
245 #define rfcomm_dlc_unlock(d) spin_unlock(&d->lock)
247 static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
249 atomic_inc(&d->refcnt);
252 static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
254 if (atomic_dec_and_test(&d->refcnt))
255 rfcomm_dlc_free(d);
258 extern void FASTCALL(__rfcomm_dlc_throttle(struct rfcomm_dlc *d));
259 extern void FASTCALL(__rfcomm_dlc_unthrottle(struct rfcomm_dlc *d));
261 static inline void rfcomm_dlc_throttle(struct rfcomm_dlc *d)
263 if (!test_and_set_bit(RFCOMM_RX_THROTTLED, &d->flags))
264 __rfcomm_dlc_throttle(d);
267 static inline void rfcomm_dlc_unthrottle(struct rfcomm_dlc *d)
269 if (test_and_clear_bit(RFCOMM_RX_THROTTLED, &d->flags))
270 __rfcomm_dlc_unthrottle(d);
273 /* ---- RFCOMM sessions ---- */
274 struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state);
275 struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst);
276 struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst, int *err);
277 void rfcomm_session_del(struct rfcomm_session *s);
278 void rfcomm_session_close(struct rfcomm_session *s, int err);
279 void rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src, bdaddr_t *dst);
281 static inline void rfcomm_session_hold(struct rfcomm_session *s)
283 atomic_inc(&s->refcnt);
286 static inline void rfcomm_session_put(struct rfcomm_session *s)
288 if (atomic_dec_and_test(&s->refcnt))
289 rfcomm_session_del(s);
292 /* ---- RFCOMM chechsum ---- */
293 extern u8 rfcomm_crc_table[];
295 /* ---- RFCOMM sockets ---- */
296 struct sockaddr_rc {
297 sa_family_t rc_family;
298 bdaddr_t rc_bdaddr;
299 u8 rc_channel;
302 #define rfcomm_pi(sk) ((struct rfcomm_pinfo *)sk->sk_protinfo)
304 struct rfcomm_pinfo {
305 struct rfcomm_dlc *dlc;
306 u8 channel;
309 int rfcomm_init_sockets(void);
310 void rfcomm_cleanup_sockets(void);
312 int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc **d);
314 /* ---- RFCOMM TTY ---- */
315 #define RFCOMM_MAX_DEV 256
317 #define RFCOMMCREATEDEV _IOW('R', 200, int)
318 #define RFCOMMRELEASEDEV _IOW('R', 201, int)
319 #define RFCOMMGETDEVLIST _IOR('R', 210, int)
320 #define RFCOMMGETDEVINFO _IOR('R', 211, int)
321 #define RFCOMMSTEALDLC _IOW('R', 220, int)
323 #define RFCOMM_REUSE_DLC 0
324 #define RFCOMM_RELEASE_ONHUP 1
325 #define RFCOMM_HANGUP_NOW 2
326 #define RFCOMM_TTY_ATTACHED 3
328 struct rfcomm_dev_req {
329 s16 dev_id;
330 u32 flags;
331 bdaddr_t src;
332 bdaddr_t dst;
333 u8 channel;
337 struct rfcomm_dev_info {
338 s16 id;
339 u32 flags;
340 u16 state;
341 bdaddr_t src;
342 bdaddr_t dst;
343 u8 channel;
346 struct rfcomm_dev_list_req {
347 u16 dev_num;
348 struct rfcomm_dev_info dev_info[0];
351 int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
352 int rfcomm_init_ttys(void);
353 void rfcomm_cleanup_ttys(void);
355 extern struct proc_dir_entry *proc_bt_rfcomm;
357 #endif /* __RFCOMM_H */