From 01c2f53329b06e51c9cc9a9bca802120808dbe76 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 19 Nov 2020 09:28:51 -0800 Subject: [PATCH] [radio-spinel] verify host is connected to an RCP (#5822) This commit addresses an issue in `RadioSpinel::Init()` to correctly verify that device is connected to an RCP (i.e., capability list includes `SPINEL_CAP_CONFIG_RADIO`) and if not then exit (`DieNow()`) with `OT_EXIT_RADIO_SPINEL_INCOMPATIBLE` code. It also simplifies the checking of capabilities for log stream support (`SPINEL_CAP_OPENTHREAD_LOG_METADATA`) by changing the code to get and process the `SPINEL_PROP_RADIO_CAPS` list only once from `IsRcp()`. --- src/lib/spinel/radio_spinel_impl.hpp | 42 +++++++++++----------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/lib/spinel/radio_spinel_impl.hpp b/src/lib/spinel/radio_spinel_impl.hpp index 678f07244..5339f0288 100644 --- a/src/lib/spinel/radio_spinel_impl.hpp +++ b/src/lib/spinel/radio_spinel_impl.hpp @@ -221,10 +221,18 @@ void RadioSpinel::Init(bool aResetRadio, bool SuccessOrExit(error = Get(SPINEL_PROP_NCP_VERSION, SPINEL_DATATYPE_UTF8_S, mVersion, sizeof(mVersion))); SuccessOrExit(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_EUI64_S, mIeeeEui64.m8)); - if (!IsRcp() && aRestoreDatasetFromNcp) + if (!IsRcp()) { - DieNow((RestoreDatasetFromNcp() == OT_ERROR_NONE) ? OT_EXIT_SUCCESS : OT_EXIT_FAILURE); + uint8_t exitCode = OT_EXIT_RADIO_SPINEL_INCOMPATIBLE; + + if (aRestoreDatasetFromNcp) + { + exitCode = (RestoreDatasetFromNcp() == OT_ERROR_NONE) ? OT_EXIT_SUCCESS : OT_EXIT_FAILURE; + } + + DieNow(exitCode); } + SuccessOrDie(CheckRadioCapabilities()); mRxRadioFrame.mPsdu = mRxPsdu; @@ -287,6 +295,11 @@ bool RadioSpinel::IsRcp(void) isRcp = true; } + if (capability == SPINEL_CAP_OPENTHREAD_LOG_METADATA) + { + mSupportsLogStream = true; + } + capsData += unpacked; capsLength -= static_cast(unpacked); } @@ -309,11 +322,8 @@ otError RadioSpinel::CheckRadioCapabilities(v #endif OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_CSMA_BACKOFF; - otError error = OT_ERROR_NONE; - unsigned int radioCaps; - uint8_t capsBuffer[kCapsBufferSize]; - const uint8_t *capsData = capsBuffer; - spinel_size_t capsLength = sizeof(capsBuffer); + otError error = OT_ERROR_NONE; + unsigned int radioCaps; SuccessOrExit(error = Get(SPINEL_PROP_RADIO_CAPS, SPINEL_DATATYPE_UINT_PACKED_S, &radioCaps)); mRadioCaps = static_cast(radioCaps); @@ -332,24 +342,6 @@ otError RadioSpinel::CheckRadioCapabilities(v DieNow(OT_EXIT_RADIO_SPINEL_INCOMPATIBLE); } - SuccessOrExit(error = Get(SPINEL_PROP_CAPS, SPINEL_DATATYPE_DATA_S, capsBuffer, &capsLength)); - while (capsLength > 0) - { - unsigned int capability; - spinel_ssize_t unpacked = - spinel_datatype_unpack(capsData, capsLength, SPINEL_DATATYPE_UINT_PACKED_S, &capability); - - VerifyOrDie(unpacked > 0, OT_EXIT_RADIO_SPINEL_INCOMPATIBLE); - - if (capability == SPINEL_CAP_OPENTHREAD_LOG_METADATA) - { - mSupportsLogStream = true; - } - - capsData += unpacked; - capsLength -= static_cast(unpacked); - } - exit: return error; }