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 void __connection_cb_type_change_cb(int type)
94 connection_type_changed_cb callback;
97 if (_connection_is_created() != true) {
98 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
99 "If multi-threaded, thread integrity be broken.");
103 state = __connection_convert_net_state(type);
105 for (list = conn_handle_list; list; list = list->next) {
106 handle = (connection_h)list->data;
108 callback = __connection_get_type_changed_callback(handle);
109 data = __connection_get_type_changed_userdata(handle);
111 callback(state, data);
115 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
117 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
121 for (list = conn_handle_list; list; list = list->next) {
122 connection_handle_s *local_handle = (connection_handle_s *)list->data;
123 if (local_handle->ethernet_cable_state_changed_callback)
124 local_handle->ethernet_cable_state_changed_callback(state,
125 local_handle->ethernet_cable_state_changed_user_data);
129 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
134 for (list = conn_handle_list; list; list = list->next) {
135 connection_handle_s *local_handle = (connection_handle_s *)list->data;
136 if (local_handle->ethernet_cable_state_changed_callback) count++;
142 static int __connection_set_type_changed_callback(connection_h connection,
143 void *callback, void *user_data)
145 static __thread gint refcount = 0;
146 connection_handle_s *local_handle;
148 local_handle = (connection_handle_s *)connection;
152 _connection_libnet_set_type_changed_cb(
153 __connection_cb_type_change_cb);
156 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
160 __connection_get_type_changed_callback(local_handle) != NULL) {
161 if (--refcount == 0) {
162 _connection_libnet_set_type_changed_cb(NULL);
163 CONNECTION_LOG(CONNECTION_INFO,
164 "Successfully de-registered(%d)", refcount);
169 local_handle->type_changed_user_data = user_data;
170 local_handle->type_changed_callback = callback;
172 return CONNECTION_ERROR_NONE;
175 static connection_address_changed_cb
176 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
178 return local_handle->ip_changed_callback;
181 static void *__connection_get_ip_changed_userdata(
182 connection_handle_s *local_handle)
184 return local_handle->ip_changed_user_data;
187 static void __connection_cb_ip_change_cb(
188 connection_address_family_e addr_family, char *ip_addr)
192 char *ip4_addr = NULL;
193 char *ip6_addr = NULL;
195 connection_address_changed_cb callback;
197 if (_connection_is_created() != true) {
198 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
199 "If multi-threaded, thread integrity be broken.");
203 switch (addr_family) {
204 case CONNECTION_ADDRESS_FAMILY_IPV4:
205 ip4_addr = g_strdup(ip_addr);
207 ip6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
208 if (ip6_addr == NULL)
209 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
210 "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
212 case CONNECTION_ADDRESS_FAMILY_IPV6:
213 ip6_addr = g_strdup(ip_addr);
215 ip4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
216 if (ip4_addr == NULL)
217 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
218 "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
221 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Address Type");
225 for (list = conn_handle_list; list; list = list->next) {
226 handle = (connection_h)list->data;
228 callback = __connection_get_ip_changed_callback(handle);
229 data = __connection_get_ip_changed_userdata(handle);
232 callback(ip4_addr, ip6_addr, data);
239 static int __connection_set_ip_changed_callback(connection_h connection,
240 void *callback, void *user_data)
242 static __thread gint refcount = 0;
243 connection_handle_s *local_handle;
245 local_handle = (connection_handle_s *)connection;
249 _connection_libnet_set_ip_changed_cb(
250 __connection_cb_ip_change_cb);
253 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
257 __connection_get_ip_changed_callback(local_handle) != NULL) {
258 if (--refcount == 0) {
259 _connection_libnet_set_ip_changed_cb(NULL);
260 CONNECTION_LOG(CONNECTION_INFO,
261 "Successfully de-registered(%d)", refcount);
266 local_handle->ip_changed_user_data = user_data;
267 local_handle->ip_changed_callback = callback;
269 return CONNECTION_ERROR_NONE;
272 static connection_address_changed_cb
273 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
275 return local_handle->proxy_changed_callback;
278 static void *__connection_get_proxy_changed_userdata(
279 connection_handle_s *local_handle)
281 return local_handle->proxy_changed_user_data;
284 static void __connection_cb_proxy_change_cb(char *proxy_addr)
289 connection_address_changed_cb callback;
291 if (_connection_is_created() != true) {
292 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
293 "If multi-threaded, thread integrity be broken.");
297 for (list = conn_handle_list; list; list = list->next) {
298 handle = (connection_h)list->data;
300 callback = __connection_get_proxy_changed_callback(handle);
301 data = __connection_get_proxy_changed_userdata(handle);
302 /* TODO: IPv6 should be supported */
304 callback(proxy_addr, NULL, data);
308 static int __connection_set_proxy_changed_callback(connection_h connection,
309 void *callback, void *user_data)
311 static __thread gint refcount = 0;
312 connection_handle_s *local_handle;
314 local_handle = (connection_handle_s *)connection;
318 _connection_libnet_set_proxy_changed_cb(
319 __connection_cb_proxy_change_cb);
322 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)",
326 __connection_get_proxy_changed_callback(local_handle) != NULL) {
327 if (--refcount == 0) {
328 _connection_libnet_set_proxy_changed_cb(NULL);
329 CONNECTION_LOG(CONNECTION_INFO,
330 "Successfully de-registered(%d)", refcount);
335 local_handle->proxy_changed_user_data = user_data;
336 local_handle->proxy_changed_callback = callback;
338 return CONNECTION_ERROR_NONE;
341 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
342 connection_ethernet_cable_state_changed_cb callback, void *user_data)
344 connection_handle_s *local_handle = (connection_handle_s *)connection;
347 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
348 _connection_libnet_set_ethernet_cable_state_changed_cb(
349 __connection_cb_ethernet_cable_state_changed_cb);
352 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1 &&
353 local_handle->ethernet_cable_state_changed_callback)
354 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
357 local_handle->ethernet_cable_state_changed_callback = callback;
358 local_handle->ethernet_cable_state_changed_user_data = user_data;
359 return CONNECTION_ERROR_NONE;
363 static int __connection_get_handle_count(void)
365 return ((int)g_slist_length(conn_handle_list));
368 /* Connection Manager ********************************************************/
369 EXPORT_API int connection_create(connection_h *connection)
371 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
373 if (connection == NULL || __connection_check_handle_validity(*connection)) {
374 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
375 return CONNECTION_ERROR_INVALID_PARAMETER;
378 int rv = _connection_libnet_init();
379 if (rv == NET_ERR_ACCESS_DENIED) {
380 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
381 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
382 } else if (rv != NET_ERR_NONE) {
383 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
384 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
387 *connection = g_try_malloc0(sizeof(connection_handle_s));
388 if (*connection != NULL)
389 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
391 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
393 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
395 return CONNECTION_ERROR_NONE;
398 EXPORT_API int connection_destroy(connection_h connection)
400 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
402 if (!(__connection_check_handle_validity(connection))) {
403 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
404 return CONNECTION_ERROR_INVALID_PARAMETER;
407 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
409 __connection_set_type_changed_callback(connection, NULL, NULL);
410 __connection_set_ip_changed_callback(connection, NULL, NULL);
411 __connection_set_proxy_changed_callback(connection, NULL, NULL);
412 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
414 conn_handle_list = g_slist_remove(conn_handle_list, connection);
419 if (__connection_get_handle_count() == 0) {
420 _connection_libnet_deinit();
421 _connection_callback_cleanup();
424 return CONNECTION_ERROR_NONE;
427 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
432 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
434 if (type == NULL || !(__connection_check_handle_validity(connection))) {
435 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
436 return CONNECTION_ERROR_INVALID_PARAMETER;
439 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
440 if (rv != VCONF_OK) {
441 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
442 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
445 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
447 *type = __connection_convert_net_state(status);
449 return CONNECTION_ERROR_NONE;
452 EXPORT_API int connection_get_ip_address(connection_h connection,
453 connection_address_family_e address_family, char** ip_address)
455 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
457 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
458 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
459 return CONNECTION_ERROR_INVALID_PARAMETER;
462 switch (address_family) {
463 case CONNECTION_ADDRESS_FAMILY_IPV4:
464 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
466 case CONNECTION_ADDRESS_FAMILY_IPV6:
467 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
470 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
471 return CONNECTION_ERROR_INVALID_PARAMETER;
474 if (*ip_address == NULL) {
475 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
476 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
479 return CONNECTION_ERROR_NONE;
482 EXPORT_API int connection_get_proxy(connection_h connection,
483 connection_address_family_e address_family, char** proxy)
485 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
487 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
488 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
489 return CONNECTION_ERROR_INVALID_PARAMETER;
492 switch (address_family) {
493 case CONNECTION_ADDRESS_FAMILY_IPV4:
494 case CONNECTION_ADDRESS_FAMILY_IPV6:
495 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
498 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
499 return CONNECTION_ERROR_INVALID_PARAMETER;
502 if (*proxy == NULL) {
503 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
504 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
507 return CONNECTION_ERROR_NONE;
510 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
513 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
515 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
517 if (type == CONNECTION_TYPE_WIFI)
518 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
519 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
520 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
522 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
523 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
524 return CONNECTION_ERROR_INVALID_PARAMETER;
528 case CONNECTION_TYPE_WIFI:
529 if (__builtin_expect(tv_profile == -1, 0)) {
531 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
532 if (*profileName == 't' || *profileName == 'T')
538 if (tv_profile == 1) {
539 fp = fopen(WIFI_MAC_INFO_FILE, "r");
541 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
542 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
545 if (fgets(buf, sizeof(buf), fp) == NULL) {
546 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
547 fclose(fp); //LCOV_EXCL_LINE
548 return CONNECTION_ERROR_OPERATION_FAILED;
551 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
553 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
554 if (*mac_addr == NULL) {
555 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
556 fclose(fp); //LCOV_EXCL_LINE
557 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
559 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
562 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
564 if (*mac_addr == NULL) {
565 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
566 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
571 case CONNECTION_TYPE_ETHERNET:
572 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
574 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
575 return CONNECTION_ERROR_OUT_OF_MEMORY;
578 if (fgets(buf, sizeof(buf), fp) == NULL) {
579 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
581 return CONNECTION_ERROR_OPERATION_FAILED;
584 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
586 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
587 if (*mac_addr == NULL) {
588 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
590 return CONNECTION_ERROR_OUT_OF_MEMORY;
593 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
599 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
600 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
603 /* Checking Invalid MAC Address */
604 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
605 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
606 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
607 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
610 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
612 return CONNECTION_ERROR_NONE;
616 EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
618 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
620 if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
621 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
622 return CONNECTION_ERROR_INVALID_PARAMETER;
625 int rv = _connection_libnet_get_metered_state(is_metered);
626 if (rv != CONNECTION_ERROR_NONE) {
627 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
628 return rv; //LCOV_EXCL_LINE
631 CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
632 return CONNECTION_ERROR_NONE;
636 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
640 int cellular_state = 0;
641 #if defined TIZEN_DUALSIM_ENABLE
645 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
647 if (state == NULL || !(__connection_check_handle_validity(connection))) {
648 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
649 return CONNECTION_ERROR_INVALID_PARAMETER;
652 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
653 if (rv != VCONF_OK) {
654 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
655 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
658 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
659 *state = __connection_convert_cellular_state(status);
661 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
662 #if defined TIZEN_DUALSIM_ENABLE
663 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
664 if (rv != VCONF_OK) {
665 CONNECTION_LOG(CONNECTION_ERROR,
666 "Failed to get default subscriber id", sim_id);
667 return CONNECTION_ERROR_OPERATION_FAILED;
671 case CONNECTION_CELLULAR_SUBSCRIBER_1:
673 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
674 #if defined TIZEN_DUALSIM_ENABLE
677 case CONNECTION_CELLULAR_SUBSCRIBER_2:
678 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
682 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
683 return CONNECTION_ERROR_OPERATION_FAILED;
686 if (rv != VCONF_OK) {
687 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
688 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
692 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
694 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
695 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
696 cellular_state == VCONFKEY_DNET_TRANSFER)
697 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
699 return CONNECTION_ERROR_NONE;
702 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
704 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
706 if (state == NULL || !(__connection_check_handle_validity(connection))) {
707 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
708 return CONNECTION_ERROR_INVALID_PARAMETER;
711 int rv = _connection_libnet_get_wifi_state(state);
712 if (rv != CONNECTION_ERROR_NONE) {
713 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
714 return rv; //LCOV_EXCL_LINE
717 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
719 return CONNECTION_ERROR_NONE;
723 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
725 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
727 if (state == NULL || !(__connection_check_handle_validity(connection))) {
728 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
729 return CONNECTION_ERROR_INVALID_PARAMETER;
732 return _connection_libnet_get_ethernet_state(state);
735 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
737 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
739 if (state == NULL || !(__connection_check_handle_validity(connection))) {
740 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
741 return CONNECTION_ERROR_INVALID_PARAMETER;
744 return _connection_libnet_get_ethernet_cable_state(state);
747 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
748 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
750 DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
751 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
753 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
754 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
755 return CONNECTION_ERROR_INVALID_PARAMETER;
758 DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
759 "connection_ethernet_cable_state_changed_cb");
761 return __connection_set_ethernet_cable_state_changed_cb(connection,
762 (connection_ethernet_cable_state_changed_cb)callback, user_data);
765 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
767 DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
768 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
770 if (!(__connection_check_handle_validity(connection))) {
771 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
772 return CONNECTION_ERROR_INVALID_PARAMETER;
775 return __connection_set_ethernet_cable_state_changed_cb(connection,
779 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
780 connection_ethernet_cable_state_changed_cb callback, void *user_data)
782 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
784 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
785 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
786 return CONNECTION_ERROR_INVALID_PARAMETER;
789 return __connection_set_ethernet_cable_state_changed_cb(connection,
790 callback, user_data);
793 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
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,
807 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
809 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
811 if (state == NULL || !(__connection_check_handle_validity(connection))) {
812 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
813 return CONNECTION_ERROR_INVALID_PARAMETER;
816 return _connection_libnet_get_bluetooth_state(state);
819 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
820 connection_type_changed_cb callback, void* user_data)
822 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
824 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
825 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
826 return CONNECTION_ERROR_INVALID_PARAMETER;
829 return __connection_set_type_changed_callback(connection, callback, user_data);
832 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
834 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
836 if (!(__connection_check_handle_validity(connection))) {
837 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
838 return CONNECTION_ERROR_INVALID_PARAMETER;
841 return __connection_set_type_changed_callback(connection, NULL, NULL);
844 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
845 connection_address_changed_cb callback, void* user_data)
847 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
849 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
850 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
851 return CONNECTION_ERROR_INVALID_PARAMETER;
854 return __connection_set_ip_changed_callback(connection, callback, user_data);
857 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
859 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
861 if (!(__connection_check_handle_validity(connection))) {
862 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
863 return CONNECTION_ERROR_INVALID_PARAMETER;
866 return __connection_set_ip_changed_callback(connection, NULL, NULL);
869 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
870 connection_address_changed_cb callback, void* user_data)
872 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
874 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
875 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
876 return CONNECTION_ERROR_INVALID_PARAMETER;
879 return __connection_set_proxy_changed_callback(connection, callback, user_data);
882 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
884 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
886 if (!(__connection_check_handle_validity(connection))) {
887 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
888 return CONNECTION_ERROR_INVALID_PARAMETER;
891 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
894 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
897 net_profile_info_t *profile_info = profile;
899 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
901 if (!(__connection_check_handle_validity(connection)) ||
902 !(_connection_libnet_check_profile_validity(profile))) {
903 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
904 return CONNECTION_ERROR_INVALID_PARAMETER;
907 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
908 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
909 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
912 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
913 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
914 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
915 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
918 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
919 (net_profile_info_t*)profile);
920 if (rv == NET_ERR_ACCESS_DENIED) {
921 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
922 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
923 } else if (rv != NET_ERR_NONE) {
924 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
925 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
928 return CONNECTION_ERROR_NONE;
931 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
934 net_profile_info_t *profile_info = profile;
936 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
938 if (!(__connection_check_handle_validity(connection)) ||
939 !(_connection_libnet_check_profile_validity(profile))) {
940 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
941 return CONNECTION_ERROR_INVALID_PARAMETER;
944 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
945 profile_info->profile_type != NET_DEVICE_WIFI) {
946 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
947 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
950 rv = net_delete_profile(profile_info->ProfileName);
951 if (rv == NET_ERR_ACCESS_DENIED) {
952 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
953 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
954 } else if (rv != NET_ERR_NONE) {
955 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
956 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
959 return CONNECTION_ERROR_NONE;
962 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
965 net_profile_info_t *profile_info = profile;
967 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
969 if (!(__connection_check_handle_validity(connection)) ||
970 !(_connection_libnet_check_profile_validity(profile))) {
971 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
972 return CONNECTION_ERROR_INVALID_PARAMETER;
975 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
976 if (rv == NET_ERR_ACCESS_DENIED) {
977 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
978 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
979 } else if (rv != NET_ERR_NONE) {
980 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
981 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
984 return CONNECTION_ERROR_NONE;
987 EXPORT_API int connection_get_profile_iterator(connection_h connection,
988 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
990 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
992 if (!(__connection_check_handle_validity(connection)) ||
993 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
994 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
995 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
996 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
997 return CONNECTION_ERROR_INVALID_PARAMETER;
1000 return _connection_libnet_get_profile_iterator(type, profile_iterator);
1003 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1004 connection_profile_h* profile)
1006 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1008 return _connection_libnet_get_iterator_next(profile_iterator, profile);
1011 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1013 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1015 return _connection_libnet_iterator_has_next(profile_iterator);
1018 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1020 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1022 return _connection_libnet_destroy_iterator(profile_iterator);
1025 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1027 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1029 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1030 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1031 return CONNECTION_ERROR_INVALID_PARAMETER;
1034 return _connection_libnet_get_current_profile(profile);
1037 EXPORT_API int connection_get_default_cellular_service_profile(
1038 connection_h connection, connection_cellular_service_type_e type,
1039 connection_profile_h *profile)
1041 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1043 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1044 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1045 return CONNECTION_ERROR_INVALID_PARAMETER;
1048 return _connection_libnet_get_cellular_service_profile(type, profile);
1051 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1052 connection_cellular_service_type_e type, connection_profile_h profile)
1054 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1056 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1057 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1058 return CONNECTION_ERROR_INVALID_PARAMETER;
1061 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1064 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1065 connection_cellular_service_type_e type, connection_profile_h profile,
1066 connection_set_default_cb callback, void* user_data)
1068 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1070 if (!(__connection_check_handle_validity(connection)) ||
1071 profile == NULL || callback == NULL) {
1072 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1073 return CONNECTION_ERROR_INVALID_PARAMETER;
1076 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1079 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1080 connection_opened_cb callback, void* user_data)
1082 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1084 if (!(__connection_check_handle_validity(connection)) ||
1085 profile == NULL || callback == NULL) {
1086 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1087 return CONNECTION_ERROR_INVALID_PARAMETER;
1090 return _connection_libnet_open_profile(profile, callback, user_data);
1093 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1094 connection_closed_cb callback, void* user_data)
1096 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_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_close_profile(profile, callback, user_data);
1107 EXPORT_API int connection_reset_profile(connection_h connection,
1108 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1110 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1112 if (!(__connection_check_handle_validity(connection))) {
1113 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1114 return CONNECTION_ERROR_INVALID_PARAMETER;
1117 if (id < 0 || id > 1) {
1118 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1119 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1122 return _connection_libnet_reset_profile(type, id, callback, user_data);
1125 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1127 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1129 if (!(__connection_check_handle_validity(connection)) ||
1130 interface_name == NULL || host_address == NULL) {
1131 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1132 return CONNECTION_ERROR_INVALID_PARAMETER;
1135 return _connection_libnet_add_route(interface_name, host_address);
1138 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1140 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1142 if (!(__connection_check_handle_validity(connection)) ||
1143 interface_name == NULL || host_address == NULL) {
1144 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1145 return CONNECTION_ERROR_INVALID_PARAMETER;
1148 return _connection_libnet_remove_route(interface_name, host_address);
1151 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1153 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1155 if (!(__connection_check_handle_validity(connection)) ||
1156 interface_name == NULL || host_address == NULL) {
1157 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1158 return CONNECTION_ERROR_INVALID_PARAMETER;
1161 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1164 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1166 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1168 if (!(__connection_check_handle_validity(connection)) ||
1169 interface_name == NULL || host_address == NULL) {
1170 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1171 return CONNECTION_ERROR_INVALID_PARAMETER;
1174 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1177 EXPORT_API int connection_add_route_entry(connection_h connection,
1178 connection_address_family_e address_family, const char *interface_name,
1179 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 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1185 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1186 interface_name == NULL || host_address == NULL) {
1187 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1188 return CONNECTION_ERROR_INVALID_PARAMETER;
1191 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1192 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1193 interface_name, host_address, gateway);
1195 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1196 interface_name, host_address, gateway);
1198 return CONNECTION_ERROR_NONE;
1201 EXPORT_API int connection_remove_route_entry(connection_h connection,
1202 connection_address_family_e address_family, const char *interface_name,
1203 const char *host_address, const char *gateway)
1205 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1207 if (!(__connection_check_handle_validity(connection)) ||
1208 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1209 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1210 interface_name == NULL || host_address == NULL) {
1211 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1212 return CONNECTION_ERROR_INVALID_PARAMETER;
1215 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1216 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1217 interface_name, host_address, gateway);
1219 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1220 interface_name, host_address, gateway);
1222 return CONNECTION_ERROR_NONE;
1225 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1227 int rv = VCONF_OK, rv1 = VCONF_OK;
1228 int last_size = 0, size = 0;
1229 #if defined TIZEN_DUALSIM_ENABLE
1233 if (llsize == NULL) {
1234 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1235 return CONNECTION_ERROR_INVALID_PARAMETER;
1238 switch (statistics_type) {
1239 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1240 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1241 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1242 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1245 return CONNECTION_ERROR_INVALID_PARAMETER;
1248 #if defined TIZEN_DUALSIM_ENABLE
1249 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1250 if (rv != VCONF_OK) {
1251 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1253 return CONNECTION_ERROR_OPERATION_FAILED;
1259 switch (statistics_type) {
1260 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1261 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1263 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1264 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1266 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1267 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1268 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1270 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1271 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1272 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1275 #if defined TIZEN_DUALSIM_ENABLE
1278 switch (statistics_type) {
1279 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1280 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1282 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1283 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1285 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1286 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1287 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1289 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1290 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1291 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1297 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1298 return CONNECTION_ERROR_OPERATION_FAILED;
1302 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1303 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1304 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1307 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1308 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1310 return CONNECTION_ERROR_NONE;
1313 static int __get_statistic(connection_type_e connection_type,
1314 connection_statistics_type_e statistics_type, long long *llsize)
1317 unsigned long long ull_size;
1319 if (llsize == NULL) {
1320 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1321 return CONNECTION_ERROR_INVALID_PARAMETER;
1324 rv = _connection_libnet_check_get_privilege();
1325 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1327 else if (rv != CONNECTION_ERROR_NONE) {
1328 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1329 return CONNECTION_ERROR_OPERATION_FAILED;
1332 if (connection_type == CONNECTION_TYPE_CELLULAR)
1333 return __get_cellular_statistic(statistics_type, llsize);
1334 else if (connection_type == CONNECTION_TYPE_WIFI) {
1335 switch (statistics_type) {
1336 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1337 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1339 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1340 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1342 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1343 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1345 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1346 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1349 return CONNECTION_ERROR_INVALID_PARAMETER;
1352 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1353 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1355 else if (rv != CONNECTION_ERROR_NONE) {
1356 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1357 *llsize = 0; //LCOV_EXCL_LINE
1358 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1361 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1362 *llsize = (long long)ull_size;
1364 return CONNECTION_ERROR_INVALID_PARAMETER;
1366 return CONNECTION_ERROR_NONE;
1369 static int __reset_statistic(connection_type_e connection_type,
1370 connection_statistics_type_e statistics_type)
1376 if (connection_type == CONNECTION_TYPE_CELLULAR)
1377 conn_type = NET_DEVICE_CELLULAR;
1378 else if (connection_type == CONNECTION_TYPE_WIFI)
1379 conn_type = NET_DEVICE_WIFI;
1381 return CONNECTION_ERROR_INVALID_PARAMETER;
1383 switch (statistics_type) {
1384 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1385 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1387 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1388 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1390 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1391 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1393 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1394 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1397 return CONNECTION_ERROR_INVALID_PARAMETER;
1400 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1401 if (rv != CONNECTION_ERROR_NONE)
1404 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1406 return CONNECTION_ERROR_NONE;
1409 EXPORT_API int connection_get_statistics(connection_h connection,
1410 connection_type_e connection_type,
1411 connection_statistics_type_e statistics_type, long long* size)
1413 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1415 if (connection_type == CONNECTION_TYPE_CELLULAR)
1416 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1417 else if (connection_type == CONNECTION_TYPE_WIFI)
1418 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1420 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1421 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1422 return CONNECTION_ERROR_INVALID_PARAMETER;
1425 return __get_statistic(connection_type, statistics_type, size);
1428 EXPORT_API int connection_reset_statistics(connection_h connection,
1429 connection_type_e connection_type,
1430 connection_statistics_type_e statistics_type)
1432 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1434 if (connection_type == CONNECTION_TYPE_CELLULAR)
1435 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1436 else if (connection_type == CONNECTION_TYPE_WIFI)
1437 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1439 if (!__connection_check_handle_validity(connection)) {
1440 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1441 return CONNECTION_ERROR_INVALID_PARAMETER;
1444 return __reset_statistic(connection_type, statistics_type);
1447 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1448 connection_type_e connection_type, connection_ipv6_address_cb callback,
1451 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1452 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1454 GSList *ipv6_address_list = NULL;
1456 if (!(__connection_check_handle_validity(connection))) {
1457 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1458 return CONNECTION_ERROR_INVALID_PARAMETER;
1461 int rv = CONNECTION_ERROR_NONE;
1463 switch (connection_type) {
1464 case CONNECTION_TYPE_WIFI:
1465 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1466 &ipv6_address_list);
1468 case CONNECTION_TYPE_CELLULAR:
1469 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1470 &ipv6_address_list);
1472 case CONNECTION_TYPE_ETHERNET:
1473 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1474 &ipv6_address_list);
1476 case CONNECTION_TYPE_BT:
1477 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1478 &ipv6_address_list);
1481 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1482 return CONNECTION_ERROR_INVALID_PARAMETER;
1485 if (rv != NET_ERR_NONE) {
1486 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1487 " Failed = %d\n", rv);
1488 return CONNECTION_ERROR_OPERATION_FAILED;
1492 for (list = ipv6_address_list; list; list = list->next) {
1493 rv = callback((char *)list->data, user_data);
1498 g_slist_free_full(ipv6_address_list, g_free);
1499 ipv6_address_list = NULL;
1501 return CONNECTION_ERROR_NONE;
1504 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1508 if (!(__connection_check_handle_validity(connection))) {
1509 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1510 return CONNECTION_ERROR_INVALID_PARAMETER;
1513 ret = _connection_libnet_start_tcpdump();
1514 if (ret != CONNECTION_ERROR_NONE) {
1515 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
1519 return CONNECTION_ERROR_NONE;
1522 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1526 if (!(__connection_check_handle_validity(connection))) {
1527 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1528 return CONNECTION_ERROR_INVALID_PARAMETER;
1531 ret = _connection_libnet_stop_tcpdump();
1532 if (ret != CONNECTION_ERROR_NONE) {
1533 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
1537 return CONNECTION_ERROR_NONE;
1540 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1544 if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1545 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1546 return CONNECTION_ERROR_INVALID_PARAMETER;
1549 ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
1550 if (ret != CONNECTION_ERROR_NONE) {
1551 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
1555 return CONNECTION_ERROR_NONE;