From ad8f7794c9b7c5c03f34e1d6a273e8b5f7c9da30 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 22 May 2023 20:21:26 +0700 Subject: [PATCH] trxcon/l1sched: remove redundant TCH/[FH] prim length checks Both gsm0503_tch_[fh]r_encode() do check the given payload length in order to determine the payload and/or codec type. The same applies to gsm0503_tch_a[fh]s_encode(). There is no real need to implement additional length checks on top of that - drop them. Change-Id: Ib1adf4945fb762bc2a51a1008f6bef6784fb7833 Related: OS#4396 --- src/host/trxcon/src/sched_lchan_tchf.c | 45 +++++++++----------------- src/host/trxcon/src/sched_lchan_tchh.c | 41 ++++++++--------------- 2 files changed, 29 insertions(+), 57 deletions(-) diff --git a/src/host/trxcon/src/sched_lchan_tchf.c b/src/host/trxcon/src/sched_lchan_tchf.c index 326713d4f..fca210889 100644 --- a/src/host/trxcon/src/sched_lchan_tchf.c +++ b/src/host/trxcon/src/sched_lchan_tchf.c @@ -219,7 +219,6 @@ int tx_tchf_fn(struct l1sched_lchan_state *lchan, ubit_t *buffer, *offset; const uint8_t *tsc; uint8_t *mask; - size_t l2_len; int rc; /* Set up pointers */ @@ -238,10 +237,16 @@ int tx_tchf_fn(struct l1sched_lchan_state *lchan, memcpy(buffer, buffer + 464, 464); /* populate the buffer with bursts */ - if (msgb_l2len(lchan->prim) == GSM_MACBLOCK_LEN) { - /* Encode payload */ - rc = gsm0503_tch_fr_encode(buffer, msgb_l2(lchan->prim), GSM_MACBLOCK_LEN, 1); - } else if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) { + switch (lchan->tch_mode) { + case GSM48_CMODE_SIGN: + case GSM48_CMODE_SPEECH_V1: + case GSM48_CMODE_SPEECH_EFR: + rc = gsm0503_tch_fr_encode(buffer, + msgb_l2(lchan->prim), + msgb_l2len(lchan->prim), 1); + break; + case GSM48_CMODE_SPEECH_AMR: + { int len; uint8_t cmr_codec; int ft, cmr, i; @@ -295,31 +300,11 @@ int tx_tchf_fn(struct l1sched_lchan_state *lchan, lchan->amr.codecs, lchan->amr.ul_ft, lchan->amr.ul_cmr); - } else { - /* Determine and check the payload length */ - switch (lchan->tch_mode) { - case GSM48_CMODE_SIGN: - case GSM48_CMODE_SPEECH_V1: /* FR */ - l2_len = GSM_FR_BYTES; - break; - case GSM48_CMODE_SPEECH_EFR: /* EFR */ - l2_len = GSM_EFR_BYTES; - break; - default: - LOGP_LCHAND(lchan, LOGL_ERROR, - "Invalid TCH mode: %u, dropping frame...\n", - lchan->tch_mode); - l1sched_lchan_prim_drop(lchan); - return -EINVAL; - } - if (msgb_l2len(lchan->prim) != l2_len) { - LOGP_LCHAND(lchan, LOGL_ERROR, "Primitive has odd length %u " - "(expected %zu for TCH or %u for FACCH), so dropping...\n", - msgb_l2len(lchan->prim), l2_len, GSM_MACBLOCK_LEN); - l1sched_lchan_prim_drop(lchan); - return -EINVAL; - } - rc = gsm0503_tch_fr_encode(buffer, msgb_l2(lchan->prim), l2_len, 1); + break; + } + default: + LOGP_LCHAND(lchan, LOGL_ERROR, "Invalid TCH mode: %u\n", lchan->tch_mode); + return -EINVAL; } if (rc) { diff --git a/src/host/trxcon/src/sched_lchan_tchh.c b/src/host/trxcon/src/sched_lchan_tchh.c index 34781d380..e3e4cdeda 100644 --- a/src/host/trxcon/src/sched_lchan_tchh.c +++ b/src/host/trxcon/src/sched_lchan_tchh.c @@ -425,7 +425,6 @@ int tx_tchh_fn(struct l1sched_lchan_state *lchan, ubit_t *buffer, *offset; const uint8_t *tsc; uint8_t *mask; - size_t l2_len; int rc; /* Set up pointers */ @@ -459,10 +458,15 @@ int tx_tchh_fn(struct l1sched_lchan_state *lchan, } /* populate the buffer with bursts */ - if (msgb_l2len(lchan->prim) == GSM_MACBLOCK_LEN) { - rc = gsm0503_tch_hr_encode(buffer, msgb_l2(lchan->prim), GSM_MACBLOCK_LEN); - lchan->ul_facch_blocks = 6; - } else if (lchan->tch_mode == GSM48_CMODE_SPEECH_AMR) { + switch (lchan->tch_mode) { + case GSM48_CMODE_SIGN: + case GSM48_CMODE_SPEECH_V1: + rc = gsm0503_tch_hr_encode(buffer, + msgb_l2(lchan->prim), + msgb_l2len(lchan->prim)); + break; + case GSM48_CMODE_SPEECH_AMR: + { int len; uint8_t cmr_codec; int ft, cmr, i; @@ -516,28 +520,11 @@ int tx_tchh_fn(struct l1sched_lchan_state *lchan, lchan->amr.codecs, lchan->amr.ul_ft, lchan->amr.ul_cmr); - } else { - /* Determine and check the payload length */ - switch (lchan->tch_mode) { - case GSM48_CMODE_SIGN: - case GSM48_CMODE_SPEECH_V1: /* HR */ - l2_len = GSM_HR_BYTES + 1; - break; - default: - LOGP_LCHAND(lchan, LOGL_ERROR, - "Invalid TCH mode: %u, dropping frame...\n", - lchan->tch_mode); - l1sched_lchan_prim_drop(lchan); - return -EINVAL; - } - if (msgb_l2len(lchan->prim) != l2_len) { - LOGP_LCHAND(lchan, LOGL_ERROR, "Primitive has odd length %u " - "(expected %zu for TCH or %u for FACCH), so dropping...\n", - msgb_l2len(lchan->prim), l2_len, GSM_MACBLOCK_LEN); - l1sched_lchan_prim_drop(lchan); - return -EINVAL; - } - rc = gsm0503_tch_hr_encode(buffer, msgb_l2(lchan->prim), l2_len); + break; + } + default: + LOGP_LCHAND(lchan, LOGL_ERROR, "Invalid TCH mode: %u\n", lchan->tch_mode); + return -EINVAL; } if (rc) {