2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation;
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
25 /* Bluetooth SCO sockets. */
27 #include <linux/module.h>
29 #include <linux/types.h>
30 #include <linux/errno.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/slab.h>
34 #include <linux/poll.h>
35 #include <linux/fcntl.h>
36 #include <linux/init.h>
37 #include <linux/interrupt.h>
38 #include <linux/socket.h>
39 #include <linux/skbuff.h>
40 #include <linux/device.h>
41 #include <linux/debugfs.h>
42 #include <linux/seq_file.h>
43 #include <linux/list.h>
46 #include <asm/system.h>
47 #include <linux/uaccess.h>
49 #include <net/bluetooth/bluetooth.h>
50 #include <net/bluetooth/hci_core.h>
51 #include <net/bluetooth/sco.h>
55 static int disable_esco
;
57 static const struct proto_ops sco_sock_ops
;
59 static struct bt_sock_list sco_sk_list
= {
60 .lock
= __RW_LOCK_UNLOCKED(sco_sk_list
.lock
)
63 static void __sco_chan_add(struct sco_conn
*conn
, struct sock
*sk
, struct sock
*parent
);
64 static void sco_chan_del(struct sock
*sk
, int err
);
66 static int sco_conn_del(struct hci_conn
*conn
, int err
);
68 static void sco_sock_close(struct sock
*sk
);
69 static void sco_sock_kill(struct sock
*sk
);
71 /* ---- SCO timers ---- */
72 static void sco_sock_timeout(unsigned long arg
)
74 struct sock
*sk
= (struct sock
*) arg
;
76 BT_DBG("sock %p state %d", sk
, sk
->sk_state
);
79 sk
->sk_err
= ETIMEDOUT
;
80 sk
->sk_state_change(sk
);
87 static void sco_sock_set_timer(struct sock
*sk
, long timeout
)
89 BT_DBG("sock %p state %d timeout %ld", sk
, sk
->sk_state
, timeout
);
90 sk_reset_timer(sk
, &sk
->sk_timer
, jiffies
+ timeout
);
93 static void sco_sock_clear_timer(struct sock
*sk
)
95 BT_DBG("sock %p state %d", sk
, sk
->sk_state
);
96 sk_stop_timer(sk
, &sk
->sk_timer
);
99 /* ---- SCO connections ---- */
100 static struct sco_conn
*sco_conn_add(struct hci_conn
*hcon
, __u8 status
)
102 struct hci_dev
*hdev
= hcon
->hdev
;
103 struct sco_conn
*conn
= hcon
->sco_data
;
108 conn
= kzalloc(sizeof(struct sco_conn
), GFP_ATOMIC
);
112 spin_lock_init(&conn
->lock
);
114 hcon
->sco_data
= conn
;
117 conn
->src
= &hdev
->bdaddr
;
118 conn
->dst
= &hcon
->dst
;
120 if (hdev
->sco_mtu
> 0)
121 conn
->mtu
= hdev
->sco_mtu
;
125 BT_DBG("hcon %p conn %p", hcon
, conn
);
130 static inline struct sock
*sco_chan_get(struct sco_conn
*conn
)
132 struct sock
*sk
= NULL
;
135 sco_conn_unlock(conn
);
139 static int sco_conn_del(struct hci_conn
*hcon
, int err
)
141 struct sco_conn
*conn
= hcon
->sco_data
;
147 BT_DBG("hcon %p conn %p, err %d", hcon
, conn
, err
);
150 sk
= sco_chan_get(conn
);
153 sco_sock_clear_timer(sk
);
154 sco_chan_del(sk
, err
);
159 hcon
->sco_data
= NULL
;
164 static inline int sco_chan_add(struct sco_conn
*conn
, struct sock
*sk
, struct sock
*parent
)
172 __sco_chan_add(conn
, sk
, parent
);
174 sco_conn_unlock(conn
);
178 static int sco_connect(struct sock
*sk
)
180 bdaddr_t
*src
= &bt_sk(sk
)->src
;
181 bdaddr_t
*dst
= &bt_sk(sk
)->dst
;
182 struct sco_conn
*conn
;
183 struct hci_conn
*hcon
;
184 struct hci_dev
*hdev
;
187 BT_DBG("%s -> %s", batostr(src
), batostr(dst
));
189 hdev
= hci_get_route(dst
, src
);
191 return -EHOSTUNREACH
;
193 hci_dev_lock_bh(hdev
);
197 if (lmp_esco_capable(hdev
) && !disable_esco
)
202 hcon
= hci_connect(hdev
, type
, dst
, BT_SECURITY_LOW
, HCI_AT_NO_BONDING
);
206 conn
= sco_conn_add(hcon
, 0);
212 /* Update source addr of the socket */
213 bacpy(src
, conn
->src
);
215 err
= sco_chan_add(conn
, sk
, NULL
);
219 if (hcon
->state
== BT_CONNECTED
) {
220 sco_sock_clear_timer(sk
);
221 sk
->sk_state
= BT_CONNECTED
;
223 sk
->sk_state
= BT_CONNECT
;
224 sco_sock_set_timer(sk
, sk
->sk_sndtimeo
);
228 hci_dev_unlock_bh(hdev
);
233 static inline int sco_send_frame(struct sock
*sk
, struct msghdr
*msg
, int len
)
235 struct sco_conn
*conn
= sco_pi(sk
)->conn
;
239 /* Check outgoing MTU */
243 BT_DBG("sk %p len %d", sk
, len
);
245 count
= min_t(unsigned int, conn
->mtu
, len
);
246 skb
= bt_skb_send_alloc(sk
, count
,
247 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
251 if (memcpy_fromiovec(skb_put(skb
, count
), msg
->msg_iov
, count
)) {
256 hci_send_sco(conn
->hcon
, skb
);
261 static inline void sco_recv_frame(struct sco_conn
*conn
, struct sk_buff
*skb
)
263 struct sock
*sk
= sco_chan_get(conn
);
268 BT_DBG("sk %p len %d", sk
, skb
->len
);
270 if (sk
->sk_state
!= BT_CONNECTED
)
273 if (!sock_queue_rcv_skb(sk
, skb
))
280 /* -------- Socket interface ---------- */
281 static struct sock
*__sco_get_sock_by_addr(bdaddr_t
*ba
)
284 struct hlist_node
*node
;
286 sk_for_each(sk
, node
, &sco_sk_list
.head
)
287 if (!bacmp(&bt_sk(sk
)->src
, ba
))
294 /* Find socket listening on source bdaddr.
295 * Returns closest match.
297 static struct sock
*sco_get_sock_listen(bdaddr_t
*src
)
299 struct sock
*sk
= NULL
, *sk1
= NULL
;
300 struct hlist_node
*node
;
302 read_lock(&sco_sk_list
.lock
);
304 sk_for_each(sk
, node
, &sco_sk_list
.head
) {
305 if (sk
->sk_state
!= BT_LISTEN
)
309 if (!bacmp(&bt_sk(sk
)->src
, src
))
313 if (!bacmp(&bt_sk(sk
)->src
, BDADDR_ANY
))
317 read_unlock(&sco_sk_list
.lock
);
319 return node
? sk
: sk1
;
322 static void sco_sock_destruct(struct sock
*sk
)
326 skb_queue_purge(&sk
->sk_receive_queue
);
327 skb_queue_purge(&sk
->sk_write_queue
);
330 static void sco_sock_cleanup_listen(struct sock
*parent
)
334 BT_DBG("parent %p", parent
);
336 /* Close not yet accepted channels */
337 while ((sk
= bt_accept_dequeue(parent
, NULL
))) {
342 parent
->sk_state
= BT_CLOSED
;
343 sock_set_flag(parent
, SOCK_ZAPPED
);
346 /* Kill socket (only if zapped and orphan)
347 * Must be called on unlocked socket.
349 static void sco_sock_kill(struct sock
*sk
)
351 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
354 BT_DBG("sk %p state %d", sk
, sk
->sk_state
);
356 /* Kill poor orphan */
357 bt_sock_unlink(&sco_sk_list
, sk
);
358 sock_set_flag(sk
, SOCK_DEAD
);
362 static void __sco_sock_close(struct sock
*sk
)
364 BT_DBG("sk %p state %d socket %p", sk
, sk
->sk_state
, sk
->sk_socket
);
366 switch (sk
->sk_state
) {
368 sco_sock_cleanup_listen(sk
);
375 sco_chan_del(sk
, ECONNRESET
);
379 sock_set_flag(sk
, SOCK_ZAPPED
);
384 /* Must be called on unlocked socket. */
385 static void sco_sock_close(struct sock
*sk
)
387 sco_sock_clear_timer(sk
);
389 __sco_sock_close(sk
);
394 static void sco_sock_init(struct sock
*sk
, struct sock
*parent
)
399 sk
->sk_type
= parent
->sk_type
;
402 static struct proto sco_proto
= {
404 .owner
= THIS_MODULE
,
405 .obj_size
= sizeof(struct sco_pinfo
)
408 static struct sock
*sco_sock_alloc(struct net
*net
, struct socket
*sock
, int proto
, gfp_t prio
)
412 sk
= sk_alloc(net
, PF_BLUETOOTH
, prio
, &sco_proto
);
416 sock_init_data(sock
, sk
);
417 INIT_LIST_HEAD(&bt_sk(sk
)->accept_q
);
419 sk
->sk_destruct
= sco_sock_destruct
;
420 sk
->sk_sndtimeo
= SCO_CONN_TIMEOUT
;
422 sock_reset_flag(sk
, SOCK_ZAPPED
);
424 sk
->sk_protocol
= proto
;
425 sk
->sk_state
= BT_OPEN
;
427 setup_timer(&sk
->sk_timer
, sco_sock_timeout
, (unsigned long)sk
);
429 bt_sock_link(&sco_sk_list
, sk
);
433 static int sco_sock_create(struct net
*net
, struct socket
*sock
, int protocol
,
438 BT_DBG("sock %p", sock
);
440 sock
->state
= SS_UNCONNECTED
;
442 if (sock
->type
!= SOCK_SEQPACKET
)
443 return -ESOCKTNOSUPPORT
;
445 sock
->ops
= &sco_sock_ops
;
447 sk
= sco_sock_alloc(net
, sock
, protocol
, GFP_ATOMIC
);
451 sco_sock_init(sk
, NULL
);
455 static int sco_sock_bind(struct socket
*sock
, struct sockaddr
*addr
, int addr_len
)
457 struct sockaddr_sco
*sa
= (struct sockaddr_sco
*) addr
;
458 struct sock
*sk
= sock
->sk
;
459 bdaddr_t
*src
= &sa
->sco_bdaddr
;
462 BT_DBG("sk %p %s", sk
, batostr(&sa
->sco_bdaddr
));
464 if (!addr
|| addr
->sa_family
!= AF_BLUETOOTH
)
469 if (sk
->sk_state
!= BT_OPEN
) {
474 write_lock_bh(&sco_sk_list
.lock
);
476 if (bacmp(src
, BDADDR_ANY
) && __sco_get_sock_by_addr(src
)) {
479 /* Save source address */
480 bacpy(&bt_sk(sk
)->src
, &sa
->sco_bdaddr
);
481 sk
->sk_state
= BT_BOUND
;
484 write_unlock_bh(&sco_sk_list
.lock
);
491 static int sco_sock_connect(struct socket
*sock
, struct sockaddr
*addr
, int alen
, int flags
)
493 struct sockaddr_sco
*sa
= (struct sockaddr_sco
*) addr
;
494 struct sock
*sk
= sock
->sk
;
500 if (alen
< sizeof(struct sockaddr_sco
) ||
501 addr
->sa_family
!= AF_BLUETOOTH
)
504 if (sk
->sk_state
!= BT_OPEN
&& sk
->sk_state
!= BT_BOUND
)
507 if (sk
->sk_type
!= SOCK_SEQPACKET
)
512 /* Set destination address and psm */
513 bacpy(&bt_sk(sk
)->dst
, &sa
->sco_bdaddr
);
515 err
= sco_connect(sk
);
519 err
= bt_sock_wait_state(sk
, BT_CONNECTED
,
520 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
527 static int sco_sock_listen(struct socket
*sock
, int backlog
)
529 struct sock
*sk
= sock
->sk
;
532 BT_DBG("sk %p backlog %d", sk
, backlog
);
536 if (sk
->sk_state
!= BT_BOUND
|| sock
->type
!= SOCK_SEQPACKET
) {
541 sk
->sk_max_ack_backlog
= backlog
;
542 sk
->sk_ack_backlog
= 0;
543 sk
->sk_state
= BT_LISTEN
;
550 static int sco_sock_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
552 DECLARE_WAITQUEUE(wait
, current
);
553 struct sock
*sk
= sock
->sk
, *ch
;
559 if (sk
->sk_state
!= BT_LISTEN
) {
564 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
566 BT_DBG("sk %p timeo %ld", sk
, timeo
);
568 /* Wait for an incoming connection. (wake-one). */
569 add_wait_queue_exclusive(sk_sleep(sk
), &wait
);
570 while (!(ch
= bt_accept_dequeue(sk
, newsock
))) {
571 set_current_state(TASK_INTERRUPTIBLE
);
578 timeo
= schedule_timeout(timeo
);
581 if (sk
->sk_state
!= BT_LISTEN
) {
586 if (signal_pending(current
)) {
587 err
= sock_intr_errno(timeo
);
591 set_current_state(TASK_RUNNING
);
592 remove_wait_queue(sk_sleep(sk
), &wait
);
597 newsock
->state
= SS_CONNECTED
;
599 BT_DBG("new socket %p", ch
);
606 static int sco_sock_getname(struct socket
*sock
, struct sockaddr
*addr
, int *len
, int peer
)
608 struct sockaddr_sco
*sa
= (struct sockaddr_sco
*) addr
;
609 struct sock
*sk
= sock
->sk
;
611 BT_DBG("sock %p, sk %p", sock
, sk
);
613 addr
->sa_family
= AF_BLUETOOTH
;
614 *len
= sizeof(struct sockaddr_sco
);
617 bacpy(&sa
->sco_bdaddr
, &bt_sk(sk
)->dst
);
619 bacpy(&sa
->sco_bdaddr
, &bt_sk(sk
)->src
);
624 static int sco_sock_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
625 struct msghdr
*msg
, size_t len
)
627 struct sock
*sk
= sock
->sk
;
630 BT_DBG("sock %p, sk %p", sock
, sk
);
632 err
= sock_error(sk
);
636 if (msg
->msg_flags
& MSG_OOB
)
641 if (sk
->sk_state
== BT_CONNECTED
)
642 err
= sco_send_frame(sk
, msg
, len
);
650 static int sco_sock_setsockopt(struct socket
*sock
, int level
, int optname
, char __user
*optval
, unsigned int optlen
)
652 struct sock
*sk
= sock
->sk
;
669 static int sco_sock_getsockopt_old(struct socket
*sock
, int optname
, char __user
*optval
, int __user
*optlen
)
671 struct sock
*sk
= sock
->sk
;
672 struct sco_options opts
;
673 struct sco_conninfo cinfo
;
678 if (get_user(len
, optlen
))
685 if (sk
->sk_state
!= BT_CONNECTED
) {
690 opts
.mtu
= sco_pi(sk
)->conn
->mtu
;
692 BT_DBG("mtu %d", opts
.mtu
);
694 len
= min_t(unsigned int, len
, sizeof(opts
));
695 if (copy_to_user(optval
, (char *)&opts
, len
))
701 if (sk
->sk_state
!= BT_CONNECTED
) {
706 cinfo
.hci_handle
= sco_pi(sk
)->conn
->hcon
->handle
;
707 memcpy(cinfo
.dev_class
, sco_pi(sk
)->conn
->hcon
->dev_class
, 3);
709 len
= min_t(unsigned int, len
, sizeof(cinfo
));
710 if (copy_to_user(optval
, (char *)&cinfo
, len
))
724 static int sco_sock_getsockopt(struct socket
*sock
, int level
, int optname
, char __user
*optval
, int __user
*optlen
)
726 struct sock
*sk
= sock
->sk
;
731 if (level
== SOL_SCO
)
732 return sco_sock_getsockopt_old(sock
, optname
, optval
, optlen
);
734 if (get_user(len
, optlen
))
749 static int sco_sock_shutdown(struct socket
*sock
, int how
)
751 struct sock
*sk
= sock
->sk
;
754 BT_DBG("sock %p, sk %p", sock
, sk
);
760 if (!sk
->sk_shutdown
) {
761 sk
->sk_shutdown
= SHUTDOWN_MASK
;
762 sco_sock_clear_timer(sk
);
763 __sco_sock_close(sk
);
765 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
766 err
= bt_sock_wait_state(sk
, BT_CLOSED
,
773 static int sco_sock_release(struct socket
*sock
)
775 struct sock
*sk
= sock
->sk
;
778 BT_DBG("sock %p, sk %p", sock
, sk
);
785 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
) {
787 err
= bt_sock_wait_state(sk
, BT_CLOSED
, sk
->sk_lingertime
);
796 static void __sco_chan_add(struct sco_conn
*conn
, struct sock
*sk
, struct sock
*parent
)
798 BT_DBG("conn %p", conn
);
800 sco_pi(sk
)->conn
= conn
;
804 bt_accept_enqueue(parent
, sk
);
808 * Must be called on the locked socket. */
809 static void sco_chan_del(struct sock
*sk
, int err
)
811 struct sco_conn
*conn
;
813 conn
= sco_pi(sk
)->conn
;
815 BT_DBG("sk %p, conn %p, err %d", sk
, conn
, err
);
820 sco_pi(sk
)->conn
= NULL
;
821 sco_conn_unlock(conn
);
822 hci_conn_put(conn
->hcon
);
825 sk
->sk_state
= BT_CLOSED
;
827 sk
->sk_state_change(sk
);
829 sock_set_flag(sk
, SOCK_ZAPPED
);
832 static void sco_conn_ready(struct sco_conn
*conn
)
835 struct sock
*sk
= conn
->sk
;
837 BT_DBG("conn %p", conn
);
842 sco_sock_clear_timer(sk
);
844 sk
->sk_state
= BT_CONNECTED
;
845 sk
->sk_state_change(sk
);
848 parent
= sco_get_sock_listen(conn
->src
);
852 bh_lock_sock(parent
);
854 sk
= sco_sock_alloc(sock_net(parent
), NULL
,
855 BTPROTO_SCO
, GFP_ATOMIC
);
857 bh_unlock_sock(parent
);
861 sco_sock_init(sk
, parent
);
863 bacpy(&bt_sk(sk
)->src
, conn
->src
);
864 bacpy(&bt_sk(sk
)->dst
, conn
->dst
);
866 hci_conn_hold(conn
->hcon
);
867 __sco_chan_add(conn
, sk
, parent
);
869 sk
->sk_state
= BT_CONNECTED
;
872 parent
->sk_data_ready(parent
, 1);
874 bh_unlock_sock(parent
);
878 sco_conn_unlock(conn
);
881 /* ----- SCO interface with lower layer (HCI) ----- */
882 static int sco_connect_ind(struct hci_dev
*hdev
, bdaddr_t
*bdaddr
, __u8 type
)
884 register struct sock
*sk
;
885 struct hlist_node
*node
;
888 if (type
!= SCO_LINK
&& type
!= ESCO_LINK
)
891 BT_DBG("hdev %s, bdaddr %s", hdev
->name
, batostr(bdaddr
));
893 /* Find listening sockets */
894 read_lock(&sco_sk_list
.lock
);
895 sk_for_each(sk
, node
, &sco_sk_list
.head
) {
896 if (sk
->sk_state
!= BT_LISTEN
)
899 if (!bacmp(&bt_sk(sk
)->src
, &hdev
->bdaddr
) ||
900 !bacmp(&bt_sk(sk
)->src
, BDADDR_ANY
)) {
905 read_unlock(&sco_sk_list
.lock
);
910 static int sco_connect_cfm(struct hci_conn
*hcon
, __u8 status
)
912 BT_DBG("hcon %p bdaddr %s status %d", hcon
, batostr(&hcon
->dst
), status
);
914 if (hcon
->type
!= SCO_LINK
&& hcon
->type
!= ESCO_LINK
)
918 struct sco_conn
*conn
;
920 conn
= sco_conn_add(hcon
, status
);
922 sco_conn_ready(conn
);
924 sco_conn_del(hcon
, bt_err(status
));
929 static int sco_disconn_cfm(struct hci_conn
*hcon
, __u8 reason
)
931 BT_DBG("hcon %p reason %d", hcon
, reason
);
933 if (hcon
->type
!= SCO_LINK
&& hcon
->type
!= ESCO_LINK
)
936 sco_conn_del(hcon
, bt_err(reason
));
941 static int sco_recv_scodata(struct hci_conn
*hcon
, struct sk_buff
*skb
)
943 struct sco_conn
*conn
= hcon
->sco_data
;
948 BT_DBG("conn %p len %d", conn
, skb
->len
);
951 sco_recv_frame(conn
, skb
);
960 static int sco_debugfs_show(struct seq_file
*f
, void *p
)
963 struct hlist_node
*node
;
965 read_lock_bh(&sco_sk_list
.lock
);
967 sk_for_each(sk
, node
, &sco_sk_list
.head
) {
968 seq_printf(f
, "%s %s %d\n", batostr(&bt_sk(sk
)->src
),
969 batostr(&bt_sk(sk
)->dst
), sk
->sk_state
);
972 read_unlock_bh(&sco_sk_list
.lock
);
977 static int sco_debugfs_open(struct inode
*inode
, struct file
*file
)
979 return single_open(file
, sco_debugfs_show
, inode
->i_private
);
982 static const struct file_operations sco_debugfs_fops
= {
983 .open
= sco_debugfs_open
,
986 .release
= single_release
,
989 static struct dentry
*sco_debugfs
;
991 static const struct proto_ops sco_sock_ops
= {
992 .family
= PF_BLUETOOTH
,
993 .owner
= THIS_MODULE
,
994 .release
= sco_sock_release
,
995 .bind
= sco_sock_bind
,
996 .connect
= sco_sock_connect
,
997 .listen
= sco_sock_listen
,
998 .accept
= sco_sock_accept
,
999 .getname
= sco_sock_getname
,
1000 .sendmsg
= sco_sock_sendmsg
,
1001 .recvmsg
= bt_sock_recvmsg
,
1002 .poll
= bt_sock_poll
,
1003 .ioctl
= bt_sock_ioctl
,
1004 .mmap
= sock_no_mmap
,
1005 .socketpair
= sock_no_socketpair
,
1006 .shutdown
= sco_sock_shutdown
,
1007 .setsockopt
= sco_sock_setsockopt
,
1008 .getsockopt
= sco_sock_getsockopt
1011 static const struct net_proto_family sco_sock_family_ops
= {
1012 .family
= PF_BLUETOOTH
,
1013 .owner
= THIS_MODULE
,
1014 .create
= sco_sock_create
,
1017 static struct hci_proto sco_hci_proto
= {
1019 .id
= HCI_PROTO_SCO
,
1020 .connect_ind
= sco_connect_ind
,
1021 .connect_cfm
= sco_connect_cfm
,
1022 .disconn_cfm
= sco_disconn_cfm
,
1023 .recv_scodata
= sco_recv_scodata
1026 static int __init
sco_init(void)
1030 err
= proto_register(&sco_proto
, 0);
1034 err
= bt_sock_register(BTPROTO_SCO
, &sco_sock_family_ops
);
1036 BT_ERR("SCO socket registration failed");
1040 err
= hci_register_proto(&sco_hci_proto
);
1042 BT_ERR("SCO protocol registration failed");
1043 bt_sock_unregister(BTPROTO_SCO
);
1048 sco_debugfs
= debugfs_create_file("sco", 0444,
1049 bt_debugfs
, NULL
, &sco_debugfs_fops
);
1051 BT_ERR("Failed to create SCO debug file");
1054 BT_INFO("SCO (Voice Link) ver %s", VERSION
);
1055 BT_INFO("SCO socket layer initialized");
1060 proto_unregister(&sco_proto
);
1064 static void __exit
sco_exit(void)
1066 debugfs_remove(sco_debugfs
);
1068 if (bt_sock_unregister(BTPROTO_SCO
) < 0)
1069 BT_ERR("SCO socket unregistration failed");
1071 if (hci_unregister_proto(&sco_hci_proto
) < 0)
1072 BT_ERR("SCO protocol unregistration failed");
1074 proto_unregister(&sco_proto
);
1077 module_init(sco_init
);
1078 module_exit(sco_exit
);
1080 module_param(disable_esco
, bool, 0644);
1081 MODULE_PARM_DESC(disable_esco
, "Disable eSCO connection creation");
1083 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
1084 MODULE_DESCRIPTION("Bluetooth SCO ver " VERSION
);
1085 MODULE_VERSION(VERSION
);
1086 MODULE_LICENSE("GPL");
1087 MODULE_ALIAS("bt-proto-2");