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 memset(&cinfo
, 0, sizeof(cinfo
));
707 cinfo
.hci_handle
= sco_pi(sk
)->conn
->hcon
->handle
;
708 memcpy(cinfo
.dev_class
, sco_pi(sk
)->conn
->hcon
->dev_class
, 3);
710 len
= min_t(unsigned int, len
, sizeof(cinfo
));
711 if (copy_to_user(optval
, (char *)&cinfo
, len
))
725 static int sco_sock_getsockopt(struct socket
*sock
, int level
, int optname
, char __user
*optval
, int __user
*optlen
)
727 struct sock
*sk
= sock
->sk
;
732 if (level
== SOL_SCO
)
733 return sco_sock_getsockopt_old(sock
, optname
, optval
, optlen
);
735 if (get_user(len
, optlen
))
750 static int sco_sock_shutdown(struct socket
*sock
, int how
)
752 struct sock
*sk
= sock
->sk
;
755 BT_DBG("sock %p, sk %p", sock
, sk
);
761 if (!sk
->sk_shutdown
) {
762 sk
->sk_shutdown
= SHUTDOWN_MASK
;
763 sco_sock_clear_timer(sk
);
764 __sco_sock_close(sk
);
766 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
)
767 err
= bt_sock_wait_state(sk
, BT_CLOSED
,
774 static int sco_sock_release(struct socket
*sock
)
776 struct sock
*sk
= sock
->sk
;
779 BT_DBG("sock %p, sk %p", sock
, sk
);
786 if (sock_flag(sk
, SOCK_LINGER
) && sk
->sk_lingertime
) {
788 err
= bt_sock_wait_state(sk
, BT_CLOSED
, sk
->sk_lingertime
);
797 static void __sco_chan_add(struct sco_conn
*conn
, struct sock
*sk
, struct sock
*parent
)
799 BT_DBG("conn %p", conn
);
801 sco_pi(sk
)->conn
= conn
;
805 bt_accept_enqueue(parent
, sk
);
809 * Must be called on the locked socket. */
810 static void sco_chan_del(struct sock
*sk
, int err
)
812 struct sco_conn
*conn
;
814 conn
= sco_pi(sk
)->conn
;
816 BT_DBG("sk %p, conn %p, err %d", sk
, conn
, err
);
821 sco_pi(sk
)->conn
= NULL
;
822 sco_conn_unlock(conn
);
823 hci_conn_put(conn
->hcon
);
826 sk
->sk_state
= BT_CLOSED
;
828 sk
->sk_state_change(sk
);
830 sock_set_flag(sk
, SOCK_ZAPPED
);
833 static void sco_conn_ready(struct sco_conn
*conn
)
836 struct sock
*sk
= conn
->sk
;
838 BT_DBG("conn %p", conn
);
843 sco_sock_clear_timer(sk
);
845 sk
->sk_state
= BT_CONNECTED
;
846 sk
->sk_state_change(sk
);
849 parent
= sco_get_sock_listen(conn
->src
);
853 bh_lock_sock(parent
);
855 sk
= sco_sock_alloc(sock_net(parent
), NULL
,
856 BTPROTO_SCO
, GFP_ATOMIC
);
858 bh_unlock_sock(parent
);
862 sco_sock_init(sk
, parent
);
864 bacpy(&bt_sk(sk
)->src
, conn
->src
);
865 bacpy(&bt_sk(sk
)->dst
, conn
->dst
);
867 hci_conn_hold(conn
->hcon
);
868 __sco_chan_add(conn
, sk
, parent
);
870 sk
->sk_state
= BT_CONNECTED
;
873 parent
->sk_data_ready(parent
, 1);
875 bh_unlock_sock(parent
);
879 sco_conn_unlock(conn
);
882 /* ----- SCO interface with lower layer (HCI) ----- */
883 static int sco_connect_ind(struct hci_dev
*hdev
, bdaddr_t
*bdaddr
, __u8 type
)
885 register struct sock
*sk
;
886 struct hlist_node
*node
;
889 if (type
!= SCO_LINK
&& type
!= ESCO_LINK
)
892 BT_DBG("hdev %s, bdaddr %s", hdev
->name
, batostr(bdaddr
));
894 /* Find listening sockets */
895 read_lock(&sco_sk_list
.lock
);
896 sk_for_each(sk
, node
, &sco_sk_list
.head
) {
897 if (sk
->sk_state
!= BT_LISTEN
)
900 if (!bacmp(&bt_sk(sk
)->src
, &hdev
->bdaddr
) ||
901 !bacmp(&bt_sk(sk
)->src
, BDADDR_ANY
)) {
906 read_unlock(&sco_sk_list
.lock
);
911 static int sco_connect_cfm(struct hci_conn
*hcon
, __u8 status
)
913 BT_DBG("hcon %p bdaddr %s status %d", hcon
, batostr(&hcon
->dst
), status
);
915 if (hcon
->type
!= SCO_LINK
&& hcon
->type
!= ESCO_LINK
)
919 struct sco_conn
*conn
;
921 conn
= sco_conn_add(hcon
, status
);
923 sco_conn_ready(conn
);
925 sco_conn_del(hcon
, bt_err(status
));
930 static int sco_disconn_cfm(struct hci_conn
*hcon
, __u8 reason
)
932 BT_DBG("hcon %p reason %d", hcon
, reason
);
934 if (hcon
->type
!= SCO_LINK
&& hcon
->type
!= ESCO_LINK
)
937 sco_conn_del(hcon
, bt_err(reason
));
942 static int sco_recv_scodata(struct hci_conn
*hcon
, struct sk_buff
*skb
)
944 struct sco_conn
*conn
= hcon
->sco_data
;
949 BT_DBG("conn %p len %d", conn
, skb
->len
);
952 sco_recv_frame(conn
, skb
);
961 static int sco_debugfs_show(struct seq_file
*f
, void *p
)
964 struct hlist_node
*node
;
966 read_lock_bh(&sco_sk_list
.lock
);
968 sk_for_each(sk
, node
, &sco_sk_list
.head
) {
969 seq_printf(f
, "%s %s %d\n", batostr(&bt_sk(sk
)->src
),
970 batostr(&bt_sk(sk
)->dst
), sk
->sk_state
);
973 read_unlock_bh(&sco_sk_list
.lock
);
978 static int sco_debugfs_open(struct inode
*inode
, struct file
*file
)
980 return single_open(file
, sco_debugfs_show
, inode
->i_private
);
983 static const struct file_operations sco_debugfs_fops
= {
984 .open
= sco_debugfs_open
,
987 .release
= single_release
,
990 static struct dentry
*sco_debugfs
;
992 static const struct proto_ops sco_sock_ops
= {
993 .family
= PF_BLUETOOTH
,
994 .owner
= THIS_MODULE
,
995 .release
= sco_sock_release
,
996 .bind
= sco_sock_bind
,
997 .connect
= sco_sock_connect
,
998 .listen
= sco_sock_listen
,
999 .accept
= sco_sock_accept
,
1000 .getname
= sco_sock_getname
,
1001 .sendmsg
= sco_sock_sendmsg
,
1002 .recvmsg
= bt_sock_recvmsg
,
1003 .poll
= bt_sock_poll
,
1004 .ioctl
= bt_sock_ioctl
,
1005 .mmap
= sock_no_mmap
,
1006 .socketpair
= sock_no_socketpair
,
1007 .shutdown
= sco_sock_shutdown
,
1008 .setsockopt
= sco_sock_setsockopt
,
1009 .getsockopt
= sco_sock_getsockopt
1012 static const struct net_proto_family sco_sock_family_ops
= {
1013 .family
= PF_BLUETOOTH
,
1014 .owner
= THIS_MODULE
,
1015 .create
= sco_sock_create
,
1018 static struct hci_proto sco_hci_proto
= {
1020 .id
= HCI_PROTO_SCO
,
1021 .connect_ind
= sco_connect_ind
,
1022 .connect_cfm
= sco_connect_cfm
,
1023 .disconn_cfm
= sco_disconn_cfm
,
1024 .recv_scodata
= sco_recv_scodata
1027 static int __init
sco_init(void)
1031 err
= proto_register(&sco_proto
, 0);
1035 err
= bt_sock_register(BTPROTO_SCO
, &sco_sock_family_ops
);
1037 BT_ERR("SCO socket registration failed");
1041 err
= hci_register_proto(&sco_hci_proto
);
1043 BT_ERR("SCO protocol registration failed");
1044 bt_sock_unregister(BTPROTO_SCO
);
1049 sco_debugfs
= debugfs_create_file("sco", 0444,
1050 bt_debugfs
, NULL
, &sco_debugfs_fops
);
1052 BT_ERR("Failed to create SCO debug file");
1055 BT_INFO("SCO (Voice Link) ver %s", VERSION
);
1056 BT_INFO("SCO socket layer initialized");
1061 proto_unregister(&sco_proto
);
1065 static void __exit
sco_exit(void)
1067 debugfs_remove(sco_debugfs
);
1069 if (bt_sock_unregister(BTPROTO_SCO
) < 0)
1070 BT_ERR("SCO socket unregistration failed");
1072 if (hci_unregister_proto(&sco_hci_proto
) < 0)
1073 BT_ERR("SCO protocol unregistration failed");
1075 proto_unregister(&sco_proto
);
1078 module_init(sco_init
);
1079 module_exit(sco_exit
);
1081 module_param(disable_esco
, bool, 0644);
1082 MODULE_PARM_DESC(disable_esco
, "Disable eSCO connection creation");
1084 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
1085 MODULE_DESCRIPTION("Bluetooth SCO ver " VERSION
);
1086 MODULE_VERSION(VERSION
);
1087 MODULE_LICENSE("GPL");
1088 MODULE_ALIAS("bt-proto-2");