Add supported features check
[platform/core/api/connection.git] / src / libnetwork.c
index 1a8390d..82c747d 100755 (executable)
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License. 
+ * limitations under the License.
  */
 
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 #include <vconf/vconf.h>
+#include <system_info.h>
+#include <arpa/inet.h>
+
 #include "net_connection_private.h"
 
 static GSList *prof_handle_list = NULL;
@@ -39,14 +42,30 @@ 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;
+       libnet_ethernet_cable_state_changed_cb ethernet_cable_state_changed_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;
 };
 
 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;
+
+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 +90,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;
        }
@@ -107,6 +128,10 @@ static const char *__libnet_convert_cp_error_type_to_string(connection_error_e e
                return "INVALID_KEY";
        case CONNECTION_ERROR_NO_REPLY:
                return "NO_REPLY";
+       case CONNECTION_ERROR_PERMISSION_DENIED:
+               return "PERMISSION_DENIED";
+       case CONNECTION_ERROR_NOT_SUPPORTED:
+               return "NOT_SUPPORTED";
        }
 
        return "UNKNOWN";
@@ -128,6 +153,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) {
@@ -136,6 +169,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)
@@ -179,6 +237,19 @@ static void __libnet_default_cb(connection_error_e result)
        libnet.set_default_user_data = NULL;
 }
 
+static void __libnet_set_ethernet_cable_state_changed_cb(
+               libnet_ethernet_cable_state_changed_cb user_cb)
+{
+       libnet.ethernet_cable_state_changed_cb = user_cb;
+}
+
+static void __libnet_ethernet_cable_state_changed_cb(
+               connection_ethernet_cable_state_e state)
+{
+       if (libnet.ethernet_cable_state_changed_cb)
+               libnet.ethernet_cable_state_changed_cb(state);
+}
+
 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
 {
        if (profile_name == NULL)
@@ -299,12 +370,37 @@ 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);
+
+       case NET_EVENT_ETHERNET_CABLE_ATTACHED:
+               CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n");
+               __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED);
+               break;
+       case NET_EVENT_ETHERNET_CABLE_DETACHED:
+               CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n");
+               __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED);
+               break;
        default :
                CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n");
                break;
        }
 }
 
+static int __libnet_check_address_type(int address_family, const char *address)
+{
+       struct in6_addr buf;
+       int err = 0;
+
+       err = inet_pton(address_family, address, &buf);
+       if(err > 0)
+               return 1;
+
+       return 0;
+}
+
 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
 {
        int count = 0;
@@ -332,7 +428,7 @@ void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_
        }
 }
 
-bool _connection_libnet_init(void)
+int _connection_libnet_init(void)
 {
        int rv;
 
@@ -347,7 +443,7 @@ bool _connection_libnet_init(void)
                        profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
        }
 
-       return true;
+       return NET_ERR_NONE;
 }
 
 bool _connection_libnet_deinit(void)
@@ -379,6 +475,9 @@ bool _connection_libnet_check_profile_validity(connection_profile_h profile)
        GSList *list;
        int i = 0;
 
+       if (profile == NULL)
+               return false;
+
        for (list = prof_handle_list; list; list = list->next)
                if (profile == list->data) return true;
 
@@ -404,14 +503,19 @@ bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
 }
 
 
-bool _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
+int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
 {
+       int rv;
        net_wifi_state_t wlan_state;
        net_profile_name_t profile_name;
 
-       if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Error!! net_get_wifi_state() failed.\n");
-               return false;
+       rv = net_get_wifi_state(&wlan_state, &profile_name);
+       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;
        }
 
        switch (wlan_state) {
@@ -428,20 +532,25 @@ bool _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
                break;
        default :
                CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
-               return false;
+               return CONNECTION_ERROR_INVALID_OPERATION;
        }
 
-       return true;
+       return CONNECTION_ERROR_NONE;
 }
 
-bool _connection_libnet_get_ethernet_state(connection_ethernet_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);
+       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;
+       }
 
        if (ethernet_profiles.count == 0) {
-               *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
-               return true;
+               state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
+               return CONNECTION_ERROR_NONE;
        }
 
        switch (ethernet_profiles.profiles->ProfileState) {
@@ -457,23 +566,57 @@ bool _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
                *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
                break;
        default:
-               return false;
+               return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
        __libnet_clear_profile_list(&ethernet_profiles);
 
-       return true;
+       return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state)
+{
+       int rv = 0;
+       int status = 0;
+
+       rv = net_get_ethernet_cable_state(&status);
+       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 ethernet cable state[%d]", rv);
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       if(status == 1)
+               *state = CONNECTION_ETHERNET_CABLE_ATTACHED;
+       else
+               *state = CONNECTION_ETHERNET_CABLE_DETACHED;
+       return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_set_ethernet_cable_state_changed_cb(
+               libnet_ethernet_cable_state_changed_cb callback)
+{
+       __libnet_set_ethernet_cable_state_changed_cb(callback);
+
+       return CONNECTION_ERROR_NONE;
 }
 
-bool _connection_libnet_get_bluetooth_state(connection_bt_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;
-               return true;
+               return CONNECTION_ERROR_NONE;
        }
 
        for (; i < bluetooth_profiles.count; i++) {
@@ -491,14 +634,14 @@ bool _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
                        break;
                default:
                        __libnet_clear_profile_list(&bluetooth_profiles);
-                       return false;
+                       return CONNECTION_ERROR_OPERATION_FAILED;
                }
        }
 
 done:
        __libnet_clear_profile_list(&bluetooth_profiles);
 
