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