[PATCH] dbus: Making the peer's properties acessible separately

Flávio Ceolin flavio.ceolin
Fri Feb 3 12:52:18 PST 2012


How there is the method org.freedesktop.DBus.Properties.GetAll
that returns all properties from a specific interface, makes more
sense separate the properties to be possible to get only a specific
property using the method org.freedesktop.DBus.Properties.Get.

Signed-hostap: Flavio Ceolin <flavio.ceolin at profusion.mobi>
---
 wpa_supplicant/dbus/dbus_new.c              |   32 +++-
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c |  269 ++++++++++++++++++++-------
 wpa_supplicant/dbus/dbus_new_handlers_p2p.h |   36 ++++-
 3 files changed, 264 insertions(+), 73 deletions(-)

diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 726b077..bd1c6f6 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -2897,8 +2897,36 @@ int wpas_dbus_unregister_interface(struct
wpa_supplicant *wpa_s)
 #ifdef CONFIG_P2P

 static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
-	{ "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}",
-	  wpas_dbus_getter_p2p_peer_properties,
+	{"DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
+	  wpas_dbus_getter_p2p_peer_device_name,
+	  NULL
+	},
+	{"PrimaryDeviceType", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
+	  wpas_dbus_getter_p2p_peer_primary_device_type,
+	  NULL
+	},
+	{"config_method", WPAS_DBUS_NEW_IFACE_P2P_PEER, "n",
+	  wpas_dbus_getter_p2p_peer_config_method,
+	  NULL
+	},
+	{"level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "au",
+	  wpas_dbus_getter_p2p_peer_level,
+	  NULL
+	},
+	{"devicecapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
+	  wpas_dbus_getter_p2p_peer_device_capability,
+	  NULL
+	},
+	{"groupcapability", WPAS_DBUS_NEW_IFACE_P2P_PEER, "y",
+	  wpas_dbus_getter_p2p_peer_group_capability,
+	  NULL
+	},
+	{"SecondaryDeviceTypes", WPAS_DBUS_NEW_IFACE_P2P_PEER, "au",
+	  wpas_dbus_getter_p2p_peer_secondary_device_types,
+	  NULL
+	},
+	{"VendorExtension", WPAS_DBUS_NEW_IFACE_P2P_PEER, "as",
+	  wpas_dbus_getter_p2p_peer_vendor_extension,
 	  NULL
 	},
 	{ "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index 0f6914c..547acbf 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -1172,14 +1172,13 @@ dbus_bool_t
wpas_dbus_getter_p2p_peergo(DBusMessageIter *iter,
  * Peer object properties accessor methods
  */

-dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
-	DBusError *error, void *user_data)
+dbus_bool_t wpas_dbus_getter_p2p_peer_device_name(DBusMessageIter *iter,
+						  DBusError *error,
+						  void *user_data)
 {
 	struct peer_handler_args *peer_args = user_data;
-	DBusMessageIter variant_iter, dict_iter;
 	const struct p2p_peer_info *info = NULL;
-	const struct wpabuf *vendor_extension[P2P_MAX_WPS_VENDOR_EXT];
-	int i, num;
+	char *tmp;

 	if (!wpa_dbus_p2p_check_enabled(peer_args->wpa_s, NULL, NULL, error))
 		return FALSE;
@@ -1192,62 +1191,203 @@ dbus_bool_t
wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
 		return FALSE;
 	}

-	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
-					      "a{sv}", &variant_iter) ||
-	    !wpa_dbus_dict_open_write(&variant_iter, &dict_iter))
-		goto err_no_mem;
+	tmp = os_strdup(info->device_name);
+	if (!tmp) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		return FALSE;
+	}

