From 54e884569b09a465835d8bdf854c914c7de97081 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 11 Mar 2020 11:57:03 -0700 Subject: [PATCH] [mle-types] adding new files mle_types.hpp/cpp (#4679) The newly added `mle_types.hpp/cpp` files include MLE specific types (e.g. `DeviceMode`) and constants. --- Android.mk | 2 +- BUILD.gn | 2 +- src/core/CMakeLists.txt | 2 +- src/core/Makefile.am | 5 +- src/core/api/thread_ftd_api.cpp | 2 +- src/core/thread/device_mode.hpp | 246 ------------------ src/core/thread/indirect_sender.hpp | 2 +- src/core/thread/mle.hpp | 45 +--- src/core/thread/mle_tlvs.hpp | 2 +- .../thread/{device_mode.cpp => mle_types.cpp} | 4 +- .../{mle_constants.hpp => mle_types.hpp} | 244 ++++++++++++++++- src/core/thread/network_diagnostic_tlvs.hpp | 3 +- src/core/thread/router_table.hpp | 2 +- src/core/thread/topology.hpp | 3 +- 14 files changed, 252 insertions(+), 312 deletions(-) delete mode 100644 src/core/thread/device_mode.hpp rename src/core/thread/{device_mode.cpp => mle_types.cpp} (97%) rename src/core/thread/{mle_constants.hpp => mle_types.hpp} (52%) diff --git a/Android.mk b/Android.mk index e8e965ae2..01dd981c9 100644 --- a/Android.mk +++ b/Android.mk @@ -217,7 +217,6 @@ LOCAL_SRC_FILES := \ src/core/thread/announce_begin_server.cpp \ src/core/thread/announce_sender.cpp \ src/core/thread/child_table.cpp \ - src/core/thread/device_mode.cpp \ src/core/thread/energy_scan_server.cpp \ src/core/thread/indirect_sender.cpp \ src/core/thread/key_manager.cpp \ @@ -228,6 +227,7 @@ LOCAL_SRC_FILES := \ src/core/thread/mesh_forwarder_mtd.cpp \ src/core/thread/mle.cpp \ src/core/thread/mle_router.cpp \ + src/core/thread/mle_types.cpp \ src/core/thread/network_data.cpp \ src/core/thread/network_data_leader.cpp \ src/core/thread/network_data_leader_ftd.cpp \ diff --git a/BUILD.gn b/BUILD.gn index 033120c35..49ac2270d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -132,7 +132,6 @@ static_library("lib-ot-core") { "src/core/thread/announce_begin_server.cpp", "src/core/thread/announce_sender.cpp", "src/core/thread/child_table.cpp", - "src/core/thread/device_mode.cpp", "src/core/thread/energy_scan_server.cpp", "src/core/thread/indirect_sender.cpp", "src/core/thread/key_manager.cpp", @@ -143,6 +142,7 @@ static_library("lib-ot-core") { "src/core/thread/mesh_forwarder_mtd.cpp", "src/core/thread/mle.cpp", "src/core/thread/mle_router.cpp", + "src/core/thread/mle_types.cpp", "src/core/thread/network_data.cpp", "src/core/thread/network_data_leader.cpp", "src/core/thread/network_data_leader_ftd.cpp", diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b27eb01d5..36281395a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -170,7 +170,6 @@ set(COMMON_SOURCES thread/announce_begin_server.cpp thread/announce_sender.cpp thread/child_table.cpp - thread/device_mode.cpp thread/energy_scan_server.cpp thread/indirect_sender.cpp thread/key_manager.cpp @@ -181,6 +180,7 @@ set(COMMON_SOURCES thread/mesh_forwarder_mtd.cpp thread/mle.cpp thread/mle_router.cpp + thread/mle_types.cpp thread/network_data.cpp thread/network_data_leader.cpp thread/network_data_leader_ftd.cpp diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8a75cd86d..79d2ca1a0 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -208,7 +208,6 @@ SOURCES_COMMON = \ thread/announce_begin_server.cpp \ thread/announce_sender.cpp \ thread/child_table.cpp \ - thread/device_mode.cpp \ thread/energy_scan_server.cpp \ thread/indirect_sender.cpp \ thread/key_manager.cpp \ @@ -219,6 +218,7 @@ SOURCES_COMMON = \ thread/mesh_forwarder_mtd.cpp \ thread/mle.cpp \ thread/mle_router.cpp \ + thread/mle_types.cpp \ thread/network_data.cpp \ thread/network_data_leader.cpp \ thread/network_data_leader_ftd.cpp \ @@ -404,7 +404,6 @@ HEADERS_COMMON = \ thread/announce_begin_server.hpp \ thread/announce_sender.hpp \ thread/child_table.hpp \ - thread/device_mode.hpp \ thread/energy_scan_server.hpp \ thread/indirect_sender.hpp \ thread/indirect_sender_frame_context.hpp \ @@ -413,11 +412,11 @@ HEADERS_COMMON = \ thread/lowpan.hpp \ thread/mesh_forwarder.hpp \ thread/mle.hpp \ - thread/mle_constants.hpp \ thread/mle_router.hpp \ thread/mle_router_ftd.hpp \ thread/mle_router_mtd.hpp \ thread/mle_tlvs.hpp \ + thread/mle_types.hpp \ thread/network_data.hpp \ thread/network_data_leader.hpp \ thread/network_data_leader_ftd.hpp \ diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index b39e4ab38..3c4a79883 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -39,7 +39,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" -#include "thread/mle_constants.hpp" +#include "thread/mle_types.hpp" #include "thread/topology.hpp" using namespace ot; diff --git a/src/core/thread/device_mode.hpp b/src/core/thread/device_mode.hpp deleted file mode 100644 index 32507aca2..000000000 --- a/src/core/thread/device_mode.hpp +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 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 MLE device mode. - */ - -#ifndef DEVICE_MODE_HPP_ -#define DEVICE_MODE_HPP_ - -#include "openthread-core-config.h" - -#include - -#include - -#include "common/string.hpp" - -namespace ot { -namespace Mle { - -/** - * @addtogroup core-mle-core - * - * @brief - * This module includes definition for MLE device mode. - * - * @{ - * - */ - -/** - * This type represents a MLE device mode. - * - */ -class DeviceMode -{ -public: - enum - { - kModeRxOnWhenIdle = 1 << 3, ///< If the device has its receiver on when not transmitting. - kModeSecureDataRequest = 1 << 2, ///< If the device uses link layer security for all data requests. - kModeFullThreadDevice = 1 << 1, ///< If the device is an FTD. - kModeFullNetworkData = 1 << 0, ///< If the device requires the full Network Data. - - kInfoStringSize = 45, ///< String buffer size used for `ToString()`. - }; - - /** - * This type defines the fixed-length `String` object returned from `ToString()`. - * - */ - typedef String InfoString; - - /** - * This structure represents an MLE Mode configuration. - * - */ - typedef otLinkModeConfig ModeConfig; - - /** - * This is the default constructor for `DeviceMode` object. - * - */ - DeviceMode(void) {} - - /** - * This constructor initializes a `DeviceMode` object from a given mode TLV bitmask. - * - * @param[in] aMode A mode TLV bitmask to initialize the `DeviceMode` object. - * - */ - explicit DeviceMode(uint8_t aMode) - : mMode(aMode) - { - } - - /** - * This constructor initializes a `DeviceMode` object from a given mode configuration structure. - * - * @param[in] aModeConfig A mode configuration to initialize the `DeviceMode` object. - * - */ - explicit DeviceMode(ModeConfig aModeConfig) { Set(aModeConfig); } - - /** - * This method gets the device mode as a mode TLV bitmask. - * - * @returns The device mode as a mode TLV bitmask. - * - */ - uint8_t Get(void) const { return mMode; } - - /** - * This method sets the device mode from a given mode TLV bitmask. - * - * @param[in] aMode A mode TLV bitmask. - * - */ - void Set(uint8_t aMode) { mMode = aMode; } - - /** - * This method gets the device mode as a mode configuration structure. - * - * @param[out] aModeConfig A reference to a mode configuration structure to output the device mode. - * - */ - void Get(ModeConfig &aModeConfig) const; - - /** - * this method sets the device mode from a given mode configuration structure. - * - * @param[in] aModeConfig A mode configuration structure. - * - */ - void Set(const ModeConfig &aModeConfig); - - /** - * This method indicates whether or not the device is rx-on-when-idle. - * - * @retval TRUE If the device is rx-on-when-idle (non-sleepy). - * @retval FALSE If the device is not rx-on-when-idle (sleepy). - * - */ - bool IsRxOnWhenIdle(void) const { return (mMode & kModeRxOnWhenIdle) != 0; } - - /** - * This method indicates whether or not the device uses secure IEEE 802.15.4 Data Request messages. - * - * @retval TRUE If the device uses secure IEEE 802.15.4 Data Request (data poll) messages. - * @retval FALSE If the device uses any IEEE 802.15.4 Data Request (data poll) messages. - * - */ - bool IsSecureDataRequest(void) const { return (mMode & kModeSecureDataRequest) != 0; } - - /** - * This method indicates whether or not the device is a Full Thread Device. - * - * @retval TRUE If the device is Full Thread Device. - * @retval FALSE If the device if not Full Thread Device. - * - */ - bool IsFullThreadDevice(void) const { return (mMode & kModeFullThreadDevice) != 0; } - - /** - * This method indicates whether or not the device requests Full Network Data. - * - * @retval TRUE If the device requests Full Network Data. - * @retval FALSE If the device does not request Full Network Data (only stable Network Data). - * - */ - bool IsFullNetworkData(void) const { return (mMode & kModeFullNetworkData) != 0; } - - /** - * This method indicates whether or not the device is a Minimal End Device. - * - * @retval TRUE If the device is a Minimal End Device. - * @retval FALSE If the device is not a Minimal End Device. - * - */ - bool IsMinimalEndDevice(void) const - { - return (mMode & (kModeFullThreadDevice | kModeRxOnWhenIdle)) != (kModeFullThreadDevice | kModeRxOnWhenIdle); - } - - /** - * This method indicates whether or not the device mode flags are valid. - * - * An FTD which is not rx-on-when-idle (is sleepy) is considered invalid. - * - * @returns TRUE if , FALSE otherwise. - * @retval TRUE If the device mode flags are valid. - * @retval FALSE If the device mode flags are not valid. - * - */ - bool IsValid(void) const { return !IsFullThreadDevice() || IsRxOnWhenIdle(); } - - /** - * This method overloads operator `==` to evaluate whether or not two device modes are equal - * - * @param[in] aOther The other device mode to compare with. - * - * @retval TRUE If the device modes are equal. - * @retval FALSE If the device modes are not equal. - * - */ - bool operator==(const DeviceMode &aOther) const { return (mMode == aOther.mMode); } - - /** - * This method overloads operator `!=` to evaluate whether or not two device modes are not equal. - * - * @param[in] aOther The other device mode to compare with. - * - * @retval TRUE If the device modes are not equal. - * @retval FALSE If the device modes are equal. - * - */ - bool operator!=(const DeviceMode &aOther) const { return !(*this == aOther); } - - /** - * This method converts the device mode into a human-readable string. - * - * @returns An `InfoString` object representing the device mode. - * - */ - InfoString ToString(void) const; - -private: - uint8_t mMode; -}; - -/** - * @} - * - */ - -} // namespace Mle -} // namespace ot - -#endif // DEVICE_MODE_HPP_ diff --git a/src/core/thread/indirect_sender.hpp b/src/core/thread/indirect_sender.hpp index 7bc47f58f..8d081b1eb 100644 --- a/src/core/thread/indirect_sender.hpp +++ b/src/core/thread/indirect_sender.hpp @@ -40,8 +40,8 @@ #include "common/message.hpp" #include "mac/data_poll_handler.hpp" #include "mac/mac_frame.hpp" -#include "thread/device_mode.hpp" #include "thread/indirect_sender_frame_context.hpp" +#include "thread/mle_types.hpp" #include "thread/src_match_controller.hpp" namespace ot { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index ab19ba8a3..650638d4c 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -42,9 +42,8 @@ #include "mac/mac.hpp" #include "meshcop/joiner_router.hpp" #include "net/udp6.hpp" -#include "thread/device_mode.hpp" -#include "thread/mle_constants.hpp" #include "thread/mle_tlvs.hpp" +#include "thread/mle_types.hpp" #include "thread/topology.hpp" namespace ot { @@ -83,48 +82,6 @@ namespace Mle { * */ -/** - * MLE Attach modes - * - */ -enum AttachMode -{ - kAttachAny = 0, ///< Attach to any Thread partition. - kAttachSame1 = 1, ///< Attach to the same Thread partition (attempt 1 when losing connectivity). - kAttachSame2 = 2, ///< Attach to the same Thread partition (attempt 2 when losing connectivity). - kAttachBetter = 3, ///< Attach to a better (i.e. higher weight/partition id) Thread partition. - kAttachSameDowngrade = 4, ///< Attach to the same Thread partition during downgrade process. -}; - -/** - * This enumeration represents the allocation of the ALOC Space - * - */ -enum AlocAllocation -{ - kAloc16Leader = 0xfc00, - kAloc16DhcpAgentStart = 0xfc01, - kAloc16DhcpAgentEnd = 0xfc0f, - kAloc16DhcpAgentMask = 0x000f, - kAloc16ServiceStart = 0xfc10, - kAloc16ServiceEnd = 0xfc2f, - kAloc16CommissionerStart = 0xfc30, - kAloc16CommissionerEnd = 0xfc37, - kAloc16CommissionerMask = 0x0007, - kAloc16NeighborDiscoveryAgentStart = 0xfc40, - kAloc16NeighborDiscoveryAgentEnd = 0xfc4e, -}; - -/** - * Service IDs - * - */ -enum ServiceID -{ - kServiceMinId = 0x00, ///< Minimal Service ID. - kServiceMaxId = 0x0f, ///< Maximal Service ID. -}; - /** * This class implements MLE Header generation and parsing. * diff --git a/src/core/thread/mle_tlvs.hpp b/src/core/thread/mle_tlvs.hpp index 99989fb40..38f191ce2 100644 --- a/src/core/thread/mle_tlvs.hpp +++ b/src/core/thread/mle_tlvs.hpp @@ -41,7 +41,7 @@ #include "common/tlvs.hpp" #include "meshcop/timestamp.hpp" #include "net/ip6_address.hpp" -#include "thread/mle_constants.hpp" +#include "thread/mle_types.hpp" namespace ot { diff --git a/src/core/thread/device_mode.cpp b/src/core/thread/mle_types.cpp similarity index 97% rename from src/core/thread/device_mode.cpp rename to src/core/thread/mle_types.cpp index 0972a541d..6bfa1beea 100644 --- a/src/core/thread/device_mode.cpp +++ b/src/core/thread/mle_types.cpp @@ -28,10 +28,10 @@ /** * @file - * This file implements of MLE device mode. + * This file implements of MLE types and constants. */ -#include "device_mode.hpp" +#include "mle_types.hpp" #include "common/code_utils.hpp" diff --git a/src/core/thread/mle_constants.hpp b/src/core/thread/mle_types.hpp similarity index 52% rename from src/core/thread/mle_constants.hpp rename to src/core/thread/mle_types.hpp index 1859c4c43..8ac860612 100644 --- a/src/core/thread/mle_constants.hpp +++ b/src/core/thread/mle_types.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, The OpenThread Authors. + * Copyright (c) 2019, The OpenThread Authors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,20 +28,31 @@ /** * @file - * This file includes definitions for MLE functionality required by the Thread Child, Router, and Leader roles. + * This file includes definitions for MLE types and constants. */ -#ifndef MLE_CONSTANTS_HPP_ -#define MLE_CONSTANTS_HPP_ +#ifndef MLE_TYPES_HPP_ +#define MLE_TYPES_HPP_ #include "openthread-core-config.h" +#include + +#include + +#include "common/string.hpp" + namespace ot { namespace Mle { /** * @addtogroup core-mle-core * + * @brief + * This module includes definition for MLE types and constants. + * + * @{ + * */ enum @@ -169,13 +180,234 @@ enum kMplRouterDataMessageTimerExpirations = 2, ///< Number of MPL retransmissions for Routers. }; -} // namespace Mle +/** + * MLE Attach modes + * + */ +enum AttachMode +{ + kAttachAny = 0, ///< Attach to any Thread partition. + kAttachSame1 = 1, ///< Attach to the same Thread partition (attempt 1 when losing connectivity). + kAttachSame2 = 2, ///< Attach to the same Thread partition (attempt 2 when losing connectivity). + kAttachBetter = 3, ///< Attach to a better (i.e. higher weight/partition id) Thread partition. + kAttachSameDowngrade = 4, ///< Attach to the same Thread partition during downgrade process. +}; + +/** + * This enumeration represents the allocation of the ALOC Space + * + */ +enum AlocAllocation +{ + kAloc16Leader = 0xfc00, + kAloc16DhcpAgentStart = 0xfc01, + kAloc16DhcpAgentEnd = 0xfc0f, + kAloc16DhcpAgentMask = 0x000f, + kAloc16ServiceStart = 0xfc10, + kAloc16ServiceEnd = 0xfc2f, + kAloc16CommissionerStart = 0xfc30, + kAloc16CommissionerEnd = 0xfc37, + kAloc16CommissionerMask = 0x0007, + kAloc16NeighborDiscoveryAgentStart = 0xfc40, + kAloc16NeighborDiscoveryAgentEnd = 0xfc4e, +}; + +/** + * Service IDs + * + */ +enum ServiceID +{ + kServiceMinId = 0x00, ///< Minimal Service ID. + kServiceMaxId = 0x0f, ///< Maximal Service ID. +}; + +/** + * This type represents a MLE device mode. + * + */ +class DeviceMode +{ +public: + enum + { + kModeRxOnWhenIdle = 1 << 3, ///< If the device has its receiver on when not transmitting. + kModeSecureDataRequest = 1 << 2, ///< If the device uses link layer security for all data requests. + kModeFullThreadDevice = 1 << 1, ///< If the device is an FTD. + kModeFullNetworkData = 1 << 0, ///< If the device requires the full Network Data. + + kInfoStringSize = 45, ///< String buffer size used for `ToString()`. + }; + + /** + * This type defines the fixed-length `String` object returned from `ToString()`. + * + */ + typedef String InfoString; + + /** + * This structure represents an MLE Mode configuration. + * + */ + typedef otLinkModeConfig ModeConfig; + + /** + * This is the default constructor for `DeviceMode` object. + * + */ + DeviceMode(void) {} + + /** + * This constructor initializes a `DeviceMode` object from a given mode TLV bitmask. + * + * @param[in] aMode A mode TLV bitmask to initialize the `DeviceMode` object. + * + */ + explicit DeviceMode(uint8_t aMode) + : mMode(aMode) + { + } + + /** + * This constructor initializes a `DeviceMode` object from a given mode configuration structure. + * + * @param[in] aModeConfig A mode configuration to initialize the `DeviceMode` object. + * + */ + explicit DeviceMode(ModeConfig aModeConfig) { Set(aModeConfig); } + + /** + * This method gets the device mode as a mode TLV bitmask. + * + * @returns The device mode as a mode TLV bitmask. + * + */ + uint8_t Get(void) const { return mMode; } + + /** + * This method sets the device mode from a given mode TLV bitmask. + * + * @param[in] aMode A mode TLV bitmask. + * + */ + void Set(uint8_t aMode) { mMode = aMode; } + + /** + * This method gets the device mode as a mode configuration structure. + * + * @param[out] aModeConfig A reference to a mode configuration structure to output the device mode. + * + */ + void Get(ModeConfig &aModeConfig) const; + + /** + * this method sets the device mode from a given mode configuration structure. + * + * @param[in] aModeConfig A mode configuration structure. + * + */ + void Set(const ModeConfig &aModeConfig); + + /** + * This method indicates whether or not the device is rx-on-when-idle. + * + * @retval TRUE If the device is rx-on-when-idle (non-sleepy). + * @retval FALSE If the device is not rx-on-when-idle (sleepy). + * + */ + bool IsRxOnWhenIdle(void) const { return (mMode & kModeRxOnWhenIdle) != 0; } + + /** + * This method indicates whether or not the device uses secure IEEE 802.15.4 Data Request messages. + * + * @retval TRUE If the device uses secure IEEE 802.15.4 Data Request (data poll) messages. + * @retval FALSE If the device uses any IEEE 802.15.4 Data Request (data poll) messages. + * + */ + bool IsSecureDataRequest(void) const { return (mMode & kModeSecureDataRequest) != 0; } + + /** + * This method indicates whether or not the device is a Full Thread Device. + * + * @retval TRUE If the device is Full Thread Device. + * @retval FALSE If the device if not Full Thread Device. + * + */ + bool IsFullThreadDevice(void) const { return (mMode & kModeFullThreadDevice) != 0; } + + /** + * This method indicates whether or not the device requests Full Network Data. + * + * @retval TRUE If the device requests Full Network Data. + * @retval FALSE If the device does not request Full Network Data (only stable Network Data). + * + */ + bool IsFullNetworkData(void) const { return (mMode & kModeFullNetworkData) != 0; } + + /** + * This method indicates whether or not the device is a Minimal End Device. + * + * @retval TRUE If the device is a Minimal End Device. + * @retval FALSE If the device is not a Minimal End Device. + * + */ + bool IsMinimalEndDevice(void) const + { + return (mMode & (kModeFullThreadDevice | kModeRxOnWhenIdle)) != (kModeFullThreadDevice | kModeRxOnWhenIdle); + } + + /** + * This method indicates whether or not the device mode flags are valid. + * + * An FTD which is not rx-on-when-idle (is sleepy) is considered invalid. + * + * @returns TRUE if , FALSE otherwise. + * @retval TRUE If the device mode flags are valid. + * @retval FALSE If the device mode flags are not valid. + * + */ + bool IsValid(void) const { return !IsFullThreadDevice() || IsRxOnWhenIdle(); } + + /** + * This method overloads operator `==` to evaluate whether or not two device modes are equal + * + * @param[in] aOther The other device mode to compare with. + * + * @retval TRUE If the device modes are equal. + * @retval FALSE If the device modes are not equal. + * + */ + bool operator==(const DeviceMode &aOther) const { return (mMode == aOther.mMode); } + + /** + * This method overloads operator `!=` to evaluate whether or not two device modes are not equal. + * + * @param[in] aOther The other device mode to compare with. + * + * @retval TRUE If the device modes are not equal. + * @retval FALSE If the device modes are equal. + * + */ + bool operator!=(const DeviceMode &aOther) const { return !(*this == aOther); } + + /** + * This method converts the device mode into a human-readable string. + * + * @returns An `InfoString` object representing the device mode. + * + */ + InfoString ToString(void) const; + +private: + uint8_t mMode; +}; /** * @} * */ +} // namespace Mle } // namespace ot -#endif // MLE_CONSTANTS_HPP_ +#endif // MLE_TYPES_HPP_ diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index 2bdaf2c6c..5b742f969 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -43,8 +43,7 @@ #include "common/tlvs.hpp" #include "net/ip6_address.hpp" #include "radio/radio.hpp" -#include "thread/device_mode.hpp" -#include "thread/mle_constants.hpp" +#include "thread/mle_types.hpp" namespace ot { diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index d7bd2518e..29819b10e 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -32,7 +32,7 @@ #include "common/encoding.hpp" #include "common/locator.hpp" #include "mac/mac_types.hpp" -#include "thread/mle_constants.hpp" +#include "thread/mle_types.hpp" #include "thread/thread_tlvs.hpp" #include "thread/topology.hpp" diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index 5534de60e..ade048356 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -44,11 +44,10 @@ #include "common/timer.hpp" #include "mac/mac_types.hpp" #include "net/ip6.hpp" -#include "thread/device_mode.hpp" #include "thread/indirect_sender.hpp" #include "thread/link_quality.hpp" -#include "thread/mle_constants.hpp" #include "thread/mle_tlvs.hpp" +#include "thread/mle_types.hpp" namespace ot {