#include <bluetooth_internal.h>
#include "caedrinterface.h"
-#include "camutex.h"
+#include "octhread.h"
#include "caedrendpoint.h"
#include "caadapterutils.h"
#include "caedrutils.h"
/**
* Mutex to synchronize the access to Bluetooth device information list.
*/
-static ca_mutex g_edrDeviceListMutex = NULL;
+static oc_mutex g_edrDeviceListMutex = NULL;
/**
* Peer Bluetooth device information list.
/**
* Mutex to synchronize the access to Pending multicast data list.
*/
-static ca_mutex g_multicastDataListMutex = NULL;
+static oc_mutex g_multicastDataListMutex = NULL;
/**
* To Store Adapter Mode information
{
case BT_SOCKET_CONNECTED:
{
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
CAResult_t res = CAGetEDRDevice(g_edrDeviceList, connection->remote_address,
&device);
if (CA_STATUS_OK != res)
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed add device to list ret[%d]", res);
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
if(!device)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "EDRDevice is null!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
device->socketFD = connection->socket_fd;
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
if(!device)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "EDRDevice is null!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
device->socketFD = connection->socket_fd;
while (device->pendingDataList)
{
EDRData *edrData = device->pendingDataList->data;
- res = CAEDRSendData(device->socketFD, edrData->data,
- edrData->dataLength);
+ res = CAEDRSendData(device->socketFD, device->remoteAddress,
+ edrData->data, edrData->dataLength);
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to send pending data [%s]",
// Remove the data which send from pending list
CARemoveEDRDataFromList(&device->pendingDataList);
}
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
}
break;
case BT_SOCKET_DISCONNECTED:
{
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
CARemoveEDRDeviceFromList(&g_edrDeviceList, connection->remote_address);
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
}
break;
case BT_ADAPTER_DEVICE_DISCOVERY_FINISHED:
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Discovery finished!");
- ca_mutex_lock(g_multicastDataListMutex);
+ oc_mutex_lock(g_multicastDataListMutex);
u_arraylist_destroy(g_multicastDataList);
g_multicastDataList = NULL;
- ca_mutex_unlock(g_multicastDataListMutex);
+ oc_mutex_unlock(g_multicastDataListMutex);
}
break;
OIC_EDR_SERVICE_ID))
{
// Check if the deivce is already in the list
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
if (CA_STATUS_OK == CAGetEDRDevice(g_edrDeviceList,
discoveryInfo->remote_address, &device))
{
if(!device)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "EDRDevice is null!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
device->serviceSearched = true;
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to add device to list!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
if(!device)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "EDRDevice is null!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
}
}
device->serviceSearched = true;
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
}
else
{
- OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Device does not support OIC service!");
+ OIC_LOG(INFO, EDR_ADAPTER_TAG, "Device does not support OIC service!");
}
}
break;
default:
- OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Unknown Bluetooth Adapter device discovery state");
+ OIC_LOG(INFO, EDR_ADAPTER_TAG, "Unknown Bluetooth Adapter device discovery state");
}
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
return;
}
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
EDRDevice *device = NULL;
CAResult_t res = CAGetEDRDevice(g_edrDeviceList, sdpInfo->remote_address, &device);
if (device->serviceSearched)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Service is already searched for this device!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
}
}
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
if (!g_edrDeviceListMutex)
{
- g_edrDeviceListMutex = ca_mutex_new();
+ g_edrDeviceListMutex = oc_mutex_new();
}
if (!g_multicastDataListMutex)
{
- g_multicastDataListMutex = ca_mutex_new();
+ g_multicastDataListMutex = oc_mutex_new();
}
if (!g_edrDeviceListMutex || !g_multicastDataListMutex)
if (g_edrDeviceListMutex)
{
- ca_mutex_free(g_edrDeviceListMutex);
+ oc_mutex_free(g_edrDeviceListMutex);
g_edrDeviceListMutex = NULL;
}
if (g_multicastDataListMutex)
{
- ca_mutex_free(g_multicastDataListMutex);
+ oc_mutex_free(g_multicastDataListMutex);
g_multicastDataListMutex = NULL;
}
// Free EDRDevices list
if (g_edrDeviceListMutex)
{
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
CADestroyEDRDeviceList(&g_edrDeviceList);
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
}
if (g_multicastDataListMutex)
{
- ca_mutex_lock(g_multicastDataListMutex);
+ oc_mutex_lock(g_multicastDataListMutex);
u_arraylist_destroy(g_multicastDataList);
g_multicastDataList = NULL;
- ca_mutex_unlock(g_multicastDataListMutex);
+ oc_mutex_unlock(g_multicastDataListMutex);
}
// Free the mutex
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
EDRDeviceList *cur = g_edrDeviceList;
while (cur != NULL)
}
}
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
}
// Check the connection existence with remote device
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
CAResult_t result = CAGetEDRDevice(g_edrDeviceList, remoteAddress, &device);
if (CA_STATUS_OK != result)
{
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed create device and add to list!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return CA_STATUS_FAILED;
}
// Remove device from list
CARemoveEDRDeviceFromList(&g_edrDeviceList, remoteAddress);
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return CA_STATUS_FAILED;
}
}
// Remove device from list
CARemoveEDRDeviceFromList(&g_edrDeviceList, remoteAddress);
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return CA_STATUS_FAILED;
}
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
if (-1 == device->socketFD)
{
}
else
{
- result = CAEDRSendData(device->socketFD, data, dataLength);
+ result = CAEDRSendData(device->socketFD, device->remoteAddress, data, dataLength);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to send data!");
}
// Send the packet to all OIC devices
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
EDRDeviceList *curList = g_edrDeviceList;
CAResult_t result = CA_STATUS_FAILED;
}
else
{
- result = CAEDRSendData(device->socketFD, data, dataLength);
+ result = CAEDRSendData(device->socketFD, device->remoteAddress ,data, dataLength);
if (CA_STATUS_OK != result)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Failed to send data to [%s] !",
}
}
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
if(g_isDiscoveryServer)
{
multicastData->dataLength = dataLength;
// Add the data to pending multicast data list.
- ca_mutex_lock(g_multicastDataListMutex);
+ oc_mutex_lock(g_multicastDataListMutex);
if (NULL == g_multicastDataList)
{
g_multicastDataList = u_arraylist_create();
}
u_arraylist_add(g_multicastDataList, (void *)multicastData);
- ca_mutex_unlock(g_multicastDataListMutex);
+ oc_mutex_unlock(g_multicastDataListMutex);
}
}
}
// Get EDR device from list
- ca_mutex_lock(g_edrDeviceListMutex);
+ oc_mutex_lock(g_edrDeviceListMutex);
CAResult_t result = CAGetEDRDeviceBySocketId(g_edrDeviceList, data->socket_fd, &device);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Could not find the device!");
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
return;
}
- ca_mutex_unlock(g_edrDeviceListMutex);
+ oc_mutex_unlock(g_edrDeviceListMutex);
//: TODO Need to check if 'check required for socket still connected or not'
if (!device)