From 80d9756956d369f3ad4f27cbadd98b6c4f619d21 Mon Sep 17 00:00:00 2001 From: Disha Das Date: Thu, 15 Apr 2021 18:51:06 +0530 Subject: [PATCH] DPP2: Get DPP Relay Controller context based on hostapd callback context Get the DPP Relay Controller context from the list of configured Controllers based on the correct hostapd callback context. This is needed to pick the correct hostapd interface for sending out the response over air, e.g., when the same hostapd process controls a 2.4 GHz only and a 5 GHz only interface. Signed-off-by: Disha Das --- src/ap/dpp_hostapd.c | 9 +++++---- src/common/dpp.h | 3 ++- src/common/dpp_tcp.c | 24 +++++++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/ap/dpp_hostapd.c b/src/ap/dpp_hostapd.c index aaeb94c2f..93ffd8cf7 100644 --- a/src/ap/dpp_hostapd.c +++ b/src/ap/dpp_hostapd.c @@ -757,7 +757,7 @@ static void hostapd_dpp_rx_auth_req(struct hostapd_data *hapd, const u8 *src, if (!own_bi) { if (dpp_relay_rx_action(hapd->iface->interfaces->dpp, src, hdr, buf, len, freq, i_bootstrap, - r_bootstrap) == 0) + r_bootstrap, hapd) == 0) return; } #endif /* CONFIG_DPP2 */ @@ -1276,7 +1276,7 @@ hostapd_dpp_rx_presence_announcement(struct hostapd_data *hapd, const u8 *src, if (!peer_bi) { if (dpp_relay_rx_action(hapd->iface->interfaces->dpp, src, hdr, buf, len, freq, NULL, - r_bootstrap) == 0) + r_bootstrap, hapd) == 0) return; wpa_printf(MSG_DEBUG, "DPP: No matching bootstrapping information found"); @@ -1366,7 +1366,7 @@ hostapd_dpp_rx_reconfig_announcement(struct hostapd_data *hapd, const u8 *src, if (!conf) { if (dpp_relay_rx_action(hapd->iface->interfaces->dpp, src, hdr, buf, len, freq, NULL, - NULL) == 0) + NULL, hapd) == 0) return; wpa_printf(MSG_DEBUG, "DPP: No matching Configurator information found"); @@ -1892,7 +1892,8 @@ void hostapd_dpp_rx_action(struct hostapd_data *hapd, const u8 *src, #ifdef CONFIG_DPP2 if (dpp_relay_rx_action(hapd->iface->interfaces->dpp, - src, hdr, buf, len, freq, NULL, NULL) == 0) + src, hdr, buf, len, freq, NULL, NULL, + hapd) == 0) return; #endif /* CONFIG_DPP2 */ diff --git a/src/common/dpp.h b/src/common/dpp.h index 65ee905a7..75de3cae9 100644 --- a/src/common/dpp.h +++ b/src/common/dpp.h @@ -669,7 +669,8 @@ int dpp_relay_add_controller(struct dpp_global *dpp, struct dpp_relay_config *config); int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr, const u8 *buf, size_t len, unsigned int freq, - const u8 *i_bootstrap, const u8 *r_bootstrap); + const u8 *i_bootstrap, const u8 *r_bootstrap, + void *cb_ctx); int dpp_relay_rx_gas_req(struct dpp_global *dpp, const u8 *src, const u8 *data, size_t data_len); int dpp_controller_start(struct dpp_global *dpp, diff --git a/src/common/dpp_tcp.c b/src/common/dpp_tcp.c index ddc720fec..c373f1077 100644 --- a/src/common/dpp_tcp.c +++ b/src/common/dpp_tcp.c @@ -156,6 +156,24 @@ dpp_relay_controller_get(struct dpp_global *dpp, const u8 *pkhash) } +static struct dpp_relay_controller * +dpp_relay_controller_get_ctx(struct dpp_global *dpp, void *cb_ctx) +{ + struct dpp_relay_controller *ctrl; + + if (!dpp) + return NULL; + + dl_list_for_each(ctrl, &dpp->controllers, struct dpp_relay_controller, + list) { + if (cb_ctx == ctrl->cb_ctx) + return ctrl; + } + + return NULL; +} + + static void dpp_controller_gas_done(struct dpp_connection *conn) { struct dpp_authentication *auth = conn->auth; @@ -477,7 +495,8 @@ static int dpp_relay_tx(struct dpp_connection *conn, const u8 *hdr, int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr, const u8 *buf, size_t len, unsigned int freq, - const u8 *i_bootstrap, const u8 *r_bootstrap) + const u8 *i_bootstrap, const u8 *r_bootstrap, + void *cb_ctx) { struct dpp_relay_controller *ctrl; struct dpp_connection *conn; @@ -505,8 +524,7 @@ int dpp_relay_rx_action(struct dpp_global *dpp, const u8 *src, const u8 *hdr, type == DPP_PA_RECONFIG_ANNOUNCEMENT) { /* TODO: Could send this to all configured Controllers. For now, * only the first Controller is supported. */ - ctrl = dl_list_first(&dpp->controllers, - struct dpp_relay_controller, list); + ctrl = dpp_relay_controller_get_ctx(dpp, cb_ctx); } else { if (!r_bootstrap) return -1;