wifi: mac80211: allow 64-bit radiotap timestamps
authorJohannes Berg <johannes.berg@intel.com>
Wed, 20 Dec 2023 11:41:40 +0000 (13:41 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 21 Dec 2023 19:35:15 +0000 (20:35 +0100)
When reporting the radiotap timestamp, the mactime field is
usually unused, we take the data from the device_timestamp.
However, there can be cases where the radiotap timestamp is
better reported as a 64-bit value, so since the mactime is
free, add a flag to support using the mactime as a 64-bit
radiotap timestamp.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Gregory Greenman <gregory.greenman@intel.com>
Reviewed-by: Benjamin Berg <benjamin.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://msgid.link/20231220133549.00c8b9234f0c.Ie3ce5eae33cce88fa01178e7aea94661ded1ac24@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/mac80211.h
net/mac80211/rx.c

index 941980c7aa214a601282a6203fce9f3f0b5bbcc3..46cc4443021695769fb8af0faadcadbcd030f117 100644 (file)
@@ -1367,6 +1367,11 @@ ieee80211_tx_info_clear_status(struct ieee80211_tx_info *info)
  *     (including FCS) was received.
  * @RX_FLAG_MACTIME_PLCP_START: The timestamp passed in the RX status (@mactime
  *     field) is valid and contains the time the SYNC preamble was received.
+ * @RX_FLAG_MACTIME_IS_RTAP_TS64: The timestamp passed in the RX status @mactime
+ *     is only for use in the radiotap timestamp header, not otherwise a valid
+ *     @mactime value. Note this is a separate flag so that we continue to see
+ *     %RX_FLAG_MACTIME as unset. Also note that in this case the timestamp is
+ *     reported to be 64 bits wide, not just 32.
  * @RX_FLAG_NO_SIGNAL_VAL: The signal strength value is not present.
  *     Valid only for data frames (mainly A-MPDU)
  * @RX_FLAG_AMPDU_DETAILS: A-MPDU details are known, in particular the reference
@@ -1442,7 +1447,7 @@ enum mac80211_rx_flags {
        RX_FLAG_IV_STRIPPED             = BIT(4),
        RX_FLAG_FAILED_FCS_CRC          = BIT(5),
        RX_FLAG_FAILED_PLCP_CRC         = BIT(6),
-       /* one free bit at 7 */
+       RX_FLAG_MACTIME_IS_RTAP_TS64    = BIT(7),
        RX_FLAG_NO_SIGNAL_VAL           = BIT(8),
        RX_FLAG_AMPDU_DETAILS           = BIT(9),
        RX_FLAG_PN_VALIDATED            = BIT(10),
index bbfdcb0ade72c03f96c3a36ea2c19fadc86bbd64..a57c8272c1dc45f53603f51020420d1447148f76 100644 (file)
@@ -566,7 +566,8 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
 
        if (local->hw.radiotap_timestamp.units_pos >= 0) {
                u16 accuracy = 0;
-               u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
+               u8 flags;
+               u64 ts;
 
                rthdr->it_present |=
                        cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
@@ -575,7 +576,15 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
                while ((pos - (u8 *)rthdr) & 7)
                        pos++;
 
-               put_unaligned_le64(status->device_timestamp, pos);
+               if (status->flag & RX_FLAG_MACTIME_IS_RTAP_TS64) {
+                       flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_64BIT;
+                       ts = status->mactime;
+               } else {
+                       flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
+                       ts = status->device_timestamp;
+               }
+
+               put_unaligned_le64(ts, pos);
                pos += sizeof(u64);
 
                if (local->hw.radiotap_timestamp.accuracy >= 0) {