+
+static int removeSubOwner(void)
+{
+ // check |g_mot_enable_list| for removing sub-owner
+ if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
+ {
+ printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
+ printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
+ return 0; // normal case
+ }
+
+ // select resource server for removing sub-owner
+ int dev_num = 0;
+ for ( ; ; )
+ {
+ printf(" > Enter Device Number to remove sub-owner: ");
+ 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_mot_enable_cnt >= dev_num)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
+ if (motDev && motDev->doxm && motDev->doxm->subOwners)
+ {
+ OicSecSubOwner_t* subOwner = motDev->doxm->subOwners;
+ int so_cnt = 0;
+ while(subOwner)
+ {
+ printf(" [%zu] ", ++so_cnt);
+ printUuid(&subOwner->uuid);
+ printf("\n");
+ subOwner = subOwner->next;
+ }
+
+ int so_num = 0;
+ for ( ; ; )
+ {
+ printf(" > Enter SubOwner Number to be removed : ");
+ for (int ret = 0; 1 != ret; )
+ {
+ ret = scanf("%d", &so_num);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if (0 < so_num && so_cnt >= so_num)
+ {
+ int target_num = 0;
+ subOwner = motDev->doxm->subOwners;
+ while (subOwner)
+ {
+ if(so_num == ++target_num)
+ {
+ if (OC_STACK_OK != OCRemoveSubOwner(NULL, motDev, &subOwner->uuid, deleteDoxmForMOTCB))
+ {
+ return -1;
+ }
+
+ g_doneCB = false;
+
+ if(waitCallbackRet()) // input |g_doneCB| flag implicitly
+ {
+ OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
+ return -1;
+ }
+ return 0;
+ }
+ subOwner = subOwner->next;
+ }
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+ }
+ else
+ {
+ printf(" SubOwner list is empty.\n");
+ }
+
+ return 0;
+}
+
+static int removeAllSubOwner(void)
+{
+ // check |g_mot_enable_list| for removing sub-owner
+ if (!g_mot_enable_list || 1 > g_mot_enable_cnt)
+ {
+ printf(" > Multiple Ownership Transfer Enabled Device List is Empty\n");
+ printf(" > Please Discover the Multiple Ownership Transfer Enabled Devices, with [13] Menu\n");
+ return 0; // normal case
+ }
+
+ // select resource server for removing sub-owner
+ int dev_num = 0;
+ for ( ; ; )
+ {
+ printf(" > Enter Device Number to remove sub-owner: ");
+ 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_mot_enable_cnt >= dev_num)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ OCProvisionDev_t* motDev = getDevInst(g_mot_enable_list, dev_num);
+ if (motDev && motDev->doxm && motDev->doxm->subOwners)
+ {
+ if (OC_STACK_OK != OCRemoveAllSubOwner(NULL, motDev, deleteDoxmForMOTCB))
+ {
+ return -1;
+ }
+
+ g_doneCB = false;
+
+ if(waitCallbackRet()) // input |g_doneCB| flag implicitly
+ {
+ OIC_LOG(ERROR, TAG, "waitCallbackRet callback error");
+ return -1;
+ }
+ return 0;
+ }
+ else
+ {
+ printf(" SubOwner list is empty.\n");
+ }
+
+ return 0;
+}
+
+#endif //MULTIPLE_OWNER