Skip to contentSkip to conversation

staging: r8188eu: clean up OnDisassoc

PATCH In review Martin Kaiser 2 participants 7 messages Nov 29, 2022 – Nov 30, 2022 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: r8188eu: clean up OnDisassoc

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(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/5 staging: r8188eu: use ieee80211_mgmt to parse addresses

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.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +4 -4
index d32b2d569e23..b2b2cb57ed04 100644
@@ -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;
 }
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/5 staging: r8188eu: read reason code from ieee80211_mgmt

In reply to Martin Kaiser

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.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +1 -2
index b2b2cb57ed04..fe58d4e3e260 100644
@@ -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;
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/5 staging: r8188eu: move bBusyTraffic update

In reply to Martin Kaiser

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.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +1 -1
index fe58d4e3e260..dd1e0b4fc5a0 100644
@@ -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)
Signature · 1 line
2.30.2
#4 lore raw

PATCH 4/5 staging: r8188eu: handle the non-ap case first

In reply to Martin Kaiser

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.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c | 36 ++++++++++-----------
 1 file changed, 17 insertions(+), 19 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +17 -19
index dd1e0b4fc5a0..d5c9eb52fb0e 100644
@@ -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);
 	}
 }
 
Signature · 1 line
2.30.2
#5 lore raw

PATCH 5/5 staging: r8188eu: simplify err handling for unknown station

In reply to Martin Kaiser

If we receive a disassoc message from an unknown station, we can drop this message immediately. Reorder the code to make this clearer.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c | 22 ++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +11 -11
index d5c9eb52fb0e..49e0b50b1243 100644
@@ -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)
Signature · 1 line
2.30.2
Tested-by on the v1 series
#6 lore raw
In reply to Martin Kaiser
Quoted 12 lines · Martin Kaiser

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

Quoted 3 lines
  drivers/staging/r8188eu/core/rtw_mlme_ext.c | 47 ++++++++++-----------
  1 file changed, 22 insertions(+), 25 deletions(-)