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:
546 fp = fopen(WIFI_MAC_INFO_FILE, "r");
548 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE);
549 return CONNECTION_ERROR_OUT_OF_MEMORY;
552 if (fgets(buf, sizeof(buf), fp) == NULL) {
553 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE);
555 return CONNECTION_ERROR_OPERATION_FAILED;
558 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
560 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
561 if (*mac_addr == NULL) {
562 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
564 return CONNECTION_ERROR_OUT_OF_MEMORY;
566 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
569 case CONNECTION_TYPE_ETHERNET:
570 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
572 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
573 return CONNECTION_ERROR_OUT_OF_MEMORY;
576 if (fgets(buf, sizeof(buf), fp) == NULL) {
577 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
579 return CONNECTION_ERROR_OPERATION_FAILED;
582 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
584 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
585 if (*mac_addr == NULL) {
586 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
588 return CONNECTION_ERROR_OUT_OF_MEMORY;
591 g_strlcpy(*mac_addr, buf,CONNECTION_MAC_INFO_LENGTH + 1);
596 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
597 return CONNECTION_ERROR_INVALID_PARAMETER;
600 /* Checking Invalid MAC Address */
601 if((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
602 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
603 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr);
604 return CONNECTION_ERROR_INVALID_OPERATION;
607 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
609 return CONNECTION_ERROR_NONE;
612 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
616 int cellular_state = 0;
617 #if defined TIZEN_DUALSIM_ENABLE
621 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
623 if (state == NULL || !(__connection_check_handle_validity(connection))) {
624 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
625 return CONNECTION_ERROR_INVALID_PARAMETER;
628 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
629 if (rv != VCONF_OK) {
630 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
631 return CONNECTION_ERROR_OPERATION_FAILED;
634 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
635 *state = __connection_convert_cellular_state(status);
637 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
638 #if defined TIZEN_DUALSIM_ENABLE
639 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
640 if (rv != VCONF_OK) {
641 CONNECTION_LOG(CONNECTION_ERROR,
642 "Failed to get default subscriber id", sim_id);
643 return CONNECTION_ERROR_OPERATION_FAILED;
647 case CONNECTION_CELLULAR_SUBSCRIBER_1:
649 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
650 #if defined TIZEN_DUALSIM_ENABLE
653 case CONNECTION_CELLULAR_SUBSCRIBER_2:
654 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
658 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
659 return CONNECTION_ERROR_OPERATION_FAILED;
662 if (rv != VCONF_OK) {
663 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
664 return CONNECTION_ERROR_OPERATION_FAILED;
668 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
670 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
671 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
672 cellular_state == VCONFKEY_DNET_TRANSFER)
673 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
675 return CONNECTION_ERROR_NONE;
678 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
680 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
682 if (state == NULL || !(__connection_check_handle_validity(connection))) {
683 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
684 return CONNECTION_ERROR_INVALID_PARAMETER;
687 int rv = _connection_libnet_get_wifi_state(state);
688 if (rv != CONNECTION_ERROR_NONE) {
689 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv);
693 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
695 return CONNECTION_ERROR_NONE;
698 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
700 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
702 if (state == NULL || !(__connection_check_handle_validity(connection))) {
703 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
704 return CONNECTION_ERROR_INVALID_PARAMETER;
707 return _connection_libnet_get_ethernet_state(state);
710 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
712 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
714 if (state == NULL || !(__connection_check_handle_validity(connection))) {
715 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
716 return CONNECTION_ERROR_INVALID_PARAMETER;
719 return _connection_libnet_get_ethernet_cable_state(state);
722 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
723 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
725 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
727 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
728 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
729 return CONNECTION_ERROR_INVALID_PARAMETER;
732 return __connection_set_ethernet_cable_state_changed_cb(connection,
733 callback, user_data);
736 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
738 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
740 if ( !(__connection_check_handle_validity(connection)) ) {
741 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
742 return CONNECTION_ERROR_INVALID_PARAMETER;
745 return __connection_set_ethernet_cable_state_changed_cb(connection,
749 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
751 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
753 if (state == NULL || !(__connection_check_handle_validity(connection))) {
754 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
755 return CONNECTION_ERROR_INVALID_PARAMETER;
758 return _connection_libnet_get_bluetooth_state(state);
761 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
762 connection_type_changed_cb callback, void* user_data)
764 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
766 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
767 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
768 return CONNECTION_ERROR_INVALID_PARAMETER;
771 return __connection_set_type_changed_callback(connection, callback, user_data);
774 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
776 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
778 if (!(__connection_check_handle_validity(connection))) {
779 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
780 return CONNECTION_ERROR_INVALID_PARAMETER;
783 return __connection_set_type_changed_callback(connection, NULL, NULL);
786 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
787 connection_address_changed_cb callback, void* user_data)
789 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
791 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
792 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
793 return CONNECTION_ERROR_INVALID_PARAMETER;
796 return __connection_set_ip_changed_callback(connection, callback, user_data);
799 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
801 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
803 if (!(__connection_check_handle_validity(connection))) {
804 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
805 return CONNECTION_ERROR_INVALID_PARAMETER;
808 return __connection_set_ip_changed_callback(connection, NULL, NULL);
811 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
812 connection_address_changed_cb callback, void* user_data)
814 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
816 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
817 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
818 return CONNECTION_ERROR_INVALID_PARAMETER;
821 return __connection_set_proxy_changed_callback(connection, callback, user_data);
824 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
826 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
828 if (!(__connection_check_handle_validity(connection))) {
829 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
830 return CONNECTION_ERROR_INVALID_PARAMETER;
833 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
836 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
839 net_profile_info_t *profile_info = profile;
841 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
843 if (!(__connection_check_handle_validity(connection)) ||
844 !(_connection_libnet_check_profile_validity(profile))) {
845 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
846 return CONNECTION_ERROR_INVALID_PARAMETER;
849 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
850 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
851 return CONNECTION_ERROR_INVALID_PARAMETER;
854 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
855 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
856 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL");
857 return CONNECTION_ERROR_INVALID_PARAMETER;
860 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
861 (net_profile_info_t*)profile);
862 if (rv == NET_ERR_ACCESS_DENIED) {
863 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
864 return CONNECTION_ERROR_PERMISSION_DENIED;
865 } else if (rv != NET_ERR_NONE) {
866 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
867 return CONNECTION_ERROR_OPERATION_FAILED;
870 return CONNECTION_ERROR_NONE;
873 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
876 net_profile_info_t *profile_info = profile;
878 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
880 if (!(__connection_check_handle_validity(connection)) ||
881 !(_connection_libnet_check_profile_validity(profile))) {
882 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
883 return CONNECTION_ERROR_INVALID_PARAMETER;
886 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
887 profile_info->profile_type != NET_DEVICE_WIFI) {
888 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
889 return CONNECTION_ERROR_INVALID_PARAMETER;
892 rv = net_delete_profile(profile_info->ProfileName);
893 if (rv == NET_ERR_ACCESS_DENIED) {
894 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
895 return CONNECTION_ERROR_PERMISSION_DENIED;
896 } else if (rv != NET_ERR_NONE) {
897 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
898 return CONNECTION_ERROR_OPERATION_FAILED;
901 return CONNECTION_ERROR_NONE;
904 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
907 net_profile_info_t *profile_info = profile;
909 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
911 if (!(__connection_check_handle_validity(connection)) ||
912 !(_connection_libnet_check_profile_validity(profile))) {
913 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
914 return CONNECTION_ERROR_INVALID_PARAMETER;
917 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
918 if (rv == NET_ERR_ACCESS_DENIED) {
919 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
920 return CONNECTION_ERROR_PERMISSION_DENIED;
921 } else if (rv != NET_ERR_NONE) {
922 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
923 return CONNECTION_ERROR_OPERATION_FAILED;
926 return CONNECTION_ERROR_NONE;
929 EXPORT_API int connection_get_profile_iterator(connection_h connection,
930 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
932 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
934 if (!(__connection_check_handle_validity(connection)) ||
935 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
936 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
937 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
938 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
939 return CONNECTION_ERROR_INVALID_PARAMETER;
942 return _connection_libnet_get_profile_iterator(type, profile_iterator);
945 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
946 connection_profile_h* profile)
948 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
950 return _connection_libnet_get_iterator_next(profile_iterator, profile);
953 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
955 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
957 return _connection_libnet_iterator_has_next(profile_iterator);
960 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
962 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
964 return _connection_libnet_destroy_iterator(profile_iterator);
967 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
969 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
971 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
972 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
973 return CONNECTION_ERROR_INVALID_PARAMETER;
976 return _connection_libnet_get_current_profile(profile);
979 EXPORT_API int connection_get_default_cellular_service_profile(
980 connection_h connection, connection_cellular_service_type_e type,
981 connection_profile_h *profile)
983 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
985 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
986 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
987 return CONNECTION_ERROR_INVALID_PARAMETER;
990 return _connection_libnet_get_cellular_service_profile(type, profile);
993 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
994 connection_cellular_service_type_e type, connection_profile_h profile)
996 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
998 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
999 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1000 return CONNECTION_ERROR_INVALID_PARAMETER;
1003 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1006 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1007 connection_cellular_service_type_e type, connection_profile_h profile,
1008 connection_set_default_cb callback, void* user_data)
1010 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1012 if (!(__connection_check_handle_validity(connection)) ||
1013 profile == NULL || callback == NULL) {
1014 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1015 return CONNECTION_ERROR_INVALID_PARAMETER;
1018 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1021 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1022 connection_opened_cb callback, void* user_data)
1024 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1026 if (!(__connection_check_handle_validity(connection)) ||
1027 profile == NULL || callback == NULL) {
1028 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1029 return CONNECTION_ERROR_INVALID_PARAMETER;
1032 return _connection_libnet_open_profile(profile, callback, user_data);
1035 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1036 connection_closed_cb callback, void* user_data)
1038 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1040 if (!(__connection_check_handle_validity(connection)) ||
1041 profile == NULL || callback == NULL) {
1042 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1043 return CONNECTION_ERROR_INVALID_PARAMETER;
1046 return _connection_libnet_close_profile(profile, callback, user_data);
1049 EXPORT_API int connection_reset_profile(connection_h connection,
1050 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1052 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1054 if (!(__connection_check_handle_validity(connection))) {
1055 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1056 return CONNECTION_ERROR_INVALID_PARAMETER;
1059 if(id < 0 || id > 1) {
1060 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1061 return CONNECTION_ERROR_INVALID_PARAMETER;
1064 return _connection_libnet_reset_profile(type, id, callback, user_data);
1067 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1069 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1071 if (!(__connection_check_handle_validity(connection)) ||
1072 interface_name == NULL || host_address == NULL) {
1073 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1074 return CONNECTION_ERROR_INVALID_PARAMETER;
1077 return _connection_libnet_add_route(interface_name, host_address);
1080 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1082 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1084 if (!(__connection_check_handle_validity(connection)) ||
1085 interface_name == NULL || host_address == NULL) {
1086 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1087 return CONNECTION_ERROR_INVALID_PARAMETER;
1090 return _connection_libnet_remove_route(interface_name, host_address);
1093 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1095 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1097 if (!(__connection_check_handle_validity(connection)) ||
1098 interface_name == NULL || host_address == NULL) {
1099 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1100 return CONNECTION_ERROR_INVALID_PARAMETER;
1103 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1106 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1108 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1110 if (!(__connection_check_handle_validity(connection)) ||
1111 interface_name == NULL || host_address == NULL) {
1112 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1113 return CONNECTION_ERROR_INVALID_PARAMETER;
1116 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1119 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1121 int rv = VCONF_OK, rv1 = VCONF_OK;
1122 int last_size = 0, size = 0;
1123 #if defined TIZEN_DUALSIM_ENABLE
1127 if (llsize == NULL) {
1128 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1129 return CONNECTION_ERROR_INVALID_PARAMETER;
1132 switch (statistics_type) {
1133 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1134 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1135 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1136 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1139 return CONNECTION_ERROR_INVALID_PARAMETER;
1142 #if defined TIZEN_DUALSIM_ENABLE
1143 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1144 if (rv != VCONF_OK) {
1145 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1147 return CONNECTION_ERROR_OPERATION_FAILED;
1153 switch (statistics_type) {
1154 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1155 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1157 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1158 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1160 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1161 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1162 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1164 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1165 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1166 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1169 #if defined TIZEN_DUALSIM_ENABLE
1172 switch (statistics_type) {
1173 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1174 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1176 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1177 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1179 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1180 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1181 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1183 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1184 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1185 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1191 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1192 return CONNECTION_ERROR_OPERATION_FAILED;
1196 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1197 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics");
1198 return CONNECTION_ERROR_OPERATION_FAILED;
1201 *llsize = (long long)(last_size * 1000 + size * 1000);
1202 CONNECTION_LOG(CONNECTION_INFO,"%lld bytes", *llsize);
1204 return CONNECTION_ERROR_NONE;
1207 static int __get_statistic(connection_type_e connection_type,
1208 connection_statistics_type_e statistics_type, long long *llsize)
1211 unsigned long long ull_size;
1213 if (llsize == NULL) {
1214 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1215 return CONNECTION_ERROR_INVALID_PARAMETER;
1218 rv = _connection_libnet_check_get_privilege();
1219 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1221 else if (rv != CONNECTION_ERROR_NONE) {
1222 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics");
1223 return CONNECTION_ERROR_OPERATION_FAILED;
1226 if (connection_type == CONNECTION_TYPE_CELLULAR)
1227 return __get_cellular_statistic(statistics_type, llsize);
1228 else if (connection_type == CONNECTION_TYPE_WIFI) {
1229 switch (statistics_type) {
1230 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1231 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1233 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1234 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1236 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1237 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1239 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1240 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1243 return CONNECTION_ERROR_INVALID_PARAMETER;
1246 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1247 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1249 else if (rv != CONNECTION_ERROR_NONE) {
1250 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
1252 return CONNECTION_ERROR_OPERATION_FAILED;
1255 CONNECTION_LOG(CONNECTION_INFO,"%lld bytes", ull_size);
1256 *llsize = (long long)ull_size;
1258 return CONNECTION_ERROR_INVALID_PARAMETER;
1260 return CONNECTION_ERROR_NONE;
1263 static int __reset_statistic(connection_type_e connection_type,
1264 connection_statistics_type_e statistics_type)
1270 if (connection_type == CONNECTION_TYPE_CELLULAR)
1271 conn_type = NET_DEVICE_CELLULAR;
1272 else if (connection_type == CONNECTION_TYPE_WIFI)
1273 conn_type = NET_DEVICE_WIFI;
1275 return CONNECTION_ERROR_INVALID_PARAMETER;
1277 switch (statistics_type) {
1278 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1279 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1281 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1282 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1284 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1285 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1287 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1288 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1291 return CONNECTION_ERROR_INVALID_PARAMETER;
1294 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1295 if (rv != CONNECTION_ERROR_NONE)
1298 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success");
1300 return CONNECTION_ERROR_NONE;
1303 EXPORT_API int connection_get_statistics(connection_h connection,
1304 connection_type_e connection_type,
1305 connection_statistics_type_e statistics_type, long long* size)
1307 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1309 if(connection_type == CONNECTION_TYPE_CELLULAR )
1310 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1311 else if(connection_type == CONNECTION_TYPE_WIFI)
1312 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1314 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1315 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1316 return CONNECTION_ERROR_INVALID_PARAMETER;
1319 return __get_statistic(connection_type, statistics_type, size);
1322 EXPORT_API int connection_reset_statistics(connection_h connection,
1323 connection_type_e connection_type,
1324 connection_statistics_type_e statistics_type)
1326 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1328 if(connection_type == CONNECTION_TYPE_CELLULAR )
1329 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1330 else if(connection_type == CONNECTION_TYPE_WIFI)
1331 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1333 if (!__connection_check_handle_validity(connection)) {
1334 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1335 return CONNECTION_ERROR_INVALID_PARAMETER;
1338 return __reset_statistic(connection_type, statistics_type);