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

host/trxcon/scheduler: share common code for lchan handlers

The training sequences array is currently used by xCCH handlers,
but will be also used for handling both TCH/F and TCH/H bursts.
Moreover the code that forwards decoded L2 payloads to L1CTL
protocol handlers was separated into a new shared function.

Change-Id: I34c3de351362ebd9a070f49bb78d7bd976784b04
---
M src/host/trxcon/Makefile.am
A src/host/trxcon/sched_lchan_common.c
M src/host/trxcon/sched_lchan_xcch.c
3 files changed, 122 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/63/6763/1

diff --git a/src/host/trxcon/Makefile.am b/src/host/trxcon/Makefile.am
index cd4bbd2..90c7a3c 100644
--- a/src/host/trxcon/Makefile.am
+++ b/src/host/trxcon/Makefile.am
@@ -31,6 +31,7 @@
 
 # Scheduler
 trxcon_SOURCES += \
+       sched_lchan_common.c \
        sched_lchan_desc.c \
        sched_lchan_xcch.c \
        sched_lchan_rach.c \
diff --git a/src/host/trxcon/sched_lchan_common.c 
b/src/host/trxcon/sched_lchan_common.c
new file mode 100644
index 0000000..7dad750
--- /dev/null
+++ b/src/host/trxcon/sched_lchan_common.c
@@ -0,0 +1,114 @@
+/*
+ * OsmocomBB <-> SDR connection bridge
+ * TDMA scheduler: common routines for lchan handlers
+ *
+ * (C) 2017 by Vadim Yanitskiy <axilira...@gmail.com>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <talloc.h>
+#include <stdint.h>
+
+#include <arpa/inet.h>
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/bits.h>
+
+#include "l1ctl_proto.h"
+#include "scheduler.h"
+#include "sched_trx.h"
+#include "logging.h"
+#include "trx_if.h"
+#include "trxcon.h"
+#include "l1ctl.h"
+
+/* GSM 05.02 Chapter 5.2.3 Normal Burst (NB) */
+const uint8_t nb_training_bits[8][26] = {
+       {
+               0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0,
+               0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1,
+       },
+       {
+               0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1,
+               1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1,
+       },
+       {
+               0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1,
+               0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
+       },
+       {
+               0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0,
+               1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0,
+       },
+       {
+               0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0,
+               1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
+       },
+       {
+               0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0,
+               0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0,
+       },
+       {
+               1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1,
+               0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1,
+       },
+       {
+               1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0,
+               0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0,
+       },
+};
+
+int sched_send_data_ind(struct trx_instance *trx, struct trx_ts *ts,
+       struct trx_lchan_state *lchan, uint8_t *l2, size_t l2_len)
+{
+       const struct trx_lchan_desc *lchan_desc;
+       struct l1ctl_info_dl *data;
+
+       /* Allocate memory */
+       data = talloc_zero_size(ts, sizeof(struct l1ctl_info_dl) + l2_len);
+       if (data == NULL)
+               return -ENOMEM;
+
+       /* Set up pointers */
+       lchan_desc = &trx_lchan_desc[lchan->type];
+
+       /* Fill in known downlink info */
+       data->chan_nr = lchan_desc->chan_nr | ts->index;
+       data->link_id = lchan_desc->link_id;
+       data->band_arfcn = htons(trx->band_arfcn);
+       data->frame_nr = htonl(lchan->rx_first_fn);
+       data->rx_level = -(lchan->rssi_sum / lchan->rssi_num);
+
+       /* FIXME: set proper values */
+       data->num_biterr = 0;
+       data->fire_crc = 0;
+       data->snr = 0;
+
+       /* Fill in the payload */
+       memcpy(data->payload, l2, l2_len);
+
+       /* Put a packet to higher layers */
+       l1ctl_tx_data_ind(trx->l1l, data, l2_len == 23 ?
+               L1CTL_DATA_IND : L1CTL_TRAFFIC_IND);
+       talloc_free(data);
+
+       return 0;
+}
diff --git a/src/host/trxcon/sched_lchan_xcch.c 
b/src/host/trxcon/sched_lchan_xcch.c
index 9a7a09b..ad4c971 100644
--- a/src/host/trxcon/sched_lchan_xcch.c
+++ b/src/host/trxcon/sched_lchan_xcch.c
@@ -46,41 +46,11 @@
 #include "trxcon.h"
 #include "l1ctl.h"
 
-/* GSM 05.02 Chapter 5.2.3 Normal Burst (NB) */
-static const uint8_t nb_training_bits[8][26] = {
-       {
-               0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0,
-               0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1,
-       },
-       {
-               0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1,
-               1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1,
-       },
-       {
-               0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1,
-               0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
-       },
-       {
-               0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0,
-               1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0,
-       },
-       {
-               0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0,
-               1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
-       },
-       {
-               0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0,
-               0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0,
-       },
-       {
-               1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1,
-               0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1,
-       },
-       {
-               1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0,
-               0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0,
-       },
-};
+/* Forward declarations */
+extern const uint8_t nb_training_bits[8][26];
+
+int sched_send_data_ind(struct trx_instance *trx, struct trx_ts *ts,
+       struct trx_lchan_state *lchan, uint8_t *l2, size_t l2_len);
 
 int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
        struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid,
@@ -159,30 +129,8 @@
                return rc;
        }
 
-       /* Compose a message to the higher layers */
-       struct l1ctl_info_dl *data;
-       data = talloc_zero_size(ts, sizeof(struct l1ctl_info_dl) + 23);
-       if (data == NULL)
-               return -ENOMEM;
-
-       /* Fill in some downlink info */
-       data->chan_nr = lchan_desc->chan_nr | ts->index;
-       data->link_id = lchan_desc->link_id;
-       data->band_arfcn = htons(trx->band_arfcn);
-       data->frame_nr = htonl(*first_fn);
-       data->rx_level = -(*rssi_sum / *rssi_num);
-
-       /* FIXME: set proper values */
-       data->num_biterr = n_errors;
-       data->fire_crc = 0;
-       data->snr = 0;
-
-       /* Fill in decoded payload */
-       memcpy(data->payload, l2, 23);
-
-       /* Put a packet to higher layers */
-       l1ctl_tx_data_ind(trx->l1l, data, L1CTL_DATA_IND);
-       talloc_free(data);
+       /* Send a L2 frame to the higher layers */
+       sched_send_data_ind(trx, ts, lchan, l2, 23);
 
        /* TODO: AGC, TA loops */
        return 0;

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

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

Reply via email to