The branch main has been updated by adrian:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=c249cc3822dc002288700ee206cf28c0c6031449

commit c249cc3822dc002288700ee206cf28c0c6031449
Author:     Adrian Chadd <[email protected]>
AuthorDate: 2024-11-09 21:44:50 +0000
Commit:     Adrian Chadd <[email protected]>
CommitDate: 2024-11-17 17:53:04 +0000

    net80211: migrate FC0_TYPE_MASK / FC0_SUBTYPE_MASK frame type checks to 
macros
    
    * Add macros for the management and control frame type checks that
      I've come across in the drivers.
    * Delete some now old code (eg ath's ieee80211_is_action()) as there's now
      a macro for it.
    
    Local testing:
    
    * not yet, I have a lot of wifi devices to find and test against
    
    Differential Revision: https://reviews.freebsd.org/D47500
---
 sys/dev/ath/if_ath_tx.c    | 24 ++----------------------
 sys/dev/ipw/if_ipw.c       |  2 +-
 sys/dev/iwn/if_iwn.c       |  4 +---
 sys/dev/malo/if_malo.c     | 12 +++---------
 sys/dev/mwl/if_mwl.c       |  7 ++-----
 sys/dev/otus/if_otus.c     |  3 +--
 sys/dev/ral/rt2560.c       |  5 +----
 sys/dev/ral/rt2661.c       |  4 +---
 sys/dev/ral/rt2860.c       |  8 ++------
 sys/dev/usb/wlan/if_rum.c  |  4 +---
 sys/dev/usb/wlan/if_run.c  |  4 +---
 sys/dev/usb/wlan/if_upgt.c |  3 +--
 sys/dev/usb/wlan/if_ural.c |  5 +----
 sys/dev/usb/wlan/if_urtw.c |  7 ++-----
 sys/dev/usb/wlan/if_zyd.c  |  4 +---
 sys/net80211/ieee80211.h   | 36 ++++++++++++++++++++++++++++++++++++
 16 files changed, 57 insertions(+), 75 deletions(-)

diff --git a/sys/dev/ath/if_ath_tx.c b/sys/dev/ath/if_ath_tx.c
index 69d0b5c00848..1ec23972f283 100644
--- a/sys/dev/ath/if_ath_tx.c
+++ b/sys/dev/ath/if_ath_tx.c
@@ -1133,8 +1133,7 @@ ath_tx_calc_duration(struct ath_softc *sc, struct ath_buf 
*bf)
         * Calculate duration.  This logically belongs in the 802.11
         * layer but it lacks sufficient information to calculate it.
         */
-       if ((flags & HAL_TXDESC_NOACK) == 0 &&
-           (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL) {
+       if ((flags & HAL_TXDESC_NOACK) == 0 && !IEEE80211_IS_CTL(wh)) {
                u_int16_t dur;
                if (shortPreamble)
                        dur = rt->info[rix].spAckDuration;
@@ -2577,25 +2576,6 @@ badbad:
  * It's a dirty hack, but someone's gotta do it.
  */
 
-/*
- * XXX doesn't belong here!
- */
-static int
-ieee80211_is_action(struct ieee80211_frame *wh)
-{
-       /* Type: Management frame? */
-       if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
-           IEEE80211_FC0_TYPE_MGT)
-               return 0;
-
-       /* Subtype: Action frame? */
-       if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) !=
-           IEEE80211_FC0_SUBTYPE_ACTION)
-               return 0;
-
-       return 1;
-}
-
 /*
  * Return an alternate TID for ADDBA request frames.
  *
@@ -2612,7 +2592,7 @@ ath_tx_action_frame_override_queue(struct ath_softc *sc,
        uint16_t baparamset;
 
        /* Not action frame? Bail */
-       if (! ieee80211_is_action(wh))
+       if (! IEEE80211_IS_MGMT_ACTION(wh))
                return 0;
 
        /* XXX Not needed for frames we send? */
diff --git a/sys/dev/ipw/if_ipw.c b/sys/dev/ipw/if_ipw.c
index 051f046d26ad..68662f378933 100644
--- a/sys/dev/ipw/if_ipw.c
+++ b/sys/dev/ipw/if_ipw.c
@@ -1119,7 +1119,7 @@ ipw_fix_channel(struct ipw_softc *sc, struct mbuf *m)
 
        wh = mtod(m, struct ieee80211_frame *);
 
-       if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_MGT)
+       if (!IEEE80211_IS_MGMT(wh))
                return;
 
        subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
