Add APIs for Wi-Fi band selection for scanning 00/316500/1 accepted/tizen/7.0/unified/20240823.184311
authorJaehyun Kim <jeik01.kim@samsung.com>
Tue, 20 Aug 2024 08:27:30 +0000 (17:27 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Thu, 22 Aug 2024 08:35:21 +0000 (17:35 +0900)
Change-Id: I0e564dccdb90ddc99237a10507ee73fb36c0da0d
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
include/wifi-manager-extension.h
src/network_dbus.c
src/network_dbus.h
src/network_interface.c
src/network_interface.h
src/wifi_internal.c
src/wifi_internal.h
src/wifi_manager.c
tools/manager-test/wman_test_extension.c
tools/manager-test/wman_test_extension.h
tools/manager-test/wman_test_main.c

index 617bc35c656ebf42dc5f6e6d26a149a61115f2df..f03d57244caedf3244799be3d6c72d9a49f9744b 100644 (file)
@@ -108,6 +108,14 @@ typedef enum {
        WIFI_MANAGER_PS_MODE_DYNAMIC,
 } wifi_manager_power_save_mode_e;
 
+/* Wi-Fi band to scan */
+typedef enum {
+       WIFI_MANAGER_BAND_SELECTION_ALL = 0x00,
+       WIFI_MANAGER_BAND_SELECTION_2_4GHZ,
+       WIFI_MANAGER_BAND_SELECTION_5GHZ,
+       WIFI_MANAGER_BAND_SELECTION_6GHZ,
+} wifi_manager_band_selection_e;
+
 /**
  * @brief The Wi-Fi netlink scan handle.
  * @since_tizen 5.0
@@ -859,6 +867,41 @@ 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 Sets the Wi-Fi band to scan.
+ * @since_tizen 9.0
+ *
+ * @param[in] wifi           The Wi-Fi handle
+ * @param[in] scan_band      The Wi-Fi band to scan
+ *
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                  Successful
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED         Not supported
+ * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED     Permission Denied
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED       Not initialized
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED      Operation failed
+ * @pre This API needs wifi_manager_initialize() before use.
+ */
+int wifi_manager_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band);
+
+/**
+ * @brief Gets the Wi-Fi band to scan.
+ * @since_tizen 9.0
+ *
+ * @param[in] wifi           The Wi-Fi handle
+ * @param[out] scan_band     The Wi-Fi band to scan
+ *
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                  Successful
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED         Not supported
+ * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED     Permission Denied
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED       Not initialized
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED      Operation failed
+ */
+int wifi_manager_get_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e *scan_band);
+
 /**
  * @brief Called when the Roaming state is changed.
  * @since_tizen 7.0
index a478a3fe3de16a5df40bfd51b50c00f805d3057e..6ff8f2c0717238da77a2eca0b5ebaa8c1f9a5c45 100644 (file)
@@ -4823,6 +4823,79 @@ int _net_dbus_get_country_code(network_info_s *network_info, char **country)
        return Error;
 }
 
+int _net_dbus_set_scan_band(network_info_s *network_info, const char *scan_band)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       const char *prop_key = "WifiBandSelection";
+       const char *method = "SetProperty";
+       GVariant *params = NULL;
+
+       params = g_variant_new("(sv)", prop_key, g_variant_new_string(scan_band));
+
+       message = _net_invoke_dbus_method(network_info,
+                       CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+                       CONNMAN_TECHNOLOGY_INTERFACE,
+                       method, params, &Error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to set country code");
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+int _net_dbus_get_scan_band(network_info_s *network_info, char **scan_band)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       GVariant *value = NULL;
+       GVariantIter *iter = NULL;
+       gchar *key = NULL;
+
+       message = _net_invoke_dbus_method(network_info,
+                       CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+                       CONNMAN_TECHNOLOGY_INTERFACE, "GetProperties",
+                       NULL, &Error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get properties");
+
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       g_variant_get(message, "(a{sv})", &iter);
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               if (g_strcmp0(key, "WifiBandSelection") == 0) {
+                       const gchar *str = g_variant_get_string(value, NULL);
+                       *scan_band = g_strdup(str);
+                       WIFI_LOG(WIFI_INFO, "Successfully get country code: %s", *scan_band);
+
+                       g_variant_unref(value);
+                       g_free(key);
+                       break;
+               }
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int _net_dbus_get_vconf_value(network_info_s *network_info,
                const char *key, const char *type, int *ret, int *int_value, char **str_value)
 {
index 19f3d9314de40f7a0cb56a83572351135fe22415..d9fb1923cf5fff189fadf5380c2000a6f8ba2401 100644 (file)
@@ -233,6 +233,8 @@ int _net_dbus_get_random_mac_lifetime(network_info_s *network_info, unsigned int
 
 int _net_dbus_set_country_code(network_info_s *network_info, const char *country);
 int _net_dbus_get_country_code(network_info_s *network_info, char **country);
+int _net_dbus_set_scan_band(network_info_s *network_info, const char *band);
+int _net_dbus_get_scan_band(network_info_s *network_info, char **band);
 int _net_dbus_get_vconf_value(network_info_s *network_info,
                const char *key, const char *type, int *ret, int *int_value, char **str_value);
 
index 28ee41ba16bd1672d35dd3b5e33655be49db9814..77690cf1bcc120d904cec6b08eaad50c83316d60 100644 (file)
@@ -4169,6 +4169,30 @@ int net_wifi_get_country_code(network_info_s *network_info, char **country)
 }
 
 //LCOV_EXCL_START
+int net_wifi_set_scan_band(network_info_s *network_info, const char *scan_band)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       Error =  _net_dbus_set_scan_band(network_info, scan_band);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
+int net_wifi_get_scan_band(network_info_s *network_info, char **scan_band)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       Error =  _net_dbus_get_scan_band(network_info, scan_band);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int net_wifi_get_power_save_state(network_info_s *network_info, unsigned int *ps_state)
 {
        __NETWORK_FUNC_ENTER__;
index f0b0a61621fe675175394d7d01c8c401aa043a5e..886b3cc02cda69c2700569c7d079bfcd5bec30d2 100644 (file)
@@ -403,6 +403,8 @@ int net_wifi_get_random_mac_lifetime(network_info_s *network_info, unsigned int
 
 int net_wifi_set_country_code(network_info_s *network_info, const char *country);
 int net_wifi_get_country_code(network_info_s *network_info, char **country);
+int net_wifi_set_scan_band(network_info_s *network_info, const char *scan_band);
+int net_wifi_get_scan_band(network_info_s *network_info, char **scan_band);
 
 typedef enum {
        WIFI_POWER_SAVE_OFF = 0x00,
index 08588659bb06ee4074a7a9223a425c5998c5da8d..2f959acc77b92170112b4e6a8383353e3aa512d4 100644 (file)
@@ -184,6 +184,36 @@ static const char *__convert_ap_state_to_string(wifi_manager_connection_state_e
                return "UNKNOWN";
        }
 }
+
+static const char *__convert_wifi_band_to_string(wifi_manager_band_selection_e wifi_band)
+{
+       switch (wifi_band) {
+       case WIFI_MANAGER_BAND_SELECTION_ALL:
+               return "all";
+       case WIFI_MANAGER_BAND_SELECTION_2_4GHZ:
+               return "2.4GHz";
+       case WIFI_MANAGER_BAND_SELECTION_5GHZ:
+               return "5GHz";
+       case WIFI_MANAGER_BAND_SELECTION_6GHZ:
+               return "6GHz";
+       default:
+               return "all";
+       }
+}
+
+static wifi_manager_band_selection_e __convert_string_to_wifi_band(const char *wifi_band)
+{
+       if (g_strcmp0(wifi_band, "all") == 0)
+               return WIFI_MANAGER_BAND_SELECTION_ALL;
+       else if (g_strcmp0(wifi_band, "2.4GHz") == 0)
+               return WIFI_MANAGER_BAND_SELECTION_2_4GHZ;
+       else if (g_strcmp0(wifi_band, "5GHz") == 0)
+               return WIFI_MANAGER_BAND_SELECTION_5GHZ;
+       else if (g_strcmp0(wifi_band, "6GHz") == 0)
+               return WIFI_MANAGER_BAND_SELECTION_6GHZ;
+       else
+               return WIFI_MANAGER_BAND_SELECTION_ALL;
+}
 //LCOV_EXCL_STOP
 
 static gchar *__wifi_change_name_to_hexadecimal(const gchar *name)
@@ -4251,6 +4281,42 @@ int _wifi_get_country_code(wifi_manager_h wifi, char **country)
 }
 
 //LCOV_EXCL_START
+int _wifi_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band)
+{
+       int rv;
+       const char *scan_band_str;
+       wifi_manager_handle_s *wifi_handle = wifi;
+
+       scan_band_str = __convert_wifi_band_to_string(scan_band);
+       rv = net_wifi_set_scan_band(wifi_handle->network_info, scan_band_str);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+       } else if (rv != NET_ERR_NONE)
+               return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
+int _wifi_get_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e *scan_band)
+{
+       int rv;
+       char *scan_band_str = NULL;
+       wifi_manager_handle_s *wifi_handle = wifi;
+
+       rv = net_wifi_get_scan_band(wifi_handle->network_info, &scan_band_str);
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+       } else if (rv != NET_ERR_NONE)
+               return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+
+       *scan_band = __convert_string_to_wifi_band(scan_band_str);
+       g_free(scan_band_str);
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 int _wifi_get_power_save_state(wifi_manager_h wifi, wifi_manager_power_save_state_e *ps_state)
 {
        int rv = 0;
index 5cef866d2da5a3c1d460f5eefe3421cb70431914..d4bfab94769139cd1f942438c85cdff1d743a427 100644 (file)
@@ -601,6 +601,8 @@ int _wifi_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime);
 
 int _wifi_set_country_code(wifi_manager_h wifi, const char *country);
 int _wifi_get_country_code(wifi_manager_h wifi, char **country);
+int _wifi_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band);
+int _wifi_get_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e *scan_band);
 
 int _wifi_get_power_save_state(wifi_manager_h wifi, wifi_manager_power_save_state_e *ps_state);
 int _wifi_set_power_save_state(wifi_manager_h wifi, wifi_manager_power_save_state_e ps_state);
index 6fdd4d28ac1d6d1cd392ae1f4fce624fca93afaf..8b2ccb138b8b4803cb13bee61f6eb38850c08e72 100644 (file)
@@ -2245,6 +2245,53 @@ EXPORT_API int wifi_manager_get_country_code(wifi_manager_h wifi, char **country
        return rv;
 }
 
+EXPORT_API int wifi_manager_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band)
+{
+       int rv;
+
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__);
+
+       if (scan_band < WIFI_MANAGER_BAND_SELECTION_ALL || scan_band > WIFI_MANAGER_BAND_SELECTION_6GHZ) {
+               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
+       }
+
+       rv = _wifi_set_scan_band(wifi, scan_band);
+       if (rv != WIFI_MANAGER_ERROR_NONE)
+               WIFI_LOG(WIFI_ERROR, "Set Wi-Fi scan band failed");
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+       return rv;
+}
+
+EXPORT_API int wifi_manager_get_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e *scan_band)
+{
+       int rv;
+
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__);
+
+       if (scan_band == NULL) {
+               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
+       }
+
+       rv = _wifi_get_scan_band(wifi, scan_band);
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+       return rv;
+}
+
+
 EXPORT_API int wifi_manager_set_roaming_cb(wifi_manager_h wifi,
                wifi_manager_roaming_state_changed_cb callback, void *user_data)
 {
index a70ad45895459ff4a71d9ad99f7e7793a2693928..10d706b2a9f870827f2cdbe7d5d2f09392c27654 100644 (file)
@@ -1036,3 +1036,54 @@ int wman_test_set_power_save_mode(wifi_manager_h wifi)
 
        return 1;
 }
+
+int wman_test_get_scan_band(wifi_manager_h wifi)
+{
+       int rv;
+       wifi_manager_band_selection_e scan_band;
+
+       rv = wifi_manager_get_scan_band(wifi, &scan_band);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get band info for Wi-Fi scanning [%s]\n", wman_test_strerror(rv));
+               return -1;
+       }
+
+       switch (scan_band) {
+       case WIFI_MANAGER_BAND_SELECTION_ALL:
+               printf("Wi-Fi band to scan: All\n");
+               break;
+       case WIFI_MANAGER_BAND_SELECTION_2_4GHZ:
+               printf("Wi-Fi band to scan: 2.4GHz\n");
+               break;
+       case WIFI_MANAGER_BAND_SELECTION_5GHZ:
+               printf("Wi-Fi band to scan: 5GHz\n");
+               break;
+       case WIFI_MANAGER_BAND_SELECTION_6GHZ:
+               printf("Wi-Fi band to scan: 6GHz\n");
+               break;
+       default:
+               printf("Wi-Fi band to scan: Unknown\n");
+               break;
+       }
+
+       return 1;
+}
+
+int wman_test_set_scan_band(wifi_manager_h wifi)
+{
+       int rv;
+       wifi_manager_band_selection_e scan_band;
+
+       printf("Set Wi-Fi band to scan (0: All, 1: 2.4GHz, 2: 5GHz, 3: 6GHz): ");
+       rv = scanf("%u", &scan_band);
+       if (rv <= 0)
+               return -1;
+
+       rv = wifi_manager_set_scan_band(wifi, scan_band);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Failed to set Wi-Fi band to scan [%s]\n", wman_test_strerror(rv));
+               return -1;
+       }
+
+       return 1;
+}
index 6221c45056a1ffe4bb24901781452aa5ad957008..45661f4cb93c316e62ab4f305eaaa369d906598d 100644 (file)
@@ -49,4 +49,6 @@ int wman_test_get_power_save_state(wifi_manager_h wifi);
 int wman_test_set_power_save_state(wifi_manager_h wifi);
 int wman_test_get_power_save_mode(wifi_manager_h wifi);
 int wman_test_set_power_save_mode(wifi_manager_h wifi);
+int wman_test_get_scan_band(wifi_manager_h wifi);
+int wman_test_set_scan_band(wifi_manager_h wifi);
 
index 2ea2ceb7801e4f0a50cb619720def1f44bdc18a5..dc308ac26cebbd10bf3888b64baa21f304db29d0 100644 (file)
@@ -331,6 +331,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("]   - Set Interval of Auto Scan\n");
                printf(";   - Remove All Wi-Fi configurations\n");
                printf(",   - Get Wi-Fi passphrase\n");
+               printf(".   - Get Wi-Fi band for scanning\n");
+               printf("/   - Set Wi-Fi band for scanning\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
 
                printf("ENTER  - Show options menu.......\n");
@@ -568,6 +570,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case ',':
                rv = wman_test_get_wifi_passphrase(wifi);
                break;
+       case '.':
+               rv = wman_test_get_scan_band(wifi);
+               break;
+       case '/':
+               rv = wman_test_set_scan_band(wifi);
+               break;
        default:
                break;
        }