Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 7994 | Differences between
and this patch

Collapse All | Expand All

(-)net-tools-1.60/mii-tool.c (-4 / +47 lines)
Lines 81-86 Link Here
81
81
82
struct option longopts[] = {
82
struct option longopts[] = {
83
 /* { name  has_arg  *flag  val } */
83
 /* { name  has_arg  *flag  val } */
84
    {"activate",	0, 0, 'a'},	/* Bring interface up/down when watching with -w. */
84
    {"advertise",	1, 0, 'A'},	/* Change capabilities advertised. */
85
    {"advertise",	1, 0, 'A'},	/* Change capabilities advertised. */
85
    {"force",		1, 0, 'F'},	/* Change capabilities advertised. */
86
    {"force",		1, 0, 'F'},	/* Change capabilities advertised. */
86
    {"phy",		1, 0, 'p'},	/* Set PHY (MII address) to report. */
87
    {"phy",		1, 0, 'p'},	/* Set PHY (MII address) to report. */
Lines 100-106 Link Here
100
    opt_restart = 0,
101
    opt_restart = 0,
101
    opt_reset = 0,
102
    opt_reset = 0,
102
    opt_log = 0,
103
    opt_log = 0,
103
    opt_watch = 0;
104
    opt_watch = 0,
105
    opt_activate = 0;
104
static int nway_advertise = 0;
106
static int nway_advertise = 0;
105
static int fixed_speed = 0;
107
static int fixed_speed = 0;
106
static int override_phy = -1;
108
static int override_phy = -1;
Lines 307-312 Link Here
307
309
308
/*--------------------------------------------------------------------*/
310
/*--------------------------------------------------------------------*/
309
311
312
static void interface_up(char *ifname)
313
{
314
    char cmd[128];
315
    sprintf(cmd, "/sbin/ifconfig %s | grep -q UP || /etc/init.d/net.%s start\n", ifname, ifname);
316
    system(cmd);
317
}
318
319
static void interface_down(char* ifname)
320
{
321
    char cmd[128];
322
    sprintf(cmd, "/sbin/ifconfig %s | grep -q UP && /etc/init.d/net.%s stop\n", ifname, ifname);
323
    system(cmd);
324
}
325
326
/*--------------------------------------------------------------------*/
327
310
static int do_one_xcvr(int skfd, char *ifname, int maybe)
328
static int do_one_xcvr(int skfd, char *ifname, int maybe)
311
{
329
{
312
    struct mii_data *mii = (struct mii_data *)&ifr.ifr_data;
330
    struct mii_data *mii = (struct mii_data *)&ifr.ifr_data;
Lines 347-353 Link Here
347
	mdio_write(skfd, MII_BMCR, bmcr);
365
	mdio_write(skfd, MII_BMCR, bmcr);
348
    }
366
    }
349
367
350
    if (!opt_restart && !opt_reset && !fixed_speed && !nway_advertise)
368
    if (opt_activate)
369
    {
370
	   int bmsr=mdio_read(skfd, MII_BMSR);
371
           if (bmsr & MII_BMSR_LINK_VALID)
372
               interface_up(ifname);
373
	   else
374
               interface_down(ifname);
375
    }
376
377
    if (!opt_activate && !opt_restart && !opt_reset && !fixed_speed && !nway_advertise)
351
	show_basic_mii(skfd, mii->phy_id);
378
	show_basic_mii(skfd, mii->phy_id);
352
379
353
    return 0;
380
    return 0;
Lines 372-378 Link Here
372
    now = (mdio_read(skfd, MII_BMCR) |
399
    now = (mdio_read(skfd, MII_BMCR) |
373
	   (mdio_read(skfd, MII_BMSR) << 16));
400
	   (mdio_read(skfd, MII_BMSR) << 16));
374
    if (status[index] && (status[index] != now))
401
    if (status[index] && (status[index] != now))
375
	show_basic_mii(skfd, mii->phy_id);
402
    {
403
        if (opt_activate)
404
        {
405
            int linkupnow=now & MII_BMSR_LINK_VALID<<16;
406
	    int linkupbefore=status[index] & MII_BMSR_LINK_VALID<<16;
407
	    if (linkupnow && !linkupbefore)
408
                interface_up(ifname);
409
	    else if (!linkupnow && linkupbefore)
410
		interface_down(ifname);
411
        }
412
	else
413
        {
414
            show_basic_mii(skfd, mii->phy_id);
415
        }
416
    }
376
    status[index] = now;
417
    status[index] = now;
377
}
418
}
378
419
Lines 386-391 Link Here
386
       -r, --restart               restart autonegotiation
427
       -r, --restart               restart autonegotiation
387
       -w, --watch                 monitor for link status changes
428
       -w, --watch                 monitor for link status changes
388
       -l, --log                   with -w, write events to syslog
429
       -l, --log                   with -w, write events to syslog
430
       -a, --activate              with -w, activate (or deactivate) interface
389
       -A, --advertise=media,...   advertise only specified media
431
       -A, --advertise=media,...   advertise only specified media
390
       -F, --force=media           force specified media technology
432
       -F, --force=media           force specified media technology
391
media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,
433
media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,
Lines 396-403 Link Here
396
    int i, c, ret, errflag = 0;
438
    int i, c, ret, errflag = 0;
397
    char s[6];
439
    char s[6];
398
    
440
    
399
    while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF)
441
    while ((c = getopt_long(argc, argv, "A:F:p:alrRvVw?", longopts, 0)) != EOF)
400
	switch (c) {
442
	switch (c) {
443
	case 'a': opt_activate++;	break;
401
	case 'A': nway_advertise = parse_media(optarg); break;
444
	case 'A': nway_advertise = parse_media(optarg); break;
402
	case 'F': fixed_speed = parse_media(optarg); break;
445
	case 'F': fixed_speed = parse_media(optarg); break;
403
	case 'p': override_phy = atoi(optarg); break;
446
	case 'p': override_phy = atoi(optarg); break;

Return to bug 7994