Merge tizen_5.0 codes into tizen_4.0
[platform/upstream/iotivity.git] / resource / csdk / security / src / pconfresource.c
index 725adda..3404a16 100644 (file)
  *
  * *****************************************************************/
 
+#include "iotivity_config.h"
 #include <stdlib.h>
 #include <string.h>
 #include "ocstack.h"
 #include "logger.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
+#if defined (__TIZENRT__)
+#include <apps/netutils/cJSON.h>
+#else
 #include "cJSON.h"
+#endif
 #include "base64.h"
 #include "ocpayload.h"
+#include "ocpayloadcbor.h"
 #include "payload_logging.h"
 #include "resourcemanager.h"
 #include "pconfresource.h"
 #include "doxmresource.h"
 #include "srmutility.h"
 #include "ocserverrequest.h"
-#include <stdlib.h>
 #include "psinterface.h"
 #include "security_internals.h"
-#ifdef WITH_ARDUINO
-#include <string.h>
-#else
+#ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
 
-#define TAG  "SRM-PCONF"
+#define TAG  "OIC_SRM_PCONF"
 
 static const uint16_t CBOR_SIZE = 1024;
 static const uint64_t CBOR_MAX_SIZE = 4400;
 static const uint8_t  PCONF_MAP_SIZE = 4;
-static const uint8_t  PCONF_RESOURCE_MAP_SIZE = 3;
+static const uint8_t  PCONF_RESOURCE_MAP_SIZE = 4;
 
 static OicSecPconf_t          *gPconf = NULL;
 static OCResourceHandle   gPconfHandle = NULL;
@@ -168,8 +171,8 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     *payload = NULL;
 
     OCStackResult ret = OC_STACK_ERROR;
-    CborEncoder encoder = { {.ptr = NULL}, .end = 0};
-    CborEncoder pconfMap = { {.ptr = NULL}, .end = 0};
+    CborEncoder encoder;
+    CborEncoder pconfMap;
 
     int64_t cborEncoderResult = CborNoError;
     uint8_t mapSize = PCONF_MAP_SIZE;
@@ -204,7 +207,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     //PRM type -- Not Mandatory
     if(pconf->prmLen > 0)
     {
-        CborEncoder prm = { {.ptr = NULL }, .end = 0 };
+        CborEncoder prm;
         cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_PRM_NAME,
                 strlen(OIC_JSON_PRM_NAME));
         VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Convert Pconf PRM NAME");
@@ -231,7 +234,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     if (pconf->pdacls)
     {
         OicSecPdAcl_t *pdacl = pconf->pdacls;
-        CborEncoder pdAclArray = {{.ptr = NULL }, .end = 0 };
+        CborEncoder pdAclArray;
         cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_PDACL_NAME,
                 strlen(OIC_JSON_PDACL_NAME));
         VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create OIC_JSON_PDACL_NAME");
@@ -241,7 +244,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
 
         while(pdacl)
         {
-            CborEncoder pdAclMap = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+            CborEncoder pdAclMap;
             // PDACL Map size - Number of mandatory items
             uint8_t aclMapSize = 2;
 
@@ -262,14 +265,14 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
                     strlen(OIC_JSON_RESOURCES_NAME));
             VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult,  "Failed to encode resource result");
 
-            CborEncoder resources = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+            CborEncoder resources;
             cborEncoderResult = cbor_encoder_create_array(&pdAclMap, &resources,
                     pdacl->resourcesLen);
             VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult,  "Failed to create resource array");
 
             for (size_t i = 0; i < pdacl->resourcesLen; i++)
             {
-                CborEncoder rMap = { {.ptr = NULL }, .end = 0 };
+                CborEncoder rMap;
                 cborEncoderResult = cbor_encoder_create_map(&resources, &rMap,
                         PCONF_RESOURCE_MAP_SIZE);
                 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding Resource Map.");
@@ -281,6 +284,15 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
                         strlen(pdacl->resources[i]));
                 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding HREF Value in Map.");
 
