Source-Changes-HG archive

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

[src/trunk]: src change the argument of SIOCS80211NWID and SIOCG80211NWID ioc...



details:   https://anonhg.NetBSD.org/src/rev/1096e7f8bc80
branches:  trunk
changeset: 494281:1096e7f8bc80
user:      onoe <onoe%NetBSD.org@localhost>
date:      Wed Jul 05 02:35:53 2000 +0000

description:
change the argument of SIOCS80211NWID and SIOCG80211NWID ioctls from
u_int8_t array to struct ieee80211_nwid to prepend length field.
The length field is necessary because IEEE 802.11 spec doesn't prohibit
even '\0' for SSID.
Though the name and the value of SIOC... macro is unchanged, this change
breaks binary compatibility.  The only affected userland program on the
tree is ifconfig(8).
As Jason suggested on tech-net, it is better than live with problems
since there are no releases for this ioctls yet.

diffstat:

 sbin/ifconfig/ifconfig.c  |  54 ++++++++++++++++++++++++++++++-------
 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 ++++-
 6 files changed, 138 insertions(+), 98 deletions(-)

diffs (truncated from 528 to 300 lines):

diff -r 560cb679d786 -r 1096e7f8bc80 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Wed Jul 05 02:30:18 2000 +0000
+++ b/sbin/ifconfig/ifconfig.c  Wed Jul 05 02:35:53 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.81 2000/07/02 00:28:01 thorpej Exp $    */
+/*     $NetBSD: ifconfig.c,v 1.82 2000/07/05 02:35:55 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.81 2000/07/02 00:28:01 thorpej Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.82 2000/07/05 02:35:55 onoe Exp $");
 #endif
 #endif /* not lint */
 
@@ -1094,12 +1094,31 @@
        const char *val;
        int d;
 {
-       u_int8_t nwid[IEEE80211_NWID_LEN];
+       struct ieee80211_nwid nwid;
+       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(val[0]) && isxdigit(val[1])) {
+#define        tohex(x)        (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
+                       *p++ = (tohex(val[0]) << 4) | tohex(val[1]);
+#undef tohex
+                       val += 2;
+               }
+               if (*val != '\0') {
+                       errno = EINVAL;
+                       warn("SIOCS80211NWID");
+                       return;
+               }
+               nwid.i_len = p - nwid.i_nwid;
+       } else {
+               nwid.i_len = strlen(val);
+               memcpy(nwid.i_nwid, val, nwid.i_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");
 }
@@ -1107,14 +1126,29 @@
 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;
+       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 560cb679d786 -r 1096e7f8bc80 sys/dev/ic/awi.c
--- a/sys/dev/ic/awi.c  Wed Jul 05 02:30:18 2000 +0000
+++ b/sys/dev/ic/awi.c  Wed Jul 05 02:35:53 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: awi.c,v 1.20 2000/07/04 14:27:57 onoe Exp $    */
+/*     $NetBSD: awi.c,v 1.21 2000/07/05 02:35:54 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 560cb679d786 -r 1096e7f8bc80 sys/dev/pcmcia/if_ray.c
--- a/sys/dev/pcmcia/if_ray.c   Wed Jul 05 02:30:18 2000 +0000
+++ b/sys/dev/pcmcia/if_ray.c   Wed Jul 05 02:35:53 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.21 2000/07/05 02:35:54 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;
                memset(&np, 0, sizeof(np));
                np.p_net_type = sc->sc_mode;
-               memcpy(np.p_ssid, sc->sc_dnwid, sizeof(np.p_ssid));
+               memcpy(np.p_ssid, sc->sc_dnwid.i_nwid, sizeof(np.p_ssid));
                ray_write_region(sc, RAY_HOST_TO_ECF_BASE, &np, sizeof(np));
                SRAM_WRITE_FIELD_1(sc, ccs, ray_cmd_net, c_upd_param, 1);
        }
@@ -2672,6 +2683,7 @@
        bus_size_t ccs;
        u_int stat;
 {
+       int i;
        struct ray_net_params np;
 
        callout_stop(&sc->sc_start_join_timo_ch);
@@ -2692,13 +2704,14 @@
                        return (0);
 
                /* see if our nwid is up to date */
-               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 {
                        memset(&np, 0, sizeof(np));
                        np.p_net_type = sc->sc_mode;
-                       memcpy(np.p_ssid, sc->sc_dnwid, sizeof(np.p_ssid));
+                       memcpy(np.p_ssid, sc->sc_dnwid.i_nwid,
+                           sizeof(np.p_ssid));
                        ray_write_region(sc, RAY_HOST_TO_ECF_BASE, &np,
                            sizeof(np));
                        SRAM_WRITE_FIELD_1(sc,ccs, ray_cmd_net, c_upd_param, 1);



Home | Main Index | Thread Index | Old Index