summaryrefslogtreecommitdiff
path: root/gsm-tvoid/src/lib/gsmstack.c
blob: 9fc4868d38c630ab1f86736afde768eb713187d5 (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
69
70
71
72
73
74
/*
 * Invoke gsmstack() with any kind of burst. Automaticly decode and retrieve
 * information.
 */
#include "system.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gsmstack.h"
#include "gsm_constants.h"
#include "interleave.h"
#include "sch.h"

INTERLEAVE_CTX ictx;

static void
diff_decode(char *dst, char *src, int len)
{
	const unsigned char *end = src + len;
	unsigned char last;

	src += 3;
	last = 0;
	memset(dst, 0, 3);
	dst += 3;

	while (src < end)
	{
		*dst = !*src ^ last;
		last = *dst;
		src++;
		dst++;
	}
}

/*
 * Initialize a new GSMSTACK context.
 */
int
GS_new(GS_CTX *ctx)
{
	memset(ctx, 0, sizeof *ctx);
	interleave_init(&ictx, 456, 114);

	return 0;
}

/*
 * 156 bit
 */
int
GS_process(GS_CTX *ctx, int ts, int type, char *data)
{
	int fn;
	int bsic;
	int ret;
	char buf[156];

	diff_decode(buf, data, 156);

	switch (type)
	{
	case SCH:
		ret = decode_sch(buf, &fn, &bsic);
		if (ret != 0)
			break;
		DEBUGF("FN %d, BSIC %d\n", fn, bsic);
		break;
	case NORMAL:
		break;
	}
}


personal git repositories of Harald Welte. Your mileage may vary