From 988dc8563991106e5e2d51c7abe949356cfec69c Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 28 Oct 2019 08:55:48 -0700 Subject: [PATCH] [mac] adding mac_types.hpp/cpp (#4276) This commit add `mac_types` module which includes definitions for different MAC types such as PanID, Address, Extended PAN Identifier, Network Name, etc. These definitions are moved from `mac_frame` into new the newly added files. --- Android.mk | 1 + src/core/Makefile.am | 3 + src/core/common/message.hpp | 2 +- src/core/common/settings.hpp | 2 +- src/core/mac/mac.hpp | 1 + src/core/mac/mac_frame.cpp | 94 ---- src/core/mac/mac_frame.hpp | 526 +----------------- src/core/mac/mac_types.cpp | 137 +++++ src/core/mac/mac_types.hpp | 586 ++++++++++++++++++++ src/core/meshcop/commissioner.hpp | 2 +- src/core/meshcop/dataset.cpp | 2 +- src/core/meshcop/joiner.cpp | 1 - src/core/meshcop/joiner.hpp | 2 +- src/core/meshcop/joiner_router.hpp | 2 +- src/core/meshcop/meshcop.cpp | 2 +- src/core/meshcop/meshcop.hpp | 2 +- src/core/meshcop/meshcop_tlvs.hpp | 2 +- src/core/net/dhcp6_client.hpp | 2 +- src/core/net/dhcp6_server.hpp | 2 +- src/core/net/ip6_address.cpp | 1 - src/core/net/ip6_address.hpp | 2 +- src/core/net/netif.hpp | 2 +- src/core/thread/address_resolver.cpp | 2 +- src/core/thread/key_manager.hpp | 2 +- src/core/thread/lowpan.hpp | 2 +- src/core/thread/mle.cpp | 1 - src/core/thread/mle_router.cpp | 2 +- src/core/thread/mle_router_ftd.hpp | 2 +- src/core/thread/network_data.cpp | 2 +- src/core/thread/network_data_leader.cpp | 2 +- src/core/thread/network_data_leader_ftd.cpp | 2 +- src/core/thread/network_data_local.cpp | 2 +- src/core/thread/network_diagnostic.cpp | 1 - src/core/thread/panid_query_server.hpp | 1 + src/core/thread/router_table.hpp | 2 +- src/core/thread/src_match_controller.cpp | 2 +- src/core/thread/topology.hpp | 2 +- src/core/utils/child_supervision.hpp | 2 +- 38 files changed, 756 insertions(+), 649 deletions(-) create mode 100644 src/core/mac/mac_types.cpp create mode 100644 src/core/mac/mac_types.hpp diff --git a/Android.mk b/Android.mk index 184c40f60..1b7df9704 100644 --- a/Android.mk +++ b/Android.mk @@ -159,6 +159,7 @@ LOCAL_SRC_FILES := \ src/core/mac/mac.cpp \ src/core/mac/mac_filter.cpp \ src/core/mac/mac_frame.cpp \ + src/core/mac/mac_types.cpp \ src/core/mac/sub_mac.cpp \ src/core/mac/sub_mac_callbacks.cpp \ src/core/meshcop/announce_begin_client.cpp \ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index b8f7bdec4..19907aca6 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -165,6 +165,7 @@ SOURCES_COMMON = \ mac/mac.cpp \ mac/mac_filter.cpp \ mac/mac_frame.cpp \ + mac/mac_types.cpp \ mac/sub_mac.cpp \ mac/sub_mac_callbacks.cpp \ meshcop/announce_begin_client.cpp \ @@ -256,6 +257,7 @@ libopenthread_radio_a_SOURCES = \ diags/factory_diags.cpp \ mac/link_raw.cpp \ mac/mac_frame.cpp \ + mac/mac_types.cpp \ mac/sub_mac.cpp \ mac/sub_mac_callbacks.cpp \ radio/radio_callbacks.cpp \ @@ -363,6 +365,7 @@ HEADERS_COMMON = \ mac/mac.hpp \ mac/mac_filter.hpp \ mac/mac_frame.hpp \ + mac/mac_types.hpp \ mac/sub_mac.hpp \ meshcop/announce_begin_client.hpp \ meshcop/border_agent.hpp \ diff --git a/src/core/common/message.hpp b/src/core/common/message.hpp index 620cf7b62..0f5346ba9 100644 --- a/src/core/common/message.hpp +++ b/src/core/common/message.hpp @@ -46,7 +46,7 @@ #include "common/code_utils.hpp" #include "common/locator.hpp" #include "common/tlvs.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/link_quality.hpp" namespace ot { diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 8e9d28276..4070a32c0 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -37,7 +37,7 @@ #include "openthread-core-config.h" #include "common/locator.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/mle.hpp" #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE #include "utils/slaac_address.hpp" diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index b09524c7c..ebb47f27f 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -45,6 +45,7 @@ #include "mac/channel_mask.hpp" #include "mac/mac_filter.hpp" #include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "mac/sub_mac.hpp" #include "thread/key_manager.hpp" #include "thread/link_quality.hpp" diff --git a/src/core/mac/mac_frame.cpp b/src/core/mac/mac_frame.cpp index b934cbcd0..8be6cf117 100644 --- a/src/core/mac/mac_frame.cpp +++ b/src/core/mac/mac_frame.cpp @@ -34,107 +34,13 @@ #include "mac_frame.hpp" #include -#include "utils/wrap_string.h" #include "common/code_utils.hpp" #include "common/debug.hpp" -#include "common/instance.hpp" -#include "common/random.hpp" namespace ot { namespace Mac { -void ExtAddress::GenerateRandom(void) -{ - Random::NonCrypto::FillBuffer(m8, sizeof(ExtAddress)); - SetGroup(false); - SetLocal(true); -} - -bool ExtAddress::operator==(const ExtAddress &aOther) const -{ - return memcmp(m8, aOther.m8, sizeof(ExtAddress)) == 0; -} - -ExtAddress::InfoString ExtAddress::ToString(void) const -{ - return InfoString("%02x%02x%02x%02x%02x%02x%02x%02x", m8[0], m8[1], m8[2], m8[3], m8[4], m8[5], m8[6], m8[7]); -} - -void ExtAddress::CopyAddress(uint8_t *aDst, const uint8_t *aSrc, CopyByteOrder aByteOrder) -{ - switch (aByteOrder) - { - case kNormalByteOrder: - memcpy(aDst, aSrc, sizeof(ExtAddress)); - break; - - case kReverseByteOrder: - aSrc += sizeof(ExtAddress) - 1; - for (uint8_t len = sizeof(ExtAddress); len > 0; len--) - { - *aDst++ = *aSrc--; - } - break; - } -} - -Address::InfoString Address::ToString(void) const -{ - return (mType == kTypeExtended) ? GetExtended().ToString() - : (mType == kTypeNone ? InfoString("None") : InfoString("0x%04x", GetShort())); -} - -bool ExtendedPanId::operator==(const ExtendedPanId &aOther) const -{ - return memcmp(m8, aOther.m8, sizeof(ExtendedPanId)) == 0; -} - -ExtendedPanId::InfoString ExtendedPanId::ToString(void) const -{ - return InfoString("%02x%02x%02x%02x%02x%02x%02x%02x", m8[0], m8[1], m8[2], m8[3], m8[4], m8[5], m8[6], m8[7]); -} - -uint8_t NetworkName::Data::CopyTo(char *aBuffer, uint8_t aMaxSize) const -{ - uint8_t len = GetLength(); - - memset(aBuffer, 0, aMaxSize); - - if (len > aMaxSize) - { - len = aMaxSize; - } - - memcpy(aBuffer, GetBuffer(), len); - - return len; -} - -NetworkName::Data NetworkName::GetAsData(void) const -{ - uint8_t len = static_cast(strnlen(m8, kMaxSize + 1)); - - return Data(m8, len); -} - -otError NetworkName::Set(const Data &aNameData) -{ - otError error = OT_ERROR_NONE; - uint8_t newLen = static_cast(strnlen(aNameData.GetBuffer(), aNameData.GetLength())); - - VerifyOrExit(newLen <= kMaxSize, error = OT_ERROR_INVALID_ARGS); - - // Ensure the new name does not match the current one. - VerifyOrExit(memcmp(m8, aNameData.GetBuffer(), newLen) || (m8[newLen] != '\0'), error = OT_ERROR_ALREADY); - - memcpy(m8, aNameData.GetBuffer(), newLen); - m8[newLen] = '\0'; - -exit: - return error; -} - void Frame::InitMacHeader(uint16_t aFcf, uint8_t aSecurityControl) { uint8_t *bytes = GetPsdu(); diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index 434ca492e..ed530fcd2 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -41,11 +41,8 @@ #include "utils/wrap_string.h" -#include -#include - #include "common/encoding.hpp" -#include "common/string.hpp" +#include "mac/mac_types.hpp" namespace ot { @@ -58,527 +55,6 @@ namespace Mac { * */ -enum -{ - kShortAddrBroadcast = 0xffff, - kShortAddrInvalid = 0xfffe, - kPanIdBroadcast = 0xffff, -}; - -/** - * This type represents the IEEE 802.15.4 PAN ID. - * - */ -typedef otPanId PanId; - -/** - * This type represents the IEEE 802.15.4 Short Address. - * - */ -typedef otShortAddress ShortAddress; - -/** - * This structure represents an IEEE 802.15.4 Extended Address. - * - */ -OT_TOOL_PACKED_BEGIN -class ExtAddress : public otExtAddress -{ -public: - enum - { - kInfoStringSize = 17, // Max chars for the info string (`ToString()`). - }; - - /** - * This type defines the fixed-length `String` object returned from `ToString()`. - * - */ - typedef String InfoString; - - /** - * This enumeration type specifies the copy byte order when Extended Address is being copied to/from a buffer. - * - */ - enum CopyByteOrder - { - kNormalByteOrder, // Copy address bytes in normal order (as provided in array buffer). - kReverseByteOrder, // Copy address bytes in reverse byte order. - }; - - /** - * This method generates a random IEEE 802.15.4 Extended Address. - * - */ - void GenerateRandom(void); - - /** - * This method sets the Extended Address from a given byte array. - * - * @param[in] aBuffer Pointer to an array containing the Extended Address. `OT_EXT_ADDRESS_SIZE` bytes from - * buffer are copied to form the Extended Address. - * @param[in] aByteOrder The byte order to use when copying the address. - * - */ - void Set(const uint8_t *aBuffer, CopyByteOrder aByteOrder = kNormalByteOrder) - { - CopyAddress(m8, aBuffer, aByteOrder); - } - - /** - * This method indicates whether or not the Group bit is set. - * - * @retval TRUE If the group bit is set. - * @retval FALSE If the group bit is not set. - * - */ - bool IsGroup(void) const { return (m8[0] & kGroupFlag) != 0; } - - /** - * This method sets the Group bit. - * - * @param[in] aGroup TRUE if group address, FALSE otherwise. - * - */ - void SetGroup(bool aGroup) - { - if (aGroup) - { - m8[0] |= kGroupFlag; - } - else - { - m8[0] &= ~kGroupFlag; - } - } - - /** - * This method toggles the Group bit. - * - */ - void ToggleGroup(void) { m8[0] ^= kGroupFlag; } - - /** - * This method indicates whether or not the Local bit is set. - * - * @retval TRUE If the local bit is set. - * @retval FALSE If the local bit is not set. - * - */ - bool IsLocal(void) const { return (m8[0] & kLocalFlag) != 0; } - - /** - * This method sets the Local bit. - * - * @param[in] aLocal TRUE if locally administered, FALSE otherwise. - * - */ - void SetLocal(bool aLocal) - { - if (aLocal) - { - m8[0] |= kLocalFlag; - } - else - { - m8[0] &= ~kLocalFlag; - } - } - - /** - * This method toggles the Local bit. - * - */ - void ToggleLocal(void) { m8[0] ^= kLocalFlag; } - - /** - * This method copies the Extended Address into a given buffer. - * - * @param[out] aBuffer A pointer to a buffer to copy the Extended Address into. - * @param[in] aByteOrder The byte order to copy the address. - * - */ - void CopyTo(uint8_t *aBuffer, CopyByteOrder aByteOrder = kNormalByteOrder) const - { - CopyAddress(aBuffer, m8, aByteOrder); - } - - /** - * This method evaluates whether or not the Extended Addresses match. - * - * @param[in] aOther The Extended Address to compare. - * - * @retval TRUE If the Extended Addresses match. - * @retval FALSE If the Extended Addresses do not match. - * - */ - bool operator==(const ExtAddress &aOther) const; - - /** - * This method evaluates whether or not the Extended Addresses match. - * - * @param[in] aOther The Extended Address to compare. - * - * @retval TRUE If the Extended Addresses do not match. - * @retval FALSE If the Extended Addresses match. - * - */ - bool operator!=(const ExtAddress &aOther) const { return !(*this == aOther); } - - /** - * This method converts an address to a string. - * - * @returns An `InfoString` containing the string representation of the Extended Address. - * - */ - InfoString ToString(void) const; - -private: - static void CopyAddress(uint8_t *aDst, const uint8_t *aSrc, CopyByteOrder aByteOrder); - - enum - { - kGroupFlag = 1 << 0, - kLocalFlag = 1 << 1, - }; -} OT_TOOL_PACKED_END; - -/** - * This class represents an IEEE 802.15.4 Short or Extended Address. - * - */ -class Address -{ -public: - /** - * This type defines the fixed-length `String` object returned from `ToString()`. - * - */ - typedef ExtAddress::InfoString InfoString; - - /** - * This enumeration specifies the IEEE 802.15.4 Address type. - * - */ - enum Type - { - kTypeNone, ///< No address. - kTypeShort, ///< IEEE 802.15.4 Short Address. - kTypeExtended, ///< IEEE 802.15.4 Extended Address. - }; - - /** - * This constructor initializes an Address. - * - */ - Address(void) - : mType(kTypeNone) - { - } - - /** - * This method gets the address type (Short Address, Extended Address, or none). - * - * @returns The address type. - * - */ - Type GetType(void) const { return mType; } - - /** - * This method indicates whether or not there is an address. - * - * @returns TRUE if there is no address (i.e. address type is `kTypeNone`), FALSE otherwise. - * - */ - bool IsNone(void) const { return (mType == kTypeNone); } - - /** - * This method indicates whether or not the Address is a Short Address. - * - * @returns TRUE if it is a Short Address, FALSE otherwise. - * - */ - bool IsShort(void) const { return (mType == kTypeShort); } - - /** - * This method indicates whether or not the Address is an Extended Address. - * - * @returns TRUE if it is an Extended Address, FALSE otherwise. - * - */ - bool IsExtended(void) const { return (mType == kTypeExtended); } - - /** - * This method gets the address as a Short Address. - * - * This method MUST be used only if the address type is Short Address. - * - * @returns The Short Address. - * - */ - ShortAddress GetShort(void) const { return mShared.mShortAddress; } - - /** - * This method gets the address as an Extended Address. - * - * This method MUST be used only if the address type is Extended Address. - * - * @returns A constant reference to the Extended Address. - * - */ - const ExtAddress &GetExtended(void) const { return mShared.mExtAddress; } - - /** - * This method gets the address as an Extended Address. - * - * This method MUST be used only if the address type is Extended Address. - * - * @returns A reference to the Extended Address. - * - */ - ExtAddress &GetExtended(void) { return mShared.mExtAddress; } - - /** - * This method sets the address to none (i.e., clears the address). - * - * Address type will be updated to `kTypeNone`. - * - */ - void SetNone(void) { mType = kTypeNone; } - - /** - * This method sets the address with a Short Address. - * - * The type is also updated to indicate that address is Short. - * - * @param[in] aShortAddress A Short Address - * - */ - void SetShort(ShortAddress aShortAddress) - { - mShared.mShortAddress = aShortAddress; - mType = kTypeShort; - } - - /** - * This method sets the address with an Extended Address. - * - * The type is also updated to indicate that the address is Extended. - * - * @param[in] aExtAddress An Extended Address - * - */ - void SetExtended(const ExtAddress &aExtAddress) - { - mShared.mExtAddress = aExtAddress; - mType = kTypeExtended; - } - - /** - * This method sets the address with an Extended Address given as a byte array. - * - * The type is also updated to indicate that the address is Extended. - * - * @param[in] aBuffer Pointer to an array containing the Extended Address. `OT_EXT_ADDRESS_SIZE` bytes from - * buffer are copied to form the Extended Address. - * @param[in] aByteOrder The byte order to copy the address from @p aBuffer. - * - */ - void SetExtended(const uint8_t *aBuffer, ExtAddress::CopyByteOrder aByteOrder = ExtAddress::kNormalByteOrder) - { - mShared.mExtAddress.Set(aBuffer, aByteOrder); - mType = kTypeExtended; - } - - /** - * This method indicates whether or not the address is a Short Broadcast Address. - * - * @returns TRUE if address is Short Broadcast Address, FALSE otherwise. - * - */ - bool IsBroadcast(void) const { return ((mType == kTypeShort) && (GetShort() == kShortAddrBroadcast)); } - - /** - * This method indicates whether or not the address is a Short Invalid Address. - * - * @returns TRUE if address is Short Invalid Address, FALSE otherwise. - * - */ - bool IsShortAddrInvalid(void) const { return ((mType == kTypeShort) && (GetShort() == kShortAddrInvalid)); } - - /** - * This method converts an address to a null-terminated string - * - * @returns A `String` representing the address. - * - */ - InfoString ToString(void) const; - -private: - union - { - ShortAddress mShortAddress; ///< The IEEE 802.15.4 Short Address. - ExtAddress mExtAddress; ///< The IEEE 802.15.4 Extended Address. - } mShared; - - Type mType; ///< The address type (Short, Extended, or none). -}; - -/** - * This structure represents an IEEE 802.15.4 Extended PAN Identifier. - * - */ -OT_TOOL_PACKED_BEGIN -class ExtendedPanId : public otExtendedPanId -{ -public: - enum - { - kInfoStringSize = 17, // Max chars for the info string (`ToString()`). - }; - - /** - * This type defines the fixed-length `String` object returned from `ToString()`. - * - */ - typedef String InfoString; - - /** - * This method evaluates whether or not the Extended PAN Identifiers match. - * - * @param[in] aOther The Extended PAN Id to compare. - * - * @retval TRUE If the Extended PAN Identifiers match. - * @retval FALSE If the Extended PAN Identifiers do not match. - * - */ - bool operator==(const ExtendedPanId &aOther) const; - - /** - * This method evaluates whether or not the Extended PAN Identifiers match. - * - * @param[in] aOther The Extended PAN Id to compare. - * - * @retval TRUE If the Extended Addresses do not match. - * @retval FALSE If the Extended Addresses match. - * - */ - bool operator!=(const ExtendedPanId &aOther) const { return !(*this == aOther); } - - /** - * This method converts an address to a string. - * - * @returns An `InfoString` containing the string representation of the Extended PAN Identifier. - * - */ - InfoString ToString(void) const; - -} OT_TOOL_PACKED_END; - -/** - * This structure represents an IEEE802.15.4 Network Name. - * - */ -class NetworkName : public otNetworkName -{ -public: - enum - { - kMaxSize = OT_NETWORK_NAME_MAX_SIZE, // Maximum number of chars in Network Name (excludes null char). - }; - - /** - * This class represents an IEEE802.15.4 Network Name as Data (pointer to a char buffer along with a length). - * - * @note The char array does NOT need to be null terminated. - * - */ - class Data - { - public: - /** - * This constructor initializes the Data object. - * - * @param[in] aBuffer A pointer to a `char` buffer (does not need to be null terminated). - * @param[in] aLength The length (number of chars) in the buffer. - * - */ - Data(const char *aBuffer, uint8_t aLength) - : mBuffer(aBuffer) - , mLength(aLength) - { - } - - /** - * This method returns the pointer to char buffer (not necessarily null terminated). - * - * @returns The pointer to the char buffer. - * - */ - const char *GetBuffer(void) const { return mBuffer; } - - /** - * This method returns the length (number of chars in buffer). - * - * @returns The name length. - * - */ - uint8_t GetLength(void) const { return mLength; } - - /** - * This method copies the name data into a given char buffer with a given size. - * - * The given buffer is cleared (`memset` to zero) before copying the Network Name into it. The copied string - * in @p aBuffer is NOT necessarily null terminated. - * - * @param[out] aBuffer A pointer to a buffer where to copy the Network Name into. - * @param[in] aMaxSize Size of @p aBuffer (maximum number of chars to write into @p aBuffer). - * - * @returns The actual number of chars copied into @p aBuffer. - * - */ - uint8_t CopyTo(char *aBuffer, uint8_t aMaxSize) const; - - private: - const char *mBuffer; - uint8_t mLength; - }; - - /** - * This constructor initializes the IEEE802.15.4 Network Name as an empty string. - * - */ - NetworkName(void) { m8[0] = '\0'; } - - /** - * This method gets the IEEE802.15.4 Network Name as a null terminated C string. - * - * @returns The Network Name as a null terminated C string array. - * - */ - const char *GetAsCString(void) const { return m8; } - - /** - * This method gets the IEEE802.15.4 Network Name as Data. - * - * @returns The Network Name as Data. - * - */ - Data GetAsData(void) const; - - /** - * This method sets the IEEE 802.15.4 Network Name. - * - * @param[in] aNameData A reference to name data. - * - * @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 Network Name. - * @retval OT_ERROR_ALREADY The name is already set to the same string. - * @retval OT_ERROR_INVALID_ARGS Given name is too long. - * - */ - otError Set(const Data &aNameData); -}; - /** * This class implements IEEE 802.15.4 IE (Information Element) generation and parsing. * diff --git a/src/core/mac/mac_types.cpp b/src/core/mac/mac_types.cpp new file mode 100644 index 000000000..355cf8b66 --- /dev/null +++ b/src/core/mac/mac_types.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016-2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements MAC types such as Address, Extended PAN Identifier, Network Name, etc. + */ + +#include "mac_types.hpp" + +#include +#include "utils/wrap_string.h" + +#include "common/code_utils.hpp" +#include "common/random.hpp" + +namespace ot { +namespace Mac { + +void ExtAddress::GenerateRandom(void) +{ + Random::NonCrypto::FillBuffer(m8, sizeof(ExtAddress)); + SetGroup(false); + SetLocal(true); +} + +bool ExtAddress::operator==(const ExtAddress &aOther) const +{ + return memcmp(m8, aOther.m8, sizeof(ExtAddress)) == 0; +} + +ExtAddress::InfoString ExtAddress::ToString(void) const +{ + return InfoString("%02x%02x%02x%02x%02x%02x%02x%02x", m8[0], m8[1], m8[2], m8[3], m8[4], m8[5], m8[6], m8[7]); +} + +void ExtAddress::CopyAddress(uint8_t *aDst, const uint8_t *aSrc, CopyByteOrder aByteOrder) +{ + switch (aByteOrder) + { + case kNormalByteOrder: + memcpy(aDst, aSrc, sizeof(ExtAddress)); + break; + + case kReverseByteOrder: + aSrc += sizeof(ExtAddress) - 1; + for (uint8_t len = sizeof(ExtAddress); len > 0; len--) + { + *aDst++ = *aSrc--; + } + break; + } +} + +Address::InfoString Address::ToString(void) const +{ + return (mType == kTypeExtended) ? GetExtended().ToString() + : (mType == kTypeNone ? InfoString("None") : InfoString("0x%04x", GetShort())); +} + +bool ExtendedPanId::operator==(const ExtendedPanId &aOther) const +{ + return memcmp(m8, aOther.m8, sizeof(ExtendedPanId)) == 0; +} + +ExtendedPanId::InfoString ExtendedPanId::ToString(void) const +{ + return InfoString("%02x%02x%02x%02x%02x%02x%02x%02x", m8[0], m8[1], m8[2], m8[3], m8[4], m8[5], m8[6], m8[7]); +} + +uint8_t NetworkName::Data::CopyTo(char *aBuffer, uint8_t aMaxSize) const +{ + uint8_t len = GetLength(); + + memset(aBuffer, 0, aMaxSize); + + if (len > aMaxSize) + { + len = aMaxSize; + } + + memcpy(aBuffer, GetBuffer(), len); + + return len; +} + +NetworkName::Data NetworkName::GetAsData(void) const +{ + uint8_t len = static_cast(strnlen(m8, kMaxSize + 1)); + + return Data(m8, len); +} + +otError NetworkName::Set(const Data &aNameData) +{ + otError error = OT_ERROR_NONE; + uint8_t newLen = static_cast(strnlen(aNameData.GetBuffer(), aNameData.GetLength())); + + VerifyOrExit(newLen <= kMaxSize, error = OT_ERROR_INVALID_ARGS); + + // Ensure the new name does not match the current one. + VerifyOrExit(memcmp(m8, aNameData.GetBuffer(), newLen) || (m8[newLen] != '\0'), error = OT_ERROR_ALREADY); + + memcpy(m8, aNameData.GetBuffer(), newLen); + m8[newLen] = '\0'; + +exit: + return error; +} + +} // namespace Mac +} // namespace ot diff --git a/src/core/mac/mac_types.hpp b/src/core/mac/mac_types.hpp new file mode 100644 index 000000000..6f093bf12 --- /dev/null +++ b/src/core/mac/mac_types.hpp @@ -0,0 +1,586 @@ +/* + * Copyright (c) 2016-2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file includes definitions for MAC types such as Address, Extended PAN Identifier, Network Name, etc. + */ + +#ifndef MAC_TYPES_HPP_ +#define MAC_TYPES_HPP_ + +#include "openthread-core-config.h" + +#include + +#include "utils/wrap_string.h" + +#include + +#include "common/string.hpp" + +namespace ot { +namespace Mac { + +/** + * @addtogroup core-mac + * + * @{ + * + */ + +enum +{ + kShortAddrBroadcast = 0xffff, + kShortAddrInvalid = 0xfffe, + kPanIdBroadcast = 0xffff, +}; + +/** + * This type represents the IEEE 802.15.4 PAN ID. + * + */ +typedef otPanId PanId; + +/** + * This type represents the IEEE 802.15.4 Short Address. + * + */ +typedef otShortAddress ShortAddress; + +/** + * This structure represents an IEEE 802.15.4 Extended Address. + * + */ +OT_TOOL_PACKED_BEGIN +class ExtAddress : public otExtAddress +{ +public: + enum + { + kInfoStringSize = 17, // Max chars for the info string (`ToString()`). + }; + + /** + * This type defines the fixed-length `String` object returned from `ToString()`. + * + */ + typedef String InfoString; + + /** + * This enumeration type specifies the copy byte order when Extended Address is being copied to/from a buffer. + * + */ + enum CopyByteOrder + { + kNormalByteOrder, // Copy address bytes in normal order (as provided in array buffer). + kReverseByteOrder, // Copy address bytes in reverse byte order. + }; + + /** + * This method generates a random IEEE 802.15.4 Extended Address. + * + */ + void GenerateRandom(void); + + /** + * This method sets the Extended Address from a given byte array. + * + * @param[in] aBuffer Pointer to an array containing the Extended Address. `OT_EXT_ADDRESS_SIZE` bytes from + * buffer are copied to form the Extended Address. + * @param[in] aByteOrder The byte order to use when copying the address. + * + */ + void Set(const uint8_t *aBuffer, CopyByteOrder aByteOrder = kNormalByteOrder) + { + CopyAddress(m8, aBuffer, aByteOrder); + } + + /** + * This method indicates whether or not the Group bit is set. + * + * @retval TRUE If the group bit is set. + * @retval FALSE If the group bit is not set. + * + */ + bool IsGroup(void) const { return (m8[0] & kGroupFlag) != 0; } + + /** + * This method sets the Group bit. + * + * @param[in] aGroup TRUE if group address, FALSE otherwise. + * + */ + void SetGroup(bool aGroup) + { + if (aGroup) + { + m8[0] |= kGroupFlag; + } + else + { + m8[0] &= ~kGroupFlag; + } + } + + /** + * This method toggles the Group bit. + * + */ + void ToggleGroup(void) { m8[0] ^= kGroupFlag; } + + /** + * This method indicates whether or not the Local bit is set. + * + * @retval TRUE If the local bit is set. + * @retval FALSE If the local bit is not set. + * + */ + bool IsLocal(void) const { return (m8[0] & kLocalFlag) != 0; } + + /** + * This method sets the Local bit. + * + * @param[in] aLocal TRUE if locally administered, FALSE otherwise. + * + */ + void SetLocal(bool aLocal) + { + if (aLocal) + { + m8[0] |= kLocalFlag; + } + else + { + m8[0] &= ~kLocalFlag; + } + } + + /** + * This method toggles the Local bit. + * + */ + void ToggleLocal(void) { m8[0] ^= kLocalFlag; } + + /** + * This method copies the Extended Address into a given buffer. + * + * @param[out] aBuffer A pointer to a buffer to copy the Extended Address into. + * @param[in] aByteOrder The byte order to copy the address. + * + */ + void CopyTo(uint8_t *aBuffer, CopyByteOrder aByteOrder = kNormalByteOrder) const + { + CopyAddress(aBuffer, m8, aByteOrder); + } + + /** + * This method evaluates whether or not the Extended Addresses match. + * + * @param[in] aOther The Extended Address to compare. + * + * @retval TRUE If the Extended Addresses match. + * @retval FALSE If the Extended Addresses do not match. + * + */ + bool operator==(const ExtAddress &aOther) const; + + /** + * This method evaluates whether or not the Extended Addresses match. + * + * @param[in] aOther The Extended Address to compare. + * + * @retval TRUE If the Extended Addresses do not match. + * @retval FALSE If the Extended Addresses match. + * + */ + bool operator!=(const ExtAddress &aOther) const { return !(*this == aOther); } + + /** + * This method converts an address to a string. + * + * @returns An `InfoString` containing the string representation of the Extended Address. + * + */ + InfoString ToString(void) const; + +private: + static void CopyAddress(uint8_t *aDst, const uint8_t *aSrc, CopyByteOrder aByteOrder); + + enum + { + kGroupFlag = 1 << 0, + kLocalFlag = 1 << 1, + }; +} OT_TOOL_PACKED_END; + +/** + * This class represents an IEEE 802.15.4 Short or Extended Address. + * + */ +class Address +{ +public: + /** + * This type defines the fixed-length `String` object returned from `ToString()`. + * + */ + typedef ExtAddress::InfoString InfoString; + + /** + * This enumeration specifies the IEEE 802.15.4 Address type. + * + */ + enum Type + { + kTypeNone, ///< No address. + kTypeShort, ///< IEEE 802.15.4 Short Address. + kTypeExtended, ///< IEEE 802.15.4 Extended Address. + }; + + /** + * This constructor initializes an Address. + * + */ + Address(void) + : mType(kTypeNone) + { + } + + /** + * This method gets the address type (Short Address, Extended Address, or none). + * + * @returns The address type. + * + */ + Type GetType(void) const { return mType; } + + /** + * This method indicates whether or not there is an address. + * + * @returns TRUE if there is no address (i.e. address type is `kTypeNone`), FALSE otherwise. + * + */ + bool IsNone(void) const { return (mType == kTypeNone); } + + /** + * This method indicates whether or not the Address is a Short Address. + * + * @returns TRUE if it is a Short Address, FALSE otherwise. + * + */ + bool IsShort(void) const { return (mType == kTypeShort); } + + /** + * This method indicates whether or not the Address is an Extended Address. + * + * @returns TRUE if it is an Extended Address, FALSE otherwise. + * + */ + bool IsExtended(void) const { return (mType == kTypeExtended); } + + /** + * This method gets the address as a Short Address. + * + * This method MUST be used only if the address type is Short Address. + * + * @returns The Short Address. + * + */ + ShortAddress GetShort(void) const { return mShared.mShortAddress; } + + /** + * This method gets the address as an Extended Address. + * + * This method MUST be used only if the address type is Extended Address. + * + * @returns A constant reference to the Extended Address. + * + */ + const ExtAddress &GetExtended(void) const { return mShared.mExtAddress; } + + /** + * This method gets the address as an Extended Address. + * + * This method MUST be used only if the address type is Extended Address. + * + * @returns A reference to the Extended Address. + * + */ + ExtAddress &GetExtended(void) { return mShared.mExtAddress; } + + /** + * This method sets the address to none (i.e., clears the address). + * + * Address type will be updated to `kTypeNone`. + * + */ + void SetNone(void) { mType = kTypeNone; } + + /** + * This method sets the address with a Short Address. + * + * The type is also updated to indicate that address is Short. + * + * @param[in] aShortAddress A Short Address + * + */ + void SetShort(ShortAddress aShortAddress) + { + mShared.mShortAddress = aShortAddress; + mType = kTypeShort; + } + + /** + * This method sets the address with an Extended Address. + * + * The type is also updated to indicate that the address is Extended. + * + * @param[in] aExtAddress An Extended Address + * + */ + void SetExtended(const ExtAddress &aExtAddress) + { + mShared.mExtAddress = aExtAddress; + mType = kTypeExtended; + } + + /** + * This method sets the address with an Extended Address given as a byte array. + * + * The type is also updated to indicate that the address is Extended. + * + * @param[in] aBuffer Pointer to an array containing the Extended Address. `OT_EXT_ADDRESS_SIZE` bytes from + * buffer are copied to form the Extended Address. + * @param[in] aByteOrder The byte order to copy the address from @p aBuffer. + * + */ + void SetExtended(const uint8_t *aBuffer, ExtAddress::CopyByteOrder aByteOrder = ExtAddress::kNormalByteOrder) + { + mShared.mExtAddress.Set(aBuffer, aByteOrder); + mType = kTypeExtended; + } + + /** + * This method indicates whether or not the address is a Short Broadcast Address. + * + * @returns TRUE if address is Short Broadcast Address, FALSE otherwise. + * + */ + bool IsBroadcast(void) const { return ((mType == kTypeShort) && (GetShort() == kShortAddrBroadcast)); } + + /** + * This method indicates whether or not the address is a Short Invalid Address. + * + * @returns TRUE if address is Short Invalid Address, FALSE otherwise. + * + */ + bool IsShortAddrInvalid(void) const { return ((mType == kTypeShort) && (GetShort() == kShortAddrInvalid)); } + + /** + * This method converts an address to a null-terminated string + * + * @returns A `String` representing the address. + * + */ + InfoString ToString(void) const; + +private: + union + { + ShortAddress mShortAddress; ///< The IEEE 802.15.4 Short Address. + ExtAddress mExtAddress; ///< The IEEE 802.15.4 Extended Address. + } mShared; + + Type mType; ///< The address type (Short, Extended, or none). +}; + +/** + * This structure represents an IEEE 802.15.4 Extended PAN Identifier. + * + */ +OT_TOOL_PACKED_BEGIN +class ExtendedPanId : public otExtendedPanId +{ +public: + enum + { + kInfoStringSize = 17, // Max chars for the info string (`ToString()`). + }; + + /** + * This type defines the fixed-length `String` object returned from `ToString()`. + * + */ + typedef String InfoString; + + /** + * This method evaluates whether or not the Extended PAN Identifiers match. + * + * @param[in] aOther The Extended PAN Id to compare. + * + * @retval TRUE If the Extended PAN Identifiers match. + * @retval FALSE If the Extended PAN Identifiers do not match. + * + */ + bool operator==(const ExtendedPanId &aOther) const; + + /** + * This method evaluates whether or not the Extended PAN Identifiers match. + * + * @param[in] aOther The Extended PAN Id to compare. + * + * @retval TRUE If the Extended Addresses do not match. + * @retval FALSE If the Extended Addresses match. + * + */ + bool operator!=(const ExtendedPanId &aOther) const { return !(*this == aOther); } + + /** + * This method converts an address to a string. + * + * @returns An `InfoString` containing the string representation of the Extended PAN Identifier. + * + */ + InfoString ToString(void) const; + +} OT_TOOL_PACKED_END; + +/** + * This structure represents an IEEE802.15.4 Network Name. + * + */ +class NetworkName : public otNetworkName +{ +public: + enum + { + kMaxSize = OT_NETWORK_NAME_MAX_SIZE, // Maximum number of chars in Network Name (excludes null char). + }; + + /** + * This class represents an IEEE802.15.4 Network Name as Data (pointer to a char buffer along with a length). + * + * @note The char array does NOT need to be null terminated. + * + */ + class Data + { + public: + /** + * This constructor initializes the Data object. + * + * @param[in] aBuffer A pointer to a `char` buffer (does not need to be null terminated). + * @param[in] aLength The length (number of chars) in the buffer. + * + */ + Data(const char *aBuffer, uint8_t aLength) + : mBuffer(aBuffer) + , mLength(aLength) + { + } + + /** + * This method returns the pointer to char buffer (not necessarily null terminated). + * + * @returns The pointer to the char buffer. + * + */ + const char *GetBuffer(void) const { return mBuffer; } + + /** + * This method returns the length (number of chars in buffer). + * + * @returns The name length. + * + */ + uint8_t GetLength(void) const { return mLength; } + + /** + * This method copies the name data into a given char buffer with a given size. + * + * The given buffer is cleared (`memset` to zero) before copying the Network Name into it. The copied string + * in @p aBuffer is NOT necessarily null terminated. + * + * @param[out] aBuffer A pointer to a buffer where to copy the Network Name into. + * @param[in] aMaxSize Size of @p aBuffer (maximum number of chars to write into @p aBuffer). + * + * @returns The actual number of chars copied into @p aBuffer. + * + */ + uint8_t CopyTo(char *aBuffer, uint8_t aMaxSize) const; + + private: + const char *mBuffer; + uint8_t mLength; + }; + + /** + * This constructor initializes the IEEE802.15.4 Network Name as an empty string. + * + */ + NetworkName(void) { m8[0] = '\0'; } + + /** + * This method gets the IEEE802.15.4 Network Name as a null terminated C string. + * + * @returns The Network Name as a null terminated C string array. + * + */ + const char *GetAsCString(void) const { return m8; } + + /** + * This method gets the IEEE802.15.4 Network Name as Data. + * + * @returns The Network Name as Data. + * + */ + Data GetAsData(void) const; + + /** + * This method sets the IEEE 802.15.4 Network Name. + * + * @param[in] aNameData A reference to name data. + * + * @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 Network Name. + * @retval OT_ERROR_ALREADY The name is already set to the same string. + * @retval OT_ERROR_INVALID_ARGS Given name is too long. + * + */ + otError Set(const Data &aNameData); +}; + +/** + * @} + * + */ + +} // namespace Mac +} // namespace ot + +#endif // MAC_TYPES_HPP_ diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index 76370c54d..eb42211ef 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -42,7 +42,7 @@ #include "coap/coap_secure.hpp" #include "common/locator.hpp" #include "common/timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/announce_begin_client.hpp" #include "meshcop/dtls.hpp" #include "meshcop/energy_scan_client.hpp" diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp index 3a1a2bab4..e1ce130e9 100644 --- a/src/core/meshcop/dataset.cpp +++ b/src/core/meshcop/dataset.cpp @@ -40,7 +40,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/meshcop_tlvs.hpp" #include "thread/mle_tlvs.hpp" diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 965d87e50..d0ef8c109 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -41,7 +41,6 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" -#include "mac/mac_frame.hpp" #include "meshcop/meshcop.hpp" #include "radio/radio.hpp" #include "thread/thread_netif.hpp" diff --git a/src/core/meshcop/joiner.hpp b/src/core/meshcop/joiner.hpp index d2fd81482..168edb9a0 100644 --- a/src/core/meshcop/joiner.hpp +++ b/src/core/meshcop/joiner.hpp @@ -44,7 +44,7 @@ #include "common/locator.hpp" #include "common/logging.hpp" #include "common/message.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/dtls.hpp" #include "meshcop/meshcop_tlvs.hpp" diff --git a/src/core/meshcop/joiner_router.hpp b/src/core/meshcop/joiner_router.hpp index c497694b2..96446c478 100644 --- a/src/core/meshcop/joiner_router.hpp +++ b/src/core/meshcop/joiner_router.hpp @@ -42,7 +42,7 @@ #include "common/message.hpp" #include "common/notifier.hpp" #include "common/timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/meshcop_tlvs.hpp" #include "net/udp6.hpp" #include "thread/key_manager.hpp" diff --git a/src/core/meshcop/meshcop.cpp b/src/core/meshcop/meshcop.cpp index e6c8c68c3..f7c5f23f0 100644 --- a/src/core/meshcop/meshcop.cpp +++ b/src/core/meshcop/meshcop.cpp @@ -33,7 +33,7 @@ #include "common/locator-getters.hpp" #include "crypto/sha256.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/thread_netif.hpp" namespace ot { diff --git a/src/core/meshcop/meshcop.hpp b/src/core/meshcop/meshcop.hpp index c70178b6c..d39b79d26 100644 --- a/src/core/meshcop/meshcop.hpp +++ b/src/core/meshcop/meshcop.hpp @@ -41,7 +41,7 @@ #include "coap/coap.hpp" #include "common/message.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" namespace ot { namespace MeshCoP { diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 443356f38..1955cb3f9 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -47,7 +47,7 @@ #include "common/encoding.hpp" #include "common/message.hpp" #include "common/tlvs.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/timestamp.hpp" #include "net/ip6_address.hpp" #include "radio/radio.hpp" diff --git a/src/core/net/dhcp6_client.hpp b/src/core/net/dhcp6_client.hpp index 4b453e236..05ca1a955 100644 --- a/src/core/net/dhcp6_client.hpp +++ b/src/core/net/dhcp6_client.hpp @@ -41,7 +41,7 @@ #include "common/timer.hpp" #include "common/trickle_timer.hpp" #include "mac/mac.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "net/dhcp6.hpp" #include "net/udp6.hpp" diff --git a/src/core/net/dhcp6_server.hpp b/src/core/net/dhcp6_server.hpp index baa2c59cd..b2dc653eb 100644 --- a/src/core/net/dhcp6_server.hpp +++ b/src/core/net/dhcp6_server.hpp @@ -38,7 +38,7 @@ #include "common/locator.hpp" #include "mac/mac.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "net/dhcp6.hpp" #include "net/udp6.hpp" #include "thread/network_data_leader.hpp" diff --git a/src/core/net/ip6_address.cpp b/src/core/net/ip6_address.cpp index 66270c6ca..b9e810af6 100644 --- a/src/core/net/ip6_address.cpp +++ b/src/core/net/ip6_address.cpp @@ -39,7 +39,6 @@ #include "common/code_utils.hpp" #include "common/encoding.hpp" #include "common/instance.hpp" -#include "mac/mac_frame.hpp" using ot::Encoding::BigEndian::HostSwap16; using ot::Encoding::BigEndian::HostSwap32; diff --git a/src/core/net/ip6_address.hpp b/src/core/net/ip6_address.hpp index 10e83a8ec..70d00fa3b 100644 --- a/src/core/net/ip6_address.hpp +++ b/src/core/net/ip6_address.hpp @@ -39,7 +39,7 @@ #include #include "common/string.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" namespace ot { namespace Ip6 { diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index f6161194f..97c9a47a6 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -39,7 +39,7 @@ #include "common/locator.hpp" #include "common/message.hpp" #include "common/tasklet.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "net/ip6_address.hpp" #include "net/socket.hpp" diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index d76894361..ee927f7b2 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -42,7 +42,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/mesh_forwarder.hpp" #include "thread/mle_router.hpp" #include "thread/thread_netif.hpp" diff --git a/src/core/thread/key_manager.hpp b/src/core/thread/key_manager.hpp index 9eab0c160..26e5da3e5 100644 --- a/src/core/thread/key_manager.hpp +++ b/src/core/thread/key_manager.hpp @@ -44,7 +44,7 @@ #include "common/random.hpp" #include "common/timer.hpp" #include "crypto/hmac_sha256.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" namespace ot { diff --git a/src/core/thread/lowpan.hpp b/src/core/thread/lowpan.hpp index 13f4baff6..20027fe6e 100644 --- a/src/core/thread/lowpan.hpp +++ b/src/core/thread/lowpan.hpp @@ -39,7 +39,7 @@ #include "common/debug.hpp" #include "common/locator.hpp" #include "common/message.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "net/ip6.hpp" #include "net/ip6_address.hpp" diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 8761cb0a1..2adae2ad6 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -45,7 +45,6 @@ #include "common/random.hpp" #include "common/settings.hpp" #include "crypto/aes_ccm.hpp" -#include "mac/mac_frame.hpp" #include "meshcop/meshcop.hpp" #include "meshcop/meshcop_tlvs.hpp" #include "net/netif.hpp" diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index d1ca4707b..c78a173df 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -42,7 +42,7 @@ #include "common/logging.hpp" #include "common/random.hpp" #include "common/settings.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/meshcop.hpp" #include "net/icmp6.hpp" #include "thread/thread_netif.hpp" diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index 9b52d0ccd..0a62446e1 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -44,7 +44,7 @@ #include "coap/coap_message.hpp" #include "common/timer.hpp" #include "common/trickle_timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/meshcop_tlvs.hpp" #include "net/icmp6.hpp" #include "net/udp6.hpp" diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index 2c24877f7..8e22bd1b1 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -39,7 +39,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/thread_netif.hpp" #include "thread/thread_tlvs.hpp" #include "thread/thread_uri_paths.hpp" diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index a1bc6670c..266a06e61 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -43,7 +43,7 @@ #include "common/message.hpp" #include "common/random.hpp" #include "common/timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/lowpan.hpp" #include "thread/mle_router.hpp" #include "thread/thread_netif.hpp" diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index 1f64dbeb8..f22e0b8f7 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -44,7 +44,7 @@ #include "common/logging.hpp" #include "common/message.hpp" #include "common/timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "meshcop/meshcop.hpp" #include "thread/lowpan.hpp" #include "thread/mle_router.hpp" diff --git a/src/core/thread/network_data_local.cpp b/src/core/thread/network_data_local.cpp index 6c965b3b3..dc533d0cb 100644 --- a/src/core/thread/network_data_local.cpp +++ b/src/core/thread/network_data_local.cpp @@ -38,7 +38,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/thread_netif.hpp" #if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 0d836ced7..bd9cd3b7d 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -41,7 +41,6 @@ #include "common/locator-getters.hpp" #include "common/logging.hpp" #include "mac/mac.hpp" -#include "mac/mac_frame.hpp" #include "net/netif.hpp" #include "thread/mesh_forwarder.hpp" #include "thread/mle_router.hpp" diff --git a/src/core/thread/panid_query_server.hpp b/src/core/thread/panid_query_server.hpp index 3213a3ccd..c898ef5b2 100644 --- a/src/core/thread/panid_query_server.hpp +++ b/src/core/thread/panid_query_server.hpp @@ -39,6 +39,7 @@ #include "coap/coap.hpp" #include "common/locator.hpp" #include "common/timer.hpp" +#include "mac/mac_frame.hpp" #include "net/ip6_address.hpp" #include "net/udp6.hpp" diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index c66b8e935..d7bd2518e 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -31,7 +31,7 @@ #include "common/encoding.hpp" #include "common/locator.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/mle_constants.hpp" #include "thread/thread_tlvs.hpp" #include "thread/topology.hpp" diff --git a/src/core/thread/src_match_controller.cpp b/src/core/thread/src_match_controller.cpp index eab3c597d..8ee8f219f 100644 --- a/src/core/thread/src_match_controller.cpp +++ b/src/core/thread/src_match_controller.cpp @@ -38,7 +38,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "radio/radio.hpp" #include "thread/mesh_forwarder.hpp" #include "thread/thread_netif.hpp" diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index 9a93c89a3..0e1100354 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -41,7 +41,7 @@ #include "common/message.hpp" #include "common/random.hpp" #include "common/timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "net/ip6.hpp" #include "thread/device_mode.hpp" #include "thread/indirect_sender.hpp" diff --git a/src/core/utils/child_supervision.hpp b/src/core/utils/child_supervision.hpp index 5dd079602..9c6666bb3 100644 --- a/src/core/utils/child_supervision.hpp +++ b/src/core/utils/child_supervision.hpp @@ -43,7 +43,7 @@ #include "common/message.hpp" #include "common/notifier.hpp" #include "common/timer.hpp" -#include "mac/mac_frame.hpp" +#include "mac/mac_types.hpp" #include "thread/topology.hpp" namespace ot {