Patchwork p2p: consider age for the p2p scan results

login
register
mail settings
Submitter Arik Nemtsov
Date Dec. 9, 2012, 10:08 a.m.
Message ID <1355047727-21379-1-git-send-email-arik@wizery.com>
Download mbox | patch
Permalink /patch/204693/
State Accepted
Commit 3dfd0484fc672860c824c5dcc6678153870d7664
Headers show

Comments

Arik Nemtsov - Dec. 9, 2012, 10:08 a.m.
From: Yoni Divinsky <yoni.divinsky@ti.com>

Cfg80211 caches the scan results according the
channel number. Due to the 15 sec aging this
might cause the user mode to see more than one
scan result with the same BSSID, e.g. - one
scan result for the p2p-device and one for the
p2p-GO (once it's enabled).

Fix this by updating the device entry only if
the new peer entry is newer than the one
previously stored.

Signed-off-by: Yoni Divinsky <yoni.divinsky@ti.com>
Signed-off-by: Victor Goldenshtein <victorg@ti.com>
Signed-off-by: Igal Chernobelsky <igalc@ti.com>
Signed-hostap: Arik Nemtsov <arik@wizery.com>
---
 src/drivers/driver_test.c       |    3 ++-
 src/p2p/p2p.c                   |   29 ++++++++++++++++++++++++-----
 src/p2p/p2p.h                   |    3 ++-
 src/p2p/p2p_i.h                 |    5 +++--
 src/p2p/p2p_invitation.c        |    3 ++-
 src/p2p/p2p_pd.c                |    4 +++-
 wpa_supplicant/p2p_supplicant.c |    2 +-
 7 files changed, 37 insertions(+), 12 deletions(-)
Jouni Malinen - Dec. 25, 2012, 9:24 a.m.
On Sun, Dec 09, 2012 at 12:08:47PM +0200, Arik Nemtsov wrote:
> Cfg80211 caches the scan results according the
> channel number. Due to the 15 sec aging this
> might cause the user mode to see more than one
> scan result with the same BSSID, e.g. - one
> scan result for the p2p-device and one for the
> p2p-GO (once it's enabled).
> 
> Fix this by updating the device entry only if
> the new peer entry is newer than the one
> previously stored.

Thanks, applied.

Patch

diff --git a/src/drivers/driver_test.c b/src/drivers/driver_test.c
index 89aee7d..bd65dd8 100644
--- a/src/drivers/driver_test.c
+++ b/src/drivers/driver_test.c
@@ -1321,7 +1321,8 @@  static void wpa_driver_test_scan_timeout(void *eloop_ctx, void *timeout_ctx)
 		for (i = 0; i < drv->num_scanres; i++) {
 			struct wpa_scan_res *bss = drv->scanres[i];
 			if (p2p_scan_res_handler(drv->p2p, bss->bssid,
-						 bss->freq, bss->level,
+						 bss->freq, bss->age,
+						 bss->level,
 						 (const u8 *) (bss + 1),
 						 bss->ie_len) > 0)
 				return;
diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 22760d9..3d05161 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -593,13 +593,15 @@  static void p2p_copy_wps_info(struct p2p_device *dev, int probe_req,
  * like Provision Discovery Request that contains P2P Capability and P2P Device
  * Info attributes.
  */
-int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level,
-		   const u8 *ies, size_t ies_len, int scan_res)
+int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
+		   unsigned int age_ms, int level, const u8 *ies,
+		   size_t ies_len, int scan_res)
 {
 	struct p2p_device *dev;
 	struct p2p_message msg;
 	const u8 *p2p_dev_addr;
 	int i;
+	struct os_time time_now, time_tmp_age, entry_ts;
 
 	os_memset(&msg, 0, sizeof(msg));
 	if (p2p_parse_ies(ies, ies_len, &msg)) {
@@ -634,7 +636,23 @@  int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level,
 		p2p_parse_free(&msg);
 		return -1;
 	}
-	os_get_time(&dev->last_seen);
+
+	os_get_time(&time_now);
+	time_tmp_age.sec = age_ms / 1000;
+	time_tmp_age.usec = (age_ms % 1000) * 1000;
+	os_time_sub(&time_now, &time_tmp_age, &entry_ts);
+
+	/*
+	 * Update the device entry only if the new peer
+	 * entry is newer than the one previously stored.
+	 */
+
+	if (dev->last_seen.usec > 0 &&
+	    os_time_before(&entry_ts, &dev->last_seen))
+		return -1;
+
+	os_memcpy(&dev->last_seen, &entry_ts, sizeof(struct os_time));
+
 	dev->flags &= ~(P2P_DEV_PROBE_REQ_ONLY | P2P_DEV_GROUP_CLIENT_ONLY);
 
 	if (os_memcmp(addr, p2p_dev_addr, ETH_ALEN) != 0)
@@ -2723,9 +2741,10 @@  static void p2p_prov_disc_cb(struct p2p_data *p2p, int success)
 
 
 int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
-			 int level, const u8 *ies, size_t ies_len)
+			 unsigned int age, int level, const u8 *ies,
+			 size_t ies_len)
 {
-	p2p_add_device(p2p, bssid, freq, level, ies, ies_len, 1);
+	p2p_add_device(p2p, bssid, freq, age, level, ies, ies_len, 1);
 
 	return 0;
 }
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index 8b2aab2..35384dc 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1204,7 +1204,8 @@  void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
  * start of a pending operation, e.g., to start a pending GO negotiation.
  */
 int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
-			 int level, const u8 *ies, size_t ies_len);
+			 unsigned int age, int level, const u8 *ies,
+			 size_t ies_len);
 
 /**
  * p2p_scan_res_handled - Indicate end of scan results
diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h
index c38eb3b..27fef01 100644
--- a/src/p2p/p2p_i.h
+++ b/src/p2p/p2p_i.h
@@ -692,8 +692,9 @@  struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p,
 						struct p2p_message *msg);
 void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
 		      struct p2p_device *dev, struct p2p_message *msg);
-int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level,
-		   const u8 *ies, size_t ies_len, int scan_res);
+int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
+		   unsigned int age_ms, int level, const u8 *ies,
+		   size_t ies_len, int scan_res);
 struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr);
 struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p,
 					     const u8 *addr);
diff --git a/src/p2p/p2p_invitation.c b/src/p2p/p2p_invitation.c
index e06ba12..8896c08 100644
--- a/src/p2p/p2p_invitation.c
+++ b/src/p2p/p2p_invitation.c
@@ -176,7 +176,8 @@  void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
 			"P2P: Invitation Request from unknown peer "
 			MACSTR, MAC2STR(sa));
 
-		if (p2p_add_device(p2p, sa, rx_freq, 0, data + 1, len - 1, 0))
+		if (p2p_add_device(p2p, sa, rx_freq, 0, 0,
+				   data + 1, len - 1, 0))
 		{
 			wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
 				"P2P: Invitation Request add device failed "
diff --git a/src/p2p/p2p_pd.c b/src/p2p/p2p_pd.c
index e40f2b7..5740668 100644
--- a/src/p2p/p2p_pd.c
+++ b/src/p2p/p2p_pd.c
@@ -151,7 +151,9 @@  void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
 		wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
 			"P2P: Provision Discovery Request from "
 			"unknown peer " MACSTR, MAC2STR(sa));
-		if (p2p_add_device(p2p, sa, rx_freq, 0, data + 1, len - 1, 0))
+
+		if (p2p_add_device(p2p, sa, rx_freq, 0, 0,
+				   data + 1, len - 1, 0))
 		{
 			wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
 			        "P2P: Provision Discovery Request add device "
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index e44bb3a..4e34e01 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -105,7 +105,7 @@  static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s,
 	for (i = 0; i < scan_res->num; i++) {
 		struct wpa_scan_res *bss = scan_res->res[i];
 		if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid,
-					 bss->freq, bss->level,
+					 bss->freq, bss->age, bss->level,
 					 (const u8 *) (bss + 1),
 					 bss->ie_len) > 0)
 			break;