Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 1 | /* A hackish minimal BSC (+MSC +HLR) implementation */ |
| 2 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 4 | * (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 Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * 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 Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 10 | * (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 Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * 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 Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/gsm_data.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 23 | #include <osmocom/gsm/gsm_utils.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 24 | #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 Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 29 | #include <osmocom/vty/telnet_interface.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 30 | #include <openbsc/system_information.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 31 | #include <openbsc/paging.h> |
| 32 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 33 | #include <openbsc/chan_alloc.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 34 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 82260a6 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 35 | #include <openbsc/ipaccess.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 36 | |
| 37 | /* global pointer to the gsm network data structure */ |
| 38 | extern struct gsm_network *bsc_gsmnet; |
Holger Hans Peter Freyther | 6f2312e | 2011-04-07 23:34:54 +0200 | [diff] [blame] | 39 | extern int hsl_setup(struct gsm_network *gsmnet); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 40 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 41 | /* Callback function for NACK on the OML NM */ |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 42 | static int oml_msg_nack(struct nm_nack_signal_data *nack) |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 43 | { |
Holger Hans Peter Freyther | 82260a6 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 44 | int i; |
| 45 | |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 46 | if (nack->mt == NM_MT_SET_BTS_ATTR_NACK) { |
Holger Hans Peter Freyther | 82260a6 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 47 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 48 | LOGP(DNM, LOGL_FATAL, "Failed to set BTS attributes. That is fatal. " |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 49 | "Was the bts type and frequency properly specified?\n"); |
| 50 | exit(-1); |
Holger Hans Peter Freyther | 82260a6 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 51 | } 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 Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | /* Callback function to be called every time we receive a signal from NM */ |
| 64 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 65 | void *handler_data, void *signal_data) |
| 66 | { |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 67 | struct nm_nack_signal_data *nack; |
Harald Welte | 6a21c73 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 68 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 69 | switch (signal) { |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 70 | case S_NM_NACK: |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 71 | nack = signal_data; |
| 72 | return oml_msg_nack(nack); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 73 | default: |
| 74 | break; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 79 | int 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 Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 84 | LOGP(DNM, LOGL_NOTICE, "shutting down OML for BTS %u\n", bts->nr); |
| 85 | dispatch_signal(SS_GLOBAL, S_GLOBAL_BTS_CLOSE_OM, bts); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 91 | static int generate_and_rsl_si(struct gsm_bts_trx *trx, enum osmo_sysinfo_type i) |
| 92 | { |
| 93 | struct gsm_bts *bts = trx->bts; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 94 | int si_len, rc, j; |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 95 | |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 96 | /* 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 Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 101 | si_len = rc; |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 102 | } |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 103 | |
| 104 | DEBUGP(DRR, "SI%s: %s\n", gsm_sitype_name(i), |
| 105 | hexdump(GSM_BTS_SI(bts, i), GSM_MACBLOCK_LEN)); |
| 106 | |
| 107 | switch (i) { |
| 108 | case SYSINFO_TYPE_5: |
| 109 | case SYSINFO_TYPE_5bis: |
| 110 | case SYSINFO_TYPE_5ter: |
| 111 | case SYSINFO_TYPE_6: |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 112 | 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], |
| 118 | gsm_sitype2rsl(i), |
| 119 | GSM_BTS_SI(bts, i), si_len); |
| 120 | for (j = 1; j < 8; j++) { |
| 121 | rsl_sacch_info_modify(&trx->ts[j].lchan[0], |
| 122 | gsm_sitype2rsl(i), |
| 123 | GSM_BTS_SI(bts, i), si_len); |
| 124 | rsl_sacch_info_modify(&trx->ts[j].lchan[1], |
| 125 | gsm_sitype2rsl(i), |
| 126 | GSM_BTS_SI(bts, i), si_len); |
| 127 | } |
| 128 | } else |
| 129 | rc = rsl_sacch_filling(trx, gsm_sitype2rsl(i), |
| 130 | GSM_BTS_SI(bts, i), rc); |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 131 | break; |
| 132 | default: |
| 133 | rc = rsl_bcch_info(trx, gsm_sitype2rsl(i), |
| 134 | GSM_BTS_SI(bts, i), rc); |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | return rc; |
| 139 | } |
| 140 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 141 | /* set all system information types */ |
| 142 | static int set_system_infos(struct gsm_bts_trx *trx) |
| 143 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 144 | int i, rc; |
Harald Welte | 36e5a79 | 2009-12-21 23:12:19 +0100 | [diff] [blame] | 145 | 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 Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 150 | |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 151 | /* First, we determine which of the SI messages we actually need */ |
| 152 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 153 | if (trx == bts->c0) { |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 154 | /* 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 Welte | 28fc963 | 2009-12-21 17:02:32 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 163 | /* 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 Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 166 | |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 167 | /* 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 Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 176 | |
| 177 | return 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 178 | err_out: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 179 | LOGP(DRR, LOGL_ERROR, "Cannot generate SI %u for BTS %u, most likely " |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 180 | "a problem with neighbor cell list generation\n", |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 181 | i, bts->nr); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 182 | return rc; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 185 | /* Produce a MA as specified in 10.5.2.21 */ |
| 186 | static 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 Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 193 | unsigned int num_cell_arfcns, bitnum, n_chan; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 194 | int i; |
| 195 | |
| 196 | /* re-set the MA to all-zero */ |
| 197 | ma->cur_bit = 0; |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 198 | ts->hopping.ma_len = 0; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 199 | memset(ma->data, 0, ma->data_len); |
| 200 | |
| 201 | if (!ts->hopping.enabled) |
| 202 | return 0; |
| 203 | |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 204 | /* 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 Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 217 | for (i = 1; i < 1024; i++) { |
| 218 | if (!bitvec_get_bit_pos(cell_chan, i)) |
| 219 | continue; |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 220 | /* set the corresponding bit in the MA */ |
| 221 | bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 222 | if (bitvec_get_bit_pos(ts_arfcn, i)) |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 223 | bitvec_set_bit_pos(ma, bitnum, 1); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 224 | else |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 225 | bitvec_set_bit_pos(ma, bitnum, 0); |
laforge | 1dcdc95 | 2010-06-20 15:56:50 +0200 | [diff] [blame] | 226 | n_chan++; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* ARFCN 0 is special: It is coded last in the bitmask */ |
| 230 | if (bitvec_get_bit_pos(cell_chan, 0)) { |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 231 | n_chan++; |
| 232 | /* set the corresponding bit in the MA */ |
| 233 | bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 234 | if (bitvec_get_bit_pos(ts_arfcn, 0)) |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 235 | bitvec_set_bit_pos(ma, bitnum, 1); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 236 | else |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 237 | bitvec_set_bit_pos(ma, bitnum, 0); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 243 | static void bootstrap_rsl(struct gsm_bts_trx *trx) |
| 244 | { |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 245 | unsigned int i; |
| 246 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 247 | LOGP(DRSL, LOGL_NOTICE, "bootstrapping RSL for BTS/TRX (%u/%u) " |
Harald Welte | 424873e | 2009-12-24 13:39:34 +0100 | [diff] [blame] | 248 | "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); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 252 | set_system_infos(trx); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 253 | |
| 254 | for (i = 0; i < ARRAY_SIZE(trx->ts); i++) |
| 255 | generate_ma_for_ts(&trx->ts[i]); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 258 | /* Callback function to be called every time we receive a signal from INPUT */ |
| 259 | static int inp_sig_cb(unsigned int subsys, unsigned int signal, |
| 260 | void *handler_data, void *signal_data) |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 261 | { |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 262 | struct input_signal_data *isd = signal_data; |
| 263 | struct gsm_bts_trx *trx = isd->trx; |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 264 | int ts_no, lchan_no; |
| 265 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 266 | if (subsys != SS_INPUT) |
| 267 | return -EINVAL; |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 268 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 269 | switch (signal) { |
| 270 | case S_INP_TEI_UP: |
| 271 | if (isd->link_type == E1INP_SIGN_RSL) |
| 272 | bootstrap_rsl(trx); |
| 273 | break; |
| 274 | case S_INP_TEI_DN: |
| 275 | LOGP(DMI, LOGL_ERROR, "Lost some E1 TEI link: %d %p\n", isd->link_type, trx); |
| 276 | |
| 277 | if (isd->link_type == E1INP_SIGN_OML) |
Holger Hans Peter Freyther | 3e09b3f | 2010-04-12 10:45:52 +0200 | [diff] [blame] | 278 | counter_inc(trx->bts->network->stats.bts.oml_fail); |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 279 | else if (isd->link_type == E1INP_SIGN_RSL) |
Holger Hans Peter Freyther | 3e09b3f | 2010-04-12 10:45:52 +0200 | [diff] [blame] | 280 | counter_inc(trx->bts->network->stats.bts.rsl_fail); |
| 281 | |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 282 | /* |
| 283 | * free all allocated channels. change the nm_state so the |
| 284 | * trx and trx_ts becomes unusable and chan_alloc.c can not |
| 285 | * allocate from it. |
| 286 | */ |
| 287 | for (ts_no = 0; ts_no < ARRAY_SIZE(trx->ts); ++ts_no) { |
| 288 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_no]; |
| 289 | |
| 290 | for (lchan_no = 0; lchan_no < ARRAY_SIZE(ts->lchan); ++lchan_no) { |
Holger Hans Peter Freyther | ade87dd | 2010-08-25 12:29:24 +0800 | [diff] [blame] | 291 | if (ts->lchan[lchan_no].state != LCHAN_S_NONE) |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 292 | lchan_free(&ts->lchan[lchan_no]); |
| 293 | lchan_reset(&ts->lchan[lchan_no]); |
| 294 | } |
| 295 | |
| 296 | ts->nm_state.operational = 0; |
| 297 | ts->nm_state.availability = 0; |
| 298 | } |
| 299 | |
| 300 | trx->nm_state.operational = 0; |
| 301 | trx->nm_state.availability = 0; |
| 302 | trx->bb_transc.nm_state.operational = 0; |
| 303 | trx->bb_transc.nm_state.availability = 0; |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 304 | |
| 305 | abis_nm_clear_queue(trx->bts); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 306 | break; |
| 307 | default: |
| 308 | break; |
| 309 | } |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 310 | |
| 311 | return 0; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static int bootstrap_bts(struct gsm_bts *bts) |
| 315 | { |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 316 | int i, n; |
| 317 | |
Harald Welte | eee698b | 2010-05-26 17:14:42 +0200 | [diff] [blame] | 318 | /* FIXME: What about secondary TRX of a BTS? What about a BTS that has TRX |
| 319 | * in different bands? Why is 'band' a parameter of the BTS and not of the TRX? */ |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 320 | switch (bts->band) { |
| 321 | case GSM_BAND_1800: |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 322 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 323 | LOGP(DNM, LOGL_ERROR, "GSM1800 channel must be between 512-885.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 324 | return -EINVAL; |
| 325 | } |
| 326 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 327 | case GSM_BAND_1900: |
| 328 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 329 | LOGP(DNM, LOGL_ERROR, "GSM1900 channel must be between 512-810.\n"); |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 330 | return -EINVAL; |
| 331 | } |
| 332 | break; |
| 333 | case GSM_BAND_900: |
Holger Hans Peter Freyther | 2ba2b33 | 2010-02-09 15:44:14 +0100 | [diff] [blame] | 334 | if (bts->c0->arfcn < 1 || |
| 335 | (bts->c0->arfcn > 124 && bts->c0->arfcn < 955) || |
| 336 | bts->c0->arfcn > 1023) { |
| 337 | LOGP(DNM, LOGL_ERROR, "GSM900 channel must be between 1-124, 955-1023.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 338 | return -EINVAL; |
| 339 | } |
| 340 | break; |
Harald Welte | eee698b | 2010-05-26 17:14:42 +0200 | [diff] [blame] | 341 | case GSM_BAND_850: |
| 342 | if (bts->c0->arfcn < 128 || bts->c0->arfcn > 251) { |
| 343 | LOGP(DNM, LOGL_ERROR, "GSM850 channel must be between 128-251.\n"); |
| 344 | return -EINVAL; |
| 345 | } |
| 346 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 347 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 348 | LOGP(DNM, LOGL_ERROR, "Unsupported frequency band.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 349 | return -EINVAL; |
| 350 | } |
| 351 | |
Harald Welte | 395cb6b | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 352 | if (bts->network->auth_policy == GSM_AUTH_POLICY_ACCEPT_ALL && |
Harald Welte | 8c973ba | 2009-12-21 23:08:18 +0100 | [diff] [blame] | 353 | !bts->si_common.rach_control.cell_bar) |
Harald Welte | 36ab545 | 2009-12-21 23:36:45 +0100 | [diff] [blame] | 354 | LOGP(DNM, LOGL_ERROR, "\nWARNING: You are running an 'accept-all' " |
Harald Welte | 395cb6b | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 355 | "network on a BTS that is not barred. This " |
| 356 | "configuration is likely to interfere with production " |
| 357 | "GSM networks and should only be used in a RF " |
| 358 | "shielded environment such as a faraday cage!\n\n"); |
| 359 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 360 | /* Control Channel Description */ |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 361 | bts->si_common.chan_desc.att = 1; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 362 | bts->si_common.chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5; |
Harald Welte | 961ac53 | 2011-01-13 23:20:45 +0100 | [diff] [blame] | 363 | bts->si_common.chan_desc.bs_ag_blks_res = 1; |
| 364 | |
Holger Hans Peter Freyther | 8c99434 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 365 | /* T3212 is set from vty/config */ |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 366 | |
Holger Hans Peter Freyther | 8c99434 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 367 | /* Set ccch config by looking at ts config */ |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 368 | for (n=0, i=0; i<8; i++) |
| 369 | n += bts->c0->ts[i].pchan == GSM_PCHAN_CCCH ? 1 : 0; |
| 370 | |
| 371 | switch (n) { |
| 372 | case 0: |
| 373 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C; |
| 374 | break; |
| 375 | case 1: |
| 376 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_NC; |
| 377 | break; |
| 378 | case 2: |
| 379 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_2_NC; |
| 380 | break; |
| 381 | case 3: |
| 382 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_3_NC; |
| 383 | break; |
| 384 | case 4: |
| 385 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_4_NC; |
| 386 | break; |
| 387 | default: |
| 388 | LOGP(DNM, LOGL_ERROR, "Unsupported CCCH timeslot configuration\n"); |
| 389 | return -EINVAL; |
| 390 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 391 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 392 | /* some defaults for our system information */ |
Holger Hans Peter Freyther | 21d63ff | 2010-09-06 09:25:48 +0800 | [diff] [blame] | 393 | bts->si_common.cell_options.radio_link_timeout = 7; /* 12 */ |
| 394 | |
| 395 | /* allow/disallow DTXu */ |
| 396 | if (bts->network->dtx_enabled) |
| 397 | bts->si_common.cell_options.dtx = 0; |
| 398 | else |
Harald Welte | ea786a5 | 2011-01-15 18:06:34 +0100 | [diff] [blame] | 399 | bts->si_common.cell_options.dtx = 2; |
Holger Hans Peter Freyther | 21d63ff | 2010-09-06 09:25:48 +0800 | [diff] [blame] | 400 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 401 | bts->si_common.cell_options.pwrc = 0; /* PWRC not set */ |
| 402 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 403 | bts->si_common.cell_sel_par.acs = 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 404 | |
| 405 | bts->si_common.ncc_permitted = 0xff; |
| 406 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 410 | int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *), |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 411 | const char *config_file) |
| 412 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 413 | struct telnet_connection dummy_conn; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 414 | struct gsm_bts *bts; |
| 415 | int rc; |
| 416 | |
| 417 | /* initialize our data structures */ |
| 418 | bsc_gsmnet = gsm_network_init(1, 1, mncc_recv); |
| 419 | if (!bsc_gsmnet) |
| 420 | return -ENOMEM; |
| 421 | |
| 422 | bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 423 | bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 424 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 425 | /* our vty command code expects vty->priv to point to a telnet_connection */ |
| 426 | dummy_conn.priv = bsc_gsmnet; |
| 427 | rc = vty_read_config_file(config_file, &dummy_conn); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 428 | if (rc < 0) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 429 | LOGP(DNM, LOGL_FATAL, "Failed to parse the config file: '%s'\n", config_file); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 430 | return rc; |
| 431 | } |
| 432 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 433 | rc = telnet_init(tall_bsc_ctx, bsc_gsmnet, 4242); |
| 434 | if (rc < 0) |
| 435 | return rc; |
| 436 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 437 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 438 | register_signal_handler(SS_INPUT, inp_sig_cb, NULL); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 439 | |
| 440 | llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) { |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 441 | rc = bootstrap_bts(bts); |
| 442 | |
| 443 | switch (bts->type) { |
| 444 | case GSM_BTS_TYPE_NANOBTS: |
| 445 | case GSM_BTS_TYPE_HSL_FEMTO: |
| 446 | break; |
| 447 | default: |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 448 | rc = e1_reconfig_bts(bts); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 449 | break; |
| 450 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 451 | |
Harald Welte | a849782 | 2011-02-05 15:41:24 +0100 | [diff] [blame] | 452 | if (rc < 0) { |
| 453 | fprintf(stderr, "Error in E1 input driver setup\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 454 | exit (1); |
Harald Welte | a849782 | 2011-02-05 15:41:24 +0100 | [diff] [blame] | 455 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* initialize nanoBTS support omce */ |
| 459 | rc = ipaccess_setup(bsc_gsmnet); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 460 | rc = hsl_setup(bsc_gsmnet); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 461 | |
| 462 | return 0; |
| 463 | } |