1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-24 07:40:52 +00:00

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
This commit is contained in:
Adrian Chadd 2024-11-09 13:44:50 -08:00
parent aab7f19974
commit c249cc3822
16 changed files with 57 additions and 75 deletions

View File

@ -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 @@ ath_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
* 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? */

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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:

View File

@ -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__);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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) */

View File

@ -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;
}

View File

@ -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;

View File

@ -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?) */

View File

@ -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)