Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bluetooth: Add initial implementation of BIS connections

This adds initial support for BIS/BIG which includes:

== Broadcaster role: Setup a periodic advertising and create a BIG ==

> tools/isotest -s 00:00:00:00:00:00
isotest[63]: Connected [00:00:00:00:00:00]
isotest[63]: QoS BIG 0x00 BIS 0x00 Packing 0x00 Framing 0x00]
isotest[63]: Output QoS [Interval 10000 us Latency 10 ms SDU 40 PHY 0x02
RTN 2]
isotest[63]: Sending ...
isotest[63]: Number of packets: 1
isotest[63]: Socket jitter buffer: 80 buffer
< HCI Command: LE Set Perio.. (0x08|0x003e) plen 7
...
> HCI Event: Command Complete (0x0e) plen 4
LE Set Periodic Advertising Parameters (0x08|0x003e) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Perio.. (0x08|0x003f) plen 7
...
> HCI Event: Command Complete (0x0e) plen 4
LE Set Periodic Advertising Data (0x08|0x003f) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Perio.. (0x08|0x0040) plen 2
...
> HCI Event: Command Complete (0x0e) plen 4
LE Set Periodic Advertising Enable (0x08|0x0040) ncmd 1
Status: Success (0x00)
< HCI Command: LE Create B.. (0x08|0x0068) plen 31
...
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 21
LE Broadcast Isochronous Group Complete (0x1b)
...

== Broadcast Receiver role: Create a PA Sync and BIG Sync ==

> tools/isotest -i hci1 -d 00:AA:01:00:00:00
isotest[66]: Waiting for connection 00:AA:01:00:00:00...
< HCI Command: LE Periodic Advert.. (0x08|0x0044) plen 14
...
> HCI Event: Command Status (0x0f) plen 4
LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Extended Sca.. (0x08|0x0041) plen 8
...
> HCI Event: Command Complete (0x0e) plen 4
LE Set Extended Scan Parameters (0x08|0x0041) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Extended Sca.. (0x08|0x0042) plen 6
...
> HCI Event: Command Complete (0x0e) plen 4
LE Set Extended Scan Enable (0x08|0x0042) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 29
LE Extended Advertising Report (0x0d)
...
> HCI Event: LE Meta Event (0x3e) plen 16
LE Periodic Advertising Sync Established (0x0e)
...
< HCI Command: LE Broadcast Isoch.. (0x08|0x006b) plen 25
...
> HCI Event: Command Status (0x0f) plen 4
LE Broadcast Isochronous Group Create Sync (0x08|0x006b) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 17
LE Broadcast Isochronous Group Sync Estabilished (0x1d)
...

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

