xref: /freebsd/sys/netgraph/bluetooth/include/ng_btsocket.h (revision 39beb93c3f8bdbf72a61fda42300b5ebed7390c8)
1 /*
2  * ng_btsocket.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_btsocket.h,v 1.8 2003/04/26 22:32:10 max Exp $
31  * $FreeBSD$
32  */
33 
34 #ifndef _NETGRAPH_BTSOCKET_H_
35 #define _NETGRAPH_BTSOCKET_H_
36 
37 /*
38  * Bluetooth protocols
39  */
40 
41 #define BLUETOOTH_PROTO_HCI	134	/* HCI protocol number */
42 #define BLUETOOTH_PROTO_L2CAP	135	/* L2CAP protocol number */
43 #define BLUETOOTH_PROTO_RFCOMM	136	/* RFCOMM protocol number */
44 #define BLUETOOTH_PROTO_SCO	137	/* SCO protocol number */
45 
46 /*
47  * Bluetooth version of struct sockaddr for raw HCI sockets
48  */
49 
50 struct sockaddr_hci {
51 	u_char		hci_len;	/* total length */
52 	u_char		hci_family;	/* address family */
53 	char		hci_node[32];	/* address (size == NG_NODESIZ ) */
54 };
55 
56 /* Raw HCI socket options */
57 #define SOL_HCI_RAW		0x0802	/* socket options level */
58 
59 #define SO_HCI_RAW_FILTER	1	/* get/set filter on socket */
60 #define SO_HCI_RAW_DIRECTION	2	/* turn on/off direction info */
61 #define SCM_HCI_RAW_DIRECTION	SO_HCI_RAW_DIRECTION /* cmsg_type  */
62 
63 /*
64  * Raw HCI socket filter.
65  *
66  * For packet mask use (1 << (HCI packet indicator - 1))
67  * For event mask use (1 << (Event - 1))
68  */
69 
70 struct ng_btsocket_hci_raw_filter {
71 	bitstr_t	bit_decl(packet_mask, 32);
72 	bitstr_t	bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8));
73 };
74 
75 /*
76  * Raw HCI sockets ioctl's
77  */
78 
79 /* Get state */
80 struct ng_btsocket_hci_raw_node_state {
81 	ng_hci_node_state_ep	state;
82 };
83 #define SIOC_HCI_RAW_NODE_GET_STATE \
84 	_IOWR('b', NGM_HCI_NODE_GET_STATE, \
85 		struct ng_btsocket_hci_raw_node_state)
86 
87 /* Initialize */
88 #define SIOC_HCI_RAW_NODE_INIT \
89 	_IO('b', NGM_HCI_NODE_INIT)
90 
91 /* Get/Set debug level */
92 struct ng_btsocket_hci_raw_node_debug {
93 	ng_hci_node_debug_ep	debug;
94 };
95 #define SIOC_HCI_RAW_NODE_GET_DEBUG \
96 	_IOWR('b', NGM_HCI_NODE_GET_DEBUG, \
97 		struct ng_btsocket_hci_raw_node_debug)
98 #define SIOC_HCI_RAW_NODE_SET_DEBUG \
99 	_IOWR('b', NGM_HCI_NODE_SET_DEBUG, \
100 		struct ng_btsocket_hci_raw_node_debug)
101 
102 /* Get buffer info */
103 struct ng_btsocket_hci_raw_node_buffer {
104 	ng_hci_node_buffer_ep	buffer;
105 };
106 #define SIOC_HCI_RAW_NODE_GET_BUFFER \
107 	_IOWR('b', NGM_HCI_NODE_GET_BUFFER, \
108 		struct ng_btsocket_hci_raw_node_buffer)
109 
110 /* Get BD_ADDR */
111 struct ng_btsocket_hci_raw_node_bdaddr {
112 	bdaddr_t	bdaddr;
113 };
114 #define SIOC_HCI_RAW_NODE_GET_BDADDR \
115 	_IOWR('b', NGM_HCI_NODE_GET_BDADDR, \
116 		struct ng_btsocket_hci_raw_node_bdaddr)
117 
118 /* Get features */
119 struct ng_btsocket_hci_raw_node_features {
120 	u_int8_t	features[NG_HCI_FEATURES_SIZE];
121 };
122 #define SIOC_HCI_RAW_NODE_GET_FEATURES \
123 	_IOWR('b', NGM_HCI_NODE_GET_FEATURES, \
124 		struct ng_btsocket_hci_raw_node_features)
125 
126 /* Get stat */
127 struct ng_btsocket_hci_raw_node_stat {
128 	ng_hci_node_stat_ep	stat;
129 };
130 #define SIOC_HCI_RAW_NODE_GET_STAT \
131 	_IOWR('b', NGM_HCI_NODE_GET_STAT, \
132 		struct ng_btsocket_hci_raw_node_stat)
133 
134 /* Reset stat */
135 #define SIOC_HCI_RAW_NODE_RESET_STAT \
136 	_IO('b', NGM_HCI_NODE_RESET_STAT)
137 
138 /* Flush neighbor cache */
139 #define SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE \
140 	_IO('b', NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE)
141 
142 /* Get neighbor cache */
143 struct ng_btsocket_hci_raw_node_neighbor_cache {
144 	u_int32_t				 num_entries;
145 	ng_hci_node_neighbor_cache_entry_ep	*entries;
146 };
147 #define SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE \
148 	_IOWR('b', NGM_HCI_NODE_GET_NEIGHBOR_CACHE, \
149 		struct ng_btsocket_hci_raw_node_neighbor_cache)
150 
151 /* Get connection list */
152 struct ng_btsocket_hci_raw_con_list {
153 	u_int32_t		 num_connections;
154 	ng_hci_node_con_ep	*connections;
155 };
156 #define SIOC_HCI_RAW_NODE_GET_CON_LIST \
157 	_IOWR('b', NGM_HCI_NODE_GET_CON_LIST, \
158 		struct ng_btsocket_hci_raw_con_list)
159 
160 /* Get/Set link policy settings mask */
161 struct ng_btsocket_hci_raw_node_link_policy_mask {
162 	ng_hci_node_link_policy_mask_ep	policy_mask;
163 };
164 #define SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK \
165 	_IOWR('b', NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK, \
166 		struct ng_btsocket_hci_raw_node_link_policy_mask)
167 #define SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK \
168 	_IOWR('b', NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK, \
169 		struct ng_btsocket_hci_raw_node_link_policy_mask)
170 
171 /* Get/Set packet mask */
172 struct ng_btsocket_hci_raw_node_packet_mask {
173 	ng_hci_node_packet_mask_ep	packet_mask;
174 };
175 #define SIOC_HCI_RAW_NODE_GET_PACKET_MASK \
176 	_IOWR('b', NGM_HCI_NODE_GET_PACKET_MASK, \
177 		struct ng_btsocket_hci_raw_node_packet_mask)
178 #define SIOC_HCI_RAW_NODE_SET_PACKET_MASK \
179 	_IOWR('b', NGM_HCI_NODE_SET_PACKET_MASK, \
180 		struct ng_btsocket_hci_raw_node_packet_mask)
181 
182 /* Get/Set role switch */
183 struct ng_btsocket_hci_raw_node_role_switch {
184 	ng_hci_node_role_switch_ep	role_switch;
185 };
186 #define SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH \
187 	_IOWR('b', NGM_HCI_NODE_GET_ROLE_SWITCH, \
188 		struct ng_btsocket_hci_raw_node_role_switch)
189 #define SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH \
190 	_IOWR('b', NGM_HCI_NODE_SET_ROLE_SWITCH, \
191 		struct ng_btsocket_hci_raw_node_role_switch)
192 
193 /* Get list of HCI node names */
194 struct ng_btsocket_hci_raw_node_list_names {
195 	u_int32_t	 num_names;
196 	struct nodeinfo	*names;
197 };
198 #define SIOC_HCI_RAW_NODE_LIST_NAMES \
199 	_IOWR('b', NGM_HCI_NODE_LIST_NAMES, \
200 		struct ng_btsocket_hci_raw_node_list_names)
201 
202 /*
203  * XXX FIXME: probably does not belong here
204  * Bluetooth version of struct sockaddr for SCO sockets (SEQPACKET)
205  */
206 
207 struct sockaddr_sco {
208 	u_char		sco_len;	/* total length */
209 	u_char		sco_family;	/* address family */
210 	bdaddr_t	sco_bdaddr;	/* address */
211 };
212 
213 /* SCO socket options */
214 #define SOL_SCO		0x0209		/* socket options level */
215 
216 #define SO_SCO_MTU	1		/* get sockets mtu */
217 #define SO_SCO_CONNINFO	2		/* get HCI connection handle */
218 
219 /*
220  * XXX FIXME: probably does not belong here
221  * Bluetooth version of struct sockaddr for L2CAP sockets (RAW and SEQPACKET)
222  */
223 
224 struct sockaddr_l2cap {
225 	u_char		l2cap_len;	/* total length */
226 	u_char		l2cap_family;	/* address family */
227 	u_int16_t	l2cap_psm;	/* PSM (Protocol/Service Multiplexor) */
228 	bdaddr_t	l2cap_bdaddr;	/* address */
229 };
230 
231 /* L2CAP socket options */
232 #define SOL_L2CAP		0x1609	/* socket option level */
233 
234 #define SO_L2CAP_IMTU		1	/* get/set incoming MTU */
235 #define SO_L2CAP_OMTU		2	/* get outgoing (peer incoming) MTU */
236 #define SO_L2CAP_IFLOW		3	/* get incoming flow spec. */
237 #define SO_L2CAP_OFLOW		4	/* get/set outgoing flow spec. */
238 #define SO_L2CAP_FLUSH		5	/* get/set flush timeout */
239 
240 /*
241  * Raw L2CAP sockets ioctl's
242  */
243 
244 /* Ping */
245 struct ng_btsocket_l2cap_raw_ping {
246 	u_int32_t		 result;
247 	u_int32_t		 echo_size;
248 	u_int8_t		*echo_data;
249 };
250 #define SIOC_L2CAP_L2CA_PING \
251 	_IOWR('b', NGM_L2CAP_L2CA_PING, \
252 		struct ng_btsocket_l2cap_raw_ping)
253 
254 /* Get info */
255 struct ng_btsocket_l2cap_raw_get_info {
256 	u_int32_t		 result;
257 	u_int32_t		 info_type;
258 	u_int32_t		 info_size;
259 	u_int8_t		*info_data;
260 };
261 #define SIOC_L2CAP_L2CA_GET_INFO \
262 	_IOWR('b', NGM_L2CAP_L2CA_GET_INFO, \
263 		struct ng_btsocket_l2cap_raw_get_info)
264 
265 /* Get flags */
266 struct ng_btsocket_l2cap_raw_node_flags {
267 	ng_l2cap_node_flags_ep	flags;
268 };
269 #define SIOC_L2CAP_NODE_GET_FLAGS \
270 	_IOWR('b', NGM_L2CAP_NODE_GET_FLAGS, \
271 		struct ng_btsocket_l2cap_raw_node_flags)
272 
273 /* Get/Set debug level */
274 struct ng_btsocket_l2cap_raw_node_debug {
275 	ng_l2cap_node_debug_ep	debug;
276 };
277 #define SIOC_L2CAP_NODE_GET_DEBUG \
278 	_IOWR('b', NGM_L2CAP_NODE_GET_DEBUG, \
279 		struct ng_btsocket_l2cap_raw_node_debug)
280 #define SIOC_L2CAP_NODE_SET_DEBUG \
281 	_IOWR('b', NGM_L2CAP_NODE_SET_DEBUG, \
282 		struct ng_btsocket_l2cap_raw_node_debug)
283 
284 /* Get connection list */
285 struct ng_btsocket_l2cap_raw_con_list {
286 	u_int32_t		 num_connections;
287 	ng_l2cap_node_con_ep	*connections;
288 };
289 #define SIOC_L2CAP_NODE_GET_CON_LIST \
290 	_IOWR('b', NGM_L2CAP_NODE_GET_CON_LIST, \
291 		struct ng_btsocket_l2cap_raw_con_list)
292 
293 /* Get channel list */
294 struct ng_btsocket_l2cap_raw_chan_list {
295 	u_int32_t		 num_channels;
296 	ng_l2cap_node_chan_ep	*channels;
297 };
298 #define SIOC_L2CAP_NODE_GET_CHAN_LIST \
299 	_IOWR('b', NGM_L2CAP_NODE_GET_CHAN_LIST, \
300 		struct ng_btsocket_l2cap_raw_chan_list)
301 
302 /* Get/Set auto disconnect timeout */
303 struct ng_btsocket_l2cap_raw_auto_discon_timo
304 {
305 	ng_l2cap_node_auto_discon_ep	timeout;
306 };
307 #define SIOC_L2CAP_NODE_GET_AUTO_DISCON_TIMO \
308 	_IOWR('b', NGM_L2CAP_NODE_GET_AUTO_DISCON_TIMO, \
309 		struct ng_btsocket_l2cap_raw_auto_discon_timo)
310 #define SIOC_L2CAP_NODE_SET_AUTO_DISCON_TIMO \
311 	_IOWR('b', NGM_L2CAP_NODE_SET_AUTO_DISCON_TIMO, \
312 		struct ng_btsocket_l2cap_raw_auto_discon_timo)
313 
314 /*
315  * XXX FIXME: probably does not belong here
316  * Bluetooth version of struct sockaddr for RFCOMM sockets (STREAM)
317  */
318 
319 struct sockaddr_rfcomm {
320 	u_char		rfcomm_len;	/* total length */
321 	u_char		rfcomm_family;	/* address family */
322 	bdaddr_t	rfcomm_bdaddr;	/* address */
323 	u_int8_t	rfcomm_channel;	/* channel */
324 };
325 
326 /* Flow control information */
327 struct ng_btsocket_rfcomm_fc_info {
328 	u_int8_t	lmodem;		/* modem signals (local) */
329 	u_int8_t	rmodem;		/* modem signals (remote) */
330 	u_int8_t	tx_cred;	/* TX credits */
331 	u_int8_t	rx_cred;	/* RX credits */
332 	u_int8_t	cfc;		/* credit flow control */
333 	u_int8_t	reserved;
334 };
335 
336 /* STREAM RFCOMM socket options */
337 #define SOL_RFCOMM		0x0816	/* socket options level */
338 
339 #define SO_RFCOMM_MTU		1	/* get channel MTU */
340 #define SO_RFCOMM_FC_INFO	2	/* get flow control information */
341 
342 /*
343  * Netgraph node type name and cookie
344  */
345 
346 #define	NG_BTSOCKET_HCI_RAW_NODE_TYPE	"btsock_hci_raw"
347 #define	NG_BTSOCKET_L2CAP_RAW_NODE_TYPE	"btsock_l2c_raw"
348 #define	NG_BTSOCKET_L2CAP_NODE_TYPE	"btsock_l2c"
349 #define	NG_BTSOCKET_SCO_NODE_TYPE	"btsock_sco"
350 
351 /*
352  * Debug levels
353  */
354 
355 #define NG_BTSOCKET_ALERT_LEVEL	1
356 #define NG_BTSOCKET_ERR_LEVEL	2
357 #define NG_BTSOCKET_WARN_LEVEL	3
358 #define NG_BTSOCKET_INFO_LEVEL	4
359 
360 #endif /* _NETGRAPH_BTSOCKET_H_ */
361 
362