diff mbox

[2/4] Add concolutional code generator for *CCH

Message ID 1461011051-11657-2-git-send-email-suraev@alumni.ntnu.no
State Not Applicable
Headers show

Commit Message

Suraev April 18, 2016, 8:24 p.m. UTC
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 by calling "./utils/conv_gen.py src/gsm". In future we might
switch to automated compile-time generation instead.
---
 include/Makefile.am           |   1 +
 include/osmocom/gsm/gsm0503.h |  37 ++++++++
 src/gsm/Makefile.am           |   2 +-
 src/gsm/conv_xcch_gen.c       |  75 +++++++++++++++
 src/gsm/libosmogsm.map        |   1 +
 tests/Makefile.am             |   2 +-
 tests/conv/conv_test.c        | 207 ++++++++++++++++++------------------------
 7 files changed, 205 insertions(+), 120 deletions(-)
 create mode 100644 include/osmocom/gsm/gsm0503.h
 create mode 100644 src/gsm/conv_xcch_gen.c

Comments

Neels Hofmeyr April 19, 2016, 12:48 a.m. UTC | #1
It's like the 4th time you post the "concolutional" commit log message ;)
Can you fix the typo for me plz?

~Neels
Max April 20, 2016, 8 a.m. UTC | #2
Thanks for spotting it. I would have already fixed it if you'd voiced
one of the previous 3 instances :)

On 04/19/2016 02:48 AM, Neels Hofmeyr wrote:
> It's like the 4th time you post the "concolutional" commit log message ;)
> Can you fix the typo for me plz?
>
> ~Neels
>
diff mbox

Patch

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..46d86ad
--- /dev/null
+++ b/include/osmocom/gsm/gsm0503.h
@@ -0,0 +1,37 @@ 
+/*
+ * 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>
+
+/*! \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.
+ */
+extern const struct osmo_conv_code osmo_conv_gsm0503_xcch;
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..5b8cc5e
--- /dev/null
+++ b/src/gsm/conv_xcch_gen.c
@@ -0,0 +1,75 @@ 
+
+/*
+ * 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>
+#include <osmocom/core/conv.h>
+
+static 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 },
+};
+
+static 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 },
+};
+
+/*  *CCH convolutional code:
+        228 bits blocks, rate 1/2, k = 5
+        G0 = 1 + D3 + D4
+        G1 = 1 + D + D3 + D4
+ */
+const struct osmo_conv_code osmo_conv_gsm0503_xcch = {
+	.N = 2,
+	.K = 5,
+	.len = 224,
+	.next_output = osmo_conv_gsm0503_xcch_output,
+	.next_state = osmo_conv_gsm0503_xcch_state,
+};
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 6886a6c..16fb7ee 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..d8779db 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 },
@@ -220,18 +196,6 @@  static const struct osmo_conv_code conv_wimax_fch = {
 	.next_state  = conv_wimax_fch_next_state,
 };
 
-
-/* Random code -> Non recursive code, direct truncation, non-punctured */
-static const struct osmo_conv_code conv_trunc = {
-	.N = 2,
-	.K = 5,
-	.len = 224,
-	.term = CONV_TERM_TRUNCATION,
-	.next_output = conv_gsm_xcch_next_output,
-	.next_state  = conv_gsm_xcch_next_state,
-};
-
-
 /* ------------------------------------------------------------------------ */
 /* Test vectors                                                             */
 /* ------------------------------------------------------------------------ */
@@ -246,87 +210,6 @@  struct conv_test_vector {
 	pbit_t vec_out[MAX_LEN_BYTES];
 };
 
-static const struct conv_test_vector tests[] = {
-	{
-		.name = "GSM xCCH (non-recursive, flushed, not punctured)",
-		.code = &conv_gsm_xcch,
-		.in_len  = 224,
-		.out_len = 456,
-		.has_vec = 1,
-		.vec_in  = { 0xf3, 0x1d, 0xb4, 0x0c, 0x4d, 0x1d, 0x9d, 0xae,
-		             0xc0, 0x0a, 0x42, 0x57, 0x13, 0x60, 0x80, 0x96,
-		             0xef, 0x23, 0x7e, 0x4c, 0x1d, 0x96, 0x24, 0x19,
-		             0x17, 0xf2, 0x44, 0x99 },
-		.vec_out = { 0xe9, 0x4d, 0x70, 0xab, 0xa2, 0x87, 0xf0, 0xe7,
-		             0x04, 0x14, 0x7c, 0xab, 0xaf, 0x6b, 0xa1, 0x16,
-		             0xeb, 0x30, 0x00, 0xde, 0xc8, 0xfd, 0x0b, 0x85,
-		             0x80, 0x41, 0x4a, 0xcc, 0xd3, 0xc0, 0xd0, 0xb6,
-		             0x26, 0xe5, 0x4e, 0x32, 0x49, 0x69, 0x38, 0x17,
-		             0x33, 0xab, 0xaf, 0xb6, 0xc1, 0x08, 0xf3, 0x9f,
-		             0x8c, 0x75, 0x6a, 0x4e, 0x08, 0xc4, 0x20, 0x5f,
-		             0x8f },
-	},
-	{
-		.name = "GSM TCH/AFS 7.95 (recursive, flushed, punctured)",
-		.code = &conv_gsm_tch_afs_7_95,
-		.in_len  = 165,
-		.out_len = 448,
-		.has_vec = 1,
-		.vec_in  = { 0x87, 0x66, 0xc3, 0x58, 0x09, 0xd4, 0x06, 0x59,
-		             0x10, 0xbf, 0x6b, 0x7f, 0xc8, 0xed, 0x72, 0xaa,
-		             0xc1, 0x3d, 0xf3, 0x1e, 0xb0 },
-		.vec_out = { 0x92, 0xbc, 0xde, 0xa0, 0xde, 0xbe, 0x01, 0x2f,
-		             0xbe, 0xe4, 0x61, 0x32, 0x4d, 0x4f, 0xdc, 0x41,
-		             0x43, 0x0d, 0x15, 0xe0, 0x23, 0xdd, 0x18, 0x91,
-		             0xe5, 0x36, 0x2d, 0xb7, 0xd9, 0x78, 0xb8, 0xb1,
-		             0xb7, 0xcb, 0x2f, 0xc0, 0x52, 0x8f, 0xe2, 0x8c,
-		             0x6f, 0xa6, 0x79, 0x88, 0xed, 0x0c, 0x2e, 0x9e,
-		             0xa1, 0x5f, 0x45, 0x4a, 0xfb, 0xe6, 0x5a, 0x9c },
-	},
-	{
-		.name = "GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)",
-		.code = &conv_gmr1_tch3_speech,
-		.in_len  = 48,
-		.out_len = 72,
-		.has_vec = 1,
-		.vec_in  = { 0x4d, 0xcb, 0xfc, 0x72, 0xf4, 0x8c },
-		.vec_out = { 0xc0, 0x86, 0x63, 0x4b, 0x8b, 0xd4, 0x6a, 0x76, 0xb2 },
-	},
-	{
-		.name = "WiMax FCH (non-recursive, tail-biting, not punctured)",
-		.code = &conv_wimax_fch,
-		.in_len  = 48,
-		.out_len = 96,
-		.has_vec = 1,
-		.vec_in  = { 0xfc, 0xa0, 0xa0, 0xfc, 0xa0, 0xa0 },
-		.vec_out = { 0x19, 0x42, 0x8a, 0xed, 0x21, 0xed, 0x19, 0x42,
-		             0x8a, 0xed, 0x21, 0xed },
-	},
-	{
-		.name = "??? (non-recursive, direct truncation, not punctured)",
-		.code = &conv_trunc,
-		.in_len  = 224,
-		.out_len = 448,
-		.has_vec = 1,
-		.vec_in  = { 0xe5, 0xe0, 0x85, 0x7e, 0xf7, 0x08, 0x19, 0x5a,
-		             0xb9, 0xad, 0x82, 0x37, 0x98, 0x8b, 0x26, 0xb9,
-		             0x81, 0x26, 0x9c, 0x75, 0xaf, 0xf3, 0xcb, 0x07,
-		             0xac, 0x63, 0xe2, 0x9c,
-		},
-		.vec_out = { 0xea, 0x3b, 0x55, 0x0c, 0xd3, 0xf7, 0x85, 0x69,
-		             0xe5, 0x79, 0x83, 0xd3, 0xc3, 0x9f, 0xb8, 0x61,
-		             0x21, 0x63, 0x51, 0x18, 0xac, 0xcd, 0x32, 0x49,
-		             0x53, 0x5c, 0x13, 0x1d, 0xbe, 0x05, 0x11, 0x63,
-		             0x5c, 0xc3, 0x42, 0x05, 0x1c, 0x68, 0x0a, 0xb4,
-		             0x61, 0x15, 0xaa, 0x4d, 0x94, 0xed, 0xb3, 0x3a,
-		             0x5d, 0x1b, 0x09, 0xc2, 0x99, 0x01, 0xec, 0x68 },
-	},
-	{ /* end */ },
-};
-
-
-
-
 /* ------------------------------------------------------------------------ */
 /* Main                                                                     */
 /* ------------------------------------------------------------------------ */
@@ -345,6 +228,94 @@  int main(int argc, char *argv[])
 	ubit_t *bu0, *bu1;
 	sbit_t *bs;
 
+/* Random code -> Non recursive code, direct truncation, non-punctured */
+	const struct osmo_conv_code conv_trunc = {
+		.N = 2,
+		.K = 5,
+		.len = 224,
+		.term = CONV_TERM_TRUNCATION,
+		.next_output = osmo_conv_gsm0503_xcch.next_output,
+		.next_state  = osmo_conv_gsm0503_xcch.next_state,
+	};
+
+	const struct conv_test_vector tests[] = {
+		{
+			.name = "GSM xCCH (non-recursive, flushed, not punctured)",
+			.code = &osmo_conv_gsm0503_xcch,
+			.in_len  = 224,
+			.out_len = 456,
+			.has_vec = 1,
+			.vec_in  = { 0xf3, 0x1d, 0xb4, 0x0c, 0x4d, 0x1d, 0x9d, 0xae,
+						 0xc0, 0x0a, 0x42, 0x57, 0x13, 0x60, 0x80, 0x96,
+						 0xef, 0x23, 0x7e, 0x4c, 0x1d, 0x96, 0x24, 0x19,
+						 0x17, 0xf2, 0x44, 0x99 },
+			.vec_out = { 0xe9, 0x4d, 0x70, 0xab, 0xa2, 0x87, 0xf0, 0xe7,
+						 0x04, 0x14, 0x7c, 0xab, 0xaf, 0x6b, 0xa1, 0x16,
+						 0xeb, 0x30, 0x00, 0xde, 0xc8, 0xfd, 0x0b, 0x85,
+						 0x80, 0x41, 0x4a, 0xcc, 0xd3, 0xc0, 0xd0, 0xb6,
+						 0x26, 0xe5, 0x4e, 0x32, 0x49, 0x69, 0x38, 0x17,
+						 0x33, 0xab, 0xaf, 0xb6, 0xc1, 0x08, 0xf3, 0x9f,
+						 0x8c, 0x75, 0x6a, 0x4e, 0x08, 0xc4, 0x20, 0x5f,
+						 0x8f },
+		},
+		{
+			.name = "GSM TCH/AFS 7.95 (recursive, flushed, punctured)",
+			.code = &conv_gsm_tch_afs_7_95,
+			.in_len  = 165,
+			.out_len = 448,
+			.has_vec = 1,
+			.vec_in  = { 0x87, 0x66, 0xc3, 0x58, 0x09, 0xd4, 0x06, 0x59,
+						 0x10, 0xbf, 0x6b, 0x7f, 0xc8, 0xed, 0x72, 0xaa,
+						 0xc1, 0x3d, 0xf3, 0x1e, 0xb0 },
+			.vec_out = { 0x92, 0xbc, 0xde, 0xa0, 0xde, 0xbe, 0x01, 0x2f,
+						 0xbe, 0xe4, 0x61, 0x32, 0x4d, 0x4f, 0xdc, 0x41,
+						 0x43, 0x0d, 0x15, 0xe0, 0x23, 0xdd, 0x18, 0x91,
+						 0xe5, 0x36, 0x2d, 0xb7, 0xd9, 0x78, 0xb8, 0xb1,
+						 0xb7, 0xcb, 0x2f, 0xc0, 0x52, 0x8f, 0xe2, 0x8c,
+						 0x6f, 0xa6, 0x79, 0x88, 0xed, 0x0c, 0x2e, 0x9e,
+						 0xa1, 0x5f, 0x45, 0x4a, 0xfb, 0xe6, 0x5a, 0x9c },
+		},
+		{
+			.name = "GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)",
+			.code = &conv_gmr1_tch3_speech,
+			.in_len  = 48,
+			.out_len = 72,
+			.has_vec = 1,
+		.vec_in  = { 0x4d, 0xcb, 0xfc, 0x72, 0xf4, 0x8c },
+			.vec_out = { 0xc0, 0x86, 0x63, 0x4b, 0x8b, 0xd4, 0x6a, 0x76, 0xb2 },
+		},
+		{
+			.name = "WiMax FCH (non-recursive, tail-biting, not punctured)",
+			.code = &conv_wimax_fch,
+			.in_len  = 48,
+			.out_len = 96,
+			.has_vec = 1,
+			.vec_in  = { 0xfc, 0xa0, 0xa0, 0xfc, 0xa0, 0xa0 },
+			.vec_out = { 0x19, 0x42, 0x8a, 0xed, 0x21, 0xed, 0x19, 0x42,
+						 0x8a, 0xed, 0x21, 0xed },
+		},
+		{
+			.name = "??? (non-recursive, direct truncation, not punctured)",
+			.code = &conv_trunc,
+			.in_len  = 224,
+			.out_len = 448,
+			.has_vec = 1,
+			.vec_in  = { 0xe5, 0xe0, 0x85, 0x7e, 0xf7, 0x08, 0x19, 0x5a,
+						 0xb9, 0xad, 0x82, 0x37, 0x98, 0x8b, 0x26, 0xb9,
+						 0x81, 0x26, 0x9c, 0x75, 0xaf, 0xf3, 0xcb, 0x07,
+						 0xac, 0x63, 0xe2, 0x9c,
+			},
+			.vec_out = { 0xea, 0x3b, 0x55, 0x0c, 0xd3, 0xf7, 0x85, 0x69,
+						 0xe5, 0x79, 0x83, 0xd3, 0xc3, 0x9f, 0xb8, 0x61,
+						 0x21, 0x63, 0x51, 0x18, 0xac, 0xcd, 0x32, 0x49,
+						 0x53, 0x5c, 0x13, 0x1d, 0xbe, 0x05, 0x11, 0x63,
+						 0x5c, 0xc3, 0x42, 0x05, 0x1c, 0x68, 0x0a, 0xb4,
+						 0x61, 0x15, 0xaa, 0x4d, 0x94, 0xed, 0xb3, 0x3a,
+						 0x5d, 0x1b, 0x09, 0xc2, 0x99, 0x01, 0xec, 0x68 },
+		},
+		{ /* end */ },
+	};
+
 	srandom(time(NULL));
 
 	bu0 = malloc(sizeof(ubit_t) * MAX_LEN_BITS);