Use GATT server's get mtu size API instead of GATT client API
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleserver_mcd.c
index 0fe64b8..9f3791f 100644 (file)
@@ -28,7 +28,7 @@
 #include "oic_malloc.h"
 #include "caleutil.h"
 #include "cautilinterface.h"
-#ifndef TIZEN_4
+#ifndef BLE_TIZEN_40
 #include <bluetooth_internal.h>
 #endif
 
@@ -147,10 +147,10 @@ static char *custom_scanrsp_data = NULL;
 static int custom_scanrsp_data_length = 0;
 
 /**
- * Maximum lenght of BLE advertisement packet data size is acctually 24 bytes,
+ * Maximum length of BLE advertisement packet data size is acctually 24 bytes,
  * but for safety reason 1 additional byte is allocated.
  */
-const int max_ble_advertisement_packet_data_size = 25;
+const int g_leAdvPacketDataSizeMax = 25;
 
 
 CAResult_t CAsetServerAdvertisementData(const char *data, int length)
@@ -193,12 +193,12 @@ void CAsetServerAdvertisementDataGetter(CAAdvertisementDataGetterCB getter)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-void CAsetServerAutoAdvertisement(bool auto_advertisement)
+void CAsetServerAutoAdvertisement(bool autoAdvertisement)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
     oc_mutex_lock(g_leServerStateMutex);
-    g_leServerAutoAdvertisement = auto_advertisement;
+    g_leServerAutoAdvertisement = autoAdvertisement;
     oc_mutex_unlock(g_leServerStateMutex);
 
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -409,8 +409,8 @@ CAResult_t CALEStartAdvertise()
     if(g_leServerAdvertisementDataGetter)
     {
         int length;
-        data = (char*) malloc(max_ble_advertisement_packet_data_size);
-        g_leServerAdvertisementDataGetter(max_ble_advertisement_packet_data_size, data, &length);
+        data = (char*) malloc(g_leAdvPacketDataSizeMax);
+        g_leServerAdvertisementDataGetter(g_leAdvPacketDataSizeMax, data, &length);
         if(!data || length <= 0)
         {
             OIC_LOG(WARNING, TAG, "Invalid data. Custom advertisement data will not be set.");
@@ -428,7 +428,8 @@ CAResult_t CALEStartAdvertise()
     }
     
     //This array is freed here because it's used in CALEStartAdvertiseImpl() method (freeing earlier causes bluetooth to crash)
-    free(data);
+    if(data)
+        free(data);
     OIC_LOG(DEBUG, TAG, "OUT");
     return res;
 }
@@ -1184,7 +1185,16 @@ uint16_t CALEServerGetMtuSize(const char* address)
     unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
     int ret = 0;
 
-#ifdef TIZEN_4
+#ifdef BLE_TIZEN_55
+    ret = bt_gatt_server_get_device_mtu(address, &mtu);
+    if (0 != ret)
+    {
+        OIC_LOG_V(ERROR, TAG,
+                  "bt_gatt_server_get_device_mtu failed with return [%s]", CALEGetErrorMsg(ret));
+        return CA_DEFAULT_BLE_MTU_SIZE;
+    }
+#else
+#ifdef BLE_TIZEN_40
     bt_gatt_client_h client = NULL;
     ret = bt_gatt_client_create(address, &client);
     if (0 != ret)
@@ -1217,7 +1227,8 @@ uint16_t CALEServerGetMtuSize(const char* address)
                   "bt_device_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
-#endif // TIZEN_4
+#endif // BLE_TIZEN_40
+#endif // BLE_TIZEN_55
 
     OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu);
     OIC_LOG(DEBUG, TAG, "OUT");