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 * @enum CALETransferType_t
42 * @brief Provide info about different mode of data transfer
43 * This enum is used to differentiate between unicast and multicast data transfer.
47 LE_MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */
48 LE_UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */
53 * @brief Initialize the LE adapter layer. This will be invoked from the CA layer.
55 * @return #CA_STATUS_OK or Appropriate error code
56 * @retval #CA_STATUS_OK Successful
57 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
58 * @retval #CA_STATUS_FAILED Operation failed
60 CAResult_t CAInitializeLEAdapter();
63 * @brief Used to get the current state of the LE adapter.
65 * @return #CA_STATUS_OK or Appropriate error code
66 * @retval #CA_STATUS_OK Successful
67 * @retval #CA_ADAPTER_NOT_ENABLED adapter not enabled
68 * @retval #CA_STATUS_FAILED Operation failed
70 CAResult_t CAGetLEAdapterState();
73 * @brief Used to initialize the network monitor layer of the LE adapter. Mutex variables required
74 * to operate in this layer and other paramters can be initialized in this function.
76 * @return #CA_STATUS_OK or Appropriate error code
77 * @retval #CA_STATUS_OK Successful
78 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
79 * @retval #CA_STATUS_FAILED Operation failed
81 CAResult_t CAInitializeLENetworkMonitor();
84 * @brief Used to terminate the network monitor layer of the LE adapter. The variables intialized
85 * in CAInitializeLEAdapterController() must be cleared in this function.
88 void CATerminateLENetworkMonitor();
91 * @brief This function is used to set the callback for the Device state changes in the adapter.
93 * @param callback [IN] Callback to notify the Device state change to the CA Layer
95 * @return #CA_STATUS_OK or Appropriate error code
96 * @retval #CA_STATUS_OK Successful
97 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
98 * @retval #CA_STATUS_FAILED Operation failed
100 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
103 * @brief Used to initilaze all the mutex variables required to operate the LE network monitor
105 * @return #CA_STATUS_OK or Appropriate error code
106 * @retval #CA_STATUS_OK Successful
107 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
108 * @retval #CA_STATUS_FAILED Operation failed
110 CAResult_t CAInitLENetworkMonitorMutexVariables();
113 * @brief Used to terminate all the mutex variables required to operate the LE network monitor
117 void CATerminateLENetworkMonitorMutexVariables();
120 * @brief Provides the BD address of the local adapter.
121 * @param local_address [OUT] pointer to the location where bd address needs to be stored.
123 * @return #CA_STATUS_OK or Appropriate error code
124 * @retval #CA_STATUS_OK Successful
125 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
126 * @retval #CA_STATUS_FAILED Operation failed
128 CAResult_t CAGetLEAddress(char **local_address);
131 * @brief Used to start Gatt Server thread for service creation and advertise ble service.
133 * @return #CA_STATUS_OK or Appropriate error code
134 * @retval #CA_STATUS_OK Successful
135 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
136 * @retval #CA_STATUS_FAILED Operation failed
138 CAResult_t CAStartBleGattServer();
141 * @brief Used to stop BLE Gatt Service.
143 * @return #CA_STATUS_OK or Appropriate error code
144 * @retval #CA_STATUS_OK Successful
145 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
146 * @retval #CA_STATUS_FAILED Operation failed
148 CAResult_t CAStopBleGattServer();
151 * @brief Used to stop Gatt Server thread and remove service registration, stop advertising.
154 void CATerminateBleGattServer();
157 * @brief Used to store upper layer callback locally which will be used to send the data to
159 * @param callback [IN] Callback function to pass the data to CA layer.
162 void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
165 * @brief Used to update characteristics(Read/Write) value that we want to send to particular
168 * @param address [IN] BD address of Gatt client
169 * @param charValue [IN] Data that we want to send to client(unicast)
170 * @param charValueLen [IN] Length of the data.
172 * @return #CA_STATUS_OK or Appropriate error code
173 * @retval #CA_STATUS_OK Successful
174 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
175 * @retval #CA_STATUS_FAILED Operation failed
177 CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *charValue,
178 const uint32_t charValueLen);
181 * @brief Used to update characteristics(Read/Write) value that we want to multicast to all clients
183 * @param charValue [IN] Data that we want to send to clients(multicast)
184 * @param charValueLen [IN] Length of the data.
186 * @return #CA_STATUS_OK or Appropriate error code
187 * @retval #CA_STATUS_OK Successful
188 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
189 * @retval #CA_STATUS_FAILED Operation failed
191 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
192 const uint32_t charValueLen);
195 * @brief Used to start CAStartBleGattClientThread for initializing Gatt Client
197 * @return #CA_STATUS_OK or Appropriate error code
198 * @retval #CA_STATUS_OK Successful
199 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
200 * @retval #CA_STATUS_FAILED Operation failed
202 CAResult_t CAStartBLEGattClient();
205 * @brief Used to stop Gatt Client gracefully in turn it will call CATerminateBLEGattClient
207 * @return #CA_STATUS_OK or Appropriate error code
208 * @retval #CA_STATUS_OK Successful
209 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
210 * @retval #CA_STATUS_FAILED Operation failed
212 void CAStopBLEGattClient();
215 * @brief Used to unset all the callbacks and stop service discovery
218 void CATerminateBLEGattClient();
221 * @brief Sets the value of characteristic and update the value to GATTServer(unicast).
223 * @param remoteAddress [IN] The address of the remote device
224 * @param data [IN] The value of characteristic (byte array)
225 * @param dataLen [IN] The length of value
226 * @param type [IN] Type of the transfer(#CALETransferType_t)
227 * @param position [IN] The unique index of each ble server. Used for multicast feature.
229 * @return #CA_STATUS_OK or Appropriate error code
230 * @retval #CA_STATUS_OK Successful
231 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
232 * @retval #CA_STATUS_FAILED Operation failed
234 CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char *data,
235 const uint32_t dataLen, CALETransferType_t type,
236 const int32_t position);
239 * @brief Sets the value of characteristic and update the value to all registered
240 * GATTServer -> Multicast
241 * @param data [IN] The value of characteristic (byte array)
242 * @param dataLen [IN] The length of value
244 * @return #CA_STATUS_OK or Appropriate error code
245 * @retval #CA_STATUS_OK Successful
246 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
247 * @retval #CA_STATUS_FAILED Operation failed
249 CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, uint32_t dataLen);
252 * @brief Used to store upper layer callback locally which will be used to send the data to
254 * @param callback [IN] Callback function to pass the data to CA layer.
258 void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
261 * @brief Used to Set the gThreadPool handle which is required for spawning new thread.
263 * @param handle [IN] Thread pool handle which is given by above layer for using thread
265 * @return #CA_STATUS_OK or Appropriate error code
266 * @retval #CA_STATUS_OK Successful
267 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
268 * @retval #CA_STATUS_FAILED Operation failed
270 void CASetBleServerThreadPoolHandle(ca_thread_pool_t handle);
273 * @brief Used to Set the gThreadPool handle which is required for spawning new thread.
274 * @param handle [IN] Thread pool handle which is given by above layer for using thread creation
278 void CASetBleClientThreadPoolHandle(ca_thread_pool_t handle);
281 * @brief Used to unset the callback of adapter connection state change.
283 * @return #CA_STATUS_OK or Appropriate error code
284 * @retval #CA_STATUS_OK Successful
285 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
286 * @retval #CA_STATUS_FAILED Operation failed
288 CAResult_t CAUnSetLEAdapterStateChangedCb();
291 * @brief This will be used to notify errors in BLE adapter
292 * @param remoteAddress [IN] Remote endpoint Address
293 * @param serviceUUID [IN] Service UUID
294 * @param data [IN] Data received
295 * @param dataLength [IN] Length of the data received
296 * @param result [IN] error code as per CAResult_t
299 typedef void (*CABLEErrorHandleCallback)(const char *remoteAddress, const void *data,
300 uint32_t dataLength, CAResult_t result);
302 * @brief sets the error handle callback
303 * @param callback [IN] Callback function to update error to the adapter
306 void CASetBLEClientErrorHandleCallback(CABLEErrorHandleCallback callback);
310 * @brief sets the error handle callback
311 * @param callback [IN] Callback function to update error to the adapter
314 void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback);
320 #endif /* CA_LE_INTERFACE_H_ */