[PATCH 02/10] staging: rtl8723bs: use ieee80211_has_*() to test frame control flags

From: Rishik Yechuri

Date: Tue Oct 13 2026 - 16:58:56 EST


The driver defines GetToDs(), GetFrDs(), get_tofr_ds(), GetMFrag(),
GetRetry(), GetPwrMgt(), GetMData(), GetPrivacy() and GetOrder() in
wifi.h to test individual bits of the IEEE 802.11 Frame Control field.
Each macro casts the frame buffer to __le16 and masks a single bit.
<linux/ieee80211.h> provides equivalent helpers that operate on the
frame_control member of struct ieee80211_hdr and test the same bits.

Replace each use of these macros with the corresponding helper:

GetToDs() -> ieee80211_has_tods()
GetFrDs() -> ieee80211_has_fromds()
GetMFrag() -> ieee80211_has_morefrags()
GetRetry() -> ieee80211_has_retry()
GetPwrMgt() -> ieee80211_has_pm()
GetMData() -> ieee80211_has_moredata()
GetPrivacy() -> ieee80211_has_protected()
GetOrder() -> ieee80211_has_order()

Open code get_tofr_ds() using ieee80211_has_tods() and
ieee80211_has_fromds(), and remove the macro definitions. Also remove
GetOrderBit(), which has no users.

No functional change intended.

Signed-off-by: Rishik Yechuri <rishik.yechuri.code@xxxxxxxxx>
---
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 10 +++---
drivers/staging/rtl8723bs/core/rtw_recv.c | 19 +++++++-----
drivers/staging/rtl8723bs/include/wifi.h | 31 ++++---------------
3 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 1349bd423..d318b0ff4 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -455,7 +455,7 @@ void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame)
ptable += index;

if (psta) {
- if (GetRetry(pframe)) {
+ if (ieee80211_has_retry(hdr->frame_control)) {
if (precv_frame->u.hdr.attrib.seq_num == psta->rx_mgmt_frame_seq_num) {
/* drop the duplicate management frame */
return;
@@ -690,7 +690,7 @@ unsigned int OnAuth(struct adapter *padapter, union recv_frame *precv_frame)

auth_mode = psecuritypriv->dot11_auth_algrthm;

- if (GetPrivacy(pframe)) {
+ if (ieee80211_has_protected(hdr->frame_control)) {
u8 *iv;
struct rx_pkt_attrib *prxattrib = &(precv_frame->u.hdr.attrib);

@@ -849,6 +849,7 @@ unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_fram
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
u8 *pframe = precv_frame->u.hdr.rx_data;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)pframe;
uint pkt_len = precv_frame->u.hdr.len;

/* check A1 matches or not */
@@ -858,7 +859,7 @@ unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_fram
if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
return _SUCCESS;

- offset = (GetPrivacy(pframe)) ? 4 : 0;
+ offset = (ieee80211_has_protected(hdr->frame_control)) ? 4 : 0;

seq = le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 2));
status = le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offset + 4));
@@ -1673,10 +1674,11 @@ static s32 rtw_action_public_decache(union recv_frame *recv_frame, s32 token)
struct adapter *adapter = recv_frame->u.hdr.adapter;
struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
u8 *frame = recv_frame->u.hdr.rx_data;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)frame;
u16 seq_ctrl = ((recv_frame->u.hdr.attrib.seq_num & 0xffff) << 4) |
(recv_frame->u.hdr.attrib.frag_num & 0xf);

