📄 mii-tool.c,v
字号:
/*--------------------------------------------------------------------*/static int do_one_xcvr(int skfd, char *ifname, int maybe){ struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; /* Get the vitals from the interface. */ strncpy(ifr.ifr_name, ifname, IFNAMSIZ); if (ioctl(skfd, SIOCGMIIPHY, &ifr) < 0) { if (!maybe || (errno != ENODEV)) fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n", ifname, strerror(errno)); return 1; } if (override_phy >= 0) { printf("using the specified MII index %d.\n", override_phy); mii->phy_id = override_phy; } if (opt_reset) { printf("resetting the transceiver...\n"); mdio_write(skfd, MII_BMCR, MII_BMCR_RESET); } if (nway_advertise) { mdio_write(skfd, MII_ANAR, nway_advertise | 1); opt_restart = 1; } if (opt_restart) { printf("restarting autonegotiation...\n"); mdio_write(skfd, MII_BMCR, 0x0000); mdio_write(skfd, MII_BMCR, MII_BMCR_AN_ENA|MII_BMCR_RESTART); } if (fixed_speed) { int bmcr = 0; if (fixed_speed & (MII_AN_100BASETX_FD|MII_AN_100BASETX_HD)) bmcr |= MII_BMCR_100MBIT; if (fixed_speed & (MII_AN_100BASETX_FD|MII_AN_10BASET_FD)) bmcr |= MII_BMCR_DUPLEX; mdio_write(skfd, MII_BMCR, bmcr); } if (!opt_restart && !opt_reset && !fixed_speed && !nway_advertise) show_basic_mii(skfd, mii->phy_id); return 0;}/*--------------------------------------------------------------------*/static void watch_one_xcvr(int skfd, char *ifname, int index){ struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; static int status[MAX_ETH] = { 0, /* ... */ }; int now; /* Get the vitals from the interface. */ strncpy(ifr.ifr_name, ifname, IFNAMSIZ); if (ioctl(skfd, SIOCGMIIPHY, &ifr) < 0) { if (errno != ENODEV) fprintf(stderr, "SIOCGMIIPHY on '%s' failed: %s\n", ifname, strerror(errno)); return; } now = (mdio_read(skfd, MII_BMCR) | (mdio_read(skfd, MII_BMSR) << 16)); if (status[index] && (status[index] != now)) show_basic_mii(skfd, mii->phy_id); status[index] = now;}/*--------------------------------------------------------------------*/const char *usage ="usage: %s [-VvRrwl] [-A media,... | -F media] [interface ...] -V, --version display version information -v, --verbose more verbose output -R, --reset reset MII to poweron state -r, --restart restart autonegotiation -w, --watch monitor for link status changes -l, --log with -w, write events to syslog -A, --advertise=media,... advertise only specified media -F, --force=media force specified media technologymedia: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD, (to advertise both HD and FD) 100baseTx, 10baseT\n";int main(int argc, char **argv){ int i, c, ret, errflag = 0; char s[6]; while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF) switch (c) { case 'A': nway_advertise = parse_media(optarg); break; case 'F': fixed_speed = parse_media(optarg); break; case 'p': override_phy = atoi(optarg); break; case 'r': opt_restart++; break; case 'R': opt_reset++; break; case 'v': verbose++; break; case 'V': opt_version++; break; case 'w': opt_watch++; break; case 'l': opt_log++; break; case '?': errflag++; } /* Check for a few inappropriate option combinations */ if (opt_watch) verbose = 0; if (errflag || (fixed_speed & (fixed_speed-1)) || (fixed_speed && (opt_restart || nway_advertise))) { fprintf(stderr, usage, argv[0]); return 2; } if (opt_version) printf(version); /* Open a basic socket. */ if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) { perror("socket"); exit(-1); } /* No remaining args means show all interfaces. */ if (optind == argc) { ret = 1; for (i = 0; i < MAX_ETH; i++) { sprintf(s, "eth%d", i); ret &= do_one_xcvr(skfd, s, 1); } if (ret) fprintf(stderr, "no MII interfaces found\n"); } else { ret = 0; for (i = optind; i < argc; i++) { ret |= do_one_xcvr(skfd, argv[i], 0); } } if (opt_watch && (ret == 0)) { while (1) { sleep(1); if (optind == argc) { for (i = 0; i < MAX_ETH; i++) { sprintf(s, "eth%d", i); watch_one_xcvr(skfd, s, i); } } else { for (i = optind; i < argc; i++) watch_one_xcvr(skfd, argv[i], i-optind); } } } close(skfd); return ret;}@1.9log@*** empty log message ***@text@d33 1a33 1"mii-tool.c $Revision: 1.8 $ $Date: 2000/04/25 23:48:20 $ (David Hinds)\n";d72 4a75 1 { 0x7810, 0x0000, "Level One LXT970/971" },@1.8log@*** empty log message ***@text@d33 1a33 1"mii-tool.c $Revision: 1.7 $ $Date: 2000/04/25 22:58:19 $ (David Hinds)\n";d382 1a382 1"usage: %s [-VvRrw] [-A media,... | -F media] [interface ...]d388 1a390 1 -l, --log with -w, write events to syslog@1.7log@*** empty log message ***@text@d33 1a33 1"mii-tool.c $Revision: 1.6 $ $Date: 2000/04/25 22:06:05 $ (David Hinds)\n";d62 4d67 1@1.6log@*** empty log message ***@text@d33 1a33 1"mii-tool.c $Revision: 1.5 $ $Date: 2000/04/11 19:53:55 $ (David Hinds)\n";d43 2d80 1d82 1a84 1 {"help", 0, 0, '?'}, /* Give help */d88 1d97 1d177 1a177 1static void show_media(int mask, int best)d179 1d181 1d185 2a186 1 printf(" %s", media[i].name);d191 2a192 1 printf(" flow-control");d197 1d208 1a208 1 printf(" No MII transceiver present!.\n");d216 1a216 1 printf("%s: ", ifr.ifr_name);d220 1a220 1 printf((lkpar & MII_AN_ACK) ?d222 2a223 2 show_media(advert & lkpar, 1); printf(", ");d225 1a225 1 printf("autonegotiation failed, ");d228 1a228 1 printf("autonegotiation restarted, ");d231 1a231 1 printf("%s Mbit, %s duplex, ",d235 14a248 2 printf((bmsr & MII_BMSR_LINK_VALID) ? "link ok" : "no link"); printf("\n");d294 4a297 8 printf("\n capabilities:"); show_media(bmsr >> 6, 0); printf("\n advertising: "); show_media(advert, 0); if (lkpar & MII_AN_ABILITY_MASK) { printf("\n link partner:"); show_media(lkpar, 0); }d385 1d394 1a394 1 while ((c = getopt_long(argc, argv, "A:F:p:rRvVw?", longopts, 0)) != EOF)d404 1d408 1@1.5log@*** empty log message ***@text@d7 1a7 1 mii-diag [-VvRrw] [-A media,... | -F media] [interface ...]d14 3a16 3 mii-diag is written/copyright 1997-1999 by Donald Becker <becker@@cesdis.gsfc.nasa.gov>d22 3a24 3 Donald Becker may be reached as becker@@CESDIS.gsfc.nasa.gov, or C/O Center of Excellence in Space Data and Information Sciences Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771d27 2a28 1 http://cesdis.gsfc.nasa.gov/linux/misc/NWay.htmld33 1a33 1"mii-tool.c $Revision: 1.4 $ $Date: 2000/04/10 20:35:24 $ (David Hinds)\n";@1.4log@*** empty log message ***@text@d32 1a32 1"mii-tool.c $Revision: 1.3 $ $Date: 2000/03/31 22:40:37 $ (David Hinds)\n";d182 1a182 1 printf(" flow control");@1.3log@*** empty log message ***@text@d32 1a32 1"mii-tool.c $Revision: 1.2 $ $Date: 2000/03/28 20:49:59 $ (David Hinds)\n";a51 3typedef unsigned short u16;typedef unsigned int u32;d56 1a56 1 u16 id1, id2;d129 1a129 1 u16 value;@1.2log@*** empty log message ***@text@d32 1a32 1"mii-tool.c $Revision: 1.1 $ $Date: 2000/03/28 20:46:54 $ (David Hinds)\n";d57 20d90 1a90 2/* Command-line flags. */unsigned intd100 2a101 2int skfd = -1; /* AF_INET socket for ioctl() calls. */struct ifreq ifr;d238 12a249 4 printf(" vendor info: id %02x:%02x:%02x, model %d rev %d\n", mii_val[2]>>10, (mii_val[2]>>2)&0xff, ((mii_val[2]<<6)|(mii_val[3]>>10))&0xff, (mii_val[3]>>4)&0x3f, mii_val[3]&0x0f);@1.1log@Initial revision@text@d32 1a32 1"mii-tool.c $Revision$ $Date$ (David Hinds)\n";d161 1a161 1 printf(" %s", media[i]);a264 1 int i;@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -