diff mbox

[3/7] wpas: Add p2p utility function to get go iface from a peer dev address

Message ID 1400586674-18542-4-git-send-email-tomasz.bursztyka@linux.intel.com
State Changes Requested
Headers show

Commit Message

Tomasz Bursztyka May 20, 2014, 11:51 a.m. UTC
This will be useful for a peer to know if it is part of a group, what is
its interface and thus its dbus object path.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
---
 wpa_supplicant/p2p_supplicant.c | 36 ++++++++++++++++++++++++++++++------
 wpa_supplicant/p2p_supplicant.h |  4 ++++
 2 files changed, 34 insertions(+), 6 deletions(-)

Comments

Jouni Malinen May 21, 2014, 9:14 p.m. UTC | #1
On Tue, May 20, 2014 at 02:51:10PM +0300, Tomasz Bursztyka wrote:
> This will be useful for a peer to know if it is part of a group, what is
> its interface and thus its dbus object path.

Hmm.. There is something quite confusing about these patches and how the
use P2P Device vs. Interface Addresses..

> -static int wpas_go_connected(void *ctx, const u8 *dev_addr)
> +struct wpa_supplicant *wpas_get_go_p2p_client(struct wpa_supplicant *wpa_s,
> +					      const u8 *dev_addr)

>  		if (os_memcmp(wpa_s->go_dev_addr, dev_addr, ETH_ALEN) == 0)
> -			return 1;
> +			return wpa_s;

So this dev_addr here is the P2P Device Address of the GO that this
interface is connected to as a P2P Client.

> +struct wpa_supplicant *wpas_get_go_p2p_go(struct wpa_supplicant *wpa_s,
> +					  const u8 *dev_addr)
> +{
> +	const u8 *go_dev_addr;
> +
> +	go_dev_addr = p2p_get_own_go_device_address(wpa_s->global->p2p,
> +						    dev_addr);
> +	if (go_dev_addr == NULL)
> +		return NULL;
> +
> +	for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
> +		if (os_memcmp(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN) == 0)
> +			return wpa_s;
> +	}

wpa_s->go_dev_addr is that P2P Device Address of the GO, but go_dev_addr
from p2p_get_own_go_device_address() was P2P Interface Address.. This
type of matching will fail if the GO uses a design where the P2P Device
Address and P2P Interface Address(es) are different.
Tomasz Bursztyka May 26, 2014, 8:15 a.m. UTC | #2
Hi Jouni,

> Hmm.. There is something quite confusing about these patches and how the
> use P2P Device vs. Interface Addresses..

Now that you put the multigroup on the table, this cannot be used as is 
anymore anyway.

I'll found another way to relate properly a peer and whatever group it 
is related to.

Tomasz
Tomasz Bursztyka May 27, 2014, 10:30 a.m. UTC | #3
Hi Jouni,

>> +struct wpa_supplicant *wpas_get_go_p2p_go(struct wpa_supplicant *wpa_s,
>> >+					  const u8 *dev_addr)
>> >+{
>> >+	const u8 *go_dev_addr;
>> >+
>> >+	go_dev_addr = p2p_get_own_go_device_address(wpa_s->global->p2p,
>> >+						    dev_addr);
>> >+	if (go_dev_addr == NULL)
>> >+		return NULL;
>> >+
>> >+	for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
>> >+		if (os_memcmp(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN) == 0)
>> >+			return wpa_s;
>> >+	}
> wpa_s->go_dev_addr is that P2P Device Address of the GO, but go_dev_addr
> from p2p_get_own_go_device_address() was P2P Interface Address..

Yes, again the bug of patch 2. I have to store the real device address 
in the group structure and
return that one and not its interface address.

Tomasz
diff mbox

Patch

diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index bbe15d8..56cf798 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -3632,11 +3632,9 @@  static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
 	return wpa_drv_get_noa(wpa_s, buf, buf_len);
 }
 
-
-static int wpas_go_connected(void *ctx, const u8 *dev_addr)
+struct wpa_supplicant *wpas_get_go_p2p_client(struct wpa_supplicant *wpa_s,
+					      const u8 *dev_addr)
 {
-	struct wpa_supplicant *wpa_s = ctx;
-
 	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,12 +3645,38 @@  static int wpas_go_connected(void *ctx, const u8 *dev_addr)
 		    wpa_s->wpa_state != WPA_GROUP_HANDSHAKE)
 			continue;
 		if (os_memcmp(wpa_s->go_dev_addr, dev_addr, ETH_ALEN) == 0)
-			return 1;
+			return wpa_s;
 	}
 
-	return 0;
+	return NULL;
+}
+
+struct wpa_supplicant *wpas_get_go_p2p_go(struct wpa_supplicant *wpa_s,
+					  const u8 *dev_addr)
+{
+	const u8 *go_dev_addr;
+
+	go_dev_addr = p2p_get_own_go_device_address(wpa_s->global->p2p,
+						    dev_addr);
+	if (go_dev_addr == NULL)
+		return NULL;
+
+	for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+		if (os_memcmp(wpa_s->go_dev_addr, go_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_go_p2p_client(wpa_s, dev_addr) != NULL)
+		return 1;
+	return 0;
+}
 
 static int wpas_is_concurrent_session_active(void *ctx)
 {
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 0bf3ca9..4044cec 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -142,6 +142,10 @@  int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s,
 			   struct hostapd_hw_modes *mode, u8 channel);
 int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s,
 			      struct hostapd_hw_modes *mode, u8 channel);
+struct wpa_supplicant *wpas_get_go_p2p_client(struct wpa_supplicant *wpa_s,
+					      const u8 *dev_addr);
+struct wpa_supplicant *wpas_get_go_p2p_go(struct wpa_supplicant *wpa_s,
+					  const u8 *dev_addr);
 unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s);
 void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr,
 			 const u8 *p2p_dev_addr,