[spinel] export RadioSpinel functions for vendor hooks (#7087)

This commit exports private spinel utility functions to access vendor
implemented properties from the host.

The commit also reserves the vendor property range for Espressif to
avoid collision.
This commit is contained in:
Jiacheng Guo
2021-10-25 12:35:31 -07:00
committed by GitHub
parent 025405645e
commit 7e2420ff3d
3 changed files with 64 additions and 50 deletions
+55 -45
View File
@@ -742,45 +742,6 @@ public:
*/
otError SetChannelMaxTransmitPower(uint8_t aChannel, int8_t aPower);
private:
enum
{
kMaxSpinelFrame = SpinelInterface::kMaxFrameSize,
kMaxWaitTime = 2000, ///< Max time to wait for response in milliseconds.
kVersionStringSize = 128, ///< Max size of version string.
kCapsBufferSize = 100, ///< Max buffer size used to store `SPINEL_PROP_CAPS` value.
kChannelMaskBufferSize = 32, ///< Max buffer size used to store `SPINEL_PROP_PHY_CHAN_SUPPORTED` value.
};
enum State
{
kStateDisabled, ///< Radio is disabled.
kStateSleep, ///< Radio is sleep.
kStateReceive, ///< Radio is in receive mode.
kStateTransmitting, ///< Frame passed to radio for transmission, waiting for done event from radio.
kStateTransmitDone, ///< Radio indicated frame transmission is done.
};
typedef otError (RadioSpinel::*ResponseHandler)(const uint8_t *aBuffer, uint16_t aLength);
static void HandleReceivedFrame(void *aContext);
otError CheckSpinelVersion(void);
otError CheckRadioCapabilities(void);
otError CheckRcpApiVersion(bool aSupportsRcpApiVersion);
/**
* This method triggers a state transfer of the state machine.
*
*/
void ProcessRadioStateMachine(void);
/**
* This method processes the frame queue.
*
*/
void ProcessFrameQueue(void);
/**
* This method tries to retrieve a spinel property from OpenThread transceiver.
*
@@ -857,6 +818,56 @@ private:
*/
otError Remove(spinel_prop_key_t aKey, const char *aFormat, ...);
/**
* This method tries to reset the co-processor.
*
* @prarm[in] aResetType The reset type, SPINEL_RESET_PLATFORM or SPINEL_RESET_STACK.
*
* @retval OT_ERROR_NONE Successfully removed item from the property.
* @retval OT_ERROR_BUSY Failed due to another operation is on going.
*
*/
otError SendReset(uint8_t aResetType);
private:
enum
{
kMaxSpinelFrame = SpinelInterface::kMaxFrameSize,
kMaxWaitTime = 2000, ///< Max time to wait for response in milliseconds.
kVersionStringSize = 128, ///< Max size of version string.
kCapsBufferSize = 100, ///< Max buffer size used to store `SPINEL_PROP_CAPS` value.
kChannelMaskBufferSize = 32, ///< Max buffer size used to store `SPINEL_PROP_PHY_CHAN_SUPPORTED` value.
};
enum State
{
kStateDisabled, ///< Radio is disabled.
kStateSleep, ///< Radio is sleep.
kStateReceive, ///< Radio is in receive mode.
kStateTransmitting, ///< Frame passed to radio for transmission, waiting for done event from radio.
kStateTransmitDone, ///< Radio indicated frame transmission is done.
};
typedef otError (RadioSpinel::*ResponseHandler)(const uint8_t *aBuffer, uint16_t aLength);
static void HandleReceivedFrame(void *aContext);
otError CheckSpinelVersion(void);
otError CheckRadioCapabilities(void);
otError CheckRcpApiVersion(bool aSupportsRcpApiVersion);
/**
* This method triggers a state transfer of the state machine.
*
*/
void ProcessRadioStateMachine(void);
/**
* This method processes the frame queue.
*
*/
void ProcessFrameQueue(void);
spinel_tid_t GetNextTid(void);
void FreeTid(spinel_tid_t tid) { mCmdTidsInUse &= ~(1 << tid); }
@@ -878,12 +889,11 @@ private:
const char * aFormat,
va_list aArgs);
otError WaitResponse(void);
otError SendReset(void);
otError SendCommand(uint32_t command,
spinel_prop_key_t key,
spinel_tid_t tid,
const char * pack_format,
va_list args);
otError SendCommand(uint32_t aCommand,
spinel_prop_key_t aKey,
spinel_tid_t aTid,
const char * aFormat,
va_list aArgs);
otError ParseRadioFrame(otRadioFrame &aFrame, const uint8_t *aBuffer, uint16_t aLength, spinel_ssize_t &aUnpacked);
otError ThreadDatasetHandler(const uint8_t *aBuffer, uint16_t aLength);
+6 -5
View File
@@ -48,6 +48,7 @@
#include "common/settings.hpp"
#include "lib/platform/exit_code.h"
#include "lib/spinel/radio_spinel.hpp"
#include "lib/spinel/spinel.h"
#include "lib/spinel/spinel_decoder.hpp"
#include "meshcop/dataset.hpp"
#include "meshcop/meshcop_tlvs.hpp"
@@ -233,7 +234,7 @@ void RadioSpinel<InterfaceType, ProcessContextType>::Init(bool aResetRadio,
if (aResetRadio)
{
SuccessOrExit(error = SendReset());
SuccessOrExit(error = SendReset(SPINEL_RESET_STACK));
SuccessOrDie(mSpinelInterface.ResetConnection());
}
@@ -1703,15 +1704,15 @@ spinel_tid_t RadioSpinel<InterfaceType, ProcessContextType>::GetNextTid(void)
}
template <typename InterfaceType, typename ProcessContextType>
otError RadioSpinel<InterfaceType, ProcessContextType>::SendReset(void)
otError RadioSpinel<InterfaceType, ProcessContextType>::SendReset(uint8_t aResetType)
{
otError error = OT_ERROR_NONE;
uint8_t buffer[kMaxSpinelFrame];
spinel_ssize_t packed;
// Pack the header, command and key
packed =
spinel_datatype_pack(buffer, sizeof(buffer), "Ci", SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_CMD_RESET);
packed = spinel_datatype_pack(buffer, sizeof(buffer), SPINEL_DATATYPE_COMMAND_S SPINEL_DATATYPE_UINT8_S,
SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_CMD_RESET, aResetType);
VerifyOrExit(packed > 0 && static_cast<size_t>(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS);
@@ -2256,7 +2257,7 @@ void RadioSpinel<InterfaceType, ProcessContextType>::RecoverFromRcpFailure(void)
if (mResetRadioOnStartup)
{
SuccessOrDie(SendReset());
SuccessOrDie(SendReset(SPINEL_RESET_STACK));
SuccessOrDie(mSpinelInterface.ResetConnection());
}
+3
View File
@@ -4728,6 +4728,9 @@ enum
SPINEL_PROP_VENDOR__BEGIN = 0x3C00,
SPINEL_PROP_VENDOR__END = 0x4000,
SPINEL_PROP_VENDOR_ESP__BEGIN = (SPINEL_PROP_VENDOR__BEGIN + 0),
SPINEL_PROP_VENDOR_ESP__END = (SPINEL_PROP_VENDOR__BEGIN + 128),
SPINEL_PROP_DEBUG__BEGIN = 0x4000,
/// Testing platform assert