mirror of
https://github.com/espressif/openthread.git
synced 2026-06-06 05:24:51 +00:00
[cli] add command for getting the network interface name and index (#4985)
* add a CLI command for getting the network interface name and index
On some platform (mostly BSDs), we do not have the option to specify
the tunnel name, although most of those platforms do have a way to dynamically
obtain a unique interface name if desired. Add a CLI command -- only enabled
on platforms that have PLATFORM_NETIF enabled -- that will return the
name of the tunnel interface, as well as it's index. Both are useful in doing
automated tests on non-Linux systems.
* remove OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE from the "check" scripts
This option really only applies to the POSIX "management" applications
(ot-daemon, ot-ctl), and not to the core radio or simulation component
builds (ot-cli, etc).
My other change adds a command ("netif") that is only useful when the
netif code is enabled, and that only happens when the netif code is linked,
which is only in those "management" utilities. Turning this setting off
allows the tests to pass, with no impact to the functionality previously
tested. But if this setting remains on, then my new code creates a
dependency that cannot be resolved outside the management applications.
This commit is contained in:
@@ -198,6 +198,21 @@ 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
|
||||
|
||||
@@ -68,7 +68,6 @@ do_scan_build()
|
||||
"-DOPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_MPL_DYNAMIC_INTERVAL_ENABLE"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE=1"
|
||||
|
||||
@@ -74,7 +74,6 @@ build_all_features()
|
||||
"-DOPENTHREAD_CONFIG_MPL_DYNAMIC_INTERVAL_ENABLE"
|
||||
"-DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE=1"
|
||||
|
||||
@@ -63,6 +63,9 @@
|
||||
#include <openthread/icmp6.h>
|
||||
#include <openthread/logging.h>
|
||||
#include <openthread/platform/uart.h>
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
|
||||
#include <openthread/platform/misc.h>
|
||||
#endif
|
||||
|
||||
#include "common/new.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -184,6 +187,9 @@ const struct Command Interpreter::sCommands[] = {
|
||||
{"netdataregister", &Interpreter::ProcessNetworkDataRegister},
|
||||
#endif
|
||||
{"netdatashow", &Interpreter::ProcessNetworkDataShow},
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
|
||||
{"netif", &Interpreter::ProcessNetif},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
{"networkdiagnostic", &Interpreter::ProcessNetworkDiagnostic},
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
@@ -1985,6 +1991,25 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
|
||||
void Interpreter::ProcessNetif(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
const char * netif = NULL;
|
||||
unsigned int netifidx = 0;
|
||||
|
||||
SuccessOrExit(error = otPlatGetNetif(mInstance, &netif, &netifidx));
|
||||
|
||||
mServer->OutputFormat("%s:%u\r\n", netif ? netif : "<NULL>", netifidx);
|
||||
|
||||
exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
void Interpreter::ProcessService(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
|
||||
@@ -285,6 +285,9 @@ private:
|
||||
void ProcessNetworkDataRegister(uint8_t aArgsLength, char *aArgs[]);
|
||||
#endif
|
||||
void ProcessNetworkDataShow(uint8_t aArgsLength, char *aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
|
||||
void ProcessNetif(uint8_t aArgsLength, char *aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
void ProcessService(uint8_t aArgsLength, char *aArgs[]);
|
||||
#endif
|
||||
|
||||
@@ -141,6 +141,7 @@ extern int
|
||||
#include <openthread/instance.h>
|
||||
#include <openthread/ip6.h>
|
||||
#include <openthread/message.h>
|
||||
#include <openthread/platform/misc.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
@@ -1461,4 +1462,20 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
otError otPlatGetNetif(otInstance *aInstance, const char **outNetIfName, unsigned int *outNetIfIndex)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(sTunIndex != 0, error = OT_ERROR_FAILED);
|
||||
|
||||
*outNetIfName = sTunName;
|
||||
*outNetIfIndex = sTunIndex;
|
||||
error = OT_ERROR_NONE;
|
||||
|
||||
exit:
|
||||
|
||||
return error;
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
|
||||
|
||||
Reference in New Issue
Block a user