6 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
30 * $Id: ng_bluetooth.c,v 1.3 2003/04/26 22:37:31 max Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/sysctl.h>
41 #include <netgraph/bluetooth/include/ng_bluetooth.h>
44 * Bluetooth stack sysctl globals
47 static u_int32_t bluetooth_hci_command_timeout_value = 5; /* sec */
48 static u_int32_t bluetooth_hci_connect_timeout_value = 60; /* sec */
49 static u_int32_t bluetooth_hci_max_neighbor_age_value = 600; /* sec */
50 static u_int32_t bluetooth_l2cap_rtx_timeout_value = 60; /* sec */
51 static u_int32_t bluetooth_l2cap_ertx_timeout_value = 300; /* sec */
52 static u_int32_t bluetooth_sco_rtx_timeout_value = 60; /* sec */
55 * Define sysctl tree that shared by other parts of Bluetooth stack
58 SYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW, 0, "Bluetooth family");
59 SYSCTL_INT(_net_bluetooth, OID_AUTO, version,
60 CTLFLAG_RD, 0, NG_BLUETOOTH_VERSION, "Version of the stack");
66 SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW,
67 0, "Bluetooth HCI family");
70 bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS)
75 value = bluetooth_hci_command_timeout_value;
76 error = sysctl_handle_int(oidp, &value, 0, req);
77 if (error == 0 && req->newptr != NULL) {
79 bluetooth_hci_command_timeout_value = value;
85 } /* bluetooth_set_hci_command_timeout_value */
87 SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, command_timeout,
88 CTLTYPE_INT | CTLFLAG_RW,
89 &bluetooth_hci_command_timeout_value, 5,
90 bluetooth_set_hci_command_timeout_value,
91 "I", "HCI command timeout (sec)");
94 bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS)
99 value = bluetooth_hci_connect_timeout_value;
100 error = sysctl_handle_int(oidp, &value, 0, req);
101 if (error == 0 && req->newptr != NULL) {
102 if (0 < value && value <= bluetooth_l2cap_rtx_timeout_value)
103 bluetooth_hci_connect_timeout_value = value;
109 } /* bluetooth_set_hci_connect_timeout_value */
111 SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, connection_timeout,
112 CTLTYPE_INT | CTLFLAG_RW,
113 &bluetooth_hci_connect_timeout_value, 60,
114 bluetooth_set_hci_connect_timeout_value,
115 "I", "HCI connect timeout (sec)");
117 SYSCTL_UINT(_net_bluetooth_hci, OID_AUTO, max_neighbor_age, CTLFLAG_RW,
118 &bluetooth_hci_max_neighbor_age_value, 600,
119 "Maximal HCI neighbor cache entry age (sec)");
125 SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW,
126 0, "Bluetooth L2CAP family");
129 bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
134 value = bluetooth_l2cap_rtx_timeout_value;
135 error = sysctl_handle_int(oidp, &value, 0, req);
136 if (error == 0 && req->newptr != NULL) {
137 if (bluetooth_hci_connect_timeout_value <= value &&
138 value <= bluetooth_l2cap_ertx_timeout_value)
139 bluetooth_l2cap_rtx_timeout_value = value;
145 } /* bluetooth_set_l2cap_rtx_timeout_value */
147 SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, rtx_timeout,
148 CTLTYPE_INT | CTLFLAG_RW,
149 &bluetooth_l2cap_rtx_timeout_value, 60,
150 bluetooth_set_l2cap_rtx_timeout_value,
151 "I", "L2CAP RTX timeout (sec)");
154 bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS)
159 value = bluetooth_l2cap_ertx_timeout_value;
160 error = sysctl_handle_int(oidp, &value, 0, req);
161 if (error == 0 && req->newptr != NULL) {
162 if (value >= bluetooth_l2cap_rtx_timeout_value)
163 bluetooth_l2cap_ertx_timeout_value = value;
169 } /* bluetooth_set_l2cap_ertx_timeout_value */
171 SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, ertx_timeout,
172 CTLTYPE_INT | CTLFLAG_RW,
173 &bluetooth_l2cap_ertx_timeout_value, 300,
174 bluetooth_set_l2cap_ertx_timeout_value,
175 "I", "L2CAP ERTX timeout (sec)");
178 * Return various sysctl values
182 bluetooth_hci_command_timeout(void)
184 return (bluetooth_hci_command_timeout_value * hz);
185 } /* bluetooth_hci_command_timeout */
188 bluetooth_hci_connect_timeout(void)
190 return (bluetooth_hci_connect_timeout_value * hz);
191 } /* bluetooth_hci_connect_timeout */
194 bluetooth_hci_max_neighbor_age(void)
196 return (bluetooth_hci_max_neighbor_age_value);
197 } /* bluetooth_hci_max_neighbor_age */
200 bluetooth_l2cap_rtx_timeout(void)
202 return (bluetooth_l2cap_rtx_timeout_value * hz);
203 } /* bluetooth_l2cap_rtx_timeout */
206 bluetooth_l2cap_ertx_timeout(void)
208 return (bluetooth_l2cap_ertx_timeout_value * hz);
209 } /* bluetooth_l2cap_ertx_timeout */
212 bluetooth_sco_rtx_timeout(void)
214 return (bluetooth_sco_rtx_timeout_value * hz);
215 } /* bluetooth_sco_rtx_timeout */
221 SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW,
222 0, "Bluetooth RFCOMM family");
228 SYSCTL_NODE(_net_bluetooth, OID_AUTO, sco, CTLFLAG_RW,
229 0, "Bluetooth SCO family");
232 bluetooth_set_sco_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
237 value = bluetooth_sco_rtx_timeout_value;
238 error = sysctl_handle_int(oidp, &value, 0, req);
239 if (error == 0 && req->newptr != NULL) {
240 if (bluetooth_hci_connect_timeout_value <= value)
241 bluetooth_sco_rtx_timeout_value = value;
247 } /* bluetooth_set_sco_rtx_timeout_value */
249 SYSCTL_PROC(_net_bluetooth_sco, OID_AUTO, rtx_timeout,
250 CTLTYPE_INT | CTLFLAG_RW,
251 &bluetooth_sco_rtx_timeout_value, 60,
252 bluetooth_set_sco_rtx_timeout_value,
253 "I", "SCO RTX timeout (sec)");
256 * Handle loading and unloading for this code.
260 bluetooth_modevent(module_t mod, int event, void *data)
277 } /* bluetooth_modevent */
283 static moduledata_t bluetooth_mod = {
289 DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
290 MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION);