Bug#549397: mii-tool decodes MII vendor ids wrongly
Ben Hutchings
ben at decadent.org.uk
Sat Oct 3 00:19:22 UTC 2009
Package: net-tools
Version: 1.60-23
Severity: normal
Tags: patch
The MII specification (IEEE 802.3 clause 22) specifies the PHY id
registers to hold the vendor id (OUI) in reverse bit order. Many PHYs
have the bytes in reverse order but the bits in normal order, and this
is what mii-tool expects. However, recent PHYs from at least AMCC,
Broadcom and Solarflare use the specified bit order and mii-tool
should follow this.
This patch changes mii-tool to decode the OUI according to both
interpretations.
--- net-tools-1.60.orig/mii-tool.c
+++ net-tools-1.60/mii-tool.c
@@ -224,6 +224,14 @@
return buf;
}
+static unsigned char bitreverse_byte(unsigned char byte)
+{
+ byte = (byte << 4) | (byte >> 4);
+ byte = (byte & 0x33) << 2 | (byte & 0xcc) >> 2;
+ byte = (byte & 0x55) << 1 | (byte & 0xaa) >> 1;
+ return byte;
+}
+
int show_basic_mii(int sock, int phy_id)
{
char buf[100];
@@ -297,11 +305,31 @@
break;
if (i < NMII)
printf("%s rev %d\n", mii_id[i].name, mii_val[3]&0x0f);
- else
- printf("vendor %02x:%02x:%02x, model %d rev %d\n",
+ else {
+ /* Each OUI consists of 24 bits a-z of which a and b are
+ * always assigned as zero. The bit assignments in these
+ * registers are specified as:
+ * 2.15-0 c-r
+ * 3.15-10 s-x
+ * This is the opposite of the bit order within each byte
+ * for the written representation specified in section
+ * 9.5.2 of IEEE 802-2001. However, some vendors mirror
+ * the written representation, using the bit assignments:
+ * 2.15-10 f-a (?)
+ * 2.9-2 p-i
+ * 2.1-0 x-w
+ * 3.15-10 v-q
+ * Therefore we decode the registers under both
+ * interpretations.
+ */
+ printf("vendor %02x:%02x:%02x or %02x:%02x:%02x, model %d rev %d\n",
+ bitreverse_byte(mii_val[2]>>10),
+ bitreverse_byte(mii_val[2]>>2),
+ bitreverse_byte((mii_val[2]<<6)|(mii_val[3]>>10)),
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);
+ }
printf(" basic mode: ");
if (bmcr & MII_BMCR_RESET)
printf("software reset, ");
--- END ---
-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (x86_64)
Kernel: Linux 2.6.30-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages net-tools depends on:
ii libc6 2.9-26 GNU C Library: Shared libraries
net-tools recommends no packages.
net-tools suggests no packages.
-- debconf-show failed
More information about the Pkg-net-tools-maintainers
mailing list