diff mbox

[1/7] dbus: Provide the interface address of the peer

Message ID 1400586674-18542-2-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 info will be useful once paired with the peer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
---
 wpa_supplicant/dbus/dbus_new.c              |  4 ++++
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 23 +++++++++++++++++++++++
 wpa_supplicant/dbus/dbus_new_handlers_p2p.h |  4 ++++
 3 files changed, 31 insertions(+)

Comments

Jouni Malinen May 21, 2014, 8:58 p.m. UTC | #1
On Tue, May 20, 2014 at 02:51:08PM +0300, Tomasz Bursztyka wrote:
> This info will be useful once paired with the peer.

Could you please describe what you would be using this information for?
There is a reason for keeping this information "hidden" outside struct
p2p_peer_info since it can be surprising how this field behaves
especially if the peer happens to be using multiple interface addresses.
In other words, this may be the interface address used in a completely
separate P2P group which has nothing to do with the local device. In
addition, the address information may change frequently if the peer is
in two P2P groups, so you don't know what exactly you'll get back here.

> +	info = p2p_get_peer_info(peer_args->wpa_s->global->p2p,
> +				 peer_args->p2p_device_addr, 0);

> +	p2p_get_interface_addr(peer_args->wpa_s->global->p2p,
> +			       info->p2p_device_addr, iface_addr);

If you want to get the interface address of the peer in a specific group
(e.g., the one in which the local device is also a member), this is not
the way to get that information. To be more complete, there is no such
information stored reliably within wpa_supplicant currently, i.e., to be
able to expose this information, you would first need to extend the P2P
module to support storage of per-group information for each peer device.
The peer may be in multiple groups concurrently and as such, can have
multiple P2P Interface Addresses. In general, you cannot find the
correct one by using P2P Device Address as the key.
Tomasz Bursztyka May 26, 2014, 8:14 a.m. UTC | #2
Hi Jouni,

> Could you please describe what you would be using this information for?
> There is a reason for keeping this information "hidden" outside struct
> p2p_peer_info since it can be surprising how this field behaves
> especially if the peer happens to be using multiple interface addresses.
> In other words, this may be the interface address used in a completely
> separate P2P group which has nothing to do with the local device.

While removing GroupMember, I thought some could still need the 
interface address
group members are built with.

But indeed let's forget that then.

Tomasz
diff mbox

Patch

diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 6bd2a40..881082a 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -3271,6 +3271,10 @@  static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
 	  wpas_dbus_getter_p2p_peer_device_address,
 	  NULL
 	},
+	{ "InterfaceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
+	  wpas_dbus_getter_p2p_peer_interface_address,
+	  NULL
+	},
 	{ NULL, NULL, NULL, NULL, NULL }
 };
 
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index 20cbeed..f76e2b6 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -1520,6 +1520,29 @@  dbus_bool_t wpas_dbus_getter_p2p_peer_device_address(DBusMessageIter *iter,
 		ETH_ALEN, error);
 }
 
+dbus_bool_t wpas_dbus_getter_p2p_peer_interface_address(DBusMessageIter *iter,
+							DBusError *error,
+							void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info;
+	u8 iface_addr[ETH_ALEN] = {};
+
+	info = p2p_get_peer_info(peer_args->wpa_s->global->p2p,
+				 peer_args->p2p_device_addr, 0);
+	if (info == NULL) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+			       "failed to find peer");
+		return FALSE;
+	}
+
+	p2p_get_interface_addr(peer_args->wpa_s->global->p2p,
+			       info->p2p_device_addr, iface_addr);
+
+	return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
+						      (char *) iface_addr,
+						      ETH_ALEN, error);
+}
 
 /**
  * wpas_dbus_getter_persistent_groups - Get array of persistent group objects
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
index 67e0e9d..3f1b577 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
@@ -151,6 +151,10 @@  dbus_bool_t wpas_dbus_getter_p2p_peer_device_address(DBusMessageIter *iter,
 						     DBusError *error,
 						     void *user_data);
 
+dbus_bool_t wpas_dbus_getter_p2p_peer_interface_address(DBusMessageIter *iter,
+							DBusError *error,
+							void *user_data);
+
 /*
  * P2P Group properties
  */