This diff adds monitor mode to iwm(4) (man page changes not included).
It requires the multi-frame interrupt support diff I just sent earlier.
Otherwise plenty of "unhandled firmware response" shows up in dmesg.
Index: if_iwm.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
retrieving revision 1.167
diff -u -p -r1.167 if_iwm.c
--- if_iwm.c 4 Apr 2017 00:40:52 -0000 1.167
+++ if_iwm.c 21 Apr 2017 15:59:48 -0000
@@ -4386,7 +4386,12 @@ iwm_add_sta_cmd(struct iwm_softc *sc, st
add_sta_cmd.tfd_queue_msk |=
htole32(1 << iwm_ac_to_tx_fifo[ac]);
}
- IEEE80211_ADDR_COPY(&add_sta_cmd.addr, in->in_ni.ni_bssid);
+ if (ic->ic_opmode == IEEE80211_M_MONITOR)
+ IEEE80211_ADDR_COPY(&add_sta_cmd.addr,
+ etherbroadcastaddr);
+ else
+ IEEE80211_ADDR_COPY(&add_sta_cmd.addr,
+ in->in_ni.ni_bssid);
}
add_sta_cmd.add_modify = update ? 1 : 0;
add_sta_cmd.station_flags_msk
@@ -5026,7 +5031,13 @@ iwm_mac_ctxt_cmd_common(struct iwm_softc
in->in_color));
cmd->action = htole32(action);
- cmd->mac_type = htole32(IWM_FW_MAC_TYPE_BSS_STA);
+ if (ic->ic_opmode == IEEE80211_M_MONITOR)
+ cmd->mac_type = htole32(IWM_FW_MAC_TYPE_LISTENER);
+ else if (ic->ic_opmode == IEEE80211_M_STA)
+ cmd->mac_type = htole32(IWM_FW_MAC_TYPE_BSS_STA);
+ else
+ panic("unsupported operating mode %d\n", ic->ic_opmode);
+
cmd->tsf_id = htole32(IWM_TSF_ID_A);
IEEE80211_ADDR_COPY(cmd->node_addr, ic->ic_myaddr);
@@ -5116,6 +5127,7 @@ int
iwm_mac_ctxt_cmd(struct iwm_softc *sc, struct iwm_node *in, uint32_t action,
int assoc)
{
+ struct ieee80211com *ic = &sc->sc_ic;
struct ieee80211_node *ni = &in->in_ni;
struct iwm_mac_ctx_cmd cmd;
@@ -5123,9 +5135,17 @@ iwm_mac_ctxt_cmd(struct iwm_softc *sc, s
iwm_mac_ctxt_cmd_common(sc, in, &cmd, action, assoc);
- /* Allow beacons to pass through as long as we are not associated or we
- * do not have dtim period information */
- if (!assoc || !ni->ni_associd || !ni->ni_dtimperiod)
+ if (ic->ic_opmode == IEEE80211_M_MONITOR) {
+ cmd.filter_flags = htole32(IWM_MAC_FILTER_IN_PROMISC |
+ IWM_MAC_FILTER_IN_CONTROL_AND_MGMT |
+ IWM_MAC_FILTER_IN_BEACON |
+ IWM_MAC_FILTER_IN_PROBE_REQUEST |
+ IWM_MAC_FILTER_IN_CRC32);
+ } else if (!assoc || !ni->ni_associd || !ni->ni_dtimperiod)
+ /*
+ * Allow beacons to pass through as long as we are not
+ * associated or we do not have dtim period information.
+ */
cmd.filter_flags |= htole32(IWM_MAC_FILTER_IN_BEACON);
else
iwm_mac_ctxt_cmd_fill_sta(sc, in, &cmd.sta, assoc);
@@ -5212,7 +5232,10 @@ iwm_auth(struct iwm_softc *sc)
if (err)
return err;
- sc->sc_phyctxt[0].channel = in->in_ni.ni_chan;
+ if (ic->ic_opmode == IEEE80211_M_MONITOR)
+ sc->sc_phyctxt[0].channel = ic->ic_ibss_chan;
+ else
+ sc->sc_phyctxt[0].channel = in->in_ni.ni_chan;
err = iwm_phy_ctxt_cmd(sc, &sc->sc_phyctxt[0], 1, 1,
IWM_FW_CTXT_ACTION_MODIFY, 0);
if (err)
@@ -5240,6 +5263,9 @@ iwm_auth(struct iwm_softc *sc)
return err;
}
+ if (ic->ic_opmode == IEEE80211_M_MONITOR)
+ return 0;
+
/*
* Prevent the FW from wandering off channel during association
* by "protecting" the session with a time event.
@@ -5467,8 +5493,12 @@ iwm_newstate_task(void *psc)
if (ostate == IEEE80211_S_SCAN && nstate != ostate)
iwm_led_blink_stop(sc);
- if (ostate == IEEE80211_S_RUN && nstate != ostate)
+ if (ostate == IEEE80211_S_RUN && nstate != ostate) {
+ if (ic->ic_opmode == IEEE80211_M_MONITOR)
+ iwm_led_blink_stop(sc);
iwm_disable_beacon_filter(sc);
+ }
+
/* Reset the device if moving out of AUTH, ASSOC, or RUN. */
/* XXX Is there a way to switch states without a full reset? */
@@ -5525,8 +5555,16 @@ iwm_newstate_task(void *psc)
break;
case IEEE80211_S_RUN:
+ if (ic->ic_opmode == IEEE80211_M_MONITOR) {
+ /* Add a MAC context and a sniffing STA. */
+ err = iwm_auth(sc);
+ if (err)
+ return;
+ }
+
/* Configure Rx chains for MIMO. */
- if ((in->in_ni.ni_flags & IEEE80211_NODE_HT) &&
+ if ((ic->ic_opmode == IEEE80211_M_MONITOR ||
+ (in->in_ni.ni_flags & IEEE80211_NODE_HT)) &&
!sc->sc_nvm.sku_cap_mimo_disable) {
err = iwm_phy_ctxt_cmd(sc, &sc->sc_phyctxt[0],
2, 2, IWM_FW_CTXT_ACTION_MODIFY, 0);
@@ -5537,6 +5575,17 @@ iwm_newstate_task(void *psc)
}
}
+ if (ic->ic_opmode == IEEE80211_M_MONITOR) {
+ err = iwm_update_quotas(sc, in);
+ if (err) {
+ printf("%s: could not update quotas "
+ "(error %d)\n", DEVNAME(sc), err);
+ return;
+ }
+ iwm_led_blink_start(sc);
+ break;
+ }
+
/* We have now been assigned an associd by the AP. */
err = iwm_mac_ctxt_cmd(sc, in, IWM_FW_CTXT_ACTION_MODIFY, 1);
if (err) {
@@ -5983,6 +6032,7 @@ int
iwm_init(struct ifnet *ifp)
{
struct iwm_softc *sc = ifp->if_softc;
+ struct ieee80211com *ic = &sc->sc_ic;
int err;
if (sc->sc_flags & IWM_FLAG_HW_INITED) {
@@ -6000,7 +6050,11 @@ iwm_init(struct ifnet *ifp)
ifq_clr_oactive(&ifp->if_snd);
ifp->if_flags |= IFF_RUNNING;
- ieee80211_begin_scan(ifp);
+ if (ic->ic_opmode != IEEE80211_M_MONITOR)
+ ieee80211_begin_scan(ifp);
+ else
+ ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
+
sc->sc_flags |= IWM_FLAG_HW_INITED;
return 0;
@@ -7201,6 +7255,7 @@ iwm_attach(struct device *parent, struct
IEEE80211_C_RSN | /* WPA/RSN */
IEEE80211_C_SCANALL | /* device scans all channels at once */
IEEE80211_C_SCANALLBAND | /* device scans all bands at once */
+ IEEE80211_C_MONITOR | /* monitor mode supported */
IEEE80211_C_SHSLOT | /* short slot time supported */
IEEE80211_C_SHPREAMBLE; /* short preamble supported */