|
@@ -3556,6 +3556,8 @@ struct global_parse_data {
|
|
|
char *name;
|
|
|
int (*parser)(const struct global_parse_data *data,
|
|
|
struct wpa_config *config, int line, const char *value);
|
|
|
+ int (*get)(const char *name, struct wpa_config *config, long offset,
|
|
|
+ char *buf, size_t buflen, int pretty_print);
|
|
|
void *param1, *param2, *param3;
|
|
|
unsigned int changed_flag;
|
|
|
};
|
|
@@ -4015,22 +4017,55 @@ static int wpa_config_process_no_ctrl_interface(
|
|
|
#endif /* CONFIG_CTRL_IFACE */
|
|
|
|
|
|
|
|
|
+static int wpa_config_get_int(const char *name, struct wpa_config *config,
|
|
|
+ long offset, char *buf, size_t buflen,
|
|
|
+ int pretty_print)
|
|
|
+{
|
|
|
+ int *val = (int *) (((u8 *) config) + (long) offset);
|
|
|
+
|
|
|
+ if (pretty_print)
|
|
|
+ return os_snprintf(buf, buflen, "%s=%d\n", name, *val);
|
|
|
+ return os_snprintf(buf, buflen, "%d", *val);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+static int wpa_config_get_str(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)
|
|
|
+ res = os_snprintf(buf, buflen, "%s=%s\n", name,
|
|
|
+ *val ? *val : "null");
|
|
|
+ else if (!*val)
|
|
|
+ return -1;
|
|
|
+ else
|
|
|
+ res = os_snprintf(buf, buflen, "%s", *val);
|
|
|
+ if (os_snprintf_error(buflen, res))
|
|
|
+ res = -1;
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
#ifdef OFFSET
|
|
|
#undef OFFSET
|
|
|
#endif /* OFFSET */
|
|
|
/* OFFSET: Get offset of a variable within the wpa_config structure */
|
|
|
#define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
|
|
|
|
|
|
-#define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
|
|
|
-#define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
|
|
|
-#define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
|
|
|
+#define FUNC(f) #f, wpa_config_process_ ## f, NULL, 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
|
|
|
#define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
|
|
|
-#define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
|
|
|
+#define _STR(f) #f, wpa_global_config_parse_str, wpa_config_get_str, OFFSET(f)
|
|
|
#define STR(f) _STR(f), NULL, NULL
|
|
|
#define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
|
|
|
-#define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
|
|
|
-#define IPV4(f) #f, wpa_global_config_parse_ipv4, OFFSET(f), NULL, NULL
|
|
|
+#define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
|
|
|
+#define IPV4(f) #f, wpa_global_config_parse_ipv4, NULL, OFFSET(f), NULL, NULL
|
|
|
|
|
|
static const struct global_parse_data global_fields[] = {
|
|
|
#ifdef CONFIG_CTRL_IFACE
|
|
@@ -4164,6 +4199,50 @@ static const struct global_parse_data global_fields[] = {
|
|
|
#define NUM_GLOBAL_FIELDS ARRAY_SIZE(global_fields)
|
|
|
|
|
|
|
|
|
+int wpa_config_dump_values(struct wpa_config *config, char *buf, size_t buflen)
|
|
|
+{
|
|
|
+ int result = 0;
|
|
|
+ size_t i;
|
|
|
+
|
|
|
+ for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
|
|
|
+ const struct global_parse_data *field = &global_fields[i];
|
|
|
+ int tmp;
|
|
|
+
|
|
|
+ if (!field->get)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ tmp = field->get(field->name, config, (long) field->param1,
|
|
|
+ buf, buflen, 1);
|
|
|
+ if (tmp < 0)
|
|
|
+ return -1;
|
|
|
+ buf += tmp;
|
|
|
+ buflen -= tmp;
|
|
|
+ result += tmp;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int wpa_config_get_value(const char *name, struct wpa_config *config,
|
|
|
+ char *buf, size_t buflen)
|
|
|
+{
|
|
|
+ size_t i;
|
|
|
+
|
|
|
+ for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
|
|
|
+ const struct global_parse_data *field = &global_fields[i];
|
|
|
+
|
|
|
+ if (os_strcmp(name, field->name) != 0)
|
|
|
+ continue;
|
|
|
+ if (!field->get)
|
|
|
+ break;
|
|
|
+ return field->get(name, config, (long) field->param1,
|
|
|
+ buf, buflen, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
|
|
|
{
|
|
|
size_t i;
|