Fix ieee80211_radiotap(9) usage in wireless drivers:

- Alignment issues:
 * Add missing __packed attributes + padding across all drivers; in
most places there was an assumption that padding will be always
minimally suitable; in few places - e.g., in urtw(4) / rtwn(4) -
padding was just missing.
 * Add __aligned(8) attribute for all Rx radiotap headers since they can
contain 64-bit TSF timestamp; it cannot appear in Tx radiotap headers, so
just drop the attribute here. Refresh ieee80211_radiotap(9) man page
accordingly.

- Since net80211 automatically updates channel frequency / flags in
ieee80211_radiotap_chan_change() drop duplicate setup for these fields
in drivers.

Tested with Netgear WG111 v3 (urtw(4)), STA mode.

MFC after:	2 weeks
This commit is contained in:
Andriy Voskoboinyk 2019-03-11 01:27:01 +00:00
parent 4f4463dfa3
commit 786ac7035f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=344990
34 changed files with 44 additions and 81 deletions

View File

@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 4, 2009
.Dd March 11, 2019
.Dt IEEE80211_RADIOTAP 9
.Os
.Sh NAME
@ -257,7 +257,7 @@ struct wi_rx_radiotap_header {
uint16_t wr_chan_flags;
uint8_t wr_antsignal;
uint8_t wr_antnoise;
} __packed;
} __packed __aligned(8);
.Ed
.Pp
and transmit definitions for the Atheros driver:

View File

@ -373,7 +373,7 @@ struct ath_rx_radiotap_header {
*/
struct ath_radiotap_vendor_hdr wr_v;
#endif /* ATH_ENABLE_RADIOTAP_VENDOR_EXT */
} __packed;
} __packed __aligned(8);
#define ATH_TX_RADIOTAP_PRESENT ( \
(1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -1729,15 +1729,6 @@ bwi_set_channel(struct ieee80211com *ic)
bwi_rf_set_chan(mac, ieee80211_chan2ieee(ic, c), 0);
sc->sc_rates = ieee80211_get_ratetable(c);
/*
* Setup radio tap channel freq and flags
*/
sc->sc_tx_th.wt_chan_freq = sc->sc_rx_th.wr_chan_freq =
htole16(c->ic_freq);
sc->sc_tx_th.wt_chan_flags = sc->sc_rx_th.wr_chan_flags =
htole16(c->ic_flags & 0xffff);
BWI_UNLOCK(sc);
}

View File

@ -513,7 +513,7 @@ struct bwi_tx_radiotap_hdr {
uint8_t wt_rate;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
};
} __packed;
#define BWI_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_TSFT) | \
@ -533,7 +533,7 @@ struct bwi_rx_radiotap_hdr {
int8_t wr_antsignal;
int8_t wr_antnoise;
/* TODO: sq */
};
} __packed __aligned(8);
struct bwi_vap {
struct ieee80211vap bv_vap;

View File

@ -2001,14 +2001,6 @@ bwn_set_channel(struct ieee80211com *ic)
bwn_mac_enable(mac);
fail:
/*
* Setup radio tap channel freq and flags
*/
sc->sc_tx_th.wt_chan_freq = sc->sc_rx_th.wr_chan_freq =
htole16(ic->ic_curchan->ic_freq);
sc->sc_tx_th.wt_chan_flags = sc->sc_rx_th.wr_chan_flags =
htole16(ic->ic_curchan->ic_flags & 0xffff);
BWN_UNLOCK(sc);
}

View File

