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 OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
506 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
507 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
508 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
510 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
511 int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
512 for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
514 modes_64[i] = gWiFiResource.supportedMode[i];
516 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
518 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
519 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
520 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
521 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
522 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
526 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
532 OCRepPayload* constructResponseOfCloud()
534 OCRepPayload* payload = OCRepPayloadCreate();
537 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
541 OIC_LOG(INFO, ES_RH_TAG, "constructResponse cloudserver res");
542 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
543 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
544 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
546 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
547 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
548 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
552 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
558 OCRepPayload* constructResponseOfDevConf()
560 OCRepPayload* payload = OCRepPayloadCreate();
563 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
567 OIC_LOG(INFO, ES_RH_TAG, "constructResponse devconf res");
568 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
569 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
570 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
572 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
573 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_MODELNUMBER, gDevConfResource.modelNumber);
574 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LOCATION, gDevConfResource.location);
575 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
576 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
580 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
586 OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
588 OCRepPayload* payload = OCRepPayloadCreate();
591 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
595 // Requested interface is Link list interface
596 //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
597 if(!ehRequest->query ||
598 (ehRequest->query && !strcmp(ehRequest->query, "")) ||
599 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
600 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
602 const OCRepPayload *arrayPayload[3] = {NULL};
606 if(gWiFiResource.handle != NULL)
608 OCRepPayload *add = OCRepPayloadCreate();
611 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
615 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
616 char **resourceType = NULL;
617 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
618 char **resourceInterface = NULL;
619 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
621 if(!resourceType || !resourceInterface)
623 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
627 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFI);
628 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
630 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
631 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFI);
632 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
633 (const char **)resourceType, dimensions);
634 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
635 (const char **)resourceInterface, dimensions);
637 arrayPayload[childResCnt++] = add;
640 if(gDevConfResource.handle != NULL)
642 OCRepPayload *add = OCRepPayloadCreate();
645 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
649 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
650 char **resourceType = NULL;
651 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
652 char **resourceInterface = NULL;
653 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
655 if(!resourceType || !resourceInterface)
657 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
661 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
662 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
664 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
665 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
666 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
667 (const char **)resourceType, dimensions);
668 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
669 (const char **)resourceInterface, dimensions);
671 arrayPayload[childResCnt++] = add;
674 if(gCloudResource.handle != NULL)
676 OCRepPayload *add = OCRepPayloadCreate();
679 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
683 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
684 char **resourceType = NULL;
685 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
686 char **resourceInterface = NULL;
687 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
689 if(!resourceType || !resourceInterface)
691 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
695 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
696 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
698 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
699 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_CLOUDSERVER);
700 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
701 (const char **)resourceType, dimensions);
702 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
703 (const char **)resourceInterface, dimensions);
705 arrayPayload[childResCnt++] = add;
708 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
710 if(!ehRequest->query ||
711 (ehRequest->query && !strcmp(ehRequest->query, "")) ||
712 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
714 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
715 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
716 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
717 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
718 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
719 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_PROV);
721 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
722 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
724 OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
726 else // link list interface
728 OCRepPayload* head = payload;
729 OCRepPayload* nextPayload = NULL;
731 for(int i = 0 ; i < childResCnt ; ++i)
733 nextPayload = arrayPayload[i];
734 if(nextPayload != NULL)
736 payload->next = nextPayload;
737 payload = payload->next;
740 if(head->next != NULL)
742 payload = head->next;
750 ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
753 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
754 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
755 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
756 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
757 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
758 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_PROV);
760 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
761 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
766 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_PROV);
771 if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
772 {// When Provisioning resource has a GET with BatchInterface
773 OCRepPayload* head = payload;
774 OCRepPayload* nextPayload = NULL;
776 nextPayload = constructResponseOfWiFi();
777 if(nextPayload != NULL)
779 payload->next = nextPayload;
780 payload = payload->next;
783 nextPayload = constructResponseOfCloud();
784 if(nextPayload != NULL)
786 payload->next = nextPayload;
787 payload = payload->next;
790 nextPayload = constructResponseOfDevConf();
791 if(nextPayload != NULL)
793 payload->next = nextPayload;
794 payload = payload->next;
805 OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
807 OCStackResult res = OC_STACK_ERROR;
808 bool maskFlag = false;
810 res = initProvResource(isSecured);
811 if(res != OC_STACK_OK)
813 // TODO: destroy logic will be added
814 OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
819 if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
822 res = initWiFiResource(isSecured);
823 if(res != OC_STACK_OK)
825 OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
829 res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
830 if(res != OC_STACK_OK)
832 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
838 if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
841 res = initCloudServerResource(isSecured);
842 if(res != OC_STACK_OK)
844 OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
848 res = OCBindResource(gProvResource.handle, gCloudResource.handle);
849 if(res != OC_STACK_OK)
851 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
856 if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
859 res = initDevConfResource(isSecured);
860 if(res != OC_STACK_OK)
862 OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
866 res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
867 if(res != OC_STACK_OK)
869 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
875 if(maskFlag == false)
877 OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
878 return OC_STACK_ERROR;
882 OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
887 OCStackResult DeleteProvisioningResource()
889 OCStackResult res = OCDeleteResource(gProvResource.handle);
890 if (res != OC_STACK_OK)
892 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
898 OCStackResult DeleteEasySetupResources()
900 OCStackResult res = OC_STACK_ERROR;
901 if (gWiFiResource.handle != NULL)
903 res = OCUnBindResource(gProvResource.handle, gWiFiResource.handle);
904 if(res != OC_STACK_OK)
906 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
909 if (gCloudResource.handle != NULL)
911 res = OCUnBindResource(gProvResource.handle, gCloudResource.handle);
912 if(res != OC_STACK_OK)
914 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
917 if (gDevConfResource.handle != NULL)
919 res = OCUnBindResource(gProvResource.handle, gDevConfResource.handle);
920 if(res != OC_STACK_OK)
922 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
926 if (gWiFiResource.handle != NULL)
928 res = OCDeleteResource(gWiFiResource.handle);
929 if (res != OC_STACK_OK)
931 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
935 if(gCloudResource.handle != NULL)
937 res = OCDeleteResource(gCloudResource.handle);
938 if (res != OC_STACK_OK)
940 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
944 if(gDevConfResource.handle != NULL)
946 res = OCDeleteResource(gDevConfResource.handle);
947 if (res != OC_STACK_OK)
949 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
953 if(gProvResource.handle != NULL)
955 res = OCDeleteResource(gProvResource.handle);
956 if (res != OC_STACK_OK)
958 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
965 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
967 OCEntityHandlerResult ehResult = OC_EH_ERROR;
970 OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
973 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
975 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
979 OCRepPayload *getResp = NULL;
982 if(ehRequest->resource == gProvResource.handle)
984 if(ehRequest->query &&
985 strcmp(ehRequest->query, "") &&
986 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) &&
987 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
988 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
990 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
991 return OC_EH_BAD_REQ;
995 getResp = constructResponseOfProv(ehRequest);
998 else if(ehRequest->resource == gWiFiResource.handle)
1000 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1002 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1003 return OC_EH_BAD_REQ;
1007 getResp = constructResponseOfWiFi();
1010 else if(ehRequest->resource == gCloudResource.handle)
1012 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1014 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1015 return OC_EH_BAD_REQ;
1019 getResp = constructResponseOfCloud();
1022 else if(ehRequest->resource == gDevConfResource.handle)
1024 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1026 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1027 return OC_EH_BAD_REQ;
1031 getResp = constructResponseOfDevConf();
1037 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1042 ehResult = OC_EH_OK;
1047 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
1049 OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
1050 OCEntityHandlerResult ehResult = OC_EH_ERROR;
1051 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1053 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1057 OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
1060 OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
1064 if(ehRequest->resource == gProvResource.handle)
1066 if(ehRequest->query &&
1067 strcmp(ehRequest->query, "") &&
1068 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1069 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1071 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1072 return OC_EH_BAD_REQ;
1076 updateProvResource(ehRequest, input);
1079 else if(ehRequest->resource == gWiFiResource.handle)
1081 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1083 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1084 return OC_EH_BAD_REQ;
1088 updateWiFiResource(input);
1091 else if(ehRequest->resource == gCloudResource.handle)
1093 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1095 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1096 return OC_EH_BAD_REQ;
1100 updateCloudResource(input);
1103 else if(ehRequest->resource == gDevConfResource.handle)
1105 if(CheckEhRequestPayload(ehRequest) != OC_EH_OK)
1107 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1108 return OC_EH_BAD_REQ;
1112 updateDevConfResource(input);
1116 OCRepPayload *getResp = NULL;
1117 if(ehRequest->resource == gProvResource.handle)
1119 getResp = constructResponseOfProv(ehRequest);
1121 else if(ehRequest->resource == gWiFiResource.handle)
1123 getResp = constructResponseOfWiFi();
1125 else if(ehRequest->resource == gCloudResource.handle)
1127 getResp = constructResponseOfCloud();
1129 else if(ehRequest->resource == gDevConfResource.handle)
1131 getResp = constructResponseOfDevConf();
1136 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1141 ehResult = OC_EH_OK;
1146 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
1147 OCRepPayload** payload)
1151 OCEntityHandlerResult ehResult = OC_EH_BAD_REQ;
1156 * This is the entity handler for the registered resource.
1157 * This is invoked by OCStack whenever it recevies a request for this resource.
1159 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
1160 OCEntityHandlerRequest* entityHandlerRequest, void *callback)
1163 OCEntityHandlerResult ehRet = OC_EH_OK;
1164 OCEntityHandlerResponse response =
1165 { 0, 0, OC_EH_ERROR, 0, 0,
1168 OCRepPayload* payload = NULL;
1170 if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
1172 if (OC_REST_GET == entityHandlerRequest->method)
1174 OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
1175 ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
1177 else if (OC_REST_PUT == entityHandlerRequest->method)
1179 OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
1181 //PUT request will be handled in the internal implementation
1182 if (gProvResource.handle != NULL)
1184 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
1188 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1189 ehRet = OC_EH_ERROR;
1192 else if (OC_REST_POST == entityHandlerRequest->method)
1194 OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
1195 if (gProvResource.handle != NULL)
1197 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
1201 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1202 ehRet = OC_EH_ERROR;
1206 // Format the response. Note this requires some info about the request
1207 response.requestHandle = entityHandlerRequest->requestHandle;
1208 response.resourceHandle = entityHandlerRequest->resource;
1209 response.ehResult = ehRet;
1210 //response uses OCPaylod while all get,put methodes use OCRepPayload
1211 response.payload = (OCPayload*) (payload);
1212 response.numSendVendorSpecificHeaderOptions = 0;
1213 memset(response.sendVendorSpecificHeaderOptions, 0,
1214 sizeof(response.sendVendorSpecificHeaderOptions));
1215 memset(response.resourceUri, 0, sizeof(response.resourceUri));
1216 // Indicate that response is NOT in a persistent buffer
1217 response.persistentBufferFlag = 0;
1219 // Send the response
1220 if (OCDoResponse(&response) != OC_STACK_OK)
1222 OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
1223 ehRet = OC_EH_ERROR;
1226 if (flag & OC_OBSERVE_FLAG)
1228 OIC_LOG(INFO, ES_RH_TAG, "Flag includes OC_OBSERVE_FLAG");
1230 if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action)
1232 OIC_LOG (INFO, ES_RH_TAG, "Received OC_OBSERVE_REGISTER from Mediator");
1234 else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action)
1236 OIC_LOG (INFO, ES_RH_TAG, "Received OC_OBSERVE_DEREGISTER from Mediator");
1242 OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
1244 OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty IN");
1246 gWiFiResource.supportedFreq = (deviceProperty->WiFi).freq;
1247 OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Freq : %d", gWiFiResource.supportedFreq);
1250 while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
1252 gWiFiResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
1253 OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Mode : %d", gWiFiResource.supportedMode[modeIdx]);
1256 gWiFiResource.numMode = modeIdx;
1258 OICStrcpy(gDevConfResource.devName, OIC_STRING_MAX_VALUE, (deviceProperty->DevConf).deviceName);
1259 OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
1261 OICStrcpy(gDevConfResource.modelNumber, OIC_STRING_MAX_VALUE,
1262 (deviceProperty->DevConf).modelNumber);
1263 OIC_LOG_V(INFO, ES_RH_TAG, "Model Number : %s", gDevConfResource.modelNumber);
1265 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gWiFiResource.handle, OC_HIGH_QOS))
1267 OIC_LOG(INFO, ES_RH_TAG, "wifiResource doesn't have any observers.");
1270 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gDevConfResource.handle, OC_HIGH_QOS))
1272 OIC_LOG(INFO, ES_RH_TAG, "devConfResource doesn't have any observers.");
1275 OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
1279 OCStackResult SetEnrolleeState(ESEnrolleeState esState)
1281 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState IN");
1283 gProvResource.status = esState;
1284 OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee Status : %d", gProvResource.status);
1286 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gProvResource.handle, OC_HIGH_QOS))
1288 OIC_LOG(INFO, ES_RH_TAG, "provResource doesn't have any observers.");
1291 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState OUT");
1295 OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
1297 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode IN");
1299 gProvResource.lastErrCode = esErrCode;
1300 OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee ErrorCode : %d", gProvResource.lastErrCode);
1302 if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(gProvResource.handle, OC_HIGH_QOS))
1304 OIC_LOG(INFO, ES_RH_TAG, "provResource doesn't have any observers.");
1307 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
1311 OCEntityHandlerResult CheckEhRequestPayload(OCEntityHandlerRequest *ehRequest)
1313 if( !(ehRequest->query) ||
1314 (ehRequest->query &&
1315 (strcmp(ehRequest->query, "") && !CompareResourceInterface(ehRequest->query,
1316 OC_RSRVD_INTERFACE_DEFAULT))))
1318 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1319 return OC_EH_BAD_REQ;
1324 const char *getResult(OCStackResult result)
1329 return "OC_STACK_OK";
1330 case OC_STACK_INVALID_URI:
1331 return "OC_STACK_INVALID_URI";
1332 case OC_STACK_INVALID_QUERY:
1333 return "OC_STACK_INVALID_QUERY";
1334 case OC_STACK_INVALID_IP:
1335 return "OC_STACK_INVALID_IP";
1336 case OC_STACK_INVALID_PORT:
1337 return "OC_STACK_INVALID_PORT";
1338 case OC_STACK_INVALID_CALLBACK:
1339 return "OC_STACK_INVALID_CALLBACK";
1340 case OC_STACK_INVALID_METHOD:
1341 return "OC_STACK_INVALID_METHOD";
1342 case OC_STACK_NO_MEMORY:
1343 return "OC_STACK_NO_MEMORY";
1344 case OC_STACK_COMM_ERROR:
1345 return "OC_STACK_COMM_ERROR";
1346 case OC_STACK_INVALID_PARAM:
1347 return "OC_STACK_INVALID_PARAM";
1348 case OC_STACK_NOTIMPL:
1349 return "OC_STACK_NOTIMPL";
1350 case OC_STACK_NO_RESOURCE:
1351 return "OC_STACK_NO_RESOURCE";
1352 case OC_STACK_RESOURCE_ERROR:
1353 return "OC_STACK_RESOURCE_ERROR";
1354 case OC_STACK_SLOW_RESOURCE:
1355 return "OC_STACK_SLOW_RESOURCE";
1356 case OC_STACK_NO_OBSERVERS:
1357 return "OC_STACK_NO_OBSERVERS";
1358 case OC_STACK_ERROR:
1359 return "OC_STACK_ERROR";