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

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.6     ! misho       6: * $Id: aitcrc.h,v 1.5.4.1 2012/08/29 08:33:06 misho Exp $
1.1       misho       7: *
1.4       misho       8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
1.5       misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
1.4       misho      16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
1.1       misho      46: #ifndef __AITCRC_H
                     47: #define __AITCRC_H
                     48: 
                     49: 
1.2       misho      50: #include <sys/types.h>
                     51: 
                     52: 
1.1       misho      53: #define REVOPTS_REVERTBYTE     1
                     54: #define REVOPTS_REVERTCRC      2
                     55: 
                     56: 
                     57: struct tagCRCPoly {
                     58:        u_char  poly_bits;
1.3       misho      59:        u_int   poly_num;
1.1       misho      60:        char    poly_name[19];
1.5       misho      61: };     /* size 24bytes */
1.1       misho      62: typedef struct tagCRCPoly crcPoly_t;
                     63: 
                     64: 
1.2       misho      65: // crc_GetErrno() Get error code of last operation
1.1       misho      66: inline int crc_GetErrno();
1.2       misho      67: // crc_GetError() Get error text of last operation
1.1       misho      68: inline const char *crc_GetError();
                     69: 
1.4       misho      70: 
1.2       misho      71: /*
1.5       misho      72:  * crcReflect() - Reflect all bits of number 
                     73:  *
1.2       misho      74:  * @crcNum = Number for reflection
                     75:  * @crcBits = Number width bits 
                     76:  * return: -1 error, !=-1 reflecting number
                     77:  */
1.5       misho      78: inline unsigned int crcReflect(unsigned int crcNum, unsigned char crcBits);
1.2       misho      79: /*
1.5       misho      80:  * crcCalc() - Generic CRC calculation function for many sub variants of CRC algorithms
                     81:  *
1.2       misho      82:  * @psBuf = Data for calculation
                     83:  * @bufLen = Length of data
                     84:  * @crcBits = CRC algorithm bits (1, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 24, 30, 32)
                     85:  * @RevOpts = Options for computation (REVOPTS_REVERTBYTE, REVOPTS_REVERTCRC)
                     86:  * @initCRC = Initial CRC value
                     87:  * @xorCRC = Last xor CRC value
                     88:  * return: -1 error, !=-1 CRC checksum
                     89:  */
1.5       misho      90: inline unsigned int crcCalc(unsigned char * __restrict psBuf, unsigned int bufLen, 
                     91:                unsigned char crcBits, unsigned char RevOpts, 
                     92:                unsigned int initCRC, unsigned int xorCRC);
1.1       misho      93: 
1.2       misho      94: /*
1.5       misho      95:  * crcIP() - Checksum in IP communication
                     96:  *
                     97:  * @buf = Data for calculation
1.2       misho      98:  * @bufLen = Length of data
                     99:  * return: -1 error, !=-1 Checksum
                    100:  */
1.5       misho     101: inline unsigned short crcIP(unsigned char * __restrict buf, int bufLen);
1.2       misho     102: /*
1.5       misho     103:  * crcFletcher16() - Fletcher-16 Checksum computing
                    104:  *
1.2       misho     105:  * @nBuf = Data for calculation
                    106:  * @bufLen = Length of data
                    107:  * return: -1 error, !=-1 Checksum
                    108:  */
1.5       misho     109: inline unsigned short crcFletcher16(unsigned short * __restrict nBuf, int bufLen);
1.3       misho     110: /*
1.5       misho     111:  * crcFletcher() - Fletcher-32 Checksum computing
                    112:  *
1.3       misho     113:  * @nBuf = Data for calculation
                    114:  * @bufLen = Length of data
                    115:  * return: -1 error, !=-1 Checksum
                    116:  */
1.5       misho     117: inline unsigned int crcFletcher(unsigned short * __restrict nBuf, int bufLen);
1.2       misho     118: /*
1.5       misho     119:  * crcAdler() - crcAdler-32 Checksum computing
                    120:  *
1.2       misho     121:  * @psBuf = Data for calculation
                    122:  * @bufLen = Length of data
                    123:  * return: -1 error, !=-1 Checksum
                    124:  */
