Skip to content

Commit

Permalink
This commit adds the Thread Domain Name TLV (59) to the MLE Discovery…
Browse files Browse the repository at this point in the history
… Response message. The TLV is only included if not equal to 'DefaultDomain', as per Thread 1.4 spec Section 8.4.4.1.1.2.
  • Loading branch information
EskoDijk committed Sep 21, 2024
1 parent bd310db commit 7b440fd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/openthread/dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ typedef enum otMeshcopTlvType
OT_MESHCOP_TLV_PERIOD = 55, ///< meshcop Period TLV
OT_MESHCOP_TLV_SCAN_DURATION = 56, ///< meshcop Scan Duration TLV
OT_MESHCOP_TLV_ENERGY_LIST = 57, ///< meshcop Energy List TLV
OT_MESHCOP_TLV_THREAD_DOMAIN_NAME = 59, ///< meshcop Thread Domain Name TLV
OT_MESHCOP_TLV_DISCOVERYREQUEST = 128, ///< meshcop Discovery Request TLV
OT_MESHCOP_TLV_DISCOVERYRESPONSE = 129, ///< meshcop Discovery Response TLV
OT_MESHCOP_TLV_JOINERADVERTISEMENT = 241, ///< meshcop Joiner Advertisement TLV
Expand Down
2 changes: 1 addition & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (446)
#define OPENTHREAD_API_VERSION (447)

/**
* @addtogroup api-instance
Expand Down
17 changes: 12 additions & 5 deletions src/core/meshcop/meshcop_tlvs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Tlv : public ot::Tlv
kPeriod = OT_MESHCOP_TLV_PERIOD, ///< Period TLV
kScanDuration = OT_MESHCOP_TLV_SCAN_DURATION, ///< Scan Duration TLV
kEnergyList = OT_MESHCOP_TLV_ENERGY_LIST, ///< Energy List TLV
kThreadDomainName = OT_MESHCOP_TLV_THREAD_DOMAIN_NAME, ///< Thread Domain Name TLV
kDiscoveryRequest = OT_MESHCOP_TLV_DISCOVERYREQUEST, ///< Discovery Request TLV
kDiscoveryResponse = OT_MESHCOP_TLV_DISCOVERYRESPONSE, ///< Discovery Response TLV
kJoinerAdvertisement = OT_MESHCOP_TLV_JOINERADVERTISEMENT, ///< Joiner Advertisement TLV
Expand All @@ -122,11 +123,12 @@ class Tlv : public ot::Tlv
*/
static constexpr uint8_t kMaxProvisioningUrlLength = OT_PROVISIONING_URL_MAX_SIZE;

static constexpr uint8_t kMaxCommissionerIdLength = 64; ///< Max length of Commissioner ID TLV.
static constexpr uint8_t kMaxVendorNameLength = 32; ///< Max length of Vendor Name TLV.
static constexpr uint8_t kMaxVendorModelLength = 32; ///< Max length of Vendor Model TLV.
static constexpr uint8_t kMaxVendorSwVersionLength = 16; ///< Max length of Vendor SW Version TLV.
static constexpr uint8_t kMaxVendorDataLength = 64; ///< Max length of Vendor Data TLV.
static constexpr uint8_t kMaxCommissionerIdLength = 64; ///< Max length of Commissioner ID TLV.
static constexpr uint8_t kMaxVendorNameLength = 32; ///< Max length of Vendor Name TLV.
static constexpr uint8_t kMaxVendorModelLength = 32; ///< Max length of Vendor Model TLV.
static constexpr uint8_t kMaxVendorSwVersionLength = 16; ///< Max length of Vendor SW Version TLV.
static constexpr uint8_t kMaxVendorDataLength = 64; ///< Max length of Vendor Data TLV.
static constexpr uint8_t kMaxThreadDomainNameLength = 16; ///< Max length of Thread Domain Name TLV.

/**
* Returns the Type value.
Expand Down Expand Up @@ -1039,6 +1041,11 @@ class UdpEncapsulationTlvHeader
// Followed by the UDP Payload.
} OT_TOOL_PACKED_END;

/**
* Implements Thread Domain Name TLV type.
*/
typedef StringTlvInfo<Tlv::kThreadDomainName, Tlv::kMaxThreadDomainNameLength> ThreadDomainNameTlv;

/**
* Implements Discovery Request TLV generation and parsing.
*
Expand Down
6 changes: 6 additions & 0 deletions src/core/meshcop/network_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "network_name.hpp"

#include "instance/instance.hpp"
#include "common/string.hpp"

namespace ot {
namespace MeshCoP {
Expand Down Expand Up @@ -158,6 +159,11 @@ Error NetworkNameManager::SetDomainName(const NameData &aNameData)

return (error == kErrorAlready) ? kErrorNone : error;
}

bool NetworkNameManager::IsDefaultDomainNameSet()
{
return StringMatch(mDomainName.GetAsCString(), NetworkName::kDomainNameInit);
}
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)

} // namespace MeshCoP
Expand Down
10 changes: 9 additions & 1 deletion src/core/meshcop/network_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class NetworkName : public otNetworkName, public Unequatable<NetworkName>
{
public:
static constexpr const char *kNetworkNameInit = "OpenThread";
static constexpr const char *kDomainNameInit = "DefaultDomain";
static constexpr const char *kDomainNameInit = "DefaultDomain"; // Section 5.22 Thread spec, MUST NOT change.

/**
* This constant specified the maximum number of chars in Network Name (excludes null char).
Expand Down Expand Up @@ -260,6 +260,14 @@ class NetworkNameManager : public InstanceLocator, private NonCopyable
*
*/
Error SetDomainName(const NameData &aNameData);

/**
* Checks whether the Thread Domain Name is currently set to the default name.
*
* @returns true if Thread Domain Name equals "DefaultDomain", false otherwise.
*/
bool IsDefaultDomainNameSet();

#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)

private:
Expand Down
7 changes: 7 additions & 0 deletions src/core/thread/mle_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,13 @@ Error MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, const M
SuccessOrExit(
error = Tlv::Append<MeshCoP::JoinerUdpPortTlv>(*message, Get<MeshCoP::JoinerRouter>().GetJoinerUdpPort()));

#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_4)
if (!Get<MeshCoP::NetworkNameManager>().IsDefaultDomainNameSet())
{
SuccessOrExit(error = Tlv::Append<MeshCoP::ThreadDomainNameTlv>(*message, Get<MeshCoP::NetworkNameManager>().GetDomainName().GetAsCString()));
}
#endif

tlv.SetLength(static_cast<uint8_t>(message->GetLength() - startOffset));
message->Write(startOffset - sizeof(tlv), tlv);

Expand Down

0 comments on commit 7b440fd

Please sign in to comment.