Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/wiconfig Pull up rev. 1.7 and 1.8 (approved by...



details:   https://anonhg.NetBSD.org/src/rev/548f370b2921
branches:  netbsd-1-5
changeset: 488942:548f370b2921
user:      enami <enami%NetBSD.org@localhost>
date:      Mon Aug 07 01:11:28 2000 +0000

description:
Pull up rev. 1.7 and 1.8 (approved by jhawk):
----------------------------
revision 1.8
date: 2000/08/07 00:55:08;  author: enami;  state: Exp;  lines: +4 -2
Add our RCS Id and restore original Id.
----------------------------
revision 1.7
date: 2000/07/06 03:37:26;  author: enami;  state: Exp;  lines: +179 -163
- Process all passed option rather than ignoring silently except the first one.
- Centerize the check whether an interface is specified.
- Print maximum data length.
- Swap wi_type and wi_code in struct wi_table so that wi_type matches with
  wi_type in wi_req.

diffstat:

 usr.sbin/wiconfig/wiconfig.c |  344 ++++++++++++++++++++++--------------------
 1 files changed, 181 insertions(+), 163 deletions(-)

diffs (truncated from 503 to 300 lines):

diff -r 41c3ed4948b1 -r 548f370b2921 usr.sbin/wiconfig/wiconfig.c
--- a/usr.sbin/wiconfig/wiconfig.c      Mon Aug 07 01:11:19 2000 +0000
+++ b/usr.sbin/wiconfig/wiconfig.c      Mon Aug 07 01:11:28 2000 +0000
@@ -1,3 +1,5 @@
+/*     $NetBSD: wiconfig.c,v 1.5.4.2 2000/08/07 01:11:28 enami Exp $   */
+
 /*
  * Copyright (c) 1997, 1998, 1999
  *     Bill Paul <wpaul%ctr.columbia.edu@localhost>.  All rights reserved.
@@ -29,7 +31,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: wiconfig.c,v 1.5.4.1 2000/06/26 01:26:16 sommerfeld Exp $
+ *     From: Id: wicontrol.c,v 1.6 1999/05/22 16:12:49 wpaul Exp $
  */
 
 #include <sys/types.h>
@@ -67,9 +69,24 @@
 static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\
        Bill Paul. All rights reserved.";
 static const char rcsid[] =
-       "@(#) $Id: wiconfig.c,v 1.5.4.1 2000/06/26 01:26:16 sommerfeld Exp $";
+       "@(#) $Id: wiconfig.c,v 1.5.4.2 2000/08/07 01:11:28 enami Exp $";
 #endif
 
+struct wi_table {
+       int wi_type;
+       int wi_code;
+#define        WI_NONE                 0x00
+#define        WI_STRING               0x01
+#define        WI_BOOL                 0x02
+#define        WI_WORDS                0x03
+#define        WI_HEXBYTES             0x04
+#define        WI_KEYSTRUCT            0x05
+       char *wi_label;                 /* label used to print info */
+       int wi_opt;                     /* option character to set this */
+       char *wi_desc;
+       char *wi_optval;
+};
+
 static void wi_getval          __P((char *, struct wi_req *));
 static void wi_setval          __P((char *, struct wi_req *));
 static void wi_printstr                __P((struct wi_req *));
@@ -84,7 +101,9 @@
 static void wi_setkeys         __P((char *, char *, int));
 static void wi_printkeys       __P((struct wi_req *));
 static void wi_dumpstats       __P((char *));
-static void usage              __P((char *));
+static void usage              __P((void));
+static struct wi_table *
+       wi_optlookup __P((struct wi_table *, int));
 static int  wi_hex2int(char c);
 static void wi_str2key         __P((char *, struct wi_key *));
 int main __P((int argc, char **argv));
@@ -96,9 +115,6 @@
        struct ifreq            ifr;
        int                     s;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&ifr, sizeof(ifr));
 
        strcpy(ifr.ifr_name, iface);
