Module Name: src
Committed By: christos
Date: Tue Jan 29 13:54:27 UTC 2013
Modified Files:
src/sys/dev/usb: if_otus.c if_otusvar.h
Log Message:
1) Use ic_curchan consistently
2) Ignore frames shorter than sizeof(struct ieee80211_frame).
3) Remove useless/dead code accidentally committed.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/usb/if_otus.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/usb/if_otusvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/if_otus.c
diff -u src/sys/dev/usb/if_otus.c:1.22 src/sys/dev/usb/if_otus.c:1.23
--- src/sys/dev/usb/if_otus.c:1.22 Tue Jan 22 07:40:42 2013
+++ src/sys/dev/usb/if_otus.c Tue Jan 29 08:54:26 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: if_otus.c,v 1.22 2013/01/22 12:40:42 jmcneill Exp $ */
+/* $NetBSD: if_otus.c,v 1.23 2013/01/29 13:54:26 christos Exp $ */
/* $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $ */
/*-
@@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.22 2013/01/22 12:40:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.23 2013/01/29 13:54:26 christos Exp $");
#include <sys/param.h>
#include <sys/sockio.h>
@@ -179,13 +179,6 @@ Static int otus_init(struct ifnet *);
Static void otus_stop(struct ifnet *);
Static void otus_wait_async(struct otus_softc *);
-#if IEEE80211_INJECTION
-#define IS_INJECTED(m) (((m)->m_flags & M_INJECT) != 0)
-
-static int otus_output(struct ifnet *, struct mbuf *,
- const struct sockaddr *, struct rtentry *);
-#endif /* IEEE80211_INJECTION */
-
/* List of supported channels. */
static const uint8_t ar_chans[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
@@ -872,12 +865,6 @@ otus_attachhook(device_t arg)
ic->ic_delete_key = otus_delete_key;
#endif /* notyet */
-#if IEEE80211_INJECTION
- /* hook our packet injection output routine */
- sc->sc_if_output = ifp->if_output;
- ifp->if_output = otus_output;
-#endif
-
/* Override state transition machine. */
sc->sc_newstate = ic->ic_newstate;
ic->ic_newstate = otus_newstate;
@@ -1381,11 +1368,11 @@ otus_newstate_cb(struct otus_softc *sc,
case IEEE80211_S_AUTH:
case IEEE80211_S_ASSOC:
- otus_set_chan(sc, ni->ni_chan, 0);
+ otus_set_chan(sc, ic->ic_curchan, 0);
break;
case IEEE80211_S_RUN:
- otus_set_chan(sc, ni->ni_chan, 1);
+ otus_set_chan(sc, ic->ic_curchan, 1);
switch (ic->ic_opmode) {
case IEEE80211_M_STA:
@@ -1774,12 +1761,16 @@ otus_sub_rxeof(struct otus_softc *sc, ui
}
/* Compute MPDU's length. */
mlen = len - AR_PLCP_HDR_LEN - sizeof(*tail);
- /* Make sure there's room for an 802.11 header + FCS. */
- if (__predict_false(mlen < IEEE80211_MIN_LEN)) {
+ mlen -= IEEE80211_CRC_LEN; /* strip 802.11 FCS */
+ /* Make sure there's room for an 802.11 header. */
+ /*
+ * XXX: This will drop most control packets. Do we really
+ * want this in IEEE80211_M_MONITOR mode?
+ */
+ if (__predict_false(mlen < sizeof(*wh))) {
ifp->if_ierrors++;
return;
}
- mlen -= IEEE80211_CRC_LEN; /* strip 802.11 FCS */
/* Provide a 32-bit aligned protocol header to the stack. */
align = (ieee80211_has_qos(wh) ^ ieee80211_has_addr4(wh)) ? 2 : 0;
@@ -1809,8 +1800,8 @@ otus_sub_rxeof(struct otus_softc *sc, ui
tap = &sc->sc_rxtap;
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_chan_freq = htole16(ic->ic_curchan->ic_freq);
+ tap->wr_chan_flags = htole16(ic->ic_curchan->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) {
@@ -1949,9 +1940,6 @@ Static int
otus_tx(struct otus_softc *sc, struct mbuf *m, struct ieee80211_node *ni,
struct otus_tx_data *data)
{
-#if IEEE80211_INJECTION
- struct ieee80211_bpf_params *params;
-#endif
struct ieee80211com *ic;
struct otus_node *on;
struct ieee80211_frame *wh;
@@ -1967,16 +1955,8 @@ otus_tx(struct otus_softc *sc, struct mb
ic = &sc->sc_ic;
on = (void *)ni;
-#if IEEE80211_INJECTION
- params = ieee80211_bpf_params(m);
-#endif
-
wh = mtod(m, struct ieee80211_frame *);
- if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED)
-#if IEEE80211_INJECTION
- && !IS_INJECTED(m)
-#endif
- ) {
+ if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED)) {
/* XXX: derived from upgt_tx_task() and ural_tx_data() */
k = ieee80211_crypto_encap(ic, ni, m);
if (k == NULL)
@@ -2042,38 +2022,6 @@ otus_tx(struct otus_softc *sc, struct mb
phyctl |= AR_TX_PHY_ANTMSK(sc->sc_txmask);
}
-#if IEEE80211_INJECTION
- if (params) {
- if (params->ibp_flags & IEEE80211_BPF_NOACK)
- macctl |= AR_TX_MAC_NOACK;
-
- if (params->ibp_flags & IEEE80211_BPF_CTS) {
- macctl &= ~AR_TX_MAC_RTS;
- macctl |= AR_TX_MAC_CTS;
- }
- else if (params->ibp_flags & IEEE80211_BPF_RTS) {
- macctl &= ~AR_TX_MAC_CTS;
- macctl |= AR_TX_MAC_RTS;
- }
- if (params->ibp_flags & IEEE80211_BPF_FCS) {
-// otus_write(sc, AR_MAC_REG_FCS_SELECT, AR_MAC_FCS_SWFCS);
- }
-#if 0 /* XXX: TODO */
- if (params->ibp_flags & IEEE80211_BPF_SHORTPRE)
- if (params->ibp_flags & IEEE80211_BPF_CRYPTO)
- if (params->ibp_flags & IEEE80211_BPF_DATAPAD)
-
-#define IEEE80211_BPF_SHORTPRE 0x01 /* tx with short preamble */
-#define IEEE80211_BPF_NOACK 0x02 /* tx with no ack */
-#define IEEE80211_BPF_CRYPTO 0x04 /* tx with h/w encryption */
-#define IEEE80211_BPF_FCS 0x10 /* frame includes FCS */
-#define IEEE80211_BPF_DATAPAD 0x20 /* frame includes data padding */
-#define IEEE80211_BPF_RTS 0x40 /* tx with RTS/CTS */
-#define IEEE80211_BPF_CTS 0x80 /* tx with CTS only */
-#endif /* XXX: TODO */
- }
-#endif /* IEEE80211_INJECTION */
-
/* Update rate control stats for frames that are ACK'ed. */
if (!(macctl & AR_TX_MAC_NOACK))
on->amn.amn_txcnt++;
@@ -2088,9 +2036,11 @@ otus_tx(struct otus_softc *sc, struct mb
struct otus_tx_radiotap_header *tap = &sc->sc_txtap;
tap->wt_flags = 0;
+ if (wh->i_fc[1] & IEEE80211_FC1_WEP)
+ tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
tap->wt_rate = otus_rates[ridx].rate;
- tap->wt_chan_freq = htole16(ic->ic_bss->ni_chan->ic_freq);
- tap->wt_chan_flags = htole16(ic->ic_bss->ni_chan->ic_flags);
+ tap->wt_chan_freq = htole16(ic->ic_curchan->ic_freq);
+ tap->wt_chan_flags = htole16(ic->ic_curchan->ic_flags);
bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_txtap_len, m);
}
@@ -2141,28 +2091,21 @@ otus_start(struct ifnet *ifp)
* later. Both must be done inside a single lock.
*/
mutex_enter(&sc->sc_tx_mtx);
- if (data == NULL) {
+ if (data == NULL && !TAILQ_EMPTY(&sc->sc_tx_free_list)) {
data = TAILQ_FIRST(&sc->sc_tx_free_list);
- if (data == NULL) {
- mutex_exit(&sc->sc_tx_mtx);
- /*
- * No data buffers are available. Set
- * the IFF_OACTIVE bit and bail
- * immediately. otus_txeof() will
- * release this bit when it releases a
- * buffer and restarts otus_start().
- */
- ifp->if_flags |= IFF_OACTIVE;
- DPRINTFN(DBG_TX, sc, "empty sc_tx_free_list\n");
- return;
- }
TAILQ_REMOVE(&sc->sc_tx_free_list, data, next);
}
+ mutex_exit(&sc->sc_tx_mtx);
+
+ if (data == NULL) {
+ ifp->if_flags |= IFF_OACTIVE;
+ DPRINTFN(DBG_TX, sc, "empty sc_tx_free_list\n");
+ return;
+ }
/* Send pending management frames first. */
IF_DEQUEUE(&ic->ic_mgtq, m);
if (m != NULL) {
- mutex_exit(&sc->sc_tx_mtx);
ni = (void *)m->m_pkthdr.rcvif;
m->m_pkthdr.rcvif = NULL;
goto sendit;
@@ -2176,8 +2119,6 @@ otus_start(struct ifnet *ifp)
if (m == NULL)
break;
- mutex_exit(&sc->sc_tx_mtx);
-
if (m->m_len < (int)sizeof(*eh) &&
(m = m_pullup(m, sizeof(*eh))) == NULL) {
ifp->if_oerrors++;
@@ -2221,6 +2162,7 @@ otus_start(struct ifnet *ifp)
* If here, we have a Tx buffer, but ran out of mbufs to
* transmit. Put the Tx buffer back to the free list.
*/
+ mutex_enter(&sc->sc_tx_mtx);
TAILQ_INSERT_TAIL(&sc->sc_tx_free_list, data, next);
mutex_exit(&sc->sc_tx_mtx);
}
@@ -2246,25 +2188,6 @@ otus_watchdog(struct ifnet *ifp)
ifp->if_timer = 1;
}
ieee80211_watchdog(&sc->sc_ic);
-
-#if 0
- /* XXX: should we be doing something like this? */
- struct url_chain *c;
- usbd_status stat;
- int s;
-
- ifp->if_oerrors++;
- printf("%s: watchdog timeout\n", device_xname(sc->sc_dev));
-
- s = splusb();
- c = &sc->sc_cdata.url_tx_chain[0];
- usbd_get_xfer_status(c->url_xfer, NULL, NULL, NULL, &stat);
- url_txeof(c->url_xfer, c, stat);
-
- if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
- url_start(ifp);
- splx(s);
-#endif
}
Static int
@@ -2346,7 +2269,7 @@ otus_ioctl(struct ifnet *ifp, u_long cmd
if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) ==
(IFF_UP | IFF_RUNNING)) {
mutex_enter(&sc->sc_write_mtx);
- otus_set_chan(sc, ic->ic_ibss_chan, 0);
+ otus_set_chan(sc, ic->ic_curchan, 0);
mutex_exit(&sc->sc_write_mtx);
}
error = 0;
@@ -3291,8 +3214,7 @@ otus_init(struct ifnet *ifp)
(void)otus_write_barrier(sc);
sc->sc_bb_reset = 1; /* Force cold reset. */
- ic->ic_bss->ni_chan = ic->ic_ibss_chan;
- if ((error = otus_set_chan(sc, ic->ic_ibss_chan, 0)) != 0) {
+ if ((error = otus_set_chan(sc, ic->ic_curchan, 0)) != 0) {
mutex_exit(&sc->sc_write_mtx);
aprint_error_dev(sc->sc_dev, "could not set channel\n");
return error;
@@ -3345,27 +3267,3 @@ otus_stop(struct ifnet *ifp)
(void)otus_write_barrier(sc);
mutex_exit(&sc->sc_write_mtx);
}
-
-#if IEEE80211_INJECTION
-static int
-otus_output(struct ifnet *ifp, struct mbuf *m,
- const struct sockaddr *dst, struct rtentry *rt)
-{
- struct otus_softc *sc;
- struct ieee80211com *ic;
-
- sc = ifp->if_softc;
-
- DPRINTFN(DBG_FN, sc, "\n");
-
- ic = &sc->sc_ic;
-
- /*
- * Hand to the 802.3 code if not tagged as a raw 802.11 frame.
- */
- if (dst->sa_family != AF_IEEE80211)
- return sc->sc_if_output(ifp, m, dst, rt);
-
- return ieee80211_output(ifp, m, dst, ic);
-}
-#endif /* IEEE80211_INJECTION */
Index: src/sys/dev/usb/if_otusvar.h
diff -u src/sys/dev/usb/if_otusvar.h:1.5 src/sys/dev/usb/if_otusvar.h:1.6
--- src/sys/dev/usb/if_otusvar.h:1.5 Mon Jan 21 11:48:23 2013
+++ src/sys/dev/usb/if_otusvar.h Tue Jan 29 08:54:26 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: if_otusvar.h,v 1.5 2013/01/21 16:48:23 christos Exp $ */
+/* $NetBSD: if_otusvar.h,v 1.6 2013/01/29 13:54:26 christos Exp $ */
/* $OpenBSD: if_otusreg.h,v 1.6 2009/04/06 18:17:01 damien Exp $ */
/*-
@@ -286,12 +286,6 @@ struct otus_softc {
uint8_t sc_rx_error_msk;
int sc_dying;
-
-#if IEEE80211_INJECTION /* XXX: ljt */
- int (*sc_if_output) /* ether output routine */
- (struct ifnet *, struct mbuf *, const struct sockaddr *,
- struct rtentry *);
-#endif
};
#endif /* _IF_OTUSVAR_H_ */