From 588dfae6f4be08106b355b18835241291497c08a Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Wed, 26 Jun 2024 23:00:46 +0800 Subject: [PATCH] [posix] check the max number of RCP supported sleepy children (#10399) This commit adds a diag command to rcp capbility diag module to check the max number of RCP supported sleepy children. --- src/posix/platform/README_RCP_CAPS_DIAG.md | 12 ++++ src/posix/platform/rcp_caps_diag.cpp | 73 ++++++++++++++++++++++ src/posix/platform/rcp_caps_diag.hpp | 6 ++ 3 files changed, 91 insertions(+) diff --git a/src/posix/platform/README_RCP_CAPS_DIAG.md b/src/posix/platform/README_RCP_CAPS_DIAG.md index c4f675f6e..faf9909e8 100644 --- a/src/posix/platform/README_RCP_CAPS_DIAG.md +++ b/src/posix/platform/README_RCP_CAPS_DIAG.md @@ -8,6 +8,7 @@ This module provides diag commands for checking RCP capabilities. - [capflags](#capflags) - [spinel](#spinel) +- [srcmatchtable](#srcmatchtable) ## Command Details @@ -112,3 +113,14 @@ PROP_VALUE_SET PHY_TX_POWER ------------------------------- OK PROP_VALUE_SET RADIO_COEX_ENABLE -------------------------- OK Done ``` + +### srcmatchtable + +Check the source match table size supported by the RCP. + +```bash +> diag rcpcaps srcmatchtable +ShortSrcMatchTableSize ------------------------------------ 128 +ExtendedSrcMatchTableSize --------------------------------- 128 +Done +``` diff --git a/src/posix/platform/rcp_caps_diag.cpp b/src/posix/platform/rcp_caps_diag.cpp index 7a2242e38..e972f0e48 100644 --- a/src/posix/platform/rcp_caps_diag.cpp +++ b/src/posix/platform/rcp_caps_diag.cpp @@ -457,6 +457,10 @@ otError RcpCapsDiag::DiagProcess(char *aArgs[], uint8_t aArgsLength) { ProcessCapabilityFlags(); } + else if (strcmp(aArgs[1], "srcmatchtable") == 0) + { + ProcessSrcMatchTable(); + } else if (strcmp(aArgs[1], "spinel") == 0) { ProcessSpinel(); @@ -616,6 +620,66 @@ exit: return ret; } +void RcpCapsDiag::ProcessSrcMatchTable(void) +{ + OutputShortSrcMatchTableSize(); + OutputExtendedSrcMatchTableSize(); +} + +void RcpCapsDiag::OutputShortSrcMatchTableSize(void) +{ + constexpr uint8_t kRouterIdOffset = 10; + constexpr uint8_t kRouterId = 5; + uint16_t num = 0; + uint16_t shortAddress; + + SuccessOrExit(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_ENABLED, SPINEL_DATATYPE_BOOL_S, true /* aEnable */)); + SuccessOrExit(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, nullptr)); + + for (num = 0; num < kMaxNumChildren; num++) + { + shortAddress = num | (kRouterId << kRouterIdOffset); + SuccessOrExit( + mRadioSpinel.Insert(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, SPINEL_DATATYPE_UINT16_S, shortAddress)); + } + +exit: + if (num != 0) + { + IgnoreReturnValue(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_SHORT_ADDRESSES, nullptr)); + IgnoreReturnValue( + mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_ENABLED, SPINEL_DATATYPE_BOOL_S, false /* aEnable */)); + } + + OutputFormat("ShortSrcMatchTableSize", num); +} + +void RcpCapsDiag::OutputExtendedSrcMatchTableSize(void) +{ + otExtAddress extAddress = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; + uint16_t num = 0; + + SuccessOrExit(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_ENABLED, SPINEL_DATATYPE_BOOL_S, true /* aEnable */)); + SuccessOrExit(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr)); + + for (num = 0; num < kMaxNumChildren; num++) + { + *reinterpret_cast(extAddress.m8) = num; + SuccessOrExit( + mRadioSpinel.Insert(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, SPINEL_DATATYPE_EUI64_S, extAddress.m8)); + } + +exit: + if (num != 0) + { + IgnoreReturnValue(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr)); + IgnoreReturnValue( + mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_ENABLED, SPINEL_DATATYPE_BOOL_S, false /* aEnable */)); + } + + OutputFormat("ExtendedSrcMatchTableSize", num); +} + void RcpCapsDiag::OutputFormat(const char *aName, const char *aValue) { static constexpr uint8_t kMaxNameLength = 56; @@ -628,6 +692,15 @@ void RcpCapsDiag::OutputFormat(const char *aName, const char *aValue) Output("%.*s %s %s\r\n", kMaxNameLength, aName, &kPadding[paddingOffset], aValue); } +void RcpCapsDiag::OutputFormat(const char *aName, uint32_t aValue) +{ + static constexpr uint16_t kValueLength = 11; + char value[kValueLength]; + + snprintf(value, sizeof(value), "%u", aValue); + OutputFormat(aName, value); +} + void RcpCapsDiag::OutputResult(const SpinelEntry &aEntry, otError error) { static constexpr uint8_t kSpaceLength = 1; diff --git a/src/posix/platform/rcp_caps_diag.hpp b/src/posix/platform/rcp_caps_diag.hpp index 05e06498b..0431f6167 100644 --- a/src/posix/platform/rcp_caps_diag.hpp +++ b/src/posix/platform/rcp_caps_diag.hpp @@ -108,8 +108,11 @@ private: RcpCapsDiag::SpinelCommandHandler mHandler; }; + static constexpr uint16_t kMaxNumChildren = 512; + void ProcessSpinel(void); void ProcessCapabilityFlags(void); + void ProcessSrcMatchTable(void); void TestSpinelCommands(Category aCategory); void TestRadioCapbilityFlags(void); void OutputRadioCapFlags(Category aCategory, uint32_t aRadioCaps, const uint32_t *aFlags, uint16_t aNumbFlags); @@ -120,7 +123,10 @@ private: const uint32_t *aFlags, uint16_t aNumbFlags); bool IsSpinelCapabilitySupported(const uint8_t *aCapsData, spinel_size_t aCapsLength, uint32_t aCapability); + void OutputExtendedSrcMatchTableSize(void); + void OutputShortSrcMatchTableSize(void); void OutputFormat(const char *aName, const char *aValue); + void OutputFormat(const char *aName, uint32_t aValue); void OutputResult(const SpinelEntry &aEntry, otError error); void Output(const char *aFormat, ...);