diff --git a/src/checksum.c b/src/checksum.c index 9d06630..6dcdcd5 100644 --- a/src/checksum.c +++ b/src/checksum.c @@ -69,7 +69,7 @@ checksum_xor_uint8 (const unsigned char data[], unsigned int size, unsigned char unsigned short -checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned short init) +checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout) { static const unsigned short crc_ccitt_table[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, @@ -110,7 +110,7 @@ checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned sh for (unsigned int i = 0; i < size; ++i) crc = (crc << 8) ^ crc_ccitt_table[(crc >> 8) ^ data[i]]; - return crc; + return crc ^ xorout; } unsigned int diff --git a/src/checksum.h b/src/checksum.h index c8a9001..39da07c 100644 --- a/src/checksum.h +++ b/src/checksum.h @@ -39,7 +39,7 @@ unsigned char checksum_xor_uint8 (const unsigned char data[], unsigned int size, unsigned char init); unsigned short -checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned short init); +checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout); unsigned int checksum_crc32 (const unsigned char data[], unsigned int size); diff --git a/src/cressi_goa.c b/src/cressi_goa.c index e414743..9df10e8 100644 --- a/src/cressi_goa.c +++ b/src/cressi_goa.c @@ -93,7 +93,7 @@ cressi_goa_device_send (cressi_goa_device_t *device, unsigned char cmd, const un if (size) { memcpy (packet + 5, data, size); } - crc = checksum_crc16_ccitt (packet + 3, size + 2, 0x000); + crc = checksum_crc16_ccitt (packet + 3, size + 2, 0x000, 0x0000); packet[5 + size + 0] = (crc ) & 0xFF; // Low packet[5 + size + 1] = (crc >> 8) & 0xFF; // High packet[5 + size + 2] = TRAILER; @@ -155,7 +155,7 @@ cressi_goa_device_receive (cressi_goa_device_t *device, unsigned char data[], un // Verify the checksum of the packet. unsigned short crc = array_uint16_le (packet + length + 5); - unsigned short ccrc = checksum_crc16_ccitt (packet + 3, length + 2, 0x0000); + unsigned short ccrc = checksum_crc16_ccitt (packet + 3, length + 2, 0x0000, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum."); return DC_STATUS_PROTOCOL; @@ -203,7 +203,7 @@ cressi_goa_device_download (cressi_goa_device_t *device, dc_buffer_t *buffer, dc // Verify the checksum of the packet. unsigned short crc = array_uint16_le (packet + sizeof(packet) - 2); - unsigned short ccrc = checksum_crc16_ccitt (packet + 3, sizeof(packet) - 5, 0x0000); + unsigned short ccrc = checksum_crc16_ccitt (packet + 3, sizeof(packet) - 5, 0x0000, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum."); return DC_STATUS_PROTOCOL; diff --git a/src/cressi_leonardo.c b/src/cressi_leonardo.c index f331537..dd941da 100644 --- a/src/cressi_leonardo.c +++ b/src/cressi_leonardo.c @@ -84,7 +84,7 @@ cressi_leonardo_make_ascii (const unsigned char raw[], unsigned int rsize, unsig array_convert_bin2hex (raw, rsize, ascii + 1, 2 * rsize); // Checksum - unsigned short crc = checksum_crc16_ccitt (ascii + 1, 2 * rsize, 0xffff); + unsigned short crc = checksum_crc16_ccitt (ascii + 1, 2 * rsize, 0xffff, 0x0000); unsigned char checksum[] = { (crc >> 8) & 0xFF, // High (crc ) & 0xFF}; // Low @@ -129,7 +129,7 @@ cressi_leonardo_packet (cressi_leonardo_device_t *device, const unsigned char co // Verify the checksum of the packet. unsigned short crc = array_uint16_be (checksum); - unsigned short ccrc = checksum_crc16_ccitt (answer + 1, asize - 6, 0xffff); + unsigned short ccrc = checksum_crc16_ccitt (answer + 1, asize - 6, 0xffff, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum."); return DC_STATUS_PROTOCOL; @@ -372,7 +372,7 @@ cressi_leonardo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) // Verify the checksum. unsigned int csum1 = array_uint16_be (checksum); - unsigned int csum2 = checksum_crc16_ccitt (data, SZ_MEMORY, 0xffff); + unsigned int csum2 = checksum_crc16_ccitt (data, SZ_MEMORY, 0xffff, 0x0000); if (csum1 != csum2) { ERROR (abstract->context, "Unexpected answer bytes."); return DC_STATUS_PROTOCOL; diff --git a/src/divesystem_idive.c b/src/divesystem_idive.c index 0410cd2..4a0bca3 100644 --- a/src/divesystem_idive.c +++ b/src/divesystem_idive.c @@ -231,7 +231,7 @@ divesystem_idive_send (divesystem_idive_device_t *device, const unsigned char co packet[0] = START; packet[1] = csize; memcpy(packet + 2, command, csize); - crc = checksum_crc16_ccitt (packet, csize + 2, 0xffff); + crc = checksum_crc16_ccitt (packet, csize + 2, 0xffff, 0x0000); packet[csize + 2] = (crc >> 8) & 0xFF; packet[csize + 3] = (crc ) & 0xFF; @@ -292,7 +292,7 @@ divesystem_idive_receive (divesystem_idive_device_t *device, unsigned char answe // Verify the checksum. unsigned short crc = array_uint16_be (packet + len + 2); - unsigned short ccrc = checksum_crc16_ccitt (packet, len + 2, 0xffff); + unsigned short ccrc = checksum_crc16_ccitt (packet, len + 2, 0xffff, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected packet checksum."); return DC_STATUS_PROTOCOL; diff --git a/src/liquivision_lynx.c b/src/liquivision_lynx.c index a0d8e0a..e7ad5a4 100644 --- a/src/liquivision_lynx.c +++ b/src/liquivision_lynx.c @@ -158,7 +158,7 @@ liquivision_lynx_recv (liquivision_lynx_device_t *device, unsigned char data[], // Verify the checksum. unsigned short crc = array_uint16_be (packet + 1 + size); - unsigned short ccrc = checksum_crc16_ccitt (packet + 1, size, 0xffff); + unsigned short ccrc = checksum_crc16_ccitt (packet + 1, size, 0xffff, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum (%04x %04x).", crc, ccrc); return DC_STATUS_PROTOCOL; diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 184bf92..600eaa9 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -296,7 +296,7 @@ mares_genius_isvalid (const unsigned char data[], size_t size, unsigned int type } unsigned short crc = array_uint16_le(data + size - 6); - unsigned short ccrc = checksum_crc16_ccitt(data + 4, size - 10, 0x0000); + unsigned short ccrc = checksum_crc16_ccitt(data + 4, size - 10, 0x0000, 0x0000); if (crc != ccrc) { return 0; } diff --git a/src/oceans_s1.c b/src/oceans_s1.c index e26979e..125d090 100644 --- a/src/oceans_s1.c +++ b/src/oceans_s1.c @@ -302,7 +302,7 @@ oceans_s1_xmodem_packet (oceans_s1_device_t *device, unsigned char seq, unsigned } unsigned short crc = array_uint16_be (packet + nbytes - 2); - unsigned short ccrc = checksum_crc16_ccitt (packet + 3, nbytes - 5, 0x0000); + unsigned short ccrc = checksum_crc16_ccitt (packet + 3, nbytes - 5, 0x0000, 0x0000); if (crc != ccrc) { ERROR (device->base.context, "Unexpected answer checksum (%04x %04x).", crc, ccrc); return DC_STATUS_PROTOCOL; diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 835fbcb..27c2fdb 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -177,7 +177,7 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device) // Verify the checksum of the handshake packet. unsigned short crc = array_uint16_le (handshake + SZ_HANDSHAKE); - unsigned short ccrc = checksum_crc16_ccitt (handshake, SZ_HANDSHAKE, 0xffff); + unsigned short ccrc = checksum_crc16_ccitt (handshake, SZ_HANDSHAKE, 0xffff, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum."); return DC_STATUS_PROTOCOL; @@ -280,7 +280,7 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) } unsigned short crc = array_uint16_le (answer + SZ_MEMORY); - unsigned short ccrc = checksum_crc16_ccitt (answer, SZ_MEMORY, 0xffff); + unsigned short ccrc = checksum_crc16_ccitt (answer, SZ_MEMORY, 0xffff, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum."); return DC_STATUS_PROTOCOL; diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index 6b059d6..bfe1c6a 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -224,7 +224,7 @@ reefnet_sensusultra_packet (reefnet_sensusultra_device_t *device, unsigned char // Verify the checksum of the packet. unsigned short crc = array_uint16_le (data + size - 2); - unsigned short ccrc = checksum_crc16_ccitt (data + header, size - header - 2, 0xffff); + unsigned short ccrc = checksum_crc16_ccitt (data + header, size - header - 2, 0xffff, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected answer checksum."); return DC_STATUS_PROTOCOL; @@ -477,7 +477,7 @@ reefnet_sensusultra_device_write_user (dc_device_t *abstract, const unsigned cha } // Send the checksum to the device. - unsigned short crc = checksum_crc16_ccitt (data, SZ_USER, 0xffff); + unsigned short crc = checksum_crc16_ccitt (data, SZ_USER, 0xffff, 0x0000); rc = reefnet_sensusultra_send_ushort (device, crc); if (rc != DC_STATUS_SUCCESS) return rc; diff --git a/src/seac_screen.c b/src/seac_screen.c index e9b5366..9b3796f 100644 --- a/src/seac_screen.c +++ b/src/seac_screen.c @@ -115,7 +115,7 @@ seac_screen_send (seac_screen_device_t *device, unsigned short cmd, const unsign if (size) { memcpy (packet + 5, data, size); } - crc = checksum_crc16_ccitt (packet, size + 5, 0xFFFF); + crc = checksum_crc16_ccitt (packet, size + 5, 0xFFFF, 0x0000); packet[size + 5] = (crc >> 8) & 0xFF; packet[size + 6] = (crc ) & 0xFF; @@ -165,7 +165,7 @@ seac_screen_receive (seac_screen_device_t *device, unsigned short cmd, unsigned // Verify the checksum. unsigned short crc = array_uint16_be (packet + 1 + length - 2); - unsigned short ccrc = checksum_crc16_ccitt (packet, 1 + length - 2, 0xFFFF); + unsigned short ccrc = checksum_crc16_ccitt (packet, 1 + length - 2, 0xFFFF, 0x0000); if (crc != ccrc) { ERROR (abstract->context, "Unexpected packet checksum (%04x %04x).", crc, ccrc); return DC_STATUS_PROTOCOL; @@ -486,8 +486,8 @@ seac_screen_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); // Check the header checksums. - if (checksum_crc16_ccitt (logbook[i].header, SZ_HEADER / 2, 0xFFFF) != 0 || - checksum_crc16_ccitt (logbook[i].header + SZ_HEADER / 2, SZ_HEADER / 2, 0xFFFF) != 0) { + if (checksum_crc16_ccitt (logbook[i].header, SZ_HEADER / 2, 0xFFFF, 0x0000) != 0 || + checksum_crc16_ccitt (logbook[i].header + SZ_HEADER / 2, SZ_HEADER / 2, 0xFFFF, 0x0000) != 0) { ERROR (abstract->context, "Unexpected header checksum."); status = DC_STATUS_DATAFORMAT; goto error_free_logbook; diff --git a/src/seac_screen_parser.c b/src/seac_screen_parser.c index 8c588d2..c4a855c 100644 --- a/src/seac_screen_parser.c +++ b/src/seac_screen_parser.c @@ -283,8 +283,8 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (abstract->size < SZ_HEADER) return DC_STATUS_DATAFORMAT; - if (checksum_crc16_ccitt (data, SZ_HEADER / 2, 0xFFFF) != 0 || - checksum_crc16_ccitt (data + SZ_HEADER / 2, SZ_HEADER / 2, 0xFFFF) != 0) { + if (checksum_crc16_ccitt (data, SZ_HEADER / 2, 0xFFFF, 0x0000) != 0 || + checksum_crc16_ccitt (data + SZ_HEADER / 2, SZ_HEADER / 2, 0xFFFF, 0x0000) != 0) { ERROR (abstract->context, "Unexpected header checksum."); return DC_STATUS_DATAFORMAT; } @@ -303,7 +303,7 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t while (offset + SZ_SAMPLE <= size) { dc_sample_value_t sample = {0}; - if (checksum_crc16_ccitt (data + offset, SZ_SAMPLE, 0xFFFF) != 0) { + if (checksum_crc16_ccitt (data + offset, SZ_SAMPLE, 0xFFFF, 0x0000) != 0) { ERROR (abstract->context, "Unexpected sample checksum."); return DC_STATUS_DATAFORMAT; }