diff options
author | agrkush <kush.agrawal@samsung.com> | 2018-12-09 23:53:35 +0530 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2018-12-12 09:51:18 +0900 |
commit | c58dd148dcb3339d6333338a7dcd1a84fb27e91b (patch) | |
tree | 7170c8e54c80040c7a683f50b283fefef417e0ba | |
parent | 24e931b7c1b2757bd088937de9f55b822e6ba28d (diff) | |
download | iotivity-c58dd148dcb3339d6333338a7dcd1a84fb27e91b.tar.gz iotivity-c58dd148dcb3339d6333338a7dcd1a84fb27e91b.tar.bz2 iotivity-c58dd148dcb3339d6333338a7dcd1a84fb27e91b.zip |
Fixes for scan in VDsubmit/tizen/20181212.005641accepted/tizen/unified/20181212.062520
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/358
(cherry picked from commit d7a3c45d3ab7d4a0ee01a3a4fb639f5ba7f366f8)
Change-Id: Ifa2d29429b9e0b4b57635d1e948477284dc23397
Signed-off-by: agrkush <kush.agrawal@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
-rw-r--r-- | resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.h | 2 | ||||
-rw-r--r-- | resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient_vd.c | 125 | ||||
-rw-r--r--[-rwxr-xr-x] | resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c | 7 |
3 files changed, 106 insertions, 28 deletions
diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.h b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.h index e967513bc..f3aac226c 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.h +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.h @@ -79,6 +79,8 @@ void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s */ void CAStartTimerThread(void *data); +void CALEClientScanThread(); + /** * Used to initialize all required mutex variable for Gatt Client implementation. * diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient_vd.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient_vd.c index ec69d56c0..2e2ea1e4c 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient_vd.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient_vd.c @@ -47,9 +47,11 @@ #define WAIT_TIME_WRITE_CHARACTERISTIC 10 * MICROSECS_PER_SEC //For custom uuid ble server -#define CA_GATT_CUSTOM_UUID "75004209-0000-0000-0000-000000000000" -#define CA_GATT_CUSTOM_UUID2 "75004204-0000-0000-0000-000000000000" -#define CUSTOM_UUID_LEN 9 +#define CA_GATT_CUSTOM_UUID "4209" +#define CA_GATT_CUSTOM_UUID2 "4204" +#define CUSTOM_UUID_LEN 4 + +static const int samsung_code = 117; uint64_t const TIMEOUT = 30 * MICROSECS_PER_SEC; @@ -182,7 +184,6 @@ static GMainLoop *g_eventLoop = NULL; * Reference to threadpool */ static ca_thread_pool_t g_LEClientThreadPool = NULL; -CAResult_t CALEClientScanThread(); void CALEGattCharacteristicChangedCb(bt_gatt_h characteristic, char *value, @@ -311,7 +312,7 @@ void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress) g_isConnectionInProgress = false; oc_mutex_unlock(g_isConnectionInProgressMutex); - + // TODO:Disabling scanning for now.Need to check. /*oc_mutex_lock(g_scanMutex); if (g_isMulticastInProgress || g_isUnicastScanInProgress) @@ -394,6 +395,32 @@ static bool CALEIsHaveServiceImpl(bt_adapter_le_device_scan_result_info_s *scanI } OICFree(uuids); } + + if(ret == false){ + char *man_data = NULL; + int man_data_len; + int man_id; + result = bt_adapter_le_get_scan_result_manufacturer_data(scanInfo, + pkt_type, &man_id, &man_data, &man_data_len); + + if (result == BT_ERROR_NONE && NULL != man_data) + { + char *compare_man_data = OICMalloc((man_data_len*2)+1); + int pos =0; + for(int i=0;i<man_data_len;i++){ + pos += sprintf(compare_man_data+pos, "%.2x", man_data[i]); + } + compare_man_data[man_data_len]='\0'; + if (man_id == samsung_code && 0 == strncasecmp(compare_man_data, service_uuid, CUSTOM_UUID_LEN)) + { + OIC_LOG_V(DEBUG, TAG, "Manufacture Data[%s] Found in %s", + compare_man_data, scanInfo->remote_address); + ret = true; + } + OICFree(compare_man_data); + OICFree(man_data); + } + } return ret; } @@ -436,19 +463,19 @@ void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s } oc_mutex_unlock(g_isScanningInProgressMutex); - LEServerInfo *serverInfo = NULL; - oc_mutex_lock(g_LEServerListMutex); - CAResult_t ret = CAGetLEServerInfo(g_LEServerList, scanInfo->remote_address, &serverInfo); - if (CA_STATUS_OK != ret) + if (CALEIsHaveService(scanInfo, CA_GATT_SERVICE_UUID) || + CALEIsHaveService(scanInfo, CA_GATT_CUSTOM_UUID)|| + CALEIsHaveService(scanInfo, CA_GATT_CUSTOM_UUID2)) { - OIC_LOG_V(DEBUG, TAG, - "Newly discovered device with address [%s] ", scanInfo->remote_address); + OIC_LOG_V(DEBUG, TAG, "Device [%s] supports OIC or custom service", scanInfo->remote_address); - if (CALEIsHaveService(scanInfo, CA_GATT_SERVICE_UUID) || - CALEIsHaveService(scanInfo, CA_GATT_CUSTOM_UUID)|| - CALEIsHaveService(scanInfo, CA_GATT_CUSTOM_UUID2)) + LEServerInfo *serverInfo = NULL; + oc_mutex_lock(g_LEServerListMutex); + CAResult_t ret = CAGetLEServerInfo(g_LEServerList, scanInfo->remote_address, &serverInfo); + if (CA_STATUS_OK != ret) { - OIC_LOG_V(DEBUG, TAG, "Device [%s] supports OIC or custom service", scanInfo->remote_address); + OIC_LOG_V(DEBUG, TAG, + "Newly discovered device with address [%s] ", scanInfo->remote_address); char *addr = OICStrdup(scanInfo->remote_address); if (NULL == addr) @@ -475,7 +502,34 @@ void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s CAFreeLEServerInfo(serverInfo); return; } - } + }else { + OIC_LOG_V(DEBUG, TAG, + "Device Present with address [%s] ", scanInfo->remote_address); + + if(serverInfo->status == LE_STATUS_UNICAST_PENDING){ + bt_gatt_client_h clientHandle = NULL; + int32_t ret = bt_gatt_client_create(serverInfo->remoteAddress, &clientHandle); + if (BT_ERROR_NONE != ret || NULL == clientHandle) + { + 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 ; + } + serverInfo->clientHandle = clientHandle; + + serverInfo->status = LE_STATUS_CONNECTION_INITIATED; + if (CA_STATUS_OK != CALEGattInitiateConnection(serverInfo->remoteAddress)) + { + OIC_LOG_V(ERROR, TAG, "Could not initiate connection to [%s]", serverInfo->remoteAddress); + serverInfo->status = LE_STATUS_DISCOVERED; + CADestroyLEDataList(&serverInfo->pendingDataList); + oc_mutex_unlock(g_LEServerListMutex); + return ; + } + } + } } oc_mutex_unlock(g_LEServerListMutex); OIC_LOG(DEBUG, TAG, "OUT"); @@ -568,7 +622,7 @@ CAResult_t CAStartLEGattClient() return CA_STATUS_OK; } -CAResult_t CALEClientScanThread() +void CALEClientScanThread() { oc_mutex_lock(g_scanMutex); if (!g_isMulticastInProgress && !g_isUnicastScanInProgress) @@ -578,7 +632,7 @@ CAResult_t CALEClientScanThread() { oc_mutex_unlock(g_scanMutex); OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed"); - return CA_STATUS_FAILED; + return ; } g_isUnicastScanInProgress = true; // Start Timer @@ -593,7 +647,7 @@ CAResult_t CALEClientScanThread() oc_mutex_unlock(g_scanMutex); OIC_LOG(DEBUG, TAG, "OUT"); - return CA_STATUS_OK; + return ; } void CAStartTimerThread(void *data) @@ -1140,6 +1194,7 @@ exit: void CADiscoverLEServicesThread(void *remoteAddress) { OIC_LOG(DEBUG, TAG, "IN"); + VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address is NULL"); char *address = (char *)remoteAddress; @@ -1282,6 +1337,32 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, "Device with address [%s] not yet found, initiating scan", remoteAddress); + char *addr = OICStrdup(remoteAddress); + if (NULL == addr) + { + oc_mutex_unlock(g_LEServerListMutex); + OIC_LOG(ERROR, TAG, "Device address is NULL"); + return CA_STATUS_FAILED; + } + serverInfo = (LEServerInfo *)OICCalloc(1, sizeof(LEServerInfo)); + if (NULL == serverInfo) + { + oc_mutex_unlock(g_LEServerListMutex); + OIC_LOG(ERROR, TAG, "Calloc failed"); + OICFree(addr); + return CA_STATUS_FAILED; + } + serverInfo->remoteAddress = addr; + serverInfo->status = LE_STATUS_UNICAST_PENDING; + + if (CA_STATUS_OK != CAAddLEServerInfoToList(&g_LEServerList, serverInfo)) + { + oc_mutex_unlock(g_LEServerListMutex); + OIC_LOG_V(ERROR, TAG, "Could not add [%s] to server list", remoteAddress); + CAFreeLEServerInfo(serverInfo); + return CA_STATUS_FAILED; + } + if (CA_STATUS_OK != CAAddLEDataToList(&serverInfo->pendingDataList, data, dataLen)) { oc_mutex_unlock(g_LEServerListMutex); @@ -1289,8 +1370,6 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, return CA_STATUS_FAILED; } - oc_mutex_unlock(g_LEServerListMutex); - oc_mutex_lock(g_scanMutex); if (!g_isMulticastInProgress && !g_isUnicastScanInProgress) { @@ -1313,8 +1392,6 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, } oc_mutex_unlock(g_scanMutex); - OIC_LOG(DEBUG, TAG, "OUT"); - return CA_STATUS_OK; } if (serverInfo->status == LE_STATUS_DISCOVERED) @@ -1325,7 +1402,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, OIC_LOG(ERROR, TAG, "Could not add data to pending list"); return CA_STATUS_FAILED; } - + bt_gatt_client_h clientHandle = NULL; int32_t ret = bt_gatt_client_create(serverInfo->remoteAddress, &clientHandle); if (BT_ERROR_NONE != ret || NULL == clientHandle) diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c index 6a52aedbd..f1a5f6e9a 100755..100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c @@ -859,10 +859,6 @@ CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const ch if (read) { - g_gattReadCharPath = charPath; - } - else - { char desc_value[2] = {0, 0}; // Notification enabled. bt_gatt_h descriptor = NULL; permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; @@ -887,6 +883,9 @@ CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const ch CALEGetErrorMsg(ret)); return CA_STATUS_FAILED; } + g_gattReadCharPath = charPath; + } + else{ g_gattWriteCharPath = charPath; } |