IBM BSC CRC?
Mattis Lind
mattislind at gmail.com
Tue Jan 28 03:21:13 CST 2020
So it all turned out to be a single bit error in the first message that
prevented me from finding the algorithm.
The annoying thing was that I used pretty much the same algorithm that
Peter provided but since I mostly looked for match of the first message and
then that CRC bytes were swapped made me miss the fact that the second
message actually matched.
Thanks Peter for spotting this!
I also got crc reveng to work eventually.
./reveng -w 16 -s 6cd90240c84050030d28
./reveng: warning: you have only given 1 sample
./reveng: warning: to reduce false positives, give 4 or more samples
width=16 poly=0x8005 init=0x0000 refin=true refout=true
xorout=0x0000 check=0xbb3d residue=0x0000 name="CRC-16/ARC"
MattisMacBook:reveng-2.1.0 mattis$ ./reveng -w 16 -s 6CD90240404070032688
./reveng: warning: you have only given 1 sample
./reveng: warning: to reduce false positives, give 4 or more samples
./reveng: no models found
$ ./reveng -w 16 -s 6CD90240404050032688
./reveng: warning: you have only given 1 sample
./reveng: warning: to reduce false positives, give 4 or more samples
width=16 poly=0x8005 init=0x0000 refin=true refout=true
xorout=0x0000 check=0xbb3d residue=0x0000 name="CRC-16/ARC"
Then from there it took a bit of fiddling with options to make crc reveng
to actually be able to get it to generate the same output:
$ ./reveng -w 16 -P a001 -i 0000 -x 0000 -l -d
width=16 poly=0x8005 init=0x0000 refin=true refout=true
xorout=0x0000 check=0xbb3d residue=0x0000 name=(none)
$ ./reveng -w 16 -P a001 -i 0000 -x 0000 -l -c 6CD9024040405003
2688
For some reaason I had to swap the bit order of the polynom to get it
working which I got when I used the -d option when using -P 8005 it showed
a001. I tried to swap that and voila it worked!
A lesson for me is then to have more message samples to spot errors easier
and also never assume there is such things that error free serial links
even though the cable was just one meter and the speed 9600 bps.
/Mattis
Den tis 28 jan. 2020 kl 03:21 skrev Peter Coghlan via cctalk <
cctalk at classiccmp.org>:
> Mattis Lind wrote:
> >
> > > > I have two actual messages from equipment employing IBM BSC:
> > > > 32016CD90240404070032688
> > > > and
> > > > 32016CD90240C84050030D28
> > > >
> >
>
> How about this code:
>
> #include <stdio.h>
>
> int crc16(unsigned char *ptr, int count)
> {
> unsigned int crc;
> char i;
>
> crc = 0x0000;
> while (--count >= 0)
> {
> crc = crc ^ (unsigned int) *ptr++;
> i = 8;
> do
> {
> if (crc & 0x0001)
> crc = (crc >> 1) ^ 0xA001; /* 0x8005 bit reversed */
> else
> crc = (crc >> 1);
> } while(--i);
> }
> return (crc);
> }
>
> void main()
> {
> /* 32 01 6C D9 02 40 40 40 70 03 26 88 */
>
> unsigned char data1[] = {0x6c, 0xd9, 0x02, 0x40, 0x40, 0x40, 0x50,
> 0x03};
>
> /* 32 01 6C D9 02 40 C8 40 50 03 0D 28 */
>
> unsigned char data2[] = {0x6c, 0xd9, 0x02, 0x40, 0xc8, 0x40, 0x50,
> 0x03};
>
> printf("crc sent: 8826 computed: %4.4x\n", crc16(data1, sizeof(data1)));
>
> printf("crc sent: 280d computed: %4.4x\n", crc16(data2, sizeof(data2)));
>
> return;
> }
>
> Please note that I had to cheat to get this to work. It worked initially
> for the second case but it only worked for the first case when I tweaked
> 70 to 50, ie I substituted the corresponding value from the second case.
>
> Regards,
> Peter Coghlan.
>
More information about the cctech
mailing list