diff --git a/examples/drivers/windows/include/otLwfIoctl.h b/examples/drivers/windows/include/otLwfIoctl.h index d21ec4f00..b32e9f295 100644 --- a/examples/drivers/windows/include/otLwfIoctl.h +++ b/examples/drivers/windows/include/otLwfIoctl.h @@ -725,8 +725,13 @@ typedef struct otCommissionConfig // uint8_t - aNewIterator (output) // otExternalRouteConfig - aConfig (output) +#define IOCTL_OTLWF_OT_MAX_ROUTER_ID \ + OTLWF_CTL_CODE(202, METHOD_BUFFERED, FILE_READ_DATA) + // GUID - InterfaceGuid + // uint8_t - aMaxRouterId + // OpenThread function IOCTL codes #define MIN_OTLWF_IOCTL_FUNC_CODE 100 -#define MAX_OTLWF_IOCTL_FUNC_CODE 201 +#define MAX_OTLWF_IOCTL_FUNC_CODE 202 #endif //__OTLWFIOCTL_H__ diff --git a/examples/drivers/windows/otApi/otApi.cpp b/examples/drivers/windows/otApi/otApi.cpp index 7f3335d1c..c3f897a48 100644 --- a/examples/drivers/windows/otApi/otApi.cpp +++ b/examples/drivers/windows/otApi/otApi.cpp @@ -3205,6 +3205,18 @@ otThreadGetRouterIdSequence( return Result; } +OTAPI +uint8_t +OTCALL +otThreadGetMaxRouterId( + _In_ otInstance *aInstance + ) +{ + uint8_t Result = 0; + if (aInstance) (void)QueryIOCTL(aInstance, IOCTL_OTLWF_OT_MAX_ROUTER_ID, &Result); + return Result; +} + OTAPI otError OTCALL diff --git a/examples/drivers/windows/otLwf/iocontrol.c b/examples/drivers/windows/otLwf/iocontrol.c index 721061a2c..914a5d070 100644 --- a/examples/drivers/windows/otLwf/iocontrol.c +++ b/examples/drivers/windows/otLwf/iocontrol.c @@ -95,6 +95,7 @@ OTLWF_IOCTL_HANDLER IoCtls[] = { "IOCTL_OTLWF_OT_PARTITION_ID", REF_IOCTL_FUNC_WITH_TUN(otPartitionId) }, { "IOCTL_OTLWF_OT_RLOC16", REF_IOCTL_FUNC_WITH_TUN(otRloc16) }, { "IOCTL_OTLWF_OT_ROUTER_ID_SEQUENCE", REF_IOCTL_FUNC(otRouterIdSequence) }, + { "IOCTL_OTLWF_OT_MAX_ROUTER_ID", REF_IOCTL_FUNC(otMaxRouterId) }, { "IOCTL_OTLWF_OT_ROUTER_INFO", REF_IOCTL_FUNC(otRouterInfo) }, { "IOCTL_OTLWF_OT_STABLE_NETWORK_DATA_VERSION", REF_IOCTL_FUNC_WITH_TUN(otStableNetworkDataVersion) }, { "IOCTL_OTLWF_OT_MAC_BLACKLIST_ENABLED", REF_IOCTL_FUNC(otMacBlacklistEnabled) }, @@ -4509,6 +4510,37 @@ otLwfIoCtl_otRouterIdSequence( return status; } +_IRQL_requires_max_(PASSIVE_LEVEL) +NTSTATUS +otLwfIoCtl_otMaxRouterId( + _In_ PMS_FILTER pFilter, + _In_reads_bytes_(InBufferLength) + PUCHAR InBuffer, + _In_ ULONG InBufferLength, + _Out_writes_bytes_(*OutBufferLength) + PVOID OutBuffer, + _Inout_ PULONG OutBufferLength + ) +{ + NTSTATUS status = STATUS_INVALID_PARAMETER; + + UNREFERENCED_PARAMETER(InBuffer); + UNREFERENCED_PARAMETER(InBufferLength); + + if (*OutBufferLength >= sizeof(uint8_t)) + { + *(uint8_t*)OutBuffer = otThreadGetMaxRouterId(pFilter->otCtx); + *OutBufferLength = sizeof(uint8_t); + status = STATUS_SUCCESS; + } + else + { + *OutBufferLength = 0; + } + + return status; +} + _IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS otLwfIoCtl_otRouterInfo( diff --git a/examples/drivers/windows/otLwf/iocontrol.h b/examples/drivers/windows/otLwf/iocontrol.h index fd1973021..12c5a5feb 100644 --- a/examples/drivers/windows/otLwf/iocontrol.h +++ b/examples/drivers/windows/otLwf/iocontrol.h @@ -181,6 +181,7 @@ DECL_IOCTL_FUNC_WITH_TUN2(otNetworkDataVersion); DECL_IOCTL_FUNC_WITH_TUN2(otPartitionId); DECL_IOCTL_FUNC_WITH_TUN2(otRloc16); DECL_IOCTL_FUNC(otRouterIdSequence); +DECL_IOCTL_FUNC(otMaxRouterId); DECL_IOCTL_FUNC(otRouterInfo); DECL_IOCTL_FUNC_WITH_TUN2(otStableNetworkDataVersion); DECL_IOCTL_FUNC(otMacBlacklistEnabled); diff --git a/include/openthread/thread_ftd.h b/include/openthread/thread_ftd.h index fab254151..f6c267311 100644 --- a/include/openthread/thread_ftd.h +++ b/include/openthread/thread_ftd.h @@ -406,7 +406,7 @@ OTAPI uint8_t OTCALL otThreadGetRouterIdSequence(otInstance *aInstance); * @returns The maximum allowed router ID. * */ -uint8_t otThreadGetMaxRouterId(otInstance *aInstance); +OTAPI uint8_t OTCALL otThreadGetMaxRouterId(otInstance *aInstance); /** * The function retains diagnostic information for a given Thread Router. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index f125d66a8..ed2732655 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2333,6 +2333,8 @@ void Interpreter::ProcessRouter(int argc, char *argv[]) if (isTable || strcmp(argv[0], "list") == 0) { + uint8_t maxRouterId; + if (isTable) { mServer->OutputFormat( @@ -2341,40 +2343,41 @@ void Interpreter::ProcessRouter(int argc, char *argv[]) "+----+--------+----------+-----------+-------+--------+-----+------------------+\r\n"); } - for (uint8_t i = 0;; i++) + maxRouterId = otThreadGetMaxRouterId(mInstance); + + for (uint8_t i = 0; i <= maxRouterId; i++) { if (otThreadGetRouterInfo(mInstance, i, &routerInfo) != OT_ERROR_NONE) { - mServer->OutputFormat("\r\n"); - ExitNow(); + continue; } - if (routerInfo.mAllocated) + if (isTable) { - if (isTable) - { - mServer->OutputFormat("| %2d ", routerInfo.mRouterId); - mServer->OutputFormat("| 0x%04x ", routerInfo.mRloc16); - mServer->OutputFormat("| %8d ", routerInfo.mNextHop); - mServer->OutputFormat("| %9d ", routerInfo.mPathCost); - mServer->OutputFormat("| %5d ", routerInfo.mLinkQualityIn); - mServer->OutputFormat("| %6d ", routerInfo.mLinkQualityOut); - mServer->OutputFormat("| %3d ", routerInfo.mAge); - mServer->OutputFormat("| "); + mServer->OutputFormat("| %2d ", routerInfo.mRouterId); + mServer->OutputFormat("| 0x%04x ", routerInfo.mRloc16); + mServer->OutputFormat("| %8d ", routerInfo.mNextHop); + mServer->OutputFormat("| %9d ", routerInfo.mPathCost); + mServer->OutputFormat("| %5d ", routerInfo.mLinkQualityIn); + mServer->OutputFormat("| %6d ", routerInfo.mLinkQualityOut); + mServer->OutputFormat("| %3d ", routerInfo.mAge); + mServer->OutputFormat("| "); - for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++) - { - mServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]); - } - - mServer->OutputFormat(" |\r\n"); - } - else + for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++) { - mServer->OutputFormat("%d ", i); + mServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]); } + + mServer->OutputFormat(" |\r\n"); + } + else + { + mServer->OutputFormat("%d ", i); } } + + mServer->OutputFormat("\r\n"); + ExitNow(); } SuccessOrExit(error = ParseLong(argv[0], value));