Refactor duplicate codes 97/280497/1 accepted/tizen/unified/20220908.124848 submit/tizen/20220902.085939
authorJaehyun Kim <jeik01.kim@samsung.com>
Wed, 31 Aug 2022 02:53:24 +0000 (11:53 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Wed, 31 Aug 2022 02:53:24 +0000 (11:53 +0900)
Change-Id: I958242747e831302ba55bed91221a44d9a493f69
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
13 files changed:
packaging/capi-network-wifi-manager.spec
src/network_interface.c
src/wifi_config.c
src/wifi_internal.c
src/wifi_internal.h
tools/manager-tool/wifi_mgr_extension_autoconnect.c
tools/manager-tool/wifi_mgr_extension_netlinkscan.c
tools/manager-tool/wifi_mgr_public.c
tools/manager-tool/wifi_mgr_public_connect.c
tools/manager-tool/wifi_mgr_public_dpp.c
tools/manager-tool/wifi_mgr_public_scan.c
tools/manager-tool/wifi_mgr_public_set.c
tools/manager-tool/wifi_mgr_tool.c

index b2f75fefad3f0cacedc93247d65f136761f9273b..62a4a332ba0a752298a9db8813f0255064643cf7 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-wifi-manager
 Summary:       Network Wi-Fi library in TIZEN C API
-Version:       1.3.18
+Version:       1.3.19
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
@@ -148,7 +148,7 @@ genhtml %{name}.info -o out --legend --show-details
 %files gcov
 %{_datadir}/gcov/obj/*
 %endif
+
 %files unittests
 %{_bindir}/gtest-wifi-manager
 %{_bindir}/tizen-unittests/%{name}/run-unittest.sh
index b2835ccdda90f67c43bcb2b31de24b4bc7761f8b..932b49568a66756564b950363c8c65a553584738 100644 (file)
@@ -407,46 +407,6 @@ static inline void _net_extract_cinfo_ipv6(GVariant *variant, net_dev_info_s *ne
        g_variant_iter_free(iter);
 }
 
-static inline void _net_extract_cinfo_ipv6_configuration(GVariant *variant, net_dev_info_s *net_info)
-{
-       GVariant *var = NULL;
-       GVariantIter *iter = NULL;
-       const gchar *value = NULL;
-       const gchar *subKey = NULL;
-
-       g_variant_get(variant, "a{sv}", &iter);
-       while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
-               if (g_strcmp0(subKey, "Method") == 0) {
-                       value = g_variant_get_string(var, NULL);
-
-                       if (g_strcmp0(value, "manual") == 0)
-                               net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_STATIC;
-                       else if (g_strcmp0(value, "off") == 0)
-                               net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_OFF;
-                       else if (g_strcmp0(value, "auto") == 0)
-                               net_info->IpConfigType6 = NET_IP_CONFIG_TYPE_AUTO_IP;
-
-               } else if (g_strcmp0(subKey, "Address") == 0) {
-                       value = g_variant_get_string(var, NULL);
-
-                       inet_pton(AF_INET6, value, &net_info->IpAddr6.Data.Ipv6);
-               } else if (g_strcmp0(subKey, "PrefixLength") == 0) {
-                       net_info->PrefixLen6 = g_variant_get_byte(var);
-               } else if (g_strcmp0(subKey, "Gateway") == 0) {
-                       value = g_variant_get_string(var, NULL);
-
-                       inet_pton(AF_INET6, value, &net_info->GatewayAddr6.Data.Ipv6);
-                       net_info->BDefGateway6 = TRUE;
-               } else if (g_strcmp0(subKey, "Privacy") == 0) {
-                       value = g_variant_get_string(var, NULL);
-
-                       if (value != NULL)
-                               g_strlcpy(net_info->Privacy6, value, NET_IPV6_MAX_PRIVACY_LEN);
-               }
-       }
-       g_variant_iter_free(iter);
-}
-
 static void _net_extract_cinfo_nameservers(GVariant *variant, net_dev_info_s *net_info)
 {
        int dnsCount = 0;
@@ -560,7 +520,7 @@ static int __net_extract_common_info(const char *key, GVariant *variant, net_pro
        } else if (g_strcmp0(key, "IPv6") == 0) {
                _net_extract_cinfo_ipv6(variant, net_info);
        } else if (g_strcmp0(key, "IPv6.Configuration") == 0) {
-               _net_extract_cinfo_ipv6_configuration(variant, net_info);
+               _net_extract_cinfo_ipv6(variant, net_info);
        } else if (g_strcmp0(key, "Nameservers") == 0) {
                _net_extract_cinfo_nameservers(variant, net_info);
        } else if (g_strcmp0(key, "Nameservers.Configuration") == 0
index 1b6ad3f6d0697396b4c837416e3d4c70e79c626e..cdb26f5050f1212ad5a11146429cbace58a267b6 100644 (file)
@@ -200,7 +200,6 @@ EXPORT_API int wifi_manager_config_destroy(wifi_manager_config_h config)
        CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
 
        wifi_config_s *h = (wifi_config_s *)config;
-       int i;
 
        if (_wifi_check_config_validity(config) == false) {
                WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
@@ -210,29 +209,7 @@ EXPORT_API int wifi_manager_config_destroy(wifi_manager_config_h config)
 
        _wifi_remove_from_config_list(config);
 
-       g_free(h->name);
-       g_free(h->passphrase);
-       g_free(h->proxy_address);
-       if (h->ip_info) {
-               g_free(h->ip_info->ip_address);
-               g_free(h->ip_info->subnet_mask);
-               g_free(h->ip_info->gateway_address);
-               for (i = 0; i < h->ip_info->dns_count; i++)
-                       g_free(h->ip_info->dns_address[i]);
-               g_free(h->ip_info);
-       }
-       if (h->eap_config) {
-               g_free(h->eap_config->ca_cert);
-               g_free(h->eap_config->client_cert);
-               g_free(h->eap_config->private_key);
-               g_free(h->eap_config->private_key_password);
-               g_free(h->eap_config->anonymous_identity);
-               g_free(h->eap_config->identity);
-               g_free(h->eap_config->subject_match);
-               g_free(h->eap_config);
-       }
-
-       g_free(h);
+       destroy_wifi_config(h);
 
        __NETWORK_CAPI_FUNC_EXIT__;
 
index 3b50982a66e2479de16010e0112081bc2e39ae1c..e12e61e2aa5cf5c321d768adc8e7c6496262b8e6 100644 (file)
@@ -3106,6 +3106,39 @@ int _wifi_config_get_config_id_list(wifi_manager_h wifi, GSList **list)
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+void destroy_wifi_config(wifi_config_s *h)
+{
+       //LCOV_EXCL_START
+       int i;
+
+       g_free(h->name);
+       g_free(h->passphrase);
+       g_free(h->proxy_address);
+
+       if (h->ip_info) {
+               g_free(h->ip_info->ip_address);
+               g_free(h->ip_info->subnet_mask);
+               g_free(h->ip_info->gateway_address);
+               for (i = 0; i < h->ip_info->dns_count; i++)
+                       g_free(h->ip_info->dns_address[i]);
+               g_free(h->ip_info);
+       }
+
+       if (h->eap_config) {
+               g_free(h->eap_config->ca_cert);
+               g_free(h->eap_config->client_cert);
+               g_free(h->eap_config->private_key);
+               g_free(h->eap_config->private_key_password);
+               g_free(h->eap_config->anonymous_identity);
+               g_free(h->eap_config->identity);
+               g_free(h->eap_config->subject_match);
+               g_free(h->eap_config);
+       }
+
+       g_free(h);
+       //LCOV_EXCL_STOP
+}
+
 int _wifi_save_configuration(wifi_manager_h wifi, wifi_config_s *config)
 {
        int rv;
@@ -3148,7 +3181,6 @@ int _wifi_save_configuration(wifi_manager_h wifi, wifi_config_s *config)
 int _wifi_load_configurations(wifi_manager_h wifi)
 {
        int rv;
-       int i;
        wifi_manager_handle_s *wifi_handle = wifi;
        GSList *config_ids = NULL;
        GSList *head_config_ids = NULL;
@@ -3194,31 +3226,7 @@ int _wifi_load_configurations(wifi_manager_h wifi)
                }
 
                if (rv != WIFI_MANAGER_ERROR_NONE) {
-                       //LCOV_EXCL_START
-                       g_free(h->name);
-                       g_free(h->passphrase);
-                       g_free(h->proxy_address);
-                       if (h->ip_info) {
-                               g_free(h->ip_info->ip_address);
-                               g_free(h->ip_info->subnet_mask);
-                               g_free(h->ip_info->gateway_address);
-                               for (i = 0; i < h->ip_info->dns_count; i++)
-                                       g_free(h->ip_info->dns_address[i]);
-                               g_free(h->ip_info);
-                       }
-
-                       if (h->eap_config) {
-                               g_free(h->eap_config->ca_cert);
-                               g_free(h->eap_config->client_cert);
-                               g_free(h->eap_config->private_key);
-                               g_free(h->eap_config->private_key_password);
-                               g_free(h->eap_config->anonymous_identity);
-                               g_free(h->eap_config->identity);
-                               g_free(h->eap_config->subject_match);
-                               g_free(h->eap_config);
-                       }
-                       g_free(h);
-                       //LCOV_EXCL_STOP
+                       destroy_wifi_config(h);
                        WIFI_LOG(WIFI_ERROR, "Fail to load configurations [%d]", rv); //LCOV_EXCL_LINE
                } else {
                        h->address_family = WIFI_MANAGER_ADDRESS_FAMILY_IPV4;
index 4358e75c2d886506378698f97618407366a00cd2..95572c1b861be4b1d531ecd87cfb0678407247cd 100644 (file)
@@ -443,6 +443,7 @@ void _wifi_remove_from_config_list(wifi_config_s *config);
 gchar * _wifi_config_get_config_id(const gchar *name, wifi_manager_security_type_e security_type);
 int _wifi_config_get_config_id_list(wifi_manager_h wifi, GSList **list);
 
+void destroy_wifi_config(wifi_config_s *h);
 int _wifi_save_configuration(wifi_manager_h wifi, wifi_config_s *config);
 int _wifi_load_configurations(wifi_manager_h wifi);
 int _wifi_foreach_configuration(wifi_manager_h wifi,
index 6a351e1a48344094eeeed54900baabe0e0b7d9d0..f6b459edc0ba8a67e3467d4317ec75c1c0cda0e0 100644 (file)
@@ -34,48 +34,59 @@ static char g_ssid[MENU_DATA_SIZE] = "dnet2";
 static char g_autoconnect_mode[MENU_DATA_SIZE] = "0";
 static char g_autoconnect_state[MENU_DATA_SIZE] = "0";
 
-static bool __test_extension_found_ap_cb(wifi_manager_ap_h ap, void *user_data)
+int __test_extension_get_ap_info(wifi_manager_ap_h ap, char **essid, wifi_manager_connection_state_e *state,
+               wifi_manager_security_type_e *type, int *rssi)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
-       char *essid = NULL;
-       wifi_manager_connection_state_e state;
-       wifi_manager_security_type_e type;
-       int rssi = 0;
-       bool autoconnect = FALSE;
-       int autoconn_state = (int)strtol((char *)g_autoconnect_state, NULL, 10);
-       int cb_type = (int)strtol((char *)user_data, NULL, 10);
 
-       ret = wifi_manager_ap_get_essid(ap, &essid);
+       ret = wifi_manager_ap_get_essid(ap, essid);
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get essid for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+                               test_wifi_mgr_convert_error_to_string(ret));
                return FALSE;
        }
 
-       ret = wifi_manager_ap_get_connection_state(ap, &state);
+       ret = wifi_manager_ap_get_connection_state(ap, state);
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get connection state for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+                               test_wifi_mgr_convert_error_to_string(ret));
+               FREE(*essid);
                return FALSE;
        }
 
-       ret = wifi_manager_ap_get_rssi(ap, &rssi);
+       ret = wifi_manager_ap_get_rssi(ap, rssi);
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get rssi for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+                               test_wifi_mgr_convert_error_to_string(ret));
+               FREE(*essid);
                return FALSE;
        }
 
-       ret = wifi_manager_ap_get_security_type(ap, &type);
+       ret = wifi_manager_ap_get_security_type(ap, type);
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get security type for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+                               test_wifi_mgr_convert_error_to_string(ret));
+               FREE(*essid);
                return FALSE;
        }
 
+       return TRUE;
+}
+
+static bool __test_extension_found_ap_cb(wifi_manager_ap_h ap, void *user_data)
+{
+       int ret = WIFI_MANAGER_ERROR_NONE;
+       char *essid = NULL;
+       wifi_manager_connection_state_e state;
+       wifi_manager_security_type_e type;
+       int rssi = 0;
+       bool autoconnect = FALSE;
+       int autoconn_state = (int)strtol((char *)g_autoconnect_state, NULL, 10);
+       int cb_type = (int)strtol((char *)user_data, NULL, 10);
+
+       if (!__test_extension_get_ap_info(ap, &essid, &state, &type, &rssi))
+               return FALSE;
+
        switch (cb_type) {
        case 0: /* get */
                if (test_wifi_mgr_compare_string(essid, g_ssid)) {
index 12339043ac0acf13076885b10f8b1ec6b3b436dd..446828468eafa1f54a027a0889bef2e4d2eacb78 100644 (file)
@@ -32,7 +32,7 @@ extern wifi_manager_h g_wifi_h;
 static char g_ssid[MENU_DATA_SIZE] = "dnet2";
 static char g_vsie[MENU_DATA_SIZE] = "x";
 
-static bool __test_extension_found_ap_cb(wifi_manager_ap_h ap, void *user_data)
+bool __test_extension_found_ap_cb(wifi_manager_ap_h ap, void *user_data)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
        char *bssid = NULL;
index 93654b9c89934c97be49ec5950290c42bef2305b..4ae19f7ef7c61afd381d527b2dfd53a85a7f416e 100644 (file)
@@ -42,6 +42,9 @@ extern struct menu_data menu_public_vsie[];
 extern struct menu_data menu_public_ipconflict[];
 extern struct menu_data menu_public_dpp[];
 
+int __test_extension_get_ap_info(wifi_manager_ap_h ap, char **essid, wifi_manager_connection_state_e *state,
+               wifi_manager_security_type_e *type, int *rssi);
+
 static void __test_public_activated_cb(wifi_manager_error_e result, void* user_data)
 {
        msg(HR_SINGLE);
@@ -90,36 +93,8 @@ static bool __test_public_found_ap_cb(wifi_manager_ap_h ap, void *user_data)
        int rssi = 0;
        int cb_type = (int)strtol((char *)user_data, NULL, 10);
 
-       ret = wifi_manager_ap_get_essid(ap, &essid);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get essid for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_connection_state(ap, &state);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get connection state for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_rssi(ap, &rssi);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get rssi for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_security_type(ap, &type);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get security type for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+       if (!__test_extension_get_ap_info(ap, &essid, &state, &type, &rssi))
                return FALSE;
-       }
 
        switch (cb_type) {
        case 0: /* scan */
index a2d63bdb1f46d0d06472843952309254371868c6..53dea4865d240cf1ec3af16dc65193fc846f4575 100644 (file)
@@ -39,6 +39,8 @@ static char g_certificate[MENU_DATA_SIZE] = "certificate";
 static char g_auth_type[MENU_DATA_SIZE] = "0";
 static char g_wps_pin[MENU_DATA_SIZE] = "1234";
 
+bool __test_public_get_ap_info(wifi_manager_ap_h ap, char **essid, bool *compare);
+
 static void __test_public_connected_cb(wifi_manager_error_e result, void* user_data)
 {
        msg(HR_SINGLE);
@@ -367,47 +369,13 @@ static bool __test_public_connect_found_wps_cb(wifi_manager_ap_h ap,
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
        char *essid = NULL;
-       wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED;
-       wifi_manager_security_type_e type = WIFI_MANAGER_SECURITY_TYPE_NONE;
-       int rssi = 0;
        int wps_type = (int)strtol((char *)user_data, NULL, 10);
+       bool compare = FALSE;
 
-       ret = wifi_manager_ap_get_essid(ap, &essid);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get essid for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_connection_state(ap, &state);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get connection state for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_rssi(ap, &rssi);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get rssi for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+       if (!__test_public_get_ap_info(ap, &essid, &compare))
                return FALSE;
-       }
 
-       ret = wifi_manager_ap_get_security_type(ap, &type);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get security type for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
-               return FALSE;
-       }
-
-       if (test_wifi_mgr_compare_string(essid, g_ssid)) {
-               msg(LOG_CYAN "[%-35s]" LOG_END "[%5s][%s][%d]", essid,
-                       test_wifi_mgr_sec_type_to_string(type),
-                       test_wifi_mgr_conn_state_to_string(state),
-                       rssi);
+       if (compare) {
 
                switch (wps_type) {
                case 1:
index eb9da4b5dac015af6c95fb3db3fb2997c2587371..90e6996eedaf957920f58edb6d4f18085904d82a 100755 (executable)
 #include "wifi_mgr_menu.h"
 #include "wifi_mgr_public_dpp.h"
 
+#define DPP_RETURN_IF_IN_PROGRESS(val) \
+       { \
+               if (val) { \
+                       msg("Previous DPP process is in progress"); \
+                       return 0; \
+               } \
+       }
+
 /* DPP Configurator SSID */
 static char g_ssid[MENU_DATA_SIZE] = "DPP-Network";
 
@@ -225,55 +233,10 @@ static const char *__get_akm_key(wifi_manager_dpp_akm_e akm)
        return NULL;
 }
 
-static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct menu_data *menu)
+static int __test_set_ssid_akm_role(wifi_manager_dpp_network_role_e net_role, wifi_manager_dpp_akm_e akm)
 {
-       wifi_manager_dpp_network_role_e net_role = (int)strtol(g_net_role, NULL, 10);
-       wifi_manager_dpp_akm_e akm = (int)strtol(g_akm, NULL, 10);
        int ret = WIFI_MANAGER_ERROR_NONE;
 
-       if (g_wifi_dpp_h) {
-               msg("Previous DPP process is in progress");
-               return 0;
-       }
-
-       ret = wifi_manager_dpp_create(g_wifi_h, TRUE, &g_wifi_dpp_h);
-
-       msg(HR_SINGLE);
-
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END);
-       } else {
-               msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return ret;
-       }
-
-       msg(HR_SINGLE);
-
-       ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_CONFIGURATOR);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to set DPP role " LOG_CYAN LOG_END);
-       } else {
-               msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               wifi_manager_dpp_destroy(g_wifi_dpp_h);
-               g_wifi_dpp_h = NULL;
-               return ret;
-       }
-
-       msg(HR_SINGLE);
-
-       ret = wifi_manager_dpp_enter_peer_uri(g_wifi_dpp_h, g_enrollee_peer_uri);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to set peer URI " LOG_CYAN LOG_END);
-       } else {
-               msg("Failed to set peer URI " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               wifi_manager_dpp_destroy(g_wifi_dpp_h);
-               g_wifi_dpp_h = NULL;
-               return ret;
-       }
-
        msg(HR_SINGLE);
 
        ret = wifi_manager_dpp_set_ssid(g_wifi_dpp_h, g_ssid);
@@ -281,7 +244,7 @@ static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct me
                msg("Succeeded to set configuration object SSID " LOG_CYAN  "[%s]" LOG_END, g_ssid);
        } else {
                msg("Failed to set configuration object SSID " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+                               test_wifi_mgr_convert_error_to_string(ret));
                wifi_manager_dpp_destroy(g_wifi_dpp_h);
                g_wifi_dpp_h = NULL;
                return ret;
@@ -294,7 +257,7 @@ static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct me
                msg("Succeeded to set DPP AKM " LOG_CYAN LOG_END);
        } else {
                msg("Failed to set DPP AKM " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+                               test_wifi_mgr_convert_error_to_string(ret));
                wifi_manager_dpp_destroy(g_wifi_dpp_h);
                g_wifi_dpp_h = NULL;
                return ret;
@@ -307,7 +270,7 @@ static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct me
                msg("Succeeded to set DPP network role " LOG_CYAN LOG_END);
        } else {
                msg("Failed to set DPP network role " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+                               test_wifi_mgr_convert_error_to_string(ret));
                wifi_manager_dpp_destroy(g_wifi_dpp_h);
                g_wifi_dpp_h = NULL;
                return ret;
@@ -315,33 +278,18 @@ static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct me
 
        msg(HR_SINGLE);
 
-       ret = wifi_manager_dpp_start(g_wifi_dpp_h, NULL, g_configurator_key, __get_akm_key(akm));
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to start DPP Configurator initiator " LOG_CYAN LOG_END);
-       } else {
-               msg("Failed to start DPP Configurator initiator " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               wifi_manager_dpp_destroy(g_wifi_dpp_h);
-               g_wifi_dpp_h = NULL;
-       }
-
-       msg(HR_SINGLE);
-
        return ret;
 }
 
