1 // SPDX-License-Identifier: GPL-2.0
3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2022 Intel Corporation
9 #include <linux/module.h>
10 #include <linux/debugfs.h>
11 #include <linux/seq_file.h>
12 #include <linux/sched/signal.h>
14 #include <net/bluetooth/bluetooth.h>
15 #include <net/bluetooth/hci_core.h>
16 #include <net/bluetooth/iso.h>
18 static const struct proto_ops iso_sock_ops;
20 static struct bt_sock_list iso_sk_list = {
21 .lock = __RW_LOCK_UNLOCKED(iso_sk_list.lock)
24 /* ---- ISO connections ---- */
26 struct hci_conn *hcon;
28 /* @lock: spinlock protecting changes to iso_conn fields */
32 struct delayed_work timeout_work;
34 struct sk_buff *rx_skb;
39 #define iso_conn_lock(c) spin_lock(&(c)->lock)
40 #define iso_conn_unlock(c) spin_unlock(&(c)->lock)
42 static void iso_sock_close(struct sock *sk);
43 static void iso_sock_kill(struct sock *sk);
45 /* ----- ISO socket info ----- */
46 #define iso_pi(sk) ((struct iso_pinfo *)sk)
48 #define EIR_SERVICE_DATA_LENGTH 4
49 #define BASE_MAX_LENGTH (HCI_MAX_PER_AD_LENGTH - EIR_SERVICE_DATA_LENGTH)
51 /* iso_pinfo flags values */
65 __u8 bc_bis[ISO_MAX_NUM_BIS];
68 struct bt_iso_qos qos;
71 __u8 base[BASE_MAX_LENGTH];
72 struct iso_conn *conn;
75 static struct bt_iso_qos default_qos;
77 static bool check_ucast_qos(struct bt_iso_qos *qos);
78 static bool check_bcast_qos(struct bt_iso_qos *qos);
79 static bool iso_match_sid(struct sock *sk, void *data);
80 static void iso_sock_disconn(struct sock *sk);
82 /* ---- ISO timers ---- */
83 #define ISO_CONN_TIMEOUT (HZ * 40)
84 #define ISO_DISCONN_TIMEOUT (HZ * 2)
86 static void iso_sock_timeout(struct work_struct *work)
88 struct iso_conn *conn = container_of(work, struct iso_conn,
96 iso_conn_unlock(conn);
101 BT_DBG("sock %p state %d", sk, sk->sk_state);
104 sk->sk_err = ETIMEDOUT;
105 sk->sk_state_change(sk);
110 static void iso_sock_set_timer(struct sock *sk, long timeout)
112 if (!iso_pi(sk)->conn)
115 BT_DBG("sock %p state %d timeout %ld", sk, sk->sk_state, timeout);
116 cancel_delayed_work(&iso_pi(sk)->conn->timeout_work);
117 schedule_delayed_work(&iso_pi(sk)->conn->timeout_work, timeout);
120 static void iso_sock_clear_timer(struct sock *sk)
122 if (!iso_pi(sk)->conn)
125 BT_DBG("sock %p state %d", sk, sk->sk_state);
126 cancel_delayed_work(&iso_pi(sk)->conn->timeout_work);
129 /* ---- ISO connections ---- */
130 static struct iso_conn *iso_conn_add(struct hci_conn *hcon)
132 struct iso_conn *conn = hcon->iso_data;
140 conn = kzalloc(sizeof(*conn), GFP_KERNEL);
144 spin_lock_init(&conn->lock);
145 INIT_DELAYED_WORK(&conn->timeout_work, iso_sock_timeout);
147 hcon->iso_data = conn;
151 BT_DBG("hcon %p conn %p", hcon, conn);
156 /* Delete channel. Must be called on the locked socket. */
157 static void iso_chan_del(struct sock *sk, int err)
159 struct iso_conn *conn;
162 conn = iso_pi(sk)->conn;
164 BT_DBG("sk %p, conn %p, err %d", sk, conn, err);
169 iso_pi(sk)->conn = NULL;
170 iso_conn_unlock(conn);
173 hci_conn_drop(conn->hcon);
176 sk->sk_state = BT_CLOSED;
179 parent = bt_sk(sk)->parent;
181 bt_accept_unlink(sk);
182 parent->sk_data_ready(parent);
184 sk->sk_state_change(sk);
187 sock_set_flag(sk, SOCK_ZAPPED);
190 static void iso_conn_del(struct hci_conn *hcon, int err)
192 struct iso_conn *conn = hcon->iso_data;
198 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
205 iso_conn_unlock(conn);
209 iso_sock_clear_timer(sk);
210 iso_chan_del(sk, err);
215 /* Ensure no more work items will run before freeing conn. */
216 cancel_delayed_work_sync(&conn->timeout_work);
218 hcon->iso_data = NULL;
222 static int __iso_chan_add(struct iso_conn *conn, struct sock *sk,
225 BT_DBG("conn %p", conn);
227 if (iso_pi(sk)->conn == conn && conn->sk == sk)
231 BT_ERR("conn->sk already set");
235 iso_pi(sk)->conn = conn;
239 bt_accept_enqueue(parent, sk, true);
244 static int iso_chan_add(struct iso_conn *conn, struct sock *sk,
250 err = __iso_chan_add(conn, sk, parent);
251 iso_conn_unlock(conn);
256 static inline u8 le_addr_type(u8 bdaddr_type)
258 if (bdaddr_type == BDADDR_LE_PUBLIC)
259 return ADDR_LE_DEV_PUBLIC;
261 return ADDR_LE_DEV_RANDOM;
264 static int iso_connect_bis(struct sock *sk)
266 struct iso_conn *conn;
267 struct hci_conn *hcon;
268 struct hci_dev *hdev;
271 BT_DBG("%pMR", &iso_pi(sk)->src);
273 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src,
274 iso_pi(sk)->src_type);
276 return -EHOSTUNREACH;
280 if (!bis_capable(hdev)) {
285 /* Fail if user set invalid QoS */
286 if (iso_pi(sk)->qos_user_set && !check_bcast_qos(&iso_pi(sk)->qos)) {
287 iso_pi(sk)->qos = default_qos;
292 /* Fail if out PHYs are marked as disabled */
293 if (!iso_pi(sk)->qos.bcast.out.phy) {
298 /* Just bind if DEFER_SETUP has been set */
299 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
300 hcon = hci_bind_bis(hdev, &iso_pi(sk)->dst,
301 &iso_pi(sk)->qos, iso_pi(sk)->base_len,
308 hcon = hci_connect_bis(hdev, &iso_pi(sk)->dst,
309 le_addr_type(iso_pi(sk)->dst_type),
310 &iso_pi(sk)->qos, iso_pi(sk)->base_len,
318 conn = iso_conn_add(hcon);
327 err = iso_chan_add(conn, sk, NULL);
333 /* Update source addr of the socket */
334 bacpy(&iso_pi(sk)->src, &hcon->src);
336 if (hcon->state == BT_CONNECTED) {
337 iso_sock_clear_timer(sk);
338 sk->sk_state = BT_CONNECTED;
339 } else if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
340 iso_sock_clear_timer(sk);
341 sk->sk_state = BT_CONNECT;
343 sk->sk_state = BT_CONNECT;
344 iso_sock_set_timer(sk, sk->sk_sndtimeo);
350 hci_dev_unlock(hdev);
355 static int iso_connect_cis(struct sock *sk)
357 struct iso_conn *conn;
358 struct hci_conn *hcon;
359 struct hci_dev *hdev;
362 BT_DBG("%pMR -> %pMR", &iso_pi(sk)->src, &iso_pi(sk)->dst);
364 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src,
365 iso_pi(sk)->src_type);
367 return -EHOSTUNREACH;
371 if (!cis_central_capable(hdev)) {
376 /* Fail if user set invalid QoS */
377 if (iso_pi(sk)->qos_user_set && !check_ucast_qos(&iso_pi(sk)->qos)) {
378 iso_pi(sk)->qos = default_qos;
383 /* Fail if either PHYs are marked as disabled */
384 if (!iso_pi(sk)->qos.ucast.in.phy && !iso_pi(sk)->qos.ucast.out.phy) {
389 /* Just bind if DEFER_SETUP has been set */
390 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
391 hcon = hci_bind_cis(hdev, &iso_pi(sk)->dst,
392 le_addr_type(iso_pi(sk)->dst_type),
399 hcon = hci_connect_cis(hdev, &iso_pi(sk)->dst,
400 le_addr_type(iso_pi(sk)->dst_type),
408 conn = iso_conn_add(hcon);
417 err = iso_chan_add(conn, sk, NULL);
423 /* Update source addr of the socket */
424 bacpy(&iso_pi(sk)->src, &hcon->src);
426 if (hcon->state == BT_CONNECTED) {
427 iso_sock_clear_timer(sk);
428 sk->sk_state = BT_CONNECTED;
429 } else if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
430 iso_sock_clear_timer(sk);
431 sk->sk_state = BT_CONNECT;
433 sk->sk_state = BT_CONNECT;
434 iso_sock_set_timer(sk, sk->sk_sndtimeo);
440 hci_dev_unlock(hdev);
445 static struct bt_iso_qos *iso_sock_get_qos(struct sock *sk)
447 if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONNECT2)
448 return &iso_pi(sk)->conn->hcon->iso_qos;
450 return &iso_pi(sk)->qos;
453 static int iso_send_frame(struct sock *sk, struct sk_buff *skb)
455 struct iso_conn *conn = iso_pi(sk)->conn;
456 struct bt_iso_qos *qos = iso_sock_get_qos(sk);
457 struct hci_iso_data_hdr *hdr;
460 BT_DBG("sk %p len %d", sk, skb->len);
462 if (skb->len > qos->ucast.out.sdu)
467 /* Push ISO data header */
468 hdr = skb_push(skb, HCI_ISO_DATA_HDR_SIZE);
469 hdr->sn = cpu_to_le16(conn->tx_sn++);
470 hdr->slen = cpu_to_le16(hci_iso_data_len_pack(len,
471 HCI_ISO_STATUS_VALID));
473 if (sk->sk_state == BT_CONNECTED)
474 hci_send_iso(conn->hcon, skb);
481 static void iso_recv_frame(struct iso_conn *conn, struct sk_buff *skb)
487 iso_conn_unlock(conn);
492 BT_DBG("sk %p len %d", sk, skb->len);
494 if (sk->sk_state != BT_CONNECTED)
497 if (!sock_queue_rcv_skb(sk, skb))
504 /* -------- Socket interface ---------- */
505 static struct sock *__iso_get_sock_listen_by_addr(bdaddr_t *src, bdaddr_t *dst)
509 sk_for_each(sk, &iso_sk_list.head) {
510 if (sk->sk_state != BT_LISTEN)
513 if (bacmp(&iso_pi(sk)->dst, dst))
516 if (!bacmp(&iso_pi(sk)->src, src))
523 static struct sock *__iso_get_sock_listen_by_sid(bdaddr_t *ba, bdaddr_t *bc,
528 sk_for_each(sk, &iso_sk_list.head) {
529 if (sk->sk_state != BT_LISTEN)
532 if (bacmp(&iso_pi(sk)->src, ba))
535 if (bacmp(&iso_pi(sk)->dst, bc))
538 if (iso_pi(sk)->bc_sid == sid)
545 typedef bool (*iso_sock_match_t)(struct sock *sk, void *data);
547 /* Find socket listening:
548 * source bdaddr (Unicast)
549 * destination bdaddr (Broadcast only)
550 * match func - pass NULL to ignore
551 * match func data - pass -1 to ignore
552 * Returns closest match.
554 static struct sock *iso_get_sock_listen(bdaddr_t *src, bdaddr_t *dst,
555 iso_sock_match_t match, void *data)
557 struct sock *sk = NULL, *sk1 = NULL;
559 read_lock(&iso_sk_list.lock);
561 sk_for_each(sk, &iso_sk_list.head) {
562 if (sk->sk_state != BT_LISTEN)
565 /* Match Broadcast destination */
566 if (bacmp(dst, BDADDR_ANY) && bacmp(&iso_pi(sk)->dst, dst))
569 /* Use Match function if provided */
570 if (match && !match(sk, data))
574 if (!bacmp(&iso_pi(sk)->src, src))
578 if (!bacmp(&iso_pi(sk)->src, BDADDR_ANY))
582 read_unlock(&iso_sk_list.lock);
584 return sk ? sk : sk1;
587 static void iso_sock_destruct(struct sock *sk)
591 skb_queue_purge(&sk->sk_receive_queue);
592 skb_queue_purge(&sk->sk_write_queue);
595 static void iso_sock_cleanup_listen(struct sock *parent)
599 BT_DBG("parent %p", parent);
601 /* Close not yet accepted channels */
602 while ((sk = bt_accept_dequeue(parent, NULL))) {
607 /* If listening socket stands for a PA sync connection,
608 * properly disconnect the hcon and socket.
610 if (iso_pi(parent)->conn && iso_pi(parent)->conn->hcon &&
611 test_bit(HCI_CONN_PA_SYNC, &iso_pi(parent)->conn->hcon->flags)) {
612 iso_sock_disconn(parent);
616 parent->sk_state = BT_CLOSED;
617 sock_set_flag(parent, SOCK_ZAPPED);
620 /* Kill socket (only if zapped and orphan)
621 * Must be called on unlocked socket.
623 static void iso_sock_kill(struct sock *sk)
625 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket ||
626 sock_flag(sk, SOCK_DEAD))
629 BT_DBG("sk %p state %d", sk, sk->sk_state);
631 /* Kill poor orphan */
632 bt_sock_unlink(&iso_sk_list, sk);
633 sock_set_flag(sk, SOCK_DEAD);
637 static void iso_sock_disconn(struct sock *sk)
639 sk->sk_state = BT_DISCONN;
640 iso_sock_set_timer(sk, ISO_DISCONN_TIMEOUT);
641 iso_conn_lock(iso_pi(sk)->conn);
642 hci_conn_drop(iso_pi(sk)->conn->hcon);
643 iso_pi(sk)->conn->hcon = NULL;
644 iso_conn_unlock(iso_pi(sk)->conn);
647 static void __iso_sock_close(struct sock *sk)
649 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
651 switch (sk->sk_state) {
653 iso_sock_cleanup_listen(sk);
659 if (iso_pi(sk)->conn->hcon)
660 iso_sock_disconn(sk);
662 iso_chan_del(sk, ECONNRESET);
666 if (iso_pi(sk)->conn->hcon &&
667 (test_bit(HCI_CONN_PA_SYNC, &iso_pi(sk)->conn->hcon->flags) ||
668 test_bit(HCI_CONN_PA_SYNC_FAILED, &iso_pi(sk)->conn->hcon->flags)))
669 iso_sock_disconn(sk);
671 iso_chan_del(sk, ECONNRESET);
674 iso_chan_del(sk, ECONNRESET);
678 sock_set_flag(sk, SOCK_ZAPPED);
683 /* Must be called on unlocked socket. */
684 static void iso_sock_close(struct sock *sk)
686 iso_sock_clear_timer(sk);
688 __iso_sock_close(sk);
693 static void iso_sock_init(struct sock *sk, struct sock *parent)
698 sk->sk_type = parent->sk_type;
699 bt_sk(sk)->flags = bt_sk(parent)->flags;
700 security_sk_clone(parent, sk);
704 static struct proto iso_proto = {
706 .owner = THIS_MODULE,
707 .obj_size = sizeof(struct iso_pinfo)
710 #define DEFAULT_IO_QOS \
712 .interval = 10000u, \
715 .phy = BT_ISO_PHY_2M, \
719 static struct bt_iso_qos default_qos = {
721 .big = BT_ISO_QOS_BIG_UNSET,
722 .bis = BT_ISO_QOS_BIS_UNSET,
726 .in = DEFAULT_IO_QOS,
727 .out = DEFAULT_IO_QOS,
732 .sync_timeout = 0x4000,
733 .sync_cte_type = 0x00,
739 static struct sock *iso_sock_alloc(struct net *net, struct socket *sock,
740 int proto, gfp_t prio, int kern)
744 sk = bt_sock_alloc(net, sock, &iso_proto, proto, prio, kern);
748 sk->sk_destruct = iso_sock_destruct;
749 sk->sk_sndtimeo = ISO_CONN_TIMEOUT;
751 /* Set address type as public as default src address is BDADDR_ANY */
752 iso_pi(sk)->src_type = BDADDR_LE_PUBLIC;
754 iso_pi(sk)->qos = default_qos;
756 bt_sock_link(&iso_sk_list, sk);
760 static int iso_sock_create(struct net *net, struct socket *sock, int protocol,
765 BT_DBG("sock %p", sock);
767 sock->state = SS_UNCONNECTED;
769 if (sock->type != SOCK_SEQPACKET)
770 return -ESOCKTNOSUPPORT;
772 sock->ops = &iso_sock_ops;
774 sk = iso_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern);
778 iso_sock_init(sk, NULL);
782 static int iso_sock_bind_bc(struct socket *sock, struct sockaddr *addr,
785 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
786 struct sock *sk = sock->sk;
789 BT_DBG("sk %p bc_sid %u bc_num_bis %u", sk, sa->iso_bc->bc_sid,
790 sa->iso_bc->bc_num_bis);
792 if (addr_len > sizeof(*sa) + sizeof(*sa->iso_bc) ||
793 sa->iso_bc->bc_num_bis < 0x01 || sa->iso_bc->bc_num_bis > 0x1f)
796 bacpy(&iso_pi(sk)->dst, &sa->iso_bc->bc_bdaddr);
797 iso_pi(sk)->dst_type = sa->iso_bc->bc_bdaddr_type;
798 iso_pi(sk)->sync_handle = -1;
799 iso_pi(sk)->bc_sid = sa->iso_bc->bc_sid;
800 iso_pi(sk)->bc_num_bis = sa->iso_bc->bc_num_bis;
802 for (i = 0; i < iso_pi(sk)->bc_num_bis; i++) {
803 if (sa->iso_bc->bc_bis[i] < 0x01 ||
804 sa->iso_bc->bc_bis[i] > 0x1f)
807 memcpy(iso_pi(sk)->bc_bis, sa->iso_bc->bc_bis,
808 iso_pi(sk)->bc_num_bis);
814 static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
817 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
818 struct sock *sk = sock->sk;
821 BT_DBG("sk %p %pMR type %u", sk, &sa->iso_bdaddr, sa->iso_bdaddr_type);
823 if (!addr || addr_len < sizeof(struct sockaddr_iso) ||
824 addr->sa_family != AF_BLUETOOTH)
829 if (sk->sk_state != BT_OPEN) {
834 if (sk->sk_type != SOCK_SEQPACKET) {
839 /* Check if the address type is of LE type */
840 if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) {
845 bacpy(&iso_pi(sk)->src, &sa->iso_bdaddr);
846 iso_pi(sk)->src_type = sa->iso_bdaddr_type;
848 /* Check for Broadcast address */
849 if (addr_len > sizeof(*sa)) {
850 err = iso_sock_bind_bc(sock, addr, addr_len);
855 sk->sk_state = BT_BOUND;
862 static int iso_sock_connect(struct socket *sock, struct sockaddr *addr,
865 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
866 struct sock *sk = sock->sk;
871 if (alen < sizeof(struct sockaddr_iso) ||
872 addr->sa_family != AF_BLUETOOTH)
875 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
878 if (sk->sk_type != SOCK_SEQPACKET)
881 /* Check if the address type is of LE type */
882 if (!bdaddr_type_is_le(sa->iso_bdaddr_type))
887 bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr);
888 iso_pi(sk)->dst_type = sa->iso_bdaddr_type;
892 if (bacmp(&iso_pi(sk)->dst, BDADDR_ANY))
893 err = iso_connect_cis(sk);
895 err = iso_connect_bis(sk);
902 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
903 err = bt_sock_wait_state(sk, BT_CONNECTED,
904 sock_sndtimeo(sk, flags & O_NONBLOCK));
911 static int iso_listen_bis(struct sock *sk)
913 struct hci_dev *hdev;
916 BT_DBG("%pMR -> %pMR (SID 0x%2.2x)", &iso_pi(sk)->src,
917 &iso_pi(sk)->dst, iso_pi(sk)->bc_sid);
919 write_lock(&iso_sk_list.lock);
921 if (__iso_get_sock_listen_by_sid(&iso_pi(sk)->src, &iso_pi(sk)->dst,
925 write_unlock(&iso_sk_list.lock);
930 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src,
931 iso_pi(sk)->src_type);
933 return -EHOSTUNREACH;
935 /* Fail if user set invalid QoS */
936 if (iso_pi(sk)->qos_user_set && !check_bcast_qos(&iso_pi(sk)->qos)) {
937 iso_pi(sk)->qos = default_qos;
941 err = hci_pa_create_sync(hdev, &iso_pi(sk)->dst,
942 le_addr_type(iso_pi(sk)->dst_type),
943 iso_pi(sk)->bc_sid, &iso_pi(sk)->qos);
950 static int iso_listen_cis(struct sock *sk)
954 BT_DBG("%pMR", &iso_pi(sk)->src);
956 write_lock(&iso_sk_list.lock);
958 if (__iso_get_sock_listen_by_addr(&iso_pi(sk)->src, &iso_pi(sk)->dst))
961 write_unlock(&iso_sk_list.lock);
966 static int iso_sock_listen(struct socket *sock, int backlog)
968 struct sock *sk = sock->sk;
971 BT_DBG("sk %p backlog %d", sk, backlog);
975 if (sk->sk_state != BT_BOUND) {
980 if (sk->sk_type != SOCK_SEQPACKET) {
985 if (!bacmp(&iso_pi(sk)->dst, BDADDR_ANY))
986 err = iso_listen_cis(sk);
988 err = iso_listen_bis(sk);
993 sk->sk_max_ack_backlog = backlog;
994 sk->sk_ack_backlog = 0;
996 sk->sk_state = BT_LISTEN;
1003 static int iso_sock_accept(struct socket *sock, struct socket *newsock,
1004 int flags, bool kern)
1006 DEFINE_WAIT_FUNC(wait, woken_wake_function);
1007 struct sock *sk = sock->sk, *ch;
1013 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
1015 BT_DBG("sk %p timeo %ld", sk, timeo);
1017 /* Wait for an incoming connection. (wake-one). */
1018 add_wait_queue_exclusive(sk_sleep(sk), &wait);
1020 if (sk->sk_state != BT_LISTEN) {
1025 ch = bt_accept_dequeue(sk, newsock);
1034 if (signal_pending(current)) {
1035 err = sock_intr_errno(timeo);
1041 timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo);
1044 remove_wait_queue(sk_sleep(sk), &wait);
1049 newsock->state = SS_CONNECTED;
1051 BT_DBG("new socket %p", ch);
1058 static int iso_sock_getname(struct socket *sock, struct sockaddr *addr,
1061 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
1062 struct sock *sk = sock->sk;
1064 BT_DBG("sock %p, sk %p", sock, sk);
1066 addr->sa_family = AF_BLUETOOTH;
1069 bacpy(&sa->iso_bdaddr, &iso_pi(sk)->dst);
1070 sa->iso_bdaddr_type = iso_pi(sk)->dst_type;
1072 bacpy(&sa->iso_bdaddr, &iso_pi(sk)->src);
1073 sa->iso_bdaddr_type = iso_pi(sk)->src_type;
1076 return sizeof(struct sockaddr_iso);
1079 static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
1082 struct sock *sk = sock->sk;
1083 struct sk_buff *skb, **frag;
1087 BT_DBG("sock %p, sk %p", sock, sk);
1089 err = sock_error(sk);
1093 if (msg->msg_flags & MSG_OOB)
1098 if (sk->sk_state != BT_CONNECTED) {
1103 mtu = iso_pi(sk)->conn->hcon->hdev->iso_mtu;
1107 skb = bt_skb_sendmsg(sk, msg, len, mtu, HCI_ISO_DATA_HDR_SIZE, 0);
1109 return PTR_ERR(skb);
1113 BT_DBG("skb %p len %d", sk, skb->len);
1115 /* Continuation fragments */
1116 frag = &skb_shinfo(skb)->frag_list;
1118 struct sk_buff *tmp;
1120 tmp = bt_skb_sendmsg(sk, msg, len, mtu, 0, 0);
1123 return PTR_ERR(tmp);
1130 skb->len += tmp->len;
1131 skb->data_len += tmp->len;
1133 BT_DBG("frag %p len %d", *frag, tmp->len);
1135 frag = &(*frag)->next;
1140 if (sk->sk_state == BT_CONNECTED)
1141 err = iso_send_frame(sk, skb);
1152 static void iso_conn_defer_accept(struct hci_conn *conn)
1154 struct hci_cp_le_accept_cis cp;
1155 struct hci_dev *hdev = conn->hdev;
1157 BT_DBG("conn %p", conn);
1159 conn->state = BT_CONFIG;
1161 cp.handle = cpu_to_le16(conn->handle);
1163 hci_send_cmd(hdev, HCI_OP_LE_ACCEPT_CIS, sizeof(cp), &cp);
1166 static void iso_conn_big_sync(struct sock *sk)
1169 struct hci_dev *hdev;
1171 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src,
1172 iso_pi(sk)->src_type);
1177 if (!test_and_set_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
1178 err = hci_le_big_create_sync(hdev, iso_pi(sk)->conn->hcon,
1180 iso_pi(sk)->sync_handle,
1181 iso_pi(sk)->bc_num_bis,
1182 iso_pi(sk)->bc_bis);
1184 bt_dev_err(hdev, "hci_le_big_create_sync: %d",
1189 static int iso_sock_recvmsg(struct socket *sock, struct msghdr *msg,
1190 size_t len, int flags)
1192 struct sock *sk = sock->sk;
1193 struct iso_pinfo *pi = iso_pi(sk);
1195 BT_DBG("sk %p", sk);
1197 if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
1199 switch (sk->sk_state) {
1201 if (pi->conn->hcon &&
1202 test_bit(HCI_CONN_PA_SYNC, &pi->conn->hcon->flags)) {
1203 iso_conn_big_sync(sk);
1204 sk->sk_state = BT_LISTEN;
1205 set_bit(BT_SK_PA_SYNC, &iso_pi(sk)->flags);
1207 iso_conn_defer_accept(pi->conn->hcon);
1208 sk->sk_state = BT_CONFIG;
1214 return iso_connect_cis(sk);
1221 return bt_sock_recvmsg(sock, msg, len, flags);
1224 static bool check_io_qos(struct bt_iso_io_qos *qos)
1226 /* If no PHY is enable SDU must be 0 */
1227 if (!qos->phy && qos->sdu)
1230 if (qos->interval && (qos->interval < 0xff || qos->interval > 0xfffff))
1233 if (qos->latency && (qos->latency < 0x05 || qos->latency > 0xfa0))
1236 if (qos->phy > BT_ISO_PHY_ANY)
1242 static bool check_ucast_qos(struct bt_iso_qos *qos)
1244 if (qos->ucast.cig > 0xef && qos->ucast.cig != BT_ISO_QOS_CIG_UNSET)
1247 if (qos->ucast.cis > 0xef && qos->ucast.cis != BT_ISO_QOS_CIS_UNSET)
1250 if (qos->ucast.sca > 0x07)
1253 if (qos->ucast.packing > 0x01)
1256 if (qos->ucast.framing > 0x01)
1259 if (!check_io_qos(&qos->ucast.in))
1262 if (!check_io_qos(&qos->ucast.out))
1268 static bool check_bcast_qos(struct bt_iso_qos *qos)
1270 if (qos->bcast.sync_factor == 0x00)
1273 if (qos->bcast.packing > 0x01)
1276 if (qos->bcast.framing > 0x01)
1279 if (!check_io_qos(&qos->bcast.in))
1282 if (!check_io_qos(&qos->bcast.out))
1285 if (qos->bcast.encryption > 0x01)
1288 if (qos->bcast.options > 0x07)
1291 if (qos->bcast.skip > 0x01f3)
1294 if (qos->bcast.sync_timeout < 0x000a || qos->bcast.sync_timeout > 0x4000)
1297 if (qos->bcast.sync_cte_type > 0x1f)
1300 if (qos->bcast.mse > 0x1f)
1303 if (qos->bcast.timeout < 0x000a || qos->bcast.timeout > 0x4000)
1309 static int iso_sock_setsockopt(struct socket *sock, int level, int optname,
1310 sockptr_t optval, unsigned int optlen)
1312 struct sock *sk = sock->sk;
1314 struct bt_iso_qos qos = default_qos;
1317 BT_DBG("sk %p", sk);
1322 case BT_DEFER_SETUP:
1323 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
1328 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
1334 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
1336 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
1340 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
1346 set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags);
1348 clear_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags);
1352 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
1353 sk->sk_state != BT_CONNECT2) {
1358 len = min_t(unsigned int, sizeof(qos), optlen);
1360 if (copy_from_sockptr(&qos, optval, len)) {
1365 if (len == sizeof(qos.ucast) && !check_ucast_qos(&qos)) {
1370 iso_pi(sk)->qos = qos;
1371 iso_pi(sk)->qos_user_set = true;
1376 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
1377 sk->sk_state != BT_CONNECT2) {
1382 if (optlen > sizeof(iso_pi(sk)->base)) {
1387 len = min_t(unsigned int, sizeof(iso_pi(sk)->base), optlen);
1389 if (copy_from_sockptr(iso_pi(sk)->base, optval, len)) {
1394 iso_pi(sk)->base_len = len;
1407 static int iso_sock_getsockopt(struct socket *sock, int level, int optname,
1408 char __user *optval, int __user *optlen)
1410 struct sock *sk = sock->sk;
1412 struct bt_iso_qos *qos;
1416 BT_DBG("sk %p", sk);
1418 if (get_user(len, optlen))
1424 case BT_DEFER_SETUP:
1425 if (sk->sk_state == BT_CONNECTED) {
1430 if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags),
1431 (u32 __user *)optval))
1437 if (put_user(test_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags),
1438 (int __user *)optval))
1443 qos = iso_sock_get_qos(sk);
1445 len = min_t(unsigned int, len, sizeof(*qos));
1446 if (copy_to_user(optval, qos, len))
1452 if (sk->sk_state == BT_CONNECTED &&
1453 !bacmp(&iso_pi(sk)->dst, BDADDR_ANY)) {
1454 base_len = iso_pi(sk)->conn->hcon->le_per_adv_data_len;
1455 base = iso_pi(sk)->conn->hcon->le_per_adv_data;
1457 base_len = iso_pi(sk)->base_len;
1458 base = iso_pi(sk)->base;
1461 len = min_t(unsigned int, len, base_len);
1462 if (copy_to_user(optval, base, len))
1476 static int iso_sock_shutdown(struct socket *sock, int how)
1478 struct sock *sk = sock->sk;
1481 BT_DBG("sock %p, sk %p, how %d", sock, sk, how);
1491 if (sk->sk_shutdown & RCV_SHUTDOWN)
1493 sk->sk_shutdown |= RCV_SHUTDOWN;
1496 if (sk->sk_shutdown & SEND_SHUTDOWN)
1498 sk->sk_shutdown |= SEND_SHUTDOWN;
1501 if (sk->sk_shutdown & SHUTDOWN_MASK)
1503 sk->sk_shutdown |= SHUTDOWN_MASK;
1507 iso_sock_clear_timer(sk);
1508 __iso_sock_close(sk);
1510 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
1511 !(current->flags & PF_EXITING))
1512 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
1521 static int iso_sock_release(struct socket *sock)
1523 struct sock *sk = sock->sk;
1526 BT_DBG("sock %p, sk %p", sock, sk);
1533 if (sock_flag(sk, SOCK_LINGER) && READ_ONCE(sk->sk_lingertime) &&
1534 !(current->flags & PF_EXITING)) {
1536 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
1545 static void iso_sock_ready(struct sock *sk)
1547 BT_DBG("sk %p", sk);
1553 iso_sock_clear_timer(sk);
1554 sk->sk_state = BT_CONNECTED;
1555 sk->sk_state_change(sk);
1559 struct iso_list_data {
1560 struct hci_conn *hcon;
1564 static bool iso_match_big(struct sock *sk, void *data)
1566 struct hci_evt_le_big_sync_estabilished *ev = data;
1568 return ev->handle == iso_pi(sk)->qos.bcast.big;
1571 static bool iso_match_pa_sync_flag(struct sock *sk, void *data)
1573 return test_bit(BT_SK_PA_SYNC, &iso_pi(sk)->flags);
1576 static void iso_conn_ready(struct iso_conn *conn)
1578 struct sock *parent = NULL;
1579 struct sock *sk = conn->sk;
1580 struct hci_ev_le_big_sync_estabilished *ev = NULL;
1581 struct hci_ev_le_pa_sync_established *ev2 = NULL;
1582 struct hci_conn *hcon;
1584 BT_DBG("conn %p", conn);
1587 iso_sock_ready(conn->sk);
1593 if (test_bit(HCI_CONN_BIG_SYNC, &hcon->flags) ||
1594 test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags)) {
1595 ev = hci_recv_event_data(hcon->hdev,
1596 HCI_EVT_LE_BIG_SYNC_ESTABILISHED);
1598 /* Get reference to PA sync parent socket, if it exists */
1599 parent = iso_get_sock_listen(&hcon->src,
1601 iso_match_pa_sync_flag, NULL);
1603 parent = iso_get_sock_listen(&hcon->src,
1606 } else if (test_bit(HCI_CONN_PA_SYNC, &hcon->flags) ||
1607 test_bit(HCI_CONN_PA_SYNC_FAILED, &hcon->flags)) {
1608 ev2 = hci_recv_event_data(hcon->hdev,
1609 HCI_EV_LE_PA_SYNC_ESTABLISHED);
1611 parent = iso_get_sock_listen(&hcon->src,
1613 iso_match_sid, ev2);
1617 parent = iso_get_sock_listen(&hcon->src,
1618 BDADDR_ANY, NULL, NULL);
1625 sk = iso_sock_alloc(sock_net(parent), NULL,
1626 BTPROTO_ISO, GFP_ATOMIC, 0);
1628 release_sock(parent);
1632 iso_sock_init(sk, parent);
1634 bacpy(&iso_pi(sk)->src, &hcon->src);
1636 /* Convert from HCI to three-value type */
1637 if (hcon->src_type == ADDR_LE_DEV_PUBLIC)
1638 iso_pi(sk)->src_type = BDADDR_LE_PUBLIC;
1640 iso_pi(sk)->src_type = BDADDR_LE_RANDOM;
1642 /* If hcon has no destination address (BDADDR_ANY) it means it
1643 * was created by HCI_EV_LE_BIG_SYNC_ESTABILISHED or
1644 * HCI_EV_LE_PA_SYNC_ESTABLISHED so we need to initialize using
1645 * the parent socket destination address.
1647 if (!bacmp(&hcon->dst, BDADDR_ANY)) {
1648 bacpy(&hcon->dst, &iso_pi(parent)->dst);
1649 hcon->dst_type = iso_pi(parent)->dst_type;
1650 hcon->sync_handle = iso_pi(parent)->sync_handle;
1653 if (ev2 && !ev2->status) {
1654 iso_pi(sk)->sync_handle = iso_pi(parent)->sync_handle;
1655 iso_pi(sk)->qos = iso_pi(parent)->qos;
1656 iso_pi(sk)->bc_num_bis = iso_pi(parent)->bc_num_bis;
1657 memcpy(iso_pi(sk)->bc_bis, iso_pi(parent)->bc_bis, ISO_MAX_NUM_BIS);
1660 bacpy(&iso_pi(sk)->dst, &hcon->dst);
1661 iso_pi(sk)->dst_type = hcon->dst_type;
1662 iso_pi(sk)->sync_handle = iso_pi(parent)->sync_handle;
1663 memcpy(iso_pi(sk)->base, iso_pi(parent)->base, iso_pi(parent)->base_len);
1664 iso_pi(sk)->base_len = iso_pi(parent)->base_len;
1666 hci_conn_hold(hcon);
1667 iso_chan_add(conn, sk, parent);
1669 if ((ev && ((struct hci_evt_le_big_sync_estabilished *)ev)->status) ||
1670 (ev2 && ev2->status)) {
1671 /* Trigger error signal on child socket */
1672 sk->sk_err = ECONNREFUSED;
1673 sk->sk_error_report(sk);
1676 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
1677 sk->sk_state = BT_CONNECT2;
1679 sk->sk_state = BT_CONNECTED;
1681 /* Wake up parent */
1682 parent->sk_data_ready(parent);
1684 release_sock(parent);
1688 static bool iso_match_sid(struct sock *sk, void *data)
1690 struct hci_ev_le_pa_sync_established *ev = data;
1692 return ev->sid == iso_pi(sk)->bc_sid;
1695 static bool iso_match_sync_handle(struct sock *sk, void *data)
1697 struct hci_evt_le_big_info_adv_report *ev = data;
1699 return le16_to_cpu(ev->sync_handle) == iso_pi(sk)->sync_handle;
1702 static bool iso_match_sync_handle_pa_report(struct sock *sk, void *data)
1704 struct hci_ev_le_per_adv_report *ev = data;
1706 return le16_to_cpu(ev->sync_handle) == iso_pi(sk)->sync_handle;
1709 /* ----- ISO interface with lower layer (HCI) ----- */
1711 int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
1713 struct hci_ev_le_pa_sync_established *ev1;
1714 struct hci_evt_le_big_info_adv_report *ev2;
1715 struct hci_ev_le_per_adv_report *ev3;
1719 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr);
1721 /* Broadcast receiver requires handling of some events before it can
1722 * proceed to establishing a BIG sync:
1724 * 1. HCI_EV_LE_PA_SYNC_ESTABLISHED: The socket may specify a specific
1725 * SID to listen to and once sync is estabilished its handle needs to
1726 * be stored in iso_pi(sk)->sync_handle so it can be matched once
1727 * receiving the BIG Info.
1728 * 2. HCI_EVT_LE_BIG_INFO_ADV_REPORT: When connect_ind is triggered by a
1729 * a BIG Info it attempts to check if there any listening socket with
1730 * the same sync_handle and if it does then attempt to create a sync.
1731 * 3. HCI_EV_LE_PER_ADV_REPORT: When a PA report is received, it is stored
1732 * in iso_pi(sk)->base so it can be passed up to user, in the case of a
1735 ev1 = hci_recv_event_data(hdev, HCI_EV_LE_PA_SYNC_ESTABLISHED);
1737 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr, iso_match_sid,
1739 if (sk && !ev1->status)
1740 iso_pi(sk)->sync_handle = le16_to_cpu(ev1->handle);
1745 ev2 = hci_recv_event_data(hdev, HCI_EVT_LE_BIG_INFO_ADV_REPORT);
1747 /* Try to get PA sync listening socket, if it exists */
1748 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr,
1749 iso_match_pa_sync_flag, NULL);
1751 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr,
1752 iso_match_sync_handle, ev2);
1756 if (ev2->num_bis < iso_pi(sk)->bc_num_bis)
1757 iso_pi(sk)->bc_num_bis = ev2->num_bis;
1759 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags) &&
1760 !test_and_set_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
1761 err = hci_le_big_create_sync(hdev, NULL,
1763 iso_pi(sk)->sync_handle,
1764 iso_pi(sk)->bc_num_bis,
1765 iso_pi(sk)->bc_bis);
1767 bt_dev_err(hdev, "hci_le_big_create_sync: %d",
1775 ev3 = hci_recv_event_data(hdev, HCI_EV_LE_PER_ADV_REPORT);
1777 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr,
1778 iso_match_sync_handle_pa_report, ev3);
1781 memcpy(iso_pi(sk)->base, ev3->data, ev3->length);
1782 iso_pi(sk)->base_len = ev3->length;
1785 sk = iso_get_sock_listen(&hdev->bdaddr, BDADDR_ANY, NULL, NULL);
1792 lm |= HCI_LM_ACCEPT;
1794 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))
1795 *flags |= HCI_PROTO_DEFER;
1800 static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
1802 if (hcon->type != ISO_LINK) {
1803 if (hcon->type != LE_LINK)
1806 /* Check if LE link has failed */
1808 struct hci_link *link, *t;
1810 list_for_each_entry_safe(link, t, &hcon->link_list,
1812 iso_conn_del(link->conn, bt_to_errno(status));
1817 /* Create CIS if pending */
1818 hci_le_create_cis_pending(hcon->hdev);
1822 BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
1824 /* Similar to the success case, if HCI_CONN_BIG_SYNC_FAILED or
1825 * HCI_CONN_PA_SYNC_FAILED is set, queue the failed connection
1826 * into the accept queue of the listening socket and wake up
1827 * userspace, to inform the user about the event.
1829 if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags) ||
1830 test_bit(HCI_CONN_PA_SYNC_FAILED, &hcon->flags)) {
1831 struct iso_conn *conn;
1833 conn = iso_conn_add(hcon);
1835 iso_conn_ready(conn);
1837 iso_conn_del(hcon, bt_to_errno(status));
1841 static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason)
1843 if (hcon->type != ISO_LINK)
1846 BT_DBG("hcon %p reason %d", hcon, reason);
1848 iso_conn_del(hcon, bt_to_errno(reason));
1851 void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
1853 struct iso_conn *conn = hcon->iso_data;
1859 pb = hci_iso_flags_pb(flags);
1860 ts = hci_iso_flags_ts(flags);
1862 BT_DBG("conn %p len %d pb 0x%x ts 0x%x", conn, skb->len, pb, ts);
1868 BT_ERR("Unexpected start frame (len %d)", skb->len);
1869 kfree_skb(conn->rx_skb);
1870 conn->rx_skb = NULL;
1875 struct hci_iso_ts_data_hdr *hdr;
1877 /* TODO: add timestamp to the packet? */
1878 hdr = skb_pull_data(skb, HCI_ISO_TS_DATA_HDR_SIZE);
1880 BT_ERR("Frame is too short (len %d)", skb->len);
1884 len = __le16_to_cpu(hdr->slen);
1886 struct hci_iso_data_hdr *hdr;
1888 hdr = skb_pull_data(skb, HCI_ISO_DATA_HDR_SIZE);
1890 BT_ERR("Frame is too short (len %d)", skb->len);
1894 len = __le16_to_cpu(hdr->slen);
1897 flags = hci_iso_data_flags(len);
1898 len = hci_iso_data_len(len);
1900 BT_DBG("Start: total len %d, frag len %d flags 0x%4.4x", len,
1903 if (len == skb->len) {
1904 /* Complete frame received */
1905 hci_skb_pkt_status(skb) = flags & 0x03;
1906 iso_recv_frame(conn, skb);
1910 if (pb == ISO_SINGLE) {
1911 BT_ERR("Frame malformed (len %d, expected len %d)",
1916 if (skb->len > len) {
1917 BT_ERR("Frame is too long (len %d, expected len %d)",
1922 /* Allocate skb for the complete frame (with header) */
1923 conn->rx_skb = bt_skb_alloc(len, GFP_KERNEL);
1927 hci_skb_pkt_status(conn->rx_skb) = flags & 0x03;
1928 skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
1930 conn->rx_len = len - skb->len;
1934 BT_DBG("Cont: frag len %d (expecting %d)", skb->len,
1937 if (!conn->rx_len) {
1938 BT_ERR("Unexpected continuation frame (len %d)",
1943 if (skb->len > conn->rx_len) {
1944 BT_ERR("Fragment is too long (len %d, expected %d)",
1945 skb->len, conn->rx_len);
1946 kfree_skb(conn->rx_skb);
1947 conn->rx_skb = NULL;
1952 skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
1954 conn->rx_len -= skb->len;
1958 skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
1960 conn->rx_len -= skb->len;
1962 if (!conn->rx_len) {
1963 struct sk_buff *rx_skb = conn->rx_skb;
1965 /* Complete frame received. iso_recv_frame
1966 * takes ownership of the skb so set the global
1967 * rx_skb pointer to NULL first.
1969 conn->rx_skb = NULL;
1970 iso_recv_frame(conn, rx_skb);
1979 static struct hci_cb iso_cb = {
1981 .connect_cfm = iso_connect_cfm,
1982 .disconn_cfm = iso_disconn_cfm,
1985 static int iso_debugfs_show(struct seq_file *f, void *p)
1989 read_lock(&iso_sk_list.lock);
1991 sk_for_each(sk, &iso_sk_list.head) {
1992 seq_printf(f, "%pMR %pMR %d\n", &iso_pi(sk)->src,
1993 &iso_pi(sk)->dst, sk->sk_state);
1996 read_unlock(&iso_sk_list.lock);
2001 DEFINE_SHOW_ATTRIBUTE(iso_debugfs);
2003 static struct dentry *iso_debugfs;
2005 static const struct proto_ops iso_sock_ops = {
2006 .family = PF_BLUETOOTH,
2007 .owner = THIS_MODULE,
2008 .release = iso_sock_release,
2009 .bind = iso_sock_bind,
2010 .connect = iso_sock_connect,
2011 .listen = iso_sock_listen,
2012 .accept = iso_sock_accept,
2013 .getname = iso_sock_getname,
2014 .sendmsg = iso_sock_sendmsg,
2015 .recvmsg = iso_sock_recvmsg,
2016 .poll = bt_sock_poll,
2017 .ioctl = bt_sock_ioctl,
2018 .mmap = sock_no_mmap,
2019 .socketpair = sock_no_socketpair,
2020 .shutdown = iso_sock_shutdown,
2021 .setsockopt = iso_sock_setsockopt,
2022 .getsockopt = iso_sock_getsockopt
2025 static const struct net_proto_family iso_sock_family_ops = {
2026 .family = PF_BLUETOOTH,
2027 .owner = THIS_MODULE,
2028 .create = iso_sock_create,
2031 static bool iso_inited;
2033 bool iso_enabled(void)
2042 BUILD_BUG_ON(sizeof(struct sockaddr_iso) > sizeof(struct sockaddr));
2047 err = proto_register(&iso_proto, 0);
2051 err = bt_sock_register(BTPROTO_ISO, &iso_sock_family_ops);
2053 BT_ERR("ISO socket registration failed");
2057 err = bt_procfs_init(&init_net, "iso", &iso_sk_list, NULL);
2059 BT_ERR("Failed to create ISO proc file");
2060 bt_sock_unregister(BTPROTO_ISO);
2064 BT_INFO("ISO socket layer initialized");
2066 hci_register_cb(&iso_cb);
2068 if (IS_ERR_OR_NULL(bt_debugfs))
2072 iso_debugfs = debugfs_create_file("iso", 0444, bt_debugfs,
2073 NULL, &iso_debugfs_fops);
2081 proto_unregister(&iso_proto);
2090 bt_procfs_cleanup(&init_net, "iso");
2092 debugfs_remove(iso_debugfs);
2095 hci_unregister_cb(&iso_cb);
2097 bt_sock_unregister(BTPROTO_ISO);
2099 proto_unregister(&iso_proto);