Base Code merged to SPIN 2.4
[platform/core/api/connection.git] / src / libnetwork.c
index 82c747d..f167480 100755 (executable)
  * limitations under the License.
  */
 
+#include <glib.h>
 #include <stdio.h>
+#include <stdarg.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;
-static GHashTable *profile_cb_table = NULL;
+static __thread GSList *prof_handle_list = NULL;
+static __thread GHashTable *profile_cb_table = NULL;
 
 struct _profile_cb_s {
        connection_profile_state_changed_cb callback;
@@ -48,18 +49,23 @@ struct _libnet_s {
        void *closed_user_data;
        void *set_default_user_data;
        void *reset_profile_user_data;
-       bool registered;
        bool is_created;
 };
 
+struct _state_notify {
+       connection_profile_state_changed_cb callback;
+       connection_profile_state_e state;
+       void *user_data;
+};
+
 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 struct _profile_list_s profile_iterator = {0, 0, NULL};
+static __thread struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
 static __thread GSList *managed_idler_list = NULL;
 
 bool _connection_is_created(void)
@@ -67,6 +73,11 @@ bool _connection_is_created(void)
        return libnet.is_created;
 }
 
+static void __connection_set_created(bool tag)
+{
+       libnet.is_created = tag;
+}
+
 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
 {
        switch (err_type) {
@@ -161,14 +172,6 @@ static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *us
        }
 }
 
-static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
-{
-       if (user_cb) {
-               libnet.opened_cb = user_cb;
-               libnet.opened_user_data = user_data;
-       }
-}
-
 static gboolean __libnet_reset_profile_cb_idle(gpointer data)
 {
        connection_error_e result = (connection_error_e)data;
@@ -194,47 +197,103 @@ static void __libnet_reset_profile_cb(connection_error_e result)
                _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
 }
 
-static void __libnet_opened_cb(connection_error_e result)
+static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
 {
-       if (libnet.opened_cb)
+       if (user_cb != NULL) {
+               libnet.opened_cb = user_cb;
+               libnet.opened_user_data = user_data;
+       }
+}
+
+static gboolean __libnet_opened_cb_idle(gpointer data)
+{
+       connection_error_e result = (connection_error_e)data;
+
+       if (libnet.opened_cb != NULL)
                libnet.opened_cb(result, libnet.opened_user_data);
 
        libnet.opened_cb = NULL;
        libnet.opened_user_data = NULL;
+
+       return FALSE;
+}
+
+static void __libnet_opened_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.opened_cb != NULL)
+               _connection_callback_add(__libnet_opened_cb_idle, (gpointer)result);
 }
 
 static void __libnet_set_closed_cb(connection_closed_cb user_cb, void *user_data)
 {
-       if (user_cb) {
+       if (user_cb != NULL) {
                libnet.closed_cb = user_cb;
                libnet.closed_user_data = user_data;
        }
 }
 
-static void __libnet_closed_cb(connection_error_e result)
+static gboolean __libnet_closed_cb_idle(gpointer data)
 {
-       if (libnet.closed_cb)
+       connection_error_e result = (connection_error_e)data;
+
+       if (libnet.closed_cb != NULL)
                libnet.closed_cb(result, libnet.closed_user_data);
 
        libnet.closed_cb = NULL;
        libnet.closed_user_data = NULL;
+
+       return FALSE;
+}
+
+static void __libnet_closed_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.closed_cb != NULL)
+               _connection_callback_add(__libnet_closed_cb_idle, (gpointer)result);
 }
 
 static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
 {
-       if (user_cb) {
+       if (user_cb != NULL) {
                libnet.set_default_cb = user_cb;
                libnet.set_default_user_data = user_data;
        }
 }
 
-static void __libnet_default_cb(connection_error_e result)
+static gboolean __libnet_default_cb_idle(gpointer data)
 {
-       if (libnet.set_default_cb)
+       connection_error_e result = (connection_error_e)data;
+
+       if (libnet.set_default_cb != NULL)
                libnet.set_default_cb(result, libnet.set_default_user_data);
 
        libnet.set_default_cb = NULL;
        libnet.set_default_user_data = NULL;
+
+       return FALSE;
+}
+
+static void __libnet_default_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.set_default_cb != NULL)
+               _connection_callback_add(__libnet_default_cb_idle, (gpointer)result);
 }
 
 static void __libnet_set_ethernet_cable_state_changed_cb(
@@ -250,14 +309,37 @@ static void __libnet_ethernet_cable_state_changed_cb(
                libnet.ethernet_cable_state_changed_cb(state);
 }
 
+static gboolean __libnet_state_changed_cb_idle(gpointer data)
+{
+       struct _state_notify *notify = (struct _state_notify *)data;
+
+       if (notify == NULL)
+               return FALSE;
+
+       if (notify->callback != NULL)
+               notify->callback(notify->state, notify->user_data);
+
+       g_free(notify);
+
+       return FALSE;
+}
+
 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
 {
+       guint id;
+       struct _state_notify *notify;
+       struct _profile_cb_s *cb_info;
+
+       if (_connection_is_created() != true) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
+                               "If multi-threaded, thread integrity be broken.");
+               return;
+       }
+
        if (profile_name == NULL)
                return;
 
