Path: blob/main/sys/netgraph/bluetooth/socket/ng_btsocket.c
34677 views
/*1* ng_btsocket.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_btsocket.c,v 1.4 2003/09/14 23:29:06 max Exp $32*/3334#include <sys/param.h>35#include <sys/systm.h>36#include <sys/bitstring.h>37#include <sys/errno.h>38#include <sys/domain.h>39#include <sys/kernel.h>40#include <sys/lock.h>41#include <sys/mbuf.h>42#include <sys/mutex.h>43#include <sys/protosw.h>44#include <sys/socket.h>45#include <sys/socketvar.h>46#include <sys/sysctl.h>47#include <sys/taskqueue.h>4849#include <net/vnet.h>5051#include <netgraph/ng_message.h>52#include <netgraph/netgraph.h>53#include <netgraph/bluetooth/include/ng_bluetooth.h>54#include <netgraph/bluetooth/include/ng_hci.h>55#include <netgraph/bluetooth/include/ng_l2cap.h>56#include <netgraph/bluetooth/include/ng_btsocket.h>57#include <netgraph/bluetooth/include/ng_btsocket_hci_raw.h>58#include <netgraph/bluetooth/include/ng_btsocket_l2cap.h>59#include <netgraph/bluetooth/include/ng_btsocket_rfcomm.h>60#include <netgraph/bluetooth/include/ng_btsocket_sco.h>6162static int ng_btsocket_modevent (module_t, int, void *);6364/*65* Definitions of protocols supported in the BLUETOOTH domain66*/6768/* Bluetooth raw HCI sockets */69static struct protosw ng_btsocket_hci_raw_protosw = {70.pr_type = SOCK_RAW,71.pr_protocol = BLUETOOTH_PROTO_HCI,72.pr_flags = PR_ATOMIC|PR_ADDR,73.pr_ctloutput = ng_btsocket_hci_raw_ctloutput,74.pr_abort = ng_btsocket_hci_raw_abort,75.pr_attach = ng_btsocket_hci_raw_attach,76.pr_bind = ng_btsocket_hci_raw_bind,77.pr_connect = ng_btsocket_hci_raw_connect,78.pr_control = ng_btsocket_hci_raw_control,79.pr_detach = ng_btsocket_hci_raw_detach,80.pr_disconnect = ng_btsocket_hci_raw_disconnect,81.pr_peeraddr = ng_btsocket_hci_raw_sockaddr,82.pr_send = ng_btsocket_hci_raw_send,83.pr_sockaddr = ng_btsocket_hci_raw_sockaddr,84.pr_close = ng_btsocket_hci_raw_close,85};8687/* Bluetooth raw L2CAP sockets */88static struct protosw ng_btsocket_l2cap_raw_protosw = {89.pr_type = SOCK_RAW,90.pr_protocol = BLUETOOTH_PROTO_L2CAP,91.pr_flags = PR_ATOMIC|PR_ADDR,92.pr_abort = ng_btsocket_l2cap_raw_abort,93.pr_attach = ng_btsocket_l2cap_raw_attach,94.pr_bind = ng_btsocket_l2cap_raw_bind,95.pr_connect = ng_btsocket_l2cap_raw_connect,96.pr_control = ng_btsocket_l2cap_raw_control,97.pr_detach = ng_btsocket_l2cap_raw_detach,98.pr_disconnect = ng_btsocket_l2cap_raw_disconnect,99.pr_peeraddr = ng_btsocket_l2cap_raw_peeraddr,100.pr_send = ng_btsocket_l2cap_raw_send,101.pr_sockaddr = ng_btsocket_l2cap_raw_sockaddr,102.pr_close = ng_btsocket_l2cap_raw_close,103};104105/* Bluetooth SEQPACKET L2CAP sockets */106static struct protosw ng_btsocket_l2cap_protosw = {107.pr_type = SOCK_SEQPACKET,108.pr_protocol = BLUETOOTH_PROTO_L2CAP,109.pr_flags = PR_ATOMIC|PR_CONNREQUIRED,110.pr_ctloutput = ng_btsocket_l2cap_ctloutput,111.pr_abort = ng_btsocket_l2cap_abort,112.pr_accept = ng_btsocket_l2cap_peeraddr,113.pr_attach = ng_btsocket_l2cap_attach,114.pr_bind = ng_btsocket_l2cap_bind,115.pr_connect = ng_btsocket_l2cap_connect,116.pr_control = ng_btsocket_l2cap_control,117.pr_detach = ng_btsocket_l2cap_detach,118.pr_disconnect = ng_btsocket_l2cap_disconnect,119.pr_listen = ng_btsocket_l2cap_listen,120.pr_peeraddr = ng_btsocket_l2cap_peeraddr,121.pr_send = ng_btsocket_l2cap_send,122.pr_sockaddr = ng_btsocket_l2cap_sockaddr,123.pr_close = ng_btsocket_l2cap_close,124};125126/* Bluetooth STREAM RFCOMM sockets */127static struct protosw ng_btsocket_rfcomm_protosw = {128.pr_type = SOCK_STREAM,129.pr_protocol = BLUETOOTH_PROTO_RFCOMM,130.pr_flags = PR_CONNREQUIRED,131.pr_ctloutput = ng_btsocket_rfcomm_ctloutput,132.pr_abort = ng_btsocket_rfcomm_abort,133.pr_accept = ng_btsocket_rfcomm_peeraddr,134.pr_attach = ng_btsocket_rfcomm_attach,135.pr_bind = ng_btsocket_rfcomm_bind,136.pr_connect = ng_btsocket_rfcomm_connect,137.pr_control = ng_btsocket_rfcomm_control,138.pr_detach = ng_btsocket_rfcomm_detach,139.pr_disconnect = ng_btsocket_rfcomm_disconnect,140.pr_listen = ng_btsocket_rfcomm_listen,141.pr_peeraddr = ng_btsocket_rfcomm_peeraddr,142.pr_send = ng_btsocket_rfcomm_send,143.pr_sockaddr = ng_btsocket_rfcomm_sockaddr,144.pr_close = ng_btsocket_rfcomm_close,145};146147/* Bluetooth SEQPACKET SCO sockets */148static struct protosw ng_btsocket_sco_protosw = {149.pr_type = SOCK_SEQPACKET,150.pr_protocol = BLUETOOTH_PROTO_SCO,151.pr_flags = PR_ATOMIC|PR_CONNREQUIRED,152.pr_ctloutput = ng_btsocket_sco_ctloutput,153.pr_abort = ng_btsocket_sco_abort,154.pr_accept = ng_btsocket_sco_peeraddr,155.pr_attach = ng_btsocket_sco_attach,156.pr_bind = ng_btsocket_sco_bind,157.pr_connect = ng_btsocket_sco_connect,158.pr_control = ng_btsocket_sco_control,159.pr_detach = ng_btsocket_sco_detach,160.pr_disconnect = ng_btsocket_sco_disconnect,161.pr_listen = ng_btsocket_sco_listen,162.pr_peeraddr = ng_btsocket_sco_peeraddr,163.pr_send = ng_btsocket_sco_send,164.pr_sockaddr = ng_btsocket_sco_sockaddr,165.pr_close = ng_btsocket_sco_close,166};167168/*169* BLUETOOTH domain170*/171172static struct domain ng_btsocket_domain = {173.dom_family = AF_BLUETOOTH,174.dom_name = "bluetooth",175.dom_nprotosw = 5,176.dom_protosw = {177&ng_btsocket_hci_raw_protosw,178&ng_btsocket_l2cap_raw_protosw,179&ng_btsocket_l2cap_protosw,180&ng_btsocket_rfcomm_protosw,181&ng_btsocket_sco_protosw,182},183};184185/*186* Socket sysctl tree187*/188189SYSCTL_NODE(_net_bluetooth_hci, OID_AUTO, sockets,190CTLFLAG_RW | CTLFLAG_MPSAFE, 0,191"Bluetooth HCI sockets family");192SYSCTL_NODE(_net_bluetooth_l2cap, OID_AUTO, sockets,193CTLFLAG_RW | CTLFLAG_MPSAFE, 0,194"Bluetooth L2CAP sockets family");195SYSCTL_NODE(_net_bluetooth_rfcomm, OID_AUTO, sockets,196CTLFLAG_RW | CTLFLAG_MPSAFE, 0,197"Bluetooth RFCOMM sockets family");198SYSCTL_NODE(_net_bluetooth_sco, OID_AUTO, sockets,199CTLFLAG_RW | CTLFLAG_MPSAFE, 0,200"Bluetooth SCO sockets family");201202/*203* Module204*/205206static moduledata_t ng_btsocket_mod = {207"ng_btsocket",208ng_btsocket_modevent,209NULL210};211212DECLARE_MODULE(ng_btsocket, ng_btsocket_mod, SI_SUB_PROTO_DOMAIN,213SI_ORDER_ANY);214MODULE_VERSION(ng_btsocket, NG_BLUETOOTH_VERSION);215MODULE_DEPEND(ng_btsocket, ng_bluetooth, NG_BLUETOOTH_VERSION,216NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION);217MODULE_DEPEND(ng_btsocket, netgraph, NG_ABI_VERSION,218NG_ABI_VERSION, NG_ABI_VERSION);219220/*221* Handle loading and unloading for this node type.222* This is to handle auxiliary linkages (e.g protocol domain addition).223*/224225static int226ng_btsocket_modevent(module_t mod, int event, void *data)227{228int error = 0;229230switch (event) {231case MOD_LOAD:232break;233234case MOD_UNLOAD:235/* XXX can't unload protocol domain yet */236error = EBUSY;237break;238239default:240error = EOPNOTSUPP;241break;242}243244return (error);245} /* ng_btsocket_modevent */246247DOMAIN_SET(ng_btsocket_);248249250