[PATCH] P2P: add new_device flag to dev_found callback

Johannes Berg johannes
Fri Dec 17 06:31:02 PST 2010


From: Johannes Berg <johannes.berg at intel.com>

The DBus code will want to have perfect matching
of dev_found and the dev_lost it adds so it doesn't
need to keep track internally. Enable that with a
new flag in the core that tracks whether we have
already notified about this -- the existing users
can ignore it.

Signed-off-by: Johannes Berg <johannes.berg at intel.com>
---
 src/p2p/p2p.c                   |   13 +++++++++----
 src/p2p/p2p.h                   |    4 +++-
 src/p2p/p2p_i.h                 |    1 +
 wpa_supplicant/p2p_supplicant.c |    3 ++-
 wpa_supplicant/p2p_supplicant.h |    3 ++-
 5 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index b630164..0d329d4 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -390,7 +390,8 @@ static int p2p_add_group_clients(struct p2p_data *p2p, const u8 *go_dev_addr,
 			dev->oper_freq = freq;
 			p2p->cfg->dev_found(p2p->cfg->cb_ctx,
 					    dev->info.p2p_device_addr,
-					    &dev->info);
+					    &dev->info, 1);
+			dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE;
 		}
 
 		os_memcpy(dev->interface_addr, cli->p2p_interface_addr,
@@ -539,8 +540,10 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level,
 			"P2P: Do not report rejected device");
 		return 0;
 	}
-	p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info);
-	dev->flags |= P2P_DEV_REPORTED;
+
+	p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info,
+			    !(dev->flags & P2P_DEV_REPORTED_ONCE));
+	dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE;
 
 	return 0;
 }
@@ -1117,7 +1120,9 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
 		return;
 	}
 
-	p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info);
+	p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info,
+			    !(dev->flags & P2P_DEV_REPORTED_ONCE));
+	dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE;
 }
 
 
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index fb4b5b2..35e3a4b 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -403,6 +403,7 @@ struct p2p_config {
 	 * @ctx: Callback context from cb_ctx
 	 * @addr: Source address of the message triggering this notification
 	 * @info: P2P Peer information
+	 * @new_device: inform if the peer is newly found.
 	 *
 	 * This callback is used to notify that a new P2P Device has been
 	 * found. This may happen, e.g., during Search state based on scan
@@ -410,7 +411,8 @@ struct p2p_config {
 	 * Group Owner Negotiation Request.
 	 */
 	void (*dev_found)(void *ctx, const u8 *addr,
-			  const struct p2p_peer_info *info);
+			  const struct p2p_peer_info *info,
+			  int new_device);
 
 	/**
 	 * go_neg_req_rx - Notification of a receive GO Negotiation Request
diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h
index 35944a5..e460cc2 100644
--- a/src/p2p/p2p_i.h
+++ b/src/p2p/p2p_i.h
@@ -89,6 +89,7 @@ struct p2p_device {
 #define P2P_DEV_GROUP_CLIENT_ONLY BIT(12)
 #define P2P_DEV_FORCE_FREQ BIT(13)
 #define P2P_DEV_PD_FOR_JOIN BIT(14)
+#define P2P_DEV_REPORTED_ONCE BIT(15)
 	unsigned int flags;
 
 	int status; /* enum p2p_status_code */
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index da5e02b..af3113e 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -1104,7 +1104,8 @@ void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
 
 
 void wpas_dev_found(void *ctx, const u8 *addr,
-		    const struct p2p_peer_info *info)
+		    const struct p2p_peer_info *info,
+		    int new_device)
 {
 	struct wpa_supplicant *wpa_s = ctx;
 	char devtype[WPS_DEV_TYPE_BUFSIZE];
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index da0287e..8b03ce9 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -64,7 +64,8 @@ void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies);
 void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s);
 void wpas_dev_found(void *ctx, const u8 *addr,
-		    const struct p2p_peer_info *info);
+		    const struct p2p_peer_info *info,
+		    int new_device);
 void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res);
 void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id);
 void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
-- 
1.7.2.3






More information about the Hostap mailing list