Home | History | Annotate | Line # | Download | only in netbt
bt_proto.c revision 1.16
      1  1.15  riastrad /*	$NetBSD: bt_proto.c,v 1.16 2016/01/21 15:41:30 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.15  riastrad __KERNEL_RCSID(0, "$NetBSD: bt_proto.c,v 1.16 2016/01/21 15:41:30 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.1   gdamore #include <sys/protosw.h>
     40   1.1   gdamore #include <sys/socket.h>
     41   1.1   gdamore #include <sys/systm.h>
     42   1.1   gdamore 
     43   1.1   gdamore #include <net/route.h>
     44   1.1   gdamore 
     45   1.1   gdamore #include <netbt/bluetooth.h>
     46   1.1   gdamore #include <netbt/hci.h>
     47   1.1   gdamore #include <netbt/l2cap.h>
     48   1.1   gdamore #include <netbt/rfcomm.h>
     49   1.1   gdamore #include <netbt/sco.h>
     50   1.1   gdamore 
     51   1.1   gdamore DOMAIN_DEFINE(btdomain);	/* forward declare and add to link set */
     52   1.1   gdamore 
     53  1.10        ad static void	bt_init(void);
     54  1.10        ad 
     55  1.10        ad PR_WRAP_CTLOUTPUT(hci_ctloutput)
     56  1.10        ad PR_WRAP_CTLOUTPUT(sco_ctloutput)
     57  1.10        ad PR_WRAP_CTLOUTPUT(l2cap_ctloutput)
     58  1.10        ad PR_WRAP_CTLOUTPUT(rfcomm_ctloutput)
     59  1.10        ad 
     60  1.10        ad #define	hci_ctloutput		hci_ctloutput_wrapper
     61  1.10        ad #define	sco_ctloutput		sco_ctloutput_wrapper
     62  1.10        ad #define	l2cap_ctloutput		l2cap_ctloutput_wrapper
     63  1.10        ad #define	rfcomm_ctloutput	rfcomm_ctloutput_wrapper
     64  1.10        ad 
     65  1.16  riastrad static const struct protosw btsw[] = {
     66  1.16  riastrad 	{ /* raw HCI commands */
     67   1.7    plunky 		.pr_type = SOCK_RAW,
     68   1.7    plunky 		.pr_domain = &btdomain,
     69   1.7    plunky 		.pr_protocol = BTPROTO_HCI,
     70   1.7    plunky 		.pr_flags = (PR_ADDR | PR_ATOMIC),
     71  1.11    plunky 		.pr_init = hci_init,
     72   1.7    plunky 		.pr_ctloutput = hci_ctloutput,
     73  1.13     rmind 		.pr_usrreqs = &hci_usrreqs,
     74   1.7    plunky 	},
     75  1.16  riastrad 	{ /* HCI SCO data (audio) */
     76   1.7    plunky 		.pr_type = SOCK_SEQPACKET,
     77   1.7    plunky 		.pr_domain = &btdomain,
     78   1.7    plunky 		.pr_protocol = BTPROTO_SCO,
     79   1.7    plunky 		.pr_flags = (PR_CONNREQUIRED | PR_ATOMIC | PR_LISTEN),
     80   1.7    plunky 		.pr_ctloutput = sco_ctloutput,
     81  1.13     rmind 		.pr_usrreqs = &sco_usrreqs,
     82   1.7    plunky 	},
     83  1.16  riastrad 	{ /* L2CAP Connection Oriented */
     84   1.7    plunky 		.pr_type = SOCK_SEQPACKET,
     85   1.7    plunky 		.pr_domain = &btdomain,
     86   1.7    plunky 		.pr_protocol = BTPROTO_L2CAP,
     87   1.7    plunky 		.pr_flags = (PR_CONNREQUIRED | PR_ATOMIC | PR_LISTEN),
     88   1.7    plunky 		.pr_ctloutput = l2cap_ctloutput,
     89  1.13     rmind 		.pr_usrreqs = &l2cap_usrreqs,
     90  1.12     pooka 		.pr_init = l2cap_init,
     91   1.7    plunky 	},
     92  1.16  riastrad 	{ /* RFCOMM */
     93   1.7    plunky 		.pr_type = SOCK_STREAM,
     94   1.7    plunky 		.pr_domain = &btdomain,
     95   1.7    plunky 		.pr_protocol = BTPROTO_RFCOMM,
     96   1.7    plunky 		.pr_flags = (PR_CONNREQUIRED | PR_LISTEN | PR_WANTRCVD),
     97   1.7    plunky 		.pr_ctloutput = rfcomm_ctloutput,
     98  1.13     rmind 		.pr_usrreqs = &rfcomm_usrreqs,
     99  1.12     pooka 		.pr_init = rfcomm_init,
    100   1.7    plunky 	},
    101   1.1   gdamore };
    102   1.1   gdamore 
    103   1.1   gdamore struct domain btdomain = {
    104   1.6    dyoung 	.dom_family = AF_BLUETOOTH,
    105   1.6    dyoung 	.dom_name = "bluetooth",
    106  1.10        ad 	.dom_init = bt_init,
    107   1.6    dyoung 	.dom_protosw = btsw,
    108  1.16  riastrad 	.dom_protoswNPROTOSW = &btsw[__arraycount(btsw)],
    109   1.1   gdamore };
    110  1.10        ad 
    111  1.10        ad kmutex_t *bt_lock;
    112  1.10        ad 
    113  1.10        ad static void
    114  1.10        ad bt_init(void)
    115  1.10        ad {
    116  1.10        ad 
    117  1.10        ad 	bt_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
    118  1.10        ad }
    119