Update
authornshero.lee <nshero.lee@samsung.com>
Wed, 20 Dec 2017 17:11:38 +0000 (02:11 +0900)
committernshero.lee <nshero.lee@samsung.com>
Wed, 20 Dec 2017 17:11:38 +0000 (02:11 +0900)
Signed-off-by: nshero.lee <nshero.lee@samsung.com>
include/setup_network.h
src/CMakeLists.txt
src/adaptor.c
src/input_file.c
src/setup_network.c

index 169e74c58f2d223e92136f9ee80875227279eec5..8be4b2e135d393918728d71cc26ea9ba97c79e75 100644 (file)
@@ -17,7 +17,9 @@
 #define __SETUP_NETWORK_H__
 
 typedef enum {
-       NETWORK_WIFI_STATE_DEACTIVATED = 0,
+       NETWORK_WIFI_STATE_DEINIT,
+       NETWORK_WIFI_STATE_DEACTIVATING,
+       NETWORK_WIFI_STATE_DEACTIVATED,
        NETWORK_WIFI_STATE_ACTIVATING,
        NETWORK_WIFI_STATE_ACTIVATED,
        NETWORK_WIFI_STATE_SCANNING,
@@ -33,7 +35,7 @@ typedef enum {
  * @param     conn_type                        [out] type of connection
  * @return    int               return of function
  */
-int sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type);
+sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type);
 
 /**
  * @fn        int sa_network_set_connection(sa_network_s *info)
index e8dc39c85bd0a1e44a7873f4c82bfd6fce3ab329..2b9918e400c643fac84eaf7c2726b68eacba13a7 100644 (file)
@@ -6,7 +6,6 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pbus_pkgs REQUIRED dlog glib-2.0 capi-network-wifi-manager capi-network-connection json-c)
 
-
 INCLUDE_DIRECTORIES(${pbus_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${pbus_pkgs_LIBRARY_DIRS})
 
index 3c6f65343d4967302123bd4af8da1201969f5948..2c145489887931a21668d4b0ab04e23b99d89326 100644 (file)
@@ -77,50 +77,56 @@ static void __print_config_info(sa_config_s *config)
        if (config != NULL) {
                if (config->version != NULL)
                        _D("Version [%s]", config->version);
-               network = config->networkData;
-               if (network != NULL) {
-                       wifi = network->wifi;
-                       if (wifi != NULL) {
-                               _D("Network::wifi::enabled[%d]", wifi->enabled);
-                               _D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled);
-                               if (wifi->ssid != NULL)
-                                       _D("Network::wifi::ssid[%s]", wifi->ssid);
-                               if (wifi->password != NULL)
-                                       _D("Network::wifi::password[%s]", wifi->password);
-
-                               if (wifi->dhcpEnabled == 0)
-                                       __print_config_network_static_info(wifi->staticInfo);
-                       }
+                       network = config->networkData;
+                       if (network != NULL) {
+                               wifi = network->wifi;
+                               if (wifi != NULL) {
+                                       _D("Network::wifi::enabled[%d]", wifi->enabled);
+                                       _D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled);
+                                       if (wifi->ssid != NULL)
+                                               _D("Network::wifi::ssid[%s]", wifi->ssid);
+                                       if (wifi->password != NULL)
+                                               _D("Network::wifi::password[%s]", wifi->password);
+
+                                       if (wifi->dhcpEnabled == 0)
+                                               __print_config_network_static_info(wifi->staticInfo);
+                               }
 
-                       eth = network->eth;
-                       if (eth != NULL) {
-                               _D("Network::eth::enabled[%d]", eth->enabled);
-                               _D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
+                               eth = network->eth;
+                               if (eth != NULL) {
+                                       _D("Network::eth::enabled[%d]", eth->enabled);
+                                       _D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
 
-                               if (eth->dhcpEnabled == 0)
-                                       __print_config_network_static_info(wifi->staticInfo);
+                                       if (eth->dhcpEnabled == 0)
+                                               __print_config_network_static_info(wifi->staticInfo);
+                               }
                        }
-               }
 
-               systemData = config->systemData;
-               if (systemData != NULL) {
-                       if (systemData->proxy != NULL) {
-                               _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
-                               _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
+                       systemData = config->systemData;
+                       if (systemData != NULL) {
+                               if (systemData->proxy != NULL) {
+                                       _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
+                                       _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
+                               }
                        }
-               }
        }
 }
 
 static void __release_network_resource(sa_network_s *network)
 {
        if (network != NULL) {
-               if (network->wifi != NULL)
-                       free(network->wifi->staticInfo);
+               if (network->wifi != NULL) {
+                       if (network->wifi->staticInfo != NULL)
+                               free(network->wifi->staticInfo);        
+                       
+                       free(network->wifi);
+               }
 
                if (network->eth != NULL) {
                        if (network->eth->staticInfo != NULL)
                                free(network->eth->staticInfo);
+
+                       free(network->eth);
                }
 
                free(network);
@@ -178,65 +184,92 @@ static int __compare_network_info(sa_network_s *devNetwork, sa_network_s *newNet
        // compare wifi
        // wifi has higher priority to compare. 
        // If wifi info is changed, it doesn't have to compare ethernet info
-       if (devNetwork->wifi != NULL && newNetwork->wifi != NULL) {
+       if (newNetwork->wifi != NULL) {
                if (newNetwork->wifi->enabled == TRUE) {
-                       // check ssid/password only
-                       if (strcmp(devNetwork->wifi->ssid, newNetwork->wifi->ssid)) {
-                               needChange = TRUE;
-                       }
-
-                       if (needChange == FALSE && strcmp(devNetwork->wifi->password, newNetwork->wifi->password)) {
+                       // in case of using wifi / check dev wifi
+                       if (devNetwork->wifi != NULL) {
+                               if (newNetwork->wifi->enabled == TRUE) {
+                                       // check ssid/password only
+                                       if (strcmp(devNetwork->wifi->ssid, newNetwork->wifi->ssid)) {
+                                               needChange = TRUE;
+                                       }
+
+                                       if (needChange == FALSE && strcmp(devNetwork->wifi->password, newNetwork->wifi->password)) {
+                                               needChange = TRUE;
+                                       }
+                                       // TBD for checking other members such as, ipaddress, dns, gateway....
+                               }
+                       } else {
                                needChange = TRUE;
                        }
-                       // TBD for checking other members such as, ipaddress, dns, gateway....
                }
        }
 
        
-       if (needChange == FALSE && (devNetwork->eth != NULL && newNetwork->eth != NULL)) {
+       if (needChange == FALSE && newNetwork->eth != NULL) {
                if (newNetwork->eth->enabled == TRUE) {
-                       // check ip address only
-                       if (devNetwork->eth->staticInfo != NULL && newNetwork->eth->staticInfo != NULL) {
-                               if (strcmp(devNetwork->eth->staticInfo->ipAddress, newNetwork->eth->staticInfo->ipAddress)) {
-                                       needChange = TRUE;
+                       if (devNetwork->eth != NULL) {
+                               // check ip address only
+                               if (devNetwork->eth->staticInfo != NULL && newNetwork->eth->staticInfo != NULL) {
+                                       if (strcmp(devNetwork->eth->staticInfo->ipAddress, newNetwork->eth->staticInfo->ipAddress)) {
+                                               needChange = TRUE;
+                                       }
                                }
+                       } else {
+                               needChange = TRUE;
                        }
                }
        }
        
-
        return needChange;      
 }
 
 static int __set_network(sa_network_s *network)
 {
-       sa_network_s *currentNetwork = NULL;
+       sa_network_s currentNetwork = {0,};
        sa_error_e ret = SA_ERROR_NONE;
        sa_network_type_e conn_type;
        sa_network_state_e conn_state;
 
-       if (network != NULL) {
+       if (network == NULL) {
+               _E("__set_network is null");
                return -1;
        }
        // 1. check network state
        // 2. if it is connected, read detail info
        ret = sa_network_get_state(&conn_state, &conn_type);
        if (ret == SA_ERROR_NONE) {
-               _D("Device Network : Type[%d][%s] State[%d][%s]", conn_type, __print_connection_type(conn_type), conn_state, __print_connection_state(conn_state));
+               _D("Device Network : T[%s] S[%s]", __print_connection_type(conn_type), __print_connection_state(conn_state));
                if (conn_state == SA_NETWORK_STATE_CONNECTED) {
                // read current network info
-                       ret = sa_network_get_connection(currentNetwork);
-                       if (ret == SA_ERROR_NONE && currentNetwork != NULL) {
+                       ret = sa_network_get_connection(&currentNetwork);
+                       if (ret == SA_ERROR_NONE) {
                                // compare network info
-                               if (__compare_network_info(currentNetwork, network)) {
+                               if (__compare_network_info(&currentNetwork, network)) {
                                        // set network connection
+                                       _D("Set Network Connection !!");
                                        ret = sa_network_set_connection(network);
                                }
                        } else {
-                               _E("__get_current_network_info return error [%d]", ret);
+                               _E("__get_current_network_info return error");
+                       }
+
+                       if (currentNetwork.wifi != NULL) {
+                               if (currentNetwork.wifi->staticInfo != NULL)
+                                       free(currentNetwork.wifi->staticInfo);
+                               
+                               free(currentNetwork.wifi);
+                       }
+
+                       if (currentNetwork.eth != NULL) {
+                               if (currentNetwork.eth->staticInfo != NULL)
+                                       free(currentNetwork.eth->staticInfo);
+
+                               free(currentNetwork.eth);
                        }
                } else {
                        // in case of disconnect state
+                       _D("Set Network Connection !!");
                        ret = sa_network_set_connection(network);
                }
        } 
@@ -269,13 +302,16 @@ static int __set_system(sa_system_s *system)
        sa_proxy_s *devProxy = NULL;
        sa_error_e ret = SA_ERROR_NONE;
 
-       if (system != NULL) {
-               if (system->proxy != NULL) {
-                       ret = sa_system_get_proxy(devProxy);
-                       if (ret == SA_ERROR_NONE && compare_proxy_info(devProxy, system->proxy)) {
-                               // set proxy
-                               ret = sa_system_set_proxy(system->proxy);
-                       }
+       if (system == NULL) {
+               _E("__set_system is null");
+               return -1;
+       }
+       
+       if (system->proxy != NULL) {
+               ret = sa_system_get_proxy(devProxy);
+               if (ret == SA_ERROR_NONE && compare_proxy_info(devProxy, system->proxy)) {
+                       // set proxy
+                       ret = sa_system_set_proxy(system->proxy);
                }
        }
 
@@ -289,14 +325,15 @@ void __monitor_file_state_cb(sa_file_state_e state, void *param1, void *param2)
        switch (state) {
        case SA_FILE_STATE_REGISTERED:
                _D("SA_FILE_STATE_REGISTERED");
-               _D("start parsing");
                if (SA_ERROR_NONE == __parsing_config(&config)) {
                        if (config.systemData != NULL) {
+                               _D("Set system data");
                                __set_system(config.systemData);
                        }
 
                        if (config.networkData != NULL) {
-                               //__set_network(config->networkData);
+                               _D("Set nework data");
+                               __set_network(config.networkData);
                        }
                        __release_config_resource(&config);
                } 
@@ -321,6 +358,7 @@ int main(int argc, char *argv[])
        //Check Config file
        if (SA_FILE_STATE_EXIST == sa_inputfile_get_config_state()) {
                // Register callback to receive file change event
+               sleep(10);
                ret = sa_inputfile_register_cb(__monitor_file_state_cb);
                if (ret != SA_ERROR_NONE) {
                        _E("__init_event_listener error [%d]", ret);
@@ -329,9 +367,9 @@ int main(int argc, char *argv[])
                _D("config file is not existed, setup-adaptor exit");
        }
 
-       _D("main thread end");
        while(1) {
                sleep(1);
        }
+
        return 0;
 }
\ No newline at end of file
index d08897a46d8f80f63a8de8aedf118e4c1515cc2a..4eb35134fdd436626321ef6503b1c0d06d99373b 100644 (file)
@@ -89,12 +89,13 @@ static void *__config_main_loop(void *arg)
                                                }
                                        }
                                } else if (event->mask & IN_MODIFY) {
-                                       if (event->mask & IN_ISDIR)
+                                       if (event->mask & IN_ISDIR) {
                                                _D("The directory %s was modified", event->name);
+                                       }
                                        else {
-                                               _D("The file %s was modified", event->name);
                                                if (!strcmp(event->name, CONFIG_NAME)) {
-                                                       _D("config.json is modifued!!");
+                                                       _D("config.json is modified!!");
+                                                       callback(SA_FILE_STATE_CHANGED, NULL, NULL);
                                                }
                                        }
                                }
index b4c04e5094babe60bf8b858b06daee75460fee61..06ee7cf97dbba99f41d081b05f26c884d1b3f5ff 100644 (file)
 #include "net_connection.h"
 #include "wifi-manager.h"
 
-static int initialize_setup_network_flag;
-static sa_network_state_e setup_network_wifi_state; 
-static char wifi_password[99+1];
-static connection_h connection_handle = NULL;
-static wifi_manager_h *wifi_handle = NULL;
+
+char wifi_password[99+1];
+int initialize_setup_network_flag;
+sa_network_state_e setup_network_wifi_state; 
+connection_h connection_handle = NULL;
+wifi_manager_h wifi_handle = NULL;
 
 static int __get_setup_network_initialized(void)
 {
        return initialize_setup_network_flag;
 }
 
-static void __set_setup_network_wifi_state(sa_network_state_e val)
+static int __set_setup_network_initialized(int val)
 {
        if (val != __get_setup_network_initialized()) {
-               setup_network_wifi_state = val;
+               initialize_setup_network_flag = val;
        }
 }
 
@@ -45,6 +46,13 @@ static int __get_setup_network_wifi_state(void)
        return setup_network_wifi_state;
 }
 
+static void __set_setup_network_wifi_state(sa_network_state_e val)
+{
+       if (val != __get_setup_network_wifi_state()) {
+               setup_network_wifi_state = val;
+       }
+}
+
 static void __set_setup_network_wifi_password(char *password)
 {
        if (strcmp(wifi_password, password)) {
@@ -221,16 +229,20 @@ static void __activated_callback(wifi_manager_error_e result, void *user_data)
 }
 
 static void __scan_request_callback(wifi_manager_error_e error_code, void* user_data)
-{
-       __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATED);
-
-       if (error_code == WIFI_MANAGER_ERROR_NONE) {
-               __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNED);
-               _D("Scan Completed from scan request");
-       }
-       else
-               _D("Wi-Fi Scan Failed! error : %s", __print_wifi_error(error_code));
+{      
+       if (user_data != NULL)
+               _D("user_data : %s", (char *)user_data);
                
+       _D("Scan Completed from scan request [%s]", __print_wifi_error(error_code));
+}
+
+static void __deactivated_callback(wifi_manager_error_e result, void* user_data)
+{
+       if (result == WIFI_MANAGER_ERROR_NONE) {
+               __set_setup_network_wifi_state(NETWORK_WIFI_STATE_DEACTIVATED);
+               _D("Wi-Fi Deactivation Succeeded");
+       } else
+               _D("Wi-Fi Deactivation Failed! error : %s", __print_wifi_error(result));
 }
 
 static int __compare_ap_name(const char *ap_name, const char *ap_name_part)
@@ -253,6 +265,14 @@ static void __connected_callback(wifi_manager_error_e result, void *user_data)
                _D("Wi-Fi Connection Failed! error : %s", __print_wifi_error(result));
 }
 
+static void __scan_changed_callback(wifi_manager_scan_state_e state, void* user_data)
+{
+       _D("Scan changed, scan state : %d", state);
+       if (state == WIFI_MANAGER_SCAN_STATE_NOT_SCANNING) {
+               __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNED);
+       }
+}
+
 static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
 {
        int rv = 0;
@@ -300,62 +320,114 @@ static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
        return;
 }
 
+static int __start_setup_network(void) 
+{
+       int err_code = 0;
+
+       err_code = wifi_manager_initialize(&wifi_handle);
+       if (err_code == WIFI_MANAGER_ERROR_NONE ||
+               err_code == WIFI_MANAGER_ERROR_ALREADY_INITIALIZED) {
+               if (connection_handle != NULL) {
+                       err_code = connection_destroy(connection_handle);
+                       _D("connection handle was already created [%s]", __print_error(err_code));
+               } else {
+                       err_code = connection_create(&connection_handle);
+                       if (err_code != CONNECTION_ERROR_NONE) {
+                               _E("create connection handle error [%s]", __print_error(err_code));
+                               return -1;
+                       }
+               }
+               __set_setup_network_initialized(TRUE);
+       } else {
+               _E("create wifi handle error [%s]", __print_wifi_error(err_code));
+               return -1;
+       }
+
+       return 0;
+}
 
 static int __connect_wifi(sa_wifi_s *info)
 {
        int rv = 0;
        bool state = false;
-       int ret = 0;
-       sa_network_state_e wifi_state = SA_NETWORK_STATE_DISCONNECTED;
+       sa_error_e ret = SA_ERROR_UNKNOWN;
+       sa_network_state_e file_state = NETWORK_WIFI_STATE_DEACTIVATED;
 
        if (info == NULL) {
                return -1;
        }
-       
+
        // if wifi is already connected, it would be diconnected
+       __set_setup_network_wifi_state(NETWORK_WIFI_STATE_DEACTIVATED);
+
        while(NETWORK_WIFI_STATE_CONNECTED != __get_setup_network_wifi_state()) {
+
+               _D("Enter while [%d]", __get_setup_network_wifi_state());
+
                // check wifi state whether it is activated or not
-               if (NETWORK_WIFI_STATE_DEACTIVATED == __get_setup_network_wifi_state()) {
+               switch(__get_setup_network_wifi_state()) {
+               case NETWORK_WIFI_STATE_DEACTIVATED:
+                       _D("deativated state");
                        rv = wifi_manager_is_activated(wifi_handle, &state);
                        if (rv != WIFI_MANAGER_ERROR_NONE) {
-                               printf("Fail to get Wi-Fi device state [%s]", __print_wifi_error(rv));
+                               _D("Fail to get Wi-Fi device state [%s]", __print_wifi_error(rv));
+                               ret = SA_ERROR_UNKNOWN;
                                break;
                        }
-                       __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATING);
-                       rv = wifi_manager_activate(wifi_handle, __activated_callback, NULL);
-                       if (rv != WIFI_MANAGER_ERROR_NONE) {
-                               printf("Fail to activate Wi-Fi device [%s]", __print_wifi_error(rv));
-                               break;
+                       
+                       if (state == FALSE) {
+                               _D("ativating state");
+                               rv = wifi_manager_activate(wifi_handle, __activated_callback, NULL);
+                               __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATING);
+                               if (rv == WIFI_MANAGER_ERROR_NONE ||
+                                       rv == CONNECTION_ERROR_NOW_IN_PROGRESS ||
+                                       rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
+                                       ;
+                               } else {
+                                       _D("First activate Wi-Fi device [%s]", __print_wifi_error(rv));
+                                       break;
+                               }
+                       } else {
+                               _D("Already Activated");
+                               __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATED);
                        }
-               }
-               
-               if (NETWORK_WIFI_STATE_ACTIVATED == __get_setup_network_wifi_state()) {
-                       // scan ap
-                       __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNING);
-                       rv = wifi_manager_scan(wifi_handle, __scan_request_callback, NULL);
+                       break;
+               case NETWORK_WIFI_STATE_ACTIVATED:
+                       _D("ativated state");
 
+                       rv = wifi_manager_scan(wifi_handle, __scan_request_callback, NULL);
+                       __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNING);
+                       _D("scanning state");
                        if (rv != WIFI_MANAGER_ERROR_NONE) {
                                _D("Scan request failed [%s]", __print_wifi_error(rv));
+                               ret = SA_ERROR_UNKNOWN;
                                break;
+                       } else {
+                               _D("scan request succeeded");
                        }
-               }
-               
-               if (NETWORK_WIFI_STATE_SCANNED == __get_setup_network_wifi_state()) {
+                       break;
+               case NETWORK_WIFI_STATE_SCANNED:                
                        // connecting
+                       _D("scanned state");
                        __set_setup_network_wifi_state(NETWORK_WIFI_STATE_CONNECTING);
                        __set_setup_network_wifi_password(info->password);
+                       _D("connecting state");
                        rv = wifi_manager_foreach_found_ap(wifi_handle, __found_connect_ap_callback, info->ssid);
 
                        if (rv != WIFI_MANAGER_ERROR_NONE) {
                                _D("Fail to connect (can't get AP list) [%s]", __print_wifi_error(rv));
+                               ret = SA_ERROR_UNKNOWN;
                                break;
                        }
-               }       
+                       break;
+               default:
+                       break; 
+               }
 
                sleep(1);       
        }
 
-       return rv;
+       return ret;
 }
 
 static int __connect_ethernet(sa_eth_s *info)
@@ -376,23 +448,6 @@ static int __connect_ethernet(sa_eth_s *info)
        return 0;
 }
 
-static int __start_setup_network(void) 
-{
-       int ret = 0;
-       int err_code = 0;
-
-       err_code = wifi_manager_initialize(wifi_handle);
-       if (err_code == WIFI_MANAGER_ERROR_NONE) {
-               err_code = connection_create(&connection_handle);
-               if (err_code != CONNECTION_ERROR_NONE)
-                       return -1;
-       } else {
-               return -1;
-       }
-
-       return 0;
-}
-
 static int __get_wifi_info(sa_wifi_s *info)
 {
        int rv = 0;
@@ -417,7 +472,7 @@ static int __get_wifi_info(sa_wifi_s *info)
        free(ap_name);
        wifi_manager_ap_destroy(ap_h);
 
-       return rv;
+       return 0;
 }
 
 static int __get_ethernet_info(sa_eth_s *info) {
@@ -433,14 +488,17 @@ static int __get_ethernet_info(sa_eth_s *info) {
                        return -1;
                }
                _D("IPv4 address : %s", ip_addr);
-               memcpy(info->staticInfo->ipAddress, ip_addr, MIN(strlen(ip_addr), sizeof(info->staticInfo->ipAddress)-1));
+               info->staticInfo = (sa_network_static_s *)malloc(sizeof(sa_network_static_s));
+               if (info->staticInfo != NULL) {
+                       memcpy(info->staticInfo->ipAddress, ip_addr, MIN(strlen(ip_addr), sizeof(info->staticInfo->ipAddress)-1));
+               }
                free(ip_addr);
        }
 
-       return rv;
+       return 0;
 }
 
-int sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type)
+sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type)
 {
        sa_error_e ret = SA_ERROR_UNKNOWN;
        connection_type_e net_state;
@@ -450,6 +508,7 @@ int sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn
        if (!__get_setup_network_initialized()) {
                if(__start_setup_network()) {
                        _E("not ready to use network api due to async reply from network api");
+                       return SA_ERROR_NOT_AVAILABLE;
                }
        }
        // check network state(eth/wifi)
@@ -514,15 +573,19 @@ sa_error_e sa_network_set_connection(sa_network_s *info)
                                        retEth = __connect_ethernet(info->eth);
                                }       
                        }*/
