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