[CONPRO-1471]Adding logic for caching MTU in tizen LE Server 80/214380/1
authorKush <kush.agrawal@samsung.com>
Tue, 10 Sep 2019 16:52:41 +0000 (22:22 +0530)
committerSudipto <sudipto.bal@samsung.com>
Tue, 10 Sep 2019 16:52:41 +0000 (22:22 +0530)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/573/commits/6e689edd472e098a873b64549006d026e597c667
(cherry-picked from 6e689edd472e098a873b64549006d026e597c667)

Change-Id: I8a7f8a5eee882894ac27cd98f501fe49345931ca
Signed-off-by: Kush <kush.agrawal@samsung.com>
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleutil.c [changed mode: 0644->0755]
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleutil.h [changed mode: 0644->0755]

index 019984d..4af723f 100644 (file)
@@ -952,6 +952,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;
+    }
 
     bt_gatt_client_h client = NULL;
     ret = bt_gatt_client_create(address, &client);
@@ -959,6 +969,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;
     }
 
@@ -967,6 +978,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;
     }
 
@@ -975,9 +987,19 @@ 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;
     }
 
+    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);
     return mtu - CA_BLE_MTU_HEADER_SIZE;
 }
index 9f3791f..0f9aaab 100644 (file)
@@ -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 BLE_TIZEN_55
     ret = bt_gatt_server_get_device_mtu(address, &mtu);
     if (0 != ret)
@@ -1201,6 +1210,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;
     }
 
@@ -1209,6 +1219,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;
     }
 
@@ -1217,6 +1228,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
@@ -1230,6 +1242,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;
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;
old mode 100644 (file)
new mode 100755 (executable)
index a4c4561..0c12e25
@@ -112,7 +112,7 @@ void CARemoveLEDataFromList(LEDataList **dataList)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    VERIFY_NON_NULL(dataList, TAG, "Data list is null");
+    VERIFY_NON_NULL_VOID(dataList, TAG, "Data list is null");
 
     if (*dataList)
     {
@@ -322,6 +322,7 @@ CAResult_t CAAddLEClientInfoToList(LEClientInfoList **clientList,
     }
 
     node->remoteAddress= clientAddress;
+    node->mtuSize = 0;
     node->next = NULL;
 
     if (*clientList == NULL)   // Empty list
@@ -339,6 +340,45 @@ CAResult_t CAAddLEClientInfoToList(LEClientInfoList **clientList,
     return CA_STATUS_OK;
 }
 
+uint16_t CAClientInfoGetMTUSize(LEClientInfoList *clientList,
+                                        const char *clientAddress)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+
+    LEClientInfoList *temp = clientList;
+    while (temp)
+    {
+        if (!strcasecmp(temp->remoteAddress, clientAddress))
+        {
+            return temp->mtuSize;
+        }
+        temp = temp->next;
+    }
+
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return 0;
+}
+
+CAResult_t CAClientInfoUpdateMTUSize(LEClientInfoList *clientList,
+                                        const char *clientAddress,uint16_t mtu_size)
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+
+    LEClientInfoList *temp = clientList;
+    while (temp)
+    {
+        if (!strcasecmp(temp->remoteAddress, clientAddress))
+        {
+            temp->mtuSize = mtu_size;
+            return CA_STATUS_OK;
+        }
+        temp = temp->next;
+    }
+
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_FAILED;
+}
+
 CAResult_t CAIsLEClientInfoInList(LEClientInfoList *clientList,
                                         const char *clientAddress)
 {
old mode 100644 (file)
new mode 100755 (executable)
index e25af92..7bd4ed0
@@ -80,6 +80,7 @@ typedef struct _LEServerInfoList
 typedef struct _LEClientInfoList
 {
     char *remoteAddress;
+    uint16_t mtuSize;
     struct _LEClientInfoList *next;
 } LEClientInfoList;
 
@@ -236,4 +237,8 @@ void CADisconnectAllClient(LEClientInfoList *clientList);
  */
 const char *CALEGetErrorMsg(bt_error_e err);
 
+uint16_t CAClientInfoGetMTUSize(LEClientInfoList *clientList, const char *clientAddress);
+
+CAResult_t CAClientInfoUpdateMTUSize(LEClientInfoList *clientList, const char *clientAddress, uint16_t mtu_size);
+
 #endif /* TZ_BLE_UTIL_H_ */