From: Jouni Malinen Date: Mon, 16 Oct 2017 21:04:52 +0000 (+0300) Subject: nl80211: Use NL80211_BSS_LAST_SEEN_BOOTTIME if available X-Git-Tag: hostap_2_7~1000 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=006fb845b807f9ef7bcf4b4e90142c424e3b44e7;p=thirdparty%2Fhostap.git nl80211: Use NL80211_BSS_LAST_SEEN_BOOTTIME if available This allows a more accurate scan result age to be fetched than the one available through NL80211_BSS_SEEN_MS_AGO. Signed-off-by: Jouni Malinen --- diff --git a/src/drivers/driver_nl80211_scan.c b/src/drivers/driver_nl80211_scan.c index 10517e403..984485b00 100644 --- a/src/drivers/driver_nl80211_scan.c +++ b/src/drivers/driver_nl80211_scan.c @@ -10,6 +10,7 @@ */ #include "includes.h" +#include #include #include "utils/common.h" @@ -696,6 +697,7 @@ nl80211_parse_bss_info(struct wpa_driver_nl80211_data *drv, [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, [NL80211_BSS_PARENT_TSF] = { .type = NLA_U64 }, [NL80211_BSS_PARENT_BSSID] = { .type = NLA_UNSPEC }, + [NL80211_BSS_LAST_SEEN_BOOTTIME] = { .type = NLA_U64 }, }; struct wpa_scan_res *r; const u8 *ie, *beacon_ie; @@ -759,6 +761,23 @@ nl80211_parse_bss_info(struct wpa_driver_nl80211_data *drv, } if (bss[NL80211_BSS_SEEN_MS_AGO]) r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); + if (bss[NL80211_BSS_LAST_SEEN_BOOTTIME]) { + u64 boottime; + struct timespec ts; + +#ifndef CLOCK_BOOTTIME +#define CLOCK_BOOTTIME 7 +#endif + if (clock_gettime(CLOCK_BOOTTIME, &ts) == 0) { + /* Use more accurate boottime information to update the + * scan result age since the driver reports this and + * CLOCK_BOOTTIME is available. */ + boottime = nla_get_u64( + bss[NL80211_BSS_LAST_SEEN_BOOTTIME]); + r->age = ((u64) ts.tv_sec * 1000000000 + + ts.tv_nsec - boottime) / 1000000; + } + } r->ie_len = ie_len; pos = (u8 *) (r + 1); if (ie) {