2019-05-20 15:19:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
Retrieve encoded MAC address from 24C16 serial 2-wire EEPROM,
|
|
|
|
decode it and store it in the associated adapter struct for
|
|
|
|
use by dvb_net.c
|
|
|
|
|
|
|
|
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)
|
|
|
|
MAC address into the EEPROM.
|
|
|
|
|
|
|
|
Robert Schlabbach GMX
|
|
|
|
Michael Glaum KVH Industries
|
|
|
|
Holger Waechtler Convergence
|
|
|
|
|
|
|
|
Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
|
2006-01-10 01:25:34 +08:00
|
|
|
Metzler Brothers Systementwicklung GbR
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/i2c.h>
|
2015-06-26 12:47:49 +08:00
|
|
|
#include <linux/etherdevice.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-12-01 16:51:53 +08:00
|
|
|
#include "ttpci-eeprom.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
#define dprintk(x...) do { printk(x); } while (0)
|
|
|
|
#else
|
|
|
|
#define dprintk(x...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static int check_mac_tt(u8 *buf)
|
|
|
|
{
|
2005-12-12 16:37:24 +08:00
|
|
|
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]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
|
|
|
|
{
|
2005-12-12 16:37:24 +08:00
|
|
|
u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
|
2005-04-17 06:20:36 +08:00
|
|
|
0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
|
|
|
|
0x1d, 0x36, 0x64, 0x78};
|
2005-12-12 16:37:24 +08:00
|
|
|
u8 data[20];
|
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* In case there is a sig check failure have the orig contents available */
|
|
|
|
memcpy(data, encodedMAC, 20);
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
2005-12-12 16:37:24 +08:00
|
|
|
data[i] ^= xor[i];
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
|
2005-04-17 06:20:36 +08:00
|
|
|
>> ((data[2 * i + 1] >> 6) & 3);
|
|
|
|
|
2005-12-12 16:37:24 +08:00
|
|
|
if (check_mac_tt(data))
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
|
|
|
|
decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
|
2005-12-12 16:37:24 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 05:33:50 +08:00
|
|
|
int ttpci_eeprom_decode_mac(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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ttpci_eeprom_decode_mac);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 b0[] = { 0xcc };
|
|
|
|
|
|
|
|
struct i2c_msg msg[] = {
|
|
|
|
{ .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
|
|
|
|
{ .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
|
|
|
|
};
|
|
|
|
|
2008-04-09 10:20:00 +08:00
|
|
|
/* dprintk("%s\n", __func__); */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = i2c_transfer(adapter, msg, 2);
|
|
|
|
|
|
|
|
if (ret != 2) /* Assume EEPROM isn't there */
|
|
|
|
return (-ENODEV);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *proposed_mac)
|
|
|
|
{
|
2018-03-10 20:24:43 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 encodedMAC[20];
|
|
|
|
u8 decodedMAC[6];
|
|
|
|
|
|
|
|
ret = ttpci_eeprom_read_encodedMAC(adapter, encodedMAC);
|
|
|
|
|
|
|
|
if (ret != 0) { /* Will only be -ENODEV */
|
|
|
|
dprintk("Couldn't read from EEPROM: not there?\n");
|
2015-06-26 12:47:49 +08:00
|
|
|
eth_zero_addr(proposed_mac);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = getmac_tt(decodedMAC, encodedMAC);
|
|
|
|
if( ret != 0 ) {
|
|
|
|
dprintk("adapter failed MAC signature check\n");
|
2018-03-10 20:24:43 +08:00
|
|
|
dprintk("encoded MAC from EEPROM was %*phC",
|
|
|
|
(int)sizeof(encodedMAC), &encodedMAC);
|
2015-06-26 12:47:49 +08:00
|
|
|
eth_zero_addr(proposed_mac);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(proposed_mac, decodedMAC, 6);
|
2015-06-15 10:01:45 +08:00
|
|
|
dprintk("adapter has MAC addr = %pM\n", decodedMAC);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
|
[media] ttpci: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-19 03:44:07 +08:00
|
|
|
MODULE_DESCRIPTION("Decode dvb_net MAC address from EEPROM of PCI DVB cards made by Siemens, Technotrend, Hauppauge");
|