summaryrefslogtreecommitdiff
path: root/gsm-receiver/src/lib/decoder/interleave.c
blob: 8d112868d79d274cd1252a8f0b692792b39e21b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//TODO: this file shouldn't be part of the GSM Receiver
#include <stdlib.h>
#include <stdio.h>
#include "interleave.h"

int
interleave_init(INTERLEAVE_CTX *ictx, int size, int block_size)
{
	ictx->trans_size = size;
	ictx->trans = (unsigned short *)malloc(size * sizeof *ictx->trans);

//	DEBUGF("size: %d\n", size);
//	DEBUGF("Block size: %d\n", block_size);
	int j, k, B;
	for (k = 0; k < size; k++)
	{
		B = k % 4;
		j = 2 * ((49 * k) % 57) + ((k % 8) / 4);
		ictx->trans[k] = B * block_size + j;
		/* Mapping: pos1 goes to pos2: pos1 -> pos2 */
//		DEBUGF("%d -> %d\n", ictx->trans[k], k);
	}
//	exit(0);
	return 0;
}

int
interleave_init_facch_f(INTERLEAVE_CTX *ictx, int size, int block_size, int block_offset)
{
	ictx->trans_size = size;
	ictx->trans = (unsigned short *)malloc(size * sizeof *ictx->trans);

//	DEBUGF("size: %d\n", size);
//	DEBUGF("Block size: %d\n", block_size);
	int j, k, B;
	for (k = 0; k < size; k++)
	{
		B = (k + block_offset) % 8;
		j = 2 * ((49 * k) % 57) + ((k % 8) / 4);
		ictx->trans[k] = B * block_size + j;
		/* Mapping: pos1 goes to pos2: pos1 -> pos2 */
//		DEBUGF("%d -> %d\n", ictx->trans[k], k);
	}
//	exit(0);
	return 0;
}

int
interleave_deinit(INTERLEAVE_CTX *ictx)
{
	if (ictx->trans != NULL)
	{
		free(ictx->trans);
		ictx->trans = NULL;
	}

	return 0;
}

void
interleave_decode(INTERLEAVE_CTX *ictx, unsigned char *dst, unsigned char *src)
{

	int k;
	for (k = 0; k < ictx->trans_size; k++)
		dst[k] = src[ictx->trans[k]];
}

personal git repositories of Harald Welte. Your mileage may vary