Home | History | Annotate | Line # | Download | only in netbt
bt_proto.c revision 1.10
      1  1.10       ad /*	$NetBSD: bt_proto.c,v 1.10 2008/04/24 11:38:37 ad 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.10       ad __KERNEL_RCSID(0, "$NetBSD: bt_proto.c,v 1.10 2008/04/24 11:38:37 ad 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.10       ad PR_WRAP_USRREQ(hci_usrreq)
     66  1.10       ad PR_WRAP_USRREQ(sco_usrreq)
     67  1.10       ad PR_WRAP_USRREQ(l2cap_usrreq)
     68  1.10       ad PR_WRAP_USRREQ(rfcomm_usrreq)
     69  1.10       ad 
     70  1.10       ad #define	hci_usrreq		hci_usrreq_wrapper
     71  1.10       ad #define	sco_usrreq		sco_usrreq_wrapper
     72  1.10       ad #define	l2cap_usrreq		l2cap_usrreq_wrapper
     73  1.10       ad #define	rfcomm_usrreq		rfcomm_usrreq_wrapper
     74  1.10       ad 
     75   1.1  gdamore const struct protosw btsw[] = {
     76   1.7   plunky 	{ /* raw HCI commands */
     77   1.7   plunky 		.pr_type = SOCK_RAW,
     78   1.7   plunky 		.pr_domain = &btdomain,
     79   1.7   plunky 		.pr_protocol = BTPROTO_HCI,
     80   1.7   plunky 		.pr_flags = (PR_ADDR | PR_ATOMIC),
     81   1.7   plunky 		.pr_ctloutput = hci_ctloutput,
     82   1.7   plunky 		.pr_usrreq = hci_usrreq,
     83   1.7   plunky 	},
     84   1.7   plunky 	{ /* HCI SCO data (audio) */
     85   1.7   plunky 		.pr_type = SOCK_SEQPACKET,
     86   1.7   plunky 		.pr_domain = &btdomain,
     87   1.7   plunky 		.pr_protocol = BTPROTO_SCO,
     88   1.7   plunky 		.pr_flags = (PR_CONNREQUIRED | PR_ATOMIC | PR_LISTEN),
     89   1.7   plunky 		.pr_ctloutput = sco_ctloutput,
     90   1.7   plunky 		.pr_usrreq = sco_usrreq,
     91   1.7   plunky 	},
     92   1.7   plunky 	{ /* L2CAP Connection Oriented */
     93   1.7   plunky 		.pr_type = SOCK_SEQPACKET,
     94   1.7   plunky 		.pr_domain = &btdomain,
     95   1.7   plunky 		.pr_protocol = BTPROTO_L2CAP,
     96   1.7   plunky 		.pr_flags = (PR_CONNREQUIRED | PR_ATOMIC | PR_LISTEN),
     97   1.7   plunky 		.pr_ctloutput = l2cap_ctloutput,
     98   1.7   plunky 		.pr_usrreq = l2cap_usrreq,
     99   1.7   plunky 	},
    100   1.7   plunky 	{ /* RFCOMM */
    101   1.7   plunky 		.pr_type = SOCK_STREAM,
    102   1.7   plunky 		.pr_domain = &btdomain,
    103   1.7   plunky 		.pr_protocol = BTPROTO_RFCOMM,
    104   1.7   plunky 		.pr_flags = (PR_CONNREQUIRED | PR_LISTEN | PR_WANTRCVD),
    105   1.7   plunky 		.pr_ctloutput = rfcomm_ctloutput,
    106   1.7   plunky 		.pr_usrreq = rfcomm_usrreq,
    107   1.7   plunky 	},
    108   1.1  gdamore };
    109   1.1  gdamore 
    110   1.1  gdamore struct domain btdomain = {
    111   1.6   dyoung 	.dom_family = AF_BLUETOOTH,
    112   1.6   dyoung 	.dom_name = "bluetooth",
    113  1.10       ad 	.dom_init = bt_init,
    114   1.6   dyoung 	.dom_protosw = btsw,
    115   1.9   plunky 	.dom_protoswNPROTOSW = &btsw[__arraycount(btsw)],
    116   1.1  gdamore };
    117  1.10       ad 
    118  1.10       ad kmutex_t *bt_lock;
    119  1.10       ad 
    120  1.10       ad static void
    121  1.10       ad bt_init(void)
    122  1.10       ad {
    123  1.10       ad 
    124  1.10       ad 	bt_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
    125  1.10       ad }
    126