summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/transceiver/main.c
blob: 3b7281dd92dea3b8c5c8867586cec3395136e5fa (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * main.c
 *
 * Tranceiver main program
 *
 * Copyright (C) 2013  Sylvain Munaut <tnt@246tNt.com>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <string.h>

#include <osmocom/core/select.h>
#include <osmocom/core/talloc.h>

#include <osmocom/bb/common/logging.h>

#include "app.h"
#include "l1ctl.h"
#include "l1ctl_link.h"
#include "trx.h"
#include "gmsk.h"
#include "gsm_ab.h"


void *l23_ctx = NULL;


int main(int argc, char *argv[])
{
	struct app_state _as, *as = &_as;
	int rv;

	/* Options */
	if (argc != 2) {
		fprintf(stderr, "Usage: %s arfcn_sync\n", argv[0]);
		return -1;
	}

	/* App state init */
	memset(as, 0x00, sizeof(struct app_state));

	as->arfcn_sync = atoi(argv[1]);
	printf("%d\n", as->arfcn_sync);

	/* Init talloc */
	l23_ctx = talloc_named_const(NULL, 1, "l23 app context");

	/* Init logging */
	log_init(&log_info, l23_ctx);

	as->stderr_target = log_target_create_stderr();

	log_add_target(as->stderr_target);
	log_set_all_filter(as->stderr_target, 1);

	/* Init signal processing */
		/* Init GMSK tables */
	as->gs = osmo_gmsk_init(1);
	if (!as->gs)
		exit(-1);

		/* Init AB corr seq */
	as->train_ab = osmo_gmsk_trainseq_generate(as->gs, gsm_ab_train, GSM_AB_TRAIN_LEN);
	if (!as->train_ab)
		exit(-1);

	/* TRX interface with OpenBTS */
	as->trx = trx_alloc("127.0.0.1", 5700, &as->l1l);
	if (!as->trx)
		exit(-1);

	/* Establish l1ctl link */
	rv = l1l_open(&as->l1l, "/tmp/osmocom_l2", l1ctl_recv, as);
	if (rv)
		exit(-1);

	/* Reset phone */
	l1ctl_tx_reset_req(&as->l1l, L1CTL_RES_T_FULL);

	/* Main loop */
	while (1) {
		osmo_select_main(0);
	}

	return 0;
}