Changing logic of fetching MTU size in server size.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleserver.c
index 9c74caf..019984d 100644 (file)
@@ -949,8 +949,35 @@ uint16_t CALEServerGetMtuSize(const char* address)
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL_RET(address, TAG, "address is null",
                         CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_MTU_HEADER_SIZE);
-    //@Todo
-    OIC_LOG(INFO, TAG,
-            "bt_device_get_att_mtu is not supported");
-    return CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_MTU_HEADER_SIZE;
+
+    unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
+    int ret = 0;
+
+    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;
+    }
+
+    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;
 }