Source-Changes-HG archive

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

[src/trunk]: src/sbin/ifconfig Add 'mode' option to change PHY media for 802....



details:   https://anonhg.NetBSD.org/src/rev/90eb37e504d5
branches:  trunk
changeset: 553258:90eb37e504d5
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Mon Oct 13 08:27:35 2003 +0000

description:
Add 'mode' option to change PHY media for 802.11 devices.  Also,
display PHY mode. E.g., run an 802.11a (5GHz, 54Mbps max) access
point:

> ifconfig ath0 nwid my_access_point mode 11a mediaopt hostap
> ifconfig -m ath0
ath0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        nwid my_access_point
        powersave off
        bssid 00:05:5d:84:cc:6e chan 3
        address: 00:05:5d:84:cc:6e
        media: IEEE802.11 autoselect mode 11a hostap
        status: active
        supported IEEE802.11 media:
                media autoselect
                media autoselect mediaopt adhoc
                media autoselect mediaopt hostap
                media autoselect mediaopt monitor
                media autoselect mode 11a
                media autoselect mode 11a mediaopt adhoc
                media autoselect mode 11a mediaopt hostap
                media autoselect mode 11a mediaopt monitor
*snip snip*

diffstat:

 sbin/ifconfig/ifconfig.c |  80 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 73 insertions(+), 7 deletions(-)

diffs (185 lines):

diff -r a9a085b53a18 -r 90eb37e504d5 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Mon Oct 13 08:22:19 2003 +0000
+++ b/sbin/ifconfig/ifconfig.c  Mon Oct 13 08:27:35 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.138 2003/08/07 10:04:24 agc Exp $       */
+/*     $NetBSD: ifconfig.c,v 1.139 2003/10/13 08:27:35 dyoung Exp $    */
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
 #else
