summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-02-25 14:53:44 +0100
committerLubomir Rintel <lkundrak@v3.sk>2018-06-13 14:44:06 +0200
commitc00e17578f727b34c41ad54c8348a49f894969c2 (patch)
treece29773ded2e7a8a2a143da0189538d56da1c121
parentc2932dd7dbb8997b7c46b49506efbd16cd3f56ca (diff)
downloadNetworkManager-c00e17578f727b34c41ad54c8348a49f894969c2.tar.gz
wifi: expose the LastScan property
This is the time when the last Wi-Fi scan finished. It will help clients decide whether the AP list is fresh enough.
-rw-r--r--introspection/org.freedesktop.NetworkManager.Device.Wireless.xml10
-rw-r--r--libnm/libnm.ver1
-rw-r--r--libnm/nm-device-wifi.c42
-rw-r--r--libnm/nm-device-wifi.h4
-rw-r--r--src/devices/wifi/nm-device-iwd.c15
-rw-r--r--src/devices/wifi/nm-device-iwd.h1
-rw-r--r--src/devices/wifi/nm-device-wifi.c13
-rw-r--r--src/devices/wifi/nm-device-wifi.h1
-rw-r--r--src/devices/wifi/nm-wifi-common.c1
-rwxr-xr-xtools/test-networkmanager-service.py2
10 files changed, 90 insertions, 0 deletions
diff --git a/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml b/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml
index bff89120a5..af6e8c7ff3 100644
--- a/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml
+++ b/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml
@@ -97,6 +97,16 @@
<property name="WirelessCapabilities" type="u" access="read"/>
<!--
+ LastScan:
+
+ The timestamp (in CLOCK_BOOTTIME seconds) for the last finished network scan.
+ A value of -1 means the device never scanned for access points.
+
+ Since: 1.12
+ -->
+ <property name="LastScan" type="i" access="read"/>
+
+ <!--
PropertiesChanged:
@properties: A dictionary containing the changed parameters.
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 60629ff65c..6408436dd3 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1350,6 +1350,7 @@ global:
nm_client_get_checkpoints;
nm_connection_get_setting_tc_config;
nm_device_ip_tunnel_get_flags;
+ nm_device_wifi_get_last_scan;
nm_ip_tunnel_flags_get_type;
nm_remote_connection_get_filename;
nm_remote_connection_get_flags;
diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c
index 1f2118fa6d..851983f46c 100644
--- a/libnm/nm-device-wifi.c
+++ b/libnm/nm-device-wifi.c
@@ -59,6 +59,7 @@ typedef struct {
NMAccessPoint *active_ap;
NMDeviceWifiCapabilities wireless_caps;
GPtrArray *aps;
+ gint last_scan;
RequestScanInfo *scan_info;
} NMDeviceWifiPrivate;
@@ -72,6 +73,7 @@ enum {
PROP_ACTIVE_ACCESS_POINT,
PROP_WIRELESS_CAPABILITIES,
PROP_ACCESS_POINTS,
+ PROP_LAST_SCAN,
LAST_PROP
};
@@ -267,6 +269,25 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
return ap;
}
+/**
+ * nm_device_wifi_get_last_scan:
+ * @device: a #NMDeviceWifi
+ *
+ * Returns the timestamp (in CLOCK_BOOTTIME seconds) for the last finished
+ * network scan. A value of -1 means the device never scanned for access points.
+ *
+ * Returns: the last scan time in seconds
+ *
+ * Since: 1.12
+ **/
+gint
+nm_device_wifi_get_last_scan (NMDeviceWifi *device)
+{
+ g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), -1);
+
+ return NM_DEVICE_WIFI_GET_PRIVATE (device)->last_scan;
+}
+
static GVariant *
prepare_scan_options (GVariant *options)
{
@@ -666,6 +687,7 @@ nm_device_wifi_init (NMDeviceWifi *device)
NULL);
priv->aps = g_ptr_array_new ();
+ priv->last_scan = -1;
}
static void
@@ -698,6 +720,9 @@ get_property (GObject *object,
case PROP_ACCESS_POINTS:
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_wifi_get_access_points (self)));
break;
+ case PROP_LAST_SCAN:
+ g_value_set_int (value, nm_device_wifi_get_last_scan (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -739,6 +764,7 @@ init_dbus (NMObject *object)
{ NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, &priv->active_ap, NULL, NM_TYPE_ACCESS_POINT },
{ NM_DEVICE_WIFI_CAPABILITIES, &priv->wireless_caps },
{ NM_DEVICE_WIFI_ACCESS_POINTS, &priv->aps, NULL, NM_TYPE_ACCESS_POINT, "access-point" },
+ { NM_DEVICE_WIFI_LAST_SCAN, &priv->last_scan },
{ NULL },
};
@@ -898,6 +924,22 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+ /**
+ * NMDeviceWifi:last-scan:
+ *
+ * The timestamp (in CLOCK_BOOTTIME seconds) for the last finished
+ * network scan. A value of -1 means the device never scanned for
+ * access points.
+ *
+ * Since: 1.12
+ **/
+ g_object_class_install_property
+ (object_class, PROP_LAST_SCAN,
+ g_param_spec_int (NM_DEVICE_WIFI_LAST_SCAN, "", "",
+ -1, G_MAXINT, -1,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
/* signals */
/**
diff --git a/libnm/nm-device-wifi.h b/libnm/nm-device-wifi.h
index 8cfea1f307..9885438f02 100644
--- a/libnm/nm-device-wifi.h
+++ b/libnm/nm-device-wifi.h
@@ -44,6 +44,7 @@ G_BEGIN_DECLS
#define NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT "active-access-point"
#define NM_DEVICE_WIFI_CAPABILITIES "wireless-capabilities"
#define NM_DEVICE_WIFI_ACCESS_POINTS "access-points"
+#define NM_DEVICE_WIFI_LAST_SCAN "last-scan"
/**
* NMDeviceWifi:
@@ -77,6 +78,9 @@ NMAccessPoint * nm_device_wifi_get_access_point_by_path (NMDeviceWifi *
const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi *device);
+NM_AVAILABLE_IN_1_2
+gint nm_device_wifi_get_last_scan (NMDeviceWifi *device);
+
gboolean nm_device_wifi_request_scan (NMDeviceWifi *device,
GCancellable *cancellable,
GError **error);
diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c
index d3c5ae9aa9..58bafb81d4 100644
--- a/src/devices/wifi/nm-device-iwd.c
+++ b/src/devices/wifi/nm-device-iwd.c
@@ -54,6 +54,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceIwd,
PROP_ACTIVE_ACCESS_POINT,
PROP_CAPABILITIES,
PROP_SCANNING,
+ PROP_LAST_SCAN,
);
enum {
@@ -79,6 +80,7 @@ typedef struct {
bool can_connect:1;
bool scanning:1;
bool scan_requested:1;
+ gint32 last_scan;
} NMDeviceIwdPrivate;
struct _NMDeviceIwd {
@@ -863,6 +865,8 @@ scan_cb (GObject *source, GAsyncResult *res, gpointer user_data)
priv = NM_DEVICE_IWD_GET_PRIVATE (self);
priv->scan_requested = FALSE;
+ priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
+ _notify (self, PROP_LAST_SCAN);
/* On success, priv->scanning becomes true right before or right
* after this callback, so the next automatic scan will be
@@ -1530,6 +1534,12 @@ get_property (GObject *object, guint prop_id,
case PROP_SCANNING:
g_value_set_boolean (value, priv->scanning);
break;
+ case PROP_LAST_SCAN:
+ g_value_set_int (value,
+ priv->last_scan > 0
+ ? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_SECOND)
+ : -1);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1909,6 +1919,11 @@ nm_device_iwd_class_init (NMDeviceIwdClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_LAST_SCAN] =
+ g_param_spec_int (NM_DEVICE_IWD_LAST_SCAN, "", "",
+ -1, G_MAXINT, -1,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[SCANNING_PROHIBITED] =
diff --git a/src/devices/wifi/nm-device-iwd.h b/src/devices/wifi/nm-device-iwd.h
index 699ba1bb2b..a4253f5217 100644
--- a/src/devices/wifi/nm-device-iwd.h
+++ b/src/devices/wifi/nm-device-iwd.h
@@ -38,6 +38,7 @@
#define NM_DEVICE_IWD_ACTIVE_ACCESS_POINT NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT
#define NM_DEVICE_IWD_CAPABILITIES NM_DEVICE_WIFI_CAPABILITIES
#define NM_DEVICE_IWD_SCANNING NM_DEVICE_WIFI_SCANNING
+#define NM_DEVICE_IWD_LAST_SCAN NM_DEVICE_WIFI_LAST_SCAN
#define NM_DEVICE_IWD_SCANNING_PROHIBITED NM_DEVICE_WIFI_SCANNING_PROHIBITED
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 90f9455742..f3c23e60f3 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -74,6 +74,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceWifi,
PROP_ACTIVE_ACCESS_POINT,
PROP_CAPABILITIES,
PROP_SCANNING,
+ PROP_LAST_SCAN,
);
enum {
@@ -1423,6 +1424,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface,
_LOGD (LOGD_WIFI, "wifi-scan: scan-done callback: %s", success ? "successful" : "failed");
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
+ _notify (self, PROP_LAST_SCAN);
schedule_scan (self, success);
_requested_scan_set (self, FALSE);
@@ -3123,6 +3125,12 @@ get_property (GObject *object, guint prop_id,
case PROP_SCANNING:
g_value_set_boolean (value, priv->is_scanning);
break;
+ case PROP_LAST_SCAN:
+ g_value_set_int (value,
+ priv->last_scan > 0
+ ? (gint) nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_SECOND)
+ : -1);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -3300,6 +3308,11 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_LAST_SCAN] =
+ g_param_spec_int (NM_DEVICE_WIFI_LAST_SCAN, "", "",
+ -1, G_MAXINT, -1,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[SCANNING_PROHIBITED] =
diff --git a/src/devices/wifi/nm-device-wifi.h b/src/devices/wifi/nm-device-wifi.h
index c13b00defc..1c555f5fe1 100644
--- a/src/devices/wifi/nm-device-wifi.h
+++ b/src/devices/wifi/nm-device-wifi.h
@@ -37,6 +37,7 @@
#define NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT "active-access-point"
#define NM_DEVICE_WIFI_CAPABILITIES "wireless-capabilities"
#define NM_DEVICE_WIFI_SCANNING "scanning"
+#define NM_DEVICE_WIFI_LAST_SCAN "last-scan"
#define NM_DEVICE_WIFI_SCANNING_PROHIBITED "scanning-prohibited"
diff --git a/src/devices/wifi/nm-wifi-common.c b/src/devices/wifi/nm-wifi-common.c
index e5e16f03e0..0030b32dff 100644
--- a/src/devices/wifi/nm-wifi-common.c
+++ b/src/devices/wifi/nm-wifi-common.c
@@ -200,6 +200,7 @@ const NMDBusInterfaceInfoExtended nm_interface_info_device_wireless = {
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("AccessPoints", "ao", NM_DEVICE_WIFI_ACCESS_POINTS),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("ActiveAccessPoint", "o", NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("WirelessCapabilities", "u", NM_DEVICE_WIFI_CAPABILITIES),
+ NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("LastScan", "i", NM_DEVICE_WIFI_LAST_SCAN),
),
),
.legacy_property_changed = TRUE,
diff --git a/tools/test-networkmanager-service.py b/tools/test-networkmanager-service.py
index af8dc27534..bc3c828b35 100755
--- a/tools/test-networkmanager-service.py
+++ b/tools/test-networkmanager-service.py
@@ -908,6 +908,7 @@ PRP_WIFI_BITRATE = "Bitrate"
PRP_WIFI_ACCESS_POINTS = "AccessPoints"
PRP_WIFI_ACTIVE_ACCESS_POINT = "ActiveAccessPoint"
PRP_WIFI_WIRELESS_CAPABILITIES = "WirelessCapabilities"
+PRP_WIFI_LAST_SCAN = "LastScan"
class WifiDevice(Device):
def __init__(self, iface, mac = None, ident = None):
@@ -926,6 +927,7 @@ class WifiDevice(Device):
PRP_WIFI_WIRELESS_CAPABILITIES: dbus.UInt32(0xFF),
PRP_WIFI_ACCESS_POINTS: ExportedObj.to_path_array(self.aps),
PRP_WIFI_ACTIVE_ACCESS_POINT: ExportedObj.to_path(None),
+ PRP_WIFI_LAST_SCAN: dbus.Int32(0x70000000),
}
self.dbus_interface_add(IFACE_WIFI, props, WifiDevice.PropertiesChanged)