1 /* ****************************************************************
3 * Copyright 2017 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
23 * This file contains the APIs for BT LE communications.
29 #include "cathreadpool.h" /* for thread pool */
31 #include "uarraylist.h"
39 typedef struct le_state_info
41 char address[CA_MACADDR_SIZE];
42 uint16_t connectedState;
44 jboolean autoConnectFlag;
45 jboolean isDescriptorFound;
50 * update new state information.
51 * @param[in] address remote address.
52 * @param[in] state_type state type.
53 * @param[in] target_state state index to update.
54 * @param[in] deviceList target device list.
55 * @param[in] deviceListMutex target device list mutex.
56 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
58 CAResult_t CALEUpdateDeviceState(const char* address,
60 uint16_t target_state,
61 u_arraylist_t *deviceList,
62 oc_mutex deviceListMutex);
65 * check whether the remote address is existed or not.
66 * @param[in] address remote address.
67 * @param[in] deviceList target device list.
68 * @return true or false.
70 bool CALEIsDeviceInList(const char* remoteAddress,
71 u_arraylist_t *deviceList);
74 * remove all device states.
75 * @param[in] deviceList target device list.
76 * @param[in] deviceListMutex target device list mutex.
77 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
79 CAResult_t CALERemoveAllDeviceState(u_arraylist_t *deviceList,
80 oc_mutex deviceListMutex);
83 * Reset values of device state for all of devices.
84 * this method has to be invoked when BT adapter is disabled.
85 * @param[in] deviceList target device list.
86 * @param[in] deviceListMutex target device list mutex.
87 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
89 CAResult_t CALEResetDeviceStateForAll(u_arraylist_t *deviceList,
90 oc_mutex deviceListMutex);
93 * remove the device state for a remote device.
94 * @param[in] remoteAddress remote address.
95 * @param[in] deviceList target device list.
96 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
98 CAResult_t CALERemoveDeviceState(const char* remoteAddress,
99 u_arraylist_t *deviceList);
102 * get state information for a remote device.
103 * @param[in] remoteAddress remote address.
104 * @param[in] deviceList target device list.
105 * @return CALEState_t.
107 CALEState_t* CALEGetStateInfo(const char* remoteAddressm,
108 u_arraylist_t *deviceList);
111 * check whether the remote address has same state with target state.
112 * @param[in] remoteAddress remote address.
113 * @param[in] state_type state_type.
114 * @param[in] target_state state index to check.
115 * @param[in] deviceList target device list.
116 * @param[in] deviceListMutex target device list mutex.
117 * @return true or false.
119 bool CALEIsValidState(const char* remoteAddress,
121 uint16_t target_state,
122 u_arraylist_t *deviceList,
123 oc_mutex deviceListMutex);
127 * set flag into State List.
128 * @param[in] env JNI interface pointer.
129 * @param[in] jni_address remote address.
130 * @param[in] state_idx state index.
131 * @param[in] flag auto connect flag.
132 * @param[in] deviceList target device list.
133 * @param[in] deviceListMutex target device list mutex.
135 CAResult_t CALESetFlagToState(JNIEnv *env, jstring jni_address,
136 jint state_idx, jboolean flag,
137 u_arraylist_t *deviceList,
138 oc_mutex deviceListMutex);
141 * get flag from State List.
142 * @param[in] env JNI interface pointer.
143 * @param[in] jni_address remote address.
144 * @param[in] state_idx state index.
145 * @param[in] deviceList target device list.
146 * @param[in] deviceListMutex target device list mutex.
147 * @return current flag;
149 jboolean CALEGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx,
150 u_arraylist_t *deviceList, oc_mutex deviceListMutex);
153 * This function is used to set MTU size
154 * which negotiated between client and server device.
155 * @param[in] address remote address.
156 * @param[in] mtuSize MTU size.
157 * @param[in] deviceList target device list.
158 * @param[in] deviceListMutex target device list mutex.
159 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
161 CAResult_t CALESetMtuSize(const char* address, uint16_t mtuSize,
162 u_arraylist_t *deviceList, oc_mutex deviceListMutex);
166 * @param[in] address the address of the remote device.
167 * @param[in] deviceList target device list.
168 * @param[in] deviceListMutex target device list mutex.
169 * @return mtu size negotiated from remote device.
171 uint16_t CALEGetMtuSize(const char* address,
172 u_arraylist_t *deviceList,
173 oc_mutex deviceListMutex);
178 #endif /* CA_LESERVER_H_ */