From 2bab073dfe0294618d2ef5dd04a0104ac6095ec6 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 15 Feb 2020 17:30:41 +0200 Subject: [PATCH] WPS: Add new PSK entries with wps=1 tag Now that hostapd wpa_psk_file has a new tag for identifying PSKs that can be used with WPS, add that tag to new entries for PSKs from WPS. This makes it clearer where the PSK came from and in addition, this allows the same PSK to be assigned if the same Enrollee goes through WPS provisioning again. Signed-off-by: Jouni Malinen --- src/ap/wps_hostapd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c index 35e5772af..7b143b821 100644 --- a/src/ap/wps_hostapd.c +++ b/src/ap/wps_hostapd.c @@ -137,16 +137,17 @@ static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, if (ssid->wpa_psk_file) { FILE *f; char hex[PMK_LEN * 2 + 1]; + /* Add the new PSK to PSK list file */ f = fopen(ssid->wpa_psk_file, "a"); - if (f == NULL) { - wpa_printf(MSG_DEBUG, "Failed to add the PSK to " - "'%s'", ssid->wpa_psk_file); + if (!f) { + wpa_printf(MSG_DEBUG, "Failed to add the PSK to '%s'", + ssid->wpa_psk_file); return -1; } wpa_snprintf_hex(hex, sizeof(hex), psk, psk_len); - fprintf(f, MACSTR " %s\n", MAC2STR(mac_addr), hex); + fprintf(f, "wps=1 " MACSTR " %s\n", MAC2STR(mac_addr), hex); fclose(f); }