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_create_cs(int tid, connection_h *connection)
431 rv = connection_create(connection);
433 if (rv == CONNECTION_ERROR_NONE)
434 _connection_set_cs_tid(tid);
439 EXPORT_API int connection_destroy_cs(int tid, connection_h connection)
443 _connection_unset_cs_tid(tid);
444 rv = connection_destroy(connection);
449 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
454 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
456 if (type == NULL || !(__connection_check_handle_validity(connection))) {
457 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
458 return CONNECTION_ERROR_INVALID_PARAMETER;
461 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
462 if (rv != VCONF_OK) {
463 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
464 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
467 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
469 *type = __connection_convert_net_state(status);
471 return CONNECTION_ERROR_NONE;
474 EXPORT_API int connection_get_ip_address(connection_h connection,
475 connection_address_family_e address_family, char** ip_address)
477 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
479 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
480 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
481 return CONNECTION_ERROR_INVALID_PARAMETER;
484 switch (address_family) {
485 case CONNECTION_ADDRESS_FAMILY_IPV4:
486 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
488 case CONNECTION_ADDRESS_FAMILY_IPV6:
489 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
492 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
493 return CONNECTION_ERROR_INVALID_PARAMETER;
496 if (*ip_address == NULL) {
497 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
498 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
501 return CONNECTION_ERROR_NONE;
504 EXPORT_API int connection_get_proxy(connection_h connection,
505 connection_address_family_e address_family, char** proxy)
507 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
509 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
510 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
511 return CONNECTION_ERROR_INVALID_PARAMETER;
514 switch (address_family) {
515 case CONNECTION_ADDRESS_FAMILY_IPV4:
516 case CONNECTION_ADDRESS_FAMILY_IPV6:
517 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
520 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
521 return CONNECTION_ERROR_INVALID_PARAMETER;
524 if (*proxy == NULL) {
525 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
526 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
529 return CONNECTION_ERROR_NONE;
532 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
535 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
537 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
539 if (type == CONNECTION_TYPE_WIFI)
540 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
541 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
542 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
544 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
545 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
546 return CONNECTION_ERROR_INVALID_PARAMETER;
550 case CONNECTION_TYPE_WIFI:
551 if (__builtin_expect(tv_profile == -1, 0)) {
553 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
554 if (*profileName == 't' || *profileName == 'T')
560 if (tv_profile == 1) {
561 fp = fopen(WIFI_MAC_INFO_FILE, "r");
563 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
564 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
567 if (fgets(buf, sizeof(buf), fp) == NULL) {
568 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); //LCOV_EXCL_LINE
569 fclose(fp); //LCOV_EXCL_LINE
570 return CONNECTION_ERROR_OPERATION_FAILED;
573 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
575 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
576 if (*mac_addr == NULL) {
577 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); //LCOV_EXCL_LINE
578 fclose(fp); //LCOV_EXCL_LINE
579 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
581 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
584 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
586 if (*mac_addr == NULL) {
587 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
588 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
593 case CONNECTION_TYPE_ETHERNET:
594 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
596 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
597 return CONNECTION_ERROR_OUT_OF_MEMORY;
600 if (fgets(buf, sizeof(buf), fp) == NULL) {
601 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
603 return CONNECTION_ERROR_OPERATION_FAILED;
606 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
608 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
609 if (*mac_addr == NULL) {
610 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
612 return CONNECTION_ERROR_OUT_OF_MEMORY;
615 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
621 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
622 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
625 /* Checking Invalid MAC Address */
626 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
627 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
628 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
629 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
632 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
634 return CONNECTION_ERROR_NONE;
638 EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
640 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
642 if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
643 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
644 return CONNECTION_ERROR_INVALID_PARAMETER;
647 int rv = _connection_libnet_get_metered_state(is_metered);
648 if (rv != CONNECTION_ERROR_NONE) {
649 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
650 return rv; //LCOV_EXCL_LINE
653 CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
654 return CONNECTION_ERROR_NONE;
658 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
662 int cellular_state = 0;
663 #if defined TIZEN_DUALSIM_ENABLE
667 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
669 if (state == NULL || !(__connection_check_handle_validity(connection))) {
670 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
671 return CONNECTION_ERROR_INVALID_PARAMETER;
674 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
675 if (rv != VCONF_OK) {
676 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
677 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
680 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
681 *state = __connection_convert_cellular_state(status);
683 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
684 #if defined TIZEN_DUALSIM_ENABLE
685 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
686 if (rv != VCONF_OK) {
687 CONNECTION_LOG(CONNECTION_ERROR,
688 "Failed to get default subscriber id", sim_id);
689 return CONNECTION_ERROR_OPERATION_FAILED;
693 case CONNECTION_CELLULAR_SUBSCRIBER_1:
695 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
696 #if defined TIZEN_DUALSIM_ENABLE
699 case CONNECTION_CELLULAR_SUBSCRIBER_2:
700 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
704 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
705 return CONNECTION_ERROR_OPERATION_FAILED;
708 if (rv != VCONF_OK) {
709 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
710 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
714 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
716 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
717 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
718 cellular_state == VCONFKEY_DNET_TRANSFER)
719 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
721 return CONNECTION_ERROR_NONE;
724 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
726 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
728 if (state == NULL || !(__connection_check_handle_validity(connection))) {
729 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
730 return CONNECTION_ERROR_INVALID_PARAMETER;
733 int rv = _connection_libnet_get_wifi_state(state);
734 if (rv != CONNECTION_ERROR_NONE) {
735 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
736 return rv; //LCOV_EXCL_LINE
739 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
741 return CONNECTION_ERROR_NONE;
745 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
747 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
749 if (state == NULL || !(__connection_check_handle_validity(connection))) {
750 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
751 return CONNECTION_ERROR_INVALID_PARAMETER;
754 return _connection_libnet_get_ethernet_state(state);
757 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_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_cable_state(state);
769 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
770 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
772 DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
773 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
775 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
776 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
777 return CONNECTION_ERROR_INVALID_PARAMETER;
780 DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
781 "connection_ethernet_cable_state_changed_cb");
783 return __connection_set_ethernet_cable_state_changed_cb(connection,
784 (connection_ethernet_cable_state_changed_cb)callback, user_data);
787 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
789 DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
790 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
792 if (!(__connection_check_handle_validity(connection))) {
793 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
794 return CONNECTION_ERROR_INVALID_PARAMETER;
797 return __connection_set_ethernet_cable_state_changed_cb(connection,
801 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
802 connection_ethernet_cable_state_changed_cb callback, void *user_data)
804 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
806 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
807 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
808 return CONNECTION_ERROR_INVALID_PARAMETER;
811 return __connection_set_ethernet_cable_state_changed_cb(connection,
812 callback, user_data);
815 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
817 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
819 if (!(__connection_check_handle_validity(connection))) {
820 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
821 return CONNECTION_ERROR_INVALID_PARAMETER;
824 return __connection_set_ethernet_cable_state_changed_cb(connection,
829 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
831 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
833 if (state == NULL || !(__connection_check_handle_validity(connection))) {
834 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
835 return CONNECTION_ERROR_INVALID_PARAMETER;
838 return _connection_libnet_get_bluetooth_state(state);
841 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
842 connection_type_changed_cb callback, void* user_data)
844 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
846 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
847 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
848 return CONNECTION_ERROR_INVALID_PARAMETER;
851 return __connection_set_type_changed_callback(connection, callback, user_data);
854 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
856 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
858 if (!(__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, NULL, NULL);
866 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
867 connection_address_changed_cb callback, void* user_data)
869 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
871 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
872 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
873 return CONNECTION_ERROR_INVALID_PARAMETER;
876 return __connection_set_ip_changed_callback(connection, callback, user_data);
879 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
881 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
883 if (!(__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, NULL, NULL);
891 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
892 connection_address_changed_cb callback, void* user_data)
894 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
896 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
897 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
898 return CONNECTION_ERROR_INVALID_PARAMETER;
901 return __connection_set_proxy_changed_callback(connection, callback, user_data);
904 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
906 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
908 if (!(__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, NULL, NULL);
916 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
919 net_profile_info_t *profile_info = profile;
921 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
923 if (!(__connection_check_handle_validity(connection)) ||
924 !(_connection_libnet_check_profile_validity(profile))) {
925 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
926 return CONNECTION_ERROR_INVALID_PARAMETER;
929 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
930 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
931 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
934 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
935 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
936 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
937 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
940 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
941 (net_profile_info_t*)profile);
942 if (rv == NET_ERR_ACCESS_DENIED) {
943 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
944 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
945 } else if (rv != NET_ERR_NONE) {
946 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
947 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
950 return CONNECTION_ERROR_NONE;
953 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
956 net_profile_info_t *profile_info = profile;
958 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
960 if (!(__connection_check_handle_validity(connection)) ||
961 !(_connection_libnet_check_profile_validity(profile))) {
962 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
963 return CONNECTION_ERROR_INVALID_PARAMETER;
966 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
967 profile_info->profile_type != NET_DEVICE_WIFI) {
968 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
969 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
972 rv = net_delete_profile(profile_info->ProfileName);
973 if (rv == NET_ERR_ACCESS_DENIED) {
974 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
975 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
976 } else if (rv != NET_ERR_NONE) {
977 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
978 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
981 return CONNECTION_ERROR_NONE;
984 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
987 net_profile_info_t *profile_info = profile;
989 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
991 if (!(__connection_check_handle_validity(connection)) ||
992 !(_connection_libnet_check_profile_validity(profile))) {
993 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
994 return CONNECTION_ERROR_INVALID_PARAMETER;
997 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
998 if (rv == NET_ERR_ACCESS_DENIED) {
999 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1000 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1001 } else if (rv != NET_ERR_NONE) {
1002 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
1003 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1006 return CONNECTION_ERROR_NONE;
1009 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1010 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1012 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1014 if (!(__connection_check_handle_validity(connection)) ||
1015 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1016 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1017 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1018 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1019 return CONNECTION_ERROR_INVALID_PARAMETER;
1022 return _connection_libnet_get_profile_iterator(type, profile_iterator);
1025 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1026 connection_profile_h* profile)
1028 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1030 return _connection_libnet_get_iterator_next(profile_iterator, profile);
1033 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1035 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1037 return _connection_libnet_iterator_has_next(profile_iterator);
1040 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1042 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1044 return _connection_libnet_destroy_iterator(profile_iterator);
1047 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1049 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1051 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1052 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1053 return CONNECTION_ERROR_INVALID_PARAMETER;
1056 return _connection_libnet_get_current_profile(profile);
1059 EXPORT_API int connection_get_default_cellular_service_profile(
1060 connection_h connection, connection_cellular_service_type_e type,
1061 connection_profile_h *profile)
1063 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1065 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1066 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1067 return CONNECTION_ERROR_INVALID_PARAMETER;
1070 return _connection_libnet_get_cellular_service_profile(type, profile);
1073 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1074 connection_cellular_service_type_e type, connection_profile_h profile)
1076 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1078 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1079 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1080 return CONNECTION_ERROR_INVALID_PARAMETER;
1083 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1086 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1087 connection_cellular_service_type_e type, connection_profile_h profile,
1088 connection_set_default_cb callback, void* user_data)
1090 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1092 if (!(__connection_check_handle_validity(connection)) ||
1093 profile == NULL || callback == NULL) {
1094 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1095 return CONNECTION_ERROR_INVALID_PARAMETER;
1098 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1101 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1102 connection_opened_cb callback, void* user_data)
1104 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1106 if (!(__connection_check_handle_validity(connection)) ||
1107 profile == NULL || callback == NULL) {
1108 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1109 return CONNECTION_ERROR_INVALID_PARAMETER;
1112 return _connection_libnet_open_profile(profile, callback, user_data);
1115 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1116 connection_closed_cb callback, void* user_data)
1118 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1120 if (!(__connection_check_handle_validity(connection)) ||
1121 profile == NULL || callback == NULL) {
1122 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1123 return CONNECTION_ERROR_INVALID_PARAMETER;
1126 return _connection_libnet_close_profile(profile, callback, user_data);
1129 EXPORT_API int connection_reset_profile(connection_h connection,
1130 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1132 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1134 if (!(__connection_check_handle_validity(connection))) {
1135 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1136 return CONNECTION_ERROR_INVALID_PARAMETER;
1139 if (id < 0 || id > 1) {
1140 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1141 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1144 return _connection_libnet_reset_profile(type, id, callback, user_data);
1147 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1149 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1151 if (!(__connection_check_handle_validity(connection)) ||
1152 interface_name == NULL || host_address == NULL) {
1153 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1154 return CONNECTION_ERROR_INVALID_PARAMETER;
1157 return _connection_libnet_add_route(interface_name, host_address);
1160 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1162 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1164 if (!(__connection_check_handle_validity(connection)) ||
1165 interface_name == NULL || host_address == NULL) {
1166 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1167 return CONNECTION_ERROR_INVALID_PARAMETER;
1170 return _connection_libnet_remove_route(interface_name, host_address);
1173 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1175 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1177 if (!(__connection_check_handle_validity(connection)) ||
1178 interface_name == NULL || host_address == NULL) {
1179 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1180 return CONNECTION_ERROR_INVALID_PARAMETER;
1183 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1186 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1188 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1190 if (!(__connection_check_handle_validity(connection)) ||
1191 interface_name == NULL || host_address == NULL) {
1192 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1193 return CONNECTION_ERROR_INVALID_PARAMETER;
1196 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1199 EXPORT_API int connection_add_route_entry(connection_h connection,
1200 connection_address_family_e address_family, const char *interface_name,
1201 const char *host_address, const char *gateway)
1203 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1205 if (!(__connection_check_handle_validity(connection)) ||
1206 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1207 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1208 interface_name == NULL || host_address == NULL) {
1209 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1210 return CONNECTION_ERROR_INVALID_PARAMETER;
1213 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1214 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1215 interface_name, host_address, gateway);
1217 return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1218 interface_name, host_address, gateway);
1220 return CONNECTION_ERROR_NONE;
1223 EXPORT_API int connection_remove_route_entry(connection_h connection,
1224 connection_address_family_e address_family, const char *interface_name,
1225 const char *host_address, const char *gateway)
1227 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1229 if (!(__connection_check_handle_validity(connection)) ||
1230 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1231 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1232 interface_name == NULL || host_address == NULL) {
1233 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1234 return CONNECTION_ERROR_INVALID_PARAMETER;
1237 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1238 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
1239 interface_name, host_address, gateway);
1241 return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
1242 interface_name, host_address, gateway);
1244 return CONNECTION_ERROR_NONE;
1247 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1249 int rv = VCONF_OK, rv1 = VCONF_OK;
1250 int last_size = 0, size = 0;
1251 #if defined TIZEN_DUALSIM_ENABLE
1255 if (llsize == NULL) {
1256 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1257 return CONNECTION_ERROR_INVALID_PARAMETER;
1260 switch (statistics_type) {
1261 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1262 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1263 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1264 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1267 return CONNECTION_ERROR_INVALID_PARAMETER;
1270 #if defined TIZEN_DUALSIM_ENABLE
1271 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1272 if (rv != VCONF_OK) {
1273 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1275 return CONNECTION_ERROR_OPERATION_FAILED;
1281 switch (statistics_type) {
1282 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1283 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1285 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1286 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1288 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1289 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1290 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1292 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1293 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1294 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1297 #if defined TIZEN_DUALSIM_ENABLE
1300 switch (statistics_type) {
1301 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1302 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1304 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1305 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1307 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1308 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1309 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1311 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1312 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1313 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1319 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1320 return CONNECTION_ERROR_OPERATION_FAILED;
1324 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1325 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1326 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1329 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1330 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1332 return CONNECTION_ERROR_NONE;
1335 static int __get_statistic(connection_type_e connection_type,
1336 connection_statistics_type_e statistics_type, long long *llsize)
1339 unsigned long long ull_size;
1341 if (llsize == NULL) {
1342 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1343 return CONNECTION_ERROR_INVALID_PARAMETER;
1346 rv = _connection_libnet_check_get_privilege();
1347 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1349 else if (rv != CONNECTION_ERROR_NONE) {
1350 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1351 return CONNECTION_ERROR_OPERATION_FAILED;
1354 if (connection_type == CONNECTION_TYPE_CELLULAR)
1355 return __get_cellular_statistic(statistics_type, llsize);
1356 else if (connection_type == CONNECTION_TYPE_WIFI) {
1357 switch (statistics_type) {
1358 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1359 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1361 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1362 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1364 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1365 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1367 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1368 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1371 return CONNECTION_ERROR_INVALID_PARAMETER;
1374 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1375 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1377 else if (rv != CONNECTION_ERROR_NONE) {
1378 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1379 *llsize = 0; //LCOV_EXCL_LINE
1380 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1383 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1384 *llsize = (long long)ull_size;
1386 return CONNECTION_ERROR_INVALID_PARAMETER;
1388 return CONNECTION_ERROR_NONE;
1391 static int __reset_statistic(connection_type_e connection_type,
1392 connection_statistics_type_e statistics_type)
1398 if (connection_type == CONNECTION_TYPE_CELLULAR)
1399 conn_type = NET_DEVICE_CELLULAR;
1400 else if (connection_type == CONNECTION_TYPE_WIFI)
1401 conn_type = NET_DEVICE_WIFI;
1403 return CONNECTION_ERROR_INVALID_PARAMETER;
1405 switch (statistics_type) {
1406 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1407 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1409 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1410 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1412 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1413 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1415 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1416 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1419 return CONNECTION_ERROR_INVALID_PARAMETER;
1422 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1423 if (rv != CONNECTION_ERROR_NONE)
1426 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1428 return CONNECTION_ERROR_NONE;
1431 EXPORT_API int connection_get_statistics(connection_h connection,
1432 connection_type_e connection_type,
1433 connection_statistics_type_e statistics_type, long long* size)
1435 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1437 if (connection_type == CONNECTION_TYPE_CELLULAR)
1438 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1439 else if (connection_type == CONNECTION_TYPE_WIFI)
1440 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1442 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1443 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1444 return CONNECTION_ERROR_INVALID_PARAMETER;
1447 return __get_statistic(connection_type, statistics_type, size);
1450 EXPORT_API int connection_reset_statistics(connection_h connection,
1451 connection_type_e connection_type,
1452 connection_statistics_type_e statistics_type)
1454 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1456 if (connection_type == CONNECTION_TYPE_CELLULAR)
1457 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1458 else if (connection_type == CONNECTION_TYPE_WIFI)
1459 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1461 if (!__connection_check_handle_validity(connection)) {
1462 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1463 return CONNECTION_ERROR_INVALID_PARAMETER;
1466 return __reset_statistic(connection_type, statistics_type);
1469 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1470 connection_type_e connection_type, connection_ipv6_address_cb callback,
1473 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1474 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1476 GSList *ipv6_address_list = NULL;
1478 if (!(__connection_check_handle_validity(connection))) {
1479 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1480 return CONNECTION_ERROR_INVALID_PARAMETER;
1483 int rv = CONNECTION_ERROR_NONE;
1485 switch (connection_type) {
1486 case CONNECTION_TYPE_WIFI:
1487 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1488 &ipv6_address_list);
1490 case CONNECTION_TYPE_CELLULAR:
1491 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1492 &ipv6_address_list);
1494 case CONNECTION_TYPE_ETHERNET:
1495 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1496 &ipv6_address_list);
1498 case CONNECTION_TYPE_BT:
1499 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1500 &ipv6_address_list);
1503 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1504 return CONNECTION_ERROR_INVALID_PARAMETER;
1507 if (rv != NET_ERR_NONE) {
1508 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address"
1509 " Failed = %d\n", rv);
1510 return CONNECTION_ERROR_OPERATION_FAILED;
1514 for (list = ipv6_address_list; list; list = list->next) {
1515 rv = callback((char *)list->data, user_data);
1520 g_slist_free_full(ipv6_address_list, g_free);
1521 ipv6_address_list = NULL;
1523 return CONNECTION_ERROR_NONE;
1526 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1530 if (!(__connection_check_handle_validity(connection))) {
1531 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1532 return CONNECTION_ERROR_INVALID_PARAMETER;
1535 ret = _connection_libnet_start_tcpdump();
1536 if (ret != CONNECTION_ERROR_NONE) {
1537 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
1541 return CONNECTION_ERROR_NONE;
1544 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1548 if (!(__connection_check_handle_validity(connection))) {
1549 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1550 return CONNECTION_ERROR_INVALID_PARAMETER;
1553 ret = _connection_libnet_stop_tcpdump();
1554 if (ret != CONNECTION_ERROR_NONE) {
1555 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
1559 return CONNECTION_ERROR_NONE;
1562 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1566 if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1567 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1568 return CONNECTION_ERROR_INVALID_PARAMETER;
1571 ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
1572 if (ret != CONNECTION_ERROR_NONE) {
1573 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
1577 return CONNECTION_ERROR_NONE;