From 6e7ed5cb554876f83c5ae496ccfd4818228540a5 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sun, 19 Nov 2023 21:19:13 -0800 Subject: [PATCH] [encoding] avoid the use of `using` for `Big/LittleEndian` functions (#9621) This commit refactors the code to eliminate the use of `using` for `BigEndian` or `LittleEndian` functions like `HostSwap` and `ReadUint`. As these functions are frequently used in header files, using the direct namespace enhances code safety by mitigating potential conflicts arising from the order of included headers in the absence of explicit `using` declarations. Generally, avoiding the `using` keyword in headers is considered a recommended practice. Additionally, this commit removes the `Encoding` namespace to shorten the full function names. --- src/core/coap/coap_message.cpp | 6 +- src/core/coap/coap_message.hpp | 6 +- src/core/common/encoding.hpp | 3 +- src/core/common/frame_builder.cpp | 14 +-- src/core/common/frame_data.cpp | 8 +- src/core/common/settings.hpp | 48 ++++----- src/core/common/tlvs.cpp | 4 +- src/core/common/tlvs.hpp | 6 +- src/core/crypto/aes_ccm.cpp | 2 +- src/core/mac/mac_frame.cpp | 31 +++--- src/core/mac/mac_frame.hpp | 31 +++--- src/core/meshcop/dataset.hpp | 4 +- src/core/meshcop/meshcop.cpp | 2 +- src/core/meshcop/meshcop_tlvs.cpp | 2 +- src/core/meshcop/meshcop_tlvs.hpp | 69 ++++++------ src/core/meshcop/timestamp.hpp | 20 ++-- src/core/net/checksum.cpp | 2 +- src/core/net/dhcp6.hpp | 64 ++++++----- src/core/net/dns_client.cpp | 11 +- src/core/net/dns_dso.hpp | 23 ++-- src/core/net/dns_types.cpp | 6 +- src/core/net/dns_types.hpp | 100 +++++++++--------- src/core/net/icmp6.hpp | 14 ++- src/core/net/ip4_types.cpp | 2 +- src/core/net/ip4_types.hpp | 27 +++-- src/core/net/ip6.cpp | 4 +- src/core/net/ip6.hpp | 3 - src/core/net/ip6_address.cpp | 33 +++--- src/core/net/ip6_address.hpp | 10 +- src/core/net/ip6_headers.hpp | 42 ++++---- src/core/net/ip6_mpl.hpp | 4 +- src/core/net/nd6.hpp | 24 ++--- src/core/net/sntp_client.hpp | 76 ++++++++----- src/core/net/tcp6.cpp | 35 +++--- src/core/net/tcp6.hpp | 16 +-- src/core/net/udp6.hpp | 16 +-- src/core/radio/trel_link.cpp | 2 +- src/core/radio/trel_packet.hpp | 8 +- src/core/thread/key_manager.cpp | 4 +- src/core/thread/link_metrics_tlvs.hpp | 6 +- src/core/thread/lowpan.cpp | 23 ++-- src/core/thread/lowpan.hpp | 10 +- src/core/thread/mle.cpp | 10 +- src/core/thread/mle.hpp | 8 +- src/core/thread/mle_tlvs.hpp | 25 ++--- src/core/thread/network_data_leader.cpp | 2 +- src/core/thread/network_data_service.cpp | 2 +- src/core/thread/network_data_service.hpp | 19 ++-- src/core/thread/network_data_tlvs.cpp | 2 +- src/core/thread/network_data_tlvs.hpp | 37 +++---- src/core/thread/network_diagnostic_tlvs.cpp | 96 ++++++++--------- src/core/thread/network_diagnostic_tlvs.hpp | 83 +++++++-------- src/core/thread/thread_tlvs.hpp | 3 - src/core/utils/ping_sender.cpp | 6 +- src/lib/spinel/multi_frame_buffer.hpp | 14 +-- src/lib/spinel/spi_frame.hpp | 11 +- src/posix/platform/settings.cpp | 2 +- tests/unit/test_checksum.cpp | 10 +- tests/unit/test_ip4_header.cpp | 8 +- tests/unit/test_ip6_header.cpp | 4 +- tests/unit/test_ip_address.cpp | 1 - tests/unit/test_multicast_listeners_table.cpp | 2 +- 62 files changed, 559 insertions(+), 607 deletions(-) diff --git a/src/core/coap/coap_message.cpp b/src/core/coap/coap_message.cpp index 18d2ad30f44..cbf5448138a 100644 --- a/src/core/coap/coap_message.cpp +++ b/src/core/coap/coap_message.cpp @@ -139,7 +139,7 @@ uint8_t Message::WriteExtendedOptionField(uint16_t aValue, uint8_t *&aBuffer) else { rval = kOption2ByteExtension; - Encoding::BigEndian::WriteUint16(aValue - kOption2ByteExtensionOffset, aBuffer); + BigEndian::WriteUint16(aValue - kOption2ByteExtensionOffset, aBuffer); aBuffer += sizeof(uint16_t); } @@ -183,7 +183,7 @@ Error Message::AppendUintOption(uint16_t aNumber, uint32_t aValue) const uint8_t *value = &buffer[0]; uint16_t length = sizeof(uint32_t); - Encoding::BigEndian::WriteUint32(aValue, buffer); + BigEndian::WriteUint32(aValue, buffer); while ((length > 0) && (value[0] == 0)) { @@ -592,7 +592,7 @@ Error Option::Iterator::ReadExtendedOptionField(uint16_t &aValue) uint16_t value16; SuccessOrExit(error = Read(sizeof(uint16_t), &value16)); - value16 = Encoding::BigEndian::HostSwap16(value16); + value16 = BigEndian::HostSwap16(value16); aValue = value16 + Message::kOption2ByteExtensionOffset; } else diff --git a/src/core/coap/coap_message.hpp b/src/core/coap/coap_message.hpp index f7910663ba2..789c91939ad 100644 --- a/src/core/coap/coap_message.hpp +++ b/src/core/coap/coap_message.hpp @@ -59,8 +59,6 @@ namespace ot { */ namespace Coap { -using ot::Encoding::BigEndian::HostSwap16; - /** * @addtogroup core-coap * @@ -315,7 +313,7 @@ class Message : public ot::Message * @returns The Message ID value. * */ - uint16_t GetMessageId(void) const { return HostSwap16(GetHelpData().mHeader.mMessageId); } + uint16_t GetMessageId(void) const { return BigEndian::HostSwap16(GetHelpData().mHeader.mMessageId); } /** * Sets the Message ID value. @@ -323,7 +321,7 @@ class Message : public ot::Message * @param[in] aMessageId The Message ID value. * */ - void SetMessageId(uint16_t aMessageId) { GetHelpData().mHeader.mMessageId = HostSwap16(aMessageId); } + void SetMessageId(uint16_t aMessageId) { GetHelpData().mHeader.mMessageId = BigEndian::HostSwap16(aMessageId); } /** * Returns the Token length. diff --git a/src/core/common/encoding.hpp b/src/core/common/encoding.hpp index f8ee910ca4d..9813385134d 100644 --- a/src/core/common/encoding.hpp +++ b/src/core/common/encoding.hpp @@ -48,7 +48,6 @@ #include namespace ot { -namespace Encoding { inline uint16_t Swap16(uint16_t v) { return (((v & 0x00ffU) << 8) & 0xff00) | (((v & 0xff00U) >> 8) & 0x00ff); } @@ -380,7 +379,7 @@ inline void WriteUint64(uint64_t aValue, uint8_t *aBuffer) } } // namespace LittleEndian -} // namespace Encoding + } // namespace ot #endif // ENCODING_HPP_ diff --git a/src/core/common/frame_builder.cpp b/src/core/common/frame_builder.cpp index 88247ca6720..abc647819c6 100644 --- a/src/core/common/frame_builder.cpp +++ b/src/core/common/frame_builder.cpp @@ -54,24 +54,18 @@ void FrameBuilder::Init(void *aBuffer, uint16_t aLength) Error FrameBuilder::AppendUint8(uint8_t aUint8) { return Append(aUint8); } -Error FrameBuilder::AppendBigEndianUint16(uint16_t aUint16) -{ - return Append(Encoding::BigEndian::HostSwap16(aUint16)); -} +Error FrameBuilder::AppendBigEndianUint16(uint16_t aUint16) { return Append(BigEndian::HostSwap16(aUint16)); } -Error FrameBuilder::AppendBigEndianUint32(uint32_t aUint32) -{ - return Append(Encoding::BigEndian::HostSwap32(aUint32)); -} +Error FrameBuilder::AppendBigEndianUint32(uint32_t aUint32) { return Append(BigEndian::HostSwap32(aUint32)); } Error FrameBuilder::AppendLittleEndianUint16(uint16_t aUint16) { - return Append(Encoding::LittleEndian::HostSwap16(aUint16)); + return Append(LittleEndian::HostSwap16(aUint16)); } Error FrameBuilder::AppendLittleEndianUint32(uint32_t aUint32) { - return Append(Encoding::LittleEndian::HostSwap32(aUint32)); + return Append(LittleEndian::HostSwap32(aUint32)); } Error FrameBuilder::AppendBytes(const void *aBuffer, uint16_t aLength) diff --git a/src/core/common/frame_data.cpp b/src/core/common/frame_data.cpp index 04d2aa94c07..a9c390003ba 100644 --- a/src/core/common/frame_data.cpp +++ b/src/core/common/frame_data.cpp @@ -45,7 +45,7 @@ Error FrameData::ReadBigEndianUint16(uint16_t &aUint16) Error error; SuccessOrExit(error = ReadBytes(&aUint16, sizeof(uint16_t))); - aUint16 = Encoding::BigEndian::HostSwap16(aUint16); + aUint16 = BigEndian::HostSwap16(aUint16); exit: return error; @@ -56,7 +56,7 @@ Error FrameData::ReadBigEndianUint32(uint32_t &aUint32) Error error; SuccessOrExit(error = ReadBytes(&aUint32, sizeof(uint32_t))); - aUint32 = Encoding::BigEndian::HostSwap32(aUint32); + aUint32 = BigEndian::HostSwap32(aUint32); exit: return error; @@ -67,7 +67,7 @@ Error FrameData::ReadLittleEndianUint16(uint16_t &aUint16) Error error; SuccessOrExit(error = ReadBytes(&aUint16, sizeof(uint16_t))); - aUint16 = Encoding::LittleEndian::HostSwap16(aUint16); + aUint16 = LittleEndian::HostSwap16(aUint16); exit: return error; @@ -78,7 +78,7 @@ Error FrameData::ReadLittleEndianUint32(uint32_t &aUint32) Error error; SuccessOrExit(error = ReadBytes(&aUint32, sizeof(uint32_t))); - aUint32 = Encoding::LittleEndian::HostSwap32(aUint32); + aUint32 = LittleEndian::HostSwap32(aUint32); exit: return error; diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index f7f538136e1..199eb9fe037 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -190,7 +190,7 @@ class SettingsBase : public InstanceLocator * @returns The RLOC16. * */ - uint16_t GetRloc16(void) const { return Encoding::LittleEndian::HostSwap16(mRloc16); } + uint16_t GetRloc16(void) const { return LittleEndian::HostSwap16(mRloc16); } /** * Sets the RLOC16. @@ -198,7 +198,7 @@ class SettingsBase : public InstanceLocator * @param[in] aRloc16 The RLOC16. * */ - void SetRloc16(uint16_t aRloc16) { mRloc16 = Encoding::LittleEndian::HostSwap16(aRloc16); } + void SetRloc16(uint16_t aRloc16) { mRloc16 = LittleEndian::HostSwap16(aRloc16); } /** * Returns the key sequence. @@ -206,7 +206,7 @@ class SettingsBase : public InstanceLocator * @returns The key sequence. * */ - uint32_t GetKeySequence(void) const { return Encoding::LittleEndian::HostSwap32(mKeySequence); } + uint32_t GetKeySequence(void) const { return LittleEndian::HostSwap32(mKeySequence); } /** * Sets the key sequence. @@ -214,7 +214,7 @@ class SettingsBase : public InstanceLocator * @param[in] aKeySequence The key sequence. * */ - void SetKeySequence(uint32_t aKeySequence) { mKeySequence = Encoding::LittleEndian::HostSwap32(aKeySequence); } + void SetKeySequence(uint32_t aKeySequence) { mKeySequence = LittleEndian::HostSwap32(aKeySequence); } /** * Returns the MLE frame counter. @@ -222,7 +222,7 @@ class SettingsBase : public InstanceLocator * @returns The MLE frame counter. * */ - uint32_t GetMleFrameCounter(void) const { return Encoding::LittleEndian::HostSwap32(mMleFrameCounter); } + uint32_t GetMleFrameCounter(void) const { return LittleEndian::HostSwap32(mMleFrameCounter); } /** * Sets the MLE frame counter. @@ -232,7 +232,7 @@ class SettingsBase : public InstanceLocator */ void SetMleFrameCounter(uint32_t aMleFrameCounter) { - mMleFrameCounter = Encoding::LittleEndian::HostSwap32(aMleFrameCounter); + mMleFrameCounter = LittleEndian::HostSwap32(aMleFrameCounter); } /** @@ -241,7 +241,7 @@ class SettingsBase : public InstanceLocator * @returns The MAC frame counter. * */ - uint32_t GetMacFrameCounter(void) const { return Encoding::LittleEndian::HostSwap32(mMacFrameCounter); } + uint32_t GetMacFrameCounter(void) const { return LittleEndian::HostSwap32(mMacFrameCounter); } /** * Sets the MAC frame counter. @@ -251,7 +251,7 @@ class SettingsBase : public InstanceLocator */ void SetMacFrameCounter(uint32_t aMacFrameCounter) { - mMacFrameCounter = Encoding::LittleEndian::HostSwap32(aMacFrameCounter); + mMacFrameCounter = LittleEndian::HostSwap32(aMacFrameCounter); } /** @@ -260,7 +260,7 @@ class SettingsBase : public InstanceLocator * @returns The previous partition ID. * */ - uint32_t GetPreviousPartitionId(void) const { return Encoding::LittleEndian::HostSwap32(mPreviousPartitionId); } + uint32_t GetPreviousPartitionId(void) const { return LittleEndian::HostSwap32(mPreviousPartitionId); } /** * Sets the previous partition id. @@ -270,7 +270,7 @@ class SettingsBase : public InstanceLocator */ void SetPreviousPartitionId(uint32_t aPreviousPartitionId) { - mPreviousPartitionId = Encoding::LittleEndian::HostSwap32(aPreviousPartitionId); + mPreviousPartitionId = LittleEndian::HostSwap32(aPreviousPartitionId); } /** @@ -311,7 +311,7 @@ class SettingsBase : public InstanceLocator * @returns The Thread version. * */ - uint16_t GetVersion(void) const { return Encoding::LittleEndian::HostSwap16(mVersion); } + uint16_t GetVersion(void) const { return LittleEndian::HostSwap16(mVersion); } /** * Sets the Thread version. @@ -319,7 +319,7 @@ class SettingsBase : public InstanceLocator * @param[in] aVersion The Thread version. * */ - void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); } + void SetVersion(uint16_t aVersion) { mVersion = LittleEndian::HostSwap16(aVersion); } private: void Log(Action aAction) const; @@ -381,7 +381,7 @@ class SettingsBase : public InstanceLocator * @returns The Thread version. * */ - uint16_t GetVersion(void) const { return Encoding::LittleEndian::HostSwap16(mVersion); } + uint16_t GetVersion(void) const { return LittleEndian::HostSwap16(mVersion); } /** * Sets the Thread version. @@ -389,7 +389,7 @@ class SettingsBase : public InstanceLocator * @param[in] aVersion The Thread version. * */ - void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); } + void SetVersion(uint16_t aVersion) { mVersion = LittleEndian::HostSwap16(aVersion); } private: void Log(Action aAction) const; @@ -443,7 +443,7 @@ class SettingsBase : public InstanceLocator * @returns The child timeout. * */ - uint32_t GetTimeout(void) const { return Encoding::LittleEndian::HostSwap32(mTimeout); } + uint32_t GetTimeout(void) const { return LittleEndian::HostSwap32(mTimeout); } /** * Sets the child timeout. @@ -451,7 +451,7 @@ class SettingsBase : public InstanceLocator * @param[in] aTimeout The child timeout. * */ - void SetTimeout(uint32_t aTimeout) { mTimeout = Encoding::LittleEndian::HostSwap32(aTimeout); } + void SetTimeout(uint32_t aTimeout) { mTimeout = LittleEndian::HostSwap32(aTimeout); } /** * Returns the RLOC16. @@ -459,7 +459,7 @@ class SettingsBase : public InstanceLocator * @returns The RLOC16. * */ - uint16_t GetRloc16(void) const { return Encoding::LittleEndian::HostSwap16(mRloc16); } + uint16_t GetRloc16(void) const { return LittleEndian::HostSwap16(mRloc16); } /** * Sets the RLOC16. @@ -467,7 +467,7 @@ class SettingsBase : public InstanceLocator * @param[in] aRloc16 The RLOC16. * */ - void SetRloc16(uint16_t aRloc16) { mRloc16 = Encoding::LittleEndian::HostSwap16(aRloc16); } + void SetRloc16(uint16_t aRloc16) { mRloc16 = LittleEndian::HostSwap16(aRloc16); } /** * Returns the Thread device mode. @@ -491,7 +491,7 @@ class SettingsBase : public InstanceLocator * @returns The Thread version. * */ - uint16_t GetVersion(void) const { return Encoding::LittleEndian::HostSwap16(mVersion); } + uint16_t GetVersion(void) const { return LittleEndian::HostSwap16(mVersion); } /** * Sets the Thread version. @@ -499,7 +499,7 @@ class SettingsBase : public InstanceLocator * @param[in] aVersion The Thread version. * */ - void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); } + void SetVersion(uint16_t aVersion) { mVersion = LittleEndian::HostSwap16(aVersion); } private: void Log(Action aAction) const; @@ -705,7 +705,7 @@ class SettingsBase : public InstanceLocator * @returns The server port number. * */ - uint16_t GetServerPort(void) const { return Encoding::LittleEndian::HostSwap16(mServerPort); } + uint16_t GetServerPort(void) const { return LittleEndian::HostSwap16(mServerPort); } /** * Sets the server port number. @@ -713,7 +713,7 @@ class SettingsBase : public InstanceLocator * @param[in] aPort The server port number. * */ - void SetServerPort(uint16_t aPort) { mServerPort = Encoding::LittleEndian::HostSwap16(aPort); } + void SetServerPort(uint16_t aPort) { mServerPort = LittleEndian::HostSwap16(aPort); } private: void Log(Action aAction) const; @@ -750,7 +750,7 @@ class SettingsBase : public InstanceLocator * @returns The server port number. * */ - uint16_t GetPort(void) const { return Encoding::LittleEndian::HostSwap16(mPort); } + uint16_t GetPort(void) const { return LittleEndian::HostSwap16(mPort); } /** * Sets the server port number. @@ -758,7 +758,7 @@ class SettingsBase : public InstanceLocator * @param[in] aPort The server port number. * */ - void SetPort(uint16_t aPort) { mPort = Encoding::LittleEndian::HostSwap16(aPort); } + void SetPort(uint16_t aPort) { mPort = LittleEndian::HostSwap16(aPort); } private: void Log(Action aAction) const; diff --git a/src/core/common/tlvs.cpp b/src/core/common/tlvs.cpp index 2620b24e84d..04756d24afd 100644 --- a/src/core/common/tlvs.cpp +++ b/src/core/common/tlvs.cpp @@ -216,7 +216,7 @@ template Error Tlv::ReadUintTlv(const Message &aMessage, uin Error error; SuccessOrExit(error = ReadTlvValue(aMessage, aOffset, &aValue, sizeof(aValue))); - aValue = Encoding::BigEndian::HostSwap(aValue); + aValue = BigEndian::HostSwap(aValue); exit: return error; @@ -294,7 +294,7 @@ Error Tlv::AppendStringTlv(Message &aMessage, uint8_t aType, uint8_t aMaxStringL template Error Tlv::AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue) { - UintType value = Encoding::BigEndian::HostSwap(aValue); + UintType value = BigEndian::HostSwap(aValue); return AppendTlv(aMessage, aType, &value, sizeof(UintType)); } diff --git a/src/core/common/tlvs.hpp b/src/core/common/tlvs.hpp index 9af6f4d40cc..e72bf46ab94 100644 --- a/src/core/common/tlvs.hpp +++ b/src/core/common/tlvs.hpp @@ -46,8 +46,6 @@ namespace ot { -using ot::Encoding::BigEndian::HostSwap16; - class Message; /** @@ -641,7 +639,7 @@ class ExtendedTlv : public Tlv * Returns the Length value. * */ - uint16_t GetLength(void) const { return HostSwap16(mLength); } + uint16_t GetLength(void) const { return BigEndian::HostSwap16(mLength); } /** * Sets the Length value. @@ -652,7 +650,7 @@ class ExtendedTlv : public Tlv void SetLength(uint16_t aLength) { Tlv::SetLength(kExtendedLength); - mLength = HostSwap16(aLength); + mLength = BigEndian::HostSwap16(aLength); } private: diff --git a/src/core/crypto/aes_ccm.cpp b/src/core/crypto/aes_ccm.cpp index 8ca66aa4e19..9d32d1cb49d 100644 --- a/src/core/crypto/aes_ccm.cpp +++ b/src/core/crypto/aes_ccm.cpp @@ -283,7 +283,7 @@ void AesCcm::GenerateNonce(const Mac::ExtAddress &aAddress, memcpy(aNonce, aAddress.m8, sizeof(Mac::ExtAddress)); aNonce += sizeof(Mac::ExtAddress); - Encoding::BigEndian::WriteUint32(aFrameCounter, aNonce); + BigEndian::WriteUint32(aFrameCounter, aNonce); aNonce += sizeof(uint32_t); aNonce[0] = aSecurityLevel; diff --git a/src/core/mac/mac_frame.cpp b/src/core/mac/mac_frame.cpp index 3e26a6ba8a3..47debefb3da 100644 --- a/src/core/mac/mac_frame.cpp +++ b/src/core/mac/mac_frame.cpp @@ -47,11 +47,6 @@ namespace ot { namespace Mac { -using ot::Encoding::LittleEndian::ReadUint16; -using ot::Encoding::LittleEndian::ReadUint32; -using ot::Encoding::LittleEndian::WriteUint16; -using ot::Encoding::LittleEndian::WriteUint32; - void HeaderIe::Init(uint16_t aId, uint8_t aLen) { Init(); @@ -237,9 +232,9 @@ void Frame::InitMacHeader(Type aType, mLength += GetFcsSize(); } -uint16_t Frame::GetFrameControlField(void) const { return ReadUint16(mPsdu); } +uint16_t Frame::GetFrameControlField(void) const { return LittleEndian::ReadUint16(mPsdu); } -void Frame::SetFrameControlField(uint16_t aFcf) { WriteUint16(aFcf, mPsdu); } +void Frame::SetFrameControlField(uint16_t aFcf) { LittleEndian::WriteUint16(aFcf, mPsdu); } Error Frame::ValidatePsdu(void) const { @@ -364,7 +359,7 @@ Error Frame::GetDstPanId(PanId &aPanId) const uint8_t index = FindDstPanIdIndex(); VerifyOrExit(index != kInvalidIndex, error = kErrorParse); - aPanId = ReadUint16(&mPsdu[index]); + aPanId = LittleEndian::ReadUint16(&mPsdu[index]); exit: return error; @@ -375,7 +370,7 @@ void Frame::SetDstPanId(PanId aPanId) uint8_t index = FindDstPanIdIndex(); OT_ASSERT(index != kInvalidIndex); - WriteUint16(aPanId, &mPsdu[index]); + LittleEndian::WriteUint16(aPanId, &mPsdu[index]); } uint8_t Frame::FindDstAddrIndex(void) const { return kFcfSize + kDsnSize + (IsDstPanIdPresent() ? sizeof(PanId) : 0); } @@ -390,7 +385,7 @@ Error Frame::GetDstAddr(Address &aAddress) const switch (GetFrameControlField() & kFcfDstAddrMask) { case kFcfDstAddrShort: - aAddress.SetShort(ReadUint16(&mPsdu[index])); + aAddress.SetShort(LittleEndian::ReadUint16(&mPsdu[index])); break; case kFcfDstAddrExt: @@ -409,7 +404,7 @@ Error Frame::GetDstAddr(Address &aAddress) const void Frame::SetDstAddr(ShortAddress aShortAddress) { OT_ASSERT((GetFrameControlField() & kFcfDstAddrMask) == kFcfDstAddrShort); - WriteUint16(aShortAddress, &mPsdu[FindDstAddrIndex()]); + LittleEndian::WriteUint16(aShortAddress, &mPsdu[FindDstAddrIndex()]); } void Frame::SetDstAddr(const ExtAddress &aExtAddress) @@ -515,7 +510,7 @@ Error Frame::GetSrcPanId(PanId &aPanId) const uint8_t index = FindSrcPanIdIndex(); VerifyOrExit(index != kInvalidIndex, error = kErrorParse); - aPanId = ReadUint16(&mPsdu[index]); + aPanId = LittleEndian::ReadUint16(&mPsdu[index]); exit: return error; @@ -527,7 +522,7 @@ Error Frame::SetSrcPanId(PanId aPanId) uint8_t index = FindSrcPanIdIndex(); VerifyOrExit(index != kInvalidIndex, error = kErrorParse); - WriteUint16(aPanId, &mPsdu[index]); + LittleEndian::WriteUint16(aPanId, &mPsdu[index]); exit: return error; @@ -575,7 +570,7 @@ Error Frame::GetSrcAddr(Address &aAddress) const switch (fcf & kFcfSrcAddrMask) { case kFcfSrcAddrShort: - aAddress.SetShort(ReadUint16(&mPsdu[index])); + aAddress.SetShort(LittleEndian::ReadUint16(&mPsdu[index])); break; case kFcfSrcAddrExt: @@ -603,7 +598,7 @@ void Frame::SetSrcAddr(ShortAddress aShortAddress) OT_ASSERT((GetFrameControlField() & kFcfSrcAddrMask) == kFcfSrcAddrShort); OT_ASSERT(index != kInvalidIndex); - WriteUint16(aShortAddress, &mPsdu[index]); + LittleEndian::WriteUint16(aShortAddress, &mPsdu[index]); } void Frame::SetSrcAddr(const ExtAddress &aExtAddress) @@ -703,7 +698,7 @@ Error Frame::GetFrameCounter(uint32_t &aFrameCounter) const // Security Control index += kSecurityControlSize; - aFrameCounter = ReadUint32(&mPsdu[index]); + aFrameCounter = LittleEndian::ReadUint32(&mPsdu[index]); exit: return error; @@ -718,7 +713,7 @@ void Frame::SetFrameCounter(uint32_t aFrameCounter) // Security Control index += kSecurityControlSize; - WriteUint32(aFrameCounter, &mPsdu[index]); + LittleEndian::WriteUint32(aFrameCounter, &mPsdu[index]); static_cast(this)->SetIsHeaderUpdated(true); } @@ -1396,7 +1391,7 @@ void TxFrame::GenerateImmAck(const RxFrame &aFrame, bool aIsFramePending) { fcf |= kFcfFramePending; } - WriteUint16(fcf, mPsdu); + LittleEndian::WriteUint16(fcf, mPsdu); mPsdu[kSequenceIndex] = aFrame.GetSequence(); diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index d1ce98a485f..ccf8a500e1e 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -46,11 +46,6 @@ namespace ot { namespace Mac { -using ot::Encoding::LittleEndian::HostSwap16; -using ot::Encoding::LittleEndian::HostSwap64; -using ot::Encoding::LittleEndian::ReadUint24; -using ot::Encoding::LittleEndian::WriteUint24; - /** * @addtogroup core-mac * @@ -87,7 +82,7 @@ class HeaderIe * @returns the IE Element Id. * */ - uint16_t GetId(void) const { return (HostSwap16(mFields.m16) & kIdMask) >> kIdOffset; } + uint16_t GetId(void) const { return (LittleEndian::HostSwap16(mFields.m16) & kIdMask) >> kIdOffset; } /** * Sets the IE Element Id. @@ -97,7 +92,8 @@ class HeaderIe */ void SetId(uint16_t aId) { - mFields.m16 = HostSwap16((HostSwap16(mFields.m16) & ~kIdMask) | ((aId << kIdOffset) & kIdMask)); + mFields.m16 = LittleEndian::HostSwap16((LittleEndian::HostSwap16(mFields.m16) & ~kIdMask) | + ((aId << kIdOffset) & kIdMask)); } /** @@ -157,7 +153,7 @@ class VendorIeHeader * @returns The Vendor OUI. * */ - uint32_t GetVendorOui(void) const { return ReadUint24(mOui); } + uint32_t GetVendorOui(void) const { return LittleEndian::ReadUint24(mOui); } /** * Sets the Vendor OUI. @@ -165,7 +161,7 @@ class VendorIeHeader * @param[in] aVendorOui A Vendor OUI. * */ - void SetVendorOui(uint32_t aVendorOui) { WriteUint24(aVendorOui, mOui); } + void SetVendorOui(uint32_t aVendorOui) { LittleEndian::WriteUint24(aVendorOui, mOui); } /** * Returns the Vendor IE sub-type. @@ -236,7 +232,7 @@ class TimeIe : public VendorIeHeader * @returns the network time, in microseconds. * */ - uint64_t GetTime(void) const { return HostSwap64(mTime); } + uint64_t GetTime(void) const { return LittleEndian::HostSwap64(mTime); } /** * Sets the network time. @@ -244,7 +240,7 @@ class TimeIe : public VendorIeHeader * @param[in] aTime The network time. * */ - void SetTime(uint64_t aTime) { mTime = HostSwap64(aTime); } + void SetTime(uint64_t aTime) { mTime = LittleEndian::HostSwap64(aTime); } private: uint8_t mSequence; @@ -1557,7 +1553,7 @@ class Beacon */ void Init(void) { - mSuperframeSpec = HostSwap16(kSuperFrameSpec); + mSuperframeSpec = LittleEndian::HostSwap16(kSuperFrameSpec); mGtsSpec = 0; mPendingAddressSpec = 0; } @@ -1571,7 +1567,8 @@ class Beacon */ bool IsValid(void) const { - return (mSuperframeSpec == HostSwap16(kSuperFrameSpec)) && (mGtsSpec == 0) && (mPendingAddressSpec == 0); + return (mSuperframeSpec == LittleEndian::HostSwap16(kSuperFrameSpec)) && (mGtsSpec == 0) && + (mPendingAddressSpec == 0); } /** @@ -1752,7 +1749,7 @@ class CslIe * @returns the CSL Period. * */ - uint16_t GetPeriod(void) const { return HostSwap16(mPeriod); } + uint16_t GetPeriod(void) const { return LittleEndian::HostSwap16(mPeriod); } /** * Sets the CSL Period. @@ -1760,7 +1757,7 @@ class CslIe * @param[in] aPeriod The CSL Period. * */ - void SetPeriod(uint16_t aPeriod) { mPeriod = HostSwap16(aPeriod); } + void SetPeriod(uint16_t aPeriod) { mPeriod = LittleEndian::HostSwap16(aPeriod); } /** * Returns the CSL Phase. @@ -1768,7 +1765,7 @@ class CslIe * @returns the CSL Phase. * */ - uint16_t GetPhase(void) const { return HostSwap16(mPhase); } + uint16_t GetPhase(void) const { return LittleEndian::HostSwap16(mPhase); } /** * Sets the CSL Phase. @@ -1776,7 +1773,7 @@ class CslIe * @param[in] aPhase The CSL Phase. * */ - void SetPhase(uint16_t aPhase) { mPhase = HostSwap16(aPhase); } + void SetPhase(uint16_t aPhase) { mPhase = LittleEndian::HostSwap16(aPhase); } private: uint16_t mPhase; diff --git a/src/core/meshcop/dataset.hpp b/src/core/meshcop/dataset.hpp index cffa4bcffad..0f9a69e0c42 100644 --- a/src/core/meshcop/dataset.hpp +++ b/src/core/meshcop/dataset.hpp @@ -938,7 +938,7 @@ class Dataset */ template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint16_t &aValue) { - uint16_t value = Encoding::BigEndian::HostSwap16(aValue); + uint16_t value = BigEndian::HostSwap16(aValue); return SetTlv(aType, &value, sizeof(uint16_t)); } @@ -955,7 +955,7 @@ template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint16_t &aValue */ template <> inline Error Dataset::SetTlv(Tlv::Type aType, const uint32_t &aValue) { - uint32_t value = Encoding::BigEndian::HostSwap32(aValue); + uint32_t value = BigEndian::HostSwap32(aValue); return SetTlv(aType, &value, sizeof(uint32_t)); } diff --git a/src/core/meshcop/meshcop.cpp b/src/core/meshcop/meshcop.cpp index 82f7a139f60..35ad539b544 100644 --- a/src/core/meshcop/meshcop.cpp +++ b/src/core/meshcop/meshcop.cpp @@ -119,7 +119,7 @@ bool JoinerDiscerner::Matches(const Mac::ExtAddress &aJoinerId) const mask = GetMask(); - return (Encoding::BigEndian::ReadUint64(aJoinerId.m8) & mask) == (mValue & mask); + return (BigEndian::ReadUint64(aJoinerId.m8) & mask) == (mValue & mask); } void JoinerDiscerner::CopyTo(Mac::ExtAddress &aExtAddress) const diff --git a/src/core/meshcop/meshcop_tlvs.cpp b/src/core/meshcop/meshcop_tlvs.cpp index 4ad9a4c6eca..04063dfa5d8 100644 --- a/src/core/meshcop/meshcop_tlvs.cpp +++ b/src/core/meshcop/meshcop_tlvs.cpp @@ -184,7 +184,7 @@ void ChannelTlv::SetChannel(uint16_t aChannel) #endif SetChannelPage(channelPage); - mChannel = HostSwap16(aChannel); + mChannel = BigEndian::HostSwap16(aChannel); } const char *StateTlv::StateToString(State aState) diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 4be763a67c7..32121bdb5b9 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -59,11 +59,6 @@ namespace ot { namespace MeshCoP { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; -using ot::Encoding::BigEndian::ReadUint24; -using ot::Encoding::BigEndian::WriteUint24; - /** * Implements MeshCoP TLV generation and parsing. * @@ -304,7 +299,7 @@ class ChannelTlv : public Tlv, public TlvInfo * @returns The Channel value. * */ - uint16_t GetChannel(void) const { return HostSwap16(mChannel); } + uint16_t GetChannel(void) const { return BigEndian::HostSwap16(mChannel); } /** * Sets the Channel value. @@ -353,7 +348,7 @@ class PanIdTlv : public Tlv, public UintTlvInfo * @returns The PAN ID value. * */ - uint16_t GetPanId(void) const { return HostSwap16(mPanId); } + uint16_t GetPanId(void) const { return BigEndian::HostSwap16(mPanId); } /** * Sets the PAN ID value. @@ -361,7 +356,7 @@ class PanIdTlv : public Tlv, public UintTlvInfo * @param[in] aPanId The PAN ID value. * */ - void SetPanId(uint16_t aPanId) { mPanId = HostSwap16(aPanId); } + void SetPanId(uint16_t aPanId) { mPanId = BigEndian::HostSwap16(aPanId); } private: uint16_t mPanId; @@ -588,7 +583,7 @@ class NetworkKeySequenceTlv : public Tlv, public UintTlvInfo static constexpr uint8_t kThread11FlagsLength = 1; // The Thread 1.1 Security Policy Flags length. static constexpr uint8_t kThread12FlagsLength = 2; // The Thread 1.2 Security Policy Flags length. - void SetRotationTime(uint16_t aRotationTime) { mRotationTime = HostSwap16(aRotationTime); } - uint16_t GetRotationTime(void) const { return HostSwap16(mRotationTime); } + void SetRotationTime(uint16_t aRotationTime) { mRotationTime = BigEndian::HostSwap16(aRotationTime); } + uint16_t GetRotationTime(void) const { return BigEndian::HostSwap16(mRotationTime); } uint8_t GetFlagsLength(void) const { return GetLength() - sizeof(mRotationTime); } uint16_t mRotationTime; @@ -989,7 +987,7 @@ class JoinerUdpPortTlv : public Tlv, public UintTlvInfo * @returns The Delay Timer value. * */ - uint32_t GetDelayTimer(void) const { return HostSwap32(mDelayTimer); } + uint32_t GetDelayTimer(void) const { return BigEndian::HostSwap32(mDelayTimer); } /** * Sets the Delay Timer value. @@ -1100,7 +1098,7 @@ class DelayTimerTlv : public Tlv, public UintTlvInfo * @param[in] aDelayTimer The Delay Timer value. * */ - void SetDelayTimer(uint32_t aDelayTimer) { mDelayTimer = HostSwap32(aDelayTimer); } + void SetDelayTimer(uint32_t aDelayTimer) { mDelayTimer = BigEndian::HostSwap32(aDelayTimer); } static constexpr uint32_t kMaxDelayTimer = 259200; ///< Maximum delay timer value for a Pending Dataset in seconds @@ -1264,7 +1262,7 @@ class ChannelMaskEntry : public ChannelMaskEntryBase * @returns The Channel Mask value. * */ - uint32_t GetMask(void) const { return Encoding::Reverse32(HostSwap32(mMask)); } + uint32_t GetMask(void) const { return Reverse32(BigEndian::HostSwap32(mMask)); } /** * Sets the Channel Mask value. @@ -1272,7 +1270,7 @@ class ChannelMaskEntry : public ChannelMaskEntryBase * @param[in] aMask The Channel Mask value. * */ - void SetMask(uint32_t aMask) { mMask = HostSwap32(Encoding::Reverse32(aMask)); } + void SetMask(uint32_t aMask) { mMask = BigEndian::HostSwap32(Reverse32(aMask)); } private: uint32_t mMask; @@ -1495,7 +1493,7 @@ class VendorStackVersionTlv : public Tlv, public TlvInfo> kBuildOffset; } + uint16_t GetBuild(void) const { return (BigEndian::HostSwap16(mBuildRevision) & kBuildMask) >> kBuildOffset; } /** * Sets the Build value. @@ -1521,8 +1519,8 @@ class VendorStackVersionTlv : public Tlv, public TlvInfo> kRevOffset; } + uint8_t GetRevision(void) const { return (BigEndian::HostSwap16(mBuildRevision) & kRevMask) >> kRevOffset; } /** * Sets the Revision value. @@ -1541,7 +1539,8 @@ class VendorStackVersionTlv : public Tlv, public TlvInfo */ uint64_t GetSeconds(void) const { - return (static_cast(HostSwap16(mSeconds16)) << 32) + HostSwap32(mSeconds32); + return (static_cast(BigEndian::HostSwap16(mSeconds16)) << 32) + BigEndian::HostSwap32(mSeconds32); } /** @@ -91,8 +88,8 @@ class Timestamp : public Clearable */ void SetSeconds(uint64_t aSeconds) { - mSeconds16 = HostSwap16(static_cast(aSeconds >> 32)); - mSeconds32 = HostSwap32(static_cast(aSeconds & 0xffffffff)); + mSeconds16 = BigEndian::HostSwap16(static_cast(aSeconds >> 32)); + mSeconds32 = BigEndian::HostSwap32(static_cast(aSeconds & 0xffffffff)); } /** @@ -101,7 +98,7 @@ class Timestamp : public Clearable * @returns The Ticks value. * */ - uint16_t GetTicks(void) const { return HostSwap16(mTicks) >> kTicksOffset; } + uint16_t GetTicks(void) const { return BigEndian::HostSwap16(mTicks) >> kTicksOffset; } /** * Sets the Ticks value. @@ -111,7 +108,8 @@ class Timestamp : public Clearable */ void SetTicks(uint16_t aTicks) { - mTicks = HostSwap16((HostSwap16(mTicks) & ~kTicksMask) | ((aTicks << kTicksOffset) & kTicksMask)); + mTicks = BigEndian::HostSwap16((BigEndian::HostSwap16(mTicks) & ~kTicksMask) | + ((aTicks << kTicksOffset) & kTicksMask)); } /** @@ -120,7 +118,7 @@ class Timestamp : public Clearable * @returns The Authoritative value. * */ - bool GetAuthoritative(void) const { return (HostSwap16(mTicks) & kAuthoritativeMask) != 0; } + bool GetAuthoritative(void) const { return (BigEndian::HostSwap16(mTicks) & kAuthoritativeMask) != 0; } /** * Sets the Authoritative value. @@ -130,8 +128,8 @@ class Timestamp : public Clearable */ void SetAuthoritative(bool aAuthoritative) { - mTicks = HostSwap16((HostSwap16(mTicks) & kTicksMask) | - ((aAuthoritative << kAuthoritativeOffset) & kAuthoritativeMask)); + mTicks = BigEndian::HostSwap16((BigEndian::HostSwap16(mTicks) & kTicksMask) | + ((aAuthoritative << kAuthoritativeOffset) & kAuthoritativeMask)); } /** diff --git a/src/core/net/checksum.cpp b/src/core/net/checksum.cpp index d07f4250829..c343fe54bf9 100644 --- a/src/core/net/checksum.cpp +++ b/src/core/net/checksum.cpp @@ -89,7 +89,7 @@ void Checksum::WriteToMessage(uint16_t aOffset, Message &aMessage) const checksum = ~checksum; } - checksum = Encoding::BigEndian::HostSwap16(checksum); + checksum = BigEndian::HostSwap16(checksum); aMessage.Write(aOffset, checksum); } diff --git a/src/core/net/dhcp6.hpp b/src/core/net/dhcp6.hpp index b2a0c187e98..62a3d7b80e7 100644 --- a/src/core/net/dhcp6.hpp +++ b/src/core/net/dhcp6.hpp @@ -48,9 +48,6 @@ namespace ot { namespace Dhcp6 { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * @addtogroup core-dhcp6 * @@ -217,7 +214,7 @@ class Option * @returns The DHCPv6 option code. * */ - Code GetCode(void) const { return static_cast(HostSwap16(mCode)); } + Code GetCode(void) const { return static_cast(BigEndian::HostSwap16(mCode)); } /** * Sets the DHCPv6 option code. @@ -225,7 +222,7 @@ class Option * @param[in] aCode The DHCPv6 option code. * */ - void SetCode(Code aCode) { mCode = HostSwap16(static_cast(aCode)); } + void SetCode(Code aCode) { mCode = BigEndian::HostSwap16(static_cast(aCode)); } /** * Returns the length of DHCPv6 option. @@ -233,7 +230,7 @@ class Option * @returns The length of DHCPv6 option. * */ - uint16_t GetLength(void) const { return HostSwap16(mLength); } + uint16_t GetLength(void) const { return BigEndian::HostSwap16(mLength); } /** * Sets the length of DHCPv6 option. @@ -241,7 +238,7 @@ class Option * @param[in] aLength The length of DHCPv6 option. * */ - void SetLength(uint16_t aLength) { mLength = HostSwap16(aLength); } + void SetLength(uint16_t aLength) { mLength = BigEndian::HostSwap16(aLength); } private: uint16_t mCode; @@ -279,7 +276,7 @@ class ClientIdentifier : public Option * @returns The client DUID Type. * */ - DuidType GetDuidType(void) const { return static_cast(HostSwap16(mDuidType)); } + DuidType GetDuidType(void) const { return static_cast(BigEndian::HostSwap16(mDuidType)); } /** * Sets the client DUID Type. @@ -287,7 +284,7 @@ class ClientIdentifier : public Option * @param[in] aDuidType The client DUID Type. * */ - void SetDuidType(DuidType aDuidType) { mDuidType = HostSwap16(static_cast(aDuidType)); } + void SetDuidType(DuidType aDuidType) { mDuidType = BigEndian::HostSwap16(static_cast(aDuidType)); } /** * Returns the client Duid HardwareType. @@ -295,7 +292,7 @@ class ClientIdentifier : public Option * @returns The client Duid HardwareType. * */ - uint16_t GetDuidHardwareType(void) const { return HostSwap16(mDuidHardwareType); } + uint16_t GetDuidHardwareType(void) const { return BigEndian::HostSwap16(mDuidHardwareType); } /** * Sets the client Duid HardwareType. @@ -303,7 +300,10 @@ class ClientIdentifier : public Option * @param[in] aDuidHardwareType The client Duid HardwareType. * */ - void SetDuidHardwareType(uint16_t aDuidHardwareType) { mDuidHardwareType = HostSwap16(aDuidHardwareType); } + void SetDuidHardwareType(uint16_t aDuidHardwareType) + { + mDuidHardwareType = BigEndian::HostSwap16(aDuidHardwareType); + } /** * Returns the client LinkLayerAddress. @@ -350,7 +350,7 @@ class ServerIdentifier : public Option * @returns The server DUID Type. * */ - DuidType GetDuidType(void) const { return static_cast(HostSwap16(mDuidType)); } + DuidType GetDuidType(void) const { return static_cast(BigEndian::HostSwap16(mDuidType)); } /** * Sets the server DUID Type. @@ -358,7 +358,7 @@ class ServerIdentifier : public Option * @param[in] aDuidType The server DUID Type. * */ - void SetDuidType(DuidType aDuidType) { mDuidType = HostSwap16(static_cast(aDuidType)); } + void SetDuidType(DuidType aDuidType) { mDuidType = BigEndian::HostSwap16(static_cast(aDuidType)); } /** * Returns the server DUID HardwareType. @@ -366,7 +366,7 @@ class ServerIdentifier : public Option * @returns The server DUID HardwareType. * */ - uint16_t GetDuidHardwareType(void) const { return HostSwap16(mDuidHardwareType); } + uint16_t GetDuidHardwareType(void) const { return BigEndian::HostSwap16(mDuidHardwareType); } /** * Sets the server DUID HardwareType. @@ -374,7 +374,10 @@ class ServerIdentifier : public Option * @param[in] aDuidHardwareType The server DUID HardwareType. * */ - void SetDuidHardwareType(uint16_t aDuidHardwareType) { mDuidHardwareType = HostSwap16(aDuidHardwareType); } + void SetDuidHardwareType(uint16_t aDuidHardwareType) + { + mDuidHardwareType = BigEndian::HostSwap16(aDuidHardwareType); + } /** * Returns the server LinkLayerAddress. @@ -428,7 +431,7 @@ class IaNa : public Option * @returns The client IAID. * */ - uint32_t GetIaid(void) const { return HostSwap32(mIaid); } + uint32_t GetIaid(void) const { return BigEndian::HostSwap32(mIaid); } /** * Sets the client IAID. @@ -436,7 +439,7 @@ class IaNa : public Option * @param[in] aIaid The client IAID. * */ - void SetIaid(uint32_t aIaid) { mIaid = HostSwap32(aIaid); } + void SetIaid(uint32_t aIaid) { mIaid = BigEndian::HostSwap32(aIaid); } /** * Returns T1. @@ -444,7 +447,7 @@ class IaNa : public Option * @returns The value of T1. * */ - uint32_t GetT1(void) const { return HostSwap32(mT1); } + uint32_t GetT1(void) const { return BigEndian::HostSwap32(mT1); } /** * Sets the value of T1. @@ -452,7 +455,7 @@ class IaNa : public Option * @param[in] aT1 The value of T1. * */ - void SetT1(uint32_t aT1) { mT1 = HostSwap32(aT1); } + void SetT1(uint32_t aT1) { mT1 = BigEndian::HostSwap32(aT1); } /** * Returns T2. @@ -460,7 +463,7 @@ class IaNa : public Option * @returns The value of T2. * */ - uint32_t GetT2(void) const { return HostSwap32(mT2); } + uint32_t GetT2(void) const { return BigEndian::HostSwap32(mT2); } /** * Sets the value of T2. @@ -468,7 +471,7 @@ class IaNa : public Option * @param[in] aT2 The value of T2. * */ - void SetT2(uint32_t aT2) { mT2 = HostSwap32(aT2); } + void SetT2(uint32_t aT2) { mT2 = BigEndian::HostSwap32(aT2); } private: uint32_t mIaid; @@ -527,7 +530,7 @@ class IaAddress : public Option * @returns The preferred lifetime of the IPv6 address. * */ - uint32_t GetPreferredLifetime(void) const { return HostSwap32(mPreferredLifetime); } + uint32_t GetPreferredLifetime(void) const { return BigEndian::HostSwap32(mPreferredLifetime); } /** * Sets the preferred lifetime of the IPv6 address. @@ -535,7 +538,10 @@ class IaAddress : public Option * @param[in] aPreferredLifetime The preferred lifetime of the IPv6 address. * */ - void SetPreferredLifetime(uint32_t aPreferredLifetime) { mPreferredLifetime = HostSwap32(aPreferredLifetime); } + void SetPreferredLifetime(uint32_t aPreferredLifetime) + { + mPreferredLifetime = BigEndian::HostSwap32(aPreferredLifetime); + } /** * Returns the valid lifetime of the IPv6 address. @@ -543,7 +549,7 @@ class IaAddress : public Option * @returns The valid lifetime of the IPv6 address. * */ - uint32_t GetValidLifetime(void) const { return HostSwap32(mValidLifetime); } + uint32_t GetValidLifetime(void) const { return BigEndian::HostSwap32(mValidLifetime); } /** * Sets the valid lifetime of the IPv6 address. @@ -551,7 +557,7 @@ class IaAddress : public Option * @param[in] aValidLifetime The valid lifetime of the IPv6 address. * */ - void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = HostSwap32(aValidLifetime); } + void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = BigEndian::HostSwap32(aValidLifetime); } private: Ip6::Address mAddress; @@ -583,7 +589,7 @@ class ElapsedTime : public Option * @returns The elapsed time since solicit starts. * */ - uint16_t GetElapsedTime(void) const { return HostSwap16(mElapsedTime); } + uint16_t GetElapsedTime(void) const { return BigEndian::HostSwap16(mElapsedTime); } /** * Sets the elapsed time since solicit starts. @@ -591,7 +597,7 @@ class ElapsedTime : public Option * @param[in] aElapsedTime The elapsed time since solicit starts. * */ - void SetElapsedTime(uint16_t aElapsedTime) { mElapsedTime = HostSwap16(aElapsedTime); } + void SetElapsedTime(uint16_t aElapsedTime) { mElapsedTime = BigEndian::HostSwap16(aElapsedTime); } private: uint16_t mElapsedTime; @@ -639,7 +645,7 @@ class StatusCode : public Option * @returns The status code. * */ - Status GetStatusCode(void) const { return static_cast(HostSwap16(mStatus)); } + Status GetStatusCode(void) const { return static_cast(BigEndian::HostSwap16(mStatus)); } /** * Sets the status code. @@ -647,7 +653,7 @@ class StatusCode : public Option * @param[in] aStatus The status code. * */ - void SetStatusCode(Status aStatus) { mStatus = HostSwap16(static_cast(aStatus)); } + void SetStatusCode(Status aStatus) { mStatus = BigEndian::HostSwap16(static_cast(aStatus)); } private: uint16_t mStatus; diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index df7c737a186..366a657a40a 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -49,11 +49,6 @@ namespace ot { namespace Dns { -#if OPENTHREAD_CONFIG_DNS_CLIENT_OVER_TCP_ENABLE -using ot::Encoding::BigEndian::ReadUint16; -using ot::Encoding::BigEndian::WriteUint16; -#endif - RegisterLogModule("DnsClient"); //--------------------------------------------------------------------------------------------------------------------- @@ -1172,7 +1167,7 @@ Error Client::SendQuery(Query &aQuery, QueryInfo &aInfo, bool aUpdateTimer) PrepareTcpMessage(*message); break; case kTcpConnectedSending: - WriteUint16(length, mSendBufferBytes + mSendLink.mLength); + BigEndian::WriteUint16(length, mSendBufferBytes + mSendLink.mLength); SuccessOrAssert(error = message->Read(message->GetOffset(), (mSendBufferBytes + sizeof(uint16_t) + mSendLink.mLength), length)); IgnoreError(mEndpoint.SendByExtension(length + sizeof(uint16_t), /* aFlags */ 0)); @@ -1678,7 +1673,7 @@ void Client::PrepareTcpMessage(Message &aMessage) uint16_t length = aMessage.GetLength() - aMessage.GetOffset(); // Prepending the DNS query with length of the packet according to RFC1035. - WriteUint16(length, mSendBufferBytes + mSendLink.mLength); + BigEndian::WriteUint16(length, mSendBufferBytes + mSendLink.mLength); SuccessOrAssert( aMessage.Read(aMessage.GetOffset(), (mSendBufferBytes + sizeof(uint16_t) + mSendLink.mLength), length)); mSendLink.mLength += length + sizeof(uint16_t); @@ -1788,7 +1783,7 @@ void Client::HandleTcpReceiveAvailable(otTcpEndpoint *aEndpoint, SuccessOrExit(ReadFromLinkBuffer(data, offset, *message, sizeof(uint16_t))); IgnoreError(message->Read(/* aOffset */ 0, length)); - length = HostSwap16(length); + length = BigEndian::HostSwap16(length); // Try to read `length` bytes. IgnoreError(message->SetLength(0)); diff --git a/src/core/net/dns_dso.hpp b/src/core/net/dns_dso.hpp index 447fa509a10..fdaf991fbfc 100644 --- a/src/core/net/dns_dso.hpp +++ b/src/core/net/dns_dso.hpp @@ -60,9 +60,6 @@ struct otPlatDsoConnection namespace ot { namespace Dns { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - extern "C" otPlatDsoConnection *otPlatDsoAccept(otInstance *aInstance, const otSockAddr *aPeerSockAddr); extern "C" void otPlatDsoHandleConnected(otPlatDsoConnection *aConnection); @@ -149,8 +146,8 @@ class Dso : public InstanceLocator, private NonCopyable */ void Init(Type aType, uint16_t aLength) { - mType = HostSwap16(aType); - mLength = HostSwap16(aLength); + mType = BigEndian::HostSwap16(aType); + mLength = BigEndian::HostSwap16(aLength); } /** @@ -159,7 +156,7 @@ class Dso : public InstanceLocator, private NonCopyable * @returns The TLV type. * */ - Type GetType(void) const { return HostSwap16(mType); } + Type GetType(void) const { return BigEndian::HostSwap16(mType); } /** * Gets the TLV length. @@ -167,7 +164,7 @@ class Dso : public InstanceLocator, private NonCopyable * @returns The TLV length (in bytes). * */ - uint16_t GetLength(void) const { return HostSwap16(mLength); } + uint16_t GetLength(void) const { return BigEndian::HostSwap16(mLength); } /** * Returns the total size of the TLV (including the type and length fields). @@ -911,11 +908,11 @@ class Dso : public InstanceLocator, private NonCopyable bool IsValid(void) const { return GetSize() >= sizeof(*this); } - uint32_t GetInactivityTimeout(void) const { return HostSwap32(mInactivityTimeout); } - void SetInactivityTimeout(uint32_t aTimeout) { mInactivityTimeout = HostSwap32(aTimeout); } + uint32_t GetInactivityTimeout(void) const { return BigEndian::HostSwap32(mInactivityTimeout); } + void SetInactivityTimeout(uint32_t aTimeout) { mInactivityTimeout = BigEndian::HostSwap32(aTimeout); } - uint32_t GetKeepAliveInterval(void) const { return HostSwap32(mKeepAliveInterval); } - void SetKeepAliveInterval(uint32_t aInterval) { mKeepAliveInterval = HostSwap32(aInterval); } + uint32_t GetKeepAliveInterval(void) const { return BigEndian::HostSwap32(mKeepAliveInterval); } + void SetKeepAliveInterval(uint32_t aInterval) { mKeepAliveInterval = BigEndian::HostSwap32(aInterval); } private: uint32_t mInactivityTimeout; // In msec @@ -932,8 +929,8 @@ class Dso : public InstanceLocator, private NonCopyable bool IsValid(void) const { return GetSize() >= sizeof(*this); } - uint32_t GetRetryDelay(void) const { return HostSwap32(mRetryDelay); } - void SetRetryDelay(uint32_t aDelay) { mRetryDelay = HostSwap32(aDelay); } + uint32_t GetRetryDelay(void) const { return BigEndian::HostSwap32(mRetryDelay); } + void SetRetryDelay(uint32_t aDelay) { mRetryDelay = BigEndian::HostSwap32(aDelay); } private: uint32_t mRetryDelay; diff --git a/src/core/net/dns_types.cpp b/src/core/net/dns_types.cpp index 2f7f3c99af0..aa19c73bf00 100644 --- a/src/core/net/dns_types.cpp +++ b/src/core/net/dns_types.cpp @@ -43,8 +43,6 @@ namespace ot { namespace Dns { -using ot::Encoding::BigEndian::HostSwap16; - Error Header::SetRandomMessageId(void) { return Random::Crypto::FillBuffer(reinterpret_cast(&mMessageId), sizeof(mMessageId)); @@ -244,7 +242,7 @@ Error Name::AppendPointerLabel(uint16_t aOffset, Message &aMessage) OT_ASSERT(aOffset < kPointerLabelTypeUint16); - value = HostSwap16(aOffset | kPointerLabelTypeUint16); + value = BigEndian::HostSwap16(aOffset | kPointerLabelTypeUint16); ExitNow(error = aMessage.Append(value)); @@ -528,7 +526,7 @@ Error Name::LabelIterator::GetNextLabel(void) // `mMessage.GetOffset()` must point to the start of the // DNS header. - nextLabelOffset = mMessage.GetOffset() + (HostSwap16(pointerValue) & kPointerLabelOffsetMask); + nextLabelOffset = mMessage.GetOffset() + (BigEndian::HostSwap16(pointerValue) & kPointerLabelOffsetMask); VerifyOrExit(nextLabelOffset < mNextLabelOffset, error = kErrorParse); mNextLabelOffset = nextLabelOffset; diff --git a/src/core/net/dns_types.hpp b/src/core/net/dns_types.hpp index f84d7d361e9..9f8a93093a1 100644 --- a/src/core/net/dns_types.hpp +++ b/src/core/net/dns_types.hpp @@ -59,9 +59,6 @@ namespace ot { */ namespace Dns { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * @addtogroup core-dns * @@ -92,7 +89,7 @@ class Header : public Clearable
* @returns The Message ID value. * */ - uint16_t GetMessageId(void) const { return HostSwap16(mMessageId); } + uint16_t GetMessageId(void) const { return BigEndian::HostSwap16(mMessageId); } /** * Sets the Message ID. @@ -100,7 +97,7 @@ class Header : public Clearable
* @param[in] aMessageId The Message ID value. * */ - void SetMessageId(uint16_t aMessageId) { mMessageId = HostSwap16(aMessageId); } + void SetMessageId(uint16_t aMessageId) { mMessageId = BigEndian::HostSwap16(aMessageId); } /** * Sets the Message ID to a crypto-secure randomly generated number. @@ -331,7 +328,7 @@ class Header : public Clearable
* @returns The number of entries in question section. * */ - uint16_t GetQuestionCount(void) const { return HostSwap16(mQdCount); } + uint16_t GetQuestionCount(void) const { return BigEndian::HostSwap16(mQdCount); } /** * Sets the number of entries in question section. @@ -339,7 +336,7 @@ class Header : public Clearable
* @param[in] aCount The number of entries in question section. * */ - void SetQuestionCount(uint16_t aCount) { mQdCount = HostSwap16(aCount); } + void SetQuestionCount(uint16_t aCount) { mQdCount = BigEndian::HostSwap16(aCount); } /** * Returns the number of entries in answer section. @@ -347,7 +344,7 @@ class Header : public Clearable
* @returns The number of entries in answer section. * */ - uint16_t GetAnswerCount(void) const { return HostSwap16(mAnCount); } + uint16_t GetAnswerCount(void) const { return BigEndian::HostSwap16(mAnCount); } /** * Sets the number of entries in answer section. @@ -355,7 +352,7 @@ class Header : public Clearable
* @param[in] aCount The number of entries in answer section. * */ - void SetAnswerCount(uint16_t aCount) { mAnCount = HostSwap16(aCount); } + void SetAnswerCount(uint16_t aCount) { mAnCount = BigEndian::HostSwap16(aCount); } /** * Returns the number of entries in authority records section. @@ -363,7 +360,7 @@ class Header : public Clearable
* @returns The number of entries in authority records section. * */ - uint16_t GetAuthorityRecordCount(void) const { return HostSwap16(mNsCount); } + uint16_t GetAuthorityRecordCount(void) const { return BigEndian::HostSwap16(mNsCount); } /** * Sets the number of entries in authority records section. @@ -371,7 +368,7 @@ class Header : public Clearable
* @param[in] aCount The number of entries in authority records section. * */ - void SetAuthorityRecordCount(uint16_t aCount) { mNsCount = HostSwap16(aCount); } + void SetAuthorityRecordCount(uint16_t aCount) { mNsCount = BigEndian::HostSwap16(aCount); } /** * Returns the number of entries in additional records section. @@ -379,7 +376,7 @@ class Header : public Clearable
* @returns The number of entries in additional records section. * */ - uint16_t GetAdditionalRecordCount(void) const { return HostSwap16(mArCount); } + uint16_t GetAdditionalRecordCount(void) const { return BigEndian::HostSwap16(mArCount); } /** * Sets the number of entries in additional records section. @@ -387,7 +384,7 @@ class Header : public Clearable
* @param[in] aCount The number of entries in additional records section. * */ - void SetAdditionalRecordCount(uint16_t aCount) { mArCount = HostSwap16(aCount); } + void SetAdditionalRecordCount(uint16_t aCount) { mArCount = BigEndian::HostSwap16(aCount); } private: // Protocol Constants (RFC 1035). @@ -1253,7 +1250,7 @@ class ResourceRecord */ bool Matches(uint16_t aType, uint16_t aClass = kClassInternet) const { - return (mType == HostSwap16(aType)) && (mClass == HostSwap16(aClass)); + return (mType == BigEndian::HostSwap16(aType)) && (mClass == BigEndian::HostSwap16(aClass)); } /** @@ -1262,7 +1259,7 @@ class ResourceRecord * @returns The type of the resource record. * */ - uint16_t GetType(void) const { return HostSwap16(mType); } + uint16_t GetType(void) const { return BigEndian::HostSwap16(mType); } /** * Sets the type of the resource record. @@ -1270,7 +1267,7 @@ class ResourceRecord * @param[in] aType The type of the resource record. * */ - void SetType(uint16_t aType) { mType = HostSwap16(aType); } + void SetType(uint16_t aType) { mType = BigEndian::HostSwap16(aType); } /** * Returns the class of the resource record. @@ -1278,7 +1275,7 @@ class ResourceRecord * @returns The class of the resource record. * */ - uint16_t GetClass(void) const { return HostSwap16(mClass); } + uint16_t GetClass(void) const { return BigEndian::HostSwap16(mClass); } /** * Sets the class of the resource record. @@ -1286,7 +1283,7 @@ class ResourceRecord * @param[in] aClass The class of the resource record. * */ - void SetClass(uint16_t aClass) { mClass = HostSwap16(aClass); } + void SetClass(uint16_t aClass) { mClass = BigEndian::HostSwap16(aClass); } /** * Returns the time to live field of the resource record. @@ -1294,7 +1291,7 @@ class ResourceRecord * @returns The time to live field of the resource record. * */ - uint32_t GetTtl(void) const { return HostSwap32(mTtl); } + uint32_t GetTtl(void) const { return BigEndian::HostSwap32(mTtl); } /** * Sets the time to live field of the resource record. @@ -1302,7 +1299,7 @@ class ResourceRecord * @param[in] aTtl The time to live field of the resource record. * */ - void SetTtl(uint32_t aTtl) { mTtl = HostSwap32(aTtl); } + void SetTtl(uint32_t aTtl) { mTtl = BigEndian::HostSwap32(aTtl); } /** * Returns the length of the resource record data. @@ -1310,7 +1307,7 @@ class ResourceRecord * @returns The length of the resource record data. * */ - uint16_t GetLength(void) const { return HostSwap16(mLength); } + uint16_t GetLength(void) const { return BigEndian::HostSwap16(mLength); } /** * Sets the length of the resource record data. @@ -1318,7 +1315,7 @@ class ResourceRecord * @param[in] aLength The length of the resource record data. * */ - void SetLength(uint16_t aLength) { mLength = HostSwap16(aLength); } + void SetLength(uint16_t aLength) { mLength = BigEndian::HostSwap16(aLength); } /** * Returns the size of (number of bytes) in resource record and its data RDATA section (excluding the @@ -1799,7 +1796,7 @@ class SrvRecord : public ResourceRecord * @returns The priority value. * */ - uint16_t GetPriority(void) const { return HostSwap16(mPriority); } + uint16_t GetPriority(void) const { return BigEndian::HostSwap16(mPriority); } /** * Sets the SRV record's priority value. @@ -1807,7 +1804,7 @@ class SrvRecord : public ResourceRecord * @param[in] aPriority The priority value. * */ - void SetPriority(uint16_t aPriority) { mPriority = HostSwap16(aPriority); } + void SetPriority(uint16_t aPriority) { mPriority = BigEndian::HostSwap16(aPriority); } /** * Returns the SRV record's weight value. @@ -1815,7 +1812,7 @@ class SrvRecord : public ResourceRecord * @returns The weight value. * */ - uint16_t GetWeight(void) const { return HostSwap16(mWeight); } + uint16_t GetWeight(void) const { return BigEndian::HostSwap16(mWeight); } /** * Sets the SRV record's weight value. @@ -1823,7 +1820,7 @@ class SrvRecord : public ResourceRecord * @param[in] aWeight The weight value. * */ - void SetWeight(uint16_t aWeight) { mWeight = HostSwap16(aWeight); } + void SetWeight(uint16_t aWeight) { mWeight = BigEndian::HostSwap16(aWeight); } /** * Returns the SRV record's port number on the target host for this service. @@ -1831,7 +1828,7 @@ class SrvRecord : public ResourceRecord * @returns The port number. * */ - uint16_t GetPort(void) const { return HostSwap16(mPort); } + uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); } /** * Sets the SRV record's port number on the target host for this service. @@ -1839,7 +1836,7 @@ class SrvRecord : public ResourceRecord * @param[in] aPort The port number. * */ - void SetPort(uint16_t aPort) { mPort = HostSwap16(aPort); } + void SetPort(uint16_t aPort) { mPort = BigEndian::HostSwap16(aPort); } /** * Parses and reads the SRV target host name from a message. @@ -2131,7 +2128,7 @@ class SigRecord : public ResourceRecord, public Clearable * @returns The type-covered value. * */ - uint16_t GetTypeCovered(void) const { return HostSwap16(mTypeCovered); } + uint16_t GetTypeCovered(void) const { return BigEndian::HostSwap16(mTypeCovered); } /** * Sets the SIG record's type-covered value. @@ -2139,7 +2136,7 @@ class SigRecord : public ResourceRecord, public Clearable * @param[in] aTypeCovered The type-covered value. * */ - void SetTypeCovered(uint8_t aTypeCovered) { mTypeCovered = HostSwap16(aTypeCovered); } + void SetTypeCovered(uint8_t aTypeCovered) { mTypeCovered = BigEndian::HostSwap16(aTypeCovered); } /** * Returns the SIG record's algorithm value. @@ -2181,7 +2178,7 @@ class SigRecord : public ResourceRecord, public Clearable * @returns The original TTL value. * */ - uint32_t GetOriginalTtl(void) const { return HostSwap32(mOriginalTtl); } + uint32_t GetOriginalTtl(void) const { return BigEndian::HostSwap32(mOriginalTtl); } /** * Sets the SIG record's original TTL value. @@ -2189,7 +2186,7 @@ class SigRecord : public ResourceRecord, public Clearable * @param[in] aOriginalTtl The original TTL value. * */ - void SetOriginalTtl(uint32_t aOriginalTtl) { mOriginalTtl = HostSwap32(aOriginalTtl); } + void SetOriginalTtl(uint32_t aOriginalTtl) { mOriginalTtl = BigEndian::HostSwap32(aOriginalTtl); } /** * Returns the SIG record's expiration time value. @@ -2197,7 +2194,7 @@ class SigRecord : public ResourceRecord, public Clearable * @returns The expiration time value (seconds since Jan 1, 1970). * */ - uint32_t GetExpiration(void) const { return HostSwap32(mExpiration); } + uint32_t GetExpiration(void) const { return BigEndian::HostSwap32(mExpiration); } /** * Sets the SIG record's expiration time value. @@ -2205,7 +2202,7 @@ class SigRecord : public ResourceRecord, public Clearable * @param[in] aExpiration The expiration time value (seconds since Jan 1, 1970). * */ - void SetExpiration(uint32_t aExpiration) { mExpiration = HostSwap32(aExpiration); } + void SetExpiration(uint32_t aExpiration) { mExpiration = BigEndian::HostSwap32(aExpiration); } /** * Returns the SIG record's inception time value. @@ -2213,7 +2210,7 @@ class SigRecord : public ResourceRecord, public Clearable * @returns The inception time value (seconds since Jan 1, 1970). * */ - uint32_t GetInception(void) const { return HostSwap32(mInception); } + uint32_t GetInception(void) const { return BigEndian::HostSwap32(mInception); } /** * Sets the SIG record's inception time value. @@ -2221,7 +2218,7 @@ class SigRecord : public ResourceRecord, public Clearable * @param[in] aInception The inception time value (seconds since Jan 1, 1970). * */ - void SetInception(uint32_t aInception) { mInception = HostSwap32(aInception); } + void SetInception(uint32_t aInception) { mInception = BigEndian::HostSwap32(aInception); } /** * Returns the SIG record's key tag value. @@ -2229,7 +2226,7 @@ class SigRecord : public ResourceRecord, public Clearable * @returns The key tag value. * */ - uint16_t GetKeyTag(void) const { return HostSwap16(mKeyTag); } + uint16_t GetKeyTag(void) const { return BigEndian::HostSwap16(mKeyTag); } /** * Sets the SIG record's key tag value. @@ -2237,7 +2234,7 @@ class SigRecord : public ResourceRecord, public Clearable * @param[in] aKeyTag The key tag value. * */ - void SetKeyTag(uint16_t aKeyTag) { mKeyTag = HostSwap16(aKeyTag); } + void SetKeyTag(uint16_t aKeyTag) { mKeyTag = BigEndian::HostSwap16(aKeyTag); } /** * Returns a pointer to the start of the record data fields. @@ -2422,7 +2419,7 @@ class Option * @returns The option code value. * */ - uint16_t GetOptionCode(void) const { return HostSwap16(mOptionCode); } + uint16_t GetOptionCode(void) const { return BigEndian::HostSwap16(mOptionCode); } /** * Sets the option code value. @@ -2430,7 +2427,7 @@ class Option * @param[in] aOptionCode The option code value. * */ - void SetOptionCode(uint16_t aOptionCode) { mOptionCode = HostSwap16(aOptionCode); } + void SetOptionCode(uint16_t aOptionCode) { mOptionCode = BigEndian::HostSwap16(aOptionCode); } /** * Returns the option length value. @@ -2438,7 +2435,7 @@ class Option * @returns The option length (size of option data in bytes). * */ - uint16_t GetOptionLength(void) const { return HostSwap16(mOptionLength); } + uint16_t GetOptionLength(void) const { return BigEndian::HostSwap16(mOptionLength); } /** * Sets the option length value. @@ -2446,7 +2443,7 @@ class Option * @param[in] aOptionLength The option length (size of option data in bytes). * */ - void SetOptionLength(uint16_t aOptionLength) { mOptionLength = HostSwap16(aOptionLength); } + void SetOptionLength(uint16_t aOptionLength) { mOptionLength = BigEndian::HostSwap16(aOptionLength); } /** * Returns the size of (number of bytes) in the Option and its data. @@ -2519,7 +2516,7 @@ class LeaseOption : public Option * @returns The lease interval value (in seconds). * */ - uint32_t GetLeaseInterval(void) const { return HostSwap32(mLeaseInterval); } + uint32_t GetLeaseInterval(void) const { return BigEndian::HostSwap32(mLeaseInterval); } /** * Returns the Update Lease OPT record's key lease interval value. @@ -2531,7 +2528,7 @@ class LeaseOption : public Option */ uint32_t GetKeyLeaseInterval(void) const { - return IsShortVariant() ? GetLeaseInterval() : HostSwap32(mKeyLeaseInterval); + return IsShortVariant() ? GetLeaseInterval() : BigEndian::HostSwap32(mKeyLeaseInterval); } /** @@ -2555,8 +2552,11 @@ class LeaseOption : public Option static constexpr uint16_t kShortLength = sizeof(uint32_t); // lease only. static constexpr uint16_t kLongLength = sizeof(uint32_t) + sizeof(uint32_t); // lease and key lease values - void SetLeaseInterval(uint32_t aLeaseInterval) { mLeaseInterval = HostSwap32(aLeaseInterval); } - void SetKeyLeaseInterval(uint32_t aKeyLeaseInterval) { mKeyLeaseInterval = HostSwap32(aKeyLeaseInterval); } + void SetLeaseInterval(uint32_t aLeaseInterval) { mLeaseInterval = BigEndian::HostSwap32(aLeaseInterval); } + void SetKeyLeaseInterval(uint32_t aKeyLeaseInterval) + { + mKeyLeaseInterval = BigEndian::HostSwap32(aKeyLeaseInterval); + } uint32_t mLeaseInterval; uint32_t mKeyLeaseInterval; @@ -2592,7 +2592,7 @@ class Question * @returns The type of the question. * */ - uint16_t GetType(void) const { return HostSwap16(mType); } + uint16_t GetType(void) const { return BigEndian::HostSwap16(mType); } /** * Sets the type of the question. @@ -2600,7 +2600,7 @@ class Question * @param[in] aType The type of the question. * */ - void SetType(uint16_t aType) { mType = HostSwap16(aType); } + void SetType(uint16_t aType) { mType = BigEndian::HostSwap16(aType); } /** * Returns the class of the question. @@ -2608,7 +2608,7 @@ class Question * @returns The class of the question. * */ - uint16_t GetClass(void) const { return HostSwap16(mClass); } + uint16_t GetClass(void) const { return BigEndian::HostSwap16(mClass); } /** * Sets the class of the question. @@ -2616,7 +2616,7 @@ class Question * @param[in] aClass The class of the question. * */ - void SetClass(uint16_t aClass) { mClass = HostSwap16(aClass); } + void SetClass(uint16_t aClass) { mClass = BigEndian::HostSwap16(aClass); } private: uint16_t mType; // The type of the data in question section. diff --git a/src/core/net/icmp6.hpp b/src/core/net/icmp6.hpp index e24b9445ce5..ae5239a9908 100644 --- a/src/core/net/icmp6.hpp +++ b/src/core/net/icmp6.hpp @@ -49,8 +49,6 @@ namespace ot { namespace Ip6 { -using ot::Encoding::BigEndian::HostSwap16; - /** * @addtogroup core-ip6-icmp6 * @@ -158,7 +156,7 @@ class Icmp : public InstanceLocator, private NonCopyable * @returns The ICMPv6 message checksum. * */ - uint16_t GetChecksum(void) const { return HostSwap16(mChecksum); } + uint16_t GetChecksum(void) const { return BigEndian::HostSwap16(mChecksum); } /** * Sets the ICMPv6 message checksum. @@ -166,7 +164,7 @@ class Icmp : public InstanceLocator, private NonCopyable * @param[in] aChecksum The ICMPv6 message checksum. * */ - void SetChecksum(uint16_t aChecksum) { mChecksum = HostSwap16(aChecksum); } + void SetChecksum(uint16_t aChecksum) { mChecksum = BigEndian::HostSwap16(aChecksum); } /** * Returns the ICMPv6 message ID for Echo Requests and Replies. @@ -174,7 +172,7 @@ class Icmp : public InstanceLocator, private NonCopyable * @returns The ICMPv6 message ID. * */ - uint16_t GetId(void) const { return HostSwap16(mData.m16[0]); } + uint16_t GetId(void) const { return BigEndian::HostSwap16(mData.m16[0]); } /** * Sets the ICMPv6 message ID for Echo Requests and Replies. @@ -182,7 +180,7 @@ class Icmp : public InstanceLocator, private NonCopyable * @param[in] aId The ICMPv6 message ID. * */ - void SetId(uint16_t aId) { mData.m16[0] = HostSwap16(aId); } + void SetId(uint16_t aId) { mData.m16[0] = BigEndian::HostSwap16(aId); } /** * Returns the ICMPv6 message sequence for Echo Requests and Replies. @@ -190,7 +188,7 @@ class Icmp : public InstanceLocator, private NonCopyable * @returns The ICMPv6 message sequence. * */ - uint16_t GetSequence(void) const { return HostSwap16(mData.m16[1]); } + uint16_t GetSequence(void) const { return BigEndian::HostSwap16(mData.m16[1]); } /** * Sets the ICMPv6 message sequence for Echo Requests and Replies. @@ -198,7 +196,7 @@ class Icmp : public InstanceLocator, private NonCopyable * @param[in] aSequence The ICMPv6 message sequence. * */ - void SetSequence(uint16_t aSequence) { mData.m16[1] = HostSwap16(aSequence); } + void SetSequence(uint16_t aSequence) { mData.m16[1] = BigEndian::HostSwap16(aSequence); } } OT_TOOL_PACKED_END; /** diff --git a/src/core/net/ip4_types.cpp b/src/core/net/ip4_types.cpp index a6bc1c2fb83..7f03a3e0e46 100644 --- a/src/core/net/ip4_types.cpp +++ b/src/core/net/ip4_types.cpp @@ -109,7 +109,7 @@ void Address::ExtractFromIp6Address(uint8_t aPrefixLength, const Ip6::Address &a void Address::SynthesizeFromCidrAndHost(const Cidr &aCidr, const uint32_t aHost) { - mFields.m32 = (aCidr.mAddress.mFields.m32 & aCidr.SubnetMask()) | (HostSwap32(aHost) & aCidr.HostMask()); + mFields.m32 = (aCidr.mAddress.mFields.m32 & aCidr.SubnetMask()) | (BigEndian::HostSwap32(aHost) & aCidr.HostMask()); } void Address::ToString(StringWriter &aWriter) const diff --git a/src/core/net/ip4_types.hpp b/src/core/net/ip4_types.hpp index 86d908f409d..8095a818aaf 100644 --- a/src/core/net/ip4_types.hpp +++ b/src/core/net/ip4_types.hpp @@ -65,9 +65,6 @@ class Address; */ namespace Ip4 { -using Encoding::BigEndian::HostSwap16; -using Encoding::BigEndian::HostSwap32; - using Ecn = Ip6::Ecn; /** @@ -279,7 +276,7 @@ class Cidr : public otIp4Cidr, public Unequatable, public Clearable> mLength); + return BigEndian::HostSwap32(0xffffffffLL >> mLength); } uint32_t SubnetMask(void) const { return ~HostMask(); } @@ -386,7 +383,7 @@ class Header : public Clearable
* @returns The IPv4 Payload Length value. * */ - uint16_t GetTotalLength(void) const { return HostSwap16(mTotalLength); } + uint16_t GetTotalLength(void) const { return BigEndian::HostSwap16(mTotalLength); } /** * Sets the IPv4 Payload Length value. @@ -394,7 +391,7 @@ class Header : public Clearable
* @param[in] aLength The IPv4 Payload Length value. * */ - void SetTotalLength(uint16_t aLength) { mTotalLength = HostSwap16(aLength); } + void SetTotalLength(uint16_t aLength) { mTotalLength = BigEndian::HostSwap16(aLength); } /** * Returns the IPv4 payload protocol. @@ -418,7 +415,7 @@ class Header : public Clearable
* @returns The checksum field in the IPv4 header. * */ - uint16_t GetChecksum(void) const { return HostSwap16(mHeaderChecksum); } + uint16_t GetChecksum(void) const { return BigEndian::HostSwap16(mHeaderChecksum); } /** * Sets the IPv4 header checksum, the checksum is in host endian. @@ -426,7 +423,7 @@ class Header : public Clearable
* @param[in] aChecksum The checksum for the IPv4 header. * */ - void SetChecksum(uint16_t aChecksum) { mHeaderChecksum = HostSwap16(aChecksum); } + void SetChecksum(uint16_t aChecksum) { mHeaderChecksum = BigEndian::HostSwap16(aChecksum); } /** * Returns the IPv4 Identification value. @@ -434,7 +431,7 @@ class Header : public Clearable
* @returns The IPv4 Identification value. * */ - uint16_t GetIdentification(void) const { return HostSwap16(mIdentification); } + uint16_t GetIdentification(void) const { return BigEndian::HostSwap16(mIdentification); } /** * Sets the IPv4 Identification value. @@ -442,7 +439,7 @@ class Header : public Clearable
* @param[in] aIdentification The IPv4 Identification value. * */ - void SetIdentification(uint16_t aIdentification) { mIdentification = HostSwap16(aIdentification); } + void SetIdentification(uint16_t aIdentification) { mIdentification = BigEndian::HostSwap16(aIdentification); } /** * Returns the IPv4 Time-to-Live value. @@ -527,7 +524,7 @@ class Header : public Clearable
* @returns Whether don't fragment flag is set. * */ - bool GetDf(void) const { return HostSwap16(mFlagsFragmentOffset) & kFlagsDf; } + bool GetDf(void) const { return BigEndian::HostSwap16(mFlagsFragmentOffset) & kFlagsDf; } /** * Returns the Mf flag in the IPv4 header. @@ -535,7 +532,7 @@ class Header : public Clearable
* @returns Whether more fragments flag is set. * */ - bool GetMf(void) const { return HostSwap16(mFlagsFragmentOffset) & kFlagsMf; } + bool GetMf(void) const { return BigEndian::HostSwap16(mFlagsFragmentOffset) & kFlagsMf; } /** * Returns the fragment offset in the IPv4 header. @@ -543,7 +540,7 @@ class Header : public Clearable
* @returns The fragment offset of the IPv4 packet. * */ - uint16_t GetFragmentOffset(void) const { return HostSwap16(mFlagsFragmentOffset) & kFragmentOffsetMask; } + uint16_t GetFragmentOffset(void) const { return BigEndian::HostSwap16(mFlagsFragmentOffset) & kFragmentOffsetMask; } private: // IPv4 header @@ -660,7 +657,7 @@ class Icmp * @returns The checksum of the ICMP message. * */ - uint16_t GetChecksum(void) const { return HostSwap16(mChecksum); } + uint16_t GetChecksum(void) const { return BigEndian::HostSwap16(mChecksum); } /** * Sets the checksum field in the ICMP message. @@ -668,7 +665,7 @@ class Icmp * @param[in] aChecksum The checksum of the ICMP message. * */ - void SetChecksum(uint16_t aChecksum) { mChecksum = HostSwap16(aChecksum); } + void SetChecksum(uint16_t aChecksum) { mChecksum = BigEndian::HostSwap16(aChecksum); } /** * Returns the rest of header field in the ICMP message. diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index df619845120..b7759ef65d0 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1246,7 +1246,7 @@ Error Ip6::HandleDatagram(OwnedPtr aMessagePtr, const void *aLinkMessag SuccessOrExit( error = aMessagePtr->Read(aMessagePtr->GetOffset() + Udp::Header::kDestPortFieldOffset, destPort)); - destPort = HostSwap16(destPort); + destPort = BigEndian::HostSwap16(destPort); if (destPort == Tmf::kUdpPort) { @@ -1262,7 +1262,7 @@ Error Ip6::HandleDatagram(OwnedPtr aMessagePtr, const void *aLinkMessag SuccessOrExit( error = aMessagePtr->Read(aMessagePtr->GetOffset() + Udp::Header::kDestPortFieldOffset, destPort)); - destPort = HostSwap16(destPort); + destPort = BigEndian::HostSwap16(destPort); if (nextHeader == kProtoUdp) { diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 945b0d041dc..1c700b590b5 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -73,9 +73,6 @@ namespace ot { */ namespace Ip6 { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * @addtogroup core-ipv6 * diff --git a/src/core/net/ip6_address.cpp b/src/core/net/ip6_address.cpp index 68db559d368..4c092267ecd 100644 --- a/src/core/net/ip6_address.cpp +++ b/src/core/net/ip6_address.cpp @@ -46,8 +46,6 @@ #include "net/ip4_types.hpp" #include "net/netif.hpp" -using ot::Encoding::BigEndian::HostSwap32; - namespace ot { namespace Ip6 { @@ -72,7 +70,8 @@ void Prefix::Set(const uint8_t *aPrefix, uint8_t aLength) bool Prefix::IsLinkLocal(void) const { - return (mLength >= 10) && ((mPrefix.mFields.m16[0] & HostSwap16(0xffc0)) == HostSwap16(0xfe80)); + return (mLength >= 10) && + ((mPrefix.mFields.m16[0] & BigEndian::HostSwap16(0xffc0)) == BigEndian::HostSwap16(0xfe80)); } bool Prefix::IsMulticast(void) const { return (mLength >= 8) && (mPrefix.mFields.m8[0] == 0xff); } @@ -251,8 +250,8 @@ bool InterfaceIdentifier::IsReservedSubnetAnycast(void) const // | 1111110111...111 | anycast ID | // +------------------+------------+ - return (mFields.m32[0] == HostSwap32(0xfdffffff) && mFields.m16[2] == HostSwap16(0xffff) && mFields.m8[6] == 0xff && - mFields.m8[7] >= 0x80); + return (mFields.m32[0] == BigEndian::HostSwap32(0xfdffffff) && mFields.m16[2] == BigEndian::HostSwap16(0xffff) && + mFields.m8[6] == 0xff && mFields.m8[7] >= 0x80); } void InterfaceIdentifier::GenerateRandom(void) { SuccessOrAssert(Random::Crypto::Fill(*this)); } @@ -283,15 +282,15 @@ void InterfaceIdentifier::ConvertToMacAddress(Mac::Address &aMacAddress) const void InterfaceIdentifier::SetToLocator(uint16_t aLocator) { // Locator IID pattern `0000:00ff:fe00:xxxx` - mFields.m32[0] = HostSwap32(0x000000ff); - mFields.m16[2] = HostSwap16(0xfe00); - mFields.m16[3] = HostSwap16(aLocator); + mFields.m32[0] = BigEndian::HostSwap32(0x000000ff); + mFields.m16[2] = BigEndian::HostSwap16(0xfe00); + mFields.m16[3] = BigEndian::HostSwap16(aLocator); } bool InterfaceIdentifier::IsLocator(void) const { // Locator IID pattern 0000:00ff:fe00:xxxx - return (mFields.m32[0] == HostSwap32(0x000000ff) && mFields.m16[2] == HostSwap16(0xfe00)); + return (mFields.m32[0] == BigEndian::HostSwap32(0x000000ff) && mFields.m16[2] == BigEndian::HostSwap16(0xfe00)); } bool InterfaceIdentifier::IsRoutingLocator(void) const @@ -340,21 +339,25 @@ bool Address::IsUnspecified(void) const bool Address::IsLoopback(void) const { - return (mFields.m32[0] == 0 && mFields.m32[1] == 0 && mFields.m32[2] == 0 && mFields.m32[3] == HostSwap32(1)); + return (mFields.m32[0] == 0 && mFields.m32[1] == 0 && mFields.m32[2] == 0 && + mFields.m32[3] == BigEndian::HostSwap32(1)); } -bool Address::IsLinkLocal(void) const { return (mFields.m16[0] & HostSwap16(0xffc0)) == HostSwap16(0xfe80); } +bool Address::IsLinkLocal(void) const +{ + return (mFields.m16[0] & BigEndian::HostSwap16(0xffc0)) == BigEndian::HostSwap16(0xfe80); +} void Address::SetToLinkLocalAddress(const Mac::ExtAddress &aExtAddress) { - mFields.m32[0] = HostSwap32(0xfe800000); + mFields.m32[0] = BigEndian::HostSwap32(0xfe800000); mFields.m32[1] = 0; GetIid().SetFromExtAddress(aExtAddress); } void Address::SetToLinkLocalAddress(const InterfaceIdentifier &aIid) { - mFields.m32[0] = HostSwap32(0xfe800000); + mFields.m32[0] = BigEndian::HostSwap32(0xfe800000); mFields.m32[1] = 0; SetIid(aIid); } @@ -612,7 +615,7 @@ Error Address::ParseFrom(const char *aString, char aTerminatorChar) VerifyOrExit((*aString == kColonChar) || (*aString == aTerminatorChar)); VerifyOrExit(index < endIndex); - mFields.m16[index++] = HostSwap16(static_cast(value)); + mFields.m16[index++] = BigEndian::HostSwap16(static_cast(value)); if (*aString == kColonChar) { @@ -685,7 +688,7 @@ void Address::AppendHexWords(StringWriter &aWriter, uint8_t aLength) const aWriter.Append(":"); } - aWriter.Append("%x", HostSwap16(mFields.m16[index])); + aWriter.Append("%x", BigEndian::HostSwap16(mFields.m16[index])); } } diff --git a/src/core/net/ip6_address.hpp b/src/core/net/ip6_address.hpp index f836f272174..b066557de6d 100644 --- a/src/core/net/ip6_address.hpp +++ b/src/core/net/ip6_address.hpp @@ -47,8 +47,6 @@ #include "common/string.hpp" #include "mac/mac_types.hpp" -using ot::Encoding::BigEndian::HostSwap16; - namespace ot { namespace Ip4 { @@ -121,7 +119,7 @@ class Prefix : public otIp6Prefix, public Clearable, public Unequatable< * @returns The 16-bit subnet ID. * */ - uint16_t GetSubnetId(void) const { return HostSwap16(mPrefix.mFields.m16[3]); } + uint16_t GetSubnetId(void) const { return BigEndian::HostSwap16(mPrefix.mFields.m16[3]); } /** * Gets the prefix length (in bits). @@ -162,7 +160,7 @@ class Prefix : public otIp6Prefix, public Clearable, public Unequatable< * @param[in] aSubnetId A 16-bit subnet ID. * */ - void SetSubnetId(uint16_t aSubnetId) { mPrefix.mFields.m16[3] = HostSwap16(aSubnetId); } + void SetSubnetId(uint16_t aSubnetId) { mPrefix.mFields.m16[3] = BigEndian::HostSwap16(aSubnetId); } /** * Set the prefix length. @@ -529,7 +527,7 @@ class InterfaceIdentifier : public otIp6InterfaceIdentifier, * @returns The RLOC16 or ALOC16. * */ - uint16_t GetLocator(void) const { return HostSwap16(mFields.m16[3]); } + uint16_t GetLocator(void) const { return BigEndian::HostSwap16(mFields.m16[3]); } /** * Sets the Interface Identifier (IID) address locator field. @@ -540,7 +538,7 @@ class InterfaceIdentifier : public otIp6InterfaceIdentifier, * @param[in] aLocator RLOC16 or ALOC16. * */ - void SetLocator(uint16_t aLocator) { mFields.m16[3] = HostSwap16(aLocator); } + void SetLocator(uint16_t aLocator) { mFields.m16[3] = BigEndian::HostSwap16(aLocator); } /** * Applies a prefix to IID. diff --git a/src/core/net/ip6_headers.hpp b/src/core/net/ip6_headers.hpp index 2fc55c5aa33..8289c53b0a0 100644 --- a/src/core/net/ip6_headers.hpp +++ b/src/core/net/ip6_headers.hpp @@ -57,9 +57,6 @@ namespace ot { */ namespace Ip6 { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * @addtogroup core-ipv6 * @@ -133,7 +130,7 @@ class Header : public Clearable
* @returns The Version, Traffic Class, and Flow fields as a 32-bit value. * */ - uint32_t GetVerionTrafficClassFlow(void) const { return HostSwap32(mVerTcFlow.m32); } + uint32_t GetVerionTrafficClassFlow(void) const { return BigEndian::HostSwap32(mVerTcFlow.m32); } /** * Sets the combination of Version, Traffic Class, and Flow fields as a 32-bit value. @@ -141,7 +138,7 @@ class Header : public Clearable
* @param[in] aVerTcFlow The Version, Traffic Class, and Flow fields as a 32-bit value. * */ - void SetVerionTrafficClassFlow(uint32_t aVerTcFlow) { mVerTcFlow.m32 = HostSwap32(aVerTcFlow); } + void SetVerionTrafficClassFlow(uint32_t aVerTcFlow) { mVerTcFlow.m32 = BigEndian::HostSwap32(aVerTcFlow); } /** * Gets the Traffic Class field. @@ -151,7 +148,8 @@ class Header : public Clearable
*/ uint8_t GetTrafficClass(void) const { - return static_cast((HostSwap16(mVerTcFlow.m16[0]) & kTrafficClassMask) >> kTrafficClassOffset); + return static_cast((BigEndian::HostSwap16(mVerTcFlow.m16[0]) & kTrafficClassMask) >> + kTrafficClassOffset); } /** @@ -162,8 +160,9 @@ class Header : public Clearable
*/ void SetTrafficClass(uint8_t aTc) { - mVerTcFlow.m16[0] = HostSwap16((HostSwap16(mVerTcFlow.m16[0]) & ~kTrafficClassMask) | - ((static_cast(aTc) << kTrafficClassOffset) & kTrafficClassMask)); + mVerTcFlow.m16[0] = + BigEndian::HostSwap16((BigEndian::HostSwap16(mVerTcFlow.m16[0]) & ~kTrafficClassMask) | + ((static_cast(aTc) << kTrafficClassOffset) & kTrafficClassMask)); } /** @@ -174,7 +173,7 @@ class Header : public Clearable
*/ uint8_t GetDscp(void) const { - return static_cast((HostSwap16(mVerTcFlow.m16[0]) & kDscpMask) >> kDscpOffset); + return static_cast((BigEndian::HostSwap16(mVerTcFlow.m16[0]) & kDscpMask) >> kDscpOffset); } /** @@ -185,8 +184,8 @@ class Header : public Clearable
*/ void SetDscp(uint8_t aDscp) { - mVerTcFlow.m16[0] = HostSwap16((HostSwap16(mVerTcFlow.m16[0]) & ~kDscpMask) | - ((static_cast(aDscp) << kDscpOffset) & kDscpMask)); + mVerTcFlow.m16[0] = BigEndian::HostSwap16((BigEndian::HostSwap16(mVerTcFlow.m16[0]) & ~kDscpMask) | + ((static_cast(aDscp) << kDscpOffset) & kDscpMask)); } /** @@ -211,7 +210,7 @@ class Header : public Clearable
* @returns The Flow value. * */ - uint32_t GetFlow(void) const { return HostSwap32(mVerTcFlow.m32) & kFlowMask; } + uint32_t GetFlow(void) const { return BigEndian::HostSwap32(mVerTcFlow.m32) & kFlowMask; } /** * Sets the 20-bit Flow field in IPv6 header. @@ -221,7 +220,8 @@ class Header : public Clearable
*/ void SetFlow(uint32_t aFlow) { - mVerTcFlow.m32 = HostSwap32((HostSwap32(mVerTcFlow.m32) & ~kFlowMask) | (aFlow & kFlowMask)); + mVerTcFlow.m32 = + BigEndian::HostSwap32((BigEndian::HostSwap32(mVerTcFlow.m32) & ~kFlowMask) | (aFlow & kFlowMask)); } /** @@ -230,7 +230,7 @@ class Header : public Clearable
* @returns The IPv6 Payload Length value. * */ - uint16_t GetPayloadLength(void) const { return HostSwap16(mPayloadLength); } + uint16_t GetPayloadLength(void) const { return BigEndian::HostSwap16(mPayloadLength); } /** * Sets the IPv6 Payload Length value. @@ -238,7 +238,7 @@ class Header : public Clearable
* @param[in] aLength The IPv6 Payload Length value. * */ - void SetPayloadLength(uint16_t aLength) { mPayloadLength = HostSwap16(aLength); } + void SetPayloadLength(uint16_t aLength) { mPayloadLength = BigEndian::HostSwap16(aLength); } /** * Returns the IPv6 Next Header value. @@ -639,7 +639,7 @@ class FragmentHeader * @returns The Fragment Offset value. * */ - uint16_t GetOffset(void) const { return (HostSwap16(mOffsetMore) & kOffsetMask) >> kOffsetOffset; } + uint16_t GetOffset(void) const { return (BigEndian::HostSwap16(mOffsetMore) & kOffsetMask) >> kOffsetOffset; } /** * Sets the Fragment Offset value. @@ -648,9 +648,9 @@ class FragmentHeader */ void SetOffset(uint16_t aOffset) { - uint16_t tmp = HostSwap16(mOffsetMore); + uint16_t tmp = BigEndian::HostSwap16(mOffsetMore); tmp = (tmp & ~kOffsetMask) | ((aOffset << kOffsetOffset) & kOffsetMask); - mOffsetMore = HostSwap16(tmp); + mOffsetMore = BigEndian::HostSwap16(tmp); } /** @@ -659,19 +659,19 @@ class FragmentHeader * @returns The M flag value. * */ - bool IsMoreFlagSet(void) const { return HostSwap16(mOffsetMore) & kMoreFlag; } + bool IsMoreFlagSet(void) const { return BigEndian::HostSwap16(mOffsetMore) & kMoreFlag; } /** * Clears the M flag value. * */ - void ClearMoreFlag(void) { mOffsetMore = HostSwap16(HostSwap16(mOffsetMore) & ~kMoreFlag); } + void ClearMoreFlag(void) { mOffsetMore = BigEndian::HostSwap16(BigEndian::HostSwap16(mOffsetMore) & ~kMoreFlag); } /** * Sets the M flag value. * */ - void SetMoreFlag(void) { mOffsetMore = HostSwap16(HostSwap16(mOffsetMore) | kMoreFlag); } + void SetMoreFlag(void) { mOffsetMore = BigEndian::HostSwap16(BigEndian::HostSwap16(mOffsetMore) | kMoreFlag); } /** * Returns the frame identification. diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index 35953b53fe5..76fe15984ef 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -140,7 +140,7 @@ class MplOption : public Option * @returns The MPL Seed Id value. * */ - uint16_t GetSeedId(void) const { return HostSwap16(mSeedId); } + uint16_t GetSeedId(void) const { return BigEndian::HostSwap16(mSeedId); } /** * Sets the MPL Seed Id value. @@ -148,7 +148,7 @@ class MplOption : public Option * @param[in] aSeedId The MPL Seed Id value. * */ - void SetSeedId(uint16_t aSeedId) { mSeedId = HostSwap16(aSeedId); } + void SetSeedId(uint16_t aSeedId) { mSeedId = BigEndian::HostSwap16(aSeedId); } private: static constexpr uint8_t kSeedIdLengthMask = 3 << 6; diff --git a/src/core/net/nd6.hpp b/src/core/net/nd6.hpp index bbf6a6ea78f..c5cf766d91d 100644 --- a/src/core/net/nd6.hpp +++ b/src/core/net/nd6.hpp @@ -51,9 +51,6 @@ #include "net/ip6.hpp" #include "thread/network_data_types.hpp" -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - namespace ot { namespace Ip6 { namespace Nd { @@ -235,7 +232,7 @@ class PrefixInfoOption : public Option, private Clearable * @param[in] aValidLifetime The valid lifetime in seconds. * */ - void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = HostSwap32(aValidLifetime); } + void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = BigEndian::HostSwap32(aValidLifetime); } /** * THis method gets the valid lifetime of the prefix in seconds. @@ -243,7 +240,7 @@ class PrefixInfoOption : public Option, private Clearable * @returns The valid lifetime in seconds. * */ - uint32_t GetValidLifetime(void) const { return HostSwap32(mValidLifetime); } + uint32_t GetValidLifetime(void) const { return BigEndian::HostSwap32(mValidLifetime); } /** * Sets the preferred lifetime of the prefix in seconds. @@ -251,7 +248,10 @@ class PrefixInfoOption : public Option, private Clearable * @param[in] aPreferredLifetime The preferred lifetime in seconds. * */ - void SetPreferredLifetime(uint32_t aPreferredLifetime) { mPreferredLifetime = HostSwap32(aPreferredLifetime); } + void SetPreferredLifetime(uint32_t aPreferredLifetime) + { + mPreferredLifetime = BigEndian::HostSwap32(aPreferredLifetime); + } /** * THis method returns the preferred lifetime of the prefix in seconds. @@ -259,7 +259,7 @@ class PrefixInfoOption : public Option, private Clearable * @returns The preferred lifetime in seconds. * */ - uint32_t GetPreferredLifetime(void) const { return HostSwap32(mPreferredLifetime); } + uint32_t GetPreferredLifetime(void) const { return BigEndian::HostSwap32(mPreferredLifetime); } /** * Sets the prefix. @@ -367,7 +367,7 @@ class RouteInfoOption : public Option, private Clearable * @param[in] aLifetime The lifetime of the route in seconds. * */ - void SetRouteLifetime(uint32_t aLifetime) { mRouteLifetime = HostSwap32(aLifetime); } + void SetRouteLifetime(uint32_t aLifetime) { mRouteLifetime = BigEndian::HostSwap32(aLifetime); } /** * Gets Route Lifetime in seconds. @@ -375,7 +375,7 @@ class RouteInfoOption : public Option, private Clearable * @returns The Route Lifetime in seconds. * */ - uint32_t GetRouteLifetime(void) const { return HostSwap32(mRouteLifetime); } + uint32_t GetRouteLifetime(void) const { return BigEndian::HostSwap32(mRouteLifetime); } /** * Sets the prefix and adjusts the option length based on the prefix length. @@ -562,7 +562,7 @@ class RouterAdvertMessage * @param[in] aChecksum The checksum value. * */ - void SetChecksum(uint16_t aChecksum) { mChecksum = HostSwap16(aChecksum); } + void SetChecksum(uint16_t aChecksum) { mChecksum = BigEndian::HostSwap16(aChecksum); } /** * Sets the Router Lifetime in seconds. @@ -570,7 +570,7 @@ class RouterAdvertMessage * @param[in] aRouterLifetime The router lifetime in seconds. * */ - void SetRouterLifetime(uint16_t aRouterLifetime) { mRouterLifetime = HostSwap16(aRouterLifetime); } + void SetRouterLifetime(uint16_t aRouterLifetime) { mRouterLifetime = BigEndian::HostSwap16(aRouterLifetime); } /** * Gets the Router Lifetime (in seconds). @@ -580,7 +580,7 @@ class RouterAdvertMessage * @returns The router lifetime in seconds. * */ - uint16_t GetRouterLifetime(void) const { return HostSwap16(mRouterLifetime); } + uint16_t GetRouterLifetime(void) const { return BigEndian::HostSwap16(mRouterLifetime); } /** * Sets the default router preference. diff --git a/src/core/net/sntp_client.hpp b/src/core/net/sntp_client.hpp index 3a513aa4e09..d6d4dad3c6b 100644 --- a/src/core/net/sntp_client.hpp +++ b/src/core/net/sntp_client.hpp @@ -50,8 +50,6 @@ namespace ot { namespace Sntp { -using ot::Encoding::BigEndian::HostSwap32; - /** * Implements SNTP client. * @@ -153,40 +151,70 @@ class Client : private NonCopyable uint8_t GetPrecision(void) const { return mPrecision; } void SetPrecision(uint8_t aPrecision) { mPrecision = aPrecision; } - uint32_t GetRootDelay(void) const { return HostSwap32(mRootDelay); } - void SetRootDelay(uint32_t aRootDelay) { mRootDelay = HostSwap32(aRootDelay); } + uint32_t GetRootDelay(void) const { return BigEndian::HostSwap32(mRootDelay); } + void SetRootDelay(uint32_t aRootDelay) { mRootDelay = BigEndian::HostSwap32(aRootDelay); } - uint32_t GetRootDispersion(void) const { return HostSwap32(mRootDispersion); } - void SetRootDispersion(uint32_t aRootDispersion) { mRootDispersion = HostSwap32(aRootDispersion); } + uint32_t GetRootDispersion(void) const { return BigEndian::HostSwap32(mRootDispersion); } + void SetRootDispersion(uint32_t aRootDispersion) { mRootDispersion = BigEndian::HostSwap32(aRootDispersion); } - uint32_t GetReferenceId(void) const { return HostSwap32(mReferenceId); } - void SetReferenceId(uint32_t aReferenceId) { mReferenceId = HostSwap32(aReferenceId); } + uint32_t GetReferenceId(void) const { return BigEndian::HostSwap32(mReferenceId); } + void SetReferenceId(uint32_t aReferenceId) { mReferenceId = BigEndian::HostSwap32(aReferenceId); } char *GetKissCode(void) { return reinterpret_cast(&mReferenceId); } - uint32_t GetReferenceTimestampSeconds(void) const { return HostSwap32(mReferenceTimestampSeconds); } - void SetReferenceTimestampSeconds(uint32_t aTimestamp) { mReferenceTimestampSeconds = HostSwap32(aTimestamp); } + uint32_t GetReferenceTimestampSeconds(void) const { return BigEndian::HostSwap32(mReferenceTimestampSeconds); } + void SetReferenceTimestampSeconds(uint32_t aTimestamp) + { + mReferenceTimestampSeconds = BigEndian::HostSwap32(aTimestamp); + } - uint32_t GetReferenceTimestampFraction(void) const { return HostSwap32(mReferenceTimestampFraction); } - void SetReferenceTimestampFraction(uint32_t aFraction) { mReferenceTimestampFraction = HostSwap32(aFraction); } + uint32_t GetReferenceTimestampFraction(void) const + { + return BigEndian::HostSwap32(mReferenceTimestampFraction); + } + void SetReferenceTimestampFraction(uint32_t aFraction) + { + mReferenceTimestampFraction = BigEndian::HostSwap32(aFraction); + } - uint32_t GetOriginateTimestampSeconds(void) const { return HostSwap32(mOriginateTimestampSeconds); } - void SetOriginateTimestampSeconds(uint32_t aTimestamp) { mOriginateTimestampSeconds = HostSwap32(aTimestamp); } + uint32_t GetOriginateTimestampSeconds(void) const { return BigEndian::HostSwap32(mOriginateTimestampSeconds); } + void SetOriginateTimestampSeconds(uint32_t aTimestamp) + { + mOriginateTimestampSeconds = BigEndian::HostSwap32(aTimestamp); + } - uint32_t GetOriginateTimestampFraction(void) const { return HostSwap32(mOriginateTimestampFraction); } - void SetOriginateTimestampFraction(uint32_t aFraction) { mOriginateTimestampFraction = HostSwap32(aFraction); } + uint32_t GetOriginateTimestampFraction(void) const + { + return BigEndian::HostSwap32(mOriginateTimestampFraction); + } + void SetOriginateTimestampFraction(uint32_t aFraction) + { + mOriginateTimestampFraction = BigEndian::HostSwap32(aFraction); + } - uint32_t GetReceiveTimestampSeconds(void) const { return HostSwap32(mReceiveTimestampSeconds); } - void SetReceiveTimestampSeconds(uint32_t aTimestamp) { mReceiveTimestampSeconds = HostSwap32(aTimestamp); } + uint32_t GetReceiveTimestampSeconds(void) const { return BigEndian::HostSwap32(mReceiveTimestampSeconds); } + void SetReceiveTimestampSeconds(uint32_t aTimestamp) + { + mReceiveTimestampSeconds = BigEndian::HostSwap32(aTimestamp); + } - uint32_t GetReceiveTimestampFraction(void) const { return HostSwap32(mReceiveTimestampFraction); } - void SetReceiveTimestampFraction(uint32_t aFraction) { mReceiveTimestampFraction = HostSwap32(aFraction); } + uint32_t GetReceiveTimestampFraction(void) const { return BigEndian::HostSwap32(mReceiveTimestampFraction); } + void SetReceiveTimestampFraction(uint32_t aFraction) + { + mReceiveTimestampFraction = BigEndian::HostSwap32(aFraction); + } - uint32_t GetTransmitTimestampSeconds(void) const { return HostSwap32(mTransmitTimestampSeconds); } - void SetTransmitTimestampSeconds(uint32_t aTimestamp) { mTransmitTimestampSeconds = HostSwap32(aTimestamp); } + uint32_t GetTransmitTimestampSeconds(void) const { return BigEndian::HostSwap32(mTransmitTimestampSeconds); } + void SetTransmitTimestampSeconds(uint32_t aTimestamp) + { + mTransmitTimestampSeconds = BigEndian::HostSwap32(aTimestamp); + } - uint32_t GetTransmitTimestampFraction(void) const { return HostSwap32(mTransmitTimestampFraction); } - void SetTransmitTimestampFraction(uint32_t aFraction) { mTransmitTimestampFraction = HostSwap32(aFraction); } + uint32_t GetTransmitTimestampFraction(void) const { return BigEndian::HostSwap32(mTransmitTimestampFraction); } + void SetTransmitTimestampFraction(uint32_t aFraction) + { + mTransmitTimestampFraction = BigEndian::HostSwap32(aFraction); + } private: static constexpr uint8_t kNtpVersion = 4; // Current NTP version. diff --git a/src/core/net/tcp6.cpp b/src/core/net/tcp6.cpp index dccb41bb2ef..d9712a3c642 100644 --- a/src/core/net/tcp6.cpp +++ b/src/core/net/tcp6.cpp @@ -54,9 +54,6 @@ namespace ot { namespace Ip6 { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - RegisterLogModule("Tcp"); static_assert(sizeof(struct tcpcb) == sizeof(Tcp::Endpoint::mTcb), "mTcb field in otTcpEndpoint is sized incorrectly"); @@ -133,7 +130,7 @@ const SockAddr &Tcp::Endpoint::GetLocalAddress(void) const static otSockAddr temp; memcpy(&temp.mAddress, &tp.laddr, sizeof(temp.mAddress)); - temp.mPort = HostSwap16(tp.lport); + temp.mPort = BigEndian::HostSwap16(tp.lport); return AsCoreType(&temp); } @@ -145,7 +142,7 @@ const SockAddr &Tcp::Endpoint::GetPeerAddress(void) const static otSockAddr temp; memcpy(&temp.mAddress, &tp.faddr, sizeof(temp.mAddress)); - temp.mPort = HostSwap16(tp.fport); + temp.mPort = BigEndian::HostSwap16(tp.fport); return AsCoreType(&temp); } @@ -159,7 +156,7 @@ Error Tcp::Endpoint::Bind(const SockAddr &aSockName) VerifyOrExit(Get().CanBind(aSockName), error = kErrorInvalidState); memcpy(&tp.laddr, &aSockName.mAddress, sizeof(tp.laddr)); - tp.lport = HostSwap16(aSockName.mPort); + tp.lport = BigEndian::HostSwap16(aSockName.mPort); error = kErrorNone; exit: @@ -179,7 +176,7 @@ Error Tcp::Endpoint::Connect(const SockAddr &aSockName, uint32_t aFlags) tp.t_flags &= ~TF_FASTOPEN; memcpy(&sin6p.sin6_addr, &aSockName.mAddress, sizeof(sin6p.sin6_addr)); - sin6p.sin6_port = HostSwap16(aSockName.mPort); + sin6p.sin6_port = BigEndian::HostSwap16(aSockName.mPort); error = BsdErrorToOtError(tcp6_usr_connect(&tp, &sin6p)); } else @@ -188,7 +185,7 @@ Error Tcp::Endpoint::Connect(const SockAddr &aSockName, uint32_t aFlags) /* Stash the destination address in tp. */ memcpy(&tp.faddr, &aSockName.mAddress, sizeof(tp.faddr)); - tp.fport = HostSwap16(aSockName.mPort); + tp.fport = BigEndian::HostSwap16(aSockName.mPort); } exit: @@ -530,8 +527,8 @@ bool Tcp::Endpoint::Matches(const MessageInfo &aMessageInfo) const const struct tcpcb *tp = &GetTcb(); VerifyOrExit(tp->t_state != TCP6S_CLOSED); - VerifyOrExit(tp->lport == HostSwap16(aMessageInfo.GetSockPort())); - VerifyOrExit(tp->fport == HostSwap16(aMessageInfo.GetPeerPort())); + VerifyOrExit(tp->lport == BigEndian::HostSwap16(aMessageInfo.GetSockPort())); + VerifyOrExit(tp->fport == BigEndian::HostSwap16(aMessageInfo.GetPeerPort())); VerifyOrExit(GetLocalIp6Address().IsUnspecified() || GetLocalIp6Address() == aMessageInfo.GetSockAddr()); VerifyOrExit(GetForeignIp6Address() == aMessageInfo.GetPeerAddr()); @@ -564,7 +561,7 @@ Instance &Tcp::Listener::GetInstance(void) const { return AsNonConst(AsCoreType( Error Tcp::Listener::Listen(const SockAddr &aSockName) { Error error; - uint16_t port = HostSwap16(aSockName.mPort); + uint16_t port = BigEndian::HostSwap16(aSockName.mPort); struct tcpcb_listen *tpl = &GetTcbListen(); VerifyOrExit(Get().CanBind(aSockName), error = kErrorInvalidState); @@ -614,7 +611,7 @@ bool Tcp::Listener::Matches(const MessageInfo &aMessageInfo) const const struct tcpcb_listen *tpl = &GetTcbListen(); VerifyOrExit(tpl->t_state == TCP6S_LISTEN); - VerifyOrExit(tpl->lport == HostSwap16(aMessageInfo.GetSockPort())); + VerifyOrExit(tpl->lport == BigEndian::HostSwap16(aMessageInfo.GetSockPort())); VerifyOrExit(GetLocalIp6Address().IsUnspecified() || GetLocalIp6Address() == aMessageInfo.GetSockAddr()); matches = true; @@ -662,8 +659,8 @@ Error Tcp::HandleMessage(ot::Ip6::Header &aIp6Header, Message &aMessage, Message tcpHeader = reinterpret_cast(&header[0]); tcp_fields_to_host(tcpHeader); - aMessageInfo.mPeerPort = HostSwap16(tcpHeader->th_sport); - aMessageInfo.mSockPort = HostSwap16(tcpHeader->th_dport); + aMessageInfo.mPeerPort = BigEndian::HostSwap16(tcpHeader->th_sport); + aMessageInfo.mSockPort = BigEndian::HostSwap16(tcpHeader->th_dport); endpoint = mEndpoints.FindMatching(aMessageInfo, endpointPrev); if (endpoint != nullptr) @@ -781,7 +778,7 @@ Error Tcp::BsdErrorToOtError(int aBsdError) bool Tcp::CanBind(const SockAddr &aSockName) { - uint16_t port = HostSwap16(aSockName.mPort); + uint16_t port = BigEndian::HostSwap16(aSockName.mPort); bool allowed = false; for (Endpoint &endpoint : mEndpoints) @@ -1013,7 +1010,7 @@ struct tcpcb *tcplp_sys_accept_ready(struct tcpcb_listen *aTcbListen, struct in6 VerifyOrExit(listener.mAcceptReadyCallback != nullptr); memcpy(&addr.mAddress, aAddr, sizeof(addr.mAddress)); - addr.mPort = HostSwap16(aPort); + addr.mPort = BigEndian::HostSwap16(aPort); action = listener.mAcceptReadyCallback(&listener, &addr, &endpointPtr); VerifyOrExit(tcp.IsInitialized(listener) && !listener.IsClosed()); @@ -1063,7 +1060,7 @@ bool tcplp_sys_accepted_connection(struct tcpcb_listen *aTcbListen, otSockAddr addr; memcpy(&addr.mAddress, aAddr, sizeof(addr.mAddress)); - addr.mPort = HostSwap16(aPort); + addr.mPort = BigEndian::HostSwap16(aPort); listener.mAcceptDoneCallback(&listener, &endpoint, &addr); if (!tcp.IsInitialized(endpoint) || endpoint.IsClosed()) @@ -1158,9 +1155,9 @@ uint32_t tcplp_sys_generate_isn() return isn; } -uint16_t tcplp_sys_hostswap16(uint16_t aHostPort) { return HostSwap16(aHostPort); } +uint16_t tcplp_sys_hostswap16(uint16_t aHostPort) { return BigEndian::HostSwap16(aHostPort); } -uint32_t tcplp_sys_hostswap32(uint32_t aHostPort) { return HostSwap32(aHostPort); } +uint32_t tcplp_sys_hostswap32(uint32_t aHostPort) { return BigEndian::HostSwap32(aHostPort); } } #endif // OPENTHREAD_CONFIG_TCP_ENABLE diff --git a/src/core/net/tcp6.hpp b/src/core/net/tcp6.hpp index 36812064557..1ffe8ef4be5 100644 --- a/src/core/net/tcp6.hpp +++ b/src/core/net/tcp6.hpp @@ -550,7 +550,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Source Port. * */ - uint16_t GetSourcePort(void) const { return HostSwap16(mSource); } + uint16_t GetSourcePort(void) const { return BigEndian::HostSwap16(mSource); } /** * Returns the TCP Destination Port. @@ -558,7 +558,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Destination Port. * */ - uint16_t GetDestinationPort(void) const { return HostSwap16(mDestination); } + uint16_t GetDestinationPort(void) const { return BigEndian::HostSwap16(mDestination); } /** * Returns the TCP Sequence Number. @@ -566,7 +566,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Sequence Number. * */ - uint32_t GetSequenceNumber(void) const { return HostSwap32(mSequenceNumber); } + uint32_t GetSequenceNumber(void) const { return BigEndian::HostSwap32(mSequenceNumber); } /** * Returns the TCP Acknowledgment Sequence Number. @@ -574,7 +574,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Acknowledgment Sequence Number. * */ - uint32_t GetAcknowledgmentNumber(void) const { return HostSwap32(mAckNumber); } + uint32_t GetAcknowledgmentNumber(void) const { return BigEndian::HostSwap32(mAckNumber); } /** * Returns the TCP Flags. @@ -582,7 +582,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Flags. * */ - uint16_t GetFlags(void) const { return HostSwap16(mFlags); } + uint16_t GetFlags(void) const { return BigEndian::HostSwap16(mFlags); } /** * Returns the TCP Window. @@ -590,7 +590,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Window. * */ - uint16_t GetWindow(void) const { return HostSwap16(mWindow); } + uint16_t GetWindow(void) const { return BigEndian::HostSwap16(mWindow); } /** * Returns the TCP Checksum. @@ -598,7 +598,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Checksum. * */ - uint16_t GetChecksum(void) const { return HostSwap16(mChecksum); } + uint16_t GetChecksum(void) const { return BigEndian::HostSwap16(mChecksum); } /** * Returns the TCP Urgent Pointer. @@ -606,7 +606,7 @@ class Tcp : public InstanceLocator, private NonCopyable * @returns The TCP Urgent Pointer. * */ - uint16_t GetUrgentPointer(void) const { return HostSwap16(mUrgentPointer); } + uint16_t GetUrgentPointer(void) const { return BigEndian::HostSwap16(mUrgentPointer); } private: uint16_t mSource; diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index af30a611e4c..24e7066073a 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -373,7 +373,7 @@ class Udp : public InstanceLocator, private NonCopyable * @returns The UDP Source Port. * */ - uint16_t GetSourcePort(void) const { return HostSwap16(mSourcePort); } + uint16_t GetSourcePort(void) const { return BigEndian::HostSwap16(mSourcePort); } /** * Sets the UDP Source Port. @@ -381,7 +381,7 @@ class Udp : public InstanceLocator, private NonCopyable * @param[in] aPort The UDP Source Port. * */ - void SetSourcePort(uint16_t aPort) { mSourcePort = HostSwap16(aPort); } + void SetSourcePort(uint16_t aPort) { mSourcePort = BigEndian::HostSwap16(aPort); } /** * Returns the UDP Destination Port. @@ -389,7 +389,7 @@ class Udp : public InstanceLocator, private NonCopyable * @returns The UDP Destination Port. * */ - uint16_t GetDestinationPort(void) const { return HostSwap16(mDestinationPort); } + uint16_t GetDestinationPort(void) const { return BigEndian::HostSwap16(mDestinationPort); } /** * Sets the UDP Destination Port. @@ -397,7 +397,7 @@ class Udp : public InstanceLocator, private NonCopyable * @param[in] aPort The UDP Destination Port. * */ - void SetDestinationPort(uint16_t aPort) { mDestinationPort = HostSwap16(aPort); } + void SetDestinationPort(uint16_t aPort) { mDestinationPort = BigEndian::HostSwap16(aPort); } /** * Returns the UDP Length. @@ -405,7 +405,7 @@ class Udp : public InstanceLocator, private NonCopyable * @returns The UDP Length. * */ - uint16_t GetLength(void) const { return HostSwap16(mLength); } + uint16_t GetLength(void) const { return BigEndian::HostSwap16(mLength); } /** * Sets the UDP Length. @@ -413,7 +413,7 @@ class Udp : public InstanceLocator, private NonCopyable * @param[in] aLength The UDP Length. * */ - void SetLength(uint16_t aLength) { mLength = HostSwap16(aLength); } + void SetLength(uint16_t aLength) { mLength = BigEndian::HostSwap16(aLength); } /** * Returns the UDP Checksum. @@ -421,7 +421,7 @@ class Udp : public InstanceLocator, private NonCopyable * @returns The UDP Checksum. * */ - uint16_t GetChecksum(void) const { return HostSwap16(mChecksum); } + uint16_t GetChecksum(void) const { return BigEndian::HostSwap16(mChecksum); } /** * Sets the UDP Checksum. @@ -429,7 +429,7 @@ class Udp : public InstanceLocator, private NonCopyable * @param[in] aChecksum The UDP Checksum. * */ - void SetChecksum(uint16_t aChecksum) { mChecksum = HostSwap16(aChecksum); } + void SetChecksum(uint16_t aChecksum) { mChecksum = BigEndian::HostSwap16(aChecksum); } private: uint16_t mSourcePort; diff --git a/src/core/radio/trel_link.cpp b/src/core/radio/trel_link.cpp index 4735f379e3a..b97676549c8 100644 --- a/src/core/radio/trel_link.cpp +++ b/src/core/radio/trel_link.cpp @@ -224,7 +224,7 @@ void Link::BeginTransmit(void) } // Prepare the ack frame (FCF followed by sequence number) - Encoding::LittleEndian::WriteUint16(fcf, mAckFrameBuffer); + LittleEndian::WriteUint16(fcf, mAckFrameBuffer); mAckFrameBuffer[sizeof(fcf)] = mTxFrame.GetSequence(); mRxFrame.mPsdu = mAckFrameBuffer; diff --git a/src/core/radio/trel_packet.hpp b/src/core/radio/trel_packet.hpp index 5b4caace6e7..3f2dd99d6ea 100644 --- a/src/core/radio/trel_packet.hpp +++ b/src/core/radio/trel_packet.hpp @@ -154,7 +154,7 @@ class Header * @returns The PAN Identifier field. * */ - Mac::PanId GetPanId(void) const { return Encoding::BigEndian::HostSwap16(mPanId); } + Mac::PanId GetPanId(void) const { return BigEndian::HostSwap16(mPanId); } /** * Sets the PAN Identifier field in the header. @@ -162,7 +162,7 @@ class Header * @param[in] aPanId A PAN Identifier. * */ - void SetPanId(Mac::PanId aPanId) { mPanId = Encoding::BigEndian::HostSwap16(aPanId); } + void SetPanId(Mac::PanId aPanId) { mPanId = BigEndian::HostSwap16(aPanId); } /** * Gets the packet number field from the header. @@ -170,7 +170,7 @@ class Header * @returns The packet number field. * */ - uint32_t GetPacketNumber(void) const { return Encoding::BigEndian::HostSwap32(mPacketNumber); } + uint32_t GetPacketNumber(void) const { return BigEndian::HostSwap32(mPacketNumber); } /** * Sets the packet number field in the header. @@ -178,7 +178,7 @@ class Header * @param[in] aPacketNumber The packet number. * */ - void SetPacketNumber(uint32_t aPacketNumber) { mPacketNumber = Encoding::BigEndian::HostSwap32(aPacketNumber); } + void SetPacketNumber(uint32_t aPacketNumber) { mPacketNumber = BigEndian::HostSwap32(aPacketNumber); } /** * Gets the source MAC address field from the header. diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 8f37d372c2f..4d734442a33 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -298,7 +298,7 @@ void KeyManager::ComputeKeys(uint32_t aKeySequence, HashKeys &aHashKeys) const hmac.Start(cryptoKey); - Encoding::BigEndian::WriteUint32(aKeySequence, keySequenceBytes); + BigEndian::WriteUint32(aKeySequence, keySequenceBytes); hmac.Update(keySequenceBytes); hmac.Update(kThreadString); @@ -318,7 +318,7 @@ void KeyManager::ComputeTrelKey(uint32_t aKeySequence, Mac::Key &aKey) const cryptoKey.Set(mNetworkKey.m8, NetworkKey::kSize); #endif - Encoding::BigEndian::WriteUint32(aKeySequence, salt); + BigEndian::WriteUint32(aKeySequence, salt); memcpy(salt + sizeof(uint32_t), kHkdfExtractSaltString, sizeof(kHkdfExtractSaltString)); hkdf.Extract(salt, sizeof(salt), cryptoKey); diff --git a/src/core/thread/link_metrics_tlvs.hpp b/src/core/thread/link_metrics_tlvs.hpp index 46464c9b3ec..ddd0ae2a495 100644 --- a/src/core/thread/link_metrics_tlvs.hpp +++ b/src/core/thread/link_metrics_tlvs.hpp @@ -50,8 +50,6 @@ namespace ot { namespace LinkMetrics { -using ot::Encoding::BigEndian::HostSwap32; - /** * Defines constants related to Link Metrics Sub-TLVs. * @@ -141,7 +139,7 @@ class ReportSubTlv : public Tlv, public TlvInfo * @returns The metric value. * */ - uint32_t GetMetricsValue32(void) const { return HostSwap32(mMetricsValue.m32); } + uint32_t GetMetricsValue32(void) const { return BigEndian::HostSwap32(mMetricsValue.m32); } /** * Sets the metric value (8 bits). @@ -163,7 +161,7 @@ class ReportSubTlv : public Tlv, public TlvInfo */ void SetMetricsValue32(uint32_t aMetricsValue) { - mMetricsValue.m32 = HostSwap32(aMetricsValue); + mMetricsValue.m32 = BigEndian::HostSwap32(aMetricsValue); SetLength(sizeof(*this) - sizeof(Tlv)); } diff --git a/src/core/thread/lowpan.cpp b/src/core/thread/lowpan.cpp index cb84634552f..a3d0ef0488a 100644 --- a/src/core/thread/lowpan.cpp +++ b/src/core/thread/lowpan.cpp @@ -44,9 +44,6 @@ #include "thread/network_data_leader.hpp" #include "thread/thread_netif.hpp" -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::ReadUint16; - namespace ot { namespace Lowpan { @@ -423,7 +420,7 @@ Error Lowpan::Compress(Message &aMessage, if (error == kErrorNone) { - aFrameBuilder.Write(hcCtlOffset, HostSwap16(hcCtl)); + aFrameBuilder.Write(hcCtlOffset, BigEndian::HostSwap16(hcCtl)); } else { @@ -723,7 +720,7 @@ Error Lowpan::DecompressBaseHeader(Ip6::Header &aIp6Header, { if ((hcCtl & kHcSrcAddrContext) == 0) { - aIp6Header.GetSource().mFields.m16[0] = HostSwap16(0xfe80); + aIp6Header.GetSource().mFields.m16[0] = BigEndian::HostSwap16(0xfe80); } else { @@ -762,7 +759,7 @@ Error Lowpan::DecompressBaseHeader(Ip6::Header &aIp6Header, { if ((hcCtl & kHcDstAddrModeMask) != 0) { - aIp6Header.GetDestination().mFields.m16[0] = HostSwap16(0xfe80); + aIp6Header.GetDestination().mFields.m16[0] = BigEndian::HostSwap16(0xfe80); } } else @@ -1022,12 +1019,12 @@ Error Lowpan::Decompress(Message &aMessage, if (aDatagramLength) { - ip6PayloadLength = HostSwap16(aDatagramLength - currentOffset - sizeof(Ip6::Header)); + ip6PayloadLength = BigEndian::HostSwap16(aDatagramLength - currentOffset - sizeof(Ip6::Header)); } else { ip6PayloadLength = - HostSwap16(aMessage.GetOffset() - currentOffset - sizeof(Ip6::Header) + aFrameData.GetLength()); + BigEndian::HostSwap16(aMessage.GetOffset() - currentOffset - sizeof(Ip6::Header) + aFrameData.GetLength()); } aMessage.Write(currentOffset + Ip6::Header::kPayloadLengthFieldOffset, ip6PayloadLength); @@ -1045,7 +1042,7 @@ Ip6::Ecn Lowpan::DecompressEcn(const Message &aMessage, uint16_t aOffset) const uint8_t byte; SuccessOrExit(aMessage.Read(aOffset, hcCtl)); - hcCtl = HostSwap16(hcCtl); + hcCtl = BigEndian::HostSwap16(hcCtl); VerifyOrExit((hcCtl & kHcDispatchMask) == kHcDispatch); aOffset += sizeof(uint16_t); @@ -1128,8 +1125,8 @@ Error MeshHeader::ParseFrom(const uint8_t *aFrame, uint16_t aFrameLength, uint16 aHeaderLength = kMinHeaderLength; } - mSource = ReadUint16(aFrame); - mDestination = ReadUint16(aFrame + 2); + mSource = BigEndian::ReadUint16(aFrame); + mDestination = BigEndian::ReadUint16(aFrame + 2); error = kErrorNone; @@ -1232,8 +1229,8 @@ Error FragmentHeader::ParseFrom(const uint8_t *aFrame, uint16_t aFrameLength, ui VerifyOrExit(IsFragmentHeader(aFrame, aFrameLength)); - mSize = ReadUint16(aFrame + kSizeIndex) & kSizeMask; - mTag = ReadUint16(aFrame + kTagIndex); + mSize = BigEndian::ReadUint16(aFrame + kSizeIndex) & kSizeMask; + mTag = BigEndian::ReadUint16(aFrame + kTagIndex); if ((*aFrame & kOffsetFlag) == kOffsetFlag) { diff --git a/src/core/thread/lowpan.hpp b/src/core/thread/lowpan.hpp index e0b7a59dc99..c83ba4a5411 100644 --- a/src/core/thread/lowpan.hpp +++ b/src/core/thread/lowpan.hpp @@ -68,8 +68,6 @@ namespace ot { */ namespace Lowpan { -using ot::Encoding::BigEndian::HostSwap16; - /** * Represents a LOWPAN_IPHC Context. * @@ -475,8 +473,8 @@ class FragmentHeader */ void Init(uint16_t aSize, uint16_t aTag) { - mDispatchSize = HostSwap16(kFirstDispatch | (aSize & kSizeMask)); - mTag = HostSwap16(aTag); + mDispatchSize = BigEndian::HostSwap16(kFirstDispatch | (aSize & kSizeMask)); + mTag = BigEndian::HostSwap16(aTag); } private: @@ -506,8 +504,8 @@ class FragmentHeader */ void Init(uint16_t aSize, uint16_t aTag, uint16_t aOffset) { - mDispatchSize = HostSwap16(kNextDispatch | (aSize & kSizeMask)); - mTag = HostSwap16(aTag); + mDispatchSize = BigEndian::HostSwap16(kNextDispatch | (aSize & kSizeMask)); + mTag = BigEndian::HostSwap16(aTag); mOffset = static_cast(aOffset >> 3); } diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index ca957855de0..cad9cacd3ab 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -60,8 +60,6 @@ #include "thread/time_sync_service.hpp" #include "thread/version.hpp" -using ot::Encoding::BigEndian::HostSwap16; - namespace ot { namespace Mle { @@ -133,12 +131,12 @@ Mle::Mle(Instance &aInstance) mMeshLocal16.mRloc = true; mLinkLocalAllThreadNodes.Clear(); - mLinkLocalAllThreadNodes.GetAddress().mFields.m16[0] = HostSwap16(0xff32); - mLinkLocalAllThreadNodes.GetAddress().mFields.m16[7] = HostSwap16(0x0001); + mLinkLocalAllThreadNodes.GetAddress().mFields.m16[0] = BigEndian::HostSwap16(0xff32); + mLinkLocalAllThreadNodes.GetAddress().mFields.m16[7] = BigEndian::HostSwap16(0x0001); mRealmLocalAllThreadNodes.Clear(); - mRealmLocalAllThreadNodes.GetAddress().mFields.m16[0] = HostSwap16(0xff33); - mRealmLocalAllThreadNodes.GetAddress().mFields.m16[7] = HostSwap16(0x0001); + mRealmLocalAllThreadNodes.GetAddress().mFields.m16[0] = BigEndian::HostSwap16(0xff33); + mRealmLocalAllThreadNodes.GetAddress().mFields.m16[7] = BigEndian::HostSwap16(0x0001); mMeshLocalPrefix.Clear(); SetMeshLocalPrefix(AsCoreType(&kMeshLocalPrefixInit)); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 7719bf62b03..8f3e9eaa09d 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1120,13 +1120,13 @@ class Mle : public InstanceLocator, private NonCopyable void InitSecurityControl(void) { mSecurityControl = kKeyIdMode2Mic32; } bool IsSecurityControlValid(void) const { return (mSecurityControl == kKeyIdMode2Mic32); } - uint32_t GetFrameCounter(void) const { return Encoding::LittleEndian::HostSwap32(mFrameCounter); } - void SetFrameCounter(uint32_t aCounter) { mFrameCounter = Encoding::LittleEndian::HostSwap32(aCounter); } + uint32_t GetFrameCounter(void) const { return LittleEndian::HostSwap32(mFrameCounter); } + void SetFrameCounter(uint32_t aCounter) { mFrameCounter = LittleEndian::HostSwap32(aCounter); } - uint32_t GetKeyId(void) const { return Encoding::BigEndian::HostSwap32(mKeySource); } + uint32_t GetKeyId(void) const { return BigEndian::HostSwap32(mKeySource); } void SetKeyId(uint32_t aKeySequence) { - mKeySource = Encoding::BigEndian::HostSwap32(aKeySequence); + mKeySource = BigEndian::HostSwap32(aKeySequence); mKeyIndex = (aKeySequence & 0x7f) + 1; } diff --git a/src/core/thread/mle_tlvs.hpp b/src/core/thread/mle_tlvs.hpp index b30d95fde92..d4be8ff459c 100644 --- a/src/core/thread/mle_tlvs.hpp +++ b/src/core/thread/mle_tlvs.hpp @@ -49,9 +49,6 @@ namespace ot { namespace Mle { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * @addtogroup core-mle-tlvs * @@ -670,7 +667,7 @@ class LeaderDataTlv : public Tlv, public TlvInfo */ void Get(LeaderData &aLeaderData) const { - aLeaderData.SetPartitionId(HostSwap32(mPartitionId)); + aLeaderData.SetPartitionId(BigEndian::HostSwap32(mPartitionId)); aLeaderData.SetWeighting(mWeighting); aLeaderData.SetDataVersion(mDataVersion); aLeaderData.SetStableDataVersion(mStableDataVersion); @@ -685,7 +682,7 @@ class LeaderDataTlv : public Tlv, public TlvInfo */ void Set(const LeaderData &aLeaderData) { - mPartitionId = HostSwap32(aLeaderData.GetPartitionId()); + mPartitionId = BigEndian::HostSwap32(aLeaderData.GetPartitionId()); mWeighting = aLeaderData.GetWeighting(); mDataVersion = aLeaderData.GetDataVersion(NetworkData::kFullSet); mStableDataVersion = aLeaderData.GetDataVersion(NetworkData::kStableSubset); @@ -906,7 +903,7 @@ class ConnectivityTlv : public Tlv, public TlvInfo if (IsSedBufferingIncluded()) { - buffersize = HostSwap16(mSedBufferSize); + buffersize = BigEndian::HostSwap16(mSedBufferSize); } return buffersize; } @@ -917,7 +914,7 @@ class ConnectivityTlv : public Tlv, public TlvInfo * @param[in] aSedBufferSize The SED Buffer Size value. * */ - void SetSedBufferSize(uint16_t aSedBufferSize) { mSedBufferSize = HostSwap16(aSedBufferSize); } + void SetSedBufferSize(uint16_t aSedBufferSize) { mSedBufferSize = BigEndian::HostSwap16(aSedBufferSize); } /** * Returns the SED Datagram Count value. @@ -1052,7 +1049,7 @@ class ChannelTlvValue */ ChannelTlvValue(uint8_t aChannelPage, uint16_t aChannel) : mChannelPage(aChannelPage) - , mChannel(HostSwap16(aChannel)) + , mChannel(BigEndian::HostSwap16(aChannel)) { } @@ -1089,7 +1086,7 @@ class ChannelTlvValue * @returns The Channel value. * */ - uint16_t GetChannel(void) const { return HostSwap16(mChannel); } + uint16_t GetChannel(void) const { return BigEndian::HostSwap16(mChannel); } /** * Sets the Channel value. @@ -1097,7 +1094,7 @@ class ChannelTlvValue * @param[in] aChannel The Channel value. * */ - void SetChannel(uint16_t aChannel) { mChannel = HostSwap16(aChannel); } + void SetChannel(uint16_t aChannel) { mChannel = BigEndian::HostSwap16(aChannel); } private: uint8_t mChannelPage; @@ -1156,7 +1153,7 @@ class TimeParameterTlv : public Tlv, public TlvInfo * @returns The time sync period. * */ - uint16_t GetTimeSyncPeriod(void) const { return HostSwap16(mTimeSyncPeriod); } + uint16_t GetTimeSyncPeriod(void) const { return BigEndian::HostSwap16(mTimeSyncPeriod); } /** * Sets the time sync period. @@ -1164,7 +1161,7 @@ class TimeParameterTlv : public Tlv, public TlvInfo * @param[in] aTimeSyncPeriod The time sync period. * */ - void SetTimeSyncPeriod(uint16_t aTimeSyncPeriod) { mTimeSyncPeriod = HostSwap16(aTimeSyncPeriod); } + void SetTimeSyncPeriod(uint16_t aTimeSyncPeriod) { mTimeSyncPeriod = BigEndian::HostSwap16(aTimeSyncPeriod); } /** * Returns the XTAL accuracy threshold. @@ -1172,7 +1169,7 @@ class TimeParameterTlv : public Tlv, public TlvInfo * @returns The XTAL accuracy threshold. * */ - uint16_t GetXtalThreshold(void) const { return HostSwap16(mXtalThreshold); } + uint16_t GetXtalThreshold(void) const { return BigEndian::HostSwap16(mXtalThreshold); } /** * Sets the XTAL accuracy threshold. @@ -1180,7 +1177,7 @@ class TimeParameterTlv : public Tlv, public TlvInfo * @param[in] aXTALThreshold The XTAL accuracy threshold. * */ - void SetXtalThreshold(uint16_t aXtalThreshold) { mXtalThreshold = HostSwap16(aXtalThreshold); } + void SetXtalThreshold(uint16_t aXtalThreshold) { mXtalThreshold = BigEndian::HostSwap16(aXtalThreshold); } private: uint16_t mTimeSyncPeriod; diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 814b5d14a5e..66a29a84647 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -470,7 +470,7 @@ Error Leader::ReadCommissioningDataUint16SubTlv(MeshCoP::Tlv::Type aType, uint16 VerifyOrExit(subTlv != nullptr, error = kErrorNotFound); VerifyOrExit(subTlv->GetLength() >= sizeof(uint16_t), error = kErrorParse); - aValue = Encoding::BigEndian::ReadUint16(subTlv->GetValue()); + aValue = BigEndian::ReadUint16(subTlv->GetValue()); exit: return error; diff --git a/src/core/thread/network_data_service.cpp b/src/core/thread/network_data_service.cpp index ab1af15e59b..77ff4859763 100644 --- a/src/core/thread/network_data_service.cpp +++ b/src/core/thread/network_data_service.cpp @@ -299,7 +299,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicast::Info // IPv6 address. aInfo.mSockAddr.GetAddress().SetToRoutingLocator(Get().GetMeshLocalPrefix(), aIterator.mServerSubTlv->GetServer16()); - aInfo.mSockAddr.SetPort(Encoding::BigEndian::ReadUint16(data.GetBytes())); + aInfo.mSockAddr.SetPort(BigEndian::ReadUint16(data.GetBytes())); aInfo.mOrigin = DnsSrpUnicast::kFromServerData; aInfo.mRloc16 = aIterator.mServerSubTlv->GetServer16(); ExitNow(); diff --git a/src/core/thread/network_data_service.hpp b/src/core/thread/network_data_service.hpp index aea859a9743..6fca444aa84 100644 --- a/src/core/thread/network_data_service.hpp +++ b/src/core/thread/network_data_service.hpp @@ -50,9 +50,6 @@ namespace ot { namespace NetworkData { namespace Service { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - const uint32_t kThreadEnterpriseNumber = ServiceTlv::kThreadEnterpriseNumber; ///< Thread enterprise number. #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) @@ -111,7 +108,7 @@ class BackboneRouter * @returns The BBR Registration Delay (in seconds) of Backbone Router. * */ - uint16_t GetReregistrationDelay(void) const { return HostSwap16(mReregistrationDelay); } + uint16_t GetReregistrationDelay(void) const { return BigEndian::HostSwap16(mReregistrationDelay); } /** * Sets the Registration Delay (in seconds) of Backbone Router. @@ -121,7 +118,7 @@ class BackboneRouter */ void SetReregistrationDelay(uint16_t aReregistrationDelay) { - mReregistrationDelay = HostSwap16(aReregistrationDelay); + mReregistrationDelay = BigEndian::HostSwap16(aReregistrationDelay); } /** @@ -130,7 +127,7 @@ class BackboneRouter * @returns The multicast listener report timeout (in seconds) of Backbone Router. * */ - uint32_t GetMlrTimeout(void) const { return HostSwap32(mMlrTimeout); } + uint32_t GetMlrTimeout(void) const { return BigEndian::HostSwap32(mMlrTimeout); } /** * Sets multicast listener report timeout (in seconds) of Backbone Router. @@ -138,7 +135,7 @@ class BackboneRouter * @param[in] aMlrTimeout The multicast listener report timeout (in seconds) of Backbone Router. * */ - void SetMlrTimeout(uint32_t aMlrTimeout) { mMlrTimeout = HostSwap32(aMlrTimeout); } + void SetMlrTimeout(uint32_t aMlrTimeout) { mMlrTimeout = BigEndian::HostSwap32(aMlrTimeout); } private: uint8_t mSequenceNumber; @@ -279,7 +276,7 @@ class DnsSrpUnicast explicit ServiceData(const Ip6::Address &aAddress, uint16_t aPort) : mServiceNumber(kServiceNumber) , mAddress(aAddress) - , mPort(HostSwap16(aPort)) + , mPort(BigEndian::HostSwap16(aPort)) { OT_UNUSED_VARIABLE(mServiceNumber); } @@ -306,7 +303,7 @@ class DnsSrpUnicast * @returns The port number. * */ - uint16_t GetPort(void) const { return HostSwap16(mPort); } + uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); } private: uint8_t mServiceNumber; @@ -331,7 +328,7 @@ class DnsSrpUnicast */ ServerData(const Ip6::Address &aAddress, uint16_t aPort) : mAddress(aAddress) - , mPort(HostSwap16(aPort)) + , mPort(BigEndian::HostSwap16(aPort)) { } @@ -357,7 +354,7 @@ class DnsSrpUnicast * @returns The port number. * */ - uint16_t GetPort(void) const { return HostSwap16(mPort); } + uint16_t GetPort(void) const { return BigEndian::HostSwap16(mPort); } private: Ip6::Address mAddress; diff --git a/src/core/thread/network_data_tlvs.cpp b/src/core/thread/network_data_tlvs.cpp index e81ec2d93c9..8a4330a03e5 100644 --- a/src/core/thread/network_data_tlvs.cpp +++ b/src/core/thread/network_data_tlvs.cpp @@ -101,7 +101,7 @@ void ServiceTlv::Init(uint8_t aServiceId, uint32_t aEnterpriseNumber, const Serv if (aEnterpriseNumber != kThreadEnterpriseNumber) { - mShared.mEnterpriseNumber = HostSwap32(aEnterpriseNumber); + mShared.mEnterpriseNumber = BigEndian::HostSwap32(aEnterpriseNumber); mServiceDataLength = aServiceData.GetLength(); aServiceData.CopyBytesTo(&mServiceDataLength + sizeof(uint8_t)); } diff --git a/src/core/thread/network_data_tlvs.hpp b/src/core/thread/network_data_tlvs.hpp index 3c128be877f..7b15fb2751b 100644 --- a/src/core/thread/network_data_tlvs.hpp +++ b/src/core/thread/network_data_tlvs.hpp @@ -48,9 +48,6 @@ namespace ot { namespace NetworkData { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * @addtogroup core-netdata-tlvs * @@ -424,7 +421,7 @@ class HasRouteEntry : public Equatable * * @returns The RLOC16 value. */ - uint16_t GetRloc(void) const { return HostSwap16(mRloc); } + uint16_t GetRloc(void) const { return BigEndian::HostSwap16(mRloc); } /** * Sets the RLOC16 value. @@ -432,7 +429,7 @@ class HasRouteEntry : public Equatable * @param[in] aRloc16 The RLOC16 value. * */ - void SetRloc(uint16_t aRloc16) { mRloc = HostSwap16(aRloc16); } + void SetRloc(uint16_t aRloc16) { mRloc = BigEndian::HostSwap16(aRloc16); } /** * Returns the Preference value. @@ -935,7 +932,7 @@ class BorderRouterEntry : public Equatable * * @returns The RLOC16 value. */ - uint16_t GetRloc(void) const { return HostSwap16(mRloc); } + uint16_t GetRloc(void) const { return BigEndian::HostSwap16(mRloc); } /** * Sets the RLOC16 value. @@ -943,7 +940,7 @@ class BorderRouterEntry : public Equatable * @param[in] aRloc16 The RLOC16 value. * */ - void SetRloc(uint16_t aRloc16) { mRloc = HostSwap16(aRloc16); } + void SetRloc(uint16_t aRloc16) { mRloc = BigEndian::HostSwap16(aRloc16); } /** * Returns the Flags value. @@ -951,7 +948,7 @@ class BorderRouterEntry : public Equatable * @returns The Flags value. * */ - uint16_t GetFlags(void) const { return HostSwap16(mFlags); } + uint16_t GetFlags(void) const { return BigEndian::HostSwap16(mFlags); } /** * Sets the Flags value. @@ -959,7 +956,7 @@ class BorderRouterEntry : public Equatable * @param[in] aFlags The Flags value. * */ - void SetFlags(uint16_t aFlags) { mFlags = HostSwap16(aFlags); } + void SetFlags(uint16_t aFlags) { mFlags = BigEndian::HostSwap16(aFlags); } /** * Returns the Preference value. @@ -976,7 +973,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the Preferred flag is not set. * */ - bool IsPreferred(void) const { return (HostSwap16(mFlags) & kPreferredFlag) != 0; } + bool IsPreferred(void) const { return (BigEndian::HostSwap16(mFlags) & kPreferredFlag) != 0; } /** * Indicates whether or not the SLAAC flag is set. @@ -985,7 +982,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the SLAAC flag is not set. * */ - bool IsSlaac(void) const { return (HostSwap16(mFlags) & kSlaacFlag) != 0; } + bool IsSlaac(void) const { return (BigEndian::HostSwap16(mFlags) & kSlaacFlag) != 0; } /** * Indicates whether or not the DHCP flag is set. @@ -994,7 +991,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the DHCP flag is not set. * */ - bool IsDhcp(void) const { return (HostSwap16(mFlags) & kDhcpFlag) != 0; } + bool IsDhcp(void) const { return (BigEndian::HostSwap16(mFlags) & kDhcpFlag) != 0; } /** * Indicates whether or not the Configure flag is set. @@ -1003,7 +1000,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the Configure flag is not set. * */ - bool IsConfigure(void) const { return (HostSwap16(mFlags) & kConfigureFlag) != 0; } + bool IsConfigure(void) const { return (BigEndian::HostSwap16(mFlags) & kConfigureFlag) != 0; } /** * Indicates whether or not the Default Route flag is set. @@ -1012,7 +1009,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the Default Route flag is not set. * */ - bool IsDefaultRoute(void) const { return (HostSwap16(mFlags) & kDefaultRouteFlag) != 0; } + bool IsDefaultRoute(void) const { return (BigEndian::HostSwap16(mFlags) & kDefaultRouteFlag) != 0; } /** * Indicates whether or not the On-Mesh flag is set. @@ -1021,7 +1018,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the On-Mesh flag is not set. * */ - bool IsOnMesh(void) const { return (HostSwap16(mFlags) & kOnMeshFlag) != 0; } + bool IsOnMesh(void) const { return (BigEndian::HostSwap16(mFlags) & kOnMeshFlag) != 0; } /** * Indicates whether or not the Nd-Dns flag is set. @@ -1030,7 +1027,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the Nd-Dns flag is not set. * */ - bool IsNdDns(void) const { return (HostSwap16(mFlags) & kNdDnsFlag) != 0; } + bool IsNdDns(void) const { return (BigEndian::HostSwap16(mFlags) & kNdDnsFlag) != 0; } /** * Indicates whether or not the Domain Prefix flag is set. @@ -1039,7 +1036,7 @@ class BorderRouterEntry : public Equatable * @retval FALSE If the Domain Prefix flag is not set. * */ - bool IsDp(void) const { return (HostSwap16(mFlags) & kDpFlag) != 0; } + bool IsDp(void) const { return (BigEndian::HostSwap16(mFlags) & kDpFlag) != 0; } /** * Returns a pointer to the next BorderRouterEntry @@ -1349,7 +1346,7 @@ class ServiceTlv : public NetworkDataTlv uint32_t GetEnterpriseNumber(void) const { return IsThreadEnterprise() ? static_cast(kThreadEnterpriseNumber) - : HostSwap32(mShared.mEnterpriseNumber); + : BigEndian::HostSwap32(mShared.mEnterpriseNumber); } /** @@ -1505,7 +1502,7 @@ class ServerTlv : public NetworkDataTlv * @returns The Server16 value. * */ - uint16_t GetServer16(void) const { return HostSwap16(mServer16); } + uint16_t GetServer16(void) const { return BigEndian::HostSwap16(mServer16); } /* * Sets the Server16 value. @@ -1513,7 +1510,7 @@ class ServerTlv : public NetworkDataTlv * @param[in] aServer16 The Server16 value. * */ - void SetServer16(uint16_t aServer16) { mServer16 = HostSwap16(aServer16); } + void SetServer16(uint16_t aServer16) { mServer16 = BigEndian::HostSwap16(aServer16); } /** * Gets the Server Data. diff --git a/src/core/thread/network_diagnostic_tlvs.cpp b/src/core/thread/network_diagnostic_tlvs.cpp index 941b0ccef63..715730f2d5a 100644 --- a/src/core/thread/network_diagnostic_tlvs.cpp +++ b/src/core/thread/network_diagnostic_tlvs.cpp @@ -38,10 +38,6 @@ namespace ot { namespace NetworkDiagnostic { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; -using ot::Encoding::BigEndian::HostSwap64; - #if OPENTHREAD_FTD void ChildTlv::InitFrom(const Child &aChild) @@ -56,24 +52,24 @@ void ChildTlv::InitFrom(const Child &aChild) mFlags |= (aChild.GetNetworkDataType() == NetworkData::kFullSet) ? kFlagsFullNetdta : 0; mFlags |= kFlagsTrackErrRate; - mRloc16 = HostSwap16(aChild.GetRloc16()); + mRloc16 = BigEndian::HostSwap16(aChild.GetRloc16()); mExtAddress = aChild.GetExtAddress(); - mVersion = HostSwap16(aChild.GetVersion()); - mTimeout = HostSwap32(aChild.GetTimeout()); - mAge = HostSwap32(Time::MsecToSec(TimerMilli::GetNow() - aChild.GetLastHeard())); - mConnectionTime = HostSwap32(aChild.GetConnectionTime()); - mSupervisionInterval = HostSwap16(aChild.GetSupervisionInterval()); + mVersion = BigEndian::HostSwap16(aChild.GetVersion()); + mTimeout = BigEndian::HostSwap32(aChild.GetTimeout()); + mAge = BigEndian::HostSwap32(Time::MsecToSec(TimerMilli::GetNow() - aChild.GetLastHeard())); + mConnectionTime = BigEndian::HostSwap32(aChild.GetConnectionTime()); + mSupervisionInterval = BigEndian::HostSwap16(aChild.GetSupervisionInterval()); mLinkMargin = aChild.GetLinkInfo().GetLinkMargin(); mAverageRssi = aChild.GetLinkInfo().GetAverageRss(); mLastRssi = aChild.GetLinkInfo().GetLastRss(); - mFrameErrorRate = HostSwap16(aChild.GetLinkInfo().GetFrameErrorRate()); - mMessageErrorRate = HostSwap16(aChild.GetLinkInfo().GetMessageErrorRate()); - mQueuedMessageCount = HostSwap16(aChild.GetIndirectMessageCount()); + mFrameErrorRate = BigEndian::HostSwap16(aChild.GetLinkInfo().GetFrameErrorRate()); + mMessageErrorRate = BigEndian::HostSwap16(aChild.GetLinkInfo().GetMessageErrorRate()); + mQueuedMessageCount = BigEndian::HostSwap16(aChild.GetIndirectMessageCount()); #if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE mFlags |= aChild.IsCslSynchronized() ? kFlagsCslSync : 0; - mCslPeriod = HostSwap16(aChild.GetCslPeriod()); - mCslTimeout = HostSwap32(aChild.GetCslTimeout()); + mCslPeriod = BigEndian::HostSwap16(aChild.GetCslPeriod()); + mCslTimeout = BigEndian::HostSwap32(aChild.GetCslTimeout()); mCslChannel = aChild.GetCslChannel(); #endif } @@ -86,15 +82,15 @@ void RouterNeighborTlv::InitFrom(const Router &aRouter) SetLength(sizeof(*this) - sizeof(Tlv)); mFlags |= kFlagsTrackErrRate; - mRloc16 = HostSwap16(aRouter.GetRloc16()); + mRloc16 = BigEndian::HostSwap16(aRouter.GetRloc16()); mExtAddress = aRouter.GetExtAddress(); - mVersion = HostSwap16(aRouter.GetVersion()); - mConnectionTime = HostSwap32(aRouter.GetConnectionTime()); + mVersion = BigEndian::HostSwap16(aRouter.GetVersion()); + mConnectionTime = BigEndian::HostSwap32(aRouter.GetConnectionTime()); mLinkMargin = aRouter.GetLinkInfo().GetLinkMargin(); mAverageRssi = aRouter.GetLinkInfo().GetAverageRss(); mLastRssi = aRouter.GetLinkInfo().GetLastRss(); - mFrameErrorRate = HostSwap16(aRouter.GetLinkInfo().GetFrameErrorRate()); - mMessageErrorRate = HostSwap16(aRouter.GetLinkInfo().GetMessageErrorRate()); + mFrameErrorRate = BigEndian::HostSwap16(aRouter.GetLinkInfo().GetFrameErrorRate()); + mMessageErrorRate = BigEndian::HostSwap16(aRouter.GetLinkInfo().GetMessageErrorRate()); } #endif // OPENTHREAD_FTD @@ -112,40 +108,40 @@ void MleCountersTlv::Init(const Mle::Counters &aMleCounters) SetType(kMleCounters); SetLength(sizeof(*this) - sizeof(Tlv)); - mDisabledRole = HostSwap16(aMleCounters.mDisabledRole); - mDetachedRole = HostSwap16(aMleCounters.mDetachedRole); - mChildRole = HostSwap16(aMleCounters.mChildRole); - mRouterRole = HostSwap16(aMleCounters.mRouterRole); - mLeaderRole = HostSwap16(aMleCounters.mLeaderRole); - mAttachAttempts = HostSwap16(aMleCounters.mAttachAttempts); - mPartitionIdChanges = HostSwap16(aMleCounters.mPartitionIdChanges); - mBetterPartitionAttachAttempts = HostSwap16(aMleCounters.mBetterPartitionAttachAttempts); - mParentChanges = HostSwap16(aMleCounters.mParentChanges); - mTrackedTime = HostSwap64(aMleCounters.mTrackedTime); - mDisabledTime = HostSwap64(aMleCounters.mDisabledTime); - mDetachedTime = HostSwap64(aMleCounters.mDetachedTime); - mChildTime = HostSwap64(aMleCounters.mChildTime); - mRouterTime = HostSwap64(aMleCounters.mRouterTime); - mLeaderTime = HostSwap64(aMleCounters.mLeaderTime); + mDisabledRole = BigEndian::HostSwap16(aMleCounters.mDisabledRole); + mDetachedRole = BigEndian::HostSwap16(aMleCounters.mDetachedRole); + mChildRole = BigEndian::HostSwap16(aMleCounters.mChildRole); + mRouterRole = BigEndian::HostSwap16(aMleCounters.mRouterRole); + mLeaderRole = BigEndian::HostSwap16(aMleCounters.mLeaderRole); + mAttachAttempts = BigEndian::HostSwap16(aMleCounters.mAttachAttempts); + mPartitionIdChanges = BigEndian::HostSwap16(aMleCounters.mPartitionIdChanges); + mBetterPartitionAttachAttempts = BigEndian::HostSwap16(aMleCounters.mBetterPartitionAttachAttempts); + mParentChanges = BigEndian::HostSwap16(aMleCounters.mParentChanges); + mTrackedTime = BigEndian::HostSwap64(aMleCounters.mTrackedTime); + mDisabledTime = BigEndian::HostSwap64(aMleCounters.mDisabledTime); + mDetachedTime = BigEndian::HostSwap64(aMleCounters.mDetachedTime); + mChildTime = BigEndian::HostSwap64(aMleCounters.mChildTime); + mRouterTime = BigEndian::HostSwap64(aMleCounters.mRouterTime); + mLeaderTime = BigEndian::HostSwap64(aMleCounters.mLeaderTime); } void MleCountersTlv::Read(MleCounters &aDiagMleCounters) const { - aDiagMleCounters.mDisabledRole = HostSwap16(mDisabledRole); - aDiagMleCounters.mDetachedRole = HostSwap16(mDetachedRole); - aDiagMleCounters.mChildRole = HostSwap16(mChildRole); - aDiagMleCounters.mRouterRole = HostSwap16(mRouterRole); - aDiagMleCounters.mLeaderRole = HostSwap16(mLeaderRole); - aDiagMleCounters.mAttachAttempts = HostSwap16(mAttachAttempts); - aDiagMleCounters.mPartitionIdChanges = HostSwap16(mPartitionIdChanges); - aDiagMleCounters.mBetterPartitionAttachAttempts = HostSwap16(mBetterPartitionAttachAttempts); - aDiagMleCounters.mParentChanges = HostSwap16(mParentChanges); - aDiagMleCounters.mTrackedTime = HostSwap64(mTrackedTime); - aDiagMleCounters.mDisabledTime = HostSwap64(mDisabledTime); - aDiagMleCounters.mDetachedTime = HostSwap64(mDetachedTime); - aDiagMleCounters.mChildTime = HostSwap64(mChildTime); - aDiagMleCounters.mRouterTime = HostSwap64(mRouterTime); - aDiagMleCounters.mLeaderTime = HostSwap64(mLeaderTime); + aDiagMleCounters.mDisabledRole = BigEndian::HostSwap16(mDisabledRole); + aDiagMleCounters.mDetachedRole = BigEndian::HostSwap16(mDetachedRole); + aDiagMleCounters.mChildRole = BigEndian::HostSwap16(mChildRole); + aDiagMleCounters.mRouterRole = BigEndian::HostSwap16(mRouterRole); + aDiagMleCounters.mLeaderRole = BigEndian::HostSwap16(mLeaderRole); + aDiagMleCounters.mAttachAttempts = BigEndian::HostSwap16(mAttachAttempts); + aDiagMleCounters.mPartitionIdChanges = BigEndian::HostSwap16(mPartitionIdChanges); + aDiagMleCounters.mBetterPartitionAttachAttempts = BigEndian::HostSwap16(mBetterPartitionAttachAttempts); + aDiagMleCounters.mParentChanges = BigEndian::HostSwap16(mParentChanges); + aDiagMleCounters.mTrackedTime = BigEndian::HostSwap64(mTrackedTime); + aDiagMleCounters.mDisabledTime = BigEndian::HostSwap64(mDisabledTime); + aDiagMleCounters.mDetachedTime = BigEndian::HostSwap64(mDetachedTime); + aDiagMleCounters.mChildTime = BigEndian::HostSwap64(mChildTime); + aDiagMleCounters.mRouterTime = BigEndian::HostSwap64(mRouterTime); + aDiagMleCounters.mLeaderTime = BigEndian::HostSwap64(mLeaderTime); } } // namespace NetworkDiagnostic diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index 5bdb8df0f84..e867e0fa0ed 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -54,9 +54,6 @@ namespace ot { namespace NetworkDiagnostic { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * Implements Network Diagnostic TLV generation and parsing. * @@ -362,7 +359,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfInUnknownProtos counter * */ - uint32_t GetIfInUnknownProtos(void) const { return HostSwap32(mIfInUnknownProtos); } + uint32_t GetIfInUnknownProtos(void) const { return BigEndian::HostSwap32(mIfInUnknownProtos); } /** * Sets the IfInUnknownProtos counter. @@ -372,7 +369,7 @@ class MacCountersTlv : public Tlv, public TlvInfo */ void SetIfInUnknownProtos(const uint32_t aIfInUnknownProtos) { - mIfInUnknownProtos = HostSwap32(aIfInUnknownProtos); + mIfInUnknownProtos = BigEndian::HostSwap32(aIfInUnknownProtos); } /** @@ -381,7 +378,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfInErrors counter * */ - uint32_t GetIfInErrors(void) const { return HostSwap32(mIfInErrors); } + uint32_t GetIfInErrors(void) const { return BigEndian::HostSwap32(mIfInErrors); } /** * Sets the IfInErrors counter. @@ -389,7 +386,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @param[in] aIfInErrors The IfInErrors counter * */ - void SetIfInErrors(const uint32_t aIfInErrors) { mIfInErrors = HostSwap32(aIfInErrors); } + void SetIfInErrors(const uint32_t aIfInErrors) { mIfInErrors = BigEndian::HostSwap32(aIfInErrors); } /** * Returns the IfOutErrors counter. @@ -397,7 +394,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfOutErrors counter * */ - uint32_t GetIfOutErrors(void) const { return HostSwap32(mIfOutErrors); } + uint32_t GetIfOutErrors(void) const { return BigEndian::HostSwap32(mIfOutErrors); } /** * Sets the IfOutErrors counter. @@ -405,7 +402,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @param[in] aIfOutErrors The IfOutErrors counter. * */ - void SetIfOutErrors(const uint32_t aIfOutErrors) { mIfOutErrors = HostSwap32(aIfOutErrors); } + void SetIfOutErrors(const uint32_t aIfOutErrors) { mIfOutErrors = BigEndian::HostSwap32(aIfOutErrors); } /** * Returns the IfInUcastPkts counter. @@ -413,7 +410,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfInUcastPkts counter * */ - uint32_t GetIfInUcastPkts(void) const { return HostSwap32(mIfInUcastPkts); } + uint32_t GetIfInUcastPkts(void) const { return BigEndian::HostSwap32(mIfInUcastPkts); } /** * Sets the IfInUcastPkts counter. @@ -421,14 +418,14 @@ class MacCountersTlv : public Tlv, public TlvInfo * @param[in] aIfInUcastPkts The IfInUcastPkts counter. * */ - void SetIfInUcastPkts(const uint32_t aIfInUcastPkts) { mIfInUcastPkts = HostSwap32(aIfInUcastPkts); } + void SetIfInUcastPkts(const uint32_t aIfInUcastPkts) { mIfInUcastPkts = BigEndian::HostSwap32(aIfInUcastPkts); } /** * Returns the IfInBroadcastPkts counter. * * @returns The IfInBroadcastPkts counter * */ - uint32_t GetIfInBroadcastPkts(void) const { return HostSwap32(mIfInBroadcastPkts); } + uint32_t GetIfInBroadcastPkts(void) const { return BigEndian::HostSwap32(mIfInBroadcastPkts); } /** * Sets the IfInBroadcastPkts counter. @@ -438,7 +435,7 @@ class MacCountersTlv : public Tlv, public TlvInfo */ void SetIfInBroadcastPkts(const uint32_t aIfInBroadcastPkts) { - mIfInBroadcastPkts = HostSwap32(aIfInBroadcastPkts); + mIfInBroadcastPkts = BigEndian::HostSwap32(aIfInBroadcastPkts); } /** @@ -447,7 +444,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfInDiscards counter * */ - uint32_t GetIfInDiscards(void) const { return HostSwap32(mIfInDiscards); } + uint32_t GetIfInDiscards(void) const { return BigEndian::HostSwap32(mIfInDiscards); } /** * Sets the IfInDiscards counter. @@ -455,7 +452,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @param[in] aIfInDiscards The IfInDiscards counter. * */ - void SetIfInDiscards(const uint32_t aIfInDiscards) { mIfInDiscards = HostSwap32(aIfInDiscards); } + void SetIfInDiscards(const uint32_t aIfInDiscards) { mIfInDiscards = BigEndian::HostSwap32(aIfInDiscards); } /** * Returns the IfOutUcastPkts counter. @@ -463,7 +460,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfOutUcastPkts counter * */ - uint32_t GetIfOutUcastPkts(void) const { return HostSwap32(mIfOutUcastPkts); } + uint32_t GetIfOutUcastPkts(void) const { return BigEndian::HostSwap32(mIfOutUcastPkts); } /** * Sets the IfOutUcastPkts counter. @@ -471,7 +468,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @param[in] aIfOutUcastPkts The IfOutUcastPkts counter. * */ - void SetIfOutUcastPkts(const uint32_t aIfOutUcastPkts) { mIfOutUcastPkts = HostSwap32(aIfOutUcastPkts); } + void SetIfOutUcastPkts(const uint32_t aIfOutUcastPkts) { mIfOutUcastPkts = BigEndian::HostSwap32(aIfOutUcastPkts); } /** * Returns the IfOutBroadcastPkts counter. @@ -479,7 +476,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfOutBroadcastPkts counter * */ - uint32_t GetIfOutBroadcastPkts(void) const { return HostSwap32(mIfOutBroadcastPkts); } + uint32_t GetIfOutBroadcastPkts(void) const { return BigEndian::HostSwap32(mIfOutBroadcastPkts); } /** * Sets the IfOutBroadcastPkts counter. @@ -489,7 +486,7 @@ class MacCountersTlv : public Tlv, public TlvInfo */ void SetIfOutBroadcastPkts(const uint32_t aIfOutBroadcastPkts) { - mIfOutBroadcastPkts = HostSwap32(aIfOutBroadcastPkts); + mIfOutBroadcastPkts = BigEndian::HostSwap32(aIfOutBroadcastPkts); } /** @@ -498,7 +495,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @returns The IfOutDiscards counter * */ - uint32_t GetIfOutDiscards(void) const { return HostSwap32(mIfOutDiscards); } + uint32_t GetIfOutDiscards(void) const { return BigEndian::HostSwap32(mIfOutDiscards); } /** * Sets the IfOutDiscards counter. @@ -506,7 +503,7 @@ class MacCountersTlv : public Tlv, public TlvInfo * @param[in] aIfOutDiscards The IfOutDiscards counter. * */ - void SetIfOutDiscards(const uint32_t aIfOutDiscards) { mIfOutDiscards = HostSwap32(aIfOutDiscards); } + void SetIfOutDiscards(const uint32_t aIfOutDiscards) { mIfOutDiscards = BigEndian::HostSwap32(aIfOutDiscards); } private: uint32_t mIfInUnknownProtos; @@ -618,8 +615,8 @@ class ChildTableEntry : public Clearable static constexpr uint16_t kLqiMask = 0x3 << kLqiOffset; static constexpr uint16_t kChildIdMask = 0x1ff << kChildIdOffset; - uint16_t GetTimeoutChildId(void) const { return HostSwap16(mTimeoutChildId); } - void SetTimeoutChildId(uint16_t aTimeoutChildIf) { mTimeoutChildId = HostSwap16(aTimeoutChildIf); } + uint16_t GetTimeoutChildId(void) const { return BigEndian::HostSwap16(mTimeoutChildId); } + void SetTimeoutChildId(uint16_t aTimeoutChildIf) { mTimeoutChildId = BigEndian::HostSwap16(aTimeoutChildIf); } uint16_t mTimeoutChildId; uint8_t mMode; @@ -735,7 +732,7 @@ class ChildTlv : public Tlv, public TlvInfo, public Clearable, public Clearable, public Clearable, public Clearable, public Clearable, public Clearable, public Clearable0%, 0xffff->100%). * */ - uint16_t GetFrameErrorRate(void) const { return HostSwap16(mFrameErrorRate); } + uint16_t GetFrameErrorRate(void) const { return BigEndian::HostSwap16(mFrameErrorRate); } /** * Returns the Message Error Rate field. @@ -829,7 +826,7 @@ class ChildTlv : public Tlv, public TlvInfo, public Clearable0%, 0xffff->100%). * */ - uint16_t GetMessageErrorRate(void) const { return HostSwap16(mMessageErrorRate); } + uint16_t GetMessageErrorRate(void) const { return BigEndian::HostSwap16(mMessageErrorRate); } /** * Returns the Queued Message Count field. @@ -837,7 +834,7 @@ class ChildTlv : public Tlv, public TlvInfo, public Clearable, public Clearable, public Clearable, publ * @returns The RLOC16 of the router. * */ - uint16_t GetRloc16(void) const { return HostSwap16(mRloc16); } + uint16_t GetRloc16(void) const { return BigEndian::HostSwap16(mRloc16); } /** * Returns the Extended Address. @@ -973,7 +970,7 @@ class RouterNeighborTlv : public Tlv, public TlvInfo, publ * @returns The Version of the router. * */ - uint16_t GetVersion(void) const { return HostSwap16(mVersion); } + uint16_t GetVersion(void) const { return BigEndian::HostSwap16(mVersion); } /** * Returns the Connection Time field. @@ -981,7 +978,7 @@ class RouterNeighborTlv : public Tlv, public TlvInfo, publ * @returns The Connection Time field (seconds since link establishment). * */ - uint32_t GetConnectionTime(void) const { return HostSwap32(mConnectionTime); } + uint32_t GetConnectionTime(void) const { return BigEndian::HostSwap32(mConnectionTime); } /** * Returns the Link Margin field. @@ -1016,7 +1013,7 @@ class RouterNeighborTlv : public Tlv, public TlvInfo, publ * @returns The Frame Error Rate (0x0000->0%, 0xffff->100%). * */ - uint16_t GetFrameErrorRate(void) const { return HostSwap16(mFrameErrorRate); } + uint16_t GetFrameErrorRate(void) const { return BigEndian::HostSwap16(mFrameErrorRate); } /** * Returns the Message Error Rate field. @@ -1027,7 +1024,7 @@ class RouterNeighborTlv : public Tlv, public TlvInfo, publ * @returns The Message Error Rate (0x0000->0%, 0xffff->100%). * */ - uint16_t GetMessageErrorRate(void) const { return HostSwap16(mMessageErrorRate); } + uint16_t GetMessageErrorRate(void) const { return BigEndian::HostSwap16(mMessageErrorRate); } private: uint8_t mFlags; // Flags (`kFlags*` constants). @@ -1082,8 +1079,8 @@ class AnswerTlv : public Tlv, public TlvInfo static constexpr uint16_t kIsLastFlag = 1 << 15; static constexpr uint16_t kIndexMask = 0x7f; - uint16_t GetFlagsIndex(void) const { return HostSwap16(mFlagsIndex); } - void SetFlagsIndex(uint16_t aFlagsIndex) { mFlagsIndex = HostSwap16(aFlagsIndex); } + uint16_t GetFlagsIndex(void) const { return BigEndian::HostSwap16(mFlagsIndex); } + void SetFlagsIndex(uint16_t aFlagsIndex) { mFlagsIndex = BigEndian::HostSwap16(aFlagsIndex); } uint16_t mFlagsIndex; } OT_TOOL_PACKED_END; diff --git a/src/core/thread/thread_tlvs.hpp b/src/core/thread/thread_tlvs.hpp index 5b3bdb24ad1..db971fe401e 100644 --- a/src/core/thread/thread_tlvs.hpp +++ b/src/core/thread/thread_tlvs.hpp @@ -46,9 +46,6 @@ namespace ot { -using ot::Encoding::BigEndian::HostSwap16; -using ot::Encoding::BigEndian::HostSwap32; - /** * Implements Network Layer TLV generation and parsing. * diff --git a/src/core/utils/ping_sender.cpp b/src/core/utils/ping_sender.cpp index 9949f2a0ee8..b5fc75f4f9b 100644 --- a/src/core/utils/ping_sender.cpp +++ b/src/core/utils/ping_sender.cpp @@ -44,8 +44,6 @@ namespace ot { namespace Utils { -using Encoding::BigEndian::HostSwap32; - void PingSender::Config::SetUnspecifiedToDefault(void) { if (mSize == 0) @@ -139,7 +137,7 @@ void PingSender::SendPing(void) message = Get().NewMessage(); VerifyOrExit(message != nullptr); - SuccessOrExit(message->Append(HostSwap32(now.GetValue()))); + SuccessOrExit(message->Append(BigEndian::HostSwap32(now.GetValue()))); if (mConfig.mSize > message->GetLength()) { @@ -203,7 +201,7 @@ void PingSender::HandleIcmpReceive(const Message &aMessage, VerifyOrExit(aIcmpHeader.GetId() == mIdentifier); SuccessOrExit(aMessage.Read(aMessage.GetOffset(), timestamp)); - timestamp = HostSwap32(timestamp); + timestamp = BigEndian::HostSwap32(timestamp); reply.mSenderAddress = aMessageInfo.GetPeerAddr(); reply.mRoundTripTime = ClampToUint16(TimerMilli::GetNow() - TimeMilli(timestamp)); diff --git a/src/lib/spinel/multi_frame_buffer.hpp b/src/lib/spinel/multi_frame_buffer.hpp index 2c90d906971..ab1ef835b10 100644 --- a/src/lib/spinel/multi_frame_buffer.hpp +++ b/src/lib/spinel/multi_frame_buffer.hpp @@ -267,7 +267,7 @@ template class MultiFrameBuffer : public FrameWritePointer if (mWriteFrameStart + kHeaderSize + aSkipLength <= GetArrayEnd(mBuffer)) { - Encoding::LittleEndian::WriteUint16(aSkipLength, mWriteFrameStart + kHeaderSkipLengthOffset); + LittleEndian::WriteUint16(aSkipLength, mWriteFrameStart + kHeaderSkipLengthOffset); mWritePointer = GetFrame(); mRemainingLength = static_cast(mBuffer + kSize - mWritePointer); error = OT_ERROR_NONE; @@ -282,10 +282,7 @@ template class MultiFrameBuffer : public FrameWritePointer * @returns The length (number of bytes) of the reserved buffer. * */ - uint16_t GetSkipLength(void) const - { - return Encoding::LittleEndian::ReadUint16(mWriteFrameStart + kHeaderSkipLengthOffset); - } + uint16_t GetSkipLength(void) const { return LittleEndian::ReadUint16(mWriteFrameStart + kHeaderSkipLengthOffset); } /** * Gets a pointer to the start of the current frame. @@ -323,8 +320,7 @@ template class MultiFrameBuffer : public FrameWritePointer } else { - Encoding::LittleEndian::WriteUint16(GetSkipLength() + GetLength(), - mWriteFrameStart + kHeaderTotalLengthOffset); + LittleEndian::WriteUint16(GetSkipLength() + GetLength(), mWriteFrameStart + kHeaderTotalLengthOffset); mWriteFrameStart = mWritePointer; IgnoreError(SetSkipLength(0)); } @@ -377,8 +373,8 @@ template class MultiFrameBuffer : public FrameWritePointer if (aFrame != mWriteFrameStart) { - uint16_t totalLength = Encoding::LittleEndian::ReadUint16(aFrame + kHeaderTotalLengthOffset); - uint16_t skipLength = Encoding::LittleEndian::ReadUint16(aFrame + kHeaderSkipLengthOffset); + uint16_t totalLength = LittleEndian::ReadUint16(aFrame + kHeaderTotalLengthOffset); + uint16_t skipLength = LittleEndian::ReadUint16(aFrame + kHeaderSkipLengthOffset); aLength = totalLength - skipLength; aFrame += kHeaderSize + skipLength; diff --git a/src/lib/spinel/spi_frame.hpp b/src/lib/spinel/spi_frame.hpp index a606c089680..bb540304030 100644 --- a/src/lib/spinel/spi_frame.hpp +++ b/src/lib/spinel/spi_frame.hpp @@ -195,10 +195,7 @@ class SpiFrame * @param[in] aAcceptLen The accept length in bytes. * */ - void SetHeaderAcceptLen(uint16_t aAcceptLen) - { - Encoding::LittleEndian::WriteUint16(aAcceptLen, mBuffer + kIndexAcceptLen); - } + void SetHeaderAcceptLen(uint16_t aAcceptLen) { LittleEndian::WriteUint16(aAcceptLen, mBuffer + kIndexAcceptLen); } /** * Gets the "accept len" field in the SPI frame header. @@ -206,7 +203,7 @@ class SpiFrame * @returns The accept length in bytes. * */ - uint16_t GetHeaderAcceptLen(void) const { return Encoding::LittleEndian::ReadUint16(mBuffer + kIndexAcceptLen); } + uint16_t GetHeaderAcceptLen(void) const { return LittleEndian::ReadUint16(mBuffer + kIndexAcceptLen); } /** * Sets the "data len" field in the SPI frame header. @@ -216,7 +213,7 @@ class SpiFrame * @param[in] aDataLen The data length in bytes. * */ - void SetHeaderDataLen(uint16_t aDataLen) { Encoding::LittleEndian::WriteUint16(aDataLen, mBuffer + kIndexDataLen); } + void SetHeaderDataLen(uint16_t aDataLen) { LittleEndian::WriteUint16(aDataLen, mBuffer + kIndexDataLen); } /** * Gets the "data len" field in the SPI frame header. @@ -224,7 +221,7 @@ class SpiFrame * @returns The data length in bytes. * */ - uint16_t GetHeaderDataLen(void) const { return Encoding::LittleEndian::ReadUint16(mBuffer + kIndexDataLen); } + uint16_t GetHeaderDataLen(void) const { return LittleEndian::ReadUint16(mBuffer + kIndexDataLen); } private: enum diff --git a/src/posix/platform/settings.cpp b/src/posix/platform/settings.cpp index f6139402a61..3b4c2fd561c 100644 --- a/src/posix/platform/settings.cpp +++ b/src/posix/platform/settings.cpp @@ -88,7 +88,7 @@ static void getSettingsFileName(otInstance *aInstance, char aFileName[kMaxFileNa uint64_t nodeId; otPlatRadioGetIeeeEui64(aInstance, reinterpret_cast(&nodeId)); - nodeId = ot::Encoding::BigEndian::HostSwap64(nodeId); + nodeId = ot::BigEndian::HostSwap64(nodeId); snprintf(aFileName, kMaxFileNameSize, OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH "/%s_%" PRIx64 ".%s", offset == nullptr ? "0" : offset, nodeId, (aSwap ? "swap" : "data")); } diff --git a/tests/unit/test_checksum.cpp b/tests/unit/test_checksum.cpp index 0949f5b9124..dafd2dbbb45 100644 --- a/tests/unit/test_checksum.cpp +++ b/tests/unit/test_checksum.cpp @@ -51,7 +51,7 @@ uint16_t CalculateChecksum(const void *aBuffer, uint16_t aLength) while (aLength >= sizeof(uint16_t)) { - sum += Encoding::BigEndian::ReadUint16(bytes); + sum += BigEndian::ReadUint16(bytes); bytes += sizeof(uint16_t); aLength -= sizeof(uint16_t); } @@ -102,8 +102,8 @@ uint16_t CalculateChecksum(const Ip6::Address &aSource, data.mPseudoHeader.mSource = aSource; data.mPseudoHeader.mDestination = aDestination; - data.mPseudoHeader.mProtocol = Encoding::BigEndian::HostSwap32(aIpProto); - data.mPseudoHeader.mPayloadLength = Encoding::BigEndian::HostSwap32(payloadLength); + data.mPseudoHeader.mProtocol = BigEndian::HostSwap32(aIpProto); + data.mPseudoHeader.mPayloadLength = BigEndian::HostSwap32(payloadLength); SuccessOrQuit(aMessage.Read(aMessage.GetOffset(), data.mPayload, payloadLength)); @@ -141,8 +141,8 @@ uint16_t CalculateChecksum(const Ip4::Address &aSource, data.mPseudoHeader.mSource = aSource; data.mPseudoHeader.mDestination = aDestination; - data.mPseudoHeader.mProtocol = Encoding::BigEndian::HostSwap16(aIpProto); - data.mPseudoHeader.mPayloadLength = Encoding::BigEndian::HostSwap16(payloadLength); + data.mPseudoHeader.mProtocol = BigEndian::HostSwap16(aIpProto); + data.mPseudoHeader.mPayloadLength = BigEndian::HostSwap16(payloadLength); SuccessOrQuit(aMessage.Read(aMessage.GetOffset(), data.mPayload, payloadLength)); diff --git a/tests/unit/test_ip4_header.cpp b/tests/unit/test_ip4_header.cpp index e9021a820be..7d9eec6dee8 100644 --- a/tests/unit/test_ip4_header.cpp +++ b/tests/unit/test_ip4_header.cpp @@ -31,8 +31,6 @@ #include "test_util.hpp" -using ot::Encoding::BigEndian::ReadUint16; - namespace ot { namespace Ip4 { @@ -91,7 +89,8 @@ void TestIp4Header(void) // Verify the offsets to different fields. - VerifyOrQuit(ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength, "kTotalLength is incorrect"); + VerifyOrQuit(BigEndian::ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength, + "kTotalLength is incorrect"); VerifyOrQuit(headerBytes[Header::kProtocolOffset] == kProtoIcmp, "kProtocol is incorrect"); VerifyOrQuit(headerBytes[Header::kTtlOffset] == kTtl, "kTtl is incorrect"); VerifyOrQuit(memcmp(&headerBytes[Header::kSourceAddressOffset], &source, sizeof(source)) == 0, @@ -116,7 +115,8 @@ void TestIp4Header(void) "Source address is incorrect"); VerifyOrQuit(memcmp(&headerBytes[Header::kDestinationAddressOffset], &destination, sizeof(destination)) == 0, "Destination address is incorrect"); - VerifyOrQuit(ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength, "kTotalLength is incorrect"); + VerifyOrQuit(BigEndian::ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength, + "kTotalLength is incorrect"); VerifyOrQuit(headerBytes[Header::kProtocolOffset] == kProtoIcmp, "kProtocol is incorrect"); VerifyOrQuit(headerBytes[Header::kTtlOffset] == kTtl, "kTtl is incorrect"); } diff --git a/tests/unit/test_ip6_header.cpp b/tests/unit/test_ip6_header.cpp index eab543d866e..f4b4c9c91f9 100644 --- a/tests/unit/test_ip6_header.cpp +++ b/tests/unit/test_ip6_header.cpp @@ -31,8 +31,6 @@ #include "test_util.hpp" -using ot::Encoding::BigEndian::ReadUint16; - namespace ot { namespace Ip6 { @@ -97,7 +95,7 @@ void TestIp6Header(void) // Verify the offsets to different fields. - VerifyOrQuit(ReadUint16(headerBytes + Header::kPayloadLengthFieldOffset) == kPayloadLength, + VerifyOrQuit(BigEndian::ReadUint16(headerBytes + Header::kPayloadLengthFieldOffset) == kPayloadLength, "kPayloadLengthFieldOffset is incorrect"); VerifyOrQuit(headerBytes[Header::kNextHeaderFieldOffset] == kProtoUdp, "kNextHeaderFieldOffset is incorrect"); VerifyOrQuit(headerBytes[Header::kHopLimitFieldOffset] == kHopLimit, "kHopLimitFieldOffset is incorrect"); diff --git a/tests/unit/test_ip_address.cpp b/tests/unit/test_ip_address.cpp index 31c52217e69..746ac02c0d4 100644 --- a/tests/unit/test_ip_address.cpp +++ b/tests/unit/test_ip_address.cpp @@ -826,7 +826,6 @@ void TestIp4Ip6Translation(void) void TestIp4Cidr(void) { - using Encoding::BigEndian::HostSwap32; struct TestCase { const char *mNetwork; diff --git a/tests/unit/test_multicast_listeners_table.cpp b/tests/unit/test_multicast_listeners_table.cpp index e11eb745655..ba50711ca30 100644 --- a/tests/unit/test_multicast_listeners_table.cpp +++ b/tests/unit/test_multicast_listeners_table.cpp @@ -100,7 +100,7 @@ void TestMulticastListenersTable(void) Ip6::Address address; address = static_cast(MA401); - address.mFields.m16[7] = HostSwap16(i); + address.mFields.m16[7] = BigEndian::HostSwap16(i); SuccessOrQuit(table.Add(address, TimerMilli::GetNow() + i)); VerifyOrQuit(table.Count() == i + 1, "Table count is wrong");