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 GSList *prof_handle_list = NULL;
28 static GHashTable *profile_cb_table = NULL;
29 static pthread_mutex_t g_conn_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
30 static __thread int g_conn_thread_mutex_ref = 0;
32 struct _profile_cb_s {
33 connection_profile_state_changed_cb callback;
34 connection_profile_state_e state;
38 struct _profile_list_s {
41 net_profile_info_t *profiles;
44 static struct _profile_list_s profile_iterator = {0, 0, NULL};
45 static bool connection_is_feature_checked[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
46 static bool connection_feature_supported[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
49 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
53 return CONNECTION_ERROR_NONE;
54 case NET_ERR_APP_ALREADY_REGISTERED:
55 return CONNECTION_ERROR_INVALID_OPERATION;
56 case NET_ERR_APP_NOT_REGISTERED:
57 return CONNECTION_ERROR_INVALID_OPERATION;
58 case NET_ERR_NO_ACTIVE_CONNECTIONS:
59 return CONNECTION_ERROR_NO_CONNECTION;
60 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
61 return CONNECTION_ERROR_ALREADY_EXISTS;
62 case NET_ERR_CONNECTION_DHCP_FAILED:
63 return CONNECTION_ERROR_DHCP_FAILED;
64 case NET_ERR_CONNECTION_INVALID_KEY:
65 return CONNECTION_ERROR_INVALID_KEY;
66 case NET_ERR_IN_PROGRESS:
67 return CONNECTION_ERROR_NOW_IN_PROGRESS;
68 case NET_ERR_OPERATION_ABORTED:
69 return CONNECTION_ERROR_OPERATION_ABORTED;
70 case NET_ERR_TIME_OUT:
71 return CONNECTION_ERROR_NO_REPLY;
72 case NET_ERR_ACCESS_DENIED:
73 return CONNECTION_ERROR_PERMISSION_DENIED;
75 return CONNECTION_ERROR_OPERATION_FAILED;
79 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
82 case CONNECTION_ERROR_NONE:
84 case CONNECTION_ERROR_INVALID_PARAMETER:
85 return "INVALID_PARAMETER";
86 case CONNECTION_ERROR_OUT_OF_MEMORY:
87 return "OUT_OF_MEMORY";
88 case CONNECTION_ERROR_INVALID_OPERATION:
89 return "INVALID_OPERATION";
90 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
91 return "ADDRESS_FAMILY_NOT_SUPPORTED";
92 case CONNECTION_ERROR_OPERATION_FAILED:
93 return "OPERATION_FAILED";
94 case CONNECTION_ERROR_ITERATOR_END:
95 return "ITERATOR_END";
96 case CONNECTION_ERROR_NO_CONNECTION:
97 return "NO_CONNECTION";
98 case CONNECTION_ERROR_NOW_IN_PROGRESS:
99 return "NOW_IN_PROGRESS";
100 case CONNECTION_ERROR_ALREADY_EXISTS:
101 return "ALREADY_EXISTS";
102 case CONNECTION_ERROR_OPERATION_ABORTED:
103 return "OPERATION_ABORTED";
104 case CONNECTION_ERROR_DHCP_FAILED:
105 return "DHCP_FAILED";
106 case CONNECTION_ERROR_INVALID_KEY:
107 return "INVALID_KEY";
108 case CONNECTION_ERROR_NO_REPLY:
110 case CONNECTION_ERROR_PERMISSION_DENIED:
111 return "PERMISSION_DENIED";
112 case CONNECTION_ERROR_NOT_SUPPORTED:
113 return "NOT_SUPPORTED";
114 case CONNECTION_ERROR_ALREADY_INITIALIZED:
115 return "ALREADY_INITIALIZED";
116 case CONNECTION_ERROR_NOT_INITIALIZED:
117 return "NOT_INITIALIZED";
123 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
126 case CONNECTION_PROFILE_STATE_DISCONNECTED:
127 return "DISCONNECTED";
128 case CONNECTION_PROFILE_STATE_ASSOCIATION:
129 return "ASSOCIATION";
130 case CONNECTION_PROFILE_STATE_CONFIGURATION:
131 return "CONFIGURATION";
132 case CONNECTION_PROFILE_STATE_CONNECTED:
139 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
141 struct _profile_cb_s *cb_info;
143 if (profile_name == NULL)
146 cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
150 if (cb_info->state == state)
153 cb_info->state = state;
155 if (state < 0 || cb_info->callback == NULL)
158 cb_info->callback(cb_info->state, cb_info->user_data);
161 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
163 if (profile_list->count > 0)
164 g_free(profile_list->profiles);
166 profile_list->count = 0;
167 profile_list->next = 0;
168 profile_list->profiles = NULL;
171 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
174 bool is_requested = false;
175 connection_error_e result = CONNECTION_ERROR_NONE;
176 connection_handle_s *conn_handle = (connection_handle_s *)user_data;
178 if (!_connection_check_handle_validity(conn_handle)) {
179 CONNECTION_LOG(CONNECTION_INFO, "Invalid handle");
184 switch (event_cb->event) {
185 case NET_EVENT_OPEN_RSP:
188 case NET_EVENT_OPEN_IND:
189 result = __libnet_convert_to_cp_error_type(event_cb->Error);
190 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
191 (is_requested) ? "RSP" : "IND",
192 __libnet_convert_cp_error_type_to_string(result));
195 if (conn_handle->opened_callback) {
196 conn_handle->opened_callback(result,
197 conn_handle->opened_user_data);
199 conn_handle->opened_callback = NULL;
200 conn_handle->opened_user_data = NULL;
204 switch (event_cb->Error) {
206 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
207 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
209 __libnet_state_changed_cb(event_cb->profile_name, CONNECTION_PROFILE_STATE_CONNECTED);
213 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
214 __libnet_convert_cp_error_type_to_string(result));
217 __libnet_state_changed_cb(event_cb->profile_name, CONNECTION_PROFILE_STATE_DISCONNECTED);
220 case NET_EVENT_CLOSE_RSP:
223 case NET_EVENT_CLOSE_IND:
224 result = __libnet_convert_to_cp_error_type(event_cb->Error);
225 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
226 (is_requested) ? "RSP" : "IND",
227 __libnet_convert_cp_error_type_to_string(result));
230 if (conn_handle->closed_callback) {
231 conn_handle->closed_callback(result,
232 conn_handle->closed_user_data);
234 conn_handle->closed_callback = NULL;
235 conn_handle->closed_user_data = NULL;
239 switch (event_cb->Error) {
241 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
243 __libnet_state_changed_cb(event_cb->profile_name, CONNECTION_PROFILE_STATE_DISCONNECTED);
247 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
248 __libnet_convert_cp_error_type_to_string(result));
252 case NET_EVENT_NET_STATE_IND:
253 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
255 if (event_cb->datalength != sizeof(net_state_type_t)) {
260 net_state_type_t *profile_state = (net_state_type_t *)event_cb->data;
261 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
263 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
264 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->profile_name);
266 __libnet_state_changed_cb(event_cb->profile_name, cp_state);
269 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
270 result = __libnet_convert_to_cp_error_type(event_cb->Error);
271 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
272 if (conn_handle->set_default_callback) {
273 conn_handle->set_default_callback(result,
274 conn_handle->set_default_user_data);
276 conn_handle->set_default_callback = NULL;
277 conn_handle->set_default_user_data = NULL;
280 case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
281 result = __libnet_convert_to_cp_error_type(event_cb->Error);
282 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
283 if (conn_handle->reset_callback) {
284 conn_handle->reset_callback(result,
285 conn_handle->reset_user_data);
287 conn_handle->reset_callback = NULL;
288 conn_handle->reset_user_data = NULL;
291 case NET_EVENT_ETHERNET_CABLE_ATTACHED:
292 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
293 if (conn_handle->ethernet_cable_state_changed_callback) {
294 conn_handle->ethernet_cable_state_changed_callback(CONNECTION_ETHERNET_CABLE_ATTACHED,
295 conn_handle->ethernet_cable_state_changed_user_data);
298 case NET_EVENT_ETHERNET_CABLE_DETACHED:
299 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
300 if (conn_handle->ethernet_cable_state_changed_callback) {
301 conn_handle->ethernet_cable_state_changed_callback(CONNECTION_ETHERNET_CABLE_DETACHED,
302 conn_handle->ethernet_cable_state_changed_user_data);
305 case NET_EVENT_NETWORK_TYPE_CHANGED:
306 CONNECTION_LOG(CONNECTION_INFO, "Got Network Type Changed Indication");
307 int *state = (int *) event_cb->data;
308 if (conn_handle->type_changed_callback) {
309 int type = CONNECTION_TYPE_DISCONNECTED;
312 case VCONFKEY_NETWORK_CELLULAR:
313 type = CONNECTION_TYPE_CELLULAR;
315 case VCONFKEY_NETWORK_WIFI:
316 type = CONNECTION_TYPE_WIFI;
318 case VCONFKEY_NETWORK_ETHERNET:
319 type = CONNECTION_TYPE_ETHERNET;
321 case VCONFKEY_NETWORK_BLUETOOTH:
322 type = CONNECTION_TYPE_BT;
324 case VCONFKEY_NETWORK_DEFAULT_PROXY:
325 type = CONNECTION_TYPE_NET_PROXY;
328 type = CONNECTION_TYPE_DISCONNECTED;
332 conn_handle->type_changed_callback(type,
333 conn_handle->type_changed_user_data);
336 case NET_EVENT_IPV4_ADDRESS_CHANGED:
337 CONNECTION_LOG(CONNECTION_INFO, "Got IPv4 Address Changed Indication");
338 if (conn_handle->ip_changed_callback) {
339 char *ipv4_addr = NULL;
340 char *ipv6_addr = NULL;
341 char *addr = (char *)event_cb->data;
343 ipv4_addr = g_strdup(addr);
344 ipv6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
345 if (ipv6_addr == NULL)
346 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
347 "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
349 conn_handle->ip_changed_callback(ipv4_addr, ipv6_addr,
350 conn_handle->ip_changed_user_data);
356 case NET_EVENT_IPV6_ADDRESS_CHANGED:
357 CONNECTION_LOG(CONNECTION_INFO, "Got IPv6 Address Changed Indication");
358 if (conn_handle->ip_changed_callback) {
359 char *ipv4_addr = NULL;
360 char *ipv6_addr = NULL;
361 char *addr = (char *)event_cb->data;
363 ipv6_addr = g_strdup(addr);
364 ipv4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
365 if (ipv4_addr == NULL)
366 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
367 "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
369 conn_handle->ip_changed_callback(ipv4_addr, ipv6_addr,
370 conn_handle->ip_changed_user_data);
376 case NET_EVENT_PROXY_ADDRESS_CHANGED:
377 CONNECTION_LOG(CONNECTION_INFO, "Got Proxy Changed Indication");
378 char *proxy_addr = (char *)event_cb->data;
380 if (conn_handle->proxy_changed_callback) {
381 conn_handle->proxy_changed_callback(proxy_addr, NULL,
382 conn_handle->proxy_changed_user_data);
385 case NET_EVENT_INTERNET_ONLINE_IND:
386 case NET_EVENT_INTERNET_OFFLINE_IND:
387 CONNECTION_LOG(CONNECTION_INFO, "Got Internet State Changed Indication: %s",
388 event_cb->event == NET_EVENT_INTERNET_ONLINE_IND ? "Online" : "Offline");
389 net_device_t *device_type = (net_device_t *) event_cb->data;
391 if (conn_handle->internet_state_changed_callback) {
392 net_profile_info_t active_profile;
395 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
397 if (rv == NET_ERR_NO_SERVICE && event_cb->event == NET_EVENT_INTERNET_OFFLINE_IND) {
398 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
399 conn_handle->internet_state_changed_user_data); //LCOV_EXCL_LINE
401 } else if (rv == NET_ERR_ACCESS_DENIED) {
402 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
404 } else if (rv != NET_ERR_NONE) {
405 CONNECTION_LOG(CONNECTION_ERROR, "Unable to get Default profile handle"); //LCOV_EXCL_LINE
406 break; //LCOV_EXCL_LINE
409 if (event_cb->event == NET_EVENT_INTERNET_ONLINE_IND) {
410 if (active_profile.profile_state == NET_STATE_TYPE_ONLINE &&
411 active_profile.profile_type == *device_type)
412 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_ONLINE,
413 conn_handle->internet_state_changed_user_data);
415 if (active_profile.profile_state != NET_STATE_TYPE_ONLINE)
416 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
417 conn_handle->internet_state_changed_user_data);
430 static int __libnet_get_connected_count(struct _profile_list_s *profile_list)
435 for (; i < profile_list->count; i++) {
436 if (profile_list->profiles[i].profile_state == NET_STATE_TYPE_ONLINE ||
437 profile_list->profiles[i].profile_state == NET_STATE_TYPE_READY)
444 static void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
448 for (; i < source->count; i++) {
449 if (source->profiles[i].profile_state == NET_STATE_TYPE_ONLINE ||
450 source->profiles[i].profile_state == NET_STATE_TYPE_READY) {
451 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
458 static int __libnet_get_default_count(struct _profile_list_s *profile_list)
463 for (; i < profile_list->count; i++) {
464 if (profile_list->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
465 if (profile_list->profiles[i].profile_info.pdp.default_conn == TRUE)
473 static void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
477 for (; i < source->count; i++) {
478 if (source->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
479 if (source->profiles[i].profile_info.pdp.default_conn == TRUE) {
480 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
488 int _connection_libnet_init(connection_handle_s *conn_handle)
492 rv = net_register_client(&(conn_handle->network_info_handle),
493 (net_event_cb_t)__libnet_evt_cb, conn_handle);
494 if (rv != NET_ERR_NONE)
497 if (profile_cb_table == NULL)
498 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
503 bool _connection_libnet_deinit(connection_handle_s *conn_handle, bool is_empty)
505 net_deregister_client(conn_handle->network_info_handle);
508 if (profile_cb_table) {
509 g_hash_table_destroy(profile_cb_table);
510 profile_cb_table = NULL;
513 __libnet_clear_profile_list(&profile_iterator);
515 if (prof_handle_list) {
516 g_slist_free_full(prof_handle_list, g_free);
517 prof_handle_list = NULL;
525 void _connection_set_cs_tid(int tid, connection_handle_s *conn_handle)
527 net_set_cs_tid(tid, conn_handle->network_info_handle);
530 void _connection_unset_cs_tid(int tid, connection_handle_s *conn_handle)
532 net_unset_cs_tid(tid, conn_handle->network_info_handle);
536 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
544 for (list = prof_handle_list; list; list = list->next)
545 if (profile == list->data) return true;
547 for (; i < profile_iterator.count; i++)
548 if (profile == &profile_iterator.profiles[i]) return true;
553 int _connection_libnet_get_metered_state(connection_handle_s *conn_handle, bool* is_metered)
558 rv = net_get_metered_state(conn_handle->network_info_handle, &status);
559 if (rv == NET_ERR_ACCESS_DENIED) {
560 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
561 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
562 } else if (rv != NET_ERR_NONE) {
563 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv); //LCOV_EXCL_LINE
564 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
571 return CONNECTION_ERROR_NONE;
574 int _connection_libnet_get_wifi_state(connection_handle_s *conn_handle, connection_wifi_state_e *state)
577 net_wifi_state_t wlan_state;
579 rv = net_get_wifi_state(conn_handle->network_info_handle, &wlan_state);
580 if (rv == NET_ERR_ACCESS_DENIED) {
581 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
582 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
583 } else if (rv != NET_ERR_NONE) {
584 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
585 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
588 switch (wlan_state) {
590 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
593 case WIFI_ASSOCIATION:
594 case WIFI_CONFIGURATION:
595 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
598 case WIFI_DISCONNECTING:
599 *state = CONNECTION_WIFI_STATE_CONNECTED;
602 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state"); //LCOV_EXCL_LINE
603 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
606 return CONNECTION_ERROR_NONE;
610 int _connection_libnet_get_ethernet_state(connection_handle_s *conn_handle,
611 connection_ethernet_state_e *state)
614 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
615 rv = net_get_profile_list(conn_handle->network_info_handle,
616 NET_DEVICE_ETHERNET, ðernet_profiles.profiles,
617 ðernet_profiles.count);
618 if (rv == NET_ERR_ACCESS_DENIED) {
619 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
620 return CONNECTION_ERROR_PERMISSION_DENIED;
623 if (ethernet_profiles.count == 0) {
624 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
625 return CONNECTION_ERROR_NONE;
628 switch (ethernet_profiles.profiles->profile_state) {
629 case NET_STATE_TYPE_ONLINE:
630 case NET_STATE_TYPE_READY:
631 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
633 case NET_STATE_TYPE_IDLE:
634 case NET_STATE_TYPE_FAILURE:
635 case NET_STATE_TYPE_ASSOCIATION:
636 case NET_STATE_TYPE_CONFIGURATION:
637 case NET_STATE_TYPE_DISCONNECT:
638 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
641 __libnet_clear_profile_list(ðernet_profiles);
642 return CONNECTION_ERROR_OPERATION_FAILED;
645 __libnet_clear_profile_list(ðernet_profiles);
647 return CONNECTION_ERROR_NONE;
650 int _connection_libnet_get_ethernet_cable_state(connection_handle_s *conn_handle,
651 connection_ethernet_cable_state_e* state)
656 rv = net_get_ethernet_cable_state(conn_handle->network_info_handle, &status);
657 if (rv == NET_ERR_ACCESS_DENIED) {
658 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
659 return CONNECTION_ERROR_PERMISSION_DENIED;
660 } else if (rv != NET_ERR_NONE) {
661 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
662 return CONNECTION_ERROR_OPERATION_FAILED;
666 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
668 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
669 return CONNECTION_ERROR_NONE;
673 int _connection_libnet_get_bluetooth_state(connection_handle_s *conn_handle, connection_bt_state_e *state)
677 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
678 rv = net_get_profile_list(conn_handle->network_info_handle,
679 NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles,
680 &bluetooth_profiles.count);
681 if (rv == NET_ERR_ACCESS_DENIED) {
682 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
683 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
686 if (bluetooth_profiles.count == 0) {
687 *state = CONNECTION_BT_STATE_DEACTIVATED;
688 return CONNECTION_ERROR_NONE;
692 for (; i < bluetooth_profiles.count; i++) {
693 switch (bluetooth_profiles.profiles[i].profile_state) {
694 case NET_STATE_TYPE_ONLINE:
695 case NET_STATE_TYPE_READY:
696 *state = CONNECTION_BT_STATE_CONNECTED;
698 case NET_STATE_TYPE_IDLE:
699 case NET_STATE_TYPE_FAILURE:
700 case NET_STATE_TYPE_ASSOCIATION:
701 case NET_STATE_TYPE_CONFIGURATION:
702 case NET_STATE_TYPE_DISCONNECT:
703 *state = CONNECTION_BT_STATE_DISCONNECTED;
706 __libnet_clear_profile_list(&bluetooth_profiles);
707 return CONNECTION_ERROR_OPERATION_FAILED;
713 __libnet_clear_profile_list(&bluetooth_profiles);
715 return CONNECTION_ERROR_NONE;
718 int _connection_libnet_get_profile_iterator(connection_handle_s *conn_handle,
719 connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
723 net_profile_info_t *profiles = NULL;
725 struct _profile_list_s profile_list = {0, 0, NULL};
727 __libnet_clear_profile_list(&profile_iterator);
729 rv = net_get_all_profile_list(conn_handle->network_info_handle,
730 &profile_list.profiles, &profile_list.count);
731 if (rv == NET_ERR_ACCESS_DENIED) {
732 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
733 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
734 } else if (rv != NET_ERR_NO_SERVICE && rv != NET_ERR_NONE)
735 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
737 *profile_iter_h = &profile_iterator;
740 case CONNECTION_ITERATOR_TYPE_REGISTERED:
741 count = profile_list.count;
742 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
744 return CONNECTION_ERROR_NONE;
746 profiles = g_try_new0(net_profile_info_t, count);
747 if (profiles == NULL) {
748 __libnet_clear_profile_list(&profile_list); //LCOV_EXCL_LINE
749 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
752 profile_iterator.profiles = profiles;
754 memcpy(profiles, profile_list.profiles, sizeof(net_profile_info_t) * count);
757 case CONNECTION_ITERATOR_TYPE_CONNECTED:
758 count = __libnet_get_connected_count(&profile_list);
759 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
761 return CONNECTION_ERROR_NONE;
763 profiles = g_try_new0(net_profile_info_t, count);
764 if (profiles == NULL) {
765 __libnet_clear_profile_list(&profile_list); //LCOV_EXCL_LINE
766 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
769 profile_iterator.profiles = profiles;
771 __libnet_copy_connected_profile(&profiles, &profile_list);
774 case CONNECTION_ITERATOR_TYPE_DEFAULT:
775 count = __libnet_get_default_count(&profile_list);
776 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
778 return CONNECTION_ERROR_NONE;
780 profiles = g_try_new0(net_profile_info_t, count);
781 if (profiles == NULL) {
782 __libnet_clear_profile_list(&profile_list);
783 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
786 profile_iterator.profiles = profiles;
788 __libnet_copy_default_profile(&profiles, &profile_list);
793 __libnet_clear_profile_list(&profile_list);
795 profile_iterator.count = count;
797 return CONNECTION_ERROR_NONE;
800 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
802 if (profile_iter_h != &profile_iterator)
803 return CONNECTION_ERROR_INVALID_PARAMETER;
805 if (profile_iterator.count <= profile_iterator.next)
806 return CONNECTION_ERROR_ITERATOR_END;
808 *profile = &profile_iterator.profiles[profile_iterator.next];
809 profile_iterator.next++;
811 return CONNECTION_ERROR_NONE;
814 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
816 if (profile_iter_h != &profile_iterator)
819 if (profile_iterator.count <= profile_iterator.next)
825 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
827 if (profile_iter_h != &profile_iterator)
828 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
830 __libnet_clear_profile_list(&profile_iterator);
832 return CONNECTION_ERROR_NONE;
835 int _connection_libnet_get_current_profile(connection_handle_s *conn_handle,
836 connection_profile_h *profile)
838 net_profile_info_t active_profile;
841 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
842 if (rv == NET_ERR_NO_SERVICE)
843 return CONNECTION_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
844 else if (rv == NET_ERR_ACCESS_DENIED) {
845 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
846 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
847 } else if (rv != NET_ERR_NONE)
848 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
850 *profile = g_try_malloc0(sizeof(net_profile_info_t));
851 if (*profile == NULL)
852 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
854 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
855 prof_handle_list = g_slist_append(prof_handle_list, *profile);
857 return CONNECTION_ERROR_NONE;
860 int _connection_libnet_reset_profile(connection_handle_s *conn_handle,
861 connection_reset_option_e type, connection_cellular_subscriber_id_e id)
865 rv = net_reset_profile(conn_handle->network_info_handle, type, id);
866 if (rv == NET_ERR_ACCESS_DENIED)
867 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
868 else if (rv != NET_ERR_NONE)
869 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
871 return CONNECTION_ERROR_NONE;
874 int _connection_libnet_open_profile(connection_handle_s *conn_handle,
875 connection_profile_h profile)
879 if (!(_connection_libnet_check_profile_validity(profile))) {
880 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
881 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
884 net_profile_info_t *profile_info = profile;
886 if (profile_info->profile_type == NET_DEVICE_MESH)
887 rv = net_open_mesh_connection_with_profile(conn_handle->network_info_handle, //LCOV_EXCL_LINE
888 profile_info->profile_name);
890 rv = net_open_connection_with_profile(conn_handle->network_info_handle,
891 profile_info->profile_name);
893 if (rv == NET_ERR_ACCESS_DENIED)
894 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
895 else if (rv != NET_ERR_NONE)
896 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
898 return CONNECTION_ERROR_NONE;
901 int _connection_libnet_get_cellular_service_profile(connection_handle_s *conn_handle,
902 connection_cellular_service_type_e type, connection_profile_h *profile)
905 int rv = NET_ERR_NONE;
906 #if defined TIZEN_DUALSIM_ENABLE
907 int default_subscriber_id = 0;
908 char subscriber_id[3];
911 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
912 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
914 rv = net_get_profile_list(conn_handle->network_info_handle,
915 NET_DEVICE_CELLULAR, &cellular_profiles.profiles,
916 &cellular_profiles.count);
917 if (rv == NET_ERR_ACCESS_DENIED) {
918 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
919 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
920 } else if (rv != NET_ERR_NONE) {
921 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv); //LCOV_EXCL_LINE
922 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
925 #if defined TIZEN_DUALSIM_ENABLE
926 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
927 &default_subscriber_id) != 0) {
928 CONNECTION_LOG(CONNECTION_ERROR,
929 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
930 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
931 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
934 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
937 for (i = 0; i < cellular_profiles.count; i++)
938 if (cellular_profiles.profiles[i].profile_info.pdp.service_type == service_type)
939 #if defined TIZEN_DUALSIM_ENABLE
940 if (g_str_has_suffix(
941 cellular_profiles.profiles[i].profile_info.pdp.ps_modem_path,
942 subscriber_id) == TRUE)
946 if (i >= cellular_profiles.count) {
947 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
948 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
951 *profile = g_try_malloc0(sizeof(net_profile_info_t));
952 if (*profile == NULL) {
953 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
954 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
957 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
959 if (cellular_profiles.profiles[i].profile_info.pdp.default_conn)
963 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
964 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
967 for (j = 0; j < cellular_profiles.count; j++) {
971 if (cellular_profiles.profiles[j].profile_info.pdp.service_type != service_type)
974 if (cellular_profiles.profiles[j].profile_info.pdp.default_conn) {
975 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
982 __libnet_clear_profile_list(&cellular_profiles);
983 prof_handle_list = g_slist_append(prof_handle_list, *profile);
985 return CONNECTION_ERROR_NONE;
988 int _connection_libnet_set_cellular_service_profile_sync(connection_handle_s *conn_handle,
989 connection_cellular_service_type_e type, connection_profile_h profile)
993 if (!(_connection_libnet_check_profile_validity(profile))) {
994 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
995 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
998 net_profile_info_t *profile_info = profile;
999 connection_cellular_service_type_e service_type;
1001 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->profile_info.pdp.service_type);
1003 if (service_type != type)
1004 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1006 rv = net_set_default_cellular_service_profile(conn_handle->network_info_handle,
1007 profile_info->profile_name);
1008 if (rv == NET_ERR_ACCESS_DENIED) {
1009 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1010 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1011 } else if (rv != NET_ERR_NONE)
1012 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1014 return CONNECTION_ERROR_NONE;
1017 int _connection_libnet_set_cellular_service_profile_async(connection_handle_s *conn_handle,
1018 connection_cellular_service_type_e type, connection_profile_h profile)
1022 if (!(_connection_libnet_check_profile_validity(profile))) {
1023 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1024 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1027 net_profile_info_t *profile_info = profile;
1028 connection_cellular_service_type_e service_type;
1030 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->profile_info.pdp.service_type);
1032 if (service_type != type)
1033 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1035 rv = net_set_default_cellular_service_profile_async(conn_handle->network_info_handle,
1036 profile_info->profile_name);
1037 if (rv == NET_ERR_ACCESS_DENIED) {
1038 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1039 } else if (rv != NET_ERR_NONE)
1040 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1042 return CONNECTION_ERROR_NONE;
1045 int _connection_libnet_close_profile(connection_handle_s *conn_handle, connection_profile_h profile)
1049 if (!(_connection_libnet_check_profile_validity(profile))) {
1050 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1051 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1054 net_profile_info_t *profile_info = profile;
1056 if (profile_info->profile_type == NET_DEVICE_MESH)
1057 rv = net_close_mesh_connection(conn_handle->network_info_handle, profile_info->profile_name); //LCOV_EXCL_LINE
1059 rv = net_close_connection(conn_handle->network_info_handle, profile_info->profile_name);
1061 if (rv == NET_ERR_ACCESS_DENIED)
1062 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1063 else if (rv != NET_ERR_NONE)
1064 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1066 return CONNECTION_ERROR_NONE;
1069 int _connection_libnet_add_route(connection_handle_s *conn_handle,
1070 const char *interface_name, const char *host_address)
1073 char *endstr = NULL;
1074 int address_family = 0;
1076 address_family = AF_INET;
1078 endstr = strrchr(host_address, '.');
1079 if (endstr == NULL ||
1080 strcmp(endstr, ".0") == 0 ||
1081 strncmp(host_address, "0.", 2) == 0 ||
1082 strstr(host_address, "255") != NULL) {
1083 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1084 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1087 rv = net_add_route(conn_handle->network_info_handle,
1088 host_address, interface_name, address_family);
1089 if (rv == NET_ERR_ACCESS_DENIED) {
1090 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1091 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1092 } else if (rv != NET_ERR_NONE)
1093 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1095 return CONNECTION_ERROR_NONE;
1098 int _connection_libnet_remove_route(connection_handle_s *conn_handle,
1099 const char *interface_name, const char *host_address)
1102 char *endstr = strrchr(host_address, '.');
1103 int address_family = 0;
1105 address_family = AF_INET;
1107 endstr = strrchr(host_address, '.');
1108 if (endstr == NULL ||
1109 strcmp(endstr, ".0") == 0 ||
1110 strncmp(host_address, "0.", 2) == 0 ||
1111 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1112 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1113 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1116 rv = net_remove_route(conn_handle->network_info_handle,
1117 host_address, interface_name, address_family);
1118 if (rv == NET_ERR_ACCESS_DENIED) {
1119 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1120 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1121 } else if (rv != NET_ERR_NONE)
1122 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1124 return CONNECTION_ERROR_NONE;
1127 int _connection_libnet_add_route_ipv6(connection_handle_s *conn_handle,
1128 const char *interface_name, const char *host_address, const char *gateway)
1131 int address_family = 0;
1133 address_family = AF_INET6;
1135 if (strncmp(host_address, "fe80:", 5) == 0 ||
1136 strncmp(host_address, "ff00:", 5) == 0 ||
1137 strncmp(host_address, "::", 2) == 0) {
1138 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1139 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1142 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1143 host_address, interface_name, address_family, gateway);
1144 if (rv == NET_ERR_ACCESS_DENIED) {
1145 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1146 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1147 } else if (rv != NET_ERR_NONE)
1148 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1150 return CONNECTION_ERROR_NONE;
1153 int _connection_libnet_remove_route_ipv6(connection_handle_s *conn_handle,
1154 const char *interface_name, const char *host_address, const char *gateway)
1157 int address_family = 0;
1159 address_family = AF_INET6;
1161 if (strncmp(host_address, "fe80:", 5) == 0 ||
1162 strncmp(host_address, "ff00:", 5) == 0 ||
1163 strncmp(host_address, "::", 2) == 0) {
1164 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1165 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1168 rv = net_remove_route_ipv6(conn_handle->network_info_handle,
1169 host_address, interface_name, address_family, gateway);
1170 if (rv == NET_ERR_ACCESS_DENIED) {
1171 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1172 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1173 } else if (rv != NET_ERR_NONE)
1174 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1176 return CONNECTION_ERROR_NONE;
1179 int _connection_libnet_add_route_entry(connection_handle_s *conn_handle,
1180 connection_address_family_e address_family, const char *interface_name,
1181 const char *host_address, const char *gateway)
1184 char *endstr = NULL;
1185 int address_family_type = 0;
1187 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1188 address_family_type = AF_INET;
1190 address_family_type = AF_INET6;
1192 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1194 endstr = strrchr(host_address, '.');
1195 if (endstr == NULL ||
1196 strcmp(endstr, ".0") == 0 ||
1197 strncmp(host_address, "0.", 2) == 0 ||
1198 strstr(host_address, "255") != NULL) {
1199 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1200 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1203 rv = net_add_route_entry(conn_handle->network_info_handle,
1204 host_address, interface_name, address_family_type, gateway);
1205 if (rv == NET_ERR_ACCESS_DENIED) {
1206 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1207 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1208 } else if (rv != NET_ERR_NONE)
1209 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1213 if (strncmp(host_address, "fe80:", 5) == 0 ||
1214 strncmp(host_address, "ff00:", 5) == 0 ||
1215 strncmp(host_address, "::", 2) == 0) {
1216 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1217 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1220 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1221 host_address, interface_name, address_family_type, gateway);
1222 if (rv == NET_ERR_ACCESS_DENIED) {
1223 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1224 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1225 } else if (rv != NET_ERR_NONE)
1226 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1229 return CONNECTION_ERROR_NONE;
1232 int _connection_libnet_remove_route_entry(connection_handle_s *conn_handle,
1233 connection_address_family_e address_family, const char *interface_name,
1234 const char *host_address, const char *gateway)
1237 char *endstr = strrchr(host_address, '.');
1238 int address_family_type = 0;
1240 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1241 address_family_type = AF_INET;
1243 address_family_type = AF_INET6;
1245 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1246 endstr = strrchr(host_address, '.');
1247 if (endstr == NULL ||
1248 strcmp(endstr, ".0") == 0 ||
1249 strncmp(host_address, "0.", 2) == 0 ||
1250 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1251 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1252 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1255 rv = net_remove_route_entry(conn_handle->network_info_handle, host_address,
1256 interface_name, address_family_type, gateway);
1257 if (rv == NET_ERR_ACCESS_DENIED) {
1258 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1259 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1260 } else if (rv != NET_ERR_NONE)
1261 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1265 if (strncmp(host_address, "fe80:", 5) == 0 ||
1266 strncmp(host_address, "ff00:", 5) == 0 ||
1267 strncmp(host_address, "::", 2) == 0) {
1268 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1269 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1272 rv = net_remove_route_ipv6(conn_handle->network_info_handle, host_address,
1273 interface_name, address_family_type, gateway);
1274 if (rv == NET_ERR_ACCESS_DENIED) {
1275 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1276 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1277 } else if (rv != NET_ERR_NONE)
1278 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1281 return CONNECTION_ERROR_NONE;
1284 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1286 prof_handle_list = g_slist_append(prof_handle_list, profile);
1289 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1291 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1295 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1296 connection_profile_state_changed_cb callback, void *user_data)
1298 net_profile_info_t *profile_info = profile;
1299 char *profile_name = g_strdup(profile_info->profile_name);
1301 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1302 if (profile_cb_info == NULL) {
1303 g_free(profile_name); //LCOV_EXCL_LINE
1304 return false; //LCOV_EXCL_LINE
1307 profile_cb_info->callback = callback;
1308 profile_cb_info->user_data = user_data;
1309 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->profile_state);
1311 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1316 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1318 net_profile_info_t *profile_info = profile;
1320 if (g_hash_table_remove(profile_cb_table, profile_info->profile_name) == TRUE)
1323 return false; //LCOV_EXCL_LINE
1326 int _connection_libnet_set_statistics(connection_handle_s *conn_handle,
1327 net_device_t device_type, net_statistics_type_e statistics_type)
1330 rv = net_set_statistics(conn_handle->network_info_handle,
1331 device_type, statistics_type);
1332 if (rv == NET_ERR_ACCESS_DENIED) {
1333 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1334 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1335 } else if (rv != NET_ERR_NONE)
1336 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1338 return CONNECTION_ERROR_NONE;
1341 int _connection_libnet_get_statistics(connection_handle_s *conn_handle,
1342 net_statistics_type_e statistics_type, unsigned long long *size)
1345 rv = net_get_statistics(conn_handle->network_info_handle,
1346 NET_DEVICE_WIFI, statistics_type, size);
1347 if (rv == NET_ERR_ACCESS_DENIED) {
1348 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1349 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1350 } else if (rv != NET_ERR_NONE)
1351 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1353 return CONNECTION_ERROR_NONE;
1356 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1357 connection_cellular_subscriber_id_e sim_id)
1359 char *modem_path = NULL;
1360 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1362 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1363 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id); //LCOV_EXCL_LINE
1364 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1368 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path"); //LCOV_EXCL_LINE
1369 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1372 g_strlcpy(profile_info->profile_info.pdp.ps_modem_path, modem_path,
1373 NET_PROFILE_NAME_LEN_MAX);
1376 return CONNECTION_ERROR_NONE;
1379 int _connection_libnet_enable_ethernet_eap(bool enable, const char *profilename)
1383 rv = net_ethernet_eap_enable(enable, profilename);
1384 if (rv == NET_ERR_ACCESS_DENIED) {
1385 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1386 return CONNECTION_ERROR_PERMISSION_DENIED;
1387 } else if (rv != NET_ERR_NONE) {
1388 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable EAP over ethernet[%d]", rv);
1389 return CONNECTION_ERROR_OPERATION_FAILED;
1392 return CONNECTION_ERROR_NONE;
1395 int _connection_libnet_ethernet_eap_enabled(const char *profilename, bool *enabled)
1398 gboolean eap_enabled = false;
1400 rv = net_ethernet_eap_enabled(profilename, &eap_enabled);
1401 if (rv == NET_ERR_ACCESS_DENIED) {
1402 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1403 return CONNECTION_ERROR_PERMISSION_DENIED;
1404 } else if (rv != NET_ERR_NONE) {
1405 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable EAP over ethernet[%d]", rv);
1406 return CONNECTION_ERROR_OPERATION_FAILED;
1409 *enabled = eap_enabled;
1410 return CONNECTION_ERROR_NONE;
1413 int _connection_libnet_profile_save_ethernet_eap_config(connection_handle_s *conn_handle,
1414 connection_profile_h profile)
1418 net_profile_info_t *profile_info = profile;
1420 rv = net_save_ethernet_eap_config(conn_handle->network_info_handle,
1421 &profile_info->profile_info.ethernet.net_info);
1423 if (rv == NET_ERR_ACCESS_DENIED) {
1424 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1425 return CONNECTION_ERROR_PERMISSION_DENIED;
1426 } else if (rv != NET_ERR_NONE) {
1427 CONNECTION_LOG(CONNECTION_ERROR, "Failed to save eap config[%d]", rv);
1428 return CONNECTION_ERROR_OPERATION_FAILED;
1431 return CONNECTION_ERROR_NONE;
1434 int _connection_libnet_check_get_privilege(void)
1438 rv = net_check_get_privilege();
1439 if (rv == NET_ERR_ACCESS_DENIED) {
1440 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1441 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1442 } else if (rv != NET_ERR_NONE)
1443 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1445 return CONNECTION_ERROR_NONE;
1448 int _connection_libnet_check_profile_privilege(void)
1452 rv = net_check_profile_privilege();
1453 if (rv == NET_ERR_ACCESS_DENIED) {
1454 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1455 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1456 } else if (rv != NET_ERR_NONE)
1457 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1459 return CONNECTION_ERROR_NONE;
1462 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1464 if (!connection_is_feature_checked[feature]) {
1465 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1466 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
1467 set_last_result(CONNECTION_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
1468 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1470 connection_is_feature_checked[feature] = true;
1472 return connection_feature_supported[feature];
1475 int _connection_check_feature_supported(const char *feature_name, ...)
1480 bool feature_supported = false;
1482 va_start(list, feature_name);
1485 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1486 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1487 if (strcmp(key, WIFI_FEATURE) == 0)
1488 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1489 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1490 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1491 if (strcmp(key, ETHERNET_FEATURE) == 0)
1492 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1494 feature_supported |= value;
1495 key = va_arg(list, const char *);
1498 if (!feature_supported) {
1499 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1500 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1502 return CONNECTION_ERROR_NOT_SUPPORTED;
1506 set_last_result(CONNECTION_ERROR_NONE);
1507 return CONNECTION_ERROR_NONE;
1511 int _connection_libnet_start_tcpdump(connection_handle_s *conn_handle)
1513 connection_error_e result = CONNECTION_ERROR_NONE;
1514 net_err_t ret = NET_ERR_NONE;
1516 ret = net_start_tcpdump(conn_handle->network_info_handle);
1517 result = __libnet_convert_to_cp_error_type(ret);
1522 int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle)
1524 connection_error_e result = CONNECTION_ERROR_NONE;
1525 net_err_t ret = NET_ERR_NONE;
1527 ret = net_stop_tcpdump(conn_handle->network_info_handle);
1528 result = __libnet_convert_to_cp_error_type(ret);
1533 int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle,
1534 gboolean *tcpdump_state)
1536 connection_error_e result = CONNECTION_ERROR_NONE;
1537 net_err_t ret = NET_ERR_NONE;
1539 ret = net_get_tcpdump_state(conn_handle->network_info_handle, tcpdump_state);
1540 result = __libnet_convert_to_cp_error_type(ret);
1546 void _connection_lock(void)
1548 if (g_conn_thread_mutex_ref == 0)
1549 pthread_mutex_lock(&g_conn_thread_mutex);
1551 g_conn_thread_mutex_ref++;
1554 void _connection_unlock(void)
1556 if (g_conn_thread_mutex_ref == 1)
1557 pthread_mutex_unlock(&g_conn_thread_mutex);
1559 g_conn_thread_mutex_ref--;
1562 if (g_conn_thread_mutex_ref < 0) {
1563 CONNECTION_LOG(CONNECTION_ERROR,
1564 "Error scenario, thread specific mutex ref is negative !!!");
1565 g_conn_thread_mutex_ref = 0;