Add CAPI to provide available security method information 51/267551/1
authorJaehyun Kim <jeik01.kim@samsung.com>
Tue, 7 Dec 2021 05:30:20 +0000 (14:30 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Tue, 7 Dec 2021 05:30:20 +0000 (14:30 +0900)
Change-Id: Ibd1c19f0e9da4e7b33b5e51ba5317ca3da1d49ee
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
include/wifi-manager-extension.h
src/network_interface.c
src/network_wlan.h
src/wifi_ap.c
tools/manager-test/wman_test_extension.c
tools/manager-test/wman_test_extension.h
tools/manager-test/wman_test_main.c

index 49fd439..04ad726 100644 (file)
@@ -756,6 +756,28 @@ int wifi_manager_set_country_code(wifi_manager_h wifi, const char *country);
 int wifi_manager_get_country_code(wifi_manager_h wifi, char **country_code);
 
 /**
+ * @brief Checks available security types of the AP.
+ * @details An AP may support several types of security modes together.
+ * You can check all supported security modes with this API.
+ * @since_tizen 7.0
+ *
+ * @param[in] ap             The access point handle
+ * @param[in] type           Wi-Fi security type
+ * @param[out] supported     true when enabled and false when disabled
+ *
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION    Invalid operation
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED     Operation failed
+ * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED    Permission Denied
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ * @pre This API needs wifi_manager_initialize() and wifi_manager_activate() before use.
+ */
+int wifi_manager_ap_is_security_type_supported(wifi_manager_ap_h ap,
+                                       wifi_manager_security_type_e type, bool *supported);
+
+/**
  * @}
  */
 
index 0b2d099..a1cf43e 100644 (file)
@@ -872,6 +872,35 @@ static inline void _net_extract_winfo_security(GVariant *var, net_profile_info_s
        g_variant_iter_free(iter_sub);
 }
 
+static inline void _net_extract_winfo_security_list(GVariant *var, net_profile_info_s *ProfInfo)
+{
+       const gchar *value;
+       GVariantIter *iter_sub = NULL;
+
+       g_variant_get(var, "as", &iter_sub);
+       while (g_variant_iter_loop(iter_sub, "s", &value)) {
+               if (g_strcmp0(value, "none") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_NONE] = TRUE;
+               else if (g_strcmp0(value, "wep") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_WEP] = TRUE;
+               else if (g_strcmp0(value, "psk") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_WPA_PSK] = TRUE;
+               else if (g_strcmp0(value, "ft_psk") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK] = TRUE;
+               else if (g_strcmp0(value, "ieee8021x") == 0 || g_strcmp0(value, "ft_ieee8021x") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_EAP] = TRUE;
+               else if (g_strcmp0(value, "rsn") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK] = TRUE;
+               else if (g_strcmp0(value, "sae") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_SAE] = TRUE;
+               else if (g_strcmp0(value, "owe") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_OWE] = TRUE;
+               else if (g_strcmp0(value, "dpp") == 0)
+                       ProfInfo->security_info.sec_list[WIFI_MANAGER_SECURITY_TYPE_DPP] = TRUE;
+       }
+       g_variant_iter_free(iter_sub);
+}
+
 static inline void _net_extract_winfo_encryptionmode(const gchar *value, net_profile_info_s *ProfInfo)
 {
        if (g_strcmp0(value, "none") == 0)
@@ -981,6 +1010,8 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s *Prof
                        ProfInfo->wlan_mode = _net_extract_winfo_mode(value);
                } else if (g_strcmp0(key, "Security") == 0) {
                        _net_extract_winfo_security(var, ProfInfo);
+               } else if (g_strcmp0(key, "SecurityList") == 0) {
+                       _net_extract_winfo_security_list(var, ProfInfo);
                } else if (g_strcmp0(key, "EncryptionMode") == 0) {
                        value = g_variant_get_string(var, NULL);
                        _net_extract_winfo_encryptionmode(value, ProfInfo);
index faf936c..5e2cc1b 100644 (file)
@@ -20,6 +20,7 @@
 #include <glib.h>
 
 #include "network_config.h"
+#include "wifi-manager.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -248,6 +249,7 @@ typedef struct {
        wlan_auth_info_u authentication;                /** authentication information */
        char wps_support;                                               /** If WPS is supported, then this property will be set to TRUE */
        unsigned int keymgmt;                                   /** If WPS is supported, then this property will be set to TRUE */
+       gboolean sec_list[WIFI_MANAGER_SECURITY_TYPE_DPP+1]; /** security mode list */
 } wlan_security_info_s;
 
 #ifdef __cplusplus
index aff594b..c3fd5ad 100644 (file)
@@ -1833,6 +1833,35 @@ EXPORT_API int wifi_manager_ap_set_security_type(wifi_manager_ap_h ap,
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+
+EXPORT_API int wifi_manager_ap_is_security_type_supported(wifi_manager_ap_h ap,
+                                       wifi_manager_security_type_e type, bool *supported)
+{
+       /* __NETWORK_CAPI_FUNC_ENTER__; */
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       if (_wifi_check_ap_validity(ap) == false ||
+                       supported == NULL ||
+                       type < WIFI_MANAGER_SECURITY_TYPE_NONE ||
+                       type > WIFI_MANAGER_SECURITY_TYPE_DPP) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               /* __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE */
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net_profile_info_s *profile_info = ap;
+
+       if (profile_info->security_info.sec_list[type])
+               *supported = true;
+       else
+               *supported = false;
+
+       /* __NETWORK_CAPI_FUNC_EXIT__; */
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 EXPORT_API int wifi_manager_ap_get_encryption_type(wifi_manager_ap_h ap,
                wifi_manager_encryption_type_e *type)
 {
index 00c5aef..15f4563 100644 (file)
@@ -753,6 +753,63 @@ int wman_test_get_country_code(wifi_manager_h wifi)
        return 1;
 }
 
+static bool __test_found_check_security_type_callback(wifi_manager_ap_h ap, void *user_data)
+{
+       int rv = 0;
+       char *ap_name = NULL;
+       char *ap_name_part = user_data;
+       int sec_type = 0;
+       bool supported = false;
+
+       rv = wifi_manager_ap_get_essid(ap, &ap_name);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("[Wi-Fi] Fail to get AP name [%s]\n", wman_test_strerror(rv));
+               return false;
+       }
+
+       if (wman_test_compare_ap_name(ap_name, ap_name_part)) {
+               printf("Enter security type to check\n"
+                               "(0:None, 1:WEP, 2:WPA, 3:WPA2, 4:EAP, 5:FT_PSK, 6:SAE, 7:OWE, 8:DPP): ");
+               rv = scanf(" %d", &sec_type);
+
+               rv = wifi_manager_ap_is_security_type_supported(ap, sec_type, &supported);
+               if (rv != WIFI_MANAGER_ERROR_NONE)
+                       printf("Fail to get security info[%s]\n", wman_test_strerror(rv));
+               else
+                       printf("Supported: %s\n", supported ? "TRUE" : "FALSE");
+
+               free(ap_name);
+               return false;
+       }
+
+       free(ap_name);
+       return true;
+}
+
+int wman_test_check_supported_security_type(wifi_manager_h wifi)
+{
+       int rv = 0;
+       char ap_name[33];
+       bool state = false;
+
+       wifi_manager_is_activated(wifi, &state);
+       if (state == false)
+               return -1;
+
+       printf("[Wi-Fi] Input a part of AP name to get : ");
+       rv = scanf(" %32[^\n]s", ap_name);
+       if (rv <= 0)
+               return -1;
+
+       rv = wifi_manager_foreach_found_ap(wifi, __test_found_check_security_type_callback, ap_name);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("[Wi-Fi] Fail to get up (can't get AP list) [%s]\n", wman_test_strerror(rv));
+               return -1;
+       }
+
+       return 1;
+}
+
 void wman_test_print_connection_mode(wifi_manager_ap_h ap)
 {
        wifi_manager_connection_mode_e mode;
index 81538c8..80b377f 100644 (file)
@@ -39,4 +39,5 @@ int wman_test_set_random_mac_lifetime(wifi_manager_h wifi);
 int wman_test_get_mac_policies(wifi_manager_h wifi);
 int wman_test_set_country_code(wifi_manager_h wifi);
 int wman_test_get_country_code(wifi_manager_h wifi);
+int wman_test_check_supported_security_type(wifi_manager_h wifi);
 void wman_test_print_connection_mode(wifi_manager_ap_h ap);
index aa0b4aa..0d492a9 100644 (file)
@@ -286,6 +286,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("$   - Get mac policies\n");
                printf("^   - Set country code\n");
                printf("&   - Get country code\n");
+               printf("*   - Check available security type\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
 
                printf("ENTER  - Show options menu.......\n");
@@ -496,6 +497,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case '&':
                rv = wman_test_get_country_code(wifi);
                break;
+       case '*':
+               rv = wman_test_check_supported_security_type(wifi);
+               break;
        default:
                break;
        }