1 /* $NetBSD: ifconfig.c,v 1.34 1997/04/21 01:17:58 lukem Exp $ */
2 /* $FreeBSD: src/sbin/ifconfig/ifmedia.c,v 1.25.6.1 2008/11/25 02:59:29 kensmith Exp $ */
5 * Copyright (c) 1997 Jason R. Thorpe.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed for the NetBSD Project
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * Copyright (c) 1983, 1993
38 * The Regents of the University of California. All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 #include <sys/param.h>
70 #include <sys/ioctl.h>
71 #include <sys/socket.h>
72 #include <sys/sysctl.h>
76 #include <net/if_dl.h>
77 #include <net/if_types.h>
78 #include <net/if_media.h>
79 #include <net/route.h>
92 static void domediaopt(const char *, int, int);
93 static int get_media_subtype(int, const char *);
95 static int get_media_mode(int, const char *);
97 static int get_media_options(int, const char *);
98 static int lookup_media_word(struct ifmedia_description
*, const char *);
99 static void print_media_word(int, int);
100 static void print_media_word_ifconfig(int);
102 static struct ifmedia_description
*get_toptype_desc(int);
103 static struct ifmedia_type_to_subtype
*get_toptype_ttos(int);
104 static struct ifmedia_description
*get_subtype_desc(int,
105 struct ifmedia_type_to_subtype
*ttos
);
110 struct ifmediareq ifmr
;
113 (void) memset(&ifmr
, 0, sizeof(ifmr
));
114 (void) strncpy(ifmr
.ifm_name
, name
, sizeof(ifmr
.ifm_name
));
116 if (ioctl(s
, SIOCGIFMEDIA
, (caddr_t
)&ifmr
) < 0) {
118 * Interface doesn't support SIOC{G,S}IFMEDIA.
123 if (ifmr
.ifm_count
== 0) {
124 warnx("%s: no media types?", name
);
128 media_list
= (int *)malloc(ifmr
.ifm_count
* sizeof(int));
129 if (media_list
== NULL
)
131 ifmr
.ifm_ulist
= media_list
;
133 if (ioctl(s
, SIOCGIFMEDIA
, (caddr_t
)&ifmr
) < 0)
134 err(1, "SIOCGIFMEDIA");
137 print_media_word(ifmr
.ifm_current
, 1);
138 if (ifmr
.ifm_active
!= ifmr
.ifm_current
) {
141 print_media_word(ifmr
.ifm_active
, 0);
147 if (ifmr
.ifm_status
& IFM_AVALID
) {
148 printf("\tstatus: ");
150 switch (IFM_TYPE(ifmr
.ifm_active
)) {
153 if (ifmr
.ifm_status
& IFM_ACTIVE
)
156 printf("no carrier");
161 if (ifmr
.ifm_status
& IFM_ACTIVE
)
168 /* XXX: Different value for adhoc? */
169 if (ifmr
.ifm_status
& IFM_ACTIVE
)
170 printf("associated");
172 printf("no carrier");
176 if (ifmr
.ifm_status
& IFM_ACTIVE
)
184 if (ifmr
.ifm_count
> 0 && supmedia
) {
185 printf("\tsupported media:\n");
186 for (i
= 0; i
< ifmr
.ifm_count
; i
++) {
188 print_media_word_ifconfig(media_list
[i
]);
197 ifmedia_getstate(int s
)
199 static struct ifmediareq
*ifmr
= NULL
;
203 ifmr
= (struct ifmediareq
*)malloc(sizeof(struct ifmediareq
));
207 (void) memset(ifmr
, 0, sizeof(struct ifmediareq
));
208 (void) strncpy(ifmr
->ifm_name
, name
,
209 sizeof(ifmr
->ifm_name
));
212 ifmr
->ifm_ulist
= NULL
;
215 * We must go through the motions of reading all
216 * supported media because we need to know both
217 * the current media type and the top-level type.
220 if (ioctl(s
, SIOCGIFMEDIA
, (caddr_t
)ifmr
) < 0) {
221 err(1, "SIOCGIFMEDIA");
224 if (ifmr
->ifm_count
== 0)
225 errx(1, "%s: no media types?", name
);
227 mwords
= (int *)malloc(ifmr
->ifm_count
* sizeof(int));
231 ifmr
->ifm_ulist
= mwords
;
232 if (ioctl(s
, SIOCGIFMEDIA
, (caddr_t
)ifmr
) < 0)
233 err(1, "SIOCGIFMEDIA");
240 setifmediacallback(int s
, void *arg
)
242 struct ifmediareq
*ifmr
= (struct ifmediareq
*)arg
;
243 static int did_it
= 0;
246 ifr
.ifr_media
= ifmr
->ifm_current
;
247 if (ioctl(s
, SIOCSIFMEDIA
, (caddr_t
)&ifr
) < 0)
248 err(1, "SIOCSIFMEDIA (media)");
249 free(ifmr
->ifm_ulist
);
256 setmedia(const char *val
, int d
, int s
, const struct afswtch
*afp
)
258 struct ifmediareq
*ifmr
;
261 ifmr
= ifmedia_getstate(s
);
264 * We are primarily concerned with the top-level type.
265 * However, "current" may be only IFM_NONE, so we just look
266 * for the top-level type in the first "supported type"
269 * (I'm assuming that all supported media types for a given
270 * interface will be the same top-level type..)
272 subtype
= get_media_subtype(IFM_TYPE(ifmr
->ifm_ulist
[0]), val
);
274 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
275 ifr
.ifr_media
= (ifmr
->ifm_current
& ~(IFM_NMASK
|IFM_TMASK
)) |
276 IFM_TYPE(ifmr
->ifm_ulist
[0]) | subtype
;
278 if ((ifr
.ifr_media
& IFM_TMASK
) == 0) {
279 ifr
.ifr_media
&= ~IFM_GMASK
;
282 ifmr
->ifm_current
= ifr
.ifr_media
;
283 callback_register(setifmediacallback
, (void *)ifmr
);
287 setmediaopt(const char *val
, int d
, int s
, const struct afswtch
*afp
)
290 domediaopt(val
, 0, s
);
294 unsetmediaopt(const char *val
, int d
, int s
, const struct afswtch
*afp
)
297 domediaopt(val
, 1, s
);
301 domediaopt(const char *val
, int clear
, int s
)
303 struct ifmediareq
*ifmr
;
306 ifmr
= ifmedia_getstate(s
);
308 options
= get_media_options(IFM_TYPE(ifmr
->ifm_ulist
[0]), val
);
310 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
311 ifr
.ifr_media
= ifmr
->ifm_current
;
313 ifr
.ifr_media
&= ~options
;
315 if (options
& IFM_HDX
) {
316 ifr
.ifr_media
&= ~IFM_FDX
;
319 ifr
.ifr_media
|= options
;
321 ifmr
->ifm_current
= ifr
.ifr_media
;
322 callback_register(setifmediacallback
, (void *)ifmr
);
326 setmediainst(const char *val
, int d
, int s
, const struct afswtch
*afp
)
328 struct ifmediareq
*ifmr
;
331 ifmr
= ifmedia_getstate(s
);
334 if (inst
< 0 || inst
> IFM_INST_MAX
)
335 errx(1, "invalid media instance: %s", val
);
337 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
338 ifr
.ifr_media
= (ifmr
->ifm_current
& ~IFM_IMASK
) | inst
<< IFM_ISHIFT
;
340 ifmr
->ifm_current
= ifr
.ifr_media
;
341 callback_register(setifmediacallback
, (void *)ifmr
);
346 setmediamode(const char *val
, int d
, int s
, const struct afswtch
*afp
)
348 struct ifmediareq
*ifmr
;
351 ifmr
= ifmedia_getstate(s
);
353 mode
= get_media_mode(IFM_TYPE(ifmr
->ifm_ulist
[0]), val
);
355 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
356 ifr
.ifr_media
= (ifmr
->ifm_current
& ~IFM_MMASK
) | mode
;
358 ifmr
->ifm_current
= ifr
.ifr_media
;
359 callback_register(setifmediacallback
, (void *)ifmr
);
363 /**********************************************************************
364 * A good chunk of this is duplicated from sys/net/ifmedia.c
365 **********************************************************************/
367 static struct ifmedia_description ifm_type_descriptions
[] =
368 IFM_TYPE_DESCRIPTIONS
;
370 static struct ifmedia_description ifm_subtype_ethernet_descriptions
[] =
371 IFM_SUBTYPE_ETHERNET_DESCRIPTIONS
;
373 static struct ifmedia_description ifm_subtype_ethernet_aliases
[] =
374 IFM_SUBTYPE_ETHERNET_ALIASES
;
376 static struct ifmedia_description ifm_subtype_ethernet_option_descriptions
[] =
377 IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS
;
379 static struct ifmedia_description ifm_subtype_tokenring_descriptions
[] =
380 IFM_SUBTYPE_TOKENRING_DESCRIPTIONS
;
382 static struct ifmedia_description ifm_subtype_tokenring_aliases
[] =
383 IFM_SUBTYPE_TOKENRING_ALIASES
;
385 static struct ifmedia_description ifm_subtype_tokenring_option_descriptions
[] =
386 IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS
;
388 static struct ifmedia_description ifm_subtype_fddi_descriptions
[] =
389 IFM_SUBTYPE_FDDI_DESCRIPTIONS
;
391 static struct ifmedia_description ifm_subtype_fddi_aliases
[] =
392 IFM_SUBTYPE_FDDI_ALIASES
;
394 static struct ifmedia_description ifm_subtype_fddi_option_descriptions
[] =
395 IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS
;
398 static struct ifmedia_description ifm_subtype_ieee80211_descriptions
[] =
399 IFM_SUBTYPE_IEEE80211_DESCRIPTIONS
;
401 static struct ifmedia_description ifm_subtype_ieee80211_aliases
[] =
402 IFM_SUBTYPE_IEEE80211_ALIASES
;
404 static struct ifmedia_description ifm_subtype_ieee80211_option_descriptions
[] =
405 IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS
;
407 struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions
[] =
408 IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS
;
410 struct ifmedia_description ifm_subtype_ieee80211_mode_aliases
[] =
411 IFM_SUBTYPE_IEEE80211_MODE_ALIASES
;
413 static struct ifmedia_description ifm_subtype_atm_descriptions
[] =
414 IFM_SUBTYPE_ATM_DESCRIPTIONS
;
416 static struct ifmedia_description ifm_subtype_atm_aliases
[] =
417 IFM_SUBTYPE_ATM_ALIASES
;
419 static struct ifmedia_description ifm_subtype_atm_option_descriptions
[] =
420 IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS
;
423 static struct ifmedia_description ifm_subtype_shared_descriptions
[] =
424 IFM_SUBTYPE_SHARED_DESCRIPTIONS
;
426 static struct ifmedia_description ifm_subtype_shared_aliases
[] =
427 IFM_SUBTYPE_SHARED_ALIASES
;
429 static struct ifmedia_description ifm_shared_option_descriptions
[] =
430 IFM_SHARED_OPTION_DESCRIPTIONS
;
432 struct ifmedia_type_to_subtype
{
434 struct ifmedia_description
*desc
;
438 struct ifmedia_description
*desc
;
442 struct ifmedia_description
*desc
;
447 /* must be in the same order as IFM_TYPE_DESCRIPTIONS */
448 static struct ifmedia_type_to_subtype ifmedia_types_to_subtypes
[] = {
451 { &ifm_subtype_shared_descriptions
[0], 0 },
452 { &ifm_subtype_shared_aliases
[0], 1 },
453 { &ifm_subtype_ethernet_descriptions
[0], 0 },
454 { &ifm_subtype_ethernet_aliases
[0], 1 },
458 { &ifm_shared_option_descriptions
[0], 0 },
459 { &ifm_subtype_ethernet_option_descriptions
[0], 0 },
468 { &ifm_subtype_shared_descriptions
[0], 0 },
469 { &ifm_subtype_shared_aliases
[0], 1 },
470 { &ifm_subtype_tokenring_descriptions
[0], 0 },
471 { &ifm_subtype_tokenring_aliases
[0], 1 },
475 { &ifm_shared_option_descriptions
[0], 0 },
476 { &ifm_subtype_tokenring_option_descriptions
[0], 0 },
485 { &ifm_subtype_shared_descriptions
[0], 0 },
486 { &ifm_subtype_shared_aliases
[0], 1 },
487 { &ifm_subtype_fddi_descriptions
[0], 0 },
488 { &ifm_subtype_fddi_aliases
[0], 1 },
492 { &ifm_shared_option_descriptions
[0], 0 },
493 { &ifm_subtype_fddi_option_descriptions
[0], 0 },
503 { &ifm_subtype_shared_descriptions
[0], 0 },
504 { &ifm_subtype_shared_aliases
[0], 1 },
505 { &ifm_subtype_ieee80211_descriptions
[0], 0 },
506 { &ifm_subtype_ieee80211_aliases
[0], 1 },
510 { &ifm_shared_option_descriptions
[0], 0 },
511 { &ifm_subtype_ieee80211_option_descriptions
[0], 0 },
515 { &ifm_subtype_ieee80211_mode_descriptions
[0], 0 },
516 { &ifm_subtype_ieee80211_mode_aliases
[0], 0 },
522 { &ifm_subtype_shared_descriptions
[0], 0 },
523 { &ifm_subtype_shared_aliases
[0], 1 },
524 { &ifm_subtype_atm_descriptions
[0], 0 },
525 { &ifm_subtype_atm_aliases
[0], 1 },
529 { &ifm_shared_option_descriptions
[0], 0 },
530 { &ifm_subtype_atm_option_descriptions
[0], 0 },
541 get_media_subtype(int type
, const char *val
)
543 struct ifmedia_description
*desc
;
544 struct ifmedia_type_to_subtype
*ttos
;
547 /* Find the top-level interface type. */
548 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
549 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
550 if (type
== desc
->ifmt_word
)
552 if (desc
->ifmt_string
== NULL
)
553 errx(1, "unknown media type 0x%x", type
);
555 for (i
= 0; ttos
->subtypes
[i
].desc
!= NULL
; i
++) {
556 rval
= lookup_media_word(ttos
->subtypes
[i
].desc
, val
);
560 errx(1, "unknown media subtype: %s", val
);
566 get_media_mode(int type
, const char *val
)
568 struct ifmedia_description
*desc
;
569 struct ifmedia_type_to_subtype
*ttos
;
572 /* Find the top-level interface type. */
573 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
574 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
575 if (type
== desc
->ifmt_word
)
577 if (desc
->ifmt_string
== NULL
)
578 errx(1, "unknown media mode 0x%x", type
);
580 for (i
= 0; ttos
->modes
[i
].desc
!= NULL
; i
++) {
581 rval
= lookup_media_word(ttos
->modes
[i
].desc
, val
);
590 get_media_options(int type
, const char *val
)
592 struct ifmedia_description
*desc
;
593 struct ifmedia_type_to_subtype
*ttos
;
594 char *optlist
, *optptr
;
595 int option
= 0, i
, rval
= 0;
597 /* We muck with the string, so copy it. */
598 optlist
= strdup(val
);
602 /* Find the top-level interface type. */
603 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
604 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
605 if (type
== desc
->ifmt_word
)
607 if (desc
->ifmt_string
== NULL
)
608 errx(1, "unknown media type 0x%x", type
);
611 * Look up the options in the user-provided comma-separated
615 for (; (optptr
= strtok(optptr
, ",")) != NULL
; optptr
= NULL
) {
616 for (i
= 0; ttos
->options
[i
].desc
!= NULL
; i
++) {
617 option
= lookup_media_word(ttos
->options
[i
].desc
, optptr
);
622 errx(1, "unknown option: %s", optptr
);
631 lookup_media_word(struct ifmedia_description
*desc
, const char *val
)
634 for (; desc
->ifmt_string
!= NULL
; desc
++)
635 if (strcasecmp(desc
->ifmt_string
, val
) == 0)
636 return (desc
->ifmt_word
);
641 static struct ifmedia_description
*get_toptype_desc(int ifmw
)
643 struct ifmedia_description
*desc
;
645 for (desc
= ifm_type_descriptions
; desc
->ifmt_string
!= NULL
; desc
++)
646 if (IFM_TYPE(ifmw
) == desc
->ifmt_word
)
652 static struct ifmedia_type_to_subtype
*get_toptype_ttos(int ifmw
)
654 struct ifmedia_description
*desc
;
655 struct ifmedia_type_to_subtype
*ttos
;
657 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
658 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
659 if (IFM_TYPE(ifmw
) == desc
->ifmt_word
)
665 static struct ifmedia_description
*get_subtype_desc(int ifmw
,
666 struct ifmedia_type_to_subtype
*ttos
)
669 struct ifmedia_description
*desc
;
671 for (i
= 0; ttos
->subtypes
[i
].desc
!= NULL
; i
++) {
672 if (ttos
->subtypes
[i
].alias
)
674 for (desc
= ttos
->subtypes
[i
].desc
;
675 desc
->ifmt_string
!= NULL
; desc
++) {
676 if (IFM_SUBTYPE(ifmw
) == desc
->ifmt_word
)
685 static struct ifmedia_description
*get_mode_desc(int ifmw
,
686 struct ifmedia_type_to_subtype
*ttos
)
689 struct ifmedia_description
*desc
;
691 for (i
= 0; ttos
->modes
[i
].desc
!= NULL
; i
++) {
692 if (ttos
->modes
[i
].alias
)
694 for (desc
= ttos
->modes
[i
].desc
;
695 desc
->ifmt_string
!= NULL
; desc
++) {
696 if (IFM_MODE(ifmw
) == desc
->ifmt_word
)
706 print_media_word(int ifmw
, int print_toptype
)
708 struct ifmedia_description
*desc
;
709 struct ifmedia_type_to_subtype
*ttos
;
710 int seen_option
= 0, i
;
712 /* Find the top-level interface type. */
713 desc
= get_toptype_desc(ifmw
);
714 ttos
= get_toptype_ttos(ifmw
);
715 if (desc
->ifmt_string
== NULL
) {
716 printf("<unknown type>");
719 } else if (print_toptype
) {
720 printf("%s", desc
->ifmt_string
);
725 * Don't print the top-level type; it's not like we can
726 * change it, or anything.
730 desc
= get_subtype_desc(ifmw
, ttos
);
732 printf("<unknown subtype>");
741 printf("%s", desc
->ifmt_string
);
745 desc
= get_mode_desc(ifmw
, ttos
);
746 if (desc
!= NULL
&& strcasecmp("autoselect", desc
->ifmt_string
))
747 printf(" mode %s", desc
->ifmt_string
);
751 for (i
= 0; ttos
->options
[i
].desc
!= NULL
; i
++) {
752 if (ttos
->options
[i
].alias
)
754 for (desc
= ttos
->options
[i
].desc
;
755 desc
->ifmt_string
!= NULL
; desc
++) {
756 if (ifmw
& desc
->ifmt_word
) {
757 if (seen_option
== 0)
759 printf("%s%s", seen_option
++ ? "," : "",
764 printf("%s", seen_option
? ">" : "");
767 if (print_toptype
&& IFM_INST(ifmw
) != 0)
768 printf(" instance %d", IFM_INST(ifmw
));
773 print_media_word_ifconfig(int ifmw
)
775 struct ifmedia_description
*desc
;
776 struct ifmedia_type_to_subtype
*ttos
;
779 /* Find the top-level interface type. */
780 desc
= get_toptype_desc(ifmw
);
781 ttos
= get_toptype_ttos(ifmw
);
782 if (desc
->ifmt_string
== NULL
) {
783 printf("<unknown type>");
788 * Don't print the top-level type; it's not like we can
789 * change it, or anything.
793 desc
= get_subtype_desc(ifmw
, ttos
);
795 printf("<unknown subtype>");
799 printf("media %s", desc
->ifmt_string
);
802 desc
= get_mode_desc(ifmw
, ttos
);
804 printf(" mode %s", desc
->ifmt_string
);
808 for (i
= 0; ttos
->options
[i
].desc
!= NULL
; i
++) {
809 if (ttos
->options
[i
].alias
)
811 for (desc
= ttos
->options
[i
].desc
;
812 desc
->ifmt_string
!= NULL
; desc
++) {
813 if (ifmw
& desc
->ifmt_word
) {
814 printf(" mediaopt %s", desc
->ifmt_string
);
819 if (IFM_INST(ifmw
) != 0)
820 printf(" instance %d", IFM_INST(ifmw
));
823 /**********************************************************************
825 **********************************************************************/
827 static struct cmd media_cmds
[] = {
828 DEF_CMD_ARG("media", setmedia
),
830 DEF_CMD_ARG("mode", setmediamode
),
832 DEF_CMD_ARG("mediaopt", setmediaopt
),
833 DEF_CMD_ARG("-mediaopt",unsetmediaopt
),
834 DEF_CMD_ARG("inst", setmediainst
),
835 DEF_CMD_ARG("instance", setmediainst
),
837 static struct afswtch af_media
= {
838 .af_name
= "af_media",
840 .af_other_status
= media_status
,
843 static __constructor
void
846 #define N(a) (sizeof(a) / sizeof(a[0]))
849 for (i
= 0; i
< N(media_cmds
); i
++)
850 cmd_register(&media_cmds
[i
]);
851 af_register(&af_media
);