changeset 19:1e375472d5a5

ater: implement TRAU frame output
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Jun 2024 08:07:45 +0000
parents 61862af2247f
children 5405c1573027
files ater/globals.h ater/main.c ater/submux.h ater/tx_func.c
diffstat 4 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ater/globals.h	Mon Jun 24 07:26:20 2024 +0000
+++ b/ater/globals.h	Mon Jun 24 08:07:45 2024 +0000
@@ -2,6 +2,7 @@
 
 #pragma once
 
+extern void *g_ctx;
 extern struct osmo_e1dp_client *g_client;
 extern int ts_fd;
 extern struct osmo_i460_timeslot i460_ts;
--- a/ater/main.c	Mon Jun 24 07:26:20 2024 +0000
+++ b/ater/main.c	Mon Jun 24 08:07:45 2024 +0000
@@ -25,6 +25,7 @@
 #include "globals.h"
 #include "submux.h"
 
+void *g_ctx;
 struct osmo_e1dp_client *g_client;
 int ts_fd;
 struct osmo_i460_timeslot i460_ts;
@@ -32,7 +33,6 @@
 
 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
 static const char *timeslot_spec;
-static void *g_ctx;
 static struct osmo_fd ts_ofd, stdin_ofd;
 
 static void process_cmdline(int argc, char **argv)
--- a/ater/submux.h	Mon Jun 24 07:26:20 2024 +0000
+++ b/ater/submux.h	Mon Jun 24 08:07:45 2024 +0000
@@ -21,9 +21,12 @@
 	bool is_active;
 	bool is_efr;
 	struct osmo_trau_frame ul_frame;
+	unsigned mfrm_count;
 };
 
 extern struct ater_subslot subslots[ATER_SUBSLOTS];
 
 void i460_rx_func(struct osmo_i460_subchan *schan, void *user_data,
 		  const ubit_t *bits, unsigned int num_bits);
+
+void init_trau_ul_frame(int nr);
--- a/ater/tx_func.c	Mon Jun 24 07:26:20 2024 +0000
+++ b/ater/tx_func.c	Mon Jun 24 08:07:45 2024 +0000
@@ -9,16 +9,56 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <osmocom/core/msgb.h>
 #include <osmocom/core/select.h>
 #include <osmocom/isdn/i460_mux.h>
 
 #include "globals.h"
 #include "submux.h"
 
+void init_trau_ul_frame(int nr)
+{
+	struct ater_subslot *at = &subslots[nr];
+	struct osmo_trau_frame *fr = &at->ul_frame;
+
+	fr->type = at->is_efr ? OSMO_TRAU16_FT_EFR : OSMO_TRAU16_FT_FR;
+	fr->dir = OSMO_TRAU_DIR_UL;
+	memset(fr->c_bits + 5, 0, 6);
+	memset(fr->c_bits + 15, 1, 6);
+	memset(fr->t_bits, 1, 4);
+}
+
+static void tx_service_subslot(int nr)
+{
+	struct ater_subslot *at = &subslots[nr];
+	struct osmo_trau_frame *fr = &at->ul_frame;
+	struct msgb *msg;
+	int len;
+
+	if (!at->is_active)
+		return;
+	at->mfrm_count++;
+	if (at->mfrm_count >= 24) {
+		at->mfrm_count = 0;
+		fr->c_bits[14] = 1;
+	} else {
+		fr->c_bits[14] = 0;
+	}
+	msg = msgb_alloc_c(g_ctx, 640, "TRAU-UL-frame");
+	if (!msg)
+		return;
+	len = osmo_trau_frame_encode(msg->tail, msgb_tailroom(msg), fr);
+	msgb_put(msg, len);
+	osmo_i460_mux_enqueue(at->schan, msg);
+}
+
 void transmit_e1_ts(void)
 {
 	uint8_t buf[160];
+	int nr;
 
+	for (nr = 0; nr < ATER_SUBSLOTS; nr++)
+		tx_service_subslot(nr);
 	osmo_i460_mux_out(&i460_ts, buf, 160);
 	write(ts_fd, buf, 160);
 }