summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/supplicant-dbus.c81
-rw-r--r--tools/supplicant-dbus.h8
-rw-r--r--tools/supplicant.c88
-rw-r--r--tools/supplicant.h3
4 files changed, 170 insertions, 10 deletions
diff --git a/tools/supplicant-dbus.c b/tools/supplicant-dbus.c
index 3f1c9af9..e6378c32 100644
--- a/tools/supplicant-dbus.c
+++ b/tools/supplicant-dbus.c
@@ -98,14 +98,14 @@ void supplicant_dbus_property_foreach(DBusMessageIter *iter,
}
}
-struct property_data {
+struct property_get_data {
supplicant_dbus_property_function function;
void *user_data;
};
static void property_get_all_reply(DBusPendingCall *call, void *user_data)
{
- struct property_data *data = user_data;
+ struct property_get_data *data = user_data;
DBusMessage *reply;
DBusMessageIter iter;
@@ -133,7 +133,7 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface,
supplicant_dbus_property_function function,
void *user_data)
{
- struct property_data *data;
+ struct property_get_data *data;
DBusMessage *message;
DBusPendingCall *call;
@@ -178,3 +178,78 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface,
return 0;
}
+
+struct property_set_data {
+ void *user_data;
+};
+
+static void property_set_reply(DBusPendingCall *call, void *user_data)
+{
+ //struct property_set_data *data = user_data;
+ DBusMessage *reply;
+
+ reply = dbus_pending_call_steal_reply(call);
+ if (reply == NULL)
+ return;
+
+ dbus_message_unref(reply);
+}
+
+int supplicant_dbus_property_set(const char *path, const char *interface,
+ const char *key, const char *signature,
+ supplicant_dbus_value_function function,
+ void *user_data)
+{
+ struct property_set_data *data;
+ DBusMessage *message;
+ DBusMessageIter iter, value;
+ DBusPendingCall *call;
+
+ if (path == NULL || interface == NULL)
+ return -EINVAL;
+
+ data = dbus_malloc0(sizeof(*data));
+ if (data == NULL)
+ return -ENOMEM;
+
+ message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
+ DBUS_INTERFACE_PROPERTIES, "Set");
+ if (message == NULL) {
+ dbus_free(data);
+ return -ENOMEM;
+ }
+
+ dbus_message_set_auto_start(message, FALSE);
+
+ dbus_message_iter_init_append(message, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ signature, &value);
+ if (function != NULL)
+ function(&value, user_data);
+ dbus_message_iter_close_container(&iter, &value);
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ dbus_message_unref(message);
+ dbus_free(data);
+ return -EIO;
+ }
+
+ if (call == NULL) {
+ dbus_message_unref(message);
+ dbus_free(data);
+ return -EIO;
+ }
+
+ data->user_data = user_data;
+
+ dbus_pending_call_set_notify(call, property_set_reply,
+ data, dbus_free);
+
+ dbus_message_unref(message);
+
+ return 0;
+}
diff --git a/tools/supplicant-dbus.h b/tools/supplicant-dbus.h
index 04cf0f54..51981e27 100644
--- a/tools/supplicant-dbus.h
+++ b/tools/supplicant-dbus.h
@@ -31,6 +31,9 @@ typedef void (* supplicant_dbus_array_function) (DBusMessageIter *iter,
typedef void (* supplicant_dbus_property_function) (const char *key,
DBusMessageIter *iter, void *user_data);
+typedef void (* supplicant_dbus_value_function) (DBusMessageIter *iter,
+ void *user_data);
+
void supplicant_dbus_setup(DBusConnection *conn);
void supplicant_dbus_array_foreach(DBusMessageIter *iter,
@@ -44,3 +47,8 @@ void supplicant_dbus_property_foreach(DBusMessageIter *iter,
int supplicant_dbus_property_get_all(const char *path, const char *interface,
supplicant_dbus_property_function function,
void *user_data);
+
+int supplicant_dbus_property_set(const char *path, const char *interface,
+ const char *key, const char *signature,
+ supplicant_dbus_value_function function,
+ void *user_data);
diff --git a/tools/supplicant.c b/tools/supplicant.c
index 9a9f1a08..cd5c6ae5 100644
--- a/tools/supplicant.c
+++ b/tools/supplicant.c
@@ -48,6 +48,10 @@ static DBusConnection *connection;
static const struct supplicant_callbacks *callbacks_pointer;
+static dbus_int32_t debug_level = 0;
+static dbus_bool_t debug_show_timestamps = FALSE;
+static dbus_bool_t debug_show_keys = FALSE;
+
static unsigned int eap_methods;
struct strvalmap {
@@ -879,12 +883,25 @@ static void service_property(const char *key, DBusMessageIter *iter,
if (key == NULL)
return;
- if (g_strcmp0(key, "Interfaces") == 0)
+ if (g_strcmp0(key, "DebugParams") == 0) {
+ DBusMessageIter list;
+
+ dbus_message_iter_recurse(iter, &list);
+ dbus_message_iter_get_basic(&list, &debug_level);
+
+ dbus_message_iter_next(&list);
+ dbus_message_iter_get_basic(&list, &debug_show_timestamps);
+
+ dbus_message_iter_next(&list);
+ dbus_message_iter_get_basic(&list, &debug_show_keys);
+
+ DBG("Debug level %d (timestamps %u keys %u)", debug_level,
+ debug_show_timestamps, debug_show_keys);
+ } else if (g_strcmp0(key, "Interfaces") == 0) {
supplicant_dbus_array_foreach(iter, interface_added, user_data);
- else if (g_strcmp0(key, "EapMethods") == 0) {
+ } else if (g_strcmp0(key, "EapMethods") == 0) {
supplicant_dbus_array_foreach(iter, eap_method, user_data);
debug_strvalmap("EAP method", eap_method_map, eap_methods);
- } else if (g_strcmp0(key, "DebugParams") == 0) {
}
}
@@ -924,6 +941,14 @@ static void signal_name_owner_changed(const char *path, DBusMessageIter *iter)
supplicant_bootstrap();
}
+static void signal_properties_changed(const char *path, DBusMessageIter *iter)
+{
+ if (g_strcmp0(path, SUPPLICANT_PATH) != 0)
+ return;
+
+ supplicant_dbus_property_foreach(iter, service_property, NULL);
+}
+
static void signal_interface_added(const char *path, DBusMessageIter *iter)
{
if (g_strcmp0(path, SUPPLICANT_PATH) == 0)
@@ -985,11 +1010,12 @@ static struct {
const char *member;
void (*function) (const char *path, DBusMessageIter *iter);
} signal_map[] = {
- { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
+ { DBUS_INTERFACE_DBUS, "NameOwnerChanged", signal_name_owner_changed },
- { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
- { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
- { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
+ { SUPPLICANT_INTERFACE, "PropertiesChanged", signal_properties_changed },
+ { SUPPLICANT_INTERFACE, "InterfaceAdded", signal_interface_added },
+ { SUPPLICANT_INTERFACE, "InterfaceCreated", signal_interface_added },
+ { SUPPLICANT_INTERFACE, "InterfaceRemoved", signal_interface_removed },
{ SUPPLICANT_INTERFACE ".Interface", "BSSAdded", signal_bss_added },
{ SUPPLICANT_INTERFACE ".Interface", "BSSRemoved", signal_bss_removed },
@@ -1114,3 +1140,51 @@ void supplicant_unregister(const struct supplicant_callbacks *callbacks)
callbacks_pointer = NULL;
eap_methods = 0;
}
+
+static void add_debug_level(DBusMessageIter *iter, void *user_data)
+{
+ dbus_int32_t level = GPOINTER_TO_UINT(user_data);
+ DBusMessageIter entry;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_INT32, &level);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_BOOLEAN,
+ &debug_show_timestamps);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_BOOLEAN,
+ &debug_show_keys);
+
+ dbus_message_iter_close_container(iter, &entry);
+}
+
+void supplicant_set_debug_level(unsigned int level)
+{
+ supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
+ "DebugParams", "(ibb)",
+ add_debug_level, GUINT_TO_POINTER(level));
+}
+
+static void add_show_timestamps(DBusMessageIter *iter, void *user_data)
+{
+ dbus_bool_t show_timestamps = GPOINTER_TO_UINT(user_data);
+ DBusMessageIter entry;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
+ NULL, &entry);
+
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_INT32, &debug_level);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_BOOLEAN,
+ &show_timestamps);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_BOOLEAN,
+ &debug_show_keys);
+
+ dbus_message_iter_close_container(iter, &entry);
+}
+
+void supplicant_set_debug_show_timestamps(dbus_bool_t enabled)
+{
+ supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE,
+ "DebugParams", "(ibb)",
+ add_show_timestamps, GUINT_TO_POINTER(enabled));
+}
diff --git a/tools/supplicant.h b/tools/supplicant.h
index 3d1b5c17..0a783e1e 100644
--- a/tools/supplicant.h
+++ b/tools/supplicant.h
@@ -87,3 +87,6 @@ struct supplicant_callbacks {
int supplicant_register(const struct supplicant_callbacks *callbacks);
void supplicant_unregister(const struct supplicant_callbacks *callbacks);
+
+void supplicant_set_debug_level(unsigned int level);
+void supplicant_set_debug_show_timestamps(dbus_bool_t enabled);