Merge "Implementation of following functionality" 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 #include "uthreadpool.h" /* for thread pool */
31
32 /**
33  * BLE Interface APIs.
34  */
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /**
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.
44  */
45 typedef struct
46 {
47     CARemoteEndpoint_t
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 */
51 } CABLEData;
52
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 , \
56  *                                             multicast servers
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)
59  */
60 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
61                           CANetworkPacketReceivedCallback reqRespCallback,
62                           CANetworkChangeCallback netCallback,
63                           u_thread_pool_t handle);
64
65 /**
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)
69  */
70 CAResult_t CAStartLE();
71
72 /**
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)
77  */
78 CAResult_t CAStartLEListeningServer();
79
80 /**
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)
85  */
86 CAResult_t CAStartLEDiscoveryServer();
87
88 /**
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.
96  */
97 uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data,
98                              uint32_t dataLen);
99
100 /**
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.
106  */
107 uint32_t CASendLEMulticastData(void *data, uint32_t dataLen);
108
109 /**
110  * @brief Starts notification server on EDR adapters.
111  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
112  */
113 CAResult_t CAStartLENotifyServer();
114
115 /**
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.
123  */
124 uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data,
125                               uint32_t dataLen);
126
127 /**
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)
132  */
133 CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
134
135 /**
136  * @brief Read Synchronous API callback.
137  * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
138  */
139 CAResult_t CAReadLEData();
140
141 /**
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)
145  */
146 CAResult_t CAStopLE();
147
148 /**
149  * @brief Terminate the LE connectivity adapter.
150  * Configuration information will be deleted from further use
151  */
152 void CATerminateLE();
153
154 CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID,
155                                         void *data, uint32_t dataLength, uint32_t *sentLength);
156
157 CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID,
158                                         void *data, uint32_t dataLength, uint32_t *sentLength);
159
160 void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback);
161
162 CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint,
163         void *data, uint32_t dataLen);
164
165 CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint,
166         void *data,  uint32_t dataLen);
167
168 void CABLEClientSendDataThread(void *threadData);
169
170 void CABLEClientDataReceiverHandler(void *threadData);
171
172 void CATerminateBleQueues();
173
174 CAResult_t CAInitBleClientReceiverQueue();
175
176 CAResult_t CAInitBleServerReceiverQueue();
177
178 void CAInitBleQueues();
179
180 void CATerminateBleQueues();
181
182 CAResult_t CAInitBleServerQueues();
183
184 CAResult_t CAInitBleClientQueues();
185
186 CAResult_t CAInitBleServerSenderQueue();
187
188 CAResult_t CAInitBleClientSenderQueue();
189
190
191
192 /**
193  * @fn CABLEDataReceiverHandler
194  * @brief This function handles data from recv message queue.
195  */
196 void CABLEServerDataReceiverHandler(void *context);
197
198 /**
199  * @fn CABLESendDataThread
200  * @brief This function handles data from sender message queue.
201  */
202 void CABLEServerSendDataThread(void *threadData);
203
204 /**
205 * @fn  CACreateBLEData
206 * @brief  This function will create the Data required to send it in the queue.
207 *
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.
211 *
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
216 *
217 */
218 CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
219                                   uint32_t dataLength);
220
221 /**
222 * @fn  CAFreeBLEData
223 * @brief  Used to free the BLE information stored in the sender/receiver queues.
224 *
225 * @param[in]  bleData  Structure contains the information of a particular data segment.
226 *
227 * @return  none.
228 */
229 void CAFreeBLEData(CABLEData *bleData);
230
231 #ifdef __cplusplus
232 } /* extern "C" */
233 #endif
234
235 #endif //#ifndef _CA_LEADAPTER_H_