dbus: Make the P2P peer's properties accessible separately

Since there is the method org.freedesktop.DBus.Properties.GetAll that
returns all properties from a specific interface, it makes more sense to
separate the properties to make it possible to get only a single
property using the method org.freedesktop.DBus.Properties.Get as well.

Signed-hostap: Flávio Ceolin <flavio.ceolin@profusion.mobi>
This commit is contained in:
Flávio Ceolin 2012-02-11 11:36:50 +02:00 committed by Jouni Malinen
parent d9a0f66696
commit 3f6e50ac28
3 changed files with 266 additions and 73 deletions

View file

@ -2897,8 +2897,36 @@ int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
#ifdef CONFIG_P2P #ifdef CONFIG_P2P
static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = { static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
{ "Properties", WPAS_DBUS_NEW_IFACE_P2P_PEER, "a{sv}", { "DeviceName", WPAS_DBUS_NEW_IFACE_P2P_PEER, "s",
wpas_dbus_getter_p2p_peer_properties, 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, "q",
wpas_dbus_getter_p2p_peer_config_method,
NULL
},
{ "level", WPAS_DBUS_NEW_IFACE_P2P_PEER, "i",
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, "ay",
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 NULL
}, },
{ "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay", { "IEs", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",

View file

@ -1172,14 +1172,13 @@ dbus_bool_t wpas_dbus_getter_p2p_peergo(DBusMessageIter *iter,
* Peer object properties accessor methods * Peer object properties accessor methods
*/ */
dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter, dbus_bool_t wpas_dbus_getter_p2p_peer_device_name(DBusMessageIter *iter,
DBusError *error, void *user_data) DBusError *error,
void *user_data)
{ {
struct peer_handler_args *peer_args = user_data; struct peer_handler_args *peer_args = user_data;
DBusMessageIter variant_iter, dict_iter; const struct p2p_peer_info *info;
const struct p2p_peer_info *info = NULL; char *tmp;
const struct wpabuf *vendor_extension[P2P_MAX_WPS_VENDOR_EXT];
int i, num;
if (!wpa_dbus_p2p_check_enabled(peer_args->wpa_s, NULL, NULL, error)) if (!wpa_dbus_p2p_check_enabled(peer_args->wpa_s, NULL, NULL, error))
return FALSE; return FALSE;
@ -1188,66 +1187,210 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
info = p2p_get_peer_found(peer_args->wpa_s->global->p2p, info = p2p_get_peer_found(peer_args->wpa_s->global->p2p,
peer_args->p2p_device_addr, 0); peer_args->p2p_device_addr, 0);
if (info == NULL) { if (info == NULL) {
dbus_set_error(error, DBUS_ERROR_FAILED, "failed to find peer"); dbus_set_error(error, DBUS_ERROR_FAILED,
"failed to find peer");
return FALSE; return FALSE;
} }
if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, tmp = os_strdup(info->device_name);
"a{sv}", &variant_iter) || if (!tmp) {
!wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
goto err_no_mem; return FALSE;
}
/* Fill out the dictionary */ if (!wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING, &tmp,
if (!wpa_dbus_dict_append_string(&dict_iter, "DeviceName", error)) {
info->device_name)) dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
goto err_no_mem; os_free(tmp);
if (!wpa_dbus_dict_append_byte_array(&dict_iter, "PrimaryDeviceType", return FALSE;
(char *)info->pri_dev_type, }
WPS_DEV_TYPE_LEN))
goto err_no_mem; os_free(tmp);
if (!wpa_dbus_dict_append_uint16(&dict_iter, "config_method", return TRUE;
info->config_methods)) }
goto err_no_mem;
if (!wpa_dbus_dict_append_int32(&dict_iter, "level",
info->level)) dbus_bool_t wpas_dbus_getter_p2p_peer_primary_device_type(
goto err_no_mem; DBusMessageIter *iter, DBusError *error, void *user_data)
if (!wpa_dbus_dict_append_byte(&dict_iter, "devicecapability", {
info->dev_capab)) struct peer_handler_args *peer_args = user_data;
goto err_no_mem; const struct p2p_peer_info *info;
if (!wpa_dbus_dict_append_byte(&dict_iter, "groupcapability",
info->group_capab)) info = p2p_get_peer_found(peer_args->wpa_s->global->p2p,
goto err_no_mem; 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;
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;
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;
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;
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;
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) { if (info->wps_sec_dev_type_list_len) {
const u8 *sec_dev_type_list = info->wps_sec_dev_type_list; const u8 *sec_dev_type_list = info->wps_sec_dev_type_list;
int num_sec_dev_types = int num_sec_dev_types = info->wps_sec_dev_type_list_len;
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 (!wpas_dbus_simple_array_property_getter(iter,
if (!wpa_dbus_dict_begin_array(&dict_iter, DBUS_TYPE_BYTE,
"SecondaryDeviceTypes", sec_dev_type_list,
DBUS_TYPE_ARRAY_AS_STRING num_sec_dev_types,
DBUS_TYPE_BYTE_AS_STRING, error))
&iter_secdev_dict_entry, goto err_no_mem;
&iter_secdev_dict_val, else
&iter_secdev_dict_array)) return TRUE;
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;
}
if (!wpa_dbus_dict_end_array(&dict_iter, if (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE, NULL,
&iter_secdev_dict_entry, 0, error))
&iter_secdev_dict_val, goto err_no_mem;
&iter_secdev_dict_array))
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;
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 */ /* Add WPS vendor extensions attribute */
@ -1258,19 +1401,14 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
num++; num++;
} }
if (!wpa_dbus_dict_append_wpabuf_array(&dict_iter, "VendorExtension", if (!wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_STRING,
vendor_extension, num)) vendor_extension, num,
goto err_no_mem; error)) {
dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) || return FALSE;
!dbus_message_iter_close_container(iter, &variant_iter)) }
goto err_no_mem;
return TRUE; return TRUE;
err_no_mem:
dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
return FALSE;
} }

View file

@ -118,9 +118,36 @@ dbus_bool_t wpas_dbus_getter_p2p_peergo(DBusMessageIter *iter,
/* /*
* P2P Peer properties. * P2P Peer properties.
*/ */
dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
DBusError *error, dbus_bool_t wpas_dbus_getter_p2p_peer_device_name(DBusMessageIter *iter,
void *user_data); 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, dbus_bool_t wpas_dbus_getter_p2p_peer_ies(DBusMessageIter *iter,
DBusError *error, DBusError *error,