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 contains the APIs for LE adapters to be implemented.
27 #ifndef CA_LEADAPTER_H_
28 #define CA_LEADAPTER_H_
31 #include "caadapterinterface.h"
32 #include "cathreadpool.h" /* for thread pool */
44 * @brief Stores the information of the Data to be sent from the queues.
45 * This structure will be pushed to the sender/receiver queue for processing.
50 *remoteEndpoint; /**< Remote endpoint contains the inforamtion of remote device */
51 void *data; /**< Data to be transmitted over LE tranport */
52 uint32_t dataLen; /**< Length of the data being transmitted */
56 * @brief Initialize LE connectivity interface.
57 * @param registerCallback [IN] Callback to register LE interfaces to Connectivity
59 * @param reqRespCallback [IN] Callback to notify request and response messages from server(s)
60 * started at Connectivity Abstraction Layer.
61 * @param netCallback [IN] Callback to notify the network additions to Connectivity
63 * @param handle [IN] Threadpool Handle
64 * @return #CA_STATUS_OK or Appropriate error code
66 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
67 CANetworkPacketReceivedCallback reqRespCallback,
68 CANetworkChangeCallback netCallback,
69 ca_thread_pool_t handle);
72 * @brief Starting LE connectivity adapters.
73 * As its peer to peer it doesnot require to start any servers
74 * @return #CA_STATUS_OK or Appropriate error code
76 CAResult_t CAStartLE();
79 * @brief Starting listening server for receiving multicast search requests
80 * Transport Specific Behavior:
81 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
82 * @return #CA_STATUS_OK or Appropriate error code
84 CAResult_t CAStartLEListeningServer();
87 * @brief for starting discovery servers for receiving multicast advertisements
88 * Transport Specific Behavior:
89 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
90 * @return #CA_STATUS_OK or Appropriate error code
92 CAResult_t CAStartLEDiscoveryServer();
95 * @brief Sends data to the endpoint using the adapter connectivity.
96 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
97 * and connectivity type) to which the unicast data has to be sent.
98 * @param data [IN] Data which required to be sent.
99 * @param dataLen [IN] Size of data to be sent.
100 * @return The number of bytes sent on the network. Returns -1 on error.
101 * @remarks dataLen must be > 0.
103 int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data,
107 * @brief Sends Multicast data to the endpoint using the LE connectivity.
108 * @param endpoint [IN] Remote Endpoint information to which the unicast data has to be sent.
109 * @param data [IN] Data which required to be sent.
110 * @param dataLen [IN] Size of data to be sent.
111 * @return The number of bytes sent on the network. Returns -1 on error.
112 * @remarks dataLen must be > 0.
114 int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
117 * @brief Starts notification server on EDR adapters.
118 * @return #CA_STATUS_OK or Appropriate error code
120 CAResult_t CAStartLENotifyServer();
123 * @brief Send notification information.
124 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
125 * and connectivity type) to which the unicast data has to be sent.
126 * @param data [IN] Data which required to be sent.
127 * @param dataLen [IN] Size of data to be sent.
128 * @return The number of bytes sent on the network. Returns 0 on error.
129 * @remarks dataLen must be > 0.
131 uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
135 * @brief Get LE Connectivity network information
136 * @param info [OUT] Local connectivity information structures
137 * @param size [OUT] Number of local connectivity structures.
138 * @return #CA_STATUS_OK or Appropriate error code
140 CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
143 * @brief Read Synchronous API callback.
144 * @return #CA_STATUS_OK or Appropriate error code
146 CAResult_t CAReadLEData();
149 * @brief Stopping the adapters and close socket connections
150 * LE Stops all GATT servers and GATT Clients.
151 * @return #CA_STATUS_OK or Appropriate error code
153 CAResult_t CAStopLE();
156 * @brief Terminate the LE connectivity adapter.
157 * Configuration information will be deleted from further use
159 void CATerminateLE();
162 * @brief This function will receive the data from the GattServer and add the data to
163 * the Server receiver queue.
164 * @param remoteAddress [IN] Remote address of the device from where data is received.
165 * @param serviceUUID [IN] Uuid of the OIC service running on the remote device
166 * @param data [IN] Actual data recevied from the remote device.
167 * @param dataLength [IN] Length of the data received from the remote device.
168 * @param sentLength [IN] Length of the data sent from the remote device.
169 * @return #CA_STATUS_OK or Appropriate error code
170 * @retval #CA_STATUS_OK Successful
171 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
172 * @retval #CA_STATUS_FAILED Operation failed
175 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
176 const void *data, uint32_t dataLength, uint32_t *sentLength);
179 * @brief This function will receive the data from the GattClient and add the data into the
180 * Client receiver queue.
181 * @param remoteAddress [IN] Remote address of the device from where data is received.
182 * @param serviceUUID [IN] Uuid of the OIC service running on the remote device
183 * @param data [IN] Actual data recevied from the remote device.
184 * @param dataLength [IN] Length of the data received from the remote device.
185 * @param sentLength [IN] Length of the data sent from the remote device.
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 CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
192 const void *data, uint32_t dataLength, uint32_t *sentLength);
195 * @brief This function is used to set the NetworkPacket received callback to CA layer from
197 * @param callback [IN] callback handle sent from the upper layer.
200 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
203 * @brief This function will push the data from CA layer to the Sender processor queue.
205 * @param remoteEndpoint [IN] Remote endpoint information of the server.
206 * @param data [IN] Data to be transmitted from LE.
207 * @param dataLen [IN] length of the Data being transmitted.
209 * @return #CA_STATUS_OK or Appropriate error code
210 * @retval #CA_STATUS_OK Successful
211 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
212 * @retval #CA_STATUS_FAILED Operation failed
214 CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
215 const void *data, uint32_t dataLen);
218 * @brief This function will push the data from CA layer to the Sender processor queue.
220 * @param remoteEndpoint [IN] Remote endpoint information of the server.
221 * @param data [IN] Data to be transmitted from LE.
222 * @param dataLen [IN] length of the Data being transmitted.
224 * @return #CA_STATUS_OK or Appropriate error code
225 * @retval #CA_STATUS_OK Successful
226 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
227 * @retval #CA_STATUS_FAILED Operation failed
229 CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
230 const void *data, uint32_t dataLen);
233 * @brief This function will be associated with the sender queue for GattServer.This function will
234 * fragment the data to the MTU of the transport and send the data in fragments to the
235 * adapters. The function will be blocked untill all data is sent out from the adapter.
237 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
242 void CABLEServerSendDataThread(void *threadData);
245 * @brief This function will be associated with the sender queue for GattClient.This function will
246 * fragment the data to the MTU of the transport and send the data in fragments to the
247 * adapters. The function will be blocked untill all data is sent out from the adapter.
249 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
254 void CABLEClientSendDataThread(void *threadData);
257 * @brief This function will be associated with the receiver queue of GattServer. This function
258 * will defragment the data received and will send the data UP to the CA layer only after
259 * it collects all the data from the adapter layer. Adapter Header will provide the
260 * length of the data sent from the server.
262 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
267 void CABLEServerDataReceiverHandler(void *threadData);
270 * @brief This function will be associated with the receiver queue of GattClient. This function
271 * will defragment the data received and will send the data UP to the CA layer only after
272 * it collects all the data from the adapter layer. Adapter Header will provide the length
273 * of the data sent from the server.
275 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
279 void CABLEClientDataReceiverHandler(void *threadData);
282 * @brief This function is used to Initalize both GattServer and GattClient queues. All four
283 * queues will be initialized with this function invocations.
286 void CAInitBleQueues();
289 * @brief This function will stop all queues created for GattServer and GattClient. All
290 * four queues will be be stopped with this function invocations.
293 void CAStopBleQueues();
296 * @brief This function will terminate all queues created for GattServer and GattClient. All
297 * four queues will be be terminated with this function invocations.
300 void CATerminateBleQueues();
303 * @brief This function will initalize the Receiver and Sender queues for GattServer. This
304 * function will inturn call the functions CAInitBleServerReceiverQueue() and
305 * CAInitBleServerSenderQueue() to initialize the queues.
306 * @return #CA_STATUS_OK or Appropriate error code
307 * @retval #CA_STATUS_OK Successful
308 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
309 * @retval #CA_STATUS_FAILED Operation failed
311 CAResult_t CAInitBleServerQueues();
314 * @brief This function will initalize the Receiver and Sender queues for GattClient. This
315 * function will inturn call the functions CAInitBleClientReceiverQueue() and
316 * CAInitBleClientSenderQueue() to initialize the queues.
318 * @return #CA_STATUS_OK or Appropriate error code
319 * @retval #CA_STATUS_OK Successful
320 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
321 * @retval #CA_STATUS_FAILED Operation failed
324 CAResult_t CAInitBleClientQueues();
327 * @brief This function will initalize the Receiver queue for GattServer. This will initialize
328 * the queue to process the function CABLEServerSendDataThread() when ever the task is
329 * added to this queue.
331 * @return #CA_STATUS_OK or Appropriate error code
332 * @retval #CA_STATUS_OK Successful
333 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
334 * @retval #CA_STATUS_FAILED Operation failed
336 CAResult_t CAInitBleServerSenderQueue();
339 * @brief This function will initalize the Receiver queue for GattClient. This will initialize
340 * the queue to process the function CABLEClientSendDataThread() when ever the task is
341 * added to this queue.
343 * @return #CA_STATUS_OK or Appropriate error code
344 * @retval #CA_STATUS_OK Successful
345 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
346 * @retval #CA_STATUS_FAILED Operation failed
348 CAResult_t CAInitBleClientSenderQueue();
351 * @brief This function will initalize the Receiver queue for GattServer. This will initialize
352 * the queue to process the function CABLEServerDataReceiverHandler() when ever the task
353 * is added to this queue.
355 * @return #CA_STATUS_OK or Appropriate error code
356 * @retval #CA_STATUS_OK Successful
357 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
358 * @retval #CA_STATUS_FAILED Operation failed
361 CAResult_t CAInitBleServerReceiverQueue();
364 * @brief This function will initalize the Receiver queue for GattClient. This will initialize
365 * the queue to process the function CABLEClientDataReceiverHandler() when ever the task
366 * is added to this queue.
368 * @return #CA_STATUS_OK or Appropriate error code
369 * @retval #CA_STATUS_OK Successful
370 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
371 * @retval #CA_STATUS_FAILED Operation failed
373 CAResult_t CAInitBleClientReceiverQueue();
376 * @brief This function will create the Data required to send it in the queue.
378 * @param remoteEndpoint [IN] Remote endpoint information of the server.
379 * @param data [IN] Data to be transmitted from LE.
380 * @param dataLength [IN] length of the Data being transmitted.
382 * @return #CA_STATUS_OK or Appropriate error code
383 * @retval #CA_STATUS_OK Successful
384 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
385 * @retval #CA_STATUS_FAILED Operation failed
387 CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
388 uint32_t dataLength);
391 * @brief Used to free the BLE information stored in the sender/receiver queues.
392 * @param bleData [IN] Structure contains the information of a particular data segment.
395 void CAFreeBLEData(CALEData_t *bleData);
398 * @brief This will be used to notify device status changes to the LE adapter layer
399 * @param adapter_state [IN] State of the adapter
402 typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
405 * @brief This will be used to notify that network packet recieved from GATTClient to adapter layer.
406 * @param remoteAddress [IN] Remote endpoint Address
407 * @param serviceUUID [IN] Service UUID
408 * @param data [IN] Data received
409 * @param dataLength [IN] Length of the data received
410 * @param sentLength [IN] Length of the data sent
411 * @return #CA_STATUS_OK or Appropriate error code
412 * @retval #CA_STATUS_OK Successful
413 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
414 * @retval #CA_STATUS_FAILED Operation failed
416 typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress,
417 const char *serviceUUID, const void *data,
418 uint32_t dataLength, uint32_t *sentLength);
421 * @brief This will be used to notify that network packet recieved from GATTServer to adapter layer.
422 * @param remoteAddress [IN] Remote endpoint Address
423 * @param serviceUUID [IN] Service UUID
424 * @param data [IN] Data received
425 * @param dataLength [IN] Length of the data received
426 * @param sentLength [IN] Length of the data sent
427 * @return #CA_STATUS_OK or Appropriate error code
428 * @retval #CA_STATUS_OK Successful
429 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
430 * @retval #CA_STATUS_FAILED Operation failed
432 typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress,
433 const char *serviceUUID, const void *data,
434 uint32_t dataLength, uint32_t *sentLength);
440 #endif /* CA_LEADAPTER_H_ */