Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[host] add active dataset as a network property #2540

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace Ncp {
NcpNetworkProperties::NcpNetworkProperties(void)
: mDeviceRole(OT_DEVICE_ROLE_DISABLED)
{
memset(&mDatasetActiveTlvs, 0, sizeof(mDatasetActiveTlvs));
}

otDeviceRole NcpNetworkProperties::GetDeviceRole(void) const
Expand All @@ -61,6 +62,18 @@ void NcpNetworkProperties::SetDeviceRole(otDeviceRole aRole)
mDeviceRole = aRole;
}

void NcpNetworkProperties::SetDatasetActiveTlvs(const otOperationalDatasetTlvs &aActiveOpDatasetTlvs)
{
mDatasetActiveTlvs.mLength = aActiveOpDatasetTlvs.mLength;
memcpy(mDatasetActiveTlvs.mTlvs, aActiveOpDatasetTlvs.mTlvs, aActiveOpDatasetTlvs.mLength);
}

void NcpNetworkProperties::GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const
{
aDatasetTlvs.mLength = mDatasetActiveTlvs.mLength;
memcpy(aDatasetTlvs.mTlvs, mDatasetActiveTlvs.mTlvs, mDatasetActiveTlvs.mLength);
}

// ===================================== NcpHost ======================================

NcpHost::NcpHost(const char *aInterfaceName, bool aDryRun)
Expand Down
5 changes: 4 additions & 1 deletion src/ncp/ncp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ class NcpNetworkProperties : virtual public NetworkProperties, public PropsObser

// NetworkProperties methods
otDeviceRole GetDeviceRole(void) const override;
void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;

private:
// PropsObserver methods
void SetDeviceRole(otDeviceRole aRole) override;
void SetDatasetActiveTlvs(const otOperationalDatasetTlvs &aActiveOpDatasetTlvs) override;

otDeviceRole mDeviceRole;
otDeviceRole mDeviceRole;
otOperationalDatasetTlvs mDatasetActiveTlvs;
};

class NcpHost : public MainloopProcessor, public ThreadHost, public NcpNetworkProperties
Expand Down
26 changes: 26 additions & 0 deletions src/ncp/ncp_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ otbrError NcpSpinel::HandleResponseForPropSet(spinel_tid_t aTid,
case SPINEL_PROP_THREAD_ACTIVE_DATASET_TLVS:
VerifyOrExit(aKey == SPINEL_PROP_THREAD_ACTIVE_DATASET_TLVS, error = OTBR_ERROR_INVALID_STATE);
CallAndClear(mDatasetSetActiveTask, OT_ERROR_NONE);
{
otOperationalDatasetTlvs datasetTlvs;
VerifyOrExit(ParseOperationalDatasetTlvs(aData, aLength, datasetTlvs) == OT_ERROR_NONE,
error = OTBR_ERROR_PARSE);
mPropsObserver->SetDatasetActiveTlvs(datasetTlvs);
}
break;

case SPINEL_PROP_NET_IF_UP:
Expand Down Expand Up @@ -725,6 +731,26 @@ otError NcpSpinel::ParseIp6StreamNet(const uint8_t *aBuf, uint8_t aLen, const ui
return error;
}

otError NcpSpinel::ParseOperationalDatasetTlvs(const uint8_t *aBuf,
uint8_t aLen,
otOperationalDatasetTlvs &aDatasetTlvs)
{
otError error = OT_ERROR_NONE;
ot::Spinel::Decoder decoder;
const uint8_t *datasetTlvsData;
uint16_t datasetTlvsLen;

decoder.Init(aBuf, aLen);
SuccessOrExit(error = decoder.ReadData(datasetTlvsData, datasetTlvsLen));
VerifyOrExit(datasetTlvsLen <= sizeof(aDatasetTlvs.mTlvs), error = OT_ERROR_PARSE);

memcpy(aDatasetTlvs.mTlvs, datasetTlvsData, datasetTlvsLen);
aDatasetTlvs.mLength = datasetTlvsLen;

exit:
return error;
}

otDeviceRole NcpSpinel::SpinelRoleToDeviceRole(spinel_net_role_t aRole)
{
otDeviceRole role = OT_DEVICE_ROLE_DISABLED;
Expand Down
8 changes: 8 additions & 0 deletions src/ncp/ncp_spinel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class PropsObserver
*/
virtual void SetDeviceRole(otDeviceRole aRole) = 0;

/**
* Updates the active dataset.
*
* @param[in] aActiveOpDatasetTlvs The active dataset tlvs.
*/
virtual void SetDatasetActiveTlvs(const otOperationalDatasetTlvs &aActiveOpDatasetTlvs) = 0;

/**
* The destructor.
*/
Expand Down Expand Up @@ -294,6 +301,7 @@ class NcpSpinel : public Netif::Dependencies
otError ParseIp6AddressTable(const uint8_t *aBuf, uint16_t aLength, std::vector<Ip6AddressInfo> &aAddressTable);
otError ParseIp6MulticastAddresses(const uint8_t *aBuf, uint8_t aLen, std::vector<Ip6Address> &aAddressList);
otError ParseIp6StreamNet(const uint8_t *aBuf, uint8_t aLen, const uint8_t *&aData, uint16_t &aDataLen);
otError ParseOperationalDatasetTlvs(const uint8_t *aBuf, uint8_t aLen, otOperationalDatasetTlvs &aDatasetTlvs);

ot::Spinel::SpinelDriver *mSpinelDriver;
uint16_t mCmdTidsInUse; ///< Used transaction ids.
Expand Down
11 changes: 11 additions & 0 deletions src/ncp/rcp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ otDeviceRole OtNetworkProperties::GetDeviceRole(void) const
return otThreadGetDeviceRole(mInstance);
}

void OtNetworkProperties::GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const
{
otError error = otDatasetGetActiveTlvs(mInstance, &aDatasetTlvs);

if (error != OT_ERROR_NONE)
{
aDatasetTlvs.mLength = 0;
memset(aDatasetTlvs.mTlvs, 0, sizeof(aDatasetTlvs.mTlvs));
}
}

void OtNetworkProperties::SetInstance(otInstance *aInstance)
{
mInstance = aInstance;
Expand Down
1 change: 1 addition & 0 deletions src/ncp/rcp_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class OtNetworkProperties : virtual public NetworkProperties

// NetworkProperties methods
otDeviceRole GetDeviceRole(void) const override;
void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const override;

// Set the otInstance
void SetInstance(otInstance *aInstance);
Expand Down
7 changes: 7 additions & 0 deletions src/ncp/thread_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class NetworkProperties
*/
virtual otDeviceRole GetDeviceRole(void) const = 0;

/**
* Returns the active operational dataset tlvs.
*
* @param[out] aDatasetTlvs A reference to where the Active Operational Dataset will be placed.
*/
virtual void GetDatasetActiveTlvs(otOperationalDatasetTlvs &aDatasetTlvs) const = 0;

/**
* The destructor.
*/
Expand Down
Loading