[PATCH v2 6/7] android/gatt: Use proper address when connecting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If device was using RPA but address was resolved IDA must be used.
---
 android/bluetooth.c | 14 ++++++++++++++
 android/bluetooth.h |  2 ++
 android/gatt.c      | 15 +++++++++++++--
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 61bee90..f8c2688 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1436,6 +1436,20 @@ bool bt_is_device_le(const bdaddr_t *addr)
 	return dev->le;
 }
 
+const bdaddr_t *bt_get_id_addr(const bdaddr_t *addr, uint8_t *type)
+{
+	struct device *dev;
+
+	dev = find_device(addr);
+	if (!dev)
+		return NULL;
+
+	if (type)
+		*type = dev->bdaddr_type;
+
+	return &dev->bdaddr;
+}
+
 const char *bt_get_adapter_name(void)
 {
 	return adapter.name;
diff --git a/android/bluetooth.h b/android/bluetooth.h
index eb50fe1..dde477d 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
@@ -76,3 +76,5 @@ void bt_update_sign_counter(const bdaddr_t *addr, enum bt_csrk_type type);
 void bt_store_gatt_ccc(const bdaddr_t *addr, uint16_t value);
 
 uint16_t bt_get_gatt_ccc(const bdaddr_t *addr);
+
+const bdaddr_t *bt_get_id_addr(const bdaddr_t *addr, uint8_t *type);
diff --git a/android/gatt.c b/android/gatt.c
index 32853fa..af83d96 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1423,6 +1423,8 @@ static int connect_le(struct gatt_device *dev)
 	GIOChannel *io;
 	GError *gerr = NULL;
 	char addr[18];
+	const bdaddr_t *bdaddr;
+	uint8_t bdaddr_type;
 
 	ba2str(&dev->bdaddr, addr);
 
@@ -1437,6 +1439,15 @@ static int connect_le(struct gatt_device *dev)
 	sec_level = bt_device_is_bonded(&dev->bdaddr) ? BT_IO_SEC_MEDIUM :
 								BT_IO_SEC_LOW;
 
+	if (dev->bdaddr_type == BDADDR_LE_RANDOM) {
+		bdaddr = bt_get_id_addr(&dev->bdaddr, &bdaddr_type);
+		if (!bdaddr)
+			return -EINVAL;
+	} else {
+		bdaddr = &dev->bdaddr;
+		bdaddr_type = dev->bdaddr_type;
+	}
+
 	/*
 	 * This connection will help us catch any PDUs that comes before
 	 * pairing finishes
@@ -1445,8 +1456,8 @@ static int connect_le(struct gatt_device *dev)
 			BT_IO_OPT_SOURCE_BDADDR,
 			&adapter_addr,
 			BT_IO_OPT_SOURCE_TYPE, BDADDR_LE_PUBLIC,
-			BT_IO_OPT_DEST_BDADDR, &dev->bdaddr,
-			BT_IO_OPT_DEST_TYPE, dev->bdaddr_type,
+			BT_IO_OPT_DEST_BDADDR, bdaddr,
+			BT_IO_OPT_DEST_TYPE, bdaddr_type,
 			BT_IO_OPT_CID, ATT_CID,
 			BT_IO_OPT_SEC_LEVEL, sec_level,
 			BT_IO_OPT_INVALID);
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux