[pskc] switch to using otPSKc struct (#3769)

This commit is contained in:
Jonathan Hui
2019-04-18 08:45:14 -07:00
committed by Jonathan Hui
parent 987e96ba0d
commit f46fbb844d
13 changed files with 52 additions and 51 deletions
+4 -8
View File
@@ -1619,7 +1619,7 @@ otThreadSetMasterKey(
}
OTAPI
const uint8_t *
const otPSKc *
OTCALL
otThreadGetPSKc(
_In_ otInstance *aInstance
@@ -1627,7 +1627,7 @@ otThreadGetPSKc(
{
if (aInstance == nullptr) return nullptr;
uint8_t *Result = (uint8_t*)malloc(sizeof(otPSKc));
otPSKc *Result = (otPSKc*)malloc(sizeof(otPSKc));
if (Result == nullptr) return nullptr;
if (QueryIOCTL(aInstance, IOCTL_OTLWF_OT_PSKC, Result) != ERROR_SUCCESS)
{
@@ -1642,16 +1642,12 @@ otError
OTCALL
otThreadSetPSKc(
_In_ otInstance *aInstance,
const uint8_t *aPSKc
const otPSKc *aPSKc
)
{
if (aInstance == nullptr) return OT_ERROR_INVALID_ARGS;
BYTE Buffer[sizeof(GUID) + sizeof(otPSKc)];
memcpy_s(Buffer, sizeof(Buffer), &aInstance->InterfaceGuid, sizeof(GUID));
memcpy_s(Buffer + sizeof(GUID), sizeof(Buffer) - sizeof(GUID), aPSKc, sizeof(otPSKc));
return DwordToThreadError(SendIOCTL(aInstance->ApiHandle, IOCTL_OTLWF_OT_PSKC, Buffer, sizeof(Buffer), nullptr, 0));
return DwordToThreadError(SetIOCTL(aInstance, IOCTL_OTLWF_OT_PSKC, aPSKc));
}
OTAPI
+2 -2
View File
@@ -1746,12 +1746,12 @@ otLwfIoCtl_otPSKc(
if (InBufferLength >= sizeof(otPSKc))
{
status = ThreadErrorToNtstatus(otThreadSetPSKc(pFilter->otCtx, InBuffer));
status = ThreadErrorToNtstatus(otThreadSetPSKc(pFilter->otCtx, (otPSKc*)InBuffer));
*OutBufferLength = 0;
}
else if (*OutBufferLength >= sizeof(otPSKc))
{
const uint8_t* aPSKc = otThreadGetPSKc(pFilter->otCtx);
const otPSKc* aPSKc = otThreadGetPSKc(pFilter->otCtx);
memcpy(OutBuffer, aPSKc, sizeof(otPSKc));
*OutBufferLength = sizeof(otPSKc);
status = STATUS_SUCCESS;
@@ -1256,14 +1256,15 @@ OTNODEAPI int32_t OTCALL otNodeSetPSKc(otNode* aNode, const char *aPSKc)
otLogFuncEntryMsg("[%d] %s", aNode->mId, aPSKc);
printf("%d: pskc %s\r\n", aNode->mId, aPSKc);
uint8_t pskc[OT_PSKC_MAX_SIZE];
if (Hex2Bin(aPSKc, pskc, sizeof(pskc)) != OT_PSKC_MAX_SIZE)
int pskcLength;
otPSKc pskc;
if ((pskcLength = Hex2Bin(aPSKc, pskc.m8, sizeof(aPSKc))) != OT_PSKC_MAX_SIZE)
{
printf("invalid pskc %s\r\n", aPSKc);
printf("invalid length pskd %d\r\n", pskcLength);
return OT_ERROR_PARSE;
}
auto error = otThreadSetPSKc(aNode->mInstance, pskc);
auto error = otThreadSetPSKc(aNode->mInstance, &pskc);
otLogFuncExit();
return error;
}
@@ -1278,7 +1279,7 @@ OTNODEAPI const char* OTCALL otNodeGetPSKc(otNode* aNode)
{
aNode->mMemoryToFree.push_back(str);
for (int i = 0; i < OT_PSKC_MAX_SIZE; i++)
sprintf_s(str + i * 2, strLength - (2 * i), "%02x", aPSKc[i]);
sprintf_s(str + i * 2, strLength - (2 * i), "%02x", aPSKc->m8[i]);
printf("%d: pskc\r\n%s\r\n", aNode->mId, str);
}
otFreeMemory(aPSKc);