@ -570,7 +570,7 @@ struct bwn_rx_radiotap_header {
int8_t wr_antsignal;
int8_t wr_antnoise;
u_int8_t wr_antenna;
};
} __packed __aligned(8);
#define BWN_TX_RADIOTAP_PRESENT ( \
(1 << IEEE80211_RADIOTAP_FLAGS) | \
@ -588,7 +588,7 @@ struct bwn_tx_radiotap_header {
u_int16_t wt_chan_flags;
u_int8_t wt_txpower;
u_int8_t wt_antenna;
};
} __packed;
struct bwn_stats {
int32_t rtsfail;

View File

@ -57,11 +57,12 @@ struct ipw_soft_buf {
struct ipw_rx_radiotap_header {
struct ieee80211_radiotap_header wr_ihdr;
uint8_t wr_flags;
uint8_t wr_pad;
uint16_t wr_chan_freq;
uint16_t wr_chan_flags;
int8_t wr_antsignal;
int8_t wr_antnoise;
};
} __packed __aligned(8);
#define IPW_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \
@ -72,9 +73,10 @@ struct ipw_rx_radiotap_header {
struct ipw_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_pad;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
};
} __packed;
#define IPW_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -38,7 +38,7 @@ struct iwi_rx_radiotap_header {
int8_t wr_antsignal;
int8_t wr_antnoise;
uint8_t wr_antenna;
};
} __packed __aligned(8);
#define IWI_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \
@ -51,9 +51,10 @@ struct iwi_rx_radiotap_header {
struct iwi_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_pad;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
};
} __packed;
#define IWI_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -113,7 +113,7 @@ struct iwm_rx_radiotap_header {
uint16_t wr_chan_flags;
int8_t wr_dbm_antsignal;
int8_t wr_dbm_antnoise;
} __packed;
} __packed __aligned(8);
#define IWM_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_TSFT) | \

View File

@ -9102,18 +9102,12 @@ iwn_scan_end(struct ieee80211com *ic)
static void
iwn_set_channel(struct ieee80211com *ic)
{
const struct ieee80211_channel *c = ic->ic_curchan;
struct iwn_softc *sc = ic->ic_softc;
int error;
DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);
IWN_LOCK(sc);
sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
/*
* Only need to set the channel in Monitor mode. AP scanning and auth
* are already taken care of by their respective firmware commands.

View File

@ -62,7 +62,7 @@ struct iwn_rx_radiotap_header {
uint16_t wr_chan_flags;
int8_t wr_dbm_antsignal;
int8_t wr_dbm_antnoise;
} __packed;
} __packed __aligned(8);
#define IWN_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_TSFT) | \

View File

@ -93,7 +93,7 @@ struct malo_rx_radiotap_header {
int8_t wr_antsignal;
int8_t wr_antnoise;
u_int8_t wr_antenna;
};
} __packed __aligned(8);
#define MALO_TX_RADIOTAP_PRESENT ( \
(1 << IEEE80211_RADIOTAP_FLAGS) | \
@ -111,6 +111,6 @@ struct malo_tx_radiotap_header {
u_int16_t wt_chan_flags;
u_int8_t wt_txpower;
u_int8_t wt_antenna;
};
} __packed;
#endif /* _DEV_MALO_MVIOCTL_H */

View File

@ -115,7 +115,7 @@ struct mwl_rx_radiotap_header {
int8_t wr_antsignal;
int8_t wr_antnoise;
u_int8_t wr_antenna;
};
} __packed __aligned(8);
#define MWL_TX_RADIOTAP_PRESENT ( \
(1 << IEEE80211_RADIOTAP_FLAGS) | \
@ -133,6 +133,6 @@ struct mwl_tx_radiotap_header {
u_int16_t wt_chan_flags;
u_int8_t wt_txpower;
u_int8_t wt_antenna;
};
} __packed;
#endif /* _DEV_MWL_MVIOCTL_H */

View File