-static int _test_public_dpp_start_configurator_responder(MManager *mm, struct menu_data *menu)
+static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct menu_data *menu)
 {
        wifi_manager_dpp_network_role_e net_role = (int)strtol(g_net_role, NULL, 10);
        wifi_manager_dpp_akm_e akm = (int)strtol(g_akm, NULL, 10);
        int ret = WIFI_MANAGER_ERROR_NONE;
 
-       if (g_wifi_dpp_h) {
-               msg("Previous DPP process is in progress");
-               return 0;
-       }
+       DPP_RETURN_IF_IN_PROGRESS(g_wifi_dpp_h);
 
-       ret = wifi_manager_dpp_create(g_wifi_h, FALSE, &g_wifi_dpp_h);
+       ret = wifi_manager_dpp_create(g_wifi_h, TRUE, &g_wifi_dpp_h);
 
        msg(HR_SINGLE);
 
@@ -350,7 +298,6 @@ static int _test_public_dpp_start_configurator_responder(MManager *mm, struct me
        } else {
                msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
-               g_wifi_dpp_h = NULL;
                return ret;
        }
 
@@ -362,49 +309,89 @@ static int _test_public_dpp_start_configurator_responder(MManager *mm, struct me
        } else {
                msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
+               wifi_manager_dpp_destroy(g_wifi_dpp_h);
+               g_wifi_dpp_h = NULL;
+               return ret;
        }
 
        msg(HR_SINGLE);
 
-       ret = wifi_manager_dpp_set_ssid(g_wifi_dpp_h, g_ssid);
+       ret = wifi_manager_dpp_enter_peer_uri(g_wifi_dpp_h, g_enrollee_peer_uri);
        if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to set configuration object SSID " LOG_CYAN  "[%s]" LOG_END, g_ssid);
+               msg("Succeeded to set peer URI " LOG_CYAN LOG_END);
        } else {
-               msg("Failed to set configuration object SSID " LOG_RED "[%s]" LOG_END,
+               msg("Failed to set peer URI " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
                wifi_manager_dpp_destroy(g_wifi_dpp_h);
                g_wifi_dpp_h = NULL;
                return ret;
        }
 
-       msg(HR_SINGLE);
+       ret = __test_set_ssid_akm_role(net_role, akm);
+       if (ret != WIFI_MANAGER_ERROR_NONE)
+               return ret;
 
-       ret = wifi_manager_dpp_set_akm(g_wifi_dpp_h, akm);
+       ret = wifi_manager_dpp_start(g_wifi_dpp_h, NULL, g_configurator_key, __get_akm_key(akm));
        if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to set DPP AKM " LOG_CYAN LOG_END);
+               msg("Succeeded to start DPP Configurator initiator " LOG_CYAN LOG_END);
        } else {
-               msg("Failed to set DPP AKM " LOG_RED "[%s]" LOG_END,
+               msg("Failed to start DPP Configurator initiator " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
                wifi_manager_dpp_destroy(g_wifi_dpp_h);
                g_wifi_dpp_h = NULL;
-               return ret;
        }
 
        msg(HR_SINGLE);
 
-       ret = wifi_manager_dpp_set_network_role(g_wifi_dpp_h, net_role);
+       return ret;
+}
+
+static int __test_public_dpp_create(bool is_initiator)
+{
+       int ret = WIFI_MANAGER_ERROR_NONE;
+
+       ret = wifi_manager_dpp_create(g_wifi_h, is_initiator, &g_wifi_dpp_h);
+
+       msg(HR_SINGLE);
+
        if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to set DPP network role " LOG_CYAN LOG_END);
+               msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END);
        } else {
-               msg("Failed to set DPP network role " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               wifi_manager_dpp_destroy(g_wifi_dpp_h);
+               msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END,
+                               test_wifi_mgr_convert_error_to_string(ret));
                g_wifi_dpp_h = NULL;
                return ret;
        }
 
        msg(HR_SINGLE);
 
+       return ret;
+}
+
+static int _test_public_dpp_start_configurator_responder(MManager *mm, struct menu_data *menu)
+{
+       wifi_manager_dpp_network_role_e net_role = (int)strtol(g_net_role, NULL, 10);
+       wifi_manager_dpp_akm_e akm = (int)strtol(g_akm, NULL, 10);
+       int ret = WIFI_MANAGER_ERROR_NONE;
+
+       DPP_RETURN_IF_IN_PROGRESS(g_wifi_dpp_h);
+
+       ret = __test_public_dpp_create(FALSE);
+       if (ret != WIFI_MANAGER_ERROR_NONE)
+               return ret;
+
+       ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_CONFIGURATOR);
+       if (ret == WIFI_MANAGER_ERROR_NONE) {
+               msg("Succeeded to set DPP role " LOG_CYAN LOG_END);
+       } else {
+               msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END,
+                       test_wifi_mgr_convert_error_to_string(ret));
+       }
+
+       ret = __test_set_ssid_akm_role(net_role, akm);
+       if (ret != WIFI_MANAGER_ERROR_NONE)
+               return ret;
+
        ret = wifi_manager_dpp_start(g_wifi_dpp_h,
                        g_configurator_responder_auth_key,
                        g_configurator_key,
@@ -423,40 +410,35 @@ static int _test_public_dpp_start_configurator_responder(MManager *mm, struct me
        return ret;
 }
 
-static int _test_public_dpp_start_enrollee_initiator(MManager *mm, struct menu_data *menu)
+static int __test_public_dpp_set_role(void)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
 
-       if (g_wifi_dpp_h) {
-               msg("Previous DPP process is in progress");
-               return 0;
-       }
-
-       ret = wifi_manager_dpp_create(g_wifi_h, TRUE, &g_wifi_dpp_h);
-
-       msg(HR_SINGLE);
-
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END);
-       } else {
-               msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               g_wifi_dpp_h = NULL;
-               return ret;
-       }
-
-       msg(HR_SINGLE);
-
        ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_ENROLLEE);
        if (ret == WIFI_MANAGER_ERROR_NONE) {
                msg("Succeeded to set DPP role " LOG_CYAN LOG_END);
        } else {
                msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+                               test_wifi_mgr_convert_error_to_string(ret));
        }
 
        msg(HR_SINGLE);
 
