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

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

index 0fead1f6937b10ac2d136f5675e89b7b9da17267..1feaff2c663435e8c2d669c9a131937b7051fa34 100644 (file)
@@ -1448,6 +1448,29 @@ static int * wpa_config_parse_int_array(const char *value)
 }
 
 
+static int wpa_config_print_int_array(char *buf, size_t buflen, int *array)
+{
+       int res, tmp;
+
+       if (!array)
+               return -1;
+
+       res = 0;
+       for (; *array != 0; array++) {
+               tmp = os_snprintf(buf + res, buflen - res, "%d ", *array);
+               if (os_snprintf_error(buflen - res, tmp))
+                       return -1;
+
+               res += tmp;
+       }
+       /* strip last space */
+       if (res > 0)
+               buf[--res] = '\0';
+
+       return res;
+}
+
+
 static int wpa_config_parse_scan_freq(const struct parse_data *data,
                                      struct wpa_ssid *ssid, int line,
                                      const char *value)
@@ -5454,6 +5477,45 @@ static int wpa_config_get_bgscan(const char *name, struct wpa_config *config,
 }
 
 
+static int wpa_config_get_freq_list(const char *name, struct wpa_config *config,
+                                   long offset, char *buf, size_t buflen,
+                                   int pretty_print)
+{
+       int **val = (int **) (((u8 *) config) + (long) offset);
+       int res, tmp;
+
+       if (pretty_print) {
+               if (*val) {
+                       res = os_snprintf(buf, buflen, "%s=", name);
+                       if (os_snprintf_error(buflen, res))
+                               return -1;
+
+                       tmp = wpa_config_print_int_array(buf + res,
+                                                        buflen - res, *val);
+                       if (tmp < 0)
+                               return -1;
+                       res += tmp;
+
+                       tmp = os_snprintf(buf + res, buflen - res, "\n");
+                       if (os_snprintf_error(buflen - res, tmp))
+                               return -1;
+                       res += tmp;
+               } else {
+                       res = os_snprintf(buf, buflen, "%s=null\n", name);
+               }
+
+       } else if (!*val) {
+               return -1;
+       } else {
+               res = wpa_config_print_int_array(buf, buflen, *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,
@@ -5665,7 +5727,7 @@ static const struct global_parse_data global_fields[] = {
        { FUNC(ap_assocresp_elements), 0 },
        { FUNC(ap_vendor_elements), 0 },
        { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
-       { FUNC(freq_list), 0 },
+       { FUNC_WITH_GET(freq_list), 0 },
        { FUNC(initial_freq_list), 0},
        { INT(scan_cur_freq), 0 },
        { INT(scan_res_valid_for_connect), 0},