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