#include "oic_string.h"
#include "oic_malloc.h"
#include "caleutil.h"
+#include "caadapterutils.h"
+#include <glib.h>
+#ifndef TIZEN_4
+#include <bluetooth_internal.h>
+#endif
/**
* Logging tag for module name
*/
static oc_mutex g_LEClientListMutex = NULL;
-/**
- * State of connect state
- */
-static bool g_LEConnectedState = false;
-
void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress)
{
VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address");
if (connected)
{
OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress);
- g_LEConnectedState = true;
char *addr = OICStrdup(remoteAddress);
oc_mutex_lock(g_LEClientListMutex);
res = CAAddLEClientInfoToList(&g_LEClientList, addr);
else
{
OIC_LOG_V(DEBUG, TAG, "Disconnected from [%s]", remoteAddress);
- g_LEConnectedState = false;
oc_mutex_lock(g_LEClientListMutex);
CARemoveLEClientInfoFromList(&g_LEClientList, remoteAddress);
oc_mutex_unlock(g_LEClientListMutex);
if (context_event_loop)
{
- OIC_LOG_V(DEBUG, TAG, "g_eventLoop context %x", context_event_loop);
+ OIC_LOG_V(DEBUG, TAG, "g_eventLoop context %p", (void *)context_event_loop);
g_main_context_wakeup(context_event_loop);
// Kill g main loops and kill threads
{
OIC_LOG_V(ERROR, TAG, "bt_gatt_server_create failed with ret[%s]",
CALEGetErrorMsg(ret));
+ bt_gatt_server_deinitialize();
return CA_STATUS_FAILED;
}
}
{
OIC_LOG_V(ERROR, TAG, "bt_gatt_server_unregister_all_services failed with ret[%s]",
CALEGetErrorMsg(ret));
- return CA_STATUS_FAILED;
+ // CONPRO-1181 continue even bt API fails during DeInit
+ //return CA_STATUS_FAILED;
}
ret = bt_gatt_server_destroy(g_gattServer);
{
OIC_LOG_V(ERROR, TAG, "bt_gatt_server_destroy failed with ret[%s]",
CALEGetErrorMsg(ret));
- return CA_STATUS_FAILED;
+ // CONPRO-1181 continue even bt API fails during DeInit
+ //return CA_STATUS_FAILED;
}
g_gattServer = NULL;
{
OIC_LOG_V(ERROR, TAG, "bt_gatt_server_deinitialize failed with ret[%s]",
CALEGetErrorMsg(ret));
- return CA_STATUS_FAILED;
+ // CONPRO-1181 continue even bt API fails during DeInit
+ //return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TAG, "OUT");
VERIFY_NON_NULL(svcPath, TAG, "svcPath");
- OIC_LOG_V(DEBUG, TAG, "svcPath:%s", svcPath);
+ OIC_LOG_V(DEBUG, TAG, "svcPath: %s", (char *)svcPath);
int ret = bt_gatt_server_register_service(g_gattServer, svcPath);
if (0 != ret)
if (read)
{
- 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;
CALEGetErrorMsg(ret));
return CA_STATUS_FAILED;
}
+ g_gattReadCharPath = charPath;
+ }
+ else{
g_gattWriteCharPath = charPath;
}
oc_mutex_lock(g_leCharacteristicMutex);
- if (!g_LEConnectedState)
+ oc_mutex_lock(g_LEClientListMutex);
+ if (CA_STATUS_FAILED == CAIsLEClientInfoInList(g_LEClientList, address))
{
- OIC_LOG(ERROR, TAG, "g_LEConnectedState is false");
+ OIC_LOG_V(ERROR, TAG, "%s device is not connected", address);
+ oc_mutex_unlock(g_LEClientListMutex);
oc_mutex_unlock(g_leCharacteristicMutex);
return CA_STATUS_FAILED;
}
+ oc_mutex_unlock(g_LEClientListMutex);
if (NULL == g_gattReadCharPath)
{
oc_mutex_lock(g_leCharacteristicMutex);
- if (!g_LEConnectedState)
- {
- OIC_LOG(ERROR, TAG, "g_LEConnectedState is false");
- oc_mutex_unlock(g_leCharacteristicMutex);
- return CA_STATUS_FAILED;
- }
-
if (NULL == g_gattReadCharPath)
{
OIC_LOG(ERROR, TAG, "g_gattReadCharPath is NULL");
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 TIZEN_4
+ 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 // TIZEN_4
+
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;