Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file crcXXgen.h |
| 2 | * Osmocom generic CRC routines (for max XX bits poly) header. */ |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 3 | /* |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 4 | * 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. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 23 | #pragma once |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 24 | |
Harald Welte | 197a4ac | 2017-10-16 14:29:26 +0200 | [diff] [blame] | 25 | /*! \addtogroup crc |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 26 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 27 | * \file crcXXgen.h.tpl */ |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 28 | |
| 29 | #include <stdint.h> |
| 30 | #include <osmocom/core/bits.h> |
| 31 | |
| 32 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 33 | /*! structure describing a given CRC code of max XX bits */ |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 34 | struct osmo_crcXXgen_code { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 35 | int bits; /*!< Actual number of bits of the CRC */ |
| 36 | uintXX_t poly; /*!< Polynom (normal representation, MSB omitted */ |
| 37 | uintXX_t init; /*!< Initialization value of the CRC state */ |
| 38 | uintXX_t remainder; /*!< Remainder of the CRC (final XOR) */ |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | uintXX_t osmo_crcXXgen_compute_bits(const struct osmo_crcXXgen_code *code, |
| 42 | const ubit_t *in, int len); |
| 43 | int osmo_crcXXgen_check_bits(const struct osmo_crcXXgen_code *code, |
| 44 | const ubit_t *in, int len, const ubit_t *crc_bits); |
| 45 | void osmo_crcXXgen_set_bits(const struct osmo_crcXXgen_code *code, |
| 46 | const ubit_t *in, int len, ubit_t *crc_bits); |
| 47 | |
| 48 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 49 | /*! @} */ |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 50 | |
Sylvain Munaut | 2749c0b | 2011-09-16 22:59:18 +0200 | [diff] [blame] | 51 | /* vim: set syntax=c: */ |