xref: /dflybsd-src/sys/netgraph7/bluetooth/include/ng_bluetooth.h (revision e85b99abf6da4a83a7dc495b0ef37ce19864149f)
1*b06ebda0SMatthew Dillon /*
2*b06ebda0SMatthew Dillon  * bluetooth.h
3*b06ebda0SMatthew Dillon  */
4*b06ebda0SMatthew Dillon 
5*b06ebda0SMatthew Dillon /*-
6*b06ebda0SMatthew Dillon  * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7*b06ebda0SMatthew Dillon  * All rights reserved.
8*b06ebda0SMatthew Dillon  *
9*b06ebda0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
10*b06ebda0SMatthew Dillon  * modification, are permitted provided that the following conditions
11*b06ebda0SMatthew Dillon  * are met:
12*b06ebda0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
13*b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
14*b06ebda0SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
15*b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
16*b06ebda0SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
17*b06ebda0SMatthew Dillon  *
18*b06ebda0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*b06ebda0SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*b06ebda0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*b06ebda0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*b06ebda0SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*b06ebda0SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*b06ebda0SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*b06ebda0SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*b06ebda0SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*b06ebda0SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*b06ebda0SMatthew Dillon  * SUCH DAMAGE.
29*b06ebda0SMatthew Dillon  *
30*b06ebda0SMatthew Dillon  * $Id: ng_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $
31*b06ebda0SMatthew Dillon  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_bluetooth.h,v 1.5 2008/04/15 21:15:32 mav Exp $
32*b06ebda0SMatthew Dillon  */
33*b06ebda0SMatthew Dillon 
34*b06ebda0SMatthew Dillon #ifndef _NETGRAPH_BLUETOOTH_H_
35*b06ebda0SMatthew Dillon #define _NETGRAPH_BLUETOOTH_H_
36*b06ebda0SMatthew Dillon 
37*b06ebda0SMatthew Dillon #include <sys/queue.h>
38*b06ebda0SMatthew Dillon 
39*b06ebda0SMatthew Dillon /*
40*b06ebda0SMatthew Dillon  * Version of the stack
41*b06ebda0SMatthew Dillon  */
42*b06ebda0SMatthew Dillon 
43*b06ebda0SMatthew Dillon #define NG_BLUETOOTH_VERSION	1
44*b06ebda0SMatthew Dillon 
45*b06ebda0SMatthew Dillon /*
46*b06ebda0SMatthew Dillon  * Declare the base of the Bluetooth sysctl hierarchy,
47*b06ebda0SMatthew Dillon  * but only if this file cares about sysctl's
48*b06ebda0SMatthew Dillon  */
49*b06ebda0SMatthew Dillon 
50*b06ebda0SMatthew Dillon #ifdef SYSCTL_DECL
51*b06ebda0SMatthew Dillon SYSCTL_DECL(_net_bluetooth);
52*b06ebda0SMatthew Dillon SYSCTL_DECL(_net_bluetooth_hci);
53*b06ebda0SMatthew Dillon SYSCTL_DECL(_net_bluetooth_l2cap);
54*b06ebda0SMatthew Dillon SYSCTL_DECL(_net_bluetooth_rfcomm);
55*b06ebda0SMatthew Dillon #endif /* SYSCTL_DECL */
56*b06ebda0SMatthew Dillon 
57*b06ebda0SMatthew Dillon /*
58*b06ebda0SMatthew Dillon  * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we
59*b06ebda0SMatthew Dillon  * do not need mutex and other locking stuff
60*b06ebda0SMatthew Dillon  */
61*b06ebda0SMatthew Dillon 
62*b06ebda0SMatthew Dillon struct mbuf;
63*b06ebda0SMatthew Dillon 
64*b06ebda0SMatthew Dillon struct ng_bt_mbufq {
65*b06ebda0SMatthew Dillon 	struct mbuf	*head;   /* first item in the queue */
66*b06ebda0SMatthew Dillon 	struct mbuf	*tail;   /* last item in the queue */
67*b06ebda0SMatthew Dillon 	u_int32_t	 len;    /* number of items in the queue */
68*b06ebda0SMatthew Dillon 	u_int32_t	 maxlen; /* maximal number of items in the queue */
69*b06ebda0SMatthew Dillon 	u_int32_t	 drops;	 /* number if dropped items */
70*b06ebda0SMatthew Dillon };
71*b06ebda0SMatthew Dillon typedef struct ng_bt_mbufq	ng_bt_mbufq_t;
72*b06ebda0SMatthew Dillon typedef struct ng_bt_mbufq *	ng_bt_mbufq_p;
73*b06ebda0SMatthew Dillon 
74*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_INIT(q, _maxlen)			\
75*b06ebda0SMatthew Dillon 	do {						\
76*b06ebda0SMatthew Dillon 		(q)->head = NULL;			\
77*b06ebda0SMatthew Dillon 		(q)->tail = NULL;			\
78*b06ebda0SMatthew Dillon 		(q)->len = 0;				\
79*b06ebda0SMatthew Dillon 		(q)->maxlen = (_maxlen);		\
80*b06ebda0SMatthew Dillon 		(q)->drops = 0;				\
81*b06ebda0SMatthew Dillon 	} while (0)
82*b06ebda0SMatthew Dillon 
83*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_DESTROY(q)				\
84*b06ebda0SMatthew Dillon 	do {						\
85*b06ebda0SMatthew Dillon 		NG_BT_MBUFQ_DRAIN((q));			\
86*b06ebda0SMatthew Dillon 	} while (0)
87*b06ebda0SMatthew Dillon 
88*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_FIRST(q)	(q)->head
89*b06ebda0SMatthew Dillon 
90*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_LEN(q)	(q)->len
91*b06ebda0SMatthew Dillon 
92*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_FULL(q)	((q)->len >= (q)->maxlen)
93*b06ebda0SMatthew Dillon 
94*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_DROP(q)	(q)->drops ++
95*b06ebda0SMatthew Dillon 
96*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_ENQUEUE(q, i)			\
97*b06ebda0SMatthew Dillon 	do {						\
98*b06ebda0SMatthew Dillon 		(i)->m_nextpkt = NULL;			\
99*b06ebda0SMatthew Dillon 							\
100*b06ebda0SMatthew Dillon 		if ((q)->tail == NULL)			\
101*b06ebda0SMatthew Dillon 			(q)->head = (i);		\
102*b06ebda0SMatthew Dillon 		else					\
103*b06ebda0SMatthew Dillon 			(q)->tail->m_nextpkt = (i);	\
104*b06ebda0SMatthew Dillon 							\
105*b06ebda0SMatthew Dillon 		(q)->tail = (i);			\
106*b06ebda0SMatthew Dillon 		(q)->len ++;				\
107*b06ebda0SMatthew Dillon 	} while (0)
108*b06ebda0SMatthew Dillon 
109*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_DEQUEUE(q, i)			\
110*b06ebda0SMatthew Dillon 	do {						\
111*b06ebda0SMatthew Dillon 		(i) = (q)->head;			\
112*b06ebda0SMatthew Dillon 		if ((i) != NULL) {			\
113*b06ebda0SMatthew Dillon 			(q)->head = (q)->head->m_nextpkt; \
114*b06ebda0SMatthew Dillon 			if ((q)->head == NULL)		\
115*b06ebda0SMatthew Dillon 				(q)->tail = NULL;	\
116*b06ebda0SMatthew Dillon 							\
117*b06ebda0SMatthew Dillon 			(q)->len --;			\
118*b06ebda0SMatthew Dillon 			(i)->m_nextpkt = NULL;		\
119*b06ebda0SMatthew Dillon 		} 					\
120*b06ebda0SMatthew Dillon 	} while (0)
121*b06ebda0SMatthew Dillon 
122*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_PREPEND(q, i)			\
123*b06ebda0SMatthew Dillon 	do {						\
124*b06ebda0SMatthew Dillon 		(i)->m_nextpkt = (q)->head;		\
125*b06ebda0SMatthew Dillon 		if ((q)->tail == NULL)			\
126*b06ebda0SMatthew Dillon 			(q)->tail = (i);		\
127*b06ebda0SMatthew Dillon 							\
128*b06ebda0SMatthew Dillon 		(q)->head = (i);			\
129*b06ebda0SMatthew Dillon 		(q)->len ++;				\
130*b06ebda0SMatthew Dillon 	} while (0)
131*b06ebda0SMatthew Dillon 
132*b06ebda0SMatthew Dillon #define NG_BT_MBUFQ_DRAIN(q)				\
133*b06ebda0SMatthew Dillon 	do { 						\
134*b06ebda0SMatthew Dillon         	struct mbuf	*m = NULL;		\
135*b06ebda0SMatthew Dillon 							\
136*b06ebda0SMatthew Dillon 		for (;;) { 				\
137*b06ebda0SMatthew Dillon 			NG_BT_MBUFQ_DEQUEUE((q), m);	\
138*b06ebda0SMatthew Dillon 			if (m == NULL) 			\
139*b06ebda0SMatthew Dillon 				break; 			\
140*b06ebda0SMatthew Dillon 							\
141*b06ebda0SMatthew Dillon 			NG_FREE_M(m);	 		\
142*b06ebda0SMatthew Dillon 		} 					\
143*b06ebda0SMatthew Dillon 	} while (0)
144*b06ebda0SMatthew Dillon 
145*b06ebda0SMatthew Dillon /*
146*b06ebda0SMatthew Dillon  * Netgraph item queue and useful itemq macros
147*b06ebda0SMatthew Dillon  */
148*b06ebda0SMatthew Dillon 
149*b06ebda0SMatthew Dillon struct ng_item;
150*b06ebda0SMatthew Dillon 
151*b06ebda0SMatthew Dillon struct ng_bt_itemq {
152*b06ebda0SMatthew Dillon 	STAILQ_HEAD(, ng_item)	queue;	/* actually items queue */
153*b06ebda0SMatthew Dillon 	u_int32_t	 len;    /* number of items in the queue */
154*b06ebda0SMatthew Dillon 	u_int32_t	 maxlen; /* maximal number of items in the queue */
155*b06ebda0SMatthew Dillon 	u_int32_t	 drops;  /* number if dropped items */
156*b06ebda0SMatthew Dillon };
157*b06ebda0SMatthew Dillon typedef struct ng_bt_itemq	ng_bt_itemq_t;
158*b06ebda0SMatthew Dillon typedef struct ng_bt_itemq *	ng_bt_itemq_p;
159*b06ebda0SMatthew Dillon 
160*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_INIT(q, _maxlen)			\
161*b06ebda0SMatthew Dillon 	do {						\
162*b06ebda0SMatthew Dillon 		STAILQ_INIT(&(q)->queue);		\
163*b06ebda0SMatthew Dillon 		(q)->len = 0;				\
164*b06ebda0SMatthew Dillon 		(q)->maxlen = (_maxlen);		\
165*b06ebda0SMatthew Dillon 		(q)->drops = 0;				\
166*b06ebda0SMatthew Dillon 	} while (0)
167*b06ebda0SMatthew Dillon 
168*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_DESTROY(q)				\
169*b06ebda0SMatthew Dillon 	do {						\
170*b06ebda0SMatthew Dillon 		NG_BT_ITEMQ_DRAIN((q));			\
171*b06ebda0SMatthew Dillon 	} while (0)
172*b06ebda0SMatthew Dillon 
173*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_FIRST(q)	STAILQ_FIRST(&(q)->queue)
174*b06ebda0SMatthew Dillon 
175*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_LEN(q)	NG_BT_MBUFQ_LEN((q))
176*b06ebda0SMatthew Dillon 
177*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_FULL(q)	NG_BT_MBUFQ_FULL((q))
178*b06ebda0SMatthew Dillon 
179*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_DROP(q)	NG_BT_MBUFQ_DROP((q))
180*b06ebda0SMatthew Dillon 
181*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_ENQUEUE(q, i)			\
182*b06ebda0SMatthew Dillon 	do {						\
183*b06ebda0SMatthew Dillon 		STAILQ_INSERT_TAIL(&(q)->queue, (i), el_next);	\
184*b06ebda0SMatthew Dillon 		(q)->len ++;				\
185*b06ebda0SMatthew Dillon 	} while (0)
186*b06ebda0SMatthew Dillon 
187*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_DEQUEUE(q, i)			\
188*b06ebda0SMatthew Dillon 	do {						\
189*b06ebda0SMatthew Dillon 		(i) = STAILQ_FIRST(&(q)->queue);	\
190*b06ebda0SMatthew Dillon 		if ((i) != NULL) {			\
191*b06ebda0SMatthew Dillon 			STAILQ_REMOVE_HEAD(&(q)->queue, el_next);	\
192*b06ebda0SMatthew Dillon 			(q)->len --;			\
193*b06ebda0SMatthew Dillon 		} 					\
194*b06ebda0SMatthew Dillon 	} while (0)
195*b06ebda0SMatthew Dillon 
196*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_PREPEND(q, i)			\
197*b06ebda0SMatthew Dillon 	do {						\
198*b06ebda0SMatthew Dillon 		STAILQ_INSERT_HEAD(&(q)->queue, (i), el_next);	\
199*b06ebda0SMatthew Dillon 		(q)->len ++;				\
200*b06ebda0SMatthew Dillon 	} while (0)
201*b06ebda0SMatthew Dillon 
202*b06ebda0SMatthew Dillon #define NG_BT_ITEMQ_DRAIN(q)				\
203*b06ebda0SMatthew Dillon 	do { 						\
204*b06ebda0SMatthew Dillon         	struct ng_item	*i = NULL;		\
205*b06ebda0SMatthew Dillon 							\
206*b06ebda0SMatthew Dillon 		for (;;) { 				\
207*b06ebda0SMatthew Dillon 			NG_BT_ITEMQ_DEQUEUE((q), i);	\
208*b06ebda0SMatthew Dillon 			if (i == NULL) 			\
209*b06ebda0SMatthew Dillon 				break; 			\
210*b06ebda0SMatthew Dillon 							\
211*b06ebda0SMatthew Dillon 			NG_FREE_ITEM(i); 		\
212*b06ebda0SMatthew Dillon 		} 					\
213*b06ebda0SMatthew Dillon 	} while (0)
214*b06ebda0SMatthew Dillon 
215*b06ebda0SMatthew Dillon /*
216*b06ebda0SMatthew Dillon  * Get Bluetooth stack sysctl globals
217*b06ebda0SMatthew Dillon  */
218*b06ebda0SMatthew Dillon 
219*b06ebda0SMatthew Dillon u_int32_t	bluetooth_hci_command_timeout	(void);
220*b06ebda0SMatthew Dillon u_int32_t	bluetooth_hci_connect_timeout	(void);
221*b06ebda0SMatthew Dillon u_int32_t	bluetooth_hci_max_neighbor_age	(void);
222*b06ebda0SMatthew Dillon u_int32_t	bluetooth_l2cap_rtx_timeout	(void);
223*b06ebda0SMatthew Dillon u_int32_t	bluetooth_l2cap_ertx_timeout	(void);
224*b06ebda0SMatthew Dillon 
225*b06ebda0SMatthew Dillon #endif /* _NETGRAPH_BLUETOOTH_H_ */
226*b06ebda0SMatthew Dillon 
227