Merge branch '1.3-rel' (5fdb8a1)
[iotivity.git] / service / easy-setup / enrollee / src / resourcehandler.c
old mode 100755 (executable)
new mode 100644 (file)
index 415b2c6..54b75f2
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include "resourcehandler.h"
+#include "internal/es_util.h"
 
 #include "ocpayload.h"
 #include "oic_string.h"
 #include "oic_malloc.h"
 #include "cautilinterface.h"
+#include "experimental/payload_logging.h"
+
+// TODO: Remove this flag and enable the code it guards.
+// This is a temporary workaround to ignore the failure of OCLinksPayloadArrayCreate
+// in some cases. This allows the response to still be made, even though links property will be
+// missing.
+// Bug: IOT-2762
+#define ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
 
 /**
  * @var ES_RH_TAG
@@ -51,10 +60,13 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandle
 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
-void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateWiFiConfResource(OCRepPayload* input);
+OCEntityHandlerResult updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
+void updateEasySetupConnectProperty(OCRepPayload* input);
+OCEntityHandlerResult updateWiFiConfResource(OCRepPayload* input);
 void updateCoapCloudConfResource(OCRepPayload* input);
 void updateDevConfResource(OCRepPayload* input);
+bool isAuthTypeSupported(WIFI_AUTHTYPE authType);
+bool isEncTypeSupported(WIFI_ENCTYPE encType);
 const char *getResult(OCStackResult result);
 
 ESConnectRequestCB gConnectRequestEvtCb = NULL;
@@ -65,38 +77,54 @@ ESDevConfCB gDevConfRsrcEvtCb = NULL;
 ESReadUserdataCb gReadUserdataCb = NULL;
 ESWriteUserdataCb gWriteUserdataCb = NULL;
 
-bool CompareResourceInterface(char *from, char *iface)
+void GetInterfaceNameFromQuery(const char *query, char **iface)
 {
-    char *str = OICStrdup(from);
-    char *ptr = strtok(str, ";");
-
-    if(ptr == NULL)
+    if (!iface)
     {
-        return false;
+        return;
     }
+    *iface = NULL;
+    char *str = OICStrdup(query);
+    char *ptr = strtok(str, ";");
 
-    do
+    while (ptr)
     {
-        if(strstr(ptr, ".if."))
+        if (strstr(ptr, ".if."))
         {
             char *if_ptr = NULL;
             if_ptr = strtok(ptr, "=");
             if_ptr = strtok(NULL, "=");
 
-            if(!strcmp(if_ptr, iface))
-            {
-                return true;
-            }
+            *iface = OICStrdup(if_ptr);
+            break;
         }
+        ptr = strtok(NULL, ";");
+    }
 
-    } while ((ptr = strtok(NULL, ";")));
+    OICFree(str);
+}
+
+bool CompareResourceInterface(const char *from, const char *iface)
+{
+    char *if_ptr = NULL;
+    GetInterfaceNameFromQuery(from, &if_ptr);
+    if (!if_ptr)
+    {
+        return false;
+    }
+    if (!strcmp(if_ptr, iface))
+    {
+        OICFree(if_ptr);
+        return true;
+    }
+    OICFree(if_ptr);
 
     return false;
 }
 
 ESResult SetCallbackForUserData(ESReadUserdataCb readCb, ESWriteUserdataCb writeCb)
 {
-    if(!readCb && !writeCb)
+    if (!readCb && !writeCb)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Both of callbacks for user data are null");
         return ES_ERROR;
@@ -150,7 +178,7 @@ OCStackResult initEasySetupResource(bool isSecured)
 {
     g_ESEasySetupResource.status = ES_STATE_INIT;
     g_ESEasySetupResource.lastErrCode = ES_ERRCODE_NO_ERROR;
-    for( int i = 0 ; i < NUM_CONNECT_TYPE ; ++i )
+    for (int i = 0; i < NUM_CONNECT_TYPE; ++i)
     {
         g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
     }
@@ -163,34 +191,35 @@ OCStackResult initEasySetupResource(bool isSecured)
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_EASYSETUP, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }else
+    }
+    else
     {
         res = OCCreateResource(&g_ESEasySetupResource.handle, OC_RSRVD_ES_RES_TYPE_EASYSETUP,
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_EASYSETUP, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Created EasySetup resource with result: %s", getResult(res));
         return res;
     }
 
     res = OCBindResourceTypeToResource(g_ESEasySetupResource.handle, OC_RSRVD_ES_RES_TYPE_COL);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource type with result: %s", getResult(res));
         return res;
     }
 
     res = OCBindResourceInterfaceToResource(g_ESEasySetupResource.handle, OC_RSRVD_INTERFACE_LL);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
         return res;
     }
     res = OCBindResourceInterfaceToResource(g_ESEasySetupResource.handle, OC_RSRVD_INTERFACE_BATCH);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
         return res;
@@ -204,7 +233,9 @@ OCStackResult initWiFiConfResource(bool isSecured)
 {
     OCStackResult res = OC_STACK_ERROR;
 
-    g_ESWiFiConfResource.supportedFreq = WIFI_BOTH;
+    g_ESWiFiConfResource.supportedFreq[0] = WIFI_24G;
+    g_ESWiFiConfResource.supportedFreq[1] = WIFI_5G;
+    g_ESWiFiConfResource.numSupportedFreq=2;
     g_ESWiFiConfResource.supportedMode[0] = WIFI_11A;
     g_ESWiFiConfResource.supportedMode[1] = WIFI_11B;
     g_ESWiFiConfResource.supportedMode[2] = WIFI_11G;
@@ -221,7 +252,8 @@ OCStackResult initWiFiConfResource(bool isSecured)
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_WIFICONF, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }else
+    }
+    else
     {
         res = OCCreateResource(&g_ESWiFiConfResource.handle, OC_RSRVD_ES_RES_TYPE_WIFICONF,
         OC_RSRVD_INTERFACE_DEFAULT,
@@ -229,6 +261,21 @@ OCStackResult initWiFiConfResource(bool isSecured)
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
 
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Failed to create WiFiConf resource with result: %s",
+            getResult(res));
+        return res;
+    }
+
+    res = OCBindResourceInterfaceToResource(g_ESWiFiConfResource.handle,
+    OC_RSRVD_INTERFACE_READ_WRITE);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
+        return res;
+    }
+
     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created WiFiConf resource with result: %s", getResult(res));
     return res;
 
@@ -239,28 +286,47 @@ OCStackResult initCoapCloudConfResource(bool isSecured)
     OCStackResult res = OC_STACK_ERROR;
 
     OICStrcpy(g_ESCoapCloudConfResource.authCode, sizeof(g_ESCoapCloudConfResource.authCode), "");
-    OICStrcpy(g_ESCoapCloudConfResource.accessToken, sizeof(g_ESCoapCloudConfResource.accessToken), "");
+    OICStrcpy(g_ESCoapCloudConfResource.accessToken, sizeof(g_ESCoapCloudConfResource.accessToken),
+            "");
     g_ESCoapCloudConfResource.accessTokenType = NONE_OAUTH_TOKENTYPE;
-    OICStrcpy(g_ESCoapCloudConfResource.authProvider, sizeof(g_ESCoapCloudConfResource.authProvider), "");
+    OICStrcpy(g_ESCoapCloudConfResource.authProvider,
+            sizeof(g_ESCoapCloudConfResource.authProvider), "");
     OICStrcpy(g_ESCoapCloudConfResource.ciServer, sizeof(g_ESCoapCloudConfResource.ciServer), "");
 
     if (isSecured)
     {
-        res = OCCreateResource(&g_ESCoapCloudConfResource.handle, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF,
-        OC_RSRVD_INTERFACE_DEFAULT,
-        OC_RSRVD_ES_URI_COAPCLOUDCONF, OCEntityHandlerCb,
-        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }else
+        res = OCCreateResource(&g_ESCoapCloudConfResource.handle,
+                OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF,
+                OC_RSRVD_INTERFACE_DEFAULT,
+                OC_RSRVD_ES_URI_COAPCLOUDCONF, OCEntityHandlerCb,
+                NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }
+    else
     {
-        res = OCCreateResource(&g_ESCoapCloudConfResource.handle, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF,
-        OC_RSRVD_INTERFACE_DEFAULT,
-        OC_RSRVD_ES_URI_COAPCLOUDCONF, OCEntityHandlerCb,
-        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+        res = OCCreateResource(&g_ESCoapCloudConfResource.handle,
+                OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF,
+                OC_RSRVD_INTERFACE_DEFAULT,
+                OC_RSRVD_ES_URI_COAPCLOUDCONF, OCEntityHandlerCb,
+                NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+    }
+
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Failed to create CoapCloudConf resource with result: %s",
+            getResult(res));
+        return res;
+    }
+
+    res = OCBindResourceInterfaceToResource(g_ESCoapCloudConfResource.handle,
+            OC_RSRVD_INTERFACE_READ_WRITE);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
+        return res;
     }
 
     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created CoapCloudConf resource with result: %s", getResult(res));
     return res;
-
 }
 
 OCStackResult initDevConfResource(bool isSecured)
@@ -268,10 +334,6 @@ OCStackResult initDevConfResource(bool isSecured)
     OCStackResult res = OC_STACK_ERROR;
 
     OICStrcpy(g_ESDevConfResource.devName, sizeof(g_ESDevConfResource.devName), "");
-    OICStrcpy(g_ESDevConfResource.modelNumber, sizeof(g_ESDevConfResource.modelNumber), "");
-    OICStrcpy(g_ESDevConfResource.location, sizeof(g_ESDevConfResource.location), "");
-    OICStrcpy(g_ESDevConfResource.country, sizeof(g_ESDevConfResource.country), "");
-    OICStrcpy(g_ESDevConfResource.language, sizeof(g_ESDevConfResource.language), "");
 
     if (isSecured)
     {
@@ -279,7 +341,8 @@ OCStackResult initDevConfResource(bool isSecured)
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }else
+    }
+    else
     {
         res = OCCreateResource(&g_ESDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
         OC_RSRVD_INTERFACE_DEFAULT,
@@ -287,27 +350,131 @@ OCStackResult initDevConfResource(bool isSecured)
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
 
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Failed to create DevConf resource with result: %s",
+            getResult(res));
+        return res;
+    }
+
+    res = OCBindResourceInterfaceToResource(g_ESDevConfResource.handle, OC_RSRVD_INTERFACE_READ);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
+        return res;
+    }
+
     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
     return res;
 
 }
 
-void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+OCEntityHandlerResult updateEasySetupResource(OCEntityHandlerRequest* ehRequest,
+    OCRepPayload* input)
 {
     OIC_LOG_V(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.status %d", g_ESEasySetupResource.status);
 
+    OCEntityHandlerResult ehResult = OC_EH_OK;
+    if (ehRequest->query)
+    {
+        if (CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
+        {
+            bool hasError = false;
+            // When Provisioning resource has a POST with BatchInterface
+            // Parsing POST request on Batch Interface cosidering same format as GET using batch.
+            OCRepPayload *children = input;
+            while(children)
+            {
+                char* uri = children->uri;
+                if (NULL == uri)
+                {
+                    OIC_LOG(DEBUG, ES_RH_TAG, "No URI found in request");
+                }
+                else
+                {
+                    OIC_LOG_V(DEBUG, ES_RH_TAG, "Request URI [%s]", uri);
+                }
+
+                OCRepPayload *repPayload = NULL;
+                OCRepPayloadGetPropObject(children, OC_RSRVD_REPRESENTATION, &repPayload);
+                if (NULL == repPayload)
+                {
+                    OIC_LOG(ERROR, ES_RH_TAG, "repPayload is null!");
+                    children = children->next;
+                    continue;
+                }
+
+                // If uri is NULL, rep is applied to all resources in collection;
+                // otherwise its applied to specific target resources.
+                if (NULL == uri || 0 == strlen(uri) || 0 == strcmp(uri, OC_RSRVD_ES_URI_EASYSETUP))
+                {
+                    updateEasySetupConnectProperty(repPayload);
+                }
+
+                if (NULL == uri || 0 == strlen(uri)
+                    || 0 == strcmp(uri, OC_RSRVD_ES_URI_WIFICONF))
+                {
+                    if (updateWiFiConfResource(repPayload) != OC_EH_OK)
+                    {
+                        // Possibility of failure exist only when updating WiFiConf resource.
+                        // So error code is checked only for this function.
+                        OIC_LOG(ERROR, ES_RH_TAG, "Failed to update WiFiConf resource.");
+                        hasError = true;
+                    }
+                }
+
+                if (NULL == uri ||  0 == strlen(uri)
+                    || 0 == strcmp(uri, OC_RSRVD_ES_URI_COAPCLOUDCONF))
+                {
+                    updateCoapCloudConfResource(repPayload);
+                }
+
+                if (NULL == uri ||  0 == strlen(uri)
+                    || 0 == strcmp(uri, OC_RSRVD_ES_URI_DEVCONF))
+                {
+                    updateDevConfResource(repPayload);
+                }
+
+                children = children->next;
+                OCRepPayloadDestroy(repPayload);
+            }
+
+            if (hasError)
+            {
+               ehResult = OC_EH_BAD_REQ;
+            }
+        }
+        else if (CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
+        {
+            OIC_LOG(DEBUG, ES_RH_TAG, "Handling POST request on default interface");
+            updateEasySetupConnectProperty(input);
+        }
+    }
+
+    OIC_LOG(DEBUG, ES_RH_TAG, "updateEasySetupResource exit");
+    return ehResult;
+}
+
+void updateEasySetupConnectProperty(OCRepPayload* input)
+{
     int64_t *connect_req = NULL;
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
     if (OCRepPayloadGetIntArray(input, OC_RSRVD_ES_CONNECT, &connect_req, dimensions))
     {
         ESConnectRequest* connectRequest = (ESConnectRequest*)OICMalloc(sizeof(ESConnectRequest));
+        if (!connectRequest)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return;
+        }
+
         int cntRequest = 0;
-        for (int i = 0 ; i < NUM_CONNECT_TYPE ; ++i)
+        for (unsigned int i = 0 ; i < NUM_CONNECT_TYPE ; ++i)
         {
             g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
             connectRequest->connect[i] = ES_CONNECT_NONE;
 
-            if(i < dimensions[0] &&
+            if (i < dimensions[0] &&
                 (connect_req[i] == ES_CONNECT_WIFI || connect_req[i] == ES_CONNECT_COAPCLOUD))
             {
                 g_ESEasySetupResource.connectRequest[cntRequest] = connect_req[i];
@@ -320,12 +487,12 @@ void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* in
         connectRequest->numRequest = cntRequest;
         g_ESEasySetupResource.numRequest = cntRequest;
 
-        if(g_ESEasySetupResource.connectRequest[0] != ES_CONNECT_NONE)
+        if (g_ESEasySetupResource.connectRequest[0] != ES_CONNECT_NONE)
         {
             OIC_LOG(DEBUG, ES_RH_TAG, "Send ConnectRequest Callback To ES");
 
-            // TODO : Need to check appropriateness of gWiFiData
-            if(gConnectRequestEvtCb != NULL)
+            //@todo Need to check appropriateness of gWiFiData
+            if (gConnectRequestEvtCb != NULL)
             {
                 gConnectRequestEvtCb(ES_OK, connectRequest);
             }
@@ -335,78 +502,103 @@ void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* in
             }
         }
     }
-
-    if(ehRequest->query)
-    {
-        if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
-        {
-            // When Provisioning resource has a POST with BatchInterface
-            updateCoapCloudConfResource(input);
-            updateWiFiConfResource(input);
-            updateDevConfResource(input);
-        }
-    }
 }
 
-void updateWiFiConfResource(OCRepPayload* input)
+OCEntityHandlerResult updateWiFiConfResource(OCRepPayload* input)
 {
-    ESWiFiConfData* wiFiData = (ESWiFiConfData*)OICMalloc(sizeof(ESWiFiConfData));
-
-    if(wiFiData == NULL)
+    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+    ESWiFiConfData* wiFiData = (ESWiFiConfData*) OICMalloc(sizeof(ESWiFiConfData));
+    if (wiFiData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
-        return ;
+        return ehResult;
     }
 
+    char* ssid = NULL;
+    char* cred = NULL;
+    char *authType = NULL;
+    char *encType = NULL;
     memset(wiFiData->ssid, 0, OIC_STRING_MAX_VALUE);
     memset(wiFiData->pwd, 0, OIC_STRING_MAX_VALUE);
     wiFiData->authtype = NONE_AUTH;
     wiFiData->enctype = NONE_AUTH;
     wiFiData->userdata = NULL;
 
-    char* ssid = NULL;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
+    bool validAuthType = false;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHTYPE, &authType))
     {
-        OICStrcpy(g_ESWiFiConfResource.ssid, sizeof(g_ESWiFiConfResource.ssid), ssid);
-        OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.ssid : %s", g_ESWiFiConfResource.ssid);
+        WIFI_AUTHTYPE tmp;
+        validAuthType = WiFiAuthTypeStringToEnum(authType, &tmp);
+        if (validAuthType && isAuthTypeSupported(tmp))
+        {
+            wiFiData->authtype = tmp;
+            OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.authType %u",
+                    wiFiData->authtype);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "AuthType is not supported.");
+            ehResult = OC_EH_BAD_REQ;
+            goto EXIT;
+        }
     }
 
-    char* cred = NULL;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
+    bool validEncType = false;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_ENCTYPE, &encType))
     {
-        OICStrcpy(g_ESWiFiConfResource.cred, sizeof(g_ESWiFiConfResource.cred), cred);
-        OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.cred %s", g_ESWiFiConfResource.cred);
+        WIFI_ENCTYPE tmp;
+        validEncType = WiFiEncTypeStringToEnum(encType, &tmp);
+        if (validEncType && isEncTypeSupported(tmp))
+        {
+            wiFiData->enctype = tmp;
+            OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.encType %u",
+                    wiFiData->enctype);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "EncType is not supported.");
+            ehResult = OC_EH_BAD_REQ;
+            goto EXIT;
+        }
+    }
+
+    if (validAuthType)
+    {
+        g_ESWiFiConfResource.authType = wiFiData->authtype;
+    }
+
+    if (validEncType)
+    {
+        g_ESWiFiConfResource.encType = wiFiData->enctype;
     }
 
-    int64_t authType = -1;
-    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
     {
-        g_ESWiFiConfResource.authType = authType;
-        wiFiData->authtype = g_ESWiFiConfResource.authType;
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.authType %u", g_ESWiFiConfResource.authType);
+        OICStrcpy(g_ESWiFiConfResource.ssid, sizeof(g_ESWiFiConfResource.ssid), ssid);
+        OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
+        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.ssid : %s",
+                g_ESWiFiConfResource.ssid);
     }
 
-    int64_t encType = -1;
-    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
     {
-        g_ESWiFiConfResource.encType = encType;
-        wiFiData->enctype = g_ESWiFiConfResource.encType;
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.encType %u", g_ESWiFiConfResource.encType);
+        OICStrcpy(g_ESWiFiConfResource.cred, sizeof(g_ESWiFiConfResource.cred), cred);
+        OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
+        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.cred %s",
+                g_ESWiFiConfResource.cred);
     }
 
-    if(gReadUserdataCb)
+    if (gReadUserdataCb)
     {
         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFICONF, &wiFiData->userdata);
     }
 
-    if(ssid || cred || authType!= -1 || encType != -1)
+    if (ssid || cred || validAuthType || validEncType)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Send WiFiConfRsrc Callback To ES");
 
-        // TODO : Need to check appropriateness of gWiFiData
-        if(gWifiConfRsrcEvtCb != NULL)
+        //@todo Need to check appropriateness of gWiFiData
+        if (gWifiConfRsrcEvtCb != NULL)
         {
             gWifiConfRsrcEvtCb(ES_OK, wiFiData);
         }
@@ -416,19 +608,27 @@ void updateWiFiConfResource(OCRepPayload* input)
         }
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Enrollee doesn't have any observer.");
     }
 
+    ehResult = OC_EH_OK;
+
+EXIT:
+    OICFree(encType);
+    OICFree(authType);
+    OICFree(cred);
+    OICFree(ssid);
     OICFree(wiFiData);
+    return ehResult;
 }
 
 void updateCoapCloudConfResource(OCRepPayload* input)
 {
     ESCoapCloudConfData* cloudData = (ESCoapCloudConfData*)OICMalloc(sizeof(ESCoapCloudConfData));
 
-    if(cloudData == NULL)
+    if (cloudData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
         return;
@@ -438,7 +638,7 @@ void updateCoapCloudConfResource(OCRepPayload* input)
     memset(cloudData->accessToken, 0, OIC_STRING_MAX_VALUE);
     g_ESCoapCloudConfResource.accessTokenType = NONE_OAUTH_TOKENTYPE;
     memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
-    memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
+    memset(cloudData->ciServer, 0, OIC_URI_STRING_MAX_VALUE);
     cloudData->userdata = NULL;
 
     char *authCode = NULL;
@@ -481,17 +681,17 @@ void updateCoapCloudConfResource(OCRepPayload* input)
         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.ciServer %s", g_ESCoapCloudConfResource.ciServer);
     }
 
-    if(gReadUserdataCb)
+    if (gReadUserdataCb)
     {
         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF, &cloudData->userdata);
     }
 
-    if(authCode || accessToken || authProvider || ciServer)
+    if (authCode || accessToken || authProvider || ciServer)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Send CoapCloudConfRsrc Callback To ES");
 
-        // TODO : Need to check appropriateness of gCloudData
-        if(gCoapCloudConfRsrcEvtCb != NULL)
+        //@todo Need to check appropriateness of gCloudData
+        if (gCoapCloudConfRsrcEvtCb != NULL)
         {
             gCoapCloudConfRsrcEvtCb(ES_OK, cloudData);
         }
@@ -501,7 +701,7 @@ void updateCoapCloudConfResource(OCRepPayload* input)
         }
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESCoapCloudConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESCoapCloudConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "CoapCloudConf resource doesn't have any observer.");
     }
@@ -513,50 +713,26 @@ void updateDevConfResource(OCRepPayload* input)
 {
     ESDevConfData* devConfData = (ESDevConfData*)OICMalloc(sizeof(ESDevConfData));
 
-    if(devConfData == NULL)
+    if (devConfData == NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
         return;
     }
-    memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
-    memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
     devConfData->userdata = NULL;
 
-    char *location = NULL;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LOCATION, &location))
-    {
-        OICStrcpy(g_ESDevConfResource.location, sizeof(g_ESDevConfResource.location), location);
-        OICStrcpy(devConfData->location, sizeof(devConfData->location), location);
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESDevConfResource.location %s", g_ESDevConfResource.location);
-    }
-
-    char *country = NULL;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country))
-    {
-        OICStrcpy(g_ESDevConfResource.country, sizeof(g_ESDevConfResource.country), country);
-        OICStrcpy(devConfData->country, sizeof(devConfData->country), country);
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESDevConfResource.country %s", g_ESDevConfResource.country);
-    }
-
-    char *language = NULL;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language))
-    {
-        OICStrcpy(g_ESDevConfResource.language, sizeof(g_ESDevConfResource.language), language);
-        OICStrcpy(devConfData->language, sizeof(devConfData->language), language);
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESDevConfResource.language %s", g_ESDevConfResource.language);
-    }
-
-    if(gReadUserdataCb)
+    if (gReadUserdataCb)
     {
         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
     }
 
-    if(country || language)
+    // If a writable property in oic.r.devconf is added later,
+    // a condition for calling a resistered callback should be implemented also.
+    if (devConfData->userdata != NULL)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
 
-        // TODO : Need to check appropriateness of gDevConfData
-        if(gDevConfRsrcEvtCb != NULL)
+        //@todo : Need to check appropriateness of gDevConfData
+        if (gDevConfRsrcEvtCb != NULL)
         {
             gDevConfRsrcEvtCb(ES_OK, devConfData);
         }
@@ -566,7 +742,7 @@ void updateDevConfResource(OCRepPayload* input)
         }
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "devConfResource doesn't have any observer.");
     }
@@ -583,7 +759,7 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
         return NULL;
     }
 
-    if(g_ESWiFiConfResource.handle == NULL)
+    if (g_ESWiFiConfResource.handle == NULL)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "WiFiConf resource is not created");
         return NULL;
@@ -594,7 +770,7 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
 
     OCRepPayload* repPayload = NULL;
     OCRepPayload* tempPayload = NULL;
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         repPayload = OCRepPayloadCreate();
         if (!repPayload)
@@ -606,46 +782,92 @@ OCRepPayload* constructResponseOfWiFiConf(char *interface)
         tempPayload = payload;
         payload = repPayload;
 
-        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
+        interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ_WRITE);
 
-        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFICONF);
 
-        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
     }
     else
     {
         OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+        OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_READ_WRITE);
         OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_WIFICONF);
     }
 
-    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESWiFiConfResource.numMode, 0, 0};
-    int64_t *modes_64 = (int64_t *)OICMalloc(g_ESWiFiConfResource.numMode * sizeof(int64_t));
-    for(int i = 0 ; i < g_ESWiFiConfResource.numMode ; ++i)
+    // Do not add Read Only Properties when using OC_RSRVD_INTERFACE_READ_WRITE
+    if (strcmp(interface, OC_RSRVD_INTERFACE_READ_WRITE) != 0)
     {
-        modes_64[i] = g_ESWiFiConfResource.supportedMode[i];
+        size_t dimensionsModes[MAX_REP_ARRAY_DEPTH] = { g_ESWiFiConfResource.numMode, 0, 0 };
+        const char *modes[NUM_WIFIMODE] = { 0, };
+        for (int i = 0; i < g_ESWiFiConfResource.numMode; ++i)
+        {
+            modes[i] = WiFiModeEnumToString(g_ESWiFiConfResource.supportedMode[i]);
+        }
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, &modes[0],
+                dimensionsModes);
+
+        size_t dimensionsFreq[MAX_REP_ARRAY_DEPTH] = { g_ESWiFiConfResource.numSupportedFreq, 0, 0 };
+        const char *freq[NUM_WIFIFREQ] = { 0, };
+        for (int i = 0; i < g_ESWiFiConfResource.numSupportedFreq; ++i)
+        {
+            freq[i] = WiFiFreqEnumToString(g_ESWiFiConfResource.supportedFreq[i]);
+        }
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, freq, dimensionsFreq);
+    }
+
+    size_t dimensionsAuthType[MAX_REP_ARRAY_DEPTH] = { g_ESWiFiConfResource.numSupportedAuthType, 0,
+            0 };
+    const char *authType[NUM_WIFIAUTHTYPE] = { 0, };
+    for (int i = 0; i < g_ESWiFiConfResource.numSupportedAuthType; ++i)
+    {
+        authType[i] = WiFiAuthTypeEnumToString(g_ESWiFiConfResource.supportedAuthType[i]);
     }
-    OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
+    OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIAUTHTYPE, authType,
+            dimensionsAuthType);
+
+    size_t dimensionsEncType[MAX_REP_ARRAY_DEPTH] =
+            { g_ESWiFiConfResource.numSupportedEncType, 0, 0 };
+    const char *encType[NUM_WIFIENCTYPE] = { 0, };
+    for (int i = 0; i < g_ESWiFiConfResource.numSupportedEncType; ++i)
+    {
+        encType[i] = WiFiEncTypeEnumToString(g_ESWiFiConfResource.supportedEncType[i]);
+    }
+    OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIENCTYPE, encType,
+            dimensionsEncType);
 
-    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, g_ESWiFiConfResource.supportedFreq);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, g_ESWiFiConfResource.ssid);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, g_ESWiFiConfResource.cred);
-    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) g_ESWiFiConfResource.authType);
-    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) g_ESWiFiConfResource.encType);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHTYPE,
+            WiFiAuthTypeEnumToString(g_ESWiFiConfResource.authType));
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_ENCTYPE,
+            WiFiEncTypeEnumToString(g_ESWiFiConfResource.encType));
 
-    if(gWriteUserdataCb)
+    if (gWriteUserdataCb)
     {
         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFICONF);
     }
 
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         payload = tempPayload;
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
@@ -663,7 +885,7 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
         return NULL;
     }
 
-    if(g_ESCoapCloudConfResource.handle == NULL)
+    if (g_ESCoapCloudConfResource.handle == NULL)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "CoapCloudConf resource is not created");
         return NULL;
@@ -674,7 +896,7 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
 
     OCRepPayload* repPayload = NULL;
     OCRepPayload* tempPayload = NULL;
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         repPayload = OCRepPayloadCreate();
         if (!repPayload)
@@ -686,23 +908,35 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
         tempPayload = payload;
         payload = repPayload;
 
-        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
+        interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ_WRITE);
 
-        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
 
-        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
     }
     else
     {
         OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+        OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_READ_WRITE);
         OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
     }
 
@@ -712,12 +946,12 @@ OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, g_ESCoapCloudConfResource.authProvider);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, g_ESCoapCloudConfResource.ciServer);
 
-    if(gWriteUserdataCb)
+    if (gWriteUserdataCb)
     {
         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
     }
 
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         payload = tempPayload;
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
@@ -735,7 +969,7 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
         return NULL;
     }
 
-    if(g_ESDevConfResource.handle == NULL)
+    if (g_ESDevConfResource.handle == NULL)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "DevConf resource is not created");
         return NULL;
@@ -746,7 +980,7 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
 
     OCRepPayload* repPayload = NULL;
     OCRepPayload* tempPayload = NULL;
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         repPayload = OCRepPayloadCreate();
         if (!repPayload)
@@ -758,38 +992,46 @@ OCRepPayload* constructResponseOfDevConf(char *interface)
         tempPayload = payload;
         payload = repPayload;
 
-        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
+        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
+        interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_READ);
 
-        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
 
         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+            return NULL;
+        }
 
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
 
-        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
+        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
     }
     else
     {
         OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+        OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_READ);
         OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
     }
 
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, g_ESDevConfResource.devName);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_MODELNUMBER, g_ESDevConfResource.modelNumber);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LOCATION, g_ESDevConfResource.location);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, g_ESDevConfResource.language);
-    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, g_ESDevConfResource.country);
 
-    if(gWriteUserdataCb)
+    if (gWriteUserdataCb)
     {
         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
     }
 
-    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
+    if (!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
     {
         payload = tempPayload;
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
@@ -807,220 +1049,155 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
         return NULL;
     }
 
-    // Requested interface is Link list interface
-    //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
-    if(!ehRequest->query ||
-        (ehRequest->query && !strcmp(ehRequest->query, "")) ||
-        (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
-        (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
-    {
-        const OCRepPayload *arrayPayload[3] = {NULL};
-
-        int childResCnt = 0;
-
-        if(g_ESWiFiConfResource.handle != NULL)
-        {
-            OCRepPayload *add = OCRepPayloadCreate();
-            if(!add)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
-            char **resourceType = NULL;
-            resourceType = (char **)OICMalloc(sizeof(char *) * 1);
-            char **resourceInterface = NULL;
-            resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
-
-            if(!resourceType || !resourceInterface)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFICONF);
-            resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
-
-            add->base.type = PAYLOAD_TYPE_REPRESENTATION;
-            OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFICONF);
-            OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
-                                            (const char **)resourceType, dimensions);
-            OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
-                                            (const char **)resourceInterface, dimensions);
-
-            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESWiFiConfResource.handle);
-            OCRepPayload *policy = OCRepPayloadCreate();
-            if (!policy)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
-                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
-            if (p & OC_SECURE)
-            {
-                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
-                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
-                                                                    ehRequest->devAddr.flags);
-                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
-            }
-
-            OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
-
-            arrayPayload[childResCnt++] = add;
-        }
-
-        if(g_ESDevConfResource.handle != NULL)
-        {
-            OCRepPayload *add = OCRepPayloadCreate();
-            if(!add)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
-            char **resourceType = NULL;
-            resourceType = (char **)OICMalloc(sizeof(char *) * 1);
-            char **resourceInterface = NULL;
-            resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
-
-            if(!resourceType || !resourceInterface)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
-            resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
-
-            add->base.type = PAYLOAD_TYPE_REPRESENTATION;
-            OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
-            OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
-                                            (const char **)resourceType, dimensions);
-            OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
-                                            (const char **)resourceInterface, dimensions);
-
-            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESDevConfResource.handle);
-            OCRepPayload *policy = OCRepPayloadCreate();
-            if (!policy)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
+    OIC_LOG_V(DEBUG, ES_RH_TAG, "constructResponseOfEasySetup: qry = %s",
+            (ehRequest->query) ? (ehRequest->query) : "null");
 
-            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
-                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
-            if (p & OC_SECURE)
-            {
-                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
-                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
-                                                                    ehRequest->devAddr.flags);
-                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
-            }
-
-            OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
+    // Requested interface is Link list or baseline interface
+     if (!ehRequest->query ||
+         (ehRequest->query && !strcmp(ehRequest->query, "")) ||
+         (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
+         (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
+     {
+        size_t arraySize;
+        OCRepPayload **linkArr = OCLinksPayloadArrayCreate(OC_RSRVD_ES_URI_EASYSETUP, ehRequest,
+            true, &arraySize);
 
-            arrayPayload[childResCnt++] = add;
-        }
+#ifdef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+        bool linkArrConstructed = true; // TODO: Remove this when
+                                        // ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE is removed.
+#endif
 
-        if(g_ESCoapCloudConfResource.handle != NULL)
+        if (!linkArr || (arraySize == 0))
         {
-            OCRepPayload *add = OCRepPayloadCreate();
-            if(!add)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
-            char **resourceType = NULL;
-            resourceType = (char **)OICMalloc(sizeof(char *) * 1);
-            char **resourceInterface = NULL;
-            resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
-
-            if(!resourceType || !resourceInterface)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
-            resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
-
-            add->base.type = PAYLOAD_TYPE_REPRESENTATION;
-            OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_COAPCLOUDCONF);
-            OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
-                                            (const char **)resourceType, dimensions);
-            OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
-                                            (const char **)resourceInterface, dimensions);
-
-            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESCoapCloudConfResource.handle);
-            OCRepPayload *policy = OCRepPayloadCreate();
-            if (!policy)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-                return NULL;
-            }
-
-            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
-                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
-            if (p & OC_SECURE)
-            {
-                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
-                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
-                                                                    ehRequest->devAddr.flags);
-                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
-            }
+            OIC_LOG(ERROR, ES_RH_TAG, "Failed to create Easy Setup collections ll response.");
 
-            OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
-
-            arrayPayload[childResCnt++] = add;
+#ifdef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+            linkArrConstructed = false;
+#else
+            OICFree(linkArr);
+            OCRepPayloadDestroy(payload);
+            return NULL;
+#endif
         }
-
-        size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
-
-        if(!ehRequest->query ||
-            (ehRequest->query && !strcmp(ehRequest->query, "")) ||
-            (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
+#ifndef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+        else
         {
-            OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res");
-            OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_EASYSETUP);
-            OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
-            OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
-            OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
-            OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
-            OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_COL);
-
-            OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
-            OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
+#endif
+            OIC_LOG(DEBUG, ES_RH_TAG, "Constructed links payload.");
 
-            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest , 0, 0};
-            int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest  * sizeof(int64_t));
-            for(int i = 0 ; i < g_ESEasySetupResource.numRequest  ; ++i)
+            if (!ehRequest->query || (ehRequest->query && !strcmp(ehRequest->query, ""))
+                    || (ehRequest->query
+                            && CompareResourceInterface(ehRequest->query,
+                                    OC_RSRVD_INTERFACE_DEFAULT)))
             {
-                connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
+                OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res (Default interface)");
+                OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_EASYSETUP);
+                OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+                OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
+                OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
+                OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
+                OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_COL);
+
+                OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS,
+                        g_ESEasySetupResource.status);
+                OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE,
+                        g_ESEasySetupResource.lastErrCode);
+
+                if (g_ESEasySetupResource.numRequest > 0)
+                {
+                    size_t dimensions[MAX_REP_ARRAY_DEPTH] = { g_ESEasySetupResource.numRequest, 0,
+                            0 };
+                    int64_t *connectRequest = (int64_t *) OICMalloc(
+                            g_ESEasySetupResource.numRequest * sizeof(int64_t));
+                    if (!connectRequest)
+                    {
+                        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+                        return NULL;
+                    }
+
+                    for (int i = 0; i < g_ESEasySetupResource.numRequest; ++i)
+                    {
+                        connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
+                    }
+
+                    bool b = OCRepPayloadSetIntArrayAsOwner(payload, OC_RSRVD_ES_CONNECT,
+                            (int64_t *) connectRequest, dimensions);
+                    if (!b)
+                    {
+                        OIC_LOG(ERROR, ES_RH_TAG, "Failed to set array value for Connect property");
+                        OICFree(connectRequest);
+                    }
+                }
+                else
+                {
+                    OIC_LOG(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.numRequest is 0");
+                    size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0, 0, 0 };
+                    OCRepPayloadSetIntArrayAsOwner(payload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
+                }
+
+                if (gWriteUserdataCb)
+                {
+                    gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
+                }
+
+#ifdef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+                if (linkArrConstructed)
+                {
+#endif
+                    size_t dimensions[MAX_REP_ARRAY_DEPTH] = { arraySize, 0, 0 };
+                    OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_LINKS,
+                            (const OCRepPayload **) linkArr, dimensions);
+                    for (size_t i = 0; i < arraySize; ++i)
+                    {
+                        OCRepPayloadDestroy(linkArr[i]);
+                    }
+#ifdef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+                }
+#endif
             }
-            OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
-
-            if(gWriteUserdataCb)
+            else // link list interface
             {
-                gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
+#ifdef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+                if (linkArrConstructed)
+                {
+#endif
+                    uint16_t acceptVersion = 0;
+                    OCPayloadFormat contentFormat; // not used
+                    OCGetRequestPayloadVersion(ehRequest, &contentFormat, &acceptVersion);
+                    // acceptVersion("OCF-Accept-Content-Format-Version") is present for OCF Request
+                    if (acceptVersion != 0)
+                    {
+                        for (size_t i = 0; i < arraySize - 1; ++i)
+                        {
+                            linkArr[i]->next = linkArr[i + 1];
+                        }
+                        // payload is directly the linkArr array, free earlier allocated memory.
+                        OCRepPayloadDestroy(payload);
+                        payload = linkArr[0];
+                    }
+                    else // for backward compatibility with OIC
+                    {
+                        size_t dimensions[MAX_REP_ARRAY_DEPTH] = { arraySize, 0, 0 };
+                        OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_LINKS,
+                                (const OCRepPayload **) linkArr, dimensions);
+                        for (size_t i = 0; i < arraySize; ++i)
+                        {
+                            OCRepPayloadDestroy(linkArr[i]);
+                        }
+                    }
+#ifdef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
+                }
+#endif
             }
-
-            OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
+#ifndef ES_IGNORE_OCLinksPayloadArrayCreate_FAILIURE
         }
-        else    // link list interface
-        {
-            OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
-        }
-    } else if (
-        ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
-
+#endif
+        OICFree(linkArr);
+    }
+    else if (ehRequest->query
+            && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
     {
-        OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res");
+        OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res (Batch Interface)");
         OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_EASYSETUP);
 
         OCRepPayload* repPayload = NULL;
@@ -1032,9 +1209,9 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
             return NULL;
         }
 
-        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {3, 0, 0};
-        char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
-        if(!interfaces)
+        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = { 3, 0, 0 };
+        char **interfaces = (char **) OICMalloc(3 * sizeof(char*));
+        if (!interfaces)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
             return NULL;
@@ -1044,11 +1221,12 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
         interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_LL);
         interfaces[2] = OICStrdup(OC_RSRVD_INTERFACE_BATCH);
 
-        OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);
+        OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_INTERFACE, (const char **) interfaces,
+                interfacesDimensions);
 
-        size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
-        char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
-        if(!resourceTypes)
+        size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = { 2, 0, 0 };
+        char **resourceTypes = (char **) OICMalloc(2 * sizeof(char*));
+        if (!resourceTypes)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
             return NULL;
@@ -1057,55 +1235,75 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_EASYSETUP);
         resourceTypes[1] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COL);
 
-        OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
+        OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_RES_TYPE, (const char **) resourceTypes,
+                resourceTypesDimensions);
 
         OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
-        OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
-        size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest , 0, 0};
-        int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest  * sizeof(int64_t));
-        for(int i = 0 ; i < g_ESEasySetupResource.numRequest  ; ++i)
+        OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_LAST_ERRORCODE,
+                g_ESEasySetupResource.lastErrCode);
+        if (g_ESEasySetupResource.numRequest > 0)
         {
-            connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
+            size_t dimensions[MAX_REP_ARRAY_DEPTH] = { g_ESEasySetupResource.numRequest, 0, 0 };
+            int64_t *connectRequest = (int64_t *) OICMalloc(
+                    g_ESEasySetupResource.numRequest * sizeof(int64_t));
+            if (!connectRequest)
+            {
+                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+                return NULL;
+            }
+
+            for (int i = 0; i < g_ESEasySetupResource.numRequest; ++i)
+            {
+                connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
+            }
+
+            bool b = OCRepPayloadSetIntArrayAsOwner(repPayload, OC_RSRVD_ES_CONNECT,
+                    (int64_t *) connectRequest, dimensions);
+            if (!b)
+            {
+                OIC_LOG(ERROR, ES_RH_TAG, "Failed to set array value for Connect property");
+                OICFree(connectRequest);
+            }
+        }
+        else
+        {
+            OIC_LOG(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.numRequest is 0");
+            size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0, 0, 0 };
+            OCRepPayloadSetIntArrayAsOwner(repPayload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
         }
-        OCRepPayloadSetIntArray(repPayload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
 
-        if(gWriteUserdataCb)
+        if (gWriteUserdataCb)
         {
             gWriteUserdataCb(repPayload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
         }
 
         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
-    }
 
-    if(ehRequest->query)
-    {
-        if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
-        {// When Provisioning resource has a GET with BatchInterface
-            OCRepPayload* head = payload;
-            OCRepPayload* nextPayload = NULL;
-
-            nextPayload = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_BATCH);
-            if(nextPayload != NULL)
-            {
-                payload->next = nextPayload;
-                payload = payload->next;
-            }
+        OCRepPayload* head = payload;
+        OCRepPayload* nextPayload = NULL;
 
-            nextPayload = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_BATCH);
-            if(nextPayload != NULL)
-            {
-                payload->next = nextPayload;
-                payload = payload->next;
-            }
+        nextPayload = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_BATCH);
+        if (nextPayload != NULL)
+        {
+            payload->next = nextPayload;
+            payload = payload->next;
+        }
 
-            nextPayload = constructResponseOfDevConf(OC_RSRVD_INTERFACE_BATCH);
-            if(nextPayload != NULL)
-            {
-                payload->next = nextPayload;
-            }
+        nextPayload = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_BATCH);
+        if (nextPayload != NULL)
+        {
+            payload->next = nextPayload;
+            payload = payload->next;
+        }
 
-            payload = head;
+        nextPayload = constructResponseOfDevConf(OC_RSRVD_INTERFACE_BATCH);
+        if (nextPayload != NULL)
+        {
+            payload->next = nextPayload;
         }
+
+        payload = head;
+
     }
 
     return payload;
@@ -1118,7 +1316,7 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
     bool maskFlag = false;
 
     res = initEasySetupResource(isSecured);
-    if(res != OC_STACK_OK)
+    if (res != OC_STACK_OK)
     {
         // TODO: destroy logic will be added
         OIC_LOG_V(ERROR, ES_RH_TAG, "initEasySetupResource result: %s", getResult(res));
@@ -1126,62 +1324,61 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
         return res;
     }
 
-    if((resourceMask & ES_WIFICONF_RESOURCE) == ES_WIFICONF_RESOURCE)
+    if ((resourceMask & ES_WIFICONF_RESOURCE) == ES_WIFICONF_RESOURCE)
     {
         maskFlag = true;
         res = initWiFiConfResource(isSecured);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiConfResource result: %s", getResult(res));
             return res;
         }
 
         res = OCBindResource(g_ESEasySetupResource.handle, g_ESWiFiConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiConfResource result: %s", getResult(res));
             return res;
         }
-
     }
 
-    if((resourceMask & ES_COAPCLOUDCONF_RESOURCE) == ES_COAPCLOUDCONF_RESOURCE)
+    if ((resourceMask & ES_COAPCLOUDCONF_RESOURCE) == ES_COAPCLOUDCONF_RESOURCE)
     {
         maskFlag = true;
         res = initCoapCloudConfResource(isSecured);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "initCoapCloudConfResource result: %s", getResult(res));
             return res;
         }
 
         res = OCBindResource(g_ESEasySetupResource.handle, g_ESCoapCloudConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CoapCloudConfResource result: %s", getResult(res));
             return res;
         }
     }
 
-    if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
+    if ((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
     {
         maskFlag = true;
         res = initDevConfResource(isSecured);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
             return res;
         }
 
         res = OCBindResource(g_ESEasySetupResource.handle, g_ESDevConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
             return res;
         }
     }
 
-    if(maskFlag == false)
+    if (maskFlag == false)
     {
         OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
         return OC_STACK_ERROR;
@@ -1199,7 +1396,7 @@ OCStackResult DeleteEasySetupResources()
     if (g_ESWiFiConfResource.handle != NULL)
     {
         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESWiFiConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
         }
@@ -1207,7 +1404,7 @@ OCStackResult DeleteEasySetupResources()
     if (g_ESCoapCloudConfResource.handle != NULL)
     {
         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESCoapCloudConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
         }
@@ -1215,7 +1412,7 @@ OCStackResult DeleteEasySetupResources()
     if (g_ESDevConfResource.handle != NULL)
     {
         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESDevConfResource.handle);
-        if(res != OC_STACK_OK)
+        if (res != OC_STACK_OK)
         {
             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
         }
@@ -1230,7 +1427,7 @@ OCStackResult DeleteEasySetupResources()
         }
     }
 
-    if(g_ESCoapCloudConfResource.handle != NULL)
+    if (g_ESCoapCloudConfResource.handle != NULL)
     {
         res = OCDeleteResource(g_ESCoapCloudConfResource.handle);
         if (res != OC_STACK_OK)
@@ -1239,7 +1436,7 @@ OCStackResult DeleteEasySetupResources()
         }
     }
 
-    if(g_ESDevConfResource.handle != NULL)
+    if (g_ESDevConfResource.handle != NULL)
     {
         res = OCDeleteResource(g_ESDevConfResource.handle);
         if (res != OC_STACK_OK)
@@ -1248,7 +1445,7 @@ OCStackResult DeleteEasySetupResources()
         }
     }
 
-    if(g_ESEasySetupResource.handle != NULL)
+    if (g_ESEasySetupResource.handle != NULL)
     {
         res = OCDeleteResource(g_ESEasySetupResource.handle);
         if (res != OC_STACK_OK)
@@ -1260,6 +1457,13 @@ OCStackResult DeleteEasySetupResources()
     return res;
 }
 
+static bool isValidESResourceHandle(OCResourceHandle handle)
+{
+    return ((handle == g_ESEasySetupResource.handle) || (handle == g_ESWiFiConfResource.handle)
+            || (handle == g_ESCoapCloudConfResource.handle)
+            || (handle == g_ESDevConfResource.handle));
+}
+
 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
 {
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
@@ -1273,63 +1477,46 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
         OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
         return ehResult;
     }
+    if (!isValidESResourceHandle(ehRequest->resource))
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Request does not have a valid Easy Setup Resource handle");
+        return ehResult;
+    }
+    if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
+        return OC_EH_BAD_REQ;
+    }
 
     OCRepPayload *getResp = NULL;
     *payload = NULL;
 
-    if(ehRequest->resource == g_ESEasySetupResource.handle)
+    char *iface_name = NULL;
+    GetInterfaceNameFromQuery(ehRequest->query, &iface_name);
+    if (!iface_name)
+    {
+        iface_name = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
+    }
+
+    if (ehRequest->resource == g_ESEasySetupResource.handle)
     {
-        if(ehRequest->query &&
-            strcmp(ehRequest->query, "") &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
-            !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
-        {
-            OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-            return OC_EH_BAD_REQ;
-        }
-        else
-        {
             getResp = constructResponseOfEasySetup(ehRequest);
-        }
     }
-    else if(ehRequest->resource == g_ESWiFiConfResource.handle)
+    else if (ehRequest->resource == g_ESWiFiConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
-        {
-            OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-            return OC_EH_BAD_REQ;
-        }
-        else
-        {
-            getResp = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_DEFAULT);
-        }
+            getResp = constructResponseOfWiFiConf(iface_name);
     }
-    else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
+    else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
-        {
-            OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-            return OC_EH_BAD_REQ;
-        }
-        else
-        {
-            getResp = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_DEFAULT);
-        }
+            getResp = constructResponseOfCoapCloudConf(iface_name);
     }
-    else if(ehRequest->resource == g_ESDevConfResource.handle)
+    else if (ehRequest->resource == g_ESDevConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
-        {
-            OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
-            return OC_EH_BAD_REQ;
-        }
-        else
-        {
-            getResp = constructResponseOfDevConf(OC_RSRVD_INTERFACE_DEFAULT);
-        }
+            getResp = constructResponseOfDevConf(iface_name);
     }
 
+    OICFree(iface_name);
+
     if (!getResp)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
@@ -1345,6 +1532,7 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
 {
     OIC_LOG(DEBUG, ES_RH_TAG, "ProcessPostRequest enter");
+
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
     {
@@ -1359,9 +1547,11 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
         return ehResult;
     }
 
-    if(ehRequest->resource == g_ESEasySetupResource.handle)
+    OIC_LOG_PAYLOAD(DEBUG, (OCPayload *)input);
+
+    if (ehRequest->resource == g_ESEasySetupResource.handle)
     {
-        if(ehRequest->query &&
+        if (ehRequest->query &&
             strcmp(ehRequest->query, "") &&
             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
@@ -1371,24 +1561,32 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
         }
         else
         {
-            updateEasySetupResource(ehRequest, input);
+            if (updateEasySetupResource(ehRequest, input) != OC_EH_OK)
+            {
+                OIC_LOG(ERROR, ES_RH_TAG, "Failed to update EasySetup resource.");
+                return OC_EH_BAD_REQ;
+            }
         }
     }
-    else if(ehRequest->resource == g_ESWiFiConfResource.handle)
+    else if (ehRequest->resource == g_ESWiFiConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
         }
         else
         {
-            updateWiFiConfResource(input);
+            if (updateWiFiConfResource(input) != OC_EH_OK)
+            {
+                OIC_LOG(ERROR, ES_RH_TAG, "Failed to update WifiConf resource.");
+                return OC_EH_BAD_REQ;
+            }
         }
     }
-    else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
+    else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (CheckEhRequestPayload(ehRequest) != OC_EH_OK)
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1398,9 +1596,10 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
             updateCoapCloudConfResource(input);
         }
     }
-    else if(ehRequest->resource == g_ESDevConfResource.handle)
+    else if (ehRequest->resource == g_ESDevConfResource.handle)
     {
-        if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
+        if (ehRequest->query && strcmp(ehRequest->query, "")
+                && !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
         {
             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
             return OC_EH_BAD_REQ;
@@ -1412,19 +1611,19 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
     }
 
     OCRepPayload *getResp = NULL;
-    if(ehRequest->resource == g_ESEasySetupResource.handle)
+    if (ehRequest->resource == g_ESEasySetupResource.handle)
     {
         getResp = constructResponseOfEasySetup(ehRequest);
     }
-    else if(ehRequest->resource == g_ESWiFiConfResource.handle)
+    else if (ehRequest->resource == g_ESWiFiConfResource.handle)
     {
         getResp = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_DEFAULT);
     }
-    else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
+    else if (ehRequest->resource == g_ESCoapCloudConfResource.handle)
     {
         getResp = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_DEFAULT);
     }
-    else if(ehRequest->resource == g_ESDevConfResource.handle)
+    else if (ehRequest->resource == g_ESDevConfResource.handle)
     {
         getResp = constructResponseOfDevConf(OC_RSRVD_INTERFACE_DEFAULT);
     }
@@ -1450,6 +1649,7 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
 
     return ehResult;
 }
+
 /**
  * This is the entity handler for the registered resource.
  * This is invoked by OCStack whenever it recevies a request for this resource.
@@ -1503,7 +1703,6 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
 
         // Format the response.  Note this requires some info about the request
         response.requestHandle = entityHandlerRequest->requestHandle;
-        response.resourceHandle = entityHandlerRequest->resource;
         response.ehResult = ehRet;
         //response uses OCPaylod while all get,put methodes use OCRepPayload
         response.payload = (OCPayload*) (payload);
@@ -1541,31 +1740,55 @@ OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
 {
     OIC_LOG(DEBUG, ES_RH_TAG, "SetDeviceProperty IN");
 
-    g_ESWiFiConfResource.supportedFreq = (deviceProperty->WiFi).freq;
-    OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Freq : %d", g_ESWiFiConfResource.supportedFreq);
+    if (deviceProperty->WiFi.numSupportedMode > NUM_WIFIMODE
+            || deviceProperty->WiFi.numSupportedFreq > NUM_WIFIFREQ
+            || deviceProperty->WiFi.numSupportedAuthType > NUM_WIFIAUTHTYPE
+            || deviceProperty->WiFi.numSupportedEncType > NUM_WIFIENCTYPE)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "SetDeviceProperty: Invalid Input Param");
+        return OC_STACK_INVALID_PARAM;
+    }
 
-    int modeIdx = 0;
-    while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
+    g_ESWiFiConfResource.numSupportedFreq = deviceProperty->WiFi.numSupportedFreq;
+    for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedFreq; ++i)
     {
-        g_ESWiFiConfResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
-        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Mode : %d", g_ESWiFiConfResource.supportedMode[modeIdx]);
-        modeIdx ++;
+        g_ESWiFiConfResource.supportedFreq[i] = (deviceProperty->WiFi).supportedFreq[i];
+        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Freq : %d", g_ESWiFiConfResource.supportedFreq[i]);
     }
-    g_ESWiFiConfResource.numMode = modeIdx;
 
-    OICStrcpy(g_ESDevConfResource.devName, OIC_STRING_MAX_VALUE, (deviceProperty->DevConf).deviceName);
-    OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Device Name : %s", g_ESDevConfResource.devName);
+    g_ESWiFiConfResource.numMode = deviceProperty->WiFi.numSupportedMode;
+    for (uint8_t i = 0; i < g_ESWiFiConfResource.numMode; ++i)
+    {
+        g_ESWiFiConfResource.supportedMode[i] = (deviceProperty->WiFi).supportedMode[i];
+        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Mode : %d", g_ESWiFiConfResource.supportedMode[i]);
+    }
 
-    OICStrcpy(g_ESDevConfResource.modelNumber, OIC_STRING_MAX_VALUE,
-                                                            (deviceProperty->DevConf).modelNumber);
-    OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Model Number : %s", g_ESDevConfResource.modelNumber);
+    g_ESWiFiConfResource.numSupportedAuthType = deviceProperty->WiFi.numSupportedAuthType;
+    for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedAuthType; ++i)
+    {
+        g_ESWiFiConfResource.supportedAuthType[i] = (deviceProperty->WiFi).supportedAuthType[i];
+        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Auth Type : %d",
+                g_ESWiFiConfResource.supportedAuthType[i]);
+    }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
+    g_ESWiFiConfResource.numSupportedEncType = deviceProperty->WiFi.numSupportedEncType;
+    for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedEncType; ++i)
+    {
+        g_ESWiFiConfResource.supportedEncType[i] = (deviceProperty->WiFi).supportedEncType[i];
+        OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Enc Type : %d",
+                g_ESWiFiConfResource.supportedEncType[i]);
+    }
+
+    OICStrcpy(g_ESDevConfResource.devName, OIC_STRING_MAX_VALUE,
+            (deviceProperty->DevConf).deviceName);
+    OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Device Name : %s", g_ESDevConfResource.devName);
+
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "wifiResource doesn't have any observers.");
     }
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "devConfResource doesn't have any observers.");
     }
@@ -1581,7 +1804,7 @@ OCStackResult SetEnrolleeState(ESEnrolleeState esState)
     g_ESEasySetupResource.status = esState;
     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Enrollee Status : %d", g_ESEasySetupResource.status);
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "provResource doesn't have any observers.");
     }
@@ -1597,7 +1820,7 @@ OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
     g_ESEasySetupResource.lastErrCode = esErrCode;
     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Enrollee ErrorCode : %d", g_ESEasySetupResource.lastErrCode);
 
-    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
+    if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "provResource doesn't have any observers.");
     }
@@ -1608,17 +1831,58 @@ OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
 
 OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
 {
-    if( !(ehRequest->query) ||
-                (ehRequest->query &&
-                (strcmp(ehRequest->query, "") && !CompareResourceInterface(ehRequest->query,
-                                                                        OC_RSRVD_INTERFACE_DEFAULT))))
+    if (ehRequest->query && strcmp(ehRequest->query, ""))
     {
+        uint8_t numResourceInterfaces = 0;
+        OCStackResult res = OCGetNumberOfResourceInterfaces(ehRequest->resource,
+                &numResourceInterfaces);
+        if (res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Unable to get Number of Interfaces: %s", getResult(res));
+            return OC_EH_ERROR;
+        }
+        for (uint8_t i = 0; i < numResourceInterfaces; ++i)
+        {
+            const char *interfaceName = OCGetResourceInterfaceName(ehRequest->resource, i);
+            if (CompareResourceInterface(ehRequest->query, interfaceName))
+            {
+                return OC_EH_OK;
+            }
+        }
         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
         return OC_EH_BAD_REQ;
     }
     return OC_EH_OK;
 }
 
+bool isAuthTypeSupported(WIFI_AUTHTYPE authType)
+{
+    bool supported = false;
+    for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedAuthType; ++i)
+    {
+        if (g_ESWiFiConfResource.supportedAuthType[i] == authType)
+        {
+            supported = true;
+            break;
+        }
+    }
+    return supported;
+}
+
+bool isEncTypeSupported(WIFI_ENCTYPE encType)
+{
+    bool supported = false;
+    for (uint8_t i = 0; i < g_ESWiFiConfResource.numSupportedEncType; ++i)
+    {
+        if (g_ESWiFiConfResource.supportedEncType[i] == encType)
+        {
+            supported = true;
+            break;
+        }
+    }
+    return supported;
+}
+
 const char *getResult(OCStackResult result)
 {
     switch (result)