From 38bb27bf65ccebbf5fc3a90f21d5357d1c68b33a Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Wed, 21 Dec 2022 16:14:41 +0900 Subject: [PATCH] Add dbus methods for setting bg scan interval Change-Id: Iae92268d8e8886b04101f9dfd266266040b07e9d Signed-off-by: Jaehyun Kim --- include/wifi-background-scan.h | 4 ++ include/wifi-scan.h | 10 ++- interfaces/netconfig-iface-wifi.xml | 10 +++ packaging/net-config.spec | 2 +- resources/etc/dbus-1/system.d/net-config.conf | 2 + src/wifi-background-scan.c | 93 ++++++++++++++++++++++++--- src/wifi-power.c | 2 +- src/wifi-scan.c | 72 ++++++++++++++++----- src/wifi-state.c | 6 +- src/wifi.c | 4 ++ 10 files changed, 171 insertions(+), 34 deletions(-) diff --git a/include/wifi-background-scan.h b/include/wifi-background-scan.h index 412bf79..62cf842 100755 --- a/include/wifi-background-scan.h +++ b/include/wifi-background-scan.h @@ -31,6 +31,10 @@ void netconfig_wifi_bgscan_stop(const char *interface_name); gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname, guint scan_mode); +gboolean handle_set_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *mode, guint interval); +gboolean handle_get_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *mode); gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname); gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context, diff --git a/include/wifi-scan.h b/include/wifi-scan.h index 9c5b090..c2ce305 100755 --- a/include/wifi-scan.h +++ b/include/wifi-scan.h @@ -28,10 +28,14 @@ extern "C" { #if defined TIZEN_WEARABLE #define SCAN_PERIODIC_DELAY 15 +#define SCAN_PERIODIC_DELAY_MIN 5 +#define SCAN_PERIODIC_DELAY_MAX 120 #define SCAN_EXPONENTIAL_MIN 5 #define SCAN_EXPONENTIAL_MAX 320 #else #define SCAN_PERIODIC_DELAY 10 +#define SCAN_PERIODIC_DELAY_MIN 5 +#define SCAN_PERIODIC_DELAY_MAX 120 #define SCAN_EXPONENTIAL_MIN 4 #define SCAN_EXPONENTIAL_MAX 128 #endif @@ -47,10 +51,12 @@ guint netconfig_wifi_scan_get_scanning(const char *interface_name); gboolean netconfig_wifi_bgscan_set_mode(const char *interface_name, guint mode); guint netconfig_wifi_bgscan_get_mode(const char *interface_name); +gboolean netconfig_wifi_bgscan_set_periodic_interval(const char *interface_name, guint interval); +guint netconfig_wifi_bgscan_get_periodic_interval(const char *interface_name); void netconfig_wifi_bgscan_set_timer_id(const char *interface_name, guint timer_id); guint netconfig_wifi_bgscan_get_timer_id(const char *interface_name); -gboolean netconfig_wifi_bgscan_set_interval(const char *interface_name, guint interval); -guint netconfig_wifi_bgscan_get_interval(const char *interface_name); +gboolean netconfig_wifi_bgscan_set_exp_interval(const char *interface_name, guint interval); +guint netconfig_wifi_bgscan_get_exp_interval(const char *interface_name); void netconfig_wifi_bgscan_set_pause(const char *interface_name, gboolean pause); gboolean netconfig_wifi_bgscan_is_paused(const char *interface_name); void netconfig_wifi_bgscan_start_timer(const char *interface_name, gboolean immediate_scan); diff --git a/interfaces/netconfig-iface-wifi.xml b/interfaces/netconfig-iface-wifi.xml index 78ee691..4095690 100755 --- a/interfaces/netconfig-iface-wifi.xml +++ b/interfaces/netconfig-iface-wifi.xml @@ -28,6 +28,16 @@ + + + + + + + + + + diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 1f68b29..55baacf 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.2.13 +Version: 1.2.14 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf index a8cb76b..5730ed9 100755 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -77,6 +77,8 @@ + + diff --git a/src/wifi-background-scan.c b/src/wifi-background-scan.c index ef1dd37..0aa25a7 100755 --- a/src/wifi-background-scan.c +++ b/src/wifi-background-scan.c @@ -32,6 +32,10 @@ void netconfig_wifi_bgscan_start(const char *interface_name, gboolean immediate_ { wifi_tech_state_e wifi_tech_state; wifi_service_state_e wifi_service_state; + int ug_state = VCONFKEY_WIFI_UG_RUN_STATE_OFF; + guint bg_mode = WIFI_BGSCAN_MODE_EXPONENTIAL; + + netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state); if (netconfig_wifi_bgscan_get_timer_id(interface_name) > 0) netconfig_wifi_bgscan_stop_timer(interface_name); @@ -45,8 +49,12 @@ void netconfig_wifi_bgscan_start(const char *interface_name, gboolean immediate_ if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) return; - if (netconfig_wifi_bgscan_get_mode(interface_name) == WIFI_BGSCAN_MODE_EXPONENTIAL && - wifi_service_state == NETCONFIG_WIFI_CONNECTED) + bg_mode = netconfig_wifi_bgscan_get_mode(interface_name); + + if (wifi_service_state == NETCONFIG_WIFI_CONNECTED && + (bg_mode == WIFI_BGSCAN_MODE_EXPONENTIAL || + (bg_mode == WIFI_BGSCAN_MODE_PERIODIC && + ug_state != VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND))) return; DBG("[%s] Wi-Fi background scan started or re-started(%d)", @@ -60,11 +68,22 @@ void netconfig_wifi_bgscan_stop(const char *interface_name) netconfig_wifi_bgscan_stop_timer(interface_name); } +void netconfig_wifi_bgscan_restart(const gchar *interface_name) +{ + int pm_state = VCONFKEY_PM_STATE_NORMAL; + + /* In case of LCD off, we don't need Wi-Fi scan right now */ + netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) + netconfig_wifi_bgscan_start(interface_name, FALSE); + else + netconfig_wifi_bgscan_start(interface_name, TRUE); +} + gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname, guint scan_mode) { gint old_mode = 0; - int pm_state = VCONFKEY_PM_STATE_NORMAL; old_mode = netconfig_wifi_bgscan_get_mode(ifname); if (old_mode == scan_mode) { @@ -80,17 +99,71 @@ gboolean handle_set_bgscan(Wifi *wifi, GDBusMethodInvocation *context, INFO("[%s] Wi-Fi scan mode is changed [%d]", ifname, scan_mode); - /* In case of LCD off, we don't need Wi-Fi scan right now */ - netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state); - if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) - netconfig_wifi_bgscan_start(ifname, FALSE); - else - netconfig_wifi_bgscan_start(ifname, TRUE); + netconfig_wifi_bgscan_restart(ifname); wifi_complete_set_bgscan(wifi, context); return TRUE; } +gboolean handle_set_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *mode, guint interval) +{ + guint old_interval = 0; + gboolean rv = FALSE; + + if (g_strcmp0(mode, "Periodic") == 0) { + old_interval = netconfig_wifi_bgscan_get_periodic_interval(ifname); + } else if (g_strcmp0(mode, "Exponential") == 0) { + old_interval = netconfig_wifi_bgscan_get_exp_interval(ifname); + } else { + ERR("invalid mode %s", mode); + netconfig_error_invalid_parameter(context); + return TRUE; + } + + if (old_interval == interval) { + wifi_complete_set_bgscan_interval(wifi, context); + return TRUE; + } + + if (g_strcmp0(mode, "Periodic") == 0) + rv = netconfig_wifi_bgscan_set_periodic_interval(ifname, interval); + else + rv = netconfig_wifi_bgscan_set_exp_interval(ifname, interval); + + if (!rv) { + netconfig_error_invalid_parameter(context); + return TRUE; + } + + INFO("[%s] Wi-Fi periodic scan interval is changed to [%d] from [%d]", + ifname, interval, old_interval); + + netconfig_wifi_bgscan_restart(ifname); + + wifi_complete_set_bgscan_interval(wifi, context); + return TRUE; +} + +gboolean handle_get_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, + const gchar *ifname, const gchar *mode) +{ + guint bgscan_interval = 0; + + if (g_strcmp0(mode, "Periodic") == 0) { + bgscan_interval = netconfig_wifi_bgscan_get_periodic_interval(ifname); + } else if (g_strcmp0(mode, "Exponential") == 0) { + bgscan_interval = netconfig_wifi_bgscan_get_exp_interval(ifname); + } else { + ERR("invalid mode %s", mode); + netconfig_error_invalid_parameter(context); + return TRUE; + } + + wifi_complete_get_bgscan_interval(wifi, context, bgscan_interval); + return TRUE; +} + gboolean handle_resume_bgscan(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname) { @@ -112,7 +185,7 @@ gboolean handle_pause_bgscan(Wifi *wifi, GDBusMethodInvocation *context, gboolean handle_reset_bgscan_interval(Wifi *wifi, GDBusMethodInvocation *context, const gchar *ifname) { - netconfig_wifi_bgscan_set_interval(ifname, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_set_exp_interval(ifname, SCAN_EXPONENTIAL_MIN); wifi_complete_reset_bgscan_interval(wifi, context); return TRUE; diff --git a/src/wifi-power.c b/src/wifi-power.c index 0cdfd8e..8c39985 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -604,7 +604,7 @@ static void __pm_state_changed_cb(keynode_t* node, void* user_data) DBG("Unset early suspend [%s]", device_data->interface_name); } netconfig_wifi_bgscan_stop(device_data->interface_name); - netconfig_wifi_bgscan_set_interval(device_data->interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_set_exp_interval(device_data->interface_name, SCAN_EXPONENTIAL_MIN); netconfig_wifi_bgscan_start(device_data->interface_name, TRUE); } } else if ((new_state == VCONFKEY_PM_STATE_LCDOFF) && (prev_state < VCONFKEY_PM_STATE_LCDOFF) && (wifi_state != VCONFKEY_WIFI_OFF)) { diff --git a/src/wifi-scan.c b/src/wifi-scan.c index c8669bd..8d4dd7f 100755 --- a/src/wifi-scan.c +++ b/src/wifi-scan.c @@ -31,7 +31,8 @@ typedef struct { const char *interface_name; /* background scan */ - guint bg_interval; + guint bg_exp_interval; + guint bg_periodic_interval; guint bg_mode; guint bg_timer_id; gboolean bg_paused; @@ -59,7 +60,8 @@ static scan_data_s *__wifi_scan_create_data(const char *interface_name) scan_data->scanning = FALSE; - scan_data->bg_interval = SCAN_EXPONENTIAL_MIN; + scan_data->bg_exp_interval = SCAN_EXPONENTIAL_MIN; + scan_data->bg_periodic_interval = SCAN_PERIODIC_DELAY; scan_data->bg_mode = WIFI_BGSCAN_MODE_EXPONENTIAL; scan_data->bg_timer_id = 0; scan_data->bg_paused = FALSE; @@ -135,6 +137,33 @@ guint netconfig_wifi_bgscan_get_mode(const char *interface_name) return scan_data->bg_mode; } +guint netconfig_wifi_bgscan_get_periodic_interval(const char *interface_name) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return 0; + + return scan_data->bg_periodic_interval; +} + +gboolean netconfig_wifi_bgscan_set_periodic_interval(const char *interface_name, guint interval) +{ + scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + + if (!scan_data) + return FALSE; + + if ((interval < SCAN_PERIODIC_DELAY_MIN) || (interval > SCAN_PERIODIC_DELAY_MAX)) { + ERR("Invalid interval [%d]", interval); + return FALSE; + } + + scan_data->bg_periodic_interval = interval; + + return TRUE; +} + void netconfig_wifi_bgscan_set_timer_id(const char *interface_name, guint timer_id) { scan_data_s *scan_data = __wifi_scan_get_data(interface_name); @@ -155,7 +184,7 @@ guint netconfig_wifi_bgscan_get_timer_id(const char *interface_name) return scan_data->bg_timer_id; } -gboolean netconfig_wifi_bgscan_set_interval(const char *interface_name, guint interval) +gboolean netconfig_wifi_bgscan_set_exp_interval(const char *interface_name, guint interval) { scan_data_s *scan_data = __wifi_scan_get_data(interface_name); @@ -167,19 +196,19 @@ gboolean netconfig_wifi_bgscan_set_interval(const char *interface_name, guint in return FALSE; } - scan_data->bg_interval = interval; + scan_data->bg_exp_interval = interval; return TRUE; } -guint netconfig_wifi_bgscan_get_interval(const char *interface_name) +guint netconfig_wifi_bgscan_get_exp_interval(const char *interface_name) { scan_data_s *scan_data = __wifi_scan_get_data(interface_name); if (!scan_data) return SCAN_EXPONENTIAL_MIN; - return scan_data->bg_interval; + return scan_data->bg_exp_interval; } void netconfig_wifi_bgscan_set_pause(const char *interface_name, gboolean pause) @@ -261,10 +290,14 @@ static gboolean __wifi_bgscan_immediate_scan(gpointer data) static int retries = 0; scan_data_s *scan_data = data; guint state = 0; + int ug_state = VCONFKEY_WIFI_UG_RUN_STATE_OFF; + guint bg_mode = WIFI_BGSCAN_MODE_EXPONENTIAL; if (!scan_data) return FALSE; + netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state); + state = wifi_state_get_service_state(scan_data->interface_name); #if !defined TIZEN_WEARABLE @@ -274,7 +307,10 @@ static gboolean __wifi_bgscan_immediate_scan(gpointer data) #endif if (state == NETCONFIG_WIFI_CONNECTED) { - if (netconfig_wifi_bgscan_get_mode(scan_data->interface_name) == WIFI_BGSCAN_MODE_EXPONENTIAL) { + bg_mode = netconfig_wifi_bgscan_get_mode(scan_data->interface_name); + if (bg_mode == WIFI_BGSCAN_MODE_EXPONENTIAL || + (bg_mode == WIFI_BGSCAN_MODE_PERIODIC && + ug_state != VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)) { DBG("[%s] Wi-Fi state is connected, scan is paused", scan_data->interface_name); return FALSE; } @@ -309,9 +345,9 @@ static gboolean __wifi_bgscan_next_scan(gpointer data) return FALSE; if (scan_data->bg_mode == WIFI_BGSCAN_MODE_EXPONENTIAL) { - scan_data->bg_interval = scan_data->bg_interval * 2; - if (scan_data->bg_interval > SCAN_EXPONENTIAL_MAX) - scan_data->bg_interval = SCAN_EXPONENTIAL_MAX; + scan_data->bg_exp_interval = scan_data->bg_exp_interval * 2; + if (scan_data->bg_exp_interval > SCAN_EXPONENTIAL_MAX) + scan_data->bg_exp_interval = SCAN_EXPONENTIAL_MAX; } /* In case of LCD off, we don't need Wi-Fi scan */ @@ -327,6 +363,7 @@ static gboolean __wifi_bgscan_next_scan(gpointer data) void netconfig_wifi_bgscan_start_timer(const char *interface_name, gboolean immediate_scan) { scan_data_s *scan_data = __wifi_scan_get_data(interface_name); + guint bg_interval = 0; if (!scan_data) return; @@ -335,12 +372,13 @@ void netconfig_wifi_bgscan_start_timer(const char *interface_name, gboolean imme switch (scan_data->bg_mode) { case WIFI_BGSCAN_MODE_EXPONENTIAL: - if (scan_data->bg_interval < SCAN_EXPONENTIAL_MIN || - scan_data->bg_interval == SCAN_PERIODIC_DELAY) - scan_data->bg_interval = SCAN_EXPONENTIAL_MIN; + if (scan_data->bg_exp_interval < SCAN_EXPONENTIAL_MIN) + scan_data->bg_exp_interval = SCAN_EXPONENTIAL_MIN; + + bg_interval = scan_data->bg_exp_interval; break; case WIFI_BGSCAN_MODE_PERIODIC: - scan_data->bg_interval = SCAN_PERIODIC_DELAY; + bg_interval = scan_data->bg_periodic_interval; break; default: DBG("Invalid Wi-Fi background scan mode[%d]", scan_data->bg_mode); @@ -349,15 +387,15 @@ void netconfig_wifi_bgscan_start_timer(const char *interface_name, gboolean imme if (immediate_scan) DBG("[%s] Scan immediately[%d], mode[%d](0 exponential / 1 periodic), next[%d]", - interface_name, immediate_scan, scan_data->bg_mode, scan_data->bg_interval); + interface_name, immediate_scan, scan_data->bg_mode, bg_interval); else DBG("[%s] Scan immediately[%d], mode[%d](0 exponential / 1 periodic), next[%d]", - interface_name, immediate_scan, scan_data->bg_mode, scan_data->bg_interval); + interface_name, immediate_scan, scan_data->bg_mode, bg_interval); if (immediate_scan) g_timeout_add(500, __wifi_bgscan_immediate_scan, scan_data); - netconfig_start_timer_seconds(scan_data->bg_interval, + netconfig_start_timer_seconds(bg_interval, __wifi_bgscan_next_scan, scan_data, &(scan_data->bg_timer_id)); } diff --git a/src/wifi-state.c b/src/wifi-state.c index ca96391..81c0d6b 100755 --- a/src/wifi-state.c +++ b/src/wifi-state.c @@ -532,7 +532,7 @@ void wifi_state_update_power_state(const char *interface_name, gboolean powered) netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON); netconfig_wifi_bgscan_stop(interface_name); - netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_set_exp_interval(interface_name, SCAN_EXPONENTIAL_MIN); netconfig_wifi_bgscan_start(interface_name, TRUE); /* Add callback to track change in notification setting */ @@ -798,7 +798,7 @@ void wifi_state_set_service_state(const char *interface_name, netconfig_wifi_indicator_stop(interface_name); netconfig_wifi_bgscan_stop(interface_name); - netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_set_exp_interval(interface_name, SCAN_EXPONENTIAL_MIN); netconfig_wifi_bgscan_start(interface_name, TRUE); } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE) { /* in ipv6 case disconnect/association -> association */ @@ -809,7 +809,7 @@ void wifi_state_set_service_state(const char *interface_name, } else if (old_state == NETCONFIG_WIFI_FAILURE && new_state == NETCONFIG_WIFI_IDLE) { DBG("reset the bg scan period, in failure case"); netconfig_wifi_bgscan_stop(interface_name); - netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN); + netconfig_wifi_bgscan_set_exp_interval(interface_name, SCAN_EXPONENTIAL_MIN); netconfig_wifi_bgscan_start(interface_name, FALSE); } diff --git a/src/wifi.c b/src/wifi.c index 0820554..9486422 100755 --- a/src/wifi.c +++ b/src/wifi.c @@ -296,6 +296,10 @@ void wifi_object_create_and_init(void) /* BG scan mode */ g_signal_connect(wifi_object, "handle-set-bgscan", G_CALLBACK(handle_set_bgscan), NULL); + g_signal_connect(wifi_object, "handle-set-bgscan-interval", + G_CALLBACK(handle_set_bgscan_interval), NULL); + g_signal_connect(wifi_object, "handle-get-bgscan-interval", + G_CALLBACK(handle_get_bgscan_interval), NULL); g_signal_connect(wifi_object, "handle-resume-bgscan", G_CALLBACK(handle_resume_bgscan), NULL); g_signal_connect(wifi_object, "handle-pause-bgscan", -- 2.7.4