[PATCH] Dbus: Add IntendedAddress in peer properties

MAYANK HAARIT mayank.h at samsung.com
Fri Aug 21 05:59:52 EDT 2015


Allow Applications using dbus to fetch intended address in peer properties same as control interface

Signed-off-by: Mayank Haarit <mayank.h at samsung.com>
Signed-off-by: Purushottam Kushwaha <p.kushwaha at samsung.com>
---
 doc/dbus.doxygen                            |  5 +++++
 src/p2p/p2p.c                               | 10 ++++++++++
 src/p2p/p2p.h                               |  2 ++
 wpa_supplicant/dbus/dbus_new.c              |  4 ++++
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 26 ++++++++++++++++++++++++++
 wpa_supplicant/dbus/dbus_new_handlers_p2p.h |  4 ++++
 6 files changed, 51 insertions(+)

diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen
index 3a08ad7..7cdb08c 100644
--- a/doc/dbus.doxygen
+++ b/doc/dbus.doxygen
@@ -1726,6 +1726,11 @@ Interface implemented by objects representing P2P peer devices.
   </li>
 
   <li>
+    <h3>IntendedAddress - ay - (read)</h3>
+    <p>Local Intended P2P Interface Address of the peer.</p>
+  </li>
+
+  <li>
     <h3>Groups - ao - (read)</h3>
     <p>The current groups in which this peer is connected.</p>
   </li>
diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 8cf0b9c..ef9adb5 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -4747,6 +4747,16 @@ int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr,
 }
 
 
+int p2p_get_intended_addr(struct p2p_data *p2p, const u8 *dev_addr,
+			  u8 *intended_addr) {
+	struct p2p_device *dev = p2p_get_device(p2p, dev_addr);
+	if (dev == NULL || is_zero_ether_addr(dev->intended_addr))
+		return -1;
+	os_memcpy(intended_addr, dev->intended_addr, ETH_ALEN);
+	return 0;
+}
+
+
 int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr,
 			   u8 *dev_addr)
 {
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index b4060be..1f8eb99 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1989,6 +1989,8 @@ int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len);
 
 int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr,
 			   u8 *iface_addr);
+int p2p_get_intended_addr(struct p2p_data *p2p, const u8 *dev_addr,
+			  u8 *intended_addr);
 int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr,
 			   u8 *dev_addr);
 
diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 1959ea7..67d0629 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -3435,6 +3435,10 @@ static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
 	  wpas_dbus_getter_p2p_peer_device_address,
 	  NULL
 	},
+	{ "IntendedAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
+	  wpas_dbus_getter_p2p_peer_intended_address,
+	  NULL
+	},
 	{ "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
 	  wpas_dbus_getter_p2p_peer_groups,
 	  NULL
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index e9d60df..a0ef2c2 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -1730,6 +1730,32 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_device_address(DBusMessageIter *iter,
 }
 
 
+dbus_bool_t wpas_dbus_getter_p2p_peer_intended_address(DBusMessageIter *iter,
+						       DBusError *error,
+						       void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info;
+	u8 intended_address[ETH_ALEN];
+
+	info = p2p_get_peer_found(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;
+	}
+	if (p2p_get_intended_addr(peer_args->wpa_s->global->p2p,
+				  peer_args->p2p_device_addr,
+				  intended_address) < 0) {
+		os_memset(intended_address, 0, ETH_ALEN);
+	}
+
+	return wpas_dbus_simple_array_property_getter(
+		iter, DBUS_TYPE_BYTE, (char *) intended_address,
+		ETH_ALEN, error);
+}
+
 struct peer_group_data {
 	struct wpa_supplicant *wpa_s;
 	const struct p2p_peer_info *info;
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
index 2aecbbe..619c36a 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
@@ -168,6 +168,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_intended_address(DBusMessageIter *iter,
+						       DBusError *error,
+						       void *user_data);
+
 dbus_bool_t wpas_dbus_getter_p2p_peer_groups(DBusMessageIter *iter,
 					     DBusError *error,
 					     void *user_data);
-- 
1.9.1



More information about the HostAP mailing list