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