Merge "Add to bss command option RANGE=ALL|N1-N2 [MASK=0xH]"
diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index d5884f2..a4c6a8f 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -2094,6 +2094,7 @@
 {
 	struct wpabuf *p2p_ie;
 	struct p2p_message msg;
+	int ret = -1;
 
 	p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
 					     P2P_IE_VENDOR_TYPE);
@@ -2105,14 +2106,16 @@
 		return -1;
 	}
 
-	if (msg.p2p_device_addr == NULL) {
-		wpabuf_free(p2p_ie);
-		return -1;
+	if (msg.p2p_device_addr) {
+		os_memcpy(dev_addr, msg.p2p_device_addr, ETH_ALEN);
+		ret = 0;
+	} else if (msg.device_id) {
+		os_memcpy(dev_addr, msg.device_id, ETH_ALEN);
+		ret = 0;
 	}
 
-	os_memcpy(dev_addr, msg.p2p_device_addr, ETH_ALEN);
 	wpabuf_free(p2p_ie);
-	return 0;
+	return ret;
 }
 
 
diff --git a/src/p2p/p2p_sd.c b/src/p2p/p2p_sd.c
index 9e3588a..4e5a2e5 100644
--- a/src/p2p/p2p_sd.c
+++ b/src/p2p/p2p_sd.c
@@ -841,6 +841,7 @@
 		      const struct wpabuf *tlvs)
 {
 	struct p2p_sd_query *q;
+	struct p2p_device *dev;
 
 	q = os_zalloc(sizeof(*q));
 	if (q == NULL)
@@ -859,6 +860,14 @@
 
 	q->next = p2p->sd_queries;
 	p2p->sd_queries = q;
+
+	dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) {
+		if (dst == NULL ||
+			os_memcmp(dev->info.p2p_device_addr, dst, ETH_ALEN) == 0) {
+			dev->flags &= ~P2P_DEV_SD_INFO;
+		}
+	}
+
 	wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Added SD Query %p", q);
 
 	return q;