summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-12-14 04:03:59 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-03-14 22:22:43 +0700
commitd49a748cbbf7d7b5bb77f3d906179da9b462e6d1 (patch)
tree8ad25e1b207893cb28491f8878c70a8981fe8a56
parenta4d255269a7d4e58d2ec0fbb42483495b8c247c9 (diff)
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: I81ec8ed3c9e72a62b22c1720c299cdc68b733cf1
-rw-r--r--src/host/layer23/src/common/l1ctl.c39
-rw-r--r--src/target/firmware/Makefile3
-rw-r--r--src/target/firmware/layer1/prim_tch.c52
3 files changed, 54 insertions, 40 deletions
diff --git a/src/host/layer23/src/common/l1ctl.c b/src/host/layer23/src/common/l1ctl.c
index c90588ea..f4c214d4 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;
@@ -71,24 +70,6 @@ static struct msgb *osmo_l1_alloc(uint8_t msg_type)
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)
{
/* TODO: Include the band */
@@ -795,23 +776,12 @@ static int rx_l1_traffic_ind(struct osmocom_ms *ms, struct msgb *msg)
{
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));
/* distribute or drop */
@@ -834,8 +804,6 @@ int l1ctl_tx_traffic_req(struct osmocom_ms *ms, struct msgb *msg,
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;
@@ -857,13 +825,6 @@ int l1ctl_tx_traffic_req(struct osmocom_ms *ms, struct msgb *msg,
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 2ae2f4dc..22fa7461 100644
--- a/src/target/firmware/Makefile
+++ b/src/target/firmware/Makefile
@@ -102,7 +102,8 @@ ANY_APP_LIBS+= calypso/libcalypso.a \
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 a0a03b81..2dadaaf4 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 @@ static int l1s_tch_resp(__unused uint8_t p1, __unused uint8_t p2, uint16_t p3)
/* 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 @@ static int l1s_tch_cmd(__unused uint8_t p1, __unused uint8_t p2, uint16_t p3)
/* 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;