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_MESH &&
973 profile_info->profile_type != NET_DEVICE_WIFI) {
974 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
975 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
978 rv = net_delete_profile(profile_info->ProfileName);
979 if (rv == NET_ERR_ACCESS_DENIED) {
980 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
981 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
982 } else if (rv != NET_ERR_NONE) {
983 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
984 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
987 return CONNECTION_ERROR_NONE;
990 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
993 net_profile_info_t *profile_info = profile;
995 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
997 if (!(__connection_check_handle_validity(connection)) ||
998 !(_connection_libnet_check_profile_validity(profile))) {
999 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1000 return CONNECTION_ERROR_INVALID_PARAMETER;
1003 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
1004 if (rv == NET_ERR_ACCESS_DENIED) {
1005 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1006 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1007 } else if (rv != NET_ERR_NONE) {
1008 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
1009 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1012 return CONNECTION_ERROR_NONE;
1015 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1016 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1018 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1020 if (!(__connection_check_handle_validity(connection)) ||
1021 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1022 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1023 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1024 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1025 return CONNECTION_ERROR_INVALID_PARAMETER;
1028 return _connection_libnet_get_profile_iterator(type, profile_iterator);
1031 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1032 connection_profile_h* profile)
1034 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1036 return _connection_libnet_get_iterator_next(profile_iterator, profile);
1039 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1041 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1043 return _connection_libnet_iterator_has_next(profile_iterator);
1046 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1048 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1050 return _connection_libnet_destroy_iterator(profile_iterator);
1053 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1055 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1057 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1058 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1059 return CONNECTION_ERROR_INVALID_PARAMETER;
1062 return _connection_libnet_get_current_profile(profile);
1065 EXPORT_API int connection_get_default_cellular_service_profile(
1066 connection_h connection, connection_cellular_service_type_e type,
1067 connection_profile_h *profile)
1069 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1071 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1072 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1073 return CONNECTION_ERROR_INVALID_PARAMETER;
1076 return _connection_libnet_get_cellular_service_profile(type, profile);
1079 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1080 connection_cellular_service_type_e type, connection_profile_h profile)
1082 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1084 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1085 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1086 return CONNECTION_ERROR_INVALID_PARAMETER;
1089 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1092 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1093 connection_cellular_service_type_e type, connection_profile_h profile,
1094 connection_set_default_cb callback, void* user_data)
1096 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1098 if (!(__connection_check_handle_validity(connection)) ||
1099 profile == NULL || callback == NULL) {
1100 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1101 return CONNECTION_ERROR_INVALID_PARAMETER;
1104 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1107 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1108 connection_opened_cb callback, void* user_data)
1110 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1112 if (!(__connection_check_handle_validity(connection)) ||
1113 profile == NULL || callback == NULL) {
1114 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1115 return CONNECTION_ERROR_INVALID_PARAMETER;
1118 return _connection_libnet_open_profile(profile, callback, user_data);
1121 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1122 connection_closed_cb callback, void* user_data)
1124 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1126 if (!(__connection_check_handle_validity(connection)) ||
1127 profile == NULL || callback == NULL) {
1128 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1129 return CONNECTION_ERROR_INVALID_PARAMETER;
1132 return _connection_libnet_close_profile(profile, callback, user_data);
1135 EXPORT_API int connection_reset_profile(connection_h connection,
1136 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1138 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1140 if (!(__connection_check_handle_validity(connection))) {
1141 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1142 return CONNECTION_ERROR_INVALID_PARAMETER;
1145 if (id < 0 || id > 1) {
1146 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1147 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1150 return _connection_libnet_reset_profile(type, id, callback, user_data);
1153 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1155 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1157 if (!(__connection_check_handle_validity(connection)) ||
1158 interface_name == NULL || host_address == NULL) {
1159 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1160 return CONNECTION_ERROR_INVALID_PARAMETER;
1163 return _connection_libnet_add_route(interface_name, host_address);
1166 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1168 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1170 if (!(__connection_check_handle_validity(connection)) ||
1171 interface_name == NULL || host_address == NULL) {
1172 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1173 return CONNECTION_ERROR_INVALID_PARAMETER;
1176 return _connection_libnet_remove_route(interface_name, host_address);
1179 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1181 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_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_ipv6(interface_name, host_address, gateway);
1192 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1194 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_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_ipv6(interface_name, host_address, gateway);
1205 EXPORT_API int connection_add_route_entry(connection_h connection,
1206 connection_address_family_e address_family, const char *interface_name,
1207 const char *host_address, const char *gateway)
1209 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1211 if (!(__connection_check_handle_validity(connection)) ||
1212 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1213 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1214 interface_name == NULL || host_address == NULL) {
1215 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1216 return CONNECTION_ERROR_INVALID_PARAMETER;
1219 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1220 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1221 interface_name, host_address, gateway);
1223 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1224 interface_name, host_address, gateway);
1226 return CONNECTION_ERROR_NONE;
1229 EXPORT_API int connection_remove_route_entry(connection_h connection,
1230 connection_address_family_e address_family, const char *interface_name,
1231 const char *host_address, const char *gateway)
1233 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1235 if (!(__connection_check_handle_validity(connection)) ||
1236 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1237 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1238 interface_name == NULL || host_address == NULL) {
1239 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1240 return CONNECTION_ERROR_INVALID_PARAMETER;
1243 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1244 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1245 interface_name, host_address, gateway);
1247 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1248 interface_name, host_address, gateway);
1250 return CONNECTION_ERROR_NONE;
1253 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1255 int rv = VCONF_OK, rv1 = VCONF_OK;
1256 int last_size = 0, size = 0;
1257 #if defined TIZEN_DUALSIM_ENABLE
1261 if (llsize == NULL) {
1262 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1263 return CONNECTION_ERROR_INVALID_PARAMETER;
1266 switch (statistics_type) {
1267 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1268 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1269 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1270 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1273 return CONNECTION_ERROR_INVALID_PARAMETER;
1276 #if defined TIZEN_DUALSIM_ENABLE
1277 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1278 if (rv != VCONF_OK) {
1279 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1281 return CONNECTION_ERROR_OPERATION_FAILED;
1287 switch (statistics_type) {
1288 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1289 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1291 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1292 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1294 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1295 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1296 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1298 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1299 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1300 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1303 #if defined TIZEN_DUALSIM_ENABLE
1306 switch (statistics_type) {
1307 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1308 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1310 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1311 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1313 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1314 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1315 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1317 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1318 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1319 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1325 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1326 return CONNECTION_ERROR_OPERATION_FAILED;
1330 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1331 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1332 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1335 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1336 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1338 return CONNECTION_ERROR_NONE;
1341 static int __get_statistic(connection_type_e connection_type,
1342 connection_statistics_type_e statistics_type, long long *llsize)
1345 unsigned long long ull_size;
1347 if (llsize == NULL) {
1348 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1349 return CONNECTION_ERROR_INVALID_PARAMETER;
1352 rv = _connection_libnet_check_get_privilege();
1353 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1355 else if (rv != CONNECTION_ERROR_NONE) {
1356 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1357 return CONNECTION_ERROR_OPERATION_FAILED;
1360 if (connection_type == CONNECTION_TYPE_CELLULAR)
1361 return __get_cellular_statistic(statistics_type, llsize);
1362 else if (connection_type == CONNECTION_TYPE_WIFI) {
1363 switch (statistics_type) {
1364 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1365 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1367 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1368 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1370 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1371 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1373 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1374 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1377 return CONNECTION_ERROR_INVALID_PARAMETER;
1380 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1381 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1383 else if (rv != CONNECTION_ERROR_NONE) {
1384 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1385 *llsize = 0; //LCOV_EXCL_LINE
1386 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1389 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1390 *llsize = (long long)ull_size;
1392 return CONNECTION_ERROR_INVALID_PARAMETER;
1394 return CONNECTION_ERROR_NONE;
1397 static int __reset_statistic(connection_type_e connection_type,
1398 connection_statistics_type_e statistics_type)
1404 if (connection_type == CONNECTION_TYPE_CELLULAR)
1405 conn_type = NET_DEVICE_CELLULAR;
1406 else if (connection_type == CONNECTION_TYPE_WIFI)
1407 conn_type = NET_DEVICE_WIFI;
1409 return CONNECTION_ERROR_INVALID_PARAMETER;
1411 switch (statistics_type) {
1412 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1413 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1415 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1416 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1418 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1419 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1421 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1422 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1425 return CONNECTION_ERROR_INVALID_PARAMETER;
1428 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1429 if (rv != CONNECTION_ERROR_NONE)
1432 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1434 return CONNECTION_ERROR_NONE;
1437 EXPORT_API int connection_get_statistics(connection_h connection,
1438 connection_type_e connection_type,
1439 connection_statistics_type_e statistics_type, long long* size)
1441 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1443 if (connection_type == CONNECTION_TYPE_CELLULAR)
1444 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1445 else if (connection_type == CONNECTION_TYPE_WIFI)
1446 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1448 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1449 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1450 return CONNECTION_ERROR_INVALID_PARAMETER;
1453 return __get_statistic(connection_type, statistics_type, size);
1456 EXPORT_API int connection_reset_statistics(connection_h connection,
1457 connection_type_e connection_type,
1458 connection_statistics_type_e statistics_type)
1460 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1462 if (connection_type == CONNECTION_TYPE_CELLULAR)
1463 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1464 else if (connection_type == CONNECTION_TYPE_WIFI)
1465 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1467 if (!__connection_check_handle_validity(connection)) {
1468 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1469 return CONNECTION_ERROR_INVALID_PARAMETER;
1472 return __reset_statistic(connection_type, statistics_type);
1475 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1476 connection_type_e connection_type, connection_ipv6_address_cb callback,
1479 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1480 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1482 GSList *ipv6_address_list = NULL;
1484 if (!(__connection_check_handle_validity(connection))) {
1485 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1486 return CONNECTION_ERROR_INVALID_PARAMETER;
1489 int rv = CONNECTION_ERROR_NONE;
1491 switch (connection_type) {
1492 case CONNECTION_TYPE_WIFI:
1493 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1494 &ipv6_address_list);
1496 case CONNECTION_TYPE_CELLULAR:
1497 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1498 &ipv6_address_list);
1500 case CONNECTION_TYPE_ETHERNET:
1501 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1502 &ipv6_address_list);
1504 case CONNECTION_TYPE_BT:
1505 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1506 &ipv6_address_list);
1509 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1510 return CONNECTION_ERROR_INVALID_PARAMETER;
1513 if (rv != NET_ERR_NONE) {
1514 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1515 " Failed = %d\n", rv);
1516 return CONNECTION_ERROR_OPERATION_FAILED;
1520 for (list = ipv6_address_list; list; list = list->next) {
1521 rv = callback((char *)list->data, user_data);
1526 g_slist_free_full(ipv6_address_list, g_free);
1527 ipv6_address_list = NULL;
1529 return CONNECTION_ERROR_NONE;
1532 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1536 if (!(__connection_check_handle_validity(connection))) {
1537 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1538 return CONNECTION_ERROR_INVALID_PARAMETER;
1541 ret = _connection_libnet_start_tcpdump();
1542 if (ret != CONNECTION_ERROR_NONE) {
1543 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
1547 return CONNECTION_ERROR_NONE;
1550 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1554 if (!(__connection_check_handle_validity(connection))) {
1555 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1556 return CONNECTION_ERROR_INVALID_PARAMETER;
1559 ret = _connection_libnet_stop_tcpdump();
1560 if (ret != CONNECTION_ERROR_NONE) {
1561 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
1565 return CONNECTION_ERROR_NONE;
1568 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1572 if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1573 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1574 return CONNECTION_ERROR_INVALID_PARAMETER;
1577 ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
1578 if (ret != CONNECTION_ERROR_NONE) {
1579 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
1583 return CONNECTION_ERROR_NONE;