summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/crcXXgen.h.tpl
blob: 823f21f2e46492725ec120a3ae9eedcba79d6c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*! \file crcXXgen.h
 * Osmocom generic CRC routines (for max XX bits poly) header. */
/*
 * Copyright (C) 2011  Sylvain Munaut <tnt@246tNt.com>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#pragma once

/*! \addtogroup crc
 *  @{
 * \file crcXXgen.h.tpl */

#include <stdint.h>
#include <osmocom/core/bits.h>


/*! structure describing a given CRC code of max XX bits */
struct osmo_crcXXgen_code {
	int bits;           /*!< Actual number of bits of the CRC */
	uintXX_t poly;      /*!< Polynom (normal representation, MSB omitted */
	uintXX_t init;      /*!< Initialization value of the CRC state */
	uintXX_t remainder; /*!< Remainder of the CRC (final XOR) */
};

uintXX_t osmo_crcXXgen_compute_bits(const struct osmo_crcXXgen_code *code,
                                    const ubit_t *in, int len);
int osmo_crcXXgen_check_bits(const struct osmo_crcXXgen_code *code,
                             const ubit_t *in, int len, const ubit_t *crc_bits);
void osmo_crcXXgen_set_bits(const struct osmo_crcXXgen_code *code,
                            const ubit_t *in, int len, ubit_t *crc_bits);


/*! @} */

/* vim: set syntax=c: */