summaryrefslogtreecommitdiff
path: root/include/net_connection.h
blob: 0a9ee7377aa9d1b20acd525441e7eebab1e5c13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */


#ifndef __NET_CONNECTION_INTF_H__        /* To prevent inclusion of a header file twice */
#define __NET_CONNECTION_INTF_H__

#include <tizen_error.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifndef DEPRECATED
#define DEPRECATED __attribute__((deprecated))
#endif



/**
 * @addtogroup CAPI_NETWORK_FRAMEWORK
 * @{
*/

/**
 * @addtogroup CAPI_NETWORK_CONNECTION_MODULE
 * @{
*/

#include <arpa/inet.h>


/**
* @enum connection_error_e
* @brief Enumerations of network API errors.
*/
typedef enum
{
	CONNECTION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
	CONNECTION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
	CONNECTION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */
	CONNECTION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */

}connection_error_e;

/**
* @enum connection_network_status_e
* @brief Enumerations of network status.
*/
typedef enum 
{

    /** Not connected / Suspended / Idle / Connecting / Disconnecting */
    CONNECTION_STATUS_UNAVAILABLE,

    /** Active */
    CONNECTION_STATUS_AVAILABLE,

    /** Service unknown */
    CONNECTION_STATUS_UNKNOWN,

}connection_network_status_e;

/**
* @enum connection_network_type_e
* @brief Enumerations of network connection type.
*/
typedef enum{
	/** Default type \n
	      The automatic connection is established.  \n
	      WiFi connection has higher priority than 3G connection. \n
	      If Wifi connection is established by user selection or auto joining,\n
	      3G connection will be automatically moved to WiFi connection in NET_DEFAULT_TYPE case. */
	CONNECTION_DEFAULT_TYPE = 0x00,

	/** Mobile Type \n
		Network connection is established in 3G network \n
	*/
	CONNECTION_MOBILE_TYPE	= 0x01,

	/** WiFi Type \n
		Network connection is established in WiFi network \n
	*/
	CONNECTION_WIFI_TYPE	= 0x02,

}connection_network_type_e;



/**
* @enum connection_network_param_e
* @brief Enumerations of changed network parameter.
* These are received as param in #connection_cb.
*/
typedef enum{
    /** Network Status has changed. \n
	*/
	CONNECTION_NETWORK_STATUS = 0x00,

	/** IP Address has changed. \n
	*/
	CONNECTION_IP_ADDRESS	= 0x01,

	/** Proxy Address has changed. \n
	*/
	CONNECTION_PROXY_ADDRESS	= 0x02,

}connection_network_param_e;


/**
 * @brief  The connection handle for all connection functions.
*/
typedef struct connection_handle_s  * connection_h;



/**
 * @brief Called when a connection event occurs. 
 * @param[in] param The enum of the parameter that changed. #connection_network_param_e
 * @param[in] user_data The user data passed from the callback registration function
 * @pre Register this function using connection_set_cb().
 * @see  connection_set_cb() 
 * @see connection_unset_cb()
 *
*/
typedef void (*connection_cb) (const connection_network_param_e param, void *user_data);


/**
 * @brief Creates a handle for managing data connections.
 *
 * @remarks @a handle must be released with connection_destroy(). \n
 *
 * @param[out] handle      The handle to the connection
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 * @retval #CONNECTION_ERROR_OUT_OF_MEMORY  Out of memory error 
 * @see connection_destroy()
 *
 *
******************************************************************************************/
int connection_create(connection_h * handle);

/*****************************************************************************************/
/**
 * @brief  Destroys the connection handle.
 *
 * @param[in] handle      The handle to the connection
 *
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 * @see connection_create()
 *
 *
******************************************************************************************/
int connection_destroy(connection_h handle);

/*****************************************************************************************/
/**
 * @brief  Registers a callback function to be invoked when connection event occurs.
 * @param[in] handle      The handle to the connection
 * @param[in] callback    The callback function to register
 * @param[in] user_data   The user data to be passed to the callback function 
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER  Invalid parameter 
 * @post  connection_cb() will be invoked.
 * @see connection_create()
 * @see connection_cb() 
 * @see connection_unset_cb()
 *
******************************************************************************************/
int connection_set_cb(connection_h handle, connection_cb callback, void *user_data);

/*****************************************************************************************/
/**
 * @brief  Unregisters the callback function.
 * @param[in] handle      The handle to the connection
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER  Invalid parameter 
 * @see connection_cb()
 * @see connection_set_cb()
******************************************************************************************/
int connection_unset_cb(connection_h handle);

/*****************************************************************************************/
/**
 * @brief 	Gets the IP address of an existing connection. 
 *
 * @remarks     @a ip_address must be released with free() by you. 
 * @param[in]	handle     The handle to the connection
 * @param[out]	ip_address   	    The pointer to IP address string.
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 *
******************************************************************************************/
int connection_get_ip_address(connection_h handle, char **ip_address);


/*****************************************************************************************/
/**
 * @brief Gets the proxy address of the current connection. 
 *
 * @remarks  @a proxy must be released with free() by you.
 *
 * @param[in]	handle     The handle to the connection
 * @param[out]	proxy   The proxy address 
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 *
 *
******************************************************************************************/
int connection_get_proxy(connection_h handle, char **proxy);

