Blame view

include/net/bluetooth/rfcomm.h 9.16 KB
be21871f2   Andrei Emeltchenko   Bluetooth: clean ...
1
2
  /*
     RFCOMM implementation for Linux Bluetooth stack (BlueZ)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
8
9
10
11
12
13
     Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
     Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation;
  
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
     IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
be21871f2   Andrei Emeltchenko   Bluetooth: clean ...
14
15
16
     CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
     WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
be21871f2   Andrei Emeltchenko   Bluetooth: clean ...
18
19
     ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
     COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
     SOFTWARE IS DISCLAIMED.
  */
dab6b5dae   Elena Reshetova   Bluetooth: conver...
22
  #include <linux/refcount.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
  #ifndef __RFCOMM_H
  #define __RFCOMM_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
  #define RFCOMM_CONN_TIMEOUT (HZ * 30)
  #define RFCOMM_DISC_TIMEOUT (HZ * 20)
  #define RFCOMM_AUTH_TIMEOUT (HZ * 25)
9e726b174   Luiz Augusto von Dentz   Bluetooth: Fix re...
28
  #define RFCOMM_IDLE_TIMEOUT (HZ * 2)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
  
  #define RFCOMM_DEFAULT_MTU	127
  #define RFCOMM_DEFAULT_CREDITS	7
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  #define RFCOMM_MAX_CREDITS	40
  
  #define RFCOMM_SKB_HEAD_RESERVE	8
  #define RFCOMM_SKB_TAIL_RESERVE	2
  #define RFCOMM_SKB_RESERVE  (RFCOMM_SKB_HEAD_RESERVE + RFCOMM_SKB_TAIL_RESERVE)
  
  #define RFCOMM_SABM	0x2f
  #define RFCOMM_DISC	0x43
  #define RFCOMM_UA	0x63
  #define RFCOMM_DM	0x0f
  #define RFCOMM_UIH	0xef
  
  #define RFCOMM_TEST	0x08
  #define RFCOMM_FCON	0x28
  #define RFCOMM_FCOFF	0x18
  #define RFCOMM_MSC	0x38
  #define RFCOMM_RPN	0x24
  #define RFCOMM_RLS	0x14
  #define RFCOMM_PN	0x20
  #define RFCOMM_NSC	0x04
  
  #define RFCOMM_V24_FC	0x02
  #define RFCOMM_V24_RTC	0x04
  #define RFCOMM_V24_RTR	0x08
  #define RFCOMM_V24_IC	0x40
  #define RFCOMM_V24_DV	0x80
  
  #define RFCOMM_RPN_BR_2400	0x0
  #define RFCOMM_RPN_BR_4800	0x1
  #define RFCOMM_RPN_BR_7200	0x2
  #define RFCOMM_RPN_BR_9600	0x3
  #define RFCOMM_RPN_BR_19200	0x4
  #define RFCOMM_RPN_BR_38400	0x5
  #define RFCOMM_RPN_BR_57600	0x6
  #define RFCOMM_RPN_BR_115200	0x7
  #define RFCOMM_RPN_BR_230400	0x8
  
  #define RFCOMM_RPN_DATA_5	0x0
  #define RFCOMM_RPN_DATA_6	0x1
  #define RFCOMM_RPN_DATA_7	0x2
  #define RFCOMM_RPN_DATA_8	0x3
  
  #define RFCOMM_RPN_STOP_1	0
  #define RFCOMM_RPN_STOP_15	1
  
  #define RFCOMM_RPN_PARITY_NONE	0x0
