Computer Interfacing
Discussions about interfacing and electronics
 

Tv-set Crc decoding

Tv-set Crc decoding


 

       Computer Interfacing Forum Index -> Error detection and correction
Author Message
gigirex
New User



Joined: 01 Mar 2012
Posts: 2


Mar 01, 2012 11:28 am

Hello all.
I am search to modify my tv-set channel list.
Every record (channel) is 76 byte long, the first four are the checksum. This is a example of 7 channels:

0D C5 0A F7 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 4E 00 65 00 77 00 73 00 00 00 20 00 4C 00 6F 00 6D 00 62 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 07 00 53 0D 07 00 00 00 00 02 14 C1 F6 C2 00 00

B4 13 16 41 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 52 00 61 00 64 00 69 00 6F 00 33 00 00 00 6F 00 6D 00 62 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 06 00 4E 0D 08 00 00 00 00 03 14 C1 F6 C2 00 00

CC 66 45 35 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 52 00 61 00 64 00 69 00 6F 00 32 00 00 00 6F 00 6D 00 62 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 05 00 4D 0D 09 00 00 00 00 03 14 C1 F6 C2 00 00

90 BE 36 7B 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 52 00 61 00 64 00 69 00 6F 00 31 00 00 00 6F 00 6D 00 62 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 04 00 4C 0D 0A 00 00 00 00 03 14 C1 F6 C2 00 00

41 B9 A5 A2 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 33 00 20 00 54 00 47 00 52 00 20 00 4C 00 6F 00 6D 00 62 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 03 00 4B 0D 0B 00 00 00 00 02 14 C1 F6 C2 00 00

2C FD 7C 2D 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 32 00 00 00 50 55 0B C0 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 02 00 4A 0D 0C 00 00 00 00 02 14 C1 F6 C2 00 00

0F 7B BC A2 09 03 00 00 FF 07 00 00 01 00 00 00 52 00 61 00 69 00 20 00 31 00 00 00 50 55 0B C0 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 40 3E 01 01 00 FF FF FF FF FF FF 01 00 49 0D 0D 00 00 00 00 02 14 C1 F6 C2 00 00

Thank you in advance

Luigi, Rome, Italy
regregex
Preferred Member



Joined: 30 Oct 2007
Posts: 184
Location: London, UK

Mar 31, 2012 3:35 pm

Hello Luigi, and thanks for your help.

This is a CRC alright, but only a 31-bit CRC. Bit 31 of the checksum is always the same as bit 0. Looks like someone tried a 'clever' optimisation, where instead of doing
Code:
      for(j = 0; j < 8; ++j) {
         if(crc & 0x80000000UL)
            crc = (crc << 1) ^ 0x04c11db7UL;
         else
            crc <<= 1;
      }
they did
Code:
      for(j = 0; j < 8; ++j) {
         crc <<= 1;
         if(crc & 0x80000000UL)
            crc ^= 0x04c11db7UL;
      }
But of course the bit being tested stays in the register, at both ends.

The parameters of the algorithm are as follows:
Code:
width=31  poly=$04c11db7  init=$7fffffff  refin=false  refout=false  xorout=$7fffffff  check=$0ce9e46c  name=(none)
(again, fix up the output by ORing the MSB with 0x80 if the LSB is odd.)

Alternatively here is a complete program to calculate the CRCs and insert them into the records.
Code:
#include <stdio.h>

#define RECLEN  76
#define RECST    4

#define PRINT(r) printf("%02x %02x %02x %02x\n", r[0], r[1], r[2], r[3])

static unsigned char
record1[] = {
   /* 0x0D,0xC5,0x0A,0xF7, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x4E,0x00,0x65,0x00,0x77,0x00,0x73,0x00,
   0x00,0x00,0x20,0x00,0x4C,0x00,0x6F,0x00,
   0x6D,0x00,0x62,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x53,0x0D,
   0x07,0x00,0x00,0x00,0x00,0x02,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
},
record2[] = {
   /* 0xB4,0x13,0x16,0x41, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x52,0x00,0x61,0x00,0x64,0x00,0x69,0x00,
   0x6F,0x00,0x33,0x00,0x00,0x00,0x6F,0x00,
   0x6D,0x00,0x62,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x06,0x00,0x4E,0x0D,
   0x08,0x00,0x00,0x00,0x00,0x03,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
},
record3[] = {
   /* 0xCC,0x66,0x45,0x35, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x52,0x00,0x61,0x00,0x64,0x00,0x69,0x00,
   0x6F,0x00,0x32,0x00,0x00,0x00,0x6F,0x00,
   0x6D,0x00,0x62,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x05,0x00,0x4D,0x0D,
   0x09,0x00,0x00,0x00,0x00,0x03,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
},
record4[] = {
   /* 0x90,0xBE,0x36,0x7B, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x52,0x00,0x61,0x00,0x64,0x00,0x69,0x00,
   0x6F,0x00,0x31,0x00,0x00,0x00,0x6F,0x00,
   0x6D,0x00,0x62,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x04,0x00,0x4C,0x0D,
   0x0A,0x00,0x00,0x00,0x00,0x03,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
},
record5[] = {
   /* 0x41,0xB9,0xA5,0xA2, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x33,0x00,0x20,0x00,0x54,0x00,0x47,0x00,
   0x52,0x00,0x20,0x00,0x4C,0x00,0x6F,0x00,
   0x6D,0x00,0x62,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x4B,0x0D,
   0x0B,0x00,0x00,0x00,0x00,0x02,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
},
record6[] = {
   /* 0x2C,0xFD,0x7C,0x2D, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x32,0x00,0x00,0x00,0x50,0x55,0x0B,0xC0,
   0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x02,0x00,0x4A,0x0D,
   0x0C,0x00,0x00,0x00,0x00,0x02,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
},
record7[] = {
   /* 0x0F,0x7B,0xBC,0xA2, */
   0x55,0x55,0x55,0x55,0x09,0x03,0x00,0x00,
   0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x00,
   0x52,0x00,0x61,0x00,0x69,0x00,0x20,0x00,
   0x31,0x00,0x00,0x00,0x50,0x55,0x0B,0xC0,
   0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x40,0x3E,0x01,0x01,0x00,0xFF,0xFF,
   0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x49,0x0D,
   0x0D,0x00,0x00,0x00,0x00,0x02,0x14,0xC1,
   0xF6,0xC2,0x00,0x00
};

void docrc(unsigned char *);
int main(int, char *[]);

int
main(int argc, char *argv[]) {
   docrc(record1); PRINT(record1);
   docrc(record2); PRINT(record2);
   docrc(record3); PRINT(record3);
   docrc(record4); PRINT(record4);
   docrc(record5); PRINT(record5);
   docrc(record6); PRINT(record6);
   docrc(record7); PRINT(record7);
   return(0);
}

void
docrc(unsigned char *record) {
   unsigned long crc = 0xffffffffUL;
   int i, j;

   for(i = RECST; i < RECLEN; ++i) {
      crc ^= (record[i] & 0xffUL) << 23;
      for(j = 0; j < 8; ++j) {
         crc <<= 1;
         if(crc & 0x80000000UL)
            crc ^= 0x04c11db7UL;
      }
   }

   crc ^= 0xffffffffUL;

   record[0] = crc & 0xff;
   record[1] = (crc >> 8) & 0xff;
   record[2] = (crc >> 16) & 0xff;
   record[3] = (crc >> 24) & 0xff;
}

HTH,

Greg
gigirex
New User



Joined: 01 Mar 2012
Posts: 2


Mar 31, 2012 3:59 pm

Greg,

thank you very, very, very much for your efforts and your time.

I am sure that your solution will resolve the dtt tuner channel overwrite problems of my tv-set and of all users at avmagazine.it - philips-37pf9731 forum.

Bye from Rome

Luigi

       Computer Interfacing Forum Index -> Error detection and correction
Page 1 of 1



Running on php BB © 2001, 2009 php BB Group
   Lammert Bies     Interfacing     Sitemap     Forum