Source-Changes-HG archive

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

[src/netbsd-1-5]: src Pullups 802.11 stuff (approved by jhawk)



details:   https://anonhg.NetBSD.org/src/rev/2b669c4a4faa
branches:  netbsd-1-5
changeset: 488614:2b669c4a4faa
user:      onoe <onoe%NetBSD.org@localhost>
date:      Fri Jul 21 18:45:44 2000 +0000

description:
Pullups 802.11 stuff (approved by jhawk)
- allow non-string nwid settings
        basesrc/sbin/ifconfig/ifconfig.c                1.82-1.86
        basesrc/sbin/ifconfig/ifconfig.8                1.37
        syssrc/sys/dev/ic/awi.c                         1.21
        syssrc/sys/dev/pcmcia/if_ray.c                  1.21
        syssrc/sys/dev/pcmcia/if_wi.c                   1.23
        syssrc/sys/dev/pcmcia/if_wivar.h                1.10
        syssrc/sys/net/if_ieee80211.h                   1.4

diffstat:

 sbin/ifconfig/ifconfig.8  |   4 ++-
 sbin/ifconfig/ifconfig.c  |  68 ++++++++++++++++++++++++++++++++++++++++------
 sys/dev/ic/awi.c          |  23 +++++++--------
 sys/dev/pcmcia/if_ray.c   |  67 +++++++++++++++++++++++++++++----------------
 sys/dev/pcmcia/if_wi.c    |  67 ++++++++++++++++++++--------------------------
 sys/dev/pcmcia/if_wivar.h |  16 ++--------
 sys/net/if_ieee80211.h    |   9 ++++-
 7 files changed, 155 insertions(+), 99 deletions(-)

diffs (truncated from 560 to 300 lines):

diff -r bf5bb4dc4074 -r 2b669c4a4faa sbin/ifconfig/ifconfig.8
--- a/sbin/ifconfig/ifconfig.8  Fri Jul 21 16:32:21 2000 +0000
+++ b/sbin/ifconfig/ifconfig.8  Fri Jul 21 18:45:44 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ifconfig.8,v 1.32.4.3 2000/07/03 22:12:46 thorpej Exp $
+.\"    $NetBSD: ifconfig.8,v 1.32.4.4 2000/07/21 18:45:45 onoe Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -298,6 +298,8 @@
 .It Cm nwid Ar id
 (IEEE 802.11 devices only)
 Configure network ID for IEEE 802.11-based wireless network interfaces.
+.Ar Id
+can either be a string or a series of hexadecimal digits.
 .It Cm tunnel Ar src_addr Ar dest_addr
 (IP tunnel devices only)
 Configure the physical source and destination address for IP tunnel
diff -r bf5bb4dc4074 -r 2b669c4a4faa sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Fri Jul 21 16:32:21 2000 +0000
+++ b/sbin/ifconfig/ifconfig.c  Fri Jul 21 18:45:44 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.79.4.1 2000/06/30 18:12:46 thorpej Exp $        */
+/*     $NetBSD: ifconfig.c,v 1.79.4.2 2000/07/21 18:45:44 onoe Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
 #if 0
 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
 #else
-__RCSID("$NetBSD: ifconfig.c,v 1.79.4.1 2000/06/30 18:12:46 thorpej Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.79.4.2 2000/07/21 18:45:44 onoe Exp $");
 #endif
 #endif /* not lint */
 