3a5e903c0   J. Suter   [Bluetooth]: Impl...
78
79
80
  #define RFCOMM_RPN_PARITY_ODD	0x1
  #define RFCOMM_RPN_PARITY_EVEN	0x3
  #define RFCOMM_RPN_PARITY_MARK	0x5
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  #define RFCOMM_RPN_PARITY_SPACE	0x7
  
  #define RFCOMM_RPN_FLOW_NONE	0x00
  
  #define RFCOMM_RPN_XON_CHAR	0x11
  #define RFCOMM_RPN_XOFF_CHAR	0x13
  
  #define RFCOMM_RPN_PM_BITRATE		0x0001
  #define RFCOMM_RPN_PM_DATA		0x0002
  #define RFCOMM_RPN_PM_STOP		0x0004
  #define RFCOMM_RPN_PM_PARITY		0x0008
  #define RFCOMM_RPN_PM_PARITY_TYPE	0x0010
  #define RFCOMM_RPN_PM_XON		0x0020
  #define RFCOMM_RPN_PM_XOFF		0x0040
  #define RFCOMM_RPN_PM_FLOW		0x3F00
  
  #define RFCOMM_RPN_PM_ALL		0x3F7F
  
  struct rfcomm_hdr {
  	u8 addr;
  	u8 ctrl;
285b4e903   Andrei Emeltchenko   Bluetooth: clean ...
102
  	u8 len;    /* Actual size can be 2 bytes */
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
103
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
107
108
109
  
  struct rfcomm_cmd {
  	u8 addr;
  	u8 ctrl;
  	u8 len;
  	u8 fcs;
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
110
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
  
  struct rfcomm_mcc {
  	u8 type;
  	u8 len;
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
115
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116
117
118
119
120
121
  
  struct rfcomm_pn {
  	u8  dlci;
  	u8  flow_ctrl;
  	u8  priority;
  	u8  ack_timer;
6ba9c755e   Al Viro   [BLUETOOTH]: rfco...
122
  	__le16 mtu;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
  	u8  max_retrans;
  	u8  credits;
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
125
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
127
128
129
130
131
132
133
  
  struct rfcomm_rpn {
  	u8  dlci;
  	u8  bit_rate;
  	u8  line_settings;
  	u8  flow_ctrl;
  	u8  xon_char;
  	u8  xoff_char;
6ba9c755e   Al Viro   [BLUETOOTH]: rfco...
134
  	__le16 param_mask;
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
135
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
137
138
139
  
  struct rfcomm_rls {
  	u8  dlci;
  	u8  status;
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
140
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
142
143
144
  
  struct rfcomm_msc {
  	u8  dlci;
  	u8  v24_sig;
66c853cc2   Gustavo F. Padovan   Bluetooth: Use __...
145
  } __packed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
147
148
149
150
151
  
  /* ---- Core structures, flags etc ---- */
  
  struct rfcomm_session {
  	struct list_head list;
  	struct socket   *sock;
9e726b174   Luiz Augusto von Dentz   Bluetooth: Fix re...
152
  	struct timer_list timer;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
  	unsigned long    state;
  	unsigned long    flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  	int              initiator;
  
  	/* Default DLC parameters */
  	int    cfc;
  	uint   mtu;
  
  	struct list_head dlcs;
  };
  
  struct rfcomm_dlc {
  	struct list_head      list;
  	struct rfcomm_session *session;
  	struct sk_buff_head   tx_queue;
  	struct timer_list     timer;
86aae6c7b   Libor Pechacek   Bluetooth: Conver...
169
  	struct mutex  lock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
  	unsigned long state;
  	unsigned long flags;
dab6b5dae   Elena Reshetova   Bluetooth: conver...
172
  	refcount_t    refcnt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173
174
175
176
  	u8            dlci;
  	u8            addr;
  	u8            priority;
  	u8            v24_sig;
8b6b3da76   Marcel Holtmann   [Bluetooth] Store...
177
  	u8            remote_v24_sig;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
  	u8            mscex;
77db19805   Marcel Holtmann   [Bluetooth] Enfor...
179
  	u8            out;
9f2c8a03f   Marcel Holtmann   Bluetooth: Replac...
180
181
  	u8            sec_level;
  	u8            role_switch;
bb23c0ab8   Marcel Holtmann   Bluetooth: Add su...
182
  	u32           defer_setup;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  
  	uint          mtu;
  	uint          cfc;
  	uint          rx_credits;
  	uint          tx_credits;
  
  	void          *owner;
  
  	void (*data_ready)(struct rfcomm_dlc *d, struct sk_buff *skb);
  	void (*state_change)(struct rfcomm_dlc *d, int err);
  	void (*modem_status)(struct rfcomm_dlc *d, u8 v24_sig);
  };
  
  /* DLC and session flags */
  #define RFCOMM_RX_THROTTLED 0
  #define RFCOMM_TX_THROTTLED 1
  #define RFCOMM_TIMED_OUT    2
bb23c0ab8   Marcel Holtmann   Bluetooth: Add su...
200
  #define RFCOMM_MSC_PENDING  3
8c84b8307   Marcel Holtmann   Bluetooth: Pause ...
201
202
203
204
205
  #define RFCOMM_SEC_PENDING  4
  #define RFCOMM_AUTH_PENDING 5
  #define RFCOMM_AUTH_ACCEPT  6
  #define RFCOMM_AUTH_REJECT  7
  #define RFCOMM_DEFER_SETUP  8
88149db49   Szymon Janc   Bluetooth: rfcomm...
206
  #define RFCOMM_ENC_DROP     9
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
  
  /* Scheduling flags and events */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
211
212
213
214
215
216
217
218
219
  #define RFCOMM_SCHED_WAKEUP 31
  
  /* MSC exchange flags */
  #define RFCOMM_MSCEX_TX     1
  #define RFCOMM_MSCEX_RX     2
  #define RFCOMM_MSCEX_OK     (RFCOMM_MSCEX_TX + RFCOMM_MSCEX_RX)
  
  /* CFC states */
  #define RFCOMM_CFC_UNKNOWN  -1
  #define RFCOMM_CFC_DISABLED 0
  #define RFCOMM_CFC_ENABLED  RFCOMM_MAX_CREDITS
3a5e903c0   J. Suter   [Bluetooth]: Impl...
220
221
222
  /* ---- RFCOMM SEND RPN ---- */
  int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
  			u8 bit_rate, u8 data_bits, u8 stop_bits,
285b4e903   Andrei Emeltchenko   Bluetooth: clean ...
223
  			u8 parity, u8 flow_ctrl_settings,
3a5e903c0   J. Suter   [Bluetooth]: Impl...
224
  			u8 xon_char, u8 xoff_char, u16 param_mask);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
  /* ---- RFCOMM DLCs (channels) ---- */
dd0fc66fb   Al Viro   [PATCH] gfp flags...
226
  struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
  void rfcomm_dlc_free(struct rfcomm_dlc *d);
5a9d0a3ff   Waldemar Rymarkiewicz   Bluetooth: Clean ...
228
229
  int  rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst,
  								u8 channel);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
  int  rfcomm_dlc_close(struct rfcomm_dlc *d, int reason);
  int  rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb);
72e5108c6   Peter Hurley   Bluetooth: Don't ...
232
  void rfcomm_dlc_send_noerror(struct rfcomm_dlc *d, struct sk_buff *skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
  int  rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig);
  int  rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
bb23c0ab8   Marcel Holtmann   Bluetooth: Add su...
235
  void rfcomm_dlc_accept(struct rfcomm_dlc *d);
c10a848ce   Peter Hurley   Bluetooth: Verify...
236
  struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237

86aae6c7b   Libor Pechacek   Bluetooth: Conver...
238
239
  #define rfcomm_dlc_lock(d)     mutex_lock(&d->lock)
  #define rfcomm_dlc_unlock(d)   mutex_unlock(&d->lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240
241
242
  
  static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
  {
dab6b5dae   Elena Reshetova   Bluetooth: conver...
243
  	refcount_inc(&d->refcnt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
246
247
  }
  
  static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
  {
dab6b5dae   Elena Reshetova   Bluetooth: conver...
248
  	if (refcount_dec_and_test(&d->refcnt))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
  		rfcomm_dlc_free(d);
  }
e74e58f8d   Joe Perches   bluetooth: Remove...
251
252
  void __rfcomm_dlc_throttle(struct rfcomm_dlc *d);
  void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  
  static inline void rfcomm_dlc_throttle(struct rfcomm_dlc *d)
  {
  	if (!test_and_set_bit(RFCOMM_RX_THROTTLED, &d->flags))
  		__rfcomm_dlc_throttle(d);
  }
  
  static inline void rfcomm_dlc_unthrottle(struct rfcomm_dlc *d)
  {
  	if (test_and_clear_bit(RFCOMM_RX_THROTTLED, &d->flags))
  		__rfcomm_dlc_unthrottle(d);
  }
  
  /* ---- RFCOMM sessions ---- */
5a9d0a3ff   Waldemar Rymarkiewicz   Bluetooth: Clean ...
267
268
  void   rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src,
  								bdaddr_t *dst);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  /* ---- RFCOMM sockets ---- */
  struct sockaddr_rc {
  	sa_family_t	rc_family;
  	bdaddr_t	rc_bdaddr;
  	u8		rc_channel;
  };
  
  #define RFCOMM_CONNINFO	0x02
  struct rfcomm_conninfo {
  	__u16 hci_handle;
  	__u8  dev_class[3];
  };
  
  #define RFCOMM_LM	0x03
  #define RFCOMM_LM_MASTER	0x0001
  #define RFCOMM_LM_AUTH		0x0002
  #define RFCOMM_LM_ENCRYPT	0x0004
  #define RFCOMM_LM_TRUSTED	0x0008
  #define RFCOMM_LM_RELIABLE	0x0010
  #define RFCOMM_LM_SECURE	0x0020
2c068e0b9   Marcel Holtmann   Bluetooth: Handle...
290
  #define RFCOMM_LM_FIPS		0x0040
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
291
292
293
294
295
  
  #define rfcomm_pi(sk) ((struct rfcomm_pinfo *) sk)
  
  struct rfcomm_pinfo {
  	struct bt_sock bt;
94a86df01   Marcel Holtmann   Bluetooth: Store ...
296
297
  	bdaddr_t src;
  	bdaddr_t dst;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
  	struct rfcomm_dlc   *dlc;
  	u8     channel;
9f2c8a03f   Marcel Holtmann   Bluetooth: Replac...
300
301
  	u8     sec_level;
  	u8     role_switch;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
303
304
305
  };
  
  int  rfcomm_init_sockets(void);
  void rfcomm_cleanup_sockets(void);
5a9d0a3ff   Waldemar Rymarkiewicz   Bluetooth: Clean ...
306
307
  int  rfcomm_connect_ind(struct rfcomm_session *s, u8 channel,
  							struct rfcomm_dlc **d);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
309
310
311
312
313
314
315
316
  
  /* ---- RFCOMM TTY ---- */
  #define RFCOMM_MAX_DEV  256
  
  #define RFCOMMCREATEDEV		_IOW('R', 200, int)
  #define RFCOMMRELEASEDEV	_IOW('R', 201, int)
  #define RFCOMMGETDEVLIST	_IOR('R', 210, int)
  #define RFCOMMGETDEVINFO	_IOR('R', 211, int)
  #define RFCOMMSTEALDLC		_IOW('R', 220, int)
1c64834e0   Peter Hurley   Bluetooth: Releas...
317
  /* rfcomm_dev.flags bit definitions */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
318
319
320
321
  #define RFCOMM_REUSE_DLC      0
  #define RFCOMM_RELEASE_ONHUP  1
  #define RFCOMM_HANGUP_NOW     2
  #define RFCOMM_TTY_ATTACHED   3
1c64834e0   Peter Hurley   Bluetooth: Releas...
322
323
324
325
  #define RFCOMM_DEFUNCT_BIT4   4	  /* don't reuse this bit - userspace visible */
  
  /* rfcomm_dev.status bit definitions */
  #define RFCOMM_DEV_RELEASED   0
80ea73378   Peter Hurley   Bluetooth: Fix un...
326
  #define RFCOMM_TTY_OWNED      1
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
328
329
330
331
332
333
  
  struct rfcomm_dev_req {
  	s16      dev_id;
  	u32      flags;
  	bdaddr_t src;
  	bdaddr_t dst;
  	u8       channel;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
334
335
336
337
338
339
340
341
342
343
344
345
346
  };
  
  struct rfcomm_dev_info {
  	s16      id;
  	u32      flags;
  	u16      state;
  	bdaddr_t src;
  	bdaddr_t dst;
  	u8       channel;
  };
  
  struct rfcomm_dev_list_req {
  	u16      dev_num;
a7e454542   Gustavo A. R. Silva   Bluetooth: Replac...
347
  	struct   rfcomm_dev_info dev_info[];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
349
350
  };
  
  int  rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
af0d3b103   Dave Young   bluetooth: rfcomm...
351
352
  
  #ifdef CONFIG_BT_RFCOMM_TTY
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
354
  int  rfcomm_init_ttys(void);
  void rfcomm_cleanup_ttys(void);
af0d3b103   Dave Young   bluetooth: rfcomm...
355
356
357
358
359
360
361
362
363
  #else
  static inline int rfcomm_init_ttys(void)
  {
  	return 0;
  }
  static inline void rfcomm_cleanup_ttys(void)
  {
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
  #endif /* __RFCOMM_H */