/*****************************************************************************************/
/**
 * @brief  Gets the network status. 
 *
 * @details The returned status is for the overall connection of the phone, not per application.
 *
 * @param[in] 	network_type    	The network type 
 * @param[out] 	network_status 		The status of network 
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 * @retval #CONNECTION_ERROR_INVALID_OPERATION   Cannot retrieve the status due to internal error
 * 
 *
******************************************************************************************/
int connection_get_network_status(connection_network_type_e network_type, connection_network_status_e* network_status);


/*****************************************************************************************/
/**
 * @brief Gets the duration of the last cellular packet data connection.
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	last_datacall_duration    The time duration of the last cellular packet data connection ( seconds )
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 *
 ******************************************************************************************/
int connection_get_last_datacall_duration(connection_h handle, int *last_datacall_duration);

/*****************************************************************************************/
/**
 * @brief  Gets the received data size of the last cellular packet data connection. 
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	last_recv_data_size     The received data size of the last cellular packet data connection ( bytes )
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 *
 ******************************************************************************************/
int connection_get_last_received_data_size(connection_h handle, int * last_recv_data_size);

/*****************************************************************************************/
/**
 * @brief Gets the sent data size of the last cellular packet data connection. 
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	last_sent_data_size     the sent data size of the last cellular packet data connection.
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 * 
 *
 ******************************************************************************************/
int connection_get_last_sent_data_size(connection_h handle, int * last_sent_data_size);

/*****************************************************************************************/
/**
 * @brief Gets the total time duration of all cellular packet data connections.
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	total_datacall_duration    The total time duration of all cellular packet data connections ( seconds )
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 * 
 *
 ******************************************************************************************/
int connection_get_total_datacall_duration(connection_h handle, int * total_datacall_duration);

/*****************************************************************************************/
/**
 * @brief Gets the total received data size of all cellular packet data connections. 
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	total_recv_data_size    The total received data size of all cellular packet data connections (bytes)
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 * 
 *
 ******************************************************************************************/
int connection_get_total_received_data_size (connection_h handle, int * total_recv_data_size);

/*****************************************************************************************/
/**
 * @brief Gets the total sent data size of all cellular packet data connections.
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	total_sent_data_size     The total sent data size of all cellular packet data connections (bytes)
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 *
 *
 ******************************************************************************************/
int connection_get_total_sent_data_size (connection_h handle, int * total_sent_data_size);

/*****************************************************************************************/
/**
 * @brief Indicates connection status.
 *
 * @return Return @c true if connection is connected, otherwise @c false 
 *
 *
******************************************************************************************/
bool connection_is_connected(void);

/*****************************************************************************************/
/**
 * @brief Gets the duration of the last WiFi packet data connection.
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	wifi_last_datacall_duration    The time duration of the last WiFi packet data connection ( seconds )
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 *
 ******************************************************************************************/
int connection_get_wifi_last_datacall_duration(connection_h handle, int *wifi_last_datacall_duration);

/*****************************************************************************************/
/**
 * @brief  Gets the received data size of the last WiFi packet data connection. 
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	wifi_last_recv_data_size     The received data size of the last WiFi packet data connection ( bytes )
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 *
 ******************************************************************************************/
int connection_get_wifi_last_received_data_size(connection_h handle, int * wifi_last_recv_data_size);

/*****************************************************************************************/
/**
 * @brief Gets the sent data size of the last WiFi packet data connection. 
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	wifi_last_sent_data_size     the sent data size of the last WiFi packet data connection.
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 * 
 *
 ******************************************************************************************/
int connection_get_wifi_last_sent_data_size(connection_h handle, int * wifi_last_sent_data_size);

/*****************************************************************************************/
/**
 * @brief Gets the total time duration of all WiFi packet data connections.
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	wifi_total_datacall_duration    The total time duration of all WiFi packet data connections ( seconds )
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 * 
 *
 ******************************************************************************************/
int connection_get_wifi_total_datacall_duration(connection_h handle, int * wifi_total_datacall_duration);

/*****************************************************************************************/
/**
 * @brief Gets the total received data size of all WiFi packet data connections. 
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	wifi_total_recv_data_size    The total received data size of all WiFi packet data connections (bytes)
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
 * 
 *
 ******************************************************************************************/
int connection_get_wifi_total_received_data_size (connection_h handle, int * wifi_total_recv_data_size);

/*****************************************************************************************/
/**
 * @brief Gets the total sent data size of all WiFi packet data connections.
 *
 * @param[in]   handle     The handle to the connection
 * @param[out]	wifi_total_sent_data_size     The total sent data size of all WiFi packet data connections (bytes)
 * @return 0 on success, otherwise negative error value.
 * @retval #CONNECTION_ERROR_NONE  Successful 
 * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
 *
 *
 ******************************************************************************************/
int connection_get_wifi_total_sent_data_size (connection_h handle, int *wifi_total_sent_data_size);

/**
 * @}
*/
/** 
 * @}
 */


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif