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