00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * crc.h 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: crc.h,v 1.4 2008/04/17 14:27:00 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 /*! \page crc_page CRC 00031 00032 \section crc_page_sec_1 What does it do? 00033 00034 \section crc_page_sec_2 How does it work? 00035 */ 00036 00037 #if !defined(_SPANDSP_CRC_H_) 00038 #define _SPANDSP_CRC_H_ 00039 00040 #if defined(__cplusplus) 00041 extern "C" 00042 { 00043 #endif 00044 00045 /*! \brief Calculate the ITU/CCITT CRC-32 value in buffer. 00046 \param buf The buffer containing the data. 00047 \param len The length of the frame. 00048 \param crc The initial CRC value. This is usually 0xFFFFFFFF, or 0 for a new block (it depends on 00049 the application). It is previous returned CRC value for the continuation of a block. 00050 \return The CRC value. 00051 */ 00052 uint32_t crc_itu32_calc(const uint8_t *buf, int len, uint32_t crc); 00053 00054 /*! \brief Append an ITU/CCITT CRC-32 value to a frame. 00055 \param buf The buffer containing the frame. This must be at least 2 bytes longer than 00056 the frame it contains, to allow room for the CRC value. 00057 \param len The length of the frame. 00058 \return The new length of the frame. 00059 */ 00060 int crc_itu32_append(uint8_t *buf, int len); 00061 00062 /*! \brief Check the ITU/CCITT CRC-32 value in a frame. 00063 \param buf The buffer containing the frame. 00064 \param len The length of the frame. 00065 \return TRUE if the CRC is OK, else FALSE. 00066 */ 00067 int crc_itu32_check(const uint8_t *buf, int len); 00068 00069 /*! \brief Calculate the ITU/CCITT CRC-16 value in buffer. 00070 \param buf The buffer containing the data. 00071 \param len The length of the frame. 00072 \param crc The initial CRC value. This is usually 0xFFFF, or 0 for a new block (it depends on 00073 the application). It is previous returned CRC value for the continuation of a block. 00074 \return The CRC value. 00075 */ 00076 uint16_t crc_itu16_calc(const uint8_t *buf, int len, uint16_t crc); 00077 00078 /*! \brief Append an ITU/CCITT CRC-16 value to a frame. 00079 \param buf The buffer containing the frame. This must be at least 2 bytes longer than 00080 the frame it contains, to allow room for the CRC value. 00081 \param len The length of the frame. 00082 \return The new length of the frame. 00083 */ 00084 int crc_itu16_append(uint8_t *buf, int len); 00085 00086 /*! \brief Check the ITU/CCITT CRC-16 value in a frame. 00087 \param buf The buffer containing the frame. 00088 \param len The length of the frame. 00089 \return TRUE if the CRC is OK, else FALSE. 00090 */ 00091 int crc_itu16_check(const uint8_t *buf, int len); 00092 00093 #if defined(__cplusplus) 00094 } 00095 #endif 00096 00097 #endif 00098 /*- End of file ------------------------------------------------------------*/