Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Adapt atw(4) to the new 802.11 layer.



details:   https://anonhg.NetBSD.org/src/rev/a9a085b53a18
branches:  trunk
changeset: 553257:a9a085b53a18
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Mon Oct 13 08:22:19 2003 +0000

description:
Adapt atw(4) to the new 802.11 layer.

Simplify atw_start, atw_newstate.

Synchronize access to atw_start by bracketing the call to
ieee80211_next_scan in atw_next_scan with splnet()/splx().

diffstat:

 sys/dev/cardbus/if_atw_cardbus.c |    8 +-
 sys/dev/ic/atw.c                 |  487 ++++++++++++++++++++++----------------
 sys/dev/ic/atwvar.h              |   54 +++-
 sys/dev/pci/if_atw_pci.c         |   10 +-
 4 files changed, 330 insertions(+), 229 deletions(-)

diffs (truncated from 1090 to 300 lines):

diff -r abd96a4b23ed -r a9a085b53a18 sys/dev/cardbus/if_atw_cardbus.c
--- a/sys/dev/cardbus/if_atw_cardbus.c  Mon Oct 13 08:10:48 2003 +0000
+++ b/sys/dev/cardbus/if_atw_cardbus.c  Mon Oct 13 08:22:19 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_atw_cardbus.c,v 1.1 2003/07/06 22:57:23 dyoung Exp $        */
+/*     $NetBSD: if_atw_cardbus.c,v 1.2 2003/10/13 08:22:19 dyoung Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2003 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_atw_cardbus.c,v 1.1 2003/07/06 22:57:23 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_atw_cardbus.c,v 1.2 2003/10/13 08:22:19 dyoung Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -65,7 +65,9 @@
 #include <net/if_dl.h>
 #include <net/if_media.h>
 #include <net/if_ether.h>
-#include <net/if_ieee80211.h>
+
+#include <net80211/ieee80211_compat.h>
+#include <net80211/ieee80211_var.h>
 
 #if NBPFILTER > 0 
 #include <net/bpf.h>
diff -r abd96a4b23ed -r a9a085b53a18 sys/dev/ic/atw.c
--- a/sys/dev/ic/atw.c  Mon Oct 13 08:10:48 2003 +0000
+++ b/sys/dev/ic/atw.c  Mon Oct 13 08:22:19 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atw.c,v 1.2 2003/09/20 01:03:30 dyoung Exp $   */
+/*     $NetBSD: atw.c,v 1.3 2003/10/13 08:22:19 dyoung Exp $   */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atw.c,v 1.2 2003/09/20 01:03:30 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atw.c,v 1.3 2003/10/13 08:22:19 dyoung Exp $");
 
 #include "bpfilter.h"
 
@@ -65,7 +65,9 @@
 #include <net/if_dl.h>
 #include <net/if_media.h>
 #include <net/if_ether.h>
-#include <net/if_ieee80211.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_compat.h>
 
 #if NBPFILTER > 0 
 #include <net/bpf.h>
@@ -142,6 +144,7 @@
 int atw_rfio_disable_delay = 2 * 1000;
 int atw_writewep_delay = 5;
 int atw_beacon_len_adjust = 4;
+int atw_dwelltime = 200;
 
 #ifdef ATW_DEBUG
 int atw_xhdrctl = 0;
@@ -197,7 +200,7 @@
 void   atw_txintr __P((struct atw_softc *));
 void   atw_linkintr __P((struct atw_softc *, u_int32_t));
 
-static int atw_newstate(void *, enum ieee80211_state);
+static int atw_newstate(struct ieee80211com *, enum ieee80211_state, int);
 static void atw_tsf(struct atw_softc *);
 static void atw_start_beacon(struct atw_softc *, int);
 static void atw_write_wep(struct atw_softc *);
@@ -207,12 +210,17 @@
 static void atw_write_sup_rates(struct atw_softc *);
 static void atw_clear_sram(struct atw_softc *);
 static void atw_write_sram(struct atw_softc *, u_int, u_int8_t *, u_int);
+static int atw_media_change(struct ifnet *);
 static void atw_media_status(struct ifnet *, struct ifmediareq *);
 static void atw_filter_setup(struct atw_softc *);
 static void atw_frame_setdurs(struct atw_softc *, struct atw_frame *, int, int);
 static __inline u_int64_t atw_predict_beacon(u_int64_t, u_int32_t);
