[PATCH v2] dbus: Add NetworkTempDisabled & NetworkReenabled signals
Fionn Cleary
fionn.cleary at streamunlimited.com
Tue Mar 9 14:22:19 GMT 2021
From: Fionn Cleary <fionn.cleary at streamunlimited.com>
These can be used to determine if a particular network has incorrect
credentials, as the existing DisconnectReason signal is only useful
for determining that a network has a problem, but not which one.
Signed-off-by: Peter Malo <peter.malo at streamunlimited.com>
[Code formatting & adding NetworkReenabled]
Signed-off-by: Fionn Cleary <fionn.cleary at streamunlimited.com>
---
doc/dbus.doxygen | 20 ++++++
wpa_supplicant/dbus/dbus_new.c | 109 ++++++++++++++++++++++++++++++++
wpa_supplicant/dbus/dbus_new.h | 16 +++++
wpa_supplicant/notify.c | 12 ++++
wpa_supplicant/notify.h | 4 ++
wpa_supplicant/wpa_supplicant.c | 4 ++
6 files changed, 165 insertions(+)
diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen
index 8231aac41..57b7c3b5a 100644
--- a/doc/dbus.doxygen
+++ b/doc/dbus.doxygen
@@ -1261,6 +1261,26 @@ fi.w1.wpa_supplicant1.CreateInterface.
<dd>A dictionary with pairs of field names and their values. Possible dictionary keys are: "addr", "dst", "bssid", "ies", "signal".</dd>
</dl>
</li>
+
+ <li>
+ <h3>NetworkTempDisabled ( a{sv} : parameters )</h3>
+ <p>Notification of a network being temporarily disabled.</p>
+ <h4>Arguments</h4>
+ <dl>
+ <dt>a{sv} : parameters</dt>
+ <dd>A dictionary with pairs of field names and their values. Possible dictionary keys are: "network", "auth_failures", "reason".</dd>
+ </dl>
+ </li>
+
+ <li>
+ <h3>NetworkReenabled ( a{sv} : paramaters )</h3>
+ <p>Notification that a network is being reenabled after it was temporarily disabled.</p>
+ <h4>Arguments</h4>
+ <dl>
+ <dt>a{sv} : parameters</dt>
+ <dd>A dictionary with pairs of field names and their values. Possible dictionary keys are: "network".</dd>
+ </dl>
+ </li>
</ul>
diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 2c01943f7..03d50d780 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -1155,6 +1155,103 @@ static void wpas_dbus_signal_station_removed(struct wpa_supplicant *wpa_s,
FALSE);
}
+/**
+ * wpas_dbus_signal_network_temp_disabled - Send a signal that a network been temporarily disabled
+ * @wpa_s: %wpa_supplicant network interface data
+ * @ssid: struct holding SSID related data
+ * @reason: reason why the network was disabled
+ *
+ * Notify listeners about a temporarily disabled network
+ */
+void wpas_dbus_signal_network_temp_disabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid,
+ const char *reason)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+ DBusMessageIter iter, dict_iter;
+ char path[WPAS_DBUS_OBJECT_PATH_MAX];
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL || !wpa_s->dbus_new_path)
+ return;
+
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
+ wpa_s->dbus_new_path, ssid->id);
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ "NetworkTempDisabled");
+
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
+ goto nomem;
+
+ if (!wpa_dbus_dict_append_object_path(&dict_iter, "network", path) ||
+ !wpa_dbus_dict_append_uint32(&dict_iter, "auth_failures",
+ ssid->auth_failures) ||
+ !wpa_dbus_dict_append_string(&dict_iter, "reason",
+ reason) ||
+ !wpa_dbus_dict_close_write(&iter, &dict_iter))
+ goto nomem;
+ else
+ dbus_connection_send(iface->con, msg, NULL);
+nomem:
+ dbus_message_unref(msg);
+}
+
+/**
+ * wpas_dbus_signal_network_reenabled - Send a signal that a network has been reenabled
+ * @wpa_s: %wpa_supplicant network interface data
+ * @ssid: struct holding SSID related data
+ *
+ * Notify listeners about reenabled network
+ */
+void wpas_dbus_signal_network_reenabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ struct wpas_dbus_priv *iface;
+ DBusMessage *msg;
+ DBusMessageIter iter, dict_iter;
+ char path[WPAS_DBUS_OBJECT_PATH_MAX];
+
+ iface = wpa_s->global->dbus;
+
+ /* Do nothing if the control interface is not turned on */
+ if (iface == NULL || !wpa_s->dbus_new_path)
+ return;
+
+ os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
+ wpa_s->dbus_new_path, ssid->id);
+
+ msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+ WPAS_DBUS_NEW_IFACE_INTERFACE,
+ "NetworkReenabled");
+
+ if (msg == NULL)
+ return;
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
+ goto nomem;
+
+ if (!wpa_dbus_dict_append_object_path(&dict_iter, "network", path) ||
+ !wpa_dbus_dict_close_write(&iter, &dict_iter))
+ goto nomem;
+ else
+ dbus_connection_send(iface->con, msg, NULL);
+nomem:
+ dbus_message_unref(msg);
+}
#ifdef CONFIG_P2P
@@ -4137,6 +4234,18 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
}
},
#endif /* CONFIG_MESH */
+ { "NetworkTempDisabled", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
+ { "NetworkRenabled", WPAS_DBUS_NEW_IFACE_INTERFACE,
+ {
+ { "properties", "a{sv}", ARG_OUT },
+ END_ARGS
+ }
+ },
{ NULL, NULL, { END_ARGS } }
};
diff --git a/wpa_supplicant/dbus/dbus_new.h b/wpa_supplicant/dbus/dbus_new.h
index 42db3892e..b22bd6e78 100644
--- a/wpa_supplicant/dbus/dbus_new.h
+++ b/wpa_supplicant/dbus/dbus_new.h
@@ -264,6 +264,11 @@ void wpas_dbus_signal_mesh_peer_connected(struct wpa_supplicant *wpa_s,
const u8 *peer_addr);
void wpas_dbus_signal_mesh_peer_disconnected(struct wpa_supplicant *wpa_s,
const u8 *peer_addr, int reason);
+void wpas_dbus_signal_network_temp_disabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid,
+ const char *reason);
+void wpas_dbus_signal_network_reenabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
#else /* CONFIG_CTRL_IFACE_DBUS_NEW */
@@ -616,6 +621,17 @@ void wpas_dbus_signal_mesh_peer_disconnected(struct wpa_supplicant *wpa_s,
{
}
+static inline void wpas_dbus_signal_network_temp_disabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid,
+ const char *reason)
+{
+}
+
+static inline void wpas_dbus_signal_network_reenabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+}
+
#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
#endif /* CTRL_IFACE_DBUS_H_NEW */
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index e0e7e5433..6bd4bcb9f 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -937,3 +937,15 @@ void wpas_notify_mesh_peer_disconnected(struct wpa_supplicant *wpa_s,
}
#endif /* CONFIG_MESH */
+
+void wpas_notify_network_temp_disabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid, const char* reason)
+{
+ wpas_dbus_signal_network_temp_disabled(wpa_s, ssid, reason);
+}
+
+void wpas_notify_network_reenabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid)
+{
+ wpas_dbus_signal_network_reenabled(wpa_s, ssid);
+}
diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h
index e843aa124..7fa687282 100644
--- a/wpa_supplicant/notify.h
+++ b/wpa_supplicant/notify.h
@@ -156,5 +156,9 @@ void wpas_notify_mesh_peer_connected(struct wpa_supplicant *wpa_s,
const u8 *peer_addr);
void wpas_notify_mesh_peer_disconnected(struct wpa_supplicant *wpa_s,
const u8 *peer_addr, u16 reason_code);
+void wpas_notify_network_temp_disabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid, const char* reason);
+void wpas_notify_network_reenabled(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid);
#endif /* NOTIFY_H */
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 6a02ed7c5..59f45a1d5 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -7804,6 +7804,8 @@ void wpas_auth_failed(struct wpa_supplicant *wpa_s, char *reason)
"id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
ssid->auth_failures, dur, reason);
+
+ wpas_notify_network_temp_disabled(wpa_s, ssid, reason);
}
@@ -7822,6 +7824,8 @@ void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s,
ssid->disabled_until.usec = 0;
if (clear_failures)
ssid->auth_failures = 0;
+
+ wpas_notify_network_reenabled(wpa_s, ssid);
}
--
2.25.1
More information about the Hostap
mailing list