Skip to content
Snippets Groups Projects
Commit 2d5a6a45 authored by Bernard Blackham's avatar Bernard Blackham
Browse files

More versatile CRC function ... planned for auth

parent 74fa3423
No related merge requests found
...@@ -53,17 +53,17 @@ readchar (int timeout) ...@@ -53,17 +53,17 @@ readchar (int timeout)
} }
/* Calculate a CRC-16 for the LEN byte message pointed at by P. */ /* Calculate a CRC-16 for the LEN byte message pointed at by P. */
/* Pads with ^Z if necessary */ /* Pads with ^Z up to 128 bytes if told to */
static unsigned short static unsigned short
docrc (unsigned char *p, int len) docrc (unsigned char *p, int len, bool pad)
{ {
int len2 = len; int len2 = len;
unsigned short crc = 0; unsigned short crc = 0;
while (len-- > 0) while (len-- > 0)
crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++]; crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++];
if (len2 < 128) { if (pad && len2 < 128) {
len = 128-len; len = 128-len;
while (len-- > 0) while (len-- > 0)
crc = (crc << 8) ^ crctab[(crc >> 8) ^ 0x1a]; crc = (crc << 8) ^ crctab[(crc >> 8) ^ 0x1a];
...@@ -162,7 +162,7 @@ xmodem_send_packet (const unsigned char *packet, int len) ...@@ -162,7 +162,7 @@ xmodem_send_packet (const unsigned char *packet, int len)
if (crcflag) { if (crcflag) {
u16 crc; u16 crc;
crc = docrc ((unsigned char*)packet, len); crc = docrc ((unsigned char*)packet, len, 1);
s[0] = crc >> 8; s[0] = crc >> 8;
s[1] = crc & 0xff; s[1] = crc & 0xff;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment