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 "cathreadpool.h"
41 * Provide info about different mode of data transfer.
43 * This enum is used to differentiate between unicast and multicast
48 LE_MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */
49 LE_UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */
53 * This will be used to notify device status changes to the LE adapter layer.
54 * @param[in] adapter_state State of the adapter.
56 typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
59 * Notify the adapter layer that a packet was received from the GATT
62 * @param[in] remoteAddress Remote endpoint Address.
63 * @param[in] data Data received.
64 * @param[in] dataLength Length of the data received.
65 * @param[in] sentLength Length of the data sent.
67 * @return ::CA_STATUS_OK or Appropriate error code.
68 * @retval ::CA_STATUS_OK Successful.
69 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
70 * @retval ::CA_STATUS_FAILED Operation failed.
72 typedef CAResult_t (*CABLEDataReceivedCallback)(const char *remoteAddress,
75 uint32_t *sentLength);
78 * Initialize the LE adapter layer. This will be invoked from the CA
81 * @return ::CA_STATUS_OK or Appropriate error code
82 * @retval ::CA_STATUS_OK Successful
83 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
84 * @retval ::CA_STATUS_FAILED Operation failed
86 CAResult_t CAInitializeLEAdapter();
89 * Start the LE adapter layer.
91 * This function will be invoked from the CA layer when the LE
92 * "network" is selected via @c CASelectNetwork(). It gives an
93 * opportunity for LE adapter implementations to perform operations
94 * before starting a GATT client or server. Most LE adapter
95 * implementations will simply implement this function as no-op.
97 * @return ::CA_STATUS_OK or Appropriate error code
99 CAResult_t CAStartLEAdapter();
102 * Used to get the current state of the LE adapter.
104 * @return ::CA_STATUS_OK or Appropriate error code
105 * @retval ::CA_STATUS_OK Successful
106 * @retval ::CA_ADAPTER_NOT_ENABLED adapter not enabled
107 * @retval ::CA_STATUS_FAILED Operation failed
109 CAResult_t CAGetLEAdapterState();
112 * Initialize the network monitor layer of the LE adapter. Mutex
113 * variables required to operate in this layer and other parameters
114 * can be initialized in this function.
116 * @return ::CA_STATUS_OK or Appropriate error code
117 * @retval ::CA_STATUS_OK Successful
118 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
119 * @retval ::CA_STATUS_FAILED Operation failed
121 CAResult_t CAInitializeLENetworkMonitor();
124 * Terminate the network monitor layer of the LE adapter. The
125 * variables initialized in @c CAInitializeLENetworkMonitor() must be
126 * cleared in this function.
128 void CATerminateLENetworkMonitor();
131 * Set the callback for the device state changes in the adapter.
133 * @param[in] callback Callback to notify the Device state change to
136 * @return ::CA_STATUS_OK or Appropriate error code
137 * @retval ::CA_STATUS_OK Successful
138 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
139 * @retval ::CA_STATUS_FAILED Operation failed
141 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
144 * Initialize all the mutex variables required to operate the LE
145 * network monitor layer.
147 * @return ::CA_STATUS_OK or Appropriate error code
148 * @retval ::CA_STATUS_OK Successful
149 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
150 * @retval ::CA_STATUS_FAILED Operation failed
152 CAResult_t CAInitLENetworkMonitorMutexVariables();
155 * Used to terminate all the mutex variables required to operate the LE
156 * network monitor layer.
158 void CATerminateLENetworkMonitorMutexVariables();
161 * Provides the MAC address of the local Bluetooth adapter.
163 * @param[out] local_address Pointer to the location where bd address
164 * needs to be stored.
166 * @return ::CA_STATUS_OK or Appropriate error code
167 * @retval ::CA_STATUS_OK Successful
168 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
169 * @retval ::CA_STATUS_FAILED Operation failed
171 CAResult_t CAGetLEAddress(char **local_address);
174 * Start Gatt Server thread for service creation and advertise BLE
177 * @return ::CA_STATUS_OK or Appropriate error code
178 * @retval ::CA_STATUS_OK Successful
179 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
180 * @retval ::CA_STATUS_FAILED Operation failed
182 CAResult_t CAStartLEGattServer();
185 * Stop BLE Gatt Service.
187 * @return ::CA_STATUS_OK or Appropriate error code
188 * @retval ::CA_STATUS_OK Successful
189 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
190 * @retval ::CA_STATUS_FAILED Operation failed
192 CAResult_t CAStopLEGattServer();
195 * Stop Gatt Server thread and remove service registration, stop
198 void CATerminateLEGattServer();
201 * Used to store upper layer callback locally which will be used to
202 * send the data to application.
204 * @param[in] callback Callback function to pass the data to CA layer.
206 void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback);
209 * Update characteristics(Read/Write) value that we want to send to
212 * @param[in] address BD address of Gatt client
213 * @param[in] value Data that we want to send to client(unicast)
214 * @param[in] valueLen Length of the data.
216 * @return ::CA_STATUS_OK or Appropriate error code
217 * @retval ::CA_STATUS_OK Successful
218 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
219 * @retval ::CA_STATUS_FAILED Operation failed
221 CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
222 const uint8_t *value,
226 * Update characteristics(Read/Write) value that we want to multicast
229 * @param[in] value Data that we want to send to clients(multicast)
230 * @param[in] valueLen Length of the data.
232 * @return ::CA_STATUS_OK or Appropriate error code
233 * @retval ::CA_STATUS_OK Successful
234 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
235 * @retval ::CA_STATUS_FAILED Operation failed
237 CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *value,
241 * Start @c CAStartBleGattClientThread for initializing Gatt Client.
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 CAStartLEGattClient();
251 * Stop Gatt client gracefully. In turn it will call the
252 * @c CATerminateBLEGattClient function.
254 * @return ::CA_STATUS_OK or Appropriate error code
255 * @retval ::CA_STATUS_OK Successful
256 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
257 * @retval ::CA_STATUS_FAILED Operation failed
259 void CAStopLEGattClient();
262 * Unset all the callbacks and stop service discovery
264 void CATerminateLEGattClient();
267 * Read the data from characteristics and invoke notify callback.
269 void CACheckLEData();
272 * Set the value of characteristic and update the value to
273 * GATTServer (unicast).
275 * @param[in] remoteAddress The address of the remote device
276 * @param[in] data The value of characteristic (byte array)
277 * @param[in] dataLen The length of value
278 * @param[in] type Type of the transfer(::CALETransferType_t)
279 * @param[in] position The unique index of each ble server. Used
280 * for multicast feature.
282 * @return ::CA_STATUS_OK or Appropriate error code
283 * @retval ::CA_STATUS_OK Successful
284 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
285 * @retval ::CA_STATUS_FAILED Operation failed
287 CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
290 CALETransferType_t type,
294 * Set the value of characteristic and update the value to all
295 * registered GATTServer (multicast).
297 * @param[in] data The value of characteristic (byte array)
298 * @param[in] dataLen The length of value
300 * @return ::CA_STATUS_OK or Appropriate error code
301 * @retval ::CA_STATUS_OK Successful
302 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
303 * @retval ::CA_STATUS_FAILED Operation failed
305 CAResult_t CAUpdateCharacteristicsToAllGattServers(const uint8_t *data,
309 * Store upper layer callback locally which will be used to send the
310 * data to application.
312 * @param[in] callback Callback function to pass the data to CA layer.
314 void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback);
317 * Set the server thread pool handle which is required for spawning
320 * @param[in] handle Thread pool handle which is given by above layer
321 * for using thread creation task.
323 * @return ::CA_STATUS_OK or Appropriate error code
324 * @retval ::CA_STATUS_OK Successful
325 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments
326 * @retval ::CA_STATUS_FAILED Operation failed
328 void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle);
331 * Set the client thread pool handle which is required for spawning new
334 * @param[in] handle Thread pool handle which is given by above layer
335 * for using thread creation task.
337 void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle);
340 * Unset the callback of adapter connection state change.
342 * @return ::CA_STATUS_OK or Appropriate error code.
343 * @retval ::CA_STATUS_OK Successful.
344 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
345 * @retval ::CA_STATUS_FAILED Operation failed.
347 CAResult_t CAUnSetLEAdapterStateChangedCb();
350 * This will be used to notify errors in BLE adapter.
352 * @param[in] remoteAddress Remote endpoint Address
353 * @param[in] data Data received
354 * @param[in] dataLength Length of the data received
355 * @param[in] result error code as per CAResult_t
357 typedef void (*CABLEErrorHandleCallback)(const char *remoteAddress,
362 * Set the client error handler callback.
364 * @param[in] callback Callback function to update error to the
367 void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback);
371 * Set the server error handler callback.
373 * @param[in] callback Callback function to update error to the
376 void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback);
382 #endif /* CA_LE_INTERFACE_H_ */