From patchwork Wed Dec 19 01:37:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Pedersen X-Patchwork-Id: 1894361 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9846E3FCD4 for ; Wed, 19 Dec 2012 02:01:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754612Ab2LSCBg (ORCPT ); Tue, 18 Dec 2012 21:01:36 -0500 Received: from mail-da0-f42.google.com ([209.85.210.42]:52982 "EHLO mail-da0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753999Ab2LSCBf (ORCPT ); Tue, 18 Dec 2012 21:01:35 -0500 Received: by mail-da0-f42.google.com with SMTP id z17so641800dal.15 for ; Tue, 18 Dec 2012 18:01:35 -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=ALV6b/hE4KI7hBUe8zwOLLj6woLACXxPqDQ0SkY2kh4=; b=TKfcZzVBiD0xvhCnetPrxkGhl9cv41aRGB3jj0frcNF3nNq//SbPrUZZexbry/IdUf atRBRcvFQkVDsU/VOc5d9Id/7wus0XTUCvqRUhqNf57RjCYsAdmuXHN5TwTki6Ez1gZ6 zQASU0LiuoaJ+Vh+74XwH30Rk3uMEbRI66P0B9qu1KMJIzleuNrq8tAcG3sxWkBeZz93 dvniO1oGGqIhl+vob7xbJ8kA6qzruygxcS6iw2lq2AxpQjIGbyJAl2jOqnuyv06s6oLa KU5iW6JyxJ50DEIyV0x57jQL/hvU5mxz4gjoK7Gn0Cc1RkpTDmchJo55nKxA6KDc40D3 5LQA== X-Received: by 10.68.217.4 with SMTP id ou4mr12641584pbc.88.1355881049759; Tue, 18 Dec 2012 17:37:29 -0800 (PST) Received: from cable.lan (70-35-43-50.static.wiline.com. [70.35.43.50]) by mx.google.com with ESMTPS id oz9sm2076684pbb.68.2012.12.18.17.37.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 18 Dec 2012 17:37:28 -0800 (PST) From: Thomas Pedersen To: linville@tuxdriver.com Cc: j@wl.fi, jlopex@cozybit.com, linux-wireless@vger.kernel.org, Thomas Pedersen Subject: [PATCH 2/3] mac80211_hwsim: beacon at beacon interval Date: Tue, 18 Dec 2012 17:37:00 -0800 Message-Id: <1355881021-7071-2-git-send-email-thomas@cozybit.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355881021-7071-1-git-send-email-thomas@cozybit.com> References: <1355881021-7071-1-git-send-email-thomas@cozybit.com> X-Gm-Message-State: ALoCoQlw2jG2hxqoArnKZUsWqCvTEtZRJRDttWSHv25UPYNKufEvdT0eTl+Bcq9tgxMucm//WHTi 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. Signed-off-by: Thomas Pedersen --- drivers/net/wireless/mac80211_hwsim.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c index 0a8f37e..764a358 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) {