svace fixes
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / src / ownershiptransfermanager.c
index 781567b..4a9021a 100644 (file)
@@ -853,7 +853,12 @@ static OCStackResult SaveOwnerPSK(OCProvisionDev_t *selectedDeviceInfo)
 
         OICFree( cred->privateData.data );
         cred->privateData.data = (uint8_t *)OICCalloc(1, outSize + 1);
-        VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR);
+        if (cred->privateData.data == NULL)
+            {
+                OICFree(b64Buf);
+                res = OC_STACK_ERROR;
+                goto exit;
+            }
 
         strncpy((char*)(cred->privateData.data), b64Buf, outSize);
         cred->privateData.data[outSize] = '\0';
@@ -1524,6 +1529,7 @@ static OCStackApplicationResult ReadyForNomalStatusHandler(void *ctx, OCDoHandle
     if (OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         OIC_LOG(INFO, TAG, "Device state is in Ready for Normal Operation.");
+        OTMStop(&otmCtx->selectedDeviceInfo->doxm->deviceID);
         OCStackResult res = PDMSetDeviceState(&otmCtx->selectedDeviceInfo->doxm->deviceID,
                                               PDM_DEVICE_ACTIVE);
          if (OC_STACK_OK == res)
@@ -1584,6 +1590,7 @@ static OCStackResult PostOwnerCredential(OTMContext_t* otmCtx)
     if(!ownerCredential)
     {
         OIC_LOG(ERROR, TAG, "Can not find OwnerPSK.");
+        OICFree(secPayload);
         return OC_STACK_NO_RESOURCE;
     }
 
@@ -2193,6 +2200,19 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte
         memcpy(&(selectedDevice->doxm->owner), &emptyOwner, sizeof(OicUuid_t));
     }
 
+    OicUuid_t ownerUuid = {0};
+    GetDoxmDevOwnerId(&ownerUuid);
+
+    res = OTMStart(&selectedDevice->doxm->deviceID, &ownerUuid);
+    if(OC_STACK_OK != res)
+    {
+        if(OC_STACK_DUPLICATE_UUID == res)
+        {
+            return res;
+        }
+        OIC_LOG_V(ERROR, TAG, "%s OTMStart error : %d", __func__, res);
+    }
+
     //Setup PDM to perform the OTM, PDM will be cleanup if necessary.
     res = SetupPDM(selectedDevice);
     if(OC_STACK_OK != res)
@@ -2255,6 +2275,19 @@ static OCStackResult StartCustomOwnershipTransfer(void* ctx, OCProvisionDev_t* s
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
     otmCtx->selectedDeviceInfo = selectedDevice;
 
+    OicUuid_t ownerUuid = {0};
+    GetDoxmDevOwnerId(&ownerUuid);
+
+    res = OTMStart(&selectedDevice->doxm->deviceID, &ownerUuid);
+    if(OC_STACK_OK != res)
+    {
+        if(OC_STACK_DUPLICATE_UUID == res)
+        {
+            return res;
+        }
+        OIC_LOG_V(ERROR, TAG, "%s OTMStart error : %d", __func__, res);
+    }
+
     //Setup PDM to perform the OTM, PDM will be cleanup if necessary.
     res = SetupPDM(selectedDevice);
     if(OC_STACK_OK != res)