diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 500291c17..6669f202d 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (109) +#define OPENTHREAD_API_VERSION (110) /** * @addtogroup api-instance diff --git a/include/openthread/platform/misc.h b/include/openthread/platform/misc.h index a5d5e4479..99c3ed3f5 100644 --- a/include/openthread/platform/misc.h +++ b/include/openthread/platform/misc.h @@ -198,21 +198,6 @@ otPlatMcuPowerState otPlatGetMcuPowerState(otInstance *aInstance); * */ -#if defined(OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE) && OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE -/** - * This function gets the name and index of the platform's network interface (if it exists). - * - * @param[in] aInstance A pointer to OpenThread instance. - * @param[out] outNetIfName A pointer for the returned network interface name. - * @param[out] outNetIfIndex A pointer for the returned network interface index (i.e., if_nametoindex). - * - * @retval OT_ERROR_NONE Successfully returned the network interface and index. - * @retval OT_ERROR_FAILED The network interface is not enabled or is unknown. - * - */ -otError otPlatGetNetif(otInstance *aInstance, const char **outNetIfName, unsigned int *outNetIfIndex); -#endif - #ifdef __cplusplus } // extern "C" #endif diff --git a/script/check-posix-pty b/script/check-posix-pty index 87ba93d3f..12be11f41 100755 --- a/script/check-posix-pty +++ b/script/check-posix-pty @@ -146,9 +146,6 @@ spawn ${OT_CLI_CMD} expect_after { timeout { error } } -send "radiourl\r\n" -expect "${RADIO_URL}" -expect "Done" send "region\r\n" expect "US" expect "Done" diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 4caecd787..c2047f605 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2947,25 +2947,6 @@ exit: } #endif // OPENTHREAD_FTD -#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE -otError Interpreter::ProcessNetif(uint8_t aArgsLength, Arg aArgs[]) -{ - OT_UNUSED_VARIABLE(aArgsLength); - OT_UNUSED_VARIABLE(aArgs); - - otError error = OT_ERROR_NONE; - const char * netif = nullptr; - unsigned int netifidx = 0; - - SuccessOrExit(error = otPlatGetNetif(mInstance, &netif, &netifidx)); - - OutputLine("%s:%u", netif ? netif : "(null)", netifidx); - -exit: - return error; -} -#endif - otError Interpreter::ProcessNetstat(uint8_t aArgsLength, Arg aArgs[]) { otUdpSocket *socket = otUdpGetSockets(mInstance); @@ -4881,6 +4862,7 @@ void Interpreter::ProcessLine(char *aBuf) Arg args[kMaxArgs]; uint8_t argsLength; const Command *command; + otError error; VerifyOrExit(aBuf != nullptr && StringLength(aBuf, kMaxLineLength) <= kMaxLineLength - 1); @@ -4897,12 +4879,13 @@ void Interpreter::ProcessLine(char *aBuf) if (command != nullptr) { - OutputResult((this->*command->mHandler)(argsLength - 1, &args[1])); - ExitNow(); + error = (this->*command->mHandler)(argsLength - 1, &args[1]); } - - VerifyOrExit(ProcessUserCommands(argsLength, args) != OT_ERROR_NONE); - OutputResult(OT_ERROR_INVALID_COMMAND); + else + { + error = ProcessUserCommands(argsLength, args); + } + OutputResult(error); exit: return; @@ -4910,7 +4893,7 @@ exit: otError Interpreter::ProcessUserCommands(uint8_t aArgsLength, Arg aArgs[]) { - otError error = OT_ERROR_NOT_FOUND; + otError error = OT_ERROR_INVALID_COMMAND; for (uint8_t i = 0; i < mUserCommandsLength; i++) { diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 522d64031..378c6f655 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -472,9 +472,6 @@ private: void OutputRoute(const otExternalRouteConfig &aConfig); void OutputService(const otServiceConfig &aConfig); -#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE - otError ProcessNetif(uint8_t aArgsLength, Arg aArgs[]); -#endif otError ProcessNetstat(uint8_t aArgsLength, Arg aArgs[]); int OutputSocketAddress(const otSockAddr &aAddress); #if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE @@ -748,9 +745,6 @@ private: {"neighbor", &Interpreter::ProcessNeighbor}, #endif {"netdata", &Interpreter::ProcessNetworkData}, -#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE - {"netif", &Interpreter::ProcessNetif}, -#endif {"netstat", &Interpreter::ProcessNetstat}, #if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE {"networkdiagnostic", &Interpreter::ProcessNetworkDiagnostic}, diff --git a/src/posix/main.c b/src/posix/main.c index f84c5be34..e00ed2449 100644 --- a/src/posix/main.c +++ b/src/posix/main.c @@ -287,21 +287,6 @@ static void ParseArg(int aArgCount, char *aArgVector[], PosixConfig *aConfig) } } -static void PrintRadioUrl(void *aContext, uint8_t aArgsLength, char *aArgs[]) -{ - (void)aArgsLength; - (void)aArgs; - - uint8_t i; - - otPlatformConfig *config = (otPlatformConfig *)aContext; - for (i = 0; i < config->mRadioUrlNum; i++) - { - otCliOutputFormat("%s\r\n", config->mRadioUrls[i]); - } - otCliOutputFormat("Done\r\n"); -} - static otInstance *InitInstance(PosixConfig *aConfig) { otInstance *instance = NULL; @@ -347,12 +332,22 @@ void otPlatReset(otInstance *aInstance) assert(false); } +static void ProcessNetif(void *aContext, uint8_t aArgsLength, char *aArgs[]) +{ + OT_UNUSED_VARIABLE(aContext); + OT_UNUSED_VARIABLE(aArgsLength); + OT_UNUSED_VARIABLE(aArgs); + + otCliOutputFormat("%s:%u\r\n", otSysGetThreadNetifName(), otSysGetThreadNetifIndex()); +} + +static const otCliCommand kCommands[] = {{"netif", ProcessNetif}}; + int main(int argc, char *argv[]) { - otInstance * instance; - int rval = 0; - PosixConfig config; - otCliCommand radioUrlCommand = {"radiourl", PrintRadioUrl}; + otInstance *instance; + int rval = 0; + PosixConfig config; #ifdef __linux__ // Ensure we terminate this process if the @@ -377,7 +372,7 @@ int main(int argc, char *argv[]) #if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE otAppCliInit(instance); #endif - otCliSetUserCommands(&radioUrlCommand, 1, &config.mPlatformConfig); + otCliSetUserCommands(kCommands, OT_ARRAY_LENGTH(kCommands), instance); while (true) { diff --git a/src/posix/platform/include/openthread/openthread-system.h b/src/posix/platform/include/openthread/openthread-system.h index b1c2feaaf..739e6659e 100644 --- a/src/posix/platform/include/openthread/openthread-system.h +++ b/src/posix/platform/include/openthread/openthread-system.h @@ -156,6 +156,22 @@ const char *otSysGetRadioUrlHelpString(void); extern otPlatResetReason gPlatResetReason; +/** + * This method returns the Thread network interface name. + * + * @returns The Thread network interface name. + * + */ +const char *otSysGetThreadNetifName(void); + +/** + * This method returns the Thread network interface index. + * + * @returns The Thread network interface index. + * + */ +unsigned int otSysGetThreadNetifIndex(void); + #ifdef __cplusplus } // end of extern "C" #endif diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 43e356ffd..6fd6f04e7 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -150,6 +150,16 @@ extern int unsigned int gNetifIndex = 0; char gNetifName[IFNAMSIZ]; +const char *otSysGetThreadNetifName(void) +{ + return gNetifName; +} + +unsigned int otSysGetThreadNetifIndex(void) +{ + return gNetifIndex; +} + #if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE #include "posix/platform/ip6_utils.hpp" @@ -1567,20 +1577,4 @@ exit: return; } -otError otPlatGetNetif(otInstance *aInstance, const char **outNetIfName, unsigned int *outNetIfIndex) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error; - - VerifyOrExit(gNetifIndex != 0, error = OT_ERROR_FAILED); - - *outNetIfName = gNetifName; - *outNetIfIndex = gNetifIndex; - error = OT_ERROR_NONE; - -exit: - - return error; -} #endif // OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE