1 /******************************************************************
3 * Copyright 2015 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 *****************************************************************/
27 #include "oic_malloc.h"
28 #include "oic_string.h"
29 #include "ocprovisioningmanager.h"
30 #include "oxmjustworks.h"
31 #include "oxmrandompin.h"
32 #include "securevirtualresourcetypes.h"
33 #include "srmutility.h"
41 // declaration(s) for provisioning client using C-level provisioning API
42 // user input definition for main loop on provisioning client
43 #define _10_DISCOV_ALL_DEVS_ 10
44 #define _11_DISCOV_UNOWN_DEVS_ 11
45 #define _12_DISCOV_OWN_DEVS_ 12
46 #define _20_REGIST_DEVS_ 20
47 #define _30_PROVIS_PAIR_DEVS_ 30
48 #define _31_PROVIS_CRED_ 31
49 #define _32_PROVIS_ACL_ 32
50 #define _33_PROVIS_DP_ 33
51 #define _34_CHECK_LINK_STATUS_ 34
52 #define _40_UNLINK_PAIR_DEVS_ 40
53 #define _50_REMOVE_SELEC_DEV_ 50
54 #define _51_REMOVE_DEV_WITH_UUID_ 51
55 #define _52_RESET_SELEC_DEV_ 52
56 #define _60_GET_CRED_ 60
57 #define _61_GET_ACL_ 61
58 #define _99_EXIT_PRVN_CLT_ 99
60 #define ACL_RESRC_MAX_NUM 16
61 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
62 #define ACL_RESRC_MAX_LEN 128
63 #define ACL_PEMISN_CNT 5
64 #define DISCOVERY_TIMEOUT 10 // 10 sec
65 #define CALLBACK_TIMEOUT 60 // 1 min
66 #define TAG "provisioningclient"
68 static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
69 static const char* SVR_DB_FILE_NAME = "oic_svr_db_client.dat";
70 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
71 static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
72 static const OicSecPrm_t SUPPORTED_PRMS[1] =
77 // |g_ctx| means provision manager application context and
78 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
79 // for accessing all function(s) for these, they are declared on global domain
80 static const char* g_ctx = "Provision Manager Client Application Context";
81 static char* g_svr_fname;
82 static char* g_prvn_fname;
83 static OCProvisionDev_t* g_own_list;
84 static OCProvisionDev_t* g_unown_list;
86 static int g_unown_cnt;
89 // function declaration(s) for calling them before implementing
90 static OicSecAcl_t* createAcl(const int);
91 static OicSecPdAcl_t* createPdAcl(const int);
92 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
93 static int printDevList(const OCProvisionDev_t*);
94 static size_t printUuidList(const OCUuidList_t*);
95 static int printResultList(const OCProvisionResult_t*, const int);
96 static void printUuid(const OicUuid_t*);
97 static FILE* fopen_prvnMng(const char*, const char*);
98 static int waitCallbackRet(void);
99 static int selectTwoDiffNum(int*, int*, const int, const char*);
101 // callback function(s) for provisioning client using C-level provisioning API
102 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
106 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
110 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
111 printResultList((const OCProvisionResult_t*) arr, nOfRes);
116 static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
120 OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
124 OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
125 printResultList((const OCProvisionResult_t*) arr, nOfRes);
130 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
134 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
138 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
139 printResultList((const OCProvisionResult_t*) arr, nOfRes);
144 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
148 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
152 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
153 printResultList((const OCProvisionResult_t*) arr, nOfRes);
158 static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
162 OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
166 OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx);
167 printResultList((const OCProvisionResult_t*) arr, nOfRes);
172 static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
176 OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
180 OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx);
181 printResultList((const OCProvisionResult_t*) arr, nOfRes);
186 static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
190 OIC_LOG_V(INFO, TAG, "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
194 OIC_LOG_V(ERROR, TAG, "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
195 printResultList((const OCProvisionResult_t*) arr, nOfRes);
200 static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
204 OIC_LOG_V(INFO, TAG, "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
208 OIC_LOG_V(ERROR, TAG, "Unlink Devices FAILED - ctx: %s", (char*) ctx);
209 printResultList((const OCProvisionResult_t*) arr, nOfRes);
214 static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
218 OIC_LOG_V(INFO, TAG, "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
222 OIC_LOG_V(ERROR, TAG, "Remove Device FAILED - ctx: %s", (char*) ctx);
223 printResultList((const OCProvisionResult_t*) arr, nOfRes);
228 static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
232 OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx);
236 OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx);
237 printResultList((const OCProvisionResult_t*) arr, nOfRes);
242 static void inputPinCB(char* pin, size_t len)
244 if(!pin || OXM_RANDOM_PIN_SIZE>=len)
246 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
250 printf(" > INPUT PIN: ");
251 for(int ret=0; 1!=ret; )
253 ret = scanf("%8s", pin);
254 for( ; 0x20<=getchar(); ); // for removing overflow garbages
255 // '0x20<=code' is character region
259 // function(s) for provisioning client using C-level provisioning API
260 static int initProvisionClient(void)
262 // initialize persistent storage for SVR DB
263 static OCPersistentStorage pstStr =
265 .open = fopen_prvnMng,
271 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
273 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
277 // initialize OC stack and provisioning manager
278 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
280 OIC_LOG(ERROR, TAG, "OCStack init error");
284 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
286 printf("************************************************************\n");
287 printf("************Provisioning DB file already exists.************\n");
288 printf("************************************************************\n");
292 printf("*************************************************************\n");
293 printf("************No provisioning DB file, creating new************\n");
294 printf("*************************************************************\n");
297 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
299 OIC_LOG(ERROR, TAG, "OC_PM init error");
303 // register callback function(s) to each OxM
304 OTMCallbackData_t otmcb =
306 .loadSecretCB = LoadSecretJustWorksCallback,
307 .createSecureSessionCB = CreateSecureSessionJustWorksCallback,
308 .createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload,
309 .createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload
311 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb))
313 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_JUST_WORKS");
316 otmcb.loadSecretCB = InputPinCodeCallback;
317 otmcb.createSecureSessionCB = CreateSecureSessionRandomPinCallback;
318 otmcb.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
319 otmcb.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
320 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_RANDOM_DEVICE_PIN, &otmcb))
322 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_RANDOM_DEVICE_PIN");
325 SetInputPinCB(inputPinCB);
330 static int discoverAllDevices(void)
332 // delete un/owned device lists before updating them
335 OCDeleteDiscoveredDevices(g_own_list);
340 OCDeleteDiscoveredDevices(g_unown_list);
344 // call |OCGetDevInfoFromNetwork| API actually
345 printf(" Discovering All Un/Owned Devices on Network..\n");
346 if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
348 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error");
352 // display the discovered un/owned lists
353 printf(" > Discovered Owned Devices\n");
354 g_own_cnt = printDevList(g_own_list);
355 printf(" > Discovered Unowned Devices\n");
356 g_unown_cnt = printDevList(g_unown_list);
362 static int discoverUnownedDevices(void)
364 // delete unowned device list before updating it
367 OCDeleteDiscoveredDevices(g_unown_list);
371 // call |OCDiscoverUnownedDevices| API actually
372 printf(" Discovering Only Unowned Devices on Network..\n");
373 if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
375 OIC_LOG(ERROR, TAG, "OCDiscoverUnownedDevices API error");
379 // display the discovered unowned list
380 printf(" > Discovered Unowned Devices\n");
381 g_unown_cnt = printDevList(g_unown_list);
386 static int discoverOwnedDevices(void)
388 // delete owned device list before updating it
391 OCDeleteDiscoveredDevices(g_own_list);
395 // call |OCDiscoverOwnedDevices| API actually
396 printf(" Discovering Only Owned Devices on Network..\n");
397 if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
399 OIC_LOG(ERROR, TAG, "OCDiscoverOwnedDevices API error");
403 // display the discovered owned list
404 printf(" > Discovered Owned Devices\n");
405 g_own_cnt = printDevList(g_own_list);
410 static int registerDevices(void)
412 // check |unown_list| for registering devices
413 if(!g_unown_list || 0>=g_unown_cnt)
415 printf(" > Unowned Device List, to Register Devices, is Empty\n");
416 printf(" > Please Discover Unowned Devices first, with [10|11] Menu\n");
417 return 0; // normal case
420 // call |OCDoOwnershipTransfer| API actually
421 // calling this API with callback actually acts like blocking
422 // for error checking, the return value saved and printed
424 printf(" Registering All Discovered Unowned Devices..\n");
425 OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
426 if(OC_STACK_OK != rst)
428 OIC_LOG_V(ERROR, TAG, "OCDoOwnershipTransfer API error: %d", rst);
431 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
433 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
437 // display the registered result
438 printf(" > Registered Discovered Unowned Devices\n");
439 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
444 static int provisionPairwise(void)
446 // check |own_list| for provisioning pairwise devices
447 if(!g_own_list || 2>g_own_cnt)
449 printf(" > Owned Device List, to Provision the Pairwise, is Empty\n");
450 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
451 return 0; // normal case
454 // select two devices for provisioning pairwise devices
455 int dev_num[2] = {0};
456 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
458 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
459 return -1; // not need to 'goto' |ERROR| before allocating |acl|
462 // create ACL(s) for each selected device
463 OicSecAcl_t* acl[2] = {0};
464 for(int i=0; 2>i; ++i)
466 acl[i] = createAcl(dev_num[i]);
469 OIC_LOG(ERROR, TAG, "createAcl error return");
474 // call |OCProvisionPairwiseDevices| API actually
475 // calling this API with callback actually acts like blocking
476 // for error checking, the return value saved and printed
478 printf(" Provisioning Selected Pairwise Devices..\n");
480 OCProvisionPairwiseDevices((void*) g_ctx,
481 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
482 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
483 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
484 provisionPairwiseCB);
485 if(OC_STACK_OK != rst)
487 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
490 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
492 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
495 OCDeleteACLList(acl[0]);
496 OCDeleteACLList(acl[1]);
498 // display the pairwise-provisioned result
499 printf(" > Provisioned Selected Pairwise Devices\n");
500 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
505 OCDeleteACLList(acl[0]);
506 OCDeleteACLList(acl[1]);
510 static int provisionCred(void)
512 // check |own_list| for provisioning pairwise credentials
513 if(!g_own_list || 2>g_own_cnt)
515 printf(" > Owned Device List, to Provision Credentials, is Empty\n");
516 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
517 return 0; // normal case
520 // select two devices for provisioning pairwise credentials
521 int dev_num[2] = {0};
522 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
524 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
528 printf(" Select PSK length..\n");
529 printf(" 1 - 128bit(Default)\n");
530 printf(" 2 - 256bit\n");
533 for(int ret=0; 1!=ret; )
535 ret = scanf("%d",&sizeOption);
536 for( ; 0x20<=getchar(); ); // for removing overflow garbages
537 // '0x20<=code' is character region
545 size = OWNER_PSK_LENGTH_128;
550 size = OWNER_PSK_LENGTH_256;
555 size = OWNER_PSK_LENGTH_128;
561 // call |OCProvisionCredentials| API actually
562 // calling this API with callback actually acts like blocking
563 // for error checking, the return value saved and printed
565 printf(" Provisioning Selected Pairwise Credentials..\n");
567 OCProvisionCredentials((void*) g_ctx,
568 SYMMETRIC_PAIR_WISE_KEY, size,
569 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
570 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
572 if(OC_STACK_OK != rst)
574 OIC_LOG_V(ERROR, TAG, "OCProvisionCredentials API error: %d", rst);
577 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
579 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
583 // display the CRED-provisioned result
584 printf(" > Provisioned Selected Pairwise Crendentials\n");
585 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
590 static int provisionAcl(void)
592 // check |own_list| for provisioning access control list
593 if(!g_own_list || 1>g_own_cnt)
595 printf(" > Owned Device List, to Provision ACL, is Empty\n");
596 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
597 return 0; // normal case
600 // select device for provisioning access control list
604 printf(" > Enter Device Number, for Provisioning ACL: ");
605 for(int ret=0; 1!=ret; )
607 ret = scanf("%d", &dev_num);
608 for( ; 0x20<=getchar(); ); // for removing overflow garbages
609 // '0x20<=code' is character region
611 if(0<dev_num && g_own_cnt>=dev_num)
615 printf(" Entered Wrong Number. Please Enter Again\n");
618 // create ACL for selected device
619 OicSecAcl_t* acl = NULL;
620 acl = createAcl(dev_num);
623 OIC_LOG(ERROR, TAG, "createAcl error return");
627 // call |OCProvisionACL| API actually
628 // calling this API with callback actually acts like blocking
629 // for error checking, the return value saved and printed
631 printf(" Provisioning Selected ACL..\n");
632 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
635 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
638 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
639 if(OC_STACK_OK != rst)
641 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
644 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
646 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
649 OCDeleteACLList(acl); // after here |acl| points nothing
651 // display the ACL-provisioned result
652 printf(" > Provisioned Selected ACL\n");
657 OCDeleteACLList(acl); // after here |acl| points nothing
661 static int provisionDirectPairing(void)
663 // check |own_list| for provisioning direct-pairing
664 if(!g_own_list || 1>g_own_cnt)
666 printf(" > Owned Device List, to Provision ACL, is Empty\n");
667 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
668 return 0; // normal case
671 // select device for provisioning direct-pairing
675 printf(" > Enter Device Number, for Provisioning Direct-Pairing: ");
676 for(int ret=0; 1!=ret; )
678 ret = scanf("%d", &dev_num);
679 for( ; 0x20<=getchar(); ); // for removing overflow garbages
680 // '0x20<=code' is character region
682 if(0<dev_num && g_own_cnt>=dev_num)
686 printf(" Entered Wrong Number. Please Enter Again\n");
689 // create Direct-Pairing Configuration(PIN, PDACL) for selected device
690 // TODO: default acl -> input from user !
692 memset(&pconf, 0, sizeof(OicSecPconf_t));
697 // set default supported PRM types
698 pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
699 pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
702 for (size_t i=0; i<pconf.prmLen; i++)
704 pconf.prm[i] = SUPPORTED_PRMS[i];
709 OIC_LOG(ERROR, TAG, "create prm error return");
714 const char DP_DEFAULT_PIN[] = "00000000";
715 memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
718 pconf.pdacls = createPdAcl(dev_num);
721 OIC_LOG(ERROR, TAG, "createPdAcl error return");
725 // call |OCProvisionDirectPairing| API actually
726 // calling this API with callback actually acts like blocking
727 // for error checking, the return value saved and printed
729 printf(" Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
730 OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
731 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
732 &pconf, provisionDPCB);
733 if(OC_STACK_OK != rst)
735 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
736 if (OC_STACK_UNAUTHORIZED_REQ == rst)
738 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
742 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
744 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
747 OCDeletePdAclList(pconf.pdacls);
749 // display the PCONF-provisioned result
750 printf(" > SUCCESS to provision Direct-Pairing !!\n");
755 OCDeletePdAclList(pconf.pdacls); // after here |acl| points nothing
759 static int checkLinkedStatus(void)
761 // check |own_list| for checking selected link status on PRVN DB
762 if(!g_own_list || 1>g_own_cnt)
764 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
765 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
766 return 0; // normal case
769 // select device for checking selected link status on PRVN DB
773 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
774 for(int ret=0; 1!=ret; )
776 ret = scanf("%d", &dev_num);
777 for( ; 0x20<=getchar(); ); // for removing overflow garbages
778 // '0x20<=code' is character region
780 if(0<dev_num && g_own_cnt>=dev_num)
784 printf(" Entered Wrong Number. Please Enter Again\n");
787 // call |OCGetLinkedStatus| API actually
788 printf(" Checking Selected Link Status on PRVN DB..\n");
789 OCUuidList_t* dvid_lst = NULL;
791 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
792 if(!dev || !dev->doxm)
794 OIC_LOG(ERROR, TAG, "checkLinkedStatus: device instance empty");
800 &dev->doxm->deviceID,
801 &dvid_lst, &dvid_cnt)) // allow empty list
803 OIC_LOG(ERROR, TAG, "OCGetLinkedStatus API error");
807 // display the linked status result
808 printf(" > Checked Selected Link Status on PRVN DB\n");
809 if(!dvid_lst || !dvid_cnt) // |size_t| is unsigned
811 printf(" Linked Device List is Empty..\n");
812 return 0; // normal case
814 if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
816 OIC_LOG(ERROR, TAG, "printUuidList error return");
819 OCDeleteUuidList(dvid_lst);
824 OCDeleteUuidList(dvid_lst);
828 static int getCred(void)
830 // check |own_list| for checking selected link status on PRVN DB
831 if(!g_own_list || 1>g_own_cnt)
833 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
834 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
835 return 0; // normal case
838 // select device for checking selected link status on PRVN DB
842 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
843 for(int ret=0; 1!=ret; )
845 ret = scanf("%d", &dev_num);
846 for( ; 0x20<=getchar(); ); // for removing overflow garbages
847 // '0x20<=code' is character region
849 if(0<dev_num && g_own_cnt>=dev_num)
853 printf(" Entered Wrong Number. Please Enter Again\n");
856 // call |getDevInst| API actually
857 // calling this API with callback actually acts like blocking
858 // for error checking, the return value saved and printed
860 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
863 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
866 OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
867 if(OC_STACK_OK != rst)
869 OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst);
872 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
874 OIC_LOG(ERROR, TAG, "OCGetCredResource callback error");
878 // display the result of get credential
879 printf(" > Get Cred SUCCEEDED\n");
887 static int getAcl(void)
889 // check |own_list| for checking selected link status on PRVN DB
890 if(!g_own_list || 1>g_own_cnt)
892 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
893 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
894 return 0; // normal case
897 // select device for checking selected link status on PRVN DB
901 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
902 for(int ret=0; 1!=ret; )
904 ret = scanf("%d", &dev_num);
905 for( ; 0x20<=getchar(); ); // for removing overflow garbages
906 // '0x20<=code' is character region
908 if(0<dev_num && g_own_cnt>=dev_num)
912 printf(" Entered Wrong Number. Please Enter Again\n");
915 // call |getDevInst| API actually
916 // calling this API with callback actually acts like blocking
917 // for error checking, the return value saved and printed
919 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
922 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
925 OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
926 if(OC_STACK_OK != rst)
928 OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst);
932 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
934 OIC_LOG(ERROR, TAG, "OCGetACLResource callback error");
938 // display the result of get credential
939 printf(" > Get ACL SUCCEEDED\n");
947 static int unlinkPairwise(void)
949 // check |own_list| for unlinking pairwise devices
950 if(!g_own_list || 2>g_own_cnt)
952 printf(" > Owned Device List, to Unlink the Pairwise, is Empty\n");
953 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
954 return 0; // normal case
957 // select two devices for unlinking pairwise devices
958 int dev_num[2] = {0};
959 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
961 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
965 // call |OCUnlinkDevices| API actually
966 // calling this API with callback actually acts like blocking
967 // for error checking, the return value saved and printed
969 printf(" Unlinking Selected Pairwise Devices..\n");
971 OCUnlinkDevices((void*) g_ctx,
972 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
973 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
975 if(OC_STACK_OK != rst)
977 OIC_LOG_V(ERROR, TAG, "OCUnlinkDevices API error: %d", rst);
980 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
982 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
986 // display the pairwise-unlinked result
987 printf(" > Unlinked Selected Pairwise Devices\n");
988 printf(" > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
993 static int removeDevice(void)
995 // check |own_list| for removing device
996 if(!g_own_list || 1>g_own_cnt)
998 printf(" > Owned Device List, to Remove Device, is Empty\n");
999 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1000 return 0; // normal case
1003 // select device for removing it
1007 printf(" > Enter Device Number, for Removing Device: ");
1008 for(int ret=0; 1!=ret; )
1010 ret = scanf("%d", &dev_num);
1011 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1012 // '0x20<=code' is character region
1014 if(0<dev_num && g_own_cnt>=dev_num)
1018 printf(" Entered Wrong Number. Please Enter Again\n");
1021 // call |OCRemoveDevice| API actually
1022 // calling this API with callback actually acts like blocking
1023 // for error checking, the return value saved and printed
1025 printf(" Removing Selected Owned Device..\n");
1027 OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
1028 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
1029 if(OC_STACK_OK != rst)
1031 OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst);
1034 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1036 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1040 // display the removed result
1041 printf(" > Removed Selected Owned Device\n");
1042 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1047 static int removeDeviceWithUuid(void)
1049 char strUuid[64] = {0};
1051 printf("Input the UUID : ");
1052 for(int ret=0; 1!=ret; )
1054 ret = scanf("%64s", strUuid);
1055 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1056 // '0x20<=code' is character region
1058 OCStackResult rst = ConvertStrToUuid(strUuid, &revUuid);
1059 if(OC_STACK_OK != rst)
1061 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
1065 rst = OCRemoveDeviceWithUuid("RemoveDeviceWithUUID", DISCOVERY_TIMEOUT, &revUuid, removeDeviceCB);
1066 if(OC_STACK_OK != rst)
1068 OIC_LOG_V(ERROR, TAG, "OCRemoveDeviceWithUuid API error: %d", rst);
1073 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1075 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid callback error");
1079 // display the removed result
1080 printf(" > Removed %s Device\n", strUuid);
1081 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1086 static int resetDevice(void)
1088 // check |own_list| for removing device
1089 if (!g_own_list || 1 > g_own_cnt)
1091 printf(" > Owned Device List, to Reset Device, is Empty\n");
1092 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1096 // select device for removing it
1100 printf(" > Enter Device Number, for Resetting Device: ");
1101 for (int ret = 0; 1 != ret; )
1103 ret = scanf("%d", &dev_num);
1104 for ( ; 0x20 <= getchar() ; ); // for removing overflow garbages
1105 // '0x20 <= code' is character region
1107 if (0 < dev_num && g_own_cnt >= dev_num)
1111 printf(" Entered Wrong Number. Please Enter Again\n");
1115 printf(" Resetting Selected Owned Device..\n");
1117 OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT,
1118 getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB);
1119 if (OC_STACK_OK != rst)
1121 OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst);
1125 if (waitCallbackRet()) // input |g_doneCB| flag implicitly
1127 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1131 // display the removed result
1132 printf(" > Reset Selected Owned Device SUCCEEDED\n");
1133 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1138 static OicSecAcl_t* createAcl(const int dev_num)
1140 if(0>=dev_num || g_own_cnt<dev_num)
1142 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1143 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1146 // allocate memory for |acl| struct
1147 printf(" **** Create ACL for the Selected Device[%d]\n", dev_num);
1148 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
1151 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1152 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1154 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
1157 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1158 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1160 LL_APPEND(acl->aces, ace);
1162 // enter |subject| device number
1166 printf(" > [A] Enter Subject Device Number: ");
1167 for(int ret=0; 1!=ret; )
1169 ret = scanf("%d", &num);
1170 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1171 // '0x20<=code' is character region
1173 if(0<num && g_own_cnt>=num && dev_num!=num)
1177 printf(" Entered Wrong Number. Please Enter Again\n");
1180 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, num);
1181 if(!dev || !dev->doxm)
1183 OIC_LOG(ERROR, TAG, "createAcl: device instance empty");
1186 memcpy(&ace->subjectuuid, &dev->doxm->deviceID, UUID_LENGTH);
1188 // enter number of |resources| in 'accessed' device
1191 printf(" > [B] Enter Number of Accessed Resources (under 16): ");
1192 // '16' is |ACL_RESRC_MAX_NUM|
1193 for(int ret=0; 1!=ret; )
1195 ret = scanf("%d", &num);
1196 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1197 // '0x20<=code' is character region
1199 if(0<num && ACL_RESRC_MAX_NUM>=num)
1203 printf(" Entered Wrong Number. Please Enter under 16 Again\n");
1204 // '16' is |ACL_RESRC_MAX_NUM|
1207 // enter actually each 'accessed' |resources| name
1208 printf(" Enter Each Accessed Resource Name (each under 128 char)\n");
1209 // '128' is ACL_RESRC_MAX_LEN
1211 char rsrc_in[ACL_RESRC_MAX_LEN+1] = {0}; // '1' for null termination
1212 for(int i = 0; num > i; ++i)
1214 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
1217 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1221 printf(" Enter Accessed Resource[%d] Name: (e.g. /a/led)", i+1);
1222 for(int ret=0; 1!=ret; )
1224 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1225 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1226 // '0x20<=code' is character region
1228 size_t len = strlen(rsrc_in)+1; // '1' for null termination
1229 rsrc->href = (char*) OICCalloc(len, sizeof(char));
1232 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1235 OICStrcpy(rsrc->href, len, rsrc_in);
1240 printf(" Enter Number of resource type for [%s] : ", rsrc->href);
1241 for(int ret=0; 1!=ret; )
1243 ret = scanf("%d", &arrLen);
1244 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1245 // '0x20<=code' is character region
1247 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1251 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1254 rsrc->typeLen = arrLen;
1255 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
1258 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1262 for(int i = 0; i < arrLen; i++)
1264 printf(" Enter ResourceType[%d] Name (e.g. core.led): ", i+1);
1265 for(int ret=0; 1!=ret; )
1267 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1268 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1269 // '0x20<=code' is character region
1271 rsrc->types[i] = OICStrdup(rsrc_in);
1274 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1281 printf(" Enter Number of interface for [%s]: ", rsrc->href);
1282 for(int ret=0; 1!=ret; )
1284 ret = scanf("%d", &arrLen);
1285 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1286 // '0x20<=code' is character region
1288 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1292 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1295 rsrc->interfaceLen = arrLen;
1296 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
1297 if(!rsrc->interfaces)
1299 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1303 for(int i = 0; i < arrLen; i++)
1305 printf(" Enter Interface[%d] Name (e.g. oic.if.baseline): ", i+1);
1306 for(int ret=0; 1!=ret; )
1308 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1309 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1310 // '0x20<=code' is character region
1312 rsrc->interfaces[i] = OICStrdup(rsrc_in);
1313 if(!rsrc->interfaces[i])
1315 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1320 LL_APPEND(ace->resources, rsrc);
1323 // enter |permission| for this access
1324 printf(" > [C] Enter Permission for This Access\n");
1325 uint16_t pmsn = PERMISSION_FULL_CONTROL; // default full permission
1326 uint16_t pmsn_msk = PERMISSION_CREATE; // default permission mask
1327 for(int i=0; ACL_PEMISN_CNT>i; ++i)
1332 printf(" Enter %s Permission (y/n): ", ACL_PEMISN[i]);
1333 for(int ret=0; 1!=ret; )
1335 ret = scanf("%c", &ans);
1336 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1337 // '0x20<=code' is character region
1339 if('y'==ans || 'Y'==ans || 'n'==ans|| 'N'==ans)
1341 ans &= ~0x20; // for masking lower case, 'y/n'
1344 printf(" Entered Wrong Answer. Please Enter 'y/n' Again\n");
1346 if('N' == ans) // masked lower case, 'n'
1352 ace->permission = pmsn;
1357 OCDeleteACLList(acl); // after here |acl| points nothing
1361 static OicSecPdAcl_t* createPdAcl(const int dev_num)
1363 if(0>=dev_num || g_own_cnt<dev_num)
1365 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1366 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1369 // allocate memory for |pdacl| struct
1370 printf(" **** Create PDACL for the Selected Device[%d]\n", dev_num);
1371 OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
1374 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1375 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1379 // number of resources
1380 char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
1381 pdAcl->resourcesLen = 1;
1384 int num = pdAcl->resourcesLen;
1385 pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
1386 if(!pdAcl->resources)
1388 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1391 for(int i=0; num>i; ++i)
1393 size_t len = strlen(rsrc_in[i])+1; // '1' for null termination
1394 char* rsrc = (char*) OICCalloc(len, sizeof(char));
1397 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1400 OICStrcpy(rsrc, len, rsrc_in[i]);
1401 pdAcl->resources[i] = rsrc; // after here, |rsrc| points nothing
1405 pdAcl->permission = PERMISSION_FULL_CONTROL;
1410 OCDeletePdAclList(pdAcl);
1414 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
1416 if(!dev_lst || 0>=dev_num)
1418 printf(" Device List is Empty..\n");
1422 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1432 return NULL; // in here |lst| is always |NULL|
1435 static int printDevList(const OCProvisionDev_t* dev_lst)
1439 printf(" Device List is Empty..\n\n");
1443 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1447 printf(" [%d] ", ++lst_cnt);
1448 printUuid((const OicUuid_t*) &lst->doxm->deviceID);
1457 static size_t printUuidList(const OCUuidList_t* uid_lst)
1461 printf(" Device List is Empty..\n\n");
1465 OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
1469 printf(" [%zu] ", ++lst_cnt);
1470 printUuid((const OicUuid_t*) &lst->dev);
1479 static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
1481 if(!rslt_lst || 0>=rslt_cnt)
1483 printf(" Device List is Empty..\n\n");
1488 for( ; rslt_cnt>lst_cnt; ++lst_cnt)
1490 printf(" [%d] ", lst_cnt+1);
1491 printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
1492 printf(" - result: %d\n", rslt_lst[lst_cnt].res);
1499 static void printUuid(const OicUuid_t* uid)
1501 for(int i=0; i<UUID_LENGTH; )
1503 printf("%02X", (*uid).id[i++]);
1504 if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
1511 static FILE* fopen_prvnMng(const char* path, const char* mode)
1513 (void)path; // unused |path| parameter
1515 // input |g_svr_db_fname| internally by force, not using |path| parameter
1516 // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
1517 // with its own |SVR_DB_FILE_NAME|
1518 return fopen(SVR_DB_FILE_NAME, mode);
1521 static int waitCallbackRet(void)
1523 for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
1526 if(OC_STACK_OK != OCProcess())
1528 OIC_LOG(ERROR, TAG, "OCStack process error");
1536 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
1538 if(!a || !b || 2>max || !str)
1545 for(int i=0; 2>i; ++i)
1547 int* num = 0==i?a:b;
1550 printf(" > Enter Device[%d] Number, %s: ", i+1, str);
1551 for(int ret=0; 1!=ret; )
1553 ret = scanf("%d", num);
1554 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1555 // '0x20<=code' is character region
1557 if(0<*num && max>=*num)
1561 printf(" Entered Wrong Number. Please Enter Again\n");
1574 static void printMenu(void)
1576 printf("************************************************************\n");
1577 printf("****** OIC Provisioning Client with using C-level API ******\n");
1578 printf("************************************************************\n\n");
1580 printf("** [A] DISCOVER DEVICES ON NETWORK\n");
1581 printf("** 10. Discover All Un/Owned Devices on Network\n");
1582 printf("** 11. Discover Only Unowned Devices on Network\n");
1583 printf("** 12. Discover Only Owned Devices on Network\n\n");
1585 printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n");
1586 printf("** 20. Register/Own All Discovered Unowned Devices\n\n");
1588 printf("** [C] PROVISION/LINK PAIRWISE THINGS\n");
1589 printf("** 30. Provision/Link Pairwise Things\n");
1590 printf("** 31. Provision Credentials for Pairwise Things\n");
1591 printf("** 32. Provision the Selected Access Control List(ACL)\n");
1592 printf("** 33. Provision Direct-Pairing Configuration\n");
1593 printf("** 34. Check Linked Status of the Selected Device on PRVN DB\n\n");
1595 printf("** [D] UNLINK PAIRWISE THINGS\n");
1596 printf("** 40. Unlink Pairwise Things\n\n");
1598 printf("** [E] REMOVE THE SELECTED DEVICE\n");
1599 printf("** 50. Remove the Selected Device\n");
1600 printf("** 51. Remove Device with UUID (UUID input is required)\n");
1601 printf("** 52. Reset the Selected Device\n\n");
1603 printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n");
1604 printf("** 60. Get the Credential resources of the Selected Device\n");
1605 printf("** 61. Get the ACL resources of the Selected Device\n\n");
1607 printf("** [G] EXIT PROVISIONING CLIENT\n");
1608 printf("** 99. Exit Provisionong Client\n\n");
1610 printf("************************************************************\n\n");
1613 #if 0 // Code for enabling path configuration for PDB and SVR DBf
1614 static void printUsage(void)
1617 printf("OIC Provisioning Client with using C-level API\n");
1618 printf("Usage: provisioningclient [option]...\n");
1620 printf(" -h print help for this provisioning client\n");
1621 printf(" -p=[prvn_db_file_path/name] input PRVN DB file path and name\n");
1622 printf(" if not exists, will load default DB file\n");
1623 printf(" (default: |oic_prvn_mng.db| on working dir)\n");
1624 printf(" (ex. -p=oic_prvn_mng.db)\n");
1625 printf(" -s=[svr_db_file_path/name] input SVR DB file path and name\n");
1626 printf(" if not exists, will load default DB file\n");
1627 printf(" (default: |oic_svr_db_client.json| on working dir)\n");
1628 printf(" (ex. -s=oic_svr_db_client.json)\n");
1633 // main function for provisioning client using C-level provisioning API
1636 // initialize provisioning client
1637 if(initProvisionClient())
1639 OIC_LOG(ERROR, TAG, "ProvisionClient init error");
1643 // main loop for provisioning manager
1649 printf(">> Enter Menu Number: ");
1650 for(int ret=0; 1!=ret; )
1652 ret = scanf("%d", &mn_num);
1653 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1654 // '0x20<=code' is character region
1659 case _10_DISCOV_ALL_DEVS_:
1660 if(discoverAllDevices())
1662 OIC_LOG(ERROR, TAG, "_10_DISCOV_ALL_DEVS_: error");
1665 case _11_DISCOV_UNOWN_DEVS_:
1666 if(discoverUnownedDevices())
1668 OIC_LOG(ERROR, TAG, "_11_DISCOV_UNOWN_DEVS_: error");
1671 case _12_DISCOV_OWN_DEVS_:
1672 if(discoverOwnedDevices())
1674 OIC_LOG(ERROR, TAG, "_12_DISCOV_OWN_DEVS_: error");
1677 case _20_REGIST_DEVS_:
1678 if(registerDevices())
1680 OIC_LOG(ERROR, TAG, "_20_REGIST_DEVS_: error");
1683 case _30_PROVIS_PAIR_DEVS_:
1684 if(provisionPairwise())
1686 OIC_LOG(ERROR, TAG, "_30_PROVIS_PAIR_DEVS_: error");
1689 case _31_PROVIS_CRED_:
1692 OIC_LOG(ERROR, TAG, "_31_PROVIS_CRED_: error");
1695 case _32_PROVIS_ACL_:
1698 OIC_LOG(ERROR, TAG, "_32_PROVIS_ACL_: error");
1701 case _33_PROVIS_DP_:
1702 if(provisionDirectPairing())
1704 OIC_LOG(ERROR, TAG, "_33_PROVIS_DP_: error");
1707 case _34_CHECK_LINK_STATUS_:
1708 if(checkLinkedStatus())
1710 OIC_LOG(ERROR, TAG, "_34_CHECK_LINK_STATUS_: error");
1713 case _40_UNLINK_PAIR_DEVS_:
1714 if(unlinkPairwise())
1716 OIC_LOG(ERROR, TAG, "_40_UNLINK_PAIR_DEVS_: error");
1719 case _50_REMOVE_SELEC_DEV_:
1722 OIC_LOG(ERROR, TAG, "_50_REMOVE_SELEC_DEV_: error");
1725 case _51_REMOVE_DEV_WITH_UUID_:
1726 if(removeDeviceWithUuid())
1728 OIC_LOG(ERROR, TAG, "_51_REMOVE_DEV_WITH_UUID_: error");
1731 case _52_RESET_SELEC_DEV_:
1734 OIC_LOG(ERROR, TAG, "_52_RESET_SELEC_DEV_: error");
1740 OIC_LOG(ERROR, TAG, "_60_GET_CRED_: error");
1746 OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error");
1749 case _99_EXIT_PRVN_CLT_:
1752 printf(">> Entered Wrong Number. Please Enter Again\n\n");
1758 if(OC_STACK_OK != OCStop())
1760 OIC_LOG(ERROR, TAG, "OCStack stop error");
1762 OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
1763 OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
1767 OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
1771 OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
1773 return 0; // always return normal case
1778 #endif //__cplusplus