view abis/main.c @ 32:94f11dc0d474

abis: Rx osmo_trau_sync hooked in
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Aug 2024 22:07:49 +0000
parents 5dd30224b70a
children
line wrap: on
line source

/*
 * This C module is the main for itt-abis-16, a test program for collecting
 * TRAU-UL captures from an E1 BTS.  This program operates on a single E1
 * timeslot on Abis and treats it as consisting of four 16 kbit/s subslots.
 *
 * This code is based on osmo-e1d-pipe,
 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>,
 * SPDX-License-Identifier: GPL-2.0+
 */

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <osmocom/core/talloc.h>
#include <osmocom/core/select.h>
#include <osmocom/core/application.h>
#include <osmocom/e1d/proto_clnt.h>
#include <osmocom/isdn/i460_mux.h>
#include <osmocom/trau/trau_sync.h>

#include "../libutil/open_ts.h"
#include "../libutil/stdin_handler.h"
#include "globals.h"
#include "submux.h"
#include "dl_frames.h"

void *g_ctx;
struct osmo_e1dp_client *g_client;
int ts_fd;
struct osmo_i460_timeslot i460_ts;
struct abis_subslot subslots[ABIS_SUBSLOTS];

static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
static const char *timeslot_spec;
static struct osmo_fd ts_ofd, stdin_ofd;

static void process_cmdline(int argc, char **argv)
{
	extern int optind;
	extern char *optarg;
	int c;

	while ((c = getopt(argc, argv, "p:")) != EOF) {
		switch (c) {
		case 'p':
			e1d_socket_path = optarg;
			continue;
		default:
		usage:
			fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n",
				argv[0]);
			exit(1);
		}
	}
	if (argc != optind + 1)
		goto usage;
	timeslot_spec = argv[optind];
}

static void register_subslots(void)
{
	int nr;
	struct osmo_i460_schan_desc chd;

	memset(&chd, 0, sizeof chd);
	chd.rate = OSMO_I460_RATE_16k;
	chd.demux.num_bits = 320;
	chd.demux.out_cb_bits = i460_rx_func;

	for (nr = 0; nr < ABIS_SUBSLOTS; nr++) {
		subslots[nr].nr = nr;
		chd.demux.user_data = subslots + nr;
		chd.mux.user_data = subslots + nr;
		subslots[nr].schan =
				osmo_i460_subchan_add(g_ctx, &i460_ts, &chd);
		OSMO_ASSERT(subslots[nr].schan);
		chd.bit_offset += 2;
	}
}

static void setup_rx_sync(void)
{
	int nr;

	for (nr = 0; nr < ABIS_SUBSLOTS; nr++) {
		subslots[nr].sync = osmo_trau_sync_alloc(g_ctx, "TRAU-UL-sync",
					sync_rx_func, OSMO_TRAU_SYNCP_16_FR_EFR,
					subslots + nr);
		OSMO_ASSERT(subslots[nr].sync);
	}
}

int main(int argc, char **argv)
{
	process_cmdline(argc, argv);
	g_ctx = talloc_named_const(NULL, 0, "g_ctx");
	OSMO_ASSERT(g_ctx);
	osmo_init_logging2(g_ctx, NULL);

	g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path);
	if (!g_client) {
		fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n",
			e1d_socket_path);
		exit(1);
	}
	ts_fd = open_e1d_ts(g_client, timeslot_spec);

	osmo_i460_ts_init(&i460_ts);
	register_subslots();
	setup_rx_sync();
	init_canned_dl_frames();

	osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0);
	OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0);

	osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb,
			handle_user_cmd, 0);
	OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0);

	while (1) {
		osmo_select_main(0);
	}
}