Computer Interfacing
Discussions about interfacing and electronics
 

crc unknown please need help


 

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



Joined: 24 Jan 2011
Posts: 1


Jan 24, 2011 3:36 pm

hello
im working on a program for samsung mobiles and my problem is i dont find the crc ,maybe someone user can help me.

i will show you an example:

CRC F7 E0,,

7F 0E 00 42 02 00 08 00 78 11 00 00 F0 0F 00 00 F7 E0 7E

7F 0E 00 42 02 00 08 00 5B 11 00 00 F0 0F 00 00 47 25 7E

7F 0E 00 42 02 00 08 00 50 11 00 00 F0 0F 00 00 F7 1F 7E

7F 0E 00 42 02 00 08 00 24 11 00 00 F0 0F 00 00 36 36 7E

7F 0E 00 42 02 00 08 00 A6 10 00 00 F0 0F 00 00 14 1A 7E


thx for any help
best regards
Gammatester
Guest







Jan 24, 2011 5:20 pm

I examined three of your data strings:

7F0E00420200080078110000F00F0000
7F0E0042020008005B110000F00F0000
7F0E004202000800A6100000F00F0000

They are compatible with these Rocksoft parameters, you should test both parameters with data strings of different length in order to get a single set.
Code:
===== Result parameter sets =====
CRC=$f7e0  Poly=$8005  init=$53dd  xorout=$0000  refin=false  refout=false
 *** Second data set verified
 *** Third  data set verified
CRC=$f7e0  Poly=$8005  init=$795d  xorout=$ffff  refin=false  refout=false
 *** Second data set verified
 *** Third  data set verified
===== done =====
.
regregex
Preferred Member



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

Jan 24, 2011 5:40 pm

Further to Gammatester's answer, this may be a more general solution.
The 7F 0E doesn't appear to be included in the CRC. I guess 7F is the start/end of packet marker and 0E is the payload length.
If you analyse only the payloads and their CRCs:-
Code:
00 42 02 00 08 00 78 11 00 00 F0 0F 00 00 F7 E0
00 42 02 00 08 00 5B 11 00 00 F0 0F 00 00 47 25
00 42 02 00 08 00 50 11 00 00 F0 0F 00 00 F7 1F
00 42 02 00 08 00 24 11 00 00 F0 0F 00 00 36 36
00 42 02 00 08 00 A6 10 00 00 F0 0F 00 00 14 1A
then you get:
Code:
   Name   : (none)
   Width  : 16
   Poly   : 8005
   Init   : EAEA
   RefIn  : False
   RefOut : False
   XorOut : 0000
   Check  : 877F
I've assumed XorOut=0 at first, but it already gives us a nice Init value of a byte repeated, so this is likely to be the algorithm in the Samsung firmware.

If that is the case, the algorithm is the same one reported by 'xtrusion' last month.

Regards,

Greg
shadab_a4u
New User



Joined: 24 Aug 2011
Posts: 3
Location: INDIA

Aug 24, 2011 6:30 pm

Hi!

I was searching for the samething and finally landed here.

But i am unable to do it in vb.

Can anybody help me to Calculate CRC in any version of VB, C or Delphi?

Br,
Shadab Ahmad
Gammatester
Guest







Aug 24, 2011 7:07 pm

Here a Pascal/Delphi function for Greg's Rocksoft parameters. There are two tests: first the Rocksoft test string '123456789' and second the Greg's first stripped set:
Code:

00 42 02 00 08 00 78 11 00 00 F0 0F 00 00 F7 E0
The code uses array of bytes. There should be not difficulties to use other data types (pointer, ansistring, etc). To avoid using unnecessary units the checks print TRUE if the CRCs are as expected.
Code:
program t_crcn;

{$ifdef WIN32}
{$apptype console}
{$endif}

{---------------------------------------------------------------------------}
function CRC16_NONE(const b: array of byte): word;
const
  poly = $8005;
var
  i,j: integer;
  crc: word;
begin
  crc := $EAEA;
  for i:=low(b) to high(b) do begin
    crc := crc xor word(b[i]) shl 8;
    for j:=1 to 8 do begin
      if crc and $8000 <> 0 then crc := (crc shl 1) xor poly
      else crc := crc shl 1;
    end;
  end;
  CRC16_NONE := crc;
