2 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <vconf/vconf.h>
22 #include <system_info.h>
24 #include "net_connection_private.h"
26 static __thread GSList *conn_handle_list = NULL;
27 static int tv_profile = -1; // Unknown
30 static int __connection_convert_net_state(int status)
33 case VCONFKEY_NETWORK_CELLULAR:
34 return CONNECTION_TYPE_CELLULAR;
35 case VCONFKEY_NETWORK_WIFI:
36 return CONNECTION_TYPE_WIFI;
37 case VCONFKEY_NETWORK_ETHERNET:
38 return CONNECTION_TYPE_ETHERNET;
39 case VCONFKEY_NETWORK_BLUETOOTH:
40 return CONNECTION_TYPE_BT;
41 case VCONFKEY_NETWORK_DEFAULT_PROXY:
42 return CONNECTION_TYPE_NET_PROXY;
44 return CONNECTION_TYPE_DISCONNECTED;
48 static int __connection_convert_cellular_state(int status)
51 case VCONFKEY_NETWORK_CELLULAR_ON:
52 return CONNECTION_CELLULAR_STATE_AVAILABLE;
53 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
54 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
55 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
56 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
57 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
58 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
60 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
64 static bool __connection_check_handle_validity(connection_h connection)
68 if (connection == NULL)
71 if (g_slist_find(conn_handle_list, connection) != NULL)
77 static connection_type_changed_cb
78 __connection_get_type_changed_callback(connection_handle_s *local_handle)
80 return local_handle->type_changed_callback;
83 static void *__connection_get_type_changed_userdata(
84 connection_handle_s *local_handle)
86 return local_handle->type_changed_user_data;
89 static gboolean __connection_cb_type_changed_cb_idle(gpointer user_data)
93 connection_type_changed_cb callback;
94 connection_handle_s *local_handle = (connection_handle_s *)user_data;
96 if (__connection_check_handle_validity((connection_h)local_handle) != true)
99 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status) != 0)
102 state = __connection_convert_net_state(status);
104 callback = __connection_get_type_changed_callback(local_handle);
105 data = __connection_get_type_changed_userdata(local_handle);
107 callback(state, data);
112 static void __connection_cb_type_change_cb(keynode_t *node, void *user_data)
117 if (_connection_is_created() != true) {
118 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
119 "If multi-threaded, thread integrity be broken.");
123 for (list = conn_handle_list; list; list = list->next) {
124 handle = (connection_h)list->data;
125 _connection_callback_add(__connection_cb_type_changed_cb_idle, (gpointer)handle);
129 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
131 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
135 for (list = conn_handle_list; list; list = list->next) {
136 connection_handle_s *local_handle = (connection_handle_s *)list->data;
137 if (local_handle->ethernet_cable_state_changed_callback)
138 local_handle->ethernet_cable_state_changed_callback(state,
139 local_handle->ethernet_cable_state_changed_user_data);
143 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
148 for (list = conn_handle_list; list; list = list->next) {
149 connection_handle_s *local_handle = (connection_handle_s *)list->data;
150 if (local_handle->ethernet_cable_state_changed_callback) count++;
156 static int __connection_set_type_changed_callback(connection_h connection,
157 void *callback, void *user_data)
159 static __thread gint refcount = 0;
160 connection_handle_s *local_handle;
162 local_handle = (connection_handle_s *)connection;
166 vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS,
167 __connection_cb_type_change_cb, NULL);
170 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
173 __connection_get_type_changed_callback(local_handle) != NULL) {
174 if (--refcount == 0) {
175 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
176 __connection_cb_type_change_cb) < 0) {
177 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
178 "Error to de-register vconf callback(%d)", refcount);
180 CONNECTION_LOG(CONNECTION_INFO,
181 "Successfully de-registered(%d)", refcount);
187 local_handle->type_changed_user_data = user_data;
188 local_handle->type_changed_callback = callback;
190 return CONNECTION_ERROR_NONE;
193 static connection_address_changed_cb
194 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
196 return local_handle->ip_changed_callback;
199 static void *__connection_get_ip_changed_userdata(
200 connection_handle_s *local_handle)
202 return local_handle->ip_changed_user_data;
205 static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
210 connection_address_changed_cb callback;
211 connection_handle_s *local_handle = (connection_handle_s *)user_data;
213 if (__connection_check_handle_validity((connection_h)local_handle) != true)
216 ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
218 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
219 "vconf_get_str(VCONFKEY_NETWORK_IP) is Failed");
221 ip6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
222 if (ip6_addr == NULL)
223 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
224 "vconf_get_str(VCONFKEY_NETWORK_IP6) is Failed");
226 callback = __connection_get_ip_changed_callback(local_handle);
227 data = __connection_get_ip_changed_userdata(local_handle);
230 callback(ip_addr, ip6_addr, data);
238 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
243 if (_connection_is_created() != true) {
244 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
245 "If multi-threaded, thread integrity be broken.");
249 for (list = conn_handle_list; list; list = list->next) {
250 handle = (connection_h)list->data;
251 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
255 static int __connection_set_ip_changed_callback(connection_h connection,
256 void *callback, void *user_data)
258 static __thread gint refcount = 0;
259 connection_handle_s *local_handle;
261 local_handle = (connection_handle_s *)connection;
265 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
266 __connection_cb_ip_change_cb, NULL);
267 vconf_notify_key_changed(VCONFKEY_NETWORK_IP6,
268 __connection_cb_ip_change_cb, NULL);
272 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
275 __connection_get_ip_changed_callback(local_handle) != NULL) {
276 if (--refcount == 0) {
277 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
278 __connection_cb_ip_change_cb) < 0) {
279 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
280 "Error to de-register vconf callback(%d)", refcount);
282 CONNECTION_LOG(CONNECTION_INFO,
283 "Successfully de-registered(%d)", refcount);
285 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP6,
286 __connection_cb_ip_change_cb) < 0) {
287 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
288 "Error to de-register vconf callback(%d)", refcount);
290 CONNECTION_LOG(CONNECTION_INFO,
291 "Successfully de-registered(%d)", refcount);
297 local_handle->ip_changed_user_data = user_data;
298 local_handle->ip_changed_callback = callback;
300 return CONNECTION_ERROR_NONE;
303 static connection_address_changed_cb
304 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
306 return local_handle->proxy_changed_callback;
309 static void *__connection_get_proxy_changed_userdata(
310 connection_handle_s *local_handle)
312 return local_handle->proxy_changed_user_data;
315 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
319 connection_address_changed_cb callback;
320 connection_handle_s *local_handle = (connection_handle_s *)user_data;
322 if (__connection_check_handle_validity((connection_h)local_handle) != true)
325 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
327 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
328 "vconf_get_str(VCONFKEY_NETWORK_PROXY) is Failed");
330 callback = __connection_get_proxy_changed_callback(local_handle);
331 data = __connection_get_proxy_changed_userdata(local_handle);
332 /* TODO: IPv6 should be supported */
334 callback(proxy, NULL, data);
341 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
346 if (_connection_is_created() != true) {
347 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
348 "If multi-threaded, thread integrity be broken.");
352 for (list = conn_handle_list; list; list = list->next) {
353 handle = (connection_h)list->data;
354 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
358 static int __connection_set_proxy_changed_callback(connection_h connection,
359 void *callback, void *user_data)
361 static __thread gint refcount = 0;
362 connection_handle_s *local_handle;
364 local_handle = (connection_handle_s *)connection;
368 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
369 __connection_cb_proxy_change_cb, NULL);
372 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
375 __connection_get_proxy_changed_callback(local_handle) != NULL) {
376 if (--refcount == 0) {
377 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
378 __connection_cb_proxy_change_cb) < 0) {
379 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
380 "Error to de-register vconf callback(%d)", refcount);
382 CONNECTION_LOG(CONNECTION_INFO,
383 "Successfully de-registered(%d)", refcount);
389 local_handle->proxy_changed_user_data = user_data;
390 local_handle->proxy_changed_callback = callback;
392 return CONNECTION_ERROR_NONE;
395 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
396 connection_ethernet_cable_state_changed_cb callback, void *user_data)
398 connection_handle_s *local_handle = (connection_handle_s *)connection;
401 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
402 _connection_libnet_set_ethernet_cable_state_changed_cb(
403 __connection_cb_ethernet_cable_state_changed_cb);
406 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1 &&
407 local_handle->ethernet_cable_state_changed_callback)
408 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
411 local_handle->ethernet_cable_state_changed_callback = callback;
412 local_handle->ethernet_cable_state_changed_user_data = user_data;
413 return CONNECTION_ERROR_NONE;
417 static int __connection_get_handle_count(void)
419 return ((int)g_slist_length(conn_handle_list));
422 /* Connection Manager ********************************************************/
423 EXPORT_API int connection_create(connection_h *connection)
425 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
427 if (connection == NULL || __connection_check_handle_validity(*connection)) {
428 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
429 return CONNECTION_ERROR_INVALID_PARAMETER;
432 int rv = _connection_libnet_init();
433 if (rv == NET_ERR_ACCESS_DENIED) {
434 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
435 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
436 } else if (rv != NET_ERR_NONE) {
437 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
438 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
441 *connection = g_try_malloc0(sizeof(connection_handle_s));
442 if (*connection != NULL)
443 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
445 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
447 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
449 return CONNECTION_ERROR_NONE;
452 EXPORT_API int connection_destroy(connection_h connection)
454 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
456 if (!(__connection_check_handle_validity(connection))) {
457 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
458 return CONNECTION_ERROR_INVALID_PARAMETER;
461 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
463 __connection_set_type_changed_callback(connection, NULL, NULL);
464 __connection_set_ip_changed_callback(connection, NULL, NULL);
465 __connection_set_proxy_changed_callback(connection, NULL, NULL);
466 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
468 conn_handle_list = g_slist_remove(conn_handle_list, connection);
473 if (__connection_get_handle_count() == 0) {
474 _connection_libnet_deinit();
475 _connection_callback_cleanup();
478 return CONNECTION_ERROR_NONE;
481 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
486 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
488 if (type == NULL || !(__connection_check_handle_validity(connection))) {
489 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
490 return CONNECTION_ERROR_INVALID_PARAMETER;
493 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
494 if (rv != VCONF_OK) {
495 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
496 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
499 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
501 *type = __connection_convert_net_state(status);
503 return CONNECTION_ERROR_NONE;
506 EXPORT_API int connection_get_ip_address(connection_h connection,
507 connection_address_family_e address_family, char** ip_address)
509 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
511 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
512 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
513 return CONNECTION_ERROR_INVALID_PARAMETER;
516 switch (address_family) {
517 case CONNECTION_ADDRESS_FAMILY_IPV4:
518 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
520 case CONNECTION_ADDRESS_FAMILY_IPV6:
521 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
524 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
525 return CONNECTION_ERROR_INVALID_PARAMETER;
528 if (*ip_address == NULL) {
529 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
530 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
533 return CONNECTION_ERROR_NONE;
536 EXPORT_API int connection_get_proxy(connection_h connection,
537 connection_address_family_e address_family, char** proxy)
539 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
541 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
542 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
543 return CONNECTION_ERROR_INVALID_PARAMETER;
546 switch (address_family) {
547 case CONNECTION_ADDRESS_FAMILY_IPV4:
548 case CONNECTION_ADDRESS_FAMILY_IPV6:
549 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
552 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
553 return CONNECTION_ERROR_INVALID_PARAMETER;
556 if (*proxy == NULL) {
557 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
558 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
561 return CONNECTION_ERROR_NONE;
564 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
567 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
569 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
571 if (type == CONNECTION_TYPE_WIFI)
572 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
573 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
574 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
576 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
577 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
578 return CONNECTION_ERROR_INVALID_PARAMETER;
582 case CONNECTION_TYPE_WIFI:
583 if (__builtin_expect(tv_profile == -1, 0)) {
585 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
586 if (*profileName == 't' || *profileName == 'T')
592 if (tv_profile == 1) {
593 fp = fopen(WIFI_MAC_INFO_FILE, "r");
595 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
596 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
599 if (fgets(buf, sizeof(buf), fp) == NULL) {
600 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
601 fclose(fp); //LCOV_EXCL_LINE
602 return CONNECTION_ERROR_OPERATION_FAILED;
605 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
607 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
608 if (*mac_addr == NULL) {
609 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
610 fclose(fp); //LCOV_EXCL_LINE
611 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
613 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
616 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
618 if (*mac_addr == NULL) {
619 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
620 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
625 case CONNECTION_TYPE_ETHERNET:
626 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
628 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
629 return CONNECTION_ERROR_OUT_OF_MEMORY;
632 if (fgets(buf, sizeof(buf), fp) == NULL) {
633 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
635 return CONNECTION_ERROR_OPERATION_FAILED;
638 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
640 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
641 if (*mac_addr == NULL) {
642 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
644 return CONNECTION_ERROR_OUT_OF_MEMORY;
647 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
653 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
654 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
657 /* Checking Invalid MAC Address */
658 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
659 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
660 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
661 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
664 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
666 return CONNECTION_ERROR_NONE;
670 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
674 int cellular_state = 0;
675 #if defined TIZEN_DUALSIM_ENABLE
679 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
681 if (state == NULL || !(__connection_check_handle_validity(connection))) {
682 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
683 return CONNECTION_ERROR_INVALID_PARAMETER;
686 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
687 if (rv != VCONF_OK) {
688 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
689 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
692 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
693 *state = __connection_convert_cellular_state(status);
695 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
696 #if defined TIZEN_DUALSIM_ENABLE
697 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
698 if (rv != VCONF_OK) {
699 CONNECTION_LOG(CONNECTION_ERROR,
700 "Failed to get default subscriber id", sim_id);
701 return CONNECTION_ERROR_OPERATION_FAILED;
705 case CONNECTION_CELLULAR_SUBSCRIBER_1:
707 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
708 #if defined TIZEN_DUALSIM_ENABLE
711 case CONNECTION_CELLULAR_SUBSCRIBER_2:
712 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
716 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
717 return CONNECTION_ERROR_OPERATION_FAILED;
720 if (rv != VCONF_OK) {
721 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
722 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
726 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
728 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
729 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
730 cellular_state == VCONFKEY_DNET_TRANSFER)
731 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
733 return CONNECTION_ERROR_NONE;
736 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
738 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
740 if (state == NULL || !(__connection_check_handle_validity(connection))) {
741 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
742 return CONNECTION_ERROR_INVALID_PARAMETER;
745 int rv = _connection_libnet_get_wifi_state(state);
746 if (rv != CONNECTION_ERROR_NONE) {
747 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
748 return rv; //LCOV_EXCL_LINE
751 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
753 return CONNECTION_ERROR_NONE;
757 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
759 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
761 if (state == NULL || !(__connection_check_handle_validity(connection))) {
762 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
763 return CONNECTION_ERROR_INVALID_PARAMETER;
766 return _connection_libnet_get_ethernet_state(state);
769 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
771 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
773 if (state == NULL || !(__connection_check_handle_validity(connection))) {
774 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
775 return CONNECTION_ERROR_INVALID_PARAMETER;
778 return _connection_libnet_get_ethernet_cable_state(state);
781 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
782 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
784 DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
785 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
787 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
788 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
789 return CONNECTION_ERROR_INVALID_PARAMETER;
792 DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
793 "connection_ethernet_cable_state_changed_cb");
795 return __connection_set_ethernet_cable_state_changed_cb(connection,
796 (connection_ethernet_cable_state_changed_cb)callback, user_data);
799 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
801 DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
802 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
804 if (!(__connection_check_handle_validity(connection))) {
805 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
806 return CONNECTION_ERROR_INVALID_PARAMETER;
809 return __connection_set_ethernet_cable_state_changed_cb(connection,
813 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
814 connection_ethernet_cable_state_changed_cb callback, void *user_data)
816 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
818 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
819 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
820 return CONNECTION_ERROR_INVALID_PARAMETER;
823 return __connection_set_ethernet_cable_state_changed_cb(connection,
824 callback, user_data);
827 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
829 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
831 if (!(__connection_check_handle_validity(connection))) {
832 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
833 return CONNECTION_ERROR_INVALID_PARAMETER;
836 return __connection_set_ethernet_cable_state_changed_cb(connection,
841 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
843 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
845 if (state == NULL || !(__connection_check_handle_validity(connection))) {
846 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
847 return CONNECTION_ERROR_INVALID_PARAMETER;
850 return _connection_libnet_get_bluetooth_state(state);
853 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
854 connection_type_changed_cb callback, void* user_data)
856 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
858 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
859 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
860 return CONNECTION_ERROR_INVALID_PARAMETER;
863 return __connection_set_type_changed_callback(connection, callback, user_data);
866 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
868 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
870 if (!(__connection_check_handle_validity(connection))) {
871 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
872 return CONNECTION_ERROR_INVALID_PARAMETER;
875 return __connection_set_type_changed_callback(connection, NULL, NULL);
878 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
879 connection_address_changed_cb callback, void* user_data)
881 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
883 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
884 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
885 return CONNECTION_ERROR_INVALID_PARAMETER;
888 return __connection_set_ip_changed_callback(connection, callback, user_data);
891 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
893 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
895 if (!(__connection_check_handle_validity(connection))) {
896 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
897 return CONNECTION_ERROR_INVALID_PARAMETER;
900 return __connection_set_ip_changed_callback(connection, NULL, NULL);
903 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
904 connection_address_changed_cb callback, void* user_data)
906 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
908 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
909 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
910 return CONNECTION_ERROR_INVALID_PARAMETER;
913 return __connection_set_proxy_changed_callback(connection, callback, user_data);
916 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
918 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
920 if (!(__connection_check_handle_validity(connection))) {
921 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
922 return CONNECTION_ERROR_INVALID_PARAMETER;
925 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
928 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
931 net_profile_info_t *profile_info = profile;
933 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
935 if (!(__connection_check_handle_validity(connection)) ||
936 !(_connection_libnet_check_profile_validity(profile))) {
937 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
938 return CONNECTION_ERROR_INVALID_PARAMETER;
941 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
942 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
943 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
946 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
947 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
948 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
949 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
952 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
953 (net_profile_info_t*)profile);
954 if (rv == NET_ERR_ACCESS_DENIED) {
955 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
956 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
957 } else if (rv != NET_ERR_NONE) {
958 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
959 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
962 return CONNECTION_ERROR_NONE;
965 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
968 net_profile_info_t *profile_info = profile;
970 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
972 if (!(__connection_check_handle_validity(connection)) ||
973 !(_connection_libnet_check_profile_validity(profile))) {
974 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
975 return CONNECTION_ERROR_INVALID_PARAMETER;
978 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
979 profile_info->profile_type != NET_DEVICE_WIFI) {
980 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
981 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
984 rv = net_delete_profile(profile_info->ProfileName);
985 if (rv == NET_ERR_ACCESS_DENIED) {
986 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
987 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
988 } else if (rv != NET_ERR_NONE) {
989 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
990 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
993 return CONNECTION_ERROR_NONE;
996 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
999 net_profile_info_t *profile_info = profile;
1001 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1003 if (!(__connection_check_handle_validity(connection)) ||
1004 !(_connection_libnet_check_profile_validity(profile))) {
1005 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1006 return CONNECTION_ERROR_INVALID_PARAMETER;
1009 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
1010 if (rv == NET_ERR_ACCESS_DENIED) {
1011 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1012 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1013 } else if (rv != NET_ERR_NONE) {
1014 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
1015 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1018 return CONNECTION_ERROR_NONE;
1021 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1022 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1024 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1026 if (!(__connection_check_handle_validity(connection)) ||
1027 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1028 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1029 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1030 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1031 return CONNECTION_ERROR_INVALID_PARAMETER;
1034 return _connection_libnet_get_profile_iterator(type, profile_iterator);
1037 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1038 connection_profile_h* profile)
1040 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1042 return _connection_libnet_get_iterator_next(profile_iterator, profile);
1045 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1047 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1049 return _connection_libnet_iterator_has_next(profile_iterator);
1052 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1054 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1056 return _connection_libnet_destroy_iterator(profile_iterator);
1059 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1061 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1063 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1064 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1065 return CONNECTION_ERROR_INVALID_PARAMETER;
1068 return _connection_libnet_get_current_profile(profile);
1071 EXPORT_API int connection_get_default_cellular_service_profile(
1072 connection_h connection, connection_cellular_service_type_e type,
1073 connection_profile_h *profile)
1075 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1077 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1078 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1079 return CONNECTION_ERROR_INVALID_PARAMETER;
1082 return _connection_libnet_get_cellular_service_profile(type, profile);
1085 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1086 connection_cellular_service_type_e type, connection_profile_h profile)
1088 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1090 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1091 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1092 return CONNECTION_ERROR_INVALID_PARAMETER;
1095 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1098 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1099 connection_cellular_service_type_e type, connection_profile_h profile,
1100 connection_set_default_cb callback, void* user_data)
1102 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1104 if (!(__connection_check_handle_validity(connection)) ||
1105 profile == NULL || callback == NULL) {
1106 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1107 return CONNECTION_ERROR_INVALID_PARAMETER;
1110 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1113 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1114 connection_opened_cb callback, void* user_data)
1116 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1118 if (!(__connection_check_handle_validity(connection)) ||
1119 profile == NULL || callback == NULL) {
1120 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1121 return CONNECTION_ERROR_INVALID_PARAMETER;
1124 return _connection_libnet_open_profile(profile, callback, user_data);
1127 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1128 connection_closed_cb callback, void* user_data)
1130 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1132 if (!(__connection_check_handle_validity(connection)) ||
1133 profile == NULL || callback == NULL) {
1134 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1135 return CONNECTION_ERROR_INVALID_PARAMETER;
1138 return _connection_libnet_close_profile(profile, callback, user_data);
1141 EXPORT_API int connection_reset_profile(connection_h connection,
1142 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1144 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1146 if (!(__connection_check_handle_validity(connection))) {
1147 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1148 return CONNECTION_ERROR_INVALID_PARAMETER;
1151 if (id < 0 || id > 1) {
1152 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1153 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1156 return _connection_libnet_reset_profile(type, id, callback, user_data);
1159 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1161 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1163 if (!(__connection_check_handle_validity(connection)) ||
1164 interface_name == NULL || host_address == NULL) {
1165 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1166 return CONNECTION_ERROR_INVALID_PARAMETER;
1169 return _connection_libnet_add_route(interface_name, host_address);
1172 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1174 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1176 if (!(__connection_check_handle_validity(connection)) ||
1177 interface_name == NULL || host_address == NULL) {
1178 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1179 return CONNECTION_ERROR_INVALID_PARAMETER;
1182 return _connection_libnet_remove_route(interface_name, host_address);
1185 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1187 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1189 if (!(__connection_check_handle_validity(connection)) ||
1190 interface_name == NULL || host_address == NULL) {
1191 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1192 return CONNECTION_ERROR_INVALID_PARAMETER;
1195 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1198 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1200 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1202 if (!(__connection_check_handle_validity(connection)) ||
1203 interface_name == NULL || host_address == NULL) {
1204 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1205 return CONNECTION_ERROR_INVALID_PARAMETER;
1208 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1211 EXPORT_API int connection_add_route_entry(connection_h connection,
1212 connection_address_family_e address_family, const char *interface_name,
1213 const char *host_address, const char *gateway)
1215 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1217 if (!(__connection_check_handle_validity(connection)) ||
1218 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1219 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1220 interface_name == NULL || host_address == NULL) {
1221 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1222 return CONNECTION_ERROR_INVALID_PARAMETER;
1225 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1226 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1227 interface_name, host_address, gateway);
1229 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1230 interface_name, host_address, gateway);
1232 return CONNECTION_ERROR_NONE;
1235 EXPORT_API int connection_remove_route_entry(connection_h connection,
1236 connection_address_family_e address_family, const char *interface_name,
1237 const char *host_address, const char *gateway)
1239 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1241 if (!(__connection_check_handle_validity(connection)) ||
1242 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1243 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1244 interface_name == NULL || host_address == NULL) {
1245 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1246 return CONNECTION_ERROR_INVALID_PARAMETER;
1249 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1250 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1251 interface_name, host_address, gateway);
1253 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1254 interface_name, host_address, gateway);
1256 return CONNECTION_ERROR_NONE;
1259 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1261 int rv = VCONF_OK, rv1 = VCONF_OK;
1262 int last_size = 0, size = 0;
1263 #if defined TIZEN_DUALSIM_ENABLE
1267 if (llsize == NULL) {
1268 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1269 return CONNECTION_ERROR_INVALID_PARAMETER;
1272 switch (statistics_type) {
1273 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1274 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1275 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1276 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1279 return CONNECTION_ERROR_INVALID_PARAMETER;
1282 #if defined TIZEN_DUALSIM_ENABLE
1283 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1284 if (rv != VCONF_OK) {
1285 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1287 return CONNECTION_ERROR_OPERATION_FAILED;
1293 switch (statistics_type) {
1294 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1295 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1297 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1298 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1300 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1301 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1302 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1304 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1305 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1306 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1309 #if defined TIZEN_DUALSIM_ENABLE
1312 switch (statistics_type) {
1313 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1314 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1316 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1317 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1319 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1320 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1321 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1323 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1324 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1325 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1331 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1332 return CONNECTION_ERROR_OPERATION_FAILED;
1336 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1337 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1338 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1341 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1342 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1344 return CONNECTION_ERROR_NONE;
1347 static int __get_statistic(connection_type_e connection_type,
1348 connection_statistics_type_e statistics_type, long long *llsize)
1351 unsigned long long ull_size;
1353 if (llsize == NULL) {
1354 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1355 return CONNECTION_ERROR_INVALID_PARAMETER;
1358 rv = _connection_libnet_check_get_privilege();
1359 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1361 else if (rv != CONNECTION_ERROR_NONE) {
1362 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1363 return CONNECTION_ERROR_OPERATION_FAILED;
1366 if (connection_type == CONNECTION_TYPE_CELLULAR)
1367 return __get_cellular_statistic(statistics_type, llsize);
1368 else if (connection_type == CONNECTION_TYPE_WIFI) {
1369 switch (statistics_type) {
1370 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1371 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1373 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1374 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1376 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1377 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1379 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1380 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1383 return CONNECTION_ERROR_INVALID_PARAMETER;
1386 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1387 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1389 else if (rv != CONNECTION_ERROR_NONE) {
1390 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1391 *llsize = 0; //LCOV_EXCL_LINE
1392 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1395 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1396 *llsize = (long long)ull_size;
1398 return CONNECTION_ERROR_INVALID_PARAMETER;
1400 return CONNECTION_ERROR_NONE;
1403 static int __reset_statistic(connection_type_e connection_type,
1404 connection_statistics_type_e statistics_type)
1410 if (connection_type == CONNECTION_TYPE_CELLULAR)
1411 conn_type = NET_DEVICE_CELLULAR;
1412 else if (connection_type == CONNECTION_TYPE_WIFI)
1413 conn_type = NET_DEVICE_WIFI;
1415 return CONNECTION_ERROR_INVALID_PARAMETER;
1417 switch (statistics_type) {
1418 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1419 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1421 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1422 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1424 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1425 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1427 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1428 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1431 return CONNECTION_ERROR_INVALID_PARAMETER;
1434 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1435 if (rv != CONNECTION_ERROR_NONE)
1438 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1440 return CONNECTION_ERROR_NONE;
1443 EXPORT_API int connection_get_statistics(connection_h connection,
1444 connection_type_e connection_type,
1445 connection_statistics_type_e statistics_type, long long* size)
1447 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1449 if (connection_type == CONNECTION_TYPE_CELLULAR)
1450 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1451 else if (connection_type == CONNECTION_TYPE_WIFI)
1452 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1454 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1455 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1456 return CONNECTION_ERROR_INVALID_PARAMETER;
1459 return __get_statistic(connection_type, statistics_type, size);
1462 EXPORT_API int connection_reset_statistics(connection_h connection,
1463 connection_type_e connection_type,
1464 connection_statistics_type_e statistics_type)
1466 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1468 if (connection_type == CONNECTION_TYPE_CELLULAR)
1469 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1470 else if (connection_type == CONNECTION_TYPE_WIFI)
1471 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1473 if (!__connection_check_handle_validity(connection)) {
1474 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1475 return CONNECTION_ERROR_INVALID_PARAMETER;
1478 return __reset_statistic(connection_type, statistics_type);
1481 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1482 connection_type_e connection_type, connection_ipv6_address_cb callback,
1485 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1486 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1488 GSList *ipv6_address_list = NULL;
1490 if (!(__connection_check_handle_validity(connection))) {
1491 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1492 return CONNECTION_ERROR_INVALID_PARAMETER;
1495 int rv = CONNECTION_ERROR_NONE;
1497 switch (connection_type) {
1498 case CONNECTION_TYPE_WIFI:
1499 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1500 &ipv6_address_list);
1502 case CONNECTION_TYPE_CELLULAR:
1503 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1504 &ipv6_address_list);
1506 case CONNECTION_TYPE_ETHERNET:
1507 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1508 &ipv6_address_list);
1510 case CONNECTION_TYPE_BT:
1511 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1512 &ipv6_address_list);
1515 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1516 return CONNECTION_ERROR_INVALID_PARAMETER;
1519 if (rv != NET_ERR_NONE) {
1520 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1521 " Failed = %d\n", rv);
1522 return CONNECTION_ERROR_OPERATION_FAILED;
1526 for (list = ipv6_address_list; list; list = list->next) {
1527 rv = callback((char *)list->data, user_data);
1532 g_slist_free_full(ipv6_address_list, g_free);
1533 ipv6_address_list = NULL;
1535 return CONNECTION_ERROR_NONE;