[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.
This commit is contained in:
Abtin Keshavarzian
2020-03-13 22:06:04 -07:00
committed by Jonathan Hui
parent 9e1020c52f
commit 54e884569b
14 changed files with 252 additions and 312 deletions
+1 -1
View File
@@ -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 \
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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
+2 -3
View File
@@ -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 \
+1 -1
View File
@@ -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;
-246
View File
@@ -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 <stdint.h>
#include <openthread/thread.h>
#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<kInfoStringSize> 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_
+1 -1
View File
@@ -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 {
+1 -44
View File
@@ -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.
*
+1 -1
View File
@@ -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 {
@@ -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"
@@ -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 <stdint.h>
#include <openthread/thread.h>
#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<kInfoStringSize> 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_
+1 -2
View File
@@ -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 {
+1 -1
View File
@@ -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"
+1 -2
View File
@@ -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 {