[CONPRO-1471]Adding logic for caching MTU in tizen LE Server
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleserver_vd.c
index bcd5d0d..f06d8c6 100644 (file)
@@ -1046,6 +1046,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 BLE_TIZEN_55
     ret = bt_gatt_server_get_device_mtu(address, &mtu);
@@ -1063,6 +1073,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;
     }
 
@@ -1071,6 +1082,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;
     }
 
@@ -1079,6 +1091,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
@@ -1092,6 +1105,15 @@ uint16_t CALEServerGetMtuSize(const char* address)
 #endif // BLE_TIZEN_40
 #endif // BLE_TIZEN_55
 
+    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;