1 /******************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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 *****************************************************************/
20 #include "iotivity_config.h"
28 #include "platform_features.h"
31 #include "oic_malloc.h"
32 #include "oic_string.h"
33 #include "ocprovisioningmanager.h"
34 #include "oxmjustworks.h"
35 #include "oxmrandompin.h"
36 #include "securevirtualresourcetypes.h"
37 #include "srmutility.h"
39 #include "pmutility.h"
46 // declaration(s) for provisioning client using C-level provisioning API
47 // user input definition for main loop on provisioning client
48 #define _10_DISCOV_MOT_ENABLED_DEV_ 10
49 #define _11_DISCOV_MULTIPLE_OWNED_DEV_ 11
50 #define _20_PERFORM_MOT_ 20
51 #define _30_GET_LED_RESOURCE_ 30
52 #define _31_PUT_LED_RESOURCE_ 31
53 #define _40_PROVISION_ACL_ 40
54 #define _41_PROVISION_CRED_ 41
55 #define _99_EXIT_PRVN_CLT_ 99
57 #define ACL_RESRC_MAX_NUM 16
58 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
59 #define ACL_RESRC_MAX_LEN 128
60 #define ACL_PEMISN_CNT 5
61 #define DISCOVERY_TIMEOUT 5 // 5 sec
62 #define CALLBACK_TIMEOUT 60 // 1 min
63 #define TAG "subownerclient"
65 static const char* SVR_DB_FILE_NAME = "oic_svr_db_subowner_client.dat";
66 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
67 static const char* PRVN_DB_FILE_NAME = "oic_pdm_subowner.db";
68 static const OicSecPrm_t SUPPORTED_PRMS[1] =
73 // |g_ctx| means provision manager application context and
74 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
75 // for accessing all function(s) for these, they are declared on global domain
76 static const char* g_ctx = "SubOwner Client Application Context";
77 static char* g_svr_fname;
78 static char* g_prvn_fname;
79 static OCProvisionDev_t* g_own_list;
80 static OCProvisionDev_t* g_unown_list;
81 static OCProvisionDev_t* g_motdev_list;
82 static OCProvisionDev_t* g_mowned_list;
84 static int g_unown_cnt;
85 static int g_motdev_cnt;
86 static int g_mowned_cnt;
89 // function declaration(s) for calling them before implementing
90 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
91 static int printDevList(const OCProvisionDev_t*);
92 static size_t printUuidList(const OCUuidList_t*);
93 static int printResultList(const OCProvisionResult_t*, const int);
94 static void printUuid(const OicUuid_t*);
95 static FILE* fopen_prvnMng(const char*, const char*);
96 static int waitCallbackRet(void);
97 static int selectTwoDiffNum(int*, int*, const int, const char*);
99 // callback function(s) for provisioning client using C-level provisioning API
100 static void multipleOwnershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
104 OIC_LOG_V(INFO, TAG, "Multiple Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
108 OIC_LOG_V(ERROR, TAG, "Multiple Ownership Transfer FAILED - ctx: %s", (char*) ctx);
109 printResultList((const OCProvisionResult_t*) arr, nOfRes);
114 // callback function(s) for provisioning client using C-level provisioning API
115 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
119 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
123 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
124 printResultList((const OCProvisionResult_t*) arr, nOfRes);
129 static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
133 OIC_LOG_V(INFO, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
137 OIC_LOG_V(ERROR, TAG, "POST 'doxm' FAILED - ctx: %s", (char*) ctx);
138 printResultList((const OCProvisionResult_t*) arr, nOfRes);
143 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
147 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
151 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
152 printResultList((const OCProvisionResult_t*) arr, nOfRes);
157 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
161 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
165 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
166 printResultList((const OCProvisionResult_t*) arr, nOfRes);
171 // response handler for LED requests.
172 static void LedCB(void *ctx, OCDoHandle UNUSED,
173 OCClientResponse *clientResponse)
177 if(OC_STACK_OK == clientResponse->result)
179 printf("Received OC_STACK_OK from server\n");
180 if(clientResponse->payload)
182 printf("Response ===================> %p\n", clientResponse->payload);
185 else if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
187 printf("Received OC_STACK_RESOURCE_CHANGED from server\n");
191 printf("Error in response : %d\n", clientResponse->result);
196 printf("Hit the response callback but can not find response data\n");
202 static void inputPinCB(char* pin, size_t len)
204 if(!pin || OXM_RANDOM_PIN_MAX_SIZE>=len)
206 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
210 printf(" > INPUT PIN: ");
211 for(int ret=0; 1!=ret; )
213 ret = scanf("%32s", pin);
214 for( ; 0x20<=getchar(); ); // for removing overflow garbages
215 // '0x20<=code' is character region
219 // function(s) for provisioning client using C-level provisioning API
220 static int initProvisionClient(void)
222 // initialize persistent storage for SVR DB
223 static OCPersistentStorage ps = {fopen_prvnMng, fread, fwrite, fclose, unlink};
224 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&ps))
226 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
230 // initialize OC stack and provisioning manager
231 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
233 OIC_LOG(ERROR, TAG, "OCStack init error");
237 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
239 printf("************************************************************\n");
240 printf("************Provisioning DB file already exists.************\n");
241 printf("************************************************************\n");
245 printf("*************************************************************\n");
246 printf("************No provisioning DB file, creating new************\n");
247 printf("*************************************************************\n");
250 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
252 OIC_LOG(ERROR, TAG, "OC_PM init error");
256 SetInputPinCB(inputPinCB);
261 static int discoverMotSupportedDevices(void)
263 // delete un/owned device lists before updating them
266 OCDeleteDiscoveredDevices(g_motdev_list);
267 g_motdev_list = NULL;
270 // call |OCDiscoverMultipleOwnerEnabledDevices| API actually
271 printf(" Discovering Multiple Ownership Transfer enabled Devices on Network..\n");
272 if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_motdev_list))
274 OIC_LOG(ERROR, TAG, "OCDiscoverMultipleOwnerEnalbedDevices API error");
278 // display the discovered device lists
279 printf(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
280 g_motdev_cnt = printDevList(g_motdev_list);
285 static int discoverSubOwnerDevices()
287 // delete un/owned device lists before updating them
290 OCDeleteDiscoveredDevices(g_mowned_list);
291 g_mowned_list = NULL;
294 // call |OCDiscoverMultipleOwnedDevices| API actually
295 printf(" Discovering Multiple Owned Devices on Network..\n");
296 if(OC_STACK_OK != OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_mowned_list))
298 OIC_LOG(ERROR, TAG, "OCDiscoverMultipleOwnerEnabledDevices API error");
302 // display the discovered device lists
303 printf(" > Discovered Multiple Owned Devices\n");
304 g_mowned_cnt = printDevList(g_mowned_list);
309 static int multipleOwnershipTransfer(void)
311 // check |unown_list| for registering devices
312 if(!g_motdev_list || 0 >=g_motdev_cnt)
314 printf(" > MultipleOwnershipTransfer Enabled Device List is Empty\n");
315 printf(" > Please Discover Devices first, with [10] Menu\n");
316 return 0; // normal case
319 // call |getDevInst| API actually
320 // calling this API with callback actually acts like blocking
321 // for error checking, the return value saved and printed
324 #ifdef MULTIPLE_OWNER
325 OCProvisionDev_t* dev = NULL;
326 LL_FOREACH(g_motdev_list, dev)
328 if(OIC_PRECONFIG_PIN == dev->doxm->oxmSel)
330 //Pre-Configured PIN initialization
331 const char* testPreconfigPin = "12341234";
332 if(OC_STACK_OK != OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin)))
334 printf("\n\n\n*** %60s ***\n", "WARNNING : Failed to save the pre-configured PIN");
335 printf("*** %60s ***\n\n\n", "WARNNING : You can't use the pre-configured PIN OxM for MOT");
340 #endif //MULTIPLE_OWNER
342 if(OC_STACK_OK != OCDoMultipleOwnershipTransfer(g_ctx, g_motdev_list, multipleOwnershipTransferCB))
344 OIC_LOG(ERROR, TAG, "_20_PERFORM_MOT_: error");
348 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
350 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
354 // display the registered result
355 printf(" > Registered Discovered Devices\n");
360 static int sendGetLed()
363 char query[256] = {0};
364 OCCallbackData cbData;
366 cbData.context = NULL;
369 printDevList(g_mowned_list);
371 // select device for provisioning access control list
374 printf(" > Enter Device Number, for sending GET LED request: ");
375 for(int ret=0; 1!=ret; )
377 ret = scanf("%d", &selDevNum);
378 for( ; 0x20<=getchar(); ); // for removing overflow garbages
379 // '0x20<=code' is character region
381 if(0<selDevNum && g_mowned_cnt>=selDevNum)
385 printf(" Entered Wrong Number. Please Enter Again\n");
388 OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
391 printf("Failed to getDevInst()\n");
395 if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
396 query, sizeof(query), "/a/led"))
399 printf("query=%s\n", query);
400 if(OC_STACK_OK != OCDoResource(NULL, OC_REST_GET, query, NULL, NULL, selDev->connType,
401 OC_HIGH_QOS, &cbData, NULL, 0))
403 printf("********************************\n");
404 printf("Failed to send GET request to %s\n", query);
405 printf("********************************\n");
414 printf("Failed to generate GET request for /a/led\n");
421 static int sendPutLed()
424 char query[256] = {0};
425 OCCallbackData cbData;
427 cbData.context = NULL;
430 printDevList(g_mowned_list);
431 // select device for provisioning access control list
434 printf(" > Enter Device Number, for sending PUT LED request: ");
435 for(int ret=0; 1!=ret; )
437 ret = scanf("%d", &selDevNum);
438 for( ; 0x20<=getchar(); ); // for removing overflow garbages
439 // '0x20<=code' is character region
441 if(0<selDevNum && g_mowned_cnt>=selDevNum)
445 printf(" Entered Wrong Number. Please Enter Again\n");
448 OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
451 printf("Failed to getDevInst()\n");
455 if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
456 query, sizeof(query), "/a/led"))
459 printf("query=%s\n", query);
460 if(OC_STACK_OK != OCDoResource(NULL, OC_REST_PUT, query, NULL, NULL, selDev->connType,
461 OC_LOW_QOS, &cbData, NULL, 0))
463 printf("********************************\n");
464 printf("Failed to send PUT request to %s\n", query);
465 printf("********************************\n");
474 printf("Failed to generate PUT request for /a/led\n");
482 static OicSecAcl_t* createAclForLEDAccess(const OicUuid_t* subject)
486 OIC_LOG(ERROR, TAG, "createAcl: Invalid paramters");
489 // allocate memory for |acl| struct
490 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
493 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
494 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
496 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
499 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
500 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
502 LL_APPEND(acl->aces, ace);
503 memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
506 char* rsrc_in = "/a/led"; // '1' for null termination
507 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
510 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
514 size_t len = strlen(rsrc_in)+1; // '1' for null termination
515 rsrc->href = (char*) OICCalloc(len, sizeof(char));
518 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
521 OICStrcpy(rsrc->href, len, rsrc_in);
523 //fill the resource type (rt)
525 rsrc->types = (char**)OICCalloc(1, sizeof(char*));
528 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
531 rsrc->types[0] = OICStrdup("oic.r.core");
534 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
538 //fill the interface (if)
539 rsrc->interfaceLen = 1;
540 rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*));
541 if(!rsrc->interfaces)
543 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
546 rsrc->interfaces[0] = OICStrdup("oic.if.baseline");
547 if(!rsrc->interfaces[0])
549 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
553 LL_APPEND(ace->resources, rsrc);
555 // full permission for /a/led
556 ace->permission = PERMISSION_FULL_CONTROL;
558 ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t));
559 if(NULL == ace->eownerID)
561 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
565 memcpy(ace->eownerID->id, subject->id, sizeof(subject->id));
570 OCDeleteACLList(acl); // after here |acl| points nothing
574 static int provisionAclForLed()
576 OicSecAcl_t* acl = NULL;
578 // check |own_list| for provisioning access control list
579 if(!g_mowned_list || 1> g_mowned_cnt)
581 printf(" > MOT Device List is Empty\n");
582 printf(" > Please Perform MOT first, with [12|21] Menu\n");
583 return 0; // normal case
586 // display the MOT dev list
587 printf(" > MOT Devices\n");
588 g_mowned_cnt = printDevList(g_mowned_list);
590 // select device for provisioning access control list
594 printf(" > Enter Device Number, for Provisioning LED's ACL: ");
595 for(int ret=0; 1!=ret; )
597 ret = scanf("%d", &dev_num);
598 for( ; 0x20<=getchar(); ); // for removing overflow garbages
599 // '0x20<=code' is character region
601 if(0<dev_num && g_mowned_list>=dev_num)
605 printf(" Entered Wrong Number. Please Enter Again\n");
609 printf(" Provisioning Selected ACL..\n");
610 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_mowned_list, dev_num);
613 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
617 acl = createAclForLEDAccess(&dev->doxm->subOwners->uuid);
620 OIC_LOG(ERROR, TAG, "provisionAcl: Failed to create ACL for LED");
624 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
625 if(OC_STACK_OK != rst)
627 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
630 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
632 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
635 // display the ACL-provisioned result
636 printf(" > Provisioned Selected ACL\n");
638 OCDeleteACLList(acl); // after here |acl| points nothing
642 OCDeleteACLList(acl);
646 static int provisionCred()
648 // check |unown_list| for registering devices
649 if(!g_mowned_list|| 0 >=g_mowned_cnt)
651 printf(" > Multiple Owned Device List is Empty\n");
652 printf(" > Please Discover Devices first, with [13] Menu\n");
653 return 0; // normal case
656 // display the MOT dev list
657 printf(" > Multiple Owned Devices\n");
658 g_mowned_cnt = printDevList(g_mowned_list);
663 printf(" > Enter Multiple Owned Device Number to link : ");
664 for(int ret=0; 1!=ret; )
666 ret = scanf("%d", &dev_num);
667 for( ; 0x20<=getchar(); ); // for removing overflow garbages
668 // '0x20<=code' is character region
670 if(0<dev_num && g_mowned_cnt>=dev_num)
674 printf(" Entered Wrong Number. Please Enter Again\n");
677 OCProvisionDev_t* motDev = getDevInst(g_mowned_list, dev_num);
680 OIC_LOG(ERROR, TAG, "Failed to getDevInst()");
684 // display the MOT dev list
685 printf(" > Owned Devices\n");
686 g_own_cnt = printDevList(g_own_list);
690 printf(" > Enter Owned Device Number to link : ");
691 for(int ret=0; 1!=ret; )
693 ret = scanf("%d", &dev_num);
694 for( ; 0x20<=getchar(); ); // for removing overflow garbages
695 // '0x20<=code' is character region
697 if(0<dev_num && g_own_cnt>=dev_num)
701 printf(" Entered Wrong Number. Please Enter Again\n");
704 OCProvisionDev_t* ownDev = getDevInst(g_own_list, dev_num);
707 OIC_LOG(ERROR, TAG, "Failed to getDevInst()");
711 // call |OCProvisionCredentials| API actually
712 // calling this API with callback actually acts like blocking
713 // for error checking, the return value saved and printed
715 printf(" Provisioning Selected Pairwise Devices..\n");
716 OCStackResult rst = OCProvisionCredentials((void*) g_ctx,
717 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
718 ownDev, motDev, provisionCredCB);
719 if(OC_STACK_OK != rst)
721 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
724 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
726 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
730 // display the pairwise-provisioned result
731 printf(" > Provisioned Selected Pairwise Devices\n");
739 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
741 if(!dev_lst || 0>=dev_num)
743 printf(" Device List is Empty..\n");
747 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
757 return NULL; // in here |lst| is always |NULL|
760 static int printDevList(const OCProvisionDev_t* dev_lst)
764 printf(" Device List is Empty..\n\n");
768 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
772 printf(" [%d] ", ++lst_cnt);
773 printUuid((const OicUuid_t*) &lst->doxm->deviceID);
782 static size_t printUuidList(const OCUuidList_t* uid_lst)
786 printf(" Device List is Empty..\n\n");
790 OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
794 printf(" [%zu] ", ++lst_cnt);
795 printUuid((const OicUuid_t*) &lst->dev);
804 static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
806 if(!rslt_lst || 0>=rslt_cnt)
808 printf(" Device List is Empty..\n\n");
813 for( ; rslt_cnt>lst_cnt; ++lst_cnt)
815 printf(" [%d] ", lst_cnt+1);
816 printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
817 printf(" - result: %d\n", rslt_lst[lst_cnt].res);
824 static void printUuid(const OicUuid_t* uid)
826 for(int i=0; i<UUID_LENGTH; )
828 printf("%02X", (*uid).id[i++]);
829 if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
836 static FILE* fopen_prvnMng(const char* path, const char* mode)
838 (void)path; // unused |path| parameter
840 // input |g_svr_db_fname| internally by force, not using |path| parameter
841 // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
842 // with its own |SVR_DB_FILE_NAME|
843 return fopen(SVR_DB_FILE_NAME, mode);
846 static int waitCallbackRet(void)
848 for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
851 if(OC_STACK_OK != OCProcess())
853 OIC_LOG(ERROR, TAG, "OCStack process error");
860 OCPDMCleanupForTimeout();
866 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
868 if(!a || !b || 2>max || !str)
875 for(int i=0; 2>i; ++i)
880 printf(" > Enter Device[%d] Number, %s: ", i+1, str);
881 for(int ret=0; 1!=ret; )
883 ret = scanf("%d", num);
884 for( ; 0x20<=getchar(); ); // for removing overflow garbages
885 // '0x20<=code' is character region
887 if(0<*num && max>=*num)
891 printf(" Entered Wrong Number. Please Enter Again\n");
904 static void printMenu(void)
906 printf("************************************************************\n");
907 printf("****** OIC Provisioning Client with using C-level API ******\n");
908 printf("************************************************************\n\n");
910 printf("** [A] DISCOVER DEVICES ON NETWORK\n");
911 printf("** 10. Discover Multiple Ownership Transfer Enabled Devices on Network\n");
912 printf("** 11. Discover Multiple Owned Devices on Network\n\n");
914 printf("** [B] PERFORM MULTIPLE OWNERSHIP TRANSFER\n");
915 printf("** 20. Perform the Multiple Ownership Transfer for ALL discovered dievices\n\n");
917 printf("** [C] Get/Put Request for APPLICATION RESOURCE\n");
918 printf("** 30. Get LED resource\n");
919 printf("** 31. Put LED resource\n\n");
921 printf("** [D] LINK DEVICES\n");
922 printf("** 40. Provision ACL for LED Resource\n");
923 printf("** 41. Provison Credential\n\n");
925 printf("** [F] EXIT PROVISIONING CLIENT\n");
926 printf("** 99. Exit Provisionong Client\n\n");
928 printf("************************************************************\n\n");
931 // main function for provisioning client using C-level provisioning API
934 // initialize provisioning client
935 if(initProvisionClient())
937 OIC_LOG(ERROR, TAG, "ProvisionClient init error");
941 // main loop for provisioning manager
948 printf(">> Enter Menu Number: ");
949 for(int ret=0; 1!=ret; )
951 ret = scanf("%d", &mnNum);
952 for( ; 0x20<=getchar(); ); // for removing overflow garbages
953 // '0x20<=code' is character region
958 case _10_DISCOV_MOT_ENABLED_DEV_:
959 if(discoverMotSupportedDevices())
961 OIC_LOG(ERROR, TAG, "_12_MOT_DISCOV_DEV_: error");
964 case _11_DISCOV_MULTIPLE_OWNED_DEV_:
965 if(discoverSubOwnerDevices())
967 OIC_LOG(ERROR, TAG, "_13_DISCOV_MULTIPLE_OWNED_DEV_: error");
970 case _20_PERFORM_MOT_:
971 if(multipleOwnershipTransfer())
973 OIC_LOG(ERROR, TAG, "_21_PERFORM_MOT_: error");
976 case _30_GET_LED_RESOURCE_:
979 OIC_LOG(ERROR, TAG, "_30_GET_LED_RESOURCE_: error");
982 case _31_PUT_LED_RESOURCE_:
985 OIC_LOG(ERROR, TAG, "_31_PUT_LED_RESOURCE_: error");
988 case _40_PROVISION_ACL_:
989 if(provisionAclForLed())
991 OIC_LOG(ERROR, TAG, "_40_PROVISION_ACL_: error");
994 case _41_PROVISION_CRED_:
995 OIC_LOG(ERROR, TAG, "NOT SUPPORTED YET.");
1000 OIC_LOG(ERROR, TAG, "_41_PROVISION_CRED_: error");
1004 case _99_EXIT_PRVN_CLT_:
1007 printf(">> Entered Wrong Number. Please Enter Again\n\n");
1013 if(OC_STACK_OK != OCStop())
1015 OIC_LOG(ERROR, TAG, "OCStack stop error");
1017 OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
1018 OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
1019 OCDeleteDiscoveredDevices(g_motdev_list); // after here |g_motdev_list| points nothing
1023 OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
1027 OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
1029 return 0; // always return normal case
1034 #endif //__cplusplus