1428Fermer1430
squalylLe 07/11/2005 à 16:28
void dbus_get_mac(u8 *dest)
{
char buffer[17];
unsigned long int a,b,c,d;
if(!AB_serno(buffer)) {
/*pphnn nnnnn vvvv -> p is platform, n is unique, v is checksum*/
sprintf(buffer,"011C6 B1267 0241");
};
sscanf(buffer,"%5lx %5lx %4lx",&a,&b,&d); /* a = 11C6 b = B1276 d = 0241 */

/*combine 16 bit checksum into a 8 bit value*/
d=(d>>8) ^ (d&0xFF); /* d = 02 xor 41 = 43 */

a&=0xFF; /* nn -- -- */ /* a = C6 */
c=b&0xFF; /* -- -- nn */ /* c = 76 */
b=b>>8; /* -- nn -- */ /* b = B12 */

/*4 bits remaining in b ^^ so we add them to d*/
d += (b>>8) /* d = 43 + B = 4E */
b&=0xFF; /* b = 12 */
a^=d; /* a = 88 */
b^=d; /* b = 5C */
c^=d; /* c = 38 */

dest[0]=0x08; /*my MAC is 08:00:28:88:5c:38*/
dest[1]=0x00;
dest[2]=0x28;
dest[3]=(char)a;
dest[4]=(char)b;
dest[5]=(char)c;
}