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
, SIOCGIFXMEDIA
, (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
, SIOCGIFXMEDIA
, (caddr_t
)&ifmr
) < 0)
134 err(1, "SIOCGIFXMEDIA");
136 print_media_word(ifmr
.ifm_current
, 1);
137 if (ifmr
.ifm_active
!= ifmr
.ifm_current
) {
140 print_media_word(ifmr
.ifm_active
, 0);
146 if (ifmr
.ifm_status
& IFM_AVALID
) {
147 printf("\tstatus: ");
149 switch (IFM_TYPE(ifmr
.ifm_active
)) {
152 if (ifmr
.ifm_status
& IFM_ACTIVE
)
155 printf("no carrier");
160 if (ifmr
.ifm_status
& IFM_ACTIVE
)
167 /* XXX: Different value for adhoc? */
168 if (ifmr
.ifm_status
& IFM_ACTIVE
)
169 printf("associated");
171 printf("no carrier");
175 if (ifmr
.ifm_status
& IFM_ACTIVE
)
183 if (ifmr
.ifm_count
> 0 && supmedia
) {
184 printf("\tsupported media:\n");
185 for (i
= 0; i
< ifmr
.ifm_count
; i
++) {
187 print_media_word_ifconfig(media_list
[i
]);
196 ifmedia_getstate(int s
)
198 static struct ifmediareq
*ifmr
= NULL
;
202 ifmr
= (struct ifmediareq
*)malloc(sizeof(struct ifmediareq
));
206 (void) memset(ifmr
, 0, sizeof(struct ifmediareq
));
207 (void) strncpy(ifmr
->ifm_name
, name
,
208 sizeof(ifmr
->ifm_name
));
211 ifmr
->ifm_ulist
= NULL
;
214 * We must go through the motions of reading all
215 * supported media because we need to know both
216 * the current media type and the top-level type.
219 if (ioctl(s
, SIOCGIFXMEDIA
, (caddr_t
)ifmr
) < 0) {
220 err(1, "SIOCGIFXMEDIA");
223 if (ifmr
->ifm_count
== 0)
224 errx(1, "%s: no media types?", name
);
226 mwords
= (int *)malloc(ifmr
->ifm_count
* sizeof(int));
230 ifmr
->ifm_ulist
= mwords
;
231 if (ioctl(s
, SIOCGIFXMEDIA
, (caddr_t
)ifmr
) < 0)
232 err(1, "SIOCGIFXMEDIA");
239 setifmediacallback(int s
, void *arg
)
241 struct ifmediareq
*ifmr
= (struct ifmediareq
*)arg
;
242 static int did_it
= 0;
245 ifr
.ifr_media
= ifmr
->ifm_current
;
246 if (ioctl(s
, SIOCSIFMEDIA
, (caddr_t
)&ifr
) < 0)
247 err(1, "SIOCSIFMEDIA (media)");
248 free(ifmr
->ifm_ulist
);
255 setmedia(const char *val
, int d
, int s
, const struct afswtch
*afp
)
257 struct ifmediareq
*ifmr
;
260 ifmr
= ifmedia_getstate(s
);
263 * We are primarily concerned with the top-level type.
264 * However, "current" may be only IFM_NONE, so we just look
265 * for the top-level type in the first "supported type"
268 * (I'm assuming that all supported media types for a given
269 * interface will be the same top-level type..)
271 subtype
= get_media_subtype(IFM_TYPE(ifmr
->ifm_ulist
[0]), val
);
273 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
274 ifr
.ifr_media
= (ifmr
->ifm_current
& ~(IFM_NMASK
|IFM_TMASK
)) |
275 IFM_TYPE(ifmr
->ifm_ulist
[0]) | subtype
;
277 if ((ifr
.ifr_media
& IFM_TMASK
) == 0) {
278 ifr
.ifr_media
&= ~IFM_GMASK
;
281 ifmr
->ifm_current
= ifr
.ifr_media
;
282 callback_register(setifmediacallback
, (void *)ifmr
);
286 setmediaopt(const char *val
, int d
, int s
, const struct afswtch
*afp
)
289 domediaopt(val
, 0, s
);
293 unsetmediaopt(const char *val
, int d
, int s
, const struct afswtch
*afp
)
296 domediaopt(val
, 1, s
);
300 domediaopt(const char *val
, int clear
, int s
)
302 struct ifmediareq
*ifmr
;
305 ifmr
= ifmedia_getstate(s
);
307 options
= get_media_options(IFM_TYPE(ifmr
->ifm_ulist
[0]), val
);
309 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
310 ifr
.ifr_media
= ifmr
->ifm_current
;
312 ifr
.ifr_media
&= ~options
;
314 if (options
& IFM_HDX
) {
315 ifr
.ifr_media
&= ~IFM_FDX
;
318 ifr
.ifr_media
|= options
;
320 ifmr
->ifm_current
= ifr
.ifr_media
;
321 callback_register(setifmediacallback
, (void *)ifmr
);
325 setmediainst(const char *val
, int d
, int s
, const struct afswtch
*afp
)
327 struct ifmediareq
*ifmr
;
330 ifmr
= ifmedia_getstate(s
);
333 if (inst
< 0 || inst
> IFM_INST_MAX
)
334 errx(1, "invalid media instance: %s", val
);
336 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
337 ifr
.ifr_media
= (ifmr
->ifm_current
& ~IFM_IMASK
) | inst
<< IFM_ISHIFT
;
339 ifmr
->ifm_current
= ifr
.ifr_media
;
340 callback_register(setifmediacallback
, (void *)ifmr
);
345 setmediamode(const char *val
, int d
, int s
, const struct afswtch
*afp
)
347 struct ifmediareq
*ifmr
;
350 ifmr
= ifmedia_getstate(s
);
352 mode
= get_media_mode(IFM_TYPE(ifmr
->ifm_ulist
[0]), val
);
354 strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
355 ifr
.ifr_media
= (ifmr
->ifm_current
& ~IFM_MMASK
) | mode
;
357 ifmr
->ifm_current
= ifr
.ifr_media
;
358 callback_register(setifmediacallback
, (void *)ifmr
);
362 /**********************************************************************
363 * A good chunk of this is duplicated from sys/net/ifmedia.c
364 **********************************************************************/
366 static struct ifmedia_description ifm_type_descriptions
[] =
367 IFM_TYPE_DESCRIPTIONS
;
369 static struct ifmedia_description ifm_subtype_ethernet_descriptions
[] =
370 IFM_SUBTYPE_ETHERNET_DESCRIPTIONS
;
372 static struct ifmedia_description ifm_subtype_ethernet_aliases
[] =
373 IFM_SUBTYPE_ETHERNET_ALIASES
;
375 static struct ifmedia_description ifm_subtype_ethernet_option_descriptions
[] =
376 IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS
;
378 static struct ifmedia_description ifm_subtype_tokenring_descriptions
[] =
379 IFM_SUBTYPE_TOKENRING_DESCRIPTIONS
;
381 static struct ifmedia_description ifm_subtype_tokenring_aliases
[] =
382 IFM_SUBTYPE_TOKENRING_ALIASES
;
384 static struct ifmedia_description ifm_subtype_tokenring_option_descriptions
[] =
385 IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS
;
387 static struct ifmedia_description ifm_subtype_fddi_descriptions
[] =
388 IFM_SUBTYPE_FDDI_DESCRIPTIONS
;
390 static struct ifmedia_description ifm_subtype_fddi_aliases
[] =
391 IFM_SUBTYPE_FDDI_ALIASES
;
393 static struct ifmedia_description ifm_subtype_fddi_option_descriptions
[] =
394 IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS
;
396 static struct ifmedia_description ifm_subtype_ieee80211_descriptions
[] =
397 IFM_SUBTYPE_IEEE80211_DESCRIPTIONS
;
399 static struct ifmedia_description ifm_subtype_ieee80211_option_descriptions
[] =
400 IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS
;
403 static struct ifmedia_description ifm_subtype_ieee80211_aliases
[] =
404 IFM_SUBTYPE_IEEE80211_ALIASES
;
406 struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions
[] =
407 IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS
;
409 struct ifmedia_description ifm_subtype_ieee80211_mode_aliases
[] =
410 IFM_SUBTYPE_IEEE80211_MODE_ALIASES
;
412 static struct ifmedia_description ifm_subtype_atm_descriptions
[] =
413 IFM_SUBTYPE_ATM_DESCRIPTIONS
;
415 static struct ifmedia_description ifm_subtype_atm_aliases
[] =
416 IFM_SUBTYPE_ATM_ALIASES
;
418 static struct ifmedia_description ifm_subtype_atm_option_descriptions
[] =
419 IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS
;
422 static struct ifmedia_description ifm_subtype_shared_descriptions
[] =
423 IFM_SUBTYPE_SHARED_DESCRIPTIONS
;
425 static struct ifmedia_description ifm_subtype_shared_aliases
[] =
426 IFM_SUBTYPE_SHARED_ALIASES
;
428 static struct ifmedia_description ifm_shared_option_descriptions
[] =
429 IFM_SHARED_OPTION_DESCRIPTIONS
;
431 struct ifmedia_type_to_subtype
{
433 struct ifmedia_description
*desc
;
437 struct ifmedia_description
*desc
;
441 struct ifmedia_description
*desc
;
446 /* must be in the same order as IFM_TYPE_DESCRIPTIONS */
447 static struct ifmedia_type_to_subtype ifmedia_types_to_subtypes
[] = {
450 { &ifm_subtype_shared_descriptions
[0], 0 },
451 { &ifm_subtype_shared_aliases
[0], 1 },
452 { &ifm_subtype_ethernet_descriptions
[0], 0 },
453 { &ifm_subtype_ethernet_aliases
[0], 1 },
457 { &ifm_shared_option_descriptions
[0], 0 },
458 { &ifm_subtype_ethernet_option_descriptions
[0], 0 },
467 { &ifm_subtype_shared_descriptions
[0], 0 },
468 { &ifm_subtype_shared_aliases
[0], 1 },
469 { &ifm_subtype_tokenring_descriptions
[0], 0 },
470 { &ifm_subtype_tokenring_aliases
[0], 1 },
474 { &ifm_shared_option_descriptions
[0], 0 },
475 { &ifm_subtype_tokenring_option_descriptions
[0], 0 },
484 { &ifm_subtype_shared_descriptions
[0], 0 },
485 { &ifm_subtype_shared_aliases
[0], 1 },
486 { &ifm_subtype_fddi_descriptions
[0], 0 },
487 { &ifm_subtype_fddi_aliases
[0], 1 },
491 { &ifm_shared_option_descriptions
[0], 0 },
492 { &ifm_subtype_fddi_option_descriptions
[0], 0 },
502 { &ifm_subtype_shared_descriptions
[0], 0 },
503 { &ifm_subtype_shared_aliases
[0], 1 },
504 { &ifm_subtype_ieee80211_descriptions
[0], 0 },
508 { &ifm_shared_option_descriptions
[0], 0 },
509 { &ifm_subtype_ieee80211_option_descriptions
[0], 1 },
516 #else /* __APPLE__ */
520 { &ifm_subtype_shared_descriptions
[0], 0 },
521 { &ifm_subtype_shared_aliases
[0], 1 },
522 { &ifm_subtype_ieee80211_descriptions
[0], 0 },
523 { &ifm_subtype_ieee80211_aliases
[0], 1 },
527 { &ifm_shared_option_descriptions
[0], 0 },
528 { &ifm_subtype_ieee80211_option_descriptions
[0], 0 },
532 { &ifm_subtype_ieee80211_mode_descriptions
[0], 0 },
533 { &ifm_subtype_ieee80211_mode_aliases
[0], 0 },
539 { &ifm_subtype_shared_descriptions
[0], 0 },
540 { &ifm_subtype_shared_aliases
[0], 1 },
541 { &ifm_subtype_atm_descriptions
[0], 0 },
542 { &ifm_subtype_atm_aliases
[0], 1 },
546 { &ifm_shared_option_descriptions
[0], 0 },
547 { &ifm_subtype_atm_option_descriptions
[0], 0 },
555 #endif /* __APPLE__ */
559 get_media_subtype(int type
, const char *val
)
561 struct ifmedia_description
*desc
;
562 struct ifmedia_type_to_subtype
*ttos
;
565 /* Find the top-level interface type. */
566 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
567 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
568 if (type
== desc
->ifmt_word
)
570 if (desc
->ifmt_string
== NULL
)
571 errx(1, "unknown media type 0x%x", type
);
573 for (i
= 0; ttos
->subtypes
[i
].desc
!= NULL
; i
++) {
574 rval
= lookup_media_word(ttos
->subtypes
[i
].desc
, val
);
578 errx(1, "unknown media subtype: %s", val
);
584 get_media_mode(int type
, const char *val
)
586 struct ifmedia_description
*desc
;
587 struct ifmedia_type_to_subtype
*ttos
;
590 /* Find the top-level interface type. */
591 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
592 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
593 if (type
== desc
->ifmt_word
)
595 if (desc
->ifmt_string
== NULL
)
596 errx(1, "unknown media mode 0x%x", type
);
598 for (i
= 0; ttos
->modes
[i
].desc
!= NULL
; i
++) {
599 rval
= lookup_media_word(ttos
->modes
[i
].desc
, val
);
608 get_media_options(int type
, const char *val
)
610 struct ifmedia_description
*desc
;
611 struct ifmedia_type_to_subtype
*ttos
;
612 char *optlist
, *optptr
;
613 int option
= 0, i
, rval
= 0;
615 /* We muck with the string, so copy it. */
616 optlist
= strdup(val
);
620 /* Find the top-level interface type. */
621 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
622 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
623 if (type
== desc
->ifmt_word
)
625 if (desc
->ifmt_string
== NULL
)
626 errx(1, "unknown media type 0x%x", type
);
629 * Look up the options in the user-provided comma-separated
633 for (; (optptr
= strtok(optptr
, ",")) != NULL
; optptr
= NULL
) {
634 for (i
= 0; ttos
->options
[i
].desc
!= NULL
; i
++) {
635 option
= lookup_media_word(ttos
->options
[i
].desc
, optptr
);
640 errx(1, "unknown option: %s", optptr
);
649 lookup_media_word(struct ifmedia_description
*desc
, const char *val
)
652 for (; desc
->ifmt_string
!= NULL
; desc
++)
653 if (strcasecmp(desc
->ifmt_string
, val
) == 0)
654 return (desc
->ifmt_word
);
659 static struct ifmedia_description
*get_toptype_desc(int ifmw
)
661 struct ifmedia_description
*desc
;
663 for (desc
= ifm_type_descriptions
; desc
->ifmt_string
!= NULL
; desc
++)
664 if (IFM_TYPE(ifmw
) == desc
->ifmt_word
)
670 static struct ifmedia_type_to_subtype
*get_toptype_ttos(int ifmw
)
672 struct ifmedia_description
*desc
;
673 struct ifmedia_type_to_subtype
*ttos
;
675 for (desc
= ifm_type_descriptions
, ttos
= ifmedia_types_to_subtypes
;
676 desc
->ifmt_string
!= NULL
; desc
++, ttos
++)
677 if (IFM_TYPE(ifmw
) == desc
->ifmt_word
)
683 static struct ifmedia_description
*get_subtype_desc(int ifmw
,
684 struct ifmedia_type_to_subtype
*ttos
)
687 struct ifmedia_description
*desc
;
689 for (i
= 0; ttos
->subtypes
[i
].desc
!= NULL
; i
++) {
690 if (ttos
->subtypes
[i
].alias
)
692 for (desc
= ttos
->subtypes
[i
].desc
;
693 desc
->ifmt_string
!= NULL
; desc
++) {
694 if (IFM_SUBTYPE(ifmw
) == desc
->ifmt_word
)
703 static struct ifmedia_description
*get_mode_desc(int ifmw
,
704 struct ifmedia_type_to_subtype
*ttos
)
707 struct ifmedia_description
*desc
;
709 for (i
= 0; ttos
->modes
[i
].desc
!= NULL
; i
++) {
710 if (ttos
->modes
[i
].alias
)
712 for (desc
= ttos
->modes
[i
].desc
;
713 desc
->ifmt_string
!= NULL
; desc
++) {
714 if (IFM_MODE(ifmw
) == desc
->ifmt_word
)
724 print_media_word(int ifmw
, int print_toptype
)
726 struct ifmedia_description
*desc
;
727 struct ifmedia_type_to_subtype
*ttos
;
728 int seen_option
= 0, i
;
730 /* Find the top-level interface type. */
731 desc
= get_toptype_desc(ifmw
);
732 ttos
= get_toptype_ttos(ifmw
);
733 if (desc
->ifmt_string
== NULL
) {
734 printf("<unknown type>");
737 } else if (print_toptype
) {
738 printf("%s", desc
->ifmt_string
);
743 * Don't print the top-level type; it's not like we can
744 * change it, or anything.
748 desc
= get_subtype_desc(ifmw
, ttos
);
750 printf("<unknown subtype>");
759 printf("%s", desc
->ifmt_string
);
763 desc
= get_mode_desc(ifmw
, ttos
);
764 if (desc
!= NULL
&& strcasecmp("autoselect", desc
->ifmt_string
))
765 printf(" mode %s", desc
->ifmt_string
);
769 for (i
= 0; ttos
->options
[i
].desc
!= NULL
; i
++) {
770 if (ttos
->options
[i
].alias
)
772 for (desc
= ttos
->options
[i
].desc
;
773 desc
->ifmt_string
!= NULL
; desc
++) {
774 if (ifmw
& desc
->ifmt_word
) {
775 if (seen_option
== 0)
777 printf("%s%s", seen_option
++ ? "," : "",
782 printf("%s", seen_option
? ">" : "");
785 if (print_toptype
&& IFM_INST(ifmw
) != 0)
786 printf(" instance %d", IFM_INST(ifmw
));
791 print_media_word_ifconfig(int ifmw
)
793 struct ifmedia_description
*desc
;
794 struct ifmedia_type_to_subtype
*ttos
;
797 /* Find the top-level interface type. */
798 desc
= get_toptype_desc(ifmw
);
799 ttos
= get_toptype_ttos(ifmw
);
800 if (desc
->ifmt_string
== NULL
) {
801 printf("<unknown type>");
806 * Don't print the top-level type; it's not like we can
807 * change it, or anything.
811 desc
= get_subtype_desc(ifmw
, ttos
);
813 printf("<unknown subtype>");
817 printf("media %s", desc
->ifmt_string
);
820 desc
= get_mode_desc(ifmw
, ttos
);
822 printf(" mode %s", desc
->ifmt_string
);
826 for (i
= 0; ttos
->options
[i
].desc
!= NULL
; i
++) {
827 if (ttos
->options
[i
].alias
)
829 for (desc
= ttos
->options
[i
].desc
;
830 desc
->ifmt_string
!= NULL
; desc
++) {
831 if (ifmw
& desc
->ifmt_word
) {
832 printf(" mediaopt %s", desc
->ifmt_string
);
837 if (IFM_INST(ifmw
) != 0)
838 printf(" instance %d", IFM_INST(ifmw
));
841 /**********************************************************************
843 **********************************************************************/
845 static struct cmd media_cmds
[] = {
846 DEF_CMD_ARG("media", setmedia
),
848 DEF_CMD_ARG("mode", setmediamode
),
850 DEF_CMD_ARG("mediaopt", setmediaopt
),
851 DEF_CMD_ARG("-mediaopt",unsetmediaopt
),
852 DEF_CMD_ARG("inst", setmediainst
),
853 DEF_CMD_ARG("instance", setmediainst
),
855 static struct afswtch af_media
= {
856 .af_name
= "af_media",
858 .af_other_status
= media_status
,
861 static __constructor
void
864 #define N(a) (sizeof(a) / sizeof(a[0]))
867 for (i
= 0; i
< N(media_cmds
); i
++)
868 cmd_register(&media_cmds
[i
]);
869 af_register(&af_media
);