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>
53 static int disable_esco
;
55 static const struct proto_ops sco_sock_ops
;
57 static struct bt_sock_list sco_sk_list
= {
58 .lock
= __RW_LOCK_UNLOCKED(sco_sk_list
.lock
)
61 static void __sco_chan_add(struct sco_conn
*conn
, struct sock
*sk
, struct sock
*parent
);
62 static void sco_chan_del(struct sock
*sk
, int err
);
64 static int sco_conn_del(struct hci_conn
*conn
, int err
);
66 static void sco_sock_close(struct sock
*sk
);
67 static void sco_sock_kill(struct sock
*sk
);
69 /* ---- SCO timers ---- */
70 static void sco_sock_timeout(unsigned long arg
)
72 struct sock
*sk
= (struct sock
*) arg
;
74 BT_DBG("sock %p state %d", sk
, sk
->sk_state
);
77 sk
->sk_err
= ETIMEDOUT
;
78 sk
->sk_state_change(sk
);
85 static void sco_sock_set_timer(struct sock
*sk
, long timeout
)
87 BT_DBG("sock %p state %d timeout %ld", sk
, sk
->sk_state
, timeout
);
88 sk_reset_timer(sk
, &sk
->sk_timer
, jiffies
+ timeout
);
91 static void sco_sock_clear_timer(struct sock
*sk
)
93 BT_DBG("sock %p state %d", sk
, sk
->sk_state
);
94 sk_stop_timer(sk
, &sk
->sk_timer
);
97 /* ---- SCO connections ---- */
98 static struct sco_conn
*sco_conn_add(struct hci_conn
*hcon
, __u8 status
)
100 struct hci_dev
*hdev
= hcon
->hdev
;
101 struct sco_conn
*conn
= hcon
->sco_data
;
106 conn
= kzalloc(sizeof(struct sco_conn
), GFP_ATOMIC
);
110 spin_lock_init(&conn
->lock
);
112 hcon
->sco_data
= conn
;
115 conn
->src
= &hdev
->bdaddr
;
116 conn
->dst
= &hcon
->dst
;
118 if (hdev
->sco_mtu
> 0)
119 conn
->mtu
= hdev
->sco_mtu
;
123 BT_DBG("hcon %p conn %p", hcon
, conn
);
128 static inline struct sock
*sco_chan_get(struct sco_conn
*conn
)
130 struct sock
*sk
= NULL
;
133 sco_conn_unlock(conn
);
137 static int sco_conn_del(struct hci_conn
*hcon
, int err
)
139 struct sco_conn
*conn
= hcon
->sco_data
;
145 BT_DBG("hcon %p conn %p, err %d", hcon
, conn
, err
);
148 sk
= sco_chan_get(conn
);
151 sco_sock_clear_timer(sk
);
152 sco_chan_del(sk
, err
);
157 hcon
->sco_data
= NULL
;
162 static inline int sco_chan_add(struct sco_conn
*conn
, struct sock
*sk
, struct sock
*parent
)
170 __sco_chan_add(conn
, sk
, parent
);
172 sco_conn_unlock(conn
);
176 static int sco_connect(struct sock
*sk
)
178 bdaddr_t
*src
= &bt_sk(sk
)->src
;
179 bdaddr_t
*dst
= &bt_sk(sk
)->dst
;
180 struct sco_conn
*conn
;
181 struct hci_conn
*hcon
;
182 struct hci_dev
*hdev
;
185 BT_DBG("%s -> %s", batostr(src
), batostr(dst
));
187 hdev
= hci_get_route(dst
, src
);
189 return -EHOSTUNREACH
;
191 hci_dev_lock_bh(hdev
);
193 if (lmp_esco_capable(hdev
) && !disable_esco
)
198 hcon
= hci_connect(hdev
, type
, dst
, BT_SECURITY_LOW
, HCI_AT_NO_BONDING
);
204 conn
= sco_conn_add(hcon
, 0);
211 /* Update source addr of the socket */
212 bacpy(src
, conn
->src
);
214 err
= sco_chan_add(conn
, sk
, NULL
);
218 if (hcon
->state
== BT_CONNECTED
) {
219 sco_sock_clear_timer(sk
);
220 sk
->sk_state
= BT_CONNECTED
;
222 sk
->sk_state
= BT_CONNECT
;
223 sco_sock_set_timer(sk
, sk
->sk_sndtimeo
);
227 hci_dev_unlock_bh(hdev
);
232 static inline int sco_send_frame(struct sock
*sk
, struct msghdr
*msg
, int len
)
234 struct sco_conn
*conn
= sco_pi(sk
)->conn
;
238 /* Check outgoing MTU */
242 BT_DBG("sk %p len %d", sk
, len
);
244 count
= min_t(unsigned int, conn
->mtu
, len
);
245 skb
= bt_skb_send_alloc(sk
, count
,
246 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
250 if (memcpy_fromiovec(skb_put(skb
, count
), msg
->msg_iov
, count
)) {
255 hci_send_sco(conn
->hcon
, skb
);
260 static inline void sco_recv_frame(struct sco_conn
*conn
, struct sk_buff
*skb
)
262 struct sock
*sk
= sco_chan_get(conn
);
267 BT_DBG("sk %p len %d", sk
, skb
->len
);
269 if (sk
->sk_state
!= BT_CONNECTED
)
272 if (!sock_queue_rcv_skb(sk
, skb
))
279 /* -------- Socket interface ---------- */
280 static struct sock
*__sco_get_sock_by_addr(bdaddr_t
*ba
)
283 struct hlist_node
*node
;
285 sk_for_each(sk
, node
, &sco_sk_list
.head
)
286 if (!bacmp(&bt_sk(sk
)->src
, ba
))
293 /* Find socket listening on source bdaddr.
294 * Returns closest match.
296 static struct sock
*sco_get_sock_listen(bdaddr_t
*src
)
298 struct sock
*sk
= NULL
, *sk1
= NULL
;
299 struct hlist_node
*node
;
301 read_lock(&sco_sk_list
.lock
);
303 sk_for_each(sk
, node
, &sco_sk_list
.head
) {
304 if (sk
->sk_state
!= BT_LISTEN
)
308 if (!bacmp(&bt_sk(sk
)->src
, src
))
312 if (!bacmp(&bt_sk(sk
)->src
, BDADDR_ANY
))
316 read_unlock(&sco_sk_list
.lock
);
318 return node
? sk
: sk1
;
321 static void sco_sock_destruct(struct sock
*sk
)
325 skb_queue_purge(&sk
->sk_receive_queue
);
326 skb_queue_purge(&sk
->sk_write_queue
);
329 static void sco_sock_cleanup_listen(struct sock
*parent
)
333 BT_DBG("parent %p", parent
);
335 /* Close not yet accepted channels */
336 while ((sk
= bt_accept_dequeue(parent
, NULL
))) {
341 parent
->sk_state
= BT_CLOSED
;
342 sock_set_flag(parent
, SOCK_ZAPPED
);
345 /* Kill socket (only if zapped and orphan)
346 * Must be called on unlocked socket.
348 static void sco_sock_kill(struct sock
*sk
)
350 if (!sock_flag(sk
, SOCK_ZAPPED
) || sk
->sk_socket
)
353 BT_DBG("sk %p state %d", sk
, sk
->sk_state
);
355 /* Kill poor orphan */
356 bt_sock_unlink(&sco_sk_list
, sk
);
357 sock_set_flag(sk
, SOCK_DEAD
);
361 static void __sco_sock_close(struct sock
*sk
)
363 BT_DBG("sk %p state %d socket %p", sk
, sk
->sk_state
, sk
->sk_socket
);
365 switch (sk
->sk_state
) {
367 sco_sock_cleanup_listen(sk
);
374 sco_chan_del(sk
, ECONNRESET
);
378 sock_set_flag(sk
, SOCK_ZAPPED
);
383 /* Must be called on unlocked socket. */
384 static void sco_sock_close(struct sock
*sk
)
386 sco_sock_clear_timer(sk
);
388 __sco_sock_close(sk
);
393 static void sco_sock_init(struct sock
*sk
, struct sock
*parent
)
398 sk
->sk_type
= parent
->sk_type
;
401 static struct proto sco_proto
= {
403 .owner
= THIS_MODULE
,
404 .obj_size
= sizeof(struct sco_pinfo
)
407 static struct sock
*sco_sock_alloc(struct net
*net
, struct socket
*sock
, int proto
, gfp_t prio
)
411 sk
= sk_alloc(net
, PF_BLUETOOTH
, prio
, &sco_proto
);
415 sock_init_data(sock
, sk
);
416 INIT_LIST_HEAD(&bt_sk(sk
)->accept_q
);
418 sk
->sk_destruct
= sco_sock_destruct
;
419 sk
->sk_sndtimeo
= SCO_CONN_TIMEOUT
;
421 sock_reset_flag(sk
, SOCK_ZAPPED
);
423 sk
->sk_protocol
= proto
;
424 sk
->sk_state
= BT_OPEN
;
426 setup_timer(&sk
->sk_timer
, sco_sock_timeout
, (unsigned long)sk
);
428 bt_sock_link(&sco_sk_list
, sk
);
432 static int sco_sock_create(struct net
*net
, struct socket
*sock
, int protocol
,
437 BT_DBG("sock %p", sock
);
439 sock
->state
= SS_UNCONNECTED
;
441 if (sock
->type
!= SOCK_SEQPACKET
)
442 return -ESOCKTNOSUPPORT
;
444 sock
->ops
= &sco_sock_ops
;
446 sk
= sco_sock_alloc(net
, sock
, protocol
, GFP_ATOMIC
);
450 sco_sock_init(sk
, NULL
);
454 static int sco_sock_bind(struct socket
*sock
, struct sockaddr
*addr
, int addr_len
)
456 struct sockaddr_sco
*sa
= (struct sockaddr_sco
*) addr
;
457 struct sock
*sk
= sock
->sk
;
458 bdaddr_t
*src
= &sa
->sco_bdaddr
;
461 BT_DBG("sk %p %s", sk
, batostr(&sa
->sco_bdaddr
));
463 if (!addr
|| addr
->sa_family
!= AF_BLUETOOTH
)
468 if (sk
->sk_state
!= BT_OPEN
) {
473 write_lock_bh(&sco_sk_list
.lock
);
475 if (bacmp(src
, BDADDR_ANY
) && __sco_get_sock_by_addr(src
)) {
478 /* Save source address */
479 bacpy(&bt_sk(sk
)->src
, &sa
->sco_bdaddr
);
480 sk
->sk_state
= BT_BOUND
;
483 write_unlock_bh(&sco_sk_list
.lock
);
490 static int sco_sock_connect(struct socket
*sock
, struct sockaddr
*addr
, int alen
, int flags
)
492 struct sockaddr_sco
*sa
= (struct sockaddr_sco
*) addr
;
493 struct sock
*sk
= sock
->sk
;
499 if (alen
< sizeof(struct sockaddr_sco
) ||
500 addr
->sa_family
!= AF_BLUETOOTH
)
503 if (sk
->sk_state
!= BT_OPEN
&& sk
->sk_state
!= BT_BOUND
)
506 if (sk
->sk_type
!= SOCK_SEQPACKET
)
511 /* Set destination address and psm */
512 bacpy(&bt_sk(sk
)->dst
, &sa
->sco_bdaddr
);
514 err
= sco_connect(sk
);
518 err
= bt_sock_wait_state(sk
, BT_CONNECTED
,
519 sock_sndtimeo(sk
, flags
& O_NONBLOCK
));
526 static int sco_sock_listen(struct socket
*sock
, int backlog
)
528 struct sock
*sk
= sock
->sk
;
531 BT_DBG("sk %p backlog %d", sk
, backlog
);
535 if (sk
->sk_state
!= BT_BOUND
|| sock
->type
!= SOCK_SEQPACKET
) {
540 sk
->sk_max_ack_backlog
= backlog
;
541 sk
->sk_ack_backlog
= 0;
542 sk
->sk_state
= BT_LISTEN
;
549 static int sco_sock_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
551 DECLARE_WAITQUEUE(wait
, current
);
552 struct sock
*sk
= sock
->sk
, *ch
;
558 if (sk
->sk_state
!= BT_LISTEN
) {
563 timeo
= sock_rcvtimeo(sk
, flags
& O_NONBLOCK
);
565 BT_DBG("sk %p timeo %ld", sk
, timeo
);
567 /* Wait for an incoming connection. (wake-one). */
568 add_wait_queue_exclusive(sk_sleep(sk
), &wait
);
569 while (!(ch
= bt_accept_dequeue(sk
, newsock
))) {
570 set_current_state(TASK_INTERRUPTIBLE
);
577 timeo
= schedule_timeout(timeo
);
580 if (sk
->sk_state
!= BT_LISTEN
) {
585 if (signal_pending(current
)) {
586 err
= sock_intr_errno(timeo
);
590 set_current_state(TASK_RUNNING
);
591 remove_wait_queue(sk_sleep(sk
), &wait
);
596 newsock
->state
= SS_CONNECTED
;
598 BT_DBG("new socket %p", ch
);
605 static int sco_sock_getname(struct socket
*sock
, struct sockaddr
*addr
, int *len
, int peer
)
607 struct sockaddr_sco
*sa
= (struct sockaddr_sco
*) addr
;
608 struct sock
*sk
= sock
->sk
;
610 BT_DBG("sock %p, sk %p", sock
, sk
);
612 addr
->sa_family
= AF_BLUETOOTH
;
613 *len
= sizeof(struct sockaddr_sco
);
616 bacpy(&sa
->sco_bdaddr
, &bt_sk(sk
)->dst
);
618 bacpy(&sa
->sco_bdaddr
, &bt_sk(sk
)->src
);
623 static int sco_sock_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
624 struct msghdr
*msg
, size_t len
)
626 struct sock
*sk
= sock
->sk
;
629 BT_DBG("sock %p, sk %p", sock
, sk
);
631 err
= sock_error(sk
);
635 if (msg
->msg_flags
& MSG_OOB
)
640 if (sk
->sk_state
== BT_CONNECTED
)
641 err
= sco_send_frame(sk
, msg
, len
);
649 static int sco_sock_setsockopt(struct socket
*sock
, int level
, int optname
, char __user
*optval
, unsigned int optlen
)
651 struct sock
*sk
= sock
->sk
;
668 static int sco_sock_getsockopt_old(struct socket
*sock
, int optname
, char __user
*optval
, int __user
*optlen
)
670 struct sock
*sk
= sock
->sk
;
671 struct sco_options opts
;
672 struct sco_conninfo cinfo
;
677 if (get_user(len
, optlen
))
684 if (sk
->sk_state
!= BT_CONNECTED
) {
689 opts
.mtu
= sco_pi(sk
)->conn
->mtu
;
691 BT_DBG("mtu %d", opts
.mtu
);
693 len
= min_t(unsigned int, len
, sizeof(opts
));
694 if (copy_to_user(optval
, (char *)&opts
, len
))
700 if (sk
->sk_state
!= BT_CONNECTED
) {
705 memset(&cinfo
, 0, sizeof(cinfo
));
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 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 socket layer initialized");
1059 proto_unregister(&sco_proto
);
1063 void __exit
sco_exit(void)
1065 debugfs_remove(sco_debugfs
);
1067 if (bt_sock_unregister(BTPROTO_SCO
) < 0)
1068 BT_ERR("SCO socket unregistration failed");
1070 if (hci_unregister_proto(&sco_hci_proto
) < 0)
1071 BT_ERR("SCO protocol unregistration failed");
1073 proto_unregister(&sco_proto
);
1076 module_param(disable_esco
, bool, 0644);
1077 MODULE_PARM_DESC(disable_esco
, "Disable eSCO connection creation");