IoT-243 Connectivity Abstraction single-threaded module missing definition for CASend...
[contrib/iotivity.git] / resource / csdk / connectivity / inc / cawifiinterface_singlethread.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 cawifiinterface_singlethread.h
23  * @brief This file provides APIs for WIFI adapter - client, server, network monitor modules
24  */
25
26 #ifndef _CA_WIFI_INTERFACE_SINGLETHREAD_H_
27 #define _CA_WIFI_INTERFACE_SINGLETHREAD_H_
28
29 #include <stdbool.h>
30
31 #include "cacommon.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 /**
39  * @enum CAAdapterServerType_t
40  * @brief Enum for defining different server types.
41  */
42 typedef enum
43 {
44     CA_UNICAST_SERVER = 0,      /**< Unicast Server */
45     CA_MULTICAST_SERVER,        /**< Multicast Server */
46     CA_SECURED_UNICAST_SERVER   /**< Secured Unicast Server */
47 } CAAdapterServerType_t;
48
49 /**
50  * @brief Callback to be notified on reception of any data from remote OIC devices.
51  * @param  ipAddress    [IN] IP address of remote OIC device.
52  * @param  port         [IN] Port number on which data is received.
53  * @param  data         [IN] Data received from remote OIC device.
54  * @param  dataLength   [IN] Length of data in bytes.
55  * @return NONE
56  * @pre  Callback must be registered using CAWiFiSetPacketReceiveCallback()
57  */
58 typedef void (*CAWiFiPacketReceivedCallback)(const char *ipAddress, const uint32_t port,
59         const void *data, const uint32_t dataLength);
60
61 /**
62  * @brief  Callback to be notified when exception occures on multicast/unicast server.
63  * @param  type  [IN] Type of server(#CAAdapterServerType_t)
64  * @return NONE
65  * @pre  Callback must be registered using CAWiFiSetExceptionCallback()
66  */
67 typedef void (*CAWiFiExceptionCallback)(CAAdapterServerType_t type);
68
69 /**
70  * @brief  Initialize WIFI server
71  * @return  #CA_STATUS_OK or Appropriate error code
72  * @retval  #CA_STATUS_OK  Successful
73  * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
74  * @retval  #CA_STATUS_FAILED Initialization failed
75  */
76 CAResult_t CAWiFiInitializeServer(void);
77
78 /**
79  * @brief  Terminate WIFI server
80  * @return NONE
81  */
82 void CAWiFiTerminateServer(void);
83
84 /**
85  * @brief  Start multicast server for specified multicast address and port
86  *
87  * @param   localAddress        [IN]      Local adapter address to which server to be binded.
88  * @param   multicastAddress    [IN]      Multicast group address.
89  * @param   multicastPort       [IN,OUT]  Port number on which server will be running. If binding
90                                           the port failed, server starts in the next available port.
91  * @param   serverFD            [OUT]     Multicast server socket FD.
92  *
93  * @return  #CA_STATUS_OK or Appropriate error code
94  * @retval  #CA_STATUS_OK  Successful
95  * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
96  * @retval  #CA_SERVER_STARTED_ALREADY Multicast server is already started and running.
97  * @retval  #CA_STATUS_FAILED Operation failed
98  */
99 CAResult_t CAWiFiStartMulticastServer(const char *localAddress, const char *multicastAddress,
100                                       const int16_t multicastPort, int32_t *serverFD);
101
102 /**
103  * @brief  Start unicast server for specified local address and port
104  *
105  * @param  localAddress [IN]      Local adapter address to which server to be binded.
106  * @param  port         [IN,OUT]  Port number on which server will be running. If binding
107                                   the port failed, server starts in the next available port.
108  * @param  forceStart   [IN]      Indicate whether to start server forcesfully on specified port
109  *                                or not.
110  * @param  serverFD     [OUT]     Unicast server socket FD.
111  *
112  * @return  #CA_STATUS_OK or Appropriate error code
113  * @retval  #CA_STATUS_OK  Successful
114  * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
115  * @retval  #CA_SERVER_STARTED_ALREADY Unicast server is already started and running.
116  * @retval  #CA_STATUS_FAILED Operation failed
117  */
118 CAResult_t CAWiFiStartUnicastServer(const char *localAddress, int16_t *port,
119                                     const bool forceStart, int32_t *serverFD);
120
121 /**
122  * @brief  Stop multicast server.
123  *
124  * @return  #CA_STATUS_OK or Appropriate error code
125  * @retval  #CA_STATUS_OK  Successful
126  * @retval  #CA_STATUS_FAILED Operation failed
127  */
128 CAResult_t CAWiFiStopMulticastServer(void);
129
130 /**
131  * @brief  Stop unicast server.
132  *
133  * @return  #CA_STATUS_OK or Appropriate error code
134  * @retval  #CA_STATUS_OK  Successful
135  * @retval  #CA_STATUS_FAILED Operation failed
136  */
137 CAResult_t CAWiFiStopUnicastServer();
138
139 #ifdef __WITH_DTLS__
140 /**
141  * @brief  Stop secured unicast server.
142  *
143  * @return  #CA_STATUS_OK or Appropriate error code
144  * @retval  #CA_STATUS_OK  Successful
145  * @retval  #CA_STATUS_FAILED Operation failed
146  */
147 CAResult_t CAWiFiStopSecureUnicastServer();
148 #endif
149
150 /**
151  * @brief  Get the Unicast Server Information if it is started
152  * @param  ipAddress    [OUT] IP address on which server is binded and running.
153  * @param  port         [OUT]Port number on which server is running
154  * @param  serverFD     [OUT]Server socket fd.
155  *
156  * @return  #CA_STATUS_OK or Appropriate error code
157  * @retval  #CA_STATUS_OK  Successful
158  * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
159  * @retval  #CA_STATUS_FAILED Operation failed
160  * @remarks  ipAddress must be freed using free().
161  */
162 CAResult_t CAWiFiGetUnicastServerInfo(char **ipAddress, int16_t *port, int32_t *serverFD);
163
164 /**
165  * @brief  Set this callback for receiving data packets from peer devices.
166  * @param  callback   [IN] Callback to be notified on reception of unicast/multicast data packets.
167  *
168  * @return  NONE
169  */
170 void CAWiFiSetPacketReceiveCallback(CAWiFiPacketReceivedCallback callback);
171
172 /**
173  * @brief  Pull the Received Data
174  * @return NONE
175  */
176 void CAWiFiPullData();
177
178 /**
179  * @brief  Set this callback for receiving exception notifications.
180  *
181  * @param  callback [IN] Callback to be notified on occurance of exception on running servers.
182  *
183  * @return  NONE
184  */
185 void CAWiFiSetExceptionCallback(CAWiFiExceptionCallback callback);
186
187 /**
188  * @brief  Set socket description for sending unicast UDP data. Once the Unicast server is started,
189  *         the same socket descriptor is used for sending the Unicast UDP data.
190  *
191  * @param  socketFD [IN]  Socket descriptor used for sending UDP data.
192  * @return  NONE
193  */
194 void CAWiFiSetUnicastSocket(const int32_t socketFD);
195
196 #ifdef __WITH_DTLS__
197 /**
198  * @brief  Set socket description for sending secured (encrypted) unicast UDP data
199  *
200  * @param socketFD [IN] Socket descriptor used for sending secured (encrypted) UDP data.
201  * @return  NONE
202  */
203 void CAWiFiSetSecureUnicastSocket(const int32_t socketFD);
204 #endif
205
206 /**
207  * @brief  API to send unicast UDP data
208  *
209  * @param  remoteAddress    [IN] IP address to which data needs to be sent.
210  * @param  port             [IN] Port to which data needs to be send.
211  * @param  data             [IN] Data to be send.
212  * @param  dataLength       [IN] Length of data in bytes
213  * @param  isMulticast      [IN] Whether data needs to be sent to multicast ip
214  *
215  * @return  The number of bytes sent on the network. Returns 0 on error.
216  */
217 uint32_t CAWiFiSendData(const char *remoteAddress, const uint32_t port,
218                         const void *data, const uint32_t dataLength, bool isMulticast);
219
220 /**
221  * @brief  Callback to be notified when wifi adapter connection state changes.
222  *
223  * @param  ipAddress    [IN] IP address of remote OIC device.
224  * @param  status       [IN] Connection status either #CA_INTERFACE_UP or #CA_INTERFACE_DOWN.
225  * @return  NONE
226  * @pre  Callback must be registered using CAWiFiSetConnectionStateChangeCallback()
227  */
228 typedef void (*CAWiFiConnectionStateChangeCallback)(const char *ipAddress,
229         const CANetworkStatus_t status);
230
231 /**
232  * @brief Initialize Wifi network monitor
233  * @return  #CA_STATUS_OK or Appropriate error code
234  * @retval  #CA_STATUS_OK  Successful
235  * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
236  * @retval  #CA_STATUS_FAILED Initialization failed
237  */
238 CAResult_t CAWiFiInitializeNetworkMonitor(void);
239
240 /**
241  * @brief Terminate WIFI network monitor
242  * @return  NONE
243  */
244 void CAWiFiTerminateNetworkMonitor(void);
245
246 /**
247  * @brief  Start network monitoring process.
248  *
249  * @return  #CA_STATUS_OK or Appropriate error code
250  * @retval  #CA_STATUS_OK  Successful
251  * @retval  #CA_STATUS_FAILED Operation failed
252  */
253 CAResult_t CAWiFiStartNetworkMonitor(void);
254
255 /**
256  * @brief  Stop network monitoring process.
257  *
258  * @return  #CA_STATUS_OK or Appropriate error code
259  * @retval  #CA_STATUS_OK  Successful
260  * @retval  #CA_STATUS_FAILED Operation failed
261  */
262 CAResult_t CAWiFiStopNetworkMonitor(void);
263
264 /**
265  * @brief  Get local adapter network information.
266  *
267  * @param  interfaceName [OUT] Local adapter interface name
268  * @param  ipAddress     [OUT] IP address
269  *
270  * @return  #CA_STATUS_OK or Appropriate error code
271  * @retval  #CA_STATUS_OK  Successful
272  * @retval  #CA_STATUS_INVALID_PARAM Invalid input data
273  * @retval  #CA_STATUS_FAILED Operation failed
274  * @remarks  interfaceName and ipAddress must be freed using free().
275  */
276 CAResult_t CAWiFiGetInterfaceInfo(char **interfaceName, char **ipAddress);
277
278 /**
279  * @brief  Get WIFI adapter connection state.
280  *
281  * @return  True if WIFI adapter is connected, otherwise false
282  */
283 bool CAWiFiIsConnected(void);
284
285 /**
286  * @brief  Set callback for receiving local wifi adapter connection status.
287  *
288  * @param  callback [IN] Callback to be notified when local WIFI adapter connection state changes.
289  * @return NONE
290  */
291 void CAWiFiSetConnectionStateChangeCallback(CAWiFiConnectionStateChangeCallback callback);
292
293 #ifdef __cplusplus
294 }
295 #endif
296
297 #endif //_CA_WIFI_INTERFACE_SINGLETHREAD_H_