Annotation of libaitcrc/inc/aitcrc.h, revision 1.3.2.2

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.3.2.2 ! misho       6: * $Id: aitcrc.h,v 1.3.2.1 2010/06/13 16:29:02 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.3       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.3.2.1   misho      35: 
1.2       misho      36: /*
                     37:  * crcReflect() Reflect all bits of number 
                     38:  * @crcNum = Number for reflection
                     39:  * @crcBits = Number width bits 
                     40:  * return: -1 error, !=-1 reflecting number
                     41:  */
1.3       misho      42: inline u_int crcReflect(u_int crcNum, u_char crcBits);
1.2       misho      43: /*
                     44:  * crcCalc() Generic CRC calculation function for many sub variants of CRC algorithms
                     45:  * @psBuf = Data for calculation
                     46:  * @bufLen = Length of data
                     47:  * @crcBits = CRC algorithm bits (1, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 24, 30, 32)
                     48:  * @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC)
                     49:  * @initCRC = Initial CRC value
                     50:  * @xorCRC = Last xor CRC value
                     51:  * return: -1 error, !=-1 CRC checksum
                     52:  */
1.3       misho      53: inline u_int crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, 
                     54:                u_char RevOpts, u_int initCRC, u_int xorCRC);
1.1       misho      55: 
1.2       misho      56: /*
                     57:  * crcIP() Checksum in IP communication
                     58:  * @nBuf = Data for calculation
                     59:  * @bufLen = Length of data
                     60:  * return: -1 error, !=-1 Checksum
                     61:  */
1.1       misho      62: inline u_short crcIP(u_short * __restrict nBuf, int bufLen);
1.2       misho      63: /*
1.3       misho      64:  * crcFletcher16() Fletcher-16 Checksum computing
1.2       misho      65:  * @nBuf = Data for calculation
                     66:  * @bufLen = Length of data
                     67:  * return: -1 error, !=-1 Checksum
                     68:  */
1.3       misho      69: inline u_short crcFletcher16(u_short * __restrict nBuf, int bufLen);
                     70: /*
                     71:  * crcFletcher() Fletcher-32 Checksum computing
                     72:  * @nBuf = Data for calculation
                     73:  * @bufLen = Length of data
                     74:  * return: -1 error, !=-1 Checksum
                     75:  */
                     76: inline u_int crcFletcher(u_short * __restrict nBuf, int bufLen);
1.2       misho      77: /*
                     78:  * crcAdler() crcAdler-32 Checksum computing
                     79:  * @psBuf = Data for calculation
                     80:  * @bufLen = Length of data
                     81:  * return: -1 error, !=-1 Checksum
                     82:  */
1.3       misho      83: inline u_int crcAdler(u_char * __restrict psBuf, int bufLen);
1.1       misho      84: 
1.2       misho      85: /*
                     86:  * crcEther() Checksum in Ethernet communication
                     87:  * @psBuf = Data for calculation
                     88:  * @bufLen = Length of data
                     89:  * return: -1 error, !=-1 Checksum
                     90:  */
1.3       misho      91: #define crcEther(psBuf, bufLen) crcCalc((psBuf), (bufLen), 32, 3, 0xFFFFFFFF, 0xFFFFFFFF)
1.1       misho      92: 
1.3.2.1   misho      93: 
1.2       misho      94: /*
                     95:  * crcPelco() Calculate Pelco D/P CRC
                     96:  * @ver = Pelco protocol version (Dd | Pp)
                     97:  * @pkt = Packet for calculate crc
                     98:  * return: crc for packet, if is 0 check and crc_GetErrno() == 1 
                     99:        Pelco protocol not supported
                    100:  */
                    101: inline u_char crcPelco(u_char ver, u_char *pkt);
                    102: 
1.1       misho     103: 
1.3.2.1   misho     104: /*
                    105:  * hash_varchar() Compute index hash by variable length string
                    106:  * @csStr = Input data buffer
                    107:  * @nStrLen = Length of data buffer
                    108:  * @nVer = Version of algorythm; 0 - original, 1 - AITNET variant
                    109:  * return: Hash value
                    110: */
                    111: inline u_int hash_varchar(const char *csStr, int nStrLen, int nVer);
                    112: /*
                    113:  * hash_bernstein() Compute index hash by Bernstein
                    114:  * @csStr = Input data buffer
                    115:  * @nStrLen = Length of data buffer
                    116:  * @nVer = Version of algorythm; 0 - Bernstein, 1 - DJBX33A variant
                    117:  * return: Hash value
                    118: */
                    119: inline u_int hash_bernstein(const char *csStr, int nStrLen, int nVer);
                    120: /*
                    121:  * hash_jenkins() Compute index hash by Jenkins (one-at-a-time)
                    122:  * @csStr = Input data buffer
                    123:  * @nStrLen = Length of data buffer
                    124:  * return: Hash value
                    125: */
                    126: inline u_int hash_jenkins(const char *csStr, int nStrLen);
                    127: /*
1.3.2.2 ! misho     128:  * hash_reddragon() Compute index hash by Red Dragon
        !           129:  * @csStr = Input data buffer
        !           130:  * @nStrLen = Length of data buffer
        !           131:  * return: Hash value
        !           132: */
        !           133: inline u_int hash_reddragon(const char *csStr, int nStrLen);
        !           134: /*
1.3.2.1   misho     135:  * hash_fnv1() Compute index hash by FNV-1
                    136:  * @csStr = Input data buffer
                    137:  * @nStrLen = Length of data buffer
                    138:  * @nVer = Version of algorythm; 0 - FNV-1, 1 - FNV-1a (best avalanche)
                    139:  * return: Hash value
                    140: */
                    141: inline u_int hash_fnv1(const char *csStr, int nStrLen, int nVer);
                    142: 
                    143: /*
                    144:  * hash_fnv() Compute index hash by FNV-1a
                    145:  * @csStr = Input data buffer
                    146:  * @nStrLen = Length of data buffer
                    147:  * return: Hash value
                    148: */
                    149: #define hash_fnv(str, len)     hash_fnv1((str), (len), 1)
                    150: 
                    151: 
1.1       misho     152: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>