From 581024e2437356a594b544f52397f0da3e83fb30 Mon Sep 17 00:00:00 2001 From: "vimala.v" Date: Wed, 13 May 2015 15:31:33 +0530 Subject: [PATCH] Fixed following Tizen BLE issues 1) Fixed JIRA-472 Issue. 2) Fixed issues related to Tizen BLE interoperability with Arduino BLE. Change-Id: Id29bb04f5ba241daa084f9ecaac8cd30d888068d Signed-off-by: vimala.v Reviewed-on: https://gerrit.iotivity.org/gerrit/970 Tested-by: jenkins-iotivity Reviewed-by: John Light Reviewed-by: Erich Keane --- resource/csdk/connectivity/inc/camsgparser.h | 30 +-- .../src/bt_le_adapter/tizen/cableclient.c | 255 +++++---------------- .../src/bt_le_adapter/tizen/cableclient.h | 36 +-- .../src/bt_le_adapter/tizen/cablenwmonitor.c | 2 +- .../src/bt_le_adapter/tizen/cableserver.c | 91 ++++---- .../src/bt_le_adapter/tizen/cableutil.c | 6 +- .../src/bt_le_adapter/tizen/cableutil.h | 27 +-- 7 files changed, 128 insertions(+), 319 deletions(-) diff --git a/resource/csdk/connectivity/inc/camsgparser.h b/resource/csdk/connectivity/inc/camsgparser.h index e7504bc..6780860 100644 --- a/resource/csdk/connectivity/inc/camsgparser.h +++ b/resource/csdk/connectivity/inc/camsgparser.h @@ -56,6 +56,12 @@ */ #define CA_HEADER_LENGTH 2 +/** + * @var CA_SUPPORTED_BLE_MTU_SIZE + * @brief The MTU supported for BLE adapter + */ +#define CA_SUPPORTED_BLE_MTU_SIZE 20 + #ifdef __TIZEN__ /** * @var PLATFORM_IDENTIFIER_BIT @@ -69,12 +75,6 @@ */ #define CA_SUPPORTED_EDR_MTU_SIZE 512 -/** - * @var CA_SUPPORTED_BLE_MTU_SIZE - * @brief The MTU supported from Tizen platform for LE adapter. - */ -#define CA_SUPPORTED_BLE_MTU_SIZE 200 - #elif __ANDROID__ /** * @var PLATFORM_IDENTIFIER_BIT @@ -88,12 +88,6 @@ */ #define CA_SUPPORTED_EDR_MTU_SIZE 200 -/** - * @var CA_SUPPORTED_BLE_MTU_SIZE - * @brief The MTU supported from Android platform for LE adapter. - */ -#define CA_SUPPORTED_BLE_MTU_SIZE 20 - #elif __ARDUINO__ /** * @var PLATFORM_IDENTIFIER_BIT @@ -107,12 +101,6 @@ */ #define CA_SUPPORTED_EDR_MTU_SIZE 200 -/** - * @var CA_SUPPORTED_BLE_MTU_SIZE - * @brief The MTU supported from Arduino platform for LE adapter. - */ -#define CA_SUPPORTED_BLE_MTU_SIZE 200 - #else //Other Platforms /** * @var PLATFORM_IDENTIFIER_BIT @@ -126,12 +114,6 @@ */ #define CA_SUPPORTED_EDR_MTU_SIZE 200 -/** - * @var CA_SUPPORTED_BLE_MTU_SIZE - * @brief The MTU supported for BLE adapter - */ -#define CA_SUPPORTED_BLE_MTU_SIZE 200 - #endif /** diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.c index 99ad1bc..30199fa 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.c @@ -265,40 +265,24 @@ bool CABleGattCharacteristicsDiscoveredCb(int result, ca_mutex_unlock(g_bleServiceListMutex); + char *uuid = NULL; + bt_gatt_get_service_uuid(characteristic, &uuid); - if (BLE_GATT_READ_CHAR_INDEX == inputIndex) // Server will read on this characteristics. - { - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "new read Characteristics is obtained [%s]", - (char *)characteristic); + VERIFY_NON_NULL_RET(uuid, TZ_BLE_CLIENT_TAG, "uuid is NULL", false); - CAResult_t retVal = CAAppendBLECharInfo(characteristic, BLE_GATT_READ_CHAR, bleServiceInfo); - if (CA_STATUS_OK != retVal) - { - OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CAAppendBLECharInfo failed "); - return false; - } - char *uuid = NULL; + OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "New Characteristics[%s] of uuid[%s] is obtained", + (char *)characteristic, uuid); - bt_gatt_get_service_uuid(characteristic, &uuid); - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "new read Characteristics uuid is obtained [%s]", - uuid); - } - else if (BLE_GATT_WRITE_CHAR_INDEX == inputIndex) // Server will write on this characterisctics + if(0 == strcasecmp(uuid, CA_BLE_READ_CHAR_UUID)) // Server will read on this characterisctics { - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "new write Characteristics is obtained [%s]", - (char *)characteristic); - - CAResult_t retVal = CAAppendBLECharInfo(characteristic, BLE_GATT_WRITE_CHAR, bleServiceInfo); + OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG , "Read characteristics is obtained"); + OICFree(uuid); + CAResult_t retVal = CAAppendBLECharInfo(characteristic, BLE_GATT_READ_CHAR, bleServiceInfo); if (CA_STATUS_OK != retVal) { OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CAAppendBLECharInfo failed! "); return false; } - char *uuid = NULL; - - bt_gatt_get_service_uuid(characteristic, &uuid); - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "new write Characteristics uuid is obtained [%s]", - uuid); stGattServiceInfo_t *stTemp = (stGattServiceInfo_t *)OICCalloc(1, sizeof(stGattServiceInfo_t)); @@ -343,98 +327,20 @@ bool CABleGattCharacteristicsDiscoveredCb(int result, } ca_mutex_unlock(g_bleClientThreadPoolMutex); } - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); - return true; -} - -void CABtGattBondCreatedCb(int result, bt_device_info_s *device_info, void *user_data) -{ - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); - if (BT_ERROR_NONE != result) - { - OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, - " create_bond Failed as [%s ]", CABTGetErrorMsg(result)); - } - else + else if (0 == strcasecmp(uuid, CA_BLE_WRITE_CHAR_UUID)) // Server will write on this characteristics. { - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "bond with remote device is created."); - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Callback: The number of service : %d.", - device_info->service_count); - - VERIFY_NON_NULL_VOID(device_info, TZ_BLE_CLIENT_TAG, - "device_info is NULL"); - VERIFY_NON_NULL_VOID(device_info->remote_address, TZ_BLE_CLIENT_TAG, - "device_info->remote_address is NULL"); - - BLEServiceInfo *bleServiceInfo = NULL; - - ca_mutex_lock(g_bleServiceListMutex); - CAResult_t retVal = CAGetBLEServiceInfo(g_bLEServiceList, device_info->remote_address, - &bleServiceInfo); + OICFree(uuid); + OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG , "Write characteristics is obtained"); + CAResult_t retVal = CAAppendBLECharInfo(characteristic, BLE_GATT_WRITE_CHAR, bleServiceInfo); if (CA_STATUS_OK != retVal) { - OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CAGetBLEServiceInfo failed! "); - return; - } - - VERIFY_NON_NULL_VOID(bleServiceInfo, TZ_BLE_CLIENT_TAG, - "bleServiceInfo is NULL"); - - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "Its OIC service"); - - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, - "serviceInfo remote address [%s]", bleServiceInfo->bdAddress); - - stGattServiceInfo_t *stTemp = (stGattServiceInfo_t *)OICCalloc(1, - sizeof(stGattServiceInfo_t)); - - VERIFY_NON_NULL_VOID(stTemp, TZ_BLE_CLIENT_TAG, "malloc failed"); - - bt_gatt_clone_attribute_handle(&(stTemp->serviceInfo), bleServiceInfo->service_clone); - - size_t len = strlen(bleServiceInfo->bdAddress); - stTemp->address = (char *)OICMalloc(sizeof(char) * (len + 1)); - if (NULL == stTemp->address) - { - OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "Malloc failed!"); - bt_gatt_destroy_attribute_handle(stTemp->serviceInfo); - OICFree(stTemp); - return; - } - - strncpy(stTemp->address, bleServiceInfo->bdAddress, len + 1); - - ca_mutex_lock(g_bleClientThreadPoolMutex); - if (NULL == g_bleClientThreadPool) - { - OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "g_bleClientThreadPool is NULL"); - bt_gatt_destroy_attribute_handle(stTemp->serviceInfo); - OICFree(stTemp->address); - OICFree(stTemp); - ca_mutex_unlock(g_bleClientThreadPoolMutex); - return; - } - - CAResult_t ret = ca_thread_pool_add_task(g_bleClientThreadPool, - CADiscoverCharThread, stTemp); - if (CA_STATUS_OK != ret) - { - OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, - "ca_thread_pool_add_task failed with ret [%d]", ret); - bt_gatt_destroy_attribute_handle(stTemp->serviceInfo); - OICFree(stTemp->address); - OICFree(stTemp); - ca_mutex_unlock(g_bleClientThreadPoolMutex); - return; + OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CAAppendBLECharInfo failed "); + return false; } - ca_mutex_unlock(g_bleClientThreadPoolMutex); - - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, - "Callback: is_bonded - %d.", device_info->is_bonded); - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, - "Callback: is_connected - %d.", device_info->is_connected); } + OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); + return true; } bool CABleGattPrimaryServiceCb(bt_gatt_attribute_h service, int index, int count, @@ -531,9 +437,10 @@ bool CABleGattPrimaryServiceCb(bt_gatt_attribute_h service, int index, int count ca_mutex_unlock(g_bleClientThreadPoolMutex); return false; } + bt_gatt_clone_attribute_handle(&(stTemp->serviceInfo), service); result = ca_thread_pool_add_task(g_bleClientThreadPool, - CAGATTCreateBondThread, + CADiscoverCharThread, stTemp); if (CA_STATUS_OK != result) { @@ -863,6 +770,14 @@ void CAStopBLEGattClient() return; } + CABleGattUnSetCallbacks(); + + CABleGattUnWatchCharacteristicChanges(); + + CABleGattStopDeviceDiscovery(); + + g_isBleGattClientStarted = false; + GMainContext *context_event_loop = NULL; // Required for waking up the thread which is running in gmain loop if (NULL != g_eventLoop) @@ -892,17 +807,12 @@ void CATerminateBLEGattClient() OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); ca_mutex_lock(g_bleClientStateMutex); + ca_mutex_lock(g_bleServerBDAddressMutex); OICFree(g_remoteAddress); ca_mutex_unlock(g_bleServerBDAddressMutex); - CABleGattUnWatchCharacteristicChanges(); - - CABleGattUnSetCallbacks(); - - CABleGattStopDeviceDiscovery(); - ca_mutex_lock(g_bleServiceListMutex); CAFreeBLEServiceList(g_bLEServiceList); g_bLEServiceList = NULL; @@ -910,7 +820,6 @@ void CATerminateBLEGattClient() CAResetRegisteredServiceCount(); - g_isBleGattClientStarted = false; ca_mutex_unlock(g_bleClientStateMutex); CATerminateGattClientMutexVariables(); @@ -1075,16 +984,6 @@ CAResult_t CABleGattSetCallbacks() return CA_STATUS_FAILED; } - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "Setting bt_device_set_bond_created_cb"); - - ret = bt_device_set_bond_created_cb(CABtGattBondCreatedCb, NULL); - if (BT_ERROR_NONE != ret) - { - OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, " bt_device_set_bond_created_cb Failed as [%s ]", - CABTGetErrorMsg(ret)); - return CA_STATUS_FAILED; - } - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); return CA_STATUS_OK; } @@ -1095,8 +994,6 @@ void CABleGattUnSetCallbacks() bt_gatt_unset_characteristic_changed_cb(); - bt_device_unset_bond_created_cb(); - bt_gatt_unset_connection_state_changed_cb(); bt_adapter_le_unset_device_discovery_state_changed_cb(); @@ -1151,14 +1048,25 @@ void CABleGattUnWatchCharacteristicChanges() CAResult_t CABleGattStartDeviceDiscovery() { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); + bool isDiscovering = false; - int ret = bt_adapter_le_start_device_discovery(); + int ret = bt_adapter_le_is_discovering(&isDiscovering); if (BT_ERROR_NONE != ret) { - OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_start_device_discovery Failed"); + OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_is_discovering Failed"); return CA_STATUS_FAILED; } + if(!isDiscovering) + { + ret = bt_adapter_le_start_device_discovery(); + if (BT_ERROR_NONE != ret) + { + OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_start_device_discovery Failed Ret: %d, %x", ret, ret); + return CA_STATUS_FAILED; + } + } + OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); return CA_STATUS_OK; } @@ -1167,7 +1075,24 @@ void CABleGattStopDeviceDiscovery() { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); - bt_adapter_le_stop_device_discovery(); + bool isDiscovering = false; + + int ret = bt_adapter_le_is_discovering(&isDiscovering); + if (BT_ERROR_NONE != ret) + { + OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_is_discovering Failed"); + return; + } + + if(isDiscovering) + { + ret = bt_adapter_le_stop_device_discovery(); + if (BT_ERROR_NONE != ret) + { + OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_stop_device_discovery Failed"); + return; + } + } OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); } @@ -1284,7 +1209,7 @@ CAResult_t CABleGattDiscoverServices(const char *remoteAddress) } else { - OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, + OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "bt_gatt_foreach_primary_services success for address [%s]", remoteAddress); } @@ -1465,59 +1390,6 @@ CAResult_t CASetCharacteristicDescriptorValue(stGattCharDescriptor_t *stGattChar return CA_STATUS_OK; } -void CAGATTCreateBondThread(void *stServiceInfo) -{ - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); - - VERIFY_NON_NULL_VOID(stServiceInfo, TZ_BLE_CLIENT_TAG, "stServiceInfo is NULL"); - - stGattServiceInfo_t *stTemp = (stGattServiceInfo_t *)stServiceInfo; - - VERIFY_NON_NULL_VOID(stTemp, TZ_BLE_CLIENT_TAG, "stTemp is NULL"); - - OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "remote address [%s]", - stTemp->address); - - CAResult_t result = CABleGATTCreateBond(stTemp->address); - if (CA_STATUS_OK != result) - { - OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , - "CABleGattDiscoverCharacteristics failed!"); - OICFree(stTemp->address); - OICFree(stTemp); - return; - } - OICFree(stTemp->address); - OICFree(stTemp); - - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); -} - -CAResult_t CABleGATTCreateBond(const char *remoteAddress) -{ - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); - - VERIFY_NON_NULL_RET(remoteAddress, TZ_BLE_CLIENT_TAG, - "remote address is NULL", CA_STATUS_FAILED); - - int ret = bt_device_create_bond(remoteAddress); - - if (BT_ERROR_NONE != ret) - { - OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, - "bt_device_create_bond Failed with ret value [%d] ", ret); - return CA_STATUS_FAILED; - } - else - { - OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, - " bt_device_create_bond query success for address [%s]", remoteAddress); - } - OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); - - return CA_STATUS_OK; -} - CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char *data, const uint32_t dataLen, CALETransferType_t type, const int32_t position) @@ -1567,13 +1439,12 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, "Updating the data of length [%d] to [%s]", dataLen, bleServiceInfo->bdAddress); - int result = bt_gatt_set_characteristic_value_request(bleServiceInfo->read_char, (unsigned char *)data, - dataLen, - CABleGattCharacteristicWriteCb); + int result = bt_gatt_set_characteristic_value(bleServiceInfo->write_char, (unsigned char *)data, + dataLen); if (BT_ERROR_NONE != result) { OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, - "bt_gatt_set_characteristic_value_request Failed with return val [%d]", + "bt_gatt_set_characteristic_value Failed with return val [%d]", result); return CA_STATUS_FAILED; } diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.h b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.h index 35d40fc..9985153 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.h +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableclient.h @@ -97,16 +97,6 @@ bool CABleGattCharacteristicsDiscoveredCb(int result, int inputIndex, int total, bt_gatt_attribute_h characteristic, void *userData); /** - * @brief This is the callback which will be called when bond created with remote device. - * - * @param result [IN] The result of bond creation. - * @param device_info [IN] remote device information - * @param userData [IN] The user data passed from the request function - * @return NONE - */ -void CABtGattBondCreatedCb(int result, bt_device_info_s *device_info, void *user_data); - -/** * @brief This is the callback which will be called when we get the primary services repeatedly. * * @param service [IN] The attribute handle of service. Unique identifier for service. @@ -158,8 +148,7 @@ void CAPrintDiscoveryInformation(const bt_adapter_le_device_discovery_info_s *di /** * @brief This thread will be used to initialize the Gatt Client and start device discovery. * 1. Set scan parameters - * 2. Setting neccessary callbacks for connection, characteristics changed and discovery - * and bond creation. + * 2. Setting neccessary callbacks for connection, characteristics changed and discovery. * 3. Start device discovery * * @param data [IN] Currently it will be NULL(no parameter) @@ -202,7 +191,7 @@ void CAClearNonOICDeviceList(); CAResult_t CABleGattSetScanParameter(); /** - * @brief Used to register required callbacks to BLE platform(connection, discovery, bond and etc). + * @brief Used to register required callbacks to BLE platform(connection, discovery, etc). * * @return #CA_STATUS_OK or Appropriate error code * @retval #CA_STATUS_OK Successful @@ -370,27 +359,6 @@ CAResult_t CASetCharacteristicDescriptorValue (stGattCharDescriptor_t *stGattCharDescriptorInfo); /** - * @brief This is the thread which will be used for creating bond with remote device. - * - * @param stServiceInfo [IN] Service Information which contains the remote address and service - * handle, characteristic handle. - * @return NONE - */ -void CAGATTCreateBondThread(void *stServiceInfo); - -/** - * @brief Used to make LE bond with remote device(pairng the device) using bt_device_create_bond - * api. - * @param remoteAddress [IN] MAC address of remote device with which we want to bond - * - * @return #CA_STATUS_OK or Appropriate error code - * @retval #CA_STATUS_OK Successful - * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets - * @retval #CA_STATUS_FAILED Operation failed - */ -CAResult_t CABleGATTCreateBond(const char *remoteAddress); - -/** * @brief Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make * signal to the thread to process. * diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cablenwmonitor.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cablenwmonitor.c index 0acaa5b..790a079 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cablenwmonitor.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cablenwmonitor.c @@ -154,7 +154,7 @@ CAResult_t CAGetLEAddress(char **local_address) { OIC_LOG(DEBUG, TZ_LE_NWK_MONITOR_TAG, "IN"); - VERIFY_NON_NULL_VOID(local_address, TZ_LE_NWK_MONITOR_TAG, "local_address is null") + VERIFY_NON_NULL(local_address, TZ_LE_NWK_MONITOR_TAG, "local_address is null") char *address = NULL; diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.c index 653414c..36889f2 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableserver.c @@ -48,18 +48,6 @@ #define CA_BLE_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E" /** - * @def CA_BLE_READ_CHAR_UUID - * @brief UUID of read characteristic. This UUID is common across all platform for LE transport. - */ -#define CA_BLE_READ_CHAR_UUID "713D0002-503E-4C75-BA94-3148F18D941E" - -/** - * @def CA_BLE_WRITE_CHAR_UUID - * @brief UUID of write characteristic. This UUID is common across all platform for LE transport. - */ -#define CA_BLE_WRITE_CHAR_UUID "713D0003-503E-4C75-BA94-3148F18D941E" - -/** * @def CA_BLE_INITIAL_BUF_SIZE * @brief Initial buffer size for Gatt Server. */ @@ -329,37 +317,6 @@ CAResult_t CAStopBleGattServer() return CA_STATUS_OK; } - GMainContext *context_event_loop = NULL; - // Required for waking up the thread which is running in gmain loop - if ( NULL != g_eventLoop) - { - context_event_loop = g_main_loop_get_context(g_eventLoop); - } - if (context_event_loop) - { - OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "g_eventLoop context %x", context_event_loop); - g_main_context_wakeup(context_event_loop); - - // Kill g main loops and kill threads - g_main_loop_quit(g_eventLoop); - } - else - { - OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_eventLoop context is NULL"); - } - - ca_mutex_unlock(g_bleServerStateMutex); - - OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT"); - return CA_STATUS_OK; -} - -void CATerminateBleGattServer() -{ - OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN"); - - ca_mutex_lock(g_bleServerStateMutex); - g_isBleGattServerStarted = false; if (NULL != g_hAdvertiser ) { @@ -392,6 +349,38 @@ void CATerminateBleGattServer() OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG, "_bt_gatt_deinit_service failed with ret [%d]", res); } + GMainContext *context_event_loop = NULL; + // Required for waking up the thread which is running in gmain loop + if (NULL != g_eventLoop) + { + context_event_loop = g_main_loop_get_context(g_eventLoop); + + if (context_event_loop) + { + OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "g_eventLoop context %x", context_event_loop); + g_main_context_wakeup(context_event_loop); + + // Kill g main loops and kill threads + g_main_loop_quit(g_eventLoop); + } + } + else + { + OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_eventLoop context is NULL"); + } + + ca_mutex_unlock(g_bleServerStateMutex); + + OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT"); + return CA_STATUS_OK; +} + +void CATerminateBleGattServer() +{ + OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN"); + + ca_mutex_lock(g_bleServerStateMutex); + // free service Path(unique identifier for ble service) ca_mutex_lock(g_bleServiceMutex); OICFree(g_gattSvcPath); @@ -729,9 +718,9 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char * ca_mutex_lock(g_bleCharacteristicMutex); - if (NULL == g_gattWriteCharPath) + if (NULL == g_gattReadCharPath) { - OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "gGattWriteCharPath is NULL"); + OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_gattReadCharPath is NULL"); ca_mutex_unlock(g_bleCharacteristicMutex); return CA_STATUS_FAILED; } @@ -748,9 +737,9 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char * strncpy(data, charValue, charValueLen); OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]", - (const char *)g_gattWriteCharPath, data, charValueLen); + (const char *)g_gattReadCharPath, data, charValueLen); - int ret = bt_gatt_update_characteristic(g_gattWriteCharPath, data, charValueLen, address); + int ret = bt_gatt_update_characteristic(g_gattReadCharPath, data, charValueLen, address); if (0 != ret) { OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG, @@ -776,9 +765,9 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue, ca_mutex_lock(g_bleCharacteristicMutex); - if (NULL == g_gattWriteCharPath) + if (NULL == g_gattReadCharPath) { - OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_gattWriteCharPath is NULL"); + OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_gattReadCharPath is NULL"); ca_mutex_unlock(g_bleCharacteristicMutex); return CA_STATUS_FAILED; } @@ -794,9 +783,9 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue, strncpy(data, charValue, charValueLen + 1); OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]", - (const char *)g_gattWriteCharPath, data, charValueLen); + (const char *)g_gattReadCharPath, data, charValueLen); - int ret = bt_gatt_update_characteristic(g_gattWriteCharPath, data, charValueLen, NULL); + int ret = bt_gatt_update_characteristic(g_gattReadCharPath, data, charValueLen, NULL); if (0 != ret) { OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG, diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.c index 340dc14..cc2eb81 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.c @@ -315,7 +315,6 @@ void CAFreeBLEServiceInfo(BLEServiceInfo *bleServiceInfo) { if (bleServiceInfo->bdAddress) { - bt_device_destroy_bond(bleServiceInfo->bdAddress); bt_gatt_disconnect(bleServiceInfo->bdAddress); OICFree(bleServiceInfo->bdAddress); bt_gatt_destroy_attribute_handle(bleServiceInfo->service_clone); @@ -351,7 +350,7 @@ CAResult_t CAVerifyOICServiceByServiceHandle(bt_gatt_attribute_h serviceHandle) char *uuid = NULL; int ret = bt_gatt_get_service_uuid(serviceHandle, &uuid); - if (0 != ret) + if (0 != ret || NULL == uuid) { OIC_LOG(ERROR, TZ_BLE_CLIENT_UTIL_TAG, "bt_gatt_get_service_uuid failed !"); return CA_STATUS_FAILED; @@ -360,8 +359,11 @@ CAResult_t CAVerifyOICServiceByServiceHandle(bt_gatt_attribute_h serviceHandle) if (strcasecmp(uuid, OIC_BLE_SERVICE_ID) != 0) { OIC_LOG(ERROR, TZ_BLE_CLIENT_UTIL_TAG, "It is not OIC service!"); + OICFree(uuid); return CA_STATUS_FAILED; } + + OICFree(uuid); OIC_LOG(DEBUG, TZ_BLE_CLIENT_UTIL_TAG, "OUT"); return CA_STATUS_OK; } diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.h b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.h index dc2882e..b390f78 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.h +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/cableutil.h @@ -81,21 +81,6 @@ typedef enum } CHAR_TYPE; /** - * @enum CHAR_INDEX - * @brief indexes for the characteristics defined.. - * - * This provides index values for the characteristics - * which will be added to OIC service. - */ -typedef enum -{ - BLE_GATT_READ_CHAR_INDEX = 1, /**< read_char index */ - BLE_GATT_WRITE_CHAR_INDEX = 2, /**< write_char index */ - BLE_GATT_NOTIFY_CHAR_INDEX = 3 /**< Reserved char index for the time being. */ -} CHAR_INDEX; - - -/** * @struct stGattCharDescriptor_t * @brief Stores the information required to set the descriptor value of the Service. */ @@ -110,6 +95,18 @@ typedef struct gattCharDescriptor ///TODO: OIC_BLE_SERVICE_ID will be generated by invoking API in future. /** + * @def CA_BLE_READ_CHAR_UUID + * @brief UUID of read characteristic. This UUID is common across all platform for LE transport. + */ +#define CA_BLE_READ_CHAR_UUID "713D0002-503E-4C75-BA94-3148F18D941E" + +/** + * @def CA_BLE_WRITE_CHAR_UUID + * @brief UUID of write characteristic. This UUID is common across all platform for LE transport. + */ +#define CA_BLE_WRITE_CHAR_UUID "713D0003-503E-4C75-BA94-3148F18D941E" + +/** * @brief Used to increment the registered service count. * @return NONE */ -- 2.7.4