1 /*
2  * ng_l2cap.h
3  */
4 
5 /*-
6  * Copyright (c) Maksim Yevmenkin <m_evmenkin@yahoo.com>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $Id: ng_l2cap.h,v 1.2 2003/04/27 00:52:26 max Exp $
31  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_l2cap.h,v 1.4 2005/08/31 18:13:23 emax Exp $
32  */
33 
34 /*
35  * This file contains everything that application needs to know about
36  * Link Layer Control and Adaptation Protocol (L2CAP). All information
37  * was obtained from Bluetooth Specification Book v1.1.
38  *
39  * This file can be included by both kernel and userland applications.
40  */
41 
42 #ifndef _NETGRAPH_L2CAP_H_
43 #define _NETGRAPH_L2CAP_H_
44 
45 /**************************************************************************
46  **************************************************************************
47  **     Netgraph node hook name, type name and type cookie and commands
48  **************************************************************************
49  **************************************************************************/
50 
51 /* Netgraph node hook names */
52 #define NG_L2CAP_HOOK_HCI		"hci"	/* HCI   <-> L2CAP */
53 #define NG_L2CAP_HOOK_L2C		"l2c"	/* L2CAP <-> Upper */
54 #define NG_L2CAP_HOOK_CTL		"ctl"	/* L2CAP <-> User  */
55 
56 /* Node type name and type cookie */
57 #define NG_L2CAP_NODE_TYPE		"l2cap"
58 #define NGM_L2CAP_COOKIE		1000774185
59 
60 /**************************************************************************
61  **************************************************************************
62  **                   Common defines and types (L2CAP)
63  **************************************************************************
64  **************************************************************************/
65 
66 /*
67  * Channel IDs are assigned relative to the instance of L2CAP node, i.e.
68  * relative to the unit. So the total number of channels that unit can have
69  * open at the same time is 0xffff - 0x0040 = 0xffbf (65471). This number
70  * does not depend on number of connections.
71  */
72 
73 #define NG_L2CAP_NULL_CID	0x0000	/* DO NOT USE THIS CID */
74 #define NG_L2CAP_SIGNAL_CID	0x0001	/* signaling channel ID */
75 #define NG_L2CAP_CLT_CID	0x0002	/* connectionless channel ID */
76 	/* 0x0003 - 0x003f Reserved */
77 #define NG_L2CAP_FIRST_CID	0x0040	/* dynamically alloc. (start) */
78 #define NG_L2CAP_LAST_CID	0xffff	/* dynamically alloc. (end) */
79 
80 /* L2CAP MTU */
81 #define NG_L2CAP_MTU_MINIMUM		48
82 #define NG_L2CAP_MTU_DEFAULT		672
83 #define NG_L2CAP_MTU_MAXIMUM		0xffff
84 
85 /* L2CAP flush and link timeouts */
86 #define NG_L2CAP_FLUSH_TIMO_DEFAULT	0xffff /* always retransmit */
87 #define NG_L2CAP_LINK_TIMO_DEFAULT	0xffff
88 
89 /* L2CAP Command Reject reasons */
90 #define NG_L2CAP_REJ_NOT_UNDERSTOOD	0x0000
91 #define NG_L2CAP_REJ_MTU_EXCEEDED	0x0001
92 #define NG_L2CAP_REJ_INVALID_CID	0x0002
93 /* 0x0003 - 0xffff - reserved for future use */
94 
95 /* Protocol/Service Multioplexor (PSM) values */
96 #define NG_L2CAP_PSM_ANY		0x0000	/* Any/Invalid PSM */
97 #define NG_L2CAP_PSM_SDP		0x0001	/* Service Discovery Protocol */
98 #define NG_L2CAP_PSM_RFCOMM		0x0003	/* RFCOMM protocol */
99 #define NG_L2CAP_PSM_TCP		0x0005	/* Telephony Control Protocol */
100 /* 0x0006 - 0x1000 - reserved for future use */
101 
102 /* L2CAP Connection response command result codes */
103 #define NG_L2CAP_SUCCESS		0x0000
104 #define NG_L2CAP_PENDING		0x0001
105 #define NG_L2CAP_PSM_NOT_SUPPORTED	0x0002
106 #define NG_L2CAP_SEQUIRY_BLOCK		0x0003
107 #define NG_L2CAP_NO_RESOURCES		0x0004
108 #define NG_L2CAP_TIMEOUT		0xeeee
109 #define NG_L2CAP_UNKNOWN		0xffff
110 /* 0x0005 - 0xffff - reserved for future use */
111 
112 /* L2CAP Connection response status codes */
113 #define NG_L2CAP_NO_INFO		0x0000
114 #define NG_L2CAP_AUTH_PENDING		0x0001
115 #define NG_L2CAP_AUTZ_PENDING		0x0002
116 /* 0x0003 - 0xffff - reserved for future use */
117 
118 /* L2CAP Configuration response result codes */
119 #define NG_L2CAP_UNACCEPTABLE_PARAMS	0x0001
120 #define NG_L2CAP_REJECT			0x0002
121 #define NG_L2CAP_UNKNOWN_OPTION		0x0003
122 /* 0x0003 - 0xffff - reserved for future use */
123 
124 /* L2CAP Configuration options */
125 #define NG_L2CAP_OPT_CFLAG_BIT		0x0001
126 #define NG_L2CAP_OPT_CFLAG(flags)	((flags) & NG_L2CAP_OPT_CFLAG_BIT)
127 #define NG_L2CAP_OPT_HINT_BIT		0x80
128 #define NG_L2CAP_OPT_HINT(type)		((type) & NG_L2CAP_OPT_HINT_BIT)
129 #define NG_L2CAP_OPT_HINT_MASK		0x7f
130 #define NG_L2CAP_OPT_MTU		0x01
131 #define NG_L2CAP_OPT_MTU_SIZE		sizeof(u_int16_t)
132 #define NG_L2CAP_OPT_FLUSH_TIMO		0x02
133 #define NG_L2CAP_OPT_FLUSH_TIMO_SIZE	sizeof(u_int16_t)
134 #define NG_L2CAP_OPT_QOS		0x03
135 #define NG_L2CAP_OPT_QOS_SIZE		sizeof(ng_l2cap_flow_t)
136 /* 0x4 - 0xff - reserved for future use */
137 
138 /* L2CAP Information request type codes */
139 #define NG_L2CAP_CONNLESS_MTU		0x0001
140 /* 0x0002 - 0xffff - reserved for future use */
141 
142 /* L2CAP Information response codes */
143 #define NG_L2CAP_NOT_SUPPORTED		0x0001
144 /* 0x0002 - 0xffff - reserved for future use */
145 
146 /* L2CAP flow control */
147 typedef struct {
148 	u_int8_t	flags;             /* reserved for future use */
149 	u_int8_t	service_type;      /* service type */
150 	u_int32_t	token_rate;        /* bytes per second */
151 	u_int32_t	token_bucket_size; /* bytes */
152 	u_int32_t	peak_bandwidth;    /* bytes per second */
153 	u_int32_t	latency;           /* microseconds */
154 	u_int32_t	delay_variation;   /* microseconds */
155 } __attribute__ ((packed)) ng_l2cap_flow_t;
156 typedef ng_l2cap_flow_t *	ng_l2cap_flow_p;
157 
158 /**************************************************************************
159  **************************************************************************
160  **                 Link level defines, headers and types
161  **************************************************************************
162  **************************************************************************/
163 
164 /* L2CAP header */
165 typedef struct {
166 	u_int16_t	length;	/* payload size */
167 	u_int16_t	dcid;	/* destination channel ID */
168 } __attribute__ ((packed)) ng_l2cap_hdr_t;
169 
170 /* L2CAP ConnectionLess Traffic (CLT) (if destination cid == 0x2) */
171 typedef struct {
172 	u_int16_t	psm; /* Protocol/Service Multiplexor */
173 } __attribute__ ((packed)) ng_l2cap_clt_hdr_t;
174 
175 #define NG_L2CAP_CLT_MTU_MAXIMUM \
176 	(NG_L2CAP_MTU_MAXIMUM - sizeof(ng_l2cap_clt_hdr_t))
177 
178 /* L2CAP command header */
179 typedef struct {
180 	u_int8_t	code;   /* command OpCode */
181 	u_int8_t	ident;  /* identifier to match request and response */
182 	u_int16_t	length; /* command parameters length */
183 } __attribute__ ((packed)) ng_l2cap_cmd_hdr_t;
184 
185 /* L2CAP Command Reject */
186 #define NG_L2CAP_CMD_REJ	0x01
187 typedef struct {
188 	u_int16_t	reason; /* reason to reject command */
189 /*	u_int8_t	data[]; -- optional data (depends on reason) */
190 } __attribute__ ((packed)) ng_l2cap_cmd_rej_cp;
191 
192 /* CommandReject data */
193 typedef union {
194  	/* NG_L2CAP_REJ_MTU_EXCEEDED */
195 	struct {
196 		u_int16_t	mtu; /* actual signaling MTU */
197 	} __attribute__ ((packed)) mtu;
198 	/* NG_L2CAP_REJ_INVALID_CID */
199 	struct {
200 		u_int16_t	scid; /* local CID */
201 		u_int16_t	dcid; /* remote CID */
202 	} __attribute__ ((packed)) cid;
203 } ng_l2cap_cmd_rej_data_t;
204 typedef ng_l2cap_cmd_rej_data_t * ng_l2cap_cmd_rej_data_p;
205 
206 /* L2CAP Connection Request */
207 #define NG_L2CAP_CON_REQ	0x02
208 typedef struct {
209 	u_int16_t	psm;  /* Protocol/Service Multiplexor (PSM) */
210 	u_int16_t	scid; /* source channel ID */
211 } __attribute__ ((packed)) ng_l2cap_con_req_cp;
212 
213 /* L2CAP Connection Response */
214 #define NG_L2CAP_CON_RSP	0x03
215 typedef struct {
216 	u_int16_t	dcid;   /* destination channel ID */
217 	u_int16_t	scid;   /* source channel ID */
218 	u_int16_t	result; /* 0x00 - success */
219 	u_int16_t	status; /* more info if result != 0x00 */
220 } __attribute__ ((packed)) ng_l2cap_con_rsp_cp;
221 
222 /* L2CAP Configuration Request */
223 #define NG_L2CAP_CFG_REQ	0x04
224 typedef struct {
225 	u_int16_t	dcid;  /* destination channel ID */
226 	u_int16_t	flags; /* flags */
227 /*	u_int8_t	options[] --  options */
228 } __attribute__ ((packed)) ng_l2cap_cfg_req_cp;
229 
230 /* L2CAP Configuration Response */
231 #define NG_L2CAP_CFG_RSP	0x05
232 typedef struct {
233 	u_int16_t	scid;   /* source channel ID */
234 	u_int16_t	flags;  /* flags */
235 	u_int16_t	result; /* 0x00 - success */
236 /*	u_int8_t	options[] -- options */
237 } __attribute__ ((packed)) ng_l2cap_cfg_rsp_cp;
238 
239 /* L2CAP configuration option */
240 typedef struct {
241 	u_int8_t	type;
242 	u_int8_t	length;
243 /*	u_int8_t	value[] -- option value (depends on type) */
244 } __attribute__ ((packed)) ng_l2cap_cfg_opt_t;
245 typedef ng_l2cap_cfg_opt_t * ng_l2cap_cfg_opt_p;
246 
247 /* L2CAP configuration option value */
248 typedef union {
249 	u_int16_t		mtu;		/* NG_L2CAP_OPT_MTU */
250 	u_int16_t		flush_timo;	/* NG_L2CAP_OPT_FLUSH_TIMO */
251 	ng_l2cap_flow_t		flow;		/* NG_L2CAP_OPT_QOS */
252 } ng_l2cap_cfg_opt_val_t;
253 typedef ng_l2cap_cfg_opt_val_t * ng_l2cap_cfg_opt_val_p;
254 
255 /* L2CAP Disconnect Request */
256 #define NG_L2CAP_DISCON_REQ	0x06
257 typedef struct {
258 	u_int16_t	dcid; /* destination channel ID */
259 	u_int16_t	scid; /* source channel ID */
260 } __attribute__ ((packed)) ng_l2cap_discon_req_cp;
261 
262 /* L2CAP Disconnect Response */
263 #define NG_L2CAP_DISCON_RSP	0x07
264 typedef ng_l2cap_discon_req_cp	ng_l2cap_discon_rsp_cp;
265 
266 /* L2CAP Echo Request */
267 #define NG_L2CAP_ECHO_REQ	0x08
268 /* No command parameters, only optional data */
269 
270 /* L2CAP Echo Response */
271 #define NG_L2CAP_ECHO_RSP	0x09
272 #define NG_L2CAP_MAX_ECHO_SIZE \
273 	(NG_L2CAP_MTU_MAXIMUM - sizeof(ng_l2cap_cmd_hdr_t))
274 /* No command parameters, only optional data */
275 
276 /* L2CAP Information Request */
277 #define NG_L2CAP_INFO_REQ	0x0a
278 typedef struct {
279 	u_int16_t	type; /* requested information type */
280 } __attribute__ ((packed)) ng_l2cap_info_req_cp;
281 
282 /* L2CAP Information Response */
283 #define NG_L2CAP_INFO_RSP	0x0b
284 typedef struct {
285 	u_int16_t	type;   /* requested information type */
286 	u_int16_t	result; /* 0x00 - success */
287 /*	u_int8_t	info[]  -- info data (depends on type)
288  *
289  * NG_L2CAP_CONNLESS_MTU - 2 bytes connectionless MTU
290  */
291 } __attribute__ ((packed)) ng_l2cap_info_rsp_cp;
292 
293 typedef union {
294  	/* NG_L2CAP_CONNLESS_MTU */
295 	struct {
296 		u_int16_t	mtu;
297 	} __attribute__ ((packed)) mtu;
298 } ng_l2cap_info_rsp_data_t;
299 typedef ng_l2cap_info_rsp_data_t *	ng_l2cap_info_rsp_data_p;
300 
301 /**************************************************************************
302  **************************************************************************
303  **        Upper layer protocol interface. L2CA_xxx messages
304  **************************************************************************
305  **************************************************************************/
306 
307 /*
308  * NOTE! NOTE! NOTE!
309  *
310  * Bluetooth specification says that L2CA_xxx request must block until
311  * response is ready. We are not allowed to block in Netgraph, so we
312  * need to queue request and save some information that can be used
313  * later and help match request and response.
314  *
315  * The idea is to use "token" field from Netgraph message header. The
316  * upper layer protocol _MUST_ populate "token". L2CAP will queue request
317  * (using L2CAP command descriptor) and start processing. Later, when
318  * response is ready or timeout has occur L2CAP layer will create new
319  * Netgraph message, set "token" and RESP flag and send the message to
320  * the upper layer protocol.
321  *
322  * L2CA_xxx_Ind messages _WILL_NOT_ populate "token" and _WILL_NOT_
323  * set RESP flag. There is no reason for this, because they are just
324  * notifications and do not require acknowlegment.
325  *
326  * NOTE: This is _NOT_ what NG_MKRESPONSE and NG_RESPOND_MSG do, however
327  *       it is somewhat similar.
328  */
329 
330 /* L2CA data packet header */
331 typedef struct {
332 	u_int32_t	token;	/* token to use in L2CAP_L2CA_WRITE */
333 	u_int16_t	length;	/* length of the data */
334 	u_int16_t	lcid;	/* local channel ID */
335 } __attribute__ ((packed)) ng_l2cap_l2ca_hdr_t;
336 
337 /* L2CA_Connect */
338 #define NGM_L2CAP_L2CA_CON		0x80
339 /* Upper -> L2CAP */
340 typedef struct {
341 	u_int16_t	psm;    /* Protocol/Service Multiplexor */
342 	bdaddr_t	bdaddr;	/* remote unit address */
343 } ng_l2cap_l2ca_con_ip;
344 
345 /* L2CAP -> Upper */
346 typedef struct {
347 	u_int16_t	lcid;   /* local channel ID */
348 	u_int16_t	result; /* 0x00 - success */
349 	u_int16_t	status; /* if result != 0x00 */
350 } ng_l2cap_l2ca_con_op;
351 
352 /* L2CA_ConnectInd */
353 #define NGM_L2CAP_L2CA_CON_IND		0x81
354 /* L2CAP -> Upper */
355 typedef struct {
356 	bdaddr_t	bdaddr; /* remote unit address */
357 	u_int16_t	lcid;   /* local channel ID */
358 	u_int16_t	psm;    /* Procotol/Service Multiplexor */
359 	u_int8_t	ident;  /* indentifier */
360 	u_int8_t	unused; /* place holder */
361 } ng_l2cap_l2ca_con_ind_ip;
362 /* No output parameters */
363 
364 /* L2CA_ConnectRsp */
365 #define NGM_L2CAP_L2CA_CON_RSP		0x82
366 /* Upper -> L2CAP */
367 typedef struct {
368 	bdaddr_t	bdaddr; /* remote unit address */
369 	u_int8_t	ident;  /* "ident" from L2CAP_ConnectInd event */
370 	u_int8_t	unused; /* place holder */
371 	u_int16_t	lcid;   /* local channel ID */
372 	u_int16_t	result; /* 0x00 - success */
373 	u_int16_t	status; /* if response != 0x00 */
374 } ng_l2cap_l2ca_con_rsp_ip;
375 
376 /* L2CAP -> Upper */
377 typedef struct {
378 	u_int16_t	result; /* 0x00 - success */
379 } ng_l2cap_l2ca_con_rsp_op;
380 
381 /* L2CA_Config */
382 #define NGM_L2CAP_L2CA_CFG		0x83
383 /* Upper -> L2CAP */
384 typedef struct {
385 	u_int16_t	lcid;        /* local channel ID */
386 	u_int16_t	imtu;        /* receiving MTU for the local channel */
387 	ng_l2cap_flow_t	oflow;       /* out flow */
388 	u_int16_t	flush_timo;  /* flush timeout (msec) */
389 	u_int16_t	link_timo;   /* link timeout (msec) */
390 } ng_l2cap_l2ca_cfg_ip;
391 
392 /* L2CAP -> Upper */
393 typedef struct {
394 	u_int16_t	result;      /* 0x00 - success */
395 	u_int16_t	imtu;        /* sending MTU for the remote channel */
396 	ng_l2cap_flow_t	oflow;       /* out flow */
397 	u_int16_t	flush_timo;  /* flush timeout (msec) */
398 } ng_l2cap_l2ca_cfg_op;
399 
400 /* L2CA_ConfigRsp */
401 #define NGM_L2CAP_L2CA_CFG_RSP		0x84
402 /* Upper -> L2CAP */
403 typedef struct {
404 	u_int16_t	lcid;  /* local channel ID */
405 	u_int16_t	omtu;  /* sending MTU for the local channel */
406 	ng_l2cap_flow_t	iflow; /* in FLOW */
407 } ng_l2cap_l2ca_cfg_rsp_ip;
408 
409 /* L2CAP -> Upper */
410 typedef struct {
411 	u_int16_t	result; /* 0x00 - sucsess */
412 } ng_l2cap_l2ca_cfg_rsp_op;
413 
414 /* L2CA_ConfigInd */
415 #define NGM_L2CAP_L2CA_CFG_IND		0x85
416 /* L2CAP -> Upper */
417 typedef struct {
418 	u_int16_t	lcid;        /* local channel ID */
419 	u_int16_t	omtu;        /* outgoing MTU for the local channel */
420 	ng_l2cap_flow_t	iflow;       /* in flow */
421 	u_int16_t	flush_timo;  /* flush timeout (msec) */
422 } ng_l2cap_l2ca_cfg_ind_ip;
423 /* No output parameters */
424 
425 /* L2CA_QoSViolationInd */
426 #define NGM_L2CAP_L2CA_QOS_IND		0x86
427 /* L2CAP -> Upper */
428 typedef struct {
429 	bdaddr_t	bdaddr;	/* remote unit address */
430 } ng_l2cap_l2ca_qos_ind_ip;
431 /* No output parameters */
432 
433 /* L2CA_Disconnect */
434 #define NGM_L2CAP_L2CA_DISCON		0x87
435 /* Upper -> L2CAP */
436 typedef struct {
437 	u_int16_t	lcid;  /* local channel ID */
438 } ng_l2cap_l2ca_discon_ip;
439 
440 /* L2CAP -> Upper */
441 typedef struct {
442 	u_int16_t	result; /* 0x00 - sucsess */
443 } ng_l2cap_l2ca_discon_op;
444 
445 /* L2CA_DisconnectInd */
446 #define NGM_L2CAP_L2CA_DISCON_IND	0x88
447 /* L2CAP -> Upper */
448 typedef ng_l2cap_l2ca_discon_ip ng_l2cap_l2ca_discon_ind_ip;
449 /* No output parameters */
450 
451 /* L2CA_Write response */
452 #define NGM_L2CAP_L2CA_WRITE		0x89
453 /* No input parameters */
454 
455 /* L2CAP -> Upper */
456 typedef struct {
457 	int		result;	/* result (0x00 - success) */
458 	u_int16_t	length;	/* amount of data written */
459 	u_int16_t	lcid;	/* local channel ID */
460 } ng_l2cap_l2ca_write_op;
461 
462 /* L2CA_GroupCreate */
463 #define NGM_L2CAP_L2CA_GRP_CREATE	0x8a
464 /* Upper -> L2CAP */
465 typedef struct {
466 	u_int16_t	psm;   /* Protocol/Service Multiplexor */
467 } ng_l2cap_l2ca_grp_create_ip;
468 
469 /* L2CAP -> Upper */
470 typedef struct {
471 	u_int16_t	lcid;  /* local group channel ID */
472 } ng_l2cap_l2ca_grp_create_op;
473 
474 /* L2CA_GroupClose */
475 #define NGM_L2CAP_L2CA_GRP_CLOSE	0x8b
476 /* Upper -> L2CAP */
477 typedef struct {
478 	u_int16_t	lcid;  /* local group channel ID */
479 } ng_l2cap_l2ca_grp_close_ip;
480 
481 #if 0
482 /* L2CAP -> Upper */
483  * typedef struct {
484  * 	u_int16_t	result; /* 0x00 - success */
485  * } ng_l2cap_l2ca_grp_close_op;
486 #endif
487 
488 /* L2CA_GroupAddMember */
489 #define NGM_L2CAP_L2CA_GRP_ADD_MEMBER	0x8c
490 /* Upper -> L2CAP */
491 typedef struct {
492 	u_int16_t	lcid;   /* local group channel ID */
493 	bdaddr_t	bdaddr; /* remote unit address */
494 } ng_l2cap_l2ca_grp_add_member_ip;
495 
496 /* L2CAP -> Upper */
497 typedef struct {
498 	u_int16_t	result; /* 0x00 - success */
499 } ng_l2cap_l2ca_grp_add_member_op;
500 
501 /* L2CA_GroupRemoveMember */
502 #define NGM_L2CAP_L2CA_GRP_REM_MEMBER	0x8d
503 /* Upper -> L2CAP */
504 typedef ng_l2cap_l2ca_grp_add_member_ip	ng_l2cap_l2ca_grp_rem_member_ip;
505 
506 /* L2CAP -> Upper */
507 #if 0
508  * typedef ng_l2cap_l2ca_grp_add_member_op	ng_l2cap_l2ca_grp_rem_member_op;
509 #endif
510 
511 /* L2CA_GroupMembeship */
512 #define NGM_L2CAP_L2CA_GRP_MEMBERSHIP	0x8e
513 /* Upper -> L2CAP */
514 typedef struct {
515 	u_int16_t	lcid;  /* local group channel ID */
516 } ng_l2cap_l2ca_grp_get_members_ip;
517 
518 /* L2CAP -> Upper */
519 typedef struct {
520 	u_int16_t	result;   /* 0x00 - success */
521 	u_int16_t	nmembers; /* number of group members */
522 /*	bdaddr_t	members[] -- group memebers */
523 } ng_l2cap_l2ca_grp_get_members_op;
524 
525 /* L2CA_Ping */
526 #define NGM_L2CAP_L2CA_PING		0x8f
527 /* Upper -> L2CAP */
528 typedef struct {
529 	bdaddr_t	bdaddr;    /* remote unit address */
530 	u_int16_t	echo_size; /* size of echo data in bytes */
531 /*	u_int8_t	echo_data[] -- echo data */
532 } ng_l2cap_l2ca_ping_ip;
533 
534 /* L2CAP -> Upper */
535 typedef struct {
536 	u_int16_t	result;    /* 0x00 - success */
537 	bdaddr_t	bdaddr;    /* remote unit address */
538 	u_int16_t	echo_size; /* size of echo data in bytes */
539 /*	u_int8_t	echo_data[] -- echo data */
540 } ng_l2cap_l2ca_ping_op;
541 
542 /* L2CA_GetInfo */
543 #define NGM_L2CAP_L2CA_GET_INFO		0x90
544 /* Upper -> L2CAP */
545 typedef struct {
546 	bdaddr_t	bdaddr;	   /* remote unit address */
547 	u_int16_t	info_type; /* info type */
548 } ng_l2cap_l2ca_get_info_ip;
549 
550 /* L2CAP -> Upper */
551 typedef struct {
552 	u_int16_t	result;    /* 0x00 - success */
553 	u_int16_t	info_size; /* size of info data in bytes */
554 /*	u_int8_t	info_data[] -- info data */
555 } ng_l2cap_l2ca_get_info_op;
556 
557 /* L2CA_EnableCLT/L2CA_DisableCLT */
558 #define NGM_L2CAP_L2CA_ENABLE_CLT	0x91
559 /* Upper -> L2CAP */
560 typedef struct {
561 	u_int16_t	psm;    /* Protocol/Service Multiplexor */
562 	u_int16_t	enable; /* 0x00 - disable */
563 } ng_l2cap_l2ca_enable_clt_ip;
564 
565 #if 0
566 /* L2CAP -> Upper */
567  * typedef struct {
568  * 	u_int16_t	result; /* 0x00 - success */
569  * } ng_l2cap_l2ca_enable_clt_op;
570 #endif
571 
572 /**************************************************************************
573  **************************************************************************
574  **                          L2CAP node messages
575  **************************************************************************
576  **************************************************************************/
577 
578 /* L2CAP connection states */
579 #define NG_L2CAP_CON_CLOSED		0	/* connection closed */
580 #define NG_L2CAP_W4_LP_CON_CFM		1	/* waiting... */
581 #define NG_L2CAP_CON_OPEN		2	/* connection open */
582 
583 /* L2CAP channel states */
584 #define NG_L2CAP_CLOSED			0	/* channel closed */
585 #define NG_L2CAP_W4_L2CAP_CON_RSP	1	/* wait for L2CAP resp. */
586 #define NG_L2CAP_W4_L2CA_CON_RSP	2	/* wait for upper resp. */
587 #define NG_L2CAP_CONFIG			3	/* L2CAP configuration */
588 #define NG_L2CAP_OPEN			4	/* channel open */
589 #define NG_L2CAP_W4_L2CAP_DISCON_RSP	5	/* wait for L2CAP discon. */
590 #define NG_L2CAP_W4_L2CA_DISCON_RSP	6	/* wait for upper discon. */
591 
592 /* Node flags */
593 #define NG_L2CAP_CLT_SDP_DISABLED	(1 << 0)      /* disable SDP CLT */
594 #define NG_L2CAP_CLT_RFCOMM_DISABLED	(1 << 1)      /* disable RFCOMM CLT */
595 #define NG_L2CAP_CLT_TCP_DISABLED	(1 << 2)      /* disable TCP CLT */
596 
597 /* Debug levels */
598 #define NG_L2CAP_ALERT_LEVEL		1
599 #define NG_L2CAP_ERR_LEVEL		2
600 #define NG_L2CAP_WARN_LEVEL		3
601 #define NG_L2CAP_INFO_LEVEL		4
602 
603 /* Get node flags (see flags above) */
604 #define	NGM_L2CAP_NODE_GET_FLAGS	0x400	/* L2CAP -> User */
605 typedef u_int16_t	ng_l2cap_node_flags_ep;
606 
607 /* Get/Set debug level (see levels above) */
608 #define	NGM_L2CAP_NODE_GET_DEBUG	0x401	/* L2CAP -> User */
609 #define	NGM_L2CAP_NODE_SET_DEBUG	0x402	/* User -> L2CAP */
610 typedef u_int16_t	ng_l2cap_node_debug_ep;
611 
612 #define NGM_L2CAP_NODE_HOOK_INFO	0x409	/* L2CAP -> Upper */
613 /* bdaddr_t bdaddr; -- local (source BDADDR) */
614 
615 #define NGM_L2CAP_NODE_GET_CON_LIST	0x40a	/* L2CAP -> User */
616 typedef struct {
617 	u_int32_t	num_connections; /* number of connections */
618 } ng_l2cap_node_con_list_ep;
619 
620 /* Connection flags */
621 #define NG_L2CAP_CON_TX			(1 << 0) /* sending data */
622 #define NG_L2CAP_CON_RX			(1 << 1) /* receiving data */
623 #define NG_L2CAP_CON_OUTGOING		(1 << 2) /* outgoing connection */
624 #define NG_L2CAP_CON_LP_TIMO		(1 << 3) /* LP timeout */
625 #define NG_L2CAP_CON_AUTO_DISCON_TIMO	(1 << 4) /* auto discon. timeout */
626 #define NG_L2CAP_CON_DYING		(1 << 5) /* connection is dying */
627 
628 typedef struct {
629 	u_int8_t	state;      /* connection state */
630 	u_int8_t	flags;      /* flags */
631 	int16_t		pending;    /* num. pending packets */
632 	u_int16_t	con_handle; /* connection handle */
633 	bdaddr_t	remote;     /* remote bdaddr */
634 } ng_l2cap_node_con_ep;
635 
636 #define NG_L2CAP_MAX_CON_NUM \
637 	((0xffff - sizeof(ng_l2cap_node_con_list_ep))/sizeof(ng_l2cap_node_con_ep))
638 
639 #define NGM_L2CAP_NODE_GET_CHAN_LIST	0x40b	/* L2CAP -> User */
640 typedef struct {
641 	u_int32_t	num_channels;	/* number of channels */
642 } ng_l2cap_node_chan_list_ep;
643 
644 typedef struct {
645 	u_int32_t	state;		/* channel state */
646 
647 	u_int16_t	scid;		/* source (local) channel ID */
648 	u_int16_t	dcid;		/* destination (remote) channel ID */
649 
650 	u_int16_t	imtu;		/* incomming MTU */
651 	u_int16_t	omtu;		/* outgoing MTU */
652 
653 	u_int16_t	psm;		/* PSM */
654 	bdaddr_t	remote;		/* remote bdaddr */
655 } ng_l2cap_node_chan_ep;
656 
657 #define NG_L2CAP_MAX_CHAN_NUM \
658 	((0xffff - sizeof(ng_l2cap_node_chan_list_ep))/sizeof(ng_l2cap_node_chan_ep))
659 
660 #define NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO 0x40c /* L2CAP -> User */
661 #define NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO 0x40d /* User -> L2CAP */
662 typedef u_int16_t	ng_l2cap_node_auto_discon_ep;
663 
664 #endif /* ndef _NETGRAPH_L2CAP_H_ */
665 
666