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 if (connection == NULL)
227 if (g_slist_find(conn_handle_list, connection) != NULL)
233 static int __connection_get_handle_count(void)
238 if (!conn_handle_list)
241 for (list = conn_handle_list; list; list = list->next) count++;
246 /* Connection Manager ********************************************************/
247 EXPORT_API int connection_create(connection_h* connection)
249 CONNECTION_MUTEX_LOCK;
251 if (connection == NULL || __connection_check_handle_validity(*connection)) {
252 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
253 CONNECTION_MUTEX_UNLOCK;
254 return CONNECTION_ERROR_INVALID_PARAMETER;
257 rv = _connection_libnet_init();
258 if (rv == NET_ERR_ACCESS_DENIED) {
259 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
260 return CONNECTION_ERROR_PERMISSION_DENIED;
262 else if (rv != NET_ERR_NONE) {
263 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv);
264 return CONNECTION_ERROR_OPERATION_FAILED;
267 *connection = g_try_malloc0(sizeof(connection_handle_s));
268 if (*connection != NULL) {
269 CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection);
271 CONNECTION_MUTEX_UNLOCK;
272 return CONNECTION_ERROR_OUT_OF_MEMORY;
275 conn_handle_list = g_slist_append(conn_handle_list, *connection);
277 CONNECTION_MUTEX_UNLOCK;
278 return CONNECTION_ERROR_NONE;
281 EXPORT_API int connection_destroy(connection_h connection)
283 CONNECTION_MUTEX_LOCK;
285 if (connection == NULL || !(__connection_check_handle_validity(connection))) {
286 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
287 CONNECTION_MUTEX_UNLOCK;
288 return CONNECTION_ERROR_INVALID_PARAMETER;
291 CONNECTION_LOG(CONNECTION_INFO, "Destroy Handle : %p\n", connection);
293 __connection_set_type_changed_callback(connection, NULL, NULL);
294 __connection_set_ip_changed_callback(connection, NULL, NULL);
295 __connection_set_proxy_changed_callback(connection, NULL, NULL);
297 conn_handle_list = g_slist_remove(conn_handle_list, connection);
301 if (__connection_get_handle_count() == 0)
302 _connection_libnet_deinit();
304 CONNECTION_MUTEX_UNLOCK;
305 return CONNECTION_ERROR_NONE;
308 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
312 if (type == NULL || !(__connection_check_handle_validity(connection))) {
313 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
314 return CONNECTION_ERROR_INVALID_PARAMETER;
317 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) {
318 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
319 return CONNECTION_ERROR_OPERATION_FAILED;
322 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n", status);
324 *type = __connection_convert_net_state(status);
326 return CONNECTION_ERROR_NONE;
329 EXPORT_API int connection_get_ip_address(connection_h connection,
330 connection_address_family_e address_family, char** ip_address)
332 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
333 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
334 return CONNECTION_ERROR_INVALID_PARAMETER;
337 switch (address_family) {
338 case CONNECTION_ADDRESS_FAMILY_IPV4:
339 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
341 case CONNECTION_ADDRESS_FAMILY_IPV6:
342 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
343 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
346 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
347 return CONNECTION_ERROR_INVALID_PARAMETER;
350 if (*ip_address == NULL) {
351 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
352 return CONNECTION_ERROR_OPERATION_FAILED;
355 return CONNECTION_ERROR_NONE;
358 EXPORT_API int connection_get_proxy(connection_h connection,
359 connection_address_family_e address_family, char** proxy)
361 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
362 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
363 return CONNECTION_ERROR_INVALID_PARAMETER;
366 switch (address_family) {
367 case CONNECTION_ADDRESS_FAMILY_IPV4:
368 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
370 case CONNECTION_ADDRESS_FAMILY_IPV6:
371 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
372 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
375 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
376 return CONNECTION_ERROR_INVALID_PARAMETER;
379 if (*proxy == NULL) {
380 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
381 return CONNECTION_ERROR_OPERATION_FAILED;
384 return CONNECTION_ERROR_NONE;
387 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
390 int cellular_state = 0;
392 if (state == NULL || !(__connection_check_handle_validity(connection))) {
393 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
394 return CONNECTION_ERROR_INVALID_PARAMETER;
397 if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) {
398 CONNECTION_LOG(CONNECTION_INFO, "Cellular = %d\n", status);
399 *state = __connection_convert_cellular_state(status);
401 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
402 if (vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state)) {
403 CONNECTION_LOG(CONNECTION_ERROR,
404 "vconf_get_int Failed = %d\n", cellular_state);
405 return CONNECTION_ERROR_OPERATION_FAILED;
409 CONNECTION_LOG(CONNECTION_INFO, "Connection state = %d\n", cellular_state);
411 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
412 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
413 cellular_state == VCONFKEY_DNET_TRANSFER)
414 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
416 return CONNECTION_ERROR_NONE;
418 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
419 return CONNECTION_ERROR_OPERATION_FAILED;
423 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
427 if (state == NULL || !(__connection_check_handle_validity(connection))) {
428 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
429 return CONNECTION_ERROR_INVALID_PARAMETER;
432 rv = _connection_libnet_get_wifi_state(state);
433 if (rv != CONNECTION_ERROR_NONE) {
434 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv);
438 CONNECTION_LOG(CONNECTION_INFO, "WiFi state = %d\n", *state);
440 return CONNECTION_ERROR_NONE;
443 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
445 if (state == NULL || !(__connection_check_handle_validity(connection))) {
446 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
447 return CONNECTION_ERROR_INVALID_PARAMETER;
450 return _connection_libnet_get_ethernet_state(state);
453 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
455 if (state == NULL || !(__connection_check_handle_validity(connection))) {
456 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
457 return CONNECTION_ERROR_INVALID_PARAMETER;
460 return _connection_libnet_get_bluetooth_state(state);
464 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
465 connection_type_changed_cb callback, void* user_data)
467 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
468 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
469 return CONNECTION_ERROR_INVALID_PARAMETER;
472 return __connection_set_type_changed_callback(connection, callback, user_data);
475 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
477 if (!(__connection_check_handle_validity(connection))) {
478 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
479 return CONNECTION_ERROR_INVALID_PARAMETER;
482 return __connection_set_type_changed_callback(connection, NULL, NULL);
485 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
486 connection_address_changed_cb callback, void* user_data)
488 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
489 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
490 return CONNECTION_ERROR_INVALID_PARAMETER;
493 return __connection_set_ip_changed_callback(connection, callback, user_data);
496 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
498 if (!(__connection_check_handle_validity(connection))) {
499 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
500 return CONNECTION_ERROR_INVALID_PARAMETER;
503 return __connection_set_ip_changed_callback(connection, NULL, NULL);
506 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
507 connection_address_changed_cb callback, void* user_data)
509 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
510 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
511 return CONNECTION_ERROR_INVALID_PARAMETER;
514 return __connection_set_proxy_changed_callback(connection, callback, user_data);
517 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
519 if (!(__connection_check_handle_validity(connection))) {
520 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
521 return CONNECTION_ERROR_INVALID_PARAMETER;
524 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
527 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
529 if (!(__connection_check_handle_validity(connection)) ||
530 !(_connection_libnet_check_profile_validity(profile))) {
531 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
532 return CONNECTION_ERROR_INVALID_PARAMETER;
537 net_profile_info_t *profile_info = profile;
539 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
540 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
541 return CONNECTION_ERROR_INVALID_PARAMETER;
544 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
545 if (rv == NET_ERR_ACCESS_DENIED) {
546 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
547 return CONNECTION_ERROR_PERMISSION_DENIED;
548 } else if (rv != NET_ERR_NONE) {
549 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
550 return CONNECTION_ERROR_OPERATION_FAILED;
553 return CONNECTION_ERROR_NONE;
556 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
558 if (!(__connection_check_handle_validity(connection)) ||
559 !(_connection_libnet_check_profile_validity(profile))) {
560 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
561 return CONNECTION_ERROR_INVALID_PARAMETER;
565 net_profile_info_t *profile_info = profile;
567 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
568 profile_info->profile_type != NET_DEVICE_WIFI) {
569 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
570 return CONNECTION_ERROR_INVALID_PARAMETER;
573 rv = net_delete_profile(profile_info->ProfileName);
574 if (rv == NET_ERR_ACCESS_DENIED) {
575 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
576 return CONNECTION_ERROR_PERMISSION_DENIED;
577 } else if (rv != NET_ERR_NONE) {
578 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
579 return CONNECTION_ERROR_OPERATION_FAILED;
582 return CONNECTION_ERROR_NONE;
585 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
587 if (!(__connection_check_handle_validity(connection)) ||
588 !(_connection_libnet_check_profile_validity(profile))) {
589 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
590 return CONNECTION_ERROR_INVALID_PARAMETER;
594 net_profile_info_t *profile_info = profile;
596 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
597 if (rv == NET_ERR_ACCESS_DENIED) {
598 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
599 return CONNECTION_ERROR_PERMISSION_DENIED;
600 } else if (rv != NET_ERR_NONE) {
601 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
602 return CONNECTION_ERROR_OPERATION_FAILED;
605 return CONNECTION_ERROR_NONE;
608 EXPORT_API int connection_get_profile_iterator(connection_h connection,
609 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
611 if (!(__connection_check_handle_validity(connection)) ||
612 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
613 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
614 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
615 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
616 return CONNECTION_ERROR_INVALID_PARAMETER;
619 return _connection_libnet_get_profile_iterator(type, profile_iterator);
622 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
623 connection_profile_h* profile)
625 return _connection_libnet_get_iterator_next(profile_iterator, profile);
628 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
630 return _connection_libnet_iterator_has_next(profile_iterator);
633 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
635 return _connection_libnet_destroy_iterator(profile_iterator);
638 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
640 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
641 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
642 return CONNECTION_ERROR_INVALID_PARAMETER;
645 return _connection_libnet_get_current_profile(profile);
648 EXPORT_API int connection_get_default_cellular_service_profile(connection_h connection,
649 connection_cellular_service_type_e type, connection_profile_h* profile)
651 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
652 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
653 return CONNECTION_ERROR_INVALID_PARAMETER;
656 return _connection_libnet_get_cellular_service_profile(type, profile);
659 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
660 connection_cellular_service_type_e type, connection_profile_h profile)
662 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
663 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
664 return CONNECTION_ERROR_INVALID_PARAMETER;
667 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
670 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
671 connection_cellular_service_type_e type, connection_profile_h profile,
672 connection_set_default_cb callback, void* user_data)
674 if (!(__connection_check_handle_validity(connection)) ||
675 profile == NULL || callback == NULL) {
676 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
677 return CONNECTION_ERROR_INVALID_PARAMETER;
680 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
683 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
684 connection_opened_cb callback, void* user_data)
686 if (!(__connection_check_handle_validity(connection)) ||
687 profile == NULL || callback == NULL) {
688 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
689 return CONNECTION_ERROR_INVALID_PARAMETER;
692 return _connection_libnet_open_profile(profile, callback, user_data);
695 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
696 connection_closed_cb callback, void* user_data)
698 if (!(__connection_check_handle_validity(connection)) ||
699 profile == NULL || callback == NULL) {
700 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
701 return CONNECTION_ERROR_INVALID_PARAMETER;
704 return _connection_libnet_close_profile(profile, callback, user_data);
707 EXPORT_API int connection_reset_profile(connection_h connection,
708 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
710 if (!(__connection_check_handle_validity(connection))) {
711 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
712 return CONNECTION_ERROR_INVALID_PARAMETER;
715 if(id < 0 || id > 1) {
716 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
717 return CONNECTION_ERROR_INVALID_PARAMETER;
720 return _connection_libnet_reset_profile(type, id, callback, user_data);
723 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
725 if (!(__connection_check_handle_validity(connection)) ||
726 interface_name == NULL || host_address == NULL) {
727 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
728 return CONNECTION_ERROR_INVALID_PARAMETER;
731 return _connection_libnet_add_route(interface_name, host_address);
734 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
736 if (!(__connection_check_handle_validity(connection)) ||
737 interface_name == NULL || host_address == NULL) {
738 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
739 return CONNECTION_ERROR_INVALID_PARAMETER;
742 return _connection_libnet_remove_route(interface_name, host_address);
745 /* Connection Statistics module ******************************************************************/
747 static int __get_statistic(connection_type_e connection_type,
748 connection_statistics_type_e statistics_type, long long* llsize)
751 unsigned long long ull_size;
755 if (llsize == NULL) {
756 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
757 return CONNECTION_ERROR_INVALID_PARAMETER;
760 if (connection_type == CONNECTION_TYPE_CELLULAR) {
761 switch (statistics_type) {
762 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
763 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT;
765 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
766 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV;
768 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
769 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT;
771 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
772 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV;
775 return CONNECTION_ERROR_INVALID_PARAMETER;
778 if (vconf_get_int(key, &size)) {
779 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size);
781 return CONNECTION_ERROR_OPERATION_FAILED;
784 CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size);
785 *llsize = (long long)size;
786 } else if (connection_type == CONNECTION_TYPE_WIFI) {
787 switch (statistics_type) {
788 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
789 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
791 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
792 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
794 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
795 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
797 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
798 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
801 return CONNECTION_ERROR_INVALID_PARAMETER;
804 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
805 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
807 else if (rv != CONNECTION_ERROR_NONE) {
808 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
810 return CONNECTION_ERROR_OPERATION_FAILED;
813 CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size);
814 *llsize = (long long)ull_size;
816 return CONNECTION_ERROR_INVALID_PARAMETER;
818 return CONNECTION_ERROR_NONE;
821 static int __reset_statistic(connection_type_e connection_type,
822 connection_statistics_type_e statistics_type)
828 if (connection_type == CONNECTION_TYPE_CELLULAR)
829 conn_type = NET_DEVICE_CELLULAR;
830 else if (connection_type == CONNECTION_TYPE_WIFI)
831 conn_type = NET_DEVICE_WIFI;
833 return CONNECTION_ERROR_INVALID_PARAMETER;
835 switch (statistics_type) {
836 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
837 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
839 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
840 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
842 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
843 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
845 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
846 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
849 return CONNECTION_ERROR_INVALID_PARAMETER;
852 rv = _connection_libnet_set_statistics(conn_type, stat_type);
853 if(rv != CONNECTION_ERROR_NONE)
857 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n");
859 return CONNECTION_ERROR_NONE;
862 EXPORT_API int connection_get_statistics(connection_h connection,
863 connection_type_e connection_type,
864 connection_statistics_type_e statistics_type, long long* size)
866 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
867 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
868 return CONNECTION_ERROR_INVALID_PARAMETER;
871 return __get_statistic(connection_type, statistics_type, size);
874 EXPORT_API int connection_reset_statistics(connection_h connection,
875 connection_type_e connection_type,
876 connection_statistics_type_e statistics_type)
878 if (!(__connection_check_handle_validity(connection))) {
879 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
880 return CONNECTION_ERROR_INVALID_PARAMETER;
883 return __reset_statistic(connection_type, statistics_type);