hostapd: backport a few upstream fixes
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 001-Fix-race-condition-between-AssocResp-callback-and-4a.patch
1 From: Jouni Malinen <jouni@qca.qualcomm.com>
2 Date: Tue, 20 Dec 2016 01:30:09 +0200
3 Subject: [PATCH] Fix race condition between AssocResp callback and 4addr event
4
5 It is apparently possible for the NL80211_CMD_UNEXPECTED_4ADDR_FRAME
6 event to be delivered to hostapd before the NL80211_CMD_FRAME_TX_STATUS
7 event for (Re)Association Response frame. This resulted in the 4-address
8 WDS mode not getting enabled for a STA. This could occur in particular
9 when operating under heavy load and the STA is reconnecting to the same
10 AP in a sequence where Deauthentication frame is followed immediately by
11 Authentication frame and the driver event processing gets delayed due to
12 removal of the previous netdev taking time in the middle of this
13 sequence.
14
15 Fix this by recording a pending item for 4-address WDS enabling if the
16 NL80211_CMD_UNEXPECTED_4ADDR_FRAME event would have been dropped due to
17 incompleted association and then process this pending item if the TX
18 status for the (Re)Association Response frame is received and it shows
19 that the frame was acknowledged.
20
21 Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
22 ---
23
24 --- a/src/ap/ieee802_11.c
25 +++ b/src/ap/ieee802_11.c
26 @@ -2634,6 +2634,8 @@ static void handle_assoc(struct hostapd_
27 taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
28 #endif /* CONFIG_TAXONOMY */
29
30 + sta->pending_wds_enable = 0;
31 +
32 fail:
33 /*
34 * In case of a successful response, add the station to the driver.
35 @@ -3248,6 +3250,14 @@ static void handle_assoc_cb(struct hosta
36
37 hostapd_set_sta_flags(hapd, sta);
38
39 + if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) {
40 + wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA "
41 + MACSTR " based on pending request",
42 + MAC2STR(sta->addr));
43 + sta->pending_wds_enable = 0;
44 + sta->flags |= WLAN_STA_WDS;
45 + }
46 +
47 if (sta->flags & WLAN_STA_WDS) {
48 int ret;
49 char ifname_wds[IFNAMSIZ + 1];
50 @@ -3512,10 +3522,22 @@ void ieee802_11_rx_from_unknown(struct h
51 struct sta_info *sta;
52
53 sta = ap_get_sta(hapd, src);
54 - if (sta && (sta->flags & WLAN_STA_ASSOC)) {
55 + if (sta &&
56 + ((sta->flags & WLAN_STA_ASSOC) ||
57 + ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) {
58 if (!hapd->conf->wds_sta)
59 return;
60
61 + if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) ==
62 + WLAN_STA_ASSOC_REQ_OK) {
63 + wpa_printf(MSG_DEBUG,
64 + "Postpone 4-address WDS mode enabling for STA "
65 + MACSTR " since TX status for AssocResp is not yet known",
66 + MAC2STR(sta->addr));
67 + sta->pending_wds_enable = 1;
68 + return;
69 + }
70 +
71 if (wds && !(sta->flags & WLAN_STA_WDS)) {
72 int ret;
73 char ifname_wds[IFNAMSIZ + 1];
74 --- a/src/ap/sta_info.h
75 +++ b/src/ap/sta_info.h
76 @@ -115,6 +115,7 @@ struct sta_info {
77 unsigned int radius_das_match:1;
78 unsigned int ecsa_supported:1;
79 unsigned int added_unassoc:1;
80 + unsigned int pending_wds_enable:1;
81
82 u16 auth_alg;
83