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;
70 static __thread bool connection_is_feature_checked[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
71 static __thread bool connection_feature_supported[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
73 bool _connection_is_created(void)
75 return libnet.is_created;
78 static void __connection_set_created(bool tag)
80 libnet.is_created = tag;
83 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
87 return CONNECTION_ERROR_NONE;
88 case NET_ERR_APP_ALREADY_REGISTERED:
89 return CONNECTION_ERROR_INVALID_OPERATION;
90 case NET_ERR_APP_NOT_REGISTERED:
91 return CONNECTION_ERROR_INVALID_OPERATION;
92 case NET_ERR_NO_ACTIVE_CONNECTIONS:
93 return CONNECTION_ERROR_NO_CONNECTION;
94 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
95 return CONNECTION_ERROR_ALREADY_EXISTS;
96 case NET_ERR_CONNECTION_DHCP_FAILED:
97 return CONNECTION_ERROR_DHCP_FAILED;
98 case NET_ERR_CONNECTION_INVALID_KEY:
99 return CONNECTION_ERROR_INVALID_KEY;
100 case NET_ERR_IN_PROGRESS:
101 return CONNECTION_ERROR_NOW_IN_PROGRESS;
102 case NET_ERR_OPERATION_ABORTED:
103 return CONNECTION_ERROR_OPERATION_ABORTED;
104 case NET_ERR_TIME_OUT:
105 return CONNECTION_ERROR_NO_REPLY;
106 case NET_ERR_ACCESS_DENIED:
107 return CONNECTION_ERROR_PERMISSION_DENIED;
109 return CONNECTION_ERROR_OPERATION_FAILED;
113 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
116 case CONNECTION_ERROR_NONE:
118 case CONNECTION_ERROR_INVALID_PARAMETER:
119 return "INVALID_PARAMETER";
120 case CONNECTION_ERROR_OUT_OF_MEMORY:
121 return "OUT_OF_MEMORY";
122 case CONNECTION_ERROR_INVALID_OPERATION:
123 return "INVALID_OPERATION";
124 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
125 return "ADDRESS_FAMILY_NOT_SUPPORTED";
126 case CONNECTION_ERROR_OPERATION_FAILED:
127 return "OPERATION_FAILED";
128 case CONNECTION_ERROR_ITERATOR_END:
129 return "ITERATOR_END";
130 case CONNECTION_ERROR_NO_CONNECTION:
131 return "NO_CONNECTION";
132 case CONNECTION_ERROR_NOW_IN_PROGRESS:
133 return "NOW_IN_PROGRESS";
134 case CONNECTION_ERROR_ALREADY_EXISTS:
135 return "ALREADY_EXISTS";
136 case CONNECTION_ERROR_OPERATION_ABORTED:
137 return "OPERATION_ABORTED";
138 case CONNECTION_ERROR_DHCP_FAILED:
139 return "DHCP_FAILED";
140 case CONNECTION_ERROR_INVALID_KEY:
141 return "INVALID_KEY";
142 case CONNECTION_ERROR_NO_REPLY:
144 case CONNECTION_ERROR_PERMISSION_DENIED:
145 return "PERMISSION_DENIED";
146 case CONNECTION_ERROR_NOT_SUPPORTED:
147 return "NOT_SUPPORTED";
153 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
156 case CONNECTION_PROFILE_STATE_DISCONNECTED:
157 return "DISCONNECTED";
158 case CONNECTION_PROFILE_STATE_ASSOCIATION:
159 return "ASSOCIATION";
160 case CONNECTION_PROFILE_STATE_CONFIGURATION:
161 return "CONFIGURATION";
162 case CONNECTION_PROFILE_STATE_CONNECTED:
169 static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
171 if (user_cb != NULL) {
172 libnet.reset_profile_cb = user_cb;
173 libnet.reset_profile_user_data = user_data;
177 static gboolean __libnet_reset_profile_cb_idle(gpointer data)
179 connection_error_e result = (connection_error_e)data;
181 if (libnet.reset_profile_cb != NULL)
182 libnet.reset_profile_cb(result, libnet.reset_profile_user_data);
184 libnet.reset_profile_cb = NULL;
185 libnet.reset_profile_user_data = NULL;
190 static void __libnet_reset_profile_cb(connection_error_e result)
192 if (_connection_is_created() != true) {
193 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
194 "If multi-threaded, thread integrity be broken.");
198 if (libnet.reset_profile_cb != NULL)
199 _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
202 static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
204 if (user_cb != NULL) {
205 libnet.opened_cb = user_cb;
206 libnet.opened_user_data = user_data;
210 static gboolean __libnet_opened_cb_idle(gpointer data)
212 connection_error_e result = (connection_error_e)data;
214 if (libnet.opened_cb != NULL)
215 libnet.opened_cb(result, libnet.opened_user_data);
217 libnet.opened_cb = NULL;
218 libnet.opened_user_data = NULL;
223 static void __libnet_opened_cb(connection_error_e result)
225 if (_connection_is_created() != true) {
226 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
227 "If multi-threaded, thread integrity be broken.");
231 if (libnet.opened_cb != NULL)
232 _connection_callback_add(__libnet_opened_cb_idle, (gpointer)result);
235 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
237 if (user_cb != NULL) {
238 libnet.closed_cb = user_cb;
239 libnet.closed_user_data = user_data;
243 static gboolean __libnet_closed_cb_idle(gpointer data)
245 connection_error_e result = (connection_error_e)data;
247 if (libnet.closed_cb != NULL)
248 libnet.closed_cb(result, libnet.closed_user_data);
250 libnet.closed_cb = NULL;
251 libnet.closed_user_data = NULL;
256 static void __libnet_closed_cb(connection_error_e result)
258 if (_connection_is_created() != true) {
259 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
260 "If multi-threaded, thread integrity be broken.");
264 if (libnet.closed_cb != NULL)
265 _connection_callback_add(__libnet_closed_cb_idle, (gpointer)result);
268 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
270 if (user_cb != NULL) {
271 libnet.set_default_cb = user_cb;
272 libnet.set_default_user_data = user_data;
276 static gboolean __libnet_default_cb_idle(gpointer data)
278 connection_error_e result = (connection_error_e)data;
280 if (libnet.set_default_cb != NULL)
281 libnet.set_default_cb(result, libnet.set_default_user_data);
283 libnet.set_default_cb = NULL;
284 libnet.set_default_user_data = NULL;
289 static void __libnet_default_cb(connection_error_e result)
291 if (_connection_is_created() != true) {
292 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
293 "If multi-threaded, thread integrity be broken.");
297 if (libnet.set_default_cb != NULL)
298 _connection_callback_add(__libnet_default_cb_idle, (gpointer)result);
301 static void __libnet_set_ethernet_cable_state_changed_cb(
302 libnet_ethernet_cable_state_changed_cb user_cb)
304 libnet.ethernet_cable_state_changed_cb = user_cb;
307 static void __libnet_ethernet_cable_state_changed_cb(
308 connection_ethernet_cable_state_e state)
310 if (libnet.ethernet_cable_state_changed_cb)
311 libnet.ethernet_cable_state_changed_cb(state);
314 static gboolean __libnet_state_changed_cb_idle(gpointer data)
316 struct _state_notify *notify = (struct _state_notify *)data;
321 if (notify->callback != NULL)
322 notify->callback(notify->state, notify->user_data);
329 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
332 struct _state_notify *notify;
333 struct _profile_cb_s *cb_info;
335 if (_connection_is_created() != true) {
336 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
337 "If multi-threaded, thread integrity be broken.");
341 if (profile_name == NULL)
344 cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
348 if (cb_info->state == state)
351 cb_info->state = state;
353 if (state < 0 || cb_info->callback == NULL)
356 notify = g_try_new0(struct _state_notify, 1);
360 notify->callback = cb_info->callback;
361 notify->state = state;
362 notify->user_data = cb_info->user_data;
364 id = _connection_callback_add(__libnet_state_changed_cb_idle,
370 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
372 if (profile_list->count > 0)
373 g_free(profile_list->profiles);
375 profile_list->count = 0;
376 profile_list->next = 0;
377 profile_list->profiles = NULL;
380 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
382 bool is_requested = false;
383 connection_error_e result = CONNECTION_ERROR_NONE;
385 switch (event_cb->Event) {
386 case NET_EVENT_OPEN_RSP:
389 case NET_EVENT_OPEN_IND:
390 result = __libnet_convert_to_cp_error_type(event_cb->Error);
391 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
392 (is_requested) ? "RSP":"IND",
393 __libnet_convert_cp_error_type_to_string(result));
396 __libnet_opened_cb(result);
398 switch (event_cb->Error) {
400 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
401 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
403 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
406 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
407 __libnet_convert_cp_error_type_to_string(result));
410 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
413 case NET_EVENT_CLOSE_RSP:
416 case NET_EVENT_CLOSE_IND:
417 result = __libnet_convert_to_cp_error_type(event_cb->Error);
418 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
419 (is_requested) ? "RSP":"IND",
420 __libnet_convert_cp_error_type_to_string(result));
423 __libnet_closed_cb(result);
425 switch (event_cb->Error) {
427 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
429 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
432 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
433 __libnet_convert_cp_error_type_to_string(result));
437 case NET_EVENT_NET_STATE_IND:
438 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
440 if (event_cb->Datalength != sizeof(net_state_type_t))
443 net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
444 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
446 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
447 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
449 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
452 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
453 result = __libnet_convert_to_cp_error_type(event_cb->Error);
454 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
455 __libnet_default_cb(result);
458 case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
459 result = __libnet_convert_to_cp_error_type(event_cb->Error);
460 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
461 __libnet_reset_profile_cb(result);
463 case NET_EVENT_ETHERNET_CABLE_ATTACHED:
464 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
465 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED);
467 case NET_EVENT_ETHERNET_CABLE_DETACHED:
468 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
469 __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED);
477 static int __libnet_check_address_type(int address_family, const char *address)
482 err = inet_pton(address_family, address, &buf);
489 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
494 for (;i < profile_list->count;i++) {
495 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
496 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
503 void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
507 for (;i < source->count;i++) {
508 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
509 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
510 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
516 int __libnet_get_default_count(struct _profile_list_s *profile_list)
521 for (;i < profile_list->count;i++) {
522 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
529 void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
533 for (;i < source->count;i++) {
534 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
535 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
541 int _connection_libnet_init(void)
545 if (_connection_is_created() != true) {
546 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
547 if (rv != NET_ERR_NONE)
550 __connection_set_created(true);
552 if (profile_cb_table == NULL)
553 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
559 bool _connection_libnet_deinit(void)
561 if (_connection_is_created() == true) {
562 if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
565 __connection_set_created(false);
567 if (profile_cb_table) {
568 g_hash_table_destroy(profile_cb_table);
569 profile_cb_table = NULL;
572 __libnet_clear_profile_list(&profile_iterator);
574 if (prof_handle_list) {
575 g_slist_free_full(prof_handle_list, g_free);
576 prof_handle_list = NULL;
583 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
591 for (list = prof_handle_list; list; list = list->next)
592 if (profile == list->data) return true;
594 for (;i < profile_iterator.count;i++)
595 if (profile == &profile_iterator.profiles[i]) return true;
600 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
602 struct _profile_cb_s *cb_info;
603 net_profile_info_t *profile_info = profile;
608 cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
616 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
619 net_wifi_state_t wlan_state;
620 net_profile_name_t profile_name;
622 rv = net_get_wifi_state(&wlan_state, &profile_name);
623 if (rv == NET_ERR_ACCESS_DENIED) {
624 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
625 return CONNECTION_ERROR_PERMISSION_DENIED;
626 } else if (rv != NET_ERR_NONE) {
627 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
628 return CONNECTION_ERROR_OPERATION_FAILED;
631 switch (wlan_state) {
633 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
636 case WIFI_ASSOCIATION:
637 case WIFI_CONFIGURATION:
638 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
641 case WIFI_DISCONNECTING:
642 *state = CONNECTION_WIFI_STATE_CONNECTED;
645 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state");
646 return CONNECTION_ERROR_INVALID_OPERATION;
649 return CONNECTION_ERROR_NONE;
652 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
655 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
656 rv = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
657 if (rv == NET_ERR_ACCESS_DENIED) {
658 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
659 return CONNECTION_ERROR_PERMISSION_DENIED;
662 if (ethernet_profiles.count == 0) {
663 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
664 return CONNECTION_ERROR_NONE;
667 switch (ethernet_profiles.profiles->ProfileState) {
668 case NET_STATE_TYPE_ONLINE:
669 case NET_STATE_TYPE_READY:
670 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
672 case NET_STATE_TYPE_IDLE:
673 case NET_STATE_TYPE_FAILURE:
674 case NET_STATE_TYPE_ASSOCIATION:
675 case NET_STATE_TYPE_CONFIGURATION:
676 case NET_STATE_TYPE_DISCONNECT:
677 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
680 __libnet_clear_profile_list(ðernet_profiles);
681 return CONNECTION_ERROR_OPERATION_FAILED;
684 __libnet_clear_profile_list(ðernet_profiles);
686 return CONNECTION_ERROR_NONE;
689 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
694 rv = net_get_ethernet_cable_state(&status);
695 if (rv == NET_ERR_ACCESS_DENIED) {
696 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
697 return CONNECTION_ERROR_PERMISSION_DENIED;
698 } else if (rv != NET_ERR_NONE) {
699 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
700 return CONNECTION_ERROR_OPERATION_FAILED;
704 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
706 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
707 return CONNECTION_ERROR_NONE;
710 int _connection_libnet_set_ethernet_cable_state_changed_cb(
711 libnet_ethernet_cable_state_changed_cb callback)
713 __libnet_set_ethernet_cable_state_changed_cb(callback);
715 return CONNECTION_ERROR_NONE;
718 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
722 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
723 rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
724 if (rv == NET_ERR_ACCESS_DENIED) {
725 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
726 return CONNECTION_ERROR_PERMISSION_DENIED;
729 if (bluetooth_profiles.count == 0) {
730 *state = CONNECTION_BT_STATE_DEACTIVATED;
731 return CONNECTION_ERROR_NONE;
734 for (; i < bluetooth_profiles.count; i++) {
735 switch (bluetooth_profiles.profiles[i].ProfileState) {
736 case NET_STATE_TYPE_ONLINE:
737 case NET_STATE_TYPE_READY:
738 *state = CONNECTION_BT_STATE_CONNECTED;
740 case NET_STATE_TYPE_IDLE:
741 case NET_STATE_TYPE_FAILURE:
742 case NET_STATE_TYPE_ASSOCIATION:
743 case NET_STATE_TYPE_CONFIGURATION:
744 case NET_STATE_TYPE_DISCONNECT:
745 *state = CONNECTION_BT_STATE_DISCONNECTED;
748 __libnet_clear_profile_list(&bluetooth_profiles);
749 return CONNECTION_ERROR_OPERATION_FAILED;
754 __libnet_clear_profile_list(&bluetooth_profiles);
756 return CONNECTION_ERROR_NONE;
759 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
762 int rv1, rv2, rv3, rv4;
763 net_profile_info_t *profiles = NULL;
765 struct _profile_list_s wifi_profiles = {0, 0, NULL};
766 struct _profile_list_s cellular_profiles = {0, 0, NULL};
767 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
768 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
770 __libnet_clear_profile_list(&profile_iterator);
772 rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
773 if (rv1 == NET_ERR_ACCESS_DENIED) {
774 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
775 return CONNECTION_ERROR_PERMISSION_DENIED;
776 } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
777 return CONNECTION_ERROR_OPERATION_FAILED;
779 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
781 rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
782 if (rv2 == NET_ERR_ACCESS_DENIED) {
783 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
784 __libnet_clear_profile_list(&wifi_profiles);
785 return CONNECTION_ERROR_PERMISSION_DENIED;
786 } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
787 __libnet_clear_profile_list(&wifi_profiles);
788 return CONNECTION_ERROR_OPERATION_FAILED;
790 CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
792 rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
793 if (rv3 == NET_ERR_ACCESS_DENIED) {
794 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
795 __libnet_clear_profile_list(&wifi_profiles);
796 __libnet_clear_profile_list(&cellular_profiles);
797 return CONNECTION_ERROR_PERMISSION_DENIED;
798 } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
799 __libnet_clear_profile_list(&wifi_profiles);
800 __libnet_clear_profile_list(&cellular_profiles);
801 return CONNECTION_ERROR_OPERATION_FAILED;
803 CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
805 rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
806 if (rv4 == NET_ERR_ACCESS_DENIED) {
807 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
808 __libnet_clear_profile_list(&wifi_profiles);
809 __libnet_clear_profile_list(&cellular_profiles);
810 __libnet_clear_profile_list(ðernet_profiles);
811 return CONNECTION_ERROR_PERMISSION_DENIED;
812 } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
813 __libnet_clear_profile_list(&wifi_profiles);
814 __libnet_clear_profile_list(&cellular_profiles);
815 __libnet_clear_profile_list(ðernet_profiles);
816 return CONNECTION_ERROR_OPERATION_FAILED;
818 CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
820 *profile_iter_h = &profile_iterator;
823 case CONNECTION_ITERATOR_TYPE_REGISTERED:
824 count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count;
825 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
827 return CONNECTION_ERROR_NONE;
829 profiles = g_try_new0(net_profile_info_t, count);
830 if (profiles == NULL) {
831 __libnet_clear_profile_list(&wifi_profiles);
832 __libnet_clear_profile_list(&cellular_profiles);
833 __libnet_clear_profile_list(ðernet_profiles);
834 __libnet_clear_profile_list(&bluetooth_profiles);
835 return CONNECTION_ERROR_OUT_OF_MEMORY;
838 profile_iterator.profiles = profiles;
840 if (wifi_profiles.count > 0) {
841 memcpy(profiles, wifi_profiles.profiles,
842 sizeof(net_profile_info_t) * wifi_profiles.count);
843 profiles += wifi_profiles.count;
846 if (cellular_profiles.count > 0) {
847 memcpy(profiles, cellular_profiles.profiles,
848 sizeof(net_profile_info_t) * cellular_profiles.count);
849 profiles += cellular_profiles.count;
852 if (ethernet_profiles.count > 0) {
853 memcpy(profiles, ethernet_profiles.profiles,
854 sizeof(net_profile_info_t) * ethernet_profiles.count);
855 profiles += ethernet_profiles.count;
858 if (bluetooth_profiles.count > 0)
859 memcpy(profiles, bluetooth_profiles.profiles,
860 sizeof(net_profile_info_t) * bluetooth_profiles.count);
863 case CONNECTION_ITERATOR_TYPE_CONNECTED:
864 count = __libnet_get_connected_count(&wifi_profiles);
865 count += __libnet_get_connected_count(&cellular_profiles);
866 count += __libnet_get_connected_count(ðernet_profiles);
867 count += __libnet_get_connected_count(&bluetooth_profiles);
868 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
870 return CONNECTION_ERROR_NONE;
872 profiles = g_try_new0(net_profile_info_t, count);
873 if (profiles == NULL) {
874 __libnet_clear_profile_list(&wifi_profiles);
875 __libnet_clear_profile_list(&cellular_profiles);
876 __libnet_clear_profile_list(ðernet_profiles);
877 __libnet_clear_profile_list(&bluetooth_profiles);
878 return CONNECTION_ERROR_OUT_OF_MEMORY;
881 profile_iterator.profiles = profiles;
883 if (wifi_profiles.count > 0)
884 __libnet_copy_connected_profile(&profiles, &wifi_profiles);
886 if (cellular_profiles.count > 0)
887 __libnet_copy_connected_profile(&profiles, &cellular_profiles);
889 if (ethernet_profiles.count > 0)
890 __libnet_copy_connected_profile(&profiles, ðernet_profiles);
892 if (bluetooth_profiles.count > 0)
893 __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
896 case CONNECTION_ITERATOR_TYPE_DEFAULT:
897 count = __libnet_get_default_count(&cellular_profiles);
898 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count);
900 return CONNECTION_ERROR_NONE;
902 profiles = g_try_new0(net_profile_info_t, count);
903 if (profiles == NULL) {
904 __libnet_clear_profile_list(&wifi_profiles);
905 __libnet_clear_profile_list(&cellular_profiles);
906 __libnet_clear_profile_list(ðernet_profiles);
907 __libnet_clear_profile_list(&bluetooth_profiles);
908 return CONNECTION_ERROR_OUT_OF_MEMORY;
911 profile_iterator.profiles = profiles;
913 if (cellular_profiles.count > 0)
914 __libnet_copy_default_profile(&profiles, &cellular_profiles);
918 __libnet_clear_profile_list(&wifi_profiles);
919 __libnet_clear_profile_list(&cellular_profiles);
920 __libnet_clear_profile_list(ðernet_profiles);
921 __libnet_clear_profile_list(&bluetooth_profiles);
923 profile_iterator.count = count;
925 return CONNECTION_ERROR_NONE;
928 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
930 if (profile_iter_h != &profile_iterator)
931 return CONNECTION_ERROR_INVALID_PARAMETER;
933 if (profile_iterator.count <= profile_iterator.next)
934 return CONNECTION_ERROR_ITERATOR_END;
936 *profile = &profile_iterator.profiles[profile_iterator.next];
937 profile_iterator.next++;
939 return CONNECTION_ERROR_NONE;
942 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
944 if (profile_iter_h != &profile_iterator)
947 if (profile_iterator.count <= profile_iterator.next)
953 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
955 if (profile_iter_h != &profile_iterator)
956 return CONNECTION_ERROR_INVALID_PARAMETER;
958 __libnet_clear_profile_list(&profile_iterator);
960 return CONNECTION_ERROR_NONE;
963 int _connection_libnet_get_current_profile(connection_profile_h *profile)
965 net_profile_info_t active_profile;
968 rv = net_get_active_net_info(&active_profile);
969 if (rv == NET_ERR_NO_SERVICE)
970 return CONNECTION_ERROR_NO_CONNECTION;
971 else if (rv == NET_ERR_ACCESS_DENIED) {
972 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
973 return CONNECTION_ERROR_PERMISSION_DENIED;
974 } else if (rv != NET_ERR_NONE)
975 return CONNECTION_ERROR_OPERATION_FAILED;
977 *profile = g_try_malloc0(sizeof(net_profile_info_t));
978 if (*profile == NULL)
979 return CONNECTION_ERROR_OUT_OF_MEMORY;
981 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
982 prof_handle_list = g_slist_append(prof_handle_list, *profile);
984 return CONNECTION_ERROR_NONE;
987 int _connection_libnet_reset_profile(connection_reset_option_e type,
988 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
992 rv = net_reset_profile(type, id);
993 if (rv == NET_ERR_ACCESS_DENIED) {
994 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
995 return CONNECTION_ERROR_PERMISSION_DENIED;
996 } else if (rv != NET_ERR_NONE) {
997 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
998 return CONNECTION_ERROR_OPERATION_FAILED;
1001 __libnet_set_reset_profile_cb(callback, user_data);
1003 return CONNECTION_ERROR_NONE;
1006 int _connection_libnet_open_profile(connection_profile_h profile,
1007 connection_opened_cb callback, void* user_data)
1011 if (!(_connection_libnet_check_profile_validity(profile))) {
1012 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1013 return CONNECTION_ERROR_INVALID_PARAMETER;
1016 net_profile_info_t *profile_info = profile;
1018 rv = net_open_connection_with_profile(profile_info->ProfileName);
1019 if (rv == NET_ERR_ACCESS_DENIED) {
1020 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1021 return CONNECTION_ERROR_PERMISSION_DENIED;
1022 } else if (rv != NET_ERR_NONE)
1023 return CONNECTION_ERROR_OPERATION_FAILED;
1025 __libnet_set_opened_cb(callback, user_data);
1027 return CONNECTION_ERROR_NONE;
1030 int _connection_libnet_get_cellular_service_profile(
1031 connection_cellular_service_type_e type, connection_profile_h *profile)
1034 int rv = NET_ERR_NONE;
1035 #if defined TIZEN_DUALSIM_ENABLE
1036 int default_subscriber_id = 0;
1037 char subscriber_id[3];
1040 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
1041 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
1043 rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
1044 if (rv == NET_ERR_ACCESS_DENIED) {
1045 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1046 return CONNECTION_ERROR_PERMISSION_DENIED;
1047 } else if (rv != NET_ERR_NONE) {
1048 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
1049 return CONNECTION_ERROR_OPERATION_FAILED;
1052 #if defined TIZEN_DUALSIM_ENABLE
1053 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
1054 &default_subscriber_id) != 0) {
1055 CONNECTION_LOG(CONNECTION_ERROR,
1056 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
1057 __libnet_clear_profile_list(&cellular_profiles);
1058 return CONNECTION_ERROR_OPERATION_FAILED;
1061 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
1064 for (i = 0; i < cellular_profiles.count; i++)
1065 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
1066 #if defined TIZEN_DUALSIM_ENABLE
1067 if (g_str_has_suffix(
1068 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
1069 subscriber_id) == TRUE)
1073 if (i >= cellular_profiles.count) {
1074 __libnet_clear_profile_list(&cellular_profiles);
1075 return CONNECTION_ERROR_OPERATION_FAILED;
1078 *profile = g_try_malloc0(sizeof(net_profile_info_t));
1079 if (*profile == NULL) {
1080 __libnet_clear_profile_list(&cellular_profiles);
1081 return CONNECTION_ERROR_OUT_OF_MEMORY;
1084 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
1086 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
1089 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
1090 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
1093 for (j = 0; j < cellular_profiles.count; j++) {
1097 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
1100 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
1101 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
1107 __libnet_clear_profile_list(&cellular_profiles);
1108 prof_handle_list = g_slist_append(prof_handle_list, *profile);
1110 return CONNECTION_ERROR_NONE;
1113 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
1117 if (!(_connection_libnet_check_profile_validity(profile))) {
1118 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1119 return CONNECTION_ERROR_INVALID_PARAMETER;
1122 net_profile_info_t *profile_info = profile;
1123 connection_cellular_service_type_e service_type;
1125 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1127 if (service_type != type)
1128 return CONNECTION_ERROR_INVALID_PARAMETER;
1130 rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
1131 if (rv == NET_ERR_ACCESS_DENIED) {
1132 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1133 return CONNECTION_ERROR_PERMISSION_DENIED;
1134 } else if (rv != NET_ERR_NONE)
1135 return CONNECTION_ERROR_OPERATION_FAILED;
1137 return CONNECTION_ERROR_NONE;
1140 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
1141 connection_profile_h profile, connection_set_default_cb callback, void* user_data)
1145 if (!(_connection_libnet_check_profile_validity(profile))) {
1146 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1147 return CONNECTION_ERROR_INVALID_PARAMETER;
1150 net_profile_info_t *profile_info = profile;
1151 connection_cellular_service_type_e service_type;
1153 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1155 if (service_type != type)
1156 return CONNECTION_ERROR_INVALID_PARAMETER;
1158 rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
1159 if (rv == NET_ERR_ACCESS_DENIED) {
1160 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1161 return CONNECTION_ERROR_PERMISSION_DENIED;
1162 } else if (rv != NET_ERR_NONE)
1163 return CONNECTION_ERROR_OPERATION_FAILED;
1165 __libnet_set_default_cb(callback, user_data);
1167 return CONNECTION_ERROR_NONE;
1170 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
1174 if (!(_connection_libnet_check_profile_validity(profile))) {
1175 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1176 return CONNECTION_ERROR_INVALID_PARAMETER;
1179 net_profile_info_t *profile_info = profile;
1181 rv = net_close_connection(profile_info->ProfileName);
1182 if (rv == NET_ERR_ACCESS_DENIED) {
1183 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1184 return CONNECTION_ERROR_PERMISSION_DENIED;
1185 } else if (rv != NET_ERR_NONE)
1186 return CONNECTION_ERROR_OPERATION_FAILED;
1188 __libnet_set_closed_cb(callback, user_data);
1190 return CONNECTION_ERROR_NONE;
1193 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
1196 char *endstr = NULL;
1197 int address_family = 0;
1199 if(__libnet_check_address_type(AF_INET, host_address))
1200 address_family = AF_INET;
1202 return CONNECTION_ERROR_INVALID_PARAMETER;
1204 switch(address_family) {
1206 endstr = strrchr(host_address, '.');
1207 if (endstr == NULL ||
1208 strcmp(endstr, ".0") == 0 ||
1209 strncmp(host_address, "0.", 2) == 0 ||
1210 strstr(host_address, "255") != NULL) {
1211 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1212 return CONNECTION_ERROR_INVALID_PARAMETER;
1216 return CONNECTION_ERROR_OPERATION_FAILED;
1219 rv = net_add_route(host_address, interface_name, address_family);
1220 if (rv == NET_ERR_ACCESS_DENIED) {
1221 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1222 return CONNECTION_ERROR_PERMISSION_DENIED;
1223 } else if (rv != NET_ERR_NONE)
1224 return CONNECTION_ERROR_OPERATION_FAILED;
1226 return CONNECTION_ERROR_NONE;
1229 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
1232 char *endstr = strrchr(host_address, '.');
1233 int address_family = 0;
1235 if (__libnet_check_address_type(AF_INET, host_address))
1236 address_family = AF_INET;
1238 return CONNECTION_ERROR_INVALID_PARAMETER;
1240 switch(address_family) {
1242 endstr = strrchr(host_address, '.');
1243 if (endstr == NULL ||
1244 strcmp(endstr, ".0") == 0 ||
1245 strncmp(host_address, "0.", 2) == 0 ||
1246 strstr(host_address, ".0.") != NULL ||strstr(host_address, "255") != NULL) {
1247 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
1248 return CONNECTION_ERROR_INVALID_PARAMETER;
1252 return CONNECTION_ERROR_OPERATION_FAILED;
1255 rv = net_remove_route(host_address, interface_name, address_family);
1256 if (rv == NET_ERR_ACCESS_DENIED) {
1257 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1258 return CONNECTION_ERROR_PERMISSION_DENIED;
1259 } else if (rv != NET_ERR_NONE)
1260 return CONNECTION_ERROR_OPERATION_FAILED;
1262 return CONNECTION_ERROR_NONE;
1265 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1268 int address_family = 0;
1270 address_family = AF_INET6;
1271 /* if(__libnet_check_address_type(AF_INET6, host_address))
1272 address_family = AF_INET6;
1274 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1276 switch(address_family) {
1278 if (strncmp(host_address, "fe80:", 5) == 0 ||
1279 strncmp(host_address, "ff00:", 5) == 0 ||
1280 strncmp(host_address, "::", 2) == 0) {
1281 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1282 return CONNECTION_ERROR_INVALID_PARAMETER;
1286 return CONNECTION_ERROR_OPERATION_FAILED;
1289 rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1290 if (rv == NET_ERR_ACCESS_DENIED) {
1291 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1292 return CONNECTION_ERROR_PERMISSION_DENIED;
1293 } else if (rv != NET_ERR_NONE)
1294 return CONNECTION_ERROR_OPERATION_FAILED;
1296 return CONNECTION_ERROR_NONE;
1299 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1302 int address_family = 0;
1304 address_family = AF_INET6;
1305 /* if (__libnet_check_address_type(AF_INET6, host_address))
1306 address_family = AF_INET6;
1308 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1310 switch(address_family) {
1312 if (strncmp(host_address, "fe80:", 5) == 0 ||
1313 strncmp(host_address, "ff00:", 5) == 0 ||
1314 strncmp(host_address, "::", 2) == 0) {
1315 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1316 return CONNECTION_ERROR_INVALID_PARAMETER;
1320 return CONNECTION_ERROR_OPERATION_FAILED;
1323 rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1324 if (rv == NET_ERR_ACCESS_DENIED) {
1325 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1326 return CONNECTION_ERROR_PERMISSION_DENIED;
1327 } else if (rv != NET_ERR_NONE)
1328 return CONNECTION_ERROR_OPERATION_FAILED;
1330 return CONNECTION_ERROR_NONE;
1333 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1335 prof_handle_list = g_slist_append(prof_handle_list, profile);
1338 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1340 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1344 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1345 connection_profile_state_changed_cb callback, void *user_data)
1347 net_profile_info_t *profile_info = profile;
1348 char *profile_name = g_strdup(profile_info->ProfileName);
1350 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1351 if (profile_cb_info == NULL) {
1352 g_free(profile_name);
1356 profile_cb_info->callback = callback;
1357 profile_cb_info->user_data = user_data;
1358 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1360 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1365 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1367 net_profile_info_t *profile_info = profile;
1369 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1375 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1378 rv = net_set_statistics(device_type, statistics_type);
1379 if (rv == NET_ERR_ACCESS_DENIED) {
1380 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1381 return CONNECTION_ERROR_PERMISSION_DENIED;
1382 } else if (rv != NET_ERR_NONE)
1383 return CONNECTION_ERROR_OPERATION_FAILED;
1385 return CONNECTION_ERROR_NONE;
1388 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1391 rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1392 if (rv == NET_ERR_ACCESS_DENIED) {
1393 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1394 return CONNECTION_ERROR_PERMISSION_DENIED;
1395 }else if (rv != NET_ERR_NONE)
1396 return CONNECTION_ERROR_OPERATION_FAILED;
1398 return CONNECTION_ERROR_NONE;
1401 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1402 connection_cellular_subscriber_id_e sim_id)
1404 char *modem_path = NULL;
1405 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1407 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1408 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
1409 return CONNECTION_ERROR_OPERATION_FAILED;
1413 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
1414 return CONNECTION_ERROR_OPERATION_FAILED;
1417 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1418 NET_PROFILE_NAME_LEN_MAX);
1421 return CONNECTION_ERROR_NONE;
1424 static void __connection_idle_destroy_cb(gpointer data)
1429 managed_idler_list = g_slist_remove(managed_idler_list, data);
1433 static gboolean __connection_idle_cb(gpointer user_data)
1435 struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1440 return data->func(data->user_data);
1443 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1446 struct managed_idle_data *data;
1451 data = g_try_new0(struct managed_idle_data, 1);
1456 data->user_data = user_data;
1458 id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
1459 __connection_idle_destroy_cb);
1467 managed_idler_list = g_slist_append(managed_idler_list, data);
1472 void _connection_callback_cleanup(void)
1474 GSList *cur = managed_idler_list;
1476 struct managed_idle_data *data;
1479 GSList *next = cur->next;
1480 data = (struct managed_idle_data *)cur->data;
1482 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1484 g_source_destroy(src);
1485 cur = managed_idler_list;
1490 g_slist_free(managed_idler_list);
1491 managed_idler_list = NULL;
1494 int _connection_libnet_check_get_privilege()
1498 rv = net_check_get_privilege();
1499 if (rv == NET_ERR_ACCESS_DENIED) {
1500 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1501 return CONNECTION_ERROR_PERMISSION_DENIED;
1502 } else if (rv != NET_ERR_NONE)
1503 return CONNECTION_ERROR_OPERATION_FAILED;
1505 return CONNECTION_ERROR_NONE;
1508 int _connection_libnet_check_profile_privilege()
1512 rv = net_check_profile_privilege();
1513 if (rv == NET_ERR_ACCESS_DENIED) {
1514 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1515 return CONNECTION_ERROR_PERMISSION_DENIED;
1516 } else if (rv != NET_ERR_NONE)
1517 return CONNECTION_ERROR_OPERATION_FAILED;
1519 return CONNECTION_ERROR_NONE;
1522 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1524 if(!connection_is_feature_checked[feature]) {
1525 if(system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1526 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info");
1527 set_last_result(CONNECTION_ERROR_OPERATION_FAILED);
1528 return CONNECTION_ERROR_OPERATION_FAILED;
1530 connection_is_feature_checked[feature] = true;
1532 return connection_feature_supported[feature];
1535 int _connection_check_feature_supported(const char *feature_name, ...)
1540 bool feature_supported = false;
1542 va_start(list, feature_name);
1545 if((strcmp(key, TELEPHONY_FEATURE) == 0)){
1546 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1548 if((strcmp(key, WIFI_FEATURE) == 0)){
1549 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1551 if((strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)){
1552 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1554 if((strcmp(key, ETHERNET_FEATURE) == 0)){
1555 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1558 SECURE_CONNECTION_LOG(CONNECTION_INFO, "%s feature is %s", key, (value?"true":"false"));
1559 feature_supported |= value;
1560 key = va_arg(list, const char *);
1563 if (!feature_supported) {
1564 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1565 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1567 return CONNECTION_ERROR_NOT_SUPPORTED;
1571 set_last_result(CONNECTION_ERROR_NONE);
1572 return CONNECTION_ERROR_NONE;