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