[spinel] remove fetching the ncp dataset (#9140)

This commit is contained in:
Zhanglong Xia
2023-06-09 15:00:32 +08:00
committed by GitHub
parent e7b591e0e7
commit b2116446bc
6 changed files with 10 additions and 403 deletions

View File

@ -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

View File

@ -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 <<EOF
spawn ${RADIO_NCP_CMD} 1
set timeout 2
expect_after {
timeout { exit 1 }
}
send "panid ${PANID}\r\n"
expect "Done"
send "extpanid ${EXT_PANID}\r\n"
expect "Done"
send "networkname ${NETWORK_NAME}\r\n"
expect "Done"
send "channel ${CHANNEL}\r\n"
expect "Done"
send "networkkey ${NETWORK_KEY}\r\n"
expect "Done"
send "ifconfig up\r\n"
expect "Done"
send "thread start\r\n"
expect "Done"
sleep 10
send "state\r\n"
expect "leader"
expect "Done"
send "exit\r\n"
expect eof
EOF
echo "Step 2. Start retrieving dataset from Radio..."
RADIO_NCP_PATH="$PWD/output/simulation/bin/ot-ncp-ftd"
"$PWD/output/posix/bin/ot-cli" -n --radio-version "spinel+hdlc+forkpty://${RADIO_NCP_PATH}?forkpty-arg=1&ncp-dataset=1"
echo "Step 3. Start posix app and check whether PAN dataset is the same..."
RADIO_RCP_PATH="$PWD/output/simulation/bin/ot-rcp"
OT_CLI_CMD="$PWD/output/posix/bin/ot-cli spinel+hdlc+forkpty://${RADIO_RCP_PATH}?forkpty-arg=1"
expect <<EOF
spawn ${OT_CLI_CMD}
set timeout 2
expect_after {
timeout { exit 1 }
}
send "panid\r\n"
expect ${PANID}
expect "Done"
send "extpanid\r\n"
expect ${EXT_PANID}
expect "Done"
send "networkname\r\n"
expect ${NETWORK_NAME}
expect "Done"
send "channel\r\n"
expect ${CHANNEL}
expect "Done"
send "networkkey\r\n"
expect ${NETWORK_KEY}
expect "Done"
send "exit\r\n"
expect eof
EOF
echo "Step 4. Start posix app and check whether it can get radio firmware version..."
RADIO_VERSION="$("$PWD/output/posix/bin/ot-cli" -n --radio-version "spinel+hdlc+forkpty://${RADIO_RCP_PATH}?forkpty-arg=1&ncp-dataset=1")" || true
echo "${RADIO_VERSION}"
test -n "{RADIO_VERSION}"
}
main()
{
case "$1" in
build)
build
;;
check)
check
;;
*)
build
check
;;
esac
}
main "$@"

View File

@ -114,13 +114,10 @@ public:
* Initialize this radio transceiver.
*
* @param[in] aResetRadio TRUE to reset on init, FALSE to not reset on init.
* @param[in] aRestoreDatasetFromNcp TRUE to restore dataset to host from non-volatile memory
* (only used when attempts to upgrade from NCP to RCP mode),
* FALSE otherwise.
* @param[in] aSkipRcpCompatibilityCheck TRUE to skip RCP compatibility check, FALSE to perform the check.
*
*/
void Init(bool aResetRadio, bool aRestoreDataSetFromNcp, bool aSkipRcpCompatibilityCheck);
void Init(bool aResetRadio, bool aSkipRcpCompatibilityCheck);
/**
* Deinitialize this radio transceiver.
@ -747,17 +744,6 @@ public:
*/
bool HasPendingFrame(void) const { return mRxFrameBuffer.HasSavedFrame(); }
/**
* Gets dataset from NCP radio and saves it.
*
* @retval OT_ERROR_NONE Successfully restore dataset.
* @retval OT_ERROR_BUSY Failed due to another operation is on going.
* @retval OT_ERROR_RESPONSE_TIMEOUT Failed due to no response received from the radio.
* @retval OT_ERROR_NOT_FOUND Failed due to spinel property not supported in radio.
* @retval OT_ERROR_FAILED Failed due to other reasons.
*/
otError RestoreDatasetFromNcp(void);
/**
* Returns the next timepoint to recalculate RCP time offset.
*
@ -1005,7 +991,6 @@ private:
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);
/**
* Returns if the property changed event is safe to be handled now.

View File

@ -36,7 +36,6 @@
#include <stdarg.h>
#include <stdlib.h>
#include <openthread/dataset.h>
#include <openthread/logging.h>
#include <openthread/platform/diag.h>
#include <openthread/platform/time.h>
@ -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<InterfaceType>::RadioSpinel(void)
}
template <typename InterfaceType>
void RadioSpinel<InterfaceType>::Init(bool aResetRadio, bool aRestoreDatasetFromNcp, bool aSkipRcpCompatibilityCheck)
void RadioSpinel<InterfaceType>::Init(bool aResetRadio, bool aSkipRcpCompatibilityCheck)
{
otError error = OT_ERROR_NONE;
bool supportsRcpApiVersion;
@ -232,19 +228,7 @@ void RadioSpinel<InterfaceType>::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 <typename InterfaceType> otError RadioSpinel<InterfaceType>::RestoreDatasetFromNcp(void)
{
otError error = OT_ERROR_NONE;
Instance::Get().template Get<SettingsDriver>().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<SettingsDriver>().Deinit();
return error;
}
#endif
template <typename InterfaceType> void RadioSpinel<InterfaceType>::Deinit(void)
{
mSpinelInterface.Deinit();
@ -642,171 +607,6 @@ exit:
LogIfFail("Error processing response", error);
}
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
template <typename InterfaceType>
otError RadioSpinel<InterfaceType>::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<spinel_prop_key_t>(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<SecurityPolicy &>(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<MeshCoP::Dataset::Info &>(opDataset)));
SuccessOrExit(error = Instance::Get().template Get<SettingsDriver>().Set(
isActive ? SettingsBase::kKeyActiveDataset : SettingsBase::kKeyPendingDataset, dataset.GetBytes(),
dataset.GetSize()));
exit:
return error;
}
#endif // #if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
template <typename InterfaceType>
void RadioSpinel<InterfaceType>::HandleWaitingResponse(uint32_t aCommand,
spinel_prop_key_t aKey,

View File

@ -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)

View File

@ -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";
}