-/* ****************************************************************
+/******************************************************************
*
* Copyright 2014 Samsung Electronics All Rights Reserved.
*
#endif
/**
- * @brief Initialize EDR Interface.
- * @param registerCallback [IN] Callback to register EDR interface to Connectivity
- * Abstraction Layer
- * @param reqRespCallback [IN] Callback to notify request and response messages from server(s)
- * started at Connectivity Abstraction Layer.
- * @param netCallback [IN] Callback to notify the network additions to Connectivity
- * Abstraction Layer.
- * @param handle [IN] Threadpool Handle
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
- * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
- * not enabled
- * @retval #CA_STATUS_FAILED Operation failed
+ * @brief Initialize EDR Interface.
+ * @param registerCallback [IN] Callback to register EDR interface to Connectivity
+ * Abstraction Layer
+ * @param reqRespCallback [IN] Callback to notify request and response messages from server(s)
+ * started at Connectivity Abstraction Layer.
+ * @param netCallback [IN] Callback to notify the network additions to Connectivity
+ * Abstraction Layer.
+ * @param handle [IN] Threadpool Handle
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback reqRespCallback,
- CANetworkChangeCallback netCallback,
- ca_thread_pool_t handle);
+ CANetworkChangeCallback netCallback, ca_thread_pool_t handle);
/**
- * @brief Starts EDR connectivity adapters. As its peer to peer it doesnot require to start
- * any servers.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_ADAPTER_NOT_ENABLED Bluetooth adapter is not enabled
- * @retval #CA_STATUS_FAILED Operation failed
- *
+ * @brief Starts EDR connectivity adapters. As its peer to peer it doesnot require to start
+ * any servers.
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAStartEDR();
* @brief Starts listening server for receiving multicast search requests.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
*
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
- * service UUID
- * @retval #CA_STATUS_FAILED Operation failed
- *
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAStartEDRListeningServer();
* @brief Starting discovery server for receiving multicast advertisements.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
*
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
- * service UUID
- * @retval #CA_STATUS_FAILED Operation failed
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAStartEDRDiscoveryServer();
*
*/
int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLength);
+ uint32_t dataLength);
/**
* @brief Sends multicast data to all discovered bluetooth OIC devices using the adapter
* @param info [OUT] Array of local connectivity information structures.
* @param size [OUT] Size of the array @info.
*
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
- * @retval #CA_MEMORY_ALLOC_FAILED Failed to allocate memory
- * @retval #CA_STATUS_FAILED Operation failed
- * @remarks info is allocated in this API and should be freed by the caller.
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
/**
* @brief Read Synchronous API callback.
- * @return #CA_STATUS_OK on success otherwise proper error code.
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_FAILED Operation failed
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAReadEDRData();
/**
* @brief EDR Stops all RFCOMM servers and close sockets.
- * @return #CA_STATUS_OK or Appropriate error code
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAStopEDR();
/**
* @brief Initializes the adapter queues.
* This will initiates both server and receiver adapter queues.
- * @return #CA_STATUS_OK or Appropriate error code
- * @retval #CA_STATUS_OK Successful
- * @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
- * @retval #CA_MEMORY_ALLOC_FAILED Failed to allocate memory
- * @retval #CA_STATUS_FAILED Operation failed
+ * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
*/
CAResult_t CAAdapterStartQueue();
-/* ****************************************************************
+/******************************************************************
*
* Copyright 2014 Samsung Electronics All Rights Reserved.
*
typedef enum
{
- STATE_DISCONNECTED, /**< State is Disconnected */
- STATE_CONNECTED /**< State is Connected */
+ STATE_DISCONNECTED, /**< State is Disconnected */
+ STATE_CONNECTED /**< State is Connected */
} CAConnectedState_t;
-typedef struct connected_state {
+typedef struct connected_state
+{
uint8_t address[CA_MACADDR_SIZE];
CAConnectedState_t state;
} state_t;
/**
- * @enum CAAdapterServerType_t
+ * @enum CAAdapterServerType_t
* @brief Enum for defining different server types.
*/
typedef enum
{
- CA_UNICAST_SERVER = 0, /**< Unicast Server */
- CA_MULTICAST_SERVER, /**< Multicast Server */
- CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
+ CA_UNICAST_SERVER = 0, /**< Unicast Server */
+ CA_MULTICAST_SERVER, /**< Multicast Server */
+ CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
} CAAdapterServerType_t;
/**
* @struct CAEDRData
- * @brief Structure to maintain the information of data in message queue.
+ * @brief Structure to maintain the information of data in message queue.
*/
typedef struct
{
/**
* @struct CAEDRNetworkEvent
- * @brief Structure to maintain the adapter information and its status.
+ * @brief Structure to maintain the adapter information and its status.
*/
typedef struct
{
- CALocalConnectivity_t *info; /**< Local Connectivity Information */
- CANetworkStatus_t status; /**< Network Status */
+ CALocalConnectivity_t *info; /**< Local Connectivity Information */
+ CANetworkStatus_t status; /**< Network Status */
} CAEDRNetworkEvent;
/**
* @return NONE
* @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
*/
-typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress,
- const void *data, uint32_t dataLength, uint32_t *sentLength);
+typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const void *data,
+ uint32_t dataLength, uint32_t *sentLength);
/**
* @brief This will be used during change in network status.
- * @param status [IN] Network Status of the adapter
+ * @param status [IN] Network Status of the adapter
* @return NONE
*/
typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
/**
* @brief Initialize the network monitor module
- *
+ * @param threadPool [IN] Threadpool Handle
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
* @retval #CA_STATUS_FAILED Operation failed
* @see CAEDRTerminateNetworkMonitor()
*/
-CAResult_t CAEDRInitializeNetworkMonitor();
+CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
/**
* @brief Deinitialize with bluetooth adapter.
* @return NONE
- * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
- * @see CAEDRInitializeNetworkMonitor()
+ * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
+ * @see CAEDRInitializeNetworkMonitor()
*/
-void CAEDRTerminateNetworkMonitor(void);
+void CAEDRTerminateNetworkMonitor();
/**
- * @brief Start Network Monitoring Process
+ * @brief Start Network Monitoring Process
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAEDRStartNetworkMonitor();
/**
- * @brief Stop Network Monitoring Process
+ * @brief Stop Network Monitoring Process
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAEDRStopNetworkMonitor();
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_FAILED Operation failed
*/
-CAResult_t CAEDRClientSetCallbacks(void);
+CAResult_t CAEDRClientSetCallbacks();
/**
* @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
* @return NONE
- * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
- * @see CAEDRClientSetCallbacks()
+ * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
+ * @see CAEDRClientSetCallbacks()
*/
-void CAEDRClientUnsetCallbacks(void);
+void CAEDRClientUnsetCallbacks();
/**
- * @brief Used to initialize the EDR client module where mutex is initialized
+ * @brief Used to initialize the EDR client module where mutex is initialized
* @return NONE
*/
void CAEDRInitializeClient(ca_thread_pool_t handle);
/**
- * @brief Destroys the Device list and mutex.
+ * @brief Destroys the Device list and mutex.
* @return NONE
*/
void CAEDRClientTerminate();
/**
- * @brief Closes all the client connection to peer bluetooth devices.
+ * @brief Closes all the client connection to peer bluetooth devices.
* @return NONE
*/
-void CAEDRClientDisconnectAll(void);
+void CAEDRClientDisconnectAll();
/**
* @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
*/
void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
-
/**
* @brief Get the local bluetooth adapter information.
*
- * @param info [IN] Local bluetooth adapter information
+ * @param info [OUT] Local bluetooth adapter information
*
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
*
* @param serviceUUID [IN] The UUID of service with which RFCOMM server needs to be started.
* @param serverFD [IN] The RFCOMM server socket file descriptor.
+ * @param handle [IN] Threadpool Handle
*
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_FAILED Operation failed
*
*/
-CAResult_t CAEDRManagerReadData(void);
+CAResult_t CAEDRManagerReadData();
/**
- * @brief This function gets bluetooth adapter enable state.
- * @param state [OUT] State of the Adapter.
+ * @brief This function gets bluetooth adapter enable state.
+ * @param state [OUT] State of the Adapter.
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAEDRGetAdapterEnableState(bool *state);
/**
- * @brief This function sends data to specified remote bluetooth device.
- * @param remoteAddress [IN] Remote EDR Address
- * @param serviceUUID [IN] Service UUID of the device
- * @param data [IN] Data to be sent
- * @param dataLength [IN] Length of the data to be sent
- * @param sentLength [OUT] Length of the actual sent data
+ * @brief This function sends data to specified remote bluetooth device.
+ * @param remoteAddress [IN] Remote EDR Address
+ * @param serviceUUID [IN] Service UUID of the device
+ * @param data [IN] Data to be sent
+ * @param dataLength [IN] Length of the data to be sent
+ * @param sentLength [OUT] Length of the actual sent data
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
const void *data, uint32_t dataLength, uint32_t *sentLength);
/**
- * @brief This function sends data to all bluetooth devices running OIC service.
- * @param serviceUUID [IN] Service UUID of the device
- * @param data [IN] Data to be sent
- * @param dataLength [IN] Length of the data to be sent
- * @param sentLength [OUT] Length of the actual sent data
+ * @brief This function sends data to all bluetooth devices running OIC service.
+ * @param serviceUUID [IN] Service UUID of the device
+ * @param data [IN] Data to be sent
+ * @param dataLength [IN] Length of the data to be sent
+ * @param sentLength [OUT] Length of the actual sent data
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
uint32_t dataLength, uint32_t *sentLength);
+/**
+ * @brief This function gets bonded bluetooth device list
+ * @return #CA_STATUS_OK or Appropriate error code
+ */
+CAResult_t CAEDRGetBondedDeviceList();
+
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif //__CA_EDR_INTERFACE_H_
-
-/* ****************************************************************
+/******************************************************************
*
* Copyright 2014 Samsung Electronics All Rights Reserved.
*
*/
static bool g_serverState = false;
-static CAResult_t CAStartServer(void);
-static CAResult_t CAEDRInitializeQueueHandlers(void);
-CAResult_t CAEDRInitializeSendHandler(void);
-CAResult_t CAEDRInitializeReceiveHandler(void);
-void CAAdapterTerminateQueues(void);
+static CAResult_t CAStartServer();
+static CAResult_t CAEDRInitializeQueueHandlers();
+CAResult_t CAEDRInitializeSendHandler();
+CAResult_t CAEDRInitializeReceiveHandler();
+void CAAdapterTerminateQueues();
void CAAdapterDataSendHandler(void *context);
void CAAdapterDataReceiverHandler(void *context);
CAResult_t CAAdapterStopQueue();
-void CAAdapterRecvData(const char *remoteAddress, const void *data,
- uint32_t dataLength, uint32_t *sentLength);
+void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dataLength,
+ uint32_t *sentLength);
void CAEDRNotifyNetworkStatus(CANetworkStatus_t status);
void CAEDROnNetworkStatusChanged(void *context);
-CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
- const void *data, uint32_t dataLength, uint32_t *sentLength);
+CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const void *data,
+ uint32_t dataLength, uint32_t *sentLength);
CAEDRNetworkEvent *CAEDRCreateNetworkEvent(CALocalConnectivity_t *connectivity,
CANetworkStatus_t status);
CAResult_t CAEDRClientSendData(const char *remoteAddress, const char *serviceUUID,
- const void *data, uint32_t dataLength, uint32_t *sentLength);
+ const void *data, uint32_t dataLength, uint32_t *sentLength);
/**
* @fn CACreateEDRData
* @brief Helper function to create CAEDRData
*/
static CAEDRData *CACreateEDRData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLength);
+ uint32_t dataLength);
/**
* @fn CAFreeEDRData
g_networkChangeCallback = networkStateChangeCallback;
// Initialize EDR Network Monitor
- CAResult_t err = CAEDRInitializeNetworkMonitor();
+ CAResult_t err = CAEDRInitializeNetworkMonitor(handle);
if (CA_STATUS_OK != err)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "EDR N/w Monitor Initialize failed!, error number [%d]",
return CA_STATUS_OK;
}
-CAResult_t CAStartEDR(void)
+CAResult_t CAStartEDR()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
//Start Monitoring EDR Network
CAResult_t ret = CAEDRStartNetworkMonitor();
- if(CA_STATUS_OK != ret)
+ if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Start n/w monitor");
}
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!");
g_adapterState = false;
- return CA_STATUS_OK;
+ return CA_ADAPTER_NOT_ENABLED;
}
if (CA_STATUS_OK != (ret = CAEDRClientSetCallbacks()))
if (CA_STATUS_OK != (ret = CAAdapterStartQueue()))
{
- OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "CAAdapterStartQueue failed!, error number [%d] ",
- ret);
+ OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "CAAdapterStartQueue failed!, error number [%d] ", ret);
}
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
return ret;
}
-CAResult_t CAStartEDRListeningServer(void)
+CAResult_t CAStartEDRListeningServer()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
return CAStartServer();
}
-CAResult_t CAStartEDRDiscoveryServer(void)
+CAResult_t CAStartEDRDiscoveryServer()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
}
int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLength)
+ uint32_t dataLength)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
- CAResult_t err = CA_STATUS_OK;
-
// Input validation
VERIFY_NON_NULL_RET(remoteEndpoint, EDR_ADAPTER_TAG, "Remote endpoint is null", -1);
VERIFY_NON_NULL_RET(data, EDR_ADAPTER_TAG, "Data is null", -1);
- if (0 == strlen(remoteEndpoint->addressInfo.BT.btMacAddress))
+ if (0 == dataLength)
{
- OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: EDR Address is empty!");
+ OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: data length is zero!");
return -1;
}
- if (0 == dataLength)
+ if (0 == strlen(remoteEndpoint->addressInfo.BT.btMacAddress))
{
- OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: data length is zero!");
+ OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: EDR Address is empty!");
return -1;
}
uint32_t sentLength = 0;
const char *serviceUUID = OIC_EDR_SERVICE_ID;
const char *address = remoteEndpoint->addressInfo.BT.btMacAddress;
- if (CA_STATUS_OK != (err = CAAdapterSendData(address, serviceUUID, data,
- dataLength, &sentLength)))
+ CAResult_t err = CAAdapterSendData(address, serviceUUID, data, dataLength, &sentLength);
+ if (CA_STATUS_OK != err)
{
OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Send unicast data failed!, error num [%d]", err);
return -1;
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CASendEDRMulticastData");
- CAResult_t err = CA_STATUS_OK;
-
// Input validation
VERIFY_NON_NULL_RET(data, EDR_ADAPTER_TAG, "Data is null", -1);
uint32_t sentLen = 0;
const char *serviceUUID = OIC_EDR_SERVICE_ID;
- if (CA_STATUS_OK != (err = CAAdapterSendData(NULL, serviceUUID, data, dataLength,
- &sentLen)))
+ CAResult_t err = CAAdapterSendData(NULL, serviceUUID, data, dataLength, &sentLen);
+ if (CA_STATUS_OK != err)
{
- OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Send multicast data failed!, error num [%d]",
- err);
+ OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Send multicast data failed!, error num [%d]", err);
return -1;
}
return err;
}
-CAResult_t CAReadEDRData(void)
+CAResult_t CAReadEDRData()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
return CAEDRManagerReadData();
}
-CAResult_t CAStopEDR(void)
+CAResult_t CAStopEDR()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
return CA_STATUS_OK;
}
-void CATerminateEDR(void)
+void CATerminateEDR()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
+ // Stop EDR adapter
+ CAStopEDR();
// Terminate EDR Network Monitor
CAEDRTerminateNetworkMonitor();
// Terminate thread pool
g_edrThreadPool = NULL;
- // Terminate BT Client
+ // Terminate EDR Client
CAEDRClientTerminate();
- // Terminate BT Server
+ // Terminate EDR Server
CAEDRServerTerminate();
// Free LocalConnectivity information
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
-CAResult_t CAStartServer(void)
+CAResult_t CAStartServer()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
if (-1 < g_serverId)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Server is already in running state.");
- return CA_STATUS_OK;
+ return CA_SERVER_STARTED_ALREADY;
}
if (CA_STATUS_OK != (err = CAEDRServerStart(OIC_EDR_SERVICE_ID, &g_serverId, g_edrThreadPool)))
return err;
}
-CAResult_t CAEDRInitializeQueueHandlers(void)
+CAResult_t CAEDRInitializeQueueHandlers()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
return CA_STATUS_FAILED;
}
-CAResult_t CAEDRInitializeSendHandler(void)
+CAResult_t CAEDRInitializeSendHandler()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
// Check if the message queue is already initialized
}
if (CA_STATUS_OK != CAQueueingThreadInitialize(g_sendQueueHandle, g_edrThreadPool,
- CAAdapterDataSendHandler, CAEDRDataDestroyer))
+ CAAdapterDataSendHandler, CAEDRDataDestroyer))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Initialize send queue thread");
return CA_STATUS_FAILED;
return CA_STATUS_OK;
}
-CAResult_t CAEDRInitializeReceiveHandler(void)
+CAResult_t CAEDRInitializeReceiveHandler()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
// Check if the message queue is already initialized
}
if (CA_STATUS_OK != CAQueueingThreadInitialize(g_recvQueueHandle, g_edrThreadPool,
- CAAdapterDataReceiverHandler, CAEDRDataDestroyer))
+ CAAdapterDataReceiverHandler,
+ CAEDRDataDestroyer))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to Initialize send queue thread");
return CA_STATUS_FAILED;
return CA_STATUS_OK;
}
-void CAAdapterTerminateQueues(void)
+void CAAdapterTerminateQueues()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CAAdapterDataSendHandler");
CAEDRData *message = (CAEDRData *) context;
- if (message == NULL)
+ if (NULL == message)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to get message!");
return;
const char *serviceUUID = NULL;
uint32_t sentLength = 0;
- if(NULL == message->remoteEndpoint)
+ if (NULL == message->remoteEndpoint)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "remoteEndpoint is not available");
}
+ else
+ {
+ remoteAddress = message->remoteEndpoint->addressInfo.BT.btMacAddress;
+ serviceUUID = message->remoteEndpoint->resourceUri;
+ }
- remoteAddress = message->remoteEndpoint->addressInfo.BT.btMacAddress;
- serviceUUID = message->remoteEndpoint->resourceUri;
-
+ uint32_t dataSegmentLength = message->dataLen + CA_HEADER_LENGTH;
+ uint32_t dataLen = message->dataLen;
OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "checking for fragmentation and the dataLen is %d",
message->dataLen);
char *header = (char *) OICCalloc(CA_HEADER_LENGTH, sizeof(char));
- VERIFY_NON_NULL_VOID(header, EDR_ADAPTER_TAG, "Malloc failed");
+ VERIFY_NON_NULL_VOID(header, EDR_ADAPTER_TAG, "Memory allocation failed");
- char* dataSegment = (char *) OICCalloc(message->dataLen + CA_HEADER_LENGTH, sizeof(char));
+ char* dataSegment = (char *) OICCalloc(dataSegmentLength, sizeof(char));
if (NULL == dataSegment)
{
- OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Malloc failed");
+ OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Memory allocation failed");
OICFree(header);
return;
}
- CAResult_t result = CAGenerateHeader(header, message->dataLen);
- if (CA_STATUS_OK != result )
+ CAResult_t result = CAGenerateHeader(header, dataLen);
+ if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Generate header failed");
OICFree(header);
memcpy(dataSegment, header, CA_HEADER_LENGTH);
OICFree(header);
- int32_t length = 0;
- if (CA_SUPPORTED_BLE_MTU_SIZE >= message->dataLen)
+ uint32_t length = 0;
+ if (CA_SUPPORTED_EDR_MTU_SIZE > dataSegmentLength)
{
- length = message->dataLen + CA_HEADER_LENGTH;
- OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "length [%d]", length);
- memcpy(dataSegment + CA_HEADER_LENGTH, message->data, message->dataLen);
+ length = dataSegmentLength;
+ memcpy(dataSegment + CA_HEADER_LENGTH, message->data, dataLen);
}
else
{
- length = CA_SUPPORTED_BLE_MTU_SIZE;
- OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "length [%d]", length);
+ length = CA_SUPPORTED_EDR_MTU_SIZE;
memcpy(dataSegment + CA_HEADER_LENGTH, message->data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_HEADER_LENGTH);
+ CA_SUPPORTED_EDR_MTU_SIZE - CA_HEADER_LENGTH);
}
- int32_t iter = message->dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
- int32_t index = 0;
- if (CA_STATUS_OK != CAEDRClientSendData(remoteAddress, serviceUUID,
- dataSegment, length, &sentLength))
+ uint32_t iter = dataSegmentLength / CA_SUPPORTED_EDR_MTU_SIZE;
+ uint32_t index = 0;
+ if (CA_STATUS_OK != CAEDRClientSendData(remoteAddress, serviceUUID, dataSegment, length,
+ &sentLength))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "CAEDRClientSendData API failed");
OICFree(dataSegment);
OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "Sending the chunk number [%d]", index);
if (CA_STATUS_OK != CAEDRClientSendData(remoteAddress, serviceUUID,
- message->data + ((index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH),
- CA_SUPPORTED_BLE_MTU_SIZE, &sentLength))
+ message->data + ((index * CA_SUPPORTED_EDR_MTU_SIZE) - CA_HEADER_LENGTH),
+ CA_SUPPORTED_EDR_MTU_SIZE, &sentLength))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "CAEDRClientSendData API failed");
return;
}
}
- if (message->dataLen / CA_SUPPORTED_BLE_MTU_SIZE)
+ uint32_t remainingLen = dataSegmentLength % CA_SUPPORTED_EDR_MTU_SIZE;
+ if (remainingLen && (dataSegmentLength > CA_SUPPORTED_EDR_MTU_SIZE))
{
// send the last segment of the data (Ex: 22 bytes of 622 bytes of data when MTU is 200)
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "Sending the last chunk");
if (CA_STATUS_OK != CAEDRClientSendData(remoteAddress, serviceUUID,
- message->data + (index * CA_SUPPORTED_BLE_MTU_SIZE) - CA_HEADER_LENGTH,
- message->dataLen % CA_SUPPORTED_BLE_MTU_SIZE + CA_HEADER_LENGTH, &sentLength))
+ message->data + (index * CA_SUPPORTED_EDR_MTU_SIZE) - CA_HEADER_LENGTH,
+ remainingLen, &sentLength))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "CAEDRClientSendData API failed");
return;
}
CAResult_t CAEDRClientSendData(const char *remoteAddress, const char *serviceUUID,
- const void *data, uint32_t dataLength, uint32_t *sentLength)
+ const void *data, uint32_t dataLength, uint32_t *sentLength)
{
// Send the first segment with the header.
if ((NULL != remoteAddress) && (0 < strlen(remoteAddress))) //Unicast data
{
- if (CA_STATUS_OK != CAEDRClientSendUnicastData(remoteAddress, serviceUUID,
- data, dataLength, sentLength))
+ if (CA_STATUS_OK != CAEDRClientSendUnicastData(remoteAddress, serviceUUID, data,
+ dataLength, sentLength))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to send unicast data !");
return CA_STATUS_FAILED;
else
{
OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "sending multicast data : %s", data);
- if (CA_STATUS_OK != CAEDRClientSendMulticastData(serviceUUID, data,
- dataLength, sentLength))
+ if (CA_STATUS_OK != CAEDRClientSendMulticastData(serviceUUID, data, dataLength,
+ sentLength))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to send multicast data !");
return CA_STATUS_FAILED;
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN_CAAdapterDataReceiverHandler");
CAEDRData *message = (CAEDRData *) context;
- if (message == NULL)
+ if (NULL == message)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to get message!");
return;
if (!g_isHeaderAvailable)
{
totalDataLen = CAParseHeader((char*)message->data);
- if (totalDataLen == 0)
+ if (0 == totalDataLen)
{
- OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "totalDataLen is zero");
+ OIC_LOG(ERROR, EDR_ADAPTER_TAG, "totalDataLen is zero");
return;
}
- OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "Total data to be accumulated [%d] bytes",
- totalDataLen);
+ OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "Total data to be accumulated [%d] bytes", totalDataLen);
defragData = (char *) OICMalloc(sizeof(char) * totalDataLen);
if (!defragData)
const char *remoteAddress = message->remoteEndpoint->addressInfo.BT.btMacAddress;
const char *serviceUUID = message->remoteEndpoint->resourceUri;
- remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
- serviceUUID);
+ remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress, serviceUUID);
memcpy(defragData + recvDataLen, message->data + CA_HEADER_LENGTH,
message->dataLen - CA_HEADER_LENGTH);
return CA_STATUS_OK;
}
-void CAAdapterRecvData(const char *remoteAddress, const void *data,
- uint32_t dataLength, uint32_t *sentLength)
+void CAAdapterRecvData(const char *remoteAddress, const void *data, uint32_t dataLength,
+ uint32_t *sentLength)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
if (false == g_adapterState)
{
- OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!");
+ OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Bluetooth adapter is disabled!");
*sentLength = 0;
return;
}
- char *serviceUUID = OIC_EDR_SERVICE_ID;
-
// Input validation
- VERIFY_NON_NULL_VOID(serviceUUID, EDR_ADAPTER_TAG, "service UUID is null");
VERIFY_NON_NULL_VOID(data, EDR_ADAPTER_TAG, "Data is null");
VERIFY_NON_NULL_VOID(sentLength, EDR_ADAPTER_TAG, "Sent data length holder is null");
+ static const char serviceUUID[] = OIC_EDR_SERVICE_ID;
// Create remote endpoint
CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
- serviceUUID);
+ serviceUUID);
if (NULL == remoteEndpoint)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !");
// Add message to data queue
CAEDRData *edrData = CACreateEDRData(remoteEndpoint, data, dataLength);
- CAQueueingThreadAddData(g_recvQueueHandle, edrData, sizeof(CARemoteEndpoint_t));
+ CAQueueingThreadAddData(g_recvQueueHandle, edrData, sizeof(CAEDRData));
*sentLength = dataLength;
// Free remote endpoint
CAAdapterFreeRemoteEndpoint(remoteEndpoint);
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
- return;
}
-CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
- const void *data, uint32_t dataLength, uint32_t *sentLength)
+CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID, const void *data,
+ uint32_t dataLength, uint32_t *sentLength)
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN - CAAdapterSendData");
// Create remote endpoint
CARemoteEndpoint_t *remoteEndpoint = CAAdapterCreateRemoteEndpoint(CA_EDR, remoteAddress,
- serviceUUID);
+ serviceUUID);
if (NULL == remoteEndpoint)
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create remote endpoint !");
CAEDRGetInterfaceInformation(&g_localConnectivity);
}
- if(CA_INTERFACE_UP == status)
+ if (CA_INTERFACE_UP == status)
{
- if(false == g_adapterState)
+ if (false == g_adapterState)
{
// Get Bluetooth adapter state
bool adapterState = false;
g_adapterState = true;
CAAdapterStartQueue();
// starting RFCommServer
- if(true == g_serverState)
+ if (true == g_serverState)
{
CAStartServer();
g_serverState = false;
g_adapterState = false;
}
- // Notity to upper layer
+ // Notify to upper layer
if (g_networkChangeCallback && g_localConnectivity && g_edrThreadPool)
{
// Add notification task to thread pool
CAEDRNetworkEvent *event = CAEDRCreateNetworkEvent(g_localConnectivity, status);
if (NULL != event)
{
- if (CA_STATUS_OK != ca_thread_pool_add_task(g_edrThreadPool, CAEDROnNetworkStatusChanged,
- event))
+ if (CA_STATUS_OK != ca_thread_pool_add_task(g_edrThreadPool,
+ CAEDROnNetworkStatusChanged,event))
{
OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create threadpool!");
return;
}
}
- OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
+ OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
void CAEDROnNetworkStatusChanged(void *context)
CAEDRNetworkEvent *networkEvent = (CAEDRNetworkEvent *) context;
- // Notity to upper layer
+ // Notify to upper layer
if (g_networkChangeCallback)
{
g_networkChangeCallback(networkEvent->info, networkEvent->status);
void CAFreeEDRData(CAEDRData *edrData)
{
- if (!edrData)
- return;
+ VERIFY_NON_NULL_VOID(edrData, EDR_ADAPTER_TAG, "edrData is NULL");
CAAdapterFreeRemoteEndpoint(edrData->remoteEndpoint);
OICFree(edrData->data);