Diff between d45529c987e89b2277608e3024a096d74bdbef6a and c23be68fa2be48daa35b2f5c196edbc17b6b064b

Changed Files

File Additions Deletions Status
emulator/btdev.c +26 -0 modified

Full Patch

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 7b33db7..9e7c4fe 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1373,6 +1373,14 @@ static void ssp_complete(struct btdev *btdev, const uint8_t *bdaddr,
 	send_event(init, BT_HCI_EVT_AUTH_COMPLETE, &auth, sizeof(auth));
 }
 
+static const uint8_t *scan_addr(const struct btdev *btdev)
+{
+	if (btdev->le_scan_own_addr_type == 0x01)
+		return btdev->random_addr;
+
+	return btdev->bdaddr;
+}
+
 static const uint8_t *adv_addr(const struct btdev *btdev)
 {
 	if (btdev->le_adv_own_addr == 0x01)
@@ -1428,6 +1436,18 @@ static uint8_t get_adv_report_type(uint8_t adv_type)
 	return adv_type;
 }
 
+static bool adv_match(struct btdev *scan, struct btdev *adv)
+{
+	/* Match everything if this is not directed advertising */
+	if (adv->le_adv_type != 0x01 && adv->le_adv_type != 0x04)
+		return true;
+
+	if (scan->le_scan_own_addr_type != adv->le_adv_direct_addr_type)
+		return false;
+
+	return !memcmp(scan_addr(scan), adv->le_adv_direct_addr, 6);
+}
+
 static void le_set_adv_enable_complete(struct btdev *btdev)
 {
 	uint8_t report_type;
@@ -1442,6 +1462,9 @@ static void le_set_adv_enable_complete(struct btdev *btdev)
 		if (!btdev_list[i]->le_scan_enable)
 			continue;
 
+		if (!adv_match(btdev_list[i], btdev))
+			continue;
+
 		le_send_adv_report(btdev_list[i], btdev, report_type);
 
 		if (btdev_list[i]->le_scan_type != 0x01)
@@ -1466,6 +1489,9 @@ static void le_set_scan_enable_complete(struct btdev *btdev)
 		if (!btdev_list[i]->le_adv_enable)
 			continue;
 
+		if (!adv_match(btdev, btdev_list[i]))
+			continue;
+
 		report_type = get_adv_report_type(btdev_list[i]->le_adv_type);
 		le_send_adv_report(btdev, btdev_list[i], report_type);