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 errorCallback [IN] errorCallback to notify error to connectivity common logic
65 * @param handle [IN] Threadpool Handle
66 * @return #CA_STATUS_OK or Appropriate error code
68 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
69 CANetworkPacketReceivedCallback reqRespCallback,
70 CANetworkChangeCallback netCallback,
71 CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
74 * @brief Starting LE connectivity adapters.
75 * As its peer to peer it doesnot require to start any servers
76 * @return #CA_STATUS_OK or Appropriate error code
78 CAResult_t CAStartLE();
81 * @brief Starting listening server for receiving multicast search requests
82 * Transport Specific Behavior:
83 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
84 * @return #CA_STATUS_OK or Appropriate error code
86 CAResult_t CAStartLEListeningServer();
89 * @brief for starting discovery servers for receiving multicast advertisements
90 * Transport Specific Behavior:
91 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
92 * @return #CA_STATUS_OK or Appropriate error code
94 CAResult_t CAStartLEDiscoveryServer();
97 * @brief Sends data to the endpoint using the adapter connectivity.
98 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
99 * and connectivity type) to which the unicast data has to be sent.
100 * @param data [IN] Data which required to be sent.
101 * @param dataLen [IN] Size of data to be sent.
102 * @return The number of bytes sent on the network. Returns -1 on error.
103 * @remarks dataLen must be > 0.
105 int32_t CASendLEUnicastData(const CAEndpoint_t *endpoint, const void *data,
109 * @brief Sends Multicast data to the endpoint using the LE connectivity.
110 * @param endpoint [IN] Remote Endpoint information to which the unicast data has to be sent.
111 * @param data [IN] Data which required to be sent.
112 * @param dataLen [IN] Size of data to be sent.
113 * @return The number of bytes sent on the network. Returns -1 on error.
114 * @remarks dataLen must be > 0.
116 int32_t CASendLEMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen);
119 * @brief Starts notification server on EDR adapters.
120 * @return #CA_STATUS_OK or Appropriate error code
122 CAResult_t CAStartLENotifyServer();
125 * @brief Send notification information.
126 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
127 * and connectivity type) to which the unicast data has to be sent.
128 * @param data [IN] Data which required to be sent.
129 * @param dataLen [IN] Size of data to be sent.
130 * @return The number of bytes sent on the network. Returns 0 on error.
131 * @remarks dataLen must be > 0.
133 uint32_t CASendLENotification(const CAEndpoint_t *endpoint, const void *data,
137 * @brief Get LE Connectivity network information
138 * @param info [OUT] Local connectivity information structures
139 * @param size [OUT] Number of local connectivity structures.
140 * @return #CA_STATUS_OK or Appropriate error code
142 CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
145 * @brief Read Synchronous API callback.
146 * @return #CA_STATUS_OK or Appropriate error code
148 CAResult_t CAReadLEData();
151 * @brief Stopping the adapters and close socket connections
152 * LE Stops all GATT servers and GATT Clients.
153 * @return #CA_STATUS_OK or Appropriate error code
155 CAResult_t CAStopLE();
158 * @brief Terminate the LE connectivity adapter.
159 * Configuration information will be deleted from further use
161 void CATerminateLE();
164 * @brief This function will receive the data from the GattServer and add the data to
165 * the Server receiver queue.
166 * @param remoteAddress [IN] Remote address of the device from where data is received.
167 * @param serviceUUID [IN] Uuid of the OIC service running on the remote device
168 * @param data [IN] Actual data recevied from the remote device.
169 * @param dataLength [IN] Length of the data received from the remote device.
170 * @param sentLength [IN] Length of the data sent from the remote device.
171 * @return #CA_STATUS_OK or Appropriate error code
172 * @retval #CA_STATUS_OK Successful
173 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
174 * @retval #CA_STATUS_FAILED Operation failed
177 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
178 const void *data, uint32_t dataLength, uint32_t *sentLength);
181 * @brief This function will receive the data from the GattClient and add the data into the
182 * Client receiver queue.
183 * @param remoteAddress [IN] Remote address of the device from where data is received.
184 * @param serviceUUID [IN] Uuid of the OIC service running on the remote device
185 * @param data [IN] Actual data recevied from the remote device.
186 * @param dataLength [IN] Length of the data received from the remote device.
187 * @param sentLength [IN] Length of the data sent from the remote device.
188 * @return #CA_STATUS_OK or Appropriate error code
189 * @retval #CA_STATUS_OK Successful
190 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
191 * @retval #CA_STATUS_FAILED Operation failed
193 CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
194 const void *data, uint32_t dataLength, uint32_t *sentLength);
197 * @brief This function is used to set the NetworkPacket received callback to CA layer from
199 * @param callback [IN] callback handle sent from the upper layer.
202 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
205 * @brief This function will push the data from CA layer to the Sender processor queue.
207 * @param remoteEndpoint [IN] Remote endpoint information of the server.
208 * @param data [IN] Data to be transmitted from LE.
209 * @param dataLen [IN] length of the Data being transmitted.
211 * @return #CA_STATUS_OK or Appropriate error code
212 * @retval #CA_STATUS_OK Successful
213 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
214 * @retval #CA_STATUS_FAILED Operation failed
216 CAResult_t CABLEServerSendData(const CAEndpoint_t *remoteEndpoint,
217 const void *data, uint32_t dataLen);
220 * @brief This function will push the data from CA layer to the Sender processor queue.
222 * @param remoteEndpoint [IN] Remote endpoint information of the server.
223 * @param data [IN] Data to be transmitted from LE.
224 * @param dataLen [IN] length of the Data being transmitted.
226 * @return #CA_STATUS_OK or Appropriate error code
227 * @retval #CA_STATUS_OK Successful
228 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
229 * @retval #CA_STATUS_FAILED Operation failed
231 CAResult_t CABLEClientSendData(const CAEndpoint_t *remoteEndpoint,
232 const void *data, uint32_t dataLen);
235 * @brief This function will be associated with the sender queue for GattServer.This function will
236 * fragment the data to the MTU of the transport and send the data in fragments to the
237 * adapters. The function will be blocked untill all data is sent out from the adapter.
239 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
244 void CABLEServerSendDataThread(void *threadData);
247 * @brief This function will be associated with the sender queue for GattClient.This function will
248 * fragment the data to the MTU of the transport and send the data in fragments to the
249 * adapters. The function will be blocked untill all data is sent out from the adapter.
251 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
256 void CABLEClientSendDataThread(void *threadData);
259 * @brief This function will be associated with the receiver queue of GattServer. This function
260 * will defragment the data received and will send the data UP to the CA layer only after
261 * it collects all the data from the adapter layer. Adapter Header will provide the
262 * length of the data sent from the server.
264 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
269 void CABLEServerDataReceiverHandler(void *threadData);
272 * @brief This function will be associated with the receiver queue of GattClient. This function
273 * will defragment the data received and will send the data UP to the CA layer only after
274 * it collects all the data from the adapter layer. Adapter Header will provide the length
275 * of the data sent from the server.
277 * @param threadData [IN] Data pushed to the queue which contains the info about RemoteEndpoint
281 void CABLEClientDataReceiverHandler(void *threadData);
284 * @brief This function is used to Initalize both GattServer and GattClient queues. All four
285 * queues will be initialized with this function invocations.
288 void CAInitBleQueues();
291 * @brief This function will stop all queues created for GattServer and GattClient. All
292 * four queues will be be stopped with this function invocations.
295 void CAStopBleQueues();
298 * @brief This function will terminate all queues created for GattServer and GattClient. All
299 * four queues will be be terminated with this function invocations.
302 void CATerminateBleQueues();
305 * @brief This function will initalize the Receiver and Sender queues for GattServer. This
306 * function will inturn call the functions CAInitBleServerReceiverQueue() and
307 * CAInitBleServerSenderQueue() to initialize the queues.
308 * @return #CA_STATUS_OK or Appropriate error code
309 * @retval #CA_STATUS_OK Successful
310 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
311 * @retval #CA_STATUS_FAILED Operation failed
313 CAResult_t CAInitBleServerQueues();
316 * @brief This function will initalize the Receiver and Sender queues for GattClient. This
317 * function will inturn call the functions CAInitBleClientReceiverQueue() and
318 * CAInitBleClientSenderQueue() to initialize the queues.
320 * @return #CA_STATUS_OK or Appropriate error code
321 * @retval #CA_STATUS_OK Successful
322 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
323 * @retval #CA_STATUS_FAILED Operation failed
326 CAResult_t CAInitBleClientQueues();
329 * @brief This function will initalize the Receiver queue for GattServer. This will initialize
330 * the queue to process the function CABLEServerSendDataThread() when ever the task is
331 * added to this queue.
333 * @return #CA_STATUS_OK or Appropriate error code
334 * @retval #CA_STATUS_OK Successful
335 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
336 * @retval #CA_STATUS_FAILED Operation failed
338 CAResult_t CAInitBleServerSenderQueue();
341 * @brief This function will initalize the Receiver queue for GattClient. This will initialize
342 * the queue to process the function CABLEClientSendDataThread() when ever the task is
343 * added to this queue.
345 * @return #CA_STATUS_OK or Appropriate error code
346 * @retval #CA_STATUS_OK Successful
347 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
348 * @retval #CA_STATUS_FAILED Operation failed
350 CAResult_t CAInitBleClientSenderQueue();
353 * @brief This function will initalize the Receiver queue for GattServer. This will initialize
354 * the queue to process the function CABLEServerDataReceiverHandler() when ever the task
355 * is added to this queue.
357 * @return #CA_STATUS_OK or Appropriate error code
358 * @retval #CA_STATUS_OK Successful
359 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
360 * @retval #CA_STATUS_FAILED Operation failed
363 CAResult_t CAInitBleServerReceiverQueue();
366 * @brief This function will initalize the Receiver queue for GattClient. This will initialize
367 * the queue to process the function CABLEClientDataReceiverHandler() when ever the task
368 * is added to this queue.
370 * @return #CA_STATUS_OK or Appropriate error code
371 * @retval #CA_STATUS_OK Successful
372 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
373 * @retval #CA_STATUS_FAILED Operation failed
375 CAResult_t CAInitBleClientReceiverQueue();
378 * @brief This function will create the Data required to send it in the queue.
380 * @param remoteEndpoint [IN] Remote endpoint information of the server.
381 * @param data [IN] Data to be transmitted from LE.
382 * @param dataLength [IN] length of the Data being transmitted.
384 * @return #CA_STATUS_OK or Appropriate error code
385 * @retval #CA_STATUS_OK Successful
386 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
387 * @retval #CA_STATUS_FAILED Operation failed
389 CALEData_t *CACreateBLEData(const CAEndpoint_t *remoteEndpoint, const void *data,
390 uint32_t dataLength);
393 * @brief Used to free the BLE information stored in the sender/receiver queues.
394 * @param bleData [IN] Structure contains the information of a particular data segment.
397 void CAFreeBLEData(CALEData_t *bleData);
400 * @brief This will be used to notify device status changes to the LE adapter layer
401 * @param adapter_state [IN] State of the adapter
404 typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state);
407 * @brief This will be used to notify that network packet recieved from GATTClient to adapter layer.
408 * @param remoteAddress [IN] Remote endpoint Address
409 * @param serviceUUID [IN] Service UUID
410 * @param data [IN] Data received
411 * @param dataLength [IN] Length of the data received
412 * @param sentLength [IN] Length of the data sent
413 * @return #CA_STATUS_OK or Appropriate error code
414 * @retval #CA_STATUS_OK Successful
415 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
416 * @retval #CA_STATUS_FAILED Operation failed
418 typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress,
419 const char *serviceUUID, const void *data,
420 uint32_t dataLength, uint32_t *sentLength);
423 * @brief This will be used to notify that network packet recieved from GATTServer to adapter layer.
424 * @param remoteAddress [IN] Remote endpoint Address
425 * @param serviceUUID [IN] Service UUID
426 * @param data [IN] Data received
427 * @param dataLength [IN] Length of the data received
428 * @param sentLength [IN] Length of the data sent
429 * @return #CA_STATUS_OK or Appropriate error code
430 * @retval #CA_STATUS_OK Successful
431 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
432 * @retval #CA_STATUS_FAILED Operation failed
434 typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress,
435 const char *serviceUUID, const void *data,
436 uint32_t dataLength, uint32_t *sentLength);
442 #endif /* CA_LEADAPTER_H_ */