From: Vitalii Irkha Date: Fri, 12 Jul 2019 11:23:07 +0000 (+0300) Subject: OCRemoveDeviceWithUuid doesn't change owned device X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6329da066a68b24f573dc0abbc4aedca103e584c;p=platform%2Fupstream%2Fiotivity.git OCRemoveDeviceWithUuid doesn't change owned device API should call SRPResetDevice() inside https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/539/commits/1211889827f00390219402eef5576b85347b6750 (cherry-picked from 1211889827f00390219402eef5576b85347b6750) Change-Id: If1dc94edcc340b49506a8c580324756708de4091 Signed-off-by: Vitalii Irkha Signed-off-by: Sudipto Bal --- diff --git a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c index 1a3f56c..a46843f 100644 --- a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c +++ b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c @@ -18,6 +18,7 @@ * * *****************************************************************/ #include +#include #include #include #include "ocprovisioningmanager.h" @@ -701,6 +702,16 @@ error: return res; } +#if !defined(MAX_WAIT_TIME) +#define MAX_WAIT_TIME 15 +#endif + +static int g_reset; +static void localResultCallback(void* ctx) +{ + OC_UNUSED(ctx); + g_reset = 0; +} /* * Function to device revocation * This function will remove credential of target device from all devices in subnet. @@ -726,7 +737,7 @@ OCStackResult OCRemoveDeviceWithUuid(void* ctx, unsigned short waitTimeForOwnedD if (!pTargetUuid || 0 == waitTimeForOwnedDeviceDiscovery) { - OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Invalied parameters"); + OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Invalid parameters"); return OC_STACK_INVALID_PARAM; } if (!resultCallback) @@ -770,41 +781,41 @@ OCStackResult OCRemoveDeviceWithUuid(void* ctx, unsigned short waitTimeForOwnedD } PDMDestoryOicUuidLinkList(linkedDevices); - //If there is no linked devices, device revocation step can be skipped. - if(0 != numOfLinkedDevices) + //2. Find owned device from the network + res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList); + if (OC_STACK_OK != res) { - OIC_LOG_V(INFO, TAG, "[%s] linked with other devices.", strUuid); - //2. Find owned device from the network - res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList); - if (OC_STACK_OK != res) - { - OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to PMDeviceDiscovery"); - goto error; - } + OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to PMDeviceDiscovery"); + goto error; + } - OCProvisionDev_t* tempDev = NULL; - LL_FOREACH(pOwnedDevList, tempDev) + OCProvisionDev_t* tempDev = NULL; + LL_FOREACH(pOwnedDevList, tempDev) + { + if(memcmp(&tempDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id)) == 0) { - if(memcmp(&tempDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id)) == 0) - { - break; - } + break; } + } - if(NULL == tempDev) - { - OIC_LOG_V(WARNING, TAG, "Can not find [%s] on the network.", strUuid); - OIC_LOG_V(WARNING, TAG, "[%s]'s information will be deleted from local and other devices.", strUuid); - } - else - { - OICFree(pTargetDev->doxm); - OICFree(pTargetDev); - pTargetDev = tempDev; - discoverdFlag = true; - OIC_LOG_V(INFO, TAG, "[%s] is dectected on the network.", strUuid); - } + if(NULL == tempDev) + { + OIC_LOG_V(WARNING, TAG, "Can not find [%s] on the network.", strUuid); + OIC_LOG_V(WARNING, TAG, "[%s]'s information will be deleted from local and other devices.", strUuid); + } + else + { + OICFree(pTargetDev->doxm); + OICFree(pTargetDev); + pTargetDev = tempDev; + discoverdFlag = true; + OIC_LOG_V(INFO, TAG, "[%s] is detected on the network.", strUuid); + } + //If there is no linked devices, device revocation step can be skipped. + if(0 != numOfLinkedDevices) + { + OIC_LOG_V(INFO, TAG, "[%s] linked with other devices.", strUuid); OIC_LOG_V(INFO, TAG, "Trying [%s] revocation.", strUuid); // Send DELETE requests to linked devices @@ -829,26 +840,28 @@ OCStackResult OCRemoveDeviceWithUuid(void* ctx, unsigned short waitTimeForOwnedD OIC_LOG(INFO, TAG, "Device discovery and SRPRemoveDevice will be skipped."); } - res = RemoveDeviceInfoFromLocal(pTargetDev); - if(OC_STACK_OK != res) + int maxWait = MAX_WAIT_TIME; + g_reset = 1; + + SRPResetDevice(pTargetDev, localResultCallback); + while(g_reset && maxWait) { - OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Filed to remove the device information from local."); - goto error; + sleep(1); + maxWait--; } if(OC_STACK_CONTINUE == resReq) { - /** - * If there is no linked device, PM does not send any request. - * So we should directly invoke the result callback to inform the result of OCRemoveDevice. - */ - if(resultCallback) - { - resultCallback(ctx, 0, NULL, false); - } + resultCallback(ctx, 0, NULL, false); res = OC_STACK_OK; } + res = RemoveDeviceInfoFromLocal(pTargetDev); + if(OC_STACK_OK != res) + { + OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to remove the device information from local."); + goto error; + } error: OICFree(strUuid); PMDeleteDeviceList(pOwnedDevList);