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;
621 rv = net_get_wifi_state(&wlan_state);
622 if (rv == NET_ERR_ACCESS_DENIED) {
623 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
624 return CONNECTION_ERROR_PERMISSION_DENIED;
625 } else if (rv != NET_ERR_NONE) {
626 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
627 return CONNECTION_ERROR_OPERATION_FAILED;
630 switch (wlan_state) {
632 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
635 case WIFI_ASSOCIATION:
636 case WIFI_CONFIGURATION:
637 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
640 case WIFI_DISCONNECTING:
641 *state = CONNECTION_WIFI_STATE_CONNECTED;
644 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state");
645 return CONNECTION_ERROR_INVALID_OPERATION;
648 return CONNECTION_ERROR_NONE;
651 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
654 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
655 rv = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
656 if (rv == NET_ERR_ACCESS_DENIED) {
657 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
658 return CONNECTION_ERROR_PERMISSION_DENIED;
661 if (ethernet_profiles.count == 0) {
662 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
663 return CONNECTION_ERROR_NONE;
666 switch (ethernet_profiles.profiles->ProfileState) {
667 case NET_STATE_TYPE_ONLINE:
668 case NET_STATE_TYPE_READY:
669 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
671 case NET_STATE_TYPE_IDLE:
672 case NET_STATE_TYPE_FAILURE:
673 case NET_STATE_TYPE_ASSOCIATION:
674 case NET_STATE_TYPE_CONFIGURATION:
675 case NET_STATE_TYPE_DISCONNECT:
676 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
679 __libnet_clear_profile_list(ðernet_profiles);
680 return CONNECTION_ERROR_OPERATION_FAILED;
683 __libnet_clear_profile_list(ðernet_profiles);
685 return CONNECTION_ERROR_NONE;
688 int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
693 rv = net_get_ethernet_cable_state(&status);
694 if (rv == NET_ERR_ACCESS_DENIED) {
695 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
696 return CONNECTION_ERROR_PERMISSION_DENIED;
697 } else if (rv != NET_ERR_NONE) {
698 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
699 return CONNECTION_ERROR_OPERATION_FAILED;
703 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
705 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
706 return CONNECTION_ERROR_NONE;
709 int _connection_libnet_set_ethernet_cable_state_changed_cb(
710 libnet_ethernet_cable_state_changed_cb callback)
712 __libnet_set_ethernet_cable_state_changed_cb(callback);
714 return CONNECTION_ERROR_NONE;
717 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
721 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
722 rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
723 if (rv == NET_ERR_ACCESS_DENIED) {
724 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
725 return CONNECTION_ERROR_PERMISSION_DENIED;
728 if (bluetooth_profiles.count == 0) {
729 *state = CONNECTION_BT_STATE_DEACTIVATED;
730 return CONNECTION_ERROR_NONE;
733 for (; i < bluetooth_profiles.count; i++) {
734 switch (bluetooth_profiles.profiles[i].ProfileState) {
735 case NET_STATE_TYPE_ONLINE:
736 case NET_STATE_TYPE_READY:
737 *state = CONNECTION_BT_STATE_CONNECTED;
739 case NET_STATE_TYPE_IDLE:
740 case NET_STATE_TYPE_FAILURE:
741 case NET_STATE_TYPE_ASSOCIATION:
742 case NET_STATE_TYPE_CONFIGURATION:
743 case NET_STATE_TYPE_DISCONNECT:
744 *state = CONNECTION_BT_STATE_DISCONNECTED;
747 __libnet_clear_profile_list(&bluetooth_profiles);
748 return CONNECTION_ERROR_OPERATION_FAILED;
753 __libnet_clear_profile_list(&bluetooth_profiles);
755 return CONNECTION_ERROR_NONE;
758 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
761 int rv1, rv2, rv3, rv4;
762 net_profile_info_t *profiles = NULL;
764 struct _profile_list_s wifi_profiles = {0, 0, NULL};
765 struct _profile_list_s cellular_profiles = {0, 0, NULL};
766 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
767 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
769 __libnet_clear_profile_list(&profile_iterator);
771 rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
772 if (rv1 == NET_ERR_ACCESS_DENIED) {
773 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
774 return CONNECTION_ERROR_PERMISSION_DENIED;
775 } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
776 return CONNECTION_ERROR_OPERATION_FAILED;
778 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
780 rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
781 if (rv2 == NET_ERR_ACCESS_DENIED) {
782 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
783 __libnet_clear_profile_list(&wifi_profiles);
784 return CONNECTION_ERROR_PERMISSION_DENIED;
785 } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
786 __libnet_clear_profile_list(&wifi_profiles);
787 return CONNECTION_ERROR_OPERATION_FAILED;
789 CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
791 rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
792 if (rv3 == NET_ERR_ACCESS_DENIED) {
793 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
794 __libnet_clear_profile_list(&wifi_profiles);
795 __libnet_clear_profile_list(&cellular_profiles);
796 return CONNECTION_ERROR_PERMISSION_DENIED;
797 } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
798 __libnet_clear_profile_list(&wifi_profiles);
799 __libnet_clear_profile_list(&cellular_profiles);
800 return CONNECTION_ERROR_OPERATION_FAILED;
802 CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
804 rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
805 if (rv4 == NET_ERR_ACCESS_DENIED) {
806 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
807 __libnet_clear_profile_list(&wifi_profiles);
808 __libnet_clear_profile_list(&cellular_profiles);
809 __libnet_clear_profile_list(ðernet_profiles);
810 return CONNECTION_ERROR_PERMISSION_DENIED;
811 } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
812 __libnet_clear_profile_list(&wifi_profiles);
813 __libnet_clear_profile_list(&cellular_profiles);
814 __libnet_clear_profile_list(ðernet_profiles);
815 return CONNECTION_ERROR_OPERATION_FAILED;
817 CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
819 *profile_iter_h = &profile_iterator;
822 case CONNECTION_ITERATOR_TYPE_REGISTERED:
823 count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count;
824 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
826 return CONNECTION_ERROR_NONE;
828 profiles = g_try_new0(net_profile_info_t, count);
829 if (profiles == NULL) {
830 __libnet_clear_profile_list(&wifi_profiles);
831 __libnet_clear_profile_list(&cellular_profiles);
832 __libnet_clear_profile_list(ðernet_profiles);
833 __libnet_clear_profile_list(&bluetooth_profiles);
834 return CONNECTION_ERROR_OUT_OF_MEMORY;
837 profile_iterator.profiles = profiles;
839 if (wifi_profiles.count > 0) {
840 memcpy(profiles, wifi_profiles.profiles,
841 sizeof(net_profile_info_t) * wifi_profiles.count);
842 profiles += wifi_profiles.count;
845 if (cellular_profiles.count > 0) {
846 memcpy(profiles, cellular_profiles.profiles,
847 sizeof(net_profile_info_t) * cellular_profiles.count);
848 profiles += cellular_profiles.count;
851 if (ethernet_profiles.count > 0) {
852 memcpy(profiles, ethernet_profiles.profiles,
853 sizeof(net_profile_info_t) * ethernet_profiles.count);
854 profiles += ethernet_profiles.count;
857 if (bluetooth_profiles.count > 0)
858 memcpy(profiles, bluetooth_profiles.profiles,
859 sizeof(net_profile_info_t) * bluetooth_profiles.count);
862 case CONNECTION_ITERATOR_TYPE_CONNECTED:
863 count = __libnet_get_connected_count(&wifi_profiles);
864 count += __libnet_get_connected_count(&cellular_profiles);
865 count += __libnet_get_connected_count(ðernet_profiles);
866 count += __libnet_get_connected_count(&bluetooth_profiles);
867 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
869 return CONNECTION_ERROR_NONE;
871 profiles = g_try_new0(net_profile_info_t, count);
872 if (profiles == NULL) {
873 __libnet_clear_profile_list(&wifi_profiles);
874 __libnet_clear_profile_list(&cellular_profiles);
875 __libnet_clear_profile_list(ðernet_profiles);
876 __libnet_clear_profile_list(&bluetooth_profiles);
877 return CONNECTION_ERROR_OUT_OF_MEMORY;
880 profile_iterator.profiles = profiles;
882 if (wifi_profiles.count > 0)
883 __libnet_copy_connected_profile(&profiles, &wifi_profiles);
885 if (cellular_profiles.count > 0)
886 __libnet_copy_connected_profile(&profiles, &cellular_profiles);
888 if (ethernet_profiles.count > 0)
889 __libnet_copy_connected_profile(&profiles, ðernet_profiles);
891 if (bluetooth_profiles.count > 0)
892 __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
895 case CONNECTION_ITERATOR_TYPE_DEFAULT:
896 count = __libnet_get_default_count(&cellular_profiles);
897 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count);
899 return CONNECTION_ERROR_NONE;
901 profiles = g_try_new0(net_profile_info_t, count);
902 if (profiles == NULL) {
903 __libnet_clear_profile_list(&wifi_profiles);
904 __libnet_clear_profile_list(&cellular_profiles);
905 __libnet_clear_profile_list(ðernet_profiles);
906 __libnet_clear_profile_list(&bluetooth_profiles);
907 return CONNECTION_ERROR_OUT_OF_MEMORY;
910 profile_iterator.profiles = profiles;
912 if (cellular_profiles.count > 0)
913 __libnet_copy_default_profile(&profiles, &cellular_profiles);
917 __libnet_clear_profile_list(&wifi_profiles);
918 __libnet_clear_profile_list(&cellular_profiles);
919 __libnet_clear_profile_list(ðernet_profiles);
920 __libnet_clear_profile_list(&bluetooth_profiles);
922 profile_iterator.count = count;
924 return CONNECTION_ERROR_NONE;
927 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
929 if (profile_iter_h != &profile_iterator)
930 return CONNECTION_ERROR_INVALID_PARAMETER;
932 if (profile_iterator.count <= profile_iterator.next)
933 return CONNECTION_ERROR_ITERATOR_END;
935 *profile = &profile_iterator.profiles[profile_iterator.next];
936 profile_iterator.next++;
938 return CONNECTION_ERROR_NONE;
941 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
943 if (profile_iter_h != &profile_iterator)
946 if (profile_iterator.count <= profile_iterator.next)
952 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
954 if (profile_iter_h != &profile_iterator)
955 return CONNECTION_ERROR_INVALID_PARAMETER;
957 __libnet_clear_profile_list(&profile_iterator);
959 return CONNECTION_ERROR_NONE;
962 int _connection_libnet_get_current_profile(connection_profile_h *profile)
964 net_profile_info_t active_profile;
967 rv = net_get_active_net_info(&active_profile);
968 if (rv == NET_ERR_NO_SERVICE)
969 return CONNECTION_ERROR_NO_CONNECTION;
970 else if (rv == NET_ERR_ACCESS_DENIED) {
971 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
972 return CONNECTION_ERROR_PERMISSION_DENIED;
973 } else if (rv != NET_ERR_NONE)
974 return CONNECTION_ERROR_OPERATION_FAILED;
976 *profile = g_try_malloc0(sizeof(net_profile_info_t));
977 if (*profile == NULL)
978 return CONNECTION_ERROR_OUT_OF_MEMORY;
980 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
981 prof_handle_list = g_slist_append(prof_handle_list, *profile);
983 return CONNECTION_ERROR_NONE;
986 int _connection_libnet_reset_profile(connection_reset_option_e type,
987 connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
991 rv = net_reset_profile(type, id);
992 if (rv == NET_ERR_ACCESS_DENIED) {
993 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
994 return CONNECTION_ERROR_PERMISSION_DENIED;
995 } else if (rv != NET_ERR_NONE) {
996 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
997 return CONNECTION_ERROR_OPERATION_FAILED;
1000 __libnet_set_reset_profile_cb(callback, user_data);
1002 return CONNECTION_ERROR_NONE;
1005 int _connection_libnet_open_profile(connection_profile_h profile,
1006 connection_opened_cb callback, void* user_data)
1010 if (!(_connection_libnet_check_profile_validity(profile))) {
1011 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1012 return CONNECTION_ERROR_INVALID_PARAMETER;
1015 net_profile_info_t *profile_info = profile;
1017 rv = net_open_connection_with_profile(profile_info->ProfileName);
1018 if (rv == NET_ERR_ACCESS_DENIED) {
1019 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1020 return CONNECTION_ERROR_PERMISSION_DENIED;
1021 } else if (rv != NET_ERR_NONE)
1022 return CONNECTION_ERROR_OPERATION_FAILED;
1024 __libnet_set_opened_cb(callback, user_data);
1026 return CONNECTION_ERROR_NONE;
1029 int _connection_libnet_get_cellular_service_profile(
1030 connection_cellular_service_type_e type, connection_profile_h *profile)
1033 int rv = NET_ERR_NONE;
1034 #if defined TIZEN_DUALSIM_ENABLE
1035 int default_subscriber_id = 0;
1036 char subscriber_id[3];
1039 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
1040 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
1042 rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
1043 if (rv == NET_ERR_ACCESS_DENIED) {
1044 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1045 return CONNECTION_ERROR_PERMISSION_DENIED;
1046 } else if (rv != NET_ERR_NONE) {
1047 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
1048 return CONNECTION_ERROR_OPERATION_FAILED;
1051 #if defined TIZEN_DUALSIM_ENABLE
1052 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
1053 &default_subscriber_id) != 0) {
1054 CONNECTION_LOG(CONNECTION_ERROR,
1055 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
1056 __libnet_clear_profile_list(&cellular_profiles);
1057 return CONNECTION_ERROR_OPERATION_FAILED;
1060 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
1063 for (i = 0; i < cellular_profiles.count; i++)
1064 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
1065 #if defined TIZEN_DUALSIM_ENABLE
1066 if (g_str_has_suffix(
1067 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
1068 subscriber_id) == TRUE)
1072 if (i >= cellular_profiles.count) {
1073 __libnet_clear_profile_list(&cellular_profiles);
1074 return CONNECTION_ERROR_OPERATION_FAILED;
1077 *profile = g_try_malloc0(sizeof(net_profile_info_t));
1078 if (*profile == NULL) {
1079 __libnet_clear_profile_list(&cellular_profiles);
1080 return CONNECTION_ERROR_OUT_OF_MEMORY;
1083 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
1085 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
1088 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
1089 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
1092 for (j = 0; j < cellular_profiles.count; j++) {
1096 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
1099 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
1100 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
1106 __libnet_clear_profile_list(&cellular_profiles);
1107 prof_handle_list = g_slist_append(prof_handle_list, *profile);
1109 return CONNECTION_ERROR_NONE;
1112 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
1116 if (!(_connection_libnet_check_profile_validity(profile))) {
1117 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1118 return CONNECTION_ERROR_INVALID_PARAMETER;
1121 net_profile_info_t *profile_info = profile;
1122 connection_cellular_service_type_e service_type;
1124 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1126 if (service_type != type)
1127 return CONNECTION_ERROR_INVALID_PARAMETER;
1129 rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
1130 if (rv == NET_ERR_ACCESS_DENIED) {
1131 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1132 return CONNECTION_ERROR_PERMISSION_DENIED;
1133 } else if (rv != NET_ERR_NONE)
1134 return CONNECTION_ERROR_OPERATION_FAILED;
1136 return CONNECTION_ERROR_NONE;
1139 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
1140 connection_profile_h profile, connection_set_default_cb callback, void* user_data)
1144 if (!(_connection_libnet_check_profile_validity(profile))) {
1145 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1146 return CONNECTION_ERROR_INVALID_PARAMETER;
1149 net_profile_info_t *profile_info = profile;
1150 connection_cellular_service_type_e service_type;
1152 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1154 if (service_type != type)
1155 return CONNECTION_ERROR_INVALID_PARAMETER;
1157 rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
1158 if (rv == NET_ERR_ACCESS_DENIED) {
1159 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1160 return CONNECTION_ERROR_PERMISSION_DENIED;
1161 } else if (rv != NET_ERR_NONE)
1162 return CONNECTION_ERROR_OPERATION_FAILED;
1164 __libnet_set_default_cb(callback, user_data);
1166 return CONNECTION_ERROR_NONE;
1169 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
1173 if (!(_connection_libnet_check_profile_validity(profile))) {
1174 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1175 return CONNECTION_ERROR_INVALID_PARAMETER;
1178 net_profile_info_t *profile_info = profile;
1180 rv = net_close_connection(profile_info->ProfileName);
1181 if (rv == NET_ERR_ACCESS_DENIED) {
1182 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1183 return CONNECTION_ERROR_PERMISSION_DENIED;
1184 } else if (rv != NET_ERR_NONE)
1185 return CONNECTION_ERROR_OPERATION_FAILED;
1187 __libnet_set_closed_cb(callback, user_data);
1189 return CONNECTION_ERROR_NONE;
1192 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
1195 char *endstr = NULL;
1196 int address_family = 0;
1198 if (__libnet_check_address_type(AF_INET, host_address))
1199 address_family = AF_INET;
1201 return CONNECTION_ERROR_INVALID_PARAMETER;
1203 switch (address_family) {
1205 endstr = strrchr(host_address, '.');
1206 if (endstr == NULL ||
1207 strcmp(endstr, ".0") == 0 ||
1208 strncmp(host_address, "0.", 2) == 0 ||
1209 strstr(host_address, "255") != NULL) {
1210 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1211 return CONNECTION_ERROR_INVALID_PARAMETER;
1215 return CONNECTION_ERROR_OPERATION_FAILED;
1218 rv = net_add_route(host_address, interface_name, address_family);
1219 if (rv == NET_ERR_ACCESS_DENIED) {
1220 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1221 return CONNECTION_ERROR_PERMISSION_DENIED;
1222 } else if (rv != NET_ERR_NONE)
1223 return CONNECTION_ERROR_OPERATION_FAILED;
1225 return CONNECTION_ERROR_NONE;
1228 int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
1231 char *endstr = strrchr(host_address, '.');
1232 int address_family = 0;
1234 if (__libnet_check_address_type(AF_INET, host_address))
1235 address_family = AF_INET;
1237 return CONNECTION_ERROR_INVALID_PARAMETER;
1239 switch (address_family) {
1241 endstr = strrchr(host_address, '.');
1242 if (endstr == NULL ||
1243 strcmp(endstr, ".0") == 0 ||
1244 strncmp(host_address, "0.", 2) == 0 ||
1245 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1246 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
1247 return CONNECTION_ERROR_INVALID_PARAMETER;
1251 return CONNECTION_ERROR_OPERATION_FAILED;
1254 rv = net_remove_route(host_address, interface_name, address_family);
1255 if (rv == NET_ERR_ACCESS_DENIED) {
1256 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1257 return CONNECTION_ERROR_PERMISSION_DENIED;
1258 } else if (rv != NET_ERR_NONE)
1259 return CONNECTION_ERROR_OPERATION_FAILED;
1261 return CONNECTION_ERROR_NONE;
1264 int _connection_libnet_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1267 int address_family = 0;
1269 address_family = AF_INET6;
1270 /* if(__libnet_check_address_type(AF_INET6, host_address))
1271 address_family = AF_INET6;
1273 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1275 switch (address_family) {
1277 if (strncmp(host_address, "fe80:", 5) == 0 ||
1278 strncmp(host_address, "ff00:", 5) == 0 ||
1279 strncmp(host_address, "::", 2) == 0) {
1280 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1281 return CONNECTION_ERROR_INVALID_PARAMETER;
1285 return CONNECTION_ERROR_OPERATION_FAILED;
1288 rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
1289 if (rv == NET_ERR_ACCESS_DENIED) {
1290 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1291 return CONNECTION_ERROR_PERMISSION_DENIED;
1292 } else if (rv != NET_ERR_NONE)
1293 return CONNECTION_ERROR_OPERATION_FAILED;
1295 return CONNECTION_ERROR_NONE;
1298 int _connection_libnet_remove_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
1301 int address_family = 0;
1303 address_family = AF_INET6;
1304 /* if (__libnet_check_address_type(AF_INET6, host_address))
1305 address_family = AF_INET6;
1307 return CONNECTION_ERROR_INVALID_PARAMETER;*/
1309 switch (address_family) {
1311 if (strncmp(host_address, "fe80:", 5) == 0 ||
1312 strncmp(host_address, "ff00:", 5) == 0 ||
1313 strncmp(host_address, "::", 2) == 0) {
1314 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
1315 return CONNECTION_ERROR_INVALID_PARAMETER;
1319 return CONNECTION_ERROR_OPERATION_FAILED;
1322 rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
1323 if (rv == NET_ERR_ACCESS_DENIED) {
1324 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1325 return CONNECTION_ERROR_PERMISSION_DENIED;
1326 } else if (rv != NET_ERR_NONE)
1327 return CONNECTION_ERROR_OPERATION_FAILED;
1329 return CONNECTION_ERROR_NONE;
1332 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1334 prof_handle_list = g_slist_append(prof_handle_list, profile);
1337 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1339 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1343 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1344 connection_profile_state_changed_cb callback, void *user_data)
1346 net_profile_info_t *profile_info = profile;
1347 char *profile_name = g_strdup(profile_info->ProfileName);
1349 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1350 if (profile_cb_info == NULL) {
1351 g_free(profile_name);
1355 profile_cb_info->callback = callback;
1356 profile_cb_info->user_data = user_data;
1357 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1359 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1364 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1366 net_profile_info_t *profile_info = profile;
1368 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1374 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
1377 rv = net_set_statistics(device_type, statistics_type);
1378 if (rv == NET_ERR_ACCESS_DENIED) {
1379 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1380 return CONNECTION_ERROR_PERMISSION_DENIED;
1381 } else if (rv != NET_ERR_NONE)
1382 return CONNECTION_ERROR_OPERATION_FAILED;
1384 return CONNECTION_ERROR_NONE;
1387 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
1390 rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
1391 if (rv == NET_ERR_ACCESS_DENIED) {
1392 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1393 return CONNECTION_ERROR_PERMISSION_DENIED;
1394 } else if (rv != NET_ERR_NONE)
1395 return CONNECTION_ERROR_OPERATION_FAILED;
1397 return CONNECTION_ERROR_NONE;
1400 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1401 connection_cellular_subscriber_id_e sim_id)
1403 char *modem_path = NULL;
1404 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1406 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1407 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
1408 return CONNECTION_ERROR_OPERATION_FAILED;
1412 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
1413 return CONNECTION_ERROR_OPERATION_FAILED;
1416 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1417 NET_PROFILE_NAME_LEN_MAX);
1420 return CONNECTION_ERROR_NONE;
1423 static void __connection_idle_destroy_cb(gpointer data)
1428 managed_idler_list = g_slist_remove(managed_idler_list, data);
1432 static gboolean __connection_idle_cb(gpointer user_data)
1434 struct managed_idle_data *data = (struct managed_idle_data *)user_data;
1439 return data->func(data->user_data);
1442 guint _connection_callback_add(GSourceFunc func, gpointer user_data)
1445 struct managed_idle_data *data;
1446 GMainContext *context;
1452 data = g_try_new0(struct managed_idle_data, 1);
1457 data->user_data = user_data;
1459 context = g_main_context_get_thread_default();
1460 src = g_idle_source_new();
1461 g_source_set_callback(src, __connection_idle_cb, data,
1462 __connection_idle_destroy_cb);
1463 id = g_source_attach(src, context);
1464 g_source_unref(src);
1472 managed_idler_list = g_slist_append(managed_idler_list, data);
1477 void _connection_callback_cleanup(void)
1479 GSList *cur = managed_idler_list;
1481 struct managed_idle_data *data;
1484 GSList *next = cur->next;
1485 data = (struct managed_idle_data *)cur->data;
1487 src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
1489 g_source_destroy(src);
1490 cur = managed_idler_list;
1495 g_slist_free(managed_idler_list);
1496 managed_idler_list = NULL;
1499 int _connection_libnet_check_get_privilege()
1503 rv = net_check_get_privilege();
1504 if (rv == NET_ERR_ACCESS_DENIED) {
1505 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1506 return CONNECTION_ERROR_PERMISSION_DENIED;
1507 } else if (rv != NET_ERR_NONE)
1508 return CONNECTION_ERROR_OPERATION_FAILED;
1510 return CONNECTION_ERROR_NONE;
1513 int _connection_libnet_check_profile_privilege()
1517 rv = net_check_profile_privilege();
1518 if (rv == NET_ERR_ACCESS_DENIED) {
1519 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1520 return CONNECTION_ERROR_PERMISSION_DENIED;
1521 } else if (rv != NET_ERR_NONE)
1522 return CONNECTION_ERROR_OPERATION_FAILED;
1524 return CONNECTION_ERROR_NONE;
1527 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1529 if (!connection_is_feature_checked[feature]) {
1530 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1531 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info");
1532 set_last_result(CONNECTION_ERROR_OPERATION_FAILED);
1533 return CONNECTION_ERROR_OPERATION_FAILED;
1535 connection_is_feature_checked[feature] = true;
1537 return connection_feature_supported[feature];
1540 int _connection_check_feature_supported(const char *feature_name, ...)
1545 bool feature_supported = false;
1547 va_start(list, feature_name);
1550 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1551 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1552 if (strcmp(key, WIFI_FEATURE) == 0)
1553 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1554 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1555 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1556 if (strcmp(key, ETHERNET_FEATURE) == 0)
1557 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
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;