mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 08:40:06 +00:00
Automatic Joiners removal in Commissioner (#1421)
* Implement automatic Joiner removal feature. * Save some RAM in JoinerRouter class. * Specify timeout for each Joiner separately. * Update Windows API files.
This commit is contained in:
committed by
Jonathan Hui
parent
6eaacdd4a4
commit
746a40a340
@@ -602,6 +602,7 @@ typedef struct otCommissionConfig
|
||||
// uint8_t - aExtAddressValid
|
||||
// otExtAddress - aExtAddress (optional)
|
||||
// char[OPENTHREAD_PSK_MAX_LENGTH + 1] - aPSKd
|
||||
// uint32_t - aTimeout
|
||||
|
||||
#define IOCTL_OTLWF_OT_COMMISIONER_REMOVE_JOINER \
|
||||
OTLWF_CTL_CODE(181, METHOD_BUFFERED, FILE_WRITE_DATA)
|
||||
|
||||
@@ -3513,7 +3513,8 @@ OTCALL
|
||||
otCommissionerAddJoiner(
|
||||
_In_ otInstance *aInstance,
|
||||
const otExtAddress *aExtAddress,
|
||||
const char *aPSKd
|
||||
const char *aPSKd,
|
||||
uint32_t aTimeout
|
||||
)
|
||||
{
|
||||
if (aInstance == nullptr || aPSKd == nullptr) return kThreadError_InvalidArgs;
|
||||
@@ -3526,13 +3527,14 @@ otCommissionerAddJoiner(
|
||||
|
||||
uint8_t aExtAddressValid = aExtAddress ? 1 : 0;
|
||||
|
||||
const ULONG BufferLength = sizeof(GUID) + sizeof(uint8_t) + sizeof(otExtAddress) + (ULONG)aPSKdLength + 1;
|
||||
BYTE Buffer[sizeof(GUID) + sizeof(uint8_t) + sizeof(otExtAddress) + OPENTHREAD_PSK_MAX_LENGTH + 1] = {0};
|
||||
const ULONG BufferLength = sizeof(GUID) + sizeof(uint8_t) + sizeof(otExtAddress) + (ULONG)aPSKdLength + 1 + sizeof(aTimeout);
|
||||
BYTE Buffer[sizeof(GUID) + sizeof(uint8_t) + sizeof(otExtAddress) + OPENTHREAD_PSK_MAX_LENGTH + 1 + sizeof(aTimeout)] = {0};
|
||||
memcpy_s(Buffer, sizeof(Buffer), &aInstance->InterfaceGuid, sizeof(GUID));
|
||||
memcpy_s(Buffer + sizeof(GUID), sizeof(Buffer) - sizeof(GUID), &aExtAddressValid, sizeof(aExtAddressValid));
|
||||
if (aExtAddressValid)
|
||||
memcpy_s(Buffer + sizeof(GUID) + sizeof(uint8_t), sizeof(Buffer) - sizeof(GUID) - sizeof(uint8_t), aExtAddress, sizeof(otExtAddress));
|
||||
memcpy_s(Buffer + sizeof(GUID) + sizeof(uint8_t) + sizeof(otExtAddress), sizeof(Buffer) - sizeof(GUID) - sizeof(uint8_t) - sizeof(otExtAddress), aPSKd, aPSKdLength);
|
||||
memcpy_s(Buffer + sizeof(GUID) + sizeof(uint8_t) + sizeof(otExtAddress) + aPSKdLength + 1, sizeof(Buffer) - sizeof(GUID) - sizeof(uint8_t) - sizeof(otExtAddress) - aPSKdLength - 1, &aTimeout, sizeof(aTimeout));
|
||||
|
||||
return DwordToThreadError(SendIOCTL(aInstance->ApiHandle, IOCTL_OTLWF_OT_COMMISIONER_ADD_JOINER, Buffer, BufferLength, nullptr, 0));
|
||||
}
|
||||
|
||||
@@ -5596,19 +5596,20 @@ otLwfIoCtl_otCommissionerAddJoiner(
|
||||
|
||||
if (InBufferLength >= sizeof(uint8_t) + sizeof(otExtAddress))
|
||||
{
|
||||
const ULONG aPSKdBufferLength = InBufferLength - sizeof(uint8_t) - sizeof(otExtAddress);
|
||||
const ULONG aPSKdBufferLength = InBufferLength - sizeof(uint8_t) - sizeof(otExtAddress) - sizeof(uint32_t);
|
||||
|
||||
if (aPSKdBufferLength <= OPENTHREAD_PSK_MAX_LENGTH + 1)
|
||||
{
|
||||
uint8_t aExtAddressValid = *(uint8_t*)InBuffer;
|
||||
const otExtAddress *aExtAddress = aExtAddressValid == 0 ? NULL : (otExtAddress*)(InBuffer + sizeof(uint8_t));
|
||||
char *aPSKd = (char*)(InBuffer + sizeof(uint8_t) + sizeof(otExtAddress));
|
||||
uint32_t aTimeout = *(uint32_t*)(InBuffer + sizeof(uint8_t) + sizeof(otExtAddress) + aPSKdBufferLength);
|
||||
|
||||
// Ensure aPSKd is NULL terminated in the buffer
|
||||
if (strnlen(aPSKd, aPSKdBufferLength) < aPSKdBufferLength)
|
||||
{
|
||||
status = ThreadErrorToNtstatus(otCommissionerAddJoiner(
|
||||
pFilter->otCtx, aExtAddress, aPSKd));
|
||||
pFilter->otCtx, aExtAddress, aPSKd, aTimeout));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1010,11 +1010,13 @@ OTNODEAPI int32_t OTCALL otNodeCommissionerJoinerAdd(otNode* aNode, const char *
|
||||
otLogFuncEntryMsg("[%d] %s %s", aNode->mId, aExtAddr, aPSKd);
|
||||
printf("%d: commissioner joiner add %s %s\r\n", aNode->mId, aExtAddr, aPSKd);
|
||||
|
||||
const uint32_t kDefaultJoinerTimeout = 120;
|
||||
|
||||
ThreadError error;
|
||||
|
||||
if (strcmp(aExtAddr, "*") == 0)
|
||||
{
|
||||
error = otCommissionerAddJoiner(aNode->mInstance, nullptr, aPSKd);
|
||||
error = otCommissionerAddJoiner(aNode->mInstance, nullptr, aPSKd, kDefaultJoinerTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1022,7 +1024,7 @@ OTNODEAPI int32_t OTCALL otNodeCommissionerJoinerAdd(otNode* aNode, const char *
|
||||
if (Hex2Bin(aExtAddr, extAddr.m8, sizeof(extAddr)) != sizeof(extAddr))
|
||||
return kThreadError_Parse;
|
||||
|
||||
error = otCommissionerAddJoiner(aNode->mInstance, &extAddr, aPSKd);
|
||||
error = otCommissionerAddJoiner(aNode->mInstance, &extAddr, aPSKd, kDefaultJoinerTimeout);
|
||||
}
|
||||
|
||||
otLogFuncExit();
|
||||
|
||||
Reference in New Issue
Block a user