version 1.5, 2017/12/08 00:07:48
|
version 1.6, 2019/12/30 18:11:16
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004 - 2015 | Copyright 2004 - 2019 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 46 SUCH DAMAGE.
|
Line 46 SUCH DAMAGE.
|
#include "global.h" |
#include "global.h" |
|
|
|
|
|
/* CRC16 poly */ |
|
const u_short crc_16poly = 0x1021; |
|
|
/* Adler module */ |
/* Adler module */ |
const u_int crc_modAdler = 0xFFF1L; |
const u_int crc_modAdler = 0xFFF1L; |
|
|
Line 73 const crcPoly_t crc_Poly[] = {
|
Line 76 const crcPoly_t crc_Poly[] = {
|
* |
* |
* @crcNum = Number for reflection |
* @crcNum = Number for reflection |
* @crcBits = Number width bits |
* @crcBits = Number width bits |
* return: -1 error, !=-1 reflecting number | * return: reflecting number |
*/ |
*/ |
u_int |
u_int |
crcReflect(u_int crcNum, u_char crcBits) |
crcReflect(u_int crcNum, u_char crcBits) |
Line 95 crcReflect(u_int crcNum, u_char crcBits)
|
Line 98 crcReflect(u_int crcNum, u_char crcBits)
|
* @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC) |
* @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC) |
* @initCRC = Initial CRC value |
* @initCRC = Initial CRC value |
* @xorCRC = Last xor CRC value |
* @xorCRC = Last xor CRC value |
* return: -1 error, !=-1 CRC checksum | * return: CRC checksum |
*/ |
*/ |
u_int |
u_int |
crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, u_char RevOpts, u_int initCRC, u_int xorCRC) |
crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, u_char RevOpts, u_int initCRC, u_int xorCRC) |
Line 187 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha
|
Line 190 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha
|
|
|
|
|
/* |
/* |
|
* crc16_ext() - Checksum ver.2 calculation in X/Y modem communication |
|
* |
|
* @buf = Data for calculation |
|
* @bufLen = Length of data |
|
* return: Checksum |
|
*/ |
|
u_short |
|
crc16_ext(u_char * __restrict buf, int bufLen) |
|
{ |
|
u_short crc, x; |
|
register u_short i; |
|
|
|
assert(buf); |
|
|
|
for (crc = 0; bufLen > 0; bufLen--, buf++) |
|
for (i = 0x80; i; i >>= 1) { |
|
x = crc >> 15; |
|
crc <<= 1; |
|
|
|
if (*buf & i) |
|
crc++; |
|
if (x) |
|
crc ^= crc_16poly; |
|
} |
|
|
|
for (i = 0; i < 16; i++) { |
|
x = crc >> 15; |
|
crc <<= 1; |
|
|
|
if (x) |
|
crc ^= crc_16poly; |
|
} |
|
|
|
return crc; |
|
} |
|
|
|
/* |
|
* crc16() - Checksum calculation in X/Y modem communication |
|
* |
|
* @buf = Data for calculation |
|
* @bufLen = Length of data |
|
* return: Checksum |
|
*/ |
|
u_short |
|
crc16(u_char * __restrict buf, int bufLen) |
|
{ |
|
u_short crc; |
|
register u_char i; |
|
|
|
for (crc = 0; bufLen > 0; bufLen--, buf++) { |
|
crc ^= (u_short) *buf << 8; |
|
for (i = 0x80; i; i >>= 1) |
|
if (crc & 0x8000) |
|
crc = crc << 1 ^ crc_16poly; |
|
else |
|
crc <<= 1; |
|
} |
|
|
|
return crc; |
|
} |
|
|
|
/* |
* crcIP() - Checksum in IP communication |
* crcIP() - Checksum in IP communication |
* |
* |
* @buf = Data for calculation |
* @buf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* return: -1 error, !=-1 Checksum | * return: Checksum |
*/ |
*/ |
u_short |
u_short |
crcIP(u_char * __restrict buf, int bufLen) |
crcIP(u_char * __restrict buf, int bufLen) |
Line 220 crcIP(u_char * __restrict buf, int bufLen)
|
Line 285 crcIP(u_char * __restrict buf, int bufLen)
|
* @buf = Data for calculation |
* @buf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* @th = TCP header |
* @th = TCP header |
* return: -1 error, !=-1 Checksum | * return: Checksum |
*/ |
*/ |
u_short |
u_short |
crcTCP(struct in_addr src, struct in_addr dst, u_char * __restrict th) |
crcTCP(struct in_addr src, struct in_addr dst, u_char * __restrict th) |
Line 250 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
Line 315 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
* @buf = Data for calculation |
* @buf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* @uh = UDP header |
* @uh = UDP header |
* return: -1 error, !=-1 Checksum | * return: Checksum |
*/ |
*/ |
u_short |
u_short |
crcUDP(struct in_addr src, struct in_addr dst, u_char * __restrict uh) |
crcUDP(struct in_addr src, struct in_addr dst, u_char * __restrict uh) |
Line 280 crcUDP(struct in_addr src, struct in_addr dst, u_char
|
Line 345 crcUDP(struct in_addr src, struct in_addr dst, u_char
|
* |
* |
* @nBuf = Data for calculation |
* @nBuf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* return: -1 error, !=-1 Checksum | * return: Checksum |
*/ |
*/ |
u_short |
u_short |
crcFletcher16(u_short * __restrict nBuf, int bufLen) |
crcFletcher16(u_short * __restrict nBuf, int bufLen) |
Line 312 crcFletcher16(u_short * __restrict nBuf, int bufLen)
|
Line 377 crcFletcher16(u_short * __restrict nBuf, int bufLen)
|
* |
* |
* @nBuf = Data for calculation |
* @nBuf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* return: -1 error, !=-1 Checksum | * return: Checksum |
*/ |
*/ |
u_int |
u_int |
crcFletcher(u_short * __restrict nBuf, int bufLen) |
crcFletcher(u_short * __restrict nBuf, int bufLen) |
Line 343 crcFletcher(u_short * __restrict nBuf, int bufLen)
|
Line 408 crcFletcher(u_short * __restrict nBuf, int bufLen)
|
* |
* |
* @psBuf = Data for calculation |
* @psBuf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* return: -1 error, !=-1 Checksum | * return: Checksum |
*/ |
*/ |
u_int |
u_int |
crcAdler(u_char * __restrict psBuf, int bufLen) |
crcAdler(u_char * __restrict psBuf, int bufLen) |