Merge "Fix compiler warnings" into connectivity-abstraction
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caleadapter.h
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file caleadapter.h
23  * @brief This file contains the APIs for LE adapters to be implemented
24  */
25 #ifndef _CA_LEADAPTER_H_
26 #define _CA_LEADAPTER_H_
27
28 #include "cacommon.h"
29 #include "caadapterinterface.h"
30 #ifndef ARDUINO
31 #include "uthreadpool.h" /* for thread pool */
32 #endif  //ARDUINO
33
34 /**
35  * BLE Interface APIs.
36  */
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41
42 /**
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.
46  */
47 typedef struct
48 {
49     CARemoteEndpoint_t
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 */
53 } CABLEData;
54
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 , \
58  *                                             multicast servers
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)
61  */
62 #ifdef ARDUINO
63 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
64                           CANetworkPacketReceivedCallback reqRespCallback,
65                           CANetworkChangeCallback netCallback);
66 #else
67 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
68                           CANetworkPacketReceivedCallback reqRespCallback,
69                           CANetworkChangeCallback netCallback,
70                           u_thread_pool_t handle);
71 #endif //#ifdef ARDUINO
72
73 /**
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)
77  */
78 CAResult_t CAStartLE();
79
80 /**
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)
85  */
86 CAResult_t CAStartLEListeningServer();
87
88 /**
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)
93  */
94 CAResult_t CAStartLEDiscoveryServer();
95
96 /**
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.
104  */
105 uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data,
106                              uint32_t dataLen);
107
108 /**
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.
114  */
115 uint32_t CASendLEMulticastData(void *data, uint32_t dataLen);
116
117 /**
118  * @brief Starts notification server on EDR adapters.
119  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
120  */
121 CAResult_t CAStartLENotifyServer();
122
123 /**
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.
131  */
132 uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data,
133                               uint32_t dataLen);
134
135 /**
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)
140  */
141 CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
142
143 /**
144  * @brief Read Synchronous API callback.
145  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
146  */
147 CAResult_t CAReadLEData();
148
149 /**
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)
153  */
154 CAResult_t CAStopLE();
155
156 /**
157  * @brief Terminate the LE connectivity adapter.
158  * Configuration information will be deleted from further use
159  */
160 void CATerminateLE();
161
162 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
163                                         void *data, uint32_t dataLength, uint32_t *sentLength);
164
165 CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
166                                         void *data, uint32_t dataLength, uint32_t *sentLength);
167
168 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
169
170 CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
171         void *data, uint32_t dataLen);
172
173 CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
174         void *data,  uint32_t dataLen);
175
176 void CABLEClientSendDataThread(void *threadData);
177
178 void CABLEClientDataReceiverHandler(void *threadData);
179
180 void CATerminateBleQueues();
181
182 CAResult_t CAInitBleClientReceiverQueue();
183
184 CAResult_t CAInitBleServerReceiverQueue();
185
186 void CAInitBleQueues();
187
188 void CATerminateBleQueues();
189
190 CAResult_t CAInitBleServerQueues();
191
192 CAResult_t CAInitBleClientQueues();
193
194 CAResult_t CAInitBleServerSenderQueue();
195
196 CAResult_t CAInitBleClientSenderQueue();
197
198
199
200 /**
201  * @fn CABLEDataReceiverHandler
202  * @brief This function handles data from recv message queue.
203  */
204 void CABLEServerDataReceiverHandler(void *context);
205
206 /**
207  * @fn CABLESendDataThread
208  * @brief This function handles data from sender message queue.
209  */
210 void CABLEServerSendDataThread(void *threadData);
211
212 /**
213 * @fn  CACreateBLEData
214 * @brief  This function will create the Data required to send it in the queue.
215 *
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.
219 *
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
224 *
225 */
226 CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
227                                   uint32_t dataLength);
228
229 /**
230 * @fn  CAFreeBLEData
231 * @brief  Used to free the BLE information stored in the sender/receiver queues.
232 *
233 * @param[in]  bleData  Structure contains the information of a particular data segment.
234 *
235 * @return  none.
236 */
237 void CAFreeBLEData(CABLEData *bleData);
238
239 #ifdef __cplusplus
240 } /* extern "C" */
241 #endif
242
243 #endif //#ifndef _CA_LEADAPTER_H_