diff mbox

[v2,2/3] mac80211_hwsim: beacon at beacon interval

Message ID 1356029871-17794-2-git-send-email-thomas@cozybit.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Thomas Pedersen Dec. 20, 2012, 6:57 p.m. UTC
A beacon period starts at TSF time 0. Spoof this by
rounding the starting beacon time to a multiple of the
beacon interval.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
---
 drivers/net/wireless/mac80211_hwsim.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

Comments

Johannes Berg Dec. 21, 2012, 2:36 p.m. UTC | #1
On Thu, 2012-12-20 at 10:57 -0800, Thomas Pedersen wrote:

> +	else if (!hrtimer_is_queued(&data->beacon_timer)) {
> +		u64 tsf = le64_to_cpu(__mac80211_hwsim_get_tsf(data));

This is odd, you haven't even modified __mac80211_hwsim_get_tsf() yet?
Also, there's mac80211_hwsim_get_tsf() (although I'd argue that they
should be the other way around wrt. endianness)

johannes


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thomas Pedersen Dec. 21, 2012, 6:30 p.m. UTC | #2
On Fri, Dec 21, 2012 at 03:36:24PM +0100, Johannes Berg wrote:
> On Thu, 2012-12-20 at 10:57 -0800, Thomas Pedersen wrote:
> 
> > +	else if (!hrtimer_is_queued(&data->beacon_timer)) {
> > +		u64 tsf = le64_to_cpu(__mac80211_hwsim_get_tsf(data));
> 
> This is odd, you haven't even modified __mac80211_hwsim_get_tsf() yet?
> Also, there's mac80211_hwsim_get_tsf() (although I'd argue that they
> should be the other way around wrt. endianness)

You're right, mac80211_hwsim_get_tsf() is less redundant. Also I guess
the timebase changes should go into the first patch.

Thomas
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 84dbfe8..0b38600 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -1044,9 +1044,14 @@  static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
 	data->power_level = conf->power_level;
 	if (!data->started || !ktime_to_ns(data->beacon_int))
 		hrtimer_cancel(&data->beacon_timer);
-	else if (!hrtimer_is_queued(&data->beacon_timer))
-		hrtimer_start(&data->beacon_timer, data->beacon_int,
-			      HRTIMER_MODE_REL);
+	else if (!hrtimer_is_queued(&data->beacon_timer)) {
+		u64 tsf = le64_to_cpu(__mac80211_hwsim_get_tsf(data));
+		u64 bcn_int = ktime_to_ns(data->beacon_int) / 1000;
+		u64 next_tbtt = bcn_int - do_div(tsf, bcn_int);
+
+		hrtimer_start(&data->beacon_timer,
+			      ns_to_ktime(next_tbtt * 1000), HRTIMER_MODE_REL);
+	}
 
 	return 0;
 }
@@ -1099,9 +1104,15 @@  static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
 		data->beacon_int = ns_to_ktime(info->beacon_int * 1024 * 1000);
 		if (WARN_ON(!ktime_to_ns(data->beacon_int)))
 			data->beacon_int = ns_to_ktime(1000 * 1000);
-		if (data->started && !hrtimer_is_queued(&data->beacon_timer))
+		if (data->started && !hrtimer_is_queued(&data->beacon_timer)) {
+			u64 tsf = le64_to_cpu(__mac80211_hwsim_get_tsf(data));
+			u64 bcn_int = ktime_to_ns(data->beacon_int) / 1000;
+			u64 next_tbtt = bcn_int - do_div(tsf, bcn_int);
+
 			hrtimer_start(&data->beacon_timer,
-				      data->beacon_int, HRTIMER_MODE_REL);
+				      ns_to_ktime(next_tbtt * 1000),
+				      HRTIMER_MODE_REL);
+		}
 	}
 
 	if (changed & BSS_CHANGED_ERP_CTS_PROT) {