Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2013 by Andreas Eversberg <jolly@eversberg.eu> |
| 3 | * (C) 2016 by Tom Tsou <tom.tsou@ettus.com> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | * |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | */ |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | #include <osmocom/core/crcgen.h> |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 27 | #include <osmocom/coding/gsm0503_parity.h> |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 28 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 29 | /*! \addtogroup parity |
| 30 | * @{ |
| 31 | * |
| 32 | * GSM TS 05.03 parity |
| 33 | * |
| 34 | * This module contains parity/crc code definitions for the various |
| 35 | * parity/crc schemes as defined in 3GPP TS 05.03 / 45.003 |
| 36 | * |
| 37 | * \file gsm0503_parity.c */ |
| 38 | |
| 39 | /*! GSM (SACCH) parity (FIRE code) |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 40 | * |
| 41 | * g(x) = (x^23 + 1)(x^17 + x^3 + 1) |
| 42 | * = x^40 + x^26 + x^23 + x^17 + x^3 + a1 |
| 43 | */ |
| 44 | const struct osmo_crc64gen_code gsm0503_fire_crc40 = { |
| 45 | .bits = 40, |
| 46 | .poly = 0x0004820009ULL, |
| 47 | .init = 0x0000000000ULL, |
| 48 | .remainder = 0xffffffffffULL, |
| 49 | }; |
| 50 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 51 | /*! GSM PDTCH CS-2, CS-3, CS-4 parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 52 | * |
| 53 | * g(x) = x^16 + x^12 + x^5 + 1 |
| 54 | */ |
| 55 | const struct osmo_crc16gen_code gsm0503_cs234_crc16 = { |
| 56 | .bits = 16, |
| 57 | .poly = 0x1021, |
| 58 | .init = 0x0000, |
| 59 | .remainder = 0xffff, |
| 60 | }; |
| 61 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 62 | /*! EDGE MCS header parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 63 | * |
| 64 | */ |
| 65 | const struct osmo_crc8gen_code gsm0503_mcs_crc8_hdr = { |
| 66 | .bits = 8, |
| 67 | .poly = 0x49, |
| 68 | .init = 0x00, |
| 69 | .remainder = 0xff, |
| 70 | }; |
| 71 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 72 | /*! EDGE MCS data parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 73 | * |
| 74 | */ |
| 75 | const struct osmo_crc16gen_code gsm0503_mcs_crc12 = { |
| 76 | .bits = 12, |
| 77 | .poly = 0x0d31, |
| 78 | .init = 0x0000, |
| 79 | .remainder = 0x0fff, |
| 80 | }; |
| 81 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 82 | /*! GSM RACH parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 83 | * |
| 84 | * g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1 |
| 85 | */ |
| 86 | const struct osmo_crc8gen_code gsm0503_rach_crc6 = { |
| 87 | .bits = 6, |
| 88 | .poly = 0x2f, |
| 89 | .init = 0x00, |
| 90 | .remainder = 0x3f, |
| 91 | }; |
| 92 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 93 | /*! GSM SCH parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 94 | * |
| 95 | * g(x) = x^10 + x^8 + x^6 + x^5 + x^4 + x^2 + 1 |
| 96 | */ |
| 97 | const struct osmo_crc16gen_code gsm0503_sch_crc10 = { |
| 98 | .bits = 10, |
| 99 | .poly = 0x175, |
| 100 | .init = 0x000, |
| 101 | .remainder = 0x3ff, |
| 102 | }; |
| 103 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 104 | /*! GSM TCH FR/HR/EFR parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 105 | * |
| 106 | * g(x) = x^3 + x + 1 |
| 107 | */ |
| 108 | const struct osmo_crc8gen_code gsm0503_tch_fr_crc3 = { |
| 109 | .bits = 3, |
| 110 | .poly = 0x3, |
| 111 | .init = 0x0, |
| 112 | .remainder = 0x7, |
| 113 | }; |
| 114 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 115 | /*! GSM TCH EFR parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 116 | * |
| 117 | * g(x) = x^8 + x^4 + x^3 + x^2 + 1 |
| 118 | */ |
| 119 | const struct osmo_crc8gen_code gsm0503_tch_efr_crc8 = { |
| 120 | .bits = 8, |
| 121 | .poly = 0x1d, |
| 122 | .init = 0x00, |
| 123 | .remainder = 0x00, |
| 124 | }; |
| 125 | |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 126 | /*! GSM AMR parity |
Piotr Krysik | 70c25a1 | 2017-01-03 08:01:23 +0100 | [diff] [blame] | 127 | * |
| 128 | * g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1 |
| 129 | */ |
| 130 | const struct osmo_crc8gen_code gsm0503_amr_crc6 = { |
| 131 | .bits = 6, |
| 132 | .poly = 0x2f, |
| 133 | .init = 0x00, |
| 134 | .remainder = 0x3f, |
| 135 | }; |
Piotr Krysik | 9e2e835 | 2018-02-27 12:16:25 +0100 | [diff] [blame] | 136 | |
| 137 | /*! @} */ |