+                cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_REL_NAME,
+                        strlen(OIC_JSON_REL_NAME));
+                VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding REL Name Tag.");
+
+                // TODO : Need to assign real value of REL
+                cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_EMPTY_STRING,
+                        strlen(OIC_JSON_EMPTY_STRING));
+                VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding REL Value.");
+
                 cborEncoderResult = cbor_encode_text_string(&rMap, OIC_JSON_RT_NAME,
                         strlen(OIC_JSON_RT_NAME));
                 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding RT Name Tag.");
@@ -316,7 +328,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
             // Period -- Not Mandatory
             if (pdacl->periods)
             {
-                CborEncoder period = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+                CborEncoder period;
                 cborEncoderResult = cbor_encode_text_string(&pdAclMap, OIC_JSON_PERIODS_NAME,
                         strlen(OIC_JSON_PERIODS_NAME));
                 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode period value");
@@ -337,7 +349,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
             // Period -- Not Mandatory
             if(0 != pdacl->prdRecrLen && pdacl->recurrences)
             {
-                CborEncoder recurrences = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+                CborEncoder recurrences;
                 cborEncoderResult = cbor_encode_text_string(&pdAclMap, OIC_JSON_RECURRENCES_NAME,
                         strlen(OIC_JSON_RECURRENCES_NAME));
                 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult,"Failed to encode recurrences");
@@ -368,7 +380,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     //There may not be paired devices if it did not pairing before
     if (pconf->pddevs && 0 < pconf->pddevLen)
     {
-        CborEncoder pddev = { {.ptr = NULL }, .end = 0, .added = 0, .flags = 0 };
+        CborEncoder pddev;
         cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_PDDEV_LIST_NAME,
                 strlen(OIC_JSON_PDDEV_LIST_NAME));
         VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode pddev");
@@ -389,7 +401,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     }
 
     //DeviceId -- Mandatory
-    //There may not be devicd id if caller is provisoning tool
+    //There may not be devicd id if caller is provisioning tool
     cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_DEVICE_ID_NAME,
             strlen(OIC_JSON_DEVICE_ID_NAME));
     VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode device id");
@@ -403,12 +415,12 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     }
 
     //ROwner -- Mandatory
