Skip to content

Commit

Permalink
[radio] move required radio caps from radio spinel into posix platform (
Browse files Browse the repository at this point in the history
openthread#10502)

This commit moves the definition of the 'RequiredRadioCaps' from
`RadioSpinel` to posix `Radio` class. Because this definition depends
on `OPENTHREAD_CONFIG_THREAD_VERSION`. And we want to remove lib's
dependency on OT core. And lib as a tool should be able to decide what
caps to check at runtime.
  • Loading branch information
Irving-cl authored Jul 11, 2024
1 parent 4c84e4d commit 78ecafb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/lib/spinel/radio_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ RadioSpinel::RadioSpinel(void)
memset(&mCallbacks, 0, sizeof(mCallbacks));
}

void RadioSpinel::Init(bool aSkipRcpCompatibilityCheck, bool aSoftwareReset, SpinelDriver *aSpinelDriver)
void RadioSpinel::Init(bool aSkipRcpCompatibilityCheck,
bool aSoftwareReset,
SpinelDriver *aSpinelDriver,
otRadioCaps aRequiredRadioCaps)
{
otError error = OT_ERROR_NONE;
bool supportsRcpApiVersion;
Expand Down Expand Up @@ -147,7 +150,7 @@ void RadioSpinel::Init(bool aSkipRcpCompatibilityCheck, bool aSoftwareReset, Spi
if (!aSkipRcpCompatibilityCheck)
{
SuccessOrDie(CheckRcpApiVersion(supportsRcpApiVersion, supportsRcpMinHostApiVersion));
SuccessOrDie(CheckRadioCapabilities());
SuccessOrDie(CheckRadioCapabilities(aRequiredRadioCaps));
}

mRxRadioFrame.mPsdu = mRxPsdu;
Expand Down Expand Up @@ -215,23 +218,17 @@ void RadioSpinel::InitializeCaps(bool &aSupportsRcpApiVersion, bool &aSupportsRc
sSupportsLogCrashDump = GetSpinelDriver().CoprocessorHasCap(SPINEL_CAP_RCP_LOG_CRASH_DUMP);
}

otError RadioSpinel::CheckRadioCapabilities(void)
otError RadioSpinel::CheckRadioCapabilities(otRadioCaps aRequiredRadioCaps)
{
const otRadioCaps kRequiredRadioCaps =
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
OT_RADIO_CAPS_TRANSMIT_SEC | OT_RADIO_CAPS_TRANSMIT_TIMING |
#endif
OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_CSMA_BACKOFF;

otError error = OT_ERROR_NONE;
unsigned int radioCaps;

EXPECT_NO_ERROR(error = Get(SPINEL_PROP_RADIO_CAPS, SPINEL_DATATYPE_UINT_PACKED_S, &radioCaps));
sRadioCaps = static_cast<otRadioCaps>(radioCaps);

if ((sRadioCaps & kRequiredRadioCaps) != kRequiredRadioCaps)
if ((sRadioCaps & aRequiredRadioCaps) != aRequiredRadioCaps)
{
otRadioCaps missingCaps = (sRadioCaps & kRequiredRadioCaps) ^ kRequiredRadioCaps;
otRadioCaps missingCaps = (sRadioCaps & aRequiredRadioCaps) ^ aRequiredRadioCaps;

// missingCaps may be an unused variable when LogCrit is blank
// avoid compiler warning in that case
Expand Down Expand Up @@ -1796,7 +1793,7 @@ void RadioSpinel::PlatDiagOutput(const char *aFormat, ...)
va_end(args);
}

#endif
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE

uint32_t RadioSpinel::GetRadioChannelMask(bool aPreferred)
{
Expand Down
9 changes: 7 additions & 2 deletions src/lib/spinel/radio_spinel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ class RadioSpinel : private Logger
* @param[in] aSoftwareReset When doing RCP recovery, TRUE to try software reset first, FALSE to
* directly do a hardware reset.
* @param[in] aSpinelDriver A pointer to the spinel driver instance that this object depends on.
* @param[in] aRequiredRadioCaps The required radio capabilities. RadioSpinel will check if RCP has
* the required capabilities during initiailization.
*
*/
void Init(bool aSkipRcpCompatibilityCheck, bool aSoftwareReset, SpinelDriver *aSpinelDriver);
void Init(bool aSkipRcpCompatibilityCheck,
bool aSoftwareReset,
SpinelDriver *aSpinelDriver,
otRadioCaps aRequiredRadioCaps);

/**
* This method sets the notification callbacks.
Expand Down Expand Up @@ -1115,7 +1120,7 @@ class RadioSpinel : private Logger
SpinelDriver &GetSpinelDriver(void) const;

otError CheckSpinelVersion(void);
otError CheckRadioCapabilities(void);
otError CheckRadioCapabilities(otRadioCaps aRequiredRadioCaps);
otError CheckRcpApiVersion(bool aSupportsRcpApiVersion, bool aSupportsRcpMinHostApiVersion);
void InitializeCaps(bool &aSupportsRcpApiVersion, bool &aSupportsRcpMinHostApiVersion);

Expand Down
2 changes: 1 addition & 1 deletion src/posix/platform/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void Radio::Init(const char *aUrl)
skipCompatibilityCheck = mRadioUrl.HasParam("skip-rcp-compatibility-check");

mRadioSpinel.SetCallbacks(callbacks);
mRadioSpinel.Init(skipCompatibilityCheck, resetRadio, &GetSpinelDriver());
mRadioSpinel.Init(skipCompatibilityCheck, resetRadio, &GetSpinelDriver(), kRequiredRadioCaps);

ProcessRadioUrl(mRadioUrl);
}
Expand Down
6 changes: 6 additions & 0 deletions src/posix/platform/radio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class Radio : public Logger<Radio>
#error "No Spinel interface is specified!"
#endif

static constexpr otRadioCaps kRequiredRadioCaps =
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
OT_RADIO_CAPS_TRANSMIT_SEC | OT_RADIO_CAPS_TRANSMIT_TIMING |
#endif
OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_CSMA_BACKOFF;

RadioUrl mRadioUrl;
#if OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE
Spinel::VendorRadioSpinel mRadioSpinel;
Expand Down

0 comments on commit 78ecafb

Please sign in to comment.