view abis/subslot_rx.c @ 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
line wrap: on
line source

/*
 * Here we are going to implement Abis subslot Rx.
 */

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#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>

#include "globals.h"
#include "submux.h"

void i460_rx_func(struct osmo_i460_subchan *schan, void *user_data,
		  const ubit_t *bits, unsigned int num_bits)
{
	struct abis_subslot *ab = user_data;

	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;
}