-    cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_ROWNERID_NAME,
-            strlen(OIC_JSON_ROWNERID_NAME));
-    VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode rowner string");
     {
         char *rowner = NULL;
-        ret = ConvertUuidToStr(&pconf->rowner, &rowner);
+        cborEncoderResult = cbor_encode_text_string(&pconfMap, OIC_JSON_ROWNERID_NAME,
+                strlen(OIC_JSON_ROWNERID_NAME));
+        VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode rowner string");
+        ret = ConvertUuidToStr(&pconf->rownerID, &rowner);
         VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
         cborEncoderResult = cbor_encode_text_string(&pconfMap, rowner, strlen(rowner));
         VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to encode rwoner value");
@@ -418,7 +430,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     cborEncoderResult = cbor_encoder_close_container(&encoder, &pconfMap);
     VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to close pconfMap");
 
-    *size = encoder.ptr - outPayload;
+    *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
     *payload = outPayload;
     ret = OC_STACK_OK;
 exit:
@@ -427,7 +439,7 @@ exit:
         // reallocate and try again!
         OICFree(outPayload);
         // Since the allocated initial memory failed, double the memory.
-        cborLen += encoder.ptr - encoder.end;
+        cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
         cborEncoderResult = CborNoError;
         ret = PconfToCBORPayload(pconf, payload, &cborLen);
         *size = cborLen;
@@ -454,9 +466,8 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
     CborValue pconfCbor = { .parser = NULL };
     CborParser parser = { .end = NULL };
     CborError cborFindResult = CborNoError;
-    int cborLen = size;
 
-    cbor_parser_init(cborPayload, cborLen, 0, &parser, &pconfCbor);
+    cbor_parser_init(cborPayload, size, 0, &parser, &pconfCbor);
     CborValue pconfMap = { .parser = NULL } ;
     OicSecPconf_t *pconf = NULL;
     cborFindResult = cbor_value_enter_container(&pconfCbor, &pconfMap);
@@ -468,7 +479,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
         char *name = NULL;
         size_t len = 0;
         CborType type = cbor_value_get_type(&pconfMap);
-        if (type == CborTextStringType)
+        if (type == CborTextStringType && cbor_value_is_text_string(&pconfMap))
         {
             cborFindResult = cbor_value_dup_text_string(&pconfMap, &name, &len, NULL);
             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
@@ -479,7 +490,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
         if (name)
         {
             //EDP -- Mandatory
-            if(0 == strcmp(OIC_JSON_EDP_NAME, name))
+            if(0 == strcmp(OIC_JSON_EDP_NAME, name) && cbor_value_is_boolean(&pconfMap))
             {
                 cborFindResult = cbor_value_get_boolean(&pconfMap, &pconf->edp);
                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
@@ -497,16 +508,19 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                 cborFindResult = cbor_value_enter_container(&pconfMap, &prm);
                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to eneter array");
 
-                while (cbor_value_is_valid(&prm))
+                while (cbor_value_is_valid(&prm) && cbor_value_is_integer(&prm))
                 {
-                    cborFindResult = cbor_value_get_int(&prm, (int *)&pconf->prm[i++]);
+                    int prm_val;
+
+                    cborFindResult = cbor_value_get_int(&prm, &prm_val);
                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
+                    pconf->prm[i++] = (OicSecPrm_t)prm_val;
                     cborFindResult = cbor_value_advance(&prm);
                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance value");
                 }
             }
             //PIN -- Mandatory
-            if (0 == strcmp(OIC_JSON_PIN_NAME, name))
+            if (0 == strcmp(OIC_JSON_PIN_NAME, name) && cbor_value_is_byte_string(&pconfMap))
             {
                 uint8_t *pin = NULL;
                 cborFindResult = cbor_value_dup_byte_string(&pconfMap, &pin, &len, NULL);
@@ -538,7 +552,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                         char* name = NULL;
                         size_t len = 0;
                         CborType type = cbor_value_get_type(&pdAclMap);
-                        if (type == CborTextStringType)
+                        if (type == CborTextStringType && cbor_value_is_text_string(&pdAclMap))
                         {
                             cborFindResult = cbor_value_dup_text_string(&pdAclMap, &name,
                                     &len, NULL);
@@ -549,7 +563,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                         if (name)
                         {
                             // Resources -- Mandatory
-                            if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0)
+                            if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
                             {
                                 int i = 0;
                                 CborValue resources = { .parser = NULL };
@@ -568,7 +582,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                     cborFindResult = cbor_value_enter_container(&resources, &rMap);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering Resource Map");
 
-                                    while(cbor_value_is_valid(&rMap))
+                                    while(cbor_value_is_valid(&rMap) && cbor_value_is_text_string(&rMap))
                                     {
                                         char *rMapName = NULL;
                                         size_t rMapNameLen = 0;
@@ -585,6 +599,16 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Href Value.");
                                         }
 
+                                        // "rel"
+                                        if (0 == strcmp(OIC_JSON_REL_NAME, rMapName))
+                                        {
+                                            // TODO : Need to check data structure of OicSecPdAcl_t and assign based on RAML spec.
+                                            char *relData = NULL;
+                                            cborFindResult = cbor_value_dup_text_string(&rMap, &relData, &len, NULL);
+                                            VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding REL Value.");
+                                            OICFree(relData);
+                                        }
+
                                         // "rt"
                                         if (0 == strcmp(OIC_JSON_RT_NAME, rMapName))
                                         {
@@ -622,15 +646,16 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                             }
 
                             // Permissions -- Mandatory
-                            if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0)
+                            if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0 && cbor_value_is_unsigned_integer(&pdAclMap))
                             {
-                                cborFindResult = cbor_value_get_uint64(&pdAclMap,
-                                        (uint64_t *) &pdacl->permission);
+                                uint64_t permission = 0;
+                                cborFindResult = cbor_value_get_uint64(&pdAclMap, &permission);
+                                pdacl->permission = (uint16_t)permission;
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
                             }
 
                             // Period -- Not mandatory
-                            if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0)
+                            if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0 && cbor_value_is_array(&pdAclMap))
                             {
                                 int i = 0;
                                 CborValue period = { .parser = NULL };
@@ -642,7 +667,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                 pdacl->periods = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*));
                                 VERIFY_NON_NULL(TAG, pdacl->periods, ERROR);
 
-                                while (cbor_value_is_text_string(&period))
+                                while (cbor_value_is_text_string(&period) && cbor_value_is_text_string(&period))
                                 {
                                     cborFindResult = cbor_value_dup_text_string(&period,
                                             &pdacl->periods[i++], &len, NULL);
@@ -654,7 +679,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                             }
 
                             // Recurrence -- Not mandatory
-                            if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0)
+                            if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
                             {
                                 int i = 0;
                                 CborValue recurrences = { .parser = NULL };
@@ -665,7 +690,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                 pdacl->recurrences = (char **) OICCalloc(pdacl->prdRecrLen, sizeof(char*));
                                 VERIFY_NON_NULL(TAG, pdacl->recurrences, ERROR);
 
-                                while (cbor_value_is_text_string(&recurrences))
+                                while (cbor_value_is_text_string(&recurrences) && cbor_value_is_text_string(&recurrences))
                                 {
                                     cborFindResult = cbor_value_dup_text_string(&recurrences,
                                             &pdacl->recurrences[i++], &len, NULL);
@@ -707,7 +732,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
             }
 
             //PDDev -- Mandatory
-            if (strcmp(name, OIC_JSON_PDDEV_LIST_NAME) == 0)
+            if (strcmp(name, OIC_JSON_PDDEV_LIST_NAME) == 0 && cbor_value_is_array(&pconfMap))
             {
                 int i = 0;
                 CborValue pddevs = { .parser = NULL };
@@ -718,7 +743,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
 
                 pconf->pddevs = (OicUuid_t *)OICMalloc(pconf->pddevLen * sizeof(OicUuid_t));
                 VERIFY_NON_NULL(TAG, pconf->pddevs, ERROR);
-                while (cbor_value_is_valid(&pddevs))
+                while (cbor_value_is_valid(&pddevs) && cbor_value_is_text_string(&pddevs))
                 {
                     char *pddev = NULL;
                     cborFindResult = cbor_value_dup_text_string(&pddevs, &pddev, &len, NULL);
@@ -732,7 +757,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
             }
 
             //Mandatory - Device Id
-            if (0 == strcmp(OIC_JSON_DEVICE_ID_NAME, name))
+            if (0 == strcmp(OIC_JSON_DEVICE_ID_NAME, name) && cbor_value_is_text_string(&pconfMap))
             {
                 char *deviceId = NULL;
                 cborFindResult = cbor_value_dup_text_string(&pconfMap, &deviceId, &len, NULL);
@@ -743,12 +768,12 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
             }
 
             // ROwner -- Mandatory
-            if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name))
+            if (0 == strcmp(OIC_JSON_ROWNERID_NAME, name) && cbor_value_is_text_string(&pconfMap))
             {
                 char *rowner = NULL;
                 cborFindResult = cbor_value_dup_text_string(&pconfMap, &rowner, &len, NULL);
                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get rowner");
-                ret = ConvertStrToUuid(rowner, &pconf->rowner);
+                ret = ConvertStrToUuid(rowner, &pconf->rownerID);
                 VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
                 OICFree(rowner);
             }
