Annotation of libaitcrc/inc/aitcrc.h, revision 1.2.2.1
1.1 misho 1: /*************************************************************************
2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.2.2.1 ! misho 6: * $Id: aitcrc.h,v 1.2 2010/01/20 00:04:45 misho Exp $
1.1 misho 7: *
8: *************************************************************************/
9: #ifndef __AITCRC_H
10: #define __AITCRC_H
11:
12:
1.2 misho 13: #include <sys/types.h>
14:
15:
1.1 misho 16: #define REVOPTS_REVERTBYTE 1
17: #define REVOPTS_REVERTCRC 2
18:
19:
20: struct tagCRCPoly {
21: u_char poly_bits;
1.2.2.1 ! misho 22: u_int poly_num;
1.1 misho 23: char poly_name[19];
24: }; // size 24bytes
25: typedef struct tagCRCPoly crcPoly_t;
26:
27:
1.2 misho 28: // -------------------------------------------------------
29: // crc_GetErrno() Get error code of last operation
1.1 misho 30: inline int crc_GetErrno();
1.2 misho 31: // crc_GetError() Get error text of last operation
1.1 misho 32: inline const char *crc_GetError();
1.2 misho 33: // -------------------------------------------------------
1.1 misho 34:
1.2 misho 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: */
1.2.2.1 ! misho 41: inline u_int crcReflect(u_int crcNum, u_char crcBits);
1.2 misho 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: */
1.2.2.1 ! misho 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);
1.1 misho 54:
1.2 misho 55: /*
56: * crcIP() Checksum in IP communication
57: * @nBuf = Data for calculation
58: * @bufLen = Length of data
59: * return: -1 error, !=-1 Checksum
60: */
1.1 misho 61: inline u_short crcIP(u_short * __restrict nBuf, int bufLen);
1.2 misho 62: /*
1.2.2.1 ! misho 63: * crcFletcher16() Fletcher-16 Checksum computing
1.2 misho 64: * @nBuf = Data for calculation
65: * @bufLen = Length of data
66: * return: -1 error, !=-1 Checksum
67: */
1.2.2.1 ! misho 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);
1.2 misho 76: /*
77: * crcAdler() crcAdler-32 Checksum computing
78: * @psBuf = Data for calculation
79: * @bufLen = Length of data
80: * return: -1 error, !=-1 Checksum
81: */
1.2.2.1 ! misho 82: inline u_int crcAdler(u_char * __restrict psBuf, int bufLen);
1.1 misho 83:
1.2 misho 84: /*
85: * crcEther() Checksum in Ethernet communication
86: * @psBuf = Data for calculation
87: * @bufLen = Length of data
88: * return: -1 error, !=-1 Checksum
89: */
1.2.2.1 ! misho 90: #define crcEther(psBuf, bufLen) crcCalc((psBuf), (bufLen), 32, 3, 0xFFFFFFFF, 0xFFFFFFFF)
1.1 misho 91:
1.2 misho 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:
1.1 misho 101:
102: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>