-       struct _profile_cb_s *cb_info;
        cb_info = g_hash_table_lookup(profile_cb_table, profile_name);
-
        if (cb_info == NULL)
                return;
 
@@ -266,8 +348,21 @@ static void __libnet_state_changed_cb(char *profile_name, connection_profile_sta
 
        cb_info->state = state;
 
-       if (state >= 0 && cb_info->callback)
-               cb_info->callback(state, cb_info->user_data);
+       if (state < 0 || cb_info->callback == NULL)
+               return;
+
+       notify = g_try_new0(struct _state_notify, 1);
+       if (notify == NULL)
+               return;
+
+       notify->callback = cb_info->callback;
+       notify->state = state;
+       notify->user_data = cb_info->user_data;
+
+       id = _connection_callback_add(__libnet_state_changed_cb_idle,
+                       (gpointer)notify);
+       if (!id)
+               g_free(notify);
 }
 
 static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
@@ -280,7 +375,7 @@ static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
        profile_list->profiles = NULL;
 }
 
-static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
+static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
 {
        bool is_requested = false;
        connection_error_e result = CONNECTION_ERROR_NONE;
@@ -291,7 +386,7 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
                /* fall through */
        case NET_EVENT_OPEN_IND:
                result = __libnet_convert_to_cp_error_type(event_cb->Error);
-               CONNECTION_LOG(CONNECTION_INFO, "Got connection open %s : %s\n",
+               CONNECTION_LOG(CONNECTION_INFO, "Connection opened %s[%s]",
                                        (is_requested) ? "RSP":"IND",
                                        __libnet_convert_cp_error_type_to_string(result));
 
@@ -301,12 +396,12 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
                switch (event_cb->Error) {
                case NET_ERR_NONE:
                case NET_ERR_ACTIVE_CONNECTION_EXISTS:
-                       CONNECTION_LOG(CONNECTION_INFO, "'Open connection' succeeded\n");
+                       CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection");
 
                        __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED);
                        return;
                default:
-                       CONNECTION_LOG(CONNECTION_ERROR, "'Open connection' failed!! [%s]\n",
+                       CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]",
                                                __libnet_convert_cp_error_type_to_string(result));
                }
 
@@ -318,7 +413,7 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
                /* fall through */
        case NET_EVENT_CLOSE_IND:
                result = __libnet_convert_to_cp_error_type(event_cb->Error);
-               CONNECTION_LOG(CONNECTION_INFO, "Got connection close %s : %s\n",
+               CONNECTION_LOG(CONNECTION_INFO, "Connection closed %s[%s]",
                                        (is_requested) ? "RSP":"IND",
                                        __libnet_convert_cp_error_type_to_string(result));
 
@@ -327,54 +422,42 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
 
                switch (event_cb->Error) {
                case NET_ERR_NONE:
-                       CONNECTION_LOG(CONNECTION_INFO, "'Close connection' succeeded!\n");
+                       CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection");
 
                        __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED);
                        return;
                default:
-                       CONNECTION_LOG(CONNECTION_ERROR, "'Close connection' failed!! [%s]\n",
-                                               __libnet_convert_cp_error_type_to_string(result));
+                       CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]",
+                                                       __libnet_convert_cp_error_type_to_string(result));
                }
 
                break;
        case NET_EVENT_NET_STATE_IND:
