spandsp: crc.h Source File

spandsp 0.0.6

crc.h
Go to the documentation of this file.
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * crc.h
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26/*! \file */
27
28/*! \page crc_page CRC
29
30\section crc_page_sec_1 What does it do?
31
32\section crc_page_sec_2 How does it work?
33*/
34
35#if !defined(_SPANDSP_CRC_H_)
36#define _SPANDSP_CRC_H_
37
38#if defined(__cplusplus)
39extern "C"
40{
41#endif
42
43/*! \brief Calculate the ITU/CCITT CRC-32 value in buffer.
44 \param buf The buffer containing the data.
45 \param len The length of the frame.
46 \param crc The initial CRC value. This is usually 0xFFFFFFFF, or 0 for a new block (it depends on
47 the application). It is previous returned CRC value for the continuation of a block.
48 \return The CRC value.
49*/
50SPAN_DECLARE(uint32_t) crc_itu32_calc(const uint8_t *buf, int len, uint32_t crc);
51
52/*! \brief Append an ITU/CCITT CRC-32 value to a frame.
53 \param buf The buffer containing the frame. This must be at least 2 bytes longer than
54 the frame it contains, to allow room for the CRC value.
55 \param len The length of the frame.
56 \return The new length of the frame.
57*/
58SPAN_DECLARE(int) crc_itu32_append(uint8_t *buf, int len);
59
60/*! \brief Check the ITU/CCITT CRC-32 value in a frame.
61 \param buf The buffer containing the frame.
62 \param len The length of the frame.
63 \return TRUE if the CRC is OK, else FALSE.
64*/
65SPAN_DECLARE(int) crc_itu32_check(const uint8_t *buf, int len);
66
67/*! \brief Calculate the ITU/CCITT CRC-16 value in buffer by whole bytes.
68 \param buf The buffer containing the data.
69 \param len The length of the frame.
70 \param crc The initial CRC value. This is usually 0xFFFF, or 0 for a new block (it depends on
71 the application). It is previous returned CRC value for the continuation of a block.
72 \return The CRC value.
73*/
74SPAN_DECLARE(uint16_t) crc_itu16_calc(const uint8_t *buf, int len, uint16_t crc);
75
76/*! \brief Calculate the ITU/CCITT CRC-16 value of some bits from a byte.
77 \param buf The buffer containing the byte of data.
78 \param len The number of bits, starting from the LSB.
79 \param crc The initial CRC value. This is usually 0xFFFF, or 0 for a new block (it depends on
80 the application). It is previous returned CRC value for the continuation of a block.
81 \return The CRC value.
82*/
83SPAN_DECLARE(uint16_t) crc_itu16_bits(uint8_t buf, int len, uint16_t crc);
84
85/*! \brief Append an ITU/CCITT CRC-16 value to a frame.
86 \param buf The buffer containing the frame. This must be at least 2 bytes longer than
87 the frame it contains, to allow room for the CRC value.
88 \param len The length of the frame.
89 \return The new length of the frame.
90*/
91SPAN_DECLARE(int) crc_itu16_append(uint8_t *buf, int len);
92
93/*! \brief Check the ITU/CCITT CRC-16 value in a frame.
94 \param buf The buffer containing the frame.
95 \param len The length of the frame.
96 \return TRUE if the CRC is OK, else FALSE.
97*/
98SPAN_DECLARE(int) crc_itu16_check(const uint8_t *buf, int len);
99
100#if defined(__cplusplus)
101}
102#endif
103
104#endif
105/*- End of file ------------------------------------------------------------*/
crc_itu32_check
int crc_itu32_check(const uint8_t *buf, int len)
Check the ITU/CCITT CRC-32 value in a frame.
Definition crc.c:105
crc_itu16_append
int crc_itu16_append(uint8_t *buf, int len)
Append an ITU/CCITT CRC-16 value to a frame.
Definition crc.c:179
crc_itu16_check
int crc_itu16_check(const uint8_t *buf, int len)
Check the ITU/CCITT CRC-16 value in a frame.
Definition crc.c:196
crc_itu32_append
int crc_itu32_append(uint8_t *buf, int len)
Append an ITU/CCITT CRC-32 value to a frame.
Definition crc.c:86
crc_itu16_calc
uint16_t crc_itu16_calc(const uint8_t *buf, int len, uint16_t crc)
Calculate the ITU/CCITT CRC-16 value in buffer by whole bytes.
Definition crc.c:153
crc_itu32_calc
uint32_t crc_itu32_calc(const uint8_t *buf, int len, uint32_t crc)
Calculate the ITU/CCITT CRC-32 value in buffer.
Definition crc.c:76
crc_itu16_bits
uint16_t crc_itu16_bits(uint8_t buf, int len, uint16_t crc)
Calculate the ITU/CCITT CRC-16 value of some bits from a byte.
Definition crc.c:163