Path: blob/main/sys/netgraph/bluetooth/common/ng_bluetooth.c
34677 views
/*1* bluetooth.c2*/34/*-5* SPDX-License-Identifier: BSD-2-Clause6*7* Copyright (c) 2001-2002 Maksim Yevmenkin <[email protected]>8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*31* $Id: ng_bluetooth.c,v 1.3 2003/04/26 22:37:31 max Exp $32*/3334#include <sys/param.h>35#include <sys/systm.h>36#include <sys/errno.h>37#include <sys/kernel.h>38#include <sys/module.h>39#include <sys/sysctl.h>4041#include <netgraph/bluetooth/include/ng_bluetooth.h>4243/*44* Bluetooth stack sysctl globals45*/4647static u_int32_t bluetooth_hci_command_timeout_value = 5; /* sec */48static u_int32_t bluetooth_hci_connect_timeout_value = 60; /* sec */49static u_int32_t bluetooth_hci_max_neighbor_age_value = 600; /* sec */50static u_int32_t bluetooth_l2cap_rtx_timeout_value = 60; /* sec */51static u_int32_t bluetooth_l2cap_ertx_timeout_value = 300; /* sec */52static u_int32_t bluetooth_sco_rtx_timeout_value = 60; /* sec */5354/*55* Define sysctl tree that shared by other parts of Bluetooth stack56*/5758SYSCTL_NODE(_net, OID_AUTO, bluetooth, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,59"Bluetooth family");60SYSCTL_INT(_net_bluetooth, OID_AUTO, version,61CTLFLAG_RD, SYSCTL_NULL_INT_PTR, NG_BLUETOOTH_VERSION, "Version of the stack");6263/*64* HCI65*/6667SYSCTL_NODE(_net_bluetooth, OID_AUTO, hci, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,68"Bluetooth HCI family");6970static int71bluetooth_set_hci_command_timeout_value(SYSCTL_HANDLER_ARGS)72{73u_int32_t value;74int error;7576value = bluetooth_hci_command_timeout_value;77error = sysctl_handle_int(oidp, &value, 0, req);78if (error == 0 && req->newptr != NULL) {79if (value > 0)80bluetooth_hci_command_timeout_value = value;81else82error = EINVAL;83}8485return (error);86} /* bluetooth_set_hci_command_timeout_value */8788SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, command_timeout,89CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,90&bluetooth_hci_command_timeout_value, 5,91bluetooth_set_hci_command_timeout_value,92"I", "HCI command timeout (sec)");9394static int95bluetooth_set_hci_connect_timeout_value(SYSCTL_HANDLER_ARGS)96{97u_int32_t value;98int error;99100value = bluetooth_hci_connect_timeout_value;101error = sysctl_handle_int(oidp, &value, 0, req);102if (error == 0 && req->newptr != NULL) {103if (0 < value && value <= bluetooth_l2cap_rtx_timeout_value)104bluetooth_hci_connect_timeout_value = value;105else106error = EINVAL;107}108109return (error);110} /* bluetooth_set_hci_connect_timeout_value */111112SYSCTL_PROC(_net_bluetooth_hci, OID_AUTO, connection_timeout,113CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,114&bluetooth_hci_connect_timeout_value, 60,115bluetooth_set_hci_connect_timeout_value,116"I", "HCI connect timeout (sec)");117118SYSCTL_UINT(_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)");121122/*123* L2CAP124*/125126SYSCTL_NODE(_net_bluetooth, OID_AUTO, l2cap, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,127"Bluetooth L2CAP family");128129static int130bluetooth_set_l2cap_rtx_timeout_value(SYSCTL_HANDLER_ARGS)131{132u_int32_t value;133int error;134135value = bluetooth_l2cap_rtx_timeout_value;136error = sysctl_handle_int(oidp, &value, 0, req);137if (error == 0 && req->newptr != NULL) {138if (bluetooth_hci_connect_timeout_value <= value &&139value <= bluetooth_l2cap_ertx_timeout_value)140bluetooth_l2cap_rtx_timeout_value = value;141else142error = EINVAL;143}144145return (error);146} /* bluetooth_set_l2cap_rtx_timeout_value */147148SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, rtx_timeout,149CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,150&bluetooth_l2cap_rtx_timeout_value, 60,151bluetooth_set_l2cap_rtx_timeout_value,152"I", "L2CAP RTX timeout (sec)");153154static int155bluetooth_set_l2cap_ertx_timeout_value(SYSCTL_HANDLER_ARGS)156{157u_int32_t value;158int error;159160value = bluetooth_l2cap_ertx_timeout_value;161error = sysctl_handle_int(oidp, &value, 0, req);162if (error == 0 && req->newptr != NULL) {163if (value >= bluetooth_l2cap_rtx_timeout_value)164bluetooth_l2cap_ertx_timeout_value = value;165else166error = EINVAL;167}168169return (error);170} /* bluetooth_set_l2cap_ertx_timeout_value */171172SYSCTL_PROC(_net_bluetooth_l2cap, OID_AUTO, ertx_timeout,173CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,174&bluetooth_l2cap_ertx_timeout_value, 300,175bluetooth_set_l2cap_ertx_timeout_value,176"I", "L2CAP ERTX timeout (sec)");177178/*179* Return various sysctl values180*/181182u_int32_t183bluetooth_hci_command_timeout(void)184{185return (bluetooth_hci_command_timeout_value * hz);186} /* bluetooth_hci_command_timeout */187188u_int32_t189bluetooth_hci_connect_timeout(void)190{191return (bluetooth_hci_connect_timeout_value * hz);192} /* bluetooth_hci_connect_timeout */193194u_int32_t195bluetooth_hci_max_neighbor_age(void)196{197return (bluetooth_hci_max_neighbor_age_value);198} /* bluetooth_hci_max_neighbor_age */199200u_int32_t201bluetooth_l2cap_rtx_timeout(void)202{203return (bluetooth_l2cap_rtx_timeout_value * hz);204} /* bluetooth_l2cap_rtx_timeout */205206u_int32_t207bluetooth_l2cap_ertx_timeout(void)208{209return (bluetooth_l2cap_ertx_timeout_value * hz);210} /* bluetooth_l2cap_ertx_timeout */211212u_int32_t213bluetooth_sco_rtx_timeout(void)214{215return (bluetooth_sco_rtx_timeout_value * hz);216} /* bluetooth_sco_rtx_timeout */217218/*219* RFCOMM220*/221222SYSCTL_NODE(_net_bluetooth, OID_AUTO, rfcomm, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,223"Bluetooth RFCOMM family");224225/*226* SCO227*/228229SYSCTL_NODE(_net_bluetooth, OID_AUTO, sco, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,230"Bluetooth SCO family");231232static int233bluetooth_set_sco_rtx_timeout_value(SYSCTL_HANDLER_ARGS)234{235u_int32_t value;236int error;237238value = bluetooth_sco_rtx_timeout_value;239error = sysctl_handle_int(oidp, &value, 0, req);240if (error == 0 && req->newptr != NULL) {241if (bluetooth_hci_connect_timeout_value <= value)242bluetooth_sco_rtx_timeout_value = value;243else244error = EINVAL;245}246247return (error);248} /* bluetooth_set_sco_rtx_timeout_value */249250SYSCTL_PROC(_net_bluetooth_sco, OID_AUTO, rtx_timeout,251CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,252&bluetooth_sco_rtx_timeout_value, 60,253bluetooth_set_sco_rtx_timeout_value,254"I", "SCO RTX timeout (sec)");255256/*257* Handle loading and unloading for this code.258*/259260static int261bluetooth_modevent(module_t mod, int event, void *data)262{263int error = 0;264265switch (event) {266case MOD_LOAD:267break;268269case MOD_UNLOAD:270break;271272default:273error = EOPNOTSUPP;274break;275}276277return (error);278} /* bluetooth_modevent */279280/*281* Module282*/283284static moduledata_t bluetooth_mod = {285"ng_bluetooth",286bluetooth_modevent,287NULL288};289290DECLARE_MODULE(ng_bluetooth, bluetooth_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);291MODULE_VERSION(ng_bluetooth, NG_BLUETOOTH_VERSION);292293294