mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-01 03:18:06 +02:00
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.
This commit is contained in:
parent
c2932dd7db
commit
c00e17578f
10 changed files with 90 additions and 0 deletions
|
|
@ -96,6 +96,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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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] =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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] =
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue