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>
28 #include <linux/debugfs.h>
29 #include <linux/seq_file.h>
31 #include <net/bluetooth/bluetooth.h>
32 #include <net/bluetooth/hci_core.h>
33 #include <net/bluetooth/sco.h>
35 static bool disable_esco;
37 static const struct proto_ops sco_sock_ops;
39 static struct bt_sock_list sco_sk_list = {
40 .lock = __RW_LOCK_UNLOCKED(sco_sk_list.lock)
43 static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent);
44 static void sco_chan_del(struct sock *sk, int err);
46 static void sco_sock_close(struct sock *sk);
47 static void sco_sock_kill(struct sock *sk);
49 /* ---- SCO timers ---- */
50 static void sco_sock_timeout(unsigned long arg)
52 struct sock *sk = (struct sock *) arg;
54 BT_DBG("sock %p state %d", sk, sk->sk_state);
57 sk->sk_err = ETIMEDOUT;
58 sk->sk_state_change(sk);
65 static void sco_sock_set_timer(struct sock *sk, long timeout)
67 BT_DBG("sock %p state %d timeout %ld", sk, sk->sk_state, timeout);
68 sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout);
71 static void sco_sock_clear_timer(struct sock *sk)
73 BT_DBG("sock %p state %d", sk, sk->sk_state);
74 sk_stop_timer(sk, &sk->sk_timer);
77 /* ---- SCO connections ---- */
78 static struct sco_conn *sco_conn_add(struct hci_conn *hcon)
80 struct hci_dev *hdev = hcon->hdev;
81 struct sco_conn *conn = hcon->sco_data;
86 conn = kzalloc(sizeof(struct sco_conn), GFP_KERNEL);
90 spin_lock_init(&conn->lock);
92 hcon->sco_data = conn;
95 if (hdev->sco_mtu > 0)
96 conn->mtu = hdev->sco_mtu;
100 BT_DBG("hcon %p conn %p", hcon, conn);
105 static struct sock *sco_chan_get(struct sco_conn *conn)
107 struct sock *sk = NULL;
110 sco_conn_unlock(conn);
114 static int sco_conn_del(struct hci_conn *hcon, int err)
116 struct sco_conn *conn = hcon->sco_data;
122 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
125 sk = sco_chan_get(conn);
128 sco_sock_clear_timer(sk);
129 sco_chan_del(sk, err);
134 hcon->sco_data = NULL;
139 static int sco_chan_add(struct sco_conn *conn, struct sock *sk,
148 __sco_chan_add(conn, sk, parent);
150 sco_conn_unlock(conn);
154 static int sco_connect(struct sock *sk)
156 struct sco_conn *conn;
157 struct hci_conn *hcon;
158 struct hci_dev *hdev;
161 BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst);
163 hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src);
165 return -EHOSTUNREACH;
169 if (lmp_esco_capable(hdev) && !disable_esco)
174 if (sco_pi(sk)->setting == BT_VOICE_TRANSPARENT &&
175 (!lmp_transp_capable(hdev) || !lmp_esco_capable(hdev))) {
180 hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst,
181 sco_pi(sk)->setting);
187 conn = sco_conn_add(hcon);
194 /* Update source addr of the socket */
195 bacpy(&sco_pi(sk)->src, &hcon->src);
197 err = sco_chan_add(conn, sk, NULL);
201 if (hcon->state == BT_CONNECTED) {
202 sco_sock_clear_timer(sk);
203 sk->sk_state = BT_CONNECTED;
205 sk->sk_state = BT_CONNECT;
206 sco_sock_set_timer(sk, sk->sk_sndtimeo);
210 hci_dev_unlock(hdev);
215 static int sco_send_frame(struct sock *sk, struct msghdr *msg, int len)
217 struct sco_conn *conn = sco_pi(sk)->conn;
221 /* Check outgoing MTU */
225 BT_DBG("sk %p len %d", sk, len);
227 skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err);
231 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
236 hci_send_sco(conn->hcon, skb);
241 static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
243 struct sock *sk = sco_chan_get(conn);
248 BT_DBG("sk %p len %d", sk, skb->len);
250 if (sk->sk_state != BT_CONNECTED)
253 if (!sock_queue_rcv_skb(sk, skb))
260 /* -------- Socket interface ---------- */
261 static struct sock *__sco_get_sock_listen_by_addr(bdaddr_t *ba)
265 sk_for_each(sk, &sco_sk_list.head) {
266 if (sk->sk_state != BT_LISTEN)
269 if (!bacmp(&sco_pi(sk)->src, ba))
276 /* Find socket listening on source bdaddr.
277 * Returns closest match.
279 static struct sock *sco_get_sock_listen(bdaddr_t *src)
281 struct sock *sk = NULL, *sk1 = NULL;
283 read_lock(&sco_sk_list.lock);
285 sk_for_each(sk, &sco_sk_list.head) {
286 if (sk->sk_state != BT_LISTEN)
290 if (!bacmp(&sco_pi(sk)->src, src))
294 if (!bacmp(&sco_pi(sk)->src, BDADDR_ANY))
298 read_unlock(&sco_sk_list.lock);
300 return sk ? sk : sk1;
303 static void sco_sock_destruct(struct sock *sk)
307 skb_queue_purge(&sk->sk_receive_queue);
308 skb_queue_purge(&sk->sk_write_queue);
311 static void sco_sock_cleanup_listen(struct sock *parent)
315 BT_DBG("parent %p", parent);
317 /* Close not yet accepted channels */
318 while ((sk = bt_accept_dequeue(parent, NULL))) {
323 parent->sk_state = BT_CLOSED;
324 sock_set_flag(parent, SOCK_ZAPPED);
327 /* Kill socket (only if zapped and orphan)
328 * Must be called on unlocked socket.
330 static void sco_sock_kill(struct sock *sk)
332 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
335 BT_DBG("sk %p state %d", sk, sk->sk_state);
337 /* Kill poor orphan */
338 bt_sock_unlink(&sco_sk_list, sk);
339 sock_set_flag(sk, SOCK_DEAD);
343 static void __sco_sock_close(struct sock *sk)
345 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
347 switch (sk->sk_state) {
349 sco_sock_cleanup_listen(sk);
354 if (sco_pi(sk)->conn->hcon) {
355 sk->sk_state = BT_DISCONN;
356 sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT);
357 hci_conn_drop(sco_pi(sk)->conn->hcon);
358 sco_pi(sk)->conn->hcon = NULL;
360 sco_chan_del(sk, ECONNRESET);
366 sco_chan_del(sk, ECONNRESET);
370 sock_set_flag(sk, SOCK_ZAPPED);
375 /* Must be called on unlocked socket. */
376 static void sco_sock_close(struct sock *sk)
378 sco_sock_clear_timer(sk);
380 __sco_sock_close(sk);
385 static void sco_sock_init(struct sock *sk, struct sock *parent)
390 sk->sk_type = parent->sk_type;
391 bt_sk(sk)->flags = bt_sk(parent)->flags;
392 security_sk_clone(parent, sk);
396 static struct proto sco_proto = {
398 .owner = THIS_MODULE,
399 .obj_size = sizeof(struct sco_pinfo)
402 static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
406 sk = sk_alloc(net, PF_BLUETOOTH, prio, &sco_proto);
410 sock_init_data(sock, sk);
411 INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
413 sk->sk_destruct = sco_sock_destruct;
414 sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
416 sock_reset_flag(sk, SOCK_ZAPPED);
418 sk->sk_protocol = proto;
419 sk->sk_state = BT_OPEN;
421 sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT;
423 setup_timer(&sk->sk_timer, sco_sock_timeout, (unsigned long)sk);
425 bt_sock_link(&sco_sk_list, sk);
429 static int sco_sock_create(struct net *net, struct socket *sock, int protocol,
434 BT_DBG("sock %p", sock);
436 sock->state = SS_UNCONNECTED;
438 if (sock->type != SOCK_SEQPACKET)
439 return -ESOCKTNOSUPPORT;
441 sock->ops = &sco_sock_ops;
443 sk = sco_sock_alloc(net, sock, protocol, GFP_ATOMIC);
447 sco_sock_init(sk, NULL);
451 static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
453 struct sockaddr_sco *sa = (struct sockaddr_sco *) addr;
454 struct sock *sk = sock->sk;
457 BT_DBG("sk %p %pMR", sk, &sa->sco_bdaddr);
459 if (!addr || addr->sa_family != AF_BLUETOOTH)
464 if (sk->sk_state != BT_OPEN) {
469 if (sk->sk_type != SOCK_SEQPACKET) {
474 bacpy(&sco_pi(sk)->src, &sa->sco_bdaddr);
476 sk->sk_state = BT_BOUND;
483 static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags)
485 struct sockaddr_sco *sa = (struct sockaddr_sco *) addr;
486 struct sock *sk = sock->sk;
491 if (alen < sizeof(struct sockaddr_sco) ||
492 addr->sa_family != AF_BLUETOOTH)
495 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
498 if (sk->sk_type != SOCK_SEQPACKET)
503 /* Set destination address and psm */
504 bacpy(&sco_pi(sk)->dst, &sa->sco_bdaddr);
506 err = sco_connect(sk);
510 err = bt_sock_wait_state(sk, BT_CONNECTED,
511 sock_sndtimeo(sk, flags & O_NONBLOCK));
518 static int sco_sock_listen(struct socket *sock, int backlog)
520 struct sock *sk = sock->sk;
521 bdaddr_t *src = &sco_pi(sk)->src;
524 BT_DBG("sk %p backlog %d", sk, backlog);
528 if (sk->sk_state != BT_BOUND) {
533 if (sk->sk_type != SOCK_SEQPACKET) {
538 write_lock(&sco_sk_list.lock);
540 if (__sco_get_sock_listen_by_addr(src)) {
545 sk->sk_max_ack_backlog = backlog;
546 sk->sk_ack_backlog = 0;
548 sk->sk_state = BT_LISTEN;
551 write_unlock(&sco_sk_list.lock);
558 static int sco_sock_accept(struct socket *sock, struct socket *newsock, int flags)
560 DECLARE_WAITQUEUE(wait, current);
561 struct sock *sk = sock->sk, *ch;
567 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
569 BT_DBG("sk %p timeo %ld", sk, timeo);
571 /* Wait for an incoming connection. (wake-one). */
572 add_wait_queue_exclusive(sk_sleep(sk), &wait);
574 set_current_state(TASK_INTERRUPTIBLE);
576 if (sk->sk_state != BT_LISTEN) {
581 ch = bt_accept_dequeue(sk, newsock);
590 if (signal_pending(current)) {
591 err = sock_intr_errno(timeo);
596 timeo = schedule_timeout(timeo);
599 __set_current_state(TASK_RUNNING);
600 remove_wait_queue(sk_sleep(sk), &wait);
605 newsock->state = SS_CONNECTED;
607 BT_DBG("new socket %p", ch);
614 static int sco_sock_getname(struct socket *sock, struct sockaddr *addr, int *len, int peer)
616 struct sockaddr_sco *sa = (struct sockaddr_sco *) addr;
617 struct sock *sk = sock->sk;
619 BT_DBG("sock %p, sk %p", sock, sk);
621 addr->sa_family = AF_BLUETOOTH;
622 *len = sizeof(struct sockaddr_sco);
625 bacpy(&sa->sco_bdaddr, &sco_pi(sk)->dst);
627 bacpy(&sa->sco_bdaddr, &sco_pi(sk)->src);
632 static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
633 struct msghdr *msg, size_t len)
635 struct sock *sk = sock->sk;
638 BT_DBG("sock %p, sk %p", sock, sk);
640 err = sock_error(sk);
644 if (msg->msg_flags & MSG_OOB)
649 if (sk->sk_state == BT_CONNECTED)
650 err = sco_send_frame(sk, msg, len);
658 static void sco_conn_defer_accept(struct hci_conn *conn, u16 setting)
660 struct hci_dev *hdev = conn->hdev;
662 BT_DBG("conn %p", conn);
664 conn->state = BT_CONFIG;
666 if (!lmp_esco_capable(hdev)) {
667 struct hci_cp_accept_conn_req cp;
669 bacpy(&cp.bdaddr, &conn->dst);
670 cp.role = 0x00; /* Ignored */
672 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
674 struct hci_cp_accept_sync_conn_req cp;
676 bacpy(&cp.bdaddr, &conn->dst);
677 cp.pkt_type = cpu_to_le16(conn->pkt_type);
679 cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
680 cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
681 cp.content_format = cpu_to_le16(setting);
683 switch (setting & SCO_AIRMODE_MASK) {
684 case SCO_AIRMODE_TRANSP:
685 if (conn->pkt_type & ESCO_2EV3)
686 cp.max_latency = __constant_cpu_to_le16(0x0008);
688 cp.max_latency = __constant_cpu_to_le16(0x000D);
689 cp.retrans_effort = 0x02;
691 case SCO_AIRMODE_CVSD:
692 cp.max_latency = __constant_cpu_to_le16(0xffff);
693 cp.retrans_effort = 0xff;
697 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
702 static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
703 struct msghdr *msg, size_t len, int flags)
705 struct sock *sk = sock->sk;
706 struct sco_pinfo *pi = sco_pi(sk);
710 if (sk->sk_state == BT_CONNECT2 &&
711 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
712 sco_conn_defer_accept(pi->conn->hcon, pi->setting);
713 sk->sk_state = BT_CONFIG;
714 msg->msg_namelen = 0;
722 return bt_sock_recvmsg(iocb, sock, msg, len, flags);
725 static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
727 struct sock *sk = sock->sk;
729 struct bt_voice voice;
739 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
744 if (get_user(opt, (u32 __user *) optval)) {
750 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
752 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
756 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
757 sk->sk_state != BT_CONNECT2) {
762 voice.setting = sco_pi(sk)->setting;
764 len = min_t(unsigned int, sizeof(voice), optlen);
765 if (copy_from_user((char *) &voice, optval, len)) {
770 /* Explicitly check for these values */
771 if (voice.setting != BT_VOICE_TRANSPARENT &&
772 voice.setting != BT_VOICE_CVSD_16BIT) {
777 sco_pi(sk)->setting = voice.setting;
789 static int sco_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen)
791 struct sock *sk = sock->sk;
792 struct sco_options opts;
793 struct sco_conninfo cinfo;
798 if (get_user(len, optlen))
805 if (sk->sk_state != BT_CONNECTED &&
806 !(sk->sk_state == BT_CONNECT2 &&
807 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) {
812 opts.mtu = sco_pi(sk)->conn->mtu;
814 BT_DBG("mtu %d", opts.mtu);
816 len = min_t(unsigned int, len, sizeof(opts));
817 if (copy_to_user(optval, (char *)&opts, len))
823 if (sk->sk_state != BT_CONNECTED &&
824 !(sk->sk_state == BT_CONNECT2 &&
825 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) {
830 memset(&cinfo, 0, sizeof(cinfo));
831 cinfo.hci_handle = sco_pi(sk)->conn->hcon->handle;
832 memcpy(cinfo.dev_class, sco_pi(sk)->conn->hcon->dev_class, 3);
834 len = min_t(unsigned int, len, sizeof(cinfo));
835 if (copy_to_user(optval, (char *)&cinfo, len))
849 static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen)
851 struct sock *sk = sock->sk;
853 struct bt_voice voice;
857 if (level == SOL_SCO)
858 return sco_sock_getsockopt_old(sock, optname, optval, optlen);
860 if (get_user(len, optlen))
868 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
873 if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags),
874 (u32 __user *) optval))
880 voice.setting = sco_pi(sk)->setting;
882 len = min_t(unsigned int, len, sizeof(voice));
883 if (copy_to_user(optval, (char *)&voice, len))
897 static int sco_sock_shutdown(struct socket *sock, int how)
899 struct sock *sk = sock->sk;
902 BT_DBG("sock %p, sk %p", sock, sk);
908 if (!sk->sk_shutdown) {
909 sk->sk_shutdown = SHUTDOWN_MASK;
910 sco_sock_clear_timer(sk);
911 __sco_sock_close(sk);
913 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
914 err = bt_sock_wait_state(sk, BT_CLOSED,
921 static int sco_sock_release(struct socket *sock)
923 struct sock *sk = sock->sk;
926 BT_DBG("sock %p, sk %p", sock, sk);
933 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) {
935 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
944 static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent)
946 BT_DBG("conn %p", conn);
948 sco_pi(sk)->conn = conn;
952 bt_accept_enqueue(parent, sk);
956 * Must be called on the locked socket. */
957 static void sco_chan_del(struct sock *sk, int err)
959 struct sco_conn *conn;
961 conn = sco_pi(sk)->conn;
963 BT_DBG("sk %p, conn %p, err %d", sk, conn, err);
968 sco_pi(sk)->conn = NULL;
969 sco_conn_unlock(conn);
972 hci_conn_drop(conn->hcon);
975 sk->sk_state = BT_CLOSED;
977 sk->sk_state_change(sk);
979 sock_set_flag(sk, SOCK_ZAPPED);
982 static void sco_conn_ready(struct sco_conn *conn)
985 struct sock *sk = conn->sk;
987 BT_DBG("conn %p", conn);
990 sco_sock_clear_timer(sk);
992 sk->sk_state = BT_CONNECTED;
993 sk->sk_state_change(sk);
998 parent = sco_get_sock_listen(&conn->hcon->src);
1000 sco_conn_unlock(conn);
1004 bh_lock_sock(parent);
1006 sk = sco_sock_alloc(sock_net(parent), NULL,
1007 BTPROTO_SCO, GFP_ATOMIC);
1009 bh_unlock_sock(parent);
1010 sco_conn_unlock(conn);
1014 sco_sock_init(sk, parent);
1016 bacpy(&sco_pi(sk)->src, &conn->hcon->src);
1017 bacpy(&sco_pi(sk)->dst, &conn->hcon->dst);
1019 hci_conn_hold(conn->hcon);
1020 __sco_chan_add(conn, sk, parent);
1022 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
1023 sk->sk_state = BT_CONNECT2;
1025 sk->sk_state = BT_CONNECTED;
1027 /* Wake up parent */
1028 parent->sk_data_ready(parent, 1);
1030 bh_unlock_sock(parent);
1032 sco_conn_unlock(conn);
1036 /* ----- SCO interface with lower layer (HCI) ----- */
1037 int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
1042 BT_DBG("hdev %s, bdaddr %pMR", hdev->name, bdaddr);
1044 /* Find listening sockets */
1045 read_lock(&sco_sk_list.lock);
1046 sk_for_each(sk, &sco_sk_list.head) {
1047 if (sk->sk_state != BT_LISTEN)
1050 if (!bacmp(&sco_pi(sk)->src, &hdev->bdaddr) ||
1051 !bacmp(&sco_pi(sk)->src, BDADDR_ANY)) {
1052 lm |= HCI_LM_ACCEPT;
1054 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))
1055 *flags |= HCI_PROTO_DEFER;
1059 read_unlock(&sco_sk_list.lock);
1064 void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
1066 BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
1068 struct sco_conn *conn;
1070 conn = sco_conn_add(hcon);
1072 sco_conn_ready(conn);
1074 sco_conn_del(hcon, bt_to_errno(status));
1077 void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
1079 BT_DBG("hcon %p reason %d", hcon, reason);
1081 sco_conn_del(hcon, bt_to_errno(reason));
1084 int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
1086 struct sco_conn *conn = hcon->sco_data;
1091 BT_DBG("conn %p len %d", conn, skb->len);
1094 sco_recv_frame(conn, skb);
1103 static int sco_debugfs_show(struct seq_file *f, void *p)
1107 read_lock(&sco_sk_list.lock);
1109 sk_for_each(sk, &sco_sk_list.head) {
1110 seq_printf(f, "%pMR %pMR %d\n", &sco_pi(sk)->src,
1111 &sco_pi(sk)->dst, sk->sk_state);
1114 read_unlock(&sco_sk_list.lock);
1119 static int sco_debugfs_open(struct inode *inode, struct file *file)
1121 return single_open(file, sco_debugfs_show, inode->i_private);
1124 static const struct file_operations sco_debugfs_fops = {
1125 .open = sco_debugfs_open,
1127 .llseek = seq_lseek,
1128 .release = single_release,
1131 static struct dentry *sco_debugfs;
1133 static const struct proto_ops sco_sock_ops = {
1134 .family = PF_BLUETOOTH,
1135 .owner = THIS_MODULE,
1136 .release = sco_sock_release,
1137 .bind = sco_sock_bind,
1138 .connect = sco_sock_connect,
1139 .listen = sco_sock_listen,
1140 .accept = sco_sock_accept,
1141 .getname = sco_sock_getname,
1142 .sendmsg = sco_sock_sendmsg,
1143 .recvmsg = sco_sock_recvmsg,
1144 .poll = bt_sock_poll,
1145 .ioctl = bt_sock_ioctl,
1146 .mmap = sock_no_mmap,
1147 .socketpair = sock_no_socketpair,
1148 .shutdown = sco_sock_shutdown,
1149 .setsockopt = sco_sock_setsockopt,
1150 .getsockopt = sco_sock_getsockopt
1153 static const struct net_proto_family sco_sock_family_ops = {
1154 .family = PF_BLUETOOTH,
1155 .owner = THIS_MODULE,
1156 .create = sco_sock_create,
1159 int __init sco_init(void)
1163 err = proto_register(&sco_proto, 0);
1167 err = bt_sock_register(BTPROTO_SCO, &sco_sock_family_ops);
1169 BT_ERR("SCO socket registration failed");
1173 err = bt_procfs_init(&init_net, "sco", &sco_sk_list, NULL);
1175 BT_ERR("Failed to create SCO proc file");
1176 bt_sock_unregister(BTPROTO_SCO);
1180 BT_INFO("SCO socket layer initialized");
1182 if (IS_ERR_OR_NULL(bt_debugfs))
1185 sco_debugfs = debugfs_create_file("sco", 0444, bt_debugfs,
1186 NULL, &sco_debugfs_fops);
1191 proto_unregister(&sco_proto);
1195 void __exit sco_exit(void)
1197 bt_procfs_cleanup(&init_net, "sco");
1199 debugfs_remove(sco_debugfs);
1201 bt_sock_unregister(BTPROTO_SCO);
1203 proto_unregister(&sco_proto);
1206 module_param(disable_esco, bool, 0644);
1207 MODULE_PARM_DESC(disable_esco, "Disable eSCO connection creation");