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>
22 #include "net_connection_private.h"
24 static __thread GSList *conn_handle_list = NULL;
26 static int __connection_convert_net_state(int status)
29 case VCONFKEY_NETWORK_CELLULAR:
30 return CONNECTION_TYPE_CELLULAR;
31 case VCONFKEY_NETWORK_WIFI:
32 return CONNECTION_TYPE_WIFI;
33 case VCONFKEY_NETWORK_ETHERNET:
34 return CONNECTION_TYPE_ETHERNET;
35 case VCONFKEY_NETWORK_BLUETOOTH:
36 return CONNECTION_TYPE_BT;
37 case VCONFKEY_NETWORK_DEFAULT_PROXY:
38 return CONNECTION_TYPE_PROXY;
40 return CONNECTION_TYPE_DISCONNECTED;
44 static int __connection_convert_cellular_state(int status)
47 case VCONFKEY_NETWORK_CELLULAR_ON:
48 return CONNECTION_CELLULAR_STATE_AVAILABLE;
49 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
50 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
51 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
52 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
53 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
54 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
56 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
60 static bool __connection_check_handle_validity(connection_h connection)
64 if (connection == NULL)
67 if (g_slist_find(conn_handle_list, connection) != NULL)
73 static connection_type_changed_cb
74 __connection_get_type_changed_callback(connection_handle_s *local_handle)
76 return local_handle->type_changed_callback;
79 static void *__connection_get_type_changed_userdata(
80 connection_handle_s *local_handle)
82 return local_handle->type_changed_user_data;
85 static gboolean __connection_cb_type_changed_cb_idle(gpointer user_data)
89 connection_type_changed_cb callback;
90 connection_handle_s *local_handle = (connection_handle_s *)user_data;
92 if (__connection_check_handle_validity((connection_h)local_handle) != true)
95 if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status) != 0)
98 state = __connection_convert_net_state(status);
100 callback = __connection_get_type_changed_callback(local_handle);
101 data = __connection_get_type_changed_userdata(local_handle);
103 callback(state, data);
108 static void __connection_cb_type_change_cb(keynode_t *node, void *user_data)
113 if (_connection_is_created() != true) {
114 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
115 "If multi-threaded, thread integrity be broken.");
119 for (list = conn_handle_list; list; list = list->next) {
120 handle = (connection_h)list->data;
121 _connection_callback_add(__connection_cb_type_changed_cb_idle, (gpointer)handle);
125 static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state)
127 CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication");
131 for (list = conn_handle_list; list; list = list->next) {
132 connection_handle_s *local_handle = (connection_handle_s *)list->data;
133 if (local_handle->ethernet_cable_state_changed_callback)
134 local_handle->ethernet_cable_state_changed_callback(state,
135 local_handle->ethernet_cable_state_changed_user_data);
139 static int __connection_get_ethernet_cable_state_changed_callback_count(void)
144 for (list = conn_handle_list; list; list = list->next) {
145 connection_handle_s *local_handle = (connection_handle_s *)list->data;
146 if (local_handle->ethernet_cable_state_changed_callback) count++;
152 static int __connection_set_type_changed_callback(connection_h connection,
153 void *callback, void *user_data)
155 static __thread gint refcount = 0;
156 connection_handle_s *local_handle;
158 local_handle = (connection_handle_s *)connection;
162 vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS,
163 __connection_cb_type_change_cb, NULL);
166 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
169 __connection_get_type_changed_callback(local_handle) != NULL) {
170 if (--refcount == 0) {
171 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
172 __connection_cb_type_change_cb) < 0) {
173 CONNECTION_LOG(CONNECTION_ERROR,
174 "Error to de-register vconf callback(%d)", refcount);
176 CONNECTION_LOG(CONNECTION_INFO,
177 "Successfully de-registered(%d)", refcount);
183 local_handle->type_changed_user_data = user_data;
184 local_handle->type_changed_callback = callback;
186 return CONNECTION_ERROR_NONE;
189 static connection_address_changed_cb
190 __connection_get_ip_changed_callback(connection_handle_s *local_handle)
192 return local_handle->ip_changed_callback;
195 static void *__connection_get_ip_changed_userdata(
196 connection_handle_s *local_handle)
198 return local_handle->ip_changed_user_data;
201 static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
205 connection_address_changed_cb callback;
206 connection_handle_s *local_handle = (connection_handle_s *)user_data;
208 if (__connection_check_handle_validity((connection_h)local_handle) != true)
211 ip_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
213 callback = __connection_get_ip_changed_callback(local_handle);
214 data = __connection_get_ip_changed_userdata(local_handle);
215 /* TODO: IPv6 should be supported */
217 callback(ip_addr, NULL, data);
222 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
227 if (_connection_is_created() != true) {
228 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
229 "If multi-threaded, thread integrity be broken.");
233 for (list = conn_handle_list; list; list = list->next) {
234 handle = (connection_h)list->data;
235 _connection_callback_add(__connection_cb_ip_changed_cb_idle, (gpointer)handle);
239 static int __connection_set_ip_changed_callback(connection_h connection,
240 void *callback, void *user_data)
242 static __thread gint refcount = 0;
243 connection_handle_s *local_handle;
245 local_handle = (connection_handle_s *)connection;
249 vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
250 __connection_cb_ip_change_cb, NULL);
253 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
256 __connection_get_ip_changed_callback(local_handle) != NULL) {
257 if (--refcount == 0) {
258 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
259 __connection_cb_ip_change_cb) < 0) {
260 CONNECTION_LOG(CONNECTION_ERROR,
261 "Error to de-register vconf callback(%d)", refcount);
263 CONNECTION_LOG(CONNECTION_INFO,
264 "Successfully de-registered(%d)", refcount);
270 local_handle->ip_changed_user_data = user_data;
271 local_handle->ip_changed_callback = callback;
273 return CONNECTION_ERROR_NONE;
276 static connection_address_changed_cb
277 __connection_get_proxy_changed_callback(connection_handle_s *local_handle)
279 return local_handle->proxy_changed_callback;
282 static void *__connection_get_proxy_changed_userdata(
283 connection_handle_s *local_handle)
285 return local_handle->proxy_changed_user_data;
288 static gboolean __connection_cb_proxy_changed_cb_idle(gpointer user_data)
292 connection_address_changed_cb callback;
293 connection_handle_s *local_handle = (connection_handle_s *)user_data;
295 if (__connection_check_handle_validity((connection_h)local_handle) != true)
298 proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
300 callback = __connection_get_proxy_changed_callback(local_handle);
301 data = __connection_get_proxy_changed_userdata(local_handle);
302 /* TODO: IPv6 should be supported */
304 callback(proxy, NULL, data);
309 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
314 if (_connection_is_created() != true) {
315 CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
316 "If multi-threaded, thread integrity be broken.");
320 for (list = conn_handle_list; list; list = list->next) {
321 handle = (connection_h)list->data;
322 _connection_callback_add(__connection_cb_proxy_changed_cb_idle, (gpointer)handle);
326 static int __connection_set_proxy_changed_callback(connection_h connection,
327 void *callback, void *user_data)
329 static __thread gint refcount = 0;
330 connection_handle_s *local_handle;
332 local_handle = (connection_handle_s *)connection;
336 vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
337 __connection_cb_proxy_change_cb, NULL);
340 CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
343 __connection_get_proxy_changed_callback(local_handle) != NULL) {
344 if (--refcount == 0) {
345 if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
346 __connection_cb_proxy_change_cb) < 0) {
347 CONNECTION_LOG(CONNECTION_ERROR,
348 "Error to de-register vconf callback(%d)", refcount);
350 CONNECTION_LOG(CONNECTION_INFO,
351 "Successfully de-registered(%d)", refcount);
357 local_handle->proxy_changed_user_data = user_data;
358 local_handle->proxy_changed_callback = callback;
360 return CONNECTION_ERROR_NONE;
363 static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection,
364 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
366 connection_handle_s *local_handle = (connection_handle_s *)connection;
369 if (__connection_get_ethernet_cable_state_changed_callback_count() == 0)
370 _connection_libnet_set_ethernet_cable_state_changed_cb(
371 __connection_cb_ethernet_cable_state_changed_cb);
374 if (__connection_get_ethernet_cable_state_changed_callback_count() == 1)
375 _connection_libnet_set_ethernet_cable_state_changed_cb(NULL);
378 local_handle->ethernet_cable_state_changed_callback = callback;
379 local_handle->ethernet_cable_state_changed_user_data = user_data;
380 return CONNECTION_ERROR_NONE;
383 static int __connection_get_handle_count(void)
385 return ((int)g_slist_length(conn_handle_list));
388 /* Connection Manager ********************************************************/
389 EXPORT_API int connection_create(connection_h *connection)
391 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
393 if (connection == NULL || __connection_check_handle_validity(*connection)) {
394 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
395 return CONNECTION_ERROR_INVALID_PARAMETER;
398 int rv = _connection_libnet_init();
399 if (rv == NET_ERR_ACCESS_DENIED) {
400 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
401 return CONNECTION_ERROR_PERMISSION_DENIED;
403 else if (rv != NET_ERR_NONE) {
404 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv);
405 return CONNECTION_ERROR_OPERATION_FAILED;
408 *connection = g_try_malloc0(sizeof(connection_handle_s));
409 if (*connection != NULL)
410 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
412 return CONNECTION_ERROR_OUT_OF_MEMORY;
414 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
416 return CONNECTION_ERROR_NONE;
419 EXPORT_API int connection_destroy(connection_h connection)
421 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
423 if (!(__connection_check_handle_validity(connection))) {
424 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
425 return CONNECTION_ERROR_INVALID_PARAMETER;
428 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
430 __connection_set_type_changed_callback(connection, NULL, NULL);
431 __connection_set_ip_changed_callback(connection, NULL, NULL);
432 __connection_set_proxy_changed_callback(connection, NULL, NULL);
433 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
435 conn_handle_list = g_slist_remove(conn_handle_list, connection);
440 if (__connection_get_handle_count() == 0) {
441 _connection_libnet_deinit();
442 _connection_callback_cleanup();
445 return CONNECTION_ERROR_NONE;
448 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
453 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
455 if (type == NULL || !(__connection_check_handle_validity(connection))) {
456 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
457 return CONNECTION_ERROR_INVALID_PARAMETER;
460 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
461 if (rv != VCONF_OK) {
462 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status);
463 return CONNECTION_ERROR_OPERATION_FAILED;
466 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
468 *type = __connection_convert_net_state(status);
470 return CONNECTION_ERROR_NONE;
473 EXPORT_API int connection_get_ip_address(connection_h connection,
474 connection_address_family_e address_family, char** ip_address)
476 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
478 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
479 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
480 return CONNECTION_ERROR_INVALID_PARAMETER;
483 switch (address_family) {
484 case CONNECTION_ADDRESS_FAMILY_IPV4:
485 case CONNECTION_ADDRESS_FAMILY_IPV6:
486 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
489 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
490 return CONNECTION_ERROR_INVALID_PARAMETER;
493 if (*ip_address == NULL) {
494 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed");
495 return CONNECTION_ERROR_OPERATION_FAILED;
498 return CONNECTION_ERROR_NONE;
501 EXPORT_API int connection_get_proxy(connection_h connection,
502 connection_address_family_e address_family, char** proxy)
504 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
506 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
507 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
508 return CONNECTION_ERROR_INVALID_PARAMETER;
511 switch (address_family) {
512 case CONNECTION_ADDRESS_FAMILY_IPV4:
513 case CONNECTION_ADDRESS_FAMILY_IPV6:
514 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
517 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
518 return CONNECTION_ERROR_INVALID_PARAMETER;
521 if (*proxy == NULL) {
522 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed");
523 return CONNECTION_ERROR_OPERATION_FAILED;
526 return CONNECTION_ERROR_NONE;
529 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
532 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
534 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
536 if(type == CONNECTION_TYPE_WIFI)
537 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
538 else if(type == CONNECTION_TYPE_ETHERNET)
539 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
541 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
542 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
543 return CONNECTION_ERROR_INVALID_PARAMETER;
547 case CONNECTION_TYPE_WIFI:
548 fp = fopen(WIFI_MAC_INFO_FILE, "r");
550 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE);
551 return CONNECTION_ERROR_OUT_OF_MEMORY;
554 if (fgets(buf, sizeof(buf), fp) == NULL) {
555 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE);
557 return CONNECTION_ERROR_OPERATION_FAILED;
560 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
562 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
563 if (*mac_addr == NULL) {
564 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
566 return CONNECTION_ERROR_OUT_OF_MEMORY;
568 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
571 case CONNECTION_TYPE_ETHERNET:
572 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
574 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
575 return CONNECTION_ERROR_OUT_OF_MEMORY;
578 if (fgets(buf, sizeof(buf), fp) == NULL) {
579 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
581 return CONNECTION_ERROR_OPERATION_FAILED;
584 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
586 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
587 if (*mac_addr == NULL) {
588 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
590 return CONNECTION_ERROR_OUT_OF_MEMORY;
593 g_strlcpy(*mac_addr, buf,CONNECTION_MAC_INFO_LENGTH + 1);
598 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
599 return CONNECTION_ERROR_INVALID_PARAMETER;
602 /* Checking Invalid MAC Address */
603 if((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
604 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
605 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr);
606 return CONNECTION_ERROR_INVALID_OPERATION;
609 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
611 return CONNECTION_ERROR_NONE;
614 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
618 int cellular_state = 0;
619 #if defined TIZEN_DUALSIM_ENABLE
623 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
625 if (state == NULL || !(__connection_check_handle_validity(connection))) {
626 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
627 return CONNECTION_ERROR_INVALID_PARAMETER;
630 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
631 if (rv != VCONF_OK) {
632 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
633 return CONNECTION_ERROR_OPERATION_FAILED;
636 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
637 *state = __connection_convert_cellular_state(status);
639 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
640 #if defined TIZEN_DUALSIM_ENABLE
641 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
642 if (rv != VCONF_OK) {
643 CONNECTION_LOG(CONNECTION_ERROR,
644 "Failed to get default subscriber id", sim_id);
645 return CONNECTION_ERROR_OPERATION_FAILED;
649 case CONNECTION_CELLULAR_SUBSCRIBER_1:
651 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
652 #if defined TIZEN_DUALSIM_ENABLE
655 case CONNECTION_CELLULAR_SUBSCRIBER_2:
656 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
660 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
661 return CONNECTION_ERROR_OPERATION_FAILED;
664 if (rv != VCONF_OK) {
665 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
666 return CONNECTION_ERROR_OPERATION_FAILED;
670 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
672 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
673 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
674 cellular_state == VCONFKEY_DNET_TRANSFER)
675 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
677 return CONNECTION_ERROR_NONE;
680 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
682 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
684 if (state == NULL || !(__connection_check_handle_validity(connection))) {
685 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
686 return CONNECTION_ERROR_INVALID_PARAMETER;
689 int rv = _connection_libnet_get_wifi_state(state);
690 if (rv != CONNECTION_ERROR_NONE) {
691 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv);
695 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
697 return CONNECTION_ERROR_NONE;
700 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
702 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
704 if (state == NULL || !(__connection_check_handle_validity(connection))) {
705 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
706 return CONNECTION_ERROR_INVALID_PARAMETER;
709 return _connection_libnet_get_ethernet_state(state);
712 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
714 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
716 if (state == NULL || !(__connection_check_handle_validity(connection))) {
717 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
718 return CONNECTION_ERROR_INVALID_PARAMETER;
721 return _connection_libnet_get_ethernet_cable_state(state);
724 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
725 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
727 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
729 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
730 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
731 return CONNECTION_ERROR_INVALID_PARAMETER;
734 return __connection_set_ethernet_cable_state_changed_cb(connection,
735 callback, user_data);
738 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
740 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
742 if ( !(__connection_check_handle_validity(connection)) ) {
743 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
744 return CONNECTION_ERROR_INVALID_PARAMETER;
747 return __connection_set_ethernet_cable_state_changed_cb(connection,
751 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
753 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
755 if (state == NULL || !(__connection_check_handle_validity(connection))) {
756 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
757 return CONNECTION_ERROR_INVALID_PARAMETER;
760 return _connection_libnet_get_bluetooth_state(state);
763 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
764 connection_type_changed_cb callback, void* user_data)
766 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
768 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
769 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
770 return CONNECTION_ERROR_INVALID_PARAMETER;
773 return __connection_set_type_changed_callback(connection, callback, user_data);
776 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
778 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
780 if (!(__connection_check_handle_validity(connection))) {
781 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
782 return CONNECTION_ERROR_INVALID_PARAMETER;
785 return __connection_set_type_changed_callback(connection, NULL, NULL);
788 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
789 connection_address_changed_cb callback, void* user_data)
791 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
793 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
794 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
795 return CONNECTION_ERROR_INVALID_PARAMETER;
798 return __connection_set_ip_changed_callback(connection, callback, user_data);
801 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
803 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
805 if (!(__connection_check_handle_validity(connection))) {
806 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
807 return CONNECTION_ERROR_INVALID_PARAMETER;
810 return __connection_set_ip_changed_callback(connection, NULL, NULL);
813 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
814 connection_address_changed_cb callback, void* user_data)
816 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
818 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
819 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
820 return CONNECTION_ERROR_INVALID_PARAMETER;
823 return __connection_set_proxy_changed_callback(connection, callback, user_data);
826 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
828 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
830 if (!(__connection_check_handle_validity(connection))) {
831 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
832 return CONNECTION_ERROR_INVALID_PARAMETER;
835 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
838 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
841 net_profile_info_t *profile_info = profile;
843 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
845 if (!(__connection_check_handle_validity(connection)) ||
846 !(_connection_libnet_check_profile_validity(profile))) {
847 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
848 return CONNECTION_ERROR_INVALID_PARAMETER;
851 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
852 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
853 return CONNECTION_ERROR_INVALID_PARAMETER;
856 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
857 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
858 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL");
859 return CONNECTION_ERROR_INVALID_PARAMETER;
862 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
863 (net_profile_info_t*)profile);
864 if (rv == NET_ERR_ACCESS_DENIED) {
865 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
866 return CONNECTION_ERROR_PERMISSION_DENIED;
867 } else if (rv != NET_ERR_NONE) {
868 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
869 return CONNECTION_ERROR_OPERATION_FAILED;
872 return CONNECTION_ERROR_NONE;
875 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
878 net_profile_info_t *profile_info = profile;
880 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
882 if (!(__connection_check_handle_validity(connection)) ||
883 !(_connection_libnet_check_profile_validity(profile))) {
884 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
885 return CONNECTION_ERROR_INVALID_PARAMETER;
888 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
889 profile_info->profile_type != NET_DEVICE_WIFI) {
890 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
891 return CONNECTION_ERROR_INVALID_PARAMETER;
894 rv = net_delete_profile(profile_info->ProfileName);
895 if (rv == NET_ERR_ACCESS_DENIED) {
896 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
897 return CONNECTION_ERROR_PERMISSION_DENIED;
898 } else if (rv != NET_ERR_NONE) {
899 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
900 return CONNECTION_ERROR_OPERATION_FAILED;
903 return CONNECTION_ERROR_NONE;
906 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
909 net_profile_info_t *profile_info = profile;
911 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
913 if (!(__connection_check_handle_validity(connection)) ||
914 !(_connection_libnet_check_profile_validity(profile))) {
915 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
916 return CONNECTION_ERROR_INVALID_PARAMETER;
919 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
920 if (rv == NET_ERR_ACCESS_DENIED) {
921 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
922 return CONNECTION_ERROR_PERMISSION_DENIED;
923 } else if (rv != NET_ERR_NONE) {
924 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
925 return CONNECTION_ERROR_OPERATION_FAILED;
928 return CONNECTION_ERROR_NONE;
931 EXPORT_API int connection_get_profile_iterator(connection_h connection,
932 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
934 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
936 if (!(__connection_check_handle_validity(connection)) ||
937 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
938 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
939 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
940 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
941 return CONNECTION_ERROR_INVALID_PARAMETER;
944 return _connection_libnet_get_profile_iterator(type, profile_iterator);
947 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
948 connection_profile_h* profile)
950 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
952 return _connection_libnet_get_iterator_next(profile_iterator, profile);
955 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
957 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
959 return _connection_libnet_iterator_has_next(profile_iterator);
962 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
964 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
966 return _connection_libnet_destroy_iterator(profile_iterator);
969 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
971 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
973 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
974 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
975 return CONNECTION_ERROR_INVALID_PARAMETER;
978 return _connection_libnet_get_current_profile(profile);
981 EXPORT_API int connection_get_default_cellular_service_profile(
982 connection_h connection, connection_cellular_service_type_e type,
983 connection_profile_h *profile)
985 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
987 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
988 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
989 return CONNECTION_ERROR_INVALID_PARAMETER;
992 return _connection_libnet_get_cellular_service_profile(type, profile);
995 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
996 connection_cellular_service_type_e type, connection_profile_h profile)
998 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1000 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1001 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1002 return CONNECTION_ERROR_INVALID_PARAMETER;
1005 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1008 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1009 connection_cellular_service_type_e type, connection_profile_h profile,
1010 connection_set_default_cb callback, void* user_data)
1012 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1014 if (!(__connection_check_handle_validity(connection)) ||
1015 profile == NULL || callback == NULL) {
1016 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1017 return CONNECTION_ERROR_INVALID_PARAMETER;
1020 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1023 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1024 connection_opened_cb callback, void* user_data)
1026 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1028 if (!(__connection_check_handle_validity(connection)) ||
1029 profile == NULL || callback == NULL) {
1030 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1031 return CONNECTION_ERROR_INVALID_PARAMETER;
1034 return _connection_libnet_open_profile(profile, callback, user_data);
1037 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1038 connection_closed_cb callback, void* user_data)
1040 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1042 if (!(__connection_check_handle_validity(connection)) ||
1043 profile == NULL || callback == NULL) {
1044 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1045 return CONNECTION_ERROR_INVALID_PARAMETER;
1048 return _connection_libnet_close_profile(profile, callback, user_data);
1051 EXPORT_API int connection_reset_profile(connection_h connection,
1052 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1054 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1056 if (!(__connection_check_handle_validity(connection))) {
1057 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1058 return CONNECTION_ERROR_INVALID_PARAMETER;
1061 if(id < 0 || id > 1) {
1062 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1063 return CONNECTION_ERROR_INVALID_PARAMETER;
1066 return _connection_libnet_reset_profile(type, id, callback, user_data);
1069 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1071 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1073 if (!(__connection_check_handle_validity(connection)) ||
1074 interface_name == NULL || host_address == NULL) {
1075 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1076 return CONNECTION_ERROR_INVALID_PARAMETER;
1079 return _connection_libnet_add_route(interface_name, host_address);
1082 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1084 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1086 if (!(__connection_check_handle_validity(connection)) ||
1087 interface_name == NULL || host_address == NULL) {
1088 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1089 return CONNECTION_ERROR_INVALID_PARAMETER;
1092 return _connection_libnet_remove_route(interface_name, host_address);
1095 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1097 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1099 if (!(__connection_check_handle_validity(connection)) ||
1100 interface_name == NULL || host_address == NULL) {
1101 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1102 return CONNECTION_ERROR_INVALID_PARAMETER;
1105 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1108 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1110 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1112 if (!(__connection_check_handle_validity(connection)) ||
1113 interface_name == NULL || host_address == NULL) {
1114 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1115 return CONNECTION_ERROR_INVALID_PARAMETER;
1118 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1121 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1123 int rv = VCONF_OK, rv1 = VCONF_OK;
1124 int last_size = 0, size = 0;
1125 #if defined TIZEN_DUALSIM_ENABLE
1129 if (llsize == NULL) {
1130 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1131 return CONNECTION_ERROR_INVALID_PARAMETER;
1134 switch (statistics_type) {
1135 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1136 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1137 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1138 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1141 return CONNECTION_ERROR_INVALID_PARAMETER;
1144 #if defined TIZEN_DUALSIM_ENABLE
1145 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1146 if (rv != VCONF_OK) {
1147 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1149 return CONNECTION_ERROR_OPERATION_FAILED;
1155 switch (statistics_type) {
1156 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1157 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1159 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1160 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1162 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1163 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1164 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1166 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1167 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1168 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1171 #if defined TIZEN_DUALSIM_ENABLE
1174 switch (statistics_type) {
1175 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1176 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1178 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1179 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1181 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1182 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1183 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1185 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1186 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1187 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1193 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1194 return CONNECTION_ERROR_OPERATION_FAILED;
1198 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1199 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics");
1200 return CONNECTION_ERROR_OPERATION_FAILED;
1203 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1204 CONNECTION_LOG(CONNECTION_INFO,"%lld bytes", *llsize);
1206 return CONNECTION_ERROR_NONE;
1209 static int __get_statistic(connection_type_e connection_type,
1210 connection_statistics_type_e statistics_type, long long *llsize)
1213 unsigned long long ull_size;
1215 if (llsize == NULL) {
1216 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1217 return CONNECTION_ERROR_INVALID_PARAMETER;
1220 rv = _connection_libnet_check_get_privilege();
1221 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1223 else if (rv != CONNECTION_ERROR_NONE) {
1224 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics");
1225 return CONNECTION_ERROR_OPERATION_FAILED;
1228 if (connection_type == CONNECTION_TYPE_CELLULAR)
1229 return __get_cellular_statistic(statistics_type, llsize);
1230 else if (connection_type == CONNECTION_TYPE_WIFI) {
1231 switch (statistics_type) {
1232 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1233 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1235 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1236 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1238 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1239 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1241 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1242 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1245 return CONNECTION_ERROR_INVALID_PARAMETER;
1248 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1249 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1251 else if (rv != CONNECTION_ERROR_NONE) {
1252 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
1254 return CONNECTION_ERROR_OPERATION_FAILED;
1257 CONNECTION_LOG(CONNECTION_INFO,"%lld bytes", ull_size);
1258 *llsize = (long long)ull_size;
1260 return CONNECTION_ERROR_INVALID_PARAMETER;
1262 return CONNECTION_ERROR_NONE;
1265 static int __reset_statistic(connection_type_e connection_type,
1266 connection_statistics_type_e statistics_type)
1272 if (connection_type == CONNECTION_TYPE_CELLULAR)
1273 conn_type = NET_DEVICE_CELLULAR;
1274 else if (connection_type == CONNECTION_TYPE_WIFI)
1275 conn_type = NET_DEVICE_WIFI;
1277 return CONNECTION_ERROR_INVALID_PARAMETER;
1279 switch (statistics_type) {
1280 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1281 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1283 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1284 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1286 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1287 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1289 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1290 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1293 return CONNECTION_ERROR_INVALID_PARAMETER;
1296 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1297 if (rv != CONNECTION_ERROR_NONE)
1300 CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success");
1302 return CONNECTION_ERROR_NONE;
1305 EXPORT_API int connection_get_statistics(connection_h connection,
1306 connection_type_e connection_type,
1307 connection_statistics_type_e statistics_type, long long* size)
1309 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1311 if(connection_type == CONNECTION_TYPE_CELLULAR )
1312 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1313 else if(connection_type == CONNECTION_TYPE_WIFI)
1314 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1316 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1317 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1318 return CONNECTION_ERROR_INVALID_PARAMETER;
1321 return __get_statistic(connection_type, statistics_type, size);
1324 EXPORT_API int connection_reset_statistics(connection_h connection,
1325 connection_type_e connection_type,
1326 connection_statistics_type_e statistics_type)
1328 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1330 if(connection_type == CONNECTION_TYPE_CELLULAR )
1331 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1332 else if(connection_type == CONNECTION_TYPE_WIFI)
1333 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1335 if (!__connection_check_handle_validity(connection)) {
1336 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1337 return CONNECTION_ERROR_INVALID_PARAMETER;
1340 return __reset_statistic(connection_type, statistics_type);