*
* *****************************************************************/
#include <stdint.h>
+#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "ocprovisioningmanager.h"
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.
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)
}
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
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);