changeset 33:351bd801cdce

abis: should be complete now
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Aug 2024 22:53:42 +0000
parents 94f11dc0d474
children f0b026615f3b
files abis/submux.h abis/subslot_rx.c abis/tx_func.c
diffstat 3 files changed, 59 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/abis/submux.h	Tue Aug 13 22:07:49 2024 +0000
+++ b/abis/submux.h	Tue Aug 13 22:53:42 2024 +0000
@@ -16,10 +16,10 @@
 
 struct abis_subslot {
 	struct osmo_i460_subchan *schan;
+	struct osmo_fsm_inst *sync;
 	int nr;
-	bool is_active;
-	bool is_efr;
-	struct osmo_fsm_inst *sync;
+	bool got_sync;
+	uint8_t frame_type;
 };
 
 extern struct abis_subslot subslots[ABIS_SUBSLOTS];
--- a/abis/subslot_rx.c	Tue Aug 13 22:07:49 2024 +0000
+++ b/abis/subslot_rx.c	Tue Aug 13 22:53:42 2024 +0000
@@ -9,6 +9,7 @@
 #include <string.h>
 
 #include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
 #include <osmocom/isdn/i460_mux.h>
 #include <osmocom/trau/trau_sync.h>
 
@@ -23,9 +24,49 @@
 	osmo_trau_sync_rx_ubits(ab->sync, bits, num_bits);
 }
 
+static void sync_lost(struct abis_subslot *ab)
+{
+	if (!ab->got_sync)
+		return;
+	printf("Subslot %d lost frame sync\n", ab->nr);
+	ab->got_sync = false;
+}
+
+/* function copied from libosmo-abis/src/trau/trau_frame.c */
+static uint32_t get_bits(const ubit_t *bitbuf, int offset, int num)
+{
+	int i;
+	uint32_t ret = 0;
+
+	for (i = offset; i < offset + num; i++) {
+		ret = ret << 1;
+		if (bitbuf[i])
+			ret |= 1;
+	}
+	return ret;
+}
+
 void sync_rx_func(void *user_data, const ubit_t *bits, unsigned int num_bits)
 {
 	struct abis_subslot *ab = user_data;
-
+	uint8_t ft;
 
+	if (!bits) {
+		sync_lost(ab);
+		return;
+	}
+	OSMO_ASSERT(num_bits == 320);
+	ft = get_bits(bits, 17, 5);
+	if (!ab->got_sync) {
+		printf("Subslot %d got frame sync with FT=0x%02X\n",
+			ab->nr, ft);
+		ab->got_sync = true;
+		ab->frame_type = ft;
+		return;
+	}
+	if (ft == ab->frame_type)
+		return;
+	printf("Subslot %d changed frame type from 0x%02X to 0x%02X\n", ab->nr,
+		ab->frame_type, ft);
+	ab->frame_type = ft;
 }
--- a/abis/tx_func.c	Tue Aug 13 22:07:49 2024 +0000
+++ b/abis/tx_func.c	Tue Aug 13 22:53:42 2024 +0000
@@ -12,6 +12,7 @@
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/select.h>
 #include <osmocom/isdn/i460_mux.h>
+#include <osmocom/trau/trau_frame.h>
 
 #include "globals.h"
 #include "submux.h"
@@ -20,16 +21,27 @@
 static void tx_service_subslot(int nr)
 {
 	struct abis_subslot *ab = &subslots[nr];
+	const uint8_t *srcbuf;
 	struct msgb *msg;
 	uint8_t *outbuf;
 
-	if (!ab->is_active)
+	if (!ab->got_sync)
 		return;
+	switch (ab->frame_type) {
+	case TRAU_FT_FR_UP:
+		srcbuf = dl_frame_fr;
+		break;
+	case TRAU_FT_EFR:
+		srcbuf = dl_frame_efr;
+		break;
+	default:
+		return;
+	}
 	msg = msgb_alloc_c(g_ctx, DL_OUTPUT_LEN, "TRAU-DL-frame");
 	if (!msg)
 		return;
 	outbuf = msgb_put(msg, DL_OUTPUT_LEN);
-	memcpy(outbuf, ab->is_efr ? dl_frame_efr : dl_frame_fr, DL_OUTPUT_LEN);
+	memcpy(outbuf, srcbuf, DL_OUTPUT_LEN);
 	osmo_i460_mux_enqueue(ab->schan, msg);
 }