mirror of
https://github.com/espressif/openthread.git
synced 2026-08-02 00:57:47 +00:00
[cli] simplify arg checking/parsing with new Arg class (#6524)
This commit adds a new `Arg` class in `parse_cmdline` which represents
a single argument (wrapper over a C string). The `Arg` class is then
used in CLI modules. This helps simplify the CLI code mainly using
simpler syntax, e.g., using an overload of `==` operator to compare an
argument with a C string, or calling `ParseAs{Type}()` methods
directly on an `Arg` instance.
This commit is contained in:
+432
-428
File diff suppressed because it is too large
Load Diff
+121
-117
@@ -69,6 +69,7 @@
|
||||
#include "common/debug.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
@@ -98,6 +99,8 @@ class Interpreter
|
||||
friend class UdpExample;
|
||||
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -283,9 +286,9 @@ public:
|
||||
void OutputEnabledDisabledStatus(bool aEnabled);
|
||||
|
||||
/**
|
||||
* This static method checks a given string against "enable" or "disable" commands.
|
||||
* This static method checks a given argument string against "enable" or "disable" commands.
|
||||
*
|
||||
* @param[in] aString The string to parse.
|
||||
* @param[in] aArgs The argument string to parse.
|
||||
* @param[out] aEnable Boolean variable to return outcome on success.
|
||||
* Set to TRUE for "enable" command, and FALSE for "disable" command.
|
||||
*
|
||||
@@ -293,7 +296,7 @@ public:
|
||||
* @retval OT_ERROR_INVALID_COMMAND The @p aString is not "enable" or "disable" command.
|
||||
*
|
||||
*/
|
||||
static otError ParseEnableOrDisable(const char *aString, bool &aEnable);
|
||||
static otError ParseEnableOrDisable(const Arg &aArg, bool &aEnable);
|
||||
|
||||
/**
|
||||
* This method sets the user command table.
|
||||
@@ -320,126 +323,127 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Interpreter::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (Interpreter::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
otError ParsePingInterval(const char *aString, uint32_t &aInterval);
|
||||
otError ParsePingInterval(const Arg &aArg, uint32_t &aInterval);
|
||||
#endif
|
||||
static otError ParseJoinerDiscerner(char *aString, otJoinerDiscerner &aDiscerner);
|
||||
static otError ParseJoinerDiscerner(Arg &aArg, otJoinerDiscerner &aDiscerner);
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCcaThreshold(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBufferInfo(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChannel(uint8_t aArgsLength, char *aArgs[]);
|
||||
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[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
otError ProcessBorderAgent(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBorderAgent(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
otError ProcessBorderRouting(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBorderRouting(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
otError ProcessBackboneRouter(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBackboneRouter(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
otError ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBackboneRouterLocal(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE && OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
||||
otError ProcessBackboneRouterMgmtMlr(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBackboneRouterMgmtMlr(uint8_t aArgsLength, Arg aArgs[]);
|
||||
void PrintMulticastListenersTable(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
otError ProcessDomainName(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDomainName(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
otError ProcessDua(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDua(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessChild(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChildIp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChildMax(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChild(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChildIp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessChildMax(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE
|
||||
otError ProcessChildSupervision(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChildSupervision(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessChildTimeout(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChildTimeout(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
|
||||
otError ProcessCoap(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCoap(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
|
||||
otError ProcessCoapSecure(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCoapSecure(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
|
||||
otError ProcessCoexMetrics(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCoexMetrics(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
otError ProcessCommissioner(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCommissioner(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessContextIdReuseDelay(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessContextIdReuseDelay(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessCounters(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCsl(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCounters(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessCsl(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessDelayTimerMin(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDelayTimerMin(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
otError ProcessDiag(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDiag(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessDiscover(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDns(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDiscover(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDns(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
void OutputEidCacheEntry(const otCacheEntryInfo &aEntry);
|
||||
otError ProcessEidCache(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessEidCache(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessEui64(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessEui64(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
otError ProcessExit(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessExit(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessLog(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessExtAddress(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessFactoryReset(uint8_t aArgsLength, char *aArgs[]);
|
||||
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[]);
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessFake(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessFake(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessFem(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIfconfig(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIpAddr(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIpAddrAdd(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIpAddrDel(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIpMulticastAddr(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIpMulticastAddrAdd(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessIpMulticastAddrDel(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMulticastPromiscuous(uint8_t aArgsLength, char *aArgs[]);
|
||||
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[]);
|
||||
#if OPENTHREAD_CONFIG_JOINER_ENABLE
|
||||
otError ProcessJoiner(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessJoiner(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessJoinerPort(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessJoinerPort(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLeaderData(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessKeySequence(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLeaderData(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessPartitionId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLeaderWeight(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPartitionId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessLeaderWeight(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMasterKey(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE
|
||||
otError ProcessLinkMetrics(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLinkMetricsQuery(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLinkMetricsMgmt(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLinkMetricsProbe(uint8_t aArgsLength, char *aArgs[]);
|
||||
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 ParseLinkMetricsFlags(otLinkMetrics &aLinkMetrics, char *aFlags);
|
||||
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, char *aArgs[]);
|
||||
otError ProcessMlr(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
otError ProcessMlrReg(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMlrReg(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
static void HandleMlrRegResult(void * aContext,
|
||||
otError aError,
|
||||
@@ -451,15 +455,15 @@ private:
|
||||
const otIp6Address *aFailedAddresses,
|
||||
uint8_t aFailedAddressNum);
|
||||
#endif
|
||||
otError ProcessMode(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMultiRadio(uint8_t aArgsLength, char *aArgsp[]);
|
||||
otError ProcessMode(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMultiRadio(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
void OutputMultiRadioInfo(const otMultiRadioNeighborInfo &aMultiRadioInfo);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessNeighbor(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNeighbor(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkData(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetworkData(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessNetworkDataPrefix(void);
|
||||
otError ProcessNetworkDataRoute(void);
|
||||
otError ProcessNetworkDataService(void);
|
||||
@@ -469,89 +473,89 @@ private:
|
||||
void OutputService(const otServiceConfig &aConfig);
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
|
||||
otError ProcessNetif(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetif(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetstat(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetstat(uint8_t aArgsLength, Arg aArgs[]);
|
||||
int OutputSocketAddress(const otSockAddr &aAddress);
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError ProcessService(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessService(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessServiceList(void);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
otError ProcessNetworkDiagnostic(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetworkDiagnostic(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessNetworkIdTimeout(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetworkIdTimeout(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetworkName(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
otError ProcessNetworkTime(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetworkTime(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPanId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessParent(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPanId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessParent(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessParentPriority(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessParentPriority(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
otError ProcessPing(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPing(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPollPeriod(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPollPeriod(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError ProcessPrefix(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPrefixAdd(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPrefixRemove(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPrefix(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPrefixAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPrefixRemove(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPrefixList(void);
|
||||
#endif
|
||||
otError ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPromiscuous(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessPreferRouterId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPskc(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPreferRouterId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPskc(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessRcp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRegion(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRcp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRegion(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessReleaseRouterId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessReleaseRouterId(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessReset(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessReset(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError ProcessRoute(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRouteAdd(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRouteRemove(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRoute(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouteAdd(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouteRemove(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRouteList(void);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessRouter(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRouterDowngradeThreshold(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRouterEligible(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRouterSelectionJitter(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRouterUpgradeThreshold(uint8_t aArgsLength, char *aArgs[]);
|
||||
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[]);
|
||||
#endif
|
||||
otError ProcessRloc16(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessScan(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSingleton(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRloc16(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessScan(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSingleton(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
|
||||
otError ProcessSntp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSntp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE || OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
otError ProcessSrp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSrp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessState(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessThread(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDataset(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessTxPower(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessUdp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessUnsecurePort(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessVersion(uint8_t aArgsLength, char *aArgs[]);
|
||||
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[]);
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
otError ProcessMacFilter(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMacFilter(uint8_t aArgsLength, Arg aArgs[]);
|
||||
void PrintMacFilter(void);
|
||||
otError ProcessMacFilterAddress(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMacFilterRss(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMacFilterAddress(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacFilterRss(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessMac(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMacRetries(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMac(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMacRetries(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessMacSend(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMacSend(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
@@ -581,7 +585,7 @@ private:
|
||||
void OutputDnsTxtData(const uint8_t *aTxtData, uint16_t aTxtDataLength);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
|
||||
otError GetDnsConfig(uint8_t aArgsLength, char *aArgs[], otDnsQueryConfig *&aConfig, uint8_t aStartArgsIndex);
|
||||
otError GetDnsConfig(uint8_t aArgsLength, Arg aArgs[], otDnsQueryConfig *&aConfig, uint8_t aStartArgsIndex);
|
||||
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
|
||||
|
||||
+44
-47
@@ -41,11 +41,6 @@
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "coap/coap_message.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsIp6Address;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint32;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint8;
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -151,7 +146,7 @@ void Coap::PrintPayload(otMessage *aMessage) const
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError Coap::ProcessCancel(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessCancel(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -160,7 +155,7 @@ otError Coap::ProcessCancel(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
#endif
|
||||
|
||||
otError Coap::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -173,13 +168,13 @@ otError Coap::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Coap::ProcessResource(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessResource(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
VerifyOrExit(strlen(aArgs[1]) < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
mResource.mUriPath = mUriPath;
|
||||
mResource.mContext = this;
|
||||
@@ -191,11 +186,12 @@ otError Coap::ProcessResource(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[2], mBlockCount));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(mBlockCount));
|
||||
}
|
||||
#endif
|
||||
|
||||
strncpy(mUriPath, aArgs[1], sizeof(mUriPath) - 1);
|
||||
strncpy(mUriPath, aArgs[1].GetCString(), sizeof(mUriPath) - 1);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
otCoapAddBlockWiseResource(mInterpreter.mInstance, &mResource);
|
||||
#else
|
||||
@@ -211,7 +207,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otMessage * notificationMessage = nullptr;
|
||||
@@ -221,8 +217,8 @@ otError Coap::ProcessSet(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
VerifyOrExit(strlen(aArgs[1]) < sizeof(mResourceContent), error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(mResourceContent, aArgs[1], sizeof(mResourceContent));
|
||||
VerifyOrExit(aArgs[1].GetLength() < sizeof(mResourceContent), error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(mResourceContent, aArgs[1].GetCString(), sizeof(mResourceContent));
|
||||
mResourceContent[sizeof(mResourceContent) - 1] = '\0';
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
@@ -273,7 +269,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -281,7 +277,7 @@ otError Coap::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
return otCoapStart(mInterpreter.mInstance, OT_DEFAULT_COAP_PORT);
|
||||
}
|
||||
|
||||
otError Coap::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -295,7 +291,7 @@ otError Coap::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
return otCoapStop(mInterpreter.mInstance);
|
||||
}
|
||||
|
||||
otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessParameters(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool * defaultTxParameters;
|
||||
@@ -303,12 +299,12 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
VerifyOrExit(aArgsLength > 1, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[1], "request") == 0)
|
||||
if (aArgs[1] == "request")
|
||||
{
|
||||
txParameters = &mRequestTxParameters;
|
||||
defaultTxParameters = &mUseDefaultRequestTxParameters;
|
||||
}
|
||||
else if (strcmp(aArgs[1], "response") == 0)
|
||||
else if (aArgs[1] == "response")
|
||||
{
|
||||
txParameters = &mResponseTxParameters;
|
||||
defaultTxParameters = &mUseDefaultResponseTxParameters;
|
||||
@@ -320,7 +316,7 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
if (strcmp(aArgs[2], "default") == 0)
|
||||
if (aArgs[2] == "default")
|
||||
{
|
||||
*defaultTxParameters = true;
|
||||
}
|
||||
@@ -328,10 +324,10 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
VerifyOrExit(aArgsLength >= 6, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[2], txParameters->mAckTimeout));
|
||||
SuccessOrExit(error = ParseAsUint8(aArgs[3], txParameters->mAckRandomFactorNumerator));
|
||||
SuccessOrExit(error = ParseAsUint8(aArgs[4], txParameters->mAckRandomFactorDenominator));
|
||||
SuccessOrExit(error = ParseAsUint8(aArgs[5], txParameters->mMaxRetransmit));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(txParameters->mAckTimeout));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint8(txParameters->mAckRandomFactorNumerator));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint8(txParameters->mAckRandomFactorDenominator));
|
||||
SuccessOrExit(error = aArgs[5].ParseAsUint8(txParameters->mMaxRetransmit));
|
||||
|
||||
VerifyOrExit(txParameters->mAckRandomFactorNumerator > txParameters->mAckRandomFactorDenominator,
|
||||
error = OT_ERROR_INVALID_ARGS);
|
||||
@@ -340,7 +336,8 @@ otError Coap::ProcessParameters(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
}
|
||||
|
||||
mInterpreter.OutputLine("Transmission parameters for %s:", aArgs[1]);
|
||||
mInterpreter.OutputLine("Transmission parameters for %s:", aArgs[1].GetCString());
|
||||
|
||||
if (*defaultTxParameters)
|
||||
{
|
||||
mInterpreter.OutputLine("default");
|
||||
@@ -356,7 +353,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::ProcessRequest(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessage * message = nullptr;
|
||||
@@ -380,7 +377,7 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// CoAP-Code
|
||||
if (strcmp(aArgs[0], "get") == 0)
|
||||
if (aArgs[0] == "get")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_GET;
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
@@ -388,28 +385,28 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
#endif
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
else if (strcmp(aArgs[0], "observe") == 0)
|
||||
else if (aArgs[0] == "observe")
|
||||
{
|
||||
// Observe request. This is a GET with Observe=0
|
||||
coapCode = OT_COAP_CODE_GET;
|
||||
coapObserve = true;
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(aArgs[0], "post") == 0)
|
||||
else if (aArgs[0] == "post")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_POST;
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
coapBlockType = ot::Coap::Message::kBlockType1;
|
||||
#endif
|
||||
}
|
||||
else if (strcmp(aArgs[0], "put") == 0)
|
||||
else if (aArgs[0] == "put")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_PUT;
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
coapBlockType = ot::Coap::Message::kBlockType1;
|
||||
#endif
|
||||
}
|
||||
else if (strcmp(aArgs[0], "delete") == 0)
|
||||
else if (aArgs[0] == "delete")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_DELETE;
|
||||
}
|
||||
@@ -421,7 +418,7 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// Destination IPv6 address
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[1], coapDestinationIp));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsIp6Address(coapDestinationIp));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -431,8 +428,8 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// CoAP-URI
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
VerifyOrExit(strlen(aArgs[2]) < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(coapUri, aArgs[2], sizeof(coapUri) - 1);
|
||||
VerifyOrExit(aArgs[2].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(coapUri, aArgs[2].GetCString(), sizeof(coapUri) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -442,48 +439,48 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// CoAP-Type
|
||||
if (aArgsLength > 3)
|
||||
{
|
||||
if (strcmp(aArgs[3], "con") == 0)
|
||||
if (aArgs[3] == "con")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
else if (strcmp(aArgs[3], "block-16") == 0)
|
||||
else if (aArgs[3] == "block-16")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_16;
|
||||
}
|
||||
else if (strcmp(aArgs[3], "block-32") == 0)
|
||||
else if (aArgs[3] == "block-32")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_32;
|
||||
}
|
||||
else if (strcmp(aArgs[3], "block-64") == 0)
|
||||
else if (aArgs[3] == "block-64")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_64;
|
||||
}
|
||||
else if (strcmp(aArgs[3], "block-128") == 0)
|
||||
else if (aArgs[3] == "block-128")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_128;
|
||||
}
|
||||
else if (strcmp(aArgs[3], "block-256") == 0)
|
||||
else if (aArgs[3] == "block-256")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_256;
|
||||
}
|
||||
else if (strcmp(aArgs[3], "block-512") == 0)
|
||||
else if (aArgs[3] == "block-512")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_512;
|
||||
}
|
||||
else if (strcmp(aArgs[3], "block-1024") == 0)
|
||||
else if (aArgs[3] == "block-1024")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
@@ -534,12 +531,12 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
if (coapBlock)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[4], mBlockCount));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint32(mBlockCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
payloadLength = static_cast<uint16_t>(strlen(aArgs[4]));
|
||||
payloadLength = aArgs[4].GetLength();
|
||||
|
||||
if (payloadLength > 0)
|
||||
{
|
||||
@@ -553,7 +550,7 @@ otError Coap::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// Embed content into message if given
|
||||
if (payloadLength > 0)
|
||||
{
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[4], payloadLength));
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[4].GetCString(), payloadLength));
|
||||
}
|
||||
|
||||
memset(&messageInfo, 0, sizeof(messageInfo));
|
||||
@@ -610,14 +607,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Coap::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength, aArgs);
|
||||
|
||||
+13
-10
@@ -40,6 +40,7 @@
|
||||
|
||||
#include "coap/coap_message.hpp"
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -53,6 +54,8 @@ class Interpreter;
|
||||
class Coap
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -68,7 +71,7 @@ public:
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -80,7 +83,7 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Coap::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (Coap::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
@@ -90,16 +93,16 @@ private:
|
||||
|
||||
void PrintPayload(otMessage *aMessage) const;
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessCancel(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCancel(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessParameters(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRequest(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessResource(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSet(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessParameters(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRequest(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[]);
|
||||
|
||||
static void HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
void HandleRequest(otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
+45
-50
@@ -40,15 +40,10 @@
|
||||
#include <openthread/random_noncrypto.h>
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
// header for place your x509 certificate and private key
|
||||
#include "x509_cert_key.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsIp6Address;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint16;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint32;
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
@@ -97,7 +92,7 @@ void CoapSecure::PrintPayload(otMessage *aMessage) const
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -110,13 +105,13 @@ otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessResource(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessResource(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
VerifyOrExit(strlen(aArgs[1]) < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
mResource.mUriPath = mUriPath;
|
||||
mResource.mContext = this;
|
||||
@@ -128,11 +123,11 @@ otError CoapSecure::ProcessResource(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[2], mBlockCount));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(mBlockCount));
|
||||
}
|
||||
#endif
|
||||
|
||||
strncpy(mUriPath, aArgs[1], sizeof(mUriPath) - 1);
|
||||
strncpy(mUriPath, aArgs[1].GetCString(), sizeof(mUriPath) - 1);
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
otCoapSecureAddBlockWiseResource(mInterpreter.mInstance, &mResource);
|
||||
#else
|
||||
@@ -148,14 +143,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessSet(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
VerifyOrExit(strlen(aArgs[1]) < sizeof(mResourceContent), error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(mResourceContent, aArgs[1], sizeof(mResourceContent));
|
||||
VerifyOrExit(aArgs[1].GetLength() < sizeof(mResourceContent), error = OT_ERROR_INVALID_ARGS);
|
||||
strncpy(mResourceContent, aArgs[1].GetCString(), sizeof(mResourceContent));
|
||||
mResourceContent[sizeof(mResourceContent) - 1] = '\0';
|
||||
}
|
||||
else
|
||||
@@ -167,20 +162,20 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
bool verifyPeerCert = true;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
if (strcmp(aArgs[1], "false") == 0)
|
||||
if (aArgs[1] == "false")
|
||||
{
|
||||
verifyPeerCert = false;
|
||||
}
|
||||
else if (strcmp(aArgs[1], "true") != 0)
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aArgs[1] == "true", error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +192,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -221,7 +216,7 @@ otError CoapSecure::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessRequest(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessage * message = nullptr;
|
||||
@@ -243,28 +238,28 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// CoAP-Code
|
||||
if (strcmp(aArgs[0], "get") == 0)
|
||||
if (aArgs[0] == "get")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_GET;
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
coapBlockType = ot::Coap::Message::kBlockType2;
|
||||
#endif
|
||||
}
|
||||
else if (strcmp(aArgs[0], "post") == 0)
|
||||
else if (aArgs[0] == "post")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_POST;
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
coapBlockType = ot::Coap::Message::kBlockType1;
|
||||
#endif
|
||||
}
|
||||
else if (strcmp(aArgs[0], "put") == 0)
|
||||
else if (aArgs[0] == "put")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_PUT;
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
coapBlockType = ot::Coap::Message::kBlockType1;
|
||||
#endif
|
||||
}
|
||||
else if (strcmp(aArgs[0], "delete") == 0)
|
||||
else if (aArgs[0] == "delete")
|
||||
{
|
||||
coapCode = OT_COAP_CODE_DELETE;
|
||||
}
|
||||
@@ -276,7 +271,7 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// Destination IPv6 address
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
error = ParseAsIp6Address(aArgs[1], coapDestinationIp);
|
||||
error = aArgs[1].ParseAsIp6Address(coapDestinationIp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -297,54 +292,54 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// CoAP-URI
|
||||
if (aArgsLength > (2 - indexShifter))
|
||||
{
|
||||
strncpy(coapUri, aArgs[2 - indexShifter], sizeof(coapUri) - 1);
|
||||
strncpy(coapUri, aArgs[2 - indexShifter].GetCString(), sizeof(coapUri) - 1);
|
||||
}
|
||||
|
||||
// CoAP-Type
|
||||
if (aArgsLength > (3 - indexShifter))
|
||||
{
|
||||
if (strcmp(aArgs[3 - indexShifter], "con") == 0)
|
||||
if (aArgs[3 - indexShifter] == "con")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-16") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-16")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_16;
|
||||
}
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-32") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-32")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_32;
|
||||
}
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-64") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-64")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_64;
|
||||
}
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-128") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-128")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_128;
|
||||
}
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-256") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-256")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_256;
|
||||
}
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-512") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-512")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
coapBlockSize = OT_COAP_OPTION_BLOCK_SZX_512;
|
||||
}
|
||||
else if (strcmp(aArgs[3 - indexShifter], "block-1024") == 0)
|
||||
else if (aArgs[3 - indexShifter] == "block-1024")
|
||||
{
|
||||
coapType = OT_COAP_TYPE_CONFIRMABLE;
|
||||
coapBlock = true;
|
||||
@@ -379,12 +374,12 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
if (coapBlock)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[4 - indexShifter], mBlockCount));
|
||||
SuccessOrExit(error = aArgs[4 - indexShifter].ParseAsUint32(mBlockCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
payloadLength = static_cast<uint16_t>(strlen(aArgs[4 - indexShifter]));
|
||||
payloadLength = aArgs[4 - indexShifter].GetLength();
|
||||
|
||||
if (payloadLength > 0)
|
||||
{
|
||||
@@ -398,7 +393,7 @@ otError CoapSecure::ProcessRequest(uint8_t aArgsLength, char *aArgs[])
|
||||
// add payload
|
||||
if (payloadLength > 0)
|
||||
{
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[4 - indexShifter], payloadLength));
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[4 - indexShifter].GetCString(), payloadLength));
|
||||
}
|
||||
|
||||
memset(&messageInfo, 0, sizeof(messageInfo));
|
||||
@@ -437,7 +432,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessConnect(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessConnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otSockAddr sockaddr;
|
||||
@@ -446,13 +441,13 @@ otError CoapSecure::ProcessConnect(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
// Destination IPv6 address
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[1], sockaddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsIp6Address(sockaddr.mAddress));
|
||||
sockaddr.mPort = OT_DEFAULT_COAP_SECURE_PORT;
|
||||
|
||||
// check for port specification
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[2], sockaddr.mPort));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint16(sockaddr.mPort));
|
||||
}
|
||||
|
||||
SuccessOrExit(error = otCoapSecureConnect(mInterpreter.mInstance, &sockaddr, &CoapSecure::HandleConnected, this));
|
||||
@@ -461,7 +456,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError CoapSecure::ProcessDisconnect(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessDisconnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -472,22 +467,22 @@ otError CoapSecure::ProcessDisconnect(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
|
||||
#ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
otError CoapSecure::ProcessPsk(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessPsk(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t length;
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(aArgsLength > 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
length = strlen(aArgs[1]);
|
||||
length = aArgs[1].GetLength();
|
||||
VerifyOrExit(length <= sizeof(mPsk), error = OT_ERROR_INVALID_ARGS);
|
||||
mPskLength = static_cast<uint8_t>(length);
|
||||
memcpy(mPsk, aArgs[1], mPskLength);
|
||||
memcpy(mPsk, aArgs[1].GetCString(), mPskLength);
|
||||
|
||||
length = strlen(aArgs[2]);
|
||||
length = aArgs[2].GetLength();
|
||||
VerifyOrExit(length <= sizeof(mPskId), error = OT_ERROR_INVALID_ARGS);
|
||||
mPskIdLength = static_cast<uint8_t>(length);
|
||||
memcpy(mPskId, aArgs[2], mPskIdLength);
|
||||
memcpy(mPskId, aArgs[2].GetCString(), mPskIdLength);
|
||||
|
||||
otCoapSecureSetPsk(mInterpreter.mInstance, mPsk, mPskLength, mPskId, mPskIdLength);
|
||||
mUseCertificate = false;
|
||||
@@ -498,7 +493,7 @@ exit:
|
||||
#endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
|
||||
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
otError CoapSecure::ProcessX509(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::ProcessX509(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -516,14 +511,14 @@ otError CoapSecure::ProcessX509(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
#endif
|
||||
|
||||
otError CoapSecure::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError CoapSecure::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength, aArgs);
|
||||
|
||||
+15
-12
@@ -41,6 +41,7 @@
|
||||
#include "coap/coap_message.hpp"
|
||||
#include "coap/coap_secure.hpp"
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#ifndef CLI_COAP_SECURE_USE_COAP_DEFAULT_HANDLER
|
||||
#define CLI_COAP_SECURE_USE_COAP_DEFAULT_HANDLER 0
|
||||
@@ -58,6 +59,8 @@ class Interpreter;
|
||||
class CoapSecure
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -73,7 +76,7 @@ public:
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -87,21 +90,21 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (CoapSecure::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (CoapSecure::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
void PrintPayload(otMessage *aMessage) const;
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessConnect(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDisconnect(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPsk(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRequest(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessResource(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSet(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessX509(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessConnect(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessDisconnect(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessPsk(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessRequest(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[]);
|
||||
|
||||
void Stop(void);
|
||||
|
||||
|
||||
@@ -34,13 +34,6 @@
|
||||
#include "cli_commissioner.hpp"
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsHexString;
|
||||
using ot::Utils::CmdLineParser::ParseAsIp6Address;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint16;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint32;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint8;
|
||||
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
@@ -49,7 +42,7 @@ namespace Cli {
|
||||
|
||||
constexpr Commissioner::Command Commissioner::sCommands[];
|
||||
|
||||
otError Commissioner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -62,7 +55,7 @@ otError Commissioner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessAnnounce(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessAnnounce(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint32_t mask;
|
||||
@@ -72,10 +65,10 @@ otError Commissioner::ProcessAnnounce(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
VerifyOrExit(aArgsLength > 4, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[1], mask));
|
||||
SuccessOrExit(error = ParseAsUint8(aArgs[2], count));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[3], period));
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[4], address));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(mask));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint8(count));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint16(period));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsIp6Address(address));
|
||||
|
||||
SuccessOrExit(error = otCommissionerAnnounceBegin(mInterpreter.mInstance, mask, count, period, &address));
|
||||
|
||||
@@ -83,7 +76,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessEnergy(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessEnergy(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint32_t mask;
|
||||
@@ -94,11 +87,11 @@ otError Commissioner::ProcessEnergy(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
VerifyOrExit(aArgsLength > 5, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[1], mask));
|
||||
SuccessOrExit(error = ParseAsUint8(aArgs[2], count));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[3], period));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[4], scanDuration));
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[5], address));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(mask));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint8(count));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint16(period));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint16(scanDuration));
|
||||
SuccessOrExit(error = aArgs[5].ParseAsIp6Address(address));
|
||||
|
||||
SuccessOrExit(error = otCommissionerEnergyScan(mInterpreter.mInstance, mask, count, period, scanDuration, &address,
|
||||
&Commissioner::HandleEnergyReport, this));
|
||||
@@ -107,7 +100,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessJoiner(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessJoiner(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otExtAddress addr;
|
||||
@@ -118,13 +111,13 @@ otError Commissioner::ProcessJoiner(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
memset(&discerner, 0, sizeof(discerner));
|
||||
|
||||
if (strcmp(aArgs[2], "*") == 0)
|
||||
if (aArgs[2] == "*")
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
else if ((error = Interpreter::ParseJoinerDiscerner(aArgs[2], discerner)) == OT_ERROR_NOT_FOUND)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[2], addr.m8));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsHexString(addr.m8));
|
||||
addrPtr = &addr;
|
||||
}
|
||||
else if (error != OT_ERROR_NONE)
|
||||
@@ -132,7 +125,7 @@ otError Commissioner::ProcessJoiner(uint8_t aArgsLength, char *aArgs[])
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[1], "add") == 0)
|
||||
if (aArgs[1] == "add")
|
||||
{
|
||||
VerifyOrExit(aArgsLength > 3, error = OT_ERROR_INVALID_ARGS);
|
||||
// Timeout parameter is optional - if not specified, use default value.
|
||||
@@ -140,20 +133,21 @@ otError Commissioner::ProcessJoiner(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 4)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[4], timeout));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint32(timeout));
|
||||
}
|
||||
|
||||
if (discerner.mLength)
|
||||
{
|
||||
SuccessOrExit(
|
||||
error = otCommissionerAddJoinerWithDiscerner(mInterpreter.mInstance, &discerner, aArgs[3], timeout));
|
||||
SuccessOrExit(error = otCommissionerAddJoinerWithDiscerner(mInterpreter.mInstance, &discerner,
|
||||
aArgs[3].GetCString(), timeout));
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = otCommissionerAddJoiner(mInterpreter.mInstance, addrPtr, aArgs[3], timeout));
|
||||
SuccessOrExit(error =
|
||||
otCommissionerAddJoiner(mInterpreter.mInstance, addrPtr, aArgs[3].GetCString(), timeout));
|
||||
}
|
||||
}
|
||||
else if (strcmp(aArgs[1], "remove") == 0)
|
||||
else if (aArgs[1] == "remove")
|
||||
{
|
||||
if (discerner.mLength)
|
||||
{
|
||||
@@ -173,7 +167,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessMgmtGet(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessMgmtGet(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t tlvs[32];
|
||||
@@ -183,29 +177,29 @@ otError Commissioner::ProcessMgmtGet(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
VerifyOrExit(static_cast<size_t>(length) < sizeof(tlvs), error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (strcmp(aArgs[index], "locator") == 0)
|
||||
if (aArgs[index] == "locator")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_BORDER_AGENT_RLOC;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "sessionid") == 0)
|
||||
else if (aArgs[index] == "sessionid")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_COMM_SESSION_ID;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "steeringdata") == 0)
|
||||
else if (aArgs[index] == "steeringdata")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_STEERING_DATA;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "joinerudpport") == 0)
|
||||
else if (aArgs[index] == "joinerudpport")
|
||||
{
|
||||
tlvs[length++] = OT_MESHCOP_TLV_JOINER_UDP_PORT;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "-x") == 0)
|
||||
else if (aArgs[index] == "-x")
|
||||
{
|
||||
uint16_t readLength;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
readLength = static_cast<uint16_t>(sizeof(tlvs) - length);
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], readLength, tlvs + length));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(readLength, tlvs + length));
|
||||
length += static_cast<uint8_t>(readLength);
|
||||
}
|
||||
else
|
||||
@@ -220,7 +214,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessMgmtSet(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessMgmtSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otCommissioningDataset dataset;
|
||||
@@ -233,41 +227,41 @@ otError Commissioner::ProcessMgmtSet(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
{
|
||||
if (strcmp(aArgs[index], "locator") == 0)
|
||||
if (aArgs[index] == "locator")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mIsLocatorSet = true;
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[index], dataset.mLocator));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mLocator));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "sessionid") == 0)
|
||||
else if (aArgs[index] == "sessionid")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mIsSessionIdSet = true;
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[index], dataset.mSessionId));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mSessionId));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "steeringdata") == 0)
|
||||
else if (aArgs[index] == "steeringdata")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mIsSteeringDataSet = true;
|
||||
length = sizeof(dataset.mSteeringData.m8);
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], length, dataset.mSteeringData.m8));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, dataset.mSteeringData.m8));
|
||||
dataset.mSteeringData.mLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else if (strcmp(aArgs[index], "joinerudpport") == 0)
|
||||
else if (aArgs[index] == "joinerudpport")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mIsJoinerUdpPortSet = true;
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[index], dataset.mJoinerUdpPort));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mJoinerUdpPort));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "-x") == 0)
|
||||
else if (aArgs[index] == "-x")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
length = sizeof(tlvs);
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], length, tlvs));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, tlvs));
|
||||
tlvsLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else
|
||||
@@ -282,7 +276,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessPanId(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessPanId(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint16_t panId;
|
||||
@@ -291,9 +285,9 @@ otError Commissioner::ProcessPanId(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
VerifyOrExit(aArgsLength > 3, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[1], panId));
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[2], mask));
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[3], address));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(panId));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(mask));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsIp6Address(address));
|
||||
|
||||
SuccessOrExit(error = otCommissionerPanIdQuery(mInterpreter.mInstance, panId, mask, &address,
|
||||
&Commissioner::HandlePanIdConflict, this));
|
||||
@@ -302,12 +296,13 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessProvisioningUrl(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessProvisioningUrl(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
return otCommissionerSetProvisioningUrl(mInterpreter.mInstance, (aArgsLength > 1) ? aArgs[1] : nullptr);
|
||||
return otCommissionerSetProvisioningUrl(mInterpreter.mInstance,
|
||||
(aArgsLength > 1) ? aArgs[1].GetCString() : nullptr);
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessSessionId(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessSessionId(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -317,7 +312,7 @@ otError Commissioner::ProcessSessionId(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -399,7 +394,7 @@ void Commissioner::HandleJoinerEvent(otCommissionerJoinerEvent aEvent,
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -407,7 +402,7 @@ otError Commissioner::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
return otCommissionerStop(mInterpreter.mInstance);
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessState(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::ProcessState(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -417,14 +412,14 @@ otError Commissioner::ProcessState(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Commissioner::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength, aArgs);
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <openthread/commissioner.h>
|
||||
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
@@ -54,6 +55,8 @@ class Interpreter;
|
||||
class Commissioner
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -72,7 +75,7 @@ public:
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -83,21 +86,21 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Commissioner::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (Commissioner::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessAnnounce(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessEnergy(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessJoiner(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMgmtGet(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMgmtSet(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPanId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessProvisioningUrl(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSessionId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessState(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, char *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[]);
|
||||
|
||||
static void HandleStateChanged(otCommissionerState aState, void *aContext);
|
||||
void HandleStateChanged(otCommissionerState aState);
|
||||
|
||||
+104
-112
@@ -42,13 +42,6 @@
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "common/string.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsHexString;
|
||||
using ot::Utils::CmdLineParser::ParseAsIp6Address;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint16;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint32;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint64;
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -134,7 +127,7 @@ otError Dataset::Print(otOperationalDataset &aDataset)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
@@ -144,7 +137,7 @@ otError Dataset::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
ExitNow(error = Print(sDataset));
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
@@ -153,7 +146,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -166,22 +159,22 @@ otError Dataset::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessInit(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessInit(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[0], "active") == 0)
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetGetActive(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
else if (strcmp(aArgs[0], "pending") == 0)
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetGetPending(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
#if OPENTHREAD_FTD
|
||||
else if (strcmp(aArgs[0], "new") == 0)
|
||||
else if (aArgs[0] == "new")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetCreateNewNetwork(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
@@ -195,7 +188,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessActive(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessActive(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
|
||||
@@ -206,11 +199,11 @@ otError Dataset::ProcessActive(uint8_t aArgsLength, char *aArgs[])
|
||||
SuccessOrExit(error = otDatasetGetActive(mInterpreter.mInstance, &dataset));
|
||||
error = Print(dataset);
|
||||
}
|
||||
else if ((aArgsLength == 1) && (strcmp(aArgs[0], "-x") == 0))
|
||||
else if ((aArgsLength == 1) && (aArgs[0] == "-x"))
|
||||
{
|
||||
otOperationalDatasetTlvs dataset;
|
||||
|
||||
VerifyOrExit(strlen(aArgs[0]) <= OT_OPERATIONAL_DATASET_MAX_LENGTH * 2, error = OT_ERROR_NO_BUFS);
|
||||
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);
|
||||
@@ -225,7 +218,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPending(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessPending(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
|
||||
@@ -236,11 +229,11 @@ otError Dataset::ProcessPending(uint8_t aArgsLength, char *aArgs[])
|
||||
SuccessOrExit(error = otDatasetGetPending(mInterpreter.mInstance, &dataset));
|
||||
error = Print(dataset);
|
||||
}
|
||||
else if ((aArgsLength == 1) && (strcmp(aArgs[0], "-x") == 0))
|
||||
else if ((aArgsLength == 1) && (aArgs[0] == "-x"))
|
||||
{
|
||||
otOperationalDatasetTlvs dataset;
|
||||
|
||||
VerifyOrExit(strlen(aArgs[0]) <= OT_OPERATIONAL_DATASET_MAX_LENGTH * 2, error = OT_ERROR_NO_BUFS);
|
||||
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);
|
||||
@@ -255,7 +248,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessActiveTimestamp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessActiveTimestamp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -268,7 +261,7 @@ otError Dataset::ProcessActiveTimestamp(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint64(aArgs[0], sDataset.mActiveTimestamp));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint64(sDataset.mActiveTimestamp));
|
||||
sDataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
}
|
||||
|
||||
@@ -276,7 +269,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessChannel(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessChannel(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -289,7 +282,7 @@ otError Dataset::ProcessChannel(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[0], sDataset.mChannel));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint16(sDataset.mChannel));
|
||||
sDataset.mComponents.mIsChannelPresent = true;
|
||||
}
|
||||
|
||||
@@ -297,7 +290,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessChannelMask(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessChannelMask(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -310,7 +303,7 @@ otError Dataset::ProcessChannelMask(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[0], sDataset.mChannelMask));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(sDataset.mChannelMask));
|
||||
sDataset.mComponents.mIsChannelMaskPresent = true;
|
||||
}
|
||||
|
||||
@@ -318,7 +311,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessClear(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessClear(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -327,17 +320,17 @@ otError Dataset::ProcessClear(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessCommit(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessCommit(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[0], "active") == 0)
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSetActive(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
else if (strcmp(aArgs[0], "pending") == 0)
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSetPending(mInterpreter.mInstance, &sDataset));
|
||||
}
|
||||
@@ -350,7 +343,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessDelay(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessDelay(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -363,7 +356,7 @@ otError Dataset::ProcessDelay(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[0], sDataset.mDelay));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(sDataset.mDelay));
|
||||
sDataset.mComponents.mIsDelayPresent = true;
|
||||
}
|
||||
|
||||
@@ -371,7 +364,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessExtPanId(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -385,7 +378,7 @@ otError Dataset::ProcessExtPanId(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[0], sDataset.mExtendedPanId.m8));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsHexString(sDataset.mExtendedPanId.m8));
|
||||
sDataset.mComponents.mIsExtendedPanIdPresent = true;
|
||||
}
|
||||
|
||||
@@ -393,7 +386,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessMasterKey(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -407,7 +400,7 @@ otError Dataset::ProcessMasterKey(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[0], sDataset.mMasterKey.m8));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsHexString(sDataset.mMasterKey.m8));
|
||||
sDataset.mComponents.mIsMasterKeyPresent = true;
|
||||
}
|
||||
|
||||
@@ -415,7 +408,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMeshLocalPrefix(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessMeshLocalPrefix(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -435,7 +428,7 @@ otError Dataset::ProcessMeshLocalPrefix(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
otIp6Address prefix;
|
||||
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[0], prefix));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(prefix));
|
||||
|
||||
memcpy(sDataset.mMeshLocalPrefix.m8, prefix.mFields.m8, sizeof(sDataset.mMeshLocalPrefix.m8));
|
||||
sDataset.mComponents.mIsMeshLocalPrefixPresent = true;
|
||||
@@ -445,7 +438,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessNetworkName(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -459,13 +452,13 @@ otError Dataset::ProcessNetworkName(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t length;
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit((length = strlen(aArgs[0])) <= OT_NETWORK_NAME_MAX_SIZE, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(IsValidUtf8String(aArgs[0]), error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit((length = aArgs[0].GetLength()) <= OT_NETWORK_NAME_MAX_SIZE, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(IsValidUtf8String(aArgs[0].GetCString()), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memset(&sDataset.mNetworkName, 0, sizeof(sDataset.mNetworkName));
|
||||
memcpy(sDataset.mNetworkName.m8, aArgs[0], length);
|
||||
memcpy(sDataset.mNetworkName.m8, aArgs[0].GetCString(), length);
|
||||
sDataset.mComponents.mIsNetworkNamePresent = true;
|
||||
}
|
||||
|
||||
@@ -473,7 +466,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPanId(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessPanId(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -486,7 +479,7 @@ otError Dataset::ProcessPanId(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[0], sDataset.mPanId));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint16(sDataset.mPanId));
|
||||
sDataset.mComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
|
||||
@@ -494,7 +487,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPendingTimestamp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessPendingTimestamp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -507,7 +500,7 @@ otError Dataset::ProcessPendingTimestamp(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint64(aArgs[0], sDataset.mPendingTimestamp));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint64(sDataset.mPendingTimestamp));
|
||||
sDataset.mComponents.mIsPendingTimestampPresent = true;
|
||||
}
|
||||
|
||||
@@ -515,7 +508,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMgmtSetCommand(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessMgmtSetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDataset dataset;
|
||||
@@ -528,88 +521,88 @@ otError Dataset::ProcessMgmtSetCommand(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
{
|
||||
if (strcmp(aArgs[index], "activetimestamp") == 0)
|
||||
if (aArgs[index] == "activetimestamp")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
SuccessOrExit(error = ParseAsUint64(aArgs[index], dataset.mActiveTimestamp));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint64(dataset.mActiveTimestamp));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "pendingtimestamp") == 0)
|
||||
else if (aArgs[index] == "pendingtimestamp")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsPendingTimestampPresent = true;
|
||||
SuccessOrExit(error = ParseAsUint64(aArgs[index], dataset.mPendingTimestamp));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint64(dataset.mPendingTimestamp));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "masterkey") == 0)
|
||||
else if (aArgs[index] == "masterkey")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsMasterKeyPresent = true;
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], dataset.mMasterKey.m8));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(dataset.mMasterKey.m8));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "networkname") == 0)
|
||||
else if (aArgs[index] == "networkname")
|
||||
{
|
||||
size_t length;
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsNetworkNamePresent = true;
|
||||
VerifyOrExit((length = strlen(aArgs[index])) <= OT_NETWORK_NAME_MAX_SIZE, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit((length = aArgs[index].GetLength()) <= OT_NETWORK_NAME_MAX_SIZE,
|
||||
error = OT_ERROR_INVALID_ARGS);
|
||||
memset(&dataset.mNetworkName, 0, sizeof(sDataset.mNetworkName));
|
||||
memcpy(dataset.mNetworkName.m8, aArgs[index], length);
|
||||
memcpy(dataset.mNetworkName.m8, aArgs[index].GetCString(), length);
|
||||
}
|
||||
else if (strcmp(aArgs[index], "extpanid") == 0)
|
||||
else if (aArgs[index] == "extpanid")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsExtendedPanIdPresent = true;
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], dataset.mExtendedPanId.m8));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(dataset.mExtendedPanId.m8));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "localprefix") == 0)
|
||||
else if (aArgs[index] == "localprefix")
|
||||
{
|
||||
otIp6Address prefix;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsMeshLocalPrefixPresent = true;
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[index], prefix));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsIp6Address(prefix));
|
||||
memcpy(dataset.mMeshLocalPrefix.m8, prefix.mFields.m8, sizeof(dataset.mMeshLocalPrefix.m8));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "delaytimer") == 0)
|
||||
else if (aArgs[index] == "delaytimer")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsDelayPresent = true;
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[index], dataset.mDelay));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint32(dataset.mDelay));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "panid") == 0)
|
||||
else if (aArgs[index] == "panid")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsPanIdPresent = true;
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[index], dataset.mPanId));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mPanId));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "channel") == 0)
|
||||
else if (aArgs[index] == "channel")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsChannelPresent = true;
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[index], dataset.mChannel));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint16(dataset.mChannel));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "channelmask") == 0)
|
||||
else if (aArgs[index] == "channelmask")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.mComponents.mIsChannelMaskPresent = true;
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[index], dataset.mChannelMask));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsUint32(dataset.mChannelMask));
|
||||
}
|
||||
else if (strcmp(aArgs[index], "securitypolicy") == 0)
|
||||
else if (aArgs[index] == "securitypolicy")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = ParseSecurityPolicy(dataset.mSecurityPolicy, aArgs[index],
|
||||
index + 1 < aArgsLength ? aArgs[index + 1] : nullptr));
|
||||
SuccessOrExit(error = ParseSecurityPolicy(dataset.mSecurityPolicy, aArgsLength - index, &aArgs[index]));
|
||||
dataset.mComponents.mIsSecurityPolicyPresent = true;
|
||||
++index;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "-x") == 0)
|
||||
else if (aArgs[index] == "-x")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
length = sizeof(tlvs);
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], length, tlvs));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, tlvs));
|
||||
tlvsLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else
|
||||
@@ -618,11 +611,11 @@ otError Dataset::ProcessMgmtSetCommand(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[0], "active") == 0)
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtActiveSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength));
|
||||
}
|
||||
else if (strcmp(aArgs[0], "pending") == 0)
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtPendingSet(mInterpreter.mInstance, &dataset, tlvs, tlvsLength));
|
||||
}
|
||||
@@ -635,7 +628,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDatasetComponents datasetComponents;
|
||||
@@ -650,59 +643,59 @@ otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
{
|
||||
if (strcmp(aArgs[index], "activetimestamp") == 0)
|
||||
if (aArgs[index] == "activetimestamp")
|
||||
{
|
||||
datasetComponents.mIsActiveTimestampPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "pendingtimestamp") == 0)
|
||||
else if (aArgs[index] == "pendingtimestamp")
|
||||
{
|
||||
datasetComponents.mIsPendingTimestampPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "masterkey") == 0)
|
||||
else if (aArgs[index] == "masterkey")
|
||||
{
|
||||
datasetComponents.mIsMasterKeyPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "networkname") == 0)
|
||||
else if (aArgs[index] == "networkname")
|
||||
{
|
||||
datasetComponents.mIsNetworkNamePresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "extpanid") == 0)
|
||||
else if (aArgs[index] == "extpanid")
|
||||
{
|
||||
datasetComponents.mIsExtendedPanIdPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "localprefix") == 0)
|
||||
else if (aArgs[index] == "localprefix")
|
||||
{
|
||||
datasetComponents.mIsMeshLocalPrefixPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "delaytimer") == 0)
|
||||
else if (aArgs[index] == "delaytimer")
|
||||
{
|
||||
datasetComponents.mIsDelayPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "panid") == 0)
|
||||
else if (aArgs[index] == "panid")
|
||||
{
|
||||
datasetComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "channel") == 0)
|
||||
else if (aArgs[index] == "channel")
|
||||
{
|
||||
datasetComponents.mIsChannelPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "securitypolicy") == 0)
|
||||
else if (aArgs[index] == "securitypolicy")
|
||||
{
|
||||
datasetComponents.mIsSecurityPolicyPresent = true;
|
||||
}
|
||||
else if (strcmp(aArgs[index], "-x") == 0)
|
||||
else if (aArgs[index] == "-x")
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
length = sizeof(tlvs);
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[index], length, tlvs));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsHexString(length, tlvs));
|
||||
tlvsLength = static_cast<uint8_t>(length);
|
||||
}
|
||||
else if (strcmp(aArgs[index], "address") == 0)
|
||||
else if (aArgs[index] == "address")
|
||||
{
|
||||
VerifyOrExit(++index < aArgsLength, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[index], address));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsIp6Address(address));
|
||||
destAddrSpecified = true;
|
||||
}
|
||||
else
|
||||
@@ -711,12 +704,12 @@ otError Dataset::ProcessMgmtGetCommand(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[0], "active") == 0)
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtActiveGet(mInterpreter.mInstance, &datasetComponents, tlvs, tlvsLength,
|
||||
destAddrSpecified ? &address : nullptr));
|
||||
}
|
||||
else if (strcmp(aArgs[0], "pending") == 0)
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
SuccessOrExit(error = otDatasetSendMgmtPendingGet(mInterpreter.mInstance, &datasetComponents, tlvs, tlvsLength,
|
||||
destAddrSpecified ? &address : nullptr));
|
||||
@@ -730,7 +723,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPskc(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessPskc(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -744,14 +737,14 @@ otError Dataset::ProcessPskc(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else if (aArgsLength == 1)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[0], sDataset.mPskc.m8));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsHexString(sDataset.mPskc.m8));
|
||||
}
|
||||
#if OPENTHREAD_FTD
|
||||
else if (aArgsLength == 2 && !strcmp(aArgs[0], "-p"))
|
||||
else if (aArgsLength == 2 && (aArgs[0] == "-p"))
|
||||
{
|
||||
SuccessOrExit(
|
||||
error = otDatasetGeneratePskc(
|
||||
aArgs[1],
|
||||
aArgs[1].GetCString(),
|
||||
(sDataset.mComponents.mIsNetworkNamePresent
|
||||
? &sDataset.mNetworkName
|
||||
: reinterpret_cast<const otNetworkName *>(otThreadGetNetworkName(mInterpreter.mInstance))),
|
||||
@@ -821,17 +814,17 @@ void Dataset::OutputSecurityPolicy(const otSecurityPolicy &aSecurityPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
Error Dataset::ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, const char *aRotation, const char *aFlags)
|
||||
Error Dataset::ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
Error error;
|
||||
otSecurityPolicy policy;
|
||||
|
||||
memset(&policy, 0, sizeof(policy));
|
||||
SuccessOrExit(error = ParseAsUint16(aRotation, policy.mRotationTime));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint16(policy.mRotationTime));
|
||||
|
||||
VerifyOrExit(aFlags != nullptr);
|
||||
VerifyOrExit(aArgsLength >= 1);
|
||||
|
||||
for (const char *flag = aFlags; *flag != '\0'; flag++)
|
||||
for (const char *flag = aArgs[1].GetCString(); *flag != '\0'; flag++)
|
||||
{
|
||||
switch (*flag)
|
||||
{
|
||||
@@ -884,7 +877,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -898,8 +891,7 @@ otError Dataset::ProcessSecurityPolicy(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(
|
||||
error = ParseSecurityPolicy(sDataset.mSecurityPolicy, aArgs[0], aArgsLength > 1 ? aArgs[1] : nullptr));
|
||||
SuccessOrExit(error = ParseSecurityPolicy(sDataset.mSecurityPolicy, aArgsLength, aArgs));
|
||||
sDataset.mComponents.mIsSecurityPolicyPresent = true;
|
||||
}
|
||||
|
||||
@@ -907,18 +899,18 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessSet(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessSet(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
MeshCoP::Dataset::Type datasetType;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[0], "active") == 0)
|
||||
if (aArgs[0] == "active")
|
||||
{
|
||||
datasetType = MeshCoP::Dataset::Type::kActive;
|
||||
}
|
||||
else if (strcmp(aArgs[0], "pending") == 0)
|
||||
else if (aArgs[0] == "pending")
|
||||
{
|
||||
datasetType = MeshCoP::Dataset::Type::kPending;
|
||||
}
|
||||
@@ -932,7 +924,7 @@ otError Dataset::ProcessSet(uint8_t aArgsLength, char *aArgs[])
|
||||
MeshCoP::Dataset::Info datasetInfo;
|
||||
uint16_t tlvsLength = MeshCoP::Dataset::kMaxSize;
|
||||
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[1], tlvsLength, dataset.GetBytes()));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsHexString(tlvsLength, dataset.GetBytes()));
|
||||
dataset.SetSize(tlvsLength);
|
||||
VerifyOrExit(dataset.IsValid(), error = OT_ERROR_INVALID_ARGS);
|
||||
dataset.ConvertTo(datasetInfo);
|
||||
@@ -954,7 +946,7 @@ exit:
|
||||
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
otError Dataset::ProcessUpdater(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Dataset::ProcessUpdater(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -964,11 +956,11 @@ otError Dataset::ProcessUpdater(uint8_t aArgsLength, char *aArgs[])
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[0], "start") == 0)
|
||||
if (aArgs[0] == "start")
|
||||
{
|
||||
error = otDatasetUpdaterRequestUpdate(mInterpreter.mInstance, &sDataset, &Dataset::HandleDatasetUpdater, this);
|
||||
}
|
||||
else if (strcmp(aArgs[0], "cancel") == 0)
|
||||
else if (aArgs[0] == "cancel")
|
||||
{
|
||||
otDatasetUpdaterCancelUpdate(mInterpreter.mInstance);
|
||||
}
|
||||
|
||||
+28
-25
@@ -41,6 +41,7 @@
|
||||
#include <openthread/dataset.h>
|
||||
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -54,6 +55,8 @@ class Interpreter;
|
||||
class Dataset
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
explicit Dataset(Interpreter &aInterpreter)
|
||||
: mInterpreter(aInterpreter)
|
||||
{
|
||||
@@ -66,47 +69,47 @@ public:
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Dataset::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (Dataset::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError Print(otOperationalDataset &aDataset);
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessActive(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessActiveTimestamp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChannel(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessChannelMask(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessClear(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCommit(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDelay(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessExtPanId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessInit(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMeshLocalPrefix(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessNetworkName(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPanId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPending(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPendingTimestamp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMgmtSetCommand(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessMgmtGetCommand(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPskc(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSecurityPolicy(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSet(uint8_t aArgsLength, char *aArgs[]);
|
||||
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 ProcessMasterKey(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessMeshLocalPrefix(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[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
otError ProcessUpdater(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessUpdater(uint8_t aArgsLength, Arg aArgs[]);
|
||||
static void HandleDatasetUpdater(otError aError, void *aContext);
|
||||
void HandleDatasetUpdater(otError aError);
|
||||
#endif
|
||||
|
||||
void OutputSecurityPolicy(const otSecurityPolicy &aSecurityPolicy);
|
||||
Error ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, const char *aRotation, const char *aFlags);
|
||||
Error ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"active", &Dataset::ProcessActive},
|
||||
|
||||
+11
-11
@@ -36,7 +36,6 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_JOINER_ENABLE
|
||||
|
||||
@@ -45,7 +44,7 @@ namespace Cli {
|
||||
|
||||
constexpr Joiner::Command Joiner::sCommands[];
|
||||
|
||||
otError Joiner::ProcessDiscerner(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Joiner::ProcessDiscerner(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -54,7 +53,8 @@ otError Joiner::ProcessDiscerner(uint8_t aArgsLength, char *aArgs[])
|
||||
otJoinerDiscerner discerner;
|
||||
|
||||
memset(&discerner, 0, sizeof(discerner));
|
||||
if (strcmp(aArgs[1], "clear") == 0)
|
||||
|
||||
if (aArgs[1] == "clear")
|
||||
{
|
||||
SuccessOrExit(error = otJoinerSetDiscerner(mInterpreter.mInstance, nullptr));
|
||||
}
|
||||
@@ -82,7 +82,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Joiner::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -95,7 +95,7 @@ otError Joiner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessId(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Joiner::ProcessId(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -106,7 +106,7 @@ otError Joiner::ProcessId(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Joiner::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
const char *provisioningUrl = nullptr;
|
||||
@@ -115,17 +115,17 @@ otError Joiner::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
provisioningUrl = aArgs[2];
|
||||
provisioningUrl = aArgs[2].GetCString();
|
||||
}
|
||||
|
||||
error = otJoinerStart(mInterpreter.mInstance, aArgs[1], provisioningUrl, PACKAGE_NAME,
|
||||
error = otJoinerStart(mInterpreter.mInstance, aArgs[1].GetCString(), provisioningUrl, PACKAGE_NAME,
|
||||
OPENTHREAD_CONFIG_PLATFORM_INFO, PACKAGE_VERSION, nullptr, &Joiner::HandleCallback, this);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Joiner::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -135,14 +135,14 @@ otError Joiner::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Joiner::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength, aArgs);
|
||||
|
||||
+10
-7
@@ -39,6 +39,7 @@
|
||||
#include <openthread/joiner.h>
|
||||
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_JOINER_ENABLE
|
||||
|
||||
@@ -54,6 +55,8 @@ class Interpreter;
|
||||
class Joiner
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -72,20 +75,20 @@ public:
|
||||
* @param[in] aArgs A pointer to an array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (Joiner::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (Joiner::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessDiscerner(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, char *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[]);
|
||||
|
||||
static void HandleCallback(otError aError, void *aContext);
|
||||
void HandleCallback(otError aError);
|
||||
|
||||
@@ -38,10 +38,6 @@
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
using ot::Encoding::BigEndian::HostSwap16;
|
||||
using ot::Utils::CmdLineParser::ParseAsHexString;
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -205,7 +201,7 @@ void NetworkData::OutputService(const otServiceConfig &aConfig)
|
||||
mInterpreter.OutputLine(" %04x", aConfig.mServerConfig.mRloc16);
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError NetworkData::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -219,7 +215,7 @@ otError NetworkData::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError NetworkData::ProcessRegister(uint8_t aArgsLength, char *aArgs[])
|
||||
otError NetworkData::ProcessRegister(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -237,13 +233,13 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
otError NetworkData::ProcessSteeringData(uint8_t aArgsLength, char *aArgs[])
|
||||
otError NetworkData::ProcessSteeringData(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
otExtAddress addr;
|
||||
otJoinerDiscerner discerner;
|
||||
|
||||
VerifyOrExit((aArgsLength > 1) && (strcmp(aArgs[0], "check") == 0));
|
||||
VerifyOrExit((aArgsLength > 1) && (aArgs[0] == "check"));
|
||||
|
||||
discerner.mLength = 0;
|
||||
|
||||
@@ -251,7 +247,7 @@ otError NetworkData::ProcessSteeringData(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (error == OT_ERROR_NOT_FOUND)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[1], addr.m8));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsHexString(addr.m8));
|
||||
}
|
||||
else if (error != OT_ERROR_NONE)
|
||||
{
|
||||
@@ -325,7 +321,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessShow(uint8_t aArgsLength, char *aArgs[])
|
||||
otError NetworkData::ProcessShow(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
|
||||
@@ -336,7 +332,7 @@ otError NetworkData::ProcessShow(uint8_t aArgsLength, char *aArgs[])
|
||||
OutputServices();
|
||||
error = OT_ERROR_NONE;
|
||||
}
|
||||
else if (strcmp(aArgs[0], "-x") == 0)
|
||||
else if (aArgs[0] == "-x")
|
||||
{
|
||||
error = OutputBinary();
|
||||
}
|
||||
@@ -348,14 +344,14 @@ otError NetworkData::ProcessShow(uint8_t aArgsLength, char *aArgs[])
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NetworkData::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError NetworkData::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <openthread/netdata.h>
|
||||
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -52,6 +53,8 @@ class Interpreter;
|
||||
class NetworkData
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -67,7 +70,7 @@ public:
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
/**
|
||||
* This method outputs the prefix config.
|
||||
@@ -97,15 +100,15 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (NetworkData::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (NetworkData::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError ProcessRegister(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessRegister(uint8_t aArgsLength, Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessShow(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSteeringData(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessShow(uint8_t aArgsLength, Arg aArgs[]);
|
||||
otError ProcessSteeringData(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
otError OutputBinary(void);
|
||||
void OutputPrefixes(void);
|
||||
|
||||
+41
-48
@@ -38,13 +38,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsBool;
|
||||
using ot::Utils::CmdLineParser::ParseAsHexString;
|
||||
using ot::Utils::CmdLineParser::ParseAsIp6Address;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint16;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint32;
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -73,14 +66,14 @@ SrpClient::SrpClient(Interpreter &aInterpreter)
|
||||
otSrpClientSetCallback(mInterpreter.mInstance, SrpClient::HandleCallback, this);
|
||||
}
|
||||
|
||||
otError SrpClient::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
@@ -91,7 +84,7 @@ exit:
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||
|
||||
otError SrpClient::ProcessAutoStart(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessAutoStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool enable;
|
||||
@@ -121,7 +114,7 @@ exit:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||
|
||||
otError SrpClient::ProcessCallback(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessCallback(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -138,7 +131,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -151,7 +144,7 @@ otError SrpClient::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -161,7 +154,7 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[0], "name") == 0)
|
||||
if (aArgs[0] == "name")
|
||||
{
|
||||
if (aArgsLength == 1)
|
||||
{
|
||||
@@ -170,14 +163,14 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t len;
|
||||
uint16_t len;
|
||||
uint16_t size;
|
||||
char * hostName;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
hostName = otSrpClientBuffersGetHostNameString(mInterpreter.mInstance, &size);
|
||||
|
||||
len = strlen(aArgs[1]);
|
||||
len = aArgs[1].GetLength();
|
||||
VerifyOrExit(len + 1 <= size, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// We first make sure we can set the name, and if so
|
||||
@@ -186,19 +179,19 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
// This ensures that we do not overwrite a previous
|
||||
// buffer with a host name that cannot be set.
|
||||
|
||||
SuccessOrExit(error = otSrpClientSetHostName(mInterpreter.mInstance, aArgs[1]));
|
||||
memcpy(hostName, aArgs[1], len + 1);
|
||||
SuccessOrExit(error = otSrpClientSetHostName(mInterpreter.mInstance, aArgs[1].GetCString()));
|
||||
memcpy(hostName, aArgs[1].GetCString(), len + 1);
|
||||
|
||||
IgnoreError(otSrpClientSetHostName(mInterpreter.mInstance, hostName));
|
||||
}
|
||||
}
|
||||
else if (strcmp(aArgs[0], "state") == 0)
|
||||
else if (aArgs[0] == "state")
|
||||
{
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
mInterpreter.OutputLine("%s",
|
||||
otSrpClientItemStateToString(otSrpClientGetHostInfo(mInterpreter.mInstance)->mState));
|
||||
}
|
||||
else if (strcmp(aArgs[0], "address") == 0)
|
||||
else if (aArgs[0] == "address")
|
||||
{
|
||||
if (aArgsLength == 1)
|
||||
{
|
||||
@@ -229,7 +222,7 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
for (uint8_t index = 1; index < aArgsLength; index++)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[index], addresses[index - 1]));
|
||||
SuccessOrExit(error = aArgs[index].ParseAsIp6Address(addresses[index - 1]));
|
||||
}
|
||||
|
||||
SuccessOrExit(error = otSrpClientSetHostAddresses(mInterpreter.mInstance, addresses, numAddresses));
|
||||
@@ -238,19 +231,19 @@ otError SrpClient::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
IgnoreError(otSrpClientSetHostAddresses(mInterpreter.mInstance, hostAddressArray, numAddresses));
|
||||
}
|
||||
}
|
||||
else if (strcmp(aArgs[0], "remove") == 0)
|
||||
else if (aArgs[0] == "remove")
|
||||
{
|
||||
bool removeKeyLease = false;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = ParseAsBool(aArgs[1], removeKeyLease));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsBool(removeKeyLease));
|
||||
}
|
||||
|
||||
error = otSrpClientRemoveHostAndServices(mInterpreter.mInstance, removeKeyLease);
|
||||
}
|
||||
else if (strcmp(aArgs[0], "clear") == 0)
|
||||
else if (aArgs[0] == "clear")
|
||||
{
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
otSrpClientClearHostAndServices(mInterpreter.mInstance);
|
||||
@@ -265,7 +258,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessLeaseInterval(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessLeaseInterval(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint32_t interval;
|
||||
@@ -277,14 +270,14 @@ otError SrpClient::ProcessLeaseInterval(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[0], interval));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(interval));
|
||||
otSrpClientSetLeaseInterval(mInterpreter.mInstance, interval);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessKeyLeaseInterval(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessKeyLeaseInterval(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint32_t interval;
|
||||
@@ -296,14 +289,14 @@ otError SrpClient::ProcessKeyLeaseInterval(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[0], interval));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsUint32(interval));
|
||||
otSrpClientSetKeyLeaseInterval(mInterpreter.mInstance, interval);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessServer(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessServer(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otSockAddr *serverSockAddr = otSrpClientGetServerAddress(mInterpreter.mInstance);
|
||||
@@ -318,12 +311,12 @@ otError SrpClient::ProcessServer(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[0], "address") == 0)
|
||||
if (aArgs[0] == "address")
|
||||
{
|
||||
mInterpreter.OutputIp6Address(serverSockAddr->mAddress);
|
||||
mInterpreter.OutputLine("");
|
||||
}
|
||||
else if (strcmp(aArgs[0], "port") == 0)
|
||||
else if (aArgs[0] == "port")
|
||||
{
|
||||
mInterpreter.OutputLine("%u", serverSockAddr->mPort);
|
||||
}
|
||||
@@ -336,7 +329,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessService(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -346,11 +339,11 @@ otError SrpClient::ProcessService(uint8_t aArgsLength, char *aArgs[])
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[0], "add") == 0)
|
||||
if (aArgs[0] == "add")
|
||||
{
|
||||
error = ProcessServiceAdd(aArgsLength, aArgs);
|
||||
}
|
||||
else if (strcmp(aArgs[0], "remove") == 0)
|
||||
else if (aArgs[0] == "remove")
|
||||
{
|
||||
// `remove` <instance-name> <service-name>
|
||||
|
||||
@@ -360,7 +353,7 @@ otError SrpClient::ProcessService(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
for (service = otSrpClientGetServices(mInterpreter.mInstance); service != nullptr; service = service->mNext)
|
||||
{
|
||||
if ((strcmp(aArgs[1], service->mInstanceName) == 0) && (strcmp(aArgs[2], service->mName) == 0))
|
||||
if ((aArgs[1] == service->mInstanceName) && (aArgs[2] == service->mName))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -371,7 +364,7 @@ otError SrpClient::ProcessService(uint8_t aArgsLength, char *aArgs[])
|
||||
error = otSrpClientRemoveService(mInterpreter.mInstance, const_cast<otSrpClientService *>(service));
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
else if (strcmp(aArgs[0], "key") == 0)
|
||||
else if (aArgs[0] == "key")
|
||||
{
|
||||
// `key [enable/disable]`
|
||||
|
||||
@@ -397,7 +390,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
// `add` <instance-name> <service-name> <port> [priority] [weight] [txt]
|
||||
|
||||
@@ -413,21 +406,21 @@ otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, char *aArgs[])
|
||||
VerifyOrExit(entry != nullptr, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
string = otSrpClientBuffersGetServiceEntryInstanceNameString(entry, &size);
|
||||
SuccessOrExit(error = CopyString(string, size, aArgs[1]));
|
||||
SuccessOrExit(error = CopyString(string, size, aArgs[1].GetCString()));
|
||||
|
||||
string = otSrpClientBuffersGetServiceEntryServiceNameString(entry, &size);
|
||||
SuccessOrExit(error = CopyString(string, size, aArgs[2]));
|
||||
SuccessOrExit(error = CopyString(string, size, aArgs[2].GetCString()));
|
||||
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[3], entry->mService.mPort));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint16(entry->mService.mPort));
|
||||
|
||||
if (aArgsLength >= 5)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[4], entry->mService.mPriority));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint16(entry->mService.mPriority));
|
||||
}
|
||||
|
||||
if (aArgsLength >= 6)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[5], entry->mService.mWeight));
|
||||
SuccessOrExit(error = aArgs[5].ParseAsUint16(entry->mService.mWeight));
|
||||
}
|
||||
|
||||
if (aArgsLength >= 7)
|
||||
@@ -437,7 +430,7 @@ otError SrpClient::ProcessServiceAdd(uint8_t aArgsLength, char *aArgs[])
|
||||
txtBuffer = otSrpClientBuffersGetServiceEntryTxtBuffer(entry, &size);
|
||||
entry->mTxtEntry.mValueLength = size;
|
||||
|
||||
SuccessOrExit(error = ParseAsHexString(aArgs[6], entry->mTxtEntry.mValueLength, txtBuffer));
|
||||
SuccessOrExit(error = aArgs[6].ParseAsHexString(entry->mTxtEntry.mValueLength, txtBuffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -501,15 +494,15 @@ void SrpClient::OutputService(uint8_t aIndentSize, const otSrpClientService &aSe
|
||||
aService.mPort, aService.mPriority, aService.mWeight);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessStart(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessStart(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otSockAddr serverSockAddr;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[0], serverSockAddr.mAddress));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[1], serverSockAddr.mPort));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(serverSockAddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(serverSockAddr.mPort));
|
||||
|
||||
error = otSrpClientStart(mInterpreter.mInstance, &serverSockAddr);
|
||||
|
||||
@@ -517,7 +510,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessState(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessState(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -531,7 +524,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessStop(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpClient::ProcessStop(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
|
||||
+17
-14
@@ -41,6 +41,7 @@
|
||||
|
||||
#include "cli/cli_config.h"
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
|
||||
|
||||
@@ -56,6 +57,8 @@ class Interpreter;
|
||||
class SrpClient
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -71,7 +74,7 @@ public:
|
||||
* @param[in] aArgs A pointer to an array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
enum : uint8_t
|
||||
@@ -83,21 +86,21 @@ private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (SrpClient::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (SrpClient::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessAutoStart(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessCallback(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHost(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLeaseInterval(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessKeyLeaseInterval(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessServer(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessService(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessServiceAdd(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStart(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessState(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessStop(uint8_t aArgsLength, char *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[]);
|
||||
|
||||
void OutputHostInfo(uint8_t aIndentSize, const otSrpClientHostInfo &aHostInfo);
|
||||
void OutputServiceList(uint8_t aIndentSize, const otSrpClientService *aServices);
|
||||
|
||||
+14
-15
@@ -37,7 +37,6 @@
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "common/string.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
|
||||
@@ -46,14 +45,14 @@ namespace Cli {
|
||||
|
||||
constexpr SrpServer::Command SrpServer::sCommands[];
|
||||
|
||||
otError SrpServer::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength, aArgs);
|
||||
@@ -62,13 +61,13 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessDomain(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessDomain(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (aArgsLength > 1)
|
||||
{
|
||||
SuccessOrExit(error = otSrpServerSetDomain(mInterpreter.mInstance, aArgs[1]));
|
||||
SuccessOrExit(error = otSrpServerSetDomain(mInterpreter.mInstance, aArgs[1].GetCString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,7 +78,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessEnable(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessEnable(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -89,7 +88,7 @@ otError SrpServer::ProcessEnable(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessDisable(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessDisable(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -99,7 +98,7 @@ otError SrpServer::ProcessDisable(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessLease(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessLease(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint32_t minLease;
|
||||
@@ -108,10 +107,10 @@ otError SrpServer::ProcessLease(uint8_t aArgsLength, char *aArgs[])
|
||||
uint32_t maxKeyLease;
|
||||
|
||||
VerifyOrExit(aArgsLength == 5, error = OT_ERROR_INVALID_ARGS);
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseAsUint32(aArgs[1], minLease));
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseAsUint32(aArgs[2], maxLease));
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseAsUint32(aArgs[3], minKeyLease));
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseAsUint32(aArgs[4], maxKeyLease));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint32(minLease));
|
||||
SuccessOrExit(error = aArgs[2].ParseAsUint32(maxLease));
|
||||
SuccessOrExit(error = aArgs[3].ParseAsUint32(minKeyLease));
|
||||
SuccessOrExit(error = aArgs[4].ParseAsUint32(maxKeyLease));
|
||||
|
||||
error = otSrpServerSetLeaseRange(mInterpreter.mInstance, minLease, maxLease, minKeyLease, maxKeyLease);
|
||||
|
||||
@@ -119,7 +118,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessHost(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessHost(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -183,7 +182,7 @@ void SrpServer::OutputHostAddresses(const otSrpServerHost *aHost)
|
||||
mInterpreter.OutputFormat("]");
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessService(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessService(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -231,7 +230,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpServer::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError SrpServer::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <openthread/srp_server.h>
|
||||
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
|
||||
@@ -54,6 +55,8 @@ class Interpreter;
|
||||
class SrpServer
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -75,22 +78,22 @@ public:
|
||||
* @retval ... Failed to execute the CLI command.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (SrpServer::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (SrpServer::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
otError ProcessDomain(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessEnable(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessDisable(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLease(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHost(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessService(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *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[]);
|
||||
|
||||
void OutputHostAddresses(const otSrpServerHost *aHost);
|
||||
|
||||
|
||||
+22
-27
@@ -38,11 +38,6 @@
|
||||
|
||||
#include "cli/cli.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsHexString;
|
||||
using ot::Utils::CmdLineParser::ParseAsIp6Address;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint16;
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -56,7 +51,7 @@ UdpExample::UdpExample(Interpreter &aInterpreter)
|
||||
memset(&mSocket, 0, sizeof(mSocket));
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessHelp(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -69,15 +64,15 @@ otError UdpExample::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessBind(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessBind(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otSockAddr sockaddr;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[0], sockaddr.mAddress));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[1], sockaddr.mPort));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(sockaddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(sockaddr.mPort));
|
||||
|
||||
error = otUdpBind(mInterpreter.mInstance, &mSocket, &sockaddr);
|
||||
|
||||
@@ -85,15 +80,15 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessConnect(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessConnect(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otSockAddr sockaddr;
|
||||
|
||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[0], sockaddr.mAddress));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[1], sockaddr.mPort));
|
||||
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(sockaddr.mAddress));
|
||||
SuccessOrExit(error = aArgs[1].ParseAsUint16(sockaddr.mPort));
|
||||
|
||||
error = otUdpConnect(mInterpreter.mInstance, &mSocket, &sockaddr);
|
||||
|
||||
@@ -101,7 +96,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessClose(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessClose(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -109,7 +104,7 @@ otError UdpExample::ProcessClose(uint8_t aArgsLength, char *aArgs[])
|
||||
return otUdpClose(mInterpreter.mInstance, &mSocket);
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessOpen(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessOpen(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
@@ -117,7 +112,7 @@ otError UdpExample::ProcessOpen(uint8_t aArgsLength, char *aArgs[])
|
||||
return otUdpOpen(mInterpreter.mInstance, &mSocket, HandleUdpReceive, this);
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessSend(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otMessageInfo messageInfo;
|
||||
@@ -133,25 +128,25 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
|
||||
|
||||
if (aArgsLength > 2)
|
||||
{
|
||||
SuccessOrExit(error = ParseAsIp6Address(aArgs[curArg++], messageInfo.mPeerAddr));
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[curArg++], messageInfo.mPeerPort));
|
||||
SuccessOrExit(error = aArgs[curArg++].ParseAsIp6Address(messageInfo.mPeerAddr));
|
||||
SuccessOrExit(error = aArgs[curArg++].ParseAsUint16(messageInfo.mPeerPort));
|
||||
}
|
||||
|
||||
if (aArgsLength == 2 || aArgsLength == 4)
|
||||
{
|
||||
uint8_t typePos = curArg++;
|
||||
|
||||
if (strcmp(aArgs[typePos], "-s") == 0)
|
||||
if (aArgs[typePos] == "-s")
|
||||
{
|
||||
payloadType = kTypeAutoSize;
|
||||
SuccessOrExit(error = ParseAsUint16(aArgs[curArg], payloadLength));
|
||||
SuccessOrExit(error = aArgs[curArg].ParseAsUint16(payloadLength));
|
||||
}
|
||||
else if (strcmp(aArgs[typePos], "-x") == 0)
|
||||
else if (aArgs[typePos] == "-x")
|
||||
{
|
||||
payloadLength = static_cast<uint16_t>(strlen(aArgs[curArg]));
|
||||
payloadLength = aArgs[curArg].GetLength();
|
||||
payloadType = kTypeHexString;
|
||||
}
|
||||
else if (strcmp(aArgs[typePos], "-t") == 0)
|
||||
else if (aArgs[typePos] == "-t")
|
||||
{
|
||||
payloadType = kTypeText;
|
||||
}
|
||||
@@ -163,7 +158,7 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
|
||||
switch (payloadType)
|
||||
{
|
||||
case kTypeText:
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[curArg], static_cast<uint16_t>(strlen(aArgs[curArg]))));
|
||||
SuccessOrExit(error = otMessageAppend(message, aArgs[curArg].GetCString(), aArgs[curArg].GetLength()));
|
||||
break;
|
||||
case kTypeAutoSize:
|
||||
SuccessOrExit(error = WriteCharToBuffer(message, payloadLength));
|
||||
@@ -173,7 +168,7 @@ otError UdpExample::ProcessSend(uint8_t aArgsLength, char *aArgs[])
|
||||
uint8_t buf[50];
|
||||
uint16_t bufLen;
|
||||
uint16_t conversionLength = 0;
|
||||
const char *hexString = aArgs[curArg];
|
||||
const char *hexString = aArgs[curArg].GetCString();
|
||||
|
||||
while (payloadLength > 0)
|
||||
{
|
||||
@@ -208,7 +203,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::ProcessLinkSecurity(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -252,14 +247,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError UdpExample::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
otError UdpExample::Process(uint8_t aArgsLength, Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
VerifyOrExit(aArgsLength != 0, IgnoreError(ProcessHelp(0, nullptr)));
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
|
||||
+12
-9
@@ -39,6 +39,7 @@
|
||||
#include <openthread/udp.h>
|
||||
|
||||
#include "utils/lookup_table.hpp"
|
||||
#include "utils/parse_cmdline.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
@@ -52,6 +53,8 @@ class Interpreter;
|
||||
class UdpExample
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -67,13 +70,13 @@ public:
|
||||
* @param[in] aArgs An array of command line arguments.
|
||||
*
|
||||
*/
|
||||
otError Process(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError Process(uint8_t aArgsLength, Arg aArgs[]);
|
||||
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
otError (UdpExample::*mHandler)(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError (UdpExample::*mHandler)(uint8_t aArgsLength, Arg aArgs[]);
|
||||
};
|
||||
|
||||
enum PayloadType
|
||||
@@ -83,13 +86,13 @@ private:
|
||||
kTypeHexString = 2,
|
||||
};
|
||||
|
||||
otError ProcessHelp(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessBind(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessClose(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessConnect(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessOpen(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessSend(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLinkSecurity(uint8_t aArgsLength, char *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 WriteCharToBuffer(otMessage *aMessage, uint16_t aMessageSize);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
@@ -515,23 +515,35 @@ Error Diags::ParseLong(char *aString, long &aLong)
|
||||
return (*endptr == '\0') ? kErrorNone : kErrorParse;
|
||||
}
|
||||
|
||||
Error Diags::ParseCmd(char *aString, uint8_t &aArgsLength, char *aArgs[])
|
||||
{
|
||||
Error error;
|
||||
Utils::CmdLineParser::Arg args[kMaxArgs];
|
||||
|
||||
SuccessOrExit(error = Utils::CmdLineParser::ParseCmd(aString, aArgsLength, args, aArgsLength));
|
||||
Utils::CmdLineParser::Arg::CopyArgsToStringArray(args, aArgsLength, aArgs);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Diags::ProcessLine(const char *aString, char *aOutput, size_t aOutputMaxLen)
|
||||
{
|
||||
enum
|
||||
{
|
||||
kMaxArgs = OPENTHREAD_CONFIG_DIAG_CMD_LINE_ARGS_MAX,
|
||||
kMaxCommandBuffer = OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE,
|
||||
};
|
||||
|
||||
Error error = kErrorNone;
|
||||
char buffer[kMaxCommandBuffer];
|
||||
char * aArgsector[kMaxArgs];
|
||||
char * args[kMaxArgs];
|
||||
uint8_t argCount = 0;
|
||||
|
||||
VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = kErrorNoBufs);
|
||||
|
||||
strcpy(buffer, aString);
|
||||
error = ot::Utils::CmdLineParser::ParseCmd(buffer, argCount, aArgsector, kMaxArgs);
|
||||
argCount = kMaxArgs;
|
||||
error = ParseCmd(buffer, argCount, args);
|
||||
|
||||
exit:
|
||||
|
||||
@@ -539,7 +551,7 @@ exit:
|
||||
{
|
||||
case kErrorNone:
|
||||
aOutput[0] = '\0'; // In case there is no output.
|
||||
IgnoreError(ProcessCmd(argCount, &aArgsector[0], aOutput, aOutputMaxLen));
|
||||
IgnoreError(ProcessCmd(argCount, &args[0], aOutput, aOutputMaxLen));
|
||||
break;
|
||||
|
||||
case kErrorNoBufs:
|
||||
|
||||
@@ -122,6 +122,11 @@ public:
|
||||
void TransmitDone(Error aError);
|
||||
|
||||
private:
|
||||
enum : uint8_t
|
||||
{
|
||||
kMaxArgs = OPENTHREAD_CONFIG_DIAG_CMD_LINE_ARGS_MAX,
|
||||
};
|
||||
|
||||
struct Command
|
||||
{
|
||||
const char *mName;
|
||||
@@ -140,6 +145,7 @@ private:
|
||||
uint8_t mLastLqi;
|
||||
};
|
||||
|
||||
Error ParseCmd(char *aString, uint8_t &aArgsLength, char *aArgs[]);
|
||||
Error ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||
Error ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||
Error ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||
|
||||
@@ -84,7 +84,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error ParseCmd(char *aCommandString, uint8_t &aArgsLength, char *aArgs[], uint8_t aArgsLengthMax)
|
||||
Error ParseCmd(char *aCommandString, uint8_t &aArgsLength, Arg *aArgs, uint8_t aArgsLengthMax)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
char *cmd;
|
||||
@@ -106,7 +106,8 @@ Error ParseCmd(char *aCommandString, uint8_t &aArgsLength, char *aArgs[], uint8_
|
||||
if ((*cmd != '\0') && ((aArgsLength == 0) || (*(cmd - 1) == '\0')))
|
||||
{
|
||||
VerifyOrExit(aArgsLength < aArgsLengthMax, error = kErrorInvalidArgs);
|
||||
aArgs[aArgsLength++] = cmd;
|
||||
|
||||
aArgs[aArgsLength++].SetCString(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,6 +337,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Arg::CopyArgsToStringArray(Arg aArgs[], uint8_t aArgsLength, char *aStrings[])
|
||||
{
|
||||
for (uint8_t i = 0; i < aArgsLength; i++)
|
||||
{
|
||||
aStrings[i] = aArgs[i].GetCString();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CmdLineParser
|
||||
} // namespace Utils
|
||||
} // namespace ot
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#define PARSE_CMD_LINE_HPP_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openthread/error.h>
|
||||
#include <openthread/ip6.h>
|
||||
@@ -62,21 +63,6 @@ enum HexStringParseMode : uint8_t
|
||||
kAllowTruncate, // Allow truncation of hex string.
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
otError ParseCmd(char *aCommandString, uint8_t &aArgsLength, char *aArgs[], uint8_t aArgsLengthMax);
|
||||
|
||||
/**
|
||||
* This function parses a string as a `uint8_t` value.
|
||||
*
|
||||
@@ -172,7 +158,7 @@ otError ParseAsInt16(const char *aString, int16_t &aInt16);
|
||||
* @param[in] aString The string to parse.
|
||||
* @param[out] aInt32 A reference to an `int32_t` variable to output the parsed value.
|
||||
*
|
||||
* @retval kErrorNone The string was parsed successfully.
|
||||
* @retval kErrorNone The string was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The string does not contain valid number (e.g., value out of range).
|
||||
*
|
||||
*/
|
||||
@@ -181,7 +167,7 @@ otError ParseAsInt32(const char *aString, int32_t &aInt32);
|
||||
/**
|
||||
* This function parses a string as a `bool` value.
|
||||
*
|
||||
* Zero value is treated as `false, non-zero value as `true`.
|
||||
* Zero value is treated as `false`, non-zero value as `true`.
|
||||
*
|
||||
* @param[in] aString The string to parse.
|
||||
* @param[out] aBool A reference to a `bool` variable to output the parsed value.
|
||||
@@ -200,7 +186,7 @@ otError ParseAsBool(const char *aString, bool &aBool);
|
||||
* @param[in] aString The string to parse.
|
||||
* @param[out] aAddress A reference to an `otIp6Address` to output the parsed IPv6 address.
|
||||
*
|
||||
* @retval kErrorNone The string was parsed successfully.
|
||||
* @retval kErrorNone The string was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The string does not contain valid IPv6 address.
|
||||
*
|
||||
*/
|
||||
@@ -218,7 +204,7 @@ inline otError ParseAsIp6Address(const char *aString, otIp6Address &aAddress)
|
||||
* @param[out] aPrefix A reference to an `otIp6Prefix` to output the parsed IPv6 prefix.
|
||||
*
|
||||
* @retval kErrorNone The string was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The string does not contain valid IPv6 prefix
|
||||
* @retval kErrorInvalidArgs The string does not contain a valid IPv6 prefix.
|
||||
*
|
||||
*/
|
||||
otError ParseAsIp6Prefix(const char *aString, otIp6Prefix &aPrefix);
|
||||
@@ -284,6 +270,298 @@ otError ParseAsHexString(const char * aString,
|
||||
uint8_t * aBuffer,
|
||||
HexStringParseMode aMode = kDisallowTruncate);
|
||||
|
||||
/**
|
||||
* This class represents a single argument from an argument list.
|
||||
*
|
||||
*/
|
||||
class Arg
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns the length (number of characters) in the argument C string.
|
||||
*
|
||||
* @returns The argument string length.
|
||||
*
|
||||
*/
|
||||
uint16_t GetLength(void) const { return static_cast<uint16_t>(strlen(mString)); }
|
||||
|
||||
/**
|
||||
* This method gets the argument as a C string.
|
||||
*
|
||||
* @returns A pointer to the argument as a C string.
|
||||
*
|
||||
*/
|
||||
const char *GetCString(void) const { return mString; }
|
||||
|
||||
/**
|
||||
* This method gets the argument as C string.
|
||||
*
|
||||
* @returns A pointer to the argument as a C string.
|
||||
*
|
||||
*/
|
||||
char *GetCString(void) { return mString; }
|
||||
|
||||
/**
|
||||
* This method sets the argument with a given C string.
|
||||
*
|
||||
* @param[in] aString A pointer to the new C string.
|
||||
*
|
||||
*/
|
||||
void SetCString(char *aString) { mString = aString; }
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @retval TRUE If the argument is equal to @p aString.
|
||||
* @retval FALSE If the argument is not equal to @p aString.
|
||||
*
|
||||
*/
|
||||
bool operator==(const char *aString) const { return (strcmp(mString, aString) == 0); }
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @retval TRUE If the argument is not equal to @p aString.
|
||||
* @retval FALSE If the argument is equal to @p aString.
|
||||
*
|
||||
*/
|
||||
bool operator!=(const char *aString) const { return !(*this == aString); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `uint8_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix).
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint8(uint8_t &aUint8) const { return CmdLineParser::ParseAsUint8(mString, aUint8); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `uint16_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix).
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint16(uint16_t &aUint16) const { return CmdLineParser::ParseAsUint16(mString, aUint16); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `uint32_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix).
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint32(uint32_t &aUint32) const { return CmdLineParser::ParseAsUint32(mString, aUint32); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `uint64_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix).
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsUint64(uint64_t &aUint64) const { return CmdLineParser::ParseAsUint64(mString, aUint64); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `int8_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix). The string can start with
|
||||
* `+`/`-` sign.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsInt8(int8_t &aInt8) const { return CmdLineParser::ParseAsInt8(mString, aInt8); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `int16_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix). The string can start with
|
||||
* `+`/`-` sign.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsInt16(int16_t &aInt16) const { return CmdLineParser::ParseAsInt16(mString, aInt16); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `int32_t` value.
|
||||
*
|
||||
* The number is parsed as decimal or hex format (if contains `0x` or `0X` prefix). The string can start with
|
||||
* `+`/`-` sign.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
*/
|
||||
otError ParseAsInt32(int32_t &aInt32) const { return CmdLineParser::ParseAsInt32(mString, aInt32); }
|
||||
|
||||
/**
|
||||
* This method parses the argument as a `bool` value.
|
||||
*
|
||||
* Zero value is treated as `false`, non-zero value as `true`.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
otError ParseAsBool(bool &aBool) const { return CmdLineParser::ParseAsBool(mString, aBool); }
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
/**
|
||||
* This method parses the argument as an IPv6 address.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
otError ParseAsIp6Address(otIp6Address &aAddress) const
|
||||
{
|
||||
return CmdLineParser::ParseAsIp6Address(mString, aAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the argument as an IPv6 prefix.
|
||||
*
|
||||
* The string is parsed as `{IPv6Address}/{PrefixLength}`.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
otError ParseAsIp6Prefix(otIp6Prefix &aPrefix) const { return CmdLineParser::ParseAsIp6Prefix(mString, aPrefix); }
|
||||
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
|
||||
/**
|
||||
* This method parses the argument as a hex string into a byte array of fixed expected size.
|
||||
*
|
||||
* This method returns `kErrorNone` only when the hex string contains exactly @p aSize bytes (after parsing). If
|
||||
* there are fewer or more bytes in hex string that @p aSize, the parsed bytes (up to @p aSize) are copied into the
|
||||
* `aBuffer` and `kErrorInvalidArgs` is returned.
|
||||
*
|
||||
* @param[out] aBuffer A pointer to a buffer to output the parsed byte sequence.
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
otError ParseAsHexString(uint8_t *aBuffer, uint16_t aSize) const
|
||||
{
|
||||
return CmdLineParser::ParseAsHexString(mString, aBuffer, aSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* This template method parses the argument as a hex string into a a given fixed size array.
|
||||
*
|
||||
* This method returns `kErrorNone` only when the hex string contains exactly @p kBufferSize bytes (after parsing).
|
||||
* If there are fewer or more bytes in hex string that @p kBufferSize, the parsed bytes (up to @p kBufferSize) are
|
||||
* copied into the `aBuffer` and `kErrorInvalidArgs` is returned.
|
||||
*
|
||||
* @tparam kBufferSize The byte array size (number of bytes).
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
template <uint16_t kBufferSize> otError ParseAsHexString(uint8_t (&aBuffer)[kBufferSize])
|
||||
{
|
||||
return ParseAsHexString(aBuffer, kBufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the argument as a hex string into a byte array.
|
||||
*
|
||||
* If @p aMode disallows truncation (`kDisallowTruncate`), this method verifies that parses hex string bytes fit in
|
||||
* @p aBuffer with its given size in @aSize. Otherwise when @p aMode allows truncation, extra bytes after @p aSize
|
||||
* bytes are ignored.
|
||||
*
|
||||
* @param[inout] aSize On entry indicates the number of bytes in @p aBuffer (max size of @p aBuffer).
|
||||
* On exit provides number of bytes parsed and copied into @p aBuffer
|
||||
* @param[out] aBuffer A pointer to a buffer to output the parsed byte sequence.
|
||||
* @param[in] aMode Indicates parsing mode whether to allow truncation or not.
|
||||
*
|
||||
* @retval kErrorNone The argument was parsed successfully.
|
||||
* @retval kErrorInvalidArgs The argument does not contain valid format or too many bytes (if truncation not
|
||||
* allowed)
|
||||
*
|
||||
*/
|
||||
otError ParseAsHexString(uint16_t &aSize, uint8_t *aBuffer, HexStringParseMode aMode = kDisallowTruncate)
|
||||
{
|
||||
return CmdLineParser::ParseAsHexString(mString, aSize, aBuffer, aMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* This static method copies the argument string pointers from an `Arg` array to a C string array.
|
||||
*
|
||||
* @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[out] aStrings An `char *` array to populate with the argument string pointers. The @p aString array
|
||||
* MUST contain at least @p aArgsLength entries.
|
||||
*
|
||||
*/
|
||||
static void CopyArgsToStringArray(Arg aArgs[], uint8_t aArgsLength, char *aStrings[]);
|
||||
|
||||
private:
|
||||
char *mString;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
otError ParseCmd(char *aCommandString, uint8_t &aArgsLength, Arg aArgs[], uint8_t aArgsLengthMax);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user