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