[cli] move netif command to posix platform (#6557)

This commit is contained in:
Yakun Xu
2021-05-07 01:47:14 +08:00
committed by GitHub
parent df2880bf9f
commit 394739f3d8
8 changed files with 50 additions and 86 deletions
+1 -1
View File
@@ -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
-15
View File
@@ -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
-3
View File
@@ -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"
+8 -25
View File
@@ -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++)
{
-6
View File
@@ -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},
+15 -20
View File
@@ -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)
{
@@ -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
+10 -16
View File
@@ -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