iso.c (ccf74f2390d60a2f9a75ef496d2564abb478f46a) | iso.c (f764a6c2c1e446f560faa3232271a0637369170b) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2022 Intel Corporation 6 */ 7 8#include <linux/module.h> --- 36 unchanged lines hidden (view full) --- 45#define iso_pi(sk) ((struct iso_pinfo *)sk) 46 47struct iso_pinfo { 48 struct bt_sock bt; 49 bdaddr_t src; 50 __u8 src_type; 51 bdaddr_t dst; 52 __u8 dst_type; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2022 Intel Corporation 6 */ 7 8#include <linux/module.h> --- 36 unchanged lines hidden (view full) --- 45#define iso_pi(sk) ((struct iso_pinfo *)sk) 46 47struct iso_pinfo { 48 struct bt_sock bt; 49 bdaddr_t src; 50 __u8 src_type; 51 bdaddr_t dst; 52 __u8 dst_type; |
53 __u8 bc_sid; 54 __u8 bc_num_bis; 55 __u8 bc_bis[ISO_MAX_NUM_BIS]; 56 __u16 sync_handle; |
|
53 __u32 flags; 54 struct bt_iso_qos qos; | 57 __u32 flags; 58 struct bt_iso_qos qos; |
59 __u8 base_len; 60 __u8 base[HCI_MAX_PER_AD_LENGTH]; |
|
55 struct iso_conn *conn; 56}; 57 58/* ---- ISO timers ---- */ 59#define ISO_CONN_TIMEOUT (HZ * 40) 60#define ISO_DISCONN_TIMEOUT (HZ * 2) 61 62static void iso_sock_timeout(struct work_struct *work) --- 62 unchanged lines hidden (view full) --- 125 126 return conn; 127} 128 129/* Delete channel. Must be called on the locked socket. */ 130static void iso_chan_del(struct sock *sk, int err) 131{ 132 struct iso_conn *conn; | 61 struct iso_conn *conn; 62}; 63 64/* ---- ISO timers ---- */ 65#define ISO_CONN_TIMEOUT (HZ * 40) 66#define ISO_DISCONN_TIMEOUT (HZ * 2) 67 68static void iso_sock_timeout(struct work_struct *work) --- 62 unchanged lines hidden (view full) --- 131 132 return conn; 133} 134 135/* Delete channel. Must be called on the locked socket. */ 136static void iso_chan_del(struct sock *sk, int err) 137{ 138 struct iso_conn *conn; |
139 struct sock *parent; |
|
133 134 conn = iso_pi(sk)->conn; 135 136 BT_DBG("sk %p, conn %p, err %d", sk, conn, err); 137 138 if (conn) { 139 iso_conn_lock(conn); 140 conn->sk = NULL; 141 iso_pi(sk)->conn = NULL; 142 iso_conn_unlock(conn); 143 144 if (conn->hcon) 145 hci_conn_drop(conn->hcon); 146 } 147 148 sk->sk_state = BT_CLOSED; 149 sk->sk_err = err; | 140 141 conn = iso_pi(sk)->conn; 142 143 BT_DBG("sk %p, conn %p, err %d", sk, conn, err); 144 145 if (conn) { 146 iso_conn_lock(conn); 147 conn->sk = NULL; 148 iso_pi(sk)->conn = NULL; 149 iso_conn_unlock(conn); 150 151 if (conn->hcon) 152 hci_conn_drop(conn->hcon); 153 } 154 155 sk->sk_state = BT_CLOSED; 156 sk->sk_err = err; |
150 sk->sk_state_change(sk); | |
151 | 157 |
158 parent = bt_sk(sk)->parent; 159 if (parent) { 160 bt_accept_unlink(sk); 161 parent->sk_data_ready(parent); 162 } else { 163 sk->sk_state_change(sk); 164 } 165 |
|
152 sock_set_flag(sk, SOCK_ZAPPED); 153} 154 155static void iso_conn_del(struct hci_conn *hcon, int err) 156{ 157 struct iso_conn *conn = hcon->iso_data; 158 struct sock *sk; 159 --- 53 unchanged lines hidden (view full) --- 213 214 iso_conn_lock(conn); 215 err = __iso_chan_add(conn, sk, parent); 216 iso_conn_unlock(conn); 217 218 return err; 219} 220 | 166 sock_set_flag(sk, SOCK_ZAPPED); 167} 168 169static void iso_conn_del(struct hci_conn *hcon, int err) 170{ 171 struct iso_conn *conn = hcon->iso_data; 172 struct sock *sk; 173 --- 53 unchanged lines hidden (view full) --- 227 228 iso_conn_lock(conn); 229 err = __iso_chan_add(conn, sk, parent); 230 iso_conn_unlock(conn); 231 232 return err; 233} 234 |
221static int iso_connect(struct sock *sk) | 235static int iso_connect_bis(struct sock *sk) |
222{ 223 struct iso_conn *conn; 224 struct hci_conn *hcon; 225 struct hci_dev *hdev; 226 int err; 227 | 236{ 237 struct iso_conn *conn; 238 struct hci_conn *hcon; 239 struct hci_dev *hdev; 240 int err; 241 |
242 BT_DBG("%pMR", &iso_pi(sk)->src); 243 244 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src, 245 iso_pi(sk)->src_type); 246 if (!hdev) 247 return -EHOSTUNREACH; 248 249 hci_dev_lock(hdev); 250 251 if (!bis_capable(hdev)) { 252 err = -EOPNOTSUPP; 253 goto done; 254 } 255 256 /* Fail if out PHYs are marked as disabled */ 257 if (!iso_pi(sk)->qos.out.phy) { 258 err = -EINVAL; 259 goto done; 260 } 261 262 hcon = hci_connect_bis(hdev, &iso_pi(sk)->dst, iso_pi(sk)->dst_type, 263 &iso_pi(sk)->qos, iso_pi(sk)->base_len, 264 iso_pi(sk)->base); 265 if (IS_ERR(hcon)) { 266 err = PTR_ERR(hcon); 267 goto done; 268 } 269 270 conn = iso_conn_add(hcon); 271 if (!conn) { 272 hci_conn_drop(hcon); 273 err = -ENOMEM; 274 goto done; 275 } 276 277 /* Update source addr of the socket */ 278 bacpy(&iso_pi(sk)->src, &hcon->src); 279 280 err = iso_chan_add(conn, sk, NULL); 281 if (err) 282 goto done; 283 284 if (hcon->state == BT_CONNECTED) { 285 iso_sock_clear_timer(sk); 286 sk->sk_state = BT_CONNECTED; 287 } else { 288 sk->sk_state = BT_CONNECT; 289 iso_sock_set_timer(sk, sk->sk_sndtimeo); 290 } 291 292done: 293 hci_dev_unlock(hdev); 294 hci_dev_put(hdev); 295 return err; 296} 297 298static int iso_connect_cis(struct sock *sk) 299{ 300 struct iso_conn *conn; 301 struct hci_conn *hcon; 302 struct hci_dev *hdev; 303 int err; 304 |
|
228 BT_DBG("%pMR -> %pMR", &iso_pi(sk)->src, &iso_pi(sk)->dst); 229 230 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src, 231 iso_pi(sk)->src_type); 232 if (!hdev) 233 return -EHOSTUNREACH; 234 235 hci_dev_lock(hdev); --- 118 unchanged lines hidden (view full) --- 354 355 if (!bacmp(&iso_pi(sk)->src, ba)) 356 return sk; 357 } 358 359 return NULL; 360} 361 | 305 BT_DBG("%pMR -> %pMR", &iso_pi(sk)->src, &iso_pi(sk)->dst); 306 307 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src, 308 iso_pi(sk)->src_type); 309 if (!hdev) 310 return -EHOSTUNREACH; 311 312 hci_dev_lock(hdev); --- 118 unchanged lines hidden (view full) --- 431 432 if (!bacmp(&iso_pi(sk)->src, ba)) 433 return sk; 434 } 435 436 return NULL; 437} 438 |
362/* Find socket listening on source bdaddr. | 439static struct sock *__iso_get_sock_listen_by_sid(bdaddr_t *ba, bdaddr_t *bc, 440 __u8 sid) 441{ 442 struct sock *sk; 443 444 sk_for_each(sk, &iso_sk_list.head) { 445 if (sk->sk_state != BT_LISTEN) 446 continue; 447 448 if (bacmp(&iso_pi(sk)->src, ba)) 449 continue; 450 451 if (bacmp(&iso_pi(sk)->dst, bc)) 452 continue; 453 454 if (iso_pi(sk)->bc_sid == sid) 455 return sk; 456 } 457 458 return NULL; 459} 460 461typedef bool (*iso_sock_match_t)(struct sock *sk, void *data); 462 463/* Find socket listening: 464 * source bdaddr (Unicast) 465 * destination bdaddr (Broadcast only) 466 * match func - pass NULL to ignore 467 * match func data - pass -1 to ignore |
363 * Returns closest match. 364 */ | 468 * Returns closest match. 469 */ |
365static struct sock *iso_get_sock_listen(bdaddr_t *src) | 470static struct sock *iso_get_sock_listen(bdaddr_t *src, bdaddr_t *dst, 471 iso_sock_match_t match, void *data) |
366{ 367 struct sock *sk = NULL, *sk1 = NULL; 368 369 read_lock(&iso_sk_list.lock); 370 371 sk_for_each(sk, &iso_sk_list.head) { 372 if (sk->sk_state != BT_LISTEN) 373 continue; 374 | 472{ 473 struct sock *sk = NULL, *sk1 = NULL; 474 475 read_lock(&iso_sk_list.lock); 476 477 sk_for_each(sk, &iso_sk_list.head) { 478 if (sk->sk_state != BT_LISTEN) 479 continue; 480 |
481 /* Match Broadcast destination */ 482 if (bacmp(dst, BDADDR_ANY) && bacmp(&iso_pi(sk)->dst, dst)) 483 continue; 484 485 /* Use Match function if provided */ 486 if (match && !match(sk, data)) 487 continue; 488 |
|
375 /* Exact match. */ 376 if (!bacmp(&iso_pi(sk)->src, src)) 377 break; 378 379 /* Closest match */ 380 if (!bacmp(&iso_pi(sk)->src, BDADDR_ANY)) 381 sk1 = sk; 382 } --- 199 unchanged lines hidden (view full) --- 582 sk = iso_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern); 583 if (!sk) 584 return -ENOMEM; 585 586 iso_sock_init(sk, NULL); 587 return 0; 588} 589 | 489 /* Exact match. */ 490 if (!bacmp(&iso_pi(sk)->src, src)) 491 break; 492 493 /* Closest match */ 494 if (!bacmp(&iso_pi(sk)->src, BDADDR_ANY)) 495 sk1 = sk; 496 } --- 199 unchanged lines hidden (view full) --- 696 sk = iso_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern); 697 if (!sk) 698 return -ENOMEM; 699 700 iso_sock_init(sk, NULL); 701 return 0; 702} 703 |
704static int iso_sock_bind_bc(struct socket *sock, struct sockaddr *addr, 705 int addr_len) 706{ 707 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr; 708 struct sock *sk = sock->sk; 709 int i; 710 711 BT_DBG("sk %p bc_sid %u bc_num_bis %u", sk, sa->iso_bc->bc_sid, 712 sa->iso_bc->bc_num_bis); 713 714 if (addr_len > sizeof(*sa) + sizeof(*sa->iso_bc) || 715 sa->iso_bc->bc_num_bis < 0x01 || sa->iso_bc->bc_num_bis > 0x1f) 716 return -EINVAL; 717 718 bacpy(&iso_pi(sk)->dst, &sa->iso_bc->bc_bdaddr); 719 iso_pi(sk)->dst_type = sa->iso_bc->bc_bdaddr_type; 720 iso_pi(sk)->sync_handle = -1; 721 iso_pi(sk)->bc_sid = sa->iso_bc->bc_sid; 722 iso_pi(sk)->bc_num_bis = sa->iso_bc->bc_num_bis; 723 724 for (i = 0; i < iso_pi(sk)->bc_num_bis; i++) { 725 if (sa->iso_bc->bc_bis[i] < 0x01 || 726 sa->iso_bc->bc_bis[i] > 0x1f) 727 return -EINVAL; 728 729 memcpy(iso_pi(sk)->bc_bis, sa->iso_bc->bc_bis, 730 iso_pi(sk)->bc_num_bis); 731 } 732 733 return 0; 734} 735 |
|
590static int iso_sock_bind(struct socket *sock, struct sockaddr *addr, 591 int addr_len) 592{ 593 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr; 594 struct sock *sk = sock->sk; 595 int err = 0; 596 597 BT_DBG("sk %p %pMR type %u", sk, &sa->iso_bdaddr, sa->iso_bdaddr_type); --- 18 unchanged lines hidden (view full) --- 616 if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) { 617 err = -EINVAL; 618 goto done; 619 } 620 621 bacpy(&iso_pi(sk)->src, &sa->iso_bdaddr); 622 iso_pi(sk)->src_type = sa->iso_bdaddr_type; 623 | 736static int iso_sock_bind(struct socket *sock, struct sockaddr *addr, 737 int addr_len) 738{ 739 struct sockaddr_iso *sa = (struct sockaddr_iso *)addr; 740 struct sock *sk = sock->sk; 741 int err = 0; 742 743 BT_DBG("sk %p %pMR type %u", sk, &sa->iso_bdaddr, sa->iso_bdaddr_type); --- 18 unchanged lines hidden (view full) --- 762 if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) { 763 err = -EINVAL; 764 goto done; 765 } 766 767 bacpy(&iso_pi(sk)->src, &sa->iso_bdaddr); 768 iso_pi(sk)->src_type = sa->iso_bdaddr_type; 769 |
770 /* Check for Broadcast address */ 771 if (addr_len > sizeof(*sa)) { 772 err = iso_sock_bind_bc(sock, addr, addr_len); 773 if (err) 774 goto done; 775 } 776 |
|
624 sk->sk_state = BT_BOUND; 625 626done: 627 release_sock(sk); 628 return err; 629} 630 631static int iso_sock_connect(struct socket *sock, struct sockaddr *addr, --- 19 unchanged lines hidden (view full) --- 651 if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) 652 return -EINVAL; 653 654 lock_sock(sk); 655 656 bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr); 657 iso_pi(sk)->dst_type = sa->iso_bdaddr_type; 658 | 777 sk->sk_state = BT_BOUND; 778 779done: 780 release_sock(sk); 781 return err; 782} 783 784static int iso_sock_connect(struct socket *sock, struct sockaddr *addr, --- 19 unchanged lines hidden (view full) --- 804 if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) 805 return -EINVAL; 806 807 lock_sock(sk); 808 809 bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr); 810 iso_pi(sk)->dst_type = sa->iso_bdaddr_type; 811 |
659 err = iso_connect(sk); | 812 if (bacmp(&iso_pi(sk)->dst, BDADDR_ANY)) 813 err = iso_connect_cis(sk); 814 else 815 err = iso_connect_bis(sk); 816 |
660 if (err) 661 goto done; 662 663 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { 664 err = bt_sock_wait_state(sk, BT_CONNECTED, 665 sock_sndtimeo(sk, flags & O_NONBLOCK)); 666 } 667 668done: 669 release_sock(sk); 670 return err; 671} 672 | 817 if (err) 818 goto done; 819 820 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { 821 err = bt_sock_wait_state(sk, BT_CONNECTED, 822 sock_sndtimeo(sk, flags & O_NONBLOCK)); 823 } 824 825done: 826 release_sock(sk); 827 return err; 828} 829 |
830static int iso_listen_bis(struct sock *sk) 831{ 832 struct hci_dev *hdev; 833 int err = 0; 834 835 BT_DBG("%pMR -> %pMR (SID 0x%2.2x)", &iso_pi(sk)->src, 836 &iso_pi(sk)->dst, iso_pi(sk)->bc_sid); 837 838 write_lock(&iso_sk_list.lock); 839 840 if (__iso_get_sock_listen_by_sid(&iso_pi(sk)->src, &iso_pi(sk)->dst, 841 iso_pi(sk)->bc_sid)) 842 err = -EADDRINUSE; 843 844 write_unlock(&iso_sk_list.lock); 845 846 if (err) 847 return err; 848 849 hdev = hci_get_route(&iso_pi(sk)->dst, &iso_pi(sk)->src, 850 iso_pi(sk)->src_type); 851 if (!hdev) 852 return -EHOSTUNREACH; 853 854 hci_dev_lock(hdev); 855 856 err = hci_pa_create_sync(hdev, &iso_pi(sk)->dst, iso_pi(sk)->dst_type, 857 iso_pi(sk)->bc_sid); 858 859 hci_dev_unlock(hdev); 860 861 return err; 862} 863 864static int iso_listen_cis(struct sock *sk) 865{ 866 int err = 0; 867 868 BT_DBG("%pMR", &iso_pi(sk)->src); 869 870 write_lock(&iso_sk_list.lock); 871 872 if (__iso_get_sock_listen_by_addr(&iso_pi(sk)->src)) 873 err = -EADDRINUSE; 874 875 write_unlock(&iso_sk_list.lock); 876 877 return err; 878} 879 |
|
673static int iso_sock_listen(struct socket *sock, int backlog) 674{ 675 struct sock *sk = sock->sk; | 880static int iso_sock_listen(struct socket *sock, int backlog) 881{ 882 struct sock *sk = sock->sk; |
676 bdaddr_t *src = &iso_pi(sk)->src; | |
677 int err = 0; 678 679 BT_DBG("sk %p backlog %d", sk, backlog); 680 681 lock_sock(sk); 682 683 if (sk->sk_state != BT_BOUND) { 684 err = -EBADFD; 685 goto done; 686 } 687 688 if (sk->sk_type != SOCK_SEQPACKET) { 689 err = -EINVAL; 690 goto done; 691 } 692 | 883 int err = 0; 884 885 BT_DBG("sk %p backlog %d", sk, backlog); 886 887 lock_sock(sk); 888 889 if (sk->sk_state != BT_BOUND) { 890 err = -EBADFD; 891 goto done; 892 } 893 894 if (sk->sk_type != SOCK_SEQPACKET) { 895 err = -EINVAL; 896 goto done; 897 } 898 |
693 write_lock(&iso_sk_list.lock); | 899 if (!bacmp(&iso_pi(sk)->dst, BDADDR_ANY)) 900 err = iso_listen_cis(sk); 901 else 902 err = iso_listen_bis(sk); |
694 | 903 |
695 if (__iso_get_sock_listen_by_addr(src)) { 696 err = -EADDRINUSE; 697 goto unlock; 698 } | 904 if (err) 905 goto done; |
699 700 sk->sk_max_ack_backlog = backlog; 701 sk->sk_ack_backlog = 0; 702 703 sk->sk_state = BT_LISTEN; 704 | 906 907 sk->sk_max_ack_backlog = backlog; 908 sk->sk_ack_backlog = 0; 909 910 sk->sk_state = BT_LISTEN; 911 |
705unlock: 706 write_unlock(&iso_sk_list.lock); 707 | |
708done: 709 release_sock(sk); 710 return err; 711} 712 713static int iso_sock_accept(struct socket *sock, struct socket *newsock, 714 int flags, bool kern) 715{ --- 165 unchanged lines hidden (view full) --- 881 if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { 882 switch (sk->sk_state) { 883 case BT_CONNECT2: 884 iso_conn_defer_accept(pi->conn->hcon); 885 sk->sk_state = BT_CONFIG; 886 release_sock(sk); 887 return 0; 888 case BT_CONNECT: | 912done: 913 release_sock(sk); 914 return err; 915} 916 917static int iso_sock_accept(struct socket *sock, struct socket *newsock, 918 int flags, bool kern) 919{ --- 165 unchanged lines hidden (view full) --- 1085 if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { 1086 switch (sk->sk_state) { 1087 case BT_CONNECT2: 1088 iso_conn_defer_accept(pi->conn->hcon); 1089 sk->sk_state = BT_CONFIG; 1090 release_sock(sk); 1091 return 0; 1092 case BT_CONNECT: |
889 err = iso_connect(sk); | 1093 err = iso_connect_cis(sk); |
890 release_sock(sk); 891 return err; 892 } 893 } 894 895 release_sock(sk); 896 897 return bt_sock_recvmsg(sock, msg, len, flags); --- 14 unchanged lines hidden (view full) --- 912 if (qos->phy > BT_ISO_PHY_ANY) 913 return false; 914 915 return true; 916} 917 918static bool check_qos(struct bt_iso_qos *qos) 919{ | 1094 release_sock(sk); 1095 return err; 1096 } 1097 } 1098 1099 release_sock(sk); 1100 1101 return bt_sock_recvmsg(sock, msg, len, flags); --- 14 unchanged lines hidden (view full) --- 1116 if (qos->phy > BT_ISO_PHY_ANY) 1117 return false; 1118 1119 return true; 1120} 1121 1122static bool check_qos(struct bt_iso_qos *qos) 1123{ |
920 /* CIS shall not be set */ 921 if (qos->cis != BT_ISO_QOS_CIS_UNSET) 922 return false; 923 | |
924 if (qos->sca > 0x07) 925 return false; 926 927 if (qos->packing > 0x01) 928 return false; 929 930 if (qos->framing > 0x01) 931 return false; --- 59 unchanged lines hidden (view full) --- 991 err = -EINVAL; 992 break; 993 } 994 995 iso_pi(sk)->qos = qos; 996 997 break; 998 | 1124 if (qos->sca > 0x07) 1125 return false; 1126 1127 if (qos->packing > 0x01) 1128 return false; 1129 1130 if (qos->framing > 0x01) 1131 return false; --- 59 unchanged lines hidden (view full) --- 1191 err = -EINVAL; 1192 break; 1193 } 1194 1195 iso_pi(sk)->qos = qos; 1196 1197 break; 1198 |
1199 case BT_ISO_BASE: 1200 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND && 1201 sk->sk_state != BT_CONNECT2) { 1202 err = -EINVAL; 1203 break; 1204 } 1205 1206 if (optlen > sizeof(iso_pi(sk)->base)) { 1207 err = -EOVERFLOW; 1208 break; 1209 } 1210 1211 len = min_t(unsigned int, sizeof(iso_pi(sk)->base), optlen); 1212 1213 if (copy_from_sockptr(iso_pi(sk)->base, optval, len)) { 1214 err = -EFAULT; 1215 break; 1216 } 1217 1218 iso_pi(sk)->base_len = len; 1219 1220 break; 1221 |
|
999 default: 1000 err = -ENOPROTOOPT; 1001 break; 1002 } 1003 1004 release_sock(sk); 1005 return err; 1006} 1007 1008static int iso_sock_getsockopt(struct socket *sock, int level, int optname, 1009 char __user *optval, int __user *optlen) 1010{ 1011 struct sock *sk = sock->sk; 1012 int len, err = 0; 1013 struct bt_iso_qos qos; | 1222 default: 1223 err = -ENOPROTOOPT; 1224 break; 1225 } 1226 1227 release_sock(sk); 1228 return err; 1229} 1230 1231static int iso_sock_getsockopt(struct socket *sock, int level, int optname, 1232 char __user *optval, int __user *optlen) 1233{ 1234 struct sock *sk = sock->sk; 1235 int len, err = 0; 1236 struct bt_iso_qos qos; |
1237 u8 base_len; 1238 u8 *base; |
|
1014 1015 BT_DBG("sk %p", sk); 1016 1017 if (get_user(len, optlen)) 1018 return -EFAULT; 1019 1020 lock_sock(sk); 1021 --- 17 unchanged lines hidden (view full) --- 1039 qos = iso_pi(sk)->qos; 1040 1041 len = min_t(unsigned int, len, sizeof(qos)); 1042 if (copy_to_user(optval, (char *)&qos, len)) 1043 err = -EFAULT; 1044 1045 break; 1046 | 1239 1240 BT_DBG("sk %p", sk); 1241 1242 if (get_user(len, optlen)) 1243 return -EFAULT; 1244 1245 lock_sock(sk); 1246 --- 17 unchanged lines hidden (view full) --- 1264 qos = iso_pi(sk)->qos; 1265 1266 len = min_t(unsigned int, len, sizeof(qos)); 1267 if (copy_to_user(optval, (char *)&qos, len)) 1268 err = -EFAULT; 1269 1270 break; 1271 |
1272 case BT_ISO_BASE: 1273 if (sk->sk_state == BT_CONNECTED) { 1274 base_len = iso_pi(sk)->conn->hcon->le_per_adv_data_len; 1275 base = iso_pi(sk)->conn->hcon->le_per_adv_data; 1276 } else { 1277 base_len = iso_pi(sk)->base_len; 1278 base = iso_pi(sk)->base; 1279 } 1280 1281 len = min_t(unsigned int, len, base_len); 1282 if (copy_to_user(optval, base, len)) 1283 err = -EFAULT; 1284 1285 break; 1286 |
|
1047 default: 1048 err = -ENOPROTOOPT; 1049 break; 1050 } 1051 1052 release_sock(sk); 1053 return err; 1054} --- 66 unchanged lines hidden (view full) --- 1121 release_sock(sk); 1122} 1123 1124struct iso_list_data { 1125 struct hci_conn *hcon; 1126 int count; 1127}; 1128 | 1287 default: 1288 err = -ENOPROTOOPT; 1289 break; 1290 } 1291 1292 release_sock(sk); 1293 return err; 1294} --- 66 unchanged lines hidden (view full) --- 1361 release_sock(sk); 1362} 1363 1364struct iso_list_data { 1365 struct hci_conn *hcon; 1366 int count; 1367}; 1368 |
1369static bool iso_match_big(struct sock *sk, void *data) 1370{ 1371 struct hci_evt_le_big_sync_estabilished *ev = data; 1372 1373 return ev->handle == iso_pi(sk)->qos.big; 1374} 1375 |
|
1129static void iso_conn_ready(struct iso_conn *conn) 1130{ 1131 struct sock *parent; 1132 struct sock *sk = conn->sk; | 1376static void iso_conn_ready(struct iso_conn *conn) 1377{ 1378 struct sock *parent; 1379 struct sock *sk = conn->sk; |
1380 struct hci_ev_le_big_sync_estabilished *ev; |
|
1133 1134 BT_DBG("conn %p", conn); 1135 1136 if (sk) { 1137 iso_sock_ready(conn->sk); 1138 } else { 1139 iso_conn_lock(conn); 1140 1141 if (!conn->hcon) { 1142 iso_conn_unlock(conn); 1143 return; 1144 } 1145 | 1381 1382 BT_DBG("conn %p", conn); 1383 1384 if (sk) { 1385 iso_sock_ready(conn->sk); 1386 } else { 1387 iso_conn_lock(conn); 1388 1389 if (!conn->hcon) { 1390 iso_conn_unlock(conn); 1391 return; 1392 } 1393 |
1146 parent = iso_get_sock_listen(&conn->hcon->src); | 1394 ev = hci_recv_event_data(conn->hcon->hdev, 1395 HCI_EVT_LE_BIG_SYNC_ESTABILISHED); 1396 if (ev) 1397 parent = iso_get_sock_listen(&conn->hcon->src, 1398 &conn->hcon->dst, 1399 iso_match_big, ev); 1400 else 1401 parent = iso_get_sock_listen(&conn->hcon->src, 1402 BDADDR_ANY, NULL, NULL); 1403 |
1147 if (!parent) { 1148 iso_conn_unlock(conn); 1149 return; 1150 } 1151 1152 lock_sock(parent); 1153 1154 sk = iso_sock_alloc(sock_net(parent), NULL, 1155 BTPROTO_ISO, GFP_ATOMIC, 0); 1156 if (!sk) { 1157 release_sock(parent); 1158 iso_conn_unlock(conn); 1159 return; 1160 } 1161 1162 iso_sock_init(sk, parent); 1163 1164 bacpy(&iso_pi(sk)->src, &conn->hcon->src); 1165 iso_pi(sk)->src_type = conn->hcon->src_type; | 1404 if (!parent) { 1405 iso_conn_unlock(conn); 1406 return; 1407 } 1408 1409 lock_sock(parent); 1410 1411 sk = iso_sock_alloc(sock_net(parent), NULL, 1412 BTPROTO_ISO, GFP_ATOMIC, 0); 1413 if (!sk) { 1414 release_sock(parent); 1415 iso_conn_unlock(conn); 1416 return; 1417 } 1418 1419 iso_sock_init(sk, parent); 1420 1421 bacpy(&iso_pi(sk)->src, &conn->hcon->src); 1422 iso_pi(sk)->src_type = conn->hcon->src_type; |
1423 1424 /* If hcon has no destination address (BDADDR_ANY) it means it 1425 * was created by HCI_EV_LE_BIG_SYNC_ESTABILISHED so we need to 1426 * initialize using the parent socket destination address. 1427 */ 1428 if (!bacmp(&conn->hcon->dst, BDADDR_ANY)) { 1429 bacpy(&conn->hcon->dst, &iso_pi(parent)->dst); 1430 conn->hcon->dst_type = iso_pi(parent)->dst_type; 1431 conn->hcon->sync_handle = iso_pi(parent)->sync_handle; 1432 } 1433 |
|
1166 bacpy(&iso_pi(sk)->dst, &conn->hcon->dst); 1167 iso_pi(sk)->dst_type = conn->hcon->dst_type; 1168 1169 hci_conn_hold(conn->hcon); 1170 __iso_chan_add(conn, sk, parent); 1171 1172 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags)) 1173 sk->sk_state = BT_CONNECT2; --- 4 unchanged lines hidden (view full) --- 1178 parent->sk_data_ready(parent); 1179 1180 release_sock(parent); 1181 1182 iso_conn_unlock(conn); 1183 } 1184} 1185 | 1434 bacpy(&iso_pi(sk)->dst, &conn->hcon->dst); 1435 iso_pi(sk)->dst_type = conn->hcon->dst_type; 1436 1437 hci_conn_hold(conn->hcon); 1438 __iso_chan_add(conn, sk, parent); 1439 1440 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags)) 1441 sk->sk_state = BT_CONNECT2; --- 4 unchanged lines hidden (view full) --- 1446 parent->sk_data_ready(parent); 1447 1448 release_sock(parent); 1449 1450 iso_conn_unlock(conn); 1451 } 1452} 1453 |
1454static bool iso_match_sid(struct sock *sk, void *data) 1455{ 1456 struct hci_ev_le_pa_sync_established *ev = data; 1457 1458 return ev->sid == iso_pi(sk)->bc_sid; 1459} 1460 1461static bool iso_match_sync_handle(struct sock *sk, void *data) 1462{ 1463 struct hci_evt_le_big_info_adv_report *ev = data; 1464 1465 return le16_to_cpu(ev->sync_handle) == iso_pi(sk)->sync_handle; 1466} 1467 |
|
1186/* ----- ISO interface with lower layer (HCI) ----- */ | 1468/* ----- ISO interface with lower layer (HCI) ----- */ |
1469 |
|
1187int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags) 1188{ | 1470int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags) 1471{ |
1472 struct hci_ev_le_pa_sync_established *ev1; 1473 struct hci_evt_le_big_info_adv_report *ev2; |
|
1189 struct sock *sk; 1190 int lm = 0; 1191 | 1474 struct sock *sk; 1475 int lm = 0; 1476 |
1192 BT_DBG("hdev %s, bdaddr %pMR", hdev->name, bdaddr); | 1477 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); |
1193 | 1478 |
1194 /* Find listening sockets */ 1195 read_lock(&iso_sk_list.lock); 1196 sk_for_each(sk, &iso_sk_list.head) { 1197 if (sk->sk_state != BT_LISTEN) 1198 continue; | 1479 /* Broadcast receiver requires handling of some events before it can 1480 * proceed to establishing a BIG sync: 1481 * 1482 * 1. HCI_EV_LE_PA_SYNC_ESTABLISHED: The socket may specify a specific 1483 * SID to listen to and once sync is estabilished its handle needs to 1484 * be stored in iso_pi(sk)->sync_handle so it can be matched once 1485 * receiving the BIG Info. 1486 * 2. HCI_EVT_LE_BIG_INFO_ADV_REPORT: When connect_ind is triggered by a 1487 * a BIG Info it attempts to check if there any listening socket with 1488 * the same sync_handle and if it does then attempt to create a sync. 1489 */ 1490 ev1 = hci_recv_event_data(hdev, HCI_EV_LE_PA_SYNC_ESTABLISHED); 1491 if (ev1) { 1492 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr, iso_match_sid, 1493 ev1); 1494 if (sk) 1495 iso_pi(sk)->sync_handle = le16_to_cpu(ev1->handle); |
1199 | 1496 |
1200 if (!bacmp(&iso_pi(sk)->src, &hdev->bdaddr) || 1201 !bacmp(&iso_pi(sk)->src, BDADDR_ANY)) { 1202 lm |= HCI_LM_ACCEPT; | 1497 goto done; 1498 } |
1203 | 1499 |
1204 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) 1205 *flags |= HCI_PROTO_DEFER; 1206 break; | 1500 ev2 = hci_recv_event_data(hdev, HCI_EVT_LE_BIG_INFO_ADV_REPORT); 1501 if (ev2) { 1502 sk = iso_get_sock_listen(&hdev->bdaddr, bdaddr, 1503 iso_match_sync_handle, ev2); 1504 if (sk) { 1505 int err; 1506 1507 if (ev2->num_bis < iso_pi(sk)->bc_num_bis) 1508 iso_pi(sk)->bc_num_bis = ev2->num_bis; 1509 1510 err = hci_le_big_create_sync(hdev, 1511 &iso_pi(sk)->qos, 1512 iso_pi(sk)->sync_handle, 1513 iso_pi(sk)->bc_num_bis, 1514 iso_pi(sk)->bc_bis); 1515 if (err) { 1516 bt_dev_err(hdev, "hci_le_big_create_sync: %d", 1517 err); 1518 sk = NULL; 1519 } |
1207 } | 1520 } |
1521 } else { 1522 sk = iso_get_sock_listen(&hdev->bdaddr, BDADDR_ANY, NULL, NULL); |
|
1208 } | 1523 } |
1209 read_unlock(&iso_sk_list.lock); | |
1210 | 1524 |
1525done: 1526 if (!sk) 1527 return lm; 1528 1529 lm |= HCI_LM_ACCEPT; 1530 1531 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) 1532 *flags |= HCI_PROTO_DEFER; 1533 |
|
1211 return lm; 1212} 1213 1214static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) 1215{ 1216 if (hcon->type != ISO_LINK) { 1217 if (hcon->type != LE_LINK) 1218 return; --- 283 unchanged lines hidden --- | 1534 return lm; 1535} 1536 1537static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) 1538{ 1539 if (hcon->type != ISO_LINK) { 1540 if (hcon->type != LE_LINK) 1541 return; --- 283 unchanged lines hidden --- |