static void setmedia(const char *val, int d, int s, const struct afswtch *afp) { struct ifmediareq *ifmr; int subtype; ifmr = ifmedia_getstate(s); /* * We are primarily concerned with the top-level type. * However, "current" may be only IFM_NONE, so we just look * for the top-level type in the first "supported type" * entry. * * (I'm assuming that all supported media types for a given * interface will be the same top-level type..) */ subtype = get_media_subtype(IFM_TYPE(ifmr->ifm_ulist[0]), val); strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & ~(IFM_NMASK|IFM_TMASK)) | IFM_TYPE(ifmr->ifm_ulist[0]) | subtype; if ((ifr.ifr_media & IFM_TMASK) == 0) { ifr.ifr_media &= ~(IFM_GMASK | IFM_OMASK); } ifmr->ifm_current = ifr.ifr_media; callback_register(setifmediacallback, (void *)ifmr); }
static void set_port_media(struct cfg *cfg, char *argv[]) { etherswitch_port_t p; int ifm_ulist[IFMEDIAREQ_NULISTENTRIES]; int subtype; bzero(&p, sizeof(p)); p.es_port = cfg->unit; p.es_ifmr.ifm_ulist = ifm_ulist; p.es_ifmr.ifm_count = IFMEDIAREQ_NULISTENTRIES; if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0) err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)"); subtype = get_media_subtype(IFM_TYPE(ifm_ulist[0]), argv[1]); p.es_ifr.ifr_media = (p.es_ifmr.ifm_current & IFM_IMASK) | IFM_TYPE(ifm_ulist[0]) | subtype; if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0) err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)"); }
int intmedia(char *ifname, int ifs, int argc, char **argv) { const char *errmsg = NULL; uint64_t set, media_current, type, subtype, inst; if (NO_ARG(argv[0])) { set = 0; argc--; argv++; } else set = 1; argv++; argc--; if ((set && (argc < 1 || argc > 2)) || (!set && argc > 2)) { printf("%% media <type> [instance]\n"); printf("%% no media [type] [instance]\n"); media_supported(ifs, ifname, "% ", "% "); return(0); } media_current = init_current_media(ifs, ifname); if (media_current == -1) { if (errno == EINVAL) printf("%% This device does not support " "media commands.\n"); else printf("%% Failed to initialize media: %s\n", strerror(errno)); return(0); } if (argc == 2) { inst = strtonum(argv[1], 0, IFM_INST_MAX, &errmsg); if (errmsg) { printf("%% Invalid media instance: %s: %s\n", argv[1], errmsg); return(0); } } else { inst = IFM_INST(media_current); } type = IFM_TYPE(media_current); /* Look up the subtype */ if (set) subtype = get_media_subtype(type, argv[0]); else subtype = get_media_subtype(type, DEFAULT_MEDIA_TYPE); if (subtype == -1) return(0); /* Build the new media_current word */ media_current = IFM_MAKEWORD(type, subtype, 0, inst); process_media_commands(ifs, ifname, media_current); return(0); }