add temporary source to test
authorjiehwan.park <jiehwan.park@samsung.com>
Thu, 21 Dec 2017 12:20:38 +0000 (21:20 +0900)
committerjiehwan.park <jiehwan.park@samsung.com>
Thu, 21 Dec 2017 12:20:38 +0000 (21:20 +0900)
Signed-off-by: jiehwan.park <jiehwan.park@samsung.com>
include/setup_network.h
packaging/setup-adaptor.service [deleted file]
packaging/setup-adaptor.spec
src/adaptor.c
src/input_file.c
src/setup_network.c

index 8be4b2e135d393918728d71cc26ea9ba97c79e75..1f8ed3477b04f821999e6d5f8243cfcd89b3d026 100644 (file)
@@ -60,4 +60,6 @@ sa_error_e sa_network_get_connection(sa_network_s *info);
  */
 sa_error_e sa_network_deactivate(void);
 
+void sa_network_test(void);
+
 #endif/* __SETUP_NETWORK_H__ */
diff --git a/packaging/setup-adaptor.service b/packaging/setup-adaptor.service
deleted file mode 100644 (file)
index fb3dd24..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-[Unit]
-Description=Setup-Adaptor daemon
-After=connman.service
-Requires=connman.service
-
-[Service]
-SmackProcessLabel=System
-Type=notify
-ExecStart=/usr/bin/setup-adaptor
-Restart=on-failure
-RestartSec=0
-
-[Install]
-WantedBy=multi-user.target
-
index 3d8e2c49783339704920200bab3f98775b3b15b9..0115439e64b1a5031362a305b591732e65a379b6 100644 (file)
@@ -7,7 +7,6 @@ ExclusiveArch: armv7l
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1:    %{name}.manifest
-Source2:    %{name}.service
 BuildRequires:  awk
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(glib-2.0)
@@ -27,7 +26,6 @@ provide setting for network and system data based on config
 %prep
 %setup -q
 cp %{SOURCE1} ./
-cp %{SOURCE2} ./
 
 %build
 export LDFLAGS+="-Wl,--as-needed"
@@ -42,24 +40,10 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %install
 %make_install
 mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants
-install -m 0644 %SOURCE2 %{buildroot}%{_unitdir}/%{name}.service
-%install_service multi-user.target.wants %{name}.service
 
 %post
-systemctl daemon-reload
-if [ $1 == 1 ]; then
-       # install
-       systemctl start %{name}.service
-elif [ $1 == 2 ]; then
-       # upgrade
-       systemctl restart %{name}.service
-fi
 
 %preun
-if [ $1 == 0 ]; then
-       # uninstall
-       systemctl stop %{name}.service
-fi
 
 %postun
 systemctl daemon-reload
@@ -69,5 +53,3 @@ systemctl daemon-reload
 %defattr(-,root,root,-)
 %license LICENSE.Apache-2.0
 %{_bindir}/%{name}
-%{_unitdir}/%{name}.service
-%{_unitdir}/multi-user.target.wants/%{name}.service
index 400c1fadb21fa448efc909fca7af1aa9727378bd..7935b0cdb9e29305b22a0f8ed9c5c3923b2626d9 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <glib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -238,7 +239,7 @@ static int __set_network(sa_network_s *network)
        // 1. check network state
        // 2. if it is connected, read detail info
        ret = sa_network_get_state(&conn_state, &conn_type);
-
+       _D("sa_network_get_state return(%d)", ret);
        if (ret == SA_ERROR_NONE) {
                _D("Device Network : T[%s] S[%s]", __print_connection_type(conn_type), __print_connection_state(conn_state));
                if (conn_state == SA_NETWORK_STATE_CONNECTED) {
@@ -323,6 +324,9 @@ static int __set_system(sa_system_s *system)
 void __monitor_file_state_cb(sa_file_state_e state, void *param1, void *param2)
 {
        sa_config_s config = {0,};      
+       _D("******************__monitor_file_state_cb ******************");
+
+       //sa_network_test();
 
        switch (state) {
        case SA_FILE_STATE_REGISTERED:
@@ -355,18 +359,18 @@ int main(int argc, char *argv[])
 {      
        sa_error_e ret = SA_ERROR_NONE;
 
+       GMainLoop *mainloop;
+       mainloop = g_main_loop_new(NULL, FALSE);
+
        _D("start setup-adaptor");
        //Check Config file
        if (SA_FILE_STATE_EXIST == sa_inputfile_get_config_state()) {
                // Waiting for booting
-               sleep(10);
+               sleep(1);
                // Register callback to receive file change event
                ret = sa_inputfile_register_cb(__monitor_file_state_cb);
                if (ret == SA_ERROR_NONE) {
                        // Keep checking callback from input
-                       while(1) {
-                               sleep(1);
-                       }
                } else {
                        _E("__init_event_listener error [%d]", ret);
                }
@@ -374,5 +378,6 @@ int main(int argc, char *argv[])
                _D("config file is not existed, setup-adaptor exit");
        }
 
+       g_main_loop_run(mainloop);
        return 0;
 }
\ No newline at end of file
index 4eb35134fdd436626321ef6503b1c0d06d99373b..3cea729b2f95247cc5e24022c10f8bbd67fa37a7 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
+#include <glib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -39,25 +39,25 @@ static void *__config_main_loop(void *arg)
        file_state_cb callback;
        char buffer[BUF_LEN];
 
-       _D("__config_main_loop start\n");
+       printf("\n__config_main_loop start\n");
 
        callback = (file_state_cb)arg;
 
        if (callback == NULL) {
-               _E("Ccallback is null for event");
+               printf("\nCcallback is null for event");
                return NULL;
        }
 
        fd = inotify_init();
 
        if (fd < 0) {
-               _E("inotify_init error");
+               printf("\ninotify_init error");
                return NULL;
        }
 
        wd = inotify_add_watch(fd, CONFIG_FOLDER, IN_MODIFY | IN_CREATE | IN_DELETE);
        // Start callack
-       _D("Registerd Callback Triggered");
+       printf("\nRegisterd Callback Triggered");
        callback(SA_FILE_STATE_REGISTERED, NULL, NULL);
        while (1) {
                int length, i = 0;
@@ -68,33 +68,33 @@ static void *__config_main_loop(void *arg)
 
                while (i < length) {
                        struct inotify_event *event = (struct inotify_event *)&buffer[i];
-                       _D("[debug] wd=%d mask=%d cookie=%d len=%d dir=%s", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR) ? "yes" : "no");
+                       printf("\n[debug] wd=%d mask=%d cookie=%d len=%d dir=%s", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR) ? "yes" : "no");
                        if (event->len) {
                                if (event->mask & IN_CREATE) {
                                        if (event->mask & IN_ISDIR)
-                                               _D("The directory %s was created", event->name);
+                                               printf("\nThe directory %s was created", event->name);
                                        else {
-                                               _D("The file %s was create.", event->name);
+                                               printf("\nThe file %s was create.", event->name);
                                                if (!strcmp(event->name, CONFIG_NAME)) {
-                                                       _D("config.json is created!!");
+                                                       printf("\nconfig.json is created!!");
                                                }
                                        }
                                } else if (event->mask & IN_DELETE) {
                                        if (event->mask & IN_ISDIR)
-                                               _D("The directory %s was deleted.", event->name);
+                                               printf("\nThe directory %s was deleted.", event->name);
                                        else {
-                                               _D("The file %s was deleted", event->name);
+                                               printf("\nThe file %s was deleted", event->name);
                                                if (!strcmp(event->name, CONFIG_NAME)) {
-                                                       _D("config.json is deleted!!");
+                                                       printf("\nconfig.json is deleted!!");
                                                }
                                        }
                                } else if (event->mask & IN_MODIFY) {
                                        if (event->mask & IN_ISDIR) {
-                                               _D("The directory %s was modified", event->name);
+                                               printf("\nThe directory %s was modified", event->name);
                                        }
                                        else {
                                                if (!strcmp(event->name, CONFIG_NAME)) {
-                                                       _D("config.json is modified!!");
+                                                       printf("\nconfig.json is modified!!");
                                                        callback(SA_FILE_STATE_CHANGED, NULL, NULL);
                                                }
                                        }
@@ -108,20 +108,22 @@ static void *__config_main_loop(void *arg)
        inotify_rm_watch(fd, wd);
        close(fd);
 
-       pthread_exit((void *)0);
-
        return NULL;
 }
 
 static int __init_event_listener(file_state_cb callback)
 {
+#if 0
        pthread_t p_thread;
 
        // Start thread to create in order to receive event
        if (pthread_create(&p_thread, NULL, &__config_main_loop, callback) < 0) {
-               _E("__init_event_listener create error");
+               printf("\n__init_event_listener create error");
                return -1;
        }
+#else
+       __config_main_loop(callback);
+#endif
 
        return 0;
 }
@@ -182,7 +184,7 @@ static char *json_get_string_from_obj(json_object *inputObj, char *key)
                return NULL;
        }
 
-       _D("string object [%s]", ret_buf);
+       printf("\nstring object [%s]", ret_buf);
        return ret_buf;
 }
 static int __parse_system_proxy(json_object *inputObj, sa_system_s *system)
@@ -192,7 +194,7 @@ static int __parse_system_proxy(json_object *inputObj, sa_system_s *system)
        int ret = 0;
 
        if (inputObj == NULL || system == NULL) {
-               _E("__parse_system_proxy input error");
+               printf("\n__parse_system_proxy input error");
                return -1;
        }
 
@@ -209,7 +211,7 @@ static int __parse_system_proxy(json_object *inputObj, sa_system_s *system)
                httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
        } else {
                ret = -1;
-               _E("system->proxy malloc fail");
+               printf("\nsystem->proxy malloc fail");
        }
 
        return ret;
@@ -224,7 +226,7 @@ static int __parse_network_static_info(json_object *inputObj, sa_network_static_
        char *secondaryDnsServer = NULL;
 
        if (inputObj == NULL || staticInfo == NULL) {
-               _E("__parse_network_static_info input error");
+               printf("\n__parse_network_static_info input error");
                return -1;
        }
 
@@ -276,7 +278,7 @@ static int __parse_network_eth(json_object *inputObj, sa_eth_s *eth)
        int ret = 0;
 
        if (inputObj == NULL || eth == NULL) {
-               _E("__parse_network_eth input error");
+               printf("\n__parse_network_eth input error");
                return -1;
        }
 
@@ -293,7 +295,7 @@ static int __parse_network_eth(json_object *inputObj, sa_eth_s *eth)
                        ret = -1;
                }
        } else {
-               _D("dhcp is true");
+               printf("\ndhcp is true");
        }
 
        return ret;
@@ -306,7 +308,7 @@ static int __parse_network_wifi(json_object *inputObj, sa_wifi_s *wifi)
        int ret = 0;
 
        if (inputObj == NULL || wifi == NULL) {
-               _E("__parse_network_wifi input error");
+               printf("\n__parse_network_wifi input error");
                return -1;
        }
        // enabled
@@ -342,7 +344,7 @@ static int __parse_network_wifi(json_object *inputObj, sa_wifi_s *wifi)
                        ret = -1;
                }
        } else {
-               _D("dhcp is true");
+               printf("\ndhcp is true");
        }
 
        return ret;
@@ -355,7 +357,7 @@ static int __parse_network_data(json_object *inputObj, sa_config_s *setupConfig)
        int wifiRet = 0, ethRet = 0;
 
        if (inputObj == NULL) {
-               _E("__parse_network_data input error");
+               printf("\n__parse_network_data input error");
                return -1;
        }
 
@@ -369,7 +371,7 @@ static int __parse_network_data(json_object *inputObj, sa_config_s *setupConfig)
                                if (setupConfig->networkData->wifi != NULL) {
                                        wifiRet = __parse_network_wifi(wifiObj, setupConfig->networkData->wifi);
                                } else {
-                                       _E("network->wifi malloc fail");
+                                       printf("\nnetwork->wifi malloc fail");
                                }
                        }
                }
@@ -382,17 +384,17 @@ static int __parse_network_data(json_object *inputObj, sa_config_s *setupConfig)
                                if (setupConfig->networkData->eth != NULL) {
                                        ethRet = __parse_network_eth(ethernetObj, setupConfig->networkData->eth);
                                } else {
-                                       _E("network->eth malloc fail");
+                                       printf("\nnetwork->eth malloc fail");
                                }
                        }
                }
        } else {
-               _E("malloc fail etupConfig->networkData");
+               printf("\nmalloc fail etupConfig->networkData");
        }
 
        // if both of network interfaces are failed, it would return -1
        if (wifiRet != 0 && ethRet != 0) {
-               _E("__parse_network_data fail");
+               printf("\n__parse_network_data fail");
                return -1;
        }
        
@@ -405,7 +407,7 @@ static int __parse_system_data(json_object *inputObj, sa_config_s *setupConfig)
        int ret = 0;
        char *httpProxyHost = NULL;
        if (inputObj == NULL) {
-               _E("__parse_system_data input error");
+               printf("\n__parse_system_data input error");
                return -1;
        }
        
@@ -425,11 +427,11 @@ static int __parse_system_data(json_object *inputObj, sa_config_s *setupConfig)
 
                        } else {
                                ret = -1;
-                               _E("malloc fail setupConfig->systemData->proxy");
+                               printf("\nmalloc fail setupConfig->systemData->proxy");
                        }
                } else {
                        ret = -1;
-                       _E("malloc fail setupConfig->systemData");
+                       printf("\nmalloc fail setupConfig->systemData");
                }
        }
 
@@ -442,7 +444,7 @@ static int __parse_version(json_object *inputObj, sa_config_s *setupConfig)
        char *version = NULL;
 
        if (inputObj == NULL) {
-               _E("__parse_version input error");
+               printf("\n__parse_version input error");
                return -1;
        }
 
@@ -476,7 +478,7 @@ static int __parse_config(char *file, sa_config_s *setupConfig)
                        if (jsonData != NULL) {
                                memset(jsonData, 0x00, len + 1);
                                readLen = read(fd, jsonData, len);
-                               _D("JSON full data[%s]", jsonData);
+                               printf("\nJSON full data[%s]", jsonData);
 
                                configObj = json_tokener_parse(jsonData);
 
@@ -492,21 +494,21 @@ static int __parse_config(char *file, sa_config_s *setupConfig)
                                        }
                                } else {
                                        ret = -1;
-                                       _E("ConfigObj is not existed");
+                                       printf("\nConfigObj is not existed");
                                }
                                
                                json_object_put(configObj);
                                free(jsonData);
                        } else {
                                ret = -1;
-                               _E("memory allocation fail for jsonData");
+                               printf("\nmemory allocation fail for jsonData");
                        }
                }
 
                close(fd);
        } else {
                ret = -1;
-               _E("config file can't be opened");
+               printf("\nconfig file can't be opened");
        }
 
        return ret;
@@ -522,7 +524,7 @@ sa_error_e sa_inputfile_get_config_info(sa_config_s *config)
        // parsing and fill into struct
        ret = __parse_config(CONFIG_FILE, config);
        if (ret != 0) {
-               _E("Config parsing error");
+               printf("\nConfig parsing error");
                return SA_ERROR_PARSING;
        }
 
index c2c16ef146a8e655535b912fb3e44ead3c26aaaa..f5af9f3aa47d6c414950e1d2a9bc7ac84e547127 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <glib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -29,6 +30,256 @@ sa_network_state_e setup_network_wifi_state;
 connection_h connection_handle = NULL;
 wifi_manager_h wifi_handle = NULL;
 
