X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Fprovisioning%2Fsample%2Fprovisioningclient.c;h=bb65ad5c74f8389e8fa0187426edeb6972b0e1ca;hb=refs%2Ftags%2Fsubmit%2Ftizen_4.0%2F20180111.020133;hp=55e7db72f22fe1ee947cb6ba4de9fc34659ccb00;hpb=8398daa1696be1f94ed00d1972f83f5c232301f2;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/provisioning/sample/provisioningclient.c b/resource/csdk/security/provisioning/sample/provisioningclient.c index 55e7db7..bb65ad5 100644 --- a/resource/csdk/security/provisioning/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/sample/provisioningclient.c @@ -257,17 +257,10 @@ static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool g_doneCB = true; } -static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void resetDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) { - if(!hasError) - { - OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx); - } - else - { - OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx); - printResultList((const OCProvisionResult_t*) arr, nOfRes); - } + OC_UNUSED(ctx); + OIC_LOG_V(INFO, TAG, "Reset Device SUCCEEDED"); g_doneCB = true; } @@ -1638,29 +1631,52 @@ static int resetDevice(void) return 0; } - // select device for removing it - int dev_num = 0; + OCProvisionDev_t *dev = NULL; + for ( ; ; ) { - printf(" > Enter Device Number, for Resetting Device: "); - 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 && g_own_cnt >= dev_num) - { + printf("************************************************************\n"); + printf("Reset device candidate list:\n"); + g_unown_cnt = printDevList(g_own_list); + if(0 == g_unown_cnt) + { + break; + } + + printf("Select number device from list\nor: -1 - escape\n"); + int c = 0; + + if (!scanf("%d",&c)) + { + continue; + } + + if(0 == c && NULL != dev) + { + break; + } + + if(-1 == c) + { + return 0; + } + + if(c > g_own_cnt) + { + continue; + } + + dev = g_own_list; + for(int lst_cnt = 1; dev && lst_cnt != c; lst_cnt++, dev = dev->next); break; - } - printf(" Entered Wrong Number. Please Enter Again\n"); + } g_doneCB = false; printf(" Resetting Selected Owned Device..\n"); - OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT, - getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB); + OCStackResult rst = SRPResetDevice(dev, resetDeviceCB); + if (OC_STACK_OK != rst) { OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst); @@ -1669,7 +1685,7 @@ static int resetDevice(void) if (waitCallbackRet()) // input |g_doneCB| flag implicitly { - OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error"); + OIC_LOG_V(ERROR, TAG, "%s: callback error", __func__); return -1; }