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>
30 #include <linux/sched/signal.h>
32 #include <net/bluetooth/bluetooth.h>
33 #include <net/bluetooth/hci_core.h>
34 #include <net/bluetooth/sco.h>
36 static bool disable_esco;
38 static const struct proto_ops sco_sock_ops;
40 static struct bt_sock_list sco_sk_list = {
41 .lock = __RW_LOCK_UNLOCKED(sco_sk_list.lock)
44 /* ---- SCO connections ---- */
46 struct hci_conn *hcon;
54 #define sco_conn_lock(c) spin_lock(&c->lock);
55 #define sco_conn_unlock(c) spin_unlock(&c->lock);
57 static void sco_sock_close(struct sock *sk);
58 static void sco_sock_kill(struct sock *sk);
60 /* ----- SCO socket info ----- */
61 #define sco_pi(sk) ((struct sco_pinfo *) sk)
69 struct sco_conn *conn;
72 /* ---- SCO timers ---- */
73 #define SCO_CONN_TIMEOUT (HZ * 40)
74 #define SCO_DISCONN_TIMEOUT (HZ * 2)
76 static void sco_sock_timeout(struct timer_list *t)
78 struct sock *sk = from_timer(sk, t, sk_timer);
80 BT_DBG("sock %p state %d", sk, sk->sk_state);
83 sk->sk_err = ETIMEDOUT;
84 sk->sk_state_change(sk);
91 static void sco_sock_set_timer(struct sock *sk, long timeout)
93 BT_DBG("sock %p state %d timeout %ld", sk, sk->sk_state, timeout);
94 sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout);
97 static void sco_sock_clear_timer(struct sock *sk)
99 BT_DBG("sock %p state %d", sk, sk->sk_state);
100 sk_stop_timer(sk, &sk->sk_timer);
103 /* ---- SCO connections ---- */
104 static struct sco_conn *sco_conn_add(struct hci_conn *hcon)
106 struct hci_dev *hdev = hcon->hdev;
107 struct sco_conn *conn = hcon->sco_data;
112 conn = kzalloc(sizeof(struct sco_conn), GFP_KERNEL);
116 spin_lock_init(&conn->lock);
118 hcon->sco_data = conn;
121 if (hdev->sco_mtu > 0)
122 conn->mtu = hdev->sco_mtu;
126 BT_DBG("hcon %p conn %p", hcon, conn);
132 * Must be called on the locked socket. */
133 static void sco_chan_del(struct sock *sk, int err)
135 struct sco_conn *conn;
137 conn = sco_pi(sk)->conn;
139 BT_DBG("sk %p, conn %p, err %d", sk, conn, err);
144 sco_pi(sk)->conn = NULL;
145 sco_conn_unlock(conn);
148 hci_conn_drop(conn->hcon);
151 sk->sk_state = BT_CLOSED;
153 sk->sk_state_change(sk);
155 sock_set_flag(sk, SOCK_ZAPPED);
158 static void sco_conn_del(struct hci_conn *hcon, int err)
160 struct sco_conn *conn = hcon->sco_data;
166 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
171 sco_conn_unlock(conn);
176 sco_sock_clear_timer(sk);
177 sco_chan_del(sk, err);
183 hcon->sco_data = NULL;
187 static void __sco_chan_add(struct sco_conn *conn, struct sock *sk,
190 BT_DBG("conn %p", conn);
192 sco_pi(sk)->conn = conn;
196 bt_accept_enqueue(parent, sk, true);
199 static int sco_chan_add(struct sco_conn *conn, struct sock *sk,
208 __sco_chan_add(conn, sk, parent);
210 sco_conn_unlock(conn);
214 static int sco_connect(struct sock *sk)
216 struct sco_conn *conn;
217 struct hci_conn *hcon;
218 struct hci_dev *hdev;
221 BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst);
223 hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src, BDADDR_BREDR);
225 return -EHOSTUNREACH;
229 if (lmp_esco_capable(hdev) && !disable_esco)
234 if (sco_pi(sk)->setting == BT_VOICE_TRANSPARENT &&
235 (!lmp_transp_capable(hdev) || !lmp_esco_capable(hdev))) {
240 hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst,
241 sco_pi(sk)->setting);
247 conn = sco_conn_add(hcon);
254 /* Update source addr of the socket */
255 bacpy(&sco_pi(sk)->src, &hcon->src);
257 err = sco_chan_add(conn, sk, NULL);
261 if (hcon->state == BT_CONNECTED) {
262 sco_sock_clear_timer(sk);
263 sk->sk_state = BT_CONNECTED;
265 sk->sk_state = BT_CONNECT;
266 sco_sock_set_timer(sk, sk->sk_sndtimeo);
270 hci_dev_unlock(hdev);
275 static int sco_send_frame(struct sock *sk, struct msghdr *msg, int len)
277 struct sco_conn *conn = sco_pi(sk)->conn;
281 /* Check outgoing MTU */
285 BT_DBG("sk %p len %d", sk, len);
287 skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err);
291 if (memcpy_from_msg(skb_put(skb, len), msg, len)) {
296 hci_send_sco(conn->hcon, skb);
301 static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
307 sco_conn_unlock(conn);
312 BT_DBG("sk %p len %d", sk, skb->len);
314 if (sk->sk_state != BT_CONNECTED)
317 if (!sock_queue_rcv_skb(sk, skb))
324 /* -------- Socket interface ---------- */
325 static struct sock *__sco_get_sock_listen_by_addr(bdaddr_t *ba)
329 sk_for_each(sk, &sco_sk_list.head) {
330 if (sk->sk_state != BT_LISTEN)
333 if (!bacmp(&sco_pi(sk)->src, ba))
340 /* Find socket listening on source bdaddr.
341 * Returns closest match.
343 static struct sock *sco_get_sock_listen(bdaddr_t *src)
345 struct sock *sk = NULL, *sk1 = NULL;
347 read_lock(&sco_sk_list.lock);
349 sk_for_each(sk, &sco_sk_list.head) {
350 if (sk->sk_state != BT_LISTEN)
354 if (!bacmp(&sco_pi(sk)->src, src))
358 if (!bacmp(&sco_pi(sk)->src, BDADDR_ANY))
362 read_unlock(&sco_sk_list.lock);
364 return sk ? sk : sk1;
367 static void sco_sock_destruct(struct sock *sk)
371 skb_queue_purge(&sk->sk_receive_queue);
372 skb_queue_purge(&sk->sk_write_queue);
375 static void sco_sock_cleanup_listen(struct sock *parent)
379 BT_DBG("parent %p", parent);
381 /* Close not yet accepted channels */
382 while ((sk = bt_accept_dequeue(parent, NULL))) {
387 parent->sk_state = BT_CLOSED;
388 sock_set_flag(parent, SOCK_ZAPPED);
391 /* Kill socket (only if zapped and orphan)
392 * Must be called on unlocked socket.
394 static void sco_sock_kill(struct sock *sk)
396 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket ||
397 sock_flag(sk, SOCK_DEAD))
400 BT_DBG("sk %p state %d", sk, sk->sk_state);
402 /* Kill poor orphan */
403 bt_sock_unlink(&sco_sk_list, sk);
404 sock_set_flag(sk, SOCK_DEAD);
408 static void __sco_sock_close(struct sock *sk)
410 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
412 switch (sk->sk_state) {
414 sco_sock_cleanup_listen(sk);
419 if (sco_pi(sk)->conn->hcon) {
420 sk->sk_state = BT_DISCONN;
421 sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT);
422 sco_conn_lock(sco_pi(sk)->conn);
423 hci_conn_drop(sco_pi(sk)->conn->hcon);
424 sco_pi(sk)->conn->hcon = NULL;
425 sco_conn_unlock(sco_pi(sk)->conn);
427 sco_chan_del(sk, ECONNRESET);
433 sco_chan_del(sk, ECONNRESET);
437 sock_set_flag(sk, SOCK_ZAPPED);
442 /* Must be called on unlocked socket. */
443 static void sco_sock_close(struct sock *sk)
445 sco_sock_clear_timer(sk);
447 __sco_sock_close(sk);
452 static void sco_sock_init(struct sock *sk, struct sock *parent)
457 sk->sk_type = parent->sk_type;
458 bt_sk(sk)->flags = bt_sk(parent)->flags;
459 security_sk_clone(parent, sk);
463 static struct proto sco_proto = {
465 .owner = THIS_MODULE,
466 .obj_size = sizeof(struct sco_pinfo)
469 static struct sock *sco_sock_alloc(struct net *net, struct socket *sock,
470 int proto, gfp_t prio, int kern)
474 sk = sk_alloc(net, PF_BLUETOOTH, prio, &sco_proto, kern);
478 sock_init_data(sock, sk);
479 INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
481 sk->sk_destruct = sco_sock_destruct;
482 sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
484 sock_reset_flag(sk, SOCK_ZAPPED);
486 sk->sk_protocol = proto;
487 sk->sk_state = BT_OPEN;
489 sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT;
491 timer_setup(&sk->sk_timer, sco_sock_timeout, 0);
493 bt_sock_link(&sco_sk_list, sk);
497 static int sco_sock_create(struct net *net, struct socket *sock, int protocol,
502 BT_DBG("sock %p", sock);
504 sock->state = SS_UNCONNECTED;
506 if (sock->type != SOCK_SEQPACKET)
507 return -ESOCKTNOSUPPORT;
509 sock->ops = &sco_sock_ops;
511 sk = sco_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern);
515 sco_sock_init(sk, NULL);
519 static int sco_sock_bind(struct socket *sock, struct sockaddr *addr,
522 struct sockaddr_sco *sa = (struct sockaddr_sco *) addr;
523 struct sock *sk = sock->sk;
526 if (!addr || addr_len < sizeof(struct sockaddr_sco) ||
527 addr->sa_family != AF_BLUETOOTH)
530 BT_DBG("sk %p %pMR", sk, &sa->sco_bdaddr);
534 if (sk->sk_state != BT_OPEN) {
539 if (sk->sk_type != SOCK_SEQPACKET) {
544 bacpy(&sco_pi(sk)->src, &sa->sco_bdaddr);
546 sk->sk_state = BT_BOUND;
553 static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags)
555 struct sockaddr_sco *sa = (struct sockaddr_sco *) addr;
556 struct sock *sk = sock->sk;
561 if (alen < sizeof(struct sockaddr_sco) ||
562 addr->sa_family != AF_BLUETOOTH)
565 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
568 if (sk->sk_type != SOCK_SEQPACKET)
573 /* Set destination address and psm */
574 bacpy(&sco_pi(sk)->dst, &sa->sco_bdaddr);
576 err = sco_connect(sk);
580 err = bt_sock_wait_state(sk, BT_CONNECTED,
581 sock_sndtimeo(sk, flags & O_NONBLOCK));
588 static int sco_sock_listen(struct socket *sock, int backlog)
590 struct sock *sk = sock->sk;
591 bdaddr_t *src = &sco_pi(sk)->src;
594 BT_DBG("sk %p backlog %d", sk, backlog);
598 if (sk->sk_state != BT_BOUND) {
603 if (sk->sk_type != SOCK_SEQPACKET) {
608 write_lock(&sco_sk_list.lock);
610 if (__sco_get_sock_listen_by_addr(src)) {
615 sk->sk_max_ack_backlog = backlog;
616 sk->sk_ack_backlog = 0;
618 sk->sk_state = BT_LISTEN;
621 write_unlock(&sco_sk_list.lock);
628 static int sco_sock_accept(struct socket *sock, struct socket *newsock,
629 int flags, bool kern)
631 DEFINE_WAIT_FUNC(wait, woken_wake_function);
632 struct sock *sk = sock->sk, *ch;
638 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
640 BT_DBG("sk %p timeo %ld", sk, timeo);
642 /* Wait for an incoming connection. (wake-one). */
643 add_wait_queue_exclusive(sk_sleep(sk), &wait);
645 if (sk->sk_state != BT_LISTEN) {
650 ch = bt_accept_dequeue(sk, newsock);
659 if (signal_pending(current)) {
660 err = sock_intr_errno(timeo);
666 timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo);
669 remove_wait_queue(sk_sleep(sk), &wait);
674 newsock->state = SS_CONNECTED;
676 BT_DBG("new socket %p", ch);
683 static int sco_sock_getname(struct socket *sock, struct sockaddr *addr,
686 struct sockaddr_sco *sa = (struct sockaddr_sco *) addr;
687 struct sock *sk = sock->sk;
689 BT_DBG("sock %p, sk %p", sock, sk);
691 addr->sa_family = AF_BLUETOOTH;
694 bacpy(&sa->sco_bdaddr, &sco_pi(sk)->dst);
696 bacpy(&sa->sco_bdaddr, &sco_pi(sk)->src);
698 return sizeof(struct sockaddr_sco);
701 static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg,
704 struct sock *sk = sock->sk;
707 BT_DBG("sock %p, sk %p", sock, sk);
709 err = sock_error(sk);
713 if (msg->msg_flags & MSG_OOB)
718 if (sk->sk_state == BT_CONNECTED)
719 err = sco_send_frame(sk, msg, len);
727 static void sco_conn_defer_accept(struct hci_conn *conn, u16 setting)
729 struct hci_dev *hdev = conn->hdev;
731 BT_DBG("conn %p", conn);
733 conn->state = BT_CONFIG;
735 if (!lmp_esco_capable(hdev)) {
736 struct hci_cp_accept_conn_req cp;
738 bacpy(&cp.bdaddr, &conn->dst);
739 cp.role = 0x00; /* Ignored */
741 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
743 struct hci_cp_accept_sync_conn_req cp;
745 bacpy(&cp.bdaddr, &conn->dst);
746 cp.pkt_type = cpu_to_le16(conn->pkt_type);
748 cp.tx_bandwidth = cpu_to_le32(0x00001f40);
749 cp.rx_bandwidth = cpu_to_le32(0x00001f40);
750 cp.content_format = cpu_to_le16(setting);
752 switch (setting & SCO_AIRMODE_MASK) {
753 case SCO_AIRMODE_TRANSP:
754 if (conn->pkt_type & ESCO_2EV3)
755 cp.max_latency = cpu_to_le16(0x0008);
757 cp.max_latency = cpu_to_le16(0x000D);
758 cp.retrans_effort = 0x02;
760 case SCO_AIRMODE_CVSD:
761 cp.max_latency = cpu_to_le16(0xffff);
762 cp.retrans_effort = 0xff;
766 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
771 static int sco_sock_recvmsg(struct socket *sock, struct msghdr *msg,
772 size_t len, int flags)
774 struct sock *sk = sock->sk;
775 struct sco_pinfo *pi = sco_pi(sk);
779 if (sk->sk_state == BT_CONNECT2 &&
780 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
781 sco_conn_defer_accept(pi->conn->hcon, pi->setting);
782 sk->sk_state = BT_CONFIG;
790 return bt_sock_recvmsg(sock, msg, len, flags);
793 static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
794 char __user *optval, unsigned int optlen)
796 struct sock *sk = sock->sk;
798 struct bt_voice voice;
808 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
813 if (get_user(opt, (u32 __user *) optval)) {
819 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
821 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
825 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
826 sk->sk_state != BT_CONNECT2) {
831 voice.setting = sco_pi(sk)->setting;
833 len = min_t(unsigned int, sizeof(voice), optlen);
834 if (copy_from_user((char *)&voice, optval, len)) {
839 /* Explicitly check for these values */
840 if (voice.setting != BT_VOICE_TRANSPARENT &&
841 voice.setting != BT_VOICE_CVSD_16BIT) {
846 sco_pi(sk)->setting = voice.setting;
858 static int sco_sock_getsockopt_old(struct socket *sock, int optname,
859 char __user *optval, int __user *optlen)
861 struct sock *sk = sock->sk;
862 struct sco_options opts;
863 struct sco_conninfo cinfo;
868 if (get_user(len, optlen))
875 if (sk->sk_state != BT_CONNECTED &&
876 !(sk->sk_state == BT_CONNECT2 &&
877 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) {
882 opts.mtu = sco_pi(sk)->conn->mtu;
884 BT_DBG("mtu %d", opts.mtu);
886 len = min_t(unsigned int, len, sizeof(opts));
887 if (copy_to_user(optval, (char *)&opts, len))
893 if (sk->sk_state != BT_CONNECTED &&
894 !(sk->sk_state == BT_CONNECT2 &&
895 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) {
900 memset(&cinfo, 0, sizeof(cinfo));
901 cinfo.hci_handle = sco_pi(sk)->conn->hcon->handle;
902 memcpy(cinfo.dev_class, sco_pi(sk)->conn->hcon->dev_class, 3);
904 len = min_t(unsigned int, len, sizeof(cinfo));
905 if (copy_to_user(optval, (char *)&cinfo, len))
919 static int sco_sock_getsockopt(struct socket *sock, int level, int optname,
920 char __user *optval, int __user *optlen)
922 struct sock *sk = sock->sk;
924 struct bt_voice voice;
928 if (level == SOL_SCO)
929 return sco_sock_getsockopt_old(sock, optname, optval, optlen);
931 if (get_user(len, optlen))
939 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
944 if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags),
945 (u32 __user *)optval))
951 voice.setting = sco_pi(sk)->setting;
953 len = min_t(unsigned int, len, sizeof(voice));
954 if (copy_to_user(optval, (char *)&voice, len))
968 static int sco_sock_shutdown(struct socket *sock, int how)
970 struct sock *sk = sock->sk;
973 BT_DBG("sock %p, sk %p", sock, sk);
981 if (!sk->sk_shutdown) {
982 sk->sk_shutdown = SHUTDOWN_MASK;
983 sco_sock_clear_timer(sk);
984 __sco_sock_close(sk);
986 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
987 !(current->flags & PF_EXITING))
988 err = bt_sock_wait_state(sk, BT_CLOSED,
998 static int sco_sock_release(struct socket *sock)
1000 struct sock *sk = sock->sk;
1003 BT_DBG("sock %p, sk %p", sock, sk);
1010 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
1011 !(current->flags & PF_EXITING)) {
1013 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
1022 static void sco_conn_ready(struct sco_conn *conn)
1024 struct sock *parent;
1025 struct sock *sk = conn->sk;
1027 BT_DBG("conn %p", conn);
1030 sco_sock_clear_timer(sk);
1032 sk->sk_state = BT_CONNECTED;
1033 sk->sk_state_change(sk);
1036 sco_conn_lock(conn);
1039 sco_conn_unlock(conn);
1043 parent = sco_get_sock_listen(&conn->hcon->src);
1045 sco_conn_unlock(conn);
1049 bh_lock_sock(parent);
1051 sk = sco_sock_alloc(sock_net(parent), NULL,
1052 BTPROTO_SCO, GFP_ATOMIC, 0);
1054 bh_unlock_sock(parent);
1055 sco_conn_unlock(conn);
1059 sco_sock_init(sk, parent);
1061 bacpy(&sco_pi(sk)->src, &conn->hcon->src);
1062 bacpy(&sco_pi(sk)->dst, &conn->hcon->dst);
1064 hci_conn_hold(conn->hcon);
1065 __sco_chan_add(conn, sk, parent);
1067 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
1068 sk->sk_state = BT_CONNECT2;
1070 sk->sk_state = BT_CONNECTED;
1072 /* Wake up parent */
1073 parent->sk_data_ready(parent);
1075 bh_unlock_sock(parent);
1077 sco_conn_unlock(conn);
1081 /* ----- SCO interface with lower layer (HCI) ----- */
1082 int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
1087 BT_DBG("hdev %s, bdaddr %pMR", hdev->name, bdaddr);
1089 /* Find listening sockets */
1090 read_lock(&sco_sk_list.lock);
1091 sk_for_each(sk, &sco_sk_list.head) {
1092 if (sk->sk_state != BT_LISTEN)
1095 if (!bacmp(&sco_pi(sk)->src, &hdev->bdaddr) ||
1096 !bacmp(&sco_pi(sk)->src, BDADDR_ANY)) {
1097 lm |= HCI_LM_ACCEPT;
1099 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))
1100 *flags |= HCI_PROTO_DEFER;
1104 read_unlock(&sco_sk_list.lock);
1109 static void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
1111 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
1114 BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
1117 struct sco_conn *conn;
1119 conn = sco_conn_add(hcon);
1121 sco_conn_ready(conn);
1123 sco_conn_del(hcon, bt_to_errno(status));
1126 static void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
1128 if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
1131 BT_DBG("hcon %p reason %d", hcon, reason);
1133 sco_conn_del(hcon, bt_to_errno(reason));
1136 void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
1138 struct sco_conn *conn = hcon->sco_data;
1143 BT_DBG("conn %p len %d", conn, skb->len);
1146 sco_recv_frame(conn, skb);
1154 static struct hci_cb sco_cb = {
1156 .connect_cfm = sco_connect_cfm,
1157 .disconn_cfm = sco_disconn_cfm,
1160 static int sco_debugfs_show(struct seq_file *f, void *p)
1164 read_lock(&sco_sk_list.lock);
1166 sk_for_each(sk, &sco_sk_list.head) {
1167 seq_printf(f, "%pMR %pMR %d\n", &sco_pi(sk)->src,
1168 &sco_pi(sk)->dst, sk->sk_state);
1171 read_unlock(&sco_sk_list.lock);
1176 DEFINE_SHOW_ATTRIBUTE(sco_debugfs);
1178 static struct dentry *sco_debugfs;
1180 static const struct proto_ops sco_sock_ops = {
1181 .family = PF_BLUETOOTH,
1182 .owner = THIS_MODULE,
1183 .release = sco_sock_release,
1184 .bind = sco_sock_bind,
1185 .connect = sco_sock_connect,
1186 .listen = sco_sock_listen,
1187 .accept = sco_sock_accept,
1188 .getname = sco_sock_getname,
1189 .sendmsg = sco_sock_sendmsg,
1190 .recvmsg = sco_sock_recvmsg,
1191 .poll = bt_sock_poll,
1192 .ioctl = bt_sock_ioctl,
1193 .gettstamp = sock_gettstamp,
1194 .mmap = sock_no_mmap,
1195 .socketpair = sock_no_socketpair,
1196 .shutdown = sco_sock_shutdown,
1197 .setsockopt = sco_sock_setsockopt,
1198 .getsockopt = sco_sock_getsockopt
1201 static const struct net_proto_family sco_sock_family_ops = {
1202 .family = PF_BLUETOOTH,
1203 .owner = THIS_MODULE,
1204 .create = sco_sock_create,
1207 int __init sco_init(void)
1211 BUILD_BUG_ON(sizeof(struct sockaddr_sco) > sizeof(struct sockaddr));
1213 err = proto_register(&sco_proto, 0);
1217 err = bt_sock_register(BTPROTO_SCO, &sco_sock_family_ops);
1219 BT_ERR("SCO socket registration failed");
1223 err = bt_procfs_init(&init_net, "sco", &sco_sk_list, NULL);
1225 BT_ERR("Failed to create SCO proc file");
1226 bt_sock_unregister(BTPROTO_SCO);
1230 BT_INFO("SCO socket layer initialized");
1232 hci_register_cb(&sco_cb);
1234 if (IS_ERR_OR_NULL(bt_debugfs))
1237 sco_debugfs = debugfs_create_file("sco", 0444, bt_debugfs,
1238 NULL, &sco_debugfs_fops);
1243 proto_unregister(&sco_proto);
1249 bt_procfs_cleanup(&init_net, "sco");
1251 debugfs_remove(sco_debugfs);
1253 hci_unregister_cb(&sco_cb);
1255 bt_sock_unregister(BTPROTO_SCO);
1257 proto_unregister(&sco_proto);
1260 module_param(disable_esco, bool, 0644);
1261 MODULE_PARM_DESC(disable_esco, "Disable eSCO connection creation");