summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-07-07 07:11:26 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-10-23 22:05:49 +0330
commit52fd453181ce320cd426fe113b21e16e6b8b9cba (patch)
treeff4bc9396d0bc45c12763ad8ba913aad7545ad3f
parent6bf0111d387dabe70955a153efbd307fd4e68753 (diff)
host/trxcon/scheduler: implement SCH decoding
-rw-r--r--src/host/trxcon/sched_lchan_desc.c11
-rw-r--r--src/host/trxcon/sched_lchan_handlers.c64
2 files changed, 73 insertions, 2 deletions
diff --git a/src/host/trxcon/sched_lchan_desc.c b/src/host/trxcon/sched_lchan_desc.c
index 93927a63..1ff6e144 100644
--- a/src/host/trxcon/sched_lchan_desc.c
+++ b/src/host/trxcon/sched_lchan_desc.c
@@ -44,6 +44,10 @@ int rx_data_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);
+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 @@ const struct trx_lchan_desc trx_lchan_desc[_TRX_CHAN_MAX] = {
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 2c2cb6a7..41e60d8b 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 @@ int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
/* 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;
+}