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;
174 connection_handle_s *conn_handle = (connection_handle_s *)user_data;
176 switch (event_cb->Event) {
177 case NET_EVENT_OPEN_RSP:
180 case NET_EVENT_OPEN_IND:
181 result = __libnet_convert_to_cp_error_type(event_cb->Error);
182 CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
183 (is_requested) ? "RSP" : "IND",
184 __libnet_convert_cp_error_type_to_string(result));
187 if (conn_handle->opened_callback) {
188 conn_handle->opened_callback(result,
189 conn_handle->opened_user_data);
191 conn_handle->opened_callback = NULL;
192 conn_handle->opened_user_data = NULL;
196 switch (event_cb->Error) {
198 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
199 CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
201 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
204 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
205 __libnet_convert_cp_error_type_to_string(result));
208 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
211 case NET_EVENT_CLOSE_RSP:
214 case NET_EVENT_CLOSE_IND:
215 result = __libnet_convert_to_cp_error_type(event_cb->Error);
216 CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
217 (is_requested) ? "RSP" : "IND",
218 __libnet_convert_cp_error_type_to_string(result));
221 if (conn_handle->closed_callback) {
222 conn_handle->closed_callback(result,
223 conn_handle->closed_user_data);
225 conn_handle->closed_callback = NULL;
226 conn_handle->closed_user_data = NULL;
230 switch (event_cb->Error) {
232 CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
234 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
237 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
238 __libnet_convert_cp_error_type_to_string(result));
242 case NET_EVENT_NET_STATE_IND:
243 CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
245 if (event_cb->Datalength != sizeof(net_state_type_t))
248 net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
249 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
251 CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
252 SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
254 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
257 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
258 result = __libnet_convert_to_cp_error_type(event_cb->Error);
259 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
260 if (conn_handle->set_default_callback) {
261 conn_handle->set_default_callback(result,
262 conn_handle->set_default_user_data);
264 conn_handle->set_default_callback = NULL;
265 conn_handle->set_default_user_data = NULL;
268 case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
269 result = __libnet_convert_to_cp_error_type(event_cb->Error);
270 CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
271 if (conn_handle->reset_callback) {
272 conn_handle->reset_callback(result,
273 conn_handle->reset_user_data);
275 conn_handle->reset_callback = NULL;
276 conn_handle->reset_user_data = NULL;
279 case NET_EVENT_ETHERNET_CABLE_ATTACHED:
280 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
281 if (conn_handle->ethernet_cable_state_changed_callback) {
282 conn_handle->ethernet_cable_state_changed_callback(CONNECTION_ETHERNET_CABLE_ATTACHED,
283 conn_handle->ethernet_cable_state_changed_user_data);
286 case NET_EVENT_ETHERNET_CABLE_DETACHED:
287 CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
288 if (conn_handle->ethernet_cable_state_changed_callback) {
289 conn_handle->ethernet_cable_state_changed_callback(CONNECTION_ETHERNET_CABLE_DETACHED,
290 conn_handle->ethernet_cable_state_changed_user_data);
293 case NET_EVENT_NETWORK_TYPE_CHANGED:
294 CONNECTION_LOG(CONNECTION_INFO, "Got Network Type Changed Indication");
295 int *state = (int *) event_cb->Data;
296 if (conn_handle->type_changed_callback) {
297 int type = CONNECTION_TYPE_DISCONNECTED;
300 case VCONFKEY_NETWORK_CELLULAR:
301 type = CONNECTION_TYPE_CELLULAR;
303 case VCONFKEY_NETWORK_WIFI:
304 type = CONNECTION_TYPE_WIFI;
306 case VCONFKEY_NETWORK_ETHERNET:
307 type = CONNECTION_TYPE_ETHERNET;
309 case VCONFKEY_NETWORK_BLUETOOTH:
310 type = CONNECTION_TYPE_BT;
312 case VCONFKEY_NETWORK_DEFAULT_PROXY:
313 type = CONNECTION_TYPE_NET_PROXY;
316 type = CONNECTION_TYPE_DISCONNECTED;
320 conn_handle->type_changed_callback(type,
321 conn_handle->type_changed_user_data);
324 case NET_EVENT_IPV4_ADDRESS_CHANGED:
325 CONNECTION_LOG(CONNECTION_INFO, "Got IPv4 Address Changed Indication");
326 if (conn_handle->ip_changed_callback) {
327 char *ipv4_addr = NULL;
328 char *ipv6_addr = NULL;
329 char *addr = (char *)event_cb->Data;
331 ipv4_addr = g_strdup(addr);
332 ipv6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
333 if (ipv6_addr == NULL)
334 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
335 "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
337 conn_handle->ip_changed_callback(ipv4_addr, ipv6_addr,
338 conn_handle->ip_changed_user_data);
344 case NET_EVENT_IPV6_ADDRESS_CHANGED:
345 CONNECTION_LOG(CONNECTION_INFO, "Got IPv6 Address Changed Indication");
346 if (conn_handle->ip_changed_callback) {
347 char *ipv4_addr = NULL;
348 char *ipv6_addr = NULL;
349 char *addr = (char *)event_cb->Data;
351 ipv6_addr = g_strdup(addr);
352 ipv4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
353 if (ipv4_addr == NULL)
354 CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
355 "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
357 conn_handle->ip_changed_callback(ipv4_addr, ipv6_addr,
358 conn_handle->ip_changed_user_data);
364 case NET_EVENT_PROXY_ADDRESS_CHANGED:
365 CONNECTION_LOG(CONNECTION_INFO, "Got Proxy Changed Indication");
366 char *proxy_addr = (char *)event_cb->Data;
368 if (conn_handle->proxy_changed_callback) {
369 conn_handle->proxy_changed_callback(proxy_addr, NULL,
370 conn_handle->proxy_changed_user_data);
373 case NET_EVENT_INTERNET_ONLINE_IND:
374 case NET_EVENT_INTERNET_OFFLINE_IND:
375 CONNECTION_LOG(CONNECTION_INFO, "Got Internet State Changed Indication: %s",
376 event_cb->Event == NET_EVENT_INTERNET_ONLINE_IND ? "Online" : "Offline");
377 net_device_t *device_type = (net_device_t *) event_cb->Data;
379 if (conn_handle->internet_state_changed_callback) {
380 net_profile_info_t active_profile;
383 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
385 if (rv == NET_ERR_NO_SERVICE && event_cb->Event == NET_EVENT_INTERNET_OFFLINE_IND) {
386 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
387 conn_handle->internet_state_changed_user_data); //LCOV_EXCL_LINE
389 } else if (rv == NET_ERR_ACCESS_DENIED) {
390 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
392 } else if (rv != NET_ERR_NONE) {
393 CONNECTION_LOG(CONNECTION_ERROR, "Unable to get Default profile handle"); //LCOV_EXCL_LINE
394 break; //LCOV_EXCL_LINE
397 if (event_cb->Event == NET_EVENT_INTERNET_ONLINE_IND) {
398 if (active_profile.ProfileState == NET_STATE_TYPE_ONLINE &&
399 active_profile.profile_type == *device_type)
400 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_ONLINE,
401 conn_handle->internet_state_changed_user_data);
403 if (active_profile.ProfileState != NET_STATE_TYPE_ONLINE)
404 conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
405 conn_handle->internet_state_changed_user_data);
416 static int __libnet_get_connected_count(struct _profile_list_s *profile_list)
421 for (; i < profile_list->count; i++) {
422 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
423 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
430 static void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
434 for (; i < source->count; i++) {
435 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
436 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
437 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
444 static int __libnet_get_default_count(struct _profile_list_s *profile_list)
449 for (; i < profile_list->count; i++) {
450 if (profile_list->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
451 if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
459 static void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
463 for (; i < source->count; i++) {
464 if (source->profiles[i].profile_type == NET_DEVICE_CELLULAR) {
465 if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
466 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
474 int _connection_libnet_init(connection_handle_s *conn_handle)
478 rv = net_register_client(&(conn_handle->network_info_handle),
479 (net_event_cb_t)__libnet_evt_cb, conn_handle);
480 if (rv != NET_ERR_NONE)
483 if (profile_cb_table == NULL)
484 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
489 bool _connection_libnet_deinit(connection_handle_s *conn_handle, bool is_empty)
491 net_deregister_client(conn_handle->network_info_handle);
494 if (profile_cb_table) {
495 g_hash_table_destroy(profile_cb_table);
496 profile_cb_table = NULL;
499 __libnet_clear_profile_list(&profile_iterator);
501 if (prof_handle_list) {
502 g_slist_free_full(prof_handle_list, g_free);
503 prof_handle_list = NULL;
510 void _connection_set_cs_tid(int tid, connection_handle_s *conn_handle)
512 net_set_cs_tid(tid, conn_handle->network_info_handle);
515 void _connection_unset_cs_tid(int tid, connection_handle_s *conn_handle)
517 net_unset_cs_tid(tid, conn_handle->network_info_handle);
520 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
528 for (list = prof_handle_list; list; list = list->next)
529 if (profile == list->data) return true;
531 for (; i < profile_iterator.count; i++)
532 if (profile == &profile_iterator.profiles[i]) return true;
537 int _connection_libnet_get_metered_state(connection_handle_s *conn_handle, bool* is_metered)
542 rv = net_get_metered_state(conn_handle->network_info_handle, &status);
543 if (rv == NET_ERR_ACCESS_DENIED) {
544 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
545 return CONNECTION_ERROR_PERMISSION_DENIED;
546 } else if (rv != NET_ERR_NONE) {
547 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv);
548 return CONNECTION_ERROR_OPERATION_FAILED;
555 return CONNECTION_ERROR_NONE;
558 int _connection_libnet_get_wifi_state(connection_handle_s *conn_handle, connection_wifi_state_e *state)
561 net_wifi_state_t wlan_state;
563 rv = net_get_wifi_state(conn_handle->network_info_handle, &wlan_state);
564 if (rv == NET_ERR_ACCESS_DENIED) {
565 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
566 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
567 } else if (rv != NET_ERR_NONE) {
568 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
569 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
572 switch (wlan_state) {
574 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
577 case WIFI_ASSOCIATION:
578 case WIFI_CONFIGURATION:
579 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
582 case WIFI_DISCONNECTING:
583 *state = CONNECTION_WIFI_STATE_CONNECTED;
586 CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state"); //LCOV_EXCL_LINE
587 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
590 return CONNECTION_ERROR_NONE;
594 int _connection_libnet_get_ethernet_state(connection_handle_s *conn_handle,
595 connection_ethernet_state_e *state)
598 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
599 rv = net_get_profile_list(conn_handle->network_info_handle,
600 NET_DEVICE_ETHERNET, ðernet_profiles.profiles,
601 ðernet_profiles.count);
602 if (rv == NET_ERR_ACCESS_DENIED) {
603 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
604 return CONNECTION_ERROR_PERMISSION_DENIED;
607 if (ethernet_profiles.count == 0) {
608 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
609 return CONNECTION_ERROR_NONE;
612 switch (ethernet_profiles.profiles->ProfileState) {
613 case NET_STATE_TYPE_ONLINE:
614 case NET_STATE_TYPE_READY:
615 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
617 case NET_STATE_TYPE_IDLE:
618 case NET_STATE_TYPE_FAILURE:
619 case NET_STATE_TYPE_ASSOCIATION:
620 case NET_STATE_TYPE_CONFIGURATION:
621 case NET_STATE_TYPE_DISCONNECT:
622 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
625 __libnet_clear_profile_list(ðernet_profiles);
626 return CONNECTION_ERROR_OPERATION_FAILED;
629 __libnet_clear_profile_list(ðernet_profiles);
631 return CONNECTION_ERROR_NONE;
634 int _connection_libnet_get_ethernet_cable_state(connection_handle_s *conn_handle,
635 connection_ethernet_cable_state_e* state)
640 rv = net_get_ethernet_cable_state(conn_handle->network_info_handle, &status);
641 if (rv == NET_ERR_ACCESS_DENIED) {
642 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
643 return CONNECTION_ERROR_PERMISSION_DENIED;
644 } else if (rv != NET_ERR_NONE) {
645 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv);
646 return CONNECTION_ERROR_OPERATION_FAILED;
650 *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
652 *state = CONNECTION_ETHERNET_CABLE_DETACHED;
653 return CONNECTION_ERROR_NONE;
657 int _connection_libnet_get_bluetooth_state(connection_handle_s *conn_handle, connection_bt_state_e *state)
661 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
662 rv = net_get_profile_list(conn_handle->network_info_handle,
663 NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles,
664 &bluetooth_profiles.count);
665 if (rv == NET_ERR_ACCESS_DENIED) {
666 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
667 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
670 if (bluetooth_profiles.count == 0) {
671 *state = CONNECTION_BT_STATE_DEACTIVATED;
672 return CONNECTION_ERROR_NONE;
676 for (; i < bluetooth_profiles.count; i++) {
677 switch (bluetooth_profiles.profiles[i].ProfileState) {
678 case NET_STATE_TYPE_ONLINE:
679 case NET_STATE_TYPE_READY:
680 *state = CONNECTION_BT_STATE_CONNECTED;
682 case NET_STATE_TYPE_IDLE:
683 case NET_STATE_TYPE_FAILURE:
684 case NET_STATE_TYPE_ASSOCIATION:
685 case NET_STATE_TYPE_CONFIGURATION:
686 case NET_STATE_TYPE_DISCONNECT:
687 *state = CONNECTION_BT_STATE_DISCONNECTED;
690 __libnet_clear_profile_list(&bluetooth_profiles);
691 return CONNECTION_ERROR_OPERATION_FAILED;
697 __libnet_clear_profile_list(&bluetooth_profiles);
699 return CONNECTION_ERROR_NONE;
702 int _connection_libnet_get_profile_iterator(connection_handle_s *conn_handle,
703 connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
707 net_profile_info_t *profiles = NULL;
709 struct _profile_list_s profile_list = {0, 0, NULL};
711 __libnet_clear_profile_list(&profile_iterator);
713 rv = net_get_all_profile_list(conn_handle->network_info_handle,
714 &profile_list.profiles, &profile_list.count);
715 if (rv == NET_ERR_ACCESS_DENIED) {
716 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
717 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
718 } else if (rv != NET_ERR_NO_SERVICE && rv != NET_ERR_NONE)
719 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
721 *profile_iter_h = &profile_iterator;
724 case CONNECTION_ITERATOR_TYPE_REGISTERED:
725 count = profile_list.count;
726 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
728 return CONNECTION_ERROR_NONE;
730 profiles = g_try_new0(net_profile_info_t, count);
731 if (profiles == NULL) {
732 __libnet_clear_profile_list(&profile_list);
733 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
736 profile_iterator.profiles = profiles;
738 memcpy(profiles, profile_list.profiles, sizeof(net_profile_info_t) * count);
741 case CONNECTION_ITERATOR_TYPE_CONNECTED:
742 count = __libnet_get_connected_count(&profile_list);
743 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
745 return CONNECTION_ERROR_NONE;
747 profiles = g_try_new0(net_profile_info_t, count);
748 if (profiles == NULL) {
749 __libnet_clear_profile_list(&profile_list);
750 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
753 profile_iterator.profiles = profiles;
755 __libnet_copy_connected_profile(&profiles, &profile_list);
758 case CONNECTION_ITERATOR_TYPE_DEFAULT:
759 count = __libnet_get_default_count(&profile_list);
760 CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count); //LCOV_EXCL_LINE
762 return CONNECTION_ERROR_NONE;
764 profiles = g_try_new0(net_profile_info_t, count);
765 if (profiles == NULL) {
766 __libnet_clear_profile_list(&profile_list);
767 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
770 profile_iterator.profiles = profiles;
772 __libnet_copy_default_profile(&profiles, &profile_list);
777 __libnet_clear_profile_list(&profile_list);
779 profile_iterator.count = count;
781 return CONNECTION_ERROR_NONE;
784 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
786 if (profile_iter_h != &profile_iterator)
787 return CONNECTION_ERROR_INVALID_PARAMETER;
789 if (profile_iterator.count <= profile_iterator.next)
790 return CONNECTION_ERROR_ITERATOR_END;
792 *profile = &profile_iterator.profiles[profile_iterator.next];
793 profile_iterator.next++;
795 return CONNECTION_ERROR_NONE;
798 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
800 if (profile_iter_h != &profile_iterator)
803 if (profile_iterator.count <= profile_iterator.next)
809 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
811 if (profile_iter_h != &profile_iterator)
812 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
814 __libnet_clear_profile_list(&profile_iterator);
816 return CONNECTION_ERROR_NONE;
819 int _connection_libnet_get_current_profile(connection_handle_s *conn_handle,
820 connection_profile_h *profile)
822 net_profile_info_t active_profile;
825 rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
826 if (rv == NET_ERR_NO_SERVICE)
827 return CONNECTION_ERROR_NO_CONNECTION; //LCOV_EXCL_LINE
828 else if (rv == NET_ERR_ACCESS_DENIED) {
829 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
830 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
831 } else if (rv != NET_ERR_NONE)
832 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
834 *profile = g_try_malloc0(sizeof(net_profile_info_t));
835 if (*profile == NULL)
836 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
838 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
839 prof_handle_list = g_slist_append(prof_handle_list, *profile);
841 return CONNECTION_ERROR_NONE;
844 int _connection_libnet_reset_profile(connection_handle_s *conn_handle,
845 connection_reset_option_e type, connection_cellular_subscriber_id_e id)
849 rv = net_reset_profile(conn_handle->network_info_handle, type, id);
850 if (rv == NET_ERR_ACCESS_DENIED)
851 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
852 else if (rv != NET_ERR_NONE)
853 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
855 return CONNECTION_ERROR_NONE;
858 int _connection_libnet_open_profile(connection_handle_s *conn_handle,
859 connection_profile_h profile)
863 if (!(_connection_libnet_check_profile_validity(profile))) {
864 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
865 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
868 net_profile_info_t *profile_info = profile;
870 if (profile_info->profile_type == NET_DEVICE_MESH)
871 rv = net_open_mesh_connection_with_profile(conn_handle->network_info_handle,
872 profile_info->ProfileName);
874 rv = net_open_connection_with_profile(conn_handle->network_info_handle,
875 profile_info->ProfileName);
877 if (rv == NET_ERR_ACCESS_DENIED)
878 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
879 else if (rv != NET_ERR_NONE)
880 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
882 return CONNECTION_ERROR_NONE;
885 int _connection_libnet_get_cellular_service_profile(connection_handle_s *conn_handle,
886 connection_cellular_service_type_e type, connection_profile_h *profile)
889 int rv = NET_ERR_NONE;
890 #if defined TIZEN_DUALSIM_ENABLE
891 int default_subscriber_id = 0;
892 char subscriber_id[3];
895 struct _profile_list_s cellular_profiles = { 0, 0, NULL };
896 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
898 rv = net_get_profile_list(conn_handle->network_info_handle,
899 NET_DEVICE_CELLULAR, &cellular_profiles.profiles,
900 &cellular_profiles.count);
901 if (rv == NET_ERR_ACCESS_DENIED) {
902 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
903 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
904 } else if (rv != NET_ERR_NONE) {
905 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv); //LCOV_EXCL_LINE
906 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
909 #if defined TIZEN_DUALSIM_ENABLE
910 if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
911 &default_subscriber_id) != 0) {
912 CONNECTION_LOG(CONNECTION_ERROR,
913 "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
914 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
915 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
918 g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
921 for (i = 0; i < cellular_profiles.count; i++)
922 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
923 #if defined TIZEN_DUALSIM_ENABLE
924 if (g_str_has_suffix(
925 cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
926 subscriber_id) == TRUE)
930 if (i >= cellular_profiles.count) {
931 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
932 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
935 *profile = g_try_malloc0(sizeof(net_profile_info_t));
936 if (*profile == NULL) {
937 __libnet_clear_profile_list(&cellular_profiles); //LCOV_EXCL_LINE
938 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
941 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
943 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
947 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
948 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
951 for (j = 0; j < cellular_profiles.count; j++) {
955 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
958 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
959 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
966 __libnet_clear_profile_list(&cellular_profiles);
967 prof_handle_list = g_slist_append(prof_handle_list, *profile);
969 return CONNECTION_ERROR_NONE;
972 int _connection_libnet_set_cellular_service_profile_sync(connection_handle_s *conn_handle,
973 connection_cellular_service_type_e type, connection_profile_h profile)
977 if (!(_connection_libnet_check_profile_validity(profile))) {
978 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
979 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
982 net_profile_info_t *profile_info = profile;
983 connection_cellular_service_type_e service_type;
985 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
987 if (service_type != type)
988 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
990 rv = net_set_default_cellular_service_profile(conn_handle->network_info_handle,
991 profile_info->ProfileName);
992 if (rv == NET_ERR_ACCESS_DENIED) {
993 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
994 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
995 } else if (rv != NET_ERR_NONE)
996 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
998 return CONNECTION_ERROR_NONE;
1001 int _connection_libnet_set_cellular_service_profile_async(connection_handle_s *conn_handle,
1002 connection_cellular_service_type_e type, connection_profile_h profile)
1006 if (!(_connection_libnet_check_profile_validity(profile))) {
1007 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1008 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1011 net_profile_info_t *profile_info = profile;
1012 connection_cellular_service_type_e service_type;
1014 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
1016 if (service_type != type)
1017 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1019 rv = net_set_default_cellular_service_profile_async(conn_handle->network_info_handle,
1020 profile_info->ProfileName);
1021 if (rv == NET_ERR_ACCESS_DENIED) {
1022 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1023 } else if (rv != NET_ERR_NONE)
1024 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1026 return CONNECTION_ERROR_NONE;
1029 int _connection_libnet_close_profile(connection_handle_s *conn_handle, connection_profile_h profile)
1033 if (!(_connection_libnet_check_profile_validity(profile))) {
1034 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1035 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1038 net_profile_info_t *profile_info = profile;
1040 if (profile_info->profile_type == NET_DEVICE_MESH)
1041 rv = net_close_mesh_connection(conn_handle->network_info_handle, profile_info->ProfileName);
1043 rv = net_close_connection(conn_handle->network_info_handle, profile_info->ProfileName);
1045 if (rv == NET_ERR_ACCESS_DENIED)
1046 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1047 else if (rv != NET_ERR_NONE)
1048 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1050 return CONNECTION_ERROR_NONE;
1053 int _connection_libnet_add_route(connection_handle_s *conn_handle,
1054 const char *interface_name, const char *host_address)
1057 char *endstr = NULL;
1058 int address_family = 0;
1060 address_family = AF_INET;
1062 endstr = strrchr(host_address, '.');
1063 if (endstr == NULL ||
1064 strcmp(endstr, ".0") == 0 ||
1065 strncmp(host_address, "0.", 2) == 0 ||
1066 strstr(host_address, "255") != NULL) {
1067 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1068 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1071 rv = net_add_route(conn_handle->network_info_handle,
1072 host_address, interface_name, address_family);
1073 if (rv == NET_ERR_ACCESS_DENIED) {
1074 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1075 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1076 } else if (rv != NET_ERR_NONE)
1077 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1079 return CONNECTION_ERROR_NONE;
1082 int _connection_libnet_remove_route(connection_handle_s *conn_handle,
1083 const char *interface_name, const char *host_address)
1086 char *endstr = strrchr(host_address, '.');
1087 int address_family = 0;
1089 address_family = AF_INET;
1091 endstr = strrchr(host_address, '.');
1092 if (endstr == NULL ||
1093 strcmp(endstr, ".0") == 0 ||
1094 strncmp(host_address, "0.", 2) == 0 ||
1095 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1096 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1097 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1100 rv = net_remove_route(conn_handle->network_info_handle,
1101 host_address, interface_name, address_family);
1102 if (rv == NET_ERR_ACCESS_DENIED) {
1103 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1104 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1105 } else if (rv != NET_ERR_NONE)
1106 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1108 return CONNECTION_ERROR_NONE;
1111 int _connection_libnet_add_route_ipv6(connection_handle_s *conn_handle,
1112 const char *interface_name, const char *host_address, const char *gateway)
1115 int address_family = 0;
1117 address_family = AF_INET6;
1119 if (strncmp(host_address, "fe80:", 5) == 0 ||
1120 strncmp(host_address, "ff00:", 5) == 0 ||
1121 strncmp(host_address, "::", 2) == 0) {
1122 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1123 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1126 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1127 host_address, interface_name, address_family, gateway);
1128 if (rv == NET_ERR_ACCESS_DENIED) {
1129 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1130 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1131 } else if (rv != NET_ERR_NONE)
1132 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1134 return CONNECTION_ERROR_NONE;
1137 int _connection_libnet_remove_route_ipv6(connection_handle_s *conn_handle,
1138 const char *interface_name, const char *host_address, const char *gateway)
1141 int address_family = 0;
1143 address_family = AF_INET6;
1145 if (strncmp(host_address, "fe80:", 5) == 0 ||
1146 strncmp(host_address, "ff00:", 5) == 0 ||
1147 strncmp(host_address, "::", 2) == 0) {
1148 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1149 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1152 rv = net_remove_route_ipv6(conn_handle->network_info_handle,
1153 host_address, interface_name, address_family, gateway);
1154 if (rv == NET_ERR_ACCESS_DENIED) {
1155 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1156 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1157 } else if (rv != NET_ERR_NONE)
1158 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1160 return CONNECTION_ERROR_NONE;
1163 int _connection_libnet_add_route_entry(connection_handle_s *conn_handle,
1164 connection_address_family_e address_family, const char *interface_name,
1165 const char *host_address, const char *gateway)
1168 char *endstr = NULL;
1169 int address_family_type = 0;
1171 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1172 address_family_type = AF_INET;
1174 address_family_type = AF_INET6;
1176 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1178 endstr = strrchr(host_address, '.');
1179 if (endstr == NULL ||
1180 strcmp(endstr, ".0") == 0 ||
1181 strncmp(host_address, "0.", 2) == 0 ||
1182 strstr(host_address, "255") != NULL) {
1183 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1184 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1187 rv = net_add_route_entry(conn_handle->network_info_handle,
1188 host_address, interface_name, address_family_type, gateway);
1189 if (rv == NET_ERR_ACCESS_DENIED) {
1190 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1191 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1192 } else if (rv != NET_ERR_NONE)
1193 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1197 if (strncmp(host_address, "fe80:", 5) == 0 ||
1198 strncmp(host_address, "ff00:", 5) == 0 ||
1199 strncmp(host_address, "::", 2) == 0) {
1200 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1201 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1204 rv = net_add_route_ipv6(conn_handle->network_info_handle,
1205 host_address, interface_name, address_family_type, gateway);
1206 if (rv == NET_ERR_ACCESS_DENIED) {
1207 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1208 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1209 } else if (rv != NET_ERR_NONE)
1210 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1213 return CONNECTION_ERROR_NONE;
1216 int _connection_libnet_remove_route_entry(connection_handle_s *conn_handle,
1217 connection_address_family_e address_family, const char *interface_name,
1218 const char *host_address, const char *gateway)
1221 char *endstr = strrchr(host_address, '.');
1222 int address_family_type = 0;
1224 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
1225 address_family_type = AF_INET;
1227 address_family_type = AF_INET6;
1229 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1230 endstr = strrchr(host_address, '.');
1231 if (endstr == NULL ||
1232 strcmp(endstr, ".0") == 0 ||
1233 strncmp(host_address, "0.", 2) == 0 ||
1234 strstr(host_address, ".0.") != NULL || strstr(host_address, "255") != NULL) {
1235 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed"); //LCOV_EXCL_LINE
1236 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1239 rv = net_remove_route_entry(conn_handle->network_info_handle, host_address,
1240 interface_name, address_family_type, gateway);
1241 if (rv == NET_ERR_ACCESS_DENIED) {
1242 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1243 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1244 } else if (rv != NET_ERR_NONE)
1245 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1249 if (strncmp(host_address, "fe80:", 5) == 0 ||
1250 strncmp(host_address, "ff00:", 5) == 0 ||
1251 strncmp(host_address, "::", 2) == 0) {
1252 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n"); //LCOV_EXCL_LINE
1253 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1256 rv = net_remove_route_ipv6(conn_handle->network_info_handle, host_address,
1257 interface_name, address_family_type, gateway);
1258 if (rv == NET_ERR_ACCESS_DENIED) {
1259 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1260 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1261 } else if (rv != NET_ERR_NONE)
1262 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1265 return CONNECTION_ERROR_NONE;
1268 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
1270 prof_handle_list = g_slist_append(prof_handle_list, profile);
1273 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
1275 prof_handle_list = g_slist_remove(prof_handle_list, profile);
1279 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
1280 connection_profile_state_changed_cb callback, void *user_data)
1282 net_profile_info_t *profile_info = profile;
1283 char *profile_name = g_strdup(profile_info->ProfileName);
1285 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
1286 if (profile_cb_info == NULL) {
1287 g_free(profile_name); //LCOV_EXCL_LINE
1288 return false; //LCOV_EXCL_LINE
1291 profile_cb_info->callback = callback;
1292 profile_cb_info->user_data = user_data;
1293 profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
1295 g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
1300 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
1302 net_profile_info_t *profile_info = profile;
1304 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
1307 return false; //LCOV_EXCL_LINE
1310 int _connection_libnet_set_statistics(connection_handle_s *conn_handle,
1311 net_device_t device_type, net_statistics_type_e statistics_type)
1314 rv = net_set_statistics(conn_handle->network_info_handle,
1315 device_type, statistics_type);
1316 if (rv == NET_ERR_ACCESS_DENIED) {
1317 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1318 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1319 } else if (rv != NET_ERR_NONE)
1320 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1322 return CONNECTION_ERROR_NONE;
1325 int _connection_libnet_get_statistics(connection_handle_s *conn_handle,
1326 net_statistics_type_e statistics_type, unsigned long long *size)
1329 rv = net_get_statistics(conn_handle->network_info_handle,
1330 NET_DEVICE_WIFI, statistics_type, size);
1331 if (rv == NET_ERR_ACCESS_DENIED) {
1332 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1333 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1334 } else if (rv != NET_ERR_NONE)
1335 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1337 return CONNECTION_ERROR_NONE;
1340 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
1341 connection_cellular_subscriber_id_e sim_id)
1343 char *modem_path = NULL;
1344 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
1346 if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
1347 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id); //LCOV_EXCL_LINE
1348 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1352 CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path"); //LCOV_EXCL_LINE
1353 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1356 g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
1357 NET_PROFILE_NAME_LEN_MAX);
1360 return CONNECTION_ERROR_NONE;
1363 int _connection_libnet_check_get_privilege(void)
1367 rv = net_check_get_privilege();
1368 if (rv == NET_ERR_ACCESS_DENIED) {
1369 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1370 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1371 } else if (rv != NET_ERR_NONE)
1372 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1374 return CONNECTION_ERROR_NONE;
1377 int _connection_libnet_check_profile_privilege(void)
1381 rv = net_check_profile_privilege();
1382 if (rv == NET_ERR_ACCESS_DENIED) {
1383 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1384 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1385 } else if (rv != NET_ERR_NONE)
1386 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1388 return CONNECTION_ERROR_NONE;
1391 bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature)
1393 if (!connection_is_feature_checked[feature]) {
1394 if (system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) {
1395 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); //LCOV_EXCL_LINE
1396 set_last_result(CONNECTION_ERROR_OPERATION_FAILED); //LCOV_EXCL_LINE
1397 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1399 connection_is_feature_checked[feature] = true;
1401 return connection_feature_supported[feature];
1404 int _connection_check_feature_supported(const char *feature_name, ...)
1409 bool feature_supported = false;
1411 va_start(list, feature_name);
1414 if (strcmp(key, TELEPHONY_FEATURE) == 0)
1415 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY);
1416 if (strcmp(key, WIFI_FEATURE) == 0)
1417 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI);
1418 if (strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)
1419 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH);
1420 if (strcmp(key, ETHERNET_FEATURE) == 0)
1421 value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET);
1423 feature_supported |= value;
1424 key = va_arg(list, const char *);
1427 if (!feature_supported) {
1428 CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
1429 set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
1431 return CONNECTION_ERROR_NOT_SUPPORTED;
1435 set_last_result(CONNECTION_ERROR_NONE);
1436 return CONNECTION_ERROR_NONE;
1439 int _connection_libnet_start_tcpdump(connection_handle_s *conn_handle)
1441 connection_error_e result = CONNECTION_ERROR_NONE;
1442 net_err_t ret = NET_ERR_NONE;
1444 ret = net_start_tcpdump(conn_handle->network_info_handle);
1445 result = __libnet_convert_to_cp_error_type(ret);
1450 int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle)
1452 connection_error_e result = CONNECTION_ERROR_NONE;
1453 net_err_t ret = NET_ERR_NONE;
1455 ret = net_stop_tcpdump(conn_handle->network_info_handle);
1456 result = __libnet_convert_to_cp_error_type(ret);
1461 int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle,
1462 gboolean *tcpdump_state)
1464 connection_error_e result = CONNECTION_ERROR_NONE;
1465 net_err_t ret = NET_ERR_NONE;
1467 ret = net_get_tcpdump_state(conn_handle->network_info_handle, tcpdump_state);
1468 result = __libnet_convert_to_cp_error_type(ret);
1473 void _connection_lock(void)
1475 pthread_mutex_lock(&g_conn_thread_mutex);
1478 void _connection_unlock(void)
1480 pthread_mutex_unlock(&g_conn_thread_mutex);