@@ -175,12 +191,6 @@
 {
        struct wi_req           wreq;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
-       if (str == NULL)
-               errx(1, "must specify string");
-
        bzero((char *)&wreq, sizeof(wreq));
 
        if (strlen(str) > 30)
@@ -204,9 +214,6 @@
 {
        struct wi_req           wreq;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&wreq, sizeof(wreq));
 
        wreq.wi_type = code;
@@ -225,9 +232,6 @@
 {
        struct wi_req           wreq;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&wreq, sizeof(wreq));
 
        wreq.wi_type = code;
@@ -246,13 +250,7 @@
 {
        struct ether_addr       *addr;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-       if (str == NULL)
-               errx(1, "must specify address");
-
        addr = ether_aton(str);
-
        if (addr == NULL)
                errx(1, "badly formatted address");
 
@@ -309,9 +307,6 @@
         struct wi_ltv_keys      *keys;
         struct wi_key           *k;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
         bzero((char *)&wreq, sizeof(wreq));
         wreq.wi_len = WI_MAX_DATALEN;
         wreq.wi_type = WI_RID_WEP_AVAIL;
@@ -427,49 +422,71 @@
        return;
 }
 
-#define WI_STRING              0x01
-#define WI_BOOL                        0x02
-#define WI_WORDS               0x03
-#define WI_HEXBYTES            0x04
-#define WI_KEYSTRUCT            0x05
-
-struct wi_table {
-       int                     wi_code;
-       int                     wi_type;
-       char                    *wi_str;
-};
-
 static struct wi_table wi_table[] = {
        { WI_RID_SERIALNO, WI_STRING, "NIC serial number:\t\t\t" },
-       { WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t" },
-       { WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t" },
+       { WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t",
+           's', "station name" },
+       { WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t",
+           'q', "own SSID" },
        { WI_RID_CURRENT_SSID, WI_STRING, "Current netname (SSID):\t\t\t" },
-       { WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t" },
+       { WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t",
+           'n', "network name" },
        { WI_RID_CURRENT_BSSID, WI_HEXBYTES, "Current BSSID:\t\t\t\t" },
        { WI_RID_CHANNEL_LIST, WI_WORDS, "Channel list:\t\t\t\t" },
-       { WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t" },
+       { WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t",
+           'f', "frequency" },
        { WI_RID_CURRENT_CHAN, WI_WORDS, "Current channel:\t\t\t" },
        { WI_RID_COMMS_QUALITY, WI_WORDS, "Comms quality/signal/noise:\t\t" },
        { WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" },
-       { WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"},
-       { WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"},
-       { WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t"},
+       { WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t",
+           'p', "port type" },
+       { WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t",
+           'm', "MAC address" },
+       { WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t",
+           't', "TX rate" },
        { WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"},
-       { WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"},
-       { WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" },
-       { WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" },
-       { WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t" },
-       { WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t" },
-       { 0, NULL }
+       { WI_RID_MAX_DATALEN, WI_WORDS, "Maximum data length:\t\t\t",
+           'd', "maximum data length" },
+       { WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t",
+           'r', "RTS threshold" },
+       { WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t",
+           'c', "create ibss" },
+       { WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t",
+           'a', "system scale" },
+       { WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t",
+           'P', "power management enabled" },
+       { WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t",
+           'S', "max sleep duration" },
+       { 0, WI_NONE }
 };
 
 static struct wi_table wi_crypt_table[] = {
-        { WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t" },
+       { WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t",
+           'e', "encryption" },
         { WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" },
         { WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" },
-        { 0, NULL }
+       { 0, WI_NONE }
+};
+
+static struct wi_table *wi_tables[] = {
+       wi_table,
+       wi_crypt_table,
+       NULL
 };
 
+static struct wi_table *
+wi_optlookup(table, opt)
+       struct wi_table *table;
+       int opt;
+{
+       struct wi_table *wt;
+
+       for (wt = table; wt->wi_type != 0; wt++)
+               if (wt->wi_opt == opt)
+                       return (wt);
+       return (NULL);
+}
+
 static void wi_dumpinfo(iface)
        char                    *iface;
 {
@@ -487,15 +504,15 @@
 
        w = wi_table;
 
-       for (i = 0; w[i].wi_type; i++) {
+       for (i = 0; w[i].wi_code != WI_NONE; i++) {
                bzero((char *)&wreq, sizeof(wreq));
 
                wreq.wi_len = WI_MAX_DATALEN;
-               wreq.wi_type = w[i].wi_code;
+               wreq.wi_type = w[i].wi_type;
 
                wi_getval(iface, &wreq);
-               printf("%s", w[i].wi_str);
-               switch (w[i].wi_type) {
+               printf("%s", w[i].wi_label);
+               switch (w[i].wi_code) {
                case WI_STRING:
                        wi_printstr(&wreq);
                        break;
@@ -516,15 +533,15 @@
 
        if (has_wep) {
                w = wi_crypt_table;
-               for (i = 0; w[i].wi_type; i++) {
+               for (i = 0; w[i].wi_code != WI_NONE; i++) {
                        bzero((char *)&wreq, sizeof(wreq));
 
                        wreq.wi_len = WI_MAX_DATALEN;
-                       wreq.wi_type = w[i].wi_code;
+                       wreq.wi_type = w[i].wi_type;
 
                        wi_getval(iface, &wreq);
-                       printf("%s", w[i].wi_str);
-                       switch (w[i].wi_type) {
+                       printf("%s", w[i].wi_label);
+                       switch (w[i].wi_code) {
                        case WI_STRING:
                                wi_printstr(&wreq);
                                break;
@@ -558,9 +575,6 @@
        struct wi_req           wreq;
        struct wi_counters      *c;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&wreq, sizeof(wreq));
        wreq.wi_len = WI_MAX_DATALEN;
        wreq.wi_type = WI_RID_IFACE_STATS;
@@ -613,16 +627,19 @@
        return;
 }
 
-static void usage(p)
-       char                    *p;
+static void
+usage()
 {
+       extern char *__progname;
+
        fprintf(stderr,
-           "usage: wiconfig interface "
+           "usage: %s interface "
            "[-o] [-t tx rate] [-n network name] [-s station name]\n"
            "       [-e 0|1] [-k key [-v 1|2|3|4]] [-T 1|2|3|4]\n"
            "       [-c 0|1] [-q SSID] [-p port type] [-a access point density]\n"
            "       [-m MAC address] [-d max data length] [-r RTS threshold]\n"
-           "       [-f frequency] [-P 0|1] [-S max sleep duration]\n");
+           "       [-f frequency] [-P 0|1] [-S max sleep duration]\n",
+           __progname);
        exit(1);
 }
 
@@ -630,11 +647,22 @@
        int                     argc;
        char                    *argv[];
 {
-       int                     ch;



Home | Main Index | Thread Index | Old Index