-               CONNECTION_LOG(CONNECTION_INFO, "Got State changed IND\n");
+               CONNECTION_LOG(CONNECTION_INFO, "State changed IND");
 
                if (event_cb->Datalength != sizeof(net_state_type_t))
                        return;
 
-               net_state_type_t *profile_state = (net_state_type_t*)event_cb->Data;
+               net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data;
                connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state);
 
-               CONNECTION_LOG(CONNECTION_INFO,
-                               "Profile State : %s, profile name : %s\n",
-                               __libnet_convert_cp_state_to_string(cp_state),
-                               event_cb->ProfileName);
+               CONNECTION_LOG(CONNECTION_INFO, "state: %s", __libnet_convert_cp_state_to_string(cp_state));
+               SECURE_CONNECTION_LOG(CONNECTION_INFO, "profile name: %s", event_cb->ProfileName);
 
                __libnet_state_changed_cb(event_cb->ProfileName, cp_state);
 
                break;
-       case NET_EVENT_WIFI_SCAN_IND:
-       case NET_EVENT_WIFI_SCAN_RSP:
-               CONNECTION_LOG(CONNECTION_INFO, "Got wifi scan IND\n");
-               break;
-       case NET_EVENT_WIFI_POWER_IND:
-       case NET_EVENT_WIFI_POWER_RSP:
-               CONNECTION_LOG(CONNECTION_INFO, "Got wifi power IND\n");
-               break;
        case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
                result = __libnet_convert_to_cp_error_type(event_cb->Error);
-               CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d\n", result);
+               CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d", result);
                __libnet_default_cb(result);
                break;
-       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);
-
+               break;
        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);
@@ -383,8 +466,8 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
                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;
        }
 }
@@ -428,16 +511,41 @@ void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_
        }
 }
 
