From 576f462504dbf0b7dd5c5f9195bab0cbe1860d70 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 26 Jan 2024 17:12:16 +0200 Subject: [PATCH] P2P: Accept P2P SD response without TX status If a GAS response is received for a pending SD query, process it even if the TX status event for the query has not yet been received. It is possible for the TX status and RX events to be reordered especially when using UML time-travel, so this is needed to avoid race conditions to make SD more robust. Signed-off-by: Jouni Malinen --- src/p2p/p2p_sd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/p2p/p2p_sd.c b/src/p2p/p2p_sd.c index 050b6fd88..d6882e4a3 100644 --- a/src/p2p/p2p_sd.c +++ b/src/p2p/p2p_sd.c @@ -489,12 +489,21 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa, u16 slen; u16 update_indic; - if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL || + if ((p2p->state != P2P_SD_DURING_FIND && p2p->state != P2P_SEARCH) || + !p2p->sd_peer || !ether_addr_equal(sa, p2p->sd_peer->info.p2p_device_addr)) { p2p_dbg(p2p, "Ignore unexpected GAS Initial Response from " MACSTR, MAC2STR(sa)); return; } + if (p2p->state == P2P_SEARCH) { + /* It is possible for the TX status and RX response events to be + * reordered, so assume the request was ACKed if a response is + * received. */ + p2p_dbg(p2p, + "GAS Initial Request had not yet received TX status - process the response anyway"); + p2p_set_state(p2p, P2P_SD_DURING_FIND); + } p2p->cfg->send_action_done(p2p->cfg->cb_ctx); p2p_clear_timeout(p2p);