static jobject g_leAdvertiseCallback = NULL;
static CAPacketReceiveCallback g_packetReceiveCallback = NULL;
+static CABLEErrorHandleCallback g_serverErrorCallback;
+
static u_arraylist_t *g_connectedDeviceList = NULL;
static ca_thread_pool_t g_threadPoolHandle = NULL;
ret = CALEServerStartAdvertise(env, g_leAdvertiseCallback);
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEServerSendMulticastMessageImpl has failed");
+ OIC_LOG(ERROR, TAG, "CALEServerStartAdvertise has failed");
}
if (isAttached)
CAResult_t ret = CALEServerStopAdvertise(env, g_leAdvertiseCallback);
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEServerSendMulticastMessageImpl has failed");
+ OIC_LOG(ERROR, TAG, "CALEServerStopAdvertise has failed");
}
g_isStartServer = false;
OIC_LOG(DEBUG, TAG, "OUT");
}
+void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback)
+{
+ g_serverErrorCallback = callback;
+}
+
CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *charValue,
const uint32_t charValueLen)
{
+ CAResult_t result = CA_SEND_FAILED;
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL(address, TAG, "env is null");
VERIFY_NON_NULL(charValue, TAG, "device is null");
if (address)
{
OIC_LOG(DEBUG, TAG, "CALEServerSendUnicastData");
- CALEServerSendUnicastMessage(address, charValue, charValueLen);
+ result = CALEServerSendUnicastMessage(address, charValue, charValueLen);
}
OIC_LOG(DEBUG, TAG, "OUT");
- return CA_STATUS_OK;
+ return result;
}
CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
VERIFY_NON_NULL(charValue, TAG, "device is null");
OIC_LOG(DEBUG, TAG, "CALEServerSendMulticastMessage");
- CALEServerSendMulticastMessage(charValue, charValueLen);
+ CAResult_t result = CALEServerSendMulticastMessage(charValue, charValueLen);
OIC_LOG(DEBUG, TAG, "OUT");
- return CA_STATUS_OK;
+ return result;
}
void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle)
static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
/**
+ * @var g_errorHandler
+ * @brief Callback to notify error from the BLE adapter
+ */
+static CAErrorHandleCallback g_errorHandler = NULL;
+
+/**
+ * @var g_bleAdapterState
+ * @brief Storing Adapter state information
+ */
+static CAAdapterState_t g_bleAdapterState = CA_ADAPTER_DISABLED;
+
+/**
* @ENUM CALeServerStatus
* @brief status of BLE Server Status
* This ENUM provides information of LE Adapter Server status
*/
static void CALEDataDestroyer(void *data, uint32_t size);
+/**
+* @fn CALEErrorHandler
+* @brief prepares and notify error through error callback
+*
+* @return void
+*/
+static void CALEErrorHandler(const char *remoteAddress, const void *data, uint32_t dataLen,
+ CAResult_t result);
+
+
CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback reqRespCallback,
CANetworkChangeCallback netCallback,
- ca_thread_pool_t handle)
+ CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
CASetBLEReqRespClientCallback(CABLEClientReceivedData);
CASetBLEReqRespAdapterCallback(reqRespCallback);
+ CASetBLEClientErrorHandleCallback(CALEErrorHandler);
+ CASetBLEServerErrorHandleCallback(CALEErrorHandler);
CALERegisterNetworkNotifications(netCallback);
+ g_errorHandler = errorCallback;
+
CAConnectivityHandler_t connHandler;
connHandler.startAdapter = CAStartLE;
connHandler.stopAdapter = CAStopLE;
CAResult_t CAStartLE()
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
- OIC_LOG(DEBUG, CALEADAPTER_TAG,
- "There is no concept of unicast/multicast in LE. So This function is not implemented");
+ OIC_LOG(DEBUG, CALEADAPTER_TAG, "CAStartLE, not implemented");
OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
return CA_STATUS_OK;
}
{
OIC_LOG(ERROR, CALEADAPTER_TAG,
"[SendLEUnicastData] CABleServerSenderQueueEnqueueMessage failed \n");
+ g_errorHandler((void *) endpoint, (void *) data, dataLen, result);
ca_mutex_unlock(g_bleIsServerMutex);
return -1;
}
{
OIC_LOG(ERROR, CALEADAPTER_TAG,
"[SendLEUnicastData] CABleClientSenderQueueEnqueueMessage failed \n");
+ g_errorHandler(endpoint, data, dataLen, result);
ca_mutex_unlock(g_bleIsServerMutex);
return -1;
}
ca_mutex_lock(g_bleIsServerMutex);
if (true == g_isServer)
{
- result = CABLEServerSendData(NULL, data, dataLen);
+ result = CABLEServerSendData(endpoint, data, dataLen);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG,
"[SendLEMulticastDataToAll] CABleServerSenderQueueEnqueueMessage failed" );
ca_mutex_unlock(g_bleIsServerMutex);
+ g_errorHandler(endpoint, data, dataLen, result);
return -1;
}
}
else
{
- result = CABLEClientSendData(NULL, data, dataLen);
+ result = CABLEClientSendData(endpoint, data, dataLen);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, CALEADAPTER_TAG,
"[SendLEMulticastDataToAll] CABleClientSenderQueueEnqueueMessage failed" );
+ g_errorHandler(endpoint, data, dataLen, result);
ca_mutex_unlock(g_bleIsServerMutex);
return -1;
}
OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), g_localBLEAddress);
ca_mutex_unlock(g_bleLocalAddressMutex);
+ g_bleAdapterState = adapter_state;
// Start a GattServer/Client if gLeServerStatus is SET
if (CA_LISTENING_SERVER == gLeServerStatus)
{
if (CA_STATUS_OK != result)
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG,
"Update characteristics failed, result [%d]", result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
result = CAUpdateCharacteristicsToAllGattClients(dataSegment, length);
if (CA_STATUS_OK != result)
{
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
+ OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
+ result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
CA_SUPPORTED_BLE_MTU_SIZE);
if (CA_STATUS_OK != result)
{
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
+ OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
+ result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
if (CA_STATUS_OK != result)
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
- result);
+ result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
if (CA_STATUS_OK != result)
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]", result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return ;
}
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
{
OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
result = CAUpdateCharacteristicsToAllGattServers(dataSegment, length);
if (CA_STATUS_OK != result)
{
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed (all), result [%d]", result);
+ OIC_LOG_V(ERROR, CALEADAPTER_TAG,
+ "Update characteristics (all) failed, result [%d]", result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return ;
}
CA_SUPPORTED_BLE_MTU_SIZE);
if (CA_STATUS_OK != result)
{
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics (all) failed, result [%d]", result);
+ OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics (all) failed, result [%d]",
+ result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
- OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length is [%d]", CA_SUPPORTED_BLE_MTU_SIZE);
+ OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length is [%d]",
+ CA_SUPPORTED_BLE_MTU_SIZE);
}
uint32_t remainingLen = totalLength % CA_SUPPORTED_BLE_MTU_SIZE;
remainingLen);
if (CA_STATUS_OK != result)
{
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics (all) failed, result [%d]", result);
+ OIC_LOG_V(ERROR, CALEADAPTER_TAG,
+ "Update characteristics (all) failed, result [%d]", result);
+ g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
OICFree(dataSegment);
return;
}
OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
}
+void CALEErrorHandler(const char *remoteAddress, const void *data, uint32_t dataLen,
+ CAResult_t result)
+{
+ OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler IN");
+
+ VERIFY_NON_NULL_VOID(data, CALEADAPTER_TAG, "Data is null");
+ CAEndpoint_t *rep = OICCalloc(1, sizeof(CAEndpoint_t));
+
+ if (!rep)
+ {
+ OIC_LOG(ERROR, CALEADAPTER_TAG, "Failed to create remote endpoint !");
+ return;
+ }
+
+ if (remoteAddress)
+ {
+ OICStrcpy(rep->addr, sizeof(rep->addr), remoteAddress);
+ }
+
+ rep->adapter = CA_ADAPTER_GATT_BTLE;
+ rep->flags = CA_DEFAULT_FLAGS;
+
+ //if required, will be used to build remote end point
+ g_errorHandler(rep, data, dataLen, result);
+ CAAdapterFreeEndpoint(rep);
+
+ OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler OUT");
+}