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

Bluetooth: HCI: Always use the identity address when initializing a connection

This makes sure hci_conn is initialized with the identity address if
a matching IRK exists which avoids the trouble of having to do it at
multiple places which seems to be missing (e.g. CIS, BIS and PA).

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

+40 -29
+2 -2
include/net/bluetooth/hci_core.h
··· 1571 1571 int hci_conn_check_create_cis(struct hci_conn *conn); 1572 1572 1573 1573 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, 1574 - u8 role, u16 handle); 1574 + u8 dst_type, u8 role, u16 handle); 1575 1575 struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, 1576 - bdaddr_t *dst, u8 role); 1576 + bdaddr_t *dst, u8 dst_type, u8 role); 1577 1577 void hci_conn_del(struct hci_conn *conn); 1578 1578 void hci_conn_hash_flush(struct hci_dev *hdev); 1579 1579
+27 -16
net/bluetooth/hci_conn.c
··· 922 922 U16_MAX, GFP_ATOMIC); 923 923 } 924 924 925 - static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, 925 + static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, 926 + bdaddr_t *dst, u8 dst_type, 926 927 u8 role, u16 handle) 927 928 { 928 929 struct hci_conn *conn; 930 + struct smp_irk *irk = NULL; 929 931 930 932 switch (type) { 931 933 case ACL_LINK: ··· 939 937 case PA_LINK: 940 938 if (!hdev->iso_mtu) 941 939 return ERR_PTR(-ECONNREFUSED); 940 + irk = hci_get_irk(hdev, dst, dst_type); 942 941 break; 943 942 case LE_LINK: 944 943 if (hdev->le_mtu && hdev->le_mtu < HCI_MIN_LE_MTU) 945 944 return ERR_PTR(-ECONNREFUSED); 946 945 if (!hdev->le_mtu && hdev->acl_mtu < HCI_MIN_LE_MTU) 947 946 return ERR_PTR(-ECONNREFUSED); 947 + irk = hci_get_irk(hdev, dst, dst_type); 948 948 break; 949 949 case SCO_LINK: 950 950 case ESCO_LINK: ··· 964 960 if (!conn) 965 961 return ERR_PTR(-ENOMEM); 966 962 967 - bacpy(&conn->dst, dst); 963 + /* If and IRK exists use its identity address */ 964 + if (!irk) { 965 + bacpy(&conn->dst, dst); 966 + conn->dst_type = dst_type; 967 + } else { 968 + bacpy(&conn->dst, &irk->bdaddr); 969 + conn->dst_type = irk->addr_type; 970 + } 971 + 968 972 bacpy(&conn->src, &hdev->bdaddr); 969 973 conn->handle = handle; 970 974 conn->hdev = hdev; ··· 1071 1059 } 1072 1060 1073 1061 struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, 1074 - bdaddr_t *dst, u8 role) 1062 + bdaddr_t *dst, u8 dst_type, u8 role) 1075 1063 { 1076 1064 int handle; 1077 1065 ··· 1081 1069 if (unlikely(handle < 0)) 1082 1070 return ERR_PTR(-ECONNREFUSED); 1083 1071 1084 - return __hci_conn_add(hdev, type, dst, role, handle); 1072 + return __hci_conn_add(hdev, type, dst, dst_type, role, handle); 1085 1073 } 1086 1074 1087 1075 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, 1088 - u8 role, u16 handle) 1076 + u8 dst_type, u8 role, u16 handle) 1089 1077 { 1090 1078 if (handle > HCI_CONN_HANDLE_MAX) 1091 1079 return ERR_PTR(-EINVAL); 1092 1080 1093 - return __hci_conn_add(hdev, type, dst, role, handle); 1081 + return __hci_conn_add(hdev, type, dst, dst_type, role, handle); 1094 1082 } 1095 1083 1096 1084 static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason) ··· 1422 1410 if (conn) { 1423 1411 bacpy(&conn->dst, dst); 1424 1412 } else { 1425 - conn = hci_conn_add_unset(hdev, LE_LINK, dst, role); 1413 + conn = hci_conn_add_unset(hdev, LE_LINK, dst, dst_type, role); 1426 1414 if (IS_ERR(conn)) 1427 1415 return conn; 1428 1416 hci_conn_hold(conn); 1429 1417 conn->pending_sec_level = sec_level; 1430 1418 } 1431 1419 1432 - conn->dst_type = dst_type; 1433 1420 conn->sec_level = BT_SECURITY_LOW; 1434 1421 conn->conn_timeout = conn_timeout; 1435 1422 conn->le_adv_phy = phy; ··· 1598 1587 memcmp(conn->le_per_adv_data, base, base_len))) 1599 1588 return ERR_PTR(-EADDRINUSE); 1600 1589 1601 - conn = hci_conn_add_unset(hdev, BIS_LINK, dst, HCI_ROLE_MASTER); 1590 + conn = hci_conn_add_unset(hdev, BIS_LINK, dst, 0, HCI_ROLE_MASTER); 1602 1591 if (IS_ERR(conn)) 1603 1592 return conn; 1604 1593 ··· 1644 1633 1645 1634 BT_DBG("requesting refresh of dst_addr"); 1646 1635 1647 - conn = hci_conn_add_unset(hdev, LE_LINK, dst, HCI_ROLE_MASTER); 1636 + conn = hci_conn_add_unset(hdev, LE_LINK, dst, dst_type, 1637 + HCI_ROLE_MASTER); 1648 1638 if (IS_ERR(conn)) 1649 1639 return conn; 1650 1640 ··· 1656 1644 1657 1645 conn->state = BT_CONNECT; 1658 1646 set_bit(HCI_CONN_SCANNING, &conn->flags); 1659 - conn->dst_type = dst_type; 1660 1647 conn->sec_level = BT_SECURITY_LOW; 1661 1648 conn->pending_sec_level = sec_level; 1662 1649 conn->conn_timeout = conn_timeout; ··· 1692 1681 1693 1682 acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst); 1694 1683 if (!acl) { 1695 - acl = hci_conn_add_unset(hdev, ACL_LINK, dst, HCI_ROLE_MASTER); 1684 + acl = hci_conn_add_unset(hdev, ACL_LINK, dst, 0, 1685 + HCI_ROLE_MASTER); 1696 1686 if (IS_ERR(acl)) 1697 1687 return acl; 1698 1688 } ··· 1762 1750 1763 1751 sco = hci_conn_hash_lookup_ba(hdev, type, dst); 1764 1752 if (!sco) { 1765 - sco = hci_conn_add_unset(hdev, type, dst, HCI_ROLE_MASTER); 1753 + sco = hci_conn_add_unset(hdev, type, dst, 0, HCI_ROLE_MASTER); 1766 1754 if (IS_ERR(sco)) { 1767 1755 hci_conn_drop(acl); 1768 1756 return sco; ··· 1954 1942 cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cig, 1955 1943 qos->ucast.cis); 1956 1944 if (!cis) { 1957 - cis = hci_conn_add_unset(hdev, CIS_LINK, dst, 1945 + cis = hci_conn_add_unset(hdev, CIS_LINK, dst, dst_type, 1958 1946 HCI_ROLE_MASTER); 1959 1947 if (IS_ERR(cis)) 1960 1948 return cis; ··· 2145 2133 2146 2134 bt_dev_dbg(hdev, "dst %pMR type %d sid %d", dst, dst_type, sid); 2147 2135 2148 - conn = hci_conn_add_unset(hdev, PA_LINK, dst, HCI_ROLE_SLAVE); 2136 + conn = hci_conn_add_unset(hdev, PA_LINK, dst, dst_type, HCI_ROLE_SLAVE); 2149 2137 if (IS_ERR(conn)) 2150 2138 return conn; 2151 2139 2152 2140 conn->iso_qos = *qos; 2153 - conn->dst_type = dst_type; 2154 2141 conn->sid = sid; 2155 2142 conn->state = BT_LISTEN; 2156 2143 conn->conn_timeout = msecs_to_jiffies(qos->bcast.sync_timeout * 10);
+10 -10
net/bluetooth/hci_event.c
··· 2267 2267 } else { 2268 2268 if (!conn) { 2269 2269 conn = hci_conn_add_unset(hdev, ACL_LINK, &cp->bdaddr, 2270 - HCI_ROLE_MASTER); 2270 + 0, HCI_ROLE_MASTER); 2271 2271 if (IS_ERR(conn)) 2272 2272 bt_dev_err(hdev, "connection err: %ld", PTR_ERR(conn)); 2273 2273 } ··· 3123 3123 &ev->bdaddr, 3124 3124 BDADDR_BREDR)) { 3125 3125 conn = hci_conn_add_unset(hdev, ev->link_type, 3126 - &ev->bdaddr, HCI_ROLE_SLAVE); 3126 + &ev->bdaddr, 0, 3127 + HCI_ROLE_SLAVE); 3127 3128 if (IS_ERR(conn)) { 3128 3129 bt_dev_err(hdev, "connection err: %ld", PTR_ERR(conn)); 3129 3130 goto unlock; ··· 3300 3299 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, 3301 3300 &ev->bdaddr); 3302 3301 if (!conn) { 3303 - conn = hci_conn_add_unset(hdev, ev->link_type, &ev->bdaddr, 3302 + conn = hci_conn_add_unset(hdev, ev->link_type, &ev->bdaddr, 0, 3304 3303 HCI_ROLE_SLAVE); 3305 3304 if (IS_ERR(conn)) { 3306 3305 bt_dev_err(hdev, "connection err: %ld", PTR_ERR(conn)); ··· 5671 5670 if (status) 5672 5671 goto unlock; 5673 5672 5674 - conn = hci_conn_add_unset(hdev, LE_LINK, bdaddr, role); 5673 + conn = hci_conn_add_unset(hdev, LE_LINK, bdaddr, bdaddr_type, 5674 + role); 5675 5675 if (IS_ERR(conn)) { 5676 5676 bt_dev_err(hdev, "connection err: %ld", PTR_ERR(conn)); 5677 5677 goto unlock; 5678 5678 } 5679 - 5680 - conn->dst_type = bdaddr_type; 5681 5679 5682 5680 /* If we didn't have a hci_conn object previously 5683 5681 * but we're in central role this must be something ··· 5982 5982 goto unlock; 5983 5983 5984 5984 /* Add connection to indicate PA sync event */ 5985 - pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY, 5985 + pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY, 0, 5986 5986 HCI_ROLE_SLAVE); 5987 5987 5988 5988 if (IS_ERR(pa_sync)) ··· 6515 6515 goto unlock; 6516 6516 6517 6517 /* Add connection to indicate PA sync event */ 6518 - pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY, 6518 + pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY, 0, 6519 6519 HCI_ROLE_SLAVE); 6520 6520 6521 6521 if (IS_ERR(pa_sync)) ··· 6956 6956 6957 6957 cis = hci_conn_hash_lookup_handle(hdev, cis_handle); 6958 6958 if (!cis) { 6959 - cis = hci_conn_add(hdev, CIS_LINK, &acl->dst, 6959 + cis = hci_conn_add(hdev, CIS_LINK, &acl->dst, acl->dst_type, 6960 6960 HCI_ROLE_SLAVE, cis_handle); 6961 6961 if (IS_ERR(cis)) { 6962 6962 hci_le_reject_cis(hdev, ev->cis_handle); ··· 7073 7073 bt_dev_dbg(hdev, "ignore too large handle %u", handle); 7074 7074 continue; 7075 7075 } 7076 - bis = hci_conn_add(hdev, BIS_LINK, BDADDR_ANY, 7076 + bis = hci_conn_add(hdev, BIS_LINK, BDADDR_ANY, 0, 7077 7077 HCI_ROLE_SLAVE, handle); 7078 7078 if (IS_ERR(bis)) 7079 7079 continue;
+1 -1
net/bluetooth/hci_sync.c
··· 7013 7013 goto unlock; 7014 7014 7015 7015 /* Add connection to indicate PA sync error */ 7016 - pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY, 7016 + pa_sync = hci_conn_add_unset(hdev, PA_LINK, BDADDR_ANY, 0, 7017 7017 HCI_ROLE_SLAVE); 7018 7018 7019 7019 if (IS_ERR(pa_sync))