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 callback = __connection_get_ip_changed_callback(local_handle);
215 data = __connection_get_ip_changed_userdata(local_handle);
216 /* TODO: IPv6 should be supported */
218 callback(ip_addr, NULL, data);
223 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
228 if (_connection_is_created() != true) {
229 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
230 "If multi-threaded, thread integrity be broken.");
234 for (list = conn_handle_list; list; list = list->next) {
235 handle = (connection_h)list->data;
236 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
240 static int __connection_set_ip_changed_callback(connection_h connection,
241 void *callback, void *user_data)
243 static __thread gint refcount = 0;
244 connection_handle_s *local_handle;
246 local_handle = (connection_handle_s *)connection;
250 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
251 __connection_cb_ip_change_cb, NULL);
254 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
257 __connection_get_ip_changed_callback(local_handle) != NULL) {
258 if (--refcount == 0) {
259 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
260 __connection_cb_ip_change_cb) < 0) {
261 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
262 "Error to de-register vconf callback(%d)", refcount);
264 CONNECTION_LOG(CONNECTION_INFO,
265 "Successfully de-registered(%d)", refcount);
271 local_handle->ip_changed_user_data = user_data;
272 local_handle->ip_changed_callback = callback;
274 return CONNECTION_ERROR_NONE;
277 static connection_address_changed_cb
278 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
280 return local_handle->proxy_changed_callback;
283 static void *__connection_get_proxy_changed_userdata(
284 connection_handle_s *local_handle)
286 return local_handle->proxy_changed_user_data;
289 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
293 connection_address_changed_cb callback;
294 connection_handle_s *local_handle = (connection_handle_s *)user_data;
296 if (__connection_check_handle_validity((connection_h)local_handle) != true)
299 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
301 callback = __connection_get_proxy_changed_callback(local_handle);
302 data = __connection_get_proxy_changed_userdata(local_handle);
303 /* TODO: IPv6 should be supported */
305 callback(proxy, NULL, data);
310 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
315 if (_connection_is_created() != true) {
316 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
317 "If multi-threaded, thread integrity be broken.");
321 for (list = conn_handle_list; list; list = list->next) {
322 handle = (connection_h)list->data;
323 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
327 static int __connection_set_proxy_changed_callback(connection_h connection,
328 void *callback, void *user_data)
330 static __thread gint refcount = 0;
331 connection_handle_s *local_handle;
333 local_handle = (connection_handle_s *)connection;
337 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
338 __connection_cb_proxy_change_cb, NULL);
341 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
344 __connection_get_proxy_changed_callback(local_handle) != NULL) {
345 if (--refcount == 0) {
346 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
347 __connection_cb_proxy_change_cb) < 0) {
348 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
349 "Error to de-register vconf callback(%d)", refcount);
351 CONNECTION_LOG(CONNECTION_INFO,
352 "Successfully de-registered(%d)", refcount);
358 local_handle->proxy_changed_user_data = user_data;
359 local_handle->proxy_changed_callback = callback;
361 return CONNECTION_ERROR_NONE;
364 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
365 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
367 connection_handle_s *local_handle = (connection_handle_s *)connection;
370 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
371 _connection_libnet_set_ethernet_cable_state_changed_cb(
372 __connection_cb_ethernet_cable_state_changed_cb);
375 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1)
376 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
379 local_handle->ethernet_cable_state_changed_callback = callback;
380 local_handle->ethernet_cable_state_changed_user_data = user_data;
381 return CONNECTION_ERROR_NONE;
385 static int __connection_get_handle_count(void)
387 return ((int)g_slist_length(conn_handle_list));
390 /* Connection Manager ********************************************************/
391 EXPORT_API int connection_create(connection_h *connection)
393 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
395 if (connection == NULL || __connection_check_handle_validity(*connection)) {
396 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
397 return CONNECTION_ERROR_INVALID_PARAMETER;
400 int rv = _connection_libnet_init();
401 if (rv == NET_ERR_ACCESS_DENIED) {
402 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
403 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
405 else if (rv != NET_ERR_NONE) {
406 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
407 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
410 *connection = g_try_malloc0(sizeof(connection_handle_s));
411 if (*connection != NULL)
412 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
414 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
416 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
418 return CONNECTION_ERROR_NONE;
421 EXPORT_API int connection_destroy(connection_h connection)
423 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
425 if (!(__connection_check_handle_validity(connection))) {
426 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
427 return CONNECTION_ERROR_INVALID_PARAMETER;
430 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
432 __connection_set_type_changed_callback(connection, NULL, NULL);
433 __connection_set_ip_changed_callback(connection, NULL, NULL);
434 __connection_set_proxy_changed_callback(connection, NULL, NULL);
435 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
437 conn_handle_list = g_slist_remove(conn_handle_list, connection);
442 if (__connection_get_handle_count() == 0) {
443 _connection_libnet_deinit();
444 _connection_callback_cleanup();
447 return CONNECTION_ERROR_NONE;
450 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
455 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
457 if (type == NULL || !(__connection_check_handle_validity(connection))) {
458 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
459 return CONNECTION_ERROR_INVALID_PARAMETER;
462 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
463 if (rv != VCONF_OK) {
464 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
465 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
468 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
470 *type = __connection_convert_net_state(status);
472 return CONNECTION_ERROR_NONE;
475 EXPORT_API int connection_get_ip_address(connection_h connection,
476 connection_address_family_e address_family, char** ip_address)
478 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
480 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
481 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
482 return CONNECTION_ERROR_INVALID_PARAMETER;
485 switch (address_family) {
486 case CONNECTION_ADDRESS_FAMILY_IPV4:
487 case CONNECTION_ADDRESS_FAMILY_IPV6:
488 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
491 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
492 return CONNECTION_ERROR_INVALID_PARAMETER;
495 if (*ip_address == NULL) {
496 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
497 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
500 return CONNECTION_ERROR_NONE;
503 EXPORT_API int connection_get_proxy(connection_h connection,
504 connection_address_family_e address_family, char** proxy)
506 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
508 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
509 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
510 return CONNECTION_ERROR_INVALID_PARAMETER;
513 switch (address_family) {
514 case CONNECTION_ADDRESS_FAMILY_IPV4:
515 case CONNECTION_ADDRESS_FAMILY_IPV6:
516 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
519 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
520 return CONNECTION_ERROR_INVALID_PARAMETER;
523 if (*proxy == NULL) {
524 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
525 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
528 return CONNECTION_ERROR_NONE;
531 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
534 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
536 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
538 if (type == CONNECTION_TYPE_WIFI)
539 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
540 else if(type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
541 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
543 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
544 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
545 return CONNECTION_ERROR_INVALID_PARAMETER;
549 case CONNECTION_TYPE_WIFI:
551 fp = fopen(WIFI_MAC_INFO_FILE, "r");
553 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
554 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
557 if (fgets(buf, sizeof(buf), fp) == NULL) {
558 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
559 fclose(fp); //LCOV_EXCL_LINE
560 return CONNECTION_ERROR_OPERATION_FAILED;
563 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
565 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
566 if (*mac_addr == NULL) {
567 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
568 fclose(fp); //LCOV_EXCL_LINE
569 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
571 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
574 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
576 if (*mac_addr == NULL) {
577 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
578 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
583 case CONNECTION_TYPE_ETHERNET:
584 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
586 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
587 return CONNECTION_ERROR_OUT_OF_MEMORY;
590 if (fgets(buf, sizeof(buf), fp) == NULL) {
591 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
593 return CONNECTION_ERROR_OPERATION_FAILED;
596 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
598 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
599 if (*mac_addr == NULL) {
600 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
602 return CONNECTION_ERROR_OUT_OF_MEMORY;
605 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
611 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
612 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
615 /* Checking Invalid MAC Address */
616 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
617 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
618 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
619 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
622 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
624 return CONNECTION_ERROR_NONE;
628 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
632 int cellular_state = 0;
633 #if defined TIZEN_DUALSIM_ENABLE
637 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
639 if (state == NULL || !(__connection_check_handle_validity(connection))) {
640 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
641 return CONNECTION_ERROR_INVALID_PARAMETER;
644 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
645 if (rv != VCONF_OK) {
646 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
647 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
650 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
651 *state = __connection_convert_cellular_state(status);
653 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
654 #if defined TIZEN_DUALSIM_ENABLE
655 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
656 if (rv != VCONF_OK) {
657 CONNECTION_LOG(CONNECTION_ERROR,
658 "Failed to get default subscriber id", sim_id);
659 return CONNECTION_ERROR_OPERATION_FAILED;
663 case CONNECTION_CELLULAR_SUBSCRIBER_1:
665 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
666 #if defined TIZEN_DUALSIM_ENABLE
669 case CONNECTION_CELLULAR_SUBSCRIBER_2:
670 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
674 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
675 return CONNECTION_ERROR_OPERATION_FAILED;
678 if (rv != VCONF_OK) {
679 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
680 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
684 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
686 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
687 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
688 cellular_state == VCONFKEY_DNET_TRANSFER)
689 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
691 return CONNECTION_ERROR_NONE;
694 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
696 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
698 if (state == NULL || !(__connection_check_handle_validity(connection))) {
699 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
700 return CONNECTION_ERROR_INVALID_PARAMETER;
703 int rv = _connection_libnet_get_wifi_state(state);
704 if (rv != CONNECTION_ERROR_NONE) {
705 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
706 return rv; //LCOV_EXCL_LINE
709 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
711 return CONNECTION_ERROR_NONE;
715 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
717 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
719 if (state == NULL || !(__connection_check_handle_validity(connection))) {
720 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
721 return CONNECTION_ERROR_INVALID_PARAMETER;
724 return _connection_libnet_get_ethernet_state(state);
727 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
729 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
731 if (state == NULL || !(__connection_check_handle_validity(connection))) {
732 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
733 return CONNECTION_ERROR_INVALID_PARAMETER;
736 return _connection_libnet_get_ethernet_cable_state(state);
739 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
740 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
742 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
744 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
745 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
746 return CONNECTION_ERROR_INVALID_PARAMETER;
749 return __connection_set_ethernet_cable_state_changed_cb(connection,
750 callback, user_data);
753 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
755 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
757 if (!(__connection_check_handle_validity(connection))) {
758 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
759 return CONNECTION_ERROR_INVALID_PARAMETER;
762 return __connection_set_ethernet_cable_state_changed_cb(connection,
767 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
769 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
771 if (state == NULL || !(__connection_check_handle_validity(connection))) {
772 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
773 return CONNECTION_ERROR_INVALID_PARAMETER;
776 return _connection_libnet_get_bluetooth_state(state);
779 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
780 connection_type_changed_cb callback, void* user_data)
782 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
784 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
785 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
786 return CONNECTION_ERROR_INVALID_PARAMETER;
789 return __connection_set_type_changed_callback(connection, callback, user_data);
792 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
794 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
796 if (!(__connection_check_handle_validity(connection))) {
797 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
798 return CONNECTION_ERROR_INVALID_PARAMETER;
801 return __connection_set_type_changed_callback(connection, NULL, NULL);
804 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
805 connection_address_changed_cb callback, void* user_data)
807 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
809 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
810 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
811 return CONNECTION_ERROR_INVALID_PARAMETER;
814 return __connection_set_ip_changed_callback(connection, callback, user_data);
817 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
819 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
821 if (!(__connection_check_handle_validity(connection))) {
822 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
823 return CONNECTION_ERROR_INVALID_PARAMETER;
826 return __connection_set_ip_changed_callback(connection, NULL, NULL);
829 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
830 connection_address_changed_cb callback, void* user_data)
832 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
834 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
835 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
836 return CONNECTION_ERROR_INVALID_PARAMETER;
839 return __connection_set_proxy_changed_callback(connection, callback, user_data);
842 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
844 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
846 if (!(__connection_check_handle_validity(connection))) {
847 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
848 return CONNECTION_ERROR_INVALID_PARAMETER;
851 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
854 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
857 net_profile_info_t *profile_info = profile;
859 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
861 if (!(__connection_check_handle_validity(connection)) ||
862 !(_connection_libnet_check_profile_validity(profile))) {
863 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
864 return CONNECTION_ERROR_INVALID_PARAMETER;
867 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
868 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
869 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
872 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
873 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
874 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
875 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
878 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
879 (net_profile_info_t*)profile);
880 if (rv == NET_ERR_ACCESS_DENIED) {
881 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
882 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
883 } else if (rv != NET_ERR_NONE) {
884 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
885 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
888 return CONNECTION_ERROR_NONE;
891 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
894 net_profile_info_t *profile_info = profile;
896 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
898 if (!(__connection_check_handle_validity(connection)) ||
899 !(_connection_libnet_check_profile_validity(profile))) {
900 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
901 return CONNECTION_ERROR_INVALID_PARAMETER;
904 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
905 profile_info->profile_type != NET_DEVICE_WIFI) {
906 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
907 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
910 rv = net_delete_profile(profile_info->ProfileName);
911 if (rv == NET_ERR_ACCESS_DENIED) {
912 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
913 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
914 } else if (rv != NET_ERR_NONE) {
915 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
916 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
919 return CONNECTION_ERROR_NONE;
922 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
925 net_profile_info_t *profile_info = profile;
927 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
929 if (!(__connection_check_handle_validity(connection)) ||
930 !(_connection_libnet_check_profile_validity(profile))) {
931 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
932 return CONNECTION_ERROR_INVALID_PARAMETER;
935 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
936 if (rv == NET_ERR_ACCESS_DENIED) {
937 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
938 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
939 } else if (rv != NET_ERR_NONE) {
940 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
941 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
944 return CONNECTION_ERROR_NONE;
947 EXPORT_API int connection_get_profile_iterator(connection_h connection,
948 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
950 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
952 if (!(__connection_check_handle_validity(connection)) ||
953 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
954 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
955 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
956 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
957 return CONNECTION_ERROR_INVALID_PARAMETER;
960 return _connection_libnet_get_profile_iterator(type, profile_iterator);
963 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
964 connection_profile_h* profile)
966 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
968 return _connection_libnet_get_iterator_next(profile_iterator, profile);
971 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
973 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
975 return _connection_libnet_iterator_has_next(profile_iterator);
978 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
980 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
982 return _connection_libnet_destroy_iterator(profile_iterator);
985 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
987 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
989 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
990 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
991 return CONNECTION_ERROR_INVALID_PARAMETER;
994 return _connection_libnet_get_current_profile(profile);
997 EXPORT_API int connection_get_default_cellular_service_profile(
998 connection_h connection, connection_cellular_service_type_e type,
999 connection_profile_h *profile)
1001 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1003 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1004 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1005 return CONNECTION_ERROR_INVALID_PARAMETER;
1008 return _connection_libnet_get_cellular_service_profile(type, profile);
1011 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1012 connection_cellular_service_type_e type, connection_profile_h profile)
1014 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1016 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1017 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1018 return CONNECTION_ERROR_INVALID_PARAMETER;
1021 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1024 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1025 connection_cellular_service_type_e type, connection_profile_h profile,
1026 connection_set_default_cb callback, void* user_data)
1028 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1030 if (!(__connection_check_handle_validity(connection)) ||
1031 profile == NULL || callback == NULL) {
1032 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1033 return CONNECTION_ERROR_INVALID_PARAMETER;
1036 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1039 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1040 connection_opened_cb callback, void* user_data)
1042 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1044 if (!(__connection_check_handle_validity(connection)) ||
1045 profile == NULL || callback == NULL) {
1046 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1047 return CONNECTION_ERROR_INVALID_PARAMETER;
1050 return _connection_libnet_open_profile(profile, callback, user_data);
1053 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1054 connection_closed_cb callback, void* user_data)
1056 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1058 if (!(__connection_check_handle_validity(connection)) ||
1059 profile == NULL || callback == NULL) {
1060 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1061 return CONNECTION_ERROR_INVALID_PARAMETER;
1064 return _connection_libnet_close_profile(profile, callback, user_data);
1067 EXPORT_API int connection_reset_profile(connection_h connection,
1068 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1070 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1072 if (!(__connection_check_handle_validity(connection))) {
1073 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1074 return CONNECTION_ERROR_INVALID_PARAMETER;
1077 if(id < 0 || id > 1) {
1078 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1079 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1082 return _connection_libnet_reset_profile(type, id, callback, user_data);
1085 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1087 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1089 if (!(__connection_check_handle_validity(connection)) ||
1090 interface_name == NULL || host_address == NULL) {
1091 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1092 return CONNECTION_ERROR_INVALID_PARAMETER;
1095 return _connection_libnet_add_route(interface_name, host_address);
1098 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1100 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1102 if (!(__connection_check_handle_validity(connection)) ||
1103 interface_name == NULL || host_address == NULL) {
1104 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1105 return CONNECTION_ERROR_INVALID_PARAMETER;
1108 return _connection_libnet_remove_route(interface_name, host_address);
1111 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1113 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1115 if (!(__connection_check_handle_validity(connection)) ||
1116 interface_name == NULL || host_address == NULL) {
1117 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1118 return CONNECTION_ERROR_INVALID_PARAMETER;
1121 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1124 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1126 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1128 if (!(__connection_check_handle_validity(connection)) ||
1129 interface_name == NULL || host_address == NULL) {
1130 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1131 return CONNECTION_ERROR_INVALID_PARAMETER;
1134 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1137 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1139 int rv = VCONF_OK, rv1 = VCONF_OK;
1140 int last_size = 0, size = 0;
1141 #if defined TIZEN_DUALSIM_ENABLE
1145 if (llsize == NULL) {
1146 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1147 return CONNECTION_ERROR_INVALID_PARAMETER;
1150 switch (statistics_type) {
1151 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1152 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1153 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1154 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1157 return CONNECTION_ERROR_INVALID_PARAMETER;
1160 #if defined TIZEN_DUALSIM_ENABLE
1161 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1162 if (rv != VCONF_OK) {
1163 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1165 return CONNECTION_ERROR_OPERATION_FAILED;
1171 switch (statistics_type) {
1172 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1173 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1175 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1176 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1178 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1179 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1180 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1182 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1183 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1184 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1187 #if defined TIZEN_DUALSIM_ENABLE
1190 switch (statistics_type) {
1191 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1192 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1194 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1195 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1197 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1198 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1199 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1201 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1202 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1203 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1209 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1210 return CONNECTION_ERROR_OPERATION_FAILED;
1214 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1215 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1216 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1219 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1220 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1222 return CONNECTION_ERROR_NONE;
1225 static int __get_statistic(connection_type_e connection_type,
1226 connection_statistics_type_e statistics_type, long long *llsize)
1229 unsigned long long ull_size;
1231 if (llsize == NULL) {
1232 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1233 return CONNECTION_ERROR_INVALID_PARAMETER;
1236 rv = _connection_libnet_check_get_privilege();
1237 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1239 else if (rv != CONNECTION_ERROR_NONE) {
1240 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1241 return CONNECTION_ERROR_OPERATION_FAILED;
1244 if (connection_type == CONNECTION_TYPE_CELLULAR)
1245 return __get_cellular_statistic(statistics_type, llsize);
1246 else if (connection_type == CONNECTION_TYPE_WIFI) {
1247 switch (statistics_type) {
1248 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1249 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1251 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1252 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1254 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1255 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1257 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1258 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1261 return CONNECTION_ERROR_INVALID_PARAMETER;
1264 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1265 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1267 else if (rv != CONNECTION_ERROR_NONE) {
1268 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1269 *llsize = 0; //LCOV_EXCL_LINE
1270 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1273 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1274 *llsize = (long long)ull_size;
1276 return CONNECTION_ERROR_INVALID_PARAMETER;
1278 return CONNECTION_ERROR_NONE;
1281 static int __reset_statistic(connection_type_e connection_type,
1282 connection_statistics_type_e statistics_type)
1288 if (connection_type == CONNECTION_TYPE_CELLULAR)
1289 conn_type = NET_DEVICE_CELLULAR;
1290 else if (connection_type == CONNECTION_TYPE_WIFI)
1291 conn_type = NET_DEVICE_WIFI;
1293 return CONNECTION_ERROR_INVALID_PARAMETER;
1295 switch (statistics_type) {
1296 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1297 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1299 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1300 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1302 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1303 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1305 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1306 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1309 return CONNECTION_ERROR_INVALID_PARAMETER;
1312 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1313 if (rv != CONNECTION_ERROR_NONE)
1316 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1318 return CONNECTION_ERROR_NONE;
1321 EXPORT_API int connection_get_statistics(connection_h connection,
1322 connection_type_e connection_type,
1323 connection_statistics_type_e statistics_type, long long* size)
1325 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1327 if (connection_type == CONNECTION_TYPE_CELLULAR)
1328 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1329 else if (connection_type == CONNECTION_TYPE_WIFI)
1330 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1332 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1333 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1334 return CONNECTION_ERROR_INVALID_PARAMETER;
1337 return __get_statistic(connection_type, statistics_type, size);
1340 EXPORT_API int connection_reset_statistics(connection_h connection,
1341 connection_type_e connection_type,
1342 connection_statistics_type_e statistics_type)
1344 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1346 if (connection_type == CONNECTION_TYPE_CELLULAR)
1347 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1348 else if (connection_type == CONNECTION_TYPE_WIFI)
1349 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1351 if (!__connection_check_handle_validity(connection)) {
1352 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1353 return CONNECTION_ERROR_INVALID_PARAMETER;
1356 return __reset_statistic(connection_type, statistics_type);