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>
23 #include <arpa/inet.h>
25 #include "net_connection_private.h"
27 static __thread GSList *prof_handle_list = NULL;
28 static __thread GHashTable *profile_cb_table = NULL;
30 struct _profile_cb_s {
31 connection_profile_state_changed_cb callback;
32 connection_profile_state_e state;
36 struct _profile_list_s {
39 net_profile_info_t *profiles;
43 connection_opened_cb opened_cb;
44 connection_closed_cb closed_cb;
45 connection_set_default_cb set_default_cb;
46 connection_reset_cb reset_profile_cb;
47 libnet_ethernet_cable_state_changed_cb ethernet_cable_state_changed_cb;
48 libnet_type_changed_cb type_changed_cb;
49 libnet_ip_changed_cb ip_changed_cb;
50 libnet_proxy_changed_cb proxy_changed_cb;
51 void *opened_user_data;
52 void *closed_user_data;
53 void *set_default_user_data;
54 void *reset_profile_user_data;
58 struct _state_notify {
59 connection_profile_state_changed_cb callback;
60 connection_profile_state_e state;
64 struct managed_idle_data {
70 static __thread struct _profile_list_s profile_iterator = {0, 0, NULL};
71 static __thread struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL,
72 NULL, NULL, NULL, NULL, NULL, NULL, false};
73 static __thread GSList *managed_idler_list = NULL;
74 static __thread bool connection_is_feature_checked[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
75 static __thread bool connection_feature_supported[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
77 bool _connection_is_created(void)
79 return libnet.is_created;
82 static void __connection_set_created(bool tag)
84 libnet.is_created = tag;
88 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
92 return CONNECTION_ERROR_NONE;
93 case NET_ERR_APP_ALREADY_REGISTERED:
94 return CONNECTION_ERROR_INVALID_OPERATION;
95 case NET_ERR_APP_NOT_REGISTERED:
96 return CONNECTION_ERROR_INVALID_OPERATION;
97 case NET_ERR_NO_ACTIVE_CONNECTIONS:
98 return CONNECTION_ERROR_NO_CONNECTION;
99 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
100 return CONNECTION_ERROR_ALREADY_EXISTS;
101 case NET_ERR_CONNECTION_DHCP_FAILED:
102 return CONNECTION_ERROR_DHCP_FAILED;
103 case NET_ERR_CONNECTION_INVALID_KEY:
104 return CONNECTION_ERROR_INVALID_KEY;
105 case NET_ERR_IN_PROGRESS:
106 return CONNECTION_ERROR_NOW_IN_PROGRESS;
107 case NET_ERR_OPERATION_ABORTED:
108 return CONNECTION_ERROR_OPERATION_ABORTED;
109 case NET_ERR_TIME_OUT:
110 return CONNECTION_ERROR_NO_REPLY;
111 case NET_ERR_ACCESS_DENIED:
112 return CONNECTION_ERROR_PERMISSION_DENIED;
114 return CONNECTION_ERROR_OPERATION_FAILED;
118 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
121 case CONNECTION_ERROR_NONE:
123 case CONNECTION_ERROR_INVALID_PARAMETER:
124 return "INVALID_PARAMETER";
125 case CONNECTION_ERROR_OUT_OF_MEMORY:
126 return "OUT_OF_MEMORY";
127 case CONNECTION_ERROR_INVALID_OPERATION:
128 return "INVALID_OPERATION";
129 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
130 return "ADDRESS_FAMILY_NOT_SUPPORTED";
131 case CONNECTION_ERROR_OPERATION_FAILED:
132 return "OPERATION_FAILED";
133 case CONNECTION_ERROR_ITERATOR_END:
134 return "ITERATOR_END";
135 case CONNECTION_ERROR_NO_CONNECTION:
136 return "NO_CONNECTION";
137 case CONNECTION_ERROR_NOW_IN_PROGRESS:
138 return "NOW_IN_PROGRESS";
139 case CONNECTION_ERROR_ALREADY_EXISTS:
140 return "ALREADY_EXISTS";
141 case CONNECTION_ERROR_OPERATION_ABORTED:
142 return "OPERATION_ABORTED";
143 case CONNECTION_ERROR_DHCP_FAILED:
144 return "DHCP_FAILED";
145 case CONNECTION_ERROR_INVALID_KEY:
146 return "INVALID_KEY";
147 case CONNECTION_ERROR_NO_REPLY:
149 case CONNECTION_ERROR_PERMISSION_DENIED:
150 return "PERMISSION_DENIED";
151 case CONNECTION_ERROR_NOT_SUPPORTED:
152 return "NOT_SUPPORTED";
153 case CONNECTION_ERROR_ALREADY_INITIALIZED:
154 return "ALREADY_INITIALIZED";
155 case CONNECTION_ERROR_NOT_INITIALIZED:
156 return "NOT_INITIALIZED";
162 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
165 case CONNECTION_PROFILE_STATE_DISCONNECTED:
166 return "DISCONNECTED";
167 case CONNECTION_PROFILE_STATE_ASSOCIATION:
168 return "ASSOCIATION";
169 case CONNECTION_PROFILE_STATE_CONFIGURATION:
170 return "CONFIGURATION";
171 case CONNECTION_PROFILE_STATE_CONNECTED:
178 static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
180 if (user_cb != NULL) {
181 libnet.reset_profile_cb = user_cb;
182 libnet.reset_profile_user_data = user_data;
186 static gboolean __libnet_reset_profile_cb_idle(gpointer data)
188 connection_error_e result = (connection_error_e)data;
190 if (libnet.reset_profile_cb != NULL)
191 libnet.reset_profile_cb(result, libnet.reset_profile_user_data);
193 libnet.reset_profile_cb = NULL;
194 libnet.reset_profile_user_data = NULL;
199 static void __libnet_reset_profile_cb(connection_error_e result)
201 if (_connection_is_created() != true) {
202 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
203 "If multi-threaded, thread integrity be broken.");
207 if (libnet.reset_profile_cb != NULL)
208 _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
211 static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
213 if (user_cb != NULL) {
214 libnet.opened_cb = user_cb;
215 libnet.opened_user_data = user_data;
219 static gboolean __libnet_opened_cb_idle(gpointer data)
221 connection_error_e result = (connection_error_e)data;
223 if (libnet.opened_cb != NULL)
224 libnet.opened_cb(result, libnet.opened_user_data);
226 libnet.opened_cb = NULL;
227 libnet.opened_user_data = NULL;
232 static void __libnet_opened_cb(connection_error_e result)
234 if (_connection_is_created() != true) {
235 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
236 "If multi-threaded, thread integrity be broken.");
240 if (libnet.opened_cb != NULL)
241 _connection_callback_add(__libnet_opened_cb_idle, (gpointer)result);
244 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
246 if (user_cb != NULL) {
247 libnet.closed_cb = user_cb;
248 libnet.closed_user_data = user_data;
252 static gboolean __libnet_closed_cb_idle(gpointer data)
254 connection_error_e result = (connection_error_e)data;
256 if (libnet.closed_cb != NULL)
257 libnet.closed_cb(result, libnet.closed_user_data);
259 libnet.closed_cb = NULL;
260 libnet.closed_user_data = NULL;
265 static void __libnet_closed_cb(connection_error_e result)
267 if (_connection_is_created() != true) {
268 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
269 "If multi-threaded, thread integrity be broken.");
273 if (libnet.closed_cb != NULL)
274 _connection_callback_add(__libnet_closed_cb_idle, (gpointer)result);
277 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
279 if (user_cb != NULL) {
280 libnet.set_default_cb = user_cb;
281 libnet.set_default_user_data = user_data;
285 static gboolean __libnet_default_cb_idle(gpointer data)
287 connection_error_e result = (connection_error_e)data;
289 if (libnet.set_default_cb != NULL)
290 libnet.set_default_cb(result, libnet.set_default_user_data);
292 libnet.set_default_cb = NULL;
293 libnet.set_default_user_data = NULL;
298 static void __libnet_default_cb(connection_error_e result)
300 if (_connection_is_created() != true) {
301 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
302 "If multi-threaded, thread integrity be broken.");
306 if (libnet.set_default_cb != NULL)
307 _connection_callback_add(__libnet_default_cb_idle, (gpointer)result);
310 static void __libnet_set_ethernet_cable_state_changed_cb(
311 libnet_ethernet_cable_state_changed_cb user_cb)
313 libnet.ethernet_cable_state_changed_cb = user_cb;
316 static void __libnet_ethernet_cable_state_changed_cb(
317 connection_ethernet_cable_state_e state)
319 if (libnet.ethernet_cable_state_changed_cb)
320 libnet.ethernet_cable_state_changed_cb(state);
323 static void __libnet_type_changed_cb(int type)
325 if (libnet.type_changed_cb)
326 libnet.type_changed_cb(type);
329 static void __libnet_ip_changed_cb(connection_address_family_e addr_family,
332 if (libnet.ip_changed_cb)
333 libnet.ip_changed_cb(addr_family, ip_addr);
336 static void __libnet_proxy_changed_cb(char *proxy_addr)
338 if (libnet.proxy_changed_cb)
339 libnet.proxy_changed_cb(proxy_addr);
342 static gboolean __libnet_state_changed_cb_idle(gpointer data)
344 struct _state_notify *notify = (struct _state_notify *)data;
349 if (notify->callback != NULL)
350 notify->callback(notify->state, notify->user_data);
357 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
360 struct _state_notify *notify;
361 struct _profile_cb_s *cb_info;
363 if (_connection_is_created() != true) {
364 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
365 "If multi-threaded, thread integrity be broken.");
369 if (profile_name == NULL)
372 cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
376 if (cb_info->state == state)
379 cb_info->state = state;
381 if (state < 0 || cb_info->callback == NULL)
384 notify = g_try_new0(struct _state_notify, 1);
388 notify->callback = cb_info->callback;
389 notify->state = state;
390 notify->user_data = cb_info->user_data;
392 id = _connection_callback_add(__libnet_state_changed_cb_idle,
398 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
400 if (profile_list->count > 0)
401 g_free(profile_list->profiles);
403 profile_list->count = 0;
404 profile_list->next = 0;
405 profile_list->profiles = NULL;
408 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
410 bool is_requested = false;
411 connection_error_e result = CONNECTION_ERROR_NONE;
413 switch (event_cb->Event) {
414 case NET_EVENT_OPEN_RSP:
417 case NET_EVENT_OPEN_IND:
418 result = __libnet_convert_to_cp_error_type(event_cb->Error);
419 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
420 (is_requested) ? "RSP" : "IND",
421 __libnet_convert_cp_error_type_to_string(result));
424 __libnet_opened_cb(result);
426 switch (event_cb->Error) {
428 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
429 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
431 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
434 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
435 __libnet_convert_cp_error_type_to_string(result));
438 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
441 case NET_EVENT_CLOSE_RSP:
444 case NET_EVENT_CLOSE_IND:
445 result = __libnet_convert_to_cp_error_type(event_cb->Error);
446 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
447 (is_requested) ? "RSP" : "IND",
448 __libnet_convert_cp_error_type_to_string(result));
451 __libnet_closed_cb(result);
453 switch (event_cb->Error) {
455 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
457 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
460 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
461 __libnet_convert_cp_error_type_to_string(result));
465 case NET_EVENT_NET_STATE_IND:
466 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
468 if (event_cb->Datalength != sizeof(net_state_type_t))
471 net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
472 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
474 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
475 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
477 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
480 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
481 result = __libnet_convert_to_cp_error_type(event_cb->Error);
482 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
483 __libnet_default_cb(result);
486 case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
487 result = __libnet_convert_to_cp_error_type(event_cb->Error);
488 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
489 __libnet_reset_profile_cb(result);
491 case NET_EVENT_ETHERNET_CABLE_ATTACHED:
492 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
493 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED);
495 case NET_EVENT_ETHERNET_CABLE_DETACHED:
496 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
497 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED);
499 case NET_EVENT_NETWORK_TYPE_CHANGED:
500 CONNECTION_LOG(CONNECTION_INFO, "Got Network Type Changed Indication");
501 int *state = (int *) event_cb->Data;
502 __libnet_type_changed_cb(*state);
504 case NET_EVENT_IPV4_ADDRESS_CHANGED:
505 CONNECTION_LOG(CONNECTION_INFO, "Got IPv4 Address Changed Indication");
506 char *ipv4_addr = (char *)event_cb->Data;
507 __libnet_ip_changed_cb(CONNECTION_ADDRESS_FAMILY_IPV4, ipv4_addr);
509 case NET_EVENT_IPV6_ADDRESS_CHANGED:
510 CONNECTION_LOG(CONNECTION_INFO, "Got IPv6 Address Changed Indication");
511 char *ipv6_addr = (char *)event_cb->Data;
512 __libnet_ip_changed_cb(CONNECTION_ADDRESS_FAMILY_IPV6, ipv6_addr);
514 case NET_EVENT_PROXY_ADDRESS_CHANGED:
515 CONNECTION_LOG(CONNECTION_INFO, "Got Proxy Changed Indication");
516 char *proxy_addr = (char *)event_cb->Data;
517 __libnet_proxy_changed_cb(proxy_addr);
526 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
531 for (; i < profile_list->count; i++) {
532 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
533 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
540 void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
544 for (; i < source->count; i++) {
545 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
546 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
547 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
554 int __libnet_get_default_count(struct _profile_list_s *profile_list)
559 for (; i < profile_list->count; i++) {
560 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
567 void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
571 for (; i < source->count; i++) {
572 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
573 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
580 int _connection_libnet_init(void)
584 if (_connection_is_created() != true) {
585 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
586 if (rv != NET_ERR_NONE)
589 __connection_set_created(true);
591 if (profile_cb_table == NULL)
592 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
598 bool _connection_libnet_deinit(void)
600 if (_connection_is_created() == true) {
601 if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
604 __connection_set_created(false);
606 if (profile_cb_table) {
607 g_hash_table_destroy(profile_cb_table);
608 profile_cb_table = NULL;
611 __libnet_clear_profile_list(&profile_iterator);
613 if (prof_handle_list) {
614 g_slist_free_full(prof_handle_list, g_free);
615 prof_handle_list = NULL;
622 void _connection_set_cs_tid(int tid)
627 void _connection_unset_cs_tid(int tid)
629 net_unset_cs_tid(tid);
632 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
640 for (list = prof_handle_list; list; list = list->next)
641 if (profile == list->data) return true;
643 for (; i < profile_iterator.count; i++)
644 if (profile == &profile_iterator.profiles[i]) return true;
650 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
652 struct _profile_cb_s *cb_info;
653 net_profile_info_t *profile_info = profile;
658 cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
666 int _connection_libnet_get_metered_state(bool* is_metered)
671 rv = net_get_metered_state(&status);
672 if (rv == NET_ERR_ACCESS_DENIED) {
673 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
674 return CONNECTION_ERROR_PERMISSION_DENIED;
675 } else if (rv != NET_ERR_NONE) {
676 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv);
677 return CONNECTION_ERROR_OPERATION_FAILED;
684 return CONNECTION_ERROR_NONE;
687 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
690 net_wifi_state_t wlan_state;
692 rv = net_get_wifi_state(&wlan_state);
693 if (rv == NET_ERR_ACCESS_DENIED) {
694 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
695 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
696 } else if (rv != NET_ERR_NONE) {
697 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
698 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
701 switch (wlan_state) {
703 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
706 case WIFI_ASSOCIATION:
707 case WIFI_CONFIGURATION:
708 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
711 case WIFI_DISCONNECTING:
712 *state = CONNECTION_WIFI_STATE_CONNECTED;
715 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state"); //LCOV_EXCL_LINE
716 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
719 return CONNECTION_ERROR_NONE;
722 void _connection_libnet_set_type_changed_cb(libnet_type_changed_cb callback)
724 libnet.type_changed_cb = callback;
727 void _connection_libnet_set_ip_changed_cb(libnet_ip_changed_cb callback)
729 libnet.ip_changed_cb = callback;
732 void _connection_libnet_set_proxy_changed_cb(libnet_proxy_changed_cb callback)
734 libnet.proxy_changed_cb = callback;
738 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e *state)
741 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
742 rv = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
743 if (rv == NET_ERR_ACCESS_DENIED) {
744 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
745 return CONNECTION_ERROR_PERMISSION_DENIED;
748 if (ethernet_profiles.count == 0) {
749 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
750 return CONNECTION_ERROR_NONE;
753 switch (ethernet_profiles.profiles->ProfileState) {
754 case NET_STATE_TYPE_ONLINE:
755 case NET_STATE_TYPE_READY:
756 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
758 case NET_STATE_TYPE_IDLE:
759 case NET_STATE_TYPE_FAILURE:
760 case NET_STATE_TYPE_ASSOCIATION:
761 case NET_STATE_TYPE_CONFIGURATION:
762 case NET_STATE_TYPE_DISCONNECT:
763 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
766 __libnet_clear_profile_list(ðernet_profiles);
767 return CONNECTION_ERROR_OPERATION_FAILED;
770 __libnet_clear_profile_list(ðernet_profiles);
772 return CONNECTION_ERROR_NONE;
775 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
780 rv = net_get_ethernet_cable_state(&status);
781 if (rv == NET_ERR_ACCESS_DENIED) {
782 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
783 return CONNECTION_ERROR_PERMISSION_DENIED;
784 } else if (rv != NET_ERR_NONE) {
785 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
786 return CONNECTION_ERROR_OPERATION_FAILED;
790 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
792 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
793 return CONNECTION_ERROR_NONE;
796 int _connection_libnet_set_ethernet_cable_state_changed_cb(
797 libnet_ethernet_cable_state_changed_cb callback)
799 __libnet_set_ethernet_cable_state_changed_cb(callback);
801 return CONNECTION_ERROR_NONE;
805 int _connection_libnet_get_bluetooth_state(connection_bt_state_e *state)
809 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
810 rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
811 if (rv == NET_ERR_ACCESS_DENIED) {
812 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
813 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
816 if (bluetooth_profiles.count == 0) {
817 *state = CONNECTION_BT_STATE_DEACTIVATED;
818 return CONNECTION_ERROR_NONE;
822 for (; i < bluetooth_profiles.count; i++) {
823 switch (bluetooth_profiles.profiles[i].ProfileState) {
824 case NET_STATE_TYPE_ONLINE:
825 case NET_STATE_TYPE_READY:
826 *state = CONNECTION_BT_STATE_CONNECTED;
828 case NET_STATE_TYPE_IDLE:
829 case NET_STATE_TYPE_FAILURE:
830 case NET_STATE_TYPE_ASSOCIATION:
831 case NET_STATE_TYPE_CONFIGURATION:
832 case NET_STATE_TYPE_DISCONNECT:
833 *state = CONNECTION_BT_STATE_DISCONNECTED;
836 __libnet_clear_profile_list(&bluetooth_profiles);
837 return CONNECTION_ERROR_OPERATION_FAILED;
843 __libnet_clear_profile_list(&bluetooth_profiles);
845 return CONNECTION_ERROR_NONE;
848 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
851 int rv1, rv2, rv3, rv4, rv5;
852 net_profile_info_t *profiles = NULL;
854 struct _profile_list_s wifi_profiles = {0, 0, NULL};
855 struct _profile_list_s cellular_profiles = {0, 0, NULL};
856 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
857 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
858 struct _profile_list_s mesh_profiles = {0, 0, NULL};
860 __libnet_clear_profile_list(&profile_iterator);
862 rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
863 if (rv1 == NET_ERR_ACCESS_DENIED) {
864 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
865 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
866 } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
867 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
869 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
871 rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
872 if (rv2 == NET_ERR_ACCESS_DENIED) {
873 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
874 __libnet_clear_profile_list(&wifi_profiles);
875 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
876 } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
877 __libnet_clear_profile_list(&wifi_profiles);
878 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
880 CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
882 rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
883 if (rv3 == NET_ERR_ACCESS_DENIED) {
884 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
885 __libnet_clear_profile_list(&wifi_profiles);
886 __libnet_clear_profile_list(&cellular_profiles);
887 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
888 } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
889 __libnet_clear_profile_list(&wifi_profiles);
890 __libnet_clear_profile_list(&cellular_profiles);
891 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
893 CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
895 rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
896 if (rv4 == NET_ERR_ACCESS_DENIED) {
897 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
898 __libnet_clear_profile_list(&wifi_profiles);
899 __libnet_clear_profile_list(&cellular_profiles);
900 __libnet_clear_profile_list(ðernet_profiles);
901 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
902 } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
903 __libnet_clear_profile_list(&wifi_profiles);
904 __libnet_clear_profile_list(&cellular_profiles);
905 __libnet_clear_profile_list(ðernet_profiles);
906 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
908 CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
910 rv5 = net_get_profile_list(NET_DEVICE_MESH, &mesh_profiles.profiles, &mesh_profiles.count);
911 if (rv5 == NET_ERR_ACCESS_DENIED) {
912 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
913 __libnet_clear_profile_list(&wifi_profiles);
914 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
915 } else if (rv5 != NET_ERR_NO_SERVICE && rv5 != NET_ERR_NONE) {
916 __libnet_clear_profile_list(&wifi_profiles);
917 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
920 CONNECTION_LOG(CONNECTION_INFO, "Mesh profile count: %d", mesh_profiles.count);
921 *profile_iter_h = &profile_iterator;
924 case CONNECTION_ITERATOR_TYPE_REGISTERED:
925 count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count + mesh_profiles.count;
926 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
928 return CONNECTION_ERROR_NONE;
930 profiles = g_try_new0(net_profile_info_t, count);
931 if (profiles == NULL) {
932 __libnet_clear_profile_list(&wifi_profiles);
933 __libnet_clear_profile_list(&cellular_profiles);
934 __libnet_clear_profile_list(ðernet_profiles);
935 __libnet_clear_profile_list(&bluetooth_profiles);
936 __libnet_clear_profile_list(&mesh_profiles);
937 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
940 profile_iterator.profiles = profiles;
942 if (wifi_profiles.count > 0) {
943 memcpy(profiles, wifi_profiles.profiles,
944 sizeof(net_profile_info_t) * wifi_profiles.count);
945 profiles += wifi_profiles.count;
948 if (cellular_profiles.count > 0) {
949 memcpy(profiles, cellular_profiles.profiles,
950 sizeof(net_profile_info_t) * cellular_profiles.count);
951 profiles += cellular_profiles.count;
954 if (ethernet_profiles.count > 0) {
955 memcpy(profiles, ethernet_profiles.profiles,
956 sizeof(net_profile_info_t) * ethernet_profiles.count);
957 profiles += ethernet_profiles.count;
960 if (mesh_profiles.count > 0) {
961 memcpy(profiles, mesh_profiles.profiles,
962 sizeof(net_profile_info_t) * mesh_profiles.count);
963 profiles += mesh_profiles.count;
966 if (bluetooth_profiles.count > 0)
967 memcpy(profiles, bluetooth_profiles.profiles,
968 sizeof(net_profile_info_t) * bluetooth_profiles.count);
971 case CONNECTION_ITERATOR_TYPE_CONNECTED:
972 count = __libnet_get_connected_count(&wifi_profiles);
973 count += __libnet_get_connected_count(&cellular_profiles);
974 count += __libnet_get_connected_count(ðernet_profiles);
975 count += __libnet_get_connected_count(&bluetooth_profiles);
976 count += __libnet_get_connected_count(&mesh_profiles);
977 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
979 return CONNECTION_ERROR_NONE;
981 profiles = g_try_new0(net_profile_info_t, count);
982 if (profiles == NULL) {
983 __libnet_clear_profile_list(&wifi_profiles);
984 __libnet_clear_profile_list(&cellular_profiles);
985 __libnet_clear_profile_list(ðernet_profiles);
986 __libnet_clear_profile_list(&bluetooth_profiles);
987 __libnet_clear_profile_list(&mesh_profiles);
988 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
991 profile_iterator.profiles = profiles;
993 if (wifi_profiles.count > 0)
994 __libnet_copy_connected_profile(&profiles, &wifi_profiles);
996 if (cellular_profiles.count > 0)
997 __libnet_copy_connected_profile(&profiles, &cellular_profiles);
999 if (ethernet_profiles.count > 0)
1000 __libnet_copy_connected_profile(&profiles, ðernet_profiles);
1002 if (bluetooth_profiles.count > 0)
1003 __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
1005 if (mesh_profiles.count > 0)
1006 __libnet_copy_connected_profile(&profiles, &mesh_profiles);
1009 case CONNECTION_ITERATOR_TYPE_DEFAULT:
1010 count = __libnet_get_default_count(&cellular_profiles);
1011 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
1013 return CONNECTION_ERROR_NONE;
1015 profiles = g_try_new0(net_profile_info_t, count);
1016 if (profiles == NULL) {
1017 __libnet_clear_profile_list(&wifi_profiles);
1018 __libnet_clear_profile_list(&cellular_profiles);
1019 __libnet_clear_profile_list(ðernet_profiles);
1020 __libnet_clear_profile_list(&bluetooth_profiles);
1021 __libnet_clear_profile_list(&mesh_profiles);
1022 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1025 profile_iterator.profiles = profiles;
1027 if (cellular_profiles.count > 0)
1028 __libnet_copy_default_profile(&profiles, &cellular_profiles);
1032 __libnet_clear_profile_list(&wifi_profiles);
1033 __libnet_clear_profile_list(&cellular_profiles);
1034 __libnet_clear_profile_list(ðernet_profiles);
1035 __libnet_clear_profile_list(&bluetooth_profiles);
1036 __libnet_clear_profile_list(&mesh_profiles);
1038 profile_iterator.count = count;
1040 return CONNECTION_ERROR_NONE;
1043 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
1045 if (profile_iter_h != &profile_iterator)
1046 return CONNECTION_ERROR_INVALID_PARAMETER;
1048 if (profile_iterator.count <= profile_iterator.next)
1049 return CONNECTION_ERROR_ITERATOR_END;
1051 *profile = &profile_iterator.profiles[profile_iterator.next];
1052 profile_iterator.next++;
1054 return CONNECTION_ERROR_NONE;
1057 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
1059 if (profile_iter_h != &profile_iterator)
1062 if (profile_iterator.count <= profile_iterator.next)
1068 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
1070 if (profile_iter_h != &profile_iterator)
1071 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1073 __libnet_clear_profile_list(&profile_iterator);
1075 return CONNECTION_ERROR_NONE;
1078 int _connection_libnet_get_current_profile(connection_profile_h *profile)
1080 net_profile_info_t active_profile;
1083 rv = net_get_active_net_info(&active_profile);
1084 if (rv == NET_ERR_NO_SERVICE)
1085 return CONNECTION_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
1086 else if (rv == NET_ERR_ACCESS_DENIED) {
1087 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1088 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1089 } else if (rv != NET_ERR_NONE)
1090 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1092 *profile = g_try_malloc0(sizeof(net_profile_info_t));
1093 if (*profile == NULL)
1094 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1096 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
1097 prof_handle_list = g_slist_append(prof_handle_list, *profile);
1099 return CONNECTION_ERROR_NONE;
1102 int _connection_libnet_reset_profile(connection_reset_option_e type,
1103 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
1107 rv = net_reset_profile(type, id);
1108 if (rv == NET_ERR_ACCESS_DENIED) {
1109 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1110 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1111 } else if (rv != NET_ERR_NONE) {
1112 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
1113 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1116 __libnet_set_reset_profile_cb(callback, user_data);
1118 return CONNECTION_ERROR_NONE;
1121 int _connection_libnet_open_profile(connection_profile_h profile,
1122 connection_opened_cb callback, void* user_data)
1126 if (!(_connection_libnet_check_profile_validity(profile))) {
1127 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1128 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1131 net_profile_info_t *profile_info = profile;
1133 if (profile_info->profile_type == NET_DEVICE_MESH)
1134 rv = net_open_mesh_connection_with_profile(profile_info->ProfileName);
1136 rv = net_open_connection_with_profile(profile_info->ProfileName);
1138 if (rv == NET_ERR_ACCESS_DENIED) {
1139 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1140 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1141 } else if (rv != NET_ERR_NONE)
1142 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1144 __libnet_set_opened_cb(callback, user_data);
1146 return CONNECTION_ERROR_NONE;
1149 int _connection_libnet_get_cellular_service_profile(
1150 connection_cellular_service_type_e type, connection_profile_h *profile)
1153 int rv = NET_ERR_NONE;
1154 #if defined TIZEN_DUALSIM_ENABLE
1155 int default_subscriber_id = 0;
1156 char subscriber_id[3];
1159 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
1160 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
1162 rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
1163 if (rv == NET_ERR_ACCESS_DENIED) {
1164 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1165 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1166 } else if (rv != NET_ERR_NONE) {
1167 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv); //LCOV_EXCL_LINE
1168 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1171 #if defined TIZEN_DUALSIM_ENABLE
1172 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
1173 &default_subscriber_id) != 0) {
1174 CONNECTION_LOG(CONNECTION_ERROR,
1175 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
1176 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
1177 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1180 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
1183 for (i = 0; i < cellular_profiles.count; i++)
1184 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
1185 #if defined TIZEN_DUALSIM_ENABLE
1186 if (g_str_has_suffix(
1187 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
1188 subscriber_id) == TRUE)
1192 if (i >= cellular_profiles.count) {
1193 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
1194 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1197 *profile = g_try_malloc0(sizeof(net_profile_info_t));
1198 if (*profile == NULL) {
1199 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
1200 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1203 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
1205 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
1209 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
1210 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
1213 for (j = 0; j < cellular_profiles.count; j++) {
1217 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
1220 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
1221 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
1228 __libnet_clear_profile_list(&cellular_profiles);
1229 prof_handle_list = g_slist_append(prof_handle_list, *profile);
1231 return CONNECTION_ERROR_NONE;
1234 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
1238 if (!(_connection_libnet_check_profile_validity(profile))) {
1239 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1240 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1243 net_profile_info_t *profile_info = profile;
1244 connection_cellular_service_type_e service_type;
1246 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1248 if (service_type != type)
1249 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1251 rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
1252 if (rv == NET_ERR_ACCESS_DENIED) {
1253 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1254 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1255 } else if (rv != NET_ERR_NONE)
1256 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1258 return CONNECTION_ERROR_NONE;
1261 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
1262 connection_profile_h profile, connection_set_default_cb callback, void* user_data)
1266 if (!(_connection_libnet_check_profile_validity(profile))) {
1267 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1268 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1271 net_profile_info_t *profile_info = profile;
1272 connection_cellular_service_type_e service_type;
1274 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1276 if (service_type != type)
1277 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1279 rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
1280 if (rv == NET_ERR_ACCESS_DENIED) {
1281 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1282 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1283 } else if (rv != NET_ERR_NONE)
1284 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1286 __libnet_set_default_cb(callback, user_data);
1288 return CONNECTION_ERROR_NONE;
1291 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
1295 if (!(_connection_libnet_check_profile_validity(profile))) {
1296 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1297 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1300 net_profile_info_t *profile_info = profile;
1302 if (profile_info->profile_type == NET_DEVICE_MESH)
1303 rv = net_close_mesh_connection(profile_info->ProfileName);
1305 rv = net_close_connection(profile_info->ProfileName);
1307 if (rv == NET_ERR_ACCESS_DENIED) {
1308 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1309 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1310 } else if (rv != NET_ERR_NONE)
1311 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1313 __libnet_set_closed_cb(callback, user_data);
1315 return CONNECTION_ERROR_NONE;
1318 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
1321 char *endstr = NULL;
1322 int address_family = 0;
1324 address_family = AF_INET;
1326 endstr = strrchr(host_address, '.');
1327 if (endstr == NULL ||
1328 strcmp(endstr, ".0") == 0 ||
1329 strncmp(host_address, "0.", 2) == 0 ||
1330 strstr(host_address, "255") != NULL) {
1331 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1332 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1335 rv = net_add_route(host_address, interface_name, address_family);
1336 if (rv == NET_ERR_ACCESS_DENIED) {
1337 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1338 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1339 } else if (rv != NET_ERR_NONE)
1340 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1342 return CONNECTION_ERROR_NONE;
1345 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
1348 char *endstr = strrchr(host_address, '.');
1349 int address_family = 0;
1351 address_family = AF_INET;
1353 endstr = strrchr(host_address, '.');
1354 if (endstr == NULL ||
1355 strcmp(endstr, ".0") == 0 ||
1356 strncmp(host_address, "0.", 2) == 0 ||
1357 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1358 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1359 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1362 rv = net_remove_route(host_address, interface_name, address_family);
1363 if (rv == NET_ERR_ACCESS_DENIED) {
1364 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1365 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1366 } else if (rv != NET_ERR_NONE)
1367 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1369 return CONNECTION_ERROR_NONE;
1372 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1375 int address_family = 0;
1377 address_family = AF_INET6;
1379 if (strncmp(host_address, "fe80:", 5) == 0 ||
1380 strncmp(host_address, "ff00:", 5) == 0 ||
1381 strncmp(host_address, "::", 2) == 0) {
1382 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1383 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1386 rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1387 if (rv == NET_ERR_ACCESS_DENIED) {
1388 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1389 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1390 } else if (rv != NET_ERR_NONE)
1391 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1393 return CONNECTION_ERROR_NONE;
1396 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1399 int address_family = 0;
1401 address_family = AF_INET6;
1403 if (strncmp(host_address, "fe80:", 5) == 0 ||
1404 strncmp(host_address, "ff00:", 5) == 0 ||
1405 strncmp(host_address, "::", 2) == 0) {
1406 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1407 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1410 rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1411 if (rv == NET_ERR_ACCESS_DENIED) {
1412 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1413 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1414 } else if (rv != NET_ERR_NONE)
1415 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1417 return CONNECTION_ERROR_NONE;
1420 int _connection_libnet_add_route_entry(connection_address_family_e address_family,
1421 const char *interface_name, const char *host_address, const char *gateway)
1424 char *endstr = NULL;
1425 int address_family_type = 0;
1427 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1428 address_family_type = AF_INET;
1430 address_family_type = AF_INET6;
1432 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1434 endstr = strrchr(host_address, '.');
1435 if (endstr == NULL ||
1436 strcmp(endstr, ".0") == 0 ||
1437 strncmp(host_address, "0.", 2) == 0 ||
1438 strstr(host_address, "255") != NULL) {
1439 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1440 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1443 rv = net_add_route_entry(host_address, interface_name, address_family_type, gateway);
1444 if (rv == NET_ERR_ACCESS_DENIED) {
1445 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1446 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1447 } else if (rv != NET_ERR_NONE)
1448 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1452 if (strncmp(host_address, "fe80:", 5) == 0 ||
1453 strncmp(host_address, "ff00:", 5) == 0 ||
1454 strncmp(host_address, "::", 2) == 0) {
1455 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1456 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1459 rv = net_add_route_ipv6(host_address, interface_name, address_family_type, gateway);
1460 if (rv == NET_ERR_ACCESS_DENIED) {
1461 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1462 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1463 } else if (rv != NET_ERR_NONE)
1464 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1467 return CONNECTION_ERROR_NONE;
1470 int _connection_libnet_remove_route_entry(connection_address_family_e address_family,
1471 const char *interface_name, const char *host_address, const char *gateway)
1474 char *endstr = strrchr(host_address, '.');
1475 int address_family_type = 0;
1477 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1478 address_family_type = AF_INET;
1480 address_family_type = AF_INET6;
1482 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1483 endstr = strrchr(host_address, '.');
1484 if (endstr == NULL ||
1485 strcmp(endstr, ".0") == 0 ||
1486 strncmp(host_address, "0.", 2) == 0 ||
1487 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1488 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1489 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1492 rv = net_remove_route_entry(host_address, interface_name, address_family_type, gateway);
1493 if (rv == NET_ERR_ACCESS_DENIED) {
1494 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1495 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1496 } else if (rv != NET_ERR_NONE)
1497 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1501 if (strncmp(host_address, "fe80:", 5) == 0 ||
1502 strncmp(host_address, "ff00:", 5) == 0 ||
1503 strncmp(host_address, "::", 2) == 0) {
1504 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1505 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1508 rv = net_remove_route_ipv6(host_address, interface_name, address_family_type, gateway);
1509 if (rv == NET_ERR_ACCESS_DENIED) {
1510 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1511 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1512 } else if (rv != NET_ERR_NONE)
1513 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1516 return CONNECTION_ERROR_NONE;
1519 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1521 prof_handle_list = g_slist_append(prof_handle_list, profile);
1524 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1526 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1530 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1531 connection_profile_state_changed_cb callback, void *user_data)
1533 net_profile_info_t *profile_info = profile;
1534 char *profile_name = g_strdup(profile_info->ProfileName);
1536 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1537 if (profile_cb_info == NULL) {
1538 g_free(profile_name); //LCOV_EXCL_LINE
1539 return false; //LCOV_EXCL_LINE
1542 profile_cb_info->callback = callback;
1543 profile_cb_info->user_data = user_data;
1544 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1546 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1551 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1553 net_profile_info_t *profile_info = profile;
1555 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1558 return false; //LCOV_EXCL_LINE
1561 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1564 rv = net_set_statistics(device_type, statistics_type);
1565 if (rv == NET_ERR_ACCESS_DENIED) {
1566 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1567 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1568 } else if (rv != NET_ERR_NONE)
1569 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1571 return CONNECTION_ERROR_NONE;
1574 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1577 rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1578 if (rv == NET_ERR_ACCESS_DENIED) {
1579 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1580 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1581 } else if (rv != NET_ERR_NONE)
1582 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1584 return CONNECTION_ERROR_NONE;
1587 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1588 connection_cellular_subscriber_id_e sim_id)
1590 char *modem_path = NULL;
1591 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1593 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1594 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id); //LCOV_EXCL_LINE
1595 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1599 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path"); //LCOV_EXCL_LINE
1600 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1603 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1604 NET_PROFILE_NAME_LEN_MAX);
1607 return CONNECTION_ERROR_NONE;
1610 static void __connection_idle_destroy_cb(gpointer data)
1615 managed_idler_list = g_slist_remove(managed_idler_list, data);
1619 static gboolean __connection_idle_cb(gpointer user_data)
1621 struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1626 return data->func(data->user_data);
1629 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1632 struct managed_idle_data *data;
1633 GMainContext *context;
1639 data = g_try_new0(struct managed_idle_data, 1);
1644 data->user_data = user_data;
1646 context = g_main_context_get_thread_default();
1647 src = g_idle_source_new();
1648 g_source_set_callback(src, __connection_idle_cb, data,
1649 __connection_idle_destroy_cb);
1650 id = g_source_attach(src, context);
1651 g_source_unref(src);
1659 managed_idler_list = g_slist_append(managed_idler_list, data);
1664 void _connection_callback_cleanup(void)
1666 GSList *cur = managed_idler_list;
1668 struct managed_idle_data *data;
1672 GSList *next = cur->next;
1673 data = (struct managed_idle_data *)cur->data;
1675 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1677 g_source_destroy(src);
1678 cur = managed_idler_list;
1684 g_slist_free(managed_idler_list);
1685 managed_idler_list = NULL;
1688 int _connection_libnet_check_get_privilege()
1692 rv = net_check_get_privilege();
1693 if (rv == NET_ERR_ACCESS_DENIED) {
1694 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1695 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1696 } else if (rv != NET_ERR_NONE)
1697 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1699 return CONNECTION_ERROR_NONE;
1702 int _connection_libnet_check_profile_privilege()
1706 rv = net_check_profile_privilege();
1707 if (rv == NET_ERR_ACCESS_DENIED) {
1708 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1709 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1710 } else if (rv != NET_ERR_NONE)
1711 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1713 return CONNECTION_ERROR_NONE;
1716 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1718 if (!connection_is_feature_checked[feature]) {
1719 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1720 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
1721 set_last_result(CONNECTION_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
1722 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1724 connection_is_feature_checked[feature] = true;
1726 return connection_feature_supported[feature];
1729 int _connection_check_feature_supported(const char *feature_name, ...)
1734 bool feature_supported = false;
1736 va_start(list, feature_name);
1739 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1740 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1741 if (strcmp(key, WIFI_FEATURE) == 0)
1742 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1743 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1744 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1745 if (strcmp(key, ETHERNET_FEATURE) == 0)
1746 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1748 feature_supported |= value;
1749 key = va_arg(list, const char *);
1752 if (!feature_supported) {
1753 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1754 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1756 return CONNECTION_ERROR_NOT_SUPPORTED;
1760 set_last_result(CONNECTION_ERROR_NONE);
1761 return CONNECTION_ERROR_NONE;
1764 int _connection_libnet_start_tcpdump(void)
1766 connection_error_e result = CONNECTION_ERROR_NONE;
1767 net_err_t ret = NET_ERR_NONE;
1769 ret = net_start_tcpdump();
1770 result = __libnet_convert_to_cp_error_type(ret);
1775 int _connection_libnet_stop_tcpdump(void)
1777 connection_error_e result = CONNECTION_ERROR_NONE;
1778 net_err_t ret = NET_ERR_NONE;
1780 ret = net_stop_tcpdump();
1781 result = __libnet_convert_to_cp_error_type(ret);
1786 int _connection_libnet_get_tcpdump_state(gboolean *tcpdump_state)
1788 connection_error_e result = CONNECTION_ERROR_NONE;
1789 net_err_t ret = NET_ERR_NONE;
1791 ret = net_get_tcpdump_state(tcpdump_state);
1792 result = __libnet_convert_to_cp_error_type(ret);