Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add support for Prism monitor mode. From Kevin Lahey



details:   https://anonhg.NetBSD.org/src/rev/d53e547e8e95
branches:  trunk
changeset: 543433:d53e547e8e95
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Tue Feb 25 01:57:35 2003 +0000

description:
Add support for Prism monitor mode. From Kevin Lahey
<kml%patheticgeek.net@localhost>.

This patch does NOT add monitor mode support for the Lucent radios.

awi(4) was only modified for compatibility with the new mediaopt.
It does NOT support monitor mode.

Tested by Kevin, Daniel Carosone, and I.

diffstat:

 sys/dev/ic/awi.c           |   8 ++++++--
 sys/dev/ic/wi.c            |  32 ++++++++++++++++++++++++++------
 sys/net/if_ieee80211.h     |   7 +++++--
 sys/net/if_ieee80211subr.c |  14 ++++++++++++--
 sys/net/if_media.h         |   4 +++-
 5 files changed, 52 insertions(+), 13 deletions(-)

diffs (248 lines):

diff -r d3ab422cac03 -r d53e547e8e95 sys/dev/ic/awi.c
--- a/sys/dev/ic/awi.c  Tue Feb 25 00:56:35 2003 +0000
+++ b/sys/dev/ic/awi.c  Tue Feb 25 01:57:35 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: awi.c,v 1.51 2003/01/18 10:14:20 thorpej Exp $ */
+/*     $NetBSD: awi.c,v 1.52 2003/02/25 01:57:35 dyoung Exp $  */
 
 /*-
  * Copyright (c) 1999,2000,2001 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awi.c,v 1.51 2003/01/18 10:14:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awi.c,v 1.52 2003/02/25 01:57:35 dyoung Exp $");
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -504,6 +504,8 @@
                sc->sc_mib_local.Network_Mode = 1;
                sc->sc_mib_local.Acting_as_AP = 1;
                break;
+       case IEEE80211_M_MONITOR:
+               return ENODEV;
        }
        IEEE80211_ADDR_COPY(ic->ic_myaddr, LLADDR(ifp->if_sadl));
        memset(&sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
@@ -951,6 +953,8 @@
        }
        imr->ifm_active |= ieee80211_rate2media(rate, ic->ic_phytype);
        switch (ic->ic_opmode) {
+       case IEEE80211_M_MONITOR: /* we should never reach here */
+               break;
        case IEEE80211_M_STA:
                break;
        case IEEE80211_M_IBSS:
diff -r d3ab422cac03 -r d53e547e8e95 sys/dev/ic/wi.c
--- a/sys/dev/ic/wi.c   Tue Feb 25 00:56:35 2003 +0000
+++ b/sys/dev/ic/wi.c   Tue Feb 25 01:57:35 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wi.c,v 1.111 2003/02/25 00:51:14 dyoung Exp $  */
+/*     $NetBSD: wi.c,v 1.112 2003/02/25 01:57:35 dyoung Exp $  */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.111 2003/02/25 00:51:14 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wi.c,v 1.112 2003/02/25 01:57:35 dyoung Exp $");
 
 #define WI_HERMES_AUTOINC_WAR  /* Work around data write autoinc bug. */
 #define WI_HERMES_STATS_WAR    /* Work around stats counter bug. */
@@ -304,6 +304,7 @@
                if (sc->sc_sta_firmware_ver >= 800) {
                        ic->ic_flags |= IEEE80211_F_HASHOSTAP;
                        ic->ic_flags |= IEEE80211_F_HASIBSS;
+                       ic->ic_flags |= IEEE80211_F_HASMONITOR;
                }
                sc->sc_ibss_port = 0;
                break;
@@ -350,6 +351,8 @@
                ADD(IFM_AUTO, IFM_IEEE80211_HOSTAP);
        if (ic->ic_flags & IEEE80211_F_HASIBSS)
                ADD(IFM_AUTO, IFM_IEEE80211_ADHOC);