@ -1670,8 +1670,6 @@ otus_sub_rxeof(struct otus_softc *sc, uint8_t *buf, int len, struct mbufq *rxq)
struct mbuf mb;
tap->wr_flags = 0;
tap->wr_chan_freq = htole16(ic->ic_ibss_chan->ic_freq);
tap->wr_chan_flags = htole16(ic->ic_ibss_chan->ic_flags);
tap->wr_antsignal = tail->rssi;
tap->wr_rate = 2; /* In case it can't be found below. */
switch (tail->status & AR_RX_STATUS_MT_MASK) {

View File

@ -900,7 +900,7 @@ struct otus_rx_radiotap_header {
uint16_t wr_chan_freq;
uint16_t wr_chan_flags;
uint8_t wr_antsignal;
} __packed;
} __packed __aligned(8);
#define OTUS_RX_RADIOTAP_PRESENT \
(1 << IEEE80211_RADIOTAP_FLAGS | \

View File

@ -27,7 +27,7 @@ struct rt2560_rx_radiotap_header {
int8_t wr_antsignal;
int8_t wr_antnoise;
uint8_t wr_antenna;
};
} __packed __aligned(8);
#define RT2560_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_TSFT) | \
@ -45,7 +45,7 @@ struct rt2560_tx_radiotap_header {
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
uint8_t wt_antenna;
};
} __packed;
#define RT2560_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -42,7 +42,7 @@ struct rt2661_tx_radiotap_header {
uint8_t wt_rate;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define RT2661_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -55,7 +55,7 @@ struct rt2860_tx_radiotap_header {
uint8_t wt_rate;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define RT2860_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -1560,10 +1560,6 @@ rtwn_set_channel(struct ieee80211com *ic)
RTWN_LOCK(sc);
rtwn_set_chan(sc, c);
sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
RTWN_UNLOCK(sc);
}

View File

@ -62,9 +62,10 @@ struct rtwn_rx_radiotap_header {
struct rtwn_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_pad;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define RTWN_TX_RADIOTAP_PRESENT \
(1 << IEEE80211_RADIOTAP_FLAGS | \

View File

@ -2447,8 +2447,6 @@ rsu_rx_frame(struct rsu_softc *sc, struct mbuf *m)
tap->wr_rate = rxs.c_rate;
tap->wr_dbm_antsignal = rssi;
tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq);
tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
};
(void) ieee80211_add_rx_params(m, &rxs);
@ -2750,7 +2748,6 @@ rsu_tx_start(struct rsu_softc *sc, struct ieee80211_node *ni,
struct mbuf *m0, struct rsu_data *data)
{
const struct ieee80211_txparam *tp = ni->ni_txparms;
struct ieee80211com *ic = &sc->sc_ic;
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211_frame *wh;
struct ieee80211_key *k = NULL;
@ -2894,8 +2891,6 @@ rsu_tx_start(struct rsu_softc *sc, struct ieee80211_node *ni,
struct rsu_tx_radiotap_header *tap = &sc->sc_txtap;
tap->wt_flags = 0;
tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
ieee80211_radiotap_tx(vap, m0);
}

View File

@ -800,9 +800,10 @@ struct rsu_rx_radiotap_header {
struct rsu_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_pad;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define RSU_TX_RADIOTAP_PRESENT \
(1 << IEEE80211_RADIOTAP_FLAGS | \

View File

@ -49,7 +49,7 @@ struct rum_tx_radiotap_header {
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
uint8_t wt_antenna;
} __packed __aligned(8);
} __packed;
#define RT2573_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -2900,8 +2900,6 @@ run_rx_frame(struct run_softc *sc, struct mbuf *m, uint32_t dmalen)
uint16_t phy;
tap->wr_flags = 0;
tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq);
tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
tap->wr_antsignal = rssi;
tap->wr_antenna = ant;
tap->wr_dbm_antsignal = run_rssi2dbm(sc, rssi, ant);
@ -3173,8 +3171,6 @@ run_bulk_tx_callbackN(struct usb_xfer *xfer, usb_error_t error, u_int index)
(struct rt2860_txwi *)(&data->desc + sizeof(struct rt2870_txd));
tap->wt_flags = 0;
tap->wt_rate = rt2860_rates[data->ridx].rate;
tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
tap->wt_hwqueue = index;
if (le16toh(txwi->phy) & RT2860_PHY_SHPRE)
tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;

View File

@ -71,7 +71,7 @@ struct run_tx_radiotap_header {
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
uint8_t wt_hwqueue;
} __packed __aligned(8);
} __packed;
#define IEEE80211_RADIOTAP_HWQUEUE 15

