Merge 2.3 code for sync #2 44/35444/2 accepted/tizen/common/20150311.133037 accepted/tizen/mobile/20150312.015336 accepted/tizen/tv/20150312.015307 accepted/tizen/wearable/20150312.015320 submit/tizen/20150311.104745
authortaesub.kim <taesub.kim@samsung.com>
Mon, 16 Feb 2015 01:24:22 +0000 (10:24 +0900)
committertaesub.kim <taesub.kim@samsung.com>
Mon, 16 Feb 2015 01:26:38 +0000 (10:26 +0900)
Change-Id: I985ce9a5700db698a749e66c793beef5cde10907
Signed-off-by: Taesub Kimz <taesub.kim@samsung.com>
src/connection.c
src/connection_profile.c
src/libnetwork.c
test/connection_test.c

index 43b2fe0..92c4ff6 100644 (file)
@@ -219,12 +219,15 @@ static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
 
 static bool __connection_check_handle_validity(connection_h connection)
 {
-       GSList *list;
+       bool ret = false;
+
+       if (connection == NULL)
+               return false;
 
-       for (list = conn_handle_list; list; list = list->next)
-               if (connection == list->data) return true;
+       if (g_slist_find(conn_handle_list, connection) != NULL)
+               ret = true;
 
-       return false;
+       return ret;
 }
 
 static int __connection_get_handle_count(void)
@@ -244,21 +247,23 @@ static int __connection_get_handle_count(void)
 EXPORT_API int connection_create(connection_h* connection)
 {
        CONNECTION_MUTEX_LOCK;
-
+       int rv;
        if (connection == NULL || __connection_check_handle_validity(*connection)) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
                CONNECTION_MUTEX_UNLOCK;
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
-       if (_connection_libnet_init() == false) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Creation failed!\n");
-               CONNECTION_MUTEX_UNLOCK;
+       rv = _connection_libnet_init();
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       }
+       else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv);
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
-       CONNECTION_LOG(CONNECTION_ERROR, "Connection successfully created!\n");
-
        *connection = g_try_malloc0(sizeof(connection_handle_s));
        if (*connection != NULL) {
                CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection);
@@ -537,8 +542,11 @@ EXPORT_API int connection_add_profile(connection_h connection, connection_profil
        }
 
        rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
