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.3 2003/04/26 22:37:31 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_max_neighbor_age_value = 600; /* sec */ 47 static u_int32_t bluetooth_l2cap_rtx_timeout_value = 60; /* sec */ 48 static u_int32_t bluetooth_l2cap_ertx_timeout_value = 300; /* sec */ 49 50 /* 51 * Define sysctl tree that shared by other parts of Bluetooth stack 52 */ 53 54 SYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW, 0, "Bluetooth family"); 55 SYSCTL_INT(_net_bluetooth, OID_AUTO, version, 56 CTLFLAG_RD, 0, NG_BLUETOOTH_VERSION, ""); 57 58 /* 59 * HCI 60 */ 61 62 SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW, 63 0, "Bluetooth HCI family"); 64 65 static int 66 bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS) 67 { 68 u_int32_t value; 69 int error; 70 71 value = bluetooth_hci_command_timeout_value; 72 error = sysctl_handle_int(oidp, &value, sizeof(value), req); 73 if (error == 0 && req->newptr != NULL) { 74 if (value > 0) 75 bluetooth_hci_command_timeout_value = value; 76 else 77 error = EINVAL; 78 } 79 80 return (error); 81 } /* bluetooth_set_hci_command_timeout_value */ 82 83 SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, command_timeout, 84 CTLTYPE_INT | CTLFLAG_RW, 85 &bluetooth_hci_command_timeout_value, 5, 86 bluetooth_set_hci_command_timeout_value, 87 "I", "HCI command timeout (sec)"); 88 89 static int 90 bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS) 91 { 92 u_int32_t value; 93 int error; 94 95 value = bluetooth_hci_connect_timeout_value; 96 error = sysctl_handle_int(oidp, &value, sizeof(value), req); 97 if (error == 0 && req->newptr != NULL) { 98 if (0 < value && value <= bluetooth_l2cap_rtx_timeout_value) 99 bluetooth_hci_connect_timeout_value = value; 100 else 101 error = EINVAL; 102 } 103 104 return (error); 105 } /* bluetooth_set_hci_connect_timeout_value */ 106 107 SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, connection_timeout, 108 CTLTYPE_INT | CTLFLAG_RW, 109 &bluetooth_hci_connect_timeout_value, 60, 110 bluetooth_set_hci_connect_timeout_value, 111 "I", "HCI connect timeout (sec)"); 112 113 SYSCTL_INT(_net_bluetooth_hci, OID_AUTO, max_neighbor_age, CTLFLAG_RW, 114 &bluetooth_hci_max_neighbor_age_value, 600, 115 "Maximal HCI neighbor cache entry age (sec)"); 116 117 /* 118 * L2CAP 119 */ 120 121 SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW, 122 0, "Bluetooth L2CAP family"); 123 124 static int 125 bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS) 126 { 127 u_int32_t value; 128 int error; 129 130 value = bluetooth_l2cap_rtx_timeout_value; 131 error = sysctl_handle_int(oidp, &value, sizeof(value), req); 132 if (error == 0 && req->newptr != NULL) { 133 if (bluetooth_hci_connect_timeout_value <= value && 134 value <= bluetooth_l2cap_ertx_timeout_value) 135 bluetooth_l2cap_rtx_timeout_value = value; 136 else 137 error = EINVAL; 138 } 139 140 return (error); 141 } /* bluetooth_set_l2cap_rtx_timeout_value */ 142 143 SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, rtx_timeout, 144 CTLTYPE_INT | CTLFLAG_RW, 145 &bluetooth_l2cap_rtx_timeout_value, 60, 146 bluetooth_set_l2cap_rtx_timeout_value, 147 "I", "L2CAP RTX timeout (sec)"); 148 149 static int 150 bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS) 151 { 152 u_int32_t value; 153 int error; 154 155 value = bluetooth_l2cap_ertx_timeout_value; 156 error = sysctl_handle_int(oidp, &value, sizeof(value), req); 157 if (error == 0 && req->newptr != NULL) { 158 if (value >= bluetooth_l2cap_rtx_timeout_value) 159 bluetooth_l2cap_ertx_timeout_value = value; 160 else 161 error = EINVAL; 162 } 163 164 return (error); 165 } /* bluetooth_set_l2cap_ertx_timeout_value */ 166 167 SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, ertx_timeout, 168 CTLTYPE_INT | CTLFLAG_RW, 169 &bluetooth_l2cap_ertx_timeout_value, 300, 170 bluetooth_set_l2cap_ertx_timeout_value, 171 "I", "L2CAP ERTX timeout (sec)"); 172 173 /* 174 * Return various sysctl values 175 */ 176 177 u_int32_t 178 bluetooth_hci_command_timeout(void) 179 { 180 return (bluetooth_hci_command_timeout_value * hz); 181 } /* bluetooth_hci_command_timeout */ 182 183 u_int32_t 184 bluetooth_hci_connect_timeout(void) 185 { 186 return (bluetooth_hci_connect_timeout_value * hz); 187 } /* bluetooth_hci_connect_timeout */ 188 189 u_int32_t 190 bluetooth_hci_max_neighbor_age(void) 191 { 192 return (bluetooth_hci_max_neighbor_age_value); 193 } /* bluetooth_hci_max_neighbor_age */ 194 195 u_int32_t 196 bluetooth_l2cap_rtx_timeout(void) 197 { 198 return (bluetooth_l2cap_rtx_timeout_value * hz); 199 } /* bluetooth_l2cap_rtx_timeout */ 200 201 u_int32_t 202 bluetooth_l2cap_ertx_timeout(void) 203 { 204 return (bluetooth_l2cap_ertx_timeout_value * hz); 205 } /* bluetooth_l2cap_ertx_timeout */ 206 207 /* 208 * RFCOMM 209 */ 210 211 SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW, 212 0, "Bluetooth RFCOMM family"); 213 214 /* 215 * Handle loading and unloading for this code. 216 */ 217 218 static int 219 bluetooth_modevent(module_t mod, int event, void *data) 220 { 221 int error = 0; 222 223 switch (event) { 224 case MOD_LOAD: 225 break; 226 227 case MOD_UNLOAD: 228 break; 229 230 default: 231 error = EOPNOTSUPP; 232 break; 233 } 234 235 return (error); 236 } /* bluetooth_modevent */ 237 238 /* 239 * Module 240 */ 241 242 static moduledata_t bluetooth_mod = { 243 "bluetooth", 244 bluetooth_modevent, 245 NULL 246 }; 247 248 DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 249 MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION); 250 251