mac80211: sync dtim_count to TSF
authorThomas Pedersen <twpedersen@gmail.com>
Thu, 19 Dec 2013 18:25:15 +0000 (10:25 -0800)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 6 Jan 2014 19:10:47 +0000 (20:10 +0100)
On starting a mesh or AP BSS, the interface dtim_count
countdown should match that of the driver TSF.

Signed-off-by: Thomas Pedersen <twpedersen@gmail.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/cfg.c
net/mac80211/debugfs_netdev.c
net/mac80211/ieee80211_i.h
net/mac80211/mesh.c
net/mac80211/util.c

index fd1020e791d836ae1c8d666c6820bc9c7eb3aff2..f9ae9b85d4c1bf297f3008e0f0693d6305c69824 100644 (file)
@@ -1035,6 +1035,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
                return err;
        }
 
+       ieee80211_recalc_dtim(local, sdata);
        ieee80211_bss_info_change_notify(sdata, changed);
 
        netif_carrier_on(dev);
index b62cbe82954c6e7f674e1580487f6f39a43a3642..ebf80f3abd83fe1af18ce94863a0fe1dd090ea19 100644 (file)
@@ -474,6 +474,7 @@ static ssize_t ieee80211_if_parse_tsf(
                }
        }
 
+       ieee80211_recalc_dtim(local, sdata);
        return buflen;
 }
 IEEE80211_IF_FILE_RW(tsf);
index 953b9e29454707b39460fb761a5ddba3e9377344..3701930c66493af53461a4f0c1849ad26450e092 100644 (file)
@@ -1800,6 +1800,8 @@ ieee80211_cs_get(struct ieee80211_local *local, u32 cipher,
 int ieee80211_cs_headroom(struct ieee80211_local *local,
                          struct cfg80211_crypto_settings *crypto,
                          enum nl80211_iftype iftype);
+void ieee80211_recalc_dtim(struct ieee80211_local *local,
+                          struct ieee80211_sub_if_data *sdata);
 
 #ifdef CONFIG_MAC80211_NOINLINE
 #define debug_noinline noinline
index 5a74b249ba35d0f47a499b08d4d0f04d75d4a5ec..5b919cab1de0015cd833d04b840c9d7cdc69e96b 100644 (file)
@@ -807,6 +807,7 @@ int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
                return -ENOMEM;
        }
 
+       ieee80211_recalc_dtim(local, sdata);
        ieee80211_bss_info_change_notify(sdata, changed);
 
        netif_carrier_on(sdata->dev);
index df00f1978a77574857a9e8cf5c37cad66ce3e487..676dc0967f377f1251a761bf2dff0c35c8e92346 100644 (file)
@@ -2734,3 +2734,44 @@ int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr,
        return ret;
 }
 EXPORT_SYMBOL(ieee80211_parse_p2p_noa);
+
+void ieee80211_recalc_dtim(struct ieee80211_local *local,
+                          struct ieee80211_sub_if_data *sdata)
+{
+       u64 tsf = drv_get_tsf(local, sdata);
+       u64 dtim_count = 0;
+       u16 beacon_int = sdata->vif.bss_conf.beacon_int * 1024;
+       u8 dtim_period = sdata->vif.bss_conf.dtim_period;
+       struct ps_data *ps;
+       u8 bcns_from_dtim;
+
+       if (tsf == -1ULL || !beacon_int || !dtim_period)
+               return;
+
+       if (sdata->vif.type == NL80211_IFTYPE_AP ||
+           sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
+               if (!sdata->bss)
+                       return;
+
+               ps = &sdata->bss->ps;
+       } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
+               ps = &sdata->u.mesh.ps;
+       } else {
+               return;
+       }
+
+       /*
+        * actually finds last dtim_count, mac80211 will update in
+        * __beacon_add_tim().
+        * dtim_count = dtim_period - (tsf / bcn_int) % dtim_period
+        */
+       do_div(tsf, beacon_int);
+       bcns_from_dtim = do_div(tsf, dtim_period);
+       /* just had a DTIM */
+       if (!bcns_from_dtim)
+               dtim_count = 0;
+       else
+               dtim_count = dtim_period - bcns_from_dtim;
+
+       ps->dtim_count = dtim_count;
+}