Change the header install path for c_common and logger
[platform/upstream/iotivity.git] / service / easy-setup / enrollee / src / resourcehandler.c
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "resourcehandler.h"
22
23 #include "ocpayload.h"
24 #include "oic_string.h"
25 #include "oic_malloc.h"
26 #include "cautilinterface.h"
27
28 /**
29  * @var ES_RH_TAG
30  * @brief Logging tag for module name.
31  */
32 #define ES_RH_TAG "ES_RH"
33 //-----------------------------------------------------------------------------
34 // Private variables
35 //-----------------------------------------------------------------------------
36
37 /**
38  * @var g_ESEasySetupResource
39  * @brief Structure for holding the Provisioning status
40  */
41 EasySetupResource g_ESEasySetupResource;
42 WiFiConfResource g_ESWiFiConfResource;
43 CoapCloudConfResource g_ESCoapCloudConfResource;
44 DevConfResource g_ESDevConfResource;
45
46 //-----------------------------------------------------------------------------
47 // Private internal function prototypes
48 //-----------------------------------------------------------------------------
49 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
50         void *callback);
51 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
52 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
53 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
54 void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
55 void updateWiFiConfResource(OCRepPayload* input);
56 void updateCoapCloudConfResource(OCRepPayload* input);
57 void updateDevConfResource(OCRepPayload* input);
58 const char *getResult(OCStackResult result);
59
60 ESConnectRequestCB gConnectRequestEvtCb = NULL;
61 ESWiFiConfCB gWifiConfRsrcEvtCb = NULL;
62 ESCoapCloudConfCB gCoapCloudConfRsrcEvtCb = NULL;
63 ESDevConfCB gDevConfRsrcEvtCb = NULL;
64
65 ESReadUserdataCb gReadUserdataCb = NULL;
66 ESWriteUserdataCb gWriteUserdataCb = NULL;
67
68 bool CompareResourceInterface(char *from, char *iface)
69 {
70     char *str = OICStrdup(from);
71     char *ptr = strtok(str, ";");
72
73     if(ptr == NULL)
74     {
75         OICFree(str);
76         return false;
77     }
78
79     do
80     {
81         if(strstr(ptr, ".if."))
82         {
83             char *if_ptr = NULL;
84             if_ptr = strtok(ptr, "=");
85             if_ptr = strtok(NULL, "=");
86
87             if(!strcmp(if_ptr, iface))
88             {
89                 OICFree(str);
90                 return true;
91             }
92         }
93
94     } while ((ptr = strtok(NULL, ";")));
95
96     OICFree(str);
97     return false;
98 }
99
100 ESResult SetCallbackForUserData(ESReadUserdataCb readCb, ESWriteUserdataCb writeCb)
101 {
102     if(!readCb && !writeCb)
103     {
104         OIC_LOG(DEBUG, ES_RH_TAG, "Both of callbacks for user data are null");
105         return ES_ERROR;
106     }
107     gReadUserdataCb = readCb;
108     gWriteUserdataCb = writeCb;
109     return ES_OK;
110 }
111
112 void RegisterWifiRsrcEventCallBack(ESWiFiConfCB cb)
113 {
114     gWifiConfRsrcEvtCb = cb;
115 }
116
117 void RegisterCloudRsrcEventCallBack(ESCoapCloudConfCB cb)
118 {
119     gCoapCloudConfRsrcEvtCb = cb;
120 }
121
122 void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
123 {
124     gDevConfRsrcEvtCb = cb;
125 }
126
127 void RegisterConnectRequestEventCallBack(ESConnectRequestCB cb)
128 {
129     gConnectRequestEvtCb = cb;
130 }
131
132 void UnRegisterResourceEventCallBack()
133 {
134     if (gWifiConfRsrcEvtCb)
135     {
136         gWifiConfRsrcEvtCb = NULL;
137     }
138     if (gCoapCloudConfRsrcEvtCb)
139     {
140         gCoapCloudConfRsrcEvtCb = NULL;
141     }
142     if (gDevConfRsrcEvtCb)
143     {
144         gDevConfRsrcEvtCb = NULL;
145     }
146     if (gConnectRequestEvtCb)
147     {
148         gConnectRequestEvtCb = NULL;
149     }
150 }
151
152 OCStackResult initEasySetupResource(bool isSecured)
153 {
154     g_ESEasySetupResource.status = ES_STATE_INIT;
155     g_ESEasySetupResource.lastErrCode = ES_ERRCODE_NO_ERROR;
156     for( int i = 0 ; i < NUM_CONNECT_TYPE ; ++i )
157     {
158         g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
159     }
160     g_ESEasySetupResource.numRequest = 0;
161
162     OCStackResult res = OC_STACK_ERROR;
163     if (isSecured)
164     {
165         res = OCCreateResource(&g_ESEasySetupResource.handle, OC_RSRVD_ES_RES_TYPE_EASYSETUP,
166         OC_RSRVD_INTERFACE_DEFAULT,
167         OC_RSRVD_ES_URI_EASYSETUP, OCEntityHandlerCb,
168         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
169     }else
170     {
171         res = OCCreateResource(&g_ESEasySetupResource.handle, OC_RSRVD_ES_RES_TYPE_EASYSETUP,
172         OC_RSRVD_INTERFACE_DEFAULT,
173         OC_RSRVD_ES_URI_EASYSETUP, OCEntityHandlerCb,
174         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
175     }
176     if(res != OC_STACK_OK)
177     {
178         OIC_LOG_V(ERROR, ES_RH_TAG, "Created EasySetup resource with result: %s", getResult(res));
179         return res;
180     }
181
182     res = OCBindResourceTypeToResource(g_ESEasySetupResource.handle, OC_RSRVD_ES_RES_TYPE_COL);
183     if(res != OC_STACK_OK)
184     {
185         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource type with result: %s", getResult(res));
186         return res;
187     }
188
189     res = OCBindResourceInterfaceToResource(g_ESEasySetupResource.handle, OC_RSRVD_INTERFACE_LL);
190     if(res != OC_STACK_OK)
191     {
192         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
193         return res;
194     }
195     res = OCBindResourceInterfaceToResource(g_ESEasySetupResource.handle, OC_RSRVD_INTERFACE_BATCH);
196     if(res != OC_STACK_OK)
197     {
198         OIC_LOG_V(ERROR, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
199         return res;
200     }
201
202     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created EasySetup resource with result: %s", getResult(res));
203     return res;
204 }
205
206 OCStackResult initWiFiConfResource(bool isSecured)
207 {
208     OCStackResult res = OC_STACK_ERROR;
209
210     g_ESWiFiConfResource.supportedFreq = WIFI_BOTH;
211     g_ESWiFiConfResource.supportedMode[0] = WIFI_11A;
212     g_ESWiFiConfResource.supportedMode[1] = WIFI_11B;
213     g_ESWiFiConfResource.supportedMode[2] = WIFI_11G;
214     g_ESWiFiConfResource.supportedMode[3] = WIFI_11N;
215     g_ESWiFiConfResource.numMode = 4;
216     g_ESWiFiConfResource.authType = NONE_AUTH;
217     g_ESWiFiConfResource.encType = NONE_ENC;
218     OICStrcpy(g_ESWiFiConfResource.ssid, sizeof(g_ESWiFiConfResource.ssid), "");
219     OICStrcpy(g_ESWiFiConfResource.cred, sizeof(g_ESWiFiConfResource.cred), "");
220
221     if (isSecured)
222     {
223         res = OCCreateResource(&g_ESWiFiConfResource.handle, OC_RSRVD_ES_RES_TYPE_WIFICONF,
224         OC_RSRVD_INTERFACE_DEFAULT,
225         OC_RSRVD_ES_URI_WIFICONF, OCEntityHandlerCb,
226         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
227     }else
228     {
229         res = OCCreateResource(&g_ESWiFiConfResource.handle, OC_RSRVD_ES_RES_TYPE_WIFICONF,
230         OC_RSRVD_INTERFACE_DEFAULT,
231         OC_RSRVD_ES_URI_WIFICONF, OCEntityHandlerCb,
232         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
233     }
234
235     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created WiFiConf resource with result: %s", getResult(res));
236     return res;
237
238 }
239
240 OCStackResult initCoapCloudConfResource(bool isSecured)
241 {
242     OCStackResult res = OC_STACK_ERROR;
243
244     OICStrcpy(g_ESCoapCloudConfResource.authCode, sizeof(g_ESCoapCloudConfResource.authCode), "");
245     OICStrcpy(g_ESCoapCloudConfResource.accessToken, sizeof(g_ESCoapCloudConfResource.accessToken), "");
246     g_ESCoapCloudConfResource.accessTokenType = NONE_OAUTH_TOKENTYPE;
247     OICStrcpy(g_ESCoapCloudConfResource.authProvider, sizeof(g_ESCoapCloudConfResource.authProvider), "");
248     OICStrcpy(g_ESCoapCloudConfResource.ciServer, sizeof(g_ESCoapCloudConfResource.ciServer), "");
249
250     if (isSecured)
251     {
252         res = OCCreateResource(&g_ESCoapCloudConfResource.handle, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF,
253         OC_RSRVD_INTERFACE_DEFAULT,
254         OC_RSRVD_ES_URI_COAPCLOUDCONF, OCEntityHandlerCb,
255         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
256     }else
257     {
258         res = OCCreateResource(&g_ESCoapCloudConfResource.handle, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF,
259         OC_RSRVD_INTERFACE_DEFAULT,
260         OC_RSRVD_ES_URI_COAPCLOUDCONF, OCEntityHandlerCb,
261         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
262     }
263
264     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created CoapCloudConf resource with result: %s", getResult(res));
265     return res;
266
267 }
268
269 OCStackResult initDevConfResource(bool isSecured)
270 {
271     OCStackResult res = OC_STACK_ERROR;
272
273     OICStrcpy(g_ESDevConfResource.devName, sizeof(g_ESDevConfResource.devName), "");
274
275     if (isSecured)
276     {
277         res = OCCreateResource(&g_ESDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
278         OC_RSRVD_INTERFACE_DEFAULT,
279         OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
280         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
281     }else
282     {
283         res = OCCreateResource(&g_ESDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
284         OC_RSRVD_INTERFACE_DEFAULT,
285         OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
286         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
287     }
288
289     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
290     return res;
291
292 }
293
294 void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
295 {
296     OIC_LOG_V(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.status %d", g_ESEasySetupResource.status);
297
298     int64_t *connect_req = NULL;
299     size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
300     if (OCRepPayloadGetIntArray(input, OC_RSRVD_ES_CONNECT, &connect_req, dimensions))
301     {
302         ESConnectRequest* connectRequest = (ESConnectRequest*)OICMalloc(sizeof(ESConnectRequest));
303         if( !connectRequest )
304         {
305             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
306             return;
307         }
308
309         int cntRequest = 0;
310         for (size_t i = 0 ; i < NUM_CONNECT_TYPE ; ++i)
311         {
312             g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
313             connectRequest->connect[i] = ES_CONNECT_NONE;
314
315             if(i < dimensions[0] &&
316                 (connect_req[i] == ES_CONNECT_WIFI || connect_req[i] == ES_CONNECT_COAPCLOUD))
317             {
318                 g_ESEasySetupResource.connectRequest[cntRequest] = connect_req[i];
319                 connectRequest->connect[cntRequest] = connect_req[i];
320                 OIC_LOG_V(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.connectType[%d] : %d",
321                                                     cntRequest, g_ESEasySetupResource.connectRequest[cntRequest]);
322                 cntRequest++;
323             }
324         }
325         connectRequest->numRequest = cntRequest;
326         g_ESEasySetupResource.numRequest = cntRequest;
327
328         if(g_ESEasySetupResource.connectRequest[0] != ES_CONNECT_NONE)
329         {
330             OIC_LOG(DEBUG, ES_RH_TAG, "Send ConnectRequest Callback To ES");
331
332             // TODO : Need to check appropriateness of gWiFiData
333             if(gConnectRequestEvtCb != NULL)
334             {
335                 gConnectRequestEvtCb(ES_OK, connectRequest);
336             }
337             else
338             {
339                 OIC_LOG(ERROR, ES_RH_TAG, "gConnectRequestEvtCb is NULL");
340             }
341         }
342     }
343
344     if(ehRequest->query)
345     {
346         if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
347         {
348             // When Provisioning resource has a POST with BatchInterface
349             updateCoapCloudConfResource(input);
350             updateWiFiConfResource(input);
351             updateDevConfResource(input);
352         }
353     }
354 }
355
356 void updateWiFiConfResource(OCRepPayload* input)
357 {
358     ESWiFiConfData* wiFiData = (ESWiFiConfData*)OICMalloc(sizeof(ESWiFiConfData));
359
360     if(wiFiData == NULL)
361     {
362         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
363         return ;
364     }
365
366     memset(wiFiData->ssid, 0, OIC_STRING_MAX_VALUE);
367     memset(wiFiData->pwd, 0, OIC_STRING_MAX_VALUE);
368     wiFiData->authtype = NONE_AUTH;
369     wiFiData->enctype = NONE_AUTH;
370     wiFiData->userdata = NULL;
371
372     char* ssid = NULL;
373     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
374     {
375         OICStrcpy(g_ESWiFiConfResource.ssid, sizeof(g_ESWiFiConfResource.ssid), ssid);
376         OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
377         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.ssid : %s", g_ESWiFiConfResource.ssid);
378     }
379
380     char* cred = NULL;
381     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
382     {
383         OICStrcpy(g_ESWiFiConfResource.cred, sizeof(g_ESWiFiConfResource.cred), cred);
384         OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
385         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.cred %s", g_ESWiFiConfResource.cred);
386     }
387
388     int64_t authType = -1;
389     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
390     {
391         g_ESWiFiConfResource.authType = authType;
392         wiFiData->authtype = g_ESWiFiConfResource.authType;
393         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.authType %u", g_ESWiFiConfResource.authType);
394     }
395
396     int64_t encType = -1;
397     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
398     {
399         g_ESWiFiConfResource.encType = encType;
400         wiFiData->enctype = g_ESWiFiConfResource.encType;
401         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESWiFiConfResource.encType %u", g_ESWiFiConfResource.encType);
402     }
403
404     if(gReadUserdataCb)
405     {
406         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFICONF, &wiFiData->userdata);
407     }
408
409     if(ssid || cred || authType!= -1 || encType != -1)
410     {
411         OIC_LOG(DEBUG, ES_RH_TAG, "Send WiFiConfRsrc Callback To ES");
412
413         // TODO : Need to check appropriateness of gWiFiData
414         if(gWifiConfRsrcEvtCb != NULL)
415         {
416             gWifiConfRsrcEvtCb(ES_OK, wiFiData);
417         }
418         else
419         {
420             OIC_LOG(ERROR, ES_RH_TAG, "gWifiConfRsrcEvtCb is NULL");
421         }
422     }
423
424     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
425     {
426         OIC_LOG(DEBUG, ES_RH_TAG, "Enrollee doesn't have any observer.");
427     }
428
429     OICFree(ssid);
430     OICFree(cred);
431     OICFree(wiFiData);
432 }
433
434 void updateCoapCloudConfResource(OCRepPayload* input)
435 {
436     ESCoapCloudConfData* cloudData = (ESCoapCloudConfData*)OICMalloc(sizeof(ESCoapCloudConfData));
437
438     if(cloudData == NULL)
439     {
440         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
441         return;
442     }
443
444     memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
445     memset(cloudData->accessToken, 0, OIC_STRING_ACCESS_TOKEN_MAX_VALUE);
446     g_ESCoapCloudConfResource.accessTokenType = NONE_OAUTH_TOKENTYPE;
447     memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
448     memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
449     cloudData->userdata = NULL;
450
451     char *authCode = NULL;
452     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
453     {
454         OICStrcpy(g_ESCoapCloudConfResource.authCode, sizeof(g_ESCoapCloudConfResource.authCode), authCode);
455         OICStrcpy(cloudData->authCode, sizeof(cloudData->authCode), authCode);
456         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.authCode %s", g_ESCoapCloudConfResource.authCode);
457     }
458
459     char *accessToken = NULL;
460     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_ACCESSTOKEN, &accessToken))
461     {
462         OICStrcpy(g_ESCoapCloudConfResource.accessToken, sizeof(g_ESCoapCloudConfResource.accessToken), accessToken);
463         OICStrcpy(cloudData->accessToken, sizeof(cloudData->accessToken), accessToken);
464         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.accessToken %s", g_ESCoapCloudConfResource.accessToken);
465     }
466
467     int64_t accessTokenType = -1;
468     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ACCESSTOKEN_TYPE, &accessTokenType))
469     {
470         g_ESCoapCloudConfResource.accessTokenType = accessTokenType;
471         cloudData->accessTokenType = g_ESCoapCloudConfResource.accessTokenType;
472         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.accessTokenType %d", g_ESCoapCloudConfResource.accessTokenType);
473     }
474
475     char *authProvider = NULL;
476     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
477     {
478         OICStrcpy(g_ESCoapCloudConfResource.authProvider, sizeof(g_ESCoapCloudConfResource.authProvider), authProvider);
479         OICStrcpy(cloudData->authProvider, sizeof(cloudData->authProvider), authProvider);
480         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.authServerUrl %s", g_ESCoapCloudConfResource.authProvider);
481     }
482
483     char *ciServer = NULL;
484     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
485     {
486         OICStrcpy(g_ESCoapCloudConfResource.ciServer, sizeof(g_ESCoapCloudConfResource.ciServer), ciServer);
487         OICStrcpy(cloudData->ciServer, sizeof(cloudData->ciServer), ciServer);
488         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "g_ESCoapCloudConfResource.ciServer %s", g_ESCoapCloudConfResource.ciServer);
489     }
490
491     if(gReadUserdataCb)
492     {
493         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF, &cloudData->userdata);
494     }
495
496     if(authCode || accessToken || authProvider || ciServer)
497     {
498         OIC_LOG(DEBUG, ES_RH_TAG, "Send CoapCloudConfRsrc Callback To ES");
499
500         // TODO : Need to check appropriateness of gCloudData
501         if(gCoapCloudConfRsrcEvtCb != NULL)
502         {
503             gCoapCloudConfRsrcEvtCb(ES_OK, cloudData);
504         }
505         else
506         {
507             OIC_LOG(DEBUG, ES_RH_TAG, "gCoapCloudConfRsrcEvtCb is NULL");
508         }
509     }
510
511     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESCoapCloudConfResource.handle, OC_HIGH_QOS))
512     {
513         OIC_LOG(DEBUG, ES_RH_TAG, "CoapCloudConf resource doesn't have any observer.");
514     }
515
516     OICFree(authCode);
517     OICFree(accessToken);
518     OICFree(authProvider);
519     OICFree(ciServer);
520     OICFree(cloudData);
521 }
522
523 void updateDevConfResource(OCRepPayload* input)
524 {
525     ESDevConfData* devConfData = (ESDevConfData*)OICMalloc(sizeof(ESDevConfData));
526
527     if(devConfData == NULL)
528     {
529         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
530         return;
531     }
532     devConfData->userdata = NULL;
533
534     if (gReadUserdataCb)
535     {
536         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
537     }
538
539     if( devConfData->userdata != NULL )
540     {
541         OIC_LOG(DEBUG, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
542
543         // TODO : Need to check appropriateness of gDevConfData
544         if(gDevConfRsrcEvtCb != NULL)
545         {
546             gDevConfRsrcEvtCb(ES_OK, devConfData);
547         }
548         else
549         {
550             OIC_LOG(DEBUG, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
551         }
552     }
553
554     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
555     {
556         OIC_LOG(DEBUG, ES_RH_TAG, "devConfResource doesn't have any observer.");
557     }
558
559     OICFree(devConfData);
560 }
561
562 OCRepPayload* constructResponseOfWiFiConf(char *interface)
563 {
564     OCRepPayload* payload = OCRepPayloadCreate();
565     if (!payload)
566     {
567         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
568         return NULL;
569     }
570
571     if(g_ESWiFiConfResource.handle == NULL)
572     {
573         OIC_LOG(ERROR, ES_RH_TAG, "WiFiConf resource is not created");
574         return NULL;
575     }
576
577     OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse WiFiConf res");
578     OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFICONF);
579
580     OCRepPayload* repPayload = NULL;
581     OCRepPayload* tempPayload = NULL;
582     if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
583     {
584         repPayload = OCRepPayloadCreate();
585         if (!repPayload)
586         {
587             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
588             return NULL;
589         }
590
591         tempPayload = payload;
592         payload = repPayload;
593
594         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
595         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
596         if( !interfaces )
597         {
598             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
599             return NULL;
600         }
601
602         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
603
604         OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
605
606         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
607         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
608         if( !resourceTypes )
609         {
610             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
611             return NULL;
612         }
613
614         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFICONF);
615
616         OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
617     }
618     else
619     {
620         OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
621         OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_WIFICONF);
622     }
623
624     size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESWiFiConfResource.numMode, 0, 0};
625     int64_t *modes_64 = (int64_t *)OICMalloc(g_ESWiFiConfResource.numMode * sizeof(int64_t));
626     if( !modes_64 )
627     {
628         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
629         return NULL;
630     }
631
632     for(int i = 0 ; i < g_ESWiFiConfResource.numMode ; ++i)
633     {
634         modes_64[i] = g_ESWiFiConfResource.supportedMode[i];
635     }
636     OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
637
638     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, g_ESWiFiConfResource.supportedFreq);
639     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, g_ESWiFiConfResource.ssid);
640     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, g_ESWiFiConfResource.cred);
641     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) g_ESWiFiConfResource.authType);
642     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) g_ESWiFiConfResource.encType);
643
644     if(gWriteUserdataCb)
645     {
646         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFICONF);
647     }
648
649     if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
650     {
651         payload = tempPayload;
652         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
653     }
654
655     return payload;
656 }
657
658 OCRepPayload* constructResponseOfCoapCloudConf(char *interface)
659 {
660     OCRepPayload* payload = OCRepPayloadCreate();
661     if (!payload)
662     {
663         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
664         return NULL;
665     }
666
667     if(g_ESCoapCloudConfResource.handle == NULL)
668     {
669         OIC_LOG(ERROR, ES_RH_TAG, "CoapCloudConf resource is not created");
670         return NULL;
671     }
672
673     OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse CoapCloudConf res");
674     OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_COAPCLOUDCONF);
675
676     OCRepPayload* repPayload = NULL;
677     OCRepPayload* tempPayload = NULL;
678     if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
679     {
680         repPayload = OCRepPayloadCreate();
681         if (!repPayload)
682         {
683             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
684             return NULL;
685         }
686
687         tempPayload = payload;
688         payload = repPayload;
689
690         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
691         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
692         if(!interfaces)
693         {
694             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
695             return NULL;
696         }
697
698         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
699
700         OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
701
702         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
703         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
704         if(!resourceTypes)
705         {
706             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
707             return NULL;
708         }
709
710         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
711
712         OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
713     }
714     else
715     {
716         OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
717         OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
718     }
719
720     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, g_ESCoapCloudConfResource.authCode);
721     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_ACCESSTOKEN, g_ESCoapCloudConfResource.accessToken);
722     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ACCESSTOKEN_TYPE, (int)g_ESCoapCloudConfResource.accessTokenType);
723     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, g_ESCoapCloudConfResource.authProvider);
724     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, g_ESCoapCloudConfResource.ciServer);
725
726     if(gWriteUserdataCb)
727     {
728         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
729     }
730
731     if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
732     {
733         payload = tempPayload;
734         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
735     }
736
737     return payload;
738 }
739
740 OCRepPayload* constructResponseOfDevConf(char *interface)
741 {
742     OCRepPayload* payload = OCRepPayloadCreate();
743     if (!payload)
744     {
745         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
746         return NULL;
747     }
748
749     if(g_ESDevConfResource.handle == NULL)
750     {
751         OIC_LOG(ERROR, ES_RH_TAG, "DevConf resource is not created");
752         return NULL;
753     }
754
755     OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse DevConf res");
756     OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
757
758     OCRepPayload* repPayload = NULL;
759     OCRepPayload* tempPayload = NULL;
760     if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
761     {
762         repPayload = OCRepPayloadCreate();
763         if (!repPayload)
764         {
765             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
766             return NULL;
767         }
768
769         tempPayload = payload;
770         payload = repPayload;
771
772         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
773         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
774         if( !interfaces )
775         {
776             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
777             return NULL;
778         }
779
780         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
781
782         OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
783
784         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
785         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
786         if( !resourceTypes )
787         {
788             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
789             return NULL;
790         }
791
792         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
793
794         OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
795     }
796     else
797     {
798         OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
799         OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
800     }
801
802     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, g_ESDevConfResource.devName);
803
804     if(gWriteUserdataCb)
805     {
806         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
807     }
808
809     if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
810     {
811         payload = tempPayload;
812         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
813     }
814
815     return payload;
816 }
817
818 OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
819 {
820     OCRepPayload* payload = OCRepPayloadCreate();
821     if (!payload)
822     {
823         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
824         return NULL;
825     }
826
827     // Requested interface is Link list interface
828     //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
829     if (!ehRequest->query || !strcmp(ehRequest->query, "") ||
830         CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) ||
831         CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
832     {
833         const OCRepPayload *arrayPayload[3] = {NULL};
834
835         int childResCnt = 0;
836
837         if(g_ESWiFiConfResource.handle != NULL)
838         {
839             OCRepPayload *add = OCRepPayloadCreate();
840             if(!add)
841             {
842                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
843                 return NULL;
844             }
845
846             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
847             char **resourceType = NULL;
848             resourceType = (char **)OICMalloc(sizeof(char *) * 1);
849             char **resourceInterface = NULL;
850             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
851
852             if(!resourceType || !resourceInterface)
853             {
854                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
855                 return NULL;
856             }
857
858             resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFICONF);
859             resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
860
861             add->base.type = PAYLOAD_TYPE_REPRESENTATION;
862             OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFICONF);
863             OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
864                                             (const char **)resourceType, dimensions);
865             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
866                                             (const char **)resourceInterface, dimensions);
867
868             OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESWiFiConfResource.handle);
869             OCRepPayload *policy = OCRepPayloadCreate();
870             if (!policy)
871             {
872                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
873                 return NULL;
874             }
875
876             OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
877                                     ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
878             if (p & OC_SECURE)
879             {
880                 OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
881                 uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
882                                                                     ehRequest->devAddr.flags);
883                 OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
884             }
885
886             OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
887
888             arrayPayload[childResCnt++] = add;
889         }
890
891         if(g_ESDevConfResource.handle != NULL)
892         {
893             OCRepPayload *add = OCRepPayloadCreate();
894             if(!add)
895             {
896                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
897                 return NULL;
898             }
899
900             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
901             char **resourceType = NULL;
902             resourceType = (char **)OICMalloc(sizeof(char *) * 1);
903             char **resourceInterface = NULL;
904             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
905
906             if(!resourceType || !resourceInterface)
907             {
908                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
909                 return NULL;
910             }
911
912             resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
913             resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
914
915             add->base.type = PAYLOAD_TYPE_REPRESENTATION;
916             OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
917             OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
918                                             (const char **)resourceType, dimensions);
919             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
920                                             (const char **)resourceInterface, dimensions);
921
922             OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESDevConfResource.handle);
923             OCRepPayload *policy = OCRepPayloadCreate();
924             if (!policy)
925             {
926                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
927                 return NULL;
928             }
929
930             OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
931                                     ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
932             if (p & OC_SECURE)
933             {
934                 OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
935                 uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
936                                                                     ehRequest->devAddr.flags);
937                 OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
938             }
939
940             OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
941
942             arrayPayload[childResCnt++] = add;
943         }
944
945         if(g_ESCoapCloudConfResource.handle != NULL)
946         {
947             OCRepPayload *add = OCRepPayloadCreate();
948             if(!add)
949             {
950                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
951                 return NULL;
952             }
953
954             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
955             char **resourceType = NULL;
956             resourceType = (char **)OICMalloc(sizeof(char *) * 1);
957             char **resourceInterface = NULL;
958             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
959
960             if(!resourceType || !resourceInterface)
961             {
962                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
963                 return NULL;
964             }
965
966             resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF);
967             resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
968
969             add->base.type = PAYLOAD_TYPE_REPRESENTATION;
970             OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_COAPCLOUDCONF);
971             OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
972                                             (const char **)resourceType, dimensions);
973             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
974                                             (const char **)resourceInterface, dimensions);
975
976             OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESCoapCloudConfResource.handle);
977             OCRepPayload *policy = OCRepPayloadCreate();
978             if (!policy)
979             {
980                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
981                 return NULL;
982             }
983
984             OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
985                                     ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
986             if (p & OC_SECURE)
987             {
988                 OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
989                 uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
990                                                                     ehRequest->devAddr.flags);
991                 OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
992             }
993
994             OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);
995
996             arrayPayload[childResCnt++] = add;
997         }
998
999         size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
1000
1001         if(!ehRequest->query || !strcmp(ehRequest->query, "") ||
1002             CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1003         {
1004             OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res");
1005             OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_EASYSETUP);
1006             OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
1007             OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
1008             OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
1009             OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
1010             OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_COL);
1011
1012             OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
1013             OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
1014
1015             if(g_ESEasySetupResource.numRequest > 0)
1016             {
1017                 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest, 0, 0};
1018                 int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest  * sizeof(int64_t));
1019                 if(!connectRequest)
1020                 {
1021                     OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
1022                     return NULL;
1023                 }
1024
1025                 for(int i = 0 ; i < g_ESEasySetupResource.numRequest  ; ++i)
1026                 {
1027                     connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
1028                 }
1029                 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
1030             }
1031             else
1032             {
1033                 OIC_LOG(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.numRequest is 0");
1034                 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
1035                 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
1036             }
1037
1038             if(gWriteUserdataCb)
1039             {
1040                 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
1041             }
1042
1043             OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
1044         }
1045         else    // link list interface
1046         {
1047             OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
1048         }
1049     } else if (
1050         ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
1051
1052     {
1053         OIC_LOG(DEBUG, ES_RH_TAG, "constructResponse EasySetup res");
1054         OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_EASYSETUP);
1055
1056         OCRepPayload* repPayload = NULL;
1057
1058         repPayload = OCRepPayloadCreate();
1059         if (!repPayload)
1060         {
1061             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
1062             return NULL;
1063         }
1064
1065         size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {3, 0, 0};
1066         char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
1067         if(!interfaces)
1068         {
1069             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
1070             return NULL;
1071         }
1072
1073         interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
1074         interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_LL);
1075         interfaces[2] = OICStrdup(OC_RSRVD_INTERFACE_BATCH);
1076
1077         OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_INTERFACE, (const char **)interfaces, interfacesDimensions);
1078
1079         size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
1080         char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
1081         if(!resourceTypes)
1082         {
1083             OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
1084             return NULL;
1085         }
1086
1087         resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_EASYSETUP);
1088         resourceTypes[1] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COL);
1089
1090         OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_RES_TYPE, (const char **)resourceTypes, resourceTypesDimensions);
1091
1092         OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
1093         OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
1094         if(g_ESEasySetupResource.numRequest > 0)
1095         {
1096             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest, 0, 0};
1097             int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest  * sizeof(int64_t));
1098             if(!connectRequest)
1099             {
1100                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
1101                 return NULL;
1102             }
1103
1104             for(int i = 0 ; i < g_ESEasySetupResource.numRequest ; ++i)
1105             {
1106                 connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
1107             }
1108             OCRepPayloadSetIntArray(repPayload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
1109         }
1110         else
1111         {
1112             OIC_LOG(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.numRequest is 0");
1113             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
1114             OCRepPayloadSetIntArray(repPayload, OC_RSRVD_ES_CONNECT, NULL, dimensions);
1115         }
1116
1117         if(gWriteUserdataCb)
1118         {
1119             gWriteUserdataCb(repPayload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
1120         }
1121
1122         OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
1123     }
1124
1125     if(ehRequest->query)
1126     {
1127         if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
1128         {// When Provisioning resource has a GET with BatchInterface
1129             OCRepPayload* head = payload;
1130             OCRepPayload* nextPayload = NULL;
1131
1132             nextPayload = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_BATCH);
1133             if(nextPayload != NULL)
1134             {
1135                 payload->next = nextPayload;
1136                 payload = payload->next;
1137             }
1138
1139             nextPayload = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_BATCH);
1140             if(nextPayload != NULL)
1141             {
1142                 payload->next = nextPayload;
1143                 payload = payload->next;
1144             }
1145
1146             nextPayload = constructResponseOfDevConf(OC_RSRVD_INTERFACE_BATCH);
1147             if(nextPayload != NULL)
1148             {
1149                 payload->next = nextPayload;
1150             }
1151
1152             payload = head;
1153         }
1154     }
1155
1156     return payload;
1157 }
1158
1159
1160 OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
1161 {
1162     OCStackResult res = OC_STACK_ERROR;
1163     bool maskFlag = false;
1164
1165     res = initEasySetupResource(isSecured);
1166     if(res != OC_STACK_OK)
1167     {
1168         // TODO: destroy logic will be added
1169         OIC_LOG_V(ERROR, ES_RH_TAG, "initEasySetupResource result: %s", getResult(res));
1170
1171         return res;
1172     }
1173
1174     if((resourceMask & ES_WIFICONF_RESOURCE) == ES_WIFICONF_RESOURCE)
1175     {
1176         maskFlag = true;
1177         res = initWiFiConfResource(isSecured);
1178         if(res != OC_STACK_OK)
1179         {
1180             OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiConfResource result: %s", getResult(res));
1181             return res;
1182         }
1183
1184         res = OCBindResource(g_ESEasySetupResource.handle, g_ESWiFiConfResource.handle);
1185         if(res != OC_STACK_OK)
1186         {
1187             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiConfResource result: %s", getResult(res));
1188             return res;
1189         }
1190
1191     }
1192
1193     if((resourceMask & ES_COAPCLOUDCONF_RESOURCE) == ES_COAPCLOUDCONF_RESOURCE)
1194     {
1195         maskFlag = true;
1196         res = initCoapCloudConfResource(isSecured);
1197         if(res != OC_STACK_OK)
1198         {
1199             OIC_LOG_V(ERROR, ES_RH_TAG, "initCoapCloudConfResource result: %s", getResult(res));
1200             return res;
1201         }
1202
1203         res = OCBindResource(g_ESEasySetupResource.handle, g_ESCoapCloudConfResource.handle);
1204         if(res != OC_STACK_OK)
1205         {
1206             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CoapCloudConfResource result: %s", getResult(res));
1207             return res;
1208         }
1209     }
1210
1211     if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
1212     {
1213         maskFlag = true;
1214         res = initDevConfResource(isSecured);
1215         if(res != OC_STACK_OK)
1216         {
1217             OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
1218             return res;
1219         }
1220
1221         res = OCBindResource(g_ESEasySetupResource.handle, g_ESDevConfResource.handle);
1222         if(res != OC_STACK_OK)
1223         {
1224             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
1225             return res;
1226         }
1227     }
1228
1229     if(maskFlag == false)
1230     {
1231         OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
1232         return OC_STACK_ERROR;
1233
1234     }
1235
1236     OIC_LOG_V(DEBUG, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
1237
1238     return res;
1239 }
1240
1241 OCStackResult DeleteEasySetupResources()
1242 {
1243     OCStackResult res = OC_STACK_ERROR;
1244     if (g_ESWiFiConfResource.handle != NULL)
1245     {
1246         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESWiFiConfResource.handle);
1247         if(res != OC_STACK_OK)
1248         {
1249             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
1250         }
1251     }
1252     if (g_ESCoapCloudConfResource.handle != NULL)
1253     {
1254         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESCoapCloudConfResource.handle);
1255         if(res != OC_STACK_OK)
1256         {
1257             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
1258         }
1259     }
1260     if (g_ESDevConfResource.handle != NULL)
1261     {
1262         res = OCUnBindResource(g_ESEasySetupResource.handle, g_ESDevConfResource.handle);
1263         if(res != OC_STACK_OK)
1264         {
1265             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
1266         }
1267     }
1268
1269     if (g_ESWiFiConfResource.handle != NULL)
1270     {
1271         res = OCDeleteResource(g_ESWiFiConfResource.handle);
1272         if (res != OC_STACK_OK)
1273         {
1274             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
1275         }
1276     }
1277
1278     if(g_ESCoapCloudConfResource.handle != NULL)
1279     {
1280         res = OCDeleteResource(g_ESCoapCloudConfResource.handle);
1281         if (res != OC_STACK_OK)
1282         {
1283             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
1284         }
1285     }
1286
1287     if(g_ESDevConfResource.handle != NULL)
1288     {
1289         res = OCDeleteResource(g_ESDevConfResource.handle);
1290         if (res != OC_STACK_OK)
1291         {
1292             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
1293         }
1294     }
1295
1296     if(g_ESEasySetupResource.handle != NULL)
1297     {
1298         res = OCDeleteResource(g_ESEasySetupResource.handle);
1299         if (res != OC_STACK_OK)
1300         {
1301             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
1302         }
1303     }
1304
1305     return res;
1306 }
1307
1308 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
1309 {
1310     OCEntityHandlerResult ehResult = OC_EH_ERROR;
1311     if (!ehRequest)
1312     {
1313         OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
1314         return ehResult;
1315     }
1316     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1317     {
1318         OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1319         return ehResult;
1320     }
1321
1322     OCRepPayload *getResp = NULL;
1323     *payload = NULL;
1324
1325     if(ehRequest->resource == g_ESEasySetupResource.handle)
1326     {
1327         if(ehRequest->query &&
1328             strcmp(ehRequest->query, "") &&
1329             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) &&
1330             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1331             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1332         {
1333             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1334             return OC_EH_BAD_REQ;
1335         }
1336         else
1337         {
1338             getResp = constructResponseOfEasySetup(ehRequest);
1339         }
1340     }
1341     else if(ehRequest->resource == g_ESWiFiConfResource.handle)
1342     {
1343         if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1344         {
1345             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1346             return OC_EH_BAD_REQ;
1347         }
1348         else
1349         {
1350             getResp = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_DEFAULT);
1351         }
1352     }
1353     else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
1354     {
1355         if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1356         {
1357             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1358             return OC_EH_BAD_REQ;
1359         }
1360         else
1361         {
1362             getResp = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_DEFAULT);
1363         }
1364     }
1365     else if(ehRequest->resource == g_ESDevConfResource.handle)
1366     {
1367         if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1368         {
1369             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1370             return OC_EH_BAD_REQ;
1371         }
1372         else
1373         {
1374             getResp = constructResponseOfDevConf(OC_RSRVD_INTERFACE_DEFAULT);
1375         }
1376     }
1377
1378     if (!getResp)
1379     {
1380         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1381         return OC_EH_ERROR;
1382     }
1383
1384     *payload = getResp;
1385     ehResult = OC_EH_OK;
1386
1387     return ehResult;
1388 }
1389
1390 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
1391 {
1392     OIC_LOG(DEBUG, ES_RH_TAG, "ProcessPostRequest enter");
1393     OCEntityHandlerResult ehResult = OC_EH_ERROR;
1394     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1395     {
1396         OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1397         return ehResult;
1398     }
1399
1400     OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
1401     if (!input)
1402     {
1403         OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
1404         return ehResult;
1405     }
1406
1407     if(ehRequest->resource == g_ESEasySetupResource.handle)
1408     {
1409         if(ehRequest->query &&
1410             strcmp(ehRequest->query, "") &&
1411             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1412             !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1413         {
1414             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1415             return OC_EH_BAD_REQ;
1416         }
1417         else
1418         {
1419             updateEasySetupResource(ehRequest, input);
1420         }
1421     }
1422     else if(ehRequest->resource == g_ESWiFiConfResource.handle)
1423     {
1424         if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1425         {
1426             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1427             return OC_EH_BAD_REQ;
1428         }
1429         else
1430         {
1431             updateWiFiConfResource(input);
1432         }
1433     }
1434     else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
1435     {
1436         if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1437         {
1438             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1439             return OC_EH_BAD_REQ;
1440         }
1441         else
1442         {
1443             updateCoapCloudConfResource(input);
1444         }
1445     }
1446     else if(ehRequest->resource == g_ESDevConfResource.handle)
1447     {
1448         if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1449         {
1450             OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1451             return OC_EH_BAD_REQ;
1452         }
1453         else
1454         {
1455             updateDevConfResource(input);
1456         }
1457     }
1458
1459     OCRepPayload *getResp = NULL;
1460     if(ehRequest->resource == g_ESEasySetupResource.handle)
1461     {
1462         getResp = constructResponseOfEasySetup(ehRequest);
1463     }
1464     else if(ehRequest->resource == g_ESWiFiConfResource.handle)
1465     {
1466         getResp = constructResponseOfWiFiConf(OC_RSRVD_INTERFACE_DEFAULT);
1467     }
1468     else if(ehRequest->resource == g_ESCoapCloudConfResource.handle)
1469     {
1470         getResp = constructResponseOfCoapCloudConf(OC_RSRVD_INTERFACE_DEFAULT);
1471     }
1472     else if(ehRequest->resource == g_ESDevConfResource.handle)
1473     {
1474         getResp = constructResponseOfDevConf(OC_RSRVD_INTERFACE_DEFAULT);
1475     }
1476
1477     if (!getResp)
1478     {
1479         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1480         return OC_EH_ERROR;
1481     }
1482
1483     *payload = getResp;
1484     ehResult = OC_EH_OK;
1485
1486     return ehResult;
1487 }
1488
1489 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
1490         OCRepPayload** payload)
1491 {
1492     (void) ehRequest;
1493     (void) payload;
1494     OCEntityHandlerResult ehResult = OC_EH_BAD_REQ;
1495
1496     return ehResult;
1497 }
1498 /**
1499  * This is the entity handler for the registered resource.
1500  * This is invoked by OCStack whenever it recevies a request for this resource.
1501  */
1502 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
1503         OCEntityHandlerRequest* entityHandlerRequest, void *callback)
1504 {
1505     (void) callback;
1506     OCEntityHandlerResult ehRet = OC_EH_OK;
1507     OCEntityHandlerResponse response =
1508     { 0, 0, OC_EH_ERROR, 0, 0,
1509     { },
1510     { 0 }, false };
1511     OCRepPayload* payload = NULL;
1512
1513     if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
1514     {
1515         if (OC_REST_GET == entityHandlerRequest->method)
1516         {
1517             OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
1518             ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
1519         }
1520         else if (OC_REST_PUT == entityHandlerRequest->method)
1521         {
1522             OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
1523
1524             //PUT request will be handled in the internal implementation
1525             if (g_ESEasySetupResource.handle != NULL)
1526             {
1527                 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
1528             }
1529             else
1530             {
1531                 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1532                 ehRet = OC_EH_ERROR;
1533             }
1534         }
1535         else if (OC_REST_POST == entityHandlerRequest->method)
1536         {
1537             OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
1538             if (g_ESEasySetupResource.handle != NULL)
1539             {
1540                 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
1541             }
1542             else
1543             {
1544                 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1545                 ehRet = OC_EH_ERROR;
1546             }
1547         }
1548
1549         // Format the response.  Note this requires some info about the request
1550         response.requestHandle = entityHandlerRequest->requestHandle;
1551         response.resourceHandle = entityHandlerRequest->resource;
1552         response.ehResult = ehRet;
1553         //response uses OCPaylod while all get,put methodes use OCRepPayload
1554         response.payload = (OCPayload*) (payload);
1555         response.numSendVendorSpecificHeaderOptions = 0;
1556         memset(response.sendVendorSpecificHeaderOptions, 0,
1557                 sizeof(response.sendVendorSpecificHeaderOptions));
1558         memset(response.resourceUri, 0, sizeof(response.resourceUri));
1559         // Indicate that response is NOT in a persistent buffer
1560         response.persistentBufferFlag = 0;
1561
1562         // Send the response
1563         OIC_LOG(INFO, ES_RH_TAG, "Invoking OCDoResponse");
1564         if (OCDoResponse(&response) != OC_STACK_OK)
1565         {
1566             OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
1567             ehRet = OC_EH_ERROR;
1568         }
1569     }
1570     if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG))
1571     {
1572         OIC_LOG(DEBUG, ES_RH_TAG, "Flag includes OC_OBSERVE_FLAG");
1573
1574         if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action)
1575         {
1576             OIC_LOG(DEBUG, ES_RH_TAG, "Received OC_OBSERVE_REGISTER from Mediator");
1577         }
1578         else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action)
1579         {
1580             OIC_LOG(DEBUG, ES_RH_TAG, "Received OC_OBSERVE_DEREGISTER from Mediator");
1581         }
1582     }
1583
1584     OIC_LOG(INFO, ES_RH_TAG, "ES OCEntityHandlerCb OUT");
1585     return ehRet;
1586 }
1587
1588 OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
1589 {
1590     OIC_LOG(DEBUG, ES_RH_TAG, "SetDeviceProperty IN");
1591
1592     g_ESWiFiConfResource.supportedFreq = (deviceProperty->WiFi).freq;
1593     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Freq : %d", g_ESWiFiConfResource.supportedFreq);
1594
1595     int modeIdx = 0;
1596     while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
1597     {
1598         g_ESWiFiConfResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
1599         OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "WiFi Mode : %d", g_ESWiFiConfResource.supportedMode[modeIdx]);
1600         modeIdx ++;
1601     }
1602     g_ESWiFiConfResource.numMode = modeIdx;
1603
1604     OICStrcpy(g_ESDevConfResource.devName, OIC_STRING_MAX_VALUE, (deviceProperty->DevConf).deviceName);
1605     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Device Name : %s", g_ESDevConfResource.devName);
1606
1607     if (OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiConfResource.handle, OC_HIGH_QOS))
1608     {
1609         OIC_LOG(DEBUG, ES_RH_TAG, "wifiResource doesn't have any observers.");
1610     }
1611
1612     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
1613     {
1614         OIC_LOG(DEBUG, ES_RH_TAG, "devConfResource doesn't have any observers.");
1615     }
1616
1617     OIC_LOG(DEBUG, ES_RH_TAG, "SetDeviceProperty OUT");
1618     return OC_STACK_OK;
1619 }
1620
1621 OCStackResult SetEnrolleeState(ESEnrolleeState esState)
1622 {
1623     OIC_LOG(DEBUG, ES_RH_TAG, "SetEnrolleeState IN");
1624
1625     g_ESEasySetupResource.status = esState;
1626     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Enrollee Status : %d", g_ESEasySetupResource.status);
1627
1628     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
1629     {
1630         OIC_LOG(DEBUG, ES_RH_TAG, "provResource doesn't have any observers.");
1631     }
1632
1633     OIC_LOG(DEBUG, ES_RH_TAG, "SetEnrolleeState OUT");
1634     return OC_STACK_OK;
1635 }
1636
1637 OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
1638 {
1639     OIC_LOG(DEBUG, ES_RH_TAG, "SetEnrolleeErrCode IN");
1640
1641     g_ESEasySetupResource.lastErrCode = esErrCode;
1642     OIC_LOG_V(INFO_PRIVATE, ES_RH_TAG, "Enrollee ErrorCode : %d", g_ESEasySetupResource.lastErrCode);
1643
1644     if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESEasySetupResource.handle, OC_HIGH_QOS))
1645     {
1646         OIC_LOG(DEBUG, ES_RH_TAG, "provResource doesn't have any observers.");
1647     }
1648
1649     OIC_LOG(DEBUG, ES_RH_TAG, "SetEnrolleeErrCode OUT");
1650     return OC_STACK_OK;
1651 }
1652
1653 OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
1654 {
1655     if( !ehRequest->query || (strcmp(ehRequest->query, "") &&
1656                 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
1657     {
1658         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1659         return OC_EH_BAD_REQ;
1660     }
1661     return OC_EH_OK;
1662 }
1663
1664 const char *getResult(OCStackResult result)
1665 {
1666     switch (result)
1667     {
1668         case OC_STACK_OK:
1669             return "OC_STACK_OK";
1670         case OC_STACK_INVALID_URI:
1671             return "OC_STACK_INVALID_URI";
1672         case OC_STACK_INVALID_QUERY:
1673             return "OC_STACK_INVALID_QUERY";
1674         case OC_STACK_INVALID_IP:
1675             return "OC_STACK_INVALID_IP";
1676         case OC_STACK_INVALID_PORT:
1677             return "OC_STACK_INVALID_PORT";
1678         case OC_STACK_INVALID_CALLBACK:
1679             return "OC_STACK_INVALID_CALLBACK";
1680         case OC_STACK_INVALID_METHOD:
1681             return "OC_STACK_INVALID_METHOD";
1682         case OC_STACK_NO_MEMORY:
1683             return "OC_STACK_NO_MEMORY";
1684         case OC_STACK_COMM_ERROR:
1685             return "OC_STACK_COMM_ERROR";
1686         case OC_STACK_INVALID_PARAM:
1687             return "OC_STACK_INVALID_PARAM";
1688         case OC_STACK_NOTIMPL:
1689             return "OC_STACK_NOTIMPL";
1690         case OC_STACK_NO_RESOURCE:
1691             return "OC_STACK_NO_RESOURCE";
1692         case OC_STACK_RESOURCE_ERROR:
1693             return "OC_STACK_RESOURCE_ERROR";
1694         case OC_STACK_SLOW_RESOURCE:
1695             return "OC_STACK_SLOW_RESOURCE";
1696         case OC_STACK_NO_OBSERVERS:
1697             return "OC_STACK_NO_OBSERVERS";
1698         case OC_STACK_ERROR:
1699             return "OC_STACK_ERROR";
1700         default:
1701             return "UNKNOWN";
1702     }
1703 }