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.
21 #include <vconf/vconf.h>
22 #include <system_info.h>
24 #include "net_connection_private.h"
26 static GSList *conn_handle_list = NULL;
27 static int tv_profile = -1; // Unknown
30 static int __connection_convert_net_state(int status)
33 case VCONFKEY_NETWORK_CELLULAR:
34 return CONNECTION_TYPE_CELLULAR;
35 case VCONFKEY_NETWORK_WIFI:
36 return CONNECTION_TYPE_WIFI;
37 case VCONFKEY_NETWORK_ETHERNET:
38 return CONNECTION_TYPE_ETHERNET;
39 case VCONFKEY_NETWORK_BLUETOOTH:
40 return CONNECTION_TYPE_BT;
41 case VCONFKEY_NETWORK_DEFAULT_PROXY:
42 return CONNECTION_TYPE_NET_PROXY;
44 return CONNECTION_TYPE_DISCONNECTED;
48 static int __connection_convert_cellular_state(int status)
51 case VCONFKEY_NETWORK_CELLULAR_ON:
52 return CONNECTION_CELLULAR_STATE_AVAILABLE;
53 case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
54 return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
55 case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
56 return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
57 case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
58 return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
60 return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
64 static bool __connection_check_handle_validity(connection_h connection)
68 if (connection == NULL)
71 if (g_slist_find(conn_handle_list, connection) != NULL)
77 bool _connection_check_handle_validity(connection_h connection)
79 return __connection_check_handle_validity(connection);
82 static void __connection_set_type_changed_callback(connection_handle_s *conn_handle,
83 void *callback, void *user_data)
85 conn_handle->type_changed_user_data = user_data;
86 conn_handle->type_changed_callback = callback;
89 static void __connection_set_ip_changed_callback(connection_handle_s *conn_handle,
90 void *callback, void *user_data)
92 conn_handle->ip_changed_user_data = user_data;
93 conn_handle->ip_changed_callback = callback;
96 static void __connection_set_proxy_changed_callback(connection_handle_s *conn_handle,
97 void *callback, void *user_data)
99 conn_handle->proxy_changed_user_data = user_data;
100 conn_handle->proxy_changed_callback = callback;
103 static void __connection_set_internet_state_changed_callback(connection_handle_s *conn_handle,
104 void *callback, void *user_data)
106 conn_handle->internet_state_changed_user_data = user_data;
107 conn_handle->internet_state_changed_callback = callback;
110 static void __connection_set_ethernet_cable_state_changed_cb(connection_handle_s *conn_handle,
111 void *callback, void *user_data)
113 conn_handle->ethernet_cable_state_changed_callback = callback;
114 conn_handle->ethernet_cable_state_changed_user_data = user_data;
117 static void __connection_set_default_cellular_service_profile_callback(connection_handle_s *conn_handle,
118 void *callback, void *user_data)
120 conn_handle->set_default_callback = callback;
121 conn_handle->set_default_user_data = user_data;
124 static void __connection_open_profile_set_callback(connection_handle_s *conn_handle,
125 void *callback, void *user_data)
127 conn_handle->opened_callback = callback;
128 conn_handle->opened_user_data = user_data;
131 static void __connection_close_profile_set_callback(connection_handle_s *conn_handle,
132 void *callback, void *user_data)
134 conn_handle->closed_callback = callback;
135 conn_handle->closed_user_data = user_data;
138 static void __connection_reset_profile_set_callback(connection_handle_s *conn_handle,
139 void *callback, void *user_data)
141 conn_handle->reset_callback = callback;
142 conn_handle->reset_user_data = user_data;
146 /* Connection Manager ********************************************************/
147 EXPORT_API int connection_create(connection_h *connection)
151 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
155 if (connection == NULL || __connection_check_handle_validity(*connection)) {
156 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
157 CONN_UNLOCK; //LCOV_EXCL_LINE
158 return CONNECTION_ERROR_INVALID_PARAMETER;
161 *connection = g_try_malloc0(sizeof(connection_handle_s));
162 if (*connection != NULL) {
163 CONNECTION_LOG(CONNECTION_INFO, "New handle created[%p]", *connection);
165 CONN_UNLOCK; //LCOV_EXCL_LINE
166 return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
169 rv = _connection_libnet_init(*connection);
170 if (rv == NET_ERR_ACCESS_DENIED) {
171 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
172 CONN_UNLOCK; //LCOV_EXCL_LINE
173 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
174 } else if (rv != NET_ERR_NONE) {
175 CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
176 CONN_UNLOCK; //LCOV_EXCL_LINE
177 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
180 conn_handle_list = g_slist_prepend(conn_handle_list, *connection);
183 return CONNECTION_ERROR_NONE;
186 EXPORT_API int connection_destroy(connection_h connection)
190 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
192 if (!(__connection_check_handle_validity(connection))) {
193 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
195 return CONNECTION_ERROR_INVALID_PARAMETER;
198 CONNECTION_LOG(CONNECTION_INFO, "Destroy handle: %p", connection);
200 __connection_set_type_changed_callback(connection, NULL, NULL);
201 __connection_set_ip_changed_callback(connection, NULL, NULL);
202 __connection_set_proxy_changed_callback(connection, NULL, NULL);
203 __connection_set_internet_state_changed_callback(connection, NULL, NULL);
204 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
206 conn_handle_list = g_slist_remove(conn_handle_list, connection);
207 _connection_libnet_deinit(connection, (conn_handle_list == NULL));
213 return CONNECTION_ERROR_NONE;
217 EXPORT_API int connection_create_cs(int tid, connection_h *connection)
221 rv = connection_create(connection);
222 if (rv == CONNECTION_ERROR_NONE) {
224 _connection_set_cs_tid(tid, *connection);
231 EXPORT_API int connection_destroy_cs(int tid, connection_h connection)
236 _connection_unset_cs_tid(tid, connection);
239 rv = connection_destroy(connection);
245 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
252 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
254 if (type == NULL || !(__connection_check_handle_validity(connection))) {
255 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
257 return CONNECTION_ERROR_INVALID_PARAMETER;
260 rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
261 if (rv != VCONF_OK) {
262 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
263 CONN_UNLOCK; //LCOV_EXCL_LINE
264 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
267 CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d", status);
269 *type = __connection_convert_net_state(status);
272 return CONNECTION_ERROR_NONE;
275 EXPORT_API int connection_get_ip_address(connection_h connection,
276 connection_address_family_e address_family, char** ip_address)
280 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
282 if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
283 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
285 return CONNECTION_ERROR_INVALID_PARAMETER;
288 switch (address_family) {
289 case CONNECTION_ADDRESS_FAMILY_IPV4:
290 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
292 case CONNECTION_ADDRESS_FAMILY_IPV6:
293 *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
296 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
298 return CONNECTION_ERROR_INVALID_PARAMETER;
301 if (*ip_address == NULL) {
302 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
303 CONN_UNLOCK; //LCOV_EXCL_LINE
304 return CONNECTION_ERROR_OPERATION_FAILED;//LCOV_EXCL_LINE
308 return CONNECTION_ERROR_NONE;
311 EXPORT_API int connection_get_proxy(connection_h connection,
312 connection_address_family_e address_family, char** proxy)
316 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
318 if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
319 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
321 return CONNECTION_ERROR_INVALID_PARAMETER;
324 switch (address_family) {
325 case CONNECTION_ADDRESS_FAMILY_IPV4:
326 case CONNECTION_ADDRESS_FAMILY_IPV6:
327 *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
330 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
332 return CONNECTION_ERROR_INVALID_PARAMETER;
335 if (*proxy == NULL) {
336 CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed"); //LCOV_EXCL_LINE
337 CONN_UNLOCK; //LCOV_EXCL_LINE
338 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
342 return CONNECTION_ERROR_NONE;
345 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
348 char buf[CONNECTION_MAC_INFO_LENGTH + 1];
352 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE);
354 if (type == CONNECTION_TYPE_WIFI)
355 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
356 else if (type == CONNECTION_TYPE_ETHERNET) //LCOV_EXCL_LINE
357 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); //LCOV_EXCL_LINE
359 if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) {
360 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
362 return CONNECTION_ERROR_INVALID_PARAMETER;
366 case CONNECTION_TYPE_WIFI:
367 if (__builtin_expect(tv_profile == -1, 0)) {
369 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
370 if (*profileName == 't' || *profileName == 'T')
371 tv_profile = 1; //LCOV_EXCL_LINE
376 if (tv_profile == 1) {
378 fp = fopen(WIFI_MAC_INFO_FILE, "r");
380 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE);
382 return CONNECTION_ERROR_OUT_OF_MEMORY;
385 if (fgets(buf, sizeof(buf), fp) == NULL) {
386 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE);
389 return CONNECTION_ERROR_OPERATION_FAILED;
392 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
394 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
395 if (*mac_addr == NULL) {
396 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
399 return CONNECTION_ERROR_OUT_OF_MEMORY;
401 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
405 *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
407 if (*mac_addr == NULL) {
408 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
409 CONN_UNLOCK; //LCOV_EXCL_LINE
410 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
415 case CONNECTION_TYPE_ETHERNET:
416 fp = fopen(ETHERNET_MAC_INFO_FILE, "r");
418 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE);
420 return CONNECTION_ERROR_OUT_OF_MEMORY;
423 if (fgets(buf, sizeof(buf), fp) == NULL) {
424 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE);
427 return CONNECTION_ERROR_OPERATION_FAILED;
430 CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
432 *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
433 if (*mac_addr == NULL) {
434 CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
437 return CONNECTION_ERROR_OUT_OF_MEMORY;
440 g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
446 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
447 CONN_UNLOCK; //LCOV_EXCL_LINE
448 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
451 /* Checking Invalid MAC Address */
452 if ((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) ||
453 (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) {
454 CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); //LCOV_EXCL_LINE
455 CONN_UNLOCK; //LCOV_EXCL_LINE
456 return CONNECTION_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
459 CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr);
462 return CONNECTION_ERROR_NONE;
466 EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
470 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
472 if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
473 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
475 return CONNECTION_ERROR_INVALID_PARAMETER;
478 int rv = _connection_libnet_get_metered_state(connection, is_metered);
479 if (rv != CONNECTION_ERROR_NONE) {
480 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
481 CONN_UNLOCK; //LCOV_EXCL_LINE
482 return rv; //LCOV_EXCL_LINE
485 CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
487 return CONNECTION_ERROR_NONE;
491 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
495 int cellular_state = 0;
496 #if defined TIZEN_DUALSIM_ENABLE
502 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
504 if (state == NULL || !(__connection_check_handle_validity(connection))) {
505 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
507 return CONNECTION_ERROR_INVALID_PARAMETER;
510 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
511 if (rv != VCONF_OK) {
512 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
513 CONN_UNLOCK; //LCOV_EXCL_LINE
514 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
517 CONNECTION_LOG(CONNECTION_INFO, "Cellular: %d", status);
518 *state = __connection_convert_cellular_state(status);
520 if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
521 #if defined TIZEN_DUALSIM_ENABLE
522 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
523 if (rv != VCONF_OK) {
524 CONNECTION_LOG(CONNECTION_ERROR,
525 "Failed to get default subscriber id", sim_id);
527 return CONNECTION_ERROR_OPERATION_FAILED;
531 case CONNECTION_CELLULAR_SUBSCRIBER_1:
533 rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
534 #if defined TIZEN_DUALSIM_ENABLE
537 case CONNECTION_CELLULAR_SUBSCRIBER_2:
538 rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
542 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
544 return CONNECTION_ERROR_OPERATION_FAILED;
547 if (rv != VCONF_OK) {
548 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
549 CONN_UNLOCK; //LCOV_EXCL_LINE
550 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
554 CONNECTION_LOG(CONNECTION_INFO, "Cellular state: %d", cellular_state);
556 if (cellular_state == VCONFKEY_DNET_NORMAL_CONNECTED ||
557 cellular_state == VCONFKEY_DNET_SECURE_CONNECTED ||
558 cellular_state == VCONFKEY_DNET_TRANSFER)
559 *state = CONNECTION_CELLULAR_STATE_CONNECTED;
562 return CONNECTION_ERROR_NONE;
565 EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
569 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
571 if (state == NULL || !(__connection_check_handle_validity(connection))) {
572 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
574 return CONNECTION_ERROR_INVALID_PARAMETER;
577 int rv = _connection_libnet_get_wifi_state(connection, state);
578 if (rv != CONNECTION_ERROR_NONE) {
579 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get Wi-Fi state[%d]", rv); //LCOV_EXCL_LINE
580 CONN_UNLOCK; //LCOV_EXCL_LINE
581 return rv; //LCOV_EXCL_LINE
584 CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi state: %d", *state);
587 return CONNECTION_ERROR_NONE;
590 EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e *state)
594 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
596 if (state == NULL || !(__connection_check_handle_validity(connection))) {
597 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
599 return CONNECTION_ERROR_INVALID_PARAMETER;
602 int rv = _connection_libnet_get_ethernet_state(connection, state);
603 if (rv != CONNECTION_ERROR_NONE) {
604 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get ethernet state[%d]", rv); //LCOV_EXCL_LINE
605 CONN_UNLOCK; //LCOV_EXCL_LINE
606 return rv; //LCOV_EXCL_LINE
610 return CONNECTION_ERROR_NONE;
613 EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state)
617 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
619 if (state == NULL || !(__connection_check_handle_validity(connection))) {
620 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
622 return CONNECTION_ERROR_INVALID_PARAMETER;
625 int rv = _connection_libnet_get_ethernet_cable_state(connection, state);
626 if (rv != CONNECTION_ERROR_NONE) {
627 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get ethernet cable state[%d]", rv); //LCOV_EXCL_LINE
628 CONN_UNLOCK; //LCOV_EXCL_LINE
629 return rv; //LCOV_EXCL_LINE
633 return CONNECTION_ERROR_NONE;
636 EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
637 connection_ethernet_cable_state_chaged_cb callback, void *user_data)
639 DEPRECATED_LOG(__FUNCTION__, "connection_set_ethernet_cable_state_changed_cb");
643 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
645 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
646 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
648 return CONNECTION_ERROR_INVALID_PARAMETER;
651 DEPRECATED_LOG("connection_ethernet_cable_state_chaged_cb",
652 "connection_ethernet_cable_state_changed_cb");
654 __connection_set_ethernet_cable_state_changed_cb(connection, callback, user_data);
657 return CONNECTION_ERROR_NONE;
660 EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection)
662 DEPRECATED_LOG(__FUNCTION__, "connection_unset_ethernet_cable_state_changed_cb");
666 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
668 if (!(__connection_check_handle_validity(connection))) {
669 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
671 return CONNECTION_ERROR_INVALID_PARAMETER;
674 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
677 return CONNECTION_ERROR_NONE;
680 EXPORT_API int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
681 connection_ethernet_cable_state_changed_cb callback, void *user_data)
685 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
687 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
688 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
690 return CONNECTION_ERROR_INVALID_PARAMETER;
693 __connection_set_ethernet_cable_state_changed_cb(connection, callback, user_data);
696 return CONNECTION_ERROR_NONE;
699 EXPORT_API int connection_unset_ethernet_cable_state_changed_cb(connection_h connection)
703 CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE);
705 if (!(__connection_check_handle_validity(connection))) {
706 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
708 return CONNECTION_ERROR_INVALID_PARAMETER;
711 __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
714 return CONNECTION_ERROR_NONE;
717 EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e *state)
721 CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE);
723 if (state == NULL || !(__connection_check_handle_validity(connection))) {
724 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
726 return CONNECTION_ERROR_INVALID_PARAMETER;
729 int rv = _connection_libnet_get_bluetooth_state(connection, state);
730 if (rv != CONNECTION_ERROR_NONE) {
731 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get bluetooth state[%d]", rv); //LCOV_EXCL_LINE
732 CONN_UNLOCK; //LCOV_EXCL_LINE
733 return rv; //LCOV_EXCL_LINE
737 return CONNECTION_ERROR_NONE;
740 EXPORT_API int connection_set_type_changed_cb(connection_h connection,
741 connection_type_changed_cb callback, void* user_data)
745 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
747 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
748 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
750 return CONNECTION_ERROR_INVALID_PARAMETER;
753 __connection_set_type_changed_callback(connection, callback, user_data);
756 return CONNECTION_ERROR_NONE;
759 EXPORT_API int connection_unset_type_changed_cb(connection_h connection)
763 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
765 if (!(__connection_check_handle_validity(connection))) {
766 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
768 return CONNECTION_ERROR_INVALID_PARAMETER;
771 __connection_set_type_changed_callback(connection, NULL, NULL);
774 return CONNECTION_ERROR_NONE;
777 EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection,
778 connection_address_changed_cb callback, void* user_data)
782 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
784 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
785 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
787 return CONNECTION_ERROR_INVALID_PARAMETER;
790 __connection_set_ip_changed_callback(connection, callback, user_data);
793 return CONNECTION_ERROR_NONE;
796 EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection)
800 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
802 if (!(__connection_check_handle_validity(connection))) {
803 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
805 return CONNECTION_ERROR_INVALID_PARAMETER;
808 __connection_set_ip_changed_callback(connection, NULL, NULL);
811 return CONNECTION_ERROR_NONE;
814 EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection,
815 connection_address_changed_cb callback, void* user_data)
819 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
821 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
822 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
824 return CONNECTION_ERROR_INVALID_PARAMETER;
827 __connection_set_proxy_changed_callback(connection, callback, user_data);
830 return CONNECTION_ERROR_NONE;
833 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");
842 return CONNECTION_ERROR_INVALID_PARAMETER;
845 __connection_set_proxy_changed_callback(connection, NULL, NULL);
848 return CONNECTION_ERROR_NONE;
851 EXPORT_API int connection_set_internet_state_changed_cb(connection_h connection,
852 connection_internet_state_changed_cb callback, void *user_data)
856 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
858 if (callback == NULL || !(__connection_check_handle_validity(connection))) {
859 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
861 return CONNECTION_ERROR_INVALID_PARAMETER;
864 __connection_set_internet_state_changed_callback(connection, callback, user_data);
867 return CONNECTION_ERROR_NONE;
870 EXPORT_API int connection_unset_internet_state_changed_cb(connection_h connection)
874 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
876 if (!(__connection_check_handle_validity(connection))) {
877 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
879 return CONNECTION_ERROR_INVALID_PARAMETER;
882 __connection_set_internet_state_changed_callback(connection, NULL, NULL);
885 return CONNECTION_ERROR_NONE;
888 EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
891 connection_handle_s *conn_handle = (connection_handle_s *)connection;
892 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
896 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
898 if (!(__connection_check_handle_validity(connection)) ||
899 !(_connection_libnet_check_profile_validity(profile))) {
900 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
902 return CONNECTION_ERROR_INVALID_PARAMETER;
905 if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
906 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
907 CONN_UNLOCK; //LCOV_EXCL_LINE
908 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
911 if (profile_info->ProfileInfo.Pdp.PSModemPath[0] != '/' ||
912 strlen(profile_info->ProfileInfo.Pdp.PSModemPath) < 2) {
913 CONNECTION_LOG(CONNECTION_ERROR, "Modem object path is NULL"); //LCOV_EXCL_LINE
914 CONN_UNLOCK; //LCOV_EXCL_LINE
915 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
918 rv = net_add_profile(conn_handle->network_info_handle,
919 profile_info->ProfileInfo.Pdp.ServiceType, profile_info);
920 if (rv == NET_ERR_ACCESS_DENIED) {
921 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
922 CONN_UNLOCK; //LCOV_EXCL_LINE
923 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
924 } else if (rv != NET_ERR_NONE) {
925 CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv); //LCOV_EXCL_LINE
926 CONN_UNLOCK; //LCOV_EXCL_LINE
927 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
931 return CONNECTION_ERROR_NONE;
934 EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile)
937 connection_handle_s *conn_handle = (connection_handle_s *)connection;
938 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
942 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
944 if (!(__connection_check_handle_validity(connection)) ||
945 !(_connection_libnet_check_profile_validity(profile))) {
946 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
948 return CONNECTION_ERROR_INVALID_PARAMETER;
951 if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
952 profile_info->profile_type != NET_DEVICE_MESH &&
953 profile_info->profile_type != NET_DEVICE_WIFI) {
954 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
955 CONN_UNLOCK; //LCOV_EXCL_LINE
956 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
959 rv = net_delete_profile(conn_handle->network_info_handle, profile_info->ProfileName);
960 if (rv == NET_ERR_ACCESS_DENIED) {
961 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
962 CONN_UNLOCK; //LCOV_EXCL_LINE
963 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
964 } else if (rv != NET_ERR_NONE) {
965 CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv); //LCOV_EXCL_LINE
966 CONN_UNLOCK; //LCOV_EXCL_LINE
967 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
971 return CONNECTION_ERROR_NONE;
974 EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile)
977 connection_handle_s *conn_handle = (connection_handle_s *)connection;
978 net_profile_info_t *profile_info = (net_profile_info_t *)profile;
982 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
984 if (!(__connection_check_handle_validity(connection)) ||
985 !(_connection_libnet_check_profile_validity(profile))) {
986 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
988 return CONNECTION_ERROR_INVALID_PARAMETER;
991 rv = net_modify_profile(conn_handle->network_info_handle,
992 profile_info->ProfileName, (net_profile_info_t*)profile);
993 if (rv == NET_ERR_ACCESS_DENIED) {
994 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
995 CONN_UNLOCK; //LCOV_EXCL_LINE
996 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
997 } else if (rv != NET_ERR_NONE) {
998 CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv); //LCOV_EXCL_LINE
999 CONN_UNLOCK; //LCOV_EXCL_LINE
1000 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1004 return CONNECTION_ERROR_NONE;
1007 EXPORT_API int connection_get_profile_iterator(connection_h connection,
1008 connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator)
1012 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1014 if (!(__connection_check_handle_validity(connection)) ||
1015 (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
1016 type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
1017 type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
1018 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1020 return CONNECTION_ERROR_INVALID_PARAMETER;
1023 int rv = _connection_libnet_get_profile_iterator(connection, type, profile_iterator);
1024 if (rv != CONNECTION_ERROR_NONE) {
1025 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get profile iterator [%d]", rv); //LCOV_EXCL_LINE
1026 CONN_UNLOCK; //LCOV_EXCL_LINE
1027 return rv; //LCOV_EXCL_LINE
1031 return CONNECTION_ERROR_NONE;
1034 EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator,
1035 connection_profile_h* profile)
1039 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1041 int rv = _connection_libnet_get_iterator_next(profile_iterator, profile);
1047 EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator)
1051 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1053 int rv = _connection_libnet_iterator_has_next(profile_iterator);
1059 EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator)
1063 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1065 int rv = _connection_libnet_destroy_iterator(profile_iterator);
1071 EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile)
1075 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1077 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1078 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1080 return CONNECTION_ERROR_INVALID_PARAMETER;
1083 int rv = _connection_libnet_get_current_profile(connection, profile);
1084 if (rv != CONNECTION_ERROR_NONE) {
1085 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get current profile [%d]", rv); //LCOV_EXCL_LINE
1086 CONN_UNLOCK; //LCOV_EXCL_LINE
1087 return rv; //LCOV_EXCL_LINE
1091 return CONNECTION_ERROR_NONE;
1094 EXPORT_API int connection_get_default_cellular_service_profile(
1095 connection_h connection, connection_cellular_service_type_e type,
1096 connection_profile_h *profile)
1100 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1102 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1103 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1105 return CONNECTION_ERROR_INVALID_PARAMETER;
1108 int rv = _connection_libnet_get_cellular_service_profile(connection, type, profile);
1109 if (rv != CONNECTION_ERROR_NONE) {
1110 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get default cellular service profile [%d]", rv); //LCOV_EXCL_LINE
1111 CONN_UNLOCK; //LCOV_EXCL_LINE
1112 return rv; //LCOV_EXCL_LINE
1116 return CONNECTION_ERROR_NONE;
1119 EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection,
1120 connection_cellular_service_type_e type, connection_profile_h profile)
1124 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1126 if (!(__connection_check_handle_validity(connection)) || profile == NULL) {
1127 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1129 return CONNECTION_ERROR_INVALID_PARAMETER;
1132 int rv = _connection_libnet_set_cellular_service_profile_sync(connection, type, profile);
1133 if (rv != CONNECTION_ERROR_NONE) {
1134 CONNECTION_LOG(CONNECTION_ERROR, "Fail to set default cellular service profile [%d]", rv); //LCOV_EXCL_LINE
1135 CONN_UNLOCK; //LCOV_EXCL_LINE
1136 return rv; //LCOV_EXCL_LINE
1140 return CONNECTION_ERROR_NONE;
1143 EXPORT_API int connection_set_default_cellular_service_profile_async(connection_h connection,
1144 connection_cellular_service_type_e type, connection_profile_h profile,
1145 connection_set_default_cb callback, void* user_data)
1149 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1153 if (!(__connection_check_handle_validity(connection)) ||
1154 profile == NULL || callback == NULL) {
1155 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1157 return CONNECTION_ERROR_INVALID_PARAMETER;
1160 rv = _connection_libnet_set_cellular_service_profile_async(connection, type, profile);
1161 if (rv == NET_ERR_ACCESS_DENIED) {
1162 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1163 CONN_UNLOCK; //LCOV_EXCL_LINE
1164 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1165 } else if (rv != NET_ERR_NONE) {
1166 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set default cellular service profile[%d]", rv); //LCOV_EXCL_LINE
1167 CONN_UNLOCK; //LCOV_EXCL_LINE
1168 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1171 __connection_set_default_cellular_service_profile_callback(connection, callback, user_data);
1174 return CONNECTION_ERROR_NONE;
1177 EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile,
1178 connection_opened_cb callback, void* user_data)
1182 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1186 if (!(__connection_check_handle_validity(connection)) ||
1187 profile == NULL || callback == NULL) {
1188 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1190 return CONNECTION_ERROR_INVALID_PARAMETER;
1193 rv = _connection_libnet_open_profile(connection, profile);
1194 if (rv == NET_ERR_ACCESS_DENIED) {
1195 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1196 CONN_UNLOCK; //LCOV_EXCL_LINE
1197 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1198 } else if (rv != NET_ERR_NONE) {
1199 CONNECTION_LOG(CONNECTION_ERROR, "Failed to open profile[%d]", rv); //LCOV_EXCL_LINE
1200 CONN_UNLOCK; //LCOV_EXCL_LINE
1201 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1204 __connection_open_profile_set_callback(connection, callback, user_data);
1207 return CONNECTION_ERROR_NONE;
1210 EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile,
1211 connection_closed_cb callback, void* user_data)
1215 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1219 if (!(__connection_check_handle_validity(connection)) ||
1220 profile == NULL || callback == NULL) {
1221 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1223 return CONNECTION_ERROR_INVALID_PARAMETER;
1226 rv = _connection_libnet_close_profile(connection, profile);
1227 if (rv == NET_ERR_ACCESS_DENIED) {
1228 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1229 CONN_UNLOCK; //LCOV_EXCL_LINE
1230 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1231 } else if (rv != NET_ERR_NONE) {
1232 CONNECTION_LOG(CONNECTION_ERROR, "Failed to close profile[%d]", rv); //LCOV_EXCL_LINE
1233 CONN_UNLOCK; //LCOV_EXCL_LINE
1234 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1237 __connection_close_profile_set_callback(connection, callback, user_data);
1240 return CONNECTION_ERROR_NONE;
1243 EXPORT_API int connection_reset_profile(connection_h connection,
1244 connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
1248 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1252 if (!(__connection_check_handle_validity(connection))) {
1253 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
1255 return CONNECTION_ERROR_INVALID_PARAMETER;
1258 if (id < 0 || id > 1) {
1259 CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); //LCOV_EXCL_LINE
1260 CONN_UNLOCK; //LCOV_EXCL_LINE
1261 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1264 rv = _connection_libnet_reset_profile(connection, type, id);
1265 if (rv == NET_ERR_ACCESS_DENIED) {
1266 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
1267 CONN_UNLOCK; //LCOV_EXCL_LINE
1268 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1269 } else if (rv != NET_ERR_NONE) {
1270 CONNECTION_LOG(CONNECTION_ERROR, "Failed to reset profile[%d]", rv); //LCOV_EXCL_LINE
1271 CONN_UNLOCK; //LCOV_EXCL_LINE
1272 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1275 __connection_reset_profile_set_callback(connection, callback, user_data);
1278 return CONNECTION_ERROR_NONE;
1281 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
1285 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1287 if (!(__connection_check_handle_validity(connection)) ||
1288 interface_name == NULL || host_address == NULL) {
1289 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1291 return CONNECTION_ERROR_INVALID_PARAMETER;
1294 int rv = _connection_libnet_add_route(connection, interface_name, host_address);
1295 if (rv != CONNECTION_ERROR_NONE) {
1296 CONNECTION_LOG(CONNECTION_ERROR, "Fail to add route [%d]", rv); //LCOV_EXCL_LINE
1297 CONN_UNLOCK; //LCOV_EXCL_LINE
1298 return rv; //LCOV_EXCL_LINE
1302 return CONNECTION_ERROR_NONE;
1305 EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
1309 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1311 if (!(__connection_check_handle_validity(connection)) ||
1312 interface_name == NULL || host_address == NULL) {
1313 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1315 return CONNECTION_ERROR_INVALID_PARAMETER;
1318 int rv = _connection_libnet_remove_route(connection, interface_name, host_address);
1319 if (rv != CONNECTION_ERROR_NONE) {
1320 CONNECTION_LOG(CONNECTION_ERROR, "Fail to remove route [%d]", rv); //LCOV_EXCL_LINE
1321 CONN_UNLOCK; //LCOV_EXCL_LINE
1322 return rv; //LCOV_EXCL_LINE
1326 return CONNECTION_ERROR_NONE;
1329 EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1333 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1335 if (!(__connection_check_handle_validity(connection)) ||
1336 interface_name == NULL || host_address == NULL) {
1337 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1339 return CONNECTION_ERROR_INVALID_PARAMETER;
1342 int rv = _connection_libnet_add_route_ipv6(connection, interface_name, host_address, gateway);
1343 if (rv != CONNECTION_ERROR_NONE) {
1344 CONNECTION_LOG(CONNECTION_ERROR, "Fail to add route ipv6 [%d]", rv); //LCOV_EXCL_LINE
1345 CONN_UNLOCK; //LCOV_EXCL_LINE
1346 return rv; //LCOV_EXCL_LINE
1350 return CONNECTION_ERROR_NONE;
1353 EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway)
1357 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1359 if (!(__connection_check_handle_validity(connection)) ||
1360 interface_name == NULL || host_address == NULL) {
1361 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1363 return CONNECTION_ERROR_INVALID_PARAMETER;
1366 int rv = _connection_libnet_remove_route_ipv6(connection, interface_name, host_address, gateway);
1367 if (rv != CONNECTION_ERROR_NONE) {
1368 CONNECTION_LOG(CONNECTION_ERROR, "Fail to remove route ipv6 [%d]", rv); //LCOV_EXCL_LINE
1369 CONN_UNLOCK; //LCOV_EXCL_LINE
1370 return rv; //LCOV_EXCL_LINE
1374 return CONNECTION_ERROR_NONE;
1377 EXPORT_API int connection_add_route_entry(connection_h connection,
1378 connection_address_family_e address_family, const char *interface_name,
1379 const char *host_address, const char *gateway)
1383 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1385 if (!(__connection_check_handle_validity(connection)) ||
1386 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1387 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1388 interface_name == NULL || host_address == NULL) {
1389 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1391 return CONNECTION_ERROR_INVALID_PARAMETER;
1394 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1395 int rv = _connection_libnet_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4,
1396 interface_name, host_address, gateway);
1400 int rv = _connection_libnet_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6,
1401 interface_name, host_address, gateway);
1407 EXPORT_API int connection_remove_route_entry(connection_h connection,
1408 connection_address_family_e address_family, const char *interface_name,
1409 const char *host_address, const char *gateway)
1413 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
1415 if (!(__connection_check_handle_validity(connection)) ||
1416 (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
1417 address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
1418 interface_name == NULL || host_address == NULL) {
1419 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1421 return CONNECTION_ERROR_INVALID_PARAMETER;
1424 if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
1425 int rv = _connection_libnet_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4,
1426 interface_name, host_address, gateway);
1430 int rv = _connection_libnet_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6,
1431 interface_name, host_address, gateway);
1437 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
1439 int rv = VCONF_OK, rv1 = VCONF_OK;
1440 int last_size = 0, size = 0;
1441 #if defined TIZEN_DUALSIM_ENABLE
1445 if (llsize == NULL) {
1446 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1447 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1450 switch (statistics_type) {
1451 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1452 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1453 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1454 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1457 return CONNECTION_ERROR_INVALID_PARAMETER;
1460 #if defined TIZEN_DUALSIM_ENABLE
1461 rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
1462 if (rv != VCONF_OK) {
1463 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
1465 return CONNECTION_ERROR_OPERATION_FAILED;
1471 switch (statistics_type) {
1472 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1473 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1475 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1476 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1478 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1479 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
1480 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
1482 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1483 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
1484 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
1487 #if defined TIZEN_DUALSIM_ENABLE
1490 switch (statistics_type) {
1491 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1492 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1494 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1495 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1497 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1498 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
1499 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
1501 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1502 rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
1503 rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
1509 CONNECTION_LOG(CONNECTION_ERROR, "Invalid subscriber id:%d", sim_id);
1510 return CONNECTION_ERROR_OPERATION_FAILED;
1514 if (rv != VCONF_OK || rv1 != VCONF_OK) {
1515 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular statistics"); //LCOV_EXCL_LINE
1516 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1519 *llsize = (long long)(last_size * 1000) + (long long)(size * 1000);
1520 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", *llsize);
1522 return CONNECTION_ERROR_NONE;
1525 static int __get_statistic(connection_handle_s *conn_handle, connection_type_e connection_type,
1526 connection_statistics_type_e statistics_type, long long *llsize)
1529 unsigned long long ull_size;
1531 if (llsize == NULL) {
1532 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
1533 return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
1536 rv = _connection_libnet_check_get_privilege();
1537 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1539 else if (rv != CONNECTION_ERROR_NONE) {
1540 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
1541 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1544 if (connection_type == CONNECTION_TYPE_CELLULAR)
1545 return __get_cellular_statistic(statistics_type, llsize);
1546 else if (connection_type == CONNECTION_TYPE_WIFI) {
1547 switch (statistics_type) {
1548 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1549 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1551 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1552 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1554 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1555 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1557 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1558 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1561 return CONNECTION_ERROR_INVALID_PARAMETER;
1564 rv = _connection_libnet_get_statistics(conn_handle, stat_type, &ull_size);
1565 if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
1567 else if (rv != CONNECTION_ERROR_NONE) {
1568 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics"); //LCOV_EXCL_LINE
1569 *llsize = 0; //LCOV_EXCL_LINE
1570 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1573 CONNECTION_LOG(CONNECTION_INFO, "%lld bytes", ull_size);
1574 *llsize = (long long)ull_size;
1576 return CONNECTION_ERROR_INVALID_PARAMETER;
1578 return CONNECTION_ERROR_NONE;
1581 static int __reset_statistic(connection_handle_s *conn_handle,
1582 connection_type_e connection_type, connection_statistics_type_e statistics_type)
1588 if (connection_type == CONNECTION_TYPE_CELLULAR)
1589 conn_type = NET_DEVICE_CELLULAR;
1590 else if (connection_type == CONNECTION_TYPE_WIFI)
1591 conn_type = NET_DEVICE_WIFI;
1593 return CONNECTION_ERROR_INVALID_PARAMETER;
1595 switch (statistics_type) {
1596 case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
1597 stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA;
1599 case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
1600 stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA;
1602 case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
1603 stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA;
1605 case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
1606 stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA;
1609 return CONNECTION_ERROR_INVALID_PARAMETER;
1612 rv = _connection_libnet_set_statistics(conn_handle, conn_type, stat_type);
1613 if (rv != CONNECTION_ERROR_NONE)
1616 CONNECTION_LOG(CONNECTION_INFO, "connection_reset_statistics success");
1618 return CONNECTION_ERROR_NONE;
1621 EXPORT_API int connection_get_statistics(connection_h connection,
1622 connection_type_e connection_type,
1623 connection_statistics_type_e statistics_type, long long* size)
1627 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1629 if (connection_type == CONNECTION_TYPE_CELLULAR)
1630 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1631 else if (connection_type == CONNECTION_TYPE_WIFI)
1632 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1634 if (!(__connection_check_handle_validity(connection)) || size == NULL) {
1635 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1637 return CONNECTION_ERROR_INVALID_PARAMETER;
1640 int rv = __get_statistic(connection, connection_type, statistics_type, size);
1641 if (rv != CONNECTION_ERROR_NONE) {
1642 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get statistics [%d]", rv); //LCOV_EXCL_LINE
1644 return rv; //LCOV_EXCL_LINE
1648 return CONNECTION_ERROR_NONE;
1651 EXPORT_API int connection_reset_statistics(connection_h connection,
1652 connection_type_e connection_type,
1653 connection_statistics_type_e statistics_type)
1657 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE);
1659 if (connection_type == CONNECTION_TYPE_CELLULAR)
1660 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
1661 else if (connection_type == CONNECTION_TYPE_WIFI)
1662 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
1664 if (!__connection_check_handle_validity(connection)) {
1665 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1667 return CONNECTION_ERROR_INVALID_PARAMETER;
1670 int rv = __reset_statistic(connection, connection_type, statistics_type);
1671 if (rv != CONNECTION_ERROR_NONE) {
1672 CONNECTION_LOG(CONNECTION_ERROR, "Fail to get statistics [%d]", rv); //LCOV_EXCL_LINE
1674 return rv; //LCOV_EXCL_LINE
1678 return CONNECTION_ERROR_NONE;
1681 EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
1682 connection_type_e connection_type, connection_ipv6_address_cb callback,
1687 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE,
1688 TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
1690 GSList *ipv6_address_list = NULL;
1692 if (!(__connection_check_handle_validity(connection))) {
1693 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1695 return CONNECTION_ERROR_INVALID_PARAMETER;
1698 int rv = CONNECTION_ERROR_NONE;
1700 switch (connection_type) {
1701 case CONNECTION_TYPE_WIFI:
1702 rv = net_foreach_ipv6_address(NET_DEVICE_WIFI,
1703 &ipv6_address_list);
1705 case CONNECTION_TYPE_CELLULAR:
1706 rv = net_foreach_ipv6_address(NET_DEVICE_CELLULAR,
1707 &ipv6_address_list);
1709 case CONNECTION_TYPE_ETHERNET:
1710 rv = net_foreach_ipv6_address(NET_DEVICE_ETHERNET,
1711 &ipv6_address_list);
1713 case CONNECTION_TYPE_BT:
1714 rv = net_foreach_ipv6_address(NET_DEVICE_BLUETOOTH,
1715 &ipv6_address_list);
1718 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1720 return CONNECTION_ERROR_INVALID_PARAMETER;
1723 if (rv != NET_ERR_NONE) {
1724 CONNECTION_LOG(CONNECTION_ERROR, "net_get_multiple_id_address" //LCOV_EXCL_LINE
1725 " Failed = %d\n", rv);
1726 CONN_UNLOCK; //LCOV_EXCL_LINE
1727 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
1731 for (list = ipv6_address_list; list; list = list->next) {
1732 rv = callback((char *)list->data, user_data);
1737 g_slist_free_full(ipv6_address_list, g_free);
1738 ipv6_address_list = NULL;
1741 return CONNECTION_ERROR_NONE;
1744 EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
1750 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1752 if (!(__connection_check_handle_validity(connection))) {
1753 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1755 return CONNECTION_ERROR_INVALID_PARAMETER;
1758 ret = _connection_libnet_start_tcpdump(connection);
1759 if (ret != CONNECTION_ERROR_NONE) {
1760 CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret); //LCOV_EXCL_LINE
1761 CONN_UNLOCK; //LCOV_EXCL_LINE
1762 return ret; //LCOV_EXCL_LINE
1766 return CONNECTION_ERROR_NONE;
1769 EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
1775 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1777 if (!(__connection_check_handle_validity(connection))) {
1778 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1780 return CONNECTION_ERROR_INVALID_PARAMETER;
1783 ret = _connection_libnet_stop_tcpdump(connection);
1784 if (ret != CONNECTION_ERROR_NONE) {
1785 CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret); //LCOV_EXCL_LINE
1786 CONN_UNLOCK; //LCOV_EXCL_LINE
1787 return ret; //LCOV_EXCL_LINE
1791 return CONNECTION_ERROR_NONE;
1794 EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
1800 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1802 if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
1803 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1805 return CONNECTION_ERROR_INVALID_PARAMETER;
1808 ret = _connection_libnet_get_tcpdump_state(connection, tcpdump_state);
1809 if (ret != CONNECTION_ERROR_NONE) {
1810 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret); //LCOV_EXCL_LINE
1811 CONN_UNLOCK; //LCOV_EXCL_LINE
1812 return ret; //LCOV_EXCL_LINE
1816 return CONNECTION_ERROR_NONE;
1819 EXPORT_API int connection_profile_save_ethernet_eap_config(connection_h connection,
1820 connection_profile_h profile)
1824 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE);
1828 if (!__connection_check_handle_validity(connection) ||
1829 !_connection_libnet_check_profile_validity(profile)) {
1830 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
1832 return CONNECTION_ERROR_INVALID_PARAMETER;
1835 rv = _connection_libnet_profile_save_ethernet_eap_config(connection, profile);
1836 if (rv != CONNECTION_ERROR_NONE) {
1837 CONNECTION_LOG(CONNECTION_ERROR, "Failed to save ethernet eap config."); //LCOV_EXCL_LINE
1838 CONN_UNLOCK; //LCOV_EXCL_LINE
1839 return rv; //LCOV_EXCL_LINE
1843 return CONNECTION_ERROR_NONE;