[PATCH 2/3] dbus: revert changes to some peer properties

Reinette Chatre reinette.chatre
Wed Feb 22 12:59:06 PST 2012


Commit 3f6e50ac282bbcb4be137023316543bd232ba350 made it possible to access
P2P peer properties using the org.freedesktop.DBus.Properties interface.

While maintaining the original intent of that patch we make two changes
to it here:

First,
3f6e50ac282bbcb4be137023316543bd232ba350 changed the type used to represent the WPS vendor
extension data from bytes to a string. In addition to the type change the way
in which the vendor extension data was provided to the function creating
the string was incorrect and would not present the correct vendor extension
data even in string format.

Revert the type change made in 3f6e50ac282bbcb4be137023316543bd232ba350 and
present the WPS vendor extension data as an array of an array of bytes as
it was before.

Second,
3f6e50ac282bbcb4be137023316543bd232ba350 changes the secondary device types
representation from an array of an array of bytes to an array of bytes.
Revert that change to make secondary device types accessible via an array
of an array of bytes again.

Signed-hostap: Reinette Chatre <reinette.chatre at intel.com>
intended-for: hostap-1
---
 wpa_supplicant/dbus/dbus_new.c              |    4 +-
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c |   96 ++++++++++++++++++++-------
 2 files changed, 75 insertions(+), 25 deletions(-)

diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index ce7cffb..a240649 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -2921,11 +2921,11 @@ static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
 	  wpas_dbus_getter_p2p_peer_group_capability,
 	  NULL
 	},
-	{ "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
+	{ "SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
 	  wpas_dbus_getter_p2p_peer_secondary_device_types,
 	  NULL
 	},
-	{ "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "as",
+	{ "VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "aay",
 	  wpas_dbus_getter_p2p_peer_vendor_extension,
 	  NULL
 	},
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index 79373b4..62489f4 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -1341,6 +1341,7 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
 {
 	struct peer_handler_args *peer_args = user_data;
 	const struct p2p_peer_info *info;
+	DBusMessageIter variant_iter, array_iter;
 
 	info = p2p_get_peer_found(peer_args->wpa_s->global->p2p,
 				  peer_args->p2p_device_addr, 0);
@@ -1350,29 +1351,78 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
 		return FALSE;
 	}
 
+	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+					      DBUS_TYPE_ARRAY_AS_STRING
+					      DBUS_TYPE_ARRAY_AS_STRING
+					      DBUS_TYPE_BYTE_AS_STRING,
+					      &variant_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+		               "%s: failed to construct message 1", __func__);
+		return FALSE;
+	}
+
+	if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
+					      DBUS_TYPE_ARRAY_AS_STRING
+					      DBUS_TYPE_BYTE_AS_STRING,
+					      &array_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+		               "%s: failed to construct message 2", __func__);
+		return FALSE;
+	}
+
 	if (info->wps_sec_dev_type_list_len) {
 		const u8 *sec_dev_type_list = info->wps_sec_dev_type_list;
-		int num_sec_dev_types = info->wps_sec_dev_type_list_len;
+		int num_sec_device_types =
+			info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN;
+		int i;
+		DBusMessageIter inner_array_iter;
+
+		for (i = 0; i < num_sec_device_types; i++) {
+			if (!dbus_message_iter_open_container(&array_iter,
+							      DBUS_TYPE_ARRAY,
+							      DBUS_TYPE_BYTE_AS_STRING,
+							      &inner_array_iter)) {
+				dbus_set_error(error, DBUS_ERROR_FAILED,
+					"%s: failed to construct message 3 (%d)",
+					__func__, i);
+				return FALSE;
+			}
 
-		if (!wpas_dbus_simple_array_property_getter(iter,
-							    DBUS_TYPE_BYTE,
-							    sec_dev_type_list,
-							    num_sec_dev_types,
-							    error))
-			goto err_no_mem;
-		else
-			return TRUE;
+			if (!dbus_message_iter_append_fixed_array(&inner_array_iter,
+								  DBUS_TYPE_BYTE,
+								  &sec_dev_type_list,
+								  WPS_DEV_TYPE_LEN)) {
+				dbus_set_error(error, DBUS_ERROR_FAILED,
+						"%s: failed to construct message 4 (%d)",
+						__func__, i);
+				return FALSE;
+			}
+
+			if (!dbus_message_iter_close_container(&array_iter,
+							       &inner_array_iter)) {
+				dbus_set_error(error, DBUS_ERROR_FAILED,
+					"%s: failed to construct message 5 (%d)",
+					__func__, i);
+				return FALSE;
+			}
+
+			sec_dev_type_list += WPS_DEV_TYPE_LEN;
+		}
 	}
 
-	if (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE, NULL,
-						    0, error))
-		goto err_no_mem;
+	if (!dbus_message_iter_close_container(&variant_iter, &array_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+		               "%s: failed to construct message 6", __func__);
+		return FALSE;
+	}
 
-	return TRUE;
+	if (!dbus_message_iter_close_container(iter, &variant_iter)) {
+		dbus_set_error(error, DBUS_ERROR_FAILED,
+		               "%s: failed to construct message 7", __func__);
+		return FALSE;
+	}
 
-err_no_mem:
-	dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
-	return FALSE;
+	return TRUE;
 }
 
 
@@ -1380,7 +1430,7 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_vendor_extension(DBusMessageIter *iter,
 						       DBusError *error,
 						       void *user_data)
 {
-	const struct wpabuf *vendor_extension[P2P_MAX_WPS_VENDOR_EXT];
+	struct wpabuf *vendor_extension[P2P_MAX_WPS_VENDOR_EXT];
 	int i, num;
 	struct peer_handler_args *peer_args = user_data;
 	const struct p2p_peer_info *info;
@@ -1401,12 +1451,12 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_vendor_extension(DBusMessageIter *iter,
 		num++;
 	}
 
-	if (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_STRING,
-						    vendor_extension, num,
-						    error)) {
-		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
-		return FALSE;
-	}
+	if (!wpas_dbus_simple_array_array_property_getter(iter,
+							  DBUS_TYPE_BYTE,
+							  vendor_extension,
+							  num,
+							  error))
+			return FALSE;
 
 	return TRUE;
 }
-- 
1.7.7.6




More information about the Hostap mailing list