1 /* 2 * bluetooth.c 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_bluetooth.c,v 1.3 2003/04/26 22:37:31 max Exp $ 31 * $FreeBSD$ 32 */ 33 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> 40 41 #include <netgraph/bluetooth/include/ng_bluetooth.h> 42 43 /* 44 * Bluetooth stack sysctl globals 45 */ 46 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 */ 53 54 /* 55 * Define sysctl tree that shared by other parts of Bluetooth stack 56 */ 57 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"); 61 62 /* 63 * HCI 64 */ 65 66 SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW, 67 0, "Bluetooth HCI family"); 68 69 static int 70 bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS) 71 { 72 u_int32_t value; 73 int error; 74 75 value = bluetooth_hci_command_timeout_value; 76 error = sysctl_handle_int(oidp, &value, 0, req); 77 if (error == 0 && req->newptr != NULL) { 78 if (value > 0) 79 bluetooth_hci_command_timeout_value = value; 80 else 81 error = EINVAL; 82 } 83 84 return (error); 85 } /* bluetooth_set_hci_command_timeout_value */ 86 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)"); 92 93 static int 94 bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS) 95 { 96 u_int32_t value; 97 int error; 98 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; 104 else 105 error = EINVAL; 106 } 107 108 return (error); 109 } /* bluetooth_set_hci_connect_timeout_value */ 110 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)"); 116 117 SYSCTL_INT(_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)"); 120 121 /* 122 * L2CAP 123 */ 124 125 SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW, 126 0, "Bluetooth L2CAP family"); 127 128 static int 129 bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS) 130 { 131 u_int32_t value; 132 int error; 133 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; 140 else 141 error = EINVAL; 142 } 143 144 return (error); 145 } /* bluetooth_set_l2cap_rtx_timeout_value */ 146 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)"); 152 153 static int 154 bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS) 155 { 156 u_int32_t value; 157 int error; 158 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; 164 else 165 error = EINVAL; 166 } 167 168 return (error); 169 } /* bluetooth_set_l2cap_ertx_timeout_value */ 170 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)"); 176 177 /* 178 * Return various sysctl values 179 */ 180 181 u_int32_t 182 bluetooth_hci_command_timeout(void) 183 { 184 return (bluetooth_hci_command_timeout_value * hz); 185 } /* bluetooth_hci_command_timeout */ 186 187 u_int32_t 188 bluetooth_hci_connect_timeout(void) 189 { 190 return (bluetooth_hci_connect_timeout_value * hz); 191 } /* bluetooth_hci_connect_timeout */ 192 193 u_int32_t 194 bluetooth_hci_max_neighbor_age(void) 195 { 196 return (bluetooth_hci_max_neighbor_age_value); 197 } /* bluetooth_hci_max_neighbor_age */ 198 199 u_int32_t 200 bluetooth_l2cap_rtx_timeout(void) 201 { 202 return (bluetooth_l2cap_rtx_timeout_value * hz); 203 } /* bluetooth_l2cap_rtx_timeout */ 204 205 u_int32_t 206 bluetooth_l2cap_ertx_timeout(void) 207 { 208 return (bluetooth_l2cap_ertx_timeout_value * hz); 209 } /* bluetooth_l2cap_ertx_timeout */ 210 211 u_int32_t 212 bluetooth_sco_rtx_timeout(void) 213 { 214 return (bluetooth_sco_rtx_timeout_value * hz); 215 } /* bluetooth_sco_rtx_timeout */ 216 217 /* 218 * RFCOMM 219 */ 220 221 SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW, 222 0, "Bluetooth RFCOMM family"); 223 224 /* 225 * SCO 226 */ 227 228 SYSCTL_NODE(_net_bluetooth, OID_AUTO, sco, CTLFLAG_RW, 229 0, "Bluetooth SCO family"); 230 231 static int 232 bluetooth_set_sco_rtx_timeout_value(SYSCTL_HANDLER_ARGS) 233 { 234 u_int32_t value; 235 int error; 236 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; 242 else 243 error = EINVAL; 244 } 245 246 return (error); 247 } /* bluetooth_set_sco_rtx_timeout_value */ 248 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)"); 254 255 /* 256 * Handle loading and unloading for this code. 257 */ 258 259 static int 260 bluetooth_modevent(module_t mod, int event, void *data) 261 { 262 int error = 0; 263 264 switch (event) { 265 case MOD_LOAD: 266 break; 267 268 case MOD_UNLOAD: 269 break; 270 271 default: 272 error = EOPNOTSUPP; 273 break; 274 } 275 276 return (error); 277 } /* bluetooth_modevent */ 278 279 /* 280 * Module 281 */ 282 283 static moduledata_t bluetooth_mod = { 284 "ng_bluetooth", 285 bluetooth_modevent, 286 NULL 287 }; 288 289 DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 290 MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION); 291 292