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_RESET_SELEC_DEV_ 51
58 #define _60_GET_CRED_ 60
59 #define _61_GET_ACL_ 61
60 #define _99_EXIT_PRVN_CLT_ 99
62 #define ACL_RESRC_MAX_NUM 16
63 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
64 #define ACL_RESRC_MAX_LEN 128
65 #define ACL_PEMISN_CNT 5
66 #define DISCOVERY_TIMEOUT 10 // 10 sec
67 #define CALLBACK_TIMEOUT 60 // 1 min
68 #define TAG "provisioningclient"
70 static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
71 static const char* SVR_DB_FILE_NAME = "oic_svr_db_client.dat";
72 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
73 static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
74 static const OicSecPrm_t SUPPORTED_PRMS[1] =
79 // |g_ctx| means provision manager application context and
80 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
81 // for accessing all function(s) for these, they are declared on global domain
82 static const char* g_ctx = "Provision Manager Client Application Context";
83 static char* g_svr_fname;
84 static char* g_prvn_fname;
85 static OCProvisionDev_t* g_own_list;
86 static OCProvisionDev_t* g_unown_list;
88 static int g_unown_cnt;
91 // function declaration(s) for calling them before implementing
92 static OicSecAcl_t* createAcl(const int);
93 static OicSecPdAcl_t* createPdAcl(const int);
94 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
95 static int printDevList(const OCProvisionDev_t*);
96 static size_t printUuidList(const OCUuidList_t*);
97 static int printResultList(const OCProvisionResult_t*, const int);
98 static void printUuid(const OicUuid_t*);
99 static FILE* fopen_prvnMng(const char*, const char*);
100 static int waitCallbackRet(void);
101 static int selectTwoDiffNum(int*, int*, const int, const char*);
103 // callback function(s) for provisioning client using C-level provisioning API
104 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
108 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
112 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
113 printResultList((const OCProvisionResult_t*) arr, nOfRes);
118 static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
122 OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
126 OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
127 printResultList((const OCProvisionResult_t*) arr, nOfRes);
132 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
136 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
140 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
141 printResultList((const OCProvisionResult_t*) arr, nOfRes);
146 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
150 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
154 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
155 printResultList((const OCProvisionResult_t*) arr, nOfRes);
160 static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
164 OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
168 OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx);
169 printResultList((const OCProvisionResult_t*) arr, nOfRes);
174 static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
178 OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
182 OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx);
183 printResultList((const OCProvisionResult_t*) arr, nOfRes);
188 static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
192 OIC_LOG_V(INFO, TAG, "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
196 OIC_LOG_V(ERROR, TAG, "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
197 printResultList((const OCProvisionResult_t*) arr, nOfRes);
202 static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
206 OIC_LOG_V(INFO, TAG, "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
210 OIC_LOG_V(ERROR, TAG, "Unlink Devices FAILED - ctx: %s", (char*) ctx);
211 printResultList((const OCProvisionResult_t*) arr, nOfRes);
216 static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
220 OIC_LOG_V(INFO, TAG, "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
224 OIC_LOG_V(ERROR, TAG, "Remove Device FAILED - ctx: %s", (char*) ctx);
225 printResultList((const OCProvisionResult_t*) arr, nOfRes);
230 static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
234 OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx);
238 OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx);
239 printResultList((const OCProvisionResult_t*) arr, nOfRes);
244 static void inputPinCB(char* pin, size_t len)
246 if(!pin || OXM_RANDOM_PIN_SIZE>=len)
248 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
252 printf(" > INPUT PIN: ");
253 for(int ret=0; 1!=ret; )
255 ret = scanf("%8s", pin);
256 for( ; 0x20<=getchar(); ); // for removing overflow garbages
257 // '0x20<=code' is character region
261 // function(s) for provisioning client using C-level provisioning API
262 static int initProvisionClient(void)
264 // initialize persistent storage for SVR DB
265 static OCPersistentStorage pstStr =
267 .open = fopen_prvnMng,
273 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
275 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
279 // initialize OC stack and provisioning manager
280 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
282 OIC_LOG(ERROR, TAG, "OCStack init error");
286 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
288 printf("************************************************************\n");
289 printf("************Provisioning DB file already exists.************\n");
290 printf("************************************************************\n");
294 printf("*************************************************************\n");
295 printf("************No provisioning DB file, creating new************\n");
296 printf("*************************************************************\n");
299 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
301 OIC_LOG(ERROR, TAG, "OC_PM init error");
305 // register callback function(s) to each OxM
306 OTMCallbackData_t otmcb =
308 .loadSecretCB = LoadSecretJustWorksCallback,
309 .createSecureSessionCB = CreateSecureSessionJustWorksCallback,
310 .createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload,
311 .createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload
313 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb))
315 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_JUST_WORKS");
318 otmcb.loadSecretCB = InputPinCodeCallback;
319 otmcb.createSecureSessionCB = CreateSecureSessionRandomPinCallback;
320 otmcb.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
321 otmcb.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
322 if(OC_STACK_OK != OCSetOwnerTransferCallbackData(OIC_RANDOM_DEVICE_PIN, &otmcb))
324 OIC_LOG(ERROR, TAG, "OCSetOwnerTransferCallbackData error: OIC_RANDOM_DEVICE_PIN");
327 SetInputPinCB(inputPinCB);
332 static int discoverAllDevices(void)
334 // delete un/owned device lists before updating them
337 OCDeleteDiscoveredDevices(g_own_list);
342 OCDeleteDiscoveredDevices(g_unown_list);
346 // call |OCGetDevInfoFromNetwork| API actually
347 printf(" Discovering All Un/Owned Devices on Network..\n");
348 if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
350 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error");
354 // display the discovered un/owned lists
355 printf(" > Discovered Owned Devices\n");
356 g_own_cnt = printDevList(g_own_list);
357 printf(" > Discovered Unowned Devices\n");
358 g_unown_cnt = printDevList(g_unown_list);
364 static int discoverUnownedDevices(void)
366 // delete unowned device list before updating it
369 OCDeleteDiscoveredDevices(g_unown_list);
373 // call |OCDiscoverUnownedDevices| API actually
374 printf(" Discovering Only Unowned Devices on Network..\n");
375 if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
377 OIC_LOG(ERROR, TAG, "OCDiscoverUnownedDevices API error");
381 // display the discovered unowned list
382 printf(" > Discovered Unowned Devices\n");
383 g_unown_cnt = printDevList(g_unown_list);
388 static int discoverOwnedDevices(void)
390 // delete owned device list before updating it
393 OCDeleteDiscoveredDevices(g_own_list);
397 // call |OCDiscoverOwnedDevices| API actually
398 printf(" Discovering Only Owned Devices on Network..\n");
399 if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
401 OIC_LOG(ERROR, TAG, "OCDiscoverOwnedDevices API error");
405 // display the discovered owned list
406 printf(" > Discovered Owned Devices\n");
407 g_own_cnt = printDevList(g_own_list);
412 static int registerDevices(void)
414 // check |unown_list| for registering devices
415 if(!g_unown_list || 0>=g_unown_cnt)
417 printf(" > Unowned Device List, to Register Devices, is Empty\n");
418 printf(" > Please Discover Unowned Devices first, with [10|11] Menu\n");
419 return 0; // normal case
422 // call |OCDoOwnershipTransfer| API actually
423 // calling this API with callback actually acts like blocking
424 // for error checking, the return value saved and printed
426 printf(" Registering All Discovered Unowned Devices..\n");
427 OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
428 if(OC_STACK_OK != rst)
430 OIC_LOG_V(ERROR, TAG, "OCDoOwnershipTransfer API error: %d", rst);
433 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
435 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
439 // display the registered result
440 printf(" > Registered Discovered Unowned Devices\n");
441 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
446 static int provisionPairwise(void)
448 // check |own_list| for provisioning pairwise devices
449 if(!g_own_list || 2>g_own_cnt)
451 printf(" > Owned Device List, to Provision the Pairwise, is Empty\n");
452 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
453 return 0; // normal case
456 // select two devices for provisioning pairwise devices
457 int dev_num[2] = {0};
458 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
460 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
461 return -1; // not need to 'goto' |ERROR| before allocating |acl|
464 // create ACL(s) for each selected device
465 OicSecAcl_t* acl[2] = {0};
466 for(int i=0; 2>i; ++i)
468 acl[i] = createAcl(dev_num[i]);
471 OIC_LOG(ERROR, TAG, "createAcl error return");
476 // call |OCProvisionPairwiseDevices| API actually
477 // calling this API with callback actually acts like blocking
478 // for error checking, the return value saved and printed
480 printf(" Provisioning Selected Pairwise Devices..\n");
482 OCProvisionPairwiseDevices((void*) g_ctx,
483 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
484 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
485 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
486 provisionPairwiseCB);
487 if(OC_STACK_OK != rst)
489 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
492 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
494 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
497 OCDeleteACLList(acl[0]);
498 OCDeleteACLList(acl[1]);
500 // display the pairwise-provisioned result
501 printf(" > Provisioned Selected Pairwise Devices\n");
502 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
507 OCDeleteACLList(acl[0]);
508 OCDeleteACLList(acl[1]);
512 static int provisionCred(void)
514 // check |own_list| for provisioning pairwise credentials
515 if(!g_own_list || 2>g_own_cnt)
517 printf(" > Owned Device List, to Provision Credentials, is Empty\n");
518 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
519 return 0; // normal case
522 // select two devices for provisioning pairwise credentials
523 int dev_num[2] = {0};
524 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
526 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
530 printf(" Select PSK length..\n");
531 printf(" 1 - 128bit(Default)\n");
532 printf(" 2 - 256bit\n");
535 for(int ret=0; 1!=ret; )
537 ret = scanf("%d",&sizeOption);
538 for( ; 0x20<=getchar(); ); // for removing overflow garbages
539 // '0x20<=code' is character region
547 size = OWNER_PSK_LENGTH_128;
552 size = OWNER_PSK_LENGTH_256;
557 size = OWNER_PSK_LENGTH_128;
563 // call |OCProvisionCredentials| API actually
564 // calling this API with callback actually acts like blocking
565 // for error checking, the return value saved and printed
567 printf(" Provisioning Selected Pairwise Credentials..\n");
569 OCProvisionCredentials((void*) g_ctx,
570 SYMMETRIC_PAIR_WISE_KEY, size,
571 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
572 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
574 if(OC_STACK_OK != rst)
576 OIC_LOG_V(ERROR, TAG, "OCProvisionCredentials API error: %d", rst);
579 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
581 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
585 // display the CRED-provisioned result
586 printf(" > Provisioned Selected Pairwise Crendentials\n");
587 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
592 static int provisionAcl(void)
594 // check |own_list| for provisioning access control list
595 if(!g_own_list || 1>g_own_cnt)
597 printf(" > Owned Device List, to Provision ACL, is Empty\n");
598 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
599 return 0; // normal case
602 // select device for provisioning access control list
606 printf(" > Enter Device Number, for Provisioning ACL: ");
607 for(int ret=0; 1!=ret; )
609 ret = scanf("%d", &dev_num);
610 for( ; 0x20<=getchar(); ); // for removing overflow garbages
611 // '0x20<=code' is character region
613 if(0<dev_num && g_own_cnt>=dev_num)
617 printf(" Entered Wrong Number. Please Enter Again\n");
620 // create ACL for selected device
621 OicSecAcl_t* acl = NULL;
622 acl = createAcl(dev_num);
625 OIC_LOG(ERROR, TAG, "createAcl error return");
629 // call |OCProvisionACL| API actually
630 // calling this API with callback actually acts like blocking
631 // for error checking, the return value saved and printed
633 printf(" Provisioning Selected ACL..\n");
634 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
637 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
640 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
641 if(OC_STACK_OK != rst)
643 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
646 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
648 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
651 OCDeleteACLList(acl); // after here |acl| points nothing
653 // display the ACL-provisioned result
654 printf(" > Provisioned Selected ACL\n");
659 OCDeleteACLList(acl); // after here |acl| points nothing
663 static int provisionDirectPairing(void)
665 // check |own_list| for provisioning direct-pairing
666 if(!g_own_list || 1>g_own_cnt)
668 printf(" > Owned Device List, to Provision ACL, is Empty\n");
669 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
670 return 0; // normal case
673 // select device for provisioning direct-pairing
677 printf(" > Enter Device Number, for Provisioning Direct-Pairing: ");
678 for(int ret=0; 1!=ret; )
680 ret = scanf("%d", &dev_num);
681 for( ; 0x20<=getchar(); ); // for removing overflow garbages
682 // '0x20<=code' is character region
684 if(0<dev_num && g_own_cnt>=dev_num)
688 printf(" Entered Wrong Number. Please Enter Again\n");
691 // create Direct-Pairing Configuration(PIN, PDACL) for selected device
692 // TODO: default acl -> input from user !
694 memset(&pconf, 0, sizeof(OicSecPconf_t));
699 // set default supported PRM types
700 pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
701 pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
704 for (size_t i=0; i<pconf.prmLen; i++)
706 pconf.prm[i] = SUPPORTED_PRMS[i];
711 OIC_LOG(ERROR, TAG, "create prm error return");
716 const char DP_DEFAULT_PIN[] = "00000000";
717 memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
720 pconf.pdacls = createPdAcl(dev_num);
723 OIC_LOG(ERROR, TAG, "createPdAcl error return");
727 // call |OCProvisionDirectPairing| API actually
728 // calling this API with callback actually acts like blocking
729 // for error checking, the return value saved and printed
731 printf(" Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
732 OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
733 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
734 &pconf, provisionDPCB);
735 if(OC_STACK_OK != rst)
737 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
738 if (OC_STACK_UNAUTHORIZED_REQ == rst)
740 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
744 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
746 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
749 OCDeletePdAclList(pconf.pdacls);
751 // display the PCONF-provisioned result
752 printf(" > SUCCESS to provision Direct-Pairing !!\n");
757 OCDeletePdAclList(pconf.pdacls); // after here |acl| points nothing
761 static int checkLinkedStatus(void)
763 // check |own_list| for checking selected link status on PRVN DB
764 if(!g_own_list || 1>g_own_cnt)
766 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
767 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
768 return 0; // normal case
771 // select device for checking selected link status on PRVN DB
775 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
776 for(int ret=0; 1!=ret; )
778 ret = scanf("%d", &dev_num);
779 for( ; 0x20<=getchar(); ); // for removing overflow garbages
780 // '0x20<=code' is character region
782 if(0<dev_num && g_own_cnt>=dev_num)
786 printf(" Entered Wrong Number. Please Enter Again\n");
789 // call |OCGetLinkedStatus| API actually
790 printf(" Checking Selected Link Status on PRVN DB..\n");
791 OCUuidList_t* dvid_lst = NULL;
793 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
794 if(!dev || !dev->doxm)
796 OIC_LOG(ERROR, TAG, "checkLinkedStatus: device instance empty");
802 &dev->doxm->deviceID,
803 &dvid_lst, &dvid_cnt)) // allow empty list
805 OIC_LOG(ERROR, TAG, "OCGetLinkedStatus API error");
809 // display the linked status result
810 printf(" > Checked Selected Link Status on PRVN DB\n");
811 if(!dvid_lst || !dvid_cnt) // |size_t| is unsigned
813 printf(" Linked Device List is Empty..\n");
814 return 0; // normal case
816 if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
818 OIC_LOG(ERROR, TAG, "printUuidList error return");
821 OCDeleteUuidList(dvid_lst);
826 OCDeleteUuidList(dvid_lst);
830 static int getCred(void)
832 // check |own_list| for checking selected link status on PRVN DB
833 if(!g_own_list || 1>g_own_cnt)
835 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
836 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
837 return 0; // normal case
840 // select device for checking selected link status on PRVN DB
844 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
845 for(int ret=0; 1!=ret; )
847 ret = scanf("%d", &dev_num);
848 for( ; 0x20<=getchar(); ); // for removing overflow garbages
849 // '0x20<=code' is character region
851 if(0<dev_num && g_own_cnt>=dev_num)
855 printf(" Entered Wrong Number. Please Enter Again\n");
858 // call |getDevInst| API actually
859 // calling this API with callback actually acts like blocking
860 // for error checking, the return value saved and printed
862 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
865 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
868 OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
869 if(OC_STACK_OK != rst)
871 OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst);
874 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
876 OIC_LOG(ERROR, TAG, "OCGetCredResource callback error");
880 // display the result of get credential
881 printf(" > Get Cred SUCCEEDED\n");
889 static int getAcl(void)
891 // check |own_list| for checking selected link status on PRVN DB
892 if(!g_own_list || 1>g_own_cnt)
894 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
895 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
896 return 0; // normal case
899 // select device for checking selected link status on PRVN DB
903 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
904 for(int ret=0; 1!=ret; )
906 ret = scanf("%d", &dev_num);
907 for( ; 0x20<=getchar(); ); // for removing overflow garbages
908 // '0x20<=code' is character region
910 if(0<dev_num && g_own_cnt>=dev_num)
914 printf(" Entered Wrong Number. Please Enter Again\n");
917 // call |getDevInst| API actually
918 // calling this API with callback actually acts like blocking
919 // for error checking, the return value saved and printed
921 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
924 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
927 OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
928 if(OC_STACK_OK != rst)
930 OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst);
934 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
936 OIC_LOG(ERROR, TAG, "OCGetACLResource callback error");
940 // display the result of get credential
941 printf(" > Get ACL SUCCEEDED\n");
949 static int unlinkPairwise(void)
951 // check |own_list| for unlinking pairwise devices
952 if(!g_own_list || 2>g_own_cnt)
954 printf(" > Owned Device List, to Unlink the Pairwise, is Empty\n");
955 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
956 return 0; // normal case
959 // select two devices for unlinking pairwise devices
960 int dev_num[2] = {0};
961 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
963 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
967 // call |OCUnlinkDevices| API actually
968 // calling this API with callback actually acts like blocking
969 // for error checking, the return value saved and printed
971 printf(" Unlinking Selected Pairwise Devices..\n");
973 OCUnlinkDevices((void*) g_ctx,
974 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
975 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
977 if(OC_STACK_OK != rst)
979 OIC_LOG_V(ERROR, TAG, "OCUnlinkDevices API error: %d", rst);
982 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
984 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
988 // display the pairwise-unlinked result
989 printf(" > Unlinked Selected Pairwise Devices\n");
990 printf(" > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
995 static int removeDevice(void)
997 // check |own_list| for removing device
998 if(!g_own_list || 1>g_own_cnt)
1000 printf(" > Owned Device List, to Remove Device, is Empty\n");
1001 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1002 return 0; // normal case
1005 // select device for removing it
1009 printf(" > Enter Device Number, for Removing Device: ");
1010 for(int ret=0; 1!=ret; )
1012 ret = scanf("%d", &dev_num);
1013 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1014 // '0x20<=code' is character region
1016 if(0<dev_num && g_own_cnt>=dev_num)
1020 printf(" Entered Wrong Number. Please Enter Again\n");
1023 // call |OCRemoveDevice| API actually
1024 // calling this API with callback actually acts like blocking
1025 // for error checking, the return value saved and printed
1027 printf(" Removing Selected Owned Device..\n");
1029 OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
1030 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
1031 if(OC_STACK_OK != rst)
1033 OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst);
1036 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1038 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1042 // display the removed result
1043 printf(" > Removed Selected Owned Device\n");
1044 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1049 static int resetDevice(void)
1051 // check |own_list| for removing device
1052 if (!g_own_list || 1 > g_own_cnt)
1054 printf(" > Owned Device List, to Reset Device, is Empty\n");
1055 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1059 // select device for removing it
1063 printf(" > Enter Device Number, for Resetting Device: ");
1064 for (int ret = 0; 1 != ret; )
1066 ret = scanf("%d", &dev_num);
1067 for ( ; 0x20 <= getchar() ; ); // for removing overflow garbages
1068 // '0x20 <= code' is character region
1070 if (0 < dev_num && g_own_cnt >= dev_num)
1074 printf(" Entered Wrong Number. Please Enter Again\n");
1078 printf(" Resetting Selected Owned Device..\n");
1080 OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT,
1081 getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB);
1082 if (OC_STACK_OK != rst)
1084 OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst);
1088 if (waitCallbackRet()) // input |g_doneCB| flag implicitly
1090 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1094 // display the removed result
1095 printf(" > Reset Selected Owned Device SUCCEEDED\n");
1096 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1101 static OicSecAcl_t* createAcl(const int dev_num)
1103 if(0>=dev_num || g_own_cnt<dev_num)
1105 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1106 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1109 // allocate memory for |acl| struct
1110 printf(" **** Create ACL for the Selected Device[%d]\n", dev_num);
1111 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
1114 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1115 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1117 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
1120 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1121 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1123 LL_APPEND(acl->aces, ace);
1125 // enter |subject| device number
1129 printf(" > [A] Enter Subject Device Number: ");
1130 for(int ret=0; 1!=ret; )
1132 ret = scanf("%d", &num);
1133 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1134 // '0x20<=code' is character region
1136 if(0<num && g_own_cnt>=num && dev_num!=num)
1140 printf(" Entered Wrong Number. Please Enter Again\n");
1143 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, num);
1144 if(!dev || !dev->doxm)
1146 OIC_LOG(ERROR, TAG, "createAcl: device instance empty");
1149 memcpy(&ace->subjectuuid, &dev->doxm->deviceID, UUID_LENGTH);
1151 // enter number of |resources| in 'accessed' device
1154 printf(" > [B] Enter Number of Accessed Resources (under 16): ");
1155 // '16' is |ACL_RESRC_MAX_NUM|
1156 for(int ret=0; 1!=ret; )
1158 ret = scanf("%d", &num);
1159 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1160 // '0x20<=code' is character region
1162 if(0<num && ACL_RESRC_MAX_NUM>=num)
1166 printf(" Entered Wrong Number. Please Enter under 16 Again\n");
1167 // '16' is |ACL_RESRC_MAX_NUM|
1170 // enter actually each 'accessed' |resources| name
1171 printf(" Enter Each Accessed Resource Name (each under 128 char)\n");
1172 // '128' is ACL_RESRC_MAX_LEN
1174 char rsrc_in[ACL_RESRC_MAX_LEN+1] = {0}; // '1' for null termination
1175 for(int i = 0; num > i; ++i)
1177 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
1180 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1184 printf(" Enter Accessed Resource[%d] Name: ", i+1);
1185 for(int ret=0; 1!=ret; )
1187 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1188 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1189 // '0x20<=code' is character region
1191 size_t len = strlen(rsrc_in)+1; // '1' for null termination
1192 rsrc->href = (char*) OICCalloc(len, sizeof(char));
1195 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1198 OICStrcpy(rsrc->href, len, rsrc_in);
1203 printf(" Enter Number of resource type for [%s]: ", rsrc_in);
1204 for(int ret=0; 1!=ret; )
1206 ret = scanf("%d", &arrLen);
1207 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1208 // '0x20<=code' is character region
1210 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1214 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1217 rsrc->typeLen = arrLen;
1218 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
1221 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1225 for(int i = 0; i < arrLen; i++)
1227 printf(" Enter ResourceType[%d] Name: ", i+1);
1228 for(int ret=0; 1!=ret; )
1230 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1231 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1232 // '0x20<=code' is character region
1234 rsrc->types[i] = OICStrdup(rsrc_in);
1237 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1244 printf(" Enter Number of interface name for [%s]: ", rsrc_in);
1245 for(int ret=0; 1!=ret; )
1247 ret = scanf("%d", &arrLen);
1248 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1249 // '0x20<=code' is character region
1251 if(0 < arrLen && ACL_RESRC_ARRAY_SIZE >= arrLen)
1255 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1258 rsrc->interfaceLen = arrLen;
1259 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
1260 if(!rsrc->interfaces)
1262 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1266 for(int i = 0; i < arrLen; i++)
1268 printf(" Enter ResourceType[%d] Name: ", i+1);
1269 for(int ret=0; 1!=ret; )
1271 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1272 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1273 // '0x20<=code' is character region
1275 rsrc->interfaces[i] = OICStrdup(rsrc_in);
1276 if(!rsrc->interfaces[i])
1278 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1283 LL_APPEND(ace->resources, rsrc);
1286 // enter |permission| for this access
1287 printf(" > [C] Enter Permission for This Access\n");
1288 uint16_t pmsn = PERMISSION_FULL_CONTROL; // default full permission
1289 uint16_t pmsn_msk = PERMISSION_CREATE; // default permission mask
1290 for(int i=0; ACL_PEMISN_CNT>i; ++i)
1295 printf(" Enter %s Permission (y/n): ", ACL_PEMISN[i]);
1296 for(int ret=0; 1!=ret; )
1298 ret = scanf("%c", &ans);
1299 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1300 // '0x20<=code' is character region
1302 if('y'==ans || 'Y'==ans || 'n'==ans|| 'N'==ans)
1304 ans &= ~0x20; // for masking lower case, 'y/n'
1307 printf(" Entered Wrong Answer. Please Enter 'y/n' Again\n");
1309 if('N' == ans) // masked lower case, 'n'
1315 ace->permission = pmsn;
1320 OCDeleteACLList(acl); // after here |acl| points nothing
1324 static OicSecPdAcl_t* createPdAcl(const int dev_num)
1326 if(0>=dev_num || g_own_cnt<dev_num)
1328 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1329 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1332 // allocate memory for |pdacl| struct
1333 printf(" **** Create PDACL for the Selected Device[%d]\n", dev_num);
1334 OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
1337 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1338 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1342 // number of resources
1343 char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
1344 pdAcl->resourcesLen = 1;
1347 int num = pdAcl->resourcesLen;
1348 pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
1349 if(!pdAcl->resources)
1351 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1354 for(int i=0; num>i; ++i)
1356 size_t len = strlen(rsrc_in[i])+1; // '1' for null termination
1357 char* rsrc = (char*) OICCalloc(len, sizeof(char));
1360 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
1363 OICStrcpy(rsrc, len, rsrc_in[i]);
1364 pdAcl->resources[i] = rsrc; // after here, |rsrc| points nothing
1368 pdAcl->permission = PERMISSION_FULL_CONTROL;
1373 OCDeletePdAclList(pdAcl);
1377 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
1379 if(!dev_lst || 0>=dev_num)
1381 printf(" Device List is Empty..\n");
1385 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1395 return NULL; // in here |lst| is always |NULL|
1398 static int printDevList(const OCProvisionDev_t* dev_lst)
1402 printf(" Device List is Empty..\n\n");
1406 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
1410 printf(" [%d] ", ++lst_cnt);
1411 printUuid((const OicUuid_t*) &lst->doxm->deviceID);
1420 static size_t printUuidList(const OCUuidList_t* uid_lst)
1424 printf(" Device List is Empty..\n\n");
1428 OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
1432 printf(" [%zu] ", ++lst_cnt);
1433 printUuid((const OicUuid_t*) &lst->dev);
1442 static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
1444 if(!rslt_lst || 0>=rslt_cnt)
1446 printf(" Device List is Empty..\n\n");
1451 for( ; rslt_cnt>lst_cnt; ++lst_cnt)
1453 printf(" [%d] ", lst_cnt+1);
1454 printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
1455 printf(" - result: %d\n", rslt_lst[lst_cnt].res);
1462 static void printUuid(const OicUuid_t* uid)
1464 for(int i=0; i<UUID_LENGTH; )
1466 printf("%02X", (*uid).id[i++]);
1467 if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
1474 static FILE* fopen_prvnMng(const char* path, const char* mode)
1476 (void)path; // unused |path| parameter
1478 // input |g_svr_db_fname| internally by force, not using |path| parameter
1479 // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
1480 // with its own |SVR_DB_FILE_NAME|
1481 return fopen(SVR_DB_FILE_NAME, mode);
1484 static int waitCallbackRet(void)
1486 for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
1489 if(OC_STACK_OK != OCProcess())
1491 OIC_LOG(ERROR, TAG, "OCStack process error");
1499 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
1501 if(!a || !b || 2>max || !str)
1508 for(int i=0; 2>i; ++i)
1510 int* num = 0==i?a:b;
1513 printf(" > Enter Device[%d] Number, %s: ", i+1, str);
1514 for(int ret=0; 1!=ret; )
1516 ret = scanf("%d", num);
1517 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1518 // '0x20<=code' is character region
1520 if(0<*num && max>=*num)
1524 printf(" Entered Wrong Number. Please Enter Again\n");
1537 static void printMenu(void)
1539 printf("************************************************************\n");
1540 printf("****** OIC Provisioning Client with using C-level API ******\n");
1541 printf("************************************************************\n\n");
1543 printf("** [A] DISCOVER DEVICES ON NETWORK\n");
1544 printf("** 10. Discover All Un/Owned Devices on Network\n");
1545 printf("** 11. Discover Only Unowned Devices on Network\n");
1546 printf("** 12. Discover Only Owned Devices on Network\n\n");
1548 printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n");
1549 printf("** 20. Register/Own All Discovered Unowned Devices\n\n");
1551 printf("** [C] PROVISION/LINK PAIRWISE THINGS\n");
1552 printf("** 30. Provision/Link Pairwise Things\n");
1553 printf("** 31. Provision Credentials for Pairwise Things\n");
1554 printf("** 32. Provision the Selected Access Control List(ACL)\n");
1555 printf("** 33. Provision Direct-Pairing Configuration\n");
1556 printf("** 34. Check Linked Status of the Selected Device on PRVN DB\n\n");
1558 printf("** [D] UNLINK PAIRWISE THINGS\n");
1559 printf("** 40. Unlink Pairwise Things\n\n");
1561 printf("** [E] REMOVE THE SELECTED DEVICE\n");
1562 printf("** 50. Remove the Selected Device\n");
1563 printf("** 51. Reset the Selected Device\n\n");
1565 printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n");
1566 printf("** 60. Get the Credential resources of the Selected Device\n");
1567 printf("** 61. Get the ACL resources of the Selected Device\n\n");
1569 printf("** [F] EXIT PROVISIONING CLIENT\n");
1570 printf("** 99. Exit Provisionong Client\n\n");
1572 printf("************************************************************\n\n");
1575 #if 0 // Code for enabling path configuration for PDB and SVR DBf
1576 static void printUsage(void)
1579 printf("OIC Provisioning Client with using C-level API\n");
1580 printf("Usage: provisioningclient [option]...\n");
1582 printf(" -h print help for this provisioning client\n");
1583 printf(" -p=[prvn_db_file_path/name] input PRVN DB file path and name\n");
1584 printf(" if not exists, will load default DB file\n");
1585 printf(" (default: |oic_prvn_mng.db| on working dir)\n");
1586 printf(" (ex. -p=oic_prvn_mng.db)\n");
1587 printf(" -s=[svr_db_file_path/name] input SVR DB file path and name\n");
1588 printf(" if not exists, will load default DB file\n");
1589 printf(" (default: |oic_svr_db_client.json| on working dir)\n");
1590 printf(" (ex. -s=oic_svr_db_client.json)\n");
1595 // main function for provisioning client using C-level provisioning API
1598 // initialize provisioning client
1599 if(initProvisionClient())
1601 OIC_LOG(ERROR, TAG, "ProvisionClient init error");
1605 // main loop for provisioning manager
1611 printf(">> Enter Menu Number: ");
1612 for(int ret=0; 1!=ret; )
1614 ret = scanf("%d", &mn_num);
1615 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1616 // '0x20<=code' is character region
1621 case _10_DISCOV_ALL_DEVS_:
1622 if(discoverAllDevices())
1624 OIC_LOG(ERROR, TAG, "_10_DISCOV_ALL_DEVS_: error");
1627 case _11_DISCOV_UNOWN_DEVS_:
1628 if(discoverUnownedDevices())
1630 OIC_LOG(ERROR, TAG, "_11_DISCOV_UNOWN_DEVS_: error");
1633 case _12_DISCOV_OWN_DEVS_:
1634 if(discoverOwnedDevices())
1636 OIC_LOG(ERROR, TAG, "_12_DISCOV_OWN_DEVS_: error");
1639 case _20_REGIST_DEVS_:
1640 if(registerDevices())
1642 OIC_LOG(ERROR, TAG, "_20_REGIST_DEVS_: error");
1645 case _30_PROVIS_PAIR_DEVS_:
1646 if(provisionPairwise())
1648 OIC_LOG(ERROR, TAG, "_30_PROVIS_PAIR_DEVS_: error");
1651 case _31_PROVIS_CRED_:
1654 OIC_LOG(ERROR, TAG, "_31_PROVIS_CRED_: error");
1657 case _32_PROVIS_ACL_:
1660 OIC_LOG(ERROR, TAG, "_32_PROVIS_ACL_: error");
1663 case _33_PROVIS_DP_:
1664 if(provisionDirectPairing())
1666 OIC_LOG(ERROR, TAG, "_33_PROVIS_DP_: error");
1669 case _34_CHECK_LINK_STATUS_:
1670 if(checkLinkedStatus())
1672 OIC_LOG(ERROR, TAG, "_34_CHECK_LINK_STATUS_: error");
1675 case _40_UNLINK_PAIR_DEVS_:
1676 if(unlinkPairwise())
1678 OIC_LOG(ERROR, TAG, "_40_UNLINK_PAIR_DEVS_: error");
1681 case _50_REMOVE_SELEC_DEV_:
1684 OIC_LOG(ERROR, TAG, "_50_REMOVE_SELEC_DEV_: error");
1687 case _51_RESET_SELEC_DEV_:
1690 OIC_LOG(ERROR, TAG, "_51_RESET_SELEC_DEV_: error");
1696 OIC_LOG(ERROR, TAG, "_60_GET_CRED_: error");
1702 OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error");
1705 case _99_EXIT_PRVN_CLT_:
1708 printf(">> Entered Wrong Number. Please Enter Again\n\n");
1714 if(OC_STACK_OK != OCStop())
1716 OIC_LOG(ERROR, TAG, "OCStack stop error");
1718 OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
1719 OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
1723 OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
1727 OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
1729 return 0; // always return normal case
1734 #endif //__cplusplus