diff mbox series

p2p: call normal SD query callback on RX/TX race

Message ID 20240417124524.2027615-1-andrei.otcheretianski@intel.com
State Accepted
Headers show
Series p2p: call normal SD query callback on RX/TX race | expand

Commit Message

Andrei Otcheretianski April 17, 2024, 12:45 p.m. UTC
From: Benjamin Berg <benjamin.berg@intel.com>

If the TX success response races with the RX frame then the state
machine was simply move to P2P_SD_DURING_FIND to continue the operation.
However, this does not take into account broadcast queries where the
callback handler updates the peer's sd_pending_bcast_queries.

Fix this by exporting the callback and calling it directly. This is
fine, as the operation is cancelled immediately afterwards, ensuring
that the callback is not called a second time.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
 src/p2p/p2p.c    | 4 ++--
 src/p2p/p2p_i.h  | 3 +++
 src/p2p/p2p_sd.c | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

Comments

Jouni Malinen April 21, 2024, 9:08 a.m. UTC | #1
On Wed, Apr 17, 2024 at 03:45:24PM +0300, Andrei Otcheretianski wrote:
> If the TX success response races with the RX frame then the state
> machine was simply move to P2P_SD_DURING_FIND to continue the operation.
> However, this does not take into account broadcast queries where the
> callback handler updates the peer's sd_pending_bcast_queries.
> 
> Fix this by exporting the callback and calling it directly. This is
> fine, as the operation is cancelled immediately afterwards, ensuring
> that the callback is not called a second time.

Thanks, applied.
diff mbox series

Patch

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index bb1938dc31..8e0fc35dfb 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -3332,7 +3332,7 @@  skip_sd:
 }
 
 
-static void p2p_sd_cb(struct p2p_data *p2p, int success)
+void p2p_sd_query_cb(struct p2p_data *p2p, int success)
 {
 	p2p_dbg(p2p, "Service Discovery Query TX callback: success=%d",
 		success);
@@ -3835,7 +3835,7 @@  void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
 		p2p_go_neg_conf_cb(p2p, result);
 		break;
 	case P2P_PENDING_SD:
-		p2p_sd_cb(p2p, success);
+		p2p_sd_query_cb(p2p, success);
 		break;
 	case P2P_PENDING_PD:
 		p2p_prov_disc_cb(p2p, success);
diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h
index 2612be5ad3..0a487e0316 100644
--- a/src/p2p/p2p_i.h
+++ b/src/p2p/p2p_i.h
@@ -899,6 +899,9 @@  void p2p_pref_channel_filter(const struct p2p_channels *a,
 			     const struct weighted_pcl *freq_list,
 			     unsigned int num_channels,
 			     struct p2p_channels *res, bool go);
+
+void p2p_sd_query_cb(struct p2p_data *p2p, int success);
+
 void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...)
 PRINTF_FORMAT(2, 3);
 void p2p_info(struct p2p_data *p2p, const char *fmt, ...)
diff --git a/src/p2p/p2p_sd.c b/src/p2p/p2p_sd.c
index d6882e4a32..5537a6eaaf 100644
--- a/src/p2p/p2p_sd.c
+++ b/src/p2p/p2p_sd.c
@@ -502,7 +502,7 @@  void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
 		 * 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_sd_query_cb(p2p, 1);
 	}
 	p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
 	p2p_clear_timeout(p2p);