aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-09-22 16:41:54 +0200
committerHarald Welte <laforge@gnumonks.org>2015-09-22 16:41:54 +0200
commitf1fb0fa3af174c605f60458388bba61ef4f40fa8 (patch)
tree006e46f78dee0ac14ffd321e0bfae344d8160096
parent329085a8ff2c1162a32eb617068fa5614efcde06 (diff)
parentcaa648d92e48a05e676e87b48c21cb0b151c9b4e (diff)
Merge branch '201509-trx-rebase'0.4.0
-rw-r--r--.gitignore3
-rw-r--r--configure.ac12
-rw-r--r--include/osmo-bts/bts_model.h2
-rw-r--r--include/osmo-bts/gsm_data.h7
-rw-r--r--include/osmo-bts/logging.h2
-rw-r--r--include/osmo-bts/rsl.h2
-rw-r--r--src/Makefile.am3
-rw-r--r--src/common/abis.c4
-rw-r--r--src/common/amr.c23
-rw-r--r--src/common/bts.c2
-rw-r--r--src/common/l1sap.c10
-rw-r--r--src/common/logging.c12
-rw-r--r--src/common/oml.c19
-rw-r--r--src/common/pcu_sock.c1
-rw-r--r--src/common/rsl.c12
-rw-r--r--src/common/vty.c5
-rw-r--r--src/osmo-bts-sysmo/l1_if.c5
-rw-r--r--src/osmo-bts-sysmo/main.c7
-rw-r--r--src/osmo-bts-sysmo/oml.c19
-rw-r--r--src/osmo-bts-trx/Makefile.am11
-rw-r--r--src/osmo-bts-trx/amr.c81
-rw-r--r--src/osmo-bts-trx/amr.h8
-rw-r--r--src/osmo-bts-trx/gsm0503_coding.c1696
-rw-r--r--src/osmo-bts-trx/gsm0503_coding.h53
-rw-r--r--src/osmo-bts-trx/gsm0503_conv.c950
-rw-r--r--src/osmo-bts-trx/gsm0503_conv.h26
-rw-r--r--src/osmo-bts-trx/gsm0503_interleaving.c144
-rw-r--r--src/osmo-bts-trx/gsm0503_interleaving.h11
-rw-r--r--src/osmo-bts-trx/gsm0503_mapping.c72
-rw-r--r--src/osmo-bts-trx/gsm0503_mapping.h10
-rw-r--r--src/osmo-bts-trx/gsm0503_parity.c103
-rw-r--r--src/osmo-bts-trx/gsm0503_parity.h12
-rw-r--r--src/osmo-bts-trx/gsm0503_tables.c193
-rw-r--r--src/osmo-bts-trx/gsm0503_tables.h19
-rw-r--r--src/osmo-bts-trx/l1_if.c716
-rw-r--r--src/osmo-bts-trx/l1_if.h179
-rw-r--r--src/osmo-bts-trx/loops.c339
-rw-r--r--src/osmo-bts-trx/loops.h31
-rw-r--r--src/osmo-bts-trx/main.c406
-rw-r--r--src/osmo-bts-trx/scheduler.c3044
-rw-r--r--src/osmo-bts-trx/scheduler.h43
-rw-r--r--src/osmo-bts-trx/trx_if.c560
-rw-r--r--src/osmo-bts-trx/trx_if.h35
-rw-r--r--src/osmo-bts-trx/trx_vty.c421
-rw-r--r--tests/Makefile.am10
-rw-r--r--tests/bursts/Makefile.am14
-rw-r--r--tests/bursts/bursts_test.c495
-rw-r--r--tests/bursts/bursts_test.ok21
-rw-r--r--tests/handover/Makefile.am8
-rw-r--r--tests/handover/handover_test.c278
-rw-r--r--tests/handover/handover_test.ok1
-rw-r--r--tests/stubs.c3
-rw-r--r--tests/sysmobts/sysmobts_test.c2
-rw-r--r--tests/testsuite.at12
54 files changed, 10123 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
index 8351349..8f6babc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ src/osmo-bts-sysmo/sysmobts
src/osmo-bts-sysmo/sysmobts-remote
src/osmo-bts-sysmo/sysmobts-mgr
+src/osmo-bts-trx/osmobts-trx
tests/atconfig
tests/package.m4
@@ -37,6 +38,8 @@ tests/paging/paging_test
tests/cipher/cipher_test
tests/sysmobts/sysmobts_test
tests/misc/misc_test
+tests/bursts/bursts_test
+tests/handover/handover_test
tests/testsuite
tests/testsuite.log
diff --git a/configure.ac b/configure.ac
index 641a6c9..5657663 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@ PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 0.3.3)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl)
PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis)
PKG_CHECK_MODULES(LIBGPS, libgps)
+PKG_CHECK_MODULES(LIBOSMOCODEC, libosmocodec)
AC_MSG_CHECKING([whether to enable sysmocom-bts hardware support])
AC_ARG_ENABLE(sysmocom-bts,
@@ -37,6 +38,14 @@ AC_ARG_ENABLE(sysmocom-bts,
AC_MSG_RESULT([$enable_sysmocom_bts])
AM_CONDITIONAL(ENABLE_SYSMOBTS, test "x$enable_sysmocom_bts" = "xyes")
+AC_MSG_CHECKING([whether to enable trx hardware support])
+AC_ARG_ENABLE(trx,
+ AC_HELP_STRING([--enable-trx],
+ [enable code for trx hardware [default=no]]),
+ [enable_trx="yes"],[enable_trx="no"])
+AC_MSG_RESULT([$enable_trx])
+AM_CONDITIONAL(ENABLE_TRX, test "x$enable_trx" = "xyes")
+
# We share gsm_data.h with OpenBSC and need to be pointed to the source
# directory of OpenBSC for now.
AC_ARG_WITH([openbsc],
@@ -70,6 +79,7 @@ AC_OUTPUT(
src/Makefile
src/common/Makefile
src/osmo-bts-sysmo/Makefile
+ src/osmo-bts-trx/Makefile
include/Makefile
include/osmo-bts/Makefile
tests/Makefile
@@ -78,4 +88,6 @@ AC_OUTPUT(
tests/cipher/Makefile
tests/sysmobts/Makefile
tests/misc/Makefile
+ tests/bursts/Makefile
+ tests/handover/Makefile
Makefile)
diff --git a/include/osmo-bts/bts_model.h b/include/osmo-bts/bts_model.h
index de84636..ecbfc3d 100644
--- a/include/osmo-bts/bts_model.h
+++ b/include/osmo-bts/bts_model.h
@@ -40,4 +40,6 @@ int bts_model_adjst_ms_pwr(struct gsm_lchan *lchan);
int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap);
+void bts_model_abis_close(struct gsm_bts *bts);
+
#endif
diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h
index bfa5285..06115b3 100644
--- a/include/osmo-bts/gsm_data.h
+++ b/include/osmo-bts/gsm_data.h
@@ -115,6 +115,13 @@ static inline struct femtol1_hdl *trx_femtol1_hdl(struct gsm_bts_trx *trx)
return trx->role_bts.l1h;
}
+struct trx_l1h;
+
+static inline struct trx_l1h *trx_l1h_hdl(struct gsm_bts_trx *trx)
+{
+ return trx->role_bts.l1h;
+}
+
void lchan_set_state(struct gsm_lchan *lchan, enum gsm_lchan_state state);
diff --git a/include/osmo-bts/logging.h b/include/osmo-bts/logging.h
index 226f77b..b1b44d5 100644
--- a/include/osmo-bts/logging.h
+++ b/include/osmo-bts/logging.h
@@ -16,6 +16,8 @@ enum {
DDSP,
DPCU,
DHO,
+ DTRX,
+ DLOOP,
DABIS,
DRTP,
DSUM,
diff --git a/include/osmo-bts/rsl.h b/include/osmo-bts/rsl.h
index 42ea6ef..6cb40dd 100644
--- a/include/osmo-bts/rsl.h
+++ b/include/osmo-bts/rsl.h
@@ -11,6 +11,8 @@ enum {
LCHAN_REL_ACT_OML,
};
+int msgb_queue_flush(struct llist_head *list);
+
int down_rsl(struct gsm_bts_trx *trx, struct msgb *msg);
int rsl_tx_rf_res(struct gsm_bts_trx *trx);
int rsl_tx_chan_rqd(struct gsm_bts_trx *trx, struct gsm_time *gtime,
diff --git a/src/Makefile.am b/src/Makefile.am
index e2eab0d..b8fe655 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,3 +3,6 @@ SUBDIRS = common
if ENABLE_SYSMOBTS
SUBDIRS += osmo-bts-sysmo
endif
+if ENABLE_TRX
+SUBDIRS += osmo-bts-trx
+endif
diff --git a/src/common/abis.c b/src/common/abis.c
index 9eb49a0..3b8a7af 100644
--- a/src/common/abis.c
+++ b/src/common/abis.c
@@ -47,6 +47,7 @@
#include <osmo-bts/bts.h>
#include <osmo-bts/rsl.h>
#include <osmo-bts/oml.h>
+#include <osmo-bts/bts_model.h>
static struct gsm_bts *g_bts;
@@ -114,7 +115,7 @@ static void sign_link_down(struct e1inp_line *line)
e1inp_sign_link_destroy(g_bts->oml_link);
g_bts->oml_link = NULL;
- bts_shutdown(g_bts, "Abis close");
+ bts_model_abis_close(g_bts);
}
@@ -203,7 +204,6 @@ void abis_init(struct gsm_bts *bts)
g_bts = bts;
oml_init();
- e1inp_vty_init();
libosmo_abis_init(NULL);
osmo_signal_register_handler(SS_L_INPUT, &inp_s_cbfn, bts);
diff --git a/src/common/amr.c b/src/common/amr.c
index 4a79b69..b0ff1b9 100644
--- a/src/common/amr.c
+++ b/src/common/amr.c
@@ -16,8 +16,9 @@ void amr_log_mr_conf(int ss, int logl, const char *pfx,
for (i = 0; i < amr_mrc->num_modes; i++)
LOGPC(ss, logl, ", mode[%u] = %u/%u/%u",
- i, amr_mrc->mode[i].mode, amr_mrc->mode[i].threshold,
- amr_mrc->mode[i].hysteresis);
+ i, amr_mrc->mode[i].mode,
+ amr_mrc->mode[i].threshold_bts,
+ amr_mrc->mode[i].hysteresis_bts);
LOGPC(ss, logl, "\n");
}
@@ -68,18 +69,18 @@ int amr_parse_mr_conf(struct amr_multirate_conf *amr_mrc,
}
if (num_codecs >= 2) {
- amr_mrc->mode[0].threshold = mr_conf[1] & 0x3F;
- amr_mrc->mode[0].hysteresis = mr_conf[2] >> 4;
+ amr_mrc->mode[0].threshold_bts = mr_conf[1] & 0x3F;
+ amr_mrc->mode[0].hysteresis_bts = mr_conf[2] >> 4;
}
if (num_codecs >= 3) {
- amr_mrc->mode[1].threshold =
+ amr_mrc->mode[1].threshold_bts =
((mr_conf[2] & 0xF) << 2) | (mr_conf[3] >> 6);
- amr_mrc->mode[1].hysteresis = (mr_conf[3] >> 2) & 0x7;
+ amr_mrc->mode[1].hysteresis_bts = (mr_conf[3] >> 2) & 0xF;
}
if (num_codecs >= 4) {
- amr_mrc->mode[3].threshold =
+ amr_mrc->mode[2].threshold_bts =
((mr_conf[3] & 0x3) << 4) | (mr_conf[4] >> 4);
- amr_mrc->mode[3].hysteresis = mr_conf[4] & 0xF;
+ amr_mrc->mode[2].hysteresis_bts = mr_conf[4] & 0xF;
}
return num_codecs;
@@ -94,10 +95,12 @@ ret_einval:
unsigned int amr_get_initial_mode(struct gsm_lchan *lchan)
{
struct amr_multirate_conf *amr_mrc = &lchan->tch.amr_mr;
+ struct gsm48_multi_rate_conf *mr_conf =
+ (struct gsm48_multi_rate_conf *) amr_mrc->gsm48_ie;
- if (lchan->mr_conf.icmi) {
+ if (mr_conf->icmi) {
/* initial mode given, coding in TS 05.09 3.4.1 */
- return lchan->mr_conf.smod;
+ return mr_conf->smod;
} else {
/* implicit rule according to TS 05.09 Chapter 3.4.3 */
switch (amr_mrc->num_modes) {
diff --git a/src/common/bts.c b/src/common/bts.c
index 77302e2..3fa2bdd 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -242,6 +242,8 @@ int trx_link_estab(struct gsm_bts_trx *trx)
if (link)
rsl_tx_rf_res(trx);
+ else
+ bts_model_trx_deact_rf(trx);
return 0;
}
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index 1cb752e..d5dd8a6 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -96,6 +96,7 @@ static int check_for_ciph_cmd(struct msgb *msg, struct gsm_lchan *lchan,
/* only do this if we are in the right state */
switch (lchan->ciph_state) {
case LCHAN_CIPH_NONE:
+ case LCHAN_CIPH_RX_REQ:
break;
default:
return 0;
@@ -278,11 +279,11 @@ static int to_gsmtap(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap)
}
/* time information received from bts model */
-static int l1sap_info_time_ind(struct gsm_bts_trx *trx,
+static int l1sap_info_time_ind(struct gsm_bts *bts,
struct osmo_phsap_prim *l1sap,
struct info_time_ind_param *info_time_ind)
{
- struct gsm_bts *bts = trx->bts;
+ struct gsm_bts_trx *trx;
struct gsm_bts_role_bts *btsb = bts->role;
int frames_expired = info_time_ind->fn - btsb->gsm_time.fn;
@@ -297,7 +298,8 @@ static int l1sap_info_time_ind(struct gsm_bts_trx *trx,
/* check if the measurement period of some lchan has ended
* and pre-compute the respective measurement */
- trx_meas_check_compute(trx, info_time_ind->fn - 1);
+ llist_for_each_entry(trx, &bts->trx_list, list)
+ trx_meas_check_compute(trx, info_time_ind->fn - 1);
/* increment number of RACH slots that have passed by since the
* last time indication */
@@ -352,7 +354,7 @@ static int l1sap_mph_info_ind(struct gsm_bts_trx *trx,
switch (info->type) {
case PRIM_INFO_TIME:
- rc = l1sap_info_time_ind(trx, l1sap, &info->u.time_ind);
+ rc = l1sap_info_time_ind(trx->bts, l1sap, &info->u.time_ind);
break;
case PRIM_INFO_MEAS:
rc = l1sap_info_meas_ind(trx, l1sap, &info->u.meas_ind);
diff --git a/src/common/logging.c b/src/common/logging.c
index 1e071db..5ce9b8b 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -107,6 +107,18 @@ static struct log_info_cat bts_log_info_cat[] = {
.color = "\033[0;37m",
.enabled = 1, .loglevel = LOGL_NOTICE,
},
+ [DTRX] = {
+ .name = "DTRX",
+ .description = "TRX interface",
+ .color = "\033[1;33m",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
+ [DLOOP] = {
+ .name = "DLOOP",
+ .description = "Control loops",
+ .color = "\033[0;34m",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
#if 0
[DNS] = {
.name = "DNS",
diff --git a/src/common/oml.c b/src/common/oml.c
index 5f9c0a2..6d778a5 100644
--- a/src/common/oml.c
+++ b/src/common/oml.c
@@ -590,6 +590,25 @@ static int oml_rx_set_radio_attr(struct gsm_bts_trx *trx, struct msgb *msg)
trx->arfcn_num = length;
} else
trx->arfcn_num = 0;
+#else
+ if (trx != trx->bts->c0 && TLVP_PRESENT(&tp, NM_ATT_ARFCN_LIST)) {
+ const uint8_t *value = TLVP_VAL(&tp, NM_ATT_ARFCN_LIST);
+ uint16_t _value;
+ uint16_t length = TLVP_LEN(&tp, NM_ATT_ARFCN_LIST);
+ uint16_t arfcn;
+ if (length != 2) {
+ LOGP(DOML, LOGL_ERROR, "Expecting only one ARFCN, "
+ "because hopping not supported\n");
+ /* FIXME: send NACK */
+ return -ENOTSUP;
+ }
+ memcpy(&_value, value, 2);
+ arfcn = ntohs(_value);
+ value += 2;
+ if (arfcn > 1024)
+ return oml_fom_ack_nack(msg, NM_NACK_FREQ_NOTAVAIL);
+ trx->arfcn = arfcn;
+ }
#endif
/* call into BTS driver to apply new attributes to hardware */
return bts_model_apply_oml(trx->bts, msg, tp_merged, NM_OC_RADIO_CARRIER, trx);
diff --git a/src/common/pcu_sock.c b/src/common/pcu_sock.c
index a4ca25f..577cfcf 100644
--- a/src/common/pcu_sock.c
+++ b/src/common/pcu_sock.c
@@ -330,6 +330,7 @@ int pcu_tx_data_ind(struct gsm_bts_trx_ts *ts, uint8_t is_ptcch, uint32_t fn,
data_ind = &pcu_prim->u.data_ind;
data_ind->sapi = (is_ptcch) ? PCU_IF_SAPI_PTCCH : PCU_IF_SAPI_PDTCH;
+ data_ind->rssi = rssi;
data_ind->fn = fn;
data_ind->arfcn = arfcn;
data_ind->trx_nr = ts->trx->nr;
diff --git a/src/common/rsl.c b/src/common/rsl.c
index 0908f1c..a225155 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -837,12 +837,12 @@ static int rsl_rx_chan_activ(struct msgb *msg)
}
/* 9.3.52 MultiRate Configuration */
if (TLVP_PRESENT(&tp, RSL_IE_MR_CONFIG)) {
- if (TLVP_LEN(&tp, RSL_IE_MR_CONFIG) > sizeof(lchan->mr_conf)) {
+ if (TLVP_LEN(&tp, RSL_IE_MR_CONFIG) > sizeof(lchan->mr_bts_lv) - 1) {
LOGP(DRSL, LOGL_ERROR, "Error parsing MultiRate conf IE\n");
return rsl_tx_error_report(msg->trx, RSL_ERR_IE_CONTENT);
}
- memcpy(&lchan->mr_conf, TLVP_VAL(&tp, RSL_IE_MR_CONFIG),
- TLVP_LEN(&tp, RSL_IE_MR_CONFIG));
+ memcpy(lchan->mr_bts_lv, TLVP_VAL(&tp, RSL_IE_MR_CONFIG) - 1,
+ TLVP_LEN(&tp, RSL_IE_MR_CONFIG) + 1);
amr_parse_mr_conf(&lchan->tch.amr_mr, TLVP_VAL(&tp, RSL_IE_MR_CONFIG),
TLVP_LEN(&tp, RSL_IE_MR_CONFIG));
amr_log_mr_conf(DRTP, LOGL_DEBUG, gsm_lchan_name(lchan),
@@ -1094,12 +1094,12 @@ static int rsl_rx_mode_modif(struct msgb *msg)
/* 9.3.52 MultiRate Configuration */
if (TLVP_PRESENT(&tp, RSL_IE_MR_CONFIG)) {
- if (TLVP_LEN(&tp, RSL_IE_MR_CONFIG) > sizeof(lchan->mr_conf)) {
+ if (TLVP_LEN(&tp, RSL_IE_MR_CONFIG) > sizeof(lchan->mr_bts_lv) - 1) {
LOGP(DRSL, LOGL_ERROR, "Error parsing MultiRate conf IE\n");
return rsl_tx_error_report(msg->trx, RSL_ERR_IE_CONTENT);
}
- memcpy(&lchan->mr_conf, TLVP_VAL(&tp, RSL_IE_MR_CONFIG),
- TLVP_LEN(&tp, RSL_IE_MR_CONFIG));
+ memcpy(lchan->mr_bts_lv, TLVP_VAL(&tp, RSL_IE_MR_CONFIG) - 1,
+ TLVP_LEN(&tp, RSL_IE_MR_CONFIG) + 1);
amr_parse_mr_conf(&lchan->tch.amr_mr, TLVP_VAL(&tp, RSL_IE_MR_CONFIG),
TLVP_LEN(&tp, RSL_IE_MR_CONFIG));
amr_log_mr_conf(DRTP, LOGL_DEBUG, gsm_lchan_name(lchan),
diff --git a/src/common/vty.c b/src/common/vty.c
index e3fd57d..0d52dd7 100644
--- a/src/common/vty.c
+++ b/src/common/vty.c
@@ -141,7 +141,7 @@ static struct cmd_node trx_node = {
};
DEFUN(cfg_bts_trx, cfg_bts_trx_cmd,
- "trx <0-0>",
+ "trx <0-254>",
"Select a TRX to configure\n" "TRX number\n")
{
int trx_nr = atoi(argv[0]);
@@ -150,7 +150,8 @@ DEFUN(cfg_bts_trx, cfg_bts_trx_cmd,
trx = gsm_bts_trx_num(bts, trx_nr);
if (!trx) {
- vty_out(vty, "Unknown TRX %u%s", trx_nr, VTY_NEWLINE);
+ vty_out(vty, "Unknown TRX %u. Aavialable TRX are: 0..%d%s",
+ trx_nr, bts->num_trx - 1, VTY_NEWLINE);
return CMD_WARNING;
}
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index e2ad500..12749dd 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -841,6 +841,7 @@ static int handle_ph_data_ind(struct femtol1_hdl *fl1, GsmL1_PhDataInd_t *data_i
uint32_t fn;
uint8_t *data, len;
int rc = 0;
+ int8_t rssi;
chan_nr = chan_nr_by_sapi(trx->ts[data_ind->u8Tn].pchan, data_ind->sapi,
data_ind->subCh, data_ind->u8Tn, data_ind->u32Fn);
@@ -877,6 +878,8 @@ static int handle_ph_data_ind(struct femtol1_hdl *fl1, GsmL1_PhDataInd_t *data_i
return rc;
}
+ /* get rssi */
+ rssi = (int8_t) (data_ind->measParam.fRssi);
/* get data pointer and length */
data = data_ind->msgUnitParam.u8Buffer;
len = data_ind->msgUnitParam.u8Size;
@@ -893,10 +896,10 @@ static int handle_ph_data_ind(struct femtol1_hdl *fl1, GsmL1_PhDataInd_t *data_i
l1sap = msgb_l1sap_prim(l1p_msg);
osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_PH_DATA,
PRIM_OP_INDICATION, l1p_msg);
- l1sap->u.data.rssi = data_ind->measParam.fRssi;
l1sap->u.data.link_id = link_id;
l1sap->u.data.chan_nr = chan_nr;
l1sap->u.data.fn = fn;
+ l1sap->u.data.rssi = rssi;
return l1sap_up(trx, l1sap);
}
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c
index b9f9fe9..bee5bda 100644
--- a/src/osmo-bts-sysmo/main.c
+++ b/src/osmo-bts-sysmo/main.c
@@ -319,6 +319,7 @@ int main(int argc, char **argv)
bts = gsm_bts_alloc(tall_bts_ctx);
vty_init(&bts_vty_info);
+ e1inp_vty_init();
bts_vty_init(bts, &bts_log_info);
handle_options(argc, argv);
@@ -419,3 +420,9 @@ int main(int argc, char **argv)
osmo_select_main(0);
}
}
+
+void bts_model_abis_close(struct gsm_bts *bts)
+{
+ /* for now, we simply terminate the program and re-spawn */
+ bts_shutdown(bts, "Abis close");
+}
diff --git a/src/osmo-bts-sysmo/oml.c b/src/osmo-bts-sysmo/oml.c
index 4c9ac49..adc0241 100644
--- a/src/osmo-bts-sysmo/oml.c
+++ b/src/osmo-bts-sysmo/oml.c
@@ -818,6 +818,9 @@ static void set_payload_format(GsmL1_LogChParam_t *lch_par)
static void lchan2lch_par(GsmL1_LogChParam_t *lch_par, struct gsm_lchan *lchan)
{
+ struct amr_multirate_conf *amr_mrc = &lchan->tch.amr_mr;
+ struct gsm48_multi_rate_conf *mr_conf =
+ (struct gsm48_multi_rate_conf *) amr_mrc->gsm48_ie;
int j;
LOGP(DL1C, LOGL_INFO, "%s: %s tch_mode=0x%02x\n",
@@ -857,41 +860,41 @@ static void lchan2lch_par(GsmL1_LogChParam_t *lch_par, struct gsm_lchan *lchan)
lch_par->tch.amrActiveCodecSet[j] = GsmL1_AmrCodec_Unset;
j = 0;
- if (lchan->mr_conf.m4_75)
+ if (mr_conf->m4_75)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_4_75;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m5_15)
+ if (mr_conf->m5_15)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_5_15;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m5_90)
+ if (mr_conf->m5_90)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_5_9;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m6_70)
+ if (mr_conf->m6_70)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_6_7;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m7_40)
+ if (mr_conf->m7_40)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_7_4;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m7_95)
+ if (mr_conf->m7_95)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_7_95;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m10_2)
+ if (mr_conf->m10_2)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_10_2;
if (j >= ARRAY_SIZE(lch_par->tch.amrActiveCodecSet))
break;
- if (lchan->mr_conf.m12_2)
+ if (mr_conf->m12_2)
lch_par->tch.amrActiveCodecSet[j++] = GsmL1_AmrCodec_12_2;
break;
case GSM48_CMODE_DATA_14k5:
diff --git a/src/osmo-bts-trx/Makefile.am b/src/osmo-bts-trx/Makefile.am
new file mode 100644
index 0000000..dbe90f8
--- /dev/null
+++ b/src/osmo-bts-trx/Makefile.am
@@ -0,0 +1,11 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) -lortp
+
+EXTRA_DIST = trx_if.h l1_if.h scheduler.h gsm0503_parity.h gsm0503_conv.h gsm0503_interleaving.h gsm0503_mapping.h gsm0503_coding.h gsm0503_tables.h loops.h amr.h
+
+bin_PROGRAMS = osmobts-trx
+
+osmobts_trx_SOURCES = main.c trx_if.c l1_if.c scheduler.c trx_vty.c gsm0503_parity.c gsm0503_conv.c gsm0503_interleaving.c gsm0503_mapping.c gsm0503_coding.c gsm0503_tables.c loops.c amr.c
+osmobts_trx_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)
+
diff --git a/src/osmo-bts-trx/amr.c b/src/osmo-bts-trx/amr.c
new file mode 100644
index 0000000..70d94ca
--- /dev/null
+++ b/src/osmo-bts-trx/amr.c
@@ -0,0 +1,81 @@
+/* AMR support for OsmoBTS-TRX */
+
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+
+static int amr_len_by_ft[16] = {
+ 12, 13, 15, 17, 19, 20, 26, 31,
+ 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+int amr_decompose_payload(uint8_t *payload, int payload_len, uint8_t *_cmr,
+ uint8_t *_ft, uint8_t *_bfi)
+{
+ uint8_t cmr, f, ft, q;
+
+ if (payload_len < 2)
+ return -EINVAL;
+
+ cmr = payload[0] >> 4;
+ if (_cmr)
+ *_cmr = cmr;
+
+ f = payload[1] >> 7;
+
+ ft = (payload[1] >> 3) & 0xf;
+ if (_ft)
+ *_ft = ft;
+
+ q = (payload[1] >> 2) & 0x1;
+ if (_bfi)
+ *_bfi = !q;
+
+ if (f) {
+ fprintf(stderr, "%s: multiple payloads not supported\n",
+ __func__);
+ return -ENOTSUP;
+ }
+
+ if (payload_len - 2 < amr_len_by_ft[ft])
+ return -EINVAL;
+
+ return 2 + amr_len_by_ft[ft];
+}
+
+int amr_compose_payload(uint8_t *payload, uint8_t cmr, uint8_t ft, uint8_t bfi)
+{
+ if (cmr >= 16)
+ return -EINVAL;
+
+ if (ft >= 16)
+ return -EINVAL;
+
+ payload[0] = cmr << 4;
+
+ payload[1] = (ft << 3) | ((!bfi) << 2); /* F = 0 */
+
+ return 2 + amr_len_by_ft[ft];
+}
+
diff --git a/src/osmo-bts-trx/amr.h b/src/osmo-bts-trx/amr.h
new file mode 100644
index 0000000..17eb5f0
--- /dev/null
+++ b/src/osmo-bts-trx/amr.h
@@ -0,0 +1,8 @@
+#ifndef _TRX_AMR_H
+#define _TRX_AMR_H
+
+int amr_decompose_payload(uint8_t *payload, int payload_len, uint8_t *_cmr,
+ uint8_t *_ft, uint8_t *_bfi);
+int amr_compose_payload(uint8_t *payload, uint8_t cmr, uint8_t ft, uint8_t bfi);
+
+#endif /* _TRX_AMR_H */
diff --git a/src/osmo-bts-trx/gsm0503_coding.c b/src/osmo-bts-trx/gsm0503_coding.c
new file mode 100644
index 0000000..fea25f9
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_coding.c
@@ -0,0 +1,1696 @@
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ * (C) 2015 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
+ *
+ * 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 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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/bits.h>
+#include <osmocom/core/conv.h>
+#include <osmocom/core/crcgen.h>
+#include <osmocom/codec/codec.h>
+
+#include <osmo-bts/logging.h>
+
+#include "gsm0503_conv.h"
+#include "gsm0503_parity.h"
+#include "gsm0503_mapping.h"
+#include "gsm0503_interleaving.h"
+#include "gsm0503_tables.h"
+#include "gsm0503_coding.h"
+
+int osmo_conv_decode_ber(const struct osmo_conv_code *code,
+ const sbit_t *input, ubit_t *output,
+ int *n_errors, int *n_bits_total)
+{
+ int res, i;
+ ubit_t recoded[1024]; /* TODO: We can do smaller, I guess */
+
+ res = osmo_conv_decode(code, input, output);
+
+ *n_bits_total = osmo_conv_encode(code, output, recoded);
+ OSMO_ASSERT(sizeof(recoded)/sizeof(recoded[0]) >= *n_bits_total);
+
+ /* Count bit errors */
+ *n_errors = 0;
+ for (i=0; i< *n_bits_total; i++) {
+ if (! ((recoded[i] && input[i]<0) ||
+ (!recoded[i] && input[i]>0)) )
+ *n_errors += 1;
+ }
+
+ return res;
+}
+
+
+static int _xcch_decode_cB(uint8_t *l2_data, sbit_t *cB,
+ int *n_errors, int *n_bits_total)
+{
+ ubit_t conv[224];
+ int rv;
+
+ osmo_conv_decode_ber(&gsm0503_conv_xcch, cB, conv, n_errors, n_bits_total);
+
+ rv = osmo_crc64gen_check_bits(&gsm0503_fire_crc40, conv, 184, conv+184);
+ if (rv)
+ return -1;
+
+ osmo_ubit2pbit_ext(l2_data, 0, conv, 0, 184, 1);
+
+ return 0;
+}
+
+static int _xcch_encode_cB(ubit_t *cB, uint8_t *l2_data)
+{
+ ubit_t conv[224];
+
+ osmo_pbit2ubit_ext(conv, 0, l2_data, 0, 184, 1);
+
+ osmo_crc64gen_set_bits(&gsm0503_fire_crc40, conv, 184, conv+184);
+
+ osmo_conv_encode(&gsm0503_conv_xcch, conv, cB);
+
+ return 0;
+}
+
+
+/*
+ * GSM xCCH block transcoding
+ */
+
+int xcch_decode(uint8_t *l2_data, sbit_t *bursts,
+ int *n_errors, int *n_bits_total)
+{
+ sbit_t iB[456], cB[456];
+ int i;
+
+ for (i=0; i<4; i++)
+ gsm0503_xcch_burst_unmap(&iB[i * 114], &bursts[i * 116], NULL,
+ NULL);
+
+ gsm0503_xcch_deinterleave(cB, iB);
+
+ return _xcch_decode_cB(l2_data, cB, n_errors, n_bits_total);
+}
+
+int xcch_encode(ubit_t *bursts, uint8_t *l2_data)
+{
+ ubit_t iB[456], cB[456], hl = 1, hn = 1;
+ int i;
+
+ _xcch_encode_cB(cB, l2_data);
+
+ gsm0503_xcch_interleave(cB, iB);
+
+ for (i=0; i<4; i++)
+ gsm0503_xcch_burst_map(&iB[i * 114], &bursts[i * 116], &hl,
+ &hn);
+
+ return 0;
+}
+
+
+/*
+ * GSM PDTCH block transcoding
+ */
+
+int pdtch_decode(uint8_t *l2_data, sbit_t *bursts, uint8_t *usf_p,
+ int *n_errors, int *n_bits_total)
+{
+ sbit_t iB[456], cB[676], hl_hn[8];
+ ubit_t conv[456];
+ int i, j, k, rv, best = 0, cs = 0, usf = 0; /* make GCC happy */
+
+ for (i=0; i<4; i++)
+ gsm0503_xcch_burst_unmap(&iB[i * 114], &bursts[i * 116],
+ hl_hn + i*2, hl_hn + i*2 + 1);
+
+ for (i=0; i<4; i++) {
+ for (j=0, k=0; j<8; j++)
+ k += abs(((int)gsm0503_pdtch_hl_hn_sbit[i][j]) -
+ ((int)hl_hn[j]));
+ if (i == 0 || k < best) {
+ best = k;
+ cs = i+1;
+ }
+ }
+
+ gsm0503_xcch_deinterleave(cB, iB);
+
+ switch (cs) {
+ case 1:
+ osmo_conv_decode_ber(&gsm0503_conv_xcch, cB, conv, n_errors, n_bits_total);
+
+ rv = osmo_crc64gen_check_bits(&gsm0503_fire_crc40, conv, 184,
+ conv+184);
+ if (rv)
+ return -1;
+
+ osmo_ubit2pbit_ext(l2_data, 0, conv, 0, 184, 1);
+
+ return 23;
+ case 2:
+ for (i=587, j=455; i>=0; i--)
+ if (!gsm0503_puncture_cs2[i])
+ cB[i] = cB[j--];
+ else
+ cB[i] = 0;
+
+ osmo_conv_decode_ber(&gsm0503_conv_cs2, cB, conv, n_errors, n_bits_total);
+
+ for (i=0; i<8; i++) {
+ for (j=0, k=0; j<6; j++)
+ k += abs(((int)gsm0503_usf2six[i][j]) -
+ ((int)conv[j]));
+ if (i == 0 || k < best) {
+ best = k;
+ usf = i;
+ }
+ }
+
+ conv[3] = usf & 1;
+ conv[4] = (usf >> 1) & 1;
+ conv[5] = (usf >> 2) & 1;
+ if (usf_p)
+ *usf_p = usf;
+
+ rv = osmo_crc16gen_check_bits(&gsm0503_cs234_crc16, conv+3, 271,
+ conv+3+271);
+ if (rv)
+ return -1;
+
+ osmo_ubit2pbit_ext(l2_data, 0, conv, 3, 271, 1);
+
+ return 34;
+ case 3:
+ for (i=675, j=455; i>=0; i--)
+ if (!gsm0503_puncture_cs3[i])
+ cB[i] = cB[j--];
+ else
+ cB[i] = 0;
+
+ osmo_conv_decode_ber(&gsm0503_conv_cs3, cB, conv, n_errors, n_bits_total);
+
+ for (i=0; i<8; i++) {
+ for (j=0, k=0; j<6; j++)
+ k += abs(((int)gsm0503_usf2six[i][j]) -
+ ((int)conv[j]));
+ if (i == 0 || k < best) {
+ best = k;
+ usf = i;
+ }
+ }
+
+ conv[3] = usf & 1;
+ conv[4] = (usf >> 1) & 1;
+ conv[5] = (usf >> 2) & 1;
+ if (usf_p)
+ *usf_p = usf;
+
+ rv = osmo_crc16gen_check_bits(&gsm0503_cs234_crc16, conv+3, 315,
+ conv+3+315);
+ if (rv)
+ return -1;
+
+ osmo_ubit2pbit_ext(l2_data, 0, conv, 3, 315, 1);
+
+ return 40;
+ case 4:
+ for (i=12; i<456;i++)
+ conv[i] = (cB[i] < 0) ? 1:0;
+
+ for (i=0; i<8; i++) {
+ for (j=0, k=0; j<12; j++)
+ k += abs(((int)gsm0503_usf2twelve_sbit[i][j]) -
+ ((int)cB[j]));
+ if (i == 0 || k < best) {
+ best = k;
+ usf = i;
+ }
+ }
+
+ conv[9] = usf & 1;
+ conv[10] = (usf >> 1) & 1;
+ conv[11] = (usf >> 2) & 1;
+ if (usf_p)
+ *usf_p = usf;
+
+ rv = osmo_crc16gen_check_bits(&gsm0503_cs234_crc16, conv+9, 431,
+ conv+9+431);
+ if (rv) {
+ *n_bits_total = 456-12;
+ *n_errors = *n_bits_total;
+ return -1;
+ }
+
+ *n_bits_total = 456-12;
+ *n_errors = 0;
+
+ osmo_ubit2pbit_ext(l2_data, 0, conv, 9, 431, 1);
+
+ return 54;
+ default:
+ *n_bits_total = 0;
+ *n_errors = 0;
+ break;
+ }
+
+ return -1;
+}
+
+int pdtch_encode(ubit_t *bursts, uint8_t *l2_data, uint8_t l2_len)
+{
+ ubit_t iB[456], cB[676];
+ const ubit_t *hl_hn;
+ ubit_t conv[334];
+ int i, j, usf;
+
+ switch (l2_len) {
+ case 23:
+ osmo_pbit2ubit_ext(conv, 0, l2_data, 0, 184, 1);
+
+ osmo_crc64gen_set_bits(&gsm0503_fire_crc40, conv, 184,
+ conv+184);
+
+ osmo_conv_encode(&gsm0503_conv_xcch, conv, cB);
+
+ hl_hn = gsm0503_pdtch_hl_hn_ubit[0];
+
+ break;
+ case 34:
+ osmo_pbit2ubit_ext(conv, 3, l2_data, 0, 271, 1);
+ usf = l2_data[0] & 0x7;
+
+ osmo_crc16gen_set_bits(&gsm0503_cs234_crc16, conv+3, 271,
+ conv+3+271);
+
+ memcpy(conv, gsm0503_usf2six[usf], 6);
+
+ osmo_conv_encode(&gsm0503_conv_cs2, conv, cB);
+
+ for (i=0, j=0; i<588; i++)
+ if (!gsm0503_puncture_cs2[i])
+ cB[j++] = cB[i];
+
+ hl_hn = gsm0503_pdtch_hl_hn_ubit[1];
+
+ break;
+ case 40:
+ osmo_pbit2ubit_ext(conv, 3, l2_data, 0, 315, 1);
+ usf = l2_data[0] & 0x7;
+
+ osmo_crc16gen_set_bits(&gsm0503_cs234_crc16, conv+3, 315,
+ conv+3+315);
+
+ memcpy(conv, gsm0503_usf2six[usf], 6);
+
+ osmo_conv_encode(&gsm0503_conv_cs3, conv, cB);
+
+ for (i=0, j=0; i<676; i++)
+ if (!gsm0503_puncture_cs3[i])
+ cB[j++] = cB[i];
+
+ hl_hn = gsm0503_pdtch_hl_hn_ubit[2];
+
+ break;
+ case 54:
+ osmo_pbit2ubit_ext(cB, 9, l2_data, 0, 431, 1);
+ usf = l2_data[0] & 0x7;
+
+ osmo_crc16gen_set_bits(&gsm0503_cs234_crc16, cB+9, 431,
+ cB+9+431);
+
+ memcpy(cB, gsm0503_usf2twelve_ubit[usf], 12);
+
+ hl_hn = gsm0503_pdtch_hl_hn_ubit[3];
+
+ break;
+ default:
+ return -1;
+ }
+
+ gsm0503_xcch_interleave(cB, iB);
+
+ for (i=0; i<4; i++)
+ gsm0503_xcch_burst_map(&iB[i * 114], &bursts[i * 116],
+ hl_hn + i*2, hl_hn + i*2 + 1);
+
+ return 0;
+}
+
+
+/*
+ * GSM TCH/F FR/EFR transcoding
+ */
+
+static void tch_fr_reassemble(uint8_t *tch_data, ubit_t *b_bits, int net_order)
+{
+ int i, j, k, l, o;
+
+ tch_data[0] = 0xd << 4;
+ memset(tch_data + 1, 0, 32);
+
+ if (net_order) {
+ i = 0; /* counts bits */
+ j = 4; /* counts output bits */
+ while (i < 260) {
+ tch_data[j>>3] |= (b_bits[i] << (7-(j&7)));
+ i++;
+ j++;
+ }
+ return;
+ }
+
+ /* reassemble d-bits */
+ i = 0; /* counts bits */
+ j = 4; /* counts output bits */
+ k = gsm0503_gsm_fr_map[0]-1; /* current number bit in element */
+ l = 0; /* counts element bits */
+ o = 0; /* offset input bits */
+ while (i < 260) {
+ tch_data[j>>3] |= (b_bits[k+o] << (7-(j&7)));
+ if (--k < 0) {
+ o += gsm0503_gsm_fr_map[l];
+ k = gsm0503_gsm_fr_map[++l]-1;
+ }
+ i++;
+ j++;
+ }
+}
+
+static void tch_fr_disassemble(ubit_t *b_bits, uint8_t *tch_data, int net_order)
+{
+ int i, j, k, l, o;
+
+ if (net_order) {
+ i = 0; /* counts bits */
+ j = 4; /* counts output bits */
+ while (i < 260) {
+ b_bits[i] = (tch_data[j>>3] >> (7-(j&7))) & 1;
+ i++;
+ j++;
+ }
+ return;
+ }
+
+ i = 0; /* counts bits */
+ j = 4; /* counts input bits */
+ k = gsm0503_gsm_fr_map[0]-1; /* current number bit in element */
+ l = 0; /* counts element bits */
+ o = 0; /* offset output bits */
+ while (i < 260) {
+ b_bits[k+o] = (tch_data[j>>3] >> (7-(j&7))) & 1;
+ if (--k < 0) {
+ o += gsm0503_gsm_fr_map[l];
+ k = gsm0503_gsm_fr_map[++l]-1;
+ }
+ i++;
+ j++;
+ }
+}
+
+static void tch_hr_reassemble(uint8_t *tch_data, ubit_t *b_bits)
+{
+ int i, j;
+
+ tch_data[0] = 0x00; /* F = 0, FT = 000 */
+ memset(tch_data + 1, 0, 14);
+
+ i = 0; /* counts bits */
+ j = 8; /* counts output bits */
+ while (i < 112) {
+ tch_data[j>>3] |= (b_bits[i] << (7-(j&7)));
+ i++;
+ j++;
+ }
+}
+
+static void tch_hr_disassemble(ubit_t *b_bits, uint8_t *tch_data)
+{
+ int i, j;
+
+ i = 0; /* counts bits */
+ j = 8; /* counts output bits */
+ while (i < 112) {
+ b_bits[i] = (tch_data[j>>3] >> (7-(j&7))) & 1;
+ i++;
+ j++;
+ }
+}
+
+static void tch_efr_reassemble(uint8_t *tch_data, ubit_t *b_bits)
+{
+ int i, j;
+
+ tch_data[0] = 0xc << 4;
+ memset(tch_data + 1, 0, 30);
+
+ i = 0; /* counts bits */
+ j = 4; /* counts output bits */
+ while (i < 244) {
+ tch_data[j>>3] |= (b_bits[i] << (7-(j&7)));
+ i++;
+ j++;
+ }
+}
+
+static void tch_efr_disassemble(ubit_t *b_bits, uint8_t *tch_data)
+{
+ int i, j;
+
+ i = 0; /* counts bits */
+ j = 4; /* counts output bits */
+ while (i < 244) {
+ b_bits[i] = (tch_data[j>>3] >> (7-(j&7))) & 1;
+ i++;
+ j++;
+ }
+}
+
+static void tch_amr_reassemble(uint8_t *tch_data, ubit_t *d_bits, int len)
+{
+ int i, j;
+
+ memset(tch_data, 0, (len + 7) >> 3);
+
+ i = 0; /* counts bits */
+ j = 0; /* counts output bits */
+ while (i < len) {
+ tch_data[j>>3] |= (d_bits[i] << (7-(j&7)));
+ i++;
+ j++;
+ }
+}
+
+static void tch_amr_disassemble(ubit_t *d_bits, uint8_t *tch_data, int len)
+{
+ int i, j;
+
+ i = 0; /* counts bits */
+ j = 0; /* counts output bits */
+ while (i < len) {
+ d_bits[i] = (tch_data[j>>3] >> (7-(j&7))) & 1;
+ i++;
+ j++;
+ }
+}
+
+static void tch_fr_d_to_b(ubit_t *b_bits, ubit_t *d_bits)
+{
+ int i;
+
+ for (i = 0; i < 260; i++)
+ b_bits[gsm610_bitorder[i]] = d_bits[i];
+}
+
+static void tch_fr_b_to_d(ubit_t *d_bits, ubit_t *b_bits)
+{
+ int i;
+
+ for (i = 0; i < 260; i++)
+ d_bits[i] = b_bits[gsm610_bitorder[i]];
+}
+
+static void tch_hr_d_to_b(ubit_t *b_bits, ubit_t *d_bits)
+{
+ int i;
+
+ const uint16_t *map;
+
+ if (!d_bits[93] && !d_bits[94])
+ map = gsm620_unvoiced_bitorder;
+ else
+ map = gsm620_voiced_bitorder;
+
+ for (i = 0; i < 112; i++)
+ b_bits[map[i]] = d_bits[i];
+}
+
+static void tch_hr_b_to_d(ubit_t *d_bits, ubit_t *b_bits)
+{
+ int i;
+ const uint16_t *map;
+
+ if (!b_bits[34] && !b_bits[35])
+ map = gsm620_unvoiced_bitorder;
+ else
+ map = gsm620_voiced_bitorder;
+
+ for (i = 0; i < 112; i++)
+ d_bits[i] = b_bits[map[i]];
+}
+
+static void tch_efr_d_to_w(ubit_t *b_bits, ubit_t *d_bits)
+{
+ int i;
+
+ for (i = 0; i < 260; i++)
+ b_bits[gsm660_bitorder[i]] = d_bits[i];
+}
+
+static void tch_efr_w_to_d(ubit_t *d_bits, ubit_t *b_bits)
+{
+ int i;
+
+ for (i = 0; i < 260; i++)
+ d_bits[i] = b_bits[gsm660_bitorder[i]];
+}
+
+static void tch_efr_protected(ubit_t *s_bits, ubit_t *b_bits)
+{
+ int i;
+
+ for (i = 0; i < 65; i++)
+ b_bits[i] = s_bits[gsm0503_gsm_efr_protected_bits[i]-1];
+}
+
+static void tch_fr_unreorder(ubit_t *d, ubit_t *p, ubit_t *u)
+{
+ int i;
+
+ for (i=0; i<91; i++) {
+ d[i<<1] = u[i];
+ d[(i<<1)+1] = u[184-i];
+ }
+ for (i=0; i<3; i++)
+ p[i] = u[91+i];
+}
+
+static void tch_fr_reorder(ubit_t *u, ubit_t *d, ubit_t *p)
+{
+ int i;
+
+ for (i=0; i<91; i++) {
+ u[i] = d[i<<1];
+ u[184-i] = d[(i<<1)+1];
+ }
+ for (i=0; i<3; i++)
+ u[91+i] = p[i];
+}
+
+static void tch_hr_unreorder(ubit_t *d, ubit_t *p, ubit_t *u)
+{
+ memcpy(d, u, 95);
+ memcpy(p, u+95, 3);
+}
+
+static void tch_hr_reorder(ubit_t *u, ubit_t *d, ubit_t *p)
+{
+ memcpy(u, d, 95);
+ memcpy(u+95, p, 3);
+}
+
+static void tch_efr_reorder(ubit_t *w, ubit_t *s, ubit_t *p)
+{
+ memcpy(w, s, 71);
+ w[71] = w[72] = s[69];
+ memcpy(w+73, s+71, 50);
+ w[123] = w[124] = s[119];
+ memcpy(w+125, s+121, 53);
+ w[178] = w[179] = s[172];
+ memcpy(w+180, s+174, 50);
+ w[230] = w[231] = s[222];
+ memcpy(w+232, s+224, 20);
+ memcpy(w+252, p, 8);
+}
+
+static void tch_efr_unreorder(ubit_t *s, ubit_t *p, ubit_t *w)
+{
+ int sum;
+
+ memcpy(s, w, 71);
+ sum = s[69] + w[71] + w[72];
+ s[69] = (sum > 2);
+ memcpy(s+71, w+73, 50);
+ sum = s[119] + w[123] + w[124];
+ s[119] = (sum > 2);
+ memcpy(s+121, w+125, 53);
+ sum = s[172] + w[178] + w[179];
+ s[172] = (sum > 2);
+ memcpy(s+174, w+180, 50);
+ sum = s[220] + w[230] + w[231];
+ s[222] = (sum > 2);
+ memcpy(s+224, w+232, 20);
+ memcpy(p, w+252, 8);
+}
+
+static void tch_amr_merge(ubit_t *u, ubit_t *d, ubit_t *p, int len, int prot)
+{
+ memcpy(u, d, prot);
+ memcpy(u+prot, p, 6);
+ memcpy(u+prot+6, d+prot, len-prot);
+}
+
+static void tch_amr_unmerge(ubit_t *d, ubit_t *p, ubit_t *u, int len, int prot)
+{
+ memcpy(d, u, prot);
+ memcpy(p, u+prot, 6);
+ memcpy(d+prot, u+prot+6, len-prot);
+}
+
+int tch_fr_decode(uint8_t *tch_data, sbit_t *bursts, int net_order, int efr,
+ int *n_errors, int *n_bits_total)
+{
+ sbit_t iB[912], cB[456], h;
+ ubit_t conv[185], s[244], w[260], b[65], d[260], p[8];
+ int i, rv, len, steal = 0;
+
+ for (i=0; i<8; i++) {
+ gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116], &h,
+ i>>2);
+ steal -= h;
+ }
+
+ gsm0503_tch_fr_deinterleave(cB, iB);
+
+ if (steal > 0) {
+ rv = _xcch_decode_cB(tch_data, cB, n_errors, n_bits_total);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_fr_decode(): error decoding FACCH frame (%d/%d bits)\n", *n_errors, *n_bits_total);
+ return -1;
+ }
+
+ return 23;
+ }
+
+ osmo_conv_decode_ber(&gsm0503_conv_tch_fr, cB, conv, n_errors, n_bits_total);
+
+ tch_fr_unreorder(d, p, conv);
+
+ for (i=0; i<78; i++)
+ d[i+182] = (cB[i+378] < 0) ? 1:0;
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_tch_fr_crc3, d, 50, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_fr_decode(): error checking CRC8 for the FR part of an %s frame\n", efr?"EFR":"FR");
+ return -1;
+ }
+
+
+ if (efr) {
+ tch_efr_d_to_w(w, d);
+
+ tch_efr_unreorder(s, p, w);
+
+ tch_efr_protected(s, b);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_tch_efr_crc8, b,
+ 65, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_fr_decode(): error checking CRC8 for the EFR part of an EFR frame\n");
+ return -1;
+ }
+
+ tch_efr_reassemble(tch_data, s);
+
+ len = 31;
+ } else {
+ tch_fr_d_to_b(w, d);
+
+ tch_fr_reassemble(tch_data, w, net_order);
+
+ len = 33;
+ }
+
+ return len;
+}
+
+int tch_fr_encode(ubit_t *bursts, uint8_t *tch_data, int len, int net_order)
+{
+ ubit_t iB[912], cB[456], h;
+ ubit_t conv[185], w[260], b[65], s[244], d[260], p[8];
+ int i;
+
+ switch (len) {
+ case 31: /* TCH EFR */
+
+ tch_efr_disassemble(s, tch_data);
+
+ tch_efr_protected(s, b);
+
+ osmo_crc8gen_set_bits(&gsm0503_tch_efr_crc8, b, 65, p);
+
+ tch_efr_reorder(w, s, p);
+
+ tch_efr_w_to_d(d, w);
+
+ goto coding_efr_fr;
+ case 33: /* TCH FR */
+ tch_fr_disassemble(w, tch_data, net_order);
+
+ tch_fr_b_to_d(d, w);
+
+coding_efr_fr:
+ osmo_crc8gen_set_bits(&gsm0503_tch_fr_crc3, d, 50, p);
+
+ tch_fr_reorder(conv, d, p);
+
+ memcpy(cB+378, d+182, 78);
+
+ osmo_conv_encode(&gsm0503_conv_tch_fr, conv, cB);
+
+ h = 0;
+
+ break;
+ case 23: /* FACCH */
+ _xcch_encode_cB(cB, tch_data);
+
+ h = 1;
+
+ break;
+ default:
+ return -1;
+ }
+
+ gsm0503_tch_fr_interleave(cB, iB);
+
+ for (i=0; i<8; i++)
+ gsm0503_tch_burst_map(&iB[i * 114], &bursts[i * 116], &h, i>>2);
+
+ return 0;
+}
+
+int tch_hr_decode(uint8_t *tch_data, sbit_t *bursts, int odd,
+ int *n_errors, int *n_bits_total)
+{
+ sbit_t iB[912], cB[456], h;
+ ubit_t conv[98], b[112], d[112], p[3];
+ int i, rv, steal = 0;
+
+ /* only unmap the stealing bits */
+ if (!odd) {
+ for (i=0; i<4; i++) {
+ gsm0503_tch_burst_unmap(NULL, &bursts[i * 116], &h, 0);
+ steal -= h;
+ }
+ for (i=2; i<5; i++) {
+ gsm0503_tch_burst_unmap(NULL, &bursts[i * 116], &h, 1);
+ steal -= h;
+ }
+ }
+
+ /* if we found a stole FACCH, but only at correct alignment */
+ if (steal > 0) {
+ for (i=0; i<6; i++)
+ gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116],
+ NULL, i>>2);
+ for (i=2; i<4; i++)
+ gsm0503_tch_burst_unmap(&iB[i * 114 + 456],
+ &bursts[i * 116], NULL, 1);
+
+ gsm0503_tch_fr_deinterleave(cB, iB);
+
+ rv = _xcch_decode_cB(tch_data, cB, n_errors, n_bits_total);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_hr_decode(): error decoding FACCH frame (%d/%d bits)\n", *n_errors, *n_bits_total);
+ return -1;
+ }
+
+ return 23;
+ }
+
+ for (i=0; i<4; i++)
+ gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116], NULL,
+ i>>1);
+
+ gsm0503_tch_hr_deinterleave(cB, iB);
+
+ osmo_conv_decode_ber(&gsm0503_conv_tch_hr, cB, conv, n_errors, n_bits_total);
+
+ tch_hr_unreorder(d, p, conv);
+
+ for (i=0; i<17; i++)
+ d[i+95] = (cB[i+211] < 0) ? 1:0;
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_tch_fr_crc3, d + 73, 22, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_fr_decode(): error checking CRC8 for an HR frame\n");
+ return -1;
+ }
+
+ tch_hr_d_to_b(b, d);
+
+ tch_hr_reassemble(tch_data, b);
+
+ return 15;
+}
+
+int tch_hr_encode(ubit_t *bursts, uint8_t *tch_data, int len)
+{
+ ubit_t iB[912], cB[456], h;
+ ubit_t conv[98], b[112], d[112], p[3];
+ int i;
+
+ switch (len) {
+ case 15: /* TCH HR */
+ tch_hr_disassemble(b, tch_data);
+
+ tch_hr_b_to_d(d, b);
+
+ osmo_crc8gen_set_bits(&gsm0503_tch_fr_crc3, d + 73, 22, p);
+
+ tch_hr_reorder(conv, d, p);
+
+ osmo_conv_encode(&gsm0503_conv_tch_hr, conv, cB);
+
+ memcpy(cB+211, d+95, 17);
+
+ h = 0;
+
+ gsm0503_tch_hr_interleave(cB, iB);
+
+ for (i=0; i<4; i++)
+ gsm0503_tch_burst_map(&iB[i * 114], &bursts[i * 116],
+ &h, i>>1);
+
+ break;
+ case 23: /* FACCH */
+ _xcch_encode_cB(cB, tch_data);
+
+ h = 1;
+
+ gsm0503_tch_fr_interleave(cB, iB);
+
+ for (i=0; i<6; i++)
+ gsm0503_tch_burst_map(&iB[i * 114], &bursts[i * 116],
+ &h, i>>2);
+ for (i=2; i<4; i++)
+ gsm0503_tch_burst_map(&iB[i * 114 + 456],
+ &bursts[i * 116], &h, 1);
+
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+int tch_afs_decode(uint8_t *tch_data, sbit_t *bursts, int codec_mode_req,
+ uint8_t *codec, int codecs, uint8_t *ft, uint8_t *cmr,
+ int *n_errors, int *n_bits_total)
+{
+ sbit_t iB[912], cB[456], h;
+ ubit_t d[244], p[6], conv[250];
+ int i, j, k, best = 0, rv, len, steal = 0, id = 0;
+ *n_errors = 0; *n_bits_total = 0;
+
+ for (i=0; i<8; i++) {
+ gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116], &h,
+ i>>2);
+ steal -= h;
+ }
+
+ gsm0503_tch_fr_deinterleave(cB, iB);
+
+ if (steal > 0) {
+ rv = _xcch_decode_cB(tch_data, cB, n_errors, n_bits_total);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error decoding FACCH frame (%d/%d bits)\n", *n_errors, *n_bits_total);
+ return -1;
+ }
+
+ return 23;
+ }
+
+ for (i=0; i<4; i++) {
+ for (j=0, k=0; j<8; j++)
+ k += abs(((int)gsm0503_afs_ic_sbit[i][j]) -
+ ((int)cB[j]));
+ if (i == 0 || k < best) {
+ best = k;
+ id = i;
+ }
+ }
+
+ /* check if indicated codec fits into range of codecs */
+ if (id >= codecs) {
+ /* codec mode out of range, return id */
+ return id;
+ }
+
+ switch ((codec_mode_req) ? codec[*ft] : codec[id]) {
+ case 7: /* TCH/AFS12.2 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_12_2, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 244, 81);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 81, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 12.2 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 244);
+
+ len = 31;
+
+ break;
+ case 6: /* TCH/AFS10.2 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_10_2, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 204, 65);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 65, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 10.2 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 204);
+
+ len = 26;
+
+ break;
+ case 5: /* TCH/AFS7.95 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_7_95, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 159, 75);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 75, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 7.95 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 159);
+
+ len = 20;
+
+ break;
+ case 4: /* TCH/AFS7.4 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_7_4, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 148, 61);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 61, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 7.4 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 148);
+
+ len = 19;
+
+ break;
+ case 3: /* TCH/AFS6.7 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_6_7, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 134, 55);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 55, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 6.7 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 134);
+
+ len = 17;
+
+ break;
+ case 2: /* TCH/AFS5.9 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_5_9, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 118, 55);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 55, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 5.9 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 118);
+
+ len = 15;
+
+ break;
+ case 1: /* TCH/AFS5.15 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_5_15, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 103, 49);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 49, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 5.15 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 103);
+
+ len = 13;
+
+ break;
+ case 0: /* TCH/AFS4.75 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_afs_4_75, cB+8, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 95, 39);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 39, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_afs_decode(): error checking CRC8 for an AMR 4.75 frame\n");
+ return -1;
+ }
+
+ tch_amr_reassemble(tch_data, d, 95);
+
+ len = 12;
+
+ break;
+ default:
+ LOGP(DL1C, LOGL_ERROR, "tch_afs_decode(): Unknown frame type\n");
+ fprintf(stderr, "FIXME: FT %d not supported!\n", *ft);
+ *n_bits_total = 448;
+ *n_errors = *n_bits_total;
+ return -1;
+ }
+
+ /* change codec request / indication, if frame is valid */
+ if (codec_mode_req)
+ *cmr = id;
+ else
+ *ft = id;
+
+ return len;
+}
+
+int tch_afs_encode(ubit_t *bursts, uint8_t *tch_data, int len,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t ft,
+ uint8_t cmr)
+{
+ ubit_t iB[912], cB[456], h;
+ ubit_t d[244], p[6], conv[250];
+ int i;
+ uint8_t id;
+
+ if (len == 23) { /* FACCH */
+ _xcch_encode_cB(cB, tch_data);
+
+ h = 1;
+
+ goto facch;
+ }
+
+ h = 0;
+
+ if (codec_mode_req) {
+ if (cmr >= codecs) {
+ fprintf(stderr, "FIXME: CMR ID %d not in codec list!\n",
+ cmr);
+ return -1;
+ }
+ id = cmr;
+ } else {
+ if (ft >= codecs) {
+ fprintf(stderr, "FIXME: FT ID %d not in codec list!\n",
+ ft);
+ return -1;
+ }
+ id = ft;
+ }
+
+ switch (codec[ft]) {
+ case 7: /* TCH/AFS12.2 */
+ if (len != 31) {
+invalid_length:
+ fprintf(stderr, "FIXME: payload length %d does not "
+ "comply with codec type %d!\n", len, ft);
+ return -1;
+ }
+
+ tch_amr_disassemble(d, tch_data, 244);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 81, p);
+
+ tch_amr_merge(conv, d, p, 244, 81);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_12_2, conv, cB+8);
+
+ break;
+ case 6: /* TCH/AFS10.2 */
+ if (len != 26)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 204);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 65, p);
+
+ tch_amr_merge(conv, d, p, 204, 65);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_10_2, conv, cB+8);
+
+ break;
+ case 5: /* TCH/AFS7.95 */
+ if (len != 20)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 159);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 75, p);
+
+ tch_amr_merge(conv, d, p, 159, 75);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_7_95, conv, cB+8);
+
+ break;
+ case 4: /* TCH/AFS7.4 */
+ if (len != 19)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 148);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 61, p);
+
+ tch_amr_merge(conv, d, p, 148, 61);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_7_4, conv, cB+8);
+
+ break;
+ case 3: /* TCH/AFS6.7 */
+ if (len != 17)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 134);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 55, p);
+
+ tch_amr_merge(conv, d, p, 134, 55);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_6_7, conv, cB+8);
+
+ break;
+ case 2: /* TCH/AFS5.9 */
+ if (len != 15)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 118);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 55, p);
+
+ tch_amr_merge(conv, d, p, 118, 55);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_5_9, conv, cB+8);
+
+ break;
+ case 1: /* TCH/AFS5.15 */
+ if (len != 13)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 103);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 49, p);
+
+ tch_amr_merge(conv, d, p, 103, 49);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_5_15, conv, cB+8);
+
+ break;
+ case 0: /* TCH/AFS4.75 */
+ if (len != 12)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 95);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 39, p);
+
+ tch_amr_merge(conv, d, p, 95, 39);
+
+ osmo_conv_encode(&gsm0503_conv_tch_afs_4_75, conv, cB+8);
+
+ break;
+ default:
+ fprintf(stderr, "FIXME: FT %d not supported!\n", ft);
+
+ return -1;
+ }
+
+ memcpy(cB, gsm0503_afs_ic_ubit[id], 8);
+
+facch:
+ gsm0503_tch_fr_interleave(cB, iB);
+
+ for (i=0; i<8; i++)
+ gsm0503_tch_burst_map(&iB[i * 114], &bursts[i * 116], &h, i>>2);
+
+ return 0;
+}
+
+int tch_ahs_decode(uint8_t *tch_data, sbit_t *bursts, int odd,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
+ uint8_t *cmr, int *n_errors, int *n_bits_total)
+{
+ sbit_t iB[912], cB[456], h;
+ ubit_t d[244], p[6], conv[135];
+ int i, j, k, best = 0, rv, len, steal = 0, id = 0;
+
+ /* only unmap the stealing bits */
+ if (!odd) {
+ for (i=0; i<4; i++) {
+ gsm0503_tch_burst_unmap(NULL, &bursts[i * 116], &h, 0);
+ steal -= h;
+ }
+ for (i=2; i<5; i++) {
+ gsm0503_tch_burst_unmap(NULL, &bursts[i * 116], &h, 1);
+ steal -= h;
+ }
+ }
+
+ /* if we found a stole FACCH, but only at correct alignment */
+ if (steal > 0) {
+ for (i=0; i<6; i++)
+ gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116],
+ NULL, i>>2);
+ for (i=2; i<4; i++)
+ gsm0503_tch_burst_unmap(&iB[i * 114 + 456],
+ &bursts[i * 116], NULL, 1);
+
+ gsm0503_tch_fr_deinterleave(cB, iB);
+
+ rv = _xcch_decode_cB(tch_data, cB, n_errors, n_bits_total);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error decoding FACCH frame (%d/%d bits)\n", *n_errors, *n_bits_total);
+ return -1;
+ }
+
+ return 23;
+ }
+
+ for (i=0; i<4; i++)
+ gsm0503_tch_burst_unmap(&iB[i * 114], &bursts[i * 116], NULL,
+ i>>1);
+
+ gsm0503_tch_hr_deinterleave(cB, iB);
+
+ for (i=0; i<4; i++) {
+ for (j=0, k=0; j<4; j++)
+ k += abs(((int)gsm0503_ahs_ic_sbit[i][j]) -
+ ((int)cB[j]));
+ if (i == 0 || k < best) {
+ best = k;
+ id = i;
+ }
+ }
+
+ /* check if indicated codec fits into range of codecs */
+ if (id >= codecs) {
+ /* codec mode out of range, return id */
+ return id;
+ }
+
+ switch ((codec_mode_req) ? codec[*ft] : codec[id]) {
+ case 5: /* TCH/AHS7.95 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_ahs_7_95, cB+4, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 123, 67);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 67, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error checking CRC8 for an AMR 7.95 frame\n");
+ return -1;
+ }
+
+ for (i=0; i<36;i++)
+ d[i+123] = (cB[i+192] < 0) ? 1:0;
+
+ tch_amr_reassemble(tch_data, d, 159);
+
+ len = 20;
+
+ break;
+ case 4: /* TCH/AHS7.4 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_ahs_7_4, cB+4, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 120, 61);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 61, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error checking CRC8 for an AMR 7.4 frame\n");
+ return -1;
+ }
+
+ for (i=0; i<28;i++)
+ d[i+120] = (cB[i+200] < 0) ? 1:0;
+
+ tch_amr_reassemble(tch_data, d, 148);
+
+ len = 19;
+
+ break;
+ case 3: /* TCH/AHS6.7 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_ahs_6_7, cB+4, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 110, 55);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 55, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error checking CRC8 for an AMR 6.7 frame\n");
+ return -1;
+ }
+
+ for (i=0; i<24;i++)
+ d[i+110] = (cB[i+204] < 0) ? 1:0;
+
+ tch_amr_reassemble(tch_data, d, 134);
+
+ len = 17;
+
+ break;
+ case 2: /* TCH/AHS5.9 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_ahs_5_9, cB+4, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 102, 55);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 55, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error checking CRC8 for an AMR 5.9 frame\n");
+ return -1;
+ }
+
+ for (i=0; i<16;i++)
+ d[i+102] = (cB[i+212] < 0) ? 1:0;
+
+ tch_amr_reassemble(tch_data, d, 118);
+
+ len = 15;
+
+ break;
+ case 1: /* TCH/AHS5.15 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_ahs_5_15, cB+4, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 91, 49);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 49, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error checking CRC8 for an AMR 5.15 frame\n");
+ return -1;
+ }
+
+ for (i=0; i<12;i++)
+ d[i+91] = (cB[i+216] < 0) ? 1:0;
+
+ tch_amr_reassemble(tch_data, d, 103);
+
+ len = 13;
+
+ break;
+ case 0: /* TCH/AHS4.75 */
+ osmo_conv_decode_ber(&gsm0503_conv_tch_ahs_4_75, cB+4, conv, n_errors, n_bits_total);
+
+ tch_amr_unmerge(d, p, conv, 83, 39);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_amr_crc6, d, 39, p);
+ if (rv) {
+ LOGP(DL1C, LOGL_NOTICE, "tch_ahs_decode(): error checking CRC8 for an AMR 4.75 frame\n");
+ return -1;
+ }
+
+ for (i=0; i<12;i++)
+ d[i+83] = (cB[i+216] < 0) ? 1:0;
+
+ tch_amr_reassemble(tch_data, d, 95);
+
+ len = 12;
+
+ break;
+ default:
+ LOGP(DL1C, LOGL_ERROR, "tch_afs_decode(): Unknown frame type\n");
+ fprintf(stderr, "FIXME: FT %d not supported!\n", *ft);
+ *n_bits_total = 159;
+ *n_errors = *n_bits_total;
+ return -1;
+ }
+
+ /* change codec request / indication, if frame is valid */
+ if (codec_mode_req)
+ *cmr = id;
+ else
+ *ft = id;
+
+ return len;
+}
+
+int tch_ahs_encode(ubit_t *bursts, uint8_t *tch_data, int len,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t ft,
+ uint8_t cmr)
+{
+ ubit_t iB[912], cB[456], h;
+ ubit_t d[244], p[6], conv[135];
+ int i;
+ uint8_t id;
+
+ if (len == 23) { /* FACCH */
+ _xcch_encode_cB(cB, tch_data);
+
+ h = 1;
+
+ gsm0503_tch_fr_interleave(cB, iB);
+
+ for (i=0; i<6; i++)
+ gsm0503_tch_burst_map(&iB[i * 114], &bursts[i * 116],
+ &h, i>>2);
+ for (i=2; i<4; i++)
+ gsm0503_tch_burst_map(&iB[i * 114 + 456],
+ &bursts[i * 116], &h, 1);
+
+ return 0;
+ }
+
+ h = 0;
+
+ if (codec_mode_req) {
+ if (cmr >= codecs) {
+ fprintf(stderr, "FIXME: CMR ID %d not in codec list!\n",
+ cmr);
+ return -1;
+ }
+ id = cmr;
+ } else {
+ if (ft >= codecs) {
+ fprintf(stderr, "FIXME: FT ID %d not in codec list!\n",
+ ft);
+ return -1;
+ }
+ id = ft;
+ }
+
+ switch (codec[ft]) {
+ case 5: /* TCH/AHS7.95 */
+ if (len != 20) {
+invalid_length:
+ fprintf(stderr, "FIXME: payload length %d does not "
+ "comply with codec type %d!\n", len, ft);
+ return -1;
+ }
+
+ tch_amr_disassemble(d, tch_data, 159);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 67, p);
+
+ tch_amr_merge(conv, d, p, 123, 67);
+
+ osmo_conv_encode(&gsm0503_conv_tch_ahs_7_95, conv, cB+4);
+
+ memcpy(cB+192, d+123, 36);
+
+ break;
+ case 4: /* TCH/AHS7.4 */
+ if (len != 19)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 148);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 61, p);
+
+ tch_amr_merge(conv, d, p, 120, 61);
+
+ osmo_conv_encode(&gsm0503_conv_tch_ahs_7_4, conv, cB+4);
+
+ memcpy(cB+200, d+120, 28);
+
+ break;
+ case 3: /* TCH/AHS6.7 */
+ if (len != 17)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 134);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 55, p);
+
+ tch_amr_merge(conv, d, p, 110, 55);
+
+ osmo_conv_encode(&gsm0503_conv_tch_ahs_6_7, conv, cB+4);
+
+ memcpy(cB+204, d+110, 24);
+
+ break;
+ case 2: /* TCH/AHS5.9 */
+ if (len != 15)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 118);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 55, p);
+
+ tch_amr_merge(conv, d, p, 102, 55);
+
+ osmo_conv_encode(&gsm0503_conv_tch_ahs_5_9, conv, cB+4);
+
+ memcpy(cB+212, d+102, 16);
+
+ break;
+ case 1: /* TCH/AHS5.15 */
+ if (len != 13)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 103);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 49, p);
+
+ tch_amr_merge(conv, d, p, 91, 49);
+
+ osmo_conv_encode(&gsm0503_conv_tch_ahs_5_15, conv, cB+4);
+
+ memcpy(cB+216, d+91, 12);
+
+ break;
+ case 0: /* TCH/AHS4.75 */
+ if (len != 12)
+ goto invalid_length;
+
+ tch_amr_disassemble(d, tch_data, 95);
+
+ osmo_crc8gen_set_bits(&gsm0503_amr_crc6, d, 39, p);
+
+ tch_amr_merge(conv, d, p, 83, 39);
+
+ osmo_conv_encode(&gsm0503_conv_tch_ahs_4_75, conv, cB+4);
+
+ memcpy(cB+216, d+83, 12);
+
+ break;
+ default:
+ fprintf(stderr, "FIXME: FT %d not supported!\n", ft);
+
+ return -1;
+ }
+
+ memcpy(cB, gsm0503_afs_ic_ubit[id], 4);
+
+ gsm0503_tch_hr_interleave(cB, iB);
+
+ for (i=0; i<4; i++)
+ gsm0503_tch_burst_map(&iB[i * 114], &bursts[i * 116], &h, i>>1);
+
+ return 0;
+}
+
+/*
+ * GSM RACH transcoding
+ */
+
+/*
+ * GSM RACH apply BSIC to parity
+ *
+ * p(j) = p(j) xor b(j) j = 0, ..., 5
+ * b(0) = MSB of PLMN colour code
+ * b(5) = LSB of BS colour code
+ */
+
+static int rach_apply_bsic(ubit_t *d, uint8_t bsic)
+{
+ int i;
+
+ /* Apply it */
+ for (i=0; i<6; i++)
+ d[8+i] ^= ((bsic >> (5-i)) & 1);
+
+ return 0;
+}
+
+int rach_decode(uint8_t *ra, sbit_t *burst, uint8_t bsic)
+{
+ ubit_t conv[14];
+ int rv;
+
+ osmo_conv_decode(&gsm0503_conv_rach, burst, conv);
+
+ rach_apply_bsic(conv, bsic);
+
+ rv = osmo_crc8gen_check_bits(&gsm0503_rach_crc6, conv, 8, conv+8);
+ if (rv)
+ return -1;
+
+ osmo_ubit2pbit_ext(ra, 0, conv, 0, 8, 1);
+
+ return 0;
+}
+
+int rach_encode(ubit_t *burst, uint8_t *ra, uint8_t bsic)
+{
+ ubit_t conv[14];
+
+ osmo_pbit2ubit_ext(conv, 0, ra, 0, 8, 1);
+
+ osmo_crc8gen_set_bits(&gsm0503_rach_crc6, conv, 8, conv+8);
+
+ rach_apply_bsic(conv, bsic);
+
+ osmo_conv_encode(&gsm0503_conv_rach, conv, burst);
+
+ return 0;
+}
+
+
+/*
+ * GSM SCH transcoding
+ */
+
+int sch_decode(uint8_t *sb_info, sbit_t *burst)
+{
+ ubit_t conv[35];
+ int rv;
+
+ osmo_conv_decode(&gsm0503_conv_sch, burst, conv);
+
+ rv = osmo_crc16gen_check_bits(&gsm0503_sch_crc10, conv, 25, conv+25);
+ if (rv)
+ return -1;
+
+ osmo_ubit2pbit_ext(sb_info, 0, conv, 0, 25, 1);
+
+ return 0;
+}
+
+int sch_encode(ubit_t *burst, uint8_t *sb_info)
+{
+ ubit_t conv[35];
+
+ osmo_pbit2ubit_ext(conv, 0, sb_info, 0, 25, 1);
+
+ osmo_crc16gen_set_bits(&gsm0503_sch_crc10, conv, 25, conv+25);
+
+ osmo_conv_encode(&gsm0503_conv_sch, conv, burst);
+
+ return 0;
+}
+
diff --git a/src/osmo-bts-trx/gsm0503_coding.h b/src/osmo-bts-trx/gsm0503_coding.h
new file mode 100644
index 0000000..a454d8f
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_coding.h
@@ -0,0 +1,53 @@
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ * (C) 2015 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
+ *
+ * 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 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/>.
+ *
+ */
+
+#ifndef _0503_CODING_H
+#define _0503_CODING_H
+
+int xcch_decode(uint8_t *l2_data, sbit_t *bursts,
+ int *n_errors, int *n_bits_total);
+int xcch_encode(ubit_t *bursts, uint8_t *l2_data);
+int pdtch_decode(uint8_t *l2_data, sbit_t *bursts, uint8_t *usf_p,
+ int *n_errors, int *n_bits_total);
+int pdtch_encode(ubit_t *bursts, uint8_t *l2_data, uint8_t l2_len);
+int tch_fr_decode(uint8_t *tch_data, sbit_t *bursts, int net_order,
+ int efr, int *n_errors, int *n_bits_total);
+int tch_fr_encode(ubit_t *bursts, uint8_t *tch_data, int len, int net_order);
+int tch_hr_decode(uint8_t *tch_data, sbit_t *bursts, int odd,
+ int *n_errors, int *n_bits_total);
+int tch_hr_encode(ubit_t *bursts, uint8_t *tch_data, int len);
+int tch_afs_decode(uint8_t *tch_data, sbit_t *bursts, int codec_mode_req,
+ uint8_t *codec, int codecs, uint8_t *ft, uint8_t *cmr,
+ int *n_errors, int *n_bits_total);
+int tch_afs_encode(ubit_t *bursts, uint8_t *tch_data, int len,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t ft,
+ uint8_t cmr);
+int tch_ahs_decode(uint8_t *tch_data, sbit_t *bursts, int odd,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t *ft,
+ uint8_t *cmr, int *n_errors, int *n_bits_total);
+int tch_ahs_encode(ubit_t *bursts, uint8_t *tch_data, int len,
+ int codec_mode_req, uint8_t *codec, int codecs, uint8_t ft,
+ uint8_t cmr);
+int rach_decode(uint8_t *ra, sbit_t *burst, uint8_t bsic);
+int rach_encode(ubit_t *burst, uint8_t *ra, uint8_t bsic);
+int sch_decode(uint8_t *sb_info, sbit_t *burst);
+int sch_encode(ubit_t *burst, uint8_t *sb_info);
+
+#endif /* _0503_CODING_H */
diff --git a/src/osmo-bts-trx/gsm0503_conv.c b/src/osmo-bts-trx/gsm0503_conv.c
new file mode 100644
index 0000000..dc50e6c
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_conv.c
@@ -0,0 +1,950 @@
+
+#include <stdint.h>
+
+#include <osmocom/core/conv.h>
+
+#include "gsm0503_conv.h"
+
+/*
+ * GSM convolutional coding
+ *
+ * G_0 = 1 + x^3 + x^4
+ * G_1 = 1 + x + x^3 + x^4
+ */
+
+static const uint8_t conv_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_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 },
+};
+
+
+const struct osmo_conv_code gsm0503_conv_xcch = {
+ .N = 2,
+ .K = 5,
+ .len = 224,
+ .next_output = conv_xcch_next_output,
+ .next_state = conv_xcch_next_state,
+};
+
+
+const struct osmo_conv_code gsm0503_conv_cs2 = {
+ .N = 2,
+ .K = 5,
+ .len = 290,
+ .next_output = conv_xcch_next_output,
+ .next_state = conv_xcch_next_state,
+};
+
+
+const struct osmo_conv_code gsm0503_conv_cs3 = {
+ .N = 2,
+ .K = 5,
+ .len = 334,
+ .next_output = conv_xcch_next_output,
+ .next_state = conv_xcch_next_state,
+};
+
+
+const struct osmo_conv_code gsm0503_conv_rach = {
+ .N = 2,
+ .K = 5,
+ .len = 14,
+ .next_output = conv_xcch_next_output,
+ .next_state = conv_xcch_next_state,
+};
+
+
+const struct osmo_conv_code gsm0503_conv_sch = {
+ .N = 2,
+ .K = 5,
+ .len = 35,
+ .next_output = conv_xcch_next_output,
+ .next_state = conv_xcch_next_state,
+};
+
+
+const struct osmo_conv_code gsm0503_conv_tch_fr = {
+ .N = 2,
+ .K = 5,
+ .len = 185,
+ .next_output = conv_xcch_next_output,
+ .next_state = conv_xcch_next_state,
+};
+
+
+/*
+ * GSM HR convolutional coding
+ *
+ * G_0 = 1 + x^2 + x^3 + x^5 + x^6
+ * G_1 = 1 + x + x^4 + x^6
+ * G_3 = 1 + x + x^2 + x^3 + x^4 + x^6
+ */
+
+static const uint8_t conv_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 conv_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 conv_tch_hr_puncture[] = {
+ /* Class 1 bits */
+ 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,
+
+ /* Tail bits */
+ 295, 298, 301, 304, 307, 310,
+
+ /* End */
+ -1,
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_hr = {
+ .N = 3,
+ .K = 7,
+ .len = 98,
+ .next_output = conv_tch_hr_next_output,
+ .next_state = conv_tch_hr_next_state,
+ .puncture = conv_tch_hr_puncture,
+};
+
+
+/* TCH/AFS12.2 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_afs_12_2_puncture[] = {
+ 321, 325, 329, 333, 337, 341, 345, 349, 353, 357, 361, 363,
+ 365, 369, 373, 377, 379, 381, 385, 389, 393, 395, 397, 401,
+ 405, 409, 411, 413, 417, 421, 425, 427, 429, 433, 437, 441,
+ 443, 445, 449, 453, 457, 459, 461, 465, 469, 473, 475, 477,
+ 481, 485, 489, 491, 493, 495, 497, 499, 501, 503, 505, 507,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_12_2 = {
+ .N = 2,
+ .K = 5,
+ .len = 250,
+ .next_output = conv_tch_afs_12_2_next_output,
+ .next_state = conv_tch_afs_12_2_next_state,
+ .next_term_output = conv_tch_afs_12_2_next_term_output,
+ .next_term_state = conv_tch_afs_12_2_next_term_state,
+ .puncture = conv_tch_afs_12_2_puncture,
+};
+
+
+/* TCH/AFS10.2 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_afs_10_2_puncture[] = {
+ 1, 4, 7, 10, 16, 19, 22, 28, 31, 34, 40, 43,
+ 46, 52, 55, 58, 64, 67, 70, 76, 79, 82, 88, 91,
+ 94, 100, 103, 106, 112, 115, 118, 124, 127, 130, 136, 139,
+ 142, 148, 151, 154, 160, 163, 166, 172, 175, 178, 184, 187,
+ 190, 196, 199, 202, 208, 211, 214, 220, 223, 226, 232, 235,
+ 238, 244, 247, 250, 256, 259, 262, 268, 271, 274, 280, 283,
+ 286, 292, 295, 298, 304, 307, 310, 316, 319, 322, 325, 328,
+ 331, 334, 337, 340, 343, 346, 349, 352, 355, 358, 361, 364,
+ 367, 370, 373, 376, 379, 382, 385, 388, 391, 394, 397, 400,
+ 403, 406, 409, 412, 415, 418, 421, 424, 427, 430, 433, 436,
+ 439, 442, 445, 448, 451, 454, 457, 460, 463, 466, 469, 472,
+ 475, 478, 481, 484, 487, 490, 493, 496, 499, 502, 505, 508,
+ 511, 514, 517, 520, 523, 526, 529, 532, 535, 538, 541, 544,
+ 547, 550, 553, 556, 559, 562, 565, 568, 571, 574, 577, 580,
+ 583, 586, 589, 592, 595, 598, 601, 604, 607, 609, 610, 613,
+ 616, 619, 621, 622, 625, 627, 628, 631, 633, 634, 636, 637,
+ 639, 640,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_10_2 = {
+ .N = 3,
+ .K = 5,
+ .len = 210,
+ .next_output = conv_tch_afs_10_2_next_output,
+ .next_state = conv_tch_afs_10_2_next_state,
+ .next_term_output = conv_tch_afs_10_2_next_term_output,
+ .next_term_state = conv_tch_afs_10_2_next_term_state,
+ .puncture = conv_tch_afs_10_2_puncture,
+};
+
+
+/* TCH/AFS7.95 */
+/* ----------- */
+
+static const uint8_t conv_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_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_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_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_tch_afs_7_95_puncture[] = {
+ 1, 2, 4, 5, 8, 22, 70, 118, 166, 214, 262, 310,
+ 317, 319, 325, 332, 334, 341, 343, 349, 356, 358, 365, 367,
+ 373, 380, 382, 385, 389, 391, 397, 404, 406, 409, 413, 415,
+ 421, 428, 430, 433, 437, 439, 445, 452, 454, 457, 461, 463,
+ 469, 476, 478, 481, 485, 487, 490, 493, 500, 502, 503, 505,
+ 506, 508, 509, 511, 512,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_7_95 = {
+ .N = 3,
+ .K = 7,
+ .len = 165,
+ .next_output = conv_tch_afs_7_95_next_output,
+ .next_state = conv_tch_afs_7_95_next_state,
+ .next_term_output = conv_tch_afs_7_95_next_term_output,
+ .next_term_state = conv_tch_afs_7_95_next_term_state,
+ .puncture = conv_tch_afs_7_95_puncture,
+};
+
+
+/* TCH/AFS7.4 */
+/* ---------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_afs_7_4_puncture[] = {
+ 0, 355, 361, 367, 373, 379, 385, 391, 397, 403, 409, 415,
+ 421, 427, 433, 439, 445, 451, 457, 460, 463, 466, 468, 469,
+ 471, 472,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_7_4 = {
+ .N = 3,
+ .K = 5,
+ .len = 154,
+ .next_output = conv_tch_afs_7_4_next_output,
+ .next_state = conv_tch_afs_7_4_next_state,
+ .next_term_output = conv_tch_afs_7_4_next_term_output,
+ .next_term_state = conv_tch_afs_7_4_next_term_state,
+ .puncture = conv_tch_afs_7_4_puncture,
+};
+
+
+/* TCH/AFS6.7 */
+/* ---------- */
+
+static const uint8_t conv_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 conv_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 conv_tch_afs_6_7_puncture[] = {
+ 1, 3, 7, 11, 15, 27, 39, 55, 67, 79, 95, 107,
+ 119, 135, 147, 159, 175, 187, 199, 215, 227, 239, 255, 267,
+ 279, 287, 291, 295, 299, 303, 307, 311, 315, 319, 323, 327,
+ 331, 335, 339, 343, 347, 351, 355, 359, 363, 367, 369, 371,
+ 375, 377, 379, 383, 385, 387, 391, 393, 395, 399, 401, 403,
+ 407, 409, 411, 415, 417, 419, 423, 425, 427, 431, 433, 435,
+ 439, 441, 443, 447, 449, 451, 455, 457, 459, 463, 465, 467,
+ 471, 473, 475, 479, 481, 483, 487, 489, 491, 495, 497, 499,
+ 503, 505, 507, 511, 513, 515, 519, 521, 523, 527, 529, 531,
+ 535, 537, 539, 543, 545, 547, 549, 551, 553, 555, 557, 559,
+ 561, 563, 565, 567, 569, 571, 573, 575,
+ -1, /* end */
+};
+
+static const uint8_t conv_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 conv_tch_afs_6_7_next_term_state[] = {
+ 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_6_7 = {
+ .N = 4,
+ .K = 5,
+ .len = 140,
+ .next_output = conv_tch_afs_6_7_next_output,
+ .next_state = conv_tch_afs_6_7_next_state,
+ .next_term_output = conv_tch_afs_6_7_next_term_output,
+ .next_term_state = conv_tch_afs_6_7_next_term_state,
+ .puncture = conv_tch_afs_6_7_puncture,
+};
+
+
+/* TCH/AFS5.9 */
+/* ---------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_afs_5_9_puncture[] = {
+ 0, 1, 3, 5, 7, 11, 15, 31, 47, 63, 79, 95,
+ 111, 127, 143, 159, 175, 191, 207, 223, 239, 255, 271, 287,
+ 303, 319, 327, 331, 335, 343, 347, 351, 359, 363, 367, 375,
+ 379, 383, 391, 395, 399, 407, 411, 415, 423, 427, 431, 439,
+ 443, 447, 455, 459, 463, 467, 471, 475, 479, 483, 487, 491,
+ 495, 499, 503, 507, 509, 511, 512, 513, 515, 516, 517, 519,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_5_9 = {
+ .N = 4,
+ .K = 7,
+ .len = 124,
+ .next_output = conv_tch_afs_5_9_next_output,
+ .next_state = conv_tch_afs_5_9_next_state,
+ .next_term_output = conv_tch_afs_5_9_next_term_output,
+ .next_term_state = conv_tch_afs_5_9_next_term_state,
+ .puncture = conv_tch_afs_5_9_puncture,
+};
+
+
+/* TCH/AFS5.15 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_afs_5_15_puncture[] = {
+ 0, 4, 5, 9, 10, 14, 15, 20, 25, 30, 35, 40,
+ 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160,
+ 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280,
+ 290, 300, 310, 315, 320, 325, 330, 334, 335, 340, 344, 345,
+ 350, 354, 355, 360, 364, 365, 370, 374, 375, 380, 384, 385,
+ 390, 394, 395, 400, 404, 405, 410, 414, 415, 420, 424, 425,
+ 430, 434, 435, 440, 444, 445, 450, 454, 455, 460, 464, 465,
+ 470, 474, 475, 480, 484, 485, 490, 494, 495, 500, 504, 505,
+ 510, 514, 515, 520, 524, 525, 529, 530, 534, 535, 539, 540,
+ 544, 545, 549, 550, 554, 555, 559, 560, 564,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_5_15 = {
+ .N = 5,
+ .K = 5,
+ .len = 109,
+ .next_output = conv_tch_afs_5_15_next_output,
+ .next_state = conv_tch_afs_5_15_next_state,
+ .next_term_output = conv_tch_afs_5_15_next_term_output,
+ .next_term_state = conv_tch_afs_5_15_next_term_state,
+ .puncture = conv_tch_afs_5_15_puncture,
+};
+
+
+/* TCH/AFS4.75 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_afs_4_75_puncture[] = {
+ 0, 1, 2, 4, 5, 7, 9, 15, 25, 35, 45, 55,
+ 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175,
+ 185, 195, 205, 215, 225, 235, 245, 255, 265, 275, 285, 295,
+ 305, 315, 325, 335, 345, 355, 365, 375, 385, 395, 400, 405,
+ 410, 415, 420, 425, 430, 435, 440, 445, 450, 455, 459, 460,
+ 465, 470, 475, 479, 480, 485, 490, 495, 499, 500, 505, 509,
+ 510, 515, 517, 519, 520, 522, 524, 525, 526, 527, 529, 530,
+ 531, 532, 534,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_afs_4_75 = {
+ .N = 5,
+ .K = 7,
+ .len = 101,
+ .next_output = conv_tch_afs_4_75_next_output,
+ .next_state = conv_tch_afs_4_75_next_state,
+ .next_term_output = conv_tch_afs_4_75_next_term_output,
+ .next_term_state = conv_tch_afs_4_75_next_term_state,
+ .puncture = conv_tch_afs_4_75_puncture,
+};
+
+
+/* TCH/AHS7.95 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_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, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_ahs_7_95 = {
+ .N = 2,
+ .K = 5,
+ .len = 129,
+ .next_output = conv_tch_ahs_7_95_next_output,
+ .next_state = conv_tch_ahs_7_95_next_state,
+ .next_term_output = conv_tch_ahs_7_95_next_term_output,
+ .next_term_state = conv_tch_ahs_7_95_next_term_state,
+ .puncture = conv_tch_ahs_7_95_puncture,
+};
+
+
+/* TCH/AHS7.4 */
+/* ---------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_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, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_ahs_7_4 = {
+ .N = 2,
+ .K = 5,
+ .len = 126,
+ .next_output = conv_tch_ahs_7_4_next_output,
+ .next_state = conv_tch_ahs_7_4_next_state,
+ .next_term_output = conv_tch_ahs_7_4_next_term_output,
+ .next_term_state = conv_tch_ahs_7_4_next_term_state,
+ .puncture = conv_tch_ahs_7_4_puncture,
+};
+
+
+/* TCH/AHS6.7 */
+/* ---------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_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, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_ahs_6_7 = {
+ .N = 2,
+ .K = 5,
+ .len = 116,
+ .next_output = conv_tch_ahs_6_7_next_output,
+ .next_state = conv_tch_ahs_6_7_next_state,
+ .next_term_output = conv_tch_ahs_6_7_next_term_output,
+ .next_term_state = conv_tch_ahs_6_7_next_term_state,
+ .puncture = conv_tch_ahs_6_7_puncture,
+};
+
+
+/* TCH/AHS5.9 */
+/* ---------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_tch_ahs_5_9_puncture[] = {
+ 1, 15, 71, 127, 139, 151, 163, 175, 187, 195, 203, 211,
+ 215, 219, 221, 223,
+ -1, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_ahs_5_9 = {
+ .N = 2,
+ .K = 5,
+ .len = 108,
+ .next_output = conv_tch_ahs_5_9_next_output,
+ .next_state = conv_tch_ahs_5_9_next_state,
+ .next_term_output = conv_tch_ahs_5_9_next_term_output,
+ .next_term_state = conv_tch_ahs_5_9_next_term_state,
+ .puncture = conv_tch_ahs_5_9_puncture,
+};
+
+
+/* TCH/AHS5.15 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_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, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_ahs_5_15 = {
+ .N = 3,
+ .K = 5,
+ .len = 97,
+ .next_output = conv_tch_ahs_5_15_next_output,
+ .next_state = conv_tch_ahs_5_15_next_state,
+ .next_term_output = conv_tch_ahs_5_15_next_term_output,
+ .next_term_state = conv_tch_ahs_5_15_next_term_state,
+ .puncture = conv_tch_ahs_5_15_puncture,
+};
+
+
+/* TCH/AHS4.75 */
+/* ----------- */
+
+static const uint8_t conv_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 conv_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 conv_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 conv_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 conv_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, /* end */
+};
+
+const struct osmo_conv_code gsm0503_conv_tch_ahs_4_75 = {
+ .N = 3,
+ .K = 7,
+ .len = 89,
+ .next_output = conv_tch_ahs_4_75_next_output,
+ .next_state = conv_tch_ahs_4_75_next_state,
+ .next_term_output = conv_tch_ahs_4_75_next_term_output,
+ .next_term_state = conv_tch_ahs_4_75_next_term_state,
+ .puncture = conv_tch_ahs_4_75_puncture,
+};
+
diff --git a/src/osmo-bts-trx/gsm0503_conv.h b/src/osmo-bts-trx/gsm0503_conv.h
new file mode 100644
index 0000000..68ad484
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_conv.h
@@ -0,0 +1,26 @@
+#ifndef _0503_CONV_H
+#define _0503_CONV_H
+
+extern const struct osmo_conv_code gsm0503_conv_xcch;
+extern const struct osmo_conv_code gsm0503_conv_cs2;
+extern const struct osmo_conv_code gsm0503_conv_cs3;
+extern const struct osmo_conv_code gsm0503_conv_rach;
+extern const struct osmo_conv_code gsm0503_conv_sch;
+extern const struct osmo_conv_code gsm0503_conv_tch_fr;
+extern const struct osmo_conv_code gsm0503_conv_tch_hr;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_12_2;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_10_2;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_7_95;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_7_4;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_6_7;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_5_9;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_5_15;
+extern const struct osmo_conv_code gsm0503_conv_tch_afs_4_75;
+extern const struct osmo_conv_code gsm0503_conv_tch_ahs_7_95;
+extern const struct osmo_conv_code gsm0503_conv_tch_ahs_7_4;
+extern const struct osmo_conv_code gsm0503_conv_tch_ahs_6_7;
+extern const struct osmo_conv_code gsm0503_conv_tch_ahs_5_9;
+extern const struct osmo_conv_code gsm0503_conv_tch_ahs_5_15;
+extern const struct osmo_conv_code gsm0503_conv_tch_ahs_4_75;
+
+#endif /* _0503_CONV_H */
diff --git a/src/osmo-bts-trx/gsm0503_interleaving.c b/src/osmo-bts-trx/gsm0503_interleaving.c
new file mode 100644
index 0000000..ec47a6b
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_interleaving.c
@@ -0,0 +1,144 @@
+
+#include <stdint.h>
+
+#include <osmocom/core/bits.h>
+
+#include "gsm0503_tables.h"
+#include "gsm0503_interleaving.h"
+
+/*
+ * GSM xCCH interleaving and burst mapping
+ *
+ * Interleaving:
+ *
+ * Given 456 coded input bits, form 4 blocks of 114 bits:
+ *
+ * i(B, j) = c(n, k) k = 0, ..., 455
+ * n = 0, ..., N, N + 1, ...
+ * B = B_0 + 4n + (k mod 4)
+ * j = 2(49k mod 57) + ((k mod 8) div 4)
+ *
+ * Mapping on Burst:
+ *
+ * e(B, j) = i(B, j)
+ * e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
+ * e(B, 57) = h_l(B)
+ * e(B, 58) = h_n(B)
+ *
+ * Where hl(B) and hn(B) are bits in burst B indicating flags.
+ */
+
+void gsm0503_xcch_deinterleave(sbit_t *cB, sbit_t *iB)
+{
+ int j, k, B;
+
+ for (k=0; k<456; k++) {
+ B = k & 3;
+ j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
+ cB[k] = iB[B * 114 + j];
+ }
+}
+
+void gsm0503_xcch_interleave(ubit_t *cB, ubit_t *iB)
+{
+ int j, k, B;
+
+ for (k=0; k<456; k++) {
+ B = k & 3;
+ j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
+ iB[B * 114 + j] = cB[k];
+ }
+}
+
+/*
+ * GSM TCH FR/EFR/AFS interleaving and burst mapping
+ *
+ * Interleaving:
+ *
+ * Given 456 coded input bits, form 8 blocks of 114 bits,
+ * where even bits of the first 4 blocks and odd bits of the last 4 blocks
+ * are used:
+ *
+ * i(B, j) = c(n, k) k = 0, ..., 455
+ * n = 0, ..., N, N + 1, ...
+ * B = B_0 + 4n + (k mod 8)
+ * j = 2(49k mod 57) + ((k mod 8) div 4)
+ *
+ * Mapping on Burst:
+ *
+ * e(B, j) = i(B, j)
+ * e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
+ * e(B, 57) = h_l(B)
+ * e(B, 58) = h_n(B)
+ *
+ * Where hl(B) and hn(B) are bits in burst B indicating flags.
+ */
+
+void gsm0503_tch_fr_deinterleave(sbit_t *cB, sbit_t *iB)
+{
+ int j, k, B;
+
+ for (k=0; k<456; k++) {
+ B = k & 7;
+ j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
+ cB[k] = iB[B * 114 + j];
+ }
+}
+
+void gsm0503_tch_fr_interleave(ubit_t *cB, ubit_t *iB)
+{
+ int j, k, B;
+
+ for (k=0; k<456; k++) {
+ B = k & 7;
+ j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
+ iB[B * 114 + j] = cB[k];
+ }
+}
+
+/*
+ * GSM TCH HR/AHS interleaving and burst mapping
+ *
+ * Interleaving:
+ *
+ * Given 288 coded input bits, form 4 blocks of 114 bits,
+ * where even bits of the first 2 blocks and odd bits of the last 2 blocks
+ * are used:
+ *
+ * i(B, j) = c(n, k) k = 0, ..., 227
+ * n = 0, ..., N, N + 1, ...
+ * B = B_0 + 2n + b
+ * j, b = table[k];
+ *
+ * Mapping on Burst:
+ *
+ * e(B, j) = i(B, j)
+ * e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
+ * e(B, 57) = h_l(B)
+ * e(B, 58) = h_n(B)
+ *
+ * Where hl(B) and hn(B) are bits in burst B indicating flags.
+ */
+
+void gsm0503_tch_hr_deinterleave(sbit_t *cB, sbit_t *iB)
+{
+ int j, k, B;
+
+ for (k=0; k<228; k++) {
+ B = gsm0503_tch_hr_interleaving[k][1];
+ j = gsm0503_tch_hr_interleaving[k][0];
+ cB[k] = iB[B * 114 + j];
+ }
+}
+
+void gsm0503_tch_hr_interleave(ubit_t *cB, ubit_t *iB)
+{
+ int j, k, B;
+
+ for (k=0; k<228; k++) {
+ B = gsm0503_tch_hr_interleaving[k][1];
+ j = gsm0503_tch_hr_interleaving[k][0];
+ iB[B * 114 + j] = cB[k];
+ }
+}
+
diff --git a/src/osmo-bts-trx/gsm0503_interleaving.h b/src/osmo-bts-trx/gsm0503_interleaving.h
new file mode 100644
index 0000000..4d546f6
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_interleaving.h
@@ -0,0 +1,11 @@
+#ifndef _0503_INTERLEAVING_H
+#define _0503_INTERLEAVING_H
+
+void gsm0503_xcch_deinterleave(sbit_t *cB, sbit_t *iB);
+void gsm0503_xcch_interleave(ubit_t *cB, ubit_t *iB);
+void gsm0503_tch_fr_deinterleave(sbit_t *cB, sbit_t *iB);
+void gsm0503_tch_fr_interleave(ubit_t *cB, ubit_t *iB);
+void gsm0503_tch_hr_deinterleave(sbit_t *cB, sbit_t *iB);
+void gsm0503_tch_hr_interleave(ubit_t *cB, ubit_t *iB);
+
+#endif /* _0503_INTERLEAVING_H */
diff --git a/src/osmo-bts-trx/gsm0503_mapping.c b/src/osmo-bts-trx/gsm0503_mapping.c
new file mode 100644
index 0000000..bdaddce
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_mapping.c
@@ -0,0 +1,72 @@
+
+#include <stdint.h>
+#include <string.h>
+
+#include <osmocom/core/bits.h>
+
+#include "gsm0503_mapping.h"
+
+void gsm0503_xcch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *hl, sbit_t *hn)
+{
+ memcpy(iB, eB, 57);
+ memcpy(iB+57, eB+59, 57);
+
+ if (hl)
+ *hl = eB[57];
+
+ if (hn)
+ *hn = eB[58];
+}
+
+void gsm0503_xcch_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *hl,
+ const ubit_t *hn)
+{
+ memcpy(eB, iB, 57);
+ memcpy(eB+59, iB+57, 57);
+
+ if (hl)
+ eB[57] = *hl;
+ if (hn)
+ eB[58] = *hn;
+}
+
+void gsm0503_tch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *h, int odd)
+{
+ int i;
+
+ /* brainfuck: only copy even or odd bits */
+ if (iB) {
+ for (i=odd; i<57; i+=2)
+ iB[i] = eB[i];
+ for (i=58-odd; i<114; i+=2)
+ iB[i] = eB[i+2];
+ }
+
+ if (h) {
+ if (!odd)
+ *h = eB[58];
+ else
+ *h = eB[57];
+ }
+}
+
+void gsm0503_tch_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd)
+{
+ int i;
+
+ /* brainfuck: only copy even or odd bits */
+ if (eB) {
+ for (i=odd; i<57; i+=2)
+ eB[i] = iB[i];
+ for (i=58-odd; i<114; i+=2)
+ eB[i+2] = iB[i];
+ }
+
+ if (h) {
+ if (!odd)
+ eB[58] = *h;
+ else
+ eB[57] = *h;
+ }
+}
+
diff --git a/src/osmo-bts-trx/gsm0503_mapping.h b/src/osmo-bts-trx/gsm0503_mapping.h
new file mode 100644
index 0000000..a693b35
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_mapping.h
@@ -0,0 +1,10 @@
+#ifndef _0503_MAPPING_H
+#define _0503_MAPPING_H
+
+void gsm0503_xcch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *hl, sbit_t *hn);
+void gsm0503_xcch_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *hl,
+ const ubit_t *hn);
+void gsm0503_tch_burst_unmap(sbit_t *iB, sbit_t *eB, sbit_t *h, int odd);
+void gsm0503_tch_burst_map(ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd);
+
+#endif /* _0503_INTERLEAVING_H */
diff --git a/src/osmo-bts-trx/gsm0503_parity.c b/src/osmo-bts-trx/gsm0503_parity.c
new file mode 100644
index 0000000..ba2e144
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_parity.c
@@ -0,0 +1,103 @@
+
+#include <stdint.h>
+
+#include <osmocom/core/crcgen.h>
+
+#include "gsm0503_parity.h"
+
+/*
+ * GSM (SACCH) parity (FIRE code)
+ *
+ * g(x) = (x^23 + 1)(x^17 + x^3 + 1)
+ * = x^40 + x^26 + x^23 + x^17 + x^3 + a1
+ */
+
+const struct osmo_crc64gen_code gsm0503_fire_crc40 = {
+ .bits = 40,
+ .poly = 0x0004820009ULL,
+ .init = 0x0000000000ULL,
+ .remainder = 0xffffffffffULL,
+};
+
+
+/*
+ * GSM PDTCH CS-2, CS-3, CS-4 parity
+ *
+ * g(x) = x^16 + x^12 + x^5 + 1
+ */
+
+const struct osmo_crc16gen_code gsm0503_cs234_crc16 = {
+ .bits = 16,
+ .poly = 0x1021,
+ .init = 0x0000,
+ .remainder = 0xffff,
+};
+
+
+/*
+ * GSM RACH parity
+ *
+ * g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1
+ */
+
+const struct osmo_crc8gen_code gsm0503_rach_crc6 = {
+ .bits = 6,
+ .poly = 0x2f,
+ .init = 0x00,
+ .remainder = 0x3f,
+};
+
+
+/*
+ * GSM SCH parity
+ *
+ * g(x) = x^10 + x^8 + x^6 + x^5 + x^4 + x^2 + 1
+ */
+
+const struct osmo_crc16gen_code gsm0503_sch_crc10 = {
+ .bits = 10,
+ .poly = 0x175,
+ .init = 0x000,
+ .remainder = 0x3ff,
+};
+
+
+/*
+ * GSM TCH FR/HR/EFR parity
+ *
+ * g(x) = x^3 + x + 1
+ */
+
+const struct osmo_crc8gen_code gsm0503_tch_fr_crc3 = {
+ .bits = 3,
+ .poly = 0x3,
+ .init = 0x0,
+ .remainder = 0x7,
+};
+
+/*
+ * GSM TCH EFR parity
+ *
+ * g(x) = x^8 + x^4 + x^3 + x^2 + 1
+ */
+
+const struct osmo_crc8gen_code gsm0503_tch_efr_crc8 = {
+ .bits = 8,
+ .poly = 0x1d,
+ .init = 0x00,
+ .remainder = 0x00,
+};
+
+/*
+ * GSM AMR parity
+ *
+ * g(x) = x^6 + x^5 + x^3 + x^2 + x^1 + 1
+ */
+
+const struct osmo_crc8gen_code gsm0503_amr_crc6 = {
+ .bits = 6,
+ .poly = 0x2f,
+ .init = 0x00,
+ .remainder = 0x3f,
+};
+
diff --git a/src/osmo-bts-trx/gsm0503_parity.h b/src/osmo-bts-trx/gsm0503_parity.h
new file mode 100644
index 0000000..ee52328
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_parity.h
@@ -0,0 +1,12 @@
+#ifndef _0503_PARITY_H
+#define _0503_PARITY_H
+
+const struct osmo_crc64gen_code gsm0503_fire_crc40;
+const struct osmo_crc16gen_code gsm0503_cs234_crc16;
+const struct osmo_crc8gen_code gsm0503_rach_crc6;
+const struct osmo_crc16gen_code gsm0503_sch_crc10;
+const struct osmo_crc8gen_code gsm0503_tch_fr_crc3;
+const struct osmo_crc8gen_code gsm0503_tch_efr_crc8;
+const struct osmo_crc8gen_code gsm0503_amr_crc6;
+
+#endif /* _0503_PARITY_H */
diff --git a/src/osmo-bts-trx/gsm0503_tables.c b/src/osmo-bts-trx/gsm0503_tables.c
new file mode 100644
index 0000000..a381784
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_tables.c
@@ -0,0 +1,193 @@
+
+#include <stdint.h>
+
+#include <osmocom/core/bits.h>
+
+#include "gsm0503_tables.h"
+
+const ubit_t gsm0503_pdtch_hl_hn_ubit[4][8] = {
+ { 1,1, 1,1, 1,1, 1,1 },
+ { 1,1, 0,0, 1,0, 0,0 },
+ { 0,0, 1,0, 0,0, 0,1 },
+ { 0,0, 0,1, 0,1, 1,0 },
+};
+
+const sbit_t gsm0503_pdtch_hl_hn_sbit[4][8] = {
+ { -127,-127, -127,-127, -127,-127, -127,-127 },
+ { -127,-127, 127, 127, -127, 127, 127, 127 },
+ { 127, 127, -127, 127, 127, 127, 127,-127 },
+ { 127, 127, 127,-127, 127,-127, -127, 127 },
+};
+
+const ubit_t gsm0503_usf2six[8][6] = {
+ { 0,0,0, 0,0,0 },
+ { 1,0,0, 1,0,1 },
+ { 0,1,0, 1,1,0 },
+ { 1,1,0, 0,1,1 },
+ { 0,0,1, 0,1,1 },
+ { 1,0,1, 1,1,0 },
+ { 0,1,1, 1,0,1 },
+ { 1,1,1, 0,0,0 },
+};
+
+const ubit_t gsm0503_usf2twelve_ubit[8][12] = {
+ { 0,0,0, 0,0,0, 0,0,0, 0,0,0 },
+ { 1,1,0, 1,0,0, 0,0,1, 0,1,1 },
+ { 0,0,1, 1,0,1, 1,1,0, 1,1,0 },
+ { 1,1,1, 0,0,1, 1,1,1, 1,0,1 },
+ { 0,0,0, 0,1,1, 0,1,1, 1,0,1 },
+ { 1,1,0, 1,1,1, 0,1,0, 1,1,0 },
+ { 0,0,1, 1,1,0, 1,0,1, 0,1,1 },
+ { 1,1,1, 0,1,0, 1,0,0, 0,0,0 },
+};
+
+const sbit_t gsm0503_usf2twelve_sbit[8][12] = {
+ { 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127 },
+ { -127,-127, 127, -127, 127, 127, 127, 127,-127, 127,-127,-127 },
+ { 127, 127,-127, -127, 127,-127, -127,-127, 127, -127,-127, 127 },
+ { -127,-127,-127, 127, 127,-127, -127,-127,-127, -127, 127,-127 },
+ { 127, 127, 127, 127,-127,-127, 127,-127,-127, -127, 127,-127 },
+ { -127,-127, 127, -127,-127,-127, 127,-127, 127, -127,-127, 127 },
+ { 127, 127,-127, -127,-127, 127, -127, 127,-127, 127,-127,-127 },
+ { -127,-127,-127, 127,-127, 127, -127, 127, 127, 127, 127, 127 },
+};
+
+const uint8_t gsm0503_puncture_cs2[588] = {
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,0,1,
+ 0,0,0,1, 0,0,0,1, 0,0,0,1
+};
+
+const uint8_t gsm0503_puncture_cs3[676] = {
+ 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,1,0,1,
+ 0,0,0,1,0,1, 0,0,0,1,0,1, 0,0,0,0
+};
+
+/* this corresponds to the bit-lengths of the individual codec
+ * parameters as indicated in Table 1.1 of TS 06.10 */
+const uint8_t gsm0503_gsm_fr_map[76] = {
+ 6, 6, 5, 5, 4, 4, 3, 3, 7, 2, 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 7, 2, 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 2, 2, 6, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 2, 2, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3
+};
+
+/* this table describes the 65 most importaint bits from EFR coded
+ * bits as indicated in TS 05.03 (3.1.1.1) */
+const uint8_t gsm0503_gsm_efr_protected_bits[65] = {
+ 39, 40, 41, 42, 43, 44, 48, 87, 45, 2,
+ 3, 8, 10, 18, 19, 24, 46, 47,142,143,
+ 144,145,146,147, 92, 93,195,196, 98,137,
+ 148, 94,197,149,150, 95,198, 4, 5, 11,
+ 12, 16, 9, 6, 7, 13, 17, 20, 96,199,
+ 1, 14, 15, 21, 25, 26, 28,151,201,190,
+ 240, 88,138,191,241
+};
+
+/* Encoded in-band data for speech frames */
+const ubit_t gsm0503_afs_ic_ubit[4][8] = {
+ { 0,0,0,0,0,0,0,0 },
+ { 0,1,0,1,1,1,0,1 },
+ { 1,0,1,1,1,0,1,0 },
+ { 1,1,1,0,0,1,1,1 },
+};
+
+const sbit_t gsm0503_afs_ic_sbit[4][8] = {
+ { 127, 127, 127, 127, 127, 127, 127, 127 },
+ { 127,-127, 127,-127,-127,-127, 127,-127 },
+ { -127, 127,-127,-127,-127, 127,-127, 127 },
+ { -127,-127,-127, 127, 127,-127,-127,-127 },
+};
+
+const ubit_t gsm0503_ahs_ic_ubit[4][4] = {
+ { 0,0,0,0 },
+ { 1,0,0,1 },
+ { 1,1,1,0 },
+ { 0,1,1,1 },
+};
+
+const sbit_t gsm0503_ahs_ic_sbit[4][4] = {
+ { 127, 127, 127, 127 },
+ { -127, 127, 127,-127 },
+ { -127,-127,-127, 127 },
+ { 127,-127,-127,-127 },
+};
+
+const uint8_t gsm0503_tch_hr_interleaving[228][2] = {
+ { 0 ,0 }, { 1 ,2 }, { 78 ,1 }, { 79 ,3 }, { 48 ,0 }, { 49 ,2 },
+ { 54 ,1 }, { 55 ,3 }, { 24 ,0 }, { 25 ,2 }, { 30 ,1 }, { 31 ,3 },
+ { 72 ,0 }, { 73 ,2 }, { 6 ,1 }, { 7 ,3 }, { 96 ,0 }, { 97 ,2 },
+ { 12 ,0 }, { 13 ,2 }, { 102,1 }, { 103,3 }, { 60 ,0 }, { 61 ,2 },
+ { 66 ,1 }, { 67 ,3 }, { 90 ,1 }, { 91 ,3 }, { 36 ,0 }, { 37 ,2 },
+ { 42 ,1 }, { 43 ,3 }, { 18 ,1 }, { 19 ,3 }, { 84 ,0 }, { 85 ,2 },
+ { 108,0 }, { 109,2 }, { 2 ,0 }, { 3 ,2 }, { 80 ,1 }, { 81 ,3 },
+ { 50 ,0 }, { 51 ,2 }, { 56 ,1 }, { 57 ,3 }, { 26 ,0 }, { 27 ,2 },
+ { 32 ,1 }, { 33 ,3 }, { 74 ,0 }, { 75 ,2 }, { 8 ,1 }, { 9 ,3 },
+ { 98 ,0 }, { 99 ,2 }, { 14 ,0 }, { 15 ,2 }, { 104,1 }, { 105,3 },
+ { 62 ,0 }, { 63 ,2 }, { 68 ,1 }, { 69 ,3 }, { 92 ,1 }, { 93 ,3 },
+ { 38 ,0 }, { 39 ,2 }, { 44 ,1 }, { 45 ,3 }, { 20 ,1 }, { 21 ,3 },
+ { 86 ,0 }, { 87 ,2 }, { 110,0 }, { 111,2 }, { 4 ,0 }, { 5 ,2 },
+ { 82 ,1 }, { 83 ,3 }, { 52 ,0 }, { 53 ,2 }, { 58 ,1 }, { 59 ,3 },
+ { 28 ,0 }, { 29 ,2 }, { 34 ,1 }, { 35 ,3 }, { 76 ,0 }, { 77 ,2 },
+ { 10 ,1 }, { 12 ,3 }, { 100,0 }, { 101,2 }, { 16 ,0 }, { 17 ,2 },
+ { 106,1 }, { 107,3 }, { 64 ,0 }, { 65 ,2 }, { 70 ,1 }, { 71 ,3 },
+ { 94 ,1 }, { 95 ,3 }, { 40 ,0 }, { 41 ,2 }, { 46 ,1 }, { 47 ,3 },
+ { 22 ,1 }, { 23 ,3 }, { 88 ,0 }, { 89 ,2 }, { 112,0 }, { 113,2 },
+ { 6 ,0 }, { 7 ,2 }, { 84 ,1 }, { 85 ,3 }, { 54 ,0 }, { 55 ,2 },
+ { 60 ,1 }, { 61 ,3 }, { 30 ,0 }, { 31 ,2 }, { 36 ,1 }, { 37 ,3 },
+ { 78 ,0 }, { 79 ,2 }, { 12 ,1 }, { 13 ,3 }, { 102,0 }, { 103,2 },
+ { 18 ,0 }, { 19 ,2 }, { 108,1 }, { 109,3 }, { 66 ,0 }, { 67 ,2 },
+ { 72 ,1 }, { 73 ,3 }, { 96 ,1 }, { 97 ,3 }, { 42 ,0 }, { 43 ,2 },
+ { 48 ,1 }, { 49 ,3 }, { 24 ,1 }, { 25 ,3 }, { 90 ,0 }, { 91 ,2 },
+ { 0 ,1 }, { 1 ,3 }, { 8 ,0 }, { 9 ,2 }, { 86 ,1 }, { 87 ,3 },
+ { 56 ,0 }, { 57 ,2 }, { 62 ,1 }, { 63 ,3 }, { 32 ,0 }, { 33 ,2 },
+ { 38 ,1 }, { 39 ,3 }, { 80 ,0 }, { 81 ,2 }, { 14 ,1 }, { 15 ,3 },
+ { 104,0 }, { 105,2 }, { 20 ,0 }, { 21 ,2 }, { 110,1 }, { 111,3 },
+ { 68 ,0 }, { 69 ,2 }, { 74 ,1 }, { 75 ,3 }, { 98 ,1 }, { 99 ,3 },
+ { 44 ,0 }, { 45 ,2 }, { 50 ,1 }, { 51 ,3 }, { 26 ,1 }, { 27 ,3 },
+ { 92 ,0 }, { 93 ,2 }, { 2 ,1 }, { 3 ,3 }, { 10 ,0 }, { 11 ,2 },
+ { 88 ,1 }, { 89 ,3 }, { 58 ,0 }, { 59 ,2 }, { 64 ,1 }, { 65 ,3 },
+ { 34 ,0 }, { 35 ,2 }, { 40 ,1 }, { 41 ,3 }, { 82 ,0 }, { 83 ,2 },
+ { 16 ,1 }, { 17 ,3 }, { 106,0 }, { 107,2 }, { 22 ,0 }, { 23 ,2 },
+ { 112,1 }, { 113,3 }, { 70 ,0 }, { 71 ,2 }, { 76 ,1 }, { 77 ,3 },
+ { 100,1 }, { 101,3 }, { 46 ,0 }, { 47 ,2 }, { 52 ,1 }, { 53 ,3 },
+ { 28 ,1 }, { 29 ,3 }, { 94 ,0 }, { 95 ,2 }, { 4 ,1 }, { 5 ,3 },
+};
+
diff --git a/src/osmo-bts-trx/gsm0503_tables.h b/src/osmo-bts-trx/gsm0503_tables.h
new file mode 100644
index 0000000..63b45a4
--- /dev/null
+++ b/src/osmo-bts-trx/gsm0503_tables.h
@@ -0,0 +1,19 @@
+#ifndef _0503_TABLES_H
+#define _0503_TABLES_H
+
+extern const ubit_t gsm0503_pdtch_hl_hn_ubit[4][8];
+extern const sbit_t gsm0503_pdtch_hl_hn_sbit[4][8];
+extern const ubit_t gsm0503_usf2six[8][6];
+extern const ubit_t gsm0503_usf2twelve_ubit[8][12];
+extern const sbit_t gsm0503_usf2twelve_sbit[8][12];
+extern const uint8_t gsm0503_puncture_cs2[588];
+extern const uint8_t gsm0503_puncture_cs3[676];
+extern const uint8_t gsm0503_gsm_fr_map[76];
+extern const uint8_t gsm0503_gsm_efr_protected_bits[65];
+extern const ubit_t gsm0503_afs_ic_ubit[4][8];
+extern const sbit_t gsm0503_afs_ic_sbit[4][8];
+extern const ubit_t gsm0503_ahs_ic_ubit[4][4];
+extern const sbit_t gsm0503_ahs_ic_sbit[4][4];
+extern const uint8_t gsm0503_tch_hr_interleaving[228][2];
+
+#endif /* _0503_TABLES_H */
diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c
new file mode 100644
index 0000000..42cb17b
--- /dev/null
+++ b/src/osmo-bts-trx/l1_if.c
@@ -0,0 +1,716 @@
+/*
+ * layer 1 primitive handling and interface
+ *
+ * Copyright (C) 2013 Andreas Eversberg <jolly@eversberg.eu>
+ * Copyright (C) 2015 Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
+ *
+ * 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 <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/bits.h>
+
+#include <osmo-bts/logging.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/oml.h>
+#include <osmo-bts/rsl.h>
+#include <osmo-bts/l1sap.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/amr.h>
+#include <osmo-bts/abis.h>
+
+#include "l1_if.h"
+#include "trx_if.h"
+#include "scheduler.h"
+
+
+static const uint8_t transceiver_chan_types[_GSM_PCHAN_MAX] = {
+ [GSM_PCHAN_NONE] = 8,
+ [GSM_PCHAN_CCCH] = 4,
+ [GSM_PCHAN_CCCH_SDCCH4] = 5,
+ [GSM_PCHAN_TCH_F] = 1,
+ [GSM_PCHAN_TCH_H] = 2,
+ [GSM_PCHAN_SDCCH8_SACCH8C] = 7,
+ [GSM_PCHAN_PDCH] = 13,
+ //[GSM_PCHAN_TCH_F_PDCH] = FIXME,
+ [GSM_PCHAN_UNKNOWN] = 0,
+};
+
+
+/*
+ * create/destroy trx l1 instance
+ */
+
+struct trx_l1h *l1if_open(struct gsm_bts_trx *trx)
+{
+ struct trx_l1h *l1h;
+ int rc;
+
+ l1h = talloc_zero(tall_bts_ctx, struct trx_l1h);
+ if (!l1h)
+ return NULL;
+ l1h->trx = trx;
+ trx->role_bts.l1h = l1h;
+
+ trx_sched_init(l1h);
+
+ rc = trx_if_open(l1h);
+ if (rc < 0) {
+ LOGP(DL1C, LOGL_FATAL, "Cannot initialize scheduler\n");
+ goto err;
+ }
+
+ return l1h;
+
+err:
+ l1if_close(l1h);
+ trx->role_bts.l1h = NULL;
+ return NULL;
+}
+
+void l1if_close(struct trx_l1h *l1h)
+{
+ trx_if_close(l1h);
+ trx_sched_exit(l1h);
+ talloc_free(l1h);
+}
+
+void l1if_reset(struct trx_l1h *l1h)
+{
+}
+
+static void check_transceiver_availability_trx(struct trx_l1h *l1h, int avail)
+{
+ struct gsm_bts_trx *trx = l1h->trx;
+ uint8_t tn;
+
+ /* HACK, we should change state when we receive first clock from
+ * transceiver */
+ if (avail) {
+ /* signal availability */
+ oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
+ oml_mo_tx_sw_act_rep(&trx->mo);
+ oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
+ oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
+
+ for (tn = 0; tn < 8; tn++)
+ oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED,
+ (l1h->config.slotmask & (1 << tn)) ?
+ NM_AVSTATE_DEPENDENCY :
+ NM_AVSTATE_NOT_INSTALLED);
+ } else {
+ oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED,
+ NM_AVSTATE_OFF_LINE);
+ oml_mo_state_chg(&trx->bb_transc.mo, NM_OPSTATE_DISABLED,
+ NM_AVSTATE_OFF_LINE);
+
+ for (tn = 0; tn < 8; tn++)
+ oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED,
+ NM_AVSTATE_OFF_LINE);
+ }
+}
+
+int check_transceiver_availability(struct gsm_bts *bts, int avail)
+{
+ struct gsm_bts_trx *trx;
+ struct trx_l1h *l1h;
+
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = trx_l1h_hdl(trx);
+ check_transceiver_availability_trx(l1h, avail);
+ }
+ return 0;
+}
+
+
+/*
+ * transceiver provisioning
+ */
+int l1if_provision_transceiver_trx(struct trx_l1h *l1h)
+{
+ uint8_t tn;
+
+ if (!transceiver_available)
+ return -EIO;
+
+ if (l1h->config.poweron
+ && l1h->config.tsc_valid
+ && l1h->config.bsic_valid
+ && l1h->config.arfcn_valid) {
+ /* before power on */
+ if (l1h->config.arfcn_valid && !l1h->config.arfcn_sent) {
+ trx_if_cmd_rxtune(l1h, l1h->config.arfcn);
+ trx_if_cmd_txtune(l1h, l1h->config.arfcn);
+ l1h->config.arfcn_sent = 1;
+ }
+ if (l1h->config.tsc_valid && !l1h->config.tsc_sent) {
+ trx_if_cmd_settsc(l1h, l1h->config.tsc);
+ l1h->config.tsc_sent = 1;
+ }
+ if (l1h->config.bsic_valid && !l1h->config.bsic_sent) {
+ trx_if_cmd_setbsic(l1h, l1h->config.bsic);
+ l1h->config.bsic_sent = 1;
+ }
+
+ if (!l1h->config.poweron_sent) {
+ trx_if_cmd_poweron(l1h);
+ l1h->config.poweron_sent = 1;
+ }
+
+ /* after power on */
+ if (l1h->config.rxgain_valid && !l1h->config.rxgain_sent) {
+ trx_if_cmd_setrxgain(l1h, l1h->config.rxgain);
+ l1h->config.rxgain_sent = 1;
+ }
+ if (l1h->config.power_valid && !l1h->config.power_sent) {
+ trx_if_cmd_setpower(l1h, l1h->config.power);
+ l1h->config.power_sent = 1;
+ }
+ if (l1h->config.maxdly_valid && !l1h->config.maxdly_sent) {
+ trx_if_cmd_setmaxdly(l1h, l1h->config.maxdly);
+ l1h->config.maxdly_sent = 1;
+ }
+ for (tn = 0; tn < 8; tn++) {
+ if (l1h->config.slottype_valid[tn]
+ && !l1h->config.slottype_sent[tn]) {
+ trx_if_cmd_setslot(l1h, tn,
+ l1h->config.slottype[tn]);
+ l1h->config.slottype_sent[tn] = 1;
+ }
+ }
+ return 0;
+ }
+
+ if (!l1h->config.poweron && !l1h->config.poweron_sent) {
+ trx_if_cmd_poweroff(l1h);
+ l1h->config.poweron_sent = 1;
+ l1h->config.rxgain_sent = 0;
+ l1h->config.power_sent = 0;
+ l1h->config.maxdly_sent = 0;
+ for (tn = 0; tn < 8; tn++)
+ l1h->config.slottype_sent[tn] = 0;
+ }
+
+ return 0;
+}
+
+int l1if_provision_transceiver(struct gsm_bts *bts)
+{
+ struct gsm_bts_trx *trx;
+ struct trx_l1h *l1h;
+ uint8_t tn;
+
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = trx_l1h_hdl(trx);
+ l1h->config.arfcn_sent = 0;
+ l1h->config.tsc_sent = 0;
+ l1h->config.bsic_sent = 0;
+ l1h->config.poweron_sent = 0;
+ l1h->config.rxgain_sent = 0;
+ l1h->config.power_sent = 0;
+ l1h->config.maxdly_sent = 0;
+ for (tn = 0; tn < 8; tn++)
+ l1h->config.slottype_sent[tn] = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+ return 0;
+}
+
+/*
+ * activation/configuration/deactivation of transceiver's TRX
+ */
+
+/* initialize the layer1 */
+static int trx_init(struct gsm_bts_trx *trx)
+{
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ /* power on transceiver, if not already */
+ if (!l1h->config.poweron) {
+ l1h->config.poweron = 1;
+ l1h->config.poweron_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+
+ if (trx == trx->bts->c0)
+ lchan_init_lapdm(&trx->ts[0].lchan[4]);
+
+ /* Set to Operational State: Enabled */
+ oml_mo_state_chg(&trx->mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
+
+ /* Send OPSTART ack */
+ return oml_mo_opstart_ack(&trx->mo);
+}
+
+/* deactivate transceiver */
+int bts_model_trx_close(struct gsm_bts_trx *trx)
+{
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+ enum gsm_phys_chan_config pchan = trx->ts[0].pchan;
+
+ /* close all logical channels and reset timeslots */
+ trx_sched_reset(l1h);
+
+ /* deactivate lchan for CCCH */
+ if (pchan == GSM_PCHAN_CCCH || pchan == GSM_PCHAN_CCCH_SDCCH4) {
+ lchan_set_state(&trx->ts[0].lchan[4], LCHAN_S_INACTIVE);
+ }
+
+ /* power off transceiver, if not already */
+ if (l1h->config.poweron) {
+ l1h->config.poweron = 0;
+ l1h->config.poweron_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+
+ /* Set to Operational State: Disabled */
+ check_transceiver_availability_trx(l1h, 0);
+
+ return 0;
+}
+
+/* on RSL failure, deactivate transceiver */
+void bts_model_abis_close(struct gsm_bts *bts)
+{
+ struct gsm_bts_trx *trx;
+
+ llist_for_each_entry(trx, &bts->trx_list, list)
+ bts_model_trx_close(trx);
+}
+
+int bts_model_adjst_ms_pwr(struct gsm_lchan *lchan)
+{
+ /* we always implement the power control loop in osmo-bts software, as
+ * there is no automatism in the underlying osmo-trx */
+ return 0;
+}
+
+/* set bts attributes */
+static uint8_t trx_set_bts(struct gsm_bts *bts, struct tlv_parsed *new_attr)
+{
+ struct gsm_bts_trx *trx;
+ struct trx_l1h *l1h;
+ uint8_t bsic = bts->bsic;
+ struct gsm_bts_role_bts *btsb = bts_role_bts(bts);
+
+ if (TLVP_PRESENT(new_attr, NM_ATT_CONN_FAIL_CRIT)) {
+ const uint8_t *val = TLVP_VAL(new_attr, NM_ATT_CONN_FAIL_CRIT);
+ btsb->radio_link_timeout = val[1];
+ }
+
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = trx_l1h_hdl(trx);
+ if (l1h->config.bsic != bsic || !l1h->config.bsic_valid) {
+ l1h->config.bsic = bsic;
+ l1h->config.bsic_valid = 1;
+ l1h->config.bsic_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+ }
+ check_transceiver_availability(bts, transceiver_available);
+
+
+ return 0;
+}
+
+/* set trx attributes */
+static uint8_t trx_set_trx(struct gsm_bts_trx *trx)
+{
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+ uint16_t arfcn = trx->arfcn;
+
+ if (l1h->config.arfcn != arfcn || !l1h->config.arfcn_valid) {
+ l1h->config.arfcn = arfcn;
+ l1h->config.arfcn_valid = 1;
+ l1h->config.arfcn_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+
+ if (l1h->config.power_oml) {
+ l1h->config.power = trx->max_power_red;
+ l1h->config.power_valid = 1;
+ l1h->config.power_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+
+ return 0;
+}
+
+/* set ts attributes */
+static uint8_t trx_set_ts(struct gsm_bts_trx_ts *ts)
+{
+ struct trx_l1h *l1h = trx_l1h_hdl(ts->trx);
+ uint8_t tn = ts->nr;
+ uint16_t tsc = ts->tsc;
+ enum gsm_phys_chan_config pchan = ts->pchan;
+ uint8_t slottype;
+ int rc;
+
+ /* all TSC of all timeslots must be equal, because transceiver only
+ * supports one TSC per TRX */
+
+ if (l1h->config.tsc != tsc || !l1h->config.tsc_valid) {
+ l1h->config.tsc = tsc;
+ l1h->config.tsc_valid = 1;
+ l1h->config.tsc_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+
+ /* set physical channel */
+ rc = trx_sched_set_pchan(l1h, tn, pchan);
+ if (rc)
+ return NM_NACK_RES_NOTAVAIL;
+
+ /* activate lchan for CCCH */
+ if (pchan == GSM_PCHAN_CCCH || pchan == GSM_PCHAN_CCCH_SDCCH4) {
+ ts->lchan[4].rel_act_kind = LCHAN_REL_ACT_OML;
+ lchan_set_state(&ts->lchan[4], LCHAN_S_ACTIVE);
+ }
+
+ slottype = transceiver_chan_types[pchan];
+
+ if (l1h->config.slottype[tn] != slottype
+ || !l1h->config.slottype_valid[tn]) {
+ l1h->config.slottype[tn] = slottype;
+ l1h->config.slottype_valid[tn] = 1;
+ l1h->config.slottype_sent[tn] = 0;
+ l1if_provision_transceiver_trx(l1h);
+ }
+
+ return 0;
+}
+
+
+/*
+ * primitive handling
+ */
+
+/* enable ciphering */
+static int l1if_set_ciphering(struct trx_l1h *l1h, struct gsm_lchan *lchan,
+ uint8_t chan_nr, int downlink)
+{
+ /* ciphering already enabled in both directions */
+ if (lchan->ciph_state == LCHAN_CIPH_RXTX_CONF)
+ return -EINVAL;
+
+ if (!downlink) {
+ /* set uplink */
+ trx_sched_set_cipher(l1h, chan_nr, 0, lchan->encr.alg_id - 1,
+ lchan->encr.key, lchan->encr.key_len);
+ lchan->ciph_state = LCHAN_CIPH_RX_CONF;
+ } else {
+ /* set downlink and also set uplink, if not already */
+ if (lchan->ciph_state != LCHAN_CIPH_RX_CONF) {
+ trx_sched_set_cipher(l1h, chan_nr, 0,
+ lchan->encr.alg_id - 1, lchan->encr.key,
+ lchan->encr.key_len);
+ }
+ trx_sched_set_cipher(l1h, chan_nr, 1, lchan->encr.alg_id - 1,
+ lchan->encr.key, lchan->encr.key_len);
+ lchan->ciph_state = LCHAN_CIPH_RXTX_CONF;
+ }
+
+ return 0;
+}
+
+static int mph_info_chan_confirm(struct trx_l1h *l1h, uint8_t chan_nr,
+ enum osmo_mph_info_type type, uint8_t cause)
+{
+ struct osmo_phsap_prim l1sap;
+
+ memset(&l1sap, 0, sizeof(l1sap));
+ osmo_prim_init(&l1sap.oph, SAP_GSM_PH, PRIM_MPH_INFO, PRIM_OP_CONFIRM,
+ NULL);
+ l1sap.u.info.type = type;
+ l1sap.u.info.u.act_cnf.chan_nr = chan_nr;
+ l1sap.u.info.u.act_cnf.cause = cause;
+
+ return l1sap_up(l1h->trx, &l1sap);
+}
+
+int l1if_mph_time_ind(struct gsm_bts *bts, uint32_t fn)
+{
+ struct osmo_phsap_prim l1sap;
+
+ memset(&l1sap, 0, sizeof(l1sap));
+ osmo_prim_init(&l1sap.oph, SAP_GSM_PH, PRIM_MPH_INFO,
+ PRIM_OP_INDICATION, NULL);
+ l1sap.u.info.type = PRIM_INFO_TIME;
+ l1sap.u.info.u.time_ind.fn = fn;
+
+ if (!bts->c0)
+ return -EINVAL;
+
+ return l1sap_up(bts->c0, &l1sap);
+}
+
+
+void l1if_fill_meas_res(struct osmo_phsap_prim *l1sap, uint8_t chan_nr, float ta,
+ float ber, float rssi)
+{
+ memset(l1sap, 0, sizeof(*l1sap));
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_MPH_INFO,
+ PRIM_OP_INDICATION, NULL);
+ l1sap->u.info.type = PRIM_INFO_MEAS;
+ l1sap->u.info.u.meas_ind.chan_nr = chan_nr;
+ l1sap->u.info.u.meas_ind.ta_offs_qbits = (int16_t)(ta*4);
+ l1sap->u.info.u.meas_ind.ber10k = (unsigned int) (ber * 10000);
+ l1sap->u.info.u.meas_ind.inv_rssi = (uint8_t) (rssi * -1);
+}
+
+int l1if_process_meas_res(struct gsm_bts_trx *trx, uint8_t tn, uint32_t fn, uint8_t chan_nr,
+ int n_errors, int n_bits_total, float rssi, float toa)
+{
+ struct gsm_lchan *lchan = &trx->ts[tn].lchan[l1sap_chan2ss(chan_nr)];
+ struct osmo_phsap_prim l1sap;
+ /* 100% BER is n_bits_total is 0 */
+ float ber = n_bits_total==0 ? 1.0 : (float)n_errors / (float)n_bits_total;
+
+ LOGP(DMEAS, LOGL_DEBUG, "RX L1 frame %s fn=%u chan_nr=0x%02x MS pwr=%ddBm rssi=%.1f dBFS "
+ "ber=%.2f%% (%d/%d bits) L1_ta=%d rqd_ta=%d toa=%.2f\n",
+ gsm_lchan_name(lchan), fn, chan_nr, ms_pwr_dbm(lchan->ts->trx->bts->band, lchan->ms_power),
+ rssi, ber*100, n_errors, n_bits_total, lchan->meas.l1_info[1], lchan->rqd_ta, toa);
+
+ l1if_fill_meas_res(&l1sap, chan_nr, lchan->rqd_ta + toa, ber, rssi);
+
+ return l1sap_up(trx, &l1sap);
+}
+
+
+/* primitive from common part */
+int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap)
+{
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+ struct msgb *msg = l1sap->oph.msg;
+ uint8_t chan_nr;
+ uint8_t tn, ss;
+ int rc = 0;
+ struct gsm_lchan *lchan;
+
+ switch (OSMO_PRIM_HDR(&l1sap->oph)) {
+ case OSMO_PRIM(PRIM_PH_DATA, PRIM_OP_REQUEST):
+ if (!msg)
+ break;
+ /* put data into scheduler's queue */
+ return trx_sched_ph_data_req(l1h, l1sap);
+ case OSMO_PRIM(PRIM_TCH, PRIM_OP_REQUEST):
+ if (!msg)
+ break;
+ /* put data into scheduler's queue */
+ return trx_sched_tch_req(l1h, l1sap);
+ case OSMO_PRIM(PRIM_MPH_INFO, PRIM_OP_REQUEST):
+ switch (l1sap->u.info.type) {
+ case PRIM_INFO_ACT_CIPH:
+ chan_nr = l1sap->u.info.u.ciph_req.chan_nr;
+ tn = L1SAP_CHAN2TS(chan_nr);
+ ss = l1sap_chan2ss(chan_nr);
+ lchan = &trx->ts[tn].lchan[ss];
+ if (l1sap->u.info.u.ciph_req.uplink)
+ l1if_set_ciphering(l1h, lchan, chan_nr, 0);
+ if (l1sap->u.info.u.ciph_req.downlink)
+ l1if_set_ciphering(l1h, lchan, chan_nr, 1);
+ break;
+ case PRIM_INFO_ACTIVATE:
+ case PRIM_INFO_DEACTIVATE:
+ case PRIM_INFO_MODIFY:
+ chan_nr = l1sap->u.info.u.act_req.chan_nr;
+ tn = L1SAP_CHAN2TS(chan_nr);
+ ss = l1sap_chan2ss(chan_nr);
+ lchan = &trx->ts[tn].lchan[ss];
+ if (l1sap->u.info.type == PRIM_INFO_ACTIVATE) {
+ if ((chan_nr & 0x80)) {
+ LOGP(DL1C, LOGL_ERROR, "Cannot activate"
+ " chan_nr 0x%02x\n", chan_nr);
+ break;
+ }
+ /* activate dedicated channel */
+ trx_sched_set_lchan(l1h, chan_nr, 0x00, 1);
+ /* activate associated channel */
+ trx_sched_set_lchan(l1h, chan_nr, 0x40, 1);
+ /* set mode */
+ trx_sched_set_mode(l1h, chan_nr,
+ lchan->rsl_cmode, lchan->tch_mode,
+ lchan->tch.amr_mr.num_modes,
+ lchan->tch.amr_mr.mode[0].mode,
+ lchan->tch.amr_mr.mode[1].mode,
+ lchan->tch.amr_mr.mode[2].mode,
+ lchan->tch.amr_mr.mode[3].mode,
+ amr_get_initial_mode(lchan),
+ (lchan->ho.active == 1));
+ /* init lapdm */
+ lchan_init_lapdm(lchan);
+ /* set lchan active */
+ lchan_set_state(lchan, LCHAN_S_ACTIVE);
+ /* set initial ciphering */
+ l1if_set_ciphering(l1h, lchan, chan_nr, 0);
+ l1if_set_ciphering(l1h, lchan, chan_nr, 1);
+ if (lchan->encr.alg_id)
+ lchan->ciph_state = LCHAN_CIPH_RXTX_CONF;
+ else
+ lchan->ciph_state = LCHAN_CIPH_NONE;
+
+ /* confirm */
+ mph_info_chan_confirm(l1h, chan_nr,
+ PRIM_INFO_ACTIVATE, 0);
+ break;
+ }
+ if (l1sap->u.info.type == PRIM_INFO_MODIFY) {
+ /* change mode */
+ trx_sched_set_mode(l1h, chan_nr,
+ lchan->rsl_cmode, lchan->tch_mode,
+ lchan->tch.amr_mr.num_modes,
+ lchan->tch.amr_mr.mode[0].mode,
+ lchan->tch.amr_mr.mode[1].mode,
+ lchan->tch.amr_mr.mode[2].mode,
+ lchan->tch.amr_mr.mode[3].mode,
+ amr_get_initial_mode(lchan),
+ 0);
+ break;
+ }
+ if ((chan_nr & 0x80)) {
+ LOGP(DL1C, LOGL_ERROR, "Cannot deactivate "
+ "chan_nr 0x%02x\n", chan_nr);
+ break;
+ }
+ /* deactivate associated channel */
+ trx_sched_set_lchan(l1h, chan_nr, 0x40, 0);
+ if (!l1sap->u.info.u.act_req.sacch_only) {
+ /* set lchan inactive */
+ lchan_set_state(lchan, LCHAN_S_NONE);
+ /* deactivate dedicated channel */
+ trx_sched_set_lchan(l1h, chan_nr, 0x00, 0);
+ /* confirm only on dedicated channel */
+ mph_info_chan_confirm(l1h, chan_nr,
+ PRIM_INFO_DEACTIVATE, 0);
+ lchan->ciph_state = 0; /* FIXME: do this in common/\*.c */
+ }
+ break;
+ default:
+ LOGP(DL1C, LOGL_NOTICE, "unknown MPH-INFO.req %d\n",
+ l1sap->u.info.type);
+ rc = -EINVAL;
+ goto done;
+ }
+ break;
+ default:
+ LOGP(DL1C, LOGL_NOTICE, "unknown prim %d op %d\n",
+ l1sap->oph.primitive, l1sap->oph.operation);
+ rc = -EINVAL;
+ goto done;
+ }
+
+done:
+ if (msg)
+ msgb_free(msg);
+ return rc;
+}
+
+
+/*
+ * oml handling
+ */
+
+/* callback from OML */
+int bts_model_check_oml(struct gsm_bts *bts, uint8_t msg_type,
+ struct tlv_parsed *old_attr, struct tlv_parsed *new_attr,
+ void *obj)
+{
+ /* FIXME: check if the attributes are valid */
+ return 0;
+}
+
+/* callback from OML */
+int bts_model_apply_oml(struct gsm_bts *bts, struct msgb *msg,
+ struct tlv_parsed *new_attr, int kind, void *obj)
+{
+ struct abis_om_fom_hdr *foh = msgb_l3(msg);
+ int cause = 0;
+
+ switch (foh->msg_type) {
+ case NM_MT_SET_BTS_ATTR:
+ cause = trx_set_bts(obj, new_attr);
+ break;
+ case NM_MT_SET_RADIO_ATTR:
+ cause = trx_set_trx(obj);
+ break;
+ case NM_MT_SET_CHAN_ATTR:
+ cause = trx_set_ts(obj);
+ break;
+ }
+
+ return oml_fom_ack_nack(msg, cause);
+}
+
+/* callback from OML */
+int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo,
+ void *obj)
+{
+ int rc;
+
+ switch (mo->obj_class) {
+ case NM_OC_RADIO_CARRIER:
+ /* activate transceiver */
+ rc = trx_init(obj);
+ break;
+ case NM_OC_CHANNEL:
+ /* configure timeslot */
+ rc = 0; //ts_connect(obj);
+
+ /* Set to Operational State: Enabled */
+ oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
+
+ /* Send OPSTART ack */
+ rc = oml_mo_opstart_ack(mo);
+
+ break;
+ case NM_OC_BTS:
+ case NM_OC_SITE_MANAGER:
+ case NM_OC_BASEB_TRANSC:
+ case NM_OC_GPRS_NSE:
+ case NM_OC_GPRS_CELL:
+ case NM_OC_GPRS_NSVC:
+ oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, -1);
+ rc = oml_mo_opstart_ack(mo);
+ break;
+ default:
+ rc = oml_mo_opstart_nack(mo, NM_NACK_OBJCLASS_NOTSUPP);
+ }
+ return rc;
+}
+
+int bts_model_chg_adm_state(struct gsm_bts *bts, struct gsm_abis_mo *mo,
+ void *obj, uint8_t adm_state)
+{
+ /* blindly accept all state changes */
+ mo->nm_state.administrative = adm_state;
+ return oml_mo_statechg_ack(mo);
+}
+
+int bts_model_trx_deact_rf(struct gsm_bts_trx *trx)
+{
+ return 0;
+}
+
+int bts_model_oml_estab(struct gsm_bts *bts)
+{
+ return 0;
+}
+
diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h
new file mode 100644
index 0000000..278537e
--- /dev/null
+++ b/src/osmo-bts-trx/l1_if.h
@@ -0,0 +1,179 @@
+#ifndef L1_IF_H_TRX
+#define L1_IF_H_TRX
+
+/* These types define the different channels on a multiframe.
+ * Each channel has queues and can be activated individually.
+ */
+enum trx_chan_type {
+ TRXC_IDLE = 0,
+ TRXC_FCCH,
+ TRXC_SCH,
+ TRXC_BCCH,
+ TRXC_RACH,
+ TRXC_CCCH,
+ TRXC_TCHF,
+ TRXC_TCHH_0,
+ TRXC_TCHH_1,
+ TRXC_SDCCH4_0,
+ TRXC_SDCCH4_1,
+ TRXC_SDCCH4_2,
+ TRXC_SDCCH4_3,
+ TRXC_SDCCH8_0,
+ TRXC_SDCCH8_1,
+ TRXC_SDCCH8_2,
+ TRXC_SDCCH8_3,
+ TRXC_SDCCH8_4,
+ TRXC_SDCCH8_5,
+ TRXC_SDCCH8_6,
+ TRXC_SDCCH8_7,
+ TRXC_SACCHTF,
+ TRXC_SACCHTH_0,
+ TRXC_SACCHTH_1,
+ TRXC_SACCH4_0,
+ TRXC_SACCH4_1,
+ TRXC_SACCH4_2,
+ TRXC_SACCH4_3,
+ TRXC_SACCH8_0,
+ TRXC_SACCH8_1,
+ TRXC_SACCH8_2,
+ TRXC_SACCH8_3,
+ TRXC_SACCH8_4,
+ TRXC_SACCH8_5,
+ TRXC_SACCH8_6,
+ TRXC_SACCH8_7,
+ TRXC_PDTCH,
+ TRXC_PTCCH,
+ _TRX_CHAN_MAX
+};
+
+/* States each channel on a multiframe */
+struct trx_chan_state {
+ /* scheduler */
+ uint8_t active; /* Channel is active */
+ ubit_t *dl_bursts; /* burst buffer for TX */
+ sbit_t *ul_bursts; /* burst buffer for RX */
+ uint32_t ul_first_fn; /* fn of first burst */
+ uint8_t ul_mask; /* mask of received bursts */
+
+ /* RSSI / TOA */
+ uint8_t rssi_num; /* number of RSSI values */
+ float rssi_sum; /* sum of RSSI values */
+ uint8_t toa_num; /* number of TOA values */
+ float toa_sum; /* sum of TOA values */
+
+ /* loss detection */
+ uint8_t lost; /* (SACCH) loss detection */
+
+ /* mode */
+ uint8_t rsl_cmode, tch_mode; /* mode for TCH channels */
+
+ /* AMR */
+ uint8_t codec[4]; /* 4 possible codecs for amr */
+ int codecs; /* number of possible codecs */
+ float ber_sum; /* sum of bit error rates */
+ int ber_num; /* number of bit error rates */
+ uint8_t ul_ft; /* current uplink FT index */
+ uint8_t dl_ft; /* current downlink FT index */
+ uint8_t ul_cmr; /* current uplink CMR index */
+ uint8_t dl_cmr; /* current downlink CMR index */
+ uint8_t amr_loop; /* if AMR loop is enabled */
+
+ /* TCH/H */
+ uint8_t dl_ongoing_facch; /* FACCH/H on downlink */
+ uint8_t ul_ongoing_facch; /* FACCH/H on uplink */
+
+ /* encryption */
+ int ul_encr_algo; /* A5/x encry algo downlink */
+ int dl_encr_algo; /* A5/x encry algo uplink */
+ int ul_encr_key_len;
+ int dl_encr_key_len;
+ uint8_t ul_encr_key[8];
+ uint8_t dl_encr_key[8];
+
+ /* measurements */
+ struct {
+ uint8_t clock; /* cyclic clock counter */
+ int8_t rssi[32]; /* last RSSI values */
+ int rssi_count; /* received RSSI values */
+ int rssi_valid_count; /* number of stored value */
+ int rssi_got_burst; /* any burst received so far */
+ float toa_sum; /* sum of TOA values */
+ int toa_num; /* number of TOA value */
+ } meas;
+
+ /* handover */
+ uint8_t ho_rach_detect; /* if rach detection is on */
+};
+
+struct trx_config {
+ uint8_t poweron; /* poweron(1) or poweroff(0) */
+ int poweron_sent;
+
+ int arfcn_valid;
+ uint16_t arfcn;
+ int arfcn_sent;
+
+ int tsc_valid;
+ uint8_t tsc;
+ int tsc_sent;
+
+ int bsic_valid;
+ uint8_t bsic;
+ int bsic_sent;
+
+ int rxgain_valid;
+ int rxgain;
+ int rxgain_sent;
+
+ int power_valid;
+ int power;
+ int power_oml;
+ int power_sent;
+
+ int maxdly_valid;
+ int maxdly;
+ int maxdly_sent;
+
+ uint8_t slotmask;
+
+ int slottype_valid[8];
+ uint8_t slottype[8];
+ int slottype_sent[8];
+};
+
+struct trx_l1h {
+ struct llist_head trx_ctrl_list;
+
+ struct gsm_bts_trx *trx;
+
+ struct osmo_fd trx_ofd_ctrl;
+ struct osmo_timer_list trx_ctrl_timer;
+ struct osmo_fd trx_ofd_data;
+
+ /* transceiver config */
+ struct trx_config config;
+
+ uint8_t mf_index[8]; /* selected multiframe index */
+ uint32_t mf_last_fn[8]; /* last received frame */
+ uint8_t mf_period[8]; /* period of multiframe */
+ struct trx_sched_frame *mf_frames[8]; /* pointer to frame layout */
+
+ /* Channel states for all channels on all timeslots */
+ struct trx_chan_state chan_states[8][_TRX_CHAN_MAX];
+ struct llist_head dl_prims[8]; /* Queue primitves for TX */
+ uint8_t ho_rach_detect[8][8];
+};
+
+struct trx_l1h *l1if_open(struct gsm_bts_trx *trx);
+void l1if_close(struct trx_l1h *l1h);
+void l1if_reset(struct trx_l1h *l1h);
+int check_transceiver_availability(struct gsm_bts *bts, int avail);
+int l1if_provision_transceiver_trx(struct trx_l1h *l1h);
+int l1if_provision_transceiver(struct gsm_bts *bts);
+int l1if_mph_time_ind(struct gsm_bts *bts, uint32_t fn);
+void l1if_fill_meas_res(struct osmo_phsap_prim *l1sap, uint8_t chan_nr, float ta,
+ float ber, float rssi);
+int l1if_process_meas_res(struct gsm_bts_trx *trx, uint8_t tn, uint32_t fn, uint8_t chan_nr,
+ int n_errors, int n_bits_total, float rssi, float toa);
+
+#endif /* L1_IF_H_TRX */
diff --git a/src/osmo-bts-trx/loops.c b/src/osmo-bts-trx/loops.c
new file mode 100644
index 0000000..fa38055
--- /dev/null
+++ b/src/osmo-bts-trx/loops.c
@@ -0,0 +1,339 @@
+/* Loop control for OsmoBTS-TRX */
+
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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 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 <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/l1sap.h>
+#include <osmocom/core/bits.h>
+
+#include "trx_if.h"
+#include "l1_if.h"
+#include "loops.h"
+
+#define MS_PWR_DBM(lvl) ms_pwr_dbm(gsm_arfcn2band(l1h->config.arfcn), lvl)
+
+/*
+ * MS Power loop
+ */
+
+int trx_ms_power_loop = 0;
+int8_t trx_target_rssi = -10;
+
+static int ms_power_diff(struct trx_l1h *l1h, struct gsm_lchan *lchan,
+ uint8_t chan_nr, struct trx_chan_state *chan_state, int8_t diff)
+{
+ int8_t new_power;
+
+ new_power = lchan->ms_power - (diff >> 1);
+
+ if (diff == 0)
+ return 0;
+
+ if (new_power < 0)
+ new_power = 0;
+
+ // FIXME: to go above 1W, we need to know classmark of MS
+ if (l1h->config.arfcn >= 512 && l1h->config.arfcn <= 885) {
+ if (new_power > 15)
+ new_power = 15;
+ } else {
+ if (new_power > 19)
+ new_power = 19;
+ }
+
+ /* a higher value means a lower level (and vice versa) */
+ if (new_power > lchan->ms_power + MS_LOWER_MAX)
+ new_power = lchan->ms_power + MS_LOWER_MAX;
+ else if (new_power < lchan->ms_power - MS_RAISE_MAX)
+ new_power = lchan->ms_power - MS_RAISE_MAX;
+
+ if (lchan->ms_power == new_power) {
+ LOGP(DLOOP, LOGL_INFO, "Keeping MS new_power of trx=%u "
+ "chan_nr=0x%02x at control level %d (%d dBm)\n",
+ l1h->trx->nr, chan_nr, new_power,
+ MS_PWR_DBM(new_power));
+
+ return 0;
+ }
+
+ LOGP(DLOOP, LOGL_INFO, "%s MS new_power of trx=%u chan_nr=0x%02x from "
+ "control level %d (%d dBm) to %d (%d dBm)\n",
+ (diff > 0) ? "Raising" : "Lowering",
+ l1h->trx->nr, chan_nr, lchan->ms_power,
+ MS_PWR_DBM(lchan->ms_power), new_power, MS_PWR_DBM(new_power));
+
+ lchan->ms_power = new_power;
+
+ return 0;
+}
+
+static int ms_power_val(struct trx_chan_state *chan_state, int8_t rssi)
+{
+ /* ignore inserted dummy frames, treat as lost frames */
+ if (rssi < -127)
+ return 0;
+
+ LOGP(DLOOP, LOGL_DEBUG, "Got RSSI value of %d\n", rssi);
+
+ chan_state->meas.rssi_count++;
+
+ chan_state->meas.rssi_got_burst = 1;
+
+ /* store and process RSSI */
+ if (chan_state->meas.rssi_valid_count
+ == ARRAY_SIZE(chan_state->meas.rssi))
+ return 0;
+ chan_state->meas.rssi[chan_state->meas.rssi_valid_count++] = rssi;
+ chan_state->meas.rssi_valid_count++;
+
+ return 0;
+}
+
+static int ms_power_clock(struct trx_l1h *l1h, struct gsm_lchan *lchan,
+ uint8_t chan_nr, struct trx_chan_state *chan_state)
+{
+ int rssi;
+ int i;
+
+ /* skip every second clock, to prevent oscillating due to roundtrip
+ * delay */
+ if (!(chan_state->meas.clock & 1))
+ return 0;
+
+ LOGP(DLOOP, LOGL_DEBUG, "Got SACCH master clock at RSSI count %d\n",
+ chan_state->meas.rssi_count);
+
+ /* wait for initial burst */
+ if (!chan_state->meas.rssi_got_burst)
+ return 0;
+
+ /* if no burst was received from MS at clock */
+ if (chan_state->meas.rssi_count == 0) {
+ LOGP(DLOOP, LOGL_NOTICE, "LOST SACCH frame of trx=%u "
+ "chan_nr=0x%02x, so we raise MS power\n",
+ l1h->trx->nr, chan_nr);
+ return ms_power_diff(l1h, lchan, chan_nr, chan_state,
+ MS_RAISE_MAX);
+ }
+
+ /* reset total counter */
+ chan_state->meas.rssi_count = 0;
+
+ /* check the minimum level received after MS acknowledged the ordered
+ * power level */
+ if (chan_state->meas.rssi_valid_count == 0)
+ return 0;
+ for (rssi = 999, i = 0; i < chan_state->meas.rssi_valid_count; i++) {
+ if (rssi > chan_state->meas.rssi[i])
+ rssi = chan_state->meas.rssi[i];
+ }
+
+ /* reset valid counter */
+ chan_state->meas.rssi_valid_count = 0;
+
+ /* change RSSI */
+ LOGP(DLOOP, LOGL_DEBUG, "Lowest RSSI: %d Target RSSI: %d Current "
+ "MS power: %d (%d dBm) of trx=%u chan_nr=0x%02x\n", rssi,
+ trx_target_rssi, lchan->ms_power, MS_PWR_DBM(lchan->ms_power),
+ l1h->trx->nr, chan_nr);
+ ms_power_diff(l1h, lchan, chan_nr, chan_state, trx_target_rssi - rssi);
+
+ return 0;
+}
+
+
+/*
+ * Timing Advance loop
+ */
+
+int trx_ta_loop = 1;
+
+int ta_val(struct trx_l1h *l1h, struct gsm_lchan *lchan, uint8_t chan_nr,
+ struct trx_chan_state *chan_state, float toa)
+{
+ /* check if the current L1 header acks to the current ordered TA */
+ if (lchan->meas.l1_info[1] != lchan->rqd_ta)
+ return 0;
+
+ /* sum measurement */
+ chan_state->meas.toa_sum += toa;
+ if (++(chan_state->meas.toa_num) < 16)
+ return 0;
+
+ /* complete set */
+ toa = chan_state->meas.toa_sum / chan_state->meas.toa_num;
+
+ /* check for change of TOA */
+ if (toa < -0.9F && lchan->rqd_ta > 0) {
+ LOGP(DLOOP, LOGL_INFO, "TOA of trx=%u chan_nr=0x%02x is too "
+ "early (%.2f), now lowering TA from %d to %d\n",
+ l1h->trx->nr, chan_nr, toa, lchan->rqd_ta,
+ lchan->rqd_ta - 1);
+ lchan->rqd_ta--;
+ } else if (toa > 0.9F && lchan->rqd_ta < 63) {
+ LOGP(DLOOP, LOGL_INFO, "TOA of trx=%u chan_nr=0x%02x is too "
+ "late (%.2f), now raising TA from %d to %d\n",
+ l1h->trx->nr, chan_nr, toa, lchan->rqd_ta,
+ lchan->rqd_ta + 1);
+ lchan->rqd_ta++;
+ } else
+ LOGP(DLOOP, LOGL_INFO, "TOA of trx=%u chan_nr=0x%02x is "
+ "correct (%.2f), keeping current TA of %d\n",
+ l1h->trx->nr, chan_nr, toa, lchan->rqd_ta);
+
+ chan_state->meas.toa_num = 0;
+ chan_state->meas.toa_sum = 0;
+
+ return 0;
+}
+
+int trx_loop_sacch_input(struct trx_l1h *l1h, uint8_t chan_nr,
+ struct trx_chan_state *chan_state, int8_t rssi, float toa)
+{
+ struct gsm_lchan *lchan = &l1h->trx->ts[L1SAP_CHAN2TS(chan_nr)]
+ .lchan[l1sap_chan2ss(chan_nr)];
+
+ if (trx_ms_power_loop)
+ ms_power_val(chan_state, rssi);
+
+ if (trx_ta_loop)
+ ta_val(l1h, lchan, chan_nr, chan_state, toa);
+
+ return 0;
+}
+
+int trx_loop_sacch_clock(struct trx_l1h *l1h, uint8_t chan_nr,
+ struct trx_chan_state *chan_state)
+{
+ struct gsm_lchan *lchan = &l1h->trx->ts[L1SAP_CHAN2TS(chan_nr)]
+ .lchan[l1sap_chan2ss(chan_nr)];
+
+ if (trx_ms_power_loop)
+ ms_power_clock(l1h, lchan, chan_nr, chan_state);
+
+ /* count the number of SACCH clocks */
+ chan_state->meas.clock++;
+
+ return 0;
+}
+
+int trx_loop_amr_input(struct trx_l1h *l1h, uint8_t chan_nr,
+ struct trx_chan_state *chan_state, float ber)
+{
+ struct gsm_lchan *lchan = &l1h->trx->ts[L1SAP_CHAN2TS(chan_nr)]
+ .lchan[l1sap_chan2ss(chan_nr)];
+ int c_i;
+
+ /* check if loop is enabled */
+ if (!chan_state->amr_loop)
+ return 0;
+
+ /* wait for MS to use the requested codec */
+ if (chan_state->ul_ft != chan_state->dl_cmr)
+ return 0;
+
+ /* count bit errors */
+ if (L1SAP_IS_CHAN_TCHH(chan_nr)) {
+ chan_state->ber_num += 2;
+ chan_state->ber_sum += (ber + ber);
+ } else {
+ chan_state->ber_num++;
+ chan_state->ber_sum += ber;
+ }
+
+ /* count frames */
+ if (chan_state->ber_num < 48)
+ return 0;
+
+ /* calculate average (reuse ber variable) */
+ ber = chan_state->ber_sum / chan_state->ber_num;
+
+ /* FIXME: calculate C/I from BER */
+ c_i = ber * 100;
+
+ /* reset bit errors */
+ chan_state->ber_num = 0;
+ chan_state->ber_sum = 0;
+
+ LOGP(DLOOP, LOGL_DEBUG, "Current bit error rate (BER) %.6f "
+ "codec id %d of trx=%u chan_nr=0x%02x\n", ber,
+ chan_state->ul_ft, l1h->trx->nr, chan_nr);
+
+ /* degrade */
+ if (chan_state->dl_cmr > 0) {
+ /* degrade, if ber is above threshold FIXME: C/I */
+ if (ber >
+ lchan->tch.amr_mr.mode[chan_state->dl_cmr-1].threshold_bts) {
+ LOGP(DLOOP, LOGL_DEBUG, "Degrading due to BER %.6f "
+ "from codec id %d to %d of trx=%u "
+ "chan_nr=0x%02x\n", ber, chan_state->dl_cmr,
+ chan_state->dl_cmr - 1, l1h->trx->nr, chan_nr);
+ chan_state->dl_cmr--;
+ }
+
+ return 0;
+ }
+
+ /* upgrade */
+ if (chan_state->dl_cmr < chan_state->codecs - 1) {
+ /* degrade, if ber is above threshold FIXME: C/I*/
+ if (ber <
+ lchan->tch.amr_mr.mode[chan_state->dl_cmr].threshold_bts
+ - lchan->tch.amr_mr.mode[chan_state->dl_cmr].hysteresis_bts) {
+ LOGP(DLOOP, LOGL_DEBUG, "Upgrading due to BER %.6f "
+ "from codec id %d to %d of trx=%u "
+ "chan_nr=0x%02x\n", ber, chan_state->dl_cmr,
+ chan_state->dl_cmr + 1, l1h->trx->nr, chan_nr);
+ chan_state->dl_cmr++;
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+
+int trx_loop_amr_set(struct trx_chan_state *chan_state, int loop)
+{
+ if (chan_state->amr_loop && !loop) {
+ chan_state->amr_loop = 0;
+
+ return 0;
+ }
+
+ if (!chan_state->amr_loop && loop) {
+ chan_state->amr_loop = 1;
+
+ /* reset bit errors */
+ chan_state->ber_num = 0;
+ chan_state->ber_sum = 0;
+
+ return 0;
+ }
+
+ return 0;
+}
+
diff --git a/src/osmo-bts-trx/loops.h b/src/osmo-bts-trx/loops.h
new file mode 100644
index 0000000..27b0ef2
--- /dev/null
+++ b/src/osmo-bts-trx/loops.h
@@ -0,0 +1,31 @@
+#ifndef _TRX_LOOPS_H
+#define _TRX_LOOPS_H
+
+/*
+ * calibration of loops
+ */
+
+/* how much power levels do we raise/lower as maximum (1 level = 2 dB) */
+#define MS_RAISE_MAX 4
+#define MS_LOWER_MAX 1
+
+/*
+ * loops api
+ */
+
+extern int trx_ms_power_loop;
+extern int8_t trx_target_rssi;
+extern int trx_ta_loop;
+
+int trx_loop_sacch_input(struct trx_l1h *l1h, uint8_t chan_nr,
+ struct trx_chan_state *chan_state, int8_t rssi, float toa);
+
+int trx_loop_sacch_clock(struct trx_l1h *l1h, uint8_t chan_nr,
+ struct trx_chan_state *chan_state);
+
+int trx_loop_amr_input(struct trx_l1h *l1h, uint8_t chan_nr,
+ struct trx_chan_state *chan_state, float ber);
+
+int trx_loop_amr_set(struct trx_chan_state *chan_state, int loop);
+
+#endif /* _TRX_LOOPS_H */
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
new file mode 100644
index 0000000..6f2dd4b
--- /dev/null
+++ b/src/osmo-bts-trx/main.c
@@ -0,0 +1,406 @@
+/* Main program for OsmoBTS-TRX */
+
+/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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 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 <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <sched.h>
+#include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/application.h>
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/core/gsmtap.h>
+#include <osmocom/core/gsmtap_util.h>
+#include <osmocom/core/bits.h>
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/abis.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/vty.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/pcu_if.h>
+#include <osmo-bts/l1sap.h>
+
+#include "l1_if.h"
+#include "trx_if.h"
+#include "scheduler.h"
+
+const int pcu_direct = 0;
+
+int quit = 0;
+static const char *config_file = "osmo-bts.cfg";
+static int daemonize = 0;
+static char *gsmtap_ip = 0;
+static int rt_prio = -1;
+static int trx_num = 1;
+char *software_version = "0.0";
+uint8_t abis_mac[6] = { 0, 1, 2, 3, 4, 5 };
+char *bsc_host = "localhost";
+char *bts_id = "1801/0";
+
+// FIXME this is a hack
+static void get_mac(void)
+{
+ struct if_nameindex *ifn = if_nameindex();
+ struct ifreq ifr;
+ int sock;
+ int ret;
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock < 0)
+ return;
+
+ memset(&ifr, 0, sizeof(ifr));
+ if (!ifn)
+ return;
+ while (ifn->if_name) {
+ strncpy(ifr.ifr_name, ifn->if_name, sizeof(ifr.ifr_name)-1);
+ ret = ioctl(sock, SIOCGIFHWADDR, &ifr);
+ if (ret == 0 && !!memcmp(ifr.ifr_hwaddr.sa_data,
+ "\0\0\0\0\0\0", 6)) {
+ memcpy(abis_mac, ifr.ifr_hwaddr.sa_data, 6);
+ printf("Using MAC address of %s: "
+ "'%02x:%02x:%02x:%02x:%02x:%02x'\n",
+ ifn->if_name,
+ abis_mac[0], abis_mac[1], abis_mac[2],
+ abis_mac[3], abis_mac[4], abis_mac[5]);
+ break;
+ }
+ ifn++;
+ }
+// if_freenameindex(ifn);
+}
+
+int bts_model_init(struct gsm_bts *bts)
+{
+ void *l1h;
+ struct gsm_bts_trx *trx;
+
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = l1if_open(trx);
+ if (!l1h) {
+ LOGP(DL1C, LOGL_FATAL, "Cannot open L1 Interface\n");
+ goto error;
+ }
+
+ trx->role_bts.l1h = l1h;
+ trx->nominal_power = 23;
+
+ l1if_reset(l1h);
+ }
+
+ bts_model_vty_init(bts);
+
+ return 0;
+
+error:
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = trx->role_bts.l1h;
+ if (l1h)
+ l1if_close(l1h);
+ }
+
+ return -EIO;
+}
+
+/* dummy, since no direct dsp support */
+uint32_t trx_get_hlayer1(struct gsm_bts_trx *trx)
+{
+ return 0;
+}
+
+static void print_help()
+{
+ printf( "Some useful options:\n"
+ " -h --help this text\n"
+ " -d --debug MASK Enable debugging (e.g. -d DRSL:DOML:DLAPDM)\n"
+ " -D --daemonize For the process into a background daemon\n"
+ " -c --config-file Specify the filename of the config file\n"
+ " -s --disable-color Don't use colors in stderr log output\n"
+ " -T --timestamp Prefix every log line with a timestamp\n"
+ " -V --version Print version information and exit\n"
+ " -e --log-level Set a global log-level\n"
+ " -t --trx-num Set number of TRX (default=%d)\n"
+ " -i --gsmtap-ip The destination IP used for GSMTAP.\n"
+ " -r --realtime PRIO Set realtime scheduler with given prio\n"
+ " -I --local-trx-ip Local IP for transceiver to connect (default=%s)\n"
+ ,trx_num, transceiver_ip);
+}
+
+/* FIXME: finally get some option parsing code into libosmocore */
+static void handle_options(int argc, char **argv)
+{
+ while (1) {
+ int option_idx = 0, c;
+ static const struct option long_options[] = {
+ /* FIXME: all those are generic Osmocom app options */
+ { "help", 0, 0, 'h' },
+ { "debug", 1, 0, 'd' },
+ { "daemonize", 0, 0, 'D' },
+ { "config-file", 1, 0, 'c' },
+ { "disable-color", 0, 0, 's' },
+ { "timestamp", 0, 0, 'T' },
+ { "version", 0, 0, 'V' },
+ { "log-level", 1, 0, 'e' },
+ { "trx-num", 1, 0, 't' },
+ { "gsmtap-ip", 1, 0, 'i' },
+ { "realtime", 1, 0, 'r' },
+ { "local-trx-ip", 1, 0, 'I' },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "hc:d:Dc:sTVe:t:i:r:I:",
+ long_options, &option_idx);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_help();
+ exit(0);
+ break;
+ case 's':
+ log_set_use_color(osmo_stderr_target, 0);
+ break;
+ case 'd':
+ log_parse_category_mask(osmo_stderr_target, optarg);
+ break;
+ case 'D':
+ daemonize = 1;
+ break;
+ case 'c':
+ config_file = strdup(optarg);
+ break;
+ case 'T':
+ log_set_print_timestamp(osmo_stderr_target, 1);
+ break;
+ case 'V':
+ print_version(1);
+ exit(0);
+ break;
+ case 'e':
+ log_set_log_level(osmo_stderr_target, atoi(optarg));
+ break;
+ case 't':
+ trx_num = atoi(optarg);
+ if (trx_num < 1)
+ trx_num = 1;
+ break;
+ case 'i':
+ gsmtap_ip = optarg;
+ break;
+ case 'r':
+ rt_prio = atoi(optarg);
+ break;
+ case 'I':
+ transceiver_ip = strdup(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static struct gsm_bts *bts;
+
+static void signal_handler(int signal)
+{
+ fprintf(stderr, "signal %u received\n", signal);
+
+ switch (signal) {
+ case SIGINT:
+ //osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL);
+ if (!quit)
+ bts_shutdown(bts, "SIGINT");
+ quit++;
+ break;
+ case SIGABRT:
+ case SIGUSR1:
+ case SIGUSR2:
+ talloc_report_full(tall_bts_ctx, stderr);
+ break;
+ default:
+ break;
+ }
+}
+
+static int write_pid_file(char *procname)
+{
+ FILE *outf;
+ char tmp[PATH_MAX+1];
+
+ snprintf(tmp, sizeof(tmp)-1, "/var/run/%s.pid", procname);
+ tmp[PATH_MAX-1] = '\0';
+
+ outf = fopen(tmp, "w");
+ if (!outf)
+ return -1;
+
+ fprintf(outf, "%d\n", getpid());
+
+ fclose(outf);
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct gsm_bts_role_bts *btsb;
+ struct gsm_bts_trx *trx;
+ struct e1inp_line *line;
+ void *tall_msgb_ctx;
+ int rc, i;
+
+ printf("((*))\n |\n / \\ OsmoBTS\n");
+
+ get_mac();
+
+ tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context");
+ tall_msgb_ctx = talloc_named_const(tall_bts_ctx, 1, "msgb");
+ msgb_set_talloc_ctx(tall_msgb_ctx);
+
+ bts_log_init(NULL);
+
+ handle_options(argc, argv);
+
+ bts = gsm_bts_alloc(tall_bts_ctx);
+ if (!bts) {
+ fprintf(stderr, "Failed to create BTS structure\n");
+ exit(1);
+ }
+ for (i = 1; i < trx_num; i++) {
+ trx = gsm_bts_trx_alloc(bts);
+ if (!trx) {
+ fprintf(stderr, "Failed to TRX structure\n");
+ exit(1);
+ }
+ }
+
+ vty_init(&bts_vty_info);
+ e1inp_vty_init();
+ bts_vty_init(bts, &bts_log_info);
+
+ if (bts_init(bts) < 0) {
+ fprintf(stderr, "unable to to open bts\n");
+ exit(1);
+ }
+ btsb = bts_role_bts(bts);
+ btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2);
+
+ if (gsmtap_ip) {
+ gsmtap = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1);
+ if (!gsmtap) {
+ fprintf(stderr, "Failed during gsmtap_init()\n");
+ exit(1);
+ }
+ gsmtap_source_add_sink(gsmtap);
+ }
+
+ abis_init(bts);
+
+ rc = vty_read_config_file(config_file, NULL);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to parse the config file: '%s'\n",
+ config_file);
+ exit(1);
+ }
+ if (!settsc_enabled && !setbsic_enabled)
+ settsc_enabled = setbsic_enabled = 1;
+
+ write_pid_file("osmo-bts");
+
+ rc = telnet_init(tall_bts_ctx, NULL, 4241);
+ if (rc < 0) {
+ fprintf(stderr, "Error initializing telnet\n");
+ exit(1);
+ }
+
+ if (pcu_sock_init()) {
+ fprintf(stderr, "PCU L1 socket failed\n");
+ exit(-1);
+ }
+
+ signal(SIGINT, &signal_handler);
+ //signal(SIGABRT, &signal_handler);
+ signal(SIGUSR1, &signal_handler);
+ signal(SIGUSR2, &signal_handler);
+ osmo_init_ignore_signals();
+
+ if (!btsb->bsc_oml_host) {
+ fprintf(stderr, "Cannot start BTS without knowing BSC OML IP\n");
+ exit(1);
+ }
+
+ line = abis_open(bts, btsb->bsc_oml_host, "sysmoBTS");
+ if (!line) {
+ fprintf(stderr, "unable to connect to BSC\n");
+ exit(1);
+ }
+
+ if (daemonize) {
+ rc = osmo_daemonize();
+ if (rc < 0) {
+ perror("Error during daemonize");
+ exit(1);
+ }
+ }
+
+ if (rt_prio != -1) {
+ struct sched_param schedp;
+
+ /* high priority scheduling required for handling bursts */
+ memset(&schedp, 0, sizeof(schedp));
+ schedp.sched_priority = rt_prio;
+ rc = sched_setscheduler(0, SCHED_RR, &schedp);
+ if (rc) {
+ fprintf(stderr, "Error setting SCHED_RR with prio %d\n",
+ rt_prio);
+ }
+ }
+
+ while (quit < 2) {
+ log_reset_context();
+ osmo_select_main(0);
+ }
+
+#if 0
+ telnet_exit();
+
+ talloc_report_full(tall_bts_ctx, stderr);
+#endif
+
+ return 0;
+}
+
diff --git a/src/osmo-bts-trx/scheduler.c b/src/osmo-bts-trx/scheduler.c
new file mode 100644
index 0000000..8d0c834
--- /dev/null
+++ b/src/osmo-bts-trx/scheduler.c
@@ -0,0 +1,3044 @@
+/* Scheduler for OsmoBTS-TRX */
+
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ * (C) 2015 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
+ *
+ * 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 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 <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <ctype.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/bits.h>
+#include <osmocom/gsm/a5.h>
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/rsl.h>
+#include <osmo-bts/l1sap.h>
+#include <osmo-bts/amr.h>
+
+#include "l1_if.h"
+#include "scheduler.h"
+#include "gsm0503_coding.h"
+#include "trx_if.h"
+#include "loops.h"
+#include "amr.h"
+#include "loops.h"
+
+/* Enable this to multiply TOA of RACH by 10.
+ * This is usefull to check tenth of timing advances with RSSI test tool.
+ * Note that regular phones will not work when using this test! */
+//#define TA_TEST
+
+void *tall_bts_ctx;
+
+static struct gsm_bts *bts;
+
+/* clock states */
+static uint32_t transceiver_lost;
+uint32_t transceiver_last_fn;
+static struct timeval transceiver_clock_tv;
+static struct osmo_timer_list transceiver_clock_timer;
+
+/* clock advance for the transceiver */
+uint32_t trx_clock_advance = 20;
+
+/* advance RTS to give some time for data processing. (especially PCU) */
+uint32_t trx_rts_advance = 5; /* about 20ms */
+
+typedef int trx_sched_rts_func(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan);
+typedef ubit_t *trx_sched_dl_func(struct trx_l1h *l1h, uint8_t tn,
+ uint32_t fn, enum trx_chan_type chan, uint8_t bid);
+typedef int trx_sched_ul_func(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa);
+
+static int rts_data_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan);
+static int rts_tchf_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan);
+static int rts_tchh_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan);
+static ubit_t *tx_idle_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static ubit_t *tx_fcch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static ubit_t *tx_sch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static ubit_t *tx_data_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static ubit_t *tx_pdtch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static ubit_t *tx_tchf_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static ubit_t *tx_tchh_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid);
+static int rx_rach_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa);
+static int rx_data_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa);
+static int rx_pdtch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa);
+static int rx_tchf_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa);
+static int rx_tchh_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa);
+
+static ubit_t dummy_burst[148] = {
+ 0,0,0,
+ 1,1,1,1,1,0,1,1,0,1,1,1,0,1,1,0,0,0,0,0,1,0,1,0,0,1,0,0,1,1,1,0,
+ 0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,
+ 0,1,0,1,1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,
+ 0,0,1,1,0,0,1,1,0,0,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,1,1,1,0,0,0,1,
+ 0,0,1,0,1,1,1,1,1,0,1,0,1,0,
+ 0,0,0,
+};
+
+static ubit_t fcch_burst[148] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+};
+
+static const ubit_t tsc[8][26] = {
+ { 0,0,1,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1,1, },
+ { 0,0,1,0,1,1,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1,1,0,1,1,1, },
+ { 0,1,0,0,0,0,1,1,1,0,1,1,1,0,1,0,0,1,0,0,0,0,1,1,1,0, },
+ { 0,1,0,0,0,1,1,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,1,1,1,0, },
+ { 0,0,0,1,1,0,1,0,1,1,1,0,0,1,0,0,0,0,0,1,1,0,1,0,1,1, },
+ { 0,1,0,0,1,1,1,0,1,0,1,1,0,0,0,0,0,1,0,0,1,1,1,0,1,0, },
+ { 1,0,1,0,0,1,1,1,1,1,0,1,1,0,0,0,1,0,1,0,0,1,1,1,1,1, },
+ { 1,1,1,0,1,1,1,1,0,0,0,1,0,0,1,0,1,1,1,0,1,1,1,1,0,0, },
+};
+
+static const ubit_t sch_train[64] = {
+ 1,0,1,1,1,0,0,1,0,1,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,
+ 0,0,1,0,1,1,0,1,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,0,0,1,1,0,1,1,
+};
+
+/*
+ * subchannel description structure
+ */
+
+struct trx_chan_desc {
+ int pdch;
+ enum trx_chan_type chan;
+ uint8_t chan_nr;
+ uint8_t link_id;
+ const char *name;
+ trx_sched_rts_func *rts_fn;
+ trx_sched_dl_func *dl_fn;
+ trx_sched_ul_func *ul_fn;
+ int auto_active;
+};
+struct trx_chan_desc trx_chan_desc[_TRX_CHAN_MAX] = {
+ { 0, TRXC_IDLE, 0, 0, "IDLE", NULL, tx_idle_fn, NULL, 1 },
+ { 0, TRXC_FCCH, 0, 0, "FCCH", NULL, tx_fcch_fn, NULL, 1 },
+ { 0, TRXC_SCH, 0, 0, "SCH", NULL, tx_sch_fn, NULL, 1 },
+ { 0, TRXC_BCCH, 0x80, 0x00, "BCCH", rts_data_fn, tx_data_fn, NULL, 1 },
+ { 0, TRXC_RACH, 0x88, 0x00, "RACH", NULL, NULL, rx_rach_fn, 1 },
+ { 0, TRXC_CCCH, 0x90, 0x00, "CCCH", rts_data_fn, tx_data_fn, NULL, 1 },
+ { 0, TRXC_TCHF, 0x08, 0x00, "TCH/F", rts_tchf_fn, tx_tchf_fn, rx_tchf_fn, 0 },
+ { 0, TRXC_TCHH_0, 0x10, 0x00, "TCH/H(0)", rts_tchh_fn, tx_tchh_fn, rx_tchh_fn, 0 },
+ { 0, TRXC_TCHH_1, 0x18, 0x00, "TCH/H(1)", rts_tchh_fn, tx_tchh_fn, rx_tchh_fn, 0 },
+ { 0, TRXC_SDCCH4_0, 0x20, 0x00, "SDCCH/4(0)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH4_1, 0x28, 0x00, "SDCCH/4(1)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH4_2, 0x30, 0x00, "SDCCH/4(2)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH4_3, 0x38, 0x00, "SDCCH/4(3)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_0, 0x40, 0x00, "SDCCH/8(0)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_1, 0x48, 0x00, "SDCCH/8(1)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_2, 0x50, 0x00, "SDCCH/8(2)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_3, 0x58, 0x00, "SDCCH/8(3)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_4, 0x60, 0x00, "SDCCH/8(4)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_5, 0x68, 0x00, "SDCCH/8(5)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_6, 0x70, 0x00, "SDCCH/8(6)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SDCCH8_7, 0x78, 0x00, "SDCCH/8(7)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCHTF, 0x08, 0x40, "SACCH/TF", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCHTH_0, 0x10, 0x40, "SACCH/TH(0)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCHTH_1, 0x18, 0x40, "SACCH/TH(1)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH4_0, 0x20, 0x40, "SACCH/4(0)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH4_1, 0x28, 0x40, "SACCH/4(1)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH4_2, 0x30, 0x40, "SACCH/4(2)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH4_3, 0x38, 0x40, "SACCH/4(3)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_0, 0x40, 0x40, "SACCH/8(0)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_1, 0x48, 0x40, "SACCH/8(1)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_2, 0x50, 0x40, "SACCH/8(2)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_3, 0x58, 0x40, "SACCH/8(3)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_4, 0x60, 0x40, "SACCH/8(4)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_5, 0x68, 0x40, "SACCH/8(5)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_6, 0x70, 0x40, "SACCH/8(6)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 0, TRXC_SACCH8_7, 0x78, 0x40, "SACCH/8(7)", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+ { 1, TRXC_PDTCH, 0x08, 0x00, "PDTCH", rts_data_fn, tx_pdtch_fn, rx_pdtch_fn, 0 },
+ { 1, TRXC_PTCCH, 0x08, 0x00, "PTCCH", rts_data_fn, tx_data_fn, rx_data_fn, 0 },
+};
+
+
+/*
+ * init / exit
+ */
+
+int trx_sched_init(struct trx_l1h *l1h)
+{
+ uint8_t tn;
+ int i;
+ struct trx_chan_state *chan_state;
+
+ LOGP(DL1C, LOGL_NOTICE, "Init scheduler for trx=%u\n", l1h->trx->nr);
+
+ /* hack to get bts */
+ bts = l1h->trx->bts;
+
+ for (tn = 0; tn < 8; tn++) {
+ l1h->mf_index[tn] = 0;
+ l1h->mf_last_fn[tn] = 0;
+ INIT_LLIST_HEAD(&l1h->dl_prims[tn]);
+ for (i = 0; i < _TRX_CHAN_MAX; i++) {
+ chan_state = &l1h->chan_states[tn][i];
+ chan_state->active = 0;
+ }
+ }
+
+ return 0;
+}
+
+void trx_sched_exit(struct trx_l1h *l1h)
+{
+ uint8_t tn;
+ int i;
+ struct trx_chan_state *chan_state;
+
+ LOGP(DL1C, LOGL_NOTICE, "Exit scheduler for trx=%u\n", l1h->trx->nr);
+
+ for (tn = 0; tn < 8; tn++) {
+ msgb_queue_flush(&l1h->dl_prims[tn]);
+ for (i = 0; i < _TRX_CHAN_MAX; i++) {
+ chan_state = &l1h->chan_states[tn][i];
+ if (chan_state->dl_bursts) {
+ talloc_free(chan_state->dl_bursts);
+ chan_state->dl_bursts = NULL;
+ }
+ if (chan_state->ul_bursts) {
+ talloc_free(chan_state->ul_bursts);
+ chan_state->ul_bursts = NULL;
+ }
+ }
+ /* clear lchan channel states */
+ for (i = 0; i < 8; i++)
+ l1h->trx->ts[tn].lchan[i].state = LCHAN_S_NONE;
+ }
+}
+
+/* close all logical channels and reset timeslots */
+void trx_sched_reset(struct trx_l1h *l1h)
+{
+ trx_sched_exit(l1h);
+ trx_sched_init(l1h);
+}
+
+
+/*
+ * data request (from upper layer)
+ */
+
+int trx_sched_ph_data_req(struct trx_l1h *l1h, struct osmo_phsap_prim *l1sap)
+{
+ uint8_t tn = l1sap->u.data.chan_nr & 7;
+
+ LOGP(DL1C, LOGL_INFO, "PH-DATA.req: chan_nr=0x%02x link_id=0x%02x "
+ "fn=%u ts=%u trx=%u\n", l1sap->u.data.chan_nr,
+ l1sap->u.data.link_id, l1sap->u.data.fn, tn, l1h->trx->nr);
+
+ if (!l1sap->oph.msg)
+ abort();
+
+ /* ignore empty frame */
+ if (!msgb_l2len(l1sap->oph.msg)) {
+ msgb_free(l1sap->oph.msg);
+ return 0;
+ }
+
+ msgb_enqueue(&l1h->dl_prims[tn], l1sap->oph.msg);
+
+ return 0;
+}
+
+int trx_sched_tch_req(struct trx_l1h *l1h, struct osmo_phsap_prim *l1sap)
+{
+ uint8_t tn = l1sap->u.tch.chan_nr & 7;
+
+ LOGP(DL1C, LOGL_INFO, "TCH.req: chan_nr=0x%02x "
+ "fn=%u ts=%u trx=%u\n", l1sap->u.tch.chan_nr,
+ l1sap->u.tch.fn, tn, l1h->trx->nr);
+
+ if (!l1sap->oph.msg)
+ abort();
+
+ /* ignore empty frame */
+ if (!msgb_l2len(l1sap->oph.msg)) {
+ msgb_free(l1sap->oph.msg);
+ return 0;
+ }
+
+ msgb_enqueue(&l1h->dl_prims[tn], l1sap->oph.msg);
+
+ return 0;
+}
+
+
+/*
+ * ready-to-send indication (to upper layer)
+ */
+
+/* RTS for data frame */
+static int rts_data_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan)
+{
+ uint8_t chan_nr, link_id;
+ struct msgb *msg;
+ struct osmo_phsap_prim *l1sap;
+
+ /* get data for RTS indication */
+ chan_nr = trx_chan_desc[chan].chan_nr | tn;
+ link_id = trx_chan_desc[chan].link_id;
+
+ if (!chan_nr) {
+ LOGP(DL1C, LOGL_FATAL, "RTS func for %s with non-existing "
+ "chan_nr %d\n", trx_chan_desc[chan].name, chan_nr);
+ return -ENODEV;
+ }
+
+ LOGP(DL1C, LOGL_INFO, "PH-RTS.ind: chan=%s chan_nr=0x%02x "
+ "link_id=0x%02x fn=%u ts=%u trx=%u\n", trx_chan_desc[chan].name,
+ chan_nr, link_id, fn, tn, l1h->trx->nr);
+
+ /* send clock information to loops process */
+ if (L1SAP_IS_LINK_SACCH(link_id))
+ trx_loop_sacch_clock(l1h, chan_nr, &l1h->chan_states[tn][chan]);
+
+ /* generate prim */
+ msg = l1sap_msgb_alloc(200);
+ if (!msg)
+ return -ENOMEM;
+ l1sap = msgb_l1sap_prim(msg);
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_PH_RTS,
+ PRIM_OP_INDICATION, msg);
+ l1sap->u.data.chan_nr = chan_nr;
+ l1sap->u.data.link_id = link_id;
+ l1sap->u.data.fn = fn;
+
+ return l1sap_up(l1h->trx, l1sap);
+}
+
+static int rts_tch_common(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, int facch)
+{
+ uint8_t chan_nr, link_id;
+ struct msgb *msg;
+ struct osmo_phsap_prim *l1sap;
+ int rc = 0;
+
+ /* get data for RTS indication */
+ chan_nr = trx_chan_desc[chan].chan_nr | tn;
+ link_id = trx_chan_desc[chan].link_id;
+
+ if (!chan_nr) {
+ LOGP(DL1C, LOGL_FATAL, "RTS func for %s with non-existing "
+ "chan_nr %d\n", trx_chan_desc[chan].name, chan_nr);
+ return -ENODEV;
+ }
+
+ LOGP(DL1C, LOGL_INFO, "TCH RTS.ind: chan=%s chan_nr=0x%02x "
+ "fn=%u ts=%u trx=%u\n", trx_chan_desc[chan].name,
+ chan_nr, fn, tn, l1h->trx->nr);
+
+ /* only send, if FACCH is selected */
+ if (facch) {
+ /* generate prim */
+ msg = l1sap_msgb_alloc(200);
+ if (!msg)
+ return -ENOMEM;
+ l1sap = msgb_l1sap_prim(msg);
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_PH_RTS,
+ PRIM_OP_INDICATION, msg);
+ l1sap->u.data.chan_nr = chan_nr;
+ l1sap->u.data.link_id = link_id;
+ l1sap->u.data.fn = fn;
+
+ rc = l1sap_up(l1h->trx, l1sap);
+ }
+
+ /* dont send, if TCH is in signalling only mode */
+ if (l1h->chan_states[tn][chan].rsl_cmode != RSL_CMOD_SPD_SIGN) {
+ /* generate prim */
+ msg = l1sap_msgb_alloc(200);
+ if (!msg)
+ return -ENOMEM;
+ l1sap = msgb_l1sap_prim(msg);
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_TCH_RTS,
+ PRIM_OP_INDICATION, msg);
+ l1sap->u.tch.chan_nr = chan_nr;
+ l1sap->u.tch.fn = fn;
+
+ return l1sap_up(l1h->trx, l1sap);
+ }
+
+ return rc;
+}
+
+/* RTS for full rate traffic frame */
+static int rts_tchf_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan)
+{
+ /* TCH/F may include FACCH on every 4th burst */
+ return rts_tch_common(l1h, tn, fn, chan, 1);
+}
+
+
+/* RTS for half rate traffic frame */
+static int rts_tchh_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan)
+{
+ /* the FN 4/5, 13/14, 21/22 defines that FACCH may be included. */
+ return rts_tch_common(l1h, tn, fn, chan, ((fn % 26) >> 2) & 1);
+}
+
+
+/*
+ * TX on downlink
+ */
+
+/* an IDLE burst returns nothing. on C0 it is replaced by dummy burst */
+static ubit_t *tx_idle_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr);
+
+ return NULL;
+}
+
+static ubit_t *tx_fcch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr);
+
+ return fcch_burst;
+}
+
+static ubit_t *tx_sch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ static ubit_t bits[148], burst[78];
+ uint8_t sb_info[4];
+ struct gsm_time t;
+ uint8_t t3p, bsic;
+
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr);
+
+ /* create SB info from GSM time and BSIC */
+ gsm_fn2gsmtime(&t, fn);
+ t3p = t.t3 / 10;
+ bsic = l1h->trx->bts->bsic;
+ sb_info[0] =
+ ((bsic & 0x3f) << 2) |
+ ((t.t1 & 0x600) >> 9);
+ sb_info[1] =
+ ((t.t1 & 0x1fe) >> 1);
+ sb_info[2] =
+ ((t.t1 & 0x001) << 7) |
+ ((t.t2 & 0x1f) << 2) |
+ ((t3p & 0x6) >> 1);
+ sb_info[3] =
+ (t3p & 0x1);
+
+ /* encode bursts */
+ sch_encode(burst, sb_info);
+
+ /* compose burst */
+ memset(bits, 0, 3);
+ memcpy(bits + 3, burst, 39);
+ memcpy(bits + 42, sch_train, 64);
+ memcpy(bits + 106, burst + 39, 39);
+ memset(bits + 145, 0, 3);
+
+ return bits;
+}
+
+static struct msgb *dequeue_prim(struct trx_l1h *l1h, int8_t tn,uint32_t fn,
+ enum trx_chan_type chan)
+{
+ struct msgb *msg, *msg2;
+ struct osmo_phsap_prim *l1sap;
+ uint32_t prim_fn;
+ uint8_t chan_nr, link_id;
+
+ /* get prim of current fn from queue */
+ llist_for_each_entry_safe(msg, msg2, &l1h->dl_prims[tn], list) {
+ l1sap = msgb_l1sap_prim(msg);
+ if (l1sap->oph.operation != PRIM_OP_REQUEST) {
+wrong_type:
+ LOGP(DL1C, LOGL_ERROR, "Prim for ts=%u at fn=%u has "
+ "wrong type.\n", tn, fn);
+free_msg:
+ /* unlink and free message */
+ llist_del(&msg->list);
+ msgb_free(msg);
+ return NULL;
+ }
+ switch (l1sap->oph.primitive) {
+ case PRIM_PH_DATA:
+ chan_nr = l1sap->u.data.chan_nr;
+ link_id = l1sap->u.data.link_id;
+ prim_fn = ((l1sap->u.data.fn + 2715648 - fn) % 2715648);
+ break;
+ case PRIM_TCH:
+ chan_nr = l1sap->u.tch.chan_nr;
+ link_id = 0;
+ prim_fn = ((l1sap->u.tch.fn + 2715648 - fn) % 2715648);
+ break;
+ default:
+ goto wrong_type;
+ }
+ if (prim_fn > 100) {
+ LOGP(DL1C, LOGL_NOTICE, "Prim for trx=%u ts=%u at fn=%u "
+ "is out of range, or channel already disabled. "
+ "If this happens in conjunction with PCU, "
+ "increase 'rts-advance' by 5. (current fn=%u)\n",
+ l1h->trx->nr, tn, l1sap->u.data.fn, fn);
+ /* unlink and free message */
+ llist_del(&msg->list);
+ msgb_free(msg);
+ continue;
+ }
+ if (prim_fn > 0)
+ continue;
+
+ goto found_msg;
+ }
+
+ return NULL;
+
+found_msg:
+ if ((chan_nr ^ (trx_chan_desc[chan].chan_nr | tn))
+ || ((link_id & 0xc0) ^ trx_chan_desc[chan].link_id)) {
+ LOGP(DL1C, LOGL_ERROR, "Prim for ts=%u at fn=%u has wrong "
+ "chan_nr=%02x link_id=%02x, expecting chan_nr=%02x "
+ "link_id=%02x.\n", tn, fn, chan_nr, link_id,
+ trx_chan_desc[chan].chan_nr | tn,
+ trx_chan_desc[chan].link_id);
+ goto free_msg;
+ }
+
+ /* unlink and return message */
+ llist_del(&msg->list);
+ return msg;
+}
+
+static int compose_ph_data_ind(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t *l2, uint8_t l2_len, float rssi)
+{
+ struct msgb *msg;
+ struct osmo_phsap_prim *l1sap;
+ uint8_t chan_nr = trx_chan_desc[chan].chan_nr | tn;
+
+ /* compose primitive */
+ msg = l1sap_msgb_alloc(l2_len);
+ l1sap = msgb_l1sap_prim(msg);
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_PH_DATA,
+ PRIM_OP_INDICATION, msg);
+ l1sap->u.data.chan_nr = chan_nr;
+ l1sap->u.data.link_id = trx_chan_desc[chan].link_id;
+ l1sap->u.data.fn = fn;
+ l1sap->u.data.rssi = (int8_t) (rssi);
+ msg->l2h = msgb_put(msg, l2_len);
+ if (l2_len)
+ memcpy(msg->l2h, l2, l2_len);
+
+ if (L1SAP_IS_LINK_SACCH(trx_chan_desc[chan].link_id))
+ l1h->chan_states[tn][chan].lost = 0;
+
+ /* forward primitive */
+ l1sap_up(l1h->trx, l1sap);
+
+ return 0;
+}
+
+static int compose_tch_ind(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t *tch, uint8_t tch_len)
+{
+ struct msgb *msg;
+ struct osmo_phsap_prim *l1sap;
+
+ /* compose primitive */
+ msg = l1sap_msgb_alloc(tch_len);
+ l1sap = msgb_l1sap_prim(msg);
+ osmo_prim_init(&l1sap->oph, SAP_GSM_PH, PRIM_TCH,
+ PRIM_OP_INDICATION, msg);
+ l1sap->u.tch.chan_nr = trx_chan_desc[chan].chan_nr | tn;
+ l1sap->u.tch.fn = fn;
+ msg->l2h = msgb_put(msg, tch_len);
+ if (tch_len)
+ memcpy(msg->l2h, tch, tch_len);
+
+ if (l1h->chan_states[tn][chan].lost)
+ l1h->chan_states[tn][chan].lost--;
+
+ /* forward primitive */
+ l1sap_up(l1h->trx, l1sap);
+
+ return 0;
+}
+
+static ubit_t *tx_data_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ struct msgb *msg = NULL; /* make GCC happy */
+ ubit_t *burst, **bursts_p = &l1h->chan_states[tn][chan].dl_bursts;
+ static ubit_t bits[148];
+
+ /* send burst, if we already got a frame */
+ if (bid > 0) {
+ if (!*bursts_p)
+ return NULL;
+ goto send_burst;
+ }
+
+ /* get burst from queue */
+ msg = dequeue_prim(l1h, tn, fn, chan);
+ if (msg)
+ goto got_msg;
+
+ LOGP(DL1C, LOGL_INFO, "%s has not been served !! No prim for "
+ "trx=%u ts=%u at fn=%u to transmit.\n",
+ trx_chan_desc[chan].name, l1h->trx->nr, tn, fn);
+
+no_msg:
+ /* free burst memory */
+ if (*bursts_p) {
+ talloc_free(*bursts_p);
+ *bursts_p = NULL;
+ }
+ return NULL;
+
+got_msg:
+ /* check validity of message */
+ if (msgb_l2len(msg) != 23) {
+ LOGP(DL1C, LOGL_FATAL, "Prim not 23 bytes, please FIX! "
+ "(len=%d)\n", msgb_l2len(msg));
+ /* free message */
+ msgb_free(msg);
+ goto no_msg;
+ }
+
+ /* handle loss detection of sacch */
+ if (L1SAP_IS_LINK_SACCH(trx_chan_desc[chan].link_id)) {
+ /* count and send BFI */
+ if (++(l1h->chan_states[tn][chan].lost) > 1) {
+ /* TODO: Should we pass old TOA here? Otherwise we risk
+ * unnecessary decreasing TA */
+
+ /* Send uplnk measurement information to L2 */
+ l1if_process_meas_res(l1h->trx, tn, fn, trx_chan_desc[chan].chan_nr | tn,
+ 456, 456, -110, 0);
+
+ compose_ph_data_ind(l1h, tn, 0, chan, NULL, 0, -110);
+ }
+ }
+
+ /* alloc burst memory, if not already */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 464);
+ if (!*bursts_p)
+ return NULL;
+ }
+
+ /* encode bursts */
+ xcch_encode(*bursts_p, msg->l2h);
+
+ /* free message */
+ msgb_free(msg);
+
+send_burst:
+ /* compose burst */
+ burst = *bursts_p + bid * 116;
+ memset(bits, 0, 3);
+ memcpy(bits + 3, burst, 58);
+ memcpy(bits + 61, tsc[l1h->config.tsc], 26);
+ memcpy(bits + 87, burst + 58, 58);
+ memset(bits + 145, 0, 3);
+
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u burst=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ return bits;
+}
+
+static ubit_t *tx_pdtch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ struct msgb *msg = NULL; /* make GCC happy */
+ ubit_t *burst, **bursts_p = &l1h->chan_states[tn][chan].dl_bursts;
+ static ubit_t bits[148];
+ int rc;
+
+ /* send burst, if we already got a frame */
+ if (bid > 0) {
+ if (!*bursts_p)
+ return NULL;
+ goto send_burst;
+ }
+
+ /* get burst from queue */
+ msg = dequeue_prim(l1h, tn, fn, chan);
+ if (msg)
+ goto got_msg;
+
+ LOGP(DL1C, LOGL_INFO, "%s has not been served !! No prim for "
+ "trx=%u ts=%u at fn=%u to transmit.\n",
+ trx_chan_desc[chan].name, l1h->trx->nr, tn, fn);
+
+no_msg:
+ /* free burst memory */
+ if (*bursts_p) {
+ talloc_free(*bursts_p);
+ *bursts_p = NULL;
+ }
+ return NULL;
+
+got_msg:
+ /* alloc burst memory, if not already */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 464);
+ if (!*bursts_p)
+ return NULL;
+ }
+
+ /* encode bursts */
+ rc = pdtch_encode(*bursts_p, msg->l2h, msg->tail - msg->l2h);
+
+ /* check validity of message */
+ if (rc) {
+ LOGP(DL1C, LOGL_FATAL, "Prim invalid length, please FIX! "
+ "(len=%d)\n", rc);
+ /* free message */
+ msgb_free(msg);
+ goto no_msg;
+ }
+
+ /* free message */
+ msgb_free(msg);
+
+send_burst:
+ /* compose burst */
+ burst = *bursts_p + bid * 116;
+ memset(bits, 0, 3);
+ memcpy(bits + 3, burst, 58);
+ memcpy(bits + 61, tsc[l1h->config.tsc], 26);
+ memcpy(bits + 87, burst + 58, 58);
+ memset(bits + 145, 0, 3);
+
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u burst=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ return bits;
+}
+
+static void tx_tch_common(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, struct msgb **_msg_tch,
+ struct msgb **_msg_facch, int codec_mode_request)
+{
+ struct msgb *msg1, *msg2, *msg_tch = NULL, *msg_facch = NULL;
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ uint8_t rsl_cmode = chan_state->rsl_cmode;
+ uint8_t tch_mode = chan_state->tch_mode;
+ struct osmo_phsap_prim *l1sap;
+
+ /* handle loss detection of received TCH frames */
+ if (rsl_cmode == RSL_CMOD_SPD_SPEECH
+ && ++(l1h->chan_states[tn][chan].lost) > 5) {
+ uint8_t tch_data[33];
+ int len;
+
+ LOGP(DL1C, LOGL_NOTICE, "Missing TCH bursts detected, sending "
+ "BFI for %s\n", trx_chan_desc[chan].name);
+
+ /* indicate bad frame */
+ switch (tch_mode) {
+ case GSM48_CMODE_SPEECH_V1: /* FR / HR */
+ if (chan != TRXC_TCHF) { /* HR */
+ tch_data[0] = 0x70; /* F = 0, FT = 111 */
+ memset(tch_data + 1, 0, 14);
+ len = 15;
+ break;
+ }
+ memset(tch_data, 0, 33);
+ len = 33;
+ break;
+ case GSM48_CMODE_SPEECH_EFR: /* EFR */
+ if (chan != TRXC_TCHF)
+ goto inval_mode1;
+ memset(tch_data, 0, 31);
+ len = 31;
+ break;
+ case GSM48_CMODE_SPEECH_AMR: /* AMR */
+ len = amr_compose_payload(tch_data,
+ chan_state->codec[chan_state->dl_cmr],
+ chan_state->codec[chan_state->dl_ft], 1);
+ if (len < 2)
+ break;
+ memset(tch_data + 2, 0, len - 2);
+ compose_tch_ind(l1h, tn, 0, chan, tch_data, len);
+ break;
+ default:
+inval_mode1:
+ LOGP(DL1C, LOGL_ERROR, "TCH mode invalid, please "
+ "fix!\n");
+ len = 0;
+ }
+ if (len)
+ compose_tch_ind(l1h, tn, 0, chan, tch_data, len);
+ }
+
+ /* get frame and unlink from queue */
+ msg1 = dequeue_prim(l1h, tn, fn, chan);
+ msg2 = dequeue_prim(l1h, tn, fn, chan);
+ if (msg1) {
+ l1sap = msgb_l1sap_prim(msg1);
+ if (l1sap->oph.primitive == PRIM_TCH) {
+ msg_tch = msg1;
+ if (msg2) {
+ l1sap = msgb_l1sap_prim(msg2);
+ if (l1sap->oph.primitive == PRIM_TCH) {
+ LOGP(DL1C, LOGL_FATAL, "TCH twice, "
+ "please FIX! ");
+ msgb_free(msg2);
+ } else
+ msg_facch = msg2;
+ }
+ } else {
+ msg_facch = msg1;
+ if (msg2) {
+ l1sap = msgb_l1sap_prim(msg2);
+ if (l1sap->oph.primitive != PRIM_TCH) {
+ LOGP(DL1C, LOGL_FATAL, "FACCH twice, "
+ "please FIX! ");
+ msgb_free(msg2);
+ } else
+ msg_tch = msg2;
+ }
+ }
+ } else if (msg2) {
+ l1sap = msgb_l1sap_prim(msg2);
+ if (l1sap->oph.primitive == PRIM_TCH)
+ msg_tch = msg2;
+ else
+ msg_facch = msg2;
+ }
+
+ /* check validity of message */
+ if (msg_facch && msgb_l2len(msg_facch) != 23) {
+ LOGP(DL1C, LOGL_FATAL, "Prim not 23 bytes, please FIX! "
+ "(len=%d)\n", msgb_l2len(msg_facch));
+ /* free message */
+ msgb_free(msg_facch);
+ msg_facch = NULL;
+ }
+
+ /* check validity of message, get AMR ft and cmr */
+ if (!msg_facch && msg_tch) {
+ int len;
+ uint8_t bfi, cmr_codec, ft_codec;
+ int cmr, ft, i;
+
+ if (rsl_cmode != RSL_CMOD_SPD_SPEECH) {
+ LOGP(DL1C, LOGL_NOTICE, "%s Dropping speech frame, "
+ "because we are not in speech mode trx=%u "
+ "ts=%u at fn=%u.\n", trx_chan_desc[chan].name,
+ l1h->trx->nr, tn, fn);
+ goto free_bad_msg;
+ }
+
+ switch (tch_mode) {
+ case GSM48_CMODE_SPEECH_V1: /* FR / HR */
+ if (chan != TRXC_TCHF) { /* HR */
+ len = 15;
+ if (msgb_l2len(msg_tch) >= 1
+ && (msg_tch->l2h[0] & 0xf0) != 0x00) {
+ LOGP(DL1C, LOGL_NOTICE, "%s "
+ "Transmitting 'bad "
+ "HR frame' trx=%u ts=%u at "
+ "fn=%u.\n",
+ trx_chan_desc[chan].name,
+ l1h->trx->nr, tn, fn);
+ goto free_bad_msg;
+ }
+ break;
+ }
+ len = 33;
+ if (msgb_l2len(msg_tch) >= 1
+ && (msg_tch->l2h[0] >> 4) != 0xd) {
+ LOGP(DL1C, LOGL_NOTICE, "%s Transmitting 'bad "
+ "FR frame' trx=%u ts=%u at fn=%u.\n",
+ trx_chan_desc[chan].name,
+ l1h->trx->nr, tn, fn);
+ goto free_bad_msg;
+ }
+ break;
+ case GSM48_CMODE_SPEECH_EFR: /* EFR */
+ if (chan != TRXC_TCHF)
+ goto inval_mode2;
+ len = 31;
+ if (msgb_l2len(msg_tch) >= 1
+ && (msg_tch->l2h[0] >> 4) != 0xc) {
+ LOGP(DL1C, LOGL_NOTICE, "%s Transmitting 'bad "
+ "EFR frame' trx=%u ts=%u at fn=%u.\n",
+ trx_chan_desc[chan].name,
+ l1h->trx->nr, tn, fn);
+ goto free_bad_msg;
+ }
+ break;
+ case GSM48_CMODE_SPEECH_AMR: /* AMR */
+ len = amr_decompose_payload(msg_tch->l2h,
+ msgb_l2len(msg_tch), &cmr_codec, &ft_codec,
+ &bfi);
+ cmr = -1;
+ ft = -1;
+ for (i = 0; i < chan_state->codecs; i++) {
+ if (chan_state->codec[i] == cmr_codec)
+ cmr = i;
+ if (chan_state->codec[i] == ft_codec)
+ ft = i;
+ }
+ if (cmr >= 0) { /* new request */
+ chan_state->dl_cmr = cmr;
+ /* disable AMR loop */
+ trx_loop_amr_set(chan_state, 0);
+ } else {
+ /* enable AMR loop */
+ trx_loop_amr_set(chan_state, 1);
+ }
+ if (ft < 0) {
+ LOGP(DL1C, LOGL_ERROR, "%s Codec (FT = %d) "
+ " of RTP frame not in list. "
+ "trx=%u ts=%u\n",
+ trx_chan_desc[chan].name, ft_codec,
+ l1h->trx->nr, tn);
+ goto free_bad_msg;
+ }
+ if (codec_mode_request && chan_state->dl_ft != ft) {
+ LOGP(DL1C, LOGL_NOTICE, "%s Codec (FT = %d) "
+ " of RTP cannot be changed now, but in "
+ "next frame. trx=%u ts=%u\n",
+ trx_chan_desc[chan].name, ft_codec,
+ l1h->trx->nr, tn);
+ goto free_bad_msg;
+ }
+ chan_state->dl_ft = ft;
+ if (bfi) {
+ LOGP(DL1C, LOGL_NOTICE, "%s Transmitting 'bad "
+ "AMR frame' trx=%u ts=%u at fn=%u.\n",
+ trx_chan_desc[chan].name,
+ l1h->trx->nr, tn, fn);
+ goto free_bad_msg;
+ }
+ break;
+ default:
+inval_mode2:
+ LOGP(DL1C, LOGL_ERROR, "TCH mode invalid, please "
+ "fix!\n");
+ goto free_bad_msg;
+ }
+ if (len < 0) {
+ LOGP(DL1C, LOGL_ERROR, "Cannot send invalid AMR "
+ "payload\n");
+ goto free_bad_msg;
+ }
+ if (msgb_l2len(msg_tch) != len) {
+ LOGP(DL1C, LOGL_ERROR, "Cannot send payload with "
+ "invalid length! (expecing %d, received %d)\n",
+ len, msgb_l2len(msg_tch));
+free_bad_msg:
+ /* free message */
+ msgb_free(msg_tch);
+ msg_tch = NULL;
+ goto send_frame;
+ }
+ }
+
+send_frame:
+ *_msg_tch = msg_tch;
+ *_msg_facch = msg_facch;
+}
+
+static ubit_t *tx_tchf_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ struct msgb *msg_tch = NULL, *msg_facch = NULL;
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ uint8_t tch_mode = chan_state->tch_mode;
+ ubit_t *burst, **bursts_p = &chan_state->dl_bursts;
+ static ubit_t bits[148];
+
+ /* send burst, if we already got a frame */
+ if (bid > 0) {
+ if (!*bursts_p)
+ return NULL;
+ goto send_burst;
+ }
+
+ tx_tch_common(l1h, tn, fn, chan, bid, &msg_tch, &msg_facch,
+ (((fn + 4) % 26) >> 2) & 1);
+
+ /* alloc burst memory, if not already,
+ * otherwise shift buffer by 4 bursts for interleaving */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 928);
+ if (!*bursts_p)
+ return NULL;
+ } else {
+ memcpy(*bursts_p, *bursts_p + 464, 464);
+ memset(*bursts_p + 464, 0, 464);
+ }
+
+ /* no message at all */
+ if (!msg_tch && !msg_facch) {
+ LOGP(DL1C, LOGL_INFO, "%s has not been served !! No prim for "
+ "trx=%u ts=%u at fn=%u to transmit.\n",
+ trx_chan_desc[chan].name, l1h->trx->nr, tn, fn);
+ goto send_burst;
+ }
+
+ /* encode bursts (priorize FACCH) */
+ if (msg_facch)
+ tch_fr_encode(*bursts_p, msg_facch->l2h, msgb_l2len(msg_facch),
+ 1);
+ else if (tch_mode == GSM48_CMODE_SPEECH_AMR)
+ /* the first FN 4,13,21 defines that CMI is included in frame,
+ * the first FN 0,8,17 defines that CMR is included in frame.
+ */
+ tch_afs_encode(*bursts_p, msg_tch->l2h + 2,
+ msgb_l2len(msg_tch) - 2, (((fn + 4) % 26) >> 2) & 1,
+ chan_state->codec, chan_state->codecs,
+ chan_state->dl_ft,
+ chan_state->dl_cmr);
+ else
+ tch_fr_encode(*bursts_p, msg_tch->l2h, msgb_l2len(msg_tch), 1);
+
+ /* free message */
+ if (msg_tch)
+ msgb_free(msg_tch);
+ if (msg_facch)
+ msgb_free(msg_facch);
+
+send_burst:
+ /* compose burst */
+ burst = *bursts_p + bid * 116;
+ memset(bits, 0, 3);
+ memcpy(bits + 3, burst, 58);
+ memcpy(bits + 61, tsc[l1h->config.tsc], 26);
+ memcpy(bits + 87, burst + 58, 58);
+ memset(bits + 145, 0, 3);
+
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u burst=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ return bits;
+}
+
+static ubit_t *tx_tchh_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid)
+{
+ struct msgb *msg_tch = NULL, *msg_facch = NULL;
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ uint8_t tch_mode = chan_state->tch_mode;
+ ubit_t *burst, **bursts_p = &chan_state->dl_bursts;
+ static ubit_t bits[148];
+
+ /* send burst, if we already got a frame */
+ if (bid > 0) {
+ if (!*bursts_p)
+ return NULL;
+ goto send_burst;
+ }
+
+ /* get TCH and/or FACCH */
+ tx_tch_common(l1h, tn, fn, chan, bid, &msg_tch, &msg_facch,
+ (((fn + 4) % 26) >> 2) & 1);
+
+ /* check for FACCH alignment */
+ if (msg_facch && ((((fn + 4) % 26) >> 2) & 1)) {
+ LOGP(DL1C, LOGL_ERROR, "%s Cannot transmit FACCH starting on "
+ "even frames, please fix RTS!\n",
+ trx_chan_desc[chan].name);
+ msgb_free(msg_facch);
+ msg_facch = NULL;
+ }
+
+ /* alloc burst memory, if not already,
+ * otherwise shift buffer by 2 bursts for interleaving */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 696);
+ if (!*bursts_p)
+ return NULL;
+ } else {
+ memcpy(*bursts_p, *bursts_p + 232, 232);
+ if (chan_state->dl_ongoing_facch) {
+ memcpy(*bursts_p + 232, *bursts_p + 464, 232);
+ memset(*bursts_p + 464, 0, 232);
+ } else {
+ memset(*bursts_p + 232, 0, 232);
+ }
+ }
+
+ /* no message at all */
+ if (!msg_tch && !msg_facch && !chan_state->dl_ongoing_facch) {
+ LOGP(DL1C, LOGL_INFO, "%s has not been served !! No prim for "
+ "trx=%u ts=%u at fn=%u to transmit.\n",
+ trx_chan_desc[chan].name, l1h->trx->nr, tn, fn);
+ goto send_burst;
+ }
+
+ /* encode bursts (priorize FACCH) */
+ if (msg_facch) {
+ tch_hr_encode(*bursts_p, msg_facch->l2h, msgb_l2len(msg_facch));
+ chan_state->dl_ongoing_facch = 1; /* first of two tch frames */
+ } else if (chan_state->dl_ongoing_facch) /* second of two tch frames */
+ chan_state->dl_ongoing_facch = 0; /* we are done with FACCH */
+ else if (tch_mode == GSM48_CMODE_SPEECH_AMR)
+ /* the first FN 4,13,21 or 5,14,22 defines that CMI is included
+ * in frame, the first FN 0,8,17 or 1,9,18 defines that CMR is
+ * included in frame. */
+ tch_ahs_encode(*bursts_p, msg_tch->l2h + 2,
+ msgb_l2len(msg_tch) - 2, (((fn + 4) % 26) >> 2) & 1,
+ chan_state->codec, chan_state->codecs,
+ chan_state->dl_ft,
+ chan_state->dl_cmr);
+ else
+ tch_hr_encode(*bursts_p, msg_tch->l2h, msgb_l2len(msg_tch));
+
+ /* free message */
+ if (msg_tch)
+ msgb_free(msg_tch);
+ if (msg_facch)
+ msgb_free(msg_facch);
+
+send_burst:
+ /* compose burst */
+ burst = *bursts_p + bid * 116;
+ memset(bits, 0, 3);
+ memcpy(bits + 3, burst, 58);
+ memcpy(bits + 61, tsc[l1h->config.tsc], 26);
+ memcpy(bits + 87, burst + 58, 58);
+ memset(bits + 145, 0, 3);
+
+ LOGP(DL1C, LOGL_DEBUG, "Transmitting %s fn=%u ts=%u trx=%u burst=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ return bits;
+}
+
+
+/*
+ * RX on uplink (indication to upper layer)
+ */
+
+static int rx_rach_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa)
+{
+ uint8_t chan_nr;
+ struct osmo_phsap_prim l1sap;
+ uint8_t ra;
+ int rc;
+
+ chan_nr = trx_chan_desc[chan].chan_nr | tn;
+
+ LOGP(DL1C, LOGL_NOTICE, "Received Access Burst on %s fn=%u toa=%.2f\n",
+ trx_chan_desc[chan].name, fn, toa);
+
+ /* decode */
+ rc = rach_decode(&ra, bits + 8 + 41, l1h->trx->bts->bsic);
+ if (rc) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad AB frame at fn=%u "
+ "(%u/51)\n", fn, fn % 51);
+ return 0;
+ }
+
+ /* compose primitive */
+ /* generate prim */
+ memset(&l1sap, 0, sizeof(l1sap));
+ osmo_prim_init(&l1sap.oph, SAP_GSM_PH, PRIM_PH_RACH, PRIM_OP_INDICATION,
+ NULL);
+ l1sap.u.rach_ind.chan_nr = chan_nr;
+ l1sap.u.rach_ind.ra = ra;
+#ifdef TA_TEST
+#warning TIMING ADVANCE TEST-HACK IS ENABLED!!!
+ toa *= 10;
+#endif
+ l1sap.u.rach_ind.acc_delay = (toa >= 0) ? toa : 0;
+ l1sap.u.rach_ind.fn = fn;
+
+ /* forward primitive */
+ l1sap_up(l1h->trx, &l1sap);
+
+ return 0;
+}
+
+static int rx_data_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa)
+{
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ sbit_t *burst, **bursts_p = &chan_state->ul_bursts;
+ uint32_t *first_fn = &chan_state->ul_first_fn;
+ uint8_t *mask = &chan_state->ul_mask;
+ float *rssi_sum = &chan_state->rssi_sum;
+ uint8_t *rssi_num = &chan_state->rssi_num;
+ float *toa_sum = &chan_state->toa_sum;
+ uint8_t *toa_num = &chan_state->toa_num;
+ uint8_t l2[23], l2_len;
+ int n_errors, n_bits_total;
+ int rc;
+
+ /* handle rach, if handover rach detection is turned on */
+ if (chan_state->ho_rach_detect == 1)
+ return rx_rach_fn(l1h, tn, fn, chan, bid, bits, rssi, toa);
+
+ LOGP(DL1C, LOGL_DEBUG, "Data received %s fn=%u ts=%u trx=%u bid=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ /* alloc burst memory, if not already */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 464);
+ if (!*bursts_p)
+ return -ENOMEM;
+ }
+
+ /* clear burst & store frame number of first burst */
+ if (bid == 0) {
+ memset(*bursts_p, 0, 464);
+ *mask = 0x0;
+ *first_fn = fn;
+ *rssi_sum = 0;
+ *rssi_num = 0;
+ *toa_sum = 0;
+ *toa_num = 0;
+ }
+
+ /* update mask + rssi */
+ *mask |= (1 << bid);
+ *rssi_sum += rssi;
+ (*rssi_num)++;
+ *toa_sum += toa;
+ (*toa_num)++;
+
+ /* copy burst to buffer of 4 bursts */
+ burst = *bursts_p + bid * 116;
+ memcpy(burst, bits + 3, 58);
+ memcpy(burst + 58, bits + 87, 58);
+
+ /* send burst information to loops process */
+ if (L1SAP_IS_LINK_SACCH(trx_chan_desc[chan].link_id)) {
+ trx_loop_sacch_input(l1h, trx_chan_desc[chan].chan_nr | tn,
+ chan_state, rssi, toa);
+ }
+
+ /* wait until complete set of bursts */
+ if (bid != 3)
+ return 0;
+
+ /* check for complete set of bursts */
+ if ((*mask & 0xf) != 0xf) {
+ LOGP(DL1C, LOGL_NOTICE, "Received incomplete data frame at "
+ "fn=%u (%u/%u) for %s\n", *first_fn,
+ (*first_fn) % l1h->mf_period[tn], l1h->mf_period[tn],
+ trx_chan_desc[chan].name);
+
+ /* we require first burst to have correct FN */
+ if (!(*mask & 0x1)) {
+ *mask = 0x0;
+ return 0;
+ }
+ }
+ *mask = 0x0;
+
+ /* decode */
+ rc = xcch_decode(l2, *bursts_p, &n_errors, &n_bits_total);
+ if (rc) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad data frame at fn=%u "
+ "(%u/%u) for %s\n", *first_fn,
+ (*first_fn) % l1h->mf_period[tn], l1h->mf_period[tn],
+ trx_chan_desc[chan].name);
+ l2_len = 0;
+ } else
+ l2_len = 23;
+
+ /* Send uplnk measurement information to L2 */
+ l1if_process_meas_res(l1h->trx, tn, fn, trx_chan_desc[chan].chan_nr | tn,
+ n_errors, n_bits_total, *rssi_sum / *rssi_num, *toa_sum / *toa_num);
+
+ return compose_ph_data_ind(l1h, tn, *first_fn, chan, l2, l2_len, *rssi_sum / *rssi_num);
+}
+
+static int rx_pdtch_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa)
+{
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ sbit_t *burst, **bursts_p = &chan_state->ul_bursts;
+ uint8_t *mask = &chan_state->ul_mask;
+ float *rssi_sum = &chan_state->rssi_sum;
+ uint8_t *rssi_num = &chan_state->rssi_num;
+ float *toa_sum = &chan_state->toa_sum;
+ uint8_t *toa_num = &chan_state->toa_num;
+ uint8_t l2[54+1];
+ int n_errors, n_bits_total;
+ int rc;
+
+ LOGP(DL1C, LOGL_DEBUG, "PDTCH received %s fn=%u ts=%u trx=%u bid=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ /* alloc burst memory, if not already */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 464);
+ if (!*bursts_p)
+ return -ENOMEM;
+ }
+
+ /* clear burst */
+ if (bid == 0) {
+ memset(*bursts_p, 0, 464);
+ *mask = 0x0;
+ *rssi_sum = 0;
+ *rssi_num = 0;
+ *toa_sum = 0;
+ *toa_num = 0;
+ }
+
+ /* update mask + rssi */
+ *mask |= (1 << bid);
+ *rssi_sum += rssi;
+ (*rssi_num)++;
+ *toa_sum += toa;
+ (*toa_num)++;
+
+ /* copy burst to buffer of 4 bursts */
+ burst = *bursts_p + bid * 116;
+ memcpy(burst, bits + 3, 58);
+ memcpy(burst + 58, bits + 87, 58);
+
+ /* wait until complete set of bursts */
+ if (bid != 3)
+ return 0;
+
+ /* check for complete set of bursts */
+ if ((*mask & 0xf) != 0xf) {
+ LOGP(DL1C, LOGL_NOTICE, "Received incomplete PDTCH block "
+ "ending at fn=%u (%u/%u) for %s\n", fn,
+ fn % l1h->mf_period[tn], l1h->mf_period[tn],
+ trx_chan_desc[chan].name);
+ }
+ *mask = 0x0;
+
+ /* decode */
+ rc = pdtch_decode(l2 + 1, *bursts_p, NULL, &n_errors, &n_bits_total);
+
+ /* Send uplnk measurement information to L2 */
+ l1if_process_meas_res(l1h->trx, tn, fn, trx_chan_desc[chan].chan_nr | tn,
+ n_errors, n_bits_total, *rssi_sum / *rssi_num, *toa_sum / *toa_num);
+
+ if (rc <= 0) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad PDTCH block ending at "
+ "fn=%u (%u/%u) for %s\n", fn, fn % l1h->mf_period[tn],
+ l1h->mf_period[tn], trx_chan_desc[chan].name);
+ return 0;
+ }
+
+ l2[0] = 7; /* valid frame */
+
+ return compose_ph_data_ind(l1h, tn, (fn + 2715648 - 3) % 2715648, chan,
+ l2, rc + 1, *rssi_sum / *rssi_num);
+}
+
+static int rx_tchf_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa)
+{
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ sbit_t *burst, **bursts_p = &chan_state->ul_bursts;
+ uint8_t *mask = &chan_state->ul_mask;
+ uint8_t rsl_cmode = chan_state->rsl_cmode;
+ uint8_t tch_mode = chan_state->tch_mode;
+ uint8_t tch_data[128]; /* just to be safe */
+ int rc, amr = 0;
+ int n_errors, n_bits_total;
+
+ /* handle rach, if handover rach detection is turned on */
+ if (chan_state->ho_rach_detect == 1)
+ return rx_rach_fn(l1h, tn, fn, chan, bid, bits, rssi, toa);
+
+ LOGP(DL1C, LOGL_DEBUG, "TCH/F received %s fn=%u ts=%u trx=%u bid=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ /* alloc burst memory, if not already */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 928);
+ if (!*bursts_p)
+ return -ENOMEM;
+ }
+
+ /* clear burst */
+ if (bid == 0) {
+ memset(*bursts_p + 464, 0, 464);
+ *mask = 0x0;
+ }
+
+ /* update mask */
+ *mask |= (1 << bid);
+
+ /* copy burst to end of buffer of 8 bursts */
+ burst = *bursts_p + bid * 116 + 464;
+ memcpy(burst, bits + 3, 58);
+ memcpy(burst + 58, bits + 87, 58);
+
+ /* wait until complete set of bursts */
+ if (bid != 3)
+ return 0;
+
+ /* check for complete set of bursts */
+ if ((*mask & 0xf) != 0xf) {
+ LOGP(DL1C, LOGL_NOTICE, "Received incomplete TCH frame ending "
+ "at fn=%u (%u/%u) for %s\n", fn,
+ fn % l1h->mf_period[tn], l1h->mf_period[tn],
+ trx_chan_desc[chan].name);
+ }
+ *mask = 0x0;
+
+ /* decode
+ * also shift buffer by 4 bursts for interleaving */
+ switch ((rsl_cmode != RSL_CMOD_SPD_SPEECH) ? GSM48_CMODE_SPEECH_V1
+ : tch_mode) {
+ case GSM48_CMODE_SPEECH_V1: /* FR */
+ rc = tch_fr_decode(tch_data, *bursts_p, 1, 0, &n_errors, &n_bits_total);
+ break;
+ case GSM48_CMODE_SPEECH_EFR: /* EFR */
+ rc = tch_fr_decode(tch_data, *bursts_p, 1, 1, &n_errors, &n_bits_total);
+ break;
+ case GSM48_CMODE_SPEECH_AMR: /* AMR */
+ /* the first FN 0,8,17 defines that CMI is included in frame,
+ * the first FN 4,13,21 defines that CMR is included in frame.
+ * NOTE: A frame ends 7 FN after start.
+ */
+ rc = tch_afs_decode(tch_data + 2, *bursts_p,
+ (((fn + 26 - 7) % 26) >> 2) & 1, chan_state->codec,
+ chan_state->codecs, &chan_state->ul_ft,
+ &chan_state->ul_cmr, &n_errors, &n_bits_total);
+ if (rc)
+ trx_loop_amr_input(l1h,
+ trx_chan_desc[chan].chan_nr | tn, chan_state,
+ (float)n_errors/(float)n_bits_total);
+ amr = 2; /* we store tch_data + 2 header bytes */
+ /* only good speech frames get rtp header */
+ if (rc != 23 && rc >= 4) {
+ rc = amr_compose_payload(tch_data,
+ chan_state->codec[chan_state->ul_cmr],
+ chan_state->codec[chan_state->ul_ft], 0);
+ }
+ break;
+ default:
+ LOGP(DL1C, LOGL_ERROR, "TCH mode %u invalid, please fix!\n",
+ tch_mode);
+ return -EINVAL;
+ }
+ memcpy(*bursts_p, *bursts_p + 464, 464);
+
+ /* Send uplnk measurement information to L2 */
+ l1if_process_meas_res(l1h->trx, tn, fn, trx_chan_desc[chan].chan_nr|tn,
+ n_errors, n_bits_total, rssi, toa);
+
+ /* Check if the frame is bad */
+ if (rc < 0) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad TCH frame ending at "
+ "fn=%u for %s\n", fn, trx_chan_desc[chan].name);
+ goto bfi;
+ }
+ if (rc < 4) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad TCH frame ending at "
+ "fn=%u for %s with codec mode %d (out of range)\n",
+ fn, trx_chan_desc[chan].name, rc);
+ goto bfi;
+ }
+
+ /* FACCH */
+ if (rc == 23) {
+ compose_ph_data_ind(l1h, tn, (fn + 2715648 - 7) % 2715648, chan,
+ tch_data + amr, 23, rssi);
+bfi:
+ if (rsl_cmode == RSL_CMOD_SPD_SPEECH) {
+ /* indicate bad frame */
+ switch (tch_mode) {
+ case GSM48_CMODE_SPEECH_V1: /* FR */
+ memset(tch_data, 0, 33);
+ rc = 33;
+ break;
+ case GSM48_CMODE_SPEECH_EFR: /* EFR */
+ memset(tch_data, 0, 31);
+ rc = 31;
+ break;
+ case GSM48_CMODE_SPEECH_AMR: /* AMR */
+ rc = amr_compose_payload(tch_data,
+ chan_state->codec[chan_state->dl_cmr],
+ chan_state->codec[chan_state->dl_ft],
+ 1);
+ if (rc < 2)
+ break;
+ memset(tch_data + 2, 0, rc - 2);
+ break;
+ default:
+ LOGP(DL1C, LOGL_ERROR, "TCH mode invalid, "
+ "please fix!\n");
+ return -EINVAL;
+ }
+ }
+ }
+
+ if (rsl_cmode != RSL_CMOD_SPD_SPEECH)
+ return 0;
+
+ /* TCH or BFI */
+ return compose_tch_ind(l1h, tn, (fn + 2715648 - 7) % 2715648, chan,
+ tch_data, rc);
+}
+
+static int rx_tchh_fn(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ enum trx_chan_type chan, uint8_t bid, sbit_t *bits, int8_t rssi,
+ float toa)
+{
+ struct trx_chan_state *chan_state = &l1h->chan_states[tn][chan];
+ sbit_t *burst, **bursts_p = &chan_state->ul_bursts;
+ uint8_t *mask = &chan_state->ul_mask;
+ uint8_t rsl_cmode = chan_state->rsl_cmode;
+ uint8_t tch_mode = chan_state->tch_mode;
+ uint8_t tch_data[128]; /* just to be safe */
+ int rc, amr = 0;
+ int n_errors, n_bits_total;
+
+ /* handle rach, if handover rach detection is turned on */
+ if (chan_state->ho_rach_detect == 1)
+ return rx_rach_fn(l1h, tn, fn, chan, bid, bits, rssi, toa);
+
+ LOGP(DL1C, LOGL_DEBUG, "TCH/H received %s fn=%u ts=%u trx=%u bid=%u\n",
+ trx_chan_desc[chan].name, fn, tn, l1h->trx->nr, bid);
+
+ /* alloc burst memory, if not already */
+ if (!*bursts_p) {
+ *bursts_p = talloc_zero_size(tall_bts_ctx, 696);
+ if (!*bursts_p)
+ return -ENOMEM;
+ }
+
+ /* clear burst */
+ if (bid == 0) {
+ memset(*bursts_p + 464, 0, 232);
+ *mask = 0x0;
+ }
+
+ /* update mask */
+ *mask |= (1 << bid);
+
+ /* copy burst to end of buffer of 6 bursts */
+ burst = *bursts_p + bid * 116 + 464;
+ memcpy(burst, bits + 3, 58);
+ memcpy(burst + 58, bits + 87, 58);
+
+ /* wait until complete set of bursts */
+ if (bid != 1)
+ return 0;
+
+ /* check for complete set of bursts */
+ if ((*mask & 0x3) != 0x3) {
+ LOGP(DL1C, LOGL_NOTICE, "Received incomplete TCH frame ending "
+ "at fn=%u (%u/%u) for %s\n", fn,
+ fn % l1h->mf_period[tn], l1h->mf_period[tn],
+ trx_chan_desc[chan].name);
+ }
+ *mask = 0x0;
+
+ /* skip second of two TCH frames of FACCH was received */
+ if (chan_state->ul_ongoing_facch) {
+ chan_state->ul_ongoing_facch = 0;
+ memcpy(*bursts_p, *bursts_p + 232, 232);
+ memcpy(*bursts_p + 232, *bursts_p + 464, 232);
+ goto bfi;
+ }
+
+ /* decode
+ * also shift buffer by 4 bursts for interleaving */
+ switch ((rsl_cmode != RSL_CMOD_SPD_SPEECH) ? GSM48_CMODE_SPEECH_V1
+ : tch_mode) {
+ case GSM48_CMODE_SPEECH_V1: /* HR or signalling */
+ /* Note on FN-10: If we are at FN 10, we decoded an even aligned
+ * TCH/FACCH frame, because our burst buffer carries 6 bursts.
+ * Even FN ending at: 10,11,19,20,2,3
+ */
+ rc = tch_hr_decode(tch_data, *bursts_p,
+ (((fn + 26 - 10) % 26) >> 2) & 1,
+ &n_errors, &n_bits_total);
+ break;
+ case GSM48_CMODE_SPEECH_AMR: /* AMR */
+ /* the first FN 0,8,17 or 1,9,18 defines that CMI is included
+ * in frame, the first FN 4,13,21 or 5,14,22 defines that CMR
+ * is included in frame.
+ */
+ rc = tch_ahs_decode(tch_data + 2, *bursts_p,
+ (((fn + 26 - 10) % 26) >> 2) & 1,
+ (((fn + 26 - 10) % 26) >> 2) & 1, chan_state->codec,
+ chan_state->codecs, &chan_state->ul_ft,
+ &chan_state->ul_cmr, &n_errors, &n_bits_total);
+ if (rc)
+ trx_loop_amr_input(l1h,
+ trx_chan_desc[chan].chan_nr | tn, chan_state,
+ (float)n_errors/(float)n_bits_total);
+ amr = 2; /* we store tch_data + 2 two */
+ /* only good speech frames get rtp header */
+ if (rc != 23 && rc >= 4) {
+ rc = amr_compose_payload(tch_data,
+ chan_state->codec[chan_state->ul_cmr],
+ chan_state->codec[chan_state->ul_ft], 0);
+ }
+ break;
+ default:
+ LOGP(DL1C, LOGL_ERROR, "TCH mode %u invalid, please fix!\n",
+ tch_mode);
+ return -EINVAL;
+ }
+ memcpy(*bursts_p, *bursts_p + 232, 232);
+ memcpy(*bursts_p + 232, *bursts_p + 464, 232);
+
+ /* Send uplnk measurement information to L2 */
+ l1if_process_meas_res(l1h->trx, tn, fn, trx_chan_desc[chan].chan_nr|tn,
+ n_errors, n_bits_total, rssi, toa);
+
+ /* Check if the frame is bad */
+ if (rc < 0) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad TCH frame ending at "
+ "fn=%u for %s\n", fn, trx_chan_desc[chan].name);
+ goto bfi;
+ }
+ if (rc < 4) {
+ LOGP(DL1C, LOGL_NOTICE, "Received bad TCH frame ending at "
+ "fn=%u for %s with codec mode %d (out of range)\n",
+ fn, trx_chan_desc[chan].name, rc);
+ goto bfi;
+ }
+
+ /* FACCH */
+ if (rc == 23) {
+ chan_state->ul_ongoing_facch = 1;
+ compose_ph_data_ind(l1h, tn,
+ (fn + 2715648 - 10 - ((fn % 26) >= 19)) % 2715648, chan,
+ tch_data + amr, 23, rssi);
+bfi:
+ if (rsl_cmode == RSL_CMOD_SPD_SPEECH) {
+ /* indicate bad frame */
+ switch (tch_mode) {
+ case GSM48_CMODE_SPEECH_V1: /* HR */
+ tch_data[0] = 0x70; /* F = 0, FT = 111 */
+ memset(tch_data + 1, 0, 14);
+ rc = 15;
+ break;
+ case GSM48_CMODE_SPEECH_AMR: /* AMR */
+ rc = amr_compose_payload(tch_data,
+ chan_state->codec[chan_state->dl_cmr],
+ chan_state->codec[chan_state->dl_ft],
+ 1);
+ if (rc < 2)
+ break;
+ memset(tch_data + 2, 0, rc - 2);
+ break;
+ default:
+ LOGP(DL1C, LOGL_ERROR, "TCH mode invalid, "
+ "please fix!\n");
+ return -EINVAL;
+ }
+ }
+ }
+
+ if (rsl_cmode != RSL_CMOD_SPD_SPEECH)
+ return 0;
+
+ /* TCH or BFI */
+ /* Note on FN 19 or 20: If we received the last burst of a frame,
+ * it actually starts at FN 8 or 9. A burst starting there, overlaps
+ * with the slot 12, so an extra FN must be substracted to get correct
+ * start of frame.
+ */
+ return compose_tch_ind(l1h, tn,
+ (fn + 2715648 - 10 - ((fn%26)==19) - ((fn%26)==20)) % 2715648,
+ chan, tch_data, rc);
+}
+
+
+/*
+ * multiframe structure
+ */
+
+/* frame structures */
+struct trx_sched_frame {
+ enum trx_chan_type dl_chan;
+ uint8_t dl_bid;
+ enum trx_chan_type ul_chan;
+ uint8_t ul_bid;
+};
+
+static struct trx_sched_frame frame_bcch[51] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_BCCH, 0, TRXC_RACH, 0 }, { TRXC_BCCH, 1, TRXC_RACH, 0 }, { TRXC_BCCH, 2, TRXC_RACH, 0 }, { TRXC_BCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 }, { TRXC_CCCH, 1, TRXC_RACH, 0 }, { TRXC_CCCH, 2, TRXC_RACH, 0 }, { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_IDLE, 0, TRXC_RACH, 0 },
+};
+
+static struct trx_sched_frame frame_bcch_sdcch4[102] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_FCCH, 0, TRXC_SDCCH4_3, 0 },
+ { TRXC_SCH, 0, TRXC_SDCCH4_3, 1 },
+ { TRXC_BCCH, 0, TRXC_SDCCH4_3, 2 },
+ { TRXC_BCCH, 1, TRXC_SDCCH4_3, 3 },
+ { TRXC_BCCH, 2, TRXC_RACH, 0 },
+ { TRXC_BCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_SACCH4_2, 0 },
+ { TRXC_CCCH, 1, TRXC_SACCH4_2, 1 },
+ { TRXC_CCCH, 2, TRXC_SACCH4_2, 2 },
+ { TRXC_CCCH, 3, TRXC_SACCH4_2, 3 },
+ { TRXC_FCCH, 0, TRXC_SACCH4_3, 0 },
+ { TRXC_SCH, 0, TRXC_SACCH4_3, 1 },
+ { TRXC_CCCH, 0, TRXC_SACCH4_3, 2 },
+ { TRXC_CCCH, 1, TRXC_SACCH4_3, 3 },
+ { TRXC_CCCH, 2, TRXC_RACH, 0 },
+ { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 },
+ { TRXC_CCCH, 1, TRXC_RACH, 0 },
+ { TRXC_CCCH, 2, TRXC_RACH, 0 },
+ { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 1, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 2, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 3, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 1, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 2, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 1, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 2, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 3, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_3, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_3, 1, TRXC_SDCCH4_0, 0 },
+ { TRXC_SDCCH4_3, 2, TRXC_SDCCH4_0, 1 },
+ { TRXC_SDCCH4_3, 3, TRXC_SDCCH4_0, 2 },
+ { TRXC_FCCH, 0, TRXC_SDCCH4_0, 3 },
+ { TRXC_SCH, 0, TRXC_SDCCH4_1, 0 },
+ { TRXC_SACCH4_0, 0, TRXC_SDCCH4_1, 1 },
+ { TRXC_SACCH4_0, 1, TRXC_SDCCH4_1, 2 },
+ { TRXC_SACCH4_0, 2, TRXC_SDCCH4_1, 3 },
+ { TRXC_SACCH4_0, 3, TRXC_RACH, 0 },
+ { TRXC_SACCH4_1, 0, TRXC_RACH, 0 },
+ { TRXC_SACCH4_1, 1, TRXC_SDCCH4_2, 0 },
+ { TRXC_SACCH4_1, 2, TRXC_SDCCH4_2, 1 },
+ { TRXC_SACCH4_1, 3, TRXC_SDCCH4_2, 2 },
+ { TRXC_IDLE, 0, TRXC_SDCCH4_2, 3 },
+
+ { TRXC_FCCH, 0, TRXC_SDCCH4_3, 0 },
+ { TRXC_SCH, 0, TRXC_SDCCH4_3, 1 },
+ { TRXC_BCCH, 0, TRXC_SDCCH4_3, 2 },
+ { TRXC_BCCH, 1, TRXC_SDCCH4_3, 3 },
+ { TRXC_BCCH, 2, TRXC_RACH, 0 },
+ { TRXC_BCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_SACCH4_0, 0 },
+ { TRXC_CCCH, 1, TRXC_SACCH4_0, 1 },
+ { TRXC_CCCH, 2, TRXC_SACCH4_0, 2 },
+ { TRXC_CCCH, 3, TRXC_SACCH4_0, 3 },
+ { TRXC_FCCH, 0, TRXC_SACCH4_1, 0 },
+ { TRXC_SCH, 0, TRXC_SACCH4_1, 1 },
+ { TRXC_CCCH, 0, TRXC_SACCH4_1, 2 },
+ { TRXC_CCCH, 1, TRXC_SACCH4_1, 3 },
+ { TRXC_CCCH, 2, TRXC_RACH, 0 },
+ { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_CCCH, 0, TRXC_RACH, 0 },
+ { TRXC_CCCH, 1, TRXC_RACH, 0 },
+ { TRXC_CCCH, 2, TRXC_RACH, 0 },
+ { TRXC_CCCH, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 1, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 2, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_0, 3, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 1, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 2, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_1, 3, TRXC_RACH, 0 },
+ { TRXC_FCCH, 0, TRXC_RACH, 0 },
+ { TRXC_SCH, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 1, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 2, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_2, 3, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_3, 0, TRXC_RACH, 0 },
+ { TRXC_SDCCH4_3, 1, TRXC_SDCCH4_0, 0 },
+ { TRXC_SDCCH4_3, 2, TRXC_SDCCH4_0, 1 },
+ { TRXC_SDCCH4_3, 3, TRXC_SDCCH4_0, 2 },
+ { TRXC_FCCH, 0, TRXC_SDCCH4_0, 3 },
+ { TRXC_SCH, 0, TRXC_SDCCH4_1, 0 },
+ { TRXC_SACCH4_2, 0, TRXC_SDCCH4_1, 1 },
+ { TRXC_SACCH4_2, 1, TRXC_SDCCH4_1, 2 },
+ { TRXC_SACCH4_2, 2, TRXC_SDCCH4_1, 3 },
+ { TRXC_SACCH4_2, 3, TRXC_RACH, 0 },
+ { TRXC_SACCH4_3, 0, TRXC_RACH, 0 },
+ { TRXC_SACCH4_3, 1, TRXC_SDCCH4_2, 0 },
+ { TRXC_SACCH4_3, 2, TRXC_SDCCH4_2, 1 },
+ { TRXC_SACCH4_3, 3, TRXC_SDCCH4_2, 2 },
+ { TRXC_IDLE, 0, TRXC_SDCCH4_2, 3 },
+};
+
+static struct trx_sched_frame frame_sdcch8[102] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_SDCCH8_0, 0, TRXC_SACCH8_5, 0 },
+ { TRXC_SDCCH8_0, 1, TRXC_SACCH8_5, 1 },
+ { TRXC_SDCCH8_0, 2, TRXC_SACCH8_5, 2 },
+ { TRXC_SDCCH8_0, 3, TRXC_SACCH8_5, 3 },
+ { TRXC_SDCCH8_1, 0, TRXC_SACCH8_6, 0 },
+ { TRXC_SDCCH8_1, 1, TRXC_SACCH8_6, 1 },
+ { TRXC_SDCCH8_1, 2, TRXC_SACCH8_6, 2 },
+ { TRXC_SDCCH8_1, 3, TRXC_SACCH8_6, 3 },
+ { TRXC_SDCCH8_2, 0, TRXC_SACCH8_7, 0 },
+ { TRXC_SDCCH8_2, 1, TRXC_SACCH8_7, 1 },
+ { TRXC_SDCCH8_2, 2, TRXC_SACCH8_7, 2 },
+ { TRXC_SDCCH8_2, 3, TRXC_SACCH8_7, 3 },
+ { TRXC_SDCCH8_3, 0, TRXC_IDLE, 0 },
+ { TRXC_SDCCH8_3, 1, TRXC_IDLE, 0 },
+ { TRXC_SDCCH8_3, 2, TRXC_IDLE, 0 },
+ { TRXC_SDCCH8_3, 3, TRXC_SDCCH8_0, 0 },
+ { TRXC_SDCCH8_4, 0, TRXC_SDCCH8_0, 1 },
+ { TRXC_SDCCH8_4, 1, TRXC_SDCCH8_0, 2 },
+ { TRXC_SDCCH8_4, 2, TRXC_SDCCH8_0, 3 },
+ { TRXC_SDCCH8_4, 3, TRXC_SDCCH8_1, 0 },
+ { TRXC_SDCCH8_5, 0, TRXC_SDCCH8_1, 1 },
+ { TRXC_SDCCH8_5, 1, TRXC_SDCCH8_1, 2 },
+ { TRXC_SDCCH8_5, 2, TRXC_SDCCH8_1, 3 },
+ { TRXC_SDCCH8_5, 3, TRXC_SDCCH8_2, 0 },
+ { TRXC_SDCCH8_6, 0, TRXC_SDCCH8_2, 1 },
+ { TRXC_SDCCH8_6, 1, TRXC_SDCCH8_2, 2 },
+ { TRXC_SDCCH8_6, 2, TRXC_SDCCH8_2, 3 },
+ { TRXC_SDCCH8_6, 3, TRXC_SDCCH8_3, 0 },
+ { TRXC_SDCCH8_7, 0, TRXC_SDCCH8_3, 1 },
+ { TRXC_SDCCH8_7, 1, TRXC_SDCCH8_3, 2 },
+ { TRXC_SDCCH8_7, 2, TRXC_SDCCH8_3, 3 },
+ { TRXC_SDCCH8_7, 3, TRXC_SDCCH8_4, 0 },
+ { TRXC_SACCH8_0, 0, TRXC_SDCCH8_4, 1 },
+ { TRXC_SACCH8_0, 1, TRXC_SDCCH8_4, 2 },
+ { TRXC_SACCH8_0, 2, TRXC_SDCCH8_4, 3 },
+ { TRXC_SACCH8_0, 3, TRXC_SDCCH8_5, 0 },
+ { TRXC_SACCH8_1, 0, TRXC_SDCCH8_5, 1 },
+ { TRXC_SACCH8_1, 1, TRXC_SDCCH8_5, 2 },
+ { TRXC_SACCH8_1, 2, TRXC_SDCCH8_5, 3 },
+ { TRXC_SACCH8_1, 3, TRXC_SDCCH8_6, 0 },
+ { TRXC_SACCH8_2, 0, TRXC_SDCCH8_6, 1 },
+ { TRXC_SACCH8_2, 1, TRXC_SDCCH8_6, 2 },
+ { TRXC_SACCH8_2, 2, TRXC_SDCCH8_6, 3 },
+ { TRXC_SACCH8_2, 3, TRXC_SDCCH8_7, 0 },
+ { TRXC_SACCH8_3, 0, TRXC_SDCCH8_7, 1 },
+ { TRXC_SACCH8_3, 1, TRXC_SDCCH8_7, 2 },
+ { TRXC_SACCH8_3, 2, TRXC_SDCCH8_7, 3 },
+ { TRXC_SACCH8_3, 3, TRXC_SACCH8_0, 0 },
+ { TRXC_IDLE, 0, TRXC_SACCH8_0, 1 },
+ { TRXC_IDLE, 0, TRXC_SACCH8_0, 2 },
+ { TRXC_IDLE, 0, TRXC_SACCH8_0, 3 },
+
+ { TRXC_SDCCH8_0, 0, TRXC_SACCH8_1, 0 },
+ { TRXC_SDCCH8_0, 1, TRXC_SACCH8_1, 1 },
+ { TRXC_SDCCH8_0, 2, TRXC_SACCH8_1, 2 },
+ { TRXC_SDCCH8_0, 3, TRXC_SACCH8_1, 3 },
+ { TRXC_SDCCH8_1, 0, TRXC_SACCH8_2, 0 },
+ { TRXC_SDCCH8_1, 1, TRXC_SACCH8_2, 1 },
+ { TRXC_SDCCH8_1, 2, TRXC_SACCH8_2, 2 },
+ { TRXC_SDCCH8_1, 3, TRXC_SACCH8_2, 3 },
+ { TRXC_SDCCH8_2, 0, TRXC_SACCH8_3, 0 },
+ { TRXC_SDCCH8_2, 1, TRXC_SACCH8_3, 1 },
+ { TRXC_SDCCH8_2, 2, TRXC_SACCH8_3, 2 },
+ { TRXC_SDCCH8_2, 3, TRXC_SACCH8_3, 3 },
+ { TRXC_SDCCH8_3, 0, TRXC_IDLE, 0 },
+ { TRXC_SDCCH8_3, 1, TRXC_IDLE, 0 },
+ { TRXC_SDCCH8_3, 2, TRXC_IDLE, 0 },
+ { TRXC_SDCCH8_3, 3, TRXC_SDCCH8_0, 0 },
+ { TRXC_SDCCH8_4, 0, TRXC_SDCCH8_0, 1 },
+ { TRXC_SDCCH8_4, 1, TRXC_SDCCH8_0, 2 },
+ { TRXC_SDCCH8_4, 2, TRXC_SDCCH8_0, 3 },
+ { TRXC_SDCCH8_4, 3, TRXC_SDCCH8_1, 0 },
+ { TRXC_SDCCH8_5, 0, TRXC_SDCCH8_1, 1 },
+ { TRXC_SDCCH8_5, 1, TRXC_SDCCH8_1, 2 },
+ { TRXC_SDCCH8_5, 2, TRXC_SDCCH8_1, 3 },
+ { TRXC_SDCCH8_5, 3, TRXC_SDCCH8_2, 0 },
+ { TRXC_SDCCH8_6, 0, TRXC_SDCCH8_2, 1 },
+ { TRXC_SDCCH8_6, 1, TRXC_SDCCH8_2, 2 },
+ { TRXC_SDCCH8_6, 2, TRXC_SDCCH8_2, 3 },
+ { TRXC_SDCCH8_6, 3, TRXC_SDCCH8_3, 0 },
+ { TRXC_SDCCH8_7, 0, TRXC_SDCCH8_3, 1 },
+ { TRXC_SDCCH8_7, 1, TRXC_SDCCH8_3, 2 },
+ { TRXC_SDCCH8_7, 2, TRXC_SDCCH8_3, 3 },
+ { TRXC_SDCCH8_7, 3, TRXC_SDCCH8_4, 0 },
+ { TRXC_SACCH8_4, 0, TRXC_SDCCH8_4, 1 },
+ { TRXC_SACCH8_4, 1, TRXC_SDCCH8_4, 2 },
+ { TRXC_SACCH8_4, 2, TRXC_SDCCH8_4, 3 },
+ { TRXC_SACCH8_4, 3, TRXC_SDCCH8_5, 0 },
+ { TRXC_SACCH8_5, 0, TRXC_SDCCH8_5, 1 },
+ { TRXC_SACCH8_5, 1, TRXC_SDCCH8_5, 2 },
+ { TRXC_SACCH8_5, 2, TRXC_SDCCH8_5, 3 },
+ { TRXC_SACCH8_5, 3, TRXC_SDCCH8_6, 0 },
+ { TRXC_SACCH8_6, 0, TRXC_SDCCH8_6, 1 },
+ { TRXC_SACCH8_6, 1, TRXC_SDCCH8_6, 2 },
+ { TRXC_SACCH8_6, 2, TRXC_SDCCH8_6, 3 },
+ { TRXC_SACCH8_6, 3, TRXC_SDCCH8_7, 0 },
+ { TRXC_SACCH8_7, 0, TRXC_SDCCH8_7, 1 },
+ { TRXC_SACCH8_7, 1, TRXC_SDCCH8_7, 2 },
+ { TRXC_SACCH8_7, 2, TRXC_SDCCH8_7, 3 },
+ { TRXC_SACCH8_7, 3, TRXC_SACCH8_4, 0 },
+ { TRXC_IDLE, 0, TRXC_SACCH8_4, 1 },
+ { TRXC_IDLE, 0, TRXC_SACCH8_4, 2 },
+ { TRXC_IDLE, 0, TRXC_SACCH8_4, 3 },
+};
+
+static struct trx_sched_frame frame_tchf_ts0[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+};
+
+static struct trx_sched_frame frame_tchf_ts1[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+};
+
+static struct trx_sched_frame frame_tchf_ts2[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+};
+
+static struct trx_sched_frame frame_tchf_ts3[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+};
+
+static struct trx_sched_frame frame_tchf_ts4[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+};
+
+static struct trx_sched_frame frame_tchf_ts5[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+};
+
+static struct trx_sched_frame frame_tchf_ts6[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+};
+
+static struct trx_sched_frame frame_tchf_ts7[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 1, TRXC_SACCHTF, 1 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 2, TRXC_SACCHTF, 2 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 3, TRXC_SACCHTF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_TCHF, 0, TRXC_TCHF, 0 }, { TRXC_TCHF, 1, TRXC_TCHF, 1 }, { TRXC_TCHF, 2, TRXC_TCHF, 2 }, { TRXC_TCHF, 3, TRXC_TCHF, 3 },
+ { TRXC_SACCHTF, 0, TRXC_SACCHTF, 0 },
+};
+
+static struct trx_sched_frame frame_tchh_ts01[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 0, TRXC_SACCHTH_0, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 0, TRXC_SACCHTH_1, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 1, TRXC_SACCHTH_0, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 1, TRXC_SACCHTH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 2, TRXC_SACCHTH_0, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 2, TRXC_SACCHTH_1, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 3, TRXC_SACCHTH_0, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 3, TRXC_SACCHTH_1, 3 },
+};
+
+static struct trx_sched_frame frame_tchh_ts23[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 3, TRXC_SACCHTH_0, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 3, TRXC_SACCHTH_1, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 0, TRXC_SACCHTH_0, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 0, TRXC_SACCHTH_1, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 1, TRXC_SACCHTH_0, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 1, TRXC_SACCHTH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 2, TRXC_SACCHTH_0, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 2, TRXC_SACCHTH_1, 2 },
+};
+
+static struct trx_sched_frame frame_tchh_ts45[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 2, TRXC_SACCHTH_0, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 2, TRXC_SACCHTH_1, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 3, TRXC_SACCHTH_0, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 3, TRXC_SACCHTH_1, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 0, TRXC_SACCHTH_0, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 0, TRXC_SACCHTH_1, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 1, TRXC_SACCHTH_0, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 1, TRXC_SACCHTH_1, 1 },
+};
+
+static struct trx_sched_frame frame_tchh_ts67[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 1, TRXC_SACCHTH_0, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 1, TRXC_SACCHTH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 2, TRXC_SACCHTH_0, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 2, TRXC_SACCHTH_1, 2 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 3, TRXC_SACCHTH_0, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 3, TRXC_SACCHTH_1, 3 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_0, 0, TRXC_SACCHTH_0, 0 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_TCHH_0, 0, TRXC_TCHH_0, 0 }, { TRXC_TCHH_1, 0, TRXC_TCHH_1, 0 }, { TRXC_TCHH_0, 1, TRXC_TCHH_0, 1 }, { TRXC_TCHH_1, 1, TRXC_TCHH_1, 1 },
+ { TRXC_SACCHTH_1, 0, TRXC_SACCHTH_1, 0 },
+};
+
+static struct trx_sched_frame frame_pdch[104] = {
+/* dl_chan dl_bid ul_chan ul_bid */
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PTCCH, 0, TRXC_PTCCH, 0 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PTCCH, 1, TRXC_PTCCH, 1 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PTCCH, 2, TRXC_PTCCH, 2 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PTCCH, 3, TRXC_PTCCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_PDTCH, 0, TRXC_PDTCH, 0 }, { TRXC_PDTCH, 1, TRXC_PDTCH, 1 }, { TRXC_PDTCH, 2, TRXC_PDTCH, 2 }, { TRXC_PDTCH, 3, TRXC_PDTCH, 3 },
+ { TRXC_IDLE, 0, TRXC_IDLE, 0 },
+};
+
+/* multiframe structure */
+struct trx_sched_multiframe {
+ enum gsm_phys_chan_config pchan;
+ uint8_t slotmask;
+ uint8_t period;
+ struct trx_sched_frame *frames;
+ const char *name;
+};
+
+static struct trx_sched_multiframe trx_sched_multiframes[] = {
+ { GSM_PCHAN_NONE, 0xff, 0, NULL, "NONE"},
+ { GSM_PCHAN_CCCH, 0xff, 51, frame_bcch, "BCCH+CCCH" },
+ { GSM_PCHAN_CCCH_SDCCH4, 0xff, 102, frame_bcch_sdcch4, "BCCH+CCCH+SDCCH/4+SACCH/4" },
+ { GSM_PCHAN_SDCCH8_SACCH8C, 0xff, 102, frame_sdcch8, "SDCCH/8+SACCH/8" },
+ { GSM_PCHAN_TCH_F, 0x01, 104, frame_tchf_ts0, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x02, 104, frame_tchf_ts1, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x04, 104, frame_tchf_ts2, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x08, 104, frame_tchf_ts3, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x10, 104, frame_tchf_ts4, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x20, 104, frame_tchf_ts5, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x40, 104, frame_tchf_ts6, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_F, 0x80, 104, frame_tchf_ts7, "TCH/F+SACCH" },
+ { GSM_PCHAN_TCH_H, 0x03, 104, frame_tchh_ts01, "TCH/H+SACCH" },
+ { GSM_PCHAN_TCH_H, 0x0c, 104, frame_tchh_ts23, "TCH/H+SACCH" },
+ { GSM_PCHAN_TCH_H, 0x30, 104, frame_tchh_ts45, "TCH/H+SACCH" },
+ { GSM_PCHAN_TCH_H, 0xc0, 104, frame_tchh_ts67, "TCH/H+SACCH" },
+ { GSM_PCHAN_PDCH, 0xff, 104, frame_pdch, "PDCH" },
+};
+
+
+/*
+ * scheduler functions
+ */
+
+/* set multiframe scheduler to given pchan */
+int trx_sched_set_pchan(struct trx_l1h *l1h, uint8_t tn,
+ enum gsm_phys_chan_config pchan)
+{
+ int i;
+
+ /* ignore disabled slots */
+ if (!(l1h->config.slotmask & (1 << tn)))
+ return -ENOTSUP;
+
+ for (i = 0; i < ARRAY_SIZE(trx_sched_multiframes); i++) {
+ if (trx_sched_multiframes[i].pchan == pchan
+ && (trx_sched_multiframes[i].slotmask & (1 << tn))) {
+ l1h->mf_index[tn] = i;
+ l1h->mf_period[tn] = trx_sched_multiframes[i].period;
+ l1h->mf_frames[tn] = trx_sched_multiframes[i].frames;
+ LOGP(DL1C, LOGL_NOTICE, "Configuring multiframe with "
+ "%s trx=%d ts=%d\n",
+ trx_sched_multiframes[i].name,
+ l1h->trx->nr, tn);
+ return 0;
+ }
+ }
+
+ LOGP(DL1C, LOGL_NOTICE, "Failed to configuring multiframe "
+ "trx=%d ts=%d\n", l1h->trx->nr, tn);
+
+ return -ENOTSUP;
+}
+
+/* setting all logical channels given attributes to active/inactive */
+int trx_sched_set_lchan(struct trx_l1h *l1h, uint8_t chan_nr, uint8_t link_id,
+ int active)
+{
+ uint8_t tn = L1SAP_CHAN2TS(chan_nr);
+ uint8_t ss = l1sap_chan2ss(chan_nr);
+ int i;
+ int rc = -EINVAL;
+ struct trx_chan_state *chan_state;
+
+ /* look for all matching chan_nr/link_id */
+ for (i = 0; i < _TRX_CHAN_MAX; i++) {
+ /* skip if pchan type does not match pdch flag */
+ if ((trx_sched_multiframes[l1h->mf_index[tn]].pchan
+ == GSM_PCHAN_PDCH)
+ != trx_chan_desc[i].pdch)
+ continue;
+ if (trx_chan_desc[i].chan_nr == (chan_nr & 0xf8)
+ && trx_chan_desc[i].link_id == link_id) {
+ chan_state = &l1h->chan_states[tn][i];
+ rc = 0;
+ if (chan_state->active == active)
+ continue;
+ LOGP(DL1C, LOGL_NOTICE, "%s %s on trx=%d ts=%d\n",
+ (active) ? "Activating" : "Deactivating",
+ trx_chan_desc[i].name, l1h->trx->nr, tn);
+ if (active)
+ memset(chan_state, 0, sizeof(*chan_state));
+ chan_state->active = active;
+ /* free burst memory, to cleanly start with burst 0 */
+ if (chan_state->dl_bursts) {
+ talloc_free(chan_state->dl_bursts);
+ chan_state->dl_bursts = NULL;
+ }
+ if (chan_state->ul_bursts) {
+ talloc_free(chan_state->ul_bursts);
+ chan_state->ul_bursts = NULL;
+ }
+ }
+ }
+
+ /* disable handover detection (on deactivation) */
+ if (l1h->ho_rach_detect[tn][ss]) {
+ l1h->ho_rach_detect[tn][ss] = 0;
+ trx_if_cmd_nohandover(l1h, tn, ss);
+ }
+
+ return rc;
+}
+
+/* setting all logical channels given attributes to active/inactive */
+int trx_sched_set_mode(struct trx_l1h *l1h, uint8_t chan_nr, uint8_t rsl_cmode,
+ uint8_t tch_mode, int codecs, uint8_t codec0, uint8_t codec1,
+ uint8_t codec2, uint8_t codec3, uint8_t initial_id, uint8_t handover)
+{
+ uint8_t tn = L1SAP_CHAN2TS(chan_nr);
+ uint8_t ss = l1sap_chan2ss(chan_nr);
+ int i;
+ int rc = -EINVAL;
+ struct trx_chan_state *chan_state;
+
+ /* no mode for PDCH */
+ if (trx_sched_multiframes[l1h->mf_index[tn]].pchan == GSM_PCHAN_PDCH)
+ return 0;
+
+ /* look for all matching chan_nr/link_id */
+ for (i = 0; i < _TRX_CHAN_MAX; i++) {
+ if (trx_chan_desc[i].chan_nr == (chan_nr & 0xf8)
+ && trx_chan_desc[i].link_id == 0x00) {
+ chan_state = &l1h->chan_states[tn][i];
+ LOGP(DL1C, LOGL_NOTICE, "Set mode %u, %u, handover %u "
+ "on %s of trx=%d ts=%d\n", rsl_cmode, tch_mode,
+ handover, trx_chan_desc[i].name, l1h->trx->nr,
+ tn);
+ chan_state->rsl_cmode = rsl_cmode;
+ chan_state->tch_mode = tch_mode;
+ chan_state->ho_rach_detect = handover;
+ if (rsl_cmode == RSL_CMOD_SPD_SPEECH
+ && tch_mode == GSM48_CMODE_SPEECH_AMR) {
+ chan_state->codecs = codecs;
+ chan_state->codec[0] = codec0;
+ chan_state->codec[1] = codec1;
+ chan_state->codec[2] = codec2;
+ chan_state->codec[3] = codec3;
+ chan_state->ul_ft = initial_id;
+ chan_state->dl_ft = initial_id;
+ chan_state->ul_cmr = initial_id;
+ chan_state->dl_cmr = initial_id;
+ chan_state->ber_sum = 0;
+ chan_state->ber_num = 0;
+ }
+ rc = 0;
+ }
+ }
+
+ /* command rach detection
+ * always enable handover, even if state is still set (due to loss
+ * of transceiver link).
+ * disable handover, if state is still set, since we might not know
+ * the actual state of transceiver (due to loss of link) */
+ if (handover) {
+ l1h->ho_rach_detect[tn][ss] = 1;
+ trx_if_cmd_handover(l1h, tn, ss);
+ } else if (l1h->ho_rach_detect[tn][ss]) {
+ l1h->ho_rach_detect[tn][ss] = 0;
+ trx_if_cmd_nohandover(l1h, tn, ss);
+ }
+
+ return rc;
+}
+
+/* setting cipher on logical channels */
+int trx_sched_set_cipher(struct trx_l1h *l1h, uint8_t chan_nr, int downlink,
+ int algo, uint8_t *key, int key_len)
+{
+ uint8_t tn = L1SAP_CHAN2TS(chan_nr);
+ int i;
+ int rc = -EINVAL;
+ struct trx_chan_state *chan_state;
+
+ /* no cipher for PDCH */
+ if (trx_sched_multiframes[l1h->mf_index[tn]].pchan == GSM_PCHAN_PDCH)
+ return 0;
+
+ /* no algorithm given means a5/0 */
+ if (algo <= 0)
+ algo = 0;
+ else if (key_len != 8) {
+ LOGP(DL1C, LOGL_ERROR, "Algo A5/%d not supported with given "
+ "key len=%d\n", algo, key_len);
+ return -ENOTSUP;
+ }
+
+ /* look for all matching chan_nr */
+ for (i = 0; i < _TRX_CHAN_MAX; i++) {
+ /* skip if pchan type */
+ if (trx_chan_desc[i].pdch)
+ continue;
+ if (trx_chan_desc[i].chan_nr == (chan_nr & 0xf8)) {
+ chan_state = &l1h->chan_states[tn][i];
+ LOGP(DL1C, LOGL_NOTICE, "Set a5/%d %s for %s on trx=%d "
+ "ts=%d\n", algo,
+ (downlink) ? "downlink" : "uplink",
+ trx_chan_desc[i].name, l1h->trx->nr, tn);
+ if (downlink) {
+ chan_state->dl_encr_algo = algo;
+ memcpy(chan_state->dl_encr_key, key, key_len);
+ chan_state->dl_encr_key_len = key_len;
+ } else {
+ chan_state->ul_encr_algo = algo;
+ memcpy(chan_state->ul_encr_key, key, key_len);
+ chan_state->ul_encr_key_len = key_len;
+ }
+ rc = 0;
+ }
+ }
+
+ return rc;
+}
+
+/* process ready-to-send */
+static int trx_sched_rts(struct trx_l1h *l1h, uint8_t tn, uint32_t fn)
+{
+ struct trx_sched_frame *frame;
+ uint8_t offset, period, bid;
+ trx_sched_rts_func *func;
+ enum trx_chan_type chan;
+
+ /* no multiframe set */
+ if (!l1h->mf_index[tn])
+ return 0;
+
+ /* get frame from multiframe */
+ period = l1h->mf_period[tn];
+ offset = fn % period;
+ frame = l1h->mf_frames[tn] + offset;
+
+ chan = frame->dl_chan;
+ bid = frame->dl_bid;
+ func = trx_chan_desc[frame->dl_chan].rts_fn;
+
+ /* only on bid == 0 */
+ if (bid != 0)
+ return 0;
+
+ /* no RTS function */
+ if (!func)
+ return 0;
+
+ /* check if channel is active */
+ if (!trx_chan_desc[chan].auto_active
+ && !l1h->chan_states[tn][chan].active)
+ return -EINVAL;
+
+ return func(l1h, tn, fn, frame->dl_chan);
+}
+
+/* process downlink burst */
+static const ubit_t *trx_sched_dl_burst(struct trx_l1h *l1h, uint8_t tn,
+ uint32_t fn)
+{
+ struct trx_sched_frame *frame;
+ uint8_t offset, period, bid;
+ trx_sched_dl_func *func;
+ enum trx_chan_type chan;
+ ubit_t *bits = NULL;
+
+ if (!l1h->mf_index[tn])
+ goto no_data;
+
+ /* get frame from multiframe */
+ period = l1h->mf_period[tn];
+ offset = fn % period;
+ frame = l1h->mf_frames[tn] + offset;
+
+ chan = frame->dl_chan;
+ bid = frame->dl_bid;
+ func = trx_chan_desc[chan].dl_fn;
+
+ /* check if channel is active */
+ if (!trx_chan_desc[chan].auto_active
+ && !l1h->chan_states[tn][chan].active)
+ goto no_data;
+
+ /* get burst from function */
+ bits = func(l1h, tn, fn, chan, bid);
+
+ /* encrypt */
+ if (bits && l1h->chan_states[tn][chan].dl_encr_algo) {
+ ubit_t ks[114];
+ int i;
+
+ osmo_a5(l1h->chan_states[tn][chan].dl_encr_algo,
+ l1h->chan_states[tn][chan].dl_encr_key, fn, ks, NULL);
+ for (i = 0; i < 57; i++) {
+ bits[i + 3] ^= ks[i];
+ bits[i + 88] ^= ks[i + 57];
+ }
+ }
+
+no_data:
+ /* in case of C0, we need a dummy burst to maintain RF power */
+ if (bits == NULL && l1h->trx == l1h->trx->bts->c0) {
+if (0) if (chan != TRXC_IDLE) // hack
+ LOGP(DL1C, LOGL_DEBUG, "No burst data for %s fn=%u ts=%u "
+ "burst=%d on C0, so filling with dummy burst\n",
+ trx_chan_desc[chan].name, fn, tn, bid);
+ bits = dummy_burst;
+ }
+
+ return bits;
+}
+
+/* process uplink burst */
+int trx_sched_ul_burst(struct trx_l1h *l1h, uint8_t tn, uint32_t current_fn,
+ sbit_t *bits, int8_t rssi, float toa)
+{
+ struct trx_sched_frame *frame;
+ uint8_t offset, period, bid;
+ trx_sched_ul_func *func;
+ enum trx_chan_type chan;
+ uint32_t fn, elapsed;
+
+ if (!l1h->mf_index[tn])
+ return -EINVAL;
+
+ /* calculate how many frames have been elapsed */
+ elapsed = (current_fn + 2715648 - l1h->mf_last_fn[tn]) % 2715648;
+
+ /* start counting from last fn + 1, but only if not too many fn have
+ * been elapsed */
+ if (elapsed < 10)
+ fn = (l1h->mf_last_fn[tn] + 1) % 2715648;
+ else
+ fn = current_fn;
+
+ while (42) {
+ /* get frame from multiframe */
+ period = l1h->mf_period[tn];
+ offset = fn % period;
+ frame = l1h->mf_frames[tn] + offset;
+
+ chan = frame->ul_chan;
+ bid = frame->ul_bid;
+ func = trx_chan_desc[chan].ul_fn;
+
+ /* check if channel is active */
+ if (!trx_chan_desc[chan].auto_active
+ && !l1h->chan_states[tn][chan].active)
+ goto next_frame;
+
+ /* omit bursts which have no handler, like IDLE bursts */
+ if (!func)
+ goto next_frame;
+
+ /* put burst to function */
+ if (fn == current_fn) {
+ /* decrypt */
+ if (bits && l1h->chan_states[tn][chan].ul_encr_algo) {
+ ubit_t ks[114];
+ int i;
+
+ osmo_a5(l1h->chan_states[tn][chan].ul_encr_algo,
+ l1h->chan_states[tn][chan].ul_encr_key,
+ fn, NULL, ks);
+ for (i = 0; i < 57; i++) {
+ if (ks[i])
+ bits[i + 3] = - bits[i + 3];
+ if (ks[i + 57])
+ bits[i + 88] = - bits[i + 88];
+ }
+ }
+
+ func(l1h, tn, fn, chan, bid, bits, rssi, toa);
+ } else if (chan != TRXC_RACH
+ && !l1h->chan_states[tn][chan].ho_rach_detect) {
+ sbit_t spare[148];
+
+ memset(spare, 0, 148);
+ func(l1h, tn, fn, chan, bid, spare, -128, 0);
+ }
+
+next_frame:
+ /* reached current fn */
+ if (fn == current_fn)
+ break;
+
+ fn = (fn + 1) % 2715648;
+ }
+
+ l1h->mf_last_fn[tn] = fn;
+
+ return 0;
+}
+
+/* schedule all frames of all TRX for given FN */
+static int trx_sched_fn(uint32_t fn)
+{
+ struct gsm_bts_trx *trx;
+ struct trx_l1h *l1h;
+ uint8_t tn;
+ const ubit_t *bits;
+ uint8_t gain;
+
+ /* send time indication */
+ l1if_mph_time_ind(bts, fn);
+
+ /* advance frame number, so the transceiver has more time until
+ * it must be transmitted. */
+ fn = (fn + trx_clock_advance) % 2715648;
+
+ /* process every TRX */
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = trx_l1h_hdl(trx);
+
+ /* we don't schedule, if power is off */
+ if (!l1h->config.poweron)
+ continue;
+
+ /* process every TS of TRX */
+ for (tn = 0; tn < 8; tn++) {
+ /* ignore disabled slots */
+ if (!(l1h->config.slotmask & (1 << tn)))
+ continue;
+ /* ready-to-send */
+ trx_sched_rts(l1h, tn,
+ (fn + trx_rts_advance) % 2715648);
+ /* get burst for FN */
+ bits = trx_sched_dl_burst(l1h, tn, fn);
+ if (!bits) {
+#if 0
+ /* if no bits, send dummy burst with no gain */
+ bits = dummy_burst;
+ gain = 128;
+#else
+ /* if no bits, send no burst */
+ continue;
+#endif
+ } else
+ gain = 0;
+ trx_if_data(l1h, tn, fn, gain, bits);
+ }
+ }
+
+ return 0;
+}
+
+
+/*
+ * frame clock
+ */
+
+#define FRAME_DURATION_uS 4615
+#define MAX_FN_SKEW 50
+#define TRX_LOSS_FRAMES 400
+
+extern int quit;
+/* this timer fires for every FN to be processed */
+static void trx_ctrl_timer_cb(void *data)
+{
+ struct timeval tv_now, *tv_clock = &transceiver_clock_tv;
+ int32_t elapsed;
+
+ /* check if transceiver is still alive */
+ if (transceiver_lost++ == TRX_LOSS_FRAMES) {
+ struct gsm_bts_trx *trx;
+
+ LOGP(DL1C, LOGL_NOTICE, "No more clock from transceiver\n");
+
+no_clock:
+ transceiver_available = 0;
+
+ /* flush pending messages of transceiver */
+ /* close all logical channels and reset timeslots */
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ trx_if_flush(trx_l1h_hdl(trx));
+ trx_sched_reset(trx_l1h_hdl(trx));
+ if (trx->nr == 0)
+ trx_if_cmd_poweroff(trx_l1h_hdl(trx));
+ }
+
+ /* tell BSC */
+ check_transceiver_availability(bts, 0);
+
+ return;
+ }
+
+ gettimeofday(&tv_now, NULL);
+
+ elapsed = (tv_now.tv_sec - tv_clock->tv_sec) * 1000000
+ + (tv_now.tv_usec - tv_clock->tv_usec);
+
+ /* if someone played with clock, or if the process stalled */
+ if (elapsed > FRAME_DURATION_uS * MAX_FN_SKEW || elapsed < 0) {
+ LOGP(DL1C, LOGL_NOTICE, "PC clock skew: elapsed uS %d\n",
+ elapsed);
+ goto no_clock;
+ }
+
+ /* schedule next FN clock */
+ while (elapsed > FRAME_DURATION_uS / 2) {
+ tv_clock->tv_usec += FRAME_DURATION_uS;
+ if (tv_clock->tv_usec >= 1000000) {
+ tv_clock->tv_sec++;
+ tv_clock->tv_usec -= 1000000;
+ }
+ transceiver_last_fn = (transceiver_last_fn + 1) % 2715648;
+ trx_sched_fn(transceiver_last_fn);
+ elapsed -= FRAME_DURATION_uS;
+ }
+ osmo_timer_schedule(&transceiver_clock_timer, 0,
+ FRAME_DURATION_uS - elapsed);
+}
+
+
+/* receive clock from transceiver */
+int trx_sched_clock(uint32_t fn)
+{
+ struct timeval tv_now, *tv_clock = &transceiver_clock_tv;
+ int32_t elapsed;
+ int32_t elapsed_fn;
+
+ if (quit)
+ return 0;
+
+ /* reset lost counter */
+ transceiver_lost = 0;
+
+ gettimeofday(&tv_now, NULL);
+
+ /* clock becomes valid */
+ if (!transceiver_available) {
+ LOGP(DL1C, LOGL_NOTICE, "initial GSM clock received: fn=%u\n",
+ fn);
+
+ transceiver_available = 1;
+
+ /* start provisioning transceiver */
+ l1if_provision_transceiver(bts);
+
+ /* tell BSC */
+ check_transceiver_availability(bts, 1);
+
+new_clock:
+ transceiver_last_fn = fn;
+ trx_sched_fn(transceiver_last_fn);
+
+ /* schedule first FN clock */
+ memcpy(tv_clock, &tv_now, sizeof(struct timeval));
+ memset(&transceiver_clock_timer, 0,
+ sizeof(transceiver_clock_timer));
+ transceiver_clock_timer.cb = trx_ctrl_timer_cb;
+ transceiver_clock_timer.data = bts;
+ osmo_timer_schedule(&transceiver_clock_timer, 0,
+ FRAME_DURATION_uS);
+
+ return 0;
+ }
+
+ osmo_timer_del(&transceiver_clock_timer);
+
+ /* calculate elapsed time since last_fn */
+ elapsed = (tv_now.tv_sec - tv_clock->tv_sec) * 1000000
+ + (tv_now.tv_usec - tv_clock->tv_usec);
+
+ /* how much frames have been elapsed since last fn processed */
+ elapsed_fn = (fn + 2715648 - transceiver_last_fn) % 2715648;
+ if (elapsed_fn >= 135774)
+ elapsed_fn -= 2715648;
+
+ /* check for max clock skew */
+ if (elapsed_fn > MAX_FN_SKEW || elapsed_fn < -MAX_FN_SKEW) {
+ LOGP(DL1C, LOGL_NOTICE, "GSM clock skew: old fn=%u, "
+ "new fn=%u\n", transceiver_last_fn, fn);
+ goto new_clock;
+ }
+
+ LOGP(DL1C, LOGL_INFO, "GSM clock jitter: %d\n",
+ elapsed_fn * FRAME_DURATION_uS - elapsed);
+
+ /* too many frames have been processed already */
+ if (elapsed_fn < 0) {
+ /* set clock to the time or last FN should have been
+ * transmitted. */
+ tv_clock->tv_sec = tv_now.tv_sec;
+ tv_clock->tv_usec = tv_now.tv_usec +
+ (0 - elapsed_fn) * FRAME_DURATION_uS;
+ if (tv_clock->tv_usec >= 1000000) {
+ tv_clock->tv_sec++;
+ tv_clock->tv_usec -= 1000000;
+ }
+ /* set time to the time our next FN has to be transmitted */
+ osmo_timer_schedule(&transceiver_clock_timer, 0,
+ FRAME_DURATION_uS * (1 - elapsed_fn));
+
+ return 0;
+ }
+
+ /* transmit what we still need to transmit */
+ while (fn != transceiver_last_fn) {
+ transceiver_last_fn = (transceiver_last_fn + 1) % 2715648;
+ trx_sched_fn(transceiver_last_fn);
+ }
+
+ /* schedule next FN to be transmitted */
+ memcpy(tv_clock, &tv_now, sizeof(struct timeval));
+ osmo_timer_schedule(&transceiver_clock_timer, 0, FRAME_DURATION_uS);
+
+ return 0;
+}
+
diff --git a/src/osmo-bts-trx/scheduler.h b/src/osmo-bts-trx/scheduler.h
new file mode 100644
index 0000000..ce7ddad
--- /dev/null
+++ b/src/osmo-bts-trx/scheduler.h
@@ -0,0 +1,43 @@
+#ifndef TRX_SCHEDULER_H
+#define TRX_SCHEDULER_H
+
+extern uint32_t trx_clock_advance;
+extern uint32_t trx_rts_advance;
+extern uint32_t transceiver_last_fn;
+
+
+int trx_sched_init(struct trx_l1h *l1h);
+
+void trx_sched_exit(struct trx_l1h *l1h);
+
+int trx_sched_ph_data_req(struct trx_l1h *l1h, struct osmo_phsap_prim *l1sap);
+
+int trx_sched_tch_req(struct trx_l1h *l1h, struct osmo_phsap_prim *l1sap);
+
+int trx_sched_clock(uint32_t fn);
+
+int trx_sched_ul_burst(struct trx_l1h *l1h, uint8_t tn, uint32_t fn,
+ sbit_t *bits, int8_t rssi, float toa);
+
+/* set multiframe scheduler to given pchan */
+int trx_sched_set_pchan(struct trx_l1h *l1h, uint8_t tn,
+ enum gsm_phys_chan_config pchan);
+
+/* setting all logical channels given attributes to active/inactive */
+int trx_sched_set_lchan(struct trx_l1h *l1h, uint8_t chan_nr, uint8_t link_id,
+ int active);
+
+/* setting all logical channels given attributes to active/inactive */
+int trx_sched_set_mode(struct trx_l1h *l1h, uint8_t chan_nr, uint8_t rsl_cmode,
+ uint8_t tch_mode, int codecs, uint8_t codec0, uint8_t codec1,
+ uint8_t codec2, uint8_t codec3, uint8_t initial_codec,
+ uint8_t handover);
+
+/* setting cipher on logical channels */
+int trx_sched_set_cipher(struct trx_l1h *l1h, uint8_t chan_nr, int downlink,
+ int algo, uint8_t *key, int key_len);
+
+/* close all logical channels and reset timeslots */
+void trx_sched_reset(struct trx_l1h *l1h);
+
+#endif /* TRX_SCHEDULER_H */
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
new file mode 100644
index 0000000..69ad841
--- /dev/null
+++ b/src/osmo-bts-trx/trx_if.c
@@ -0,0 +1,560 @@
+/*
+ * OpenBTS TRX interface handling
+ *
+ * Copyright (C) 2013 Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <netinet/in.h>
+
+#include <osmocom/core/select.h>
+#include <osmocom/core/socket.h>
+#include <osmocom/core/timer.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/bits.h>
+
+#include <osmo-bts/logging.h>
+#include <osmo-bts/bts.h>
+
+#include "l1_if.h"
+#include "trx_if.h"
+#include "scheduler.h"
+
+/* enable to print RSSI level graph */
+//#define TOA_RSSI_DEBUG
+
+int transceiver_available = 0;
+const char *transceiver_ip = "127.0.0.1";
+int settsc_enabled = 0;
+int setbsic_enabled = 0;
+
+/*
+ * socket
+ */
+
+static uint16_t base_port_local = 5800;
+
+/* open socket */
+static int trx_udp_open(void *priv, struct osmo_fd *ofd, uint16_t port,
+ int (*cb)(struct osmo_fd *fd, unsigned int what))
+{
+ struct sockaddr_storage sas;
+ struct sockaddr *sa = (struct sockaddr *)&sas;
+ socklen_t sa_len;
+
+ int rc;
+
+ /* Init */
+ ofd->fd = -1;
+ ofd->cb = cb;
+ ofd->data = priv;
+
+ /* Listen / Binds */
+ rc = osmo_sock_init_ofd(ofd, AF_UNSPEC, SOCK_DGRAM, 0, transceiver_ip,
+ port, OSMO_SOCK_F_BIND);
+ if (rc < 0)
+ return rc;
+
+ /* Connect */
+ sa_len = sizeof(sas);
+ rc = getsockname(ofd->fd, sa, &sa_len);
+ if (rc)
+ return rc;
+
+ if (sa->sa_family == AF_INET) {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ sin->sin_port = htons(ntohs(sin->sin_port) - 100);
+ } else if (sa->sa_family == AF_INET6) {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+ sin6->sin6_port = htons(ntohs(sin6->sin6_port) - 100);
+ } else {
+ return -EINVAL;
+ }
+
+ rc = connect(ofd->fd, sa, sa_len);
+ if (rc)
+ return rc;
+
+
+ return 0;
+}
+
+/* close socket */
+static void trx_udp_close(struct osmo_fd *ofd)
+{
+ if (ofd->fd > 0) {
+ osmo_fd_unregister(ofd);
+ close(ofd->fd);
+ ofd->fd = -1;
+ }
+}
+
+
+/*
+ * clock
+ */
+
+static struct osmo_fd trx_ofd_clk;
+
+
+/* get clock from clock socket */
+static int trx_clk_read_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ char buf[1500];
+ int len;
+ uint32_t fn;
+
+ len = recv(ofd->fd, buf, sizeof(buf) - 1, 0);
+ if (len <= 0)
+ return len;
+ buf[len] = '\0';
+
+ if (!!strncmp(buf, "IND CLOCK ", 10)) {
+ LOGP(DTRX, LOGL_NOTICE, "Unknown message on clock port: %s\n",
+ buf);
+ return 0;
+ }
+
+ sscanf(buf, "IND CLOCK %u", &fn);
+ LOGP(DTRX, LOGL_INFO, "Clock indication: fn=%u\n", fn);
+
+ if (fn >= 2715648) {
+ fn %= 2715648;
+ LOGP(DTRX, LOGL_ERROR, "Indicated clock's FN is not wrapping "
+ "correctly, correcting to fn=%u\n", fn);
+ }
+
+ trx_sched_clock(fn);
+
+ return 0;
+}
+
+
+/*
+ * ctrl
+ */
+
+static void trx_ctrl_timer_cb(void *data);
+
+/* send first ctrl message and start timer */
+static void trx_ctrl_send(struct trx_l1h *l1h)
+{
+ struct trx_ctrl_msg *tcm;
+
+ /* get first command */
+ if (llist_empty(&l1h->trx_ctrl_list))
+ return;
+ tcm = llist_entry(l1h->trx_ctrl_list.next, struct trx_ctrl_msg, list);
+
+ LOGP(DTRX, LOGL_DEBUG, "Sending control '%s' to trx=%u\n", tcm->cmd,
+ l1h->trx->nr);
+ /* send command */
+ send(l1h->trx_ofd_ctrl.fd, tcm->cmd, strlen(tcm->cmd)+1, 0);
+
+ /* start timer */
+ l1h->trx_ctrl_timer.cb = trx_ctrl_timer_cb;
+ l1h->trx_ctrl_timer.data = l1h;
+ osmo_timer_schedule(&l1h->trx_ctrl_timer, 2, 0);
+}
+
+/* send first ctrl message and start timer */
+static void trx_ctrl_timer_cb(void *data)
+{
+ struct trx_l1h *l1h = data;
+
+ LOGP(DTRX, LOGL_NOTICE, "No response from transceiver for trx=%d\n",
+ l1h->trx->nr);
+
+ trx_ctrl_send(l1h);
+}
+
+/* add a new ctrl command */
+static int trx_ctrl_cmd(struct trx_l1h *l1h, int critical, const char *cmd,
+ const char *fmt, ...)
+{
+ struct trx_ctrl_msg *tcm;
+ va_list ap;
+ int l, pending = 0;
+
+ if (!transceiver_available && !!strcmp(cmd, "POWEROFF")) {
+ LOGP(DTRX, LOGL_ERROR, "CTRL ignored: No clock from "
+ "transceiver, please fix!\n");
+ return -EIO;
+ }
+
+ if (!llist_empty(&l1h->trx_ctrl_list))
+ pending = 1;
+
+ /* create message */
+ tcm = talloc_zero(tall_bts_ctx, struct trx_ctrl_msg);
+ if (!tcm)
+ return -ENOMEM;
+ if (fmt && fmt[0]) {
+ l = snprintf(tcm->cmd, sizeof(tcm->cmd)-1, "CMD %s ", cmd);
+ va_start(ap, fmt);
+ vsnprintf(tcm->cmd + l, sizeof(tcm->cmd) - l - 1, fmt, ap);
+ va_end(ap);
+ } else
+ snprintf(tcm->cmd, sizeof(tcm->cmd)-1, "CMD %s", cmd);
+ tcm->cmd_len = strlen(cmd);
+ tcm->critical = critical;
+ llist_add_tail(&tcm->list, &l1h->trx_ctrl_list);
+ LOGP(DTRX, LOGL_INFO, "Adding new control '%s'\n", tcm->cmd);
+
+ /* send message, if no pending message */
+ if (!pending)
+ trx_ctrl_send(l1h);
+
+ return 0;
+}
+
+int trx_if_cmd_poweroff(struct trx_l1h *l1h)
+{
+ if (l1h->trx->nr == 0)
+ return trx_ctrl_cmd(l1h, 1, "POWEROFF", "");
+ else
+ return 0;
+}
+
+int trx_if_cmd_poweron(struct trx_l1h *l1h)
+{
+ if (l1h->trx->nr == 0)
+ return trx_ctrl_cmd(l1h, 1, "POWERON", "");
+ else
+ return 0;
+}
+
+int trx_if_cmd_settsc(struct trx_l1h *l1h, uint8_t tsc)
+{
+ if (!settsc_enabled)
+ return 0;
+ /* if TSC is enabled only, the positive response is mandatory */
+ return trx_ctrl_cmd(l1h, (setbsic_enabled) ? 0 : 1, "SETTSC", "%d",
+ tsc);
+}
+
+int trx_if_cmd_setbsic(struct trx_l1h *l1h, uint8_t bsic)
+{
+ if (!setbsic_enabled)
+ return 0;
+ /* if BSIC is enabled only, the positive response is mandatory */
+ return trx_ctrl_cmd(l1h, (settsc_enabled) ? 0 : 1, "SETBSIC", "%d",
+ bsic);
+}
+
+int trx_if_cmd_setrxgain(struct trx_l1h *l1h, int db)
+{
+ return trx_ctrl_cmd(l1h, 0, "SETRXGAIN", "%d", db);
+}
+
+int trx_if_cmd_setpower(struct trx_l1h *l1h, int db)
+{
+ return trx_ctrl_cmd(l1h, 0, "SETPOWER", "%d", db);
+}
+
+int trx_if_cmd_setmaxdly(struct trx_l1h *l1h, int dly)
+{
+ return trx_ctrl_cmd(l1h, 0, "SETMAXDLY", "%d", dly);
+}
+
+int trx_if_cmd_setslot(struct trx_l1h *l1h, uint8_t tn, uint8_t type)
+{
+ return trx_ctrl_cmd(l1h, 1, "SETSLOT", "%d %d", tn, type);
+}
+
+int trx_if_cmd_rxtune(struct trx_l1h *l1h, uint16_t arfcn)
+{
+ uint16_t freq10;
+
+ freq10 = gsm_arfcn2freq10(arfcn, 1); /* RX = uplink */
+ if (freq10 == 0xffff) {
+ LOGP(DTRX, LOGL_ERROR, "Arfcn %d not defined.\n", arfcn);
+ return -ENOTSUP;
+ }
+
+ return trx_ctrl_cmd(l1h, 1, "RXTUNE", "%d", freq10 * 100);
+}
+
+int trx_if_cmd_txtune(struct trx_l1h *l1h, uint16_t arfcn)
+{
+ uint16_t freq10;
+
+ freq10 = gsm_arfcn2freq10(arfcn, 0); /* TX = downlink */
+ if (freq10 == 0xffff) {
+ LOGP(DTRX, LOGL_ERROR, "Arfcn %d not defined.\n", arfcn);
+ return -ENOTSUP;
+ }
+
+ return trx_ctrl_cmd(l1h, 1, "TXTUNE", "%d", freq10 * 100);
+}
+
+int trx_if_cmd_handover(struct trx_l1h *l1h, uint8_t tn, uint8_t ss)
+{
+ return trx_ctrl_cmd(l1h, 1, "HANDOVER", "%d %d", tn, ss);
+}
+
+int trx_if_cmd_nohandover(struct trx_l1h *l1h, uint8_t tn, uint8_t ss)
+{
+ return trx_ctrl_cmd(l1h, 1, "NOHANDOVER", "%d %d", tn, ss);
+}
+
+/* get response from ctrl socket */
+static int trx_ctrl_read_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ struct trx_l1h *l1h = ofd->data;
+ char buf[1500];
+ int len, resp;
+
+ len = recv(ofd->fd, buf, sizeof(buf) - 1, 0);
+ if (len <= 0)
+ return len;
+ buf[len] = '\0';
+
+ if (!strncmp(buf, "RSP ", 4)) {
+ struct trx_ctrl_msg *tcm;
+ char *p;
+ int rsp_len = 0;
+
+ /* calculate the length of response item */
+ p = strchr(buf + 4, ' ');
+ if (p)
+ rsp_len = p - buf - 4;
+ else
+ rsp_len = strlen(buf) - 4;
+
+ LOGP(DTRX, LOGL_INFO, "Response message: '%s'\n", buf);
+
+ /* abort timer and send next message, if any */
+ if (osmo_timer_pending(&l1h->trx_ctrl_timer))
+ osmo_timer_del(&l1h->trx_ctrl_timer);
+
+ /* get command for response message */
+ if (llist_empty(&l1h->trx_ctrl_list)) {
+ LOGP(DTRX, LOGL_NOTICE, "Response message without "
+ "command\n");
+ return -EINVAL;
+ }
+ tcm = llist_entry(l1h->trx_ctrl_list.next, struct trx_ctrl_msg,
+ list);
+
+ /* check if respose matches command */
+ if (rsp_len != tcm->cmd_len) {
+ notmatch:
+ LOGP(DTRX, (tcm->critical) ? LOGL_FATAL : LOGL_NOTICE,
+ "Response message '%s' does not match command "
+ "message '%s'\n", buf, tcm->cmd);
+ goto rsp_error;
+ }
+ if (!!strncmp(buf + 4, tcm->cmd + 4, rsp_len))
+ goto notmatch;
+
+ /* check for response code */
+ sscanf(p + 1, "%d", &resp);
+ if (resp) {
+ LOGP(DTRX, (tcm->critical) ? LOGL_FATAL : LOGL_NOTICE,
+ "transceiver (trx=%d) rejected TRX command "
+ "with response: '%s'\n", l1h->trx->nr, buf);
+rsp_error:
+ if (tcm->critical) {
+ bts_shutdown(l1h->trx->bts, "SIGINT");
+ /* keep tcm list, so process is stopped */
+ return -EIO;
+ }
+ }
+
+ /* remove command from list */
+ llist_del(&tcm->list);
+ talloc_free(tcm);
+
+ trx_ctrl_send(l1h);
+ } else
+ LOGP(DTRX, LOGL_NOTICE, "Unknown message on ctrl port: %s\n",
+ buf);
+
+ return 0;
+}
+
+
+/*
+ * data
+ */
+
+static int trx_data_read_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ struct trx_l1h *l1h = ofd->data;
+ uint8_t buf[256];
+ int len;
+ uint8_t tn;
+ int8_t rssi;
+ float toa = 0.0;
+ uint32_t fn;
+ sbit_t bits[148];
+ int i;
+
+ len = recv(ofd->fd, buf, sizeof(buf), 0);
+ if (len <= 0)
+ return len;
+ if (len != 158) {
+ LOGP(DTRX, LOGL_NOTICE, "Got data message with invalid lenght "
+ "'%d'\n", len);
+ return -EINVAL;
+ }
+ tn = buf[0];
+ fn = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | buf[4];
+ rssi = -(int8_t)buf[5];
+ toa = ((int16_t)(buf[6] << 8) | buf[7]) / 256.0F;
+
+ /* copy and convert bits {254..0} to sbits {-127..127} */
+ for (i = 0; i < 148; i++) {
+ if (buf[8 + i] == 255)
+ bits[i] = -127;
+ else
+ bits[i] = 127 - buf[8 + i];
+ }
+
+ if (tn >= 8) {
+ LOGP(DTRX, LOGL_ERROR, "Illegal TS %d\n", tn);
+ return -EINVAL;
+ }
+ if (fn >= 2715648) {
+ LOGP(DTRX, LOGL_ERROR, "Illegal FN %u\n", fn);
+ return -EINVAL;
+ }
+
+ LOGP(DTRX, LOGL_DEBUG, "RX burst tn=%u fn=%u rssi=%d toa=%.2f\n",
+ tn, fn, rssi, toa);
+
+#ifdef TOA_RSSI_DEBUG
+ char deb[128];
+
+ sprintf(deb, "| 0 "
+ " | rssi=%4d toa=%4.2f fn=%u", rssi, toa, fn);
+ deb[1 + (128 + rssi) / 4] = '*';
+ fprintf(stderr, "%s\n", deb);
+#endif
+
+ trx_sched_ul_burst(l1h, tn, fn, bits, rssi, toa);
+
+ return 0;
+}
+
+int trx_if_data(struct trx_l1h *l1h, uint8_t tn, uint32_t fn, uint8_t pwr,
+ const ubit_t *bits)
+{
+ uint8_t buf[256];
+
+ LOGP(DTRX, LOGL_DEBUG, "TX burst tn=%u fn=%u pwr=%u\n", tn, fn, pwr);
+
+ buf[0] = tn;
+ buf[1] = (fn >> 24) & 0xff;
+ buf[2] = (fn >> 16) & 0xff;
+ buf[3] = (fn >> 8) & 0xff;
+ buf[4] = (fn >> 0) & 0xff;
+ buf[5] = pwr;
+
+ /* copy ubits {0,1} */
+ memcpy(buf + 6, bits, 148);
+
+ /* we must be sure that we have clock, and we have sent all control
+ * data */
+ if (transceiver_available && llist_empty(&l1h->trx_ctrl_list)) {
+ send(l1h->trx_ofd_data.fd, buf, 154, 0);
+ } else
+ LOGP(DTRX, LOGL_DEBUG, "Ignoring TX data, transceiver "
+ "offline.\n");
+
+ return 0;
+}
+
+
+/*
+ * open/close
+ */
+
+int trx_if_open(struct trx_l1h *l1h)
+{
+ int rc;
+
+ LOGP(DTRX, LOGL_NOTICE, "Open transceiver for trx=%u\n", l1h->trx->nr);
+
+ /* initialize ctrl queue */
+ INIT_LLIST_HEAD(&l1h->trx_ctrl_list);
+
+ /* open sockets */
+ if (l1h->trx->nr == 0) {
+ rc = trx_udp_open(NULL, &trx_ofd_clk, base_port_local,
+ trx_clk_read_cb);
+ if (rc < 0)
+ return rc;
+ LOGP(DTRX, LOGL_NOTICE, "Waiting for transceiver send clock\n");
+ }
+ rc = trx_udp_open(l1h, &l1h->trx_ofd_ctrl,
+ base_port_local + (l1h->trx->nr << 1) + 1, trx_ctrl_read_cb);
+ if (rc < 0)
+ goto err;
+ rc = trx_udp_open(l1h, &l1h->trx_ofd_data,
+ base_port_local + (l1h->trx->nr << 1) + 2, trx_data_read_cb);
+ if (rc < 0)
+ goto err;
+
+ /* enable all slots */
+ l1h->config.slotmask = 0xff;
+
+ if (l1h->trx->nr == 0)
+ trx_if_cmd_poweroff(l1h);
+
+ return 0;
+
+err:
+ trx_if_close(l1h);
+ return rc;
+}
+
+/* flush pending control messages */
+void trx_if_flush(struct trx_l1h *l1h)
+{
+ struct trx_ctrl_msg *tcm;
+
+ /* free ctrl message list */
+ while (!llist_empty(&l1h->trx_ctrl_list)) {
+ tcm = llist_entry(l1h->trx_ctrl_list.next, struct trx_ctrl_msg,
+ list);
+ llist_del(&tcm->list);
+ talloc_free(tcm);
+ }
+}
+
+void trx_if_close(struct trx_l1h *l1h)
+{
+ LOGP(DTRX, LOGL_NOTICE, "Close transceiver for trx=%u\n", l1h->trx->nr);
+
+ trx_if_flush(l1h);
+
+ /* close sockets */
+ if (l1h->trx->nr == 0)
+ trx_udp_close(&trx_ofd_clk);
+ trx_udp_close(&l1h->trx_ofd_ctrl);
+ trx_udp_close(&l1h->trx_ofd_data);
+}
+
diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h
new file mode 100644
index 0000000..ac0ee42
--- /dev/null
+++ b/src/osmo-bts-trx/trx_if.h
@@ -0,0 +1,35 @@
+#ifndef TRX_IF_H
+#define TRX_IF_H
+
+extern int transceiver_available;
+extern const char *transceiver_ip;
+extern int settsc_enabled;
+extern int setbsic_enabled;
+
+
+struct trx_ctrl_msg {
+ struct llist_head list;
+ char cmd[128];
+ int cmd_len;
+ int critical;
+};
+
+int trx_if_cmd_poweroff(struct trx_l1h *l1h);
+int trx_if_cmd_poweron(struct trx_l1h *l1h);
+int trx_if_cmd_settsc(struct trx_l1h *l1h, uint8_t tsc);
+int trx_if_cmd_setbsic(struct trx_l1h *l1h, uint8_t bsic);
+int trx_if_cmd_setrxgain(struct trx_l1h *l1h, int db);
+int trx_if_cmd_setpower(struct trx_l1h *l1h, int db);
+int trx_if_cmd_setmaxdly(struct trx_l1h *l1h, int dly);
+int trx_if_cmd_setslot(struct trx_l1h *l1h, uint8_t tn, uint8_t type);
+int trx_if_cmd_rxtune(struct trx_l1h *l1h, uint16_t arfcn);
+int trx_if_cmd_txtune(struct trx_l1h *l1h, uint16_t arfcn);
+int trx_if_cmd_handover(struct trx_l1h *l1h, uint8_t tn, uint8_t ss);
+int trx_if_cmd_nohandover(struct trx_l1h *l1h, uint8_t tn, uint8_t ss);
+int trx_if_data(struct trx_l1h *l1h, uint8_t tn, uint32_t fn, uint8_t pwr,
+ const ubit_t *bits);
+int trx_if_open(struct trx_l1h *l1h);
+void trx_if_flush(struct trx_l1h *l1h);
+void trx_if_close(struct trx_l1h *l1h);
+
+#endif /* TRX_IF_H */
diff --git a/src/osmo-bts-trx/trx_vty.c b/src/osmo-bts-trx/trx_vty.c
new file mode 100644
index 0000000..e3e9c36
--- /dev/null
+++ b/src/osmo-bts-trx/trx_vty.c
@@ -0,0 +1,421 @@
+/* VTY interface for sysmoBTS */
+
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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 <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <ctype.h>
+
+#include <arpa/inet.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/bits.h>
+
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/command.h>
+#include <osmocom/vty/misc.h>
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/vty.h>
+
+#include "l1_if.h"
+#include "scheduler.h"
+#include "trx_if.h"
+#include "loops.h"
+
+static struct gsm_bts *vty_bts;
+
+DEFUN(show_transceiver, show_transceiver_cmd, "show transceiver",
+ SHOW_STR "Display information about transceivers\n")
+{
+ struct gsm_bts *bts = vty_bts;
+ struct gsm_bts_trx *trx;
+ struct trx_l1h *l1h;
+ uint8_t tn;
+
+ if (!transceiver_available) {
+ vty_out(vty, "transceiver is not connected%s", VTY_NEWLINE);
+ } else {
+ vty_out(vty, "transceiver is connected, current fn=%u%s",
+ transceiver_last_fn, VTY_NEWLINE);
+ }
+
+ llist_for_each_entry(trx, &bts->trx_list, list) {
+ l1h = trx_l1h_hdl(trx);
+ vty_out(vty, "TRX %d%s", trx->nr, VTY_NEWLINE);
+ vty_out(vty, " %s%s",
+ (l1h->config.poweron) ? "poweron":"poweroff",
+ VTY_NEWLINE);
+ if (l1h->config.arfcn_valid)
+ vty_out(vty, " arfcn : %d%s%s",
+ (l1h->config.arfcn & ~ARFCN_PCS),
+ (l1h->config.arfcn & ARFCN_PCS) ? " (PCS)" : "",
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " arfcn : undefined%s", VTY_NEWLINE);
+ if (l1h->config.tsc_valid)
+ vty_out(vty, " tsc : %d%s", l1h->config.tsc,
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " tsc : undefined%s", VTY_NEWLINE);
+ if (l1h->config.bsic_valid)
+ vty_out(vty, " bsic : %d%s", l1h->config.bsic,
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " bisc : undefined%s", VTY_NEWLINE);
+ if (l1h->config.rxgain_valid)
+ vty_out(vty, " rxgain : %d%s", l1h->config.rxgain,
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " rxgain : undefined%s", VTY_NEWLINE);
+ if (l1h->config.power_valid)
+ vty_out(vty, " power : %d%s", l1h->config.power,
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " power : undefined%s", VTY_NEWLINE);
+ if (l1h->config.maxdly_valid)
+ vty_out(vty, " maxdly : %d%s", l1h->config.maxdly,
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " maxdly : undefined%s", VTY_NEWLINE);
+ for (tn = 0; tn < 8; tn++) {
+ if (!((1 << tn) & l1h->config.slotmask))
+ vty_out(vty, " slot #%d: unsupported%s", tn,
+ VTY_NEWLINE);
+ else if (l1h->config.slottype_valid[tn])
+ vty_out(vty, " slot #%d: type %d%s", tn,
+ l1h->config.slottype[tn],
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " slot #%d: undefined%s", tn,
+ VTY_NEWLINE);
+ }
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_fn_advance, cfg_bts_fn_advance_cmd,
+ "fn-advance <0-30>",
+ "Set the number of frames to be transmitted to transceiver in advance "
+ "of current FN\n"
+ "Advance in frames\n")
+{
+ trx_clock_advance = atoi(argv[0]);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_rts_advance, cfg_bts_rts_advance_cmd,
+ "rts-advance <0-30>",
+ "Set the number of frames to be requested (PCU) in advance of current "
+ "FN. Do not change this, unless you have a good reason!\n"
+ "Advance in frames\n")
+{
+ trx_rts_advance = atoi(argv[0]);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_ms_power_loop, cfg_bts_ms_power_loop_cmd,
+ "ms-power-loop <-127-127>",
+ "Enable MS power control loop\nTarget RSSI value (transceiver specific, "
+ "should be 6dB or more above noise floor)\n")
+{
+ trx_ms_power_loop = 1;
+ trx_target_rssi = atoi(argv[0]);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_no_ms_power_loop, cfg_bts_no_ms_power_loop_cmd,
+ "no ms-power-loop",
+ NO_STR "Disable MS power control loop\n")
+{
+ trx_ms_power_loop = 0;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_timing_advance_loop, cfg_bts_timing_advance_loop_cmd,
+ "timing-advance-loop",
+ "Enable timing advance control loop\n")
+{
+ trx_ta_loop = 1;
+
+ return CMD_SUCCESS;
+}
+DEFUN(cfg_bts_no_timing_advance_loop, cfg_bts_no_timing_advance_loop_cmd,
+ "no timing-advance-loop",
+ NO_STR "Disable timing advance control loop\n")
+{
+ trx_ta_loop = 0;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_settsc, cfg_bts_settsc_cmd,
+ "settsc",
+ "Use SETTSC to configure transceiver\n")
+{
+ settsc_enabled = 1;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_setbsic, cfg_bts_setbsic_cmd,
+ "setbsic",
+ "Use SETBSIC to configure transceiver\n")
+{
+ setbsic_enabled = 1;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_no_settsc, cfg_bts_no_settsc_cmd,
+ "no settsc",
+ NO_STR "Disable SETTSC to configure transceiver\n")
+{
+ settsc_enabled = 0;
+ if (!setbsic_enabled) {
+ vty_out(vty, "%% Auto enabling SETBSIC.%s", VTY_NEWLINE);
+ setbsic_enabled = 1;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_no_setbsic, cfg_bts_no_setbsic_cmd,
+ "no setbsic",
+ NO_STR "Disable SETBSIC to configure transceiver\n")
+{
+ setbsic_enabled = 0;
+ if (!settsc_enabled) {
+ vty_out(vty, "%% Auto enabling SETTSC.%s", VTY_NEWLINE);
+ settsc_enabled = 1;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_rxgain, cfg_trx_rxgain_cmd,
+ "rxgain <0-50>",
+ "Set the receiver gain in dB\n"
+ "Gain in dB\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.rxgain = atoi(argv[0]);
+ l1h->config.rxgain_valid = 1;
+ l1h->config.rxgain_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_power, cfg_trx_power_cmd,
+ "power <0-50>",
+ "Set the transmitter power dampening\n"
+ "Power dampening in dB\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.power = atoi(argv[0]);
+ l1h->config.power_oml = 0;
+ l1h->config.power_valid = 1;
+ l1h->config.power_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_poweroml_, cfg_trx_power_oml_cmd,
+ "power oml",
+ "Set the transmitter power dampening\n"
+ "Given by NM_ATT_RF_MAXPOWR_R (max power reduction) via OML\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.power = trx->max_power_red;
+ l1h->config.power_oml = 1;
+ l1h->config.power_valid = 1;
+ l1h->config.power_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_maxdly, cfg_trx_maxdly_cmd,
+ "maxdly <0-31>",
+ "Set the maximum delay of GSM symbols\n"
+ "GSM symbols (approx. 1.1km per symbol)\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.maxdly = atoi(argv[0]);
+ l1h->config.maxdly_valid = 1;
+ l1h->config.maxdly_sent = 0;
+ l1if_provision_transceiver_trx(l1h);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_slotmask, cfg_trx_slotmask_cmd,
+ "slotmask (1|0) (1|0) (1|0) (1|0) (1|0) (1|0) (1|0) (1|0)",
+ "Set the supported slots\n"
+ "TS0 supported\nTS0 unsupported\nTS1 supported\nTS1 unsupported\n"
+ "TS2 supported\nTS2 unsupported\nTS3 supported\nTS3 unsupported\n"
+ "TS4 supported\nTS4 unsupported\nTS5 supported\nTS5 unsupported\n"
+ "TS6 supported\nTS6 unsupported\nTS7 supported\nTS7 unsupported\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+ uint8_t tn;
+
+ l1h->config.slotmask = 0;
+ for (tn = 0; tn < 8; tn++)
+ if (argv[tn][0] == '1')
+ l1h->config.slotmask |= (1 << tn);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_no_rxgain, cfg_trx_no_rxgain_cmd,
+ "no rxgain <0-50>",
+ NO_STR "Unset the receiver gain in dB\n"
+ "Gain in dB\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.rxgain_valid = 0;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_no_power, cfg_trx_no_power_cmd,
+ "no power <0-50>",
+ NO_STR "Unset the transmitter power dampening\n"
+ "Power dampening in dB\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.power_valid = 0;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trx_no_maxdly, cfg_trx_no_maxdly_cmd,
+ "no maxdly <0-31>",
+ NO_STR "Unset the maximum delay of GSM symbols\n"
+ "GSM symbols (approx. 1.1km per symbol)\n")
+{
+ struct gsm_bts_trx *trx = vty->index;
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ l1h->config.maxdly_valid = 0;
+
+ return CMD_SUCCESS;
+}
+
+void bts_model_config_write_bts(struct vty *vty, struct gsm_bts *bts)
+{
+ vty_out(vty, " fn-advance %d%s", trx_clock_advance, VTY_NEWLINE);
+ vty_out(vty, " rts-advance %d%s", trx_rts_advance, VTY_NEWLINE);
+
+ if (trx_ms_power_loop)
+ vty_out(vty, " ms-power-loop %d%s", trx_target_rssi,
+ VTY_NEWLINE);
+ else
+ vty_out(vty, " no ms-power-loop%s", VTY_NEWLINE);
+ vty_out(vty, " %stiming-advance-loop%s", (trx_ta_loop) ? "":"no ",
+ VTY_NEWLINE);
+ if (settsc_enabled)
+ vty_out(vty, " settsc%s", VTY_NEWLINE);
+ if (setbsic_enabled)
+ vty_out(vty, " setbsic%s", VTY_NEWLINE);
+}
+
+void bts_model_config_write_trx(struct vty *vty, struct gsm_bts_trx *trx)
+{
+ struct trx_l1h *l1h = trx_l1h_hdl(trx);
+
+ if (l1h->config.rxgain_valid)
+ vty_out(vty, " rxgain %d%s", l1h->config.rxgain, VTY_NEWLINE);
+ if (l1h->config.power_valid) {
+ if (l1h->config.power_oml)
+ vty_out(vty, " power oml%s", VTY_NEWLINE);
+ else
+ vty_out(vty, " power %d%s", l1h->config.power,
+ VTY_NEWLINE);
+ }
+ if (l1h->config.maxdly_valid)
+ vty_out(vty, " maxdly %d%s", l1h->config.maxdly, VTY_NEWLINE);
+ if (l1h->config.slotmask != 0xff)
+ vty_out(vty, " slotmask %d %d %d %d %d %d %d %d%s",
+ l1h->config.slotmask & 1,
+ (l1h->config.slotmask >> 1) & 1,
+ (l1h->config.slotmask >> 2) & 1,
+ (l1h->config.slotmask >> 3) & 1,
+ (l1h->config.slotmask >> 4) & 1,
+ (l1h->config.slotmask >> 5) & 1,
+ (l1h->config.slotmask >> 6) & 1,
+ l1h->config.slotmask >> 7,
+ VTY_NEWLINE);
+}
+
+int bts_model_vty_init(struct gsm_bts *bts)
+{
+ vty_bts = bts;
+
+ install_element_ve(&show_transceiver_cmd);
+
+ install_element(BTS_NODE, &cfg_bts_fn_advance_cmd);
+ install_element(BTS_NODE, &cfg_bts_rts_advance_cmd);
+ install_element(BTS_NODE, &cfg_bts_ms_power_loop_cmd);
+ install_element(BTS_NODE, &cfg_bts_no_ms_power_loop_cmd);
+ install_element(BTS_NODE, &cfg_bts_timing_advance_loop_cmd);
+ install_element(BTS_NODE, &cfg_bts_no_timing_advance_loop_cmd);
+ install_element(BTS_NODE, &cfg_bts_settsc_cmd);
+ install_element(BTS_NODE, &cfg_bts_setbsic_cmd);
+ install_element(BTS_NODE, &cfg_bts_no_settsc_cmd);
+ install_element(BTS_NODE, &cfg_bts_no_setbsic_cmd);
+
+ install_element(TRX_NODE, &cfg_trx_rxgain_cmd);
+ install_element(TRX_NODE, &cfg_trx_power_cmd);
+ install_element(TRX_NODE, &cfg_trx_power_oml_cmd);
+ install_element(TRX_NODE, &cfg_trx_maxdly_cmd);
+ install_element(TRX_NODE, &cfg_trx_slotmask_cmd);
+ install_element(TRX_NODE, &cfg_trx_no_rxgain_cmd);
+ install_element(TRX_NODE, &cfg_trx_no_power_cmd);
+ install_element(TRX_NODE, &cfg_trx_no_maxdly_cmd);
+
+ return 0;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 633b6a4..7904486 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,12 @@
-SUBDIRS = paging cipher sysmobts agch misc
+SUBDIRS = paging cipher agch misc bursts handover
+
+if ENABLE_SYSMOBTS
+SUBDIRS += sysmobts
+endif
+
+if ENABLE_SYSMOBTS
+SUBDIRS += sysmobts
+endif
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
diff --git a/tests/bursts/Makefile.am b/tests/bursts/Makefile.am
new file mode 100644
index 0000000..462b728
--- /dev/null
+++ b/tests/bursts/Makefile.am
@@ -0,0 +1,14 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS)
+noinst_PROGRAMS = bursts_test
+EXTRA_DIST = bursts_test.ok
+
+bursts_test_SOURCES = bursts_test.c \
+ $(top_builddir)/src/osmo-bts-trx/gsm0503_coding.c \
+ $(top_builddir)/src/osmo-bts-trx/gsm0503_conv.c \
+ $(top_builddir)/src/osmo-bts-trx/gsm0503_interleaving.c \
+ $(top_builddir)/src/osmo-bts-trx/gsm0503_mapping.c \
+ $(top_builddir)/src/osmo-bts-trx/gsm0503_tables.c \
+ $(top_builddir)/src/osmo-bts-trx/gsm0503_parity.c
+bursts_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)
diff --git a/tests/bursts/bursts_test.c b/tests/bursts/bursts_test.c
new file mode 100644
index 0000000..cc0eacf
--- /dev/null
+++ b/tests/bursts/bursts_test.c
@@ -0,0 +1,495 @@
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ * (C) 2015 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
+ *
+ * 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 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 <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/utils.h>
+
+#include "../../src/osmo-bts-trx/gsm0503_coding.h"
+
+#include <osmo-bts/logging.h>
+
+#define ASSERT_TRUE(rc) \
+ if (!(rc)) { \
+ printf("Assert failed in %s:%d.\n", \
+ __FILE__, __LINE__); \
+ abort(); \
+ }
+
+/* set condition to 1, to show debugging */
+#define printd if (0) printf
+
+static int ubits2sbits(ubit_t *ubits, sbit_t *sbits, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ if (*ubits == 0x23) {
+ ubits++;
+ sbits++;
+ continue;
+ }
+ if ((*ubits++) & 1)
+ *sbits++ = -127;
+ else
+ *sbits++ = 127;
+ }
+
+ return count;
+}
+
+static void test_xcch(uint8_t *l2)
+{
+ uint8_t result[23];
+ ubit_t bursts_u[116 * 4];
+ sbit_t bursts_s[116 * 4];
+ int n_errors, n_bits_total;
+
+ printd("Encoding: %s\n", osmo_hexdump(l2, 23));
+
+ /* encode */
+ xcch_encode(bursts_u, l2);
+
+ printd("U-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57),
+ bursts_u[57], bursts_u[58]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57),
+ bursts_u[57 + 116], bursts_u[58 + 116]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57),
+ bursts_u[57 + 232], bursts_u[58 + 232]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57),
+ bursts_u[57 + 348], bursts_u[58 + 348]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
+ ubits2sbits(bursts_u, bursts_s, 116 * 4);
+ printd("S-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57),
+ (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57),
+ (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57),
+ (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57),
+ (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57));
+
+ /* destroy */
+ memset(bursts_s, 0, 30);
+ memset(bursts_s + 116, 0, 30);
+
+ /* decode */
+ xcch_decode(result, bursts_s, &n_errors, &n_bits_total);
+
+ ASSERT_TRUE(n_bits_total == 456);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, 23));
+ printf("xcch_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
+ n_errors, n_bits_total, (float)n_errors/n_bits_total);
+
+ ASSERT_TRUE(!memcmp(l2, result, 23));
+
+ printd("\n");
+}
+
+static void test_rach(uint8_t bsic, uint8_t ra)
+{
+ uint8_t result;
+ ubit_t bursts_u[36];
+ sbit_t bursts_s[36];
+
+ printd("Encoding: %02x\n", ra);
+
+ /* encode */
+ rach_encode(bursts_u, &ra, bsic);
+
+ printd("U-Bits:\n");
+ printd("%s\n", osmo_hexdump(bursts_u, 36));
+ ubits2sbits(bursts_u, bursts_s, 36);
+ printd("S-Bits:\n");
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s, 36));
+
+ /* destroy */
+ memset(bursts_s + 6, 0, 8);
+
+ /* decode */
+ rach_decode(&result, bursts_s, bsic);
+
+ printd("Decoded: %02x\n", result);
+
+ ASSERT_TRUE(ra == result);
+
+ printd("\n");
+}
+
+static void test_sch(uint8_t *info)
+{
+ uint8_t result[4];
+ ubit_t bursts_u[78];
+ sbit_t bursts_s[78];
+
+ /* zero bits 25 and above */
+ info[3] &= 1;
+ result[3] = 0;
+
+ printd("Encoding: %s\n", osmo_hexdump(info, 4));
+
+ /* encode */
+ sch_encode(bursts_u, info);
+
+ printd("U-Bits:\n");
+ printd("%s\n", osmo_hexdump(bursts_u, 78));
+ ubits2sbits(bursts_u, bursts_s, 78);
+ printd("S-Bits:\n");
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s, 78));
+
+ /* destroy */
+ memset(bursts_s + 6, 0, 10);
+
+ /* decode */
+ sch_decode(result, bursts_s);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, 4));
+
+ ASSERT_TRUE(!memcmp(info, result, 4));
+
+ printd("\n");
+}
+
+static void test_fr(uint8_t *speech, int len)
+{
+ uint8_t result[33];
+ ubit_t bursts_u[116 * 8];
+ sbit_t bursts_s[116 * 8];
+ int n_errors, n_bits_total;
+ int rc;
+
+ memset(bursts_u, 0x23, sizeof(bursts_u));
+ memset(bursts_s, 0, sizeof(bursts_s));
+
+ printd("Encoding: %s\n", osmo_hexdump(speech, len));
+
+ /* encode */
+ tch_fr_encode(bursts_u, speech, len, 1);
+
+ printd("U-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57),
+ bursts_u[57], bursts_u[58]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57),
+ bursts_u[57 + 116], bursts_u[58 + 116]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57),
+ bursts_u[57 + 232], bursts_u[58 + 232]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57),
+ bursts_u[57 + 348], bursts_u[58 + 348]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 464, 57),
+ bursts_u[57 + 464], bursts_u[58 + 464]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 464, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 580, 57),
+ bursts_u[57 + 580], bursts_u[58 + 580]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 580, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 696, 57),
+ bursts_u[57 + 696], bursts_u[58 + 696]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 696, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 812, 57),
+ bursts_u[57 + 812], bursts_u[58 + 812]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 812, 57));
+ ubits2sbits(bursts_u, bursts_s, 116 * 8);
+ printd("S-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57),
+ (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57),
+ (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57),
+ (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57),
+ (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 464, 57),
+ (uint8_t)bursts_s[57 + 464], (uint8_t)bursts_s[58 + 464]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 464, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 580, 57),
+ (uint8_t)bursts_s[57 + 580], (uint8_t)bursts_s[58 + 580]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 580, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 696, 57),
+ (uint8_t)bursts_s[57 + 696], (uint8_t)bursts_s[58 + 696]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 696, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 812, 57),
+ (uint8_t)bursts_s[57 + 812], (uint8_t)bursts_s[58 + 812]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 812, 57));
+
+ /* destroy */
+ memset(bursts_s + 6, 0, 20);
+
+ /* decode */
+ rc = tch_fr_decode(result, bursts_s, 1, len == 31, &n_errors, &n_bits_total);
+
+ ASSERT_TRUE(rc == len);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, len));
+ printf("tch_fr_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
+ n_errors, n_bits_total, (float)n_errors/n_bits_total);
+
+ ASSERT_TRUE(!memcmp(speech, result, len));
+
+ printd("\n");
+}
+
+static void test_hr(uint8_t *speech, int len)
+{
+ uint8_t result[23];
+ ubit_t bursts_u[116 * 6];
+ sbit_t bursts_s[116 * 6];
+ int n_errors, n_bits_total;
+ int rc;
+
+ memset(bursts_u, 0x23, sizeof(bursts_u));
+ memset(bursts_s, 0, sizeof(bursts_s));
+
+ printd("Encoding: %s\n", osmo_hexdump(speech, len));
+
+ /* encode */
+ tch_hr_encode(bursts_u, speech, len);
+
+ printd("U-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57),
+ bursts_u[57], bursts_u[58]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57),
+ bursts_u[57 + 116], bursts_u[58 + 116]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57),
+ bursts_u[57 + 232], bursts_u[58 + 232]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57),
+ bursts_u[57 + 348], bursts_u[58 + 348]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 464, 57),
+ bursts_u[57 + 464], bursts_u[58 + 464]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 464, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 580, 57),
+ bursts_u[57 + 580], bursts_u[58 + 580]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 580, 57));
+ ubits2sbits(bursts_u, bursts_s, 116 * 6);
+ printd("S-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57),
+ (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57),
+ (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57),
+ (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57),
+ (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 464, 57),
+ (uint8_t)bursts_s[57 + 464], (uint8_t)bursts_s[58 + 464]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 464, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 580, 57),
+ (uint8_t)bursts_s[57 + 580], (uint8_t)bursts_s[58 + 580]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 580, 57));
+
+ /* destroy */
+ memset(bursts_s + 6, 0, 20);
+
+ /* decode */
+ rc = tch_hr_decode(result, bursts_s, 0, &n_errors, &n_bits_total);
+
+ ASSERT_TRUE(rc == len);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, len));
+ printf("tch_hr_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
+ n_errors, n_bits_total, (float)n_errors/n_bits_total);
+
+ ASSERT_TRUE(!memcmp(speech, result, len));
+
+ printd("\n");
+}
+
+static void test_pdtch(uint8_t *l2, int len)
+{
+ uint8_t result[len];
+ ubit_t bursts_u[116 * 4];
+ sbit_t bursts_s[116 * 4];
+ int n_errors, n_bits_total;
+ int rc;
+
+ /* zero the not coded tail bits */
+ switch (len) {
+ case 34:
+ case 54:
+ l2[len - 1] &= 0x7f;
+ result[len - 1] &= 0x7f;
+ break;
+ case 40:
+ l2[len - 1] &= 0x07;
+ result[len - 1] &= 0x07;
+ break;
+ }
+
+ printd("Encoding: %s\n", osmo_hexdump(l2, len));
+
+ /* encode */
+ pdtch_encode(bursts_u, l2, len);
+
+ printd("U-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u, 57),
+ bursts_u[57], bursts_u[58]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 116, 57),
+ bursts_u[57 + 116], bursts_u[58 + 116]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 232, 57),
+ bursts_u[57 + 232], bursts_u[58 + 232]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump(bursts_u + 348, 57),
+ bursts_u[57 + 348], bursts_u[58 + 348]);
+ printd("%s\n", osmo_hexdump(bursts_u + 59 + 348, 57));
+ ubits2sbits(bursts_u, bursts_s, 116 * 4);
+ printd("S-Bits:\n");
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s, 57),
+ (uint8_t)bursts_s[57], (uint8_t)bursts_s[58]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 116, 57),
+ (uint8_t)bursts_s[57 + 116], (uint8_t)bursts_s[58 + 116]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 116, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 232, 57),
+ (uint8_t)bursts_s[57 + 232], (uint8_t)bursts_s[58 + 232]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 232, 57));
+ printd("%s %02x %02x ", osmo_hexdump((uint8_t *)bursts_s + 348, 57),
+ (uint8_t)bursts_s[57 + 348], (uint8_t)bursts_s[58 + 348]);
+ printd("%s\n", osmo_hexdump((uint8_t *)bursts_s + 59 + 348, 57));
+
+ /* decode */
+ rc = pdtch_decode(result, bursts_s, NULL, &n_errors, &n_bits_total);
+
+ ASSERT_TRUE(rc == len);
+
+ printd("Decoded: %s\n", osmo_hexdump(result, len));
+ printf("pdtch_decode: n_errors=%d n_bits_total=%d ber=%.2f\n",
+ n_errors, n_bits_total, (float)n_errors/n_bits_total);
+
+ ASSERT_TRUE(!memcmp(l2, result, len));
+
+ printd("\n");
+}
+
+uint8_t test_l2[][23] = {
+ /* dummy frame */
+ { 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ /* random frame */
+ { 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab,
+ 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92,
+ 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0x59, 0xa8 },
+ /* jolly frame */
+ { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
+};
+
+uint8_t test_macblock[][54] = {
+ /* random frame */
+ { 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab,
+ 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92,
+ 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0x59, 0xa8, 0x42,
+ 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab,
+ 0xa3, 0xaf, 0x5f, 0xc6, 0x36, 0x43, 0x44, 0xab,
+ 0xd9, 0x6d, 0x7d, 0x62, 0x24, 0xc9, 0xd2, 0x92,
+ 0xfa, 0x27, 0x5d, 0x71, 0x7a, 0xa8 },
+ /* jolly frame */
+ { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
+};
+
+uint8_t test_speech_fr[33];
+uint8_t test_speech_efr[31];
+uint8_t test_speech_hr[15];
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ bts_log_init(NULL);
+
+ for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++)
+ test_xcch(test_l2[i]);
+
+ for (i = 0; i < 256; i++) {
+ test_rach(0x3f, i);
+ test_rach(0x00, i);
+ test_rach(0x1a, i);
+ }
+
+ for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++)
+ test_sch(test_l2[i]);
+
+ for (i = 0; i < sizeof(test_speech_fr); i++)
+ test_speech_fr[i] = i;
+ test_speech_fr[0] = 0xd0;
+ test_fr(test_speech_fr, sizeof(test_speech_fr));
+
+ for (i = 0; i < sizeof(test_speech_efr); i++)
+ test_speech_efr[i] = i;
+ test_speech_efr[0] = 0xc0;
+ test_fr(test_speech_efr, sizeof(test_speech_efr));
+
+ for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++)
+ test_fr(test_l2[i], sizeof(test_l2[0]));
+
+ for (i = 0; i < sizeof(test_speech_hr); i++)
+ test_speech_hr[i] = i*17;
+ test_speech_hr[0] = 0x00;
+ test_hr(test_speech_hr, sizeof(test_speech_hr));
+
+ for (i = 0; i < sizeof(test_l2) / sizeof(test_l2[0]); i++)
+ test_hr(test_l2[i], sizeof(test_l2[0]));
+
+ for (i = 0; i < sizeof(test_macblock) / sizeof(test_macblock[0]); i++) {
+ test_pdtch(test_macblock[i], 23);
+ test_pdtch(test_macblock[i], 34);
+ test_pdtch(test_macblock[i], 40);
+ test_pdtch(test_macblock[i], 54);
+ }
+
+ printf("Success\n");
+
+ return 0;
+}
+
diff --git a/tests/bursts/bursts_test.ok b/tests/bursts/bursts_test.ok
new file mode 100644
index 0000000..4136905
--- /dev/null
+++ b/tests/bursts/bursts_test.ok
@@ -0,0 +1,21 @@
+xcch_decode: n_errors=60 n_bits_total=456 ber=0.13
+xcch_decode: n_errors=60 n_bits_total=456 ber=0.13
+xcch_decode: n_errors=60 n_bits_total=456 ber=0.13
+tch_fr_decode: n_errors=8 n_bits_total=378 ber=0.02
+tch_fr_decode: n_errors=8 n_bits_total=378 ber=0.02
+tch_fr_decode: n_errors=10 n_bits_total=456 ber=0.02
+tch_fr_decode: n_errors=10 n_bits_total=456 ber=0.02
+tch_fr_decode: n_errors=10 n_bits_total=456 ber=0.02
+tch_hr_decode: n_errors=11 n_bits_total=211 ber=0.05
+tch_hr_decode: n_errors=10 n_bits_total=456 ber=0.02
+tch_hr_decode: n_errors=10 n_bits_total=456 ber=0.02
+tch_hr_decode: n_errors=10 n_bits_total=456 ber=0.02
+pdtch_decode: n_errors=0 n_bits_total=456 ber=0.00
+pdtch_decode: n_errors=132 n_bits_total=588 ber=0.22
+pdtch_decode: n_errors=220 n_bits_total=676 ber=0.33
+pdtch_decode: n_errors=0 n_bits_total=444 ber=0.00
+pdtch_decode: n_errors=0 n_bits_total=456 ber=0.00
+pdtch_decode: n_errors=132 n_bits_total=588 ber=0.22
+pdtch_decode: n_errors=220 n_bits_total=676 ber=0.33
+pdtch_decode: n_errors=0 n_bits_total=444 ber=0.00
+Success
diff --git a/tests/handover/Makefile.am b/tests/handover/Makefile.am
new file mode 100644
index 0000000..597ab2d
--- /dev/null
+++ b/tests/handover/Makefile.am
@@ -0,0 +1,8 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
+AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS)$(LIBOSMOTRAU_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS)
+noinst_PROGRAMS = handover_test
+EXTRA_DIST = handover_test.ok
+
+handover_test_SOURCES = handover_test.c
+handover_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)
diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
new file mode 100644
index 0000000..6d7e6d1
--- /dev/null
+++ b/tests/handover/handover_test.c
@@ -0,0 +1,278 @@
+#include <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <sched.h>
+#include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/application.h>
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/core/gsmtap.h>
+#include <osmocom/core/gsmtap_util.h>
+#include <osmocom/core/bits.h>
+#include <osmocom/core/backtrace.h>
+#include <osmocom/abis/abis.h>
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/logging.h>
+#include <osmo-bts/abis.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/vty.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/pcu_if.h>
+#include <osmo-bts/l1sap.h>
+#include <osmo-bts/handover.h>
+
+uint8_t phys_info[] = { 0x03, 0x03, 0x0d, 0x06, 0x2d, 0x00, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b };
+
+static struct gsm_bts *bts;
+struct gsm_bts_trx *trx;
+int quit = 0;
+uint8_t abis_mac[6] = { 0, 1, 2, 3, 4, 5 };
+const int pcu_direct = 0;
+int modify_count = 0;
+
+static void expect_phys_info(struct lapdm_entity *le)
+{
+ struct osmo_phsap_prim pp;
+ int rc;
+
+ rc = lapdm_phsap_dequeue_prim(le, &pp);
+ OSMO_ASSERT(rc == 0);
+ OSMO_ASSERT(sizeof(phys_info) == pp.oph.msg->len);
+ OSMO_ASSERT(!memcmp(phys_info, pp.oph.msg->data, pp.oph.msg->len));
+ msgb_free(pp.oph.msg);
+}
+
+int main(int argc, char **argv)
+{
+ struct gsm_bts_role_bts *btsb;
+ void *tall_bts_ctx;
+ void *tall_msgb_ctx;
+ struct e1inp_line *line;
+ struct gsm_lchan *lchan;
+ struct osmo_phsap_prim nl1sap;
+ struct msgb *msg;
+ struct abis_rsl_dchan_hdr *rslh;
+ int i;
+
+ tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context");
+ tall_msgb_ctx = talloc_named_const(tall_bts_ctx, 1, "msgb");
+ msgb_set_talloc_ctx(tall_msgb_ctx);
+
+ bts_log_init(NULL);
+ osmo_stderr_target->categories[DHO].loglevel = LOGL_DEBUG;
+
+ bts = gsm_bts_alloc(tall_bts_ctx);
+ if (!bts) {
+ fprintf(stderr, "Failed to create BTS structure\n");
+ exit(1);
+ }
+ trx = gsm_bts_trx_alloc(bts);
+ if (!trx) {
+ fprintf(stderr, "Failed to TRX structure\n");
+ exit(1);
+ }
+
+ if (bts_init(bts) < 0) {
+ fprintf(stderr, "unable to to open bts\n");
+ exit(1);
+ }
+
+ btsb = bts_role_bts(bts);
+
+ libosmo_abis_init(NULL);
+
+ line = e1inp_line_create(0, "ipa");
+ OSMO_ASSERT(line);
+
+ e1inp_ts_config_sign(&line->ts[E1INP_SIGN_RSL-1], line);
+ trx->rsl_link = e1inp_sign_link_create(&line->ts[E1INP_SIGN_RSL-1], E1INP_SIGN_RSL, NULL, 0, 0);
+ OSMO_ASSERT(trx->rsl_link);
+ trx->rsl_link->trx = trx;
+
+ fprintf(stderr, "test 1: without timeout\n");
+
+ /* create two lchans for handover */
+ lchan = &trx->ts[1].lchan[0];
+ l1sap_chan_act(lchan->ts->trx, 0x09, NULL);
+ lchan = &trx->ts[2].lchan[0];
+ lchan->ho.active = HANDOVER_ENABLED;
+ lchan->ho.ref = 23;
+ l1sap_chan_act(lchan->ts->trx, 0x0a, NULL);
+ OSMO_ASSERT(msgb_dequeue(&trx->rsl_link->tx_list));
+ OSMO_ASSERT(msgb_dequeue(&trx->rsl_link->tx_list));
+ OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list));
+
+ /* send access burst with wrong ref */
+ memset(&nl1sap, 0, sizeof(nl1sap));
+ osmo_prim_init(&nl1sap.oph, SAP_GSM_PH, PRIM_PH_RACH, PRIM_OP_INDICATION, NULL);
+ nl1sap.u.rach_ind.chan_nr = 0x0a;
+ nl1sap.u.rach_ind.ra = 42;
+ l1sap_up(trx, &nl1sap);
+
+ /* expect no action */
+ OSMO_ASSERT(modify_count == 0);
+ OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list));
+
+ /* send access burst with correct ref */
+ nl1sap.u.rach_ind.ra = 23;
+ l1sap_up(trx, &nl1sap);
+ OSMO_ASSERT(modify_count == 1);
+
+ /* expect PHYS INFO */
+ expect_phys_info(&trx->ts[2].lchan[0].lapdm_ch.lapdm_dcch);
+
+ /* expect exactly one HO.DET */
+ OSMO_ASSERT(msg = msgb_dequeue(&trx->rsl_link->tx_list));
+ rslh = msgb_l2(msg);
+ OSMO_ASSERT(rslh->c.msg_type == RSL_MT_HANDO_DET);
+ OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list));
+
+ /* expect T3105 running */
+ OSMO_ASSERT(osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105))
+
+ /* indicate frame */
+ handover_frame(&trx->ts[2].lchan[0]);
+
+ /* expect T3105 not running */
+ OSMO_ASSERT(!osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105))
+
+ fprintf(stderr, "test 2: with timeout\n");
+
+ /* enable handover again */
+ lchan = &trx->ts[2].lchan[0];
+ lchan->ho.active = HANDOVER_ENABLED;
+ lchan->ho.ref = 23;
+ modify_count = 0;
+
+ /* send access burst with correct ref */
+ nl1sap.u.rach_ind.ra = 23;
+ l1sap_up(trx, &nl1sap);
+ OSMO_ASSERT(modify_count == 1);
+
+ /* expect PHYS INFO */
+ expect_phys_info(&trx->ts[2].lchan[0].lapdm_ch.lapdm_dcch);
+
+ /* expect exactly one HO.DET */
+ OSMO_ASSERT(msg = msgb_dequeue(&trx->rsl_link->tx_list));
+ rslh = msgb_l2(msg);
+ OSMO_ASSERT(rslh->c.msg_type == RSL_MT_HANDO_DET);
+ OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list));
+
+ for (i = 0; i < btsb->ny1 - 1; i++) {
+ /* expect T3105 running */
+ OSMO_ASSERT(osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105))
+
+ /* timeout T3105 */
+ gettimeofday(&trx->ts[2].lchan[0].ho.t3105.timeout, NULL);
+ osmo_select_main(0);
+
+ /* expect PHYS INFO */
+ expect_phys_info(&trx->ts[2].lchan[0].lapdm_ch.lapdm_dcch);
+ }
+
+ /* timeout T3105 */
+ gettimeofday(&trx->ts[2].lchan[0].ho.t3105.timeout, NULL);
+ osmo_select_main(0);
+
+ /* expect T3105 not running */
+ OSMO_ASSERT(!osmo_timer_pending(&trx->ts[2].lchan[0].ho.t3105))
+
+ /* expect exactly one CONN.FAIL */
+ OSMO_ASSERT(msg = msgb_dequeue(&trx->rsl_link->tx_list));
+ rslh = msgb_l2(msg);
+ OSMO_ASSERT(rslh->c.msg_type == RSL_MT_CONN_FAIL);
+ OSMO_ASSERT(!msgb_dequeue(&trx->rsl_link->tx_list));
+
+#if 0
+ while (!quit) {
+ log_reset_context();
+ osmo_select_main(0);
+ }
+#endif
+
+ printf("Success\n");
+
+ return 0;
+}
+
+void bts_model_abis_close(struct gsm_bts *bts)
+{
+}
+
+int bts_model_oml_estab(struct gsm_bts *bts)
+{
+ return 0;
+}
+
+int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap)
+{
+ int rc = 0;
+ uint8_t chan_nr;
+ uint8_t tn, ss;
+ struct gsm_lchan *lchan;
+ struct msgb *msg = l1sap->oph.msg;
+ struct osmo_phsap_prim nl1sap;
+
+ switch (OSMO_PRIM_HDR(&l1sap->oph)) {
+ case OSMO_PRIM(PRIM_MPH_INFO, PRIM_OP_REQUEST):
+ switch (l1sap->u.info.type) {
+ case PRIM_INFO_ACTIVATE:
+ chan_nr = l1sap->u.info.u.act_req.chan_nr;
+ tn = L1SAP_CHAN2TS(chan_nr);
+ ss = l1sap_chan2ss(chan_nr);
+ lchan = &trx->ts[tn].lchan[ss];
+
+ lchan_init_lapdm(lchan);
+
+ lchan_set_state(lchan, LCHAN_S_ACTIVE);
+
+ memset(&nl1sap, 0, sizeof(nl1sap));
+ osmo_prim_init(&nl1sap.oph, SAP_GSM_PH, PRIM_MPH_INFO, PRIM_OP_CONFIRM, NULL);
+ nl1sap.u.info.type = PRIM_INFO_ACTIVATE;
+ nl1sap.u.info.u.act_cnf.chan_nr = chan_nr;
+ return l1sap_up(trx, &nl1sap);
+ case PRIM_INFO_MODIFY:
+ modify_count++;
+ break;
+ default:
+ LOGP(DL1C, LOGL_NOTICE, "unknown MPH-INFO.req %d\n",
+ l1sap->u.info.type);
+ rc = -EINVAL;
+ goto done;
+ }
+ break;
+ default:
+ LOGP(DL1C, LOGL_NOTICE, "unknown prim %d op %d\n",
+ l1sap->oph.primitive, l1sap->oph.operation);
+ rc = -EINVAL;
+ goto done;
+ }
+
+done:
+ if (msg)
+ msgb_free(msg);
+ return rc;
+}
+
+int bts_model_check_oml(struct gsm_bts *bts, uint8_t msg_type, struct tlv_parsed *old_attr, struct tlv_parsed *new_attr, void *obj) { return 0; }
+int bts_model_apply_oml(struct gsm_bts *bts, struct msgb *msg, struct tlv_parsed *new_attr, int obj_kind, void *obj) { return 0; }
+int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj) { return 0; }
+int bts_model_chg_adm_state(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj, uint8_t adm_state) { return 0; }
+int bts_model_init(struct gsm_bts *bts) { return 0; }
+int bts_model_trx_deact_rf(struct gsm_bts_trx *trx) { return 0; }
+int bts_model_trx_close(struct gsm_bts_trx *trx) { return 0; }
+void trx_get_hlayer1(void) {}
+int bts_model_adjst_ms_pwr(struct gsm_lchan *lchan) { return 0; }
diff --git a/tests/handover/handover_test.ok b/tests/handover/handover_test.ok
new file mode 100644
index 0000000..3582111
--- /dev/null
+++ b/tests/handover/handover_test.ok
@@ -0,0 +1 @@
+Success
diff --git a/tests/stubs.c b/tests/stubs.c
index 89ab802..f1ba5cc 100644
--- a/tests/stubs.c
+++ b/tests/stubs.c
@@ -59,3 +59,6 @@ int l1if_set_txpower(struct femtol1_hdl *fl1h, float tx_power)
int bts_model_adjst_ms_pwr(struct gsm_lchan *lchan)
{ return 0; }
+
+void bts_model_abis_close(struct gsm_bts *bts)
+{ }
diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c
index 99fd4c7..def7a81 100644
--- a/tests/sysmobts/sysmobts_test.c
+++ b/tests/sysmobts/sysmobts_test.c
@@ -265,3 +265,5 @@ int bts_model_init(struct gsm_bts *bts)
{ return 0; }
int bts_model_oml_estab(struct gsm_bts *bts)
{ return 0; }
+void bts_model_abis_close(struct gsm_bts *bts)
+{ }
diff --git a/tests/testsuite.at b/tests/testsuite.at
index b528335..171fade 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -24,3 +24,15 @@ AT_KEYWORDS([misc])
cat $abs_srcdir/misc/misc_test.ok > expout
AT_CHECK([$OSMO_QEMU $abs_top_builddir/tests/misc/misc_test], [], [expout], [ignore])
AT_CLEANUP
+
+AT_SETUP([bursts])
+AT_KEYWORDS([bursts])
+cat $abs_srcdir/bursts/bursts_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/bursts/bursts_test], [], [expout], [ignore])
+AT_CLEANUP
+
+AT_SETUP([handover])
+AT_KEYWORDS([handover])
+cat $abs_srcdir/handover/handover_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/handover/handover_test], [], [expout], [ignore])
+AT_CLEANUP