OCRemoveDeviceWithUuid doesn't change owned device 15/211015/1
authorVitalii Irkha <v.irkha@samsung.com>
Fri, 12 Jul 2019 11:23:07 +0000 (14:23 +0300)
committerSudipto Bal <sudipto.bal@samsung.com>
Mon, 29 Jul 2019 07:02:58 +0000 (12:32 +0530)
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 <v.irkha@samsung.com>
Signed-off-by: Sudipto Bal <sudipto.bal@samsung.com>
resource/csdk/security/provisioning/src/ocprovisioningmanager.c

index 1a3f56c..a46843f 100644 (file)
@@ -18,6 +18,7 @@
  *
  * *****************************************************************/
 #include <stdint.h>
+#include <unistd.h>
 #include <stdio.h>
 #include <string.h>
 #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);