Lines 15-20
Link Here
|
15 |
mii-diag is written/copyright 1997-2000 by Donald Becker |
15 |
mii-diag is written/copyright 1997-2000 by Donald Becker |
16 |
<becker@scyld.com> |
16 |
<becker@scyld.com> |
17 |
|
17 |
|
|
|
18 |
activate patch is written 2002 by Pat Double |
19 |
<double@inebraska.com> |
20 |
|
18 |
This program is free software; you can redistribute it |
21 |
This program is free software; you can redistribute it |
19 |
and/or modify it under the terms of the GNU General Public |
22 |
and/or modify it under the terms of the GNU General Public |
20 |
License as published by the Free Software Foundation. |
23 |
License as published by the Free Software Foundation. |
Lines 51-56
Link Here
|
51 |
#include <linux/if_ether.h> |
54 |
#include <linux/if_ether.h> |
52 |
#endif |
55 |
#endif |
53 |
#include "mii.h" |
56 |
#include "mii.h" |
|
|
57 |
#include "interface.h" |
58 |
#include "sockets.h" |
54 |
|
59 |
|
55 |
#define MAX_ETH 8 /* Maximum # of interfaces */ |
60 |
#define MAX_ETH 8 /* Maximum # of interfaces */ |
56 |
|
61 |
|
Lines 81-86
Link Here
|
81 |
|
86 |
|
82 |
struct option longopts[] = { |
87 |
struct option longopts[] = { |
83 |
/* { name has_arg *flag val } */ |
88 |
/* { name has_arg *flag val } */ |
|
|
89 |
{"activate", 1, 0, 'a'}, /* Bring interface up/down when watching with -w. */ |
84 |
{"advertise", 1, 0, 'A'}, /* Change capabilities advertised. */ |
90 |
{"advertise", 1, 0, 'A'}, /* Change capabilities advertised. */ |
85 |
{"force", 1, 0, 'F'}, /* Change capabilities advertised. */ |
91 |
{"force", 1, 0, 'F'}, /* Change capabilities advertised. */ |
86 |
{"phy", 1, 0, 'p'}, /* Set PHY (MII address) to report. */ |
92 |
{"phy", 1, 0, 'p'}, /* Set PHY (MII address) to report. */ |
Lines 100-111
Link Here
|
100 |
opt_restart = 0, |
106 |
opt_restart = 0, |
101 |
opt_reset = 0, |
107 |
opt_reset = 0, |
102 |
opt_log = 0, |
108 |
opt_log = 0, |
103 |
opt_watch = 0; |
109 |
opt_watch = 0, |
|
|
110 |
opt_activate = 0; |
104 |
static int nway_advertise = 0; |
111 |
static int nway_advertise = 0; |
105 |
static int fixed_speed = 0; |
112 |
static int fixed_speed = 0; |
106 |
static int override_phy = -1; |
113 |
static int override_phy = -1; |
|
|
114 |
static char* activate_script = 0; |
107 |
|
115 |
|
108 |
static int skfd = -1; /* AF_INET socket for ioctl() calls. */ |
116 |
static int skfd_mii = -1; /* AF_INET socket for ioctl() calls. */ |
109 |
static struct ifreq ifr; |
117 |
static struct ifreq ifr; |
110 |
|
118 |
|
111 |
/*--------------------------------------------------------------------*/ |
119 |
/*--------------------------------------------------------------------*/ |
Lines 307-312
Link Here
|
307 |
|
315 |
|
308 |
/*--------------------------------------------------------------------*/ |
316 |
/*--------------------------------------------------------------------*/ |
309 |
|
317 |
|
|
|
318 |
static void interface_cmd(char *ifname, char *start_or_stop) |
319 |
{ |
320 |
char cmd[128]; |
321 |
int pos; |
322 |
|
323 |
pos=snprintf(cmd, 128, activate_script, ifname); |
324 |
|
325 |
if (pos<127) |
326 |
{ |
327 |
strcat(cmd, " "); |
328 |
pos++; |
329 |
} |
330 |
|
331 |
if ((pos+strlen(start_or_stop)) < 127 ) |
332 |
strcat(cmd, start_or_stop); |
333 |
|
334 |
system(cmd); |
335 |
} |
336 |
|
337 |
static void interface_up(char *ifname) |
338 |
{ |
339 |
struct interface *ife; |
340 |
|
341 |
ife=lookup_interface(ifname); |
342 |
if (!ife) return; |
343 |
if (do_if_fetch(ife) < 0) return; |
344 |
|
345 |
if ((ife->flags & IFF_UP)==0) |
346 |
interface_cmd(ifname, "start"); |
347 |
} |
348 |
|
349 |
static void interface_down(char* ifname) |
350 |
{ |
351 |
struct interface *ife; |
352 |
|
353 |
ife=lookup_interface(ifname); |
354 |
if (!ife) return; |
355 |
if (do_if_fetch(ife) < 0) return; |
356 |
|
357 |
if ((ife->flags & IFF_UP)!=0) |
358 |
interface_cmd(ifname, "stop"); |
359 |
} |
360 |
|
361 |
/*--------------------------------------------------------------------*/ |
362 |
|
310 |
static int do_one_xcvr(int skfd, char *ifname, int maybe) |
363 |
static int do_one_xcvr(int skfd, char *ifname, int maybe) |
311 |
{ |
364 |
{ |
312 |
struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; |
365 |
struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; |
Lines 347-353
Link Here
|
347 |
mdio_write(skfd, MII_BMCR, bmcr); |
400 |
mdio_write(skfd, MII_BMCR, bmcr); |
348 |
} |
401 |
} |
349 |
|
402 |
|
350 |
if (!opt_restart && !opt_reset && !fixed_speed && !nway_advertise) |
403 |
if (opt_activate) |
|
|
404 |
{ |
405 |
int bmsr=mdio_read(skfd, MII_BMSR); |
406 |
if (bmsr & MII_BMSR_LINK_VALID) |
407 |
interface_up(ifname); |
408 |
else |
409 |
interface_down(ifname); |
410 |
} |
411 |
|
412 |
if (!opt_activate && !opt_restart && !opt_reset && !fixed_speed && !nway_advertise) |
351 |
show_basic_mii(skfd, mii->phy_id); |
413 |
show_basic_mii(skfd, mii->phy_id); |
352 |
|
414 |
|
353 |
return 0; |
415 |
return 0; |
Lines 372-378
Link Here
|
372 |
now = (mdio_read(skfd, MII_BMCR) | |
434 |
now = (mdio_read(skfd, MII_BMCR) | |
373 |
(mdio_read(skfd, MII_BMSR) << 16)); |
435 |
(mdio_read(skfd, MII_BMSR) << 16)); |
374 |
if (status[index] && (status[index] != now)) |
436 |
if (status[index] && (status[index] != now)) |
375 |
show_basic_mii(skfd, mii->phy_id); |
437 |
{ |
|
|
438 |
if (opt_activate) |
439 |
{ |
440 |
int linkupnow=now & MII_BMSR_LINK_VALID<<16; |
441 |
int linkupbefore=status[index] & MII_BMSR_LINK_VALID<<16; |
442 |
if (linkupnow && !linkupbefore) |
443 |
interface_up(ifname); |
444 |
else if (!linkupnow && linkupbefore) |
445 |
interface_down(ifname); |
446 |
} |
447 |
else |
448 |
{ |
449 |
show_basic_mii(skfd, mii->phy_id); |
450 |
} |
451 |
} |
376 |
status[index] = now; |
452 |
status[index] = now; |
377 |
} |
453 |
} |
378 |
|
454 |
|
Lines 386-391
Link Here
|
386 |
-r, --restart restart autonegotiation |
462 |
-r, --restart restart autonegotiation |
387 |
-w, --watch monitor for link status changes |
463 |
-w, --watch monitor for link status changes |
388 |
-l, --log with -w, write events to syslog |
464 |
-l, --log with -w, write events to syslog |
|
|
465 |
-a, --activate=initscript with -w, activate (or deactivate) interface |
466 |
using the given init script (interface in %s) |
389 |
-A, --advertise=media,... advertise only specified media |
467 |
-A, --advertise=media,... advertise only specified media |
390 |
-F, --force=media force specified media technology |
468 |
-F, --force=media force specified media technology |
391 |
media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD, |
469 |
media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD, |
Lines 396-403
Link Here
|
396 |
int i, c, ret, errflag = 0; |
474 |
int i, c, ret, errflag = 0; |
397 |
char s[6]; |
475 |
char s[6]; |
398 |
|
476 |
|
399 |
while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF) |
477 |
while ((c = getopt_long(argc, argv, "A:F:p:a:lrRvVw?", longopts, 0)) != EOF) |
400 |
switch (c) { |
478 |
switch (c) { |
|
|
479 |
case 'a': |
480 |
opt_activate++; |
481 |
activate_script=malloc(strlen(optarg)+1); |
482 |
if (activate_script) |
483 |
strcpy(activate_script, optarg); |
484 |
break; |
401 |
case 'A': nway_advertise = parse_media(optarg); break; |
485 |
case 'A': nway_advertise = parse_media(optarg); break; |
402 |
case 'F': fixed_speed = parse_media(optarg); break; |
486 |
case 'F': fixed_speed = parse_media(optarg); break; |
403 |
case 'p': override_phy = atoi(optarg); break; |
487 |
case 'p': override_phy = atoi(optarg); break; |
Lines 420-427
Link Here
|
420 |
if (opt_version) |
504 |
if (opt_version) |
421 |
printf(version); |
505 |
printf(version); |
422 |
|
506 |
|
|
|
507 |
/* Open the socket for the library. */ |
508 |
if ((skfd = sockets_open(0)) < 0) { |
509 |
perror("socket"); |
510 |
exit(1); |
511 |
} |
512 |
|
423 |
/* Open a basic socket. */ |
513 |
/* Open a basic socket. */ |
424 |
if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) { |
514 |
if ((skfd_mii = socket(AF_INET, SOCK_DGRAM,0)) < 0) { |
425 |
perror("socket"); |
515 |
perror("socket"); |
426 |
exit(-1); |
516 |
exit(-1); |
427 |
} |
517 |
} |
Lines 431-444
Link Here
|
431 |
ret = 1; |
521 |
ret = 1; |
432 |
for (i = 0; i < MAX_ETH; i++) { |
522 |
for (i = 0; i < MAX_ETH; i++) { |
433 |
sprintf(s, "eth%d", i); |
523 |
sprintf(s, "eth%d", i); |
434 |
ret &= do_one_xcvr(skfd, s, 1); |
524 |
ret &= do_one_xcvr(skfd_mii, s, 1); |
435 |
} |
525 |
} |
436 |
if (ret) |
526 |
if (ret) |
437 |
fprintf(stderr, "no MII interfaces found\n"); |
527 |
fprintf(stderr, "no MII interfaces found\n"); |
438 |
} else { |
528 |
} else { |
439 |
ret = 0; |
529 |
ret = 0; |
440 |
for (i = optind; i < argc; i++) { |
530 |
for (i = optind; i < argc; i++) { |
441 |
ret |= do_one_xcvr(skfd, argv[i], 0); |
531 |
ret |= do_one_xcvr(skfd_mii, argv[i], 0); |
442 |
} |
532 |
} |
443 |
} |
533 |
} |
444 |
|
534 |
|
Lines 448-462
Link Here
|
448 |
if (optind == argc) { |
538 |
if (optind == argc) { |
449 |
for (i = 0; i < MAX_ETH; i++) { |
539 |
for (i = 0; i < MAX_ETH; i++) { |
450 |
sprintf(s, "eth%d", i); |
540 |
sprintf(s, "eth%d", i); |
451 |
watch_one_xcvr(skfd, s, i); |
541 |
watch_one_xcvr(skfd_mii, s, i); |
452 |
} |
542 |
} |
453 |
} else { |
543 |
} else { |
454 |
for (i = optind; i < argc; i++) |
544 |
for (i = optind; i < argc; i++) |
455 |
watch_one_xcvr(skfd, argv[i], i-optind); |
545 |
watch_one_xcvr(skfd_mii, argv[i], i-optind); |
456 |
} |
546 |
} |
457 |
} |
547 |
} |
458 |
} |
548 |
} |
459 |
|
549 |
|
|
|
550 |
close(skfd_mii); |
460 |
close(skfd); |
551 |
close(skfd); |
|
|
552 |
|
461 |
return ret; |
553 |
return ret; |
462 |
} |
554 |
} |