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;
31 struct _profile_cb_s {
32 connection_profile_state_changed_cb callback;
33 connection_profile_state_e state;
37 struct _profile_list_s {
40 net_profile_info_t *profiles;
43 static struct _profile_list_s profile_iterator = {0, 0, NULL};
44 static bool connection_is_feature_checked[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
45 static bool connection_feature_supported[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, };
48 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
52 return CONNECTION_ERROR_NONE;
53 case NET_ERR_APP_ALREADY_REGISTERED:
54 return CONNECTION_ERROR_INVALID_OPERATION;
55 case NET_ERR_APP_NOT_REGISTERED:
56 return CONNECTION_ERROR_INVALID_OPERATION;
57 case NET_ERR_NO_ACTIVE_CONNECTIONS:
58 return CONNECTION_ERROR_NO_CONNECTION;
59 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
60 return CONNECTION_ERROR_ALREADY_EXISTS;
61 case NET_ERR_CONNECTION_DHCP_FAILED:
62 return CONNECTION_ERROR_DHCP_FAILED;
63 case NET_ERR_CONNECTION_INVALID_KEY:
64 return CONNECTION_ERROR_INVALID_KEY;
65 case NET_ERR_IN_PROGRESS:
66 return CONNECTION_ERROR_NOW_IN_PROGRESS;
67 case NET_ERR_OPERATION_ABORTED:
68 return CONNECTION_ERROR_OPERATION_ABORTED;
69 case NET_ERR_TIME_OUT:
70 return CONNECTION_ERROR_NO_REPLY;
71 case NET_ERR_ACCESS_DENIED:
72 return CONNECTION_ERROR_PERMISSION_DENIED;
74 return CONNECTION_ERROR_OPERATION_FAILED;
78 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
81 case CONNECTION_ERROR_NONE:
83 case CONNECTION_ERROR_INVALID_PARAMETER:
84 return "INVALID_PARAMETER";
85 case CONNECTION_ERROR_OUT_OF_MEMORY:
86 return "OUT_OF_MEMORY";
87 case CONNECTION_ERROR_INVALID_OPERATION:
88 return "INVALID_OPERATION";
89 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
90 return "ADDRESS_FAMILY_NOT_SUPPORTED";
91 case CONNECTION_ERROR_OPERATION_FAILED:
92 return "OPERATION_FAILED";
93 case CONNECTION_ERROR_ITERATOR_END:
94 return "ITERATOR_END";
95 case CONNECTION_ERROR_NO_CONNECTION:
96 return "NO_CONNECTION";
97 case CONNECTION_ERROR_NOW_IN_PROGRESS:
98 return "NOW_IN_PROGRESS";
99 case CONNECTION_ERROR_ALREADY_EXISTS:
100 return "ALREADY_EXISTS";
101 case CONNECTION_ERROR_OPERATION_ABORTED:
102 return "OPERATION_ABORTED";
103 case CONNECTION_ERROR_DHCP_FAILED:
104 return "DHCP_FAILED";
105 case CONNECTION_ERROR_INVALID_KEY:
106 return "INVALID_KEY";
107 case CONNECTION_ERROR_NO_REPLY:
109 case CONNECTION_ERROR_PERMISSION_DENIED:
110 return "PERMISSION_DENIED";
111 case CONNECTION_ERROR_NOT_SUPPORTED:
112 return "NOT_SUPPORTED";
113 case CONNECTION_ERROR_ALREADY_INITIALIZED:
114 return "ALREADY_INITIALIZED";
115 case CONNECTION_ERROR_NOT_INITIALIZED:
116 return "NOT_INITIALIZED";
122 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
125 case CONNECTION_PROFILE_STATE_DISCONNECTED:
126 return "DISCONNECTED";
127 case CONNECTION_PROFILE_STATE_ASSOCIATION:
128 return "ASSOCIATION";
129 case CONNECTION_PROFILE_STATE_CONFIGURATION:
130 return "CONFIGURATION";
131 case CONNECTION_PROFILE_STATE_CONNECTED:
138 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
140 struct _profile_cb_s *cb_info;
142 if (profile_name == NULL)
145 cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
149 if (cb_info->state == state)
152 cb_info->state = state;
154 if (state < 0 || cb_info->callback == NULL)
157 cb_info->callback(cb_info->state, cb_info->user_data);
160 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
162 if (profile_list->count > 0)
163 g_free(profile_list->profiles);
165 profile_list->count = 0;
166 profile_list->next = 0;
167 profile_list->profiles = NULL;
170 static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
172 bool is_requested = false;
173 connection_error_e result = CONNECTION_ERROR_NONE;
175 connection_handle_s conn_handle_local;
176 connection_handle_s *conn_handle = &conn_handle_local;
177 connection_handle_s *conn_handle_origin = (connection_handle_s *)user_data;
179 if(!_connection_check_handle_validity(conn_handle_origin)) {
180 CONNECTION_LOG(CONNECTION_INFO, "Invalid handle");
184 memcpy(conn_handle, conn_handle_origin, sizeof(connection_handle_s));
187 switch (event_cb->Event) {
188 case NET_EVENT_OPEN_RSP:
191 case NET_EVENT_OPEN_IND:
192 result = __libnet_convert_to_cp_error_type(event_cb->Error);
193 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
194 (is_requested) ? "RSP" : "IND",
195 __libnet_convert_cp_error_type_to_string(result));
198 if (conn_handle->opened_callback) {
199 conn_handle->opened_callback(result,
200 conn_handle->opened_user_data);
202 conn_handle->opened_callback = NULL;
203 conn_handle->opened_user_data = NULL;
207 switch (event_cb->Error) {
209 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
210 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
212 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
215 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
216 __libnet_convert_cp_error_type_to_string(result));
219 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
222 case NET_EVENT_CLOSE_RSP:
225 case NET_EVENT_CLOSE_IND:
226 result = __libnet_convert_to_cp_error_type(event_cb->Error);
227 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
228 (is_requested) ? "RSP" : "IND",
229 __libnet_convert_cp_error_type_to_string(result));
232 if (conn_handle->closed_callback) {
233 conn_handle->closed_callback(result,
234 conn_handle->closed_user_data);
236 conn_handle->closed_callback = NULL;
237 conn_handle->closed_user_data = NULL;
241 switch (event_cb->Error) {
243 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
245 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
248 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
249 __libnet_convert_cp_error_type_to_string(result));
253 case NET_EVENT_NET_STATE_IND:
254 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
256 if (event_cb->Datalength != sizeof(net_state_type_t))
259 net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
260 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
262 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
263 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
265 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
268 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
269 result = __libnet_convert_to_cp_error_type(event_cb->Error);
270 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
271 if (conn_handle->set_default_callback) {
272 conn_handle->set_default_callback(result,
273 conn_handle->set_default_user_data);
275 conn_handle->set_default_callback = NULL;
276 conn_handle->set_default_user_data = NULL;
279 case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
280 result = __libnet_convert_to_cp_error_type(event_cb->Error);
281 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
282 if (conn_handle->reset_callback) {
283 conn_handle->reset_callback(result,
284 conn_handle->reset_user_data);
286 conn_handle->reset_callback = NULL;
287 conn_handle->reset_user_data = NULL;
290 case NET_EVENT_ETHERNET_CABLE_ATTACHED:
291 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
292 if (conn_handle->ethernet_cable_state_changed_callback) {
293 conn_handle->ethernet_cable_state_changed_callback(CONNECTION_ETHERNET_CABLE_ATTACHED,
294 conn_handle->ethernet_cable_state_changed_user_data);
297 case NET_EVENT_ETHERNET_CABLE_DETACHED:
298 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
299 if (conn_handle->ethernet_cable_state_changed_callback) {
300 conn_handle->ethernet_cable_state_changed_callback(CONNECTION_ETHERNET_CABLE_DETACHED,
301 conn_handle->ethernet_cable_state_changed_user_data);
304 case NET_EVENT_NETWORK_TYPE_CHANGED:
305 CONNECTION_LOG(CONNECTION_INFO, "Got Network Type Changed Indication");
306 int *state = (int *) event_cb->Data;
307 if (conn_handle->type_changed_callback) {
308 int type = CONNECTION_TYPE_DISCONNECTED;
311 case VCONFKEY_NETWORK_CELLULAR:
312 type = CONNECTION_TYPE_CELLULAR;
314 case VCONFKEY_NETWORK_WIFI:
315 type = CONNECTION_TYPE_WIFI;
317 case VCONFKEY_NETWORK_ETHERNET:
318 type = CONNECTION_TYPE_ETHERNET;
320 case VCONFKEY_NETWORK_BLUETOOTH:
321 type = CONNECTION_TYPE_BT;
323 case VCONFKEY_NETWORK_DEFAULT_PROXY:
324 type = CONNECTION_TYPE_NET_PROXY;
327 type = CONNECTION_TYPE_DISCONNECTED;
331 conn_handle->type_changed_callback(type,
332 conn_handle->type_changed_user_data);
335 case NET_EVENT_IPV4_ADDRESS_CHANGED:
336 CONNECTION_LOG(CONNECTION_INFO, "Got IPv4 Address Changed Indication");
337 if (conn_handle->ip_changed_callback) {
338 char *ipv4_addr = NULL;
339 char *ipv6_addr = NULL;
340 char *addr = (char *)event_cb->Data;
342 ipv4_addr = g_strdup(addr);
343 ipv6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
344 if (ipv6_addr == NULL)
345 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
346 "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
348 conn_handle->ip_changed_callback(ipv4_addr, ipv6_addr,
349 conn_handle->ip_changed_user_data);
355 case NET_EVENT_IPV6_ADDRESS_CHANGED:
356 CONNECTION_LOG(CONNECTION_INFO, "Got IPv6 Address Changed Indication");
357 if (conn_handle->ip_changed_callback) {
358 char *ipv4_addr = NULL;
359 char *ipv6_addr = NULL;
360 char *addr = (char *)event_cb->Data;
362 ipv6_addr = g_strdup(addr);
363 ipv4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
364 if (ipv4_addr == NULL)
365 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
366 "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
368 conn_handle->ip_changed_callback(ipv4_addr, ipv6_addr,
369 conn_handle->ip_changed_user_data);
375 case NET_EVENT_PROXY_ADDRESS_CHANGED:
376 CONNECTION_LOG(CONNECTION_INFO, "Got Proxy Changed Indication");
377 char *proxy_addr = (char *)event_cb->Data;
379 if (conn_handle->proxy_changed_callback) {
380 conn_handle->proxy_changed_callback(proxy_addr, NULL,
381 conn_handle->proxy_changed_user_data);
384 case NET_EVENT_INTERNET_ONLINE_IND:
385 case NET_EVENT_INTERNET_OFFLINE_IND:
386 CONNECTION_LOG(CONNECTION_INFO, "Got Internet State Changed Indication: %s",
387 event_cb->Event == NET_EVENT_INTERNET_ONLINE_IND ? "Online" : "Offline");
388 net_device_t *device_type = (net_device_t *) event_cb->Data;
390 if (conn_handle->internet_state_changed_callback) {
391 net_profile_info_t active_profile;
394 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
396 if (rv == NET_ERR_NO_SERVICE && event_cb->Event == NET_EVENT_INTERNET_OFFLINE_IND) {
397 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
398 conn_handle->internet_state_changed_user_data); //LCOV_EXCL_LINE
400 } else if (rv == NET_ERR_ACCESS_DENIED) {
401 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
403 } else if (rv != NET_ERR_NONE) {
404 CONNECTION_LOG(CONNECTION_ERROR, "Unable to get Default profile handle"); //LCOV_EXCL_LINE
405 break; //LCOV_EXCL_LINE
408 if (event_cb->Event == NET_EVENT_INTERNET_ONLINE_IND) {
409 if (active_profile.ProfileState == NET_STATE_TYPE_ONLINE &&
410 active_profile.profile_type == *device_type)
411 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_ONLINE,
412 conn_handle->internet_state_changed_user_data);
414 if (active_profile.ProfileState != NET_STATE_TYPE_ONLINE)
415 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
416 conn_handle->internet_state_changed_user_data);
427 static int __libnet_get_connected_count(struct _profile_list_s *profile_list)
432 for (; i < profile_list->count; i++) {
433 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
434 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
441 static void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
445 for (; i < source->count; i++) {
446 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
447 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
448 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
455 static int __libnet_get_default_count(struct _profile_list_s *profile_list)
460 for (; i < profile_list->count; i++) {
461 if (profile_list->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
462 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
470 static void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
474 for (; i < source->count; i++) {
475 if (source->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
476 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
477 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
485 int _connection_libnet_init(connection_handle_s *conn_handle)
489 rv = net_register_client(&(conn_handle->network_info_handle),
490 (net_event_cb_t)__libnet_evt_cb, conn_handle);
491 if (rv != NET_ERR_NONE)
494 if (profile_cb_table == NULL)
495 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
500 bool _connection_libnet_deinit(connection_handle_s *conn_handle, bool is_empty)
502 net_deregister_client(conn_handle->network_info_handle);
505 if (profile_cb_table) {
506 g_hash_table_destroy(profile_cb_table);
507 profile_cb_table = NULL;
510 __libnet_clear_profile_list(&profile_iterator);
512 if (prof_handle_list) {
513 g_slist_free_full(prof_handle_list, g_free);
514 prof_handle_list = NULL;
522 void _connection_set_cs_tid(int tid, connection_handle_s *conn_handle)
524 net_set_cs_tid(tid, conn_handle->network_info_handle);
527 void _connection_unset_cs_tid(int tid, connection_handle_s *conn_handle)
529 net_unset_cs_tid(tid, conn_handle->network_info_handle);
533 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
541 for (list = prof_handle_list; list; list = list->next)
542 if (profile == list->data) return true;
544 for (; i < profile_iterator.count; i++)
545 if (profile == &profile_iterator.profiles[i]) return true;
550 int _connection_libnet_get_metered_state(connection_handle_s *conn_handle, bool* is_metered)
555 rv = net_get_metered_state(conn_handle->network_info_handle, &status);
556 if (rv == NET_ERR_ACCESS_DENIED) {
557 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
558 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
559 } else if (rv != NET_ERR_NONE) {
560 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv); //LCOV_EXCL_LINE
561 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
568 return CONNECTION_ERROR_NONE;
571 int _connection_libnet_get_wifi_state(connection_handle_s *conn_handle, connection_wifi_state_e *state)
574 net_wifi_state_t wlan_state;
576 rv = net_get_wifi_state(conn_handle->network_info_handle, &wlan_state);
577 if (rv == NET_ERR_ACCESS_DENIED) {
578 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
579 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
580 } else if (rv != NET_ERR_NONE) {
581 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
582 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
585 switch (wlan_state) {
587 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
590 case WIFI_ASSOCIATION:
591 case WIFI_CONFIGURATION:
592 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
595 case WIFI_DISCONNECTING:
596 *state = CONNECTION_WIFI_STATE_CONNECTED;
599 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state"); //LCOV_EXCL_LINE
600 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
603 return CONNECTION_ERROR_NONE;
607 int _connection_libnet_get_ethernet_state(connection_handle_s *conn_handle,
608 connection_ethernet_state_e *state)
611 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
612 rv = net_get_profile_list(conn_handle->network_info_handle,
613 NET_DEVICE_ETHERNET, ðernet_profiles.profiles,
614 ðernet_profiles.count);
615 if (rv == NET_ERR_ACCESS_DENIED) {
616 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
617 return CONNECTION_ERROR_PERMISSION_DENIED;
620 if (ethernet_profiles.count == 0) {
621 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
622 return CONNECTION_ERROR_NONE;
625 switch (ethernet_profiles.profiles->ProfileState) {
626 case NET_STATE_TYPE_ONLINE:
627 case NET_STATE_TYPE_READY:
628 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
630 case NET_STATE_TYPE_IDLE:
631 case NET_STATE_TYPE_FAILURE:
632 case NET_STATE_TYPE_ASSOCIATION:
633 case NET_STATE_TYPE_CONFIGURATION:
634 case NET_STATE_TYPE_DISCONNECT:
635 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
638 __libnet_clear_profile_list(ðernet_profiles);
639 return CONNECTION_ERROR_OPERATION_FAILED;
642 __libnet_clear_profile_list(ðernet_profiles);
644 return CONNECTION_ERROR_NONE;
647 int _connection_libnet_get_ethernet_cable_state(connection_handle_s *conn_handle,
648 connection_ethernet_cable_state_e* state)
653 rv = net_get_ethernet_cable_state(conn_handle->network_info_handle, &status);
654 if (rv == NET_ERR_ACCESS_DENIED) {
655 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
656 return CONNECTION_ERROR_PERMISSION_DENIED;
657 } else if (rv != NET_ERR_NONE) {
658 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
659 return CONNECTION_ERROR_OPERATION_FAILED;
663 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
665 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
666 return CONNECTION_ERROR_NONE;
670 int _connection_libnet_get_bluetooth_state(connection_handle_s *conn_handle, connection_bt_state_e *state)
674 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
675 rv = net_get_profile_list(conn_handle->network_info_handle,
676 NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles,
677 &bluetooth_profiles.count);
678 if (rv == NET_ERR_ACCESS_DENIED) {
679 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
680 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
683 if (bluetooth_profiles.count == 0) {
684 *state = CONNECTION_BT_STATE_DEACTIVATED;
685 return CONNECTION_ERROR_NONE;
689 for (; i < bluetooth_profiles.count; i++) {
690 switch (bluetooth_profiles.profiles[i].ProfileState) {
691 case NET_STATE_TYPE_ONLINE:
692 case NET_STATE_TYPE_READY:
693 *state = CONNECTION_BT_STATE_CONNECTED;
695 case NET_STATE_TYPE_IDLE:
696 case NET_STATE_TYPE_FAILURE:
697 case NET_STATE_TYPE_ASSOCIATION:
698 case NET_STATE_TYPE_CONFIGURATION:
699 case NET_STATE_TYPE_DISCONNECT:
700 *state = CONNECTION_BT_STATE_DISCONNECTED;
703 __libnet_clear_profile_list(&bluetooth_profiles);
704 return CONNECTION_ERROR_OPERATION_FAILED;
710 __libnet_clear_profile_list(&bluetooth_profiles);
712 return CONNECTION_ERROR_NONE;
715 int _connection_libnet_get_profile_iterator(connection_handle_s *conn_handle,
716 connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
720 net_profile_info_t *profiles = NULL;
722 struct _profile_list_s profile_list = {0, 0, NULL};
724 __libnet_clear_profile_list(&profile_iterator);
726 rv = net_get_all_profile_list(conn_handle->network_info_handle,
727 &profile_list.profiles, &profile_list.count);
728 if (rv == NET_ERR_ACCESS_DENIED) {
729 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
730 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
731 } else if (rv != NET_ERR_NO_SERVICE && rv != NET_ERR_NONE)
732 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
734 *profile_iter_h = &profile_iterator;
737 case CONNECTION_ITERATOR_TYPE_REGISTERED:
738 count = profile_list.count;
739 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
741 return CONNECTION_ERROR_NONE;
743 profiles = g_try_new0(net_profile_info_t, count);
744 if (profiles == NULL) {
745 __libnet_clear_profile_list(&profile_list); //LCOV_EXCL_LINE
746 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
749 profile_iterator.profiles = profiles;
751 memcpy(profiles, profile_list.profiles, sizeof(net_profile_info_t) * count);
754 case CONNECTION_ITERATOR_TYPE_CONNECTED:
755 count = __libnet_get_connected_count(&profile_list);
756 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
758 return CONNECTION_ERROR_NONE;
760 profiles = g_try_new0(net_profile_info_t, count);
761 if (profiles == NULL) {
762 __libnet_clear_profile_list(&profile_list); //LCOV_EXCL_LINE
763 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
766 profile_iterator.profiles = profiles;
768 __libnet_copy_connected_profile(&profiles, &profile_list);
771 case CONNECTION_ITERATOR_TYPE_DEFAULT:
772 count = __libnet_get_default_count(&profile_list);
773 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
775 return CONNECTION_ERROR_NONE;
777 profiles = g_try_new0(net_profile_info_t, count);
778 if (profiles == NULL) {
779 __libnet_clear_profile_list(&profile_list);
780 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
783 profile_iterator.profiles = profiles;
785 __libnet_copy_default_profile(&profiles, &profile_list);
790 __libnet_clear_profile_list(&profile_list);
792 profile_iterator.count = count;
794 return CONNECTION_ERROR_NONE;
797 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
799 if (profile_iter_h != &profile_iterator)
800 return CONNECTION_ERROR_INVALID_PARAMETER;
802 if (profile_iterator.count <= profile_iterator.next)
803 return CONNECTION_ERROR_ITERATOR_END;
805 *profile = &profile_iterator.profiles[profile_iterator.next];
806 profile_iterator.next++;
808 return CONNECTION_ERROR_NONE;
811 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
813 if (profile_iter_h != &profile_iterator)
816 if (profile_iterator.count <= profile_iterator.next)
822 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
824 if (profile_iter_h != &profile_iterator)
825 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
827 __libnet_clear_profile_list(&profile_iterator);
829 return CONNECTION_ERROR_NONE;
832 int _connection_libnet_get_current_profile(connection_handle_s *conn_handle,
833 connection_profile_h *profile)
835 net_profile_info_t active_profile;
838 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
839 if (rv == NET_ERR_NO_SERVICE)
840 return CONNECTION_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
841 else if (rv == NET_ERR_ACCESS_DENIED) {
842 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
843 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
844 } else if (rv != NET_ERR_NONE)
845 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
847 *profile = g_try_malloc0(sizeof(net_profile_info_t));
848 if (*profile == NULL)
849 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
851 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
852 prof_handle_list = g_slist_append(prof_handle_list, *profile);
854 return CONNECTION_ERROR_NONE;
857 int _connection_libnet_reset_profile(connection_handle_s *conn_handle,
858 connection_reset_option_e type, connection_cellular_subscriber_id_e id)
862 rv = net_reset_profile(conn_handle->network_info_handle, type, id);
863 if (rv == NET_ERR_ACCESS_DENIED)
864 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
865 else if (rv != NET_ERR_NONE)
866 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
868 return CONNECTION_ERROR_NONE;
871 int _connection_libnet_open_profile(connection_handle_s *conn_handle,
872 connection_profile_h profile)
876 if (!(_connection_libnet_check_profile_validity(profile))) {
877 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
878 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
881 net_profile_info_t *profile_info = profile;
883 if (profile_info->profile_type == NET_DEVICE_MESH)
884 rv = net_open_mesh_connection_with_profile(conn_handle->network_info_handle, //LCOV_EXCL_LINE
885 profile_info->ProfileName);
887 rv = net_open_connection_with_profile(conn_handle->network_info_handle,
888 profile_info->ProfileName);
890 if (rv == NET_ERR_ACCESS_DENIED)
891 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
892 else if (rv != NET_ERR_NONE)
893 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
895 return CONNECTION_ERROR_NONE;
898 int _connection_libnet_get_cellular_service_profile(connection_handle_s *conn_handle,
899 connection_cellular_service_type_e type, connection_profile_h *profile)
902 int rv = NET_ERR_NONE;
903 #if defined TIZEN_DUALSIM_ENABLE
904 int default_subscriber_id = 0;
905 char subscriber_id[3];
908 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
909 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
911 rv = net_get_profile_list(conn_handle->network_info_handle,
912 NET_DEVICE_CELLULAR, &cellular_profiles.profiles,
913 &cellular_profiles.count);
914 if (rv == NET_ERR_ACCESS_DENIED) {
915 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
916 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
917 } else if (rv != NET_ERR_NONE) {
918 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv); //LCOV_EXCL_LINE
919 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
922 #if defined TIZEN_DUALSIM_ENABLE
923 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
924 &default_subscriber_id) != 0) {
925 CONNECTION_LOG(CONNECTION_ERROR,
926 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
927 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
928 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
931 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
934 for (i = 0; i < cellular_profiles.count; i++)
935 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
936 #if defined TIZEN_DUALSIM_ENABLE
937 if (g_str_has_suffix(
938 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
939 subscriber_id) == TRUE)
943 if (i >= cellular_profiles.count) {
944 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
945 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
948 *profile = g_try_malloc0(sizeof(net_profile_info_t));
949 if (*profile == NULL) {
950 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
951 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
954 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
956 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
960 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
961 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
964 for (j = 0; j < cellular_profiles.count; j++) {
968 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
971 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
972 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
979 __libnet_clear_profile_list(&cellular_profiles);
980 prof_handle_list = g_slist_append(prof_handle_list, *profile);
982 return CONNECTION_ERROR_NONE;
985 int _connection_libnet_set_cellular_service_profile_sync(connection_handle_s *conn_handle,
986 connection_cellular_service_type_e type, connection_profile_h profile)
990 if (!(_connection_libnet_check_profile_validity(profile))) {
991 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
992 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
995 net_profile_info_t *profile_info = profile;
996 connection_cellular_service_type_e service_type;
998 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1000 if (service_type != type)
1001 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1003 rv = net_set_default_cellular_service_profile(conn_handle->network_info_handle,
1004 profile_info->ProfileName);
1005 if (rv == NET_ERR_ACCESS_DENIED) {
1006 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1007 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1008 } else if (rv != NET_ERR_NONE)
1009 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1011 return CONNECTION_ERROR_NONE;
1014 int _connection_libnet_set_cellular_service_profile_async(connection_handle_s *conn_handle,
1015 connection_cellular_service_type_e type, connection_profile_h profile)
1019 if (!(_connection_libnet_check_profile_validity(profile))) {
1020 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1021 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1024 net_profile_info_t *profile_info = profile;
1025 connection_cellular_service_type_e service_type;
1027 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1029 if (service_type != type)
1030 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1032 rv = net_set_default_cellular_service_profile_async(conn_handle->network_info_handle,
1033 profile_info->ProfileName);
1034 if (rv == NET_ERR_ACCESS_DENIED) {
1035 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1036 } else if (rv != NET_ERR_NONE)
1037 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1039 return CONNECTION_ERROR_NONE;
1042 int _connection_libnet_close_profile(connection_handle_s *conn_handle, connection_profile_h profile)
1046 if (!(_connection_libnet_check_profile_validity(profile))) {
1047 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1048 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1051 net_profile_info_t *profile_info = profile;
1053 if (profile_info->profile_type == NET_DEVICE_MESH)
1054 rv = net_close_mesh_connection(conn_handle->network_info_handle, profile_info->ProfileName); //LCOV_EXCL_LINE
1056 rv = net_close_connection(conn_handle->network_info_handle, profile_info->ProfileName);
1058 if (rv == NET_ERR_ACCESS_DENIED)
1059 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1060 else if (rv != NET_ERR_NONE)
1061 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1063 return CONNECTION_ERROR_NONE;
1066 int _connection_libnet_add_route(connection_handle_s *conn_handle,
1067 const char *interface_name, const char *host_address)
1070 char *endstr = NULL;
1071 int address_family = 0;
1073 address_family = AF_INET;
1075 endstr = strrchr(host_address, '.');
1076 if (endstr == NULL ||
1077 strcmp(endstr, ".0") == 0 ||
1078 strncmp(host_address, "0.", 2) == 0 ||
1079 strstr(host_address, "255") != NULL) {
1080 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1081 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1084 rv = net_add_route(conn_handle->network_info_handle,
1085 host_address, interface_name, address_family);
1086 if (rv == NET_ERR_ACCESS_DENIED) {
1087 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1088 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1089 } else if (rv != NET_ERR_NONE)
1090 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1092 return CONNECTION_ERROR_NONE;
1095 int _connection_libnet_remove_route(connection_handle_s *conn_handle,
1096 const char *interface_name, const char *host_address)
1099 char *endstr = strrchr(host_address, '.');
1100 int address_family = 0;
1102 address_family = AF_INET;
1104 endstr = strrchr(host_address, '.');
1105 if (endstr == NULL ||
1106 strcmp(endstr, ".0") == 0 ||
1107 strncmp(host_address, "0.", 2) == 0 ||
1108 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1109 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1110 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1113 rv = net_remove_route(conn_handle->network_info_handle,
1114 host_address, interface_name, address_family);
1115 if (rv == NET_ERR_ACCESS_DENIED) {
1116 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1117 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1118 } else if (rv != NET_ERR_NONE)
1119 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1121 return CONNECTION_ERROR_NONE;
1124 int _connection_libnet_add_route_ipv6(connection_handle_s *conn_handle,
1125 const char *interface_name, const char *host_address, const char *gateway)
1128 int address_family = 0;
1130 address_family = AF_INET6;
1132 if (strncmp(host_address, "fe80:", 5) == 0 ||
1133 strncmp(host_address, "ff00:", 5) == 0 ||
1134 strncmp(host_address, "::", 2) == 0) {
1135 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1136 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1139 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1140 host_address, interface_name, address_family, gateway);
1141 if (rv == NET_ERR_ACCESS_DENIED) {
1142 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1143 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1144 } else if (rv != NET_ERR_NONE)
1145 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1147 return CONNECTION_ERROR_NONE;
1150 int _connection_libnet_remove_route_ipv6(connection_handle_s *conn_handle,
1151 const char *interface_name, const char *host_address, const char *gateway)
1154 int address_family = 0;
1156 address_family = AF_INET6;
1158 if (strncmp(host_address, "fe80:", 5) == 0 ||
1159 strncmp(host_address, "ff00:", 5) == 0 ||
1160 strncmp(host_address, "::", 2) == 0) {
1161 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1162 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1165 rv = net_remove_route_ipv6(conn_handle->network_info_handle,
1166 host_address, interface_name, address_family, gateway);
1167 if (rv == NET_ERR_ACCESS_DENIED) {
1168 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1169 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1170 } else if (rv != NET_ERR_NONE)
1171 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1173 return CONNECTION_ERROR_NONE;
1176 int _connection_libnet_add_route_entry(connection_handle_s *conn_handle,
1177 connection_address_family_e address_family, const char *interface_name,
1178 const char *host_address, const char *gateway)
1181 char *endstr = NULL;
1182 int address_family_type = 0;
1184 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1185 address_family_type = AF_INET;
1187 address_family_type = AF_INET6;
1189 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1191 endstr = strrchr(host_address, '.');
1192 if (endstr == NULL ||
1193 strcmp(endstr, ".0") == 0 ||
1194 strncmp(host_address, "0.", 2) == 0 ||
1195 strstr(host_address, "255") != NULL) {
1196 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1197 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1200 rv = net_add_route_entry(conn_handle->network_info_handle,
1201 host_address, interface_name, address_family_type, gateway);
1202 if (rv == NET_ERR_ACCESS_DENIED) {
1203 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1204 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1205 } else if (rv != NET_ERR_NONE)
1206 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1210 if (strncmp(host_address, "fe80:", 5) == 0 ||
1211 strncmp(host_address, "ff00:", 5) == 0 ||
1212 strncmp(host_address, "::", 2) == 0) {
1213 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1214 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1217 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1218 host_address, interface_name, address_family_type, gateway);
1219 if (rv == NET_ERR_ACCESS_DENIED) {
1220 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1221 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1222 } else if (rv != NET_ERR_NONE)
1223 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1226 return CONNECTION_ERROR_NONE;
1229 int _connection_libnet_remove_route_entry(connection_handle_s *conn_handle,
1230 connection_address_family_e address_family, const char *interface_name,
1231 const char *host_address, const char *gateway)
1234 char *endstr = strrchr(host_address, '.');
1235 int address_family_type = 0;
1237 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1238 address_family_type = AF_INET;
1240 address_family_type = AF_INET6;
1242 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1243 endstr = strrchr(host_address, '.');
1244 if (endstr == NULL ||
1245 strcmp(endstr, ".0") == 0 ||
1246 strncmp(host_address, "0.", 2) == 0 ||
1247 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1248 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1249 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1252 rv = net_remove_route_entry(conn_handle->network_info_handle, host_address,
1253 interface_name, address_family_type, gateway);
1254 if (rv == NET_ERR_ACCESS_DENIED) {
1255 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1256 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1257 } else if (rv != NET_ERR_NONE)
1258 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1262 if (strncmp(host_address, "fe80:", 5) == 0 ||
1263 strncmp(host_address, "ff00:", 5) == 0 ||
1264 strncmp(host_address, "::", 2) == 0) {
1265 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1266 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1269 rv = net_remove_route_ipv6(conn_handle->network_info_handle, host_address,
1270 interface_name, address_family_type, gateway);
1271 if (rv == NET_ERR_ACCESS_DENIED) {
1272 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1273 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1274 } else if (rv != NET_ERR_NONE)
1275 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1278 return CONNECTION_ERROR_NONE;
1281 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1283 prof_handle_list = g_slist_append(prof_handle_list, profile);
1286 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1288 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1292 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1293 connection_profile_state_changed_cb callback, void *user_data)
1295 net_profile_info_t *profile_info = profile;
1296 char *profile_name = g_strdup(profile_info->ProfileName);
1298 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1299 if (profile_cb_info == NULL) {
1300 g_free(profile_name); //LCOV_EXCL_LINE
1301 return false; //LCOV_EXCL_LINE
1304 profile_cb_info->callback = callback;
1305 profile_cb_info->user_data = user_data;
1306 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1308 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1313 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1315 net_profile_info_t *profile_info = profile;
1317 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1320 return false; //LCOV_EXCL_LINE
1323 int _connection_libnet_set_statistics(connection_handle_s *conn_handle,
1324 net_device_t device_type, net_statistics_type_e statistics_type)
1327 rv = net_set_statistics(conn_handle->network_info_handle,
1328 device_type, statistics_type);
1329 if (rv == NET_ERR_ACCESS_DENIED) {
1330 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1331 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1332 } else if (rv != NET_ERR_NONE)
1333 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1335 return CONNECTION_ERROR_NONE;
1338 int _connection_libnet_get_statistics(connection_handle_s *conn_handle,
1339 net_statistics_type_e statistics_type, unsigned long long *size)
1342 rv = net_get_statistics(conn_handle->network_info_handle,
1343 NET_DEVICE_WIFI, statistics_type, size);
1344 if (rv == NET_ERR_ACCESS_DENIED) {
1345 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1346 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1347 } else if (rv != NET_ERR_NONE)
1348 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1350 return CONNECTION_ERROR_NONE;
1353 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1354 connection_cellular_subscriber_id_e sim_id)
1356 char *modem_path = NULL;
1357 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1359 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1360 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id); //LCOV_EXCL_LINE
1361 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1365 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path"); //LCOV_EXCL_LINE
1366 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1369 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1370 NET_PROFILE_NAME_LEN_MAX);
1373 return CONNECTION_ERROR_NONE;
1376 int _connection_libnet_enable_ethernet_eap(bool enable, const char *profilename)
1380 rv = net_ethernet_eap_enable(enable, profilename);
1381 if (rv == NET_ERR_ACCESS_DENIED) {
1382 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1383 return CONNECTION_ERROR_PERMISSION_DENIED;
1384 } else if (rv != NET_ERR_NONE) {
1385 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable EAP over ethernet[%d]", rv);
1386 return CONNECTION_ERROR_OPERATION_FAILED;
1389 return CONNECTION_ERROR_NONE;
1392 int _connection_libnet_ethernet_eap_enabled(bool *enabled)
1395 gboolean eap_enabled = false;
1397 rv = net_ethernet_eap_supported(&eap_enabled);
1398 if (rv == NET_ERR_ACCESS_DENIED) {
1399 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1400 return CONNECTION_ERROR_PERMISSION_DENIED;
1401 } else if (rv != NET_ERR_NONE) {
1402 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable EAP over ethernet[%d]", rv);
1403 return CONNECTION_ERROR_OPERATION_FAILED;
1406 *enabled = eap_enabled;
1407 return CONNECTION_ERROR_NONE;
1410 int _connection_libnet_profile_save_ethernet_eap_config(connection_handle_s *conn_handle,
1411 connection_profile_h profile)
1415 net_profile_info_t *profile_info = profile;
1417 rv = net_save_ethernet_eap_config(conn_handle->network_info_handle,
1418 &profile_info->ProfileInfo.Ethernet.net_info);
1420 if (rv == NET_ERR_ACCESS_DENIED) {
1421 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
1422 return CONNECTION_ERROR_PERMISSION_DENIED;
1423 } else if (rv != NET_ERR_NONE) {
1424 CONNECTION_LOG(CONNECTION_ERROR, "Failed to save eap config[%d]", rv);
1425 return CONNECTION_ERROR_OPERATION_FAILED;
1428 return CONNECTION_ERROR_NONE;
1431 int _connection_libnet_check_get_privilege(void)
1435 rv = net_check_get_privilege();
1436 if (rv == NET_ERR_ACCESS_DENIED) {
1437 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1438 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1439 } else if (rv != NET_ERR_NONE)
1440 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1442 return CONNECTION_ERROR_NONE;
1445 int _connection_libnet_check_profile_privilege(void)
1449 rv = net_check_profile_privilege();
1450 if (rv == NET_ERR_ACCESS_DENIED) {
1451 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1452 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1453 } else if (rv != NET_ERR_NONE)
1454 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1456 return CONNECTION_ERROR_NONE;
1459 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1461 if (!connection_is_feature_checked[feature]) {
1462 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1463 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
1464 set_last_result(CONNECTION_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
1465 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1467 connection_is_feature_checked[feature] = true;
1469 return connection_feature_supported[feature];
1472 int _connection_check_feature_supported(const char *feature_name, ...)
1477 bool feature_supported = false;
1479 va_start(list, feature_name);
1482 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1483 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1484 if (strcmp(key, WIFI_FEATURE) == 0)
1485 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1486 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1487 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1488 if (strcmp(key, ETHERNET_FEATURE) == 0)
1489 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1491 feature_supported |= value;
1492 key = va_arg(list, const char *);
1495 if (!feature_supported) {
1496 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1497 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1499 return CONNECTION_ERROR_NOT_SUPPORTED;
1503 set_last_result(CONNECTION_ERROR_NONE);
1504 return CONNECTION_ERROR_NONE;
1508 int _connection_libnet_start_tcpdump(connection_handle_s *conn_handle)
1510 connection_error_e result = CONNECTION_ERROR_NONE;
1511 net_err_t ret = NET_ERR_NONE;
1513 ret = net_start_tcpdump(conn_handle->network_info_handle);
1514 result = __libnet_convert_to_cp_error_type(ret);
1519 int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle)
1521 connection_error_e result = CONNECTION_ERROR_NONE;
1522 net_err_t ret = NET_ERR_NONE;
1524 ret = net_stop_tcpdump(conn_handle->network_info_handle);
1525 result = __libnet_convert_to_cp_error_type(ret);
1530 int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle,
1531 gboolean *tcpdump_state)
1533 connection_error_e result = CONNECTION_ERROR_NONE;
1534 net_err_t ret = NET_ERR_NONE;
1536 ret = net_get_tcpdump_state(conn_handle->network_info_handle, tcpdump_state);
1537 result = __libnet_convert_to_cp_error_type(ret);
1543 void _connection_lock(void)
1545 pthread_mutex_lock(&g_conn_thread_mutex);
1548 void _connection_unlock(void)
1550 pthread_mutex_unlock(&g_conn_thread_mutex);