Vendor import of netgraph from FreeBSD-current 20080626
[dragonfly.git] / sys / netgraph7 / bluetooth / include / ng_bluetooth.h
blobc59812b9bfbbe31bbd20c905a2b823346f182bd7
1 /*
2 * bluetooth.h
3 */
5 /*-
6 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * All rights reserved.
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.
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.
30 * $Id: ng_bluetooth.h,v 1.4 2003/04/26 22:32:34 max Exp $
31 * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_bluetooth.h,v 1.5 2008/04/15 21:15:32 mav Exp $
34 #ifndef _NETGRAPH_BLUETOOTH_H_
35 #define _NETGRAPH_BLUETOOTH_H_
37 #include <sys/queue.h>
40 * Version of the stack
43 #define NG_BLUETOOTH_VERSION 1
46 * Declare the base of the Bluetooth sysctl hierarchy,
47 * but only if this file cares about sysctl's
50 #ifdef SYSCTL_DECL
51 SYSCTL_DECL(_net_bluetooth);
52 SYSCTL_DECL(_net_bluetooth_hci);
53 SYSCTL_DECL(_net_bluetooth_l2cap);
54 SYSCTL_DECL(_net_bluetooth_rfcomm);
55 #endif /* SYSCTL_DECL */
58 * Mbuf qeueue and useful mbufq macros. We do not use ifqueue because we
59 * do not need mutex and other locking stuff
62 struct mbuf;
64 struct 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 */
71 typedef struct ng_bt_mbufq ng_bt_mbufq_t;
72 typedef struct ng_bt_mbufq * ng_bt_mbufq_p;
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)
83 #define NG_BT_MBUFQ_DESTROY(q) \
84 do { \
85 NG_BT_MBUFQ_DRAIN((q)); \
86 } while (0)
88 #define NG_BT_MBUFQ_FIRST(q) (q)->head
90 #define NG_BT_MBUFQ_LEN(q) (q)->len
92 #define NG_BT_MBUFQ_FULL(q) ((q)->len >= (q)->maxlen)
94 #define NG_BT_MBUFQ_DROP(q) (q)->drops ++
96 #define NG_BT_MBUFQ_ENQUEUE(q, i) \
97 do { \
98 (i)->m_nextpkt = NULL; \
100 if ((q)->tail == NULL) \
101 (q)->head = (i); \
102 else \
103 (q)->tail->m_nextpkt = (i); \
105 (q)->tail = (i); \
106 (q)->len ++; \
107 } while (0)
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; \
117 (q)->len --; \
118 (i)->m_nextpkt = NULL; \
120 } while (0)
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); \
128 (q)->head = (i); \
129 (q)->len ++; \
130 } while (0)
132 #define NG_BT_MBUFQ_DRAIN(q) \
133 do { \
134 struct mbuf *m = NULL; \
136 for (;;) { \
137 NG_BT_MBUFQ_DEQUEUE((q), m); \
138 if (m == NULL) \
139 break; \
141 NG_FREE_M(m); \
143 } while (0)
146 * Netgraph item queue and useful itemq macros
149 struct ng_item;
151 struct 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 */
157 typedef struct ng_bt_itemq ng_bt_itemq_t;
158 typedef struct ng_bt_itemq * ng_bt_itemq_p;
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)
168 #define NG_BT_ITEMQ_DESTROY(q) \
169 do { \
170 NG_BT_ITEMQ_DRAIN((q)); \
171 } while (0)
173 #define NG_BT_ITEMQ_FIRST(q) STAILQ_FIRST(&(q)->queue)
175 #define NG_BT_ITEMQ_LEN(q) NG_BT_MBUFQ_LEN((q))
177 #define NG_BT_ITEMQ_FULL(q) NG_BT_MBUFQ_FULL((q))
179 #define NG_BT_ITEMQ_DROP(q) NG_BT_MBUFQ_DROP((q))
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)
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 --; \
194 } while (0)
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)
202 #define NG_BT_ITEMQ_DRAIN(q) \
203 do { \
204 struct ng_item *i = NULL; \
206 for (;;) { \
207 NG_BT_ITEMQ_DEQUEUE((q), i); \
208 if (i == NULL) \
209 break; \
211 NG_FREE_ITEM(i); \
213 } while (0)
216 * Get Bluetooth stack sysctl globals
219 u_int32_t bluetooth_hci_command_timeout (void);
220 u_int32_t bluetooth_hci_connect_timeout (void);
221 u_int32_t bluetooth_hci_max_neighbor_age (void);
222 u_int32_t bluetooth_l2cap_rtx_timeout (void);
223 u_int32_t bluetooth_l2cap_ertx_timeout (void);
225 #endif /* _NETGRAPH_BLUETOOTH_H_ */