xref: /freebsd/sys/netgraph/bluetooth/include/ng_l2cap.h (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
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$
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 #define NG_L2CAP_A2MP_CID	0x0003
77 #define NG_L2CAP_ATT_CID	0x0004
78 #define NG_L2CAP_LESIGNAL_CID	0x0005
79 #define NG_L2CAP_SMP_CID	0x0006
80 	/* 0x0007 - 0x003f Reserved */
81 #define NG_L2CAP_FIRST_CID	0x0040	/* dynamically alloc. (start) */
82 #define NG_L2CAP_LAST_CID	0xffff	/* dynamically alloc. (end) */
83 #define NG_L2CAP_LELAST_CID	0x007f
84 
85 
86 /* L2CAP MTU */
87 #define NG_L2CAP_MTU_LE_MINIMAM		23
88 #define NG_L2CAP_MTU_MINIMUM		48
89 #define NG_L2CAP_MTU_DEFAULT		672
90 #define NG_L2CAP_MTU_MAXIMUM		0xffff
91 
92 /* L2CAP flush and link timeouts */
93 #define NG_L2CAP_FLUSH_TIMO_DEFAULT	0xffff /* always retransmit */
94 #define NG_L2CAP_LINK_TIMO_DEFAULT	0xffff
95 
96 /* L2CAP Command Reject reasons */
97 #define NG_L2CAP_REJ_NOT_UNDERSTOOD	0x0000
98 #define NG_L2CAP_REJ_MTU_EXCEEDED	0x0001
99 #define NG_L2CAP_REJ_INVALID_CID	0x0002
100 /* 0x0003 - 0xffff - reserved for future use */
101 
102 /* Protocol/Service Multioplexor (PSM) values */
103 #define NG_L2CAP_PSM_ANY		0x0000	/* Any/Invalid PSM */
104 #define NG_L2CAP_PSM_SDP		0x0001	/* Service Discovery Protocol */
105 #define NG_L2CAP_PSM_RFCOMM		0x0003	/* RFCOMM protocol */
106 #define NG_L2CAP_PSM_TCP		0x0005	/* Telephony Control Protocol */
107 /* 0x0006 - 0x1000 - reserved for future use */
108 
109 /* L2CAP Connection response command result codes */
110 #define NG_L2CAP_SUCCESS		0x0000
111 #define NG_L2CAP_PENDING		0x0001
112 #define NG_L2CAP_PSM_NOT_SUPPORTED	0x0002
113 #define NG_L2CAP_SEQUIRY_BLOCK		0x0003
114 #define NG_L2CAP_NO_RESOURCES		0x0004
115 #define NG_L2CAP_TIMEOUT		0xeeee
116 #define NG_L2CAP_UNKNOWN		0xffff
117 /* 0x0005 - 0xffff - reserved for future use */
118 
119 /* L2CAP Connection response status codes */
120 #define NG_L2CAP_NO_INFO		0x0000
121 #define NG_L2CAP_AUTH_PENDING		0x0001
122 #define NG_L2CAP_AUTZ_PENDING		0x0002
123 /* 0x0003 - 0xffff - reserved for future use */
124 
125 /* L2CAP Configuration response result codes */
126 #define NG_L2CAP_UNACCEPTABLE_PARAMS	0x0001
127 #define NG_L2CAP_REJECT			0x0002
128 #define NG_L2CAP_UNKNOWN_OPTION		0x0003
129 /* 0x0003 - 0xffff - reserved for future use */
130 
131 /* L2CAP Configuration options */
132 #define NG_L2CAP_OPT_CFLAG_BIT		0x0001
133 #define NG_L2CAP_OPT_CFLAG(flags)	((flags) & NG_L2CAP_OPT_CFLAG_BIT)
134 #define NG_L2CAP_OPT_HINT_BIT		0x80
135 #define NG_L2CAP_OPT_HINT(type)		((type) & NG_L2CAP_OPT_HINT_BIT)
136 #define NG_L2CAP_OPT_HINT_MASK		0x7f
137 #define NG_L2CAP_OPT_MTU		0x01
138 #define NG_L2CAP_OPT_MTU_SIZE		sizeof(u_int16_t)
139 #define NG_L2CAP_OPT_FLUSH_TIMO		0x02
140 #define NG_L2CAP_OPT_FLUSH_TIMO_SIZE	sizeof(u_int16_t)
141 #define NG_L2CAP_OPT_QOS		0x03
142 #define NG_L2CAP_OPT_QOS_SIZE		sizeof(ng_l2cap_flow_t)
143 /* 0x4 - 0xff - reserved for future use */
144 
145 /* L2CAP Information request type codes */
146 #define NG_L2CAP_CONNLESS_MTU		0x0001
147 /* 0x0002 - 0xffff - reserved for future use */
148 
149 /* L2CAP Information response codes */
150 #define NG_L2CAP_NOT_SUPPORTED		0x0001
151 /* 0x0002 - 0xffff - reserved for future use */
152 
153 /* L2CAP flow control */
154 typedef struct {
155 	u_int8_t	flags;             /* reserved for future use */
156 	u_int8_t	service_type;      /* service type */
157 	u_int32_t	token_rate;        /* bytes per second */
158 	u_int32_t	token_bucket_size; /* bytes */
159 	u_int32_t	peak_bandwidth;    /* bytes per second */
160 	u_int32_t	latency;           /* microseconds */
161 	u_int32_t	delay_variation;   /* microseconds */
162 } __attribute__ ((packed)) ng_l2cap_flow_t;
163 typedef ng_l2cap_flow_t *	ng_l2cap_flow_p;
164 
165 /**************************************************************************
166  **************************************************************************
167  **                 Link level defines, headers and types
168  **************************************************************************
169  **************************************************************************/
170 
171 /* L2CAP header */
172 typedef struct {
173 	u_int16_t	length;	/* payload size */
174 	u_int16_t	dcid;	/* destination channel ID */
175 } __attribute__ ((packed)) ng_l2cap_hdr_t;
176 
177 /* L2CAP ConnectionLess Traffic (CLT) (if destination cid == 0x2) */
178 typedef struct {
179 	u_int16_t	psm; /* Protocol/Service Multiplexor */
180 } __attribute__ ((packed)) ng_l2cap_clt_hdr_t;
181 
182 #define NG_L2CAP_CLT_MTU_MAXIMUM \
183 	(NG_L2CAP_MTU_MAXIMUM - sizeof(ng_l2cap_clt_hdr_t))
184 
185 /* L2CAP command header */
186 typedef struct {
187 	u_int8_t	code;   /* command OpCode */
188 	u_int8_t	ident;  /* identifier to match request and response */
189 	u_int16_t	length; /* command parameters length */
190 } __attribute__ ((packed)) ng_l2cap_cmd_hdr_t;
191 
192 /* L2CAP Command Reject */
193 #define NG_L2CAP_CMD_REJ	0x01
194 typedef struct {
195 	u_int16_t	reason; /* reason to reject command */
196 /*	u_int8_t	data[]; -- optional data (depends on reason) */
197 } __attribute__ ((packed)) ng_l2cap_cmd_rej_cp;
198 
199 /* CommandReject data */
200 typedef union {
201  	/* NG_L2CAP_REJ_MTU_EXCEEDED */
202 	struct {
203 		u_int16_t	mtu; /* actual signaling MTU */
204 	} __attribute__ ((packed)) mtu;
205 	/* NG_L2CAP_REJ_INVALID_CID */
206 	struct {
207 		u_int16_t	scid; /* local CID */
208 		u_int16_t	dcid; /* remote CID */
209 	} __attribute__ ((packed)) cid;
210 } ng_l2cap_cmd_rej_data_t;
211 typedef ng_l2cap_cmd_rej_data_t * ng_l2cap_cmd_rej_data_p;
212 
213 /* L2CAP Connection Request */
214 #define NG_L2CAP_CON_REQ	0x02
215 typedef struct {
216 	u_int16_t	psm;  /* Protocol/Service Multiplexor (PSM) */
217 	u_int16_t	scid; /* source channel ID */
218 } __attribute__ ((packed)) ng_l2cap_con_req_cp;
219 
220 /* L2CAP Connection Response */
221 #define NG_L2CAP_CON_RSP	0x03
222 typedef struct {
223 	u_int16_t	dcid;   /* destination channel ID */
224 	u_int16_t	scid;   /* source channel ID */
225 	u_int16_t	result; /* 0x00 - success */
226 	u_int16_t	status; /* more info if result != 0x00 */
227 } __attribute__ ((packed)) ng_l2cap_con_rsp_cp;
228 
229 /* L2CAP Configuration Request */
230 #define NG_L2CAP_CFG_REQ	0x04
231 typedef struct {
232 	u_int16_t	dcid;  /* destination channel ID */
233 	u_int16_t	flags; /* flags */
234 /*	u_int8_t	options[] --  options */
235 } __attribute__ ((packed)) ng_l2cap_cfg_req_cp;
236 
237 /* L2CAP Configuration Response */
238 #define NG_L2CAP_CFG_RSP	0x05
239 typedef struct {
240 	u_int16_t	scid;   /* source channel ID */
241 	u_int16_t	flags;  /* flags */
242 	u_int16_t	result; /* 0x00 - success */
243 /*	u_int8_t	options[] -- options */
244 } __attribute__ ((packed)) ng_l2cap_cfg_rsp_cp;
245 
246 /* L2CAP configuration option */
247 typedef struct {
248 	u_int8_t	type;
249 	u_int8_t	length;
250 /*	u_int8_t	value[] -- option value (depends on type) */
251 } __attribute__ ((packed)) ng_l2cap_cfg_opt_t;
252 typedef ng_l2cap_cfg_opt_t * ng_l2cap_cfg_opt_p;
253 
254 /* L2CAP configuration option value */
255 typedef union {
256 	u_int16_t		mtu;		/* NG_L2CAP_OPT_MTU */
257 	u_int16_t		flush_timo;	/* NG_L2CAP_OPT_FLUSH_TIMO */
258 	ng_l2cap_flow_t		flow;		/* NG_L2CAP_OPT_QOS */
259 	uint16_t		encryption;
260 } ng_l2cap_cfg_opt_val_t;
261 typedef ng_l2cap_cfg_opt_val_t * ng_l2cap_cfg_opt_val_p;
262 
263 /* L2CAP Disconnect Request */
264 #define NG_L2CAP_DISCON_REQ	0x06
265 typedef struct {
266 	u_int16_t	dcid; /* destination channel ID */
267 	u_int16_t	scid; /* source channel ID */
268 } __attribute__ ((packed)) ng_l2cap_discon_req_cp;
269 
270 /* L2CAP Disconnect Response */
271 #define NG_L2CAP_DISCON_RSP	0x07
272 typedef ng_l2cap_discon_req_cp	ng_l2cap_discon_rsp_cp;
273 
274 /* L2CAP Echo Request */
275 #define NG_L2CAP_ECHO_REQ	0x08
276 /* No command parameters, only optional data */
277 
278 /* L2CAP Echo Response */
279 #define NG_L2CAP_ECHO_RSP	0x09
280 #define NG_L2CAP_MAX_ECHO_SIZE \
281 	(NG_L2CAP_MTU_MAXIMUM - sizeof(ng_l2cap_cmd_hdr_t))
282 /* No command parameters, only optional data */
283 
284 /* L2CAP Information Request */
285 #define NG_L2CAP_INFO_REQ	0x0a
286 typedef struct {
287 	u_int16_t	type; /* requested information type */
288 } __attribute__ ((packed)) ng_l2cap_info_req_cp;
289 
290 /* L2CAP Information Response */
291 #define NG_L2CAP_INFO_RSP	0x0b
292 typedef struct {
293 	u_int16_t	type;   /* requested information type */
294 	u_int16_t	result; /* 0x00 - success */
295 /*	u_int8_t	info[]  -- info data (depends on type)
296  *
297  * NG_L2CAP_CONNLESS_MTU - 2 bytes connectionless MTU
298  */
299 } __attribute__ ((packed)) ng_l2cap_info_rsp_cp;
300 typedef union {
301  	/* NG_L2CAP_CONNLESS_MTU */
302 	struct {
303 		u_int16_t	mtu;
304 	} __attribute__ ((packed)) mtu;
305 } ng_l2cap_info_rsp_data_t;
306 typedef ng_l2cap_info_rsp_data_t *	ng_l2cap_info_rsp_data_p;
307 
308 #define NG_L2CAP_CMD_PARAM_UPDATE_REQUEST	0x12
309 
310 typedef struct {
311   uint16_t interval_min;
312   uint16_t interval_max;
313   uint16_t slave_latency;
314   uint16_t timeout_mpl;
315 } __attribute__ ((packed)) ng_l2cap_param_update_req_cp;
316 
317 #define NG_L2CAP_CMD_PARAM_UPDATE_RESPONSE	0x13
318 #define NG_L2CAP_UPDATE_PARAM_ACCEPT 0
319 #define NG_L2CAP_UPDATE_PARAM_REJECT 1
320 
321 //typedef uint16_t update_response;
322 /**************************************************************************
323  **************************************************************************
324  **        Upper layer protocol interface. L2CA_xxx messages
325  **************************************************************************
326  **************************************************************************/
327 
328 /*
329  * NOTE! NOTE! NOTE!
330  *
331  * Bluetooth specification says that L2CA_xxx request must block until
332  * response is ready. We are not allowed to block in Netgraph, so we
333  * need to queue request and save some information that can be used
334  * later and help match request and response.
335  *
336  * The idea is to use "token" field from Netgraph message header. The
337  * upper layer protocol _MUST_ populate "token". L2CAP will queue request
338  * (using L2CAP command descriptor) and start processing. Later, when
339  * response is ready or timeout has occur L2CAP layer will create new
340  * Netgraph message, set "token" and RESP flag and send the message to
341  * the upper layer protocol.
342  *
343  * L2CA_xxx_Ind messages _WILL_NOT_ populate "token" and _WILL_NOT_
344  * set RESP flag. There is no reason for this, because they are just
345  * notifications and do not require acknowlegment.
346  *
347  * NOTE: This is _NOT_ what NG_MKRESPONSE and NG_RESPOND_MSG do, however
348  *       it is somewhat similar.
349  */
350 
351 /* L2CA data packet header */
352 typedef struct {
353 	u_int32_t	token;	/* token to use in L2CAP_L2CA_WRITE */
354 	u_int16_t	length;	/* length of the data */
355 	u_int16_t	lcid;	/* local channel ID */
356 	uint16_t	idtype;
357 } __attribute__ ((packed)) ng_l2cap_l2ca_hdr_t;
358 #define NG_L2CAP_L2CA_IDTYPE_BREDR 0
359 #define NG_L2CAP_L2CA_IDTYPE_ATT  1
360 #define NG_L2CAP_L2CA_IDTYPE_LE  2
361 #define NG_L2CAP_L2CA_IDTYPE_SMP  3
362 /* L2CA_Connect */
363 #define NGM_L2CAP_L2CA_CON		0x80
364 /* Upper -> L2CAP */
365 typedef struct {
366 	u_int16_t	psm;    /* Protocol/Service Multiplexor */
367 	bdaddr_t	bdaddr;	/* remote unit address */
368 	uint8_t		linktype;
369 	uint8_t		idtype;
370 } ng_l2cap_l2ca_con_ip;
371 
372 /* L2CAP -> Upper */
373 typedef struct {
374 	u_int16_t	lcid;   /* local channel ID */
375 	uint16_t	idtype; /*ID type*/
376 	u_int16_t	result; /* 0x00 - success */
377 	u_int16_t	status; /* if result != 0x00 */
378 	uint8_t 	encryption;
379 } ng_l2cap_l2ca_con_op;
380 
381 /* L2CA_ConnectInd */
382 #define NGM_L2CAP_L2CA_CON_IND		0x81
383 /* L2CAP -> Upper */
384 typedef struct {
385 	bdaddr_t	bdaddr; /* remote unit address */
386 	u_int16_t	lcid;   /* local channel ID */
387 	u_int16_t	psm;    /* Procotol/Service Multiplexor */
388 	u_int8_t	ident;  /* indentifier */
389 	u_int8_t	linktype; /* link type*/
390 } ng_l2cap_l2ca_con_ind_ip;
391 /* No output parameters */
392 
393 /* L2CA_ConnectRsp */
394 #define NGM_L2CAP_L2CA_CON_RSP		0x82
395 /* Upper -> L2CAP */
396 typedef struct {
397 	bdaddr_t	bdaddr; /* remote unit address */
398 	u_int8_t	ident;  /* "ident" from L2CAP_ConnectInd event */
399 	u_int8_t	linktype; /*link type */
400 	u_int16_t	lcid;   /* local channel ID */
401 	u_int16_t	result; /* 0x00 - success */
402 	u_int16_t	status; /* if response != 0x00 */
403 } ng_l2cap_l2ca_con_rsp_ip;
404 
405 /* L2CAP -> Upper */
406 typedef struct {
407 	u_int16_t	result; /* 0x00 - success */
408 } ng_l2cap_l2ca_con_rsp_op;
409 
410 /* L2CA_Config */
411 #define NGM_L2CAP_L2CA_CFG		0x83
412 /* Upper -> L2CAP */
413 typedef struct {
414 	u_int16_t	lcid;        /* local channel ID */
415 	u_int16_t	imtu;        /* receiving MTU for the local channel */
416 	ng_l2cap_flow_t	oflow;       /* out flow */
417 	u_int16_t	flush_timo;  /* flush timeout (msec) */
418 	u_int16_t	link_timo;   /* link timeout (msec) */
419 } ng_l2cap_l2ca_cfg_ip;
420 
421 /* L2CAP -> Upper */
422 typedef struct {
423 	u_int16_t	result;      /* 0x00 - success */
424 	u_int16_t	imtu;        /* sending MTU for the remote channel */
425 	ng_l2cap_flow_t	oflow;       /* out flow */
426 	u_int16_t	flush_timo;  /* flush timeout (msec) */
427 } ng_l2cap_l2ca_cfg_op;
428 
429 /* L2CA_ConfigRsp */
430 #define NGM_L2CAP_L2CA_CFG_RSP		0x84
431 /* Upper -> L2CAP */
432 typedef struct {
433 	u_int16_t	lcid;  /* local channel ID */
434 	u_int16_t	omtu;  /* sending MTU for the local channel */
435 	ng_l2cap_flow_t	iflow; /* in FLOW */
436 } ng_l2cap_l2ca_cfg_rsp_ip;
437 
438 /* L2CAP -> Upper */
439 typedef struct {
440 	u_int16_t	result; /* 0x00 - sucsess */
441 } ng_l2cap_l2ca_cfg_rsp_op;
442 
443 /* L2CA_ConfigInd */
444 #define NGM_L2CAP_L2CA_CFG_IND		0x85
445 /* L2CAP -> Upper */
446 typedef struct {
447 	u_int16_t	lcid;        /* local channel ID */
448 	u_int16_t	omtu;        /* outgoing MTU for the local channel */
449 	ng_l2cap_flow_t	iflow;       /* in flow */
450 	u_int16_t	flush_timo;  /* flush timeout (msec) */
451 } ng_l2cap_l2ca_cfg_ind_ip;
452 /* No output parameters */
453 
454 /* L2CA_QoSViolationInd */
455 #define NGM_L2CAP_L2CA_QOS_IND		0x86
456 /* L2CAP -> Upper */
457 typedef struct {
458 	bdaddr_t	bdaddr;	/* remote unit address */
459 } ng_l2cap_l2ca_qos_ind_ip;
460 /* No output parameters */
461 
462 /* L2CA_Disconnect */
463 #define NGM_L2CAP_L2CA_DISCON		0x87
464 /* Upper -> L2CAP */
465 typedef struct {
466 	u_int16_t	lcid;  /* local channel ID */
467 	u_int16_t	idtype;
468 } ng_l2cap_l2ca_discon_ip;
469 
470 /* L2CAP -> Upper */
471 typedef struct {
472 	u_int16_t	result; /* 0x00 - sucsess */
473 } ng_l2cap_l2ca_discon_op;
474 
475 /* L2CA_DisconnectInd */
476 #define NGM_L2CAP_L2CA_DISCON_IND	0x88
477 /* L2CAP -> Upper */
478 typedef ng_l2cap_l2ca_discon_ip ng_l2cap_l2ca_discon_ind_ip;
479 /* No output parameters */
480 
481 /* L2CA_Write response */
482 #define NGM_L2CAP_L2CA_WRITE		0x89
483 /* No input parameters */
484 
485 /* L2CAP -> Upper */
486 typedef struct {
487 	int		result;	/* result (0x00 - success) */
488 	u_int16_t	length;	/* amount of data written */
489 	u_int16_t	lcid;	/* local channel ID */
490 	uint16_t 	idtype;
491 } ng_l2cap_l2ca_write_op;
492 
493 /* L2CA_GroupCreate */
494 #define NGM_L2CAP_L2CA_GRP_CREATE	0x8a
495 /* Upper -> L2CAP */
496 typedef struct {
497 	u_int16_t	psm;   /* Protocol/Service Multiplexor */
498 } ng_l2cap_l2ca_grp_create_ip;
499 
500 /* L2CAP -> Upper */
501 typedef struct {
502 	u_int16_t	lcid;  /* local group channel ID */
503 } ng_l2cap_l2ca_grp_create_op;
504 
505 /* L2CA_GroupClose */
506 #define NGM_L2CAP_L2CA_GRP_CLOSE	0x8b
507 /* Upper -> L2CAP */
508 typedef struct {
509 	u_int16_t	lcid;  /* local group channel ID */
510 } ng_l2cap_l2ca_grp_close_ip;
511 
512 #if 0
513 /* L2CAP -> Upper */
514  * typedef struct {
515  * 	u_int16_t	result; /* 0x00 - success */
516  * } ng_l2cap_l2ca_grp_close_op;
517 #endif
518 
519 /* L2CA_GroupAddMember */
520 #define NGM_L2CAP_L2CA_GRP_ADD_MEMBER	0x8c
521 /* Upper -> L2CAP */
522 typedef struct {
523 	u_int16_t	lcid;   /* local group channel ID */
524 	bdaddr_t	bdaddr; /* remote unit address */
525 } ng_l2cap_l2ca_grp_add_member_ip;
526 
527 /* L2CAP -> Upper */
528 typedef struct {
529 	u_int16_t	result; /* 0x00 - success */
530 } ng_l2cap_l2ca_grp_add_member_op;
531 
532 /* L2CA_GroupRemoveMember */
533 #define NGM_L2CAP_L2CA_GRP_REM_MEMBER	0x8d
534 /* Upper -> L2CAP */
535 typedef ng_l2cap_l2ca_grp_add_member_ip	ng_l2cap_l2ca_grp_rem_member_ip;
536 
537 /* L2CAP -> Upper */
538 #if 0
539  * typedef ng_l2cap_l2ca_grp_add_member_op	ng_l2cap_l2ca_grp_rem_member_op;
540 #endif
541 
542 /* L2CA_GroupMembeship */
543 #define NGM_L2CAP_L2CA_GRP_MEMBERSHIP	0x8e
544 /* Upper -> L2CAP */
545 typedef struct {
546 	u_int16_t	lcid;  /* local group channel ID */
547 } ng_l2cap_l2ca_grp_get_members_ip;
548 
549 /* L2CAP -> Upper */
550 typedef struct {
551 	u_int16_t	result;   /* 0x00 - success */
552 	u_int16_t	nmembers; /* number of group members */
553 /*	bdaddr_t	members[] -- group memebers */
554 } ng_l2cap_l2ca_grp_get_members_op;
555 
556 /* L2CA_Ping */
557 #define NGM_L2CAP_L2CA_PING		0x8f
558 /* Upper -> L2CAP */
559 typedef struct {
560 	bdaddr_t	bdaddr;    /* remote unit address */
561 	u_int16_t	echo_size; /* size of echo data in bytes */
562 /*	u_int8_t	echo_data[] -- echo data */
563 } ng_l2cap_l2ca_ping_ip;
564 
565 /* L2CAP -> Upper */
566 typedef struct {
567 	u_int16_t	result;    /* 0x00 - success */
568 	bdaddr_t	bdaddr;    /* remote unit address */
569 	u_int16_t	echo_size; /* size of echo data in bytes */
570 /*	u_int8_t	echo_data[] -- echo data */
571 } ng_l2cap_l2ca_ping_op;
572 
573 /* L2CA_GetInfo */
574 #define NGM_L2CAP_L2CA_GET_INFO		0x90
575 /* Upper -> L2CAP */
576 typedef struct {
577 	bdaddr_t	bdaddr;	   /* remote unit address */
578 	u_int16_t	info_type; /* info type */
579 	uint8_t		linktype;
580 	uint8_t	        unused;
581 } ng_l2cap_l2ca_get_info_ip;
582 
583 /* L2CAP -> Upper */
584 typedef struct {
585 	u_int16_t	result;    /* 0x00 - success */
586 	u_int16_t	info_size; /* size of info data in bytes */
587 /*	u_int8_t	info_data[] -- info data */
588 } ng_l2cap_l2ca_get_info_op;
589 
590 /* L2CA_EnableCLT/L2CA_DisableCLT */
591 #define NGM_L2CAP_L2CA_ENABLE_CLT	0x91
592 /* Upper -> L2CAP */
593 typedef struct {
594 	u_int16_t	psm;    /* Protocol/Service Multiplexor */
595 	u_int16_t	enable; /* 0x00 - disable */
596 } ng_l2cap_l2ca_enable_clt_ip;
597 
598 #if 0
599 /* L2CAP -> Upper */
600  * typedef struct {
601  * 	u_int16_t	result; /* 0x00 - success */
602  * } ng_l2cap_l2ca_enable_clt_op;
603 #endif
604 #define NGM_L2CAP_L2CA_ENC_CHANGE 0x92
605 typedef struct {
606 	uint16_t 	lcid;
607 	uint16_t	result;
608 	uint8_t 	idtype;
609 } ng_l2cap_l2ca_enc_chg_op;
610 
611 /**************************************************************************
612  **************************************************************************
613  **                          L2CAP node messages
614  **************************************************************************
615  **************************************************************************/
616 
617 /* L2CAP connection states */
618 #define NG_L2CAP_CON_CLOSED		0	/* connection closed */
619 #define NG_L2CAP_W4_LP_CON_CFM		1	/* waiting... */
620 #define NG_L2CAP_CON_OPEN		2	/* connection open */
621 
622 /* L2CAP channel states */
623 #define NG_L2CAP_CLOSED			0	/* channel closed */
624 #define NG_L2CAP_W4_L2CAP_CON_RSP	1	/* wait for L2CAP resp. */
625 #define NG_L2CAP_W4_L2CA_CON_RSP	2	/* wait for upper resp. */
626 #define NG_L2CAP_CONFIG			3	/* L2CAP configuration */
627 #define NG_L2CAP_OPEN			4	/* channel open */
628 #define NG_L2CAP_W4_L2CAP_DISCON_RSP	5	/* wait for L2CAP discon. */
629 #define NG_L2CAP_W4_L2CA_DISCON_RSP	6	/* wait for upper discon. */
630 
631 /* Node flags */
632 #define NG_L2CAP_CLT_SDP_DISABLED	(1 << 0)      /* disable SDP CLT */
633 #define NG_L2CAP_CLT_RFCOMM_DISABLED	(1 << 1)      /* disable RFCOMM CLT */
634 #define NG_L2CAP_CLT_TCP_DISABLED	(1 << 2)      /* disable TCP CLT */
635 
636 /* Debug levels */
637 #define NG_L2CAP_ALERT_LEVEL		1
638 #define NG_L2CAP_ERR_LEVEL		2
639 #define NG_L2CAP_WARN_LEVEL		3
640 #define NG_L2CAP_INFO_LEVEL		4
641 
642 /* Get node flags (see flags above) */
643 #define	NGM_L2CAP_NODE_GET_FLAGS	0x400	/* L2CAP -> User */
644 typedef u_int16_t	ng_l2cap_node_flags_ep;
645 
646 /* Get/Set debug level (see levels above) */
647 #define	NGM_L2CAP_NODE_GET_DEBUG	0x401	/* L2CAP -> User */
648 #define	NGM_L2CAP_NODE_SET_DEBUG	0x402	/* User -> L2CAP */
649 typedef u_int16_t	ng_l2cap_node_debug_ep;
650 
651 #define NGM_L2CAP_NODE_HOOK_INFO	0x409	/* L2CAP -> Upper */
652 typedef struct {
653 	bdaddr_t addr;
654 }ng_l2cap_node_hook_info_ep;
655 
656 #define NGM_L2CAP_NODE_GET_CON_LIST	0x40a	/* L2CAP -> User */
657 typedef struct {
658 	u_int32_t	num_connections; /* number of connections */
659 } ng_l2cap_node_con_list_ep;
660 
661 /* Connection flags */
662 #define NG_L2CAP_CON_TX			(1 << 0) /* sending data */
663 #define NG_L2CAP_CON_RX			(1 << 1) /* receiving data */
664 #define NG_L2CAP_CON_OUTGOING		(1 << 2) /* outgoing connection */
665 #define NG_L2CAP_CON_LP_TIMO		(1 << 3) /* LP timeout */
666 #define NG_L2CAP_CON_AUTO_DISCON_TIMO	(1 << 4) /* auto discon. timeout */
667 #define NG_L2CAP_CON_DYING		(1 << 5) /* connection is dying */
668 
669 typedef struct {
670 	u_int8_t	state;      /* connection state */
671 	u_int8_t	flags;      /* flags */
672 	int16_t		pending;    /* num. pending packets */
673 	u_int16_t	con_handle; /* connection handle */
674 	bdaddr_t	remote;     /* remote bdaddr */
675 } ng_l2cap_node_con_ep;
676 
677 #define NG_L2CAP_MAX_CON_NUM \
678 	((0xffff - sizeof(ng_l2cap_node_con_list_ep))/sizeof(ng_l2cap_node_con_ep))
679 
680 #define NGM_L2CAP_NODE_GET_CHAN_LIST	0x40b	/* L2CAP -> User */
681 typedef struct {
682 	u_int32_t	num_channels;	/* number of channels */
683 } ng_l2cap_node_chan_list_ep;
684 
685 typedef struct {
686 	u_int32_t	state;		/* channel state */
687 
688 	u_int16_t	scid;		/* source (local) channel ID */
689 	u_int16_t	dcid;		/* destination (remote) channel ID */
690 
691 	u_int16_t	imtu;		/* incomming MTU */
692 	u_int16_t	omtu;		/* outgoing MTU */
693 
694 	u_int16_t	psm;		/* PSM */
695 	bdaddr_t	remote;		/* remote bdaddr */
696 } ng_l2cap_node_chan_ep;
697 
698 #define NG_L2CAP_MAX_CHAN_NUM \
699 	((0xffff - sizeof(ng_l2cap_node_chan_list_ep))/sizeof(ng_l2cap_node_chan_ep))
700 
701 #define NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO 0x40c /* L2CAP -> User */
702 #define NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO 0x40d /* User -> L2CAP */
703 typedef u_int16_t	ng_l2cap_node_auto_discon_ep;
704 
705 #endif /* ndef _NETGRAPH_L2CAP_H_ */
706 
707