+#ifdef MULTIPLE_OWNER
+ case 16:
+ {
+ if (!pOwnedDevList.size() && !pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Owned device list and MOT device list both are empty."<<std::endl;
+ break;
+ }
+ unsigned int dev_count = 0;
+ if (pOwnedDevList.size())
+ {
+ dev_count = pOwnedDevList.size();
+ printDevices(pOwnedDevList);
+ }
+
+ if (pMOTEnabledDeviceList.size())
+ {
+ dev_count += pMOTEnabledDeviceList.size();
+ for (unsigned int i = 0; i < pMOTEnabledDeviceList.size(); i++ )
+ {
+ std::cout << "Device ";
+ std::cout <<((dev_count - pMOTEnabledDeviceList.size())+ i + 1) ;
+ std::cout <<" ID : ";
+ std::cout << pMOTEnabledDeviceList[i]->getDeviceID()<<" From IP: ";
+ std::cout << pMOTEnabledDeviceList[i]->getDevAddr() << std::endl;
+ }
+ }
+
+ // select device
+ unsigned int dev_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter Device Number, to change the mode: "<<std::endl;
+ std::cin >> dev_num;
+ if(0 < dev_num && dev_count >= dev_num)
+ {
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ OicSecMomType_t momType = OIC_MULTIPLE_OWNER_ENABLE;
+ int mom = 0;
+ for( ; ; )
+ {
+ std::cout <<" 0. Disable Multiple Ownership Transfer"<<std::endl;
+ std::cout <<" 1. Enable Multiple Ownership Transfer "<<std::endl;
+ std::cout <<"> Enter Mode of Multiple Ownership Transfer :"<<std::endl;
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &mom);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(mom == 0)
+ {
+ momType = OIC_MULTIPLE_OWNER_DISABLE;
+ break;
+ }
+ if(mom == 1)
+ {
+ momType = OIC_MULTIPLE_OWNER_ENABLE;
+ break;
+ }
+ std::cout <<" Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ if (!pOwnedDevList.size())
+ {
+ if(OC_STACK_OK != pMOTEnabledDeviceList[dev_num-1]->changeMOTMode(
+ (const OicSecMomType_t)momType,MOTMethodCB))
+ {
+ OIC_LOG(ERROR, TAG, "changeMOTMode API error");
+ }
+ }
+ else
+ {
+ if(dev_num <= pOwnedDevList.size())
+ {
+ if(OC_STACK_OK != pOwnedDevList[dev_num-1]->changeMOTMode(momType,
+ MOTMethodCB))
+ {
+ OIC_LOG(ERROR, TAG, "changeMOTMode API error");
+ }
+ }
+ else
+ {
+ if(OC_STACK_OK != pMOTEnabledDeviceList[(dev_num -
+ pOwnedDevList.size() - 1)]->changeMOTMode(momType,
+ MOTMethodCB))
+ {
+ OIC_LOG(ERROR, TAG, "changeMOTMode API error");
+ }
+ }
+ }
+ break;
+ }
+ case 17:
+ {
+ if (!pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Please discover the MOT device first. Use option 18"<<std::endl;
+ break;
+ }
+
+ printDevices(pMOTEnabledDeviceList);
+ // select device
+ unsigned int dev_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter Device Number, for MOT Device: "<<std::endl;
+ std::cin >> dev_num;
+ if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num)
+ {
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ int oxm = 0;
+ OicSecOxm_t secOxm = OIC_PRECONFIG_PIN;
+ std::cout << "Select method for Multiple Ownership Transfer: "<<std::endl;
+ for( ; ; )
+ {
+ std::cout << " 0. Random PIN OxM "<<std::endl;
+ std::cout << " 1. Pre-Configured PIN OxM "<<std::endl;
+ std::cout << " > Enter Number of OxM for Multiple Ownership Transfer : "<<std::endl;
+ std::cin >> oxm;
+ if(0 == oxm)
+ {
+ secOxm = OIC_RANDOM_DEVICE_PIN;
+ break;
+ }
+ if(1 == oxm)
+ {
+ secOxm = OIC_PRECONFIG_PIN;
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ if(OC_STACK_OK != pMOTEnabledDeviceList[dev_num-1]->selectMOTMethod((const OicSecOxm_t)secOxm,
+ MOTMethodCB))
+ {
+ OIC_LOG(ERROR, TAG, "selectMOTMethod API error");
+ }
+ break;
+ }
+ case 18:
+ {
+ pMOTEnabledDeviceList.clear();
+ std::cout << "Started MOT Enabled device discovery..." <<std::endl;
+ OCStackResult result = OCSecure::discoverMultipleOwnerEnabledDevices
+ (DISCOVERY_TIMEOUT, pMOTEnabledDeviceList);
+ if (result != OC_STACK_OK)
+ {
+ std::cout<< "!!Error - MOT Enabled dev Discovery failed."<<std::endl;
+ }
+ else if (pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Found MOT enabled devices, count = " <<
+ pMOTEnabledDeviceList.size() << std::endl;
+ printDevices(pMOTEnabledDeviceList);
+ }
+ else
+ {
+ std::cout <<"No MOT enabled Secure devices found"<<std::endl;
+ }
+ break;
+ }
+ case 19:
+ {
+ if (!pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Please discover the MOT device first. Use option 16"<<std::endl;
+ break;
+ }
+
+ printDevices(pMOTEnabledDeviceList);
+ // select device
+ unsigned int dev_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter Device Number, for MOT Device: "<<std::endl;
+ std::cin >> dev_num;
+ if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num)
+ {
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ char preconfigPin[9] = {0};
+ std::cout << " > Input the 8 digit PreconfigPin (e.g. 12341234) :" <<std::endl;
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%8s", preconfigPin);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ size_t preconfPinLength = strlen(preconfigPin);
+ if(OC_STACK_OK != pMOTEnabledDeviceList[dev_num-1]->provisionPreconfPin(preconfigPin,
+ preconfPinLength, MOTMethodCB))
+ {
+ OIC_LOG(ERROR, TAG, "provisionPreconfPin API error");
+ }
+ break;
+ }
+ case 20:
+ {
+ if (!pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Please discover the MOT device first. Use option 16"<<std::endl;
+ break;
+ }
+
+ printDevices(pMOTEnabledDeviceList);
+ // select device
+ unsigned int dev_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter Device Number, for MOT Device: "<<std::endl;
+ std::cin >> dev_num;
+ if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num)
+ {
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ char preconfPIN[9] = {0};
+ std::cout << " > Input the 8 digit preconfPIN (e.g. 12341234) :" <<std::endl;
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%8s", preconfPIN);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ size_t preconfPinLength = strlen(preconfPIN);
+ if(OC_STACK_OK != pMOTEnabledDeviceList[dev_num-1]->addPreconfigPIN(preconfPIN,
+ preconfPinLength))
+ {
+ OIC_LOG(ERROR, TAG, "addPreconfigPIN API error");
+ }
+ break;
+ }
+ case 21: //Remove sub-owner
+ {
+ if (!pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Please discover the MOT device first. Use option 16"<<std::endl;
+ break;
+ }
+
+ printDevices(pMOTEnabledDeviceList);
+ // select device
+ unsigned int dev_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter Device Number, for MOT Device: "<<std::endl;
+ std::cin >> dev_num;
+ if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num)
+ {
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ UuidList_t subOwenrList;
+ pMOTEnabledDeviceList[dev_num - 1]->getSubOwnerList(subOwenrList);
+ if (0 == subOwenrList.size())
+ {
+ std::cout << "SubOwner List is empty."<<std::endl;
+ }
+ else
+ {
+ //display the Linked devices (UUIDs)
+ for(unsigned int i = 0; i < subOwenrList.size(); i++)
+ {
+ printUuid(subOwenrList[i]);
+ }
+ }
+ unsigned int so_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter SubOwner Number to be Removed: "<<std::endl;
+ std::cin >> so_num;
+ if(0 < so_num && subOwenrList.size() >=so_num)
+ {
+ pMOTEnabledDeviceList[dev_num - 1]->removeSubOwner(&subOwenrList[so_num], MOTRemoveSubOwnerCB);
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ break;
+ }
+ case 22: //Remove all sub-owner
+ {
+ if (!pMOTEnabledDeviceList.size())
+ {
+ std::cout <<"Please discover the MOT device first. Use option 16"<<std::endl;
+ break;
+ }
+
+ printDevices(pMOTEnabledDeviceList);
+ // select device
+ unsigned int dev_num = 0;
+ for( ; ; )
+ {
+ std::cout << "Enter Device Number, for MOT Device: "<<std::endl;
+ std::cin >> dev_num;
+ if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num)
+ {
+ break;
+ }
+ std::cout << " Entered Wrong Number. Please Enter Again"<<std::endl;
+ }
+
+ UuidList_t subOwenrList;
+ pMOTEnabledDeviceList[dev_num - 1]->getSubOwnerList(subOwenrList);
+ if (0 == subOwenrList.size())
+ {
+ std::cout << "SubOwner List is empty."<<std::endl;
+ }
+ else
+ {
+ pMOTEnabledDeviceList[dev_num - 1]->removeAllSubOwner(MOTRemoveSubOwnerCB);
+ }
+ break;
+ }
+#endif //MULTIPLE_OWNER
+ case 30:
+ {
+ OCStackResult result;
+ result = OCSecure::configSelfOwnership();
+ if (OC_STACK_OK != result)
+ {
+ std::cout<<"configSelfOwnership API error. Please check SVR DB"<<std::endl;
+ }
+ else
+ {
+ std::cout<<"Success to configures SVR DB as self-ownership"<<std::endl;
+ }
+ break;
+ }