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(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
56 void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
57 void updateDevConfResource(OCEntityHandlerRequest* ehRequest, 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(NULL, input);
282 updateWiFiResource(NULL, input);
283 updateDevConfResource(NULL, input);
288 void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
291 strcmp(ehRequest->query, "") &&
292 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
294 // In case of link list, batch interface
295 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
299 ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
303 OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
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;
314 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
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);
322 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
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);
329 int64_t authType = -1;
330 if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
332 gWiFiResource.authType = authType;
333 wiFiData->authtype = gWiFiResource.authType;
334 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
337 int64_t encType = -1;
338 if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
340 gWiFiResource.encType = encType;
341 wiFiData->enctype = gWiFiResource.encType;
342 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
347 gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFI, &wiFiData->userdata);
350 if(ssid || cred || authType!= -1 || encType != -1)
352 OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");
354 // TODO : Need to check appropriateness of gWiFiData
355 if(gWifiRsrcEvtCb != NULL)
357 gWifiRsrcEvtCb(ES_OK, wiFiData);
361 OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
368 void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
371 strcmp(ehRequest->query, "") &&
372 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
374 // In case of link list, batch interface
375 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
379 ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
381 if(cloudData == NULL)
383 OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
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;
392 char *authCode = NULL;
393 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
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);
400 char *authProvider = NULL;
401 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
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);
408 char *ciServer = NULL;
409 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
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);
418 gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER, &cloudData->userdata);
421 if(authCode || authProvider || ciServer)
423 OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");
425 // TODO : Need to check appropriateness of gCloudData
426 if(gCloudRsrcEvtCb != NULL)
428 gCloudRsrcEvtCb(ES_OK, cloudData);
432 OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
439 void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
442 strcmp(ehRequest->query, "") &&
443 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
445 // In case of link list, batch interface
446 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
450 ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
452 if(devConfData == NULL)
454 OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
457 memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
458 memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
459 devConfData->userdata = NULL;
461 char *location = NULL;
462 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LOCATION, &location))
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);
469 char *country = NULL;
470 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country))
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);
477 char *language = NULL;
478 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language))
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);
487 gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
490 if(country || language)
492 OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
494 // TODO : Need to check appropriateness of gDevConfData
495 if(gDevConfRsrcEvtCb != NULL)
497 gDevConfRsrcEvtCb(ES_OK, devConfData);
501 OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
505 OICFree(devConfData);
508 OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
511 strcmp(ehRequest->query, "") &&
512 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
514 // In case of link list, batch interface
515 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
519 OCRepPayload* payload = OCRepPayloadCreate();
522 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
526 OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
527 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
528 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
529 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
531 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
532 int64_t *modes_64 = (int64_t *)OICMalloc(gWiFiResource.numMode * sizeof(int64_t));
533 for(int i = 0 ; i < gWiFiResource.numMode ; ++i)
535 modes_64[i] = gWiFiResource.supportedMode[i];
537 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
539 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
540 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
541 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
542 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
543 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
547 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
553 OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
556 strcmp(ehRequest->query, "") &&
557 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
559 // In case of link list, batch interface
560 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
564 OCRepPayload* payload = OCRepPayloadCreate();
567 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
571 OIC_LOG(INFO, ES_RH_TAG, "constructResponse cloudserver res");
572 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
573 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
574 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
576 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
577 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
578 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
582 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
588 OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
591 strcmp(ehRequest->query, "") &&
592 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
594 // In case of link list, batch interface
595 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
599 OCRepPayload* payload = OCRepPayloadCreate();
602 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
606 OIC_LOG(INFO, ES_RH_TAG, "constructResponse devconf res");
607 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
608 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
609 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
611 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
612 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_MODELNUMBER, gDevConfResource.modelNumber);
613 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LOCATION, gDevConfResource.location);
614 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
615 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
619 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
625 OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
627 OCRepPayload* payload = OCRepPayloadCreate();
630 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
634 // Requested interface is Link list interface
635 //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
636 if(!ehRequest->query ||
637 (ehRequest->query && !strcmp(ehRequest->query, "")) ||
638 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
639 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
641 const OCRepPayload *arrayPayload[3] = {NULL};
645 if(gWiFiResource.handle != NULL)
647 OCRepPayload *add = OCRepPayloadCreate();
650 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
654 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
655 char **resourceType = NULL;
656 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
657 char **resourceInterface = NULL;
658 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
660 if(!resourceType || !resourceInterface)
662 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
666 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFI);
667 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
669 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
670 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFI);
671 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
672 (const char **)resourceType, dimensions);
673 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
674 (const char **)resourceInterface, dimensions);
676 arrayPayload[childResCnt++] = add;
679 if(gDevConfResource.handle != NULL)
681 OCRepPayload *add = OCRepPayloadCreate();
684 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
688 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
689 char **resourceType = NULL;
690 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
691 char **resourceInterface = NULL;
692 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
694 if(!resourceType || !resourceInterface)
696 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
700 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
701 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
703 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
704 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
705 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
706 (const char **)resourceType, dimensions);
707 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
708 (const char **)resourceInterface, dimensions);
710 arrayPayload[childResCnt++] = add;
713 if(gCloudResource.handle != NULL)
715 OCRepPayload *add = OCRepPayloadCreate();
718 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
722 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
723 char **resourceType = NULL;
724 resourceType = (char **)OICMalloc(sizeof(char *) * 1);
725 char **resourceInterface = NULL;
726 resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);
728 if(!resourceType || !resourceInterface)
730 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
734 resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
735 resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
737 add->base.type = PAYLOAD_TYPE_REPRESENTATION;
738 OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_CLOUDSERVER);
739 OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
740 (const char **)resourceType, dimensions);
741 OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
742 (const char **)resourceInterface, dimensions);
744 arrayPayload[childResCnt++] = add;
747 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};
749 if(!ehRequest->query ||
750 (ehRequest->query && !strcmp(ehRequest->query, "")) ||
751 (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
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);
763 OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
765 else // link list interface
767 OCRepPayload* head = payload;
768 OCRepPayload* nextPayload = NULL;
772 for(int i = 0 ; i < childResCnt ; ++i)
774 nextPayload = arrayPayload[i];
775 if(nextPayload != NULL)
777 payload->next = nextPayload;
778 payload = payload->next;
781 if(head->next != NULL)
783 payload = head->next;
791 ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
794 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
795 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
796 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
797 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
798 OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
799 OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_PROV);
801 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
802 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
807 gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_PROV);
812 if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
813 {// When Provisioning resource has a GET with BatchInterface
814 OCRepPayload* head = payload;
815 OCRepPayload* nextPayload = NULL;
817 nextPayload = constructResponseOfWiFi(NULL);
818 if(nextPayload != NULL)
820 payload->next = nextPayload;
821 payload = payload->next;
824 nextPayload = constructResponseOfCloud(NULL);
825 if(nextPayload != NULL)
827 payload->next = nextPayload;
828 payload = payload->next;
831 nextPayload = constructResponseOfDevConf(NULL);
832 if(nextPayload != NULL)
834 payload->next = nextPayload;
835 payload = payload->next;
846 OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
848 OCStackResult res = OC_STACK_ERROR;
849 bool maskFlag = false;
851 res = initProvResource(isSecured);
852 if(res != OC_STACK_OK)
854 // TODO: destroy logic will be added
855 OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
860 if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
863 res = initWiFiResource(isSecured);
864 if(res != OC_STACK_OK)
866 OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
870 res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
871 if(res != OC_STACK_OK)
873 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
879 if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
882 res = initCloudServerResource(isSecured);
883 if(res != OC_STACK_OK)
885 OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
889 res = OCBindResource(gProvResource.handle, gCloudResource.handle);
890 if(res != OC_STACK_OK)
892 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
897 if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
900 res = initDevConfResource(isSecured);
901 if(res != OC_STACK_OK)
903 OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
907 res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
908 if(res != OC_STACK_OK)
910 OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
916 if(maskFlag == false)
918 OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
919 return OC_STACK_ERROR;
923 OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
928 OCStackResult DeleteProvisioningResource()
930 OCStackResult res = OCDeleteResource(gProvResource.handle);
931 if (res != OC_STACK_OK)
933 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
939 OCStackResult DeleteEasySetupResources()
941 OCStackResult res = OC_STACK_ERROR;
942 if (gWiFiResource.handle != NULL)
944 res = OCUnBindResource(gProvResource.handle, gWiFiResource.handle);
945 if(res != OC_STACK_OK)
947 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind WiFi resource error with result: %s", getResult(res));
950 if (gCloudResource.handle != NULL)
952 res = OCUnBindResource(gProvResource.handle, gCloudResource.handle);
953 if(res != OC_STACK_OK)
955 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind CloudServer resource error with result: %s", getResult(res));
958 if (gDevConfResource.handle != NULL)
960 res = OCUnBindResource(gProvResource.handle, gDevConfResource.handle);
961 if(res != OC_STACK_OK)
963 OIC_LOG_V(ERROR, ES_RH_TAG, "Unbind DevConf resource error with result: %s", getResult(res));
967 if (gWiFiResource.handle != NULL)
969 res = OCDeleteResource(gWiFiResource.handle);
970 if (res != OC_STACK_OK)
972 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
976 if(gCloudResource.handle != NULL)
978 res = OCDeleteResource(gCloudResource.handle);
979 if (res != OC_STACK_OK)
981 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
985 if(gDevConfResource.handle != NULL)
987 res = OCDeleteResource(gDevConfResource.handle);
988 if (res != OC_STACK_OK)
990 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
994 if(gProvResource.handle != NULL)
996 res = OCDeleteResource(gProvResource.handle);
997 if (res != OC_STACK_OK)
999 OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
1006 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
1008 OCEntityHandlerResult ehResult = OC_EH_ERROR;
1011 OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
1014 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1016 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1020 OCRepPayload *getResp = NULL;
1023 if(ehRequest->resource == gProvResource.handle)
1025 if(ehRequest->query &&
1026 strcmp(ehRequest->query, "") &&
1027 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL) &&
1028 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1029 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1031 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1032 return OC_EH_BAD_REQ;
1036 getResp = constructResponseOfProv(ehRequest);
1039 else if(ehRequest->resource == gWiFiResource.handle)
1041 if(ehRequest->query &&
1042 strcmp(ehRequest->query, "") &&
1043 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1045 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1046 return OC_EH_BAD_REQ;
1050 getResp = constructResponseOfWiFi(ehRequest);
1053 else if(ehRequest->resource == gCloudResource.handle)
1055 if(ehRequest->query &&
1056 strcmp(ehRequest->query, "") &&
1057 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1059 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1060 return OC_EH_BAD_REQ;
1064 getResp = constructResponseOfCloud(ehRequest);
1067 else if(ehRequest->resource == gDevConfResource.handle)
1069 if(ehRequest->query &&
1070 strcmp(ehRequest->query, "") &&
1071 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1073 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1074 return OC_EH_BAD_REQ;
1078 getResp = constructResponseOfDevConf(ehRequest);
1084 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1089 ehResult = OC_EH_OK;
1094 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
1096 OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
1097 OCEntityHandlerResult ehResult = OC_EH_ERROR;
1098 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
1100 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
1104 OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
1107 OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
1111 if(ehRequest->resource == gProvResource.handle)
1113 if(ehRequest->query &&
1114 strcmp(ehRequest->query, "") &&
1115 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH) &&
1116 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1118 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1119 return OC_EH_BAD_REQ;
1123 updateProvResource(ehRequest, input);
1126 else if(ehRequest->resource == gWiFiResource.handle)
1128 if(ehRequest->query &&
1129 strcmp(ehRequest->query, "") &&
1130 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1132 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1133 return OC_EH_BAD_REQ;
1137 updateWiFiResource(ehRequest, input);
1140 else if(ehRequest->resource == gCloudResource.handle)
1142 if(ehRequest->query &&
1143 strcmp(ehRequest->query, "") &&
1144 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1146 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1147 return OC_EH_BAD_REQ;
1151 updateCloudResource(ehRequest, input);
1154 else if(ehRequest->resource == gDevConfResource.handle)
1156 if(ehRequest->query &&
1157 strcmp(ehRequest->query, "") &&
1158 !CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))
1160 OIC_LOG(ERROR, ES_RH_TAG, "Not supported Interface");
1161 return OC_EH_BAD_REQ;
1165 updateDevConfResource(ehRequest, input);
1169 OCRepPayload *getResp = NULL;
1170 if(ehRequest->resource == gProvResource.handle)
1172 getResp = constructResponseOfProv(ehRequest);
1174 else if(ehRequest->resource == gWiFiResource.handle)
1176 getResp = constructResponseOfWiFi(NULL);
1178 else if(ehRequest->resource == gCloudResource.handle)
1180 getResp = constructResponseOfCloud(NULL);
1182 else if(ehRequest->resource == gDevConfResource.handle)
1184 getResp = constructResponseOfDevConf(NULL);
1189 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
1194 ehResult = OC_EH_OK;
1199 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
1200 OCRepPayload** payload)
1204 OCEntityHandlerResult ehResult = OC_EH_BAD_REQ;
1209 * This is the entity handler for the registered resource.
1210 * This is invoked by OCStack whenever it recevies a request for this resource.
1212 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
1213 OCEntityHandlerRequest* entityHandlerRequest, void *callback)
1216 OCEntityHandlerResult ehRet = OC_EH_OK;
1217 OCEntityHandlerResponse response =
1218 { 0, 0, OC_EH_ERROR, 0, 0,
1221 OCRepPayload* payload = NULL;
1223 if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
1225 if (OC_REST_GET == entityHandlerRequest->method)
1227 OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
1228 ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
1230 else if (OC_REST_PUT == entityHandlerRequest->method)
1232 OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
1234 //PUT request will be handled in the internal implementation
1235 if (gProvResource.handle != NULL)
1237 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
1241 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1242 ehRet = OC_EH_ERROR;
1245 else if (OC_REST_POST == entityHandlerRequest->method)
1247 OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
1248 if (gProvResource.handle != NULL)
1250 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
1254 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
1255 ehRet = OC_EH_ERROR;
1259 // Format the response. Note this requires some info about the request
1260 response.requestHandle = entityHandlerRequest->requestHandle;
1261 response.resourceHandle = entityHandlerRequest->resource;
1262 response.ehResult = ehRet;
1263 //response uses OCPaylod while all get,put methodes use OCRepPayload
1264 response.payload = (OCPayload*) (payload);
1265 response.numSendVendorSpecificHeaderOptions = 0;
1266 memset(response.sendVendorSpecificHeaderOptions, 0,
1267 sizeof(response.sendVendorSpecificHeaderOptions));
1268 memset(response.resourceUri, 0, sizeof(response.resourceUri));
1269 // Indicate that response is NOT in a persistent buffer
1270 response.persistentBufferFlag = 0;
1272 // Send the response
1273 if (OCDoResponse(&response) != OC_STACK_OK)
1275 OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
1276 ehRet = OC_EH_ERROR;
1283 OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
1285 OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty IN");
1287 gWiFiResource.supportedFreq = (deviceProperty->WiFi).freq;
1288 OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Freq : %d", gWiFiResource.supportedFreq);
1291 while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
1293 gWiFiResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
1294 OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Mode : %d", gWiFiResource.supportedMode[modeIdx]);
1297 gWiFiResource.numMode = modeIdx;
1299 OICStrcpy(gDevConfResource.devName, OIC_STRING_MAX_VALUE, (deviceProperty->DevConf).deviceName);
1300 OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
1302 OICStrcpy(gDevConfResource.modelNumber, OIC_STRING_MAX_VALUE,
1303 (deviceProperty->DevConf).modelNumber);
1304 OIC_LOG_V(INFO, ES_RH_TAG, "Model Number : %s", gDevConfResource.modelNumber);
1306 OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
1310 OCStackResult SetEnrolleeState(ESEnrolleeState esState)
1312 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState IN");
1314 gProvResource.status = esState;
1315 OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee Status : %d", gProvResource.status);
1317 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState OUT");
1321 OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
1323 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode IN");
1325 gProvResource.lastErrCode = esErrCode;
1326 OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee ErrorCode : %d", gProvResource.lastErrCode);
1328 OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
1332 const char *getResult(OCStackResult result)
1337 return "OC_STACK_OK";
1338 case OC_STACK_INVALID_URI:
1339 return "OC_STACK_INVALID_URI";
1340 case OC_STACK_INVALID_QUERY:
1341 return "OC_STACK_INVALID_QUERY";
1342 case OC_STACK_INVALID_IP:
1343 return "OC_STACK_INVALID_IP";
1344 case OC_STACK_INVALID_PORT:
1345 return "OC_STACK_INVALID_PORT";
1346 case OC_STACK_INVALID_CALLBACK:
1347 return "OC_STACK_INVALID_CALLBACK";
1348 case OC_STACK_INVALID_METHOD:
1349 return "OC_STACK_INVALID_METHOD";
1350 case OC_STACK_NO_MEMORY:
1351 return "OC_STACK_NO_MEMORY";
1352 case OC_STACK_COMM_ERROR:
1353 return "OC_STACK_COMM_ERROR";
1354 case OC_STACK_INVALID_PARAM:
1355 return "OC_STACK_INVALID_PARAM";
1356 case OC_STACK_NOTIMPL:
1357 return "OC_STACK_NOTIMPL";
1358 case OC_STACK_NO_RESOURCE:
1359 return "OC_STACK_NO_RESOURCE";
1360 case OC_STACK_RESOURCE_ERROR:
1361 return "OC_STACK_RESOURCE_ERROR";
1362 case OC_STACK_SLOW_RESOURCE:
1363 return "OC_STACK_SLOW_RESOURCE";
1364 case OC_STACK_NO_OBSERVERS:
1365 return "OC_STACK_NO_OBSERVERS";
1366 case OC_STACK_ERROR:
1367 return "OC_STACK_ERROR";