@@ -797,6 +822,7 @@ static OCEntityHandlerResult HandlePconfGetRequest (const OCEntityHandlerRequest
 {
     uint8_t* payload = NULL;
     size_t size = 0;
+    const OicSecDoxm_t *m_doxm = NULL;
     OCEntityHandlerResult ehRet = OC_EH_OK;
 
     OicSecPconf_t pconf;
@@ -804,23 +830,31 @@ static OCEntityHandlerResult HandlePconfGetRequest (const OCEntityHandlerRequest
 
     OIC_LOG (DEBUG, TAG, "Pconf EntityHandle processing GET request");
 
-    if (true == GetDoxmResourceData()->dpc)
+    m_doxm = GetDoxmResourceData();
+    if (NULL == m_doxm)
+    {
+      OIC_LOG (DEBUG, TAG, "Doxm resource Data is NULL");
+    }
+
+    if ((m_doxm) && (true == m_doxm->dpc))
     {
         //Making response elements for Get request
-        if( (true == gPconf->edp) && (gPconf->prm && 0 < gPconf->prmLen) &&
-                (0 < strlen((const char*)gPconf->deviceID.id)) && (0 < strlen((const char*)gPconf->rowner.id)))
+        if( (true == gPconf->edp) &&
+            (gPconf->prm && 0 < gPconf->prmLen) &&
+            (0 < strlen((const char*)gPconf->deviceID.id)) &&
+            (0 < strlen((const char*)gPconf->rownerID.id)))
         {
             pconf.edp = true;
             pconf.prm = gPconf->prm;
             pconf.prmLen = gPconf->prmLen;
             memcpy(&pconf.deviceID, &gPconf->deviceID, sizeof(OicUuid_t));
-            memcpy(&pconf.rowner, &gPconf->rowner, sizeof(OicUuid_t));
+            memcpy(&pconf.rownerID, &gPconf->rownerID, sizeof(OicUuid_t));
             OIC_LOG (DEBUG, TAG, "PCONF - direct pairing enabled");
         }
         else if (false == gPconf->edp)
         {
             pconf.edp = false;
-            memcpy(&pconf.rowner, &gPconf->rowner, sizeof(OicUuid_t));
+            memcpy(&pconf.rownerID, &gPconf->rownerID, sizeof(OicUuid_t));
             OIC_LOG (DEBUG, TAG, "PCONF - direct pairing disable");
         }
         else
@@ -852,9 +886,14 @@ static OCEntityHandlerResult HandlePconfGetRequest (const OCEntityHandlerRequest
     }
 
     // Send response payload to request originator
-    SendSRMCBORResponse(ehRequest, ehRet, payload, size);
+    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
+    {
+        ehRet = OC_EH_ERROR;
+        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandlePconfGetRequest");
+    }
     OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
 
+    OICFree(payload);
     return ehRet;
 }
 
@@ -864,10 +903,10 @@ static OCEntityHandlerResult HandlePconfPostRequest (const OCEntityHandlerReques
     OCStackResult res=OC_STACK_OK;
     OicSecPconf_t* newPconf = NULL;
 
-    if (true == GetDoxmResourceData()->dpc)
+    if (NULL != GetDoxmResourceData() && true == GetDoxmResourceData()->dpc)
     {
         // Convert CBOR PCONF data into binary. This will also validate the PCONF data received.
-        uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData1;
+        uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
         size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
 
         if(payload){
@@ -884,7 +923,7 @@ static OCEntityHandlerResult HandlePconfPostRequest (const OCEntityHandlerReques
     {
         // Check if valid Post request
         if ((true == newPconf->edp) && (0 < newPconf->prmLen) &&
-                DP_PIN_LENGTH == sizeof((const char*)newPconf->pin.val))
+                DP_PIN_LENGTH == sizeof(newPconf->pin.val))
         {
             OicSecPrm_t *oldPrm = gPconf->prm;
             OicSecPdAcl_t *oldPdacl = gPconf->pdacls;
@@ -895,7 +934,7 @@ static OCEntityHandlerResult HandlePconfPostRequest (const OCEntityHandlerReques
             gPconf->prm = newPconf->prm;
             gPconf->prmLen = newPconf->prmLen;
             gPconf->pdacls = newPconf->pdacls;
-            memcpy(&gPconf->rowner, &newPconf->rowner, sizeof(OicUuid_t));
+            memcpy(&gPconf->rownerID, &newPconf->rownerID, sizeof(OicUuid_t));
 
             // to delete old value(prm, pdacl)
             newPconf->prm = oldPrm;
@@ -913,7 +952,7 @@ static OCEntityHandlerResult HandlePconfPostRequest (const OCEntityHandlerReques
         // Update storage
         if(OC_EH_ERROR != ehRet && true == UpdatePersistentStorage(gPconf))
         {
-            ehRet = OC_EH_RESOURCE_CREATED;
+            ehRet = OC_EH_CHANGED;
         }
 
         DeletePconfBinData(newPconf);
@@ -924,7 +963,11 @@ static OCEntityHandlerResult HandlePconfPostRequest (const OCEntityHandlerReques
     }
 
     // Send payload to request originator
-    SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
+    if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
+    {
+        ehRet = OC_EH_ERROR;
+        OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandlePconfPostRequest");
+    }
 
     OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
     return ehRet;
@@ -965,7 +1008,7 @@ OCEntityHandlerResult PconfEntityHandler (OCEntityHandlerFlag flag,
 
             default:
                 ehRet = OC_EH_ERROR;
-                SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
+                SendSRMResponse(ehRequest, ehRet, NULL, 0);
         }
     }
 
@@ -981,7 +1024,7 @@ OCStackResult CreatePconfResource()
 
     ret = OCCreateResource(&gPconfHandle,
                            OIC_RSRC_TYPE_SEC_PCONF,
-                           OIC_MI_DEF,
+                           OC_RSRVD_INTERFACE_DEFAULT,
                            OIC_RSRC_PCONF_URI,
                            PconfEntityHandler,
                            NULL,
@@ -1210,3 +1253,52 @@ bool IsPairedDevice(const OicUuid_t* pdeviceId)
     }
     return false;
 }
+
+OCStackResult SetPconfRownerId(const OicUuid_t* newROwner)
+{
+    OCStackResult ret = OC_STACK_ERROR;
+    uint8_t *cborPayload = NULL;
+    size_t size = 0;
+    OicUuid_t prevId = {.id={0}};
+
+    if(NULL == newROwner)
+    {
+        ret = OC_STACK_INVALID_PARAM;
+    }
+    if(NULL == gPconf)
+    {
+        ret = OC_STACK_NO_RESOURCE;
+    }
+
+    if(newROwner && gPconf)
+    {
+        memcpy(prevId.id, gPconf->rownerID.id, sizeof(prevId.id));
+        memcpy(gPconf->rownerID.id, newROwner->id, sizeof(newROwner->id));
+
+        ret = PconfToCBORPayload(gPconf, &cborPayload, &size);
+        VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
+
+        ret = UpdateSecureResourceInPS(OIC_JSON_PCONF_NAME, cborPayload, size);
+        VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
+
+        OICFree(cborPayload);
+    }
+
+    return ret;
+
+exit:
+    OICFree(cborPayload);
+    memcpy(gPconf->rownerID.id, prevId.id, sizeof(prevId.id));
+    return ret;
+}
+
+OCStackResult GetPconfRownerId(OicUuid_t *rowneruuid)
+{
+    OCStackResult retVal = OC_STACK_ERROR;
+    if (gPconf)
+    {
+        *rowneruuid = gPconf->rownerID;
+        retVal = OC_STACK_OK;
+    }
+    return retVal;
+}