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 ******************************************************************/
22 * This file provides APIs for BLE modules.
25 #ifndef CA_LE_INTERFACE_H_
26 #define CA_LE_INTERFACE_H_
31 #include "cathreadpool.h"
39 * Provide info about different mode of data transfer.
41 * This enum is used to differentiate between unicast and multicast
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. */
51 * This will be used to notify device status changes to the LE adapter layer.
52 * @param[in] adapter_state State of the adapter.
54 typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
57 * Notify the adapter layer that a packet was received from the GATT
60 * @param[in] remoteAddress Remote endpoint Address.
61 * @param[in] data Data received.
62 * @param[in] dataLength Length of the data received.
63 * @param[in] sentLength Length of the data sent.
65 * @return ::CA_STATUS_OK or Appropriate error code.
66 * @retval ::CA_STATUS_OK Successful.
67 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
68 * @retval ::CA_STATUS_FAILED Operation failed.
70 typedef CAResult_t (*CABLEDataReceivedCallback)(const char *remoteAddress,
73 uint32_t *sentLength);
76 * Initialize the LE adapter layer. This will be invoked from the CA
79 * @return ::CA_STATUS_OK or Appropriate error code
80 * @retval ::CA_STATUS_OK Successful
81 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
82 * @retval ::CA_STATUS_FAILED Operation failed
84 CAResult_t CAInitializeLEAdapter();
87 * Start the LE adapter layer.
89 * This function will be invoked from the CA layer when the LE
90 * "network" is selected via @c CASelectNetwork(). It gives an
91 * opportunity for LE adapter implementations to perform operations
92 * before starting a GATT client or server. Most LE adapter
93 * implementations will simply implement this function as no-op.
95 * @return ::CA_STATUS_OK or Appropriate error code
97 CAResult_t CAStartLEAdapter();
100 * Used to get the current state of the LE adapter.
102 * @return ::CA_STATUS_OK or Appropriate error code
103 * @retval ::CA_STATUS_OK Successful
104 * @retval ::CA_ADAPTER_NOT_ENABLED adapter not enabled
105 * @retval ::CA_STATUS_FAILED Operation failed
107 CAResult_t CAGetLEAdapterState();
110 * Initialize the network monitor layer of the LE adapter. Mutex
111 * variables required to operate in this layer and other parameters
112 * can be initialized in this function.
114 * @return ::CA_STATUS_OK or Appropriate error code
115 * @retval ::CA_STATUS_OK Successful
116 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
117 * @retval ::CA_STATUS_FAILED Operation failed
119 CAResult_t CAInitializeLENetworkMonitor();
122 * Terminate the network monitor layer of the LE adapter. The
123 * variables initialized in @c CAInitializeLENetworkMonitor() must be
124 * cleared in this function.
126 void CATerminateLENetworkMonitor();
129 * Set the callback for the device state changes in the adapter.
131 * @param[in] callback Callback to notify the Device state change to
134 * @return ::CA_STATUS_OK or Appropriate error code
135 * @retval ::CA_STATUS_OK Successful
136 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
137 * @retval ::CA_STATUS_FAILED Operation failed
139 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
142 * Initialize all the mutex variables required to operate the LE
143 * network monitor layer.
145 * @return ::CA_STATUS_OK or Appropriate error code
146 * @retval ::CA_STATUS_OK Successful
147 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
148 * @retval ::CA_STATUS_FAILED Operation failed
150 CAResult_t CAInitLENetworkMonitorMutexVariables();
153 * Used to terminate all the mutex variables required to operate the LE
154 * network monitor layer.
156 void CATerminateLENetworkMonitorMutexVariables();
159 * Provides the MAC address of the local Bluetooth adapter.
161 * @param[out] local_address Pointer to the location where bd address
162 * needs to be stored.
164 * @return ::CA_STATUS_OK or Appropriate error code
165 * @retval ::CA_STATUS_OK Successful
166 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
167 * @retval ::CA_STATUS_FAILED Operation failed
169 CAResult_t CAGetLEAddress(char **local_address);
172 * Start Gatt Server thread for service creation and advertise BLE
175 * @return ::CA_STATUS_OK or Appropriate error code
176 * @retval ::CA_STATUS_OK Successful
177 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
178 * @retval ::CA_STATUS_FAILED Operation failed
180 CAResult_t CAStartLEGattServer();
183 * Stop BLE Gatt Service.
185 * @return ::CA_STATUS_OK or Appropriate error code
186 * @retval ::CA_STATUS_OK Successful
187 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
188 * @retval ::CA_STATUS_FAILED Operation failed
190 CAResult_t CAStopLEGattServer();
193 * Stop Gatt Server thread and remove service registration, stop
196 void CATerminateLEGattServer();
199 * Used to store upper layer callback locally which will be used to
200 * send the data to application.
202 * @param[in] callback Callback function to pass the data to CA layer.
204 void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback);
207 * Update characteristics(Read/Write) value that we want to send to
210 * @param[in] address BD address of Gatt client
211 * @param[in] charValue Data that we want to send to client(unicast)
212 * @param[in] charValueLen Length of the data.
214 * @return ::CA_STATUS_OK or Appropriate error code
215 * @retval ::CA_STATUS_OK Successful
216 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
217 * @retval ::CA_STATUS_FAILED Operation failed
219 CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
220 const char *charValue,
221 uint32_t charValueLen);
224 * Update characteristics(Read/Write) value that we want to multicast
227 * @param[in] charValue Data that we want to send to clients(multicast)
228 * @param[in] charValueLen Length of the data.
230 * @return ::CA_STATUS_OK or Appropriate error code
231 * @retval ::CA_STATUS_OK Successful
232 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
233 * @retval ::CA_STATUS_FAILED Operation failed
235 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
236 uint32_t charValueLen);
239 * Start @c CAStartBleGattClientThread for initializing Gatt Client.
241 * @return ::CA_STATUS_OK or Appropriate error code
242 * @retval ::CA_STATUS_OK Successful
243 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
244 * @retval ::CA_STATUS_FAILED Operation failed
246 CAResult_t CAStartLEGattClient();
249 * Stop Gatt client gracefully. In turn it will call the
250 * @c CATerminateBLEGattClient function.
252 * @return ::CA_STATUS_OK or Appropriate error code
253 * @retval ::CA_STATUS_OK Successful
254 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
255 * @retval ::CA_STATUS_FAILED Operation failed
257 void CAStopLEGattClient();
260 * Unset all the callbacks and stop service discovery
262 void CATerminateLEGattClient();
265 * Read the data from characteristics and invoke notify callback.
267 void CACheckLEData();
270 * Set the value of characteristic and update the value to
271 * GATTServer (unicast).
273 * @param[in] remoteAddress The address of the remote device
274 * @param[in] data The value of characteristic (byte array)
275 * @param[in] dataLen The length of value
276 * @param[in] type Type of the transfer(::CALETransferType_t)
277 * @param[in] position The unique index of each ble server. Used
278 * for multicast feature.
280 * @return ::CA_STATUS_OK or Appropriate error code
281 * @retval ::CA_STATUS_OK Successful
282 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
283 * @retval ::CA_STATUS_FAILED Operation failed
285 CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
288 CALETransferType_t type,
292 * Set the value of characteristic and update the value to all
293 * registered GATTServer (multicast).
295 * @param[in] data The value of characteristic (byte array)
296 * @param[in] dataLen The length of value
298 * @return ::CA_STATUS_OK or Appropriate error code
299 * @retval ::CA_STATUS_OK Successful
300 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
301 * @retval ::CA_STATUS_FAILED Operation failed
303 CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data,
307 * Store upper layer callback locally which will be used to send the
308 * data to application.
310 * @param[in] callback Callback function to pass the data to CA layer.
312 void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback);
315 * Set the server thread pool handle which is required for spawning
318 * @param[in] handle Thread pool handle which is given by above layer
319 * for using thread creation task.
321 * @return ::CA_STATUS_OK or Appropriate error code
322 * @retval ::CA_STATUS_OK Successful
323 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
324 * @retval ::CA_STATUS_FAILED Operation failed
326 void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle);
329 * Set the client thread pool handle which is required for spawning new
332 * @param[in] handle Thread pool handle which is given by above layer
333 * for using thread creation task.
335 void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle);
338 * Unset the callback of adapter connection state change.
340 * @return ::CA_STATUS_OK or Appropriate error code.
341 * @retval ::CA_STATUS_OK Successful.
342 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
343 * @retval ::CA_STATUS_FAILED Operation failed.
345 CAResult_t CAUnSetLEAdapterStateChangedCb();
348 * This will be used to notify errors in BLE adapter.
350 * @param[in] remoteAddress Remote endpoint Address
351 * @param[in] data Data received
352 * @param[in] dataLength Length of the data received
353 * @param[in] result error code as per CAResult_t
355 typedef void (*CABLEErrorHandleCallback)(const char *remoteAddress,
360 * Set the client error handler callback.
362 * @param[in] callback Callback function to update error to the
365 void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback);
369 * Set the server error handler callback.
371 * @param[in] callback Callback function to update error to the
374 void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback);
380 #endif /* CA_LE_INTERFACE_H_ */