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 "platform_features.h"
30 #include "oic_malloc.h"
31 #include "oic_string.h"
32 #include "ocprovisioningmanager.h"
33 #include "oxmjustworks.h"
34 #include "oxmrandompin.h"
35 #include "securevirtualresourcetypes.h"
36 #include "srmutility.h"
44 // declaration(s) for provisioning client using C-level provisioning API
45 // user input definition for main loop on provisioning client
46 #define _10_DISCOV_ALL_DEVS_ 10
47 #define _11_DISCOV_UNOWN_DEVS_ 11
48 #define _12_DISCOV_OWN_DEVS_ 12
49 #define _20_REGIST_DEVS_ 20
50 #define _30_PROVIS_PAIR_DEVS_ 30
51 #define _31_PROVIS_CRED_ 31
52 #define _32_PROVIS_ACL_ 32
53 #define _33_PROVIS_DP_ 33
54 #define _34_CHECK_LINK_STATUS_ 34
55 #define _40_UNLINK_PAIR_DEVS_ 40
56 #define _50_REMOVE_SELEC_DEV_ 50
57 #define _51_REMOVE_DEV_WITH_UUID_ 51
58 #define _52_RESET_SELEC_DEV_ 52
59 #define _60_GET_CRED_ 60
60 #define _61_GET_ACL_ 61
61 #define _70_SELECT_PROTOCOL_ 70
62 #define _99_EXIT_PRVN_CLT_ 99
64 #define ACL_RESRC_MAX_NUM 16
65 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
66 #define ACL_RESRC_MAX_LEN 128
67 #define ACL_PEMISN_CNT 5
68 #define DISCOVERY_TIMEOUT 10 // 10 sec
69 #define CALLBACK_TIMEOUT 60 // 1 min
70 #define TAG "provisioningclient"
72 static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
73 static const char* SVR_DB_FILE_NAME = "oic_svr_db_client.dat";
74 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
75 static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
76 static const OicSecPrm_t SUPPORTED_PRMS[1] =
81 // |g_ctx| means provision manager application context and
82 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
83 // for accessing all function(s) for these, they are declared on global domain
84 static const char* g_ctx = "Provision Manager Client Application Context";
85 static char* g_svr_fname;
86 static char* g_prvn_fname;
87 static OCProvisionDev_t* g_own_list;
88 static OCProvisionDev_t* g_unown_list;
90 static int g_unown_cnt;
93 static int secure_protocol = 1;
94 static void setDevProtocol(const OCProvisionDev_t* dev_lst);
96 // function declaration(s) for calling them before implementing
97 static OicSecAcl_t* createAcl(const int);
98 static OicSecPdAcl_t* createPdAcl(const int);
99 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
100 static int printDevList(const OCProvisionDev_t*);
101 static size_t printUuidList(const OCUuidList_t*);
102 static int printResultList(const OCProvisionResult_t*, const int);
103 static void printUuid(const OicUuid_t*);
104 static FILE* fopen_prvnMng(const char*, const char*);
105 static int waitCallbackRet(void);
106 static int selectTwoDiffNum(int*, int*, const int, const char*);
108 // callback function(s) for provisioning client using C-level provisioning API
109 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
113 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
117 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
118 printResultList((const OCProvisionResult_t*) arr, nOfRes);
123 static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
127 OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
131 OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
132 printResultList((const OCProvisionResult_t*) arr, nOfRes);
137 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
141 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
145 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
146 printResultList((const OCProvisionResult_t*) arr, nOfRes);
151 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
155 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
159 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
160 printResultList((const OCProvisionResult_t*) arr, nOfRes);
165 static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
169 OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
173 OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx);
174 printResultList((const OCProvisionResult_t*) arr, nOfRes);
179 static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
183 OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
187 OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx);
188 printResultList((const OCProvisionResult_t*) arr, nOfRes);
193 static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
197 OIC_LOG_V(INFO, TAG, "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
201 OIC_LOG_V(ERROR, TAG, "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
202 printResultList((const OCProvisionResult_t*) arr, nOfRes);
207 static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
211 OIC_LOG_V(INFO, TAG, "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
215 OIC_LOG_V(ERROR, TAG, "Unlink Devices FAILED - ctx: %s", (char*) ctx);
216 printResultList((const OCProvisionResult_t*) arr, nOfRes);
221 static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
225 OIC_LOG_V(INFO, TAG, "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
229 OIC_LOG_V(ERROR, TAG, "Remove Device FAILED - ctx: %s", (char*) ctx);
230 printResultList((const OCProvisionResult_t*) arr, nOfRes);
235 static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
239 OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx);
243 OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx);
244 printResultList((const OCProvisionResult_t*) arr, nOfRes);
249 static void inputPinCB(char* pin, size_t len)
251 if(!pin || OXM_RANDOM_PIN_SIZE>=len)
253 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
257 printf(" > INPUT PIN: ");
258 for(int ret=0; 1!=ret; )
260 ret = scanf("%8s", pin);
261 for( ; 0x20<=getchar(); ); // for removing overflow garbages
262 // '0x20<=code' is character region
266 // function(s) for provisioning client using C-level provisioning API
267 static int initProvisionClient(void)
269 // initialize persistent storage for SVR DB
270 static OCPersistentStorage pstStr =
272 .open = fopen_prvnMng,
278 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
280 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
284 // initialize OC stack and provisioning manager
285 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
287 OIC_LOG(ERROR, TAG, "OCStack init error");
291 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
293 printf("************************************************************\n");
294 printf("************Provisioning DB file already exists.************\n");
295 printf("************************************************************\n");
299 printf("*************************************************************\n");
300 printf("************No provisioning DB file, creating new************\n");
301 printf("*************************************************************\n");
304 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
306 OIC_LOG(ERROR, TAG, "OC_PM init error");
310 // register callback function(s) to each OxM
311 OTMCallbackData_t otmcb =
313 .loadSecretCB = LoadSecretJustWorksCallback,
314 .createSecureSessionCB = CreateSecureSessionJustWorksCallback,
315 .createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload,
316 .createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload
318 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb))
320 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_JUST_WORKS");
323 otmcb.loadSecretCB = InputPinCodeCallback;
324 otmcb.createSecureSessionCB = CreateSecureSessionRandomPinCallback;
325 otmcb.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
326 otmcb.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
327 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_RANDOM_DEVICE_PIN, &otmcb))
329 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_RANDOM_DEVICE_PIN");
332 SetInputPinCB(inputPinCB);
337 static int discoverAllDevices(void)
339 // delete un/owned device lists before updating them
342 OCDeleteDiscoveredDevices(g_own_list);
347 OCDeleteDiscoveredDevices(g_unown_list);
351 // call |OCGetDevInfoFromNetwork| API actually
352 printf(" Discovering All Un/Owned Devices on Network..\n");
353 if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
355 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error");
359 // display the discovered un/owned lists
360 printf(" > Discovered Owned Devices\n");
361 g_own_cnt = printDevList(g_own_list);
362 printf(" > Discovered Unowned Devices\n");
363 g_unown_cnt = printDevList(g_unown_list);
365 setDevProtocol(g_own_list);
366 setDevProtocol(g_unown_list);
372 static int discoverUnownedDevices(void)
374 // delete unowned device list before updating it
377 OCDeleteDiscoveredDevices(g_unown_list);
381 // call |OCDiscoverUnownedDevices| API actually
382 printf(" Discovering Only Unowned Devices on Network..\n");
383 if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
385 OIC_LOG(ERROR, TAG, "OCDiscoverUnownedDevices API error");
389 // display the discovered unowned list
390 printf(" > Discovered Unowned Devices\n");
391 g_unown_cnt = printDevList(g_unown_list);
393 setDevProtocol(g_unown_list);
398 static int discoverOwnedDevices(void)
400 // delete owned device list before updating it
403 OCDeleteDiscoveredDevices(g_own_list);
407 // call |OCDiscoverOwnedDevices| API actually
408 printf(" Discovering Only Owned Devices on Network..\n");
409 if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
411 OIC_LOG(ERROR, TAG, "OCDiscoverOwnedDevices API error");
415 // display the discovered owned list
416 printf(" > Discovered Owned Devices\n");
417 g_own_cnt = printDevList(g_own_list);
419 setDevProtocol(g_own_list);
424 static int registerDevices(void)
426 // check |unown_list| for registering devices
427 if(!g_unown_list || 0>=g_unown_cnt)
429 printf(" > Unowned Device List, to Register Devices, is Empty\n");
430 printf(" > Please Discover Unowned Devices first, with [10|11] Menu\n");
431 return 0; // normal case
434 // call |OCDoOwnershipTransfer| API actually
435 // calling this API with callback actually acts like blocking
436 // for error checking, the return value saved and printed
438 printf(" Registering All Discovered Unowned Devices..\n");
439 OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
440 if(OC_STACK_OK != rst)
442 OIC_LOG_V(ERROR, TAG, "OCDoOwnershipTransfer API error: %d", rst);
445 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
447 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
451 // display the registered result
452 printf(" > Registered Discovered Unowned Devices\n");
453 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
458 static int provisionPairwise(void)
460 // check |own_list| for provisioning pairwise devices
461 if(!g_own_list || 2>g_own_cnt)
463 printf(" > Owned Device List, to Provision the Pairwise, is Empty\n");
464 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
465 return 0; // normal case
468 // select two devices for provisioning pairwise devices
469 int dev_num[2] = {0};
470 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
472 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
473 return -1; // not need to 'goto' |ERROR| before allocating |acl|
476 // create ACL(s) for each selected device
477 OicSecAcl_t* acl[2] = {0};
478 for(int i=0; 2>i; ++i)
480 acl[i] = createAcl(dev_num[i]);
483 OIC_LOG(ERROR, TAG, "createAcl error return");
488 // call |OCProvisionPairwiseDevices| API actually
489 // calling this API with callback actually acts like blocking
490 // for error checking, the return value saved and printed
492 printf(" Provisioning Selected Pairwise Devices..\n");
494 OCProvisionPairwiseDevices((void*) g_ctx,
495 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
496 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
497 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
498 provisionPairwiseCB);
499 if(OC_STACK_OK != rst)
501 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
504 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
506 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
509 OCDeleteACLList(acl[0]);
510 OCDeleteACLList(acl[1]);
512 // display the pairwise-provisioned result
513 printf(" > Provisioned Selected Pairwise Devices\n");
514 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
519 OCDeleteACLList(acl[0]);
520 OCDeleteACLList(acl[1]);
524 static int provisionCred(void)
526 // check |own_list| for provisioning pairwise credentials
527 if(!g_own_list || 2>g_own_cnt)
529 printf(" > Owned Device List, to Provision Credentials, is Empty\n");
530 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
531 return 0; // normal case
534 // select two devices for provisioning pairwise credentials
535 int dev_num[2] = {0};
536 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
538 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
542 printf(" Select PSK length..\n");
543 printf(" 1 - 128bit(Default)\n");
544 printf(" 2 - 256bit\n");
547 for(int ret=0; 1!=ret; )
549 ret = scanf("%d",&sizeOption);
550 for( ; 0x20<=getchar(); ); // for removing overflow garbages
551 // '0x20<=code' is character region
559 size = OWNER_PSK_LENGTH_128;
564 size = OWNER_PSK_LENGTH_256;
569 size = OWNER_PSK_LENGTH_128;
575 // call |OCProvisionCredentials| API actually
576 // calling this API with callback actually acts like blocking
577 // for error checking, the return value saved and printed
579 printf(" Provisioning Selected Pairwise Credentials..\n");
581 OCProvisionCredentials((void*) g_ctx,
582 SYMMETRIC_PAIR_WISE_KEY, size,
583 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
584 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
586 if(OC_STACK_OK != rst)
588 OIC_LOG_V(ERROR, TAG, "OCProvisionCredentials API error: %d", rst);
591 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
593 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
597 // display the CRED-provisioned result
598 printf(" > Provisioned Selected Pairwise Crendentials\n");
599 printf(" > Please Check Device's Status for the Linked Result, with [34] Menu\n");
604 static int provisionAcl(void)
606 // check |own_list| for provisioning access control list
607 if(!g_own_list || 1>g_own_cnt)
609 printf(" > Owned Device List, to Provision ACL, is Empty\n");
610 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
611 return 0; // normal case
614 // select device for provisioning access control list
618 printf(" > Enter Device Number, for Provisioning ACL: ");
619 for(int ret=0; 1!=ret; )
621 ret = scanf("%d", &dev_num);
622 for( ; 0x20<=getchar(); ); // for removing overflow garbages
623 // '0x20<=code' is character region
625 if(0<dev_num && g_own_cnt>=dev_num)
629 printf(" Entered Wrong Number. Please Enter Again\n");
632 // create ACL for selected device
633 OicSecAcl_t* acl = NULL;
634 acl = createAcl(dev_num);
637 OIC_LOG(ERROR, TAG, "createAcl error return");
641 // call |OCProvisionACL| API actually
642 // calling this API with callback actually acts like blocking
643 // for error checking, the return value saved and printed
645 printf(" Provisioning Selected ACL..\n");
646 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
649 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
652 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
653 if(OC_STACK_OK != rst)
655 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
658 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
660 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
663 OCDeleteACLList(acl); // after here |acl| points nothing
665 // display the ACL-provisioned result
666 printf(" > Provisioned Selected ACL\n");
671 OCDeleteACLList(acl); // after here |acl| points nothing
675 static int provisionDirectPairing(void)
677 // check |own_list| for provisioning direct-pairing
678 if(!g_own_list || 1>g_own_cnt)
680 printf(" > Owned Device List, to Provision ACL, is Empty\n");
681 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
682 return 0; // normal case
685 // select device for provisioning direct-pairing
689 printf(" > Enter Device Number, for Provisioning Direct-Pairing: ");
690 for(int ret=0; 1!=ret; )
692 ret = scanf("%d", &dev_num);
693 for( ; 0x20<=getchar(); ); // for removing overflow garbages
694 // '0x20<=code' is character region
696 if(0<dev_num && g_own_cnt>=dev_num)
700 printf(" Entered Wrong Number. Please Enter Again\n");
703 // create Direct-Pairing Configuration(PIN, PDACL) for selected device
704 // TODO: default acl -> input from user !
706 memset(&pconf, 0, sizeof(OicSecPconf_t));
711 // set default supported PRM types
712 pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
713 pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
716 for (size_t i=0; i<pconf.prmLen; i++)
718 pconf.prm[i] = SUPPORTED_PRMS[i];
723 OIC_LOG(ERROR, TAG, "create prm error return");
728 const char DP_DEFAULT_PIN[] = "00000000";
729 memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
732 pconf.pdacls = createPdAcl(dev_num);
735 OIC_LOG(ERROR, TAG, "createPdAcl error return");
739 // call |OCProvisionDirectPairing| API actually
740 // calling this API with callback actually acts like blocking
741 // for error checking, the return value saved and printed
743 printf(" Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
744 OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
745 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
746 &pconf, provisionDPCB);
747 if(OC_STACK_OK != rst)
749 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
750 if (OC_STACK_UNAUTHORIZED_REQ == rst)
752 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
756 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
758 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
761 OCDeletePdAclList(pconf.pdacls);
763 // display the PCONF-provisioned result
764 printf(" > SUCCESS to provision Direct-Pairing !!\n");
769 OCDeletePdAclList(pconf.pdacls); // after here |acl| points nothing
773 static int checkLinkedStatus(void)
775 // check |own_list| for checking selected link status on PRVN DB
776 if(!g_own_list || 1>g_own_cnt)
778 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
779 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
780 return 0; // normal case
783 // select device for checking selected link status on PRVN DB
787 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
788 for(int ret=0; 1!=ret; )
790 ret = scanf("%d", &dev_num);
791 for( ; 0x20<=getchar(); ); // for removing overflow garbages
792 // '0x20<=code' is character region
794 if(0<dev_num && g_own_cnt>=dev_num)
798 printf(" Entered Wrong Number. Please Enter Again\n");
801 // call |OCGetLinkedStatus| API actually
802 printf(" Checking Selected Link Status on PRVN DB..\n");
803 OCUuidList_t* dvid_lst = NULL;
805 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
806 if(!dev || !dev->doxm)
808 OIC_LOG(ERROR, TAG, "checkLinkedStatus: device instance empty");
814 &dev->doxm->deviceID,
815 &dvid_lst, &dvid_cnt)) // allow empty list
817 OIC_LOG(ERROR, TAG, "OCGetLinkedStatus API error");
821 // display the linked status result
822 printf(" > Checked Selected Link Status on PRVN DB\n");
823 if(!dvid_lst || !dvid_cnt) // |size_t| is unsigned
825 printf(" Linked Device List is Empty..\n");
826 return 0; // normal case
828 if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
830 OIC_LOG(ERROR, TAG, "printUuidList error return");
833 OCDeleteUuidList(dvid_lst);
838 OCDeleteUuidList(dvid_lst);
842 static int getCred(void)
844 // check |own_list| for checking selected link status on PRVN DB
845 if(!g_own_list || 1>g_own_cnt)
847 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
848 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
849 return 0; // normal case
852 // select device for checking selected link status on PRVN DB
856 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
857 for(int ret=0; 1!=ret; )
859 ret = scanf("%d", &dev_num);
860 for( ; 0x20<=getchar(); ); // for removing overflow garbages
861 // '0x20<=code' is character region
863 if(0<dev_num && g_own_cnt>=dev_num)
867 printf(" Entered Wrong Number. Please Enter Again\n");
870 // call |getDevInst| API actually
871 // calling this API with callback actually acts like blocking
872 // for error checking, the return value saved and printed
874 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
877 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
880 OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
881 if(OC_STACK_OK != rst)
883 OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst);
886 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
888 OIC_LOG(ERROR, TAG, "OCGetCredResource callback error");
892 // display the result of get credential
893 printf(" > Get Cred SUCCEEDED\n");
901 static int getAcl(void)
903 // check |own_list| for checking selected link status on PRVN DB
904 if(!g_own_list || 1>g_own_cnt)
906 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
907 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
908 return 0; // normal case
911 // select device for checking selected link status on PRVN DB
915 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
916 for(int ret=0; 1!=ret; )
918 ret = scanf("%d", &dev_num);
919 for( ; 0x20<=getchar(); ); // for removing overflow garbages
920 // '0x20<=code' is character region
922 if(0<dev_num && g_own_cnt>=dev_num)
926 printf(" Entered Wrong Number. Please Enter Again\n");
929 // call |getDevInst| API actually
930 // calling this API with callback actually acts like blocking
931 // for error checking, the return value saved and printed
933 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
936 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
939 OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
940 if(OC_STACK_OK != rst)
942 OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst);
946 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
948 OIC_LOG(ERROR, TAG, "OCGetACLResource callback error");
952 // display the result of get credential
953 printf(" > Get ACL SUCCEEDED\n");
961 static int unlinkPairwise(void)
963 // check |own_list| for unlinking pairwise devices
964 if(!g_own_list || 2>g_own_cnt)
966 printf(" > Owned Device List, to Unlink the Pairwise, is Empty\n");
967 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
968 return 0; // normal case
971 // select two devices for unlinking pairwise devices
972 int dev_num[2] = {0};
973 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
975 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
979 // call |OCUnlinkDevices| API actually
980 // calling this API with callback actually acts like blocking
981 // for error checking, the return value saved and printed
983 printf(" Unlinking Selected Pairwise Devices..\n");
985 OCUnlinkDevices((void*) g_ctx,
986 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
987 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
989 if(OC_STACK_OK != rst)
991 OIC_LOG_V(ERROR, TAG, "OCUnlinkDevices API error: %d", rst);
994 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
996 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1000 // display the pairwise-unlinked result
1001 printf(" > Unlinked Selected Pairwise Devices\n");
1002 printf(" > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
1007 static int removeDevice(void)
1009 // check |own_list| for removing device
1010 if(!g_own_list || 1>g_own_cnt)
1012 printf(" > Owned Device List, to Remove Device, is Empty\n");
1013 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1014 return 0; // normal case
1017 // select device for removing it
1021 printf(" > Enter Device Number, for Removing Device: ");
1022 for(int ret=0; 1!=ret; )
1024 ret = scanf("%d", &dev_num);
1025 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1026 // '0x20<=code' is character region
1028 if(0<dev_num && g_own_cnt>=dev_num)
1032 printf(" Entered Wrong Number. Please Enter Again\n");
1035 // call |OCRemoveDevice| API actually
1036 // calling this API with callback actually acts like blocking
1037 // for error checking, the return value saved and printed
1039 printf(" Removing Selected Owned Device..\n");
1041 OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
1042 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
1043 if(OC_STACK_OK != rst)
1045 OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst);
1048 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1050 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1054 // display the removed result
1055 printf(" > Removed Selected Owned Device\n");
1056 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1061 static int removeDeviceWithUuid(void)
1063 char strUuid[64] = {0};
1065 printf("Input the UUID : ");
1066 for(int ret=0; 1!=ret; )
1068 ret = scanf("%64s", strUuid);
1069 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1070 // '0x20<=code' is character region
1072 OCStackResult rst = ConvertStrToUuid(strUuid, &revUuid);
1073 if(OC_STACK_OK != rst)
1075 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
1080 rst = OCRemoveDeviceWithUuid("RemoveDeviceWithUUID", DISCOVERY_TIMEOUT, &revUuid, removeDeviceCB);
1081 if(OC_STACK_OK != rst)
1083 OIC_LOG_V(ERROR, TAG, "OCRemoveDeviceWithUuid API error: %d", rst);
1087 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1089 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid callback error");
1093 // display the removed result
1094 printf(" > Removed %s Device\n", strUuid);
1095 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1100 static int resetDevice(void)
1102 // check |own_list| for removing device
1103 if (!g_own_list || 1 > g_own_cnt)
1105 printf(" > Owned Device List, to Reset Device, is Empty\n");
1106 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1110 // select device for removing it
1114 printf(" > Enter Device Number, for Resetting Device: ");
1115 for (int ret = 0; 1 != ret; )
1117 ret = scanf("%d", &dev_num);
1118 for ( ; 0x20 <= getchar() ; ); // for removing overflow garbages
1119 // '0x20 <= code' is character region
1121 if (0 < dev_num && g_own_cnt >= dev_num)
1125 printf(" Entered Wrong Number. Please Enter Again\n");
1129 printf(" Resetting Selected Owned Device..\n");
1131 OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT,
1132 getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB);
1133 if (OC_STACK_OK != rst)
1135 OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst);
1139 if (waitCallbackRet()) // input |g_doneCB| flag implicitly
1141 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1145 // display the removed result
1146 printf(" > Reset Selected Owned Device SUCCEEDED\n");
1147 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1152 static OicSecAcl_t* createAcl(const int dev_num)
1154 if(0>=dev_num || g_own_cnt<dev_num)
1156 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1157 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1160 // allocate memory for |acl| struct
1161 printf(" **** Create ACL for the Selected Device[%d]\n", dev_num);
1162 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
1165 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1166 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1168 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
1171 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1172 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1174 LL_APPEND(acl->aces, ace);
1176 // enter |subject| device number
1180 printf(" > [A] Enter Subject Device Number: ");
1181 for(int ret=0; 1!=ret; )
1183 ret = scanf("%d", &num);
1184 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1185 // '0x20<=code' is character region
1187 if(0<num && g_own_cnt>=num && dev_num!=num)
1191 printf(" Entered Wrong Number. Please Enter Again\n");
1194 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, num);
1195 if(!dev || !dev->doxm)
1197 OIC_LOG(ERROR, TAG, "createAcl: device instance empty");
1200 memcpy(&ace->subjectuuid, &dev->doxm->deviceID, UUID_LENGTH);
1202 // enter number of |resources| in 'accessed' device
1205 printf(" > [B] Enter Number of Accessed Resources (under 16): ");
1206 // '16' is |ACL_RESRC_MAX_NUM|
1207 for(int ret=0; 1!=ret; )
1209 ret = scanf("%d", &num);
1210 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1211 // '0x20<=code' is character region
1213 if(0<num && ACL_RESRC_MAX_NUM>=num)
1217 printf(" Entered Wrong Number. Please Enter under 16 Again\n");
1218 // '16' is |ACL_RESRC_MAX_NUM|
1221 // enter actually each 'accessed' |resources| name
1222 printf(" Enter Each Accessed Resource Name (each under 128 char)\n");
1223 // '128' is ACL_RESRC_MAX_LEN
1225 char rsrc_in[ACL_RESRC_MAX_LEN+1] = {0}; // '1' for null termination
1226 for(int i = 0; num > i; ++i)
1228 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
1231 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1235 printf(" Enter Accessed Resource[%d] Name: (e.g. /a/led)", i+1);
1236 for(int ret=0; 1!=ret; )
1238 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1239 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1240 // '0x20<=code' is character region
1242 size_t len = strlen(rsrc_in)+1; // '1' for null termination
1243 rsrc->href = (char*) OICCalloc(len, sizeof(char));
1246 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1249 OICStrcpy(rsrc->href, len, rsrc_in);
1254 printf(" Enter Number of resource type for [%s] : ", rsrc->href);
1255 for(int ret=0; 1!=ret; )
1257 ret = scanf("%d", &arrLen);
1258 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1259 // '0x20<=code' is character region
1261 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1265 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1268 rsrc->typeLen = arrLen;
1269 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
1272 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1276 for(int i = 0; i < arrLen; i++)
1278 printf(" Enter ResourceType[%d] Name (e.g. core.led): ", i+1);
1279 for(int ret=0; 1!=ret; )
1281 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1282 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1283 // '0x20<=code' is character region
1285 rsrc->types[i] = OICStrdup(rsrc_in);
1288 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1295 printf(" Enter Number of interface for [%s]: ", rsrc->href);
1296 for(int ret=0; 1!=ret; )
1298 ret = scanf("%d", &arrLen);
1299 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1300 // '0x20<=code' is character region
1302 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1306 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1309 rsrc->interfaceLen = arrLen;
1310 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
1311 if(!rsrc->interfaces)
1313 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1317 for(int i = 0; i < arrLen; i++)
1319 printf(" Enter Interface[%d] Name (e.g. oic.if.baseline): ", i+1);
1320 for(int ret=0; 1!=ret; )
1322 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1323 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1324 // '0x20<=code' is character region
1326 rsrc->interfaces[i] = OICStrdup(rsrc_in);
1327 if(!rsrc->interfaces[i])
1329 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1334 LL_APPEND(ace->resources, rsrc);
1337 // enter |permission| for this access
1338 printf(" > [C] Enter Permission for This Access\n");
1339 uint16_t pmsn = PERMISSION_FULL_CONTROL; // default full permission
1340 uint16_t pmsn_msk = PERMISSION_CREATE; // default permission mask
1341 for(int i=0; ACL_PEMISN_CNT>i; ++i)
1346 printf(" Enter %s Permission (y/n): ", ACL_PEMISN[i]);
1347 for(int ret=0; 1!=ret; )
1349 ret = scanf("%c", &ans);
1350 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1351 // '0x20<=code' is character region
1353 if('y'==ans || 'Y'==ans || 'n'==ans|| 'N'==ans)
1355 ans &= ~0x20; // for masking lower case, 'y/n'
1358 printf(" Entered Wrong Answer. Please Enter 'y/n' Again\n");
1360 if('N' == ans) // masked lower case, 'n'
1366 ace->permission = pmsn;
1371 OCDeleteACLList(acl); // after here |acl| points nothing
1375 static OicSecPdAcl_t* createPdAcl(const int dev_num)
1377 if(0>=dev_num || g_own_cnt<dev_num)
1379 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1380 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1383 // allocate memory for |pdacl| struct
1384 printf(" **** Create PDACL for the Selected Device[%d]\n", dev_num);
1385 OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
1388 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1389 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1393 // number of resources
1394 char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
1395 pdAcl->resourcesLen = 1;
1398 int num = pdAcl->resourcesLen;
1399 pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
1400 if(!pdAcl->resources)
1402 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1405 for(int i=0; num>i; ++i)
1407 size_t len = strlen(rsrc_in[i])+1; // '1' for null termination
1408 char* rsrc = (char*) OICCalloc(len, sizeof(char));
1411 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1414 OICStrcpy(rsrc, len, rsrc_in[i]);
1415 pdAcl->resources[i] = rsrc; // after here, |rsrc| points nothing
1419 pdAcl->permission = PERMISSION_FULL_CONTROL;
1424 OCDeletePdAclList(pdAcl);
1428 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
1430 if(!dev_lst || 0>=dev_num)
1432 printf(" Device List is Empty..\n");
1436 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1446 return NULL; // in here |lst| is always |NULL|
1449 static int printDevList(const OCProvisionDev_t* dev_lst)
1453 printf(" Device List is Empty..\n\n");
1457 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1461 printf(" [%d] ", ++lst_cnt);
1462 printUuid((const OicUuid_t*) &lst->doxm->deviceID);
1471 static size_t printUuidList(const OCUuidList_t* uid_lst)
1475 printf(" Device List is Empty..\n\n");
1479 OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
1483 printf(" [%zu] ", ++lst_cnt);
1484 printUuid((const OicUuid_t*) &lst->dev);
1493 static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
1495 if(!rslt_lst || 0>=rslt_cnt)
1497 printf(" Device List is Empty..\n\n");
1502 for( ; rslt_cnt>lst_cnt; ++lst_cnt)
1504 printf(" [%d] ", lst_cnt+1);
1505 printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
1506 printf(" - result: %d\n", rslt_lst[lst_cnt].res);
1513 static void printUuid(const OicUuid_t* uid)
1515 for(int i=0; i<UUID_LENGTH; )
1517 printf("%02X", (*uid).id[i++]);
1518 if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
1525 static FILE* fopen_prvnMng(const char* path, const char* mode)
1527 (void)path; // unused |path| parameter
1529 // input |g_svr_db_fname| internally by force, not using |path| parameter
1530 // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
1531 // with its own |SVR_DB_FILE_NAME|
1532 return fopen(SVR_DB_FILE_NAME, mode);
1535 static int waitCallbackRet(void)
1537 for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
1540 if(OC_STACK_OK != OCProcess())
1542 OIC_LOG(ERROR, TAG, "OCStack process error");
1550 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
1552 if(!a || !b || 2>max || !str)
1559 for(int i=0; 2>i; ++i)
1561 int* num = 0==i?a:b;
1564 printf(" > Enter Device[%d] Number, %s: ", i+1, str);
1565 for(int ret=0; 1!=ret; )
1567 ret = scanf("%d", num);
1568 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1569 // '0x20<=code' is character region
1571 if(0<*num && max>=*num)
1575 printf(" Entered Wrong Number. Please Enter Again\n");
1590 static void setDevProtocol(const OCProvisionDev_t* dev_lst)
1594 printf(" Device List is Empty..\n\n");
1598 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1602 if(2 == secure_protocol)
1604 lst->connType &= ~CT_ADAPTER_IP; //reset IP flag
1605 lst->connType |= CT_ADAPTER_TCP; //set TCP flag
1606 lst->endpoint.adapter = OC_ADAPTER_TCP;
1607 lst->endpoint.port = lst->tcpPort;
1608 lst->securePort = lst->tcpPort;
1614 static void selectSecureProtocol()
1616 printf(" Select protocol\n");
1617 printf(" 1 - DTLS(Default)\n");
1618 printf(" 2 - TLS\n");
1620 for(int ret=0; 1!=ret; )
1622 ret = scanf("%d",&secure_protocol);
1623 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1624 // '0x20<=code' is character region
1627 if(0 >= secure_protocol || 2 < secure_protocol)
1629 secure_protocol = 1;
1632 setDevProtocol(g_own_list);
1633 setDevProtocol(g_unown_list);
1637 static void printMenu(void)
1639 printf("************************************************************\n");
1640 printf("****** OIC Provisioning Client with using C-level API ******\n");
1641 printf("************************************************************\n\n");
1643 printf("** [A] DISCOVER DEVICES ON NETWORK\n");
1644 printf("** 10. Discover All Un/Owned Devices on Network\n");
1645 printf("** 11. Discover Only Unowned Devices on Network\n");
1646 printf("** 12. Discover Only Owned Devices on Network\n\n");
1648 printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n");
1649 printf("** 20. Register/Own All Discovered Unowned Devices\n\n");
1651 printf("** [C] PROVISION/LINK PAIRWISE THINGS\n");
1652 printf("** 30. Provision/Link Pairwise Things\n");
1653 printf("** 31. Provision Credentials for Pairwise Things\n");
1654 printf("** 32. Provision the Selected Access Control List(ACL)\n");
1655 printf("** 33. Provision Direct-Pairing Configuration\n");
1656 printf("** 34. Check Linked Status of the Selected Device on PRVN DB\n\n");
1658 printf("** [D] UNLINK PAIRWISE THINGS\n");
1659 printf("** 40. Unlink Pairwise Things\n\n");
1661 printf("** [E] REMOVE THE SELECTED DEVICE\n");
1662 printf("** 50. Remove the Selected Device\n");
1663 printf("** 51. Remove Device with UUID (UUID input is required)\n");
1664 printf("** 52. Reset the Selected Device\n\n");
1666 printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n");
1667 printf("** 60. Get the Credential resources of the Selected Device\n");
1668 printf("** 61. Get the ACL resources of the Selected Device\n\n");
1670 printf("** [F] SELECT SECURE PROTOCOL DTLS/TLS\n");
1671 printf("** 70. Select secure protocol(default DTLS)\n\n");
1673 printf("** [F] EXIT PROVISIONING CLIENT\n");
1674 printf("** 99. Exit Provisionong Client\n\n");
1676 printf("************************************************************\n\n");
1679 #if 0 // Code for enabling path configuration for PDB and SVR DBf
1680 static void printUsage(void)
1683 printf("OIC Provisioning Client with using C-level API\n");
1684 printf("Usage: provisioningclient [option]...\n");
1686 printf(" -h print help for this provisioning client\n");
1687 printf(" -p=[prvn_db_file_path/name] input PRVN DB file path and name\n");
1688 printf(" if not exists, will load default DB file\n");
1689 printf(" (default: |oic_prvn_mng.db| on working dir)\n");
1690 printf(" (ex. -p=oic_prvn_mng.db)\n");
1691 printf(" -s=[svr_db_file_path/name] input SVR DB file path and name\n");
1692 printf(" if not exists, will load default DB file\n");
1693 printf(" (default: |oic_svr_db_client.json| on working dir)\n");
1694 printf(" (ex. -s=oic_svr_db_client.json)\n");
1699 // main function for provisioning client using C-level provisioning API
1702 // initialize provisioning client
1703 if(initProvisionClient())
1705 OIC_LOG(ERROR, TAG, "ProvisionClient init error");
1709 // main loop for provisioning manager
1715 printf(">> Enter Menu Number: ");
1716 for(int ret=0; 1!=ret; )
1718 ret = scanf("%d", &mn_num);
1719 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1720 // '0x20<=code' is character region
1725 case _10_DISCOV_ALL_DEVS_:
1726 if(discoverAllDevices())
1728 OIC_LOG(ERROR, TAG, "_10_DISCOV_ALL_DEVS_: error");
1731 case _11_DISCOV_UNOWN_DEVS_:
1732 if(discoverUnownedDevices())
1734 OIC_LOG(ERROR, TAG, "_11_DISCOV_UNOWN_DEVS_: error");
1737 case _12_DISCOV_OWN_DEVS_:
1738 if(discoverOwnedDevices())
1740 OIC_LOG(ERROR, TAG, "_12_DISCOV_OWN_DEVS_: error");
1743 case _20_REGIST_DEVS_:
1744 if(registerDevices())
1746 OIC_LOG(ERROR, TAG, "_20_REGIST_DEVS_: error");
1749 case _30_PROVIS_PAIR_DEVS_:
1750 if(provisionPairwise())
1752 OIC_LOG(ERROR, TAG, "_30_PROVIS_PAIR_DEVS_: error");
1755 case _31_PROVIS_CRED_:
1758 OIC_LOG(ERROR, TAG, "_31_PROVIS_CRED_: error");
1761 case _32_PROVIS_ACL_:
1764 OIC_LOG(ERROR, TAG, "_32_PROVIS_ACL_: error");
1767 case _33_PROVIS_DP_:
1768 if(provisionDirectPairing())
1770 OIC_LOG(ERROR, TAG, "_33_PROVIS_DP_: error");
1773 case _34_CHECK_LINK_STATUS_:
1774 if(checkLinkedStatus())
1776 OIC_LOG(ERROR, TAG, "_34_CHECK_LINK_STATUS_: error");
1779 case _40_UNLINK_PAIR_DEVS_:
1780 if(unlinkPairwise())
1782 OIC_LOG(ERROR, TAG, "_40_UNLINK_PAIR_DEVS_: error");
1785 case _50_REMOVE_SELEC_DEV_:
1788 OIC_LOG(ERROR, TAG, "_50_REMOVE_SELEC_DEV_: error");
1791 case _51_REMOVE_DEV_WITH_UUID_:
1792 if(removeDeviceWithUuid())
1794 OIC_LOG(ERROR, TAG, "_51_REMOVE_DEV_WITH_UUID_: error");
1797 case _52_RESET_SELEC_DEV_:
1800 OIC_LOG(ERROR, TAG, "_52_RESET_SELEC_DEV_: error");
1806 OIC_LOG(ERROR, TAG, "_60_GET_CRED_: error");
1812 OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error");
1816 case _70_SELECT_PROTOCOL_:
1817 selectSecureProtocol();
1820 case _99_EXIT_PRVN_CLT_:
1823 printf(">> Entered Wrong Number. Please Enter Again\n\n");
1829 if(OC_STACK_OK != OCStop())
1831 OIC_LOG(ERROR, TAG, "OCStack stop error");
1833 OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
1834 OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
1838 OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
1842 OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
1844 return 0; // always return normal case
1849 #endif //__cplusplus