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