dpp: handle sending a frame after ROC ends
James Prestwood
PATCH 1/4 dpp: handle sending a frame after ROC ends
There is a potential corner case of an offchannel frame callback being called after ROC has ended.
This could happen in theory if a received frame is queued right as the ROC session expires. If the ROC cancel event makes it to user space before the frame IWD will schedule another ROC then receive the frame. This doesn't prevent IWD from sending out another frame since OFFCHANNEL_TX_OK is used, but it will prevent IWD from receiving a response frame since no dwell duration is used with DPP.
To handle this an roc_started bool was added to the dpp_sm which tracks the ROC state. If dpp_send_frame is called when roc_started is false the frame will be saved and sent out once the ROC session is started again.
--- src/dpp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
src/dpp.c +67 -0
@@ -138,12 +138,39 @@ struct dpp_sm {uint32_t connect_scan_id;uint64_t frame_cookie;uint8_t frame_retry; +void *frame_pending; +size_t frame_size;struct l_dbus_message *pending; bool mcast_support : 1; + bool roc_started : 1; }; +static void *dpp_serialize_iovec (struct iovec *iov,size_t iov_len, +size_t *out_len) +{ +unsigned int i; +size_t size =0 ; +uint8_t *ret; + +for (i =0 ; i < iov_len; i++) + size += iov[i].iov_len; + + ret =l_malloc (size); + size =0 ; + +for (i =0 ; i < iov_len; i++) { +memcpy (ret + size, iov[i].iov_base, iov[i].iov_len); + size += iov[i].iov_len; + } + +if (out_len) + *out_len = size; + +return ret; +} +static void dpp_free_auth_data (struct dpp_sm *dpp) {if (dpp->own_proto_public) {
@@ -209,6 +236,11 @@ static void dpp_reset(struct dpp_sm *dpp) dpp->peer_asn1 =NULL ; } +if (dpp->frame_pending) { +l_free (dpp->frame_pending); + dpp->frame_pending =NULL ; + } + dpp->state =DPP_STATE_NOTHING ; dpp->new_freq =0 ; dpp->frame_retry =0 ;
@@ -267,6 +299,19 @@ static void dpp_send_frame(struct dpp_sm *dpp, {struct l_genl_msg *msg; +/* +* A received frame could potentially come in after the ROC session has +* ended. In this case the frame needs to be stored until ROC is started +* and sent at that time. The offchannel_id is also checked since +* this is not applicable when DPP is in a responder role waiting +* on the currently connected channel i.e. offchannel is never used. +*/ +if (!dpp->roc_started && dpp->offchannel_id) { + dpp->frame_pending =dpp_serialize_iovec (iov, iov_len, + &dpp->frame_size); +return ; + } + msg =l_genl_msg_new_sized (NL80211_CMD_FRAME ,512 );l_genl_msg_append_attr (msg,NL80211_ATTR_WDEV ,8 , &dpp->wdev_id);l_genl_msg_append_attr (msg,NL80211_ATTR_WIPHY_FREQ ,4 , &freq);
@@ -281,6 +326,20 @@ static void dpp_send_frame(struct dpp_sm *dpp, } } +static void dpp_frame_retry (struct dpp_sm *dpp) +{ +struct iovec iov; + + iov.iov_base = dpp->frame_pending; + iov.iov_len = dpp->frame_size; + +dpp_send_frame (dpp, &iov,1 , dpp->current_freq); + +l_free (dpp->frame_pending); + dpp->frame_pending =NULL ; +} + +static size_t dpp_build_header (const uint8_t *src,const uint8_t *dest,enum dpp_frame_type type,uint8_t buf[static 32 ])
@@ -1360,6 +1419,13 @@ static void dpp_roc_started(void *user_data)* the authenticate response now. */ + dpp->roc_started = true; + +if (dpp->frame_pending) { +dpp_frame_retry (dpp); +return ; + } +switch (dpp->state) {case DPP_STATE_PRESENCE :if (dpp->role ==DPP_CAPABILITY_CONFIGURATOR )
@@ -1409,6 +1475,7 @@ static void dpp_presence_timeout(int error, void *user_data)struct dpp_sm *dpp = user_data; dpp->offchannel_id =0 ; + dpp->roc_started = false;/* * If cancelled this is likely due to netdev going down or from Stop().
Signature · 1 line
2.34.1
James Prestwood
PATCH 2/4 dpp: print error if CMD_FRAME fails
--- src/dpp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
src/dpp.c +3 -2
@@ -282,9 +282,10 @@ static void dpp_free(struct dpp_sm *dpp)static void dpp_send_frame_cb (struct l_genl_msg *msg,void *user_data) {struct dpp_sm *dpp = user_data; +int err =l_genl_msg_get_error (msg); -if (l_genl_msg_get_error (msg) <0 ) { -l_error ("Error sending frame" ); +if (err <0 ) { +l_error ("Error sending frame (%d)" , err);return ; }
Signature · 1 line
2.34.1
James Prestwood
PATCH 3/4 dpp: wait before retransmitting frames with no-ACK
In reply to James PrestwoodThe upstream code immediately retransmitted any no-ACK frames. This would work in cases where the peer wasn't actively switching channels (e.g. the ACK was simply lost) but caused unintended behavior in the case of a channel switch when the peer was not listening.
If either IWD or the peer needed to switch channels based on the authenticate request the response may end up not getting ACKed because the peer is idle, or in the middle of the hardware changing channels. IWD would get no-ACK and immediately send the frame again and most likely the same behavior would result. This would very quickly increment frame_retry past the maximum and DPP would fail.
Instead when no ACK is received wait 1 second before sending out the next frame. This can re-use the existing frame_pending buffer and the same logic for re-transmitting.
--- src/dpp.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
src/dpp.c +43 -2
@@ -55,6 +55,7 @@#include "src/nl80211util.h" #define DPP_FRAME_MAX_RETRIES 5 +#define DPP_FRAME_RETRY_TIMEOUT 1static uint32_t netdev_watch;static struct l_genl_family *nl80211;
@@ -140,6 +141,7 @@ struct dpp_sm {uint8_t frame_retry;void *frame_pending;size_t frame_size; +struct l_timeout *retry_timeout;struct l_dbus_message *pending;
@@ -241,6 +243,11 @@ static void dpp_reset(struct dpp_sm *dpp) dpp->frame_pending =NULL ; } +if (dpp->retry_timeout) { +l_timeout_remove (dpp->retry_timeout); + dpp->retry_timeout =NULL ; + } + dpp->state =DPP_STATE_NOTHING ; dpp->new_freq =0 ; dpp->frame_retry =0 ;
@@ -1422,6 +1429,13 @@ static void dpp_roc_started(void *user_data) dpp->roc_started = true; +/* +* The retry timer indicates a frame was not acked in which case we +* should not change any state or send any frames until that expires. +*/ +if (dpp->retry_timeout) +return ; +if (dpp->frame_pending) {dpp_frame_retry (dpp);return ;
@@ -2082,6 +2096,25 @@ static bool match_wdev(const void *a, const void *b)return *wdev_id == dpp->wdev_id; } +static void dpp_frame_timeout (struct l_timeout *timeout,void *user_data) +{ +struct dpp_sm *dpp = user_data; + +l_timeout_remove (timeout); + dpp->retry_timeout =NULL ; + +/* +* ROC has not yet started (in between an ROC timeout and starting a +* new session), this will most likely result in the frame failing to +* send. Just bail out now and the roc_started callback will take care +* of sending this out. +*/ +if (!dpp->roc_started) +return ; + +dpp_frame_retry (dpp); +} +static void dpp_mlme_notify (struct l_genl_msg *msg,void *user_data) {struct dpp_sm *dpp;
@@ -2120,11 +2153,19 @@ static void dpp_mlme_notify(struct l_genl_msg *msg, void *user_data)return ; } -l_debug ("No ACK from peer, re-transmitting" ); +/* This should never happen */ +if (L_WARN_ON (dpp->frame_pending)) +return ; + +l_debug ("No ACK from peer, re-transmitting in %us" , +DPP_FRAME_RETRY_TIMEOUT ); dpp->frame_retry++; -dpp_send_frame (dpp, &iov,1 , dpp->current_freq); + dpp->frame_pending =l_memdup (iov.iov_base, iov.iov_len); + dpp->frame_size = iov.iov_len; + dpp->retry_timeout =l_timeout_create (DPP_FRAME_RETRY_TIMEOUT , + dpp_frame_timeout, dpp,NULL ); }static void dpp_unicast_notify (struct l_genl_msg *msg,void *user_data)
Signature · 1 line
2.34.1
James Prestwood
PATCH 4/4 auto-t: disable update_config for testDPP
In reply to James Prestwoodupdate_config=1 lets wpa_supplicant write config changes to the config file. In the real world this is what you want so your DPP credentials are persistant. But for testing this is not correct since multiple tests use the same config file and expect it to be pristine.
Occationally wpa_supplicant was connecting to the AP without running DPP because the config already had the network credentials.
--- autotests/testDPP/wpas.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
autotests/testDPP/wpas.conf +1 -1
@@ -1,5 +1,5 @@ ctrl_interface=/tmp/rad1-p2p-wpas -update_config=1 +update_config=0 pmf=2 dpp_config_processing=2
Signature · 1 line
2.34.1
Denis Kenzior
Hi James,
Quoted 10 lines · James Prestwood
There is a potential corner case of an offchannel frame callback being called after ROC has ended.
This could happen in theory if a received frame is queued right as the ROC session expires. If the ROC cancel event makes it to user space before the frame IWD will schedule another ROC then receive the frame. This doesn't prevent IWD from sending out another frame since
OFFCHANNEL_TX_OKis used, but it will prevent IWD from receiving a response frame since no dwell duration is used with DPP.
Quoted 8 lines
To handle this an
roc_startedbool was added to thedpp_smwhich tracks the ROC state. Ifdpp_send_frameis called whenroc_startedis false the frame will be saved and sent out once the ROC session is started again.--- src/dpp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
All applied, thanks.
Regards,
-Denis