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.
21 #include <vconf/vconf.h>
22 #include <system_info.h>
24 #include "net_connection_private.h"
26 static __thread GSList *conn_handle_list = NULL;
27 static int tv_profile = -1; // Unknown
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;
37 case VCONFKEY_NETWORK_ETHERNET:
38 return CONNECTION_TYPE_ETHERNET;
39 case VCONFKEY_NETWORK_BLUETOOTH:
40 return CONNECTION_TYPE_BT;
41 case VCONFKEY_NETWORK_DEFAULT_PROXY:
42 return CONNECTION_TYPE_NET_PROXY;
44 return CONNECTION_TYPE_DISCONNECTED;
48 static int __connection_convert_cellular_state(int status)
51 case VCONFKEY_NETWORK_CELLULAR_ON:
52 return CONNECTION_CELLULAR_STATE_AVAILABLE;
53 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
54 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
55 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
56 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
57 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
58 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
60 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
64 static bool __connection_check_handle_validity(connection_h connection)
68 if (connection == NULL)
71 if (g_slist_find(conn_handle_list, connection) != NULL)
77 static connection_type_changed_cb
78 __connection_get_type_changed_callback(connection_handle_s *local_handle)
80 return local_handle->type_changed_callback;
83 static void *__connection_get_type_changed_userdata(
84 connection_handle_s *local_handle)
86 return local_handle->type_changed_user_data;
89 static gboolean __connection_cb_type_changed_cb_idle(gpointer user_data)
93 connection_type_changed_cb callback;
94 connection_handle_s *local_handle = (connection_handle_s *)user_data;
96 if (__connection_check_handle_validity((connection_h)local_handle) != true)
99 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status) != 0)
102 state = __connection_convert_net_state(status);
104 callback = __connection_get_type_changed_callback(local_handle);
105 data = __connection_get_type_changed_userdata(local_handle);
107 callback(state, data);
112 static void __connection_cb_type_change_cb(keynode_t *node, void *user_data)
117 if (_connection_is_created() != true) {
118 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
119 "If multi-threaded, thread integrity be broken.");
123 for (list = conn_handle_list; list; list = list->next) {
124 handle = (connection_h)list->data;
125 _connection_callback_add(__connection_cb_type_changed_cb_idle, (gpointer)handle);
129 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
131 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
135 for (list = conn_handle_list; list; list = list->next) {
136 connection_handle_s *local_handle = (connection_handle_s *)list->data;
137 if (local_handle->ethernet_cable_state_changed_callback)
138 local_handle->ethernet_cable_state_changed_callback(state,
139 local_handle->ethernet_cable_state_changed_user_data);
143 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
148 for (list = conn_handle_list; list; list = list->next) {
149 connection_handle_s *local_handle = (connection_handle_s *)list->data;
150 if (local_handle->ethernet_cable_state_changed_callback) count++;
156 static int __connection_set_type_changed_callback(connection_h connection,
157 void *callback, void *user_data)
159 static __thread gint refcount = 0;
160 connection_handle_s *local_handle;
162 local_handle = (connection_handle_s *)connection;
166 vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS,
167 __connection_cb_type_change_cb, NULL);
170 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
173 __connection_get_type_changed_callback(local_handle) != NULL) {
174 if (--refcount == 0) {
175 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
176 __connection_cb_type_change_cb) < 0) {
177 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
178 "Error to de-register vconf callback(%d)", refcount);
180 CONNECTION_LOG(CONNECTION_INFO,
181 "Successfully de-registered(%d)", refcount);
187 local_handle->type_changed_user_data = user_data;
188 local_handle->type_changed_callback = callback;
190 return CONNECTION_ERROR_NONE;
193 static connection_address_changed_cb
194 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
196 return local_handle->ip_changed_callback;
199 static void *__connection_get_ip_changed_userdata(
200 connection_handle_s *local_handle)
202 return local_handle->ip_changed_user_data;
205 static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
209 connection_address_changed_cb callback;
210 connection_handle_s *local_handle = (connection_handle_s *)user_data;
212 if (__connection_check_handle_validity((connection_h)local_handle) != true)
215 ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
217 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
218 "vconf_get_str(VCONFKEY_NETWORK_IP) is Failed");
220 callback = __connection_get_ip_changed_callback(local_handle);
221 data = __connection_get_ip_changed_userdata(local_handle);
222 /* TODO: IPv6 should be supported */
224 callback(ip_addr, NULL, data);
231 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
236 if (_connection_is_created() != true) {
237 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
238 "If multi-threaded, thread integrity be broken.");
242 for (list = conn_handle_list; list; list = list->next) {
243 handle = (connection_h)list->data;
244 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
248 static int __connection_set_ip_changed_callback(connection_h connection,
249 void *callback, void *user_data)
251 static __thread gint refcount = 0;
252 connection_handle_s *local_handle;
254 local_handle = (connection_handle_s *)connection;
258 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
259 __connection_cb_ip_change_cb, NULL);
262 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
265 __connection_get_ip_changed_callback(local_handle) != NULL) {
266 if (--refcount == 0) {
267 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
268 __connection_cb_ip_change_cb) < 0) {
269 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
270 "Error to de-register vconf callback(%d)", refcount);
272 CONNECTION_LOG(CONNECTION_INFO,
273 "Successfully de-registered(%d)", refcount);
279 local_handle->ip_changed_user_data = user_data;
280 local_handle->ip_changed_callback = callback;
282 return CONNECTION_ERROR_NONE;
285 static connection_address_changed_cb
286 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
288 return local_handle->proxy_changed_callback;
291 static void *__connection_get_proxy_changed_userdata(
292 connection_handle_s *local_handle)
294 return local_handle->proxy_changed_user_data;
297 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
301 connection_address_changed_cb callback;
302 connection_handle_s *local_handle = (connection_handle_s *)user_data;
304 if (__connection_check_handle_validity((connection_h)local_handle) != true)
307 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
309 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
310 "vconf_get_str(VCONFKEY_NETWORK_PROXY) is Failed");
312 callback = __connection_get_proxy_changed_callback(local_handle);
313 data = __connection_get_proxy_changed_userdata(local_handle);
314 /* TODO: IPv6 should be supported */
316 callback(proxy, NULL, data);
323 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
328 if (_connection_is_created() != true) {
329 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
330 "If multi-threaded, thread integrity be broken.");
334 for (list = conn_handle_list; list; list = list->next) {
335 handle = (connection_h)list->data;
336 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
340 static int __connection_set_proxy_changed_callback(connection_h connection,
341 void *callback, void *user_data)
343 static __thread gint refcount = 0;
344 connection_handle_s *local_handle;
346 local_handle = (connection_handle_s *)connection;
350 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
351 __connection_cb_proxy_change_cb, NULL);
354 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
357 __connection_get_proxy_changed_callback(local_handle) != NULL) {
358 if (--refcount == 0) {
359 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
360 __connection_cb_proxy_change_cb) < 0) {
361 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
362 "Error to de-register vconf callback(%d)", refcount);
364 CONNECTION_LOG(CONNECTION_INFO,
365 "Successfully de-registered(%d)", refcount);
371 local_handle->proxy_changed_user_data = user_data;
372 local_handle->proxy_changed_callback = callback;
374 return CONNECTION_ERROR_NONE;
377 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
378 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
380 connection_handle_s *local_handle = (connection_handle_s *)connection;
383 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
384 _connection_libnet_set_ethernet_cable_state_changed_cb(
385 __connection_cb_ethernet_cable_state_changed_cb);
388 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1)
389 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
392 local_handle->ethernet_cable_state_changed_callback = callback;
393 local_handle->ethernet_cable_state_changed_user_data = user_data;
394 return CONNECTION_ERROR_NONE;
398 static int __connection_get_handle_count(void)
400 return ((int)g_slist_length(conn_handle_list));
403 /* Connection Manager ********************************************************/
404 EXPORT_API int connection_create(connection_h *connection)
406 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
408 if (connection == NULL || __connection_check_handle_validity(*connection)) {
409 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
410 return CONNECTION_ERROR_INVALID_PARAMETER;
413 int rv = _connection_libnet_init();
414 if (rv == NET_ERR_ACCESS_DENIED) {
415 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
416 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
417 } else if (rv != NET_ERR_NONE) {
418 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
419 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
422 *connection = g_try_malloc0(sizeof(connection_handle_s));
423 if (*connection != NULL)
424 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
426 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
428 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
430 return CONNECTION_ERROR_NONE;
433 EXPORT_API int connection_destroy(connection_h connection)
435 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
437 if (!(__connection_check_handle_validity(connection))) {
438 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
439 return CONNECTION_ERROR_INVALID_PARAMETER;
442 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
444 __connection_set_type_changed_callback(connection, NULL, NULL);
445 __connection_set_ip_changed_callback(connection, NULL, NULL);
446 __connection_set_proxy_changed_callback(connection, NULL, NULL);
447 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
449 conn_handle_list = g_slist_remove(conn_handle_list, connection);
454 if (__connection_get_handle_count() == 0) {
455 _connection_libnet_deinit();
456 _connection_callback_cleanup();
459 return CONNECTION_ERROR_NONE;
462 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
467 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
469 if (type == NULL || !(__connection_check_handle_validity(connection))) {
470 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
471 return CONNECTION_ERROR_INVALID_PARAMETER;
474 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
475 if (rv != VCONF_OK) {
476 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
477 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
480 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
482 *type = __connection_convert_net_state(status);
484 return CONNECTION_ERROR_NONE;
487 EXPORT_API int connection_get_ip_address(connection_h connection,
488 connection_address_family_e address_family, char** ip_address)
490 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
492 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
493 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
494 return CONNECTION_ERROR_INVALID_PARAMETER;
497 switch (address_family) {
498 case CONNECTION_ADDRESS_FAMILY_IPV4:
499 case CONNECTION_ADDRESS_FAMILY_IPV6:
500 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
503 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
504 return CONNECTION_ERROR_INVALID_PARAMETER;
507 if (*ip_address == NULL) {
508 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
509 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
512 return CONNECTION_ERROR_NONE;
515 EXPORT_API int connection_get_proxy(connection_h connection,
516 connection_address_family_e address_family, char** proxy)
518 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
520 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
521 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
522 return CONNECTION_ERROR_INVALID_PARAMETER;
525 switch (address_family) {
526 case CONNECTION_ADDRESS_FAMILY_IPV4:
527 case CONNECTION_ADDRESS_FAMILY_IPV6:
528 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
531 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
532 return CONNECTION_ERROR_INVALID_PARAMETER;
535 if (*proxy == NULL) {
536 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
537 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
540 return CONNECTION_ERROR_NONE;
543 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
546 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
548 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
550 if (type == CONNECTION_TYPE_WIFI)
551 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
552 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
553 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
555 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
556 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
557 return CONNECTION_ERROR_INVALID_PARAMETER;
561 case CONNECTION_TYPE_WIFI:
562 if (__builtin_expect(tv_profile == -1, 0)) {
564 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
565 if (*profileName == 't' || *profileName == 'T')
571 if (tv_profile == 1) {
572 fp = fopen(WIFI_MAC_INFO_FILE, "r");
574 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
575 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
578 if (fgets(buf, sizeof(buf), fp) == NULL) {
579 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
580 fclose(fp); //LCOV_EXCL_LINE
581 return CONNECTION_ERROR_OPERATION_FAILED;
584 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
586 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
587 if (*mac_addr == NULL) {
588 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
589 fclose(fp); //LCOV_EXCL_LINE
590 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
592 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
595 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
597 if (*mac_addr == NULL) {
598 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
599 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
604 case CONNECTION_TYPE_ETHERNET:
605 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
607 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
608 return CONNECTION_ERROR_OUT_OF_MEMORY;
611 if (fgets(buf, sizeof(buf), fp) == NULL) {
612 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
614 return CONNECTION_ERROR_OPERATION_FAILED;
617 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
619 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
620 if (*mac_addr == NULL) {
621 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
623 return CONNECTION_ERROR_OUT_OF_MEMORY;
626 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
632 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
633 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
636 /* Checking Invalid MAC Address */
637 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
638 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
639 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
640 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
643 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
645 return CONNECTION_ERROR_NONE;
649 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
653 int cellular_state = 0;
654 #if defined TIZEN_DUALSIM_ENABLE
658 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
660 if (state == NULL || !(__connection_check_handle_validity(connection))) {
661 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
662 return CONNECTION_ERROR_INVALID_PARAMETER;
665 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
666 if (rv != VCONF_OK) {
667 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
668 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
671 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
672 *state = __connection_convert_cellular_state(status);
674 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
675 #if defined TIZEN_DUALSIM_ENABLE
676 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
677 if (rv != VCONF_OK) {
678 CONNECTION_LOG(CONNECTION_ERROR,
679 "Failed to get default subscriber id", sim_id);
680 return CONNECTION_ERROR_OPERATION_FAILED;
684 case CONNECTION_CELLULAR_SUBSCRIBER_1:
686 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
687 #if defined TIZEN_DUALSIM_ENABLE
690 case CONNECTION_CELLULAR_SUBSCRIBER_2:
691 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
695 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
696 return CONNECTION_ERROR_OPERATION_FAILED;
699 if (rv != VCONF_OK) {
700 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
701 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
705 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
707 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
708 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
709 cellular_state == VCONFKEY_DNET_TRANSFER)
710 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
712 return CONNECTION_ERROR_NONE;
715 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
717 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
719 if (state == NULL || !(__connection_check_handle_validity(connection))) {
720 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
721 return CONNECTION_ERROR_INVALID_PARAMETER;
724 int rv = _connection_libnet_get_wifi_state(state);
725 if (rv != CONNECTION_ERROR_NONE) {
726 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
727 return rv; //LCOV_EXCL_LINE
730 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
732 return CONNECTION_ERROR_NONE;
736 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
738 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
740 if (state == NULL || !(__connection_check_handle_validity(connection))) {
741 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
742 return CONNECTION_ERROR_INVALID_PARAMETER;
745 return _connection_libnet_get_ethernet_state(state);
748 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
750 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
752 if (state == NULL || !(__connection_check_handle_validity(connection))) {
753 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
754 return CONNECTION_ERROR_INVALID_PARAMETER;
757 return _connection_libnet_get_ethernet_cable_state(state);
760 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
761 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
763 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
765 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
766 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
767 return CONNECTION_ERROR_INVALID_PARAMETER;
770 return __connection_set_ethernet_cable_state_changed_cb(connection,
771 callback, user_data);
774 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
776 CHECK_FEATURE_SUPPORTED(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_ethernet_cable_state_changed_cb(connection,
788 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
790 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
792 if (state == NULL || !(__connection_check_handle_validity(connection))) {
793 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
794 return CONNECTION_ERROR_INVALID_PARAMETER;
797 return _connection_libnet_get_bluetooth_state(state);
800 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
801 connection_type_changed_cb callback, void* user_data)
803 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
805 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
806 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
807 return CONNECTION_ERROR_INVALID_PARAMETER;
810 return __connection_set_type_changed_callback(connection, callback, user_data);
813 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
815 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
817 if (!(__connection_check_handle_validity(connection))) {
818 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
819 return CONNECTION_ERROR_INVALID_PARAMETER;
822 return __connection_set_type_changed_callback(connection, NULL, NULL);
825 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
826 connection_address_changed_cb callback, void* user_data)
828 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
830 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
831 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
832 return CONNECTION_ERROR_INVALID_PARAMETER;
835 return __connection_set_ip_changed_callback(connection, callback, user_data);
838 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
840 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
842 if (!(__connection_check_handle_validity(connection))) {
843 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
844 return CONNECTION_ERROR_INVALID_PARAMETER;
847 return __connection_set_ip_changed_callback(connection, NULL, NULL);
850 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
851 connection_address_changed_cb callback, void* user_data)
853 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
855 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
856 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
857 return CONNECTION_ERROR_INVALID_PARAMETER;
860 return __connection_set_proxy_changed_callback(connection, callback, user_data);
863 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
865 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
867 if (!(__connection_check_handle_validity(connection))) {
868 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
869 return CONNECTION_ERROR_INVALID_PARAMETER;
872 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
875 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
878 net_profile_info_t *profile_info = profile;
880 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
882 if (!(__connection_check_handle_validity(connection)) ||
883 !(_connection_libnet_check_profile_validity(profile))) {
884 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
885 return CONNECTION_ERROR_INVALID_PARAMETER;
888 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
889 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
890 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
893 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
894 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
895 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
896 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
899 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
900 (net_profile_info_t*)profile);
901 if (rv == NET_ERR_ACCESS_DENIED) {
902 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
903 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
904 } else if (rv != NET_ERR_NONE) {
905 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
906 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
909 return CONNECTION_ERROR_NONE;
912 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
915 net_profile_info_t *profile_info = profile;
917 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
919 if (!(__connection_check_handle_validity(connection)) ||
920 !(_connection_libnet_check_profile_validity(profile))) {
921 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
922 return CONNECTION_ERROR_INVALID_PARAMETER;
925 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
926 profile_info->profile_type != NET_DEVICE_WIFI) {
927 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
928 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
931 rv = net_delete_profile(profile_info->ProfileName);
932 if (rv == NET_ERR_ACCESS_DENIED) {
933 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
934 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
935 } else if (rv != NET_ERR_NONE) {
936 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
937 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
940 return CONNECTION_ERROR_NONE;
943 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
946 net_profile_info_t *profile_info = profile;
948 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
950 if (!(__connection_check_handle_validity(connection)) ||
951 !(_connection_libnet_check_profile_validity(profile))) {
952 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
953 return CONNECTION_ERROR_INVALID_PARAMETER;
956 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
957 if (rv == NET_ERR_ACCESS_DENIED) {
958 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
959 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
960 } else if (rv != NET_ERR_NONE) {
961 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
962 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
965 return CONNECTION_ERROR_NONE;
968 EXPORT_API int connection_get_profile_iterator(connection_h connection,
969 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
971 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
973 if (!(__connection_check_handle_validity(connection)) ||
974 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
975 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
976 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
977 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
978 return CONNECTION_ERROR_INVALID_PARAMETER;
981 return _connection_libnet_get_profile_iterator(type, profile_iterator);
984 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
985 connection_profile_h* profile)
987 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
989 return _connection_libnet_get_iterator_next(profile_iterator, profile);
992 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
994 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
996 return _connection_libnet_iterator_has_next(profile_iterator);
999 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1001 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1003 return _connection_libnet_destroy_iterator(profile_iterator);
1006 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1008 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1010 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1011 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1012 return CONNECTION_ERROR_INVALID_PARAMETER;
1015 return _connection_libnet_get_current_profile(profile);
1018 EXPORT_API int connection_get_default_cellular_service_profile(
1019 connection_h connection, connection_cellular_service_type_e type,
1020 connection_profile_h *profile)
1022 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1024 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1025 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1026 return CONNECTION_ERROR_INVALID_PARAMETER;
1029 return _connection_libnet_get_cellular_service_profile(type, profile);
1032 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1033 connection_cellular_service_type_e type, connection_profile_h profile)
1035 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1037 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1038 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1039 return CONNECTION_ERROR_INVALID_PARAMETER;
1042 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1045 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1046 connection_cellular_service_type_e type, connection_profile_h profile,
1047 connection_set_default_cb callback, void* user_data)
1049 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1051 if (!(__connection_check_handle_validity(connection)) ||
1052 profile == NULL || callback == NULL) {
1053 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1054 return CONNECTION_ERROR_INVALID_PARAMETER;
1057 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1060 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1061 connection_opened_cb callback, void* user_data)
1063 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1065 if (!(__connection_check_handle_validity(connection)) ||
1066 profile == NULL || callback == NULL) {
1067 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1068 return CONNECTION_ERROR_INVALID_PARAMETER;
1071 return _connection_libnet_open_profile(profile, callback, user_data);
1074 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1075 connection_closed_cb callback, void* user_data)
1077 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1079 if (!(__connection_check_handle_validity(connection)) ||
1080 profile == NULL || callback == NULL) {
1081 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1082 return CONNECTION_ERROR_INVALID_PARAMETER;
1085 return _connection_libnet_close_profile(profile, callback, user_data);
1088 EXPORT_API int connection_reset_profile(connection_h connection,
1089 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1091 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1093 if (!(__connection_check_handle_validity(connection))) {
1094 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1095 return CONNECTION_ERROR_INVALID_PARAMETER;
1098 if (id < 0 || id > 1) {
1099 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1100 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1103 return _connection_libnet_reset_profile(type, id, callback, user_data);
1106 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1108 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_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_add_route(interface_name, host_address);
1119 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1121 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1123 if (!(__connection_check_handle_validity(connection)) ||
1124 interface_name == NULL || host_address == NULL) {
1125 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1126 return CONNECTION_ERROR_INVALID_PARAMETER;
1129 return _connection_libnet_remove_route(interface_name, host_address);
1132 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1134 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1136 if (!(__connection_check_handle_validity(connection)) ||
1137 interface_name == NULL || host_address == NULL) {
1138 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1139 return CONNECTION_ERROR_INVALID_PARAMETER;
1142 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1145 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1147 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1149 if (!(__connection_check_handle_validity(connection)) ||
1150 interface_name == NULL || host_address == NULL) {
1151 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1152 return CONNECTION_ERROR_INVALID_PARAMETER;
1155 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1158 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1160 int rv = VCONF_OK, rv1 = VCONF_OK;
1161 int last_size = 0, size = 0;
1162 #if defined TIZEN_DUALSIM_ENABLE
1166 if (llsize == NULL) {
1167 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1168 return CONNECTION_ERROR_INVALID_PARAMETER;
1171 switch (statistics_type) {
1172 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1173 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1174 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1175 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1178 return CONNECTION_ERROR_INVALID_PARAMETER;
1181 #if defined TIZEN_DUALSIM_ENABLE
1182 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1183 if (rv != VCONF_OK) {
1184 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1186 return CONNECTION_ERROR_OPERATION_FAILED;
1192 switch (statistics_type) {
1193 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1194 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1196 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1197 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1199 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1200 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1201 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1203 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1204 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1205 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1208 #if defined TIZEN_DUALSIM_ENABLE
1211 switch (statistics_type) {
1212 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1213 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1215 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1216 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1218 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1219 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1220 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1222 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1223 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1224 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1230 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1231 return CONNECTION_ERROR_OPERATION_FAILED;
1235 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1236 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1237 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1240 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1241 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1243 return CONNECTION_ERROR_NONE;
1246 static int __get_statistic(connection_type_e connection_type,
1247 connection_statistics_type_e statistics_type, long long *llsize)
1250 unsigned long long ull_size;
1252 if (llsize == NULL) {
1253 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1254 return CONNECTION_ERROR_INVALID_PARAMETER;
1257 rv = _connection_libnet_check_get_privilege();
1258 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1260 else if (rv != CONNECTION_ERROR_NONE) {
1261 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1262 return CONNECTION_ERROR_OPERATION_FAILED;
1265 if (connection_type == CONNECTION_TYPE_CELLULAR)
1266 return __get_cellular_statistic(statistics_type, llsize);
1267 else if (connection_type == CONNECTION_TYPE_WIFI) {
1268 switch (statistics_type) {
1269 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1270 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1272 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1273 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1275 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1276 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1278 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1279 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1282 return CONNECTION_ERROR_INVALID_PARAMETER;
1285 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1286 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1288 else if (rv != CONNECTION_ERROR_NONE) {
1289 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1290 *llsize = 0; //LCOV_EXCL_LINE
1291 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1294 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1295 *llsize = (long long)ull_size;
1297 return CONNECTION_ERROR_INVALID_PARAMETER;
1299 return CONNECTION_ERROR_NONE;
1302 static int __reset_statistic(connection_type_e connection_type,
1303 connection_statistics_type_e statistics_type)
1309 if (connection_type == CONNECTION_TYPE_CELLULAR)
1310 conn_type = NET_DEVICE_CELLULAR;
1311 else if (connection_type == CONNECTION_TYPE_WIFI)
1312 conn_type = NET_DEVICE_WIFI;
1314 return CONNECTION_ERROR_INVALID_PARAMETER;
1316 switch (statistics_type) {
1317 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1318 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1320 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1321 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1323 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1324 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1326 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1327 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1330 return CONNECTION_ERROR_INVALID_PARAMETER;
1333 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1334 if (rv != CONNECTION_ERROR_NONE)
1337 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1339 return CONNECTION_ERROR_NONE;
1342 EXPORT_API int connection_get_statistics(connection_h connection,
1343 connection_type_e connection_type,
1344 connection_statistics_type_e statistics_type, long long* size)
1346 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1348 if (connection_type == CONNECTION_TYPE_CELLULAR)
1349 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1350 else if (connection_type == CONNECTION_TYPE_WIFI)
1351 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1353 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1354 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1355 return CONNECTION_ERROR_INVALID_PARAMETER;
1358 return __get_statistic(connection_type, statistics_type, size);
1361 EXPORT_API int connection_reset_statistics(connection_h connection,
1362 connection_type_e connection_type,
1363 connection_statistics_type_e statistics_type)
1365 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1367 if (connection_type == CONNECTION_TYPE_CELLULAR)
1368 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1369 else if (connection_type == CONNECTION_TYPE_WIFI)
1370 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1372 if (!__connection_check_handle_validity(connection)) {
1373 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1374 return CONNECTION_ERROR_INVALID_PARAMETER;
1377 return __reset_statistic(connection_type, statistics_type);