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)
210 connection_address_changed_cb callback;
211 connection_handle_s *local_handle = (connection_handle_s *)user_data;
213 if (__connection_check_handle_validity((connection_h)local_handle) != true)
216 ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
218 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
219 "vconf_get_str(VCONFKEY_NETWORK_IP) is Failed");
221 ip6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
222 if (ip6_addr == NULL)
223 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
224 "vconf_get_str(VCONFKEY_NETWORK_IP6) is Failed");
226 callback = __connection_get_ip_changed_callback(local_handle);
227 data = __connection_get_ip_changed_userdata(local_handle);
230 callback(ip_addr, ip6_addr, data);
238 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
243 if (_connection_is_created() != true) {
244 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
245 "If multi-threaded, thread integrity be broken.");
249 for (list = conn_handle_list; list; list = list->next) {
250 handle = (connection_h)list->data;
251 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
255 static int __connection_set_ip_changed_callback(connection_h connection,
256 void *callback, void *user_data)
258 static __thread gint refcount = 0;
259 connection_handle_s *local_handle;
261 local_handle = (connection_handle_s *)connection;
265 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
266 __connection_cb_ip_change_cb, NULL);
267 vconf_notify_key_changed(VCONFKEY_NETWORK_IP6,
268 __connection_cb_ip_change_cb, NULL);
272 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
275 __connection_get_ip_changed_callback(local_handle) != NULL) {
276 if (--refcount == 0) {
277 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
278 __connection_cb_ip_change_cb) < 0) {
279 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
280 "Error to de-register vconf callback(%d)", refcount);
282 CONNECTION_LOG(CONNECTION_INFO,
283 "Successfully de-registered(%d)", refcount);
285 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP6,
286 __connection_cb_ip_change_cb) < 0) {
287 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
288 "Error to de-register vconf callback(%d)", refcount);
290 CONNECTION_LOG(CONNECTION_INFO,
291 "Successfully de-registered(%d)", refcount);
297 local_handle->ip_changed_user_data = user_data;
298 local_handle->ip_changed_callback = callback;
300 return CONNECTION_ERROR_NONE;
303 static connection_address_changed_cb
304 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
306 return local_handle->proxy_changed_callback;
309 static void *__connection_get_proxy_changed_userdata(
310 connection_handle_s *local_handle)
312 return local_handle->proxy_changed_user_data;
315 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
319 connection_address_changed_cb callback;
320 connection_handle_s *local_handle = (connection_handle_s *)user_data;
322 if (__connection_check_handle_validity((connection_h)local_handle) != true)
325 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
327 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
328 "vconf_get_str(VCONFKEY_NETWORK_PROXY) is Failed");
330 callback = __connection_get_proxy_changed_callback(local_handle);
331 data = __connection_get_proxy_changed_userdata(local_handle);
332 /* TODO: IPv6 should be supported */
334 callback(proxy, NULL, data);
341 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
346 if (_connection_is_created() != true) {
347 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
348 "If multi-threaded, thread integrity be broken.");
352 for (list = conn_handle_list; list; list = list->next) {
353 handle = (connection_h)list->data;
354 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
358 static int __connection_set_proxy_changed_callback(connection_h connection,
359 void *callback, void *user_data)
361 static __thread gint refcount = 0;
362 connection_handle_s *local_handle;
364 local_handle = (connection_handle_s *)connection;
368 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
369 __connection_cb_proxy_change_cb, NULL);
372 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
375 __connection_get_proxy_changed_callback(local_handle) != NULL) {
376 if (--refcount == 0) {
377 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
378 __connection_cb_proxy_change_cb) < 0) {
379 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
380 "Error to de-register vconf callback(%d)", refcount);
382 CONNECTION_LOG(CONNECTION_INFO,
383 "Successfully de-registered(%d)", refcount);
389 local_handle->proxy_changed_user_data = user_data;
390 local_handle->proxy_changed_callback = callback;
392 return CONNECTION_ERROR_NONE;
395 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
396 connection_ethernet_cable_state_changed_cb callback, void *user_data)
398 connection_handle_s *local_handle = (connection_handle_s *)connection;
401 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
402 _connection_libnet_set_ethernet_cable_state_changed_cb(
403 __connection_cb_ethernet_cable_state_changed_cb);
406 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1 &&
407 local_handle->ethernet_cable_state_changed_callback)
408 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
411 local_handle->ethernet_cable_state_changed_callback = callback;
412 local_handle->ethernet_cable_state_changed_user_data = user_data;
413 return CONNECTION_ERROR_NONE;
417 static int __connection_get_handle_count(void)
419 return ((int)g_slist_length(conn_handle_list));
422 /* Connection Manager ********************************************************/
423 EXPORT_API int connection_create(connection_h *connection)
425 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
427 if (connection == NULL || __connection_check_handle_validity(*connection)) {
428 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
429 return CONNECTION_ERROR_INVALID_PARAMETER;
432 int rv = _connection_libnet_init();
433 if (rv == NET_ERR_ACCESS_DENIED) {
434 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
435 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
436 } else if (rv != NET_ERR_NONE) {
437 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
438 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
441 *connection = g_try_malloc0(sizeof(connection_handle_s));
442 if (*connection != NULL)
443 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
445 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
447 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
449 return CONNECTION_ERROR_NONE;
452 EXPORT_API int connection_destroy(connection_h connection)
454 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
456 if (!(__connection_check_handle_validity(connection))) {
457 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
458 return CONNECTION_ERROR_INVALID_PARAMETER;
461 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
463 __connection_set_type_changed_callback(connection, NULL, NULL);
464 __connection_set_ip_changed_callback(connection, NULL, NULL);
465 __connection_set_proxy_changed_callback(connection, NULL, NULL);
466 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
468 conn_handle_list = g_slist_remove(conn_handle_list, connection);
473 if (__connection_get_handle_count() == 0) {
474 _connection_libnet_deinit();
475 _connection_callback_cleanup();
478 return CONNECTION_ERROR_NONE;
481 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
486 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
488 if (type == NULL || !(__connection_check_handle_validity(connection))) {
489 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
490 return CONNECTION_ERROR_INVALID_PARAMETER;
493 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
494 if (rv != VCONF_OK) {
495 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
496 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
499 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
501 *type = __connection_convert_net_state(status);
503 return CONNECTION_ERROR_NONE;
506 EXPORT_API int connection_get_ip_address(connection_h connection,
507 connection_address_family_e address_family, char** ip_address)
509 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
511 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
512 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
513 return CONNECTION_ERROR_INVALID_PARAMETER;
516 switch (address_family) {
517 case CONNECTION_ADDRESS_FAMILY_IPV4:
518 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
520 case CONNECTION_ADDRESS_FAMILY_IPV6:
521 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
524 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
525 return CONNECTION_ERROR_INVALID_PARAMETER;
528 if (*ip_address == NULL) {
529 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
530 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
533 return CONNECTION_ERROR_NONE;
536 EXPORT_API int connection_get_proxy(connection_h connection,
537 connection_address_family_e address_family, char** proxy)
539 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
541 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
542 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
543 return CONNECTION_ERROR_INVALID_PARAMETER;
546 switch (address_family) {
547 case CONNECTION_ADDRESS_FAMILY_IPV4:
548 case CONNECTION_ADDRESS_FAMILY_IPV6:
549 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
552 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
553 return CONNECTION_ERROR_INVALID_PARAMETER;
556 if (*proxy == NULL) {
557 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
558 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
561 return CONNECTION_ERROR_NONE;
564 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
567 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
569 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
571 if (type == CONNECTION_TYPE_WIFI)
572 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
573 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
574 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
576 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
577 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
578 return CONNECTION_ERROR_INVALID_PARAMETER;
582 case CONNECTION_TYPE_WIFI:
583 if (__builtin_expect(tv_profile == -1, 0)) {
585 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
586 if (*profileName == 't' || *profileName == 'T')
592 if (tv_profile == 1) {
593 fp = fopen(WIFI_MAC_INFO_FILE, "r");
595 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
596 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
599 if (fgets(buf, sizeof(buf), fp) == NULL) {
600 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
601 fclose(fp); //LCOV_EXCL_LINE
602 return CONNECTION_ERROR_OPERATION_FAILED;
605 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
607 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
608 if (*mac_addr == NULL) {
609 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
610 fclose(fp); //LCOV_EXCL_LINE
611 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
613 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
616 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
618 if (*mac_addr == NULL) {
619 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
620 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
625 case CONNECTION_TYPE_ETHERNET:
626 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
628 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
629 return CONNECTION_ERROR_OUT_OF_MEMORY;
632 if (fgets(buf, sizeof(buf), fp) == NULL) {
633 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
635 return CONNECTION_ERROR_OPERATION_FAILED;
638 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
640 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
641 if (*mac_addr == NULL) {
642 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
644 return CONNECTION_ERROR_OUT_OF_MEMORY;
647 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
653 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
654 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
657 /* Checking Invalid MAC Address */
658 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
659 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
660 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
661 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
664 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
666 return CONNECTION_ERROR_NONE;
670 EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
672 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
674 if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
675 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
676 return CONNECTION_ERROR_INVALID_PARAMETER;
679 int rv = _connection_libnet_get_metered_state(is_metered);
680 if (rv != CONNECTION_ERROR_NONE) {
681 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
682 return rv; //LCOV_EXCL_LINE
685 CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
686 return CONNECTION_ERROR_NONE;
690 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
694 int cellular_state = 0;
695 #if defined TIZEN_DUALSIM_ENABLE
699 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
701 if (state == NULL || !(__connection_check_handle_validity(connection))) {
702 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
703 return CONNECTION_ERROR_INVALID_PARAMETER;
706 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
707 if (rv != VCONF_OK) {
708 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
709 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
712 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
713 *state = __connection_convert_cellular_state(status);
715 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
716 #if defined TIZEN_DUALSIM_ENABLE
717 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
718 if (rv != VCONF_OK) {
719 CONNECTION_LOG(CONNECTION_ERROR,
720 "Failed to get default subscriber id", sim_id);
721 return CONNECTION_ERROR_OPERATION_FAILED;
725 case CONNECTION_CELLULAR_SUBSCRIBER_1:
727 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
728 #if defined TIZEN_DUALSIM_ENABLE
731 case CONNECTION_CELLULAR_SUBSCRIBER_2:
732 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
736 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
737 return CONNECTION_ERROR_OPERATION_FAILED;
740 if (rv != VCONF_OK) {
741 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
742 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
746 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
748 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
749 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
750 cellular_state == VCONFKEY_DNET_TRANSFER)
751 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
753 return CONNECTION_ERROR_NONE;
756 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
758 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
760 if (state == NULL || !(__connection_check_handle_validity(connection))) {
761 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
762 return CONNECTION_ERROR_INVALID_PARAMETER;
765 int rv = _connection_libnet_get_wifi_state(state);
766 if (rv != CONNECTION_ERROR_NONE) {
767 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
768 return rv; //LCOV_EXCL_LINE
771 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
773 return CONNECTION_ERROR_NONE;
777 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
779 CHECK_FEATURE_SUPPORTED(ETHERNET_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_ethernet_state(state);
789 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
791 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
793 if (state == NULL || !(__connection_check_handle_validity(connection))) {
794 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
795 return CONNECTION_ERROR_INVALID_PARAMETER;
798 return _connection_libnet_get_ethernet_cable_state(state);
801 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
802 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
804 DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
805 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
807 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
808 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
809 return CONNECTION_ERROR_INVALID_PARAMETER;
812 DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
813 "connection_ethernet_cable_state_changed_cb");
815 return __connection_set_ethernet_cable_state_changed_cb(connection,
816 (connection_ethernet_cable_state_changed_cb)callback, user_data);
819 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
821 DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
822 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
824 if (!(__connection_check_handle_validity(connection))) {
825 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
826 return CONNECTION_ERROR_INVALID_PARAMETER;
829 return __connection_set_ethernet_cable_state_changed_cb(connection,
833 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
834 connection_ethernet_cable_state_changed_cb callback, void *user_data)
836 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
838 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
839 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
840 return CONNECTION_ERROR_INVALID_PARAMETER;
843 return __connection_set_ethernet_cable_state_changed_cb(connection,
844 callback, user_data);
847 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
849 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
851 if (!(__connection_check_handle_validity(connection))) {
852 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
853 return CONNECTION_ERROR_INVALID_PARAMETER;
856 return __connection_set_ethernet_cable_state_changed_cb(connection,
861 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
863 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
865 if (state == NULL || !(__connection_check_handle_validity(connection))) {
866 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
867 return CONNECTION_ERROR_INVALID_PARAMETER;
870 return _connection_libnet_get_bluetooth_state(state);
873 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
874 connection_type_changed_cb callback, void* user_data)
876 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
878 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
879 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
880 return CONNECTION_ERROR_INVALID_PARAMETER;
883 return __connection_set_type_changed_callback(connection, callback, user_data);
886 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
888 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
890 if (!(__connection_check_handle_validity(connection))) {
891 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
892 return CONNECTION_ERROR_INVALID_PARAMETER;
895 return __connection_set_type_changed_callback(connection, NULL, NULL);
898 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
899 connection_address_changed_cb callback, void* user_data)
901 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
903 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
904 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
905 return CONNECTION_ERROR_INVALID_PARAMETER;
908 return __connection_set_ip_changed_callback(connection, callback, user_data);
911 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
913 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
915 if (!(__connection_check_handle_validity(connection))) {
916 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
917 return CONNECTION_ERROR_INVALID_PARAMETER;
920 return __connection_set_ip_changed_callback(connection, NULL, NULL);
923 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
924 connection_address_changed_cb callback, void* user_data)
926 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
928 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
929 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
930 return CONNECTION_ERROR_INVALID_PARAMETER;
933 return __connection_set_proxy_changed_callback(connection, callback, user_data);
936 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
938 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
940 if (!(__connection_check_handle_validity(connection))) {
941 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
942 return CONNECTION_ERROR_INVALID_PARAMETER;
945 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
948 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
951 net_profile_info_t *profile_info = profile;
953 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
955 if (!(__connection_check_handle_validity(connection)) ||
956 !(_connection_libnet_check_profile_validity(profile))) {
957 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
958 return CONNECTION_ERROR_INVALID_PARAMETER;
961 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
962 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
963 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
966 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
967 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
968 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
969 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
972 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
973 (net_profile_info_t*)profile);
974 if (rv == NET_ERR_ACCESS_DENIED) {
975 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
976 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
977 } else if (rv != NET_ERR_NONE) {
978 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
979 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
982 return CONNECTION_ERROR_NONE;
985 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
988 net_profile_info_t *profile_info = profile;
990 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
992 if (!(__connection_check_handle_validity(connection)) ||
993 !(_connection_libnet_check_profile_validity(profile))) {
994 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
995 return CONNECTION_ERROR_INVALID_PARAMETER;
998 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
999 profile_info->profile_type != NET_DEVICE_WIFI) {
1000 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1001 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1004 rv = net_delete_profile(profile_info->ProfileName);
1005 if (rv == NET_ERR_ACCESS_DENIED) {
1006 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1007 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1008 } else if (rv != NET_ERR_NONE) {
1009 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
1010 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1013 return CONNECTION_ERROR_NONE;
1016 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
1019 net_profile_info_t *profile_info = profile;
1021 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1023 if (!(__connection_check_handle_validity(connection)) ||
1024 !(_connection_libnet_check_profile_validity(profile))) {
1025 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1026 return CONNECTION_ERROR_INVALID_PARAMETER;
1029 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
1030 if (rv == NET_ERR_ACCESS_DENIED) {
1031 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1032 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1033 } else if (rv != NET_ERR_NONE) {
1034 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
1035 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1038 return CONNECTION_ERROR_NONE;
1041 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1042 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1044 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1046 if (!(__connection_check_handle_validity(connection)) ||
1047 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1048 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1049 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1050 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1051 return CONNECTION_ERROR_INVALID_PARAMETER;
1054 return _connection_libnet_get_profile_iterator(type, profile_iterator);
1057 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1058 connection_profile_h* profile)
1060 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1062 return _connection_libnet_get_iterator_next(profile_iterator, profile);
1065 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1067 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1069 return _connection_libnet_iterator_has_next(profile_iterator);
1072 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1074 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1076 return _connection_libnet_destroy_iterator(profile_iterator);
1079 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1081 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1083 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1084 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1085 return CONNECTION_ERROR_INVALID_PARAMETER;
1088 return _connection_libnet_get_current_profile(profile);
1091 EXPORT_API int connection_get_default_cellular_service_profile(
1092 connection_h connection, connection_cellular_service_type_e type,
1093 connection_profile_h *profile)
1095 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1097 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1098 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1099 return CONNECTION_ERROR_INVALID_PARAMETER;
1102 return _connection_libnet_get_cellular_service_profile(type, profile);
1105 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1106 connection_cellular_service_type_e type, connection_profile_h profile)
1108 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1110 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1111 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1112 return CONNECTION_ERROR_INVALID_PARAMETER;
1115 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1118 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1119 connection_cellular_service_type_e type, connection_profile_h profile,
1120 connection_set_default_cb callback, void* user_data)
1122 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1124 if (!(__connection_check_handle_validity(connection)) ||
1125 profile == NULL || callback == NULL) {
1126 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1127 return CONNECTION_ERROR_INVALID_PARAMETER;
1130 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1133 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1134 connection_opened_cb callback, void* user_data)
1136 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1138 if (!(__connection_check_handle_validity(connection)) ||
1139 profile == NULL || callback == NULL) {
1140 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1141 return CONNECTION_ERROR_INVALID_PARAMETER;
1144 return _connection_libnet_open_profile(profile, callback, user_data);
1147 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1148 connection_closed_cb callback, void* user_data)
1150 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1152 if (!(__connection_check_handle_validity(connection)) ||
1153 profile == NULL || callback == NULL) {
1154 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1155 return CONNECTION_ERROR_INVALID_PARAMETER;
1158 return _connection_libnet_close_profile(profile, callback, user_data);
1161 EXPORT_API int connection_reset_profile(connection_h connection,
1162 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1164 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1166 if (!(__connection_check_handle_validity(connection))) {
1167 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1168 return CONNECTION_ERROR_INVALID_PARAMETER;
1171 if (id < 0 || id > 1) {
1172 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1173 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1176 return _connection_libnet_reset_profile(type, id, callback, user_data);
1179 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1181 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1183 if (!(__connection_check_handle_validity(connection)) ||
1184 interface_name == NULL || host_address == NULL) {
1185 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1186 return CONNECTION_ERROR_INVALID_PARAMETER;
1189 return _connection_libnet_add_route(interface_name, host_address);
1192 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1194 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1196 if (!(__connection_check_handle_validity(connection)) ||
1197 interface_name == NULL || host_address == NULL) {
1198 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1199 return CONNECTION_ERROR_INVALID_PARAMETER;
1202 return _connection_libnet_remove_route(interface_name, host_address);
1205 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1207 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1209 if (!(__connection_check_handle_validity(connection)) ||
1210 interface_name == NULL || host_address == NULL) {
1211 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1212 return CONNECTION_ERROR_INVALID_PARAMETER;
1215 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1218 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1220 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1222 if (!(__connection_check_handle_validity(connection)) ||
1223 interface_name == NULL || host_address == NULL) {
1224 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1225 return CONNECTION_ERROR_INVALID_PARAMETER;
1228 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1231 EXPORT_API int connection_add_route_entry(connection_h connection,
1232 connection_address_family_e address_family, const char *interface_name,
1233 const char *host_address, const char *gateway)
1235 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1237 if (!(__connection_check_handle_validity(connection)) ||
1238 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1239 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1240 interface_name == NULL || host_address == NULL) {
1241 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1242 return CONNECTION_ERROR_INVALID_PARAMETER;
1245 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1246 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1247 interface_name, host_address, gateway);
1249 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1250 interface_name, host_address, gateway);
1252 return CONNECTION_ERROR_NONE;
1255 EXPORT_API int connection_remove_route_entry(connection_h connection,
1256 connection_address_family_e address_family, const char *interface_name,
1257 const char *host_address, const char *gateway)
1259 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1261 if (!(__connection_check_handle_validity(connection)) ||
1262 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1263 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1264 interface_name == NULL || host_address == NULL) {
1265 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1266 return CONNECTION_ERROR_INVALID_PARAMETER;
1269 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1270 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1271 interface_name, host_address, gateway);
1273 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1274 interface_name, host_address, gateway);
1276 return CONNECTION_ERROR_NONE;
1279 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1281 int rv = VCONF_OK, rv1 = VCONF_OK;
1282 int last_size = 0, size = 0;
1283 #if defined TIZEN_DUALSIM_ENABLE
1287 if (llsize == NULL) {
1288 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1289 return CONNECTION_ERROR_INVALID_PARAMETER;
1292 switch (statistics_type) {
1293 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1294 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1295 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1296 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1299 return CONNECTION_ERROR_INVALID_PARAMETER;
1302 #if defined TIZEN_DUALSIM_ENABLE
1303 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1304 if (rv != VCONF_OK) {
1305 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1307 return CONNECTION_ERROR_OPERATION_FAILED;
1313 switch (statistics_type) {
1314 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1315 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1317 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1318 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1320 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1321 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1322 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1324 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1325 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1326 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1329 #if defined TIZEN_DUALSIM_ENABLE
1332 switch (statistics_type) {
1333 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1334 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1336 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1337 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1339 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1340 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1341 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1343 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1344 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1345 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1351 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1352 return CONNECTION_ERROR_OPERATION_FAILED;
1356 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1357 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1358 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1361 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1362 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1364 return CONNECTION_ERROR_NONE;
1367 static int __get_statistic(connection_type_e connection_type,
1368 connection_statistics_type_e statistics_type, long long *llsize)
1371 unsigned long long ull_size;
1373 if (llsize == NULL) {
1374 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1375 return CONNECTION_ERROR_INVALID_PARAMETER;
1378 rv = _connection_libnet_check_get_privilege();
1379 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1381 else if (rv != CONNECTION_ERROR_NONE) {
1382 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1383 return CONNECTION_ERROR_OPERATION_FAILED;
1386 if (connection_type == CONNECTION_TYPE_CELLULAR)
1387 return __get_cellular_statistic(statistics_type, llsize);
1388 else if (connection_type == CONNECTION_TYPE_WIFI) {
1389 switch (statistics_type) {
1390 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1391 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1393 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1394 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1396 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1397 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1399 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1400 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1403 return CONNECTION_ERROR_INVALID_PARAMETER;
1406 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1407 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1409 else if (rv != CONNECTION_ERROR_NONE) {
1410 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1411 *llsize = 0; //LCOV_EXCL_LINE
1412 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1415 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1416 *llsize = (long long)ull_size;
1418 return CONNECTION_ERROR_INVALID_PARAMETER;
1420 return CONNECTION_ERROR_NONE;
1423 static int __reset_statistic(connection_type_e connection_type,
1424 connection_statistics_type_e statistics_type)
1430 if (connection_type == CONNECTION_TYPE_CELLULAR)
1431 conn_type = NET_DEVICE_CELLULAR;
1432 else if (connection_type == CONNECTION_TYPE_WIFI)
1433 conn_type = NET_DEVICE_WIFI;
1435 return CONNECTION_ERROR_INVALID_PARAMETER;
1437 switch (statistics_type) {
1438 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1439 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1441 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1442 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1444 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1445 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1447 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1448 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1451 return CONNECTION_ERROR_INVALID_PARAMETER;
1454 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1455 if (rv != CONNECTION_ERROR_NONE)
1458 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1460 return CONNECTION_ERROR_NONE;
1463 EXPORT_API int connection_get_statistics(connection_h connection,
1464 connection_type_e connection_type,
1465 connection_statistics_type_e statistics_type, long long* size)
1467 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1469 if (connection_type == CONNECTION_TYPE_CELLULAR)
1470 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1471 else if (connection_type == CONNECTION_TYPE_WIFI)
1472 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1474 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1475 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1476 return CONNECTION_ERROR_INVALID_PARAMETER;
1479 return __get_statistic(connection_type, statistics_type, size);
1482 EXPORT_API int connection_reset_statistics(connection_h connection,
1483 connection_type_e connection_type,
1484 connection_statistics_type_e statistics_type)
1486 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1488 if (connection_type == CONNECTION_TYPE_CELLULAR)
1489 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1490 else if (connection_type == CONNECTION_TYPE_WIFI)
1491 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1493 if (!__connection_check_handle_validity(connection)) {
1494 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1495 return CONNECTION_ERROR_INVALID_PARAMETER;
1498 return __reset_statistic(connection_type, statistics_type);
1501 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1502 connection_type_e connection_type, connection_ipv6_address_cb callback,
1505 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1506 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1508 GSList *ipv6_address_list = NULL;
1510 if (!(__connection_check_handle_validity(connection))) {
1511 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1512 return CONNECTION_ERROR_INVALID_PARAMETER;
1515 int rv = CONNECTION_ERROR_NONE;
1517 switch (connection_type) {
1518 case CONNECTION_TYPE_WIFI:
1519 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1520 &ipv6_address_list);
1522 case CONNECTION_TYPE_CELLULAR:
1523 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1524 &ipv6_address_list);
1526 case CONNECTION_TYPE_ETHERNET:
1527 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1528 &ipv6_address_list);
1530 case CONNECTION_TYPE_BT:
1531 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1532 &ipv6_address_list);
1535 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1536 return CONNECTION_ERROR_INVALID_PARAMETER;
1539 if (rv != NET_ERR_NONE) {
1540 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1541 " Failed = %d\n", rv);
1542 return CONNECTION_ERROR_OPERATION_FAILED;
1546 for (list = ipv6_address_list; list; list = list->next) {
1547 rv = callback((char *)list->data, user_data);
1552 g_slist_free_full(ipv6_address_list, g_free);
1553 ipv6_address_list = NULL;
1555 return CONNECTION_ERROR_NONE;
1558 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1562 if (!(__connection_check_handle_validity(connection))) {
1563 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1564 return CONNECTION_ERROR_INVALID_PARAMETER;
1567 ret = _connection_libnet_start_tcpdump();
1568 if (ret != CONNECTION_ERROR_NONE) {
1569 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
1573 return CONNECTION_ERROR_NONE;
1576 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1580 if (!(__connection_check_handle_validity(connection))) {
1581 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1582 return CONNECTION_ERROR_INVALID_PARAMETER;
1585 ret = _connection_libnet_stop_tcpdump();
1586 if (ret != CONNECTION_ERROR_NONE) {
1587 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
1591 return CONNECTION_ERROR_NONE;
1594 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1598 if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1599 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1600 return CONNECTION_ERROR_INVALID_PARAMETER;
1603 ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
1604 if (ret != CONNECTION_ERROR_NONE) {
1605 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
1609 return CONNECTION_ERROR_NONE;