X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Fsrc%2Fbt_le_adapter%2Ftizen%2Fcaleserver_vd.c;h=bcfe6d41f5b7aee8689a68e397003ad8fea4bfb8;hb=0e2281a1d503c8ffb6fba02345355965fb498d83;hp=ef3654bab00dc5b1e8a14824e7f59d0d4107e959;hpb=3c093548382bb2542c87a67e6e5fa32552c29cb3;p=platform%2Fupstream%2Fiotivity.git 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 old mode 100755 new mode 100644 index ef3654b..bcfe6d4 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c @@ -27,15 +27,16 @@ #include "oic_string.h" #include "oic_malloc.h" #include "caleutil.h" +#include "caadapterutils.h" +#include +#ifndef BLE_TIZEN_40 +#include +#endif /** * Logging tag for module name */ #define TAG "OIC_CA_LE_SERVER_VD" -/** - * Initial buffer size for Gatt Server. - */ -#define CA_LE_INITIAL_BUF_SIZE 512 /** * The handle of the OIC server. @@ -124,11 +125,6 @@ static LEClientInfoList *g_LEClientList = NULL; */ static oc_mutex g_LEClientListMutex = NULL; -/** - * State of connect state - */ -static bool g_LEConnectedState = false; - void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress) { VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address"); @@ -137,7 +133,6 @@ void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddr if (connected) { OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress); - g_LEConnectedState = true; char *addr = OICStrdup(remoteAddress); oc_mutex_lock(g_LEClientListMutex); res = CAAddLEClientInfoToList(&g_LEClientList, addr); @@ -164,7 +159,6 @@ void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddr else { OIC_LOG_V(DEBUG, TAG, "Disconnected from [%s]", remoteAddress); - g_LEConnectedState = false; oc_mutex_lock(g_LEClientListMutex); CARemoveLEClientInfoFromList(&g_LEClientList, remoteAddress); oc_mutex_unlock(g_LEClientListMutex); @@ -190,6 +184,11 @@ void CALEServerNotificationSentCB(int result, char *remote_address, bt_gatt_serv bt_gatt_h characteristic, bool completed, void *user_data) #endif { + (void)server; + (void)characteristic; + (void)completed; + (void)user_data; + OIC_LOG_V(DEBUG, TAG, "Notification to the device[%s] result[%d]", remote_address, result); } @@ -228,7 +227,7 @@ CAResult_t CAStartLEGattServer() // For Read Characteristics. ret = CAAddNewCharacteristicsToGattServer(g_gattSvcPath, charReadUUID, charReadValue, - CA_LE_INITIAL_BUF_SIZE, true); + sizeof(charReadValue), true); if (CA_STATUS_OK != ret) { OIC_LOG_V(ERROR, TAG, "CAAddNewCharacteristicsToGattServer failed[%d]", ret); @@ -242,7 +241,7 @@ CAResult_t CAStartLEGattServer() ret = CAAddNewCharacteristicsToGattServer(g_gattSvcPath, charWriteUUID, charWriteValue, - CA_LE_INITIAL_BUF_SIZE, false); // For Write Characteristics. + sizeof(charWriteValue), false); // For Write Characteristics. if (CA_STATUS_OK != ret ) { OIC_LOG_V(ERROR, TAG, "CAAddNewCharacteristicsToGattServer failed[%d]", ret); @@ -284,6 +283,10 @@ CAResult_t CAStartLEGattServer() void CALENotificationCb(bool notify, bt_gatt_server_h server, bt_gatt_h gatt_handle, void *user_data) { + (void)server; + (void)gatt_handle; + (void)user_data; + OIC_LOG(DEBUG, TAG, "IN"); if (notify) { @@ -428,7 +431,7 @@ CAResult_t CAStopLEGattServer() if (context_event_loop) { - OIC_LOG_V(DEBUG, TAG, "g_eventLoop context %x", context_event_loop); + OIC_LOG_V(DEBUG, TAG, "g_eventLoop context %p", (void *)context_event_loop); g_main_context_wakeup(context_event_loop); // Kill g main loops and kill threads @@ -596,6 +599,7 @@ CAResult_t CAInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_create failed with ret[%s]", CALEGetErrorMsg(ret)); + bt_gatt_server_deinitialize(); return CA_STATUS_FAILED; } } @@ -613,7 +617,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_unregister_all_services failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } ret = bt_gatt_server_destroy(g_gattServer); @@ -621,7 +626,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_destroy failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } g_gattServer = NULL; @@ -630,7 +636,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_deinitialize failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } OIC_LOG(DEBUG, TAG, "OUT"); @@ -687,6 +694,10 @@ void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h s int charLen, void *userData) #endif { + (void)server; + (void)gatt_handle; + (void)userData; + OIC_LOG(INFO, TAG, "IN - WriteCharCB"); if (NULL == charValue || NULL == remoteAddress) @@ -743,7 +754,7 @@ CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath) VERIFY_NON_NULL(svcPath, TAG, "svcPath"); - OIC_LOG_V(DEBUG, TAG, "svcPath:%s", svcPath); + OIC_LOG_V(DEBUG, TAG, "svcPath: %s", (char *)svcPath); int ret = bt_gatt_server_register_service(g_gattServer, svcPath); if (0 != ret) @@ -846,12 +857,16 @@ CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const ch oc_mutex_lock(g_leCharacteristicMutex); + /** + * NOTE : Currently this sequence of adding characterstic works both on android and tizen. + * With previous logic it was faling on android in some devices giving wrong attribute + * handle error. This issue needs to be fixed in Android BT layer but we have applied + * workaround for now so that it should work with both Android and Tizen devices. + */ if (read) { - g_gattReadCharPath = charPath; - } - else - { + 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; @@ -897,12 +912,15 @@ CAResult_t CAUpdateCharacteristicsToGattClient(const char *address, const uint8_ oc_mutex_lock(g_leCharacteristicMutex); - if (!g_LEConnectedState) + oc_mutex_lock(g_LEClientListMutex); + if (CA_STATUS_FAILED == CAIsLEClientInfoInList(g_LEClientList, address)) { - OIC_LOG(ERROR, TAG, "g_LEConnectedState is false"); + OIC_LOG_V(ERROR, TAG, "%s device is not connected", address); + oc_mutex_unlock(g_LEClientListMutex); oc_mutex_unlock(g_leCharacteristicMutex); return CA_STATUS_FAILED; } + oc_mutex_unlock(g_LEClientListMutex); if (NULL == g_gattReadCharPath) { @@ -956,13 +974,6 @@ CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *charValue, uin oc_mutex_lock(g_leCharacteristicMutex); - if (!g_LEConnectedState) - { - OIC_LOG(ERROR, TAG, "g_LEConnectedState is false"); - oc_mutex_unlock(g_leCharacteristicMutex); - return CA_STATUS_FAILED; - } - if (NULL == g_gattReadCharPath) { OIC_LOG(ERROR, TAG, "g_gattReadCharPath is NULL"); @@ -1023,6 +1034,7 @@ void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback) bool CALEServerIsConnected(const char* address) { + (void)address; //@Todo return true; } @@ -1032,14 +1044,44 @@ uint16_t CALEServerGetMtuSize(const char* address) OIC_LOG(DEBUG, TAG, "IN"); VERIFY_NON_NULL_RET(address, TAG, "address is null", CA_DEFAULT_BLE_MTU_SIZE); - unsigned int mtu; - int ret = bt_device_get_att_mtu(address, &mtu); + unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE; + int ret = 0; + +#ifdef BLE_TIZEN_40 + bt_gatt_client_h client = NULL; + ret = bt_gatt_client_create(address, &client); + if (0 != ret) + { + OIC_LOG_V(ERROR, TAG, + "bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret)); + return CA_DEFAULT_BLE_MTU_SIZE; + } + + ret = bt_gatt_client_get_att_mtu(client, &mtu); + if (0 != ret) + { + OIC_LOG_V(ERROR, TAG, + "bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret)); + return CA_DEFAULT_BLE_MTU_SIZE; + } + + ret = bt_gatt_client_destroy(client); + if (0 != ret) + { + OIC_LOG_V(ERROR, TAG, + "bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret)); + return CA_DEFAULT_BLE_MTU_SIZE; + } +#else + ret = bt_device_get_att_mtu(address, &mtu); if (0 != ret) { OIC_LOG_V(ERROR, TAG, "bt_device_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret)); return CA_DEFAULT_BLE_MTU_SIZE; } +#endif // BLE_TIZEN_40 + OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu); OIC_LOG(DEBUG, TAG, "OUT"); return mtu - CA_BLE_MTU_HEADER_SIZE;