@@ -1049,12 +1049,41 @@
        const char *val;
        int d;
 {
-       u_int8_t nwid[IEEE80211_NWID_LEN];
+       struct ieee80211_nwid nwid;
+       int len;
+       u_int8_t *p;
 
        memset(&nwid, 0, sizeof(nwid));
-       (void)strncpy(nwid, val, sizeof(nwid));
+       if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) {
+               val += 2;
+               p = nwid.i_nwid;
+               while (isxdigit((u_char)val[0]) && isxdigit((u_char)val[1])) {
+                       if (p >= nwid.i_nwid + sizeof(nwid.i_nwid)) {
+                               warnx("SIOCS80211NWID: Too long nwid.");
+                               return;
+                       }
+#define        tohex(x)        (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
+                       *p++ = (tohex((u_char)val[0]) << 4) |
+                           tohex((u_char)val[1]);
+#undef tohex
+                       val += 2;
+               }
+               if (*val != '\0') {
+                       warnx("SIOCS80211NWID: Bad hexadecimal digits.");
+                       return;
+               }
+               nwid.i_len = p - nwid.i_nwid;
+       } else {
+               len = strlen(val);
+               if (len > sizeof(nwid.i_nwid)) {
+                       warnx("SIOCS80211NWID: Too long nwid.");
+                       return;
+               }
+               nwid.i_len = len;
+               memcpy(nwid.i_nwid, val, len);
+       }
        (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
-       ifr.ifr_data = (caddr_t)nwid;
+       ifr.ifr_data = (caddr_t)&nwid;
        if (ioctl(s, SIOCS80211NWID, (caddr_t)&ifr) < 0)
                warn("SIOCS80211NWID");
 }
