aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libbsc/bts_ericsson_rbs2000.c
blob: 28e7df4cce976713cc0a65406500d1332854f4fe (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* Ericsson RBS-2xxx specific code */

/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
 *
 * 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 <osmocom/gsm/tlv.h>

#include <openbsc/debug.h>
#include <openbsc/gsm_data.h>
#include <openbsc/abis_om2000.h>
#include <openbsc/abis_nm.h>
#include <osmocom/abis/e1_input.h>
#include <openbsc/signal.h>

#include <osmocom/abis/lapd.h>

static void bootstrap_om_bts(struct gsm_bts *bts)
{
	LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for BTS %u\n", bts->nr);
	abis_om2k_tx_start_req(bts, &om2k_mo_cf);
	/* FIXME */
}

static void bootstrap_om_trx(struct gsm_bts_trx *trx)
{
	struct abis_om2k_mo trx_mo = { OM2K_MO_CLS_TRXC, 0, 255, trx->nr };

	LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for TRX %u/%u\n",
	     trx->bts->nr, trx->nr);

	abis_om2k_tx_reset_cmd(trx->bts, &trx_mo);
}

static int shutdown_om(struct gsm_bts *bts)
{
	/* FIXME */
	return 0;
}


/* Tell LAPD to start start the SAP (send SABM requests) for all signalling
 * timeslots in this line */
static void start_sabm_in_line(struct e1inp_line *line, int start)
{
	struct e1inp_sign_link *link;
	int i;

	for (i = 0; i < ARRAY_SIZE(line->ts); i++) {
		struct e1inp_ts *ts = &line->ts[i];

		if (ts->type != E1INP_TS_TYPE_SIGN)
			continue;

		llist_for_each_entry(link, &ts->sign.sign_links, list) {
			if (start)
				lapd_sap_start(ts->driver.dahdi.lapd, link->tei, link->sapi);
			else
				lapd_sap_stop(ts->driver.dahdi.lapd, link->tei, link->sapi);
		}
	}
}

/* Callback function to be called every time we receive a signal from INPUT */
static int gbl_sig_cb(unsigned int subsys, unsigned int signal,
		      void *handler_data, void *signal_data)
{
	struct gsm_bts *bts;

	if (subsys != SS_L_GLOBAL)
		return 0;

	switch (signal) {
	case S_GLOBAL_BTS_CLOSE_OM:
		bts = signal_data;
		if (bts->type == GSM_BTS_TYPE_RBS2000)
			shutdown_om(signal_data);
		break;
	}

	return 0;
}

/* Callback function to be called every time we receive a signal from INPUT */
static int inp_sig_cb(unsigned int subsys, unsigned int signal,
		      void *handler_data, void *signal_data)
{
	struct input_signal_data *isd = signal_data;

	if (subsys != SS_L_INPUT)
		return 0;

	switch (signal) {
	case S_L_INP_TEI_UP:
		switch (isd->link_type) {
		case E1INP_SIGN_OML:
			if (isd->trx->bts->type != GSM_BTS_TYPE_RBS2000)
				break;
			if (isd->tei == isd->trx->bts->oml_tei)
				bootstrap_om_bts(isd->trx->bts);
			else
				bootstrap_om_trx(isd->trx);
			break;
		}
		break;
	case S_L_INP_LINE_INIT:
		/* Right now Ericsson RBS are only supported on DAHDI */
		if (strcasecmp(isd->line->driver->name, "DAHDI"))
			break;
		start_sabm_in_line(isd->line, 1);
		break;
	case S_L_INP_LINE_ALARM:
		if (strcasecmp(isd->line->driver->name, "DAHDI"))
			break;
		start_sabm_in_line(isd->line, 0);
		break;
	case S_L_INP_LINE_NOALARM:
		if (strcasecmp(isd->line->driver->name, "DAHDI"))
			break;
		start_sabm_in_line(isd->line, 1);
		break;
	}

	return 0;
}

static void nm_statechg_evt(unsigned int signal,
			    struct nm_statechg_signal_data *nsd)
{
	struct abis_om2k_mo mo;

	if (nsd->bts->type != GSM_BTS_TYPE_RBS2000)
		return;

