Source-Changes-HG archive

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

[src/trunk]: src/sys Support WEP functions for awi driver.



details:   https://anonhg.NetBSD.org/src/rev/8e0efd67077e
branches:  trunk
changeset: 494251:8e0efd67077e
user:      onoe <onoe%NetBSD.org@localhost>
date:      Tue Jul 04 14:27:56 2000 +0000

description:
Support WEP functions for awi driver.
        arc4 implementation by Kalle Kaukonen has been added.
        define "wlan" in files.
                XXX: only awi depends on wlan for now.
        Allow authentication for adhoc (IBSS) mode.
Disable adhoc mode without bssid (mediaopt adhoc,flag0) for FH radio.
        FH cannot work without synchronization by beacons.
Align IP header for ethernet encapsulation (IFF_FLAG0) mode.
Print available access points for IFF_DEBUG.

diffstat:

 sys/conf/files              |   13 +-
 sys/crypto/arc4/arc4.c      |  111 ++++++++++++++
 sys/crypto/arc4/arc4.h      |   40 +++++
 sys/dev/ic/awi.c            |  330 ++++++++++++++++++++++++++++++++-----------
 sys/dev/ic/awi_wicfg.c      |   49 +++++-
 sys/dev/ic/awivar.h         |    7 +-
 sys/dev/pcmcia/files.pcmcia |    8 +-
 7 files changed, 454 insertions(+), 104 deletions(-)

diffs (truncated from 1115 to 300 lines):

diff -r bb2208d3272e -r 8e0efd67077e sys/conf/files
--- a/sys/conf/files    Tue Jul 04 14:18:06 2000 +0000
+++ b/sys/conf/files    Tue Jul 04 14:27:56 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.375 2000/06/24 00:37:19 thorpej Exp $
+#      $NetBSD: files,v 1.376 2000/07/04 14:27:56 onoe Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -168,6 +168,7 @@
 define hippi
 define token
 define sppp
+define wlan
 define crypto
 
 # devices ARPing IPv4 pull this in:
@@ -267,6 +268,13 @@
 device uha: scsi
 file   dev/ic/uha.c                    uha
 
+# AMD 79c930-based 802.11 cards
+device awi: arp, wlan, ifnet
+file   dev/ic/awi.c                    awi
+file   dev/ic/awi_wep.c                awi
+file   dev/ic/awi_wicfg.c              awi
+file   dev/ic/am79c930.c               awi
+
 # 3Com Etherlink-III Ethernet controller
 device ep: arp, ether, ifnet, mii, mii_bitbang
 file   dev/ic/elink3.c                 ep
@@ -542,6 +550,7 @@
 file coda/coda_venus.c                 coda
 file coda/coda_vfsops.c                        coda
 file coda/coda_vnops.c                 coda
+file crypto/arc4/arc4.c                        wlan
 file crypto/des/des_cbc.c              ipsec & ipsec_esp
 file crypto/des/des_ecb.c              ipsec & ipsec_esp
 file crypto/des/des_setkey.c           ipsec & ipsec_esp
@@ -780,7 +789,7 @@
 file net/if.c
 file net/if_arcsubr.c                  arc                     needs-flag
 file net/if_atmsubr.c                  atm
-file net/if_ethersubr.c                        ether | fddi | netatalk | token
+file net/if_ethersubr.c                        ether | fddi | netatalk | token | wlan
 file net/if_faith.c                    faith                   needs-count
 file net/if_fddisubr.c                 fddi                    needs-flag
 file net/if_gif.c                      gif                     needs-count
