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 bool _connection_check_handle_validity(connection_h connection)
79 return __connection_check_handle_validity(connection);
82 static connection_type_changed_cb
83 __connection_get_type_changed_callback(connection_handle_s *local_handle)
85 return local_handle->type_changed_callback;
88 static void *__connection_get_type_changed_userdata(
89 connection_handle_s *local_handle)
91 return local_handle->type_changed_user_data;
94 static void __connection_cb_type_change_cb(int type)
99 connection_type_changed_cb callback;
102 if (_connection_is_created() != true) {
103 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
104 "If multi-threaded, thread integrity be broken.");
108 state = __connection_convert_net_state(type);
110 for (list = conn_handle_list; list; list = list->next) {
111 handle = (connection_h)list->data;
113 callback = __connection_get_type_changed_callback(handle);
114 data = __connection_get_type_changed_userdata(handle);
116 callback(state, data);
120 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
122 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
126 for (list = conn_handle_list; list; list = list->next) {
127 connection_handle_s *local_handle = (connection_handle_s *)list->data;
128 if (local_handle->ethernet_cable_state_changed_callback)
129 local_handle->ethernet_cable_state_changed_callback(state,
130 local_handle->ethernet_cable_state_changed_user_data);
134 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
139 for (list = conn_handle_list; list; list = list->next) {
140 connection_handle_s *local_handle = (connection_handle_s *)list->data;
141 if (local_handle->ethernet_cable_state_changed_callback) count++;
147 static int __connection_set_type_changed_callback(connection_h connection,
148 void *callback, void *user_data)
150 static __thread gint refcount = 0;
151 connection_handle_s *local_handle;
153 local_handle = (connection_handle_s *)connection;
157 _connection_libnet_set_type_changed_cb(
158 __connection_cb_type_change_cb);
161 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
165 __connection_get_type_changed_callback(local_handle) != NULL) {
166 if (--refcount == 0) {
167 _connection_libnet_set_type_changed_cb(NULL);
168 CONNECTION_LOG(CONNECTION_INFO,
169 "Successfully de-registered(%d)", refcount);
174 local_handle->type_changed_user_data = user_data;
175 local_handle->type_changed_callback = callback;
177 return CONNECTION_ERROR_NONE;
180 static connection_address_changed_cb
181 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
183 return local_handle->ip_changed_callback;
186 static void *__connection_get_ip_changed_userdata(
187 connection_handle_s *local_handle)
189 return local_handle->ip_changed_user_data;
192 static void __connection_cb_ip_change_cb(
193 connection_address_family_e addr_family, char *ip_addr)
197 char *ip4_addr = NULL;
198 char *ip6_addr = NULL;
200 connection_address_changed_cb callback;
202 if (_connection_is_created() != true) {
203 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
204 "If multi-threaded, thread integrity be broken.");
208 switch (addr_family) {
209 case CONNECTION_ADDRESS_FAMILY_IPV4:
210 ip4_addr = g_strdup(ip_addr);
212 ip6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
213 if (ip6_addr == NULL)
214 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
215 "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
217 case CONNECTION_ADDRESS_FAMILY_IPV6:
218 ip6_addr = g_strdup(ip_addr);
220 ip4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
221 if (ip4_addr == NULL)
222 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
223 "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
226 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Address Type");
230 for (list = conn_handle_list; list; list = list->next) {
231 handle = (connection_h)list->data;
233 callback = __connection_get_ip_changed_callback(handle);
234 data = __connection_get_ip_changed_userdata(handle);
237 callback(ip4_addr, ip6_addr, data);
244 static int __connection_set_ip_changed_callback(connection_h connection,
245 void *callback, void *user_data)
247 static __thread gint refcount = 0;
248 connection_handle_s *local_handle;
250 local_handle = (connection_handle_s *)connection;
254 _connection_libnet_set_ip_changed_cb(
255 __connection_cb_ip_change_cb);
258 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
262 __connection_get_ip_changed_callback(local_handle) != NULL) {
263 if (--refcount == 0) {
264 _connection_libnet_set_ip_changed_cb(NULL);
265 CONNECTION_LOG(CONNECTION_INFO,
266 "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 void __connection_cb_proxy_change_cb(char *proxy_addr)
294 connection_address_changed_cb callback;
296 if (_connection_is_created() != true) {
297 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
298 "If multi-threaded, thread integrity be broken.");
302 for (list = conn_handle_list; list; list = list->next) {
303 handle = (connection_h)list->data;
305 callback = __connection_get_proxy_changed_callback(handle);
306 data = __connection_get_proxy_changed_userdata(handle);
307 /* TODO: IPv6 should be supported */
309 callback(proxy_addr, NULL, data);
313 static int __connection_set_proxy_changed_callback(connection_h connection,
314 void *callback, void *user_data)
316 static __thread gint refcount = 0;
317 connection_handle_s *local_handle;
319 local_handle = (connection_handle_s *)connection;
323 _connection_libnet_set_proxy_changed_cb(
324 __connection_cb_proxy_change_cb);
327 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
331 __connection_get_proxy_changed_callback(local_handle) != NULL) {
332 if (--refcount == 0) {
333 _connection_libnet_set_proxy_changed_cb(NULL);
334 CONNECTION_LOG(CONNECTION_INFO,
335 "Successfully de-registered(%d)", refcount);
340 local_handle->proxy_changed_user_data = user_data;
341 local_handle->proxy_changed_callback = callback;
343 return CONNECTION_ERROR_NONE;
346 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
347 connection_ethernet_cable_state_changed_cb callback, void *user_data)
349 connection_handle_s *local_handle = (connection_handle_s *)connection;
352 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
353 _connection_libnet_set_ethernet_cable_state_changed_cb(
354 __connection_cb_ethernet_cable_state_changed_cb);
357 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1 &&
358 local_handle->ethernet_cable_state_changed_callback)
359 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
362 local_handle->ethernet_cable_state_changed_callback = callback;
363 local_handle->ethernet_cable_state_changed_user_data = user_data;
364 return CONNECTION_ERROR_NONE;
368 static int __connection_get_handle_count(void)
370 return ((int)g_slist_length(conn_handle_list));
373 /* Connection Manager ********************************************************/
374 EXPORT_API int connection_create(connection_h *connection)
376 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
378 if (connection == NULL || __connection_check_handle_validity(*connection)) {
379 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
380 return CONNECTION_ERROR_INVALID_PARAMETER;
383 int rv = _connection_libnet_init();
384 if (rv == NET_ERR_ACCESS_DENIED) {
385 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
386 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
387 } else if (rv != NET_ERR_NONE) {
388 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
389 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
392 *connection = g_try_malloc0(sizeof(connection_handle_s));
393 if (*connection != NULL)
394 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
396 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
398 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
400 return CONNECTION_ERROR_NONE;
403 EXPORT_API int connection_destroy(connection_h connection)
405 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
407 if (!(__connection_check_handle_validity(connection))) {
408 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
409 return CONNECTION_ERROR_INVALID_PARAMETER;
412 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
414 __connection_set_type_changed_callback(connection, NULL, NULL);
415 __connection_set_ip_changed_callback(connection, NULL, NULL);
416 __connection_set_proxy_changed_callback(connection, NULL, NULL);
417 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
419 conn_handle_list = g_slist_remove(conn_handle_list, connection);
424 if (__connection_get_handle_count() == 0) {
425 _connection_libnet_deinit();
426 _connection_callback_cleanup();
429 return CONNECTION_ERROR_NONE;
432 EXPORT_API int connection_create_cs(int tid, connection_h *connection)
436 rv = connection_create(connection);
438 if (rv == CONNECTION_ERROR_NONE)
439 _connection_set_cs_tid(tid);
444 EXPORT_API int connection_destroy_cs(int tid, connection_h connection)
448 _connection_unset_cs_tid(tid);
449 rv = connection_destroy(connection);
454 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
459 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
461 if (type == NULL || !(__connection_check_handle_validity(connection))) {
462 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
463 return CONNECTION_ERROR_INVALID_PARAMETER;
466 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
467 if (rv != VCONF_OK) {
468 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
469 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
472 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
474 *type = __connection_convert_net_state(status);
476 return CONNECTION_ERROR_NONE;
479 EXPORT_API int connection_get_ip_address(connection_h connection,
480 connection_address_family_e address_family, char** ip_address)
482 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
484 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
485 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
486 return CONNECTION_ERROR_INVALID_PARAMETER;
489 switch (address_family) {
490 case CONNECTION_ADDRESS_FAMILY_IPV4:
491 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
493 case CONNECTION_ADDRESS_FAMILY_IPV6:
494 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
497 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
498 return CONNECTION_ERROR_INVALID_PARAMETER;
501 if (*ip_address == NULL) {
502 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
503 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
506 return CONNECTION_ERROR_NONE;
509 EXPORT_API int connection_get_proxy(connection_h connection,
510 connection_address_family_e address_family, char** proxy)
512 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
514 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
515 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
516 return CONNECTION_ERROR_INVALID_PARAMETER;
519 switch (address_family) {
520 case CONNECTION_ADDRESS_FAMILY_IPV4:
521 case CONNECTION_ADDRESS_FAMILY_IPV6:
522 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
525 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
526 return CONNECTION_ERROR_INVALID_PARAMETER;
529 if (*proxy == NULL) {
530 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
531 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
534 return CONNECTION_ERROR_NONE;
537 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
540 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
542 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
544 if (type == CONNECTION_TYPE_WIFI)
545 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
546 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
547 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
549 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
550 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
551 return CONNECTION_ERROR_INVALID_PARAMETER;
555 case CONNECTION_TYPE_WIFI:
556 if (__builtin_expect(tv_profile == -1, 0)) {
558 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
559 if (*profileName == 't' || *profileName == 'T')
565 if (tv_profile == 1) {
566 fp = fopen(WIFI_MAC_INFO_FILE, "r");
568 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
569 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
572 if (fgets(buf, sizeof(buf), fp) == NULL) {
573 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
574 fclose(fp); //LCOV_EXCL_LINE
575 return CONNECTION_ERROR_OPERATION_FAILED;
578 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
580 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
581 if (*mac_addr == NULL) {
582 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
583 fclose(fp); //LCOV_EXCL_LINE
584 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
586 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
589 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
591 if (*mac_addr == NULL) {
592 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
593 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
598 case CONNECTION_TYPE_ETHERNET:
599 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
601 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
602 return CONNECTION_ERROR_OUT_OF_MEMORY;
605 if (fgets(buf, sizeof(buf), fp) == NULL) {
606 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
608 return CONNECTION_ERROR_OPERATION_FAILED;
611 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
613 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
614 if (*mac_addr == NULL) {
615 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
617 return CONNECTION_ERROR_OUT_OF_MEMORY;
620 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
626 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
627 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
630 /* Checking Invalid MAC Address */
631 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
632 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
633 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
634 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
637 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
639 return CONNECTION_ERROR_NONE;
643 EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
645 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
647 if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
648 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
649 return CONNECTION_ERROR_INVALID_PARAMETER;
652 int rv = _connection_libnet_get_metered_state(is_metered);
653 if (rv != CONNECTION_ERROR_NONE) {
654 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
655 return rv; //LCOV_EXCL_LINE
658 CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
659 return CONNECTION_ERROR_NONE;
663 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
667 int cellular_state = 0;
668 #if defined TIZEN_DUALSIM_ENABLE
672 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
674 if (state == NULL || !(__connection_check_handle_validity(connection))) {
675 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
676 return CONNECTION_ERROR_INVALID_PARAMETER;
679 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
680 if (rv != VCONF_OK) {
681 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
682 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
685 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
686 *state = __connection_convert_cellular_state(status);
688 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
689 #if defined TIZEN_DUALSIM_ENABLE
690 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
691 if (rv != VCONF_OK) {
692 CONNECTION_LOG(CONNECTION_ERROR,
693 "Failed to get default subscriber id", sim_id);
694 return CONNECTION_ERROR_OPERATION_FAILED;
698 case CONNECTION_CELLULAR_SUBSCRIBER_1:
700 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
701 #if defined TIZEN_DUALSIM_ENABLE
704 case CONNECTION_CELLULAR_SUBSCRIBER_2:
705 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
709 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
710 return CONNECTION_ERROR_OPERATION_FAILED;
713 if (rv != VCONF_OK) {
714 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
715 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
719 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
721 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
722 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
723 cellular_state == VCONFKEY_DNET_TRANSFER)
724 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
726 return CONNECTION_ERROR_NONE;
729 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
731 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
733 if (state == NULL || !(__connection_check_handle_validity(connection))) {
734 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
735 return CONNECTION_ERROR_INVALID_PARAMETER;
738 int rv = _connection_libnet_get_wifi_state(state);
739 if (rv != CONNECTION_ERROR_NONE) {
740 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
741 return rv; //LCOV_EXCL_LINE
744 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
746 return CONNECTION_ERROR_NONE;
750 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
752 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
754 if (state == NULL || !(__connection_check_handle_validity(connection))) {
755 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
756 return CONNECTION_ERROR_INVALID_PARAMETER;
759 return _connection_libnet_get_ethernet_state(state);
762 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
764 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
766 if (state == NULL || !(__connection_check_handle_validity(connection))) {
767 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
768 return CONNECTION_ERROR_INVALID_PARAMETER;
771 return _connection_libnet_get_ethernet_cable_state(state);
774 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
775 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
777 DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
778 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
780 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
781 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
782 return CONNECTION_ERROR_INVALID_PARAMETER;
785 DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
786 "connection_ethernet_cable_state_changed_cb");
788 return __connection_set_ethernet_cable_state_changed_cb(connection,
789 (connection_ethernet_cable_state_changed_cb)callback, user_data);
792 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
794 DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
795 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
797 if (!(__connection_check_handle_validity(connection))) {
798 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
799 return CONNECTION_ERROR_INVALID_PARAMETER;
802 return __connection_set_ethernet_cable_state_changed_cb(connection,
806 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
807 connection_ethernet_cable_state_changed_cb callback, void *user_data)
809 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
811 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
812 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
813 return CONNECTION_ERROR_INVALID_PARAMETER;
816 return __connection_set_ethernet_cable_state_changed_cb(connection,
817 callback, user_data);
820 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
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,
834 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
836 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
838 if (state == NULL || !(__connection_check_handle_validity(connection))) {
839 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
840 return CONNECTION_ERROR_INVALID_PARAMETER;
843 return _connection_libnet_get_bluetooth_state(state);
846 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
847 connection_type_changed_cb callback, void* user_data)
849 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
851 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
852 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
853 return CONNECTION_ERROR_INVALID_PARAMETER;
856 return __connection_set_type_changed_callback(connection, callback, user_data);
859 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
861 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
863 if (!(__connection_check_handle_validity(connection))) {
864 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
865 return CONNECTION_ERROR_INVALID_PARAMETER;
868 return __connection_set_type_changed_callback(connection, NULL, NULL);
871 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
872 connection_address_changed_cb callback, void* user_data)
874 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
876 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
877 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
878 return CONNECTION_ERROR_INVALID_PARAMETER;
881 return __connection_set_ip_changed_callback(connection, callback, user_data);
884 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
886 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
888 if (!(__connection_check_handle_validity(connection))) {
889 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
890 return CONNECTION_ERROR_INVALID_PARAMETER;
893 return __connection_set_ip_changed_callback(connection, NULL, NULL);
896 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
897 connection_address_changed_cb callback, void* user_data)
899 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
901 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
902 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
903 return CONNECTION_ERROR_INVALID_PARAMETER;
906 return __connection_set_proxy_changed_callback(connection, callback, user_data);
909 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
911 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
913 if (!(__connection_check_handle_validity(connection))) {
914 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
915 return CONNECTION_ERROR_INVALID_PARAMETER;
918 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
921 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
924 net_profile_info_t *profile_info = profile;
926 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
928 if (!(__connection_check_handle_validity(connection)) ||
929 !(_connection_libnet_check_profile_validity(profile))) {
930 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
931 return CONNECTION_ERROR_INVALID_PARAMETER;
934 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
935 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
936 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
939 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
940 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
941 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
942 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
945 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
946 (net_profile_info_t*)profile);
947 if (rv == NET_ERR_ACCESS_DENIED) {
948 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
949 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
950 } else if (rv != NET_ERR_NONE) {
951 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
952 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
955 return CONNECTION_ERROR_NONE;
958 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
961 net_profile_info_t *profile_info = profile;
963 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
965 if (!(__connection_check_handle_validity(connection)) ||
966 !(_connection_libnet_check_profile_validity(profile))) {
967 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
968 return CONNECTION_ERROR_INVALID_PARAMETER;
971 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
972 profile_info->profile_type != NET_DEVICE_WIFI) {
973 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
974 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
977 rv = net_delete_profile(profile_info->ProfileName);
978 if (rv == NET_ERR_ACCESS_DENIED) {
979 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
980 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
981 } else if (rv != NET_ERR_NONE) {
982 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
983 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
986 return CONNECTION_ERROR_NONE;
989 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
992 net_profile_info_t *profile_info = profile;
994 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
996 if (!(__connection_check_handle_validity(connection)) ||
997 !(_connection_libnet_check_profile_validity(profile))) {
998 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
999 return CONNECTION_ERROR_INVALID_PARAMETER;
1002 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
1003 if (rv == NET_ERR_ACCESS_DENIED) {
1004 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1005 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1006 } else if (rv != NET_ERR_NONE) {
1007 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
1008 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1011 return CONNECTION_ERROR_NONE;
1014 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1015 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1017 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1019 if (!(__connection_check_handle_validity(connection)) ||
1020 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1021 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1022 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1023 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1024 return CONNECTION_ERROR_INVALID_PARAMETER;
1027 return _connection_libnet_get_profile_iterator(type, profile_iterator);
1030 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1031 connection_profile_h* profile)
1033 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1035 return _connection_libnet_get_iterator_next(profile_iterator, profile);
1038 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1040 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1042 return _connection_libnet_iterator_has_next(profile_iterator);
1045 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1047 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1049 return _connection_libnet_destroy_iterator(profile_iterator);
1052 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1054 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1056 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1057 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1058 return CONNECTION_ERROR_INVALID_PARAMETER;
1061 return _connection_libnet_get_current_profile(profile);
1064 EXPORT_API int connection_get_default_cellular_service_profile(
1065 connection_h connection, connection_cellular_service_type_e type,
1066 connection_profile_h *profile)
1068 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1070 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1071 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1072 return CONNECTION_ERROR_INVALID_PARAMETER;
1075 return _connection_libnet_get_cellular_service_profile(type, profile);
1078 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1079 connection_cellular_service_type_e type, connection_profile_h profile)
1081 CHECK_FEATURE_SUPPORTED(TELEPHONY_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_set_cellular_service_profile_sync(type, profile);
1091 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1092 connection_cellular_service_type_e type, connection_profile_h profile,
1093 connection_set_default_cb callback, void* user_data)
1095 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1097 if (!(__connection_check_handle_validity(connection)) ||
1098 profile == NULL || callback == NULL) {
1099 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1100 return CONNECTION_ERROR_INVALID_PARAMETER;
1103 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1106 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1107 connection_opened_cb callback, void* user_data)
1109 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1111 if (!(__connection_check_handle_validity(connection)) ||
1112 profile == NULL || callback == NULL) {
1113 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1114 return CONNECTION_ERROR_INVALID_PARAMETER;
1117 return _connection_libnet_open_profile(profile, callback, user_data);
1120 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1121 connection_closed_cb callback, void* user_data)
1123 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1125 if (!(__connection_check_handle_validity(connection)) ||
1126 profile == NULL || callback == NULL) {
1127 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1128 return CONNECTION_ERROR_INVALID_PARAMETER;
1131 return _connection_libnet_close_profile(profile, callback, user_data);
1134 EXPORT_API int connection_reset_profile(connection_h connection,
1135 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1137 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1139 if (!(__connection_check_handle_validity(connection))) {
1140 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1141 return CONNECTION_ERROR_INVALID_PARAMETER;
1144 if (id < 0 || id > 1) {
1145 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1146 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1149 return _connection_libnet_reset_profile(type, id, callback, user_data);
1152 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1154 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1156 if (!(__connection_check_handle_validity(connection)) ||
1157 interface_name == NULL || host_address == NULL) {
1158 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1159 return CONNECTION_ERROR_INVALID_PARAMETER;
1162 return _connection_libnet_add_route(interface_name, host_address);
1165 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1167 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1169 if (!(__connection_check_handle_validity(connection)) ||
1170 interface_name == NULL || host_address == NULL) {
1171 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1172 return CONNECTION_ERROR_INVALID_PARAMETER;
1175 return _connection_libnet_remove_route(interface_name, host_address);
1178 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1180 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1182 if (!(__connection_check_handle_validity(connection)) ||
1183 interface_name == NULL || host_address == NULL) {
1184 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1185 return CONNECTION_ERROR_INVALID_PARAMETER;
1188 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1191 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1193 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1195 if (!(__connection_check_handle_validity(connection)) ||
1196 interface_name == NULL || host_address == NULL) {
1197 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1198 return CONNECTION_ERROR_INVALID_PARAMETER;
1201 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1204 EXPORT_API int connection_add_route_entry(connection_h connection,
1205 connection_address_family_e address_family, const char *interface_name,
1206 const char *host_address, const char *gateway)
1208 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1210 if (!(__connection_check_handle_validity(connection)) ||
1211 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1212 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1213 interface_name == NULL || host_address == NULL) {
1214 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1215 return CONNECTION_ERROR_INVALID_PARAMETER;
1218 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1219 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1220 interface_name, host_address, gateway);
1222 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1223 interface_name, host_address, gateway);
1225 return CONNECTION_ERROR_NONE;
1228 EXPORT_API int connection_remove_route_entry(connection_h connection,
1229 connection_address_family_e address_family, const char *interface_name,
1230 const char *host_address, const char *gateway)
1232 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1234 if (!(__connection_check_handle_validity(connection)) ||
1235 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1236 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1237 interface_name == NULL || host_address == NULL) {
1238 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1239 return CONNECTION_ERROR_INVALID_PARAMETER;
1242 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1243 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1244 interface_name, host_address, gateway);
1246 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1247 interface_name, host_address, gateway);
1249 return CONNECTION_ERROR_NONE;
1252 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1254 int rv = VCONF_OK, rv1 = VCONF_OK;
1255 int last_size = 0, size = 0;
1256 #if defined TIZEN_DUALSIM_ENABLE
1260 if (llsize == NULL) {
1261 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1262 return CONNECTION_ERROR_INVALID_PARAMETER;
1265 switch (statistics_type) {
1266 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1267 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1268 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1269 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1272 return CONNECTION_ERROR_INVALID_PARAMETER;
1275 #if defined TIZEN_DUALSIM_ENABLE
1276 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1277 if (rv != VCONF_OK) {
1278 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1280 return CONNECTION_ERROR_OPERATION_FAILED;
1286 switch (statistics_type) {
1287 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1288 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1290 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1291 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1293 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1294 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1295 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1297 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1298 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1299 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1302 #if defined TIZEN_DUALSIM_ENABLE
1305 switch (statistics_type) {
1306 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1307 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1309 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1310 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1312 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1313 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1314 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1316 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1317 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1318 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1324 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1325 return CONNECTION_ERROR_OPERATION_FAILED;
1329 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1330 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1331 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1334 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1335 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1337 return CONNECTION_ERROR_NONE;
1340 static int __get_statistic(connection_type_e connection_type,
1341 connection_statistics_type_e statistics_type, long long *llsize)
1344 unsigned long long ull_size;
1346 if (llsize == NULL) {
1347 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1348 return CONNECTION_ERROR_INVALID_PARAMETER;
1351 rv = _connection_libnet_check_get_privilege();
1352 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1354 else if (rv != CONNECTION_ERROR_NONE) {
1355 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1356 return CONNECTION_ERROR_OPERATION_FAILED;
1359 if (connection_type == CONNECTION_TYPE_CELLULAR)
1360 return __get_cellular_statistic(statistics_type, llsize);
1361 else if (connection_type == CONNECTION_TYPE_WIFI) {
1362 switch (statistics_type) {
1363 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1364 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1366 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1367 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1369 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1370 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1372 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1373 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1376 return CONNECTION_ERROR_INVALID_PARAMETER;
1379 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1380 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1382 else if (rv != CONNECTION_ERROR_NONE) {
1383 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1384 *llsize = 0; //LCOV_EXCL_LINE
1385 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1388 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1389 *llsize = (long long)ull_size;
1391 return CONNECTION_ERROR_INVALID_PARAMETER;
1393 return CONNECTION_ERROR_NONE;
1396 static int __reset_statistic(connection_type_e connection_type,
1397 connection_statistics_type_e statistics_type)
1403 if (connection_type == CONNECTION_TYPE_CELLULAR)
1404 conn_type = NET_DEVICE_CELLULAR;
1405 else if (connection_type == CONNECTION_TYPE_WIFI)
1406 conn_type = NET_DEVICE_WIFI;
1408 return CONNECTION_ERROR_INVALID_PARAMETER;
1410 switch (statistics_type) {
1411 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1412 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1414 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1415 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1417 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1418 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1420 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1421 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1424 return CONNECTION_ERROR_INVALID_PARAMETER;
1427 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1428 if (rv != CONNECTION_ERROR_NONE)
1431 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1433 return CONNECTION_ERROR_NONE;
1436 EXPORT_API int connection_get_statistics(connection_h connection,
1437 connection_type_e connection_type,
1438 connection_statistics_type_e statistics_type, long long* size)
1440 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1442 if (connection_type == CONNECTION_TYPE_CELLULAR)
1443 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1444 else if (connection_type == CONNECTION_TYPE_WIFI)
1445 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1447 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1448 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1449 return CONNECTION_ERROR_INVALID_PARAMETER;
1452 return __get_statistic(connection_type, statistics_type, size);
1455 EXPORT_API int connection_reset_statistics(connection_h connection,
1456 connection_type_e connection_type,
1457 connection_statistics_type_e statistics_type)
1459 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1461 if (connection_type == CONNECTION_TYPE_CELLULAR)
1462 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1463 else if (connection_type == CONNECTION_TYPE_WIFI)
1464 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1466 if (!__connection_check_handle_validity(connection)) {
1467 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1468 return CONNECTION_ERROR_INVALID_PARAMETER;
1471 return __reset_statistic(connection_type, statistics_type);
1474 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1475 connection_type_e connection_type, connection_ipv6_address_cb callback,
1478 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1479 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1481 GSList *ipv6_address_list = NULL;
1483 if (!(__connection_check_handle_validity(connection))) {
1484 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1485 return CONNECTION_ERROR_INVALID_PARAMETER;
1488 int rv = CONNECTION_ERROR_NONE;
1490 switch (connection_type) {
1491 case CONNECTION_TYPE_WIFI:
1492 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1493 &ipv6_address_list);
1495 case CONNECTION_TYPE_CELLULAR:
1496 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1497 &ipv6_address_list);
1499 case CONNECTION_TYPE_ETHERNET:
1500 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1501 &ipv6_address_list);
1503 case CONNECTION_TYPE_BT:
1504 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1505 &ipv6_address_list);
1508 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1509 return CONNECTION_ERROR_INVALID_PARAMETER;
1512 if (rv != NET_ERR_NONE) {
1513 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1514 " Failed = %d\n", rv);
1515 return CONNECTION_ERROR_OPERATION_FAILED;
1519 for (list = ipv6_address_list; list; list = list->next) {
1520 rv = callback((char *)list->data, user_data);
1525 g_slist_free_full(ipv6_address_list, g_free);
1526 ipv6_address_list = NULL;
1528 return CONNECTION_ERROR_NONE;
1531 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1535 if (!(__connection_check_handle_validity(connection))) {
1536 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1537 return CONNECTION_ERROR_INVALID_PARAMETER;
1540 ret = _connection_libnet_start_tcpdump();
1541 if (ret != CONNECTION_ERROR_NONE) {
1542 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
1546 return CONNECTION_ERROR_NONE;
1549 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1553 if (!(__connection_check_handle_validity(connection))) {
1554 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1555 return CONNECTION_ERROR_INVALID_PARAMETER;
1558 ret = _connection_libnet_stop_tcpdump();
1559 if (ret != CONNECTION_ERROR_NONE) {
1560 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
1564 return CONNECTION_ERROR_NONE;
1567 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1571 if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1572 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1573 return CONNECTION_ERROR_INVALID_PARAMETER;
1576 ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
1577 if (ret != CONNECTION_ERROR_NONE) {
1578 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
1582 return CONNECTION_ERROR_NONE;