From: Jaehyun Kim Date: Thu, 22 Aug 2024 09:04:31 +0000 (+0900) Subject: Add APIs for Wi-Fi band selection for scanning X-Git-Tag: accepted/tizen/8.0/unified/20240830.163849^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ce13bde95ec50f4d7c69e032cf40704283d37aa;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Add APIs for Wi-Fi band selection for scanning Change-Id: If1c51ce410a893634421a9e1dfd20fd296656f21 Signed-off-by: Jaehyun Kim --- diff --git a/include/wifi-manager-extension.h b/include/wifi-manager-extension.h index 2010a8b..ddccecb 100644 --- a/include/wifi-manager-extension.h +++ b/include/wifi-manager-extension.h @@ -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 @@ -840,6 +848,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 diff --git a/src/network_dbus.c b/src/network_dbus.c index b628ac4..22051e7 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -4868,6 +4868,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) { diff --git a/src/network_dbus.h b/src/network_dbus.h index 1ba146d..28039ac 100755 --- a/src/network_dbus.h +++ b/src/network_dbus.h @@ -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); diff --git a/src/network_interface.c b/src/network_interface.c index 0fa4bd8..5e6c695 100644 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -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__; diff --git a/src/network_interface.h b/src/network_interface.h index 74f2907..98755b1 100644 --- a/src/network_interface.h +++ b/src/network_interface.h @@ -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, diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 52f4f22..ef22b05 100644 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -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) @@ -4261,6 +4291,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; diff --git a/src/wifi_internal.h b/src/wifi_internal.h index 9f7ef54..d3cdb4f 100644 --- a/src/wifi_internal.h +++ b/src/wifi_internal.h @@ -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); diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 4394943..3d92d03 100644 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -2267,6 +2267,52 @@ 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) { diff --git a/tools/manager-test/wman_test_extension.c b/tools/manager-test/wman_test_extension.c index 7e7fd53..21252aa 100644 --- a/tools/manager-test/wman_test_extension.c +++ b/tools/manager-test/wman_test_extension.c @@ -993,3 +993,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; +} diff --git a/tools/manager-test/wman_test_extension.h b/tools/manager-test/wman_test_extension.h index 824b29f..56f0c5a 100644 --- a/tools/manager-test/wman_test_extension.h +++ b/tools/manager-test/wman_test_extension.h @@ -48,4 +48,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); diff --git a/tools/manager-test/wman_test_main.c b/tools/manager-test/wman_test_main.c index b44218d..c66a1f0 100644 --- a/tools/manager-test/wman_test_main.c +++ b/tools/manager-test/wman_test_main.c @@ -365,6 +365,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("[ - Get Interval of Auto Scan\n"); printf("] - Set Interval of Auto Scan\n"); printf("; - Remove All Wi-Fi configurations\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"); @@ -602,6 +604,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case ';': rv = wman_test_reset_wifi_configurations(wifi); break; + case '.': + rv = wman_test_get_scan_band(wifi); + break; + case '/': + rv = wman_test_set_scan_band(wifi); + break; default: break; }