1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 #ifndef _NETBT_RFCOMM_H_
64 #define _NETBT_RFCOMM_H_
65
66 #include <sys/types.h>
67
68
69
70
71
72
73
74 #define RFCOMM_MTU_MAX 32767
75 #define RFCOMM_MTU_MIN 23
76 #define RFCOMM_MTU_DEFAULT 127
77
78 #define RFCOMM_CREDITS_MAX 255
79 #define RFCOMM_CREDITS_DEFAULT 7
80
81 #define RFCOMM_CHANNEL_MIN 1
82 #define RFCOMM_CHANNEL_MAX 30
83
84
85 #define RFCOMM_FRAME_SABM 0x2f
86 #define RFCOMM_FRAME_DISC 0x43
87 #define RFCOMM_FRAME_UA 0x63
88 #define RFCOMM_FRAME_DM 0x0f
89 #define RFCOMM_FRAME_UIH 0xef
90
91
92 #define RFCOMM_MCC_TEST 0x08
93 #define RFCOMM_MCC_FCON 0x28
94 #define RFCOMM_MCC_FCOFF 0x18
95 #define RFCOMM_MCC_MSC 0x38
96 #define RFCOMM_MCC_RPN 0x24
97 #define RFCOMM_MCC_RLS 0x14
98 #define RFCOMM_MCC_PN 0x20
99 #define RFCOMM_MCC_NSC 0x04
100
101
102 #define RFCOMM_MSC_FC 0x02
103 #define RFCOMM_MSC_RTC 0x04
104 #define RFCOMM_MSC_RTR 0x08
105 #define RFCOMM_MSC_IC 0x40
106 #define RFCOMM_MSC_DV 0x80
107
108
109 #define RFCOMM_RPN_BR_2400 0x0
110 #define RFCOMM_RPN_BR_4800 0x1
111 #define RFCOMM_RPN_BR_7200 0x2
112 #define RFCOMM_RPN_BR_9600 0x3
113 #define RFCOMM_RPN_BR_19200 0x4
114 #define RFCOMM_RPN_BR_38400 0x5
115 #define RFCOMM_RPN_BR_57600 0x6
116 #define RFCOMM_RPN_BR_115200 0x7
117 #define RFCOMM_RPN_BR_230400 0x8
118
119
120 #define RFCOMM_RPN_DATA_5 0x0
121 #define RFCOMM_RPN_DATA_6 0x1
122 #define RFCOMM_RPN_DATA_7 0x2
123 #define RFCOMM_RPN_DATA_8 0x3
124
125
126 #define RFCOMM_RPN_STOP_1 0
127 #define RFCOMM_RPN_STOP_15 1
128
129
130 #define RFCOMM_RPN_PARITY_NONE 0x0
131
132
133 #define RFCOMM_RPN_PARITY_ODD 0x0
134 #define RFCOMM_RPN_PARITY_EVEN 0x1
135 #define RFCOMM_RPN_PARITY_MARK 0x2
136 #define RFCOMM_RPN_PARITY_SPACE 0x3
137
138
139 #define RFCOMM_RPN_8_N_1 0x03
140
141
142 #define RFCOMM_RPN_XON_CHAR 0x11
143 #define RFCOMM_RPN_XOFF_CHAR 0x13
144 #define RFCOMM_RPN_FLOW_NONE 0x00
145
146
147 #define RFCOMM_RPN_PM_RATE 0x0001
148 #define RFCOMM_RPN_PM_DATA 0x0002
149 #define RFCOMM_RPN_PM_STOP 0x0004
150 #define RFCOMM_RPN_PM_PARITY 0x0008
151 #define RFCOMM_RPN_PM_PTYPE 0x0010
152 #define RFCOMM_RPN_PM_XON 0x0020
153 #define RFCOMM_RPN_PM_XOFF 0x0040
154
155 #define RFCOMM_RPN_PM_FLOW 0x3f00
156
157 #define RFCOMM_RPN_PM_ALL 0x3f7f
158
159
160 struct rfcomm_cmd_hdr
161 {
162 uint8_t address;
163 uint8_t control;
164 uint8_t length;
165 uint8_t fcs;
166 } __attribute__ ((__packed__));
167
168
169 struct rfcomm_mcc_msc
170 {
171 uint8_t address;
172 uint8_t modem;
173 uint8_t brk;
174 } __attribute__ ((__packed__));
175
176
177 struct rfcomm_mcc_rpn
178 {
179 uint8_t dlci;
180 uint8_t bit_rate;
181 uint8_t line_settings;
182 uint8_t flow_control;
183 uint8_t xon_char;
184 uint8_t xoff_char;
185 uint16_t param_mask;
186 } __attribute__ ((__packed__));
187
188
189 struct rfcomm_mcc_rls
190 {
191 uint8_t address;
192 uint8_t status;
193 } __attribute__ ((__packed__));
194
195
196 struct rfcomm_mcc_pn
197 {
198 uint8_t dlci;
199 uint8_t flow_control;
200 uint8_t priority;
201 uint8_t ack_timer;
202 uint16_t mtu;
203 uint8_t max_retrans;
204 uint8_t credits;
205 } __attribute__ ((__packed__));
206
207
208 #define RFCOMM_DLCI(b) (((b) & 0xfc) >> 2)
209 #define RFCOMM_TYPE(b) (((b) & 0xef))
210
211 #define RFCOMM_EA(b) (((b) & 0x01))
212 #define RFCOMM_CR(b) (((b) & 0x02) >> 1)
213 #define RFCOMM_PF(b) (((b) & 0x10) >> 4)
214
215 #define RFCOMM_CHANNEL(dlci) (((dlci) >> 1) & 0x2f)
216 #define RFCOMM_DIRECTION(dlci) ((dlci) & 0x1)
217
218 #define RFCOMM_MKADDRESS(cr, dlci) \
219 ((((dlci) & 0x3f) << 2) | ((cr) << 1) | 0x01)
220
221 #define RFCOMM_MKCONTROL(type, pf) ((((type) & 0xef) | ((pf) << 4)))
222 #define RFCOMM_MKDLCI(dir, channel) ((((channel) & 0x1f) << 1) | (dir))
223
224
225 #define RFCOMM_MCC_TYPE(b) (((b) & 0xfc) >> 2)
226 #define RFCOMM_MCC_LENGTH(b) (((b) & 0xfe) >> 1)
227 #define RFCOMM_MKMCC_TYPE(cr, type) ((((type) << 2) | ((cr) << 1) | 0x01))
228
229
230 #define RFCOMM_RPN_DATA_BITS(line) ((line) & 0x3)
231 #define RFCOMM_RPN_STOP_BITS(line) (((line) >> 2) & 0x1)
232 #define RFCOMM_RPN_PARITY(line) (((line) >> 3) & 0x1)
233
234
235
236
237
238
239
240
241 #define SO_RFCOMM_MTU 1
242 #define SO_RFCOMM_FC_INFO 2
243 #define SO_RFCOMM_LM 3
244
245
246 struct rfcomm_fc_info {
247 uint8_t lmodem;
248 uint8_t rmodem;
249 uint8_t tx_cred;
250 uint8_t rx_cred;
251 uint8_t cfc;
252 uint8_t reserved;
253 };
254
255
256 #define RFCOMM_LM_AUTH (1<<0)
257 #define RFCOMM_LM_ENCRYPT (1<<1)
258 #define RFCOMM_LM_SECURE (1<<2)
259
260 #ifdef _KERNEL
261
262
263 extern int rfcomm_sendspace;
264 extern int rfcomm_recvspace;
265 extern int rfcomm_mtu_default;
266 extern int rfcomm_ack_timeout;
267 extern int rfcomm_mcc_timeout;
268
269
270
271
272
273
274
275 struct rfcomm_credit {
276 struct rfcomm_dlc *rc_dlc;
277 uint16_t rc_len;
278 SIMPLEQ_ENTRY(rfcomm_credit) rc_next;
279 };
280
281
282 struct rfcomm_session {
283 struct l2cap_channel *rs_l2cap;
284 uint16_t rs_flags;
285 uint16_t rs_state;
286 uint16_t rs_mtu;
287
288 SIMPLEQ_HEAD(,rfcomm_credit) rs_credits;
289 LIST_HEAD(,rfcomm_dlc) rs_dlcs;
290
291 struct timeout rs_timeout;
292
293 LIST_ENTRY(rfcomm_session) rs_next;
294 };
295
296 LIST_HEAD(rfcomm_session_list, rfcomm_session);
297 extern struct rfcomm_session_list rfcomm_session_active;
298 extern struct rfcomm_session_list rfcomm_session_listen;
299
300
301 #define RFCOMM_SESSION_CLOSED 0
302 #define RFCOMM_SESSION_WAIT_CONNECT 1
303 #define RFCOMM_SESSION_OPEN 2
304 #define RFCOMM_SESSION_WAIT_DISCONNECT 3
305 #define RFCOMM_SESSION_LISTEN 4
306
307
308 #define RFCOMM_SESSION_INITIATOR (1 << 0)
309 #define RFCOMM_SESSION_CFC (1 << 1)
310 #define RFCOMM_SESSION_LFC (1 << 2)
311 #define RFCOMM_SESSION_RFC (1 << 3)
312 #define RFCOMM_SESSION_FREE (1 << 4)
313
314 #define IS_INITIATOR(rs) ((rs)->rs_flags & RFCOMM_SESSION_INITIATOR)
315
316
317 struct rfcomm_dlc {
318 struct rfcomm_session *rd_session;
319 uint8_t rd_dlci;
320
321 uint16_t rd_flags;
322 uint16_t rd_state;
323 uint16_t rd_mtu;
324 int rd_mode;
325
326 struct sockaddr_bt rd_laddr;
327 struct sockaddr_bt rd_raddr;
328
329 uint8_t rd_lmodem;
330 uint8_t rd_rmodem;
331
332 int rd_rxcred;
333 size_t rd_rxsize;
334 int rd_txcred;
335 int rd_pending;
336
337 struct timeout rd_timeout;
338 struct mbuf *rd_txbuf;
339
340 const struct btproto *rd_proto;
341 void *rd_upper;
342
343 LIST_ENTRY(rfcomm_dlc) rd_next;
344 };
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366 #define RFCOMM_DLC_DETACH (1 << 0)
367 #define RFCOMM_DLC_SHUTDOWN (1 << 1)
368
369
370 #define RFCOMM_DLC_CLOSED 0
371 #define RFCOMM_DLC_WAIT_SESSION 1
372 #define RFCOMM_DLC_WAIT_CONNECT 2
373 #define RFCOMM_DLC_WAIT_SEND_SABM 3
374 #define RFCOMM_DLC_WAIT_SEND_UA 4
375 #define RFCOMM_DLC_WAIT_RECV_UA 5
376 #define RFCOMM_DLC_OPEN 6
377 #define RFCOMM_DLC_WAIT_DISCONNECT 7
378 #define RFCOMM_DLC_LISTEN 8
379
380
381
382
383
384 struct socket;
385
386
387 struct rfcomm_dlc *rfcomm_dlc_lookup(struct rfcomm_session *, int);
388 struct rfcomm_dlc *rfcomm_dlc_newconn(struct rfcomm_session *, int);
389 void rfcomm_dlc_close(struct rfcomm_dlc *, int);
390 void rfcomm_dlc_timeout(void *);
391 int rfcomm_dlc_setmode(struct rfcomm_dlc *);
392 int rfcomm_dlc_connect(struct rfcomm_dlc *);
393 int rfcomm_dlc_open(struct rfcomm_dlc *);
394 void rfcomm_dlc_start(struct rfcomm_dlc *);
395
396
397 void rfcomm_init(void);
398 struct rfcomm_session *rfcomm_session_alloc(struct rfcomm_session_list *, struct sockaddr_bt *);
399 struct rfcomm_session *rfcomm_session_lookup(struct sockaddr_bt *, struct sockaddr_bt *);
400 void rfcomm_session_free(struct rfcomm_session *);
401 int rfcomm_session_send_frame(struct rfcomm_session *, int, int);
402 int rfcomm_session_send_uih(struct rfcomm_session *, struct rfcomm_dlc *, int, struct mbuf *);
403 int rfcomm_session_send_mcc(struct rfcomm_session *, int, uint8_t, void *, int);
404
405
406 int rfcomm_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *);
407 int rfcomm_ctloutput(int, struct socket *, int, int, struct mbuf **);
408
409
410 int rfcomm_attach(struct rfcomm_dlc **, const struct btproto *, void *);
411 int rfcomm_bind(struct rfcomm_dlc *, struct sockaddr_bt *);
412 int rfcomm_sockaddr(struct rfcomm_dlc *, struct sockaddr_bt *);
413 int rfcomm_connect(struct rfcomm_dlc *, struct sockaddr_bt *);
414 int rfcomm_peeraddr(struct rfcomm_dlc *, struct sockaddr_bt *);
415 int rfcomm_disconnect(struct rfcomm_dlc *, int);
416 int rfcomm_detach(struct rfcomm_dlc **);
417 int rfcomm_listen(struct rfcomm_dlc *);
418 int rfcomm_send(struct rfcomm_dlc *, struct mbuf *);
419 int rfcomm_rcvd(struct rfcomm_dlc *, size_t);
420 int rfcomm_setopt(struct rfcomm_dlc *, int, void *);
421 int rfcomm_getopt(struct rfcomm_dlc *, int, void *);
422
423 #endif
424
425 #endif