[PATCH] osmocom-bb[master]: common/l1ctl.c move TCH bit-ordering to the firmware

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Feb 22 15:33:31 UTC 2018


Review at  https://gerrit.osmocom.org/6801

common/l1ctl.c move TCH bit-ordering to the firmware

Previously, TCH frames coming from L1 were reordered to the RTP
format. Moreover, the implementation had a few problems:

  - L1CTL is not the best place for such manipulations;
  - payloads with other than FR codec were corrupted.

Let's use RTP-ordered payloads on the L1CTL interface,
performing TCH frame reordering at the firmware.

Please note, that actual FR reordering was moved to the firmware
as is, without any codec determination. This could be fixed in
a separate change.

Change-Id: I235a9f535c39d8e57f5d2c6566daeaf883aeef9e
---
M src/host/layer23/src/common/l1ctl.c
M src/target/firmware/Makefile
M src/target/firmware/layer1/prim_tch.c
3 files changed, 54 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/01/6801/1

diff --git a/src/host/layer23/src/common/l1ctl.c b/src/host/layer23/src/common/l1ctl.c
index c75872e..3e642df 100644
--- a/src/host/layer23/src/common/l1ctl.c
+++ b/src/host/layer23/src/common/l1ctl.c
@@ -47,7 +47,6 @@
 #include <osmocom/bb/common/l1l2_interface.h>
 #include <osmocom/gsm/lapdm.h>
 #include <osmocom/bb/common/logging.h>
-#include <osmocom/codec/codec.h>
 
 extern struct gsmtap_inst *gsmtap_inst;
 
@@ -70,24 +69,6 @@
 	
 	return msg;
 }