-__RCSID("$NetBSD: ifconfig.c,v 1.138 2003/08/07 10:04:24 agc Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.139 2003/10/13 08:27:35 dyoung Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,7 +88,8 @@
 #include <net/if_dl.h>
 #include <net/if_media.h>
 #include <net/if_ether.h>
-#include <net/if_ieee80211.h>
+#include <net80211/ieee80211.h>
+#include <net80211/ieee80211_ioctl.h>
 #include <net/if_vlanvar.h>
 #include <netinet/in.h>
 #include <netinet/in_var.h>
@@ -186,6 +187,7 @@
 #endif
 void   checkatrange __P ((struct sockaddr_at *));
 void   setmedia __P((const char *, int));
+void   setmediamode __P((const char *, int));
 void   setmediaopt __P((const char *, int));
 void   unsetmediaopt __P((const char *, int));
 void   setmediainst __P((const char *, int));
@@ -215,6 +217,7 @@
 #define        A_MEDIAOPTCLR   0x0004          /* -mediaopt command */
 #define        A_MEDIAOPT      (A_MEDIAOPTSET|A_MEDIAOPTCLR)
 #define        A_MEDIAINST     0x0008          /* instance or inst command */
+#define        A_MEDIAMODE     0x0010          /* mode command */
 
 #define        NEXTARG         0xffffff
 #define        NEXTARG2        0xfffffe
@@ -295,6 +298,7 @@
        { "media",      NEXTARG,        A_MEDIA,        setmedia },
        { "mediaopt",   NEXTARG,        A_MEDIAOPTSET,  setmediaopt },
        { "-mediaopt",  NEXTARG,        A_MEDIAOPTCLR,  unsetmediaopt },
+       { "mode",       NEXTARG,        A_MEDIAMODE,    setmediamode },
        { "instance",   NEXTARG,        A_MEDIAINST,    setmediainst },
        { "inst",       NEXTARG,        A_MEDIAINST,    setmediainst },
        { "ip4csum",    IFCAP_CSUM_IPv4,0,              setifcaps },
@@ -330,6 +334,7 @@
 
 const char *get_media_type_string __P((int));
 const char *get_media_subtype_string __P((int));
+int    get_media_mode __P((int, const char *));
 int    get_media_subtype __P((int, const char *));
 int    get_media_options __P((int, const char *));
 int    lookup_media_word __P((struct ifmedia_description *, int,
@@ -1425,7 +1430,7 @@
        const char *val;
        int d;
 {
-       struct ieee80211_channel channel;
+       struct ieee80211chanreq channel;
        int chan;
 
        if (d != 0)
@@ -1550,7 +1555,7 @@
        struct ieee80211_power power;
        u_int8_t keybuf[IEEE80211_WEP_NKID][16];
        struct ieee80211_bssid bssid;
-       struct ieee80211_channel channel;
+       struct ieee80211chanreq channel;
        struct ether_addr ea;
        static const u_int8_t zero_macaddr[IEEE80211_ADDR_LEN];
 
@@ -1662,7 +1667,7 @@
         * If we have not yet done so, grab the currently-selected
         * media.
         */
-       if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {
+       if ((actions & (A_MEDIA|A_MEDIAOPT|A_MEDIAMODE)) == 0) {
                (void) memset(&ifmr, 0, sizeof(ifmr));
                (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
 
@@ -1687,7 +1692,7 @@
 process_media_commands()
 {
 
-       if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {
+       if ((actions & (A_MEDIA|A_MEDIAOPT|A_MEDIAMODE)) == 0) {
                /* Nothing to do. */
                return;
        }
@@ -1719,6 +1724,11 @@
        if (actions & A_MEDIA)
                errx(EXIT_FAILURE, "only one `media' command may be issued");
 
+       /* Must not come after mode commands */
+       if (actions & A_MEDIAMODE)
+               errx(EXIT_FAILURE,
+                   "may not issue `media' after `mode' commands");
+
        /* Must not come after mediaopt commands */
        if (actions & A_MEDIAOPT)
                errx(EXIT_FAILURE,
@@ -1820,6 +1830,35 @@
        /* Media will be set after other processing is complete. */
 }
 
+void
+setmediamode(val, d)
+       const char *val;
+       int d;
+{
+       int type, subtype, options, inst, mode;
+
+       init_current_media();
+
+       /* Can only issue `mode' once. */
+       if (actions & A_MEDIAMODE)
+               errx(EXIT_FAILURE, "only one `mode' command may be issued");
+
+       type = IFM_TYPE(media_current);
+       subtype = IFM_SUBTYPE(media_current);
+       options = IFM_OPTIONS(media_current);
+       inst = IFM_INST(media_current);
+
+       if ((mode = get_media_mode(type, val)) == -1)
+               errx(EXIT_FAILURE, "invalid media mode: %s", val);
+
+       media_current = IFM_MAKEWORD(type, subtype, options, inst) | mode;
+
+       /* Media will be set after other processing is complete. */
+}
+
+struct ifmedia_description ifm_mode_descriptions[] =
+    IFM_MODE_DESCRIPTIONS;
+
 struct ifmedia_description ifm_type_descriptions[] =
     IFM_TYPE_DESCRIPTIONS;
 
@@ -1859,6 +1898,21 @@
 }
 
 int
+get_media_mode(type, val)
+       int type;
+       const char *val;
+{
+       int rval;
+
+       rval = lookup_media_word(ifm_mode_descriptions, type, val);
+       if (rval == -1)
+               errx(EXIT_FAILURE, "unknown %s media mode: %s",
+                   get_media_type_string(type), val);
+
+       return (rval);
+}
+
+int
 get_media_subtype(type, val)
        int type;
        const char *val;
@@ -1929,6 +1983,18 @@
        printf("%s%s", as_syntax ? "media " : "",
            get_media_subtype_string(ifmw));
 
+       /* Find mode. */
+       if (IFM_MODE(ifmw) != 0) {
+               for (desc = ifm_mode_descriptions; desc->ifmt_string != NULL;
+                    desc++) {
+                       if (IFM_TYPE_MATCH(desc->ifmt_word, ifmw) &&
+                           IFM_MODE(ifmw) == IFM_MODE(desc->ifmt_word)) {
+                               printf(" mode %s", desc->ifmt_string);
+                               break;
+                       }
+               }
+       }
+
        /* Find options. */
        for (desc = ifm_option_descriptions; desc->ifmt_string != NULL;
             desc++) {



Home | Main Index | Thread Index | Old Index