Home | History | Annotate | Line # | Download | only in netbt
bt_proto.c revision 1.17
      1  1.17  riastrad /*	$NetBSD: bt_proto.c,v 1.17 2023/08/07 13:31:54 riastradh Exp $	*/
      2   1.1   gdamore 
      3   1.1   gdamore /*-
      4   1.1   gdamore  * Copyright (c) 2005 Iain Hibbert.
      5   1.1   gdamore  * Copyright (c) 2006 Itronix Inc.
      6   1.1   gdamore  * All rights reserved.
      7   1.1   gdamore  *
      8   1.1   gdamore  * Redistribution and use in source and binary forms, with or without
      9   1.1   gdamore  * modification, are permitted provided that the following conditions
     10   1.1   gdamore  * are met:
     11   1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     12   1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     13   1.1   gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1   gdamore  *    notice, this list of conditions and the following disclaimer in the
     15   1.1   gdamore  *    documentation and/or other materials provided with the distribution.
     16   1.1   gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     17   1.1   gdamore  *    or promote products derived from this software without specific
     18   1.1   gdamore  *    prior written permission.
     19   1.1   gdamore  *
     20   1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     21   1.1   gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.1   gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.1   gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     24   1.1   gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25   1.1   gdamore  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26   1.1   gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27   1.1   gdamore  * ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.1   gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1   gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1   gdamore  * POSSIBILITY OF SUCH DAMAGE.
     31   1.1   gdamore  */
     32   1.1   gdamore 
     33   1.1   gdamore #include <sys/cdefs.h>
     34  1.17  riastrad __KERNEL_RCSID(0, "$NetBSD: bt_proto.c,v 1.17 2023/08/07 13:31:54 riastradh Exp $");
     35   1.1   gdamore 
     36   1.1   gdamore #include <sys/param.h>
     37   1.1   gdamore #include <sys/domain.h>
     38   1.1   gdamore #include <sys/kernel.h>
     39  1.17  riastrad #include <sys/module.h>
     40   1.1   gdamore #include <sys/protosw.h>
     41   1.1   gdamore #include <sys/socket.h>
     42   1.1   gdamore #include <sys/systm.h>
     43   1.1   gdamore 
     44   1.1   gdamore #include <net/route.h>
     45   1.1   gdamore 
     46   1.1   gdamore #include <netbt/bluetooth.h>
     47   1.1   gdamore #include <netbt/hci.h>
     48   1.1   gdamore #include <netbt/l2cap.h>
     49   1.1   gdamore #include <netbt/rfcomm.h>
     50   1.1   gdamore #include <netbt/sco.h>
     51   1.1   gdamore 
     52   1.1   gdamore DOMAIN_DEFINE(btdomain);	/* forward declare and add to link set */
     53   1.1   gdamore 
     54  1.10        ad static void	bt_init(void);
     55  1.10        ad 
     56  1.10        ad PR_WRAP_CTLOUTPUT(hci_ctloutput)
     57  1.10        ad PR_WRAP_CTLOUTPUT(sco_ctloutput)
     58  1.10        ad PR_WRAP_CTLOUTPUT(l2cap_ctloutput)
     59  1.10        ad PR_WRAP_CTLOUTPUT(rfcomm_ctloutput)
     60  1.10        ad 
     61  1.10        ad #define	hci_ctloutput		hci_ctloutput_wrapper
     62  1.10        ad #define	sco_ctloutput		sco_ctloutput_wrapper
     63  1.10        ad #define	l2cap_ctloutput		l2cap_ctloutput_wrapper
     64  1.10        ad #define	rfcomm_ctloutput	rfcomm_ctloutput_wrapper
     65  1.10        ad 
     66  1.16  riastrad static const struct protosw btsw[] = {
     67  1.16  riastrad 	{ /* raw HCI commands */
     68   1.7    plunky 		.pr_type = SOCK_RAW,
     69   1.7    plunky 		.pr_domain = &btdomain,
     70   1.7    plunky 		.pr_protocol = BTPROTO_HCI,
     71   1.7    plunky 		.pr_flags = (PR_ADDR | PR_ATOMIC),
     72  1.11    plunky 		.pr_init = hci_init,
     73   1.7    plunky 		.pr_ctloutput = hci_ctloutput,
     74  1.13     rmind 		.pr_usrreqs = &hci_usrreqs,
     75   1.7    plunky 	},
     76  1.16  riastrad 	{ /* HCI SCO data (audio) */
     77   1.7    plunky 		.pr_type = SOCK_SEQPACKET,
     78   1.7    plunky 		.pr_domain = &btdomain,
     79   1.7    plunky 		.pr_protocol = BTPROTO_SCO,
     80   1.7    plunky 		.pr_flags = (PR_CONNREQUIRED | PR_ATOMIC | PR_LISTEN),
     81   1.7    plunky 		.pr_ctloutput = sco_ctloutput,
     82  1.13     rmind 		.pr_usrreqs = &sco_usrreqs,
     83   1.7    plunky 	},
     84  1.16  riastrad 	{ /* L2CAP Connection Oriented */
     85   1.7    plunky 		.pr_type = SOCK_SEQPACKET,
     86   1.7    plunky 		.pr_domain = &btdomain,
     87   1.7    plunky 		.pr_protocol = BTPROTO_L2CAP,
     88   1.7    plunky 		.pr_flags = (PR_CONNREQUIRED | PR_ATOMIC | PR_LISTEN),
     89   1.7    plunky 		.pr_ctloutput = l2cap_ctloutput,
     90  1.13     rmind 		.pr_usrreqs = &l2cap_usrreqs,
     91  1.12     pooka 		.pr_init = l2cap_init,
     92   1.7    plunky 	},
     93  1.16  riastrad 	{ /* RFCOMM */
     94   1.7    plunky 		.pr_type = SOCK_STREAM,
     95   1.7    plunky 		.pr_domain = &btdomain,
     96   1.7    plunky 		.pr_protocol = BTPROTO_RFCOMM,
     97   1.7    plunky 		.pr_flags = (PR_CONNREQUIRED | PR_LISTEN | PR_WANTRCVD),
     98   1.7    plunky 		.pr_ctloutput = rfcomm_ctloutput,
     99  1.13     rmind 		.pr_usrreqs = &rfcomm_usrreqs,
    100  1.12     pooka 		.pr_init = rfcomm_init,
    101   1.7    plunky 	},
    102   1.1   gdamore };
    103   1.1   gdamore 
    104   1.1   gdamore struct domain btdomain = {
    105   1.6    dyoung 	.dom_family = AF_BLUETOOTH,
    106   1.6    dyoung 	.dom_name = "bluetooth",
    107  1.10        ad 	.dom_init = bt_init,
    108   1.6    dyoung 	.dom_protosw = btsw,
    109  1.16  riastrad 	.dom_protoswNPROTOSW = &btsw[__arraycount(btsw)],
    110   1.1   gdamore };
    111  1.10        ad 
    112  1.10        ad kmutex_t *bt_lock;
    113  1.10        ad 
    114  1.10        ad static void
    115  1.10        ad bt_init(void)
    116  1.10        ad {
    117  1.17  riastrad }
    118  1.17  riastrad 
    119  1.17  riastrad MODULE(MODULE_CLASS_DRIVER, netbt, NULL);
    120  1.17  riastrad 
    121  1.17  riastrad static int
    122  1.17  riastrad netbt_modcmd(modcmd_t cmd, void *aux)
    123  1.17  riastrad {
    124  1.10        ad 
    125  1.17  riastrad 	switch (cmd) {
    126  1.17  riastrad 	case MODULE_CMD_INIT:
    127  1.17  riastrad 		bt_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
    128  1.17  riastrad 		return 0;
    129  1.17  riastrad 	case MODULE_CMD_FINI:
    130  1.17  riastrad 		return EBUSY;	/* XXX */
    131  1.17  riastrad 	default:
    132  1.17  riastrad 		return ENOTTY;
    133  1.17  riastrad 	}
    134  1.10        ad }
    135