From patchwork Wed Jan 2 22:55:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Pedersen X-Patchwork-Id: 1925611 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 4D6C1DF230 for ; Wed, 2 Jan 2013 22:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752764Ab3ABWz5 (ORCPT ); Wed, 2 Jan 2013 17:55:57 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:64116 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752635Ab3ABWz4 (ORCPT ); Wed, 2 Jan 2013 17:55:56 -0500 Received: by mail-pa0-f45.google.com with SMTP id bg2so8224131pad.4 for ; Wed, 02 Jan 2013 14:55:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=CcSI8dKD3Dt6lDMY1pCIZMrnZM+BghYI8GNvx8pO60M=; b=mOuj76tMIzXpqwJrMJq7vbRbhSQR5ZeU9lJt3UmeXYXAjhrLnhS/xhcaD+VHxAGjE9 5t09ctlGKuFDdXRexFJ5gIonUkD0geWcrejiKQrjZ3a3uw6QQMXhB6tU2J6BoL88C1wn WygtMpD1sdmq2QrytDWSrLJOcRD05XU/qQ8Z1/0Ye63rTD1EFIb+0rKLfTbneRMWxRn6 tmDC/Rfi7RlP5gRvKcEBdQtQc5VBvZSDxm4VeZjXcxM6QWuQcxS3lZ7WGj5oN9q1CiK7 NjEja8whjAjM03+30o3/ckxyarEhqb0LXnVn2YEjlV+59cr62ooidY+a5YSgj8ULAebC OP5g== X-Received: by 10.68.143.41 with SMTP id sb9mr148671644pbb.50.1357167355982; Wed, 02 Jan 2013 14:55:55 -0800 (PST) Received: from cable.lan (70-35-43-50.static.wiline.com. [70.35.43.50]) by mx.google.com with ESMTPS id gl9sm29119358pbc.51.2013.01.02.14.55.53 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 02 Jan 2013 14:55:54 -0800 (PST) From: Thomas Pedersen To: linville@tuxdriver.org Cc: j@w1.fi, linux-wireless@vger.kernel.org, johannes@sipsolutions.net, devel@lists.open80211s.org, Thomas Pedersen Subject: [PATCH v2 3/4] mac80211_hwsim: fix beacon timing Date: Wed, 2 Jan 2013 14:55:18 -0800 Message-Id: <1357167319-13338-3-git-send-email-thomas@cozybit.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357167319-13338-1-git-send-email-thomas@cozybit.com> References: <1357167319-13338-1-git-send-email-thomas@cozybit.com> X-Gm-Message-State: ALoCoQn0HpMnQLkyPOQI0oiQlUefEd0lfgZaIGZGFfqw85X4tPtpJ3uQaNu0Z6Zxt/uUEnCtO7iT Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org A beacon period starts at TSF time 0. Spoof this by rounding the starting beacon time to a multiple of the beacon interval, and keep TBTT aligned on TSF adjustment. Signed-off-by: Thomas Pedersen --- drivers/net/wireless/mac80211_hwsim.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c index bccd17c..7b2acdd 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -358,6 +358,7 @@ struct mac80211_hwsim_data { /* difference between this hw's clock and the real clock, in usecs */ s64 tsf_offset; + s64 bcn_delta; }; @@ -424,9 +425,12 @@ static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, { struct mac80211_hwsim_data *data = hw->priv; u64 now = mac80211_hwsim_get_tsf(hw, vif); + u32 bcn_int = data->beacon_int; s64 delta = tsf - now; data->tsf_offset += delta; + /* adjust after beaconing with new timestamp at old TBTT */ + data->bcn_delta = do_div(delta, bcn_int); } static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, @@ -1001,6 +1005,12 @@ mac80211_hwsim_beacon(struct hrtimer *timer) hw, IEEE80211_IFACE_ITER_NORMAL, mac80211_hwsim_beacon_tx, hw); + /* beacon at new TBTT + beacon interval */ + if (data->bcn_delta) { + bcn_int -= data->bcn_delta; + data->bcn_delta = 0; + } + next_bcn = ktime_add(hrtimer_get_expires(timer), ns_to_ktime(bcn_int * 1000)); tasklet_hrtimer_start(ttimer, next_bcn, HRTIMER_MODE_ABS); @@ -1045,8 +1055,12 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed) if (!data->started || !data->beacon_int) tasklet_hrtimer_cancel(&data->beacon_timer); else if (!hrtimer_is_queued(&data->beacon_timer.timer)) { + u64 tsf = mac80211_hwsim_get_tsf(hw, NULL); + u32 bcn_int = data->beacon_int; + u64 until_tbtt = bcn_int - do_div(tsf, bcn_int); + tasklet_hrtimer_start(&data->beacon_timer, - ns_to_ktime(data->beacon_int * 1000), + ns_to_ktime(until_tbtt * 1000), HRTIMER_MODE_REL); } @@ -1106,11 +1120,15 @@ static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw, if (data->started && !hrtimer_is_queued(&data->beacon_timer.timer) && info->enable_beacon) { + u64 tsf, until_tbtt; + u32 bcn_int; if (WARN_ON(!data->beacon_int)) data->beacon_int = 1000 * 1024; + tsf = mac80211_hwsim_get_tsf(hw, vif); + bcn_int = data->beacon_int; + until_tbtt = bcn_int - do_div(tsf, bcn_int); tasklet_hrtimer_start(&data->beacon_timer, - ns_to_ktime(data->beacon_int * - 1000), + ns_to_ktime(until_tbtt * 1000), HRTIMER_MODE_REL); } else if (!info->enable_beacon) tasklet_hrtimer_cancel(&data->beacon_timer);