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