hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/bluetooth/hci_conn.c
....@@ -122,8 +122,18 @@
122122
123123 hci_conn_hash_del(hdev, conn);
124124
125
- if (hdev->notify)
126
- hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
125
+ if (conn->type == SCO_LINK || conn->type == ESCO_LINK) {
126
+ switch (conn->setting & SCO_AIRMODE_MASK) {
127
+ case SCO_AIRMODE_CVSD:
128
+ case SCO_AIRMODE_TRANSP:
129
+ if (hdev->notify)
130
+ hdev->notify(hdev, HCI_NOTIFY_DISABLE_SCO);
131
+ break;
132
+ }
133
+ } else {
134
+ if (hdev->notify)
135
+ hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
136
+ }
127137
128138 hci_conn_del_sysfs(conn);
129139
....@@ -215,8 +225,6 @@
215225 }
216226
217227 memcpy(conn->dev_class, ie->data.dev_class, 3);
218
- if (ie->data.ssp_mode > 0)
219
- set_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
220228 }
221229
222230 cp.pkt_type = cpu_to_le16(conn->pkt_type);
....@@ -232,7 +240,7 @@
232240 {
233241 BT_DBG("hcon %p", conn);
234242
235
- /* When we are master of an established connection and it enters
243
+ /* When we are central of an established connection and it enters
236244 * the disconnect timeout, then go ahead and try to read the
237245 * current clock offset. Processing of the result is done
238246 * within the event handling and hci_clock_offset_evt function.
....@@ -467,6 +475,23 @@
467475 &conn->dst);
468476 }
469477
478
+static void le_disable_advertising(struct hci_dev *hdev)
479
+{
480
+ if (ext_adv_capable(hdev)) {
481
+ struct hci_cp_le_set_ext_adv_enable cp;
482
+
483
+ cp.enable = 0x00;
484
+ cp.num_of_sets = 0x00;
485
+
486
+ hci_send_cmd(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, sizeof(cp),
487
+ &cp);
488
+ } else {
489
+ u8 enable = 0x00;
490
+ hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
491
+ &enable);
492
+ }
493
+}
494
+
470495 static void le_conn_timeout(struct work_struct *work)
471496 {
472497 struct hci_conn *conn = container_of(work, struct hci_conn,
....@@ -481,10 +506,11 @@
481506 * (which doesn't have a timeout of its own).
482507 */
483508 if (conn->role == HCI_ROLE_SLAVE) {
484
- u8 enable = 0x00;
485
- hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
486
- &enable);
509
+ /* Disable LE Advertising */
510
+ le_disable_advertising(hdev);
511
+ hci_dev_lock(hdev);
487512 hci_le_conn_failed(conn, HCI_ERROR_ADVERTISING_TIMEOUT);
513
+ hci_dev_unlock(hdev);
488514 return;
489515 }
490516
....@@ -519,6 +545,9 @@
519545
520546 set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
521547 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
548
+
549
+ /* Set Default Authenticated payload timeout to 30s */
550
+ conn->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
522551
523552 if (conn->role == HCI_ROLE_MASTER)
524553 conn->out = true;
....@@ -558,8 +587,15 @@
558587 hci_dev_hold(hdev);
559588
560589 hci_conn_hash_add(hdev, conn);
561
- if (hdev->notify)
562
- hdev->notify(hdev, HCI_NOTIFY_CONN_ADD);
590
+
591
+ /* The SCO and eSCO connections will only be notified when their
592
+ * setup has been completed. This is different to ACL links which
593
+ * can be notified right away.
594
+ */
595
+ if (conn->type != SCO_LINK && conn->type != ESCO_LINK) {
596
+ if (hdev->notify)
597
+ hdev->notify(hdev, HCI_NOTIFY_CONN_ADD);
598
+ }
563599
564600 hci_conn_init_sysfs(conn);
565601
....@@ -755,11 +791,8 @@
755791
756792 memset(p, 0, sizeof(*p));
757793
758
- /* Set window to be the same value as the interval to
759
- * enable continuous scanning.
760
- */
761
- p->scan_interval = cpu_to_le16(hdev->le_scan_interval);
762
- p->scan_window = p->scan_interval;
794
+ p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect);
795
+ p->scan_window = cpu_to_le16(hdev->le_scan_window_connect);
763796 p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval);
764797 p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval);
765798 p->conn_latency = cpu_to_le16(conn->le_conn_latency);
....@@ -841,11 +874,8 @@
841874
842875 memset(&cp, 0, sizeof(cp));
843876
844
- /* Set window to be the same value as the interval to enable
845
- * continuous scanning.
846
- */
847
- cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
848
- cp.scan_window = cp.scan_interval;
877
+ cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect);
878
+ cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect);
849879
850880 bacpy(&cp.peer_addr, &conn->dst);
851881 cp.peer_addr_type = conn->dst_type;
....@@ -895,6 +925,16 @@
895925 cp.peer_addr_type = conn->dst_type;
896926 bacpy(&cp.peer_addr, &conn->dst);
897927
928
+ /* As per Core Spec 5.2 Vol 2, PART E, Sec 7.8.53, for
929
+ * advertising_event_property LE_LEGACY_ADV_DIRECT_IND
930
+ * does not supports advertising data when the advertising set already
931
+ * contains some, the controller shall return erroc code 'Invalid
932
+ * HCI Command Parameters(0x12).
933
+ * So it is required to remove adv set for handle 0x00. since we use
934
+ * instance 0 for directed adv.
935
+ */
936
+ __hci_req_remove_ext_adv_instance(req, cp.handle);
937
+
898938 hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
899939
900940 if (own_addr_type == ADDR_LE_DEV_RANDOM &&
....@@ -912,7 +952,7 @@
912952 sizeof(cp), &cp);
913953 }
914954
915
- __hci_req_enable_ext_advertising(req);
955
+ __hci_req_enable_ext_advertising(req, 0x00);
916956 } else {
917957 struct hci_cp_le_set_adv_param cp;
918958
....@@ -964,6 +1004,11 @@
9641004 struct smp_irk *irk;
9651005 struct hci_request req;
9661006 int err;
1007
+
1008
+ /* This ensures that during disable le_scan address resolution
1009
+ * will not be disabled if it is followed by le_create_conn
1010
+ */
1011
+ bool rpa_le_conn = true;
9671012
9681013 /* Let's make sure that le is enabled.*/
9691014 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
....@@ -1020,19 +1065,16 @@
10201065
10211066 hci_req_init(&req, hdev);
10221067
1023
- /* Disable advertising if we're active. For master role
1068
+ /* Disable advertising if we're active. For central role
10241069 * connections most controllers will refuse to connect if
1025
- * advertising is enabled, and for slave role connections we
1070
+ * advertising is enabled, and for peripheral role connections we
10261071 * anyway have to disable it in order to start directed
10271072 * advertising.
10281073 */
1029
- if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
1030
- u8 enable = 0x00;
1031
- hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
1032
- &enable);
1033
- }
1074
+ if (hci_dev_test_flag(hdev, HCI_LE_ADV))
1075
+ __hci_req_disable_advertising(&req);
10341076
1035
- /* If requested to connect as slave use directed advertising */
1077
+ /* If requested to connect as peripheral use directed advertising */
10361078 if (conn->role == HCI_ROLE_SLAVE) {
10371079 /* If we're active scanning most controllers are unable
10381080 * to initiate advertising. Simply reject the attempt.
....@@ -1068,7 +1110,7 @@
10681110 * state.
10691111 */
10701112 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
1071
- hci_req_add_le_scan_disable(&req);
1113
+ hci_req_add_le_scan_disable(&req, rpa_le_conn);
10721114 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED);
10731115 }
10741116
....@@ -1139,7 +1181,8 @@
11391181 /* This function requires the caller holds hdev->lock */
11401182 struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
11411183 u8 dst_type, u8 sec_level,
1142
- u16 conn_timeout)
1184
+ u16 conn_timeout,
1185
+ enum conn_reasons conn_reason)
11431186 {
11441187 struct hci_conn *conn;
11451188
....@@ -1184,6 +1227,7 @@
11841227 conn->sec_level = BT_SECURITY_LOW;
11851228 conn->pending_sec_level = sec_level;
11861229 conn->conn_timeout = conn_timeout;
1230
+ conn->conn_reason = conn_reason;
11871231
11881232 hci_update_background_scan(hdev);
11891233
....@@ -1193,7 +1237,8 @@
11931237 }
11941238
11951239 struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
1196
- u8 sec_level, u8 auth_type)
1240
+ u8 sec_level, u8 auth_type,
1241
+ enum conn_reasons conn_reason)
11971242 {
11981243 struct hci_conn *acl;
11991244
....@@ -1213,6 +1258,7 @@
12131258
12141259 hci_conn_hold(acl);
12151260
1261
+ acl->conn_reason = conn_reason;
12161262 if (acl->state == BT_OPEN || acl->state == BT_CLOSED) {
12171263 acl->sec_level = BT_SECURITY_LOW;
12181264 acl->pending_sec_level = sec_level;
....@@ -1229,7 +1275,8 @@
12291275 struct hci_conn *acl;
12301276 struct hci_conn *sco;
12311277
1232
- acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
1278
+ acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING,
1279
+ CONN_REASON_SCO_CONNECT);
12331280 if (IS_ERR(acl))
12341281 return acl;
12351282
....@@ -1343,7 +1390,7 @@
13431390 return 0;
13441391 }
13451392
1346
-/* Encrypt the the link */
1393
+/* Encrypt the link */
13471394 static void hci_conn_encrypt(struct hci_conn *conn)
13481395 {
13491396 BT_DBG("hcon %p", conn);
....@@ -1739,3 +1786,106 @@
17391786
17401787 return hchan;
17411788 }
1789
+
1790
+u32 hci_conn_get_phy(struct hci_conn *conn)
1791
+{
1792
+ u32 phys = 0;
1793
+
1794
+ /* BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 2, Part B page 471:
1795
+ * Table 6.2: Packets defined for synchronous, asynchronous, and
1796
+ * CSB logical transport types.
1797
+ */
1798
+ switch (conn->type) {
1799
+ case SCO_LINK:
1800
+ /* SCO logical transport (1 Mb/s):
1801
+ * HV1, HV2, HV3 and DV.
1802
+ */
1803
+ phys |= BT_PHY_BR_1M_1SLOT;
1804
+
1805
+ break;
1806
+
1807
+ case ACL_LINK:
1808
+ /* ACL logical transport (1 Mb/s) ptt=0:
1809
+ * DH1, DM3, DH3, DM5 and DH5.
1810
+ */
1811
+ phys |= BT_PHY_BR_1M_1SLOT;
1812
+
1813
+ if (conn->pkt_type & (HCI_DM3 | HCI_DH3))
1814
+ phys |= BT_PHY_BR_1M_3SLOT;
1815
+
1816
+ if (conn->pkt_type & (HCI_DM5 | HCI_DH5))
1817
+ phys |= BT_PHY_BR_1M_5SLOT;
1818
+
1819
+ /* ACL logical transport (2 Mb/s) ptt=1:
1820
+ * 2-DH1, 2-DH3 and 2-DH5.
1821
+ */
1822
+ if (!(conn->pkt_type & HCI_2DH1))
1823
+ phys |= BT_PHY_EDR_2M_1SLOT;
1824
+
1825
+ if (!(conn->pkt_type & HCI_2DH3))
1826
+ phys |= BT_PHY_EDR_2M_3SLOT;
1827
+
1828
+ if (!(conn->pkt_type & HCI_2DH5))
1829
+ phys |= BT_PHY_EDR_2M_5SLOT;
1830
+
1831
+ /* ACL logical transport (3 Mb/s) ptt=1:
1832
+ * 3-DH1, 3-DH3 and 3-DH5.
1833
+ */
1834
+ if (!(conn->pkt_type & HCI_3DH1))
1835
+ phys |= BT_PHY_EDR_3M_1SLOT;
1836
+
1837
+ if (!(conn->pkt_type & HCI_3DH3))
1838
+ phys |= BT_PHY_EDR_3M_3SLOT;
1839
+
1840
+ if (!(conn->pkt_type & HCI_3DH5))
1841
+ phys |= BT_PHY_EDR_3M_5SLOT;
1842
+
1843
+ break;
1844
+
1845
+ case ESCO_LINK:
1846
+ /* eSCO logical transport (1 Mb/s): EV3, EV4 and EV5 */
1847
+ phys |= BT_PHY_BR_1M_1SLOT;
1848
+
1849
+ if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
1850
+ phys |= BT_PHY_BR_1M_3SLOT;
1851
+
1852
+ /* eSCO logical transport (2 Mb/s): 2-EV3, 2-EV5 */
1853
+ if (!(conn->pkt_type & ESCO_2EV3))
1854
+ phys |= BT_PHY_EDR_2M_1SLOT;
1855
+
1856
+ if (!(conn->pkt_type & ESCO_2EV5))
1857
+ phys |= BT_PHY_EDR_2M_3SLOT;
1858
+
1859
+ /* eSCO logical transport (3 Mb/s): 3-EV3, 3-EV5 */
1860
+ if (!(conn->pkt_type & ESCO_3EV3))
1861
+ phys |= BT_PHY_EDR_3M_1SLOT;
1862
+
1863
+ if (!(conn->pkt_type & ESCO_3EV5))
1864
+ phys |= BT_PHY_EDR_3M_3SLOT;
1865
+
1866
+ break;
1867
+
1868
+ case LE_LINK:
1869
+ if (conn->le_tx_phy & HCI_LE_SET_PHY_1M)
1870
+ phys |= BT_PHY_LE_1M_TX;
1871
+
1872
+ if (conn->le_rx_phy & HCI_LE_SET_PHY_1M)
1873
+ phys |= BT_PHY_LE_1M_RX;
1874
+
1875
+ if (conn->le_tx_phy & HCI_LE_SET_PHY_2M)
1876
+ phys |= BT_PHY_LE_2M_TX;
1877
+
1878
+ if (conn->le_rx_phy & HCI_LE_SET_PHY_2M)
1879
+ phys |= BT_PHY_LE_2M_RX;
1880
+
1881
+ if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED)
1882
+ phys |= BT_PHY_LE_CODED_TX;
1883
+
1884
+ if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED)
1885
+ phys |= BT_PHY_LE_CODED_RX;
1886
+
1887
+ break;
1888
+ }
1889
+
1890
+ return phys;
1891
+}