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 provides APIs for BLE modules.
27 #ifndef CA_LE_INTERFACE_H_
28 #define CA_LE_INTERFACE_H_
33 #include "caleadapter.h"
41 * Provide info about different mode of data transfer.
42 * This enum is used to differentiate between unicast and multicast data transfer.
46 LE_MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */
47 LE_UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */
52 * Initialize the LE adapter layer. This will be invoked from the CA layer.
54 * @return ::CA_STATUS_OK or Appropriate error code.
55 * @retval ::CA_STATUS_OK Successful.
56 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
57 * @retval ::CA_STATUS_FAILED Operation failed.
59 CAResult_t CAInitializeLEAdapter();
62 * Used to get the current state of the LE adapter.
64 * @return ::CA_STATUS_OK or Appropriate error code.
65 * @retval ::CA_STATUS_OK Successful.
66 * @retval ::CA_ADAPTER_NOT_ENABLED adapter not enabled.
67 * @retval ::CA_STATUS_FAILED Operation failed.
69 CAResult_t CAGetLEAdapterState();
72 * Used to initialize the network monitor layer of the LE adapter. Mutex variables required
73 * to operate in this layer and other paramters can be initialized in this function.
75 * @return ::CA_STATUS_OK or Appropriate error code.
76 * @retval ::CA_STATUS_OK Successful.
77 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
78 * @retval ::CA_STATUS_FAILED Operation failed.
80 CAResult_t CAInitializeLENetworkMonitor();
83 * Used to terminate the network monitor layer of the LE adapter. The variables intialized
84 * in CAInitializeLEAdapterController() must be cleared in this function.
86 void CATerminateLENetworkMonitor();
89 * This function is used to set the callback for the Device state changes in the adapter.
91 * @param[in] callback Callback to notify the Device state change to the CA Layer.
93 * @return ::CA_STATUS_OK or Appropriate error code.
94 * @retval ::CA_STATUS_OK Successful.
95 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
96 * @retval ::CA_STATUS_FAILED Operation failed.
98 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
101 * Used to initilaze all the mutex variables required.
102 * to operate the LE network monitor layer.
103 * @return ::CA_STATUS_OK or Appropriate error code.
104 * @retval ::CA_STATUS_OK Successful.
105 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
106 * @retval ::CA_STATUS_FAILED Operation failed.
108 CAResult_t CAInitLENetworkMonitorMutexVariables();
111 * Used to terminate all the mutex variables required
112 * to operate the LE network monitor layer.
114 void CATerminateLENetworkMonitorMutexVariables();
117 * Provides the BD address of the local adapter.
118 * @param[out] local_address pointer to the location where bd address needs to be stored.
120 * @return ::CA_STATUS_OK or Appropriate error code.
121 * @retval ::CA_STATUS_OK Successful.
122 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
123 * @retval ::CA_STATUS_FAILED Operation failed.
125 CAResult_t CAGetLEAddress(char **local_address);
128 * Used to start Gatt Server thread for service creation and advertise ble service.
130 * @return ::CA_STATUS_OK or Appropriate error code.
131 * @retval ::CA_STATUS_OK Successful.
132 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
133 * @retval ::CA_STATUS_FAILED Operation failed.
135 CAResult_t CAStartLEGattServer();
138 * Used to stop BLE Gatt Service.
140 * @return ::CA_STATUS_OK or Appropriate error code.
141 * @retval ::CA_STATUS_OK Successful.
142 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
143 * @retval ::CA_STATUS_FAILED Operation failed.
145 CAResult_t CAStopLEGattServer();
148 * Used to stop Gatt Server thread and remove service registration, stop advertising.
150 void CATerminateLEGattServer();
153 * Used to store upper layer callback locally
154 * which will be used to send the data to application.
155 * @param[in] callback Callback function to pass the data to CA layer.
157 void CASetLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
160 * Used to update characteristics(Read/Write) value
161 * that we want to send to particular client.
163 * @param[in] address BD address of Gatt client.
164 * @param[in] charValue Data that we want to send to client(unicast).
165 * @param[in] charValueLen Length of the data.
167 * @return ::CA_STATUS_OK or Appropriate error code.
168 * @retval ::CA_STATUS_OK Successful.
169 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
170 * @retval ::CA_STATUS_FAILED Operation failed.
172 CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *charValue,
173 const uint32_t charValueLen);
176 * Used to update characteristics(Read/Write) value that we want to multicast to all clients.
178 * @param[in] charValue Data that we want to send to clients(multicast).
179 * @param[in] charValueLen Length of the data.
181 * @return ::CA_STATUS_OK or Appropriate error code.
182 * @retval ::CA_STATUS_OK Successful.
183 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
184 * @retval ::CA_STATUS_FAILED Operation failed.
186 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
187 uint32_t charValueLen);
190 * Used to start CAStartBleGattClientThread for initializing Gatt Client.
192 * @return ::CA_STATUS_OK or Appropriate error code.
193 * @retval ::CA_STATUS_OK Successful.
194 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
195 * @retval ::CA_STATUS_FAILED Operation failed.
197 CAResult_t CAStartLEGattClient();
200 * Used to stop Gatt Client gracefully in turn it will
201 * call CATerminateBLEGattClient function.
202 * @return ::CA_STATUS_OK or Appropriate error code.
203 * @retval ::CA_STATUS_OK Successful.
204 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
205 * @retval ::CA_STATUS_FAILED Operation failed.
207 void CAStopLEGattClient();
210 * Used to unset all the callbacks and stop service discovery.
212 void CATerminateLEGattClient();
215 * API to read the data from characteristics and invoke notifyCallback.
217 void CACheckLEData();
220 * Sets the value of characteristic and update the value to GATTServer(unicast).
222 * @param[in] remoteAddress The address of the remote device.
223 * @param[in] data The value of characteristic (byte array).
224 * @param[in] dataLen The length of value.
225 * @param[in] type Type of the transfer(::CALETransferType_t).
226 * @param[in] position The unique index of each ble server. Used for multicast feature.
228 * @return ::CA_STATUS_OK or Appropriate error code.
229 * @retval ::CA_STATUS_OK Successful.
230 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
231 * @retval ::CA_STATUS_FAILED Operation failed.
233 CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char *data,
234 const uint32_t dataLen, CALETransferType_t type,
235 const int32_t position);
238 * Sets the value of characteristic and update the value to all registered.
239 * GATTServer -> Multicast.
240 * @param[in] data The value of characteristic (byte array).
241 * @param[in] dataLen The length of value.
243 * @return ::CA_STATUS_OK or Appropriate error code.
244 * @retval ::CA_STATUS_OK Successful.
245 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
246 * @retval ::CA_STATUS_FAILED Operation failed.
248 CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, uint32_t dataLen);
251 * Used to store upper layer callback locally which will be used
252 * to send the data to application.
253 * @param[in] callback Callback function to pass the data to CA layer.
255 void CASetLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
258 * Used to Set the gThreadPool handle which is required for spawning new thread.
260 * @param[in] handle Thread pool handle which is given by above layer
261 * for using thread creation task.
262 * @return ::CA_STATUS_OK or Appropriate error code.
263 * @retval ::CA_STATUS_OK Successful.
264 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
265 * @retval ::CA_STATUS_FAILED Operation failed.
267 void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle);
270 * Used to Set the gThreadPool handle which is required for spawning new thread.
271 * @param[in] handle Thread pool handle which is given by above layer
272 * for using thread creation task.
274 void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle);
277 * Used to unset the callback of adapter connection state change.
279 * @return ::CA_STATUS_OK or Appropriate error code.
280 * @retval ::CA_STATUS_OK Successful.
281 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
282 * @retval ::CA_STATUS_FAILED Operation failed.
284 CAResult_t CAUnSetLEAdapterStateChangedCb();
287 * This will be used to notify errors in BLE adapter
288 * @param[in] remoteAddress Remote endpoint Address.
289 * @param[in] serviceUUID Service UUID.
290 * @param[in] data Data received.
291 * @param[in] dataLength Length of the data received.
292 * @param[in] result error code as per CAResult_t.
294 typedef void (*CABLEErrorHandleCallback)(const char *remoteAddress, const void *data,
295 uint32_t dataLength, CAResult_t result);
297 * sets the error handle callback.
298 * @param[in] callback Callback function to update error to the adapter.
300 void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback);
304 * sets the error handle callback.
305 * @param[in] callback Callback function to update error to the adapter.
307 void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback);
313 #endif /* CA_LE_INTERFACE_H_ */