+ // 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;
+ }
+
+ 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_ESCoapCloudConfResource.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_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);
+ }
+
+ OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
+
+ arrayPayload[childResCnt++] = add;
+ }
+
+ 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)))
+ {
+ 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);
+
+ 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];
+ }
+ OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
+ }
+ else
+ {
+ OIC_LOG(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.numRequest is 0");
+ size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
+ OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
+ }
+
+ if(gWriteUserdataCb)
+ {
+ gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
+ }
+
+ OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
+ }
+ else // link list interface
+ {
+ OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
+ }
+ } else if (
+ ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))