+       return ret;
+}
+
+static int _test_public_dpp_start_enrollee_initiator(MManager *mm, struct menu_data *menu)
+{
+       int ret = WIFI_MANAGER_ERROR_NONE;
+
+       DPP_RETURN_IF_IN_PROGRESS(g_wifi_dpp_h);
+
+       ret = __test_public_dpp_create(TRUE);
+       if (ret != WIFI_MANAGER_ERROR_NONE)
+               return ret;
+
+       __test_public_dpp_set_role();
+
        ret = wifi_manager_dpp_enter_peer_uri(g_wifi_dpp_h, g_configurator_peer_uri);
        if (ret == WIFI_MANAGER_ERROR_NONE) {
                msg("Succeeded to set peer URI " LOG_CYAN LOG_END);
@@ -489,32 +471,14 @@ static int _test_public_dpp_start_enrollee_responder(MManager *mm, struct menu_d
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
 
-       if (g_wifi_dpp_h) {
-               msg("Previous DPP process is in progress");
-               return 0;
-       }
-
-       ret = wifi_manager_dpp_create(g_wifi_h, FALSE, &g_wifi_dpp_h);
-
-       msg(HR_SINGLE);
+       DPP_RETURN_IF_IN_PROGRESS(g_wifi_dpp_h);
 
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END);
-       } else {
-               msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               g_wifi_dpp_h = NULL;
+       ret = __test_public_dpp_create(FALSE);
+       if (ret != WIFI_MANAGER_ERROR_NONE)
                return ret;
-       }
 
-       msg(HR_SINGLE);
-
-       ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_ENROLLEE);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               msg("Succeeded to set DPP role " LOG_CYAN LOG_END);
-       } else {
-               msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+       ret = __test_public_dpp_set_role();
+       if (ret != WIFI_MANAGER_ERROR_NONE) {
                wifi_manager_dpp_destroy(g_wifi_dpp_h);
                g_wifi_dpp_h = NULL;
        }
index 96e1b9a65a46d854c85780548ae93eea9d33ee97..768da7e5963f9da6cdeb9de6f676fdd3a6518133 100644 (file)
@@ -35,6 +35,8 @@ static int g_specific_scan_cnt = 0;
 static char g_ssid[MENU_DATA_SIZE] = "dnet2";
 static char g_frequency[MENU_DATA_SIZE] = "0";
 
+bool __test_extension_found_ap_cb(wifi_manager_ap_h ap, void *user_data);
+
 static bool __test_public_found_ap_cb(wifi_manager_ap_h ap, void *user_data)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
@@ -117,44 +119,6 @@ static void __test_public_scan_request_cb(wifi_manager_error_e error_code, void*
                __test_public_foreach_scan();
 }
 
-static bool __test_public_found_bssid_ap_cb(wifi_manager_ap_h ap, void *user_data)
-{
-       int ret = WIFI_MANAGER_ERROR_NONE;
-       char *bssid = NULL;
-       char *essid = NULL;
-       int rssi = 0;
-
-       ret = wifi_manager_ap_get_bssid(ap, &bssid);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get bssid for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_essid(ap, &essid);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get essid for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(bssid);
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_rssi(ap, &rssi);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get rssi for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(bssid);
-               FREE(essid);
-               return FALSE;
-       }
-
-       msg("[%s]" LOG_CYAN "[%-35s]" LOG_END "[%d]", bssid, essid, rssi);
-
-       FREE(bssid);
-       FREE(essid);
-       return TRUE;
-}
-
 static int __test_public_foreach_bssid_scan(void)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
