Message Integrity Checking
[uccvend-snackrom.git] / ROM2 / xmodem.c
index b164243..d0e09dd 100644 (file)
@@ -55,14 +55,15 @@ readchar (int timeout)
 /* Calculate a CRC-16 for the LEN byte message pointed at by P.  */
 /* Pads with ^Z up to 128 bytes if told to */
 
-static unsigned short
-docrc (unsigned char *p, int len, bool pad)
+unsigned short
+docrc (unsigned char *p, short len, bool pad, unsigned short crc)
 {
-  int len2 = len;
-  unsigned short crc = 0;
+  short len2 = len;
 
-  while (len-- > 0)
-    crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++];
+  while (len-- > 0) {
+    crc = (crc << 8) ^ (crctab[(crc >> 8) ^ *p]);
+       p++;
+  }
   if (pad && len2 < 128) {
     len = 128-len;
     while (len-- > 0)
@@ -162,7 +163,7 @@ xmodem_send_packet (const unsigned char *packet, int len)
     if (crcflag) {
       u16 crc;
 
-      crc = docrc ((unsigned char*)packet, len, 1);
+      crc = docrc ((unsigned char*)packet, len, 1, 0);
 
       s[0] = crc >> 8;
       s[1] = crc & 0xff;

UCC git Repository :: git.ucc.asn.au