]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Use NL80211_BSS_LAST_SEEN_BOOTTIME if available
authorJouni Malinen <j@w1.fi>
Mon, 16 Oct 2017 21:04:52 +0000 (00:04 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 16 Oct 2017 21:07:17 +0000 (00:07 +0300)
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 <j@w1.fi>
src/drivers/driver_nl80211_scan.c

index 10517e4030cdc6f879fa26aba968f1057e943e99..984485b006ffca3820c03b73ecc9cc0e2cfc3cee 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include "includes.h"
+#include <time.h>
 #include <netlink/genl/genl.h>
 
 #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) {