summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Zaborowski <andrew.zaborowski@intel.com>2020-10-22 15:59:04 +0200
committerThomas Haller <thaller@redhat.com>2020-11-19 10:12:02 +0100
commit7d9b37feaf247d7d456d3dc86e5fbec78b164284 (patch)
tree3498907286e88d8d6edcc9ba9b6fcc0fc3aed127
parentadaeb7a872ce7c1b934de441d4db19c49973aeac (diff)
downloadNetworkManager-7d9b37feaf247d7d456d3dc86e5fbec78b164284.tar.gz
iwd: Handle the net.connman.iwd.Agent.Cancel() method
Implement a Cancel method on our IWD secrets agent DBus object. This results in a call to nm_device_iwd_agent_query() for the device currently handling the request and the @invocation parameter is NULL to signal that the current query is being cancelled. nm_device_iwd_agent_query doesn't do much with this call just yet but the handling will be necessary when IWD autoconnect is used by NM.
-rw-r--r--src/devices/wifi/nm-device-iwd.c17
-rw-r--r--src/devices/wifi/nm-iwd-manager.c48
2 files changed, 61 insertions, 4 deletions
diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c
index e59dafdefe..064ca4e53b 100644
--- a/src/devices/wifi/nm-device-iwd.c
+++ b/src/devices/wifi/nm-device-iwd.c
@@ -2607,6 +2607,23 @@ nm_device_iwd_agent_query(NMDeviceIwd *self, GDBusMethodInvocation *invocation)
NMSecretAgentGetSecretsFlags get_secret_flags =
NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION;
+ if (!invocation) {
+ NMActRequest *act_req = nm_device_get_act_request(device);
+
+ if (!act_req)
+ return FALSE;
+
+ wifi_secrets_cancel(self);
+
+ if (nm_device_get_state(device) == NM_DEVICE_STATE_NEED_AUTH)
+ nm_device_state_changed(device, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE);
+
+ /* The secrets request is being cancelled. Let the Network.Connect
+ * method call's callback handle the failure.
+ */
+ return TRUE;
+ }
+
req = nm_device_get_act_request(device);
if (!req || nm_device_get_state(device) != NM_DEVICE_STATE_CONFIG) {
_LOGI(LOGD_WIFI, "IWD asked for secrets without explicit connect request");
diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c
index 402480d279..2ab023492a 100644
--- a/src/devices/wifi/nm-iwd-manager.c
+++ b/src/devices/wifi/nm-iwd-manager.c
@@ -39,6 +39,7 @@ typedef struct {
guint agent_id;
char * agent_path;
GHashTable * known_networks;
+ NMDeviceIwd * last_agent_call_device;
} NMIwdManagerPrivate;
struct _NMIwdManager {
@@ -178,6 +179,25 @@ agent_dbus_method_cb(GDBusConnection * connection,
if (!nm_streq0(name_owner, sender))
goto return_error;
+ if (!strcmp(method_name, "Cancel")) {
+ const char *reason = NULL;
+
+ g_variant_get(parameters, "(&s)", &reason);
+ _LOGD("agent-request: Cancel reason: %s", reason);
+
+ if (!priv->last_agent_call_device)
+ goto return_error;
+
+ if (nm_device_iwd_agent_query(priv->last_agent_call_device, NULL)) {
+ priv->last_agent_call_device = NULL;
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ return;
+ }
+
+ priv->last_agent_call_device = NULL;
+ goto return_error;
+ }
+
if (!strcmp(method_name, "RequestUserPassword"))
g_variant_get(parameters, "(&os)", &network_path, NULL);
else
@@ -197,8 +217,10 @@ agent_dbus_method_cb(GDBusConnection * connection,
goto return_error;
}
- if (nm_device_iwd_agent_query(device, invocation))
+ if (nm_device_iwd_agent_query(device, invocation)) {
+ priv->last_agent_call_device = device;
return;
+ }
_LOGD("agent-request: device %s did not handle the IWD Agent request",
nm_device_get_iface(NM_DEVICE(device)));
@@ -229,10 +251,12 @@ static const GDBusInterfaceInfo iwd_agent_iface_info = NM_DEFINE_GDBUS_INTERFACE
NM_DEFINE_GDBUS_ARG_INFO("password", "s"), ), ),
NM_DEFINE_GDBUS_METHOD_INFO(
"RequestUserPassword",
- .in_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("network", "o"),
+ .in_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("network", "o"),
NM_DEFINE_GDBUS_ARG_INFO("user", "s"), ),
- .out_args =
- NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("password", "s"), ), ), ), );
+ .out_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("password", "s"), ), ),
+ NM_DEFINE_GDBUS_METHOD_INFO("Cancel",
+ .in_args = NM_DEFINE_GDBUS_ARG_INFOS(
+ NM_DEFINE_GDBUS_ARG_INFO("reason", "s"), ), ), ), );
static guint
iwd_agent_export(GDBusConnection *connection, gpointer user_data, char **agent_path, GError **error)
@@ -840,6 +864,19 @@ device_added(NMManager *manager, NMDevice *device, gpointer user_data)
}
static void
+device_removed(NMManager *manager, NMDevice *device, gpointer user_data)
+{
+ NMIwdManager * self = user_data;
+ NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self);
+
+ if (!NM_IS_DEVICE_IWD(device))
+ return;
+
+ if (priv->last_agent_call_device == NM_DEVICE_IWD(device))
+ priv->last_agent_call_device = NULL;
+}
+
+static void
got_object_manager(GObject *object, GAsyncResult *result, gpointer user_data)
{
NMIwdManager * self = user_data;
@@ -955,6 +992,7 @@ nm_iwd_manager_init(NMIwdManager *self)
priv->manager = g_object_ref(NM_MANAGER_GET);
g_signal_connect(priv->manager, NM_MANAGER_DEVICE_ADDED, G_CALLBACK(device_added), self);
+ g_signal_connect(priv->manager, NM_MANAGER_DEVICE_REMOVED, G_CALLBACK(device_removed), self);
priv->settings = g_object_ref(NM_SETTINGS_GET);
g_signal_connect(priv->settings,
@@ -997,6 +1035,8 @@ dispose(GObject *object)
g_clear_object(&priv->manager);
}
+ priv->last_agent_call_device = NULL;
+
G_OBJECT_CLASS(nm_iwd_manager_parent_class)->dispose(object);
}