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;
27 static int __connection_convert_net_state(int status)
30 case VCONFKEY_NETWORK_CELLULAR:
31 return CONNECTION_TYPE_CELLULAR;
32 case VCONFKEY_NETWORK_WIFI:
33 return CONNECTION_TYPE_WIFI;
34 case VCONFKEY_NETWORK_ETHERNET:
35 return CONNECTION_TYPE_ETHERNET;
36 case VCONFKEY_NETWORK_BLUETOOTH:
37 return CONNECTION_TYPE_BT;
38 case VCONFKEY_NETWORK_DEFAULT_PROXY:
39 return CONNECTION_TYPE_NET_PROXY;
41 return CONNECTION_TYPE_DISCONNECTED;
45 static int __connection_convert_cellular_state(int status)
48 case VCONFKEY_NETWORK_CELLULAR_ON:
49 return CONNECTION_CELLULAR_STATE_AVAILABLE;
50 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
51 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
52 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
53 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
54 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
55 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
57 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
61 static bool __connection_check_handle_validity(connection_h connection)
65 if (connection == NULL)
68 if (g_slist_find(conn_handle_list, connection) != NULL)
74 static connection_type_changed_cb
75 __connection_get_type_changed_callback(connection_handle_s *local_handle)
77 return local_handle->type_changed_callback;
80 static void *__connection_get_type_changed_userdata(
81 connection_handle_s *local_handle)
83 return local_handle->type_changed_user_data;
86 static gboolean __connection_cb_type_changed_cb_idle(gpointer user_data)
90 connection_type_changed_cb callback;
91 connection_handle_s *local_handle = (connection_handle_s *)user_data;
93 if (__connection_check_handle_validity((connection_h)local_handle) != true)
96 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status) != 0)
99 state = __connection_convert_net_state(status);
101 callback = __connection_get_type_changed_callback(local_handle);
102 data = __connection_get_type_changed_userdata(local_handle);
104 callback(state, data);
109 static void __connection_cb_type_change_cb(keynode_t *node, void *user_data)
114 if (_connection_is_created() != true) {
115 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
116 "If multi-threaded, thread integrity be broken.");
120 for (list = conn_handle_list; list; list = list->next) {
121 handle = (connection_h)list->data;
122 _connection_callback_add(__connection_cb_type_changed_cb_idle, (gpointer)handle);
126 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
128 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
132 for (list = conn_handle_list; list; list = list->next) {
133 connection_handle_s *local_handle = (connection_handle_s *)list->data;
134 if (local_handle->ethernet_cable_state_changed_callback)
135 local_handle->ethernet_cable_state_changed_callback(state,
136 local_handle->ethernet_cable_state_changed_user_data);
140 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
145 for (list = conn_handle_list; list; list = list->next) {
146 connection_handle_s *local_handle = (connection_handle_s *)list->data;
147 if (local_handle->ethernet_cable_state_changed_callback) count++;
153 static int __connection_set_type_changed_callback(connection_h connection,
154 void *callback, void *user_data)
156 static __thread gint refcount = 0;
157 connection_handle_s *local_handle;
159 local_handle = (connection_handle_s *)connection;
163 vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS,
164 __connection_cb_type_change_cb, NULL);
167 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
170 __connection_get_type_changed_callback(local_handle) != NULL) {
171 if (--refcount == 0) {
172 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
173 __connection_cb_type_change_cb) < 0) {
174 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
175 "Error to de-register vconf callback(%d)", refcount);
177 CONNECTION_LOG(CONNECTION_INFO,
178 "Successfully de-registered(%d)", refcount);
184 local_handle->type_changed_user_data = user_data;
185 local_handle->type_changed_callback = callback;
187 return CONNECTION_ERROR_NONE;
190 static connection_address_changed_cb
191 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
193 return local_handle->ip_changed_callback;
196 static void *__connection_get_ip_changed_userdata(
197 connection_handle_s *local_handle)
199 return local_handle->ip_changed_user_data;
202 static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
206 connection_address_changed_cb callback;
207 connection_handle_s *local_handle = (connection_handle_s *)user_data;
209 if (__connection_check_handle_validity((connection_h)local_handle) != true)
212 ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
214 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
215 "vconf_get_str(VCONFKEY_NETWORK_IP) is Failed");
217 callback = __connection_get_ip_changed_callback(local_handle);
218 data = __connection_get_ip_changed_userdata(local_handle);
219 /* TODO: IPv6 should be supported */
221 callback(ip_addr, NULL, data);
228 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
233 if (_connection_is_created() != true) {
234 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
235 "If multi-threaded, thread integrity be broken.");
239 for (list = conn_handle_list; list; list = list->next) {
240 handle = (connection_h)list->data;
241 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
245 static int __connection_set_ip_changed_callback(connection_h connection,
246 void *callback, void *user_data)
248 static __thread gint refcount = 0;
249 connection_handle_s *local_handle;
251 local_handle = (connection_handle_s *)connection;
255 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
256 __connection_cb_ip_change_cb, NULL);
259 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
262 __connection_get_ip_changed_callback(local_handle) != NULL) {
263 if (--refcount == 0) {
264 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
265 __connection_cb_ip_change_cb) < 0) {
266 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
267 "Error to de-register vconf callback(%d)", refcount);
269 CONNECTION_LOG(CONNECTION_INFO,
270 "Successfully de-registered(%d)", refcount);
276 local_handle->ip_changed_user_data = user_data;
277 local_handle->ip_changed_callback = callback;
279 return CONNECTION_ERROR_NONE;
282 static connection_address_changed_cb
283 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
285 return local_handle->proxy_changed_callback;
288 static void *__connection_get_proxy_changed_userdata(
289 connection_handle_s *local_handle)
291 return local_handle->proxy_changed_user_data;
294 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
298 connection_address_changed_cb callback;
299 connection_handle_s *local_handle = (connection_handle_s *)user_data;
301 if (__connection_check_handle_validity((connection_h)local_handle) != true)
304 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
306 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
307 "vconf_get_str(VCONFKEY_NETWORK_PROXY) is Failed");
309 callback = __connection_get_proxy_changed_callback(local_handle);
310 data = __connection_get_proxy_changed_userdata(local_handle);
311 /* TODO: IPv6 should be supported */
313 callback(proxy, NULL, data);
320 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
325 if (_connection_is_created() != true) {
326 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
327 "If multi-threaded, thread integrity be broken.");
331 for (list = conn_handle_list; list; list = list->next) {
332 handle = (connection_h)list->data;
333 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
337 static int __connection_set_proxy_changed_callback(connection_h connection,
338 void *callback, void *user_data)
340 static __thread gint refcount = 0;
341 connection_handle_s *local_handle;
343 local_handle = (connection_handle_s *)connection;
347 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
348 __connection_cb_proxy_change_cb, NULL);
351 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
354 __connection_get_proxy_changed_callback(local_handle) != NULL) {
355 if (--refcount == 0) {
356 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
357 __connection_cb_proxy_change_cb) < 0) {
358 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
359 "Error to de-register vconf callback(%d)", refcount);
361 CONNECTION_LOG(CONNECTION_INFO,
362 "Successfully de-registered(%d)", refcount);
368 local_handle->proxy_changed_user_data = user_data;
369 local_handle->proxy_changed_callback = callback;
371 return CONNECTION_ERROR_NONE;
374 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
375 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
377 connection_handle_s *local_handle = (connection_handle_s *)connection;
380 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
381 _connection_libnet_set_ethernet_cable_state_changed_cb(
382 __connection_cb_ethernet_cable_state_changed_cb);
385 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1 &&
386 local_handle->ethernet_cable_state_changed_callback)
387 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
390 local_handle->ethernet_cable_state_changed_callback = callback;
391 local_handle->ethernet_cable_state_changed_user_data = user_data;
392 return CONNECTION_ERROR_NONE;
396 static int __connection_get_handle_count(void)
398 return ((int)g_slist_length(conn_handle_list));
401 /* Connection Manager ********************************************************/
402 EXPORT_API int connection_create(connection_h *connection)
404 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
406 if (connection == NULL || __connection_check_handle_validity(*connection)) {
407 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
408 return CONNECTION_ERROR_INVALID_PARAMETER;
411 int rv = _connection_libnet_init();
412 if (rv == NET_ERR_ACCESS_DENIED) {
413 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
414 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
415 } else if (rv != NET_ERR_NONE) {
416 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
417 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
420 *connection = g_try_malloc0(sizeof(connection_handle_s));
421 if (*connection != NULL)
422 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
424 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
426 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
428 return CONNECTION_ERROR_NONE;
431 EXPORT_API int connection_destroy(connection_h connection)
433 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
435 if (!(__connection_check_handle_validity(connection))) {
436 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
437 return CONNECTION_ERROR_INVALID_PARAMETER;
440 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
442 __connection_set_type_changed_callback(connection, NULL, NULL);
443 __connection_set_ip_changed_callback(connection, NULL, NULL);
444 __connection_set_proxy_changed_callback(connection, NULL, NULL);
445 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
447 conn_handle_list = g_slist_remove(conn_handle_list, connection);
452 if (__connection_get_handle_count() == 0) {
453 _connection_libnet_deinit();
454 _connection_callback_cleanup();
457 return CONNECTION_ERROR_NONE;
460 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
465 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
467 if (type == NULL || !(__connection_check_handle_validity(connection))) {
468 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
469 return CONNECTION_ERROR_INVALID_PARAMETER;
472 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
473 if (rv != VCONF_OK) {
474 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
475 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
478 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
480 *type = __connection_convert_net_state(status);
482 return CONNECTION_ERROR_NONE;
485 EXPORT_API int connection_get_ip_address(connection_h connection,
486 connection_address_family_e address_family, char** ip_address)
488 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
490 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
491 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
492 return CONNECTION_ERROR_INVALID_PARAMETER;
495 switch (address_family) {
496 case CONNECTION_ADDRESS_FAMILY_IPV4:
497 case CONNECTION_ADDRESS_FAMILY_IPV6:
498 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
501 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
502 return CONNECTION_ERROR_INVALID_PARAMETER;
505 if (*ip_address == NULL) {
506 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
507 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
510 return CONNECTION_ERROR_NONE;
513 EXPORT_API int connection_get_proxy(connection_h connection,
514 connection_address_family_e address_family, char** proxy)
516 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
518 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
519 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
520 return CONNECTION_ERROR_INVALID_PARAMETER;
523 switch (address_family) {
524 case CONNECTION_ADDRESS_FAMILY_IPV4:
525 case CONNECTION_ADDRESS_FAMILY_IPV6:
526 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
529 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
530 return CONNECTION_ERROR_INVALID_PARAMETER;
533 if (*proxy == NULL) {
534 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
535 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
538 return CONNECTION_ERROR_NONE;
541 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
544 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
546 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
548 if (type == CONNECTION_TYPE_WIFI)
549 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
550 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
551 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
553 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
554 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
555 return CONNECTION_ERROR_INVALID_PARAMETER;
559 case CONNECTION_TYPE_WIFI:
561 fp = fopen(WIFI_MAC_INFO_FILE, "r");
563 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
564 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
567 if (fgets(buf, sizeof(buf), fp) == NULL) {
568 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
569 fclose(fp); //LCOV_EXCL_LINE
570 return CONNECTION_ERROR_OPERATION_FAILED;
573 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
575 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
576 if (*mac_addr == NULL) {
577 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
578 fclose(fp); //LCOV_EXCL_LINE
579 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
581 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
584 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
586 if (*mac_addr == NULL) {
587 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
588 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
593 case CONNECTION_TYPE_ETHERNET:
594 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
596 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
597 return CONNECTION_ERROR_OUT_OF_MEMORY;
600 if (fgets(buf, sizeof(buf), fp) == NULL) {
601 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
603 return CONNECTION_ERROR_OPERATION_FAILED;
606 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
608 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
609 if (*mac_addr == NULL) {
610 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
612 return CONNECTION_ERROR_OUT_OF_MEMORY;
615 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
621 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
622 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
625 /* Checking Invalid MAC Address */
626 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
627 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
628 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
629 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
632 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
634 return CONNECTION_ERROR_NONE;
638 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
642 int cellular_state = 0;
643 #if defined TIZEN_DUALSIM_ENABLE
647 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
649 if (state == NULL || !(__connection_check_handle_validity(connection))) {
650 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
651 return CONNECTION_ERROR_INVALID_PARAMETER;
654 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
655 if (rv != VCONF_OK) {
656 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
657 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
660 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
661 *state = __connection_convert_cellular_state(status);
663 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
664 #if defined TIZEN_DUALSIM_ENABLE
665 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
666 if (rv != VCONF_OK) {
667 CONNECTION_LOG(CONNECTION_ERROR,
668 "Failed to get default subscriber id", sim_id);
669 return CONNECTION_ERROR_OPERATION_FAILED;
673 case CONNECTION_CELLULAR_SUBSCRIBER_1:
675 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
676 #if defined TIZEN_DUALSIM_ENABLE
679 case CONNECTION_CELLULAR_SUBSCRIBER_2:
680 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
684 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
685 return CONNECTION_ERROR_OPERATION_FAILED;
688 if (rv != VCONF_OK) {
689 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
690 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
694 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
696 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
697 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
698 cellular_state == VCONFKEY_DNET_TRANSFER)
699 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
701 return CONNECTION_ERROR_NONE;
704 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
706 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
708 if (state == NULL || !(__connection_check_handle_validity(connection))) {
709 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
710 return CONNECTION_ERROR_INVALID_PARAMETER;
713 int rv = _connection_libnet_get_wifi_state(state);
714 if (rv != CONNECTION_ERROR_NONE) {
715 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
716 return rv; //LCOV_EXCL_LINE
719 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
721 return CONNECTION_ERROR_NONE;
725 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
727 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
729 if (state == NULL || !(__connection_check_handle_validity(connection))) {
730 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
731 return CONNECTION_ERROR_INVALID_PARAMETER;
734 return _connection_libnet_get_ethernet_state(state);
737 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
739 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
741 if (state == NULL || !(__connection_check_handle_validity(connection))) {
742 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
743 return CONNECTION_ERROR_INVALID_PARAMETER;
746 return _connection_libnet_get_ethernet_cable_state(state);
749 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
750 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
752 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
754 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
755 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
756 return CONNECTION_ERROR_INVALID_PARAMETER;
759 return __connection_set_ethernet_cable_state_changed_cb(connection,
760 callback, user_data);
763 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
765 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
767 if (!(__connection_check_handle_validity(connection))) {
768 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
769 return CONNECTION_ERROR_INVALID_PARAMETER;
772 return __connection_set_ethernet_cable_state_changed_cb(connection,
777 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
779 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
781 if (state == NULL || !(__connection_check_handle_validity(connection))) {
782 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
783 return CONNECTION_ERROR_INVALID_PARAMETER;
786 return _connection_libnet_get_bluetooth_state(state);
789 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
790 connection_type_changed_cb callback, void* user_data)
792 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
794 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
795 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
796 return CONNECTION_ERROR_INVALID_PARAMETER;
799 return __connection_set_type_changed_callback(connection, callback, user_data);
802 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
804 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
806 if (!(__connection_check_handle_validity(connection))) {
807 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
808 return CONNECTION_ERROR_INVALID_PARAMETER;
811 return __connection_set_type_changed_callback(connection, NULL, NULL);
814 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
815 connection_address_changed_cb callback, void* user_data)
817 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
819 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
820 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
821 return CONNECTION_ERROR_INVALID_PARAMETER;
824 return __connection_set_ip_changed_callback(connection, callback, user_data);
827 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
829 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
831 if (!(__connection_check_handle_validity(connection))) {
832 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
833 return CONNECTION_ERROR_INVALID_PARAMETER;
836 return __connection_set_ip_changed_callback(connection, NULL, NULL);
839 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
840 connection_address_changed_cb callback, void* user_data)
842 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
844 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
845 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
846 return CONNECTION_ERROR_INVALID_PARAMETER;
849 return __connection_set_proxy_changed_callback(connection, callback, user_data);
852 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
854 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
856 if (!(__connection_check_handle_validity(connection))) {
857 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
858 return CONNECTION_ERROR_INVALID_PARAMETER;
861 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
864 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
867 net_profile_info_t *profile_info = profile;
869 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
871 if (!(__connection_check_handle_validity(connection)) ||
872 !(_connection_libnet_check_profile_validity(profile))) {
873 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
874 return CONNECTION_ERROR_INVALID_PARAMETER;
877 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
878 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
879 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
882 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
883 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
884 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
885 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
888 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
889 (net_profile_info_t*)profile);
890 if (rv == NET_ERR_ACCESS_DENIED) {
891 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
892 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
893 } else if (rv != NET_ERR_NONE) {
894 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
895 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
898 return CONNECTION_ERROR_NONE;
901 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
904 net_profile_info_t *profile_info = profile;
906 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
908 if (!(__connection_check_handle_validity(connection)) ||
909 !(_connection_libnet_check_profile_validity(profile))) {
910 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
911 return CONNECTION_ERROR_INVALID_PARAMETER;
914 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
915 profile_info->profile_type != NET_DEVICE_WIFI) {
916 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
917 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
920 rv = net_delete_profile(profile_info->ProfileName);
921 if (rv == NET_ERR_ACCESS_DENIED) {
922 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
923 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
924 } else if (rv != NET_ERR_NONE) {
925 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
926 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
929 return CONNECTION_ERROR_NONE;
932 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
935 net_profile_info_t *profile_info = profile;
937 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
939 if (!(__connection_check_handle_validity(connection)) ||
940 !(_connection_libnet_check_profile_validity(profile))) {
941 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
942 return CONNECTION_ERROR_INVALID_PARAMETER;
945 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
946 if (rv == NET_ERR_ACCESS_DENIED) {
947 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
948 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
949 } else if (rv != NET_ERR_NONE) {
950 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
951 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
954 return CONNECTION_ERROR_NONE;
957 EXPORT_API int connection_get_profile_iterator(connection_h connection,
958 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
960 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
962 if (!(__connection_check_handle_validity(connection)) ||
963 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
964 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
965 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
966 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
967 return CONNECTION_ERROR_INVALID_PARAMETER;
970 return _connection_libnet_get_profile_iterator(type, profile_iterator);
973 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
974 connection_profile_h* profile)
976 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
978 return _connection_libnet_get_iterator_next(profile_iterator, profile);
981 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
983 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
985 return _connection_libnet_iterator_has_next(profile_iterator);
988 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
990 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
992 return _connection_libnet_destroy_iterator(profile_iterator);
995 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
997 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
999 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1000 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1001 return CONNECTION_ERROR_INVALID_PARAMETER;
1004 return _connection_libnet_get_current_profile(profile);
1007 EXPORT_API int connection_get_default_cellular_service_profile(
1008 connection_h connection, connection_cellular_service_type_e type,
1009 connection_profile_h *profile)
1011 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1013 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1014 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1015 return CONNECTION_ERROR_INVALID_PARAMETER;
1018 return _connection_libnet_get_cellular_service_profile(type, profile);
1021 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1022 connection_cellular_service_type_e type, connection_profile_h profile)
1024 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1026 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1027 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1028 return CONNECTION_ERROR_INVALID_PARAMETER;
1031 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1034 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1035 connection_cellular_service_type_e type, connection_profile_h profile,
1036 connection_set_default_cb callback, void* user_data)
1038 CHECK_FEATURE_SUPPORTED(TELEPHONY_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_set_cellular_service_profile_async(type, profile, callback, user_data);
1049 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1050 connection_opened_cb callback, void* user_data)
1052 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1054 if (!(__connection_check_handle_validity(connection)) ||
1055 profile == NULL || callback == NULL) {
1056 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1057 return CONNECTION_ERROR_INVALID_PARAMETER;
1060 return _connection_libnet_open_profile(profile, callback, user_data);
1063 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1064 connection_closed_cb callback, void* user_data)
1066 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1068 if (!(__connection_check_handle_validity(connection)) ||
1069 profile == NULL || callback == NULL) {
1070 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1071 return CONNECTION_ERROR_INVALID_PARAMETER;
1074 return _connection_libnet_close_profile(profile, callback, user_data);
1077 EXPORT_API int connection_reset_profile(connection_h connection,
1078 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1080 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1082 if (!(__connection_check_handle_validity(connection))) {
1083 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1084 return CONNECTION_ERROR_INVALID_PARAMETER;
1087 if (id < 0 || id > 1) {
1088 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1089 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1092 return _connection_libnet_reset_profile(type, id, callback, user_data);
1095 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1097 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1099 if (!(__connection_check_handle_validity(connection)) ||
1100 interface_name == NULL || host_address == NULL) {
1101 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1102 return CONNECTION_ERROR_INVALID_PARAMETER;
1105 return _connection_libnet_add_route(interface_name, host_address);
1108 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1110 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1112 if (!(__connection_check_handle_validity(connection)) ||
1113 interface_name == NULL || host_address == NULL) {
1114 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1115 return CONNECTION_ERROR_INVALID_PARAMETER;
1118 return _connection_libnet_remove_route(interface_name, host_address);
1121 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1123 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1125 if (!(__connection_check_handle_validity(connection)) ||
1126 interface_name == NULL || host_address == NULL) {
1127 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1128 return CONNECTION_ERROR_INVALID_PARAMETER;
1131 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1134 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1136 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1138 if (!(__connection_check_handle_validity(connection)) ||
1139 interface_name == NULL || host_address == NULL) {
1140 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1141 return CONNECTION_ERROR_INVALID_PARAMETER;
1144 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1147 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1149 int rv = VCONF_OK, rv1 = VCONF_OK;
1150 int last_size = 0, size = 0;
1151 #if defined TIZEN_DUALSIM_ENABLE
1155 if (llsize == NULL) {
1156 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1157 return CONNECTION_ERROR_INVALID_PARAMETER;
1160 switch (statistics_type) {
1161 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1162 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1163 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1164 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1167 return CONNECTION_ERROR_INVALID_PARAMETER;
1170 #if defined TIZEN_DUALSIM_ENABLE
1171 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1172 if (rv != VCONF_OK) {
1173 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1175 return CONNECTION_ERROR_OPERATION_FAILED;
1181 switch (statistics_type) {
1182 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1183 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1185 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1186 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1188 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1189 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1190 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1192 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1193 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1194 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1197 #if defined TIZEN_DUALSIM_ENABLE
1200 switch (statistics_type) {
1201 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1202 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1204 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1205 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1207 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1208 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1209 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1211 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1212 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1213 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1219 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1220 return CONNECTION_ERROR_OPERATION_FAILED;
1224 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1225 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1226 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1229 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1230 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1232 return CONNECTION_ERROR_NONE;
1235 static int __get_statistic(connection_type_e connection_type,
1236 connection_statistics_type_e statistics_type, long long *llsize)
1239 unsigned long long ull_size;
1241 if (llsize == NULL) {
1242 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1243 return CONNECTION_ERROR_INVALID_PARAMETER;
1246 rv = _connection_libnet_check_get_privilege();
1247 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1249 else if (rv != CONNECTION_ERROR_NONE) {
1250 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1251 return CONNECTION_ERROR_OPERATION_FAILED;
1254 if (connection_type == CONNECTION_TYPE_CELLULAR)
1255 return __get_cellular_statistic(statistics_type, llsize);
1256 else if (connection_type == CONNECTION_TYPE_WIFI) {
1257 switch (statistics_type) {
1258 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1259 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1261 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1262 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1264 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1265 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1267 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1268 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1271 return CONNECTION_ERROR_INVALID_PARAMETER;
1274 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1275 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1277 else if (rv != CONNECTION_ERROR_NONE) {
1278 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1279 *llsize = 0; //LCOV_EXCL_LINE
1280 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1283 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1284 *llsize = (long long)ull_size;
1286 return CONNECTION_ERROR_INVALID_PARAMETER;
1288 return CONNECTION_ERROR_NONE;
1291 static int __reset_statistic(connection_type_e connection_type,
1292 connection_statistics_type_e statistics_type)
1298 if (connection_type == CONNECTION_TYPE_CELLULAR)
1299 conn_type = NET_DEVICE_CELLULAR;
1300 else if (connection_type == CONNECTION_TYPE_WIFI)
1301 conn_type = NET_DEVICE_WIFI;
1303 return CONNECTION_ERROR_INVALID_PARAMETER;
1305 switch (statistics_type) {
1306 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1307 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1309 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1310 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1312 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1313 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1315 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1316 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1319 return CONNECTION_ERROR_INVALID_PARAMETER;
1322 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1323 if (rv != CONNECTION_ERROR_NONE)
1326 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1328 return CONNECTION_ERROR_NONE;
1331 EXPORT_API int connection_get_statistics(connection_h connection,
1332 connection_type_e connection_type,
1333 connection_statistics_type_e statistics_type, long long* size)
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)) || size == NULL) {
1343 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1344 return CONNECTION_ERROR_INVALID_PARAMETER;
1347 return __get_statistic(connection_type, statistics_type, size);
1350 EXPORT_API int connection_reset_statistics(connection_h connection,
1351 connection_type_e connection_type,
1352 connection_statistics_type_e statistics_type)
1354 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1356 if (connection_type == CONNECTION_TYPE_CELLULAR)
1357 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1358 else if (connection_type == CONNECTION_TYPE_WIFI)
1359 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1361 if (!__connection_check_handle_validity(connection)) {
1362 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1363 return CONNECTION_ERROR_INVALID_PARAMETER;
1366 return __reset_statistic(connection_type, statistics_type);