2019-05-20 09:19:02 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-04-16 15:20:36 -07:00
/*
Retrieve encoded MAC address from 24 C16 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 24 C16 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-09 15:25:34 -02:00
Metzler Brothers Systementwicklung GbR
2005-04-16 15:20:36 -07:00
*/
# include <asm/errno.h>
# include <linux/init.h>
# include <linux/module.h>
# include <linux/string.h>
# include <linux/i2c.h>
2015-06-26 01:47:49 -03:00
# include <linux/etherdevice.h>
2005-04-16 15:20:36 -07:00
2005-12-01 00:51:53 -08:00
# include "ttpci-eeprom.h"
2005-04-16 15:20:36 -07: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 00: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-16 15:20:36 -07:00
}
static int getmac_tt ( u8 * decodedMAC , u8 * encodedMAC )
{
2005-12-12 00:37:24 -08:00
u8 xor [ 20 ] = { 0x72 , 0x23 , 0x68 , 0x19 , 0x5c , 0xa8 , 0x71 , 0x2c ,
2005-04-16 15:20:36 -07:00
0x54 , 0xd3 , 0x7b , 0xf1 , 0x9E , 0x23 , 0x16 , 0xf6 ,
0x1d , 0x36 , 0x64 , 0x78 } ;
2005-12-12 00:37:24 -08:00
u8 data [ 20 ] ;
int i ;
2005-04-16 15:20:36 -07: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 00: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-16 15:20:36 -07:00
> > ( ( data [ 2 * i + 1 ] > > 6 ) & 3 ) ;
2005-12-12 00:37:24 -08:00
if ( check_mac_tt ( data ) )
return - ENODEV ;
2005-04-16 15:20:36 -07: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 00:37:24 -08:00
return 0 ;
2005-04-16 15:20:36 -07:00
}
2011-09-23 18:33:50 -03: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-16 15:20:36 -07: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-08 23:20:00 -03:00
/* dprintk("%s\n", __func__); */
2005-04-16 15:20:36 -07: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 07:24:43 -05:00
int ret ;
2005-04-16 15:20:36 -07: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 01:47:49 -03:00
eth_zero_addr ( proposed_mac ) ;
2005-04-16 15:20:36 -07:00
return ret ;
}
ret = getmac_tt ( decodedMAC , encodedMAC ) ;
if ( ret ! = 0 ) {
dprintk ( " adapter failed MAC signature check \n " ) ;
2018-03-10 07:24:43 -05:00
dprintk ( " encoded MAC from EEPROM was %*phC " ,
( int ) sizeof ( encodedMAC ) , & encodedMAC ) ;
2015-06-26 01:47:49 -03:00
eth_zero_addr ( proposed_mac ) ;
2005-04-16 15:20:36 -07:00
return ret ;
}
memcpy ( proposed_mac , decodedMAC , 6 ) ;
2015-06-14 23:01:45 -03:00
dprintk ( " adapter has MAC addr = %pM \n " , decodedMAC ) ;
2005-04-16 15:20:36 -07: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-18 17:44:07 -02:00
MODULE_DESCRIPTION ( " Decode dvb_net MAC address from EEPROM of PCI DVB cards made by Siemens, Technotrend, Hauppauge " ) ;