Fix warning codes in Easysetup
[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
27 /**
28  * @var ES_RH_TAG
29  * @brief Logging tag for module name.
30  */
31 #define ES_RH_TAG "ES_RH"
32 //-----------------------------------------------------------------------------
33 // Private variables
34 //-----------------------------------------------------------------------------
35
36 /**
37  * @var gProvResource
38  * @brief Structure for holding the Provisioning status and target information required to
39  * connect to the target network
40  */
41 static ProvResource gProvResource;
42 static WiFiResource gWiFiResource;
43 static CloudResource gCloudResource;
44 static DevConfResource gDevConfResource;
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 updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
55 void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
56 void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
57 void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
58 const char *getResult(OCStackResult result);
59
60 ESWiFiCB gWifiRsrcEvtCb = NULL;
61 ESCloudCB gCloudRsrcEvtCb = NULL;
62 ESDevConfCB gDevConfRsrcEvtCb = NULL;
63
64 ESReadUserdataCb gReadUserdataCb = NULL;
65 ESWriteUserdataCb gWriteUserdataCb = NULL;
66
67 bool CompareResourceInterface(char *from, char *iface)
68 {
69     char *str = OICStrdup(from);
70     char *ptr = strtok(str, ";");
71
72     if(ptr == NULL)
73     {
74         return false;
75     }
76
77     do
78     {
79         if(strstr(ptr, ".if."))
80         {
81             char *if_ptr = NULL;
82             if_ptr = strtok(ptr, "=");
83             if_ptr = strtok(NULL, "=");
84
85             if(!strcmp(if_ptr, iface))
86             {
87                 return true;
88             }
89         }
90
91     } while ((ptr = strtok(NULL, ";")));
92
93     return false;
94 }
95
96 ESResult SetCallbackForUserData(ESReadUserdataCb readCb, ESWriteUserdataCb writeCb)
97 {
98     if(!readCb && !writeCb)
99     {
100         OIC_LOG(INFO, ES_RH_TAG, "Both of callbacks for user data are null");
101         return ES_ERROR;
102     }
103     gReadUserdataCb = readCb;
104     gWriteUserdataCb = writeCb;
105     return ES_OK;
106 }
107
108 void RegisterWifiRsrcEventCallBack(ESWiFiCB cb)
109 {
110     gWifiRsrcEvtCb = cb;
111 }
112
113 void RegisterCloudRsrcEventCallBack(ESCloudCB cb)
114 {
115     gCloudRsrcEvtCb = cb;
116 }
117
118 void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
119 {
120     gDevConfRsrcEvtCb = cb;
121 }
122
123 void UnRegisterResourceEventCallBack()
124 {
125     if (gWifiRsrcEvtCb)
126     {
127         gWifiRsrcEvtCb = NULL;
128     }
129     if (gCloudRsrcEvtCb)
130     {
131         gCloudRsrcEvtCb = NULL;
132     }
133     if (gDevConfRsrcEvtCb)
134     {
135         gDevConfRsrcEvtCb = NULL;
136     }
137 }
138
139 OCStackResult initProvResource(bool isSecured)
140 {
141     gProvResource.status = ES_STATE_INIT;
142     gProvResource.lastErrCode = ES_ERRCODE_NO_ERROR;
143     OICStrcpy(gProvResource.ocfWebLinks, MAX_WEBLINKLEN, "");
144
145     OCStackResult res = OC_STACK_ERROR;
146     if (isSecured)
147     {
148         res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
149         OC_RSRVD_INTERFACE_DEFAULT,
150         OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
151         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
152     }else
153     {
154         res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
155         OC_RSRVD_INTERFACE_DEFAULT,
156         OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
157         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
158     }
159     if(res)
160     {
161         OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
162         return res;
163     }
164
165     res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_LL);
166     if(res)
167     {
168         OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
169         return res;
170     }
171     res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
172     if(res)
173     {
174         OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
175         return res;
176     }
177
178     OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
179     return res;
180 }
181
182 OCStackResult initWiFiResource(bool isSecured)
183 {
184     OCStackResult res = OC_STACK_ERROR;
185
186     gWiFiResource.supportedFreq = WIFI_BOTH;
187     gWiFiResource.supportedMode[0] = WIFI_11A;
188     gWiFiResource.supportedMode[1] = WIFI_11B;
189     gWiFiResource.supportedMode[2] = WIFI_11G;
190     gWiFiResource.supportedMode[3] = WIFI_11N;
191     gWiFiResource.numMode = 4;
192     gWiFiResource.authType = NONE_AUTH;
193     gWiFiResource.encType = NONE_ENC;
194     OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), "");
195     OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), "");
196
197     if (isSecured)
198     {
199         res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
200         OC_RSRVD_INTERFACE_DEFAULT,
201         OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
202         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
203     }else
204     {
205         res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
206         OC_RSRVD_INTERFACE_DEFAULT,
207         OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
208         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
209     }
210
211     OIC_LOG_V(INFO, ES_RH_TAG, "Created WiFi resource with result: %s", getResult(res));
212     return res;
213
214 }
215
216 OCStackResult initCloudServerResource(bool isSecured)
217 {
218     OCStackResult res = OC_STACK_ERROR;
219
220     OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), "");
221     OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), "");
222     OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), "");
223
224     if (isSecured)
225     {
226         res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
227         OC_RSRVD_INTERFACE_DEFAULT,
228         OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
229         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
230     }else
231     {
232         res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
233         OC_RSRVD_INTERFACE_DEFAULT,
234         OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
235         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
236     }
237
238     OIC_LOG_V(INFO, ES_RH_TAG, "Created CloudServer resource with result: %s", getResult(res));
239     return res;
240
241 }
242
243 OCStackResult initDevConfResource(bool isSecured)
244 {
245     OCStackResult res = OC_STACK_ERROR;
246
247     OICStrcpy(gDevConfResource.devName, sizeof(gDevConfResource.devName), "");
248     OICStrcpy(gDevConfResource.modelNumber, sizeof(gDevConfResource.modelNumber), "");
249     OICStrcpy(gDevConfResource.location, sizeof(gDevConfResource.location), "");
250     OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), "");
251     OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), "");
252
253     if (isSecured)
254     {
255         res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
256         OC_RSRVD_INTERFACE_DEFAULT,
257         OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
258         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
259     }else
260     {
261         res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
262         OC_RSRVD_INTERFACE_DEFAULT,
263         OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
264         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
265     }
266
267     OIC_LOG_V(INFO, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
268     return res;
269
270 }
271
272 void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
273 {
274     OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %d", gProvResource.status);
275
276     if(ehRequest->query)
277     {
278         if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
279         {
280             // When Provisioning resource has a POST with BatchInterface
281             updateCloudResource(NULL, input);
282             updateWiFiResource(NULL, input);
283             updateDevConfResource(NULL, input);
284         }
285     }
286 }
287
288 void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
289 {
290     if(ehRequest &&
291         strcmp(ehRequest->query, "") &&
292         !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
293     {
294         // In case of link list, batch interface
295         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
296         return ;
297     }
298
299     ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
300
301     if(wiFiData == NULL)
302     {
303         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
304         return ;
305     }
306
307     memset(wiFiData->ssid, 0, MAX_WEBLINKLEN);
308     memset(wiFiData->pwd, 0, MAX_WEBLINKLEN);
309     wiFiData->authtype = NONE_AUTH;
310     wiFiData->enctype = NONE_AUTH;
311     wiFiData->userdata = NULL;
312
313     char* ssid = NULL;
314     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
315     {
316         OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
317         OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
318         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.ssid : %s", gWiFiResource.ssid);
319     }
320
321     char* cred = NULL;
322     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
323     {
324         OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
325         OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
326         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
327     }
328
329     int64_t authType = -1;
330     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
331     {
332         gWiFiResource.authType = authType;
333         wiFiData->authtype = gWiFiResource.authType;
334         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
335     }
336
337     int64_t encType = -1;
338     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
339     {
340         gWiFiResource.encType = encType;
341         wiFiData->enctype = gWiFiResource.encType;
342         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
343     }
344
345     if(gReadUserdataCb)
346     {
347         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFI, &wiFiData->userdata);
348     }
349
350     if(ssid || cred || authType!= -1 || encType != -1)
351     {
352         OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");
353
354         // TODO : Need to check appropriateness of gWiFiData
355         if(gWifiRsrcEvtCb != NULL)
356         {
357             gWifiRsrcEvtCb(ES_OK, wiFiData);
358         }
359         else
360         {
361             OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
362         }
363     }
364
365     OICFree(wiFiData);
366 }
367
368 void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
369 {
370     if(ehRequest &&
371         strcmp(ehRequest->query, "") &&
372         !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
373     {
374         // In case of link list, batch interface
375         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
376         return ;
377     }
378
379     ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
380
381     if(cloudData == NULL)
382     {
383         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
384         return;
385     }
386
387     memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
388     memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
389     memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
390     cloudData->userdata = NULL;
391
392     char *authCode = NULL;
393     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
394     {
395         OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
396         OICStrcpy(cloudData->authCode, sizeof(cloudData->authCode), authCode);
397         OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
398     }
399
400     char *authProvider = NULL;
401     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
402     {
403         OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
404         OICStrcpy(cloudData->authProvider, sizeof(cloudData->authProvider), authProvider);
405         OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
406     }
407
408     char *ciServer = NULL;
409     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
410     {
411         OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
412         OICStrcpy(cloudData->ciServer, sizeof(cloudData->ciServer), ciServer);
413         OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
414     }
415
416     if(gReadUserdataCb)
417     {
418         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER, &cloudData->userdata);
419     }
420
421     if(authCode || authProvider || ciServer)
422     {
423         OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");
424
425         // TODO : Need to check appropriateness of gCloudData
426         if(gCloudRsrcEvtCb != NULL)
427         {
428             gCloudRsrcEvtCb(ES_OK, cloudData);
429         }
430         else
431         {
432             OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
433         }
434     }
435
436     OICFree(cloudData);
437 }
438
439 void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
440 {
441     if(ehRequest &&
442         strcmp(ehRequest->query, "") &&
443         !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
444     {
445         // In case of link list, batch interface
446         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
447         return ;
448     }
449
450     ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
451
452     if(devConfData == NULL)
453     {
454         OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
455         return;
456     }
457     memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
458     memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
459     devConfData->userdata = NULL;
460
461     char *location = NULL;
462     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LOCATION, &location))
463     {
464         OICStrcpy(gDevConfResource.location, sizeof(gDevConfResource.location), location);
465         OICStrcpy(devConfData->location, sizeof(devConfData->location), location);
466         OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.location %s", gDevConfResource.location);
467     }
468
469     char *country = NULL;
470     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country))
471     {
472         OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
473         OICStrcpy(devConfData->country, sizeof(devConfData->country), country);
474         OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
475     }
476
477     char *language = NULL;
478     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language))
479     {
480         OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
481         OICStrcpy(devConfData->language, sizeof(devConfData->language), language);
482         OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
483     }
484
485     if(gReadUserdataCb)
486     {
487         gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
488     }
489
490     if(country || language)
491     {
492         OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
493
494         // TODO : Need to check appropriateness of gDevConfData
495         if(gDevConfRsrcEvtCb != NULL)
496         {
497             gDevConfRsrcEvtCb(ES_OK, devConfData);
498         }
499         else
500         {
501             OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
502         }
503     }
504
505     OICFree(devConfData);
506 }
507
508 OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
509 {
510     if(ehRequest &&
511         strcmp(ehRequest->query, "") &&
512         !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
513     {
514         // In case of link list, batch interface
515         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
516         return NULL;
517     }
518
519     OCRepPayload* payload = OCRepPayloadCreate();
520     if (!payload)
521     {
522         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
523         return NULL;
524     }
525
526     OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
527     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_HREF, OC_RSRVD_ES_URI_WIFI);
528
529     size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
530     int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
531     for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
532     {
533         modes_64[i] = gWiFiResource.supportedMode[i];
534     }
535     OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
536
537     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
538     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
539     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
540     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
541     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
542
543     if(gWriteUserdataCb)
544     {
545         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
546     }
547
548     return payload;
549 }
550
551 OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
552 {
553     if(ehRequest &&
554         strcmp(ehRequest->query, "") &&
555         !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
556     {
557         // In case of link list, batch interface
558         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
559         return NULL;
560     }
561
562     OCRepPayload* payload = OCRepPayloadCreate();
563     if (!payload)
564     {
565         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
566         return NULL;
567     }
568
569     OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
570     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_HREF, OC_RSRVD_ES_URI_CLOUDSERVER);
571     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
572     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
573     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
574
575     if(gWriteUserdataCb)
576     {
577         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
578     }
579
580     return payload;
581 }
582
583 OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
584 {
585     if(ehRequest &&
586         strcmp(ehRequest->query, "") &&
587         !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
588     {
589         // In case of link list, batch interface
590         OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
591         return NULL;
592     }
593
594     OCRepPayload* payload = OCRepPayloadCreate();
595     if (!payload)
596     {
597         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
598         return NULL;
599     }
600
601     OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
602     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_HREF, OC_RSRVD_ES_URI_DEVCONF);
603     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
604     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_MODELNUMBER, gDevConfResource.modelNumber);
605     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LOCATION, gDevConfResource.location);
606     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
607     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
608
609     if(gWriteUserdataCb)
610     {
611         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
612     }
613
614     return payload;
615 }
616
617 OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
618 {
619     OCRepPayload* payload = OCRepPayloadCreate();
620     if (!payload)
621     {
622         OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
623         return NULL;
624     }
625
626     // Requested interface is Link list interface
627     if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
628     {
629         const OCRepPayload *arrayPayload[3] = {NULL};
630
631         int childResCnt = 0;
632
633         if(gWiFiResource.handle != NULL)
634         {
635             OCRepPayload *add = OCRepPayloadCreate();
636             if(!add)
637             {
638                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
639                 return NULL;
640             }
641
642             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
643             char **resourceType = NULL;
644             resourceType = (char **)OICMalloc(sizeof(char *) * 1);
645             char **resourceInterface = NULL;
646             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
647
648             if(!resourceType || !resourceInterface)
649             {
650                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
651                 return NULL;
652             }
653
654             resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFI);
655             resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
656
657             add->base.type = PAYLOAD_TYPE_REPRESENTATION;
658             OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFI);
659             OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
660                                             (const char **)resourceType, dimensions);
661             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
662                                             (const char **)resourceInterface, dimensions);
663
664             arrayPayload[childResCnt++] = add;
665         }
666
667         if(gDevConfResource.handle != NULL)
668         {
669             OCRepPayload *add = OCRepPayloadCreate();
670             if(!add)
671             {
672                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
673                 return NULL;
674             }
675
676             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
677             char **resourceType = NULL;
678             resourceType = (char **)OICMalloc(sizeof(char *) * 1);
679             char **resourceInterface = NULL;
680             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
681
682             if(!resourceType || !resourceInterface)
683             {
684                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
685                 return NULL;
686             }
687
688             resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
689             resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
690
691             add->base.type = PAYLOAD_TYPE_REPRESENTATION;
692             OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
693             OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
694                                             (const char **)resourceType, dimensions);
695             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
696                                             (const char **)resourceInterface, dimensions);
697
698             arrayPayload[childResCnt++] = add;
699         }
700
701         if(gCloudResource.handle != NULL)
702         {
703             OCRepPayload *add = OCRepPayloadCreate();
704             if(!add)
705             {
706                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
707                 return NULL;
708             }
709
710             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
711             char **resourceType = NULL;
712             resourceType = (char **)OICMalloc(sizeof(char *) * 1);
713             char **resourceInterface = NULL;
714             resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
715
716             if(!resourceType || !resourceInterface)
717             {
718                 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
719                 return NULL;
720             }
721
722             resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
723             resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
724
725             add->base.type = PAYLOAD_TYPE_REPRESENTATION;
726             OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_CLOUDSERVER);
727             OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
728                                             (const char **)resourceType, dimensions);
729             OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
730                                             (const char **)resourceInterface, dimensions);
731
732             arrayPayload[childResCnt++] = add;
733         }
734
735         size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
736         OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
737
738         return payload;
739     } else if (!ehRequest->query ||
740         (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH)) ||
741         (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
742     {
743         OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
744         OCRepPayloadSetPropString(payload, OC_RSRVD_ES_HREF, OC_RSRVD_ES_URI_PROV);
745         OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
746         OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
747         OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LINKS, gProvResource.ocfWebLinks);
748     }
749
750     if(gWriteUserdataCb)
751     {
752         gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_PROV);
753     }
754
755     if(ehRequest->query)
756     {
757         if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
758         {// When Provisioning resource has a GET with BatchInterface
759             OCRepPayload* head = payload;
760             OCRepPayload* nextPayload = NULL;
761
762             nextPayload = constructResponseOfWiFi(NULL);
763             if(nextPayload != NULL)
764             {
765                 payload->next = nextPayload;
766                 payload = payload->next;
767             }
768
769             nextPayload = constructResponseOfCloud(NULL);
770             if(nextPayload != NULL)
771             {
772                 payload->next = nextPayload;
773                 payload = payload->next;
774             }
775
776             nextPayload = constructResponseOfDevConf(NULL);
777             if(nextPayload != NULL)
778             {
779                 payload->next = nextPayload;
780                 payload = payload->next;
781             }
782
783             payload = head;
784         }
785     }
786
787     return payload;
788 }
789
790
791 OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
792 {
793     OCStackResult res = OC_STACK_ERROR;
794     bool maskFlag = false;
795
796     res = initProvResource(isSecured);
797     if(res != OC_STACK_OK)
798     {
799         // TODO: destroy logic will be added
800         OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
801
802         return res;
803     }
804
805     if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
806     {
807         maskFlag = true;
808         res = initWiFiResource(isSecured);
809         if(res != OC_STACK_OK)
810         {
811             OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
812             return res;
813         }
814
815         res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
816         if(res != OC_STACK_OK)
817         {
818             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
819             return res;
820         }
821
822     }
823
824     if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
825     {
826         maskFlag = true;
827         res = initCloudServerResource(isSecured);
828         if(res != OC_STACK_OK)
829         {
830             OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
831             return res;
832         }
833
834         res = OCBindResource(gProvResource.handle, gCloudResource.handle);
835         if(res != OC_STACK_OK)
836         {
837             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
838             return res;
839         }
840     }
841
842     if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
843     {
844         maskFlag = true;
845         res = initDevConfResource(isSecured);
846         if(res != OC_STACK_OK)
847         {
848             OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
849             return res;
850         }
851
852         res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
853         if(res != OC_STACK_OK)
854         {
855             OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
856             return res;
857         }
858     }
859
860
861     if(maskFlag == false)
862     {
863         OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
864         return OC_STACK_ERROR;
865
866     }
867
868     OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
869
870     return res;
871 }
872
873 OCStackResult DeleteProvisioningResource()
874 {
875     OCStackResult res = OCDeleteResource(gProvResource.handle);
876     if (res != OC_STACK_OK)
877     {
878         OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
879     }
880
881     return res;
882 }
883
884 OCStackResult DeleteEasySetupResources()
885 {
886     OCStackResult res = OC_STACK_ERROR;
887     if (gWiFiResource.handle != NULL)
888     {
889         res = OCUnBindResource(gProvResource.handle, gWiFiResource.handle);
890         if(res != OC_STACK_OK)
891         {
892             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
893         }
894     }
895     if (gCloudResource.handle != NULL)
896     {
897         res = OCUnBindResource(gProvResource.handle, gCloudResource.handle);
898         if(res != OC_STACK_OK)
899         {
900             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
901         }
902     }
903     if (gDevConfResource.handle != NULL)
904     {
905         res = OCUnBindResource(gProvResource.handle, gDevConfResource.handle);
906         if(res != OC_STACK_OK)
907         {
908             OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
909         }
910     }
911
912     if (gWiFiResource.handle != NULL)
913     {
914         res = OCDeleteResource(gWiFiResource.handle);
915         if (res != OC_STACK_OK)
916         {
917             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
918         }
919     }
920
921     if(gCloudResource.handle != NULL)
922     {
923         res = OCDeleteResource(gCloudResource.handle);
924         if (res != OC_STACK_OK)
925         {
926             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
927         }
928     }
929
930     if(gDevConfResource.handle != NULL)
931     {
932         res = OCDeleteResource(gDevConfResource.handle);
933         if (res != OC_STACK_OK)
934         {
935             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
936         }
937     }
938
939     if(gProvResource.handle != NULL)
940     {
941         res = OCDeleteResource(gProvResource.handle);
942         if (res != OC_STACK_OK)
943         {
944             OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
945         }
946     }
947
948     return res;
949 }
950
951 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
952 {
953     OCEntityHandlerResult ehResult = OC_EH_ERROR;
954     if (!ehRequest)
955     {
956         OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
957         return ehResult;
958     }
959     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
960     {
961         OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
962         return ehResult;
963     }
964
965     OCRepPayload *getResp = NULL;
966
967     if(ehRequest->resource == gProvResource.handle)
968     {
969         getResp = constructResponseOfProv(ehRequest);
970     }
971     else if(ehRequest->resource == gWiFiResource.handle)
972     {
973         getResp = constructResponseOfWiFi(ehRequest);
974     }
975     else if(ehRequest->resource == gCloudResource.handle)
976     {
977         getResp = constructResponseOfCloud(ehRequest);
978     }
979     else if(ehRequest->resource == gDevConfResource.handle)
980     {
981         getResp = constructResponseOfDevConf(ehRequest);
982     }
983
984     if (!getResp)
985     {
986         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
987         return OC_EH_ERROR;
988     }
989
990     *payload = getResp;
991     ehResult = OC_EH_OK;
992
993     return ehResult;
994 }
995
996 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
997 {
998     OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
999     OCEntityHandlerResult ehResult = OC_EH_ERROR;
1000     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1001     {
1002         OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1003         return ehResult;
1004     }
1005
1006     OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
1007     if (!input)
1008     {
1009         OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
1010         return ehResult;
1011     }
1012
1013     if(ehRequest->resource == gProvResource.handle)
1014     {
1015         updateProvResource(ehRequest, input);
1016     }
1017     else if(ehRequest->resource == gWiFiResource.handle)
1018     {
1019         updateWiFiResource(ehRequest, input);
1020     }
1021     else if(ehRequest->resource == gCloudResource.handle)
1022     {
1023         updateCloudResource(ehRequest, input);
1024     }
1025     else if(ehRequest->resource == gDevConfResource.handle)
1026     {
1027         updateDevConfResource(ehRequest, input);
1028     }
1029
1030     OCRepPayload *getResp = NULL;
1031     if(ehRequest->resource == gProvResource.handle)
1032     {
1033         getResp = constructResponseOfProv(ehRequest);
1034     }
1035     else if(ehRequest->resource == gWiFiResource.handle)
1036     {
1037         getResp = constructResponseOfWiFi(NULL);
1038     }
1039     else if(ehRequest->resource == gCloudResource.handle)
1040     {
1041         getResp = constructResponseOfCloud(NULL);
1042     }
1043     else if(ehRequest->resource == gDevConfResource.handle)
1044     {
1045         getResp = constructResponseOfDevConf(NULL);
1046     }
1047
1048     if (!getResp)
1049     {
1050         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1051         return OC_EH_ERROR;
1052     }
1053
1054     *payload = getResp;
1055     ehResult = OC_EH_OK;
1056
1057     return ehResult;
1058 }
1059
1060 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
1061         OCRepPayload** payload)
1062 {
1063     (void) ehRequest;
1064     (void) payload;
1065     OCEntityHandlerResult ehResult = OC_EH_METHOD_NOT_ALLOWED;
1066
1067     return ehResult;
1068 }
1069 /**
1070  * This is the entity handler for the registered resource.
1071  * This is invoked by OCStack whenever it recevies a request for this resource.
1072  */
1073 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
1074         OCEntityHandlerRequest* entityHandlerRequest, void *callback)
1075 {
1076     (void) callback;
1077     OCEntityHandlerResult ehRet = OC_EH_OK;
1078     OCEntityHandlerResponse response =
1079     { 0, 0, OC_EH_ERROR, 0, 0,
1080     { },
1081     { 0 }, false };
1082     OCRepPayload* payload = NULL;
1083
1084     if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
1085     {
1086         if (OC_REST_GET == entityHandlerRequest->method)
1087         {
1088             OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
1089             ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
1090         }
1091         else if (OC_REST_PUT == entityHandlerRequest->method)
1092         {
1093             OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
1094
1095             //PUT request will be handled in the internal implementation
1096             if (gProvResource.handle != NULL)
1097             {
1098                 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
1099             }
1100             else
1101             {
1102                 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1103                 ehRet = OC_EH_ERROR;
1104             }
1105         }
1106         else if (OC_REST_POST == entityHandlerRequest->method)
1107         {
1108             OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
1109             if (gProvResource.handle != NULL)
1110             {
1111                 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
1112             }
1113             else
1114             {
1115                 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1116                 ehRet = OC_EH_ERROR;
1117             }
1118         }
1119
1120         // Format the response.  Note this requires some info about the request
1121         response.requestHandle = entityHandlerRequest->requestHandle;
1122         response.resourceHandle = entityHandlerRequest->resource;
1123         response.ehResult = ehRet;
1124         //response uses OCPaylod while all get,put methodes use OCRepPayload
1125         response.payload = (OCPayload*) (payload);
1126         response.numSendVendorSpecificHeaderOptions = 0;
1127         memset(response.sendVendorSpecificHeaderOptions, 0,
1128                 sizeof(response.sendVendorSpecificHeaderOptions));
1129         memset(response.resourceUri, 0, sizeof(response.resourceUri));
1130         // Indicate that response is NOT in a persistent buffer
1131         response.persistentBufferFlag = 0;
1132
1133         // Send the response
1134         if (OCDoResponse(&response) != OC_STACK_OK)
1135         {
1136             OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
1137             ehRet = OC_EH_ERROR;
1138         }
1139     }
1140
1141     return ehRet;
1142 }
1143
1144 OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
1145 {
1146     OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty IN");
1147
1148     gWiFiResource.supportedFreq = (deviceProperty->WiFi).freq;
1149     OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Freq : %d", gWiFiResource.supportedFreq);
1150
1151     int modeIdx = 0;
1152     while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
1153     {
1154         gWiFiResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
1155         OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Mode : %d", gWiFiResource.supportedMode[modeIdx]);
1156         modeIdx ++;
1157     }
1158     gWiFiResource.numMode = modeIdx;
1159
1160     OICStrcpy(gDevConfResource.devName, OIC_STRING_MAX_VALUE, (deviceProperty->DevConf).deviceName);
1161     OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
1162
1163     OICStrcpy(gDevConfResource.modelNumber, OIC_STRING_MAX_VALUE,
1164                                                             (deviceProperty->DevConf).modelNumber);
1165     OIC_LOG_V(INFO, ES_RH_TAG, "Model Number : %s", gDevConfResource.modelNumber);
1166
1167     OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
1168     return OC_STACK_OK;
1169 }
1170
1171 OCStackResult SetEnrolleeState(ESEnrolleeState esState)
1172 {
1173     OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState IN");
1174
1175     gProvResource.status = esState;
1176     OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee Status : %d", gProvResource.status);
1177
1178     OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState OUT");
1179     return OC_STACK_OK;
1180 }
1181
1182 OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
1183 {
1184     OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode IN");
1185
1186     gProvResource.lastErrCode = esErrCode;
1187     OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee ErrorCode : %d", gProvResource.lastErrCode);
1188
1189     OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
1190     return OC_STACK_OK;
1191 }
1192
1193 const char *getResult(OCStackResult result)
1194 {
1195     switch (result)
1196     {
1197         case OC_STACK_OK:
1198             return "OC_STACK_OK";
1199         case OC_STACK_INVALID_URI:
1200             return "OC_STACK_INVALID_URI";
1201         case OC_STACK_INVALID_QUERY:
1202             return "OC_STACK_INVALID_QUERY";
1203         case OC_STACK_INVALID_IP:
1204             return "OC_STACK_INVALID_IP";
1205         case OC_STACK_INVALID_PORT:
1206             return "OC_STACK_INVALID_PORT";
1207         case OC_STACK_INVALID_CALLBACK:
1208             return "OC_STACK_INVALID_CALLBACK";
1209         case OC_STACK_INVALID_METHOD:
1210             return "OC_STACK_INVALID_METHOD";
1211         case OC_STACK_NO_MEMORY:
1212             return "OC_STACK_NO_MEMORY";
1213         case OC_STACK_COMM_ERROR:
1214             return "OC_STACK_COMM_ERROR";
1215         case OC_STACK_INVALID_PARAM:
1216             return "OC_STACK_INVALID_PARAM";
1217         case OC_STACK_NOTIMPL:
1218             return "OC_STACK_NOTIMPL";
1219         case OC_STACK_NO_RESOURCE:
1220             return "OC_STACK_NO_RESOURCE";
1221         case OC_STACK_RESOURCE_ERROR:
1222             return "OC_STACK_RESOURCE_ERROR";
1223         case OC_STACK_SLOW_RESOURCE:
1224             return "OC_STACK_SLOW_RESOURCE";
1225         case OC_STACK_NO_OBSERVERS:
1226             return "OC_STACK_NO_OBSERVERS";
1227         case OC_STACK_ERROR:
1228             return "OC_STACK_ERROR";
1229         default:
1230             return "UNKNOWN";
1231     }
1232 }