Merge hostapd driver init functions into one
[wpasupplicant] / wpa_supplicant / config_file.c
index a94f31d..29e494c 100644 (file)
@@ -286,6 +286,23 @@ static int wpa_config_parse_int(const struct global_parse_data *data,
        dst = (int *) (((u8 *) config) + (long) data->param1);
        *dst = atoi(pos);
        wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
+
+       if (data->param2 && *dst < (long) data->param2) {
+               wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
+                          "min_value=%ld)", line, data->name, *dst,
+                          (long) data->param2);
+               *dst = (long) data->param2;
+               return -1;
+       }
+
+       if (data->param3 && *dst > (long) data->param3) {
+               wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
+                          "max_value=%ld)", line, data->name, *dst,
+                          (long) data->param3);
+               *dst = (long) data->param3;
+               return -1;
+       }
+
        return 0;
 }
 
@@ -341,21 +358,6 @@ static int wpa_config_process_country(const struct global_parse_data *data,
 }
 
 
-static int wpa_config_process_eapol_version(
-       const struct global_parse_data *data, struct wpa_config *config,
-       int line, const char *pos)
-{
-       config->eapol_version = atoi(pos);
-       if (config->eapol_version < 1 || config->eapol_version > 2) {
-               wpa_printf(MSG_ERROR, "Line %d: Invalid EAPOL version (%d): "
-                          "'%s'.", line, config->eapol_version, pos);
-               return -1;
-       }
-       wpa_printf(MSG_DEBUG, "eapol_version=%d", config->eapol_version);
-       return 0;
-}
-
-
 static int wpa_config_process_load_dynamic_eap(
        const struct global_parse_data *data, struct wpa_config *config,
        int line, const char *so)
@@ -417,7 +419,9 @@ static int wpa_config_process_os_version(const struct global_parse_data *data,
 
 #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_config_parse_int, OFFSET(f), NULL, NULL
+#define _INT(f) #f, wpa_config_parse_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_config_parse_str, OFFSET(f)
 #define STR(f) _STR(f), NULL, NULL
 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
@@ -427,7 +431,7 @@ static const struct global_parse_data global_fields[] = {
        { STR(ctrl_interface) },
        { STR(ctrl_interface_group) } /* deprecated */,
 #endif /* CONFIG_CTRL_IFACE */
-       { FUNC(eapol_version) },
+       { INT_RANGE(eapol_version, 1, 2) },
        { INT(ap_scan) },
        { INT(fast_reauth) },
 #ifdef EAP_TLS_OPENSSL
@@ -452,12 +456,15 @@ static const struct global_parse_data global_fields[] = {
        { STR_RANGE(serial_number, 0, 32) },
        { STR(device_type) },
        { FUNC(os_version) },
+       { INT_RANGE(wps_cred_processing, 0, 2) },
 #endif /* CONFIG_WPS */
        { FUNC(country) }
 };
 
 #undef FUNC
+#undef _INT
 #undef INT
+#undef INT_RANGE
 #undef _STR
 #undef STR
 #undef STR_RANGE
@@ -855,7 +862,7 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
        if (config->update_config)
                fprintf(f, "update_config=%d\n", config->update_config);
 #ifdef CONFIG_WPS
-       if (is_nil_uuid(config->uuid)) {
+       if (!is_nil_uuid(config->uuid)) {
                char buf[40];
                uuid_bin2str(config->uuid, buf, sizeof(buf));
                fprintf(f, "uuid=%s\n", buf);
@@ -872,9 +879,12 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
                fprintf(f, "serial_number=%s\n", config->serial_number);
        if (config->device_type)
                fprintf(f, "device_type=%s\n", config->device_type);
-       if (config->os_version)
+       if (WPA_GET_BE32(config->os_version))
                fprintf(f, "os_version=%08x\n",
                        WPA_GET_BE32(config->os_version));
+       if (config->wps_cred_processing)
+               fprintf(f, "wps_cred_processing=%d\n",
+                       config->wps_cred_processing);
 #endif /* CONFIG_WPS */
        if (config->country[0] && config->country[1]) {
                fprintf(f, "country=%c%c\n",