1 /* ****************************************************************
3 * Copyright 2014 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 ******************************************************************/
24 * This file contains the APIs for BT EDR communications.
27 #ifndef __CA_EDRCORE_H_
28 #define __CA_EDRCORE_H_
33 #include "cathreadpool.h"
43 * @brief Set context of application
44 * @param context [IN] context of application
47 void CAEDRJniSetContext(jobject context);
50 * @brief Create JNI Object
51 * @param context [IN] context of application
54 void CAEDRCreateJNIInterfaceObject(jobject context);
57 * @brief Initialize client for EDR
58 * @param handle [IN] thread pool handle object
61 void CAEDRInitialize(ca_thread_pool_t handle);
64 * @brief Terminate server for EDR
67 void CAEDRTerminate();
70 * @brief Initialize JNI object
71 * @param env [IN] JNI interface pointer
72 * @param jvm [IN] java virtual machine pointer
75 void CAEDRCoreJniInit(JNIEnv *env, JavaVM *jvm);
78 * @brief Send data for unicast
79 * @param address [IN] remote address
80 * @param data [IN] data for transmission
81 * @param dataLen [IN] data length
82 * @return #CA_STATUS_OK or Appropriate error code
83 * @retval #CA_STATUS_OK Successful
84 * @retval #CA_STATUS_FAILED Operation failed
86 CAResult_t CAEDRSendUnicastMessage(const char *address,
87 const char *data, uint32_t dataLen);
90 * @brief Send data for multicast
91 * @param data [IN] data for transmission
92 * @param dataLen [IN] data length
93 * @return #CA_STATUS_OK or Appropriate error code
94 * @retval #CA_STATUS_OK Successful
95 * @retval #CA_STATUS_FAILED Operation failed
97 CAResult_t CAEDRSendMulticastMessage(const char *data, uint32_t dataLen);
100 * @brief Get Local EDR Address
101 * @param address [OUT] local address
102 * @return #CA_STATUS_OK or Appropriate error code
103 * @retval #CA_STATUS_OK Successful
104 * @retval #CA_STATUS_FAILED Operation failed
106 CAResult_t CAEDRGetInterfaceInfo(char **address);
109 * @brief Get address from a local device
110 * @param address [OUT] local address
113 void CAEDRGetLocalAddress(char **address);
116 * @brief Send data for unicast (implement)
117 * @param address [IN] remote address
118 * @param data [IN] data for transmission
119 * @param dataLen [IN] data length
120 * @return #CA_STATUS_OK or Appropriate error code
121 * @retval #CA_STATUS_OK Successful
122 * @retval #CA_STATUS_FAILED Operation failed
124 CAResult_t CAEDRSendUnicastMessageImpl(const char *address,
125 const char *data, uint32_t dataLen);
128 * @brief Send data for multicast (implement)
129 * @param env [IN] JNI interface pointer
130 * @param data [IN] data for transmission
131 * @param dataLen [IN] data length
132 * @return #CA_STATUS_OK or Appropriate error code
133 * @retval #CA_STATUS_OK Successful
134 * @retval #CA_STATUS_FAILED Operation failed
136 CAResult_t CAEDRSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen);
143 * @brief This function will send the data to remote device.
144 * @param env [IN] JNI interface pointer
145 * @param address [IN] Remote Address
146 * @param data [IN] Data to be transmitted from EDR
147 * @param id [IN] index of remote address
150 void CAEDRNativeSendData(JNIEnv *env, const char *address, const char *data, uint32_t id);
153 * @brief This function will connect to remote device.
154 * @param env [IN] JNI interface pointer
155 * @param address [IN] Remote Address
156 * @param id [IN] index of remote address
159 void CAEDRNativeConnect(JNIEnv *env, const char *address, uint32_t id);
162 * @brief This function will close socket.
163 * @param env [IN] JNI interface pointer
164 * @param address [IN] Remote Address
165 * @param id [IN] index of remote address
168 void CAEDRNativeSocketClose(JNIEnv *env, const char *address, uint32_t id);
175 * @brief This function will create the device state list.
178 void CAEDRNativeCreateDeviceStateList();
181 * @brief Update connection state of device
182 * @param state [IN] connection state
183 * @param address [IN] remote address
186 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address);
189 * @brief Add device object to the list
190 * @param state [IN] connection state object
193 void CAEDRNativeAddDeviceStateToList(state_t *state);
196 * @brief Check whether the device exist in the list or not
197 * @param remoteAddress [IN] remote address
198 * @return TRUE or FALSE
200 jboolean CAEDRNativeIsDeviceInList(const char *remoteAddress);
203 * @brief Remove all device objects in the list
206 void CAEDRNativeRemoveAllDeviceState();
209 * @brief Remove target device in the list
210 * @param remoteAddress [IN] remote address
213 void CAEDRNativeRemoveDevice(const char *remoteAddress);
216 * @brief Get current device connection state
217 * @param remoteAddress [IN] remote address
218 * @return STATE_DISCONNECTED or STATE_CONNECTED
220 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress);
223 * @brief Reordering for the list
224 * @param index [IN] index of device list that want to reordering
227 void CAEDRReorderingDeviceList(uint32_t index);
230 * Bluetooth Socket Object List
234 * @brief This function will create the device socket list.
237 void CAEDRNativeCreateDeviceSocketList();
240 * @brief Add device object to the list
241 * @param env [IN] JNI interface pointer
242 * @param deviceSocket [IN] device socket object
245 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
248 * @brief Add device object to the list
249 * @param env [IN] JNI interface pointer
250 * @param remoteAddress [IN] remote address
251 * @return TRUE or FALSE
253 jboolean CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
256 * @brief Add device object to the list
257 * @param env [IN] JNI interface pointer
260 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env);
263 * @brief Add device object to the list
264 * @param env [IN] JNI interface pointer
265 * @param deviceSocket [IN] device socket object
268 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
271 * @brief Get device socket object from the list
272 * @param idx [IN] index of device list
273 * @return Device socket object or NULL
275 jobject CAEDRNativeGetDeviceSocket(uint32_t idx);
278 * @brief Get length of device socket list
279 * @return length of list
281 uint32_t CAEDRGetSocketListLength();
284 * @brief Reordering for the list
285 * @param index [IN] index of device list that want to reordering
288 void CAEDRReorderingDeviceSocketList(uint32_t index);