summaryrefslogtreecommitdiff
path: root/resource
diff options
context:
space:
mode:
authorKush <kush.agrawal@samsung.com>2019-10-15 16:04:17 +0530
committerPyun DoHyun <dh79.pyun@samsung.com>2020-01-12 23:05:38 +0000
commitbd41b92525a8df6c63cc0b1d87e623e453516bd0 (patch)
tree7ccd3d2ede177c9bf2bf2fc2d16cc5d8f4615c40 /resource
parent1cd1a6cd15480a9d42ae0c69e553ec72202b3dcb (diff)
downloadiotivity-bd41b92525a8df6c63cc0b1d87e623e453516bd0.tar.gz
iotivity-bd41b92525a8df6c63cc0b1d87e623e453516bd0.tar.bz2
iotivity-bd41b92525a8df6c63cc0b1d87e623e453516bd0.zip
BLE Scan when GATT already connected.
If GATT is already connected by some other service then Iotivity should use that GATT connection only. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/427b61effdc348e139c27fb314b44c011689e523 (cherry-picked from 427b61effdc348e139c27fb314b44c011689e523) Change-Id: I8bd79cd7752a0312b1fa73a91cf2851c8af24c85 Signed-off-by: Kush <kush.agrawal@samsung.com> Signed-off-by: Sudipto <sudipto.bal@samsung.com>
Diffstat (limited to 'resource')
-rwxr-xr-x[-rw-r--r--]resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c82
1 files changed, 64 insertions, 18 deletions
diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c
index f6cb5b8ea..c13d8e290 100644..100755
--- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c
+++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c
@@ -1368,8 +1368,8 @@ CAResult_t CALEGattDiscoverServices(const char *remoteAddress)
else
{
oc_mutex_unlock(g_LEServerListMutex);
- OIC_LOG(ERROR, TAG, "Previous connection attempt failed, attempting to retry again");
- OIC_LOG_V(DEBUG, TAG, "Retry count left %d time(s)", g_retrycount);
+ OIC_LOG(ERROR, TAG, "Previous connection attempt failed, attempting to retry again");
+ OIC_LOG_V(DEBUG, TAG, "Retry count left %d time(s)", g_retrycount);
return CA_STATUS_FAILED;
}
}
@@ -1505,6 +1505,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
}
LEServerInfo *serverInfo = NULL;
+ bool isConnected = false;
oc_mutex_lock(g_LEServerListMutex);
if (LE_UNICAST == type)
{
@@ -1550,28 +1551,72 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
if(serverInfo->status == LE_STATUS_UNICAST_PENDING)
{
- oc_mutex_lock(g_scanMutex);
- if (!g_isMulticastInProgress && !g_isUnicastScanInProgress)
+
+ int ret = bt_device_is_profile_connected(remoteAddress, BT_PROFILE_GATT, &isConnected);
+ if (BT_ERROR_NONE != ret)
{
- CAResult_t result = CALEGattStartDeviceScanning();
- if (CA_STATUS_OK != result)
+ OIC_LOG_V(ERROR, TAG, "bt_device_is_profile_connected Failed with ret value [%s] ",
+ CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
+ }
+
+ if (isConnected){
+ OIC_LOG_V(DEBUG, TAG, "Already connected to address [%s]", remoteAddress);
+ serverInfo->status = LE_STATUS_CONNECTED;
+ } else {
+ oc_mutex_lock(g_scanMutex);
+ if (!g_isMulticastInProgress && !g_isUnicastScanInProgress)
+ {
+ CAResult_t result = CALEGattStartDeviceScanning();
+ if (CA_STATUS_OK != result)
+ {
+ oc_mutex_unlock(g_scanMutex);
+ OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed");
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
+ }
+ g_isUnicastScanInProgress = true;
+ // Start Timer
+ oc_cond_signal(g_startTimerCond);
+ }
+ else
{
- oc_mutex_unlock(g_scanMutex);
- OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed");
- return CA_STATUS_FAILED;
+ g_isUnicastScanInProgress = true;
+ // Reset Timer
+ oc_cond_signal(g_scanningTimeCond);
}
- g_isUnicastScanInProgress = true;
- // Start Timer
- oc_cond_signal(g_startTimerCond);
+ oc_mutex_unlock(g_scanMutex);
+ }
+
+ }
+
+ if (serverInfo->status == LE_STATUS_CONNECTED)
+ {
+ oc_mutex_lock(g_LEClientThreadPoolMutex);
+ if (NULL == g_LEClientThreadPool)
+ {
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ OIC_LOG(ERROR, TAG, "g_LEClientThreadPool is NULL");
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
}
- else
+ char *addr = OICStrdup(remoteAddress);
+ if (NULL == addr)
{
- g_isUnicastScanInProgress = true;
- // Reset Timer
- oc_cond_signal(g_scanningTimeCond);
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ OIC_LOG(ERROR, TAG, "addr is NULL");
+ oc_mutex_unlock(g_LEServerListMutex);
+ return CA_STATUS_FAILED;
+ }
+ CAResult_t ret = ca_thread_pool_add_task(g_LEClientThreadPool, CADiscoverLEServicesThread,
+ addr, NULL);
+ oc_mutex_unlock(g_LEClientThreadPoolMutex);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "ca_thread_pool_add_task failed with ret [%d]", ret);
+ OICFree(addr);
}
- oc_mutex_unlock(g_scanMutex);
-
}
if (serverInfo->status == LE_STATUS_DISCOVERED)
@@ -1590,6 +1635,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_create Failed with ret value [%s] ", CALEGetErrorMsg(ret));
CALEGattDisConnect(serverInfo->remoteAddress);
+ oc_mutex_unlock(g_LEServerListMutex);
return CA_STATUS_FAILED;
}
serverInfo->clientHandle = clientHandle;