-static void atw_recv_beacon(struct ieee80211com *, struct mbuf *, int,
-    u_int32_t);
+static void atw_recv_beacon(struct ieee80211com *, struct mbuf *,
+    struct ieee80211_node *, int, int, u_int32_t);
+static void atw_recv_mgmt(struct ieee80211com *, struct mbuf *,
+    struct ieee80211_node *, int, int, u_int32_t);
+static void atw_node_free(struct ieee80211com *, struct ieee80211_node *);
+static struct ieee80211_node *atw_node_alloc(struct ieee80211com *);
 
 static int atw_tune(struct atw_softc *);
 
@@ -643,31 +651,37 @@
        country_code = MASK_AND_RSHIFT(sc->sc_srom[ATW_SR_CTRY_CR29],
            ATW_SR_CTRY_MASK);
 
+#define ADD_CHANNEL(_ic, _chan) do {                                   \
+       _ic->ic_channels[_chan].ic_flags = IEEE80211_CHAN_B;            \
+       _ic->ic_channels[_chan].ic_freq =                               \
+           ieee80211_ieee2mhz(_chan, _ic->ic_channels[_chan].ic_flags);\
+} while (0)
+
        /* Find available channels */
        switch (country_code) {
        case COUNTRY_MMK2:      /* 1-14 */
-               setbit(ic->ic_chan_avail, 14);
+               ADD_CHANNEL(ic, 14);
                /*FALLTHROUGH*/
        case COUNTRY_ETSI:      /* 1-13 */
                for (i = 1; i <= 13; i++)
-                       setbit(ic->ic_chan_avail, i);
+                       ADD_CHANNEL(ic, i);
                break;
        case COUNTRY_FCC:       /* 1-11 */
        case COUNTRY_IC:        /* 1-11 */
                for (i = 1; i <= 11; i++)
-                       setbit(ic->ic_chan_avail, i);
+                       ADD_CHANNEL(ic, i);
                break;
        case COUNTRY_MMK:       /* 14 */
-               setbit(ic->ic_chan_avail, 14);
+               ADD_CHANNEL(ic, 14);
                break;
        case COUNTRY_FRANCE:    /* 10-13 */
                for (i = 10; i <= 13; i++)
-                       setbit(ic->ic_chan_avail, i);
+                       ADD_CHANNEL(ic, i);
                break;
        default:        /* assume channels 10-11 */
        case COUNTRY_SPAIN:     /* 10-11 */
                for (i = 10; i <= 11; i++)
-                       setbit(ic->ic_chan_avail, i);
+                       ADD_CHANNEL(ic, i);
                break;
        }
 
@@ -701,21 +715,15 @@
 
        ic->ic_phytype = IEEE80211_T_DS;
        ic->ic_opmode = IEEE80211_M_STA;
-       ic->ic_flags = IEEE80211_F_HASPMGT | IEEE80211_F_HASIBSS |
-           IEEE80211_F_HASHOSTAP | IEEE80211_F_HASWEP;
-       ic->ic_state = IEEE80211_S_INIT;
-       ic->ic_newstate = atw_newstate;
-
-#if 0
-       ic->ic_pfxlen = offsetof(struct atw_frame, atw_ihdr);
-#endif
-       ic->ic_hdrlen = sizeof(struct ieee80211_frame_addr4);
+       ic->ic_caps = IEEE80211_C_PMGT | IEEE80211_C_IBSS |
+           IEEE80211_C_HOSTAP | IEEE80211_C_MONITOR | IEEE80211_C_WEP;
 
        nrate = 0;
-       ic->ic_sup_rates[nrate++] = 2;
-       ic->ic_sup_rates[nrate++] = 4;
-       ic->ic_sup_rates[nrate++] = 11;
-       ic->ic_sup_rates[nrate++] = 22;
+       ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[nrate++] = 2;
+       ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[nrate++] = 4;
+       ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[nrate++] = 11;
+       ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[nrate++] = 22;
+       ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates = nrate;
 
        /*
         * Call MI attach routines.
@@ -724,31 +732,27 @@
        if_attach(ifp);
        ieee80211_ifattach(ifp);
 
-       callout_init(&sc->sc_scan_timer);
-
-       /* hardware answers probe request */
-       ic->ic_recv_mgmt[IEEE80211_FC0_SUBTYPE_PROBE_REQ
-           >> IEEE80211_FC0_SUBTYPE_SHIFT] = NULL;
-
-        /* NB: override default setting */
-       ic->ic_media.ifm_status = atw_media_status;
+       sc->sc_newstate = ic->ic_newstate;
+       ic->ic_newstate = atw_newstate;
+
+       sc->sc_recv_mgmt = ic->ic_recv_mgmt;
+       ic->ic_recv_mgmt = atw_recv_mgmt;
+
+       sc->sc_node_free = ic->ic_node_free;
+       ic->ic_node_free = atw_node_free;
+
+       sc->sc_node_alloc = ic->ic_node_alloc;
+       ic->ic_node_alloc = atw_node_alloc;
 
        /* possibly we should fill in our own sc_send_prresp, since
         * the ADM8211 is probably sending probe responses in ad hoc
         * mode.
         */
 
