2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <vconf/vconf.h>
21 #include "net_connection_private.h"
23 static GSList *conn_handle_list = NULL;
25 static void __connection_cb_state_change_cb(keynode_t *node, void *user_data);
26 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data);
27 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data);
30 static int __connection_convert_net_state(int status)
33 case VCONFKEY_NETWORK_CELLULAR:
34 return CONNECTION_TYPE_CELLULAR;
35 case VCONFKEY_NETWORK_WIFI:
36 return CONNECTION_TYPE_WIFI;
38 return CONNECTION_TYPE_DISCONNECTED;
42 static int __connection_convert_cellular_state(int status)
45 case VCONFKEY_NETWORK_CELLULAR_ON:
46 return CONNECTION_CELLULAR_STATE_AVAILABLE;
47 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
48 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
49 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
50 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
51 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
52 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
54 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
58 static int __connection_convert_wifi_state(int status)
61 case VCONFKEY_NETWORK_WIFI_CONNECTED:
62 return CONNECTION_WIFI_STATE_CONNECTED;
63 case VCONFKEY_NETWORK_WIFI_NOT_CONNECTED:
64 return CONNECTION_WIFI_STATE_DISCONNECTED;
66 return CONNECTION_WIFI_STATE_DEACTIVATED;
70 static int __connection_get_state_changed_callback_count(void)
75 for (list = conn_handle_list; list; list = list->next) {
76 connection_handle_s *local_handle = (connection_handle_s *)list->data;
77 if (local_handle->state_changed_callback) count++;
83 static int __connection_get_ip_changed_callback_count(void)
88 for (list = conn_handle_list; list; list = list->next) {
89 connection_handle_s *local_handle = (connection_handle_s *)list->data;
90 if (local_handle->ip_changed_callback) count++;
96 static int __connection_get_proxy_changed_callback_count(void)
101 for (list = conn_handle_list; list; list = list->next) {
102 connection_handle_s *local_handle = (connection_handle_s *)list->data;
103 if (local_handle->proxy_changed_callback) count++;
109 static int __connection_set_state_changed_callback(connection_h connection, void *callback, void *user_data)
111 connection_handle_s *local_handle = (connection_handle_s *)connection;
114 if (__connection_get_state_changed_callback_count() == 0)
115 if (vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS ,
116 __connection_cb_state_change_cb, NULL))
117 return CONNECTION_ERROR_OPERATION_FAILED;
119 local_handle->state_changed_user_data = user_data;
121 if (local_handle->state_changed_callback &&
122 __connection_get_state_changed_callback_count() == 1)
123 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
124 __connection_cb_state_change_cb))
125 return CONNECTION_ERROR_OPERATION_FAILED;
128 local_handle->state_changed_callback = callback;
129 return CONNECTION_ERROR_NONE;
132 static int __connection_set_ip_changed_callback(connection_h connection, void *callback, void *user_data)
134 connection_handle_s *local_handle = (connection_handle_s *)connection;
137 if (__connection_get_ip_changed_callback_count() == 0)
138 if (vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
139 __connection_cb_ip_change_cb, NULL))
140 return CONNECTION_ERROR_OPERATION_FAILED;
142 local_handle->ip_changed_user_data = user_data;
144 if (local_handle->ip_changed_callback &&
145 __connection_get_ip_changed_callback_count() == 1)
146 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
147 __connection_cb_ip_change_cb))
148 return CONNECTION_ERROR_OPERATION_FAILED;
151 local_handle->ip_changed_callback = callback;
152 return CONNECTION_ERROR_NONE;
155 static int __connection_set_proxy_changed_callback(connection_h connection, void *callback, void *user_data)
157 connection_handle_s *local_handle = (connection_handle_s *)connection;
160 if (__connection_get_proxy_changed_callback_count() == 0)
161 if (vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
162 __connection_cb_proxy_change_cb, NULL))
163 return CONNECTION_ERROR_OPERATION_FAILED;
165 local_handle->proxy_changed_user_data = user_data;
167 if (local_handle->proxy_changed_callback &&
168 __connection_get_proxy_changed_callback_count() == 1)
169 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
170 __connection_cb_proxy_change_cb))
171 return CONNECTION_ERROR_OPERATION_FAILED;
174 local_handle->proxy_changed_callback = callback;
175 return CONNECTION_ERROR_NONE;
178 static void __connection_cb_state_change_cb(keynode_t *node, void *user_data)
180 CONNECTION_LOG(CONNECTION_INFO, "Net Status Changed Indication\n");
183 int state = vconf_keynode_get_int(node);
185 for (list = conn_handle_list; list; list = list->next) {
186 connection_handle_s *local_handle = (connection_handle_s *)list->data;
187 if (local_handle->state_changed_callback)
188 local_handle->state_changed_callback(
189 __connection_convert_net_state(state),
190 local_handle->state_changed_user_data);
194 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
196 CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n");
199 char *ip_addr = vconf_keynode_get_str(node);
201 for (list = conn_handle_list; list; list = list->next) {
202 connection_handle_s *local_handle = (connection_handle_s *)list->data;
203 if (local_handle->ip_changed_callback)
204 local_handle->ip_changed_callback(
206 local_handle->ip_changed_user_data);
210 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
212 CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n");
215 char *proxy = vconf_keynode_get_str(node);
217 for (list = conn_handle_list; list; list = list->next) {
218 connection_handle_s *local_handle = (connection_handle_s *)list->data;
219 if (local_handle->proxy_changed_callback)
220 local_handle->proxy_changed_callback(
222 local_handle->proxy_changed_user_data);
226 static bool __connection_check_handle_validity(connection_h connection)
230 for (list = conn_handle_list; list; list = list->next)
231 if (connection == list->data) return true;
236 static int __connection_get_handle_count(void)
241 if (!conn_handle_list)
244 for (list = conn_handle_list; list; list = list->next) count++;
249 /* Connection Manager module ********************************************************************/
251 int connection_create(connection_h* connection)
253 CONNECTION_MUTEX_LOCK;
255 if (connection == NULL || __connection_check_handle_validity(*connection)) {
256 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
257 CONNECTION_MUTEX_UNLOCK;
258 return CONNECTION_ERROR_INVALID_PARAMETER;
261 if (_connection_libnet_init() == false) {
262 CONNECTION_LOG(CONNECTION_ERROR, "Creation failed!\n");
263 CONNECTION_MUTEX_UNLOCK;
264 return CONNECTION_ERROR_OPERATION_FAILED;
267 *connection = g_try_malloc0(sizeof(connection_handle_s));
268 if (*connection != NULL) {
269 CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection);
271 CONNECTION_MUTEX_UNLOCK;
272 return CONNECTION_ERROR_OUT_OF_MEMORY;
275 conn_handle_list = g_slist_append(conn_handle_list, *connection);
277 CONNECTION_MUTEX_UNLOCK;
278 return CONNECTION_ERROR_NONE;
281 int connection_destroy(connection_h connection)
283 CONNECTION_MUTEX_LOCK;
285 if (connection == NULL || !(__connection_check_handle_validity(connection))) {
286 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
287 CONNECTION_MUTEX_UNLOCK;
288 return CONNECTION_ERROR_INVALID_PARAMETER;
291 CONNECTION_LOG(CONNECTION_INFO, "Destroy Handle : %p\n", connection);
293 __connection_set_state_changed_callback(connection, NULL, NULL);
294 __connection_set_ip_changed_callback(connection, NULL, NULL);
295 __connection_set_proxy_changed_callback(connection, NULL, NULL);
297 conn_handle_list = g_slist_remove(conn_handle_list, connection);
301 if (__connection_get_handle_count() == 0)
302 _connection_libnet_deinit();
304 CONNECTION_MUTEX_UNLOCK;
305 return CONNECTION_ERROR_NONE;
308 int connection_get_type(connection_h connection, connection_type_e* type)
312 if (type == NULL || !(__connection_check_handle_validity(connection))) {
313 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
314 return CONNECTION_ERROR_INVALID_PARAMETER;
317 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) {
318 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
319 return CONNECTION_ERROR_OPERATION_FAILED;
322 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n", status);
324 *type = __connection_convert_net_state(status);
326 return CONNECTION_ERROR_NONE;
329 int connection_get_ip_address(connection_h connection, connection_address_family_e address_family, char** ip_address)
331 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
332 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
333 return CONNECTION_ERROR_INVALID_PARAMETER;
336 switch (address_family) {
337 case CONNECTION_ADDRESS_FAMILY_IPV4:
338 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
340 case CONNECTION_ADDRESS_FAMILY_IPV6:
341 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
342 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
345 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
346 return CONNECTION_ERROR_INVALID_PARAMETER;
349 if (*ip_address == NULL) {
350 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
351 return CONNECTION_ERROR_OPERATION_FAILED;
354 CONNECTION_LOG(CONNECTION_INFO, "IP Address %s\n", *ip_address);
356 return CONNECTION_ERROR_NONE;
359 int connection_get_proxy(connection_h connection, connection_address_family_e address_family, char** proxy)
361 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
362 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
363 return CONNECTION_ERROR_INVALID_PARAMETER;
366 switch (address_family) {
367 case CONNECTION_ADDRESS_FAMILY_IPV4:
368 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
370 case CONNECTION_ADDRESS_FAMILY_IPV6:
371 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
372 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
375 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
376 return CONNECTION_ERROR_INVALID_PARAMETER;
379 if (*proxy == NULL) {
380 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
381 return CONNECTION_ERROR_OPERATION_FAILED;
384 CONNECTION_LOG(CONNECTION_INFO, "Proxy Address %s\n", *proxy);
386 return CONNECTION_ERROR_NONE;
389 int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
393 if (state == NULL || !(__connection_check_handle_validity(connection))) {
394 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
395 return CONNECTION_ERROR_INVALID_PARAMETER;
398 if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) {
399 CONNECTION_LOG(CONNECTION_INFO, "Cellular = %d\n", status);
400 *state = __connection_convert_cellular_state(status);
401 return CONNECTION_ERROR_NONE;
403 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
404 return CONNECTION_ERROR_OPERATION_FAILED;
408 int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
412 if (state == NULL || !(__connection_check_handle_validity(connection))) {
413 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
414 return CONNECTION_ERROR_INVALID_PARAMETER;
417 if (!vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status)) {
418 CONNECTION_LOG(CONNECTION_INFO, "WiFi = %d\n", status);
419 *state = __connection_convert_wifi_state(status);
420 return CONNECTION_ERROR_NONE;
422 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
423 return CONNECTION_ERROR_OPERATION_FAILED;
427 int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
429 if (state == NULL || !(__connection_check_handle_validity(connection))) {
430 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
431 return CONNECTION_ERROR_INVALID_PARAMETER;
434 if (_connection_libnet_get_ethernet_state(state) == false)
435 return CONNECTION_ERROR_OPERATION_FAILED;
437 return CONNECTION_ERROR_NONE;
440 int connection_set_type_changed_cb(connection_h connection,
441 connection_type_changed_cb callback, void* user_data)
443 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
444 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
445 return CONNECTION_ERROR_INVALID_PARAMETER;
448 return __connection_set_state_changed_callback(connection, callback, user_data);
451 int connection_unset_type_changed_cb(connection_h connection)
453 if (!(__connection_check_handle_validity(connection))) {
454 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
455 return CONNECTION_ERROR_INVALID_PARAMETER;
458 return __connection_set_state_changed_callback(connection, NULL, NULL);
461 int connection_set_ip_address_changed_cb(connection_h connection,
462 connection_address_changed_cb callback, void* user_data)
464 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
465 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
466 return CONNECTION_ERROR_INVALID_PARAMETER;
469 return __connection_set_ip_changed_callback(connection, callback, user_data);
472 int connection_unset_ip_address_changed_cb(connection_h connection)
474 if (!(__connection_check_handle_validity(connection))) {
475 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
476 return CONNECTION_ERROR_INVALID_PARAMETER;
479 return __connection_set_ip_changed_callback(connection, NULL, NULL);
482 int connection_set_proxy_address_changed_cb(connection_h connection,
483 connection_address_changed_cb callback, void* user_data)
485 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
486 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
487 return CONNECTION_ERROR_INVALID_PARAMETER;
490 return __connection_set_proxy_changed_callback(connection, callback, user_data);
493 int connection_unset_proxy_address_changed_cb(connection_h connection)
495 if (!(__connection_check_handle_validity(connection))) {
496 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
497 return CONNECTION_ERROR_INVALID_PARAMETER;
500 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
503 int connection_add_profile(connection_h connection, connection_profile_h profile)
505 if (!(__connection_check_handle_validity(connection)) ||
506 !(_connection_libnet_check_profile_validity(profile))) {
507 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
508 return CONNECTION_ERROR_INVALID_PARAMETER;
513 net_profile_info_t *profile_info = profile;
515 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
516 if (rv != NET_ERR_NONE) {
517 CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
518 return CONNECTION_ERROR_OPERATION_FAILED;
521 return CONNECTION_ERROR_NONE;
524 int connection_remove_profile(connection_h connection, connection_profile_h profile)
526 if (!(__connection_check_handle_validity(connection)) ||
527 !(_connection_libnet_check_profile_validity(profile))) {
528 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
529 return CONNECTION_ERROR_INVALID_PARAMETER;
533 net_profile_info_t *profile_info = profile;
535 rv = net_delete_profile(profile_info->ProfileName);
536 if (rv != NET_ERR_NONE) {
537 CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
538 return CONNECTION_ERROR_OPERATION_FAILED;
541 return CONNECTION_ERROR_NONE;
544 int connection_update_profile(connection_h connection, connection_profile_h profile)
546 if (!(__connection_check_handle_validity(connection)) ||
547 !(_connection_libnet_check_profile_validity(profile))) {
548 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
549 return CONNECTION_ERROR_INVALID_PARAMETER;
553 net_profile_info_t *profile_info = profile;
555 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
556 if (rv != NET_ERR_NONE) {
557 CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
558 return CONNECTION_ERROR_OPERATION_FAILED;
561 return CONNECTION_ERROR_NONE;
564 int connection_get_profile_iterator(connection_h connection,
565 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
567 if (!(__connection_check_handle_validity(connection)) ||
568 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
569 type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
570 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
571 return CONNECTION_ERROR_INVALID_PARAMETER;
574 return _connection_libnet_get_profile_iterator(type, profile_iterator);
577 int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator, connection_profile_h* profile)
579 return _connection_libnet_get_iterator_next(profile_iterator, profile);
582 bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
584 return _connection_libnet_iterator_has_next(profile_iterator);
587 int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
589 return _connection_libnet_destroy_iterator(profile_iterator);
592 int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
594 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
595 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
596 return CONNECTION_ERROR_INVALID_PARAMETER;
599 return _connection_libnet_get_current_profile(profile);
602 int connection_open_profile(connection_h connection, connection_profile_h profile)
604 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
605 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
606 return CONNECTION_ERROR_INVALID_PARAMETER;
609 return _connection_libnet_open_profile(profile);
612 int connection_open_cellular_service_type(connection_h connection,
613 connection_cellular_service_type_e type, connection_profile_h* profile)
615 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
616 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
617 return CONNECTION_ERROR_INVALID_PARAMETER;
620 return _connection_libnet_open_cellular_service_type(type, profile);
623 int connection_close_profile(connection_h connection, connection_profile_h profile)
625 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
626 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
627 return CONNECTION_ERROR_INVALID_PARAMETER;
630 return _connection_libnet_close_profile(profile);
634 /* Connection Statistics module ******************************************************************/
636 static int __get_statistic(connection_type_e connection_type, connection_statistics_type_e statistics_type, long long* llsize)
639 unsigned long long ull_size;
643 if (llsize == NULL) {
644 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
645 return CONNECTION_ERROR_INVALID_PARAMETER;
648 if (connection_type == CONNECTION_TYPE_CELLULAR) {
649 switch (statistics_type) {
650 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
651 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT;
653 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
654 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV;
656 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
657 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT;
659 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
660 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV;
663 return CONNECTION_ERROR_INVALID_PARAMETER;
666 if (vconf_get_int(key, &size)) {
667 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size);
669 return CONNECTION_ERROR_OPERATION_FAILED;
672 CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size);
673 *llsize = (long long)size;
674 } else if (connection_type == CONNECTION_TYPE_WIFI) {
675 switch (statistics_type) {
676 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
677 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
679 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
680 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
682 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
683 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
685 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
686 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
689 return CONNECTION_ERROR_INVALID_PARAMETER;
692 if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
693 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
695 return CONNECTION_ERROR_OPERATION_FAILED;
698 CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size);
699 *llsize = (long long)ull_size;
701 return CONNECTION_ERROR_INVALID_PARAMETER;
703 return CONNECTION_ERROR_NONE;
706 static int __reset_statistic(connection_type_e connection_type, connection_statistics_type_e statistics_type)
712 if (connection_type == CONNECTION_TYPE_CELLULAR)
713 conn_type = NET_DEVICE_CELLULAR;
714 else if (connection_type == CONNECTION_TYPE_WIFI)
715 conn_type = NET_DEVICE_WIFI;
717 return CONNECTION_ERROR_INVALID_PARAMETER;
719 switch (statistics_type) {
720 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
721 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
723 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
724 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
726 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
727 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
729 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
730 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
733 return CONNECTION_ERROR_INVALID_PARAMETER;
736 rv = _connection_libnet_set_statistics(conn_type, stat_type);
737 if(rv != CONNECTION_ERROR_NONE)
741 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n");
743 return CONNECTION_ERROR_NONE;
746 int connection_get_statistics(connection_type_e connection_type, connection_statistics_type_e statistics_type, long long* size)
748 return __get_statistic(connection_type, statistics_type, size);
751 int connection_reset_statistics(connection_type_e connection_type, connection_statistics_type_e statistics_type)
753 return __reset_statistic(connection_type, statistics_type);