blob: 874114ff27d248075e3edd0aaba083fa5b1bb378 [file] [log] [blame]
Piotr Krysik70c25a12017-01-03 08:01:23 +01001/*
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 Krysik9e2e8352018-02-27 12:16:25 +01007 * SPDX-License-Identifier: GPL-2.0+
8 *
Piotr Krysik70c25a12017-01-03 08:01:23 +01009 * 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 Krysik9e2e8352018-02-27 12:16:25 +010027#include <osmocom/coding/gsm0503_parity.h>
Piotr Krysik70c25a12017-01-03 08:01:23 +010028
Piotr Krysik9e2e8352018-02-27 12:16:25 +010029/*! \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 Krysik70c25a12017-01-03 08:01:23 +010040 *
41 * g(x) = (x^23 + 1)(x^17 + x^3 + 1)
42 * = x^40 + x^26 + x^23 + x^17 + x^3 + a1
43 */
44const struct osmo_crc64gen_code gsm0503_fire_crc40 = {
45 .bits = 40,
46 .poly = 0x0004820009ULL,
47 .init = 0x0000000000ULL,
48 .remainder = 0xffffffffffULL,
49};
50
Piotr Krysik9e2e8352018-02-27 12:16:25 +010051/*! GSM PDTCH CS-2, CS-3, CS-4 parity
Piotr Krysik70c25a12017-01-03 08:01:23 +010052 *
53 * g(x) = x^16 + x^12 + x^5 + 1
54 */
55const struct osmo_crc16gen_code gsm0503_cs234_crc16 = {
56 .bits = 16,
57 .poly = 0x1021,
58 .init = 0x0000,
59 .remainder = 0xffff,
60};
61
Piotr Krysik9e2e8352018-02-27 12:16:25 +010062/*! EDGE MCS header parity
Piotr Krysik70c25a12017-01-03 08:01:23 +010063 *
64 */
65const struct osmo_crc8gen_code gsm0503_mcs_crc8_hdr = {
66 .bits = 8,
67 .poly = 0x49,
68 .init = 0x00,
69 .remainder = 0xff,
70};
71
Piotr Krysik9e2e8352018-02-27 12:16:25 +010072/*! EDGE MCS data parity
Piotr Krysik70c25a12017-01-03 08:01:23 +010073 *
74 */
75const struct osmo_crc16gen_code gsm0503_mcs_crc12 = {
76 .bits = 12,
77 .poly = 0x0d31,
78 .init = 0x0000,
79 .remainder = 0x0fff,
80};
81
Piotr Krysik9e2e8352018-02-27 12:16:25 +010082/*! GSM RACH parity
Piotr Krysik70c25a12017-01-03 08:01:23 +010083 *
84 * g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1
85 */
86const struct osmo_crc8gen_code gsm0503_rach_crc6 = {
87 .bits = 6,
88 .poly = 0x2f,
89 .init = 0x00,
90 .remainder = 0x3f,
91};
92
Piotr Krysik9e2e8352018-02-27 12:16:25 +010093/*! GSM SCH parity
Piotr Krysik70c25a12017-01-03 08:01:23 +010094 *
95 * g(x) = x^10 + x^8 + x^6 + x^5 + x^4 + x^2 + 1
96 */
97const struct osmo_crc16gen_code gsm0503_sch_crc10 = {
98 .bits = 10,
99 .poly = 0x175,
100 .init = 0x000,
101 .remainder = 0x3ff,
102};
103
Piotr Krysik9e2e8352018-02-27 12:16:25 +0100104/*! GSM TCH FR/HR/EFR parity
Piotr Krysik70c25a12017-01-03 08:01:23 +0100105 *
106 * g(x) = x^3 + x + 1
107 */
108const struct osmo_crc8gen_code gsm0503_tch_fr_crc3 = {
109 .bits = 3,
110 .poly = 0x3,
111 .init = 0x0,
112 .remainder = 0x7,
113};
114
Piotr Krysik9e2e8352018-02-27 12:16:25 +0100115/*! GSM TCH EFR parity
Piotr Krysik70c25a12017-01-03 08:01:23 +0100116 *
117 * g(x) = x^8 + x^4 + x^3 + x^2 + 1
118 */
119const struct osmo_crc8gen_code gsm0503_tch_efr_crc8 = {
120 .bits = 8,
121 .poly = 0x1d,
122 .init = 0x00,
123 .remainder = 0x00,
124};
125
Piotr Krysik9e2e8352018-02-27 12:16:25 +0100126/*! GSM AMR parity
Piotr Krysik70c25a12017-01-03 08:01:23 +0100127 *
128 * g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1
129 */
130const struct osmo_crc8gen_code gsm0503_amr_crc6 = {
131 .bits = 6,
132 .poly = 0x2f,
133 .init = 0x00,
134 .remainder = 0x3f,
135};
Piotr Krysik9e2e8352018-02-27 12:16:25 +0100136
137/*! @} */