+int __libnet_get_default_count(struct _profile_list_s *profile_list)
+{
+       int count = 0;
+       int i = 0;
+
+       for (;i < profile_list->count;i++) {
+               if (profile_list->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE)
+                       count++;
+       }
+
+       return count;
+}
+
+void __libnet_copy_default_profile(net_profile_info_t **dest, struct _profile_list_s *source)
+{
+       int i = 0;
+
+       for (;i < source->count;i++) {
+               if (source->profiles[i].ProfileInfo.Pdp.DefaultConn == TRUE) {
+                       memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t));
+                       (*dest)++;
+               }
+       }
+}
+
 int _connection_libnet_init(void)
 {
        int rv;
 
-       if (!libnet.registered) {
+       if (_connection_is_created() != true) {
                rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL);
                if (rv != NET_ERR_NONE)
-                       return false;
+                       return rv;
 
-               libnet.registered = true;
+               __connection_set_created(true);
 
                if (profile_cb_table == NULL)
                        profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
@@ -448,11 +556,11 @@ int _connection_libnet_init(void)
 
 bool _connection_libnet_deinit(void)
 {
-       if (libnet.registered) {
+       if (_connection_is_created() == true) {
                if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE)
                        return false;
 
-               libnet.registered = false;
+               __connection_set_created(false);
 
                if (profile_cb_table) {
                        g_hash_table_destroy(profile_cb_table);
@@ -523,7 +631,8 @@ int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
                *state = CONNECTION_WIFI_STATE_DEACTIVATED;
                break;
        case WIFI_ON:
-       case WIFI_CONNECTING:
+       case WIFI_ASSOCIATION:
+       case WIFI_CONFIGURATION:
                *state = CONNECTION_WIFI_STATE_DISCONNECTED;
                break;
        case WIFI_CONNECTED:
@@ -531,7 +640,7 @@ int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
                *state = CONNECTION_WIFI_STATE_CONNECTED;
                break;
        default :
-               CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
+               CONNECTION_LOG(CONNECTION_ERROR, "Unknown Wi-Fi state");
                return CONNECTION_ERROR_INVALID_OPERATION;
        }
 
@@ -549,7 +658,7 @@ int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
        }
 
        if (ethernet_profiles.count == 0) {
-               state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
+               *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
                return CONNECTION_ERROR_NONE;
        }
 
@@ -566,6 +675,7 @@ int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
                *state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
                break;
        default:
+               __libnet_clear_profile_list(&ethernet_profiles);
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
@@ -647,60 +757,167 @@ done:
 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
 {
        int count = 0;
-       int rv;
+       int rv1, rv2, rv3, rv4;
        net_profile_info_t *profiles = NULL;
 
-       struct _profile_list_s all_profiles = {0, 0, NULL};
+       struct _profile_list_s wifi_profiles = {0, 0, NULL};
+       struct _profile_list_s cellular_profiles = {0, 0, NULL};
+       struct _profile_list_s ethernet_profiles = {0, 0, NULL};
+       struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
 
        __libnet_clear_profile_list(&profile_iterator);
 
-       rv = net_get_profile_list(NET_DEVICE_MAX, &all_profiles.profiles, &all_profiles.count);
+       rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
+       if (rv1 == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
 
-       if (rv != NET_ERR_NONE) {
-               if (rv == NET_ERR_NO_SERVICE) {
-                       *profile_iter_h = &profile_iterator;
-                       return CONNECTION_ERROR_NONE;
-               } else
-                       return CONNECTION_ERROR_OPERATION_FAILED;
+       CONNECTION_LOG(CONNECTION_INFO, "Wi-Fi profile count: %d", wifi_profiles.count);
+
+       rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
+       if (rv2 == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               __libnet_clear_profile_list(&wifi_profiles);
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
+               __libnet_clear_profile_list(&wifi_profiles);
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+       CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count: %d", cellular_profiles.count);
+
+       rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, &ethernet_profiles.profiles, &ethernet_profiles.count);
+       if (rv3 == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               __libnet_clear_profile_list(&wifi_profiles);
+               __libnet_clear_profile_list(&cellular_profiles);
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
+               __libnet_clear_profile_list(&wifi_profiles);
+               __libnet_clear_profile_list(&cellular_profiles);
+               return CONNECTION_ERROR_OPERATION_FAILED;
        }
+       CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d", ethernet_profiles.count);
+
+       rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
+       if (rv4 == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+               __libnet_clear_profile_list(&wifi_profiles);
+               __libnet_clear_profile_list(&cellular_profiles);
+               __libnet_clear_profile_list(&ethernet_profiles);
+               return CONNECTION_ERROR_PERMISSION_DENIED;
+       } else if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
+               __libnet_clear_profile_list(&wifi_profiles);
+               __libnet_clear_profile_list(&cellular_profiles);
+               __libnet_clear_profile_list(&ethernet_profiles);
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+       CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
 
        *profile_iter_h = &profile_iterator;
 
        switch (type) {
        case CONNECTION_ITERATOR_TYPE_REGISTERED:
-               count = all_profiles.count;
-               CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d\n", count);
-
+               count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count;
+               CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
 
-               profile_iterator.profiles = all_profiles.profiles;
+               profiles = g_try_new0(net_profile_info_t, count);
+               if (profiles == NULL) {
+                       __libnet_clear_profile_list(&wifi_profiles);
+                       __libnet_clear_profile_list(&cellular_profiles);
+                       __libnet_clear_profile_list(&ethernet_profiles);
+                       __libnet_clear_profile_list(&bluetooth_profiles);
+                       return CONNECTION_ERROR_OUT_OF_MEMORY;
+               }
+
+               profile_iterator.profiles = profiles;
+
+               if (wifi_profiles.count > 0) {
+                       memcpy(profiles, wifi_profiles.profiles,
+                                       sizeof(net_profile_info_t) * wifi_profiles.count);
+                       profiles += wifi_profiles.count;
+               }
+
+               if (cellular_profiles.count > 0) {
+                       memcpy(profiles, cellular_profiles.profiles,
+                                       sizeof(net_profile_info_t) * cellular_profiles.count);
+                       profiles += cellular_profiles.count;
+               }
+
+               if (ethernet_profiles.count > 0) {
+                       memcpy(profiles, ethernet_profiles.profiles,
+                                       sizeof(net_profile_info_t) * ethernet_profiles.count);
+                       profiles += ethernet_profiles.count;
+               }
+
+               if (bluetooth_profiles.count > 0)
+                       memcpy(profiles, bluetooth_profiles.profiles,
+                                       sizeof(net_profile_info_t) * bluetooth_profiles.count);
 
                break;
        case CONNECTION_ITERATOR_TYPE_CONNECTED:
-               count = __libnet_get_connected_count(&all_profiles);
-               CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d\n", count);
-
+               count = __libnet_get_connected_count(&wifi_profiles);
+               count += __libnet_get_connected_count(&cellular_profiles);
+               count += __libnet_get_connected_count(&ethernet_profiles);
+               count += __libnet_get_connected_count(&bluetooth_profiles);
+               CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
 
                profiles = g_try_new0(net_profile_info_t, count);
                if (profiles == NULL) {
-                       __libnet_clear_profile_list(&all_profiles);
+                       __libnet_clear_profile_list(&wifi_profiles);
+                       __libnet_clear_profile_list(&cellular_profiles);
+                       __libnet_clear_profile_list(&ethernet_profiles);
+                       __libnet_clear_profile_list(&bluetooth_profiles);
                        return CONNECTION_ERROR_OUT_OF_MEMORY;
+               }
+
+               profile_iterator.profiles = profiles;
+
+               if (wifi_profiles.count > 0)
+                       __libnet_copy_connected_profile(&profiles, &wifi_profiles);
+
+               if (cellular_profiles.count > 0)
+                       __libnet_copy_connected_profile(&profiles, &cellular_profiles);
+
+               if (ethernet_profiles.count > 0)
+                       __libnet_copy_connected_profile(&profiles, &ethernet_profiles);
+
+               if (bluetooth_profiles.count > 0)
+                       __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
+
                break;
        case CONNECTION_ITERATOR_TYPE_DEFAULT:
-                       /* To do : Not supported yet */
-               break;
+               count = __libnet_get_default_count(&cellular_profiles);
+               CONNECTION_LOG(CONNECTION_INFO, "Total default profile count : %d", count);
+               if (count == 0)
+                       return CONNECTION_ERROR_NONE;
+
+               profiles = g_try_new0(net_profile_info_t, count);
+               if (profiles == NULL) {
+                       __libnet_clear_profile_list(&wifi_profiles);
+                       __libnet_clear_profile_list(&cellular_profiles);
+                       __libnet_clear_profile_list(&ethernet_profiles);
+                       __libnet_clear_profile_list(&bluetooth_profiles);
+                       return CONNECTION_ERROR_OUT_OF_MEMORY;
                }
 
                profile_iterator.profiles = profiles;
 
-               __libnet_copy_connected_profile(&profiles, &all_profiles);
-
-               __libnet_clear_profile_list(&all_profiles);
+               if (cellular_profiles.count > 0)
+                       __libnet_copy_default_profile(&profiles, &cellular_profiles);
+               break;
        }
 
+       __libnet_clear_profile_list(&wifi_profiles);
+       __libnet_clear_profile_list(&cellular_profiles);
+       __libnet_clear_profile_list(&ethernet_profiles);
+       __libnet_clear_profile_list(&bluetooth_profiles);
+
        profile_iterator.count = count;
 
        return CONNECTION_ERROR_NONE;
@@ -784,7 +1001,8 @@ int _connection_libnet_reset_profile(connection_reset_option_e type,
        return CONNECTION_ERROR_NONE;
 }
 
-int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void* user_data)
+int _connection_libnet_open_profile(connection_profile_h profile,
+               connection_opened_cb callback, void* user_data)
 {
        int rv;
 
@@ -807,14 +1025,18 @@ int _connection_libnet_open_profile(connection_profile_h profile, connection_ope
        return CONNECTION_ERROR_NONE;
 }
 
-int _connection_libnet_get_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h *profile)
+int _connection_libnet_get_cellular_service_profile(
+               connection_cellular_service_type_e type, connection_profile_h *profile)
 {
-       int i = 0;
-       int j = 0;
+       int i = 0, j = 0;
        int rv = NET_ERR_NONE;
-       net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
+#if defined TIZEN_DUALSIM_ENABLE
+       int default_subscriber_id = 0;
+       char subscriber_id[3];
+#endif
 
-       struct _profile_list_s cellular_profiles = {0, 0, NULL};
+       struct _profile_list_s cellular_profiles = { 0, 0, NULL };
+       net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type);
 
        rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
        if (rv == NET_ERR_ACCESS_DENIED) {
@@ -825,16 +1047,37 @@ int _connection_libnet_get_cellular_service_profile(connection_cellular_service_
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
-       for (;i < cellular_profiles.count;i++)
-               if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
-                       break;
+#if defined TIZEN_DUALSIM_ENABLE
+       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");
+               __libnet_clear_profile_list(&cellular_profiles);
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
 
-       if (i >= cellular_profiles.count)
+       g_snprintf(subscriber_id, sizeof(subscriber_id), "%d", default_subscriber_id);
+#endif
+
+       for (i = 0; i < cellular_profiles.count; i++)
+               if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
+#if defined TIZEN_DUALSIM_ENABLE
+                       if (g_str_has_suffix(
+                                       cellular_profiles.profiles[i].ProfileInfo.Pdp.PSModemPath,
+                                       subscriber_id) == TRUE)
+#endif
+                               break;
+
+       if (i >= cellular_profiles.count) {
+               __libnet_clear_profile_list(&cellular_profiles);
                return CONNECTION_ERROR_OPERATION_FAILED;
+       }
 
        *profile = g_try_malloc0(sizeof(net_profile_info_t));
-       if (*profile == NULL)
+       if (*profile == NULL) {
+               __libnet_clear_profile_list(&cellular_profiles);
                return CONNECTION_ERROR_OUT_OF_MEMORY;
+       }
 
        memcpy(*profile, &cellular_profiles.profiles[i], sizeof(net_profile_info_t));
 
@@ -845,7 +1088,7 @@ int _connection_libnet_get_cellular_service_profile(connection_cellular_service_
            type != CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
                goto done;
 
-       for (;j < cellular_profiles.count;j++) {
+       for (j = 0; j < cellular_profiles.count; j++) {
                if (i == j)
                        continue;
 
@@ -859,6 +1102,7 @@ int _connection_libnet_get_cellular_service_profile(connection_cellular_service_
        }
 
 done:
+       __libnet_clear_profile_list(&cellular_profiles);
        prof_handle_list = g_slist_append(prof_handle_list, *profile);
 
        return CONNECTION_ERROR_NONE;
@@ -869,7 +1113,7 @@ int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_ser
        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;
        }
 
@@ -897,7 +1141,7 @@ int _connection_libnet_set_cellular_service_profile_async(connection_cellular_se
        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;
        }
 
@@ -926,7 +1170,7 @@ int _connection_libnet_close_profile(connection_profile_h profile, connection_cl
        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;
        }
 
@@ -939,9 +1183,6 @@ int _connection_libnet_close_profile(connection_profile_h profile, connection_cl
        } 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;
-
        __libnet_set_closed_cb(callback, user_data);
 
        return CONNECTION_ERROR_NONE;
@@ -1112,8 +1353,9 @@ bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
 
        profile_cb_info->callback = callback;
        profile_cb_info->user_data = user_data;
+       profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState);
 
-       g_hash_table_insert(profile_cb_table, profile_name, profile_cb_info);
+       g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info);
 
        return true;
 }
@@ -1121,6 +1363,7 @@ bool _connection_libnet_add_to_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;
+
        if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
                return true;