Added SetDoxmDeviceId() API.
authorRandeep Singh <randeep.s@samsung.com>
Tue, 6 Sep 2016 12:42:34 +0000 (18:12 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 6 Sep 2016 14:10:39 +0000 (14:10 +0000)
 - Patch #1 : Initial upload.
 - Patch #2 : 1. Move the PDM related files to SRM layer.
              Becuase PDM PAI is required from DOXM to check owned device list.
              2. Add logic to check OTM state.

Change-Id: Ib21a2984fde0f1aa4fc98e5fc246d56ef15456c8
Signed-off-by: Chul Lee <chuls.lee@samsung.com>
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11283
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/security/SConscript
resource/csdk/security/include/internal/doxmresource.h [changed mode: 0755->0644]
resource/csdk/security/include/internal/provisioningdatabasemanager.h [moved from resource/csdk/security/provisioning/include/internal/provisioningdatabasemanager.h with 100% similarity]
resource/csdk/security/provisioning/SConscript
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/provisioningdatabasemanager.c [moved from resource/csdk/security/provisioning/src/provisioningdatabasemanager.c with 100% similarity]

index 4952d83..4abd6a0 100644 (file)
@@ -58,6 +58,9 @@ libocsrm_env.PrependUnique(CPPPATH = [
                '../security/provisioning/include'
                ])
 
+if env.get('SECURED') == '1' and target_os not in ['tizen']:
+       libocsrm_env.AppendUnique(CPPPATH = ['../../../extlibs/sqlite3'])
+
 if target_os not in ['arduino', 'windows']:
        libocsrm_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX'])
        libocsrm_env.AppendUnique(CFLAGS = ['-std=c99', '-Wall'])
@@ -112,6 +115,12 @@ libocsrm_src = [
        ]
 
 if env.get('SECURED') == '1':
+       libocsrm_src = libocsrm_src + [OCSRM_SRC + 'provisioningdatabasemanager.c']
+
+if env.get('SECURED') == '1' and target_os != 'tizen':
+       libocsrm_src = libocsrm_src + ['../../../extlibs/sqlite3/sqlite3.c']
+
+if env.get('SECURED') == '1':
        libocsrm_src  = libocsrm_src + [OCSRM_SRC + 'oxmpincommon.c', OCSRM_SRC + 'pbkdf2.c']
 
 if target_os in ['windows', 'msys_nt']:
old mode 100755 (executable)
new mode 100644 (file)
index f63a2b1..fb8843f
@@ -87,6 +87,14 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t * doxm, uint8_t **cborPayload
 OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID);
 
 /**
+ * This method changes the SRM device ID for this device.
+ * This api will update device Id iff device is in unowned state.
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID);
+
+
+/**
  * Gets the OicUuid_t value for the owner of this device.
  *
  * @param devownerid a pointer to be assigned to the devownerid property
index 96d59f3..7587370 100644 (file)
@@ -101,8 +101,7 @@ provisioning_src = [
        'src/secureresourceprovider.c',
        'src/ocprovisioningmanager.c',
        'src/oxmjustworks.c',
-       'src/oxmrandompin.c',
-       'src/provisioningdatabasemanager.c' ]
+       'src/oxmrandompin.c' ]
 
 if target_os != 'tizen':
        provisioning_src = provisioning_src + [root_dir+'/extlibs/sqlite3/sqlite3.c' ]
index 9aac585..ab17d77 100644 (file)
@@ -49,6 +49,8 @@
 #include "credresource.h"
 #include "srmutility.h"
 #include "pinoxmcommon.h"
+#include "pmtypes.h"
+#include "provisioningdatabasemanager.h"
 
 #define TAG  "SRM-DOXM"
 
@@ -1205,6 +1207,88 @@ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID)
     return OC_STACK_ERROR;
 }
 
+OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID)
+{
+    bool isPT = false;
+
+    if(NULL == deviceID)
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+    if(NULL == gDoxm)
+    {
+        OIC_LOG(ERROR, TAG, "Doxm resource is not initialized.");
+        return OC_STACK_NO_RESOURCE;
+    }
+
+    //Check the device's OTM state
+
+#ifdef __WITH_DTLS__
+    //for PT.
+    if(true == gDoxm->owned &&
+       memcmp(gDoxm->deviceID.id, gDoxm->owner.id, sizeof(gDoxm->owner.id)) == 0)
+    {
+        OCUuidList_t* ownedDevices = NULL;
+        size_t* ownedDevNum = 0;
+
+        if(OC_STACK_OK == PDMGetOwnedDevices(&ownedDevices, &ownedDevNum))
+        {
+            OCUuidList_t* temp1 = NULL;
+            OCUuidList_t* temp2 = NULL;
+            LL_FOREACH_SAFE(ownedDevices, temp1, temp2)
+            {
+                LL_DELETE(ownedDevices, temp1);
+                OICFree(temp1);
+            }
+
+            if(0 != ownedDevNum)
+            {
+                OIC_LOG(ERROR, TAG, "This device has ownership for other device.");
+                OIC_LOG(ERROR, TAG, "Device UUID cannot be changed to guarantee the reliability of the connection.");
+                return OC_STACK_ERROR;
+            }
+        }
+
+        isPT = true;
+    }
+    //for normal device.
+    else if(true == gDoxm->owned)
+    {
+        OIC_LOG(ERROR, TAG, "This device owned by owner's device.");
+        OIC_LOG(ERROR, TAG, "Device UUID cannot be changed to guarantee the reliability of the connection.");
+        return OC_STACK_ERROR;
+    }
+#endif //__WITH_DTLS
+
+    //Save the previous UUID
+    OicUuid_t tempUuid;
+    memcpy(tempUuid.id, gDoxm->deviceID.id, sizeof(tempUuid.id));
+
+    //Change the UUID
+    memcpy(gDoxm->deviceID.id, deviceID->id, sizeof(deviceID->id));
+    if(isPT)
+    {
+        memcpy(gDoxm->owner.id, deviceID->id, sizeof(deviceID->id));
+        memcpy(gDoxm->rownerID.id, deviceID->id, sizeof(deviceID->id));
+    }
+
+    //Update PS
+    if(!UpdatePersistentStorage(gDoxm))
+    {
+        //revert UUID in case of update error
+        memcpy(gDoxm->deviceID.id, tempUuid.id, sizeof(tempUuid.id));
+        if(isPT)
+        {
+            memcpy(gDoxm->owner.id, tempUuid.id, sizeof(tempUuid.id));
+            memcpy(gDoxm->rownerID.id, tempUuid.id, sizeof(tempUuid.id));
+        }
+
+        OIC_LOG(ERROR, TAG, "Failed to update persistent storage");
+        return OC_STACK_ERROR;
+    }
+    return OC_STACK_OK;
+}
+
 OCStackResult GetDoxmDevOwnerId(OicUuid_t *devownerid)
 {
     OCStackResult retVal = OC_STACK_ERROR;