#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/sysctl.h>
#include <netgraph/bluetooth/include/ng_bluetooth.h>
static u_int32_t bluetooth_hci_command_timeout_value = 5;
static u_int32_t bluetooth_hci_connect_timeout_value = 60;
static u_int32_t bluetooth_hci_max_neighbor_age_value = 600;
static u_int32_t bluetooth_l2cap_rtx_timeout_value = 60;
static u_int32_t bluetooth_l2cap_ertx_timeout_value = 300;
static u_int32_t bluetooth_sco_rtx_timeout_value = 60;
SYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"Bluetooth family");
SYSCTL_INT(_net_bluetooth, OID_AUTO, version,
CTLFLAG_RD, SYSCTL_NULL_INT_PTR, NG_BLUETOOTH_VERSION, "Version of the stack");
SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"Bluetooth HCI family");
static int
bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS)
{
u_int32_t value;
int error;
value = bluetooth_hci_command_timeout_value;
error = sysctl_handle_int(oidp, &value, 0, req);
if (error == 0 && req->newptr != NULL) {
if (value > 0)
bluetooth_hci_command_timeout_value = value;
else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, command_timeout,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
&bluetooth_hci_command_timeout_value, 5,
bluetooth_set_hci_command_timeout_value,
"I", "HCI command timeout (sec)");
static int
bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS)
{
u_int32_t value;
int error;
value = bluetooth_hci_connect_timeout_value;
error = sysctl_handle_int(oidp, &value, 0, req);
if (error == 0 && req->newptr != NULL) {
if (0 < value && value <= bluetooth_l2cap_rtx_timeout_value)
bluetooth_hci_connect_timeout_value = value;
else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, connection_timeout,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
&bluetooth_hci_connect_timeout_value, 60,
bluetooth_set_hci_connect_timeout_value,
"I", "HCI connect timeout (sec)");
SYSCTL_UINT(_net_bluetooth_hci, OID_AUTO, max_neighbor_age, CTLFLAG_RW,
&bluetooth_hci_max_neighbor_age_value, 600,
"Maximal HCI neighbor cache entry age (sec)");
SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"Bluetooth L2CAP family");
static int
bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
{
u_int32_t value;
int error;
value = bluetooth_l2cap_rtx_timeout_value;
error = sysctl_handle_int(oidp, &value, 0, req);
if (error == 0 && req->newptr != NULL) {
if (bluetooth_hci_connect_timeout_value <= value &&
value <= bluetooth_l2cap_ertx_timeout_value)
bluetooth_l2cap_rtx_timeout_value = value;
else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, rtx_timeout,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
&bluetooth_l2cap_rtx_timeout_value, 60,
bluetooth_set_l2cap_rtx_timeout_value,
"I", "L2CAP RTX timeout (sec)");
static int
bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS)
{
u_int32_t value;
int error;
value = bluetooth_l2cap_ertx_timeout_value;
error = sysctl_handle_int(oidp, &value, 0, req);
if (error == 0 && req->newptr != NULL) {
if (value >= bluetooth_l2cap_rtx_timeout_value)
bluetooth_l2cap_ertx_timeout_value = value;
else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, ertx_timeout,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
&bluetooth_l2cap_ertx_timeout_value, 300,
bluetooth_set_l2cap_ertx_timeout_value,
"I", "L2CAP ERTX timeout (sec)");
u_int32_t
bluetooth_hci_command_timeout(void)
{
return (bluetooth_hci_command_timeout_value * hz);
}
u_int32_t
bluetooth_hci_connect_timeout(void)
{
return (bluetooth_hci_connect_timeout_value * hz);
}
u_int32_t
bluetooth_hci_max_neighbor_age(void)
{
return (bluetooth_hci_max_neighbor_age_value);
}
u_int32_t
bluetooth_l2cap_rtx_timeout(void)
{
return (bluetooth_l2cap_rtx_timeout_value * hz);
}
u_int32_t
bluetooth_l2cap_ertx_timeout(void)
{
return (bluetooth_l2cap_ertx_timeout_value * hz);
}
u_int32_t
bluetooth_sco_rtx_timeout(void)
{
return (bluetooth_sco_rtx_timeout_value * hz);
}
SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"Bluetooth RFCOMM family");
SYSCTL_NODE(_net_bluetooth, OID_AUTO, sco, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"Bluetooth SCO family");
static int
bluetooth_set_sco_rtx_timeout_value(SYSCTL_HANDLER_ARGS)
{
u_int32_t value;
int error;
value = bluetooth_sco_rtx_timeout_value;
error = sysctl_handle_int(oidp, &value, 0, req);
if (error == 0 && req->newptr != NULL) {
if (bluetooth_hci_connect_timeout_value <= value)
bluetooth_sco_rtx_timeout_value = value;
else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_net_bluetooth_sco, OID_AUTO, rtx_timeout,
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
&bluetooth_sco_rtx_timeout_value, 60,
bluetooth_set_sco_rtx_timeout_value,
"I", "SCO RTX timeout (sec)");
static int
bluetooth_modevent(module_t mod, int event, void *data)
{
int error = 0;
switch (event) {
case MOD_LOAD:
break;
case MOD_UNLOAD:
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
static moduledata_t bluetooth_mod = {
"ng_bluetooth",
bluetooth_modevent,
NULL
};
DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION);