Sorry... long post....
For all the test vectors I have got from the thread, I've got something that is almost there..
00 01 00 00 00 00 => 00 01 00 00 00 00 => e4 f4 should be e4 f5, error 00 01
01 00 20 01 01 01 => 01 00 20 01 01 01 => 7b 38
01 00 20 02 02 02 => 01 00 20 02 02 02 => 1b 04
01 00 20 03 03 03 => 01 00 20 03 03 03 => 3b 10
01 00 20 04 04 04 => 01 00 20 04 04 04 => db 7c
01 00 20 05 05 05 => 01 00 20 05 05 05 => fb 68
01 00 20 06 06 06 => 01 00 20 06 06 06 => 9b 54
01 00 20 07 07 07 => 01 00 20 07 07 07 => bb 40
01 00 20 08 08 08 => 01 00 20 08 09 08 => 6a be
01 00 20 09 09 09 => 01 00 20 09 08 09 => 4a aa
01 00 20 0a 0a 0a => 01 00 20 0a 0b 0a => 2a 96
01 00 20 0b 0b 0b => 01 00 20 0b 0a 0b => 0a 82
01 00 20 0c 0c 0c => 01 00 20 0c 0d 0c => ea ee
01 00 20 0d 0d 0d => 01 00 20 0d 0c 0d => ca fa
01 00 20 0e 0e 0e => 01 00 20 0e 0f 0e => aa c6
01 00 20 0f 0f 0f => 01 00 20 0f 0e 0f => 8a d2
00 01 70 01 22 01 => 00 01 70 01 23 00 => 14 d2 should be 14 d3, error 00 01
00 01 60 00 80 00 => 00 01 60 00 81 00 => 9f 85
00 01 b0 00 20 00 => 00 01 b0 01 21 01 => f3 17 should be f3 16, error 00 01
00 01 b0 01 20 00 => 00 01 b0 00 21 01 => c3 20 should be c3 21, error 00 01
00 01 b0 02 53 00 => 00 01 b0 03 52 01 => 99 24
00 01 b0 03 65 00 => 00 01 b0 02 64 01 => 9a bc
00 01 b0 04 71 00 => 00 01 b0 05 70 01 => bd f6
00 01 b0 05 75 00 => 00 01 b0 04 74 01 => 49 0d
00 01 b0 06 65 00 => 00 01 b0 07 64 01 => 6a 57
00 01 b0 07 6e 00 => 00 01 b0 06 6f 00 => 81 ac should be 81 ad, error 00 01
00 01 b0 08 63 00 => 00 01 b0 09 63 00 => dd c5
00 01 b0 09 65 00 => 00 01 b0 08 65 00 => 4b 58
00 01 b0 0a 72 00 => 00 01 b0 0b 72 00 => ff 9b
00 01 b0 0b 20 00 => 00 01 b0 0a 20 00 => 12 c4 should be 12 c5, error 00 01
00 01 b0 0c 36 00 => 00 01 b0 0d 36 00 => 57 e8 should be 57 e9, error 00 01
00 01 b0 0d 34 00 => 00 01 b0 0c 34 00 => 05 b9 should be 05 b8, error 00 01
00 01 b0 0e 20 00 => 00 01 b0 0f 20 00 => e2 2f should be e2 2e, error 00 01
00 01 b0 0f 20 00 => 00 01 b0 0e 20 00 => d2 18 should be d2 19, error 00 01
00 01 30 00 58 00 => 00 01 30 00 58 01 => 3a 4f
00 01 30 00 01 00 => 00 01 30 00 01 00 => 3c eb
00 01 30 00 02 00 => 00 01 30 00 02 00 => 6f be
00 01 30 00 03 00 => 00 01 30 00 03 00 => 5e 8d
00 01 30 00 04 00 => 00 01 30 00 04 00 => c9 14
00 01 30 00 05 00 => 00 01 30 00 05 00 => f8 27
00 01 30 00 06 00 => 00 01 30 00 06 00 => ab 72
00 01 30 00 07 00 => 00 01 30 00 07 00 => 9a 41
00 01 30 00 08 00 => 00 01 30 00 08 01 => 85 41 should be 85 40, error 00 01
00 01 30 00 09 00 => 00 01 30 00 09 01 => b4 72 should be b4 73, error 00 01
00 01 30 00 0a 00 => 00 01 30 00 0a 01 => e7 27 should be e7 26, error 00 01
00 01 30 00 0b 00 => 00 01 30 00 0b 01 => d6 14 should be d6 15, error 00 01
01 00 00 00 00 00 => 01 00 00 00 00 00 => 15 1b should be 15 1a, error 00 01
It is some sort of obscuring transform in front of a CRC16...
short int my_crc(unsigned char *data, short unsigned length)
{
int i;
short unsigned crc = 0, crc_low, crc_high;
for(i = 0; i < length; i++)
printf("%02x ",data[i]);
printf("=> ",data[i]);
if((data[2] & 0x80)) {
data[3] ^= 0x01;
data[4] ^= 0x01;
data[5] ^= 0x01;
}
if((data[2] & 0x70) == 0x70) {
data[4] ^= 0x01;
data[5] ^= 0x01;
}
if((data[3] & 0x08) ^ (data[4] & 0x80))
data[4] ^= 0x01;
if((data[2] & 0x08) ^ (data[3] & 0x08) ^ (data[4] & 0x08))
data[5] ^= 0x01;
crc = 0x0000;
for(i = 0; i < length*8; i++)
{
int mask, index,bit,wrap;
mask = 0x80>>(i%8);
index = i/8;
bit = (data[index] & mask) ? 1 : 0;
wrap = (crc & 0x8000) ? 1 : 0;
crc <<= 1;
if(wrap ^ bit) crc ^= 0x1021;
}
/* Display the data) */
for(i = 0; i < length; i++)
printf("%02x ",data[i]);
#if 1
if( data[i] || data[i+1])
crc ^= 0x1b15 ^ 0x45a0;
#endif
crc_low = (crc>>0)&0xFF;
crc_high = (crc>>8)&0xFF;
if( crc_low == data[i] && crc_high == data[i+1])
printf(" => %02x %02x\r\n", data[i], data[i+1]);
else
printf(" => %02x %02x should be %02x %02x, error %02x %02x\r\n",
crc_low, crc_high,
data[i], data[i+1],
crc_low^data[i], crc_high^data[i+1]);
return 0;
}