6 * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $Id: ng_btsocket.c,v 1.4 2003/09/14 23:29:06 max Exp $
34 #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>
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>
49 #include <netgraph/ng_message.h>
50 #include <netgraph/netgraph.h>
51 #include <netgraph/bluetooth/include/ng_bluetooth.h>
52 #include <netgraph/bluetooth/include/ng_hci.h>
53 #include <netgraph/bluetooth/include/ng_l2cap.h>
54 #include <netgraph/bluetooth/include/ng_btsocket.h>
55 #include <netgraph/bluetooth/include/ng_btsocket_hci_raw.h>
56 #include <netgraph/bluetooth/include/ng_btsocket_l2cap.h>
57 #include <netgraph/bluetooth/include/ng_btsocket_rfcomm.h>
58 #include <netgraph/bluetooth/include/ng_btsocket_sco.h>
60 static int ng_btsocket_modevent (module_t, int, void *);
61 static struct domain ng_btsocket_domain;
64 * Bluetooth raw HCI sockets
67 static struct pr_usrreqs ng_btsocket_hci_raw_usrreqs = {
68 .pru_abort = ng_btsocket_hci_raw_abort,
69 .pru_attach = ng_btsocket_hci_raw_attach,
70 .pru_bind = ng_btsocket_hci_raw_bind,
71 .pru_connect = ng_btsocket_hci_raw_connect,
72 .pru_control = ng_btsocket_hci_raw_control,
73 .pru_detach = ng_btsocket_hci_raw_detach,
74 .pru_disconnect = ng_btsocket_hci_raw_disconnect,
75 .pru_peeraddr = ng_btsocket_hci_raw_peeraddr,
76 .pru_send = ng_btsocket_hci_raw_send,
78 .pru_sockaddr = ng_btsocket_hci_raw_sockaddr,
79 .pru_close = ng_btsocket_hci_raw_close,
83 * Bluetooth raw L2CAP sockets
86 static struct pr_usrreqs ng_btsocket_l2cap_raw_usrreqs = {
87 .pru_abort = ng_btsocket_l2cap_raw_abort,
88 .pru_attach = ng_btsocket_l2cap_raw_attach,
89 .pru_bind = ng_btsocket_l2cap_raw_bind,
90 .pru_connect = ng_btsocket_l2cap_raw_connect,
91 .pru_control = ng_btsocket_l2cap_raw_control,
92 .pru_detach = ng_btsocket_l2cap_raw_detach,
93 .pru_disconnect = ng_btsocket_l2cap_raw_disconnect,
94 .pru_peeraddr = ng_btsocket_l2cap_raw_peeraddr,
95 .pru_send = ng_btsocket_l2cap_raw_send,
97 .pru_sockaddr = ng_btsocket_l2cap_raw_sockaddr,
98 .pru_close = ng_btsocket_l2cap_raw_close,
102 * Bluetooth SEQPACKET L2CAP sockets
105 static struct pr_usrreqs ng_btsocket_l2cap_usrreqs = {
106 .pru_abort = ng_btsocket_l2cap_abort,
107 .pru_accept = ng_btsocket_l2cap_accept,
108 .pru_attach = ng_btsocket_l2cap_attach,
109 .pru_bind = ng_btsocket_l2cap_bind,
110 .pru_connect = ng_btsocket_l2cap_connect,
111 .pru_control = ng_btsocket_l2cap_control,
112 .pru_detach = ng_btsocket_l2cap_detach,
113 .pru_disconnect = ng_btsocket_l2cap_disconnect,
114 .pru_listen = ng_btsocket_l2cap_listen,
115 .pru_peeraddr = ng_btsocket_l2cap_peeraddr,
116 .pru_send = ng_btsocket_l2cap_send,
117 .pru_shutdown = NULL,
118 .pru_sockaddr = ng_btsocket_l2cap_sockaddr,
119 .pru_close = ng_btsocket_l2cap_close,
123 * Bluetooth STREAM RFCOMM sockets
126 static struct pr_usrreqs ng_btsocket_rfcomm_usrreqs = {
127 .pru_abort = ng_btsocket_rfcomm_abort,
128 .pru_accept = ng_btsocket_rfcomm_accept,
129 .pru_attach = ng_btsocket_rfcomm_attach,
130 .pru_bind = ng_btsocket_rfcomm_bind,
131 .pru_connect = ng_btsocket_rfcomm_connect,
132 .pru_control = ng_btsocket_rfcomm_control,
133 .pru_detach = ng_btsocket_rfcomm_detach,
134 .pru_disconnect = ng_btsocket_rfcomm_disconnect,
135 .pru_listen = ng_btsocket_rfcomm_listen,
136 .pru_peeraddr = ng_btsocket_rfcomm_peeraddr,
137 .pru_send = ng_btsocket_rfcomm_send,
138 .pru_shutdown = NULL,
139 .pru_sockaddr = ng_btsocket_rfcomm_sockaddr,
140 .pru_close = ng_btsocket_rfcomm_close,
144 * Bluetooth SEQPACKET SCO sockets
147 static struct pr_usrreqs ng_btsocket_sco_usrreqs = {
148 .pru_abort = ng_btsocket_sco_abort,
149 .pru_accept = ng_btsocket_sco_accept,
150 .pru_attach = ng_btsocket_sco_attach,
151 .pru_bind = ng_btsocket_sco_bind,
152 .pru_connect = ng_btsocket_sco_connect,
153 .pru_control = ng_btsocket_sco_control,
154 .pru_detach = ng_btsocket_sco_detach,
155 .pru_disconnect = ng_btsocket_sco_disconnect,
156 .pru_listen = ng_btsocket_sco_listen,
157 .pru_peeraddr = ng_btsocket_sco_peeraddr,
158 .pru_send = ng_btsocket_sco_send,
159 .pru_shutdown = NULL,
160 .pru_sockaddr = ng_btsocket_sco_sockaddr,
161 .pru_close = ng_btsocket_sco_close,
165 * Definitions of protocols supported in the BLUETOOTH domain
168 static struct protosw ng_btsocket_protosw[] = {
171 .pr_domain = &ng_btsocket_domain,
172 .pr_protocol = BLUETOOTH_PROTO_HCI,
173 .pr_flags = PR_ATOMIC|PR_ADDR,
174 .pr_ctloutput = ng_btsocket_hci_raw_ctloutput,
175 .pr_init = ng_btsocket_hci_raw_init,
176 .pr_usrreqs = &ng_btsocket_hci_raw_usrreqs,
180 .pr_domain = &ng_btsocket_domain,
181 .pr_protocol = BLUETOOTH_PROTO_L2CAP,
182 .pr_flags = PR_ATOMIC|PR_ADDR,
183 .pr_init = ng_btsocket_l2cap_raw_init,
184 .pr_usrreqs = &ng_btsocket_l2cap_raw_usrreqs,
187 .pr_type = SOCK_SEQPACKET,
188 .pr_domain = &ng_btsocket_domain,
189 .pr_protocol = BLUETOOTH_PROTO_L2CAP,
190 .pr_flags = PR_ATOMIC|PR_CONNREQUIRED,
191 .pr_ctloutput = ng_btsocket_l2cap_ctloutput,
192 .pr_init = ng_btsocket_l2cap_init,
193 .pr_usrreqs = &ng_btsocket_l2cap_usrreqs,
196 .pr_type = SOCK_STREAM,
197 .pr_domain = &ng_btsocket_domain,
198 .pr_protocol = BLUETOOTH_PROTO_RFCOMM,
199 .pr_flags = PR_CONNREQUIRED,
200 .pr_ctloutput = ng_btsocket_rfcomm_ctloutput,
201 .pr_init = ng_btsocket_rfcomm_init,
202 .pr_usrreqs = &ng_btsocket_rfcomm_usrreqs,
205 .pr_type = SOCK_SEQPACKET,
206 .pr_domain = &ng_btsocket_domain,
207 .pr_protocol = BLUETOOTH_PROTO_SCO,
208 .pr_flags = PR_ATOMIC|PR_CONNREQUIRED,
209 .pr_ctloutput = ng_btsocket_sco_ctloutput,
210 .pr_init = ng_btsocket_sco_init,
211 .pr_usrreqs = &ng_btsocket_sco_usrreqs,
214 #define ng_btsocket_protosw_size \
215 (sizeof(ng_btsocket_protosw)/sizeof(ng_btsocket_protosw[0]))
216 #define ng_btsocket_protosw_end \
217 &ng_btsocket_protosw[ng_btsocket_protosw_size]
223 static struct domain ng_btsocket_domain = {
224 .dom_family = AF_BLUETOOTH,
225 .dom_name = "bluetooth",
226 .dom_protosw = ng_btsocket_protosw,
227 .dom_protoswNPROTOSW = ng_btsocket_protosw_end
234 SYSCTL_NODE(_net_bluetooth_hci, OID_AUTO, sockets, CTLFLAG_RW,
235 0, "Bluetooth HCI sockets family");
236 SYSCTL_NODE(_net_bluetooth_l2cap, OID_AUTO, sockets, CTLFLAG_RW,
237 0, "Bluetooth L2CAP sockets family");
238 SYSCTL_NODE(_net_bluetooth_rfcomm, OID_AUTO, sockets, CTLFLAG_RW,
239 0, "Bluetooth RFCOMM sockets family");
240 SYSCTL_NODE(_net_bluetooth_sco, OID_AUTO, sockets, CTLFLAG_RW,
241 0, "Bluetooth SCO sockets family");
247 static moduledata_t ng_btsocket_mod = {
249 ng_btsocket_modevent,
253 DECLARE_MODULE(ng_btsocket, ng_btsocket_mod, SI_SUB_PROTO_DOMAIN,
255 MODULE_VERSION(ng_btsocket, NG_BLUETOOTH_VERSION);
256 MODULE_DEPEND(ng_btsocket, ng_bluetooth, NG_BLUETOOTH_VERSION,
257 NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION);
258 MODULE_DEPEND(ng_btsocket, netgraph, NG_ABI_VERSION,
259 NG_ABI_VERSION, NG_ABI_VERSION);
262 * Handle loading and unloading for this node type.
263 * This is to handle auxiliary linkages (e.g protocol domain addition).
267 ng_btsocket_modevent(module_t mod, int event, void *data)
276 /* XXX can't unload protocol domain yet */
286 } /* ng_btsocket_modevent */
288 DOMAIN_SET(ng_btsocket_);