diff --git a/sys/dev/iwn/if_iwn.c b/sys/dev/iwn/if_iwn.c
index d2d44d93f948..50d50fdc473c 100644
--- a/sys/dev/iwn/if_iwn.c
+++ b/sys/dev/iwn/if_iwn.c
@@ -4624,9 +4624,7 @@ iwn_tx_data(struct iwn_softc *sc, struct mbuf *m, struct 
ieee80211_node *ni)
                    IEEE80211_QOS_ACKPOLICY_NOACK)
                        flags |= IWN_TX_NEED_ACK;
        }
-       if ((wh->i_fc[0] &
-           (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
-           (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR))
+       if (IEEE80211_IS_CTL_BAR(wh))
                flags |= IWN_TX_IMM_BA;         /* Cannot happen yet. */
 
        if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG)
diff --git a/sys/dev/malo/if_malo.c b/sys/dev/malo/if_malo.c
index 56310085ef5f..52419f377bb6 100644
--- a/sys/dev/malo/if_malo.c
+++ b/sys/dev/malo/if_malo.c
@@ -94,13 +94,9 @@ enum {
        MALO_DEBUG_FW           = 0x00008000,   /* firmware */
        MALO_DEBUG_ANY          = 0xffffffff
 };
-#define        IS_BEACON(wh)                                                   
\
-       ((wh->i_fc[0] & (IEEE80211_FC0_TYPE_MASK |                      \
-               IEEE80211_FC0_SUBTYPE_MASK)) ==                         \
-        (IEEE80211_FC0_TYPE_MGT|IEEE80211_FC0_SUBTYPE_BEACON))
 #define        IFF_DUMPPKTS_RECV(sc, wh)                                       
\
        (((sc->malo_debug & MALO_DEBUG_RECV) &&                         \
-         ((sc->malo_debug & MALO_DEBUG_RECV_ALL) || !IS_BEACON(wh))))
+         ((sc->malo_debug & MALO_DEBUG_RECV_ALL) || 
!IEEE80211_IS_MGMT_BEACON(wh))))
 #define        IFF_DUMPPKTS_XMIT(sc)                                           
\
        (sc->malo_debug & MALO_DEBUG_XMIT)
 #define        DPRINTF(sc, m, fmt, ...) do {                           \
