blob: 13a3623e4622998f5d40702c862146f2fd7c79cf [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file crcXXgen.h
2 * Osmocom generic CRC routines (for max XX bits poly) header. */
Sylvain Munaut2749c0b2011-09-16 22:59:18 +02003/*
Sylvain Munaut2749c0b2011-09-16 22:59:18 +02004 * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020017 */
18
Sylvain Munaut12ba7782014-06-16 10:13:40 +020019#pragma once
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020020
Harald Welte197a4ac2017-10-16 14:29:26 +020021/*! \addtogroup crc
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020022 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020023 * \file crcXXgen.h.tpl */
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020024
25#include <stdint.h>
26#include <osmocom/core/bits.h>
27
28
Neels Hofmeyr87e45502017-06-20 00:17:59 +020029/*! structure describing a given CRC code of max XX bits */
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020030struct osmo_crcXXgen_code {
Neels Hofmeyr87e45502017-06-20 00:17:59 +020031 int bits; /*!< Actual number of bits of the CRC */
32 uintXX_t poly; /*!< Polynom (normal representation, MSB omitted */
33 uintXX_t init; /*!< Initialization value of the CRC state */
34 uintXX_t remainder; /*!< Remainder of the CRC (final XOR) */
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020035};
36
37uintXX_t osmo_crcXXgen_compute_bits(const struct osmo_crcXXgen_code *code,
38 const ubit_t *in, int len);
39int osmo_crcXXgen_check_bits(const struct osmo_crcXXgen_code *code,
40 const ubit_t *in, int len, const ubit_t *crc_bits);
41void osmo_crcXXgen_set_bits(const struct osmo_crcXXgen_code *code,
42 const ubit_t *in, int len, ubit_t *crc_bits);
43
44
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020045/*! @} */
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020046
Sylvain Munaut2749c0b2011-09-16 22:59:18 +020047/* vim: set syntax=c: */