mirror of
https://github.com/espressif/openthread.git
synced 2026-09-14 05:00:11 +00:00
[posix-app] get RCP (NCP in radio mode) version (#3140)
This commit contains the following changes: - It adds `otPlatRadioGetVersionString()` as an optional radio platform API. If the radio platform does not implement this function, OpenThread core provides a default weak implementation of this function which return the OpenThread version. - A public OpenThread API `otGetRadioVersionString()` is added which provides the radio version string. - POSIX App is updated to get the version from its RCP and provide `otPlatRadioGetVersionString()` - A new spinel capability `SPINEL_CAP_POSIX_APP` is added which corresponds to `ENABLE_POSIX_APP` configuration. - A new spinel property `SPINEL_PROP_RCP_VERSION` (only available in POSIX_APP) is added which gets the RCP version.
This commit is contained in:
committed by
Jonathan Hui
parent
2457aa1864
commit
7c8a37263b
@@ -379,13 +379,23 @@ otLogLevel otGetDynamicLogLevel(otInstance *aInstance);
|
|||||||
otError otSetDynamicLogLevel(otInstance *aInstance, otLogLevel aLogLevel);
|
otError otSetDynamicLogLevel(otInstance *aInstance, otLogLevel aLogLevel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the OpenThread version string.
|
* This function gets the OpenThread version string.
|
||||||
*
|
*
|
||||||
* @returns A pointer to the OpenThread version.
|
* @returns A pointer to the OpenThread version.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
OTAPI const char *OTCALL otGetVersionString(void);
|
OTAPI const char *OTCALL otGetVersionString(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function gets the OpenThread radio version string.
|
||||||
|
*
|
||||||
|
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||||
|
*
|
||||||
|
* @returns A pointer to the OpenThread radio version.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const char *otGetRadioVersionString(otInstance *aInstance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -634,6 +634,19 @@ int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance);
|
|||||||
*/
|
*/
|
||||||
extern void otPlatRadioFrameUpdated(otInstance *aInstance, otRadioFrame *aFrame);
|
extern void otPlatRadioFrameUpdated(otInstance *aInstance, otRadioFrame *aFrame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the radio version string.
|
||||||
|
*
|
||||||
|
* This is an optional radio driver platform function. If not provided by platform radio driver, OpenThread uses
|
||||||
|
* the OpenThread version instead (@sa otGetVersionString()).
|
||||||
|
*
|
||||||
|
* @param[in] aInstance The OpenThread instance structure.
|
||||||
|
*
|
||||||
|
* @returns A pointer to the OpenThread radio version.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const char *otPlatRadioGetVersionString(otInstance *aInstance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <openthread/instance.h>
|
#include <openthread/instance.h>
|
||||||
#include <openthread/platform/misc.h>
|
#include <openthread/platform/misc.h>
|
||||||
|
#include <openthread/platform/radio.h>
|
||||||
|
|
||||||
#include "common/instance.hpp"
|
#include "common/instance.hpp"
|
||||||
#include "common/logging.hpp"
|
#include "common/logging.hpp"
|
||||||
@@ -183,3 +184,14 @@ const char *otGetVersionString(void)
|
|||||||
|
|
||||||
return sVersion;
|
return sVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *otGetRadioVersionString(otInstance *aInstance)
|
||||||
|
{
|
||||||
|
return otPlatRadioGetVersionString(aInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
OT_TOOL_WEAK const char *otPlatRadioGetVersionString(otInstance *aInstance)
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(aInstance);
|
||||||
|
return otGetVersionString();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1774,6 +1774,10 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CAPS>(void)
|
|||||||
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_MAC_RAW));
|
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_MAC_RAW));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if OPENTHREAD_ENABLE_POSIX_APP
|
||||||
|
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_POSIX_APP));
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||||
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_OPENTHREAD_LOG_METADATA));
|
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_OPENTHREAD_LOG_METADATA));
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -500,6 +500,11 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
|
|||||||
handler = &NcpBase::HandlePropertyGet<SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT>;
|
handler = &NcpBase::HandlePropertyGet<SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT>;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#if OPENTHREAD_ENABLE_POSIX_APP
|
||||||
|
case SPINEL_PROP_RCP_VERSION:
|
||||||
|
handler = &NcpBase::HandlePropertyGet<SPINEL_PROP_RCP_VERSION>;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#endif // OPENTHREAD_MTD || OPENTHREAD_FTD
|
#endif // OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -614,7 +619,7 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
|
|||||||
#endif // OPENTHREAD_FTD
|
#endif // OPENTHREAD_FTD
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Raw Link API Properties (Get Handler)
|
// Raw Link or Radio Mode Properties (Get Handler)
|
||||||
|
|
||||||
#if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API
|
#if OPENTHREAD_RADIO || OPENTHREAD_ENABLE_RAW_LINK_API
|
||||||
case SPINEL_PROP_RADIO_CAPS:
|
case SPINEL_PROP_RADIO_CAPS:
|
||||||
|
|||||||
@@ -2484,6 +2484,15 @@ exit:
|
|||||||
|
|
||||||
#endif // OPENTHREAD_ENABLE_MAC_FILTER
|
#endif // OPENTHREAD_ENABLE_MAC_FILTER
|
||||||
|
|
||||||
|
#if OPENTHREAD_ENABLE_POSIX_APP
|
||||||
|
|
||||||
|
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_RCP_VERSION>(void)
|
||||||
|
{
|
||||||
|
return mEncoder.WriteUtf8(otGetRadioVersionString(mInstance));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // OPENTHREAD_ENABLE_POSIX_APP
|
||||||
|
|
||||||
#if OPENTHREAD_ENABLE_LEGACY
|
#if OPENTHREAD_ENABLE_LEGACY
|
||||||
|
|
||||||
void NcpBase::RegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers)
|
void NcpBase::RegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers)
|
||||||
|
|||||||
@@ -1838,6 +1838,10 @@ const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
|
|||||||
ret = "CHILD_SUPERVISION_CHECK_TIMEOUT";
|
ret = "CHILD_SUPERVISION_CHECK_TIMEOUT";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SPINEL_PROP_RCP_VERSION:
|
||||||
|
ret = "RCP_VERSION";
|
||||||
|
break;
|
||||||
|
|
||||||
case SPINEL_PROP_UART_BITRATE:
|
case SPINEL_PROP_UART_BITRATE:
|
||||||
ret = "UART_BITRATE";
|
ret = "UART_BITRATE";
|
||||||
break;
|
break;
|
||||||
@@ -2443,6 +2447,10 @@ const char *spinel_capability_to_cstr(unsigned int capability)
|
|||||||
ret = "CHILD_SUPERVISION";
|
ret = "CHILD_SUPERVISION";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SPINEL_CAP_POSIX_APP:
|
||||||
|
ret = "POSIX_APP";
|
||||||
|
break;
|
||||||
|
|
||||||
case SPINEL_CAP_ERROR_RATE_TRACKING:
|
case SPINEL_CAP_ERROR_RATE_TRACKING:
|
||||||
ret = "ERROR_RATE_TRACKING";
|
ret = "ERROR_RATE_TRACKING";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -477,6 +477,7 @@ enum
|
|||||||
SPINEL_CAP_OPENTHREAD_LOG_METADATA = (SPINEL_CAP_OPENTHREAD__BEGIN + 6),
|
SPINEL_CAP_OPENTHREAD_LOG_METADATA = (SPINEL_CAP_OPENTHREAD__BEGIN + 6),
|
||||||
SPINEL_CAP_TIME_SYNC = (SPINEL_CAP_OPENTHREAD__BEGIN + 7),
|
SPINEL_CAP_TIME_SYNC = (SPINEL_CAP_OPENTHREAD__BEGIN + 7),
|
||||||
SPINEL_CAP_CHILD_SUPERVISION = (SPINEL_CAP_OPENTHREAD__BEGIN + 8),
|
SPINEL_CAP_CHILD_SUPERVISION = (SPINEL_CAP_OPENTHREAD__BEGIN + 8),
|
||||||
|
SPINEL_CAP_POSIX_APP = (SPINEL_CAP_OPENTHREAD__BEGIN + 9),
|
||||||
SPINEL_CAP_OPENTHREAD__END = 640,
|
SPINEL_CAP_OPENTHREAD__END = 640,
|
||||||
|
|
||||||
SPINEL_CAP_THREAD__BEGIN = 1024,
|
SPINEL_CAP_THREAD__BEGIN = 1024,
|
||||||
@@ -2003,6 +2004,18 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT = SPINEL_PROP_OPENTHREAD__BEGIN + 11,
|
SPINEL_PROP_CHILD_SUPERVISION_CHECK_TIMEOUT = SPINEL_PROP_OPENTHREAD__BEGIN + 11,
|
||||||
|
|
||||||
|
// RCP (NCP in radio only mode) version
|
||||||
|
/** Format `U` - Read only
|
||||||
|
*
|
||||||
|
* Required capability: SPINEL_CAP_POSIX_APP
|
||||||
|
*
|
||||||
|
* This property gives the version string of RCP (NCP in radio mode) which is being controlled by the POSIX
|
||||||
|
* application. It is available only in "POSIX Application" configuration (i.e., `OPENTHREAD_ENABLE_POSIX_APP` is
|
||||||
|
* enabled).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
SPINEL_PROP_RCP_VERSION = SPINEL_PROP_OPENTHREAD__BEGIN + 12,
|
||||||
|
|
||||||
SPINEL_PROP_OPENTHREAD__END = 0x2000,
|
SPINEL_PROP_OPENTHREAD__END = 0x2000,
|
||||||
|
|
||||||
SPINEL_PROP_INTERFACE__BEGIN = 0x100,
|
SPINEL_PROP_INTERFACE__BEGIN = 0x100,
|
||||||
|
|||||||
@@ -506,6 +506,7 @@ RadioSpinel::RadioSpinel(void)
|
|||||||
, mDiagOutputMaxLen(0)
|
, mDiagOutputMaxLen(0)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
mVersion[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioSpinel::Init(const char *aRadioFile, const char *aRadioConfig)
|
void RadioSpinel::Init(const char *aRadioFile, const char *aRadioConfig)
|
||||||
@@ -535,6 +536,8 @@ void RadioSpinel::Init(const char *aRadioFile, const char *aRadioConfig)
|
|||||||
SuccessOrExit(error = WaitResponse());
|
SuccessOrExit(error = WaitResponse());
|
||||||
VerifyOrExit(mIsReady, error = OT_ERROR_FAILED);
|
VerifyOrExit(mIsReady, error = OT_ERROR_FAILED);
|
||||||
|
|
||||||
|
SuccessOrExit(error = Get(SPINEL_PROP_NCP_VERSION, SPINEL_DATATYPE_UTF8_S, mVersion, sizeof(mVersion)));
|
||||||
|
|
||||||
SuccessOrExit(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_UINT64_S, &gNodeId));
|
SuccessOrExit(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_UINT64_S, &gNodeId));
|
||||||
gNodeId = ot::Encoding::BigEndian::HostSwap64(gNodeId);
|
gNodeId = ot::Encoding::BigEndian::HostSwap64(gNodeId);
|
||||||
|
|
||||||
@@ -1725,6 +1728,12 @@ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
|
|||||||
return sRadioSpinel.GetRadioCaps();
|
return sRadioSpinel.GetRadioCaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *otPlatRadioGetVersionString(otInstance *aInstance)
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(aInstance);
|
||||||
|
return sRadioSpinel.GetVersion();
|
||||||
|
}
|
||||||
|
|
||||||
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
|
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aInstance);
|
OT_UNUSED_VARIABLE(aInstance);
|
||||||
|
|||||||
@@ -160,6 +160,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
otError SetTransmitPower(int8_t aPower);
|
otError SetTransmitPower(int8_t aPower);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the radio sw version string.
|
||||||
|
*
|
||||||
|
* @returns A pointer to the radio version string.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const char *GetVersion(void) const { return mVersion; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the radio capabilities.
|
* This method returns the radio capabilities.
|
||||||
*
|
*
|
||||||
@@ -434,8 +442,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kMaxSpinelFrame = 2048, ///< Max size in bytes for transferring spinel frames.
|
kMaxSpinelFrame = 2048, ///< Max size in bytes for transferring spinel frames.
|
||||||
kMaxWaitTime = 2000, ///< Max time to wait for response in milliseconds.
|
kMaxWaitTime = 2000, ///< Max time to wait for response in milliseconds.
|
||||||
|
kVersionStringSize = 128, ///< Max size of version string.
|
||||||
};
|
};
|
||||||
|
|
||||||
void DecodeHdlc(const uint8_t *aData, uint16_t aLength);
|
void DecodeHdlc(const uint8_t *aData, uint16_t aLength);
|
||||||
@@ -578,6 +587,7 @@ private:
|
|||||||
int8_t mRxSensitivity;
|
int8_t mRxSensitivity;
|
||||||
uint8_t mTxState;
|
uint8_t mTxState;
|
||||||
otError mTxError;
|
otError mTxError;
|
||||||
|
char mVersion[kVersionStringSize];
|
||||||
|
|
||||||
int mSockFd;
|
int mSockFd;
|
||||||
otRadioState mState;
|
otRadioState mState;
|
||||||
|
|||||||
@@ -40,7 +40,13 @@
|
|||||||
* The platform-specific string to insert into the OpenThread version string.
|
* The platform-specific string to insert into the OpenThread version string.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#if OPENTHREAD_RADIO
|
||||||
|
#define OPENTHREAD_CONFIG_PLATFORM_INFO "POSIX-RCP-toranj"
|
||||||
|
#elif OPENTHREAD_ENABLE_POSIX_APP
|
||||||
|
#define OPENTHREAD_CONFIG_PLATFORM_INFO "POSIX-App-toranj"
|
||||||
|
#else
|
||||||
#define OPENTHREAD_CONFIG_PLATFORM_INFO "POSIX-toranj"
|
#define OPENTHREAD_CONFIG_PLATFORM_INFO "POSIX-toranj"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
|
* @def OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
|
||||||
|
|||||||
Reference in New Issue
Block a user