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 *conn_handle_list = NULL;
25 static void __connection_cb_state_change_cb(keynode_t *node, void *user_data);
26 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data);
27 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data);
29 static int __connection_convert_net_state(int status)
32 case VCONFKEY_NETWORK_CELLULAR:
33 return CONNECTION_TYPE_CELLULAR;
34 case VCONFKEY_NETWORK_WIFI:
35 return CONNECTION_TYPE_WIFI;
36 case VCONFKEY_NETWORK_ETHERNET:
37 return CONNECTION_TYPE_ETHERNET;
38 case VCONFKEY_NETWORK_BLUETOOTH:
39 return CONNECTION_TYPE_BT;
41 return CONNECTION_TYPE_DISCONNECTED;
45 static int __connection_convert_cellular_state(int status)
48 case VCONFKEY_NETWORK_CELLULAR_ON:
49 return CONNECTION_CELLULAR_STATE_AVAILABLE;
50 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
51 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
52 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
53 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
54 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
55 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
57 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
61 static int __connection_get_type_changed_callback_count(void)
66 for (list = conn_handle_list; list; list = list->next) {
67 connection_handle_s *local_handle = (connection_handle_s *)list->data;
68 if (local_handle->type_changed_callback) count++;
74 static int __connection_get_ip_changed_callback_count(void)
79 for (list = conn_handle_list; list; list = list->next) {
80 connection_handle_s *local_handle = (connection_handle_s *)list->data;
81 if (local_handle->ip_changed_callback) count++;
87 static int __connection_get_proxy_changed_callback_count(void)
92 for (list = conn_handle_list; list; list = list->next) {
93 connection_handle_s *local_handle = (connection_handle_s *)list->data;
94 if (local_handle->proxy_changed_callback) count++;
100 static int __connection_set_type_changed_callback(connection_h connection,
101 void *callback, void *user_data)
103 connection_handle_s *local_handle = (connection_handle_s *)connection;
106 if (__connection_get_type_changed_callback_count() == 0)
107 if (vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS ,
108 __connection_cb_state_change_cb, NULL))
109 return CONNECTION_ERROR_OPERATION_FAILED;
111 local_handle->state_changed_user_data = user_data;
113 if (local_handle->type_changed_callback &&
114 __connection_get_type_changed_callback_count() == 1)
115 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
116 __connection_cb_state_change_cb))
117 return CONNECTION_ERROR_OPERATION_FAILED;
120 local_handle->type_changed_callback = callback;
121 return CONNECTION_ERROR_NONE;
124 static int __connection_set_ip_changed_callback(connection_h connection,
125 void *callback, void *user_data)
127 connection_handle_s *local_handle = (connection_handle_s *)connection;
130 if (__connection_get_ip_changed_callback_count() == 0)
131 if (vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
132 __connection_cb_ip_change_cb, NULL))
133 return CONNECTION_ERROR_OPERATION_FAILED;
135 local_handle->ip_changed_user_data = user_data;
137 if (local_handle->ip_changed_callback &&
138 __connection_get_ip_changed_callback_count() == 1)
139 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
140 __connection_cb_ip_change_cb))
141 return CONNECTION_ERROR_OPERATION_FAILED;
144 local_handle->ip_changed_callback = callback;
145 return CONNECTION_ERROR_NONE;
148 static int __connection_set_proxy_changed_callback(connection_h connection,
149 void *callback, void *user_data)
151 connection_handle_s *local_handle = (connection_handle_s *)connection;
154 if (__connection_get_proxy_changed_callback_count() == 0)
155 if (vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
156 __connection_cb_proxy_change_cb, NULL))
157 return CONNECTION_ERROR_OPERATION_FAILED;
159 local_handle->proxy_changed_user_data = user_data;
161 if (local_handle->proxy_changed_callback &&
162 __connection_get_proxy_changed_callback_count() == 1)
163 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
164 __connection_cb_proxy_change_cb))
165 return CONNECTION_ERROR_OPERATION_FAILED;
168 local_handle->proxy_changed_callback = callback;
169 return CONNECTION_ERROR_NONE;
172 static void __connection_cb_state_change_cb(keynode_t *node, void *user_data)
174 CONNECTION_LOG(CONNECTION_INFO, "Net Status Changed Indication\n");
177 int state = vconf_keynode_get_int(node);
179 for (list = conn_handle_list; list; list = list->next) {
180 connection_handle_s *local_handle = (connection_handle_s *)list->data;
181 if (local_handle->type_changed_callback)
182 local_handle->type_changed_callback(
183 __connection_convert_net_state(state),
184 local_handle->state_changed_user_data);
188 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
190 CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n");
193 char *ip_addr = vconf_keynode_get_str(node);
195 for (list = conn_handle_list; list; list = list->next) {
196 connection_handle_s *local_handle = (connection_handle_s *)list->data;
197 if (local_handle->ip_changed_callback)
198 local_handle->ip_changed_callback(
200 local_handle->ip_changed_user_data);
204 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
206 CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n");
209 char *proxy = vconf_keynode_get_str(node);
211 for (list = conn_handle_list; list; list = list->next) {
212 connection_handle_s *local_handle = (connection_handle_s *)list->data;
213 if (local_handle->proxy_changed_callback)
214 local_handle->proxy_changed_callback(
216 local_handle->proxy_changed_user_data);
220 static bool __connection_check_handle_validity(connection_h connection)
224 for (list = conn_handle_list; list; list = list->next)
225 if (connection == list->data) return true;
230 static int __connection_get_handle_count(void)
235 if (!conn_handle_list)
238 for (list = conn_handle_list; list; list = list->next) count++;
243 /* Connection Manager ********************************************************/
244 EXPORT_API int connection_create(connection_h* connection)
246 CONNECTION_MUTEX_LOCK;
248 if (connection == NULL || __connection_check_handle_validity(*connection)) {
249 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
250 CONNECTION_MUTEX_UNLOCK;
251 return CONNECTION_ERROR_INVALID_PARAMETER;
254 if (_connection_libnet_init() == false) {
255 CONNECTION_LOG(CONNECTION_ERROR, "Creation failed!\n");
256 CONNECTION_MUTEX_UNLOCK;
257 return CONNECTION_ERROR_OPERATION_FAILED;
260 CONNECTION_LOG(CONNECTION_ERROR, "Connection successfully created!\n");
262 *connection = g_try_malloc0(sizeof(connection_handle_s));
263 if (*connection != NULL) {
264 CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection);
266 CONNECTION_MUTEX_UNLOCK;
267 return CONNECTION_ERROR_OUT_OF_MEMORY;
270 conn_handle_list = g_slist_append(conn_handle_list, *connection);
272 CONNECTION_MUTEX_UNLOCK;
273 return CONNECTION_ERROR_NONE;
276 EXPORT_API int connection_destroy(connection_h connection)
278 CONNECTION_MUTEX_LOCK;
280 if (connection == NULL || !(__connection_check_handle_validity(connection))) {
281 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
282 CONNECTION_MUTEX_UNLOCK;
283 return CONNECTION_ERROR_INVALID_PARAMETER;
286 CONNECTION_LOG(CONNECTION_INFO, "Destroy Handle : %p\n", connection);
288 __connection_set_type_changed_callback(connection, NULL, NULL);
289 __connection_set_ip_changed_callback(connection, NULL, NULL);
290 __connection_set_proxy_changed_callback(connection, NULL, NULL);
292 conn_handle_list = g_slist_remove(conn_handle_list, connection);
296 if (__connection_get_handle_count() == 0)
297 _connection_libnet_deinit();
299 CONNECTION_MUTEX_UNLOCK;
300 return CONNECTION_ERROR_NONE;
303 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
307 if (type == NULL || !(__connection_check_handle_validity(connection))) {
308 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
309 return CONNECTION_ERROR_INVALID_PARAMETER;
312 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) {
313 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
314 return CONNECTION_ERROR_OPERATION_FAILED;
317 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n", status);
319 *type = __connection_convert_net_state(status);
321 return CONNECTION_ERROR_NONE;
324 EXPORT_API int connection_get_ip_address(connection_h connection,
325 connection_address_family_e address_family, char** ip_address)
327 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
328 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
329 return CONNECTION_ERROR_INVALID_PARAMETER;
332 switch (address_family) {
333 case CONNECTION_ADDRESS_FAMILY_IPV4:
334 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
336 case CONNECTION_ADDRESS_FAMILY_IPV6:
337 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
338 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
341 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
342 return CONNECTION_ERROR_INVALID_PARAMETER;
345 if (*ip_address == NULL) {
346 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
347 return CONNECTION_ERROR_OPERATION_FAILED;
350 return CONNECTION_ERROR_NONE;
353 EXPORT_API int connection_get_proxy(connection_h connection,
354 connection_address_family_e address_family, char** proxy)
356 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
357 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
358 return CONNECTION_ERROR_INVALID_PARAMETER;
361 switch (address_family) {
362 case CONNECTION_ADDRESS_FAMILY_IPV4:
363 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
365 case CONNECTION_ADDRESS_FAMILY_IPV6:
366 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
367 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
370 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
371 return CONNECTION_ERROR_INVALID_PARAMETER;
374 if (*proxy == NULL) {
375 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
376 return CONNECTION_ERROR_OPERATION_FAILED;
379 return CONNECTION_ERROR_NONE;
382 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
385 int cellular_state = 0;
387 if (state == NULL || !(__connection_check_handle_validity(connection))) {
388 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
389 return CONNECTION_ERROR_INVALID_PARAMETER;
392 if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) {
393 CONNECTION_LOG(CONNECTION_INFO, "Cellular = %d\n", status);
394 *state = __connection_convert_cellular_state(status);
396 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
397 if (vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state)) {
398 CONNECTION_LOG(CONNECTION_ERROR,
399 "vconf_get_int Failed = %d\n", cellular_state);
400 return CONNECTION_ERROR_OPERATION_FAILED;
404 CONNECTION_LOG(CONNECTION_INFO, "Connection state = %d\n", cellular_state);
406 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
407 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
408 cellular_state == VCONFKEY_DNET_TRANSFER)
409 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
411 return CONNECTION_ERROR_NONE;
413 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
414 return CONNECTION_ERROR_OPERATION_FAILED;
418 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
422 if (state == NULL || !(__connection_check_handle_validity(connection))) {
423 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
424 return CONNECTION_ERROR_INVALID_PARAMETER;
427 rv = _connection_libnet_get_wifi_state(state);
428 if (rv != CONNECTION_ERROR_NONE) {
429 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv);
433 CONNECTION_LOG(CONNECTION_INFO, "WiFi state = %d\n", *state);
435 return CONNECTION_ERROR_NONE;
438 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
440 if (state == NULL || !(__connection_check_handle_validity(connection))) {
441 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
442 return CONNECTION_ERROR_INVALID_PARAMETER;
445 return _connection_libnet_get_ethernet_state(state);
448 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
450 if (state == NULL || !(__connection_check_handle_validity(connection))) {
451 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
452 return CONNECTION_ERROR_INVALID_PARAMETER;
455 return _connection_libnet_get_bluetooth_state(state);
459 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
460 connection_type_changed_cb callback, void* user_data)
462 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
463 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
464 return CONNECTION_ERROR_INVALID_PARAMETER;
467 return __connection_set_type_changed_callback(connection, callback, user_data);
470 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
472 if (!(__connection_check_handle_validity(connection))) {
473 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
474 return CONNECTION_ERROR_INVALID_PARAMETER;
477 return __connection_set_type_changed_callback(connection, NULL, NULL);
480 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
481 connection_address_changed_cb callback, void* user_data)
483 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
484 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
485 return CONNECTION_ERROR_INVALID_PARAMETER;
488 return __connection_set_ip_changed_callback(connection, callback, user_data);
491 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
493 if (!(__connection_check_handle_validity(connection))) {
494 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
495 return CONNECTION_ERROR_INVALID_PARAMETER;
498 return __connection_set_ip_changed_callback(connection, NULL, NULL);
501 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
502 connection_address_changed_cb callback, void* user_data)
504 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
505 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
506 return CONNECTION_ERROR_INVALID_PARAMETER;
509 return __connection_set_proxy_changed_callback(connection, callback, user_data);
512 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
514 if (!(__connection_check_handle_validity(connection))) {
515 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
516 return CONNECTION_ERROR_INVALID_PARAMETER;
519 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
522 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
524 if (!(__connection_check_handle_validity(connection)) ||
525 !(_connection_libnet_check_profile_validity(profile))) {
526 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
527 return CONNECTION_ERROR_INVALID_PARAMETER;
532 net_profile_info_t *profile_info = profile;
534 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
535 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
536 return CONNECTION_ERROR_INVALID_PARAMETER;
539 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
540 if (rv != NET_ERR_NONE) {
541 CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
542 return CONNECTION_ERROR_OPERATION_FAILED;
545 return CONNECTION_ERROR_NONE;
548 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
550 if (!(__connection_check_handle_validity(connection)) ||
551 !(_connection_libnet_check_profile_validity(profile))) {
552 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
553 return CONNECTION_ERROR_INVALID_PARAMETER;
557 net_profile_info_t *profile_info = profile;
559 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
560 profile_info->profile_type != NET_DEVICE_WIFI) {
561 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
562 return CONNECTION_ERROR_INVALID_PARAMETER;
565 rv = net_delete_profile(profile_info->ProfileName);
566 if (rv != NET_ERR_NONE) {
567 CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
568 return CONNECTION_ERROR_OPERATION_FAILED;
571 return CONNECTION_ERROR_NONE;
574 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
576 if (!(__connection_check_handle_validity(connection)) ||
577 !(_connection_libnet_check_profile_validity(profile))) {
578 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
579 return CONNECTION_ERROR_INVALID_PARAMETER;
583 net_profile_info_t *profile_info = profile;
585 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
586 if (rv != NET_ERR_NONE) {
587 CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
588 return CONNECTION_ERROR_OPERATION_FAILED;
591 return CONNECTION_ERROR_NONE;
594 EXPORT_API int connection_get_profile_iterator(connection_h connection,
595 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
597 if (!(__connection_check_handle_validity(connection)) ||
598 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
599 type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
600 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
601 return CONNECTION_ERROR_INVALID_PARAMETER;
604 return _connection_libnet_get_profile_iterator(type, profile_iterator);
607 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
608 connection_profile_h* profile)
610 return _connection_libnet_get_iterator_next(profile_iterator, profile);
613 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
615 return _connection_libnet_iterator_has_next(profile_iterator);
618 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
620 return _connection_libnet_destroy_iterator(profile_iterator);
623 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
625 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
626 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
627 return CONNECTION_ERROR_INVALID_PARAMETER;
630 return _connection_libnet_get_current_profile(profile);
633 EXPORT_API int connection_get_default_cellular_service_profile(connection_h connection,
634 connection_cellular_service_type_e type, connection_profile_h* profile)
636 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
637 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
638 return CONNECTION_ERROR_INVALID_PARAMETER;
641 return _connection_libnet_get_cellular_service_profile(type, profile);
644 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
645 connection_cellular_service_type_e type, connection_profile_h profile)
647 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
648 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
649 return CONNECTION_ERROR_INVALID_PARAMETER;
652 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
655 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
656 connection_cellular_service_type_e type, connection_profile_h profile,
657 connection_set_default_cb callback, void* user_data)
659 if (!(__connection_check_handle_validity(connection)) ||
660 profile == NULL || callback == NULL) {
661 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
662 return CONNECTION_ERROR_INVALID_PARAMETER;
665 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
668 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
669 connection_opened_cb callback, void* user_data)
671 if (!(__connection_check_handle_validity(connection)) ||
672 profile == NULL || callback == NULL) {
673 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
674 return CONNECTION_ERROR_INVALID_PARAMETER;
677 return _connection_libnet_open_profile(profile, callback, user_data);
680 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
681 connection_closed_cb callback, void* user_data)
683 if (!(__connection_check_handle_validity(connection)) ||
684 profile == NULL || callback == NULL) {
685 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
686 return CONNECTION_ERROR_INVALID_PARAMETER;
689 return _connection_libnet_close_profile(profile, callback, user_data);
692 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
694 if (!(__connection_check_handle_validity(connection)) ||
695 interface_name == NULL || host_address == NULL) {
696 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
697 return CONNECTION_ERROR_INVALID_PARAMETER;
700 return _connection_libnet_add_route(interface_name, host_address);
704 /* Connection Statistics module ******************************************************************/
706 static int __get_statistic(connection_type_e connection_type,
707 connection_statistics_type_e statistics_type, long long* llsize)
710 unsigned long long ull_size;
714 if (llsize == NULL) {
715 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
716 return CONNECTION_ERROR_INVALID_PARAMETER;
719 if (connection_type == CONNECTION_TYPE_CELLULAR) {
720 switch (statistics_type) {
721 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
722 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT;
724 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
725 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV;
727 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
728 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT;
730 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
731 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV;
734 return CONNECTION_ERROR_INVALID_PARAMETER;
737 if (vconf_get_int(key, &size)) {
738 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size);
740 return CONNECTION_ERROR_OPERATION_FAILED;
743 CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size);
744 *llsize = (long long)size;
745 } else if (connection_type == CONNECTION_TYPE_WIFI) {
746 switch (statistics_type) {
747 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
748 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
750 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
751 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
753 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
754 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
756 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
757 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
760 return CONNECTION_ERROR_INVALID_PARAMETER;
763 if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
764 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
766 return CONNECTION_ERROR_OPERATION_FAILED;
769 CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size);
770 *llsize = (long long)ull_size;
772 return CONNECTION_ERROR_INVALID_PARAMETER;
774 return CONNECTION_ERROR_NONE;
777 static int __reset_statistic(connection_type_e connection_type,
778 connection_statistics_type_e statistics_type)
784 if (connection_type == CONNECTION_TYPE_CELLULAR)
785 conn_type = NET_DEVICE_CELLULAR;
786 else if (connection_type == CONNECTION_TYPE_WIFI)
787 conn_type = NET_DEVICE_WIFI;
789 return CONNECTION_ERROR_INVALID_PARAMETER;
791 switch (statistics_type) {
792 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
793 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
795 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
796 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
798 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
799 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
801 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
802 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
805 return CONNECTION_ERROR_INVALID_PARAMETER;
808 rv = _connection_libnet_set_statistics(conn_type, stat_type);
809 if(rv != CONNECTION_ERROR_NONE)
813 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n");
815 return CONNECTION_ERROR_NONE;
818 EXPORT_API int connection_get_statistics(connection_h connection,
819 connection_type_e connection_type,
820 connection_statistics_type_e statistics_type, long long* size)
822 return __get_statistic(connection_type, statistics_type, size);
825 EXPORT_API int connection_reset_statistics(connection_h connection,
826 connection_type_e connection_type,
827 connection_statistics_type_e statistics_type)
829 return __reset_statistic(connection_type, statistics_type);