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"
43 #include "secureresourceprovider.h"
50 // declaration(s) for provisioning client using C-level provisioning API
51 // user input definition for main loop on provisioning client
52 #define _10_DISCOV_ALL_DEVS_ 10
53 #define _11_DISCOV_UNOWN_DEVS_ 11
54 #define _12_DISCOV_OWN_DEVS_ 12
56 #define _13_MOT_DISCOV_DEV_ 13
57 #endif //MULTIPLE_OWNER
58 #define _20_REGIST_DEVS_ 20
59 #define _30_PROVIS_PAIR_DEVS_ 30
60 #define _31_PROVIS_CRED_ 31
61 #define _32_PROVIS_ACL_ 32
62 #define _33_PROVIS_DP_ 33
63 #define _34_CHECK_LINK_STATUS_ 34
64 #define _35_SAVE_ACL_ 35
65 #define _40_UNLINK_PAIR_DEVS_ 40
66 #define _50_REMOVE_SELEC_DEV_ 50
67 #define _51_REMOVE_DEV_WITH_UUID_ 51
68 #define _52_RESET_SELEC_DEV_ 52
69 #define _53_RESET_SVR_DB_ 53
70 #define _60_GET_CRED_ 60
71 #define _61_GET_ACL_ 61
73 #define _70_MOT_CHANGE_MOM_ 70
74 #define _71_MOT_PROV_PRECONF_PIN_ 71
75 #define _72_MOT_OXM_SEL_ 72
76 #define _73_MOT_REMOVE_SUBOWNER_ 73
77 #define _74_MOT_REMOVE_ALL_SUBOWNER_ 74
78 #endif //MULTIPLE_OWNER
79 #define _80_SELECT_PROTOCOL_ 80
80 #define _81_SELECT_VERIF_METHOD_ 81
81 #define _82_SECURE_STORAGE_HW_EMULATION_ 82
82 #define _99_EXIT_PRVN_CLT_ 99
84 #define ACL_RESRC_MAX_NUM 16
85 #define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
86 #define ACL_RESRC_MAX_LEN 128
87 #define ACL_PEMISN_CNT 5
88 #define DISCOVERY_TIMEOUT 10 // 10 sec
89 #define CALLBACK_TIMEOUT 60 // 1 min
90 #define TAG "provisioningclient"
92 static const char* ACL_PEMISN[5] = {"CREATE", "READ", "WRITE", "DELETE", "NOTIFY"};
93 static const char* SVR_DB_FILE_NAME = "oic_svr_db_client.dat";
94 // '_' for separaing from the same constant variable in |srmresourcestrings.c|
95 static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
96 static const OicSecPrm_t SUPPORTED_PRMS[1] =
101 // |g_ctx| means provision manager application context and
102 // the following, includes |un/own_list|, could be variables, which |g_ctx| has,
103 // for accessing all function(s) for these, they are declared on global domain
104 static const char* g_ctx = "Provision Manager Client Application Context";
105 static char* g_svr_fname;
106 static char* g_prvn_fname;
107 static OCProvisionDev_t* g_own_list;
108 static OCProvisionDev_t* g_unown_list;
109 static int g_own_cnt;
110 static int g_unown_cnt;
111 #ifdef MULTIPLE_OWNER
112 static OCProvisionDev_t* g_mot_enable_list;
113 static int g_mot_enable_cnt;
114 #endif //MULTIPLE_OWNER
116 static bool g_doneCB;
118 static int secure_protocol = 1;
119 static void setDevProtocol(OCProvisionDev_t* dev_lst);
121 // function declaration(s) for calling them before implementing
122 static OicSecAcl_t* createAcl(const int);
123 static OicSecAcl_t* createSimpleAcl(const OicUuid_t uuid);
124 static OicSecPdAcl_t* createPdAcl(const int);
125 static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
126 static int printDevList(const OCProvisionDev_t*);
127 static size_t printUuidList(const OCUuidList_t*);
128 static int printResultList(const OCProvisionResult_t*, const int);
129 static void printUuid(const OicUuid_t*);
130 static FILE* fopen_prvnMng(const char*, const char*);
131 static int waitCallbackRet(void);
132 static int selectTwoDiffNum(int*, int*, const int, const char*);
134 // callback function(s) for provisioning client using C-level provisioning API
135 static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
139 OIC_LOG_V(INFO, TAG, "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
143 OIC_LOG_V(ERROR, TAG, "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
144 printResultList((const OCProvisionResult_t*) arr, nOfRes);
149 static void provisionPairwiseCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
153 OIC_LOG_V(INFO, TAG, "Provision Pairwise SUCCEEDED - ctx: %s", (char*) ctx);
157 OIC_LOG_V(ERROR, TAG, "Provision Pairwise FAILED - ctx: %s", (char*) ctx);
158 printResultList((const OCProvisionResult_t*) arr, nOfRes);
163 static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
167 OIC_LOG_V(INFO, TAG, "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
171 OIC_LOG_V(ERROR, TAG, "Provision Credential FAILED - ctx: %s", (char*) ctx);
172 printResultList((const OCProvisionResult_t*) arr, nOfRes);
177 static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
181 OIC_LOG_V(INFO, TAG, "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
185 OIC_LOG_V(ERROR, TAG, "Provision ACL FAILED - ctx: %s", (char*) ctx);
186 printResultList((const OCProvisionResult_t*) arr, nOfRes);
191 static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
195 OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx);
199 OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx);
200 printResultList((const OCProvisionResult_t*) arr, nOfRes);
205 static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
209 OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx);
213 OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx);
214 printResultList((const OCProvisionResult_t*) arr, nOfRes);
219 static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
223 OIC_LOG_V(INFO, TAG, "Provision Direct-Pairing SUCCEEDED - ctx: %s", (char*) ctx);
227 OIC_LOG_V(ERROR, TAG, "Provision Direct-Pairing FAILED - ctx: %s", (char*) ctx);
228 printResultList((const OCProvisionResult_t*) arr, nOfRes);
233 static void unlinkDevicesCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
237 OIC_LOG_V(INFO, TAG, "Unlink Devices SUCCEEDED - ctx: %s", (char*) ctx);
241 OIC_LOG_V(ERROR, TAG, "Unlink Devices FAILED - ctx: %s", (char*) ctx);
242 printResultList((const OCProvisionResult_t*) arr, nOfRes);
247 static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
251 OIC_LOG_V(INFO, TAG, "Remove Device SUCCEEDED - ctx: %s", (char*) ctx);
255 OIC_LOG_V(ERROR, TAG, "Remove Device FAILED - ctx: %s", (char*) ctx);
256 printResultList((const OCProvisionResult_t*) arr, nOfRes);
261 static void resetDeviceCB(void* ctx)
264 OIC_LOG_V(INFO, TAG, "Reset Device SUCCEEDED");
268 #ifdef MULTIPLE_OWNER
269 static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
273 OIC_LOG_V(INFO, TAG, "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
277 OIC_LOG_V(ERROR, TAG, "POST 'doxm' FAILED - ctx: %s", (char*) ctx);
278 printResultList((const OCProvisionResult_t*) arr, nOfRes);
283 static void deleteDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
287 OIC_LOG_V(INFO, TAG, "DELETE 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
291 OIC_LOG_V(ERROR, TAG, "DELETE 'doxm' FAILED - ctx: %s", (char*) ctx);
292 printResultList((const OCProvisionResult_t*) arr, nOfRes);
297 #endif //MULTIPLE_OWNER
299 static void inputPinCB(char* pin, size_t len)
301 if(!pin || OXM_RANDOM_PIN_MIN_SIZE > len)
303 OIC_LOG(ERROR, TAG, "inputPinCB invalid parameters");
307 printf(" > INPUT PIN: ");
308 for(int ret=0; 1!=ret; )
310 ret = scanf("%32s", pin);
311 for( ; 0x20<=getchar(); ); // for removing overflow garbages
312 // '0x20<=code' is character region
316 // function(s) for provisioning client using C-level provisioning API
317 static int initProvisionClient(void)
319 // initialize persistent storage for SVR DB
320 static OCPersistentStorage pstStr =
322 .open = fopen_prvnMng,
328 if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&pstStr))
330 OIC_LOG(ERROR, TAG, "OCRegisterPersistentStorageHandler error");
334 // initialize OC stack and provisioning manager
335 if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
337 OIC_LOG(ERROR, TAG, "OCStack init error");
341 if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
343 printf("************************************************************\n");
344 printf("************Provisioning DB file already exists.************\n");
345 printf("************************************************************\n");
349 printf("*************************************************************\n");
350 printf("************No provisioning DB file, creating new************\n");
351 printf("*************************************************************\n");
354 if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
356 OIC_LOG(ERROR, TAG, "OC_PM init error");
360 SetInputPinCB(inputPinCB);
365 static int discoverAllDevices(void)
367 // delete un/owned device lists before updating them
370 OCDeleteDiscoveredDevices(g_own_list);
375 OCDeleteDiscoveredDevices(g_unown_list);
379 // call |OCGetDevInfoFromNetwork| API actually
380 printf(" Discovering All Un/Owned Devices on Network..\n");
381 if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list))
383 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error");
387 // display the discovered un/owned lists
388 printf(" > Discovered Owned Devices\n");
389 g_own_cnt = printDevList(g_own_list);
390 printf(" > Discovered Unowned Devices\n");
391 g_unown_cnt = printDevList(g_unown_list);
393 setDevProtocol(g_own_list);
394 setDevProtocol(g_unown_list);
400 static int discoverUnownedDevices(void)
402 // delete unowned device list before updating it
405 OCDeleteDiscoveredDevices(g_unown_list);
409 // call |OCDiscoverUnownedDevices| API actually
410 printf(" Discovering Only Unowned Devices on Network..\n");
411 if(OC_STACK_OK != OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unown_list))
413 OIC_LOG(ERROR, TAG, "OCDiscoverUnownedDevices API error");
417 // display the discovered unowned list
418 printf(" > Discovered Unowned Devices\n");
419 g_unown_cnt = printDevList(g_unown_list);
421 setDevProtocol(g_unown_list);
426 static int discoverOwnedDevices(void)
428 // delete owned device list before updating it
431 OCDeleteDiscoveredDevices(g_own_list);
435 // call |OCDiscoverOwnedDevices| API actually
436 printf(" Discovering Only Owned Devices on Network..\n");
437 if(OC_STACK_OK != OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_own_list))
439 OIC_LOG(ERROR, TAG, "OCDiscoverOwnedDevices API error");
443 // display the discovered owned list
444 printf(" > Discovered Owned Devices\n");
445 g_own_cnt = printDevList(g_own_list);
447 setDevProtocol(g_own_list);
452 #ifdef MULTIPLE_OWNER
453 static int discoverMOTEnabledDevices(void)
455 // delete owned device list before updating it
456 if(g_mot_enable_list)
458 OCDeleteDiscoveredDevices(g_mot_enable_list);
459 g_mot_enable_list = NULL;
462 // call |OCDiscoverOwnedDevices| API actually
463 printf(" Discovering Multiple Ownership Transfer Enabled Devices on Network..\n");
464 if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_mot_enable_list))
466 OIC_LOG(ERROR, TAG, "OCDiscoverMultipleOwnerEnalbedDevices API error");
470 // display the discovered owned list
471 printf(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
472 g_mot_enable_cnt = printDevList(g_mot_enable_list);
476 #endif //MULTIPLE_OWNER
478 static int registerDevices(void)
480 // check |unown_list| for registering devices
481 if(!g_unown_list || 0>=g_unown_cnt)
483 printf(" > Unowned Device List, to Register Devices, is Empty\n");
484 printf(" > Please Discover Unowned Devices first, with [10|11] Menu\n");
485 return 0; // normal case
488 // call |OCDoOwnershipTransfer| API actually
489 // calling this API with callback actually acts like blocking
490 // for error checking, the return value saved and printed
492 printf(" Registering All Discovered Unowned Devices..\n");
493 OCStackResult rst = OCDoOwnershipTransfer((void*) g_ctx, g_unown_list, ownershipTransferCB);
494 if(OC_STACK_OK != rst)
496 OIC_LOG_V(ERROR, TAG, "OCDoOwnershipTransfer API error: %d", rst);
499 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
501 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
505 // display the registered result
506 printf(" > Registered Discovered Unowned Devices\n");
507 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
512 static int provisionPairwise(void)
514 // check |own_list| for provisioning pairwise devices
515 if(!g_own_list || 2>g_own_cnt)
517 printf(" > Owned Device List, to Provision the Pairwise, 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 devices
523 int dev_num[2] = {0};
524 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking Devices"))
526 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
527 return -1; // not need to 'goto' |ERROR| before allocating |acl|
530 // create ACL(s) for each selected device
531 OicSecAcl_t* acl[2] = {0};
532 for(int i=0; 2>i; ++i)
534 acl[i] = createAcl(dev_num[i]);
537 OIC_LOG(ERROR, TAG, "createAcl error return");
542 // call |OCProvisionPairwiseDevices| API actually
543 // calling this API with callback actually acts like blocking
544 // for error checking, the return value saved and printed
546 printf(" Provisioning Selected Pairwise Devices..\n");
548 OCProvisionPairwiseDevices((void*) g_ctx,
549 SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
550 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]), acl[0],
551 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]), acl[1],
552 provisionPairwiseCB);
553 if(OC_STACK_OK != rst)
555 OIC_LOG_V(ERROR, TAG, "OCProvisionPairwiseDevices API error: %d", rst);
558 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
560 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
563 OCDeleteACLList(acl[0]);
564 OCDeleteACLList(acl[1]);
566 // display the pairwise-provisioned result
567 printf(" > Provisioned Selected Pairwise Devices\n");
568 printf(" > Please Check Device's Status for the Linked Result, with [33] Menu\n");
573 OCDeleteACLList(acl[0]);
574 OCDeleteACLList(acl[1]);
578 static int provisionCred(void)
580 // check |own_list| for provisioning pairwise credentials
581 if(!g_own_list || 2>g_own_cnt)
583 printf(" > Owned Device List, to Provision Credentials, is Empty\n");
584 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
585 return 0; // normal case
588 // select two devices for provisioning pairwise credentials
589 int dev_num[2] = {0};
590 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Linking CRED(s)"))
592 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
596 printf(" Select PSK length..\n");
597 printf(" 1 - 128bit(Default)\n");
598 printf(" 2 - 256bit\n");
601 for(int ret=0; 1!=ret; )
603 ret = scanf("%d",&sizeOption);
604 for( ; 0x20<=getchar(); ); // for removing overflow garbages
605 // '0x20<=code' is character region
613 size = OWNER_PSK_LENGTH_128;
618 size = OWNER_PSK_LENGTH_256;
623 size = OWNER_PSK_LENGTH_128;
629 // call |OCProvisionCredentials| 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 Pairwise Credentials..\n");
635 OCProvisionCredentials((void*) g_ctx,
636 SYMMETRIC_PAIR_WISE_KEY, size,
637 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
638 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
640 if(OC_STACK_OK != rst)
642 OIC_LOG_V(ERROR, TAG, "OCProvisionCredentials API error: %d", rst);
645 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
647 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
651 // display the CRED-provisioned result
652 printf(" > Provisioned Selected Pairwise Crendentials\n");
653 printf(" > Please Check Device's Status for the Linked Result, with [34] Menu\n");
658 static int provisionAcl(void)
660 // check |own_list| for provisioning access control list
661 if(!g_own_list || 1>g_own_cnt)
663 printf(" > Owned Device List, to Provision ACL, is Empty\n");
664 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
665 return 0; // normal case
668 // select device for provisioning access control list
672 printf(" > Enter Device Number, for Provisioning ACL: ");
673 for(int ret=0; 1!=ret; )
675 ret = scanf("%d", &dev_num);
676 for( ; 0x20<=getchar(); ); // for removing overflow garbages
677 // '0x20<=code' is character region
679 if(0<dev_num && g_own_cnt>=dev_num)
683 printf(" Entered Wrong Number. Please Enter Again\n");
686 // create ACL for selected device
687 OicSecAcl_t* acl = NULL;
688 acl = createAcl(dev_num);
691 OIC_LOG(ERROR, TAG, "createAcl error return");
695 // call |OCProvisionACL| API actually
696 // calling this API with callback actually acts like blocking
697 // for error checking, the return value saved and printed
699 printf(" Provisioning Selected ACL..\n");
700 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
703 OIC_LOG(ERROR, TAG, "provisionAcl: device instance empty");
706 OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
707 if(OC_STACK_OK != rst)
709 OIC_LOG_V(ERROR, TAG, "OCProvisionACL API error: %d", rst);
712 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
714 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
717 OCDeleteACLList(acl); // after here |acl| points nothing
719 // display the ACL-provisioned result
720 printf(" > Provisioned Selected ACL\n");
725 OCDeleteACLList(acl); // after here |acl| points nothing
729 static int provisionDirectPairing(void)
731 // check |own_list| for provisioning direct-pairing
732 if(!g_own_list || 1>g_own_cnt)
734 printf(" > Owned Device List, to Provision ACL, is Empty\n");
735 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
736 return 0; // normal case
739 // select device for provisioning direct-pairing
743 printf(" > Enter Device Number, for Provisioning Direct-Pairing: ");
744 for(int ret=0; 1!=ret; )
746 ret = scanf("%d", &dev_num);
747 for( ; 0x20<=getchar(); ); // for removing overflow garbages
748 // '0x20<=code' is character region
750 if(0<dev_num && g_own_cnt>=dev_num)
754 printf(" Entered Wrong Number. Please Enter Again\n");
757 // create Direct-Pairing Configuration(PIN, PDACL) for selected device
758 // TODO: default acl -> input from user !
760 memset(&pconf, 0, sizeof(OicSecPconf_t));
765 // set default supported PRM types
766 pconf.prmLen = sizeof(SUPPORTED_PRMS)/sizeof(OicSecPrm_t);
767 pconf.prm = (OicSecPrm_t *)OICCalloc(pconf.prmLen, sizeof(OicSecPrm_t));
770 for (size_t i=0; i<pconf.prmLen; i++)
772 pconf.prm[i] = SUPPORTED_PRMS[i];
777 OIC_LOG(ERROR, TAG, "create prm error return");
782 const char DP_DEFAULT_PIN[] = "00000000";
783 memcpy(pconf.pin.val, DP_DEFAULT_PIN, DP_PIN_LENGTH);
786 pconf.pdacls = createPdAcl(dev_num);
789 OIC_LOG(ERROR, TAG, "createPdAcl error return");
793 // call |OCProvisionDirectPairing| API actually
794 // calling this API with callback actually acts like blocking
795 // for error checking, the return value saved and printed
797 printf(" Atempt Direct-Pairing Provisioning (PIN : [%s])..\n", (char*)pconf.pin.val);
798 OCStackResult rst = OCProvisionDirectPairing((void*) g_ctx,
799 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num),
800 &pconf, provisionDPCB);
801 if(OC_STACK_OK != rst)
803 OIC_LOG_V(ERROR, TAG, "OCProvisionDirectPairing API error: %d", rst);
804 if (OC_STACK_UNAUTHORIZED_REQ == rst)
806 OIC_LOG(ERROR, TAG, "Target Server NOT Support Direct-Pairing !!! (DPC == false)");
810 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
812 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
815 OCDeletePdAclList(pconf.pdacls);
817 // display the PCONF-provisioned result
818 printf(" > SUCCESS to provision Direct-Pairing !!\n");
823 OCDeletePdAclList(pconf.pdacls); // after here |acl| points nothing
827 static int checkLinkedStatus(void)
829 // check |own_list| for checking selected link status on PRVN DB
830 if(!g_own_list || 1>g_own_cnt)
832 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
833 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
834 return 0; // normal case
837 // select device for checking selected link status on PRVN DB
841 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
842 for(int ret=0; 1!=ret; )
844 ret = scanf("%d", &dev_num);
845 for( ; 0x20<=getchar(); ); // for removing overflow garbages
846 // '0x20<=code' is character region
848 if(0<dev_num && g_own_cnt>=dev_num)
852 printf(" Entered Wrong Number. Please Enter Again\n");
855 // call |OCGetLinkedStatus| API actually
856 printf(" Checking Selected Link Status on PRVN DB..\n");
857 OCUuidList_t* dvid_lst = NULL;
859 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*)g_own_list, dev_num);
860 if(!dev || !dev->doxm)
862 OIC_LOG(ERROR, TAG, "checkLinkedStatus: device instance empty");
868 &dev->doxm->deviceID,
869 &dvid_lst, &dvid_cnt)) // allow empty list
871 OIC_LOG(ERROR, TAG, "OCGetLinkedStatus API error");
875 // display the linked status result
876 printf(" > Checked Selected Link Status on PRVN DB\n");
877 if(!dvid_lst || !dvid_cnt) // |size_t| is unsigned
879 printf(" Linked Device List is Empty..\n");
880 return 0; // normal case
882 if(dvid_cnt != printUuidList((const OCUuidList_t*) dvid_lst))
884 OIC_LOG(ERROR, TAG, "printUuidList error return");
887 OCDeleteUuidList(dvid_lst);
892 OCDeleteUuidList(dvid_lst);
896 static int saveAcl(void)
898 // create ACL to save into local SVR DB
899 OicSecAcl_t* acl = NULL;
900 OicUuid_t uuid = {.id={0}};
901 char strUuid[64] = {0};
903 printf("[1] Use a test UUID [11111111-2222-3333-4444-555555555555]\n");
904 printf("[2] Use a user input\n");
908 printf(" > Select Number, for Subject UUID of new ACE: ");
909 for(int ret=0; 1!=ret; )
911 ret = scanf("%d", &sel_num);
912 for( ; 0x20<=getchar(); ); // for removing overflow garbages
913 // '0x20<=code' is character region
917 OICStrcpy(strUuid, sizeof(strUuid), "11111111-2222-3333-4444-555555555555");
920 else if(2 == sel_num)
922 printf(" > Input the UUID : ");
923 for(int ret=0; 1!=ret; )
925 ret = scanf("%64s", strUuid);
926 for( ; 0x20<=getchar(); ); // for removing overflow garbages
927 // '0x20<=code' is character region
931 printf(" Entered Wrong Number. Please Enter Again\n");
935 printf("Selected Subject UUID : %s\n", strUuid);
936 OCStackResult rst = ConvertStrToUuid(strUuid, &uuid);
937 if(OC_STACK_OK != rst)
939 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
943 acl = createSimpleAcl(uuid);
946 OIC_LOG(ERROR, TAG, "createAcl error return");
950 // call |OCSaveACL| API actually
951 rst = OCSaveACL(acl);
952 if(OC_STACK_OK != rst)
954 OIC_LOG_V(ERROR, TAG, "OCSaveACL API error: %d", rst);
957 OCDeleteACLList(acl); // after here |acl| points nothing
959 // display the ACL-provisioned result
960 printf(" > Saved Selected ACL\n");
965 OCDeleteACLList(acl); // after here |acl| points nothing
969 static int getCred(void)
971 // check |own_list| for checking selected link status on PRVN DB
972 if(!g_own_list || 1>g_own_cnt)
974 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
975 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
976 return 0; // normal case
979 // select device for checking selected link status on PRVN DB
983 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
984 for(int ret=0; 1!=ret; )
986 ret = scanf("%d", &dev_num);
987 for( ; 0x20<=getchar(); ); // for removing overflow garbages
988 // '0x20<=code' is character region
990 if(0<dev_num && g_own_cnt>=dev_num)
994 printf(" Entered Wrong Number. Please Enter Again\n");
997 // call |getDevInst| API actually
998 // calling this API with callback actually acts like blocking
999 // for error checking, the return value saved and printed
1001 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
1004 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
1007 OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB);
1008 if(OC_STACK_OK != rst)
1010 OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst);
1013 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1015 OIC_LOG(ERROR, TAG, "OCGetCredResource callback error");
1019 // display the result of get credential
1020 printf(" > Get Cred SUCCEEDED\n");
1028 static int getAcl(void)
1030 // check |own_list| for checking selected link status on PRVN DB
1031 if(!g_own_list || 1>g_own_cnt)
1033 printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n");
1034 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1035 return 0; // normal case
1038 // select device for checking selected link status on PRVN DB
1042 printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: ");
1043 for(int ret=0; 1!=ret; )
1045 ret = scanf("%d", &dev_num);
1046 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1047 // '0x20<=code' is character region
1049 if(0<dev_num && g_own_cnt>=dev_num)
1053 printf(" Entered Wrong Number. Please Enter Again\n");
1056 // call |getDevInst| API actually
1057 // calling this API with callback actually acts like blocking
1058 // for error checking, the return value saved and printed
1060 OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num);
1063 OIC_LOG(ERROR, TAG, "getDevInst: device instance empty");
1066 OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB);
1067 if(OC_STACK_OK != rst)
1069 OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst);
1073 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1075 OIC_LOG(ERROR, TAG, "OCGetACLResource callback error");
1079 // display the result of get credential
1080 printf(" > Get ACL SUCCEEDED\n");
1088 static int unlinkPairwise(void)
1090 // check |own_list| for unlinking pairwise devices
1091 if(!g_own_list || 2>g_own_cnt)
1093 printf(" > Owned Device List, to Unlink the Pairwise, is Empty\n");
1094 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1095 return 0; // normal case
1098 // select two devices for unlinking pairwise devices
1099 int dev_num[2] = {0};
1100 if(selectTwoDiffNum(&(dev_num[0]), &(dev_num[1]), g_own_cnt, "for Unlinking Devices"))
1102 OIC_LOG(ERROR, TAG, "selectTwoDiffNum error return");
1106 // call |OCUnlinkDevices| API actually
1107 // calling this API with callback actually acts like blocking
1108 // for error checking, the return value saved and printed
1110 printf(" Unlinking Selected Pairwise Devices..\n");
1112 OCUnlinkDevices((void*) g_ctx,
1113 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[0]),
1114 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num[1]),
1116 if(OC_STACK_OK != rst)
1118 OIC_LOG_V(ERROR, TAG, "OCUnlinkDevices API error: %d", rst);
1121 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1123 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1127 // display the pairwise-unlinked result
1128 printf(" > Unlinked Selected Pairwise Devices\n");
1129 printf(" > Please Check Device's Status for the Unlinked Result, with [33] Menu\n");
1134 static int removeDevice(void)
1136 // check |own_list| for removing device
1137 if(!g_own_list || 1>g_own_cnt)
1139 printf(" > Owned Device List, to Remove Device, is Empty\n");
1140 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1141 return 0; // normal case
1144 // select device for removing it
1148 printf(" > Enter Device Number, for Removing Device: ");
1149 for(int ret=0; 1!=ret; )
1151 ret = scanf("%d", &dev_num);
1152 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1153 // '0x20<=code' is character region
1155 if(0<dev_num && g_own_cnt>=dev_num)
1159 printf(" Entered Wrong Number. Please Enter Again\n");
1162 // call |OCRemoveDevice| API actually
1163 // calling this API with callback actually acts like blocking
1164 // for error checking, the return value saved and printed
1166 printf(" Removing Selected Owned Device..\n");
1168 OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT,
1169 getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB);
1170 if(OC_STACK_OK != rst)
1172 OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst);
1175 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1177 OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
1181 // display the removed result
1182 printf(" > Removed Selected Owned Device\n");
1183 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1188 static int removeDeviceWithUuid(void)
1190 char strUuid[64] = {0};
1192 printf("Input the UUID : ");
1193 for(int ret=0; 1!=ret; )
1195 ret = scanf("%63s", strUuid);
1196 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1197 // '0x20<=code' is character region
1199 OCStackResult rst = ConvertStrToUuid(strUuid, &revUuid);
1200 if(OC_STACK_OK != rst)
1202 OIC_LOG_V(ERROR, TAG, "ConvertStrToUuid API error: %d", rst);
1207 rst = OCRemoveDeviceWithUuid("RemoveDeviceWithUUID", DISCOVERY_TIMEOUT, &revUuid, removeDeviceCB);
1208 if(OC_STACK_OK != rst)
1210 OIC_LOG_V(ERROR, TAG, "OCRemoveDeviceWithUuid API error: %d", rst);
1214 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1216 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid callback error");
1220 // display the removed result
1221 printf(" > Removed %s Device\n", strUuid);
1222 printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n");
1227 OCStackResult displayNumCB(void * ctx, uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN])
1229 OIC_LOG(INFO, TAG, "IN displayMutualVerifNumCB");
1231 if (NULL != mutualVerifNum)
1233 OIC_LOG(INFO, TAG, "############ mutualVerifNum ############");
1234 OIC_LOG_BUFFER(INFO, TAG, mutualVerifNum, MUTUAL_VERIF_NUM_LEN);
1235 OIC_LOG(INFO, TAG, "############ mutualVerifNum ############");
1236 OIC_LOG(INFO, TAG, "OUT displayMutualVerifNumCB");
1240 OIC_LOG(INFO, TAG, "############ Confirm on the Server side ############");
1245 OCStackResult confirmNumCB(void * ctx)
1252 printf(" > Press 1 if the mutual verification numbers are the same\n");
1253 printf(" > Press 0 if the mutual verification numbers are not the same\n");
1255 for (int ret=0; 1!=ret; )
1257 ret = scanf("%d", &userConfirm);
1258 for (; 0x20<=getchar(); ); // for removing overflow garbage
1259 // '0x20<=code' is character region
1261 if (1 == userConfirm)
1265 else if (0 == userConfirm)
1267 return OC_STACK_USER_DENIED_REQ;
1269 printf(" Entered Wrong Number. Please Enter Again\n");
1274 OCStackResult notifyInputStateCB(void * ctx)
1278 OIC_LOG(DEBUG, TAG, "IN notifyInputStateCB");
1279 OIC_LOG(DEBUG, TAG, "User input Callback in progress");
1280 OIC_LOG(DEBUG, TAG, "OUT notifyInputStateCB");
1285 #ifdef MULTIPLE_OWNER
1286 static int changeMultipleOwnershipTrnasferMode(void)
1288 // check |own_list| for removing device
1289 if(!g_own_list || 1>g_own_cnt)
1291 printf(" > Owned Device List is Empty\n");
1292 printf(" > Please Discover the Owned Devices, with [12] Menu\n");
1293 return 0; // normal case
1296 // select device for removing it
1300 printf(" > Enter Device Number, for MOT Device: ");
1301 for(int ret=0; 1!=ret; )
1303 ret = scanf("%d", &dev_num);
1304 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1305 // '0x20<=code' is character region
1307 if(0<dev_num && g_own_cnt>=dev_num)
1311 printf(" Entered Wrong Number. Please Enter Again\n");
1317 printf(" 0. Disable Multuple Ownership Transfer\n");
1318 printf(" 1. Enable Multuple Ownership Transfer\n");
1319 printf(" 2. (Not Supported yet) Timely Enable Multuple Ownership Transfer\n");
1320 printf(" > Enter Mode of Multuple Ownership Transfer : ");
1321 for(int ret=0; 1!=ret; )
1323 ret = scanf("%d", &mom);
1324 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1325 // '0x20<=code' is character region
1327 if(0 <= dev_num && OIC_NUMBER_OF_MOM_TYPE > dev_num)
1331 printf(" Entered Wrong Number. Please Enter Again\n");
1334 OCProvisionDev_t* motDev = getDevInst(g_own_list, dev_num);
1335 if(OC_STACK_OK == OCChangeMOTMode(NULL, motDev, (OicSecMomType_t)dev_num, updateDoxmForMOTCB))
1341 OIC_LOG(ERROR, TAG, "OCChangeMOTMode API error");
1345 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1347 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1354 static int selectMultipleOwnershipTrnasferMethod(void)
1356 // check |own_list| for removing device
1357 if(!g_mot_enable_list || 1>g_mot_enable_cnt)
1359 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1360 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1361 return 0; // normal case
1364 // select device for removing it
1368 printf(" > Enter Device Number, for MOT Device: ");
1369 for(int ret=0; 1!=ret; )
1371 ret = scanf("%d", &dev_num);
1372 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1373 // '0x20<=code' is character region
1375 if(0<dev_num && g_mot_enable_cnt>=dev_num)
1379 printf(" Entered Wrong Number. Please Enter Again\n");
1382 const int preconfOxm = 4;
1386 printf(" %d. (Not Supported)\n", OIC_JUST_WORKS);
1387 printf(" %d. Random PIN OxM\n", OIC_RANDOM_DEVICE_PIN);
1388 printf(" %d. (Not Supported)\n", OIC_MANUFACTURER_CERTIFICATE);
1389 printf(" %d. (Not Supported)\n", OIC_DECENTRALIZED_PUBLIC_KEY);
1390 printf(" %d. Pre-Configured PIN OxM\n", OIC_PRECONFIG_PIN);
1391 printf(" > Enter Number of OxM for Multiple Ownership Transfer : ");
1392 for(int ret=0; 1!=ret; )
1394 ret = scanf("%d", &oxm);
1395 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1396 // '0x20<=code' is character region
1398 if(OIC_PRECONFIG_PIN == oxm || OIC_RANDOM_DEVICE_PIN == oxm)
1402 printf(" Entered Wrong Number. Please Enter Again\n");
1405 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1406 if(OC_STACK_OK == OCSelectMOTMethod(NULL, motDev, (OicSecOxm_t)oxm, updateDoxmForMOTCB))
1412 OIC_LOG(ERROR, TAG, "OCSelectMOTMethod API error");
1416 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1418 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1425 static int provisionPreconfigPIN()
1427 // check |own_list| for removing device
1428 if(!g_mot_enable_list || 1>g_mot_enable_cnt)
1430 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1431 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1432 return 0; // normal case
1435 // select device for removing it
1439 printf(" > Enter Device Number, for MOT Device: ");
1440 for(int ret=0; 1!=ret; )
1442 ret = scanf("%d", &dev_num);
1443 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1444 // '0x20<=code' is character region
1446 if(0<dev_num && g_mot_enable_cnt>=dev_num)
1450 printf(" Entered Wrong Number. Please Enter Again\n");
1453 char preconfigPin[9] = {0};
1454 printf(" > Input the PreconfigPin (e.g. 12341234) : ");
1455 for(int ret=0; 1!=ret; )
1457 ret = scanf("%8s", preconfigPin);
1458 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1459 // '0x20<=code' is character region
1462 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1463 if(OC_STACK_OK == OCProvisionPreconfigPin(NULL, motDev, preconfigPin, strlen(preconfigPin), provisionCredCB))
1469 OIC_LOG(ERROR, TAG, "OCProvisionPreconfigPin API error");
1473 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1475 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1482 static int removeSubOwner(void)
1484 // check |g_mot_enable_list| for removing sub-owner
1485 if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
1487 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1488 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1489 return 0; // normal case
1492 // select resource server for removing sub-owner
1496 printf(" > Enter Device Number to remove sub-owner: ");
1497 for (int ret = 0; 1 != ret; )
1499 ret = scanf("%d", &dev_num);
1500 for( ; 0x20 <= getchar(); ); // for removing overflow garbages
1501 // '0x20<=code' is character region
1503 if (0 < dev_num && g_mot_enable_cnt >= dev_num)
1507 printf(" Entered Wrong Number. Please Enter Again\n");
1510 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1511 if (motDev && motDev->doxm && motDev->doxm->subOwners)
1513 OicSecSubOwner_t* subOwner = motDev->doxm->subOwners;
1517 printf(" [%zu] ", ++so_cnt);
1518 printUuid(&subOwner->uuid);
1520 subOwner = subOwner->next;
1526 printf(" > Enter SubOwner Number to be removed : ");
1527 for (int ret = 0; 1 != ret; )
1529 ret = scanf("%d", &so_num);
1530 for( ; 0x20<=getchar(); ); // for removing overflow garbages
1531 // '0x20<=code' is character region
1533 if (0 < so_num && so_cnt >= so_num)
1536 subOwner = motDev->doxm->subOwners;
1539 if(so_num == ++target_num)
1541 if (OC_STACK_OK != OCRemoveSubOwner(NULL, motDev, &subOwner->uuid, deleteDoxmForMOTCB))
1548 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1550 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1555 subOwner = subOwner->next;
1559 printf(" Entered Wrong Number. Please Enter Again\n");
1564 printf(" SubOwner list is empty.\n");
1570 static int removeAllSubOwner(void)
1572 // check |g_mot_enable_list| for removing sub-owner
1573 if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
1575 printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
1576 printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
1577 return 0; // normal case
1580 // select resource server for removing sub-owner
1584 printf(" > Enter Device Number to remove sub-owner: ");
1585 for (int ret = 0; 1 != ret; )
1587 ret = scanf("%d", &dev_num);
1588 for( ; 0x20 <= getchar(); ); // for removing overflow garbages
1589 // '0x20<=code' is character region
1591 if (0 < dev_num && g_mot_enable_cnt >= dev_num)
1595 printf(" Entered Wrong Number. Please Enter Again\n");
1598 OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
1599 if (motDev && motDev->doxm && motDev->doxm->subOwners)
1601 if (OC_STACK_OK != OCRemoveAllSubOwner(NULL, motDev, deleteDoxmForMOTCB))
1608 if(waitCallbackRet()) // input |g_doneCB| flag implicitly
1610 OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
1617 printf(" SubOwner list is empty.\n");
1623 #endif //MULTIPLE_OWNER
1625 static int resetDevice(void)
1627 // check |own_list| for removing device
1628 if (!g_own_list || 1 > g_own_cnt)
1630 printf(" > Owned Device List, to Reset Device, is Empty\n");
1631 printf(" > Please Register Unowned Devices first, with [20] Menu\n");
1635 OCProvisionDev_t *dev = NULL;
1639 printf("************************************************************\n");
1640 printf("Reset device candidate list:\n");
1641 g_unown_cnt = printDevList(g_own_list);
1642 if(0 == g_unown_cnt)
1647 printf("Select number device from list\nor: -1 - escape\n");
1650 if (!scanf("%d",&c))
1655 if(0 == c && NULL != dev)
1671 for(int lst_cnt = 1; dev && lst_cnt != c; lst_cnt++, dev = dev->next);
1677 printf(" Resetting Selected Owned Device..\n");
1679 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