@@ -1025,8 +1021,6 @@ static int
 malo_tx_start(struct malo_softc *sc, struct ieee80211_node *ni,
     struct malo_txbuf *bf, struct mbuf *m0)
 {
-#define        IS_DATA_FRAME(wh)                                               
\
-       ((wh->i_fc[0] & (IEEE80211_FC0_TYPE_MASK)) == IEEE80211_FC0_TYPE_DATA)
        int error, iswep;
        int hdrlen, pktlen;
        struct ieee80211_frame *wh;
@@ -1150,7 +1144,7 @@ malo_tx_start(struct malo_softc *sc, struct 
ieee80211_node *ni,
        ds->pktptr = htole32(bf->bf_segs[0].ds_addr);
        ds->pktlen = htole16(bf->bf_segs[0].ds_len);
        /* NB: pPhysNext setup once, don't touch */
-       ds->datarate = IS_DATA_FRAME(wh) ? 1 : 0;
+       ds->datarate = IEEE80211_IS_DATA(wh) ? 1 : 0;
        ds->sap_pktinfo = 0;
        ds->format = 0;
 
@@ -1183,7 +1177,7 @@ malo_tx_start(struct malo_softc *sc, struct 
ieee80211_node *ni,
 #endif
 
        MALO_TXQ_LOCK(txq);
-       if (!IS_DATA_FRAME(wh))
+       if (!IEEE80211_IS_DATA(wh))
                ds->status |= htole32(1);
        ds->status |= htole32(MALO_TXD_STATUS_FW_OWNED);
        STAILQ_INSERT_TAIL(&txq->active, bf, bf_list);
diff --git a/sys/dev/mwl/if_mwl.c b/sys/dev/mwl/if_mwl.c
index 49b8b3279c7f..f396ef7256f4 100644
--- a/sys/dev/mwl/if_mwl.c
+++ b/sys/dev/mwl/if_mwl.c
@@ -226,12 +226,9 @@ enum {
        MWL_DEBUG_AMPDU         = 0x00004000,   /* BA stream handling */
        MWL_DEBUG_ANY           = 0xffffffff
 };
-#define        IS_BEACON(wh) \
-    ((wh->i_fc[0] & (IEEE80211_FC0_TYPE_MASK|IEEE80211_FC0_SUBTYPE_MASK)) == \
-        (IEEE80211_FC0_TYPE_MGT|IEEE80211_FC0_SUBTYPE_BEACON))
 #define        IFF_DUMPPKTS_RECV(sc, wh) \
     ((sc->sc_debug & MWL_DEBUG_RECV) && \
-      ((sc->sc_debug & MWL_DEBUG_RECV_ALL) || !IS_BEACON(wh)))
+      ((sc->sc_debug & MWL_DEBUG_RECV_ALL) || !IEEE80211_IS_MGMT_BEACON(wh)))
 #define        IFF_DUMPPKTS_XMIT(sc) \
        (sc->sc_debug & MWL_DEBUG_XMIT)
 
@@ -2553,7 +2550,7 @@ mwl_anyhdrsize(const void *data)
 {
        const struct ieee80211_frame *wh = data;
 
-       if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) {
+       if (IEEE80211_IS_CTL(wh)) {
                switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
                case IEEE80211_FC0_SUBTYPE_CTS:
                case IEEE80211_FC0_SUBTYPE_ACK:
diff --git a/sys/dev/otus/if_otus.c b/sys/dev/otus/if_otus.c
index dbb913d83ae8..a620a400bfd6 100644
--- a/sys/dev/otus/if_otus.c
+++ b/sys/dev/otus/if_otus.c
@@ -1686,8 +1686,7 @@ otus_sub_rxeof(struct otus_softc *sc, uint8_t *buf, int 
len, struct mbufq *rxq)
         * with invalid frame control values here.  Just toss them
         * rather than letting net80211 get angry and log.
         */
-       if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
-           IEEE80211_FC0_VERSION_0) {
+       if (!IEEE80211_IS_FC0_CHECK_VER(wh, IEEE80211_FC0_VERSION_0)) {
                OTUS_DPRINTF(sc, OTUS_DEBUG_RXDONE,
                    "%s: invalid 802.11 fc version (firmware bug?)\n",
                        __func__);
diff --git a/sys/dev/ral/rt2560.c b/sys/dev/ral/rt2560.c
index d7cafe1994c9..aaae1245a9a1 100644
--- a/sys/dev/ral/rt2560.c
+++ b/sys/dev/ral/rt2560.c
@@ -1558,10 +1558,7 @@ rt2560_tx_mgt(struct rt2560_softc *sc, struct mbuf *m0,
                *(uint16_t *)wh->i_dur = htole16(dur);
 
                /* tell hardware to add timestamp for probe responses */
-               if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
-                   IEEE80211_FC0_TYPE_MGT &&
-                   (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
-                   IEEE80211_FC0_SUBTYPE_PROBE_RESP)
+               if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
                        flags |= RT2560_TX_TIMESTAMP;
        }
 
diff --git a/sys/dev/ral/rt2661.c b/sys/dev/ral/rt2661.c
index 1194ef12189f..4912e1106fa6 100644
--- a/sys/dev/ral/rt2661.c
+++ b/sys/dev/ral/rt2661.c
@@ -1326,9 +1326,7 @@ rt2661_tx_mgt(struct rt2661_softc *sc, struct mbuf *m0,
                *(uint16_t *)wh->i_dur = htole16(dur);
 
                /* tell hardware to add timestamp in probe responses */
-               if ((wh->i_fc[0] &
-                   (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
-                   (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP))
+               if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
                        flags |= RT2661_TX_TIMESTAMP;
        }
 
diff --git a/sys/dev/ral/rt2860.c b/sys/dev/ral/rt2860.c
index ab5b32b4e026..e928de084bcb 100644
--- a/sys/dev/ral/rt2860.c
+++ b/sys/dev/ral/rt2860.c
@@ -1559,9 +1559,7 @@ rt2860_tx(struct rt2860_softc *sc, struct mbuf *m, struct 
ieee80211_node *ni)
                *(uint16_t *)wh->i_dur = htole16(dur);
        }
        /* ask MAC to insert timestamp into probe responses */
-       if ((wh->i_fc[0] &
-            (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
-            (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP))
+       if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
            /* NOTE: beacons do not pass through tx_data() */
                txwi->flags |= RT2860_TX_TS;
 
@@ -1802,9 +1800,7 @@ rt2860_tx_raw(struct rt2860_softc *sc, struct mbuf *m,
                *(uint16_t *)wh->i_dur = htole16(dur);
        }
        /* ask MAC to insert timestamp into probe responses */
-       if ((wh->i_fc[0] &
-            (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
-            (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP))
+       if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
            /* NOTE: beacons do not pass through tx_data() */
                txwi->flags |= RT2860_TX_TS;
 
diff --git a/sys/dev/usb/wlan/if_rum.c b/sys/dev/usb/wlan/if_rum.c
index edf92e2222b4..fc83409543ec 100644
--- a/sys/dev/usb/wlan/if_rum.c
+++ b/sys/dev/usb/wlan/if_rum.c
@@ -1526,9 +1526,7 @@ rum_tx_mgt(struct rum_softc *sc, struct mbuf *m0, struct 
ieee80211_node *ni)
                USETW(wh->i_dur, dur);
 
                /* tell hardware to add timestamp for probe responses */
-               if (type == IEEE80211_FC0_TYPE_MGT &&
-                   (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
-                   IEEE80211_FC0_SUBTYPE_PROBE_RESP)
+               if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
                        flags |= RT2573_TX_TIMESTAMP;
        }
 
diff --git a/sys/dev/usb/wlan/if_run.c b/sys/dev/usb/wlan/if_run.c
index e2ea78f78b13..e709ceff8849 100644
--- a/sys/dev/usb/wlan/if_run.c
+++ b/sys/dev/usb/wlan/if_run.c
@@ -3595,9 +3595,7 @@ run_tx_mgt(struct run_softc *sc, struct mbuf *m, struct 
ieee80211_node *ni)
        wh = mtod(m, struct ieee80211_frame *);
 
        /* tell hardware to add timestamp for probe responses */
-       if ((wh->i_fc[0] &
-           (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
-           (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP))
+       if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
                wflags |= RT2860_TX_TS;
        else if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
                xflags |= RT2860_TX_ACK;
diff --git a/sys/dev/usb/wlan/if_upgt.c b/sys/dev/usb/wlan/if_upgt.c
index 55d231e2c655..642631ae34b7 100644
--- a/sys/dev/usb/wlan/if_upgt.c
+++ b/sys/dev/usb/wlan/if_upgt.c
@@ -2139,8 +2139,7 @@ upgt_tx_start(struct upgt_softc *sc, struct mbuf *m, 
struct ieee80211_node *ni,
        mem->addr = htole32(data->addr);
        txdesc = (struct upgt_lmac_tx_desc *)(mem + 1);
 
-       if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
-           IEEE80211_FC0_TYPE_MGT) {
+       if (IEEE80211_IS_MGMT(wh)) {
                /* mgmt frames  */
                txdesc->header1.flags = UPGT_H1_FLAGS_TX_MGMT;
                /* always send mgmt frames at lowest rate (DS1) */
diff --git a/sys/dev/usb/wlan/if_ural.c b/sys/dev/usb/wlan/if_ural.c
index 1acae6d84b53..6e01592da44f 100644
--- a/sys/dev/usb/wlan/if_ural.c
+++ b/sys/dev/usb/wlan/if_ural.c
@@ -1097,10 +1097,7 @@ ural_tx_mgt(struct ural_softc *sc, struct mbuf *m0, 
struct ieee80211_node *ni)
                USETW(wh->i_dur, dur);
 
                /* tell hardware to add timestamp for probe responses */
-               if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
-                   IEEE80211_FC0_TYPE_MGT &&
-                   (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
-                   IEEE80211_FC0_SUBTYPE_PROBE_RESP)
+               if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
                        flags |= RAL_TX_TIMESTAMP;
        }
 
diff --git a/sys/dev/usb/wlan/if_urtw.c b/sys/dev/usb/wlan/if_urtw.c
index d08a3237e9b2..1a7a1eba4758 100644
--- a/sys/dev/usb/wlan/if_urtw.c
+++ b/sys/dev/usb/wlan/if_urtw.c
@@ -1724,8 +1724,7 @@ urtw_tx_start(struct urtw_softc *sc, struct 
ieee80211_node *ni, struct mbuf *m0,
                ieee80211_radiotap_tx(vap, m0);
        }
 
-       if (type == IEEE80211_FC0_TYPE_MGT ||
-           type == IEEE80211_FC0_TYPE_CTL ||
+       if (IEEE80211_IS_MGMT(wh) || IEEE80211_IS_CTL(wh) ||
            (m0->m_flags & M_EAPOL) != 0) {
                rate = tp->mgmtrate;
        } else {
@@ -1803,9 +1802,7 @@ urtw_tx_start(struct urtw_softc *sc, struct 
ieee80211_node *ni, struct mbuf *m0,
                }
                tx->flag = htole32(flags);
                tx->txdur = txdur;
-               if (type == IEEE80211_FC0_TYPE_MGT &&
-                   (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
-                   IEEE80211_FC0_SUBTYPE_PROBE_RESP)
+               if (IEEE80211_IS_MGMT_PROBE_RESP(wh))
                        tx->retry = 1;
                else
                        tx->retry = URTW_TX_MAXRETRY;
diff --git a/sys/dev/usb/wlan/if_zyd.c b/sys/dev/usb/wlan/if_zyd.c
index a4dc6b972c96..76e7d4312040 100644
--- a/sys/dev/usb/wlan/if_zyd.c
+++ b/sys/dev/usb/wlan/if_zyd.c
@@ -2505,9 +2505,7 @@ zyd_tx_start(struct zyd_softc *sc, struct mbuf *m0, 
struct ieee80211_node *ni)
                }
        } else
                desc->flags |= ZYD_TX_FLAG_MULTICAST;
-       if ((wh->i_fc[0] &
-           (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
-           (IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_PS_POLL))
+       if (IEEE80211_IS_CTL_PS_POLL(wh))
                desc->flags |= ZYD_TX_FLAG_TYPE(ZYD_TX_TYPE_PS_POLL);
 
        /* actual transmit length (XXX why +10?) */
diff --git a/sys/net80211/ieee80211.h b/sys/net80211/ieee80211.h
index a2d6b3040032..e9147e028385 100644
--- a/sys/net80211/ieee80211.h
+++ b/sys/net80211/ieee80211.h
@@ -219,6 +219,42 @@ struct ieee80211_qosframe_addr4 {
        (IEEE80211_IS_FC0_CHECK_VER_TYPE(wh, IEEE80211_FC0_VERSION_0,   \
         IEEE80211_FC0_TYPE_EXT))
 
+/* Management frame types */
+
+#define        IEEE80211_IS_MGMT_BEACON(wh)                    \
+       (IEEE80211_IS_FC0_CHECK_VER_TYPE_SUBTYPE(wh,    \
+        IEEE80211_FC0_VERSION_0,                       \
+        IEEE80211_FC0_TYPE_MGT,                        \
+        IEEE80211_FC0_SUBTYPE_BEACON))
+
+#define        IEEE80211_IS_MGMT_PROBE_RESP(wh)                \
+       (IEEE80211_IS_FC0_CHECK_VER_TYPE_SUBTYPE(wh,    \
+        IEEE80211_FC0_VERSION_0,                       \
+        IEEE80211_FC0_TYPE_MGT,                        \
+        IEEE80211_FC0_SUBTYPE_PROBE_RESP))
+
+#define        IEEE80211_IS_MGMT_ACTION(wh)            \
+       (IEEE80211_IS_FC0_CHECK_VER_TYPE_SUBTYPE(wh,    \
+        IEEE80211_FC0_VERSION_0,                       \
+        IEEE80211_FC0_TYPE_MGT,                        \
+        IEEE80211_FC0_SUBTYPE_ACTION))
+
+/* Control frame types */
+
+#define        IEEE80211_IS_CTL_PS_POLL(wh)                    \
+       (IEEE80211_IS_FC0_CHECK_VER_TYPE_SUBTYPE(wh,    \
+        IEEE80211_FC0_VERSION_0,                       \
+        IEEE80211_FC0_TYPE_CTL,                        \
+        IEEE80211_FC0_SUBTYPE_PS_POLL))
+
+#define        IEEE80211_IS_CTL_BAR(wh)                        \
+       (IEEE80211_IS_FC0_CHECK_VER_TYPE_SUBTYPE(wh,    \
+        IEEE80211_FC0_VERSION_0,                       \
+        IEEE80211_FC0_TYPE_CTL,                        \
+        IEEE80211_FC0_SUBTYPE_BAR))
+
+/* Data frame types */
+
 #define        IEEE80211_FC0_QOSDATA \
        
(IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS_DATA|IEEE80211_FC0_VERSION_0)
 

Reply via email to