-       if (rv != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
@@ -563,8 +571,11 @@ EXPORT_API int connection_remove_profile(connection_h connection, connection_pro
        }
 
        rv = net_delete_profile(profile_info->ProfileName);
-       if (rv != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
@@ -583,8 +594,11 @@ EXPORT_API int connection_update_profile(connection_h connection, connection_pro
        net_profile_info_t *profile_info = profile;
 
        rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
-       if (rv != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
@@ -596,8 +610,9 @@ EXPORT_API int connection_get_profile_iterator(connection_h connection,
 {
        if (!(__connection_check_handle_validity(connection)) ||
            (type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
-            type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
+            type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
+            type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
@@ -689,6 +704,22 @@ EXPORT_API int connection_close_profile(connection_h connection, connection_prof
        return _connection_libnet_close_profile(profile, callback, user_data);
 }
 
+EXPORT_API int connection_reset_profile(connection_h connection,
+                               connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
+{
+       if (!(__connection_check_handle_validity(connection))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if(id < 0 || id > 1) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       return _connection_libnet_reset_profile(type, id, callback, user_data);
+}
+
 EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
 {
        if (!(__connection_check_handle_validity(connection)) ||
@@ -700,13 +731,23 @@ EXPORT_API int connection_add_route(connection_h connection, const char* interfa
        return _connection_libnet_add_route(interface_name, host_address);
 }
 
+EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
+{
+       if (!(__connection_check_handle_validity(connection)) ||
+           interface_name == NULL || host_address == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       return _connection_libnet_remove_route(interface_name, host_address);
+}
 
 /* Connection Statistics module ******************************************************************/
 
 static int __get_statistic(connection_type_e connection_type,
                        connection_statistics_type_e statistics_type, long long* llsize)
 {
-       int size;
+       int rv, size;
        unsigned long long ull_size;
        int stat_type;
        char *key = NULL;
@@ -760,8 +801,11 @@ static int __get_statistic(connection_type_e connection_type,
                        return CONNECTION_ERROR_INVALID_PARAMETER;
                }
 
-               if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
-                       CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
+               rv  = _connection_libnet_get_statistics(stat_type, &ull_size);
+               if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
+                       return rv;
+               else if (rv != CONNECTION_ERROR_NONE) {
+                       CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
                        *llsize = 0;
                        return CONNECTION_ERROR_OPERATION_FAILED;
                }
@@ -819,6 +863,11 @@ EXPORT_API int connection_get_statistics(connection_h connection,
                                connection_type_e connection_type,
                                connection_statistics_type_e statistics_type, long long* size)
 {
+       if (!(__connection_check_handle_validity(connection)) || size == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
        return __get_statistic(connection_type, statistics_type, size);
 }
 
@@ -826,5 +875,10 @@ EXPORT_API int connection_reset_statistics(connection_h connection,
                                connection_type_e connection_type,
                                connection_statistics_type_e statistics_type)
 {
+       if (!(__connection_check_handle_validity(connection))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
        return __reset_statistic(connection_type, statistics_type);
 }
index 3d30695..922bc18 100644 (file)
@@ -59,11 +59,22 @@ static char* __profile_convert_ip_to_string(net_addr_t *ip_addr)
 
 static void __profile_init_cellular_profile(net_profile_info_t *profile_info, const char *keyword)
 {
+       int default_subscriber_id = 0;
+       connection_profile_h profile = NULL;
+
        profile_info->profile_type = NET_DEVICE_CELLULAR;
        profile_info->ProfileState = NET_STATE_TYPE_IDLE;
        profile_info->ProfileInfo.Pdp.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF;
        profile_info->ProfileInfo.Pdp.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT;
        g_strlcpy(profile_info->ProfileInfo.Pdp.Keyword, keyword, NET_PDP_APN_LEN_MAX);
+
+       if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
+                                       &default_subscriber_id) != 0)
+               CONNECTION_LOG(CONNECTION_ERROR,
+                                               "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
+
+       profile = (connection_profile_h)profile_info;
+       _connection_libnet_set_cellular_subscriber_id(profile, default_subscriber_id);
 }
 
 static void __profile_init_wifi_profile(net_profile_info_t *profile_info)
@@ -355,6 +366,7 @@ EXPORT_API int connection_profile_get_network_interface_name(connection_profile_
 
 EXPORT_API int connection_profile_refresh(connection_profile_h profile)
 {
+       int rv;
        if (!(_connection_libnet_check_profile_validity(profile))) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
                return CONNECTION_ERROR_INVALID_PARAMETER;
@@ -363,8 +375,12 @@ EXPORT_API int connection_profile_refresh(connection_profile_h profile)
        net_profile_info_t profile_info_local;
        net_profile_info_t *profile_info = profile;
 
-       if (net_get_profile_info(profile_info->ProfileName, &profile_info_local) != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Error!!! net_get_profile_info() failed\n");
+       rv = net_get_profile_info(profile_info->ProfileName, &profile_info_local);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile information");
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
@@ -1246,6 +1262,72 @@ EXPORT_API int connection_profile_is_cellular_roaming(connection_profile_h profi
        return CONNECTION_ERROR_NONE;
 }
 
+EXPORT_API int connection_profile_is_cellular_hidden(connection_profile_h profile, bool* is_hidden)
+{
+       if (!(_connection_libnet_check_profile_validity(profile)) || is_hidden == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (profile_info->ProfileInfo.Pdp.Hidden)
+               *is_hidden = true;
+       else
+               *is_hidden = false;
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_is_cellular_editable(connection_profile_h profile, bool* is_editable)
+{
+       if (!(_connection_libnet_check_profile_validity(profile)) || is_editable == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (profile_info->ProfileInfo.Pdp.Editable)
+               *is_editable = true;
+       else
+               *is_editable = false;
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_is_cellular_default(connection_profile_h profile, bool* is_default)
+{
+       if (!(_connection_libnet_check_profile_validity(profile)) || is_default == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (profile_info->ProfileInfo.Pdp.DefaultConn)
+               *is_default = true;
+       else
+               *is_default = false;
+
+       return CONNECTION_ERROR_NONE;
+}
+
 EXPORT_API int connection_profile_set_cellular_service_type(connection_profile_h profile,
                connection_cellular_service_type_e service_type)
 {
index b63a600..3f61754 100755 (executable)
@@ -18,6 +18,7 @@
 #include <string.h>
 #include <glib.h>
 #include <vconf/vconf.h>
+
 #include "net_connection_private.h"
 
 static GSList *prof_handle_list = NULL;
@@ -39,14 +40,37 @@ struct _libnet_s {
        connection_opened_cb opened_cb;
        connection_closed_cb closed_cb;
        connection_set_default_cb set_default_cb;
+       connection_reset_cb reset_profile_cb;
        void *opened_user_data;
        void *closed_user_data;
        void *set_default_user_data;
+       void *reset_profile_user_data;
        bool registered;
+       bool is_created;
+};
+
+struct managed_idle_data {
+       GSourceFunc func;
+       gpointer user_data;
+       guint id;
+};
+
+struct feature_type {
+       bool telephony;
+       bool wifi;
+       bool tethering_bluetooth;
 };
 
 static struct _profile_list_s profile_iterator = {0, 0, NULL};
 static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
+static __thread GSList *managed_idler_list = NULL;
+static __thread bool is_check_enable_feature = false;
+static __thread struct feature_type enable_feature = {false, false, false};
+
+bool _connection_is_created(void)
+{
+       return libnet.is_created;
+}
 
 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
 {
@@ -71,6 +95,8 @@ static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
                return CONNECTION_ERROR_OPERATION_ABORTED;
        case NET_ERR_TIME_OUT:
                return CONNECTION_ERROR_NO_REPLY;
+       case NET_ERR_ACCESS_DENIED:
+               return CONNECTION_ERROR_PERMISSION_DENIED;
        default:
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
@@ -132,6 +158,14 @@ static const char *__libnet_convert_cp_state_to_string(connection_profile_state_
        }
 }
 
+static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
+{
+       if (user_cb != NULL) {
+               libnet.reset_profile_cb = user_cb;
+               libnet.reset_profile_user_data = user_data;
+       }
+}
+
 static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
 {
        if (user_cb) {
@@ -140,6 +174,31 @@ static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data
        }
 }
 
+static gboolean __libnet_reset_profile_cb_idle(gpointer data)
+{
+       connection_error_e result = (connection_error_e)data;
+
+       if (libnet.reset_profile_cb != NULL)
+               libnet.reset_profile_cb(result, libnet.reset_profile_user_data);
+
+       libnet.reset_profile_cb = NULL;
+       libnet.reset_profile_user_data = NULL;
+
+       return FALSE;
+}
+
+static void __libnet_reset_profile_cb(connection_error_e result)
+{
+       if (_connection_is_created() != true) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
+                               "If multi-threaded, thread integrity be broken.");
+               return;
+       }
+
+       if (libnet.reset_profile_cb != NULL)
+               _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
+}
+
 static void __libnet_opened_cb(connection_error_e result)
 {
        if (libnet.opened_cb)
@@ -303,6 +362,10 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
        case NET_EVENT_WIFI_WPS_RSP:
                CONNECTION_LOG(CONNECTION_INFO, "Got wifi WPS RSP\n");
                /* fall through */
+       case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
+               result = __libnet_convert_to_cp_error_type(event_cb->Error);
+               CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
+               __libnet_reset_profile_cb(result);
        default :
                CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n");
                break;
@@ -415,8 +478,11 @@ int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
        net_profile_name_t profile_name;
 
        rv = net_get_wifi_state(&wlan_state, &profile_name);
-       if (rv != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Error!! net_get_wifi_state() failed.\n");
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
@@ -442,12 +508,12 @@ int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
 
 int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
 {
+       int rv;
        struct _profile_list_s ethernet_profiles = {0, 0, NULL};
-       net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
-
-       if (ethernet_profiles.count == 0) {
-               *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
-               return CONNECTION_ERROR_NONE;
+       rv = net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
        }
 
        switch (ethernet_profiles.profiles->ProfileState) {
@@ -474,8 +540,13 @@ int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
 int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
 {
        int i = 0;
+       int rv = 0;
        struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
-       net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
+       rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       }
 
        if (bluetooth_profiles.count == 0) {
                *state = CONNECTION_BT_STATE_DEACTIVATED;
@@ -612,7 +683,10 @@ int _connection_libnet_get_current_profile(connection_profile_h *profile)
        rv = net_get_active_net_info(&active_profile);
        if (rv == NET_ERR_NO_SERVICE)
                return CONNECTION_ERROR_NO_CONNECTION;
-       else if (rv != NET_ERR_NONE)
+       else if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
        *profile = g_try_malloc0(sizeof(net_profile_info_t));
@@ -625,16 +699,41 @@ int _connection_libnet_get_current_profile(connection_profile_h *profile)
        return CONNECTION_ERROR_NONE;
 }
 
+int _connection_libnet_reset_profile(connection_reset_option_e type,
+               connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
+{
+       int rv;
+
+       rv = net_reset_profile(type, id);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       __libnet_set_reset_profile_cb(callback, user_data);
+
+       return CONNECTION_ERROR_NONE;
+}
+
 int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void* user_data)
 {
+       int rv;
+
        if (!(_connection_libnet_check_profile_validity(profile))) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
        net_profile_info_t *profile_info = profile;
 
-       if (net_open_connection_with_profile(profile_info->ProfileName) != NET_ERR_NONE)
+       rv = net_open_connection_with_profile(profile_info->ProfileName);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
        __libnet_set_opened_cb(callback, user_data);
@@ -652,8 +751,13 @@ int _connection_libnet_get_cellular_service_profile(connection_cellular_service_
        struct _profile_list_s cellular_profiles = {0, 0, NULL};
 
        rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
-       if (rv != NET_ERR_NONE)
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
                return CONNECTION_ERROR_OPERATION_FAILED;
+       }
 
        for (;i < cellular_profiles.count;i++)
                if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
@@ -696,6 +800,8 @@ done:
 
 int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
 {
+       int rv;
+
        if (!(_connection_libnet_check_profile_validity(profile))) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
                return CONNECTION_ERROR_INVALID_PARAMETER;
@@ -709,7 +815,11 @@ int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_ser
        if (service_type != type)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       if (net_set_default_cellular_service_profile(profile_info->ProfileName) != NET_ERR_NONE)
+       rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
        return CONNECTION_ERROR_NONE;
@@ -718,6 +828,8 @@ int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_ser
 int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
                        connection_profile_h profile, connection_set_default_cb callback, void* user_data)
 {
+       int rv;
+
        if (!(_connection_libnet_check_profile_validity(profile))) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
                return CONNECTION_ERROR_INVALID_PARAMETER;
@@ -731,7 +843,11 @@ int _connection_libnet_set_cellular_service_profile_async(connection_cellular_se
        if (service_type != type)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       if (net_set_default_cellular_service_profile_async(profile_info->ProfileName) != NET_ERR_NONE)
+       rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
        __libnet_set_default_cb(callback, user_data);
@@ -741,6 +857,8 @@ int _connection_libnet_set_cellular_service_profile_async(connection_cellular_se
 
 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
 {
+       int rv;
+
        if (!(_connection_libnet_check_profile_validity(profile))) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
                return CONNECTION_ERROR_INVALID_PARAMETER;
@@ -748,6 +866,13 @@ int _connection_libnet_close_profile(connection_profile_h profile, connection_cl
 
        net_profile_info_t *profile_info = profile;
 
+       rv = net_close_connection(profile_info->ProfileName);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
        if (net_close_connection(profile_info->ProfileName) != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
@@ -758,6 +883,7 @@ int _connection_libnet_close_profile(connection_profile_h profile, connection_cl
 
 int _connection_libnet_add_route(const char *interface_name, const char *host_address)
 {
+       int rv;
        char *endstr = strrchr(host_address, '.');
 
        if (endstr == NULL ||
@@ -769,7 +895,35 @@ int _connection_libnet_add_route(const char *interface_name, const char *host_ad
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
-       if (net_add_route(host_address, interface_name) != NET_ERR_NONE)
+       rv = net_add_route(host_address, interface_name);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
+       return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
+{
+       int rv;
+       char *endstr = strrchr(host_address, '.');
+
+       if (endstr == NULL ||
+           strcmp(endstr, ".0") == 0 ||
+           strncmp(host_address, "0.", 2) == 0 ||
+           strstr(host_address, ".0.") != NULL ||
+           strstr(host_address, "255") != NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       rv = net_remove_route(host_address, interface_name);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
        return CONNECTION_ERROR_NONE;
@@ -817,7 +971,12 @@ bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile
 
 int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
 {
-       if (net_set_statistics(device_type, statistics_type) != NET_ERR_NONE)
+       int rv;
+       rv = net_set_statistics(device_type, statistics_type);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
                return CONNECTION_ERROR_OPERATION_FAILED;
 
        return CONNECTION_ERROR_NONE;
@@ -825,9 +984,158 @@ int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_t
 
 int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
 {
-       if (net_get_statistics(NET_DEVICE_WIFI, statistics_type, size) != NET_ERR_NONE)
-                       return CONNECTION_ERROR_OPERATION_FAILED;
+       int rv;
+       rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       }else if (rv != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
 
-               return CONNECTION_ERROR_NONE;
+       return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
+               connection_cellular_subscriber_id_e sim_id)
+{
+       char *modem_path = NULL;
+       net_profile_info_t *profile_info = (net_profile_info_t *)profile;
+
+       if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       if (!modem_path) {
+               CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
+                               NET_PROFILE_NAME_LEN_MAX);
+       g_free(modem_path);
+
+       return CONNECTION_ERROR_NONE;
+}
+
+static void __connection_idle_destroy_cb(gpointer data)
+{
+       if (!data)
+               return;
+
+       managed_idler_list = g_slist_remove(managed_idler_list, data);
+       g_free(data);
+}
+
+static gboolean __connection_idle_cb(gpointer user_data)
+{
+       struct managed_idle_data *data = (struct managed_idle_data *)user_data;
+
+       if (!data)
+               return FALSE;
+
+       return data->func(data->user_data);
+}
+
+guint _connection_callback_add(GSourceFunc func, gpointer user_data)
+{
+       guint id;
+       struct managed_idle_data *data;
+
+       if (!func)
+               return 0;
+
+       data = g_try_new0(struct managed_idle_data, 1);
+       if (!data)
+               return 0;
+
+       data->func = func;
+       data->user_data = user_data;
+
+       id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
+                       __connection_idle_destroy_cb);
+       if (!id) {
+               g_free(data);
+               return id;
+       }
+
+       data->id = id;
+
+       managed_idler_list = g_slist_append(managed_idler_list, data);
+
+       return id;
+}
+
+void _connection_callback_cleanup(void)
+{
+       GSList *cur = managed_idler_list;
+       GSource *src;
+       struct managed_idle_data *data;
+
+       while (cur) {
+               GSList *next = cur->next;
+               data = (struct managed_idle_data *)cur->data;
+
+               src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
+               if (src) {
+                       g_source_destroy(src);
+                       cur = managed_idler_list;
+               } else
+                       cur = next;
+       }
+
+       g_slist_free(managed_idler_list);
+       managed_idler_list = NULL;
 }
 
+int _connection_libnet_check_get_privilege()
+{
+       int rv;
+
+       rv = net_check_get_privilege();
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
+       return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_check_profile_privilege()
+{
+       int rv;
+
+       rv = net_check_profile_privilege();
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
+       return CONNECTION_ERROR_NONE;
+}
+
+bool _connection_libnet_get_is_check_enable_feature()
+{
+       return is_check_enable_feature;
+}
+
+bool _connection_libnet_get_enable_feature_state(enable_feature_type_e feature_type)
+{
+       if(is_check_enable_feature){
+               switch(feature_type) {
+               case FEATURE_TYPE_TELEPHONY:
+                       return enable_feature.telephony;
+               case FEATURE_TYPE_WIFI:
+                       return enable_feature.wifi;
+               case FEATURE_TYPE_TETHERING_BLUETOOTH:
+                       return enable_feature.tethering_bluetooth;
+               default:
+                       CONNECTION_LOG(CONNECTION_ERROR, "Invalid feature type");
+                       return false;
+               }
+       }
+       CONNECTION_LOG(CONNECTION_ERROR, "Not checked enable feature yet");
+       return false;
+}
index dca780e..aa68ef6 100644 (file)
@@ -47,7 +47,9 @@ static bool test_get_user_string(const char *msg, char *buf, int buf_size)
                return false;
        }
 
-       buf[strlen(buf) - 1] = '\0';
+       if (rv >= 0)
+               buf[rv] = '\0';
+
 
        return true;
 }
@@ -85,6 +87,46 @@ static const char *test_print_state(connection_profile_state_e state)
        }
 }
 
+static const char *test_print_error(connection_error_e error)
+{
+       switch (error) {
+       case CONNECTION_ERROR_NONE:
+               return "CONNECTION_ERROR_NONE";
+       case CONNECTION_ERROR_INVALID_PARAMETER:
+               return "CONNECTION_ERROR_INVALID_PARAMETER";
+       case CONNECTION_ERROR_OUT_OF_MEMORY:
+               return "CONNECTION_ERROR_OUT_OF_MEMORY";
+       case CONNECTION_ERROR_INVALID_OPERATION:
+               return "CONNECTION_ERROR_INVALID_OPERATION";
+       case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
+               return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
+       case CONNECTION_ERROR_OPERATION_FAILED:
+               return "CONNECTION_ERROR_OPERATION_FAILED";
+       case CONNECTION_ERROR_ITERATOR_END:
+               return "CONNECTION_ERROR_ITERATOR_END";
+       case CONNECTION_ERROR_NO_CONNECTION:
+               return "CONNECTION_ERROR_NO_CONNECTION";
+       case CONNECTION_ERROR_NOW_IN_PROGRESS:
+               return "CONNECTION_ERROR_NOW_IN_PROGRESS";
+       case CONNECTION_ERROR_ALREADY_EXISTS:
+               return "CONNECTION_ERROR_ALREADY_EXISTS";
+       case CONNECTION_ERROR_OPERATION_ABORTED:
+               return "CONNECTION_ERROR_OPERATION_ABORTED";
+       case CONNECTION_ERROR_DHCP_FAILED:
+               return "CONNECTION_ERROR_DHCP_FAILED";
+       case CONNECTION_ERROR_INVALID_KEY:
+               return "CONNECTION_ERROR_INVALID_KEY";
+       case CONNECTION_ERROR_NO_REPLY:
+               return "CONNECTION_ERROR_NO_REPLY";
+       case CONNECTION_ERROR_PERMISSION_DENIED:
+               return "CONNECTION_ERROR_PERMISSION_DENIED";
+       case CONNECTION_ERROR_NOT_SUPPORTED:
+               return "CONNECTION_ERROR_NOT_SUPPORTED";
+       default:
+               return "CONNECTION_ERROR_UNKNOWN";
+       }
+}
+
 static void test_type_changed_callback(connection_type_e type, void* user_data)
 {
        printf("Type changed callback, connection type : %d\n", type);
@@ -133,6 +175,14 @@ static void test_connection_closed_callback(connection_error_e result, void* use
                printf("Connection close Failed, err : %d\n", result);
 }
 
+static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
+{
+       if (result ==  CONNECTION_ERROR_NONE)
+               printf("Reset profile Succeeded\n");
+       else
+               printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
+}
+
 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
 {
        if (result ==  CONNECTION_ERROR_NONE)
@@ -473,6 +523,8 @@ static void test_print_cellular_info(connection_profile_h profile)
        char *password = NULL;
        char *home_url = NULL;
        bool roaming = false;
+       bool hidden = false;
+       bool editable = false;
 
        if (connection_profile_get_cellular_network_type(profile, &network_type) != CONNECTION_ERROR_NONE)
                printf("Fail to get cellular network type!\n");
@@ -512,6 +564,16 @@ static void test_print_cellular_info(connection_profile_h profile)
                printf("Fail to get cellular is roaming!\n");
        else
                printf("Cellular roaming : %s\n", roaming ? "true" : "false");
+
+       if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
+               printf("Fail to get cellular hidden state!\n");
+       else
+               printf("Cellular hidden : %s\n", hidden ? "true" : "false");
+
+       if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
+               printf("Fail to get cellular editing state!\n");
+       else
+               printf("Cellular editable : %s\n", editable ? "true" : "false");
 }
 
 static void test_print_wifi_info(connection_profile_h profile)
@@ -825,12 +887,58 @@ int test_get_profile_list(void)
        return 1;
 }
 
+int test_get_default_profile_list(void)
+{
+       int rv = 0;
+       char *profile_name = NULL;
+       connection_profile_iterator_h profile_iter;
+       connection_profile_h profile_h;
+       connection_cellular_service_type_e service_type;
+       bool is_default = false;
+
+       rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       while (connection_profile_iterator_has_next(profile_iter)) {
+               if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get profile handle\n");
+                       return -1;
+               }
+
+               if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get profile name\n");
+                       return -1;
+               }
+               printf("profile name : %s\n", profile_name);
+               g_free(profile_name);
+
+               if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get profile service type\n");
+                       return -1;
+               }
+               printf("service type : %d\n", service_type);
+
+               if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get profile subscriber id\n");
+                       return -1;
+               }
+               printf("Default : %d\n", is_default);
+       }
+
+       return 1;
+}
+
 int test_get_connected_profile_list(void)
 {
        int rv = 0;
        char *profile_name = NULL;
        connection_profile_iterator_h profile_iter;
        connection_profile_h profile_h;
+       bool is_default = false;
+       connection_profile_type_e type;
 
        rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
        if (rv != CONNECTION_ERROR_NONE) {
@@ -850,6 +958,20 @@ int test_get_connected_profile_list(void)
                }
                printf("profile name : %s\n", profile_name);
                g_free(profile_name);
+
+               if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get profile type\n");
+                       return -1;
+               }
+               printf("profile type is %d\n", type);
+
+               if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
+               if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get profile is default\n");
+                       return -1;
+               }
+                       printf("[%s]\n", is_default ? "default" : "not default");
+               }
        }
 
        return 1;
@@ -1320,6 +1442,27 @@ int test_add_route(void)
        return 1;
 }
 
+int test_remove_route(void)
+{
+       int rv = 0;
+       char ip_addr[30];
+       char if_name[40];
+
+       if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 30) == false)
+               return -1;
+
+       if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
+               return -1;
+
+       rv = connection_remove_route(connection, if_name, ip_addr);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Fail to remove the route [%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       return 1;
+}
+
 int test_get_bt_state(void)
 {
        int rv = 0;
@@ -1357,9 +1500,33 @@ int test_get_profile_id(void)
        return 1;
 }
 
+int test_reset_profile(void)
+{
+       int type, sim_id, rv;
+
+       rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
+
+       if (rv == false || (type != 0 && type != 1)) {
+               printf("Invalid input!!\n");
+               return -1;
+       }
+
+       rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
+
+       if (rv == false || (sim_id != 0 && sim_id != 1)) {
+               printf("Invalid input!!\n");
+               return -1;
+       }
+
+       if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
-       
        GMainLoop *mainloop;
        mainloop = g_main_loop_new (NULL, FALSE);
 
@@ -1505,11 +1672,20 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                rv = test_add_route();
                break;
        case 'r':
-               rv = test_get_bt_state();
+               rv = test_remove_route();
                break;
        case 's':
+               rv = test_get_bt_state();
+               break;
+       case 't':
                rv = test_get_profile_id();
                break;
+       case 'u':
+               rv = test_reset_profile();
+               break;
+       case 'v':
+               rv = test_get_default_profile_list();
+               break;
        }
 
        if (rv == 1)