From 9d05a6ddb7994cadde4c26c0335aae490e6dce22 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 30 Sep 2017 04:28:09 +0200 Subject: [PATCH] ap: Reorder ap_assoc_req_cb, fix comment Set all the new field values into struct sta_state only after all the error checks for better readabilty and fixing a possible issue if we did "sta->rates = rates" and then detected en error and freed "rates". Also update a comment which I think used the wording from 802.11-2012 instead of 802.11-2016. --- src/ap.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/ap.c b/src/ap.c index d94afb15..185ee901 100644 --- a/src/ap.c +++ b/src/ap.c @@ -855,9 +855,6 @@ static void ap_assoc_req_cb(struct netdev *netdev, if (sta->assoc_resp_cmd_id) return; - sta->capability = req->capability; - sta->listen_interval = L_LE16_TO_CPU(req->listen_interval); - ie_tlv_iter_init(&iter, req->ies, body_len - sizeof(*req)); while (ie_tlv_iter_next(&iter)) @@ -893,12 +890,7 @@ static void ap_assoc_req_cb(struct netdev *netdev, goto bad_frame; } - if (sta->rates) - l_uintset_free(sta->rates); - - sta->rates = rates; - - if (!ap_common_rates(ap->rates, sta->rates)) { + if (!ap_common_rates(ap->rates, rates)) { err = MMPDU_REASON_CODE_UNSPECIFIED; goto unsupported; } @@ -918,12 +910,6 @@ static void ap_assoc_req_cb(struct netdev *netdev, goto unsupported; } - if (sta->assoc_rsne) - l_free(sta->assoc_rsne); - - sta->assoc_rsne = l_memdup(rsn, rsn_len); - sta->assoc_rsne_len = rsn_len; - /* * Everything fine so far, assign an AID, send response. According * to 802.11-2016 11.3.5.3 l) we will only go to State 3 @@ -932,6 +918,24 @@ static void ap_assoc_req_cb(struct netdev *netdev, */ sta->aid = ++ap->last_aid; + sta->capability = req->capability; + sta->listen_interval = L_LE16_TO_CPU(req->listen_interval); + + if (sta->rates) + l_uintset_free(sta->rates); + + sta->rates = rates; + + if (sta->assoc_rsne) + l_free(sta->assoc_rsne); + + sta->assoc_rsne = l_memdup(rsn, rsn_len); + sta->assoc_rsne_len = rsn_len; + + /* 802.11-2016 11.3.5.3 j) */ + if (sta->rsna) + ap_drop_rsna(ap, sta); + sta->assoc_resp_cmd_id = ap_assoc_resp(ap, sta, sta->addr, sta->aid, 0, ap_success_assoc_resp_cb); if (!sta->assoc_resp_cmd_id) @@ -944,10 +948,12 @@ bad_frame: /* * TODO: MFP * - * 802.11-2016 11.3.5.3 j) - * "if management frame protection is in use the state for the STA - * shall be left unchanged. and if management frame protection is - * not in use set to State 3 if it was in State 4." + * 802.11-2016 11.3.5.3 m) + * "If the ResultCode in the MLME-ASSOCIATE.response primitive is + * not SUCCESS and management frame protection is in use the state + * for the STA shall be left unchanged. If the ResultCode is not + * SUCCESS and management frame protection is not in use the state + * for the STA shall be set to State 3 if it was State 4." * * For now, we need to drop the RSNA. */