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"
39 #include "oxmverifycommon.h"
40 #include "pkix_interface.h"
41 #include "hw_emul/hw_interface.h"
42 #include "mbedtls/x509_crt.h"
49 // declaration(s) for provisioning client using C-level provisioning API
50 // user input definition for main loop on provisioning client
51 #define _10_DISCOV_ALL_DEVS_ 10
52 #define _11_DISCOV_UNOWN_DEVS_ 11
53 #define _12_DISCOV_OWN_DEVS_ 12
55 #define _13_MOT_DISCOV_DEV_ 13
56 #endif //MULTIPLE_OWNER
57 #define _20_REGIST_DEVS_ 20
58 #define _30_PROVIS_PAIR_DEVS_ 30
59 #define _31_PROVIS_CRED_ 31
60 #define _32_PROVIS_ACL_ 32
61 #define _33_PROVIS_DP_ 33
62 #define _34_CHECK_LINK_STATUS_ 34
63 #define _35_SAVE_ACL_ 35
64 #define _40_UNLINK_PAIR_DEVS_ 40
65 #define _50_REMOVE_SELEC_DEV_ 50
66 #define _51_REMOVE_DEV_WITH_UUID_ 51
67 #define _52_RESET_SELEC_DEV_ 52
68 #define _53_RESET_SVR_DB_ 53
69 #define _60_GET_CRED_ 60
70 #define _61_GET_ACL_ 61
72 #define _70_MOT_CHANGE_MOM_ 70
73 #define _71_MOT_PROV_PRECONF_PIN_ 71
74 #define _72_MOT_OXM_SEL_ 72
75 #define _73_MOT_REMOVE_SUBOWNER_ 73
76 #define _74_MOT_REMOVE_ALL_SUBOWNER_ 74
77 #endif //MULTIPLE_OWNER
78 #define _80_SELECT_PROTOCOL_ 80
79 #define _81_SELECT_VERIF_METHOD_ 81
80 #define _82_SECURE_STORAGE_HW_EMULATION_ 82
81 #define _99_EXIT_PRVN_CLT_ 99
83 #define ACL_RESRC_MAX_NUM 16
84 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
85 #define ACL_RESRC_MAX_LEN 128
86 #define ACL_PEMISN_CNT 5
87 #define DISCOVERY_TIMEOUT 10 // 10 sec
88 #define CALLBACK_TIMEOUT 60 // 1 min
89 #define TAG "provisioningclient"
91 static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
92 static const char* SVR_DB_FILE_NAME = "oic_svr_db_client.dat";
93 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
94 static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
95 static const OicSecPrm_t SUPPORTED_PRMS[1] =
100 // |g_ctx| means provision manager application context and
101 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
102 // for accessing all function(s) for these, they are declared on global domain
103 static const char* g_ctx = "Provision Manager Client Application Context";
104 static char* g_svr_fname;
105 static char* g_prvn_fname;
106 static OCProvisionDev_t* g_own_list;
107 static OCProvisionDev_t* g_unown_list;
108 static int g_own_cnt;
109 static int g_unown_cnt;
110 #ifdef MULTIPLE_OWNER
111 static OCProvisionDev_t* g_mot_enable_list;
112 static int g_mot_enable_cnt;
113 #endif //MULTIPLE_OWNER
115 static bool g_doneCB;
117 static int secure_protocol = 1;
118 static void setDevProtocol(OCProvisionDev_t* dev_lst);
120 // function declaration(s) for calling them before implementing
121 static OicSecAcl_t* createAcl(const int);
122 static OicSecAcl_t* createSimpleAcl(const OicUuid_t uuid);
123 static OicSecPdAcl_t* createPdAcl(const int);
124 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
125 static int printDevList(const OCProvisionDev_t*);
126 static size_t printUuidList(const OCUuidList_t*);
127 static int printResultList(const OCProvisionResult_t*, const int);
128 static void printUuid(const OicUuid_t*);
129 static FILE* fopen_prvnMng(const char*, const char*);
130 static int waitCallbackRet(void);
131 static int selectTwoDiffNum(int*, int*, const int, const char*);
133 // callback function(s) for provisioning client using C-level provisioning API
134 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
138 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
142 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
143 printResultList((const OCProvisionResult_t*) arr, nOfRes);
148 static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
152 OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
156 OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
157 printResultList((const OCProvisionResult_t*) arr, nOfRes);
162 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
166 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
170 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
171 printResultList((const OCProvisionResult_t*) arr, nOfRes);
176 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
180 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
184 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
185 printResultList((const OCProvisionResult_t*) arr, nOfRes);
190 static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
194 OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
198 OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx);
199 printResultList((const OCProvisionResult_t*) arr, nOfRes);
204 static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
208 OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
212 OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx);
213 printResultList((const OCProvisionResult_t*) arr, nOfRes);
218 static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
222 OIC_LOG_V(INFO, TAG, "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
226 OIC_LOG_V(ERROR, TAG, "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
227 printResultList((const OCProvisionResult_t*) arr, nOfRes);
232 static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
236 OIC_LOG_V(INFO, TAG, "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
240 OIC_LOG_V(ERROR, TAG, "Unlink Devices FAILED - ctx: %s", (char*) ctx);
241 printResultList((const OCProvisionResult_t*) arr, nOfRes);
246 static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
250 OIC_LOG_V(INFO, TAG, "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
254 OIC_LOG_V(ERROR, TAG, "Remove Device FAILED - ctx: %s", (char*) ctx);
255 printResultList((const OCProvisionResult_t*) arr, nOfRes);
260 static void resetDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
263 OIC_LOG_V(INFO, TAG, "Reset Device SUCCEEDED");
267 #ifdef MULTIPLE_OWNER
268 static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
272 OIC_LOG_V(INFO, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
276 OIC_LOG_V(ERROR, TAG, "POST 'doxm' FAILED - ctx: %s", (char*) ctx);
277 printResultList((const OCProvisionResult_t*) arr, nOfRes);
282 static void deleteDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
286 OIC_LOG_V(INFO, TAG, "DELETE 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
290 OIC_LOG_V(ERROR, TAG, "DELETE 'doxm' FAILED - ctx: %s", (char*) ctx);
291 printResultList((const OCProvisionResult_t*) arr, nOfRes);
296 #endif //MULTIPLE_OWNER
298 static void inputPinCB(char* pin, size_t len)
300 if(!pin || OXM_RANDOM_PIN_MIN_SIZE > len)
302 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
306 printf(" > INPUT PIN: ");
307 for(int ret=0; 1!=ret; )
309 ret = scanf("%32s", pin);
310 for( ; 0x20<=getchar(); ); // for removing overflow garbages
311 // '0x20<=code' is character region
315 // function(s) for provisioning client using C-level provisioning API
316 static int initProvisionClient(void)
318 // initialize persistent storage for SVR DB
319 static OCPersistentStorage pstStr =
321 .open = fopen_prvnMng,
327 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
329 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
333 // initialize OC stack and provisioning manager
334 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
336 OIC_LOG(ERROR, TAG, "OCStack init error");
340 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
342 printf("************************************************************\n");
343 printf("************Provisioning DB file already exists.************\n");
344 printf("************************************************************\n");
348 printf("*************************************************************\n");
349 printf("************No provisioning DB file, creating new************\n");
350 printf("*************************************************************\n");
353 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
355 OIC_LOG(ERROR, TAG, "OC_PM init error");
359 SetInputPinCB(inputPinCB);
364 static int discoverAllDevices(void)
366 // delete un/owned device lists before updating them
369 OCDeleteDiscoveredDevices(g_own_list);
374 OCDeleteDiscoveredDevices(g_unown_list);
378 // call |OCGetDevInfoFromNetwork| API actually
379 printf(" Discovering All Un/Owned Devices on Network..\n");
380 if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
382 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error");
386 // display the discovered un/owned lists
387 printf(" > Discovered Owned Devices\n");
388 g_own_cnt = printDevList(g_own_list);
389 printf(" > Discovered Unowned Devices\n");
390 g_unown_cnt = printDevList(g_unown_list);
392 setDevProtocol(g_own_list);
393 setDevProtocol(g_unown_list);
399 static int discoverUnownedDevices(void)
401 // delete unowned device list before updating it
404 OCDeleteDiscoveredDevices(g_unown_list);
408 // call |OCDiscoverUnownedDevices| API actually
409 printf(" Discovering Only Unowned Devices on Network..\n");
410 if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
412 OIC_LOG(ERROR, TAG, "OCDiscoverUnownedDevices API error");
416 // display the discovered unowned list
417 printf(" > Discovered Unowned Devices\n");
418 g_unown_cnt = printDevList(g_unown_list);
420 setDevProtocol(g_unown_list);
425 static int discoverOwnedDevices(void)
427 // delete owned device list before updating it
430 OCDeleteDiscoveredDevices(g_own_list);
434 // call |OCDiscoverOwnedDevices| API actually
435 printf(" Discovering Only Owned Devices on Network..\n");
436 if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
438 OIC_LOG(ERROR, TAG, "OCDiscoverOwnedDevices API error");
442 // display the discovered owned list
443 printf(" > Discovered Owned Devices\n");
444 g_own_cnt = printDevList(g_own_list);
446 setDevProtocol(g_own_list);
451 #ifdef MULTIPLE_OWNER
452 static int discoverMOTEnabledDevices(void)
454 // delete owned device list before updating it
455 if(g_mot_enable_list)
457 OCDeleteDiscoveredDevices(g_mot_enable_list);
458 g_mot_enable_list = NULL;
461 // call |OCDiscoverOwnedDevices| API actually
462 printf(" Discovering Multiple Ownership Transfer Enabled Devices on Network..\n");
463 if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_mot_enable_list))
465 OIC_LOG(ERROR, TAG, "OCDiscoverMultipleOwnerEnalbedDevices API error");
469 // display the discovered owned list
470 printf(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
471 g_mot_enable_cnt = printDevList(g_mot_enable_list);
475 #endif //MULTIPLE_OWNER
477 static int registerDevices(void)
479 // check |unown_list| for registering devices
480 if(!g_unown_list || 0>=g_unown_cnt)
482 printf(" > Unowned Device List, to Register Devices, is Empty\n");
483 printf(" > Please Discover Unowned Devices first, with [10|11] Menu\n");
484 return 0; // normal case
487 // call |OCDoOwnershipTransfer| API actually
488 // calling this API with callback actually acts like blocking
489 // for error checking, the return value saved and printed
491 printf(" Registering All Discovered Unowned Devices..\n");
492 OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
493 if(OC_STACK_OK != rst)
495 OIC_LOG_V(ERROR, TAG, "OCDoOwnershipTransfer API error: %d", rst);
498 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
500 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
504 // display the registered result
505 printf(" > Registered Discovered Unowned Devices\n");
506 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
511 static int provisionPairwise(void)
513 // check |own_list| for provisioning pairwise devices
514 if(!g_own_list || 2>g_own_cnt)
516 printf(" > Owned Device List, to Provision the Pairwise, is Empty\n");
517 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
518 return 0; // normal case
521 // select two devices for provisioning pairwise devices
522 int dev_num[2] = {0};
523 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
525 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
526 return -1; // not need to 'goto' |ERROR| before allocating |acl|
529 // create ACL(s) for each selected device
530 OicSecAcl_t* acl[2] = {0};
531 for(int i=0; 2>i; ++i)
533 acl[i] = createAcl(dev_num[i]);
536 OIC_LOG(ERROR, TAG, "createAcl error return");
541 // call |OCProvisionPairwiseDevices| API actually
542 // calling this API with callback actually acts like blocking
543 // for error checking, the return value saved and printed
545 printf(" Provisioning Selected Pairwise Devices..\n");
547 OCProvisionPairwiseDevices((void*) g_ctx,
548 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
549 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
550 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
551 provisionPairwiseCB);
552 if(OC_STACK_OK != rst)
554 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
557 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
559 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
562 OCDeleteACLList(acl[0]);
563 OCDeleteACLList(acl[1]);
565 // display the pairwise-provisioned result
566 printf(" > Provisioned Selected Pairwise Devices\n");
567 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
572 OCDeleteACLList(acl[0]);
573 OCDeleteACLList(acl[1]);
577 static int provisionCred(void)
579 // check |own_list| for provisioning pairwise credentials
580 if(!g_own_list || 2>g_own_cnt)
582 printf(" > Owned Device List, to Provision Credentials, is Empty\n");
583 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
584 return 0; // normal case
587 // select two devices for provisioning pairwise credentials
588 int dev_num[2] = {0};
589 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
591 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
595 printf(" Select PSK length..\n");
596 printf(" 1 - 128bit(Default)\n");
597 printf(" 2 - 256bit\n");
600 for(int ret=0; 1!=ret; )
602 ret = scanf("%d",&sizeOption);
603 for( ; 0x20<=getchar(); ); // for removing overflow garbages
604 // '0x20<=code' is character region
612 size = OWNER_PSK_LENGTH_128;
617 size = OWNER_PSK_LENGTH_256;
622 size = OWNER_PSK_LENGTH_128;
628 // call |OCProvisionCredentials| API actually
629 // calling this API with callback actually acts like blocking
630 // for error checking, the return value saved and printed
632 printf(" Provisioning Selected Pairwise Credentials..\n");
634 OCProvisionCredentials((void*) g_ctx,
635 SYMMETRIC_PAIR_WISE_KEY, size,
636 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
637 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
639 if(OC_STACK_OK != rst)
641 OIC_LOG_V(ERROR, TAG, "OCProvisionCredentials API error: %d", rst);
644 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
646 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
650 // display the CRED-provisioned result
651 printf(" > Provisioned Selected Pairwise Crendentials\n");
652 printf(" > Please Check Device's Status for the Linked Result, with [34] Menu\n");
657 static int provisionAcl(void)
659 // check |own_list| for provisioning access control list
660 if(!g_own_list || 1>g_own_cnt)
662 printf(" > Owned Device List, to Provision ACL, is Empty\n");
663 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
664 return 0; // normal case
667 // select device for provisioning access control list
671 printf(" > Enter Device Number, for Provisioning ACL: ");
672 for(int ret=0; 1!=ret; )
674 ret = scanf("%d", &dev_num);
675 for( ; 0x20<=getchar(); ); // for removing overflow garbages
676 // '0x20<=code' is character region
678 if(0<dev_num && g_own_cnt>=dev_num)
682 printf(" Entered Wrong Number. Please Enter Again\n");
685 // create ACL for selected device
686 OicSecAcl_t* acl = NULL;
687 acl = createAcl(dev_num);
690 OIC_LOG(ERROR, TAG, "createAcl error return");
694 // call |OCProvisionACL| API actually
695 // calling this API with callback actually acts like blocking
696 // for error checking, the return value saved and printed
698 printf(" Provisioning Selected ACL..\n");
699 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
702 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
705 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
706 if(OC_STACK_OK != rst)
708 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
711 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
713 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
716 OCDeleteACLList(acl); // after here |acl| points nothing
718 // display the ACL-provisioned result
719 printf(" > Provisioned Selected ACL\n");
724 OCDeleteACLList(acl); // after here |acl| points nothing
728 static int provisionDirectPairing(void)
730 // check |own_list| for provisioning direct-pairing
731 if(!g_own_list || 1>g_own_cnt)
733 printf(" > Owned Device List, to Provision ACL, is Empty\n");
734 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
735 return 0; // normal case
738 // select device for provisioning direct-pairing
742 printf(" > Enter Device Number, for Provisioning Direct-Pairing: ");
743 for(int ret=0; 1!=ret; )
745 ret = scanf("%d", &dev_num);
746 for( ; 0x20<=getchar(); ); // for removing overflow garbages
747 // '0x20<=code' is character region
749 if(0<dev_num && g_own_cnt>=dev_num)
753 printf(" Entered Wrong Number. Please Enter Again\n");
756 // create Direct-Pairing Configuration(PIN, PDACL) for selected device
757 // TODO: default acl -> input from user !
759 memset(&pconf, 0, sizeof(OicSecPconf_t));
764 // set default supported PRM types
765 pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
766 pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
769 for (size_t i=0; i<pconf.prmLen; i++)
771 pconf.prm[i] = SUPPORTED_PRMS[i];
776 OIC_LOG(ERROR, TAG, "create prm error return");
781 const char DP_DEFAULT_PIN[] = "00000000";
782 memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
785 pconf.pdacls = createPdAcl(dev_num);
788 OIC_LOG(ERROR, TAG, "createPdAcl error return");
792 // call |OCProvisionDirectPairing| API actually
793 // calling this API with callback actually acts like blocking
794 // for error checking, the return value saved and printed
796 printf(" Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
797 OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
798 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
799 &pconf, provisionDPCB);
800 if(OC_STACK_OK != rst)
802 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
803 if (OC_STACK_UNAUTHORIZED_REQ == rst)
805 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
809 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
811 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
814 OCDeletePdAclList(pconf.pdacls);
816 // display the PCONF-provisioned result
817 printf(" > SUCCESS to provision Direct-Pairing !!\n");
822 OCDeletePdAclList(pconf.pdacls); // after here |acl| points nothing
826 static int checkLinkedStatus(void)
828 // check |own_list| for checking selected link status on PRVN DB
829 if(!g_own_list || 1>g_own_cnt)
831 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
832 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
833 return 0; // normal case
836 // select device for checking selected link status on PRVN DB
840 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
841 for(int ret=0; 1!=ret; )
843 ret = scanf("%d", &dev_num);
844 for( ; 0x20<=getchar(); ); // for removing overflow garbages
845 // '0x20<=code' is character region
847 if(0<dev_num && g_own_cnt>=dev_num)
851 printf(" Entered Wrong Number. Please Enter Again\n");
854 // call |OCGetLinkedStatus| API actually
855 printf(" Checking Selected Link Status on PRVN DB..\n");
856 OCUuidList_t* dvid_lst = NULL;
858 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
859 if(!dev || !dev->doxm)
861 OIC_LOG(ERROR, TAG, "checkLinkedStatus: device instance empty");
867 &dev->doxm->deviceID,
868 &dvid_lst, &dvid_cnt)) // allow empty list
870 OIC_LOG(ERROR, TAG, "OCGetLinkedStatus API error");
874 // display the linked status result
875 printf(" > Checked Selected Link Status on PRVN DB\n");
876 if(!dvid_lst || !dvid_cnt) // |size_t| is unsigned
878 printf(" Linked Device List is Empty..\n");
879 return 0; // normal case
881 if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
883 OIC_LOG(ERROR, TAG, "printUuidList error return");
886 OCDeleteUuidList(dvid_lst);
891 OCDeleteUuidList(dvid_lst);
895 static int saveAcl(void)
897 // create ACL to save into local SVR DB
898 OicSecAcl_t* acl = NULL;
899 OicUuid_t uuid = {.id={0}};
900 char strUuid[64] = {0};
902 printf("[1] Use a test UUID [11111111-2222-3333-4444-555555555555]\n");
903 printf("[2] Use a user input\n");
907 printf(" > Select Number, for Subject UUID of new ACE: ");
908 for(int ret=0; 1!=ret; )
910 ret = scanf("%d", &sel_num);
911 for( ; 0x20<=getchar(); ); // for removing overflow garbages
912 // '0x20<=code' is character region
916 OICStrcpy(strUuid, sizeof(strUuid), "11111111-2222-3333-4444-555555555555");
919 else if(2 == sel_num)
921 printf(" > Input the UUID : ");
922 for(int ret=0; 1!=ret; )
924 ret = scanf("%64s", strUuid);
925 for( ; 0x20<=getchar(); ); // for removing overflow garbages
926 // '0x20<=code' is character region
930 printf(" Entered Wrong Number. Please Enter Again\n");
934 printf("Selected Subject UUID : %s\n", strUuid);
935 OCStackResult rst = ConvertStrToUuid(strUuid, &uuid);
936 if(OC_STACK_OK != rst)
938 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
942 acl = createSimpleAcl(uuid);
945 OIC_LOG(ERROR, TAG, "createAcl error return");
949 // call |OCSaveACL| API actually
950 rst = OCSaveACL(acl);
951 if(OC_STACK_OK != rst)
953 OIC_LOG_V(ERROR, TAG, "OCSaveACL API error: %d", rst);
956 OCDeleteACLList(acl); // after here |acl| points nothing
958 // display the ACL-provisioned result
959 printf(" > Saved Selected ACL\n");
964 OCDeleteACLList(acl); // after here |acl| points nothing
968 static int getCred(void)
970 // check |own_list| for checking selected link status on PRVN DB
971 if(!g_own_list || 1>g_own_cnt)
973 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
974 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
975 return 0; // normal case
978 // select device for checking selected link status on PRVN DB
982 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
983 for(int ret=0; 1!=ret; )
985 ret = scanf("%d", &dev_num);
986 for( ; 0x20<=getchar(); ); // for removing overflow garbages
987 // '0x20<=code' is character region
989 if(0<dev_num && g_own_cnt>=dev_num)
993 printf(" Entered Wrong Number. Please Enter Again\n");
996 // call |getDevInst| API actually
997 // calling this API with callback actually acts like blocking
998 // for error checking, the return value saved and printed
1000 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
1003 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
1006 OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
1007 if(OC_STACK_OK != rst)
1009 OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst);
1012 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1014 OIC_LOG(ERROR, TAG, "OCGetCredResource callback error");
1018 // display the result of get credential
1019 printf(" > Get Cred SUCCEEDED\n");
1027 static int getAcl(void)
1029 // check |own_list| for checking selected link status on PRVN DB
1030 if(!g_own_list || 1>g_own_cnt)
1032 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
1033 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1034 return 0; // normal case
1037 // select device for checking selected link status on PRVN DB
1041 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
1042 for(int ret=0; 1!=ret; )
1044 ret = scanf("%d", &dev_num);
1045 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1046 // '0x20<=code' is character region
1048 if(0<dev_num && g_own_cnt>=dev_num)
1052 printf(" Entered Wrong Number. Please Enter Again\n");
1055 // call |getDevInst| API actually
1056 // calling this API with callback actually acts like blocking
1057 // for error checking, the return value saved and printed
1059 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
1062 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
1065 OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
1066 if(OC_STACK_OK != rst)
1068 OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst);
1072 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1074 OIC_LOG(ERROR, TAG, "OCGetACLResource callback error");
1078 // display the result of get credential
1079 printf(" > Get ACL SUCCEEDED\n");
1087 static int unlinkPairwise(void)
1089 // check |own_list| for unlinking pairwise devices
1090 if(!g_own_list || 2>g_own_cnt)
1092 printf(" > Owned Device List, to Unlink the Pairwise, is Empty\n");
1093 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1094 return 0; // normal case
1097 // select two devices for unlinking pairwise devices
1098 int dev_num[2] = {0};
1099 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
1101 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
1105 // call |OCUnlinkDevices| API actually
1106 // calling this API with callback actually acts like blocking
1107 // for error checking, the return value saved and printed
1109 printf(" Unlinking Selected Pairwise Devices..\n");
1111 OCUnlinkDevices((void*) g_ctx,
1112 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
1113 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
1115 if(OC_STACK_OK != rst)
1117 OIC_LOG_V(ERROR, TAG, "OCUnlinkDevices API error: %d", rst);
1120 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1122 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1126 // display the pairwise-unlinked result
1127 printf(" > Unlinked Selected Pairwise Devices\n");
1128 printf(" > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
1133 static int removeDevice(void)
1135 // check |own_list| for removing device
1136 if(!g_own_list || 1>g_own_cnt)
1138 printf(" > Owned Device List, to Remove Device, is Empty\n");
1139 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1140 return 0; // normal case
1143 // select device for removing it
1147 printf(" > Enter Device Number, for Removing Device: ");
1148 for(int ret=0; 1!=ret; )
1150 ret = scanf("%d", &dev_num);
1151 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1152 // '0x20<=code' is character region
1154 if(0<dev_num && g_own_cnt>=dev_num)
1158 printf(" Entered Wrong Number. Please Enter Again\n");
1161 // call |OCRemoveDevice| API actually
1162 // calling this API with callback actually acts like blocking
1163 // for error checking, the return value saved and printed
1165 printf(" Removing Selected Owned Device..\n");
1167 OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
1168 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
1169 if(OC_STACK_OK != rst)
1171 OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst);
1174 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1176 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1180 // display the removed result
1181 printf(" > Removed Selected Owned Device\n");
1182 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1187 static int removeDeviceWithUuid(void)
1189 char strUuid[64] = {0};
1191 printf("Input the UUID : ");
1192 for(int ret=0; 1!=ret; )
1194 ret = scanf("%63s", strUuid);
1195 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1196 // '0x20<=code' is character region
1198 OCStackResult rst = ConvertStrToUuid(strUuid, &revUuid);
1199 if(OC_STACK_OK != rst)
1201 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
1206 rst = OCRemoveDeviceWithUuid("RemoveDeviceWithUUID", DISCOVERY_TIMEOUT, &revUuid, removeDeviceCB);
1207 if(OC_STACK_OK != rst)
1209 OIC_LOG_V(ERROR, TAG, "OCRemoveDeviceWithUuid API error: %d", rst);
1213 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1215 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid callback error");
1219 // display the removed result
1220 printf(" > Removed %s Device\n", strUuid);
1221 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1226 OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
1228 OIC_LOG(INFO, TAG, "IN displayMutualVerifNumCB");
1230 if (NULL != mutualVerifNum)
1232 OIC_LOG(INFO, TAG, "############ mutualVerifNum ############");
1233 OIC_LOG_BUFFER(INFO, TAG, mutualVerifNum, MUTUAL_VERIF_NUM_LEN);
1234 OIC_LOG(INFO, TAG, "############ mutualVerifNum ############");
1235 OIC_LOG(INFO, TAG, "OUT displayMutualVerifNumCB");
1239 OIC_LOG(INFO, TAG, "############ Confirm on the Server side ############");
1244 OCStackResult confirmNumCB(void * ctx)
1251 printf(" > Press 1 if the mutual verification numbers are the same\n");
1252 printf(" > Press 0 if the mutual verification numbers are not the same\n");
1254 for (int ret=0; 1!=ret; )
1256 ret = scanf("%d", &userConfirm);
1257 for (; 0x20<=getchar(); ); // for removing overflow garbage
1258 // '0x20<=code' is character region
1260 if (1 == userConfirm)
1264 else if (0 == userConfirm)
1266 return OC_STACK_USER_DENIED_REQ;
1268 printf(" Entered Wrong Number. Please Enter Again\n");
1273 OCStackResult notifyInputStateCB(void * ctx)
1277 OIC_LOG(DEBUG, TAG, "IN notifyInputStateCB");
1278 OIC_LOG(DEBUG, TAG, "User input Callback in progress");
1279 OIC_LOG(DEBUG, TAG, "OUT notifyInputStateCB");
1284 #ifdef MULTIPLE_OWNER
1285 static int changeMultipleOwnershipTrnasferMode(void)
1287 // check |own_list| for removing device
1288 if(!g_own_list || 1>g_own_cnt)
1290 printf(" > Owned Device List is Empty\n");
1291 printf(" > Please Discover the Owned Devices, with [12] Menu\n");
1292 return 0; // normal case
1295 // select device for removing it
1299 printf(" > Enter Device Number, for MOT Device: ");
1300 for(int ret=0; 1!=ret; )
1302 ret = scanf("%d", &dev_num);
1303 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1304 // '0x20<=code' is character region
1306 if(0<dev_num && g_own_cnt>=dev_num)
1310 printf(" Entered Wrong Number. Please Enter Again\n");
1316 printf(" 0. Disable Multuple Ownership Transfer\n");
1317 printf(" 1. Enable Multuple Ownership Transfer\n");
1318 printf(" 2. (Not Supported yet) Timely Enable Multuple Ownership Transfer\n");
1319 printf(" > Enter Mode of Multuple Ownership Transfer : ");
1320 for(int ret=0; 1!=ret; )
1322 ret = scanf("%d", &mom);
1323 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1324 // '0x20<=code' is character region
1326 if(0 <= dev_num && OIC_NUMBER_OF_MOM_TYPE > dev_num)
1330 printf(" Entered Wrong Number. Please Enter Again\n");
1333 OCProvisionDev_t* motDev = getDevInst(g_own_list, dev_num);
1334 if(OC_STACK_OK == OCChangeMOTMode(NULL, motDev, (OicSecMomType_t)dev_num, updateDoxmForMOTCB))
1340 OIC_LOG(ERROR, TAG, "OCChangeMOTMode API error");
1344 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1346 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1353 static int selectMultipleOwnershipTrnasferMethod(void)
1355 // check |own_list| for removing device
1356 if(!g_mot_enable_list || 1>g_mot_enable_cnt)
1358 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1359 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1360 return 0; // normal case
1363 // select device for removing it
1367 printf(" > Enter Device Number, for MOT Device: ");
1368 for(int ret=0; 1!=ret; )
1370 ret = scanf("%d", &dev_num);
1371 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1372 // '0x20<=code' is character region
1374 if(0<dev_num && g_mot_enable_cnt>=dev_num)
1378 printf(" Entered Wrong Number. Please Enter Again\n");
1381 const int preconfOxm = 4;
1385 printf(" %d. (Not Supported)\n", OIC_JUST_WORKS);
1386 printf(" %d. Random PIN OxM\n", OIC_RANDOM_DEVICE_PIN);
1387 printf(" %d. (Not Supported)\n", OIC_MANUFACTURER_CERTIFICATE);
1388 printf(" %d. (Not Supported)\n", OIC_DECENTRALIZED_PUBLIC_KEY);
1389 printf(" %d. Pre-Configured PIN OxM\n", OIC_PRECONFIG_PIN);
1390 printf(" > Enter Number of OxM for Multiple Ownership Transfer : ");
1391 for(int ret=0; 1!=ret; )
1393 ret = scanf("%d", &oxm);
1394 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1395 // '0x20<=code' is character region
1397 if(OIC_PRECONFIG_PIN == oxm || OIC_RANDOM_DEVICE_PIN == oxm)
1401 printf(" Entered Wrong Number. Please Enter Again\n");
1404 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1405 if(OC_STACK_OK == OCSelectMOTMethod(NULL, motDev, (OicSecOxm_t)oxm, updateDoxmForMOTCB))
1411 OIC_LOG(ERROR, TAG, "OCSelectMOTMethod API error");
1415 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1417 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1424 static int provisionPreconfigPIN()
1426 // check |own_list| for removing device
1427 if(!g_mot_enable_list || 1>g_mot_enable_cnt)
1429 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1430 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1431 return 0; // normal case
1434 // select device for removing it
1438 printf(" > Enter Device Number, for MOT Device: ");
1439 for(int ret=0; 1!=ret; )
1441 ret = scanf("%d", &dev_num);
1442 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1443 // '0x20<=code' is character region
1445 if(0<dev_num && g_mot_enable_cnt>=dev_num)
1449 printf(" Entered Wrong Number. Please Enter Again\n");
1452 char preconfigPin[9] = {0};
1453 printf(" > Input the PreconfigPin (e.g. 12341234) : ");
1454 for(int ret=0; 1!=ret; )
1456 ret = scanf("%8s", preconfigPin);
1457 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1458 // '0x20<=code' is character region
1461 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1462 if(OC_STACK_OK == OCProvisionPreconfigPin(NULL, motDev, preconfigPin, strlen(preconfigPin), provisionCredCB))
1468 OIC_LOG(ERROR, TAG, "OCProvisionPreconfigPin API error");
1472 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1474 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1481 static int removeSubOwner(void)
1483 // check |g_mot_enable_list| for removing sub-owner
1484 if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
1486 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1487 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1488 return 0; // normal case
1491 // select resource server for removing sub-owner
1495 printf(" > Enter Device Number to remove sub-owner: ");
1496 for (int ret = 0; 1 != ret; )
1498 ret = scanf("%d", &dev_num);
1499 for( ; 0x20 <= getchar(); ); // for removing overflow garbages
1500 // '0x20<=code' is character region
1502 if (0 < dev_num && g_mot_enable_cnt >= dev_num)
1506 printf(" Entered Wrong Number. Please Enter Again\n");
1509 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1510 if (motDev && motDev->doxm && motDev->doxm->subOwners)
1512 OicSecSubOwner_t* subOwner = motDev->doxm->subOwners;
1516 printf(" [%zu] ", ++so_cnt);
1517 printUuid(&subOwner->uuid);
1519 subOwner = subOwner->next;
1525 printf(" > Enter SubOwner Number to be removed : ");
1526 for (int ret = 0; 1 != ret; )
1528 ret = scanf("%d", &so_num);
1529 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1530 // '0x20<=code' is character region
1532 if (0 < so_num && so_cnt >= so_num)
1535 subOwner = motDev->doxm->subOwners;
1538 if(so_num == ++target_num)
1540 if (OC_STACK_OK != OCRemoveSubOwner(NULL, motDev, &subOwner->uuid, deleteDoxmForMOTCB))
1547 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1549 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1554 subOwner = subOwner->next;
1558 printf(" Entered Wrong Number. Please Enter Again\n");
1563 printf(" SubOwner list is empty.\n");
1569 static int removeAllSubOwner(void)
1571 // check |g_mot_enable_list| for removing sub-owner
1572 if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
1574 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1575 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1576 return 0; // normal case
1579 // select resource server for removing sub-owner
1583 printf(" > Enter Device Number to remove sub-owner: ");
1584 for (int ret = 0; 1 != ret; )
1586 ret = scanf("%d", &dev_num);
1587 for( ; 0x20 <= getchar(); ); // for removing overflow garbages
1588 // '0x20<=code' is character region
1590 if (0 < dev_num && g_mot_enable_cnt >= dev_num)
1594 printf(" Entered Wrong Number. Please Enter Again\n");
1597 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1598 if (motDev && motDev->doxm && motDev->doxm->subOwners)
1600 if (OC_STACK_OK != OCRemoveAllSubOwner(NULL, motDev, deleteDoxmForMOTCB))
1607 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1609 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1616 printf(" SubOwner list is empty.\n");
1622 #endif //MULTIPLE_OWNER
1624 static int resetDevice(void)
1626 // check |own_list| for removing device
1627 if (!g_own_list || 1 > g_own_cnt)
1629 printf(" > Owned Device List, to Reset Device, is Empty\n");
1630 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1634 OCProvisionDev_t *dev = NULL;
1638 printf("************************************************************\n");
1639 printf("Reset device candidate list:\n");
1640 g_unown_cnt = printDevList(g_own_list);
1641 if(0 == g_unown_cnt)
1646 printf("Select number device from list\nor: -1 - escape\n");
1649 if (!scanf("%d",&c))
1654 if(0 == c && NULL != dev)
1670 for(int lst_cnt = 1; dev && lst_cnt != c; lst_cnt++, dev = dev->next);
1676 printf(" Resetting Selected Owned Device..\n");
1678 OCStackResult rst = SRPResetDevice(dev, resetDeviceCB);
1680 if (OC_STACK_OK != rst)
1682 OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst);
1686 if (waitCallbackRet()) // input |g_doneCB| flag implicitly
1688 OIC_LOG_V(ERROR, TAG, "%s: callback error", __func__);
1692 // display the removed result
1693 printf(" > Reset Selected Owned Device SUCCEEDED\n");
1694 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1699 static int resetSVRDB(void)
1701 printf(" Resetting SVR DB..\n");
1702 OCStackResult rst = OCResetSVRDB();
1703 if (OC_STACK_OK != rst)
1705 OIC_LOG_V(ERROR, TAG, "OCResetSVRDB API error: %d", rst);
1711 static OicSecAcl_t* createAcl(const int dev_num)
1713 if(0>=dev_num || g_own_cnt<dev_num)
1715 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
1716 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1719 // allocate memory for |acl| struct
1720 printf(" **** Create ACL for the Selected Device[%d]\n", dev_num);
1721 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
1724 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1725 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1727 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
1730 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1731 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1733 LL_APPEND(acl->aces, ace);
1735 // enter |subject| device number
1739 printf(" > [A] Enter Subject Device Number: ");
1740 for(int ret=0; 1!=ret; )
1742 ret = scanf("%d", &num);
1743 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1744 // '0x20<=code' is character region
1746 if(0<num && g_own_cnt>=num && dev_num!=num)
1750 printf(" Entered Wrong Number. Please Enter Again\n");
1753 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, num);
1754 if(!dev || !dev->doxm)
1756 OIC_LOG(ERROR, TAG, "createAcl: device instance empty");
1759 memcpy(&ace->subjectuuid, &dev->doxm->deviceID, UUID_LENGTH);
1761 // enter number of |resources| in 'accessed' device
1764 printf(" > [B] Enter Number of Accessed Resources (under 16): ");
1765 // '16' is |ACL_RESRC_MAX_NUM|
1766 for(int ret=0; 1!=ret; )
1768 ret = scanf("%d", &num);
1769 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1770 // '0x20<=code' is character region
1772 if(0<num && ACL_RESRC_MAX_NUM>=num)
1776 printf(" Entered Wrong Number. Please Enter under 16 Again\n");
1777 // '16' is |ACL_RESRC_MAX_NUM|
1780 // enter actually each 'accessed' |resources| name
1781 printf(" Enter Each Accessed Resource Name (each under 128 char)\n");
1782 // '128' is ACL_RESRC_MAX_LEN
1784 char rsrc_in[ACL_RESRC_MAX_LEN+1] = {0}; // '1' for null termination
1785 for(int i = 0; num > i; ++i)
1787 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
1790 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1794 printf(" Enter Accessed Resource[%d] Name: (e.g. /a/led)", i+1);
1795 for(int ret=0; 1!=ret; )
1797 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1798 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1799 // '0x20<=code' is character region
1801 size_t len = strlen(rsrc_in)+1; // '1' for null termination
1802 rsrc->href = (char*) OICCalloc(len, sizeof(char));
1805 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1808 OICStrcpy(rsrc->href, len, rsrc_in);
1813 printf(" Enter Number of resource type for [%s] : ", rsrc->href);
1814 for(int ret=0; 1!=ret; )
1816 ret = scanf("%zu", &arrLen);
1817 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1818 // '0x20<=code' is character region
1820 if(ACL_RESRC_ARRAY_SIZE >= arrLen)
1824 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1827 rsrc->typeLen = arrLen;
1828 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
1831 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1835 for(size_t i = 0; i < arrLen; i++)
1837 printf(" Enter ResourceType[%zu] Name (e.g. core.led): ", i+1);
1838 for(int ret=0; 1!=ret; )
1840 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1841 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1842 // '0x20<=code' is character region
1844 rsrc->types[i] = OICStrdup(rsrc_in);
1847 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1854 printf(" Enter Number of interface for [%s]: ", rsrc->href);
1855 for(int ret=0; 1!=ret; )
1857 ret = scanf("%zu", &arrLen);
1858 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1859 // '0x20<=code' is character region
1861 if(ACL_RESRC_ARRAY_SIZE >= arrLen)
1865 printf(" Entered Wrong Number. Please Enter under %d Again\n", ACL_RESRC_ARRAY_SIZE);
1868 rsrc->interfaceLen = arrLen;
1869 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
1870 if(!rsrc->interfaces)
1872 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
1876 for(size_t i = 0; i < arrLen; i++)
1878 printf(" Enter Interface[%zu] Name (e.g. oic.if.baseline): ", i+1);
1879 for(int ret=0; 1!=ret; )
1881 ret = scanf("%128s", rsrc_in); // '128' is ACL_RESRC_MAX_LEN
1882 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1883 // '0x20<=code' is character region
1885 rsrc->interfaces[i] = OICStrdup(rsrc_in);
1886 if(!rsrc->interfaces[i])
1888 OIC_LOG(ERROR, TAG, "createAcl: OICStrdup error return");
1893 LL_APPEND(ace->resources, rsrc);
1896 // enter |permission| for this access
1897 printf(" > [C] Enter Permission for This Access\n");
1898 uint16_t pmsn = PERMISSION_FULL_CONTROL; // default full permission
1899 uint16_t pmsn_msk = PERMISSION_CREATE; // default permission mask
1900 for(int i=0; ACL_PEMISN_CNT>i; ++i)
1905 printf(" Enter %s Permission (y/n): ", ACL_PEMISN[i]);
1906 for(int ret=0; 1!=ret; )
1908 ret = scanf("%c", &ans);
1909 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1910 // '0x20<=code' is character region
1912 if('y'==ans || 'Y'==ans || 'n'==ans|| 'N'==ans)
1914 ans &= ~0x20; // for masking lower case, 'y/n'
1917 printf(" Entered Wrong Answer. Please Enter 'y/n' Again\n");
1919 if('N' == ans) // masked lower case, 'n'
1925 ace->permission = pmsn;
1930 OCDeleteACLList(acl); // after here |acl| points nothing
1934 static OicSecAcl_t* createSimpleAcl(const OicUuid_t uuid)
1936 OIC_LOG(DEBUG, TAG, "createSimpleAcl IN");
1938 // allocate memory for |acl| struct
1939 OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
1942 OIC_LOG(DEBUG, TAG, "OICCalloc error return");
1943 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1945 OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
1948 OIC_LOG(DEBUG, TAG, "OICCalloc error return");
1949 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
1951 LL_APPEND(acl->aces, ace);
1953 memcpy(&ace->subjectuuid, &uuid, UUID_LENGTH);
1955 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
1958 OIC_LOG(DEBUG, TAG, "OICCalloc error return");
1959 OCDeleteACLList(acl);
1964 size_t len = strlen(href)+1; // '1' for null termination
1965 rsrc->href = (char*) OICCalloc(len, sizeof(char));
1968 OIC_LOG(DEBUG, TAG, "OICCalloc error return");
1969 OCDeleteACLList(acl);
1972 OICStrcpy(rsrc->href, len, href);
1975 rsrc->typeLen = arrLen;
1976 rsrc->types = (char**)OICCalloc(arrLen, sizeof(char*));
1979 OIC_LOG(DEBUG, TAG, "OICCalloc error return");
1980 OCDeleteACLList(acl);
1983 rsrc->types[0] = OICStrdup(""); // ignore
1985 rsrc->interfaceLen = 1;
1986 rsrc->interfaces = (char**)OICCalloc(arrLen, sizeof(char*));
1987 if(!rsrc->interfaces)
1989 OIC_LOG(DEBUG, TAG, "OICCalloc error return");
1990 OCDeleteACLList(acl);
1993 rsrc->interfaces[0] = OICStrdup("oic.if.baseline"); // ignore
1995 LL_APPEND(ace->resources, rsrc);
1997 ace->permission = 31; // R/W/U/D
1999 OIC_LOG(DEBUG, TAG, "createSimpleAcl OUT");
2004 static OicSecPdAcl_t* createPdAcl(const int dev_num)
2006 if(0>=dev_num || g_own_cnt<dev_num)
2008 OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
2009 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
2012 // allocate memory for |pdacl| struct
2013 printf(" **** Create PDACL for the Selected Device[%d]\n", dev_num);
2014 OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
2017 OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
2018 return NULL; // not need to 'goto' |ERROR| before allocating |acl|
2022 // number of resources
2023 char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
2024 pdAcl->resourcesLen = 1;
2027 int num = pdAcl->resourcesLen;
2028 pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
2029 if(!pdAcl->resources)
2031 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
2034 for(int i=0; num>i; ++i)
2036 size_t len = strlen(rsrc_in[i])+1; // '1' for null termination
2037 char* rsrc = (char*) OICCalloc(len, sizeof(char));
2040 OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
2043 OICStrcpy(rsrc, len, rsrc_in[i]);
2044 pdAcl->resources[i] = rsrc; // after here, |rsrc| points nothing
2048 pdAcl->permission = PERMISSION_FULL_CONTROL;
2053 OCDeletePdAclList(pdAcl);
2057 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
2059 if(!dev_lst || 0>=dev_num)
2061 printf(" Device List is Empty..\n");
2065 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
2075 return NULL; // in here |lst| is always |NULL|
2078 static int printDevList(const OCProvisionDev_t* dev_lst)
2082 printf(" Device List is Empty..\n\n");
2086 OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
2090 printf(" [%d] ", ++lst_cnt);
2091 printUuid((const OicUuid_t*) &lst->doxm->deviceID);
2100 static size_t printUuidList(const OCUuidList_t* uid_lst)
2104 printf(" Device List is Empty..\n\n");
2108 OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
2112 printf(" [%zu] ", ++lst_cnt);
2113 printUuid((const OicUuid_t*) &lst->dev);
2122 static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
2124 if(!rslt_lst || 0>=rslt_cnt)
2126 printf(" Device List is Empty..\n\n");
2131 for( ; rslt_cnt>lst_cnt; ++lst_cnt)
2133 printf(" [%d] ", lst_cnt+1);
2134 printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
2135 printf(" - result: %d\n", rslt_lst[lst_cnt].res);
2142 static void printUuid(const OicUuid_t* uid)
2144 for(int i=0; i<UUID_LENGTH; )
2146 printf("%02X", (*uid).id[i++]);
2147 if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
2154 static FILE* fopen_prvnMng(const char* path, const char* mode)
2156 (void)path; // unused |path| parameter
2158 // input |g_svr_db_fname| internally by force, not using |path| parameter
2159 // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
2160 // with its own |SVR_DB_FILE_NAME|
2161 return fopen(SVR_DB_FILE_NAME, mode);
2164 static int peerCertCallback(void *ctx, const mbedtls_x509_crt *cert, int depth)
2168 OIC_LOG_V(DEBUG, TAG, "Depth : %d", depth);
2169 OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
2170 OIC_LOG(DEBUG, TAG, "***** Serial number of certificate is below *****");
2171 OIC_LOG_BUFFER(DEBUG, TAG, cert->serial.p, cert->serial.len);
2172 OIC_LOG(DEBUG, TAG, "***** Serial number of certificate is above *****");
2173 OIC_LOG_V(DEBUG, TAG, "OUT%s", __func__);
2178 static int waitCallbackRet(void)
2180 for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
2183 if(OC_STACK_OK != OCProcess())
2185 OIC_LOG(ERROR, TAG, "OCStack process error");
2192 OCPDMCleanupForTimeout();
2198 static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
2200 if(!a || !b || 2>max || !str)
2207 for(int i=0; 2>i; ++i)
2209 int* num = 0==i?a:b;
2212 printf(" > Enter Device[%d] Number, %s: ", i+1, str);
2213 for(int ret=0; 1!=ret; )
2215 ret = scanf("%d", num);
2216 for( ; 0x20<=getchar(); ); // for removing overflow garbages
2217 // '0x20<=code' is character region
2219 if(0<*num && max>=*num)
2223 printf(" Entered Wrong Number. Please Enter Again\n");
2238 static void setDevProtocol(OCProvisionDev_t* lst)
2242 printf(" Device List is Empty..\n\n");
2248 if(2 == secure_protocol)
2250 lst->connType &= ~CT_ADAPTER_IP; //reset IP flag
2251 lst->connType |= CT_ADAPTER_TCP; //set TCP flag
2252 lst->endpoint.adapter = OC_ADAPTER_TCP;
2253 lst->endpoint.port = lst->tcpPort;
2254 lst->securePort = lst->tcpPort;
2260 static void selectSecureProtocol()
2262 printf(" Select protocol\n");
2263 printf(" 1 - DTLS(Default)\n");
2264 printf(" 2 - TLS\n");
2266 for(int ret=0; 1!=ret; )
2268 ret = scanf("%d",&secure_protocol);
2269 for( ; 0x20<=getchar(); ); // for removing overflow garbages
2270 // '0x20<=code' is character region
2273 if(0 >= secure_protocol || 2 < secure_protocol)
2275 secure_protocol = 1;
2278 setDevProtocol(g_own_list);
2279 setDevProtocol(g_unown_list);
2283 static void secureStorageHwEmulation()
2285 printf(" Enable Secure Storage HW Emulation\n");
2287 printf(" Enter Own Certificate File Path[~4095]: ");
2288 char cert_filepath[4096] = {0,};
2289 for(int ret=0; 1!=ret; )
2291 ret = scanf("%255s", cert_filepath);
2292 for( ; 0x20<=getchar(); ); // for removing overflow garbages
2293 // '0x20<=code' is character region
2296 printf(" Enter Private Key File Path[~4095]: ");
2297 char key_filepath[4096] = {0,};
2298 for(int ret=0; 1!=ret; )
2300 ret = scanf("%255s", key_filepath);
2301 for( ; 0x20<=getchar(); ); // for removing overflow garbages
2302 // '0x20<=code' is character region
2305 printf(" Enter Password for Key Password[~31][Press (Enter) to not set]: ");
2306 char pwd[32] = {0,};
2307 for(int i=0; i < 31; i++)
2309 pwd[i] = (char)getchar();
2322 if (0 != SSemulSetCertkeyFilepath(cert_filepath, key_filepath, pwd))
2324 printf(" Fail to set cert/key file path");
2328 if (0 != SetHwPkixCallbacks(HWGetKeyContext,
2330 HWGetOwnCertificateChain,
2333 printf(" Fail to regist HW Pkix Callbacks");
2336 printf(" Success to regist HW Pkix Callbacks");
2339 static void selectVerifMethod()
2342 printf(" Select verification method for ownership transfer\n");
2343 printf(" 0 - No verification\n");
2344 printf(" 1 - Display only\n");
2345 printf(" 2 - Confirm only\n");
2346 printf(" 3 - Both Display and Confirm\n");
2348 for(int ret=0; 1!=ret; )
2350 ret = scanf("%d",&option);
2351 for( ; 0x20<=getchar(); ); // for removing overflow garbages
2352 // '0x20<=code' is character region
2355 if(0 > option || 3 < option)
2357 printf("Invalid option!");
2359 SetVerifyOption((VerifyOptionBitmask_t) option);
2360 printf("Option %d chosen!", option);
2363 static void printMenu(void)
2365 printf("************************************************************\n");
2366 printf("****** OIC Provisioning Client with using C-level API ******\n");
2367 printf("************************************************************\n\n");
2369 printf("** [A] DISCOVER DEVICES ON NETWORK\n");
2370 printf("** 10. Discover All Un/Owned Devices on Network\n");
2371 printf("** 11. Discover Only Unowned Devices on Network\n");
2372 #ifdef MULTIPLE_OWNER
2373 printf("** 12. Discover Only Owned Devices on Network\n");
2374 printf("** 13. Discover Multiple Ownership Transfer Enabled Devices on Network\n\n");
2376 printf("** 12. Discover Only Owned Devices on Network\n\n");
2377 #endif //MULTIPLE_OWNER
2379 printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n");
2380 printf("** 20. Register/Own All Discovered Unowned Devices\n\n");
2382 printf("** [C] PROVISION/LINK PAIRWISE THINGS\n");
2383 printf("** 30. Provision/Link Pairwise Things\n");
2384 printf("** 31. Provision Credentials for Pairwise Things\n");
2385 printf("** 32. Provision the Selected Access Control List(ACL)\n");
2386 printf("** 33. Provision Direct-Pairing Configuration\n");
2387 printf("** 34. Check Linked Status of the Selected Device on PRVN DB\n");
2388 printf("** 35. Save the Selected Access Control List(ACL) into local SVR DB\n\n");
2390 printf("** [D] UNLINK PAIRWISE THINGS\n");
2391 printf("** 40. Unlink Pairwise Things\n\n");
2393 printf("** [E] REMOVE THE SELECTED DEVICE\n");
2394 printf("** 50. Remove the Selected Device\n");
2395 printf("** 51. Remove Device with UUID (UUID input is required)\n");
2396 printf("** 52. Reset the Selected Device\n");
2397 printf("** 53. Reset SVR DB\n\n");
2399 printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n");
2400 printf("** 60. Get the Credential resources of the Selected Device\n");
2401 printf("** 61. Get the ACL resources of the Selected Device\n\n");
2403 #ifdef MULTIPLE_OWNER
2404 printf("** [G] UPDATE THE MULTIPLE OWNERSHIP TRANSFER RELATED VALUE\n");
2405 printf("** 70. Change the Multiple Ownership transfer MODE(update mom)\n");
2406 printf("** 71. Provision Preconfigured PIN\n");
2407 printf("** 72. Change the Multiple Ownership transfer METHOD(update oxmsel)\n");
2408 printf("** 73. Remove Sub-Owner from Resource Server\n");
2409 printf("** 74. Remove All Sub-Owner from Resource Server\n\n");
2410 #endif //MULTIPLE_OWNER
2413 printf("** [H] SELECT SECURE PROTOCOL DTLS/TLS AND OTHERS\n");
2414 printf("** 80. Select secure protocol(default DTLS)\n");
2415 printf("** 81. Select verification method\n");
2416 printf("** 82. Enable secure storage hw emulation\n\n");
2418 printf("** [H] SELECT VERIFICATION OPTION\n");
2419 printf("** 81. Select verification method\n\n");
2421 printf("** [I] EXIT PROVISIONING CLIENT\n");
2423 printf("** 99. Exit Provisionong Client\n\n");
2425 printf("************************************************************\n\n");
2428 #if 0 // Code for enabling path configuration for PDB and SVR DBf
2429 static void printUsage(void)
2432 printf("OIC Provisioning Client with using C-level API\n");
2433 printf("Usage: provisioningclient [option]...\n");
2435 printf(" -h print help for this provisioning client\n");
2436 printf(" -p=[prvn_db_file_path/name] input PRVN DB file path and name\n");
2437 printf(" if not exists, will load default DB file\n");
2438 printf(" (default: |oic_prvn_mng.db| on working dir)\n");
2439 printf(" (ex. -p=oic_prvn_mng.db)\n");
2440 printf(" -s=[svr_db_file_path/name] input SVR DB file path and name\n");
2441 printf(" if not exists, will load default DB file\n");
2442 printf(" (default: |oic_svr_db_client.json| on working dir)\n");
2443 printf(" (ex. -s=oic_svr_db_client.json)\n");
2449 * Sample implementation of Export key block and master secret
2451 * @param[in] p_expkey Context for the callback
2452 * @aram[in] ms Pointer to master secret (fixed length: 48 bytes)
2453 * @param[in] kb Pointer to key block, see RFC 5246 section 6.3
2454 * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
2455 * @param[in] maclen MAC length
2456 * @param[in] keylen Key length
2457 * @param[in] ivlen IV length
2459 static void SslExportKeysCallback(const unsigned char* masterSecret,
2460 const unsigned char* keyBlock,
2461 size_t macLen, size_t keyLen, size_t ivLen)
2463 OIC_LOG_V(INFO, TAG, "In %s ", __func__);
2465 OIC_LOG(INFO, TAG, "[MASTER SECRET] : ");
2466 OIC_LOG_BUFFER(INFO, TAG, masterSecret, 48);
2468 OIC_LOG(INFO, TAG, "[KEY BLOCK] : ");
2469 OIC_LOG_BUFFER(INFO, TAG, keyBlock, (2 * macLen) + (2 * keyLen) + (2 * ivLen));
2471 OIC_LOG_V(INFO, TAG, "Mac Length = %zu, Key Length = %zu, IV Length = %zu",
2472 macLen, keyLen, ivLen);
2474 OIC_LOG_V(INFO, TAG, "Out %s ", __func__);
2477 // main function for provisioning client using C-level provisioning API
2480 // initialize provisioning client
2481 if(initProvisionClient())
2483 OIC_LOG(ERROR, TAG, "ProvisionClient init error");
2488 CASetSslExportKeysCallback(SslExportKeysCallback, CA_SSL_EKCB_DTLS, CA_SSL_EKCB_CLIENT))
2490 OIC_LOG(ERROR, TAG, "Failed to register the (D)TLS export Key Callback!");
2494 // Client can choose a allowed/not-allowed OxM method.
2495 if(OC_STACK_OK != OCSetOxmAllowStatus(OIC_DECENTRALIZED_PUBLIC_KEY, false))
2497 OIC_LOG(WARNING, TAG, "Failed to disable OIC_DECENTRALIZED_PUBLIC_KEY OxM");
2500 // set callbacks for verification options
2501 SetDisplayNumCB(NULL, displayNumCB);
2502 SetUserConfirmCB(NULL, confirmNumCB);
2503 SetInputStateCB(NULL, notifyInputStateCB);
2505 // set callback for checking peer certificate information
2506 OCSetPeerCertCallback(NULL, peerCertCallback);
2508 #ifdef MULTIPLE_OWNER
2509 SetPreconfigPin("12341234", 8);
2510 #endif //MULTIPLE_OWNER
2512 // main loop for provisioning manager
2518 printf(">> Enter Menu Number: ");
2519 for(int ret=0; 1!=ret; )
2521 ret = scanf("%d", &mn_num);
2522 for( ; 0x20<=getchar(); ); // for removing overflow garbages
2523 // '0x20<=code' is character region
2528 case _10_DISCOV_ALL_DEVS_:
2529 if(discoverAllDevices())
2531 OIC_LOG(ERROR, TAG, "_10_DISCOV_ALL_DEVS_: error");
2534 case _11_DISCOV_UNOWN_DEVS_:
2535 if(discoverUnownedDevices())
2537 OIC_LOG(ERROR, TAG, "_11_DISCOV_UNOWN_DEVS_: error");
2540 case _12_DISCOV_OWN_DEVS_:
2541 if(discoverOwnedDevices())
2543 OIC_LOG(ERROR, TAG, "_12_DISCOV_OWN_DEVS_: error");
2546 #ifdef MULTIPLE_OWNER
2547 case _13_MOT_DISCOV_DEV_:
2548 if(discoverMOTEnabledDevices())
2550 OIC_LOG(ERROR, TAG, "_13_MOT_DISCOV_DEV_: error");
2553 #endif //MULTIPLE_OWNER
2554 case _20_REGIST_DEVS_:
2555 if(registerDevices())
2557 OIC_LOG(ERROR, TAG, "_20_REGIST_DEVS_: error");
2560 case _30_PROVIS_PAIR_DEVS_:
2561 if(provisionPairwise())
2563 OIC_LOG(ERROR, TAG, "_30_PROVIS_PAIR_DEVS_: error");
2566 case _31_PROVIS_CRED_:
2569 OIC_LOG(ERROR, TAG, "_31_PROVIS_CRED_: error");
2572 case _32_PROVIS_ACL_:
2575 OIC_LOG(ERROR, TAG, "_32_PROVIS_ACL_: error");
2578 case _33_PROVIS_DP_:
2579 if(provisionDirectPairing())
2581 OIC_LOG(ERROR, TAG, "_33_PROVIS_DP_: error");
2584 case _34_CHECK_LINK_STATUS_:
2585 if(checkLinkedStatus())
2587 OIC_LOG(ERROR, TAG, "_34_CHECK_LINK_STATUS_: error");
2593 OIC_LOG(ERROR, TAG, "_35_SAVE_ACL_: error");
2596 case _40_UNLINK_PAIR_DEVS_:
2597 if(unlinkPairwise())
2599 OIC_LOG(ERROR, TAG, "_40_UNLINK_PAIR_DEVS_: error");
2602 case _50_REMOVE_SELEC_DEV_:
2605 OIC_LOG(ERROR, TAG, "_50_REMOVE_SELEC_DEV_: error");
2608 case _51_REMOVE_DEV_WITH_UUID_:
2609 if(removeDeviceWithUuid())
2611 OIC_LOG(ERROR, TAG, "_51_REMOVE_DEV_WITH_UUID_: error");
2614 case _52_RESET_SELEC_DEV_:
2617 OIC_LOG(ERROR, TAG, "_52_RESET_SELEC_DEV_: error");
2620 case _53_RESET_SVR_DB_:
2623 OIC_LOG(ERROR, TAG, "_53_RESET_SVR_DB_: error");
2629 OIC_LOG(ERROR, TAG, "_60_GET_CRED_: error");
2635 OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error");
2638 #ifdef MULTIPLE_OWNER
2639 case _70_MOT_CHANGE_MOM_:
2640 if(changeMultipleOwnershipTrnasferMode())
2642 OIC_LOG(ERROR, TAG, "_70_MOT_CHANGE_MOM_: error");
2645 case _71_MOT_PROV_PRECONF_PIN_:
2646 if(provisionPreconfigPIN())
2648 OIC_LOG(ERROR, TAG, "_71_MOT_PROV_PRECONF_PIN_: error");
2651 case _72_MOT_OXM_SEL_:
2652 if(selectMultipleOwnershipTrnasferMethod())
2654 OIC_LOG(ERROR, TAG, "_72_MOT_OXM_SEL_: error");
2657 case _73_MOT_REMOVE_SUBOWNER_:
2658 if(removeSubOwner())
2660 OIC_LOG(ERROR, TAG, "_73_MOT_REMOVE_SUBOWNER_ : error");
2663 case _74_MOT_REMOVE_ALL_SUBOWNER_:
2664 if(removeAllSubOwner())
2666 OIC_LOG(ERROR, TAG, "_74_MOT_REMOVE_ALL_SUBOWNER_ : error");
2669 #endif //MULTIPLE_OWNER
2671 case _80_SELECT_PROTOCOL_:
2672 selectSecureProtocol();
2675 case _81_SELECT_VERIF_METHOD_:
2676 selectVerifMethod();
2678 case _82_SECURE_STORAGE_HW_EMULATION_:
2679 secureStorageHwEmulation();
2681 case _99_EXIT_PRVN_CLT_:
2684 printf(">> Entered Wrong Number. Please Enter Again\n\n");
2690 if(OC_STACK_OK != OCStop())
2692 OIC_LOG(ERROR, TAG, "OCStack stop error");
2694 OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
2695 OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
2696 #ifdef MULTIPLE_OWNER
2697 OCDeleteDiscoveredDevices(g_mot_enable_list); // after here |g_motdev_list| points nothing
2698 #endif //MULTIPLE_OWNER
2702 OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
2706 OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
2708 return 0; // always return normal case
2713 #endif //__cplusplus