diff -r bb2208d3272e -r 8e0efd67077e sys/crypto/arc4/arc4.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/crypto/arc4/arc4.c    Tue Jul 04 14:27:56 2000 +0000
@@ -0,0 +1,111 @@
+/*     $NetBSD: arc4.c,v 1.1 2000/07/04 14:27:57 onoe Exp $    */
+
+/*
+ * ARC4 implementation
+ *     A Stream Cipher Encryption Algorithm "Arcfour"
+ *     <draft-kaukonen-cipher-arcfour-03.txt>
+ */
+
+/*        This code illustrates a sample implementation
+ *                 of the Arcfour algorithm
+ *         Copyright (c) April 29, 1997 Kalle Kaukonen.
+ *                    All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that this copyright
+ * notice and disclaimer are retained.
+ *
+ * THIS SOFTWARE IS PROVIDED BY KALLE KAUKONEN AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KALLE
+ * KAUKONEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <crypto/arc4/arc4.h>
+
+struct arc4_ctx {
+       int     x;
+       int     y;
+       int     state[256];
+       /* was unsigned char, changed to int for performance -- onoe */
+};
+
+int
+arc4_ctxlen()
+{
+       return sizeof(struct arc4_ctx);
+}
+
+void
+arc4_setkey(ctxp, key, keylen)
+       void *ctxp;
+       unsigned char *key;
+       int keylen;
+{
+       struct arc4_ctx *ctx = ctxp;
+       unsigned int i, t, u, ki, si;
+       unsigned int *state;
+
+       state = ctx->state;
+       ctx->x = 0;
+       ctx->y = 0;
+       for (i = 0; i < 256; i++)
+              state[i] = i;
+       ki = si = 0;
+       for (i = 0; i < 256; i++) {
+               t = state[i];
+               si = (si + key[ki] + t) & 0xff;
+               u = state[si];
+               state[si] = t;
+               state[i] = u;
+               if (++ki >= keylen)
+                       ki = 0;
+       }
+}
+
+void
+arc4_encrypt(ctxp, dst, src, len)
+       void *ctxp;
+       unsigned char *dst;
+       unsigned char *src;
+       int len;
+{
+       struct arc4_ctx *ctx = ctxp;
+       unsigned int x, y, sx, sy;
+       unsigned int *state;
+       const unsigned char *endsrc;
+
+       state = ctx->state;
+       x = ctx->x;
+       y = ctx->y;
+       for (endsrc = src + len; src != endsrc; src++, dst++) {
+               x = (x + 1) & 0xff;
+               sx = state[x];
+               y = (sx + y) & 0xff;
+               state[x] = sy = state[y];
+               state[y] = sx;
+               *dst = *src ^ state[(sx + sy) & 0xff];
+       }
+       ctx->x = x;
+       ctx->y = y;
+}
+
+void
+arc4_decrypt(ctxp, dst, src, len)
+       void *ctxp;
+       unsigned char *dst;
+       unsigned char *src;
+       int len;
+{
+       arc4_encrypt(ctxp, dst, src, len);
+}
diff -r bb2208d3272e -r 8e0efd67077e sys/crypto/arc4/arc4.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/crypto/arc4/arc4.h    Tue Jul 04 14:27:56 2000 +0000
@@ -0,0 +1,40 @@
+/*     $NetBSD: arc4.h,v 1.1 2000/07/04 14:27:57 onoe Exp $    */
+
+/*
+ * ARC4 implementation
+ *     A Stream Cipher Encryption Algorithm "Arcfour"
+ *     <draft-kaukonen-cipher-arcfour-03.txt>
+ */
+
+/*        This code illustrates a sample implementation
+ *                 of the Arcfour algorithm
+ *         Copyright (c) April 29, 1997 Kalle Kaukonen.
+ *                    All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that this copyright
+ * notice and disclaimer are retained.
+ *
+ * THIS SOFTWARE IS PROVIDED BY KALLE KAUKONEN AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KALLE
+ * KAUKONEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _CRYPTO_ARC4_H_
+#define        _CRYPTO_ARC4_H_
+
+int arc4_ctxlen __P((void));
+void arc4_setkey __P((void *, unsigned char *, int));
+void arc4_encrypt __P((void *, unsigned char *, unsigned char *, int));
+void arc4_decrypt __P((void *, unsigned char *, unsigned char *, int));
+
+#endif /* _CRYPTO_ARC4_H_ */
diff -r bb2208d3272e -r 8e0efd67077e sys/dev/ic/awi.c
--- a/sys/dev/ic/awi.c  Tue Jul 04 14:18:06 2000 +0000
+++ b/sys/dev/ic/awi.c  Tue Jul 04 14:27:56 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: awi.c,v 1.19 2000/06/09 14:36:25 onoe Exp $    */
+/*     $NetBSD: awi.c,v 1.20 2000/07/04 14:27:57 onoe Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -84,9 +84,10 @@
  * and to support adhoc mode by Atsushi Onoe <onoe%netbsd.org@localhost>
  */
 
