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"
31 #include "uthreadpool.h" /* for thread pool */
43 * @Structure CABLEData
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 */
55 /** @brief Initialize LE connectivity interface.
56 * @param registerCallback [IN] To register LE interfaces to Connectivity Abstraction Layer
57 * @param reqRespCallback [IN] sending responses and discovery messages from unicast , \
59 * @param netCallback [IN] Intimate the network additions to Connectivity Abstraction Layer.
60 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
63 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
64 CANetworkPacketReceivedCallback reqRespCallback,
65 CANetworkChangeCallback netCallback);
67 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
68 CANetworkPacketReceivedCallback reqRespCallback,
69 CANetworkChangeCallback netCallback,
70 u_thread_pool_t handle);
71 #endif //#ifdef ARDUINO
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 ERROR CODES ( CAResult_t error codes in cacommon.h)
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 ERROR CODES ( CAResult_t error codes in cacommon.h)
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 ERROR CODES ( CAResult_t error codes in cacommon.h)
94 CAResult_t CAStartLEDiscoveryServer();
97 * @brief Sends data to the endpoint using the adapter connectivity.
98 * Note: length must be > 0.
99 * @param endpoint [IN] Remote Endpoint information (like ipaddress , port, reference uri \
100 * and connectivity type) to which the unicast data has to be sent.
101 * @param data [IN] Data which required to be sent.
102 * @param dataLen [IN] Size of data to be sent.
103 * @return - The number of bytes sent on the network. Return value equal to zero indicates error.
105 uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data,
109 * @brief Sends Multicast data to the endpoint using the LE connectivity.
110 * Note: length must be > 0.
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. Return value equal to zero indicates error.
115 uint32_t CASendLEMulticastData(void *data, uint32_t dataLen);
118 * @brief Starts notification server on EDR adapters.
119 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
121 CAResult_t CAStartLENotifyServer();
124 * @brief Send notification information.
125 * Note: length must be > 0.
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. Return value equal to zero indicates error.
132 uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data,
136 * @brief Get LE Connectivity network information
137 * @param info [OUT] Local connectivity information structures
138 * @param size [OUT] Number of local connectivity structures.
139 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
141 CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
144 * @brief Read Synchronous API callback.
145 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
147 CAResult_t CAReadLEData();
150 * @brief Stopping the adapters and close socket connections
151 * LE Stops all GATT servers and close sockets.
152 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
154 CAResult_t CAStopLE();
157 * @brief Terminate the LE connectivity adapter.
158 * Configuration information will be deleted from further use
160 void CATerminateLE();
162 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
163 void *data, uint32_t dataLength, uint32_t *sentLength);
165 CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
166 void *data, uint32_t dataLength, uint32_t *sentLength);
168 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
170 CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
171 void *data, uint32_t dataLen);
173 CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
174 void *data, uint32_t dataLen);
176 void CABLEClientSendDataThread(void *threadData);
178 void CABLEClientDataReceiverHandler(void *threadData);
180 void CATerminateBleQueues();
182 CAResult_t CAInitBleClientReceiverQueue();
184 CAResult_t CAInitBleServerReceiverQueue();
186 void CAInitBleQueues();
188 void CATerminateBleQueues();
190 CAResult_t CAInitBleServerQueues();
192 CAResult_t CAInitBleClientQueues();
194 CAResult_t CAInitBleServerSenderQueue();
196 CAResult_t CAInitBleClientSenderQueue();
201 * @fn CABLEDataReceiverHandler
202 * @brief This function handles data from recv message queue.
204 void CABLEServerDataReceiverHandler(void *context);
207 * @fn CABLESendDataThread
208 * @brief This function handles data from sender message queue.
210 void CABLEServerSendDataThread(void *threadData);
213 * @fn CACreateBLEData
214 * @brief This function will create the Data required to send it in the queue.
216 * @param[in] remoteEndpoint Remote endpoint information of the server.
217 * @param[in] data Data to be transmitted from LE.
218 * @param[in] length of the Data being transmitted.
220 * @return 0 on success otherwise a positive error value.
221 * @retval CA_STATUS_OK Successful
222 * @retval CA_STATUS_INVALID_PARAM Invalid input argumets
223 * @retval CA_STATUS_FAILED Operation failed
226 CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
227 uint32_t dataLength);
231 * @brief Used to free the BLE information stored in the sender/receiver queues.
233 * @param[in] bleData Structure contains the information of a particular data segment.
237 void CAFreeBLEData(CABLEData *bleData);
243 #endif //#ifndef _CA_LEADAPTER_H_