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

host/trxcon/scheduler: implement SCH decoding

Change-Id: Ic5e7416271d647752cd1aaf90de51fa48286798e
---
M src/host/trxcon/sched_lchan_desc.c
M src/host/trxcon/sched_lchan_handlers.c
2 files changed, 73 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/97/6697/1

diff --git a/src/host/trxcon/sched_lchan_desc.c 
b/src/host/trxcon/sched_lchan_desc.c
index 93927a6..1ff6e14 100644
--- a/src/host/trxcon/sched_lchan_desc.c
+++ b/src/host/trxcon/sched_lchan_desc.c
@@ -44,6 +44,10 @@
        uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
        sbit_t *bits, uint16_t nbits, int8_t rssi, float toa);
 
+int rx_sch_fn(struct trx_instance *trx, struct trx_ts *ts,
+       uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
+       sbit_t *bits, uint16_t nbits, int8_t rssi, float toa);
+
 const struct trx_lchan_desc trx_lchan_desc[_TRX_CHAN_MAX] = {
        {
                TRXC_IDLE,              "IDLE",
@@ -69,8 +73,11 @@
                0x00,                   LID_DEDIC,
                0x00,                   0x00,
 
-               /* We already have clock indications from TRX */
-               NULL,                   NULL,
+               /**
+                * We already have clock indications from TRX,
+                * but we also need BSIC (BCC / NCC) value.
+                */
+               rx_sch_fn,              NULL,
        },
        {
                TRXC_BCCH,              "BCCH",
diff --git a/src/host/trxcon/sched_lchan_handlers.c 
b/src/host/trxcon/sched_lchan_handlers.c
index 2c2cb6a..41e60d8 100644
--- a/src/host/trxcon/sched_lchan_handlers.c
+++ b/src/host/trxcon/sched_lchan_handlers.c
@@ -34,6 +34,7 @@
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/fsm.h>
 
+#include <osmocom/gsm/gsm_utils.h>
 #include <osmocom/coding/gsm0503_coding.h>
 
 #include "l1ctl_proto.h"
@@ -159,3 +160,66 @@
        /* TODO: AGC, TA loops */
        return 0;
 }
+
+static void decode_sb(struct gsm_time *time, uint8_t *bsic, uint8_t *sb_info)
+{
+       uint8_t t3p;
+       uint32_t sb;
+
+       sb = (sb_info[3] << 24)
+          | (sb_info[2] << 16)
+          | (sb_info[1] << 8)
+          | sb_info[0];
+
+       *bsic = (sb >> 2) & 0x3f;
+
+       /* TS 05.02 Chapter 3.3.2.2.1 SCH Frame Numbers */
+       time->t1 = ((sb >> 23) & 0x01)
+                | ((sb >> 7) & 0x1fe)
+                | ((sb << 9) & 0x600);
+
+       time->t2 = (sb >> 18) & 0x1f;
+
+       t3p = ((sb >> 24) & 0x01) | ((sb >> 15) & 0x06);
+       time->t3 = t3p * 10 + 1;
+
+       /* TS 05.02 Chapter 4.3.3 TDMA frame number */
+       time->fn = gsm_gsmtime2fn(time);
+}
+
+int rx_sch_fn(struct trx_instance *trx, struct trx_ts *ts,
+       uint32_t fn, enum trx_lchan_type chan, uint8_t bid,
+       sbit_t *bits, uint16_t nbits, int8_t rssi, float toa)
+{
+       sbit_t payload[2 * 39];
+       struct gsm_time time;
+       uint8_t sb_info[4];
+       uint8_t bsic;
+       int rc;
+
+       /* Obtain payload from burst */
+       memcpy(payload, bits + 3, 39);
+       memcpy(payload + 39, bits + 3 + 39 + 64, 39);
+
+       /* Attempt to decode */
+       rc = gsm0503_sch_decode(sb_info, payload);
+       if (rc) {
+               LOGP(DSCH, LOGL_DEBUG, "Received bad SCH burst at fn=%u\n", fn);
+               return rc;
+       }
+
+       /* Decode BSIC and TDMA frame number */
+       decode_sb(&time, &bsic, sb_info);
+
+       LOGP(DSCH, LOGL_DEBUG, "Received SCH: bsic=%u, fn=%u, sched_fn=%u\n",
+               bsic, time.fn, trx->sched.fn_counter_proc);
+
+       /* Check if decoded frame number matches */
+       if (time.fn != fn) {
+               LOGP(DSCH, LOGL_ERROR, "Decoded fn=%u does not match "
+                       "fn=%u provided by scheduler\n", time.fn, fn);
+               return -EINVAL;
+       }
+
+       return 0;
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5e7416271d647752cd1aaf90de51fa48286798e
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>

Reply via email to