From: Jaehyun Kim Date: Thu, 22 Dec 2022 03:44:38 +0000 (+0900) Subject: Add APIs for setting background scan interval X-Git-Tag: accepted/tizen/7.0/unified/20230126.170237~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F285872%2F3;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Add APIs for setting background scan interval Change-Id: Ia71290f860cecb876fae398bab15979783d27a8b Signed-off-by: Jaehyun Kim --- diff --git a/include/wifi-manager-extension.h b/include/wifi-manager-extension.h index 7816134..d96d4d7 100644 --- a/include/wifi-manager-extension.h +++ b/include/wifi-manager-extension.h @@ -326,6 +326,49 @@ int wifi_manager_get_autoscan_mode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e *mode); /** + * @brief Sets the interval of autoscan. + * @since_tizen 7.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/network.set + * + * @param[in] wifi The Wi-Fi handle + * @param[in] mode The auto scan mode + * @param[in] interval The interval of autoscan + * + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation + * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied + * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported + * @pre This API needs wifi_manager_initialize() before use. + */ +int wifi_manager_set_autoscan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode, int interval); + +/** + * @brief Gets the autoscan interval. + * @since_tizen 7.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/network.get + * + * @param[in] wifi The Wi-Fi handle + * @param[in] mode The auto scan mode + * @param[out] interval The interval of autoscan + * + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized + * @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 + */ +int wifi_manager_get_autoscan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode, int *interval); + +/** * @brief Set BSSID to connman to be connected * @since_tizen 5.0 * @param[in] wifi The Wi-Fi handle diff --git a/packaging/capi-network-wifi-manager.spec b/packaging/capi-network-wifi-manager.spec index ab11824..3a6880e 100644 --- a/packaging/capi-network-wifi-manager.spec +++ b/packaging/capi-network-wifi-manager.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-manager Summary: Network Wi-Fi library in TIZEN C API -Version: 1.3.20 +Version: 1.3.21 Release: 0 Group: System/Network License: Apache-2.0 diff --git a/src/network_dbus.c b/src/network_dbus.c index 129a834..d31e36a 100644 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -1410,6 +1410,35 @@ int _net_dbus_set_bgscan_mode(network_info_s *network_info, return Error; } +int _net_dbus_set_bgscan_interval(network_info_s *network_info, + net_wifi_background_scan_mode_e mode, int interval) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + GVariant *message = NULL; + GVariant *params; + + if (mode == WIFI_BGSCAN_MODE_EXPONENTIAL) + params = g_variant_new("(ssu)", network_info->interface_name, "Exponential", interval); + else + params = g_variant_new("(ssu)", network_info->interface_name, "Periodic", interval); + + message = _net_invoke_dbus_method(network_info, + NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, "SetBgscanInterval", + params, &Error); + + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "_net_invoke_dbus_method failed"); //LCOV_EXCL_LINE + + if (message != NULL) + g_variant_unref(message); //LCOV_EXCL_LINE + + __NETWORK_FUNC_EXIT__; + return Error; +} + int _net_dbus_set_ip_conflict_period(network_info_s *network_info, unsigned int initial_time) { __NETWORK_FUNC_ENTER__; @@ -4294,6 +4323,43 @@ int _net_dbus_get_autoscanmode(network_info_s *network_info, return Error; } +int _net_dbus_get_autoscan_interval(network_info_s *network_info, + unsigned int autoscanmode, int *interval) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *params = NULL; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + if (autoscanmode == WIFI_BGSCAN_MODE_EXPONENTIAL) + params = g_variant_new("(ss)", network_info->interface_name, "Exponential"); + else + params = g_variant_new("(ss)", network_info->interface_name, "Periodic"); + + message = _net_invoke_dbus_method(network_info, + NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, "GetBgscanInterval", + params, &Error); + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to Get Bgscan Interval"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + /** Check Reply */ + int result = 0; + g_variant_get(message, "(u)", &result); + *interval = result; + + WIFI_LOG(WIFI_INFO, "Get Auto scan Interval Result: %d", result); + + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; + return Error; +} + static void __net_multi_scan_request_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) { diff --git a/src/network_dbus.h b/src/network_dbus.h index d617292..a97a400 100644 --- a/src/network_dbus.h +++ b/src/network_dbus.h @@ -90,6 +90,8 @@ int _net_dbus_scan_request(network_info_s *network_info); int _net_dbus_get_scan_state(network_info_s *network_info, int *state); int _net_dbus_set_bgscan_mode(network_info_s *network_info, net_wifi_background_scan_mode_e mode); +int _net_dbus_set_bgscan_interval(network_info_s *network_info, + net_wifi_background_scan_mode_e mode, int interval); int _net_dbus_set_agent_passphrase_and_connect(network_info_s *network_info, const char *passphrase, const char *profilename); int _net_dbus_get_wps_generated_pin(network_info_s *network_info, char **wps_pin); @@ -179,6 +181,8 @@ int _net_dbus_resume_bgscan(network_info_s *network_info); int _net_dbus_pause_bgscan(network_info_s *network_info); int _net_dbus_get_autoscanmode(network_info_s *network_info, unsigned int *autoscanmode); +int _net_dbus_get_autoscan_interval(network_info_s *network_info, + unsigned int autoscanmode, int *interval); int _net_dbus_get_autoscan(network_info_s *network_info, gboolean *autoscan); int _net_dbus_add_vsie(network_info_s *network_info, diff --git a/src/network_interface.c b/src/network_interface.c index d5ee6fd..a4adaae 100644 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -3593,6 +3593,39 @@ int net_wifi_set_background_scan_mode(network_info_s *network_info, return NET_ERR_NONE; } +int net_wifi_set_background_scan_interval(network_info_s *network_info, + net_wifi_background_scan_mode_e scan_mode, int interval) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + Error = __net_get_wifi_state(network_info); + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to get Wi-Fi state"); //LCOV_EXCL_LINE + __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE + return Error; //LCOV_EXCL_LINE + } + + if (network_info->wifi_state == WIFI_OFF) { + WIFI_LOG(WIFI_ERROR, "Wi-Fi powered off!"); //LCOV_EXCL_LINE + __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE + return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE + } + + if ((Error = _net_dbus_set_bgscan_interval(network_info, scan_mode, interval)) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "Failed to set bgscan interval. Error [%s]", + _net_print_error(Error)); + + __NETWORK_FUNC_EXIT__; + return Error; + } + + __NETWORK_FUNC_EXIT__; + return NET_ERR_NONE; +} + int net_wifi_set_ip_conflict_period(network_info_s *network_info, unsigned int initial_time) { @@ -3702,6 +3735,24 @@ int net_wifi_get_autoscanmode(network_info_s *network_info, unsigned int *autosc return Error; } +int net_wifi_get_autoscan_interval(network_info_s *network_info, + unsigned int autoscanmode, int *interval) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + Error = _net_dbus_get_autoscan_interval(network_info, autoscanmode, interval); + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "_net_dbus_get_autoscan_interval() failed. Error [%s]", + _net_print_error(Error)); + } + + __NETWORK_FUNC_EXIT__; + return Error; +} + int net_wifi_get_module_state(network_info_s *network_info, int *module_state) { GVariant *message = NULL, *variant; diff --git a/src/network_interface.h b/src/network_interface.h index b07c351..d215e40 100644 --- a/src/network_interface.h +++ b/src/network_interface.h @@ -340,8 +340,12 @@ int net_get_device_policy_wifi_profile(network_info_s *network_info); int net_wifi_set_autoscan(network_info_s *network_info, gboolean autoscan); int net_wifi_set_background_scan_mode(network_info_s *network_info, net_wifi_background_scan_mode_e scan_mode); +int net_wifi_set_background_scan_interval(network_info_s *network_info, + net_wifi_background_scan_mode_e scan_mode, int interval); int net_wifi_get_autoscan(network_info_s *network_info, gboolean *autoscan); int net_wifi_get_autoscanmode(network_info_s *network_info, unsigned int *autoscanmode); +int net_wifi_get_autoscan_interval(network_info_s *network_info, + unsigned int autoscanmode, int *interval); int net_wifi_get_module_state(network_info_s *network_info, int *module_state); int net_foreach_ipv6_address(GSList **ipv6_address_list); diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 6deafd3..8e7b302 100644 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -3590,6 +3590,22 @@ int _wifi_set_background_scan_mode(wifi_manager_h wifi, return WIFI_MANAGER_ERROR_NONE; } +int _wifi_set_background_scan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode, int interval) +{ + int rv = 0; + wifi_manager_handle_s *wifi_handle = wifi; + + rv = net_wifi_set_background_scan_interval(wifi_handle->network_info, mode, interval); + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv != NET_ERR_NONE) + return WIFI_MANAGER_ERROR_OPERATION_FAILED; + + return WIFI_MANAGER_ERROR_NONE; +} + int _wifi_set_ip_conflict_period(wifi_manager_h wifi, unsigned int initial_time) { int rv = 0; @@ -3641,6 +3657,24 @@ int _wifi_get_autoscanmode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e *au return WIFI_MANAGER_ERROR_NONE; } +int _wifi_get_autoscan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e autoscanmode, int *interval) +{ + int rv; + wifi_manager_handle_s *wifi_handle = wifi; + + rv = net_wifi_get_autoscan_interval(wifi_handle->network_info, autoscanmode, interval); + 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) { + WIFI_LOG(WIFI_ERROR, "Failed to get auto scan interval"); //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + return WIFI_MANAGER_ERROR_NONE; +} + int _wifi_set_passpoint(wifi_manager_h wifi, int passpoint) { int rv; diff --git a/src/wifi_internal.h b/src/wifi_internal.h index 8b13efe..74567be 100644 --- a/src/wifi_internal.h +++ b/src/wifi_internal.h @@ -461,8 +461,12 @@ gchar *_wifi_eap_auth_type_to_string(wifi_manager_eap_auth_type_e eap_auth_type) int _wifi_set_autoscan(wifi_manager_h wifi, bool autoscan); int _wifi_set_background_scan_mode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e mode); +int _wifi_set_background_scan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode, int interval); int _wifi_get_autoscan(wifi_manager_h wifi, bool *autoscan); int _wifi_get_autoscanmode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e *autoscanmode); +int _wifi_get_autoscan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e autoscanmode, int *interval); int _wifi_get_passpoint(wifi_manager_h wifi, int *passpoint); int _wifi_set_passpoint(wifi_manager_h wifi, int passpoint); int _wifi_get_module_state(wifi_manager_h wifi, wifi_manager_module_state_e *state); diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 1fad8ee..84bab68 100644 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -1394,6 +1394,33 @@ EXPORT_API int wifi_manager_set_autoscan_mode(wifi_manager_h wifi, return rv; } +EXPORT_API int wifi_manager_set_autoscan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode, int interval) +{ + 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 (mode < WIFI_MANAGER_AUTOSCAN_MODE_EXPONENTIAL || + mode > WIFI_MANAGER_AUTOSCAN_MODE_PERIODIC || + interval < 0) { + 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_background_scan_interval(wifi, mode, interval); + if (rv != WIFI_MANAGER_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Set background scan interval failed"); + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + EXPORT_API int wifi_manager_get_autoscan(wifi_manager_h wifi, bool *autoscan) { @@ -1440,6 +1467,31 @@ EXPORT_API int wifi_manager_get_autoscan_mode(wifi_manager_h wifi, return rv; } +EXPORT_API int wifi_manager_get_autoscan_interval(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode, int *interval) +{ + 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 (mode < WIFI_MANAGER_AUTOSCAN_MODE_EXPONENTIAL || + mode > WIFI_MANAGER_AUTOSCAN_MODE_PERIODIC || + interval == 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_autoscan_interval(wifi, mode, interval); + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + EXPORT_API int wifi_manager_set_passpoint(wifi_manager_h wifi, int passpoint) { __NETWORK_CAPI_FUNC_ENTER__; diff --git a/tools/manager-test/wman_test_extension.c b/tools/manager-test/wman_test_extension.c index 50832af..ff199c7 100644 --- a/tools/manager-test/wman_test_extension.c +++ b/tools/manager-test/wman_test_extension.c @@ -78,6 +78,37 @@ int wman_test_set_autoscan_mode(wifi_manager_h wifi) return 1; } +int wman_test_set_autoscan_interval(wifi_manager_h wifi) +{ + int mode = 0; + int rv = 0; + int autoscan_interval = 0; + + printf("Input autoscan mode (0:exponential, 1:periodic): \n"); + rv = scanf(" %9d", &mode); + + if (rv <= 0) { + printf("Invalid input!\n"); + return -1; + } + + printf("Input autoscan interval: \n"); + rv = scanf(" %9d", &autoscan_interval); + + if (rv <= 0) { + printf("Invalid input!\n"); + return -1; + } + + rv = wifi_manager_set_autoscan_interval(wifi, mode, autoscan_interval); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("failed to set autoscan mode [%s]\n", wman_test_strerror(rv)); + return -1; + } + + return 1; +} + int wman_test_get_autoscan_state(wifi_manager_h wifi) { int rv = 0; @@ -110,6 +141,31 @@ int wman_test_get_autoscan_mode(wifi_manager_h wifi) return 1; } +int wman_test_get_autoscan_interval(wifi_manager_h wifi) +{ + int mode = 0; + int rv = 0; + int autoscan_interval = 0; + + printf("Input autoscan mode (0:exponential, 1:periodic): \n"); + rv = scanf(" %9d", &mode); + + if (rv <= 0) { + printf("Invalid input!\n"); + return -1; + } + + rv = wifi_manager_get_autoscan_interval(wifi, mode, &autoscan_interval); + + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Fail to get auto scan interval [%s]\n", wman_test_strerror(rv)); + return -1; + } + + printf("Auto Scan Interval: %d\n", autoscan_interval); + return 1; +} + int wman_test_flush_bss(wifi_manager_h wifi) { int rv; diff --git a/tools/manager-test/wman_test_extension.h b/tools/manager-test/wman_test_extension.h index 0aa651e..1ed4047 100644 --- a/tools/manager-test/wman_test_extension.h +++ b/tools/manager-test/wman_test_extension.h @@ -19,8 +19,10 @@ int wman_test_set_autoscan_state(wifi_manager_h wifi); int wman_test_set_autoscan_mode(wifi_manager_h wifi); +int wman_test_set_autoscan_interval(wifi_manager_h wifi); int wman_test_get_autoscan_state(wifi_manager_h wifi); int wman_test_get_autoscan_mode(wifi_manager_h wifi); +int wman_test_get_autoscan_interval(wifi_manager_h wifi); int wman_test_flush_bss(wifi_manager_h wifi); int wman_test_set_auto_connect(wifi_manager_h wifi); int wman_test_get_auto_connect(wifi_manager_h wifi); diff --git a/tools/manager-test/wman_test_main.c b/tools/manager-test/wman_test_main.c index d1b9d6d..d84c44d 100644 --- a/tools/manager-test/wman_test_main.c +++ b/tools/manager-test/wman_test_main.c @@ -337,6 +337,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("- - Get power-save mode\n"); printf("= - Set power-save mode\n"); #endif /* TIZEN_DA */ + printf("[ - Get Interval of Auto Scan\n"); + printf("] - Set Interval of Auto Scan\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -564,6 +566,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) rv = wman_test_set_power_save_mode(wifi); break; #endif /* TIZEN_DA */ + case '[': + rv = wman_test_get_autoscan_interval(wifi); + break; + case ']': + rv = wman_test_set_autoscan_interval(wifi); + break; default: break; }