	switch (nsd->om2k_mo->class) {
	case OM2K_MO_CLS_CF:
		if (nsd->new_state->operational != NM_OPSTATE_ENABLED ||
		    nsd->new_state->availability != OM2K_MO_S_STARTED)
			break;
		/* CF has started, we can trigger IS and TF start */
		abis_om2k_tx_connect_cmd(nsd->bts, &om2k_mo_is);
		abis_om2k_tx_connect_cmd(nsd->bts, &om2k_mo_tf);
		break;
	case OM2K_MO_CLS_IS:
		if (nsd->new_state->availability == OM2K_MO_S_ENABLED) {
			/* IS is enabled, we can proceed with TRXC/RX/TX/TS */
			break;
		}
		if (nsd->new_state->operational != NM_OPSTATE_ENABLED)
			break;
		/* IS has started, we can configure + enable it */
		abis_om2k_tx_is_conf_req(nsd->bts);
		break;
	case OM2K_MO_CLS_TF:
		if (nsd->new_state->operational != NM_OPSTATE_ENABLED ||
		    nsd->new_state->availability == OM2K_MO_S_DISABLED)
			break;
		if (nsd->new_state->availability == OM2K_MO_S_STARTED) {
			/* TF has started, configure + enable it */
			abis_om2k_tx_is_conf_req(nsd->bts);
		}
		break;
	case OM2K_MO_CLS_TRXC:
		if (nsd->new_state->availability != OM2K_MO_S_STARTED)
			break;
		/* TRXC is started, connect the TX and RX objects */
		memcpy(&mo, nsd->om2k_mo, sizeof(mo));
		mo.class = OM2K_MO_CLS_TX;
		abis_om2k_tx_connect_cmd(nsd->bts, &mo);
		mo.class = OM2K_MO_CLS_RX;
		abis_om2k_tx_connect_cmd(nsd->bts, &mo);
		break;
	case OM2K_MO_CLS_RX:
		if (nsd->new_state->operational != NM_OPSTATE_ENABLED ||
		    nsd->new_state->availability != OM2K_MO_S_STARTED)
			break;
		/* RX is started, configure + enable it */
		abis_om2k_tx_rx_conf_req(nsd->obj);
		break;
	case OM2K_MO_CLS_TX:
		if (nsd->new_state->operational != NM_OPSTATE_ENABLED ||
		    nsd->new_state->availability != OM2K_MO_S_STARTED)
			break;
		/* RX is started, configure + enable it */
		abis_om2k_tx_tx_conf_req(nsd->obj);
		break;
	}
}

static void nm_conf_res(struct nm_om2k_signal_data *nsd)
{
	switch (nsd->om2k_mo->class) {
	case OM2K_MO_CLS_IS:
	case OM2K_MO_CLS_TF:
	case OM2K_MO_CLS_RX:
	case OM2K_MO_CLS_TX:
		/* If configuration was a success, enable it */
		abis_om2k_tx_enable_req(nsd->bts, nsd->om2k_mo);
		break;
	}
}

static int nm_sig_cb(unsigned int subsys, unsigned int signal,
		     void *handler_data, void *signal_data)
{
	if (subsys != SS_NM)
		return 0;

	switch (signal) {
	case S_NM_STATECHG_OPER:
	case S_NM_STATECHG_ADM:
		nm_statechg_evt(signal, signal_data);
		break;
	case S_NM_OM2K_CONF_RES:
		nm_conf_res(signal_data);
		break;
	default:
		break;
	}

	return 0;
}

static void config_write_bts(struct vty *vty, struct gsm_bts *bts)
{
	abis_om2k_config_write_bts(vty, bts);
}

static int bts_model_rbs2k_start(struct gsm_network *net);

static void bts_model_rbs2k_e1line_bind_ops(struct e1inp_line *line)
{
	e1inp_line_bind_ops(line, &bts_isdn_e1inp_line_ops);
}

static struct gsm_bts_model model_rbs2k = {
	.type = GSM_BTS_TYPE_RBS2000,
	.name = "rbs2000",
	.start = bts_model_rbs2k_start,
	.oml_rcvmsg = &abis_om2k_rcvmsg,
	.config_write_bts = &config_write_bts,
	.e1line_bind_ops = &bts_model_rbs2k_e1line_bind_ops,
};

static int bts_model_rbs2k_start(struct gsm_network *net)
{
	model_rbs2k.features.data = &model_rbs2k._features_data[0];
	model_rbs2k.features.data_len = sizeof(model_rbs2k._features_data);

	gsm_btsmodel_set_feature(&model_rbs2k, BTS_FEAT_HOPPING);
	gsm_btsmodel_set_feature(&model_rbs2k, BTS_FEAT_HSCSD);

	osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL);
	osmo_signal_register_handler(SS_L_GLOBAL, gbl_sig_cb, NULL);
	osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL);

	return 0;
}

int bts_model_rbs2k_init(void)
{
	return gsm_bts_model_register(&model_rbs2k);
}