6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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
32 * $Id: ng_bluetooth.c,v 1.3 2003/04/26 22:37:31 max Exp $
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
41 #include <sys/sysctl.h>
43 #include <netgraph/bluetooth/include/ng_bluetooth.h>
46 * Bluetooth stack sysctl globals
49 static u_int32_t bluetooth_hci_command_timeout_value = 5; /* sec */
50 static u_int32_t bluetooth_hci_connect_timeout_value = 60; /* sec */
51 static u_int32_t bluetooth_hci_max_neighbor_age_value = 600; /* sec */
52 static u_int32_t bluetooth_l2cap_rtx_timeout_value = 60; /* sec */
53 static u_int32_t bluetooth_l2cap_ertx_timeout_value = 300; /* sec */
54 static u_int32_t bluetooth_sco_rtx_timeout_value = 60; /* sec */
57 * Define sysctl tree that shared by other parts of Bluetooth stack
60 SYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW, 0, "Bluetooth family");
61 SYSCTL_INT(_net_bluetooth, OID_AUTO, version,
62 CTLFLAG_RD, SYSCTL_NULL_INT_PTR, NG_BLUETOOTH_VERSION, "Version of the stack");
68 SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW,
69 0, "Bluetooth HCI family");
72 bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS)
77 value = bluetooth_hci_command_timeout_value;
78 error = sysctl_handle_int(oidp, &value, 0, req);
79 if (error == 0 && req->newptr != NULL) {
81 bluetooth_hci_command_timeout_value = value;
87 } /* bluetooth_set_hci_command_timeout_value */
89 SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, command_timeout,
90 CTLTYPE_INT | CTLFLAG_RW,
91 &bluetooth_hci_command_timeout_value, 5,
92 bluetooth_set_hci_command_timeout_value,
93 "I", "HCI command timeout (sec)");
96 bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS)
101 value = bluetooth_hci_connect_timeout_value;
102 error = sysctl_handle_int(oidp, &value, 0, req);
103 if (error == 0 && req->newptr != NULL) {
104 if (0 < value && value <= bluetooth_l2cap_rtx_timeout_value)
105 bluetooth_hci_connect_timeout_value = value;
111 } /* bluetooth_set_hci_connect_timeout_value */
113 SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, connection_timeout,
114 CTLTYPE_INT | CTLFLAG_RW,
115 &bluetooth_hci_connect_timeout_value, 60,
116 bluetooth_set_hci_connect_timeout_value,
117 "I", "HCI connect timeout (sec)");
119 SYSCTL_UINT(_net_bluetooth_hci, OID_AUTO, max_neighbor_age, CTLFLAG_RW,
120 &bluetooth_hci_max_neighbor_age_value, 600,
121 "Maximal HCI neighbor cache entry age (sec)");
127 SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW,
128 0, "Bluetooth L2CAP family");
131 bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
136 value = bluetooth_l2cap_rtx_timeout_value;
137 error = sysctl_handle_int(oidp, &value, 0, req);
138 if (error == 0 && req->newptr != NULL) {
139 if (bluetooth_hci_connect_timeout_value <= value &&
140 value <= bluetooth_l2cap_ertx_timeout_value)
141 bluetooth_l2cap_rtx_timeout_value = value;
147 } /* bluetooth_set_l2cap_rtx_timeout_value */
149 SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, rtx_timeout,
150 CTLTYPE_INT | CTLFLAG_RW,
151 &bluetooth_l2cap_rtx_timeout_value, 60,
152 bluetooth_set_l2cap_rtx_timeout_value,
153 "I", "L2CAP RTX timeout (sec)");
156 bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS)
161 value = bluetooth_l2cap_ertx_timeout_value;
162 error = sysctl_handle_int(oidp, &value, 0, req);
163 if (error == 0 && req->newptr != NULL) {
164 if (value >= bluetooth_l2cap_rtx_timeout_value)
165 bluetooth_l2cap_ertx_timeout_value = value;
171 } /* bluetooth_set_l2cap_ertx_timeout_value */
173 SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, ertx_timeout,
174 CTLTYPE_INT | CTLFLAG_RW,
175 &bluetooth_l2cap_ertx_timeout_value, 300,
176 bluetooth_set_l2cap_ertx_timeout_value,
177 "I", "L2CAP ERTX timeout (sec)");
180 * Return various sysctl values
184 bluetooth_hci_command_timeout(void)
186 return (bluetooth_hci_command_timeout_value * hz);
187 } /* bluetooth_hci_command_timeout */
190 bluetooth_hci_connect_timeout(void)
192 return (bluetooth_hci_connect_timeout_value * hz);
193 } /* bluetooth_hci_connect_timeout */
196 bluetooth_hci_max_neighbor_age(void)
198 return (bluetooth_hci_max_neighbor_age_value);
199 } /* bluetooth_hci_max_neighbor_age */
202 bluetooth_l2cap_rtx_timeout(void)
204 return (bluetooth_l2cap_rtx_timeout_value * hz);
205 } /* bluetooth_l2cap_rtx_timeout */
208 bluetooth_l2cap_ertx_timeout(void)
210 return (bluetooth_l2cap_ertx_timeout_value * hz);
211 } /* bluetooth_l2cap_ertx_timeout */
214 bluetooth_sco_rtx_timeout(void)
216 return (bluetooth_sco_rtx_timeout_value * hz);
217 } /* bluetooth_sco_rtx_timeout */
223 SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW,
224 0, "Bluetooth RFCOMM family");
230 SYSCTL_NODE(_net_bluetooth, OID_AUTO, sco, CTLFLAG_RW,
231 0, "Bluetooth SCO family");
234 bluetooth_set_sco_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
239 value = bluetooth_sco_rtx_timeout_value;
240 error = sysctl_handle_int(oidp, &value, 0, req);
241 if (error == 0 && req->newptr != NULL) {
242 if (bluetooth_hci_connect_timeout_value <= value)
243 bluetooth_sco_rtx_timeout_value = value;
249 } /* bluetooth_set_sco_rtx_timeout_value */
251 SYSCTL_PROC(_net_bluetooth_sco, OID_AUTO, rtx_timeout,
252 CTLTYPE_INT | CTLFLAG_RW,
253 &bluetooth_sco_rtx_timeout_value, 60,
254 bluetooth_set_sco_rtx_timeout_value,
255 "I", "SCO RTX timeout (sec)");
258 * Handle loading and unloading for this code.
262 bluetooth_modevent(module_t mod, int event, void *data)
279 } /* bluetooth_modevent */
285 static moduledata_t bluetooth_mod = {
291 DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
292 MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION);