1: /*************************************************************************
2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
6: * $Id: aitcrc.h,v 1.3 2010/06/13 16:13:51 misho Exp $
7: *
8: *************************************************************************/
9: #ifndef __AITCRC_H
10: #define __AITCRC_H
11:
12:
13: #include <sys/types.h>
14:
15:
16: #define REVOPTS_REVERTBYTE 1
17: #define REVOPTS_REVERTCRC 2
18:
19:
20: struct tagCRCPoly {
21: u_char poly_bits;
22: u_int poly_num;
23: char poly_name[19];
24: }; // size 24bytes
25: typedef struct tagCRCPoly crcPoly_t;
26:
27:
28: // -------------------------------------------------------
29: // crc_GetErrno() Get error code of last operation
30: inline int crc_GetErrno();
31: // crc_GetError() Get error text of last operation
32: inline const char *crc_GetError();
33: // -------------------------------------------------------
34:
35: /*
36: * crcReflect() Reflect all bits of number
37: * @crcNum = Number for reflection
38: * @crcBits = Number width bits
39: * return: -1 error, !=-1 reflecting number
40: */
41: inline u_int crcReflect(u_int crcNum, u_char crcBits);
42: /*
43: * crcCalc() Generic CRC calculation function for many sub variants of CRC algorithms
44: * @psBuf = Data for calculation
45: * @bufLen = Length of data
46: * @crcBits = CRC algorithm bits (1, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 24, 30, 32)
47: * @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC)
48: * @initCRC = Initial CRC value
49: * @xorCRC = Last xor CRC value
50: * return: -1 error, !=-1 CRC checksum
51: */
52: inline u_int crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits,
53: u_char RevOpts, u_int initCRC, u_int xorCRC);
54:
55: /*
56: * crcIP() Checksum in IP communication
57: * @nBuf = Data for calculation
58: * @bufLen = Length of data
59: * return: -1 error, !=-1 Checksum
60: */
61: inline u_short crcIP(u_short * __restrict nBuf, int bufLen);
62: /*
63: * crcFletcher16() Fletcher-16 Checksum computing
64: * @nBuf = Data for calculation
65: * @bufLen = Length of data
66: * return: -1 error, !=-1 Checksum
67: */
68: inline u_short crcFletcher16(u_short * __restrict nBuf, int bufLen);
69: /*
70: * crcFletcher() Fletcher-32 Checksum computing
71: * @nBuf = Data for calculation
72: * @bufLen = Length of data
73: * return: -1 error, !=-1 Checksum
74: */
75: inline u_int crcFletcher(u_short * __restrict nBuf, int bufLen);
76: /*
77: * crcAdler() crcAdler-32 Checksum computing
78: * @psBuf = Data for calculation
79: * @bufLen = Length of data
80: * return: -1 error, !=-1 Checksum
81: */
82: inline u_int crcAdler(u_char * __restrict psBuf, int bufLen);
83:
84: /*
85: * crcEther() Checksum in Ethernet communication
86: * @psBuf = Data for calculation
87: * @bufLen = Length of data
88: * return: -1 error, !=-1 Checksum
89: */
90: #define crcEther(psBuf, bufLen) crcCalc((psBuf), (bufLen), 32, 3, 0xFFFFFFFF, 0xFFFFFFFF)
91:
92: /*
93: * crcPelco() Calculate Pelco D/P CRC
94: * @ver = Pelco protocol version (Dd | Pp)
95: * @pkt = Packet for calculate crc
96: * return: crc for packet, if is 0 check and crc_GetErrno() == 1
97: Pelco protocol not supported
98: */
99: inline u_char crcPelco(u_char ver, u_char *pkt);
100:
101:
102: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>