+
+static void __tmp_do_connect(sa_wifi_s *info);
+
+static const char *__test_convert_error_to_string(wifi_manager_error_e err_type)
+{
+       switch (err_type) {
+       case WIFI_MANAGER_ERROR_NONE:
+               return "NONE";
+       case WIFI_MANAGER_ERROR_INVALID_PARAMETER:
+               return "INVALID_PARAMETER";
+       case WIFI_MANAGER_ERROR_OUT_OF_MEMORY:
+               return "OUT_OF_MEMORY";
+       case WIFI_MANAGER_ERROR_INVALID_OPERATION:
+               return "INVALID_OPERATION";
+       case WIFI_MANAGER_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
+               return "ADDRESS_FAMILY_NOT_SUPPORTED";
+       case WIFI_MANAGER_ERROR_OPERATION_FAILED:
+               return "OPERATION_FAILED";
+       case WIFI_MANAGER_ERROR_NO_CONNECTION:
+               return "NO_CONNECTION";
+       case WIFI_MANAGER_ERROR_NOW_IN_PROGRESS:
+               return "NOW_IN_PROGRESS";
+       case WIFI_MANAGER_ERROR_ALREADY_EXISTS:
+               return "ALREADY_EXISTS";
+       case WIFI_MANAGER_ERROR_OPERATION_ABORTED:
+               return "OPERATION_ABORTED";
+       case WIFI_MANAGER_ERROR_DHCP_FAILED:
+               return "DHCP_FAILED";
+       case WIFI_MANAGER_ERROR_INVALID_KEY:
+               return "INVALID_KEY";
+       case WIFI_MANAGER_ERROR_OUT_OF_RANGE:
+               return "OUT_OF_RANGE";
+       case WIFI_MANAGER_ERROR_PIN_MISSING:
+               return "PIN_MISSING";
+       case WIFI_MANAGER_ERROR_CONNECT_FAILED:
+               return "CONNECT_FAILED";
+       case WIFI_MANAGER_ERROR_LOGIN_FAILED:
+               return "LOGIN_FAILED";
+       case WIFI_MANAGER_ERROR_AUTHENTICATION_FAILED:
+               return "AUTH_FAILED";
+       case WIFI_MANAGER_ERROR_NO_REPLY:
+               return "NO_REPLY";
+       case WIFI_MANAGER_ERROR_SECURITY_RESTRICTED:
+               return "SECURITY_RESTRICTED";
+       case WIFI_MANAGER_ERROR_ALREADY_INITIALIZED:
+               return "ALREADY_INITIALIZED";
+       case WIFI_MANAGER_ERROR_PERMISSION_DENIED:
+               return "PERMISSION_DENIED";
+       case WIFI_MANAGER_ERROR_NOT_SUPPORTED:
+               return "NOT_SUPPORTED";
+       case WIFI_MANAGER_ERROR_WPS_OVERLAP:
+               return "WPS_OVERLAP";
+       case WIFI_MANAGER_ERROR_WPS_TIMEOUT:
+               return "WPS_TIMEOUT";
+       case WIFI_MANAGER_ERROR_WPS_WEP_PROHIBITED:
+               return "WPS_WEP_PROHIBITED";
+       default:
+               return "UNKNOWN";
+       }
+}
+
+static void __test_device_state_callback(wifi_manager_device_state_e state, void* user_data)
+{
+       printf("[%s] Device state changed callback", (char *)user_data);
+
+       if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED)
+               printf(", state : Activated\n");
+       else
+               printf(", state : Deactivated\n");
+}
+
+static void __test_scan_changed_callback(wifi_manager_scan_state_e state, void* user_data)
+{
+       printf("Scan changed, scan state : %d\n", state);
+}
+
+static void __test_bg_scan_completed_callback(wifi_manager_error_e error_code, void* user_data)
+{
+       printf("[%s] Background Scan Completed, error code : %s\n",
+                       (char *)user_data, __test_convert_error_to_string(error_code));
+}
+
+static void __test_ip_conflict_callback(char *mac, wifi_manager_ip_conflict_state_e state, void *user_data)
+{
+       if (state == WIFI_MANAGER_IP_CONFLICT_STATE_CONFLICT_DETECTED)
+               printf("[%s] Ip conflict detected : %s\n", (char *)user_data, mac);
+       else if (state == WIFI_MANAGER_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED)
+               printf("Ip conflict removed\n");
+       else
+               printf("Ip conflict state unknown\n");
+}
+
+static void __test_scan_request_callback(wifi_manager_error_e error_code, void* user_data)
+{
+       if (user_data != NULL)
+               printf("user_data : %s\n", (char *)user_data);
+
+       printf("Scan Completed from scan request, error code : %s\n",
+                       __test_convert_error_to_string(error_code));
+}
+
+static void __test_bssid_scan_request_callback(wifi_manager_error_e error_code, void *user_data)
+{
+       printf("BSSID Scan Completed, error code : %s\n",
+                       __test_convert_error_to_string(error_code));
+
+}
+
+static void __test_netlink_scan_request_callback(wifi_manager_error_e error_code, void *user_data)
+{
+       printf("Netlink Scan Completed, error code : %s\n",
+                       __test_convert_error_to_string(error_code));
+
+}
+
+static void __test_netlink_scan_specific_ap_callback(wifi_manager_error_e error_code, void *user_data)
+{
+       printf("Netlink Specific Scan Completed, error code : %s\n",
+                       __test_convert_error_to_string(error_code));
+
+}
+
+static void __test_connection_state_callback(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void* user_data)
+{
+       int rv = 0;
+       char *ap_name = NULL;
+
+       printf("[%s] Connection state changed callback", (char *)user_data);
+
+       switch (state) {
+       case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
+               printf(", state : Connected");
+               break;
+       case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
+               printf(", state : Association");
+               break;
+       case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
+               printf(", state : Configuration");
+               break;
+       case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED:
+               printf(", state : Disconnected");
+               break;
+       default:
+               printf(", state : Unknown");
+       }
+
+       rv = wifi_manager_ap_get_essid(ap, &ap_name);
+       if (rv != WIFI_MANAGER_ERROR_NONE)
+               printf(", Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
+       else {
+               printf(", AP name : %s\n", ap_name);
+       }
+}
+
+static void __test_activated_callback(wifi_manager_error_e result, void* user_data)
+{
+       if (result == WIFI_MANAGER_ERROR_NONE)
+               printf("Wi-Fi Activation Succeeded\n");
+       else
+               printf("Wi-Fi Activation Failed! error : %s\n", __test_convert_error_to_string(result));
+}
+
+static void __test_deactivated_callback(wifi_manager_error_e result, void* user_data)
+{
+       if (result == WIFI_MANAGER_ERROR_NONE)
+               printf("Wi-Fi Deactivation Succeeded\n");
+       else
+               printf("Wi-Fi Deactivation Failed! error : %s\n", __test_convert_error_to_string(result));
+}
+
+static void __test_connected_callback(wifi_manager_error_e result, void* user_data)
+{
+       if (result == WIFI_MANAGER_ERROR_NONE)
+               printf("Wi-Fi Connection Succeeded\n");
+       else
+               printf("Wi-Fi Connection Failed! error : %s\n", __test_convert_error_to_string(result));
+}
+
+static void __test_disconnected_callback(wifi_manager_error_e result, void* user_data)
+{
+       if (result == WIFI_MANAGER_ERROR_NONE)
+               printf("Wi-Fi Disconnection Succeeded\n");
+       else
+               printf("Wi-Fi Disconnection Failed! error : %s\n", __test_convert_error_to_string(result));
+}
+
+static void __test_rssi_level_callback(wifi_manager_rssi_level_e rssi_level, void* user_data)
+{
+       printf("[%s] RSSI level changed callback, level = %d\n", (char *)user_data, rssi_level);
+}
+
+static void __test_tdls_discover_callback(wifi_manager_tdls_discovery_state_e state, char *peer_mac_add, void *user_data)
+{
+       printf("[%s] TDLS discover callback", (char *)user_data);
+
+       printf(", Peer Mac Address [%s], state :%d\n", peer_mac_add, state);
+       if (state == WIFI_MANAGER_TDLS_DISCOVERY_STATE_ONGOING)
+               printf(", Discovery is ongoing");
+       else
+               printf(", Discovery is finished");
+}
+
+static void __test_get_wifi_module_state_callback(wifi_manager_module_state_e state, void *user_data)
+{
+       printf("Wi-Fi Module State Changed callback : %d", state);
+
+       if (state == WIFI_MANAGER_MODULE_STATE_ATTACHED)
+               printf(", Wi-Fi Module Attached\n");
+       else
+               printf(", Wi-Fi Module Detached\n");
+}
+
+static void __test_tdls_state_callback(wifi_manager_tdls_state_e state, char *peer_mac_add, void *user_data)
+{
+       printf("[%s] TDLS state changed callback", (char *)user_data);
+
+       if (state == WIFI_MANAGER_TDLS_STATE_CONNECTED)
+               printf(", state : TDLS Connected, Peer Mac Address [%s]\n", peer_mac_add);
+       else
+               printf(", state : TDLS Disconnected, Peer Mac Address [%s]\n", peer_mac_add);
+}
+
+static const char* __test_print_state(wifi_manager_connection_state_e state)
+{
+       switch (state) {
+       case WIFI_MANAGER_CONNECTION_STATE_FAILURE:
+               return "Failure";
+       case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED:
+               return "Disconnected";
+       case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
+               return "Association";
+       case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
+               return "Connected";
+       case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
+               return "Configuration";
+       }
+
+       return "Unknown";
+}
+
+
+
+
+
+
+
+
+
+
+
 static int __get_setup_network_initialized(void)
 {
        return initialize_setup_network_flag;
@@ -210,9 +461,9 @@ static int __check_wifi_state(connection_h connection, connection_wifi_state_e w
 
        rv = connection_get_wifi_state(connection, &wifi_state);
        if (rv != CONNECTION_ERROR_NONE) {
-               _D("Fail to get WiFi state [%s]", __print_error(rv));
+               printf("\nFail to get WiFi state [%s]", __print_error(rv));
        } else {
-               _D("Retval = [%s] WiFi state [%s]", __print_error(rv), __print_wifi_state(wifi_state));
+               printf("\nRetval = [%s] WiFi state [%s]", __print_error(rv), __print_wifi_state(wifi_state));
        }
 
        return 0;
@@ -221,28 +472,28 @@ static int __check_wifi_state(connection_h connection, connection_wifi_state_e w
 static void __activated_callback(wifi_manager_error_e result, void *user_data)
 {
        if (result == WIFI_MANAGER_ERROR_NONE) {
-               __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATED);
-               _D("Wi-Fi Activation Succeeded");
+               printf("\nMY~~~Wi-Fi Activation Succeeded");
+               __tmp_do_connect((sa_wifi_s *)user_data);
        }
        else
-               _D("Wi-Fi Activation Failed! error : %s", __print_wifi_error(result));
+               printf("\nWi-Fi Activation Failed! error : %s", __print_wifi_error(result));
 }
 
 static void __scan_request_callback(wifi_manager_error_e error_code, void* user_data)
 {      
        if (user_data != NULL)
-               _D("user_data : %s", (char *)user_data);
+               printf("\nuser_data : %s", (char *)user_data);
                
-       _D("Scan Completed from scan request [%s]", __print_wifi_error(error_code));
+       printf("\nScan 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");
+               printf("\nWi-Fi Deactivation Succeeded");
        } else
-               _D("Wi-Fi Deactivation Failed! error : %s", __print_wifi_error(result));
+               printf("\nWi-Fi Deactivation Failed! error : %s", __print_wifi_error(result));
 }
 
 static int __compare_ap_name(const char *ap_name, const char *ap_name_part)
@@ -260,14 +511,14 @@ static int __compare_ap_name(const char *ap_name, const char *ap_name_part)
 static void __connected_callback(wifi_manager_error_e result, void *user_data)
 {
        if (result == WIFI_MANAGER_ERROR_NONE)
-               _D("Wi-Fi Connection Succeeded");
+               printf("\nWi-Fi Connection Succeeded");
        else
-               _D("Wi-Fi Connection Failed! error : %s", __print_wifi_error(result));
+               printf("\nWi-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);
+       printf("\nScan changed, scan state : %d", state);
        if (state == WIFI_MANAGER_SCAN_STATE_NOT_SCANNING) {
                __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNED);
        }
@@ -281,7 +532,7 @@ static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
 
        rv = wifi_manager_ap_get_essid(ap, &ap_name);
        if (rv != WIFI_MANAGER_ERROR_NONE) {
-               _D("Fail to get AP name [%s]\n", __print_wifi_error(rv));
+               printf("\nFail to get AP name [%s]\n", __print_wifi_error(rv));
                return;
        }
 
@@ -293,10 +544,10 @@ static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
                if (rv == WIFI_MANAGER_ERROR_NONE) {
                        if (required) {
                                char *passphrase = __get_setup_network_wifi_password();
-                               _D("password : [%s]", passphrase);
+                               printf("\npassword : [%s]", passphrase);
                                rv = wifi_manager_ap_set_passphrase(ap, passphrase);
                                if (rv != WIFI_MANAGER_ERROR_NONE) {
-                                       _D("Fail to set passphrase : %s", __print_wifi_error(rv));
+                                       printf("\nFail to set passphrase : %s", __print_wifi_error(rv));
                                        if (ap_name != NULL) 
                                                free(ap_name);;
                                        return ;
@@ -305,9 +556,9 @@ static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
 
                        //rv = wifi_manager_connect(wifi, ap, __connected_callback, NULL);
                        if (rv != WIFI_MANAGER_ERROR_NONE)
-                               _D("Fail to connection request [%s] : %s", ap_name, __print_wifi_error(rv));
+                               printf("\nFail to connection request [%s] : %s", ap_name, __print_wifi_error(rv));
                        else {
-                               _D("Success to connection request [%s]", ap_name);
+                               printf("\nSuccess to connection request [%s]", ap_name);
                                __set_setup_network_wifi_state(NETWORK_WIFI_STATE_CONNECTED);
                        }
                }
@@ -324,42 +575,74 @@ 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 {
+       if (!__get_setup_network_initialized()) {
+               err_code = wifi_manager_initialize(&wifi_handle);
+               printf("\nwifi_manager_initialize ret(%s)", __print_error(err_code));
+               if (err_code == WIFI_MANAGER_ERROR_NONE ||
+                       err_code == WIFI_MANAGER_ERROR_ALREADY_INITIALIZED) {
+                       if (connection_handle != NULL) {
+                               err_code = connection_destroy(connection_handle);
+                               printf("\nconnection handle was already created [%s]", __print_error(err_code));
+                       }
+
                        err_code = connection_create(&connection_handle);
+                       printf("\nconnection_create : ret[%s]", __print_error(err_code));
                        if (err_code != CONNECTION_ERROR_NONE) {
-                               _E("create connection handle error [%s]", __print_error(err_code));
+                               printf("\ncreate connection handle error [%s]", __print_error(err_code));
                                return -1;
                        }
+                       __set_setup_network_initialized(TRUE);
+               } else {
+                       printf("\ncreate wifi handle error [%s]", __print_wifi_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 __init_wifi_handle(wifi_manager_h *wifi) {
 
-       int err_code = 0;
+void __wifi_state_changed_cb(wifi_manager_device_state_e state, void *user_data)
+{
+       printf("\n__wifi_state_changed_cb() state=[%d]", state);
 
-       err_code = wifi_manager_initialize(&wifi);
-       if (err_code == WIFI_MANAGER_ERROR_NONE ||
-               err_code == WIFI_MANAGER_ERROR_ALREADY_INITIALIZED) {
-               _D(" Create handle for wiri");
-       } else {
-               _E("create wifi handle error [%s]", __print_wifi_error(err_code));
-               return -1;
+       if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) {
+               printf("\n__wifi_state_changed_cb start scan...");
+               wifi_manager_scan(wifi_handle, __scan_request_callback, user_data);
+               wifi_manager_unset_device_state_changed_cb(wifi_handle);
        }
+}
 
-       return 0;
+static void __tmp_exit(void)
+{
+       printf("\nExit Case :: To-Do");
+}
+
+static void __tmp_do_activate(sa_wifi_s *info)
+{
+       int rv = 0;
+       sa_error_e ret = SA_ERROR_UNKNOWN;
+
+       printf("\nativating state");
+
+       wifi_manager_set_device_state_changed_cb(wifi_handle, __wifi_state_changed_cb, (void *)info);
+       rv = wifi_manager_activate(wifi_handle, __activated_callback, (void *)info);
+       printf("\nwifi_manager_activate:ret[%s]", __print_wifi_error(rv));
+}
+
+static void __tmp_do_connect(sa_wifi_s *info)
+{
+       int rv = 0;
+       
+       printf("\nscanned state");
+       __set_setup_network_wifi_password(info->password);
+       printf("\nconnecting state");
+       rv = wifi_manager_foreach_found_ap(wifi_handle, __found_connect_ap_callback, info->ssid);
+
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("\nFail to connect (can't get AP list) [%s]", __print_wifi_error(rv));
+               __tmp_exit();
+       }
 }
 
 static int __connect_wifi(sa_wifi_s *info)
@@ -369,79 +652,18 @@ static int __connect_wifi(sa_wifi_s *info)
        sa_error_e ret = SA_ERROR_UNKNOWN;
        sa_network_state_e file_state = NETWORK_WIFI_STATE_DEACTIVATED;
 
+       printf("\n------------------- __connect_wifi -------------------");
+
        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
-               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) {
-                               _D("Fail to get Wi-Fi device state [%s]", __print_wifi_error(rv));
-                               ret = SA_ERROR_UNKNOWN;
-                               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);
-                       }
-                       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");
-                       }
-                       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);       
-       }
-       
+       GMainLoop *mainloop;
+       mainloop = g_main_loop_new(NULL, FALSE);
 
+       __tmp_do_activate(info);
+       
+       g_main_loop_run(mainloop);
        return ret;
 }
 
@@ -471,18 +693,18 @@ static int __get_wifi_info(sa_wifi_s *info)
 
        rv = wifi_manager_get_connected_ap(wifi_handle, &ap_h);
        if (rv != WIFI_MANAGER_ERROR_NONE) {
-               _D("Fail to get connected AP [%s]", __print_wifi_error(rv));
+               printf("\nFail to get connected AP [%s]", __print_wifi_error(rv));
                return -1;
        }
 
        rv = wifi_manager_ap_get_essid(ap_h, &ap_name);
        if (rv != WIFI_MANAGER_ERROR_NONE) {
-               _D("Fail to get essid [%s]", __print_wifi_error(rv));
+               printf("\nFail to get essid [%s]", __print_wifi_error(rv));
                wifi_manager_ap_destroy(ap_h);
                return -1;
        }
 
-       _D("Connected AP : %s\n", ap_name);
+       printf("\nConnected AP : %s\n", ap_name);
        memcpy(info->ssid, ap_name, MIN(strlen(ap_name), sizeof(info->ssid)-1));
        free(ap_name);
        wifi_manager_ap_destroy(ap_h);
@@ -499,10 +721,10 @@ static int __get_ethernet_info(sa_eth_s *info) {
                // only for ipv4
                rv = connection_get_ip_address(connection_handle, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
                if (ip_addr == NULL) {
-                       _D("IPv4 address does not exist");
+                       printf("\nIPv4 address does not exist");
                        return -1;
                }
-               _D("IPv4 address : %s", ip_addr);
+               printf("\nIPv4 address : %s", ip_addr);
                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));
@@ -520,19 +742,22 @@ sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_
        connection_wifi_state_e wifi_state;
        int rv = 0;
 
-       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;
-               }
+       printf("\nsa_network_get_state~~~");
+
+
+       if(__start_setup_network()) {
+               printf("\nnot ready to use network api due to async reply from network api");
+               return SA_ERROR_NOT_AVAILABLE;
        }
+       
        // check network state(eth/wifi)
        rv = connection_get_type(connection_handle, &net_state);
+       printf("\nconnection_get_type return(%d)", rv);
        if (rv != CONNECTION_ERROR_NONE) {
-               printf("Fail to get network state [%s]\n", __print_error(rv));
+               printf("\nFail to get network state [%s]\n", __print_error(rv));
        } else {
                ret = SA_ERROR_NONE;
-               _D("Retval = [%s] network connection state [%s]\n", __print_error(rv), __print_connection_type(net_state));     
+               printf("\nRetval = [%s] network connection state [%s]\n", __print_error(rv), __print_connection_type(net_state));       
                if (CONNECTION_TYPE_DISCONNECTED == net_state) {
                        *conn_state = SA_NETWORK_STATE_DISCONNECTED;
                } else if (CONNECTION_TYPE_WIFI == net_state) {
@@ -568,18 +793,16 @@ sa_error_e sa_network_set_connection(sa_network_s *info)
                return SA_ERROR_INVALID_PARAMETER;
        }
 
-       if (!__get_setup_network_initialized()) {
-               if(__start_setup_network()) {
-                       _E("not ready to use network api due to async reply from network api");
-               }
+       if(__start_setup_network()) {
+               printf("\nnot ready to use network api due to async reply from network api");
        }
-
+       
        // first priority is wifi
        if (info->wifi != NULL) {
                if (info->wifi->enabled == TRUE) {
                        // wifi setting and waiting to get response
                        retWifi = __connect_wifi(info->wifi);
-                       _D("return wifi [%d]", retWifi);
+                       printf("\nreturn wifi [%d]", retWifi);
                        // or if wifi is enabled but fail to connect, try to connect eth
 
                        /*
@@ -589,11 +812,11 @@ sa_error_e sa_network_set_connection(sa_network_s *info)
                                }       
                        }*/
                } else {
-                       _D("wifi enabled flag is false");
+                       printf("\nwifi enabled flag is false");
                }
        }
 
-       _D("End setting");
+       printf("\nEnd setting");
                
        return ret;
 }
@@ -607,10 +830,8 @@ sa_error_e sa_network_get_connection(sa_network_s *info)
        sa_network_type_e conn_type;
        int rv = 0;
 
-       if (!__get_setup_network_initialized()) {
-               if(__start_setup_network()) {
-                       _E("not ready to use network api due to async reply from network api");
-               }
+       if(__start_setup_network()) {
+               printf("\nnot ready to use network api due to async reply from network api");
        }
        // get network state
        if (connection_handle != NULL) {
@@ -637,7 +858,7 @@ sa_error_e sa_network_get_connection(sa_network_s *info)
                        } 
                }
        } else {
-               _E("Connection handle is null");
+               printf("\nConnection handle is null");
        }
 
        return ret;
@@ -649,3 +870,90 @@ sa_error_e sa_network_deactivate(void)
 
        return ret;
 }
+
+
+
+
+
+
+
+
+
+
+
+
+wifi_manager_h wifi = NULL;
+
+
+int test_wifi_manager_init(void)
+{
+       int rv = wifi_manager_initialize(&wifi);
+
+       if (rv == WIFI_MANAGER_ERROR_NONE) {
+               wifi_manager_set_device_state_changed_cb(wifi, __test_device_state_callback, "1");
+               wifi_manager_set_scan_state_changed_cb(wifi, __test_scan_changed_callback, "1");
+               wifi_manager_set_background_scan_cb(wifi, __test_bg_scan_completed_callback, "1");
+               wifi_manager_set_ip_conflict_cb(wifi, __test_ip_conflict_callback, "1");
+               wifi_manager_set_connection_state_changed_cb(wifi, __test_connection_state_callback, "1");
+               wifi_manager_set_rssi_level_changed_cb(wifi, __test_rssi_level_callback, "1");
+               wifi_manager_tdls_set_state_changed_cb(wifi, __test_tdls_state_callback, "1");
+               wifi_manager_tdls_set_discovered_cb(wifi, __test_tdls_discover_callback, "1");
+               wifi_manager_set_module_state_changed_cb(wifi, __test_get_wifi_module_state_callback, "1");
+
+       } else {
+               printf("[1] Wifi init failed [%s]\n", __test_convert_error_to_string(rv));
+               return -1;
+       }
+
+       printf("Wifi init succeeded\n");
+       return 1;
+}
+
+int test_wifi_manager_activate(void)
+{
+       int rv = 0;
+
+       rv = wifi_manager_activate(wifi, __test_activated_callback, NULL);
+
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to activate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
+               return -1;
+       }
+
+       printf("Success to activate Wi-Fi device\n");
+
+       return 1;
+}
+
+
+void sa_network_test(void)
+{
+       printf("\nsa_network_test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
+       
+       GMainLoop *mainloop;
+       mainloop = g_main_loop_new(NULL, FALSE);
+
+       test_wifi_manager_init();
+       //test_wifi_manager_activate();
+
+
+       wifi_manager_initialize(&wifi_handle);
+       if(wifi_handle)
+       {
+               wifi_manager_set_device_state_changed_cb(wifi_handle, __test_device_state_callback, "2");
+               wifi_manager_set_scan_state_changed_cb(wifi_handle, __test_scan_changed_callback, "2");
+               wifi_manager_set_background_scan_cb(wifi_handle, __test_bg_scan_completed_callback, "2");
+               wifi_manager_set_ip_conflict_cb(wifi_handle, __test_ip_conflict_callback, "2");
+               wifi_manager_set_connection_state_changed_cb(wifi_handle, __test_connection_state_callback, "2");
+               wifi_manager_set_rssi_level_changed_cb(wifi_handle, __test_rssi_level_callback, "2");
+               wifi_manager_tdls_set_state_changed_cb(wifi_handle, __test_tdls_state_callback, "2");
+               wifi_manager_tdls_set_discovered_cb(wifi_handle, __test_tdls_discover_callback, "2");
+               wifi_manager_set_module_state_changed_cb(wifi_handle, __test_get_wifi_module_state_callback, "2");
+               
+               wifi_manager_activate(wifi_handle, __test_activated_callback, NULL);
+       }
+
+       g_main_loop_run(mainloop);
+       printf("\nsa_network_test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<END>");
+}
+