@@ -162,7 +126,7 @@ static int __test_public_foreach_bssid_scan(void)
        msg(HR_SINGLE);
 
        ret = wifi_manager_foreach_found_bssid_ap(g_wifi_h,
-                       __test_public_found_bssid_ap_cb, NULL);
+                       __test_extension_found_ap_cb, NULL);
 
        msg(HR_SINGLE);
 
index e6cd4944ef5149be2bf591b12866b7ef3e28f246..47e62d1392c65e0d64ce8c62f91e4b858834e230 100644 (file)
@@ -44,18 +44,14 @@ static char g_proxy_type[MENU_DATA_SIZE] = "0";
 static char g_proxy_address_type[MENU_DATA_SIZE] = "0";
 static char g_proxy_address[MENU_DATA_SIZE] = "0";
 
-static bool __test_public_found_ip_method_cb(wifi_manager_ap_h ap, void *user_data)
+bool __test_public_get_ap_info(wifi_manager_ap_h ap, char **essid, bool *compare)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
-       char *essid = NULL;
        wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_FAILURE;
        wifi_manager_security_type_e type = WIFI_MANAGER_SECURITY_TYPE_NONE;
-       wifi_manager_ip_config_type_e config_type = (int)strtol(g_ip_config_type, NULL, 10);
-       wifi_manager_address_family_e address_type = (int)strtol(g_ip_address_type, NULL, 10);
-       wifi_manager_dns_config_type_e dns_type = (int)strtol(g_dns_type, NULL, 10);
        int rssi = 0;
 
