summaryrefslogtreecommitdiff
path: root/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c
diff options
context:
space:
mode:
authorJohannes Stezenbach <devnull@localhost>2003-07-21 15:24:06 +0000
committerJohannes Stezenbach <devnull@localhost>2003-07-21 15:24:06 +0000
commit563f50f11a3ffbf4dfb41b19b6f0508c0ea533dd (patch)
tree7cdb3b3035a201fed099b93264c46c7c3c760f6f /linux/drivers/media/dvb/ttpci/ttpci-eeprom.c
parentbece0ee41ada89cb339afdecf7501eec5883d189 (diff)
downloadmediapointer-dvb-s2-563f50f11a3ffbf4dfb41b19b6f0508c0ea533dd.tar.gz
mediapointer-dvb-s2-563f50f11a3ffbf4dfb41b19b6f0508c0ea533dd.tar.bz2
Patch by Michael Glaum, code by Metzler Bros.:
correctly read MAC from eeprom on TT and KNC1 cards
Diffstat (limited to 'linux/drivers/media/dvb/ttpci/ttpci-eeprom.c')
-rw-r--r--linux/drivers/media/dvb/ttpci/ttpci-eeprom.c105
1 files changed, 64 insertions, 41 deletions
diff --git a/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c b/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c
index 8089db27c..ed3d9f4ea 100644
--- a/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c
+++ b/linux/drivers/media/dvb/ttpci/ttpci-eeprom.c
@@ -3,9 +3,6 @@
decode it and store it in the associated adapter struct for
use by dvb_net.c
- This code was tested on TT-Budget/WinTV-NOVA-CI PCI boards with
- Atmel and ST Microelectronics EEPROMs.
-
This card appear to have the 24C16 write protect held to ground,
thus permitting normal read/write operation. Theoretically it
would be possible to write routines to burn a different (encoded)
@@ -15,6 +12,9 @@
Michael Glaum KVH Industries
Holger Waechtler Convergence
+ Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
+ Metzler Brothers Systementwicklung GbR
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@@ -40,23 +40,62 @@
#include "dvb_functions.h"
#if 1
-#define dprintk(x...) printk(x)
+#define dprintk(x...) do { printk(x); } while (0)
#else
-#define dprintk(x...)
+#define dprintk(x...) do { } while (0)
#endif
+static int check_mac_tt(u8 *buf)
+{
+ int i;
+ u16 tmp = 0xffff;
+
+ for (i = 0; i < 8; i++) {
+ tmp = (tmp << 8) | ((tmp >> 8) ^ buf[i]);
+ tmp ^= (tmp >> 4) & 0x0f;
+ tmp ^= (tmp << 12) ^ ((tmp & 0xff) << 5);
+ }
+ tmp ^= 0xffff;
+ return (((tmp >> 8) ^ buf[8]) | ((tmp & 0xff) ^ buf[9]));
+}
+
+static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
+{
+ u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
+ 0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
+ 0x1d, 0x36, 0x64, 0x78};
+ u8 data[20];
+ int i;
+
+ /* In case there is a sig check failure have the orig contents available */
+ memcpy(data, encodedMAC, 20);
+
+ for (i = 0; i < 20; i++)
+ data[i] ^= xor[i];
+ for (i = 0; i < 10; i++)
+ data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
+ >> ((data[2 * i + 1] >> 6) & 3);
+
+ if (check_mac_tt(data))
+ return -ENODEV;
+
+ decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
+ decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
+ return 0;
+}
+
static int ttpci_eeprom_read_encodedMAC(struct dvb_i2c_bus *i2c, u8 * encodedMAC)
{
int ret;
- u8 b0[] = { 0xd4 };
+ u8 b0[] = { 0xcc };
struct i2c_msg msg[] = {
- {.addr = 0x50,.flags = 0,.buf = b0,.len = 1},
- {.addr = 0x50,.flags = I2C_M_RD,.buf = encodedMAC,.len = 6}
+ { .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
+ { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
};
- dprintk("%s\n", __FUNCTION__);
+ /* dprintk("%s\n", __FUNCTION__); */
ret = i2c->xfer(i2c, msg, 2);
@@ -66,34 +105,11 @@ static int ttpci_eeprom_read_encodedMAC(struct dvb_i2c_bus *i2c, u8 * encodedMAC
return 0;
}
-static void decodeMAC(u8 * decodedMAC, const u8 * encodedMAC)
-{
- u8 ormask0[3] = { 0x54, 0x7B, 0x9E };
- u8 ormask1[3] = { 0xD3, 0xF1, 0x23 };
- u8 low;
- u8 high;
- u8 shift;
- int i;
-
- decodedMAC[0] = 0x00;
- decodedMAC[1] = 0xD0;
- decodedMAC[2] = 0x5C;
-
- for (i = 0; i < 3; i++) {
- low = encodedMAC[2 * i] ^ ormask0[i];
- high = encodedMAC[2 * i + 1] ^ ormask1[i];
- shift = (high >> 6) & 0x3;
-
- decodedMAC[5 - i] = ((high << 8) | low) >> shift;
- }
-
-}
-
int ttpci_eeprom_parse_mac(struct dvb_i2c_bus *i2c)
{
- int ret;
- u8 encodedMAC[6];
+ int ret, i;
+ u8 encodedMAC[20];
u8 decodedMAC[6];
ret = ttpci_eeprom_read_encodedMAC(i2c, encodedMAC);
@@ -104,18 +120,25 @@ int ttpci_eeprom_parse_mac(struct dvb_i2c_bus *i2c)
return ret;
}
- decodeMAC(decodedMAC, encodedMAC);
- memcpy(i2c->adapter->proposed_mac, decodedMAC, 6);
+ ret = getmac_tt(decodedMAC, encodedMAC);
+ if( ret != 0 ) {
+ dprintk("%s adapter %i failed MAC signature check\n",
+ i2c->adapter->name, i2c->adapter->num);
+ dprintk("encoded MAC from EEPROM was " );
+ for(i=0; i<19; i++) {
+ dprintk( "%.2x:", encodedMAC[i]);
+ }
+ dprintk("%.2x\n", encodedMAC[19]);
+ memset(i2c->adapter->proposed_mac, 0, 6);
+ return ret;
+ }
- dprintk("%s adapter %i has MAC addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ memcpy(i2c->adapter->proposed_mac, decodedMAC, 6);
+ dprintk("%s adapter %i has MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
i2c->adapter->name, i2c->adapter->num,
decodedMAC[0], decodedMAC[1], decodedMAC[2],
decodedMAC[3], decodedMAC[4], decodedMAC[5]);
- dprintk("encoded MAC was %02x:%02x:%02x:%02x:%02x:%02x\n",
- encodedMAC[0], encodedMAC[1], encodedMAC[2],
- encodedMAC[3], encodedMAC[4], encodedMAC[5]);
return 0;
}
EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
-