1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "resourcehandler.h"
23 #include "ocpayload.h"
24 #include "oic_string.h"
25 #include "oic_malloc.h"
29 * @brief Logging tag for module name.
31 #define ES_RH_TAG "ES_RH"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
38 * @brief Structure for holding the Provisioning status and target information required to
39 * connect to the target network
41 static ProvResource gProvResource;
42 static WiFiResource gWiFiResource;
43 static CloudResource gCloudResource;
44 static DevConfResource gDevConfResource;
46 //-----------------------------------------------------------------------------
47 // Private internal function prototypes
48 //-----------------------------------------------------------------------------
49 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
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(OCRepPayload* input);
56 void updateCloudResource(OCRepPayload* input);
57 void updateDevConfResource(OCRepPayload* input);
58 const char *getResult(OCStackResult result);
60 ESWiFiCB gWifiRsrcEvtCb = NULL;
61 ESCloudCB gCloudRsrcEvtCb = NULL;
62 ESDevConfCB gDevConfRsrcEvtCb = NULL;
64 ESReadUserdataCb gReadUserdataCb = NULL;
65 ESWriteUserdataCb gWriteUserdataCb = NULL;
67 bool CompareResourceInterface(char *from, char *iface)
69 char *str = OICStrdup(from);
70 char *ptr = strtok(str, ";");
79 if(strstr(ptr, ".if."))
82 if_ptr = strtok(ptr, "=");
83 if_ptr = strtok(NULL, "=");
85 if(!strcmp(if_ptr, iface))
91 } while ((ptr = strtok(NULL, ";")));
96 ESResult SetCallbackForUserData(ESReadUserdataCb readCb, ESWriteUserdataCb writeCb)
98 if(!readCb && !writeCb)
100 OIC_LOG(INFO, ES_RH_TAG, "Both of callbacks for user data are null");
103 gReadUserdataCb = readCb;
104 gWriteUserdataCb = writeCb;
108 void RegisterWifiRsrcEventCallBack(ESWiFiCB cb)
113 void RegisterCloudRsrcEventCallBack(ESCloudCB cb)
115 gCloudRsrcEvtCb = cb;
118 void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
120 gDevConfRsrcEvtCb = cb;
123 void UnRegisterResourceEventCallBack()
127 gWifiRsrcEvtCb = NULL;
131 gCloudRsrcEvtCb = NULL;
133 if (gDevConfRsrcEvtCb)
135 gDevConfRsrcEvtCb = NULL;
139 OCStackResult initProvResource(bool isSecured)
141 gProvResource.status = ES_STATE_INIT;
142 gProvResource.lastErrCode = ES_ERRCODE_NO_ERROR;
143 OICStrcpy(gProvResource.ocfWebLinks, MAX_WEBLINKLEN, "");
145 OCStackResult res = OC_STACK_ERROR;
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);
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);
161 OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
165 res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_LL);
168 OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
171 res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
174 OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
178 OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
182 OCStackResult initWiFiResource(bool isSecured)
184 OCStackResult res = OC_STACK_ERROR;
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), "");
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);
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);
211 OIC_LOG_V(INFO, ES_RH_TAG, "Created WiFi resource with result: %s", getResult(res));
216 OCStackResult initCloudServerResource(bool isSecured)
218 OCStackResult res = OC_STACK_ERROR;
220 OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), "");
221 OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), "");
222 OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), "");
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);
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);
238 OIC_LOG_V(INFO, ES_RH_TAG, "Created CloudServer resource with result: %s", getResult(res));
243 OCStackResult initDevConfResource(bool isSecured)
245 OCStackResult res = OC_STACK_ERROR;
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), "");
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);
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);
267 OIC_LOG_V(INFO, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
272 void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
274 OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %d", gProvResource.status);
278 if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
280 // When Provisioning resource has a POST with BatchInterface
281 updateCloudResource(input);
282 updateWiFiResource(input);
283 updateDevConfResource(input);
288 void updateWiFiResource(OCRepPayload* input)
290 ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
294 OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
298 memset(wiFiData->ssid, 0, MAX_WEBLINKLEN);
299 memset(wiFiData->pwd, 0, MAX_WEBLINKLEN);
300 wiFiData->authtype = NONE_AUTH;
301 wiFiData->enctype = NONE_AUTH;
302 wiFiData->userdata = NULL;
305 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
307 OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
308 OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
309 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.ssid : %s", gWiFiResource.ssid);
313 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
315 OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
316 OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
317 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
320 int64_t authType = -1;
321 if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
323 gWiFiResource.authType = authType;
324 wiFiData->authtype = gWiFiResource.authType;
325 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
328 int64_t encType = -1;
329 if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
331 gWiFiResource.encType = encType;
332 wiFiData->enctype = gWiFiResource.encType;
333 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
338 gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFI, &wiFiData->userdata);
341 if(ssid || cred || authType!= -1 || encType != -1)
343 OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");
345 // TODO : Need to check appropriateness of gWiFiData
346 if(gWifiRsrcEvtCb != NULL)
348 gWifiRsrcEvtCb(ES_OK, wiFiData);
352 OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
356 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gWiFiResource.handle, OC_HIGH_QOS))
358 OIC_LOG(INFO, ES_RH_TAG, "Enrollee doesn't have any observers.");
364 void updateCloudResource(OCRepPayload* input)
366 ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
368 if(cloudData == NULL)
370 OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
374 memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
375 memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
376 memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
377 cloudData->userdata = NULL;
379 char *authCode = NULL;
380 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
382 OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
383 OICStrcpy(cloudData->authCode, sizeof(cloudData->authCode), authCode);
384 OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
387 char *authProvider = NULL;
388 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
390 OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
391 OICStrcpy(cloudData->authProvider, sizeof(cloudData->authProvider), authProvider);
392 OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
395 char *ciServer = NULL;
396 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
398 OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
399 OICStrcpy(cloudData->ciServer, sizeof(cloudData->ciServer), ciServer);
400 OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
405 gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER, &cloudData->userdata);
408 if(authCode || authProvider || ciServer)
410 OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");
412 // TODO : Need to check appropriateness of gCloudData
413 if(gCloudRsrcEvtCb != NULL)
415 gCloudRsrcEvtCb(ES_OK, cloudData);
419 OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
423 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gCloudResource.handle, OC_HIGH_QOS))
425 OIC_LOG(INFO, ES_RH_TAG, "cloudResource doesn't have any observers.");
431 void updateDevConfResource(OCRepPayload* input)
433 ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
435 if(devConfData == NULL)
437 OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
440 memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
441 memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
442 devConfData->userdata = NULL;
444 char *location = NULL;
445 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LOCATION, &location))
447 OICStrcpy(gDevConfResource.location, sizeof(gDevConfResource.location), location);
448 OICStrcpy(devConfData->location, sizeof(devConfData->location), location);
449 OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.location %s", gDevConfResource.location);
452 char *country = NULL;
453 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country))
455 OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
456 OICStrcpy(devConfData->country, sizeof(devConfData->country), country);
457 OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
460 char *language = NULL;
461 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language))
463 OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
464 OICStrcpy(devConfData->language, sizeof(devConfData->language), language);
465 OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
470 gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
473 if(country || language)
475 OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
477 // TODO : Need to check appropriateness of gDevConfData
478 if(gDevConfRsrcEvtCb != NULL)
480 gDevConfRsrcEvtCb(ES_OK, devConfData);
484 OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
488 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gDevConfResource.handle, OC_HIGH_QOS))
490 OIC_LOG(INFO, ES_RH_TAG, "devConfResource doesn't have any observers.");
493 OICFree(devConfData);
496 OCRepPayload* constructResponseOfWiFi()
498 OCRepPayload* payload = OCRepPayloadCreate();
501 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
505 if(gWiFiResource.handle == NULL)
507 OIC_LOG(ERROR, ES_RH_TAG, "WiFi resource is not created");
511 OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
512 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
513 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
514 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
516 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
517 int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
518 for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
520 modes_64[i] = gWiFiResource.supportedMode[i];
522 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
524 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
525 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
526 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
527 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
528 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
532 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
538 OCRepPayload* constructResponseOfCloud()
540 OCRepPayload* payload = OCRepPayloadCreate();
543 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
547 if(gCloudResource.handle == NULL)
549 OIC_LOG(ERROR, ES_RH_TAG, "CloudServer resource is not created");
553 OIC_LOG(INFO, ES_RH_TAG, "constructResponse cloudserver res");
554 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
555 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
556 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
558 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
559 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
560 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
564 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
570 OCRepPayload* constructResponseOfDevConf()
572 OCRepPayload* payload = OCRepPayloadCreate();
575 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
579 if(gDevConfResource.handle == NULL)
581 OIC_LOG(ERROR, ES_RH_TAG, "DevConf resource is not created");
585 OIC_LOG(INFO, ES_RH_TAG, "constructResponse devconf res");
586 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
587 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
588 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
590 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
591 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_MODELNUMBER, gDevConfResource.modelNumber);
592 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LOCATION, gDevConfResource.location);
593 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
594 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
598 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
604 OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
606 OCRepPayload* payload = OCRepPayloadCreate();
609 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
613 // Requested interface is Link list interface
614 //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
615 if(!ehRequest->query ||
616 (ehRequest->query && !strcmp(ehRequest->query, "")) ||
617 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
618 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
620 const OCRepPayload *arrayPayload[3] = {NULL};
624 if(gWiFiResource.handle != NULL)
626 OCRepPayload *add = OCRepPayloadCreate();
629 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
633 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
634 char **resourceType = NULL;
635 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
636 char **resourceInterface = NULL;
637 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
639 if(!resourceType || !resourceInterface)
641 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
645 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFI);
646 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
648 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
649 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFI);
650 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
651 (const char **)resourceType, dimensions);
652 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
653 (const char **)resourceInterface, dimensions);
655 arrayPayload[childResCnt++] = add;
658 if(gDevConfResource.handle != NULL)
660 OCRepPayload *add = OCRepPayloadCreate();
663 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
667 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
668 char **resourceType = NULL;
669 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
670 char **resourceInterface = NULL;
671 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
673 if(!resourceType || !resourceInterface)
675 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
679 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
680 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
682 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
683 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
684 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
685 (const char **)resourceType, dimensions);
686 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
687 (const char **)resourceInterface, dimensions);
689 arrayPayload[childResCnt++] = add;
692 if(gCloudResource.handle != NULL)
694 OCRepPayload *add = OCRepPayloadCreate();
697 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
701 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
702 char **resourceType = NULL;
703 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
704 char **resourceInterface = NULL;
705 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
707 if(!resourceType || !resourceInterface)
709 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
713 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
714 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
716 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
717 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_CLOUDSERVER);
718 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
719 (const char **)resourceType, dimensions);
720 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
721 (const char **)resourceInterface, dimensions);
723 arrayPayload[childResCnt++] = add;
726 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
728 if(!ehRequest->query ||
729 (ehRequest->query && !strcmp(ehRequest->query, "")) ||
730 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
732 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
733 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
734 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
735 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
736 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
737 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_PROV);
739 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
740 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
742 OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
744 else // link list interface
746 OCRepPayload* head = payload;
747 OCRepPayload* nextPayload = NULL;
749 for(int i = 0 ; i < childResCnt ; ++i)
751 nextPayload = arrayPayload[i];
752 if(nextPayload != NULL)
754 payload->next = nextPayload;
755 payload = payload->next;
758 if(head->next != NULL)
760 payload = head->next;
768 ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
771 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
772 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
773 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
774 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
775 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
776 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_PROV);
778 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
779 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
784 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_PROV);
789 if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
790 {// When Provisioning resource has a GET with BatchInterface
791 OCRepPayload* head = payload;
792 OCRepPayload* nextPayload = NULL;
794 nextPayload = constructResponseOfWiFi();
795 if(nextPayload != NULL)
797 payload->next = nextPayload;
798 payload = payload->next;
801 nextPayload = constructResponseOfCloud();
802 if(nextPayload != NULL)
804 payload->next = nextPayload;
805 payload = payload->next;
808 nextPayload = constructResponseOfDevConf();
809 if(nextPayload != NULL)
811 payload->next = nextPayload;
812 payload = payload->next;
823 OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
825 OCStackResult res = OC_STACK_ERROR;
826 bool maskFlag = false;
828 res = initProvResource(isSecured);
829 if(res != OC_STACK_OK)
831 // TODO: destroy logic will be added
832 OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
837 if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
840 res = initWiFiResource(isSecured);
841 if(res != OC_STACK_OK)
843 OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
847 res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
848 if(res != OC_STACK_OK)
850 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
856 if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
859 res = initCloudServerResource(isSecured);
860 if(res != OC_STACK_OK)
862 OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
866 res = OCBindResource(gProvResource.handle, gCloudResource.handle);
867 if(res != OC_STACK_OK)
869 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
874 if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
877 res = initDevConfResource(isSecured);
878 if(res != OC_STACK_OK)
880 OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
884 res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
885 if(res != OC_STACK_OK)
887 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
893 if(maskFlag == false)
895 OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
896 return OC_STACK_ERROR;
900 OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
905 OCStackResult DeleteProvisioningResource()
907 OCStackResult res = OCDeleteResource(gProvResource.handle);
908 if (res != OC_STACK_OK)
910 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
916 OCStackResult DeleteEasySetupResources()
918 OCStackResult res = OC_STACK_ERROR;
919 if (gWiFiResource.handle != NULL)
921 res = OCUnBindResource(gProvResource.handle, gWiFiResource.handle);
922 if(res != OC_STACK_OK)
924 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
927 if (gCloudResource.handle != NULL)
929 res = OCUnBindResource(gProvResource.handle, gCloudResource.handle);
930 if(res != OC_STACK_OK)
932 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
935 if (gDevConfResource.handle != NULL)
937 res = OCUnBindResource(gProvResource.handle, gDevConfResource.handle);
938 if(res != OC_STACK_OK)
940 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
944 if (gWiFiResource.handle != NULL)
946 res = OCDeleteResource(gWiFiResource.handle);
947 if (res != OC_STACK_OK)
949 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
953 if(gCloudResource.handle != NULL)
955 res = OCDeleteResource(gCloudResource.handle);
956 if (res != OC_STACK_OK)
958 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
962 if(gDevConfResource.handle != NULL)
964 res = OCDeleteResource(gDevConfResource.handle);
965 if (res != OC_STACK_OK)
967 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
971 if(gProvResource.handle != NULL)
973 res = OCDeleteResource(gProvResource.handle);
974 if (res != OC_STACK_OK)
976 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
983 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
985 OCEntityHandlerResult ehResult = OC_EH_ERROR;
988 OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
991 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
993 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
997 OCRepPayload *getResp = NULL;
1000 if(ehRequest->resource == gProvResource.handle)
1002 if(ehRequest->query &&
1003 strcmp(ehRequest->query, "") &&
1004 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) &&
1005 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1006 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1008 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1009 return OC_EH_BAD_REQ;
1013 getResp = constructResponseOfProv(ehRequest);
1016 else if(ehRequest->resource == gWiFiResource.handle)
1018 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1020 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1021 return OC_EH_BAD_REQ;
1025 getResp = constructResponseOfWiFi();
1028 else if(ehRequest->resource == gCloudResource.handle)
1030 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1032 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1033 return OC_EH_BAD_REQ;
1037 getResp = constructResponseOfCloud();
1040 else if(ehRequest->resource == gDevConfResource.handle)
1042 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1044 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1045 return OC_EH_BAD_REQ;
1049 getResp = constructResponseOfDevConf();
1055 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1060 ehResult = OC_EH_OK;
1065 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
1067 OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
1068 OCEntityHandlerResult ehResult = OC_EH_ERROR;
1069 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1071 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1075 OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
1078 OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
1082 if(ehRequest->resource == gProvResource.handle)
1084 if(ehRequest->query &&
1085 strcmp(ehRequest->query, "") &&
1086 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1087 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1089 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1090 return OC_EH_BAD_REQ;
1094 updateProvResource(ehRequest, input);
1097 else if(ehRequest->resource == gWiFiResource.handle)
1099 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1101 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1102 return OC_EH_BAD_REQ;
1106 updateWiFiResource(input);
1109 else if(ehRequest->resource == gCloudResource.handle)
1111 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1113 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1114 return OC_EH_BAD_REQ;
1118 updateCloudResource(input);
1121 else if(ehRequest->resource == gDevConfResource.handle)
1123 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1125 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1126 return OC_EH_BAD_REQ;
1130 updateDevConfResource(input);
1134 OCRepPayload *getResp = NULL;
1135 if(ehRequest->resource == gProvResource.handle)
1137 getResp = constructResponseOfProv(ehRequest);
1139 else if(ehRequest->resource == gWiFiResource.handle)
1141 getResp = constructResponseOfWiFi();
1143 else if(ehRequest->resource == gCloudResource.handle)
1145 getResp = constructResponseOfCloud();
1147 else if(ehRequest->resource == gDevConfResource.handle)
1149 getResp = constructResponseOfDevConf();
1154 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1159 ehResult = OC_EH_OK;
1164 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
1165 OCRepPayload** payload)
1169 OCEntityHandlerResult ehResult = OC_EH_BAD_REQ;
1174 * This is the entity handler for the registered resource.
1175 * This is invoked by OCStack whenever it recevies a request for this resource.
1177 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
1178 OCEntityHandlerRequest* entityHandlerRequest, void *callback)
1181 OCEntityHandlerResult ehRet = OC_EH_OK;
1182 OCEntityHandlerResponse response =
1183 { 0, 0, OC_EH_ERROR, 0, 0,
1186 OCRepPayload* payload = NULL;
1188 if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
1190 if (OC_REST_GET == entityHandlerRequest->method)
1192 OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
1193 ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
1195 else if (OC_REST_PUT == entityHandlerRequest->method)
1197 OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
1199 //PUT request will be handled in the internal implementation
1200 if (gProvResource.handle != NULL)
1202 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
1206 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1207 ehRet = OC_EH_ERROR;
1210 else if (OC_REST_POST == entityHandlerRequest->method)
1212 OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
1213 if (gProvResource.handle != NULL)
1215 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
1219 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1220 ehRet = OC_EH_ERROR;
1224 // Format the response. Note this requires some info about the request
1225 response.requestHandle = entityHandlerRequest->requestHandle;
1226 response.resourceHandle = entityHandlerRequest->resource;
1227 response.ehResult = ehRet;
1228 //response uses OCPaylod while all get,put methodes use OCRepPayload
1229 response.payload = (OCPayload*) (payload);
1230 response.numSendVendorSpecificHeaderOptions = 0;
1231 memset(response.sendVendorSpecificHeaderOptions, 0,
1232 sizeof(response.sendVendorSpecificHeaderOptions));
1233 memset(response.resourceUri, 0, sizeof(response.resourceUri));
1234 // Indicate that response is NOT in a persistent buffer
1235 response.persistentBufferFlag = 0;
1237 // Send the response
1238 if (OCDoResponse(&response) != OC_STACK_OK)
1240 OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
1241 ehRet = OC_EH_ERROR;
1244 if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG))
1246 OIC_LOG(INFO, ES_RH_TAG, "Flag includes OC_OBSERVE_FLAG");
1248 if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action)
1250 OIC_LOG (INFO, ES_RH_TAG, "Received OC_OBSERVE_REGISTER from Mediator");
1252 else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action)
1254 OIC_LOG (INFO, ES_RH_TAG, "Received OC_OBSERVE_DEREGISTER from Mediator");
1260 OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
1262 OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty IN");
1264 gWiFiResource.supportedFreq = (deviceProperty->WiFi).freq;
1265 OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Freq : %d", gWiFiResource.supportedFreq);
1268 while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
1270 gWiFiResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
1271 OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Mode : %d", gWiFiResource.supportedMode[modeIdx]);
1274 gWiFiResource.numMode = modeIdx;
1276 OICStrcpy(gDevConfResource.devName, OIC_STRING_MAX_VALUE, (deviceProperty->DevConf).deviceName);
1277 OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
1279 OICStrcpy(gDevConfResource.modelNumber, OIC_STRING_MAX_VALUE,
1280 (deviceProperty->DevConf).modelNumber);
1281 OIC_LOG_V(INFO, ES_RH_TAG, "Model Number : %s", gDevConfResource.modelNumber);
1283 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gWiFiResource.handle, OC_HIGH_QOS))
1285 OIC_LOG(INFO, ES_RH_TAG, "wifiResource doesn't have any observers.");
1288 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gDevConfResource.handle, OC_HIGH_QOS))
1290 OIC_LOG(INFO, ES_RH_TAG, "devConfResource doesn't have any observers.");
1293 OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
1297 OCStackResult SetEnrolleeState(ESEnrolleeState esState)
1299 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState IN");
1301 gProvResource.status = esState;
1302 OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee Status : %d", gProvResource.status);
1304 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gProvResource.handle, OC_HIGH_QOS))
1306 OIC_LOG(INFO, ES_RH_TAG, "provResource doesn't have any observers.");
1309 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState OUT");
1313 OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
1315 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode IN");
1317 gProvResource.lastErrCode = esErrCode;
1318 OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee ErrorCode : %d", gProvResource.lastErrCode);
1320 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gProvResource.handle, OC_HIGH_QOS))
1322 OIC_LOG(INFO, ES_RH_TAG, "provResource doesn't have any observers.");
1325 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
1329 OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
1331 if( !(ehRequest->query) ||
1332 (ehRequest->query &&
1333 (strcmp(ehRequest->query, "") && !CompareResourceInterface(ehRequest->query,
1334 OC_RSRVD_INTERFACE_DEFAULT))))
1336 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1337 return OC_EH_BAD_REQ;
1342 const char *getResult(OCStackResult result)
1347 return "OC_STACK_OK";
1348 case OC_STACK_INVALID_URI:
1349 return "OC_STACK_INVALID_URI";
1350 case OC_STACK_INVALID_QUERY:
1351 return "OC_STACK_INVALID_QUERY";
1352 case OC_STACK_INVALID_IP:
1353 return "OC_STACK_INVALID_IP";
1354 case OC_STACK_INVALID_PORT:
1355 return "OC_STACK_INVALID_PORT";
1356 case OC_STACK_INVALID_CALLBACK:
1357 return "OC_STACK_INVALID_CALLBACK";
1358 case OC_STACK_INVALID_METHOD:
1359 return "OC_STACK_INVALID_METHOD";
1360 case OC_STACK_NO_MEMORY:
1361 return "OC_STACK_NO_MEMORY";
1362 case OC_STACK_COMM_ERROR:
1363 return "OC_STACK_COMM_ERROR";
1364 case OC_STACK_INVALID_PARAM:
1365 return "OC_STACK_INVALID_PARAM";
1366 case OC_STACK_NOTIMPL:
1367 return "OC_STACK_NOTIMPL";
1368 case OC_STACK_NO_RESOURCE:
1369 return "OC_STACK_NO_RESOURCE";
1370 case OC_STACK_RESOURCE_ERROR:
1371 return "OC_STACK_RESOURCE_ERROR";
1372 case OC_STACK_SLOW_RESOURCE:
1373 return "OC_STACK_SLOW_RESOURCE";
1374 case OC_STACK_NO_OBSERVERS:
1375 return "OC_STACK_NO_OBSERVERS";
1376 case OC_STACK_ERROR:
1377 return "OC_STACK_ERROR";