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 *ba)
509 sk_for_each(sk, &iso_sk_list.head) {
510 if (sk->sk_state != BT_LISTEN)
513 if (!bacmp(&iso_pi(sk)->src, ba))
520 static struct sock *__iso_get_sock_listen_by_sid(bdaddr_t *ba, bdaddr_t *bc,
525 sk_for_each(sk, &iso_sk_list.head) {
526 if (sk->sk_state != BT_LISTEN)
529 if (bacmp(&iso_pi(sk)->src, ba))
532 if (bacmp(&iso_pi(sk)->dst, bc))
535 if (iso_pi(sk)->bc_sid == sid)
542 typedef bool (*iso_sock_match_t)(struct sock *sk, void *data);
544 /* Find socket listening:
545 * source bdaddr (Unicast)
546 * destination bdaddr (Broadcast only)
547 * match func - pass NULL to ignore
548 * match func data - pass -1 to ignore
549 * Returns closest match.
551 static struct sock *iso_get_sock_listen(bdaddr_t *src, bdaddr_t *dst,
552 iso_sock_match_t match, void *data)
554 struct sock *sk = NULL, *sk1 = NULL;
556 read_lock(&iso_sk_list.lock);
558 sk_for_each(sk, &iso_sk_list.head) {
559 if (sk->sk_state != BT_LISTEN)
562 /* Match Broadcast destination */
563 if (bacmp(dst, BDADDR_ANY) && bacmp(&iso_pi(sk)->dst, dst))
566 /* Use Match function if provided */
567 if (match && !match(sk, data))
571 if (!bacmp(&iso_pi(sk)->src, src))
575 if (!bacmp(&iso_pi(sk)->src, BDADDR_ANY))
579 read_unlock(&iso_sk_list.lock);
581 return sk ? sk : sk1;
584 static void iso_sock_destruct(struct sock *sk)
588 skb_queue_purge(&sk->sk_receive_queue);
589 skb_queue_purge(&sk->sk_write_queue);
592 static void iso_sock_cleanup_listen(struct sock *parent)
596 BT_DBG("parent %p", parent);
598 /* Close not yet accepted channels */
599 while ((sk = bt_accept_dequeue(parent, NULL))) {
604 /* If listening socket stands for a PA sync connection,
605 * properly disconnect the hcon and socket.
607 if (iso_pi(parent)->conn && iso_pi(parent)->conn->hcon &&
608 test_bit(HCI_CONN_PA_SYNC, &iso_pi(parent)->conn->hcon->flags)) {
609 iso_sock_disconn(parent);
613 parent->sk_state = BT_CLOSED;
614 sock_set_flag(parent, SOCK_ZAPPED);
617 /* Kill socket (only if zapped and orphan)
618 * Must be called on unlocked socket.
620 static void iso_sock_kill(struct sock *sk)
622 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket ||
623 sock_flag(sk, SOCK_DEAD))
626 BT_DBG("sk %p state %d", sk, sk->sk_state);
628 /* Kill poor orphan */
629 bt_sock_unlink(&iso_sk_list, sk);
630 sock_set_flag(sk, SOCK_DEAD);
634 static void iso_sock_disconn(struct sock *sk)
636 sk->sk_state = BT_DISCONN;
637 iso_sock_set_timer(sk, ISO_DISCONN_TIMEOUT);
638 iso_conn_lock(iso_pi(sk)->conn);
639 hci_conn_drop(iso_pi(sk)->conn->hcon);
640 iso_pi(sk)->conn->hcon = NULL;
641 iso_conn_unlock(iso_pi(sk)->conn);
644 static void __iso_sock_close(struct sock *sk)
646 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
648 switch (sk->sk_state) {
650 iso_sock_cleanup_listen(sk);
656 if (iso_pi(sk)->conn->hcon)
657 iso_sock_disconn(sk);
659 iso_chan_del(sk, ECONNRESET);
663 if (iso_pi(sk)->conn->hcon &&
664 (test_bit(HCI_CONN_PA_SYNC, &iso_pi(sk)->conn->hcon->flags) ||
665 test_bit(HCI_CONN_PA_SYNC_FAILED, &iso_pi(sk)->conn->hcon->flags)))
666 iso_sock_disconn(sk);
668 iso_chan_del(sk, ECONNRESET);
671 iso_chan_del(sk, ECONNRESET);
675 sock_set_flag(sk, SOCK_ZAPPED);
680 /* Must be called on unlocked socket. */
681 static void iso_sock_close(struct sock *sk)
683 iso_sock_clear_timer(sk);
685 __iso_sock_close(sk);
690 static void iso_sock_init(struct sock *sk, struct sock *parent)
695 sk->sk_type = parent->sk_type;
696 bt_sk(sk)->flags = bt_sk(parent)->flags;
697 security_sk_clone(parent, sk);
701 static struct proto iso_proto = {
703 .owner = THIS_MODULE,
704 .obj_size = sizeof(struct iso_pinfo)
707 #define DEFAULT_IO_QOS \
709 .interval = 10000u, \
712 .phy = BT_ISO_PHY_2M, \
716 static struct bt_iso_qos default_qos = {
718 .big = BT_ISO_QOS_BIG_UNSET,
719 .bis = BT_ISO_QOS_BIS_UNSET,
723 .in = DEFAULT_IO_QOS,
724 .out = DEFAULT_IO_QOS,
729 .sync_timeout = 0x4000,
730 .sync_cte_type = 0x00,
736 static struct sock *iso_sock_alloc(struct net *net, struct socket *sock,
737 int proto, gfp_t prio, int kern)
741 sk = bt_sock_alloc(net, sock, &iso_proto, proto, prio, kern);
745 sk->sk_destruct = iso_sock_destruct;
746 sk->sk_sndtimeo = ISO_CONN_TIMEOUT;
748 /* Set address type as public as default src address is BDADDR_ANY */
749 iso_pi(sk)->src_type = BDADDR_LE_PUBLIC;
751 iso_pi(sk)->qos = default_qos;
753 bt_sock_link(&iso_sk_list, sk);
757 static int iso_sock_create(struct net *net, struct socket *sock, int protocol,
762 BT_DBG("sock %p", sock);
764 sock->state = SS_UNCONNECTED;
766 if (sock->type != SOCK_SEQPACKET)
767 return -ESOCKTNOSUPPORT;
769 sock->ops = &iso_sock_ops;
771 sk = iso_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern);
775 iso_sock_init(sk, NULL);
779 static int iso_sock_bind_bc(struct socket *sock, struct sockaddr *addr,
782 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
783 struct sock *sk = sock->sk;
786 BT_DBG("sk %p bc_sid %u bc_num_bis %u", sk, sa->iso_bc->bc_sid,
787 sa->iso_bc->bc_num_bis);
789 if (addr_len > sizeof(*sa) + sizeof(*sa->iso_bc) ||
790 sa->iso_bc->bc_num_bis < 0x01 || sa->iso_bc->bc_num_bis > 0x1f)
793 bacpy(&iso_pi(sk)->dst, &sa->iso_bc->bc_bdaddr);
794 iso_pi(sk)->dst_type = sa->iso_bc->bc_bdaddr_type;
795 iso_pi(sk)->sync_handle = -1;
796 iso_pi(sk)->bc_sid = sa->iso_bc->bc_sid;
797 iso_pi(sk)->bc_num_bis = sa->iso_bc->bc_num_bis;
799 for (i = 0; i < iso_pi(sk)->bc_num_bis; i++) {
800 if (sa->iso_bc->bc_bis[i] < 0x01 ||
801 sa->iso_bc->bc_bis[i] > 0x1f)
804 memcpy(iso_pi(sk)->bc_bis, sa->iso_bc->bc_bis,
805 iso_pi(sk)->bc_num_bis);
811 static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
814 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
815 struct sock *sk = sock->sk;
818 BT_DBG("sk %p %pMR type %u", sk, &sa->iso_bdaddr, sa->iso_bdaddr_type);
820 if (!addr || addr_len < sizeof(struct sockaddr_iso) ||
821 addr->sa_family != AF_BLUETOOTH)
826 if (sk->sk_state != BT_OPEN) {
831 if (sk->sk_type != SOCK_SEQPACKET) {
836 /* Check if the address type is of LE type */
837 if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) {
842 bacpy(&iso_pi(sk)->src, &sa->iso_bdaddr);
843 iso_pi(sk)->src_type = sa->iso_bdaddr_type;
845 /* Check for Broadcast address */
846 if (addr_len > sizeof(*sa)) {
847 err = iso_sock_bind_bc(sock, addr, addr_len);
852 sk->sk_state = BT_BOUND;
859 static int iso_sock_connect(struct socket *sock, struct sockaddr *addr,
862 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
863 struct sock *sk = sock->sk;
868 if (alen < sizeof(struct sockaddr_iso) ||
869 addr->sa_family != AF_BLUETOOTH)
872 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
875 if (sk->sk_type != SOCK_SEQPACKET)
878 /* Check if the address type is of LE type */
879 if (!bdaddr_type_is_le(sa->iso_bdaddr_type))
884 bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr);
885 iso_pi(sk)->dst_type = sa->iso_bdaddr_type;
889 if (bacmp(&iso_pi(sk)->dst, BDADDR_ANY))
890 err = iso_connect_cis(sk);
892 err = iso_connect_bis(sk);
899 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
900 err = bt_sock_wait_state(sk, BT_CONNECTED,
901 sock_sndtimeo(sk, flags & O_NONBLOCK));
908 static int iso_listen_bis(struct sock *sk)
910 struct hci_dev *hdev;
913 BT_DBG("%pMR -> %pMR (SID 0x%2.2x)", &iso_pi(sk)->src,
914 &iso_pi(sk)->dst, iso_pi(sk)->bc_sid);
916 write_lock(&iso_sk_list.lock);
918 if (__iso_get_sock_listen_by_sid(&iso_pi(sk)->src, &iso_pi(sk)->dst,
922 write_unlock(&iso_sk_list.lock);
927 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src,
928 iso_pi(sk)->src_type);
930 return -EHOSTUNREACH;
932 /* Fail if user set invalid QoS */
933 if (iso_pi(sk)->qos_user_set && !check_bcast_qos(&iso_pi(sk)->qos)) {
934 iso_pi(sk)->qos = default_qos;
938 err = hci_pa_create_sync(hdev, &iso_pi(sk)->dst,
939 le_addr_type(iso_pi(sk)->dst_type),
940 iso_pi(sk)->bc_sid, &iso_pi(sk)->qos);
947 static int iso_listen_cis(struct sock *sk)
951 BT_DBG("%pMR", &iso_pi(sk)->src);
953 write_lock(&iso_sk_list.lock);
955 if (__iso_get_sock_listen_by_addr(&iso_pi(sk)->src))
958 write_unlock(&iso_sk_list.lock);
963 static int iso_sock_listen(struct socket *sock, int backlog)
965 struct sock *sk = sock->sk;
968 BT_DBG("sk %p backlog %d", sk, backlog);
972 if (sk->sk_state != BT_BOUND) {
977 if (sk->sk_type != SOCK_SEQPACKET) {
982 if (!bacmp(&iso_pi(sk)->dst, BDADDR_ANY))
983 err = iso_listen_cis(sk);
985 err = iso_listen_bis(sk);
990 sk->sk_max_ack_backlog = backlog;
991 sk->sk_ack_backlog = 0;
993 sk->sk_state = BT_LISTEN;
1000 static int iso_sock_accept(struct socket *sock, struct socket *newsock,
1001 int flags, bool kern)
1003 DEFINE_WAIT_FUNC(wait, woken_wake_function);
1004 struct sock *sk = sock->sk, *ch;
1010 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
1012 BT_DBG("sk %p timeo %ld", sk, timeo);
1014 /* Wait for an incoming connection. (wake-one). */
1015 add_wait_queue_exclusive(sk_sleep(sk), &wait);
1017 if (sk->sk_state != BT_LISTEN) {
1022 ch = bt_accept_dequeue(sk, newsock);
1031 if (signal_pending(current)) {
1032 err = sock_intr_errno(timeo);
1038 timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo);
1041 remove_wait_queue(sk_sleep(sk), &wait);
1046 newsock->state = SS_CONNECTED;
1048 BT_DBG("new socket %p", ch);
1055 static int iso_sock_getname(struct socket *sock, struct sockaddr *addr,
1058 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
1059 struct sock *sk = sock->sk;
1061 BT_DBG("sock %p, sk %p", sock, sk);
1063 addr->sa_family = AF_BLUETOOTH;
1066 bacpy(&sa->iso_bdaddr, &iso_pi(sk)->dst);
1067 sa->iso_bdaddr_type = iso_pi(sk)->dst_type;
1069 bacpy(&sa->iso_bdaddr, &iso_pi(sk)->src);
1070 sa->iso_bdaddr_type = iso_pi(sk)->src_type;
1073 return sizeof(struct sockaddr_iso);
1076 static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
1079 struct sock *sk = sock->sk;
1080 struct sk_buff *skb, **frag;
1084 BT_DBG("sock %p, sk %p", sock, sk);
1086 err = sock_error(sk);
1090 if (msg->msg_flags & MSG_OOB)
1095 if (sk->sk_state != BT_CONNECTED) {
1100 mtu = iso_pi(sk)->conn->hcon->hdev->iso_mtu;
1104 skb = bt_skb_sendmsg(sk, msg, len, mtu, HCI_ISO_DATA_HDR_SIZE, 0);
1106 return PTR_ERR(skb);
1110 BT_DBG("skb %p len %d", sk, skb->len);
1112 /* Continuation fragments */
1113 frag = &skb_shinfo(skb)->frag_list;
1115 struct sk_buff *tmp;
1117 tmp = bt_skb_sendmsg(sk, msg, len, mtu, 0, 0);
1120 return PTR_ERR(tmp);
1127 skb->len += tmp->len;
1128 skb->data_len += tmp->len;
1130 BT_DBG("frag %p len %d", *frag, tmp->len);
1132 frag = &(*frag)->next;
1137 if (sk->sk_state == BT_CONNECTED)
1138 err = iso_send_frame(sk, skb);
1149 static void iso_conn_defer_accept(struct hci_conn *conn)
1151 struct hci_cp_le_accept_cis cp;
1152 struct hci_dev *hdev = conn->hdev;
1154 BT_DBG("conn %p", conn);
1156 conn->state = BT_CONFIG;
1158 cp.handle = cpu_to_le16(conn->handle);
1160 hci_send_cmd(hdev, HCI_OP_LE_ACCEPT_CIS, sizeof(cp), &cp);
1163 static void iso_conn_big_sync(struct sock *sk)
1166 struct hci_dev *hdev;
1168 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src,
1169 iso_pi(sk)->src_type);
1174 if (!test_and_set_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
1175 err = hci_le_big_create_sync(hdev, iso_pi(sk)->conn->hcon,
1177 iso_pi(sk)->sync_handle,
1178 iso_pi(sk)->bc_num_bis,
1179 iso_pi(sk)->bc_bis);
1181 bt_dev_err(hdev, "hci_le_big_create_sync: %d",
1186 static int iso_sock_recvmsg(struct socket *sock, struct msghdr *msg,
1187 size_t len, int flags)
1189 struct sock *sk = sock->sk;
1190 struct iso_pinfo *pi = iso_pi(sk);
1192 BT_DBG("sk %p", sk);
1194 if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
1196 switch (sk->sk_state) {
1198 if (pi->conn->hcon &&
1199 test_bit(HCI_CONN_PA_SYNC, &pi->conn->hcon->flags)) {
1200 iso_conn_big_sync(sk);
1201 sk->sk_state = BT_LISTEN;
1202 set_bit(BT_SK_PA_SYNC, &iso_pi(sk)->flags);
1204 iso_conn_defer_accept(pi->conn->hcon);
1205 sk->sk_state = BT_CONFIG;
1211 return iso_connect_cis(sk);
1218 return bt_sock_recvmsg(sock, msg, len, flags);
1221 static bool check_io_qos(struct bt_iso_io_qos *qos)
1223 /* If no PHY is enable SDU must be 0 */
1224 if (!qos->phy && qos->sdu)
1227 if (qos->interval && (qos->interval < 0xff || qos->interval > 0xfffff))
1230 if (qos->latency && (qos->latency < 0x05 || qos->latency > 0xfa0))
1233 if (qos->phy > BT_ISO_PHY_ANY)
1239 static bool check_ucast_qos(struct bt_iso_qos *qos)
1241 if (qos->ucast.cig > 0xef && qos->ucast.cig != BT_ISO_QOS_CIG_UNSET)
1244 if (qos->ucast.cis > 0xef && qos->ucast.cis != BT_ISO_QOS_CIS_UNSET)
1247 if (qos->ucast.sca > 0x07)
1250 if (qos->ucast.packing > 0x01)
1253 if (qos->ucast.framing > 0x01)
1256 if (!check_io_qos(&qos->ucast.in))
1259 if (!check_io_qos(&qos->ucast.out))
1265 static bool check_bcast_qos(struct bt_iso_qos *qos)
1267 if (qos->bcast.sync_factor == 0x00)
1270 if (qos->bcast.packing > 0x01)
1273 if (qos->bcast.framing > 0x01)
1276 if (!check_io_qos(&qos->bcast.in))
1279 if (!check_io_qos(&qos->bcast.out))
1282 if (qos->bcast.encryption > 0x01)
1285 if (qos->bcast.options > 0x07)
1288 if (qos->bcast.skip > 0x01f3)
1291 if (qos->bcast.sync_timeout < 0x000a || qos->bcast.sync_timeout > 0x4000)
1294 if (qos->bcast.sync_cte_type > 0x1f)
1297 if (qos->bcast.mse > 0x1f)
1300 if (qos->bcast.timeout < 0x000a || qos->bcast.timeout > 0x4000)
1306 static int iso_sock_setsockopt(struct socket *sock, int level, int optname,
1307 sockptr_t optval, unsigned int optlen)
1309 struct sock *sk = sock->sk;
1311 struct bt_iso_qos qos = default_qos;
1314 BT_DBG("sk %p", sk);
1319 case BT_DEFER_SETUP:
1320 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
1325 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
1331 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
1333 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
1337 if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
1343 set_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags);
1345 clear_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags);
1349 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
1350 sk->sk_state != BT_CONNECT2) {
1355 len = min_t(unsigned int, sizeof(qos), optlen);
1357 if (copy_from_sockptr(&qos, optval, len)) {
1362 if (len == sizeof(qos.ucast) && !check_ucast_qos(&qos)) {
1367 iso_pi(sk)->qos = qos;
1368 iso_pi(sk)->qos_user_set = true;
1373 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
1374 sk->sk_state != BT_CONNECT2) {
1379 if (optlen > sizeof(iso_pi(sk)->base)) {
1384 len = min_t(unsigned int, sizeof(iso_pi(sk)->base), optlen);
1386 if (copy_from_sockptr(iso_pi(sk)->base, optval, len)) {
1391 iso_pi(sk)->base_len = len;
1404 static int iso_sock_getsockopt(struct socket *sock, int level, int optname,
1405 char __user *optval, int __user *optlen)
1407 struct sock *sk = sock->sk;
1409 struct bt_iso_qos *qos;
1413 BT_DBG("sk %p", sk);
1415 if (get_user(len, optlen))
1421 case BT_DEFER_SETUP:
1422 if (sk->sk_state == BT_CONNECTED) {
1427 if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags),
1428 (u32 __user *)optval))
1434 if (put_user(test_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags),
1435 (int __user *)optval))
1440 qos = iso_sock_get_qos(sk);
1442 len = min_t(unsigned int, len, sizeof(*qos));
1443 if (copy_to_user(optval, qos, len))
1449 if (sk->sk_state == BT_CONNECTED &&
1450 !bacmp(&iso_pi(sk)->dst, BDADDR_ANY)) {
1451 base_len = iso_pi(sk)->conn->hcon->le_per_adv_data_len;
1452 base = iso_pi(sk)->conn->hcon->le_per_adv_data;
1454 base_len = iso_pi(sk)->base_len;
1455 base = iso_pi(sk)->base;
1458 len = min_t(unsigned int, len, base_len);
1459 if (copy_to_user(optval, base, len))
1473 static int iso_sock_shutdown(struct socket *sock, int how)
1475 struct sock *sk = sock->sk;
1478 BT_DBG("sock %p, sk %p, how %d", sock, sk, how);
1488 if (sk->sk_shutdown & RCV_SHUTDOWN)
1490 sk->sk_shutdown |= RCV_SHUTDOWN;
1493 if (sk->sk_shutdown & SEND_SHUTDOWN)
1495 sk->sk_shutdown |= SEND_SHUTDOWN;
1498 if (sk->sk_shutdown & SHUTDOWN_MASK)
1500 sk->sk_shutdown |= SHUTDOWN_MASK;
1504 iso_sock_clear_timer(sk);
1505 __iso_sock_close(sk);
1507 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
1508 !(current->flags & PF_EXITING))
1509 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
1518 static int iso_sock_release(struct socket *sock)
1520 struct sock *sk = sock->sk;
1523 BT_DBG("sock %p, sk %p", sock, sk);
1530 if (sock_flag(sk, SOCK_LINGER) && READ_ONCE(sk->sk_lingertime) &&
1531 !(current->flags & PF_EXITING)) {
1533 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
1542 static void iso_sock_ready(struct sock *sk)
1544 BT_DBG("sk %p", sk);
1550 iso_sock_clear_timer(sk);
1551 sk->sk_state = BT_CONNECTED;
1552 sk->sk_state_change(sk);
1556 struct iso_list_data {
1557 struct hci_conn *hcon;
1561 static bool iso_match_big(struct sock *sk, void *data)
1563 struct hci_evt_le_big_sync_estabilished *ev = data;
1565 return ev->handle == iso_pi(sk)->qos.bcast.big;
1568 static bool iso_match_pa_sync_flag(struct sock *sk, void *data)
1570 return test_bit(BT_SK_PA_SYNC, &iso_pi(sk)->flags);
1573 static void iso_conn_ready(struct iso_conn *conn)
1575 struct sock *parent = NULL;
1576 struct sock *sk = conn->sk;
1577 struct hci_ev_le_big_sync_estabilished *ev = NULL;
1578 struct hci_ev_le_pa_sync_established *ev2 = NULL;
1579 struct hci_conn *hcon;
1581 BT_DBG("conn %p", conn);
1584 iso_sock_ready(conn->sk);
1590 if (test_bit(HCI_CONN_BIG_SYNC, &hcon->flags) ||
1591 test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags)) {
1592 ev = hci_recv_event_data(hcon->hdev,
1593 HCI_EVT_LE_BIG_SYNC_ESTABILISHED);
1595 /* Get reference to PA sync parent socket, if it exists */
1596 parent = iso_get_sock_listen(&hcon->src,
1598 iso_match_pa_sync_flag, NULL);
1600 parent = iso_get_sock_listen(&hcon->src,
1603 } else if (test_bit(HCI_CONN_PA_SYNC, &hcon->flags) ||
1604 test_bit(HCI_CONN_PA_SYNC_FAILED, &hcon->flags)) {
1605 ev2 = hci_recv_event_data(hcon->hdev,
1606 HCI_EV_LE_PA_SYNC_ESTABLISHED);
1608 parent = iso_get_sock_listen(&hcon->src,
1610 iso_match_sid, ev2);
1614 parent = iso_get_sock_listen(&hcon->src,
1615 BDADDR_ANY, NULL, NULL);
1622 sk = iso_sock_alloc(sock_net(parent), NULL,
1623 BTPROTO_ISO, GFP_ATOMIC, 0);
1625 release_sock(parent);
1629 iso_sock_init(sk, parent);
1631 bacpy(&iso_pi(sk)->src, &hcon->src);
1633 /* Convert from HCI to three-value type */
1634 if (hcon->src_type == ADDR_LE_DEV_PUBLIC)
1635 iso_pi(sk)->src_type = BDADDR_LE_PUBLIC;
1637 iso_pi(sk)->src_type = BDADDR_LE_RANDOM;
1639 /* If hcon has no destination address (BDADDR_ANY) it means it
1640 * was created by HCI_EV_LE_BIG_SYNC_ESTABILISHED or
1641 * HCI_EV_LE_PA_SYNC_ESTABLISHED so we need to initialize using
1642 * the parent socket destination address.
1644 if (!bacmp(&hcon->dst, BDADDR_ANY)) {
1645 bacpy(&hcon->dst, &iso_pi(parent)->dst);
1646 hcon->dst_type = iso_pi(parent)->dst_type;
1647 hcon->sync_handle = iso_pi(parent)->sync_handle;
1650 if (ev2 && !ev2->status) {
1651 iso_pi(sk)->sync_handle = iso_pi(parent)->sync_handle;
1652 iso_pi(sk)->qos = iso_pi(parent)->qos;
1653 iso_pi(sk)->bc_num_bis = iso_pi(parent)->bc_num_bis;
1654 memcpy(iso_pi(sk)->bc_bis, iso_pi(parent)->bc_bis, ISO_MAX_NUM_BIS);
1657 bacpy(&iso_pi(sk)->dst, &hcon->dst);
1658 iso_pi(sk)->dst_type = hcon->dst_type;
1659 iso_pi(sk)->sync_handle = iso_pi(parent)->sync_handle;
1660 memcpy(iso_pi(sk)->base, iso_pi(parent)->base, iso_pi(parent)->base_len);
1661 iso_pi(sk)->base_len = iso_pi(parent)->base_len;
1663 hci_conn_hold(hcon);
1664 iso_chan_add(conn, sk, parent);
1666 if ((ev && ((struct hci_evt_le_big_sync_estabilished *)ev)->status) ||
1667 (ev2 && ev2->status)) {
1668 /* Trigger error signal on child socket */
1669 sk->sk_err = ECONNREFUSED;
1670 sk->sk_error_report(sk);
1673 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
1674 sk->sk_state = BT_CONNECT2;
1676 sk->sk_state = BT_CONNECTED;
1678 /* Wake up parent */
1679 parent->sk_data_ready(parent);
1681 release_sock(parent);
1685 static bool iso_match_sid(struct sock *sk, void *data)
1687 struct hci_ev_le_pa_sync_established *ev = data;
1689 return ev->sid == iso_pi(sk)->bc_sid;
1692 static bool iso_match_sync_handle(struct sock *sk, void *data)
1694 struct hci_evt_le_big_info_adv_report *ev = data;
1696 return le16_to_cpu(ev->sync_handle) == iso_pi(sk)->sync_handle;
1699 static bool iso_match_sync_handle_pa_report(struct sock *sk, void *data)
1701 struct hci_ev_le_per_adv_report *ev = data;
1703 return le16_to_cpu(ev->sync_handle) == iso_pi(sk)->sync_handle;
1706 /* ----- ISO interface with lower layer (HCI) ----- */
1708 int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
1710 struct hci_ev_le_pa_sync_established *ev1;
1711 struct hci_evt_le_big_info_adv_report *ev2;
1712 struct hci_ev_le_per_adv_report *ev3;
1716 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr);
1718 /* Broadcast receiver requires handling of some events before it can
1719 * proceed to establishing a BIG sync:
1721 * 1. HCI_EV_LE_PA_SYNC_ESTABLISHED: The socket may specify a specific
1722 * SID to listen to and once sync is estabilished its handle needs to
1723 * be stored in iso_pi(sk)->sync_handle so it can be matched once
1724 * receiving the BIG Info.
1725 * 2. HCI_EVT_LE_BIG_INFO_ADV_REPORT: When connect_ind is triggered by a
1726 * a BIG Info it attempts to check if there any listening socket with
1727 * the same sync_handle and if it does then attempt to create a sync.
1728 * 3. HCI_EV_LE_PER_ADV_REPORT: When a PA report is received, it is stored
1729 * in iso_pi(sk)->base so it can be passed up to user, in the case of a
1732 ev1 = hci_recv_event_data(hdev, HCI_EV_LE_PA_SYNC_ESTABLISHED);
1734 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr, iso_match_sid,
1736 if (sk && !ev1->status)
1737 iso_pi(sk)->sync_handle = le16_to_cpu(ev1->handle);
1742 ev2 = hci_recv_event_data(hdev, HCI_EVT_LE_BIG_INFO_ADV_REPORT);
1744 /* Try to get PA sync listening socket, if it exists */
1745 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr,
1746 iso_match_pa_sync_flag, NULL);
1748 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr,
1749 iso_match_sync_handle, ev2);
1753 if (ev2->num_bis < iso_pi(sk)->bc_num_bis)
1754 iso_pi(sk)->bc_num_bis = ev2->num_bis;
1756 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags) &&
1757 !test_and_set_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
1758 err = hci_le_big_create_sync(hdev, NULL,
1760 iso_pi(sk)->sync_handle,
1761 iso_pi(sk)->bc_num_bis,
1762 iso_pi(sk)->bc_bis);
1764 bt_dev_err(hdev, "hci_le_big_create_sync: %d",
1772 ev3 = hci_recv_event_data(hdev, HCI_EV_LE_PER_ADV_REPORT);
1774 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr,
1775 iso_match_sync_handle_pa_report, ev3);
1778 memcpy(iso_pi(sk)->base, ev3->data, ev3->length);
1779 iso_pi(sk)->base_len = ev3->length;
1782 sk = iso_get_sock_listen(&hdev->bdaddr, BDADDR_ANY, NULL, NULL);
1789 lm |= HCI_LM_ACCEPT;
1791 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))
1792 *flags |= HCI_PROTO_DEFER;
1797 static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
1799 if (hcon->type != ISO_LINK) {
1800 if (hcon->type != LE_LINK)
1803 /* Check if LE link has failed */
1805 struct hci_link *link, *t;
1807 list_for_each_entry_safe(link, t, &hcon->link_list,
1809 iso_conn_del(link->conn, bt_to_errno(status));
1814 /* Create CIS if pending */
1815 hci_le_create_cis_pending(hcon->hdev);
1819 BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
1821 /* Similar to the success case, if HCI_CONN_BIG_SYNC_FAILED or
1822 * HCI_CONN_PA_SYNC_FAILED is set, queue the failed connection
1823 * into the accept queue of the listening socket and wake up
1824 * userspace, to inform the user about the event.
1826 if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags) ||
1827 test_bit(HCI_CONN_PA_SYNC_FAILED, &hcon->flags)) {
1828 struct iso_conn *conn;
1830 conn = iso_conn_add(hcon);
1832 iso_conn_ready(conn);
1834 iso_conn_del(hcon, bt_to_errno(status));
1838 static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason)
1840 if (hcon->type != ISO_LINK)
1843 BT_DBG("hcon %p reason %d", hcon, reason);
1845 iso_conn_del(hcon, bt_to_errno(reason));
1848 void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
1850 struct iso_conn *conn = hcon->iso_data;
1856 pb = hci_iso_flags_pb(flags);
1857 ts = hci_iso_flags_ts(flags);
1859 BT_DBG("conn %p len %d pb 0x%x ts 0x%x", conn, skb->len, pb, ts);
1865 BT_ERR("Unexpected start frame (len %d)", skb->len);
1866 kfree_skb(conn->rx_skb);
1867 conn->rx_skb = NULL;
1872 struct hci_iso_ts_data_hdr *hdr;
1874 /* TODO: add timestamp to the packet? */
1875 hdr = skb_pull_data(skb, HCI_ISO_TS_DATA_HDR_SIZE);
1877 BT_ERR("Frame is too short (len %d)", skb->len);
1881 len = __le16_to_cpu(hdr->slen);
1883 struct hci_iso_data_hdr *hdr;
1885 hdr = skb_pull_data(skb, HCI_ISO_DATA_HDR_SIZE);
1887 BT_ERR("Frame is too short (len %d)", skb->len);
1891 len = __le16_to_cpu(hdr->slen);
1894 flags = hci_iso_data_flags(len);
1895 len = hci_iso_data_len(len);
1897 BT_DBG("Start: total len %d, frag len %d flags 0x%4.4x", len,
1900 if (len == skb->len) {
1901 /* Complete frame received */
1902 hci_skb_pkt_status(skb) = flags & 0x03;
1903 iso_recv_frame(conn, skb);
1907 if (pb == ISO_SINGLE) {
1908 BT_ERR("Frame malformed (len %d, expected len %d)",
1913 if (skb->len > len) {
1914 BT_ERR("Frame is too long (len %d, expected len %d)",
1919 /* Allocate skb for the complete frame (with header) */
1920 conn->rx_skb = bt_skb_alloc(len, GFP_KERNEL);
1924 hci_skb_pkt_status(conn->rx_skb) = flags & 0x03;
1925 skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
1927 conn->rx_len = len - skb->len;
1931 BT_DBG("Cont: frag len %d (expecting %d)", skb->len,
1934 if (!conn->rx_len) {
1935 BT_ERR("Unexpected continuation frame (len %d)",
1940 if (skb->len > conn->rx_len) {
1941 BT_ERR("Fragment is too long (len %d, expected %d)",
1942 skb->len, conn->rx_len);
1943 kfree_skb(conn->rx_skb);
1944 conn->rx_skb = NULL;
1949 skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
1951 conn->rx_len -= skb->len;
1955 skb_copy_from_linear_data(skb, skb_put(conn->rx_skb, skb->len),
1957 conn->rx_len -= skb->len;
1959 if (!conn->rx_len) {
1960 struct sk_buff *rx_skb = conn->rx_skb;
1962 /* Complete frame received. iso_recv_frame
1963 * takes ownership of the skb so set the global
1964 * rx_skb pointer to NULL first.
1966 conn->rx_skb = NULL;
1967 iso_recv_frame(conn, rx_skb);
1976 static struct hci_cb iso_cb = {
1978 .connect_cfm = iso_connect_cfm,
1979 .disconn_cfm = iso_disconn_cfm,
1982 static int iso_debugfs_show(struct seq_file *f, void *p)
1986 read_lock(&iso_sk_list.lock);
1988 sk_for_each(sk, &iso_sk_list.head) {
1989 seq_printf(f, "%pMR %pMR %d\n", &iso_pi(sk)->src,
1990 &iso_pi(sk)->dst, sk->sk_state);
1993 read_unlock(&iso_sk_list.lock);
1998 DEFINE_SHOW_ATTRIBUTE(iso_debugfs);
2000 static struct dentry *iso_debugfs;
2002 static const struct proto_ops iso_sock_ops = {
2003 .family = PF_BLUETOOTH,
2004 .owner = THIS_MODULE,
2005 .release = iso_sock_release,
2006 .bind = iso_sock_bind,
2007 .connect = iso_sock_connect,
2008 .listen = iso_sock_listen,
2009 .accept = iso_sock_accept,
2010 .getname = iso_sock_getname,
2011 .sendmsg = iso_sock_sendmsg,
2012 .recvmsg = iso_sock_recvmsg,
2013 .poll = bt_sock_poll,
2014 .ioctl = bt_sock_ioctl,
2015 .mmap = sock_no_mmap,
2016 .socketpair = sock_no_socketpair,
2017 .shutdown = iso_sock_shutdown,
2018 .setsockopt = iso_sock_setsockopt,
2019 .getsockopt = iso_sock_getsockopt
2022 static const struct net_proto_family iso_sock_family_ops = {
2023 .family = PF_BLUETOOTH,
2024 .owner = THIS_MODULE,
2025 .create = iso_sock_create,
2028 static bool iso_inited;
2030 bool iso_enabled(void)
2039 BUILD_BUG_ON(sizeof(struct sockaddr_iso) > sizeof(struct sockaddr));
2044 err = proto_register(&iso_proto, 0);
2048 err = bt_sock_register(BTPROTO_ISO, &iso_sock_family_ops);
2050 BT_ERR("ISO socket registration failed");
2054 err = bt_procfs_init(&init_net, "iso", &iso_sk_list, NULL);
2056 BT_ERR("Failed to create ISO proc file");
2057 bt_sock_unregister(BTPROTO_ISO);
2061 BT_INFO("ISO socket layer initialized");
2063 hci_register_cb(&iso_cb);
2065 if (IS_ERR_OR_NULL(bt_debugfs))
2069 iso_debugfs = debugfs_create_file("iso", 0444, bt_debugfs,
2070 NULL, &iso_debugfs_fops);
2078 proto_unregister(&iso_proto);
2087 bt_procfs_cleanup(&init_net, "iso");
2089 debugfs_remove(iso_debugfs);
2092 hci_unregister_cb(&iso_cb);
2094 bt_sock_unregister(BTPROTO_ISO);
2096 proto_unregister(&iso_proto);