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;
402 } else if (rv != NET_ERR_NONE) {
403 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv);
404 return CONNECTION_ERROR_OPERATION_FAILED;
407 *connection = g_try_malloc0(sizeof(connection_handle_s));
408 if (*connection != NULL)
409 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
411 return CONNECTION_ERROR_OUT_OF_MEMORY;
413 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
415 return CONNECTION_ERROR_NONE;
418 EXPORT_API int connection_destroy(connection_h connection)
420 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
422 if (!(__connection_check_handle_validity(connection))) {
423 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
424 return CONNECTION_ERROR_INVALID_PARAMETER;
427 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
429 __connection_set_type_changed_callback(connection, NULL, NULL);
430 __connection_set_ip_changed_callback(connection, NULL, NULL);
431 __connection_set_proxy_changed_callback(connection, NULL, NULL);
432 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
434 conn_handle_list = g_slist_remove(conn_handle_list, connection);
439 if (__connection_get_handle_count() == 0) {
440 _connection_libnet_deinit();
441 _connection_callback_cleanup();
444 return CONNECTION_ERROR_NONE;
447 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
452 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
454 if (type == NULL || !(__connection_check_handle_validity(connection))) {
455 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
456 return CONNECTION_ERROR_INVALID_PARAMETER;
459 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
460 if (rv != VCONF_OK) {
461 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status);
462 return CONNECTION_ERROR_OPERATION_FAILED;
465 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
467 *type = __connection_convert_net_state(status);
469 return CONNECTION_ERROR_NONE;
472 EXPORT_API int connection_get_ip_address(connection_h connection,
473 connection_address_family_e address_family, char** ip_address)
475 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
477 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
478 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
479 return CONNECTION_ERROR_INVALID_PARAMETER;
482 switch (address_family) {
483 case CONNECTION_ADDRESS_FAMILY_IPV4:
484 case CONNECTION_ADDRESS_FAMILY_IPV6:
485 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
488 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
489 return CONNECTION_ERROR_INVALID_PARAMETER;
492 if (*ip_address == NULL) {
493 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed");
494 return CONNECTION_ERROR_OPERATION_FAILED;
497 return CONNECTION_ERROR_NONE;
500 EXPORT_API int connection_get_proxy(connection_h connection,
501 connection_address_family_e address_family, char** proxy)
503 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
505 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
506 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
507 return CONNECTION_ERROR_INVALID_PARAMETER;
510 switch (address_family) {
511 case CONNECTION_ADDRESS_FAMILY_IPV4:
512 case CONNECTION_ADDRESS_FAMILY_IPV6:
513 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
516 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
517 return CONNECTION_ERROR_INVALID_PARAMETER;
520 if (*proxy == NULL) {
521 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed");
522 return CONNECTION_ERROR_OPERATION_FAILED;
525 return CONNECTION_ERROR_NONE;
528 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
531 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
533 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
535 if (type == CONNECTION_TYPE_WIFI)
536 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
537 else if (type == CONNECTION_TYPE_ETHERNET)
538 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
540 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
541 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
542 return CONNECTION_ERROR_INVALID_PARAMETER;
546 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 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
573 if (*mac_addr == NULL) {
574 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS);
575 return CONNECTION_ERROR_OPERATION_FAILED;
579 case CONNECTION_TYPE_ETHERNET:
580 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
582 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
583 return CONNECTION_ERROR_OUT_OF_MEMORY;
586 if (fgets(buf, sizeof(buf), fp) == NULL) {
587 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
589 return CONNECTION_ERROR_OPERATION_FAILED;
592 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
594 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
595 if (*mac_addr == NULL) {
596 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
598 return CONNECTION_ERROR_OUT_OF_MEMORY;
601 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
606 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
607 return CONNECTION_ERROR_INVALID_PARAMETER;
610 /* Checking Invalid MAC Address */
611 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
612 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
613 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr);
614 return CONNECTION_ERROR_INVALID_OPERATION;
617 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
619 return CONNECTION_ERROR_NONE;
623 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
627 int cellular_state = 0;
628 #if defined TIZEN_DUALSIM_ENABLE
632 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
634 if (state == NULL || !(__connection_check_handle_validity(connection))) {
635 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
636 return CONNECTION_ERROR_INVALID_PARAMETER;
639 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
640 if (rv != VCONF_OK) {
641 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
642 return CONNECTION_ERROR_OPERATION_FAILED;
645 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
646 *state = __connection_convert_cellular_state(status);
648 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
649 #if defined TIZEN_DUALSIM_ENABLE
650 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
651 if (rv != VCONF_OK) {
652 CONNECTION_LOG(CONNECTION_ERROR,
653 "Failed to get default subscriber id", sim_id);
654 return CONNECTION_ERROR_OPERATION_FAILED;
658 case CONNECTION_CELLULAR_SUBSCRIBER_1:
660 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
661 #if defined TIZEN_DUALSIM_ENABLE
664 case CONNECTION_CELLULAR_SUBSCRIBER_2:
665 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
669 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
670 return CONNECTION_ERROR_OPERATION_FAILED;
673 if (rv != VCONF_OK) {
674 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state");
675 return CONNECTION_ERROR_OPERATION_FAILED;
679 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
681 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
682 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
683 cellular_state == VCONFKEY_DNET_TRANSFER)
684 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
686 return CONNECTION_ERROR_NONE;
689 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
691 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
693 if (state == NULL || !(__connection_check_handle_validity(connection))) {
694 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
695 return CONNECTION_ERROR_INVALID_PARAMETER;
698 int rv = _connection_libnet_get_wifi_state(state);
699 if (rv != CONNECTION_ERROR_NONE) {
700 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv);
704 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
706 return CONNECTION_ERROR_NONE;
709 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state)
711 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
713 if (state == NULL || !(__connection_check_handle_validity(connection))) {
714 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
715 return CONNECTION_ERROR_INVALID_PARAMETER;
718 return _connection_libnet_get_ethernet_state(state);
721 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
723 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
725 if (state == NULL || !(__connection_check_handle_validity(connection))) {
726 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
727 return CONNECTION_ERROR_INVALID_PARAMETER;
730 return _connection_libnet_get_ethernet_cable_state(state);
733 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
734 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
736 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
738 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
739 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
740 return CONNECTION_ERROR_INVALID_PARAMETER;
743 return __connection_set_ethernet_cable_state_changed_cb(connection,
744 callback, user_data);
747 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
749 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
751 if (!(__connection_check_handle_validity(connection))) {
752 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
753 return CONNECTION_ERROR_INVALID_PARAMETER;
756 return __connection_set_ethernet_cable_state_changed_cb(connection,
760 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state)
762 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
764 if (state == NULL || !(__connection_check_handle_validity(connection))) {
765 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
766 return CONNECTION_ERROR_INVALID_PARAMETER;
769 return _connection_libnet_get_bluetooth_state(state);
772 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
773 connection_type_changed_cb callback, void* user_data)
775 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
777 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
778 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
779 return CONNECTION_ERROR_INVALID_PARAMETER;
782 return __connection_set_type_changed_callback(connection, callback, user_data);
785 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
787 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
789 if (!(__connection_check_handle_validity(connection))) {
790 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
791 return CONNECTION_ERROR_INVALID_PARAMETER;
794 return __connection_set_type_changed_callback(connection, NULL, NULL);
797 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
798 connection_address_changed_cb callback, void* user_data)
800 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
802 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
803 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
804 return CONNECTION_ERROR_INVALID_PARAMETER;
807 return __connection_set_ip_changed_callback(connection, callback, user_data);
810 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
812 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
814 if (!(__connection_check_handle_validity(connection))) {
815 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
816 return CONNECTION_ERROR_INVALID_PARAMETER;
819 return __connection_set_ip_changed_callback(connection, NULL, NULL);
822 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
823 connection_address_changed_cb callback, void* user_data)
825 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
827 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
828 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
829 return CONNECTION_ERROR_INVALID_PARAMETER;
832 return __connection_set_proxy_changed_callback(connection, callback, user_data);
835 EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection)
837 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
839 if (!(__connection_check_handle_validity(connection))) {
840 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
841 return CONNECTION_ERROR_INVALID_PARAMETER;
844 return __connection_set_proxy_changed_callback(connection, NULL, NULL);
847 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
850 net_profile_info_t *profile_info = profile;
852 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
854 if (!(__connection_check_handle_validity(connection)) ||
855 !(_connection_libnet_check_profile_validity(profile))) {
856 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
857 return CONNECTION_ERROR_INVALID_PARAMETER;
860 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
861 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
862 return CONNECTION_ERROR_INVALID_PARAMETER;
865 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
866 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
867 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL");
868 return CONNECTION_ERROR_INVALID_PARAMETER;
871 rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType,
872 (net_profile_info_t*)profile);
873 if (rv == NET_ERR_ACCESS_DENIED) {
874 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
875 return CONNECTION_ERROR_PERMISSION_DENIED;
876 } else if (rv != NET_ERR_NONE) {
877 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
878 return CONNECTION_ERROR_OPERATION_FAILED;
881 return CONNECTION_ERROR_NONE;
884 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
887 net_profile_info_t *profile_info = profile;
889 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
891 if (!(__connection_check_handle_validity(connection)) ||
892 !(_connection_libnet_check_profile_validity(profile))) {
893 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
894 return CONNECTION_ERROR_INVALID_PARAMETER;
897 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
898 profile_info->profile_type != NET_DEVICE_WIFI) {
899 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
900 return CONNECTION_ERROR_INVALID_PARAMETER;
903 rv = net_delete_profile(profile_info->ProfileName);
904 if (rv == NET_ERR_ACCESS_DENIED) {
905 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
906 return CONNECTION_ERROR_PERMISSION_DENIED;
907 } else if (rv != NET_ERR_NONE) {
908 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
909 return CONNECTION_ERROR_OPERATION_FAILED;
912 return CONNECTION_ERROR_NONE;
915 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
918 net_profile_info_t *profile_info = profile;
920 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
922 if (!(__connection_check_handle_validity(connection)) ||
923 !(_connection_libnet_check_profile_validity(profile))) {
924 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
925 return CONNECTION_ERROR_INVALID_PARAMETER;
928 rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
929 if (rv == NET_ERR_ACCESS_DENIED) {
930 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
931 return CONNECTION_ERROR_PERMISSION_DENIED;
932 } else if (rv != NET_ERR_NONE) {
933 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
934 return CONNECTION_ERROR_OPERATION_FAILED;
937 return CONNECTION_ERROR_NONE;
940 EXPORT_API int connection_get_profile_iterator(connection_h connection,
941 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
943 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
945 if (!(__connection_check_handle_validity(connection)) ||
946 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
947 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
948 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
949 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
950 return CONNECTION_ERROR_INVALID_PARAMETER;
953 return _connection_libnet_get_profile_iterator(type, profile_iterator);
956 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
957 connection_profile_h* profile)
959 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
961 return _connection_libnet_get_iterator_next(profile_iterator, profile);
964 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
966 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
968 return _connection_libnet_iterator_has_next(profile_iterator);
971 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
973 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
975 return _connection_libnet_destroy_iterator(profile_iterator);
978 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
980 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
982 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
983 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
984 return CONNECTION_ERROR_INVALID_PARAMETER;
987 return _connection_libnet_get_current_profile(profile);
990 EXPORT_API int connection_get_default_cellular_service_profile(
991 connection_h connection, connection_cellular_service_type_e type,
992 connection_profile_h *profile)
994 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
996 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
997 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
998 return CONNECTION_ERROR_INVALID_PARAMETER;
1001 return _connection_libnet_get_cellular_service_profile(type, profile);
1004 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1005 connection_cellular_service_type_e type, connection_profile_h profile)
1007 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1009 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1010 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1011 return CONNECTION_ERROR_INVALID_PARAMETER;
1014 return _connection_libnet_set_cellular_service_profile_sync(type, profile);
1017 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1018 connection_cellular_service_type_e type, connection_profile_h profile,
1019 connection_set_default_cb callback, void* user_data)
1021 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1023 if (!(__connection_check_handle_validity(connection)) ||
1024 profile == NULL || callback == NULL) {
1025 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1026 return CONNECTION_ERROR_INVALID_PARAMETER;
1029 return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
1032 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1033 connection_opened_cb callback, void* user_data)
1035 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1037 if (!(__connection_check_handle_validity(connection)) ||
1038 profile == NULL || callback == NULL) {
1039 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1040 return CONNECTION_ERROR_INVALID_PARAMETER;
1043 return _connection_libnet_open_profile(profile, callback, user_data);
1046 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1047 connection_closed_cb callback, void* user_data)
1049 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1051 if (!(__connection_check_handle_validity(connection)) ||
1052 profile == NULL || callback == NULL) {
1053 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1054 return CONNECTION_ERROR_INVALID_PARAMETER;
1057 return _connection_libnet_close_profile(profile, callback, user_data);
1060 EXPORT_API int connection_reset_profile(connection_h connection,
1061 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1063 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1065 if (!(__connection_check_handle_validity(connection))) {
1066 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1067 return CONNECTION_ERROR_INVALID_PARAMETER;
1070 if (id < 0 || id > 1) {
1071 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1072 return CONNECTION_ERROR_INVALID_PARAMETER;
1075 return _connection_libnet_reset_profile(type, id, callback, user_data);
1078 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1080 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1082 if (!(__connection_check_handle_validity(connection)) ||
1083 interface_name == NULL || host_address == NULL) {
1084 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1085 return CONNECTION_ERROR_INVALID_PARAMETER;
1088 return _connection_libnet_add_route(interface_name, host_address);
1091 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1093 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1095 if (!(__connection_check_handle_validity(connection)) ||
1096 interface_name == NULL || host_address == NULL) {
1097 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1098 return CONNECTION_ERROR_INVALID_PARAMETER;
1101 return _connection_libnet_remove_route(interface_name, host_address);
1104 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1106 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1108 if (!(__connection_check_handle_validity(connection)) ||
1109 interface_name == NULL || host_address == NULL) {
1110 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1111 return CONNECTION_ERROR_INVALID_PARAMETER;
1114 return _connection_libnet_add_route_ipv6(interface_name, host_address, gateway);
1117 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1119 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1121 if (!(__connection_check_handle_validity(connection)) ||
1122 interface_name == NULL || host_address == NULL) {
1123 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1124 return CONNECTION_ERROR_INVALID_PARAMETER;
1127 return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
1130 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1132 int rv = VCONF_OK, rv1 = VCONF_OK;
1133 int last_size = 0, size = 0;
1134 #if defined TIZEN_DUALSIM_ENABLE
1138 if (llsize == NULL) {
1139 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1140 return CONNECTION_ERROR_INVALID_PARAMETER;
1143 switch (statistics_type) {
1144 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1145 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1146 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1147 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1150 return CONNECTION_ERROR_INVALID_PARAMETER;
1153 #if defined TIZEN_DUALSIM_ENABLE
1154 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1155 if (rv != VCONF_OK) {
1156 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1158 return CONNECTION_ERROR_OPERATION_FAILED;
1164 switch (statistics_type) {
1165 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1166 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1168 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1169 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1171 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1172 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1173 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1175 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1176 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1177 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1180 #if defined TIZEN_DUALSIM_ENABLE
1183 switch (statistics_type) {
1184 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1185 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1187 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1188 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1190 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1191 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1192 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1194 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1195 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1196 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1202 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1203 return CONNECTION_ERROR_OPERATION_FAILED;
1207 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1208 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics");
1209 return CONNECTION_ERROR_OPERATION_FAILED;
1212 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1213 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1215 return CONNECTION_ERROR_NONE;
1218 static int __get_statistic(connection_type_e connection_type,
1219 connection_statistics_type_e statistics_type, long long *llsize)
1222 unsigned long long ull_size;
1224 if (llsize == NULL) {
1225 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1226 return CONNECTION_ERROR_INVALID_PARAMETER;
1229 rv = _connection_libnet_check_get_privilege();
1230 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1232 else if (rv != CONNECTION_ERROR_NONE) {
1233 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics");
1234 return CONNECTION_ERROR_OPERATION_FAILED;
1237 if (connection_type == CONNECTION_TYPE_CELLULAR)
1238 return __get_cellular_statistic(statistics_type, llsize);
1239 else if (connection_type == CONNECTION_TYPE_WIFI) {
1240 switch (statistics_type) {
1241 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1242 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1244 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1245 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1247 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1248 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1250 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1251 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1254 return CONNECTION_ERROR_INVALID_PARAMETER;
1257 rv = _connection_libnet_get_statistics(stat_type, &ull_size);
1258 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1260 else if (rv != CONNECTION_ERROR_NONE) {
1261 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
1263 return CONNECTION_ERROR_OPERATION_FAILED;
1266 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1267 *llsize = (long long)ull_size;
1269 return CONNECTION_ERROR_INVALID_PARAMETER;
1271 return CONNECTION_ERROR_NONE;
1274 static int __reset_statistic(connection_type_e connection_type,
1275 connection_statistics_type_e statistics_type)
1281 if (connection_type == CONNECTION_TYPE_CELLULAR)
1282 conn_type = NET_DEVICE_CELLULAR;
1283 else if (connection_type == CONNECTION_TYPE_WIFI)
1284 conn_type = NET_DEVICE_WIFI;
1286 return CONNECTION_ERROR_INVALID_PARAMETER;
1288 switch (statistics_type) {
1289 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1290 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1292 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1293 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1295 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1296 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1298 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1299 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1302 return CONNECTION_ERROR_INVALID_PARAMETER;
1305 rv = _connection_libnet_set_statistics(conn_type, stat_type);
1306 if (rv != CONNECTION_ERROR_NONE)
1309 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1311 return CONNECTION_ERROR_NONE;
1314 EXPORT_API int connection_get_statistics(connection_h connection,
1315 connection_type_e connection_type,
1316 connection_statistics_type_e statistics_type, long long* size)
1318 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1320 if (connection_type == CONNECTION_TYPE_CELLULAR)
1321 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1322 else if (connection_type == CONNECTION_TYPE_WIFI)
1323 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1325 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1326 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1327 return CONNECTION_ERROR_INVALID_PARAMETER;
1330 return __get_statistic(connection_type, statistics_type, size);
1333 EXPORT_API int connection_reset_statistics(connection_h connection,
1334 connection_type_e connection_type,
1335 connection_statistics_type_e statistics_type)
1337 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1339 if (connection_type == CONNECTION_TYPE_CELLULAR)
1340 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1341 else if (connection_type == CONNECTION_TYPE_WIFI)
1342 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1344 if (!__connection_check_handle_validity(connection)) {
1345 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1346 return CONNECTION_ERROR_INVALID_PARAMETER;
1349 return __reset_statistic(connection_type, statistics_type);