-       ret = wifi_manager_ap_get_essid(ap, &essid);
+       ret = wifi_manager_ap_get_essid(ap, essid);
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get essid for AP " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
@@ -66,7 +62,7 @@ static bool __test_public_found_ip_method_cb(wifi_manager_ap_h ap, void *user_da
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get connection state for AP " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+               FREE(*essid);
                return FALSE;
        }
 
@@ -74,7 +70,7 @@ static bool __test_public_found_ip_method_cb(wifi_manager_ap_h ap, void *user_da
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get rssi for AP " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+               FREE(*essid);
                return FALSE;
        }
 
@@ -82,17 +78,36 @@ static bool __test_public_found_ip_method_cb(wifi_manager_ap_h ap, void *user_da
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                msg("Failed to get security type for AP " LOG_RED "[%s]" LOG_END,
                        test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+               FREE(*essid);
                return FALSE;
        }
 
-       if (test_wifi_mgr_compare_string(essid, g_ssid)) {
-               msg(LOG_CYAN "[%-35s]" LOG_END "[%5s][%s][%d]", essid,
-                       test_wifi_mgr_sec_type_to_string(type),
-                       test_wifi_mgr_conn_state_to_string(state),
-                       rssi);
+       if (test_wifi_mgr_compare_string(*essid, g_ssid)) {
+               msg(LOG_CYAN "[%-35s]" LOG_END "[%5s][%s][%d]", *essid,
+                               test_wifi_mgr_sec_type_to_string(type),
+                               test_wifi_mgr_conn_state_to_string(state),
+                               rssi);
 
                msg(HR_SINGLE);
+               *compare = TRUE;
+       }
+
+       return TRUE;
+}
+
+static bool __test_public_found_ip_method_cb(wifi_manager_ap_h ap, void *user_data)
+{
+       int ret = WIFI_MANAGER_ERROR_NONE;
+       char *essid = NULL;
+       wifi_manager_ip_config_type_e config_type = (int)strtol(g_ip_config_type, NULL, 10);
+       wifi_manager_address_family_e address_type = (int)strtol(g_ip_address_type, NULL, 10);
+       wifi_manager_dns_config_type_e dns_type = (int)strtol(g_dns_type, NULL, 10);
+       bool compare = FALSE;
+
+       if (!__test_public_get_ap_info(ap, &essid, &compare))
+               return FALSE;
+
+       if (compare) {
 
                /* IP config type */
                ret = wifi_manager_ap_set_ip_config_type(ap, address_type, config_type);
@@ -285,50 +300,14 @@ static bool __test_public_found_proxy_method_cb(wifi_manager_ap_h ap, void *user
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
        char *essid = NULL;
-       wifi_manager_connection_state_e state = WIFI_MANAGER_CONNECTION_STATE_FAILURE;
-       wifi_manager_security_type_e type = WIFI_MANAGER_SECURITY_TYPE_NONE;
        wifi_manager_proxy_type_e proxy_type = (int)strtol(g_proxy_type, NULL, 10);
        wifi_manager_address_family_e address_type = (int)strtol(g_proxy_address_type, NULL, 10);
-       int rssi = 0;
-
-       ret = wifi_manager_ap_get_essid(ap, &essid);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get essid for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_connection_state(ap, &state);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get connection state for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
-               return FALSE;
-       }
-
-       ret = wifi_manager_ap_get_rssi(ap, &rssi);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get rssi for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
-               return FALSE;
-       }
+       bool compare = FALSE;
 
-       ret = wifi_manager_ap_get_security_type(ap, &type);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               msg("Failed to get security type for AP " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               FREE(essid);
+       if (!__test_public_get_ap_info(ap, &essid, &compare))
                return FALSE;
-       }
-
-       if (test_wifi_mgr_compare_string(essid, g_ssid)) {
-               msg(LOG_CYAN "[%-35s]" LOG_END "[%5s][%s][%d]", essid,
-                       test_wifi_mgr_sec_type_to_string(type),
-                       test_wifi_mgr_conn_state_to_string(state),
-                       rssi);
 
-               msg(HR_SINGLE);
+       if (compare) {
 
                /* Proxy type */
                ret = wifi_manager_ap_set_proxy_type(ap, proxy_type);
index f77d02e9d21bc2429a7e6c207c2c4c835c9a577d..2e5cd982cd7b0213af2dee845058206a052ccdad 100644 (file)
@@ -223,69 +223,42 @@ static void __test_dpp_event_cb(wifi_manager_dpp_event_e event,
        FREE(if_name);
 }
 
-static int _test_wifi_mgr_initialize(MManager *mm, struct menu_data *menu)
+static int __test_init_cbs(wifi_manager_h g_wifi_h, int ret, int num)
 {
-       int ret = WIFI_MANAGER_ERROR_NONE;
-       bool state = FALSE;
        char *if_name = NULL;
 
-       if (g_wifi_h) {
-               wifi_manager_deinitialize(g_wifi_h);
-               g_wifi_h = NULL;
-       }
-
-       if (g_wifi2_h) {
-               wifi_manager_deinitialize(g_wifi2_h);
-               g_wifi2_h = NULL;
-       }
-
-       ret = wifi_manager_initialize(&g_wifi_h);
        if (ret == WIFI_MANAGER_ERROR_NONE) {
-               wifi_manager_set_device_state_changed_cb(g_wifi_h, __test_device_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_scan_state_changed_cb(g_wifi_h, __test_scan_changed_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_connection_state_changed_cb(g_wifi_h, __test_connection_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_rssi_level_changed_cb(g_wifi_h, __test_rssi_level_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_background_scan_cb(g_wifi_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_ip_conflict_cb(g_wifi_h, __test_ip_conflict_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_module_state_changed_cb(g_wifi_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(1));
+               wifi_manager_set_device_state_changed_cb(g_wifi_h, __test_device_state_cb, GINT_TO_POINTER(num));
+               wifi_manager_set_scan_state_changed_cb(g_wifi_h, __test_scan_changed_cb, GINT_TO_POINTER(num));
+               wifi_manager_set_connection_state_changed_cb(g_wifi_h, __test_connection_state_cb, GINT_TO_POINTER(num));
+               wifi_manager_set_rssi_level_changed_cb(g_wifi_h, __test_rssi_level_cb, GINT_TO_POINTER(num));
+               wifi_manager_set_background_scan_cb(g_wifi_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(num));
+               wifi_manager_set_ip_conflict_cb(g_wifi_h, __test_ip_conflict_cb, GINT_TO_POINTER(num));
+               wifi_manager_set_module_state_changed_cb(g_wifi_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(num));
 
-               wifi_manager_tdls_set_state_changed_cb(g_wifi_h, __test_tdls_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_tdls_set_discovered_cb(g_wifi_h, __test_tdls_discover_cb, GINT_TO_POINTER(1));
+               wifi_manager_tdls_set_state_changed_cb(g_wifi_h, __test_tdls_state_cb, GINT_TO_POINTER(num));
+               wifi_manager_tdls_set_discovered_cb(g_wifi_h, __test_tdls_discover_cb, GINT_TO_POINTER(num));
 
-               wifi_manager_dpp_set_event_cb(g_wifi_h, __test_dpp_event_cb, GINT_TO_POINTER(1));
+               wifi_manager_dpp_set_event_cb(g_wifi_h, __test_dpp_event_cb, GINT_TO_POINTER(num));
 
                wifi_manager_get_network_interface_name(g_wifi_h, &if_name);
-               msg(LOG_GREEN "[1:%s] Success to initialize wifi handle [%p]" LOG_END, if_name, g_wifi_h);
+               msg(LOG_GREEN "[%d:%s] Success to initialize wifi handle [%p]" LOG_END, num, if_name, g_wifi_h);
                FREE(if_name);
-       } else {
-               msg("[1] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return ret;
-       }
-
-       ret = wifi_manager_initialize(&g_wifi2_h);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               wifi_manager_set_device_state_changed_cb(g_wifi2_h, __test_device_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_scan_state_changed_cb(g_wifi2_h, __test_scan_changed_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_connection_state_changed_cb(g_wifi2_h, __test_connection_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_rssi_level_changed_cb(g_wifi2_h, __test_rssi_level_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_background_scan_cb(g_wifi2_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_ip_conflict_cb(g_wifi2_h, __test_ip_conflict_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_module_state_changed_cb(g_wifi2_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(2));
-
-               wifi_manager_tdls_set_state_changed_cb(g_wifi2_h, __test_tdls_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_tdls_set_discovered_cb(g_wifi2_h, __test_tdls_discover_cb, GINT_TO_POINTER(2));
-
-               wifi_manager_dpp_set_event_cb(g_wifi2_h, __test_dpp_event_cb, GINT_TO_POINTER(2));
 
-               wifi_manager_get_network_interface_name(g_wifi2_h, &if_name);
-               msg(LOG_GREEN "[2:%s] Success to initialize wifi handle [%p]" LOG_END, if_name, g_wifi2_h);
-               FREE(if_name);
+               return 1;
        } else {
-               msg("[2] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-               return ret;
+               msg("[%d] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
+                       num, test_wifi_mgr_convert_error_to_string(ret));
+
+               return 0;
        }
+}
+
+static int __test_init_dev_state_out(void)
+{
+       char *if_name = NULL;
+       int ret = WIFI_MANAGER_ERROR_NONE;
+       bool state = FALSE;
 
        ret = wifi_manager_is_activated(g_wifi_h, &state);
        wifi_manager_get_network_interface_name(g_wifi_h, &if_name);
@@ -297,19 +270,14 @@ static int _test_wifi_mgr_initialize(MManager *mm, struct menu_data *menu)
                msg("[1] Failed to get Wi-Fi device state " LOG_RED "[%s]" LOG_END,
                                test_wifi_mgr_convert_error_to_string(ret));
        }
+
        FREE(if_name);
 
        return ret;
 }
 
-static int _test_wifi_mgr_initialize_cs(MManager *mm, struct menu_data *menu)
+static void __test_deinit_all(void)
 {
-       int ret = WIFI_MANAGER_ERROR_NONE;
-       bool state = FALSE;
-       char *if_name = NULL;
-
-       cs_tid = get_tid();
-
        if (g_wifi_h) {
                wifi_manager_deinitialize(g_wifi_h);
                g_wifi_h = NULL;
@@ -319,66 +287,43 @@ static int _test_wifi_mgr_initialize_cs(MManager *mm, struct menu_data *menu)
                wifi_manager_deinitialize(g_wifi2_h);
                g_wifi2_h = NULL;
        }
+}
 
-       ret = wifi_manager_initialize_cs(cs_tid, &g_wifi_h);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               wifi_manager_set_device_state_changed_cb(g_wifi_h, __test_device_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_scan_state_changed_cb(g_wifi_h, __test_scan_changed_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_connection_state_changed_cb(g_wifi_h, __test_connection_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_rssi_level_changed_cb(g_wifi_h, __test_rssi_level_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_background_scan_cb(g_wifi_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_ip_conflict_cb(g_wifi_h, __test_ip_conflict_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_module_state_changed_cb(g_wifi_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(1));
+static int _test_wifi_mgr_initialize(MManager *mm, struct menu_data *menu)
+{
+       int ret = WIFI_MANAGER_ERROR_NONE;
 
-               wifi_manager_tdls_set_state_changed_cb(g_wifi_h, __test_tdls_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_tdls_set_discovered_cb(g_wifi_h, __test_tdls_discover_cb, GINT_TO_POINTER(1));
+       __test_deinit_all();
 
-               wifi_manager_dpp_set_event_cb(g_wifi_h, __test_dpp_event_cb, GINT_TO_POINTER(1));
+       ret = wifi_manager_initialize(&g_wifi_h);
+       if (!__test_init_cbs(g_wifi_h, ret, 1))
+               return ret;
 
-               wifi_manager_get_network_interface_name(g_wifi_h, &if_name);
-               msg(LOG_GREEN "[1:%s] Success to initialize wifi handle [%p]" LOG_END, if_name, g_wifi_h);
-               FREE(if_name);
-       } else {
-               msg("[1] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-       }
+       ret = wifi_manager_initialize(&g_wifi2_h);
+       if (!__test_init_cbs(g_wifi2_h, ret, 2))
+               return ret;
 
-       ret = wifi_manager_initialize_cs(cs_tid, &g_wifi2_h);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               wifi_manager_set_device_state_changed_cb(g_wifi2_h, __test_device_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_scan_state_changed_cb(g_wifi2_h, __test_scan_changed_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_connection_state_changed_cb(g_wifi2_h, __test_connection_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_rssi_level_changed_cb(g_wifi2_h, __test_rssi_level_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_background_scan_cb(g_wifi2_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_ip_conflict_cb(g_wifi2_h, __test_ip_conflict_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_module_state_changed_cb(g_wifi2_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(2));
+       ret = __test_init_dev_state_out();
 
-               wifi_manager_tdls_set_state_changed_cb(g_wifi2_h, __test_tdls_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_tdls_set_discovered_cb(g_wifi2_h, __test_tdls_discover_cb, GINT_TO_POINTER(2));
+       return ret;
+}
 
-               wifi_manager_dpp_set_event_cb(g_wifi2_h, __test_dpp_event_cb, GINT_TO_POINTER(2));
+static int _test_wifi_mgr_initialize_cs(MManager *mm, struct menu_data *menu)
+{
+       int ret = WIFI_MANAGER_ERROR_NONE;
 
-               wifi_manager_get_network_interface_name(g_wifi2_h, &if_name);
-               msg(LOG_GREEN "[2:%s] Success to initialize wifi handle [%p]" LOG_END, if_name, g_wifi2_h);
-               FREE(if_name);
-       } else {
-               msg("[2] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
-       }
+       cs_tid = get_tid();
 
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               ret = wifi_manager_is_activated(g_wifi_h, &state);
-               wifi_manager_get_network_interface_name(g_wifi_h, &if_name);
-               if (ret == WIFI_MANAGER_ERROR_NONE) {
-                       g_device_state = state;
-                       msg("[1:%s] Wi-Fi device state " LOG_CYAN "[%s]" LOG_END, if_name,
-                               test_wifi_mgr_device_state_to_string(g_device_state));
-               } else {
-                       msg("[1] Failed to get Wi-Fi device state " LOG_RED "[%s]" LOG_END,
-                               test_wifi_mgr_convert_error_to_string(ret));
-               }
-               FREE(if_name);
-       }
+       __test_deinit_all();
+
+       ret = wifi_manager_initialize_cs(cs_tid, &g_wifi_h);
+       __test_init_cbs(g_wifi_h, ret, 1);
+
+       ret = wifi_manager_initialize_cs(cs_tid, &g_wifi2_h);
+       __test_init_cbs(g_wifi2_h, ret, 2);
+
+       if (ret == WIFI_MANAGER_ERROR_NONE)
+               ret = __test_init_dev_state_out();
 
        return ret;
 }
@@ -386,78 +331,18 @@ static int _test_wifi_mgr_initialize_cs(MManager *mm, struct menu_data *menu)
 static int _test_wifi_mgr_initialize_with_ifname(MManager *mm, struct menu_data *menu)
 {
        int ret = WIFI_MANAGER_ERROR_NONE;
-       bool state = FALSE;
-       char *if_name = NULL;
 
-       if (g_wifi_h) {
-               wifi_manager_deinitialize(g_wifi_h);
-               g_wifi_h = NULL;
-       }
-
-       if (g_wifi2_h) {
-               wifi_manager_deinitialize(g_wifi2_h);
-               g_wifi2_h = NULL;
-       }
+       __test_deinit_all();
 
        ret = wifi_manager_initialize_with_interface_name(&g_wifi_h, g_ifname);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               wifi_manager_set_device_state_changed_cb(g_wifi_h, __test_device_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_scan_state_changed_cb(g_wifi_h, __test_scan_changed_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_connection_state_changed_cb(g_wifi_h, __test_connection_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_rssi_level_changed_cb(g_wifi_h, __test_rssi_level_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_background_scan_cb(g_wifi_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_ip_conflict_cb(g_wifi_h, __test_ip_conflict_cb, GINT_TO_POINTER(1));
-               wifi_manager_set_module_state_changed_cb(g_wifi_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(1));
-
-               wifi_manager_tdls_set_state_changed_cb(g_wifi_h, __test_tdls_state_cb, GINT_TO_POINTER(1));
-               wifi_manager_tdls_set_discovered_cb(g_wifi_h, __test_tdls_discover_cb, GINT_TO_POINTER(1));
-
-               wifi_manager_dpp_set_event_cb(g_wifi_h, __test_dpp_event_cb, GINT_TO_POINTER(1));
-
-               wifi_manager_get_network_interface_name(g_wifi_h, &if_name);
-               msg(LOG_GREEN "[1:%s] Success to initialize wifi handle [%p]" LOG_END, if_name, g_wifi_h);
-               FREE(if_name);
-       } else {
-               msg("[1] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+       if (!__test_init_cbs(g_wifi_h, ret, 1))
                return ret;
-       }
 
        ret = wifi_manager_initialize_with_interface_name(&g_wifi2_h, g_ifname);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               wifi_manager_set_device_state_changed_cb(g_wifi2_h, __test_device_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_scan_state_changed_cb(g_wifi2_h, __test_scan_changed_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_connection_state_changed_cb(g_wifi2_h, __test_connection_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_rssi_level_changed_cb(g_wifi2_h, __test_rssi_level_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_background_scan_cb(g_wifi2_h, __test_bg_scan_completed_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_ip_conflict_cb(g_wifi2_h, __test_ip_conflict_cb, GINT_TO_POINTER(2));
-               wifi_manager_set_module_state_changed_cb(g_wifi2_h, __test_get_wifi_module_state_cb, GINT_TO_POINTER(2));
-
-               wifi_manager_tdls_set_state_changed_cb(g_wifi2_h, __test_tdls_state_cb, GINT_TO_POINTER(2));
-               wifi_manager_tdls_set_discovered_cb(g_wifi2_h, __test_tdls_discover_cb, GINT_TO_POINTER(2));
-
-               wifi_manager_dpp_set_event_cb(g_wifi2_h, __test_dpp_event_cb, GINT_TO_POINTER(2));
-
-               wifi_manager_get_network_interface_name(g_wifi2_h, &if_name);
-               msg(LOG_GREEN "[2:%s] Success to initialize wifi handle [%p]" LOG_END, if_name, g_wifi2_h);
-               FREE(if_name);
-       } else {
-               msg("[2] Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END,
-                       test_wifi_mgr_convert_error_to_string(ret));
+       if (!__test_init_cbs(g_wifi2_h, ret, 2))
                return ret;
-       }
 
-       ret = wifi_manager_is_activated(g_wifi_h, &state);
-       wifi_manager_get_network_interface_name(g_wifi_h, &if_name);
-       if (ret == WIFI_MANAGER_ERROR_NONE) {
-               g_device_state = state;
-               msg("[1:%s] Wi-Fi device state " LOG_CYAN "[%s]" LOG_END, if_name,
-                               test_wifi_mgr_device_state_to_string(g_device_state));
-       } else {
-               msg("[1] Failed to get Wi-Fi device state " LOG_RED "[%s]" LOG_END,
-                               test_wifi_mgr_convert_error_to_string(ret));
-       }
-       FREE(if_name);
+       ret = __test_init_dev_state_out();
 
        return ret;
 }