1 /* $NetBSD: ifconfig.c,v 1.34 1997/04/21 01:17:58 lukem 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 *);
94 static int get_media_mode(int, const char *);
95 static int get_media_options(int, const char *);
96 static int lookup_media_word(struct ifmedia_description *, const char *);
97 static void print_media_word(int, int);
98 static void print_media_word_ifconfig(int);
100 static struct ifmedia_description *get_toptype_desc(int);
101 static struct ifmedia_type_to_subtype *get_toptype_ttos(int);
102 static struct ifmedia_description *get_subtype_desc(int,
103 struct ifmedia_type_to_subtype *ttos);
105 #define IFM_OPMODE(x) \
106 ((x) & (IFM_IEEE80211_ADHOC | IFM_IEEE80211_HOSTAP | \
107 IFM_IEEE80211_IBSS | IFM_IEEE80211_WDS | IFM_IEEE80211_MONITOR))
108 #define IFM_IEEE80211_STA 0
113 struct ifmediareq ifmr;
116 (void) memset(&ifmr, 0, sizeof(ifmr));
117 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
119 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
121 * Interface doesn't support SIOC{G,S}IFMEDIA.
126 if (ifmr.ifm_count == 0) {
127 warnx("%s: no media types?", name);
131 media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
132 if (media_list == NULL)
134 ifmr.ifm_ulist = media_list;
136 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
137 err(1, "SIOCGIFMEDIA");
140 print_media_word(ifmr.ifm_current, 1);
141 if (ifmr.ifm_active != ifmr.ifm_current) {
144 print_media_word(ifmr.ifm_active, 0);
150 if (ifmr.ifm_status & IFM_AVALID) {
151 printf("\tstatus: ");
152 switch (IFM_TYPE(ifmr.ifm_active)) {
155 if (ifmr.ifm_status & IFM_ACTIVE)
158 printf("no carrier");
163 if (ifmr.ifm_status & IFM_ACTIVE)
170 if (ifmr.ifm_status & IFM_ACTIVE) {
171 /* NB: only sta mode associates */
172 if (IFM_OPMODE(ifmr.ifm_active) == IFM_IEEE80211_STA)
173 printf("associated");
177 printf("no carrier");
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, SIOCGIFMEDIA, (caddr_t)ifmr) < 0) {
220 err(1, "SIOCGIFMEDIA");
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, SIOCGIFMEDIA, (caddr_t)ifmr) < 0)
232 err(1, "SIOCGIFMEDIA");
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);
344 setmediamode(const char *val, int d, int s, const struct afswtch *afp)
346 struct ifmediareq *ifmr;
349 ifmr = ifmedia_getstate(s);
351 mode = get_media_mode(IFM_TYPE(ifmr->ifm_ulist[0]), val);
353 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
354 ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode;
356 ifmr->ifm_current = ifr.ifr_media;
357 callback_register(setifmediacallback, (void *)ifmr);
360 /**********************************************************************
361 * A good chunk of this is duplicated from sys/net/ifmedia.c
362 **********************************************************************/
364 static struct ifmedia_description ifm_type_descriptions[] =
365 IFM_TYPE_DESCRIPTIONS;
367 static struct ifmedia_description ifm_subtype_ethernet_descriptions[] =
368 IFM_SUBTYPE_ETHERNET_DESCRIPTIONS;
370 static struct ifmedia_description ifm_subtype_ethernet_aliases[] =
371 IFM_SUBTYPE_ETHERNET_ALIASES;
373 static struct ifmedia_description ifm_subtype_ethernet_option_descriptions[] =
374 IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS;
376 static struct ifmedia_description ifm_subtype_tokenring_descriptions[] =
377 IFM_SUBTYPE_TOKENRING_DESCRIPTIONS;
379 static struct ifmedia_description ifm_subtype_tokenring_aliases[] =
380 IFM_SUBTYPE_TOKENRING_ALIASES;
382 static struct ifmedia_description ifm_subtype_tokenring_option_descriptions[] =
383 IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS;
385 static struct ifmedia_description ifm_subtype_fddi_descriptions[] =
386 IFM_SUBTYPE_FDDI_DESCRIPTIONS;
388 static struct ifmedia_description ifm_subtype_fddi_aliases[] =
389 IFM_SUBTYPE_FDDI_ALIASES;
391 static struct ifmedia_description ifm_subtype_fddi_option_descriptions[] =
392 IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS;
394 static struct ifmedia_description ifm_subtype_ieee80211_descriptions[] =
395 IFM_SUBTYPE_IEEE80211_DESCRIPTIONS;
397 static struct ifmedia_description ifm_subtype_ieee80211_aliases[] =
398 IFM_SUBTYPE_IEEE80211_ALIASES;
400 static struct ifmedia_description ifm_subtype_ieee80211_option_descriptions[] =
401 IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS;
403 struct ifmedia_description ifm_subtype_ieee80211_mode_descriptions[] =
404 IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS;
406 struct ifmedia_description ifm_subtype_ieee80211_mode_aliases[] =
407 IFM_SUBTYPE_IEEE80211_MODE_ALIASES;
409 static struct ifmedia_description ifm_subtype_atm_descriptions[] =
410 IFM_SUBTYPE_ATM_DESCRIPTIONS;
412 static struct ifmedia_description ifm_subtype_atm_aliases[] =
413 IFM_SUBTYPE_ATM_ALIASES;
415 static struct ifmedia_description ifm_subtype_atm_option_descriptions[] =
416 IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS;
418 static struct ifmedia_description ifm_subtype_shared_descriptions[] =
419 IFM_SUBTYPE_SHARED_DESCRIPTIONS;
421 static struct ifmedia_description ifm_subtype_shared_aliases[] =
422 IFM_SUBTYPE_SHARED_ALIASES;
424 static struct ifmedia_description ifm_shared_option_descriptions[] =
425 IFM_SHARED_OPTION_DESCRIPTIONS;
427 struct ifmedia_type_to_subtype {
429 struct ifmedia_description *desc;
433 struct ifmedia_description *desc;
437 struct ifmedia_description *desc;
442 /* must be in the same order as IFM_TYPE_DESCRIPTIONS */
443 static struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = {
446 { &ifm_subtype_shared_descriptions[0], 0 },
447 { &ifm_subtype_shared_aliases[0], 1 },
448 { &ifm_subtype_ethernet_descriptions[0], 0 },
449 { &ifm_subtype_ethernet_aliases[0], 1 },
453 { &ifm_shared_option_descriptions[0], 0 },
454 { &ifm_subtype_ethernet_option_descriptions[0], 0 },
463 { &ifm_subtype_shared_descriptions[0], 0 },
464 { &ifm_subtype_shared_aliases[0], 1 },
465 { &ifm_subtype_tokenring_descriptions[0], 0 },
466 { &ifm_subtype_tokenring_aliases[0], 1 },
470 { &ifm_shared_option_descriptions[0], 0 },
471 { &ifm_subtype_tokenring_option_descriptions[0], 0 },
480 { &ifm_subtype_shared_descriptions[0], 0 },
481 { &ifm_subtype_shared_aliases[0], 1 },
482 { &ifm_subtype_fddi_descriptions[0], 0 },
483 { &ifm_subtype_fddi_aliases[0], 1 },
487 { &ifm_shared_option_descriptions[0], 0 },
488 { &ifm_subtype_fddi_option_descriptions[0], 0 },
497 { &ifm_subtype_shared_descriptions[0], 0 },
498 { &ifm_subtype_shared_aliases[0], 1 },
499 { &ifm_subtype_ieee80211_descriptions[0], 0 },
500 { &ifm_subtype_ieee80211_aliases[0], 1 },
504 { &ifm_shared_option_descriptions[0], 0 },
505 { &ifm_subtype_ieee80211_option_descriptions[0], 0 },
509 { &ifm_subtype_ieee80211_mode_descriptions[0], 0 },
510 { &ifm_subtype_ieee80211_mode_aliases[0], 0 },
516 { &ifm_subtype_shared_descriptions[0], 0 },
517 { &ifm_subtype_shared_aliases[0], 1 },
518 { &ifm_subtype_atm_descriptions[0], 0 },
519 { &ifm_subtype_atm_aliases[0], 1 },
523 { &ifm_shared_option_descriptions[0], 0 },
524 { &ifm_subtype_atm_option_descriptions[0], 0 },
534 get_media_subtype(int type, const char *val)
536 struct ifmedia_description *desc;
537 struct ifmedia_type_to_subtype *ttos;
540 /* Find the top-level interface type. */
541 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
542 desc->ifmt_string != NULL; desc++, ttos++)
543 if (type == desc->ifmt_word)
545 if (desc->ifmt_string == NULL)
546 errx(1, "unknown media type 0x%x", type);
548 for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
549 rval = lookup_media_word(ttos->subtypes[i].desc, val);
553 errx(1, "unknown media subtype: %s", val);
558 get_media_mode(int type, const char *val)
560 struct ifmedia_description *desc;
561 struct ifmedia_type_to_subtype *ttos;
564 /* Find the top-level interface type. */
565 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
566 desc->ifmt_string != NULL; desc++, ttos++)
567 if (type == desc->ifmt_word)
569 if (desc->ifmt_string == NULL)
570 errx(1, "unknown media mode 0x%x", type);
572 for (i = 0; ttos->modes[i].desc != NULL; i++) {
573 rval = lookup_media_word(ttos->modes[i].desc, val);
581 get_media_options(int type, const char *val)
583 struct ifmedia_description *desc;
584 struct ifmedia_type_to_subtype *ttos;
585 char *optlist, *optptr;
586 int option = 0, i, rval = 0;
588 /* We muck with the string, so copy it. */
589 optlist = strdup(val);
593 /* Find the top-level interface type. */
594 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
595 desc->ifmt_string != NULL; desc++, ttos++)
596 if (type == desc->ifmt_word)
598 if (desc->ifmt_string == NULL)
599 errx(1, "unknown media type 0x%x", type);
602 * Look up the options in the user-provided comma-separated
606 for (; (optptr = strtok(optptr, ",")) != NULL; optptr = NULL) {
607 for (i = 0; ttos->options[i].desc != NULL; i++) {
608 option = lookup_media_word(ttos->options[i].desc, optptr);
613 errx(1, "unknown option: %s", optptr);
622 lookup_media_word(struct ifmedia_description *desc, const char *val)
625 for (; desc->ifmt_string != NULL; desc++)
626 if (strcasecmp(desc->ifmt_string, val) == 0)
627 return (desc->ifmt_word);
632 static struct ifmedia_description *get_toptype_desc(int ifmw)
634 struct ifmedia_description *desc;
636 for (desc = ifm_type_descriptions; desc->ifmt_string != NULL; desc++)
637 if (IFM_TYPE(ifmw) == desc->ifmt_word)
643 static struct ifmedia_type_to_subtype *get_toptype_ttos(int ifmw)
645 struct ifmedia_description *desc;
646 struct ifmedia_type_to_subtype *ttos;
648 for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes;
649 desc->ifmt_string != NULL; desc++, ttos++)
650 if (IFM_TYPE(ifmw) == desc->ifmt_word)
656 static struct ifmedia_description *get_subtype_desc(int ifmw,
657 struct ifmedia_type_to_subtype *ttos)
660 struct ifmedia_description *desc;
662 for (i = 0; ttos->subtypes[i].desc != NULL; i++) {
663 if (ttos->subtypes[i].alias)
665 for (desc = ttos->subtypes[i].desc;
666 desc->ifmt_string != NULL; desc++) {
667 if (IFM_SUBTYPE(ifmw) == desc->ifmt_word)
675 static struct ifmedia_description *get_mode_desc(int ifmw,
676 struct ifmedia_type_to_subtype *ttos)
679 struct ifmedia_description *desc;
681 for (i = 0; ttos->modes[i].desc != NULL; i++) {
682 if (ttos->modes[i].alias)
684 for (desc = ttos->modes[i].desc;
685 desc->ifmt_string != NULL; desc++) {
686 if (IFM_MODE(ifmw) == desc->ifmt_word)
695 print_media_word(int ifmw, int print_toptype)
697 struct ifmedia_description *desc;
698 struct ifmedia_type_to_subtype *ttos;
699 int seen_option = 0, i;
701 /* Find the top-level interface type. */
702 desc = get_toptype_desc(ifmw);
703 ttos = get_toptype_ttos(ifmw);
704 if (desc->ifmt_string == NULL) {
705 printf("<unknown type>");
707 } else if (print_toptype) {
708 printf("%s", desc->ifmt_string);
712 * Don't print the top-level type; it's not like we can
713 * change it, or anything.
717 desc = get_subtype_desc(ifmw, ttos);
719 printf("<unknown subtype>");
726 printf("%s", desc->ifmt_string);
729 desc = get_mode_desc(ifmw, ttos);
730 if (desc != NULL && strcasecmp("autoselect", desc->ifmt_string))
731 printf(" mode %s", desc->ifmt_string);
735 for (i = 0; ttos->options[i].desc != NULL; i++) {
736 if (ttos->options[i].alias)
738 for (desc = ttos->options[i].desc;
739 desc->ifmt_string != NULL; desc++) {
740 if (ifmw & desc->ifmt_word) {
741 if (seen_option == 0)
743 printf("%s%s", seen_option++ ? "," : "",
748 printf("%s", seen_option ? ">" : "");
750 if (print_toptype && IFM_INST(ifmw) != 0)
751 printf(" instance %d", IFM_INST(ifmw));
755 print_media_word_ifconfig(int ifmw)
757 struct ifmedia_description *desc;
758 struct ifmedia_type_to_subtype *ttos;
761 /* Find the top-level interface type. */
762 desc = get_toptype_desc(ifmw);
763 ttos = get_toptype_ttos(ifmw);
764 if (desc->ifmt_string == NULL) {
765 printf("<unknown type>");
770 * Don't print the top-level type; it's not like we can
771 * change it, or anything.
775 desc = get_subtype_desc(ifmw, ttos);
777 printf("<unknown subtype>");
781 printf("media %s", desc->ifmt_string);
783 desc = get_mode_desc(ifmw, ttos);
785 printf(" mode %s", desc->ifmt_string);
788 for (i = 0; ttos->options[i].desc != NULL; i++) {
789 if (ttos->options[i].alias)
791 for (desc = ttos->options[i].desc;
792 desc->ifmt_string != NULL; desc++) {
793 if (ifmw & desc->ifmt_word) {
794 printf(" mediaopt %s", desc->ifmt_string);
799 if (IFM_INST(ifmw) != 0)
800 printf(" instance %d", IFM_INST(ifmw));
803 /**********************************************************************
805 **********************************************************************/
807 static struct cmd media_cmds[] = {
808 DEF_CMD_ARG("media", setmedia),
809 DEF_CMD_ARG("mode", setmediamode),
810 DEF_CMD_ARG("mediaopt", setmediaopt),
811 DEF_CMD_ARG("-mediaopt",unsetmediaopt),
812 DEF_CMD_ARG("inst", setmediainst),
813 DEF_CMD_ARG("instance", setmediainst),
815 static struct afswtch af_media = {
816 .af_name = "af_media",
818 .af_other_status = media_status,
821 static __constructor void
824 #define N(a) (sizeof(a) / sizeof(a[0]))
827 for (i = 0; i < N(media_cmds); i++)
828 cmd_register(&media_cmds[i]);
829 af_register(&af_media);