+       if (ic->ic_flags & IEEE80211_F_HASMONITOR)
+               ADD(IFM_AUTO, IFM_IEEE80211_MONITOR);
        ADD(IFM_AUTO, IFM_IEEE80211_ADHOC | IFM_FLAG0);
        for (i = 0; i < nrate; i++) {
                r = ic->ic_sup_rates[i];
@@ -363,6 +366,8 @@
                        ADD(mword, IFM_IEEE80211_HOSTAP);
                if (ic->ic_flags & IEEE80211_F_HASIBSS)
                        ADD(mword, IFM_IEEE80211_ADHOC);
+               if (ic->ic_flags & IEEE80211_F_HASMONITOR)
+                       ADD(mword, IFM_IEEE80211_MONITOR);
                ADD(mword, IFM_IEEE80211_ADHOC | IFM_FLAG0);
        }
        printf("\n");
@@ -559,6 +564,9 @@
        case IEEE80211_M_HOSTAP:
                wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_HOSTAP);
                break;
+       case IEEE80211_M_MONITOR:
+               wi_cmd(sc, WI_CMD_TEST | (WI_TEST_MONITOR << 8), 0, 0, 0);
+               break;
        }
 
        /* Intersil interprets this RID as joining ESS even in IBSS mode */
@@ -647,6 +655,7 @@
        ifp->if_flags |= IFF_RUNNING;
        ifp->if_flags &= ~IFF_OACTIVE;
        if (ic->ic_opmode == IEEE80211_M_AHDEMO ||
+           ic->ic_opmode == IEEE80211_M_MONITOR ||
            ic->ic_opmode == IEEE80211_M_HOSTAP)
                wi_newstate(sc, IEEE80211_S_RUN);
 
@@ -1021,6 +1030,8 @@
                newmode = IEEE80211_M_IBSS;
        else if (ime->ifm_media & IFM_IEEE80211_HOSTAP)
                newmode = IEEE80211_M_HOSTAP;
+       else if (ime->ifm_media & IFM_IEEE80211_MONITOR)
+               newmode = IEEE80211_M_MONITOR;
        else
                newmode = IEEE80211_M_STA;
        if (ic->ic_opmode != newmode) {
@@ -1086,6 +1097,9 @@
        case IEEE80211_M_HOSTAP:
                imr->ifm_active |= IFM_IEEE80211_HOSTAP;
                break;
+       case IEEE80211_M_MONITOR:
+               imr->ifm_active |= IFM_IEEE80211_MONITOR;
+               break;
        }
 }
 
@@ -1154,11 +1168,17 @@
        len = le16toh(frmhdr.wi_dat_len);
        off = ALIGN(sizeof(struct ieee80211_frame));
 
+       /* Sometimes the PRISM2.x returns bogusly large frames. Except
+        * in monitor mode, just throw them away.
+        */
        if (off + len > MCLBYTES) {
-               CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
-               ifp->if_ierrors++;
-               DPRINTF(("wi_rx_intr: oversized packet\n"));
-               return;
+               if (ic->ic_opmode != IEEE80211_M_MONITOR) {
+                       CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
+                       ifp->if_ierrors++;
+                       DPRINTF(("wi_rx_intr: oversized packet\n"));
+                       return;
+               } else
+                       len = 0;
        }
 
        MGETHDR(m, M_DONTWAIT, MT_DATA);
diff -r d3ab422cac03 -r d53e547e8e95 sys/net/if_ieee80211.h
--- a/sys/net/if_ieee80211.h    Tue Feb 25 00:56:35 2003 +0000
+++ b/sys/net/if_ieee80211.h    Tue Feb 25 01:57:35 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ieee80211.h,v 1.25 2002/11/16 06:08:31 dyoung Exp $ */
+/*     $NetBSD: if_ieee80211.h,v 1.26 2003/02/25 01:57:35 dyoung Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -377,7 +377,9 @@
        IEEE80211_M_STA = 1,            /* infrastructure station */
        IEEE80211_M_IBSS = 0,           /* IBSS (adhoc) station */
        IEEE80211_M_AHDEMO = 3,         /* Old lucent compatible adhoc demo */
