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