+               } else {
+                       _D("wifi enabled flag is false");
                }
        }
+
+       _D("End setting");
                
-       return 0;
+       return ret;
 }
 
 sa_error_e sa_network_get_connection(sa_network_s *info)
 {
-       sa_error_e ret;
+       sa_error_e ret = SA_ERROR_NONE;
        connection_type_e net_state;
        connection_wifi_state_e wifi_state;
        sa_network_state_e conn_state;
@@ -535,27 +598,31 @@ sa_error_e sa_network_get_connection(sa_network_s *info)
                }
        }
        // get network state
-       rv = connection_get_type(connection_handle, &net_state);
-       if (rv != CONNECTION_ERROR_NONE) {
-               // get detail information
-               if (CONNECTION_TYPE_WIFI == net_state) {
-                       // check wifi state
-                       if (!__check_wifi_state(connection_handle, wifi_state)) {
-                               if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
-                                       // detail info for wifi
-                                       info->wifi = (sa_wifi_s *)malloc(sizeof(sa_wifi_s));
-                                       if (info->wifi != NULL) {
-                                               ret = __get_wifi_info(info->wifi);
-                                       }
-                               } 
-                       }
-               } else if (CONNECTION_TYPE_ETHERNET == net_state) {
-                       // detail info for ethernet
-                       info->eth = (sa_eth_s *)malloc(sizeof(sa_eth_s));
-                       if (info->eth != NULL) {
-                               ret = __get_ethernet_info(info->eth);
-                       }
-               } 
+       if (connection_handle != NULL) {
+               rv = connection_get_type(connection_handle, &net_state);
+               if (rv == CONNECTION_ERROR_NONE) {
+                       // get detail information
+                       if (CONNECTION_TYPE_WIFI == net_state) {
+                               // check wifi state
+                               if (!__check_wifi_state(connection_handle, wifi_state)) {
+                                       if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
+                                               // detail info for wifi
+                                               info->wifi = (sa_wifi_s *)malloc(sizeof(sa_wifi_s));
+                                               if (info->wifi != NULL) {
+                                                       ret = __get_wifi_info(info->wifi);
+                                               }
+                                       } 
+                               }
+                       } else if (CONNECTION_TYPE_ETHERNET == net_state) {
+                               // detail info for ethernet
+                               info->eth = (sa_eth_s *)malloc(sizeof(sa_eth_s));
+                               if (info->eth != NULL) {
+                                       ret = __get_ethernet_info(info->eth);
+                               }
+                       } 
+               }
+       } else {
+               _E("Connection handle is null");
        }
 
        return ret;