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)
173 bool is_requested = false;
174 connection_error_e result = CONNECTION_ERROR_NONE;
176 connection_handle_s conn_handle_local;
177 connection_handle_s *conn_handle = &conn_handle_local;
178 connection_handle_s *conn_handle_origin = (connection_handle_s *)user_data;
180 if(!_connection_check_handle_validity(conn_handle_origin)) {
181 CONNECTION_LOG(CONNECTION_INFO, "Invalid handle");
185 memcpy(conn_handle, conn_handle_origin, sizeof(connection_handle_s));
188 switch (event_cb->Event) {
189 case NET_EVENT_OPEN_RSP:
192 case NET_EVENT_OPEN_IND:
193 result = __libnet_convert_to_cp_error_type(event_cb->Error);
194 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
195 (is_requested) ? "RSP" : "IND",
196 __libnet_convert_cp_error_type_to_string(result));
199 if (conn_handle->opened_callback) {
200 conn_handle->opened_callback(result,
201 conn_handle->opened_user_data);
203 conn_handle->opened_callback = NULL;
204 conn_handle->opened_user_data = NULL;
208 switch (event_cb->Error) {
210 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
211 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
213 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
216 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
217 __libnet_convert_cp_error_type_to_string(result));
220 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
223 case NET_EVENT_CLOSE_RSP:
226 case NET_EVENT_CLOSE_IND:
227 result = __libnet_convert_to_cp_error_type(event_cb->Error);
228 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
229 (is_requested) ? "RSP" : "IND",
230 __libnet_convert_cp_error_type_to_string(result));
233 if (conn_handle->closed_callback) {
234 conn_handle->closed_callback(result,
235 conn_handle->closed_user_data);
237 conn_handle->closed_callback = NULL;
238 conn_handle->closed_user_data = NULL;
242 switch (event_cb->Error) {
244 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
246 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
249 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
250 __libnet_convert_cp_error_type_to_string(result));
254 case NET_EVENT_NET_STATE_IND:
255 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
257 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->ProfileName);
266 __libnet_state_changed_cb(event_cb->ProfileName, 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.ProfileState == 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.ProfileState != NET_STATE_TYPE_ONLINE)
416 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
417 conn_handle->internet_state_changed_user_data);
428 static int __libnet_get_connected_count(struct _profile_list_s *profile_list)
433 for (; i < profile_list->count; i++) {
434 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
435 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
442 static void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
446 for (; i < source->count; i++) {
447 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
448 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
449 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
456 static int __libnet_get_default_count(struct _profile_list_s *profile_list)
461 for (; i < profile_list->count; i++) {
462 if (profile_list->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
463 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
471 static void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
475 for (; i < source->count; i++) {
476 if (source->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
477 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
478 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
486 int _connection_libnet_init(connection_handle_s *conn_handle)
490 rv = net_register_client(&(conn_handle->network_info_handle),
491 (net_event_cb_t)__libnet_evt_cb, conn_handle);
492 if (rv != NET_ERR_NONE)
495 if (profile_cb_table == NULL)
496 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
501 bool _connection_libnet_deinit(connection_handle_s *conn_handle, bool is_empty)
503 net_deregister_client(conn_handle->network_info_handle);
506 if (profile_cb_table) {
507 g_hash_table_destroy(profile_cb_table);
508 profile_cb_table = NULL;
511 __libnet_clear_profile_list(&profile_iterator);
513 if (prof_handle_list) {
514 g_slist_free_full(prof_handle_list, g_free);
515 prof_handle_list = NULL;
523 void _connection_set_cs_tid(int tid, connection_handle_s *conn_handle)
525 net_set_cs_tid(tid, conn_handle->network_info_handle);
528 void _connection_unset_cs_tid(int tid, connection_handle_s *conn_handle)
530 net_unset_cs_tid(tid, conn_handle->network_info_handle);
534 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
542 for (list = prof_handle_list; list; list = list->next)
543 if (profile == list->data) return true;
545 for (; i < profile_iterator.count; i++)
546 if (profile == &profile_iterator.profiles[i]) return true;
551 int _connection_libnet_get_metered_state(connection_handle_s *conn_handle, bool* is_metered)
556 rv = net_get_metered_state(conn_handle->network_info_handle, &status);
557 if (rv == NET_ERR_ACCESS_DENIED) {
558 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
559 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
560 } else if (rv != NET_ERR_NONE) {
561 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv); //LCOV_EXCL_LINE
562 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
569 return CONNECTION_ERROR_NONE;
572 int _connection_libnet_get_wifi_state(connection_handle_s *conn_handle, connection_wifi_state_e *state)
575 net_wifi_state_t wlan_state;
577 rv = net_get_wifi_state(conn_handle->network_info_handle, &wlan_state);
578 if (rv == NET_ERR_ACCESS_DENIED) {
579 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
580 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
581 } else if (rv != NET_ERR_NONE) {
582 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
583 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
586 switch (wlan_state) {
588 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
591 case WIFI_ASSOCIATION:
592 case WIFI_CONFIGURATION:
593 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
596 case WIFI_DISCONNECTING:
597 *state = CONNECTION_WIFI_STATE_CONNECTED;
600 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state"); //LCOV_EXCL_LINE
601 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
604 return CONNECTION_ERROR_NONE;
608 int _connection_libnet_get_ethernet_state(connection_handle_s *conn_handle,
609 connection_ethernet_state_e *state)
612 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
613 rv = net_get_profile_list(conn_handle->network_info_handle,
614 NET_DEVICE_ETHERNET, ðernet_profiles.profiles,
615 ðernet_profiles.count);
616 if (rv == NET_ERR_ACCESS_DENIED) {
617 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
618 return CONNECTION_ERROR_PERMISSION_DENIED;
621 if (ethernet_profiles.count == 0) {
622 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
623 return CONNECTION_ERROR_NONE;
626 switch (ethernet_profiles.profiles->ProfileState) {
627 case NET_STATE_TYPE_ONLINE:
628 case NET_STATE_TYPE_READY:
629 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
631 case NET_STATE_TYPE_IDLE:
632 case NET_STATE_TYPE_FAILURE:
633 case NET_STATE_TYPE_ASSOCIATION:
634 case NET_STATE_TYPE_CONFIGURATION:
635 case NET_STATE_TYPE_DISCONNECT:
636 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
639 __libnet_clear_profile_list(ðernet_profiles);
640 return CONNECTION_ERROR_OPERATION_FAILED;
643 __libnet_clear_profile_list(ðernet_profiles);
645 return CONNECTION_ERROR_NONE;
648 int _connection_libnet_get_ethernet_cable_state(connection_handle_s *conn_handle,
649 connection_ethernet_cable_state_e* state)
654 rv = net_get_ethernet_cable_state(conn_handle->network_info_handle, &status);
655 if (rv == NET_ERR_ACCESS_DENIED) {
656 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
657 return CONNECTION_ERROR_PERMISSION_DENIED;
658 } else if (rv != NET_ERR_NONE) {
659 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
660 return CONNECTION_ERROR_OPERATION_FAILED;
664 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
666 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
667 return CONNECTION_ERROR_NONE;
671 int _connection_libnet_get_bluetooth_state(connection_handle_s *conn_handle, connection_bt_state_e *state)
675 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
676 rv = net_get_profile_list(conn_handle->network_info_handle,
677 NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles,
678 &bluetooth_profiles.count);
679 if (rv == NET_ERR_ACCESS_DENIED) {
680 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
681 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
684 if (bluetooth_profiles.count == 0) {
685 *state = CONNECTION_BT_STATE_DEACTIVATED;
686 return CONNECTION_ERROR_NONE;
690 for (; i < bluetooth_profiles.count; i++) {
691 switch (bluetooth_profiles.profiles[i].ProfileState) {
692 case NET_STATE_TYPE_ONLINE:
693 case NET_STATE_TYPE_READY:
694 *state = CONNECTION_BT_STATE_CONNECTED;
696 case NET_STATE_TYPE_IDLE:
697 case NET_STATE_TYPE_FAILURE:
698 case NET_STATE_TYPE_ASSOCIATION:
699 case NET_STATE_TYPE_CONFIGURATION:
700 case NET_STATE_TYPE_DISCONNECT:
701 *state = CONNECTION_BT_STATE_DISCONNECTED;
704 __libnet_clear_profile_list(&bluetooth_profiles);
705 return CONNECTION_ERROR_OPERATION_FAILED;
711 __libnet_clear_profile_list(&bluetooth_profiles);
713 return CONNECTION_ERROR_NONE;
716 int _connection_libnet_get_profile_iterator(connection_handle_s *conn_handle,
717 connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
721 net_profile_info_t *profiles = NULL;
723 struct _profile_list_s profile_list = {0, 0, NULL};
725 __libnet_clear_profile_list(&profile_iterator);
727 rv = net_get_all_profile_list(conn_handle->network_info_handle,
728 &profile_list.profiles, &profile_list.count);
729 if (rv == NET_ERR_ACCESS_DENIED) {
730 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
731 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
732 } else if (rv != NET_ERR_NO_SERVICE && rv != NET_ERR_NONE)
733 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
735 *profile_iter_h = &profile_iterator;
738 case CONNECTION_ITERATOR_TYPE_REGISTERED:
739 count = profile_list.count;
740 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
742 return CONNECTION_ERROR_NONE;
744 profiles = g_try_new0(net_profile_info_t, count);
745 if (profiles == NULL) {
746 __libnet_clear_profile_list(&profile_list); //LCOV_EXCL_LINE
747 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
750 profile_iterator.profiles = profiles;
752 memcpy(profiles, profile_list.profiles, sizeof(net_profile_info_t) * count);
755 case CONNECTION_ITERATOR_TYPE_CONNECTED:
756 count = __libnet_get_connected_count(&profile_list);
757 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
759 return CONNECTION_ERROR_NONE;
761 profiles = g_try_new0(net_profile_info_t, count);
762 if (profiles == NULL) {
763 __libnet_clear_profile_list(&profile_list); //LCOV_EXCL_LINE
764 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
767 profile_iterator.profiles = profiles;
769 __libnet_copy_connected_profile(&profiles, &profile_list);
772 case CONNECTION_ITERATOR_TYPE_DEFAULT:
773 count = __libnet_get_default_count(&profile_list);
774 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
776 return CONNECTION_ERROR_NONE;
778 profiles = g_try_new0(net_profile_info_t, count);
779 if (profiles == NULL) {
780 __libnet_clear_profile_list(&profile_list);
781 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
784 profile_iterator.profiles = profiles;
786 __libnet_copy_default_profile(&profiles, &profile_list);
791 __libnet_clear_profile_list(&profile_list);
793 profile_iterator.count = count;
795 return CONNECTION_ERROR_NONE;
798 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
800 if (profile_iter_h != &profile_iterator)
801 return CONNECTION_ERROR_INVALID_PARAMETER;
803 if (profile_iterator.count <= profile_iterator.next)
804 return CONNECTION_ERROR_ITERATOR_END;
806 *profile = &profile_iterator.profiles[profile_iterator.next];
807 profile_iterator.next++;
809 return CONNECTION_ERROR_NONE;
812 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
814 if (profile_iter_h != &profile_iterator)
817 if (profile_iterator.count <= profile_iterator.next)
823 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
825 if (profile_iter_h != &profile_iterator)
826 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
828 __libnet_clear_profile_list(&profile_iterator);
830 return CONNECTION_ERROR_NONE;
833 int _connection_libnet_get_current_profile(connection_handle_s *conn_handle,
834 connection_profile_h *profile)
836 net_profile_info_t active_profile;
839 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
840 if (rv == NET_ERR_NO_SERVICE)
841 return CONNECTION_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
842 else if (rv == NET_ERR_ACCESS_DENIED) {
843 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
844 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
845 } else if (rv != NET_ERR_NONE)
846 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
848 *profile = g_try_malloc0(sizeof(net_profile_info_t));
849 if (*profile == NULL)
850 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
852 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
853 prof_handle_list = g_slist_append(prof_handle_list, *profile);
855 return CONNECTION_ERROR_NONE;
858 int _connection_libnet_reset_profile(connection_handle_s *conn_handle,
859 connection_reset_option_e type, connection_cellular_subscriber_id_e id)
863 rv = net_reset_profile(conn_handle->network_info_handle, type, id);
864 if (rv == NET_ERR_ACCESS_DENIED)
865 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
866 else if (rv != NET_ERR_NONE)
867 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
869 return CONNECTION_ERROR_NONE;
872 int _connection_libnet_open_profile(connection_handle_s *conn_handle,
873 connection_profile_h profile)
877 if (!(_connection_libnet_check_profile_validity(profile))) {
878 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
879 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
882 net_profile_info_t *profile_info = profile;
884 if (profile_info->profile_type == NET_DEVICE_MESH)
885 rv = net_open_mesh_connection_with_profile(conn_handle->network_info_handle, //LCOV_EXCL_LINE
886 profile_info->ProfileName);
888 rv = net_open_connection_with_profile(conn_handle->network_info_handle,
889 profile_info->ProfileName);
891 if (rv == NET_ERR_ACCESS_DENIED)
892 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
893 else if (rv != NET_ERR_NONE)
894 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
896 return CONNECTION_ERROR_NONE;
899 int _connection_libnet_get_cellular_service_profile(connection_handle_s *conn_handle,
900 connection_cellular_service_type_e type, connection_profile_h *profile)
903 int rv = NET_ERR_NONE;
904 #if defined TIZEN_DUALSIM_ENABLE
905 int default_subscriber_id = 0;
906 char subscriber_id[3];
909 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
910 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
912 rv = net_get_profile_list(conn_handle->network_info_handle,
913 NET_DEVICE_CELLULAR, &cellular_profiles.profiles,
914 &cellular_profiles.count);
915 if (rv == NET_ERR_ACCESS_DENIED) {
916 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
917 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
918 } else if (rv != NET_ERR_NONE) {
919 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv); //LCOV_EXCL_LINE
920 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
923 #if defined TIZEN_DUALSIM_ENABLE
924 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
925 &default_subscriber_id) != 0) {
926 CONNECTION_LOG(CONNECTION_ERROR,
927 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
928 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
929 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
932 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
935 for (i = 0; i < cellular_profiles.count; i++)
936 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
937 #if defined TIZEN_DUALSIM_ENABLE
938 if (g_str_has_suffix(
939 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
940 subscriber_id) == TRUE)
944 if (i >= cellular_profiles.count) {
945 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
946 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
949 *profile = g_try_malloc0(sizeof(net_profile_info_t));
950 if (*profile == NULL) {
951 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
952 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
955 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
957 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
961 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
962 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
965 for (j = 0; j < cellular_profiles.count; j++) {
969 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
972 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
973 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
980 __libnet_clear_profile_list(&cellular_profiles);
981 prof_handle_list = g_slist_append(prof_handle_list, *profile);
983 return CONNECTION_ERROR_NONE;
986 int _connection_libnet_set_cellular_service_profile_sync(connection_handle_s *conn_handle,
987 connection_cellular_service_type_e type, connection_profile_h profile)
991 if (!(_connection_libnet_check_profile_validity(profile))) {
992 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
993 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
996 net_profile_info_t *profile_info = profile;
997 connection_cellular_service_type_e service_type;
999 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1001 if (service_type != type)
1002 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1004 rv = net_set_default_cellular_service_profile(conn_handle->network_info_handle,
1005 profile_info->ProfileName);
1006 if (rv == NET_ERR_ACCESS_DENIED) {
1007 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1008 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1009 } else if (rv != NET_ERR_NONE)
1010 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1012 return CONNECTION_ERROR_NONE;
1015 int _connection_libnet_set_cellular_service_profile_async(connection_handle_s *conn_handle,
1016 connection_cellular_service_type_e type, connection_profile_h profile)
1020 if (!(_connection_libnet_check_profile_validity(profile))) {
1021 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1022 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1025 net_profile_info_t *profile_info = profile;
1026 connection_cellular_service_type_e service_type;
1028 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1030 if (service_type != type)
1031 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1033 rv = net_set_default_cellular_service_profile_async(conn_handle->network_info_handle,
1034 profile_info->ProfileName);
1035 if (rv == NET_ERR_ACCESS_DENIED) {
1036 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1037 } else if (rv != NET_ERR_NONE)
1038 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1040 return CONNECTION_ERROR_NONE;
1043 int _connection_libnet_close_profile(connection_handle_s *conn_handle, connection_profile_h profile)
1047 if (!(_connection_libnet_check_profile_validity(profile))) {
1048 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1049 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1052 net_profile_info_t *profile_info = profile;
1054 if (profile_info->profile_type == NET_DEVICE_MESH)
1055 rv = net_close_mesh_connection(conn_handle->network_info_handle, profile_info->ProfileName); //LCOV_EXCL_LINE
1057 rv = net_close_connection(conn_handle->network_info_handle, profile_info->ProfileName);
1059 if (rv == NET_ERR_ACCESS_DENIED)
1060 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1061 else if (rv != NET_ERR_NONE)
1062 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1064 return CONNECTION_ERROR_NONE;
1067 int _connection_libnet_add_route(connection_handle_s *conn_handle,
1068 const char *interface_name, const char *host_address)
1071 char *endstr = NULL;
1072 int address_family = 0;
1074 address_family = AF_INET;
1076 endstr = strrchr(host_address, '.');
1077 if (endstr == NULL ||
1078 strcmp(endstr, ".0") == 0 ||
1079 strncmp(host_address, "0.", 2) == 0 ||
1080 strstr(host_address, "255") != NULL) {
1081 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1082 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1085 rv = net_add_route(conn_handle->network_info_handle,
1086 host_address, interface_name, address_family);
1087 if (rv == NET_ERR_ACCESS_DENIED) {
1088 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1089 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1090 } else if (rv != NET_ERR_NONE)
1091 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1093 return CONNECTION_ERROR_NONE;
1096 int _connection_libnet_remove_route(connection_handle_s *conn_handle,
1097 const char *interface_name, const char *host_address)
1100 char *endstr = strrchr(host_address, '.');
1101 int address_family = 0;
1103 address_family = AF_INET;
1105 endstr = strrchr(host_address, '.');
1106 if (endstr == NULL ||
1107 strcmp(endstr, ".0") == 0 ||
1108 strncmp(host_address, "0.", 2) == 0 ||
1109 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1110 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1111 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1114 rv = net_remove_route(conn_handle->network_info_handle,
1115 host_address, interface_name, address_family);
1116 if (rv == NET_ERR_ACCESS_DENIED) {
1117 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1118 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1119 } else if (rv != NET_ERR_NONE)
1120 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1122 return CONNECTION_ERROR_NONE;
1125 int _connection_libnet_add_route_ipv6(connection_handle_s *conn_handle,
1126 const char *interface_name, const char *host_address, const char *gateway)
1129 int address_family = 0;
1131 address_family = AF_INET6;
1133 if (strncmp(host_address, "fe80:", 5) == 0 ||
1134 strncmp(host_address, "ff00:", 5) == 0 ||
1135 strncmp(host_address, "::", 2) == 0) {
1136 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1137 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1140 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1141 host_address, interface_name, address_family, gateway);
1142 if (rv == NET_ERR_ACCESS_DENIED) {
1143 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1144 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1145 } else if (rv != NET_ERR_NONE)
1146 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1148 return CONNECTION_ERROR_NONE;
1151 int _connection_libnet_remove_route_ipv6(connection_handle_s *conn_handle,
1152 const char *interface_name, const char *host_address, const char *gateway)
1155 int address_family = 0;
1157 address_family = AF_INET6;
1159 if (strncmp(host_address, "fe80:", 5) == 0 ||
1160 strncmp(host_address, "ff00:", 5) == 0 ||
1161 strncmp(host_address, "::", 2) == 0) {
1162 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1163 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1166 rv = net_remove_route_ipv6(conn_handle->network_info_handle,
1167 host_address, interface_name, address_family, gateway);
1168 if (rv == NET_ERR_ACCESS_DENIED) {
1169 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1170 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1171 } else if (rv != NET_ERR_NONE)
1172 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1174 return CONNECTION_ERROR_NONE;
1177 int _connection_libnet_add_route_entry(connection_handle_s *conn_handle,
1178 connection_address_family_e address_family, const char *interface_name,
1179 const char *host_address, const char *gateway)
1182 char *endstr = NULL;
1183 int address_family_type = 0;
1185 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1186 address_family_type = AF_INET;
1188 address_family_type = AF_INET6;
1190 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1192 endstr = strrchr(host_address, '.');
1193 if (endstr == NULL ||
1194 strcmp(endstr, ".0") == 0 ||
1195 strncmp(host_address, "0.", 2) == 0 ||
1196 strstr(host_address, "255") != NULL) {
1197 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1198 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1201 rv = net_add_route_entry(conn_handle->network_info_handle,
1202 host_address, interface_name, address_family_type, gateway);
1203 if (rv == NET_ERR_ACCESS_DENIED) {
1204 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1205 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1206 } else if (rv != NET_ERR_NONE)
1207 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1211 if (strncmp(host_address, "fe80:", 5) == 0 ||
1212 strncmp(host_address, "ff00:", 5) == 0 ||
1213 strncmp(host_address, "::", 2) == 0) {
1214 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1215 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1218 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1219 host_address, interface_name, address_family_type, gateway);
1220 if (rv == NET_ERR_ACCESS_DENIED) {
1221 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1222 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1223 } else if (rv != NET_ERR_NONE)
1224 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1227 return CONNECTION_ERROR_NONE;
1230 int _connection_libnet_remove_route_entry(connection_handle_s *conn_handle,
1231 connection_address_family_e address_family, const char *interface_name,
1232 const char *host_address, const char *gateway)
1235 char *endstr = strrchr(host_address, '.');
1236 int address_family_type = 0;
1238 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1239 address_family_type = AF_INET;
1241 address_family_type = AF_INET6;
1243 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1244 endstr = strrchr(host_address, '.');
1245 if (endstr == NULL ||
1246 strcmp(endstr, ".0") == 0 ||
1247 strncmp(host_address, "0.", 2) == 0 ||
1248 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1249 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1250 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1253 rv = net_remove_route_entry(conn_handle->network_info_handle, host_address,
1254 interface_name, address_family_type, gateway);
1255 if (rv == NET_ERR_ACCESS_DENIED) {
1256 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1257 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1258 } else if (rv != NET_ERR_NONE)
1259 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1263 if (strncmp(host_address, "fe80:", 5) == 0 ||
1264 strncmp(host_address, "ff00:", 5) == 0 ||
1265 strncmp(host_address, "::", 2) == 0) {
1266 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1267 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1270 rv = net_remove_route_ipv6(conn_handle->network_info_handle, host_address,
1271 interface_name, address_family_type, gateway);
1272 if (rv == NET_ERR_ACCESS_DENIED) {
1273 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1274 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1275 } else if (rv != NET_ERR_NONE)
1276 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1279 return CONNECTION_ERROR_NONE;
1282 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1284 prof_handle_list = g_slist_append(prof_handle_list, profile);
1287 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1289 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1293 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1294 connection_profile_state_changed_cb callback, void *user_data)
1296 net_profile_info_t *profile_info = profile;
1297 char *profile_name = g_strdup(profile_info->ProfileName);
1299 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1300 if (profile_cb_info == NULL) {
1301 g_free(profile_name); //LCOV_EXCL_LINE
1302 return false; //LCOV_EXCL_LINE
1305 profile_cb_info->callback = callback;
1306 profile_cb_info->user_data = user_data;
1307 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1309 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1314 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1316 net_profile_info_t *profile_info = profile;
1318 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1321 return false; //LCOV_EXCL_LINE
1324 int _connection_libnet_set_statistics(connection_handle_s *conn_handle,
1325 net_device_t device_type, net_statistics_type_e statistics_type)
1328 rv = net_set_statistics(conn_handle->network_info_handle,
1329 device_type, statistics_type);
1330 if (rv == NET_ERR_ACCESS_DENIED) {
1331 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1332 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1333 } else if (rv != NET_ERR_NONE)
1334 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1336 return CONNECTION_ERROR_NONE;
1339 int _connection_libnet_get_statistics(connection_handle_s *conn_handle,
1340 net_statistics_type_e statistics_type, unsigned long long *size)
1343 rv = net_get_statistics(conn_handle->network_info_handle,
1344 NET_DEVICE_WIFI, statistics_type, size);
1345 if (rv == NET_ERR_ACCESS_DENIED) {
1346 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1347 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1348 } else if (rv != NET_ERR_NONE)
1349 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1351 return CONNECTION_ERROR_NONE;
1354 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1355 connection_cellular_subscriber_id_e sim_id)
1357 char *modem_path = NULL;
1358 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1360 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1361 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id); //LCOV_EXCL_LINE
1362 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1366 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path"); //LCOV_EXCL_LINE
1367 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1370 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1371 NET_PROFILE_NAME_LEN_MAX);
1374 return CONNECTION_ERROR_NONE;
1377 int _connection_libnet_enable_ethernet_eap(bool enable, const char *profilename)
1381 rv = net_ethernet_eap_enable(enable, profilename);
1382 if (rv == NET_ERR_ACCESS_DENIED) {
1383 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1384 return CONNECTION_ERROR_PERMISSION_DENIED;
1385 } else if (rv != NET_ERR_NONE) {
1386 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable EAP over ethernet[%d]", rv);
1387 return CONNECTION_ERROR_OPERATION_FAILED;
1390 return CONNECTION_ERROR_NONE;
1393 int _connection_libnet_ethernet_eap_enabled(bool *enabled)
1396 gboolean eap_enabled = false;
1398 rv = net_ethernet_eap_supported(&eap_enabled);
1399 if (rv == NET_ERR_ACCESS_DENIED) {
1400 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1401 return CONNECTION_ERROR_PERMISSION_DENIED;
1402 } else if (rv != NET_ERR_NONE) {
1403 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable EAP over ethernet[%d]", rv);
1404 return CONNECTION_ERROR_OPERATION_FAILED;
1407 *enabled = eap_enabled;
1408 return CONNECTION_ERROR_NONE;
1411 int _connection_libnet_profile_save_ethernet_eap_config(connection_handle_s *conn_handle,
1412 connection_profile_h profile)
1416 net_profile_info_t *profile_info = profile;
1418 rv = net_save_ethernet_eap_config(conn_handle->network_info_handle,
1419 &profile_info->ProfileInfo.Ethernet.net_info);
1421 if (rv == NET_ERR_ACCESS_DENIED) {
1422 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1423 return CONNECTION_ERROR_PERMISSION_DENIED;
1424 } else if (rv != NET_ERR_NONE) {
1425 CONNECTION_LOG(CONNECTION_ERROR, "Failed to save eap config[%d]", rv);
1426 return CONNECTION_ERROR_OPERATION_FAILED;
1429 return CONNECTION_ERROR_NONE;
1432 int _connection_libnet_check_get_privilege(void)
1436 rv = net_check_get_privilege();
1437 if (rv == NET_ERR_ACCESS_DENIED) {
1438 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1439 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1440 } else if (rv != NET_ERR_NONE)
1441 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1443 return CONNECTION_ERROR_NONE;
1446 int _connection_libnet_check_profile_privilege(void)
1450 rv = net_check_profile_privilege();
1451 if (rv == NET_ERR_ACCESS_DENIED) {
1452 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1453 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1454 } else if (rv != NET_ERR_NONE)
1455 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1457 return CONNECTION_ERROR_NONE;
1460 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1462 if (!connection_is_feature_checked[feature]) {
1463 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1464 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
1465 set_last_result(CONNECTION_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
1466 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1468 connection_is_feature_checked[feature] = true;
1470 return connection_feature_supported[feature];
1473 int _connection_check_feature_supported(const char *feature_name, ...)
1478 bool feature_supported = false;
1480 va_start(list, feature_name);
1483 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1484 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1485 if (strcmp(key, WIFI_FEATURE) == 0)
1486 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1487 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1488 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1489 if (strcmp(key, ETHERNET_FEATURE) == 0)
1490 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1492 feature_supported |= value;
1493 key = va_arg(list, const char *);
1496 if (!feature_supported) {
1497 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1498 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1500 return CONNECTION_ERROR_NOT_SUPPORTED;
1504 set_last_result(CONNECTION_ERROR_NONE);
1505 return CONNECTION_ERROR_NONE;
1509 int _connection_libnet_start_tcpdump(connection_handle_s *conn_handle)
1511 connection_error_e result = CONNECTION_ERROR_NONE;
1512 net_err_t ret = NET_ERR_NONE;
1514 ret = net_start_tcpdump(conn_handle->network_info_handle);
1515 result = __libnet_convert_to_cp_error_type(ret);
1520 int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle)
1522 connection_error_e result = CONNECTION_ERROR_NONE;
1523 net_err_t ret = NET_ERR_NONE;
1525 ret = net_stop_tcpdump(conn_handle->network_info_handle);
1526 result = __libnet_convert_to_cp_error_type(ret);
1531 int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle,
1532 gboolean *tcpdump_state)
1534 connection_error_e result = CONNECTION_ERROR_NONE;
1535 net_err_t ret = NET_ERR_NONE;
1537 ret = net_get_tcpdump_state(conn_handle->network_info_handle, tcpdump_state);
1538 result = __libnet_convert_to_cp_error_type(ret);
1544 void _connection_lock(void)
1546 if (g_conn_thread_mutex_ref == 0)
1547 pthread_mutex_lock(&g_conn_thread_mutex);
1549 g_conn_thread_mutex_ref++;
1552 void _connection_unlock(void)
1554 if (g_conn_thread_mutex_ref == 1)
1555 pthread_mutex_unlock(&g_conn_thread_mutex);
1557 g_conn_thread_mutex_ref--;
1560 if (g_conn_thread_mutex_ref < 0) {
1561 CONNECTION_LOG(CONNECTION_ERROR,
1562 "Error scenario, thread specific mutex ref is negative !!!");
1563 g_conn_thread_mutex_ref = 0;