-       return true;
+       return CONNECTION_ERROR_NONE;
 }
 
 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
@@ -545,6 +688,10 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                if (profiles == NULL) {
                        __libnet_clear_profile_list(&all_profiles);
                        return CONNECTION_ERROR_OUT_OF_MEMORY;
+               break;
+       case CONNECTION_ITERATOR_TYPE_DEFAULT:
+                       /* To do : Not supported yet */
+               break;
                }
 
                profile_iterator.profiles = profiles;
@@ -602,7 +749,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));
@@ -615,16 +765,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);
@@ -642,8 +817,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)
@@ -686,6 +866,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;
@@ -699,7 +881,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;
@@ -708,6 +894,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;
@@ -721,7 +909,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);
@@ -731,6 +923,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;
@@ -738,6 +932,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;
 
@@ -748,18 +949,139 @@ 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 = NULL;
+       int address_family = 0;
+
+       if(__libnet_check_address_type(AF_INET, host_address))
+               address_family = AF_INET;
+       else
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+
+       switch(address_family) {
+               case AF_INET:
+                       endstr = strrchr(host_address, '.');
+                       if (endstr == NULL ||
+                                       strcmp(endstr, ".0") == 0 ||
+                                       strncmp(host_address, "0.", 2) == 0 ||
+                                       strstr(host_address, "255") != NULL) {
+                               CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
+                               return CONNECTION_ERROR_INVALID_PARAMETER;
+                       }
+                       break;
+               default:
+                       return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       rv = net_add_route(host_address, interface_name, address_family);
+       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, '.');
+       int address_family = 0;
 
-       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\n");
+       if (__libnet_check_address_type(AF_INET, host_address))
+               address_family = AF_INET;
+       else
                return CONNECTION_ERROR_INVALID_PARAMETER;
+
+       switch(address_family) {
+               case AF_INET:
+                       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;
+                       }
+                       break;
+               default:
+                       return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       rv = net_remove_route(host_address, interface_name, address_family);
+       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_add_route_ipv6(const char *interface_name, const char *host_address, const char *gateway)
+{
+       int rv;
+       int address_family = 0;
+
+       address_family = AF_INET6;
+/*     if(__libnet_check_address_type(AF_INET6, host_address))
+               address_family = AF_INET6;
+       else
+               return CONNECTION_ERROR_INVALID_PARAMETER;*/
+
+       switch(address_family) {
+               case AF_INET6:
+                       if (strncmp(host_address, "fe80:", 5) == 0 ||
+                               strncmp(host_address, "ff00:", 5) == 0 ||
+                               strncmp(host_address, "::", 2) == 0) {
+                               CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
+                               return CONNECTION_ERROR_INVALID_PARAMETER;
+                       }
+                       break;
+               default:
+                       return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       rv = net_add_route_ipv6(host_address, interface_name, address_family, gateway);
+       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_ipv6(const char *interface_name, const char *host_address, const char *gateway)
+{
+       int rv;
+       int address_family = 0;
+
+       address_family = AF_INET6;
+/*     if (__libnet_check_address_type(AF_INET6, host_address))
+               address_family = AF_INET6;
+       else
+               return CONNECTION_ERROR_INVALID_PARAMETER;*/
+
+       switch(address_family) {
+               case AF_INET6:
+                       if (strncmp(host_address, "fe80:", 5) == 0 ||
+                               strncmp(host_address, "ff00:", 5) == 0 ||
+                               strncmp(host_address, "::", 2) == 0) {
+                               CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed\n");
+                               return CONNECTION_ERROR_INVALID_PARAMETER;
+                       }
+                       break;
+               default:
+                       return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
-       if (net_add_route(host_address, interface_name) != NET_ERR_NONE)
+       rv = net_remove_route_ipv6(host_address, interface_name, address_family, gateway);
+       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;
@@ -796,15 +1118,23 @@ bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
        return true;
 }
 
-void _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
+bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
 {
        net_profile_info_t *profile_info = profile;
-       g_hash_table_remove(profile_cb_table, profile_info->ProfileName);
+       if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
+               return true;
+
+       return false;
 }
 
 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;
@@ -812,9 +1142,164 @@ 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;
+}
+
+int _connection_check_feature_supported(const char *feature_name, ...)
+{
+       va_list list;
+       const char *key;
+       bool value, feature_supported = false;
+
+       va_start(list, feature_name);
+       key = feature_name;
+       while(1) {
+               if(system_info_get_platform_bool(key, &value) < 0) {
+                       CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info");
+                       set_last_result(CONNECTION_ERROR_OPERATION_FAILED);
+                       return CONNECTION_ERROR_OPERATION_FAILED;
+               }
+               SECURE_CONNECTION_LOG(CONNECTION_INFO, "%s feature is %s", key, (value?"true":"false"));
+               feature_supported |= value;
+               key = va_arg(list, const char *);
+               if (!key) break;
+       }
+       if (!feature_supported) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported");
+               set_last_result(CONNECTION_ERROR_NOT_SUPPORTED);
+               return CONNECTION_ERROR_NOT_SUPPORTED;
+       }
+       va_end(list);
+
+       set_last_result(CONNECTION_ERROR_NONE);
+       return CONNECTION_ERROR_NONE;
+}