xref: /dflybsd-src/sys/netgraph7/bluetooth/common/ng_bluetooth.c (revision e85b99abf6da4a83a7dc495b0ef37ce19864149f)
1b06ebda0SMatthew Dillon /*
2b06ebda0SMatthew Dillon  * bluetooth.c
3b06ebda0SMatthew Dillon  */
4b06ebda0SMatthew Dillon 
5b06ebda0SMatthew Dillon /*-
6b06ebda0SMatthew Dillon  * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7b06ebda0SMatthew Dillon  * All rights reserved.
8b06ebda0SMatthew Dillon  *
9b06ebda0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
10b06ebda0SMatthew Dillon  * modification, are permitted provided that the following conditions
11b06ebda0SMatthew Dillon  * are met:
12b06ebda0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
13b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
14b06ebda0SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
15b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
16b06ebda0SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
17b06ebda0SMatthew Dillon  *
18b06ebda0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19b06ebda0SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b06ebda0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b06ebda0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22b06ebda0SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23b06ebda0SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24b06ebda0SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25b06ebda0SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26b06ebda0SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27b06ebda0SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28b06ebda0SMatthew Dillon  * SUCH DAMAGE.
29b06ebda0SMatthew Dillon  *
30b06ebda0SMatthew Dillon  * $Id: ng_bluetooth.c,v 1.3 2003/04/26 22:37:31 max Exp $
31b06ebda0SMatthew Dillon  * $FreeBSD: src/sys/netgraph/bluetooth/common/ng_bluetooth.c,v 1.7 2007/06/04 18:25:07 dwmalone Exp $
32b06ebda0SMatthew Dillon  */
33b06ebda0SMatthew Dillon 
34b06ebda0SMatthew Dillon #include <sys/param.h>
35b06ebda0SMatthew Dillon #include <sys/systm.h>
36b06ebda0SMatthew Dillon #include <sys/errno.h>
37b06ebda0SMatthew Dillon #include <sys/kernel.h>
38b06ebda0SMatthew Dillon #include <sys/module.h>
39b06ebda0SMatthew Dillon #include <sys/sysctl.h>
40b06ebda0SMatthew Dillon 
41*e85b99abSSascha Wildner #include <netgraph7/bluetooth/include/ng_bluetooth.h>
42b06ebda0SMatthew Dillon 
43b06ebda0SMatthew Dillon /*
44b06ebda0SMatthew Dillon  * Bluetooth stack sysctl globals
45b06ebda0SMatthew Dillon  */
46b06ebda0SMatthew Dillon 
47b06ebda0SMatthew Dillon static u_int32_t	bluetooth_hci_command_timeout_value  = 5;   /* sec */
48b06ebda0SMatthew Dillon static u_int32_t	bluetooth_hci_connect_timeout_value  = 60;  /* sec */
49b06ebda0SMatthew Dillon static u_int32_t	bluetooth_hci_max_neighbor_age_value = 600; /* sec */
50b06ebda0SMatthew Dillon static u_int32_t	bluetooth_l2cap_rtx_timeout_value    = 60;  /* sec */
51b06ebda0SMatthew Dillon static u_int32_t	bluetooth_l2cap_ertx_timeout_value   = 300; /* sec */
52b06ebda0SMatthew Dillon 
53b06ebda0SMatthew Dillon /*
54b06ebda0SMatthew Dillon  * Define sysctl tree that shared by other parts of Bluetooth stack
55b06ebda0SMatthew Dillon  */
56b06ebda0SMatthew Dillon 
57b06ebda0SMatthew Dillon SYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW, 0, "Bluetooth family");
58b06ebda0SMatthew Dillon SYSCTL_INT(_net_bluetooth, OID_AUTO, version,
59b06ebda0SMatthew Dillon 	CTLFLAG_RD, 0, NG_BLUETOOTH_VERSION, "");
60b06ebda0SMatthew Dillon 
61b06ebda0SMatthew Dillon /*
62b06ebda0SMatthew Dillon  * HCI
63b06ebda0SMatthew Dillon  */
64b06ebda0SMatthew Dillon 
65b06ebda0SMatthew Dillon SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW,
66b06ebda0SMatthew Dillon 	0, "Bluetooth HCI family");
67b06ebda0SMatthew Dillon 
68b06ebda0SMatthew Dillon static int
bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS)69b06ebda0SMatthew Dillon bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS)
70b06ebda0SMatthew Dillon {
71b06ebda0SMatthew Dillon 	u_int32_t	value;
72b06ebda0SMatthew Dillon 	int		error;
73b06ebda0SMatthew Dillon 
74b06ebda0SMatthew Dillon 	value = bluetooth_hci_command_timeout_value;
75b06ebda0SMatthew Dillon 	error = sysctl_handle_int(oidp, &value, 0, req);
76b06ebda0SMatthew Dillon 	if (error == 0 && req->newptr != NULL) {
77b06ebda0SMatthew Dillon 		if (value > 0)
78b06ebda0SMatthew Dillon 			bluetooth_hci_command_timeout_value = value;
79b06ebda0SMatthew Dillon 		else
80b06ebda0SMatthew Dillon 			error = EINVAL;
81b06ebda0SMatthew Dillon 	}
82b06ebda0SMatthew Dillon 
83b06ebda0SMatthew Dillon 	return (error);
84b06ebda0SMatthew Dillon } /* bluetooth_set_hci_command_timeout_value */
85b06ebda0SMatthew Dillon 
86b06ebda0SMatthew Dillon SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, command_timeout,
87b06ebda0SMatthew Dillon 	CTLTYPE_INT | CTLFLAG_RW,
88b06ebda0SMatthew Dillon 	&bluetooth_hci_command_timeout_value, 5,
89b06ebda0SMatthew Dillon 	bluetooth_set_hci_command_timeout_value,
90b06ebda0SMatthew Dillon 	"I", "HCI command timeout (sec)");
91b06ebda0SMatthew Dillon 
92b06ebda0SMatthew Dillon static int
bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS)93b06ebda0SMatthew Dillon bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS)
94b06ebda0SMatthew Dillon {
95b06ebda0SMatthew Dillon 	u_int32_t	value;
96b06ebda0SMatthew Dillon 	int		error;
97b06ebda0SMatthew Dillon 
98b06ebda0SMatthew Dillon 	value = bluetooth_hci_connect_timeout_value;
99b06ebda0SMatthew Dillon 	error = sysctl_handle_int(oidp, &value, 0, req);
100b06ebda0SMatthew Dillon 	if (error == 0 && req->newptr != NULL) {
101b06ebda0SMatthew Dillon 		if (0 < value && value <= bluetooth_l2cap_rtx_timeout_value)
102b06ebda0SMatthew Dillon 			bluetooth_hci_connect_timeout_value = value;
103b06ebda0SMatthew Dillon 		else
104b06ebda0SMatthew Dillon 			error = EINVAL;
105b06ebda0SMatthew Dillon 	}
106b06ebda0SMatthew Dillon 
107b06ebda0SMatthew Dillon 	return (error);
108b06ebda0SMatthew Dillon } /* bluetooth_set_hci_connect_timeout_value */
109b06ebda0SMatthew Dillon 
110b06ebda0SMatthew Dillon SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, connection_timeout,
111b06ebda0SMatthew Dillon 	CTLTYPE_INT | CTLFLAG_RW,
112b06ebda0SMatthew Dillon 	&bluetooth_hci_connect_timeout_value, 60,
113b06ebda0SMatthew Dillon 	bluetooth_set_hci_connect_timeout_value,
114b06ebda0SMatthew Dillon 	"I", "HCI connect timeout (sec)");
115b06ebda0SMatthew Dillon 
116b06ebda0SMatthew Dillon SYSCTL_INT(_net_bluetooth_hci, OID_AUTO, max_neighbor_age, CTLFLAG_RW,
117b06ebda0SMatthew Dillon 	&bluetooth_hci_max_neighbor_age_value, 600,
118b06ebda0SMatthew Dillon 	"Maximal HCI neighbor cache entry age (sec)");
119b06ebda0SMatthew Dillon 
120b06ebda0SMatthew Dillon /*
121b06ebda0SMatthew Dillon  * L2CAP
122b06ebda0SMatthew Dillon  */
123b06ebda0SMatthew Dillon 
124b06ebda0SMatthew Dillon SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW,
125b06ebda0SMatthew Dillon 	0, "Bluetooth L2CAP family");
126b06ebda0SMatthew Dillon 
127b06ebda0SMatthew Dillon static int
bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS)128b06ebda0SMatthew Dillon bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
129b06ebda0SMatthew Dillon {
130b06ebda0SMatthew Dillon 	u_int32_t	value;
131b06ebda0SMatthew Dillon 	int		error;
132b06ebda0SMatthew Dillon 
133b06ebda0SMatthew Dillon 	value = bluetooth_l2cap_rtx_timeout_value;
134b06ebda0SMatthew Dillon 	error = sysctl_handle_int(oidp, &value, 0, req);
135b06ebda0SMatthew Dillon 	if (error == 0 && req->newptr != NULL) {
136b06ebda0SMatthew Dillon 		if (bluetooth_hci_connect_timeout_value <= value &&
137b06ebda0SMatthew Dillon 		    value <= bluetooth_l2cap_ertx_timeout_value)
138b06ebda0SMatthew Dillon 			bluetooth_l2cap_rtx_timeout_value = value;
139b06ebda0SMatthew Dillon 		else
140b06ebda0SMatthew Dillon 			error = EINVAL;
141b06ebda0SMatthew Dillon 	}
142b06ebda0SMatthew Dillon 
143b06ebda0SMatthew Dillon 	return (error);
144b06ebda0SMatthew Dillon } /* bluetooth_set_l2cap_rtx_timeout_value */
145b06ebda0SMatthew Dillon 
146b06ebda0SMatthew Dillon SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, rtx_timeout,
147b06ebda0SMatthew Dillon 	CTLTYPE_INT | CTLFLAG_RW,
148b06ebda0SMatthew Dillon 	&bluetooth_l2cap_rtx_timeout_value, 60,
149b06ebda0SMatthew Dillon 	bluetooth_set_l2cap_rtx_timeout_value,
150b06ebda0SMatthew Dillon 	"I", "L2CAP RTX timeout (sec)");
151b06ebda0SMatthew Dillon 
152b06ebda0SMatthew Dillon static int
bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS)153b06ebda0SMatthew Dillon bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS)
154b06ebda0SMatthew Dillon {
155b06ebda0SMatthew Dillon 	u_int32_t	value;
156b06ebda0SMatthew Dillon 	int		error;
157b06ebda0SMatthew Dillon 
158b06ebda0SMatthew Dillon 	value = bluetooth_l2cap_ertx_timeout_value;
159b06ebda0SMatthew Dillon 	error = sysctl_handle_int(oidp, &value, 0, req);
160b06ebda0SMatthew Dillon 	if (error == 0 && req->newptr != NULL) {
161b06ebda0SMatthew Dillon 		if (value >= bluetooth_l2cap_rtx_timeout_value)
162b06ebda0SMatthew Dillon 			bluetooth_l2cap_ertx_timeout_value = value;
163b06ebda0SMatthew Dillon 		else
164b06ebda0SMatthew Dillon 			error = EINVAL;
165b06ebda0SMatthew Dillon 	}
166b06ebda0SMatthew Dillon 
167b06ebda0SMatthew Dillon 	return (error);
168b06ebda0SMatthew Dillon } /* bluetooth_set_l2cap_ertx_timeout_value */
169b06ebda0SMatthew Dillon 
170b06ebda0SMatthew Dillon SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, ertx_timeout,
171b06ebda0SMatthew Dillon 	CTLTYPE_INT | CTLFLAG_RW,
172b06ebda0SMatthew Dillon 	&bluetooth_l2cap_ertx_timeout_value, 300,
173b06ebda0SMatthew Dillon 	bluetooth_set_l2cap_ertx_timeout_value,
174b06ebda0SMatthew Dillon 	"I", "L2CAP ERTX timeout (sec)");
175b06ebda0SMatthew Dillon 
176b06ebda0SMatthew Dillon /*
177b06ebda0SMatthew Dillon  * Return various sysctl values
178b06ebda0SMatthew Dillon  */
179b06ebda0SMatthew Dillon 
180b06ebda0SMatthew Dillon u_int32_t
bluetooth_hci_command_timeout(void)181b06ebda0SMatthew Dillon bluetooth_hci_command_timeout(void)
182b06ebda0SMatthew Dillon {
183b06ebda0SMatthew Dillon 	return (bluetooth_hci_command_timeout_value * hz);
184b06ebda0SMatthew Dillon } /* bluetooth_hci_command_timeout */
185b06ebda0SMatthew Dillon 
186b06ebda0SMatthew Dillon u_int32_t
bluetooth_hci_connect_timeout(void)187b06ebda0SMatthew Dillon bluetooth_hci_connect_timeout(void)
188b06ebda0SMatthew Dillon {
189b06ebda0SMatthew Dillon 	return (bluetooth_hci_connect_timeout_value * hz);
190b06ebda0SMatthew Dillon } /* bluetooth_hci_connect_timeout */
191b06ebda0SMatthew Dillon 
192b06ebda0SMatthew Dillon u_int32_t
bluetooth_hci_max_neighbor_age(void)193b06ebda0SMatthew Dillon bluetooth_hci_max_neighbor_age(void)
194b06ebda0SMatthew Dillon {
195b06ebda0SMatthew Dillon 	return (bluetooth_hci_max_neighbor_age_value);
196b06ebda0SMatthew Dillon } /* bluetooth_hci_max_neighbor_age */
197b06ebda0SMatthew Dillon 
198b06ebda0SMatthew Dillon u_int32_t
bluetooth_l2cap_rtx_timeout(void)199b06ebda0SMatthew Dillon bluetooth_l2cap_rtx_timeout(void)
200b06ebda0SMatthew Dillon {
201b06ebda0SMatthew Dillon 	return (bluetooth_l2cap_rtx_timeout_value * hz);
202b06ebda0SMatthew Dillon } /* bluetooth_l2cap_rtx_timeout */
203b06ebda0SMatthew Dillon 
204b06ebda0SMatthew Dillon u_int32_t
bluetooth_l2cap_ertx_timeout(void)205b06ebda0SMatthew Dillon bluetooth_l2cap_ertx_timeout(void)
206b06ebda0SMatthew Dillon {
207b06ebda0SMatthew Dillon 	return (bluetooth_l2cap_ertx_timeout_value * hz);
208b06ebda0SMatthew Dillon } /* bluetooth_l2cap_ertx_timeout */
209b06ebda0SMatthew Dillon 
210b06ebda0SMatthew Dillon /*
211b06ebda0SMatthew Dillon  * RFCOMM
212b06ebda0SMatthew Dillon  */
213b06ebda0SMatthew Dillon 
214b06ebda0SMatthew Dillon SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW,
215b06ebda0SMatthew Dillon 	0, "Bluetooth RFCOMM family");
216b06ebda0SMatthew Dillon 
217b06ebda0SMatthew Dillon /*
218b06ebda0SMatthew Dillon  * Handle loading and unloading for this code.
219b06ebda0SMatthew Dillon  */
220b06ebda0SMatthew Dillon 
221b06ebda0SMatthew Dillon static int
bluetooth_modevent(module_t mod,int event,void * data)222b06ebda0SMatthew Dillon bluetooth_modevent(module_t mod, int event, void *data)
223b06ebda0SMatthew Dillon {
224b06ebda0SMatthew Dillon 	int	error = 0;
225b06ebda0SMatthew Dillon 
226b06ebda0SMatthew Dillon 	switch (event) {
227b06ebda0SMatthew Dillon 	case MOD_LOAD:
228b06ebda0SMatthew Dillon 		break;
229b06ebda0SMatthew Dillon 
230b06ebda0SMatthew Dillon 	case MOD_UNLOAD:
231b06ebda0SMatthew Dillon 		break;
232b06ebda0SMatthew Dillon 
233b06ebda0SMatthew Dillon 	default:
234b06ebda0SMatthew Dillon 		error = EOPNOTSUPP;
235b06ebda0SMatthew Dillon 		break;
236b06ebda0SMatthew Dillon 	}
237b06ebda0SMatthew Dillon 
238b06ebda0SMatthew Dillon 	return (error);
239b06ebda0SMatthew Dillon } /* bluetooth_modevent */
240b06ebda0SMatthew Dillon 
241b06ebda0SMatthew Dillon /*
242b06ebda0SMatthew Dillon  * Module
243b06ebda0SMatthew Dillon  */
244b06ebda0SMatthew Dillon 
245b06ebda0SMatthew Dillon static moduledata_t	bluetooth_mod = {
246b06ebda0SMatthew Dillon 	"ng_bluetooth",
247b06ebda0SMatthew Dillon 	bluetooth_modevent,
248b06ebda0SMatthew Dillon 	NULL
249b06ebda0SMatthew Dillon };
250b06ebda0SMatthew Dillon 
251b06ebda0SMatthew Dillon DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
252b06ebda0SMatthew Dillon MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION);
253b06ebda0SMatthew Dillon 
254