View File

@ -67,9 +67,10 @@ struct uath_rx_radiotap_header {
struct uath_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_pad;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define UATH_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -394,7 +394,7 @@ struct upgt_tx_radiotap_header {
uint8_t wt_rate;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define UPGT_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -51,7 +51,7 @@ struct ural_tx_radiotap_header {
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
uint8_t wt_antenna;
} __packed __aligned(8);
} __packed;
#define RAL_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -1684,11 +1684,7 @@ urtw_tx_start(struct urtw_softc *sc, struct ieee80211_node *ni, struct mbuf *m0,
if (ieee80211_radiotap_active_vap(vap)) {
struct urtw_tx_radiotap_header *tap = &sc->sc_txtap;
/* XXX Are variables correct? */
tap->wt_flags = 0;
tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
ieee80211_radiotap_tx(vap, m0);
}
@ -3976,9 +3972,7 @@ urtw_rxeof(struct usb_xfer *xfer, struct urtw_data *data, int *rssi_p,
if (ieee80211_radiotap_active(ic)) {
struct urtw_rx_radiotap_header *tap = &sc->sc_rxtap;
/* XXX Are variables correct? */
tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq);
tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
tap->wr_flags = 0;
tap->wr_dbm_antsignal = (int8_t)rssi;
}

View File

@ -56,6 +56,7 @@ typedef STAILQ_HEAD(, urtw_data) urtw_datahead;
struct urtw_rx_radiotap_header {
struct ieee80211_radiotap_header wr_ihdr;
uint8_t wr_flags;
uint8_t wr_pad;
uint16_t wr_chan_freq;
uint16_t wr_chan_flags;
int8_t wr_dbm_antsignal;
@ -69,9 +70,10 @@ struct urtw_rx_radiotap_header {
struct urtw_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
uint8_t wt_flags;
uint8_t wt_pad;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define URTW_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -1200,7 +1200,7 @@ struct zyd_tx_radiotap_header {
uint8_t wt_rate;
uint16_t wt_chan_freq;
uint16_t wt_chan_flags;
} __packed __aligned(8);
} __packed;
#define ZYD_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \

View File

@ -709,7 +709,7 @@ struct wi_rx_radiotap_header {
u_int16_t wr_chan_flags;
u_int8_t wr_antsignal;
u_int8_t wr_antnoise;
};
} __packed __aligned(8);
#define WI_TX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_FLAGS) | \
@ -722,5 +722,5 @@ struct wi_tx_radiotap_header {
u_int8_t wt_rate;
u_int16_t wt_chan_freq;
u_int16_t wt_chan_flags;
};
} __packed;
#endif /* IEEE80211_RADIOTAP_F_CFP */

View File

@ -26,7 +26,7 @@ struct wpi_rx_radiotap_header {
int8_t wr_dbm_antsignal;
int8_t wr_dbm_antnoise;
uint8_t wr_antenna;
} __packed;
} __packed __aligned(8);
#define WPI_RX_RADIOTAP_PRESENT \
((1 << IEEE80211_RADIOTAP_TSFT) | \

View File

@ -159,7 +159,7 @@ struct wtap_rx_radiotap_header {
u_int8_t wr_chan_ieee;
int8_t wr_chan_maxpow;
#endif
} __packed;
} __packed __aligned(8);
#define WTAP_TX_RADIOTAP_PRESENT ( \
0)
@ -167,7 +167,6 @@ struct wtap_rx_radiotap_header {
struct wtap_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
#if 0
u_int64_t wt_tsf;
u_int8_t wt_flags;
u_int8_t wt_rate;
u_int8_t wt_txpower;