- if (GetRetry(frame)) {
+ if (ieee80211_has_retry(hdr->frame_control)) {
if (token >= 0) {
if ((seq_ctrl == mlmeext->action_public_rxseq)
&& (token == mlmeext->action_public_dialog_token))
diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c b/drivers/staging/rtl8723bs/core/rtw_recv.c
index 8f3c0552e..43452f50d 100644
--- a/drivers/staging/rtl8723bs/core/rtw_recv.c
+++ b/drivers/staging/rtl8723bs/core/rtw_recv.c
@@ -566,13 +566,14 @@ static void process_pwrbit_data(struct adapter *padapter, union recv_frame *prec
{
unsigned char pwrbit;
u8 *ptr = precv_frame->u.hdr.rx_data;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)ptr;
struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
struct sta_priv *pstapriv = &padapter->stapriv;
struct sta_info *psta = NULL;

psta = rtw_get_stainfo(pstapriv, pattrib->src);

- pwrbit = GetPwrMgt(ptr);
+ pwrbit = ieee80211_has_pm(hdr->frame_control);

if (psta) {
if (pwrbit) {
@@ -1248,7 +1249,7 @@ static signed int validate_recv_data_frame(struct adapter *adapter, union recv_f
struct security_priv *psecuritypriv = &adapter->securitypriv;
signed int ret = _SUCCESS;

- bretry = GetRetry(ptr);
+ bretry = ieee80211_has_retry(hdr->frame_control);
pda = get_da(ptr);
psa = get_sa(ptr);
pbssid = get_hdr_bssid(ptr);
@@ -1435,6 +1436,7 @@ static signed int validate_recv_frame(struct adapter *adapter, union recv_frame
struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;

u8 *ptr = precv_frame->u.hdr.rx_data;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)ptr;
u8 ver = (unsigned char) (*ptr) & 0x3;

/* add version chk */
@@ -1446,16 +1448,17 @@ static signed int validate_recv_frame(struct adapter *adapter, union recv_frame
type = GetFrameType(ptr);
subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */

- pattrib->to_fr_ds = get_tofr_ds(ptr);
+ pattrib->to_fr_ds = (ieee80211_has_tods(hdr->frame_control) << 1) |
+ ieee80211_has_fromds(hdr->frame_control);

pattrib->frag_num = GetFragNum(ptr);
pattrib->seq_num = GetSequence(ptr);

- pattrib->pw_save = GetPwrMgt(ptr);
- pattrib->mfrag = GetMFrag(ptr);
- pattrib->mdata = GetMData(ptr);
- pattrib->privacy = GetPrivacy(ptr);
- pattrib->order = GetOrder(ptr);
+ pattrib->pw_save = ieee80211_has_pm(hdr->frame_control);
+ pattrib->mfrag = ieee80211_has_morefrags(hdr->frame_control);
+ pattrib->mdata = ieee80211_has_moredata(hdr->frame_control);
+ pattrib->privacy = ieee80211_has_protected(hdr->frame_control);
+ pattrib->order = ieee80211_has_order(hdr->frame_control);

switch (type) {
case WIFI_MGT_TYPE: /* mgnt */
diff --git a/drivers/staging/rtl8723bs/include/wifi.h b/drivers/staging/rtl8723bs/include/wifi.h
index 6c877c7ca..800bfd962 100644
--- a/drivers/staging/rtl8723bs/include/wifi.h
+++ b/drivers/staging/rtl8723bs/include/wifi.h
@@ -75,53 +75,33 @@ enum {
#define SetToDs(pbuf) \
(*(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_))

-#define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
-
#define SetFrDs(pbuf) \
(*(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_))

-#define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
-
-#define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe))
-
#define SetMFrag(pbuf) \
(*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_))

-#define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
-
#define ClearMFrag(pbuf) \
(*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)))

-#define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
-
#define ClearRetry(pbuf) \
(*(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_)))

#define SetPwrMgt(pbuf) \
(*(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_))

-#define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_PWRMGT_)) != 0)
-
#define ClearPwrMgt(pbuf) \
(*(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)))

#define SetMData(pbuf) \
(*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_))

-#define GetMData(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_DATA_)) != 0)
-
#define ClearMData(pbuf) \
(*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)))

#define SetPrivacy(pbuf) \
(*(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_))

-#define GetPrivacy(pbuf) \
- (((*(__le16 *)(pbuf)) & cpu_to_le16(_PRIVACY_)) != 0)
-
-#define GetOrder(pbuf) \
- (((*(__le16 *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0)
-
#define GetFrameType(pbuf) \
(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(3) | BIT(2)))

@@ -204,7 +184,8 @@ static inline unsigned char *get_da(unsigned char *pframe)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)pframe;
unsigned char *da;
- unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
+ unsigned int to_fr_ds = (ieee80211_has_tods(hdr->frame_control) << 1) |
+ ieee80211_has_fromds(hdr->frame_control);

switch (to_fr_ds) {
case 0x00: /* ToDs = 0, FromDs = 0 */
@@ -228,7 +209,8 @@ static inline unsigned char *get_sa(unsigned char *pframe)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)pframe;
unsigned char *sa;
- unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
+ unsigned int to_fr_ds = (ieee80211_has_tods(hdr->frame_control) << 1) |
+ ieee80211_has_fromds(hdr->frame_control);

switch (to_fr_ds) {
case 0x00: /* ToDs = 0, FromDs = 0 */
@@ -252,7 +234,8 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)pframe;
unsigned char *sa = NULL;
- unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
+ unsigned int to_fr_ds = (ieee80211_has_tods(hdr->frame_control) << 1) |
+ ieee80211_has_fromds(hdr->frame_control);

switch (to_fr_ds) {
case 0x00: /* ToDs = 0, FromDs = 0 */
@@ -317,8 +300,6 @@ static inline int IsFrameTypeCtrl(unsigned char *pframe)
/*-----------------------------------------------------------------------------
Below is the definition for 802.11n
------------------------------------------------------------------------------*/
-#define GetOrderBit(pbuf) (((*(unsigned short *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0)
-
#define ACT_CAT_VENDOR 0x7F/* 127 */

/**
--
2.43.0