*/\r
OCStackResult OCDiscoverSingleDevice(unsigned short timeout, const OicUuid_t* deviceID,\r
OCProvisionDev_t **ppFoundDevice);\r
+
+/**
+ * The function is responsible for discovery of owned/unowned device is specified endpoint/MAC
+ * address.
+ * It will return the found device even though timeout is not exceeded.
+ *
+ * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
+ * server before returning the device.
+ * @param[in] deviceID deviceID of target device.
+ * @param[in] hostAddress MAC address of target device.
+ * @param[in] connType ConnectivityType for discovery.
+ * @param[out] ppFoundDevice OCProvisionDev_t of found device.
+ * @return OTM_SUCCESS in case of success and other value otherwise.
+ */
+OCStackResult OCDiscoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t* deviceID,
+ const char* hostAddress, OCConnectivityType connType,
+ OCProvisionDev_t **ppFoundDevice);
\r
/**\r
* The function is responsible for discovery of device is current subnet. It will list\r
OCProvisionDev_t **ppFoundDevice);
/**
+ * Discover owned/unowned device in the specified endpoint/MAC address.
+ * It will return the found device even though timeout is not exceeded.
+ *
+ * @param[in] waittime Timeout in seconds.
+ * @param[in] deviceID deviceID of target device.
+ * @param[in] hostAddress MAC address of target device.
+ * @param[in] connType ConnectivityType for discovery.
+ * @param[out] ppFoundDevice OCProvisionDev_t of found device.
+ *
+ * @return OC_STACK_OK on success otherwise error.
+ * OC_STACK_INVALID_PARAM when deviceID is NULL or ppFoundDevice is not initailized.
+ */
+OCStackResult PMSingleDeviceDiscoveryInUnicast(unsigned short waittime, const OicUuid_t* deviceID,
+ const char* hostAddress, OCConnectivityType connType,
+ OCProvisionDev_t **ppFoundDevice);
+
+/**
* Discover owned/unowned devices in the same IP subnet. .
*
* @param[in] waittime Timeout in seconds.
}
/**
+ * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
+ * And this function will only return the specified device's response.
+ *
+ * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
+ * server before returning the device.
+ * @param[in] deviceID deviceID of target device.
+ * @param[in] hostAddress MAC address of target device.
+ * @param[in] connType ConnectivityType for discovery.
+ * @param[out] ppFoundDevice OCProvisionDev_t of found device.
+ * @return OTM_SUCCESS in case of success and other value otherwise.
+ */
+OCStackResult OCDiscoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t* deviceID,
+ const char* hostAddress, OCConnectivityType connType,
+ OCProvisionDev_t **ppFoundDevice)
+{
+ if( NULL == ppFoundDevice || NULL != *ppFoundDevice || 0 == timeout || NULL == deviceID ||
+ NULL == hostAddress)
+ {
+ OIC_LOG(ERROR, TAG, "OCDiscoverSingleDeviceInUnicast : Invalid Parameter");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ return PMSingleDeviceDiscoveryInUnicast(timeout, deviceID, hostAddress, connType,
+ ppFoundDevice);
+}
+
+/**
* The function is responsible for discovery of device is current subnet. It will list
* all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
* OCMode.
return res;
}
+OCStackResult PMSingleDeviceDiscoveryInUnicast(unsigned short waittime, const OicUuid_t* deviceID,
+ const char* hostAddress, OCConnectivityType connType,
+ OCProvisionDev_t **ppFoundDevice)
+{
+ OIC_LOG(DEBUG, TAG, "IN PMSingleDeviceDiscoveryInUnicast");
+
+ if (NULL != *ppFoundDevice)
+ {
+ OIC_LOG(ERROR, TAG, "List is not null can cause memory leak");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ if (NULL == deviceID)
+ {
+ OIC_LOG(ERROR, TAG, "Invalid device ID");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ DiscoveryInfo *pDInfo = (DiscoveryInfo*)OICCalloc(1, sizeof(DiscoveryInfo));
+ if (NULL == pDInfo)
+ {
+ OIC_LOG(ERROR, TAG, "PMSingleDeviceDiscoveryInUnicast : Memory allocation failed.");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ pDInfo->ppDevicesList = ppFoundDevice;
+ pDInfo->pCandidateList = NULL;
+ pDInfo->isOwnedDiscovery = false;
+ pDInfo->isSingleDiscovery = true;
+ pDInfo->isFound = false;
+ pDInfo->targetId = deviceID;
+
+ OCCallbackData cbData;
+ cbData.cb = &DeviceDiscoveryHandler;
+ cbData.context = (void *)pDInfo;
+ cbData.cd = &DeviceDiscoveryDeleteHandler;
+
+ OCStackResult res = OC_STACK_ERROR;
+
+ char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH + 1] = { '\0' };
+ if (hostAddress == NULL)
+ {
+ hostAddress = "";
+ }
+ snprintf(query, MAX_URI_LENGTH + MAX_QUERY_LENGTH + 1, "%s/oic/sec/doxm", hostAddress);
+ connType = connType & CT_MASK_ADAPTER;
+
+ OCDoHandle handle = NULL;
+ res = OCDoResource(&handle, OC_REST_DISCOVER, query, 0, 0,
+ connType, OC_HIGH_QOS, &cbData, NULL, 0);
+
+ if (res != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
+ OICFree(pDInfo);
+ pDInfo = NULL;
+ return res;
+ }
+
+ res = OC_STACK_OK;
+ uint64_t startTime = OICGetCurrentTime(TIME_IN_MS);
+ while (OC_STACK_OK == res && !pDInfo->isFound)
+ {
+ uint64_t currTime = OICGetCurrentTime(TIME_IN_MS);
+
+ long elapsed = (long)((currTime - startTime) / MS_PER_SEC);
+ if (elapsed > waittime)
+ {
+ break;
+ }
+ res = OCProcess();
+ }
+
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG (ERROR, TAG, "Failed to wait response for secure discovery.");
+ OICFree(pDInfo);
+ pDInfo = NULL;
+ OCStackResult resCancel = OCCancel(handle, OC_HIGH_QOS, NULL, 0);
+ if (OC_STACK_OK != resCancel)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to remove registered callback");
+ }
+ return res;
+ }
+
+ res = OCCancel(handle, OC_HIGH_QOS, NULL, 0);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to remove registered callback");
+ OICFree(pDInfo);
+ pDInfo = NULL;
+ return res;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT PMSingleDeviceDiscoveryInUnicast");
+ OICFree(pDInfo);
+ pDInfo = NULL;
+ return res;
+}
+
#ifdef MULTIPLE_OWNER
static OCStackApplicationResult MOTDeviceDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
const OicUuid_t* deviceID,
std::shared_ptr<OCSecureResource> &foundDevice);
+ /**
+ * API is responsible for discovery of devices in specified endpoint/deviceID.
+ * And this function will only return the specified device's response.
+ *
+ * @param timeout Timeout in seconds, time until which function will listen to
+ * responses from server before returning the specified device.
+ * @param deviceID deviceID of target device.
+ * @param hostAddress MAC address of target device.
+ * @param connType ConnectivityType for discovery.
+ * @param foundDevice OCSecureResource object of found device.
+ * @return ::OC_STACK_OK in case of success and other value otherwise.
+ * ::OC_STACK_INVALID_PARAM when deviceID is NULL or ppFoundDevice is not
+ * initailized.
+ */
+ static OCStackResult discoverSingleDeviceInUnicast(unsigned short timeout,
+ const OicUuid_t* deviceID,
+ const std::string& hostAddress,
+ OCConnectivityType connType,
+ std::shared_ptr<OCSecureResource> &foundDevice);
+
#ifdef MULTIPLE_OWNER
/**
* API is responsible for discovery of MOT(Mutilple Owner Transfer)
return result;
}
+ OCStackResult OCSecure::discoverSingleDeviceInUnicast(unsigned short timeout,
+ const OicUuid_t* deviceID,
+ const std::string& hostAddress,
+ OCConnectivityType connType,
+ std::shared_ptr<OCSecureResource> &foundDevice)
+ {
+ OCStackResult result = OC_STACK_ERROR;
+ OCProvisionDev_t *pDev = nullptr;
+ auto csdkLock = OCPlatform_impl::Instance().csdkLock();
+ auto cLock = csdkLock.lock();
+
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCDiscoverSingleDeviceInUnicast(timeout, deviceID, hostAddress.c_str(),
+ connType, &pDev);
+
+ if (result == OC_STACK_OK)
+ {
+ if (pDev)
+ {
+ foundDevice.reset(new OCSecureResource(csdkLock, pDev));
+ }
+ else
+ {
+ oclog() <<"Not found Secure resource!";
+ foundDevice.reset();
+ }
+ }
+ else
+ {
+ oclog() <<"Secure resource discovery failed!";
+ }
+ }
+ else
+ {
+ oclog() <<"Mutex not found";
+ result = OC_STACK_ERROR;
+ }
+
+ return result;
+ }
+
#ifdef MULTIPLE_OWNER
OCStackResult OCSecure::discoverMultipleOwnerEnabledDevices(unsigned short timeout,
DeviceList_t &list)