Add APIs for Wi-Fi band selection for scanning 69/316369/1 accepted/tizen/unified/20240829.153519 accepted/tizen/unified/dev/20240901.214620 accepted/tizen/unified/x/20240830.014105
authorJaehyun Kim <jeik01.kim@samsung.com>
Tue, 20 Aug 2024 08:27:30 +0000 (17:27 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Tue, 20 Aug 2024 08:27:30 +0000 (17:27 +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 8344aee90f5691698277c1535afcf387107d1a8b..e532f9d711420d504ea09e19234a11b79d88157d 100755 (executable)
@@ -4866,6 +4866,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 1ba146dc834c6ebd8a604c6c58b998079e992971..28039ac1cd410b8bd74337d6f2a77bff86fcd19c 100755 (executable)
@@ -234,6 +234,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 0fa4bd80a107f37761fbdfd2beefd0ff0dba7811..5e6c695f4372aa0a548eab9b8958f99a5a57301a 100644 (file)
@@ -4188,6 +4188,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 74f29070a414a8ec3be38c6e320279fef2e6ff2f..98755b182485d0f380c1c6b273fc27059c8ae871 100644 (file)
@@ -404,6 +404,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 d5c6f2cc350a17ae3529fee4c4ee71455d6c84d8..4078262dea6568efcc92b1100642dc7e0a89c45b 100644 (file)
@@ -186,6 +186,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)
@@ -4256,6 +4286,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 9f7ef54c7a66e336df6e4709798f9f623efcd965..d3cdb4ffb8b5f716973015210db0192ae415483e 100644 (file)
@@ -602,6 +602,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 4394943c7d5cae73858ca7c396ad571d24f22fae..7b178d344fd59122e98f193048d61c4b281862e3 100644 (file)
@@ -2267,6 +2267,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 91c407a29c830b79cc1f360157975ebe3002ccde..8912cb0e8dbc51c400f8b88f94f5c4faf04c8846 100644 (file)
@@ -1046,3 +1046,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 026edf1b308e86c17889acb1464e17fb5605282e..f96b78b411634d3a50028861cf452d9f5f6e8c41 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 edccfe025474c6184b779ba5f8107c1bf79949b6..534724988d9f649f43b5e651d65d2b29a25ec047 100644 (file)
@@ -366,6 +366,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");
@@ -606,6 +608,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;
        }