-	/* Fill out the dictionary */
-	if (!wpa_dbus_dict_append_string(&dict_iter, "DeviceName",
-					 info->device_name))
-		goto err_no_mem;
-	if (!wpa_dbus_dict_append_byte_array(&dict_iter, "PrimaryDeviceType",
-					     (char *)info->pri_dev_type,
-					     WPS_DEV_TYPE_LEN))
-		goto err_no_mem;
-	if (!wpa_dbus_dict_append_uint16(&dict_iter, "config_method",
-					 info->config_methods))
-		goto err_no_mem;
-	if (!wpa_dbus_dict_append_int32(&dict_iter, "level",
-					info->level))
-		goto err_no_mem;
-	if (!wpa_dbus_dict_append_byte(&dict_iter, "devicecapability",
-				       info->dev_capab))
-		goto err_no_mem;
-	if (!wpa_dbus_dict_append_byte(&dict_iter, "groupcapability",
-				       info->group_capab))
-		goto err_no_mem;
+
+	if (!wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
+					      &tmp,
+					      error)) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		os_free(tmp);
+		return FALSE;
+	}
+
+	os_free(tmp);
+	return TRUE;
+}
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_primary_device_type(DBusMessageIter
*iter,
+                                                          DBusError *error,
+                                                          void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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 (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
+						     (char *)info->pri_dev_type,
+						    WPS_DEV_TYPE_LEN, error)) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_config_method(DBusMessageIter *iter,
+                                                    DBusError *error,
+                                                    void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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 (!wpas_dbus_simple_property_getter(iter, DBUS_TYPE_UINT16,
+					      &info->config_methods,
+					      error)) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_level(DBusMessageIter *iter,
+                                            DBusError *error,
+                                            void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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 (!wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
+					     &info->level,
+					     error)) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_device_capability(DBusMessageIter *iter,
+                                                        DBusError *error,
+                                                        void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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 (!wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BYTE,
+					     &info->dev_capab,
+					     error)) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_group_capability(DBusMessageIter *iter,
+                                                        DBusError *error,
+                                                        void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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 (!wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BYTE,
+					     &info->group_capab,
+					     error)) {
+		dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
+                                                       DBusMessageIter *iter,
+                                                       DBusError *error,
+                                                       void *user_data)
+{
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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 (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 / WPS_DEV_TYPE_LEN;
-		DBusMessageIter iter_secdev_dict_entry, iter_secdev_dict_val,
-				iter_secdev_dict_array;
-
-		if (num_sec_dev_types) {
-			if (!wpa_dbus_dict_begin_array(&dict_iter,
-						"SecondaryDeviceTypes",
-						DBUS_TYPE_ARRAY_AS_STRING
-						DBUS_TYPE_BYTE_AS_STRING,
-						&iter_secdev_dict_entry,
-						&iter_secdev_dict_val,
-						&iter_secdev_dict_array))
-				goto err_no_mem;
-			for (i = 0; i < num_sec_dev_types; i++) {
-				wpa_dbus_dict_bin_array_add_element(
-						&iter_secdev_dict_array,
-						sec_dev_type_list,
-						WPS_DEV_TYPE_LEN);
-				sec_dev_type_list += WPS_DEV_TYPE_LEN;
-			}
+		int num_sec_dev_types = info->wps_sec_dev_type_list_len;

-			if (!wpa_dbus_dict_end_array(&dict_iter,
-						&iter_secdev_dict_entry,
-						&iter_secdev_dict_val,
-						&iter_secdev_dict_array))
-				goto err_no_mem;
-		}
+		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 (!wpas_dbus_simple_array_property_getter(iter,
+						    DBUS_TYPE_BYTE,
+						    NULL,
+						    0,
+						    error))
+		goto err_no_mem;
+
+	return TRUE;
+
+err_no_mem:
+	dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
+	return FALSE;
+}
+
+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];
+	int i, num;
+
+	struct peer_handler_args *peer_args = user_data;
+	const struct p2p_peer_info *info = NULL;
+
+	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;
 	}

 	/* Add WPS vendor extensions attribute */
@@ -1258,22 +1398,15 @@ dbus_bool_t
wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
 		num++;
 	}

-	if (!wpa_dbus_dict_append_wpabuf_array(&dict_iter, "VendorExtension",
-					       vendor_extension, num))
-		goto err_no_mem;
-
-	if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
-	    !dbus_message_iter_close_container(iter, &variant_iter))
-		goto err_no_mem;
+	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;
+	}

 	return TRUE;
-
-err_no_mem:
-	dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
-	return FALSE;
 }

-
 dbus_bool_t wpas_dbus_getter_p2p_peer_ies(DBusMessageIter *iter,
 					  DBusError *error, void *user_data)
 {
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
index 206e904..2f05154 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h
@@ -118,9 +118,39 @@ dbus_bool_t
wpas_dbus_getter_p2p_peergo(DBusMessageIter *iter,
 /*
  * P2P Peer properties.
  */
-dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
-						 DBusError *error,
-						 void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_device_name(DBusMessageIter *iter,
+                                                  DBusError *error,
+                                                  void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_primary_device_type(DBusMessageIter
*iter,
+                                                          DBusError *error,
+                                                          void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_config_method(DBusMessageIter *iter,
+                                                    DBusError *error,
+                                                    void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_level(DBusMessageIter *iter,
+                                            DBusError *error,
+                                            void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_device_capability(DBusMessageIter *iter,
+                                                        DBusError *error,
+                                                        void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_group_capability(DBusMessageIter *iter,
+                                                       DBusError *error,
+                                                       void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
+                                                       DBusMessageIter *iter,
+                                                       DBusError *error,
+                                                       void *user_data);
+
+dbus_bool_t wpas_dbus_getter_p2p_peer_vendor_extension(DBusMessageIter *iter,
+                                                       DBusError *error,
+                                                       void *user_data);

 dbus_bool_t wpas_dbus_getter_p2p_peer_ies(DBusMessageIter *iter,
 					  DBusError *error,
-- 
1.7.9



More information about the Hostap mailing list