From b2116446bc79230a7afec49fb421d538bbb6fbdc Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Fri, 9 Jun 2023 15:00:32 +0800 Subject: [PATCH] [spinel] remove fetching the ncp dataset (#9140) --- .github/workflows/posix.yml | 33 ----- script/check-ncp-rcp-migrate | 150 -------------------- src/lib/spinel/radio_spinel.hpp | 17 +-- src/lib/spinel/radio_spinel_impl.hpp | 204 +-------------------------- src/posix/platform/radio.cpp | 8 +- src/posix/platform/radio_url.cpp | 1 - 6 files changed, 10 insertions(+), 403 deletions(-) delete mode 100755 script/check-ncp-rcp-migrate diff --git a/.github/workflows/posix.yml b/.github/workflows/posix.yml index d39e07f3e..42dc96b52 100644 --- a/.github/workflows/posix.yml +++ b/.github/workflows/posix.yml @@ -166,38 +166,6 @@ jobs: name: cov-thread-cert path: tmp/coverage.info - ncp-rcp-migrate: - runs-on: ubuntu-20.04 - env: - COVERAGE: 1 - steps: - - name: Harden Runner - uses: step-security/harden-runner@6b3083af2869dc3314a0257a42f4af696cc79ba3 # v2.3.1 - with: - egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - with: - submodules: true - - name: Bootstrap - run: | - sudo rm /etc/apt/sources.list.d/* && sudo apt-get update - sudo apt-get --no-install-recommends install -y expect lcov - - name: Build - run: | - ./bootstrap - script/check-ncp-rcp-migrate build - - name: Run - run: | - script/check-ncp-rcp-migrate check - - name: Generate Coverage - run: | - ./script/test generate_coverage gcc - - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 - with: - name: cov-ncp-rcp-migrate - path: tmp/coverage.info - pty-linux: name: pty-linux OT_DAEMON=${{ matrix.OT_DAEMON }} runs-on: ubuntu-20.04 @@ -318,7 +286,6 @@ jobs: upload-coverage: needs: - expects-linux - - ncp-rcp-migrate - pty-linux - thread-cert runs-on: ubuntu-20.04 diff --git a/script/check-ncp-rcp-migrate b/script/check-ncp-rcp-migrate deleted file mode 100755 index ce38eb527..000000000 --- a/script/check-ncp-rcp-migrate +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2020, The OpenThread Authors. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -set -e -set -x - -at_exit() -{ - EXIT_CODE=$? - - killall expect || true - killall ot-cli-ftd || true - killall ot-cli || true - killall ot-rcp || true - - exit $EXIT_CODE -} - -build() -{ - make -f examples/Makefile-simulation - make -f src/posix/Makefile-posix -} - -check() -{ - trap at_exit INT TERM EXIT - - rm -rf tmp/ - - PANID="0xc001" - EXT_PANID="0123456789abcdef" - NETWORK_NAME="OT_NCP_TO_RCP" - CHANNEL="20" - NETWORK_KEY="0123456789abcdef0123456789abcdef" - - echo "Step 1. Start NCP platform and form a PAN..." - RADIO_NCP_CMD="$PWD/output/simulation/bin/ot-cli-ftd" - - expect < #include -#include #include #include #include @@ -45,13 +44,10 @@ #include "common/encoding.hpp" #include "common/instance.hpp" #include "common/new.hpp" -#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" #include "radio/radio.hpp" #include "thread/key_manager.hpp" @@ -217,7 +213,7 @@ RadioSpinel::RadioSpinel(void) } template -void RadioSpinel::Init(bool aResetRadio, bool aRestoreDatasetFromNcp, bool aSkipRcpCompatibilityCheck) +void RadioSpinel::Init(bool aResetRadio, bool aSkipRcpCompatibilityCheck) { otError error = OT_ERROR_NONE; bool supportsRcpApiVersion; @@ -232,19 +228,7 @@ void RadioSpinel::Init(bool aResetRadio, bool aRestoreDatasetFrom 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(supportsRcpApiVersion, supportsRcpMinHostApiVersion)) - { - uint8_t exitCode = OT_EXIT_RADIO_SPINEL_INCOMPATIBLE; - - if (aRestoreDatasetFromNcp) - { -#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE - exitCode = (RestoreDatasetFromNcp() == OT_ERROR_NONE) ? OT_EXIT_SUCCESS : OT_EXIT_FAILURE; -#endif - } - - DieNow(exitCode); - } + VerifyOrDie(IsRcp(supportsRcpApiVersion, supportsRcpMinHostApiVersion), OT_EXIT_RADIO_SPINEL_INCOMPATIBLE); if (!aSkipRcpCompatibilityCheck) { @@ -464,25 +448,6 @@ exit: return error; } -#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE -template otError RadioSpinel::RestoreDatasetFromNcp(void) -{ - otError error = OT_ERROR_NONE; - - Instance::Get().template Get().Init(nullptr, 0); - - otLogInfoPlat("Trying to get saved dataset from NCP"); - SuccessOrExit( - error = Get(SPINEL_PROP_THREAD_ACTIVE_DATASET, SPINEL_DATATYPE_VOID_S, &RadioSpinel::ThreadDatasetHandler)); - SuccessOrExit( - error = Get(SPINEL_PROP_THREAD_PENDING_DATASET, SPINEL_DATATYPE_VOID_S, &RadioSpinel::ThreadDatasetHandler)); - -exit: - Instance::Get().template Get().Deinit(); - return error; -} -#endif - template void RadioSpinel::Deinit(void) { mSpinelInterface.Deinit(); @@ -642,171 +607,6 @@ exit: LogIfFail("Error processing response", error); } -#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE -template -otError RadioSpinel::ThreadDatasetHandler(const uint8_t *aBuffer, uint16_t aLength) -{ - otError error = OT_ERROR_NONE; - otOperationalDataset opDataset; - bool isActive = ((mWaitingKey == SPINEL_PROP_THREAD_ACTIVE_DATASET) ? true : false); - Spinel::Decoder decoder; - MeshCoP::Dataset dataset; - - memset(&opDataset, 0, sizeof(otOperationalDataset)); - decoder.Init(aBuffer, aLength); - - while (!decoder.IsAllReadInStruct()) - { - unsigned int propKey; - - SuccessOrExit(error = decoder.OpenStruct()); - SuccessOrExit(error = decoder.ReadUintPacked(propKey)); - - switch (static_cast(propKey)) - { - case SPINEL_PROP_NET_NETWORK_KEY: - { - const uint8_t *key; - uint16_t len; - - SuccessOrExit(error = decoder.ReadData(key, len)); - VerifyOrExit(len == OT_NETWORK_KEY_SIZE, error = OT_ERROR_INVALID_ARGS); - memcpy(opDataset.mNetworkKey.m8, key, len); - opDataset.mComponents.mIsNetworkKeyPresent = true; - break; - } - - case SPINEL_PROP_NET_NETWORK_NAME: - { - const char *name; - size_t len; - - SuccessOrExit(error = decoder.ReadUtf8(name)); - len = StringLength(name, OT_NETWORK_NAME_MAX_SIZE); - memcpy(opDataset.mNetworkName.m8, name, len); - opDataset.mNetworkName.m8[len] = '\0'; - opDataset.mComponents.mIsNetworkNamePresent = true; - break; - } - - case SPINEL_PROP_NET_XPANID: - { - const uint8_t *xpanid; - uint16_t len; - - SuccessOrExit(error = decoder.ReadData(xpanid, len)); - VerifyOrExit(len == OT_EXT_PAN_ID_SIZE, error = OT_ERROR_INVALID_ARGS); - memcpy(opDataset.mExtendedPanId.m8, xpanid, len); - opDataset.mComponents.mIsExtendedPanIdPresent = true; - break; - } - - case SPINEL_PROP_IPV6_ML_PREFIX: - { - const otIp6Address *addr; - uint8_t prefixLen; - - SuccessOrExit(error = decoder.ReadIp6Address(addr)); - SuccessOrExit(error = decoder.ReadUint8(prefixLen)); - VerifyOrExit(prefixLen == OT_IP6_PREFIX_BITSIZE, error = OT_ERROR_INVALID_ARGS); - memcpy(opDataset.mMeshLocalPrefix.m8, addr, OT_MESH_LOCAL_PREFIX_SIZE); - opDataset.mComponents.mIsMeshLocalPrefixPresent = true; - break; - } - - case SPINEL_PROP_DATASET_DELAY_TIMER: - { - SuccessOrExit(error = decoder.ReadUint32(opDataset.mDelay)); - opDataset.mComponents.mIsDelayPresent = true; - break; - } - - case SPINEL_PROP_MAC_15_4_PANID: - { - SuccessOrExit(error = decoder.ReadUint16(opDataset.mPanId)); - opDataset.mComponents.mIsPanIdPresent = true; - break; - } - - case SPINEL_PROP_PHY_CHAN: - { - uint8_t channel; - - SuccessOrExit(error = decoder.ReadUint8(channel)); - opDataset.mChannel = channel; - opDataset.mComponents.mIsChannelPresent = true; - break; - } - - case SPINEL_PROP_NET_PSKC: - { - const uint8_t *psk; - uint16_t len; - - SuccessOrExit(error = decoder.ReadData(psk, len)); - VerifyOrExit(len == OT_PSKC_MAX_SIZE, error = OT_ERROR_INVALID_ARGS); - memcpy(opDataset.mPskc.m8, psk, OT_PSKC_MAX_SIZE); - opDataset.mComponents.mIsPskcPresent = true; - break; - } - - case SPINEL_PROP_DATASET_SECURITY_POLICY: - { - uint8_t flags[2]; - uint8_t flagsLength = 1; - - SuccessOrExit(error = decoder.ReadUint16(opDataset.mSecurityPolicy.mRotationTime)); - SuccessOrExit(error = decoder.ReadUint8(flags[0])); - if (otThreadGetVersion() >= OT_THREAD_VERSION_1_2 && decoder.GetRemainingLengthInStruct() > 0) - { - SuccessOrExit(error = decoder.ReadUint8(flags[1])); - ++flagsLength; - } - static_cast(opDataset.mSecurityPolicy).SetFlags(flags, flagsLength); - opDataset.mComponents.mIsSecurityPolicyPresent = true; - break; - } - - case SPINEL_PROP_PHY_CHAN_SUPPORTED: - { - uint8_t channel; - - opDataset.mChannelMask = 0; - - while (!decoder.IsAllReadInStruct()) - { - SuccessOrExit(error = decoder.ReadUint8(channel)); - VerifyOrExit(channel <= 31, error = OT_ERROR_INVALID_ARGS); - opDataset.mChannelMask |= (1UL << channel); - } - opDataset.mComponents.mIsChannelMaskPresent = true; - break; - } - - default: - break; - } - - SuccessOrExit(error = decoder.CloseStruct()); - } - - /* - * Initially set Active Timestamp to 0. This is to allow the node to join the network - * yet retrieve the full Active Dataset from a neighboring device if one exists. - */ - memset(&opDataset.mActiveTimestamp, 0, sizeof(opDataset.mActiveTimestamp)); - opDataset.mComponents.mIsActiveTimestampPresent = true; - - SuccessOrExit(error = dataset.SetFrom(static_cast(opDataset))); - SuccessOrExit(error = Instance::Get().template Get().Set( - isActive ? SettingsBase::kKeyActiveDataset : SettingsBase::kKeyPendingDataset, dataset.GetBytes(), - dataset.GetSize())); - -exit: - return error; -} -#endif // #if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE - template void RadioSpinel::HandleWaitingResponse(uint32_t aCommand, spinel_prop_key_t aKey, diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp index 17d9c8ae8..c9d613395 100644 --- a/src/posix/platform/radio.cpp +++ b/src/posix/platform/radio.cpp @@ -109,8 +109,14 @@ void Radio::Init(void) } #endif + if (restoreDataset) + { + otLogCritPlat("The argument \"ncp-dataset\" is no longer supported"); + DieNow(OT_ERROR_FAILED); + } + SuccessOrDie(sRadioSpinel.GetSpinelInterface().Init(mRadioUrl)); - sRadioSpinel.Init(resetRadio, restoreDataset, skipCompatibilityCheck); + sRadioSpinel.Init(resetRadio, skipCompatibilityCheck); parameterValue = mRadioUrl.GetValue("fem-lnagain"); if (parameterValue != nullptr) diff --git a/src/posix/platform/radio_url.cpp b/src/posix/platform/radio_url.cpp index e062ec900..a8513f326 100644 --- a/src/posix/platform/radio_url.cpp +++ b/src/posix/platform/radio_url.cpp @@ -102,7 +102,6 @@ const char *otSysGetRadioUrlHelpString(void) " enable-coex[=1|0] If not specified, RCP coex operates with its default configuration.\n" " Disable coex with 0, and enable it with other values.\n" " fem-lnagain[=dbm] Set the Rx LNA gain in dBm of the external FEM.\n" - " ncp-dataset Retrieve dataset from ncp.\n" " no-reset Do not send Spinel reset command to RCP on initialization.\n" " skip-rcp-compatibility-check Skip checking RCP API version and capabilities during initialization.\n"; }