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.
20 #include <vconf/vconf.h>
21 #include "net_connection_private.h"
23 static GSList *prof_handle_list = NULL;
24 static GHashTable *profile_cb_table = NULL;
26 struct _profile_cb_s {
27 connection_profile_state_changed_cb callback;
28 connection_profile_state_e state;
32 struct _profile_list_s {
35 net_profile_info_t *profiles;
39 connection_opened_cb opened_cb;
40 connection_closed_cb closed_cb;
41 connection_set_default_cb set_default_cb;
42 void *opened_user_data;
43 void *closed_user_data;
44 void *set_default_user_data;
48 static struct _profile_list_s profile_iterator = {0, 0, NULL};
49 static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
51 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
55 return CONNECTION_ERROR_NONE;
56 case NET_ERR_APP_ALREADY_REGISTERED:
57 return CONNECTION_ERROR_INVALID_OPERATION;
58 case NET_ERR_APP_NOT_REGISTERED:
59 return CONNECTION_ERROR_INVALID_OPERATION;
60 case NET_ERR_NO_ACTIVE_CONNECTIONS:
61 return CONNECTION_ERROR_NO_CONNECTION;
62 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
63 return CONNECTION_ERROR_ALREADY_EXISTS;
64 case NET_ERR_CONNECTION_DHCP_FAILED:
65 return CONNECTION_ERROR_DHCP_FAILED;
66 case NET_ERR_CONNECTION_INVALID_KEY:
67 return CONNECTION_ERROR_INVALID_KEY;
68 case NET_ERR_IN_PROGRESS:
69 return CONNECTION_ERROR_NOW_IN_PROGRESS;
70 case NET_ERR_OPERATION_ABORTED:
71 return CONNECTION_ERROR_OPERATION_ABORTED;
72 case NET_ERR_TIME_OUT:
73 return CONNECTION_ERROR_NO_REPLY;
75 return CONNECTION_ERROR_OPERATION_FAILED;
79 static const char *__libnet_convert_cp_error_type_to_string(connection_error_e err_type)
82 case CONNECTION_ERROR_NONE:
84 case CONNECTION_ERROR_INVALID_PARAMETER:
85 return "INVALID_PARAMETER";
86 case CONNECTION_ERROR_OUT_OF_MEMORY:
87 return "OUT_OF_MEMORY";
88 case CONNECTION_ERROR_INVALID_OPERATION:
89 return "INVALID_OPERATION";
90 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
91 return "ADDRESS_FAMILY_NOT_SUPPORTED";
92 case CONNECTION_ERROR_OPERATION_FAILED:
93 return "OPERATION_FAILED";
94 case CONNECTION_ERROR_ITERATOR_END:
95 return "ITERATOR_END";
96 case CONNECTION_ERROR_NO_CONNECTION:
97 return "NO_CONNECTION";
98 case CONNECTION_ERROR_NOW_IN_PROGRESS:
99 return "NOW_IN_PROGRESS";
100 case CONNECTION_ERROR_ALREADY_EXISTS:
101 return "ALREADY_EXISTS";
102 case CONNECTION_ERROR_OPERATION_ABORTED:
103 return "OPERATION_ABORTED";
104 case CONNECTION_ERROR_DHCP_FAILED:
105 return "DHCP_FAILED";
106 case CONNECTION_ERROR_INVALID_KEY:
107 return "INVALID_KEY";
108 case CONNECTION_ERROR_NO_REPLY:
110 case CONNECTION_ERROR_PERMISSION_DENIED:
111 return "PERMISSION_DENIED";
112 case CONNECTION_ERROR_NOT_SUPPORTED:
113 return "NOT_SUPPORTED";
119 static const char *__libnet_convert_cp_state_to_string(connection_profile_state_e state)
122 case CONNECTION_PROFILE_STATE_DISCONNECTED:
123 return "DISCONNECTED";
124 case CONNECTION_PROFILE_STATE_ASSOCIATION:
125 return "ASSOCIATION";
126 case CONNECTION_PROFILE_STATE_CONFIGURATION:
127 return "CONFIGURATION";
128 case CONNECTION_PROFILE_STATE_CONNECTED:
135 static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
138 libnet.opened_cb = user_cb;
139 libnet.opened_user_data = user_data;
143 static void __libnet_opened_cb(connection_error_e result)
145 if (libnet.opened_cb)
146 libnet.opened_cb(result, libnet.opened_user_data);
148 libnet.opened_cb = NULL;
149 libnet.opened_user_data = NULL;
152 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
155 libnet.closed_cb = user_cb;
156 libnet.closed_user_data = user_data;
160 static void __libnet_closed_cb(connection_error_e result)
162 if (libnet.closed_cb)
163 libnet.closed_cb(result, libnet.closed_user_data);
165 libnet.closed_cb = NULL;
166 libnet.closed_user_data = NULL;
169 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
172 libnet.set_default_cb = user_cb;
173 libnet.set_default_user_data = user_data;
177 static void __libnet_default_cb(connection_error_e result)
179 if (libnet.set_default_cb)
180 libnet.set_default_cb(result, libnet.set_default_user_data);
182 libnet.set_default_cb = NULL;
183 libnet.set_default_user_data = NULL;
186 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
188 if (profile_name == NULL)
191 struct _profile_cb_s *cb_info;
192 cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
197 if (cb_info->state == state)
200 cb_info->state = state;
202 if (state >= 0 && cb_info->callback)
203 cb_info->callback(state, cb_info->user_data);
206 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
208 if (profile_list->count > 0)
209 g_free(profile_list->profiles);
211 profile_list->count = 0;
212 profile_list->next = 0;
213 profile_list->profiles = NULL;
216 static void __libnet_evt_cb(net_event_info_t* event_cb, void* user_data)
218 bool is_requested = false;
219 connection_error_e result = CONNECTION_ERROR_NONE;
221 switch (event_cb->Event) {
222 case NET_EVENT_OPEN_RSP:
225 case NET_EVENT_OPEN_IND:
226 result = __libnet_convert_to_cp_error_type(event_cb->Error);
227 CONNECTION_LOG(CONNECTION_INFO, "Got connection open %s : %s\n",
228 (is_requested) ? "RSP":"IND",
229 __libnet_convert_cp_error_type_to_string(result));
232 __libnet_opened_cb(result);
234 switch (event_cb->Error) {
236 case NET_ERR_ACTIVE_CONNECTION_EXISTS:
237 CONNECTION_LOG(CONNECTION_INFO, "'Open connection' succeeded\n");
239 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
242 CONNECTION_LOG(CONNECTION_ERROR, "'Open connection' failed!! [%s]\n",
243 __libnet_convert_cp_error_type_to_string(result));
246 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
249 case NET_EVENT_CLOSE_RSP:
252 case NET_EVENT_CLOSE_IND:
253 result = __libnet_convert_to_cp_error_type(event_cb->Error);
254 CONNECTION_LOG(CONNECTION_INFO, "Got connection close %s : %s\n",
255 (is_requested) ? "RSP":"IND",
256 __libnet_convert_cp_error_type_to_string(result));
259 __libnet_closed_cb(result);
261 switch (event_cb->Error) {
263 CONNECTION_LOG(CONNECTION_INFO, "'Close connection' succeeded!\n");
265 __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
268 CONNECTION_LOG(CONNECTION_ERROR, "'Close connection' failed!! [%s]\n",
269 __libnet_convert_cp_error_type_to_string(result));
273 case NET_EVENT_NET_STATE_IND:
274 CONNECTION_LOG(CONNECTION_INFO, "Got State changed IND\n");
276 if (event_cb->Datalength != sizeof(net_state_type_t))
279 net_state_type_t *profile_state = (net_state_type_t*)event_cb->Data;
280 connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
282 CONNECTION_LOG(CONNECTION_INFO,
283 "Profile State : %s, profile name : %s\n",
284 __libnet_convert_cp_state_to_string(cp_state),
285 event_cb->ProfileName);
287 __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
290 case NET_EVENT_WIFI_SCAN_IND:
291 case NET_EVENT_WIFI_SCAN_RSP:
292 CONNECTION_LOG(CONNECTION_INFO, "Got wifi scan IND\n");
294 case NET_EVENT_WIFI_POWER_IND:
295 case NET_EVENT_WIFI_POWER_RSP:
296 CONNECTION_LOG(CONNECTION_INFO, "Got wifi power IND\n");
298 case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
299 result = __libnet_convert_to_cp_error_type(event_cb->Error);
300 CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d\n", result);
301 __libnet_default_cb(result);
303 case NET_EVENT_WIFI_WPS_RSP:
304 CONNECTION_LOG(CONNECTION_INFO, "Got wifi WPS RSP\n");
307 CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n");
312 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
317 for (;i < profile_list->count;i++) {
318 if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
319 profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY)
326 void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source)
330 for (;i < source->count;i++) {
331 if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE ||
332 source->profiles[i].ProfileState == NET_STATE_TYPE_READY) {
333 memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
339 bool _connection_libnet_init(void)
343 if (!libnet.registered) {
344 rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
345 if (rv != NET_ERR_NONE)
348 libnet.registered = true;
350 if (profile_cb_table == NULL)
351 profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
357 bool _connection_libnet_deinit(void)
359 if (libnet.registered) {
360 if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
363 libnet.registered = false;
365 if (profile_cb_table) {
366 g_hash_table_destroy(profile_cb_table);
367 profile_cb_table = NULL;
370 __libnet_clear_profile_list(&profile_iterator);
372 if (prof_handle_list) {
373 g_slist_free_full(prof_handle_list, g_free);
374 prof_handle_list = NULL;
381 bool _connection_libnet_check_profile_validity(connection_profile_h profile)
386 for (list = prof_handle_list; list; list = list->next)
387 if (profile == list->data) return true;
389 for (;i < profile_iterator.count;i++)
390 if (profile == &profile_iterator.profiles[i]) return true;
395 bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
397 struct _profile_cb_s *cb_info;
398 net_profile_info_t *profile_info = profile;
403 cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName);
411 int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
414 net_wifi_state_t wlan_state;
415 net_profile_name_t profile_name;
417 rv = net_get_wifi_state(&wlan_state, &profile_name);
418 if (rv != NET_ERR_NONE) {
419 CONNECTION_LOG(CONNECTION_ERROR, "Error!! net_get_wifi_state() failed.\n");
420 return CONNECTION_ERROR_OPERATION_FAILED;
423 switch (wlan_state) {
425 *state = CONNECTION_WIFI_STATE_DEACTIVATED;
428 case WIFI_CONNECTING:
429 *state = CONNECTION_WIFI_STATE_DISCONNECTED;
432 case WIFI_DISCONNECTING:
433 *state = CONNECTION_WIFI_STATE_CONNECTED;
436 CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
437 return CONNECTION_ERROR_INVALID_OPERATION;
440 return CONNECTION_ERROR_NONE;
443 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
445 struct _profile_list_s ethernet_profiles = {0, 0, NULL};
446 net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
448 if (ethernet_profiles.count == 0) {
449 *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
450 return CONNECTION_ERROR_NONE;
453 switch (ethernet_profiles.profiles->ProfileState) {
454 case NET_STATE_TYPE_ONLINE:
455 case NET_STATE_TYPE_READY:
456 *state = CONNECTION_ETHERNET_STATE_CONNECTED;
458 case NET_STATE_TYPE_IDLE:
459 case NET_STATE_TYPE_FAILURE:
460 case NET_STATE_TYPE_ASSOCIATION:
461 case NET_STATE_TYPE_CONFIGURATION:
462 case NET_STATE_TYPE_DISCONNECT:
463 *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
466 return CONNECTION_ERROR_OPERATION_FAILED;
469 __libnet_clear_profile_list(ðernet_profiles);
471 return CONNECTION_ERROR_NONE;
474 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
477 struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
478 net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
480 if (bluetooth_profiles.count == 0) {
481 *state = CONNECTION_BT_STATE_DEACTIVATED;
482 return CONNECTION_ERROR_NONE;
485 for (; i < bluetooth_profiles.count; i++) {
486 switch (bluetooth_profiles.profiles[i].ProfileState) {
487 case NET_STATE_TYPE_ONLINE:
488 case NET_STATE_TYPE_READY:
489 *state = CONNECTION_BT_STATE_CONNECTED;
491 case NET_STATE_TYPE_IDLE:
492 case NET_STATE_TYPE_FAILURE:
493 case NET_STATE_TYPE_ASSOCIATION:
494 case NET_STATE_TYPE_CONFIGURATION:
495 case NET_STATE_TYPE_DISCONNECT:
496 *state = CONNECTION_BT_STATE_DISCONNECTED;
499 __libnet_clear_profile_list(&bluetooth_profiles);
500 return CONNECTION_ERROR_OPERATION_FAILED;
505 __libnet_clear_profile_list(&bluetooth_profiles);
507 return CONNECTION_ERROR_NONE;
510 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
514 net_profile_info_t *profiles = NULL;
516 struct _profile_list_s all_profiles = {0, 0, NULL};
518 __libnet_clear_profile_list(&profile_iterator);
520 rv = net_get_profile_list(NET_DEVICE_MAX, &all_profiles.profiles, &all_profiles.count);
522 if (rv != NET_ERR_NONE) {
523 if (rv == NET_ERR_NO_SERVICE) {
524 *profile_iter_h = &profile_iterator;
525 return CONNECTION_ERROR_NONE;
527 return CONNECTION_ERROR_OPERATION_FAILED;
530 *profile_iter_h = &profile_iterator;
533 case CONNECTION_ITERATOR_TYPE_REGISTERED:
534 count = all_profiles.count;
535 CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d\n", count);
538 return CONNECTION_ERROR_NONE;
540 profile_iterator.profiles = all_profiles.profiles;
543 case CONNECTION_ITERATOR_TYPE_CONNECTED:
544 count = __libnet_get_connected_count(&all_profiles);
545 CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d\n", count);
548 return CONNECTION_ERROR_NONE;
550 profiles = g_try_new0(net_profile_info_t, count);
551 if (profiles == NULL) {
552 __libnet_clear_profile_list(&all_profiles);
553 return CONNECTION_ERROR_OUT_OF_MEMORY;
555 case CONNECTION_ITERATOR_TYPE_DEFAULT:
556 /* To do : Not supported yet */
560 profile_iterator.profiles = profiles;
562 __libnet_copy_connected_profile(&profiles, &all_profiles);
564 __libnet_clear_profile_list(&all_profiles);
567 profile_iterator.count = count;
569 return CONNECTION_ERROR_NONE;
572 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile)
574 if (profile_iter_h != &profile_iterator)
575 return CONNECTION_ERROR_INVALID_PARAMETER;
577 if (profile_iterator.count <= profile_iterator.next)
578 return CONNECTION_ERROR_ITERATOR_END;
580 *profile = &profile_iterator.profiles[profile_iterator.next];
581 profile_iterator.next++;
583 return CONNECTION_ERROR_NONE;
586 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h)
588 if (profile_iter_h != &profile_iterator)
591 if (profile_iterator.count <= profile_iterator.next)
597 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h)
599 if (profile_iter_h != &profile_iterator)
600 return CONNECTION_ERROR_INVALID_PARAMETER;
602 __libnet_clear_profile_list(&profile_iterator);
604 return CONNECTION_ERROR_NONE;
607 int _connection_libnet_get_current_profile(connection_profile_h *profile)
609 net_profile_info_t active_profile;
612 rv = net_get_active_net_info(&active_profile);
613 if (rv == NET_ERR_NO_SERVICE)
614 return CONNECTION_ERROR_NO_CONNECTION;
615 else if (rv != NET_ERR_NONE)
616 return CONNECTION_ERROR_OPERATION_FAILED;
618 *profile = g_try_malloc0(sizeof(net_profile_info_t));
619 if (*profile == NULL)
620 return CONNECTION_ERROR_OUT_OF_MEMORY;
622 memcpy(*profile, &active_profile, sizeof(net_profile_info_t));
623 prof_handle_list = g_slist_append(prof_handle_list, *profile);
625 return CONNECTION_ERROR_NONE;
628 int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void* user_data)
630 if (!(_connection_libnet_check_profile_validity(profile))) {
631 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
632 return CONNECTION_ERROR_INVALID_PARAMETER;
635 net_profile_info_t *profile_info = profile;
637 if (net_open_connection_with_profile(profile_info->ProfileName) != NET_ERR_NONE)
638 return CONNECTION_ERROR_OPERATION_FAILED;
640 __libnet_set_opened_cb(callback, user_data);
642 return CONNECTION_ERROR_NONE;
645 int _connection_libnet_get_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h *profile)
649 int rv = NET_ERR_NONE;
650 net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
652 struct _profile_list_s cellular_profiles = {0, 0, NULL};
654 rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
655 if (rv != NET_ERR_NONE)
656 return CONNECTION_ERROR_OPERATION_FAILED;
658 for (;i < cellular_profiles.count;i++)
659 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
662 if (i >= cellular_profiles.count)
663 return CONNECTION_ERROR_OPERATION_FAILED;
665 *profile = g_try_malloc0(sizeof(net_profile_info_t));
666 if (*profile == NULL)
667 return CONNECTION_ERROR_OUT_OF_MEMORY;
669 memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
671 if (cellular_profiles.profiles[i].ProfileInfo.Pdp.DefaultConn)
674 if (type != CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET &&
675 type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
678 for (;j < cellular_profiles.count;j++) {
682 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.ServiceType != service_type)
685 if (cellular_profiles.profiles[j].ProfileInfo.Pdp.DefaultConn) {
686 memcpy(*profile, &cellular_profiles.profiles[j], sizeof(net_profile_info_t));
692 prof_handle_list = g_slist_append(prof_handle_list, *profile);
694 return CONNECTION_ERROR_NONE;
697 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
699 if (!(_connection_libnet_check_profile_validity(profile))) {
700 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
701 return CONNECTION_ERROR_INVALID_PARAMETER;
704 net_profile_info_t *profile_info = profile;
705 connection_cellular_service_type_e service_type;
707 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
709 if (service_type != type)
710 return CONNECTION_ERROR_INVALID_PARAMETER;
712 if (net_set_default_cellular_service_profile(profile_info->ProfileName) != NET_ERR_NONE)
713 return CONNECTION_ERROR_OPERATION_FAILED;
715 return CONNECTION_ERROR_NONE;
718 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
719 connection_profile_h profile, connection_set_default_cb callback, void* user_data)
721 if (!(_connection_libnet_check_profile_validity(profile))) {
722 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
723 return CONNECTION_ERROR_INVALID_PARAMETER;
726 net_profile_info_t *profile_info = profile;
727 connection_cellular_service_type_e service_type;
729 service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
731 if (service_type != type)
732 return CONNECTION_ERROR_INVALID_PARAMETER;
734 if (net_set_default_cellular_service_profile_async(profile_info->ProfileName) != NET_ERR_NONE)
735 return CONNECTION_ERROR_OPERATION_FAILED;
737 __libnet_set_default_cb(callback, user_data);
739 return CONNECTION_ERROR_NONE;
742 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
744 if (!(_connection_libnet_check_profile_validity(profile))) {
745 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
746 return CONNECTION_ERROR_INVALID_PARAMETER;
749 net_profile_info_t *profile_info = profile;
751 if (net_close_connection(profile_info->ProfileName) != NET_ERR_NONE)
752 return CONNECTION_ERROR_OPERATION_FAILED;
754 __libnet_set_closed_cb(callback, user_data);
756 return CONNECTION_ERROR_NONE;
759 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
761 char *endstr = strrchr(host_address, '.');
763 if (endstr == NULL ||
764 strcmp(endstr, ".0") == 0 ||
765 strncmp(host_address, "0.", 2) == 0 ||
766 strstr(host_address, ".0.") != NULL ||
767 strstr(host_address, "255") != NULL) {
768 CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
769 return CONNECTION_ERROR_INVALID_PARAMETER;
772 if (net_add_route(host_address, interface_name) != NET_ERR_NONE)
773 return CONNECTION_ERROR_OPERATION_FAILED;
775 return CONNECTION_ERROR_NONE;
778 void _connection_libnet_add_to_profile_list(connection_profile_h profile)
780 prof_handle_list = g_slist_append(prof_handle_list, profile);
783 void _connection_libnet_remove_from_profile_list(connection_profile_h profile)
785 prof_handle_list = g_slist_remove(prof_handle_list, profile);
789 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
790 connection_profile_state_changed_cb callback, void *user_data)
792 net_profile_info_t *profile_info = profile;
793 char *profile_name = g_strdup(profile_info->ProfileName);
795 struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s));
796 if (profile_cb_info == NULL) {
797 g_free(profile_name);
801 profile_cb_info->callback = callback;
802 profile_cb_info->user_data = user_data;
804 g_hash_table_insert(profile_cb_table, profile_name, profile_cb_info);
809 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
811 net_profile_info_t *profile_info = profile;
812 if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
818 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
820 if (net_set_statistics(device_type, statistics_type) != NET_ERR_NONE)
821 return CONNECTION_ERROR_OPERATION_FAILED;
823 return CONNECTION_ERROR_NONE;
826 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
828 if (net_get_statistics(NET_DEVICE_WIFI, statistics_type, size) != NET_ERR_NONE)
829 return CONNECTION_ERROR_OPERATION_FAILED;
831 return CONNECTION_ERROR_NONE;