blob: 84dfa6e80afc5888af28ad2fbe91703c0deea212 [file] [log] [blame]
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +02001/* A hackish minimal BSC (+MSC +HLR) implementation */
2
Harald Welte40152872010-05-16 20:52:23 +02003/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +02004 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte0e3e88e2011-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
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020010 * (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 Welte0e3e88e2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020016 *
Harald Welte0e3e88e2011-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/>.
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020019 *
20 */
21
22#include <openbsc/gsm_data.h>
Pablo Neira Ayusodd5fff42011-03-22 16:47:59 +010023#include <osmocom/gsm/gsm_utils.h>
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020024#include <openbsc/gsm_04_08.h>
25#include <openbsc/abis_rsl.h>
26#include <openbsc/abis_nm.h>
27#include <openbsc/debug.h>
28#include <openbsc/misdn.h>
Harald Weltebd9591f2010-05-19 19:45:32 +020029#include <osmocom/vty/telnet_interface.h>
Harald Weltea54a2bb2009-12-01 18:04:30 +053030#include <openbsc/system_information.h>
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020031#include <openbsc/paging.h>
32#include <openbsc/signal.h>
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +020033#include <openbsc/chan_alloc.h>
Pablo Neira Ayusodd5fff42011-03-22 16:47:59 +010034#include <osmocom/core/talloc.h>
Holger Hans Peter Freyther82260a62010-11-15 20:43:02 +010035#include <openbsc/ipaccess.h>
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020036
37/* global pointer to the gsm network data structure */
38extern struct gsm_network *bsc_gsmnet;
Holger Hans Peter Freyther6f2312e2011-04-07 23:34:54 +020039extern int hsl_setup(struct gsm_network *gsmnet);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020040
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020041/* Callback function for NACK on the OML NM */
Holger Hans Peter Freytherdfea6c82010-07-14 02:08:35 +080042static int oml_msg_nack(struct nm_nack_signal_data *nack)
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020043{
Holger Hans Peter Freyther82260a62010-11-15 20:43:02 +010044 int i;
45
Holger Hans Peter Freytherdfea6c82010-07-14 02:08:35 +080046 if (nack->mt == NM_MT_SET_BTS_ATTR_NACK) {
Holger Hans Peter Freyther82260a62010-11-15 20:43:02 +010047
Harald Weltecf2ec4a2009-12-17 23:10:46 +010048 LOGP(DNM, LOGL_FATAL, "Failed to set BTS attributes. That is fatal. "
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020049 "Was the bts type and frequency properly specified?\n");
50 exit(-1);
Holger Hans Peter Freyther82260a62010-11-15 20:43:02 +010051 } else {
52 LOGP(DNM, LOGL_ERROR, "Got a NACK going to drop the OML links.\n");
53 for (i = 0; i < bsc_gsmnet->num_bts; ++i) {
54 struct gsm_bts *bts = gsm_bts_num(bsc_gsmnet, i);
55 if (is_ipaccess_bts(bts))
56 ipaccess_drop_oml(bts);
57 }
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020058 }
59
60 return 0;
61}
62
63/* Callback function to be called every time we receive a signal from NM */
64static int nm_sig_cb(unsigned int subsys, unsigned int signal,
65 void *handler_data, void *signal_data)
66{
Holger Hans Peter Freytherdfea6c82010-07-14 02:08:35 +080067 struct nm_nack_signal_data *nack;
Harald Welte6a21c732009-11-17 06:09:56 +010068
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020069 switch (signal) {
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020070 case S_NM_NACK:
Holger Hans Peter Freytherdfea6c82010-07-14 02:08:35 +080071 nack = signal_data;
72 return oml_msg_nack(nack);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020073 default:
74 break;
75 }
76 return 0;
77}
78
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020079int bsc_shutdown_net(struct gsm_network *net)
80{
81 struct gsm_bts *bts;
82
83 llist_for_each_entry(bts, &net->bts_list, list) {
Harald Welte4c826f72011-01-14 15:55:42 +010084 LOGP(DNM, LOGL_NOTICE, "shutting down OML for BTS %u\n", bts->nr);
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +020085 osmo_signal_dispatch(SS_L_GLOBAL, S_GLOBAL_BTS_CLOSE_OM, bts);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +020086 }
87
88 return 0;
89}
90
Harald Welte99bed522010-06-15 16:44:12 +020091static int generate_and_rsl_si(struct gsm_bts_trx *trx, enum osmo_sysinfo_type i)
92{
93 struct gsm_bts *bts = trx->bts;
Harald Welte08011e22011-03-04 13:41:31 +010094 int si_len, rc, j;
Harald Welte99bed522010-06-15 16:44:12 +020095
Harald Welted8acf142010-07-30 11:50:09 +020096 /* Only generate SI if this SI is not in "static" (user-defined) mode */
97 if (!(bts->si_mode_static & (1 << i))) {
98 rc = gsm_generate_si(bts, i);
99 if (rc < 0)
100 return rc;
Harald Welte08011e22011-03-04 13:41:31 +0100101 si_len = rc;
Harald Welted8acf142010-07-30 11:50:09 +0200102 }
Harald Welte99bed522010-06-15 16:44:12 +0200103
Harald Welte6b77f0f2011-05-24 15:02:20 +0200104 DEBUGP(DRR, "SI%s: %s\n", get_value_string(osmo_sitype_strs, i),
Pablo Neira Ayusob1d5a692011-05-07 12:12:48 +0200105 osmo_hexdump(GSM_BTS_SI(bts, i), GSM_MACBLOCK_LEN));
Harald Welte99bed522010-06-15 16:44:12 +0200106
107 switch (i) {
108 case SYSINFO_TYPE_5:
109 case SYSINFO_TYPE_5bis:
110 case SYSINFO_TYPE_5ter:
111 case SYSINFO_TYPE_6:
Harald Welte08011e22011-03-04 13:41:31 +0100112 if (trx->bts->type == GSM_BTS_TYPE_HSL_FEMTO) {
113 /* HSL has mistaken SACCH INFO MODIFY for SACCH FILLING,
114 * so we need a special workaround here */
115 /* This assumes a combined BCCH and TCH on TS1...7 */
116 for (j = 0; j < 4; j++)
117 rsl_sacch_info_modify(&trx->ts[0].lchan[j],
Harald Welte6b77f0f2011-05-24 15:02:20 +0200118 osmo_sitype2rsl(i),
Harald Welte08011e22011-03-04 13:41:31 +0100119 GSM_BTS_SI(bts, i), si_len);
120 for (j = 1; j < 8; j++) {
121 rsl_sacch_info_modify(&trx->ts[j].lchan[0],
Harald Welte6b77f0f2011-05-24 15:02:20 +0200122 osmo_sitype2rsl(i),
Harald Welte08011e22011-03-04 13:41:31 +0100123 GSM_BTS_SI(bts, i), si_len);
124 rsl_sacch_info_modify(&trx->ts[j].lchan[1],
Harald Welte6b77f0f2011-05-24 15:02:20 +0200125 osmo_sitype2rsl(i),
Harald Welte08011e22011-03-04 13:41:31 +0100126 GSM_BTS_SI(bts, i), si_len);
127 }
128 } else
Harald Welte6b77f0f2011-05-24 15:02:20 +0200129 rc = rsl_sacch_filling(trx, osmo_sitype2rsl(i),
Harald Welte08011e22011-03-04 13:41:31 +0100130 GSM_BTS_SI(bts, i), rc);
Harald Welte99bed522010-06-15 16:44:12 +0200131 break;
132 default:
Harald Welte6b77f0f2011-05-24 15:02:20 +0200133 rc = rsl_bcch_info(trx, osmo_sitype2rsl(i),
Harald Welte99bed522010-06-15 16:44:12 +0200134 GSM_BTS_SI(bts, i), rc);
135 break;
136 }
137
138 return rc;
139}
140
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200141/* set all system information types */
142static int set_system_infos(struct gsm_bts_trx *trx)
143{
Harald Weltea54a2bb2009-12-01 18:04:30 +0530144 int i, rc;
Harald Welte36e5a792009-12-21 23:12:19 +0100145 struct gsm_bts *bts = trx->bts;
146
147 bts->si_common.cell_sel_par.ms_txpwr_max_ccch =
148 ms_pwr_ctl_lvl(bts->band, bts->ms_max_power);
149 bts->si_common.cell_sel_par.neci = bts->network->neci;
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200150
Harald Welted8acf142010-07-30 11:50:09 +0200151 /* First, we determine which of the SI messages we actually need */
152
Harald Welte99bed522010-06-15 16:44:12 +0200153 if (trx == bts->c0) {
Harald Welted8acf142010-07-30 11:50:09 +0200154 /* 1...4 are always present on a C0 TRX */
155 for (i = SYSINFO_TYPE_1; i <= SYSINFO_TYPE_4; i++)
156 bts->si_valid |= (1 << i);
157
158 /* 13 is always present on a C0 TRX of a GPRS BTS */
159 if (bts->gprs.mode != BTS_GPRS_NONE)
160 bts->si_valid |= (1 << SYSINFO_TYPE_13);
Harald Welte28fc9632009-12-21 17:02:32 +0100161 }
162
Harald Welted8acf142010-07-30 11:50:09 +0200163 /* 5 and 6 are always present on every TRX */
164 bts->si_valid |= (1 << SYSINFO_TYPE_5);
165 bts->si_valid |= (1 << SYSINFO_TYPE_6);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530166
Harald Welted8acf142010-07-30 11:50:09 +0200167 /* Second, we generate and send the selected SI via RSL */
168 for (i = SYSINFO_TYPE_1; i < _MAX_SYSINFO_TYPE; i++) {
169 if (!(bts->si_valid & (1 << i)))
170 continue;
171
172 rc = generate_and_rsl_si(trx, i);
173 if (rc < 0)
174 goto err_out;
175 }
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200176
177 return 0;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530178err_out:
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100179 LOGP(DRR, LOGL_ERROR, "Cannot generate SI %u for BTS %u, most likely "
Harald Weltea54a2bb2009-12-01 18:04:30 +0530180 "a problem with neighbor cell list generation\n",
Harald Welte99bed522010-06-15 16:44:12 +0200181 i, bts->nr);
Harald Weltea54a2bb2009-12-01 18:04:30 +0530182 return rc;
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200183}
184
Harald Weltebf6624d2010-06-15 08:52:12 +0200185/* Produce a MA as specified in 10.5.2.21 */
186static int generate_ma_for_ts(struct gsm_bts_trx_ts *ts)
187{
188 /* we have three bitvecs: the per-timeslot ARFCNs, the cell chan ARFCNs
189 * and the MA */
190 struct bitvec *cell_chan = &ts->trx->bts->si_common.cell_alloc;
191 struct bitvec *ts_arfcn = &ts->hopping.arfcns;
192 struct bitvec *ma = &ts->hopping.ma;
Harald Welte6332a8a2010-06-15 16:45:51 +0200193 unsigned int num_cell_arfcns, bitnum, n_chan;
Harald Weltebf6624d2010-06-15 08:52:12 +0200194 int i;
195
196 /* re-set the MA to all-zero */
197 ma->cur_bit = 0;
Harald Welte6332a8a2010-06-15 16:45:51 +0200198 ts->hopping.ma_len = 0;
Harald Weltebf6624d2010-06-15 08:52:12 +0200199 memset(ma->data, 0, ma->data_len);
200
201 if (!ts->hopping.enabled)
202 return 0;
203
Harald Welte6332a8a2010-06-15 16:45:51 +0200204 /* count the number of ARFCNs in the cell channel allocation */
205 num_cell_arfcns = 0;
206 for (i = 1; i < 1024; i++) {
207 if (bitvec_get_bit_pos(cell_chan, i))
208 num_cell_arfcns++;
209 }
210
211 /* pad it to octet-aligned number of bits */
212 ts->hopping.ma_len = num_cell_arfcns / 8;
213 if (num_cell_arfcns % 8)
214 ts->hopping.ma_len++;
215
216 n_chan = 0;
Harald Weltebf6624d2010-06-15 08:52:12 +0200217 for (i = 1; i < 1024; i++) {
218 if (!bitvec_get_bit_pos(cell_chan, i))
219 continue;
Harald Welte6332a8a2010-06-15 16:45:51 +0200220 /* set the corresponding bit in the MA */
221 bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan;
Harald Weltebf6624d2010-06-15 08:52:12 +0200222 if (bitvec_get_bit_pos(ts_arfcn, i))
Harald Welte6332a8a2010-06-15 16:45:51 +0200223 bitvec_set_bit_pos(ma, bitnum, 1);
Harald Weltebf6624d2010-06-15 08:52:12 +0200224 else
Harald Welte6332a8a2010-06-15 16:45:51 +0200225 bitvec_set_bit_pos(ma, bitnum, 0);
laforge1dcdc952010-06-20 15:56:50 +0200226 n_chan++;
Harald Weltebf6624d2010-06-15 08:52:12 +0200227 }
228
229 /* ARFCN 0 is special: It is coded last in the bitmask */
230 if (bitvec_get_bit_pos(cell_chan, 0)) {
Harald Welte6332a8a2010-06-15 16:45:51 +0200231 n_chan++;
232 /* set the corresponding bit in the MA */
233 bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan;
Harald Weltebf6624d2010-06-15 08:52:12 +0200234 if (bitvec_get_bit_pos(ts_arfcn, 0))
Harald Welte6332a8a2010-06-15 16:45:51 +0200235 bitvec_set_bit_pos(ma, bitnum, 1);
Harald Weltebf6624d2010-06-15 08:52:12 +0200236 else
Harald Welte6332a8a2010-06-15 16:45:51 +0200237 bitvec_set_bit_pos(ma, bitnum, 0);
Harald Weltebf6624d2010-06-15 08:52:12 +0200238 }
239
240 return 0;
241}
242
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200243static void bootstrap_rsl(struct gsm_bts_trx *trx)
244{
Harald Weltebf6624d2010-06-15 08:52:12 +0200245 unsigned int i;
246
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100247 LOGP(DRSL, LOGL_NOTICE, "bootstrapping RSL for BTS/TRX (%u/%u) "
Harald Welte424873e2009-12-24 13:39:34 +0100248 "on ARFCN %u using MCC=%u MNC=%u LAC=%u CID=%u BSIC=%u TSC=%u\n",
249 trx->bts->nr, trx->nr, trx->arfcn, bsc_gsmnet->country_code,
250 bsc_gsmnet->network_code, trx->bts->location_area_code,
251 trx->bts->cell_identity, trx->bts->bsic, trx->bts->tsc);
Dieter Spaar49c843e2011-07-28 00:01:50 +0200252
253 if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) {
254 rsl_nokia_si_begin(trx);
255 }
256
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200257 set_system_infos(trx);
Harald Weltebf6624d2010-06-15 08:52:12 +0200258
Dieter Spaar49c843e2011-07-28 00:01:50 +0200259 if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) {
260 /* channel unspecific, power reduction in 2 dB steps */
261 rsl_bs_power_control(trx, 0xFF, trx->max_power_red / 2);
262 rsl_nokia_si_end(trx);
263 }
264
Harald Weltebf6624d2010-06-15 08:52:12 +0200265 for (i = 0; i < ARRAY_SIZE(trx->ts); i++)
266 generate_ma_for_ts(&trx->ts[i]);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200267}
268
Harald Welte4c826f72011-01-14 15:55:42 +0100269/* Callback function to be called every time we receive a signal from INPUT */
270static int inp_sig_cb(unsigned int subsys, unsigned int signal,
271 void *handler_data, void *signal_data)
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200272{
Harald Welte4c826f72011-01-14 15:55:42 +0100273 struct input_signal_data *isd = signal_data;
274 struct gsm_bts_trx *trx = isd->trx;
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200275 int ts_no, lchan_no;
276
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +0200277 if (subsys != SS_L_INPUT)
Harald Welte4c826f72011-01-14 15:55:42 +0100278 return -EINVAL;
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200279
Harald Welte4c826f72011-01-14 15:55:42 +0100280 switch (signal) {
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +0200281 case S_L_INP_TEI_UP:
Dieter Spaar49c843e2011-07-28 00:01:50 +0200282 if (isd->link_type == E1INP_SIGN_OML) {
283 /* TODO: this is required for the Nokia BTS, hopping is configured
284 during OML, other MA is not set. */
285 struct gsm_bts_trx *cur_trx;
286 /* was static in system_information.c */
287 extern int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts);
288 uint8_t ca[20];
289 /* has to be called before generate_ma_for_ts to
290 set bts->si_common.cell_alloc */
291 generate_cell_chan_list(ca, trx->bts);
292
293 llist_for_each_entry(cur_trx, &trx->bts->trx_list, list) {
294 int i;
295
296 for (i = 0; i < ARRAY_SIZE(cur_trx->ts); i++)
297 generate_ma_for_ts(&cur_trx->ts[i]);
298 }
299 }
Harald Welte4c826f72011-01-14 15:55:42 +0100300 if (isd->link_type == E1INP_SIGN_RSL)
301 bootstrap_rsl(trx);
302 break;
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +0200303 case S_L_INP_TEI_DN:
304 LOGP(DLMI, LOGL_ERROR, "Lost some E1 TEI link: %d %p\n", isd->link_type, trx);
Harald Welte4c826f72011-01-14 15:55:42 +0100305
306 if (isd->link_type == E1INP_SIGN_OML)
Pablo Neira Ayuso1c450742011-05-06 12:13:10 +0200307 osmo_counter_inc(trx->bts->network->stats.bts.oml_fail);
Harald Welte4c826f72011-01-14 15:55:42 +0100308 else if (isd->link_type == E1INP_SIGN_RSL)
Pablo Neira Ayuso1c450742011-05-06 12:13:10 +0200309 osmo_counter_inc(trx->bts->network->stats.bts.rsl_fail);
Holger Hans Peter Freyther3e09b3f2010-04-12 10:45:52 +0200310
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200311 /*
312 * free all allocated channels. change the nm_state so the
313 * trx and trx_ts becomes unusable and chan_alloc.c can not
314 * allocate from it.
315 */
316 for (ts_no = 0; ts_no < ARRAY_SIZE(trx->ts); ++ts_no) {
317 struct gsm_bts_trx_ts *ts = &trx->ts[ts_no];
318
319 for (lchan_no = 0; lchan_no < ARRAY_SIZE(ts->lchan); ++lchan_no) {
Holger Hans Peter Freytherade87dd2010-08-25 12:29:24 +0800320 if (ts->lchan[lchan_no].state != LCHAN_S_NONE)
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200321 lchan_free(&ts->lchan[lchan_no]);
322 lchan_reset(&ts->lchan[lchan_no]);
323 }
Holger Hans Peter Freyther5a8b2b42010-04-15 11:21:02 +0200324 }
325
Harald Welte452119d2011-06-29 16:49:03 +0200326 gsm_bts_mo_reset(trx->bts);
Holger Hans Peter Freyther2a6bffe2010-11-15 20:50:42 +0100327
328 abis_nm_clear_queue(trx->bts);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200329 break;
330 default:
331 break;
332 }
Harald Welte4c826f72011-01-14 15:55:42 +0100333
334 return 0;
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200335}
336
337static int bootstrap_bts(struct gsm_bts *bts)
338{
Sylvain Munaut63e014e2010-04-28 21:31:29 +0200339 int i, n;
340
Pablo Neira Ayuso5bd96a72011-05-14 11:32:48 +0200341 if (bts->model->start && !bts->model->started) {
342 int ret = bts->model->start(bts->network);
343 if (ret < 0)
344 return ret;
345
346 bts->model->started = true;
347 }
348
Harald Welteeee698b2010-05-26 17:14:42 +0200349 /* FIXME: What about secondary TRX of a BTS? What about a BTS that has TRX
350 * in different bands? Why is 'band' a parameter of the BTS and not of the TRX? */
Mike Haben66e0ba02009-10-02 12:19:34 +0100351 switch (bts->band) {
352 case GSM_BAND_1800:
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200353 if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100354 LOGP(DNM, LOGL_ERROR, "GSM1800 channel must be between 512-885.\n");
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200355 return -EINVAL;
356 }
357 break;
Mike Haben66e0ba02009-10-02 12:19:34 +0100358 case GSM_BAND_1900:
359 if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100360 LOGP(DNM, LOGL_ERROR, "GSM1900 channel must be between 512-810.\n");
Mike Haben66e0ba02009-10-02 12:19:34 +0100361 return -EINVAL;
362 }
363 break;
364 case GSM_BAND_900:
Holger Hans Peter Freyther2ba2b332010-02-09 15:44:14 +0100365 if (bts->c0->arfcn < 1 ||
366 (bts->c0->arfcn > 124 && bts->c0->arfcn < 955) ||
367 bts->c0->arfcn > 1023) {
368 LOGP(DNM, LOGL_ERROR, "GSM900 channel must be between 1-124, 955-1023.\n");
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200369 return -EINVAL;
370 }
371 break;
Harald Welteeee698b2010-05-26 17:14:42 +0200372 case GSM_BAND_850:
373 if (bts->c0->arfcn < 128 || bts->c0->arfcn > 251) {
374 LOGP(DNM, LOGL_ERROR, "GSM850 channel must be between 128-251.\n");
375 return -EINVAL;
376 }
377 break;
Mike Haben66e0ba02009-10-02 12:19:34 +0100378 default:
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100379 LOGP(DNM, LOGL_ERROR, "Unsupported frequency band.\n");
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200380 return -EINVAL;
381 }
382
Harald Welte395cb6b2009-12-12 13:44:19 +0100383 if (bts->network->auth_policy == GSM_AUTH_POLICY_ACCEPT_ALL &&
Harald Welte8c973ba2009-12-21 23:08:18 +0100384 !bts->si_common.rach_control.cell_bar)
Harald Welte36ab5452009-12-21 23:36:45 +0100385 LOGP(DNM, LOGL_ERROR, "\nWARNING: You are running an 'accept-all' "
Harald Welte395cb6b2009-12-12 13:44:19 +0100386 "network on a BTS that is not barred. This "
387 "configuration is likely to interfere with production "
388 "GSM networks and should only be used in a RF "
389 "shielded environment such as a faraday cage!\n\n");
390
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200391 /* Control Channel Description */
Harald Weltea54a2bb2009-12-01 18:04:30 +0530392 bts->si_common.chan_desc.att = 1;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530393 bts->si_common.chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
Harald Welte961ac532011-01-13 23:20:45 +0100394 bts->si_common.chan_desc.bs_ag_blks_res = 1;
395
Holger Hans Peter Freyther8c994342010-04-30 13:32:05 +0800396 /* T3212 is set from vty/config */
Sylvain Munaut63e014e2010-04-28 21:31:29 +0200397
Holger Hans Peter Freyther8c994342010-04-30 13:32:05 +0800398 /* Set ccch config by looking at ts config */
Sylvain Munaut63e014e2010-04-28 21:31:29 +0200399 for (n=0, i=0; i<8; i++)
400 n += bts->c0->ts[i].pchan == GSM_PCHAN_CCCH ? 1 : 0;
401
402 switch (n) {
403 case 0:
404 bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C;
405 break;
406 case 1:
407 bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_NC;
408 break;
409 case 2:
410 bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_2_NC;
411 break;
412 case 3:
413 bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_3_NC;
414 break;
415 case 4:
416 bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_4_NC;
417 break;
418 default:
419 LOGP(DNM, LOGL_ERROR, "Unsupported CCCH timeslot configuration\n");
420 return -EINVAL;
421 }
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200422
Harald Weltea54a2bb2009-12-01 18:04:30 +0530423 /* some defaults for our system information */
Holger Hans Peter Freyther21d63ff2010-09-06 09:25:48 +0800424 bts->si_common.cell_options.radio_link_timeout = 7; /* 12 */
425
426 /* allow/disallow DTXu */
427 if (bts->network->dtx_enabled)
428 bts->si_common.cell_options.dtx = 0;
429 else
Harald Welteea786a52011-01-15 18:06:34 +0100430 bts->si_common.cell_options.dtx = 2;
Holger Hans Peter Freyther21d63ff2010-09-06 09:25:48 +0800431
Harald Weltea54a2bb2009-12-01 18:04:30 +0530432 bts->si_common.cell_options.pwrc = 0; /* PWRC not set */
433
Harald Weltea54a2bb2009-12-01 18:04:30 +0530434 bts->si_common.cell_sel_par.acs = 0;
Harald Weltea54a2bb2009-12-01 18:04:30 +0530435
436 bts->si_common.ncc_permitted = 0xff;
437
Holger Hans Peter Freyther29cd72a2011-07-18 11:26:07 +0200438 /* Initialize the BTS state */
439 gsm_bts_mo_reset(bts);
440
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200441 return 0;
442}
443
Harald Welte5c05ed32010-12-23 01:07:46 +0100444int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *),
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200445 const char *config_file)
446{
Harald Welte40152872010-05-16 20:52:23 +0200447 struct telnet_connection dummy_conn;
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200448 struct gsm_bts *bts;
449 int rc;
450
451 /* initialize our data structures */
452 bsc_gsmnet = gsm_network_init(1, 1, mncc_recv);
453 if (!bsc_gsmnet)
454 return -ENOMEM;
455
456 bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC");
457 bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC");
458
Harald Welte40152872010-05-16 20:52:23 +0200459 /* our vty command code expects vty->priv to point to a telnet_connection */
460 dummy_conn.priv = bsc_gsmnet;
461 rc = vty_read_config_file(config_file, &dummy_conn);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200462 if (rc < 0) {
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100463 LOGP(DNM, LOGL_FATAL, "Failed to parse the config file: '%s'\n", config_file);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200464 return rc;
465 }
466
Harald Welte40152872010-05-16 20:52:23 +0200467 rc = telnet_init(tall_bsc_ctx, bsc_gsmnet, 4242);
468 if (rc < 0)
469 return rc;
470
Pablo Neira Ayusoef717c62011-05-06 12:12:31 +0200471 osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL);
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +0200472 osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL);
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200473
474 llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) {
Harald Welte08011e22011-03-04 13:41:31 +0100475 rc = bootstrap_bts(bts);
Pablo Neira Ayuso4726e7e2011-05-14 11:32:46 +0200476 if (rc < 0) {
477 LOGP(DNM, LOGL_FATAL, "Error bootstrapping BTS\n");
478 return rc;
479 }
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +0200480 rc = e1_reconfig_bts(bts);
Harald Weltea8497822011-02-05 15:41:24 +0100481 if (rc < 0) {
Pablo Neira Ayuso4726e7e2011-05-14 11:32:46 +0200482 LOGP(DNM, LOGL_FATAL, "Error enabling E1 input driver\n");
483 return rc;
Harald Weltea8497822011-02-05 15:41:24 +0100484 }
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200485 }
Holger Hans Peter Freythercad370f2009-08-17 06:55:10 +0200486 return 0;
487}