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 */
41 * @Structure CABLEData
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 */
53 /** @brief Initialize LE connectivity interface.
54 * @param registerCallback [IN] To register LE interfaces to Connectivity Abstraction Layer
55 * @param reqRespCallback [IN] sending responses and discovery messages from unicast , \
57 * @param netCallback [IN] Intimate the network additions to Connectivity Abstraction Layer.
58 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
60 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
61 CANetworkPacketReceivedCallback reqRespCallback,
62 CANetworkChangeCallback netCallback,
63 u_thread_pool_t handle);
66 * @brief Starting LE connectivity adapters . \
67 * As its peer to peer it doesnot require to start any servers
68 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
70 CAResult_t CAStartLE();
73 * @brief Starting listening server for receiving multicast search requests
74 * Transport Specific Behavior:
75 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
76 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
78 CAResult_t CAStartLEListeningServer();
81 * @brief for starting discovery servers for receiving multicast advertisements
82 * Transport Specific Behavior:
83 * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification.
84 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
86 CAResult_t CAStartLEDiscoveryServer();
89 * @brief Sends data to the endpoint using the adapter connectivity.
90 * Note: length must be > 0.
91 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
92 * and connectivity type) to which the unicast data has to be sent.
93 * @param data [IN] Data which required to be sent.
94 * @param dataLen [IN] Size of data to be sent.
95 * @return - The number of bytes sent on the network. Return value equal to zero indicates error.
97 uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data,
101 * @brief Sends Multicast data to the endpoint using the LE connectivity.
102 * Note: length must be > 0.
103 * @param data [IN] Data which required to be sent.
104 * @param dataLen [IN] Size of data to be sent.
105 * @return - The number of bytes sent on the network. Return value equal to zero indicates error.
107 uint32_t CASendLEMulticastData(void *data, uint32_t dataLen);
110 * @brief Starts notification server on EDR adapters.
111 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
113 CAResult_t CAStartLENotifyServer();
116 * @brief Send notification information.
117 * Note: length must be > 0.
118 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
119 * and connectivity type) to which the unicast data has to be sent.
120 * @param data [IN] Data which required to be sent.
121 * @param dataLen [IN] Size of data to be sent.
122 * @return - The number of bytes sent on the network. Return value equal to zero indicates error.
124 uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data,
128 * @brief Get LE Connectivity network information
129 * @param info [OUT] Local connectivity information structures
130 * @param size [OUT] Number of local connectivity structures.
131 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
133 CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
136 * @brief Read Synchronous API callback.
137 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
139 CAResult_t CAReadLEData();
142 * @brief Stopping the adapters and close socket connections
143 * LE Stops all GATT servers and close sockets.
144 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
146 CAResult_t CAStopLE();
149 * @brief Terminate the LE connectivity adapter.
150 * Configuration information will be deleted from further use
152 void CATerminateLE();
154 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
155 void *data, uint32_t dataLength, uint32_t *sentLength);
157 CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
158 void *data, uint32_t dataLength, uint32_t *sentLength);
160 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
162 CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
163 void *data, uint32_t dataLen);
165 CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
166 void *data, uint32_t dataLen);
168 void CABLEClientSendDataThread(void *threadData);
170 void CABLEClientDataReceiverHandler(void *threadData);
172 void CATerminateBleQueues();
174 CAResult_t CAInitBleClientReceiverQueue();
176 CAResult_t CAInitBleServerReceiverQueue();
178 void CAInitBleQueues();
180 void CATerminateBleQueues();
182 CAResult_t CAInitBleServerQueues();
184 CAResult_t CAInitBleClientQueues();
186 CAResult_t CAInitBleServerSenderQueue();
188 CAResult_t CAInitBleClientSenderQueue();
193 * @fn CABLEDataReceiverHandler
194 * @brief This function handles data from recv message queue.
196 void CABLEServerDataReceiverHandler(void *context);
199 * @fn CABLESendDataThread
200 * @brief This function handles data from sender message queue.
202 void CABLEServerSendDataThread(void *threadData);
205 * @fn CACreateBLEData
206 * @brief This function will create the Data required to send it in the queue.
208 * @param[in] remoteEndpoint Remote endpoint information of the server.
209 * @param[in] data Data to be transmitted from LE.
210 * @param[in] length of the Data being transmitted.
212 * @return 0 on success otherwise a positive error value.
213 * @retval CA_STATUS_OK Successful
214 * @retval CA_STATUS_INVALID_PARAM Invalid input argumets
215 * @retval CA_STATUS_FAILED Operation failed
218 CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
219 uint32_t dataLength);
223 * @brief Used to free the BLE information stored in the sender/receiver queues.
225 * @param[in] bleData Structure contains the information of a particular data segment.
229 void CAFreeBLEData(CABLEData *bleData);
235 #endif //#ifndef _CA_LEADAPTER_H_