end;

const
  tvs: array[1..9] of byte = ($31,$32,$33,$34,$35,$36,$37,$38,$39);
  tv1: array[1..14] of byte = ($00,$42,$02,$00,$08,$00,$78,$11,$00,$00,$F0,$0F,$00,$00);
begin
  writeln('Selftest   CRC16_NONE: ', CRC16_NONE(tvs)=$877F);
  writeln('CRC16_NONE(tv1)=$F7E0: ', CRC16_NONE(tv1)=$F7E0);
end.


D:\WORK>D:\DMX\M12\DCC32 -b t_crcn.pas
CodeGear Delphi for Win32 compiler version 20.0
Copyright (c) 1983,2008 CodeGear
t_crcn.dpr(34)
35 lines, 0.04 seconds, 14592 bytes code, 13576 bytes data.

D:\WORK>t_crcn.exe
Selftest   CRC16_NONE: TRUE
CRC16_NONE(tv1)=$F7E0: TRUE
shadab_a4u
New User



Joined: 24 Aug 2011
Posts: 3
Location: INDIA

Aug 25, 2011 3:36 pm

Hi Gammatester!

As told by you, i converted my code but looks like some error is there:
Code:

    Private Function DoCRC(ByVal gBytes() As Byte) As String
        Dim Poly As Integer = &H8005
        Dim i, j As Integer
        Dim crc As Integer
        crc = &HEAEA
        For i = 0 To gBytes.Length - 1
            crc = crc Xor gBytes(i) << 8 ' << is shl in vb net
            For j = 1 To 8
                If (crc And &H8000) <> 0 Then
                    crc = (crc << 1) Xor Poly
                Else
                    crc = crc << 1
                End If
            Next
        Next
        Return Hex(crc)
    End Function


it return 63E2D56A as CRC for string "123456789"

Any suggestion will be much appreciated.

Br,
Shadab Ahmad
Gammatester
Guest







Aug 25, 2011 5:24 pm

To be on the safe side I would write
Code:

j = gBytes(i)
crc = crc Xor (j << 8)
..
Return Hex(crc & &HFFFF)
I simulated a few possibilities for operator precedence but never got your result. Here is the same function in C, perhaps this is more portable. Hope that helps!
Code:

//---------------------------------------------------------------------------
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>

static uint16_t CRC16_NONE(uint8_t *data, size_t len) {
  uint16_t crc = 0xEAEA;
  size_t j;
  int i;
  for (j=len; j>0; j--) {
    crc ^= (uint16_t)(*data++) << 8;
    for (i=0; i<8; i++) {
      if (crc & 0x8000) crc = (crc<<1) ^ 0x8005;
      else crc <<= 1;
    }
  }
  return (crc);
}

int main() {
  uint8_t test1[] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
  uint8_t test2[] = {0x00,0x42,0x02,0x00,0x08,0x00,0x78,0x11,0x00,0x00,0xF0,0x0F,0x00,0x00};
  uint16_t crc;

  crc = CRC16_NONE(test1, sizeof(test1));
  printf("Rocksoft check value: 0x%04X, test1 ", crc);
  if (crc==0x877F) printf("passed.\n"); else printf("failed!\n");

  crc = CRC16_NONE(test2, sizeof(test2));
  printf("   CRC16_NONE(test2): 0x%04X, test2 ", crc);
  if (crc==0xF7E0) printf("passed.\n"); else printf("failed!\n");

  return 0;
}

C:\TEST>gcc t_crcnc.c -o t_crcnc.exe
C:\TEST>t_crcnc
Rocksoft check value: 0x877F, test1 passed.
   CRC16_NONE(test2): 0xF7E0, test2 passed.
shadab_a4u
New User



Joined: 24 Aug 2011
Posts: 3
Location: INDIA

Aug 25, 2011 5:45 pm

Definitely something is wrong in you app.

In first example
Code:
for j:=1 to 8 do begin


and later it is
Code:
for (j=len; j>0; j--)


I think there is some error in you code.

Br,
Shadab Ahmad
Gammatester
Guest







Aug 25, 2011 5:48 pm

No error. Unfortunately the loop variables are named different. Look at the correct results.

       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