1.5       misho     125: inline unsigned int crcAdler(unsigned char * __restrict psBuf, int bufLen);
1.1       misho     126: 
1.2       misho     127: /*
1.5       misho     128:  * crcEther() - Checksum in Ethernet communication
                    129:  *
1.2       misho     130:  * @psBuf = Data for calculation
                    131:  * @bufLen = Length of data
                    132:  * return: -1 error, !=-1 Checksum
                    133:  */
1.3       misho     134: #define crcEther(psBuf, bufLen) crcCalc((psBuf), (bufLen), 32, 3, 0xFFFFFFFF, 0xFFFFFFFF)
1.1       misho     135: 
1.4       misho     136: 
1.2       misho     137: /*
1.5       misho     138:  * crcPelco() - Calculate Pelco D/P CRC
                    139:  *
1.2       misho     140:  * @ver = Pelco protocol version (Dd | Pp)
                    141:  * @pkt = Packet for calculate crc
                    142:  * return: crc for packet, if is 0 check and crc_GetErrno() == 1 
                    143:        Pelco protocol not supported
                    144:  */
1.5       misho     145: inline unsigned char crcPelco(unsigned char ver, unsigned char *pkt);
1.2       misho     146: 
1.1       misho     147: 
1.4       misho     148: /*
1.5       misho     149:  * hash_varchar() - Compute index hash by variable length string
                    150:  *
1.4       misho     151:  * @csStr = Input data buffer
                    152:  * @nStrLen = Length of data buffer
                    153:  * @nVer = Version of algorythm; 0 - original, 1 - AITNET variant
                    154:  * return: Hash value
                    155: */
1.5       misho     156: inline unsigned int hash_varchar(const char *csStr, int nStrLen, int nVer);
1.4       misho     157: /*
1.5       misho     158:  * hash_bernstein() - Compute index hash by Bernstein
                    159:  *
1.4       misho     160:  * @csStr = Input data buffer
                    161:  * @nStrLen = Length of data buffer
                    162:  * @nVer = Version of algorythm; 0 - Bernstein, 1 - DJBX33A variant
                    163:  * return: Hash value
                    164: */
1.5       misho     165: inline unsigned int hash_bernstein(const char *csStr, int nStrLen, int nVer);
1.4       misho     166: /*
1.5       misho     167:  * hash_jenkins() - Compute index hash by Jenkins (one-at-a-time)
                    168:  *
1.4       misho     169:  * @csStr = Input data buffer
                    170:  * @nStrLen = Length of data buffer
                    171:  * return: Hash value
                    172: */
1.5       misho     173: inline unsigned int hash_jenkins(const char *csStr, int nStrLen);
1.4       misho     174: /*
1.6     ! misho     175:  * hash_jenkins32() - Fast Jenkins hash function
        !           176:  *
        !           177:  * @buf = Input buffer
        !           178:  * @len = Length of buffer
        !           179:  * @prevhash = Previous hash, if participate in continuing hash
        !           180:  * return: Hash value
        !           181:  */
        !           182: unsigned int hash_jenkins32(const unsigned int *buf, int len, unsigned int prevhash);
        !           183: /*
1.5       misho     184:  * hash_reddragon() - Compute index hash by Red Dragon
                    185:  *
1.4       misho     186:  * @csStr = Input data buffer
                    187:  * @nStrLen = Length of data buffer
                    188:  * return: Hash value
                    189: */
1.5       misho     190: inline unsigned int hash_reddragon(const char *csStr, int nStrLen);
1.4       misho     191: /*
1.5       misho     192:  * hash_fnv1() - Compute index hash by FNV-1
                    193:  *
1.4       misho     194:  * @csStr = Input data buffer
                    195:  * @nStrLen = Length of data buffer
                    196:  * @nVer = Version of algorythm; 0 - FNV-1, 1 - FNV-1a (best avalanche)
                    197:  * return: Hash value
                    198: */
1.5       misho     199: inline unsigned int hash_fnv1(const char *csStr, int nStrLen, int nVer);
1.4       misho     200: 
                    201: /*
1.5       misho     202:  * hash_fnv() - Compute index hash by FNV-1a
                    203:  *
1.4       misho     204:  * @csStr = Input data buffer
                    205:  * @nStrLen = Length of data buffer
                    206:  * return: Hash value
                    207: */
                    208: #define hash_fnv(str, len)     hash_fnv1((str), (len), 1)
                    209: 
                    210: 
1.1       misho     211: #endif

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