Updated the list of USB device IDs for uvisor(4) and needed routines.
[dragonfly.git] / sys / netbt / bt_proto.c
blobb8c287d68cf365e038b35373df5c6fb1637721c3
1 /* $OpenBSD: bt_proto.c,v 1.4 2007/06/24 20:55:27 uwe Exp $ */
2 /* $DragonFly: src/sys/netbt/bt_proto.c,v 1.1 2007/12/30 20:02:56 hasso Exp $ */
4 /*
5 * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/param.h>
21 #include <sys/domain.h>
22 #include <sys/protosw.h>
23 #include <sys/socket.h>
24 #include <sys/socketvar.h>
25 #include <sys/queue.h>
26 #include <sys/kernel.h>
27 #include <sys/mbuf.h>
28 #include <sys/sysctl.h>
29 #include <sys/bus.h>
30 #include <sys/malloc.h>
31 #include <net/if.h>
32 #include <net/pf/pfvar.h>
34 #include <netbt/bluetooth.h>
35 #include <netbt/hci.h>
36 #include <netbt/l2cap.h>
37 #include <netbt/rfcomm.h>
38 #include <netbt/sco.h>
40 MALLOC_DEFINE(M_BLUETOOTH, "Bluetooth", "Bluetooth system memory");
42 extern struct pr_usrreqs hci_usrreqs;
44 static int
45 netbt_modevent(module_t mod, int type, void *data)
47 switch (type) {
48 case MOD_LOAD:
49 break;
50 case MOD_UNLOAD:
51 return EBUSY;
52 break;
53 default:
54 break;
56 return 0;
59 static moduledata_t netbt_mod = {
60 "netbt",
61 netbt_modevent,
62 NULL
65 DECLARE_MODULE(netbt, netbt_mod, SI_SUB_EXEC, SI_ORDER_ANY);
67 struct domain btdomain;
69 struct protosw btsw[] = {
70 { /* raw HCI commands */
71 .pr_type = SOCK_RAW,
72 .pr_domain = &btdomain,
73 .pr_protocol = BTPROTO_HCI,
74 .pr_flags = (PR_ADDR | PR_ATOMIC),
75 .pr_input = 0,
76 .pr_output = 0,
77 .pr_ctlinput = 0,
78 .pr_ctloutput = hci_ctloutput,
79 .pr_mport = cpu0_soport,
80 .pr_init = 0,
81 .pr_fasttimo = 0,
82 .pr_slowtimo = 0,
83 .pr_drain = 0,
84 .pr_usrreqs = &hci_usrreqs
86 { /* HCI SCO data (audio) */
87 .pr_type = SOCK_SEQPACKET,
88 .pr_domain = &btdomain,
89 .pr_protocol = BTPROTO_SCO,
90 .pr_flags = (PR_CONNREQUIRED | PR_ATOMIC ),
91 .pr_input = 0,
92 .pr_output = 0,
93 .pr_ctlinput = 0,
94 .pr_ctloutput = sco_ctloutput,
95 .pr_mport = cpu0_soport,
96 .pr_init = 0,
97 .pr_fasttimo = 0,
98 .pr_slowtimo = 0,
99 .pr_drain = 0,
100 .pr_usrreqs = &sco_usrreqs
103 { /* L2CAP Connection Oriented */
104 .pr_type = SOCK_SEQPACKET,
105 .pr_domain = &btdomain,
106 .pr_protocol = BTPROTO_L2CAP,
107 .pr_flags = (PR_CONNREQUIRED | PR_ATOMIC ),
108 .pr_input = 0,
109 .pr_output = 0,
110 .pr_ctlinput = 0,
111 .pr_ctloutput = l2cap_ctloutput,
112 .pr_mport = cpu0_soport,
113 .pr_init = 0,
114 .pr_fasttimo = 0,
115 .pr_slowtimo = 0,
116 .pr_drain = 0,
117 .pr_usrreqs = &l2cap_usrreqs
119 { /* RFCOMM */
120 .pr_type = SOCK_STREAM,
121 .pr_domain = &btdomain,
122 .pr_protocol = BTPROTO_RFCOMM,
123 .pr_flags = (PR_CONNREQUIRED | PR_WANTRCVD),
124 .pr_input = 0,
125 .pr_output = 0,
126 .pr_ctlinput = 0,
127 .pr_ctloutput = rfcomm_ctloutput,
128 .pr_mport = cpu0_soport,
129 .pr_init = 0,
130 .pr_fasttimo = 0,
131 .pr_slowtimo = 0,
132 .pr_drain = 0,
133 .pr_usrreqs = &rfcomm_usrreqs
137 static void
138 netbt_dispose(struct mbuf* m)
140 ZONE_DESTROY(l2cap_pdu_pool);
141 ZONE_DESTROY(l2cap_req_pool);
142 ZONE_DESTROY(rfcomm_credit_pool);
145 static void
146 netbt_init(void)
148 int error = 1;
149 do {
150 ZONE_CREATE(l2cap_pdu_pool, struct l2cap_pdu, "l2cap_pdu");
151 ZONE_CREATE(l2cap_req_pool, struct l2cap_req, "l2cap_req");
152 ZONE_CREATE(rfcomm_credit_pool, struct rfcomm_credit,
153 "rfcomm_credit");
154 error = 0;
155 } while(0);
157 if (error) {
158 netbt_dispose(NULL);
159 panic("Can't create vm_zones");
163 struct domain btdomain = {
164 .dom_family = AF_BLUETOOTH,
165 .dom_name = "bluetooth",
166 .dom_init = netbt_init,
167 .dom_externalize = NULL,
168 .dom_dispose = netbt_dispose,
169 .dom_protosw = btsw,
170 .dom_protoswNPROTOSW = &btsw[sizeof(btsw)/sizeof(btsw[0])],
171 .dom_next = SLIST_ENTRY_INITIALIZER,
172 .dom_rtattach = 0,
173 .dom_rtoffset = 32,
174 .dom_maxrtkey = sizeof(struct sockaddr_bt),
175 .dom_ifattach = 0,
176 .dom_ifdetach = 0,
179 DOMAIN_SET(bt);
180 SYSCTL_NODE(_net, PF_BLUETOOTH, bt, CTLFLAG_RW, 0, "Bluetooth protocol");
181 SYSCTL_NODE(_net_bt, BTPROTO_HCI, hci_unit, CTLFLAG_RW, 0,
182 "Bluetooth HCI protocol");
184 static void
185 netisr_netbt_setup(void *dummy __unused)
187 netisr_register(NETISR_BLUETOOTH, cpu0_portfn, btintr);
190 SYSINIT(netbt_setup, SI_BOOT2_KLD, SI_ORDER_ANY, netisr_netbt_setup, NULL);