@@ -1062,14 +1091,33 @@
 void
 ieee80211_status()
 {
-       u_int8_t nwid[IEEE80211_NWID_LEN + 1];
+       int i;
+       struct ieee80211_nwid nwid;
 
        memset(&ifr, 0, sizeof(ifr));
-       ifr.ifr_data = (caddr_t)nwid;
+       ifr.ifr_data = (caddr_t)&nwid;
        (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
-       nwid[IEEE80211_NWID_LEN] = 0;
-       if (ioctl(s, SIOCG80211NWID, (caddr_t)&ifr) == 0)
-               printf("\tnwid %s\n", nwid);
+       if (ioctl(s, SIOCG80211NWID, (caddr_t)&ifr) != 0)
+               return;
+       if (nwid.i_len > IEEE80211_NWID_LEN) {
+               warnx("SIOCG80211NWID: wrong length of nwid (%d)", nwid.i_len);
+               return;
+       }
+       i = 0;
+       if (nwid.i_nwid[0] != '0' || tolower(nwid.i_nwid[1]) != 'x') {
+               for (; i < nwid.i_len; i++) {
+                       if (!isprint(nwid.i_nwid[i]))
+                               break;
+               }
+       }
+       if (i == nwid.i_len)
+               printf("\tnwid \"%.*s\"\n", nwid.i_len, nwid.i_nwid);
+       else {
+               printf("\tnwid 0x");
+               for (i = 0; i < nwid.i_len; i++)
+                       printf("%02x", nwid.i_nwid[i]);
+               printf("\n");
+       }
 }
 
 void
diff -r bf5bb4dc4074 -r 2b669c4a4faa sys/dev/ic/awi.c
--- a/sys/dev/ic/awi.c  Fri Jul 21 16:32:21 2000 +0000
+++ b/sys/dev/ic/awi.c  Fri Jul 21 18:45:44 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: awi.c,v 1.19.2.1 2000/07/14 14:36:59 onoe Exp $        */
+/*     $NetBSD: awi.c,v 1.19.2.2 2000/07/21 18:45:46 onoe Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -460,8 +460,7 @@
        struct ifreq *ifr = (struct ifreq *)data;
        struct ifaddr *ifa = (struct ifaddr *)data;
        int s, error;
-       size_t nwidlen;
-       u_int8_t nwid[IEEE80211_NWID_LEN + 1];
+       struct ieee80211_nwid nwid;
        u_int8_t *p;
 
        s = splnet();
@@ -521,22 +520,22 @@
                        ifp->if_mtu = ifr->ifr_mtu;
                break;
        case SIOCS80211NWID:
-               error = copyinstr(ifr->ifr_data, nwid, sizeof(nwid), &nwidlen);
+               error = copyin(ifr->ifr_data, &nwid, sizeof(nwid));
                if (error)
                        break;
-               nwidlen--;      /* eliminate trailing '\0' */
-               if (nwidlen > IEEE80211_NWID_LEN) {
+               if (nwid.i_len > IEEE80211_NWID_LEN) {
                        error = EINVAL;
                        break;
                }
-               if (sc->sc_mib_mac.aDesired_ESS_ID[1] == nwidlen &&
-                   memcmp(&sc->sc_mib_mac.aDesired_ESS_ID[2], nwid,
-                   nwidlen) == 0)
+               if (sc->sc_mib_mac.aDesired_ESS_ID[1] == nwid.i_len &&
+                   memcmp(&sc->sc_mib_mac.aDesired_ESS_ID[2], nwid.i_nwid,
+                   nwid.i_len) == 0)
                        break;
                memset(sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
                sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
-               sc->sc_mib_mac.aDesired_ESS_ID[1] = nwidlen;
-               memcpy(&sc->sc_mib_mac.aDesired_ESS_ID[2], nwid, nwidlen);
+               sc->sc_mib_mac.aDesired_ESS_ID[1] = nwid.i_len;
+               memcpy(&sc->sc_mib_mac.aDesired_ESS_ID[2], nwid.i_nwid,
+                   nwid.i_len);
                if (sc->sc_enabled) {
                        awi_stop(sc);
                        error = awi_init(sc);
@@ -547,7 +546,7 @@
                        p = sc->sc_bss.essid;
                else
                        p = sc->sc_mib_mac.aDesired_ESS_ID;
-               error = copyout(p + 2, ifr->ifr_data, IEEE80211_NWID_LEN);
+               error = copyout(p + 1, ifr->ifr_data, 1 + IEEE80211_NWID_LEN);
                break;
 #ifdef IFM_IEEE80211
        case SIOCSIFMEDIA:
diff -r bf5bb4dc4074 -r 2b669c4a4faa sys/dev/pcmcia/if_ray.c
--- a/sys/dev/pcmcia/if_ray.c   Fri Jul 21 16:32:21 2000 +0000
+++ b/sys/dev/pcmcia/if_ray.c   Fri Jul 21 18:45:44 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ray.c,v 1.20 2000/05/29 17:37:16 jhawk Exp $        */
+/*     $NetBSD: if_ray.c,v 1.20.2.1 2000/07/21 18:45:46 onoe Exp $     */
 /* 
  * Copyright (c) 2000 Christian E. Hopps
  * All rights reserved.
@@ -179,8 +179,8 @@
        u_int           sc_txfree;      /* a free count for efficiency */
 
        u_int8_t        sc_bssid[ETHER_ADDR_LEN];       /* current net values */
-       u_int8_t        sc_cnwid[IEEE80211_NWID_LEN];   /* last nwid */
-       u_int8_t        sc_dnwid[IEEE80211_NWID_LEN];   /* desired nwid */
+       struct ieee80211_nwid   sc_cnwid;       /* last nwid */
+       struct ieee80211_nwid   sc_dnwid;       /* desired nwid */
        u_int8_t        sc_omode;       /* old operating mode SC_MODE_xx */
        u_int8_t        sc_mode;        /* current operating mode SC_MODE_xx */
        u_int8_t        sc_countrycode; /* current country code */
@@ -578,10 +578,13 @@
        /*
         * set the parameters that will survive stop/init
         */
-       memset(sc->sc_cnwid, 0, sizeof(sc->sc_cnwid));
-       memset(sc->sc_dnwid, 0, sizeof(sc->sc_dnwid));
-       strncpy(sc->sc_dnwid, RAY_DEF_NWID, sizeof(sc->sc_dnwid));
-       strncpy(sc->sc_cnwid, RAY_DEF_NWID, sizeof(sc->sc_dnwid));
+       memset(&sc->sc_dnwid, 0, sizeof(sc->sc_dnwid));
+       sc->sc_dnwid.i_len = strlen(RAY_DEF_NWID);
+       if (sc->sc_dnwid.i_len > IEEE80211_NWID_LEN)
+               sc->sc_dnwid.i_len = IEEE80211_NWID_LEN;
+       if (sc->sc_dnwid.i_len > 0)
+               memcpy(sc->sc_dnwid.i_nwid, RAY_DEF_NWID, sc->sc_dnwid.i_len);
+       memcpy(&sc->sc_cnwid, &sc->sc_dnwid, sizeof(sc->sc_cnwid));
        sc->sc_omode = sc->sc_mode = RAY_MODE_DEFAULT;
        sc->sc_countrycode = sc->sc_dcountrycode =
            RAY_PID_COUNTRY_CODE_DEFAULT;
@@ -958,12 +961,12 @@
        u_long cmd;
        caddr_t data;
 {
-       u_int8_t nwid[IEEE80211_NWID_LEN];
+       struct ieee80211_nwid nwid;
        struct ray_param_req pr;
        struct ray_softc *sc;
        struct ifreq *ifr;
        struct ifaddr *ifa;
-       int error, error2, s;
+       int error, error2, s, i;
 
        sc = ifp->if_softc;
        error = 0;
@@ -1053,24 +1056,31 @@
                error = error2 ? error2 : error;
                break;
        case SIOCS80211NWID:
-               RAY_DPRINTF(("%s: ioctl: cmd SIOCSNWID\n", ifp->if_xname));
+               RAY_DPRINTF(("%s: ioctl: cmd SIOCS80211NWID\n", ifp->if_xname));
                /*
                 * if later people overwrite thats ok -- the latest version
                 * will always get start/joined even if it was set by
                 * a previous command
                 */
-               if ((error = copyin(ifr->ifr_data, nwid, sizeof(nwid))))
+               if ((error = copyin(ifr->ifr_data, &nwid, sizeof(nwid))))
+                       break;
+               if (nwid.i_len > IEEE80211_NWID_LEN) {
+                       error = EINVAL;
                        break;
-               if (!memcmp(sc->sc_dnwid, nwid, sizeof(nwid)))
+               }
+               /* clear trailing garbages */
+               for (i = nwid.i_len; i < IEEE80211_NWID_LEN; i++)
+                       nwid.i_nwid[i] = 0;
+               if (!memcmp(&sc->sc_dnwid, &nwid, sizeof(nwid)))
                        break;
-               memcpy(sc->sc_dnwid, nwid, sizeof(nwid));
+               memcpy(&sc->sc_dnwid, &nwid, sizeof(nwid));
                if (ifp->if_flags & IFF_RUNNING)
                        ray_start_join_net(sc);
                break;
        case SIOCG80211NWID:
-               RAY_DPRINTF(("%s: ioctl: cmd SIOCHNWID\n", ifp->if_xname));
-               error = copyout(sc->sc_cnwid, ifr->ifr_data,
-                   IEEE80211_NWID_LEN);
+               RAY_DPRINTF(("%s: ioctl: cmd SIOCG80211NWID\n", ifp->if_xname));
+               error = copyout(&sc->sc_cnwid, ifr->ifr_data,
+                   sizeof(sc->sc_cnwid));
                break;
 #ifdef RAY_DO_SIGLEV
        case SIOCGRAYSIGLEV:
@@ -1869,7 +1879,7 @@
                sc->sc_if.if_flags &= ~IFF_OACTIVE;
 
                sc->sc_omode = sc->sc_mode;
-               memcpy(sc->sc_cnwid, sc->sc_dnwid, sizeof(sc->sc_cnwid));
+               memcpy(&sc->sc_cnwid, &sc->sc_dnwid, sizeof(sc->sc_cnwid));
 
                rcmd = ray_start_join_net;
                break;
@@ -2435,7 +2445,8 @@
                memset(sp4, 0, sizeof(*sp4));
        else
                memset(sp5, 0, sizeof(*sp5));
-       memcpy(sp->sp_ssid, sc->sc_dnwid, sizeof(sp->sp_ssid));
+       /* XXX: Raylink firmware doesn't have length field for ssid */
+       memcpy(sp->sp_ssid, sc->sc_dnwid.i_nwid, sizeof(sp->sp_ssid));
        sp->sp_scan_mode = 0x1;
        memcpy(sp->sp_mac_addr, sc->sc_ecf_startup.e_station_addr,
            ETHER_ADDR_LEN);
@@ -2629,14 +2640,14 @@
                return;
        sc->sc_startccs = ccs;
        sc->sc_startcmd = cmd;
-       if (!memcmp(sc->sc_cnwid, sc->sc_dnwid, sizeof(sc->sc_cnwid))
+       if (!memcmp(&sc->sc_cnwid, &sc->sc_dnwid, sizeof(sc->sc_cnwid))
            && sc->sc_omode == sc->sc_mode)
                SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_net, c_upd_param, 0);
        else {
                sc->sc_havenet = 0;



Home | Main Index | Thread Index | Old Index