-
-
-static inline int msb_get_bit(uint8_t *buf, int bn)
-{
-	int pos_byte = bn >> 3;
-	int pos_bit  = 7 - (bn & 7);
-
-	return (buf[pos_byte] >> pos_bit) & 1;
-}
-
-static inline void msb_set_bit(uint8_t *buf, int bn, int bit)
-{
-	int pos_byte = bn >> 3;
-	int pos_bit  = 7 - (bn & 7);
-
-	buf[pos_byte] |=  (bit << pos_bit);
-}
-
 
 static int osmo_make_band_arfcn(struct osmocom_ms *ms, uint16_t arfcn)
 {
@@ -791,22 +772,11 @@
 {
 	struct l1ctl_info_dl *dl;
 	struct l1ctl_traffic_ind *ti;
-	uint8_t fr[33];
-	int i, di, si;
 
 	/* Header handling */
 	dl = (struct l1ctl_info_dl *) msg->l1h;
 	msg->l2h = dl->payload;
 	ti = (struct l1ctl_traffic_ind *) msg->l2h;
-
-	memset(fr, 0x00, 33);
-	fr[0] = 0xd0;
-	for (i = 0; i < 260; i++) {
-		di = gsm610_bitorder[i];
-		si = (i > 181) ? i + 4 : i;
-		msb_set_bit(fr, 4 + di, msb_get_bit(ti->data, si));
-        }
-	memcpy(ti->data, fr, 33);
 
 	DEBUGP(DL1C, "TRAFFIC IND (%s)\n", osmo_hexdump(ti->data, 33));
 
@@ -830,8 +800,6 @@
 	struct l1ctl_hdr *l1h;
 	struct l1ctl_info_ul *l1i_ul;
 	struct l1ctl_traffic_req *tr;
-	uint8_t fr[33];
-	int i, di, si;
 
 	/* Header handling */
 	tr = (struct l1ctl_traffic_req *) msg->l2h;
@@ -853,13 +821,6 @@
 		return -EINVAL;
 	}
 
-	memset(fr, 0x00, 33);
-	for (i = 0; i < 260; i++) {
-		si = gsm610_bitorder[i];
-		di = (i > 181) ? i + 4 : i;
-		msb_set_bit(fr, di, msb_get_bit(tr->data, 4 + si));
-        }
-	memcpy(tr->data, fr, 33);
 //	printf("TX %s\n", osmo_hexdump(tr->data, 33));
 
 	/* prepend uplink info header */
diff --git a/src/target/firmware/Makefile b/src/target/firmware/Makefile
index 2ae2f4d..22fa746 100644
--- a/src/target/firmware/Makefile
+++ b/src/target/firmware/Makefile
@@ -102,7 +102,8 @@
 		lib/libmini.a \
 		comm/libcomm.a \
 		../../shared/libosmocore/build-target/src/.libs/libosmocore.a \
-		../../shared/libosmocore/build-target/src/gsm/.libs/libosmogsm.a
+		../../shared/libosmocore/build-target/src/gsm/.libs/libosmogsm.a \
+		../../shared/libosmocore/build-target/src/codec/.libs/libosmocodec.a
 
 
 #
diff --git a/src/target/firmware/layer1/prim_tch.c b/src/target/firmware/layer1/prim_tch.c
index a0a03b8..2dadaaf 100644
--- a/src/target/firmware/layer1/prim_tch.c
+++ b/src/target/firmware/layer1/prim_tch.c
@@ -32,6 +32,7 @@
 #include <byteorder.h>
 #include <osmocom/gsm/gsm_utils.h>
 #include <osmocom/gsm/protocol/gsm_04_08.h>
+#include <osmocom/codec/codec.h>
 #include <osmocom/core/msgb.h>
 #include <calypso/dsp_api.h>
 #include <calypso/irq.h>
@@ -55,6 +56,44 @@
 
 #include <l1ctl_proto.h>
 
+static inline int msb_get_bit(uint8_t *buf, int bn)
+{
+	int pos_byte = bn >> 3;
+	int pos_bit  = 7 - (bn & 7);
+
+	return (buf[pos_byte] >> pos_bit) & 1;
+}
+
+static inline void msb_set_bit(uint8_t *buf, int bn, int bit)
+{
+	int pos_byte = bn >> 3;
+	int pos_bit  = 7 - (bn & 7);
+
+	buf[pos_byte] |=  (bit << pos_bit);
+}
+
+static void tch_fr_bit_magic(uint8_t *frame, int dl)
+{
+	uint8_t fr[33];
+	int i, di, si;
+
+	memset(fr, 0x00, 33);
+
+	if (dl)
+		fr[0] = 0xd0;
+
+	for (i = 0; i < 260; i++) {
+		di = gsm610_bitorder[i];
+		si = (i > 181) ? i + 4 : i;
+
+		if (dl)
+			msb_set_bit(fr, 4 + di, msb_get_bit(frame, si));
+		else
+			msb_set_bit(fr, si, msb_get_bit(frame, 4 + di));
+	}
+
+	memcpy(frame, fr, 33);
+}
 
 /* This computes various parameters both for the DSP and for
  * our logic. Not all are used all the time, but it's easier
@@ -314,6 +353,12 @@
 				/* Copy actual data, skipping the information block [0,1,2] */
 				dsp_memcpy_from_api(ti->data, &traffic_buf[3], 33, 1);
 
+				/**
+				 * Perform some bit conversations
+				 * FIXME: what about other (than FR) codecs?
+				 */
+				tch_fr_bit_magic(ti, 1);
+
 				/* Give message to up layer */
 				l1_queue_for_l2(msg);
 			}
@@ -440,6 +485,13 @@
 		/* Pull Traffic data (if any) */
 		msg = msgb_dequeue(&l1s.tx_queue[L1S_CHAN_TRAFFIC]);
 
+		/**
+		 * Perform some bit conversations
+		 * FIXME: what about other (than FR) codecs?
+		 */
+		if (msg)
+			tch_fr_bit_magic(msg->l2h, 0);
+
 		/* Copy actual data, skipping the information block [0,1,2] */
 		if (msg) {
 			data = msg->l2h;

-- 
To view, visit https://gerrit.osmocom.org/6801
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I235a9f535c39d8e57f5d2c6566daeaf883aeef9e
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list