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
This commit is contained in:
Vadim Yanitskiy 2017-07-31 17:24:27 +06:00
parent f2179e6763
commit 0dc5b233e6
3 changed files with 122 additions and 59 deletions

View File

@ -31,6 +31,7 @@ trxcon_SOURCES = \
# Scheduler
trxcon_SOURCES += \
sched_lchan_common.c \
sched_lchan_desc.c \
sched_lchan_xcch.c \
sched_lchan_rach.c \

View File

@ -0,0 +1,114 @@
/*
* OsmocomBB <-> SDR connection bridge
* TDMA scheduler: common routines for lchan handlers
*
* (C) 2017 by Vadim Yanitskiy <axilirator@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;
}

View File

@ -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 @@ int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts,
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;