#include <jni.h>
#include <unistd.h>
+#include "calestate.h"
#include "caleclient.h"
#include "caleserver.h"
#include "caleutils.h"
g_uuidList = NULL;
}
- ret = CALEClientRemoveAllDeviceState();
+ ret = CALERemoveAllDeviceState(g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != ret)
{
- OIC_LOG(ERROR, TAG, "CALEClientRemoveAllDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALERemoveAllDeviceState has failed");
}
ret = CALEClientRemoveAllScanDevices(env);
oc_mutex_unlock(g_threadSendMutex);
OIC_LOG(INFO, TAG, "unicast - send logic has finished");
- if (CALEClientIsValidState(address, CA_LE_SEND_STATE,
- STATE_SEND_SUCCESS))
+ if (CALEIsValidState(address, CA_LE_SEND_STATE,
+ STATE_SEND_SUCCESS,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "send success");
ret = CA_STATUS_OK;
}
- else if (CALEClientIsValidState(address, CA_LE_SEND_STATE,
- STATE_SEND_MTU_NEGO_SUCCESS))
+ else if (CALEIsValidState(address, CA_LE_SEND_STATE,
+ STATE_SEND_MTU_NEGO_SUCCESS,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "mtu nego success");
ret = CA_STATUS_OK;
}
// reset send state
- CAResult_t resetRet = CALEClientUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_NONE);
+ CAResult_t resetRet = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_NONE,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != resetRet)
{
- OIC_LOG_V(ERROR, TAG, "CALEClientUpdateDeviceState has failed (%d)", resetRet);
+ OIC_LOG_V(ERROR, TAG, "CALEUpdateDeviceState has failed (%d)", resetRet);
ret = CA_SEND_FAILED;
}
return CA_STATUS_FAILED;
}
oc_mutex_lock(g_deviceStateListMutex);
- state = CALEClientGetStateInfo(address);
+ state = CALEGetStateInfo(address, g_deviceStateList);
oc_mutex_unlock(g_deviceStateListMutex);
}
}
else
{
- if (CALEClientIsValidState(address, CA_LE_CONNECTION_STATE,
- STATE_SERVICE_CONNECTED))
+ if (CALEIsValidState(address, CA_LE_CONNECTION_STATE,
+ STATE_SERVICE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "GATT has already connected");
}
(*env)->ReleaseStringUTFChars(env, jni_address, address);
}
- else if(CALEClientIsValidState(address, CA_LE_CONNECTION_STATE,
- STATE_CONNECTED))
+ else if(CALEIsValidState(address, CA_LE_CONNECTION_STATE,
+ STATE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "service connecting...");
}
- else if(CALEClientIsValidState(address, CA_LE_CONNECTION_STATE,
- STATE_DISCONNECTED))
+ else if(CALEIsValidState(address, CA_LE_CONNECTION_STATE,
+ STATE_DISCONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "STATE_DISCONNECTED - start to connect LE");
OIC_LOG(DEBUG, TAG, "start to connect LE");
jobject gatt = CALEClientConnect(env, device,
- CALEClientGetFlagFromState(env, jni_address,
- CA_LE_AUTO_CONNECT_FLAG));
+ CALEGetFlagFromState(env, jni_address,
+ CA_LE_AUTO_CONNECT_FLAG,
+ g_deviceStateList,
+ g_deviceStateListMutex));
if (NULL == gatt)
{
return CA_STATUS_OK;
}
-CAResult_t CALEClientSetFlagToState(JNIEnv *env, jstring jni_address, jint state_idx, jboolean flag)
-{
- OIC_LOG(DEBUG, TAG, "IN - CALEClientSetFlagToState");
- VERIFY_NON_NULL(env, TAG, "env");
- VERIFY_NON_NULL(jni_address, TAG, "jni_address");
-
- oc_mutex_lock(g_deviceStateListMutex);
-
- char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- OIC_LOG(ERROR, TAG, "address is not available");
- CACheckJNIException(env);
- return CA_STATUS_FAILED;
- }
-
- if (CALEClientIsDeviceInList(address))
- {
- CALEState_t* curState = CALEClientGetStateInfo(address);
- if(!curState)
- {
- OIC_LOG(ERROR, TAG, "curState is null");
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_FAILED;
- }
- OIC_LOG_V(INFO, TAG, "%d flag is set : %d", state_idx, flag);
-
- switch(state_idx)
- {
- case CA_LE_AUTO_CONNECT_FLAG:
- curState->autoConnectFlag = flag;
- break;
- case CA_LE_DESCRIPTOR_FOUND:
- curState->isDescriptorFound = flag;
- break;
- default:
- break;
- }
- }
-
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- oc_mutex_unlock(g_deviceStateListMutex);
- OIC_LOG(DEBUG, TAG, "OUT - CALEClientSetFlagToState");
- return CA_STATUS_OK;
-}
-
-jboolean CALEClientGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx)
-{
- OIC_LOG(DEBUG, TAG, "IN - CALEClientGetFlagFromState");
- VERIFY_NON_NULL_RET(env, TAG, "env", false);
- VERIFY_NON_NULL_RET(jni_address, TAG, "jni_address", false);
-
- oc_mutex_lock(g_deviceStateListMutex);
-
- char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
- if (!address)
- {
- OIC_LOG(ERROR, TAG, "address is not available");
- CACheckJNIException(env);
- oc_mutex_unlock(g_deviceStateListMutex);
- return JNI_FALSE;
- }
-
- CALEState_t* curState = CALEClientGetStateInfo(address);
- (*env)->ReleaseStringUTFChars(env, jni_address, address);
- if(!curState)
- {
- OIC_LOG(INFO, TAG, "there is no information. auto connect flag is false");
- oc_mutex_unlock(g_deviceStateListMutex);
- return JNI_FALSE;
- }
-
- jboolean ret = JNI_FALSE;
- switch(state_idx)
- {
- case CA_LE_AUTO_CONNECT_FLAG:
- ret = curState->autoConnectFlag;
- break;
- case CA_LE_DESCRIPTOR_FOUND:
- ret = curState->isDescriptorFound;
- break;
- default:
- break;
- }
- oc_mutex_unlock(g_deviceStateListMutex);
-
- OIC_LOG_V(INFO, TAG, "%d flag is %d", state_idx, ret);
- OIC_LOG(DEBUG, TAG, "OUT - CALEClientGetFlagFromState");
- return ret;
-}
-
CAResult_t CALEClientDirectConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect)
{
OIC_LOG(DEBUG, TAG, "CALEClientDirectConnect");
}
CAResult_t res = CA_STATUS_OK;
- if(CALEClientIsValidState(address, CA_LE_CONNECTION_STATE,
- STATE_DISCONNECTED))
+ if(CALEIsValidState(address, CA_LE_CONNECTION_STATE,
+ STATE_DISCONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
jobject newGatt = CALEClientConnect(env, bluetoothDevice, autoconnect);
if (NULL == newGatt)
bool CALEClientIsConnected(const char* address)
{
- if (CALEClientIsValidState(address, CA_LE_CONNECTION_STATE,
- STATE_SERVICE_CONNECTED))
+ if (CALEIsValidState(address, CA_LE_CONNECTION_STATE,
+ STATE_SERVICE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(DEBUG, TAG, "current state is connected");
return true;
oc_mutex_lock(g_threadSendStateMutex);
- if (CALEClientIsValidState(address, CA_LE_SEND_STATE, STATE_SENDING))
+ if (CALEIsValidState(address, CA_LE_SEND_STATE, STATE_SENDING,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "current state is SENDING");
(*env)->ReleaseStringUTFChars(env, jni_address, address);
return CA_STATUS_OK;
}
- if (CA_STATUS_OK != CALEClientUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SENDING))
+ if (CA_STATUS_OK != CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SENDING,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
(*env)->ReleaseStringUTFChars(env, jni_address, address);
CALEClientSendFinish(env, gatt);
oc_mutex_unlock(g_threadSendStateMutex);
return CA_STATUS_FAILED;
}
- if (CALEClientIsValidState(address, state_type, target_state))
+ if (CALEIsValidState(address, state_type, target_state,
+ g_deviceStateList,
+ g_deviceStateListMutex))
{
(*env)->DeleteLocalRef(env, jni_Address);
return CA_STATUS_OK;
}
- CAResult_t res = CALEClientUpdateDeviceState(address, state_type,
- target_state);
+ CAResult_t res = CALEUpdateDeviceState(address, state_type,
+ target_state,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
}
(*env)->ReleaseStringUTFChars(env, jni_Address, address);
(*env)->DeleteLocalRef(env, jni_Address);
return res;
}
-CAResult_t CALEClientSetMtuSize(const char* address, uint16_t mtuSize)
+CAResult_t CALEClientSetFlagToState(JNIEnv *env, jstring jni_address,
+ jint state_idx, jboolean flag)
{
- VERIFY_NON_NULL(address, TAG, "address is null");
-
- oc_mutex_lock(g_deviceStateListMutex);
- if (CALEClientIsDeviceInList(address))
- {
- CALEState_t* curState = CALEClientGetStateInfo(address);
- if(!curState)
- {
- OIC_LOG(ERROR, TAG, "curState is null");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_FAILED;
- }
-
- curState->mtuSize = mtuSize;
- OIC_LOG_V(INFO, TAG, "update state - addr: %s, mtu: %d",
- curState->address, curState->mtuSize);
- }
- else
- {
- OIC_LOG(ERROR, TAG, "there is no state info in the list");
- }
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_OK;
+ return CALESetFlagToState(env, jni_address, state_idx, flag,
+ g_deviceStateList, g_deviceStateListMutex);
}
-uint16_t CALEClientGetMtuSize(const char* address)
-{
- VERIFY_NON_NULL_RET(address, TAG, "address is null", CA_DEFAULT_BLE_MTU_SIZE);
-
- oc_mutex_lock(g_deviceStateListMutex);
- if (CALEClientIsDeviceInList(address))
- {
- CALEState_t* curState = CALEClientGetStateInfo(address);
- if(!curState)
- {
- OIC_LOG(ERROR, TAG, "curState is null");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_DEFAULT_BLE_MTU_SIZE;
- }
-
- OIC_LOG_V(INFO, TAG, "state - addr: %s, mtu: %d",
- curState->address, curState->mtuSize);
- oc_mutex_unlock(g_deviceStateListMutex);
- return curState->mtuSize;
- }
-
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_DEFAULT_BLE_MTU_SIZE;
-}
-
-CAResult_t CALEClientUpdateDeviceState(const char* address, uint16_t state_type,
- uint16_t target_state)
-{
- VERIFY_NON_NULL(address, TAG, "address is null");
-
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "gdevice_list is null");
- return CA_STATUS_FAILED;
- }
-
- oc_mutex_lock(g_deviceStateListMutex);
-
- if (CALEClientIsDeviceInList(address))
- {
- CALEState_t* curState = CALEClientGetStateInfo(address);
- if(!curState)
- {
- OIC_LOG(ERROR, TAG, "curState is null");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_FAILED;
- }
-
- switch(state_type)
- {
- case CA_LE_CONNECTION_STATE:
- curState->connectedState = target_state;
- break;
- case CA_LE_SEND_STATE:
- curState->sendState = target_state;
- break;
- default:
- break;
- }
- OIC_LOG_V(INFO, TAG, "update state - addr: %s, conn: %d, send: %d, ACFlag: %d, mtu: %d",
- curState->address, curState->connectedState, curState->sendState,
- curState->autoConnectFlag, curState->mtuSize);
- }
- else /** state is added newly **/
- {
- if (strlen(address) > CA_MACADDR_SIZE)
- {
- OIC_LOG(ERROR, TAG, "address is not proper");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_INVALID_PARAM;
- }
-
- CALEState_t *newstate = (CALEState_t*) OICCalloc(1, sizeof(*newstate));
- if (!newstate)
- {
- OIC_LOG(ERROR, TAG, "out of memory");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_MEMORY_ALLOC_FAILED;
- }
-
- OICStrcpy(newstate->address, sizeof(newstate->address), address);
- newstate->mtuSize = CA_DEFAULT_BLE_MTU_SIZE;
- switch(state_type)
- {
- case CA_LE_CONNECTION_STATE:
- newstate->connectedState = target_state;
- newstate->sendState = STATE_SEND_NONE;
- break;
- case CA_LE_SEND_STATE:
- newstate->connectedState = STATE_DISCONNECTED;
- newstate->sendState = target_state;
- break;
- default:
- break;
- }
- OIC_LOG_V(INFO, TAG, "add a new state to List - addr : %s, "
- "conn : %d, send : %d, ACFlag : %d",
- newstate->address, newstate->connectedState, newstate->sendState,
- newstate->autoConnectFlag);
- u_arraylist_add(g_deviceStateList, newstate); // update new state
- }
- oc_mutex_unlock(g_deviceStateListMutex);
-
- return CA_STATUS_OK;
-}
-
-bool CALEClientIsDeviceInList(const char* remoteAddress)
-{
- VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress is null", false);
-
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
- return false;
- }
-
- uint32_t length = u_arraylist_length(g_deviceStateList);
- for (uint32_t index = 0; index < length; index++)
- {
- CALEState_t* state = (CALEState_t*) u_arraylist_get(g_deviceStateList, index);
- if (!state)
- {
- OIC_LOG(ERROR, TAG, "CALEState_t object is null");
- return false;
- }
-
- if (!strcmp(remoteAddress, state->address))
- {
- OIC_LOG(DEBUG, TAG, "the device is already set");
- return true;
- }
- else
- {
- continue;
- }
- }
-
- OIC_LOG(DEBUG, TAG, "there are no the device in list.");
- return false;
-}
-
-CAResult_t CALEClientRemoveAllDeviceState()
-{
- OIC_LOG(DEBUG, TAG, "CALEClientRemoveAllDeviceState");
-
- oc_mutex_lock(g_deviceStateListMutex);
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_FAILED;
- }
-
- uint32_t length = u_arraylist_length(g_deviceStateList);
- for (uint32_t index = 0; index < length; index++)
- {
- CALEState_t* state = (CALEState_t*) u_arraylist_get(g_deviceStateList, index);
- if (!state)
- {
- OIC_LOG(ERROR, TAG, "jarrayObj is null");
- continue;
- }
- OICFree(state);
- }
-
- OICFree(g_deviceStateList);
- g_deviceStateList = NULL;
- oc_mutex_unlock(g_deviceStateListMutex);
-
- return CA_STATUS_OK;
-}
-
-CAResult_t CALEClientResetDeviceStateForAll()
-{
- OIC_LOG(DEBUG, TAG, "CALEClientResetDeviceStateForAll");
-
- oc_mutex_lock(g_deviceStateListMutex);
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
- oc_mutex_unlock(g_deviceStateListMutex);
- return CA_STATUS_FAILED;
- }
-
- size_t length = u_arraylist_length(g_deviceStateList);
- for (size_t index = 0; index < length; index++)
- {
- CALEState_t* state = (CALEState_t*) u_arraylist_get(g_deviceStateList, index);
- if (!state)
- {
- OIC_LOG(ERROR, TAG, "jarrayObj is null");
- continue;
- }
-
- // autoConnectFlag value will be not changed,
- // since it has reset only termination case.
- state->connectedState = STATE_DISCONNECTED;
- state->sendState = STATE_SEND_NONE;
- }
- oc_mutex_unlock(g_deviceStateListMutex);
-
- return CA_STATUS_OK;
-}
-
-CAResult_t CALEClientRemoveDeviceState(const char* remoteAddress)
-{
- OIC_LOG(DEBUG, TAG, "CALEClientRemoveDeviceState");
- VERIFY_NON_NULL(remoteAddress, TAG, "remoteAddress is null");
-
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
- return CA_STATUS_FAILED;
- }
-
- uint32_t length = u_arraylist_length(g_deviceStateList);
- for (uint32_t index = 0; index < length; index++)
- {
- CALEState_t* state = (CALEState_t*) u_arraylist_get(g_deviceStateList, index);
- if (!state)
- {
- OIC_LOG(ERROR, TAG, "CALEState_t object is null");
- continue;
- }
-
- if (!strcmp(state->address, remoteAddress))
- {
- OIC_LOG_V(DEBUG, TAG, "remove state : %s", state->address);
-
- CALEState_t* targetState = (CALEState_t*)u_arraylist_remove(g_deviceStateList,
- index);
- if (NULL == targetState)
- {
- OIC_LOG(ERROR, TAG, "List removal failed.");
- return CA_STATUS_FAILED;
- }
-
- OICFree(targetState);
- return CA_STATUS_OK;
- }
- }
-
- return CA_STATUS_OK;
-}
-
-CALEState_t* CALEClientGetStateInfo(const char* remoteAddress)
+jboolean CALEClientGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx)
{
- VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress is null", NULL);
-
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
- return NULL;
- }
-
- uint32_t length = u_arraylist_length(g_deviceStateList);
- OIC_LOG_V(DEBUG, TAG, "length of deviceStateList : %d", length);
- OIC_LOG_V(DEBUG, TAG, "target address : %s", remoteAddress);
-
- for (uint32_t index = 0; index < length; index++)
- {
- CALEState_t* state = (CALEState_t*) u_arraylist_get(g_deviceStateList, index);
- if (!state)
- {
- OIC_LOG(ERROR, TAG, "CALEState_t object is null");
- continue;
- }
-
- OIC_LOG_V(DEBUG, TAG, "state address : %s (idx: %d)", state->address, index);
-
- if (!strcmp(state->address, remoteAddress))
- {
- OIC_LOG(DEBUG, TAG, "found state");
- return state;
- }
- }
-
- OIC_LOG_V(DEBUG, TAG, "[%s] doesn't exist in deviceStateList", remoteAddress);
- return NULL;
+ return CALEGetFlagFromState(env, jni_address, state_idx, g_deviceStateList,
+ g_deviceStateListMutex);
}
-bool CALEClientIsValidState(const char* remoteAddress, uint16_t state_type,
- uint16_t target_state)
+uint16_t CALEClientGetMtuSize(const char* address)
{
- OIC_LOG_V(DEBUG, TAG, "CALEClientIsValidState : type[%d], target state[%d]",
- state_type, target_state);
- VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress is null", false);
-
- oc_mutex_lock(g_deviceStateListMutex);
- if (!g_deviceStateList)
- {
- OIC_LOG(ERROR, TAG, "g_deviceStateList is null");
- oc_mutex_unlock(g_deviceStateListMutex);
- return false;
- }
-
- CALEState_t* state = CALEClientGetStateInfo(remoteAddress);
- if (NULL == state)
- {
- OIC_LOG(DEBUG, TAG, "state is not updated yet");
- oc_mutex_unlock(g_deviceStateListMutex);
- return false;
- }
-
- uint16_t curValue = 0;
- switch(state_type)
- {
- case CA_LE_CONNECTION_STATE:
- curValue = state->connectedState;
- break;
- case CA_LE_SEND_STATE:
- curValue = state->sendState;
- break;
- default:
- break;
- }
- oc_mutex_unlock(g_deviceStateListMutex);
-
- if (target_state == curValue)
- {
- return true;
- }
- else
- {
- return false;
- }
+ return CALEGetMtuSize(address, g_deviceStateList, g_deviceStateListMutex);
}
void CALEClientCreateDeviceList()
}
}
+CAResult_t CALEClientResetDeviceStateForAll()
+{
+ return CALEResetDeviceStateForAll(g_deviceStateList, g_deviceStateListMutex);
+}
+
/**
* Check Sent Count for remove g_sendBuffer
*/
OIC_LOG(DEBUG, TAG, "LE is connected");
if (GATT_SUCCESS == status)
{
- CAResult_t res = CALEClientUpdateDeviceState(address,
- CA_LE_CONNECTION_STATE,
- STATE_CONNECTED);
+ CAResult_t res = CALEUpdateDeviceState(address,
+ CA_LE_CONNECTION_STATE,
+ STATE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
(*env)->ReleaseStringUTFChars(env, jni_address, address);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
goto error_exit;
}
{
OIC_LOG(DEBUG, TAG, "LE is disconnected");
- if (CALEClientIsValidState(address, CA_LE_SEND_STATE, STATE_SEND_PREPARING))
+ if (CALEIsValidState(address, CA_LE_SEND_STATE, STATE_SEND_PREPARING,
+ g_deviceStateList, g_deviceStateListMutex))
{
OIC_LOG(INFO, TAG, "current state is STATE_SEND_PREPARING");
- CAResult_t res = CALEClientUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_FAIL);
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_FAIL,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
}
}
- CAResult_t res = CALEClientUpdateDeviceState(address,
- CA_LE_CONNECTION_STATE,
- STATE_DISCONNECTED);
+ CAResult_t res = CALEUpdateDeviceState(address,
+ CA_LE_CONNECTION_STATE,
+ STATE_DISCONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
(*env)->ReleaseStringUTFChars(env, jni_address, address);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
goto error_exit;
}
{
OIC_LOG_V(INFO, TAG, "Descriptor is not found : %d", res);
- res = CALEClientSetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_FALSE);
+ res = CALESetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_FALSE,
+ g_deviceStateList, g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientSetFlagToState has failed");
+ OIC_LOG(ERROR, TAG, "CALESetFlagToState has failed");
goto error_exit;
}
- res = CALEClientUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
- STATE_SERVICE_CONNECTED);
+ res = CALEUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
+ STATE_SERVICE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
goto error_exit;
}
}
else
{
- res = CALEClientSetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_TRUE);
+ res = CALESetFlagToState(env, jni_address, CA_LE_DESCRIPTOR_FOUND, JNI_TRUE,
+ g_deviceStateList, g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientSetFlagToState has failed");
+ OIC_LOG(ERROR, TAG, "CALESetFlagToState has failed");
goto error_exit;
}
}
oc_cond_signal(g_threadWriteCharacteristicCond);
oc_mutex_unlock(g_threadWriteCharacteristicMutex);
- CAResult_t res = CALEClientUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_FAIL);
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_FAIL,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
}
if (g_clientErrorCallback)
else
{
OIC_LOG(DEBUG, TAG, "send success");
- CAResult_t res = CALEClientUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_SUCCESS);
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_SUCCESS,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
}
oc_mutex_lock(g_threadWriteCharacteristicMutex);
goto error_exit;
}
- CAResult_t res = CALEClientUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
- STATE_SERVICE_CONNECTED);
+ CAResult_t res = CALEUpdateDeviceState(address, CA_LE_CONNECTION_STATE,
+ STATE_SERVICE_CONNECTED,
+ g_deviceStateList,
+ g_deviceStateListMutex);
(*env)->ReleaseStringUTFChars(env, jni_address, address);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
goto error_exit;
}
}
// update mtu size
- CAResult_t res = CALEClientSetMtuSize(address, mtu - CA_BLE_MTU_HEADER_SIZE);
+ CAResult_t res = CALESetMtuSize(address, mtu - CA_BLE_MTU_HEADER_SIZE,
+ g_deviceStateList, g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientSetMtuSize has failed");
+ OIC_LOG(ERROR, TAG, "CALESetMtuSize has failed");
}
- res = CALEClientUpdateDeviceState(address, CA_LE_SEND_STATE,
- STATE_SEND_MTU_NEGO_SUCCESS);
+ res = CALEUpdateDeviceState(address, CA_LE_SEND_STATE,
+ STATE_SEND_MTU_NEGO_SUCCESS,
+ g_deviceStateList,
+ g_deviceStateListMutex);
if (CA_STATUS_OK != res)
{
- OIC_LOG(ERROR, TAG, "CALEClientUpdateDeviceState has failed");
+ OIC_LOG(ERROR, TAG, "CALEUpdateDeviceState has failed");
}
CALEClientUpdateSendCnt(env);
(*env)->ReleaseStringUTFChars(env, jni_address, address);
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <jni.h>
+#include <unistd.h>
+
+#include "calestate.h"
+#include "caleinterface.h"
+#include "caadapterutils.h"
+#include "caleutils.h"
+
+#include "logger.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "cathreadpool.h" /* for thread pool */
+#include "octhread.h"
+#include "uarraylist.h"
+
+#define TAG PCF("OIC_CA_LE_STATE")
+
+CAResult_t CALEUpdateDeviceState(const char* address,
+ uint16_t state_type,
+ uint16_t target_state,
+ u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex)
+{
+ VERIFY_NON_NULL(address, TAG, "address is null");
+ VERIFY_NON_NULL(deviceList, TAG, "deviceList is null");
+
+ oc_mutex_lock(deviceListMutex);
+
+ if (CALEIsDeviceInList(address, deviceList))
+ {
+ CALEState_t* curState = CALEGetStateInfo(address, deviceList);
+ if(!curState)
+ {
+ OIC_LOG(ERROR, TAG, "curState is null");
+ oc_mutex_unlock(deviceListMutex);
+ return CA_STATUS_FAILED;
+ }
+
+ switch(state_type)
+ {
+ case CA_LE_CONNECTION_STATE:
+ curState->connectedState = target_state;
+ break;
+ case CA_LE_SEND_STATE:
+ curState->sendState = target_state;
+ break;
+ default:
+ break;
+ }
+ OIC_LOG_V(INFO, TAG, "update state - addr: %s, conn: %d, send: %d, ACFlag: %d, mtu: %d",
+ curState->address, curState->connectedState, curState->sendState,
+ curState->autoConnectFlag, curState->mtuSize);
+ }
+ else /** state is added newly **/
+ {
+ if (strlen(address) > CA_MACADDR_SIZE)
+ {
+ OIC_LOG(ERROR, TAG, "address is not proper");
+ oc_mutex_unlock(deviceListMutex);
+ return CA_STATUS_INVALID_PARAM;
+ }
+
+ CALEState_t *newstate = (CALEState_t*) OICCalloc(1, sizeof(*newstate));
+ if (!newstate)
+ {
+ OIC_LOG(ERROR, TAG, "out of memory");
+ oc_mutex_unlock(deviceListMutex);
+ return CA_MEMORY_ALLOC_FAILED;
+ }
+
+ OICStrcpy(newstate->address, sizeof(newstate->address), address);
+ newstate->mtuSize = CA_DEFAULT_BLE_MTU_SIZE;
+ switch(state_type)
+ {
+ case CA_LE_CONNECTION_STATE:
+ newstate->connectedState = target_state;
+ newstate->sendState = STATE_SEND_NONE;
+ break;
+ case CA_LE_SEND_STATE:
+ newstate->connectedState = STATE_DISCONNECTED;
+ newstate->sendState = target_state;
+ break;
+ default:
+ break;
+ }
+ OIC_LOG_V(INFO, TAG, "add a new state to List - addr : %s, "
+ "conn : %d, send : %d, ACFlag : %d",
+ newstate->address, newstate->connectedState, newstate->sendState,
+ newstate->autoConnectFlag);
+ u_arraylist_add(deviceList, newstate); // update new state
+ }
+ oc_mutex_unlock(deviceListMutex);
+
+ return CA_STATUS_OK;
+}
+
+bool CALEIsDeviceInList(const char* remoteAddress,
+ u_arraylist_t *deviceList)
+{
+ VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress is null", false);
+ VERIFY_NON_NULL_RET(deviceList, TAG, "deviceList is null", false);
+
+ uint32_t length = u_arraylist_length(deviceList);
+ for (uint32_t index = 0; index < length; index++)
+ {
+ CALEState_t* state = (CALEState_t*) u_arraylist_get(deviceList, index);
+ if (!state)
+ {
+ OIC_LOG(ERROR, TAG, "CALEState_t object is null");
+ return false;
+ }
+
+ if (!strcmp(remoteAddress, state->address))
+ {
+ OIC_LOG(DEBUG, TAG, "the device is already set");
+ return true;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ OIC_LOG(DEBUG, TAG, "there are no the device in list.");
+ return false;
+}
+
+CAResult_t CALERemoveAllDeviceState(u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex)
+{
+ OIC_LOG(DEBUG, TAG, "CALERemoveAllDeviceState");
+ VERIFY_NON_NULL(deviceList, TAG, "deviceList is null");
+
+ oc_mutex_lock(deviceListMutex);
+ uint32_t length = u_arraylist_length(deviceList);
+ for (uint32_t index = 0; index < length; index++)
+ {
+ CALEState_t* state = (CALEState_t*) u_arraylist_get(deviceList, index);
+ if (!state)
+ {
+ OIC_LOG(ERROR, TAG, "jarrayObj is null");
+ continue;
+ }
+ OICFree(state);
+ }
+
+ OICFree(deviceList);
+ deviceList = NULL;
+ oc_mutex_unlock(deviceListMutex);
+
+ return CA_STATUS_OK;
+}
+
+CAResult_t CALEResetDeviceStateForAll(u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex)
+{
+ OIC_LOG(DEBUG, TAG, "CALEClientResetDeviceStateForAll");
+ VERIFY_NON_NULL(deviceList, TAG, "deviceList is null");
+
+ oc_mutex_lock(deviceListMutex);
+ size_t length = u_arraylist_length(deviceList);
+ for (size_t index = 0; index < length; index++)
+ {
+ CALEState_t* state = (CALEState_t*) u_arraylist_get(deviceList, index);
+ if (!state)
+ {
+ OIC_LOG(ERROR, TAG, "jarrayObj is null");
+ continue;
+ }
+
+ // autoConnectFlag value will be not changed,
+ // since it has reset only termination case.
+ state->connectedState = STATE_DISCONNECTED;
+ state->sendState = STATE_SEND_NONE;
+ }
+ oc_mutex_unlock(deviceListMutex);
+
+ return CA_STATUS_OK;
+}
+
+CAResult_t CALERemoveDeviceState(const char* remoteAddress,
+ u_arraylist_t *deviceList)
+{
+ OIC_LOG(DEBUG, TAG, "CALERemoveDeviceState");
+ VERIFY_NON_NULL(remoteAddress, TAG, "remoteAddress is null");
+ VERIFY_NON_NULL(deviceList, TAG, "deviceList is null");
+
+ uint32_t length = u_arraylist_length(deviceList);
+ for (uint32_t index = 0; index < length; index++)
+ {
+ CALEState_t* state = (CALEState_t*) u_arraylist_get(deviceList, index);
+ if (!state)
+ {
+ OIC_LOG(ERROR, TAG, "CALEState_t object is null");
+ continue;
+ }
+
+ if (!strcmp(state->address, remoteAddress))
+ {
+ OIC_LOG_V(DEBUG, TAG, "remove state : %s", state->address);
+
+ CALEState_t* targetState = (CALEState_t*)u_arraylist_remove(deviceList,
+ index);
+ if (NULL == targetState)
+ {
+ OIC_LOG(ERROR, TAG, "List removal failed.");
+ return CA_STATUS_FAILED;
+ }
+
+ OICFree(targetState);
+ return CA_STATUS_OK;
+ }
+ }
+ return CA_STATUS_OK;
+}
+
+CALEState_t* CALEGetStateInfo(const char* remoteAddress,
+ u_arraylist_t *deviceList)
+{
+ VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress is null", NULL);
+ VERIFY_NON_NULL_RET(deviceList, TAG, "deviceList is null", NULL);
+
+ uint32_t length = u_arraylist_length(deviceList);
+ OIC_LOG_V(DEBUG, TAG, "length of deviceStateList : %d", length);
+ OIC_LOG_V(DEBUG, TAG, "target address : %s", remoteAddress);
+
+ for (uint32_t index = 0; index < length; index++)
+ {
+ CALEState_t* state = (CALEState_t*) u_arraylist_get(deviceList, index);
+ if (!state)
+ {
+ OIC_LOG(ERROR, TAG, "CALEState_t object is null");
+ continue;
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "state address : %s (idx: %d)", state->address, index);
+
+ if (!strcmp(state->address, remoteAddress))
+ {
+ OIC_LOG(DEBUG, TAG, "found state");
+ return state;
+ }
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "[%s] doesn't exist in deviceStateList", remoteAddress);
+ return NULL;
+}
+
+bool CALEIsValidState(const char* remoteAddress,
+ uint16_t state_type,
+ uint16_t target_state,
+ u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex)
+{
+ OIC_LOG_V(DEBUG, TAG, "CALEIsValidState : type[%d], target state[%d]",
+ state_type, target_state);
+ VERIFY_NON_NULL_RET(remoteAddress, TAG, "remoteAddress is null", false);
+ VERIFY_NON_NULL_RET(deviceList, TAG, "deviceList is null", false);
+
+ oc_mutex_lock(deviceListMutex);
+ CALEState_t* state = CALEGetStateInfo(remoteAddress, deviceList);
+ if (NULL == state)
+ {
+ OIC_LOG(DEBUG, TAG, "state is not updated yet");
+ oc_mutex_unlock(deviceListMutex);
+ return false;
+ }
+
+ uint16_t curValue = 0;
+ switch(state_type)
+ {
+ case CA_LE_CONNECTION_STATE:
+ curValue = state->connectedState;
+ break;
+ case CA_LE_SEND_STATE:
+ curValue = state->sendState;
+ break;
+ default:
+ break;
+ }
+
+ if (target_state == curValue)
+ {
+ oc_mutex_unlock(deviceListMutex);
+ return true;
+ }
+ else
+ {
+ oc_mutex_unlock(deviceListMutex);
+ return false;
+ }
+
+ oc_mutex_unlock(deviceListMutex);
+ return false;
+}
+
+
+CAResult_t CALESetFlagToState(JNIEnv *env, jstring jni_address, jint state_idx, jboolean flag,
+ u_arraylist_t *deviceList, oc_mutex deviceListMutex)
+{
+ OIC_LOG(DEBUG, TAG, "IN - CALESetFlagToState");
+ VERIFY_NON_NULL(env, TAG, "env");
+ VERIFY_NON_NULL(jni_address, TAG, "jni_address");
+ VERIFY_NON_NULL(deviceList, TAG, "deviceList");
+
+ oc_mutex_lock(deviceListMutex);
+
+ char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is not available");
+ CACheckJNIException(env);
+ return CA_STATUS_FAILED;
+ }
+
+ if (CALEIsDeviceInList(address, deviceList))
+ {
+ CALEState_t* curState = CALEGetStateInfo(address, deviceList);
+ if(!curState)
+ {
+ OIC_LOG(ERROR, TAG, "curState is null");
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ oc_mutex_unlock(deviceListMutex);
+ return CA_STATUS_FAILED;
+ }
+ OIC_LOG_V(INFO, TAG, "%d flag is set : %d", state_idx, flag);
+
+ switch(state_idx)
+ {
+ case CA_LE_AUTO_CONNECT_FLAG:
+ curState->autoConnectFlag = flag;
+ break;
+ case CA_LE_DESCRIPTOR_FOUND:
+ curState->isDescriptorFound = flag;
+ break;
+ default:
+ break;
+ }
+ }
+
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ oc_mutex_unlock(deviceListMutex);
+ OIC_LOG(DEBUG, TAG, "OUT - CALESetFlagToState");
+ return CA_STATUS_OK;
+}
+
+jboolean CALEGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx,
+ u_arraylist_t *deviceList, oc_mutex deviceListMutex)
+{
+ OIC_LOG(DEBUG, TAG, "IN - CALEGetFlagFromState");
+ VERIFY_NON_NULL_RET(env, TAG, "env", false);
+ VERIFY_NON_NULL_RET(jni_address, TAG, "jni_address", false);
+ VERIFY_NON_NULL_RET(deviceList, TAG, "deviceList", false);
+
+ oc_mutex_lock(deviceListMutex);
+
+ char* address = (char*)(*env)->GetStringUTFChars(env, jni_address, NULL);
+ if (!address)
+ {
+ OIC_LOG(ERROR, TAG, "address is not available");
+ CACheckJNIException(env);
+ oc_mutex_unlock(deviceListMutex);
+ return JNI_FALSE;
+ }
+
+ CALEState_t* curState = CALEGetStateInfo(address, deviceList);
+ (*env)->ReleaseStringUTFChars(env, jni_address, address);
+ if(!curState)
+ {
+ OIC_LOG(INFO, TAG, "there is no information. auto connect flag is false");
+ oc_mutex_unlock(deviceListMutex);
+ return JNI_FALSE;
+ }
+
+ jboolean ret = JNI_FALSE;
+ switch(state_idx)
+ {
+ case CA_LE_AUTO_CONNECT_FLAG:
+ ret = curState->autoConnectFlag;
+ break;
+ case CA_LE_DESCRIPTOR_FOUND:
+ ret = curState->isDescriptorFound;
+ break;
+ default:
+ break;
+ }
+ oc_mutex_unlock(deviceListMutex);
+
+ OIC_LOG_V(INFO, TAG, "%d flag is %d", state_idx, ret);
+ OIC_LOG(DEBUG, TAG, "OUT - CALEGetFlagFromState");
+ return ret;
+}
+
+CAResult_t CALESetMtuSize(const char* address, uint16_t mtuSize,
+ u_arraylist_t *deviceList, oc_mutex deviceListMutex)
+
+{
+ VERIFY_NON_NULL(address, TAG, "address is null");
+ VERIFY_NON_NULL(deviceList, TAG, "deviceList is null");
+
+ oc_mutex_lock(deviceListMutex);
+ if (CALEIsDeviceInList(address, deviceList))
+ {
+ CALEState_t* curState = CALEGetStateInfo(address, deviceList);
+ if(!curState)
+ {
+ OIC_LOG(ERROR, TAG, "curState is null");
+ oc_mutex_unlock(deviceListMutex);
+ return CA_STATUS_FAILED;
+ }
+
+ curState->mtuSize = mtuSize;
+ OIC_LOG_V(INFO, TAG, "update state - addr: %s, mtu: %d",
+ curState->address, curState->mtuSize);
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "there is no state info in the list");
+ }
+ oc_mutex_unlock(deviceListMutex);
+ return CA_STATUS_OK;
+}
+
+uint16_t CALEGetMtuSize(const char* address, u_arraylist_t *deviceList, oc_mutex deviceListMutex)
+{
+ VERIFY_NON_NULL_RET(address, TAG, "address is null", CA_DEFAULT_BLE_MTU_SIZE);
+ VERIFY_NON_NULL_RET(deviceList, TAG, "deviceList is null", CA_DEFAULT_BLE_MTU_SIZE);
+
+ oc_mutex_lock(deviceListMutex);
+ if (CALEIsDeviceInList(address, deviceList))
+ {
+ CALEState_t* curState = CALEGetStateInfo(address, deviceList);
+ if(!curState)
+ {
+ OIC_LOG(ERROR, TAG, "curState is null");
+ oc_mutex_unlock(deviceListMutex);
+ return CA_DEFAULT_BLE_MTU_SIZE;
+ }
+
+ OIC_LOG_V(INFO, TAG, "state - addr: %s, mtu: %d",
+ curState->address, curState->mtuSize);
+ oc_mutex_unlock(deviceListMutex);
+ return curState->mtuSize;
+ }
+
+ oc_mutex_unlock(deviceListMutex);
+ return CA_DEFAULT_BLE_MTU_SIZE;
+}
--- /dev/null
+/* ****************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+/**
+ * @file
+ * This file contains the APIs for BT LE communications.
+ */
+#ifndef CA_LE_LIST_H_
+#define CA_LE_LIST_H_
+
+#include "cacommon.h"
+#include "cathreadpool.h" /* for thread pool */
+#include "octhread.h"
+#include "uarraylist.h"
+#include "jni.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct le_state_info
+{
+ char address[CA_MACADDR_SIZE];
+ uint16_t connectedState;
+ uint16_t sendState;
+ jboolean autoConnectFlag;
+ jboolean isDescriptorFound;
+ uint16_t mtuSize;
+} CALEState_t;
+
+/**
+ * update new state information.
+ * @param[in] address remote address.
+ * @param[in] state_type state type.
+ * @param[in] target_state state index to update.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEUpdateDeviceState(const char* address,
+ uint16_t state_type,
+ uint16_t target_state,
+ u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex);
+
+/**
+ * check whether the remote address is existed or not.
+ * @param[in] address remote address.
+ * @param[in] deviceList target device list.
+ * @return true or false.
+ */
+bool CALEIsDeviceInList(const char* remoteAddress,
+ u_arraylist_t *deviceList);
+
+/**
+ * remove all device states.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALERemoveAllDeviceState(u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex);
+
+/**
+ * Reset values of device state for all of devices.
+ * this method has to be invoked when BT adapter is disabled.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALEResetDeviceStateForAll(u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex);
+
+/**
+ * remove the device state for a remote device.
+ * @param[in] remoteAddress remote address.
+ * @param[in] deviceList target device list.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALERemoveDeviceState(const char* remoteAddress,
+ u_arraylist_t *deviceList);
+
+/**
+ * get state information for a remote device.
+ * @param[in] remoteAddress remote address.
+ * @param[in] deviceList target device list.
+ * @return CALEState_t.
+ */
+CALEState_t* CALEGetStateInfo(const char* remoteAddressm,
+ u_arraylist_t *deviceList);
+
+/**
+ * check whether the remote address has same state with target state.
+ * @param[in] remoteAddress remote address.
+ * @param[in] state_type state_type.
+ * @param[in] target_state state index to check.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return true or false.
+ */
+bool CALEIsValidState(const char* remoteAddress,
+ uint16_t state_type,
+ uint16_t target_state,
+ u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex);
+
+
+/**
+ * set flag into State List.
+ * @param[in] env JNI interface pointer.
+ * @param[in] jni_address remote address.
+ * @param[in] state_idx state index.
+ * @param[in] flag auto connect flag.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ */
+CAResult_t CALESetFlagToState(JNIEnv *env, jstring jni_address,
+ jint state_idx, jboolean flag,
+ u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex);
+
+/**
+ * get flag from State List.
+ * @param[in] env JNI interface pointer.
+ * @param[in] jni_address remote address.
+ * @param[in] state_idx state index.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return current flag;
+ */
+jboolean CALEGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx,
+ u_arraylist_t *deviceList, oc_mutex deviceListMutex);
+
+/**
+ * This function is used to set MTU size
+ * which negotiated between client and server device.
+ * @param[in] address remote address.
+ * @param[in] mtuSize MTU size.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CALESetMtuSize(const char* address, uint16_t mtuSize,
+ u_arraylist_t *deviceList, oc_mutex deviceListMutex);
+
+/**
+ * get MTU size.
+ * @param[in] address the address of the remote device.
+ * @param[in] deviceList target device list.
+ * @param[in] deviceListMutex target device list mutex.
+ * @return mtu size negotiated from remote device.
+ */
+uint16_t CALEGetMtuSize(const char* address,
+ u_arraylist_t *deviceList,
+ oc_mutex deviceListMutex);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* CA_LESERVER_H_ */