On Tue, Jan 12, 2016 at 01:06:42PM +0100, Stefan Sperling wrote:
> Do not require users to type 'media autoselect mode ...' if all
> they want is to force a particular operating mode.
> 
> This allows 11n support to be disabled by typing short commands like:
> 
>   ifconfig iwn0 mode 11a
>   ifconfig iwn0 mode 11g
>   ifconfig iwn0 mode 11b
> 
> The new -mode command restores the default behaviour (mode autoselect).
> 
> ok?

Slightly improved diff:

Shorten the man page blurb.
Note that 'operating mode' is also used to refer to hostap, ibss,
and monitor mode, at least in the net80211 code. The code calls
11a/b/g/n the 'phy mode'.
In the ethernet world, we have 'media instance' (IFM_INST) for
selecting a PHY. I'm not sure why wireless doesn't use IFM_INST
instead of 'mode' (IFM_MODE), but in any case changing that right
now opens a bigger can of worms. For now, I decided to just use the
word 'mode' in the man page to avoid spreading further confusion.

Use the proper shift for clearing the mode bits in the media word.
This is a no-op since 0 is being shifted but the code is clearer this way.

Index: ifconfig.8
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.264
diff -u -p -r1.264 ifconfig.8
--- ifconfig.8  6 Dec 2015 12:50:05 -0000       1.264
+++ ifconfig.8  12 Jan 2016 12:36:38 -0000
@@ -373,16 +373,21 @@ The routing metric can be used by routin
 Higher metrics have the effect of making a route less favorable.
 .It Cm mode Ar mode
 If the driver for the interface supports the media selection system,
-set the specified operating mode on the interface to the given
+force the mode of the interface to the given
 .Ar mode .
-For IEEE 802.11 wireless interfaces that support multiple operating modes,
+For IEEE 802.11 wireless interfaces that support multiple modes,
 this directive is used to select between 802.11a
 .Pq Dq 11a ,
 802.11b
 .Pq Dq 11b ,
-and 802.11g
-.Pq Dq 11g
-operating modes.
+802.11g
+.Pq Dq 11g,
+and 802.11n
+.Pq Dq 11n
+modes.
+.It Fl mode
+Select the mode automatically.
+This is the default for IEEE 802.11 wireless interfaces.
 .It Cm mpls
 Enable Multiprotocol Label Switching (MPLS) on the interface,
 allowing it to send and receive MPLS traffic.
Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.314
diff -u -p -r1.314 ifconfig.c
--- ifconfig.c  6 Jan 2016 21:37:00 -0000       1.314
+++ ifconfig.c  12 Jan 2016 12:23:53 -0000
@@ -193,6 +193,7 @@ void        unsetkeepalive(const char *, int);
 void   setmedia(const char *, int);
 void   setmediaopt(const char *, int);
 void   setmediamode(const char *, int);
+void   unsetmediamode(const char *, int);
 void   clone_create(const char *, int);
 void   clone_destroy(const char *, int);
 void   unsetmediaopt(const char *, int);
@@ -517,6 +518,7 @@ const struct        cmd {
        { "mediaopt",   NEXTARG,        A_MEDIAOPTSET,  setmediaopt },
        { "-mediaopt",  NEXTARG,        A_MEDIAOPTCLR,  unsetmediaopt },
        { "mode",       NEXTARG,        A_MEDIAMODE,    setmediamode },
+       { "-mode",      0,              A_MEDIAMODE,    unsetmediamode },
        { "instance",   NEXTARG,        A_MEDIAINST,    setmediainst },
        { "inst",       NEXTARG,        A_MEDIAINST,    setmediainst },
        { "lladdr",     NEXTARG,        0,              setiflladdr },
@@ -2367,7 +2369,7 @@ void
 process_media_commands(void)
 {
 
-       if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {
+       if ((actions & (A_MEDIA|A_MEDIAOPT|A_MEDIAMODE)) == 0) {
                /* Nothing to do. */
                return;
        }
@@ -2450,6 +2452,27 @@ setmediamode(const char *val, int d)
        if ((mode = get_media_mode(type, val)) == -1)
                errx(1, "invalid media mode: %s", val);
        media_current = IFM_MAKEWORD(type, subtype, options, inst) | mode;
+       /* Media will be set after other processing is complete. */
+}
+
+void
+unsetmediamode(const char *val, int d)
+{
+       uint64_t type, subtype, options, inst;
+
+       init_current_media();
+
+       /* Can only issue `mode' once. */
+       if (actions & A_MEDIAMODE)
+               errx(1, "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);
+
+       media_current = IFM_MAKEWORD(type, subtype, options, inst) |
+           (IFM_AUTO << IFM_MSHIFT);
        /* Media will be set after other processing is complete. */
 }
 

Reply via email to