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);
30 static int __connection_convert_net_state(int status)
33 case VCONFKEY_NETWORK_CELLULAR:
34 return CONNECTION_TYPE_CELLULAR;
35 case VCONFKEY_NETWORK_WIFI:
36 return CONNECTION_TYPE_WIFI;
37 case VCONFKEY_NETWORK_ETHERNET:
38 return CONNECTION_TYPE_ETHERNET;
39 case VCONFKEY_NETWORK_BLUETOOTH:
40 return CONNECTION_TYPE_BT;
42 return CONNECTION_TYPE_DISCONNECTED;
46 static int __connection_convert_cellular_state(int status)
49 case VCONFKEY_NETWORK_CELLULAR_ON:
50 return CONNECTION_CELLULAR_STATE_AVAILABLE;
51 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
52 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
53 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
54 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
55 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
56 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
58 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
62 static int __connection_get_type_changed_callback_count(void)
67 for (list = conn_handle_list; list; list = list->next) {
68 connection_handle_s *local_handle = (connection_handle_s *)list->data;
69 if (local_handle->type_changed_callback) count++;
75 static int __connection_get_ip_changed_callback_count(void)
80 for (list = conn_handle_list; list; list = list->next) {
81 connection_handle_s *local_handle = (connection_handle_s *)list->data;
82 if (local_handle->ip_changed_callback) count++;
88 static int __connection_get_proxy_changed_callback_count(void)
93 for (list = conn_handle_list; list; list = list->next) {
94 connection_handle_s *local_handle = (connection_handle_s *)list->data;
95 if (local_handle->proxy_changed_callback) count++;
101 static int __connection_set_type_changed_callback(connection_h connection,
102 void *callback, void *user_data)
104 connection_handle_s *local_handle = (connection_handle_s *)connection;
107 if (__connection_get_type_changed_callback_count() == 0)
108 if (vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS ,
109 __connection_cb_state_change_cb, NULL))
110 return CONNECTION_ERROR_OPERATION_FAILED;
112 local_handle->state_changed_user_data = user_data;
114 if (local_handle->type_changed_callback &&
115 __connection_get_type_changed_callback_count() == 1)
116 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
117 __connection_cb_state_change_cb))
118 return CONNECTION_ERROR_OPERATION_FAILED;
121 local_handle->type_changed_callback = callback;
122 return CONNECTION_ERROR_NONE;
125 static int __connection_set_ip_changed_callback(connection_h connection,
126 void *callback, void *user_data)
128 connection_handle_s *local_handle = (connection_handle_s *)connection;
131 if (__connection_get_ip_changed_callback_count() == 0)
132 if (vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
133 __connection_cb_ip_change_cb, NULL))
134 return CONNECTION_ERROR_OPERATION_FAILED;
136 local_handle->ip_changed_user_data = user_data;
138 if (local_handle->ip_changed_callback &&
139 __connection_get_ip_changed_callback_count() == 1)
140 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
141 __connection_cb_ip_change_cb))
142 return CONNECTION_ERROR_OPERATION_FAILED;
145 local_handle->ip_changed_callback = callback;
146 return CONNECTION_ERROR_NONE;
149 static int __connection_set_proxy_changed_callback(connection_h connection,
150 void *callback, void *user_data)
152 connection_handle_s *local_handle = (connection_handle_s *)connection;
155 if (__connection_get_proxy_changed_callback_count() == 0)
156 if (vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
157 __connection_cb_proxy_change_cb, NULL))
158 return CONNECTION_ERROR_OPERATION_FAILED;
160 local_handle->proxy_changed_user_data = user_data;
162 if (local_handle->proxy_changed_callback &&
163 __connection_get_proxy_changed_callback_count() == 1)
164 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
165 __connection_cb_proxy_change_cb))
166 return CONNECTION_ERROR_OPERATION_FAILED;
169 local_handle->proxy_changed_callback = callback;
170 return CONNECTION_ERROR_NONE;
173 static void __connection_cb_state_change_cb(keynode_t *node, void *user_data)
175 CONNECTION_LOG(CONNECTION_INFO, "Net Status Changed Indication\n");
178 int state = vconf_keynode_get_int(node);
180 for (list = conn_handle_list; list; list = list->next) {
181 connection_handle_s *local_handle = (connection_handle_s *)list->data;
182 if (local_handle->type_changed_callback)
183 local_handle->type_changed_callback(
184 __connection_convert_net_state(state),
185 local_handle->state_changed_user_data);
189 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
191 CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n");
194 char *ip_addr = vconf_keynode_get_str(node);
196 for (list = conn_handle_list; list; list = list->next) {
197 connection_handle_s *local_handle = (connection_handle_s *)list->data;
198 if (local_handle->ip_changed_callback)
199 local_handle->ip_changed_callback(
201 local_handle->ip_changed_user_data);
205 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
207 CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n");
210 char *proxy = vconf_keynode_get_str(node);
212 for (list = conn_handle_list; list; list = list->next) {
213 connection_handle_s *local_handle = (connection_handle_s *)list->data;
214 if (local_handle->proxy_changed_callback)
215 local_handle->proxy_changed_callback(
217 local_handle->proxy_changed_user_data);
221 static bool __connection_check_handle_validity(connection_h connection)
225 for (list = conn_handle_list; list; list = list->next)
226 if (connection == list->data) return true;
231 static int __connection_get_handle_count(void)
236 if (!conn_handle_list)
239 for (list = conn_handle_list; list; list = list->next) count++;
244 /* Connection Manager module ********************************************************************/
246 int connection_create(connection_h* connection)
248 CONNECTION_MUTEX_LOCK;
250 if (connection == NULL || __connection_check_handle_validity(*connection)) {
251 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
252 CONNECTION_MUTEX_UNLOCK;
253 return CONNECTION_ERROR_INVALID_PARAMETER;
256 if (_connection_libnet_init() == false) {
257 CONNECTION_LOG(CONNECTION_ERROR, "Creation failed!\n");
258 CONNECTION_MUTEX_UNLOCK;
259 return CONNECTION_ERROR_OPERATION_FAILED;
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 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 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 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 CONNECTION_LOG(CONNECTION_INFO, "IP Address %s\n", *ip_address);
352 return CONNECTION_ERROR_NONE;
355 int connection_get_proxy(connection_h connection,
356 connection_address_family_e address_family, char** proxy)
358 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
359 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
360 return CONNECTION_ERROR_INVALID_PARAMETER;
363 switch (address_family) {
364 case CONNECTION_ADDRESS_FAMILY_IPV4:
365 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
367 case CONNECTION_ADDRESS_FAMILY_IPV6:
368 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
369 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
372 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
373 return CONNECTION_ERROR_INVALID_PARAMETER;
376 if (*proxy == NULL) {
377 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
378 return CONNECTION_ERROR_OPERATION_FAILED;
381 CONNECTION_LOG(CONNECTION_INFO, "Proxy Address %s\n", *proxy);
383 return CONNECTION_ERROR_NONE;
386 int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
389 int cellular_state = 0;
391 if (state == NULL || !(__connection_check_handle_validity(connection))) {
392 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
393 return CONNECTION_ERROR_INVALID_PARAMETER;
396 if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) {
397 CONNECTION_LOG(CONNECTION_INFO, "Cellular = %d\n", status);
398 *state = __connection_convert_cellular_state(status);
400 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
401 if (vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state)) {
402 CONNECTION_LOG(CONNECTION_ERROR,
403 "vconf_get_int Failed = %d\n", cellular_state);
404 return CONNECTION_ERROR_OPERATION_FAILED;
408 CONNECTION_LOG(CONNECTION_INFO, "Connection state = %d\n", cellular_state);
410 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
411 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
412 cellular_state == VCONFKEY_DNET_TRANSFER)
413 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
415 return CONNECTION_ERROR_NONE;
417 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
418 return CONNECTION_ERROR_OPERATION_FAILED;
422 int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
424 if (state == NULL || !(__connection_check_handle_validity(connection))) {
425 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
426 return CONNECTION_ERROR_INVALID_PARAMETER;
429 if (_connection_libnet_get_wifi_state(state) == false) {
430 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get wifi state\n");
431 return CONNECTION_ERROR_OPERATION_FAILED;
434 CONNECTION_LOG(CONNECTION_INFO, "WiFi state = %d\n", *state);
436 return CONNECTION_ERROR_NONE;
439 int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
441 if (state == NULL || !(__connection_check_handle_validity(connection))) {
442 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
443 return CONNECTION_ERROR_INVALID_PARAMETER;
446 if (_connection_libnet_get_ethernet_state(state) == false)
447 return CONNECTION_ERROR_OPERATION_FAILED;
449 return CONNECTION_ERROR_NONE;
452 int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
454 if (state == NULL || !(__connection_check_handle_validity(connection))) {
455 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
456 return CONNECTION_ERROR_INVALID_PARAMETER;
459 if (_connection_libnet_get_bluetooth_state(state) == false)
460 return CONNECTION_ERROR_OPERATION_FAILED;
462 return CONNECTION_ERROR_NONE;
465 int connection_set_type_changed_cb(connection_h connection,
466 connection_type_changed_cb callback, void* user_data)
468 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
469 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
470 return CONNECTION_ERROR_INVALID_PARAMETER;
473 return __connection_set_type_changed_callback(connection, callback, user_data);
476 int connection_unset_type_changed_cb(connection_h connection)
478 if (!(__connection_check_handle_validity(connection))) {
479 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
480 return CONNECTION_ERROR_INVALID_PARAMETER;
483 return __connection_set_type_changed_callback(connection, NULL, NULL);
486 int connection_set_ip_address_changed_cb(connection_h connection,
487 connection_address_changed_cb callback, void* user_data)
489 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
490 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
491 return CONNECTION_ERROR_INVALID_PARAMETER;
494 return __connection_set_ip_changed_callback(connection, callback, user_data);
497 int connection_unset_ip_address_changed_cb(connection_h connection)
499 if (!(__connection_check_handle_validity(connection))) {
500 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
501 return CONNECTION_ERROR_INVALID_PARAMETER;
504 return __connection_set_ip_changed_callback(connection, NULL, NULL);
507 int connection_set_proxy_address_changed_cb(connection_h connection,
508 connection_address_changed_cb callback, void* user_data)
510 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
511 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
512 return CONNECTION_ERROR_INVALID_PARAMETER;
515 return __connection_set_proxy_changed_callback(connection, callback, user_data);
518 int connection_unset_proxy_address_changed_cb(connection_h connection)
520 if (!(__connection_check_handle_validity(connection))) {
521 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
522 return CONNECTION_ERROR_INVALID_PARAMETER;
525 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
528 int connection_add_profile(connection_h connection, connection_profile_h profile)
530 if (!(__connection_check_handle_validity(connection)) ||
531 !(_connection_libnet_check_profile_validity(profile))) {
532 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
533 return CONNECTION_ERROR_INVALID_PARAMETER;
538 net_profile_info_t *profile_info = profile;
540 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
541 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
542 return CONNECTION_ERROR_INVALID_PARAMETER;
545 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
546 if (rv != NET_ERR_NONE) {
547 CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
548 return CONNECTION_ERROR_OPERATION_FAILED;
551 return CONNECTION_ERROR_NONE;
554 int connection_remove_profile(connection_h connection, connection_profile_h profile)
556 if (!(__connection_check_handle_validity(connection)) ||
557 !(_connection_libnet_check_profile_validity(profile))) {
558 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
559 return CONNECTION_ERROR_INVALID_PARAMETER;
563 net_profile_info_t *profile_info = profile;
565 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
566 profile_info->profile_type != NET_DEVICE_WIFI) {
567 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
568 return CONNECTION_ERROR_INVALID_PARAMETER;
571 rv = net_delete_profile(profile_info->ProfileName);
572 if (rv != NET_ERR_NONE) {
573 CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
574 return CONNECTION_ERROR_OPERATION_FAILED;
577 return CONNECTION_ERROR_NONE;
580 int connection_update_profile(connection_h connection, connection_profile_h profile)
582 if (!(__connection_check_handle_validity(connection)) ||
583 !(_connection_libnet_check_profile_validity(profile))) {
584 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
585 return CONNECTION_ERROR_INVALID_PARAMETER;
589 net_profile_info_t *profile_info = profile;
591 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
592 if (rv != NET_ERR_NONE) {
593 CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
594 return CONNECTION_ERROR_OPERATION_FAILED;
597 return CONNECTION_ERROR_NONE;
600 int connection_get_profile_iterator(connection_h connection,
601 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
603 if (!(__connection_check_handle_validity(connection)) ||
604 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
605 type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
606 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
607 return CONNECTION_ERROR_INVALID_PARAMETER;
610 return _connection_libnet_get_profile_iterator(type, profile_iterator);
613 int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
614 connection_profile_h* profile)
616 return _connection_libnet_get_iterator_next(profile_iterator, profile);
619 bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
621 return _connection_libnet_iterator_has_next(profile_iterator);
624 int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
626 return _connection_libnet_destroy_iterator(profile_iterator);
629 int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
631 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
632 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
633 return CONNECTION_ERROR_INVALID_PARAMETER;
636 return _connection_libnet_get_current_profile(profile);
639 int connection_open_profile(connection_h connection, connection_profile_h profile,
640 connection_opened_cb callback, void* user_data)
642 if (!(__connection_check_handle_validity(connection)) ||
643 profile == NULL || callback == NULL) {
644 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
645 return CONNECTION_ERROR_INVALID_PARAMETER;
648 return _connection_libnet_open_profile(profile, callback, user_data);
650 int connection_get_default_cellular_service_profile(connection_h connection,
651 connection_cellular_service_type_e type, connection_profile_h* profile)
653 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
654 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
655 return CONNECTION_ERROR_INVALID_PARAMETER;
658 return _connection_libnet_get_cellular_service_profile(type, profile);
661 int connection_set_default_cellular_service_profile(connection_h connection,
662 connection_cellular_service_type_e type, connection_profile_h profile)
664 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
665 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
666 return CONNECTION_ERROR_INVALID_PARAMETER;
669 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
672 int connection_set_default_cellular_service_profile_async(connection_h connection,
673 connection_cellular_service_type_e type, connection_profile_h profile,
674 connection_set_default_cb callback, void* user_data)
676 if (!(__connection_check_handle_validity(connection)) ||
677 profile == NULL || callback == NULL) {
678 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
679 return CONNECTION_ERROR_INVALID_PARAMETER;
682 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
685 int connection_close_profile(connection_h connection, connection_profile_h profile,
686 connection_closed_cb callback, void* user_data)
688 if (!(__connection_check_handle_validity(connection)) ||
689 profile == NULL || callback == NULL) {
690 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
691 return CONNECTION_ERROR_INVALID_PARAMETER;
694 return _connection_libnet_close_profile(profile, callback, user_data);
697 int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
699 if (!(__connection_check_handle_validity(connection)) ||
700 interface_name == NULL || host_address == NULL) {
701 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
702 return CONNECTION_ERROR_INVALID_PARAMETER;
705 return _connection_libnet_add_route(interface_name, host_address);
709 /* Connection Statistics module ******************************************************************/
711 static int __get_statistic(connection_type_e connection_type,
712 connection_statistics_type_e statistics_type, long long* llsize)
715 unsigned long long ull_size;
719 if (llsize == NULL) {
720 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
721 return CONNECTION_ERROR_INVALID_PARAMETER;
724 if (connection_type == CONNECTION_TYPE_CELLULAR) {
725 switch (statistics_type) {
726 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
727 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT;
729 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
730 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV;
732 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
733 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT;
735 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
736 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV;
739 return CONNECTION_ERROR_INVALID_PARAMETER;
742 if (vconf_get_int(key, &size)) {
743 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size);
745 return CONNECTION_ERROR_OPERATION_FAILED;
748 CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size);
749 *llsize = (long long)size;
750 } else if (connection_type == CONNECTION_TYPE_WIFI) {
751 switch (statistics_type) {
752 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
753 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
755 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
756 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
758 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
759 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
761 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
762 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
765 return CONNECTION_ERROR_INVALID_PARAMETER;
768 if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
769 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
771 return CONNECTION_ERROR_OPERATION_FAILED;
774 CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size);
775 *llsize = (long long)ull_size;
777 return CONNECTION_ERROR_INVALID_PARAMETER;
779 return CONNECTION_ERROR_NONE;
782 static int __reset_statistic(connection_type_e connection_type,
783 connection_statistics_type_e statistics_type)
789 if (connection_type == CONNECTION_TYPE_CELLULAR)
790 conn_type = NET_DEVICE_CELLULAR;
791 else if (connection_type == CONNECTION_TYPE_WIFI)
792 conn_type = NET_DEVICE_WIFI;
794 return CONNECTION_ERROR_INVALID_PARAMETER;
796 switch (statistics_type) {
797 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
798 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
800 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
801 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
803 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
804 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
806 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
807 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
810 return CONNECTION_ERROR_INVALID_PARAMETER;
813 rv = _connection_libnet_set_statistics(conn_type, stat_type);
814 if(rv != CONNECTION_ERROR_NONE)
818 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n");
820 return CONNECTION_ERROR_NONE;
823 int connection_get_statistics(connection_type_e connection_type,
824 connection_statistics_type_e statistics_type, long long* size)
826 return __get_statistic(connection_type, statistics_type, size);
829 int connection_reset_statistics(connection_type_e connection_type,
830 connection_statistics_type_e statistics_type)
832 return __reset_statistic(connection_type, statistics_type);