-#include "opt_awi.h"
 #include "opt_inet.h"
 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
+#define        NBPFILTER       1
+#elif defined(__FreeBSD__) && __FreeBSD__ >= 3
 #include "bpf.h"
 #define        NBPFILTER       NBPF
 #else
@@ -186,7 +187,7 @@
 static void awi_try_sync __P((struct awi_softc *sc));
 static void awi_sync_done __P((struct awi_softc *sc));
 static void awi_send_deauth __P((struct awi_softc *sc));
-static void awi_send_auth __P((struct awi_softc *sc));
+static void awi_send_auth __P((struct awi_softc *sc, int seq));
 static void awi_recv_auth __P((struct awi_softc *sc, struct mbuf *m0));
 static void awi_send_asreq __P((struct awi_softc *sc, int reassoc));
 static void awi_recv_asresp __P((struct awi_softc *sc, struct mbuf *m0));
@@ -200,9 +201,10 @@
 static int awi_intr_lock __P((struct awi_softc *sc));
 static void awi_intr_unlock __P((struct awi_softc *sc));
 static int awi_cmd_wait __P((struct awi_softc *sc));
+static void awi_print_essid __P((u_int8_t *essid));
 
 #ifdef AWI_DEBUG
-static void awi_dump_pkt __P((struct awi_softc *sc, struct mbuf *m, u_int8_t rssi));
+static void awi_dump_pkt __P((struct awi_softc *sc, struct mbuf *m, int rssi));
 int awi_verbose = 0;
 int awi_dump = 0;
 #define        AWI_DUMP_MASK(fc0)  (1 << (((fc0) & IEEE80211_FC0_SUBTYPE_MASK) >> 4))
@@ -309,7 +311,6 @@
            ETHER_ADDR_LEN);
 #endif
 
-       awi_read_bytes(sc, AWI_BANNER, sc->sc_banner, AWI_BANNER_LEN);
        printf("%s: IEEE802.11 %s %dMbps (firmware %s)\n",
            sc->sc_dev.dv_xname,
            sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH ? "FH" : "DS",
@@ -340,8 +341,9 @@
                ifmedia_add(&sc->sc_media, mword, 0, NULL);
                ifmedia_add(&sc->sc_media,
                    mword | IFM_IEEE80211_ADHOC, 0, NULL);
-               ifmedia_add(&sc->sc_media,
-                   mword | IFM_IEEE80211_ADHOC | IFM_FLAG0, 0, NULL);
+               if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_FH)
+                       ifmedia_add(&sc->sc_media,
+                           mword | IFM_IEEE80211_ADHOC | IFM_FLAG0, 0, NULL);
        }
        awi_media_status(ifp, &imr);
        ifmedia_set(&sc->sc_media, imr.ifm_active);
@@ -667,7 +669,10 @@
        }
        if (ime->ifm_media & IFM_IEEE80211_ADHOC) {
                sc->sc_mib_local.Network_Mode = 0;
-               sc->sc_no_bssid = (ime->ifm_media & IFM_FLAG0) ? 1 : 0;
+               if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
+                       sc->sc_no_bssid = 0;
+               else
+                       sc->sc_no_bssid = (ime->ifm_media & IFM_FLAG0) ? 1 : 0;
        } else {
                sc->sc_mib_local.Network_Mode = 1;
        }
@@ -805,6 +810,9 @@
        sc->sc_mib_local.Accept_All_Multicast_Dis = 1;
 
   set_mib:
+#ifdef notdef  /* allow non-encrypted frame for receiving. */
+       sc->sc_mib_mgt.Wep_Required = sc->sc_wep_algo != NULL ? 1 : 0;
+#endif
        if (!sc->sc_enabled) {
                sc->sc_enabled = 1;
                if (sc->sc_enable)
@@ -895,6 +903,7 @@
        if (sc->sc_rx_timer && --sc->sc_rx_timer == 0) {
                printf("%s: no recent beacons from %s; rescanning\n",
                    sc->sc_dev.dv_xname, ether_sprintf(sc->sc_bss.bssid));
+               ifp->if_flags &= ~IFF_RUNNING;
                awi_start_scan(sc);
        }
        if (sc->sc_mgt_timer && --sc->sc_mgt_timer == 0) {
@@ -967,6 +976,10 @@



Home | Main Index | Thread Index | Old Index