From b8023dee27bf4fbdd129da515a06bf8978bb1a86 Mon Sep 17 00:00:00 2001 From: Kush Date: Tue, 10 Sep 2019 22:22:41 +0530 Subject: [PATCH] Adding logic for caching MTU in tizen LE Server https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/573/commits/6e689edd472e098a873b64549006d026e597c667 (cherry-picked from 6e689edd472e098a873b64549006d026e597c667) Change-Id: I8a7f8a5eee882894ac27cd98f501fe49345931ca Signed-off-by: Kush Signed-off-by: Sudipto --- .../src/bt_le_adapter/tizen/caleserver_mcd.c | 20 ++++++++++++++++++++ .../src/bt_le_adapter/tizen/caleserver_vd.c | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c index cf81f37..a9dbd57 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c @@ -1184,7 +1184,16 @@ uint16_t CALEServerGetMtuSize(const char* address) unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE; int ret = 0; + unsigned int cached_mtu; + oc_mutex_lock(g_LEClientListMutex); + cached_mtu = CAClientInfoGetMTUSize(g_LEClientList, address); + if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE) + { + OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu); + oc_mutex_unlock(g_LEClientListMutex); + return cached_mtu -CA_BLE_MTU_HEADER_SIZE; + } #ifdef TIZEN_4 bt_gatt_client_h client = NULL; ret = bt_gatt_client_create(address, &client); @@ -1192,6 +1201,7 @@ uint16_t CALEServerGetMtuSize(const char* address) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret)); + oc_mutex_unlock(g_LEClientListMutex); return CA_DEFAULT_BLE_MTU_SIZE; } @@ -1200,6 +1210,7 @@ uint16_t CALEServerGetMtuSize(const char* address) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret)); + oc_mutex_unlock(g_LEClientListMutex); return CA_DEFAULT_BLE_MTU_SIZE; } @@ -1208,6 +1219,7 @@ uint16_t CALEServerGetMtuSize(const char* address) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret)); + oc_mutex_unlock(g_LEClientListMutex); return CA_DEFAULT_BLE_MTU_SIZE; } #else @@ -1219,7 +1231,15 @@ uint16_t CALEServerGetMtuSize(const char* address) return CA_DEFAULT_BLE_MTU_SIZE; } #endif // TIZEN_4 + ret = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu); + if (CA_STATUS_OK != ret) + { + OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed"); + oc_mutex_unlock(g_LEClientListMutex); + return CA_DEFAULT_BLE_MTU_SIZE; + } + oc_mutex_unlock(g_LEClientListMutex); 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; 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 6a52aedb..1e309c1 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 @@ -1042,7 +1042,16 @@ uint16_t CALEServerGetMtuSize(const char* address) unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE; int ret = 0; + unsigned int cached_mtu; + oc_mutex_lock(g_LEClientListMutex); + cached_mtu = CAClientInfoGetMTUSize(g_LEClientList, address); + if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE) + { + OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu); + oc_mutex_unlock(g_LEClientListMutex); + return cached_mtu -CA_BLE_MTU_HEADER_SIZE; + } #ifdef TIZEN_4 bt_gatt_client_h client = NULL; ret = bt_gatt_client_create(address, &client); @@ -1050,6 +1059,7 @@ uint16_t CALEServerGetMtuSize(const char* address) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret)); + oc_mutex_unlock(g_LEClientListMutex); return CA_DEFAULT_BLE_MTU_SIZE; } @@ -1058,6 +1068,7 @@ uint16_t CALEServerGetMtuSize(const char* address) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret)); + oc_mutex_unlock(g_LEClientListMutex); return CA_DEFAULT_BLE_MTU_SIZE; } @@ -1066,6 +1077,7 @@ uint16_t CALEServerGetMtuSize(const char* address) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret)); + oc_mutex_unlock(g_LEClientListMutex); return CA_DEFAULT_BLE_MTU_SIZE; } #else @@ -1078,6 +1090,16 @@ uint16_t CALEServerGetMtuSize(const char* address) } #endif // TIZEN_4 + ret = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu); + if (CA_STATUS_OK != ret) + { + OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed"); + oc_mutex_unlock(g_LEClientListMutex); + return CA_DEFAULT_BLE_MTU_SIZE; + } + + oc_mutex_unlock(g_LEClientListMutex); + 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; -- 2.7.4