-       IEEE80211_M_HOSTAP = 6          /* Software Access Point */
+       IEEE80211_M_HOSTAP = 6,         /* Software Access Point */
+       IEEE80211_M_MONITOR = 8         /* Monitor mode (doesn't correspond
+                                          to a PRISM port like the others) */
 };
 
 enum ieee80211_state {
@@ -502,6 +504,7 @@
 #define        IEEE80211_F_HASPMGT     0x00040000      /* CAPABILITY: Power mgmt */
 #define        IEEE80211_F_HASHOSTAP   0x00080000      /* CAPABILITY: HOSTAP avail */
 #define        IEEE80211_F_HASAHDEMO   0x00100000      /* CAPABILITY: Old Adhoc Demo */
+#define        IEEE80211_F_HASMONITOR  0x00200000      /* CAPABILITY: Monitor mode */
 
 /* flags for ieee80211_fix_rate() */
 #define        IEEE80211_F_DOSORT      0x00000001      /* sort rate list */
diff -r d3ab422cac03 -r d53e547e8e95 sys/net/if_ieee80211subr.c
--- a/sys/net/if_ieee80211subr.c        Tue Feb 25 00:56:35 2003 +0000
+++ b/sys/net/if_ieee80211subr.c        Tue Feb 25 01:57:35 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ieee80211subr.c,v 1.23 2003/01/19 23:17:21 simonb Exp $     */
+/*     $NetBSD: if_ieee80211subr.c,v 1.24 2003/02/25 01:57:36 dyoung Exp $     */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ieee80211subr.c,v 1.23 2003/01/19 23:17:21 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ieee80211subr.c,v 1.24 2003/02/25 01:57:36 dyoung Exp $");
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -288,6 +288,8 @@
                                ni = &ic->ic_bss;       /* XXX allocate? */
                        }
                        break;
+               case IEEE80211_M_MONITOR:
+                       goto out;
                }
                ni->ni_rssi = rssi;
                ni->ni_rstamp = rstamp;
@@ -354,6 +356,9 @@
                                goto err;
                        }
                        break;
+               case IEEE80211_M_MONITOR:
+                       /* Should never get here */
+                       break;
                }
                if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
                        if (ic->ic_flags & IEEE80211_F_WEPON) {
@@ -601,6 +606,10 @@
                IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid);
                IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);
                break;
+       case IEEE80211_M_MONITOR:
+               /* Should never get here! */
+               m_freem(m);
+               return NULL;
        }
        return m;
 }
@@ -1884,6 +1893,7 @@
                break;
 
        case IEEE80211_M_AHDEMO:
+       case IEEE80211_M_MONITOR:
                /* should not come here */
                break;
 
diff -r d3ab422cac03 -r d53e547e8e95 sys/net/if_media.h
--- a/sys/net/if_media.h        Tue Feb 25 00:56:35 2003 +0000
+++ b/sys/net/if_media.h        Tue Feb 25 01:57:35 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_media.h,v 1.32 2002/11/07 08:00:47 thorpej Exp $    */
+/*     $NetBSD: if_media.h,v 1.33 2003/02/25 01:57:36 dyoung Exp $     */
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -215,6 +215,7 @@
 
 #define        IFM_IEEE80211_ADHOC      0x00000100     /* Operate in Adhoc mode */
 #define        IFM_IEEE80211_HOSTAP     0x00000200     /* Operate in Host AP mode */
+#define        IFM_IEEE80211_MONITOR    0x00000400     /* Operate in Monitor mode */
 
 /*
  * Shared media sub-types
@@ -417,6 +418,7 @@
        { IFM_IEEE80211|IFM_IEEE80211_ADHOC,    "adhoc" },              \
        { IFM_IEEE80211|IFM_IEEE80211_ADHOC,    "ibss" },               \
        { IFM_IEEE80211|IFM_IEEE80211_HOSTAP,   "hostap" },             \
+       { IFM_IEEE80211|IFM_IEEE80211_MONITOR,  "monitor" },            \
                                                                        \
        { 0, NULL },                                                    \
 }



Home | Main Index | Thread Index | Old Index