mirror of
https://github.com/espressif/openthread.git
synced 2026-09-12 04:00:10 +00:00
[dataset] update dataset SendMgmtGet APIs and add support in spinel/NCP (#2866)
This commit updates the APIs `otDatasetSendMgmtActiveGet` and `otDatasetSendMgmtPendingGet` to be similar to MgmtSet APIs and use an `otOperationalDatasetComponents` as input to specify the Dataset components to be requested. The implementation of APIs in `DatasetManager` and their use in in CLI is also updated. It also defines new spinel properties `MGMT_GET_ACTIVE_DATASET` and `THREAD_MGMT_GET_PENDING_DATASET` (with their set handlers) to add support for sending `MGMT_GET` meshcop command for Active/Pending Operational Dataset. It also renames the existing properties used for sending `MGMT_SET` (include `MGMT_SET` in the property name). It also adds a new property to allow an optional destination IPv6 address to be specified (for sending `MGMT_GET` command) as part of spinel dictionary representation of Dataset instance.
This commit is contained in:
committed by
Jonathan Hui
parent
7ba8f348dc
commit
758e647d91
@@ -2287,13 +2287,14 @@ OTAPI
|
||||
otError
|
||||
OTCALL
|
||||
otDatasetSendMgmtActiveGet(
|
||||
_In_ otInstance *aInstance,
|
||||
_In_ otInstance *aInstance,
|
||||
const otOperationalDatasetComponents *aDatasetComponents,
|
||||
const uint8_t *aTlvTypes,
|
||||
uint8_t aLength,
|
||||
_In_opt_ const otIp6Address *aAddress
|
||||
)
|
||||
{
|
||||
if (aInstance == nullptr) return OT_ERROR_INVALID_ARGS;
|
||||
if (aInstance == nullptr || aDatasetComponents == nullptr) return OT_ERROR_INVALID_ARGS;
|
||||
if (aTlvTypes == nullptr && aLength != 0) return OT_ERROR_INVALID_ARGS;
|
||||
|
||||
DWORD BufferSize = sizeof(GUID) + sizeof(uint8_t) + aLength;
|
||||
@@ -2302,6 +2303,7 @@ otDatasetSendMgmtActiveGet(
|
||||
if (Buffer == nullptr) return OT_ERROR_NO_BUFS;
|
||||
|
||||
memcpy_s(Buffer, BufferSize, &aInstance->InterfaceGuid, sizeof(GUID));
|
||||
memcpy_s(Buffer + sizeof(GUID), BufferSize - sizeof(GUID), aDatasetComponents, sizeof(otOperationalDatasetComponents));
|
||||
memcpy_s(Buffer + sizeof(GUID), BufferSize - sizeof(GUID), &aLength, sizeof(aLength));
|
||||
if (aLength > 0)
|
||||
memcpy_s(Buffer + sizeof(GUID) + sizeof(uint8_t), BufferSize - sizeof(GUID) - sizeof(uint8_t), aTlvTypes, aLength);
|
||||
@@ -2320,7 +2322,7 @@ otError
|
||||
OTCALL
|
||||
otDatasetSendMgmtActiveSet(
|
||||
_In_ otInstance *aInstance,
|
||||
const otOperationalDataset *aDataset,
|
||||
const otOperationalDataset *aDataset,
|
||||
const uint8_t *aTlvs,
|
||||
uint8_t aLength
|
||||
)
|
||||
@@ -2349,13 +2351,14 @@ OTAPI
|
||||
otError
|
||||
OTCALL
|
||||
otDatasetSendMgmtPendingGet(
|
||||
_In_ otInstance *aInstance,
|
||||
_In_ otInstance *aInstance,
|
||||
const otOperationalDatasetComponents *aDatasetComponents,
|
||||
const uint8_t *aTlvTypes,
|
||||
uint8_t aLength,
|
||||
_In_opt_ const otIp6Address *aAddress
|
||||
)
|
||||
{
|
||||
if (aInstance == nullptr) return OT_ERROR_INVALID_ARGS;
|
||||
if (aInstance == nullptr || aDatasetComponents == nullptr) return OT_ERROR_INVALID_ARGS;
|
||||
if (aTlvTypes == nullptr && aLength != 0) return OT_ERROR_INVALID_ARGS;
|
||||
|
||||
DWORD BufferSize = sizeof(GUID) + sizeof(uint8_t) + aLength;
|
||||
@@ -2364,6 +2367,7 @@ otDatasetSendMgmtPendingGet(
|
||||
if (Buffer == nullptr) return OT_ERROR_NO_BUFS;
|
||||
|
||||
memcpy_s(Buffer, BufferSize, &aInstance->InterfaceGuid, sizeof(GUID));
|
||||
memcpy_s(Buffer + sizeof(GUID), BufferSize - sizeof(GUID), aDatasetComponents, sizeof(otOperationalDatasetComponents));
|
||||
memcpy_s(Buffer + sizeof(GUID), BufferSize - sizeof(GUID), &aLength, sizeof(aLength));
|
||||
if (aLength > 0)
|
||||
memcpy_s(Buffer + sizeof(GUID) + sizeof(uint8_t), BufferSize - sizeof(GUID) - sizeof(uint8_t), aTlvTypes, aLength);
|
||||
|
||||
@@ -5918,20 +5918,22 @@ otLwfIoCtl_otSendActiveGet(
|
||||
*OutBufferLength = 0;
|
||||
UNREFERENCED_PARAMETER(OutBuffer);
|
||||
|
||||
if (InBufferLength >= sizeof(uint8_t))
|
||||
if (InBufferLength >= sizeof(otOperationalDatasetComponents) + sizeof(uint8_t))
|
||||
{
|
||||
uint8_t aLength = *(uint8_t*)InBuffer;
|
||||
PUCHAR aTlvTypes = aLength == 0 ? NULL : InBuffer + sizeof(uint8_t);
|
||||
const otOperationalDatasetComponents *aDatasetComp = (otOperationalDatasetComponents*)InBuffer;
|
||||
uint8_t aLength = *(uint8_t*)(InBuffer + sizeof(otOperationalDatasetComponents));
|
||||
PUCHAR aTlvTypes = aLength == 0 ? NULL : InBuffer + sizeof(otOperationalDatasetComponents) + sizeof(uint8_t);
|
||||
|
||||
if (InBufferLength >= sizeof(uint8_t) + aLength)
|
||||
if (InBufferLength >= sizeof(otOperationalDatasetComponents) + sizeof(uint8_t) + aLength)
|
||||
{
|
||||
otIp6Address *aAddress = NULL;
|
||||
if (InBufferLength >= sizeof(uint8_t) + aLength + sizeof(otIp6Address))
|
||||
aAddress = (otIp6Address*)(InBuffer + sizeof(uint8_t) + aLength);
|
||||
if (InBufferLength >= sizeof(otOperationalDatasetComponents) + sizeof(uint8_t) + aLength + sizeof(otIp6Address))
|
||||
aAddress = (otIp6Address*)(InBuffer + sizeof(otOperationalDatasetComponents) + sizeof(uint8_t) + aLength);
|
||||
|
||||
status = ThreadErrorToNtstatus(
|
||||
otDatasetSendMgmtActiveGet(
|
||||
pFilter->otCtx,
|
||||
aDatasetComp,
|
||||
aTlvTypes,
|
||||
aLength,
|
||||
aAddress)
|
||||
@@ -5997,20 +5999,22 @@ otLwfIoCtl_otSendPendingGet(
|
||||
*OutBufferLength = 0;
|
||||
UNREFERENCED_PARAMETER(OutBuffer);
|
||||
|
||||
if (InBufferLength >= sizeof(uint8_t))
|
||||
if (InBufferLength >= sizeof(otOperationalDataset) + sizeof(uint8_t))
|
||||
{
|
||||
uint8_t aLength = *(uint8_t*)InBuffer;
|
||||
PUCHAR aTlvTypes = aLength == 0 ? NULL : InBuffer + sizeof(uint8_t);
|
||||
const otOperationalDatasetComponents *aDatasetComp = (otOperationalDatasetComponents*)InBuffer;
|
||||
uint8_t aLength = *(uint8_t*)(InBuffer + sizeof(otOperationalDataset));
|
||||
PUCHAR aTlvTypes = aLength == 0 ? NULL : InBuffer + sizeof(otOperationalDataset) + sizeof(uint8_t);
|
||||
|
||||
if (InBufferLength >= sizeof(uint8_t) + aLength)
|
||||
if (InBufferLength >= sizeof(otOperationalDatasetComponents) + sizeof(uint8_t) + aLength)
|
||||
{
|
||||
otIp6Address *aAddress = NULL;
|
||||
if (InBufferLength >= sizeof(uint8_t) + aLength + sizeof(otIp6Address))
|
||||
aAddress = (otIp6Address*)(InBuffer + sizeof(uint8_t) + aLength);
|
||||
if (InBufferLength >= sizeof(otOperationalDatasetComponents) + sizeof(uint8_t) + aLength + sizeof(otIp6Address))
|
||||
aAddress = (otIp6Address*)(InBuffer + sizeof(otOperationalDataset) + sizeof(uint8_t) + aLength);
|
||||
|
||||
status = ThreadErrorToNtstatus(
|
||||
otDatasetSendMgmtPendingGet(
|
||||
pFilter->otCtx,
|
||||
aDatasetComp,
|
||||
aTlvTypes,
|
||||
aLength,
|
||||
aAddress)
|
||||
|
||||
@@ -1976,24 +1976,24 @@ OTNODEAPI int32_t OTCALL otNodeSetActiveDataset(otNode* aNode, uint64_t aTimesta
|
||||
otOperationalDataset aDataset = {};
|
||||
|
||||
aDataset.mActiveTimestamp = aTimestamp;
|
||||
aDataset.mIsActiveTimestampSet = true;
|
||||
aDataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
|
||||
if (aPanId != 0)
|
||||
{
|
||||
aDataset.mPanId = aPanId;
|
||||
aDataset.mIsPanIdSet = true;
|
||||
aDataset.mComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
|
||||
if (aChannel != 0)
|
||||
{
|
||||
aDataset.mChannel = aChannel;
|
||||
aDataset.mIsChannelSet = true;
|
||||
aDataset.mComponents.mIsChannelPresent = true;
|
||||
}
|
||||
|
||||
if (aChannelMask != 0)
|
||||
{
|
||||
aDataset.mChannelMaskPage0 = aChannelMask;
|
||||
aDataset.mIsChannelMaskPage0Set = true;
|
||||
aDataset.mComponents.mIsChannelMaskPage0Present = true;
|
||||
}
|
||||
|
||||
if (aMasterKey != NULL && strlen(aMasterKey) != 0)
|
||||
@@ -2004,7 +2004,7 @@ OTNODEAPI int32_t OTCALL otNodeSetActiveDataset(otNode* aNode, uint64_t aTimesta
|
||||
printf("invalid length key %d\r\n", keyLength);
|
||||
return OT_ERROR_PARSE;
|
||||
}
|
||||
aDataset.mIsMasterKeySet = true;
|
||||
aDataset.mComponents.mIsMasterKeyPresent = true;
|
||||
}
|
||||
|
||||
auto result = otDatasetSetActive(aNode->mInstance, &aDataset);
|
||||
@@ -2022,25 +2022,25 @@ OTNODEAPI int32_t OTCALL otNodeSetPendingDataset(otNode* aNode, uint64_t aActive
|
||||
if (aActiveTimestamp != 0)
|
||||
{
|
||||
aDataset.mActiveTimestamp = aActiveTimestamp;
|
||||
aDataset.mIsActiveTimestampSet = true;
|
||||
aDataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
}
|
||||
|
||||
if (aPendingTimestamp != 0)
|
||||
{
|
||||
aDataset.mPendingTimestamp = aPendingTimestamp;
|
||||
aDataset.mIsPendingTimestampSet = true;
|
||||
aDataset.mComponents.mIsPendingTimestampPresent = true;
|
||||
}
|
||||
|
||||
if (aPanId != 0)
|
||||
{
|
||||
aDataset.mPanId = aPanId;
|
||||
aDataset.mIsPanIdSet = true;
|
||||
aDataset.mComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
|
||||
if (aChannel != 0)
|
||||
{
|
||||
aDataset.mChannel = aChannel;
|
||||
aDataset.mIsChannelSet = true;
|
||||
aDataset.mComponents.mIsChannelPresent = true;
|
||||
}
|
||||
|
||||
auto result = otDatasetSetPending(aNode->mInstance, &aDataset);
|
||||
@@ -2058,31 +2058,31 @@ OTNODEAPI int32_t OTCALL otNodeSendPendingSet(otNode* aNode, uint64_t aActiveTim
|
||||
if (aActiveTimestamp != 0)
|
||||
{
|
||||
aDataset.mActiveTimestamp = aActiveTimestamp;
|
||||
aDataset.mIsActiveTimestampSet = true;
|
||||
aDataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
}
|
||||
|
||||
if (aPendingTimestamp != 0)
|
||||
{
|
||||
aDataset.mPendingTimestamp = aPendingTimestamp;
|
||||
aDataset.mIsPendingTimestampSet = true;
|
||||
aDataset.mComponents.mIsPendingTimestampPresent = true;
|
||||
}
|
||||
|
||||
if (aDelayTimer != 0)
|
||||
{
|
||||
aDataset.mDelay = aDelayTimer;
|
||||
aDataset.mIsDelaySet = true;
|
||||
aDataset.mComponents.mIsDelayPresent = true;
|
||||
}
|
||||
|
||||
if (aPanId != 0)
|
||||
{
|
||||
aDataset.mPanId = aPanId;
|
||||
aDataset.mIsPanIdSet = true;
|
||||
aDataset.mComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
|
||||
if (aChannel != 0)
|
||||
{
|
||||
aDataset.mChannel = aChannel;
|
||||
aDataset.mIsChannelSet = true;
|
||||
aDataset.mComponents.mIsChannelPresent = true;
|
||||
}
|
||||
|
||||
if (aMasterKey != NULL && strlen(aMasterKey) != 0)
|
||||
@@ -2093,7 +2093,7 @@ OTNODEAPI int32_t OTCALL otNodeSendPendingSet(otNode* aNode, uint64_t aActiveTim
|
||||
printf("invalid length key %d\r\n", keyLength);
|
||||
return OT_ERROR_PARSE;
|
||||
}
|
||||
aDataset.mIsMasterKeySet = true;
|
||||
aDataset.mComponents.mIsMasterKeyPresent = true;
|
||||
}
|
||||
|
||||
if (aMeshLocal != NULL && strlen(aMeshLocal) != 0)
|
||||
@@ -2102,13 +2102,13 @@ OTNODEAPI int32_t OTCALL otNodeSendPendingSet(otNode* aNode, uint64_t aActiveTim
|
||||
auto error = otIp6AddressFromString(aMeshLocal, &prefix);
|
||||
if (error != OT_ERROR_NONE) return error;
|
||||
memcpy(aDataset.mMeshLocalPrefix.m8, prefix.mFields.m8, sizeof(aDataset.mMeshLocalPrefix.m8));
|
||||
aDataset.mIsMeshLocalPrefixSet = true;
|
||||
aDataset.mComponents.mIsMeshLocalPrefixPresent = true;
|
||||
}
|
||||
|
||||
if (aNetworkName != NULL && strlen(aNetworkName) != 0)
|
||||
{
|
||||
strcpy_s(aDataset.mNetworkName.m8, sizeof(aDataset.mNetworkName.m8), aNetworkName);
|
||||
aDataset.mIsNetworkNameSet = true;
|
||||
aDataset.mComponents.mIsNetworkNamePresent = true;
|
||||
}
|
||||
|
||||
auto result = otDatasetSendMgmtPendingSet(aNode->mInstance, &aDataset, nullptr, 0);
|
||||
@@ -2128,24 +2128,24 @@ OTNODEAPI int32_t OTCALL otNodeSendActiveSet(otNode* aNode, uint64_t aActiveTime
|
||||
if (aActiveTimestamp != 0)
|
||||
{
|
||||
aDataset.mActiveTimestamp = aActiveTimestamp;
|
||||
aDataset.mIsActiveTimestampSet = true;
|
||||
aDataset.mComponents.mIsActiveTimestampPresent = true;
|
||||
}
|
||||
if (aPanId != 0)
|
||||
{
|
||||
aDataset.mPanId = aPanId;
|
||||
aDataset.mIsPanIdSet = true;
|
||||
aDataset.mComponents.mIsPanIdPresent = true;
|
||||
}
|
||||
|
||||
if (aChannel != 0)
|
||||
{
|
||||
aDataset.mChannel = aChannel;
|
||||
aDataset.mIsChannelSet = true;
|
||||
aDataset.mComponents.mIsChannelPresent = true;
|
||||
}
|
||||
|
||||
if (aChannelMask != 0)
|
||||
{
|
||||
aDataset.mChannelMaskPage0 = aChannelMask;
|
||||
aDataset.mIsChannelMaskPage0Set = true;
|
||||
aDataset.mComponents.mIsChannelMaskPage0Present = true;
|
||||
}
|
||||
|
||||
if (aExtPanId != NULL && strlen(aExtPanId) != 0)
|
||||
@@ -2156,7 +2156,7 @@ OTNODEAPI int32_t OTCALL otNodeSendActiveSet(otNode* aNode, uint64_t aActiveTime
|
||||
printf("invalid length ext pan id %d\r\n", keyLength);
|
||||
return OT_ERROR_PARSE;
|
||||
}
|
||||
aDataset.mIsExtendedPanIdSet = true;
|
||||
aDataset.mComponents.mIsExtendedPanIdPresent = true;
|
||||
}
|
||||
|
||||
if (aMasterKey != NULL && strlen(aMasterKey) != 0)
|
||||
@@ -2167,7 +2167,7 @@ OTNODEAPI int32_t OTCALL otNodeSendActiveSet(otNode* aNode, uint64_t aActiveTime
|
||||
printf("invalid length key %d\r\n", keyLength);
|
||||
return OT_ERROR_PARSE;
|
||||
}
|
||||
aDataset.mIsMasterKeySet = true;
|
||||
aDataset.mComponents.mIsMasterKeyPresent = true;
|
||||
}
|
||||
|
||||
if (aMeshLocal != NULL && strlen(aMeshLocal) != 0)
|
||||
@@ -2176,13 +2176,13 @@ OTNODEAPI int32_t OTCALL otNodeSendActiveSet(otNode* aNode, uint64_t aActiveTime
|
||||
auto error = otIp6AddressFromString(aMeshLocal, &prefix);
|
||||
if (error != OT_ERROR_NONE) return error;
|
||||
memcpy(aDataset.mMeshLocalPrefix.m8, prefix.mFields.m8, sizeof(aDataset.mMeshLocalPrefix.m8));
|
||||
aDataset.mIsMeshLocalPrefixSet = true;
|
||||
aDataset.mComponents.mIsMeshLocalPrefixPresent = true;
|
||||
}
|
||||
|
||||
if (aNetworkName != NULL && strlen(aNetworkName) != 0)
|
||||
{
|
||||
strcpy_s(aDataset.mNetworkName.m8, sizeof(aDataset.mNetworkName.m8), aNetworkName);
|
||||
aDataset.mIsNetworkNameSet = true;
|
||||
aDataset.mComponents.mIsNetworkNamePresent = true;
|
||||
}
|
||||
|
||||
if (aBinary != NULL && strlen(aBinary) != 0)
|
||||
|
||||
Reference in New Issue
Block a user