1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
/* $OpenBSD: bt.h,v 1.2 2005/01/17 18:12:49 mickey Exp $ */
/*
* ng_btsocket.h
*
* Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket.h,v 1.6 2004/08/20 01:24:23 julian Exp $
*/
#ifndef _NETGRAPH_BTSOCKET_H_
#define _NETGRAPH_BTSOCKET_H_
/*
* XXX: bitstring operations, must be removed later.
*/
typedef unsigned char bitstr_t;
#define bitstr_size(nbits) (((nbits) + 7) >> 3)
#define bit_decl(name, nbits) ((name)[bitstr_size(nbits)])
#define _bit_byte(bit) ((bit) >> 3)
#define _bit_mask(bit) (1 << ((bit)&0x7))
#define bit_test(name, bit) ((name)[_bit_byte(bit)] & _bit_mask(bit))
#define bit_set(name, bit) ((name)[_bit_byte(bit)] |= _bit_mask(bit))
#define bit_clear(name, bit) ((name)[_bit_byte(bit)] &= ~_bit_mask(bit))
/*
* Bluetooth protocols
*/
#define BLUETOOTH_PROTO_HCI 134 /* HCI protocol number */
#define BLUETOOTH_PROTO_L2CAP 135 /* L2CAP protocol number */
#define BLUETOOTH_PROTO_RFCOMM 136 /* RFCOMM protocol number */
/*
* Bluetooth version of struct sockaddr for raw HCI sockets
*/
struct sockaddr_hci {
u_char hci_len; /* total length */
u_char hci_family; /* address family */
char hci_node[32]; /* address (size == NG_NODESIZ ) */
};
/* Raw HCI socket options */
#define SOL_HCI_RAW 0x0802 /* socket options level */
#define SO_HCI_RAW_FILTER 1 /* get/set filter on socket */
#define SO_HCI_RAW_DIRECTION 2 /* turn on/off direction info */
#define SCM_HCI_RAW_DIRECTION SO_HCI_RAW_DIRECTION /* cmsg_type */
/*
* Raw HCI socket filter.
*
* For packet mask use (1 << (HCI packet indicator - 1))
* For event mask use (1 << (Event - 1))
*/
struct ng_btsocket_hci_raw_filter {
bitstr_t bit_decl(packet_mask, 32);
bitstr_t bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8));
};
/*
* Raw HCI sockets ioctl's
*/
/* Get state */
struct ng_btsocket_hci_raw_node_state {
ng_hci_node_state_ep state;
};
#define SIOC_HCI_RAW_NODE_GET_STATE \
_IOWR('b', NGM_HCI_NODE_GET_STATE, \
struct ng_btsocket_hci_raw_node_state)
/* Initialize */
#define SIOC_HCI_RAW_NODE_INIT \
_IO('b', NGM_HCI_NODE_INIT)
/* Get/Set debug level */
struct ng_btsocket_hci_raw_node_debug {
ng_hci_node_debug_ep debug;
};
#define SIOC_HCI_RAW_NODE_GET_DEBUG \
_IOWR('b', NGM_HCI_NODE_GET_DEBUG, \
struct ng_btsocket_hci_raw_node_debug)
#define SIOC_HCI_RAW_NODE_SET_DEBUG \
_IOWR('b', NGM_HCI_NODE_SET_DEBUG, \
struct ng_btsocket_hci_raw_node_debug)
/* Get buffer info */
struct ng_btsocket_hci_raw_node_buffer {
ng_hci_node_buffer_ep buffer;
};
#define SIOC_HCI_RAW_NODE_GET_BUFFER \
_IOWR('b', NGM_HCI_NODE_GET_BUFFER, \
struct ng_btsocket_hci_raw_node_buffer)
/* Get BD_ADDR */
struct ng_btsocket_hci_raw_node_bdaddr {
bdaddr_t bdaddr;
};
#define SIOC_HCI_RAW_NODE_GET_BDADDR \
_IOWR('b', NGM_HCI_NODE_GET_BDADDR, \
struct ng_btsocket_hci_raw_node_bdaddr)
/* Get features */
struct ng_btsocket_hci_raw_node_features {
u_int8_t features[NG_HCI_FEATURES_SIZE];
};
#define SIOC_HCI_RAW_NODE_GET_FEATURES \
_IOWR('b', NGM_HCI_NODE_GET_FEATURES, \
struct ng_btsocket_hci_raw_node_features)
/* Get stat */
struct ng_btsocket_hci_raw_node_stat {
ng_hci_node_stat_ep stat;
};
#define SIOC_HCI_RAW_NODE_GET_STAT \
_IOWR('b', NGM_HCI_NODE_GET_STAT, \
struct ng_btsocket_hci_raw_node_stat)
/* Reset stat */
#define SIOC_HCI_RAW_NODE_RESET_STAT \
_IO('b', NGM_HCI_NODE_RESET_STAT)
/* Flush neighbor cache */
#define SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE \
_IO('b', NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE)
/* Get neighbor cache */
struct ng_btsocket_hci_raw_node_neighbor_cache {
u_int32_t num_entries;
ng_hci_node_neighbor_cache_entry_ep *entries;
};
#define SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE \
_IOWR('b', NGM_HCI_NODE_GET_NEIGHBOR_CACHE, \
struct ng_btsocket_hci_raw_node_neighbor_cache)
/* Get connection list */
struct ng_btsocket_hci_raw_con_list {
u_int32_t num_connections;
ng_hci_node_con_ep *connections;
};
#define SIOC_HCI_RAW_NODE_GET_CON_LIST \
_IOWR('b', NGM_HCI_NODE_GET_CON_LIST, \
struct ng_btsocket_hci_raw_con_list)
/* Get/Set link policy settings mask */
struct ng_btsocket_hci_raw_node_link_policy_mask {
ng_hci_node_link_policy_mask_ep policy_mask;
};
#define SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK \
_IOWR('b', NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK, \
struct ng_btsocket_hci_raw_node_link_policy_mask)
#define SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK \
_IOWR('b', NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK, \
struct ng_btsocket_hci_raw_node_link_policy_mask)
/* Get/Set packet mask */
struct ng_btsocket_hci_raw_node_packet_mask {
ng_hci_node_packet_mask_ep packet_mask;
};
#define SIOC_HCI_RAW_NODE_GET_PACKET_MASK \
_IOWR('b', NGM_HCI_NODE_GET_PACKET_MASK, \
struct ng_btsocket_hci_raw_node_packet_mask)
#define SIOC_HCI_RAW_NODE_SET_PACKET_MASK \
_IOWR('b', NGM_HCI_NODE_SET_PACKET_MASK, \
struct ng_btsocket_hci_raw_node_packet_mask)
/* Get/Set role switch */
struct ng_btsocket_hci_raw_node_role_switch {
ng_hci_node_role_switch_ep role_switch;
};
#define SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH \
_IOWR('b', NGM_HCI_NODE_GET_ROLE_SWITCH, \
struct ng_btsocket_hci_raw_node_role_switch)
#define SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH \
_IOWR('b', NGM_HCI_NODE_SET_ROLE_SWITCH, \
struct ng_btsocket_hci_raw_node_role_switch)
/*
* XXX FIXME: probably does not belong here
* Bluetooth version of struct sockaddr for L2CAP sockets (RAW and SEQPACKET)
*/
struct sockaddr_l2cap {
u_char l2cap_len; /* total length */
u_char l2cap_family; /* address family */
u_int16_t l2cap_psm; /* PSM (Protocol/Service Multiplexor) */
bdaddr_t l2cap_bdaddr; /* address */
};
/* L2CAP socket options */
#define SOL_L2CAP 0x1609 /* socket option level */
#define SO_L2CAP_IMTU 1 /* get/set incoming MTU */
#define SO_L2CAP_OMTU 2 /* get outgoing (peer incoming) MTU */
#define SO_L2CAP_IFLOW 3 /* get incoming flow spec. */
#define SO_L2CAP_OFLOW 4 /* get/set outgoing flow spec. */
#define SO_L2CAP_FLUSH 5 /* get/set flush timeout */
/*
* Raw L2CAP sockets ioctl's
*/
/* Ping */
struct ng_btsocket_l2cap_raw_ping {
u_int32_t result;
u_int32_t echo_size;
u_int8_t *echo_data;
};
#define SIOC_L2CAP_L2CA_PING \
_IOWR('b', NGM_L2CAP_L2CA_PING, \
struct ng_btsocket_l2cap_raw_ping)
/* Get info */
struct ng_btsocket_l2cap_raw_get_info {
u_int32_t result;
u_int32_t info_type;
u_int32_t info_size;
u_int8_t *info_data;
};
#define SIOC_L2CAP_L2CA_GET_INFO \
_IOWR('b', NGM_L2CAP_L2CA_GET_INFO, \
struct ng_btsocket_l2cap_raw_get_info)
/* Get flags */
struct ng_btsocket_l2cap_raw_node_flags {
ng_l2cap_node_flags_ep flags;
};
#define SIOC_L2CAP_NODE_GET_FLAGS \
_IOWR('b', NGM_L2CAP_NODE_GET_FLAGS, \
struct ng_btsocket_l2cap_raw_node_flags)
/* Get/Set debug level */
struct ng_btsocket_l2cap_raw_node_debug {
ng_l2cap_node_debug_ep debug;
};
#define SIOC_L2CAP_NODE_GET_DEBUG \
_IOWR('b', NGM_L2CAP_NODE_GET_DEBUG, \
struct ng_btsocket_l2cap_raw_node_debug)
#define SIOC_L2CAP_NODE_SET_DEBUG \
_IOWR('b', NGM_L2CAP_NODE_SET_DEBUG, \
struct ng_btsocket_l2cap_raw_node_debug)
/* Get connection list */
struct ng_btsocket_l2cap_raw_con_list {
u_int32_t num_connections;
ng_l2cap_node_con_ep *connections;
};
#define SIOC_L2CAP_NODE_GET_CON_LIST \
_IOWR('b', NGM_L2CAP_NODE_GET_CON_LIST, \
struct ng_btsocket_l2cap_raw_con_list)
/* Get channel list */
struct ng_btsocket_l2cap_raw_chan_list {
u_int32_t num_channels;
ng_l2cap_node_chan_ep *channels;
};
#define SIOC_L2CAP_NODE_GET_CHAN_LIST \
_IOWR('b', NGM_L2CAP_NODE_GET_CHAN_LIST, \
struct ng_btsocket_l2cap_raw_chan_list)
/* Get/Set auto disconnect timeout */
struct ng_btsocket_l2cap_raw_auto_discon_timo
{
ng_l2cap_node_auto_discon_ep timeout;
};
#define SIOC_L2CAP_NODE_GET_AUTO_DISCON_TIMO \
_IOWR('b', NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO, \
struct ng_btsocket_l2cap_raw_auto_discon_timo)
#define SIOC_L2CAP_NODE_SET_AUTO_DISCON_TIMO \
_IOWR('b', NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO, \
struct ng_btsocket_l2cap_raw_auto_discon_timo)
/*
* XXX FIXME: probably does not belong here
* Bluetooth version of struct sockaddr for RFCOMM sockets (STREAM)
*/
struct sockaddr_rfcomm {
u_char rfcomm_len; /* total length */
u_char rfcomm_family; /* address family */
bdaddr_t rfcomm_bdaddr; /* address */
u_int8_t rfcomm_channel; /* channel */
};
/* Flow control information */
struct ng_btsocket_rfcomm_fc_info {
u_int8_t lmodem; /* modem signals (local) */
u_int8_t rmodem; /* modem signals (remote) */
u_int8_t tx_cred; /* TX credits */
u_int8_t rx_cred; /* RX credits */
u_int8_t cfc; /* credit flow control */
u_int8_t reserved;
};
/* STREAM RFCOMM socket options */
#define SOL_RFCOMM 0x0816 /* socket options level */
#define SO_RFCOMM_MTU 1 /* get channel MTU */
#define SO_RFCOMM_FC_INFO 2 /* get flow control information */
/*
* Netgraph node type name and cookie
*/
#define NG_BTSOCKET_HCI_RAW_NODE_TYPE "btsock_hci_raw"
#define NG_BTSOCKET_L2CAP_RAW_NODE_TYPE "btsock_l2c_raw"
#define NG_BTSOCKET_L2CAP_NODE_TYPE "btsock_l2c"
/*
* Debug levels
*/
#define NG_BTSOCKET_ALERT_LEVEL 1
#define NG_BTSOCKET_ERR_LEVEL 2
#define NG_BTSOCKET_WARN_LEVEL 3
#define NG_BTSOCKET_INFO_LEVEL 4
#endif /* _NETGRAPH_BTSOCKET_H_ */
|