#include "oic_malloc.h"
#include "caleutil.h"
#include "caadapterutils.h"
+#include <glib.h>
+#ifndef BLE_TIZEN_40
+#include <bluetooth_internal.h>
+#endif
/**
* Logging tag for module name
oc_mutex_lock(g_leCharacteristicMutex);
+ /**
+ * NOTE : Currently this sequence of adding characterstic works both on android and tizen.
+ * With previous logic it was faling on android in some devices giving wrong attribute
+ * handle error. This issue needs to be fixed in Android BT layer but we have applied
+ * workaround for now so that it should work with both Android and Tizen devices.
+ */
if (read)
{
- g_gattReadCharPath = charPath;
- }
- else
- {
+ g_gattReadCharPath = charPath;
+ } else {
char desc_value[2] = {0, 0}; // Notification enabled.
bt_gatt_h descriptor = NULL;
permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE;
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL_RET(address, TAG, "address is null", CA_DEFAULT_BLE_MTU_SIZE);
- unsigned int mtu;
- int ret = bt_device_get_att_mtu(address, &mtu);
+ unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
+ int ret = 0;
+
+#ifdef BLE_TIZEN_40
+ 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;
+ }
+#else
+ ret = bt_device_get_att_mtu(address, &mtu);
if (0 != ret)
{
OIC_LOG_V(ERROR, TAG,
"bt_device_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
return CA_DEFAULT_BLE_MTU_SIZE;
}
+#endif // BLE_TIZEN_40
+
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;