Subject: kern/17432: ieee1394 camera device CRC calculation
To: None <gnats-bugs@gnats.netbsd.org>
From: Anthony Mallet <anthony.mallet@useless-ficus.net>
List: netbsd-bugs
Date: 06/30/2002 01:00:57
>Number:         17432
>Category:       kern
>Synopsis:       ieee1394 camera device CRC calculation
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 29 16:02:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Anthony Mallet
>Release:        NetBSD 1.5ZC
>Organization:
>Environment:
System: NetBSD ficus 1.5ZC NetBSD 1.5ZC (FICUS) #3: Sat May 4 20:51:04 CEST 2002 toto@ficus:/home/src/netbsd-current/sys/arch/i386/compile/FICUS i386
Architecture: i386
Machine: i386
>Description:

I have a 1394 camera device whose config. ROM didn't pass the CRC
test. Since I have only one firewire device, it's difficult for 
me to know whether it's a general problem or not.

In case it's useful, here's the content of the rom, as output by
fwnode_dump_rom()

      0x04205b5e, 0x31333934, 0x20ff4000, 0x00d0f540,
      0x00070285, 0x000446b3, 0x0300d0f5, 0x06070198, 
      0x8d000002, 0xd1000004, 0x0002d192, 0x00d0f540, 
      0x00070285, 0x00034462, 0x1200a02d, 0x13000100, 
      0xd4000001, 0x00031226, 0x403c0000, 0x81000002, 
      0x82000008, 0x000642dd, 0x00000000, 0x00000000, 
      0x4f52414e, 0x4745204d, 0x4943524f, 0x00000000,
      0x000448cb, 0x00000000, 0x00000000, 0x49424f54, 
      0x00000000

The following patch in p1212_calc_crc() in ieee1212.c works for
me. I simply removed calls to ntohl(data[i]) and swapped the two bytes of
the crc-16 at the end (the latter because of the way the CRC is fetched
into the rom).

>How-To-Repeat:

>Fix:
Index: ieee1212.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/std/ieee1212.ēv
retrieving revision 1.2
diff -u -r1.2 ieee1212.c
--- ieee1212.c  2002/04/02 10:10:54     1.2
+++ ieee1212.c  2002/06/29 22:57:45
@@ -1191,7 +1191,7 @@
 
        for (i = 0; i < len; i++) {
                for (shift = 28; shift > 0; shift -= 4) {
-                       sum = ((crc » 12) ^ (ntohl(data[i]) » shift)) &
+                       sum = ((crc » 12) ^ (data[i] » shift)) &
                            0x0000000f;
                        crc = (crc « 4) ^ (sum « 12) ^ (sum « 5) ^ sum;
                }
@@ -1199,11 +1199,11 @@
 
                /* The broken implementation doesn't do the last
shift. */
                if (!broke) {
-                       sum = ((crc » 12) ^ ntohl(data[i])) & 0x0000000f;
+                       sum = ((crc » 12) ^ data[i]) & 0x0000000f;
                        crc = (crc « 4) ^ (sum « 12) ^ (sum « 5) ^ sum;
                }
        }
-       return (u_int16_t)crc;
+       return htons((u_int16_t)crc);
 }
 
 /*

>Release-Note:
>Audit-Trail:
>Unformatted: