Clean up the OnDisassoc function. Use a struct ieee80211_mgmt for parsing
the incoming message and reduce the indentation levels.
Please apply this after the two series I sent some days ago
Martin Kaiser (5):
staging: r8188eu: use ieee80211_mgmt to parse addresses
staging: r8188eu: read reason code from ieee80211_mgmt
staging: r8188eu: move bBusyTraffic update
staging: r8188eu: handle the non-ap case first
staging: r8188eu: simplify err handling for unknown station
drivers/staging/r8188eu/core/rtw_mlme_ext.c | 47 ++++++++++-----------
1 file changed, 22 insertions(+), 25 deletions(-)
--
2.30.2
The OnDisassoc function hasn't got much to do if we're not working as an
access point. Move this case out of the large if statement to simplify the
code.
Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/core/rtw_mlme_ext.c | 36 ++++++++++-----------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_mlme_ext.c b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
index dd1e0b4fc5a0..d5c9eb52fb0e 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
@@ -1433,6 +1433,8 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
struct wifidirect_info *pwdinfo = &padapter->wdinfo;
+ struct sta_info *psta;
+ struct sta_priv *pstapriv = &padapter->stapriv;
if (memcmp(mgmt->bssid, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
return;
@@ -1444,29 +1446,25 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
reason = le16_to_cpu(mgmt->u.disassoc.reason_code);
- if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
- struct sta_info *psta;
- struct sta_priv *pstapriv = &padapter->stapriv;
-
- psta = rtw_get_stainfo(pstapriv, mgmt->sa);
- if (psta) {
- u8 updated = 0;
+ if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
+ receive_disconnect(padapter, mgmt->bssid, reason);
+ pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
+ return;
+ }
- spin_lock_bh(&pstapriv->asoc_list_lock);
- if (!list_empty(&psta->asoc_list)) {
- list_del_init(&psta->asoc_list);
- pstapriv->asoc_list_cnt--;
- updated = ap_free_sta(padapter, psta, false, reason);
- }
- spin_unlock_bh(&pstapriv->asoc_list_lock);
+ psta = rtw_get_stainfo(pstapriv, mgmt->sa);
+ if (psta) {
+ u8 updated = 0;
- associated_clients_update(padapter, updated);
+ spin_lock_bh(&pstapriv->asoc_list_lock);
+ if (!list_empty(&psta->asoc_list)) {
+ list_del_init(&psta->asoc_list);
+ pstapriv->asoc_list_cnt--;
+ updated = ap_free_sta(padapter, psta, false, reason);
}
+ spin_unlock_bh(&pstapriv->asoc_list_lock);
- return;
- } else {
- receive_disconnect(padapter, mgmt->bssid, reason);
- pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
+ associated_clients_update(padapter, updated);
}
}
--
2.30.2
Define a struct ieee80211_mgmt in the OnDisassoc function and use it to
parse the addresses in the incoming disassoc message. This replaces some
driver-specific functions for address parsing.
Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/core/rtw_mlme_ext.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_mlme_ext.c b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
index d32b2d569e23..b2b2cb57ed04 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
@@ -1427,6 +1427,7 @@ static void OnDeAuth(struct adapter *padapter, struct recv_frame *precv_frame)
static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
{
+ struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)precv_frame->rx_data;
u16 reason;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -1434,8 +1435,7 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
u8 *pframe = precv_frame->rx_data;
struct wifidirect_info *pwdinfo = &padapter->wdinfo;
- /* check A3 */
- if (!(!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
+ if (memcmp(mgmt->bssid, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
return;
if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
@@ -1449,7 +1449,7 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
struct sta_info *psta;
struct sta_priv *pstapriv = &padapter->stapriv;
- psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
+ psta = rtw_get_stainfo(pstapriv, mgmt->sa);
if (psta) {
u8 updated = 0;
@@ -1466,7 +1466,7 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
return;
} else {
- receive_disconnect(padapter, GetAddr3Ptr(pframe), reason);
+ receive_disconnect(padapter, mgmt->bssid, reason);
}
pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
}
--
2.30.2
Move the update of bBusyTraffic into the else branch. The if branch ends
with a return statement, so bBusyTraffic will not be updated in this case.
With this change in place, we can reorder the code and save some levels of
indentation.
Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/core/rtw_mlme_ext.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/r8188eu/core/rtw_mlme_ext.c b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
index fe58d4e3e260..dd1e0b4fc5a0 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
@@ -1466,8 +1466,8 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
return;
} else {
receive_disconnect(padapter, mgmt->bssid, reason);
+ pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
}
- pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
}
static void OnAction_back(struct adapter *padapter, struct recv_frame *precv_frame)
--
2.30.2
If we receive a disassoc message from an unknown station, we can drop this
message immediately. Reorder the code to make this clearer.
Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/core/rtw_mlme_ext.c | 22 ++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_mlme_ext.c b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
index d5c9eb52fb0e..49e0b50b1243 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
@@ -1435,6 +1435,7 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
struct wifidirect_info *pwdinfo = &padapter->wdinfo;
struct sta_info *psta;
struct sta_priv *pstapriv = &padapter->stapriv;
+ u8 updated = 0;
if (memcmp(mgmt->bssid, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
return;
@@ -1453,19 +1454,18 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
}
psta = rtw_get_stainfo(pstapriv, mgmt->sa);
- if (psta) {
- u8 updated = 0;
-
- spin_lock_bh(&pstapriv->asoc_list_lock);
- if (!list_empty(&psta->asoc_list)) {
- list_del_init(&psta->asoc_list);
- pstapriv->asoc_list_cnt--;
- updated = ap_free_sta(padapter, psta, false, reason);
- }
- spin_unlock_bh(&pstapriv->asoc_list_lock);
+ if (!psta)
+ return;
- associated_clients_update(padapter, updated);
+ spin_lock_bh(&pstapriv->asoc_list_lock);
+ if (!list_empty(&psta->asoc_list)) {
+ list_del_init(&psta->asoc_list);
+ pstapriv->asoc_list_cnt--;
+ updated = ap_free_sta(padapter, psta, false, reason);
}
+ spin_unlock_bh(&pstapriv->asoc_list_lock);
+
+ associated_clients_update(padapter, updated);
}
static void OnAction_back(struct adapter *padapter, struct recv_frame *precv_frame)
--
2.30.2
Use the struct ieee80211_mgmt to read the reason code instead of parsing
the message manually.
Remove the pframe pointer, it's no longer used.
Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/core/rtw_mlme_ext.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_mlme_ext.c b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
index b2b2cb57ed04..fe58d4e3e260 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
@@ -1432,7 +1432,6 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
- u8 *pframe = precv_frame->rx_data;
struct wifidirect_info *pwdinfo = &padapter->wdinfo;
if (memcmp(mgmt->bssid, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
@@ -1443,7 +1442,7 @@ static void OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
_set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
}
- reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
+ reason = le16_to_cpu(mgmt->u.disassoc.reason_code);
if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
struct sta_info *psta;
--
2.30.2
On 11/29/22 21:51, Martin Kaiser wrote:
> Clean up the OnDisassoc function. Use a struct ieee80211_mgmt for parsing
> the incoming message and reduce the indentation levels.
>
> Please apply this after the two series I sent some days ago
>
> Martin Kaiser (5):
> staging: r8188eu: use ieee80211_mgmt to parse addresses
> staging: r8188eu: read reason code from ieee80211_mgmt
> staging: r8188eu: move bBusyTraffic update
> staging: r8188eu: handle the non-ap case first
> staging: r8188eu: simplify err handling for unknown station
>
> drivers/staging/r8188eu/core/rtw_mlme_ext.c | 47 ++++++++++-----------
> 1 file changed, 22 insertions(+), 25 deletions(-)
>
Tested-by: Philipp Hortmann <[email protected]> # Edimax N150