X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Fprovisioning%2Fsample%2Fprovisioningclient.c;h=19fd535da0e7331cd9e8e90bd7b5f97510742ef1;hb=a2593578edc02d063c1335a3e89b19a3b5a4b1ad;hp=e1c6d5a83eb3bad2c698586bcaeb6cb07c10485e;hpb=98bd99636f3e216562976544be94bc1dd228cb91;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/provisioning/sample/provisioningclient.c b/resource/csdk/security/provisioning/sample/provisioningclient.c index e1c6d5a..19fd535 100644 --- a/resource/csdk/security/provisioning/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/sample/provisioningclient.c @@ -53,6 +53,8 @@ extern "C" #define _34_CHECK_LINK_STATUS_ 34 #define _40_UNLINK_PAIR_DEVS_ 40 #define _50_REMOVE_SELEC_DEV_ 50 +#define _60_GET_CRED_ 60 +#define _61_GET_ACL_ 61 #define _99_EXIT_PRVN_CLT_ 99 #define ACL_RESRC_MAX_NUM 16 @@ -152,6 +154,34 @@ static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool g_doneCB = true; } +static void getCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +{ + if(!hasError) + { + OIC_LOG_V(INFO, TAG, "getCredCB SUCCEEDED - ctx: %s", (char*) ctx); + } + else + { + OIC_LOG_V(ERROR, TAG, "getCredCB FAILED - ctx: %s", (char*) ctx); + printResultList((const OCProvisionResult_t*) arr, nOfRes); + } + g_doneCB = true; +} + +static void getAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +{ + if(!hasError) + { + OIC_LOG_V(INFO, TAG, "getAclCB SUCCEEDED - ctx: %s", (char*) ctx); + } + else + { + OIC_LOG_V(ERROR, TAG, "getAclCB FAILED - ctx: %s", (char*) ctx); + printResultList((const OCProvisionResult_t*) arr, nOfRes); + } + g_doneCB = true; +} + static void provisionDPCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) @@ -780,6 +810,125 @@ CKLST_ERROR: return -1; } +static int getCred(void) +{ + // check |own_list| for checking selected link status on PRVN DB + if(!g_own_list || 1>g_own_cnt) + { + printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n"); + printf(" > Please Register Unowned Devices first, with [20] Menu\n"); + return 0; // normal case + } + + // select device for checking selected link status on PRVN DB + int dev_num = 0; + for( ; ; ) + { + printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: "); + for(int ret=0; 1!=ret; ) + { + ret = scanf("%d", &dev_num); + for( ; 0x20<=getchar(); ); // for removing overflow garbages + // '0x20<=code' is character region + } + if(0=dev_num) + { + break; + } + printf(" Entered Wrong Number. Please Enter Again\n"); + } + + // call |getDevInst| API actually + // calling this API with callback actually acts like blocking + // for error checking, the return value saved and printed + g_doneCB = false; + OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num); + if(!dev) + { + OIC_LOG(ERROR, TAG, "getDevInst: device instance empty"); + goto PVACL_ERROR; + } + OCStackResult rst = OCGetCredResource((void*) g_ctx, dev, getCredCB); + if(OC_STACK_OK != rst) + { + OIC_LOG_V(ERROR, TAG, "OCGetCred API error: %d", rst); + goto PVACL_ERROR; + } + if(waitCallbackRet()) // input |g_doneCB| flag implicitly + { + OIC_LOG(ERROR, TAG, "OCGetCredResource callback error"); + goto PVACL_ERROR; + } + + // display the result of get credential + printf(" > Get Cred SUCCEEDED\n"); + + return 0; + +PVACL_ERROR: + return -1; +} + +static int getAcl(void) +{ + // check |own_list| for checking selected link status on PRVN DB + if(!g_own_list || 1>g_own_cnt) + { + printf(" > Owned Device List, to Check Linked Status on PRVN DB, is Empty\n"); + printf(" > Please Register Unowned Devices first, with [20] Menu\n"); + return 0; // normal case + } + + // select device for checking selected link status on PRVN DB + int dev_num = 0; + for( ; ; ) + { + printf(" > Enter Device Number, for Checking Linked Status on PRVN DB: "); + for(int ret=0; 1!=ret; ) + { + ret = scanf("%d", &dev_num); + for( ; 0x20<=getchar(); ); // for removing overflow garbages + // '0x20<=code' is character region + } + if(0=dev_num) + { + break; + } + printf(" Entered Wrong Number. Please Enter Again\n"); + } + + // call |getDevInst| API actually + // calling this API with callback actually acts like blocking + // for error checking, the return value saved and printed + g_doneCB = false; + OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_own_list, dev_num); + if(!dev) + { + OIC_LOG(ERROR, TAG, "getDevInst: device instance empty"); + goto PVACL_ERROR; + } + OCStackResult rst = OCGetACLResource((void*) g_ctx, dev, getAclCB); + if(OC_STACK_OK != rst) + { + OIC_LOG_V(ERROR, TAG, "OCGetACLResource API error: %d", rst); + + goto PVACL_ERROR; + } + if(waitCallbackRet()) // input |g_doneCB| flag implicitly + { + OIC_LOG(ERROR, TAG, "OCGetACLResource callback error"); + goto PVACL_ERROR; + } + + // display the result of get credential + printf(" > Get ACL SUCCEEDED\n"); + + return 0; + +PVACL_ERROR: + return -1; +} + static int unlinkPairwise(void) { // check |own_list| for unlinking pairwise devices @@ -1215,7 +1364,7 @@ static int waitCallbackRet(void) static int selectTwoDiffNum(int* a, int* b, const int max, const char* str) { - if(!a || !b || 2>=max || !str) + if(!a || !b || 2>max || !str) { return -1; } @@ -1278,6 +1427,10 @@ static void printMenu(void) printf("** [E] REMOVE THE SELECTED DEVICE\n"); printf("** 50. Remove the Selected Device\n\n"); + printf("** [F] GET SECURITY RESOURCE FOR DEBUGGING ONLY\n"); + printf("** 60. Get the Credential resources of the Selected Device\n"); + printf("** 61. Get the ACL resources of the Selected Device\n\n"); + printf("** [F] EXIT PROVISIONING CLIENT\n"); printf("** 99. Exit Provisionong Client\n\n"); @@ -1396,6 +1549,18 @@ int main() OIC_LOG(ERROR, TAG, "_50_REMOVE_SELEC_DEV_: error"); } break; + case _60_GET_CRED_: + if(getCred()) + { + OIC_LOG(ERROR, TAG, "_60_GET_CRED_: error"); + } + break; + case _61_GET_ACL_: + if(getAcl()) + { + OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error"); + } + break; case _99_EXIT_PRVN_CLT_: goto PMCLT_ERROR; default: