From: Max msuraev@sysmocom.de
Add python utility to generate .c code with state/output tables for convolutional encoder/decoder based on polynomial description of the code. If argument given it'll be interpreted as intended output directory, otherwise current working directory is used. Note: only necessary tables are generated. Corresponding header files with actual osmo_conv_code instance (including puncturing etc) have to be added manually.
Fixes: OS#1629 --- utils/conv_gen.py | 359 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100755 utils/conv_gen.py
diff --git a/utils/conv_gen.py b/utils/conv_gen.py new file mode 100755 index 0000000..52c1ab3 --- /dev/null +++ b/utils/conv_gen.py @@ -0,0 +1,359 @@ +#!/usr/bin/python + +license =""" +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +""" + +import sys, os + +class ConvolutionalCode(object): + + def __init__(self, block_len, k, polys, name = "call-me", description = "LOL"): + # Save simple params + self.block_len = block_len + self.k = k + self.rate_inv = len(polys) + + # Infos + self.name = name + self.description = description + + # Handle polynoms (and check for recursion) + self.polys = [(1, 1) if x[0] == x[1] else x for x in polys] + + rp = [x[1] for x in self.polys if x[1] != 1] + if rp: + if not all([x == rp[0] for x in rp]): + raise ValueError("Bad polynoms: Can't have multiple different divider polynoms !") + if not all([x[0] == 1 for x in polys if x[1] == 1]): + raise ValueError("Bad polynoms: Can't have a '1' divider with a non '1' dividend in a recursive code") + self.poly_divider = rp[0] + else: + self.poly_divider = 1 + + @property + def recursive(self): + return self.poly_divider != 1 + + def _combine(self, src, sel, nb): + x = src & sel + fn_xor = lambda x, y: x ^ y + return reduce(fn_xor, [(x >> n) & 1 for n in range(nb)]) + + @property + def _state_mask(self): + return ((1 << (self.k - 1)) - 1) + + def next_state(self, state, bit): + nb = self._combine( + (state << 1) | bit, + self.poly_divider, + self.k, + ) + return ((state << 1) | nb) & self._state_mask + + def next_term_state(self, state): + return (state << 1) & self._state_mask + + def next_output(self, state, bit, ns = None): + # Next state bit + if ns is None: + ns = self.next_state(state, bit) + + src = (ns & 1) | (state << 1) + + # Scan polynoms + rv = [] + for p_n, p_d in self.polys: + if self.recursive and p_d == 1: + o = bit # No choice ... (systematic output in recursive case) + else: + o = self._combine(src, p_n, self.k) + rv.append(o) + + return rv + + def next_term_output(self, state, ns = None): + # Next state bit + if ns is None: + ns = self.next_term_state(state) + + src = (ns & 1) | (state << 1) + + # Scan polynoms + rv = [] + for p_n, p_d in self.polys: + if self.recursive and p_d == 1: + # Systematic output are replaced when in 'termination' mode + o = self._combine(src, self.poly_divider, self.k) + else: + o = self._combine(src, p_n, self.k) + rv.append(o) + + return rv + + def next(self, state, bit): + ns = self.next_state(state, bit) + nb = self.next_output(state, bit, ns = ns) + return ns, nb + + def next_term(self, state): + ns = self.next_term_state(state) + nb = self.next_term_output(state, ns = ns) + return ns, nb + + def _print_term(self, pref, fi, num_states, pack, is_state = True): + s = "state" if is_state else "output" + print >>fi, "\n/* .next_term_%s */" % s + print >>fi, "const uint8_t %s_%s_term_%s[] = {" % (pref, self.name, s) + d = [] + for state in range(num_states): + if is_state: + x = self.next_term_state(state) + else: + x = pack(self.next_term_output(state)) + d.append("%d, " % x) + print >>fi, "\t%s\n};" % ''.join(d) + + def _print_x(self, pref, fi, num_states, pack, is_state = True): + s = "state" if is_state else "output" + print >>fi, "\n/* .next_%s */" % s + print >>fi, "const uint8_t %s_%s_%s[][2] = {" % (pref, self.name, s) + for state in range(num_states): + if is_state: + x0 = self.next_state(state, 0) + x1 = self.next_state(state, 1) + else: + x0 = pack(self.next_output(state, 0)) + x1 = pack(self.next_output(state, 1)) + print >>fi, "\t{ %2d, %2d }," % (x0, x1) + print >>fi, "};" + + def gen_tables(self, pref, fi): + pack = lambda n: sum([x << (self.rate_inv - i - 1) for i, x in enumerate(n)]) + num_states = 1 << (self.k - 1) + print >>fi, "\n/* %s */" % self.description + #print >>fi, "const int %s_%s_length = %d;" % (pref, self.name, self.block_len) + #print >>fi, "const int %s_%s_K = %d;" % (pref, self.name, self.k) + self._print_x(pref, fi, num_states, pack) + self._print_x(pref, fi, num_states, pack, False) + + if self.recursive: + self._print_term(pref, fi, num_states, pack) + self._print_term(pref, fi, num_states, pack, False) + +poly = lambda *args: sum([(1 << x) for x in args]) + +xcch = ConvolutionalCode( + 224, 5, + [ + ( poly(0, 3, 4), 1 ), + ( poly(0, 1, 3, 4), 1 ), + ], + name = "xcch", + description =""" *CCH convolutional code: + 228 bits blocks, rate 1/2, k = 5 + G0 = 1 + D3 + D4 + G1 = 1 + D + D3 + D4 +""" +) + +tch_afs_12_2 = ConvolutionalCode( + 250, 5, + [ + ( 1, 1 ), + ( poly(0, 1, 3, 4), poly(0, 3, 4) ), + ], + name = 'tch_afs_12_2', + description = """TCH/AFS 12.2 convolutional code: + 250 bits block, rate 1/2, punctured + G0/G0 = 1 + G1/G0 = 1 + D + D3 + D4 / 1 + D3 + D4 +""" +) + +tch_afs_10_2 = ConvolutionalCode( + 210, 5, + [ + ( poly(0, 1, 3, 4), poly(0, 1, 2, 3, 4) ), + ( poly(0, 2, 4), poly(0, 1, 2, 3, 4) ), + ( 1, 1 ), + ], + name = 'tch_afs_10_2', + description = """TCH/AFS 10.2 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 +""" +) + +tch_afs_7_95 = ConvolutionalCode( + 165, 7, + [ + ( 1, 1 ), + ( poly(0, 1, 4, 6), poly(0, 2, 3, 5, 6) ), + ( poly(0, 1, 2, 3, 4, 6), poly(0, 2, 3, 5, 6) ), + ], + name = 'tch_afs_7_95', + description = """TCH/AFS 7.95 kbits convolutional code: + G4/G4 = 1 + G5/G4 = 1 + D + D4 + D6 / 1 + D2 + D3 + D5 + D6 + G6/G4 = 1 + D + D2 + D3 + D4 + D6 / 1 + D2 + D3 + D5 + D6 +""" +) + +tch_afs_7_4 = ConvolutionalCode( + 154, 5, + [ + ( poly(0, 1, 3, 4), poly(0, 1, 2, 3, 4) ), + ( poly(0, 2, 4), poly(0, 1, 2, 3, 4) ), + ( 1, 1 ), + ], + name = 'tch_afs_7_4', + description = """TCH/AFS 7.4 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 +""" +) + +tch_afs_6_7 = ConvolutionalCode( + 140, 5, + [ + ( poly(0, 1, 3, 4), poly(0, 1, 2, 3, 4) ), + ( poly(0, 2, 4), poly(0, 1, 2, 3, 4) ), + ( 1, 1 ), + ( 1, 1 ), + ], + name = 'tch_afs_6_7', + description = """TCH/AFS 6.7 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 + G3/G3 = 1 +""" +) + +tch_afs_5_9 = ConvolutionalCode( + 124, 7, + [ + ( poly(0, 2, 3, 5, 6), poly(0, 1, 2, 3, 4, 6) ), + ( poly(0, 1, 4, 6), poly(0, 1, 2, 3, 4, 6) ), + ( 1, 1), + ( 1, 1), + ], + name = 'tch_afs_5_9', + description = """TCH/AFS 5.9 kbits convolutional code: + 124 bits + G4/G6 = 1 + D2 + D3 + D5 + D6 / 1 + D + D2 + D3 + D4 + D6 + G5/G6 = 1 + D + D4 + D6 / 1 + D + D2 + D3 + D4 + D6 + G6/G6 = 1 + G6/G6 = 1 +""" +) + +tch_afs_5_15 = ConvolutionalCode( + 109, 5, + [ + ( poly(0, 1, 3, 4), poly(0, 1, 2, 3, 4) ), + ( poly(0, 1, 3, 4), poly(0, 1, 2, 3, 4) ), + ( poly(0, 2, 4), poly(0, 1, 2, 3, 4) ), + ( 1, 1 ), + ( 1, 1 ), + ], + name = 'tch_afs_5_15', + description = """TCH/AFS 5.15 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 + G3/G3 = 1 +""" +) + +tch_afs_4_75 = ConvolutionalCode( + 101, 7, + [ + ( poly(0, 2, 3, 5, 6), poly(0, 1, 2, 3, 4, 6) ), + ( poly(0, 2, 3, 5, 6), poly(0, 1, 2, 3, 4, 6) ), + ( poly(0, 1, 4, 6), poly(0, 1, 2, 3, 4, 6) ), + ( 1, 1 ), + ( 1, 1 ), + ], + name = 'tch_afs_4_75', + description = """TCH/AFS 4.75 kbits convolutional code: + G4/G6 = 1 + D2 + D3 + D5 + D6 / 1 + D + D2 + D3 + D4 + D6 + G4/G6 = 1 + D2 + D3 + D5 + D6 / 1 + D + D2 + D3 + D4 + D6 + G5/G6 = 1 + D + D4 + D6 / 1 + D + D2 + D3 + D4 + D6 + G6/G6 = 1 + G6/G6 = 1 +""" +) + +tetra_rcpc = ConvolutionalCode( + 288, 5, + [ + ( poly(0,1,4), 1 ), + ( poly(0,2,3,4), 1 ), + ( poly(0,1,2,4), 1 ), + ( poly(0,1,3,4), 1 ), + ], + name = 'tetra_rcpc', + description = """TETRA RCPC code + G1 = 1 + D + D4 + G2 = 1 + D2 + D3 + D4 + G3 = 1 + D + D2 + D4 + G4 = 1 + D + D3 + D4 +""" +) + +tetra_rcpc_tch = ConvolutionalCode( + 288, 5, + [ + ( poly(0, 1, 2, 3, 4), 1 ), + ( poly(0, 1, 3, 4), 1 ), + ( poly(0, 2, 4), 1 ), + ], + description = """TETRA RCPC TCH code +""" +) + +def gen_c(path, prefix, code): + f = open(os.path.join(path, 'conv_' + code.name + '_gen.c'), 'w') + print >>f, license + print >>f, "#include <stdint.h>" + code.gen_tables(prefix, f) + +if __name__ == '__main__': + print >>sys.stderr, "Generating convolutional codes..." + prefix = "osmo_conv_gsm0503" + path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd() + gen_c(path, prefix, xcch) + gen_c(path, prefix, tch_afs_12_2) + gen_c(path, prefix, tch_afs_10_2) + gen_c(path, prefix, tch_afs_7_95) + gen_c(path, prefix, tch_afs_7_4) + gen_c(path, prefix, tch_afs_6_7) + gen_c(path, prefix, tch_afs_5_9) + gen_c(path, prefix, tch_afs_5_15) + gen_c(path, prefix, tch_afs_4_75) + print >>sys.stderr, "\tdone."
From: Max msuraev@sysmocom.de
Move convolutional code for *CCH channels from test to public API because it's useful not only for testing. Note: the code was manually generating with utils/conv_gen.py --- include/Makefile.am | 1 + include/osmocom/gsm/gsm0503.h | 47 +++++++++++++++++++++++++++++ src/gsm/Makefile.am | 2 +- src/gsm/conv_xcch_gen.c | 69 +++++++++++++++++++++++++++++++++++++++++++ src/gsm/libosmogsm.map | 1 + tests/Makefile.am | 2 +- tests/conv/conv_test.c | 32 +++----------------- 7 files changed, 124 insertions(+), 30 deletions(-) create mode 100644 include/osmocom/gsm/gsm0503.h create mode 100644 src/gsm/conv_xcch_gen.c
diff --git a/include/Makefile.am b/include/Makefile.am index 0e5ed74..e7888c5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -64,6 +64,7 @@ nobase_include_HEADERS = \ osmocom/gsm/gsm0411_utils.h \ osmocom/gsm/gsm0480.h \ osmocom/gsm/gsm0502.h \ + osmocom/gsm/gsm0503.h \ osmocom/gsm/gsm0808.h \ osmocom/gsm/gsm48.h \ osmocom/gsm/gsm48_ie.h \ diff --git a/include/osmocom/gsm/gsm0503.h b/include/osmocom/gsm/gsm0503.h new file mode 100644 index 0000000..e68aa9a --- /dev/null +++ b/include/osmocom/gsm/gsm0503.h @@ -0,0 +1,47 @@ +/* + * gsm0503.h + * + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include <stdint.h> + +#include <osmocom/core/conv.h> + +extern const uint8_t osmo_conv_gsm0503_xcch_output[][2]; +extern const uint8_t osmo_conv_gsm0503_xcch_state[][2]; + +/*! \file conv_gen.h + * Osmocom convolutional encoder/decoder for xCCH channels, see 3GPP TS 05.03 + */ + +/*! \brief structure describing convolutional code xCCH + * + * Non-recursive code, flushed, not punctured code. + */ +static const struct osmo_conv_code osmo_conv_gsm0503_xcch = { + .N = 2, + .K = 5, + .len = 224, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_xcch_output, + .next_state = osmo_conv_gsm0503_xcch_state, +}; diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am index b0ea643..0ab2bd8 100644 --- a/src/gsm/Makefile.am +++ b/src/gsm/Makefile.am @@ -17,7 +17,7 @@ libgsmint_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \ gsm_utils.c rsl.c gsm48.c gsm48_ie.c gsm0808.c sysinfo.c \ gprs_cipher_core.c gsm0480.c abis_nm.c gsm0502.c \ gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c \ - lapd_core.c lapdm.c kasumi.c \ + lapd_core.c lapdm.c kasumi.c conv_xcch_gen.c \ auth_core.c auth_comp128v1.c auth_comp128v23.c \ auth_milenage.c milenage/aes-encblock.c \ milenage/aes-internal.c milenage/aes-internal-enc.c \ diff --git a/src/gsm/conv_xcch_gen.c b/src/gsm/conv_xcch_gen.c new file mode 100644 index 0000000..25fa226 --- /dev/null +++ b/src/gsm/conv_xcch_gen.c @@ -0,0 +1,69 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* *CCH convolutional code: + 228 bits blocks, rate 1/2, k = 5 + G0 = 1 + D3 + D4 + G1 = 1 + D + D3 + D4 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_xcch_state[][2] = { + { 0, 1 }, + { 2, 3 }, + { 4, 5 }, + { 6, 7 }, + { 8, 9 }, + { 10, 11 }, + { 12, 13 }, + { 14, 15 }, + { 0, 1 }, + { 2, 3 }, + { 4, 5 }, + { 6, 7 }, + { 8, 9 }, + { 10, 11 }, + { 12, 13 }, + { 14, 15 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_xcch_output[][2] = { + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 3, 0 }, + { 2, 1 }, + { 3, 0 }, + { 2, 1 }, + { 3, 0 }, + { 2, 1 }, + { 3, 0 }, + { 2, 1 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, +}; diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index a3e4e14..53d112e 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -25,6 +25,7 @@ abis_nm_osmo_magic; abis_nm_ipa_magic;
osmo_sitype_strs; +osmo_conv_gsm0503_xcch;
comp128; dbm2rxlev; diff --git a/tests/Makefile.am b/tests/Makefile.am index 03506af..3aaa99b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -47,7 +47,7 @@ bits_bitcomp_test_SOURCES = bits/bitcomp_test.c bits_bitcomp_test_LDADD = $(top_builddir)/src/libosmocore.la
conv_conv_test_SOURCES = conv/conv_test.c -conv_conv_test_LDADD = $(top_builddir)/src/libosmocore.la +conv_conv_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libgsmint.la
gsm0808_gsm0808_test_SOURCES = gsm0808/gsm0808_test.c gsm0808_gsm0808_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la diff --git a/tests/conv/conv_test.c b/tests/conv/conv_test.c index de62f23..6e99b2e 100644 --- a/tests/conv/conv_test.c +++ b/tests/conv/conv_test.c @@ -6,6 +6,7 @@ #include <osmocom/core/bits.h> #include <osmocom/core/conv.h> #include <osmocom/core/utils.h> +#include <osmocom/gsm/gsm0503.h>
#define MAX_LEN_BITS 512 #define MAX_LEN_BYTES (512/8) @@ -15,31 +16,6 @@ /* Test codes */ /* ------------------------------------------------------------------------ */
-/* GSM xCCH -> Non-recursive code, flushed, not punctured */ -static const uint8_t conv_gsm_xcch_next_output[][2] = { - { 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 }, - { 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 }, - { 3, 0 }, { 2, 1 }, { 3, 0 }, { 2, 1 }, - { 0, 3 }, { 1, 2 }, { 0, 3 }, { 1, 2 }, -}; - -static const uint8_t conv_gsm_xcch_next_state[][2] = { - { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, - { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, - { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, - { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, -}; - -static const struct osmo_conv_code conv_gsm_xcch = { - .N = 2, - .K = 5, - .len = 224, - .term = CONV_TERM_FLUSH, - .next_output = conv_gsm_xcch_next_output, - .next_state = conv_gsm_xcch_next_state, -}; - - /* GSM TCH/AFS 7.95 -> Recursive code, flushed, with puncturing */ static const uint8_t conv_gsm_tch_afs_7_95_next_output[][2] = { { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 }, @@ -227,8 +203,8 @@ static const struct osmo_conv_code conv_trunc = { .K = 5, .len = 224, .term = CONV_TERM_TRUNCATION, - .next_output = conv_gsm_xcch_next_output, - .next_state = conv_gsm_xcch_next_state, + .next_output = osmo_conv_gsm0503_xcch_output, + .next_state = osmo_conv_gsm0503_xcch_state, };
@@ -249,7 +225,7 @@ struct conv_test_vector { static const struct conv_test_vector tests[] = { { .name = "GSM xCCH (non-recursive, flushed, not punctured)", - .code = &conv_gsm_xcch, + .code = &osmo_conv_gsm0503_xcch, .in_len = 224, .out_len = 456, .has_vec = 1,
Why would you put the conv code struct in the .h ? And why expose the tables in the public symbols ?
The fact you can 'reuse' the tables in the test is really no reason to pollute the API namespace.
Cheers,
Sylvain
Hi Max,
On Mon, Apr 11, 2016 at 07:28:20PM +0200, Sylvain Munaut wrote:
Why would you put the conv code struct in the .h ?
I have to agree with Sylvain here, and fail to see the reason for the above design decisions. Particularly in a shared library like libosmocore/libosmogsm, the definition of the data should be in a C file that is actually shared read-only text to all its users, while the header files only contain forward declarations.
And why expose the tables in the public symbols ?
Indeed let's try to avoid this if possible.
The fact you can 'reuse' the tables in the test is really no reason to pollute the API namespace.
If I understand the code corectly, users would interact with it by means of the 'struct osmo_conv_code'. So that one would have to be declared in a header file, like:
extern const struct osmo_conv_code osmo_conv_gsm0503_xcch;
This kind of symbol would have to be exported in the .map file for actual consumption by the users of the library.
which is then subsequently defined in a C file:
const struct osmo_conv_code osmo_conv_gsm0503_xcch = { ... }
But why would those declaraions below be in a header file? Why are those relevant to the user?
+extern const uint8_t osmo_conv_gsm0503_xcch_output[][2]; +extern const uint8_t osmo_conv_gsm0503_xcch_state[][2];
Regards, Harald
From: Max msuraev@sysmocom.de
--- include/osmocom/gsm/gsm0503.h | 26 +++++++++++++++++++++ src/gsm/Makefile.am | 2 +- src/gsm/conv_csx.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/gsm/conv_csx.c
diff --git a/include/osmocom/gsm/gsm0503.h b/include/osmocom/gsm/gsm0503.h index e68aa9a..3896821 100644 --- a/include/osmocom/gsm/gsm0503.h +++ b/include/osmocom/gsm/gsm0503.h @@ -45,3 +45,29 @@ static const struct osmo_conv_code osmo_conv_gsm0503_xcch = { .next_output = osmo_conv_gsm0503_xcch_output, .next_state = osmo_conv_gsm0503_xcch_state, }; + +extern const int osmo_conv_gsm0503_cs2_puncture[]; + +/*! \brief structure describing convolutional code CS2 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_cs2 = { + .N = 2, + .K = 5, + .len = 290, + .next_output = osmo_conv_gsm0503_xcch_output, + .next_state = osmo_conv_gsm0503_xcch_state, + .puncture = osmo_conv_gsm0503_cs2_puncture +}; + +extern const int osmo_conv_gsm0503_cs3_puncture[]; + +/*! \brief structure describing convolutional code CS2 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_cs3 = { + .N = 2, + .K = 5, + .len = 334, + .next_output = osmo_conv_gsm0503_xcch_output, + .next_state = osmo_conv_gsm0503_xcch_state, + .puncture = osmo_conv_gsm0503_cs3_puncture +}; diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am index 0ab2bd8..8c7f2be 100644 --- a/src/gsm/Makefile.am +++ b/src/gsm/Makefile.am @@ -17,7 +17,7 @@ libgsmint_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \ gsm_utils.c rsl.c gsm48.c gsm48_ie.c gsm0808.c sysinfo.c \ gprs_cipher_core.c gsm0480.c abis_nm.c gsm0502.c \ gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c \ - lapd_core.c lapdm.c kasumi.c conv_xcch_gen.c \ + lapd_core.c lapdm.c kasumi.c conv_xcch_gen.c conv_csx.c \ auth_core.c auth_comp128v1.c auth_comp128v23.c \ auth_milenage.c milenage/aes-encblock.c \ milenage/aes-internal.c milenage/aes-internal-enc.c \ diff --git a/src/gsm/conv_csx.c b/src/gsm/conv_csx.c new file mode 100644 index 0000000..1f94cd4 --- /dev/null +++ b/src/gsm/conv_csx.c @@ -0,0 +1,53 @@ +/* + * conv_csx.c + * + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +const int osmo_conv_gsm0503_cs2_puncture[] = { + 15, 19, 23, 27, 31, 35, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 91, + 95, 99, 103, 107, 111, 115, 119, 123, 127, 131, 139, 143, 147, 151, 155, + 159, 163, 167, 171, 175, 179, 187, 191, 195, 199, 203, 207, 211, 215, + 219, 223, 227, 235, 239, 243, 247, 251, 255, 259, 263, 267, 271, 275, + 283, 287, 291, 295, 299, 303, 307, 311, 315, 319, 323, 331, 335, 339, + 343, 347, 351, 355, 359, 363, 367, 371, 379, 383, 387, 391, 395, 399, + 403, 407, 411, 415, 419, 427, 431, 435, 439, 443, 447, 451, 455, 459, + 463, 467, 475, 479, 483, 487, 491, 495, 499, 503, 507, 511, 515, 523, + 527, 531, 535, 539, 543, 547, 551, 555, 559, 563, 571, 575, 579, 583, + 587, -1 +}; + +const int osmo_conv_gsm0503_cs3_puncture[] = { + 15, 17, 21, 23, 27, 29, 33, 35, 39, 41, 45, 47, 51, 53, 57, 59, 63, 65, + 69, 71, 75, 77, 81, 83, 87, 89, 93, 95, 99, 101, 105, 107, 111, 113, + 117, 119, 123, 125, 129, 131, 135, 137, 141, 143, 147, 149, 153, 155, + 159, 161, 165, 167, 171, 173, 177, 179, 183, 185, 189, 191, 195, 197, + 201, 203, 207, 209, 213, 215, 219, 221, 225, 227, 231, 233, 237, 239, + 243, 245, 249, 251, 255, 257, 261, 263, 267, 269, 273, 275, 279, 281, + 285, 287, 291, 293, 297, 299, 303, 305, 309, 311, 315, 317, 321, 323, + 327, 329, 333, 335, 339, 341, 345, 347, 351, 353, 357, 359, 363, 365, + 369, 371, 375, 377, 381, 383, 387, 389, 393, 395, 399, 401, 405, 407, + 411, 413, 417, 419, 423, 425, 429, 431, 435, 437, 441, 443, 447, 449, + 453, 455, 459, 461, 465, 467, 471, 473, 477, 479, 483, 485, 489, 491, + 495, 497, 501, 503, 507, 509, 513, 515, 519, 521, 525, 527, 531, 533, + 537, 539, 543, 545, 549, 551, 555, 557, 561, 563, 567, 569, 573, 575, + 579, 581, 585, 587, 591, 593, 597, 599, 603, 605, 609, 611, 615, 617, + 621, 623, 627, 629, 633, 635, 639, 641, 645, 647, 651, 653, 657, 659, + 663, 665, 669, 671, -1 +};
From: Max msuraev@sysmocom.de
Replace implementation in tests with added code. Note: the code was manually generated with utils/conv_gen.py --- include/osmocom/gsm/gsm0503.h | 160 ++++++++++++++++++++++++++++++++++++ src/gsm/Makefile.am | 5 ++ src/gsm/conv_tch_afs.c | 119 +++++++++++++++++++++++++++ src/gsm/conv_tch_afs_10_2_gen.c | 79 ++++++++++++++++++ src/gsm/conv_tch_afs_12_2_gen.c | 79 ++++++++++++++++++ src/gsm/conv_tch_afs_4_75_gen.c | 177 ++++++++++++++++++++++++++++++++++++++++ src/gsm/conv_tch_afs_5_15_gen.c | 81 ++++++++++++++++++ src/gsm/conv_tch_afs_5_9_gen.c | 177 ++++++++++++++++++++++++++++++++++++++++ src/gsm/conv_tch_afs_6_7_gen.c | 80 ++++++++++++++++++ src/gsm/conv_tch_afs_7_4_gen.c | 79 ++++++++++++++++++ src/gsm/conv_tch_afs_7_95_gen.c | 175 +++++++++++++++++++++++++++++++++++++++ tests/conv/conv_test.c | 78 +----------------- 12 files changed, 1212 insertions(+), 77 deletions(-) create mode 100644 src/gsm/conv_tch_afs.c create mode 100644 src/gsm/conv_tch_afs_10_2_gen.c create mode 100644 src/gsm/conv_tch_afs_12_2_gen.c create mode 100644 src/gsm/conv_tch_afs_4_75_gen.c create mode 100644 src/gsm/conv_tch_afs_5_15_gen.c create mode 100644 src/gsm/conv_tch_afs_5_9_gen.c create mode 100644 src/gsm/conv_tch_afs_6_7_gen.c create mode 100644 src/gsm/conv_tch_afs_7_4_gen.c create mode 100644 src/gsm/conv_tch_afs_7_95_gen.c
diff --git a/include/osmocom/gsm/gsm0503.h b/include/osmocom/gsm/gsm0503.h index 3896821..b9e5cba 100644 --- a/include/osmocom/gsm/gsm0503.h +++ b/include/osmocom/gsm/gsm0503.h @@ -71,3 +71,163 @@ static const struct osmo_conv_code osmo_conv_gsm0503_cs3 = { .next_state = osmo_conv_gsm0503_xcch_state, .puncture = osmo_conv_gsm0503_cs3_puncture }; + +extern const int osmo_conv_gsm0503_tch_afs_12_2_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_12_2_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_12_2_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_12_2_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_12_2_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 12.2 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_12_2 = { + .N = 2, + .K = 5, + .len = 250, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_12_2_output, + .next_state = osmo_conv_gsm0503_tch_afs_12_2_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_12_2_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_12_2_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_12_2_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_10_2_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_10_2_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_10_2_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_10_2_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_10_2_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 10.2 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_10_2 = { + .N = 3, + .K = 5, + .len = 210, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_10_2_output, + .next_state = osmo_conv_gsm0503_tch_afs_10_2_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_10_2_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_10_2_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_10_2_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_7_95_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_95_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_95_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_95_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_95_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 7.95 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_7_95 = { + .N = 3, + .K = 7, + .len = 165, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_7_95_output, + .next_state = osmo_conv_gsm0503_tch_afs_7_95_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_7_95_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_7_95_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_7_95_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_7_4_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_4_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_4_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_4_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_7_4_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 7.4 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_7_4 = { + .N = 3, + .K = 5, + .len = 154, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_7_4_output, + .next_state = osmo_conv_gsm0503_tch_afs_7_4_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_7_4_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_7_4_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_7_4_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_6_7_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_6_7_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_6_7_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_6_7_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_6_7_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 6.7 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_6_7 = { + .N = 4, + .K = 5, + .len = 140, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_6_7_output, + .next_state = osmo_conv_gsm0503_tch_afs_6_7_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_6_7_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_6_7_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_6_7_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_5_9_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_9_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_9_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_9_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_9_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 5.9 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_5_9 = { + .N = 4, + .K = 7, + .len = 124, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_5_9_output, + .next_state = osmo_conv_gsm0503_tch_afs_5_9_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_5_9_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_5_9_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_5_9_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_5_15_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_15_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_15_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_15_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_5_15_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 5.15 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_5_15 = { + .N = 5, + .K = 5, + .len = 109, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_5_15_output, + .next_state = osmo_conv_gsm0503_tch_afs_5_15_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_5_15_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_5_15_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_5_15_puncture +}; + +extern const int osmo_conv_gsm0503_tch_afs_4_75_puncture[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_4_75_output[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_4_75_state[][2]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_4_75_term_output[]; +extern const uint8_t osmo_conv_gsm0503_tch_afs_4_75_term_state[]; + +/*! \brief structure describing convolutional code TCH/AFS 4.75 + */ +static const struct osmo_conv_code osmo_conv_gsm0503_tch_afs_4_75 = { + .N = 5, + .K = 7, + .len = 101, + .term = CONV_TERM_FLUSH, + .next_output = osmo_conv_gsm0503_tch_afs_4_75_output, + .next_state = osmo_conv_gsm0503_tch_afs_4_75_state, + .next_term_output = osmo_conv_gsm0503_tch_afs_4_75_term_output, + .next_term_state = osmo_conv_gsm0503_tch_afs_4_75_term_state, + .puncture = osmo_conv_gsm0503_tch_afs_4_75_puncture +}; diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am index 8c7f2be..a362a3b 100644 --- a/src/gsm/Makefile.am +++ b/src/gsm/Makefile.am @@ -18,6 +18,11 @@ libgsmint_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \ gprs_cipher_core.c gsm0480.c abis_nm.c gsm0502.c \ gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c \ lapd_core.c lapdm.c kasumi.c conv_xcch_gen.c conv_csx.c \ + conv_tch_afs.c conv_tch_afs_12_2_gen.c \ + conv_tch_afs_4_75_gen.c \ + conv_tch_afs_10_2_gen.c conv_tch_afs_7_95_gen.c \ + conv_tch_afs_7_4_gen.c conv_tch_afs_6_7_gen.c \ + conv_tch_afs_5_9_gen.c conv_tch_afs_5_15_gen.c \ auth_core.c auth_comp128v1.c auth_comp128v23.c \ auth_milenage.c milenage/aes-encblock.c \ milenage/aes-internal.c milenage/aes-internal-enc.c \ diff --git a/src/gsm/conv_tch_afs.c b/src/gsm/conv_tch_afs.c new file mode 100644 index 0000000..dd65e0d --- /dev/null +++ b/src/gsm/conv_tch_afs.c @@ -0,0 +1,119 @@ +/* + * conv_tch_afs.c + * + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +const int osmo_conv_gsm0503_tch_afs_12_2_puncture[] = { + 321, 325, 329, 333, 337, 341, 345, 349, 353, 357, 361, 363, + 365, 369, 373, 377, 379, 381, 385, 389, 393, 395, 397, 401, + 405, 409, 411, 413, 417, 421, 425, 427, 429, 433, 437, 441, + 443, 445, 449, 453, 457, 459, 461, 465, 469, 473, 475, 477, + 481, 485, 489, 491, 493, 495, 497, 499, 501, 503, 505, 507, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_10_2_puncture[] = { + 1, 4, 7, 10, 16, 19, 22, 28, 31, 34, 40, 43, + 46, 52, 55, 58, 64, 67, 70, 76, 79, 82, 88, 91, + 94, 100, 103, 106, 112, 115, 118, 124, 127, 130, 136, 139, + 142, 148, 151, 154, 160, 163, 166, 172, 175, 178, 184, 187, + 190, 196, 199, 202, 208, 211, 214, 220, 223, 226, 232, 235, + 238, 244, 247, 250, 256, 259, 262, 268, 271, 274, 280, 283, + 286, 292, 295, 298, 304, 307, 310, 316, 319, 322, 325, 328, + 331, 334, 337, 340, 343, 346, 349, 352, 355, 358, 361, 364, + 367, 370, 373, 376, 379, 382, 385, 388, 391, 394, 397, 400, + 403, 406, 409, 412, 415, 418, 421, 424, 427, 430, 433, 436, + 439, 442, 445, 448, 451, 454, 457, 460, 463, 466, 469, 472, + 475, 478, 481, 484, 487, 490, 493, 496, 499, 502, 505, 508, + 511, 514, 517, 520, 523, 526, 529, 532, 535, 538, 541, 544, + 547, 550, 553, 556, 559, 562, 565, 568, 571, 574, 577, 580, + 583, 586, 589, 592, 595, 598, 601, 604, 607, 609, 610, 613, + 616, 619, 621, 622, 625, 627, 628, 631, 633, 634, 636, 637, + 639, 640, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_7_95_puncture[] = { + 1, 2, 4, 5, 8, 22, 70, 118, 166, 214, 262, 310, + 317, 319, 325, 332, 334, 341, 343, 349, 356, 358, 365, 367, + 373, 380, 382, 385, 389, 391, 397, 404, 406, 409, 413, 415, + 421, 428, 430, 433, 437, 439, 445, 452, 454, 457, 461, 463, + 469, 476, 478, 481, 485, 487, 490, 493, 500, 502, 503, 505, + 506, 508, 509, 511, 512, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_7_4_puncture[] = { + 0, 355, 361, 367, 373, 379, 385, 391, 397, 403, 409, 415, + 421, 427, 433, 439, 445, 451, 457, 460, 463, 466, 468, 469, + 471, 472, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_6_7_puncture[] = { + 1, 3, 7, 11, 15, 27, 39, 55, 67, 79, 95, 107, + 119, 135, 147, 159, 175, 187, 199, 215, 227, 239, 255, 267, + 279, 287, 291, 295, 299, 303, 307, 311, 315, 319, 323, 327, + 331, 335, 339, 343, 347, 351, 355, 359, 363, 367, 369, 371, + 375, 377, 379, 383, 385, 387, 391, 393, 395, 399, 401, 403, + 407, 409, 411, 415, 417, 419, 423, 425, 427, 431, 433, 435, + 439, 441, 443, 447, 449, 451, 455, 457, 459, 463, 465, 467, + 471, 473, 475, 479, 481, 483, 487, 489, 491, 495, 497, 499, + 503, 505, 507, 511, 513, 515, 519, 521, 523, 527, 529, 531, + 535, 537, 539, 543, 545, 547, 549, 551, 553, 555, 557, 559, + 561, 563, 565, 567, 569, 571, 573, 575, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_5_9_puncture[] = { + 0, 1, 3, 5, 7, 11, 15, 31, 47, 63, 79, 95, + 111, 127, 143, 159, 175, 191, 207, 223, 239, 255, 271, 287, + 303, 319, 327, 331, 335, 343, 347, 351, 359, 363, 367, 375, + 379, 383, 391, 395, 399, 407, 411, 415, 423, 427, 431, 439, + 443, 447, 455, 459, 463, 467, 471, 475, 479, 483, 487, 491, + 495, 499, 503, 507, 509, 511, 512, 513, 515, 516, 517, 519, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_5_15_puncture[] = { + 0, 4, 5, 9, 10, 14, 15, 20, 25, 30, 35, 40, + 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, + 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, + 290, 300, 310, 315, 320, 325, 330, 334, 335, 340, 344, 345, + 350, 354, 355, 360, 364, 365, 370, 374, 375, 380, 384, 385, + 390, 394, 395, 400, 404, 405, 410, 414, 415, 420, 424, 425, + 430, 434, 435, 440, 444, 445, 450, 454, 455, 460, 464, 465, + 470, 474, 475, 480, 484, 485, 490, 494, 495, 500, 504, 505, + 510, 514, 515, 520, 524, 525, 529, 530, 534, 535, 539, 540, + 544, 545, 549, 550, 554, 555, 559, 560, 564, + -1, /* end */ +}; + +const int osmo_conv_gsm0503_tch_afs_4_75_puncture[] = { + 0, 1, 2, 4, 5, 7, 9, 15, 25, 35, 45, 55, + 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, + 185, 195, 205, 215, 225, 235, 245, 255, 265, 275, 285, 295, + 305, 315, 325, 335, 345, 355, 365, 375, 385, 395, 400, 405, + 410, 415, 420, 425, 430, 435, 440, 445, 450, 455, 459, 460, + 465, 470, 475, 479, 480, 485, 490, 495, 499, 500, 505, 509, + 510, 515, 517, 519, 520, 522, 524, 525, 526, 527, 529, 530, + 531, 532, 534, + -1, /* end */ +}; diff --git a/src/gsm/conv_tch_afs_10_2_gen.c b/src/gsm/conv_tch_afs_10_2_gen.c new file mode 100644 index 0000000..a4c3826 --- /dev/null +++ b/src/gsm/conv_tch_afs_10_2_gen.c @@ -0,0 +1,79 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 10.2 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_10_2_state[][2] = { + { 0, 1 }, + { 3, 2 }, + { 5, 4 }, + { 6, 7 }, + { 9, 8 }, + { 10, 11 }, + { 12, 13 }, + { 15, 14 }, + { 1, 0 }, + { 2, 3 }, + { 4, 5 }, + { 7, 6 }, + { 8, 9 }, + { 11, 10 }, + { 13, 12 }, + { 14, 15 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_10_2_output[][2] = { + { 0, 7 }, + { 2, 5 }, + { 4, 3 }, + { 6, 1 }, + { 2, 5 }, + { 0, 7 }, + { 6, 1 }, + { 4, 3 }, + { 0, 7 }, + { 2, 5 }, + { 4, 3 }, + { 6, 1 }, + { 2, 5 }, + { 0, 7 }, + { 6, 1 }, + { 4, 3 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_10_2_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_10_2_term_output[] = { + 0, 5, 3, 6, 5, 0, 6, 3, 7, 2, 4, 1, 2, 7, 1, 4, +}; diff --git a/src/gsm/conv_tch_afs_12_2_gen.c b/src/gsm/conv_tch_afs_12_2_gen.c new file mode 100644 index 0000000..e5e8a92 --- /dev/null +++ b/src/gsm/conv_tch_afs_12_2_gen.c @@ -0,0 +1,79 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 12.2 convolutional code: + 250 bits block, rate 1/2, punctured + G0/G0 = 1 + G1/G0 = 1 + D + D3 + D4 / 1 + D3 + D4 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_12_2_state[][2] = { + { 0, 1 }, + { 2, 3 }, + { 4, 5 }, + { 6, 7 }, + { 9, 8 }, + { 11, 10 }, + { 13, 12 }, + { 15, 14 }, + { 1, 0 }, + { 3, 2 }, + { 5, 4 }, + { 7, 6 }, + { 8, 9 }, + { 10, 11 }, + { 12, 13 }, + { 14, 15 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_12_2_output[][2] = { + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, + { 0, 3 }, + { 1, 2 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_12_2_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_12_2_term_output[] = { + 0, 1, 0, 1, 3, 2, 3, 2, 3, 2, 3, 2, 0, 1, 0, 1, +}; diff --git a/src/gsm/conv_tch_afs_4_75_gen.c b/src/gsm/conv_tch_afs_4_75_gen.c new file mode 100644 index 0000000..9180fbc --- /dev/null +++ b/src/gsm/conv_tch_afs_4_75_gen.c @@ -0,0 +1,177 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 4.75 kbits convolutional code: + G4/G6 = 1 + D2 + D3 + D5 + D6 / 1 + D + D2 + D3 + D4 + D6 + G4/G6 = 1 + D2 + D3 + D5 + D6 / 1 + D + D2 + D3 + D4 + D6 + G5/G6 = 1 + D + D4 + D6 / 1 + D + D2 + D3 + D4 + D6 + G6/G6 = 1 + G6/G6 = 1 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_4_75_state[][2] = { + { 0, 1 }, + { 3, 2 }, + { 5, 4 }, + { 6, 7 }, + { 9, 8 }, + { 10, 11 }, + { 12, 13 }, + { 15, 14 }, + { 17, 16 }, + { 18, 19 }, + { 20, 21 }, + { 23, 22 }, + { 24, 25 }, + { 27, 26 }, + { 29, 28 }, + { 30, 31 }, + { 32, 33 }, + { 35, 34 }, + { 37, 36 }, + { 38, 39 }, + { 41, 40 }, + { 42, 43 }, + { 44, 45 }, + { 47, 46 }, + { 49, 48 }, + { 50, 51 }, + { 52, 53 }, + { 55, 54 }, + { 56, 57 }, + { 59, 58 }, + { 61, 60 }, + { 62, 63 }, + { 1, 0 }, + { 2, 3 }, + { 4, 5 }, + { 7, 6 }, + { 8, 9 }, + { 11, 10 }, + { 13, 12 }, + { 14, 15 }, + { 16, 17 }, + { 19, 18 }, + { 21, 20 }, + { 22, 23 }, + { 25, 24 }, + { 26, 27 }, + { 28, 29 }, + { 31, 30 }, + { 33, 32 }, + { 34, 35 }, + { 36, 37 }, + { 39, 38 }, + { 40, 41 }, + { 43, 42 }, + { 45, 44 }, + { 46, 47 }, + { 48, 49 }, + { 51, 50 }, + { 53, 52 }, + { 54, 55 }, + { 57, 56 }, + { 58, 59 }, + { 60, 61 }, + { 63, 62 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_4_75_output[][2] = { + { 0, 31 }, + { 24, 7 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 0, 31 }, + { 24, 7 }, + { 24, 7 }, + { 0, 31 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 24, 7 }, + { 0, 31 }, + { 24, 7 }, + { 0, 31 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 24, 7 }, + { 0, 31 }, + { 0, 31 }, + { 24, 7 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 0, 31 }, + { 24, 7 }, + { 0, 31 }, + { 24, 7 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 0, 31 }, + { 24, 7 }, + { 24, 7 }, + { 0, 31 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 24, 7 }, + { 0, 31 }, + { 24, 7 }, + { 0, 31 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 24, 7 }, + { 0, 31 }, + { 0, 31 }, + { 24, 7 }, + { 4, 27 }, + { 28, 3 }, + { 4, 27 }, + { 28, 3 }, + { 0, 31 }, + { 24, 7 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_4_75_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_4_75_term_output[] = { + 0, 7, 27, 28, 27, 28, 0, 7, 7, 0, 28, 27, 28, 27, 7, 0, 24, 31, 3, 4, 3, 4, 24, 31, 31, 24, 4, 3, 4, 3, 31, 24, 31, 24, 4, 3, 4, 3, 31, 24, 24, 31, 3, 4, 3, 4, 24, 31, 7, 0, 28, 27, 28, 27, 7, 0, 0, 7, 27, 28, 27, 28, 0, 7, +}; diff --git a/src/gsm/conv_tch_afs_5_15_gen.c b/src/gsm/conv_tch_afs_5_15_gen.c new file mode 100644 index 0000000..1f20978 --- /dev/null +++ b/src/gsm/conv_tch_afs_5_15_gen.c @@ -0,0 +1,81 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 5.15 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 + G3/G3 = 1 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_15_state[][2] = { + { 0, 1 }, + { 3, 2 }, + { 5, 4 }, + { 6, 7 }, + { 9, 8 }, + { 10, 11 }, + { 12, 13 }, + { 15, 14 }, + { 1, 0 }, + { 2, 3 }, + { 4, 5 }, + { 7, 6 }, + { 8, 9 }, + { 11, 10 }, + { 13, 12 }, + { 14, 15 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_15_output[][2] = { + { 0, 31 }, + { 4, 27 }, + { 24, 7 }, + { 28, 3 }, + { 4, 27 }, + { 0, 31 }, + { 28, 3 }, + { 24, 7 }, + { 0, 31 }, + { 4, 27 }, + { 24, 7 }, + { 28, 3 }, + { 4, 27 }, + { 0, 31 }, + { 28, 3 }, + { 24, 7 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_15_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_15_term_output[] = { + 0, 27, 7, 28, 27, 0, 28, 7, 31, 4, 24, 3, 4, 31, 3, 24, +}; diff --git a/src/gsm/conv_tch_afs_5_9_gen.c b/src/gsm/conv_tch_afs_5_9_gen.c new file mode 100644 index 0000000..1aa9b31 --- /dev/null +++ b/src/gsm/conv_tch_afs_5_9_gen.c @@ -0,0 +1,177 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 5.9 kbits convolutional code: + 124 bits + G4/G6 = 1 + D2 + D3 + D5 + D6 / 1 + D + D2 + D3 + D4 + D6 + G5/G6 = 1 + D + D4 + D6 / 1 + D + D2 + D3 + D4 + D6 + G6/G6 = 1 + G6/G6 = 1 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_9_state[][2] = { + { 0, 1 }, + { 3, 2 }, + { 5, 4 }, + { 6, 7 }, + { 9, 8 }, + { 10, 11 }, + { 12, 13 }, + { 15, 14 }, + { 17, 16 }, + { 18, 19 }, + { 20, 21 }, + { 23, 22 }, + { 24, 25 }, + { 27, 26 }, + { 29, 28 }, + { 30, 31 }, + { 32, 33 }, + { 35, 34 }, + { 37, 36 }, + { 38, 39 }, + { 41, 40 }, + { 42, 43 }, + { 44, 45 }, + { 47, 46 }, + { 49, 48 }, + { 50, 51 }, + { 52, 53 }, + { 55, 54 }, + { 56, 57 }, + { 59, 58 }, + { 61, 60 }, + { 62, 63 }, + { 1, 0 }, + { 2, 3 }, + { 4, 5 }, + { 7, 6 }, + { 8, 9 }, + { 11, 10 }, + { 13, 12 }, + { 14, 15 }, + { 16, 17 }, + { 19, 18 }, + { 21, 20 }, + { 22, 23 }, + { 25, 24 }, + { 26, 27 }, + { 28, 29 }, + { 31, 30 }, + { 33, 32 }, + { 34, 35 }, + { 36, 37 }, + { 39, 38 }, + { 40, 41 }, + { 43, 42 }, + { 45, 44 }, + { 46, 47 }, + { 48, 49 }, + { 51, 50 }, + { 53, 52 }, + { 54, 55 }, + { 57, 56 }, + { 58, 59 }, + { 60, 61 }, + { 63, 62 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_9_output[][2] = { + { 0, 15 }, + { 8, 7 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 0, 15 }, + { 8, 7 }, + { 8, 7 }, + { 0, 15 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 8, 7 }, + { 0, 15 }, + { 8, 7 }, + { 0, 15 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 8, 7 }, + { 0, 15 }, + { 0, 15 }, + { 8, 7 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 0, 15 }, + { 8, 7 }, + { 0, 15 }, + { 8, 7 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 0, 15 }, + { 8, 7 }, + { 8, 7 }, + { 0, 15 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 8, 7 }, + { 0, 15 }, + { 8, 7 }, + { 0, 15 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 8, 7 }, + { 0, 15 }, + { 0, 15 }, + { 8, 7 }, + { 4, 11 }, + { 12, 3 }, + { 4, 11 }, + { 12, 3 }, + { 0, 15 }, + { 8, 7 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_9_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_5_9_term_output[] = { + 0, 7, 11, 12, 11, 12, 0, 7, 7, 0, 12, 11, 12, 11, 7, 0, 8, 15, 3, 4, 3, 4, 8, 15, 15, 8, 4, 3, 4, 3, 15, 8, 15, 8, 4, 3, 4, 3, 15, 8, 8, 15, 3, 4, 3, 4, 8, 15, 7, 0, 12, 11, 12, 11, 7, 0, 0, 7, 11, 12, 11, 12, 0, 7, +}; diff --git a/src/gsm/conv_tch_afs_6_7_gen.c b/src/gsm/conv_tch_afs_6_7_gen.c new file mode 100644 index 0000000..fe17e7b --- /dev/null +++ b/src/gsm/conv_tch_afs_6_7_gen.c @@ -0,0 +1,80 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 6.7 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 + G3/G3 = 1 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_6_7_state[][2] = { + { 0, 1 }, + { 3, 2 }, + { 5, 4 }, + { 6, 7 }, + { 9, 8 }, + { 10, 11 }, + { 12, 13 }, + { 15, 14 }, + { 1, 0 }, + { 2, 3 }, + { 4, 5 }, + { 7, 6 }, + { 8, 9 }, + { 11, 10 }, + { 13, 12 }, + { 14, 15 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_6_7_output[][2] = { + { 0, 15 }, + { 4, 11 }, + { 8, 7 }, + { 12, 3 }, + { 4, 11 }, + { 0, 15 }, + { 12, 3 }, + { 8, 7 }, + { 0, 15 }, + { 4, 11 }, + { 8, 7 }, + { 12, 3 }, + { 4, 11 }, + { 0, 15 }, + { 12, 3 }, + { 8, 7 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_6_7_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_6_7_term_output[] = { + 0, 11, 7, 12, 11, 0, 12, 7, 15, 4, 8, 3, 4, 15, 3, 8, +}; diff --git a/src/gsm/conv_tch_afs_7_4_gen.c b/src/gsm/conv_tch_afs_7_4_gen.c new file mode 100644 index 0000000..d4441c6 --- /dev/null +++ b/src/gsm/conv_tch_afs_7_4_gen.c @@ -0,0 +1,79 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 7.4 kbits convolutional code: + G1/G3 = 1 + D + D3 + D4 / 1 + D + D2 + D3 + D4 + G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4 + G3/G3 = 1 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_4_state[][2] = { + { 0, 1 }, + { 3, 2 }, + { 5, 4 }, + { 6, 7 }, + { 9, 8 }, + { 10, 11 }, + { 12, 13 }, + { 15, 14 }, + { 1, 0 }, + { 2, 3 }, + { 4, 5 }, + { 7, 6 }, + { 8, 9 }, + { 11, 10 }, + { 13, 12 }, + { 14, 15 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_4_output[][2] = { + { 0, 7 }, + { 2, 5 }, + { 4, 3 }, + { 6, 1 }, + { 2, 5 }, + { 0, 7 }, + { 6, 1 }, + { 4, 3 }, + { 0, 7 }, + { 2, 5 }, + { 4, 3 }, + { 6, 1 }, + { 2, 5 }, + { 0, 7 }, + { 6, 1 }, + { 4, 3 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_4_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_4_term_output[] = { + 0, 5, 3, 6, 5, 0, 6, 3, 7, 2, 4, 1, 2, 7, 1, 4, +}; diff --git a/src/gsm/conv_tch_afs_7_95_gen.c b/src/gsm/conv_tch_afs_7_95_gen.c new file mode 100644 index 0000000..f89be5b --- /dev/null +++ b/src/gsm/conv_tch_afs_7_95_gen.c @@ -0,0 +1,175 @@ + +/* + * Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com + * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdint.h> + +/* TCH/AFS 7.95 kbits convolutional code: + G4/G4 = 1 + G5/G4 = 1 + D + D4 + D6 / 1 + D2 + D3 + D5 + D6 + G6/G4 = 1 + D + D2 + D3 + D4 + D6 / 1 + D2 + D3 + D5 + D6 + */ + +/* .next_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_95_state[][2] = { + { 0, 1 }, + { 2, 3 }, + { 5, 4 }, + { 7, 6 }, + { 9, 8 }, + { 11, 10 }, + { 12, 13 }, + { 14, 15 }, + { 16, 17 }, + { 18, 19 }, + { 21, 20 }, + { 23, 22 }, + { 25, 24 }, + { 27, 26 }, + { 28, 29 }, + { 30, 31 }, + { 33, 32 }, + { 35, 34 }, + { 36, 37 }, + { 38, 39 }, + { 40, 41 }, + { 42, 43 }, + { 45, 44 }, + { 47, 46 }, + { 49, 48 }, + { 51, 50 }, + { 52, 53 }, + { 54, 55 }, + { 56, 57 }, + { 58, 59 }, + { 61, 60 }, + { 63, 62 }, + { 1, 0 }, + { 3, 2 }, + { 4, 5 }, + { 6, 7 }, + { 8, 9 }, + { 10, 11 }, + { 13, 12 }, + { 15, 14 }, + { 17, 16 }, + { 19, 18 }, + { 20, 21 }, + { 22, 23 }, + { 24, 25 }, + { 26, 27 }, + { 29, 28 }, + { 31, 30 }, + { 32, 33 }, + { 34, 35 }, + { 37, 36 }, + { 39, 38 }, + { 41, 40 }, + { 43, 42 }, + { 44, 45 }, + { 46, 47 }, + { 48, 49 }, + { 50, 51 }, + { 53, 52 }, + { 55, 54 }, + { 57, 56 }, + { 59, 58 }, + { 60, 61 }, + { 62, 63 }, +}; + +/* .next_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_95_output[][2] = { + { 0, 7 }, + { 3, 4 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 0, 7 }, + { 3, 4 }, + { 3, 4 }, + { 0, 7 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 3, 4 }, + { 0, 7 }, + { 3, 4 }, + { 0, 7 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 3, 4 }, + { 0, 7 }, + { 0, 7 }, + { 3, 4 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 0, 7 }, + { 3, 4 }, + { 0, 7 }, + { 3, 4 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 0, 7 }, + { 3, 4 }, + { 3, 4 }, + { 0, 7 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 3, 4 }, + { 0, 7 }, + { 3, 4 }, + { 0, 7 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 3, 4 }, + { 0, 7 }, + { 0, 7 }, + { 3, 4 }, + { 2, 5 }, + { 1, 6 }, + { 2, 5 }, + { 1, 6 }, + { 0, 7 }, + { 3, 4 }, +}; + +/* .next_term_state */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_95_term_state[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, +}; + +/* .next_term_output */ +const uint8_t osmo_conv_gsm0503_tch_afs_7_95_term_output[] = { + 0, 3, 5, 6, 5, 6, 0, 3, 3, 0, 6, 5, 6, 5, 3, 0, 4, 7, 1, 2, 1, 2, 4, 7, 7, 4, 2, 1, 2, 1, 7, 4, 7, 4, 2, 1, 2, 1, 7, 4, 4, 7, 1, 2, 1, 2, 4, 7, 3, 0, 6, 5, 6, 5, 3, 0, 0, 3, 5, 6, 5, 6, 0, 3, +}; diff --git a/tests/conv/conv_test.c b/tests/conv/conv_test.c index 6e99b2e..3032ee0 100644 --- a/tests/conv/conv_test.c +++ b/tests/conv/conv_test.c @@ -16,82 +16,6 @@ /* Test codes */ /* ------------------------------------------------------------------------ */
-/* GSM TCH/AFS 7.95 -> Recursive code, flushed, with puncturing */ -static const uint8_t conv_gsm_tch_afs_7_95_next_output[][2] = { - { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 }, - { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 }, - { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 }, - { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 }, - { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 }, - { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 }, - { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 }, - { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 }, - { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 }, - { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 }, - { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 }, - { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 }, - { 3, 4 }, { 0, 7 }, { 1, 6 }, { 2, 5 }, - { 1, 6 }, { 2, 5 }, { 3, 4 }, { 0, 7 }, - { 0, 7 }, { 3, 4 }, { 2, 5 }, { 1, 6 }, - { 2, 5 }, { 1, 6 }, { 0, 7 }, { 3, 4 }, -}; - -static const uint8_t conv_gsm_tch_afs_7_95_next_state[][2] = { - { 0, 1 }, { 2, 3 }, { 5, 4 }, { 7, 6 }, - { 9, 8 }, { 11, 10 }, { 12, 13 }, { 14, 15 }, - { 16, 17 }, { 18, 19 }, { 21, 20 }, { 23, 22 }, - { 25, 24 }, { 27, 26 }, { 28, 29 }, { 30, 31 }, - { 33, 32 }, { 35, 34 }, { 36, 37 }, { 38, 39 }, - { 40, 41 }, { 42, 43 }, { 45, 44 }, { 47, 46 }, - { 49, 48 }, { 51, 50 }, { 52, 53 }, { 54, 55 }, - { 56, 57 }, { 58, 59 }, { 61, 60 }, { 63, 62 }, - { 1, 0 }, { 3, 2 }, { 4, 5 }, { 6, 7 }, - { 8, 9 }, { 10, 11 }, { 13, 12 }, { 15, 14 }, - { 17, 16 }, { 19, 18 }, { 20, 21 }, { 22, 23 }, - { 24, 25 }, { 26, 27 }, { 29, 28 }, { 31, 30 }, - { 32, 33 }, { 34, 35 }, { 37, 36 }, { 39, 38 }, - { 41, 40 }, { 43, 42 }, { 44, 45 }, { 46, 47 }, - { 48, 49 }, { 50, 51 }, { 53, 52 }, { 55, 54 }, - { 57, 56 }, { 59, 58 }, { 60, 61 }, { 62, 63 }, -}; - -static const uint8_t conv_gsm_tch_afs_7_95_next_term_output[] = { - 0, 3, 5, 6, 5, 6, 0, 3, 3, 0, 6, 5, 6, 5, 3, 0, - 4, 7, 1, 2, 1, 2, 4, 7, 7, 4, 2, 1, 2, 1, 7, 4, - 7, 4, 2, 1, 2, 1, 7, 4, 4, 7, 1, 2, 1, 2, 4, 7, - 3, 0, 6, 5, 6, 5, 3, 0, 0, 3, 5, 6, 5, 6, 0, 3, -}; - -static const uint8_t conv_gsm_tch_afs_7_95_next_term_state[] = { - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, -}; - -static int conv_gsm_tch_afs_7_95_puncture[] = { - 1, 2, 4, 5, 8, 22, 70, 118, 166, 214, 262, 310, - 317, 319, 325, 332, 334, 341, 343, 349, 356, 358, 365, 367, - 373, 380, 382, 385, 389, 391, 397, 404, 406, 409, 413, 415, - 421, 428, 430, 433, 437, 439, 445, 452, 454, 457, 461, 463, - 469, 476, 478, 481, 485, 487, 490, 493, 500, 502, 503, 505, - 506, 508, 509, 511, 512, - -1, /* end */ -}; - -static const struct osmo_conv_code conv_gsm_tch_afs_7_95 = { - .N = 3, - .K = 7, - .len = 165, - .term = CONV_TERM_FLUSH, - .next_output = conv_gsm_tch_afs_7_95_next_output, - .next_state = conv_gsm_tch_afs_7_95_next_state, - .next_term_output = conv_gsm_tch_afs_7_95_next_term_output, - .next_term_state = conv_gsm_tch_afs_7_95_next_term_state, - .puncture = conv_gsm_tch_afs_7_95_puncture, -}; - - /* GMR-1 TCH3 Speech -> Non recursive code, tail-biting, punctured */ static const uint8_t conv_gmr1_tch3_speech_next_output[][2] = { { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, @@ -244,7 +168,7 @@ static const struct conv_test_vector tests[] = { }, { .name = "GSM TCH/AFS 7.95 (recursive, flushed, punctured)", - .code = &conv_gsm_tch_afs_7_95, + .code = &osmo_conv_gsm0503_tch_afs_7_95, .in_len = 165, .out_len = 448, .has_vec = 1,
On 11 Apr 2016, at 10:22, msuraev@sysmocom.de wrote:
From: Max msuraev@sysmocom.de
Add python utility to generate .c code with state/output tables for convolutional encoder/decoder based on polynomial description of the code. If argument given it'll be interpreted as intended output directory, otherwise current working directory is used. Note: only necessary tables are generated. Corresponding header files with actual osmo_conv_code instance (including puncturing etc) have to be added manually.
Fixes: OS#1629
utils/conv_gen.py | 359 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100755 utils/conv_gen.py
diff --git a/utils/conv_gen.py b/utils/conv_gen.py new file mode 100755 index 0000000..52c1ab3 --- /dev/null +++ b/utils/conv_gen.py @@ -0,0 +1,359 @@ +#!/usr/bin/python
+license =""" +/*
- Copyright (C) 2011-2016 Sylvain Munaut tnt@246tNt.com
- Copyright (C) 2016 sysmocom s.f.m.c. GmbH
what is yours (sysmocom's) contribution to that file? I assume that Sylvain did most of the work, it would be nice to have this be reflected in the commit message.
thank you holger