Home | History | Annotate | Line # | Download | only in ifconfig
media.c revision 1.2
      1  1.1  dyoung #include <sys/cdefs.h>
      2  1.1  dyoung #ifndef lint
      3  1.2  dyoung __RCSID("$NetBSD: media.c,v 1.2 2008/07/15 20:56:13 dyoung Exp $");
      4  1.1  dyoung #endif /* not lint */
      5  1.1  dyoung 
      6  1.1  dyoung #include <assert.h>
      7  1.1  dyoung #include <err.h>
      8  1.1  dyoung #include <errno.h>
      9  1.1  dyoung #include <stdio.h>
     10  1.1  dyoung #include <stdlib.h>
     11  1.1  dyoung #include <string.h>
     12  1.1  dyoung #include <util.h>
     13  1.1  dyoung 
     14  1.1  dyoung #include <sys/ioctl.h>
     15  1.1  dyoung 
     16  1.1  dyoung #include <net/if.h>
     17  1.1  dyoung #include <net/if_dl.h>
     18  1.1  dyoung #include <net/if_media.h>
     19  1.1  dyoung 
     20  1.1  dyoung #include <prop/proplib.h>
     21  1.1  dyoung 
     22  1.1  dyoung #include "env.h"
     23  1.1  dyoung #include "extern.h"
     24  1.1  dyoung #include "media.h"
     25  1.1  dyoung #include "parse.h"
     26  1.1  dyoung #include "util.h"
     27  1.1  dyoung 
     28  1.1  dyoung static void init_current_media(prop_dictionary_t, prop_dictionary_t);
     29  1.1  dyoung static void media_constructor(void) __attribute__((constructor));
     30  1.1  dyoung static int setmedia(prop_dictionary_t, prop_dictionary_t);
     31  1.1  dyoung static int setmediainst(prop_dictionary_t, prop_dictionary_t);
     32  1.1  dyoung static int setmediamode(prop_dictionary_t, prop_dictionary_t);
     33  1.1  dyoung static int setmediaopt(prop_dictionary_t, prop_dictionary_t);
     34  1.1  dyoung static int unsetmediaopt(prop_dictionary_t, prop_dictionary_t);
     35  1.1  dyoung 
     36  1.1  dyoung /*
     37  1.1  dyoung  * Media stuff.  Whenever a media command is first performed, the
     38  1.1  dyoung  * currently select media is grabbed for this interface.  If `media'
     39  1.1  dyoung  * is given, the current media word is modifed.  `mediaopt' commands
     40  1.1  dyoung  * only modify the set and clear words.  They then operate on the
     41  1.1  dyoung  * current media word later.
     42  1.1  dyoung  */
     43  1.1  dyoung static int	media_current;
     44  1.1  dyoung static int	mediaopt_set;
     45  1.1  dyoung static int	mediaopt_clear;
     46  1.1  dyoung 
     47  1.2  dyoung static struct usage_func usage;
     48  1.2  dyoung 
     49  1.1  dyoung static const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
     50  1.1  dyoung 
     51  1.1  dyoung static const struct ifmedia_status_description ifm_status_descriptions[] =
     52  1.1  dyoung     IFM_STATUS_DESCRIPTIONS;
     53  1.1  dyoung 
     54  1.1  dyoung static struct pstr mediamode = PSTR_INITIALIZER(&mediamode, "mediamode",
     55  1.1  dyoung     setmediamode, "mediamode", &command_root.pb_parser);
     56  1.1  dyoung 
     57  1.1  dyoung static struct pinteger mediainst = PINTEGER_INITIALIZER1(&mediainst,
     58  1.1  dyoung     "mediainst", 0, IFM_INST_MAX, 10, setmediainst, "mediainst",
     59  1.1  dyoung     &command_root.pb_parser);
     60  1.1  dyoung 
     61  1.1  dyoung static struct pstr unmediaopt = PSTR_INITIALIZER(&unmediaopt, "-mediaopt",
     62  1.1  dyoung     unsetmediaopt, "unmediaopt", &command_root.pb_parser);
     63  1.1  dyoung 
     64  1.1  dyoung static struct pstr mediaopt = PSTR_INITIALIZER(&mediaopt, "mediaopt",
     65  1.1  dyoung     setmediaopt, "mediaopt", &command_root.pb_parser);
     66  1.1  dyoung 
     67  1.1  dyoung static struct pstr media = PSTR_INITIALIZER(&media, "media", setmedia, "media",
     68  1.1  dyoung     &command_root.pb_parser);
     69  1.1  dyoung 
     70  1.1  dyoung static const struct kwinst mediakw[] = {
     71  1.1  dyoung 	  {.k_word = "instance", .k_key = "anymedia", .k_type = KW_T_BOOL,
     72  1.1  dyoung 	   .k_bool = true, .k_act = "media", .k_deact = "mediainst",
     73  1.1  dyoung 	   .k_nextparser = &mediainst.pi_parser}
     74  1.1  dyoung 	, {.k_word = "inst", .k_key = "anymedia", .k_type = KW_T_BOOL,
     75  1.1  dyoung 	   .k_bool = true, .k_act = "media", .k_deact = "mediainst",
     76  1.1  dyoung 	   .k_nextparser = &mediainst.pi_parser}
     77  1.1  dyoung 	, {.k_word = "media", .k_key = "anymedia", .k_type = KW_T_BOOL,
     78  1.1  dyoung 	   .k_bool = true, .k_deact = "media", .k_altdeact = "anymedia",
     79  1.1  dyoung 	   .k_nextparser = &media.ps_parser}
     80  1.1  dyoung 	, {.k_word = "mediaopt", .k_key = "anymedia", .k_type = KW_T_BOOL,
     81  1.1  dyoung 	   .k_bool = true, .k_deact = "mediaopt", .k_altdeact = "instance",
     82  1.1  dyoung 	   .k_nextparser = &mediaopt.ps_parser}
     83  1.1  dyoung 	, {.k_word = "-mediaopt", .k_key = "anymedia", .k_type = KW_T_BOOL,
     84  1.1  dyoung 	   .k_bool = true, .k_deact = "unmediaopt", .k_altdeact = "media",
     85  1.1  dyoung 	   .k_nextparser = &unmediaopt.ps_parser}
     86  1.1  dyoung 	, {.k_word = "mode", .k_key = "anymedia", .k_type = KW_T_BOOL,
     87  1.1  dyoung 	   .k_bool = true, .k_deact = "mode",
     88  1.1  dyoung 	   .k_nextparser = &mediamode.ps_parser}
     89  1.1  dyoung };
     90  1.1  dyoung 
     91  1.1  dyoung struct pkw kwmedia = PKW_INITIALIZER(&kwmedia, "media keywords", NULL, NULL,
     92  1.1  dyoung     mediakw, __arraycount(mediakw), NULL);
     93  1.1  dyoung 
     94  1.1  dyoung static void
     95  1.1  dyoung media_error(int type, const char *val, const char *opt)
     96  1.1  dyoung {
     97  1.1  dyoung 	errx(EXIT_FAILURE, "unknown %s media %s: %s",
     98  1.1  dyoung 		get_media_type_string(type), opt, val);
     99  1.1  dyoung }
    100  1.1  dyoung 
    101  1.1  dyoung void
    102  1.1  dyoung init_current_media(prop_dictionary_t env, prop_dictionary_t oenv)
    103  1.1  dyoung {
    104  1.1  dyoung 	const char *ifname;
    105  1.1  dyoung 	struct ifmediareq ifmr;
    106  1.1  dyoung 
    107  1.1  dyoung 	if ((ifname = getifname(env)) == NULL)
    108  1.1  dyoung 		err(EXIT_FAILURE, "getifname");
    109  1.1  dyoung 
    110  1.1  dyoung 	/*
    111  1.1  dyoung 	 * If we have not yet done so, grab the currently-selected
    112  1.1  dyoung 	 * media.
    113  1.1  dyoung 	 */
    114  1.1  dyoung 
    115  1.1  dyoung 	if (prop_dictionary_get(env, "initmedia") == NULL) {
    116  1.1  dyoung 		memset(&ifmr, 0, sizeof(ifmr));
    117  1.1  dyoung 
    118  1.1  dyoung 		if (direct_ioctl(env, SIOCGIFMEDIA, &ifmr) == -1) {
    119  1.1  dyoung 			/*
    120  1.1  dyoung 			 * If we get E2BIG, the kernel is telling us
    121  1.1  dyoung 			 * that there are more, so we can ignore it.
    122  1.1  dyoung 			 */
    123  1.1  dyoung 			if (errno != E2BIG)
    124  1.1  dyoung 				err(EXIT_FAILURE, "SIOCGIFMEDIA");
    125  1.1  dyoung 		}
    126  1.1  dyoung 
    127  1.1  dyoung 		if (!prop_dictionary_set_bool(oenv, "initmedia", true)) {
    128  1.1  dyoung 			err(EXIT_FAILURE, "%s: prop_dictionary_set_bool",
    129  1.1  dyoung 			    __func__);
    130  1.1  dyoung 		}
    131  1.1  dyoung 		media_current = ifmr.ifm_current;
    132  1.1  dyoung 	}
    133  1.1  dyoung 
    134  1.1  dyoung 	/* Sanity. */
    135  1.1  dyoung 	if (IFM_TYPE(media_current) == 0)
    136  1.1  dyoung 		errx(EXIT_FAILURE, "%s: no link type?", ifname);
    137  1.1  dyoung }
    138  1.1  dyoung 
    139  1.1  dyoung void
    140  1.1  dyoung process_media_commands(prop_dictionary_t env)
    141  1.1  dyoung {
    142  1.1  dyoung 	struct ifreq ifr;
    143  1.1  dyoung 
    144  1.1  dyoung 	if (prop_dictionary_get(env, "media") == NULL &&
    145  1.1  dyoung 	    prop_dictionary_get(env, "mediaopt") == NULL &&
    146  1.1  dyoung 	    prop_dictionary_get(env, "unmediaopt") == NULL &&
    147  1.1  dyoung 	    prop_dictionary_get(env, "mediamode") == NULL) {
    148  1.1  dyoung 		/* Nothing to do. */
    149  1.1  dyoung 		return;
    150  1.1  dyoung 	}
    151  1.1  dyoung 
    152  1.1  dyoung 	/*
    153  1.1  dyoung 	 * Media already set up, and commands sanity-checked.  Set/clear
    154  1.1  dyoung 	 * any options, and we're ready to go.
    155  1.1  dyoung 	 */
    156  1.1  dyoung 	media_current |= mediaopt_set;
    157  1.1  dyoung 	media_current &= ~mediaopt_clear;
    158  1.1  dyoung 
    159  1.1  dyoung 	memset(&ifr, 0, sizeof(ifr));
    160  1.1  dyoung 	ifr.ifr_media = media_current;
    161  1.1  dyoung 
    162  1.1  dyoung 	if (direct_ioctl(env, SIOCSIFMEDIA, &ifr) == -1)
    163  1.1  dyoung 		err(EXIT_FAILURE, "SIOCSIFMEDIA");
    164  1.1  dyoung }
    165  1.1  dyoung 
    166  1.1  dyoung static int
    167  1.1  dyoung setmedia(prop_dictionary_t env, prop_dictionary_t xenv)
    168  1.1  dyoung {
    169  1.1  dyoung 	int type, subtype, inst;
    170  1.1  dyoung 	prop_data_t data;
    171  1.1  dyoung 	char *val;
    172  1.1  dyoung 
    173  1.1  dyoung 	init_current_media(env, xenv);
    174  1.1  dyoung 
    175  1.1  dyoung 	data = (prop_data_t)prop_dictionary_get(env, "media");
    176  1.1  dyoung 	assert(data != NULL);
    177  1.1  dyoung 
    178  1.1  dyoung 	/* Only one media command may be given. */
    179  1.1  dyoung 	/* Must not come after mode commands */
    180  1.1  dyoung 	/* Must not come after mediaopt commands */
    181  1.1  dyoung 
    182  1.1  dyoung 	/*
    183  1.1  dyoung 	 * No need to check if `instance' has been issued; setmediainst()
    184  1.1  dyoung 	 * craps out if `media' has not been specified.
    185  1.1  dyoung 	 */
    186  1.1  dyoung 
    187  1.1  dyoung 	type = IFM_TYPE(media_current);
    188  1.1  dyoung 	inst = IFM_INST(media_current);
    189  1.1  dyoung 
    190  1.1  dyoung 	val = strndup(prop_data_data_nocopy(data), prop_data_size(data));
    191  1.1  dyoung 	if (val == NULL)
    192  1.1  dyoung 		return -1;
    193  1.1  dyoung 
    194  1.1  dyoung 	/* Look up the subtype. */
    195  1.1  dyoung 	subtype = get_media_subtype(type, val);
    196  1.1  dyoung 	if (subtype == -1)
    197  1.1  dyoung 		media_error(type, val, "subtype");
    198  1.1  dyoung 
    199  1.1  dyoung 	/* Build the new current media word. */
    200  1.1  dyoung 	media_current = IFM_MAKEWORD(type, subtype, 0, inst);
    201  1.1  dyoung 
    202  1.1  dyoung 	/* Media will be set after other processing is complete. */
    203  1.1  dyoung 	return 0;
    204  1.1  dyoung }
    205  1.1  dyoung 
    206  1.1  dyoung static int
    207  1.1  dyoung setmediaopt(prop_dictionary_t env, prop_dictionary_t xenv)
    208  1.1  dyoung {
    209  1.1  dyoung 	char *invalid;
    210  1.1  dyoung 	prop_data_t data;
    211  1.1  dyoung 	char *val;
    212  1.1  dyoung 
    213  1.1  dyoung 	init_current_media(env, xenv);
    214  1.1  dyoung 
    215  1.1  dyoung 	data = (prop_data_t)prop_dictionary_get(env, "mediaopt");
    216  1.1  dyoung 	assert(data != NULL);
    217  1.1  dyoung 
    218  1.1  dyoung 	/* Can only issue `mediaopt' once. */
    219  1.1  dyoung 	/* Can't issue `mediaopt' if `instance' has already been issued. */
    220  1.1  dyoung 
    221  1.1  dyoung 	val = strndup(prop_data_data_nocopy(data), prop_data_size(data));
    222  1.1  dyoung 	if (val == NULL)
    223  1.1  dyoung 		return -1;
    224  1.1  dyoung 
    225  1.1  dyoung 	mediaopt_set = get_media_options(media_current, val, &invalid);
    226  1.1  dyoung 	free(val);
    227  1.1  dyoung 	if (mediaopt_set == -1)
    228  1.1  dyoung 		media_error(media_current, invalid, "option");
    229  1.1  dyoung 
    230  1.1  dyoung 	/* Media will be set after other processing is complete. */
    231  1.1  dyoung 	return 0;
    232  1.1  dyoung }
    233  1.1  dyoung 
    234  1.1  dyoung static int
    235  1.1  dyoung unsetmediaopt(prop_dictionary_t env, prop_dictionary_t xenv)
    236  1.1  dyoung {
    237  1.1  dyoung 	char *invalid, *val;
    238  1.1  dyoung 	prop_data_t data;
    239  1.1  dyoung 
    240  1.1  dyoung 	init_current_media(env, xenv);
    241  1.1  dyoung 
    242  1.1  dyoung 	data = (prop_data_t)prop_dictionary_get(env, "unmediaopt");
    243  1.1  dyoung 	if (data == NULL) {
    244  1.1  dyoung 		errno = ENOENT;
    245  1.1  dyoung 		return -1;
    246  1.1  dyoung 	}
    247  1.1  dyoung 
    248  1.1  dyoung 	val = strndup(prop_data_data_nocopy(data), prop_data_size(data));
    249  1.1  dyoung 	if (val == NULL)
    250  1.1  dyoung 		return -1;
    251  1.1  dyoung 
    252  1.1  dyoung 	/*
    253  1.1  dyoung 	 * No need to check for A_MEDIAINST, since the test for A_MEDIA
    254  1.1  dyoung 	 * implicitly checks for A_MEDIAINST.
    255  1.1  dyoung 	 */
    256  1.1  dyoung 
    257  1.1  dyoung 	mediaopt_clear = get_media_options(media_current, val, &invalid);
    258  1.1  dyoung 	free(val);
    259  1.1  dyoung 	if (mediaopt_clear == -1)
    260  1.1  dyoung 		media_error(media_current, invalid, "option");
    261  1.1  dyoung 
    262  1.1  dyoung 	/* Media will be set after other processing is complete. */
    263  1.1  dyoung 	return 0;
    264  1.1  dyoung }
    265  1.1  dyoung 
    266  1.1  dyoung static int
    267  1.1  dyoung setmediainst(prop_dictionary_t env, prop_dictionary_t xenv)
    268  1.1  dyoung {
    269  1.1  dyoung 	int type, subtype, options;
    270  1.1  dyoung 	int64_t inst;
    271  1.1  dyoung 	bool rc;
    272  1.1  dyoung 
    273  1.1  dyoung 	init_current_media(env, xenv);
    274  1.1  dyoung 
    275  1.1  dyoung 	rc = prop_dictionary_get_int64(env, "mediainst", &inst);
    276  1.1  dyoung 	assert(rc);
    277  1.1  dyoung 
    278  1.1  dyoung 	/* Can only issue `instance' once. */
    279  1.1  dyoung 	/* Must have already specified `media' */
    280  1.1  dyoung 
    281  1.1  dyoung 	type = IFM_TYPE(media_current);
    282  1.1  dyoung 	subtype = IFM_SUBTYPE(media_current);
    283  1.1  dyoung 	options = IFM_OPTIONS(media_current);
    284  1.1  dyoung 
    285  1.1  dyoung 	media_current = IFM_MAKEWORD(type, subtype, options, inst);
    286  1.1  dyoung 
    287  1.1  dyoung 	/* Media will be set after other processing is complete. */
    288  1.1  dyoung 	return 0;
    289  1.1  dyoung }
    290  1.1  dyoung 
    291  1.1  dyoung static int
    292  1.1  dyoung setmediamode(prop_dictionary_t env, prop_dictionary_t xenv)
    293  1.1  dyoung {
    294  1.1  dyoung 	int type, subtype, options, inst, mode;
    295  1.1  dyoung 	prop_data_t data;
    296  1.1  dyoung 	char *val;
    297  1.1  dyoung 
    298  1.1  dyoung 	init_current_media(env, xenv);
    299  1.1  dyoung 
    300  1.1  dyoung 	data = (prop_data_t)prop_dictionary_get(env, "mediamode");
    301  1.1  dyoung 	assert(data != NULL);
    302  1.1  dyoung 
    303  1.1  dyoung 	type = IFM_TYPE(media_current);
    304  1.1  dyoung 	subtype = IFM_SUBTYPE(media_current);
    305  1.1  dyoung 	options = IFM_OPTIONS(media_current);
    306  1.1  dyoung 	inst = IFM_INST(media_current);
    307  1.1  dyoung 
    308  1.1  dyoung 	val = strndup(prop_data_data_nocopy(data), prop_data_size(data));
    309  1.1  dyoung 	if (val == NULL)
    310  1.1  dyoung 		return -1;
    311  1.1  dyoung 
    312  1.1  dyoung 	mode = get_media_mode(type, val);
    313  1.1  dyoung 	if (mode == -1)
    314  1.1  dyoung 		media_error(type, val, "mode");
    315  1.1  dyoung 
    316  1.1  dyoung 	free(val);
    317  1.1  dyoung 
    318  1.1  dyoung 	media_current = IFM_MAKEWORD(type, subtype, options, inst) | mode;
    319  1.1  dyoung 
    320  1.1  dyoung 	/* Media will be set after other processing is complete. */
    321  1.1  dyoung 	return 0;
    322  1.1  dyoung }
    323  1.1  dyoung 
    324  1.1  dyoung void
    325  1.1  dyoung print_media_word(int ifmw, const char *opt_sep)
    326  1.1  dyoung {
    327  1.1  dyoung 	const char *str;
    328  1.1  dyoung 
    329  1.1  dyoung 	printf("%s", get_media_subtype_string(ifmw));
    330  1.1  dyoung 
    331  1.1  dyoung 	/* Find mode. */
    332  1.1  dyoung 	if (IFM_MODE(ifmw) != 0) {
    333  1.1  dyoung 		str = get_media_mode_string(ifmw);
    334  1.1  dyoung 		if (str != NULL)
    335  1.1  dyoung 			printf(" mode %s", str);
    336  1.1  dyoung 	}
    337  1.1  dyoung 
    338  1.1  dyoung 	/* Find options. */
    339  1.1  dyoung 	for (; (str = get_media_option_string(&ifmw)) != NULL; opt_sep = ",")
    340  1.1  dyoung 		printf("%s%s", opt_sep, str);
    341  1.1  dyoung 
    342  1.1  dyoung 	if (IFM_INST(ifmw) != 0)
    343  1.1  dyoung 		printf(" instance %d", IFM_INST(ifmw));
    344  1.1  dyoung }
    345  1.1  dyoung 
    346  1.1  dyoung void
    347  1.1  dyoung media_status(prop_dictionary_t env, prop_dictionary_t oenv)
    348  1.1  dyoung {
    349  1.1  dyoung 	struct ifmediareq ifmr;
    350  1.1  dyoung 	int af, i, s;
    351  1.1  dyoung 	int *media_list;
    352  1.1  dyoung 	const char *ifname;
    353  1.1  dyoung 
    354  1.1  dyoung 	if ((ifname = getifname(env)) == NULL)
    355  1.1  dyoung 		err(EXIT_FAILURE, "getifname");
    356  1.1  dyoung 	if ((af = getaf(env)) == -1)
    357  1.1  dyoung 		af = AF_UNSPEC;
    358  1.1  dyoung 
    359  1.1  dyoung 	/* get out early if the family is unsupported by the kernel */
    360  1.1  dyoung 	if ((s = getsock(af)) == -1)
    361  1.1  dyoung 		err(EXIT_FAILURE, "%s: getsock", __func__);
    362  1.1  dyoung 
    363  1.1  dyoung 	memset(&ifmr, 0, sizeof(ifmr));
    364  1.1  dyoung 	estrlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
    365  1.1  dyoung 
    366  1.1  dyoung 	if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
    367  1.1  dyoung 		/*
    368  1.1  dyoung 		 * Interface doesn't support SIOC{G,S}IFMEDIA.
    369  1.1  dyoung 		 */
    370  1.1  dyoung 		return;
    371  1.1  dyoung 	}
    372  1.1  dyoung 
    373  1.1  dyoung 	if (ifmr.ifm_count == 0) {
    374  1.1  dyoung 		warnx("%s: no media types?", ifname);
    375  1.1  dyoung 		return;
    376  1.1  dyoung 	}
    377  1.1  dyoung 
    378  1.1  dyoung 	media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
    379  1.1  dyoung 	if (media_list == NULL)
    380  1.1  dyoung 		err(EXIT_FAILURE, "malloc");
    381  1.1  dyoung 	ifmr.ifm_ulist = media_list;
    382  1.1  dyoung 
    383  1.1  dyoung 	if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1)
    384  1.1  dyoung 		err(EXIT_FAILURE, "SIOCGIFMEDIA");
    385  1.1  dyoung 
    386  1.1  dyoung 	printf("\tmedia: %s ", get_media_type_string(ifmr.ifm_current));
    387  1.1  dyoung 	print_media_word(ifmr.ifm_current, " ");
    388  1.1  dyoung 	if (ifmr.ifm_active != ifmr.ifm_current) {
    389  1.1  dyoung 		printf(" (");
    390  1.1  dyoung 		print_media_word(ifmr.ifm_active, " ");
    391  1.1  dyoung 		printf(")");
    392  1.1  dyoung 	}
    393  1.1  dyoung 	printf("\n");
    394  1.1  dyoung 
    395  1.1  dyoung 	if (ifmr.ifm_status & IFM_STATUS_VALID) {
    396  1.1  dyoung 		const struct ifmedia_status_description *ifms;
    397  1.1  dyoung 		int bitno, found = 0;
    398  1.1  dyoung 
    399  1.1  dyoung 		printf("\tstatus: ");
    400  1.1  dyoung 		for (bitno = 0; ifm_status_valid_list[bitno] != 0; bitno++) {
    401  1.1  dyoung 			for (ifms = ifm_status_descriptions;
    402  1.1  dyoung 			     ifms->ifms_valid != 0; ifms++) {
    403  1.1  dyoung 				if (ifms->ifms_type !=
    404  1.1  dyoung 				      IFM_TYPE(ifmr.ifm_current) ||
    405  1.1  dyoung 				    ifms->ifms_valid !=
    406  1.1  dyoung 				      ifm_status_valid_list[bitno])
    407  1.1  dyoung 					continue;
    408  1.1  dyoung 				printf("%s%s", found ? ", " : "",
    409  1.1  dyoung 				    IFM_STATUS_DESC(ifms, ifmr.ifm_status));
    410  1.1  dyoung 				found = 1;
    411  1.1  dyoung 
    412  1.1  dyoung 				/*
    413  1.1  dyoung 				 * For each valid indicator bit, there's
    414  1.1  dyoung 				 * only one entry for each media type, so
    415  1.1  dyoung 				 * terminate the inner loop now.
    416  1.1  dyoung 				 */
    417  1.1  dyoung 				break;
    418  1.1  dyoung 			}
    419  1.1  dyoung 		}
    420  1.1  dyoung 
    421  1.1  dyoung 		if (found == 0)
    422  1.1  dyoung 			printf("unknown");
    423  1.1  dyoung 		printf("\n");
    424  1.1  dyoung 	}
    425  1.1  dyoung 
    426  1.1  dyoung 	if (get_flag('m')) {
    427  1.1  dyoung 		int type, printed_type;
    428  1.1  dyoung 
    429  1.1  dyoung 		for (type = IFM_NMIN; type <= IFM_NMAX; type += IFM_NMIN) {
    430  1.1  dyoung 			for (i = 0, printed_type = 0; i < ifmr.ifm_count; i++) {
    431  1.1  dyoung 				if (IFM_TYPE(media_list[i]) != type)
    432  1.1  dyoung 					continue;
    433  1.1  dyoung 				if (printed_type == 0) {
    434  1.1  dyoung 					printf("\tsupported %s media:\n",
    435  1.1  dyoung 					    get_media_type_string(type));
    436  1.1  dyoung 					printed_type = 1;
    437  1.1  dyoung 				}
    438  1.1  dyoung 				printf("\t\tmedia ");
    439  1.1  dyoung 				print_media_word(media_list[i], " mediaopt ");
    440  1.1  dyoung 				printf("\n");
    441  1.1  dyoung 			}
    442  1.1  dyoung 		}
    443  1.1  dyoung 	}
    444  1.1  dyoung 
    445  1.1  dyoung 	free(media_list);
    446  1.1  dyoung }
    447  1.1  dyoung 
    448  1.1  dyoung static void
    449  1.2  dyoung media_usage(prop_dictionary_t env)
    450  1.2  dyoung {
    451  1.2  dyoung 	fprintf(stderr,
    452  1.2  dyoung 	    "\t[ media type ] [ mediaopt opts ] [ -mediaopt opts ] "
    453  1.2  dyoung 	    "[ instance minst ]\n");
    454  1.2  dyoung }
    455  1.2  dyoung 
    456  1.2  dyoung static void
    457  1.1  dyoung media_constructor(void)
    458  1.1  dyoung {
    459  1.1  dyoung 	if (register_flag('m') != 0)
    460  1.1  dyoung 		err(EXIT_FAILURE, __func__);
    461  1.2  dyoung 	usage_func_init(&usage, media_usage);
    462  1.2  dyoung 	register_usage(&usage);
    463  1.1  dyoung }
    464