OpenBSC
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
April 2014
- 15 participants
- 23 discussions
[openbsc PATCH 1/5] openbsc/gsm_data_shared.h: Added the attribute reduce_power in TRX
by Alvaro Neira Ayuso 29 Apr '14
by Alvaro Neira Ayuso 29 Apr '14
29 Apr '14
From: Álvaro Neira Ayuso <anayuso(a)sysmocom.de>
Signed-off-by: Alvaro Neira Ayuso <anayuso(a)sysmocom.de>
---
openbsc/include/openbsc/gsm_data_shared.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/openbsc/include/openbsc/gsm_data_shared.h b/openbsc/include/openbsc/gsm_data_shared.h
index ae9e7d8..a4d3c54 100644
--- a/openbsc/include/openbsc/gsm_data_shared.h
+++ b/openbsc/include/openbsc/gsm_data_shared.h
@@ -371,6 +371,7 @@ struct gsm_bts_trx {
uint16_t arfcn;
int nominal_power; /* in dBm */
unsigned int max_power_red; /* in actual dB */
+ int power_reduce; /* in dBm */
struct {
void *l1h;
--
1.7.10.4
2
3
Gentoo Linux now supports Network from Scratch in 5 easy steps. We're
using jolly's branches for the live ebuilds. (ETA on when we can ship
master?)
Network from Scratch on Gentoo
==============================
1. Add these to packages.keywords (in /etc/portage):
=net-wireless/openbsc-9999 **
=net-wireless/osmobts-9999 **
=net-wireless/osmotrx-9999 **
=net-libs/libosmo-abis-9999 **
2. Make sure your portage tree is up to date, and emerge the right packages:
$ sudo emerge --sync
$ sudo emerge openbsc osmobts osmotrx
3. Download configuration templates:
$ mkdir ~/.osmocom
$ wget -O ~/.osmocom/open-bsc.cfg http://bpaste.net/raw/236987/
$ wget -O ~/.osmocom/osmo-bts.cfg http://bpaste.net/raw/237000/
4. Edit configuration templates to work on spectrum you have a license for:
$ vim ~/.osmocom/*.cfg
5. Start these babies up, in separate shells:
shell1 $ osmo-nitb -c ~/.osmocom/open-bsc.cfg -l
~/.osmocom/hlr.sqlite3 -P -C --debug=DRLL:DCC:DMM:DRR:DRSL:DNM
shell2 $ osmobts-trx -c ~/.osmocom/osmo-bts.cfg
shell3 $ osmo-trx
4
5
Funny bug. osmo-nitb, jolly's branches for everything.
Send a blank SMS. Receiver doesn't get blank message. Instead receiver
gets garbage, different everytime. Presumably this is uninitialized
memory until the first null.
2
1
Add 20 additional convolutional test cases for commonly used codes.
These include 16 codes for various cases of GSM TCH handing and an
additional tail-biting case for LTE broadcast channels.
Signed-off-by: Thomas Tsou <tom(a)tsou.cc>
---
tests/Makefile.am | 2 +-
tests/conv/codes.c | 1034 +++++++++++++++++++++++++++++++++++++++++++++++
tests/conv/codes.h | 30 ++
tests/conv/conv_test.c | 378 +++++++----------
tests/conv/conv_test.ok | 128 ++++++
5 files changed, 1344 insertions(+), 228 deletions(-)
create mode 100644 tests/conv/codes.c
create mode 100644 tests/conv/codes.h
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c6216d5..42fea46 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,7 @@ auth_milenage_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/sr
bits_bitrev_test_SOURCES = bits/bitrev_test.c
bits_bitrev_test_LDADD = $(top_builddir)/src/libosmocore.la
-conv_conv_test_SOURCES = conv/conv_test.c
+conv_conv_test_SOURCES = conv/conv_test.c conv/codes.c
conv_conv_test_LDADD = $(top_builddir)/src/libosmocore.la
gsm0808_gsm0808_test_SOURCES = gsm0808/gsm0808_test.c
diff --git a/tests/conv/codes.c b/tests/conv/codes.c
new file mode 100644
index 0000000..703946b
--- /dev/null
+++ b/tests/conv/codes.c
@@ -0,0 +1,1034 @@
+#include <osmocom/core/conv.h>
+#include "codes.h"
+
+static const uint8_t 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 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 },
+};
+
+/* GSM XCCH */
+const struct osmo_conv_code gsm_conv_xcch = {
+ .N = 2,
+ .K = 5,
+ .len = 224,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
+
+/* GPRS CS2 */
+const struct osmo_conv_code gsm_conv_cs2 = {
+ .N = 2,
+ .K = 5,
+ .len = 290,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
+
+/* GPRS CS3 */
+const struct osmo_conv_code gsm_conv_cs3 = {
+ .N = 2,
+ .K = 5,
+ .len = 334,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
+
+/* GSM RACH */
+const struct osmo_conv_code gsm_conv_rach = {
+ .N = 2,
+ .K = 5,
+ .len = 14,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
+
+/* GSM SCH */
+const struct osmo_conv_code gsm_conv_sch = {
+ .N = 2,
+ .K = 5,
+ .len = 35,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
+
+/* GSM TCH-FR */
+const struct osmo_conv_code gsm_conv_tch_fr = {
+ .N = 2,
+ .K = 5,
+ .len = 185,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
+
+static const uint8_t tch_hr_next_output[][2] = {
+ { 0, 7 }, { 3, 4 }, { 5, 2 }, { 6, 1 },
+ { 5, 2 }, { 6, 1 }, { 0, 7 }, { 3, 4 },
+ { 3, 4 }, { 0, 7 }, { 6, 1 }, { 5, 2 },
+ { 6, 1 }, { 5, 2 }, { 3, 4 }, { 0, 7 },
+ { 4, 3 }, { 7, 0 }, { 1, 6 }, { 2, 5 },
+ { 1, 6 }, { 2, 5 }, { 4, 3 }, { 7, 0 },
+ { 7, 0 }, { 4, 3 }, { 2, 5 }, { 1, 6 },
+ { 2, 5 }, { 1, 6 }, { 7, 0 }, { 4, 3 },
+ { 7, 0 }, { 4, 3 }, { 2, 5 }, { 1, 6 },
+ { 2, 5 }, { 1, 6 }, { 7, 0 }, { 4, 3 },
+ { 4, 3 }, { 7, 0 }, { 1, 6 }, { 2, 5 },
+ { 1, 6 }, { 2, 5 }, { 4, 3 }, { 7, 0 },
+ { 3, 4 }, { 0, 7 }, { 6, 1 }, { 5, 2 },
+ { 6, 1 }, { 5, 2 }, { 3, 4 }, { 0, 7 },
+ { 0, 7 }, { 3, 4 }, { 5, 2 }, { 6, 1 },
+ { 5, 2 }, { 6, 1 }, { 0, 7 }, { 3, 4 },
+};
+
+static const uint8_t tch_hr_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+};
+
+static const int tch_hr_puncture[] = {
+ 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34,
+ 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70,
+ 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106,
+ 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142,
+ 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178,
+ 181, 184, 187, 190, 193, 196, 199, 202, 205, 208, 211, 214,
+ 217, 220, 223, 226, 229, 232, 235, 238, 241, 244, 247, 250,
+ 253, 256, 259, 262, 265, 268, 271, 274, 277, 280, 283, 295,
+ 298, 301, 304, 307, 310, 313, -1,
+};
+
+/* GSM TCH-HR */
+const struct osmo_conv_code gsm_conv_tch_hr = {
+ .N = 3,
+ .K = 7,
+ .len = 98,
+ .next_output = tch_hr_next_output,
+ .next_state = tch_hr_next_state,
+ .puncture = tch_hr_puncture,
+};
+
+/* GSM TCH-AFS12.2 */
+static const uint8_t tch_afs_12_2_next_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 },
+};
+
+static const uint8_t tch_afs_12_2_next_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 },
+};
+
+static const uint8_t tch_afs_12_2_next_term_output[] = {
+ 0, 1, 0, 1, 3, 2, 3, 2, 3, 2, 3, 2, 0, 1, 0, 1,
+};
+
+static const uint8_t tch_afs_12_2_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int 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,
+};
+
+/* GSM TCH-AFS12.2 */
+const struct osmo_conv_code gsm_conv_tch_afs_12_2 = {
+ .N = 2,
+ .K = 5,
+ .len = 250,
+ .next_output = tch_afs_12_2_next_output,
+ .next_state = tch_afs_12_2_next_state,
+ .next_term_output = tch_afs_12_2_next_term_output,
+ .next_term_state = tch_afs_12_2_next_term_state,
+ .puncture = tch_afs_12_2_puncture,
+};
+
+static const uint8_t tch_afs_10_2_next_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 },
+};
+
+static const uint8_t tch_afs_10_2_next_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 },
+};
+
+static const uint8_t tch_afs_10_2_next_term_output[] = {
+ 0, 5, 3, 6, 5, 0, 6, 3, 7, 2, 4, 1, 2, 7, 1, 4,
+};
+
+static const uint8_t tch_afs_10_2_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int 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,
+};
+
+/* GSM TCH-AFS10.2 */
+const struct osmo_conv_code gsm_conv_tch_afs_10_2 = {
+ .N = 3,
+ .K = 5,
+ .len = 210,
+ .next_output = tch_afs_10_2_next_output,
+ .next_state = tch_afs_10_2_next_state,
+ .next_term_output = tch_afs_10_2_next_term_output,
+ .next_term_state = tch_afs_10_2_next_term_state,
+ .puncture = tch_afs_10_2_puncture,
+};
+
+static const uint8_t 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 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 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 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 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,
+};
+
+/* GSM TCH-AFS7.95 */
+const struct osmo_conv_code gsm_conv_tch_afs_7_95 = {
+ .N = 3,
+ .K = 7,
+ .len = 165,
+ .next_output = tch_afs_7_95_next_output,
+ .next_state = tch_afs_7_95_next_state,
+ .next_term_output = tch_afs_7_95_next_term_output,
+ .next_term_state = tch_afs_7_95_next_term_state,
+ .puncture = tch_afs_7_95_puncture,
+};
+
+static const uint8_t tch_afs_7_4_next_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 },
+};
+
+static const uint8_t tch_afs_7_4_next_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 },
+};
+
+static const uint8_t tch_afs_7_4_next_term_output[] = {
+ 0, 5, 3, 6, 5, 0, 6, 3, 7, 2, 4, 1, 2, 7, 1, 4,
+};
+
+static const uint8_t tch_afs_7_4_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int 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,
+};
+
+/* GSM TCH-AFS7.4 */
+const struct osmo_conv_code gsm_conv_tch_afs_7_4 = {
+ .N = 3,
+ .K = 5,
+ .len = 154,
+ .next_output = tch_afs_7_4_next_output,
+ .next_state = tch_afs_7_4_next_state,
+ .next_term_output = tch_afs_7_4_next_term_output,
+ .next_term_state = tch_afs_7_4_next_term_state,
+ .puncture = tch_afs_7_4_puncture,
+};
+
+static const uint8_t tch_afs_6_7_next_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 },
+};
+
+static const uint8_t tch_afs_6_7_next_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 },
+};
+
+static int 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,
+};
+
+static const uint8_t tch_afs_6_7_next_term_output[] = {
+ 0, 11, 7, 12, 11, 0, 12, 7, 15, 4, 8, 3, 4, 15, 3, 8,
+};
+
+static const uint8_t tch_afs_6_7_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+/* GSM TCH-AFS6.7 */
+const struct osmo_conv_code gsm_conv_tch_afs_6_7 = {
+ .N = 4,
+ .K = 5,
+ .len = 140,
+ .next_output = tch_afs_6_7_next_output,
+ .next_state = tch_afs_6_7_next_state,
+ .next_term_output = tch_afs_6_7_next_term_output,
+ .next_term_state = tch_afs_6_7_next_term_state,
+ .puncture = tch_afs_6_7_puncture,
+};
+
+static const uint8_t tch_afs_5_9_next_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 },
+};
+
+static const uint8_t tch_afs_5_9_next_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 },
+};
+
+static const uint8_t tch_afs_5_9_next_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,
+};
+
+static const uint8_t tch_afs_5_9_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 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,
+};
+
+/* GSM TCH-AFS5.9 */
+const struct osmo_conv_code gsm_conv_tch_afs_5_9 = {
+ .N = 4,
+ .K = 7,
+ .len = 124,
+ .next_output = tch_afs_5_9_next_output,
+ .next_state = tch_afs_5_9_next_state,
+ .next_term_output = tch_afs_5_9_next_term_output,
+ .next_term_state = tch_afs_5_9_next_term_state,
+ .puncture = tch_afs_5_9_puncture,
+};
+
+static const uint8_t tch_afs_5_15_next_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 },
+};
+
+static const uint8_t tch_afs_5_15_next_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 },
+};
+
+static const uint8_t tch_afs_5_15_next_term_output[] = {
+ 0, 27, 7, 28, 27, 0, 28, 7, 31, 4, 24, 3, 4, 31, 3, 24,
+};
+
+static const uint8_t tch_afs_5_15_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int 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,
+};
+
+/* GSM TCH-AFS5.15 */
+const struct osmo_conv_code gsm_conv_tch_afs_5_15 = {
+ .N = 5,
+ .K = 5,
+ .len = 109,
+ .next_output = tch_afs_5_15_next_output,
+ .next_state = tch_afs_5_15_next_state,
+ .next_term_output = tch_afs_5_15_next_term_output,
+ .next_term_state = tch_afs_5_15_next_term_state,
+ .puncture = tch_afs_5_15_puncture,
+};
+
+static const uint8_t tch_afs_4_75_next_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 },
+};
+
+static const uint8_t tch_afs_4_75_next_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 },
+};
+
+static const uint8_t tch_afs_4_75_next_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,
+};
+
+static const uint8_t tch_afs_4_75_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 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,
+};
+
+/* GSM TCH-AFS4.75 */
+const struct osmo_conv_code gsm_conv_tch_afs_4_75 = {
+ .N = 5,
+ .K = 7,
+ .len = 101,
+ .next_output = tch_afs_4_75_next_output,
+ .next_state = tch_afs_4_75_next_state,
+ .next_term_output = tch_afs_4_75_next_term_output,
+ .next_term_state = tch_afs_4_75_next_term_state,
+ .puncture = tch_afs_4_75_puncture,
+};
+
+static const uint8_t tch_ahs_7_95_next_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 },
+};
+
+static const uint8_t tch_ahs_7_95_next_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 },
+};
+
+static const uint8_t tch_ahs_7_95_next_term_output[] = {
+ 0, 1, 0, 1, 3, 2, 3, 2, 3, 2, 3, 2, 0, 1, 0, 1,
+};
+
+static const uint8_t tch_ahs_7_95_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int tch_ahs_7_95_puncture[] = {
+ 1, 3, 5, 7, 11, 15, 19, 23, 27, 31, 35, 43,
+ 47, 51, 55, 59, 63, 67, 71, 79, 83, 87, 91, 95,
+ 99, 103, 107, 115, 119, 123, 127, 131, 135, 139, 143, 151,
+ 155, 159, 163, 167, 171, 175, 177, 179, 183, 185, 187, 191,
+ 193, 195, 197, 199, 203, 205, 207, 211, 213, 215, 219, 221,
+ 223, 227, 229, 231, 233, 235, 239, 241, 243, 247, 249, 251,
+ 255, 257, 259, 261, 263, 265,
+ -1,
+};
+
+/* GSM TCH-AHS7.95 */
+const struct osmo_conv_code gsm_conv_tch_ahs_7_95 = {
+ .N = 2,
+ .K = 5,
+ .len = 129,
+ .next_output = tch_ahs_7_95_next_output,
+ .next_state = tch_ahs_7_95_next_state,
+ .next_term_output = tch_ahs_7_95_next_term_output,
+ .next_term_state = tch_ahs_7_95_next_term_state,
+ .puncture = tch_ahs_7_95_puncture,
+};
+
+static const uint8_t tch_ahs_7_4_next_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 },
+};
+
+static const uint8_t tch_ahs_7_4_next_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 },
+};
+
+static const uint8_t tch_ahs_7_4_next_term_output[] = {
+ 0, 1, 0, 1, 3, 2, 3, 2, 3, 2, 3, 2, 0, 1, 0, 1,
+};
+
+static const uint8_t tch_ahs_7_4_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int tch_ahs_7_4_puncture[] = {
+ 1, 3, 7, 11, 19, 23, 27, 35, 39, 43, 51, 55,
+ 59, 67, 71, 75, 83, 87, 91, 99, 103, 107, 115, 119,
+ 123, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171,
+ 175, 179, 183, 187, 191, 195, 199, 203, 207, 211, 215, 219,
+ 221, 223, 227, 229, 231, 235, 237, 239, 243, 245, 247, 251,
+ 253, 255, 257, 259, -1,
+};
+
+/* GSM TCH-AHS7.4 */
+const struct osmo_conv_code gsm_conv_tch_ahs_7_4 = {
+ .N = 2,
+ .K = 5,
+ .len = 126,
+ .next_output = tch_ahs_7_4_next_output,
+ .next_state = tch_ahs_7_4_next_state,
+ .next_term_output = tch_ahs_7_4_next_term_output,
+ .next_term_state = tch_ahs_7_4_next_term_state,
+ .puncture = tch_ahs_7_4_puncture,
+};
+
+static const uint8_t tch_ahs_6_7_next_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 },
+};
+
+static const uint8_t tch_ahs_6_7_next_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 },
+};
+
+static const uint8_t tch_ahs_6_7_next_term_output[] = {
+ 0, 1, 0, 1, 3, 2, 3, 2, 3, 2, 3, 2, 0, 1, 0, 1,
+};
+
+static const uint8_t tch_ahs_6_7_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int tch_ahs_6_7_puncture[] = {
+ 1, 3, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99,
+ 109, 119, 129, 139, 149, 159, 167, 169, 177, 179, 187, 189,
+ 197, 199, 203, 207, 209, 213, 217, 219, 223, 227, 229, 231,
+ 233, 235, 237, 239, -1,
+};
+
+/* GSM TCH-AHS6.7 */
+const struct osmo_conv_code gsm_conv_tch_ahs_6_7 = {
+ .N = 2,
+ .K = 5,
+ .len = 116,
+ .next_output = tch_ahs_6_7_next_output,
+ .next_state = tch_ahs_6_7_next_state,
+ .next_term_output = tch_ahs_6_7_next_term_output,
+ .next_term_state = tch_ahs_6_7_next_term_state,
+ .puncture = tch_ahs_6_7_puncture,
+};
+
+static const uint8_t tch_ahs_5_9_next_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 },
+};
+
+static const uint8_t tch_ahs_5_9_next_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 },
+};
+
+static const uint8_t tch_ahs_5_9_next_term_output[] = {
+ 0, 1, 0, 1, 3, 2, 3, 2, 3, 2, 3, 2, 0, 1, 0, 1,
+};
+
+static const uint8_t tch_ahs_5_9_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int tch_ahs_5_9_puncture[] = {
+ 1, 15, 71, 127, 139, 151, 163, 175, 187, 195, 203, 211,
+ 215, 219, 221, 223, -1,
+};
+
+/* GSM TCH-AHS5.9 */
+const struct osmo_conv_code gsm_conv_tch_ahs_5_9 = {
+ .N = 2,
+ .K = 5,
+ .len = 108,
+ .next_output = tch_ahs_5_9_next_output,
+ .next_state = tch_ahs_5_9_next_state,
+ .next_term_output = tch_ahs_5_9_next_term_output,
+ .next_term_state = tch_ahs_5_9_next_term_state,
+ .puncture = tch_ahs_5_9_puncture,
+};
+
+static const uint8_t tch_ahs_5_15_next_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 },
+};
+
+static const uint8_t tch_ahs_5_15_next_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 },
+};
+
+static const uint8_t tch_ahs_5_15_next_term_output[] = {
+ 0, 5, 3, 6, 5, 0, 6, 3, 7, 2, 4, 1, 2, 7, 1, 4,
+};
+
+static const uint8_t tch_ahs_5_15_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static int tch_ahs_5_15_puncture[] = {
+ 0, 1, 3, 4, 6, 9, 12, 15, 18, 21, 27, 33,
+ 39, 45, 51, 54, 57, 63, 69, 75, 81, 87, 90, 93,
+ 99, 105, 111, 117, 123, 126, 129, 135, 141, 147, 153, 159,
+ 162, 165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195,
+ 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231,
+ 234, 237, 240, 243, 244, 246, 249, 252, 255, 256, 258, 261,
+ 264, 267, 268, 270, 273, 276, 279, 280, 282, 285, 288, 289,
+ 291, 294, 295, 297, 298, 300, 301, -1,
+};
+
+/* GSM TCH-AHS5.15 */
+const struct osmo_conv_code gsm_conv_tch_ahs_5_15 = {
+ .N = 3,
+ .K = 5,
+ .len = 97,
+ .next_output = tch_ahs_5_15_next_output,
+ .next_state = tch_ahs_5_15_next_state,
+ .next_term_output = tch_ahs_5_15_next_term_output,
+ .next_term_state = tch_ahs_5_15_next_term_state,
+ .puncture = tch_ahs_5_15_puncture,
+};
+
+static const uint8_t tch_ahs_4_75_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 tch_ahs_4_75_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 tch_ahs_4_75_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 tch_ahs_4_75_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 tch_ahs_4_75_puncture[] = {
+ 1, 2, 4, 5, 7, 8, 10, 13, 16, 22, 28, 34,
+ 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 100, 106,
+ 112, 118, 124, 130, 136, 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, 241, 244, 247, 250, 253, 256,
+ 259, 262, 265, 268, 271, 274, 275, 277, 278, 280, 281, 283,
+ 284, -1,
+};
+
+/* GSM TCH-AHS4.75 */
+const struct osmo_conv_code gsm_conv_tch_ahs_4_75 = {
+ .N = 3,
+ .K = 7,
+ .len = 89,
+ .next_output = tch_ahs_4_75_next_output,
+ .next_state = tch_ahs_4_75_next_state,
+ .next_term_output = tch_ahs_4_75_next_term_output,
+ .next_term_state = tch_ahs_4_75_next_term_state,
+ .puncture = tch_ahs_4_75_puncture,
+};
+
+static const uint8_t wimax_fch_next_output[][2] = {
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
+ { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+ { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
+ { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
+};
+
+static const uint8_t wimax_fch_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+};
+
+/* WiMax FCH */
+const struct osmo_conv_code wimax_conv_fch = {
+ .N = 2,
+ .K = 7,
+ .len = 48,
+ .term = CONV_TERM_TAIL_BITING,
+ .next_output = wimax_fch_next_output,
+ .next_state = wimax_fch_next_state,
+};
+
+static const uint8_t gmr1_tch3_speech_next_output[][2] = {
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
+ { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+ { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
+ { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
+};
+
+static const uint8_t gmr1_tch3_speech_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+};
+
+static const int gmr1_tch3_speech_puncture[] = {
+ 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47,
+ 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95,
+ -1,
+};
+
+/* GMR-1 TCH3 */
+const struct osmo_conv_code gmr1_conv_tch3_speech = {
+ .N = 2,
+ .K = 7,
+ .len = 48,
+ .term = CONV_TERM_TAIL_BITING,
+ .next_output = gmr1_tch3_speech_next_output,
+ .next_state = gmr1_tch3_speech_next_state,
+ .puncture = gmr1_tch3_speech_puncture,
+};
+
+static const uint8_t lte_pbch_next_output[][2] = {
+ { 0, 7 }, { 3, 4 }, { 7, 0 }, { 4 , 3 },
+ { 6, 1 }, { 5, 2 }, { 1, 6 }, { 2 , 5 },
+ { 1, 6 }, { 2, 5 }, { 6, 1 }, { 5 , 2 },
+ { 7, 0 }, { 4, 3 }, { 0, 7 }, { 3 , 4 },
+ { 4, 3 }, { 7, 0 }, { 3, 4 }, { 0 , 7 },
+ { 2, 5 }, { 1, 6 }, { 5, 2 }, { 6 , 1 },
+ { 5, 2 }, { 6, 1 }, { 2, 5 }, { 1 , 6 },
+ { 3, 4 }, { 0, 7 }, { 4, 3 }, { 7 , 0 },
+ { 7, 0 }, { 4, 3 }, { 0, 7 }, { 3 , 4 },
+ { 1, 6 }, { 2, 5 }, { 6, 1 }, { 5 , 2 },
+ { 6, 1 }, { 5, 2 }, { 1, 6 }, { 2 , 5 },
+ { 0, 7 }, { 3, 4 }, { 7, 0 }, { 4 , 3 },
+ { 3, 4 }, { 0, 7 }, { 4, 3 }, { 7 , 0 },
+ { 5, 2 }, { 6, 1 }, { 2, 5 }, { 1 , 6 },
+ { 2, 5 }, { 1, 6 }, { 5, 2 }, { 6 , 1 },
+ { 4, 3 }, { 7, 0 }, { 3, 4 }, { 0 , 7 },
+};
+
+static const uint8_t lte_pbch_next_state[][2] = {
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+ { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
+ { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
+ { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
+ { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
+ { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
+ { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
+ { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
+ { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
+};
+
+/* LTE PBCH */
+const struct osmo_conv_code lte_conv_pbch = {
+ .N = 3,
+ .K = 7,
+ .len = 40,
+ .term = CONV_TERM_TAIL_BITING,
+ .next_output = lte_pbch_next_output,
+ .next_state = lte_pbch_next_state,
+};
+
+/* Truncated code */
+const struct osmo_conv_code conv_trunc = {
+ .N = 2,
+ .K = 5,
+ .len = 224,
+ .term = CONV_TERM_TRUNCATION,
+ .next_output = xcch_next_output,
+ .next_state = xcch_next_state,
+};
diff --git a/tests/conv/codes.h b/tests/conv/codes.h
new file mode 100644
index 0000000..e7c06cb
--- /dev/null
+++ b/tests/conv/codes.h
@@ -0,0 +1,30 @@
+#ifndef TEST_CODES_H
+#define TEST_CODES_H
+
+const struct osmo_conv_code gsm_conv_xcch;
+const struct osmo_conv_code gsm_conv_cs2;
+const struct osmo_conv_code gsm_conv_cs3;
+const struct osmo_conv_code gsm_conv_rach;
+const struct osmo_conv_code gsm_conv_sch;
+const struct osmo_conv_code gsm_conv_tch_fr;
+const struct osmo_conv_code gsm_conv_tch_hr;
+const struct osmo_conv_code gsm_conv_tch_afs_12_2;
+const struct osmo_conv_code gsm_conv_tch_afs_10_2;
+const struct osmo_conv_code gsm_conv_tch_afs_7_95;
+const struct osmo_conv_code gsm_conv_tch_afs_7_4;
+const struct osmo_conv_code gsm_conv_tch_afs_6_7;
+const struct osmo_conv_code gsm_conv_tch_afs_5_9;
+const struct osmo_conv_code gsm_conv_tch_afs_5_15;
+const struct osmo_conv_code gsm_conv_tch_afs_4_75;
+const struct osmo_conv_code gsm_conv_tch_ahs_7_95;
+const struct osmo_conv_code gsm_conv_tch_ahs_7_4;
+const struct osmo_conv_code gsm_conv_tch_ahs_6_7;
+const struct osmo_conv_code gsm_conv_tch_ahs_5_9;
+const struct osmo_conv_code gsm_conv_tch_ahs_5_15;
+const struct osmo_conv_code gsm_conv_tch_ahs_4_75;
+const struct osmo_conv_code wimax_conv_fch;
+const struct osmo_conv_code gmr1_conv_tch3_speech;
+const struct osmo_conv_code lte_conv_pbch;
+const struct osmo_conv_code conv_trunc;
+
+#endif /* TEST_CODES_H */
diff --git a/tests/conv/conv_test.c b/tests/conv/conv_test.c
index d9440f9..89ffdb8 100644
--- a/tests/conv/conv_test.c
+++ b/tests/conv/conv_test.c
@@ -7,230 +7,10 @@
#include <osmocom/core/conv.h>
#include <osmocom/core/utils.h>
-#define MAX_LEN_BITS 512
-#define MAX_LEN_BYTES (512/8)
-
-
-/* ------------------------------------------------------------------------ */
-/* 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 },
- { 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 },
- { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
- { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
- { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
- { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
- { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
- { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
- { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
- { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
- { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
- { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 },
- { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 },
- { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
- { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
- { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 },
- { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 },
-};
-
-static const uint8_t conv_gmr1_tch3_speech_next_state[][2] = {
- { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
- { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
- { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
- { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
- { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
- { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
- { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
- { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
- { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
- { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
- { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
- { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
- { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
- { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
- { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
- { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
-};
-
-static const int conv_gmr1_tch3_speech_puncture[] = {
- 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47,
- 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95,
- -1, /* end */
-};
-
-static const struct osmo_conv_code conv_gmr1_tch3_speech = {
- .N = 2,
- .K = 7,
- .len = 48,
- .term = CONV_TERM_TAIL_BITING,
- .next_output = conv_gmr1_tch3_speech_next_output,
- .next_state = conv_gmr1_tch3_speech_next_state,
- .puncture = conv_gmr1_tch3_speech_puncture,
-};
-
-
-/* WiMax FCH -> Non recursive code, tail-biting, non-punctured */
-static const uint8_t conv_wimax_fch_next_output[][2] = {
- { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
- { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
- { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
- { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
- { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
- { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
- { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
- { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
- { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
- { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
- { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 },
- { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 },
- { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
- { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
- { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 },
- { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 },
-};
-
-static const uint8_t conv_wimax_fch_next_state[][2] = {
- { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
- { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
- { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
- { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
- { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
- { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
- { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
- { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
- { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 },
- { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 },
- { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 },
- { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 },
- { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 },
- { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 },
- { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 },
- { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 },
-};
-
-static const struct osmo_conv_code conv_wimax_fch = {
- .N = 2,
- .K = 7,
- .len = 48,
- .term = CONV_TERM_TAIL_BITING,
- .next_output = conv_wimax_fch_next_output,
- .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,
-};
+#include "codes.h"
+#define MAX_LEN_BITS 1024
+#define MAX_LEN_BYTES (1024/8)
/* ------------------------------------------------------------------------ */
/* Test vectors */
@@ -249,7 +29,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 = &gsm_conv_xcch,
.in_len = 224,
.out_len = 456,
.has_vec = 1,
@@ -267,8 +47,62 @@ static const struct conv_test_vector tests[] = {
0x8f },
},
{
+ .name = "GPRS CS2 (non-recursive, flushed, not punctured)",
+ .code = &gsm_conv_cs2,
+ .in_len = 290,
+ .out_len = 588,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GPRS CS3 (non-recursive, flushed, not punctured)",
+ .code = &gsm_conv_cs3,
+ .in_len = 334,
+ .out_len = 676,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM RACH (non-recursive, flushed, not punctured)",
+ .code = &gsm_conv_rach,
+ .in_len = 14,
+ .out_len = 36,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/FR (non-recursive, flushed, not punctured)",
+ .code = &gsm_conv_tch_fr,
+ .in_len = 185,
+ .out_len = 378,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AFS 12.2 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_afs_12_2,
+ .in_len = 250,
+ .out_len = 448,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AFS 10.2 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_afs_10_2,
+ .in_len = 210,
+ .out_len = 448,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
.name = "GSM TCH/AFS 7.95 (recursive, flushed, punctured)",
- .code = &conv_gsm_tch_afs_7_95,
+ .code = &gsm_conv_tch_afs_7_95,
.in_len = 165,
.out_len = 448,
.has_vec = 1,
@@ -284,8 +118,89 @@ static const struct conv_test_vector tests[] = {
0xa1, 0x5f, 0x45, 0x4a, 0xfb, 0xe6, 0x5a, 0x9c },
},
{
+ .name = "GSM TCH/AFS 7.4 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_afs_7_4,
+ .in_len = 154,
+ .out_len = 448,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AFS 6.7 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_afs_6_7,
+ .in_len = 140,
+ .out_len = 448,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AFS 5.9 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_afs_5_9,
+ .in_len = 124,
+ .out_len = 448,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AHS 7.95 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_ahs_7_95,
+ .in_len = 129,
+ .out_len = 188,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AHS 7.4 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_ahs_7_4,
+ .in_len = 126,
+ .out_len = 196,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AHS 6.7 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_ahs_6_7,
+ .in_len = 116,
+ .out_len = 200,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AHS 5.9 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_ahs_5_9,
+ .in_len = 108,
+ .out_len = 208,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AHS 5.15 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_ahs_5_15,
+ .in_len = 97,
+ .out_len = 212,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
+ .name = "GSM TCH/AHS 4.75 (recursive, flushed, punctured)",
+ .code = &gsm_conv_tch_ahs_4_75,
+ .in_len = 89,
+ .out_len = 212,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
.name = "GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)",
- .code = &conv_gmr1_tch3_speech,
+ .code = &gmr1_conv_tch3_speech,
.in_len = 48,
.out_len = 72,
.has_vec = 1,
@@ -294,7 +209,7 @@ static const struct conv_test_vector tests[] = {
},
{
.name = "WiMax FCH (non-recursive, tail-biting, not punctured)",
- .code = &conv_wimax_fch,
+ .code = &wimax_conv_fch,
.in_len = 48,
.out_len = 96,
.has_vec = 1,
@@ -303,6 +218,15 @@ static const struct conv_test_vector tests[] = {
0x8a, 0xed, 0x21, 0xed },
},
{
+ .name = "LTE PBCH (non-recursive, tail-biting, non-punctured)",
+ .code = <e_conv_pbch,
+ .in_len = 40,
+ .out_len = 120,
+ .has_vec = 0,
+ .vec_in = { },
+ .vec_out = { },
+ },
+ {
.name = "??? (non-recursive, direct truncation, not punctured)",
.code = &conv_trunc,
.in_len = 224,
diff --git a/tests/conv/conv_test.ok b/tests/conv/conv_test.ok
index 2122961..95ea671 100644
--- a/tests/conv/conv_test.ok
+++ b/tests/conv/conv_test.ok
@@ -9,6 +9,54 @@
[..] Encoding / Decoding cycle : OK
[..] Encoding / Decoding cycle : OK
+[+] Testing: GPRS CS2 (non-recursive, flushed, not punctured)
+[.] Input length : ret = 290 exp = 290 -> OK
+[.] Output length : ret = 588 exp = 588 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GPRS CS3 (non-recursive, flushed, not punctured)
+[.] Input length : ret = 334 exp = 334 -> OK
+[.] Output length : ret = 676 exp = 676 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM RACH (non-recursive, flushed, not punctured)
+[.] Input length : ret = 14 exp = 14 -> OK
+[.] Output length : ret = 36 exp = 36 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/FR (non-recursive, flushed, not punctured)
+[.] Input length : ret = 185 exp = 185 -> OK
+[.] Output length : ret = 378 exp = 378 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AFS 12.2 (recursive, flushed, punctured)
+[.] Input length : ret = 250 exp = 250 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AFS 10.2 (recursive, flushed, punctured)
+[.] Input length : ret = 210 exp = 210 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
[+] Testing: GSM TCH/AFS 7.95 (recursive, flushed, punctured)
[.] Input length : ret = 165 exp = 165 -> OK
[.] Output length : ret = 448 exp = 448 -> OK
@@ -20,6 +68,78 @@
[..] Encoding / Decoding cycle : OK
[..] Encoding / Decoding cycle : OK
+[+] Testing: GSM TCH/AFS 7.4 (recursive, flushed, punctured)
+[.] Input length : ret = 154 exp = 154 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AFS 6.7 (recursive, flushed, punctured)
+[.] Input length : ret = 140 exp = 140 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AFS 5.9 (recursive, flushed, punctured)
+[.] Input length : ret = 124 exp = 124 -> OK
+[.] Output length : ret = 448 exp = 448 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AHS 7.95 (recursive, flushed, punctured)
+[.] Input length : ret = 129 exp = 129 -> OK
+[.] Output length : ret = 188 exp = 188 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AHS 7.4 (recursive, flushed, punctured)
+[.] Input length : ret = 126 exp = 126 -> OK
+[.] Output length : ret = 196 exp = 196 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AHS 6.7 (recursive, flushed, punctured)
+[.] Input length : ret = 116 exp = 116 -> OK
+[.] Output length : ret = 200 exp = 200 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AHS 5.9 (recursive, flushed, punctured)
+[.] Input length : ret = 108 exp = 108 -> OK
+[.] Output length : ret = 208 exp = 208 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AHS 5.15 (recursive, flushed, punctured)
+[.] Input length : ret = 97 exp = 97 -> OK
+[.] Output length : ret = 212 exp = 212 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
+[+] Testing: GSM TCH/AHS 4.75 (recursive, flushed, punctured)
+[.] Input length : ret = 89 exp = 89 -> OK
+[.] Output length : ret = 212 exp = 212 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
[+] Testing: GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)
[.] Input length : ret = 48 exp = 48 -> OK
[.] Output length : ret = 72 exp = 72 -> OK
@@ -42,6 +162,14 @@
[..] Encoding / Decoding cycle : OK
[..] Encoding / Decoding cycle : OK
+[+] Testing: LTE PBCH (non-recursive, tail-biting, non-punctured)
+[.] Input length : ret = 40 exp = 40 -> OK
+[.] Output length : ret = 120 exp = 120 -> OK
+[.] Random vector checks:
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+[..] Encoding / Decoding cycle : OK
+
[+] Testing: ??? (non-recursive, direct truncation, not punctured)
[.] Input length : ret = 224 exp = 224 -> OK
[.] Output length : ret = 448 exp = 448 -> OK
--
1.9.0
1
0
Detect x86 SSE availability for architecture specific convolutional
decoding. Use the GNU autoconf macro AX_EXT to provide built time
detection and set the following definitions.
http://www.gnu.org/software/autoconf-archive/ax_ext.html
HAVE_SSE3
HAVE_SSE4_1
AX_EXT is generally packaged with autoconf-archive and requires the
following macro files.
ax_check_compile_flag.m4
ax_ext.m4
ax_gcc_x86_avx_xgetbv.m4
ax_gcc_x86_cpuid.m4
Set -march=native for automatic compile flag setting. Combined, this
allows automatic detection on x86 and pass-through support for non-x86
platforms (e.g. ARM).
Signed-off-by: Thomas Tsou <tom(a)tsou.cc>
---
configure.ac | 1 +
src/Makefile.am | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index eaaab50..4b0c572 100644
--- a/configure.ac
+++ b/configure.ac
@@ -179,6 +179,7 @@ then
AC_DEFINE([PANIC_INFLOOP],[1],[Use infinite loop on panic rather than fprintf/abort])
fi
+AX_EXT
AC_OUTPUT(
libosmocore.pc
diff --git a/src/Makefile.am b/src/Makefile.am
index 0ecf4b0..c0b78a8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,7 @@
# Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification
LIBVERSION=4:0:0
-AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include
+AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/include -march=native
lib_LTLIBRARIES = libosmocore.la
--
1.9.0
1
0
29 Apr '14
Fast convolutional decoding is provided through x86 intrinsic based
SSE operations. SSE3, found on virtually all modern x86 processors,
is the minimal requirement with SSE4.1 used for path metric
normalization if available.
This feature is enabled with the compile flags HAVE_SSE3 and
HAVE_SSE4_1.
Signed-off-by: Thomas Tsou <tom(a)tsou.cc>
---
src/Makefile.am | 2 +-
src/viterbi_gen.c | 4 +
src/viterbi_sse.c | 581 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 586 insertions(+), 1 deletion(-)
create mode 100644 src/viterbi_sse.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 262a4e6..0ecf4b0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,7 @@ libosmocore_la_SOURCES = timer.c select.c signal.c msgb.c bits.c \
gsmtap_util.c crc16.c panic.c backtrace.c \
conv.c application.c rbtree.c strrb.c \
loggingrb.c crc8gen.c crc16gen.c crc32gen.c crc64gen.c \
- viterbi.c viterbi_gen.c
+ viterbi.c viterbi_gen.c viterbi_sse.c
BUILT_SOURCES = crc8gen.c crc16gen.c crc32gen.c crc64gen.c
diff --git a/src/viterbi_gen.c b/src/viterbi_gen.c
index 894d5ae..e3585ec 100644
--- a/src/viterbi_gen.c
+++ b/src/viterbi_gen.c
@@ -17,6 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "config.h"
+
+#ifndef HAVE_SSE3
#include <stdint.h>
#include <string.h>
@@ -180,3 +183,4 @@ void gen_metrics_k7_n4(const int8_t *seq, const int16_t *out,
_gen_branch_metrics_n4(64, seq, out, metrics);
_gen_path_metrics(64, sums, metrics, paths, norm);
}
+#endif /* !HAVE_SSE3 */
diff --git a/src/viterbi_sse.c b/src/viterbi_sse.c
new file mode 100644
index 0000000..2372994
--- /dev/null
+++ b/src/viterbi_sse.c
@@ -0,0 +1,581 @@
+/*
+ * Intel SSE Viterbi decoder
+ * Copyright (C) 2013, 2014 Thomas Tsou <tom(a)tsou.cc>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#ifdef HAVE_SSE3
+#include <stdint.h>
+#include <emmintrin.h>
+#include <tmmintrin.h>
+
+#if defined(HAVE_SSE4_1) || defined(HAVE_SSE41)
+#include <smmintrin.h>
+#endif
+
+#ifdef HAVE_AVX2
+#include <immintrin.h>
+#endif
+
+/* Octo-Viterbi butterfly:
+ * Compute 8-wide butterfly generating 16 path decisions and 16 accumulated
+ * sums. Inputs all packed 16-bit integers in three 128-bit XMM registers.
+ * Two intermediate registers are used and results are set in the upper 4
+ * registers.
+ *
+ * Input:
+ * M0 - Path metrics 0 (packed 16-bit integers)
+ * M1 - Path metrics 1 (packed 16-bit integers)
+ * M2 - Branch metrics (packed 16-bit integers)
+ *
+ * Output:
+ * M2 - Selected and accumulated path metrics 0
+ * M4 - Selected and accumulated path metrics 1
+ * M3 - Path selections 0
+ * M1 - Path selections 1
+ */
+#define SSE_BUTTERFLY(M0,M1,M2,M3,M4) \
+{ \
+ M3 = _mm_adds_epi16(M0, M2); \
+ M4 = _mm_subs_epi16(M1, M2); \
+ M0 = _mm_subs_epi16(M0, M2); \
+ M1 = _mm_adds_epi16(M1, M2); \
+ M2 = _mm_max_epi16(M3, M4); \
+ M3 = _mm_cmpgt_epi16(M3, M4); \
+ M4 = _mm_max_epi16(M0, M1); \
+ M1 = _mm_cmpgt_epi16(M0, M1); \
+}
+
+/* Two lane deinterleaving K = 5:
+ * Take 16 interleaved 16-bit integers and deinterleave to 2 packed 128-bit
+ * registers. The operation summarized below. Four registers are used with
+ * the lower 2 as input and upper 2 as output.
+ *
+ * In - 10101010 10101010 10101010 10101010
+ * Out - 00000000 11111111 00000000 11111111
+ *
+ * Input:
+ * M0:1 - Packed 16-bit integers
+ *
+ * Output:
+ * M2:3 - Deinterleaved packed 16-bit integers
+ */
+#define _I8_SHUFFLE_MASK 15, 14, 11, 10, 7, 6, 3, 2, 13, 12, 9, 8, 5, 4, 1, 0
+
+#define SSE_DEINTERLEAVE_K5(M0,M1,M2,M3) \
+{ \
+ M2 = _mm_set_epi8(_I8_SHUFFLE_MASK); \
+ M0 = _mm_shuffle_epi8(M0, M2); \
+ M1 = _mm_shuffle_epi8(M1, M2); \
+ M2 = _mm_unpacklo_epi64(M0, M1); \
+ M3 = _mm_unpackhi_epi64(M0, M1); \
+}
+
+/* Two lane deinterleaving K = 7:
+ * Take 64 interleaved 16-bit integers and deinterleave to 8 packed 128-bit
+ * registers. The operation summarized below. 16 registers are used with the
+ * lower 8 as input and upper 8 as output.
+ *
+ * In - 10101010 10101010 10101010 10101010 ...
+ * Out - 00000000 11111111 00000000 11111111 ...
+ *
+ * Input:
+ * M0:7 - Packed 16-bit integers
+ *
+ * Output:
+ * M8:15 - Deinterleaved packed 16-bit integers
+ */
+#define SSE_DEINTERLEAVE_K7(M0,M1,M2,M3,M4,M5,M6,M7, \
+ M8,M9,M10,M11,M12,M13,M14,M15) \
+{ \
+ M8 = _mm_set_epi8(_I8_SHUFFLE_MASK); \
+ M0 = _mm_shuffle_epi8(M0, M8); \
+ M1 = _mm_shuffle_epi8(M1, M8); \
+ M2 = _mm_shuffle_epi8(M2, M8); \
+ M3 = _mm_shuffle_epi8(M3, M8); \
+ M4 = _mm_shuffle_epi8(M4, M8); \
+ M5 = _mm_shuffle_epi8(M5, M8); \
+ M6 = _mm_shuffle_epi8(M6, M8); \
+ M7 = _mm_shuffle_epi8(M7, M8); \
+ M8 = _mm_unpacklo_epi64(M0, M1); \
+ M9 = _mm_unpackhi_epi64(M0, M1); \
+ M10 = _mm_unpacklo_epi64(M2, M3); \
+ M11 = _mm_unpackhi_epi64(M2, M3); \
+ M12 = _mm_unpacklo_epi64(M4, M5); \
+ M13 = _mm_unpackhi_epi64(M4, M5); \
+ M14 = _mm_unpacklo_epi64(M6, M7); \
+ M15 = _mm_unpackhi_epi64(M6, M7); \
+}
+
+/* Generate branch metrics N = 2:
+ * Compute 16 branch metrics from trellis outputs and input values.
+ *
+ * Input:
+ * M0:3 - 16 x 2 packed 16-bit trellis outputs
+ * M4 - Expanded and packed 16-bit input value
+ *
+ * Output:
+ * M6:7 - 16 computed 16-bit branch metrics
+ */
+#define SSE_BRANCH_METRIC_N2(M0,M1,M2,M3,M4,M6,M7) \
+{ \
+ M0 = _mm_sign_epi16(M4, M0); \
+ M1 = _mm_sign_epi16(M4, M1); \
+ M2 = _mm_sign_epi16(M4, M2); \
+ M3 = _mm_sign_epi16(M4, M3); \
+ M6 = _mm_hadds_epi16(M0, M1); \
+ M7 = _mm_hadds_epi16(M2, M3); \
+}
+
+/* Generate branch metrics N = 4:
+ * Compute 8 branch metrics from trellis outputs and input values. This
+ * macro is reused for N less than 4 where the extra soft input bits are
+ * padded.
+ *
+ * Input:
+ * M0:3 - 8 x 4 packed 16-bit trellis outputs
+ * M4 - Expanded and packed 16-bit input value
+ *
+ * Output:
+ * M5 - 8 computed 16-bit branch metrics
+ */
+#define SSE_BRANCH_METRIC_N4(M0,M1,M2,M3,M4,M5) \
+{ \
+ M0 = _mm_sign_epi16(M4, M0); \
+ M1 = _mm_sign_epi16(M4, M1); \
+ M2 = _mm_sign_epi16(M4, M2); \
+ M3 = _mm_sign_epi16(M4, M3); \
+ M0 = _mm_hadds_epi16(M0, M1); \
+ M1 = _mm_hadds_epi16(M2, M3); \
+ M5 = _mm_hadds_epi16(M0, M1); \
+}
+
+/* Broadcast 16-bit integer
+ * Repeat the low 16-bit integer to all elements of the 128-bit SSE
+ * register. Only AVX2 has a dedicated broadcast instruction; use repeat
+ * unpacks for SSE only architectures. This is a destructive operation and
+ * the source register is overwritten.
+ *
+ * Input:
+ * M0 - Low 16-bit element is read
+ *
+ * Output:
+ * M0 - Contains broadcasted values
+ */
+#ifdef HAVE_AVX2
+#define SSE_BROADCAST(M0) \
+{ \
+ M0 = _mm_broadcastw_epi16(M0); \
+}
+#else
+#define SSE_BROADCAST(M0) \
+{ \
+ M0 = _mm_unpacklo_epi16(M0, M0); \
+ M0 = _mm_unpacklo_epi32(M0, M0); \
+ M0 = _mm_unpacklo_epi64(M0, M0); \
+}
+#endif
+
+/* Horizontal minimum
+ * Compute horizontal minimum of packed unsigned 16-bit integers and place
+ * result in the low 16-bit element of the source register. Only SSE 4.1
+ * has a dedicated minpos instruction. One internmediate register is used
+ * if SSE 4.1 is not available. This is a destructive operation and the
+ * source register is overwritten.
+ *
+ * Input:
+ * M0 - Packed unsigned 16-bit integers
+ *
+ * Output:
+ * M0 - Minimum value placed in low 16-bit element
+ */
+#if defined(HAVE_SSE4_1) || defined(HAVE_SSE41)
+#define SSE_MINPOS(M0,M1) \
+{ \
+ M0 = _mm_minpos_epu16(M0); \
+}
+#else
+#define SSE_MINPOS(M0,M1) \
+{ \
+ M1 = _mm_shuffle_epi32(M0, _MM_SHUFFLE(0, 0, 3, 2)); \
+ M0 = _mm_min_epi16(M0, M1); \
+ M1 = _mm_shufflelo_epi16(M0, _MM_SHUFFLE(0, 0, 3, 2)); \
+ M0 = _mm_min_epi16(M0, M1); \
+ M1 = _mm_shufflelo_epi16(M0, _MM_SHUFFLE(0, 0, 0, 1)); \
+ M0 = _mm_min_epi16(M0, M1); \
+}
+#endif
+
+/* Normalize state metrics K = 5:
+ * Compute 16-wide normalization by subtracting the smallest value from
+ * all values. Inputs are 16 packed 16-bit integers across 2 XMM registers.
+ * Two intermediate registers are used and normalized results are placed
+ * in the originating locations.
+ *
+ * Input:
+ * M0:1 - Path metrics 0:1 (packed 16-bit integers)
+ *
+ * Output:
+ * M0:1 - Normalized path metrics 0:1
+ */
+#define SSE_NORMALIZE_K5(M0,M1,M2,M3) \
+{ \
+ M2 = _mm_min_epi16(M0, M1); \
+ SSE_MINPOS(M2, M3) \
+ SSE_BROADCAST(M2) \
+ M0 = _mm_subs_epi16(M0, M2); \
+ M1 = _mm_subs_epi16(M1, M2); \
+}
+
+/* Normalize state metrics K = 7:
+ * Compute 64-wide normalization by subtracting the smallest value from
+ * all values. Inputs are 8 registers of accumulated sums and 4 temporary
+ * registers. Normalized results are returned in the originating locations.
+ *
+ * Input:
+ * M0:7 - Path metricss 0:7 (packed 16-bit integers)
+ *
+ * Output:
+ * M0:7 - Normalized path metrics 0:7
+ */
+#define SSE_NORMALIZE_K7(M0,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11) \
+{ \
+ M8 = _mm_min_epi16(M0, M1); \
+ M9 = _mm_min_epi16(M2, M3); \
+ M10 = _mm_min_epi16(M4, M5); \
+ M11 = _mm_min_epi16(M6, M7); \
+ M8 = _mm_min_epi16(M8, M9); \
+ M10 = _mm_min_epi16(M10, M11); \
+ M8 = _mm_min_epi16(M8, M10); \
+ SSE_MINPOS(M8, M9) \
+ SSE_BROADCAST(M8) \
+ M0 = _mm_subs_epi16(M0, M8); \
+ M1 = _mm_subs_epi16(M1, M8); \
+ M2 = _mm_subs_epi16(M2, M8); \
+ M3 = _mm_subs_epi16(M3, M8); \
+ M4 = _mm_subs_epi16(M4, M8); \
+ M5 = _mm_subs_epi16(M5, M8); \
+ M6 = _mm_subs_epi16(M6, M8); \
+ M7 = _mm_subs_epi16(M7, M8); \
+}
+
+/* Combined BMU/PMU (K=5, N=2)
+ * Compute branch metrics followed by path metrics for half rate 16-state
+ * trellis. 8 butterflies are computed. Accumulated path sums are not
+ * preserved and read and written into the same memory location. Normalize
+ * sums if requires.
+ */
+__always_inline void _sse_metrics_k5_n2(const int16_t *val,
+ const int16_t *out,
+ int16_t *sums,
+ int16_t *paths,
+ int norm)
+{
+ __m128i m0, m1, m2, m3, m4, m5, m6;
+
+ /* (BMU) Load input sequence */
+ m2 = _mm_castpd_si128(_mm_loaddup_pd((double const *) val));
+
+ /* (BMU) Load trellis outputs */
+ m0 = _mm_load_si128((__m128i *) &out[0]);
+ m1 = _mm_load_si128((__m128i *) &out[8]);
+
+ /* (BMU) Compute branch metrics */
+ m0 = _mm_sign_epi16(m2, m0);
+ m1 = _mm_sign_epi16(m2, m1);
+ m2 = _mm_hadds_epi16(m0, m1);
+
+ /* (PMU) Load accumulated path matrics */
+ m0 = _mm_load_si128((__m128i *) &sums[0]);
+ m1 = _mm_load_si128((__m128i *) &sums[8]);
+
+ SSE_DEINTERLEAVE_K5(m0, m1, m3, m4)
+
+ /* (PMU) Butterflies: 0-7 */
+ SSE_BUTTERFLY(m3, m4, m2, m5, m6)
+
+ if (norm)
+ SSE_NORMALIZE_K5(m2, m6, m0, m1)
+
+ _mm_store_si128((__m128i *) &sums[0], m2);
+ _mm_store_si128((__m128i *) &sums[8], m6);
+ _mm_store_si128((__m128i *) &paths[0], m5);
+ _mm_store_si128((__m128i *) &paths[8], m4);
+}
+
+/* Combined BMU/PMU (K=5, N=3 and N=4)
+ * Compute branch metrics followed by path metrics for 16-state and rates
+ * to 1/4. 8 butterflies are computed. The input sequence is read four 16-bit
+ * values at a time, and extra values should be set to zero for rates other
+ * than 1/4. Normally only rates 1/3 and 1/4 are used as there is a
+ * dedicated implementation of rate 1/2.
+ */
+__always_inline void _sse_metrics_k5_n4(const int16_t *val,
+ const int16_t *out,
+ int16_t *sums,
+ int16_t *paths,
+ int norm)
+{
+ __m128i m0, m1, m2, m3, m4, m5, m6;
+
+ /* (BMU) Load input sequence */
+ m4 = _mm_castpd_si128(_mm_loaddup_pd((double const *) val));
+
+ /* (BMU) Load trellis outputs */
+ m0 = _mm_load_si128((__m128i *) &out[0]);
+ m1 = _mm_load_si128((__m128i *) &out[8]);
+ m2 = _mm_load_si128((__m128i *) &out[16]);
+ m3 = _mm_load_si128((__m128i *) &out[24]);
+
+ SSE_BRANCH_METRIC_N4(m0, m1, m2, m3, m4, m2)
+
+ /* (PMU) Load accumulated path matrics */
+ m0 = _mm_load_si128((__m128i *) &sums[0]);
+ m1 = _mm_load_si128((__m128i *) &sums[8]);
+
+ SSE_DEINTERLEAVE_K5(m0, m1, m3, m4)
+
+ /* (PMU) Butterflies: 0-7 */
+ SSE_BUTTERFLY(m3, m4, m2, m5, m6)
+
+ if (norm)
+ SSE_NORMALIZE_K5(m2, m6, m0, m1)
+
+ _mm_store_si128((__m128i *) &sums[0], m2);
+ _mm_store_si128((__m128i *) &sums[8], m6);
+ _mm_store_si128((__m128i *) &paths[0], m5);
+ _mm_store_si128((__m128i *) &paths[8], m4);
+}
+
+/* Combined BMU/PMU (K=7, N=2)
+ * Compute branch metrics followed by path metrics for half rate 64-state
+ * trellis. 32 butterfly operations are computed. Deinterleaving path
+ * metrics requires usage of the full SSE register file, so separate sums
+ * before computing branch metrics to avoid register spilling.
+ */
+__always_inline void _sse_metrics_k7_n2(const int16_t *val,
+ const const int16_t *out,
+ int16_t *sums,
+ int16_t *paths,
+ int norm)
+{
+ __m128i m0, m1, m2, m3, m4, m5, m6, m7, m8,
+ m9, m10, m11, m12, m13, m14, m15;
+
+ /* (PMU) Load accumulated path matrics */
+ m0 = _mm_load_si128((__m128i *) &sums[0]);
+ m1 = _mm_load_si128((__m128i *) &sums[8]);
+ m2 = _mm_load_si128((__m128i *) &sums[16]);
+ m3 = _mm_load_si128((__m128i *) &sums[24]);
+ m4 = _mm_load_si128((__m128i *) &sums[32]);
+ m5 = _mm_load_si128((__m128i *) &sums[40]);
+ m6 = _mm_load_si128((__m128i *) &sums[48]);
+ m7 = _mm_load_si128((__m128i *) &sums[56]);
+
+ /* (PMU) Deinterleave to even-odd registers */
+ SSE_DEINTERLEAVE_K7(m0, m1, m2, m3 ,m4 ,m5, m6, m7,
+ m8, m9, m10, m11, m12, m13, m14, m15)
+
+ /* (BMU) Load input symbols */
+ m7 = _mm_castpd_si128(_mm_loaddup_pd((double const *) val));
+
+ /* (BMU) Load trellis outputs */
+ m0 = _mm_load_si128((__m128i *) &out[0]);
+ m1 = _mm_load_si128((__m128i *) &out[8]);
+ m2 = _mm_load_si128((__m128i *) &out[16]);
+ m3 = _mm_load_si128((__m128i *) &out[24]);
+
+ SSE_BRANCH_METRIC_N2(m0, m1, m2, m3, m7, m4, m5)
+
+ m0 = _mm_load_si128((__m128i *) &out[32]);
+ m1 = _mm_load_si128((__m128i *) &out[40]);
+ m2 = _mm_load_si128((__m128i *) &out[48]);
+ m3 = _mm_load_si128((__m128i *) &out[56]);
+
+ SSE_BRANCH_METRIC_N2(m0, m1, m2, m3, m7, m6, m7)
+
+ /* (PMU) Butterflies: 0-15 */
+ SSE_BUTTERFLY(m8, m9, m4, m0, m1)
+ SSE_BUTTERFLY(m10, m11, m5, m2, m3)
+
+ _mm_store_si128((__m128i *) &paths[0], m0);
+ _mm_store_si128((__m128i *) &paths[8], m2);
+ _mm_store_si128((__m128i *) &paths[32], m9);
+ _mm_store_si128((__m128i *) &paths[40], m11);
+
+ /* (PMU) Butterflies: 17-31 */
+ SSE_BUTTERFLY(m12, m13, m6, m0, m2)
+ SSE_BUTTERFLY(m14, m15, m7, m9, m11)
+
+ _mm_store_si128((__m128i *) &paths[16], m0);
+ _mm_store_si128((__m128i *) &paths[24], m9);
+ _mm_store_si128((__m128i *) &paths[48], m13);
+ _mm_store_si128((__m128i *) &paths[56], m15);
+
+ if (norm)
+ SSE_NORMALIZE_K7(m4, m1, m5, m3, m6, m2,
+ m7, m11, m0, m8, m9, m10)
+
+ _mm_store_si128((__m128i *) &sums[0], m4);
+ _mm_store_si128((__m128i *) &sums[8], m5);
+ _mm_store_si128((__m128i *) &sums[16], m6);
+ _mm_store_si128((__m128i *) &sums[24], m7);
+ _mm_store_si128((__m128i *) &sums[32], m1);
+ _mm_store_si128((__m128i *) &sums[40], m3);
+ _mm_store_si128((__m128i *) &sums[48], m2);
+ _mm_store_si128((__m128i *) &sums[56], m11);
+}
+
+/* Combined BMU/PMU (K=7, N=3 and N=4)
+ * Compute branch metrics followed by path metrics for half rate 64-state
+ * trellis. 32 butterfly operations are computed. Deinterleave path
+ * metrics before computing branch metrics as in the half rate case.
+ */
+__always_inline void _sse_metrics_k7_n4(const int16_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ __m128i m0, m1, m2, m3, m4, m5, m6, m7;
+ __m128i m8, m9, m10, m11, m12, m13, m14, m15;
+
+ /* (PMU) Load accumulated path matrics */
+ m0 = _mm_load_si128((__m128i *) &sums[0]);
+ m1 = _mm_load_si128((__m128i *) &sums[8]);
+ m2 = _mm_load_si128((__m128i *) &sums[16]);
+ m3 = _mm_load_si128((__m128i *) &sums[24]);
+ m4 = _mm_load_si128((__m128i *) &sums[32]);
+ m5 = _mm_load_si128((__m128i *) &sums[40]);
+ m6 = _mm_load_si128((__m128i *) &sums[48]);
+ m7 = _mm_load_si128((__m128i *) &sums[56]);
+
+ /* (PMU) Deinterleave into even and odd packed registers */
+ SSE_DEINTERLEAVE_K7(m0, m1, m2, m3 ,m4 ,m5, m6, m7,
+ m8, m9, m10, m11, m12, m13, m14, m15)
+
+ /* (BMU) Load and expand 8-bit input out to 16-bits */
+ m7 = _mm_castpd_si128(_mm_loaddup_pd((double const *) val));
+
+ /* (BMU) Load and compute branch metrics */
+ m0 = _mm_load_si128((__m128i *) &out[0]);
+ m1 = _mm_load_si128((__m128i *) &out[8]);
+ m2 = _mm_load_si128((__m128i *) &out[16]);
+ m3 = _mm_load_si128((__m128i *) &out[24]);
+
+ SSE_BRANCH_METRIC_N4(m0, m1, m2, m3, m7, m4)
+
+ m0 = _mm_load_si128((__m128i *) &out[32]);
+ m1 = _mm_load_si128((__m128i *) &out[40]);
+ m2 = _mm_load_si128((__m128i *) &out[48]);
+ m3 = _mm_load_si128((__m128i *) &out[56]);
+
+ SSE_BRANCH_METRIC_N4(m0, m1, m2, m3, m7, m5)
+
+ m0 = _mm_load_si128((__m128i *) &out[64]);
+ m1 = _mm_load_si128((__m128i *) &out[72]);
+ m2 = _mm_load_si128((__m128i *) &out[80]);
+ m3 = _mm_load_si128((__m128i *) &out[88]);
+
+ SSE_BRANCH_METRIC_N4(m0, m1, m2, m3, m7, m6)
+
+ m0 = _mm_load_si128((__m128i *) &out[96]);
+ m1 = _mm_load_si128((__m128i *) &out[104]);
+ m2 = _mm_load_si128((__m128i *) &out[112]);
+ m3 = _mm_load_si128((__m128i *) &out[120]);
+
+ SSE_BRANCH_METRIC_N4(m0, m1, m2, m3, m7, m7)
+
+ /* (PMU) Butterflies: 0-15 */
+ SSE_BUTTERFLY(m8, m9, m4, m0, m1)
+ SSE_BUTTERFLY(m10, m11, m5, m2, m3)
+
+ _mm_store_si128((__m128i *) &paths[0], m0);
+ _mm_store_si128((__m128i *) &paths[8], m2);
+ _mm_store_si128((__m128i *) &paths[32], m9);
+ _mm_store_si128((__m128i *) &paths[40], m11);
+
+ /* (PMU) Butterflies: 17-31 */
+ SSE_BUTTERFLY(m12, m13, m6, m0, m2)
+ SSE_BUTTERFLY(m14, m15, m7, m9, m11)
+
+ _mm_store_si128((__m128i *) &paths[16], m0);
+ _mm_store_si128((__m128i *) &paths[24], m9);
+ _mm_store_si128((__m128i *) &paths[48], m13);
+ _mm_store_si128((__m128i *) &paths[56], m15);
+
+ if (norm)
+ SSE_NORMALIZE_K7(m4, m1, m5, m3, m6, m2,
+ m7, m11, m0, m8, m9, m10)
+
+ _mm_store_si128((__m128i *) &sums[0], m4);
+ _mm_store_si128((__m128i *) &sums[8], m5);
+ _mm_store_si128((__m128i *) &sums[16], m6);
+ _mm_store_si128((__m128i *) &sums[24], m7);
+ _mm_store_si128((__m128i *) &sums[32], m1);
+ _mm_store_si128((__m128i *) &sums[40], m3);
+ _mm_store_si128((__m128i *) &sums[48], m2);
+ _mm_store_si128((__m128i *) &sums[56], m11);
+}
+
+void gen_metrics_k5_n2(const int8_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ const int16_t _val[4] = { val[0], val[1], val[0], val[1] };
+
+ _sse_metrics_k5_n2(_val, out, sums, paths, norm);
+}
+
+void gen_metrics_k5_n3(const int8_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ const int16_t _val[4] = { val[0], val[1], val[2], 0 };
+
+ _sse_metrics_k5_n4(_val, out, sums, paths, norm);
+}
+
+void gen_metrics_k5_n4(const int8_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ const int16_t _val[4] = { val[0], val[1], val[2], val[3] };
+
+ _sse_metrics_k5_n4(_val, out, sums, paths, norm);
+}
+
+void gen_metrics_k7_n2(const int8_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ const int16_t _val[4] = { val[0], val[1], val[0], val[1] };
+
+ _sse_metrics_k7_n2(_val, out, sums, paths, norm);
+}
+
+void gen_metrics_k7_n3(const int8_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ const int16_t _val[4] = { val[0], val[1], val[2], 0 };
+
+ _sse_metrics_k7_n4(_val, out, sums, paths, norm);
+}
+
+void gen_metrics_k7_n4(const int8_t *val, const int16_t *out,
+ int16_t *sums, int16_t *paths, int norm)
+{
+ const int16_t _val[4] = { val[0], val[1], val[2], val[3] };
+
+ _sse_metrics_k7_n4(_val, out, sums, paths, norm);
+}
+
+#endif /* HAVE_SSE3 */
--
1.9.0
1
0
[osmo-bts PATCH 2/5] osmo-bts-sysmo/utils.c: Added a function for calculate the power transmitter
by Alvaro Neira Ayuso 28 Apr '14
by Alvaro Neira Ayuso 28 Apr '14
28 Apr '14
From: Álvaro Neira Ayuso <anayuso(a)sysmocom.de>
Signed-off-by: Alvaro Neira Ayuso <anayuso(a)sysmocom.de>
---
src/osmo-bts-sysmo/oml.c | 4 ++--
src/osmo-bts-sysmo/utils.c | 11 +++++++++++
src/osmo-bts-sysmo/utils.h | 1 +
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/osmo-bts-sysmo/oml.c b/src/osmo-bts-sysmo/oml.c
index 1543f85..4ebf664 100644
--- a/src/osmo-bts-sysmo/oml.c
+++ b/src/osmo-bts-sysmo/oml.c
@@ -323,7 +323,7 @@ static int trx_init(struct gsm_bts_trx *trx)
dev_par->u16BcchArfcn = trx->bts->c0->arfcn;
dev_par->u8NbTsc = trx->bts->bsic & 7;
dev_par->fRxPowerLevel = fl1h->ul_power_target;
- dev_par->fTxPowerLevel = trx->nominal_power - trx->max_power_red;
+ dev_par->fTxPowerLevel = sysmobts_get_power_trx(trx);
LOGP(DL1C, LOGL_NOTICE, "Init TRX (ARFCN %u, TSC %u, RxPower % 2f dBm, "
"TxPower % 2.2f dBm\n", dev_par->u16Arfcn, dev_par->u8NbTsc,
dev_par->fRxPowerLevel, dev_par->fTxPowerLevel);
@@ -1544,7 +1544,7 @@ int bts_model_apply_oml(struct gsm_bts *bts, struct msgb *msg,
/* Did we go through MphInit yet? If yes fire and forget */
if (fl1h->hLayer1)
- l1if_set_txpower(fl1h, trx->nominal_power - trx->max_power_red);
+ l1if_set_txpower(fl1h, sysmobts_get_power_trx(trx));
}
/* FIXME: we actaully need to send a ACK or NACK for the OML message */
diff --git a/src/osmo-bts-sysmo/utils.c b/src/osmo-bts-sysmo/utils.c
index f576eef..af1e5d2 100644
--- a/src/osmo-bts-sysmo/utils.c
+++ b/src/osmo-bts-sysmo/utils.c
@@ -136,3 +136,14 @@ int sysmobts_get_nominal_power(struct gsm_bts_trx *trx)
}
return -1;
}
+
+int sysmobts_get_power_trx(struct gsm_bts_trx *trx)
+{
+ int power_transmitter = trx->nominal_power - trx->max_power_red;
+ power_transmitter -= trx->power_reduce;
+
+ if (power_transmitter < 0)
+ power_transmitter = 0;
+
+ return power_transmitter;
+}
diff --git a/src/osmo-bts-sysmo/utils.h b/src/osmo-bts-sysmo/utils.h
index ff41437..aef774c 100644
--- a/src/osmo-bts-sysmo/utils.h
+++ b/src/osmo-bts-sysmo/utils.h
@@ -12,4 +12,5 @@ int sysmobts_select_femto_band(struct gsm_bts_trx *trx, uint16_t arfcn);
int sysmobts_get_nominal_power(struct gsm_bts_trx *trx);
+int sysmobts_get_power_trx(struct gsm_bts_trx *trx);
#endif
--
1.7.10.4
1
0
[PATCH 1/5] sms: Kill the sms->sender and use addr/ton/npi throughout the code
by Holger Freyther 25 Apr '14
by Holger Freyther 25 Apr '14
25 Apr '14
From: Holger Hans Peter Freyther <zecke(a)selfish.org>
This is an incompatible database schema change. Store the type of
the address in the database for both the sender and the receiver.
Currently it is possible to use SMPP to store a SMS and the NPI
and TON will be lost on the delivery of the SMS. The schema is
changed to make the delivery always use the right NPI/TON. This
patch is not ready for the master branch as there is no upgrade
path for the HLR yet.
---
openbsc/include/openbsc/gsm_data.h | 1 -
openbsc/src/libmsc/db.c | 62 +++++++++++++++++++++++---------------
openbsc/src/libmsc/gsm_04_11.c | 9 ++----
openbsc/src/libmsc/smpp_openbsc.c | 5 ++-
4 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 8f24d4f..4338cd6 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -304,7 +304,6 @@ struct gsm_sms_addr {
struct gsm_sms {
unsigned long long id;
- struct gsm_subscriber *sender;
struct gsm_subscriber *receiver;
struct gsm_sms_addr src, dst;
enum gsm_sms_source_id source;
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index bfa4e75..df26b04 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -95,7 +95,6 @@ static char *create_stmts[] = {
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"created TIMESTAMP NOT NULL, "
"sent TIMESTAMP, "
- "sender_id INTEGER NOT NULL, "
"receiver_id INTEGER NOT NULL, "
"deliver_attempts INTEGER NOT NULL DEFAULT 0, "
/* data directly copied/derived from SMS */
@@ -105,7 +104,12 @@ static char *create_stmts[] = {
"protocol_id INTEGER NOT NULL, "
"data_coding_scheme INTEGER NOT NULL, "
"ud_hdr_ind INTEGER NOT NULL, "
- "dest_addr TEXT, "
+ "src_addr TEXT NOT NULL, "
+ "src_ton INTEGER NOT NULL, "
+ "src_npi INTEGER NOT NULL, "
+ "dest_addr TEXT NOT NULL, "
+ "dest_ton INTEGER NOT NULL, "
+ "dest_npi INTEGER NOT NULL, "
"user_data BLOB, " /* TP-UD */
/* additional data, interpreted from SMS */
"header BLOB, " /* UD Header */
@@ -1214,7 +1218,7 @@ int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char imei[GSM_IM
int db_sms_store(struct gsm_sms *sms)
{
dbi_result result;
- char *q_text, *q_daddr;
+ char *q_text, *q_daddr, *q_saddr;
unsigned char *q_udata;
char *validity_timestamp = "2222-2-2";
@@ -1222,25 +1226,35 @@ int db_sms_store(struct gsm_sms *sms)
dbi_conn_quote_string_copy(conn, (char *)sms->text, &q_text);
dbi_conn_quote_string_copy(conn, (char *)sms->dst.addr, &q_daddr);
+ dbi_conn_quote_string_copy(conn, (char *)sms->src.addr, &q_saddr);
dbi_conn_quote_binary_copy(conn, sms->user_data, sms->user_data_len,
&q_udata);
+
/* FIXME: correct validity period */
result = dbi_conn_queryf(conn,
"INSERT INTO SMS "
- "(created, sender_id, receiver_id, valid_until, "
+ "(created, receiver_id, valid_until, "
"reply_path_req, status_rep_req, protocol_id, "
- "data_coding_scheme, ud_hdr_ind, dest_addr, "
- "user_data, text) VALUES "
- "(datetime('now'), %llu, %llu, %u, "
- "%u, %u, %u, %u, %u, %s, %s, %s)",
- sms->sender->id,
+ "data_coding_scheme, ud_hdr_ind, "
+ "user_data, text, "
+ "dest_addr, dest_ton, dest_npi, "
+ "src_addr, src_ton, src_npi) VALUES "
+ "(datetime('now'), %llu, %u, "
+ "%u, %u, %u, "
+ "%u, %u, "
+ "%s, %s, "
+ "%s, %u, %u, "
+ "%s, %u, %u)",
sms->receiver ? sms->receiver->id : 0, validity_timestamp,
sms->reply_path_req, sms->status_rep_req, sms->protocol_id,
sms->data_coding_scheme, sms->ud_hdr_ind,
- q_daddr, q_udata, q_text);
+ q_udata, q_text,
+ q_daddr, sms->dst.ton, sms->dst.npi,
+ q_saddr, sms->src.ton, sms->src.npi);
free(q_text);
- free(q_daddr);
free(q_udata);
+ free(q_daddr);
+ free(q_saddr);
if (!result)
return -EIO;
@@ -1252,8 +1266,8 @@ int db_sms_store(struct gsm_sms *sms)
static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result result)
{
struct gsm_sms *sms = sms_alloc();
- long long unsigned int sender_id, receiver_id;
- const char *text, *daddr;
+ long long unsigned int receiver_id;
+ const char *text, *daddr, *saddr;
const unsigned char *user_data;
if (!sms)
@@ -1261,18 +1275,6 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
sms->id = dbi_result_get_ulonglong(result, "id");
- sender_id = dbi_result_get_ulonglong(result, "sender_id");
- sms->sender = subscr_get_by_id(net, sender_id);
- if (!sms->sender) {
- LOGP(DLSMS, LOGL_ERROR,
- "Failed to find sender(%llu) for id(%llu)\n",
- sender_id, sms->id);
- sms_free(sms);
- return NULL;
- }
-
- strncpy(sms->src.addr, sms->sender->extension, sizeof(sms->src.addr)-1);
-
receiver_id = dbi_result_get_ulonglong(result, "receiver_id");
sms->receiver = subscr_get_by_id(net, receiver_id);
if (!sms->receiver) {
@@ -1293,12 +1295,22 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
"data_coding_scheme");
/* sms->msg_ref is temporary and not stored in DB */
+ sms->dst.npi = dbi_result_get_uint(result, "dest_npi");
+ sms->dst.ton = dbi_result_get_uint(result, "dest_ton");
daddr = dbi_result_get_string(result, "dest_addr");
if (daddr) {
strncpy(sms->dst.addr, daddr, sizeof(sms->dst.addr));
sms->dst.addr[sizeof(sms->dst.addr)-1] = '\0';
}
+ sms->src.npi = dbi_result_get_uint(result, "src_npi");
+ sms->src.ton = dbi_result_get_uint(result, "src_ton");
+ saddr = dbi_result_get_string(result, "src_addr");
+ if (saddr) {
+ strncpy(sms->src.addr, saddr, sizeof(sms->src.addr));
+ sms->src.addr[sizeof(sms->src.addr)-1] = '\0';
+ }
+
sms->user_data_len = dbi_result_get_field_length(result, "user_data");
user_data = dbi_result_get_binary(result, "user_data");
if (sms->user_data_len > sizeof(sms->user_data))
diff --git a/openbsc/src/libmsc/gsm_04_11.c b/openbsc/src/libmsc/gsm_04_11.c
index 5f10759..b2100d8 100644
--- a/openbsc/src/libmsc/gsm_04_11.c
+++ b/openbsc/src/libmsc/gsm_04_11.c
@@ -73,8 +73,6 @@ struct gsm_sms *sms_alloc(void)
void sms_free(struct gsm_sms *sms)
{
/* drop references to subscriber structure */
- if (sms->sender)
- subscr_put(sms->sender);
if (sms->receiver)
subscr_put(sms->receiver);
#ifdef BUILD_SMPP
@@ -97,8 +95,7 @@ struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver,
sms->receiver = subscr_get(receiver);
strncpy(sms->text, text, sizeof(sms->text)-1);
- sms->sender = subscr_get(sender);
- strncpy(sms->src.addr, sms->sender->extension, sizeof(sms->src.addr)-1);
+ strncpy(sms->src.addr, sender->extension, sizeof(sms->src.addr)-1);
sms->reply_path_req = 0;
sms->status_rep_req = 0;
sms->ud_hdr_ind = 0;
@@ -378,12 +375,12 @@ static int gsm340_rx_tpdu(struct gsm_subscriber_connection *conn, struct msgb *m
}
}
- gsms->sender = subscr_get(conn->subscr);
+ strncpy(gsms->src.addr, conn->subscr->extension, sizeof(gsms->src.addr)-1);
LOGP(DLSMS, LOGL_INFO, "RX SMS: Sender: %s, MTI: 0x%02x, VPF: 0x%02x, "
"MR: 0x%02x PID: 0x%02x, DCS: 0x%02x, DA: %s, "
"UserDataLength: 0x%02x, UserData: \"%s\"\n",
- subscr_name(gsms->sender), sms_mti, sms_vpf, gsms->msg_ref,
+ subscr_name(conn->subscr), sms_mti, sms_vpf, gsms->msg_ref,
gsms->protocol_id, gsms->data_coding_scheme, gsms->dst.addr,
gsms->user_data_len,
sms_alphabet == DCS_7BIT_DEFAULT ? gsms->text :
diff --git a/openbsc/src/libmsc/smpp_openbsc.c b/openbsc/src/libmsc/smpp_openbsc.c
index ab558ce..ec541c2 100644
--- a/openbsc/src/libmsc/smpp_openbsc.c
+++ b/openbsc/src/libmsc/smpp_openbsc.c
@@ -133,7 +133,6 @@ static int submit_to_sms(struct gsm_sms **psms, struct gsm_network *net,
strncpy(sms->dst.addr, dest->extension, sizeof(sms->dst.addr)-1);
/* fill in the source address */
- sms->sender = subscr_get_by_id(net, 1);
sms->src.ton = submit->source_addr_ton;
sms->src.npi = submit->source_addr_npi;
strncpy(sms->src.addr, (char *)submit->source_addr, sizeof(sms->src.addr)-1);
@@ -475,13 +474,13 @@ static int deliver_to_esme(struct osmo_esme *esme, struct gsm_sms *sms,
deliver.source_addr_npi = NPI_Land_Mobile_E212;
snprintf((char *)deliver.source_addr,
sizeof(deliver.source_addr), "%s",
- sms->sender->imsi);
+ conn->subscr->imsi);
} else {
deliver.source_addr_ton = TON_Network_Specific;
deliver.source_addr_npi = NPI_ISDN_E163_E164;
snprintf((char *)deliver.source_addr,
sizeof(deliver.source_addr), "%s",
- sms->sender->extension);
+ conn->subscr->extension);
}
deliver.dest_addr_ton = sms->dst.ton;
--
1.9.1
3
6
In order to free RTP socket when lchan_free() or lchan_reset() is called,
a signal is used between libbsc and rtp_proxy.
---
openbsc/include/openbsc/signal.h | 1 +
openbsc/src/libbsc/chan_alloc.c | 14 +-
openbsc/src/libmsc/Makefile.am | 3 +-
openbsc/src/libmsc/rtp_proxy.c | 847 +++++++++++++++++++++++++++++++++++++++
openbsc/src/libtrau/Makefile.am | 2 +-
openbsc/src/libtrau/rtp_proxy.c | 816 -------------------------------------
6 files changed, 863 insertions(+), 820 deletions(-)
create mode 100644 openbsc/src/libmsc/rtp_proxy.c
delete mode 100644 openbsc/src/libtrau/rtp_proxy.c
diff --git a/openbsc/include/openbsc/signal.h b/openbsc/include/openbsc/signal.h
index 39319f1..4e7a71a 100644
--- a/openbsc/include/openbsc/signal.h
+++ b/openbsc/include/openbsc/signal.h
@@ -99,6 +99,7 @@ enum signal_lchan {
S_LCHAN_HANDOVER_FAIL, /* 04.08 Handover Failed */
S_LCHAN_HANDOVER_DETECT, /* 08.58 Handover Detect */
S_LCHAN_MEAS_REP, /* 08.58 Measurement Report */
+ S_LCHAN_RTP_SOCKET_FREE,
};
/* SS_CHALLOC signals */
diff --git a/openbsc/src/libbsc/chan_alloc.c b/openbsc/src/libbsc/chan_alloc.c
index 9b74329..7bf6477 100644
--- a/openbsc/src/libbsc/chan_alloc.c
+++ b/openbsc/src/libbsc/chan_alloc.c
@@ -311,9 +311,13 @@ void lchan_free(struct gsm_lchan *lchan)
}
if (lchan->abis_ip.rtp_socket) {
+ struct lchan_signal_data sig;
+
LOGP(DRLL, LOGL_ERROR, "%s RTP Proxy Socket remained open.\n",
gsm_lchan_name(lchan));
- rtp_socket_free(lchan->abis_ip.rtp_socket);
+ sig.lchan = lchan;
+ sig.mr = NULL;
+ osmo_signal_dispatch(SS_LCHAN, S_LCHAN_RTP_SOCKET_FREE, &sig);
lchan->abis_ip.rtp_socket = NULL;
}
@@ -369,7 +373,13 @@ void lchan_reset(struct gsm_lchan *lchan)
lchan->state = LCHAN_S_NONE;
if (lchan->abis_ip.rtp_socket) {
- rtp_socket_free(lchan->abis_ip.rtp_socket);
+ struct lchan_signal_data sig;
+
+ LOGP(DRLL, LOGL_ERROR, "%s RTP Proxy Socket remained open.\n",
+ gsm_lchan_name(lchan));
+ sig.lchan = lchan;
+ sig.mr = NULL;
+ osmo_signal_dispatch(SS_LCHAN, S_LCHAN_RTP_SOCKET_FREE, &sig);
lchan->abis_ip.rtp_socket = NULL;
}
}
diff --git a/openbsc/src/libmsc/Makefile.am b/openbsc/src/libmsc/Makefile.am
index 24db2c2..4d44a62 100644
--- a/openbsc/src/libmsc/Makefile.am
+++ b/openbsc/src/libmsc/Makefile.am
@@ -17,7 +17,8 @@ libmsc_a_SOURCES = auth.c \
ussd.c \
vty_interface_layer3.c \
transaction.c \
- osmo_msc.c ctrl_commands.c
+ osmo_msc.c ctrl_commands.c \
+ rtp_proxy.c
if BUILD_SMPP
noinst_HEADERS = smpp_smsc.h
diff --git a/openbsc/src/libmsc/rtp_proxy.c b/openbsc/src/libmsc/rtp_proxy.c
new file mode 100644
index 0000000..a950a72
--- /dev/null
+++ b/openbsc/src/libmsc/rtp_proxy.c
@@ -0,0 +1,847 @@
+/* RTP proxy handling for ip.access nanoBTS */
+
+/* (C) 2009-2013 by Harald Welte <laforge(a)gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/time.h> /* gettimeofday() */
+#include <unistd.h> /* get..() */
+#include <time.h> /* clock() */
+#include <sys/utsname.h> /* uname() */
+
+#include <osmocom/core/talloc.h>
+#include <openbsc/gsm_data.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/select.h>
+#include <openbsc/debug.h>
+#include <openbsc/rtp_proxy.h>
+#include <openbsc/mncc.h>
+#include <openbsc/trau_upqueue.h>
+#include <openbsc/signal.h>
+
+/* attempt to determine byte order */
+#include <sys/param.h>
+#include <limits.h>
+
+#ifndef __BYTE_ORDER
+# ifdef __APPLE__
+# define __BYTE_ORDER __DARWIN_BYTE_ORDER
+# define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+# define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+# error "__BYTE_ORDER should be defined by someone"
+# endif
+#endif
+
+static LLIST_HEAD(rtp_sockets);
+
+/* should we mangle the CNAME inside SDES of RTCP packets? We disable
+ * this by default, as it seems to be not needed */
+static int mangle_rtcp_cname = 0;
+
+enum rtp_bfd_priv {
+ RTP_PRIV_NONE,
+ RTP_PRIV_RTP,
+ RTP_PRIV_RTCP
+};
+
+#define RTP_ALLOC_SIZE 1500
+
+/* according to RFC 1889 */
+struct rtcp_hdr {
+ uint8_t byte0;
+ uint8_t type;
+ uint16_t length;
+} __attribute__((packed));
+
+#define RTCP_TYPE_SDES 202
+
+#define RTCP_IE_CNAME 1
+
+/* according to RFC 3550 */
+struct rtp_hdr {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint8_t csrc_count:4,
+ extension:1,
+ padding:1,
+ version:2;
+ uint8_t payload_type:7,
+ marker:1;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint8_t version:2,
+ padding:1,
+ extension:1,
+ csrc_count:4;
+ uint8_t marker:1,
+ payload_type:7;
+#endif
+ uint16_t sequence;
+ uint32_t timestamp;
+ uint32_t ssrc;
+} __attribute__((packed));
+
+struct rtp_x_hdr {
+ uint16_t by_profile;
+ uint16_t length;
+} __attribute__((packed));
+
+#define RTP_VERSION 2
+
+/* decode an rtp frame and create a new buffer with payload */
+static int rtp_decode(struct msgb *msg, uint32_t callref, struct msgb **data)
+{
+ struct msgb *new_msg;
+ struct gsm_data_frame *frame;
+ struct rtp_hdr *rtph = (struct rtp_hdr *)msg->data;
+ struct rtp_x_hdr *rtpxh;
+ uint8_t *payload;
+ int payload_len;
+ int msg_type;
+ int x_len;
+
+ if (msg->len < 12) {
+ DEBUGPC(DLMUX, "received RTP frame too short (len = %d)\n",
+ msg->len);
+ return -EINVAL;
+ }
+ if (rtph->version != RTP_VERSION) {
+ DEBUGPC(DLMUX, "received RTP version %d not supported.\n",
+ rtph->version);
+ return -EINVAL;
+ }
+ payload = msg->data + sizeof(struct rtp_hdr) + (rtph->csrc_count << 2);
+ payload_len = msg->len - sizeof(struct rtp_hdr) - (rtph->csrc_count << 2);
+ if (payload_len < 0) {
+ DEBUGPC(DLMUX, "received RTP frame too short (len = %d, "
+ "csrc count = %d)\n", msg->len, rtph->csrc_count);
+ return -EINVAL;
+ }
+ if (rtph->extension) {
+ if (payload_len < sizeof(struct rtp_x_hdr)) {
+ DEBUGPC(DLMUX, "received RTP frame too short for "
+ "extension header\n");
+ return -EINVAL;
+ }
+ rtpxh = (struct rtp_x_hdr *)payload;
+ x_len = ntohs(rtpxh->length) * 4 + sizeof(struct rtp_x_hdr);
+ payload += x_len;
+ payload_len -= x_len;
+ if (payload_len < 0) {
+ DEBUGPC(DLMUX, "received RTP frame too short, "
+ "extension header exceeds frame length\n");
+ return -EINVAL;
+ }
+ }
+ if (rtph->padding) {
+ if (payload_len < 1) {
+ DEBUGPC(DLMUX, "received RTP frame too short for "
+ "padding length\n");
+ return -EINVAL;
+ }
+ payload_len -= payload[payload_len - 1];
+ if (payload_len < 0) {
+ DEBUGPC(DLMUX, "received RTP frame with padding "
+ "greater than payload\n");
+ return -EINVAL;
+ }
+ }
+
+ switch (rtph->payload_type) {
+ case RTP_PT_GSM_FULL:
+ msg_type = GSM_TCHF_FRAME;
+ if (payload_len != RTP_LEN_GSM_FULL) {
+ DEBUGPC(DLMUX, "received RTP full rate frame with "
+ "payload length != %d (len = %d)\n",
+ RTP_LEN_GSM_FULL, payload_len);
+ return -EINVAL;
+ }
+ break;
+ case RTP_PT_GSM_EFR:
+ msg_type = GSM_TCHF_FRAME_EFR;
+ if (payload_len != RTP_LEN_GSM_EFR) {
+ DEBUGPC(DLMUX, "received RTP extended full rate frame "
+ "with payload length != %d (len = %d)\n",
+ RTP_LEN_GSM_EFR, payload_len);
+ return -EINVAL;
+ }
+ break;
+ case RTP_PT_GSM_HALF:
+ msg_type = GSM_TCHH_FRAME;
+ if (payload_len != RTP_LEN_GSM_HALF) {
+ DEBUGPC(DLMUX, "received RTP half rate frame with "
+ "payload length != %d (len = %d)\n",
+ RTP_LEN_GSM_HALF, payload_len);
+ return -EINVAL;
+ }
+ break;
+ case RTP_PT_AMR:
+ break;
+ default:
+ DEBUGPC(DLMUX, "received RTP frame with unknown payload "
+ "type %d\n", rtph->payload_type);
+ return -EINVAL;
+ }
+
+ if (rtph->payload_type == RTP_PT_AMR) {
+ new_msg = msgb_alloc(sizeof(struct gsm_data_frame) + 1
+ + payload_len, "GSM-DATA");
+ } else {
+ new_msg = msgb_alloc(sizeof(struct gsm_data_frame)
+ + payload_len, "GSM-DATA");
+ }
+ if (!new_msg)
+ return -ENOMEM;
+ frame = (struct gsm_data_frame *)(new_msg->data);
+ frame->msg_type = msg_type;
+ frame->callref = callref;
+ if (rtph->payload_type == RTP_PT_AMR) {
+ frame->data[0] = payload_len;
+ msgb_put(new_msg, sizeof(struct gsm_data_frame) + 1
+ + payload_len);
+ memcpy(frame->data + 1, payload, payload_len);
+ } else {
+ msgb_put(new_msg, sizeof(struct gsm_data_frame) + payload_len);
+ memcpy(frame->data, payload, payload_len);
+ }
+
+ *data = new_msg;
+ return 0;
+}
+
+/* "to - from" */
+static void tv_difference(struct timeval *diff, const struct timeval *from,
+ const struct timeval *__to)
+{
+ struct timeval _to = *__to, *to = &_to;
+
+ if (to->tv_usec < from->tv_usec) {
+ to->tv_sec -= 1;
+ to->tv_usec += 1000000;
+ }
+
+ diff->tv_usec = to->tv_usec - from->tv_usec;
+ diff->tv_sec = to->tv_sec - from->tv_sec;
+}
+
+/*! \brief encode and send a rtp frame
+ * \param[in] rs RTP socket through which we shall send
+ * \param[in] frame GSM RTP frame to be sent
+ */
+int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame)
+{
+ struct rtp_sub_socket *rss = &rs->rtp;
+ struct msgb *msg;
+ struct rtp_hdr *rtph;
+ int payload_type;
+ int payload_len;
+ int duration; /* in samples */
+ int is_bfi = 0;
+
+ if (rs->tx_action != RTP_SEND_DOWNSTREAM) {
+ /* initialize sequences */
+ rs->tx_action = RTP_SEND_DOWNSTREAM;
+ rs->transmit.ssrc = rand();
+ rs->transmit.sequence = random();
+ rs->transmit.timestamp = random();
+ }
+
+ switch (frame->msg_type) {
+ case GSM_TCHF_FRAME:
+ payload_type = RTP_PT_GSM_FULL;
+ payload_len = RTP_LEN_GSM_FULL;
+ duration = RTP_GSM_DURATION;
+ break;
+ case GSM_TCHF_FRAME_EFR:
+ payload_type = RTP_PT_GSM_EFR;
+ payload_len = RTP_LEN_GSM_EFR;
+ duration = RTP_GSM_DURATION;
+ break;
+ case GSM_TCHH_FRAME:
+ payload_type = RTP_PT_GSM_HALF;
+ payload_len = RTP_LEN_GSM_HALF;
+ duration = RTP_GSM_DURATION;
+ break;
+ case GSM_TCH_FRAME_AMR:
+ payload_type = RTP_PT_AMR;
+ payload_len = frame->data[0];
+ duration = RTP_GSM_DURATION;
+ break;
+ case GSM_BAD_FRAME:
+ payload_type = 0;
+ payload_len = 0;
+ duration = RTP_GSM_DURATION;
+ is_bfi = 1;
+ break;
+ default:
+ DEBUGPC(DLMUX, "unsupported message type %d\n",
+ frame->msg_type);
+ return -EINVAL;
+ }
+
+ {
+ struct timeval tv, tv_diff;
+ long int usec_diff, frame_diff;
+
+ gettimeofday(&tv, NULL);
+ tv_difference(&tv_diff, &rs->transmit.last_tv, &tv);
+ rs->transmit.last_tv = tv;
+
+ usec_diff = tv_diff.tv_sec * 1000000 + tv_diff.tv_usec;
+ frame_diff = (usec_diff / 20000);
+
+ if (abs(frame_diff) > 1) {
+ long int frame_diff_excess = frame_diff - 1;
+
+ LOGP(DLMUX, LOGL_NOTICE,
+ "Correcting frame difference of %ld frames\n", frame_diff_excess);
+ rs->transmit.sequence += frame_diff_excess;
+ rs->transmit.timestamp += frame_diff_excess * duration;
+ }
+ }
+
+ if (is_bfi) {
+ /* In case of a bad frame, just count and drop packt. */
+ rs->transmit.timestamp += duration;
+ rs->transmit.sequence++;
+ return 0;
+ }
+
+ msg = msgb_alloc(sizeof(struct rtp_hdr) + payload_len, "RTP-GSM-FULL");
+ if (!msg)
+ return -ENOMEM;
+ rtph = (struct rtp_hdr *)msg->data;
+ rtph->version = RTP_VERSION;
+ rtph->padding = 0;
+ rtph->extension = 0;
+ rtph->csrc_count = 0;
+ rtph->marker = 0;
+ rtph->payload_type = payload_type;
+ rtph->sequence = htons(rs->transmit.sequence++);
+ rtph->timestamp = htonl(rs->transmit.timestamp);
+ rs->transmit.timestamp += duration;
+ rtph->ssrc = htonl(rs->transmit.ssrc);
+ if (frame->msg_type == GSM_TCH_FRAME_AMR) {
+ memcpy(msg->data + sizeof(struct rtp_hdr), frame->data + 1,
+ payload_len);
+ } else {
+ memcpy(msg->data + sizeof(struct rtp_hdr), frame->data,
+ payload_len);
+ }
+ msgb_put(msg, sizeof(struct rtp_hdr) + payload_len);
+ msgb_enqueue(&rss->tx_queue, msg);
+ rss->bfd.when |= BSC_FD_WRITE;
+
+ return 0;
+}
+
+/* iterate over all chunks in one RTCP message, look for CNAME IEs and
+ * replace all of those with 'new_cname' */
+static int rtcp_sdes_cname_mangle(struct msgb *msg, struct rtcp_hdr *rh,
+ uint16_t *rtcp_len, const char *new_cname)
+{
+ uint8_t *rtcp_end;
+ uint8_t *cur = (uint8_t *) rh;
+ uint8_t tag, len = 0;
+
+ rtcp_end = cur + *rtcp_len;
+ /* move cur to end of RTP header */
+ cur += sizeof(*rh);
+
+ /* iterate over Chunks */
+ while (cur+4 < rtcp_end) {
+ /* skip four bytes SSRC/CSRC */
+ cur += 4;
+
+ /* iterate over IE's inside the chunk */
+ while (cur+1 < rtcp_end) {
+ tag = *cur++;
+ if (tag == 0) {
+ /* end of chunk, skip additional zero */
+ while (*cur++ == 0) { }
+ break;
+ }
+ len = *cur++;
+
+ if (tag == RTCP_IE_CNAME) {
+ /* we've found the CNAME, lets mangle it */
+ if (len < strlen(new_cname)) {
+ /* we need to make more space */
+ int increase = strlen(new_cname) - len;
+
+ msgb_push(msg, increase);
+ memmove(cur+len+increase, cur+len,
+ rtcp_end - (cur+len));
+ /* FIXME: we have to respect RTCP
+ * padding/alignment rules! */
+ len += increase;
+ *(cur-1) += increase;
+ rtcp_end += increase;
+ *rtcp_len += increase;
+ }
+ /* copy new CNAME into message */
+ memcpy(cur, new_cname, strlen(new_cname));
+ /* FIXME: zero the padding in case new CNAME
+ * is smaller than old one !!! */
+ }
+ cur += len;
+ }
+ }
+
+ return 0;
+}
+
+static int rtcp_mangle(struct msgb *msg, struct rtp_socket *rs)
+{
+ struct rtp_sub_socket *rss = &rs->rtcp;
+ struct rtcp_hdr *rtph;
+ uint16_t old_len;
+ int rc;
+
+ if (!mangle_rtcp_cname)
+ return 0;
+
+ printf("RTCP\n");
+ /* iterate over list of RTCP messages */
+ rtph = (struct rtcp_hdr *)msg->data;
+ while ((void *)rtph + sizeof(*rtph) <= (void *)msg->data + msg->len) {
+ old_len = (ntohs(rtph->length) + 1) * 4;
+ if ((void *)rtph + old_len > (void *)msg->data + msg->len) {
+ DEBUGPC(DLMUX, "received RTCP packet too short for "
+ "length element\n");
+ return -EINVAL;
+ }
+ if (rtph->type == RTCP_TYPE_SDES) {
+ char new_cname[255];
+ strncpy(new_cname, inet_ntoa(rss->sin_local.sin_addr),
+ sizeof(new_cname));
+ new_cname[sizeof(new_cname)-1] = '\0';
+ rc = rtcp_sdes_cname_mangle(msg, rtph, &old_len,
+ new_cname);
+ if (rc < 0)
+ return rc;
+ }
+ rtph = (void *)rtph + old_len;
+ }
+
+ return 0;
+}
+
+/* read from incoming RTP/RTCP socket */
+static int rtp_socket_read(struct rtp_socket *rs, struct rtp_sub_socket *rss)
+{
+ int rc;
+ struct msgb *msg = msgb_alloc(RTP_ALLOC_SIZE, "RTP/RTCP");
+ struct msgb *new_msg;
+ struct rtp_sub_socket *other_rss;
+
+ if (!msg)
+ return -ENOMEM;
+
+ rc = read(rss->bfd.fd, msg->data, RTP_ALLOC_SIZE);
+ if (rc <= 0) {
+ rss->bfd.when &= ~BSC_FD_READ;
+ return rc;
+ }
+
+ msgb_put(msg, rc);
+
+ switch (rs->rx_action) {
+ case RTP_PROXY:
+ if (!rs->proxy.other_sock) {
+ rc = -EIO;
+ goto out_free;
+ }
+ if (rss->bfd.priv_nr == RTP_PRIV_RTP)
+ other_rss = &rs->proxy.other_sock->rtp;
+ else if (rss->bfd.priv_nr == RTP_PRIV_RTCP) {
+ other_rss = &rs->proxy.other_sock->rtcp;
+ /* modify RTCP SDES CNAME */
+ rc = rtcp_mangle(msg, rs);
+ if (rc < 0)
+ goto out_free;
+ } else {
+ rc = -EINVAL;
+ goto out_free;
+ }
+ msgb_enqueue(&other_rss->tx_queue, msg);
+ other_rss->bfd.when |= BSC_FD_WRITE;
+ break;
+
+ case RTP_RECV_UPSTREAM:
+ if (!rs->receive.callref || !rs->receive.net) {
+ rc = -EIO;
+ goto out_free;
+ }
+ if (rss->bfd.priv_nr == RTP_PRIV_RTCP) {
+ if (!mangle_rtcp_cname) {
+ msgb_free(msg);
+ break;
+ }
+ /* modify RTCP SDES CNAME */
+ rc = rtcp_mangle(msg, rs);
+ if (rc < 0)
+ goto out_free;
+ msgb_enqueue(&rss->tx_queue, msg);
+ rss->bfd.when |= BSC_FD_WRITE;
+ break;
+ }
+ if (rss->bfd.priv_nr != RTP_PRIV_RTP) {
+ rc = -EINVAL;
+ goto out_free;
+ }
+ rc = rtp_decode(msg, rs->receive.callref, &new_msg);
+ if (rc < 0)
+ goto out_free;
+ msgb_free(msg);
+ trau_tx_to_mncc(rs->receive.net, new_msg);
+ break;
+
+ case RTP_NONE: /* if socket exists, but disabled by app */
+ msgb_free(msg);
+ break;
+ }
+
+ return 0;
+
+out_free:
+ msgb_free(msg);
+ return rc;
+}
+
+/* \brief write from tx_queue to RTP/RTCP socket */
+static int rtp_socket_write(struct rtp_socket *rs, struct rtp_sub_socket *rss)
+{
+ struct msgb *msg;
+ int written;
+
+ msg = msgb_dequeue(&rss->tx_queue);
+ if (!msg) {
+ rss->bfd.when &= ~BSC_FD_WRITE;
+ return 0;
+ }
+
+ written = write(rss->bfd.fd, msg->data, msg->len);
+ if (written < msg->len) {
+ LOGP(DLMIB, LOGL_ERROR, "short write");
+ msgb_free(msg);
+ return -EIO;
+ }
+
+ msgb_free(msg);
+
+ return 0;
+}
+
+
+/*! \brief callback for the select.c:bfd_* layer */
+static int rtp_bfd_cb(struct osmo_fd *bfd, unsigned int flags)
+{
+ struct rtp_socket *rs = bfd->data;
+ struct rtp_sub_socket *rss;
+
+ switch (bfd->priv_nr) {
+ case RTP_PRIV_RTP:
+ rss = &rs->rtp;
+ break;
+ case RTP_PRIV_RTCP:
+ rss = &rs->rtcp;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (flags & BSC_FD_READ)
+ rtp_socket_read(rs, rss);
+
+ if (flags & BSC_FD_WRITE)
+ rtp_socket_write(rs, rss);
+
+ return 0;
+}
+
+/*! \brief initialize one rtp sub-socket */
+static void init_rss(struct rtp_sub_socket *rss,
+ struct rtp_socket *rs, int fd, int priv_nr)
+{
+ /* initialize bfd */
+ rss->bfd.fd = fd;
+ rss->bfd.data = rs;
+ rss->bfd.priv_nr = priv_nr;
+ rss->bfd.cb = rtp_bfd_cb;
+}
+
+/*! \brief create a new RTP/RTCP socket and bind it */
+struct rtp_socket *rtp_socket_create(void)
+{
+ int rc;
+ struct rtp_socket *rs;
+
+ DEBUGP(DLMUX, "rtp_socket_create(): ");
+
+ rs = talloc_zero(tall_bsc_ctx, struct rtp_socket);
+ if (!rs)
+ return NULL;
+
+ INIT_LLIST_HEAD(&rs->rtp.tx_queue);
+ INIT_LLIST_HEAD(&rs->rtcp.tx_queue);
+
+ rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (rc < 0)
+ goto out_free;
+
+ init_rss(&rs->rtp, rs, rc, RTP_PRIV_RTP);
+ rc = osmo_fd_register(&rs->rtp.bfd);
+ if (rc < 0)
+ goto out_rtp_socket;
+
+ rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (rc < 0)
+ goto out_rtp_bfd;
+
+ init_rss(&rs->rtcp, rs, rc, RTP_PRIV_RTCP);
+ rc = osmo_fd_register(&rs->rtcp.bfd);
+ if (rc < 0)
+ goto out_rtcp_socket;
+
+ DEBUGPC(DLMUX, "success\n");
+
+ rc = rtp_socket_bind(rs, INADDR_ANY);
+ if (rc < 0)
+ goto out_rtcp_bfd;
+
+ return rs;
+
+out_rtcp_bfd:
+ osmo_fd_unregister(&rs->rtcp.bfd);
+out_rtcp_socket:
+ close(rs->rtcp.bfd.fd);
+out_rtp_bfd:
+ osmo_fd_unregister(&rs->rtp.bfd);
+out_rtp_socket:
+ close(rs->rtp.bfd.fd);
+out_free:
+ talloc_free(rs);
+ DEBUGPC(DLMUX, "failed\n");
+ return NULL;
+}
+
+static int rtp_sub_socket_bind(struct rtp_sub_socket *rss, uint32_t ip,
+ uint16_t port)
+{
+ int rc;
+ socklen_t alen = sizeof(rss->sin_local);
+
+ rss->sin_local.sin_family = AF_INET;
+ rss->sin_local.sin_addr.s_addr = htonl(ip);
+ rss->sin_local.sin_port = htons(port);
+ rss->bfd.when |= BSC_FD_READ;
+
+ rc = bind(rss->bfd.fd, (struct sockaddr *)&rss->sin_local,
+ sizeof(rss->sin_local));
+ if (rc < 0)
+ return rc;
+
+ /* retrieve the address we actually bound to, in case we
+ * passed INADDR_ANY as IP address */
+ return getsockname(rss->bfd.fd, (struct sockaddr *)&rss->sin_local,
+ &alen);
+}
+
+#define RTP_PORT_BASE 30000
+static unsigned int next_udp_port = RTP_PORT_BASE;
+
+/*! \brief bind a RTP socket to a specific local address
+ * \param[in] rs RTP socket to be bound
+ * \param[in] ip local IP address to which socket is to be bound
+ */
+int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip)
+{
+ int rc = -EIO;
+ struct in_addr ia;
+
+ ia.s_addr = htonl(ip);
+ DEBUGP(DLMUX, "rtp_socket_bind(rs=%p, IP=%s): ", rs,
+ inet_ntoa(ia));
+
+ /* try to bind to a consecutive pair of ports */
+ for (next_udp_port = next_udp_port % 0xffff;
+ next_udp_port < 0xffff; next_udp_port += 2) {
+ rc = rtp_sub_socket_bind(&rs->rtp, ip, next_udp_port);
+ if (rc != 0)
+ continue;
+
+ rc = rtp_sub_socket_bind(&rs->rtcp, ip, next_udp_port+1);
+ if (rc == 0)
+ break;
+ }
+ if (rc < 0) {
+ DEBUGPC(DLMUX, "failed\n");
+ return rc;
+ }
+
+ ia.s_addr = rs->rtp.sin_local.sin_addr.s_addr;
+ DEBUGPC(DLMUX, "BOUND_IP=%s, BOUND_PORT=%u\n",
+ inet_ntoa(ia), ntohs(rs->rtp.sin_local.sin_port));
+ return ntohs(rs->rtp.sin_local.sin_port);
+}
+
+static int rtp_sub_socket_connect(struct rtp_sub_socket *rss,
+ uint32_t ip, uint16_t port)
+{
+ int rc;
+ socklen_t alen = sizeof(rss->sin_local);
+
+ rss->sin_remote.sin_family = AF_INET;
+ rss->sin_remote.sin_addr.s_addr = htonl(ip);
+ rss->sin_remote.sin_port = htons(port);
+
+ rc = connect(rss->bfd.fd, (struct sockaddr *) &rss->sin_remote,
+ sizeof(rss->sin_remote));
+ if (rc < 0)
+ return rc;
+
+ return getsockname(rss->bfd.fd, (struct sockaddr *)&rss->sin_local,
+ &alen);
+}
+
+/*! \brief 'connect' a RTP socket to a remote peer
+ * \param[in] rs RTP socket to be connected
+ * \param[in] ip remote IP address to which to connect
+ * \param[in] port remote UDP port number to which to connect
+ */
+int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port)
+{
+ int rc;
+ struct in_addr ia;
+
+ ia.s_addr = htonl(ip);
+ DEBUGP(DLMUX, "rtp_socket_connect(rs=%p, ip=%s, port=%u)\n",
+ rs, inet_ntoa(ia), port);
+
+ rc = rtp_sub_socket_connect(&rs->rtp, ip, port);
+ if (rc < 0)
+ return rc;
+
+ return rtp_sub_socket_connect(&rs->rtcp, ip, port+1);
+}
+
+/*! \brief bind two RTP/RTCP sockets together in the proxy
+ * \param[in] this First RTP socket
+ * \param[in] other Second RTP socket
+ */
+int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other)
+{
+ DEBUGP(DLMUX, "rtp_socket_proxy(this=%p, other=%p)\n",
+ this, other);
+
+ this->rx_action = RTP_PROXY;
+ this->proxy.other_sock = other;
+
+ other->rx_action = RTP_PROXY;
+ other->proxy.other_sock = this;
+
+ return 0;
+}
+
+/*! \brief bind RTP/RTCP socket to application, disabling proxy
+ * \param[in] this RTP socket
+ * \param[in] net gsm_network argument to trau_tx_to_mncc()
+ * \param[in] callref callref argument to trau_tx_to_mncc()
+ */
+int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net,
+ uint32_t callref)
+{
+ DEBUGP(DLMUX, "rtp_socket_proxy(this=%p, callref=%u)\n",
+ this, callref);
+
+ if (callref) {
+ this->rx_action = RTP_RECV_UPSTREAM;
+ this->receive.net = net;
+ this->receive.callref = callref;
+ } else
+ this->rx_action = RTP_NONE;
+
+ return 0;
+}
+
+static void free_tx_queue(struct rtp_sub_socket *rss)
+{
+ struct msgb *msg;
+
+ while ((msg = msgb_dequeue(&rss->tx_queue)))
+ msgb_free(msg);
+}
+
+/*! \brief Free/release a previously allocated RTP socket
+ * \param[in[] rs RTP/RTCP socket to be released
+ */
+int rtp_socket_free(struct rtp_socket *rs)
+{
+ DEBUGP(DLMUX, "rtp_socket_free(rs=%p)\n", rs);
+
+ /* make sure we don't leave references dangling to us */
+ if (rs->rx_action == RTP_PROXY &&
+ rs->proxy.other_sock)
+ rs->proxy.other_sock->proxy.other_sock = NULL;
+
+ osmo_fd_unregister(&rs->rtp.bfd);
+ close(rs->rtp.bfd.fd);
+ free_tx_queue(&rs->rtp);
+
+ osmo_fd_unregister(&rs->rtcp.bfd);
+ close(rs->rtcp.bfd.fd);
+ free_tx_queue(&rs->rtcp);
+
+ talloc_free(rs);
+
+ return 0;
+}
+
+static int rtp_handle_lchan_signal(unsigned int subsys, unsigned int signal,
+ void *handler_data, void *signal_data)
+{
+ struct gsm_lchan *lchan;
+ struct lchan_signal_data *lchan_data;
+
+ if (subsys != SS_LCHAN)
+ return 0;
+
+
+ lchan_data = signal_data;
+ if (!lchan_data->lchan || !lchan_data->lchan->conn)
+ return 0;
+
+ lchan = lchan_data->lchan;
+
+ switch (signal) {
+ case S_LCHAN_RTP_SOCKET_FREE:
+ rtp_socket_free(lchan->abis_ip.rtp_socket);
+ break;
+ }
+
+ return 0;
+}
+
+static __attribute__((constructor)) void on_dso_load_rtp_proxy(void)
+{
+ osmo_signal_register_handler(SS_LCHAN, rtp_handle_lchan_signal, NULL);
+}
diff --git a/openbsc/src/libtrau/Makefile.am b/openbsc/src/libtrau/Makefile.am
index 0c8cf17..7b71417 100644
--- a/openbsc/src/libtrau/Makefile.am
+++ b/openbsc/src/libtrau/Makefile.am
@@ -4,4 +4,4 @@ AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOABIS_LIBS) $(COVERA
noinst_LIBRARIES = libtrau.a
-libtrau_a_SOURCES = rtp_proxy.c trau_mux.c trau_upqueue.c
+libtrau_a_SOURCES = trau_mux.c trau_upqueue.c
diff --git a/openbsc/src/libtrau/rtp_proxy.c b/openbsc/src/libtrau/rtp_proxy.c
deleted file mode 100644
index c011765..0000000
--- a/openbsc/src/libtrau/rtp_proxy.c
+++ /dev/null
@@ -1,816 +0,0 @@
-/* RTP proxy handling for ip.access nanoBTS */
-
-/* (C) 2009-2013 by Harald Welte <laforge(a)gnumonks.org>
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/time.h> /* gettimeofday() */
-#include <unistd.h> /* get..() */
-#include <time.h> /* clock() */
-#include <sys/utsname.h> /* uname() */
-
-#include <osmocom/core/talloc.h>
-#include <openbsc/gsm_data.h>
-#include <osmocom/core/msgb.h>
-#include <osmocom/core/select.h>
-#include <openbsc/debug.h>
-#include <openbsc/rtp_proxy.h>
-#include <openbsc/mncc.h>
-#include <openbsc/trau_upqueue.h>
-
-/* attempt to determine byte order */
-#include <sys/param.h>
-#include <limits.h>
-
-#ifndef __BYTE_ORDER
-# ifdef __APPLE__
-# define __BYTE_ORDER __DARWIN_BYTE_ORDER
-# define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
-# define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
-# else
-# error "__BYTE_ORDER should be defined by someone"
-# endif
-#endif
-
-static LLIST_HEAD(rtp_sockets);
-
-/* should we mangle the CNAME inside SDES of RTCP packets? We disable
- * this by default, as it seems to be not needed */
-static int mangle_rtcp_cname = 0;
-
-enum rtp_bfd_priv {
- RTP_PRIV_NONE,
- RTP_PRIV_RTP,
- RTP_PRIV_RTCP
-};
-
-#define RTP_ALLOC_SIZE 1500
-
-/* according to RFC 1889 */
-struct rtcp_hdr {
- uint8_t byte0;
- uint8_t type;
- uint16_t length;
-} __attribute__((packed));
-
-#define RTCP_TYPE_SDES 202
-
-#define RTCP_IE_CNAME 1
-
-/* according to RFC 3550 */
-struct rtp_hdr {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- uint8_t csrc_count:4,
- extension:1,
- padding:1,
- version:2;
- uint8_t payload_type:7,
- marker:1;
-#elif __BYTE_ORDER == __BIG_ENDIAN
- uint8_t version:2,
- padding:1,
- extension:1,
- csrc_count:4;
- uint8_t marker:1,
- payload_type:7;
-#endif
- uint16_t sequence;
- uint32_t timestamp;
- uint32_t ssrc;
-} __attribute__((packed));
-
-struct rtp_x_hdr {
- uint16_t by_profile;
- uint16_t length;
-} __attribute__((packed));
-
-#define RTP_VERSION 2
-
-/* decode an rtp frame and create a new buffer with payload */
-static int rtp_decode(struct msgb *msg, uint32_t callref, struct msgb **data)
-{
- struct msgb *new_msg;
- struct gsm_data_frame *frame;
- struct rtp_hdr *rtph = (struct rtp_hdr *)msg->data;
- struct rtp_x_hdr *rtpxh;
- uint8_t *payload;
- int payload_len;
- int msg_type;
- int x_len;
-
- if (msg->len < 12) {
- DEBUGPC(DLMUX, "received RTP frame too short (len = %d)\n",
- msg->len);
- return -EINVAL;
- }
- if (rtph->version != RTP_VERSION) {
- DEBUGPC(DLMUX, "received RTP version %d not supported.\n",
- rtph->version);
- return -EINVAL;
- }
- payload = msg->data + sizeof(struct rtp_hdr) + (rtph->csrc_count << 2);
- payload_len = msg->len - sizeof(struct rtp_hdr) - (rtph->csrc_count << 2);
- if (payload_len < 0) {
- DEBUGPC(DLMUX, "received RTP frame too short (len = %d, "
- "csrc count = %d)\n", msg->len, rtph->csrc_count);
- return -EINVAL;
- }
- if (rtph->extension) {
- if (payload_len < sizeof(struct rtp_x_hdr)) {
- DEBUGPC(DLMUX, "received RTP frame too short for "
- "extension header\n");
- return -EINVAL;
- }
- rtpxh = (struct rtp_x_hdr *)payload;
- x_len = ntohs(rtpxh->length) * 4 + sizeof(struct rtp_x_hdr);
- payload += x_len;
- payload_len -= x_len;
- if (payload_len < 0) {
- DEBUGPC(DLMUX, "received RTP frame too short, "
- "extension header exceeds frame length\n");
- return -EINVAL;
- }
- }
- if (rtph->padding) {
- if (payload_len < 1) {
- DEBUGPC(DLMUX, "received RTP frame too short for "
- "padding length\n");
- return -EINVAL;
- }
- payload_len -= payload[payload_len - 1];
- if (payload_len < 0) {
- DEBUGPC(DLMUX, "received RTP frame with padding "
- "greater than payload\n");
- return -EINVAL;
- }
- }
-
- switch (rtph->payload_type) {
- case RTP_PT_GSM_FULL:
- msg_type = GSM_TCHF_FRAME;
- if (payload_len != RTP_LEN_GSM_FULL) {
- DEBUGPC(DLMUX, "received RTP full rate frame with "
- "payload length != %d (len = %d)\n",
- RTP_LEN_GSM_FULL, payload_len);
- return -EINVAL;
- }
- break;
- case RTP_PT_GSM_EFR:
- msg_type = GSM_TCHF_FRAME_EFR;
- if (payload_len != RTP_LEN_GSM_EFR) {
- DEBUGPC(DLMUX, "received RTP extended full rate frame "
- "with payload length != %d (len = %d)\n",
- RTP_LEN_GSM_EFR, payload_len);
- return -EINVAL;
- }
- break;
- case RTP_PT_GSM_HALF:
- msg_type = GSM_TCHH_FRAME;
- if (payload_len != RTP_LEN_GSM_HALF) {
- DEBUGPC(DLMUX, "received RTP half rate frame with "
- "payload length != %d (len = %d)\n",
- RTP_LEN_GSM_HALF, payload_len);
- return -EINVAL;
- }
- break;
- case RTP_PT_AMR:
- break;
- default:
- DEBUGPC(DLMUX, "received RTP frame with unknown payload "
- "type %d\n", rtph->payload_type);
- return -EINVAL;
- }
-
- if (rtph->payload_type == RTP_PT_AMR) {
- new_msg = msgb_alloc(sizeof(struct gsm_data_frame) + 1
- + payload_len, "GSM-DATA");
- } else {
- new_msg = msgb_alloc(sizeof(struct gsm_data_frame)
- + payload_len, "GSM-DATA");
- }
- if (!new_msg)
- return -ENOMEM;
- frame = (struct gsm_data_frame *)(new_msg->data);
- frame->msg_type = msg_type;
- frame->callref = callref;
- if (rtph->payload_type == RTP_PT_AMR) {
- frame->data[0] = payload_len;
- msgb_put(new_msg, sizeof(struct gsm_data_frame) + 1
- + payload_len);
- memcpy(frame->data + 1, payload, payload_len);
- } else {
- msgb_put(new_msg, sizeof(struct gsm_data_frame) + payload_len);
- memcpy(frame->data, payload, payload_len);
- }
-
- *data = new_msg;
- return 0;
-}
-
-/* "to - from" */
-static void tv_difference(struct timeval *diff, const struct timeval *from,
- const struct timeval *__to)
-{
- struct timeval _to = *__to, *to = &_to;
-
- if (to->tv_usec < from->tv_usec) {
- to->tv_sec -= 1;
- to->tv_usec += 1000000;
- }
-
- diff->tv_usec = to->tv_usec - from->tv_usec;
- diff->tv_sec = to->tv_sec - from->tv_sec;
-}
-
-/*! \brief encode and send a rtp frame
- * \param[in] rs RTP socket through which we shall send
- * \param[in] frame GSM RTP frame to be sent
- */
-int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame)
-{
- struct rtp_sub_socket *rss = &rs->rtp;
- struct msgb *msg;
- struct rtp_hdr *rtph;
- int payload_type;
- int payload_len;
- int duration; /* in samples */
- int is_bfi = 0;
-
- if (rs->tx_action != RTP_SEND_DOWNSTREAM) {
- /* initialize sequences */
- rs->tx_action = RTP_SEND_DOWNSTREAM;
- rs->transmit.ssrc = rand();
- rs->transmit.sequence = random();
- rs->transmit.timestamp = random();
- }
-
- switch (frame->msg_type) {
- case GSM_TCHF_FRAME:
- payload_type = RTP_PT_GSM_FULL;
- payload_len = RTP_LEN_GSM_FULL;
- duration = RTP_GSM_DURATION;
- break;
- case GSM_TCHF_FRAME_EFR:
- payload_type = RTP_PT_GSM_EFR;
- payload_len = RTP_LEN_GSM_EFR;
- duration = RTP_GSM_DURATION;
- break;
- case GSM_TCHH_FRAME:
- payload_type = RTP_PT_GSM_HALF;
- payload_len = RTP_LEN_GSM_HALF;
- duration = RTP_GSM_DURATION;
- break;
- case GSM_TCH_FRAME_AMR:
- payload_type = RTP_PT_AMR;
- payload_len = frame->data[0];
- duration = RTP_GSM_DURATION;
- break;
- case GSM_BAD_FRAME:
- payload_type = 0;
- payload_len = 0;
- duration = RTP_GSM_DURATION;
- is_bfi = 1;
- break;
- default:
- DEBUGPC(DLMUX, "unsupported message type %d\n",
- frame->msg_type);
- return -EINVAL;
- }
-
- {
- struct timeval tv, tv_diff;
- long int usec_diff, frame_diff;
-
- gettimeofday(&tv, NULL);
- tv_difference(&tv_diff, &rs->transmit.last_tv, &tv);
- rs->transmit.last_tv = tv;
-
- usec_diff = tv_diff.tv_sec * 1000000 + tv_diff.tv_usec;
- frame_diff = (usec_diff / 20000);
-
- if (abs(frame_diff) > 1) {
- long int frame_diff_excess = frame_diff - 1;
-
- LOGP(DLMUX, LOGL_NOTICE,
- "Correcting frame difference of %ld frames\n", frame_diff_excess);
- rs->transmit.sequence += frame_diff_excess;
- rs->transmit.timestamp += frame_diff_excess * duration;
- }
- }
-
- if (is_bfi) {
- /* In case of a bad frame, just count and drop packt. */
- rs->transmit.timestamp += duration;
- rs->transmit.sequence++;
- return 0;
- }
-
- msg = msgb_alloc(sizeof(struct rtp_hdr) + payload_len, "RTP-GSM-FULL");
- if (!msg)
- return -ENOMEM;
- rtph = (struct rtp_hdr *)msg->data;
- rtph->version = RTP_VERSION;
- rtph->padding = 0;
- rtph->extension = 0;
- rtph->csrc_count = 0;
- rtph->marker = 0;
- rtph->payload_type = payload_type;
- rtph->sequence = htons(rs->transmit.sequence++);
- rtph->timestamp = htonl(rs->transmit.timestamp);
- rs->transmit.timestamp += duration;
- rtph->ssrc = htonl(rs->transmit.ssrc);
- if (frame->msg_type == GSM_TCH_FRAME_AMR) {
- memcpy(msg->data + sizeof(struct rtp_hdr), frame->data + 1,
- payload_len);
- } else {
- memcpy(msg->data + sizeof(struct rtp_hdr), frame->data,
- payload_len);
- }
- msgb_put(msg, sizeof(struct rtp_hdr) + payload_len);
- msgb_enqueue(&rss->tx_queue, msg);
- rss->bfd.when |= BSC_FD_WRITE;
-
- return 0;
-}
-
-/* iterate over all chunks in one RTCP message, look for CNAME IEs and
- * replace all of those with 'new_cname' */
-static int rtcp_sdes_cname_mangle(struct msgb *msg, struct rtcp_hdr *rh,
- uint16_t *rtcp_len, const char *new_cname)
-{
- uint8_t *rtcp_end;
- uint8_t *cur = (uint8_t *) rh;
- uint8_t tag, len = 0;
-
- rtcp_end = cur + *rtcp_len;
- /* move cur to end of RTP header */
- cur += sizeof(*rh);
-
- /* iterate over Chunks */
- while (cur+4 < rtcp_end) {
- /* skip four bytes SSRC/CSRC */
- cur += 4;
-
- /* iterate over IE's inside the chunk */
- while (cur+1 < rtcp_end) {
- tag = *cur++;
- if (tag == 0) {
- /* end of chunk, skip additional zero */
- while (*cur++ == 0) { }
- break;
- }
- len = *cur++;
-
- if (tag == RTCP_IE_CNAME) {
- /* we've found the CNAME, lets mangle it */
- if (len < strlen(new_cname)) {
- /* we need to make more space */
- int increase = strlen(new_cname) - len;
-
- msgb_push(msg, increase);
- memmove(cur+len+increase, cur+len,
- rtcp_end - (cur+len));
- /* FIXME: we have to respect RTCP
- * padding/alignment rules! */
- len += increase;
- *(cur-1) += increase;
- rtcp_end += increase;
- *rtcp_len += increase;
- }
- /* copy new CNAME into message */
- memcpy(cur, new_cname, strlen(new_cname));
- /* FIXME: zero the padding in case new CNAME
- * is smaller than old one !!! */
- }
- cur += len;
- }
- }
-
- return 0;
-}
-
-static int rtcp_mangle(struct msgb *msg, struct rtp_socket *rs)
-{
- struct rtp_sub_socket *rss = &rs->rtcp;
- struct rtcp_hdr *rtph;
- uint16_t old_len;
- int rc;
-
- if (!mangle_rtcp_cname)
- return 0;
-
- printf("RTCP\n");
- /* iterate over list of RTCP messages */
- rtph = (struct rtcp_hdr *)msg->data;
- while ((void *)rtph + sizeof(*rtph) <= (void *)msg->data + msg->len) {
- old_len = (ntohs(rtph->length) + 1) * 4;
- if ((void *)rtph + old_len > (void *)msg->data + msg->len) {
- DEBUGPC(DLMUX, "received RTCP packet too short for "
- "length element\n");
- return -EINVAL;
- }
- if (rtph->type == RTCP_TYPE_SDES) {
- char new_cname[255];
- strncpy(new_cname, inet_ntoa(rss->sin_local.sin_addr),
- sizeof(new_cname));
- new_cname[sizeof(new_cname)-1] = '\0';
- rc = rtcp_sdes_cname_mangle(msg, rtph, &old_len,
- new_cname);
- if (rc < 0)
- return rc;
- }
- rtph = (void *)rtph + old_len;
- }
-
- return 0;
-}
-
-/* read from incoming RTP/RTCP socket */
-static int rtp_socket_read(struct rtp_socket *rs, struct rtp_sub_socket *rss)
-{
- int rc;
- struct msgb *msg = msgb_alloc(RTP_ALLOC_SIZE, "RTP/RTCP");
- struct msgb *new_msg;
- struct rtp_sub_socket *other_rss;
-
- if (!msg)
- return -ENOMEM;
-
- rc = read(rss->bfd.fd, msg->data, RTP_ALLOC_SIZE);
- if (rc <= 0) {
- rss->bfd.when &= ~BSC_FD_READ;
- return rc;
- }
-
- msgb_put(msg, rc);
-
- switch (rs->rx_action) {
- case RTP_PROXY:
- if (!rs->proxy.other_sock) {
- rc = -EIO;
- goto out_free;
- }
- if (rss->bfd.priv_nr == RTP_PRIV_RTP)
- other_rss = &rs->proxy.other_sock->rtp;
- else if (rss->bfd.priv_nr == RTP_PRIV_RTCP) {
- other_rss = &rs->proxy.other_sock->rtcp;
- /* modify RTCP SDES CNAME */
- rc = rtcp_mangle(msg, rs);
- if (rc < 0)
- goto out_free;
- } else {
- rc = -EINVAL;
- goto out_free;
- }
- msgb_enqueue(&other_rss->tx_queue, msg);
- other_rss->bfd.when |= BSC_FD_WRITE;
- break;
-
- case RTP_RECV_UPSTREAM:
- if (!rs->receive.callref || !rs->receive.net) {
- rc = -EIO;
- goto out_free;
- }
- if (rss->bfd.priv_nr == RTP_PRIV_RTCP) {
- if (!mangle_rtcp_cname) {
- msgb_free(msg);
- break;
- }
- /* modify RTCP SDES CNAME */
- rc = rtcp_mangle(msg, rs);
- if (rc < 0)
- goto out_free;
- msgb_enqueue(&rss->tx_queue, msg);
- rss->bfd.when |= BSC_FD_WRITE;
- break;
- }
- if (rss->bfd.priv_nr != RTP_PRIV_RTP) {
- rc = -EINVAL;
- goto out_free;
- }
- rc = rtp_decode(msg, rs->receive.callref, &new_msg);
- if (rc < 0)
- goto out_free;
- msgb_free(msg);
- trau_tx_to_mncc(rs->receive.net, new_msg);
- break;
-
- case RTP_NONE: /* if socket exists, but disabled by app */
- msgb_free(msg);
- break;
- }
-
- return 0;
-
-out_free:
- msgb_free(msg);
- return rc;
-}
-
-/* \brief write from tx_queue to RTP/RTCP socket */
-static int rtp_socket_write(struct rtp_socket *rs, struct rtp_sub_socket *rss)
-{
- struct msgb *msg;
- int written;
-
- msg = msgb_dequeue(&rss->tx_queue);
- if (!msg) {
- rss->bfd.when &= ~BSC_FD_WRITE;
- return 0;
- }
-
- written = write(rss->bfd.fd, msg->data, msg->len);
- if (written < msg->len) {
- LOGP(DLMIB, LOGL_ERROR, "short write");
- msgb_free(msg);
- return -EIO;
- }
-
- msgb_free(msg);
-
- return 0;
-}
-
-
-/*! \brief callback for the select.c:bfd_* layer */
-static int rtp_bfd_cb(struct osmo_fd *bfd, unsigned int flags)
-{
- struct rtp_socket *rs = bfd->data;
- struct rtp_sub_socket *rss;
-
- switch (bfd->priv_nr) {
- case RTP_PRIV_RTP:
- rss = &rs->rtp;
- break;
- case RTP_PRIV_RTCP:
- rss = &rs->rtcp;
- break;
- default:
- return -EINVAL;
- }
-
- if (flags & BSC_FD_READ)
- rtp_socket_read(rs, rss);
-
- if (flags & BSC_FD_WRITE)
- rtp_socket_write(rs, rss);
-
- return 0;
-}
-
-/*! \brief initialize one rtp sub-socket */
-static void init_rss(struct rtp_sub_socket *rss,
- struct rtp_socket *rs, int fd, int priv_nr)
-{
- /* initialize bfd */
- rss->bfd.fd = fd;
- rss->bfd.data = rs;
- rss->bfd.priv_nr = priv_nr;
- rss->bfd.cb = rtp_bfd_cb;
-}
-
-/*! \brief create a new RTP/RTCP socket and bind it */
-struct rtp_socket *rtp_socket_create(void)
-{
- int rc;
- struct rtp_socket *rs;
-
- DEBUGP(DLMUX, "rtp_socket_create(): ");
-
- rs = talloc_zero(tall_bsc_ctx, struct rtp_socket);
- if (!rs)
- return NULL;
-
- INIT_LLIST_HEAD(&rs->rtp.tx_queue);
- INIT_LLIST_HEAD(&rs->rtcp.tx_queue);
-
- rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (rc < 0)
- goto out_free;
-
- init_rss(&rs->rtp, rs, rc, RTP_PRIV_RTP);
- rc = osmo_fd_register(&rs->rtp.bfd);
- if (rc < 0)
- goto out_rtp_socket;
-
- rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (rc < 0)
- goto out_rtp_bfd;
-
- init_rss(&rs->rtcp, rs, rc, RTP_PRIV_RTCP);
- rc = osmo_fd_register(&rs->rtcp.bfd);
- if (rc < 0)
- goto out_rtcp_socket;
-
- DEBUGPC(DLMUX, "success\n");
-
- rc = rtp_socket_bind(rs, INADDR_ANY);
- if (rc < 0)
- goto out_rtcp_bfd;
-
- return rs;
-
-out_rtcp_bfd:
- osmo_fd_unregister(&rs->rtcp.bfd);
-out_rtcp_socket:
- close(rs->rtcp.bfd.fd);
-out_rtp_bfd:
- osmo_fd_unregister(&rs->rtp.bfd);
-out_rtp_socket:
- close(rs->rtp.bfd.fd);
-out_free:
- talloc_free(rs);
- DEBUGPC(DLMUX, "failed\n");
- return NULL;
-}
-
-static int rtp_sub_socket_bind(struct rtp_sub_socket *rss, uint32_t ip,
- uint16_t port)
-{
- int rc;
- socklen_t alen = sizeof(rss->sin_local);
-
- rss->sin_local.sin_family = AF_INET;
- rss->sin_local.sin_addr.s_addr = htonl(ip);
- rss->sin_local.sin_port = htons(port);
- rss->bfd.when |= BSC_FD_READ;
-
- rc = bind(rss->bfd.fd, (struct sockaddr *)&rss->sin_local,
- sizeof(rss->sin_local));
- if (rc < 0)
- return rc;
-
- /* retrieve the address we actually bound to, in case we
- * passed INADDR_ANY as IP address */
- return getsockname(rss->bfd.fd, (struct sockaddr *)&rss->sin_local,
- &alen);
-}
-
-#define RTP_PORT_BASE 30000
-static unsigned int next_udp_port = RTP_PORT_BASE;
-
-/*! \brief bind a RTP socket to a specific local address
- * \param[in] rs RTP socket to be bound
- * \param[in] ip local IP address to which socket is to be bound
- */
-int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip)
-{
- int rc = -EIO;
- struct in_addr ia;
-
- ia.s_addr = htonl(ip);
- DEBUGP(DLMUX, "rtp_socket_bind(rs=%p, IP=%s): ", rs,
- inet_ntoa(ia));
-
- /* try to bind to a consecutive pair of ports */
- for (next_udp_port = next_udp_port % 0xffff;
- next_udp_port < 0xffff; next_udp_port += 2) {
- rc = rtp_sub_socket_bind(&rs->rtp, ip, next_udp_port);
- if (rc != 0)
- continue;
-
- rc = rtp_sub_socket_bind(&rs->rtcp, ip, next_udp_port+1);
- if (rc == 0)
- break;
- }
- if (rc < 0) {
- DEBUGPC(DLMUX, "failed\n");
- return rc;
- }
-
- ia.s_addr = rs->rtp.sin_local.sin_addr.s_addr;
- DEBUGPC(DLMUX, "BOUND_IP=%s, BOUND_PORT=%u\n",
- inet_ntoa(ia), ntohs(rs->rtp.sin_local.sin_port));
- return ntohs(rs->rtp.sin_local.sin_port);
-}
-
-static int rtp_sub_socket_connect(struct rtp_sub_socket *rss,
- uint32_t ip, uint16_t port)
-{
- int rc;
- socklen_t alen = sizeof(rss->sin_local);
-
- rss->sin_remote.sin_family = AF_INET;
- rss->sin_remote.sin_addr.s_addr = htonl(ip);
- rss->sin_remote.sin_port = htons(port);
-
- rc = connect(rss->bfd.fd, (struct sockaddr *) &rss->sin_remote,
- sizeof(rss->sin_remote));
- if (rc < 0)
- return rc;
-
- return getsockname(rss->bfd.fd, (struct sockaddr *)&rss->sin_local,
- &alen);
-}
-
-/*! \brief 'connect' a RTP socket to a remote peer
- * \param[in] rs RTP socket to be connected
- * \param[in] ip remote IP address to which to connect
- * \param[in] port remote UDP port number to which to connect
- */
-int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port)
-{
- int rc;
- struct in_addr ia;
-
- ia.s_addr = htonl(ip);
- DEBUGP(DLMUX, "rtp_socket_connect(rs=%p, ip=%s, port=%u)\n",
- rs, inet_ntoa(ia), port);
-
- rc = rtp_sub_socket_connect(&rs->rtp, ip, port);
- if (rc < 0)
- return rc;
-
- return rtp_sub_socket_connect(&rs->rtcp, ip, port+1);
-}
-
-/*! \brief bind two RTP/RTCP sockets together in the proxy
- * \param[in] this First RTP socket
- * \param[in] other Second RTP socket
- */
-int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other)
-{
- DEBUGP(DLMUX, "rtp_socket_proxy(this=%p, other=%p)\n",
- this, other);
-
- this->rx_action = RTP_PROXY;
- this->proxy.other_sock = other;
-
- other->rx_action = RTP_PROXY;
- other->proxy.other_sock = this;
-
- return 0;
-}
-
-/*! \brief bind RTP/RTCP socket to application, disabling proxy
- * \param[in] this RTP socket
- * \param[in] net gsm_network argument to trau_tx_to_mncc()
- * \param[in] callref callref argument to trau_tx_to_mncc()
- */
-int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net,
- uint32_t callref)
-{
- DEBUGP(DLMUX, "rtp_socket_proxy(this=%p, callref=%u)\n",
- this, callref);
-
- if (callref) {
- this->rx_action = RTP_RECV_UPSTREAM;
- this->receive.net = net;
- this->receive.callref = callref;
- } else
- this->rx_action = RTP_NONE;
-
- return 0;
-}
-
-static void free_tx_queue(struct rtp_sub_socket *rss)
-{
- struct msgb *msg;
-
- while ((msg = msgb_dequeue(&rss->tx_queue)))
- msgb_free(msg);
-}
-
-/*! \brief Free/release a previously allocated RTP socket
- * \param[in[] rs RTP/RTCP socket to be released
- */
-int rtp_socket_free(struct rtp_socket *rs)
-{
- DEBUGP(DLMUX, "rtp_socket_free(rs=%p)\n", rs);
-
- /* make sure we don't leave references dangling to us */
- if (rs->rx_action == RTP_PROXY &&
- rs->proxy.other_sock)
- rs->proxy.other_sock->proxy.other_sock = NULL;
-
- osmo_fd_unregister(&rs->rtp.bfd);
- close(rs->rtp.bfd.fd);
- free_tx_queue(&rs->rtp);
-
- osmo_fd_unregister(&rs->rtcp.bfd);
- close(rs->rtcp.bfd.fd);
- free_tx_queue(&rs->rtcp);
-
- talloc_free(rs);
-
- return 0;
-}
--
1.8.1.5
--------------010802080805090906090602--
1
0
In order to free RTP socket when lchan_free() or lchan_reset() is called,
a signal is used between libbsc and rtp_proxy.
---
openbsc/include/openbsc/signal.h | 1 +
openbsc/src/libbsc/chan_alloc.c | 19 +++++++---------
openbsc/src/libmsc/Makefile.am | 3 ++-
openbsc/src/{libtrau => libmsc}/rtp_proxy.c | 35 +++++++++++++++++++++++++++++
openbsc/src/libtrau/Makefile.am | 2 +-
5 files changed, 47 insertions(+), 13 deletions(-)
rename openbsc/src/{libtrau => libmsc}/rtp_proxy.c (96%)
diff --git a/openbsc/include/openbsc/signal.h b/openbsc/include/openbsc/signal.h
index 39319f1..31c9187 100644
--- a/openbsc/include/openbsc/signal.h
+++ b/openbsc/include/openbsc/signal.h
@@ -105,6 +105,7 @@ enum signal_lchan {
enum signal_challoc {
S_CHALLOC_ALLOC_FAIL, /* allocation of lchan has failed */
S_CHALLOC_FREED, /* lchan has been successfully freed */
+ S_CHALLOC_RESET, /* lchan has been reset */
};
/* SS_SUBSCR signals */
diff --git a/openbsc/src/libbsc/chan_alloc.c b/openbsc/src/libbsc/chan_alloc.c
index 9b74329..18ffa93 100644
--- a/openbsc/src/libbsc/chan_alloc.c
+++ b/openbsc/src/libbsc/chan_alloc.c
@@ -310,13 +310,6 @@ void lchan_free(struct gsm_lchan *lchan)
osmo_signal_dispatch(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, &sig);
}
- if (lchan->abis_ip.rtp_socket) {
- LOGP(DRLL, LOGL_ERROR, "%s RTP Proxy Socket remained open.\n",
- gsm_lchan_name(lchan));
- rtp_socket_free(lchan->abis_ip.rtp_socket);
- lchan->abis_ip.rtp_socket = NULL;
- }
-
/* stop the timer */
osmo_timer_del(&lchan->T3101);
@@ -360,18 +353,22 @@ void lchan_free(struct gsm_lchan *lchan)
*/
void lchan_reset(struct gsm_lchan *lchan)
{
+ struct challoc_signal_data sig;
+
osmo_timer_del(&lchan->T3101);
osmo_timer_del(&lchan->T3109);
osmo_timer_del(&lchan->T3111);
osmo_timer_del(&lchan->error_timer);
+ memset(&sig, 0, sizeof(sig));
+ sig.type = lchan->type;
+
lchan->type = GSM_LCHAN_NONE;
lchan->state = LCHAN_S_NONE;
- if (lchan->abis_ip.rtp_socket) {
- rtp_socket_free(lchan->abis_ip.rtp_socket);
- lchan->abis_ip.rtp_socket = NULL;
- }
+ sig.lchan = lchan;
+ sig.bts = lchan->ts->trx->bts;
+ osmo_signal_dispatch(SS_CHALLOC, S_CHALLOC_RESET, &sig);
}
/* Drive the release process of the lchan */
diff --git a/openbsc/src/libmsc/Makefile.am b/openbsc/src/libmsc/Makefile.am
index 24db2c2..4d44a62 100644
--- a/openbsc/src/libmsc/Makefile.am
+++ b/openbsc/src/libmsc/Makefile.am
@@ -17,7 +17,8 @@ libmsc_a_SOURCES = auth.c \
ussd.c \
vty_interface_layer3.c \
transaction.c \
- osmo_msc.c ctrl_commands.c
+ osmo_msc.c ctrl_commands.c \
+ rtp_proxy.c
if BUILD_SMPP
noinst_HEADERS = smpp_smsc.h
diff --git a/openbsc/src/libtrau/rtp_proxy.c b/openbsc/src/libmsc/rtp_proxy.c
similarity index 96%
rename from openbsc/src/libtrau/rtp_proxy.c
rename to openbsc/src/libmsc/rtp_proxy.c
index 82d50ae..b86d228 100644
--- a/openbsc/src/libtrau/rtp_proxy.c
+++ b/openbsc/src/libmsc/rtp_proxy.c
@@ -36,6 +36,7 @@
#include <openbsc/rtp_proxy.h>
#include <openbsc/mncc.h>
#include <openbsc/trau_upqueue.h>
+#include <openbsc/signal.h>
/* attempt to determine byte order */
#include <sys/param.h>
@@ -830,3 +831,37 @@ int rtp_socket_free(struct rtp_socket *rs)
return 0;
}
+
+static int rtp_handle_challoc_signal(unsigned int subsys, unsigned int signal,
+ void *handler_data, void *signal_data)
+{
+ struct gsm_lchan *lchan;
+ struct challoc_signal_data *sig;
+
+ if (subsys != SS_CHALLOC)
+ return 0;
+
+
+ sig = signal_data;
+ if (!sig->lchan || !sig->lchan->conn)
+ return 0;
+
+ lchan = sig->lchan;
+
+ switch (signal) {
+ case S_CHALLOC_FREED:
+ case S_CHALLOC_RESET:
+ if (lchan->abis_ip.rtp_socket) {
+ rtp_socket_free(lchan->abis_ip.rtp_socket);
+ lchan->abis_ip.rtp_socket = NULL;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+static __attribute__((constructor)) void on_dso_load_rtp_proxy(void)
+{
+ osmo_signal_register_handler(SS_CHALLOC, rtp_handle_challoc_signal, NULL);
+}
diff --git a/openbsc/src/libtrau/Makefile.am b/openbsc/src/libtrau/Makefile.am
index 0c8cf17..7b71417 100644
--- a/openbsc/src/libtrau/Makefile.am
+++ b/openbsc/src/libtrau/Makefile.am
@@ -4,4 +4,4 @@ AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOABIS_LIBS) $(COVERA
noinst_LIBRARIES = libtrau.a
-libtrau_a_SOURCES = rtp_proxy.c trau_mux.c trau_upqueue.c
+libtrau_a_SOURCES = trau_mux.c trau_upqueue.c
--
1.8.1.5
--------------040603060708080405050707--
1
0