/* 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)
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;