aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/util.c
diff options
context:
space:
mode:
authorThomas Pedersen <thomas@cozybit.com>2012-11-13 13:46:27 -0500
committerJohannes Berg <johannes.berg@intel.com>2012-11-13 15:43:55 -0500
commitf4bda337bbb6e245e2a07f344990adeb6a70ff35 (patch)
tree6ccf2bc38fb67098df931ce55eb0905959813864 /net/mac80211/util.c
parent2a91c9f781de209d420d751e43eb43ffe6934803 (diff)
mac80211: support RX_FLAG_MACTIME_END
Allow drivers to indicate their mactime is at RX completion and adjust for this in mac80211. Also rename the existing RX_FLAG_MACTIME_MPDU to RX_FLAG_MACTIME_START to clarify its intent. Based on similar code by Johannes Berg. Signed-off-by: Thomas Pedersen <thomas@cozybit.com> [fix docs, atheros drivers] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/mac80211/util.c')
-rw-r--r--net/mac80211/util.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 4e4f58513673..5bad758abfb3 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -2013,3 +2013,54 @@ u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
2013 return 2; 2013 return 2;
2014 return 1; 2014 return 1;
2015} 2015}
2016
2017/**
2018 * ieee80211_calculate_rx_timestamp - calculate timestamp in frame
2019 * @local: mac80211 hw info struct
2020 * @status: RX status
2021 * @mpdu_len: total MPDU length (including FCS)
2022 * @mpdu_offset: offset into MPDU to calculate timestamp at
2023 *
2024 * This function calculates the RX timestamp at the given MPDU offset, taking
2025 * into account what the RX timestamp was. An offset of 0 will just normalize
2026 * the timestamp to TSF at beginning of MPDU reception.
2027 */
2028u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
2029 struct ieee80211_rx_status *status,
2030 unsigned int mpdu_len,
2031 unsigned int mpdu_offset)
2032{
2033 u64 ts = status->mactime;
2034 struct rate_info ri;
2035 u16 rate;
2036
2037 if (WARN_ON(!ieee80211_have_rx_timestamp(status)))
2038 return 0;
2039
2040 memset(&ri, 0, sizeof(ri));
2041
2042 /* Fill cfg80211 rate info */
2043 if (status->flag & RX_FLAG_HT) {
2044 ri.mcs = status->rate_idx;
2045 ri.flags |= RATE_INFO_FLAGS_MCS;
2046 if (status->flag & RX_FLAG_40MHZ)
2047 ri.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
2048 if (status->flag & RX_FLAG_SHORT_GI)
2049 ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
2050 } else {
2051 struct ieee80211_supported_band *sband;
2052
2053 sband = local->hw.wiphy->bands[status->band];
2054 ri.legacy = sband->bitrates[status->rate_idx].bitrate;
2055 }
2056
2057 rate = cfg80211_calculate_bitrate(&ri);
2058
2059 /* rewind from end of MPDU */
2060 if (status->flag & RX_FLAG_MACTIME_END)
2061 ts -= mpdu_len * 8 * 10 / rate;
2062
2063 ts += mpdu_offset * 8 * 10 / rate;
2064
2065 return ts;
2066}