mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 04:37:47 +00:00
[cli] simplify argument processing (#6767)
This commit changes `ParseCmd()` such that as `aArgs` array entries
are populated with parsed arguments from a command line string, the
remaining unused `aArgs` entries in the array are marked as "empty".
We also ensure that the `aArgs[]` array always end with an "empty"
`Arg` which indicates end of the list (this is similar to how C
string ends with a null '\0' character). This commit also changes
different methods of `Arg` class (`Arg::ParseAs{Type}()` or overload
of operator `==`, etc) to check and handle when `Arg` is marked
as "empty".
These changes help simplify how the arguments are processed in CLI
modules. In `Cli::Process{Command}()` methods we can just pass the
`aArgs[]` array and do not need to pass a separate args length
parameter. In many cases the args length checks can be removed since
it will be checked from `ParseAs{Type}()` call.
This commit is contained in:
+439
-565
File diff suppressed because it is too large
Load Diff
+128
-144
@@ -311,7 +311,7 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Interpreter::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (Interpreter::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
template <typename ValueType> using GetHandler = ValueType (&)(otInstance *);
|
||||
@@ -321,7 +321,7 @@ private:
|
||||
// Returns format string to output a `ValueType` (e.g., "%u" for `uint16_t`).
|
||||
template <typename ValueType> static constexpr const char *FormatStringFor(void);
|
||||
|
||||
template <typename ValueType> otError ProcessGet(uint8_t aArgsLength, GetHandler<ValueType> aGetHandler)
|
||||
template <typename ValueType> otError ProcessGet(Arg aArgs[], GetHandler<ValueType> aGetHandler)
|
||||
{
|
||||
static_assert(
|
||||
TypeTraits::IsSame<ValueType, uint8_t>::kValue || TypeTraits::IsSame<ValueType, uint16_t>::kValue ||
|
||||
@@ -331,44 +331,35 @@ private:
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
OutputLine(FormatStringFor<ValueType>(), aGetHandler(mInstance));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
template <typename ValueType> otError ParseValue(uint8_t aArgsLength, Arg aArgs[], ValueType &aValue)
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
VerifyOrExit(aArgsLength == 1);
|
||||
error = aArgs[0].ParseAs<ValueType>(aValue);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
otError ProcessSet(uint8_t aArgsLength, Arg aArgs[], SetHandler<ValueType> aSetHandler)
|
||||
template <typename ValueType> otError ProcessSet(Arg aArgs[], SetHandler<ValueType> aSetHandler)
|
||||
{
|
||||
otError error;
|
||||
ValueType value;
|
||||
|
||||
SuccessOrExit(error = ParseValue(aArgsLength, aArgs, value));
|
||||
SuccessOrExit(error = aArgs[0].ParseAs<ValueType>(value));
|
||||
VerifyOrExit(aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
aSetHandler(mInstance, value);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
otError ProcessSet(uint8_t aArgsLength, Arg aArgs[], SetHandlerFailable<ValueType> aSetHandler)
|
||||
template <typename ValueType> otError ProcessSet(Arg aArgs[], SetHandlerFailable<ValueType> aSetHandler)
|
||||
{
|
||||
otError error;
|
||||
ValueType value;
|
||||
|
||||
SuccessOrExit(error = ParseValue(aArgsLength, aArgs, value));
|
||||
SuccessOrExit(error = aArgs[0].ParseAs<ValueType>(value));
|
||||
VerifyOrExit(aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = aSetHandler(mInstance, value);
|
||||
|
||||
exit:
|
||||
@@ -376,30 +367,24 @@ private:
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
otError ProcessGetSet(uint8_t aArgsLength,
|
||||
Arg aArgs[],
|
||||
GetHandler<ValueType> aGetHandler,
|
||||
SetHandler<ValueType> aSetHandler)
|
||||
otError ProcessGetSet(Arg aArgs[], GetHandler<ValueType> aGetHandler, SetHandler<ValueType> aSetHandler)
|
||||
{
|
||||
otError error = ProcessGet(aArgsLength, aGetHandler);
|
||||
otError error = ProcessGet(aArgs, aGetHandler);
|
||||
|
||||
VerifyOrExit(error != OT_ERROR_NONE);
|
||||
error = ProcessSet(aArgsLength, aArgs, aSetHandler);
|
||||
error = ProcessSet(aArgs, aSetHandler);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
otError ProcessGetSet(uint8_t aArgsLength,
|
||||
Arg aArgs[],
|
||||
GetHandler<ValueType> aGetHandler,
|
||||
SetHandlerFailable<ValueType> aSetHandler)
|
||||
otError ProcessGetSet(Arg aArgs[], GetHandler<ValueType> aGetHandler, SetHandlerFailable<ValueType> aSetHandler)
|
||||
{
|
||||
otError error = ProcessGet(aArgsLength, aGetHandler);
|
||||
otError error = ProcessGet(aArgs, aGetHandler);
|
||||
|
||||
VerifyOrExit(error != OT_ERROR_NONE);
|
||||
error = ProcessSet(aArgsLength, aArgs, aSetHandler);
|
||||
error = ProcessSet(aArgs, aSetHandler);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -418,121 +403,120 @@ private:
|
||||
#endif
|
||||
static otError ParseJoinerDiscerner(Arg &aArg, otJoinerDiscerner &aDiscerner);
|
||||
|
||||
otError ProcessUserCommands(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCcaThreshold(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBufferInfo(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChannel(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessUserCommands(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessCcaThreshold(Arg aArgs[]);
|
||||
otError ProcessBufferInfo(Arg aArgs[]);
|
||||
otError ProcessChannel(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
otError ProcessBorderAgent(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBorderAgent(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
otError ProcessBorderRouting(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBorderRouting(Arg aArgs[]);
|
||||
#endif
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
otError ProcessBackboneRouter(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBackboneRouter(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
otError ProcessBackboneRouterLocal(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBackboneRouterLocal(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
||||
otError ProcessBackboneRouterMgmtMlr(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBackboneRouterMgmtMlr(Arg aArgs[]);
|
||||
void PrintMulticastListenersTable(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
otError ProcessDomainName(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDomainName(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
otError ProcessDua(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDua(Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessChild(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChildIp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChildMax(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChild(Arg aArgs[]);
|
||||
otError ProcessChildIp(Arg aArgs[]);
|
||||
otError ProcessChildMax(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE
|
||||
otError ProcessChildSupervision(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChildSupervision(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessChildTimeout(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChildTimeout(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
|
||||
otError ProcessCoap(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCoap(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
|
||||
otError ProcessCoapSecure(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCoapSecure(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
|
||||
otError ProcessCoexMetrics(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCoexMetrics(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
otError ProcessCommissioner(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCommissioner(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessContextIdReuseDelay(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessContextIdReuseDelay(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessCounters(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCsl(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCounters(Arg aArgs[]);
|
||||
otError ProcessCsl(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessDelayTimerMin(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDelayTimerMin(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
otError ProcessDiag(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDiag(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessDiscover(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDns(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDiscover(Arg aArgs[]);
|
||||
otError ProcessDns(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
void OutputEidCacheEntry(const otCacheEntryInfo &aEntry);
|
||||
otError ProcessEidCache(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessEidCache(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessEui64(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessEui64(Arg aArgs[]);
|
||||
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
otError ProcessExit(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessExit(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessLog(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessExtAddress(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessExtPanId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessFactoryReset(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLog(Arg aArgs[]);
|
||||
otError ProcessExtAddress(Arg aArgs[]);
|
||||
otError ProcessExtPanId(Arg aArgs[]);
|
||||
otError ProcessFactoryReset(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessFake(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessFake(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessFem(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIfconfig(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIpAddr(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIpAddrAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIpAddrDel(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddr(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddrAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddrDel(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMulticastPromiscuous(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessFem(Arg aArgs[]);
|
||||
otError ProcessIfconfig(Arg aArgs[]);
|
||||
otError ProcessIpAddr(Arg aArgs[]);
|
||||
otError ProcessIpAddrAdd(Arg aArgs[]);
|
||||
otError ProcessIpAddrDel(Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddr(Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddrAdd(Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddrDel(Arg aArgs[]);
|
||||
otError ProcessMulticastPromiscuous(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_JOINER_ENABLE
|
||||
otError ProcessJoiner(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessJoiner(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessJoinerPort(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessJoinerPort(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessKeySequence(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLeaderData(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessKeySequence(Arg aArgs[]);
|
||||
otError ProcessLeaderData(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessPartitionId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLeaderWeight(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPartitionId(Arg aArgs[]);
|
||||
otError ProcessLeaderWeight(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessMlIid(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMlIid(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
|
||||
otError ProcessLinkMetrics(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLinkMetricsQuery(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLinkMetricsMgmt(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLinkMetricsProbe(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
otError ProcessLinkMetrics(Arg aArgs[]);
|
||||
otError ProcessLinkMetricsQuery(Arg aArgs[]);
|
||||
otError ProcessLinkMetricsMgmt(Arg aArgs[]);
|
||||
otError ProcessLinkMetricsProbe(Arg aArgs[]);
|
||||
otError ParseLinkMetricsFlags(otLinkMetrics &aLinkMetrics, const Arg &aFlags);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
|
||||
otError ProcessMlr(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMlr(Arg aArgs[]);
|
||||
|
||||
otError ProcessMlrReg(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMlrReg(Arg aArgs[]);
|
||||
|
||||
static void HandleMlrRegResult(void * aContext,
|
||||
otError aError,
|
||||
@@ -544,101 +528,101 @@ private:
|
||||
const otIp6Address *aFailedAddresses,
|
||||
uint8_t aFailedAddressNum);
|
||||
#endif
|
||||
otError ProcessMode(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMultiRadio(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMode(Arg aArgs[]);
|
||||
otError ProcessMultiRadio(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
void OutputMultiRadioInfo(const otMultiRadioNeighborInfo &aMultiRadioInfo);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessNeighbor(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNeighbor(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkData(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkData(Arg aArgs[]);
|
||||
otError ProcessNetworkDataPrefix(void);
|
||||
otError ProcessNetworkDataRoute(void);
|
||||
otError ProcessNetworkDataService(void);
|
||||
void OutputPrefix(const otMeshLocalPrefix &aPrefix);
|
||||
|
||||
otError ProcessNetstat(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetstat(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError ProcessService(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessService(Arg aArgs[]);
|
||||
otError ProcessServiceList(void);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
otError ProcessNetworkDiagnostic(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkDiagnostic(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessNetworkIdTimeout(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkIdTimeout(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkKey(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkName(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkKey(Arg aArgs[]);
|
||||
otError ProcessNetworkName(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
otError ProcessNetworkTime(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkTime(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPanId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessParent(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPanId(Arg aArgs[]);
|
||||
otError ProcessParent(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessParentPriority(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessParentPriority(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
otError ProcessPing(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPing(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPollPeriod(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPollPeriod(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError ProcessPrefix(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPrefixAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPrefixRemove(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPrefix(Arg aArgs[]);
|
||||
otError ProcessPrefixAdd(Arg aArgs[]);
|
||||
otError ProcessPrefixRemove(Arg aArgs[]);
|
||||
otError ProcessPrefixList(void);
|
||||
#endif
|
||||
otError ProcessPromiscuous(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPromiscuous(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessPreferRouterId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPskc(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPreferRouterId(Arg aArgs[]);
|
||||
otError ProcessPskc(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessRcp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRegion(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRcp(Arg aArgs[]);
|
||||
otError ProcessRegion(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessReleaseRouterId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessReleaseRouterId(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessReset(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessReset(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError ProcessRoute(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouteAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouteRemove(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRoute(Arg aArgs[]);
|
||||
otError ProcessRouteAdd(Arg aArgs[]);
|
||||
otError ProcessRouteRemove(Arg aArgs[]);
|
||||
otError ProcessRouteList(void);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessRouter(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouterDowngradeThreshold(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouterEligible(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouterSelectionJitter(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouterUpgradeThreshold(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouter(Arg aArgs[]);
|
||||
otError ProcessRouterDowngradeThreshold(Arg aArgs[]);
|
||||
otError ProcessRouterEligible(Arg aArgs[]);
|
||||
otError ProcessRouterSelectionJitter(Arg aArgs[]);
|
||||
otError ProcessRouterUpgradeThreshold(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessRloc16(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessScan(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSingleton(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRloc16(Arg aArgs[]);
|
||||
otError ProcessScan(Arg aArgs[]);
|
||||
otError ProcessSingleton(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
|
||||
otError ProcessSntp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSntp(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE || OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
otError ProcessSrp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSrp(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessState(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessThread(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDataset(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessTxPower(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessUdp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessUnsecurePort(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessVersion(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
otError ProcessThread(Arg aArgs[]);
|
||||
otError ProcessDataset(Arg aArgs[]);
|
||||
otError ProcessTxPower(Arg aArgs[]);
|
||||
otError ProcessUdp(Arg aArgs[]);
|
||||
otError ProcessUnsecurePort(Arg aArgs[]);
|
||||
otError ProcessVersion(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
otError ProcessMacFilter(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacFilter(Arg aArgs[]);
|
||||
void PrintMacFilter(void);
|
||||
otError ProcessMacFilterAddress(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacFilterRss(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacFilterAddress(Arg aArgs[]);
|
||||
otError ProcessMacFilterRss(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessMac(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacRetries(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMac(Arg aArgs[]);
|
||||
otError ProcessMacRetries(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessMacSend(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacSend(Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
@@ -669,7 +653,7 @@ private:
|
||||
void OutputDnsTxtData(const uint8_t *aTxtData, uint16_t aTxtDataLength);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
|
||||
otError GetDnsConfig(uint8_t aArgsLength, Arg aArgs[], otDnsQueryConfig *&aConfig, uint8_t aStartArgsIndex);
|
||||
otError GetDnsConfig(Arg aArgs[], otDnsQueryConfig *&aConfig);
|
||||
static void HandleDnsAddressResponse(otError aError, const otDnsAddressResponse *aResponse, void *aContext);
|
||||
void HandleDnsAddressResponse(otError aError, const otDnsAddressResponse *aResponse);
|
||||
#if OPENTHREAD_CONFIG_DNS_CLIENT_SERVICE_DISCOVERY_ENABLE
|
||||
|
||||
+33
-38
@@ -145,18 +145,16 @@ void Coap::PrintPayload(otMessage *aMessage) const
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError Coap::ProcessCancel(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessCancel(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return CancelResourceSubscription();
|
||||
}
|
||||
#endif
|
||||
|
||||
otError Coap::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -167,11 +165,11 @@ otError Coap::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Coap::ProcessResource(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessResource(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 0)
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
VerifyOrExit(aArgs[0].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
@@ -183,7 +181,7 @@ otError Coap::ProcessResource(uint8_t aArgsLength, Arg aArgs[])
|
||||
mResource.mReceiveHook = &Coap::BlockwiseReceiveHook;
|
||||
mResource.mTransmitHook = &Coap::BlockwiseTransmitHook;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
if (!aArgs[1].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(mBlockCount));
|
||||
}
|
||||
@@ -206,7 +204,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessSet(Arg aArgs[])
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otMessage * notificationMessage = nullptr;
|
||||
@@ -214,7 +212,7 @@ otError Coap::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
#endif
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 0)
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
VerifyOrExit(aArgs[0].GetLength() < sizeof(mResourceContent), error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(mResourceContent, aArgs[0].GetCString(), sizeof(mResourceContent));
|
||||
@@ -268,17 +266,15 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessStart(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return otCoapStart(mInterpreter.mInstance, OT_DEFAULT_COAP_PORT);
|
||||
}
|
||||
|
||||
otError Coap::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessStop(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
@@ -290,14 +286,12 @@ otError Coap::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
return otCoapStop(mInterpreter.mInstance);
|
||||
}
|
||||
|
||||
otError Coap::ProcessParameters(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessParameters(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool * defaultTxParameters;
|
||||
otCoapTxParameters *txParameters;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aArgs[0] == "request")
|
||||
{
|
||||
txParameters = &mRequestTxParameters;
|
||||
@@ -313,7 +307,7 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, Arg aArgs[])
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
if (aArgsLength > 1)
|
||||
if (!aArgs[1].IsEmpty())
|
||||
{
|
||||
if (aArgs[1] == "default")
|
||||
{
|
||||
@@ -321,8 +315,6 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(aArgsLength >= 5, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(txParameters->mAckTimeout));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint8(txParameters->mAckRandomFactorNumerator));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint8(txParameters->mAckRandomFactorDenominator));
|
||||
@@ -352,37 +344,37 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessGet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessGet(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_GET);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_GET);
|
||||
}
|
||||
|
||||
otError Coap::ProcessPost(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessPost(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_POST);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_POST);
|
||||
}
|
||||
|
||||
otError Coap::ProcessPut(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessPut(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_PUT);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_PUT);
|
||||
}
|
||||
|
||||
otError Coap::ProcessDelete(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessDelete(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_DELETE);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_DELETE);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError Coap::ProcessObserve(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::ProcessObserve(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_GET, /* aCoapObserve */ true);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_GET, /* aCoapObserve */ true);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError Coap::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapCode, bool aCoapObserve)
|
||||
otError Coap::ProcessRequest(Arg aArgs[], otCoapCode aCoapCode, bool aCoapObserve)
|
||||
#else
|
||||
otError Coap::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapCode)
|
||||
otError Coap::ProcessRequest(Arg aArgs[], otCoapCode aCoapCode)
|
||||
#endif
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -407,15 +399,14 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapC
|
||||
}
|
||||
#endif
|
||||
|
||||
VerifyOrExit(aArgsLength > 1, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(coapDestinationIp));
|
||||
|
||||
VerifyOrExit(!aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(coapUri, aArgs[1].GetCString(), sizeof(coapUri) - 1);
|
||||
|
||||
// CoAP-Type
|
||||
if (aArgsLength > 2)
|
||||
if (!aArgs[2].IsEmpty())
|
||||
{
|
||||
if (aArgs[2] == "con")
|
||||
{
|
||||
@@ -504,7 +495,7 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapC
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aArgsLength > 3)
|
||||
if (!aArgs[3].IsEmpty())
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
if (coapBlock)
|
||||
@@ -585,17 +576,21 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Coap::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
+16
-17
@@ -68,11 +68,10 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -84,7 +83,7 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Coap::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (Coap::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
@@ -102,27 +101,27 @@ private:
|
||||
|
||||
void PrintPayload(otMessage *aMessage) const;
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessCancel(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCancel(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessDelete(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessGet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDelete(Arg aArgs[]);
|
||||
otError ProcessGet(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessObserve(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessObserve(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessParameters(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPost(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPut(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessResource(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessParameters(Arg aArgs[]);
|
||||
otError ProcessPost(Arg aArgs[]);
|
||||
otError ProcessPut(Arg aArgs[]);
|
||||
otError ProcessResource(Arg aArgs[]);
|
||||
otError ProcessSet(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapCode, bool aCoapObserve = false);
|
||||
otError ProcessRequest(Arg aArgs[], otCoapCode aCoapCode, bool aCoapObserve = false);
|
||||
#else
|
||||
otError ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapCode);
|
||||
otError ProcessRequest(Arg aArgs[], otCoapCode aCoapCode);
|
||||
#endif
|
||||
|
||||
static void HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
+36
-38
@@ -91,9 +91,8 @@ void CoapSecure::PrintPayload(otMessage *aMessage) const
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -104,11 +103,11 @@ otError CoapSecure::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessResource(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessResource(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 0)
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
VerifyOrExit(aArgs[0].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
@@ -120,7 +119,7 @@ otError CoapSecure::ProcessResource(uint8_t aArgsLength, Arg aArgs[])
|
||||
mResource.mReceiveHook = &CoapSecure::BlockwiseReceiveHook;
|
||||
mResource.mTransmitHook = &CoapSecure::BlockwiseTransmitHook;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
if (!aArgs[1].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(mBlockCount));
|
||||
}
|
||||
@@ -142,11 +141,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessSet(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 0)
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
VerifyOrExit(aArgs[0].GetLength() < sizeof(mResourceContent), error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(mResourceContent, aArgs[0].GetCString(), sizeof(mResourceContent));
|
||||
@@ -161,12 +160,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessStart(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool verifyPeerCert = true;
|
||||
|
||||
if (aArgsLength > 0)
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
if (aArgs[0] == "false")
|
||||
{
|
||||
@@ -185,15 +184,14 @@ otError CoapSecure::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otCoapSecureSetDefaultHandler(mInterpreter.mInstance, &CoapSecure::DefaultHandler, this);
|
||||
#endif
|
||||
|
||||
SuccessOrExit(error = otCoapSecureStart(mInterpreter.mInstance, OT_DEFAULT_COAP_SECURE_PORT));
|
||||
error = otCoapSecureStart(mInterpreter.mInstance, OT_DEFAULT_COAP_SECURE_PORT);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessStop(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
@@ -215,27 +213,27 @@ otError CoapSecure::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessGet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessGet(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_GET);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_GET);
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessPost(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessPost(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_POST);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_POST);
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessPut(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessPut(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_PUT);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_PUT);
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessDelete(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessDelete(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgsLength, aArgs, OT_COAP_CODE_DELETE);
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_DELETE);
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapCode)
|
||||
otError CoapSecure::ProcessRequest(Arg aArgs[], otCoapCode aCoapCode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessage *message = nullptr;
|
||||
@@ -250,12 +248,12 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode
|
||||
BlockType coapBlockType = (aCoapCode == OT_COAP_CODE_GET) ? kBlockType2 : kBlockType1;
|
||||
#endif
|
||||
|
||||
if (aArgsLength > 0)
|
||||
if (!aArgs[0].IsEmpty())
|
||||
{
|
||||
strncpy(coapUri, aArgs[0].GetCString(), sizeof(coapUri) - 1);
|
||||
}
|
||||
|
||||
if (aArgsLength > 1)
|
||||
if (!aArgs[1].IsEmpty())
|
||||
{
|
||||
if (aArgs[1] == "con")
|
||||
{
|
||||
@@ -328,7 +326,7 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aArgsLength > 2)
|
||||
if (!aArgs[2].IsEmpty())
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
if (coapBlock)
|
||||
@@ -386,18 +384,16 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessConnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessConnect(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otSockAddr sockaddr;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(sockaddr.mAddress));
|
||||
sockaddr.mPort = OT_DEFAULT_COAP_SECURE_PORT;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
if (!aArgs[1].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(sockaddr.mPort));
|
||||
}
|
||||
@@ -408,9 +404,8 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessDisconnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessDisconnect(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otCoapSecureDisconnect(mInterpreter.mInstance);
|
||||
@@ -419,12 +414,12 @@ otError CoapSecure::ProcessDisconnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
|
||||
#ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
otError CoapSecure::ProcessPsk(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessPsk(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(aArgsLength > 1, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
length = aArgs[0].GetLength();
|
||||
VerifyOrExit(length <= sizeof(mPsk), error = OT_ERROR_INVALID_ARGS);
|
||||
@@ -445,9 +440,8 @@ exit:
|
||||
#endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
|
||||
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
otError CoapSecure::ProcessX509(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::ProcessX509(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otCoapSecureSetCertificate(mInterpreter.mInstance, reinterpret_cast<const uint8_t *>(OT_CLI_COAPS_X509_CERT),
|
||||
@@ -463,17 +457,21 @@ otError CoapSecure::ProcessX509(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
#endif
|
||||
|
||||
otError CoapSecure::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError CoapSecure::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
+16
-17
@@ -74,11 +74,10 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -92,7 +91,7 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (CoapSecure::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (CoapSecure::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
@@ -105,21 +104,21 @@ private:
|
||||
|
||||
void PrintPayload(otMessage *aMessage) const;
|
||||
|
||||
otError ProcessConnect(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDelete(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDisconnect(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessGet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPost(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPsk(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPut(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessResource(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessX509(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessConnect(Arg aArgs[]);
|
||||
otError ProcessDelete(Arg aArgs[]);
|
||||
otError ProcessDisconnect(Arg aArgs[]);
|
||||
otError ProcessGet(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessPost(Arg aArgs[]);
|
||||
otError ProcessPsk(Arg aArgs[]);
|
||||
otError ProcessPut(Arg aArgs[]);
|
||||
otError ProcessResource(Arg aArgs[]);
|
||||
otError ProcessSet(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
otError ProcessX509(Arg aArgs[]);
|
||||
|
||||
otError ProcessRequest(uint8_t aArgsLength, Arg aArgs[], otCoapCode aCoapCode);
|
||||
otError ProcessRequest(Arg aArgs[], otCoapCode aCoapCode);
|
||||
|
||||
void Stop(void);
|
||||
|
||||
|
||||
@@ -42,9 +42,8 @@ namespace Cli {
|
||||
|
||||
constexpr Commissioner::Command Commissioner::sCommands[];
|
||||
|
||||
otError Commissioner::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -55,7 +54,7 @@ otError Commissioner::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessAnnounce(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessAnnounce(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint32_t mask;
|
||||
@@ -63,20 +62,18 @@ otError Commissioner::ProcessAnnounce(uint8_t aArgsLength, Arg aArgs[])
|
||||
uint16_t period;
|
||||
otIp6Address address;
|
||||
|
||||
VerifyOrExit(aArgsLength > 3, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(mask));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint8(count));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint16(period));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsIp6Address(address));
|
||||
|
||||
SuccessOrExit(error = otCommissionerAnnounceBegin(mInterpreter.mInstance, mask, count, period, &address));
|
||||
error = otCommissionerAnnounceBegin(mInterpreter.mInstance, mask, count, period, &address);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessEnergy(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessEnergy(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint32_t mask;
|
||||
@@ -85,29 +82,27 @@ otError Commissioner::ProcessEnergy(uint8_t aArgsLength, Arg aArgs[])
|
||||
uint16_t scanDuration;
|
||||
otIp6Address address;
|
||||
|
||||
VerifyOrExit(aArgsLength > 4, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(mask));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint8(count));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint16(period));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint16(scanDuration));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsIp6Address(address));
|
||||
|
||||
SuccessOrExit(error = otCommissionerEnergyScan(mInterpreter.mInstance, mask, count, period, scanDuration, &address,
|
||||
&Commissioner::HandleEnergyReport, this));
|
||||
error = otCommissionerEnergyScan(mInterpreter.mInstance, mask, count, period, scanDuration, &address,
|
||||
&Commissioner::HandleEnergyReport, this);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessJoiner(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessJoiner(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otError error = OT_ERROR_NONE;
|
||||
otExtAddress addr;
|
||||
const otExtAddress *addrPtr = nullptr;
|
||||
otJoinerDiscerner discerner;
|
||||
|
||||
VerifyOrExit(aArgsLength > 1, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memset(&discerner, 0, sizeof(discerner));
|
||||
|
||||
@@ -115,91 +110,93 @@ otError Commissioner::ProcessJoiner(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
else if ((error = Interpreter::ParseJoinerDiscerner(aArgs[1], discerner)) == OT_ERROR_NOT_FOUND)
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = aArgs[1].ParseAsHexString(addr.m8));
|
||||
addrPtr = &addr;
|
||||
}
|
||||
else if (error != OT_ERROR_NONE)
|
||||
{
|
||||
ExitNow();
|
||||
error = Interpreter::ParseJoinerDiscerner(aArgs[1], discerner);
|
||||
|
||||
if (error == OT_ERROR_NOT_FOUND)
|
||||
{
|
||||
error = aArgs[1].ParseAsHexString(addr.m8);
|
||||
addrPtr = &addr;
|
||||
}
|
||||
|
||||
SuccessOrExit(error);
|
||||
}
|
||||
|
||||
if (aArgs[0] == "add")
|
||||
{
|
||||
VerifyOrExit(aArgsLength > 2, error = OT_ERROR_INVALID_ARGS);
|
||||
// Timeout parameter is optional - if not specified, use default value.
|
||||
uint32_t timeout = kDefaultJoinerTimeout;
|
||||
|
||||
if (aArgsLength > 3)
|
||||
VerifyOrExit(!aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (!aArgs[3].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint32(timeout));
|
||||
}
|
||||
|
||||
if (discerner.mLength)
|
||||
{
|
||||
SuccessOrExit(error = otCommissionerAddJoinerWithDiscerner(mInterpreter.mInstance, &discerner,
|
||||
aArgs[2].GetCString(), timeout));
|
||||
error = otCommissionerAddJoinerWithDiscerner(mInterpreter.mInstance, &discerner, aArgs[2].GetCString(),
|
||||
timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error =
|
||||
otCommissionerAddJoiner(mInterpreter.mInstance, addrPtr, aArgs[2].GetCString(), timeout));
|
||||
error = otCommissionerAddJoiner(mInterpreter.mInstance, addrPtr, aArgs[2].GetCString(), timeout);
|
||||
}
|
||||
}
|
||||
else if (aArgs[0] == "remove")
|
||||
{
|
||||
if (discerner.mLength)
|
||||
{
|
||||
SuccessOrExit(error = otCommissionerRemoveJoinerWithDiscerner(mInterpreter.mInstance, &discerner));
|
||||
error = otCommissionerRemoveJoinerWithDiscerner(mInterpreter.mInstance, &discerner);
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = otCommissionerRemoveJoiner(mInterpreter.mInstance, addrPtr));
|
||||
error = otCommissionerRemoveJoiner(mInterpreter.mInstance, addrPtr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessMgmtGet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessMgmtGet(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t tlvs[32];
|
||||
uint8_t length = 0;
|
||||
|
||||
for (uint8_t index = 0; index < aArgsLength; index++)
|
||||
for (; !aArgs->IsEmpty(); aArgs++)
|
||||
{
|
||||
VerifyOrExit(static_cast<size_t>(length) < sizeof(tlvs), error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (aArgs[index] == "locator")
|
||||
if (*aArgs == "locator")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_BORDER_AGENT_RLOC;
|
||||
}
|
||||
else if (aArgs[index] == "sessionid")
|
||||
else if (*aArgs == "sessionid")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_COMM_SESSION_ID;
|
||||
}
|
||||
else if (aArgs[index] == "steeringdata")
|
||||
else if (*aArgs == "steeringdata")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_STEERING_DATA;
|
||||
}
|
||||
else if (aArgs[index] == "joinerudpport")
|
||||
else if (*aArgs == "joinerudpport")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_JOINER_UDP_PORT;
|
||||
}
|
||||
else if (aArgs[index] == "-x")
|
||||
else if (*aArgs == "-x")
|
||||
{
|
||||
uint16_t readLength;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
aArgs++;
|
||||
readLength = static_cast<uint16_t>(sizeof(tlvs) - length);
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(readLength, tlvs + length));
|
||||
SuccessOrExit(error = aArgs->ParseAsHexString(readLength, tlvs + length));
|
||||
length += static_cast<uint8_t>(readLength);
|
||||
}
|
||||
else
|
||||
@@ -208,60 +205,60 @@ otError Commissioner::ProcessMgmtGet(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
}
|
||||
|
||||
SuccessOrExit(error = otCommissionerSendMgmtGet(mInterpreter.mInstance, tlvs, static_cast<uint8_t>(length)));
|
||||
error = otCommissionerSendMgmtGet(mInterpreter.mInstance, tlvs, static_cast<uint8_t>(length));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessMgmtSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessMgmtSet(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otCommissioningDataset dataset;
|
||||
uint8_t tlvs[32];
|
||||
uint8_t tlvsLength = 0;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memset(&dataset, 0, sizeof(dataset));
|
||||
|
||||
for (uint8_t index = 0; index < aArgsLength; index++)
|
||||
for (; !aArgs->IsEmpty(); aArgs++)
|
||||
{
|
||||
if (aArgs[index] == "locator")
|
||||
if (*aArgs == "locator")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
aArgs++;
|
||||
dataset.mIsLocatorSet = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mLocator));
|
||||
SuccessOrExit(error = aArgs->ParseAsUint16(dataset.mLocator));
|
||||
}
|
||||
else if (aArgs[index] == "sessionid")
|
||||
else if (*aArgs == "sessionid")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
aArgs++;
|
||||
dataset.mIsSessionIdSet = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mSessionId));
|
||||
SuccessOrExit(error = aArgs->ParseAsUint16(dataset.mSessionId));
|
||||
}
|
||||
else if (aArgs[index] == "steeringdata")
|
||||
else if (*aArgs == "steeringdata")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
aArgs++;
|
||||
dataset.mIsSteeringDataSet = true;
|
||||
length = sizeof(dataset.mSteeringData.m8);
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, dataset.mSteeringData.m8));
|
||||
SuccessOrExit(error = aArgs->ParseAsHexString(length, dataset.mSteeringData.m8));
|
||||
dataset.mSteeringData.mLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else if (aArgs[index] == "joinerudpport")
|
||||
else if (*aArgs == "joinerudpport")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
aArgs++;
|
||||
dataset.mIsJoinerUdpPortSet = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mJoinerUdpPort));
|
||||
SuccessOrExit(error = aArgs->ParseAsUint16(dataset.mJoinerUdpPort));
|
||||
}
|
||||
else if (aArgs[index] == "-x")
|
||||
else if (*aArgs == "-x")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
aArgs++;
|
||||
length = sizeof(tlvs);
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, tlvs));
|
||||
SuccessOrExit(error = aArgs->ParseAsHexString(length, tlvs));
|
||||
tlvsLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else
|
||||
@@ -270,41 +267,39 @@ otError Commissioner::ProcessMgmtSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
}
|
||||
|
||||
SuccessOrExit(error = otCommissionerSendMgmtSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength));
|
||||
error = otCommissionerSendMgmtSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessPanId(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessPanId(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint16_t panId;
|
||||
uint32_t mask;
|
||||
otIp6Address address;
|
||||
|
||||
VerifyOrExit(aArgsLength > 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint16(panId));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(mask));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsIp6Address(address));
|
||||
|
||||
SuccessOrExit(error = otCommissionerPanIdQuery(mInterpreter.mInstance, panId, mask, &address,
|
||||
&Commissioner::HandlePanIdConflict, this));
|
||||
error = otCommissionerPanIdQuery(mInterpreter.mInstance, panId, mask, &address, &Commissioner::HandlePanIdConflict,
|
||||
this);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessProvisioningUrl(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessProvisioningUrl(Arg aArgs[])
|
||||
{
|
||||
return otCommissionerSetProvisioningUrl(mInterpreter.mInstance,
|
||||
(aArgsLength > 0) ? aArgs[0].GetCString() : nullptr);
|
||||
// If aArgs[0] is empty, `GetCString() will return `nullptr`
|
||||
/// which will correctly clear the provisioning URL.
|
||||
return otCommissionerSetProvisioningUrl(mInterpreter.mInstance, aArgs[0].GetCString());
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessSessionId(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessSessionId(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
mInterpreter.OutputLine("%d", otCommissionerGetSessionId(mInterpreter.mInstance));
|
||||
@@ -312,9 +307,8 @@ otError Commissioner::ProcessSessionId(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessStart(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return otCommissionerStart(mInterpreter.mInstance, &Commissioner::HandleStateChanged,
|
||||
@@ -394,17 +388,15 @@ void Commissioner::HandleJoinerEvent(otCommissionerJoinerEvent aEvent,
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessStop(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return otCommissionerStop(mInterpreter.mInstance);
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessState(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::ProcessState(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
mInterpreter.OutputLine(StateToString(otCommissionerGetState(mInterpreter.mInstance)));
|
||||
@@ -412,17 +404,21 @@ otError Commissioner::ProcessState(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Commissioner::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -71,11 +71,10 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -86,21 +85,21 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Commissioner::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (Commissioner::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessAnnounce(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessEnergy(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessJoiner(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMgmtGet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMgmtSet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPanId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessProvisioningUrl(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSessionId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessState(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessAnnounce(Arg aArgs[]);
|
||||
otError ProcessEnergy(Arg aArgs[]);
|
||||
otError ProcessJoiner(Arg aArgs[]);
|
||||
otError ProcessMgmtGet(Arg aArgs[]);
|
||||
otError ProcessMgmtSet(Arg aArgs[]);
|
||||
otError ProcessPanId(Arg aArgs[]);
|
||||
otError ProcessProvisioningUrl(Arg aArgs[]);
|
||||
otError ProcessSessionId(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
|
||||
static void HandleStateChanged(otCommissionerState aState, void *aContext);
|
||||
void HandleStateChanged(otCommissionerState aState);
|
||||
|
||||
+148
-178
@@ -124,12 +124,12 @@ otError Dataset::Print(otOperationalDataset &aDataset)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
ExitNow(error = Print(sDataset));
|
||||
}
|
||||
@@ -137,15 +137,14 @@ otError Dataset::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -156,100 +155,81 @@ otError Dataset::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessInit(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessInit(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetGetActive(mInterpreter.mInstance, &sDataset));
|
||||
error = otDatasetGetActive(mInterpreter.mInstance, &sDataset);
|
||||
}
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetGetPending(mInterpreter.mInstance, &sDataset));
|
||||
error = otDatasetGetPending(mInterpreter.mInstance, &sDataset);
|
||||
}
|
||||
#if OPENTHREAD_FTD
|
||||
else if (aArgs[0] == "new")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetCreateNewNetwork(mInterpreter.mInstance, &sDataset));
|
||||
error = otDatasetCreateNewNetwork(mInterpreter.mInstance, &sDataset);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessActive(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessActive(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
otOperationalDataset dataset;
|
||||
|
||||
SuccessOrExit(error = otDatasetGetActive(mInterpreter.mInstance, &dataset));
|
||||
error = Print(dataset);
|
||||
}
|
||||
else if ((aArgsLength == 1) && (aArgs[0] == "-x"))
|
||||
else if (aArgs[0] == "-x")
|
||||
{
|
||||
otOperationalDatasetTlvs dataset;
|
||||
|
||||
VerifyOrExit(aArgs[0].GetLength() <= OT_OPERATIONAL_DATASET_MAX_LENGTH * 2, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = otDatasetGetActiveTlvs(mInterpreter.mInstance, &dataset));
|
||||
mInterpreter.OutputBytes(dataset.mTlvs, dataset.mLength);
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPending(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessPending(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
otOperationalDataset dataset;
|
||||
|
||||
SuccessOrExit(error = otDatasetGetPending(mInterpreter.mInstance, &dataset));
|
||||
error = Print(dataset);
|
||||
}
|
||||
else if ((aArgsLength == 1) && (aArgs[0] == "-x"))
|
||||
else if (aArgs[0] == "-x")
|
||||
{
|
||||
otOperationalDatasetTlvs dataset;
|
||||
|
||||
VerifyOrExit(aArgs[0].GetLength() <= OT_OPERATIONAL_DATASET_MAX_LENGTH * 2, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = otDatasetGetPendingTlvs(mInterpreter.mInstance, &dataset));
|
||||
mInterpreter.OutputBytes(dataset.mTlvs, dataset.mLength);
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessActiveTimestamp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessActiveTimestamp(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsActiveTimestampPresent)
|
||||
{
|
||||
@@ -266,11 +246,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessChannel(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessChannel(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsChannelPresent)
|
||||
{
|
||||
@@ -287,11 +267,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessChannelMask(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessChannelMask(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsChannelMaskPresent)
|
||||
{
|
||||
@@ -308,43 +288,35 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessClear(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessClear(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
memset(&sDataset, 0, sizeof(sDataset));
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessCommit(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessCommit(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSetActive(mInterpreter.mInstance, &sDataset));
|
||||
error = otDatasetSetActive(mInterpreter.mInstance, &sDataset);
|
||||
}
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSetPending(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
error = otDatasetSetPending(mInterpreter.mInstance, &sDataset);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessDelay(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessDelay(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsDelayPresent)
|
||||
{
|
||||
@@ -361,11 +333,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessExtPanId(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessExtPanId(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsExtendedPanIdPresent)
|
||||
{
|
||||
@@ -383,11 +355,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMeshLocalPrefix(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessMeshLocalPrefix(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsMeshLocalPrefixPresent)
|
||||
{
|
||||
@@ -410,11 +382,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessNetworkKey(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessNetworkKey(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsNetworkKeyPresent)
|
||||
{
|
||||
@@ -432,11 +404,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessNetworkName(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessNetworkName(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsNetworkNamePresent)
|
||||
{
|
||||
@@ -453,11 +425,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPanId(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessPanId(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsPanIdPresent)
|
||||
{
|
||||
@@ -474,11 +446,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPendingTimestamp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessPendingTimestamp(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsPendingTimestampPresent)
|
||||
{
|
||||
@@ -495,96 +467,94 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMgmtSetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessMgmtSetCommand(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDataset dataset;
|
||||
uint8_t tlvs[128];
|
||||
uint8_t tlvsLength = 0;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memset(&dataset, 0, sizeof(dataset));
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
for (Arg *arg = &aArgs[1]; !arg->IsEmpty(); arg++)
|
||||
{
|
||||
if (aArgs[index] == "activetimestamp")
|
||||
if (*arg == "activetimestamp")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint64(dataset.mActiveTimestamp));
|
||||
SuccessOrExit(error = arg->ParseAsUint64(dataset.mActiveTimestamp));
|
||||
}
|
||||
else if (aArgs[index] == "pendingtimestamp")
|
||||
else if (*arg == "pendingtimestamp")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsPendingTimestampPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint64(dataset.mPendingTimestamp));
|
||||
SuccessOrExit(error = arg->ParseAsUint64(dataset.mPendingTimestamp));
|
||||
}
|
||||
else if (aArgs[index] == "networkkey")
|
||||
else if (*arg == "networkkey")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsNetworkKeyPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(dataset.mNetworkKey.m8));
|
||||
SuccessOrExit(error = arg->ParseAsHexString(dataset.mNetworkKey.m8));
|
||||
}
|
||||
else if (aArgs[index] == "networkname")
|
||||
else if (*arg == "networkname")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsNetworkNamePresent = true;
|
||||
SuccessOrExit(error = otNetworkNameFromString(&dataset.mNetworkName, aArgs[index].GetCString()));
|
||||
VerifyOrExit(!arg->IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = otNetworkNameFromString(&dataset.mNetworkName, arg->GetCString()));
|
||||
}
|
||||
else if (aArgs[index] == "extpanid")
|
||||
else if (*arg == "extpanid")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsExtendedPanIdPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(dataset.mExtendedPanId.m8));
|
||||
SuccessOrExit(error = arg->ParseAsHexString(dataset.mExtendedPanId.m8));
|
||||
}
|
||||
else if (aArgs[index] == "localprefix")
|
||||
else if (*arg == "localprefix")
|
||||
{
|
||||
otIp6Address prefix;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsMeshLocalPrefixPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsIp6Address(prefix));
|
||||
SuccessOrExit(error = arg->ParseAsIp6Address(prefix));
|
||||
memcpy(dataset.mMeshLocalPrefix.m8, prefix.mFields.m8, sizeof(dataset.mMeshLocalPrefix.m8));
|
||||
}
|
||||
else if (aArgs[index] == "delaytimer")
|
||||
else if (*arg == "delaytimer")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsDelayPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint32(dataset.mDelay));
|
||||
SuccessOrExit(error = arg->ParseAsUint32(dataset.mDelay));
|
||||
}
|
||||
else if (aArgs[index] == "panid")
|
||||
else if (*arg == "panid")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsPanIdPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mPanId));
|
||||
SuccessOrExit(error = arg->ParseAsUint16(dataset.mPanId));
|
||||
}
|
||||
else if (aArgs[index] == "channel")
|
||||
else if (*arg == "channel")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsChannelPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mChannel));
|
||||
SuccessOrExit(error = arg->ParseAsUint16(dataset.mChannel));
|
||||
}
|
||||
else if (aArgs[index] == "channelmask")
|
||||
else if (*arg == "channelmask")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
dataset.mComponents.mIsChannelMaskPresent = true;
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint32(dataset.mChannelMask));
|
||||
SuccessOrExit(error = arg->ParseAsUint32(dataset.mChannelMask));
|
||||
}
|
||||
else if (aArgs[index] == "securitypolicy")
|
||||
else if (*arg == "securitypolicy")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = ParseSecurityPolicy(dataset.mSecurityPolicy, aArgsLength - index, &aArgs[index]));
|
||||
arg++;
|
||||
SuccessOrExit(error = ParseSecurityPolicy(dataset.mSecurityPolicy, arg));
|
||||
dataset.mComponents.mIsSecurityPolicyPresent = true;
|
||||
++index;
|
||||
}
|
||||
else if (aArgs[index] == "-x")
|
||||
else if (*arg == "-x")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
length = sizeof(tlvs);
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, tlvs));
|
||||
SuccessOrExit(error = arg->ParseAsHexString(length, tlvs));
|
||||
tlvsLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else
|
||||
@@ -595,22 +565,22 @@ otError Dataset::ProcessMgmtSetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtActiveSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength));
|
||||
error = otDatasetSendMgmtActiveSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength);
|
||||
}
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtPendingSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength));
|
||||
error = otDatasetSendMgmtPendingSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessMgmtGetCommand(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDatasetComponents datasetComponents;
|
||||
@@ -619,65 +589,63 @@ otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
bool destAddrSpecified = false;
|
||||
otIp6Address address;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memset(&datasetComponents, 0, sizeof(datasetComponents));
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
for (Arg *arg = &aArgs[1]; !arg->IsEmpty(); arg++)
|
||||
{
|
||||
if (aArgs[index] == "activetimestamp")
|
||||
if (*arg == "activetimestamp")
|
||||
{
|
||||
datasetComponents.mIsActiveTimestampPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "pendingtimestamp")
|
||||
else if (*arg == "pendingtimestamp")
|
||||
{
|
||||
datasetComponents.mIsPendingTimestampPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "networkkey")
|
||||
else if (*arg == "networkkey")
|
||||
{
|
||||
datasetComponents.mIsNetworkKeyPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "networkname")
|
||||
else if (*arg == "networkname")
|
||||
{
|
||||
datasetComponents.mIsNetworkNamePresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "extpanid")
|
||||
else if (*arg == "extpanid")
|
||||
{
|
||||
datasetComponents.mIsExtendedPanIdPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "localprefix")
|
||||
else if (*arg == "localprefix")
|
||||
{
|
||||
datasetComponents.mIsMeshLocalPrefixPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "delaytimer")
|
||||
else if (*arg == "delaytimer")
|
||||
{
|
||||
datasetComponents.mIsDelayPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "panid")
|
||||
else if (*arg == "panid")
|
||||
{
|
||||
datasetComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "channel")
|
||||
else if (*arg == "channel")
|
||||
{
|
||||
datasetComponents.mIsChannelPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "securitypolicy")
|
||||
else if (*arg == "securitypolicy")
|
||||
{
|
||||
datasetComponents.mIsSecurityPolicyPresent = true;
|
||||
}
|
||||
else if (aArgs[index] == "-x")
|
||||
else if (*arg == "-x")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
arg++;
|
||||
length = sizeof(tlvs);
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, tlvs));
|
||||
SuccessOrExit(error = arg->ParseAsHexString(length, tlvs));
|
||||
tlvsLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else if (aArgs[index] == "address")
|
||||
else if (*arg == "address")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = aArgs[index].ParseAsIp6Address(address));
|
||||
arg++;
|
||||
SuccessOrExit(error = arg->ParseAsIp6Address(address));
|
||||
destAddrSpecified = true;
|
||||
}
|
||||
else
|
||||
@@ -688,28 +656,28 @@ otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtActiveGet(mInterpreter.mInstance, &datasetComponents, tlvs, tlvsLength,
|
||||
destAddrSpecified ? &address : nullptr));
|
||||
error = otDatasetSendMgmtActiveGet(mInterpreter.mInstance, &datasetComponents, tlvs, tlvsLength,
|
||||
destAddrSpecified ? &address : nullptr);
|
||||
}
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtPendingGet(mInterpreter.mInstance, &datasetComponents, tlvs, tlvsLength,
|
||||
destAddrSpecified ? &address : nullptr));
|
||||
error = otDatasetSendMgmtPendingGet(mInterpreter.mInstance, &datasetComponents, tlvs, tlvsLength,
|
||||
destAddrSpecified ? &address : nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPskc(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessPskc(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsPskcPresent)
|
||||
{
|
||||
@@ -717,30 +685,31 @@ otError Dataset::ProcessPskc(uint8_t aArgsLength, Arg aArgs[])
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
}
|
||||
else if (aArgsLength == 1)
|
||||
{
|
||||
SuccessOrExit(error = aArgs[0].ParseAsHexString(sDataset.mPskc.m8));
|
||||
}
|
||||
#if OPENTHREAD_FTD
|
||||
else if (aArgsLength == 2 && (aArgs[0] == "-p"))
|
||||
{
|
||||
SuccessOrExit(
|
||||
error = otDatasetGeneratePskc(
|
||||
aArgs[1].GetCString(),
|
||||
(sDataset.mComponents.mIsNetworkNamePresent
|
||||
? &sDataset.mNetworkName
|
||||
: reinterpret_cast<const otNetworkName *>(otThreadGetNetworkName(mInterpreter.mInstance))),
|
||||
(sDataset.mComponents.mIsExtendedPanIdPresent ? &sDataset.mExtendedPanId
|
||||
: otThreadGetExtendedPanId(mInterpreter.mInstance)),
|
||||
&sDataset.mPskc));
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
#if OPENTHREAD_FTD
|
||||
if (aArgs[0] == "-p")
|
||||
{
|
||||
VerifyOrExit(!aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
sDataset.mComponents.mIsPskcPresent = true;
|
||||
SuccessOrExit(
|
||||
error = otDatasetGeneratePskc(
|
||||
aArgs[1].GetCString(),
|
||||
(sDataset.mComponents.mIsNetworkNamePresent
|
||||
? &sDataset.mNetworkName
|
||||
: reinterpret_cast<const otNetworkName *>(otThreadGetNetworkName(mInterpreter.mInstance))),
|
||||
(sDataset.mComponents.mIsExtendedPanIdPresent ? &sDataset.mExtendedPanId
|
||||
: otThreadGetExtendedPanId(mInterpreter.mInstance)),
|
||||
&sDataset.mPskc));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
SuccessOrExit(error = aArgs[0].ParseAsHexString(sDataset.mPskc.m8));
|
||||
}
|
||||
|
||||
sDataset.mComponents.mIsPskcPresent = true;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -796,17 +765,19 @@ void Dataset::OutputSecurityPolicy(const otSecurityPolicy &aSecurityPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
otError Dataset::ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, Arg *&aArgs)
|
||||
{
|
||||
otError error;
|
||||
otSecurityPolicy policy;
|
||||
|
||||
memset(&policy, 0, sizeof(policy));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint16(policy.mRotationTime));
|
||||
|
||||
VerifyOrExit(aArgsLength >= 2);
|
||||
SuccessOrExit(error = aArgs->ParseAsUint16(policy.mRotationTime));
|
||||
aArgs++;
|
||||
|
||||
for (const char *flag = aArgs[1].GetCString(); *flag != '\0'; flag++)
|
||||
VerifyOrExit(!aArgs->IsEmpty());
|
||||
|
||||
for (const char *flag = aArgs->GetCString(); *flag != '\0'; flag++)
|
||||
{
|
||||
switch (*flag)
|
||||
{
|
||||
@@ -851,6 +822,8 @@ otError Dataset::ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
aArgs++;
|
||||
|
||||
exit:
|
||||
if (error == OT_ERROR_NONE)
|
||||
{
|
||||
@@ -860,11 +833,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessSecurityPolicy(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
if (sDataset.mComponents.mIsSecurityPolicyPresent)
|
||||
{
|
||||
@@ -874,7 +847,9 @@ otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseSecurityPolicy(sDataset.mSecurityPolicy, aArgsLength, aArgs));
|
||||
Arg *arg = &aArgs[0];
|
||||
|
||||
SuccessOrExit(error = ParseSecurityPolicy(sDataset.mSecurityPolicy, arg));
|
||||
sDataset.mComponents.mIsSecurityPolicyPresent = true;
|
||||
}
|
||||
|
||||
@@ -882,13 +857,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessSet(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
MeshCoP::Dataset::Type datasetType;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
datasetType = MeshCoP::Dataset::Type::kActive;
|
||||
@@ -929,17 +902,15 @@ exit:
|
||||
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
otError Dataset::ProcessUpdater(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Dataset::ProcessUpdater(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
mInterpreter.OutputEnabledDisabledStatus(otDatasetUpdaterIsUpdateOngoing(mInterpreter.mInstance));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (aArgs[0] == "start")
|
||||
else if (aArgs[0] == "start")
|
||||
{
|
||||
error = otDatasetUpdaterRequestUpdate(mInterpreter.mInstance, &sDataset, &Dataset::HandleDatasetUpdater, this);
|
||||
}
|
||||
@@ -952,7 +923,6 @@ otError Dataset::ProcessUpdater(uint8_t aArgsLength, Arg aArgs[])
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
+25
-26
@@ -65,51 +65,50 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Dataset::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (Dataset::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError Print(otOperationalDataset &aDataset);
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessActive(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessActiveTimestamp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChannel(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChannelMask(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessClear(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCommit(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDelay(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessExtPanId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessInit(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMeshLocalPrefix(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkKey(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkName(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPanId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPending(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPendingTimestamp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMgmtSetCommand(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMgmtGetCommand(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPskc(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSecurityPolicy(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSet(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessActive(Arg aArgs[]);
|
||||
otError ProcessActiveTimestamp(Arg aArgs[]);
|
||||
otError ProcessChannel(Arg aArgs[]);
|
||||
otError ProcessChannelMask(Arg aArgs[]);
|
||||
otError ProcessClear(Arg aArgs[]);
|
||||
otError ProcessCommit(Arg aArgs[]);
|
||||
otError ProcessDelay(Arg aArgs[]);
|
||||
otError ProcessExtPanId(Arg aArgs[]);
|
||||
otError ProcessInit(Arg aArgs[]);
|
||||
otError ProcessMeshLocalPrefix(Arg aArgs[]);
|
||||
otError ProcessNetworkName(Arg aArgs[]);
|
||||
otError ProcessNetworkKey(Arg aArgs[]);
|
||||
otError ProcessPanId(Arg aArgs[]);
|
||||
otError ProcessPending(Arg aArgs[]);
|
||||
otError ProcessPendingTimestamp(Arg aArgs[]);
|
||||
otError ProcessMgmtSetCommand(Arg aArgs[]);
|
||||
otError ProcessMgmtGetCommand(Arg aArgs[]);
|
||||
otError ProcessPskc(Arg aArgs[]);
|
||||
otError ProcessSecurityPolicy(Arg aArgs[]);
|
||||
otError ProcessSet(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
otError ProcessUpdater(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessUpdater(Arg aArgs[]);
|
||||
static void HandleDatasetUpdater(otError aError, void *aContext);
|
||||
void HandleDatasetUpdater(otError aError);
|
||||
#endif
|
||||
|
||||
void OutputSecurityPolicy(const otSecurityPolicy &aSecurityPolicy);
|
||||
otError ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, Arg *&aArgs);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"active", &Dataset::ProcessActive},
|
||||
|
||||
+36
-39
@@ -44,11 +44,20 @@ namespace Cli {
|
||||
|
||||
constexpr Joiner::Command Joiner::sCommands[];
|
||||
|
||||
otError Joiner::ProcessDiscerner(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Joiner::ProcessDiscerner(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
if (aArgsLength == 1)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
const otJoinerDiscerner *discerner = otJoinerGetDiscerner(mInterpreter.mInstance);
|
||||
|
||||
VerifyOrExit(discerner != nullptr, error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
mInterpreter.OutputLine("0x%llx/%u", static_cast<unsigned long long>(discerner->mValue), discerner->mLength);
|
||||
error = OT_ERROR_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
otJoinerDiscerner discerner;
|
||||
|
||||
@@ -56,35 +65,21 @@ otError Joiner::ProcessDiscerner(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
if (aArgs[0] == "clear")
|
||||
{
|
||||
SuccessOrExit(error = otJoinerSetDiscerner(mInterpreter.mInstance, nullptr));
|
||||
error = otJoinerSetDiscerner(mInterpreter.mInstance, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(OT_ERROR_NONE == Interpreter::ParseJoinerDiscerner(aArgs[0], discerner),
|
||||
error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = otJoinerSetDiscerner(mInterpreter.mInstance, &discerner));
|
||||
SuccessOrExit(Interpreter::ParseJoinerDiscerner(aArgs[0], discerner));
|
||||
error = otJoinerSetDiscerner(mInterpreter.mInstance, &discerner);
|
||||
}
|
||||
}
|
||||
else if (aArgsLength == 0)
|
||||
{
|
||||
const otJoinerDiscerner *discerner = otJoinerGetDiscerner(mInterpreter.mInstance);
|
||||
|
||||
VerifyOrExit(discerner != nullptr, error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
mInterpreter.OutputLine("0x%llx/%u", static_cast<unsigned long long>(discerner->mValue), discerner->mLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Joiner::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -95,9 +90,8 @@ otError Joiner::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessId(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Joiner::ProcessId(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
mInterpreter.OutputExtAddress(*otJoinerGetId(mInterpreter.mInstance));
|
||||
@@ -106,28 +100,27 @@ otError Joiner::ProcessId(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Joiner::ProcessStart(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
const char *provisioningUrl = nullptr;
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
provisioningUrl = aArgs[1].GetCString();
|
||||
}
|
||||
|
||||
error = otJoinerStart(mInterpreter.mInstance, aArgs[0].GetCString(), provisioningUrl, PACKAGE_NAME,
|
||||
OPENTHREAD_CONFIG_PLATFORM_INFO, PACKAGE_VERSION, nullptr, &Joiner::HandleCallback, this);
|
||||
error = otJoinerStart(mInterpreter.mInstance,
|
||||
aArgs[0].GetCString(), // aPskd
|
||||
aArgs[1].GetCString(), // aProvisioningUrl (nullptr if aArgs[1] is empty)
|
||||
PACKAGE_NAME, // aVendorName
|
||||
OPENTHREAD_CONFIG_PLATFORM_INFO, // aVendorModel
|
||||
PACKAGE_VERSION, // aVendorSwVersion
|
||||
nullptr, // aVendorData
|
||||
&Joiner::HandleCallback, this);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Joiner::ProcessStop(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otJoinerStop(mInterpreter.mInstance);
|
||||
@@ -135,17 +128,21 @@ otError Joiner::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError Joiner::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -71,24 +71,23 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs A pointer to an array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Joiner::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (Joiner::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessDiscerner(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDiscerner(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessId(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
|
||||
static void HandleCallback(otError aError, void *aContext);
|
||||
void HandleCallback(otError aError);
|
||||
|
||||
@@ -203,9 +203,8 @@ void NetworkData::OutputService(const otServiceConfig &aConfig)
|
||||
mInterpreter.OutputLine(" %04x", aConfig.mServerConfig.mRloc16);
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError NetworkData::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -217,9 +216,8 @@ otError NetworkData::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError NetworkData::ProcessRegister(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError NetworkData::ProcessRegister(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -235,27 +233,24 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
otError NetworkData::ProcessSteeringData(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError NetworkData::ProcessSteeringData(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
otError error;
|
||||
otExtAddress addr;
|
||||
otJoinerDiscerner discerner;
|
||||
|
||||
VerifyOrExit((aArgsLength > 1) && (aArgs[0] == "check"));
|
||||
|
||||
discerner.mLength = 0;
|
||||
VerifyOrExit(aArgs[0] == "check", error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = Interpreter::ParseJoinerDiscerner(aArgs[1], discerner);
|
||||
|
||||
if (error == OT_ERROR_NOT_FOUND)
|
||||
{
|
||||
SuccessOrExit(error = aArgs[1].ParseAsHexString(addr.m8));
|
||||
}
|
||||
else if (error != OT_ERROR_NONE)
|
||||
{
|
||||
ExitNow();
|
||||
discerner.mLength = 0;
|
||||
error = aArgs[1].ParseAsHexString(addr.m8);
|
||||
}
|
||||
|
||||
SuccessOrExit(error);
|
||||
|
||||
if (discerner.mLength)
|
||||
{
|
||||
error = otNetDataSteeringDataCheckJoinerWithDiscerner(mInterpreter.mInstance, &discerner);
|
||||
@@ -323,11 +318,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessShow(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError NetworkData::ProcessShow(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
OutputPrefixes();
|
||||
OutputRoutes();
|
||||
@@ -338,25 +333,25 @@ otError NetworkData::ProcessShow(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
error = OutputBinary();
|
||||
}
|
||||
else
|
||||
{
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NetworkData::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError NetworkData::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -66,11 +66,10 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
/**
|
||||
* This method outputs the prefix config.
|
||||
@@ -100,15 +99,15 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (NetworkData::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (NetworkData::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError ProcessRegister(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRegister(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessShow(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSteeringData(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessShow(Arg aArgs[]);
|
||||
otError ProcessSteeringData(Arg aArgs[]);
|
||||
|
||||
otError OutputBinary(void);
|
||||
void OutputPrefixes(void);
|
||||
|
||||
+60
-59
@@ -66,17 +66,21 @@ SrpClient::SrpClient(Interpreter &aInterpreter)
|
||||
otSrpClientSetCallback(mInterpreter.mInstance, SrpClient::HandleCallback, this);
|
||||
}
|
||||
|
||||
otError SrpClient::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -84,19 +88,17 @@ exit:
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||
|
||||
otError SrpClient::ProcessAutoStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessAutoStart(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool enable;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
mInterpreter.OutputEnabledDisabledStatus(otSrpClientIsAutoStartModeEnabled(mInterpreter.mInstance));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = Interpreter::ParseEnableOrDisable(aArgs[0], enable));
|
||||
|
||||
if (enable)
|
||||
@@ -114,26 +116,24 @@ exit:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||
|
||||
otError SrpClient::ProcessCallback(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessCallback(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
mInterpreter.OutputEnabledDisabledStatus(mCallbackEnabled);
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
error = Interpreter::ParseEnableOrDisable(aArgs[0], mCallbackEnabled);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -144,11 +144,11 @@ otError SrpClient::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessHost(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
OutputHostInfo(0, *otSrpClientGetHostInfo(mInterpreter.mInstance));
|
||||
ExitNow();
|
||||
@@ -156,7 +156,7 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
if (aArgs[0] == "name")
|
||||
{
|
||||
if (aArgsLength == 1)
|
||||
if (aArgs[1].IsEmpty())
|
||||
{
|
||||
const char *name = otSrpClientGetHostInfo(mInterpreter.mInstance)->mName;
|
||||
mInterpreter.OutputLine("%s", (name != nullptr) ? name : "(null)");
|
||||
@@ -167,7 +167,7 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
uint16_t size;
|
||||
char * hostName;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
hostName = otSrpClientBuffersGetHostNameString(mInterpreter.mInstance, &size);
|
||||
|
||||
len = aArgs[1].GetLength();
|
||||
@@ -187,13 +187,13 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
else if (aArgs[0] == "state")
|
||||
{
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
mInterpreter.OutputLine("%s",
|
||||
otSrpClientItemStateToString(otSrpClientGetHostInfo(mInterpreter.mInstance)->mState));
|
||||
}
|
||||
else if (aArgs[0] == "address")
|
||||
{
|
||||
if (aArgsLength == 1)
|
||||
if (aArgs[1].IsEmpty())
|
||||
{
|
||||
const otSrpClientHostInfo *hostInfo = otSrpClientGetHostInfo(mInterpreter.mInstance);
|
||||
|
||||
@@ -205,7 +205,7 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t numAddresses = aArgsLength - 1;
|
||||
uint8_t numAddresses = 0;
|
||||
otIp6Address addresses[kMaxHostAddresses];
|
||||
uint8_t arrayLength;
|
||||
otIp6Address *hostAddressArray;
|
||||
@@ -218,11 +218,16 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
// a previous list before we know it is safe to set/change
|
||||
// the address list.
|
||||
|
||||
VerifyOrExit(numAddresses <= arrayLength, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
if (arrayLength > kMaxHostAddresses)
|
||||
{
|
||||
SuccessOrExit(error = aArgs[index].ParseAsIp6Address(addresses[index - 1]));
|
||||
arrayLength = kMaxHostAddresses;
|
||||
}
|
||||
|
||||
for (Arg *arg = &aArgs[1]; !arg->IsEmpty(); arg++)
|
||||
{
|
||||
VerifyOrExit(numAddresses < arrayLength, error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = arg->ParseAsIp6Address(addresses[numAddresses]));
|
||||
numAddresses++;
|
||||
}
|
||||
|
||||
SuccessOrExit(error = otSrpClientSetHostAddresses(mInterpreter.mInstance, addresses, numAddresses));
|
||||
@@ -235,17 +240,17 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
bool removeKeyLease = false;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
if (!aArgs[1].IsEmpty())
|
||||
{
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = aArgs[1].ParseAsBool(removeKeyLease));
|
||||
VerifyOrExit(aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
error = otSrpClientRemoveHostAndServices(mInterpreter.mInstance, removeKeyLease);
|
||||
}
|
||||
else if (aArgs[0] == "clear")
|
||||
{
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
otSrpClientClearHostAndServices(mInterpreter.mInstance);
|
||||
otSrpClientBuffersFreeAllServices(mInterpreter.mInstance);
|
||||
}
|
||||
@@ -258,23 +263,22 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessLeaseInterval(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessLeaseInterval(Arg aArgs[])
|
||||
{
|
||||
return mInterpreter.ProcessGetSet(aArgsLength, aArgs, otSrpClientGetLeaseInterval, otSrpClientSetLeaseInterval);
|
||||
return mInterpreter.ProcessGetSet(aArgs, otSrpClientGetLeaseInterval, otSrpClientSetLeaseInterval);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessKeyLeaseInterval(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessKeyLeaseInterval(Arg aArgs[])
|
||||
{
|
||||
return mInterpreter.ProcessGetSet(aArgsLength, aArgs, otSrpClientGetKeyLeaseInterval,
|
||||
otSrpClientSetKeyLeaseInterval);
|
||||
return mInterpreter.ProcessGetSet(aArgs, otSrpClientGetKeyLeaseInterval, otSrpClientSetKeyLeaseInterval);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessServer(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessServer(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otSockAddr *serverSockAddr = otSrpClientGetServerAddress(mInterpreter.mInstance);
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
char string[OT_IP6_SOCK_ADDR_STRING_SIZE];
|
||||
|
||||
@@ -283,7 +287,7 @@ otError SrpClient::ProcessServer(uint8_t aArgsLength, Arg aArgs[])
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aArgs[0] == "address")
|
||||
{
|
||||
@@ -303,12 +307,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessService(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool isRemove;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
OutputServiceList(0, otSrpClientGetServices(mInterpreter.mInstance));
|
||||
ExitNow();
|
||||
@@ -316,7 +320,7 @@ otError SrpClient::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
if (aArgs[0] == "add")
|
||||
{
|
||||
error = ProcessServiceAdd(aArgsLength, aArgs);
|
||||
error = ProcessServiceAdd(aArgs);
|
||||
}
|
||||
else if ((isRemove = (aArgs[0] == "remove")) || (aArgs[0] == "clear"))
|
||||
{
|
||||
@@ -324,7 +328,7 @@ otError SrpClient::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
const otSrpClientService *service;
|
||||
|
||||
VerifyOrExit(aArgsLength == 3, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(!aArgs[2].IsEmpty() && aArgs[3].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
for (service = otSrpClientGetServices(mInterpreter.mInstance); service != nullptr; service = service->mNext)
|
||||
{
|
||||
@@ -356,14 +360,14 @@ otError SrpClient::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
|
||||
bool enable;
|
||||
|
||||
if (aArgsLength == 1)
|
||||
if (aArgs[1].IsEmpty())
|
||||
{
|
||||
mInterpreter.OutputEnabledDisabledStatus(otSrpClientIsServiceKeyRecordEnabled(mInterpreter.mInstance));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = Interpreter::ParseEnableOrDisable(aArgs[1], enable));
|
||||
VerifyOrExit(aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
otSrpClientSetServiceKeyRecordEnabled(mInterpreter.mInstance, enable);
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
@@ -376,7 +380,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessServiceAdd(Arg aArgs[])
|
||||
{
|
||||
// `add` <instance-name> <service-name> <port> [priority] [weight] [txt]
|
||||
|
||||
@@ -385,31 +389,32 @@ otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, Arg aArgs[])
|
||||
char * string;
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(4 <= aArgsLength && aArgsLength <= 7, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
entry = otSrpClientBuffersAllocateService(mInterpreter.mInstance);
|
||||
|
||||
VerifyOrExit(entry != nullptr, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint16(entry->mService.mPort));
|
||||
|
||||
// Successfully parsing aArgs[3] indicates that aArgs[1] and
|
||||
// aArgs[2] are also non-empty.
|
||||
|
||||
string = otSrpClientBuffersGetServiceEntryInstanceNameString(entry, &size);
|
||||
SuccessOrExit(error = CopyString(string, size, aArgs[1].GetCString()));
|
||||
|
||||
string = otSrpClientBuffersGetServiceEntryServiceNameString(entry, &size);
|
||||
SuccessOrExit(error = CopyString(string, size, aArgs[2].GetCString()));
|
||||
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint16(entry->mService.mPort));
|
||||
|
||||
if (aArgsLength >= 5)
|
||||
if (!aArgs[4].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint16(entry->mService.mPriority));
|
||||
}
|
||||
|
||||
if (aArgsLength >= 6)
|
||||
if (!aArgs[5].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[5].ParseAsUint16(entry->mService.mWeight));
|
||||
}
|
||||
|
||||
if (aArgsLength >= 7)
|
||||
if (!aArgs[6].IsEmpty())
|
||||
{
|
||||
uint8_t *txtBuffer;
|
||||
|
||||
@@ -417,6 +422,7 @@ otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, Arg aArgs[])
|
||||
entry->mTxtEntry.mValueLength = size;
|
||||
|
||||
SuccessOrExit(error = aArgs[6].ParseAsHexString(entry->mTxtEntry.mValueLength, txtBuffer));
|
||||
VerifyOrExit(aArgs[7].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -480,15 +486,14 @@ void SrpClient::OutputService(uint8_t aIndentSize, const otSrpClientService &aSe
|
||||
aService.mPort, aService.mPriority, aService.mWeight);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessStart(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otSockAddr serverSockAddr;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(serverSockAddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(serverSockAddr.mPort));
|
||||
VerifyOrExit(aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = otSrpClientStart(mInterpreter.mInstance, &serverSockAddr);
|
||||
|
||||
@@ -496,13 +501,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessState(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessState(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
mInterpreter.OutputEnabledDisabledStatus(otSrpClientIsRunning(mInterpreter.mInstance));
|
||||
|
||||
@@ -510,13 +513,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpClient::ProcessStop(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
otSrpClientStop(mInterpreter.mInstance);
|
||||
|
||||
exit:
|
||||
|
||||
+15
-16
@@ -70,11 +70,10 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs A pointer to an array of command line arguments.
|
||||
* @param[in] aArgs A pointer an array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum : uint8_t
|
||||
@@ -86,21 +85,21 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (SrpClient::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (SrpClient::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessAutoStart(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCallback(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHost(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLeaseInterval(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessKeyLeaseInterval(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessServer(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessService(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessServiceAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessState(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessAutoStart(Arg aArgs[]);
|
||||
otError ProcessCallback(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessHost(Arg aArgs[]);
|
||||
otError ProcessLeaseInterval(Arg aArgs[]);
|
||||
otError ProcessKeyLeaseInterval(Arg aArgs[]);
|
||||
otError ProcessServer(Arg aArgs[]);
|
||||
otError ProcessService(Arg aArgs[]);
|
||||
otError ProcessServiceAdd(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
|
||||
void OutputHostInfo(uint8_t aIndentSize, const otSrpClientHostInfo &aHostInfo);
|
||||
void OutputServiceList(uint8_t aIndentSize, const otSrpClientService *aServices);
|
||||
|
||||
+29
-35
@@ -45,42 +45,44 @@ namespace Cli {
|
||||
|
||||
constexpr SrpServer::Command SrpServer::sCommands[];
|
||||
|
||||
otError SrpServer::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessDomain(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessDomain(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 0)
|
||||
{
|
||||
SuccessOrExit(error = otSrpServerSetDomain(mInterpreter.mInstance, aArgs[0].GetCString()));
|
||||
}
|
||||
else
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
mInterpreter.OutputLine("%s", otSrpServerGetDomain(mInterpreter.mInstance));
|
||||
}
|
||||
else
|
||||
{
|
||||
error = otSrpServerSetDomain(mInterpreter.mInstance, aArgs[0].GetCString());
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessEnable(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessEnable(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otSrpServerSetEnabled(mInterpreter.mInstance, /* aEnabled */ true);
|
||||
@@ -88,9 +90,8 @@ otError SrpServer::ProcessEnable(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessDisable(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessDisable(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otSrpServerSetEnabled(mInterpreter.mInstance, /* aEnabled */ false);
|
||||
@@ -98,20 +99,12 @@ otError SrpServer::ProcessDisable(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessLease(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessLease(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otSrpServerLeaseConfig leaseConfig;
|
||||
|
||||
if (aArgsLength == 4)
|
||||
{
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(leaseConfig.mMinLease));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(leaseConfig.mMaxLease));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(leaseConfig.mMinKeyLease));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint32(leaseConfig.mMaxKeyLease));
|
||||
error = otSrpServerSetLeaseConfig(mInterpreter.mInstance, &leaseConfig);
|
||||
}
|
||||
else if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
otSrpServerGetLeaseConfig(mInterpreter.mInstance, &leaseConfig);
|
||||
mInterpreter.OutputLine("min lease: %u", leaseConfig.mMinLease);
|
||||
@@ -121,21 +114,25 @@ otError SrpServer::ProcessLease(uint8_t aArgsLength, Arg aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(leaseConfig.mMinLease));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(leaseConfig.mMaxLease));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(leaseConfig.mMinKeyLease));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint32(leaseConfig.mMaxKeyLease));
|
||||
VerifyOrExit(aArgs[4].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = otSrpServerSetLeaseConfig(mInterpreter.mInstance, &leaseConfig);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessHost(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otSrpServerHost *host;
|
||||
|
||||
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
host = nullptr;
|
||||
while ((host = otSrpServerGetNextHost(mInterpreter.mInstance, host)) != nullptr)
|
||||
@@ -192,14 +189,12 @@ void SrpServer::OutputHostAddresses(const otSrpServerHost *aHost)
|
||||
mInterpreter.OutputFormat("]");
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessService(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otSrpServerHost *host;
|
||||
|
||||
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
host = nullptr;
|
||||
while ((host = otSrpServerGetNextHost(mInterpreter.mInstance, host)) != nullptr)
|
||||
@@ -240,9 +235,8 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError SrpServer::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
|
||||
@@ -71,29 +71,28 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs A pointer to an array of command line arguments.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully executed the CLI command.
|
||||
* @retval ... Failed to execute the CLI command.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (SrpServer::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (SrpServer::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessDomain(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessEnable(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDisable(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLease(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHost(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessService(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDomain(Arg aArgs[]);
|
||||
otError ProcessEnable(Arg aArgs[]);
|
||||
otError ProcessDisable(Arg aArgs[]);
|
||||
otError ProcessLease(Arg aArgs[]);
|
||||
otError ProcessHost(Arg aArgs[]);
|
||||
otError ProcessService(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
|
||||
void OutputHostAddresses(const otSrpServerHost *aHost);
|
||||
|
||||
|
||||
+30
-36
@@ -51,9 +51,8 @@ UdpExample::UdpExample(Interpreter &aInterpreter)
|
||||
memset(&mSocket, 0, sizeof(mSocket));
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
@@ -64,15 +63,14 @@ otError UdpExample::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessBind(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessBind(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otSockAddr sockaddr;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(sockaddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(sockaddr.mPort));
|
||||
VerifyOrExit(aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = otUdpBind(mInterpreter.mInstance, &mSocket, &sockaddr);
|
||||
|
||||
@@ -80,15 +78,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessConnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessConnect(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otSockAddr sockaddr;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(sockaddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(sockaddr.mPort));
|
||||
VerifyOrExit(aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = otUdpConnect(mInterpreter.mInstance, &mSocket, &sockaddr);
|
||||
|
||||
@@ -96,17 +93,15 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessClose(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessClose(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return otUdpClose(mInterpreter.mInstance, &mSocket);
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessOpen(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessOpen(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error;
|
||||
@@ -118,12 +113,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessSend(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessSend(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessage * message = nullptr;
|
||||
otMessageInfo messageInfo;
|
||||
uint8_t argIndex = 0;
|
||||
otMessageSettings messageSettings = {mLinkSecurityEnabled, OT_MESSAGE_PRIORITY_NORMAL};
|
||||
|
||||
memset(&messageInfo, 0, sizeof(messageInfo));
|
||||
@@ -135,47 +129,43 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, Arg aArgs[])
|
||||
// send <ip> <port> <text>
|
||||
// send <ip> <port> <type> <value>
|
||||
|
||||
VerifyOrExit(aArgsLength >= 1 && aArgsLength <= 4, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aArgsLength > 2)
|
||||
if (!aArgs[2].IsEmpty())
|
||||
{
|
||||
SuccessOrExit(error = aArgs[argIndex++].ParseAsIp6Address(messageInfo.mPeerAddr));
|
||||
SuccessOrExit(error = aArgs[argIndex++].ParseAsUint16(messageInfo.mPeerPort));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(messageInfo.mPeerAddr));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(messageInfo.mPeerPort));
|
||||
aArgs += 2;
|
||||
}
|
||||
|
||||
message = otUdpNewMessage(mInterpreter.mInstance, &messageSettings);
|
||||
VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (aArgs[argIndex] == "-s")
|
||||
if (aArgs[0] == "-s")
|
||||
{
|
||||
// Auto-generated payload with a given length
|
||||
|
||||
uint16_t payloadLength;
|
||||
|
||||
argIndex++;
|
||||
VerifyOrExit(argIndex < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = aArgs[argIndex].ParseAsUint16(payloadLength));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(payloadLength));
|
||||
SuccessOrExit(error = PrepareAutoGeneratedPayload(*message, payloadLength));
|
||||
}
|
||||
else if (aArgs[argIndex] == "-x")
|
||||
else if (aArgs[0] == "-x")
|
||||
{
|
||||
// Binary hex data payload
|
||||
|
||||
argIndex++;
|
||||
VerifyOrExit(argIndex < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = PrepareHexStringPaylod(*message, aArgs[argIndex].GetCString()));
|
||||
VerifyOrExit(!aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = PrepareHexStringPaylod(*message, aArgs[1].GetCString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Text payload (same as without specifying the type)
|
||||
|
||||
if (aArgs[argIndex] == "-t")
|
||||
if (aArgs[0] == "-t")
|
||||
{
|
||||
argIndex++;
|
||||
aArgs++;
|
||||
}
|
||||
|
||||
VerifyOrExit(argIndex < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[argIndex].GetCString(), aArgs[argIndex].GetLength()));
|
||||
VerifyOrExit(!aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[0].GetCString(), aArgs[0].GetLength()));
|
||||
}
|
||||
|
||||
SuccessOrExit(error = otUdpSend(mInterpreter.mInstance, &mSocket, message, &messageInfo));
|
||||
@@ -191,11 +181,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::ProcessLinkSecurity(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
mInterpreter.OutputEnabledDisabledStatus(mLinkSecurityEnabled);
|
||||
}
|
||||
@@ -264,17 +254,21 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
otError UdpExample::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
+9
-10
@@ -66,26 +66,25 @@ public:
|
||||
/**
|
||||
* This method interprets a list of CLI arguments.
|
||||
*
|
||||
* @param[in] aArgsLength The number of elements in @p aArgs.
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError Process(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (UdpExample::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError (UdpExample::*mHandler)(Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessBind(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessClose(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessConnect(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessOpen(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSend(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLinkSecurity(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessBind(Arg aArgs[]);
|
||||
otError ProcessClose(Arg aArgs[]);
|
||||
otError ProcessConnect(Arg aArgs[]);
|
||||
otError ProcessOpen(Arg aArgs[]);
|
||||
otError ProcessSend(Arg aArgs[]);
|
||||
otError ProcessLinkSecurity(Arg aArgs[]);
|
||||
|
||||
static otError PrepareAutoGeneratedPayload(otMessage &aMessage, uint16_t aPayloadLength);
|
||||
static otError PrepareHexStringPaylod(otMessage &aMessage, const char *aHexString);
|
||||
|
||||
@@ -520,10 +520,11 @@ Error Diags::ParseLong(char *aString, long &aLong)
|
||||
Error Diags::ParseCmd(char *aString, uint8_t &aArgsLength, char *aArgs[])
|
||||
{
|
||||
Error error;
|
||||
Utils::CmdLineParser::Arg args[kMaxArgs];
|
||||
Utils::CmdLineParser::Arg args[kMaxArgs + 1];
|
||||
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseCmd(aString, aArgsLength, args, aArgsLength));
|
||||
Utils::CmdLineParser::Arg::CopyArgsToStringArray(args, aArgsLength, aArgs);
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseCmd(aString, args));
|
||||
aArgsLength = Utils::CmdLineParser::Arg::GetArgsLength(args);
|
||||
Utils::CmdLineParser::Arg::CopyArgsToStringArray(args, aArgs);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -544,8 +545,7 @@ void Diags::ProcessLine(const char *aString, char *aOutput, size_t aOutputMaxLen
|
||||
VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = kErrorNoBufs);
|
||||
|
||||
strcpy(buffer, aString);
|
||||
argCount = kMaxArgs;
|
||||
error = ParseCmd(buffer, argCount, args);
|
||||
error = ParseCmd(buffer, argCount, args);
|
||||
|
||||
exit:
|
||||
|
||||
|
||||
@@ -85,12 +85,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error ParseCmd(char *aCommandString, uint8_t &aArgsLength, Arg *aArgs, uint8_t aArgsLengthMax)
|
||||
Error ParseCmd(char *aCommandString, Arg aArgs[], uint8_t aArgsMaxLength)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
char *cmd;
|
||||
|
||||
aArgsLength = 0;
|
||||
Error error = kErrorNone;
|
||||
uint8_t index = 0;
|
||||
char * cmd;
|
||||
|
||||
for (cmd = aCommandString; *cmd; cmd++)
|
||||
{
|
||||
@@ -104,15 +103,23 @@ Error ParseCmd(char *aCommandString, uint8_t &aArgsLength, Arg *aArgs, uint8_t a
|
||||
*cmd = '\0';
|
||||
}
|
||||
|
||||
if ((*cmd != '\0') && ((aArgsLength == 0) || (*(cmd - 1) == '\0')))
|
||||
if ((*cmd != '\0') && ((index == 0) || (*(cmd - 1) == '\0')))
|
||||
{
|
||||
VerifyOrExit(aArgsLength < aArgsLengthMax, error = kErrorInvalidArgs);
|
||||
if (index == aArgsMaxLength - 1)
|
||||
{
|
||||
error = kErrorInvalidArgs;
|
||||
break;
|
||||
}
|
||||
|
||||
aArgs[aArgsLength++].SetCString(cmd);
|
||||
aArgs[index++].SetCString(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
while (index < aArgsMaxLength)
|
||||
{
|
||||
aArgs[index++].Clear();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -158,6 +165,8 @@ Error ParseAsUint64(const char *aString, uint64_t &aUint64)
|
||||
kMaxDecBeforeOverlow = (0xffffffffffffffffULL / 10),
|
||||
};
|
||||
|
||||
VerifyOrExit(aString != nullptr, error = kErrorInvalidArgs);
|
||||
|
||||
if (cur[0] == '0' && (cur[1] == 'x' || cur[1] == 'X'))
|
||||
{
|
||||
cur += 2;
|
||||
@@ -215,6 +224,8 @@ Error ParseAsInt32(const char *aString, int32_t &aInt32)
|
||||
uint64_t value;
|
||||
bool isNegavtive = false;
|
||||
|
||||
VerifyOrExit(aString != nullptr, error = kErrorInvalidArgs);
|
||||
|
||||
if (*aString == '-')
|
||||
{
|
||||
aString++;
|
||||
@@ -248,6 +259,11 @@ exit:
|
||||
}
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
|
||||
Error ParseAsIp6Address(const char *aString, otIp6Address &aAddress)
|
||||
{
|
||||
return (aString != nullptr) ? otIp6AddressFromString(aString, &aAddress) : kErrorInvalidArgs;
|
||||
}
|
||||
|
||||
Error ParseAsIp6Prefix(const char *aString, otIp6Prefix &aPrefix)
|
||||
{
|
||||
enum : uint8_t
|
||||
@@ -259,6 +275,8 @@ Error ParseAsIp6Prefix(const char *aString, otIp6Prefix &aPrefix)
|
||||
char string[kMaxIp6AddressStringSize];
|
||||
const char *prefixLengthStr;
|
||||
|
||||
VerifyOrExit(aString != nullptr);
|
||||
|
||||
prefixLengthStr = StringFind(aString, '/');
|
||||
VerifyOrExit(prefixLengthStr != nullptr);
|
||||
|
||||
@@ -359,14 +377,39 @@ Error ParseAsHexStringSegment(const char *&aString, uint16_t &aSize, uint8_t *aB
|
||||
return ParseHexString(aString, aSize, aBuffer, kModeAllowPartial);
|
||||
}
|
||||
|
||||
void Arg::CopyArgsToStringArray(Arg aArgs[], uint8_t aArgsLength, char *aStrings[])
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// Arg class
|
||||
|
||||
uint16_t Arg::GetLength(void) const
|
||||
{
|
||||
for (uint8_t i = 0; i < aArgsLength; i++)
|
||||
return IsEmpty() ? 0 : static_cast<uint16_t>(strlen(mString));
|
||||
}
|
||||
|
||||
bool Arg::operator==(const char *aString) const
|
||||
{
|
||||
return !IsEmpty() && (strcmp(mString, aString) == 0);
|
||||
}
|
||||
|
||||
void Arg::CopyArgsToStringArray(Arg aArgs[], char *aStrings[])
|
||||
{
|
||||
for (uint8_t i = 0; !aArgs[i].IsEmpty(); i++)
|
||||
{
|
||||
aStrings[i] = aArgs[i].GetCString();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Arg::GetArgsLength(Arg aArgs[])
|
||||
{
|
||||
uint8_t length = 0;
|
||||
|
||||
while (!aArgs[length].IsEmpty())
|
||||
{
|
||||
length++;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
} // namespace CmdLineParser
|
||||
} // namespace Utils
|
||||
} // namespace ot
|
||||
|
||||
@@ -180,10 +180,7 @@ otError ParseAsBool(const char *aString, bool &aBool);
|
||||
* @retval kErrorInvalidArgs The string does not contain valid IPv6 address.
|
||||
*
|
||||
*/
|
||||
inline otError ParseAsIp6Address(const char *aString, otIp6Address &aAddress)
|
||||
{
|
||||
return otIp6AddressFromString(aString, &aAddress);
|
||||
}
|
||||
otError ParseAsIp6Address(const char *aString, otIp6Address &aAddress);
|
||||
|
||||
/**
|
||||
* This function parses a string as an IPv6 prefix.
|
||||
@@ -295,17 +292,32 @@ class Arg
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns the length (number of characters) in the argument C string.
|
||||
*
|
||||
* @returns The argument string length.
|
||||
* This method clears the argument.
|
||||
*
|
||||
*/
|
||||
uint16_t GetLength(void) const { return static_cast<uint16_t>(strlen(mString)); }
|
||||
void Clear(void) { mString = nullptr; }
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the argument is empty (i.e., reached the end of argument list).
|
||||
*
|
||||
* @retval TRUE The argument is empty.
|
||||
* @retval FALSE The argument is not empty.
|
||||
*
|
||||
*/
|
||||
bool IsEmpty(void) const { return (mString == nullptr); }
|
||||
|
||||
/**
|
||||
* This method returns the length (number of characters) in the argument C string.
|
||||
*
|
||||
* @returns The argument string length if argument is not empty, zero otherwise.
|
||||
*
|
||||
*/
|
||||
uint16_t GetLength(void) const;
|
||||
|
||||
/**
|
||||
* This method gets the argument as a C string.
|
||||
*
|
||||
* @returns A pointer to the argument as a C string.
|
||||
* @returns A pointer to the argument as a C string, or `nullptr` if argument is empty.
|
||||
*
|
||||
*/
|
||||
const char *GetCString(void) const { return mString; }
|
||||
@@ -313,7 +325,7 @@ public:
|
||||
/**
|
||||
* This method gets the argument as C string.
|
||||
*
|
||||
* @returns A pointer to the argument as a C string.
|
||||
* @returns A pointer to the argument as a C string, or `nullptr` if argument is empty.
|
||||
*
|
||||
*/
|
||||
char *GetCString(void) { return mString; }
|
||||
@@ -329,21 +341,24 @@ public:
|
||||
/**
|
||||
* This method overload the operator `==` to evaluate whether the argument is equal to a given C string.
|
||||
*
|
||||
* @param[in] aString The C string to compare with.
|
||||
* If the argument is empty (`IsEmpty()` is `true`) then comparing it using operator `==` with any C string will
|
||||
* return false.
|
||||
*
|
||||
* @retval TRUE If the argument is equal to @p aString.
|
||||
* @retval FALSE If the argument is not equal to @p aString.
|
||||
* @param[in] aString The C string to compare with (MUST not be `nullptr`).
|
||||
*
|
||||
* @retval TRUE If the argument is not empty and is equal to @p aString.
|
||||
* @retval FALSE If the argument is not equal to @p aString, or if the argument is empty.
|
||||
*
|
||||
*/
|
||||
bool operator==(const char *aString) const { return (strcmp(mString, aString) == 0); }
|
||||
bool operator==(const char *aString) const;
|
||||
|
||||
/**
|
||||
* This method overload the operator `!=` to evaluate whether the argument is unequal to a given C string.
|
||||
*
|
||||
* @param[in] aString The C string to compare with.
|
||||
* @param[in] aString The C string to compare with (MUST not be `nullptr`).
|
||||
*
|
||||
* @retval TRUE If the argument is not equal to @p aString.
|
||||
* @retval FALSE If the argument is equal to @p aString.
|
||||
* @retval TRUE If the argument is not equal to @p aString, or if the argument is empty.
|
||||
* @retval FALSE If the argument is not empty and equal to @p aString.
|
||||
*
|
||||
*/
|
||||
bool operator!=(const char *aString) const { return !(*this == aString); }
|
||||
@@ -356,7 +371,7 @@ public:
|
||||
* @param[out] aUint8 A reference to an `uint8_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint8(uint8_t &aUint8) const { return CmdLineParser::ParseAsUint8(mString, aUint8); }
|
||||
@@ -369,7 +384,7 @@ public:
|
||||
* @param[out] aUint16 A reference to an `uint16_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint16(uint16_t &aUint16) const { return CmdLineParser::ParseAsUint16(mString, aUint16); }
|
||||
@@ -382,7 +397,7 @@ public:
|
||||
* @param[out] aUint32 A reference to an `uint32_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint32(uint32_t &aUint32) const { return CmdLineParser::ParseAsUint32(mString, aUint32); }
|
||||
@@ -395,7 +410,7 @@ public:
|
||||
* @param[out] aUint64 A reference to an `uint64_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint64(uint64_t &aUint64) const { return CmdLineParser::ParseAsUint64(mString, aUint64); }
|
||||
@@ -409,7 +424,7 @@ public:
|
||||
* @param[out] aInt8 A reference to an `int8_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsInt8(int8_t &aInt8) const { return CmdLineParser::ParseAsInt8(mString, aInt8); }
|
||||
@@ -423,7 +438,7 @@ public:
|
||||
* @param[out] aInt16 A reference to an `int16_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsInt16(int16_t &aInt16) const { return CmdLineParser::ParseAsInt16(mString, aInt16); }
|
||||
@@ -437,7 +452,7 @@ public:
|
||||
* @param[out] aInt32 A reference to an `int32_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number (e.g., value out of range).
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
otError ParseAsInt32(int32_t &aInt32) const { return CmdLineParser::ParseAsInt32(mString, aInt32); }
|
||||
@@ -450,7 +465,7 @@ public:
|
||||
* @param[out] aBool A reference to a `bool` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid number.
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid number.
|
||||
*
|
||||
*/
|
||||
otError ParseAsBool(bool &aBool) const { return CmdLineParser::ParseAsBool(mString, aBool); }
|
||||
@@ -462,7 +477,7 @@ public:
|
||||
* @param[out] aAddress A reference to an `otIp6Address` to output the parsed IPv6 address.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid IPv6 address.
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid IPv6 address.
|
||||
*
|
||||
*/
|
||||
otError ParseAsIp6Address(otIp6Address &aAddress) const
|
||||
@@ -478,7 +493,7 @@ public:
|
||||
* @param[out] aPrefix A reference to an `otIp6Prefix` to output the parsed IPv6 prefix.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain a valid IPv6 prefix.
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain a valid IPv6 prefix.
|
||||
*
|
||||
*/
|
||||
otError ParseAsIp6Prefix(otIp6Prefix &aPrefix) const { return CmdLineParser::ParseAsIp6Prefix(mString, aPrefix); }
|
||||
@@ -493,7 +508,7 @@ public:
|
||||
* @param[out] aValue A reference to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain a valid value.
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain a valid value.
|
||||
*
|
||||
*/
|
||||
template <typename Type> otError ParseAs(Type &aValue) const;
|
||||
@@ -509,7 +524,7 @@ public:
|
||||
* @param[in] aSize The expected size of byte sequence (number of bytes after parsing).
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid hex bytes and/or not @p aSize bytes.
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid hex bytes and/or not @p aSize bytes.
|
||||
*
|
||||
*/
|
||||
otError ParseAsHexString(uint8_t *aBuffer, uint16_t aSize) const
|
||||
@@ -529,7 +544,7 @@ public:
|
||||
* @param[out] aBuffer A reference to a byte array to output the parsed byte sequence.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid hex bytes and/or not @p aSize bytes.
|
||||
* @retval kErrorInvalidArgs The argument is empty or does not contain valid hex bytes and/or not @p aSize bytes.
|
||||
*
|
||||
*/
|
||||
template <uint16_t kBufferSize> otError ParseAsHexString(uint8_t (&aBuffer)[kBufferSize])
|
||||
@@ -561,13 +576,22 @@ public:
|
||||
* @note this method only copies the string pointer value (i.e., `GetString()` pointer) from `aArgs` array to the
|
||||
* @p aStrings array (the content of strings are not copied).
|
||||
*
|
||||
* @param[in] aArgs A pointer to an `Arg` array.
|
||||
* @param[in] aArgsLength Number of entries in the @p aArgs array.
|
||||
* @param[in] aArgs An `Arg` array.
|
||||
* @param[out] aStrings An `char *` array to populate with the argument string pointers. The @p aString array
|
||||
* MUST contain at least @p aArgsLength entries.
|
||||
* MUST contain at least same number of entries as in @p aArgs array.
|
||||
*
|
||||
*/
|
||||
static void CopyArgsToStringArray(Arg aArgs[], uint8_t aArgsLength, char *aStrings[]);
|
||||
static void CopyArgsToStringArray(Arg aArgs[], char *aStrings[]);
|
||||
|
||||
/**
|
||||
* This static method returns the length of argument array, i.e. number of consecutive non-empty arguments.
|
||||
*
|
||||
* @param[in] aArgs An `Arg` array.
|
||||
*
|
||||
* @returns Number of non-empty arguments in the array.
|
||||
*
|
||||
*/
|
||||
static uint8_t GetArgsLength(Arg aArgs[]);
|
||||
|
||||
private:
|
||||
char *mString;
|
||||
@@ -576,17 +600,31 @@ private:
|
||||
/**
|
||||
* This function parses a given command line string and breaks it into an argument list.
|
||||
*
|
||||
* Note: this method may change the input @p aCommandString, it will put a '\0' by the end of each argument,
|
||||
* and @p aArgs will point to the arguments in the input @p aCommandString. Backslash ('\') can be used
|
||||
* to escape separators (' ', '\t', '\r', '\n') and the backslash itself.
|
||||
* This function may change the input @p aCommandString, it will put a '\0' by the end of each argument, and @p aArgs
|
||||
* will point to the arguments in the input @p aCommandString. Backslash ('\') can be used to escape separators
|
||||
* (' ', '\t', '\r', '\n') and the backslash itself.
|
||||
*
|
||||
* As the arguments are parsed, the @p aArgs array entries are populated. Any remaining @p aArgs entries in the array
|
||||
* will be cleared and marked as empty. So the number of arguments can be determined by going through @p aArgs array
|
||||
* entries till we get to an empty `Arg` (i.e., `Arg::IsEmpty()` returns `true).
|
||||
*
|
||||
* This function ensures that the last entry in @p aArgs array is always used to indicate the end (always marked as
|
||||
* empty), so the @p aArgs array should have one more entry than the desired max number of arguments.
|
||||
*
|
||||
* @param[in] aCommandString A null-terminated input string.
|
||||
* @param[out] aArgsLength The argument counter of the command line.
|
||||
* @param[out] aArgs The argument vector of the command line.
|
||||
* @param[in] aArgsLengthMax The maximum argument counter.
|
||||
* @param[out] aArgs The argument array.
|
||||
* @param[in] aArgsMaxLength The max length of @p aArgs array.
|
||||
*
|
||||
* @retval OT_ERROR_NONE The command line parsed successfully and @p aArgs array is populated.
|
||||
* @retval OT_ERROR_INVALID_ARGS Too many arguments in @p aCommandString and could not fit in @p aArgs array.
|
||||
*
|
||||
*/
|
||||
otError ParseCmd(char *aCommandString, uint8_t &aArgsLength, Arg aArgs[], uint8_t aArgsLengthMax);
|
||||
otError ParseCmd(char *aCommandString, Arg aArgs[], uint8_t aArgsMaxLength);
|
||||
|
||||
template <uint8_t kLength> inline otError ParseCmd(char *aCommandString, Arg (&aArgs)[kLength])
|
||||
{
|
||||
return ParseCmd(aCommandString, aArgs, kLength);
|
||||
}
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Specializations of `Arg::ParseAs<Type>()` method.
|
||||
|
||||
Reference in New Issue
Block a user