-       sc->sc_recv_beacon =
-           ic->ic_recv_mgmt[IEEE80211_FC0_SUBTYPE_BEACON >>
-               IEEE80211_FC0_SUBTYPE_SHIFT];
-       sc->sc_recv_prresp =
-           ic->ic_recv_mgmt[IEEE80211_FC0_SUBTYPE_PROBE_RESP >>
-               IEEE80211_FC0_SUBTYPE_SHIFT];
-
-       ic->ic_recv_mgmt[IEEE80211_FC0_SUBTYPE_BEACON
-           >> IEEE80211_FC0_SUBTYPE_SHIFT] = atw_recv_beacon;
-       ic->ic_recv_mgmt[IEEE80211_FC0_SUBTYPE_PROBE_RESP
-           >> IEEE80211_FC0_SUBTYPE_SHIFT] = atw_recv_beacon;
+       /* complete initialization */
+       ieee80211_media_init(ifp, atw_media_change, atw_media_status);
+       callout_init(&sc->sc_scan_ch);
+
 #if 0
 #if NBPFILTER > 0
        bpfattach2(ifp, DLT_IEEE802_11_RADIO, /* ??? */,
@@ -803,6 +807,26 @@
        return;
 }
 
+static struct ieee80211_node *
+atw_node_alloc(struct ieee80211com *ic)
+{
+       struct atw_softc *sc = (struct atw_softc *)ic->ic_if.if_softc;
+       struct ieee80211_node *ni = (*sc->sc_node_alloc)(ic);
+
+       DPRINTF(sc, ("%s: alloc node %p\n", sc->sc_dev.dv_xname, ni));
+       return ni;
+}
+
+static void
+atw_node_free(struct ieee80211com *ic, struct ieee80211_node *ni)
+{
+       struct atw_softc *sc = (struct atw_softc *)ic->ic_if.if_softc;
+
+       DPRINTF(sc, ("%s: freeing node %p %s\n", sc->sc_dev.dv_xname, ni,
+           ether_sprintf(ni->ni_bssid)));
+       (*sc->sc_node_free)(ic, ni);
+}
+
 /*
  * atw_reset:
  *
@@ -869,7 +893,7 @@
 
 /* TBD atw_init
  *
- * set MAC based on ic->ic_bss.myaddr
+ * set MAC based on ic->ic_bss->myaddr
  * write WEP keys
  * set TX rate
  */
@@ -898,6 +922,11 @@
         */
        atw_stop(ifp, 0);
 
+       ic->ic_bss->ni_chan = ic->ic_ibss_chan;
+       DPRINTF(sc, ("%s: channel %d freq %d flags 0x%04x\n",
+           __func__, ieee80211_chan2ieee(ic, ic->ic_bss->ni_chan),
+           ic->ic_bss->ni_chan->ic_freq, ic->ic_bss->ni_chan->ic_flags));
+
        /* Turn off APM??? (A binary-only driver does this.)
         *
         * Set Rx store-and-forward mode.
@@ -1185,19 +1214,18 @@
        switch (ic->ic_opmode) {
        case IEEE80211_M_IBSS:
        case IEEE80211_M_STA:
-               error = ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1);
+               error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
                if (error)
                        goto out;
                break;
        case IEEE80211_M_AHDEMO:
        case IEEE80211_M_HOSTAP:
-               ic->ic_bss.ni_chan = ic->ic_ibss_chan;
-               ic->ic_bss.ni_intval = ic->ic_lintval;
-               ic->ic_bss.ni_rssi = 0;
-               ic->ic_bss.ni_rstamp = 0;
+               ic->ic_bss->ni_intval = ic->ic_lintval;
+               ic->ic_bss->ni_rssi = 0;
+               ic->ic_bss->ni_rstamp = 0;
                ic->ic_state = IEEE80211_S_SCAN;        /*XXX*/
 
-               error = ieee80211_new_state(&ic->ic_if, IEEE80211_S_RUN, -1);
+               error = ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
                if (error)
                        goto out;
                break;
@@ -1207,7 +1235,7 @@
 
        atw_write_ssid(sc);
        atw_write_sup_rates(sc);
-       if (ic->ic_flags & IEEE80211_F_HASWEP)
+       if (ic->ic_caps & IEEE80211_C_WEP)
                atw_write_wep(sc);
 
        /*
@@ -1226,6 +1254,7 @@
         */
        ifp->if_flags |= IFF_RUNNING;



Home | Main Index | Thread Index | Old Index