blob: 7ece94ee1c1bfad090f04fe6513093056e002eee [file] [log] [blame]
Harald Welte39315c42010-01-10 18:01:52 +01001/* ip.access nanoBTS specific code */
2
3/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
Harald Welte39315c42010-01-10 18:01:52 +010010 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte39315c42010-01-10 18:01:52 +010016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte39315c42010-01-10 18:01:52 +010019 *
20 */
21
Harald Weltef338a032011-01-14 15:55:42 +010022#include <arpa/inet.h>
23
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010024#include <osmocom/gsm/tlv.h>
Harald Welte39315c42010-01-10 18:01:52 +010025
26#include <openbsc/gsm_data.h>
Harald Weltef338a032011-01-14 15:55:42 +010027#include <openbsc/signal.h>
Harald Welte39315c42010-01-10 18:01:52 +010028#include <openbsc/abis_nm.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020029#include <osmocom/abis/e1_input.h>
30#include <osmocom/gsm/tlv.h>
31#include <osmocom/core/msgb.h>
32#include <osmocom/core/talloc.h>
33#include <openbsc/gsm_data.h>
34#include <openbsc/abis_nm.h>
35#include <openbsc/abis_rsl.h>
36#include <openbsc/debug.h>
37#include <osmocom/abis/subchan_demux.h>
38#include <osmocom/abis/ipaccess.h>
39#include <osmocom/core/logging.h>
Pablo Neira Ayuso0d2881a2011-05-14 11:32:48 +020040
41static int bts_model_nanobts_start(struct gsm_network *net);
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020042static void bts_model_nanobts_e1line_bind_ops(struct e1inp_line *line);
Harald Welte39315c42010-01-10 18:01:52 +010043
44static struct gsm_bts_model model_nanobts = {
45 .type = GSM_BTS_TYPE_NANOBTS,
Harald Welte09cefee2011-02-12 12:29:21 +010046 .name = "nanobts",
Pablo Neira Ayuso0d2881a2011-05-14 11:32:48 +020047 .start = bts_model_nanobts_start,
Harald Welte09cefee2011-02-12 12:29:21 +010048 .oml_rcvmsg = &abis_nm_rcvmsg,
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020049 .e1line_bind_ops = bts_model_nanobts_e1line_bind_ops,
Harald Welte39315c42010-01-10 18:01:52 +010050 .nm_att_tlvdef = {
51 .def = {
52 /* ip.access specifics */
53 [NM_ATT_IPACC_DST_IP] = { TLV_TYPE_FIXED, 4 },
54 [NM_ATT_IPACC_DST_IP_PORT] = { TLV_TYPE_FIXED, 2 },
55 [NM_ATT_IPACC_STREAM_ID] = { TLV_TYPE_TV, },
Harald Welte39315c42010-01-10 18:01:52 +010056 [NM_ATT_IPACC_SEC_OML_CFG] = { TLV_TYPE_FIXED, 6 },
57 [NM_ATT_IPACC_IP_IF_CFG] = { TLV_TYPE_FIXED, 8 },
58 [NM_ATT_IPACC_IP_GW_CFG] = { TLV_TYPE_FIXED, 12 },
59 [NM_ATT_IPACC_IN_SERV_TIME] = { TLV_TYPE_FIXED, 4 },
60 [NM_ATT_IPACC_LOCATION] = { TLV_TYPE_TL16V },
61 [NM_ATT_IPACC_PAGING_CFG] = { TLV_TYPE_FIXED, 2 },
62 [NM_ATT_IPACC_UNIT_ID] = { TLV_TYPE_TL16V },
63 [NM_ATT_IPACC_UNIT_NAME] = { TLV_TYPE_TL16V },
64 [NM_ATT_IPACC_SNMP_CFG] = { TLV_TYPE_TL16V },
65 [NM_ATT_IPACC_PRIM_OML_CFG_LIST] = { TLV_TYPE_TL16V },
66 [NM_ATT_IPACC_NV_FLAGS] = { TLV_TYPE_TL16V },
67 [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_FIXED, 2 },
68 [NM_ATT_IPACC_PRIM_OML_FB_TOUT] = { TLV_TYPE_TL16V },
69 [NM_ATT_IPACC_CUR_SW_CFG] = { TLV_TYPE_TL16V },
70 [NM_ATT_IPACC_TIMING_BUS] = { TLV_TYPE_TL16V },
71 [NM_ATT_IPACC_CGI] = { TLV_TYPE_TL16V },
72 [NM_ATT_IPACC_RAC] = { TLV_TYPE_TL16V },
73 [NM_ATT_IPACC_OBJ_VERSION] = { TLV_TYPE_TL16V },
74 [NM_ATT_IPACC_GPRS_PAGING_CFG]= { TLV_TYPE_TL16V },
75 [NM_ATT_IPACC_NSEI] = { TLV_TYPE_TL16V },
76 [NM_ATT_IPACC_BVCI] = { TLV_TYPE_TL16V },
77 [NM_ATT_IPACC_NSVCI] = { TLV_TYPE_TL16V },
78 [NM_ATT_IPACC_NS_CFG] = { TLV_TYPE_TL16V },
79 [NM_ATT_IPACC_BSSGP_CFG] = { TLV_TYPE_TL16V },
80 [NM_ATT_IPACC_NS_LINK_CFG] = { TLV_TYPE_TL16V },
81 [NM_ATT_IPACC_RLC_CFG] = { TLV_TYPE_TL16V },
82 [NM_ATT_IPACC_ALM_THRESH_LIST]= { TLV_TYPE_TL16V },
83 [NM_ATT_IPACC_MONIT_VAL_LIST] = { TLV_TYPE_TL16V },
84 [NM_ATT_IPACC_TIB_CONTROL] = { TLV_TYPE_TL16V },
85 [NM_ATT_IPACC_SUPP_FEATURES] = { TLV_TYPE_TL16V },
86 [NM_ATT_IPACC_CODING_SCHEMES] = { TLV_TYPE_TL16V },
87 [NM_ATT_IPACC_RLC_CFG_2] = { TLV_TYPE_TL16V },
88 [NM_ATT_IPACC_HEARTB_TOUT] = { TLV_TYPE_TL16V },
89 [NM_ATT_IPACC_UPTIME] = { TLV_TYPE_TL16V },
90 [NM_ATT_IPACC_RLC_CFG_3] = { TLV_TYPE_TL16V },
91 [NM_ATT_IPACC_SSL_CFG] = { TLV_TYPE_TL16V },
92 [NM_ATT_IPACC_SEC_POSSIBLE] = { TLV_TYPE_TL16V },
93 [NM_ATT_IPACC_IML_SSL_STATE] = { TLV_TYPE_TL16V },
94 [NM_ATT_IPACC_REVOC_DATE] = { TLV_TYPE_TL16V },
95 },
96 },
97};
98
Harald Weltef338a032011-01-14 15:55:42 +010099static unsigned char nanobts_attr_bts[] = {
100 NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73,
101 /* interference avg. period in numbers of SACCH multifr */
102 NM_ATT_INTAVE_PARAM, 0x06,
103 /* conn fail based on SACCH error rate */
104 NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10,
105 NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8,
106 NM_ATT_MAX_TA, 0x3f,
107 NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */
108 NM_ATT_CCCH_L_T, 10, /* percent */
109 NM_ATT_CCCH_L_I_P, 1, /* seconds */
110 NM_ATT_RACH_B_THRESH, 10, /* busy threshold in - dBm */
111 NM_ATT_LDAVG_SLOTS, 0x03, 0xe8, /* rach load averaging 1000 slots */
112 NM_ATT_BTS_AIR_TIMER, 128, /* miliseconds */
113 NM_ATT_NY1, 10, /* 10 retransmissions of physical config */
114 NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
115 NM_ATT_BSIC, HARDCODED_BSIC,
Harald Weltee86b3eb2011-06-27 21:15:59 +0200116 NM_ATT_IPACC_CGI, 0, 7, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x00, 0x00,
Harald Weltef338a032011-01-14 15:55:42 +0100117};
118
119static unsigned char nanobts_attr_radio[] = {
120 NM_ATT_RF_MAXPOWR_R, 0x0c, /* number of -2dB reduction steps / Pn */
121 NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff,
122};
123
124static unsigned char nanobts_attr_nse[] = {
125 NM_ATT_IPACC_NSEI, 0, 2, 0x03, 0x9d, /* NSEI 925 */
126 NM_ATT_IPACC_NS_CFG, 0, 7, 3, /* (un)blocking timer (Tns-block) */
127 3, /* (un)blocking retries */
128 3, /* reset timer (Tns-reset) */
129 3, /* reset retries */
130 30, /* test timer (Tns-test) */
131 3, /* alive timer (Tns-alive) */
132 10, /* alive retrires */
133 NM_ATT_IPACC_BSSGP_CFG, 0, 11,
134 3, /* blockimg timer (T1) */
135 3, /* blocking retries */
136 3, /* unblocking retries */
137 3, /* reset timer */
138 3, /* reset retries */
139 10, /* suspend timer (T3) in 100ms */
140 3, /* suspend retries */
141 10, /* resume timer (T4) in 100ms */
142 3, /* resume retries */
143 10, /* capability update timer (T5) */
144 3, /* capability update retries */
145};
146
147static unsigned char nanobts_attr_cell[] = {
148 NM_ATT_IPACC_RAC, 0, 1, 1, /* routing area code */
149 NM_ATT_IPACC_GPRS_PAGING_CFG, 0, 2,
150 5, /* repeat time (50ms) */
151 3, /* repeat count */
152 NM_ATT_IPACC_BVCI, 0, 2, 0x03, 0x9d, /* BVCI 925 */
153 NM_ATT_IPACC_RLC_CFG, 0, 9,
154 20, /* T3142 */
155 5, /* T3169 */
156 5, /* T3191 */
157 200, /* T3193 */
158 5, /* T3195 */
159 10, /* N3101 */
160 4, /* N3103 */
161 8, /* N3105 */
162 15, /* RLC CV countdown */
163 NM_ATT_IPACC_CODING_SCHEMES, 0, 2, 0x0f, 0x00, /* CS1..CS4 */
164 NM_ATT_IPACC_RLC_CFG_2, 0, 5,
165 0x00, 250, /* T downlink TBF extension (0..500) */
166 0x00, 250, /* T uplink TBF extension (0..500) */
167 2, /* CS2 */
168#if 0
169 /* EDGE model only, breaks older models.
170 * Should inquire the BTS capabilities */
171 NM_ATT_IPACC_RLC_CFG_3, 0, 1,
172 2, /* MCS2 */
173#endif
174};
175
176static unsigned char nanobts_attr_nsvc0[] = {
177 NM_ATT_IPACC_NSVCI, 0, 2, 0x03, 0x9d, /* 925 */
178 NM_ATT_IPACC_NS_LINK_CFG, 0, 8,
179 0x59, 0xd8, /* remote udp port (23000) */
180 192, 168, 100, 11, /* remote ip address */
181 0x59, 0xd8, /* local udp port (23000) */
182};
183
184static void patch_16(uint8_t *data, const uint16_t val)
185{
186 memcpy(data, &val, sizeof(val));
187}
188
189static void patch_32(uint8_t *data, const uint32_t val)
190{
191 memcpy(data, &val, sizeof(val));
192}
193
194/*
195 * Patch the various SYSTEM INFORMATION tables to update
196 * the LAI
197 */
198static void patch_nm_tables(struct gsm_bts *bts)
199{
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200200 uint8_t arfcn_low = bts->c0->arfcn & 0xff;
201 uint8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f;
Harald Weltef338a032011-01-14 15:55:42 +0100202
203 /* patch ARFCN into BTS Attributes */
204 nanobts_attr_bts[42] &= 0xf0;
205 nanobts_attr_bts[42] |= arfcn_high;
206 nanobts_attr_bts[43] = arfcn_low;
207
208 /* patch the RACH attributes */
209 if (bts->rach_b_thresh != -1) {
210 nanobts_attr_bts[33] = bts->rach_b_thresh & 0xff;
211 }
212
213 if (bts->rach_ldavg_slots != -1) {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200214 uint8_t avg_high = bts->rach_ldavg_slots & 0xff;
215 uint8_t avg_low = (bts->rach_ldavg_slots >> 8) & 0x0f;
Harald Weltef338a032011-01-14 15:55:42 +0100216
217 nanobts_attr_bts[35] = avg_high;
218 nanobts_attr_bts[36] = avg_low;
219 }
220
221 /* patch BSIC */
222 nanobts_attr_bts[sizeof(nanobts_attr_bts)-11] = bts->bsic;
223
224 /* patch CGI */
Harald Weltee86b3eb2011-06-27 21:15:59 +0200225 abis_nm_ipaccess_cgi(nanobts_attr_bts+sizeof(nanobts_attr_bts)-7, bts);
Harald Weltef338a032011-01-14 15:55:42 +0100226
227 /* patch the power reduction */
228 nanobts_attr_radio[1] = bts->c0->max_power_red / 2;
229
230 /* patch NSEI */
231 nanobts_attr_nse[3] = bts->gprs.nse.nsei >> 8;
232 nanobts_attr_nse[4] = bts->gprs.nse.nsei & 0xff;
233 memcpy(nanobts_attr_nse+8, bts->gprs.nse.timer,
234 ARRAY_SIZE(bts->gprs.nse.timer));
235 memcpy(nanobts_attr_nse+18, bts->gprs.cell.timer,
236 ARRAY_SIZE(bts->gprs.cell.timer));
237
238 /* patch NSVCI */
239 nanobts_attr_nsvc0[3] = bts->gprs.nsvc[0].nsvci >> 8;
240 nanobts_attr_nsvc0[4] = bts->gprs.nsvc[0].nsvci & 0xff;
241
242 /* patch IP address as SGSN IP */
243 patch_16(nanobts_attr_nsvc0 + 8,
244 htons(bts->gprs.nsvc[0].remote_port));
245 patch_32(nanobts_attr_nsvc0 + 10,
246 htonl(bts->gprs.nsvc[0].remote_ip));
247 patch_16(nanobts_attr_nsvc0 + 14,
248 htons(bts->gprs.nsvc[0].local_port));
249
250 /* patch BVCI */
251 nanobts_attr_cell[12] = bts->gprs.cell.bvci >> 8;
252 nanobts_attr_cell[13] = bts->gprs.cell.bvci & 0xff;
253 /* patch RAC */
254 nanobts_attr_cell[3] = bts->gprs.rac;
255
256 if (bts->gprs.mode == BTS_GPRS_EGPRS) {
257 /* patch EGPRS coding schemes MCS 1..9 */
258 nanobts_attr_cell[29] = 0x8f;
259 nanobts_attr_cell[30] = 0xff;
260 }
261}
262
263
264/* Callback function to be called whenever we get a GSM 12.21 state change event */
265static int nm_statechg_event(int evt, struct nm_statechg_signal_data *nsd)
266{
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200267 uint8_t obj_class = nsd->obj_class;
Harald Weltef338a032011-01-14 15:55:42 +0100268 void *obj = nsd->obj;
269 struct gsm_nm_state *new_state = nsd->new_state;
270
271 struct gsm_bts *bts;
272 struct gsm_bts_trx *trx;
273 struct gsm_bts_trx_ts *ts;
274 struct gsm_bts_gprs_nsvc *nsvc;
275
Harald Weltef38ca9a2011-03-06 22:11:32 +0100276 if (nsd->bts->type != GSM_BTS_TYPE_NANOBTS)
277 return 0;
278
Harald Weltef338a032011-01-14 15:55:42 +0100279 /* This event-driven BTS setup is currently only required on nanoBTS */
280
281 /* S_NM_STATECHG_ADM is called after we call chg_adm_state() and would create
282 * endless loop */
283 if (evt != S_NM_STATECHG_OPER)
284 return 0;
285
286 switch (obj_class) {
287 case NM_OC_SITE_MANAGER:
288 bts = container_of(obj, struct gsm_bts, site_mgr);
289 if ((new_state->operational == NM_OPSTATE_ENABLED &&
290 new_state->availability == NM_AVSTATE_OK) ||
291 (new_state->operational == NM_OPSTATE_DISABLED &&
292 new_state->availability == NM_AVSTATE_OFF_LINE))
293 abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff);
294 break;
295 case NM_OC_BTS:
296 bts = obj;
297 if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
298 patch_nm_tables(bts);
299 abis_nm_set_bts_attr(bts, nanobts_attr_bts,
300 sizeof(nanobts_attr_bts));
301 abis_nm_chg_adm_state(bts, obj_class,
302 bts->bts_nr, 0xff, 0xff,
303 NM_STATE_UNLOCKED);
304 abis_nm_opstart(bts, obj_class,
305 bts->bts_nr, 0xff, 0xff);
306 }
307 break;
308 case NM_OC_CHANNEL:
309 ts = obj;
310 trx = ts->trx;
311 if (new_state->operational == NM_OPSTATE_DISABLED &&
312 new_state->availability == NM_AVSTATE_DEPENDENCY) {
313 patch_nm_tables(trx->bts);
314 enum abis_nm_chan_comb ccomb =
315 abis_nm_chcomb4pchan(ts->pchan);
316 abis_nm_set_channel_attr(ts, ccomb);
317 abis_nm_chg_adm_state(trx->bts, obj_class,
318 trx->bts->bts_nr, trx->nr, ts->nr,
319 NM_STATE_UNLOCKED);
320 abis_nm_opstart(trx->bts, obj_class,
321 trx->bts->bts_nr, trx->nr, ts->nr);
322 }
323 break;
324 case NM_OC_RADIO_CARRIER:
325 trx = obj;
326 if (new_state->operational == NM_OPSTATE_DISABLED &&
327 new_state->availability == NM_AVSTATE_OK)
328 abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr,
329 trx->nr, 0xff);
330 break;
331 case NM_OC_GPRS_NSE:
332 bts = container_of(obj, struct gsm_bts, gprs.nse);
333 if (bts->gprs.mode == BTS_GPRS_NONE)
334 break;
335 if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
336 abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
337 0xff, 0xff, nanobts_attr_nse,
338 sizeof(nanobts_attr_nse));
339 abis_nm_opstart(bts, obj_class, bts->bts_nr,
340 0xff, 0xff);
341 }
342 break;
343 case NM_OC_GPRS_CELL:
344 bts = container_of(obj, struct gsm_bts, gprs.cell);
345 if (bts->gprs.mode == BTS_GPRS_NONE)
346 break;
347 if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
348 abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
349 0, 0xff, nanobts_attr_cell,
350 sizeof(nanobts_attr_cell));
351 abis_nm_opstart(bts, obj_class, bts->bts_nr,
352 0, 0xff);
353 abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr,
354 0, 0xff, NM_STATE_UNLOCKED);
355 abis_nm_chg_adm_state(bts, NM_OC_GPRS_NSE, bts->bts_nr,
356 0xff, 0xff, NM_STATE_UNLOCKED);
357 }
358 break;
359 case NM_OC_GPRS_NSVC:
360 nsvc = obj;
361 bts = nsvc->bts;
362 if (bts->gprs.mode == BTS_GPRS_NONE)
363 break;
364 /* We skip NSVC1 since we only use NSVC0 */
365 if (nsvc->id == 1)
366 break;
Sylvain Munaut67c0c7f2011-10-17 13:57:58 +0200367 if ((new_state->availability == NM_AVSTATE_OFF_LINE) ||
368 (new_state->availability == NM_AVSTATE_DEPENDENCY)) {
Harald Weltef338a032011-01-14 15:55:42 +0100369 abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
370 nsvc->id, 0xff,
371 nanobts_attr_nsvc0,
372 sizeof(nanobts_attr_nsvc0));
373 abis_nm_opstart(bts, obj_class, bts->bts_nr,
374 nsvc->id, 0xff);
375 abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr,
376 nsvc->id, 0xff,
377 NM_STATE_UNLOCKED);
378 }
379 default:
380 break;
381 }
382 return 0;
383}
384
385/* Callback function to be called every time we receive a 12.21 SW activated report */
386static int sw_activ_rep(struct msgb *mb)
387{
388 struct abis_om_fom_hdr *foh = msgb_l3(mb);
Pablo Neira Ayuso7abecfc2011-08-17 22:43:54 +0200389 struct e1inp_sign_link *sign_link = mb->dst;
390 struct gsm_bts *bts = sign_link->trx->bts;
Harald Weltef338a032011-01-14 15:55:42 +0100391 struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, foh->obj_inst.trx_nr);
392
393 if (!trx)
394 return -EINVAL;
395
396 if (trx->bts->type != GSM_BTS_TYPE_NANOBTS)
397 return 0;
398
399 switch (foh->obj_class) {
400 case NM_OC_BASEB_TRANSC:
401 abis_nm_chg_adm_state(trx->bts, foh->obj_class,
402 trx->bts->bts_nr, trx->nr, 0xff,
403 NM_STATE_UNLOCKED);
404 abis_nm_opstart(trx->bts, foh->obj_class,
405 trx->bts->bts_nr, trx->nr, 0xff);
406 /* TRX software is active, tell it to initiate RSL Link */
407 abis_nm_ipaccess_rsl_connect(trx, 0, 3003, trx->rsl_tei);
408 break;
409 case NM_OC_RADIO_CARRIER: {
410 /*
411 * Locking the radio carrier will make it go
412 * offline again and we would come here. The
413 * framework should determine that there was
414 * no change and avoid recursion.
415 *
416 * This code is here to make sure that on start
417 * a TRX remains locked.
418 */
Harald Welted64c0bc2011-05-30 12:07:53 +0200419 int rc_state = trx->mo.nm_state.administrative;
Harald Weltef338a032011-01-14 15:55:42 +0100420 /* Patch ARFCN into radio attribute */
421 nanobts_attr_radio[5] &= 0xf0;
422 nanobts_attr_radio[5] |= trx->arfcn >> 8;
423 nanobts_attr_radio[6] = trx->arfcn & 0xff;
424 abis_nm_set_radio_attr(trx, nanobts_attr_radio,
425 sizeof(nanobts_attr_radio));
426 abis_nm_chg_adm_state(trx->bts, foh->obj_class,
427 trx->bts->bts_nr, trx->nr, 0xff,
428 rc_state);
429 abis_nm_opstart(trx->bts, foh->obj_class, trx->bts->bts_nr,
430 trx->nr, 0xff);
431 break;
432 }
433 }
434 return 0;
435}
436
437/* Callback function to be called every time we receive a signal from NM */
438static int nm_sig_cb(unsigned int subsys, unsigned int signal,
439 void *handler_data, void *signal_data)
440{
441 if (subsys != SS_NM)
442 return 0;
443
444 switch (signal) {
445 case S_NM_SW_ACTIV_REP:
446 return sw_activ_rep(signal_data);
447 case S_NM_STATECHG_OPER:
448 case S_NM_STATECHG_ADM:
449 return nm_statechg_event(signal, signal_data);
450 default:
451 break;
452 }
453 return 0;
454}
455
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200456static struct gsm_network *ipaccess_gsmnet;
457
Pablo Neira Ayuso0d2881a2011-05-14 11:32:48 +0200458static int bts_model_nanobts_start(struct gsm_network *net)
Harald Welte39315c42010-01-10 18:01:52 +0100459{
Holger Hans Peter Freytherc8bf3c12010-06-21 18:11:37 +0800460 model_nanobts.features.data = &model_nanobts._features_data[0];
Harald Weltef3d8e922010-06-14 22:44:42 +0200461 model_nanobts.features.data_len = sizeof(model_nanobts._features_data);
462
463 gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_GPRS);
464 gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_EGPRS);
465
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200466 osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL);
Harald Weltef338a032011-01-14 15:55:42 +0100467
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200468 ipaccess_gsmnet = net;
469 return 0;
Pablo Neira Ayuso0d2881a2011-05-14 11:32:48 +0200470}
471
472int bts_model_nanobts_init(void)
473{
Harald Welte39315c42010-01-10 18:01:52 +0100474 return gsm_bts_model_register(&model_nanobts);
475}
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200476
477#define OML_UP 0x0001
478#define RSL_UP 0x0002
479
480static struct gsm_bts *
481find_bts_by_unitid(struct gsm_network *net, uint16_t site_id, uint16_t bts_id)
482{
483 struct gsm_bts *bts;
484
485 llist_for_each_entry(bts, &net->bts_list, list) {
486 if (!is_ipaccess_bts(bts))
487 continue;
488
489 if (bts->ip_access.site_id == site_id &&
490 bts->ip_access.bts_id == bts_id)
491 return bts;
492 }
493 return NULL;
494}
495
496/* These are exported because they are used by the VTY interface. */
497void ipaccess_drop_rsl(struct gsm_bts_trx *trx)
498{
499 if (!trx->rsl_link)
500 return;
501
502 e1inp_sign_link_destroy(trx->rsl_link);
503 trx->rsl_link = NULL;
504}
505
506void ipaccess_drop_oml(struct gsm_bts *bts)
507{
508 struct gsm_bts_trx *trx;
509 struct e1inp_line *line;
510
511 if (!bts->oml_link)
512 return;
513
514 line = bts->oml_link->ts->line;
515
516 e1inp_sign_link_destroy(bts->oml_link);
517 bts->oml_link = NULL;
518
519 /* we have issues reconnecting RSL, drop everything. */
520 llist_for_each_entry(trx, &bts->trx_list, list)
521 ipaccess_drop_rsl(trx);
522
523 bts->ip_access.flags = 0;
524}
525
526/* This function is called once the OML/RSL link becomes up. */
527static struct e1inp_sign_link *
528ipaccess_sign_link_up(void *unit_data, struct e1inp_line *line,
529 enum e1inp_sign_type type)
530{
531 struct gsm_bts *bts;
532 struct ipaccess_unit *dev = unit_data;
533 struct e1inp_sign_link *sign_link = NULL;
534
535 bts = find_bts_by_unitid(ipaccess_gsmnet, dev->site_id, dev->bts_id);
536 if (!bts) {
537 LOGP(DLINP, LOGL_ERROR, "Unable to find BTS configuration for "
538 " %u/%u/%u, disconnecting\n", dev->site_id,
539 dev->bts_id, dev->trx_id);
540 return NULL;
541 }
542 DEBUGP(DLINP, "Identified BTS %u/%u/%u\n",
543 dev->site_id, dev->bts_id, dev->trx_id);
544
545 switch(type) {
546 case E1INP_SIGN_OML:
547 /* remove old OML signal link for this BTS. */
548 ipaccess_drop_oml(bts);
549
550 /* create new OML link. */
551 sign_link = bts->oml_link =
552 e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML - 1],
553 E1INP_SIGN_OML, bts->c0,
554 bts->oml_tei, 0);
555 break;
556 case E1INP_SIGN_RSL: {
557 struct e1inp_ts *ts;
558 struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, dev->trx_id);
559
560 /* no OML link set yet? give up. */
561 if (!bts->oml_link)
562 return NULL;
563
564 /* remove old RSL link for this TRX. */
565 ipaccess_drop_rsl(trx);
566
567 /* set new RSL link for this TRX. */
568 line = bts->oml_link->ts->line;
569 ts = &line->ts[E1INP_SIGN_RSL + dev->trx_id - 1];
570 e1inp_ts_config_sign(ts, line);
571 sign_link = trx->rsl_link =
572 e1inp_sign_link_create(ts, E1INP_SIGN_RSL,
573 trx, trx->rsl_tei, 0);
574 trx->rsl_link->ts->sign.delay = 0;
575 break;
576 }
577 default:
578 break;
579 }
580 return sign_link;
581}
582
583static void ipaccess_sign_link_down(struct e1inp_line *line)
584{
585 /* No matter what link went down, we close both signal links. */
586 struct e1inp_ts *ts = &line->ts[E1INP_SIGN_OML-1];
587 struct e1inp_sign_link *link;
588
589 llist_for_each_entry(link, &ts->sign.sign_links, list) {
590 struct gsm_bts *bts = link->trx->bts;
591
592 ipaccess_drop_oml(bts);
593 /* Yes, we only use the first element of the list. */
594 break;
595 }
596}
597
598/* This function is called if we receive one OML/RSL message. */
599static int ipaccess_sign_link(struct msgb *msg)
600{
601 int ret = 0;
602 struct e1inp_sign_link *link = msg->dst;
603 struct e1inp_ts *e1i_ts = link->ts;
604
605 switch (link->type) {
606 case E1INP_SIGN_RSL:
607 if (!(link->trx->bts->ip_access.flags &
608 (RSL_UP << link->trx->nr))) {
609 e1inp_event(e1i_ts, S_L_INP_TEI_UP,
610 link->tei, link->sapi);
611 link->trx->bts->ip_access.flags |=
612 (RSL_UP << link->trx->nr);
613 }
614 ret = abis_rsl_rcvmsg(msg);
615 break;
616 case E1INP_SIGN_OML:
617 if (!(link->trx->bts->ip_access.flags & OML_UP)) {
618 e1inp_event(e1i_ts, S_L_INP_TEI_UP,
619 link->tei, link->sapi);
620 link->trx->bts->ip_access.flags |= OML_UP;
621 }
622 ret = abis_nm_rcvmsg(msg);
623 break;
624 default:
625 LOGP(DLINP, LOGL_ERROR, "Unknown signal link type %d\n",
626 link->type);
627 msgb_free(msg);
628 break;
629 }
630 return ret;
631}
632
633/* not static, ipaccess-config needs it. */
634struct e1inp_line_ops ipaccess_e1inp_line_ops = {
635 .cfg = {
636 .ipa = {
637 .addr = "0.0.0.0",
638 .role = E1INP_LINE_R_BSC,
639 },
640 },
641 .sign_link_up = ipaccess_sign_link_up,
642 .sign_link_down = ipaccess_sign_link_down,
643 .sign_link = ipaccess_sign_link,
644};
645
646static void bts_model_nanobts_e1line_bind_ops(struct e1inp_line *line)
647{
648 e1inp_line_bind_ops(line, &ipaccess_e1inp_line_ops);
649}