[PATCH 3/7] p2p_supplicant: Add utility functions to get go interface

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Mon Jun 2 10:42:04 EDT 2014


This will be useful for a peer to know if it is part of a group either
as a client of our local GO or as the distant GO.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka at linux.intel.com>
---
 wpa_supplicant/p2p_supplicant.c | 42 +++++++++++++++++++++++++++++++++++++----
 wpa_supplicant/p2p_supplicant.h |  5 +++++
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 393f13b..8526d48 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -3634,10 +3634,32 @@ static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
 }
 
 
-static int wpas_go_connected(void *ctx, const u8 *dev_addr)
+struct wpa_supplicant *wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s,
+					     const u8 *ssid,
+					     size_t ssid_len)
 {
-	struct wpa_supplicant *wpa_s = ctx;
+	for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+		struct wpa_ssid *s = wpa_s->current_ssid;
+		if (s == NULL)
+			continue;
+		if (s->mode != WPAS_MODE_P2P_GO &&
+		    s->mode != WPAS_MODE_AP &&
+		    s->mode != WPAS_MODE_P2P_GROUP_FORMATION)
+			continue;
+		if (s->ssid_len != ssid_len ||
+		    os_memcmp(s, s->ssid, ssid_len) != 0)
+			continue;
+		return wpa_s;
+	}
+
+	return NULL;
+
+}
+
 
+struct wpa_supplicant *wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s,
+						 const u8 *peer_dev_addr)
+{
 	for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
 		struct wpa_ssid *ssid = wpa_s->current_ssid;
 		if (ssid == NULL)
@@ -3647,10 +3669,22 @@ static int wpas_go_connected(void *ctx, const u8 *dev_addr)
 		if (wpa_s->wpa_state != WPA_COMPLETED &&
 		    wpa_s->wpa_state != WPA_GROUP_HANDSHAKE)
 			continue;
-		if (os_memcmp(wpa_s->go_dev_addr, dev_addr, ETH_ALEN) == 0)
-			return 1;
+		if (os_memcmp(wpa_s->go_dev_addr,
+			      peer_dev_addr, ETH_ALEN) == 0)
+			return wpa_s;
 	}
 
+	return NULL;
+}
+
+
+static int wpas_go_connected(void *ctx, const u8 *dev_addr)
+{
+	struct wpa_supplicant *wpa_s = ctx;
+
+	if (wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL)
+		return 1;
+
 	return 0;
 }
 
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 0bf3ca9..a74bb1b 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -20,6 +20,11 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s);
 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s);
 void wpas_p2p_deinit_global(struct wpa_global *global);
 int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s);
+struct wpa_supplicant *wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s,
+					     const u8 *ssid,
+					     size_t ssid_len);
+struct wpa_supplicant *wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s,
+						 const u8 *peer_dev_addr);
 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
 		     const char *pin, enum p2p_wps_method wps_method,
 		     int persistent_group, int auto_join, int join,
-- 
1.8.5.5



More information about the HostAP mailing list