From ee642bf005ebc51e3f1eba58db27a8a4077d0c15 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 15 May 2025 10:06:07 -0700 Subject: [PATCH] [border-agent] add 'rv' key to MeshCoP TXT data (#11504) This commit updates `BorderAgent::PrepareServiceTxtData()` to include the "rv" key. This key represents the version of the TXT record format. Per the Thread specification, it must be set to "1". Values other than "1" are reserved for the future and MUST NOT be used. This commit also updates `test_border_agent` to validate this key. --- include/openthread/border_agent.h | 3 ++- include/openthread/instance.h | 2 +- src/core/meshcop/border_agent.cpp | 2 ++ src/core/meshcop/border_agent.hpp | 1 + tests/nexus/test_border_agent.cpp | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/openthread/border_agent.h b/include/openthread/border_agent.h index 89cb8a334..7cd7f8d59 100644 --- a/include/openthread/border_agent.h +++ b/include/openthread/border_agent.h @@ -126,6 +126,7 @@ typedef struct otBorderAgentSessionIterator * * Fields: * Border Agent Id (id) - 4 + 16 = 20 bytes + * Version of TXT record format (rv) - 4 + 1 = 5 bytes * Network Name (nn) - 4 + 16 = 20 bytes * ExtendedPanId (xp) - 4 + 8 = 12 bytes * Thread Version (tv) - 4 + 5 = 9 bytes @@ -138,7 +139,7 @@ typedef struct otBorderAgentSessionIterator * Backbone Router Domain Name (dn) - 4 + 16 = 20 bytes * On-Mesh Routable Prefix (omr) - 5 + 9 = 14 bytes * - * Maximum possible data length: 146 bytes + * Maximum possible data length: 151 bytes */ #define OT_BORDER_AGENT_MESHCOP_SERVICE_TXT_DATA_MAX_LENGTH 256 diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 1cc875012..81968cbca 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (507) +#define OPENTHREAD_API_VERSION (508) /** * @addtogroup api-instance diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index 2819d4009..3741aac14 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -45,6 +45,7 @@ RegisterLogModule("BorderAgent"); //---------------------------------------------------------------------------------------------------------------------- // `BorderAgent` +const char BorderAgent::kTxtDataRecordVersion[] = "1"; #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE const char BorderAgent::kServiceType[] = "_meshcop._udp"; const char BorderAgent::kDefaultBaseServiceName[] = OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME; @@ -542,6 +543,7 @@ Error BorderAgent::PrepareServiceTxtData(uint8_t *aBuffer, uint16_t aBufferSize, } } #endif + SuccessOrExit(error = encoder.AppendStringEntry("rv", kTxtDataRecordVersion)); SuccessOrExit(error = encoder.AppendNameEntry("nn", Get().GetNetworkName().GetAsData())); SuccessOrExit(error = encoder.AppendEntry("xp", Get().GetExtPanId())); SuccessOrExit(error = encoder.AppendStringEntry("tv", kThreadVersionString)); diff --git a/src/core/meshcop/border_agent.hpp b/src/core/meshcop/border_agent.hpp index 19521088f..029e510d0 100644 --- a/src/core/meshcop/border_agent.hpp +++ b/src/core/meshcop/border_agent.hpp @@ -620,6 +620,7 @@ private: using ServiceTask = TaskletIn; + static const char kTxtDataRecordVersion[]; #if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE static const char kServiceType[]; static const char kDefaultBaseServiceName[]; diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index cf47c6fb8..883e4de9a 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -897,6 +897,7 @@ void ValidateMeshCoPTxtData(TxtData &aTxtData, Node &aNode) SuccessOrQuit(aNode.Get().GetId(id)); aTxtData.ValidateKey("id", id); + aTxtData.ValidateKey("rv", "1"); aTxtData.ValidateKey("nn", aNode.Get().GetNetworkName().GetAsCString()); aTxtData.ValidateKey("xp", aNode.Get().GetExtPanId()); aTxtData.ValidateKey("tv", kThreadVersionString);