From 43c693c21ae8aaa3e52b02ef43d854cbbcea2bd9 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 1 Sep 2013 17:47:05 +0300 Subject: [PATCH] P2P: Do not store duplicate PSK entries for the same device If a client joins a P2P group multiple times, replace the previous per-client PSK entry instead of adding a new entry each time. Signed-hostap: Jouni Malinen --- wpa_supplicant/p2p_supplicant.c | 68 ++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index f87cc7fc9..62d3b64e4 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -6034,6 +6034,33 @@ void wpas_p2p_continue_after_scan(struct wpa_supplicant *wpa_s) } +static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, + struct wpa_ssid *s, const u8 *addr, + int iface_addr) +{ + struct psk_list_entry *psk, *tmp; + int changed = 0; + + dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, + list) { + if ((iface_addr && !psk->p2p && + os_memcmp(addr, psk->addr, ETH_ALEN) == 0) || + (!iface_addr && psk->p2p && + os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) { + wpa_dbg(wpa_s, MSG_DEBUG, + "P2P: Remove persistent group PSK list entry for " + MACSTR " p2p=%u", + MAC2STR(psk->addr), psk->p2p); + dl_list_del(&psk->list); + os_free(psk); + changed++; + } + } + + return changed; +} + + void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, const u8 *p2p_dev_addr, const u8 *psk, size_t psk_len) @@ -6111,6 +6138,16 @@ void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, os_free(last); } + wpas_p2p_remove_psk_entry(wpa_s->parent, persistent, + p2p_dev_addr ? p2p_dev_addr : mac_addr, + p2p_dev_addr == NULL); + if (p2p_dev_addr) { + wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" + MACSTR, MAC2STR(p2p_dev_addr)); + } else { + wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, + MAC2STR(mac_addr)); + } dl_list_add(&persistent->psk_list, &p->list); #ifndef CONFIG_NO_CONFIG_WRITE @@ -6125,32 +6162,17 @@ static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, struct wpa_ssid *s, const u8 *addr, int iface_addr) { - struct psk_list_entry *psk, *tmp; - int changed = 0; - - dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, - list) { - if ((iface_addr && !psk->p2p && - os_memcmp(addr, psk->addr, ETH_ALEN) == 0) || - (!iface_addr && psk->p2p && - os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) { - wpa_dbg(wpa_s, MSG_DEBUG, - "P2P: Remove persistent group PSK list entry for " - MACSTR " p2p=%u", - MAC2STR(psk->addr), psk->p2p); - dl_list_del(&psk->list); - os_free(psk); - changed++; - } - } - + int res; + res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); + if (res > 0) { #ifndef CONFIG_NO_CONFIG_WRITE - if (changed && wpa_s->conf->update_config && - wpa_config_write(wpa_s->confname, wpa_s->conf)) - wpa_dbg(wpa_s, MSG_DEBUG, - "P2P: Failed to update configuration"); + if (wpa_s->conf->update_config && + wpa_config_write(wpa_s->confname, wpa_s->conf)) + wpa_dbg(wpa_s, MSG_DEBUG, + "P2P: Failed to update configuration"); #endif /* CONFIG_NO_CONFIG_WRITE */ + } }