+1333 -126
+15 -3
include/net/bluetooth/bluetooth.h
··· 160 160 #define BT_ISO_QOS_CIG_UNSET 0xff 161 161 #define BT_ISO_QOS_CIS_UNSET 0xff 162 162 163 + #define BT_ISO_QOS_BIG_UNSET 0xff 164 + #define BT_ISO_QOS_BIS_UNSET 0xff 165 + 163 166 struct bt_iso_io_qos { 164 167 __u32 interval; 165 168 __u16 latency; ··· 172 169 }; 173 170 174 171 struct bt_iso_qos { 175 - __u8 cig; 176 - __u8 cis; 177 - __u8 sca; 172 + union { 173 + __u8 cig; 174 + __u8 big; 175 + }; 176 + union { 177 + __u8 cis; 178 + __u8 bis; 179 + }; 180 + union { 181 + __u8 sca; 182 + __u8 sync_interval; 183 + }; 178 184 __u8 packing; 179 185 __u8 framing; 180 186 struct bt_iso_io_qos in;
+155 -7
include/net/bluetooth/hci.h
··· 316 316 HCI_USER_CHANNEL, 317 317 HCI_EXT_CONFIGURED, 318 318 HCI_LE_ADV, 319 + HCI_LE_PER_ADV, 319 320 HCI_LE_SCAN, 320 321 HCI_SSP_ENABLED, 321 322 HCI_SC_ENABLED, ··· 339 338 HCI_LE_SCAN_INTERRUPTED, 340 339 HCI_WIDEBAND_SPEECH_ENABLED, 341 340 HCI_EVENT_FILTER_CONFIGURED, 341 + HCI_PA_SYNC, 342 342 343 343 HCI_DUT_MODE, 344 344 HCI_VENDOR_DIAG, ··· 521 519 #define HCI_LE_PHY_2M 0x01 522 520 #define HCI_LE_PHY_CODED 0x08 523 521 #define HCI_LE_EXT_ADV 0x10 522 + #define HCI_LE_PERIODIC_ADV 0x20 524 523 #define HCI_LE_CHAN_SEL_ALG2 0x40 525 524 #define HCI_LE_CIS_CENTRAL 0x10 526 525 #define HCI_LE_CIS_PERIPHERAL 0x20 526 + #define HCI_LE_ISO_BROADCASTER 0x40 527 527 528 528 /* Connection modes */ 529 529 #define HCI_CM_ACTIVE 0x0000 ··· 1869 1865 __le16 max_ce_len; 1870 1866 } __packed; 1871 1867 1868 + #define HCI_OP_LE_PA_CREATE_SYNC 0x2044 1869 + struct hci_cp_le_pa_create_sync { 1870 + __u8 options; 1871 + __u8 sid; 1872 + __u8 addr_type; 1873 + bdaddr_t addr; 1874 + __le16 skip; 1875 + __le16 sync_timeout; 1876 + __u8 sync_cte_type; 1877 + } __packed; 1878 + 1879 + #define HCI_OP_LE_PA_TERM_SYNC 0x2046 1880 + struct hci_cp_le_pa_term_sync { 1881 + __le16 handle; 1882 + } __packed; 1883 + 1872 1884 #define HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS 0x203b 1873 1885 struct hci_rp_le_read_num_supported_adv_sets { 1874 1886 __u8 status; ··· 1919 1899 __u8 tx_power; 1920 1900 } __packed; 1921 1901 1922 - #define HCI_OP_LE_SET_EXT_ADV_ENABLE 0x2039 1923 - struct hci_cp_le_set_ext_adv_enable { 1924 - __u8 enable; 1925 - __u8 num_of_sets; 1926 - __u8 data[]; 1927 - } __packed; 1928 - 1929 1902 struct hci_cp_ext_adv_set { 1930 1903 __u8 handle; 1931 1904 __le16 duration; ··· 1943 1930 __u8 frag_pref; 1944 1931 __u8 length; 1945 1932 __u8 data[]; 1933 + } __packed; 1934 + 1935 + #define HCI_OP_LE_SET_EXT_ADV_ENABLE 0x2039 1936 + struct hci_cp_le_set_ext_adv_enable { 1937 + __u8 enable; 1938 + __u8 num_of_sets; 1939 + __u8 data[]; 1940 + } __packed; 1941 + 1942 + #define HCI_OP_LE_SET_PER_ADV_PARAMS 0x203e 1943 + struct hci_cp_le_set_per_adv_params { 1944 + __u8 handle; 1945 + __le16 min_interval; 1946 + __le16 max_interval; 1947 + __le16 periodic_properties; 1948 + } __packed; 1949 + 1950 + #define HCI_MAX_PER_AD_LENGTH 252 1951 + 1952 + #define HCI_OP_LE_SET_PER_ADV_DATA 0x203f 1953 + struct hci_cp_le_set_per_adv_data { 1954 + __u8 handle; 1955 + __u8 operation; 1956 + __u8 length; 1957 + __u8 data[]; 1958 + } __packed; 1959 + 1960 + #define HCI_OP_LE_SET_PER_ADV_ENABLE 0x2040 1961 + struct hci_cp_le_set_per_adv_enable { 1962 + __u8 enable; 1963 + __u8 handle; 1946 1964 } __packed; 1947 1965 1948 1966 #define LE_SET_ADV_DATA_OP_COMPLETE 0x03 ··· 2085 2041 struct hci_cp_le_reject_cis { 2086 2042 __le16 handle; 2087 2043 __u8 reason; 2044 + } __packed; 2045 + 2046 + #define HCI_OP_LE_CREATE_BIG 0x2068 2047 + struct hci_bis { 2048 + __u8 sdu_interval[3]; 2049 + __le16 sdu; 2050 + __le16 latency; 2051 + __u8 rtn; 2052 + __u8 phy; 2053 + __u8 packing; 2054 + __u8 framing; 2055 + __u8 encryption; 2056 + __u8 bcode[16]; 2057 + } __packed; 2058 + 2059 + struct hci_cp_le_create_big { 2060 + __u8 handle; 2061 + __u8 adv_handle; 2062 + __u8 num_bis; 2063 + struct hci_bis bis; 2064 + } __packed; 2065 + 2066 + #define HCI_OP_LE_TERM_BIG 0x206a 2067 + struct hci_cp_le_term_big { 2068 + __u8 handle; 2069 + __u8 reason; 2070 + } __packed; 2071 + 2072 + #define HCI_OP_LE_BIG_CREATE_SYNC 0x206b 2073 + struct hci_cp_le_big_create_sync { 2074 + __u8 handle; 2075 + __le16 sync_handle; 2076 + __u8 encryption; 2077 + __u8 bcode[16]; 2078 + __u8 mse; 2079 + __le16 timeout; 2080 + __u8 num_bis; 2081 + __u8 bis[0]; 2082 + } __packed; 2083 + 2084 + #define HCI_OP_LE_BIG_TERM_SYNC 0x206c 2085 + struct hci_cp_le_big_term_sync { 2086 + __u8 handle; 2088 2087 } __packed; 2089 2088 2090 2089 #define HCI_OP_LE_SETUP_ISO_PATH 0x206e ··· 2682 2595 struct hci_ev_le_ext_adv_info info[]; 2683 2596 } __packed; 2684 2597 2598 + #define HCI_EV_LE_PA_SYNC_ESTABLISHED 0x0e 2599 + struct hci_ev_le_pa_sync_established { 2600 + __u8 status; 2601 + __le16 handle; 2602 + __u8 sid; 2603 + __u8 bdaddr_type; 2604 + bdaddr_t bdaddr; 2605 + __u8 phy; 2606 + __le16 interval; 2607 + __u8 clock_accuracy; 2608 + } __packed; 2609 + 2685 2610 #define HCI_EV_LE_ENHANCED_CONN_COMPLETE 0x0a 2686 2611 struct hci_ev_le_enh_conn_complete { 2687 2612 __u8 status; ··· 2743 2644 __le16 cis_handle; 2744 2645 __u8 cig_id; 2745 2646 __u8 cis_id; 2647 + } __packed; 2648 + 2649 + #define HCI_EVT_LE_CREATE_BIG_COMPLETE 0x1b 2650 + struct hci_evt_le_create_big_complete { 2651 + __u8 status; 2652 + __u8 handle; 2653 + __u8 sync_delay[3]; 2654 + __u8 transport_delay[3]; 2655 + __u8 phy; 2656 + __u8 nse; 2657 + __u8 bn; 2658 + __u8 pto; 2659 + __u8 irc; 2660 + __le16 max_pdu; 2661 + __le16 interval; 2662 + __u8 num_bis; 2663 + __le16 bis_handle[]; 2664 + } __packed; 2665 + 2666 + #define HCI_EVT_LE_BIG_SYNC_ESTABILISHED 0x1d 2667 + struct hci_evt_le_big_sync_estabilished { 2668 + __u8 status; 2669 + __u8 handle; 2670 + __u8 latency[3]; 2671 + __u8 nse; 2672 + __u8 bn; 2673 + __u8 pto; 2674 + __u8 irc; 2675 + __le16 max_pdu; 2676 + __le16 interval; 2677 + __u8 num_bis; 2678 + __le16 bis[]; 2679 + } __packed; 2680 + 2681 + #define HCI_EVT_LE_BIG_INFO_ADV_REPORT 0x22 2682 + struct hci_evt_le_big_info_adv_report { 2683 + __le16 sync_handle; 2684 + __u8 num_bis; 2685 + __u8 nse; 2686 + __le16 iso_interval; 2687 + __u8 bn; 2688 + __u8 pto; 2689 + __u8 irc; 2690 + __le16 max_pdu; 2691 + __u8 sdu_interval[3]; 2692 + __le16 max_sdu; 2693 + __u8 phy; 2694 + __u8 framing; 2695 + __u8 encryption; 2746 2696 } __packed; 2747 2697 2748 2698 #define HCI_EV_VENDOR 0xff
+80 -9
include/net/bluetooth/hci_core.h
··· 235 235 236 236 struct adv_info { 237 237 struct list_head list; 238 - bool enabled; 239 - bool pending; 238 + bool enabled; 239 + bool pending; 240 + bool periodic; 240 241 __u8 instance; 241 242 __u32 flags; 242 243 __u16 timeout; ··· 249 248 __u16 scan_rsp_len; 250 249 __u8 scan_rsp_data[HCI_MAX_EXT_AD_LENGTH]; 251 250 bool scan_rsp_changed; 251 + __u16 per_adv_data_len; 252 + __u8 per_adv_data[HCI_MAX_PER_AD_LENGTH]; 252 253 __s8 tx_power; 253 254 __u32 min_interval; 254 255 __u32 max_interval; ··· 597 594 __u8 adv_data_len; 598 595 __u8 scan_rsp_data[HCI_MAX_EXT_AD_LENGTH]; 599 596 __u8 scan_rsp_data_len; 597 + __u8 per_adv_data[HCI_MAX_PER_AD_LENGTH]; 598 + __u8 per_adv_data_len; 600 599 601 600 struct list_head adv_instances; 602 601 unsigned int adv_instance_cnt; ··· 684 679 __u8 resp_addr_type; 685 680 __u8 adv_instance; 686 681 __u16 handle; 682 + __u16 sync_handle; 687 683 __u16 state; 688 684 __u8 mode; 689 685 __u8 type; ··· 715 709 __u16 le_supv_timeout; 716 710 __u8 le_adv_data[HCI_MAX_AD_LENGTH]; 717 711 __u8 le_adv_data_len; 712 + __u8 le_per_adv_data[HCI_MAX_PER_AD_LENGTH]; 713 + __u8 le_per_adv_data_len; 718 714 __u8 le_tx_phy; 719 715 __u8 le_rx_phy; 720 716 __s8 rssi; ··· 950 942 HCI_CONN_NEW_LINK_KEY, 951 943 HCI_CONN_SCANNING, 952 944 HCI_CONN_AUTH_FAILURE, 945 + HCI_CONN_PER_ADV, 953 946 }; 954 947 955 948 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) ··· 1069 1060 return type; 1070 1061 } 1071 1062 1063 + static inline struct hci_conn *hci_conn_hash_lookup_bis(struct hci_dev *hdev, 1064 + bdaddr_t *ba, 1065 + __u8 big, __u8 bis) 1066 + { 1067 + struct hci_conn_hash *h = &hdev->conn_hash; 1068 + struct hci_conn *c; 1069 + 1070 + rcu_read_lock(); 1071 + 1072 + list_for_each_entry_rcu(c, &h->list, list) { 1073 + if (bacmp(&c->dst, ba) || c->type != ISO_LINK) 1074 + continue; 1075 + 1076 + if (c->iso_qos.big == big && c->iso_qos.bis == bis) { 1077 + rcu_read_unlock(); 1078 + return c; 1079 + } 1080 + } 1081 + rcu_read_unlock(); 1082 + 1083 + return NULL; 1084 + } 1085 + 1072 1086 static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 1073 1087 __u16 handle) 1074 1088 { ··· 1202 1170 return NULL; 1203 1171 } 1204 1172 1173 + static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev, 1174 + __u8 handle) 1175 + { 1176 + struct hci_conn_hash *h = &hdev->conn_hash; 1177 + struct hci_conn *c; 1178 + 1179 + rcu_read_lock(); 1180 + 1181 + list_for_each_entry_rcu(c, &h->list, list) { 1182 + if (bacmp(&c->dst, BDADDR_ANY) || c->type != ISO_LINK) 1183 + continue; 1184 + 1185 + if (handle == c->iso_qos.big) { 1186 + rcu_read_unlock(); 1187 + return c; 1188 + } 1189 + } 1190 + 1191 + rcu_read_unlock(); 1192 + 1193 + return NULL; 1194 + } 1195 + 1205 1196 static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, 1206 1197 __u8 type, __u16 state) 1207 1198 { ··· 1319 1264 __u8 dst_type, struct bt_iso_qos *qos); 1320 1265 struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst, 1321 1266 __u8 dst_type, struct bt_iso_qos *qos); 1267 + struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst, 1268 + __u8 dst_type, struct bt_iso_qos *qos, 1269 + __u8 data_len, __u8 *data); 1270 + int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type, 1271 + __u8 sid); 1272 + int hci_le_big_create_sync(struct hci_dev *hdev, struct bt_iso_qos *qos, 1273 + __u16 sync_handle, __u8 num_bis, __u8 bis[]); 1322 1274 int hci_conn_check_link_mode(struct hci_conn *conn); 1323 1275 int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); 1324 1276 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type, ··· 1572 1510 void hci_adv_instances_clear(struct hci_dev *hdev); 1573 1511 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance); 1574 1512 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance); 1575 - int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, 1576 - u16 adv_data_len, u8 *adv_data, 1577 - u16 scan_rsp_len, u8 *scan_rsp_data, 1578 - u16 timeout, u16 duration, s8 tx_power, 1579 - u32 min_interval, u32 max_interval); 1513 + struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, 1514 + u32 flags, u16 adv_data_len, u8 *adv_data, 1515 + u16 scan_rsp_len, u8 *scan_rsp_data, 1516 + u16 timeout, u16 duration, s8 tx_power, 1517 + u32 min_interval, u32 max_interval); 1518 + struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, 1519 + u32 flags, u8 data_len, u8 *data, 1520 + u32 min_interval, u32 max_interval); 1580 1521 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, 1581 1522 u16 adv_data_len, u8 *adv_data, 1582 1523 u16 scan_rsp_len, u8 *scan_rsp_data); ··· 1696 1631 #define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \ 1697 1632 ext_adv_capable(dev)) 1698 1633 1699 - /* CIS Master/Slave support */ 1700 - #define iso_capable(dev) (cis_capable(dev)) 1634 + /* Periodic advertising support */ 1635 + #define per_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_PERIODIC_ADV)) 1636 + 1637 + /* CIS Master/Slave and BIS support */ 1638 + #define iso_capable(dev) (cis_capable(dev) || bis_capable(dev)) 1701 1639 #define cis_capable(dev) \ 1702 1640 (cis_central_capable(dev) || cis_peripheral_capable(dev)) 1703 1641 #define cis_central_capable(dev) \ 1704 1642 ((dev)->le_features[3] & HCI_LE_CIS_CENTRAL) 1705 1643 #define cis_peripheral_capable(dev) \ 1706 1644 ((dev)->le_features[3] & HCI_LE_CIS_PERIPHERAL) 1645 + #define bis_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_BROADCASTER) 1707 1646 1708 1647 /* ----- HCI protocols ----- */ 1709 1648 #define HCI_PROTO_DEFER 0x01 ··· 1995 1926 #define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200) /* msec */ 1996 1927 #define DISCOV_LE_FAST_ADV_INT_MIN 0x00A0 /* 100 msec */ 1997 1928 #define DISCOV_LE_FAST_ADV_INT_MAX 0x00F0 /* 150 msec */ 1929 + #define DISCOV_LE_PER_ADV_INT_MIN 0x00A0 /* 200 msec */ 1930 + #define DISCOV_LE_PER_ADV_INT_MAX 0x00A0 /* 200 msec */ 1998 1931 1999 1932 #define NAME_RESOLVE_DURATION msecs_to_jiffies(10240) /* 10.24 sec */ 2000 1933
+11 -1
include/net/bluetooth/hci_sync.h
··· 65 65 int hci_enable_advertising_sync(struct hci_dev *hdev); 66 66 int hci_enable_advertising(struct hci_dev *hdev); 67 67 68 + int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, 69 + u8 *data, u32 flags, u16 min_interval, 70 + u16 max_interval, u16 sync_interval); 71 + 68 72 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, 69 73 u8 instance, bool force); 70 74 int hci_disable_advertising_sync(struct hci_dev *hdev); ··· 87 83 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul); 88 84 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, 89 85 struct sock *sk); 86 + int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance); 90 87 struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, bool ext, 91 88 struct sock *sk); 92 89 ··· 116 111 int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn); 117 112 118 113 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle); 119 - int hci_le_remove_cig(struct hci_dev *hdev, u8 handle); 114 + 115 + int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason); 116 + 117 + int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle); 118 + 119 + int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle);
+21
net/bluetooth/eir.c
··· 236 236 ptr = create_uuid128_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); 237 237 } 238 238 239 + u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) 240 + { 241 + struct adv_info *adv = NULL; 242 + u8 ad_len = 0; 243 + 244 + /* Return 0 when the current instance identifier is invalid. */ 245 + if (instance) { 246 + adv = hci_find_adv_instance(hdev, instance); 247 + if (!adv) 248 + return 0; 249 + } 250 + 251 + if (adv) { 252 + memcpy(ptr, adv->per_adv_data, adv->per_adv_data_len); 253 + ad_len += adv->per_adv_data_len; 254 + ptr += adv->per_adv_data_len; 255 + } 256 + 257 + return ad_len; 258 + } 259 + 239 260 u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) 240 261 { 241 262 struct adv_info *adv = NULL;
+1
net/bluetooth/eir.h
··· 11 11 12 12 u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr); 13 13 u8 eir_create_scan_rsp(struct hci_dev *hdev, u8 instance, u8 *ptr); 14 + u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr); 14 15 15 16 u8 eir_append_local_name(struct hci_dev *hdev, u8 *eir, u8 ad_len); 16 17 u8 eir_append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len);
+508 -53
net/bluetooth/hci_conn.c
··· 30 30 #include <net/bluetooth/bluetooth.h> 31 31 #include <net/bluetooth/hci_core.h> 32 32 #include <net/bluetooth/l2cap.h> 33 + #include <net/bluetooth/iso.h> 34 + #include <net/bluetooth/mgmt.h> 33 35 34 36 #include "hci_request.h" 35 37 #include "smp.h" 36 38 #include "a2mp.h" 39 + #include "eir.h" 37 40 38 41 struct sco_param { 39 42 u16 pkt_type; ··· 687 684 hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM); 688 685 } 689 686 687 + struct iso_list_data { 688 + union { 689 + u8 cig; 690 + u8 big; 691 + }; 692 + union { 693 + u8 cis; 694 + u8 bis; 695 + u16 sync_handle; 696 + }; 697 + int count; 698 + struct { 699 + struct hci_cp_le_set_cig_params cp; 700 + struct hci_cis_params cis[0x11]; 701 + } pdu; 702 + }; 703 + 704 + static void bis_list(struct hci_conn *conn, void *data) 705 + { 706 + struct iso_list_data *d = data; 707 + 708 + /* Skip if not broadcast/ANY address */ 709 + if (bacmp(&conn->dst, BDADDR_ANY)) 710 + return; 711 + 712 + if (d->big != conn->iso_qos.big || d->bis == BT_ISO_QOS_BIS_UNSET || 713 + d->bis != conn->iso_qos.bis) 714 + return; 715 + 716 + d->count++; 717 + } 718 + 719 + static void find_bis(struct hci_conn *conn, void *data) 720 + { 721 + struct iso_list_data *d = data; 722 + 723 + /* Ignore unicast */ 724 + if (bacmp(&conn->dst, BDADDR_ANY)) 725 + return; 726 + 727 + d->count++; 728 + } 729 + 730 + static int terminate_big_sync(struct hci_dev *hdev, void *data) 731 + { 732 + struct iso_list_data *d = data; 733 + 734 + bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", d->big, d->bis); 735 + 736 + hci_remove_ext_adv_instance_sync(hdev, d->bis, NULL); 737 + 738 + /* Check if ISO connection is a BIS and terminate BIG if there are 739 + * no other connections using it. 740 + */ 741 + hci_conn_hash_list_state(hdev, find_bis, ISO_LINK, BT_CONNECTED, d); 742 + if (d->count) 743 + return 0; 744 + 745 + return hci_le_terminate_big_sync(hdev, d->big, 746 + HCI_ERROR_LOCAL_HOST_TERM); 747 + } 748 + 749 + static void terminate_big_destroy(struct hci_dev *hdev, void *data, int err) 750 + { 751 + kfree(data); 752 + } 753 + 754 + static int hci_le_terminate_big(struct hci_dev *hdev, u8 big, u8 bis) 755 + { 756 + struct iso_list_data *d; 757 + 758 + bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", big, bis); 759 + 760 + d = kmalloc(sizeof(*d), GFP_KERNEL); 761 + if (!d) 762 + return -ENOMEM; 763 + 764 + memset(d, 0, sizeof(*d)); 765 + d->big = big; 766 + d->bis = bis; 767 + 768 + return hci_cmd_sync_queue(hdev, terminate_big_sync, d, 769 + terminate_big_destroy); 770 + } 771 + 772 + static int big_terminate_sync(struct hci_dev *hdev, void *data) 773 + { 774 + struct iso_list_data *d = data; 775 + 776 + bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", d->big, 777 + d->sync_handle); 778 + 779 + /* Check if ISO connection is a BIS and terminate BIG if there are 780 + * no other connections using it. 781 + */ 782 + hci_conn_hash_list_state(hdev, find_bis, ISO_LINK, BT_CONNECTED, d); 783 + if (d->count) 784 + return 0; 785 + 786 + hci_le_big_terminate_sync(hdev, d->big); 787 + 788 + return hci_le_pa_terminate_sync(hdev, d->sync_handle); 789 + } 790 + 791 + static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16 sync_handle) 792 + { 793 + struct iso_list_data *d; 794 + 795 + bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, sync_handle); 796 + 797 + d = kmalloc(sizeof(*d), GFP_KERNEL); 798 + if (!d) 799 + return -ENOMEM; 800 + 801 + memset(d, 0, sizeof(*d)); 802 + d->big = big; 803 + d->sync_handle = sync_handle; 804 + 805 + return hci_cmd_sync_queue(hdev, big_terminate_sync, d, 806 + terminate_big_destroy); 807 + } 808 + 809 + /* Cleanup BIS connection 810 + * 811 + * Detects if there any BIS left connected in a BIG 812 + * broadcaster: Remove advertising instance and terminate BIG. 813 + * broadcaster receiver: Teminate BIG sync and terminate PA sync. 814 + */ 815 + static void bis_cleanup(struct hci_conn *conn) 816 + { 817 + struct hci_dev *hdev = conn->hdev; 818 + 819 + bt_dev_dbg(hdev, "conn %p", conn); 820 + 821 + if (conn->role == HCI_ROLE_MASTER) { 822 + if (!test_and_clear_bit(HCI_CONN_PER_ADV, &conn->flags)) 823 + return; 824 + 825 + hci_le_terminate_big(hdev, conn->iso_qos.big, 826 + conn->iso_qos.bis); 827 + } else { 828 + hci_le_big_terminate(hdev, conn->iso_qos.big, 829 + conn->sync_handle); 830 + } 831 + } 832 + 833 + static int remove_cig_sync(struct hci_dev *hdev, void *data) 834 + { 835 + u8 handle = PTR_ERR(data); 836 + 837 + return hci_le_remove_cig_sync(hdev, handle); 838 + } 839 + 840 + static int hci_le_remove_cig(struct hci_dev *hdev, u8 handle) 841 + { 842 + bt_dev_dbg(hdev, "handle 0x%2.2x", handle); 843 + 844 + return hci_cmd_sync_queue(hdev, remove_cig_sync, ERR_PTR(handle), NULL); 845 + } 846 + 847 + static void find_cis(struct hci_conn *conn, void *data) 848 + { 849 + struct iso_list_data *d = data; 850 + 851 + /* Ignore broadcast */ 852 + if (!bacmp(&conn->dst, BDADDR_ANY)) 853 + return; 854 + 855 + d->count++; 856 + } 857 + 858 + /* Cleanup CIS connection: 859 + * 860 + * Detects if there any CIS left connected in a CIG and remove it. 861 + */ 862 + static void cis_cleanup(struct hci_conn *conn) 863 + { 864 + struct hci_dev *hdev = conn->hdev; 865 + struct iso_list_data d; 866 + 867 + memset(&d, 0, sizeof(d)); 868 + d.cig = conn->iso_qos.cig; 869 + 870 + /* Check if ISO connection is a CIS and remove CIG if there are 871 + * no other connections using it. 872 + */ 873 + hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_CONNECTED, &d); 874 + if (d.count) 875 + return; 876 + 877 + hci_le_remove_cig(hdev, conn->iso_qos.cig); 878 + } 879 + 690 880 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, 691 881 u8 role) 692 882 { ··· 921 725 conn->pkt_type = hdev->pkt_type & ACL_PTYPE_MASK; 922 726 break; 923 727 case LE_LINK: 728 + /* conn->src should reflect the local identity address */ 729 + hci_copy_identity_address(hdev, &conn->src, &conn->src_type); 730 + break; 924 731 case ISO_LINK: 925 732 /* conn->src should reflect the local identity address */ 926 733 hci_copy_identity_address(hdev, &conn->src, &conn->src_type); 734 + 735 + /* set proper cleanup function */ 736 + if (!bacmp(dst, BDADDR_ANY)) 737 + conn->cleanup = bis_cleanup; 738 + else if (conn->role == HCI_ROLE_MASTER) 739 + conn->cleanup = cis_cleanup; 740 + 927 741 break; 928 742 case SCO_LINK: 929 743 if (lmp_esco_capable(hdev)) ··· 1306 1100 return 0; 1307 1101 } 1308 1102 1103 + static int qos_set_big(struct hci_dev *hdev, struct bt_iso_qos *qos) 1104 + { 1105 + struct iso_list_data data; 1106 + 1107 + /* Allocate a BIG if not set */ 1108 + if (qos->big == BT_ISO_QOS_BIG_UNSET) { 1109 + for (data.big = 0x00; data.big < 0xef; data.big++) { 1110 + data.count = 0; 1111 + data.bis = 0xff; 1112 + 1113 + hci_conn_hash_list_state(hdev, bis_list, ISO_LINK, 1114 + BT_BOUND, &data); 1115 + if (!data.count) 1116 + break; 1117 + } 1118 + 1119 + if (data.big == 0xef) 1120 + return -EADDRNOTAVAIL; 1121 + 1122 + /* Update BIG */ 1123 + qos->big = data.big; 1124 + } 1125 + 1126 + return 0; 1127 + } 1128 + 1129 + static int qos_set_bis(struct hci_dev *hdev, struct bt_iso_qos *qos) 1130 + { 1131 + struct iso_list_data data; 1132 + 1133 + /* Allocate BIS if not set */ 1134 + if (qos->bis == BT_ISO_QOS_BIS_UNSET) { 1135 + /* Find an unused adv set to advertise BIS, skip instance 0x00 1136 + * since it is reserved as general purpose set. 1137 + */ 1138 + for (data.bis = 0x01; data.bis < hdev->le_num_of_adv_sets; 1139 + data.bis++) { 1140 + data.count = 0; 1141 + 1142 + hci_conn_hash_list_state(hdev, bis_list, ISO_LINK, 1143 + BT_BOUND, &data); 1144 + if (!data.count) 1145 + break; 1146 + } 1147 + 1148 + if (data.bis == hdev->le_num_of_adv_sets) 1149 + return -EADDRNOTAVAIL; 1150 + 1151 + /* Update BIS */ 1152 + qos->bis = data.bis; 1153 + } 1154 + 1155 + return 0; 1156 + } 1157 + 1158 + /* This function requires the caller holds hdev->lock */ 1159 + static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst, 1160 + struct bt_iso_qos *qos) 1161 + { 1162 + struct hci_conn *conn; 1163 + struct iso_list_data data; 1164 + int err; 1165 + 1166 + /* Let's make sure that le is enabled.*/ 1167 + if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { 1168 + if (lmp_le_capable(hdev)) 1169 + return ERR_PTR(-ECONNREFUSED); 1170 + return ERR_PTR(-EOPNOTSUPP); 1171 + } 1172 + 1173 + err = qos_set_big(hdev, qos); 1174 + if (err) 1175 + return ERR_PTR(err); 1176 + 1177 + err = qos_set_bis(hdev, qos); 1178 + if (err) 1179 + return ERR_PTR(err); 1180 + 1181 + data.big = qos->big; 1182 + data.bis = qos->bis; 1183 + data.count = 0; 1184 + 1185 + /* Check if there is already a matching BIG/BIS */ 1186 + hci_conn_hash_list_state(hdev, bis_list, ISO_LINK, BT_BOUND, &data); 1187 + if (data.count) 1188 + return ERR_PTR(-EADDRINUSE); 1189 + 1190 + conn = hci_conn_hash_lookup_bis(hdev, dst, qos->big, qos->bis); 1191 + if (conn) 1192 + return ERR_PTR(-EADDRINUSE); 1193 + 1194 + conn = hci_conn_add(hdev, ISO_LINK, dst, HCI_ROLE_MASTER); 1195 + if (!conn) 1196 + return ERR_PTR(-ENOMEM); 1197 + 1198 + set_bit(HCI_CONN_PER_ADV, &conn->flags); 1199 + conn->state = BT_CONNECT; 1200 + 1201 + hci_conn_hold(conn); 1202 + return conn; 1203 + } 1204 + 1309 1205 /* This function requires the caller holds hdev->lock */ 1310 1206 struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, 1311 1207 u8 dst_type, u8 sec_level, ··· 1544 1236 return sco; 1545 1237 } 1546 1238 1547 - struct iso_list_data { 1548 - u8 cig; 1549 - u8 cis; 1550 - int count; 1551 - struct { 1552 - struct hci_cp_le_set_cig_params cp; 1553 - struct hci_cis_params cis[0x11]; 1554 - } pdu; 1555 - }; 1556 - 1557 1239 static void cis_add(struct iso_list_data *d, struct bt_iso_qos *qos) 1558 1240 { 1559 1241 struct hci_cis_params *cis = &d->pdu.cis[d->pdu.cp.num_cis]; ··· 1563 1265 { 1564 1266 struct iso_list_data *d = data; 1565 1267 1268 + /* Skip if broadcast/ANY address */ 1269 + if (!bacmp(&conn->dst, BDADDR_ANY)) 1270 + return; 1271 + 1566 1272 if (d->cig != conn->iso_qos.cig || d->cis == BT_ISO_QOS_CIS_UNSET || 1567 1273 d->cis != conn->iso_qos.cis) 1568 1274 return; ··· 1578 1276 return; 1579 1277 1580 1278 cis_add(d, &conn->iso_qos); 1279 + } 1280 + 1281 + static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos *qos) 1282 + { 1283 + struct hci_dev *hdev = conn->hdev; 1284 + struct hci_cp_le_create_big cp; 1285 + 1286 + memset(&cp, 0, sizeof(cp)); 1287 + 1288 + cp.handle = qos->big; 1289 + cp.adv_handle = qos->bis; 1290 + cp.num_bis = 0x01; 1291 + hci_cpu_to_le24(qos->out.interval, cp.bis.sdu_interval); 1292 + cp.bis.sdu = cpu_to_le16(qos->out.sdu); 1293 + cp.bis.latency = cpu_to_le16(qos->out.latency); 1294 + cp.bis.rtn = qos->out.rtn; 1295 + cp.bis.phy = qos->out.phy; 1296 + cp.bis.packing = qos->packing; 1297 + cp.bis.framing = qos->framing; 1298 + cp.bis.encryption = 0x00; 1299 + memset(&cp.bis.bcode, 0, sizeof(cp.bis.bcode)); 1300 + 1301 + return hci_send_cmd(hdev, HCI_OP_LE_CREATE_BIG, sizeof(cp), &cp); 1581 1302 } 1582 1303 1583 1304 static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos) ··· 1684 1359 return false; 1685 1360 1686 1361 return true; 1687 - } 1688 - 1689 - static void find_cis(struct hci_conn *conn, void *data) 1690 - { 1691 - struct iso_list_data *d = data; 1692 - 1693 - /* Ignore broadcast */ 1694 - if (!bacmp(&conn->dst, BDADDR_ANY)) 1695 - return; 1696 - 1697 - d->count++; 1698 - } 1699 - 1700 - static int remove_cig_sync(struct hci_dev *hdev, void *data) 1701 - { 1702 - u8 handle = PTR_ERR(data); 1703 - 1704 - return hci_le_remove_cig_sync(hdev, handle); 1705 - } 1706 - 1707 - int hci_le_remove_cig(struct hci_dev *hdev, u8 handle) 1708 - { 1709 - bt_dev_dbg(hdev, "handle 0x%2.2x", handle); 1710 - 1711 - return hci_cmd_sync_queue(hdev, remove_cig_sync, ERR_PTR(handle), NULL); 1712 - } 1713 - 1714 - static void cis_cleanup(struct hci_conn *conn) 1715 - { 1716 - struct hci_dev *hdev = conn->hdev; 1717 - struct iso_list_data d; 1718 - 1719 - memset(&d, 0, sizeof(d)); 1720 - d.cig = conn->iso_qos.cig; 1721 - 1722 - /* Check if ISO connection is a CIS and remove CIG if there are 1723 - * no other connections using it. 1724 - */ 1725 - hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_CONNECTED, &d); 1726 - if (d.count) 1727 - return; 1728 - 1729 - hci_le_remove_cig(hdev, conn->iso_qos.cig); 1730 1362 } 1731 1363 1732 1364 struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst, ··· 1902 1620 /* Use LE ACL connection latency if not set */ 1903 1621 if (!qos->latency) 1904 1622 qos->latency = conn->le_conn_latency; 1623 + } 1624 + 1625 + static struct hci_conn *hci_bind_bis(struct hci_conn *conn, 1626 + struct bt_iso_qos *qos) 1627 + { 1628 + /* Update LINK PHYs according to QoS preference */ 1629 + conn->le_tx_phy = qos->out.phy; 1630 + conn->le_tx_phy = qos->out.phy; 1631 + conn->iso_qos = *qos; 1632 + conn->state = BT_BOUND; 1633 + 1634 + return conn; 1635 + } 1636 + 1637 + static int create_big_sync(struct hci_dev *hdev, void *data) 1638 + { 1639 + struct hci_conn *conn = data; 1640 + struct bt_iso_qos *qos = &conn->iso_qos; 1641 + u16 interval, sync_interval = 0; 1642 + u32 flags = 0; 1643 + int err; 1644 + 1645 + if (qos->out.phy == 0x02) 1646 + flags |= MGMT_ADV_FLAG_SEC_2M; 1647 + 1648 + /* Align intervals */ 1649 + interval = qos->out.interval / 1250; 1650 + 1651 + if (qos->bis) 1652 + sync_interval = qos->sync_interval * 1600; 1653 + 1654 + err = hci_start_per_adv_sync(hdev, qos->bis, conn->le_per_adv_data_len, 1655 + conn->le_per_adv_data, flags, interval, 1656 + interval, sync_interval); 1657 + if (err) 1658 + return err; 1659 + 1660 + return hci_le_create_big(conn, &conn->iso_qos); 1661 + } 1662 + 1663 + static void create_pa_complete(struct hci_dev *hdev, void *data, int err) 1664 + { 1665 + struct hci_cp_le_pa_create_sync *cp = data; 1666 + 1667 + bt_dev_dbg(hdev, ""); 1668 + 1669 + if (err) 1670 + bt_dev_err(hdev, "Unable to create PA: %d", err); 1671 + 1672 + kfree(cp); 1673 + } 1674 + 1675 + static int create_pa_sync(struct hci_dev *hdev, void *data) 1676 + { 1677 + struct hci_cp_le_pa_create_sync *cp = data; 1678 + int err; 1679 + 1680 + err = __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_CREATE_SYNC, 1681 + sizeof(*cp), cp, HCI_CMD_TIMEOUT); 1682 + if (err) { 1683 + hci_dev_clear_flag(hdev, HCI_PA_SYNC); 1684 + return err; 1685 + } 1686 + 1687 + return hci_update_passive_scan_sync(hdev); 1688 + } 1689 + 1690 + int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type, 1691 + __u8 sid) 1692 + { 1693 + struct hci_cp_le_pa_create_sync *cp; 1694 + 1695 + if (hci_dev_test_and_set_flag(hdev, HCI_PA_SYNC)) 1696 + return -EBUSY; 1697 + 1698 + cp = kmalloc(sizeof(*cp), GFP_KERNEL); 1699 + if (!cp) { 1700 + hci_dev_clear_flag(hdev, HCI_PA_SYNC); 1701 + return -ENOMEM; 1702 + } 1703 + 1704 + /* Convert from ISO socket address type to HCI address type */ 1705 + if (dst_type == BDADDR_LE_PUBLIC) 1706 + dst_type = ADDR_LE_DEV_PUBLIC; 1707 + else 1708 + dst_type = ADDR_LE_DEV_RANDOM; 1709 + 1710 + memset(cp, 0, sizeof(*cp)); 1711 + cp->sid = sid; 1712 + cp->addr_type = dst_type; 1713 + bacpy(&cp->addr, dst); 1714 + 1715 + /* Queue start pa_create_sync and scan */ 1716 + return hci_cmd_sync_queue(hdev, create_pa_sync, cp, create_pa_complete); 1717 + } 1718 + 1719 + int hci_le_big_create_sync(struct hci_dev *hdev, struct bt_iso_qos *qos, 1720 + __u16 sync_handle, __u8 num_bis, __u8 bis[]) 1721 + { 1722 + struct _packed { 1723 + struct hci_cp_le_big_create_sync cp; 1724 + __u8 bis[0x11]; 1725 + } pdu; 1726 + int err; 1727 + 1728 + if (num_bis > sizeof(pdu.bis)) 1729 + return -EINVAL; 1730 + 1731 + err = qos_set_big(hdev, qos); 1732 + if (err) 1733 + return err; 1734 + 1735 + memset(&pdu, 0, sizeof(pdu)); 1736 + pdu.cp.handle = qos->big; 1737 + pdu.cp.sync_handle = cpu_to_le16(sync_handle); 1738 + pdu.cp.num_bis = num_bis; 1739 + memcpy(pdu.bis, bis, num_bis); 1740 + 1741 + return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC, 1742 + sizeof(pdu.cp) + num_bis, &pdu); 1743 + } 1744 + 1745 + static void create_big_complete(struct hci_dev *hdev, void *data, int err) 1746 + { 1747 + struct hci_conn *conn = data; 1748 + 1749 + bt_dev_dbg(hdev, "conn %p", conn); 1750 + 1751 + if (err) { 1752 + bt_dev_err(hdev, "Unable to create BIG: %d", err); 1753 + hci_connect_cfm(conn, err); 1754 + hci_conn_del(conn); 1755 + } 1756 + } 1757 + 1758 + struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst, 1759 + __u8 dst_type, struct bt_iso_qos *qos, 1760 + __u8 base_len, __u8 *base) 1761 + { 1762 + struct hci_conn *conn; 1763 + int err; 1764 + 1765 + /* We need hci_conn object using the BDADDR_ANY as dst */ 1766 + conn = hci_add_bis(hdev, dst, qos); 1767 + if (IS_ERR(conn)) 1768 + return conn; 1769 + 1770 + conn = hci_bind_bis(conn, qos); 1771 + if (!conn) { 1772 + hci_conn_drop(conn); 1773 + return ERR_PTR(-ENOMEM); 1774 + } 1775 + 1776 + /* Add Basic Announcement into Peridic Adv Data if BASE is set */ 1777 + if (base_len && base) { 1778 + base_len = eir_append_service_data(conn->le_per_adv_data, 0, 1779 + 0x1851, base, base_len); 1780 + conn->le_per_adv_data_len = base_len; 1781 + } 1782 + 1783 + /* Queue start periodic advertising and create BIG */ 1784 + err = hci_cmd_sync_queue(hdev, create_big_sync, conn, 1785 + create_big_complete); 1786 + if (err < 0) { 1787 + hci_conn_drop(conn); 1788 + return ERR_PTR(err); 1789 + } 1790 + 1791 + hci_iso_qos_setup(hdev, conn, &qos->out, 1792 + conn->le_tx_phy ? conn->le_tx_phy : 1793 + hdev->le_tx_def_phys); 1794 + 1795 + return conn; 1905 1796 } 1906 1797 1907 1798 struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
+50 -30
net/bluetooth/hci_core.c
··· 1702 1702 } 1703 1703 1704 1704 /* This function requires the caller holds hdev->lock */ 1705 - int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, 1706 - u16 adv_data_len, u8 *adv_data, 1707 - u16 scan_rsp_len, u8 *scan_rsp_data, 1708 - u16 timeout, u16 duration, s8 tx_power, 1709 - u32 min_interval, u32 max_interval) 1705 + struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, 1706 + u32 flags, u16 adv_data_len, u8 *adv_data, 1707 + u16 scan_rsp_len, u8 *scan_rsp_data, 1708 + u16 timeout, u16 duration, s8 tx_power, 1709 + u32 min_interval, u32 max_interval) 1710 1710 { 1711 - struct adv_info *adv_instance; 1711 + struct adv_info *adv; 1712 1712 1713 - adv_instance = hci_find_adv_instance(hdev, instance); 1714 - if (adv_instance) { 1715 - memset(adv_instance->adv_data, 0, 1716 - sizeof(adv_instance->adv_data)); 1717 - memset(adv_instance->scan_rsp_data, 0, 1718 - sizeof(adv_instance->scan_rsp_data)); 1713 + adv = hci_find_adv_instance(hdev, instance); 1714 + if (adv) { 1715 + memset(adv->adv_data, 0, sizeof(adv->adv_data)); 1716 + memset(adv->scan_rsp_data, 0, sizeof(adv->scan_rsp_data)); 1717 + memset(adv->per_adv_data, 0, sizeof(adv->per_adv_data)); 1719 1718 } else { 1720 1719 if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets || 1721 1720 instance < 1 || instance > hdev->le_num_of_adv_sets) 1722 - return -EOVERFLOW; 1721 + return ERR_PTR(-EOVERFLOW); 1723 1722 1724 - adv_instance = kzalloc(sizeof(*adv_instance), GFP_KERNEL); 1725 - if (!adv_instance) 1726 - return -ENOMEM; 1723 + adv = kzalloc(sizeof(*adv), GFP_KERNEL); 1724 + if (!adv) 1725 + return ERR_PTR(-ENOMEM); 1727 1726 1728 - adv_instance->pending = true; 1729 - adv_instance->instance = instance; 1730 - list_add(&adv_instance->list, &hdev->adv_instances); 1727 + adv->pending = true; 1728 + adv->instance = instance; 1729 + list_add(&adv->list, &hdev->adv_instances); 1731 1730 hdev->adv_instance_cnt++; 1732 1731 } 1733 1732 1734 - adv_instance->flags = flags; 1735 - adv_instance->min_interval = min_interval; 1736 - adv_instance->max_interval = max_interval; 1737 - adv_instance->tx_power = tx_power; 1733 + adv->flags = flags; 1734 + adv->min_interval = min_interval; 1735 + adv->max_interval = max_interval; 1736 + adv->tx_power = tx_power; 1738 1737 1739 1738 hci_set_adv_instance_data(hdev, instance, adv_data_len, adv_data, 1740 1739 scan_rsp_len, scan_rsp_data); 1741 1740 1742 - adv_instance->timeout = timeout; 1743 - adv_instance->remaining_time = timeout; 1741 + adv->timeout = timeout; 1742 + adv->remaining_time = timeout; 1744 1743 1745 1744 if (duration == 0) 1746 - adv_instance->duration = hdev->def_multi_adv_rotation_duration; 1745 + adv->duration = hdev->def_multi_adv_rotation_duration; 1747 1746 else 1748 - adv_instance->duration = duration; 1747 + adv->duration = duration; 1749 1748 1750 - INIT_DELAYED_WORK(&adv_instance->rpa_expired_cb, 1751 - adv_instance_rpa_expired); 1749 + INIT_DELAYED_WORK(&adv->rpa_expired_cb, adv_instance_rpa_expired); 1752 1750 1753 1751 BT_DBG("%s for %dMR", hdev->name, instance); 1754 1752 1755 - return 0; 1753 + return adv; 1754 + } 1755 + 1756 + /* This function requires the caller holds hdev->lock */ 1757 + struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, 1758 + u32 flags, u8 data_len, u8 *data, 1759 + u32 min_interval, u32 max_interval) 1760 + { 1761 + struct adv_info *adv; 1762 + 1763 + adv = hci_add_adv_instance(hdev, instance, flags, 0, NULL, 0, NULL, 1764 + 0, 0, HCI_ADV_TX_POWER_NO_PREFERENCE, 1765 + min_interval, max_interval); 1766 + if (IS_ERR(adv)) 1767 + return adv; 1768 + 1769 + adv->periodic = true; 1770 + adv->per_adv_data_len = data_len; 1771 + 1772 + if (data) 1773 + memcpy(adv->per_adv_data, data, data_len); 1774 + 1775 + return adv; 1756 1776 } 1757 1777 1758 1778 /* This function requires the caller holds hdev->lock */
+206
net/bluetooth/hci_event.c
··· 3893 3893 return rp->status; 3894 3894 } 3895 3895 3896 + static void hci_cs_le_create_big(struct hci_dev *hdev, u8 status) 3897 + { 3898 + bt_dev_dbg(hdev, "status 0x%2.2x", status); 3899 + } 3900 + 3901 + static u8 hci_cc_set_per_adv_param(struct hci_dev *hdev, void *data, 3902 + struct sk_buff *skb) 3903 + { 3904 + struct hci_ev_status *rp = data; 3905 + struct hci_cp_le_set_per_adv_params *cp; 3906 + 3907 + bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); 3908 + 3909 + if (rp->status) 3910 + return rp->status; 3911 + 3912 + cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS); 3913 + if (!cp) 3914 + return rp->status; 3915 + 3916 + /* TODO: set the conn state */ 3917 + return rp->status; 3918 + } 3919 + 3920 + static u8 hci_cc_le_set_per_adv_enable(struct hci_dev *hdev, void *data, 3921 + struct sk_buff *skb) 3922 + { 3923 + struct hci_ev_status *rp = data; 3924 + __u8 *sent; 3925 + 3926 + bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); 3927 + 3928 + if (rp->status) 3929 + return rp->status; 3930 + 3931 + sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE); 3932 + if (!sent) 3933 + return rp->status; 3934 + 3935 + hci_dev_lock(hdev); 3936 + 3937 + if (*sent) 3938 + hci_dev_set_flag(hdev, HCI_LE_PER_ADV); 3939 + else 3940 + hci_dev_clear_flag(hdev, HCI_LE_PER_ADV); 3941 + 3942 + hci_dev_unlock(hdev); 3943 + 3944 + return rp->status; 3945 + } 3946 + 3896 3947 #define HCI_CC_VL(_op, _func, _min, _max) \ 3897 3948 { \ 3898 3949 .op = _op, \ ··· 4117 4066 hci_cc_le_set_adv_set_random_addr), 4118 4067 HCI_CC_STATUS(HCI_OP_LE_REMOVE_ADV_SET, hci_cc_le_remove_adv_set), 4119 4068 HCI_CC_STATUS(HCI_OP_LE_CLEAR_ADV_SETS, hci_cc_le_clear_adv_sets), 4069 + HCI_CC_STATUS(HCI_OP_LE_SET_PER_ADV_PARAMS, hci_cc_set_per_adv_param), 4070 + HCI_CC_STATUS(HCI_OP_LE_SET_PER_ADV_ENABLE, 4071 + hci_cc_le_set_per_adv_enable), 4120 4072 HCI_CC(HCI_OP_LE_READ_TRANSMIT_POWER, hci_cc_le_read_transmit_power, 4121 4073 sizeof(struct hci_rp_le_read_transmit_power)), 4122 4074 HCI_CC_STATUS(HCI_OP_LE_SET_PRIVACY_MODE, hci_cc_le_set_privacy_mode), ··· 4256 4202 HCI_CS(HCI_OP_LE_START_ENC, hci_cs_le_start_enc), 4257 4203 HCI_CS(HCI_OP_LE_EXT_CREATE_CONN, hci_cs_le_ext_create_conn), 4258 4204 HCI_CS(HCI_OP_LE_CREATE_CIS, hci_cs_le_create_cis), 4205 + HCI_CS(HCI_OP_LE_CREATE_BIG, hci_cs_le_create_big), 4259 4206 }; 4260 4207 4261 4208 static void hci_cmd_status_evt(struct hci_dev *hdev, void *data, ··· 6480 6425 hci_dev_unlock(hdev); 6481 6426 } 6482 6427 6428 + static int hci_le_pa_term_sync(struct hci_dev *hdev, __le16 handle) 6429 + { 6430 + struct hci_cp_le_pa_term_sync cp; 6431 + 6432 + memset(&cp, 0, sizeof(cp)); 6433 + cp.handle = handle; 6434 + 6435 + return hci_send_cmd(hdev, HCI_OP_LE_PA_TERM_SYNC, sizeof(cp), &cp); 6436 + } 6437 + 6438 + static void hci_le_pa_sync_estabilished_evt(struct hci_dev *hdev, void *data, 6439 + struct sk_buff *skb) 6440 + { 6441 + struct hci_ev_le_pa_sync_established *ev = data; 6442 + int mask = hdev->link_mode; 6443 + __u8 flags = 0; 6444 + 6445 + bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); 6446 + 6447 + if (ev->status) 6448 + return; 6449 + 6450 + hci_dev_lock(hdev); 6451 + 6452 + hci_dev_clear_flag(hdev, HCI_PA_SYNC); 6453 + 6454 + mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ISO_LINK, &flags); 6455 + if (!(mask & HCI_LM_ACCEPT)) 6456 + hci_le_pa_term_sync(hdev, ev->handle); 6457 + 6458 + hci_dev_unlock(hdev); 6459 + } 6460 + 6483 6461 static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data, 6484 6462 struct sk_buff *skb) 6485 6463 { ··· 6864 6776 hci_dev_unlock(hdev); 6865 6777 } 6866 6778 6779 + static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data, 6780 + struct sk_buff *skb) 6781 + { 6782 + struct hci_evt_le_create_big_complete *ev = data; 6783 + struct hci_conn *conn; 6784 + 6785 + BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); 6786 + 6787 + if (!hci_le_ev_skb_pull(hdev, skb, HCI_EVT_LE_CREATE_BIG_COMPLETE, 6788 + flex_array_size(ev, bis_handle, ev->num_bis))) 6789 + return; 6790 + 6791 + hci_dev_lock(hdev); 6792 + 6793 + conn = hci_conn_hash_lookup_big(hdev, ev->handle); 6794 + if (!conn) 6795 + goto unlock; 6796 + 6797 + if (ev->num_bis) 6798 + conn->handle = __le16_to_cpu(ev->bis_handle[0]); 6799 + 6800 + if (!ev->status) { 6801 + conn->state = BT_CONNECTED; 6802 + hci_debugfs_create_conn(conn); 6803 + hci_conn_add_sysfs(conn); 6804 + hci_iso_setup_path(conn); 6805 + goto unlock; 6806 + } 6807 + 6808 + hci_connect_cfm(conn, ev->status); 6809 + hci_conn_del(conn); 6810 + 6811 + unlock: 6812 + hci_dev_unlock(hdev); 6813 + } 6814 + 6815 + static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data, 6816 + struct sk_buff *skb) 6817 + { 6818 + struct hci_evt_le_big_sync_estabilished *ev = data; 6819 + struct hci_conn *bis; 6820 + int i; 6821 + 6822 + bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); 6823 + 6824 + if (!hci_le_ev_skb_pull(hdev, skb, HCI_EVT_LE_BIG_SYNC_ESTABILISHED, 6825 + flex_array_size(ev, bis, ev->num_bis))) 6826 + return; 6827 + 6828 + if (ev->status) 6829 + return; 6830 + 6831 + hci_dev_lock(hdev); 6832 + 6833 + for (i = 0; i < ev->num_bis; i++) { 6834 + u16 handle = le16_to_cpu(ev->bis[i]); 6835 + __le32 interval; 6836 + 6837 + bis = hci_conn_hash_lookup_handle(hdev, handle); 6838 + if (!bis) { 6839 + bis = hci_conn_add(hdev, ISO_LINK, BDADDR_ANY, 6840 + HCI_ROLE_SLAVE); 6841 + if (!bis) 6842 + continue; 6843 + bis->handle = handle; 6844 + } 6845 + 6846 + bis->iso_qos.big = ev->handle; 6847 + memset(&interval, 0, sizeof(interval)); 6848 + memcpy(&interval, ev->latency, sizeof(ev->latency)); 6849 + bis->iso_qos.in.interval = le32_to_cpu(interval); 6850 + /* Convert ISO Interval (1.25 ms slots) to latency (ms) */ 6851 + bis->iso_qos.in.latency = le16_to_cpu(ev->interval) * 125 / 100; 6852 + bis->iso_qos.in.sdu = le16_to_cpu(ev->max_pdu); 6853 + 6854 + hci_connect_cfm(bis, ev->status); 6855 + } 6856 + 6857 + hci_dev_unlock(hdev); 6858 + } 6859 + 6860 + static void hci_le_big_info_adv_report_evt(struct hci_dev *hdev, void *data, 6861 + struct sk_buff *skb) 6862 + { 6863 + struct hci_evt_le_big_info_adv_report *ev = data; 6864 + int mask = hdev->link_mode; 6865 + __u8 flags = 0; 6866 + 6867 + bt_dev_dbg(hdev, "sync_handle 0x%4.4x", le16_to_cpu(ev->sync_handle)); 6868 + 6869 + hci_dev_lock(hdev); 6870 + 6871 + mask |= hci_proto_connect_ind(hdev, BDADDR_ANY, ISO_LINK, &flags); 6872 + if (!(mask & HCI_LM_ACCEPT)) 6873 + hci_le_pa_term_sync(hdev, ev->sync_handle); 6874 + 6875 + hci_dev_unlock(hdev); 6876 + } 6877 + 6867 6878 #define HCI_LE_EV_VL(_op, _func, _min_len, _max_len) \ 6868 6879 [_op] = { \ 6869 6880 .func = _func, \ ··· 7023 6836 HCI_LE_EV_VL(HCI_EV_LE_EXT_ADV_REPORT, hci_le_ext_adv_report_evt, 7024 6837 sizeof(struct hci_ev_le_ext_adv_report), 7025 6838 HCI_MAX_EVENT_SIZE), 6839 + /* [0x0e = HCI_EV_LE_PA_SYNC_ESTABLISHED] */ 6840 + HCI_LE_EV(HCI_EV_LE_PA_SYNC_ESTABLISHED, 6841 + hci_le_pa_sync_estabilished_evt, 6842 + sizeof(struct hci_ev_le_pa_sync_established)), 7026 6843 /* [0x12 = HCI_EV_LE_EXT_ADV_SET_TERM] */ 7027 6844 HCI_LE_EV(HCI_EV_LE_EXT_ADV_SET_TERM, hci_le_ext_adv_term_evt, 7028 6845 sizeof(struct hci_evt_le_ext_adv_set_term)), ··· 7036 6845 /* [0x1a = HCI_EVT_LE_CIS_REQ] */ 7037 6846 HCI_LE_EV(HCI_EVT_LE_CIS_REQ, hci_le_cis_req_evt, 7038 6847 sizeof(struct hci_evt_le_cis_req)), 6848 + /* [0x1b = HCI_EVT_LE_CREATE_BIG_COMPLETE] */ 6849 + HCI_LE_EV_VL(HCI_EVT_LE_CREATE_BIG_COMPLETE, 6850 + hci_le_create_big_complete_evt, 6851 + sizeof(struct hci_evt_le_create_big_complete), 6852 + HCI_MAX_EVENT_SIZE), 6853 + /* [0x1d = HCI_EV_LE_BIG_SYNC_ESTABILISHED] */ 6854 + HCI_LE_EV_VL(HCI_EVT_LE_BIG_SYNC_ESTABILISHED, 6855 + hci_le_big_sync_established_evt, 6856 + sizeof(struct hci_evt_le_big_sync_estabilished), 6857 + HCI_MAX_EVENT_SIZE), 6858 + /* [0x22 = HCI_EVT_LE_BIG_INFO_ADV_REPORT] */ 6859 + HCI_LE_EV_VL(HCI_EVT_LE_BIG_INFO_ADV_REPORT, 6860 + hci_le_big_info_adv_report_evt, 6861 + sizeof(struct hci_evt_le_big_info_adv_report), 6862 + HCI_MAX_EVENT_SIZE), 7039 6863 }; 7040 6864 7041 6865 static void hci_le_meta_evt(struct hci_dev *hdev, void *data,
+21 -15
net/bluetooth/hci_request.c
··· 827 827 { 828 828 if (ext_adv_capable(req->hdev)) { 829 829 __hci_req_disable_ext_adv_instance(req, 0x00); 830 - 831 830 } else { 832 831 u8 enable = 0x00; 833 832 ··· 1337 1338 bdaddr_t random_addr; 1338 1339 u8 own_addr_type; 1339 1340 int err; 1340 - struct adv_info *adv_instance; 1341 - bool secondary_adv; 1341 + struct adv_info *adv; 1342 + bool secondary_adv, require_privacy; 1342 1343 1343 1344 if (instance > 0) { 1344 - adv_instance = hci_find_adv_instance(hdev, instance); 1345 - if (!adv_instance) 1345 + adv = hci_find_adv_instance(hdev, instance); 1346 + if (!adv) 1346 1347 return -EINVAL; 1347 1348 } else { 1348 - adv_instance = NULL; 1349 + adv = NULL; 1349 1350 } 1350 1351 1351 1352 flags = hci_adv_instance_flags(hdev, instance); ··· 1363 1364 * advertising is used. In that case it is fine to use a 1364 1365 * non-resolvable private address. 1365 1366 */ 1366 - err = hci_get_random_address(hdev, !connectable, 1367 - adv_use_rpa(hdev, flags), adv_instance, 1367 + require_privacy = !connectable; 1368 + 1369 + /* Don't require privacy for periodic adv? */ 1370 + if (adv && adv->periodic) 1371 + require_privacy = false; 1372 + 1373 + err = hci_get_random_address(hdev, require_privacy, 1374 + adv_use_rpa(hdev, flags), adv, 1368 1375 &own_addr_type, &random_addr); 1369 1376 if (err < 0) 1370 1377 return err; 1371 1378 1372 1379 memset(&cp, 0, sizeof(cp)); 1373 1380 1374 - if (adv_instance) { 1375 - hci_cpu_to_le24(adv_instance->min_interval, cp.min_interval); 1376 - hci_cpu_to_le24(adv_instance->max_interval, cp.max_interval); 1377 - cp.tx_power = adv_instance->tx_power; 1381 + if (adv) { 1382 + hci_cpu_to_le24(adv->min_interval, cp.min_interval); 1383 + hci_cpu_to_le24(adv->max_interval, cp.max_interval); 1384 + cp.tx_power = adv->tx_power; 1378 1385 } else { 1379 1386 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); 1380 1387 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); ··· 1401 1396 else 1402 1397 cp.evt_properties = cpu_to_le16(LE_LEGACY_ADV_SCAN_IND); 1403 1398 } else { 1404 - if (secondary_adv) 1399 + /* Secondary and periodic cannot use legacy PDUs */ 1400 + if (secondary_adv || (adv && adv->periodic)) 1405 1401 cp.evt_properties = cpu_to_le16(LE_EXT_ADV_NON_CONN_IND); 1406 1402 else 1407 1403 cp.evt_properties = cpu_to_le16(LE_LEGACY_NONCONN_IND); ··· 1432 1426 struct hci_cp_le_set_adv_set_rand_addr cp; 1433 1427 1434 1428 /* Check if random address need to be updated */ 1435 - if (adv_instance) { 1436 - if (!bacmp(&random_addr, &adv_instance->random_addr)) 1429 + if (adv) { 1430 + if (!bacmp(&random_addr, &adv->random_addr)) 1437 1431 return 0; 1438 1432 } else { 1439 1433 if (!bacmp(&random_addr, &hdev->random_addr))
+9
net/bluetooth/hci_request.h
··· 83 83 void __hci_req_disable_advertising(struct hci_request *req); 84 84 void __hci_req_update_adv_data(struct hci_request *req, u8 instance); 85 85 int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance); 86 + int hci_req_start_per_adv(struct hci_dev *hdev, u8 instance, u32 flags, 87 + u16 min_interval, u16 max_interval, 88 + u16 sync_interval); 86 89 void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance); 87 90 88 91 int __hci_req_schedule_adv_instance(struct hci_request *req, u8 instance, ··· 95 92 bool force); 96 93 97 94 int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance); 95 + int __hci_req_setup_per_adv_instance(struct hci_request *req, u8 instance, 96 + u16 min_interval, u16 max_interval); 98 97 int __hci_req_start_ext_adv(struct hci_request *req, u8 instance); 98 + int __hci_req_start_per_adv(struct hci_request *req, u8 instance, u32 flags, 99 + u16 min_interval, u16 max_interval, 100 + u16 sync_interval); 99 101 int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance); 102 + int __hci_req_enable_per_advertising(struct hci_request *req, u8 instance); 100 103 int __hci_req_disable_ext_adv_instance(struct hci_request *req, u8 instance); 101 104 int __hci_req_remove_ext_adv_instance(struct hci_request *req, u8 instance); 102 105 void __hci_req_clear_ext_adv_sets(struct hci_request *req);
+248 -1
net/bluetooth/hci_sync.c
··· 977 977 return hci_enable_ext_advertising_sync(hdev, instance); 978 978 } 979 979 980 + static int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) 981 + { 982 + struct hci_cp_le_set_per_adv_enable cp; 983 + 984 + /* If periodic advertising already disabled there is nothing to do. */ 985 + if (!hci_dev_test_flag(hdev, HCI_LE_PER_ADV)) 986 + return 0; 987 + 988 + memset(&cp, 0, sizeof(cp)); 989 + 990 + cp.enable = 0x00; 991 + cp.handle = instance; 992 + 993 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, 994 + sizeof(cp), &cp, HCI_CMD_TIMEOUT); 995 + } 996 + 997 + static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, 998 + u16 min_interval, u16 max_interval) 999 + { 1000 + struct hci_cp_le_set_per_adv_params cp; 1001 + 1002 + memset(&cp, 0, sizeof(cp)); 1003 + 1004 + if (!min_interval) 1005 + min_interval = DISCOV_LE_PER_ADV_INT_MIN; 1006 + 1007 + if (!max_interval) 1008 + max_interval = DISCOV_LE_PER_ADV_INT_MAX; 1009 + 1010 + cp.handle = instance; 1011 + cp.min_interval = cpu_to_le16(min_interval); 1012 + cp.max_interval = cpu_to_le16(max_interval); 1013 + cp.periodic_properties = 0x0000; 1014 + 1015 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS, 1016 + sizeof(cp), &cp, HCI_CMD_TIMEOUT); 1017 + } 1018 + 1019 + static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) 1020 + { 1021 + struct { 1022 + struct hci_cp_le_set_per_adv_data cp; 1023 + u8 data[HCI_MAX_PER_AD_LENGTH]; 1024 + } pdu; 1025 + u8 len; 1026 + 1027 + memset(&pdu, 0, sizeof(pdu)); 1028 + 1029 + if (instance) { 1030 + struct adv_info *adv = hci_find_adv_instance(hdev, instance); 1031 + 1032 + if (!adv || !adv->periodic) 1033 + return 0; 1034 + } 1035 + 1036 + len = eir_create_per_adv_data(hdev, instance, pdu.data); 1037 + 1038 + pdu.cp.length = len; 1039 + pdu.cp.handle = instance; 1040 + pdu.cp.operation = LE_SET_ADV_DATA_OP_COMPLETE; 1041 + 1042 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA, 1043 + sizeof(pdu.cp) + len, &pdu, 1044 + HCI_CMD_TIMEOUT); 1045 + } 1046 + 1047 + static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) 1048 + { 1049 + struct hci_cp_le_set_per_adv_enable cp; 1050 + 1051 + /* If periodic advertising already enabled there is nothing to do. */ 1052 + if (hci_dev_test_flag(hdev, HCI_LE_PER_ADV)) 1053 + return 0; 1054 + 1055 + memset(&cp, 0, sizeof(cp)); 1056 + 1057 + cp.enable = 0x01; 1058 + cp.handle = instance; 1059 + 1060 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, 1061 + sizeof(cp), &cp, HCI_CMD_TIMEOUT); 1062 + } 1063 + 1064 + /* Checks if periodic advertising data contains a Basic Announcement and if it 1065 + * does generates a Broadcast ID and add Broadcast Announcement. 1066 + */ 1067 + static int hci_adv_bcast_annoucement(struct hci_dev *hdev, struct adv_info *adv) 1068 + { 1069 + u8 bid[3]; 1070 + u8 ad[4 + 3]; 1071 + 1072 + /* Skip if NULL adv as instance 0x00 is used for general purpose 1073 + * advertising so it cannot used for the likes of Broadcast Announcement 1074 + * as it can be overwritten at any point. 1075 + */ 1076 + if (!adv) 1077 + return 0; 1078 + 1079 + /* Check if PA data doesn't contains a Basic Audio Announcement then 1080 + * there is nothing to do. 1081 + */ 1082 + if (!eir_get_service_data(adv->per_adv_data, adv->per_adv_data_len, 1083 + 0x1851, NULL)) 1084 + return 0; 1085 + 1086 + /* Check if advertising data already has a Broadcast Announcement since 1087 + * the process may want to control the Broadcast ID directly and in that 1088 + * case the kernel shall no interfere. 1089 + */ 1090 + if (eir_get_service_data(adv->adv_data, adv->adv_data_len, 0x1852, 1091 + NULL)) 1092 + return 0; 1093 + 1094 + /* Generate Broadcast ID */ 1095 + get_random_bytes(bid, sizeof(bid)); 1096 + eir_append_service_data(ad, 0, 0x1852, bid, sizeof(bid)); 1097 + hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); 1098 + 1099 + return hci_update_adv_data_sync(hdev, adv->instance); 1100 + } 1101 + 1102 + int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, 1103 + u8 *data, u32 flags, u16 min_interval, 1104 + u16 max_interval, u16 sync_interval) 1105 + { 1106 + struct adv_info *adv = NULL; 1107 + int err; 1108 + bool added = false; 1109 + 1110 + hci_disable_per_advertising_sync(hdev, instance); 1111 + 1112 + if (instance) { 1113 + adv = hci_find_adv_instance(hdev, instance); 1114 + /* Create an instance if that could not be found */ 1115 + if (!adv) { 1116 + adv = hci_add_per_instance(hdev, instance, flags, 1117 + data_len, data, 1118 + sync_interval, 1119 + sync_interval); 1120 + if (IS_ERR(adv)) 1121 + return PTR_ERR(adv); 1122 + added = true; 1123 + } 1124 + } 1125 + 1126 + /* Only start advertising if instance 0 or if a dedicated instance has 1127 + * been added. 1128 + */ 1129 + if (!adv || added) { 1130 + err = hci_start_ext_adv_sync(hdev, instance); 1131 + if (err < 0) 1132 + goto fail; 1133 + 1134 + err = hci_adv_bcast_annoucement(hdev, adv); 1135 + if (err < 0) 1136 + goto fail; 1137 + } 1138 + 1139 + err = hci_set_per_adv_params_sync(hdev, instance, min_interval, 1140 + max_interval); 1141 + if (err < 0) 1142 + goto fail; 1143 + 1144 + err = hci_set_per_adv_data_sync(hdev, instance); 1145 + if (err < 0) 1146 + goto fail; 1147 + 1148 + err = hci_enable_per_advertising_sync(hdev, instance); 1149 + if (err < 0) 1150 + goto fail; 1151 + 1152 + return 0; 1153 + 1154 + fail: 1155 + if (added) 1156 + hci_remove_adv_instance(hdev, instance); 1157 + 1158 + return err; 1159 + } 1160 + 980 1161 static int hci_start_adv_sync(struct hci_dev *hdev, u8 instance) 981 1162 { 982 1163 int err; ··· 1295 1114 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, 1296 1115 sizeof(instance), &instance, 0, 1297 1116 HCI_CMD_TIMEOUT, sk); 1117 + } 1118 + 1119 + static int remove_ext_adv_sync(struct hci_dev *hdev, void *data) 1120 + { 1121 + struct adv_info *adv = data; 1122 + u8 instance = 0; 1123 + 1124 + if (adv) 1125 + instance = adv->instance; 1126 + 1127 + return hci_remove_ext_adv_instance_sync(hdev, instance, NULL); 1128 + } 1129 + 1130 + int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance) 1131 + { 1132 + struct adv_info *adv = NULL; 1133 + 1134 + if (instance) { 1135 + adv = hci_find_adv_instance(hdev, instance); 1136 + if (!adv) 1137 + return -EINVAL; 1138 + } 1139 + 1140 + return hci_cmd_sync_queue(hdev, remove_ext_adv_sync, adv, NULL); 1141 + } 1142 + 1143 + int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) 1144 + { 1145 + struct hci_cp_le_term_big cp; 1146 + 1147 + memset(&cp, 0, sizeof(cp)); 1148 + cp.handle = handle; 1149 + cp.reason = reason; 1150 + 1151 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG, 1152 + sizeof(cp), &cp, HCI_CMD_TIMEOUT); 1298 1153 } 1299 1154 1300 1155 static void cancel_adv_timeout(struct hci_dev *hdev) ··· 2418 2201 2419 2202 if (list_empty(&hdev->pend_le_conns) && 2420 2203 list_empty(&hdev->pend_le_reports) && 2421 - !hci_is_adv_monitoring(hdev)) { 2204 + !hci_is_adv_monitoring(hdev) && 2205 + !hci_dev_test_flag(hdev, HCI_PA_SYNC)) { 2422 2206 /* If there is no pending LE connections or devices 2423 2207 * to be scanned for or no ADV monitors, we should stop the 2424 2208 * background scanning. ··· 3621 3403 events[3] |= 0x01; /* LE CIS Established */ 3622 3404 if (cis_peripheral_capable(hdev)) 3623 3405 events[3] |= 0x02; /* LE CIS Request */ 3406 + } 3407 + 3408 + if (bis_capable(hdev)) { 3409 + events[3] |= 0x04; /* LE Create BIG Complete */ 3410 + events[3] |= 0x08; /* LE Terminate BIG Complete */ 3411 + events[3] |= 0x10; /* LE BIG Sync Established */ 3412 + events[3] |= 0x20; /* LE BIG Sync Loss */ 3624 3413 } 3625 3414 3626 3415 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EVENT_MASK, ··· 5708 5483 5709 5484 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REMOVE_CIG, sizeof(cp), 5710 5485 &cp, HCI_CMD_TIMEOUT); 5486 + } 5487 + 5488 + int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle) 5489 + { 5490 + struct hci_cp_le_big_term_sync cp; 5491 + 5492 + memset(&cp, 0, sizeof(cp)); 5493 + cp.handle = handle; 5494 + 5495 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_BIG_TERM_SYNC, 5496 + sizeof(cp), &cp, HCI_CMD_TIMEOUT); 5497 + } 5498 + 5499 + int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle) 5500 + { 5501 + struct hci_cp_le_pa_term_sync cp; 5502 + 5503 + memset(&cp, 0, sizeof(cp)); 5504 + cp.handle = cpu_to_le16(handle); 5505 + 5506 + return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC, 5507 + sizeof(cp), &cp, HCI_CMD_TIMEOUT); 5711 5508 }
+8 -7
net/bluetooth/mgmt.c
··· 8158 8158 u16 timeout, duration; 8159 8159 unsigned int prev_instance_cnt; 8160 8160 u8 schedule_instance = 0; 8161 - struct adv_info *next_instance; 8161 + struct adv_info *adv, *next_instance; 8162 8162 int err; 8163 8163 struct mgmt_pending_cmd *cmd; 8164 8164 ··· 8209 8209 8210 8210 prev_instance_cnt = hdev->adv_instance_cnt; 8211 8211 8212 - err = hci_add_adv_instance(hdev, cp->instance, flags, 8212 + adv = hci_add_adv_instance(hdev, cp->instance, flags, 8213 8213 cp->adv_data_len, cp->data, 8214 8214 cp->scan_rsp_len, 8215 8215 cp->data + cp->adv_data_len, ··· 8217 8217 HCI_ADV_TX_POWER_NO_PREFERENCE, 8218 8218 hdev->le_adv_min_interval, 8219 8219 hdev->le_adv_max_interval); 8220 - if (err < 0) { 8220 + if (IS_ERR(adv)) { 8221 8221 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, 8222 8222 MGMT_STATUS_FAILED); 8223 8223 goto unlock; ··· 8348 8348 struct mgmt_cp_add_ext_adv_params *cp = data; 8349 8349 struct mgmt_rp_add_ext_adv_params rp; 8350 8350 struct mgmt_pending_cmd *cmd = NULL; 8351 + struct adv_info *adv; 8351 8352 u32 flags, min_interval, max_interval; 8352 8353 u16 timeout, duration; 8353 8354 u8 status; ··· 8418 8417 HCI_ADV_TX_POWER_NO_PREFERENCE; 8419 8418 8420 8419 /* Create advertising instance with no advertising or response data */ 8421 - err = hci_add_adv_instance(hdev, cp->instance, flags, 8422 - 0, NULL, 0, NULL, timeout, duration, 8423 - tx_power, min_interval, max_interval); 8420 + adv = hci_add_adv_instance(hdev, cp->instance, flags, 0, NULL, 0, NULL, 8421 + timeout, duration, tx_power, min_interval, 8422 + max_interval); 8424 8423 8425 - if (err < 0) { 8424 + if (IS_ERR(adv)) { 8426 8425 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, 8427 8426 MGMT_STATUS_FAILED); 8428 8427 goto unlock;