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