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 = g_try_malloc0(sizeof(connection_handle_s));
261 if (*connection != NULL) {
262 CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection);
264 CONNECTION_MUTEX_UNLOCK;
265 return CONNECTION_ERROR_OUT_OF_MEMORY;
268 conn_handle_list = g_slist_append(conn_handle_list, *connection);
270 CONNECTION_MUTEX_UNLOCK;
271 return CONNECTION_ERROR_NONE;
274 EXPORT_API int connection_destroy(connection_h connection)
276 CONNECTION_MUTEX_LOCK;
278 if (connection == NULL || !(__connection_check_handle_validity(connection))) {
279 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
280 CONNECTION_MUTEX_UNLOCK;
281 return CONNECTION_ERROR_INVALID_PARAMETER;
284 CONNECTION_LOG(CONNECTION_INFO, "Destroy Handle : %p\n", connection);
286 __connection_set_type_changed_callback(connection, NULL, NULL);
287 __connection_set_ip_changed_callback(connection, NULL, NULL);
288 __connection_set_proxy_changed_callback(connection, NULL, NULL);
290 conn_handle_list = g_slist_remove(conn_handle_list, connection);
294 if (__connection_get_handle_count() == 0)
295 _connection_libnet_deinit();
297 CONNECTION_MUTEX_UNLOCK;
298 return CONNECTION_ERROR_NONE;
301 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
305 if (type == NULL || !(__connection_check_handle_validity(connection))) {
306 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
307 return CONNECTION_ERROR_INVALID_PARAMETER;
310 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) {
311 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
312 return CONNECTION_ERROR_OPERATION_FAILED;
315 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n", status);
317 *type = __connection_convert_net_state(status);
319 return CONNECTION_ERROR_NONE;
322 EXPORT_API int connection_get_ip_address(connection_h connection,
323 connection_address_family_e address_family, char** ip_address)
325 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
326 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
327 return CONNECTION_ERROR_INVALID_PARAMETER;
330 switch (address_family) {
331 case CONNECTION_ADDRESS_FAMILY_IPV4:
332 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
334 case CONNECTION_ADDRESS_FAMILY_IPV6:
335 CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
336 return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
339 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
340 return CONNECTION_ERROR_INVALID_PARAMETER;
343 if (*ip_address == NULL) {
344 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
345 return CONNECTION_ERROR_OPERATION_FAILED;
348 CONNECTION_LOG(CONNECTION_INFO, "IP Address %s\n", *ip_address);
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 CONNECTION_LOG(CONNECTION_INFO, "Proxy Address %s\n", *proxy);
381 return CONNECTION_ERROR_NONE;
384 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
387 int cellular_state = 0;
389 if (state == NULL || !(__connection_check_handle_validity(connection))) {
390 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
391 return CONNECTION_ERROR_INVALID_PARAMETER;
394 if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) {
395 CONNECTION_LOG(CONNECTION_INFO, "Cellular = %d\n", status);
396 *state = __connection_convert_cellular_state(status);
398 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
399 if (vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state)) {
400 CONNECTION_LOG(CONNECTION_ERROR,
401 "vconf_get_int Failed = %d\n", cellular_state);
402 return CONNECTION_ERROR_OPERATION_FAILED;
406 CONNECTION_LOG(CONNECTION_INFO, "Connection state = %d\n", cellular_state);
408 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
409 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
410 cellular_state == VCONFKEY_DNET_TRANSFER)
411 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
413 return CONNECTION_ERROR_NONE;
415 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
416 return CONNECTION_ERROR_OPERATION_FAILED;
420 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 if (_connection_libnet_get_wifi_state(state) == false) {
428 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get wifi state\n");
429 return CONNECTION_ERROR_OPERATION_FAILED;
432 CONNECTION_LOG(CONNECTION_INFO, "WiFi state = %d\n", *state);
434 return CONNECTION_ERROR_NONE;
437 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
439 if (state == NULL || !(__connection_check_handle_validity(connection))) {
440 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
441 return CONNECTION_ERROR_INVALID_PARAMETER;
444 if (_connection_libnet_get_ethernet_state(state) == false)
445 return CONNECTION_ERROR_OPERATION_FAILED;
447 return CONNECTION_ERROR_NONE;
450 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
452 if (state == NULL || !(__connection_check_handle_validity(connection))) {
453 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
454 return CONNECTION_ERROR_INVALID_PARAMETER;
457 if (_connection_libnet_get_bluetooth_state(state) == false)
458 return CONNECTION_ERROR_OPERATION_FAILED;
460 return CONNECTION_ERROR_NONE;
463 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
464 connection_type_changed_cb callback, void* user_data)
466 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
467 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
468 return CONNECTION_ERROR_INVALID_PARAMETER;
471 return __connection_set_type_changed_callback(connection, callback, user_data);
474 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
476 if (!(__connection_check_handle_validity(connection))) {
477 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
478 return CONNECTION_ERROR_INVALID_PARAMETER;
481 return __connection_set_type_changed_callback(connection, NULL, NULL);
484 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
485 connection_address_changed_cb callback, void* user_data)
487 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
488 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
489 return CONNECTION_ERROR_INVALID_PARAMETER;
492 return __connection_set_ip_changed_callback(connection, callback, user_data);
495 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
497 if (!(__connection_check_handle_validity(connection))) {
498 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
499 return CONNECTION_ERROR_INVALID_PARAMETER;
502 return __connection_set_ip_changed_callback(connection, NULL, NULL);
505 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
506 connection_address_changed_cb callback, void* user_data)
508 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
509 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
510 return CONNECTION_ERROR_INVALID_PARAMETER;
513 return __connection_set_proxy_changed_callback(connection, callback, user_data);
516 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
518 if (!(__connection_check_handle_validity(connection))) {
519 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
520 return CONNECTION_ERROR_INVALID_PARAMETER;
523 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
526 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
528 if (!(__connection_check_handle_validity(connection)) ||
529 !(_connection_libnet_check_profile_validity(profile))) {
530 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
531 return CONNECTION_ERROR_INVALID_PARAMETER;
536 net_profile_info_t *profile_info = profile;
538 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
539 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
540 return CONNECTION_ERROR_INVALID_PARAMETER;
543 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
544 if (rv != NET_ERR_NONE) {
545 CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
546 return CONNECTION_ERROR_OPERATION_FAILED;
549 return CONNECTION_ERROR_NONE;
552 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
554 if (!(__connection_check_handle_validity(connection)) ||
555 !(_connection_libnet_check_profile_validity(profile))) {
556 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
557 return CONNECTION_ERROR_INVALID_PARAMETER;
561 net_profile_info_t *profile_info = profile;
563 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
564 profile_info->profile_type != NET_DEVICE_WIFI) {
565 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
566 return CONNECTION_ERROR_INVALID_PARAMETER;
569 rv = net_delete_profile(profile_info->ProfileName);
570 if (rv != NET_ERR_NONE) {
571 CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
572 return CONNECTION_ERROR_OPERATION_FAILED;
575 return CONNECTION_ERROR_NONE;
578 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
580 if (!(__connection_check_handle_validity(connection)) ||
581 !(_connection_libnet_check_profile_validity(profile))) {
582 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
583 return CONNECTION_ERROR_INVALID_PARAMETER;
587 net_profile_info_t *profile_info = profile;
589 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
590 if (rv != NET_ERR_NONE) {
591 CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
592 return CONNECTION_ERROR_OPERATION_FAILED;
595 return CONNECTION_ERROR_NONE;
598 EXPORT_API int connection_get_profile_iterator(connection_h connection,
599 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
601 if (!(__connection_check_handle_validity(connection)) ||
602 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
603 type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
604 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
605 return CONNECTION_ERROR_INVALID_PARAMETER;
608 return _connection_libnet_get_profile_iterator(type, profile_iterator);
611 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
612 connection_profile_h* profile)
614 return _connection_libnet_get_iterator_next(profile_iterator, profile);
617 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
619 return _connection_libnet_iterator_has_next(profile_iterator);
622 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
624 return _connection_libnet_destroy_iterator(profile_iterator);
627 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
629 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
630 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
631 return CONNECTION_ERROR_INVALID_PARAMETER;
634 return _connection_libnet_get_current_profile(profile);
637 EXPORT_API int connection_get_default_cellular_service_profile(connection_h connection,
638 connection_cellular_service_type_e type, 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_cellular_service_profile(type, profile);
648 EXPORT_API int connection_set_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_set_cellular_service_profile_sync(type, profile);
659 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
660 connection_cellular_service_type_e type, connection_profile_h profile,
661 connection_set_default_cb callback, void* user_data)
663 if (!(__connection_check_handle_validity(connection)) ||
664 profile == NULL || callback == NULL) {
665 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
666 return CONNECTION_ERROR_INVALID_PARAMETER;
669 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
672 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
673 connection_opened_cb callback, void* user_data)
675 if (!(__connection_check_handle_validity(connection)) ||
676 profile == NULL || callback == NULL) {
677 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
678 return CONNECTION_ERROR_INVALID_PARAMETER;
681 return _connection_libnet_open_profile(profile, callback, user_data);
684 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
685 connection_closed_cb callback, void* user_data)
687 if (!(__connection_check_handle_validity(connection)) ||
688 profile == NULL || callback == NULL) {
689 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
690 return CONNECTION_ERROR_INVALID_PARAMETER;
693 return _connection_libnet_close_profile(profile, callback, user_data);
696 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
698 if (!(__connection_check_handle_validity(connection)) ||
699 interface_name == NULL || host_address == NULL) {
700 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
701 return CONNECTION_ERROR_INVALID_PARAMETER;
704 return _connection_libnet_add_route(interface_name, host_address);
708 /* Connection Statistics module ******************************************************************/
710 static int __get_statistic(connection_type_e connection_type,
711 connection_statistics_type_e statistics_type, long long* llsize)
714 unsigned long long ull_size;
718 if (llsize == NULL) {
719 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
720 return CONNECTION_ERROR_INVALID_PARAMETER;
723 if (connection_type == CONNECTION_TYPE_CELLULAR) {
724 switch (statistics_type) {
725 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
726 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT;
728 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
729 key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV;
731 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
732 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT;
734 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
735 key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV;
738 return CONNECTION_ERROR_INVALID_PARAMETER;
741 if (vconf_get_int(key, &size)) {
742 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size);
744 return CONNECTION_ERROR_OPERATION_FAILED;
747 CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size);
748 *llsize = (long long)size;
749 } else if (connection_type == CONNECTION_TYPE_WIFI) {
750 switch (statistics_type) {
751 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
752 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
754 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
755 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
757 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
758 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
760 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
761 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
764 return CONNECTION_ERROR_INVALID_PARAMETER;
767 if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
768 CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
770 return CONNECTION_ERROR_OPERATION_FAILED;
773 CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size);
774 *llsize = (long long)ull_size;
776 return CONNECTION_ERROR_INVALID_PARAMETER;
778 return CONNECTION_ERROR_NONE;
781 static int __reset_statistic(connection_type_e connection_type,
782 connection_statistics_type_e statistics_type)
788 if (connection_type == CONNECTION_TYPE_CELLULAR)
789 conn_type = NET_DEVICE_CELLULAR;
790 else if (connection_type == CONNECTION_TYPE_WIFI)
791 conn_type = NET_DEVICE_WIFI;
793 return CONNECTION_ERROR_INVALID_PARAMETER;
795 switch (statistics_type) {
796 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
797 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
799 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
800 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
802 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
803 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
805 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
806 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
809 return CONNECTION_ERROR_INVALID_PARAMETER;
812 rv = _connection_libnet_set_statistics(conn_type, stat_type);
813 if(rv != CONNECTION_ERROR_NONE)
817 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n");
819 return CONNECTION_ERROR_NONE;
822 EXPORT_API int connection_get_statistics(connection_type_e connection_type,
823 connection_statistics_type_e statistics_type, long long* size)
825 return __get_statistic(connection_type, statistics_type, size);
828 EXPORT_API int connection_reset_statistics(connection_type_e connection_type,
829 connection_statistics_type_e statistics_type)
831 return __reset_statistic(connection_type, statistics_type);