.. | .. |
---|
122 | 122 | |
---|
123 | 123 | hci_conn_hash_del(hdev, conn); |
---|
124 | 124 | |
---|
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 | + } |
---|
127 | 137 | |
---|
128 | 138 | hci_conn_del_sysfs(conn); |
---|
129 | 139 | |
---|
.. | .. |
---|
215 | 225 | } |
---|
216 | 226 | |
---|
217 | 227 | 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); |
---|
220 | 228 | } |
---|
221 | 229 | |
---|
222 | 230 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
---|
.. | .. |
---|
232 | 240 | { |
---|
233 | 241 | BT_DBG("hcon %p", conn); |
---|
234 | 242 | |
---|
235 | | - /* When we are master of an established connection and it enters |
---|
| 243 | + /* When we are central of an established connection and it enters |
---|
236 | 244 | * the disconnect timeout, then go ahead and try to read the |
---|
237 | 245 | * current clock offset. Processing of the result is done |
---|
238 | 246 | * within the event handling and hci_clock_offset_evt function. |
---|
.. | .. |
---|
467 | 475 | &conn->dst); |
---|
468 | 476 | } |
---|
469 | 477 | |
---|
| 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 | + |
---|
470 | 495 | static void le_conn_timeout(struct work_struct *work) |
---|
471 | 496 | { |
---|
472 | 497 | struct hci_conn *conn = container_of(work, struct hci_conn, |
---|
.. | .. |
---|
481 | 506 | * (which doesn't have a timeout of its own). |
---|
482 | 507 | */ |
---|
483 | 508 | 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); |
---|
487 | 512 | hci_le_conn_failed(conn, HCI_ERROR_ADVERTISING_TIMEOUT); |
---|
| 513 | + hci_dev_unlock(hdev); |
---|
488 | 514 | return; |
---|
489 | 515 | } |
---|
490 | 516 | |
---|
.. | .. |
---|
519 | 545 | |
---|
520 | 546 | set_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
---|
521 | 547 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
---|
| 548 | + |
---|
| 549 | + /* Set Default Authenticated payload timeout to 30s */ |
---|
| 550 | + conn->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; |
---|
522 | 551 | |
---|
523 | 552 | if (conn->role == HCI_ROLE_MASTER) |
---|
524 | 553 | conn->out = true; |
---|
.. | .. |
---|
558 | 587 | hci_dev_hold(hdev); |
---|
559 | 588 | |
---|
560 | 589 | 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 | + } |
---|
563 | 599 | |
---|
564 | 600 | hci_conn_init_sysfs(conn); |
---|
565 | 601 | |
---|
.. | .. |
---|
755 | 791 | |
---|
756 | 792 | memset(p, 0, sizeof(*p)); |
---|
757 | 793 | |
---|
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); |
---|
763 | 796 | p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); |
---|
764 | 797 | p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); |
---|
765 | 798 | p->conn_latency = cpu_to_le16(conn->le_conn_latency); |
---|
.. | .. |
---|
841 | 874 | |
---|
842 | 875 | memset(&cp, 0, sizeof(cp)); |
---|
843 | 876 | |
---|
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); |
---|
849 | 879 | |
---|
850 | 880 | bacpy(&cp.peer_addr, &conn->dst); |
---|
851 | 881 | cp.peer_addr_type = conn->dst_type; |
---|
.. | .. |
---|
895 | 925 | cp.peer_addr_type = conn->dst_type; |
---|
896 | 926 | bacpy(&cp.peer_addr, &conn->dst); |
---|
897 | 927 | |
---|
| 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 | + |
---|
898 | 938 | hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp); |
---|
899 | 939 | |
---|
900 | 940 | if (own_addr_type == ADDR_LE_DEV_RANDOM && |
---|
.. | .. |
---|
912 | 952 | sizeof(cp), &cp); |
---|
913 | 953 | } |
---|
914 | 954 | |
---|
915 | | - __hci_req_enable_ext_advertising(req); |
---|
| 955 | + __hci_req_enable_ext_advertising(req, 0x00); |
---|
916 | 956 | } else { |
---|
917 | 957 | struct hci_cp_le_set_adv_param cp; |
---|
918 | 958 | |
---|
.. | .. |
---|
964 | 1004 | struct smp_irk *irk; |
---|
965 | 1005 | struct hci_request req; |
---|
966 | 1006 | 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; |
---|
967 | 1012 | |
---|
968 | 1013 | /* Let's make sure that le is enabled.*/ |
---|
969 | 1014 | if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { |
---|
.. | .. |
---|
1020 | 1065 | |
---|
1021 | 1066 | hci_req_init(&req, hdev); |
---|
1022 | 1067 | |
---|
1023 | | - /* Disable advertising if we're active. For master role |
---|
| 1068 | + /* Disable advertising if we're active. For central role |
---|
1024 | 1069 | * 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 |
---|
1026 | 1071 | * anyway have to disable it in order to start directed |
---|
1027 | 1072 | * advertising. |
---|
1028 | 1073 | */ |
---|
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); |
---|
1034 | 1076 | |
---|
1035 | | - /* If requested to connect as slave use directed advertising */ |
---|
| 1077 | + /* If requested to connect as peripheral use directed advertising */ |
---|
1036 | 1078 | if (conn->role == HCI_ROLE_SLAVE) { |
---|
1037 | 1079 | /* If we're active scanning most controllers are unable |
---|
1038 | 1080 | * to initiate advertising. Simply reject the attempt. |
---|
.. | .. |
---|
1068 | 1110 | * state. |
---|
1069 | 1111 | */ |
---|
1070 | 1112 | 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); |
---|
1072 | 1114 | hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); |
---|
1073 | 1115 | } |
---|
1074 | 1116 | |
---|
.. | .. |
---|
1139 | 1181 | /* This function requires the caller holds hdev->lock */ |
---|
1140 | 1182 | struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, |
---|
1141 | 1183 | u8 dst_type, u8 sec_level, |
---|
1142 | | - u16 conn_timeout) |
---|
| 1184 | + u16 conn_timeout, |
---|
| 1185 | + enum conn_reasons conn_reason) |
---|
1143 | 1186 | { |
---|
1144 | 1187 | struct hci_conn *conn; |
---|
1145 | 1188 | |
---|
.. | .. |
---|
1184 | 1227 | conn->sec_level = BT_SECURITY_LOW; |
---|
1185 | 1228 | conn->pending_sec_level = sec_level; |
---|
1186 | 1229 | conn->conn_timeout = conn_timeout; |
---|
| 1230 | + conn->conn_reason = conn_reason; |
---|
1187 | 1231 | |
---|
1188 | 1232 | hci_update_background_scan(hdev); |
---|
1189 | 1233 | |
---|
.. | .. |
---|
1193 | 1237 | } |
---|
1194 | 1238 | |
---|
1195 | 1239 | 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) |
---|
1197 | 1242 | { |
---|
1198 | 1243 | struct hci_conn *acl; |
---|
1199 | 1244 | |
---|
.. | .. |
---|
1213 | 1258 | |
---|
1214 | 1259 | hci_conn_hold(acl); |
---|
1215 | 1260 | |
---|
| 1261 | + acl->conn_reason = conn_reason; |
---|
1216 | 1262 | if (acl->state == BT_OPEN || acl->state == BT_CLOSED) { |
---|
1217 | 1263 | acl->sec_level = BT_SECURITY_LOW; |
---|
1218 | 1264 | acl->pending_sec_level = sec_level; |
---|
.. | .. |
---|
1229 | 1275 | struct hci_conn *acl; |
---|
1230 | 1276 | struct hci_conn *sco; |
---|
1231 | 1277 | |
---|
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); |
---|
1233 | 1280 | if (IS_ERR(acl)) |
---|
1234 | 1281 | return acl; |
---|
1235 | 1282 | |
---|
.. | .. |
---|
1343 | 1390 | return 0; |
---|
1344 | 1391 | } |
---|
1345 | 1392 | |
---|
1346 | | -/* Encrypt the the link */ |
---|
| 1393 | +/* Encrypt the link */ |
---|
1347 | 1394 | static void hci_conn_encrypt(struct hci_conn *conn) |
---|
1348 | 1395 | { |
---|
1349 | 1396 | BT_DBG("hcon %p", conn); |
---|
.. | .. |
---|
1739 | 1786 | |
---|
1740 | 1787 | return hchan; |
---|
1741 | 1788 | } |
---|
| 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 | +} |
---|