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 void *opened_user_data;
49 void *closed_user_data;
50 void *set_default_user_data;
51 void *reset_profile_user_data;
55 struct _state_notify {
56 connection_profile_state_changed_cb callback;
57 connection_profile_state_e state;
61 struct managed_idle_data {
67 static __thread struct _profile_list_s profile_iterator = {0, 0, NULL};
68 static __thread struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
69 static __thread GSList *managed_idler_list = NULL;
71 bool _connection_is_created(void)
73 return libnet.is_created;
76 static void __connection_set_created(bool tag)
78 libnet.is_created = tag;
81 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
85 return CONNECTION_ERROR_NONE;
86 case NET_ERR_APP_ALREADY_REGISTERED:
87 return CONNECTION_ERROR_INVALID_OPERATION;
88 case NET_ERR_APP_NOT_REGISTERED:
89 return CONNECTION_ERROR_INVALID_OPERATION;
90 case NET_ERR_NO_ACTIVE_CONNECTIONS:
91 return CONNECTION_ERROR_NO_CONNECTION;
92 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
93 return CONNECTION_ERROR_ALREADY_EXISTS;
94 case NET_ERR_CONNECTION_DHCP_FAILED:
95 return CONNECTION_ERROR_DHCP_FAILED;
96 case NET_ERR_CONNECTION_INVALID_KEY:
97 return CONNECTION_ERROR_INVALID_KEY;
98 case NET_ERR_IN_PROGRESS:
99 return CONNECTION_ERROR_NOW_IN_PROGRESS;
100 case NET_ERR_OPERATION_ABORTED:
101 return CONNECTION_ERROR_OPERATION_ABORTED;
102 case NET_ERR_TIME_OUT:
103 return CONNECTION_ERROR_NO_REPLY;
104 case NET_ERR_ACCESS_DENIED:
105 return CONNECTION_ERROR_PERMISSION_DENIED;
107 return CONNECTION_ERROR_OPERATION_FAILED;
111 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
114 case CONNECTION_ERROR_NONE:
116 case CONNECTION_ERROR_INVALID_PARAMETER:
117 return "INVALID_PARAMETER";
118 case CONNECTION_ERROR_OUT_OF_MEMORY:
119 return "OUT_OF_MEMORY";
120 case CONNECTION_ERROR_INVALID_OPERATION:
121 return "INVALID_OPERATION";
122 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
123 return "ADDRESS_FAMILY_NOT_SUPPORTED";
124 case CONNECTION_ERROR_OPERATION_FAILED:
125 return "OPERATION_FAILED";
126 case CONNECTION_ERROR_ITERATOR_END:
127 return "ITERATOR_END";
128 case CONNECTION_ERROR_NO_CONNECTION:
129 return "NO_CONNECTION";
130 case CONNECTION_ERROR_NOW_IN_PROGRESS:
131 return "NOW_IN_PROGRESS";
132 case CONNECTION_ERROR_ALREADY_EXISTS:
133 return "ALREADY_EXISTS";
134 case CONNECTION_ERROR_OPERATION_ABORTED:
135 return "OPERATION_ABORTED";
136 case CONNECTION_ERROR_DHCP_FAILED:
137 return "DHCP_FAILED";
138 case CONNECTION_ERROR_INVALID_KEY:
139 return "INVALID_KEY";
140 case CONNECTION_ERROR_NO_REPLY:
142 case CONNECTION_ERROR_PERMISSION_DENIED:
143 return "PERMISSION_DENIED";
144 case CONNECTION_ERROR_NOT_SUPPORTED:
145 return "NOT_SUPPORTED";
151 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
154 case CONNECTION_PROFILE_STATE_DISCONNECTED:
155 return "DISCONNECTED";
156 case CONNECTION_PROFILE_STATE_ASSOCIATION:
157 return "ASSOCIATION";
158 case CONNECTION_PROFILE_STATE_CONFIGURATION:
159 return "CONFIGURATION";
160 case CONNECTION_PROFILE_STATE_CONNECTED:
167 static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
169 if (user_cb != NULL) {
170 libnet.reset_profile_cb = user_cb;
171 libnet.reset_profile_user_data = user_data;
175 static gboolean __libnet_reset_profile_cb_idle(gpointer data)
177 connection_error_e result = (connection_error_e)data;
179 if (libnet.reset_profile_cb != NULL)
180 libnet.reset_profile_cb(result, libnet.reset_profile_user_data);
182 libnet.reset_profile_cb = NULL;
183 libnet.reset_profile_user_data = NULL;
188 static void __libnet_reset_profile_cb(connection_error_e result)
190 if (_connection_is_created() != true) {
191 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
192 "If multi-threaded, thread integrity be broken.");
196 if (libnet.reset_profile_cb != NULL)
197 _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
200 static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
202 if (user_cb != NULL) {
203 libnet.opened_cb = user_cb;
204 libnet.opened_user_data = user_data;
208 static gboolean __libnet_opened_cb_idle(gpointer data)
210 connection_error_e result = (connection_error_e)data;
212 if (libnet.opened_cb != NULL)
213 libnet.opened_cb(result, libnet.opened_user_data);
215 libnet.opened_cb = NULL;
216 libnet.opened_user_data = NULL;
221 static void __libnet_opened_cb(connection_error_e result)
223 if (_connection_is_created() != true) {
224 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
225 "If multi-threaded, thread integrity be broken.");
229 if (libnet.opened_cb != NULL)
230 _connection_callback_add(__libnet_opened_cb_idle, (gpointer)result);
233 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
235 if (user_cb != NULL) {
236 libnet.closed_cb = user_cb;
237 libnet.closed_user_data = user_data;
241 static gboolean __libnet_closed_cb_idle(gpointer data)
243 connection_error_e result = (connection_error_e)data;
245 if (libnet.closed_cb != NULL)
246 libnet.closed_cb(result, libnet.closed_user_data);
248 libnet.closed_cb = NULL;
249 libnet.closed_user_data = NULL;
254 static void __libnet_closed_cb(connection_error_e result)
256 if (_connection_is_created() != true) {
257 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
258 "If multi-threaded, thread integrity be broken.");
262 if (libnet.closed_cb != NULL)
263 _connection_callback_add(__libnet_closed_cb_idle, (gpointer)result);
266 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
268 if (user_cb != NULL) {
269 libnet.set_default_cb = user_cb;
270 libnet.set_default_user_data = user_data;
274 static gboolean __libnet_default_cb_idle(gpointer data)
276 connection_error_e result = (connection_error_e)data;
278 if (libnet.set_default_cb != NULL)
279 libnet.set_default_cb(result, libnet.set_default_user_data);
281 libnet.set_default_cb = NULL;
282 libnet.set_default_user_data = NULL;
287 static void __libnet_default_cb(connection_error_e result)
289 if (_connection_is_created() != true) {
290 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
291 "If multi-threaded, thread integrity be broken.");
295 if (libnet.set_default_cb != NULL)
296 _connection_callback_add(__libnet_default_cb_idle, (gpointer)result);
299 static void __libnet_set_ethernet_cable_state_changed_cb(
300 libnet_ethernet_cable_state_changed_cb user_cb)
302 libnet.ethernet_cable_state_changed_cb = user_cb;
305 static void __libnet_ethernet_cable_state_changed_cb(
306 connection_ethernet_cable_state_e state)
308 if (libnet.ethernet_cable_state_changed_cb)
309 libnet.ethernet_cable_state_changed_cb(state);
312 static gboolean __libnet_state_changed_cb_idle(gpointer data)
314 struct _state_notify *notify = (struct _state_notify *)data;
319 if (notify->callback != NULL)
320 notify->callback(notify->state, notify->user_data);
327 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
330 struct _state_notify *notify;
331 struct _profile_cb_s *cb_info;
333 if (_connection_is_created() != true) {
334 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
335 "If multi-threaded, thread integrity be broken.");
339 if (profile_name == NULL)
342 cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
346 if (cb_info->state == state)
349 cb_info->state = state;
351 if (state < 0 || cb_info->callback == NULL)
354 notify = g_try_new0(struct _state_notify, 1);
358 notify->callback = cb_info->callback;
359 notify->state = state;
360 notify->user_data = cb_info->user_data;
362 id = _connection_callback_add(__libnet_state_changed_cb_idle,
368 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
370 if (profile_list->count > 0)
371 g_free(profile_list->profiles);
373 profile_list->count = 0;
374 profile_list->next = 0;
375 profile_list->profiles = NULL;
378 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
380 bool is_requested = false;
381 connection_error_e result = CONNECTION_ERROR_NONE;
383 switch (event_cb->Event) {
384 case NET_EVENT_OPEN_RSP:
387 case NET_EVENT_OPEN_IND:
388 result = __libnet_convert_to_cp_error_type(event_cb->Error);
389 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
390 (is_requested) ? "RSP":"IND",
391 __libnet_convert_cp_error_type_to_string(result));
394 __libnet_opened_cb(result);
396 switch (event_cb->Error) {
398 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
399 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
401 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
404 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
405 __libnet_convert_cp_error_type_to_string(result));
408 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
411 case NET_EVENT_CLOSE_RSP:
414 case NET_EVENT_CLOSE_IND:
415 result = __libnet_convert_to_cp_error_type(event_cb->Error);
416 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
417 (is_requested) ? "RSP":"IND",
418 __libnet_convert_cp_error_type_to_string(result));
421 __libnet_closed_cb(result);
423 switch (event_cb->Error) {
425 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
427 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
430 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
431 __libnet_convert_cp_error_type_to_string(result));
435 case NET_EVENT_NET_STATE_IND:
436 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
438 if (event_cb->Datalength != sizeof(net_state_type_t))
441 net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
442 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
444 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
445 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
447 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
450 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
451 result = __libnet_convert_to_cp_error_type(event_cb->Error);
452 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
453 __libnet_default_cb(result);
456 case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
457 result = __libnet_convert_to_cp_error_type(event_cb->Error);
458 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
459 __libnet_reset_profile_cb(result);
461 case NET_EVENT_ETHERNET_CABLE_ATTACHED:
462 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
463 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED);
465 case NET_EVENT_ETHERNET_CABLE_DETACHED:
466 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
467 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED);
475 static int __libnet_check_address_type(int address_family, const char *address)
480 err = inet_pton(address_family, address, &buf);
487 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
492 for (;i < profile_list->count;i++) {
493 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
494 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
501 void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
505 for (;i < source->count;i++) {
506 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
507 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
508 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
514 int __libnet_get_default_count(struct _profile_list_s *profile_list)
519 for (;i < profile_list->count;i++) {
520 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
527 void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
531 for (;i < source->count;i++) {
532 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
533 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
539 int _connection_libnet_init(void)
543 if (_connection_is_created() != true) {
544 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
545 if (rv != NET_ERR_NONE)
548 __connection_set_created(true);
550 if (profile_cb_table == NULL)
551 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
557 bool _connection_libnet_deinit(void)
559 if (_connection_is_created() == true) {
560 if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
563 __connection_set_created(false);
565 if (profile_cb_table) {
566 g_hash_table_destroy(profile_cb_table);
567 profile_cb_table = NULL;
570 __libnet_clear_profile_list(&profile_iterator);
572 if (prof_handle_list) {
573 g_slist_free_full(prof_handle_list, g_free);
574 prof_handle_list = NULL;
581 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
589 for (list = prof_handle_list; list; list = list->next)
590 if (profile == list->data) return true;
592 for (;i < profile_iterator.count;i++)
593 if (profile == &profile_iterator.profiles[i]) return true;
598 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
600 struct _profile_cb_s *cb_info;
601 net_profile_info_t *profile_info = profile;
606 cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
614 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
617 net_wifi_state_t wlan_state;
618 net_profile_name_t profile_name;
620 rv = net_get_wifi_state(&wlan_state, &profile_name);
621 if (rv == NET_ERR_ACCESS_DENIED) {
622 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
623 return CONNECTION_ERROR_PERMISSION_DENIED;
624 } else if (rv != NET_ERR_NONE) {
625 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
626 return CONNECTION_ERROR_OPERATION_FAILED;
629 switch (wlan_state) {
631 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
634 case WIFI_ASSOCIATION:
635 case WIFI_CONFIGURATION:
636 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
639 case WIFI_DISCONNECTING:
640 *state = CONNECTION_WIFI_STATE_CONNECTED;
643 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state");
644 return CONNECTION_ERROR_INVALID_OPERATION;
647 return CONNECTION_ERROR_NONE;
650 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
653 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
654 rv = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
655 if (rv == NET_ERR_ACCESS_DENIED) {
656 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
657 return CONNECTION_ERROR_PERMISSION_DENIED;
660 if (ethernet_profiles.count == 0) {
661 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
662 return CONNECTION_ERROR_NONE;
665 switch (ethernet_profiles.profiles->ProfileState) {
666 case NET_STATE_TYPE_ONLINE:
667 case NET_STATE_TYPE_READY:
668 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
670 case NET_STATE_TYPE_IDLE:
671 case NET_STATE_TYPE_FAILURE:
672 case NET_STATE_TYPE_ASSOCIATION:
673 case NET_STATE_TYPE_CONFIGURATION:
674 case NET_STATE_TYPE_DISCONNECT:
675 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
678 __libnet_clear_profile_list(ðernet_profiles);
679 return CONNECTION_ERROR_OPERATION_FAILED;
682 __libnet_clear_profile_list(ðernet_profiles);
684 return CONNECTION_ERROR_NONE;
687 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
692 rv = net_get_ethernet_cable_state(&status);
693 if (rv == NET_ERR_ACCESS_DENIED) {
694 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
695 return CONNECTION_ERROR_PERMISSION_DENIED;
696 } else if (rv != NET_ERR_NONE) {
697 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
698 return CONNECTION_ERROR_OPERATION_FAILED;
702 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
704 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
705 return CONNECTION_ERROR_NONE;
708 int _connection_libnet_set_ethernet_cable_state_changed_cb(
709 libnet_ethernet_cable_state_changed_cb callback)
711 __libnet_set_ethernet_cable_state_changed_cb(callback);
713 return CONNECTION_ERROR_NONE;
716 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
720 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
721 rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
722 if (rv == NET_ERR_ACCESS_DENIED) {
723 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
724 return CONNECTION_ERROR_PERMISSION_DENIED;
727 if (bluetooth_profiles.count == 0) {
728 *state = CONNECTION_BT_STATE_DEACTIVATED;
729 return CONNECTION_ERROR_NONE;
732 for (; i < bluetooth_profiles.count; i++) {
733 switch (bluetooth_profiles.profiles[i].ProfileState) {
734 case NET_STATE_TYPE_ONLINE:
735 case NET_STATE_TYPE_READY:
736 *state = CONNECTION_BT_STATE_CONNECTED;
738 case NET_STATE_TYPE_IDLE:
739 case NET_STATE_TYPE_FAILURE:
740 case NET_STATE_TYPE_ASSOCIATION:
741 case NET_STATE_TYPE_CONFIGURATION:
742 case NET_STATE_TYPE_DISCONNECT:
743 *state = CONNECTION_BT_STATE_DISCONNECTED;
746 __libnet_clear_profile_list(&bluetooth_profiles);
747 return CONNECTION_ERROR_OPERATION_FAILED;
752 __libnet_clear_profile_list(&bluetooth_profiles);
754 return CONNECTION_ERROR_NONE;
757 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
760 int rv1, rv2, rv3, rv4;
761 net_profile_info_t *profiles = NULL;
763 struct _profile_list_s wifi_profiles = {0, 0, NULL};
764 struct _profile_list_s cellular_profiles = {0, 0, NULL};
765 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
766 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
768 __libnet_clear_profile_list(&profile_iterator);
770 rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
771 if (rv1 == NET_ERR_ACCESS_DENIED) {
772 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
773 return CONNECTION_ERROR_PERMISSION_DENIED;
774 } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
775 return CONNECTION_ERROR_OPERATION_FAILED;
777 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
779 rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
780 if (rv2 == NET_ERR_ACCESS_DENIED) {
781 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
782 __libnet_clear_profile_list(&wifi_profiles);
783 return CONNECTION_ERROR_PERMISSION_DENIED;
784 } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
785 __libnet_clear_profile_list(&wifi_profiles);
786 return CONNECTION_ERROR_OPERATION_FAILED;
788 CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
790 rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
791 if (rv3 == NET_ERR_ACCESS_DENIED) {
792 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
793 __libnet_clear_profile_list(&wifi_profiles);
794 __libnet_clear_profile_list(&cellular_profiles);
795 return CONNECTION_ERROR_PERMISSION_DENIED;
796 } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
797 __libnet_clear_profile_list(&wifi_profiles);
798 __libnet_clear_profile_list(&cellular_profiles);
799 return CONNECTION_ERROR_OPERATION_FAILED;
801 CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
803 rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
804 if (rv4 == NET_ERR_ACCESS_DENIED) {
805 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
806 __libnet_clear_profile_list(&wifi_profiles);
807 __libnet_clear_profile_list(&cellular_profiles);
808 __libnet_clear_profile_list(ðernet_profiles);
809 return CONNECTION_ERROR_PERMISSION_DENIED;
810 } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
811 __libnet_clear_profile_list(&wifi_profiles);
812 __libnet_clear_profile_list(&cellular_profiles);
813 __libnet_clear_profile_list(ðernet_profiles);
814 return CONNECTION_ERROR_OPERATION_FAILED;
816 CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
818 *profile_iter_h = &profile_iterator;
821 case CONNECTION_ITERATOR_TYPE_REGISTERED:
822 count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count;
823 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
825 return CONNECTION_ERROR_NONE;
827 profiles = g_try_new0(net_profile_info_t, count);
828 if (profiles == NULL) {
829 __libnet_clear_profile_list(&wifi_profiles);
830 __libnet_clear_profile_list(&cellular_profiles);
831 __libnet_clear_profile_list(ðernet_profiles);
832 __libnet_clear_profile_list(&bluetooth_profiles);
833 return CONNECTION_ERROR_OUT_OF_MEMORY;
836 profile_iterator.profiles = profiles;
838 if (wifi_profiles.count > 0) {
839 memcpy(profiles, wifi_profiles.profiles,
840 sizeof(net_profile_info_t) * wifi_profiles.count);
841 profiles += wifi_profiles.count;
844 if (cellular_profiles.count > 0) {
845 memcpy(profiles, cellular_profiles.profiles,
846 sizeof(net_profile_info_t) * cellular_profiles.count);
847 profiles += cellular_profiles.count;
850 if (ethernet_profiles.count > 0) {
851 memcpy(profiles, ethernet_profiles.profiles,
852 sizeof(net_profile_info_t) * ethernet_profiles.count);
853 profiles += ethernet_profiles.count;
856 if (bluetooth_profiles.count > 0)
857 memcpy(profiles, bluetooth_profiles.profiles,
858 sizeof(net_profile_info_t) * bluetooth_profiles.count);
861 case CONNECTION_ITERATOR_TYPE_CONNECTED:
862 count = __libnet_get_connected_count(&wifi_profiles);
863 count += __libnet_get_connected_count(&cellular_profiles);
864 count += __libnet_get_connected_count(ðernet_profiles);
865 count += __libnet_get_connected_count(&bluetooth_profiles);
866 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
868 return CONNECTION_ERROR_NONE;
870 profiles = g_try_new0(net_profile_info_t, count);
871 if (profiles == NULL) {
872 __libnet_clear_profile_list(&wifi_profiles);
873 __libnet_clear_profile_list(&cellular_profiles);
874 __libnet_clear_profile_list(ðernet_profiles);
875 __libnet_clear_profile_list(&bluetooth_profiles);
876 return CONNECTION_ERROR_OUT_OF_MEMORY;
879 profile_iterator.profiles = profiles;
881 if (wifi_profiles.count > 0)
882 __libnet_copy_connected_profile(&profiles, &wifi_profiles);
884 if (cellular_profiles.count > 0)
885 __libnet_copy_connected_profile(&profiles, &cellular_profiles);
887 if (ethernet_profiles.count > 0)
888 __libnet_copy_connected_profile(&profiles, ðernet_profiles);
890 if (bluetooth_profiles.count > 0)
891 __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
894 case CONNECTION_ITERATOR_TYPE_DEFAULT:
895 count = __libnet_get_default_count(&cellular_profiles);
896 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count);
898 return CONNECTION_ERROR_NONE;
900 profiles = g_try_new0(net_profile_info_t, count);
901 if (profiles == NULL) {
902 __libnet_clear_profile_list(&wifi_profiles);
903 __libnet_clear_profile_list(&cellular_profiles);
904 __libnet_clear_profile_list(ðernet_profiles);
905 __libnet_clear_profile_list(&bluetooth_profiles);
906 return CONNECTION_ERROR_OUT_OF_MEMORY;
909 profile_iterator.profiles = profiles;
911 if (cellular_profiles.count > 0)
912 __libnet_copy_default_profile(&profiles, &cellular_profiles);
916 __libnet_clear_profile_list(&wifi_profiles);
917 __libnet_clear_profile_list(&cellular_profiles);
918 __libnet_clear_profile_list(ðernet_profiles);
919 __libnet_clear_profile_list(&bluetooth_profiles);
921 profile_iterator.count = count;
923 return CONNECTION_ERROR_NONE;
926 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
928 if (profile_iter_h != &profile_iterator)
929 return CONNECTION_ERROR_INVALID_PARAMETER;
931 if (profile_iterator.count <= profile_iterator.next)
932 return CONNECTION_ERROR_ITERATOR_END;
934 *profile = &profile_iterator.profiles[profile_iterator.next];
935 profile_iterator.next++;
937 return CONNECTION_ERROR_NONE;
940 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
942 if (profile_iter_h != &profile_iterator)
945 if (profile_iterator.count <= profile_iterator.next)
951 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
953 if (profile_iter_h != &profile_iterator)
954 return CONNECTION_ERROR_INVALID_PARAMETER;
956 __libnet_clear_profile_list(&profile_iterator);
958 return CONNECTION_ERROR_NONE;
961 int _connection_libnet_get_current_profile(connection_profile_h *profile)
963 net_profile_info_t active_profile;
966 rv = net_get_active_net_info(&active_profile);
967 if (rv == NET_ERR_NO_SERVICE)
968 return CONNECTION_ERROR_NO_CONNECTION;
969 else if (rv == NET_ERR_ACCESS_DENIED) {
970 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
971 return CONNECTION_ERROR_PERMISSION_DENIED;
972 } else if (rv != NET_ERR_NONE)
973 return CONNECTION_ERROR_OPERATION_FAILED;
975 *profile = g_try_malloc0(sizeof(net_profile_info_t));
976 if (*profile == NULL)
977 return CONNECTION_ERROR_OUT_OF_MEMORY;
979 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
980 prof_handle_list = g_slist_append(prof_handle_list, *profile);
982 return CONNECTION_ERROR_NONE;
985 int _connection_libnet_reset_profile(connection_reset_option_e type,
986 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
990 rv = net_reset_profile(type, id);
991 if (rv == NET_ERR_ACCESS_DENIED) {
992 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
993 return CONNECTION_ERROR_PERMISSION_DENIED;
994 } else if (rv != NET_ERR_NONE) {
995 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
996 return CONNECTION_ERROR_OPERATION_FAILED;
999 __libnet_set_reset_profile_cb(callback, user_data);
1001 return CONNECTION_ERROR_NONE;
1004 int _connection_libnet_open_profile(connection_profile_h profile,
1005 connection_opened_cb callback, void* user_data)
1009 if (!(_connection_libnet_check_profile_validity(profile))) {
1010 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1011 return CONNECTION_ERROR_INVALID_PARAMETER;
1014 net_profile_info_t *profile_info = profile;
1016 rv = net_open_connection_with_profile(profile_info->ProfileName);
1017 if (rv == NET_ERR_ACCESS_DENIED) {
1018 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1019 return CONNECTION_ERROR_PERMISSION_DENIED;
1020 } else if (rv != NET_ERR_NONE)
1021 return CONNECTION_ERROR_OPERATION_FAILED;
1023 __libnet_set_opened_cb(callback, user_data);
1025 return CONNECTION_ERROR_NONE;
1028 int _connection_libnet_get_cellular_service_profile(
1029 connection_cellular_service_type_e type, connection_profile_h *profile)
1032 int rv = NET_ERR_NONE;
1033 #if defined TIZEN_DUALSIM_ENABLE
1034 int default_subscriber_id = 0;
1035 char subscriber_id[3];
1038 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
1039 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
1041 rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
1042 if (rv == NET_ERR_ACCESS_DENIED) {
1043 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1044 return CONNECTION_ERROR_PERMISSION_DENIED;
1045 } else if (rv != NET_ERR_NONE) {
1046 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
1047 return CONNECTION_ERROR_OPERATION_FAILED;
1050 #if defined TIZEN_DUALSIM_ENABLE
1051 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
1052 &default_subscriber_id) != 0) {
1053 CONNECTION_LOG(CONNECTION_ERROR,
1054 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
1055 __libnet_clear_profile_list(&cellular_profiles);
1056 return CONNECTION_ERROR_OPERATION_FAILED;
1059 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
1062 for (i = 0; i < cellular_profiles.count; i++)
1063 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
1064 #if defined TIZEN_DUALSIM_ENABLE
1065 if (g_str_has_suffix(
1066 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
1067 subscriber_id) == TRUE)
1071 if (i >= cellular_profiles.count) {
1072 __libnet_clear_profile_list(&cellular_profiles);
1073 return CONNECTION_ERROR_OPERATION_FAILED;
1076 *profile = g_try_malloc0(sizeof(net_profile_info_t));
1077 if (*profile == NULL) {
1078 __libnet_clear_profile_list(&cellular_profiles);
1079 return CONNECTION_ERROR_OUT_OF_MEMORY;
1082 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
1084 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
1087 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
1088 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
1091 for (j = 0; j < cellular_profiles.count; j++) {
1095 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
1098 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
1099 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
1105 __libnet_clear_profile_list(&cellular_profiles);
1106 prof_handle_list = g_slist_append(prof_handle_list, *profile);
1108 return CONNECTION_ERROR_NONE;
1111 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
1115 if (!(_connection_libnet_check_profile_validity(profile))) {
1116 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1117 return CONNECTION_ERROR_INVALID_PARAMETER;
1120 net_profile_info_t *profile_info = profile;
1121 connection_cellular_service_type_e service_type;
1123 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1125 if (service_type != type)
1126 return CONNECTION_ERROR_INVALID_PARAMETER;
1128 rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
1129 if (rv == NET_ERR_ACCESS_DENIED) {
1130 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1131 return CONNECTION_ERROR_PERMISSION_DENIED;
1132 } else if (rv != NET_ERR_NONE)
1133 return CONNECTION_ERROR_OPERATION_FAILED;
1135 return CONNECTION_ERROR_NONE;
1138 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
1139 connection_profile_h profile, connection_set_default_cb callback, void* user_data)
1143 if (!(_connection_libnet_check_profile_validity(profile))) {
1144 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1145 return CONNECTION_ERROR_INVALID_PARAMETER;
1148 net_profile_info_t *profile_info = profile;
1149 connection_cellular_service_type_e service_type;
1151 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1153 if (service_type != type)
1154 return CONNECTION_ERROR_INVALID_PARAMETER;
1156 rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
1157 if (rv == NET_ERR_ACCESS_DENIED) {
1158 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1159 return CONNECTION_ERROR_PERMISSION_DENIED;
1160 } else if (rv != NET_ERR_NONE)
1161 return CONNECTION_ERROR_OPERATION_FAILED;
1163 __libnet_set_default_cb(callback, user_data);
1165 return CONNECTION_ERROR_NONE;
1168 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
1172 if (!(_connection_libnet_check_profile_validity(profile))) {
1173 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1174 return CONNECTION_ERROR_INVALID_PARAMETER;
1177 net_profile_info_t *profile_info = profile;
1179 rv = net_close_connection(profile_info->ProfileName);
1180 if (rv == NET_ERR_ACCESS_DENIED) {
1181 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1182 return CONNECTION_ERROR_PERMISSION_DENIED;
1183 } else if (rv != NET_ERR_NONE)
1184 return CONNECTION_ERROR_OPERATION_FAILED;
1186 __libnet_set_closed_cb(callback, user_data);
1188 return CONNECTION_ERROR_NONE;
1191 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
1194 char *endstr = NULL;
1195 int address_family = 0;
1197 if(__libnet_check_address_type(AF_INET, host_address))
1198 address_family = AF_INET;
1200 return CONNECTION_ERROR_INVALID_PARAMETER;
1202 switch(address_family) {
1204 endstr = strrchr(host_address, '.');
1205 if (endstr == NULL ||
1206 strcmp(endstr, ".0") == 0 ||
1207 strncmp(host_address, "0.", 2) == 0 ||
1208 strstr(host_address, "255") != NULL) {
1209 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1210 return CONNECTION_ERROR_INVALID_PARAMETER;
1214 return CONNECTION_ERROR_OPERATION_FAILED;
1217 rv = net_add_route(host_address, interface_name, address_family);
1218 if (rv == NET_ERR_ACCESS_DENIED) {
1219 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1220 return CONNECTION_ERROR_PERMISSION_DENIED;
1221 } else if (rv != NET_ERR_NONE)
1222 return CONNECTION_ERROR_OPERATION_FAILED;
1224 return CONNECTION_ERROR_NONE;
1227 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
1230 char *endstr = strrchr(host_address, '.');
1231 int address_family = 0;
1233 if (__libnet_check_address_type(AF_INET, host_address))
1234 address_family = AF_INET;
1236 return CONNECTION_ERROR_INVALID_PARAMETER;
1238 switch(address_family) {
1240 endstr = strrchr(host_address, '.');
1241 if (endstr == NULL ||
1242 strcmp(endstr, ".0") == 0 ||
1243 strncmp(host_address, "0.", 2) == 0 ||
1244 strstr(host_address, ".0.") != NULL ||strstr(host_address, "255") != NULL) {
1245 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
1246 return CONNECTION_ERROR_INVALID_PARAMETER;
1250 return CONNECTION_ERROR_OPERATION_FAILED;
1253 rv = net_remove_route(host_address, interface_name, address_family);
1254 if (rv == NET_ERR_ACCESS_DENIED) {
1255 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1256 return CONNECTION_ERROR_PERMISSION_DENIED;
1257 } else if (rv != NET_ERR_NONE)
1258 return CONNECTION_ERROR_OPERATION_FAILED;
1260 return CONNECTION_ERROR_NONE;
1263 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1266 int address_family = 0;
1268 address_family = AF_INET6;
1269 /* if(__libnet_check_address_type(AF_INET6, host_address))
1270 address_family = AF_INET6;
1272 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1274 switch(address_family) {
1276 if (strncmp(host_address, "fe80:", 5) == 0 ||
1277 strncmp(host_address, "ff00:", 5) == 0 ||
1278 strncmp(host_address, "::", 2) == 0) {
1279 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1280 return CONNECTION_ERROR_INVALID_PARAMETER;
1284 return CONNECTION_ERROR_OPERATION_FAILED;
1287 rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1288 if (rv == NET_ERR_ACCESS_DENIED) {
1289 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1290 return CONNECTION_ERROR_PERMISSION_DENIED;
1291 } else if (rv != NET_ERR_NONE)
1292 return CONNECTION_ERROR_OPERATION_FAILED;
1294 return CONNECTION_ERROR_NONE;
1297 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1300 int address_family = 0;
1302 address_family = AF_INET6;
1303 /* if (__libnet_check_address_type(AF_INET6, host_address))
1304 address_family = AF_INET6;
1306 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1308 switch(address_family) {
1310 if (strncmp(host_address, "fe80:", 5) == 0 ||
1311 strncmp(host_address, "ff00:", 5) == 0 ||
1312 strncmp(host_address, "::", 2) == 0) {
1313 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1314 return CONNECTION_ERROR_INVALID_PARAMETER;
1318 return CONNECTION_ERROR_OPERATION_FAILED;
1321 rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1322 if (rv == NET_ERR_ACCESS_DENIED) {
1323 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1324 return CONNECTION_ERROR_PERMISSION_DENIED;
1325 } else if (rv != NET_ERR_NONE)
1326 return CONNECTION_ERROR_OPERATION_FAILED;
1328 return CONNECTION_ERROR_NONE;
1331 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1333 prof_handle_list = g_slist_append(prof_handle_list, profile);
1336 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1338 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1342 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1343 connection_profile_state_changed_cb callback, void *user_data)
1345 net_profile_info_t *profile_info = profile;
1346 char *profile_name = g_strdup(profile_info->ProfileName);
1348 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1349 if (profile_cb_info == NULL) {
1350 g_free(profile_name);
1354 profile_cb_info->callback = callback;
1355 profile_cb_info->user_data = user_data;
1356 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1358 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1363 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1365 net_profile_info_t *profile_info = profile;
1367 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1373 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1376 rv = net_set_statistics(device_type, statistics_type);
1377 if (rv == NET_ERR_ACCESS_DENIED) {
1378 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1379 return CONNECTION_ERROR_PERMISSION_DENIED;
1380 } else if (rv != NET_ERR_NONE)
1381 return CONNECTION_ERROR_OPERATION_FAILED;
1383 return CONNECTION_ERROR_NONE;
1386 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1389 rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1390 if (rv == NET_ERR_ACCESS_DENIED) {
1391 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1392 return CONNECTION_ERROR_PERMISSION_DENIED;
1393 }else if (rv != NET_ERR_NONE)
1394 return CONNECTION_ERROR_OPERATION_FAILED;
1396 return CONNECTION_ERROR_NONE;
1399 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1400 connection_cellular_subscriber_id_e sim_id)
1402 char *modem_path = NULL;
1403 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1405 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1406 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
1407 return CONNECTION_ERROR_OPERATION_FAILED;
1411 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
1412 return CONNECTION_ERROR_OPERATION_FAILED;
1415 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1416 NET_PROFILE_NAME_LEN_MAX);
1419 return CONNECTION_ERROR_NONE;
1422 static void __connection_idle_destroy_cb(gpointer data)
1427 managed_idler_list = g_slist_remove(managed_idler_list, data);
1431 static gboolean __connection_idle_cb(gpointer user_data)
1433 struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1438 return data->func(data->user_data);
1441 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1444 struct managed_idle_data *data;
1449 data = g_try_new0(struct managed_idle_data, 1);
1454 data->user_data = user_data;
1456 id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
1457 __connection_idle_destroy_cb);
1465 managed_idler_list = g_slist_append(managed_idler_list, data);
1470 void _connection_callback_cleanup(void)
1472 GSList *cur = managed_idler_list;
1474 struct managed_idle_data *data;
1477 GSList *next = cur->next;
1478 data = (struct managed_idle_data *)cur->data;
1480 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1482 g_source_destroy(src);
1483 cur = managed_idler_list;
1488 g_slist_free(managed_idler_list);
1489 managed_idler_list = NULL;
1492 int _connection_libnet_check_get_privilege()
1496 rv = net_check_get_privilege();
1497 if (rv == NET_ERR_ACCESS_DENIED) {
1498 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1499 return CONNECTION_ERROR_PERMISSION_DENIED;
1500 } else if (rv != NET_ERR_NONE)
1501 return CONNECTION_ERROR_OPERATION_FAILED;
1503 return CONNECTION_ERROR_NONE;
1506 int _connection_libnet_check_profile_privilege()
1510 rv = net_check_profile_privilege();
1511 if (rv == NET_ERR_ACCESS_DENIED) {
1512 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1513 return CONNECTION_ERROR_PERMISSION_DENIED;
1514 } else if (rv != NET_ERR_NONE)
1515 return CONNECTION_ERROR_OPERATION_FAILED;
1517 return CONNECTION_ERROR_NONE;
1520 int _connection_check_feature_supported(const char *feature_name, ...)
1524 bool value, feature_supported = false;
1526 va_start(list, feature_name);
1529 if(system_info_get_platform_bool(key, &value) < 0) {
1530 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info");
1531 set_last_result(CONNECTION_ERROR_OPERATION_FAILED);
1532 return CONNECTION_ERROR_OPERATION_FAILED;
1534 SECURE_CONNECTION_LOG(CONNECTION_INFO, "%s feature is %s", key, (value?"true":"false"));
1535 feature_supported |= value;
1536 key = va_arg(list, const char *);
1539 if (!feature_supported) {
1540 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1541 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1542 return CONNECTION_ERROR_NOT_SUPPORTED;
1546 set_last_result(CONNECTION_ERROR_NONE);
1547 return CONNECTION_ERROR_NONE;