Skip to content

Commit cb3a8ee

Browse files
Dan Williamslinvjw
authored andcommitted
cfg80211: age scan results on resume
Scanned BSS entries are timestamped with jiffies, which doesn't increment across suspend and hibernate. On resume, every BSS in the scan list looks like it was scanned within the last 10 seconds, irregardless of how long the machine was actually asleep. Age scan results on resume with the time spent during sleep so userspace has a clue how old they really are. Signed-off-by: Dan Williams <dcbw@redhat.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent abd2fdb commit cb3a8ee

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎net/wireless/core.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct cfg80211_registered_device {
4949
struct rb_root bss_tree;
5050
u32 bss_generation;
5151
struct cfg80211_scan_request *scan_req; /* protected by RTNL */
52+
unsigned long suspend_at;
5253

5354
/* must be last because of the way we do wiphy_priv(),
5455
* and it should at least be aligned to NETDEV_ALIGN */
@@ -113,5 +114,7 @@ void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
113114
void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby);
114115

115116
void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
117+
void cfg80211_bss_age(struct cfg80211_registered_device *dev,
118+
unsigned long age_secs);
116119

117120
#endif /* __NET_WIRELESS_CORE_H */

‎net/wireless/scan.c‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ static void bss_release(struct kref *ref)
6161
kfree(bss);
6262
}
6363

64+
/* must hold dev->bss_lock! */
65+
void cfg80211_bss_age(struct cfg80211_registered_device *dev,
66+
unsigned long age_secs)
67+
{
68+
struct cfg80211_internal_bss *bss;
69+
unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
70+
71+
list_for_each_entry(bss, &dev->bss_list, list) {
72+
bss->ts -= age_jiffies;
73+
}
74+
}
75+
6476
/* must hold dev->bss_lock! */
6577
void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
6678
{
@@ -584,6 +596,15 @@ static void ieee80211_scan_add_ies(struct iw_request_info *info,
584596
}
585597
}
586598

599+
static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
600+
{
601+
unsigned long end = jiffies;
602+
603+
if (end >= start)
604+
return jiffies_to_msecs(end - start);
605+
606+
return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
607+
}
587608

588609
static char *
589610
ieee80211_bss(struct iw_request_info *info,
@@ -763,8 +784,8 @@ ieee80211_bss(struct iw_request_info *info,
763784
&iwe, buf);
764785
memset(&iwe, 0, sizeof(iwe));
765786
iwe.cmd = IWEVCUSTOM;
766-
sprintf(buf, " Last beacon: %dms ago",
767-
jiffies_to_msecs(jiffies - bss->ts));
787+
sprintf(buf, " Last beacon: %ums ago",
788+
elapsed_jiffies_msecs(bss->ts));
768789
iwe.u.data.length = strlen(buf);
769790
current_ev = iwe_stream_add_point(info, current_ev,
770791
end_buf, &iwe, buf);

‎net/wireless/sysfs.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static int wiphy_suspend(struct device *dev, pm_message_t state)
6060
struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
6161
int ret = 0;
6262

63+
rdev->suspend_at = get_seconds();
64+
6365
if (rdev->ops->suspend) {
6466
rtnl_lock();
6567
ret = rdev->ops->suspend(&rdev->wiphy);
@@ -74,6 +76,11 @@ static int wiphy_resume(struct device *dev)
7476
struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
7577
int ret = 0;
7678

79+
/* Age scan results with time spent in suspend */
80+
spin_lock_bh(&rdev->bss_lock);
81+
cfg80211_bss_age(rdev, get_seconds() - rdev->suspend_at);
82+
spin_unlock_bh(&rdev->bss_lock);
83+
7784
if (rdev->ops->resume) {
7885
rtnl_lock();
7986
ret = rdev->ops->resume(&rdev->wiphy);

0 commit comments

Comments
 (0)