This source file includes following definitions.
- l2cap_qos_t
- l2cap_rfc_t
- l2cap_hdr_t
- l2cap_clt_hdr_t
- l2cap_cmd_hdr_t
- l2cap_cmd_rej_cp
- l2cap_con_req_cp
- l2cap_con_rsp_cp
- l2cap_cfg_req_cp
- l2cap_cfg_rsp_cp
- l2cap_cfg_opt_t
- l2cap_cfg_opt_val_t
- l2cap_discon_req_cp
- l2cap_info_req_cp
- l2cap_info_rsp_cp
- l2cap_info_rsp_data_t
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
64
65
66
67
68
69
70 #ifndef _NETBT_L2CAP_H_
71 #define _NETBT_L2CAP_H_
72
73 #include <sys/types.h>
74
75
76
77
78
79
80
81
82
83
84
85
86
87 #define L2CAP_NULL_CID 0x0000
88 #define L2CAP_SIGNAL_CID 0x0001
89 #define L2CAP_CLT_CID 0x0002
90
91 #define L2CAP_FIRST_CID 0x0040
92 #define L2CAP_LAST_CID 0xffff
93
94
95 #define L2CAP_MTU_MINIMUM 48
96 #define L2CAP_MTU_DEFAULT 672
97 #define L2CAP_MTU_MAXIMUM 0xffff
98
99
100 #define L2CAP_FLUSH_TIMO_DEFAULT 0xffff
101 #define L2CAP_LINK_TIMO_DEFAULT 0xffff
102
103
104 #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000
105 #define L2CAP_REJ_MTU_EXCEEDED 0x0001
106 #define L2CAP_REJ_INVALID_CID 0x0002
107
108
109
110 #define L2CAP_PSM_ANY 0x0000
111 #define L2CAP_PSM_SDP 0x0001
112 #define L2CAP_PSM_RFCOMM 0x0003
113 #define L2CAP_PSM_TCP 0x0005
114 #define L2CAP_PSM_TCS 0x0007
115 #define L2CAP_PSM_BNEP 0x000f
116
117 #define L2CAP_PSM_HID_CNTL 0x0011
118 #define L2CAP_PSM_HID_INTR 0x0013
119 #define L2CAP_PSM_ESDP 0x0015
120
121 #define L2CAP_PSM_AVCTP 0x0017
122
123 #define L2CAP_PSM_AVDTP 0x0019
124
125
126
127 #define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001)
128
129
130 #define L2CAP_SUCCESS 0x0000
131 #define L2CAP_PENDING 0x0001
132 #define L2CAP_PSM_NOT_SUPPORTED 0x0002
133 #define L2CAP_SECURITY_BLOCK 0x0003
134 #define L2CAP_NO_RESOURCES 0x0004
135 #define L2CAP_TIMEOUT 0xeeee
136 #define L2CAP_UNKNOWN 0xffff
137
138
139
140 #define L2CAP_NO_INFO 0x0000
141 #define L2CAP_AUTH_PENDING 0x0001
142 #define L2CAP_AUTZ_PENDING 0x0002
143
144
145
146 #define L2CAP_UNACCEPTABLE_PARAMS 0x0001
147 #define L2CAP_REJECT 0x0002
148 #define L2CAP_UNKNOWN_OPTION 0x0003
149
150
151
152 #define L2CAP_OPT_CFLAG_BIT 0x0001
153 #define L2CAP_OPT_CFLAG(flags) ((flags) & L2CAP_OPT_CFLAG_BIT)
154 #define L2CAP_OPT_HINT_BIT 0x80
155 #define L2CAP_OPT_HINT(type) ((type) & L2CAP_OPT_HINT_BIT)
156 #define L2CAP_OPT_HINT_MASK 0x7f
157 #define L2CAP_OPT_MTU 0x01
158 #define L2CAP_OPT_MTU_SIZE sizeof(uint16_t)
159 #define L2CAP_OPT_FLUSH_TIMO 0x02
160 #define L2CAP_OPT_FLUSH_TIMO_SIZE sizeof(uint16_t)
161 #define L2CAP_OPT_QOS 0x03
162 #define L2CAP_OPT_QOS_SIZE sizeof(l2cap_qos_t)
163 #define L2CAP_OPT_RFC 0x04
164 #define L2CAP_OPT_RFC_SIZE sizeof(l2cap_rfc_t)
165
166
167
168 #define L2CAP_CONNLESS_MTU 0x0001
169 #define L2CAP_EXTENDED_FEATURES 0x0002
170
171
172
173 #define L2CAP_NOT_SUPPORTED 0x0001
174
175
176
177 typedef struct {
178 uint8_t flags;
179 uint8_t service_type;
180 uint32_t token_rate;
181 uint32_t token_bucket_size;
182 uint32_t peak_bandwidth;
183 uint32_t latency;
184 uint32_t delay_variation;
185 } __attribute__ ((__packed__)) l2cap_qos_t;
186
187
188 #define L2CAP_QOS_NO_TRAFFIC 0x00
189 #define L2CAP_QOS_BEST_EFFORT 0x01
190 #define L2CAP_QOS_GUARANTEED 0x02
191
192
193
194 typedef struct {
195 uint8_t mode;
196 uint8_t window_size;
197 uint8_t max_transmit;
198 uint16_t retransmit_timo;
199 uint16_t monitor_timo;
200 uint16_t max_pdu_size;
201 } __attribute__ ((__packed__)) l2cap_rfc_t;
202
203
204 #define L2CAP_RFC_BASIC 0x00
205 #define L2CAP_RFC_RETRANSMIT 0x01
206 #define L2CAP_RFC_FLOW 0x02
207
208
209
210
211
212
213
214
215
216 typedef struct {
217 uint16_t length;
218 uint16_t dcid;
219 } __attribute__ ((__packed__)) l2cap_hdr_t;
220
221
222 typedef struct {
223 uint16_t psm;
224 } __attribute__ ((__packed__)) l2cap_clt_hdr_t;
225
226 #define L2CAP_CLT_MTU_MAXIMUM \
227 (L2CAP_MTU_MAXIMUM - sizeof(l2cap_clt_hdr_t))
228
229
230 typedef struct {
231 uint8_t code;
232 uint8_t ident;
233 uint16_t length;
234 } __attribute__ ((__packed__)) l2cap_cmd_hdr_t;
235
236
237 #define L2CAP_COMMAND_REJ 0x01
238 typedef struct {
239 uint16_t reason;
240 uint16_t data[2];
241 } __attribute__ ((__packed__)) l2cap_cmd_rej_cp;
242
243
244 #define L2CAP_CONNECT_REQ 0x02
245 typedef struct {
246 uint16_t psm;
247 uint16_t scid;
248 } __attribute__ ((__packed__)) l2cap_con_req_cp;
249
250
251 #define L2CAP_CONNECT_RSP 0x03
252 typedef struct {
253 uint16_t dcid;
254 uint16_t scid;
255 uint16_t result;
256 uint16_t status;
257 } __attribute__ ((__packed__)) l2cap_con_rsp_cp;
258
259
260 #define L2CAP_CONFIG_REQ 0x04
261 typedef struct {
262 uint16_t dcid;
263 uint16_t flags;
264
265 } __attribute__ ((__packed__)) l2cap_cfg_req_cp;
266
267
268 #define L2CAP_CONFIG_RSP 0x05
269 typedef struct {
270 uint16_t scid;
271 uint16_t flags;
272 uint16_t result;
273
274 } __attribute__ ((__packed__)) l2cap_cfg_rsp_cp;
275
276
277 typedef struct {
278 uint8_t type;
279 uint8_t length;
280
281 } __attribute__ ((__packed__)) l2cap_cfg_opt_t;
282
283
284 typedef union {
285 uint16_t mtu;
286 uint16_t flush_timo;
287 l2cap_qos_t qos;
288 l2cap_rfc_t rfc;
289 } l2cap_cfg_opt_val_t;
290
291
292 #define L2CAP_DISCONNECT_REQ 0x06
293 typedef struct {
294 uint16_t dcid;
295 uint16_t scid;
296 } __attribute__ ((__packed__)) l2cap_discon_req_cp;
297
298
299 #define L2CAP_DISCONNECT_RSP 0x07
300 typedef l2cap_discon_req_cp l2cap_discon_rsp_cp;
301
302
303 #define L2CAP_ECHO_REQ 0x08
304
305
306
307 #define L2CAP_ECHO_RSP 0x09
308 #define L2CAP_MAX_ECHO_SIZE \
309 (L2CAP_MTU_MAXIMUM - sizeof(l2cap_cmd_hdr_t))
310
311
312
313 #define L2CAP_INFO_REQ 0x0a
314 typedef struct {
315 uint16_t type;
316 } __attribute__ ((__packed__)) l2cap_info_req_cp;
317
318
319 #define L2CAP_INFO_RSP 0x0b
320 typedef struct {
321 uint16_t type;
322 uint16_t result;
323
324
325
326
327 } __attribute__ ((__packed__)) l2cap_info_rsp_cp;
328
329 typedef union {
330
331 struct {
332 uint16_t mtu;
333 } __attribute__ ((__packed__)) mtu;
334 } l2cap_info_rsp_data_t;
335
336
337
338
339
340
341
342
343 #define SO_L2CAP_IMTU 1
344 #define SO_L2CAP_OMTU 2
345 #define SO_L2CAP_IQOS 3
346 #define SO_L2CAP_OQOS 4
347 #define SO_L2CAP_FLUSH 5
348 #define SO_L2CAP_LM 6
349
350
351 #define L2CAP_LM_AUTH (1<<0)
352 #define L2CAP_LM_ENCRYPT (1<<1)
353 #define L2CAP_LM_SECURE (1<<2)
354
355 #ifdef _KERNEL
356
357 #include <net/if.h>
358
359 LIST_HEAD(l2cap_channel_list, l2cap_channel);
360
361
362 extern struct l2cap_channel_list l2cap_active_list;
363 extern struct l2cap_channel_list l2cap_listen_list;
364 extern struct pool l2cap_pdu_pool;
365 extern struct pool l2cap_req_pool;
366 extern const l2cap_qos_t l2cap_default_qos;
367
368
369 extern int l2cap_response_timeout;
370 extern int l2cap_response_extended_timeout;
371 extern int l2cap_sendspace, l2cap_recvspace;
372
373
374
375
376 struct l2cap_channel {
377 struct hci_link *lc_link;
378 uint16_t lc_state;
379 uint16_t lc_flags;
380 uint8_t lc_ident;
381
382 uint16_t lc_lcid;
383 struct sockaddr_bt lc_laddr;
384
385 uint16_t lc_rcid;
386 struct sockaddr_bt lc_raddr;
387
388 int lc_mode;
389 uint16_t lc_imtu;
390 uint16_t lc_omtu;
391 uint16_t lc_flush;
392 l2cap_qos_t lc_iqos;
393 l2cap_qos_t lc_oqos;
394
395 uint8_t lc_pending;
396 struct ifqueue lc_txq;
397
398 const struct btproto *lc_proto;
399 void *lc_upper;
400
401 LIST_ENTRY(l2cap_channel)lc_ncid;
402 };
403
404
405 #define L2CAP_CLOSED 0
406 #define L2CAP_WAIT_SEND_CONNECT_REQ 1
407 #define L2CAP_WAIT_RECV_CONNECT_RSP 2
408 #define L2CAP_WAIT_SEND_CONNECT_RSP 3
409 #define L2CAP_WAIT_CONFIG 4
410 #define L2CAP_OPEN 5
411 #define L2CAP_WAIT_DISCONNECT 6
412
413
414 #define L2CAP_SHUTDOWN (1<<0)
415 #define L2CAP_WAIT_CONFIG_REQ (1<<1)
416 #define L2CAP_WAIT_CONFIG_RSP (1<<2)
417
418
419
420
421 struct l2cap_req {
422 struct hci_link *lr_link;
423 struct l2cap_channel *lr_chan;
424 uint8_t lr_code;
425 uint8_t lr_id;
426 struct timeout lr_rtx;
427 TAILQ_ENTRY(l2cap_req) lr_next;
428 };
429
430
431
432
433 struct l2cap_pdu {
434 struct l2cap_channel *lp_chan;
435 struct ifqueue lp_data;
436 TAILQ_ENTRY(l2cap_pdu) lp_next;
437 int lp_pending;
438 };
439
440
441
442
443
444 struct socket;
445 struct mbuf;
446
447
448 void l2cap_close(struct l2cap_channel *, int);
449 void l2cap_recv_frame(struct mbuf *, struct hci_link *);
450 int l2cap_start(struct l2cap_channel *);
451
452
453 void l2cap_init(void);
454 int l2cap_setmode(struct l2cap_channel *);
455 int l2cap_cid_alloc(struct l2cap_channel *);
456 struct l2cap_channel *l2cap_cid_lookup(uint16_t);
457 int l2cap_request_alloc(struct l2cap_channel *, uint8_t);
458 struct l2cap_req *l2cap_request_lookup(struct hci_link *, uint8_t);
459 void l2cap_request_free(struct l2cap_req *);
460 void l2cap_rtx(void *);
461
462
463 void l2cap_recv_signal(struct mbuf *, struct hci_link *);
464 int l2cap_send_connect_req(struct l2cap_channel *);
465 int l2cap_send_config_req(struct l2cap_channel *);
466 int l2cap_send_disconnect_req(struct l2cap_channel *);
467 int l2cap_send_connect_rsp(struct hci_link *, uint8_t, uint16_t, uint16_t, uint16_t);
468
469
470 int l2cap_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *);
471 int l2cap_ctloutput(int, struct socket *, int, int, struct mbuf **);
472
473
474 int l2cap_attach(struct l2cap_channel **, const struct btproto *, void *);
475 int l2cap_bind(struct l2cap_channel *, struct sockaddr_bt *);
476 int l2cap_sockaddr(struct l2cap_channel *, struct sockaddr_bt *);
477 int l2cap_connect(struct l2cap_channel *, struct sockaddr_bt *);
478 int l2cap_peeraddr(struct l2cap_channel *, struct sockaddr_bt *);
479 int l2cap_disconnect(struct l2cap_channel *, int);
480 int l2cap_detach(struct l2cap_channel **);
481 int l2cap_listen(struct l2cap_channel *);
482 int l2cap_send(struct l2cap_channel *, struct mbuf *);
483 int l2cap_setopt(struct l2cap_channel *, int, void *);
484 int l2cap_getopt(struct l2cap_channel *, int, void *);
485
486 #endif
487
488 #endif