ng_bluetooth.c revision 180399
10Sduke/* 22933Sakulyakh * bluetooth.c 30Sduke */ 40Sduke 50Sduke/*- 60Sduke * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com> 70Sduke * All rights reserved. 80Sduke * 90Sduke * Redistribution and use in source and binary forms, with or without 100Sduke * modification, are permitted provided that the following conditions 110Sduke * are met: 120Sduke * 1. Redistributions of source code must retain the above copyright 130Sduke * notice, this list of conditions and the following disclaimer. 140Sduke * 2. Redistributions in binary form must reproduce the above copyright 150Sduke * notice, this list of conditions and the following disclaimer in the 160Sduke * documentation and/or other materials provided with the distribution. 170Sduke * 180Sduke * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19553Sohair * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20553Sohair * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21553Sohair * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 220Sduke * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 230Sduke * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 240Sduke * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 250Sduke * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 260Sduke * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 270Sduke * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 282933Sakulyakh * SUCH DAMAGE. 290Sduke * 300Sduke * $Id: ng_bluetooth.c,v 1.3 2003/04/26 22:37:31 max Exp $ 310Sduke * $FreeBSD: head/sys/netgraph/bluetooth/common/ng_bluetooth.c 180399 2008-07-10 00:15:29Z emax $ 320Sduke */ 330Sduke 340Sduke#include <sys/param.h> 350Sduke#include <sys/systm.h> 360Sduke#include <sys/errno.h> 370Sduke#include <sys/kernel.h> 380Sduke#include <sys/module.h> 390Sduke#include <sys/sysctl.h> 400Sduke 410Sduke#include <netgraph/bluetooth/include/ng_bluetooth.h> 420Sduke 430Sduke/* 440Sduke * Bluetooth stack sysctl globals 450Sduke */ 460Sduke 470Sdukestatic u_int32_t bluetooth_hci_command_timeout_value = 5; /* sec */ 480Sdukestatic u_int32_t bluetooth_hci_connect_timeout_value = 60; /* sec */ 490Sdukestatic u_int32_t bluetooth_hci_max_neighbor_age_value = 600; /* sec */ 500Sdukestatic u_int32_t bluetooth_l2cap_rtx_timeout_value = 60; /* sec */ 510Sdukestatic u_int32_t bluetooth_l2cap_ertx_timeout_value = 300; /* sec */ 520Sdukestatic u_int32_t bluetooth_sco_rtx_timeout_value = 60; /* sec */ 530Sduke 540Sduke/* 550Sduke * Define sysctl tree that shared by other parts of Bluetooth stack 560Sduke */ 570Sduke 580SdukeSYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW, 0, "Bluetooth family"); 590SdukeSYSCTL_INT(_net_bluetooth, OID_AUTO, version, 600Sduke CTLFLAG_RD, 0, NG_BLUETOOTH_VERSION, ""); 610Sduke 620Sduke/* 630Sduke * HCI 640Sduke */ 650Sduke 660SdukeSYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW, 670Sduke 0, "Bluetooth HCI family"); 680Sduke 690Sdukestatic int 700Sdukebluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS) 710Sduke{ 720Sduke u_int32_t value; 730Sduke int error; 740Sduke 750Sduke value = bluetooth_hci_command_timeout_value; 760Sduke error = sysctl_handle_int(oidp, &value, 0, req); 770Sduke if (error == 0 && req->newptr != NULL) { 780Sduke if (value > 0) 790Sduke bluetooth_hci_command_timeout_value = value; 800Sduke else 810Sduke error = EINVAL; 820Sduke } 83 84 return (error); 85} /* bluetooth_set_hci_command_timeout_value */ 86 87SYSCTL_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 93static int 94bluetooth_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 111SYSCTL_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 117SYSCTL_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 125SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW, 126 0, "Bluetooth L2CAP family"); 127 128static int 129bluetooth_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 147SYSCTL_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 153static int 154bluetooth_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 171SYSCTL_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 181u_int32_t 182bluetooth_hci_command_timeout(void) 183{ 184 return (bluetooth_hci_command_timeout_value * hz); 185} /* bluetooth_hci_command_timeout */ 186 187u_int32_t 188bluetooth_hci_connect_timeout(void) 189{ 190 return (bluetooth_hci_connect_timeout_value * hz); 191} /* bluetooth_hci_connect_timeout */ 192 193u_int32_t 194bluetooth_hci_max_neighbor_age(void) 195{ 196 return (bluetooth_hci_max_neighbor_age_value); 197} /* bluetooth_hci_max_neighbor_age */ 198 199u_int32_t 200bluetooth_l2cap_rtx_timeout(void) 201{ 202 return (bluetooth_l2cap_rtx_timeout_value * hz); 203} /* bluetooth_l2cap_rtx_timeout */ 204 205u_int32_t 206bluetooth_l2cap_ertx_timeout(void) 207{ 208 return (bluetooth_l2cap_ertx_timeout_value * hz); 209} /* bluetooth_l2cap_ertx_timeout */ 210 211u_int32_t 212bluetooth_sco_rtx_timeout(void) 213{ 214 return (bluetooth_sco_rtx_timeout_value * hz); 215} /* bluetooth_sco_rtx_timeout */ 216 217/* 218 * RFCOMM 219 */ 220 221SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW, 222 0, "Bluetooth RFCOMM family"); 223 224/* 225 * SCO 226 */ 227 228SYSCTL_NODE(_net_bluetooth, OID_AUTO, sco, CTLFLAG_RW, 229 0, "Bluetooth SCO family"); 230 231static int 232bluetooth_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 249SYSCTL_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 259static int 260bluetooth_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 283static moduledata_t bluetooth_mod = { 284 "ng_bluetooth", 285 bluetooth_modevent, 286 NULL 287}; 288 289DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 290MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION); 291 292