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)
420 if (state == NULL || !(__connection_check_handle_validity(connection))) {
421 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
422 return CONNECTION_ERROR_INVALID_PARAMETER;
425 if (_connection_libnet_get_wifi_state(state) == false) {
426 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get wifi state\n");
427 return CONNECTION_ERROR_OPERATION_FAILED;
430 CONNECTION_LOG(CONNECTION_INFO, "WiFi state = %d\n", *state);
432 return CONNECTION_ERROR_NONE;
435 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
437 if (state == NULL || !(__connection_check_handle_validity(connection))) {
438 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
439 return CONNECTION_ERROR_INVALID_PARAMETER;
442 if (_connection_libnet_get_ethernet_state(state) == false)
443 return CONNECTION_ERROR_OPERATION_FAILED;
445 return CONNECTION_ERROR_NONE;
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 if (_connection_libnet_get_bluetooth_state(state) == false)
456 return CONNECTION_ERROR_OPERATION_FAILED;
458 return CONNECTION_ERROR_NONE;
461 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
462 connection_type_changed_cb callback, void* user_data)
464 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
465 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
466 return CONNECTION_ERROR_INVALID_PARAMETER;
469 return __connection_set_type_changed_callback(connection, callback, user_data);
472 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
474 if (!(__connection_check_handle_validity(connection))) {
475 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
476 return CONNECTION_ERROR_INVALID_PARAMETER;
479 return __connection_set_type_changed_callback(connection, NULL, NULL);
482 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
483 connection_address_changed_cb callback, void* user_data)
485 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
486 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
487 return CONNECTION_ERROR_INVALID_PARAMETER;
490 return __connection_set_ip_changed_callback(connection, callback, user_data);
493 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
495 if (!(__connection_check_handle_validity(connection))) {
496 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
497 return CONNECTION_ERROR_INVALID_PARAMETER;
500 return __connection_set_ip_changed_callback(connection, NULL, NULL);
503 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
504 connection_address_changed_cb callback, void* user_data)
506 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
507 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
508 return CONNECTION_ERROR_INVALID_PARAMETER;
511 return __connection_set_proxy_changed_callback(connection, callback, user_data);
514 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
516 if (!(__connection_check_handle_validity(connection))) {
517 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
518 return CONNECTION_ERROR_INVALID_PARAMETER;
521 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
524 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
526 if (!(__connection_check_handle_validity(connection)) ||
527 !(_connection_libnet_check_profile_validity(profile))) {
528 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
529 return CONNECTION_ERROR_INVALID_PARAMETER;
534 net_profile_info_t *profile_info = profile;
536 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
537 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
538 return CONNECTION_ERROR_INVALID_PARAMETER;
541 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
542 if (rv != NET_ERR_NONE) {
543 CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
544 return CONNECTION_ERROR_OPERATION_FAILED;
547 return CONNECTION_ERROR_NONE;
550 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
552 if (!(__connection_check_handle_validity(connection)) ||
553 !(_connection_libnet_check_profile_validity(profile))) {
554 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
555 return CONNECTION_ERROR_INVALID_PARAMETER;
559 net_profile_info_t *profile_info = profile;
561 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
562 profile_info->profile_type != NET_DEVICE_WIFI) {
563 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
564 return CONNECTION_ERROR_INVALID_PARAMETER;
567 rv = net_delete_profile(profile_info->ProfileName);
568 if (rv != NET_ERR_NONE) {
569 CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
570 return CONNECTION_ERROR_OPERATION_FAILED;
573 return CONNECTION_ERROR_NONE;
576 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
578 if (!(__connection_check_handle_validity(connection)) ||
579 !(_connection_libnet_check_profile_validity(profile))) {
580 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
581 return CONNECTION_ERROR_INVALID_PARAMETER;
585 net_profile_info_t *profile_info = profile;
587 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
588 if (rv != NET_ERR_NONE) {
589 CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
590 return CONNECTION_ERROR_OPERATION_FAILED;
593 return CONNECTION_ERROR_NONE;
596 EXPORT_API int connection_get_profile_iterator(connection_h connection,
597 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
599 if (!(__connection_check_handle_validity(connection)) ||
600 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
601 type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
602 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
603 return CONNECTION_ERROR_INVALID_PARAMETER;
606 return _connection_libnet_get_profile_iterator(type, profile_iterator);
609 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
610 connection_profile_h* profile)
612 return _connection_libnet_get_iterator_next(profile_iterator, profile);
615 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
617 return _connection_libnet_iterator_has_next(profile_iterator);
620 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
622 return _connection_libnet_destroy_iterator(profile_iterator);
625 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
627 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
628 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
629 return CONNECTION_ERROR_INVALID_PARAMETER;
632 return _connection_libnet_get_current_profile(profile);
635 EXPORT_API int connection_get_default_cellular_service_profile(connection_h connection,
636 connection_cellular_service_type_e type, connection_profile_h* profile)
638 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
639 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
640 return CONNECTION_ERROR_INVALID_PARAMETER;
643 return _connection_libnet_get_cellular_service_profile(type, profile);
646 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
647 connection_cellular_service_type_e type, connection_profile_h profile)
649 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
650 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
651 return CONNECTION_ERROR_INVALID_PARAMETER;
654 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
657 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
658 connection_cellular_service_type_e type, connection_profile_h profile,
659 connection_set_default_cb callback, void* user_data)
661 if (!(__connection_check_handle_validity(connection)) ||
662 profile == NULL || callback == NULL) {
663 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
664 return CONNECTION_ERROR_INVALID_PARAMETER;
667 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
670 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
671 connection_opened_cb callback, void* user_data)
673 if (!(__connection_check_handle_validity(connection)) ||
674 profile == NULL || callback == NULL) {
675 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
676 return CONNECTION_ERROR_INVALID_PARAMETER;
679 return _connection_libnet_open_profile(profile, callback, user_data);
682 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
683 connection_closed_cb callback, void* user_data)
685 if (!(__connection_check_handle_validity(connection)) ||
686 profile == NULL || callback == NULL) {
687 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
688 return CONNECTION_ERROR_INVALID_PARAMETER;
691 return _connection_libnet_close_profile(profile, callback, user_data);
694 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
696 if (!(__connection_check_handle_validity(connection)) ||
697 interface_name == NULL || host_address == NULL) {
698 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
699 return CONNECTION_ERROR_INVALID_PARAMETER;
702 return _connection_libnet_add_route(interface_name, host_address);
706 /* Connection Statistics module ******************************************************************/
708 static int __get_statistic(connection_type_e connection_type,
709 connection_statistics_type_e statistics_type, long long* llsize)
712 unsigned long long ull_size;
716 if (llsize == NULL) {
717 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
718 return CONNECTION_ERROR_INVALID_PARAMETER;
721 if (connection_type == CONNECTION_TYPE_CELLULAR) {
722 switch (statistics_type) {
723 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
724 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT;
726 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
727 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV;
729 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
730 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT;
732 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
733 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV;
736 return CONNECTION_ERROR_INVALID_PARAMETER;
739 if (vconf_get_int(key, &size)) {
740 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size);
742 return CONNECTION_ERROR_OPERATION_FAILED;
745 CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size);
746 *llsize = (long long)size;
747 } else if (connection_type == CONNECTION_TYPE_WIFI) {
748 switch (statistics_type) {
749 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
750 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
752 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
753 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
755 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
756 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
758 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
759 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
762 return CONNECTION_ERROR_INVALID_PARAMETER;
765 if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
766 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
768 return CONNECTION_ERROR_OPERATION_FAILED;
771 CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size);
772 *llsize = (long long)ull_size;
774 return CONNECTION_ERROR_INVALID_PARAMETER;
776 return CONNECTION_ERROR_NONE;
779 static int __reset_statistic(connection_type_e connection_type,
780 connection_statistics_type_e statistics_type)
786 if (connection_type == CONNECTION_TYPE_CELLULAR)
787 conn_type = NET_DEVICE_CELLULAR;
788 else if (connection_type == CONNECTION_TYPE_WIFI)
789 conn_type = NET_DEVICE_WIFI;
791 return CONNECTION_ERROR_INVALID_PARAMETER;
793 switch (statistics_type) {
794 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
795 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
797 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
798 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
800 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
801 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
803 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
804 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
807 return CONNECTION_ERROR_INVALID_PARAMETER;
810 rv = _connection_libnet_set_statistics(conn_type, stat_type);
811 if(rv != CONNECTION_ERROR_NONE)
815 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n");
817 return CONNECTION_ERROR_NONE;
820 EXPORT_API int connection_get_statistics(connection_type_e connection_type,
821 connection_statistics_type_e statistics_type, long long* size)
823 return __get_statistic(connection_type, statistics_type, size);
826 EXPORT_API int connection_reset_statistics(connection_type_e connection_type,
827 connection_statistics_type_e statistics_type)
829 return __reset_statistic(connection_type, statistics_type);