ResultCallBack resultCallback);
/*
- * API to remove device credential from all devices in subnet.
- *
- * @param[in] resultCallback callback provided by API user, callback will be called when
- * credential revocation is finished.
+ * API to remove device credential from all devices in subnet.
+ *
+ * @param[in] resultCallback callback provided by API user, callback will be called when
+ * credential revocation is finished.
+ * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device
+ * discovery.(seconds)
* @return OC_STACK_OK in case of success and other value otherwise.
- */
- OCStackResult removeDevice(ResultCallBack resultCallback);
+ */
+ OCStackResult removeDevice(unsigned short waitTimeForOwnedDeviceDiscovery,
+ ResultCallBack resultCallback);
/**
* This method is used to get linked devices' IDs.
DeviceList_t pUnownedDevList, pOwnedDevList;
static int transferDevIdx, ask = 1;
-OicSecAcl_t defaultAcl =
-{
- {},
- 1,
- NULL,
- 0x001F,
- 0,
- NULL,
- NULL,
- 1,
- NULL,
- NULL,
-};
-
-static FILE* client_open(const char *path, const char *mode)
+static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
{
+ (void)UNUSED_PARAM;
return fopen(JSON_DB_PATH, mode);
}
{
for (int i = 0; i < UUID_LENGTH; i++)
{
- std::cout << uuid.id[i];
+ std::cout <<std::hex << uuid.id[i] << " ";
}
std::cout<<std::endl;
}
std::cout<< "\nReceived provisioning results: ";
for (unsigned int i = 0; i < result->size(); i++)
{
- for (int j = 0; j < UUID_LENGTH; j++) std::cout << result->at(i).deviceId.id[j];
- std::cout << ", result = " << result->at(i).res << std::endl;
+ std::cout << "Result is = " << result->at(i).res <<" for device ";
+ printUuid(result->at(i).deviceId);
}
delete result;
/* Clean ACL node itself */
/* Required only if acl was created in heap */
- //OICFree((acl));
+ OICFree((acl));
}
}
try
{
int choice;
+ OicSecAcl_t *acl1 = nullptr, *acl2 = nullptr;
if (OCSecure::provisionInit("") != OC_STACK_OK)
{
std::cout <<"PM Init failed"<< std::endl;
- //return 1;
+ return 1;
}
for (int out = 0; !out;)
{
sleep(1);
}
+
+ if (acl1)
+ {
+ deleteACL(acl1);
+ acl1 = nullptr;
+ }
+
+ if (acl2)
+ {
+ deleteACL(acl2);
+ acl2 = nullptr;
+ }
+
printMenu();
std::cin >> choice;
switch(choice) {
std::cout << "Provision ACL for : "<<
pOwnedDevList[index]->getDeviceID()<< std::endl;
- OicSecAcl_t acl = defaultAcl;
+ acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
+ if (NULL == acl1)
+ {
+ OC_LOG(ERROR, TAG, "Error while memory allocation");
+ break;
+ }
std::cout << "Please input ACL for selected device: " << std::endl;
- if (0 != InputACL(&acl))
+ if (0 != InputACL(acl1))
{
- deleteACL(&acl);
break;
}
ask = 0;
- if (pOwnedDevList[index]->provisionACL(&acl, provisionCB) != OC_STACK_OK)
+ if (pOwnedDevList[index]->provisionACL(acl1, provisionCB) != OC_STACK_OK)
{
ask = 1;
std::cout <<"provisionACL is failed"<< std::endl;
}
- deleteACL(&acl);
}
break;
case 5: //Provision Credentials
if (0 != InputCredentials(cred))
break;
- OicSecAcl_t acl1 = defaultAcl;
+ acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
+ if (NULL == acl1)
+ {
+ OC_LOG(ERROR, TAG, "Error while memory allocation");
+ break;
+ }
std::cout << "Please input ACL for selected device: " << std::endl;
- if (0 != InputACL(&acl1))
+ if (0 != InputACL(acl1))
{
- deleteACL(&acl1);
break;
}
- OicSecAcl_t acl2 = defaultAcl;
+ acl2 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
+ if (NULL == acl2)
+ {
+ OC_LOG(ERROR, TAG, "Error while memory allocation");
+ break;
+ }
std::cout << "Please input ACL for selected device: " << std::endl;
- if (0 != InputACL(&acl2))
+ if (0 != InputACL(acl2))
{
- deleteACL(&acl2);
break;
}
ask = 0;
- if (pOwnedDevList[first]->provisionPairwiseDevices(cred, &acl1,
- *pOwnedDevList[second].get(), &acl2, provisionCB) != OC_STACK_OK)
+ if (pOwnedDevList[first]->provisionPairwiseDevices(cred, acl1,
+ *pOwnedDevList[second].get(), acl2, provisionCB) != OC_STACK_OK)
{
ask = 1;
std::cout <<"provisionPairwiseDevices is failed"<< std::endl;
}
- deleteACL(&acl1);
- deleteACL(&acl2);
}
break;
case 7: //Unlink Devices
- {
- int devices[2];
+ {
+ int devices[2];
- if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
+ if (0 != readDeviceNumber(pOwnedDevList, 2, devices)) break;
- int first = devices[0];
- int second = devices[1];
+ int first = devices[0];
+ int second = devices[1];
- std::cout << "Unlink devices: "<< pOwnedDevList[first]->getDeviceID();
- std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
+ std::cout << "Unlink devices: "<< pOwnedDevList[first]->getDeviceID();
+ std::cout << " and "<< pOwnedDevList[second]->getDeviceID() << std::endl;
- ask = 0;
+ ask = 0;
- if (pOwnedDevList[first]->unlinkDevices(*pOwnedDevList[second].get(),
- provisionCB) != OC_STACK_OK)
- {
- ask = 1;
- std::cout <<"removeDevice is failed"<< std::endl;
- }
- break;
- }
+ if (pOwnedDevList[first]->unlinkDevices(*pOwnedDevList[second].get(),
+ provisionCB) != OC_STACK_OK)
+ {
+ ask = 1;
+ std::cout <<"unlinkDevice is failed"<< std::endl;
+ }
+ break;
+ }
case 8: //Remove Device
- {
- int index;
+ {
+ int index;
- if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
+ if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
- std::cout << "Remove Device: "<< pOwnedDevList[index]->getDeviceID()<< std::endl;
+ std::cout << "Remove Device: "<< pOwnedDevList[index]->getDeviceID()<< std::endl;
- ask = 0;
+ ask = 0;
- if (pOwnedDevList[index]->removeDevice(provisionCB) != OC_STACK_OK)
- {
- ask = 1;
- std::cout <<"removeDevice is failed"<< std::endl;
- }
- break;
- }
+ if (pOwnedDevList[index]->removeDevice(DISCOVERY_TIMEOUT, provisionCB)
+ != OC_STACK_OK)
+ {
+ ask = 1;
+ std::cout <<"removeDevice is failed"<< std::endl;
+ }
+ break;
+ }
case 9: //Get Linked devices
{
UuidList_t linkedUuid;
if(cLock)
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
-//TODO: this change is dependent on changesets #2333, 2316. Once these are merged, this code will be
-// updated
-// result = OCGetDevInfoFromNetwork(nullptr, timeout, &owned, &unowned);
+ result = OCGetDevInfoFromNetwork(timeout, &owned, &unowned);
if (result == OC_STACK_OK)
{
ProvisionContext* context = new ProvisionContext(resultCallback);
std::lock_guard<std::recursive_mutex> lock(*cLock);
-//TODO: this change is dependent on changesets #2344. Once these are merged, this code will be
-// updated
-// result = OCUnlinkDevices(static_cast<void*>(context),
-// devPtr, device2.getDevPtr(), &OCSecureResource::callbackWrapper);
+ result = OCUnlinkDevices(static_cast<void*>(context),
+ devPtr, device2.getDevPtr(), &OCSecureResource::callbackWrapper);
}
else
{
return result;
}
- OCStackResult OCSecureResource::removeDevice(ResultCallBack resultCallback)
+ OCStackResult OCSecureResource::removeDevice(unsigned short waitTimeForOwnedDeviceDiscovery,
+ ResultCallBack resultCallback)
{
if(!resultCallback)
{
ProvisionContext* context = new ProvisionContext(resultCallback);
std::lock_guard<std::recursive_mutex> lock(*cLock);
-//TODO: this change is dependent on changesets #2344. Once these are merged, this code will be
-// updated
-// result = OCRemoveDevice(static_cast<void*>(context),
-// devPtr, &OCSecureResource::callbackWrapper);
+ result = OCRemoveDevice(static_cast<void*>(context), waitTimeForOwnedDeviceDiscovery,
+ devPtr, &OCSecureResource::callbackWrapper);
}
else
{
if(cLock)
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
-//TODO: this change is dependent on changesets #2333, 2316. Once these are merged, this code will be
-// updated
-#if CHANGESET_2316
- OicUuidList* linkedDevs = nullptr, *tmp = nullptr;
+ OCUuidList_t* linkedDevs = nullptr, *tmp = nullptr;
result = OCGetLinkedStatus(&devUuid, &linkedDevs, &numOfDevices);
if (result == OC_STACK_OK)
{
{
uuidList.push_back(tmp->dev);
}
- OCDeleteUuidList(&linkedDevs);
+ OCDeleteUuidList(linkedDevs);
}
-#endif
}
else
{
b64Ret = b64Encode(devPtr->doxm->deviceID.id, sizeof(devPtr->doxm->deviceID.id), base64Buff,
sizeof(base64Buff), &outLen);
- deviceId << base64Buff;
+ if (B64_OK == b64Ret)
+ {
+ deviceId << base64Buff;
+ }
return deviceId.str();
}
int OCSecureResource::getDeviceStatus()
{
validateSecureResource();
-//TODO: this change is dependent on changesets #2333, 2316. Once these are merged, this code will be
-// updated
-// return (int)devPtr->devStatus;
- return 0;
+ return (int)devPtr->devStatus;
}
bool OCSecureResource::getOwnedStatus()
*
* *****************************************************************/
-//#include <ocprovisioningmanager.h>
+#include <ocstack.h>
+#include <oic_malloc.h>
#include <OCApi.h>
#include <OCPlatform_impl.h>
#include <oxmjustworks.h>
{
using namespace OC;
- static OicSecAcl_t defaultAcl =
- { {},
- 1,
- NULL,
- 0x001F,
- 0,
- NULL,
- NULL,
- 1,
- NULL,
- NULL,
- };
-
void resultCallback(PMResultList_t *result, int hasError)
{
+ (void)result;
+ (void)hasError;
}
TEST(ProvisionInitTest, TestWithEmptyPath)
TEST(ProvisionAclTest, ProvisionAclTestNullCallback)
{
OCSecureResource device;
- OicSecAcl_t acl = defaultAcl;
- EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionACL(&acl, nullptr));
+ OicSecAcl_t *acl = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionACL(acl, nullptr));
+ OICFree(acl);
}
TEST(ProvisionAclTest, ProvisionAclTestNullCallbackNUllAcl)
{
OCSecureResource device, dev2;
Credential cred;
- OicSecAcl_t acl1 = defaultAcl, acl2 = defaultAcl;
- EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionPairwiseDevices(cred, &acl1,
- dev2, &acl2, nullptr));
+ OicSecAcl_t *acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
+ OicSecAcl_t *acl2 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionPairwiseDevices(cred, acl1,
+ dev2, acl2, nullptr));
+ OICFree(acl1);
+ OICFree(acl2);
}
}