1 /* $DragonFly: src/sys/netbt/bt_proto.c,v 1.7 2008/11/01 04:22:15 sephe Exp $ */
2 /* $OpenBSD: bt_proto.c,v 1.4 2007/06/24 20:55:27 uwe Exp $ */
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>
28 #include <sys/sysctl.h>
30 #include <sys/malloc.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
;
45 netbt_modevent(module_t mod
, int type
, void *data
)
59 static moduledata_t netbt_mod
= {
65 DECLARE_MODULE(netbt
, netbt_mod
, SI_SUB_EXEC
, SI_ORDER_ANY
);
67 struct domain btdomain
;
69 struct protosw btsw
[] = {
70 { /* raw HCI commands */
72 .pr_domain
= &btdomain
,
73 .pr_protocol
= BTPROTO_HCI
,
74 .pr_flags
= (PR_ADDR
| PR_ATOMIC
),
78 .pr_ctloutput
= hci_ctloutput
,
79 .pr_mport
= cpu0_soport
,
85 .pr_usrreqs
= &hci_usrreqs
87 { /* HCI SCO data (audio) */
88 .pr_type
= SOCK_SEQPACKET
,
89 .pr_domain
= &btdomain
,
90 .pr_protocol
= BTPROTO_SCO
,
91 .pr_flags
= (PR_CONNREQUIRED
| PR_ATOMIC
),
95 .pr_ctloutput
= sco_ctloutput
,
96 .pr_mport
= cpu0_soport
,
102 .pr_usrreqs
= &sco_usrreqs
105 { /* L2CAP Connection Oriented */
106 .pr_type
= SOCK_SEQPACKET
,
107 .pr_domain
= &btdomain
,
108 .pr_protocol
= BTPROTO_L2CAP
,
109 .pr_flags
= (PR_CONNREQUIRED
| PR_ATOMIC
),
113 .pr_ctloutput
= l2cap_ctloutput
,
114 .pr_mport
= cpu0_soport
,
120 .pr_usrreqs
= &l2cap_usrreqs
123 .pr_type
= SOCK_STREAM
,
124 .pr_domain
= &btdomain
,
125 .pr_protocol
= BTPROTO_RFCOMM
,
126 .pr_flags
= (PR_CONNREQUIRED
| PR_WANTRCVD
),
130 .pr_ctloutput
= rfcomm_ctloutput
,
131 .pr_mport
= cpu0_soport
,
137 .pr_usrreqs
= &rfcomm_usrreqs
142 netbt_dispose(struct mbuf
* m
)
144 ZONE_DESTROY(l2cap_pdu_pool
);
145 ZONE_DESTROY(l2cap_req_pool
);
146 ZONE_DESTROY(rfcomm_credit_pool
);
154 ZONE_CREATE(l2cap_pdu_pool
, struct l2cap_pdu
, "l2cap_pdu");
155 ZONE_CREATE(l2cap_req_pool
, struct l2cap_req
, "l2cap_req");
156 ZONE_CREATE(rfcomm_credit_pool
, struct rfcomm_credit
,
163 panic("Can't create vm_zones");
167 struct domain btdomain
= {
168 .dom_family
= AF_BLUETOOTH
,
169 .dom_name
= "bluetooth",
170 .dom_init
= netbt_init
,
171 .dom_externalize
= NULL
,
172 .dom_dispose
= netbt_dispose
,
174 .dom_protoswNPROTOSW
= &btsw
[sizeof(btsw
)/sizeof(btsw
[0])],
175 .dom_next
= SLIST_ENTRY_INITIALIZER
,
178 .dom_maxrtkey
= sizeof(struct sockaddr_bt
),
184 SYSCTL_NODE(_net
, OID_AUTO
, bluetooth
, CTLFLAG_RD
, 0,
185 "Bluetooth Protocol Family");
188 SYSCTL_NODE(_net_bluetooth
, OID_AUTO
, hci
, CTLFLAG_RD
, 0,
189 "Host Controller Interface");
190 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, sendspace
, CTLFLAG_RW
, &hci_sendspace
,
191 0, "Socket Send Buffer Size");
192 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, recvspace
, CTLFLAG_RW
, &hci_recvspace
,
193 0, "Socket Receive Buffer Size");
194 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, acl_expiry
, CTLFLAG_RW
,
195 &hci_acl_expiry
, 0, "ACL Connection Expiry Time");
196 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, memo_expiry
, CTLFLAG_RW
,
197 &hci_memo_expiry
, 0, "Memo Expiry Time");
198 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, eventq_max
, CTLFLAG_RW
,
199 &hci_eventq_max
, 0, "Max Event queue length");
200 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, aclrxq_max
, CTLFLAG_RW
,
201 &hci_aclrxq_max
, 0, "Max ACL rx queue length");
202 SYSCTL_INT(_net_bluetooth_hci
, OID_AUTO
, scorxq_max
, CTLFLAG_RW
,
203 &hci_scorxq_max
, 0, "Max SCO rx queue length");
206 SYSCTL_NODE(_net_bluetooth
, OID_AUTO
, l2cap
, CTLFLAG_RD
, 0,
207 "Logical Link Control & Adaptation Protocol");
208 SYSCTL_INT(_net_bluetooth_l2cap
, OID_AUTO
, sendspace
, CTLFLAG_RW
,
209 &l2cap_sendspace
, 0, "Socket Send Buffer Size");
210 SYSCTL_INT(_net_bluetooth_l2cap
, OID_AUTO
, recvspace
, CTLFLAG_RW
,
211 &l2cap_recvspace
, 0, "Socket Receive Buffer Size");
212 SYSCTL_INT(_net_bluetooth_l2cap
, OID_AUTO
, rtx
, CTLFLAG_RW
,
213 &l2cap_response_timeout
, 0, "Response Timeout");
214 SYSCTL_INT(_net_bluetooth_l2cap
, OID_AUTO
, ertx
, CTLFLAG_RW
,
215 &l2cap_response_extended_timeout
, 0, "Extended Response Timeout");
218 SYSCTL_NODE(_net_bluetooth
, OID_AUTO
, rfcomm
, CTLFLAG_RD
, 0,
219 "Serial Cable Emulation");
220 SYSCTL_INT(_net_bluetooth_rfcomm
, OID_AUTO
, sendspace
, CTLFLAG_RW
,
221 &rfcomm_sendspace
, 0, "Socket Send Buffer Size");
222 SYSCTL_INT(_net_bluetooth_rfcomm
, OID_AUTO
, recvspace
, CTLFLAG_RW
,
223 &rfcomm_recvspace
, 0, "Socket Receive Buffer Size");
224 SYSCTL_INT(_net_bluetooth_rfcomm
, OID_AUTO
, mtu_default
, CTLFLAG_RW
,
225 &rfcomm_mtu_default
, 0, "Default MTU");
226 SYSCTL_INT(_net_bluetooth_rfcomm
, OID_AUTO
, ack_timeout
, CTLFLAG_RW
,
227 &rfcomm_ack_timeout
, 0, "Acknowledgement Timer");
228 SYSCTL_INT(_net_bluetooth_rfcomm
, OID_AUTO
, mcc_timeout
, CTLFLAG_RW
,
229 &rfcomm_mcc_timeout
, 0, "Response Timeout for Multiplexer Control Channel");
232 SYSCTL_NODE(_net_bluetooth
, OID_AUTO
, sco
, CTLFLAG_RD
, 0, "SCO data");
233 SYSCTL_INT(_net_bluetooth_sco
, OID_AUTO
, sendspace
, CTLFLAG_RW
, &sco_sendspace
,
234 0, "Socket Send Buffer Size");
235 SYSCTL_INT(_net_bluetooth_sco
, OID_AUTO
, recvspace
, CTLFLAG_RW
, &sco_recvspace
,
236 0, "Socket Receive Buffer Size");
239 netisr_netbt_setup(void *dummy __unused
)
241 netisr_register(NETISR_BLUETOOTH
, cpu0_portfn
, pktinfo_portfn_cpu0
,
242 btintr
, NETISR_FLAG_NOTMPSAFE
);
245 SYSINIT(netbt_setup
, SI_BOOT2_KLD
, SI_ORDER_ANY
, netisr_netbt_setup
, NULL
);