]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add get function for global bgscan value
authorClemens Famulla-Conrad <cfamullaconrad@suse.com>
Thu, 24 Jul 2025 16:03:59 +0000 (18:03 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 30 Sep 2025 20:21:14 +0000 (23:21 +0300)
Add a get() function for the global bgscan configuration value. This
allow `wpa_cli dump` and `wpa_cli get bgscan` return the current value.
If the value isn't set, the `wpa_cli dump` will output "bgscan=null" and
`wpa_cli get bgscan` will fail, similar to STR() values.

Signed-off-by: Clemens Famulla-Conrad <cfamullaconrad@suse.com>
wpa_supplicant/config.c

index a0f71cfc6ecc670b26474a0468c8d5dc4a1d850b..0fead1f6937b10ac2d136f5675e89b7b9da17267 100644 (file)
@@ -5429,6 +5429,31 @@ static int wpa_config_get_str(const char *name, struct wpa_config *config,
 }
 
 
+static int wpa_config_get_bgscan(const char *name, struct wpa_config *config,
+                                long offset, char *buf, size_t buflen,
+                                int pretty_print)
+{
+       char **val = (char **) (((u8 *) config) + (long) offset);
+       int res;
+
+       if (pretty_print) {
+               if (*val)
+                       res = os_snprintf(buf, buflen, "%s=\"%s\"\n", name,
+                                         *val);
+               else
+                       res = os_snprintf(buf, buflen, "%s=null\n", name);
+       } else if (!*val) {
+               return -1;
+       } else {
+               res = os_snprintf(buf, buflen, "\"%s\"", *val);
+       }
+       if (os_snprintf_error(buflen, res))
+               res = -1;
+
+       return res;
+}
+
+
 #ifdef CONFIG_P2P
 static int wpa_config_get_ipv4(const char *name, struct wpa_config *config,
                               long offset, char *buf, size_t buflen,
@@ -5478,6 +5503,8 @@ static int wpa_config_process_mld_connect_bssid_pref(
 #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
 
 #define FUNC(f) #f, wpa_config_process_ ## f, NULL, OFFSET(f), NULL, NULL
+#define FUNC_WITH_GET(f) #f, wpa_config_process_ ## f, wpa_config_get_ ## f, \
+               OFFSET(f), NULL, NULL
 #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL, NULL
 #define _INT(f) #f, wpa_global_config_parse_int, wpa_config_get_int, OFFSET(f)
 #define INT(f) _INT(f), NULL, NULL
@@ -5504,7 +5531,7 @@ static const struct global_parse_data global_fields[] = {
        { INT_RANGE(eapol_version, 1, 2), 0 },
 #endif /* CONFIG_MACSEC */
        { INT(ap_scan), 0 },
-       { FUNC(bgscan), CFG_CHANGED_BGSCAN },
+       { FUNC_WITH_GET(bgscan), CFG_CHANGED_BGSCAN },
 #ifdef CONFIG_MESH
        { INT(user_mpm), 0 },
        { INT_RANGE(max_peer_links, 0, 255), 0 },