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