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 *****************************************************************/
21 #include "iotivity_config.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"
45 // declaration(s) for provisioning client using C-level provisioning API
46 // user input definition for main loop on provisioning client
47 #define _10_DISCOV_ALL_DEVS_ 10
48 #define _11_DISCOV_UNOWN_DEVS_ 11
49 #define _12_DISCOV_OWN_DEVS_ 12
50 #define _20_REGIST_DEVS_ 20
51 #define _30_PROVIS_PAIR_DEVS_ 30
52 #define _31_PROVIS_CRED_ 31
53 #define _32_PROVIS_ACL_ 32
54 #define _33_PROVIS_DP_ 33
55 #define _34_CHECK_LINK_STATUS_ 34
56 #define _40_UNLINK_PAIR_DEVS_ 40
57 #define _50_REMOVE_SELEC_DEV_ 50
58 #define _51_REMOVE_DEV_WITH_UUID_ 51
59 #define _52_RESET_SELEC_DEV_ 52
60 #define _60_GET_CRED_ 60
61 #define _61_GET_ACL_ 61
62 #define _70_SELECT_PROTOCOL_ 70
63 #define _99_EXIT_PRVN_CLT_ 99
65 #define ACL_RESRC_MAX_NUM 16
66 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
67 #define ACL_RESRC_MAX_LEN 128
68 #define ACL_PEMISN_CNT 5
69 #define DISCOVERY_TIMEOUT 10 // 10 sec
70 #define CALLBACK_TIMEOUT 60 // 1 min
71 #define TAG "provisioningclient"
73 static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
74 static const char* SVR_DB_FILE_NAME = "oic_svr_db_client.dat";
75 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
76 static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
77 static const OicSecPrm_t SUPPORTED_PRMS[1] =
82 // |g_ctx| means provision manager application context and
83 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
84 // for accessing all function(s) for these, they are declared on global domain
85 static const char* g_ctx = "Provision Manager Client Application Context";
86 static char* g_svr_fname;
87 static char* g_prvn_fname;
88 static OCProvisionDev_t* g_own_list;
89 static OCProvisionDev_t* g_unown_list;
91 static int g_unown_cnt;
94 static int secure_protocol = 1;
95 static void setDevProtocol(const OCProvisionDev_t* dev_lst);
97 // function declaration(s) for calling them before implementing
98 static OicSecAcl_t* createAcl(const int);
99 static OicSecPdAcl_t* createPdAcl(const int);
100 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
101 static int printDevList(const OCProvisionDev_t*);
102 static size_t printUuidList(const OCUuidList_t*);
103 static int printResultList(const OCProvisionResult_t*, const int);
104 static void printUuid(const OicUuid_t*);
105 static FILE* fopen_prvnMng(const char*, const char*);
106 static int waitCallbackRet(void);
107 static int selectTwoDiffNum(int*, int*, const int, const char*);
109 // callback function(s) for provisioning client using C-level provisioning API
110 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
114 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
118 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
119 printResultList((const OCProvisionResult_t*) arr, nOfRes);
124 static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
128 OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
132 OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
133 printResultList((const OCProvisionResult_t*) arr, nOfRes);
138 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
142 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
146 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
147 printResultList((const OCProvisionResult_t*) arr, nOfRes);
152 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
156 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
160 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
161 printResultList((const OCProvisionResult_t*) arr, nOfRes);
166 static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
170 OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
174 OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx);
175 printResultList((const OCProvisionResult_t*) arr, nOfRes);
180 static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
184 OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
188 OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx);
189 printResultList((const OCProvisionResult_t*) arr, nOfRes);
194 static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
198 OIC_LOG_V(INFO, TAG, "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
202 OIC_LOG_V(ERROR, TAG, "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
203 printResultList((const OCProvisionResult_t*) arr, nOfRes);
208 static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
212 OIC_LOG_V(INFO, TAG, "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
216 OIC_LOG_V(ERROR, TAG, "Unlink Devices FAILED - ctx: %s", (char*) ctx);
217 printResultList((const OCProvisionResult_t*) arr, nOfRes);
222 static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
226 OIC_LOG_V(INFO, TAG, "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
230 OIC_LOG_V(ERROR, TAG, "Remove Device FAILED - ctx: %s", (char*) ctx);
231 printResultList((const OCProvisionResult_t*) arr, nOfRes);
236 static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
240 OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx);
244 OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx);
245 printResultList((const OCProvisionResult_t*) arr, nOfRes);
250 static void inputPinCB(char* pin, size_t len)
252 if(!pin || OXM_RANDOM_PIN_SIZE>=len)
254 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
258 printf(" > INPUT PIN: ");
259 for(int ret=0; 1!=ret; )
261 ret = scanf("%8s", pin);
262 for( ; 0x20<=getchar(); ); // for removing overflow garbages
263 // '0x20<=code' is character region
267 // function(s) for provisioning client using C-level provisioning API
268 static int initProvisionClient(void)
270 // initialize persistent storage for SVR DB
271 static OCPersistentStorage pstStr =
273 .open = fopen_prvnMng,
279 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
281 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
285 // initialize OC stack and provisioning manager
286 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
288 OIC_LOG(ERROR, TAG, "OCStack init error");
292 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
294 printf("************************************************************\n");
295 printf("************Provisioning DB file already exists.************\n");
296 printf("************************************************************\n");
300 printf("*************************************************************\n");
301 printf("************No provisioning DB file, creating new************\n");
302 printf("*************************************************************\n");
305 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
307 OIC_LOG(ERROR, TAG, "OC_PM init error");
311 // register callback function(s) to each OxM
312 OTMCallbackData_t otmcb =
314 .loadSecretCB = LoadSecretJustWorksCallback,
315 .createSecureSessionCB = CreateSecureSessionJustWorksCallback,
316 .createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload,
317 .createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload
319 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb))
321 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_JUST_WORKS");
324 otmcb.loadSecretCB = InputPinCodeCallback;
325 otmcb.createSecureSessionCB = CreateSecureSessionRandomPinCallback;
326 otmcb.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
327 otmcb.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
328 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_RANDOM_DEVICE_PIN, &otmcb))
330 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_RANDOM_DEVICE_PIN");
333 SetInputPinCB(inputPinCB);
338 static int discoverAllDevices(void)
340 // delete un/owned device lists before updating them
343 OCDeleteDiscoveredDevices(g_own_list);
348 OCDeleteDiscoveredDevices(g_unown_list);
352 // call |OCGetDevInfoFromNetwork| API actually
353 printf(" Discovering All Un/Owned Devices on Network..\n");
354 if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
356 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error");
360 // display the discovered un/owned lists
361 printf(" > Discovered Owned Devices\n");
362 g_own_cnt = printDevList(g_own_list);
363 printf(" > Discovered Unowned Devices\n");
364 g_unown_cnt = printDevList(g_unown_list);
366 setDevProtocol(g_own_list);
367 setDevProtocol(g_unown_list);
373 static int discoverUnownedDevices(void)
375 // delete unowned device list before updating it
378 OCDeleteDiscoveredDevices(g_unown_list);
382 // call |OCDiscoverUnownedDevices| API actually
383 printf(" Discovering Only Unowned Devices on Network..\n");
384 if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
386 OIC_LOG(ERROR, TAG, "OCDiscoverUnownedDevices API error");
390 // display the discovered unowned list
391 printf(" > Discovered Unowned Devices\n");
392 g_unown_cnt = printDevList(g_unown_list);
394 setDevProtocol(g_unown_list);
399 static int discoverOwnedDevices(void)
401 // delete owned device list before updating it
404 OCDeleteDiscoveredDevices(g_own_list);
408 // call |OCDiscoverOwnedDevices| API actually
409 printf(" Discovering Only Owned Devices on Network..\n");
410 if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
412 OIC_LOG(ERROR, TAG, "OCDiscoverOwnedDevices API error");
416 // display the discovered owned list
417 printf(" > Discovered Owned Devices\n");
418 g_own_cnt = printDevList(g_own_list);
420 setDevProtocol(g_own_list);
425 static int registerDevices(void)
427 // check |unown_list| for registering devices
428 if(!g_unown_list || 0>=g_unown_cnt)
430 printf(" > Unowned Device List, to Register Devices, is Empty\n");
431 printf(" > Please Discover Unowned Devices first, with [10|11] Menu\n");
432 return 0; // normal case
435 // call |OCDoOwnershipTransfer| API actually
436 // calling this API with callback actually acts like blocking
437 // for error checking, the return value saved and printed
439 printf(" Registering All Discovered Unowned Devices..\n");
440 OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
441 if(OC_STACK_OK != rst)
443 OIC_LOG_V(ERROR, TAG, "OCDoOwnershipTransfer API error: %d", rst);
446 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
448 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
452 // display the registered result
453 printf(" > Registered Discovered Unowned Devices\n");
454 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
459 static int provisionPairwise(void)
461 // check |own_list| for provisioning pairwise devices
462 if(!g_own_list || 2>g_own_cnt)
464 printf(" > Owned Device List, to Provision the Pairwise, is Empty\n");
465 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
466 return 0; // normal case
469 // select two devices for provisioning pairwise devices
470 int dev_num[2] = {0};
471 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
473 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
474 return -1; // not need to 'goto' |ERROR| before allocating |acl|
477 // create ACL(s) for each selected device
478 OicSecAcl_t* acl[2] = {0};
479 for(int i=0; 2>i; ++i)
481 acl[i] = createAcl(dev_num[i]);
484 OIC_LOG(ERROR, TAG, "createAcl error return");
489 // call |OCProvisionPairwiseDevices| API actually
490 // calling this API with callback actually acts like blocking
491 // for error checking, the return value saved and printed
493 printf(" Provisioning Selected Pairwise Devices..\n");
495 OCProvisionPairwiseDevices((void*) g_ctx,
496 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
497 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
498 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
499 provisionPairwiseCB);
500 if(OC_STACK_OK != rst)
502 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
505 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
507 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
510 OCDeleteACLList(acl[0]);
511 OCDeleteACLList(acl[1]);
513 // display the pairwise-provisioned result
514 printf(" > Provisioned Selected Pairwise Devices\n");
515 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
520 OCDeleteACLList(acl[0]);
521 OCDeleteACLList(acl[1]);
525 static int provisionCred(void)
527 // check |own_list| for provisioning pairwise credentials
528 if(!g_own_list || 2>g_own_cnt)
530 printf(" > Owned Device List, to Provision Credentials, is Empty\n");
531 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
532 return 0; // normal case
535 // select two devices for provisioning pairwise credentials
536 int dev_num[2] = {0};
537 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
539 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
543 printf(" Select PSK length..\n");
544 printf(" 1 - 128bit(Default)\n");
545 printf(" 2 - 256bit\n");
548 for(int ret=0; 1!=ret; )
550 ret = scanf("%d",&sizeOption);
551 for( ; 0x20<=getchar(); ); // for removing overflow garbages
552 // '0x20<=code' is character region
560 size = OWNER_PSK_LENGTH_128;
565 size = OWNER_PSK_LENGTH_256;
570 size = OWNER_PSK_LENGTH_128;
576 // call |OCProvisionCredentials| API actually
577 // calling this API with callback actually acts like blocking
578 // for error checking, the return value saved and printed
580 printf(" Provisioning Selected Pairwise Credentials..\n");
582 OCProvisionCredentials((void*) g_ctx,
583 SYMMETRIC_PAIR_WISE_KEY, size,
584 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
585 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
587 if(OC_STACK_OK != rst)
589 OIC_LOG_V(ERROR, TAG, "OCProvisionCredentials API error: %d", rst);
592 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
594 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
598 // display the CRED-provisioned result
599 printf(" > Provisioned Selected Pairwise Crendentials\n");
600 printf(" > Please Check Device's Status for the Linked Result, with [34] Menu\n");
605 static int provisionAcl(void)
607 // check |own_list| for provisioning access control list
608 if(!g_own_list || 1>g_own_cnt)
610 printf(" > Owned Device List, to Provision ACL, is Empty\n");
611 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
612 return 0; // normal case
615 // select device for provisioning access control list
619 printf(" > Enter Device Number, for Provisioning ACL: ");
620 for(int ret=0; 1!=ret; )
622 ret = scanf("%d", &dev_num);
623 for( ; 0x20<=getchar(); ); // for removing overflow garbages
624 // '0x20<=code' is character region
626 if(0<dev_num && g_own_cnt>=dev_num)
630 printf(" Entered Wrong Number. Please Enter Again\n");
633 // create ACL for selected device
634 OicSecAcl_t* acl = NULL;
635 acl = createAcl(dev_num);
638 OIC_LOG(ERROR, TAG, "createAcl error return");
642 // call |OCProvisionACL| API actually
643 // calling this API with callback actually acts like blocking
644 // for error checking, the return value saved and printed
646 printf(" Provisioning Selected ACL..\n");
647 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
650 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
653 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
654 if(OC_STACK_OK != rst)
656 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
659 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
661 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
664 OCDeleteACLList(acl); // after here |acl| points nothing
666 // display the ACL-provisioned result
667 printf(" > Provisioned Selected ACL\n");
672 OCDeleteACLList(acl); // after here |acl| points nothing
676 static int provisionDirectPairing(void)
678 // check |own_list| for provisioning direct-pairing
679 if(!g_own_list || 1>g_own_cnt)
681 printf(" > Owned Device List, to Provision ACL, is Empty\n");
682 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
683 return 0; // normal case
686 // select device for provisioning direct-pairing
690 printf(" > Enter Device Number, for Provisioning Direct-Pairing: ");
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 // create Direct-Pairing Configuration(PIN, PDACL) for selected device
705 // TODO: default acl -> input from user !
707 memset(&pconf, 0, sizeof(OicSecPconf_t));
712 // set default supported PRM types
713 pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
714 pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
717 for (size_t i=0; i<pconf.prmLen; i++)
719 pconf.prm[i] = SUPPORTED_PRMS[i];
724 OIC_LOG(ERROR, TAG, "create prm error return");
729 const char DP_DEFAULT_PIN[] = "00000000";
730 memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
733 pconf.pdacls = createPdAcl(dev_num);
736 OIC_LOG(ERROR, TAG, "createPdAcl error return");
740 // call |OCProvisionDirectPairing| API actually
741 // calling this API with callback actually acts like blocking
742 // for error checking, the return value saved and printed
744 printf(" Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
745 OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
746 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
747 &pconf, provisionDPCB);
748 if(OC_STACK_OK != rst)
750 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
751 if (OC_STACK_UNAUTHORIZED_REQ == rst)
753 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
757 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
759 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
762 OCDeletePdAclList(pconf.pdacls);
764 // display the PCONF-provisioned result
765 printf(" > SUCCESS to provision Direct-Pairing !!\n");
770 OCDeletePdAclList(pconf.pdacls); // after here |acl| points nothing
774 static int checkLinkedStatus(void)
776 // check |own_list| for checking selected link status on PRVN DB
777 if(!g_own_list || 1>g_own_cnt)
779 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
780 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
781 return 0; // normal case
784 // select device for checking selected link status on PRVN DB
788 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
789 for(int ret=0; 1!=ret; )
791 ret = scanf("%d", &dev_num);
792 for( ; 0x20<=getchar(); ); // for removing overflow garbages
793 // '0x20<=code' is character region
795 if(0<dev_num && g_own_cnt>=dev_num)
799 printf(" Entered Wrong Number. Please Enter Again\n");
802 // call |OCGetLinkedStatus| API actually
803 printf(" Checking Selected Link Status on PRVN DB..\n");
804 OCUuidList_t* dvid_lst = NULL;
806 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
807 if(!dev || !dev->doxm)
809 OIC_LOG(ERROR, TAG, "checkLinkedStatus: device instance empty");
815 &dev->doxm->deviceID,
816 &dvid_lst, &dvid_cnt)) // allow empty list
818 OIC_LOG(ERROR, TAG, "OCGetLinkedStatus API error");
822 // display the linked status result
823 printf(" > Checked Selected Link Status on PRVN DB\n");
824 if(!dvid_lst || !dvid_cnt) // |size_t| is unsigned
826 printf(" Linked Device List is Empty..\n");
827 return 0; // normal case
829 if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
831 OIC_LOG(ERROR, TAG, "printUuidList error return");
834 OCDeleteUuidList(dvid_lst);
839 OCDeleteUuidList(dvid_lst);
843 static int getCred(void)
845 // check |own_list| for checking selected link status on PRVN DB
846 if(!g_own_list || 1>g_own_cnt)
848 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
849 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
850 return 0; // normal case
853 // select device for checking selected link status on PRVN DB
857 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
858 for(int ret=0; 1!=ret; )
860 ret = scanf("%d", &dev_num);
861 for( ; 0x20<=getchar(); ); // for removing overflow garbages
862 // '0x20<=code' is character region
864 if(0<dev_num && g_own_cnt>=dev_num)
868 printf(" Entered Wrong Number. Please Enter Again\n");
871 // call |getDevInst| API actually
872 // calling this API with callback actually acts like blocking
873 // for error checking, the return value saved and printed
875 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
878 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
881 OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
882 if(OC_STACK_OK != rst)
884 OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst);
887 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
889 OIC_LOG(ERROR, TAG, "OCGetCredResource callback error");
893 // display the result of get credential
894 printf(" > Get Cred SUCCEEDED\n");
902 static int getAcl(void)
904 // check |own_list| for checking selected link status on PRVN DB
905 if(!g_own_list || 1>g_own_cnt)
907 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
908 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
909 return 0; // normal case
912 // select device for checking selected link status on PRVN DB
916 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
917 for(int ret=0; 1!=ret; )
919 ret = scanf("%d", &dev_num);
920 for( ; 0x20<=getchar(); ); // for removing overflow garbages
921 // '0x20<=code' is character region
923 if(0<dev_num && g_own_cnt>=dev_num)
927 printf(" Entered Wrong Number. Please Enter Again\n");
930 // call |getDevInst| API actually
931 // calling this API with callback actually acts like blocking
932 // for error checking, the return value saved and printed
934 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
937 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
940 OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
941 if(OC_STACK_OK != rst)
943 OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst);
947 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
949 OIC_LOG(ERROR, TAG, "OCGetACLResource callback error");
953 // display the result of get credential
954 printf(" > Get ACL SUCCEEDED\n");
962 static int unlinkPairwise(void)
964 // check |own_list| for unlinking pairwise devices
965 if(!g_own_list || 2>g_own_cnt)
967 printf(" > Owned Device List, to Unlink the Pairwise, is Empty\n");
968 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
969 return 0; // normal case
972 // select two devices for unlinking pairwise devices
973 int dev_num[2] = {0};
974 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
976 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
980 // call |OCUnlinkDevices| API actually
981 // calling this API with callback actually acts like blocking
982 // for error checking, the return value saved and printed
984 printf(" Unlinking Selected Pairwise Devices..\n");
986 OCUnlinkDevices((void*) g_ctx,
987 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
988 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
990 if(OC_STACK_OK != rst)
992 OIC_LOG_V(ERROR, TAG, "OCUnlinkDevices API error: %d", rst);
995 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
997 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1001 // display the pairwise-unlinked result
1002 printf(" > Unlinked Selected Pairwise Devices\n");
1003 printf(" > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
1008 static int removeDevice(void)
1010 // check |own_list| for removing device
1011 if(!g_own_list || 1>g_own_cnt)
1013 printf(" > Owned Device List, to Remove Device, is Empty\n");
1014 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1015 return 0; // normal case
1018 // select device for removing it
1022 printf(" > Enter Device Number, for Removing Device: ");
1023 for(int ret=0; 1!=ret; )
1025 ret = scanf("%d", &dev_num);
1026 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1027 // '0x20<=code' is character region
1029 if(0<dev_num && g_own_cnt>=dev_num)
1033 printf(" Entered Wrong Number. Please Enter Again\n");
1036 // call |OCRemoveDevice| API actually
1037 // calling this API with callback actually acts like blocking
1038 // for error checking, the return value saved and printed
1040 printf(" Removing Selected Owned Device..\n");
1042 OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
1043 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
1044 if(OC_STACK_OK != rst)
1046 OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst);
1049 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1051 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1055 // display the removed result
1056 printf(" > Removed Selected Owned Device\n");
1057 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1062 static int removeDeviceWithUuid(void)
1064 char strUuid[64] = {0};
1066 printf("Input the UUID : ");
1067 for(int ret=0; 1!=ret; )
1069 ret = scanf("%64s", strUuid);
1070 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1071 // '0x20<=code' is character region
1073 OCStackResult rst = ConvertStrToUuid(strUuid, &revUuid);
1074 if(OC_STACK_OK != rst)
1076 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
1081 rst = OCRemoveDeviceWithUuid("RemoveDeviceWithUUID", DISCOVERY_TIMEOUT, &revUuid, removeDeviceCB);
1082 if(OC_STACK_OK != rst)
1084 OIC_LOG_V(ERROR, TAG, "OCRemoveDeviceWithUuid API error: %d", rst);
1088 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1090 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid callback error");
1094 // display the removed result
1095 printf(" > Removed %s Device\n", strUuid);
1096 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1101 static int resetDevice(void)
1103 // check |own_list| for removing device
1104 if (!g_own_list || 1 > g_own_cnt)
1106 printf(" > Owned Device List, to Reset Device, is Empty\n");
1107 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1111 // select device for removing it
1115 printf(" > Enter Device Number, for Resetting Device: ");
1116 for (int ret = 0; 1 != ret; )
1118 ret = scanf("%d", &dev_num);
1119 for ( ; 0x20 <= getchar() ; ); // for removing overflow garbages
1120 // '0x20 <= code' is character region
1122 if (0 < dev_num && g_own_cnt >= dev_num)
1126 printf(" Entered Wrong Number. Please Enter Again\n");
1130 printf(" Resetting Selected Owned Device..\n");
1132 OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT,
1133 getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB);
1134 if (OC_STACK_OK != rst)
1136 OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst);
1140 if (waitCallbackRet()) // input |g_doneCB| flag implicitly
1142 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1146 // display the removed result
1147 printf(" > Reset Selected Owned Device SUCCEEDED\n");
1148 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1153 static OicSecAcl_t* createAcl(const int dev_num)
1155 if(0>=dev_num || g_own_cnt<dev_num)
1157 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1158 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1161 // allocate memory for |acl| struct
1162 printf(" **** Create ACL for the Selected Device[%d]\n", dev_num);
1163 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
1166 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1167 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1169 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
1172 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1173 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1175 LL_APPEND(acl->aces, ace);
1177 // enter |subject| device number
1181 printf(" > [A] Enter Subject Device Number: ");
1182 for(int ret=0; 1!=ret; )
1184 ret = scanf("%d", &num);
1185 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1186 // '0x20<=code' is character region
1188 if(0<num && g_own_cnt>=num && dev_num!=num)
1192 printf(" Entered Wrong Number. Please Enter Again\n");
1195 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, num);
1196 if(!dev || !dev->doxm)
1198 OIC_LOG(ERROR, TAG, "createAcl: device instance empty");
1201 memcpy(&ace->subjectuuid, &dev->doxm->deviceID, UUID_LENGTH);
1203 // enter number of |resources| in 'accessed' device
1206 printf(" > [B] Enter Number of Accessed Resources (under 16): ");
1207 // '16' is |ACL_RESRC_MAX_NUM|
1208 for(int ret=0; 1!=ret; )
1210 ret = scanf("%d", &num);
1211 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1212 // '0x20<=code' is character region
1214 if(0<num && ACL_RESRC_MAX_NUM>=num)
1218 printf(" Entered Wrong Number. Please Enter under 16 Again\n");
1219 // '16' is |ACL_RESRC_MAX_NUM|
1222 // enter actually each 'accessed' |resources| name
1223 printf(" Enter Each Accessed Resource Name (each under 128 char)\n");
1224 // '128' is ACL_RESRC_MAX_LEN
1226 char rsrc_in[ACL_RESRC_MAX_LEN+1] = {0}; // '1' for null termination
1227 for(int i = 0; num > i; ++i)
1229 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
1232 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1236 printf(" Enter Accessed Resource[%d] Name: (e.g. /a/led)", i+1);
1237 for(int ret=0; 1!=ret; )
1239 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1240 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1241 // '0x20<=code' is character region
1243 size_t len = strlen(rsrc_in)+1; // '1' for null termination
1244 rsrc->href = (char*) OICCalloc(len, sizeof(char));
1247 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1250 OICStrcpy(rsrc->href, len, rsrc_in);
1255 printf(" Enter Number of resource type for [%s] : ", rsrc->href);
1256 for(int ret=0; 1!=ret; )
1258 ret = scanf("%d", &arrLen);
1259 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1260 // '0x20<=code' is character region
1262 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1266 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1269 rsrc->typeLen = arrLen;
1270 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
1273 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1277 for(int i = 0; i < arrLen; i++)
1279 printf(" Enter ResourceType[%d] Name (e.g. core.led): ", i+1);
1280 for(int ret=0; 1!=ret; )
1282 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1283 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1284 // '0x20<=code' is character region
1286 rsrc->types[i] = OICStrdup(rsrc_in);
1289 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1296 printf(" Enter Number of interface for [%s]: ", rsrc->href);
1297 for(int ret=0; 1!=ret; )
1299 ret = scanf("%d", &arrLen);
1300 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1301 // '0x20<=code' is character region
1303 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1307 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1310 rsrc->interfaceLen = arrLen;
1311 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
1312 if(!rsrc->interfaces)
1314 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1318 for(int i = 0; i < arrLen; i++)
1320 printf(" Enter Interface[%d] Name (e.g. oic.if.baseline): ", i+1);
1321 for(int ret=0; 1!=ret; )
1323 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1324 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1325 // '0x20<=code' is character region
1327 rsrc->interfaces[i] = OICStrdup(rsrc_in);
1328 if(!rsrc->interfaces[i])
1330 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1335 LL_APPEND(ace->resources, rsrc);
1338 // enter |permission| for this access
1339 printf(" > [C] Enter Permission for This Access\n");
1340 uint16_t pmsn = PERMISSION_FULL_CONTROL; // default full permission
1341 uint16_t pmsn_msk = PERMISSION_CREATE; // default permission mask
1342 for(int i=0; ACL_PEMISN_CNT>i; ++i)
1347 printf(" Enter %s Permission (y/n): ", ACL_PEMISN[i]);
1348 for(int ret=0; 1!=ret; )
1350 ret = scanf("%c", &ans);
1351 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1352 // '0x20<=code' is character region
1354 if('y'==ans || 'Y'==ans || 'n'==ans|| 'N'==ans)
1356 ans &= ~0x20; // for masking lower case, 'y/n'
1359 printf(" Entered Wrong Answer. Please Enter 'y/n' Again\n");
1361 if('N' == ans) // masked lower case, 'n'
1367 ace->permission = pmsn;
1372 OCDeleteACLList(acl); // after here |acl| points nothing
1376 static OicSecPdAcl_t* createPdAcl(const int dev_num)
1378 if(0>=dev_num || g_own_cnt<dev_num)
1380 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1381 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1384 // allocate memory for |pdacl| struct
1385 printf(" **** Create PDACL for the Selected Device[%d]\n", dev_num);
1386 OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
1389 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1390 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1394 // number of resources
1395 char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
1396 pdAcl->resourcesLen = 1;
1399 int num = pdAcl->resourcesLen;
1400 pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
1401 if(!pdAcl->resources)
1403 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1406 for(int i=0; num>i; ++i)
1408 size_t len = strlen(rsrc_in[i])+1; // '1' for null termination
1409 char* rsrc = (char*) OICCalloc(len, sizeof(char));
1412 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1415 OICStrcpy(rsrc, len, rsrc_in[i]);
1416 pdAcl->resources[i] = rsrc; // after here, |rsrc| points nothing
1420 pdAcl->permission = PERMISSION_FULL_CONTROL;
1425 OCDeletePdAclList(pdAcl);
1429 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
1431 if(!dev_lst || 0>=dev_num)
1433 printf(" Device List is Empty..\n");
1437 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1447 return NULL; // in here |lst| is always |NULL|
1450 static int printDevList(const OCProvisionDev_t* dev_lst)
1454 printf(" Device List is Empty..\n\n");
1458 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1462 printf(" [%d] ", ++lst_cnt);
1463 printUuid((const OicUuid_t*) &lst->doxm->deviceID);
1472 static size_t printUuidList(const OCUuidList_t* uid_lst)
1476 printf(" Device List is Empty..\n\n");
1480 OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
1484 printf(" [%zu] ", ++lst_cnt);
1485 printUuid((const OicUuid_t*) &lst->dev);
1494 static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
1496 if(!rslt_lst || 0>=rslt_cnt)
1498 printf(" Device List is Empty..\n\n");
1503 for( ; rslt_cnt>lst_cnt; ++lst_cnt)
1505 printf(" [%d] ", lst_cnt+1);
1506 printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
1507 printf(" - result: %d\n", rslt_lst[lst_cnt].res);
1514 static void printUuid(const OicUuid_t* uid)
1516 for(int i=0; i<UUID_LENGTH; )
1518 printf("%02X", (*uid).id[i++]);
1519 if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
1526 static FILE* fopen_prvnMng(const char* path, const char* mode)
1528 (void)path; // unused |path| parameter
1530 // input |g_svr_db_fname| internally by force, not using |path| parameter
1531 // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
1532 // with its own |SVR_DB_FILE_NAME|
1533 return fopen(SVR_DB_FILE_NAME, mode);
1536 static int waitCallbackRet(void)
1538 for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
1541 if(OC_STACK_OK != OCProcess())
1543 OIC_LOG(ERROR, TAG, "OCStack process error");
1551 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
1553 if(!a || !b || 2>max || !str)
1560 for(int i=0; 2>i; ++i)
1562 int* num = 0==i?a:b;
1565 printf(" > Enter Device[%d] Number, %s: ", i+1, str);
1566 for(int ret=0; 1!=ret; )
1568 ret = scanf("%d", num);
1569 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1570 // '0x20<=code' is character region
1572 if(0<*num && max>=*num)
1576 printf(" Entered Wrong Number. Please Enter Again\n");
1591 static void setDevProtocol(const OCProvisionDev_t* dev_lst)
1595 printf(" Device List is Empty..\n\n");
1599 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1603 if(2 == secure_protocol)
1605 lst->connType &= ~CT_ADAPTER_IP; //reset IP flag
1606 lst->connType |= CT_ADAPTER_TCP; //set TCP flag
1607 lst->endpoint.adapter = OC_ADAPTER_TCP;
1608 lst->endpoint.port = lst->tcpPort;
1609 lst->securePort = lst->tcpPort;
1615 static void selectSecureProtocol()
1617 printf(" Select protocol\n");
1618 printf(" 1 - DTLS(Default)\n");
1619 printf(" 2 - TLS\n");
1621 for(int ret=0; 1!=ret; )
1623 ret = scanf("%d",&secure_protocol);
1624 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1625 // '0x20<=code' is character region
1628 if(0 >= secure_protocol || 2 < secure_protocol)
1630 secure_protocol = 1;
1633 setDevProtocol(g_own_list);
1634 setDevProtocol(g_unown_list);
1638 static void printMenu(void)
1640 printf("************************************************************\n");
1641 printf("****** OIC Provisioning Client with using C-level API ******\n");
1642 printf("************************************************************\n\n");
1644 printf("** [A] DISCOVER DEVICES ON NETWORK\n");
1645 printf("** 10. Discover All Un/Owned Devices on Network\n");
1646 printf("** 11. Discover Only Unowned Devices on Network\n");
1647 printf("** 12. Discover Only Owned Devices on Network\n\n");
1649 printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n");
1650 printf("** 20. Register/Own All Discovered Unowned Devices\n\n");
1652 printf("** [C] PROVISION/LINK PAIRWISE THINGS\n");
1653 printf("** 30. Provision/Link Pairwise Things\n");
1654 printf("** 31. Provision Credentials for Pairwise Things\n");
1655 printf("** 32. Provision the Selected Access Control List(ACL)\n");
1656 printf("** 33. Provision Direct-Pairing Configuration\n");
1657 printf("** 34. Check Linked Status of the Selected Device on PRVN DB\n\n");
1659 printf("** [D] UNLINK PAIRWISE THINGS\n");
1660 printf("** 40. Unlink Pairwise Things\n\n");
1662 printf("** [E] REMOVE THE SELECTED DEVICE\n");
1663 printf("** 50. Remove the Selected Device\n");
1664 printf("** 51. Remove Device with UUID (UUID input is required)\n");
1665 printf("** 52. Reset the Selected Device\n\n");
1667 printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n");
1668 printf("** 60. Get the Credential resources of the Selected Device\n");
1669 printf("** 61. Get the ACL resources of the Selected Device\n\n");
1671 printf("** [F] SELECT SECURE PROTOCOL DTLS/TLS\n");
1672 printf("** 70. Select secure protocol(default DTLS)\n\n");
1674 printf("** [F] EXIT PROVISIONING CLIENT\n");
1675 printf("** 99. Exit Provisionong Client\n\n");
1677 printf("************************************************************\n\n");
1680 #if 0 // Code for enabling path configuration for PDB and SVR DBf
1681 static void printUsage(void)
1684 printf("OIC Provisioning Client with using C-level API\n");
1685 printf("Usage: provisioningclient [option]...\n");
1687 printf(" -h print help for this provisioning client\n");
1688 printf(" -p=[prvn_db_file_path/name] input PRVN DB file path and name\n");
1689 printf(" if not exists, will load default DB file\n");
1690 printf(" (default: |oic_prvn_mng.db| on working dir)\n");
1691 printf(" (ex. -p=oic_prvn_mng.db)\n");
1692 printf(" -s=[svr_db_file_path/name] input SVR DB file path and name\n");
1693 printf(" if not exists, will load default DB file\n");
1694 printf(" (default: |oic_svr_db_client.json| on working dir)\n");
1695 printf(" (ex. -s=oic_svr_db_client.json)\n");
1700 // main function for provisioning client using C-level provisioning API
1703 // initialize provisioning client
1704 if(initProvisionClient())
1706 OIC_LOG(ERROR, TAG, "ProvisionClient init error");
1710 // main loop for provisioning manager
1716 printf(">> Enter Menu Number: ");
1717 for(int ret=0; 1!=ret; )
1719 ret = scanf("%d", &mn_num);
1720 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1721 // '0x20<=code' is character region
1726 case _10_DISCOV_ALL_DEVS_:
1727 if(discoverAllDevices())
1729 OIC_LOG(ERROR, TAG, "_10_DISCOV_ALL_DEVS_: error");
1732 case _11_DISCOV_UNOWN_DEVS_:
1733 if(discoverUnownedDevices())
1735 OIC_LOG(ERROR, TAG, "_11_DISCOV_UNOWN_DEVS_: error");
1738 case _12_DISCOV_OWN_DEVS_:
1739 if(discoverOwnedDevices())
1741 OIC_LOG(ERROR, TAG, "_12_DISCOV_OWN_DEVS_: error");
1744 case _20_REGIST_DEVS_:
1745 if(registerDevices())
1747 OIC_LOG(ERROR, TAG, "_20_REGIST_DEVS_: error");
1750 case _30_PROVIS_PAIR_DEVS_:
1751 if(provisionPairwise())
1753 OIC_LOG(ERROR, TAG, "_30_PROVIS_PAIR_DEVS_: error");
1756 case _31_PROVIS_CRED_:
1759 OIC_LOG(ERROR, TAG, "_31_PROVIS_CRED_: error");
1762 case _32_PROVIS_ACL_:
1765 OIC_LOG(ERROR, TAG, "_32_PROVIS_ACL_: error");
1768 case _33_PROVIS_DP_:
1769 if(provisionDirectPairing())
1771 OIC_LOG(ERROR, TAG, "_33_PROVIS_DP_: error");
1774 case _34_CHECK_LINK_STATUS_:
1775 if(checkLinkedStatus())
1777 OIC_LOG(ERROR, TAG, "_34_CHECK_LINK_STATUS_: error");
1780 case _40_UNLINK_PAIR_DEVS_:
1781 if(unlinkPairwise())
1783 OIC_LOG(ERROR, TAG, "_40_UNLINK_PAIR_DEVS_: error");
1786 case _50_REMOVE_SELEC_DEV_:
1789 OIC_LOG(ERROR, TAG, "_50_REMOVE_SELEC_DEV_: error");
1792 case _51_REMOVE_DEV_WITH_UUID_:
1793 if(removeDeviceWithUuid())
1795 OIC_LOG(ERROR, TAG, "_51_REMOVE_DEV_WITH_UUID_: error");
1798 case _52_RESET_SELEC_DEV_:
1801 OIC_LOG(ERROR, TAG, "_52_RESET_SELEC_DEV_: error");
1807 OIC_LOG(ERROR, TAG, "_60_GET_CRED_: error");
1813 OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error");
1817 case _70_SELECT_PROTOCOL_:
1818 selectSecureProtocol();
1821 case _99_EXIT_PRVN_CLT_:
1824 printf(">> Entered Wrong Number. Please Enter Again\n\n");
1830 if(OC_STACK_OK != OCStop())
1832 OIC_LOG(ERROR, TAG, "OCStack stop error");
1834 OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
1835 OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
1839 OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
1843 OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
1845 return 0; // always return normal case
1850 #endif //__cplusplus