xref: /freebsd/sys/netgraph/bluetooth/include/ng_bluetooth.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /*
2  * bluetooth.h
3  */
4 
5 /*-
6  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7  *
8  * Copyright (c) 2001-2002 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_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $
33  * $FreeBSD$
34  */
35 
36 #ifndef _NETGRAPH_BLUETOOTH_H_
37 #define _NETGRAPH_BLUETOOTH_H_
38 
39 #include <sys/queue.h>
40 
41 /*
42  * Version of the stack
43  */
44 
45 #define NG_BLUETOOTH_VERSION	1
46 
47 /*
48  * Declare the base of the Bluetooth sysctl hierarchy,
49  * but only if this file cares about sysctl's
50  */
51 
52 #ifdef SYSCTL_DECL
53 SYSCTL_DECL(_net_bluetooth);
54 SYSCTL_DECL(_net_bluetooth_hci);
55 SYSCTL_DECL(_net_bluetooth_l2cap);
56 SYSCTL_DECL(_net_bluetooth_rfcomm);
57 SYSCTL_DECL(_net_bluetooth_sco);
58 #endif /* SYSCTL_DECL */
59 
60 /*
61  * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we
62  * do not need mutex and other locking stuff
63  */
64 
65 struct mbuf;
66 
67 struct ng_bt_mbufq {
68 	struct mbuf	*head;   /* first item in the queue */
69 	struct mbuf	*tail;   /* last item in the queue */
70 	u_int32_t	 len;    /* number of items in the queue */
71 	u_int32_t	 maxlen; /* maximal number of items in the queue */
72 	u_int32_t	 drops;	 /* number if dropped items */
73 };
74 typedef struct ng_bt_mbufq	ng_bt_mbufq_t;
75 typedef struct ng_bt_mbufq *	ng_bt_mbufq_p;
76 
77 #define NG_BT_MBUFQ_INIT(q, _maxlen)			\
78 	do {						\
79 		(q)->head = NULL;			\
80 		(q)->tail = NULL;			\
81 		(q)->len = 0;				\
82 		(q)->maxlen = (_maxlen);		\
83 		(q)->drops = 0;				\
84 	} while (0)
85 
86 #define NG_BT_MBUFQ_DESTROY(q)				\
87 	do {						\
88 		NG_BT_MBUFQ_DRAIN((q));			\
89 	} while (0)
90 
91 #define NG_BT_MBUFQ_FIRST(q)	(q)->head
92 
93 #define NG_BT_MBUFQ_LEN(q)	(q)->len
94 
95 #define NG_BT_MBUFQ_FULL(q)	((q)->len >= (q)->maxlen)
96 
97 #define NG_BT_MBUFQ_DROP(q)	(q)->drops ++
98 
99 #define NG_BT_MBUFQ_ENQUEUE(q, i)			\
100 	do {						\
101 		(i)->m_nextpkt = NULL;			\
102 							\
103 		if ((q)->tail == NULL)			\
104 			(q)->head = (i);		\
105 		else					\
106 			(q)->tail->m_nextpkt = (i);	\
107 							\
108 		(q)->tail = (i);			\
109 		(q)->len ++;				\
110 	} while (0)
111 
112 #define NG_BT_MBUFQ_DEQUEUE(q, i)			\
113 	do {						\
114 		(i) = (q)->head;			\
115 		if ((i) != NULL) {			\
116 			(q)->head = (q)->head->m_nextpkt; \
117 			if ((q)->head == NULL)		\
118 				(q)->tail = NULL;	\
119 							\
120 			(q)->len --;			\
121 			(i)->m_nextpkt = NULL;		\
122 		} 					\
123 	} while (0)
124 
125 #define NG_BT_MBUFQ_PREPEND(q, i)			\
126 	do {						\
127 		(i)->m_nextpkt = (q)->head;		\
128 		if ((q)->tail == NULL)			\
129 			(q)->tail = (i);		\
130 							\
131 		(q)->head = (i);			\
132 		(q)->len ++;				\
133 	} while (0)
134 
135 #define NG_BT_MBUFQ_DRAIN(q)				\
136 	do { 						\
137         	struct mbuf	*m = NULL;		\
138 							\
139 		for (;;) { 				\
140 			NG_BT_MBUFQ_DEQUEUE((q), m);	\
141 			if (m == NULL) 			\
142 				break; 			\
143 							\
144 			NG_FREE_M(m);	 		\
145 		} 					\
146 	} while (0)
147 
148 /*
149  * Netgraph item queue and useful itemq macros
150  */
151 
152 struct ng_item;
153 
154 struct ng_bt_itemq {
155 	STAILQ_HEAD(, ng_item)	queue;	/* actually items queue */
156 	u_int32_t	 len;    /* number of items in the queue */
157 	u_int32_t	 maxlen; /* maximal number of items in the queue */
158 	u_int32_t	 drops;  /* number if dropped items */
159 };
160 typedef struct ng_bt_itemq	ng_bt_itemq_t;
161 typedef struct ng_bt_itemq *	ng_bt_itemq_p;
162 
163 #define NG_BT_ITEMQ_INIT(q, _maxlen)			\
164 	do {						\
165 		STAILQ_INIT(&(q)->queue);		\
166 		(q)->len = 0;				\
167 		(q)->maxlen = (_maxlen);		\
168 		(q)->drops = 0;				\
169 	} while (0)
170 
171 #define NG_BT_ITEMQ_DESTROY(q)				\
172 	do {						\
173 		NG_BT_ITEMQ_DRAIN((q));			\
174 	} while (0)
175 
176 #define NG_BT_ITEMQ_FIRST(q)	STAILQ_FIRST(&(q)->queue)
177 
178 #define NG_BT_ITEMQ_LEN(q)	NG_BT_MBUFQ_LEN((q))
179 
180 #define NG_BT_ITEMQ_FULL(q)	NG_BT_MBUFQ_FULL((q))
181 
182 #define NG_BT_ITEMQ_DROP(q)	NG_BT_MBUFQ_DROP((q))
183 
184 #define NG_BT_ITEMQ_ENQUEUE(q, i)			\
185 	do {						\
186 		STAILQ_INSERT_TAIL(&(q)->queue, (i), el_next);	\
187 		(q)->len ++;				\
188 	} while (0)
189 
190 #define NG_BT_ITEMQ_DEQUEUE(q, i)			\
191 	do {						\
192 		(i) = STAILQ_FIRST(&(q)->queue);	\
193 		if ((i) != NULL) {			\
194 			STAILQ_REMOVE_HEAD(&(q)->queue, el_next);	\
195 			(q)->len --;			\
196 		} 					\
197 	} while (0)
198 
199 #define NG_BT_ITEMQ_PREPEND(q, i)			\
200 	do {						\
201 		STAILQ_INSERT_HEAD(&(q)->queue, (i), el_next);	\
202 		(q)->len ++;				\
203 	} while (0)
204 
205 #define NG_BT_ITEMQ_DRAIN(q)				\
206 	do { 						\
207         	struct ng_item	*i = NULL;		\
208 							\
209 		for (;;) { 				\
210 			NG_BT_ITEMQ_DEQUEUE((q), i);	\
211 			if (i == NULL) 			\
212 				break; 			\
213 							\
214 			NG_FREE_ITEM(i); 		\
215 		} 					\
216 	} while (0)
217 
218 /*
219  * Get Bluetooth stack sysctl globals
220  */
221 
222 u_int32_t	bluetooth_hci_command_timeout	(void);
223 u_int32_t	bluetooth_hci_connect_timeout	(void);
224 u_int32_t	bluetooth_hci_max_neighbor_age	(void);
225 u_int32_t	bluetooth_l2cap_rtx_timeout	(void);
226 u_int32_t	bluetooth_l2cap_ertx_timeout	(void);
227 u_int32_t      bluetooth_sco_rtx_timeout       (void);
228 
229 #define BDADDR_BREDR 0
230 #define BDADDR_LE_PUBLIC 1
231 #define BDADDR_LE_RANDOM 2
232 
233 #endif /* _NETGRAPH_BLUETOOTH_H_ */
234