Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 1 | /* A hackish minimal BSC (+MSC +HLR) implementation */ |
| 2 | |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 8b457fb | 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 | 9af6ddf | 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 | 8b457fb | 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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 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 | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/gsm_data.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 23 | #include <osmocom/gsm/gsm_utils.h> |
Holger Hans Peter Freyther | 8b457fb | 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 | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 29 | #include <osmocom/vty/telnet_interface.h> |
Harald Welte | 55dc31e | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 30 | #include <osmocom/vty/ports.h> |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 31 | #include <openbsc/system_information.h> |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 32 | #include <openbsc/paging.h> |
| 33 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 34 | #include <openbsc/chan_alloc.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 35 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 39e6ba0 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 36 | #include <openbsc/ipaccess.h> |
Alexander Huemer | e1d2e1c | 2011-09-06 00:09:50 +0200 | [diff] [blame] | 37 | #include <osmocom/gsm/sysinfo.h> |
| 38 | #include <openbsc/e1_config.h> |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 39 | |
| 40 | /* global pointer to the gsm network data structure */ |
| 41 | extern struct gsm_network *bsc_gsmnet; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 42 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 43 | /* Callback function for NACK on the OML NM */ |
Holger Hans Peter Freyther | 6d2b66e | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 44 | static int oml_msg_nack(struct nm_nack_signal_data *nack) |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 45 | { |
Holger Hans Peter Freyther | 6d2b66e | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 46 | if (nack->mt == NM_MT_SET_BTS_ATTR_NACK) { |
Holger Hans Peter Freyther | 39e6ba0 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 47 | |
Holger Hans Peter Freyther | df82b72 | 2011-05-21 00:05:09 +0200 | [diff] [blame] | 48 | LOGP(DNM, LOGL_ERROR, "Failed to set BTS attributes. That is fatal. " |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 49 | "Was the bts type and frequency properly specified?\n"); |
Holger Hans Peter Freyther | df82b72 | 2011-05-21 00:05:09 +0200 | [diff] [blame] | 50 | goto drop_bts; |
Holger Hans Peter Freyther | 39e6ba0 | 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"); |
Holger Hans Peter Freyther | df82b72 | 2011-05-21 00:05:09 +0200 | [diff] [blame] | 53 | goto drop_bts; |
| 54 | } |
| 55 | |
| 56 | return 0; |
| 57 | |
| 58 | drop_bts: |
Holger Hans Peter Freyther | de1674a | 2012-11-11 18:26:23 +0100 | [diff] [blame] | 59 | if (!nack->bts) { |
| 60 | LOGP(DNM, LOGL_ERROR, "Unknown bts. Can not drop it.\n"); |
Harald Welte | d9173c3 | 2012-10-05 15:48:54 +0200 | [diff] [blame] | 61 | return 0; |
Holger Hans Peter Freyther | de1674a | 2012-11-11 18:26:23 +0100 | [diff] [blame] | 62 | } |
Harald Welte | d9173c3 | 2012-10-05 15:48:54 +0200 | [diff] [blame] | 63 | |
Holger Hans Peter Freyther | de1674a | 2012-11-11 18:26:23 +0100 | [diff] [blame] | 64 | if (is_ipaccess_bts(nack->bts)) |
| 65 | ipaccess_drop_oml(nack->bts); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | /* Callback function to be called every time we receive a signal from NM */ |
| 71 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 72 | void *handler_data, void *signal_data) |
| 73 | { |
Holger Hans Peter Freyther | 6d2b66e | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 74 | struct nm_nack_signal_data *nack; |
Harald Welte | d8cfc90 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 75 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 76 | switch (signal) { |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 77 | case S_NM_NACK: |
Holger Hans Peter Freyther | 6d2b66e | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 78 | nack = signal_data; |
| 79 | return oml_msg_nack(nack); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 80 | default: |
| 81 | break; |
| 82 | } |
| 83 | return 0; |
| 84 | } |
| 85 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 86 | int bsc_shutdown_net(struct gsm_network *net) |
| 87 | { |
| 88 | struct gsm_bts *bts; |
| 89 | |
| 90 | llist_for_each_entry(bts, &net->bts_list, list) { |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 91 | LOGP(DNM, LOGL_NOTICE, "shutting down OML for BTS %u\n", bts->nr); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 92 | osmo_signal_dispatch(SS_L_GLOBAL, S_GLOBAL_BTS_CLOSE_OM, bts); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 98 | static int rsl_si(struct gsm_bts_trx *trx, enum osmo_sysinfo_type i, int si_len) |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 99 | { |
| 100 | struct gsm_bts *bts = trx->bts; |
Holger Hans Peter Freyther | f0167dd | 2013-07-03 16:06:20 +0200 | [diff] [blame] | 101 | int rc; |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 102 | |
Harald Welte | 80cffaf | 2011-05-24 15:02:20 +0200 | [diff] [blame] | 103 | DEBUGP(DRR, "SI%s: %s\n", get_value_string(osmo_sitype_strs, i), |
Pablo Neira Ayuso | c0d17f2 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 104 | osmo_hexdump(GSM_BTS_SI(bts, i), GSM_MACBLOCK_LEN)); |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 105 | |
| 106 | switch (i) { |
| 107 | case SYSINFO_TYPE_5: |
| 108 | case SYSINFO_TYPE_5bis: |
| 109 | case SYSINFO_TYPE_5ter: |
| 110 | case SYSINFO_TYPE_6: |
Holger Hans Peter Freyther | f0167dd | 2013-07-03 16:06:20 +0200 | [diff] [blame] | 111 | rc = rsl_sacch_filling(trx, osmo_sitype2rsl(i), |
| 112 | GSM_BTS_SI(bts, i), si_len); |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 113 | break; |
| 114 | default: |
Harald Welte | 80cffaf | 2011-05-24 15:02:20 +0200 | [diff] [blame] | 115 | rc = rsl_bcch_info(trx, osmo_sitype2rsl(i), |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 116 | GSM_BTS_SI(bts, i), si_len); |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 117 | break; |
| 118 | } |
| 119 | |
| 120 | return rc; |
| 121 | } |
| 122 | |
Alexander Chemeris | c36a13b | 2015-05-30 14:40:54 -0400 | [diff] [blame] | 123 | /* set all system information types for a TRX */ |
Holger Hans Peter Freyther | a49b2c0 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 124 | int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx) |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 125 | { |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 126 | int i, rc; |
Harald Welte | 73d4fce | 2009-12-21 23:12:19 +0100 | [diff] [blame] | 127 | struct gsm_bts *bts = trx->bts; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 128 | uint8_t gen_si[_MAX_SYSINFO_TYPE], n_si = 0, n; |
| 129 | int si_len[_MAX_SYSINFO_TYPE]; |
Harald Welte | 73d4fce | 2009-12-21 23:12:19 +0100 | [diff] [blame] | 130 | |
| 131 | bts->si_common.cell_sel_par.ms_txpwr_max_ccch = |
| 132 | ms_pwr_ctl_lvl(bts->band, bts->ms_max_power); |
| 133 | bts->si_common.cell_sel_par.neci = bts->network->neci; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 134 | |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 135 | /* First, we determine which of the SI messages we actually need */ |
| 136 | |
Harald Welte | 7401ae6 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 137 | if (trx == bts->c0) { |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 138 | /* 1...4 are always present on a C0 TRX */ |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 139 | gen_si[n_si++] = SYSINFO_TYPE_1; |
| 140 | gen_si[n_si++] = SYSINFO_TYPE_2; |
| 141 | gen_si[n_si++] = SYSINFO_TYPE_2bis; |
| 142 | gen_si[n_si++] = SYSINFO_TYPE_2ter; |
| 143 | gen_si[n_si++] = SYSINFO_TYPE_3; |
| 144 | gen_si[n_si++] = SYSINFO_TYPE_4; |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 145 | |
| 146 | /* 13 is always present on a C0 TRX of a GPRS BTS */ |
| 147 | if (bts->gprs.mode != BTS_GPRS_NONE) |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 148 | gen_si[n_si++] = SYSINFO_TYPE_13; |
Harald Welte | 6a22c01 | 2009-12-21 17:02:32 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 151 | /* 5 and 6 are always present on every TRX */ |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 152 | gen_si[n_si++] = SYSINFO_TYPE_5; |
| 153 | gen_si[n_si++] = SYSINFO_TYPE_5bis; |
| 154 | gen_si[n_si++] = SYSINFO_TYPE_5ter; |
| 155 | gen_si[n_si++] = SYSINFO_TYPE_6; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 156 | |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 157 | /* Second, we generate the selected SI via RSL */ |
| 158 | |
| 159 | for (n = 0; n < n_si; n++) { |
| 160 | i = gen_si[n]; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 161 | /* Only generate SI if this SI is not in "static" (user-defined) mode */ |
| 162 | if (!(bts->si_mode_static & (1 << i))) { |
Andreas Eversberg | f2621e5 | 2013-01-08 19:33:42 +0100 | [diff] [blame] | 163 | /* Set SI as being valid. gsm_generate_si() might unset |
| 164 | * it, if SI is not required. */ |
| 165 | bts->si_valid |= (1 << i); |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 166 | rc = gsm_generate_si(bts, i); |
| 167 | if (rc < 0) |
| 168 | goto err_out; |
| 169 | si_len[i] = rc; |
| 170 | } else { |
| 171 | if (i == SYSINFO_TYPE_5 || i == SYSINFO_TYPE_5bis |
| 172 | || i == SYSINFO_TYPE_5ter) |
| 173 | si_len[i] = 18; |
| 174 | else if (i == SYSINFO_TYPE_6) |
| 175 | si_len[i] = 11; |
| 176 | else |
| 177 | si_len[i] = 23; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /* Third, we send the selected SI via RSL */ |
| 182 | |
Andreas Eversberg | f2621e5 | 2013-01-08 19:33:42 +0100 | [diff] [blame] | 183 | for (n = 0; n < n_si; n++) { |
| 184 | i = gen_si[n]; |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 185 | if (!(bts->si_valid & (1 << i))) |
| 186 | continue; |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 187 | rc = rsl_si(trx, i, si_len[i]); |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 188 | if (rc < 0) |
Andreas Eversberg | c50543b | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 189 | return rc; |
Harald Welte | 9fbff4a | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 190 | } |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 191 | |
| 192 | return 0; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 193 | err_out: |
Holger Hans Peter Freyther | 94c2b05 | 2012-10-09 10:52:33 +0200 | [diff] [blame] | 194 | LOGP(DRR, LOGL_ERROR, "Cannot generate SI%s for BTS %u, most likely " |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 195 | "a problem with neighbor cell list generation\n", |
Holger Hans Peter Freyther | 94c2b05 | 2012-10-09 10:52:33 +0200 | [diff] [blame] | 196 | get_value_string(osmo_sitype_strs, i), bts->nr); |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 197 | return rc; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Alexander Chemeris | c36a13b | 2015-05-30 14:40:54 -0400 | [diff] [blame] | 200 | /* set all system information types for a BTS */ |
| 201 | int gsm_bts_set_system_infos(struct gsm_bts *bts) |
| 202 | { |
| 203 | struct gsm_bts_trx *trx; |
| 204 | |
| 205 | /* Generate a new ID */ |
| 206 | bts->bcch_change_mark += 1; |
| 207 | bts->bcch_change_mark %= 0x7; |
| 208 | |
| 209 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 210 | int rc; |
| 211 | |
| 212 | rc = gsm_bts_trx_set_system_infos(trx); |
| 213 | if (rc != 0) |
| 214 | return rc; |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 220 | /* Produce a MA as specified in 10.5.2.21 */ |
| 221 | static int generate_ma_for_ts(struct gsm_bts_trx_ts *ts) |
| 222 | { |
| 223 | /* we have three bitvecs: the per-timeslot ARFCNs, the cell chan ARFCNs |
| 224 | * and the MA */ |
| 225 | struct bitvec *cell_chan = &ts->trx->bts->si_common.cell_alloc; |
| 226 | struct bitvec *ts_arfcn = &ts->hopping.arfcns; |
| 227 | struct bitvec *ma = &ts->hopping.ma; |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 228 | unsigned int num_cell_arfcns, bitnum, n_chan; |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 229 | int i; |
| 230 | |
| 231 | /* re-set the MA to all-zero */ |
| 232 | ma->cur_bit = 0; |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 233 | ts->hopping.ma_len = 0; |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 234 | memset(ma->data, 0, ma->data_len); |
| 235 | |
| 236 | if (!ts->hopping.enabled) |
| 237 | return 0; |
| 238 | |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 239 | /* count the number of ARFCNs in the cell channel allocation */ |
| 240 | num_cell_arfcns = 0; |
Harald Welte | 1fe73a1 | 2012-01-29 13:24:12 +0100 | [diff] [blame] | 241 | for (i = 0; i < 1024; i++) { |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 242 | if (bitvec_get_bit_pos(cell_chan, i)) |
| 243 | num_cell_arfcns++; |
| 244 | } |
| 245 | |
| 246 | /* pad it to octet-aligned number of bits */ |
| 247 | ts->hopping.ma_len = num_cell_arfcns / 8; |
| 248 | if (num_cell_arfcns % 8) |
| 249 | ts->hopping.ma_len++; |
| 250 | |
| 251 | n_chan = 0; |
Harald Welte | 1fe73a1 | 2012-01-29 13:24:12 +0100 | [diff] [blame] | 252 | for (i = 0; i < 1024; i++) { |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 253 | if (!bitvec_get_bit_pos(cell_chan, i)) |
| 254 | continue; |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 255 | /* set the corresponding bit in the MA */ |
| 256 | bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan; |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 257 | if (bitvec_get_bit_pos(ts_arfcn, i)) |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 258 | bitvec_set_bit_pos(ma, bitnum, 1); |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 259 | else |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 260 | bitvec_set_bit_pos(ma, bitnum, 0); |
laforge | abeb951 | 2010-06-20 15:56:50 +0200 | [diff] [blame] | 261 | n_chan++; |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* ARFCN 0 is special: It is coded last in the bitmask */ |
| 265 | if (bitvec_get_bit_pos(cell_chan, 0)) { |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 266 | n_chan++; |
| 267 | /* set the corresponding bit in the MA */ |
| 268 | bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan; |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 269 | if (bitvec_get_bit_pos(ts_arfcn, 0)) |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 270 | bitvec_set_bit_pos(ma, bitnum, 1); |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 271 | else |
Harald Welte | 29aca17 | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 272 | bitvec_set_bit_pos(ma, bitnum, 0); |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 278 | static void bootstrap_rsl(struct gsm_bts_trx *trx) |
| 279 | { |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 280 | unsigned int i; |
| 281 | |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 282 | LOGP(DRSL, LOGL_NOTICE, "bootstrapping RSL for BTS/TRX (%u/%u) " |
Harald Welte | 19a3f0b | 2009-12-24 13:39:34 +0100 | [diff] [blame] | 283 | "on ARFCN %u using MCC=%u MNC=%u LAC=%u CID=%u BSIC=%u TSC=%u\n", |
| 284 | trx->bts->nr, trx->nr, trx->arfcn, bsc_gsmnet->country_code, |
| 285 | bsc_gsmnet->network_code, trx->bts->location_area_code, |
| 286 | trx->bts->cell_identity, trx->bts->bsic, trx->bts->tsc); |
Dieter Spaar | 1664602 | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 287 | |
| 288 | if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) { |
| 289 | rsl_nokia_si_begin(trx); |
| 290 | } |
| 291 | |
Holger Hans Peter Freyther | a49b2c0 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 292 | gsm_bts_trx_set_system_infos(trx); |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 293 | |
Dieter Spaar | 1664602 | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 294 | if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) { |
| 295 | /* channel unspecific, power reduction in 2 dB steps */ |
| 296 | rsl_bs_power_control(trx, 0xFF, trx->max_power_red / 2); |
| 297 | rsl_nokia_si_end(trx); |
| 298 | } |
| 299 | |
Harald Welte | fd37089 | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 300 | for (i = 0; i < ARRAY_SIZE(trx->ts); i++) |
| 301 | generate_ma_for_ts(&trx->ts[i]); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 302 | } |
| 303 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 304 | /* Callback function to be called every time we receive a signal from INPUT */ |
| 305 | static int inp_sig_cb(unsigned int subsys, unsigned int signal, |
| 306 | void *handler_data, void *signal_data) |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 307 | { |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 308 | struct input_signal_data *isd = signal_data; |
| 309 | struct gsm_bts_trx *trx = isd->trx; |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 310 | int ts_no, lchan_no; |
| 311 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 312 | if (subsys != SS_L_INPUT) |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 313 | return -EINVAL; |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 314 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 315 | switch (signal) { |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 316 | case S_L_INP_TEI_UP: |
Dieter Spaar | 1664602 | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 317 | if (isd->link_type == E1INP_SIGN_OML) { |
| 318 | /* TODO: this is required for the Nokia BTS, hopping is configured |
| 319 | during OML, other MA is not set. */ |
| 320 | struct gsm_bts_trx *cur_trx; |
| 321 | /* was static in system_information.c */ |
| 322 | extern int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts); |
| 323 | uint8_t ca[20]; |
| 324 | /* has to be called before generate_ma_for_ts to |
| 325 | set bts->si_common.cell_alloc */ |
| 326 | generate_cell_chan_list(ca, trx->bts); |
| 327 | |
| 328 | llist_for_each_entry(cur_trx, &trx->bts->trx_list, list) { |
| 329 | int i; |
| 330 | |
| 331 | for (i = 0; i < ARRAY_SIZE(cur_trx->ts); i++) |
| 332 | generate_ma_for_ts(&cur_trx->ts[i]); |
| 333 | } |
| 334 | } |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 335 | if (isd->link_type == E1INP_SIGN_RSL) |
| 336 | bootstrap_rsl(trx); |
| 337 | break; |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 338 | case S_L_INP_TEI_DN: |
| 339 | LOGP(DLMI, LOGL_ERROR, "Lost some E1 TEI link: %d %p\n", isd->link_type, trx); |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 340 | |
| 341 | if (isd->link_type == E1INP_SIGN_OML) |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 342 | osmo_counter_inc(trx->bts->network->stats.bts.oml_fail); |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 343 | else if (isd->link_type == E1INP_SIGN_RSL) |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 344 | osmo_counter_inc(trx->bts->network->stats.bts.rsl_fail); |
Holger Hans Peter Freyther | bb110f9 | 2010-04-12 10:45:52 +0200 | [diff] [blame] | 345 | |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 346 | /* |
| 347 | * free all allocated channels. change the nm_state so the |
| 348 | * trx and trx_ts becomes unusable and chan_alloc.c can not |
| 349 | * allocate from it. |
| 350 | */ |
| 351 | for (ts_no = 0; ts_no < ARRAY_SIZE(trx->ts); ++ts_no) { |
| 352 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_no]; |
| 353 | |
| 354 | for (lchan_no = 0; lchan_no < ARRAY_SIZE(ts->lchan); ++lchan_no) { |
Holger Hans Peter Freyther | 4dc025b | 2010-08-25 12:29:24 +0800 | [diff] [blame] | 355 | if (ts->lchan[lchan_no].state != LCHAN_S_NONE) |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 356 | lchan_free(&ts->lchan[lchan_no]); |
| 357 | lchan_reset(&ts->lchan[lchan_no]); |
| 358 | } |
Holger Hans Peter Freyther | 135f797 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Harald Welte | b784998 | 2011-06-29 16:49:03 +0200 | [diff] [blame] | 361 | gsm_bts_mo_reset(trx->bts); |
Holger Hans Peter Freyther | 6f61555 | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 362 | |
| 363 | abis_nm_clear_queue(trx->bts); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 364 | break; |
| 365 | default: |
| 366 | break; |
| 367 | } |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 368 | |
| 369 | return 0; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static int bootstrap_bts(struct gsm_bts *bts) |
| 373 | { |
Sylvain Munaut | 50f81b0 | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 374 | int i, n; |
| 375 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 376 | if (bts->model->start && !bts->model->started) { |
| 377 | int ret = bts->model->start(bts->network); |
| 378 | if (ret < 0) |
| 379 | return ret; |
| 380 | |
| 381 | bts->model->started = true; |
| 382 | } |
| 383 | |
Harald Welte | 71b822b | 2010-05-26 17:14:42 +0200 | [diff] [blame] | 384 | /* FIXME: What about secondary TRX of a BTS? What about a BTS that has TRX |
| 385 | * in different bands? Why is 'band' a parameter of the BTS and not of the TRX? */ |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 386 | switch (bts->band) { |
| 387 | case GSM_BAND_1800: |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 388 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 389 | LOGP(DNM, LOGL_ERROR, "GSM1800 channel must be between 512-885.\n"); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 390 | return -EINVAL; |
| 391 | } |
| 392 | break; |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 393 | case GSM_BAND_1900: |
| 394 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 395 | LOGP(DNM, LOGL_ERROR, "GSM1900 channel must be between 512-810.\n"); |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 396 | return -EINVAL; |
| 397 | } |
| 398 | break; |
| 399 | case GSM_BAND_900: |
Michael McTernan | c58a1e5 | 2015-06-19 20:51:43 +0200 | [diff] [blame] | 400 | if (bts->c0->arfcn < 0 || |
Holger Hans Peter Freyther | fb0b6fc | 2010-02-09 15:44:14 +0100 | [diff] [blame] | 401 | (bts->c0->arfcn > 124 && bts->c0->arfcn < 955) || |
| 402 | bts->c0->arfcn > 1023) { |
Michael McTernan | c58a1e5 | 2015-06-19 20:51:43 +0200 | [diff] [blame] | 403 | LOGP(DNM, LOGL_ERROR, "GSM900 channel must be between 0-124, 955-1023.\n"); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 404 | return -EINVAL; |
| 405 | } |
| 406 | break; |
Harald Welte | 71b822b | 2010-05-26 17:14:42 +0200 | [diff] [blame] | 407 | case GSM_BAND_850: |
| 408 | if (bts->c0->arfcn < 128 || bts->c0->arfcn > 251) { |
| 409 | LOGP(DNM, LOGL_ERROR, "GSM850 channel must be between 128-251.\n"); |
| 410 | return -EINVAL; |
| 411 | } |
| 412 | break; |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 413 | default: |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 414 | LOGP(DNM, LOGL_ERROR, "Unsupported frequency band.\n"); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 415 | return -EINVAL; |
| 416 | } |
| 417 | |
Harald Welte | d6aa524 | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 418 | if (bts->network->auth_policy == GSM_AUTH_POLICY_ACCEPT_ALL && |
Harald Welte | 7135501 | 2009-12-21 23:08:18 +0100 | [diff] [blame] | 419 | !bts->si_common.rach_control.cell_bar) |
Harald Welte | a992a36 | 2009-12-21 23:36:45 +0100 | [diff] [blame] | 420 | LOGP(DNM, LOGL_ERROR, "\nWARNING: You are running an 'accept-all' " |
Harald Welte | d6aa524 | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 421 | "network on a BTS that is not barred. This " |
| 422 | "configuration is likely to interfere with production " |
| 423 | "GSM networks and should only be used in a RF " |
| 424 | "shielded environment such as a faraday cage!\n\n"); |
| 425 | |
Andreas Eversberg | 2ee7ecd | 2012-10-13 07:27:47 +0200 | [diff] [blame] | 426 | /* Control Channel Description is set from vty/config */ |
Harald Welte | aace9fc | 2011-01-13 23:20:45 +0100 | [diff] [blame] | 427 | |
Holger Hans Peter Freyther | a581136 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 428 | /* T3212 is set from vty/config */ |
Sylvain Munaut | 50f81b0 | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 429 | |
Holger Hans Peter Freyther | a581136 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 430 | /* Set ccch config by looking at ts config */ |
Sylvain Munaut | 50f81b0 | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 431 | for (n=0, i=0; i<8; i++) |
| 432 | n += bts->c0->ts[i].pchan == GSM_PCHAN_CCCH ? 1 : 0; |
| 433 | |
| 434 | switch (n) { |
| 435 | case 0: |
| 436 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C; |
Andreas Eversberg | 2ee7ecd | 2012-10-13 07:27:47 +0200 | [diff] [blame] | 437 | /* Limit reserved block to 2 on combined channel */ |
| 438 | if (bts->si_common.chan_desc.bs_ag_blks_res > 2) |
| 439 | bts->si_common.chan_desc.bs_ag_blks_res = 2; |
Sylvain Munaut | 50f81b0 | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 440 | break; |
| 441 | case 1: |
| 442 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_NC; |
| 443 | break; |
| 444 | case 2: |
| 445 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_2_NC; |
| 446 | break; |
| 447 | case 3: |
| 448 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_3_NC; |
| 449 | break; |
| 450 | case 4: |
| 451 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_4_NC; |
| 452 | break; |
| 453 | default: |
| 454 | LOGP(DNM, LOGL_ERROR, "Unsupported CCCH timeslot configuration\n"); |
| 455 | return -EINVAL; |
| 456 | } |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 457 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 458 | /* some defaults for our system information */ |
Holger Hans Peter Freyther | 5a3a61d | 2010-09-06 09:25:48 +0800 | [diff] [blame] | 459 | bts->si_common.cell_options.radio_link_timeout = 7; /* 12 */ |
| 460 | |
| 461 | /* allow/disallow DTXu */ |
| 462 | if (bts->network->dtx_enabled) |
| 463 | bts->si_common.cell_options.dtx = 0; |
| 464 | else |
Harald Welte | 17a7634 | 2011-01-15 18:06:34 +0100 | [diff] [blame] | 465 | bts->si_common.cell_options.dtx = 2; |
Holger Hans Peter Freyther | 5a3a61d | 2010-09-06 09:25:48 +0800 | [diff] [blame] | 466 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 467 | bts->si_common.cell_options.pwrc = 0; /* PWRC not set */ |
| 468 | |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 469 | bts->si_common.cell_sel_par.acs = 0; |
Harald Welte | a43f789 | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 470 | |
| 471 | bts->si_common.ncc_permitted = 0xff; |
| 472 | |
Holger Hans Peter Freyther | fe1ca35 | 2011-07-18 11:26:07 +0200 | [diff] [blame] | 473 | /* Initialize the BTS state */ |
| 474 | gsm_bts_mo_reset(bts); |
| 475 | |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 479 | int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *), |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 480 | const char *config_file) |
| 481 | { |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 482 | struct telnet_connection dummy_conn; |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 483 | struct gsm_bts *bts; |
| 484 | int rc; |
| 485 | |
| 486 | /* initialize our data structures */ |
| 487 | bsc_gsmnet = gsm_network_init(1, 1, mncc_recv); |
| 488 | if (!bsc_gsmnet) |
| 489 | return -ENOMEM; |
| 490 | |
| 491 | bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 492 | bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 493 | |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 494 | /* our vty command code expects vty->priv to point to a telnet_connection */ |
| 495 | dummy_conn.priv = bsc_gsmnet; |
| 496 | rc = vty_read_config_file(config_file, &dummy_conn); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 497 | if (rc < 0) { |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 498 | LOGP(DNM, LOGL_FATAL, "Failed to parse the config file: '%s'\n", config_file); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 499 | return rc; |
| 500 | } |
| 501 | |
Harald Welte | 55dc31e | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 502 | rc = telnet_init(tall_bsc_ctx, bsc_gsmnet, OSMO_VTY_PORT_NITB_BSC); |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 503 | if (rc < 0) |
| 504 | return rc; |
| 505 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 506 | osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 507 | osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL); |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 508 | |
| 509 | llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) { |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 510 | rc = bootstrap_bts(bts); |
Pablo Neira Ayuso | 6e52b88 | 2011-05-14 11:32:46 +0200 | [diff] [blame] | 511 | if (rc < 0) { |
| 512 | LOGP(DNM, LOGL_FATAL, "Error bootstrapping BTS\n"); |
| 513 | return rc; |
| 514 | } |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 515 | rc = e1_reconfig_bts(bts); |
Harald Welte | 889f16e | 2011-02-05 15:41:24 +0100 | [diff] [blame] | 516 | if (rc < 0) { |
Pablo Neira Ayuso | 6e52b88 | 2011-05-14 11:32:46 +0200 | [diff] [blame] | 517 | LOGP(DNM, LOGL_FATAL, "Error enabling E1 input driver\n"); |
| 518 | return rc; |
Harald Welte | 889f16e | 2011-02-05 15:41:24 +0100 | [diff] [blame] | 519 | } |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 520 | } |
Holger Hans Peter Freyther | 8b457fb | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 521 | return 0; |
| 522 | } |