I'm working on reverse engineering the serial communication protocol of an obsolete electronic control system, but I'm having trouble figuring out the CRC algorithm and polynomial.
I have reverse engineered another similar system made by the same company in the past. On that previous one I was able to dump the 8051
micro-controller program from the EPROM
and disassemble it. Here is my working code in C, with the original 8051
disassembly in the comments:
unsigned char CalculateChecksum(void) {
unsigned char r1 = 0; // MOV R1,#0
unsigned char r2, r3, c, a;
for (r2=1; r2<4; r2++) { // MOV R2,#07
a = out_buffer[r2]; // MOV A,@R0
r3 = a; // XCH A,R1
a = r1;
r1 = r3;
c = 0; // CLR C
if (a & 0x80) {
c = 1; // FAKE CARRY
}
a = a << 1; // RLC A
if (c == 1) { // JNC 0x03E8
a = a ^ 0x19; // XRL A,#19
}
a = a ^ r1; // XRL A,R1 (0x03E8)
r1 = a; // MOV R1,A
printf("%d: 0x%x ", r2, a);
}
return a;
}
The problem is that this function does not work on this newer system. I've tried all 255 possible polynomials, so it is unclear wether the algorithms are shared (perhaps with some modifications?) between the different systems, however I believe there is a relation between algorithms.
Here is a capture of some of the transmitted message from one unit:
7E 00 12 03 00 50 FB 01 60
7E 00 12 03 00 50 FB 01 60
7E 00 12 03 00 50 FB 01 60
7E 00 12 03 00 50 FB 01 60
7E 00 12 03 00 51 FB 01 61
7E 00 12 03 00 51 FB 01 61
7E 00 12 03 00 51 FB 01 61
7E 00 12 03 00 51 FF 01 65
7E 00 12 03 00 51 03 00 69
7E 00 12 03 00 51 09 00 6F
0x7E appears to be a preamble, followed by 7 bytes of data, then the checksum byte. Can anyone figure it out?