Add APIs for setting background scan interval 72/285872/3
authorJaehyun Kim <jeik01.kim@samsung.com>
Thu, 22 Dec 2022 03:44:38 +0000 (12:44 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Thu, 22 Dec 2022 09:27:09 +0000 (18:27 +0900)
Change-Id: Ia71290f860cecb876fae398bab15979783d27a8b
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
12 files changed:
include/wifi-manager-extension.h
packaging/capi-network-wifi-manager.spec
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 7816134605fd28f5a2d30037e904aeea0a84cc72..d96d4d79befc9ac64fbae2a436cc8c5d011e1360 100644 (file)
@@ -325,6 +325,49 @@ int wifi_manager_set_autoscan_mode(wifi_manager_h wifi,
 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
index ab11824cd1f4a758344cc8e2fcff2a2144d1c4a3..3a6880e4d7b21cfe51868a6393731424949fb4b6 100644 (file)
@@ -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
index 129a83416f5a1c29339efeb691098042a5938986..d31e36a2f06feec3384550dfc22ec6ee8d01e9fc 100644 (file)
@@ -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)
 {
index d617292cfa921d6ec613afd751c557c0ad0f64e2..a97a400fdd615a32b9b4a4cdf8e02611021aad68 100644 (file)
@@ -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,
index d5ee6fd1554ed64bf5dcd9b0e8184c75286f844c..a4adaae4d90d546ed5c1c95bbe583dc821c4745d 100644 (file)
@@ -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;
index b07c351512f1396d9d618c3d3624fc486adfce8d..d215e40deb9aa8c5e2948fc013dcf0e3a710a5e2 100644 (file)
@@ -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);
index 6deafd35effbf30b72f32e6a12bcbb6835e86dc8..8e7b302ef422cc3765e57509d9ebab543f5cff96 100644 (file)
@@ -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;
index 8b13efe55b1baa7a97d92926c09ac41ac882e7fc..74567be9954cdb171321776bfe096827e942e7f5 100644 (file)
@@ -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);
index 1fad8ee8b9840044112ae226c179bcdaf6586bc5..84bab68f6587de6a3dab1e5d4e8a07cd8cb388f7 100644 (file)
@@ -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__;
index 50832af8085f066b5e15f078bb462d167f52f434..ff199c7f02e61e00251025598dfc1343f55cd7e1 100644 (file)
@@ -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;
index 0aa651edb02d21c02954cc681339c51c8e1c7430..1ed40476bb9ff006b6b73c263a82f775fd486e13 100644 (file)
 
 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);
index d1b9d6dee21cf4649adef3eeab233879ca80fd04..d84c44d3ee4097c608a2b80cd3a3444e8e0ad6dc 100644 (file)
@@ -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;
        }