On Wed, Aug 31, 2016 at 05:04:38PM +0200, Stefan Sperling wrote:
> This makes ifconfig display baudrates defined in ifmedia.h tables.
>
> Before (prints media subtype):
>
> $ ifconfig iwn0 | grep media:
> media: IEEE802.11 autoselect (OFDM6 mode 11a)
> $ ifconfig em0 | grep media:
> media: Ethernet autoselect (100baseTX full-duplex,rxpause,txpause)
>
> After (prints corresponding baudrate):
>
> $ ifconfig iwn0 | grep media:
> media: IEEE802.11 autoselect (6Mbps mode 11a)
> $ ifconfig em0 | grep media:
> media: Ethernet autoselect (100Mbps full-duplex,rxpause,txpause)
>
> The output of 'ifconfig media' (which prints command syntax) is unchanged
> and we fall back to printing the media subtype if no baudrate is found.
>
> I've kept this disabled in the ramdisk for now.
> The baudrate table will grow when more 11n features are implemented.
>
I find it much more useful to have the actual speed ("baudrate")
displayed instead of the mode or rate name - especially with these
non-obvious MCS rates from 11n.
OK reyk@
> Index: ifconfig.c
> ===================================================================
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.328
> diff -u -p -r1.328 ifconfig.c
> --- ifconfig.c 31 Aug 2016 13:32:27 -0000 1.328
> +++ ifconfig.c 31 Aug 2016 14:51:36 -0000
> @@ -2715,6 +2715,11 @@ const struct ifmedia_description ifm_typ
> const struct ifmedia_description ifm_subtype_descriptions[] =
> IFM_SUBTYPE_DESCRIPTIONS;
>
> +#ifndef SMALL
> +const struct ifmedia_baudrate ifm_baudrate_descriptions[] =
> + IFM_BAUDRATE_DESCRIPTIONS;
> +#endif
> +
> struct ifmedia_description ifm_mode_descriptions[] =
> IFM_MODE_DESCRIPTIONS;
>
> @@ -2748,6 +2753,39 @@ get_media_subtype_string(uint64_t mword)
> return ("<unknown subtype>");
> }
>
> +#ifndef SMALL
> +char *
> +get_media_baudrate_string(uint64_t mword)
> +{
> + const struct ifmedia_baudrate *ifmb;
> + char *str;
> + int ret = -1;
> +
> + for (ifmb = ifm_baudrate_descriptions; ifmb->ifmb_word != 0; ifmb++) {
> + if (!IFM_TYPE_MATCH(ifmb->ifmb_word, mword) ||
> + IFM_SUBTYPE(ifmb->ifmb_word) != IFM_SUBTYPE(mword))
> + continue;
> +
> + if (ifmb->ifmb_baudrate >= IF_Gbps(1))
> + ret = asprintf(&str,
> + "%lluGbps", ifmb->ifmb_baudrate / IF_Gbps(1));
> + else if (ifmb->ifmb_baudrate >= IF_Mbps(1))
> + ret = asprintf(&str,
> + "%lluMbps", ifmb->ifmb_baudrate / IF_Mbps(1));
> + else if (ifmb->ifmb_baudrate >= IF_Kbps(1))
> + ret = asprintf(&str,
> + "%lluKbps", ifmb->ifmb_baudrate / IF_Kbps(1));
> + else
> + ret = asprintf(&str, "%llubps", ifmb->ifmb_baudrate);
> +
> + break;
> + }
> + if (ret == -1)
> + str = NULL;
> + return str;
> +}
> +#endif
> +
> uint64_t
> get_media_subtype(uint64_t type, const char *val)
> {
> @@ -2818,11 +2856,18 @@ print_media_word(uint64_t ifmw, int prin
> {
> const struct ifmedia_description *desc;
> uint64_t seen_option = 0;
> + char *baudrate = NULL;
> +
> +#ifndef SMALL
> + baudrate = as_syntax ? NULL : get_media_baudrate_string(ifmw);
> +#endif
>
> if (print_type)
> printf("%s ", get_media_type_string(ifmw));
> printf("%s%s", as_syntax ? "media " : "",
> - get_media_subtype_string(ifmw));
> + baudrate ? baudrate : get_media_subtype_string(ifmw));
> +
> + free(baudrate);
>
> /* Find mode. */
> if (IFM_MODE(ifmw) != 0) {
>
--