* This method is used by provisioning manager free memory allocated to OCUuidList_t lists.
*
* @param[in] ptr start pointer of link list.
- * @return OC_STACK_OK in case of success and other value otherwise.
*/
-OCStackResult PDMDestoryOicUuidLinkList(OCUuidList_t* ptr);
+void PDMDestoryOicUuidLinkList(OCUuidList_t* ptr);
/**
* This method is used by provisioning manager free memory allocated to Stalelist.
*
* @param[in] ptr start pointer of link list.
- * @return OC_STACK_OK in case of success and other value otherwise.
+ *
*/
-OCStackResult PDMDestoryStaleLinkList(OCPairList_t* ptr);
+void PDMDestoryStaleLinkList(OCPairList_t* ptr);
#ifdef __cplusplus
}
unsigned short waitTimeForOwnedDeviceDiscovery,\r
const OCProvisionDev_t* pTargetDev,\r
OCProvisionResultCB resultCallback);\r
+/**
+ * API to get status of all the devices in current subnet. The status include endpoint information\r
+ * and doxm information which can be extracted duing owned and unowned discovery. Along with this\r
+ * information. The API will provide information about devices' status\r
+ * Device can have following states\r
+ * - ON/OFF: Device is switched on or off.\r
+ *\r
+ * NOTE: Caller need to call OCDeleteDiscoveredDevices to delete memory allocated by this API for out\r
+ * variables pOwnedDevList and pUnownedDevList.\r
+ *\r
+ * @param[in] waitime Wait time for the API. The wait time will be divided by 2, and half of wait time\r
+ * will be used for unowned discovery and remaining half for owned discovery.\r
+ * @param[out] pOwnedDevList list of owned devices.\r
+ * @param[out] pUnownedDevList list of unowned devices.\r
+ * @return OC_STACK_OK in case of success and other value otherwise.\r
+ */\r
+OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,\r
+ OCProvisionDev_t** pOwnedDevList,\r
+ OCProvisionDev_t** pUnownedDevList);\r
+/**\r
+ * This method is used to get linked devices' IDs.\r
+ *\r
+ * @param[in] uuidOfDevice a target device's uuid.\r
+ * @param[out] uuidList information about the list of linked devices' uuids.\r
+ * @param[out] numOfDevices total number of linked devices.\r
+ * @return OC_STACK_OK in case of success and other value otherwise.\r
+ */\r
+OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice,\r
+ OCUuidList_t** uuidList,\r
+ size_t* numOfDevices);\r
\r
/**\r
* API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API.\r
*/\r
void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList);\r
\r
+/**\r
+ * API to delete memory allocated to OicUuid_t list.\r
+ *\r
+ * @param[in] pList Pointer to OicUuid_t list which should be deleted.\r
+ */\r
+void OCDeleteUuidList(OCUuidList_t* pList);\r
+\r
#ifdef __cplusplus\r
}\r
#endif // __cplusplus\r
OCUuidList_t *next;
};
+/*
+ * Device's power on/off state.
+ */
+typedef enum {
+ DEV_STATUS_ON = (1 << 0),
+ DEV_STATUS_OFF = (1 << 1)
+}DeviceStatus;
/**
* Device Information of discoverd unowned/owned device(s) for provisioning.
OicSecDoxm_t *doxm; /**< Pointer to target's doxm resource. **/
OCConnectivityType connType; /**< Connectivity type of endpoint */
uint16_t securePort; /**< secure port **/
- struct OCProvisionDev *next; /**< Next pointer. **/
+ DeviceStatus devStatus; /**< status of device **/
+ struct OCProvisionDev *next; /**< Next pointer. **/
}OCProvisionDev_t;
/**
*/
void PMPrintOCProvisionDev(const OCProvisionDev_t* pDev);
+/** Function to delete matched UUID from the UUIDlist.
+ *
+ * @param[in] pUuidList a pointer to UUID list.
+ * @param[in] targetId a pointer to UUID to be deleted in the list.
+ *
+ * @return true when deletion is happened, false when no deletion is occured. In case either of
+ * two arguments is null it will return false.
+ */
+bool PMDeleteFromUUIDList(OCUuidList_t *pUuidList, OicUuid_t *targetId);
+
#ifdef __cplusplus
}
#endif
#include "secureresourceprovider.h"
#include "provisioningdatabasemanager.h"
#include "credresource.h"
+#include "utlist.h"
+
#define TAG "OCPMAPI"
return res;
}
+
+OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,
+ OCProvisionDev_t** pOwnedDevList,
+ OCProvisionDev_t** pUnownedDevList)
+{
+ //TODO will be replaced by more efficient logic
+ if (pOwnedDevList == NULL || *pOwnedDevList != NULL || pUnownedDevList == NULL
+ || *pUnownedDevList != NULL)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ // Code for unowned discovery
+ OCProvisionDev_t *unownedDevice = NULL;
+ OCStackResult res = OCDiscoverUnownedDevices(waittime/2, &unownedDevice);
+ if (OC_STACK_OK != res)
+ {
+ OC_LOG(ERROR,TAG, "Error in unowned discovery");
+ return res;
+ }
+
+ // Code for owned discovery
+ OCProvisionDev_t *ownedDevice = NULL;
+ res = OCDiscoverOwnedDevices(waittime/2, &ownedDevice);
+ if (OC_STACK_OK != res)
+ {
+ OC_LOG(ERROR,TAG, "Error in owned discovery");
+ PMDeleteDeviceList(unownedDevice);
+ return res;
+ }
+
+ // Code to get list of all the owned devices.
+ OCUuidList_t *uuidList = NULL;
+ size_t numOfDevices = 0;
+ res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
+ if (OC_STACK_OK != res)
+ {
+ OC_LOG(ERROR, TAG, "Error while getting info from DB");
+ PMDeleteDeviceList(unownedDevice);
+ PMDeleteDeviceList(ownedDevice);
+ return res;
+ }
+
+ // Code to compare devices in owned list and deviceid from DB.
+ OCProvisionDev_t* pCurDev = ownedDevice;
+ size_t deleteCnt = 0;
+ while (pCurDev)
+ {
+ if(true == PMDeleteFromUUIDList(uuidList, &pCurDev->doxm->deviceID))
+ {
+ deleteCnt++;
+ }
+ pCurDev = pCurDev->next;
+ }
+ // If there is no remaind device in uuidList, we have to assign NULL to prevent free.
+ if (deleteCnt == numOfDevices)
+ {
+ uuidList = NULL;
+ }
+ // Code to add information of the devices which are currently off in owned list.
+ OCUuidList_t *powerOffDeviceList = uuidList;
+ while (powerOffDeviceList)
+ {
+ OCProvisionDev_t *ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
+ if (NULL == ptr)
+ {
+ OC_LOG(ERROR,TAG,"Fail to allocate memory");
+ PMDeleteDeviceList(unownedDevice);
+ PMDeleteDeviceList(ownedDevice);
+ OCDeleteUuidList(uuidList);
+ return OC_STACK_NO_MEMORY;
+ }
+
+ ptr->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
+ if (NULL == ptr->doxm)
+ {
+ OC_LOG(ERROR,TAG,"Fail to allocate memory");
+ PMDeleteDeviceList(unownedDevice);
+ PMDeleteDeviceList(ownedDevice);
+ OCDeleteUuidList(uuidList);
+ OICFree(ptr);
+ return OC_STACK_NO_MEMORY;
+ }
+
+ memcpy(ptr->doxm->deviceID.id, powerOffDeviceList->dev.id, sizeof(ptr->doxm->deviceID.id));
+
+ ptr->devStatus = DEV_STATUS_OFF;
+ LL_PREPEND(ownedDevice, ptr);
+ powerOffDeviceList = powerOffDeviceList->next;
+
+ }
+ OCDeleteUuidList(uuidList);
+ *pOwnedDevList = ownedDevice;
+ *pUnownedDevList = unownedDevice;
+ return OC_STACK_OK;
+}
+
+OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice, OCUuidList_t** uuidList,
+ size_t* numOfDevices)
+{
+ return PDMGetLinkedDevices(uuidOfDevice, uuidList, numOfDevices);
+}
+
+void OCDeleteUuidList(OCUuidList_t* pList)
+{
+ PDMDestoryOicUuidLinkList(pList);
+}
OC_LOG(DEBUG, TAG, "+++++ OCProvisionDev_t is NULL +++++");
}
}
+
+bool PMDeleteFromUUIDList(OCUuidList_t *pUuidList, OicUuid_t *targetId)
+{
+ if(pUuidList == NULL || targetId == NULL)
+ {
+ return false;
+ }
+ OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
+ LL_FOREACH_SAFE(pUuidList, tmp1, tmp2)
+ {
+ if(0 == memcmp(tmp1->dev.id, targetId->id, sizeof(targetId->id)))
+ {
+ LL_DELETE(pUuidList, tmp1);
+ OICFree(tmp1);
+ return true;
+ }
+ }
+ return false;
+}
return OC_STACK_OK;
}
-OCStackResult PDMDestoryOicUuidLinkList(OCUuidList_t* ptr)
+void PDMDestoryOicUuidLinkList(OCUuidList_t* ptr)
{
- OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
- LL_FOREACH_SAFE(ptr, tmp1, tmp2)
+ if(ptr)
{
- LL_DELETE(ptr, tmp1);
- OICFree(tmp1);
+ OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
+ LL_FOREACH_SAFE(ptr, tmp1, tmp2)
+ {
+ LL_DELETE(ptr, tmp1);
+ OICFree(tmp1);
+ }
}
- return OC_STACK_OK;
}
-OCStackResult PDMDestoryStaleLinkList(OCPairList_t* ptr)
+void PDMDestoryStaleLinkList(OCPairList_t* ptr)
{
- OCPairList_t *tmp1 = NULL,*tmp2=NULL;
- LL_FOREACH_SAFE(ptr, tmp1, tmp2)
+ if(ptr)
{
- LL_DELETE(ptr, tmp1);
- OICFree(tmp1);
+ OCPairList_t *tmp1 = NULL,*tmp2=NULL;
+ LL_FOREACH_SAFE(ptr, tmp1, tmp2)
+ {
+ LL_DELETE(ptr, tmp1);
+ OICFree(tmp1);
+ }
}
- return OC_STACK_OK;
}
unsigned short waitTime = 0;
OCProvisionDev_t dev1;
EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &dev1, NULL));
-}
\ No newline at end of file
+}
+
+TEST(OCGetDevInfoFromNetworkTest, NullUnOwnedDeviceInfo)
+{
+ OCProvisionDev_t *ownedList = NULL;
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(0, &ownedList, NULL));
+}
+
+TEST(OCGetDevInfoFromNetworkTest, NullOwnedDeviceInfo)
+{
+ OCProvisionDev_t *unownedList = NULL;
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(0, NULL, &unownedList));
+}
+
+TEST(OCGetLinkedStatusTest, NULLDeviceID)
+{
+ OCUuidList_t *list = NULL;
+ size_t noOfDevices = 0;
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetLinkedStatus(NULL, &list, &noOfDevices));
+}
TEST(PDMDestoryOicUuidLinkList, NULLParam)
{
- EXPECT_EQ(OC_STACK_OK, PDMDestoryOicUuidLinkList(NULL));
+ PDMDestoryOicUuidLinkList(NULL);
}
TEST(PDMDestoryStaleLinkList, NULLParam)
{
- EXPECT_EQ(OC_STACK_OK, PDMDestoryOicUuidLinkList(NULL));
+ PDMDestoryStaleLinkList(NULL);
}