Skip to contentSkip to conversation

Bluetooth: Check for matching IRK when looking for paired LE devices

PATCH Superseded Johan Hedberg 2 participants 4 messages Mar 11, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: Check for matching IRK when looking for paired LE devices

From: Johan Hedberg <[email protected]>

If we're given an RPA when checking whether we're paired or not, we should consult the local RPA storage whether there's a matching IRK. This we we ensure that hci_bdaddr_is_paired() gives the right result even when trying to pair a second time with the same device with an RPA.

---
 net/bluetooth/hci_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/hci_core.c +7 -0
index 4eba9d6fc9a5..84df8f358415 100644
@@ -2519,6 +2519,7 @@ void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type)
 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 {
 	struct smp_ltk *k;
+	struct smp_irk *irk;
 	u8 addr_type;
 
 	if (type == BDADDR_BREDR) {
@@ -2533,6 +2534,12 @@ bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 	else
 		addr_type = ADDR_LE_DEV_RANDOM;
 
+	irk = hci_get_irk(hdev, bdaddr, addr_type);
+	if (irk) {
+		bacpy(bdaddr, &irk->bdaddr);
+		addr_type = irk->addr_type;
+	}
+
 	rcu_read_lock();
 	list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
 		if (k->bdaddr_type == addr_type && !bacmp(bdaddr, &k->bdaddr)) {
Signature · 1 line
2.1.0
#1 lore raw

Hi,

Quoted 23 lines · Johan Hedberg

If we're given an RPA when checking whether we're paired or not, we should consult the local RPA storage whether there's a matching IRK. This we we ensure that hci_bdaddr_is_paired() gives the right result even when trying to pair a second time with the same device with an RPA.

---
 net/bluetooth/hci_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/hci_core.c +1 -0
index 4eba9d6fc9a5..84df8f358415 100644
@@ -2519,6 +2519,7 @@ void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type)
 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 {
 	struct smp_ltk *k;
+	struct smp_irk *irk;
 	u8 addr_type;
 
 	if (type == BDADDR_BREDR) {

net/bluetooth/hci_core.c bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) · line 2541

Quoted 8 lines
net/bluetooth/hci_core.c +5 -0
@@ -2533,6 +2534,12 @@ bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 	else
 		addr_type = ADDR_LE_DEV_RANDOM;
 
+	irk = hci_get_irk(hdev, bdaddr, addr_type);
+	if (irk) {
+		bacpy(bdaddr, &irk->bdaddr);
+		addr_type = irk->addr_type;
+	}

Actually please ignore this one. We shouldn't be overwriting the data that bdaddr points to as that may create unexpected behavior in the caller.

Johan

#2 lore raw

PATCH v2 1/1 Bluetooth: Check for matching IRK when looking for paired LE devices

In reply to Johan Hedberg

From: Johan Hedberg <[email protected]>

If we're given an RPA when checking whether we're paired or not, we should consult the local RPA storage whether there's a matching IRK. This we we ensure that hci_bdaddr_is_paired() gives the right result even when trying to pair a second time with the same device with an RPA.

---
v2: Avoid overwriting callers bdaddr

 net/bluetooth/hci_core.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/hci_core.c +7 -0
index 4eba9d6fc9a5..e3bbdd537b90 100644
@@ -2519,6 +2519,7 @@ void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type)
 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 {
 	struct smp_ltk *k;
+	struct smp_irk *irk;
 	u8 addr_type;
 
 	if (type == BDADDR_BREDR) {
@@ -2533,6 +2534,12 @@ bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
 	else
 		addr_type = ADDR_LE_DEV_RANDOM;
 
+	irk = hci_get_irk(hdev, bdaddr, addr_type);
+	if (irk) {
+		bdaddr = &irk->bdaddr;
+		addr_type = irk->addr_type;
+	}
+
 	rcu_read_lock();
 	list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
 		if (k->bdaddr_type == addr_type && !bacmp(bdaddr, &k->bdaddr)) {
Signature · 1 line
2.1.0
maintainer
#3 lore raw

Hi Johan,

Quoted 11 lines

If we're given an RPA when checking whether we're paired or not, we should consult the local RPA storage whether there's a matching IRK. This we we ensure that hci_bdaddr_is_paired() gives the right result even when trying to pair a second time with the same device with an RPA.

---
v2: Avoid overwriting callers bdaddr

net/bluetooth/hci_core.c | 7 +++++++

1 file changed, 7 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel