From patchwork Thu Dec 19 08:37:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Pedersen X-Patchwork-Id: 3375671 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4EA4C9F344 for ; Thu, 19 Dec 2013 08:39:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E4902061D for ; Thu, 19 Dec 2013 08:39:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 374F82062D for ; Thu, 19 Dec 2013 08:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752741Ab3LSIjV (ORCPT ); Thu, 19 Dec 2013 03:39:21 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:45527 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752700Ab3LSIjS (ORCPT ); Thu, 19 Dec 2013 03:39:18 -0500 Received: by mail-pa0-f42.google.com with SMTP id lj1so877237pab.1 for ; Thu, 19 Dec 2013 00:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zWKGKGiHWJ2mkLivpjZRHJO6qTthp2nWikuvXqzHT3k=; b=pONxSpok3FSgsaIgNkirxnB4Q/MidHTWkcdrcfMrnfvSz5I6dMJfkRUyuW0JiFDhQe /p14wlnR9UAP+y1mSTJFb98td41UivXEgn5L9WSOCheNUAyP0e0uT3ItsOy4IRSYNK4w cOPghAPLkUEwQOgbo33QQETkNMLw+g8ah51h7acvfGiEsexv5enP+nCUPk2ZO6MIk1GL qHSPxGMCQnpl3JHtULLl9P1OVtxcxRCsa8IOVe7GAkm8mSOpN6QY4ziKwJDdR4KVW3dO vmt3cyodnLNcHgCjHie4ExIHvG5umdENKvrgG6ABX2kBzVJ/h0i+/dXOVIPRWmTMFW8J dhYQ== X-Received: by 10.66.65.134 with SMTP id x6mr281150pas.142.1387442357427; Thu, 19 Dec 2013 00:39:17 -0800 (PST) Received: from localhost.localdomain (c-69-181-202-165.hsd1.ca.comcast.net. [69.181.202.165]) by mx.google.com with ESMTPSA id om6sm5406493pbc.43.2013.12.19.00.39.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Dec 2013 00:39:16 -0800 (PST) From: Thomas Pedersen To: Johannes Berg Cc: linux-wireless , open80211s , Thomas Pedersen Subject: [PATCH 2/2] mac80211: sync dtim_count to TSF Date: Thu, 19 Dec 2013 00:37:59 -0800 Message-Id: <1387442279-1526-2-git-send-email-twpedersen@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1387442279-1526-1-git-send-email-twpedersen@gmail.com> References: <1387442279-1526-1-git-send-email-twpedersen@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thomas Pedersen On starting a mesh, ad-hoc, or AP BSS, the interface dtim_count countdown should match that of the driver TSF. Signed-off-by: Thomas Pedersen --- v2: adjust dtim_count instead of setting TSF=0 (Sergey) net/mac80211/cfg.c | 2 ++ net/mac80211/debugfs_netdev.c | 1 + net/mac80211/ibss.c | 1 + net/mac80211/ieee80211_i.h | 2 ++ net/mac80211/mesh.c | 1 + net/mac80211/util.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 35 insertions(+) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index ac18528..8211d30 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -951,6 +951,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_ap_settings *params) { struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); + struct ieee80211_local *local = sdata->local; struct beacon_data *old; struct ieee80211_sub_if_data *vlan; u32 changed = BSS_CHANGED_BEACON_INT | @@ -1030,6 +1031,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); diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c index 04b5a14..89160f7 100644 --- a/net/mac80211/debugfs_netdev.c +++ b/net/mac80211/debugfs_netdev.c @@ -468,6 +468,7 @@ static ssize_t ieee80211_if_parse_tsf( } } + ieee80211_recalc_dtim(local, sdata); return buflen; } __IEEE80211_IF_FILE_W(tsf); diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c index d6ba8414..a92c8a9 100644 --- a/net/mac80211/ibss.c +++ b/net/mac80211/ibss.c @@ -369,6 +369,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, return; } + ieee80211_recalc_dtim(local, sdata); ieee80211_bss_info_change_notify(sdata, bss_change); ifibss->state = IEEE80211_IBSS_MLME_JOINED; diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 33ebe08..337fcad 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1794,6 +1794,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 diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c index 5a74b24..5b919ca 100644 --- a/net/mac80211/mesh.c +++ b/net/mac80211/mesh.c @@ -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); diff --git a/net/mac80211/util.c b/net/mac80211/util.c index 656648b..599cf37 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -2588,3 +2588,31 @@ int ieee80211_cs_headroom(struct ieee80211_local *local, return headroom; } + +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; + u8 bcns_from_dtim; + + if (tsf == -1ULL || !beacon_int || !dtim_period) + 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; + + sdata->u.mesh.ps.dtim_count = dtim_count; +}