version 1.5.28.1, 2019/12/18 20:00:18
|
version 1.9.4.1, 2024/10/29 01:22:08
|
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 - 2019 | Copyright 2004 - 2024 |
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 59 const crcPoly_t crc_Poly[] = {
|
Line 59 const crcPoly_t crc_Poly[] = {
|
{ 5, (u_int) 0x15, "CRC-5-ITU" }, |
{ 5, (u_int) 0x15, "CRC-5-ITU" }, |
{ 6, (u_int) 0x3, "CRC-6-ITU" }, |
{ 6, (u_int) 0x3, "CRC-6-ITU" }, |
{ 7, (u_int) 0x9, "CRC-7-MMC" }, |
{ 7, (u_int) 0x9, "CRC-7-MMC" }, |
{ 8, (u_int) 0x8D, "CRC-8-CCITT" }, | { 8, (u_int) 0x7, "CRC-8-CCITT" }, |
{ 10, (u_int) 0x233, "CRC-10" }, |
{ 10, (u_int) 0x233, "CRC-10" }, |
{ 11, (u_int) 0x385, "CRC-11-FlexRay" }, |
{ 11, (u_int) 0x385, "CRC-11-FlexRay" }, |
{ 12, (u_int) 0x80F, "CRC-12-Telco" }, |
{ 12, (u_int) 0x80F, "CRC-12-Telco" }, |
Line 67 const crcPoly_t crc_Poly[] = {
|
Line 67 const crcPoly_t crc_Poly[] = {
|
{ 16, (u_int) 0x8005, "CRC-16-IBM" }, |
{ 16, (u_int) 0x8005, "CRC-16-IBM" }, |
{ 24, (u_int) 0x864CFB, "CRC-24-Radix64" }, |
{ 24, (u_int) 0x864CFB, "CRC-24-Radix64" }, |
{ 30, (u_int) 0x2030B9C7, "CRC-30-CDMA" }, |
{ 30, (u_int) 0x2030B9C7, "CRC-30-CDMA" }, |
{ 32, (u_int) 0x04C11DB7, "CRC-32-802.3" } | { 32, (u_int) 0x04C11DB7, "CRC-32-802.3" }, |
| { 16, (u_int) 0x1021, "CRC-16-CCITT" }, |
| { 16, (u_int) 0x8408, "CRC-16-XMODEM" } |
}; |
}; |
|
|
|
|
Line 103 crcReflect(u_int crcNum, u_char crcBits)
|
Line 105 crcReflect(u_int crcNum, u_char crcBits)
|
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) |
{ |
{ |
const u_int bits = sizeof(int) * 8 - crcBits; | u_int bits = sizeof(int) * 8; |
u_int poly, crchibit, crc; |
u_int poly, crchibit, crc; |
register u_int i, j, b, ch; |
register u_int i, j, b, ch; |
|
|
Line 112 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha
|
Line 114 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha
|
switch (crcBits) { |
switch (crcBits) { |
case 1: |
case 1: |
poly = crc_Poly[0].poly_num; |
poly = crc_Poly[0].poly_num; |
|
bits -= crc_Poly[0].poly_bits; |
break; |
break; |
case 4: |
case 4: |
poly = crc_Poly[1].poly_num; |
poly = crc_Poly[1].poly_num; |
|
bits -= crc_Poly[1].poly_bits; |
break; |
break; |
case 5: |
case 5: |
poly = crc_Poly[2].poly_num; |
poly = crc_Poly[2].poly_num; |
|
bits -= crc_Poly[2].poly_bits; |
break; |
break; |
case 6: |
case 6: |
poly = crc_Poly[3].poly_num; |
poly = crc_Poly[3].poly_num; |
|
bits -= crc_Poly[3].poly_bits; |
break; |
break; |
case 7: |
case 7: |
poly = crc_Poly[4].poly_num; |
poly = crc_Poly[4].poly_num; |
|
bits -= crc_Poly[4].poly_bits; |
break; |
break; |
case 8: |
case 8: |
poly = crc_Poly[5].poly_num; |
poly = crc_Poly[5].poly_num; |
|
bits -= crc_Poly[5].poly_bits; |
break; |
break; |
case 10: |
case 10: |
poly = crc_Poly[6].poly_num; |
poly = crc_Poly[6].poly_num; |
|
bits -= crc_Poly[6].poly_bits; |
break; |
break; |
case 11: |
case 11: |
poly = crc_Poly[7].poly_num; |
poly = crc_Poly[7].poly_num; |
|
bits -= crc_Poly[7].poly_bits; |
break; |
break; |
case 12: |
case 12: |
poly = crc_Poly[8].poly_num; |
poly = crc_Poly[8].poly_num; |
|
bits -= crc_Poly[8].poly_bits; |
break; |
break; |
case 15: |
case 15: |
poly = crc_Poly[9].poly_num; |
poly = crc_Poly[9].poly_num; |
|
bits -= crc_Poly[9].poly_bits; |
break; |
break; |
case 16: |
case 16: |
poly = crc_Poly[10].poly_num; |
poly = crc_Poly[10].poly_num; |
|
bits -= crc_Poly[10].poly_bits; |
break; |
break; |
case 24: |
case 24: |
poly = crc_Poly[11].poly_num; |
poly = crc_Poly[11].poly_num; |
|
bits -= crc_Poly[11].poly_bits; |
break; |
break; |
case 30: |
case 30: |
poly = crc_Poly[12].poly_num; |
poly = crc_Poly[12].poly_num; |
|
bits -= crc_Poly[12].poly_bits; |
break; |
break; |
case 32: |
case 32: |
poly = crc_Poly[13].poly_num; |
poly = crc_Poly[13].poly_num; |
|
bits -= crc_Poly[13].poly_bits; |
break; |
break; |
|
case 161: |
|
poly = crc_Poly[14].poly_num; |
|
bits -= crc_Poly[14].poly_bits; |
|
crcBits = crc_Poly[14].poly_bits; |
|
break; |
|
case 162: |
|
poly = crc_Poly[15].poly_num; |
|
bits -= crc_Poly[15].poly_bits; |
|
crcBits = crc_Poly[15].poly_bits; |
|
break; |
default: |
default: |
elwix_SetErr(EINVAL, "crcCalc(): Unsupported CRC method!!!"); |
elwix_SetErr(EINVAL, "crcCalc(): Unsupported CRC method!!!"); |
return -1; |
return -1; |
Line 190 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha
|
Line 216 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_cha
|
|
|
|
|
/* |
/* |
* crc16() - Checksum in X/Y modem communication | * crc16_xy() - Checksum calculation in X/Y modem communication |
* |
* |
* @buf = Data for calculation |
* @buf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* return: Checksum |
* return: Checksum |
*/ |
*/ |
u_short |
u_short |
crc16(u_char * __restrict buf, int bufLen) | crc16_xy(u_char * __restrict buf, int bufLen) |
{ |
{ |
u_short crc, x; |
u_short crc, x; |
register u_short i; |
register u_short i; |
Line 227 crc16(u_char * __restrict buf, int bufLen)
|
Line 253 crc16(u_char * __restrict buf, int bufLen)
|
} |
} |
|
|
/* |
/* |
* crcIP() - Checksum in IP communication | * crc16_ccitt() - Checksum calculation |
* |
* |
* @buf = Data for calculation |
* @buf = Data for calculation |
* @bufLen = Length of data |
* @bufLen = Length of data |
* return: Checksum |
* return: Checksum |
*/ |
*/ |
u_short |
u_short |
crcIP(u_char * __restrict buf, int bufLen) | crc16_ccitt(u_char * __restrict buf, int bufLen) |
{ |
{ |
register u_int sum; | u_short crc; |
u_short last = 0, *nBuf = (u_short*) buf; | 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 |
|
* |
|
* @buf = Data for calculation |
|
* @len = Length of data in bytes |
|
* return: Checksum |
|
*/ |
|
u_short |
|
crcIP(u_short* __restrict buf, int len) |
|
{ |
|
register u_long sum = 0; |
|
|
assert(buf); |
assert(buf); |
|
|
for (sum = 0; bufLen > 1; bufLen -= 2) | for (sum = 0; len > 1; len -= 2) |
sum += *nBuf++; | sum += *buf++; |
if (bufLen == 1) { | if (len > 0) |
*(u_char*)(&last) += *(u_char*) nBuf; | sum += ((*buf) & htons(0xFF00)); |
sum += last; | |
} | |
|
|
sum = (sum >> 16) + (sum & 0xFFFF); |
sum = (sum >> 16) + (sum & 0xFFFF); |
sum += sum >> 16; |
sum += sum >> 16; |
|
|
return (u_short) ~sum; | return (u_short) (~sum); |
} |
} |
|
|
/* |
/* |
Line 265 crcIP(u_char * __restrict buf, int bufLen)
|
Line 313 crcIP(u_char * __restrict buf, int bufLen)
|
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) |
{ |
{ |
|
assert(th); |
|
|
struct psd_tcp { |
struct psd_tcp { |
struct in_addr src; |
struct in_addr src; |
struct in_addr dst; |
struct in_addr dst; |
Line 281 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
Line 331 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
buf.tcp_len = htons(sizeof buf.tcp); |
buf.tcp_len = htons(sizeof buf.tcp); |
memcpy(&buf.tcp, th, sizeof buf.tcp); |
memcpy(&buf.tcp, th, sizeof buf.tcp); |
|
|
return crcIP((u_char*) &buf, sizeof buf); | return crcIP((u_short*) &buf, sizeof buf); |
} |
} |
|
|
/* |
/* |
Line 295 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
Line 345 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
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) |
{ |
{ |
|
assert(uh); |
|
|
struct psd_udp { |
struct psd_udp { |
struct in_addr src; |
struct in_addr src; |
struct in_addr dst; |
struct in_addr dst; |
Line 311 crcUDP(struct in_addr src, struct in_addr dst, u_char
|
Line 363 crcUDP(struct in_addr src, struct in_addr dst, u_char
|
buf.udp_len = htons(sizeof buf.udp); |
buf.udp_len = htons(sizeof buf.udp); |
memcpy(&buf.udp, uh, sizeof buf.udp); |
memcpy(&buf.udp, uh, sizeof buf.udp); |
|
|
return crcIP((u_char*) &buf, sizeof buf); | return crcIP((u_short*) &buf, sizeof buf); |
} |
} |
|
|
|
|