From 4da2fbfca2bdce3021e13cebb0a7a2685a6f3d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Wed, 23 Jul 2025 20:06:11 +0200 Subject: [PATCH] network: Fix alignment for TSFT radiotap subfield --- src/network/utils/radiotap-header.cc | 24 ++++++++++++++++++++---- src/network/utils/radiotap-header.h | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/network/utils/radiotap-header.cc b/src/network/utils/radiotap-header.cc index 33fe6ae89..52e98c225 100644 --- a/src/network/utils/radiotap-header.cc +++ b/src/network/utils/radiotap-header.cc @@ -72,7 +72,7 @@ RadiotapHeader::Serialize(Buffer::Iterator start) const // if (m_present & RADIOTAP_TSFT) // bit 0 { - start.WriteU64(m_tsft); + SerializeTsft(start); } // @@ -307,8 +307,7 @@ RadiotapHeader::Deserialize(Buffer::Iterator start) // if (m_present & RADIOTAP_TSFT) // bit 0 { - m_tsft = start.ReadU64(); - bytesRead += 8; + bytesRead += DeserializeTsft(start, bytesRead); } // @@ -575,14 +574,31 @@ RadiotapHeader::SetTsft(uint64_t value) NS_LOG_FUNCTION(this << value); NS_ASSERT_MSG(!(m_present & RADIOTAP_TSFT), "TSFT radiotap field already present"); + m_tsftPad = ((8 - m_length % 8) % 8); m_present |= RADIOTAP_TSFT; - m_length += 8; + m_length += 8 + m_tsftPad; m_tsft = value; NS_LOG_LOGIC(this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); } +void +RadiotapHeader::SerializeTsft(Buffer::Iterator& start) const +{ + start.WriteU8(0, m_tsftPad); + start.WriteU64(m_tsft); +} + +uint32_t +RadiotapHeader::DeserializeTsft(Buffer::Iterator start, uint32_t bytesRead) +{ + m_tsftPad = ((8 - bytesRead % 8) % 8); + start.Next(m_tsftPad); + m_tsft = start.ReadU64(); + return sizeof(m_tsft) + m_tsftPad; +} + void RadiotapHeader::SetFrameFlags(uint8_t flags) { diff --git a/src/network/utils/radiotap-header.h b/src/network/utils/radiotap-header.h index 94e214e16..501b81130 100644 --- a/src/network/utils/radiotap-header.h +++ b/src/network/utils/radiotap-header.h @@ -773,6 +773,23 @@ class RadiotapHeader : public Header void SetEhtFields(const EhtFields& ehtFields); private: + /** + * Serialize the TSFT radiotap header. + * + * @param start An iterator which points to where the header should be written. + */ + void SerializeTsft(Buffer::Iterator& start) const; + + /** + * Deserialize the TSFT radiotap header. + * + * @param start An iterator which points to where the header should be read. + * @param bytesRead the number of bytes already read. + + * @returns The number of bytes read. + */ + uint32_t DeserializeTsft(Buffer::Iterator start, uint32_t bytesRead); + /** * Serialize the Channel radiotap header. * @@ -1035,8 +1052,9 @@ class RadiotapHeader : public Header uint32_t m_present{0}; //!< bits describing which fields follow header std::optional m_presentExt{}; //!< optional extended present bitmask - uint64_t m_tsft{0}; //!< Time Synchronization Function Timer (when the first bit of the MPDU - //!< arrived at the MAC) + uint8_t m_tsftPad{0}; //!< TSFT padding. + uint64_t m_tsft{0}; //!< Time Synchronization Function Timer (when the first bit of the MPDU + //!< arrived at the MAC) uint8_t m_flags{FRAME_FLAG_NONE}; //!< Properties of transmitted and received frames.