2 * Copyright (c) 2011-2013 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>
22 #include "net_connection_private.h"
24 static __thread GSList *conn_handle_list = NULL;
26 static int __connection_convert_net_state(int status)
29 case VCONFKEY_NETWORK_CELLULAR:
30 return CONNECTION_TYPE_CELLULAR;
31 case VCONFKEY_NETWORK_WIFI:
32 return CONNECTION_TYPE_WIFI;
33 case VCONFKEY_NETWORK_ETHERNET:
34 return CONNECTION_TYPE_ETHERNET;
35 case VCONFKEY_NETWORK_BLUETOOTH:
36 return CONNECTION_TYPE_BT;
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 bool __connection_check_handle_validity(connection_h connection)
62 if (connection == NULL)
65 if (g_slist_find(conn_handle_list, connection) != NULL)
71 static connection_type_changed_cb
72 __connection_get_type_changed_callback(connection_handle_s *local_handle)
74 return local_handle->type_changed_callback;
77 static void *__connection_get_type_changed_userdata(
78 connection_handle_s *local_handle)
80 return local_handle->type_changed_user_data;
83 static gboolean __connection_cb_type_changed_cb_idle(gpointer user_data)
87 connection_type_changed_cb callback;
88 connection_handle_s *local_handle = (connection_handle_s *)user_data;
90 if (__connection_check_handle_validity((connection_h)local_handle) != true)
93 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status) != 0)
96 state = __connection_convert_net_state(status);
98 callback = __connection_get_type_changed_callback(local_handle);
99 data = __connection_get_type_changed_userdata(local_handle);
101 callback(state, data);
106 static void __connection_cb_type_change_cb(keynode_t *node, void *user_data)
111 if (_connection_is_created() != true) {
112 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
113 "If multi-threaded, thread integrity be broken.");
117 for (list = conn_handle_list; list; list = list->next) {
118 handle = (connection_h)list->data;
119 _connection_callback_add(__connection_cb_type_changed_cb_idle, (gpointer)handle);
123 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
125 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
129 for (list = conn_handle_list; list; list = list->next) {
130 connection_handle_s *local_handle = (connection_handle_s *)list->data;
131 if (local_handle->ethernet_cable_state_changed_callback)
132 local_handle->ethernet_cable_state_changed_callback(state,
133 local_handle->ethernet_cable_state_changed_user_data);
137 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
142 for (list = conn_handle_list; list; list = list->next) {
143 connection_handle_s *local_handle = (connection_handle_s *)list->data;
144 if (local_handle->ethernet_cable_state_changed_callback) count++;
150 static int __connection_set_type_changed_callback(connection_h connection,
151 void *callback, void *user_data)
153 static __thread gint refcount = 0;
154 connection_handle_s *local_handle;
156 local_handle = (connection_handle_s *)connection;
160 vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS,
161 __connection_cb_type_change_cb, NULL);
164 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
167 __connection_get_type_changed_callback(local_handle) != NULL) {
168 if (--refcount == 0) {
169 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
170 __connection_cb_type_change_cb) < 0) {
171 CONNECTION_LOG(CONNECTION_ERROR,
172 "Error to de-register vconf callback(%d)", refcount);
174 CONNECTION_LOG(CONNECTION_INFO,
175 "Successfully de-registered(%d)", refcount);
181 local_handle->type_changed_user_data = user_data;
182 local_handle->type_changed_callback = callback;
184 return CONNECTION_ERROR_NONE;
187 static connection_address_changed_cb
188 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
190 return local_handle->ip_changed_callback;
193 static void *__connection_get_ip_changed_userdata(
194 connection_handle_s *local_handle)
196 return local_handle->ip_changed_user_data;
199 static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
203 connection_address_changed_cb callback;
204 connection_handle_s *local_handle = (connection_handle_s *)user_data;
206 if (__connection_check_handle_validity((connection_h)local_handle) != true)
209 ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
211 callback = __connection_get_ip_changed_callback(local_handle);
212 data = __connection_get_ip_changed_userdata(local_handle);
213 /* TODO: IPv6 should be supported */
215 callback(ip_addr, NULL, data);
220 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
225 if (_connection_is_created() != true) {
226 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
227 "If multi-threaded, thread integrity be broken.");
231 for (list = conn_handle_list; list; list = list->next) {
232 handle = (connection_h)list->data;
233 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
237 static int __connection_set_ip_changed_callback(connection_h connection,
238 void *callback, void *user_data)
240 static __thread gint refcount = 0;
241 connection_handle_s *local_handle;
243 local_handle = (connection_handle_s *)connection;
247 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
248 __connection_cb_ip_change_cb, NULL);
251 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
254 __connection_get_ip_changed_callback(local_handle) != NULL) {
255 if (--refcount == 0) {
256 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
257 __connection_cb_ip_change_cb) < 0) {
258 CONNECTION_LOG(CONNECTION_ERROR,
259 "Error to de-register vconf callback(%d)", refcount);
261 CONNECTION_LOG(CONNECTION_INFO,
262 "Successfully de-registered(%d)", refcount);
268 local_handle->ip_changed_user_data = user_data;
269 local_handle->ip_changed_callback = callback;
271 return CONNECTION_ERROR_NONE;
274 static connection_address_changed_cb
275 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
277 return local_handle->proxy_changed_callback;
280 static void *__connection_get_proxy_changed_userdata(
281 connection_handle_s *local_handle)
283 return local_handle->proxy_changed_user_data;
286 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
290 connection_address_changed_cb callback;
291 connection_handle_s *local_handle = (connection_handle_s *)user_data;
293 if (__connection_check_handle_validity((connection_h)local_handle) != true)
296 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
298 callback = __connection_get_proxy_changed_callback(local_handle);
299 data = __connection_get_proxy_changed_userdata(local_handle);
300 /* TODO: IPv6 should be supported */
302 callback(proxy, NULL, data);
307 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
312 if (_connection_is_created() != true) {
313 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
314 "If multi-threaded, thread integrity be broken.");
318 for (list = conn_handle_list; list; list = list->next) {
319 handle = (connection_h)list->data;
320 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
324 static int __connection_set_proxy_changed_callback(connection_h connection,
325 void *callback, void *user_data)
327 static __thread gint refcount = 0;
328 connection_handle_s *local_handle;
330 local_handle = (connection_handle_s *)connection;
334 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
335 __connection_cb_proxy_change_cb, NULL);
338 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
341 __connection_get_proxy_changed_callback(local_handle) != NULL) {
342 if (--refcount == 0) {
343 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
344 __connection_cb_proxy_change_cb) < 0) {
345 CONNECTION_LOG(CONNECTION_ERROR,
346 "Error to de-register vconf callback(%d)", refcount);
348 CONNECTION_LOG(CONNECTION_INFO,
349 "Successfully de-registered(%d)", refcount);
355 local_handle->proxy_changed_user_data = user_data;
356 local_handle->proxy_changed_callback = callback;
358 return CONNECTION_ERROR_NONE;
361 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
362 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
364 connection_handle_s *local_handle = (connection_handle_s *)connection;
367 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
368 _connection_libnet_set_ethernet_cable_state_changed_cb(
369 __connection_cb_ethernet_cable_state_changed_cb);
372 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1)
373 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
376 local_handle->ethernet_cable_state_changed_callback = callback;
377 local_handle->ethernet_cable_state_changed_user_data = user_data;
378 return CONNECTION_ERROR_NONE;
381 static int __connection_get_handle_count(void)
383 return ((int)g_slist_length(conn_handle_list));
386 /* Connection Manager ********************************************************/
387 EXPORT_API int connection_create(connection_h *connection)
389 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
391 if (connection == NULL || __connection_check_handle_validity(*connection)) {
392 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
393 return CONNECTION_ERROR_INVALID_PARAMETER;
396 int rv = _connection_libnet_init();
397 if (rv == NET_ERR_ACCESS_DENIED) {
398 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
399 return CONNECTION_ERROR_PERMISSION_DENIED;
401 else if (rv != NET_ERR_NONE) {
402 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv);
403 return CONNECTION_ERROR_OPERATION_FAILED;
406 *connection = g_try_malloc0(sizeof(connection_handle_s));
407 if (*connection != NULL)
408 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
410 return CONNECTION_ERROR_OUT_OF_MEMORY;
412 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
414 return CONNECTION_ERROR_NONE;
417 EXPORT_API int connection_destroy(connection_h connection)
419 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
421 if (!(__connection_check_handle_validity(connection))) {
422 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
423 return CONNECTION_ERROR_INVALID_PARAMETER;
426 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
428 __connection_set_type_changed_callback(connection, NULL, NULL);
429 __connection_set_ip_changed_callback(connection, NULL, NULL);
430 __connection_set_proxy_changed_callback(connection, NULL, NULL);
431 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
433 conn_handle_list = g_slist_remove(conn_handle_list, connection);
438 if (__connection_get_handle_count() == 0) {
439 _connection_libnet_deinit();
440 _connection_callback_cleanup();
443 return CONNECTION_ERROR_NONE;
446 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
451 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
453 if (type == NULL || !(__connection_check_handle_validity(connection))) {
454 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
455 return CONNECTION_ERROR_INVALID_PARAMETER;
458 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
459 if (rv != VCONF_OK) {
460 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status);
461 return CONNECTION_ERROR_OPERATION_FAILED;
464 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
466 *type = __connection_convert_net_state(status);
468 return CONNECTION_ERROR_NONE;
471 EXPORT_API int connection_get_ip_address(connection_h connection,
472 connection_address_family_e address_family, char** ip_address)
474 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
476 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
477 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
478 return CONNECTION_ERROR_INVALID_PARAMETER;
481 switch (address_family) {
482 case CONNECTION_ADDRESS_FAMILY_IPV4:
483 case CONNECTION_ADDRESS_FAMILY_IPV6:
484 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
487 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
488 return CONNECTION_ERROR_INVALID_PARAMETER;
491 if (*ip_address == NULL) {
492 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed");
493 return CONNECTION_ERROR_OPERATION_FAILED;
496 return CONNECTION_ERROR_NONE;
499 EXPORT_API int connection_get_proxy(connection_h connection,
500 connection_address_family_e address_family, char** proxy)
502 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
504 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
505 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
506 return CONNECTION_ERROR_INVALID_PARAMETER;
509 switch (address_family) {
510 case CONNECTION_ADDRESS_FAMILY_IPV4:
511 case CONNECTION_ADDRESS_FAMILY_IPV6:
512 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
515 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
516 return CONNECTION_ERROR_INVALID_PARAMETER;
519 if (*proxy == NULL) {
520 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed");
521 return CONNECTION_ERROR_OPERATION_FAILED;
524 return CONNECTION_ERROR_NONE;
527 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
530 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
532 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
534 if(type == CONNECTION_TYPE_WIFI)
535 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
536 else if(type == CONNECTION_TYPE_ETHERNET)
537 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
539 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
540 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
541 return CONNECTION_ERROR_INVALID_PARAMETER;
545 case CONNECTION_TYPE_WIFI:
547 fp = fopen(WIFI_MAC_INFO_FILE, "r");
549 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE);
550 return CONNECTION_ERROR_OUT_OF_MEMORY;
553 if (fgets(buf, sizeof(buf), fp) == NULL) {
554 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE);
556 return CONNECTION_ERROR_OPERATION_FAILED;
559 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
561 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
562 if (*mac_addr == NULL) {
563 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
565 return CONNECTION_ERROR_OUT_OF_MEMORY;
567 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
570 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
572 if(*mac_addr == NULL) {
573 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS);
574 return CONNECTION_ERROR_OPERATION_FAILED;
578 case CONNECTION_TYPE_ETHERNET:
579 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
581 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
582 return CONNECTION_ERROR_OUT_OF_MEMORY;
585 if (fgets(buf, sizeof(buf), fp) == NULL) {
586 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
588 return CONNECTION_ERROR_OPERATION_FAILED;
591 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
593 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
594 if (*mac_addr == NULL) {
595 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
597 return CONNECTION_ERROR_OUT_OF_MEMORY;
600 g_strlcpy(*mac_addr, buf,CONNECTION_MAC_INFO_LENGTH + 1);
605 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
606 return CONNECTION_ERROR_INVALID_PARAMETER;
609 /* Checking Invalid MAC Address */
610 if((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
611 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
612 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr);
613 return CONNECTION_ERROR_INVALID_OPERATION;
616 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
618 return CONNECTION_ERROR_NONE;
621 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
625 int cellular_state = 0;
626 #if defined TIZEN_DUALSIM_ENABLE
630 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
632 if (state == NULL || !(__connection_check_handle_validity(connection))) {
633 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
634 return CONNECTION_ERROR_INVALID_PARAMETER;
637 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
638 if (rv != VCONF_OK) {
639 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
640 return CONNECTION_ERROR_OPERATION_FAILED;
643 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
644 *state = __connection_convert_cellular_state(status);
646 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
647 #if defined TIZEN_DUALSIM_ENABLE
648 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
649 if (rv != VCONF_OK) {
650 CONNECTION_LOG(CONNECTION_ERROR,
651 "Failed to get default subscriber id", sim_id);
652 return CONNECTION_ERROR_OPERATION_FAILED;
656 case CONNECTION_CELLULAR_SUBSCRIBER_1:
658 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
659 #if defined TIZEN_DUALSIM_ENABLE
662 case CONNECTION_CELLULAR_SUBSCRIBER_2:
663 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
667 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
668 return CONNECTION_ERROR_OPERATION_FAILED;
671 if (rv != VCONF_OK) {
672 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
673 return CONNECTION_ERROR_OPERATION_FAILED;
677 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
679 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
680 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
681 cellular_state == VCONFKEY_DNET_TRANSFER)
682 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
684 return CONNECTION_ERROR_NONE;
687 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
689 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
691 if (state == NULL || !(__connection_check_handle_validity(connection))) {
692 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
693 return CONNECTION_ERROR_INVALID_PARAMETER;
696 int rv = _connection_libnet_get_wifi_state(state);
697 if (rv != CONNECTION_ERROR_NONE) {
698 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv);
702 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
704 return CONNECTION_ERROR_NONE;
707 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
709 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
711 if (state == NULL || !(__connection_check_handle_validity(connection))) {
712 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
713 return CONNECTION_ERROR_INVALID_PARAMETER;
716 return _connection_libnet_get_ethernet_state(state);
719 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
721 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
723 if (state == NULL || !(__connection_check_handle_validity(connection))) {
724 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
725 return CONNECTION_ERROR_INVALID_PARAMETER;
728 return _connection_libnet_get_ethernet_cable_state(state);
731 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
732 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
734 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
736 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
737 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
738 return CONNECTION_ERROR_INVALID_PARAMETER;
741 return __connection_set_ethernet_cable_state_changed_cb(connection,
742 callback, user_data);
745 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
747 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
749 if ( !(__connection_check_handle_validity(connection)) ) {
750 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
751 return CONNECTION_ERROR_INVALID_PARAMETER;
754 return __connection_set_ethernet_cable_state_changed_cb(connection,
758 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
760 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
762 if (state == NULL || !(__connection_check_handle_validity(connection))) {
763 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
764 return CONNECTION_ERROR_INVALID_PARAMETER;
767 return _connection_libnet_get_bluetooth_state(state);
770 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
771 connection_type_changed_cb callback, void* user_data)
773 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
775 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
776 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
777 return CONNECTION_ERROR_INVALID_PARAMETER;
780 return __connection_set_type_changed_callback(connection, callback, user_data);
783 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
785 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
787 if (!(__connection_check_handle_validity(connection))) {
788 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
789 return CONNECTION_ERROR_INVALID_PARAMETER;
792 return __connection_set_type_changed_callback(connection, NULL, NULL);
795 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
796 connection_address_changed_cb callback, void* user_data)
798 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
800 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
801 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
802 return CONNECTION_ERROR_INVALID_PARAMETER;
805 return __connection_set_ip_changed_callback(connection, callback, user_data);
808 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
810 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
812 if (!(__connection_check_handle_validity(connection))) {
813 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
814 return CONNECTION_ERROR_INVALID_PARAMETER;
817 return __connection_set_ip_changed_callback(connection, NULL, NULL);
820 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
821 connection_address_changed_cb callback, void* user_data)
823 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
825 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
826 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
827 return CONNECTION_ERROR_INVALID_PARAMETER;
830 return __connection_set_proxy_changed_callback(connection, callback, user_data);
833 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
835 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
837 if (!(__connection_check_handle_validity(connection))) {
838 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
839 return CONNECTION_ERROR_INVALID_PARAMETER;
842 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
845 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
848 net_profile_info_t *profile_info = profile;
850 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
852 if (!(__connection_check_handle_validity(connection)) ||
853 !(_connection_libnet_check_profile_validity(profile))) {
854 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
855 return CONNECTION_ERROR_INVALID_PARAMETER;
858 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
859 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
860 return CONNECTION_ERROR_INVALID_PARAMETER;
863 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
864 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
865 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL");
866 return CONNECTION_ERROR_INVALID_PARAMETER;
869 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
870 (net_profile_info_t*)profile);
871 if (rv == NET_ERR_ACCESS_DENIED) {
872 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
873 return CONNECTION_ERROR_PERMISSION_DENIED;
874 } else if (rv != NET_ERR_NONE) {
875 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
876 return CONNECTION_ERROR_OPERATION_FAILED;
879 return CONNECTION_ERROR_NONE;
882 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
885 net_profile_info_t *profile_info = profile;
887 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
889 if (!(__connection_check_handle_validity(connection)) ||
890 !(_connection_libnet_check_profile_validity(profile))) {
891 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
892 return CONNECTION_ERROR_INVALID_PARAMETER;
895 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
896 profile_info->profile_type != NET_DEVICE_WIFI) {
897 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
898 return CONNECTION_ERROR_INVALID_PARAMETER;
901 rv = net_delete_profile(profile_info->ProfileName);
902 if (rv == NET_ERR_ACCESS_DENIED) {
903 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
904 return CONNECTION_ERROR_PERMISSION_DENIED;
905 } else if (rv != NET_ERR_NONE) {
906 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
907 return CONNECTION_ERROR_OPERATION_FAILED;
910 return CONNECTION_ERROR_NONE;
913 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
916 net_profile_info_t *profile_info = profile;
918 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
920 if (!(__connection_check_handle_validity(connection)) ||
921 !(_connection_libnet_check_profile_validity(profile))) {
922 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
923 return CONNECTION_ERROR_INVALID_PARAMETER;
926 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
927 if (rv == NET_ERR_ACCESS_DENIED) {
928 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
929 return CONNECTION_ERROR_PERMISSION_DENIED;
930 } else if (rv != NET_ERR_NONE) {
931 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
932 return CONNECTION_ERROR_OPERATION_FAILED;
935 return CONNECTION_ERROR_NONE;
938 EXPORT_API int connection_get_profile_iterator(connection_h connection,
939 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
941 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
943 if (!(__connection_check_handle_validity(connection)) ||
944 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
945 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
946 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
947 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
948 return CONNECTION_ERROR_INVALID_PARAMETER;
951 return _connection_libnet_get_profile_iterator(type, profile_iterator);
954 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
955 connection_profile_h* profile)
957 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
959 return _connection_libnet_get_iterator_next(profile_iterator, profile);
962 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
964 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
966 return _connection_libnet_iterator_has_next(profile_iterator);
969 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
971 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
973 return _connection_libnet_destroy_iterator(profile_iterator);
976 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
978 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
980 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
981 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
982 return CONNECTION_ERROR_INVALID_PARAMETER;
985 return _connection_libnet_get_current_profile(profile);
988 EXPORT_API int connection_get_default_cellular_service_profile(
989 connection_h connection, connection_cellular_service_type_e type,
990 connection_profile_h *profile)
992 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
994 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
995 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
996 return CONNECTION_ERROR_INVALID_PARAMETER;
999 return _connection_libnet_get_cellular_service_profile(type, profile);
1002 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1003 connection_cellular_service_type_e type, connection_profile_h profile)
1005 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1007 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1008 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1009 return CONNECTION_ERROR_INVALID_PARAMETER;
1012 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1015 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1016 connection_cellular_service_type_e type, connection_profile_h profile,
1017 connection_set_default_cb callback, void* user_data)
1019 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1021 if (!(__connection_check_handle_validity(connection)) ||
1022 profile == NULL || callback == NULL) {
1023 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1024 return CONNECTION_ERROR_INVALID_PARAMETER;
1027 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1030 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1031 connection_opened_cb callback, void* user_data)
1033 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1035 if (!(__connection_check_handle_validity(connection)) ||
1036 profile == NULL || callback == NULL) {
1037 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1038 return CONNECTION_ERROR_INVALID_PARAMETER;
1041 return _connection_libnet_open_profile(profile, callback, user_data);
1044 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1045 connection_closed_cb callback, void* user_data)
1047 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1049 if (!(__connection_check_handle_validity(connection)) ||
1050 profile == NULL || callback == NULL) {
1051 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1052 return CONNECTION_ERROR_INVALID_PARAMETER;
1055 return _connection_libnet_close_profile(profile, callback, user_data);
1058 EXPORT_API int connection_reset_profile(connection_h connection,
1059 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1061 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1063 if (!(__connection_check_handle_validity(connection))) {
1064 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1065 return CONNECTION_ERROR_INVALID_PARAMETER;
1068 if(id < 0 || id > 1) {
1069 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1070 return CONNECTION_ERROR_INVALID_PARAMETER;
1073 return _connection_libnet_reset_profile(type, id, callback, user_data);
1076 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1078 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1080 if (!(__connection_check_handle_validity(connection)) ||
1081 interface_name == NULL || host_address == NULL) {
1082 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1083 return CONNECTION_ERROR_INVALID_PARAMETER;
1086 return _connection_libnet_add_route(interface_name, host_address);
1089 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1091 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1093 if (!(__connection_check_handle_validity(connection)) ||
1094 interface_name == NULL || host_address == NULL) {
1095 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1096 return CONNECTION_ERROR_INVALID_PARAMETER;
1099 return _connection_libnet_remove_route(interface_name, host_address);
1102 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1104 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1106 if (!(__connection_check_handle_validity(connection)) ||
1107 interface_name == NULL || host_address == NULL) {
1108 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1109 return CONNECTION_ERROR_INVALID_PARAMETER;
1112 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1115 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1117 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1119 if (!(__connection_check_handle_validity(connection)) ||
1120 interface_name == NULL || host_address == NULL) {
1121 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1122 return CONNECTION_ERROR_INVALID_PARAMETER;
1125 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1128 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1130 int rv = VCONF_OK, rv1 = VCONF_OK;
1131 int last_size = 0, size = 0;
1132 #if defined TIZEN_DUALSIM_ENABLE
1136 if (llsize == NULL) {
1137 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1138 return CONNECTION_ERROR_INVALID_PARAMETER;
1141 switch (statistics_type) {
1142 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1143 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1144 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1145 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1148 return CONNECTION_ERROR_INVALID_PARAMETER;
1151 #if defined TIZEN_DUALSIM_ENABLE
1152 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1153 if (rv != VCONF_OK) {
1154 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1156 return CONNECTION_ERROR_OPERATION_FAILED;
1162 switch (statistics_type) {
1163 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1164 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1166 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1167 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1169 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1170 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1171 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1173 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1174 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1175 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1178 #if defined TIZEN_DUALSIM_ENABLE
1181 switch (statistics_type) {
1182 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1183 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1185 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1186 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1188 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1189 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1190 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1192 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1193 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1194 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1200 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1201 return CONNECTION_ERROR_OPERATION_FAILED;
1205 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1206 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics");
1207 return CONNECTION_ERROR_OPERATION_FAILED;
1210 *llsize = (long long)(last_size * 1000 + size * 1000);
1211 CONNECTION_LOG(CONNECTION_INFO,"%lld bytes", *llsize);
1213 return CONNECTION_ERROR_NONE;
1216 static int __get_statistic(connection_type_e connection_type,
1217 connection_statistics_type_e statistics_type, long long *llsize)
1220 unsigned long long ull_size;
1222 if (llsize == NULL) {
1223 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1224 return CONNECTION_ERROR_INVALID_PARAMETER;
1227 rv = _connection_libnet_check_get_privilege();
1228 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1230 else if (rv != CONNECTION_ERROR_NONE) {
1231 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics");
1232 return CONNECTION_ERROR_OPERATION_FAILED;
1235 if (connection_type == CONNECTION_TYPE_CELLULAR)
1236 return __get_cellular_statistic(statistics_type, llsize);
1237 else if (connection_type == CONNECTION_TYPE_WIFI) {
1238 switch (statistics_type) {
1239 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1240 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1242 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1243 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1245 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1246 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1248 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1249 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1252 return CONNECTION_ERROR_INVALID_PARAMETER;
1255 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1256 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1258 else if (rv != CONNECTION_ERROR_NONE) {
1259 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
1261 return CONNECTION_ERROR_OPERATION_FAILED;
1264 CONNECTION_LOG(CONNECTION_INFO,"%lld bytes", ull_size);
1265 *llsize = (long long)ull_size;
1267 return CONNECTION_ERROR_INVALID_PARAMETER;
1269 return CONNECTION_ERROR_NONE;
1272 static int __reset_statistic(connection_type_e connection_type,
1273 connection_statistics_type_e statistics_type)
1279 if (connection_type == CONNECTION_TYPE_CELLULAR)
1280 conn_type = NET_DEVICE_CELLULAR;
1281 else if (connection_type == CONNECTION_TYPE_WIFI)
1282 conn_type = NET_DEVICE_WIFI;
1284 return CONNECTION_ERROR_INVALID_PARAMETER;
1286 switch (statistics_type) {
1287 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1288 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1290 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1291 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1293 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1294 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1296 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1297 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1300 return CONNECTION_ERROR_INVALID_PARAMETER;
1303 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1304 if (rv != CONNECTION_ERROR_NONE)
1307 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success");
1309 return CONNECTION_ERROR_NONE;
1312 EXPORT_API int connection_get_statistics(connection_h connection,
1313 connection_type_e connection_type,
1314 connection_statistics_type_e statistics_type, long long* size)
1316 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1318 if(connection_type == CONNECTION_TYPE_CELLULAR )
1319 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1320 else if(connection_type == CONNECTION_TYPE_WIFI)
1321 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1323 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1324 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1325 return CONNECTION_ERROR_INVALID_PARAMETER;
1328 return __get_statistic(connection_type, statistics_type, size);
1331 EXPORT_API int connection_reset_statistics(connection_h connection,
1332 connection_type_e connection_type,
1333 connection_statistics_type_e statistics_type)
1335 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1337 if(connection_type == CONNECTION_TYPE_CELLULAR )
1338 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1339 else if(connection_type == CONNECTION_TYPE_WIFI)
1340 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1342 if (!__connection_check_handle_validity(connection)) {
1343 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1344 return CONNECTION_ERROR_INVALID_PARAMETER;
1347 return __reset_statistic(connection_type, statistics_type);