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 ******************************************************************/
23 * @brief This file contains the APIs for LE adapters to be implemented
25 #ifndef _CA_LEADAPTER_H_
26 #define _CA_LEADAPTER_H_
29 #include "caadapterinterface.h"
30 #include "uthreadpool.h" /* for thread pool */
42 * @brief Stores the information of the Data to be sent from the queues.
43 * This structure will be pushed to the sender/receiver queue for processing.
48 *remoteEndpoint; /**< Remote endpoint contains the inforamtion of remote device */
49 void *data; /**< Data to be transmitted over LE tranport */
50 uint32_t dataLen; /**< Length of the data being transmitted */
54 * @brief Initialize LE connectivity interface.
55 * @param registerCallback [IN] Callback to register LE interfaces to Connectivity
57 * @param reqRespCallback [IN] Callback to notify request and response messages from server(s)
58 * started at Connectivity Abstraction Layer.
59 * @param netCallback [IN] Callback to intimate the network additions to Connectivity
61 * @param handle [IN] Threadpool Handle
62 * @return #CA_STATUS_OK or Appropriate error code
64 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
65 CANetworkPacketReceivedCallback reqRespCallback,
66 CANetworkChangeCallback netCallback,
67 u_thread_pool_t handle);
70 * @brief Starting LE connectivity adapters.
71 * As its peer to peer it doesnot require to start any servers
72 * @return #CA_STATUS_OK or Appropriate error code
74 CAResult_t CAStartLE();
77 * @brief Starting listening server for receiving multicast search requests
78 * Transport Specific Behavior:
79 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
80 * @return #CA_STATUS_OK or Appropriate error code
82 CAResult_t CAStartLEListeningServer();
85 * @brief for starting discovery servers for receiving multicast advertisements
86 * Transport Specific Behavior:
87 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
88 * @return #CA_STATUS_OK or Appropriate error code
90 CAResult_t CAStartLEDiscoveryServer();
93 * @brief Sends data to the endpoint using the adapter connectivity.
94 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
95 * and connectivity type) to which the unicast data has to be sent.
96 * @param data [IN] Data which required to be sent.
97 * @param dataLen [IN] Size of data to be sent.
98 * @return The number of bytes sent on the network. Returns 0 on error.
99 * @remarks dataLen must be > 0.
101 uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data,
105 * @brief Sends Multicast data to the endpoint using the LE connectivity.
106 * @param data [IN] Data which required to be sent.
107 * @param dataLen [IN] Size of data to be sent.
108 * @return The number of bytes sent on the network. Returns 0 on error.
109 * @remarks dataLen must be > 0.
111 uint32_t CASendLEMulticastData(void *data, uint32_t dataLen);
114 * @brief Starts notification server on EDR adapters.
115 * @return #CA_STATUS_OK or Appropriate error code
117 CAResult_t CAStartLENotifyServer();
120 * @brief Send notification information.
121 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
122 * and connectivity type) to which the unicast data has to be sent.
123 * @param data [IN] Data which required to be sent.
124 * @param dataLen [IN] Size of data to be sent.
125 * @return The number of bytes sent on the network. Returns 0 on error.
126 * @remarks dataLen must be > 0.
128 uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data,
132 * @brief Get LE Connectivity network information
133 * @param info [OUT] Local connectivity information structures
134 * @param size [OUT] Number of local connectivity structures.
135 * @return #CA_STATUS_OK or Appropriate error code
137 CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
140 * @brief Read Synchronous API callback.
141 * @return #CA_STATUS_OK or Appropriate error code
143 CAResult_t CAReadLEData();
146 * @brief Stopping the adapters and close socket connections
147 * LE Stops all GATT servers and GATT Clients.
148 * @return #CA_STATUS_OK or Appropriate error code
150 CAResult_t CAStopLE();
153 * @brief Terminate the LE connectivity adapter.
154 * Configuration information will be deleted from further use
156 void CATerminateLE();
159 * @brief This function will receive the data from the GattServer and add the data to
160 * the Server receiver queue.
161 * @param remoteAddress [IN] Remote address of the device from where data is received.
162 * @param serviceUUID [IN] Uuid of the OIC service running on the remote device
163 * @param data [IN] Actual data recevied from the remote device.
164 * @param dataLength [IN] Length of the data received from the remote device.
165 * @param sentLength [IN] Length of the data sent from the remote device.
166 * @return #CA_STATUS_OK or Appropriate error code
167 * @retval #CA_STATUS_OK Successful
168 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
169 * @retval #CA_STATUS_FAILED Operation failed
172 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
173 void *data, uint32_t dataLength, uint32_t *sentLength);
176 * @brief This function will receive the data from the GattClient and add the data into the
177 * Client receiver queue.
178 * @param remoteAddress [IN] Remote address of the device from where data is received.
179 * @param serviceUUID [IN] Uuid of the OIC service running on the remote device
180 * @param data [IN] Actual data recevied from the remote device.
181 * @param dataLength [IN] Length of the data received from the remote device.
182 * @param sentLength [IN] Length of the data sent from the remote device.
183 * @return #CA_STATUS_OK or Appropriate error code
184 * @retval #CA_STATUS_OK Successful
185 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
186 * @retval #CA_STATUS_FAILED Operation failed
188 CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
189 void *data, uint32_t dataLength, uint32_t *sentLength);
192 * @brief This function is used to set the NetworkPacket received callback to CA layer from
194 * @param callback [IN] callback handle sent from the upper layer.
197 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
200 * @brief This function will push the data from CA layer to the Sender processor queue.
202 * @param remoteEndpoint [IN] Remote endpoint information of the server.
203 * @param data [IN] Data to be transmitted from LE.
204 * @param dataLen [IN] length of the Data being transmitted.
206 * @return #CA_STATUS_OK or Appropriate error code
207 * @retval #CA_STATUS_OK Successful
208 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
209 * @retval #CA_STATUS_FAILED Operation failed
211 CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
212 void *data, uint32_t dataLen);
215 * @brief This function will push the data from CA layer to the Sender processor queue.
217 * @param remoteEndpoint [IN] Remote endpoint information of the server.
218 * @param data [IN] Data to be transmitted from LE.
219 * @param dataLen [IN] length of the Data being transmitted.
221 * @return #CA_STATUS_OK or Appropriate error code
222 * @retval #CA_STATUS_OK Successful
223 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
224 * @retval #CA_STATUS_FAILED Operation failed
226 CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
227 void *data, uint32_t dataLen);
230 * @brief This function will be associated with the sender queue for GattServer.This function will
231 * fragment the data to the MTU of the transport and send the data in fragments to the
232 * adapters. The function will be blocked untill all data is sent out from the adapter.
234 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
239 void CABLEServerSendDataThread(void *threadData);
242 * @brief This function will be associated with the sender queue for GattClient.This function will
243 * fragment the data to the MTU of the transport and send the data in fragments to the
244 * adapters. The function will be blocked untill all data is sent out from the adapter.
246 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
251 void CABLEClientSendDataThread(void *threadData);
254 * @brief This function will be associated with the receiver queue of GattServer. This function
255 * will defragment the data received and will send the data UP to the CA layer only after
256 * it collects all the data from the adapter layer. Adapter Header will provide the
257 * length of the data sent from the server.
259 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
264 void CABLEServerDataReceiverHandler(void *threadData);
267 * @brief This function will be associated with the receiver queue of GattClient. This function
268 * will defragment the data received and will send the data UP to the CA layer only after
269 * it collects all the data from the adapter layer. Adapter Header will provide the length
270 * of the data sent from the server.
272 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
276 void CABLEClientDataReceiverHandler(void *threadData);
279 * @brief This function is used to Initalize both GattServer and GattClient queues. All four
280 * queues will be initialized with this function invocations.
283 void CAInitBleQueues();
286 * @brief This function will stop all queues created for GattServer and GattClient. All
287 * four queues will be be stopped with this function invocations.
290 void CAStopBleQueues();
293 * @brief This function will terminate all queues created for GattServer and GattClient. All
294 * four queues will be be terminated with this function invocations.
297 void CATerminateBleQueues();
300 * @brief This function will initalize the Receiver and Sender queues for GattServer. This
301 * function will inturn call the functions CAInitBleServerReceiverQueue() and
302 * CAInitBleServerSenderQueue() to initialize the queues.
303 * @return #CA_STATUS_OK or Appropriate error code
304 * @retval #CA_STATUS_OK Successful
305 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
306 * @retval #CA_STATUS_FAILED Operation failed
308 CAResult_t CAInitBleServerQueues();
311 * @brief This function will initalize the Receiver and Sender queues for GattClient. This
312 * function will inturn call the functions CAInitBleClientReceiverQueue() and
313 * CAInitBleClientSenderQueue() to initialize the queues.
315 * @return #CA_STATUS_OK or Appropriate error code
316 * @retval #CA_STATUS_OK Successful
317 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
318 * @retval #CA_STATUS_FAILED Operation failed
321 CAResult_t CAInitBleClientQueues();
324 * @brief This function will initalize the Receiver queue for GattServer. This will initlialize
325 * the queue to process the function CABLEServerSendDataThread() when ever the task is
326 * added to this queue.
328 * @return #CA_STATUS_OK or Appropriate error code
329 * @retval #CA_STATUS_OK Successful
330 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
331 * @retval #CA_STATUS_FAILED Operation failed
333 CAResult_t CAInitBleServerSenderQueue();
336 * @brief This function will initalize the Receiver queue for GattClient. This will initlialize
337 * the queue to process the function CABLEClientSendDataThread() when ever the task is
338 * added to this queue.
340 * @return #CA_STATUS_OK or Appropriate error code
341 * @retval #CA_STATUS_OK Successful
342 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
343 * @retval #CA_STATUS_FAILED Operation failed
345 CAResult_t CAInitBleClientSenderQueue();
348 * @brief This function will initalize the Receiver queue for GattServer. This will initlialize
349 * the queue to process the function CABLEServerDataReceiverHandler() when ever the task
350 * is added to this queue.
352 * @return #CA_STATUS_OK or Appropriate error code
353 * @retval #CA_STATUS_OK Successful
354 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
355 * @retval #CA_STATUS_FAILED Operation failed
358 CAResult_t CAInitBleServerReceiverQueue();
361 * @brief This function will initalize the Receiver queue for GattClient. This will initlialize
362 * the queue to process the function CABLEClientDataReceiverHandler() when ever the task
363 * is added to this queue.
365 * @return #CA_STATUS_OK or Appropriate error code
366 * @retval #CA_STATUS_OK Successful
367 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
368 * @retval #CA_STATUS_FAILED Operation failed
370 CAResult_t CAInitBleClientReceiverQueue();
373 * @brief This function will create the Data required to send it in the queue.
375 * @param remoteEndpoint [IN] Remote endpoint information of the server.
376 * @param data [IN] Data to be transmitted from LE.
377 * @param dataLength [IN] length of the Data being transmitted.
379 * @return #CA_STATUS_OK or Appropriate error code
380 * @retval #CA_STATUS_OK Successful
381 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
382 * @retval #CA_STATUS_FAILED Operation failed
384 CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
385 uint32_t dataLength);
388 * @brief Used to free the BLE information stored in the sender/receiver queues.
389 * @param bleData [IN] Structure contains the information of a particular data segment.
392 void CAFreeBLEData(CABLEData *bleData);
395 * @brief This will be used to intimate device status changes to the LE adapter layer
396 * @param adapter_state [IN] State of the adapter
399 typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
402 * @brief This will be used to intimate network packet recieved from GATTClient to adapter layer.
403 * @param remoteAddress [IN] Remote endpoint Address
404 * @param serviceUUID [IN] Service UUID
405 * @param data [IN] Data received
406 * @param dataLength [IN] Length of the data received
407 * @param sentLength [IN] Length of the data sent
408 * @return #CA_STATUS_OK or Appropriate error code
409 * @retval #CA_STATUS_OK Successful
410 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
411 * @retval #CA_STATUS_FAILED Operation failed
413 typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress,
414 const char *serviceUUID, void *data,
415 uint32_t dataLength, uint32_t *sentLength);
418 * @brief This will be used to intimate network packet recieved from GATTServer to adapter layer.
419 * @param remoteAddress [IN] Remote endpoint Address
420 * @param serviceUUID [IN] Service UUID
421 * @param data [IN] Data received
422 * @param dataLength [IN] Length of the data received
423 * @param sentLength [IN] Length of the data sent
424 * @return #CA_STATUS_OK or Appropriate error code
425 * @retval #CA_STATUS_OK Successful
426 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
427 * @retval #CA_STATUS_FAILED Operation failed
429 typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress,
430 const char *serviceUUID, void *data,
431 uint32_t dataLength, uint32_t *sentLength);
437 #endif //#ifndef _CA_LEADAPTER_H_