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 | 6bcd303 | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 30 | #include <osmocom/vty/ports.h> |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 31 | #include <openbsc/system_information.h> |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 32 | #include <openbsc/paging.h> |
| 33 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 34 | #include <openbsc/chan_alloc.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 35 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 82260a6 | 2010-11-15 20:43:02 +0100 | [diff] [blame] | 36 | #include <openbsc/ipaccess.h> |
Alexander Huemer | 6489afd | 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 | cad370f | 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 | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 42 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 43 | /* Callback function for NACK on the OML NM */ |
Holger Hans Peter Freyther | dfea6c8 | 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 | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 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 | |
Holger Hans Peter Freyther | 860efdf | 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 | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 49 | "Was the bts type and frequency properly specified?\n"); |
Holger Hans Peter Freyther | 860efdf | 2011-05-21 00:05:09 +0200 | [diff] [blame] | 50 | goto drop_bts; |
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"); |
Holger Hans Peter Freyther | 860efdf | 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 | 70f1e47 | 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 | f8878b3 | 2012-10-05 15:48:54 +0200 | [diff] [blame] | 61 | return 0; |
Holger Hans Peter Freyther | 70f1e47 | 2012-11-11 18:26:23 +0100 | [diff] [blame] | 62 | } |
Harald Welte | f8878b3 | 2012-10-05 15:48:54 +0200 | [diff] [blame] | 63 | |
Holger Hans Peter Freyther | 70f1e47 | 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 | cad370f | 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 | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 74 | struct nm_nack_signal_data *nack; |
Harald Welte | 6a21c73 | 2009-11-17 06:09:56 +0100 | [diff] [blame] | 75 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 76 | switch (signal) { |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 77 | case S_NM_NACK: |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 78 | nack = signal_data; |
| 79 | return oml_msg_nack(nack); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 80 | default: |
| 81 | break; |
| 82 | } |
| 83 | return 0; |
| 84 | } |
| 85 | |
Holger Hans Peter Freyther | cad370f | 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 | 4c826f7 | 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 | 42e41df | 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 | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
Andreas Eversberg | 02de47d | 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 | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 99 | { |
| 100 | struct gsm_bts *bts = trx->bts; |
Holger Hans Peter Freyther | 1b0af51 | 2013-07-03 16:06:20 +0200 | [diff] [blame] | 101 | int rc; |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 102 | |
Harald Welte | 6b77f0f | 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 | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 104 | osmo_hexdump(GSM_BTS_SI(bts, i), GSM_MACBLOCK_LEN)); |
Harald Welte | 99bed52 | 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 | 1b0af51 | 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 | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 113 | break; |
| 114 | default: |
Harald Welte | 6b77f0f | 2011-05-24 15:02:20 +0200 | [diff] [blame] | 115 | rc = rsl_bcch_info(trx, osmo_sitype2rsl(i), |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 116 | GSM_BTS_SI(bts, i), si_len); |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 117 | break; |
| 118 | } |
| 119 | |
| 120 | return rc; |
| 121 | } |
| 122 | |
Alexander Chemeris | 143ac5f | 2015-05-30 14:40:54 -0400 | [diff] [blame] | 123 | /* set all system information types for a TRX */ |
Holger Hans Peter Freyther | d0284c8 | 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 | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 125 | { |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 126 | int i, rc; |
Harald Welte | 36e5a79 | 2009-12-21 23:12:19 +0100 | [diff] [blame] | 127 | struct gsm_bts *bts = trx->bts; |
Andreas Eversberg | 02de47d | 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 | 36e5a79 | 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 | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 134 | |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 135 | /* First, we determine which of the SI messages we actually need */ |
| 136 | |
Harald Welte | 99bed52 | 2010-06-15 16:44:12 +0200 | [diff] [blame] | 137 | if (trx == bts->c0) { |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 138 | /* 1...4 are always present on a C0 TRX */ |
Andreas Eversberg | 02de47d | 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; |
Max | cab5beb | 2016-04-15 16:04:44 +0200 | [diff] [blame] | 143 | gen_si[n_si++] = SYSINFO_TYPE_2quater; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 144 | gen_si[n_si++] = SYSINFO_TYPE_3; |
| 145 | gen_si[n_si++] = SYSINFO_TYPE_4; |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 146 | |
| 147 | /* 13 is always present on a C0 TRX of a GPRS BTS */ |
| 148 | if (bts->gprs.mode != BTS_GPRS_NONE) |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 149 | gen_si[n_si++] = SYSINFO_TYPE_13; |
Harald Welte | 28fc963 | 2009-12-21 17:02:32 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 152 | /* 5 and 6 are always present on every TRX */ |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 153 | gen_si[n_si++] = SYSINFO_TYPE_5; |
| 154 | gen_si[n_si++] = SYSINFO_TYPE_5bis; |
| 155 | gen_si[n_si++] = SYSINFO_TYPE_5ter; |
| 156 | gen_si[n_si++] = SYSINFO_TYPE_6; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 157 | |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 158 | /* Second, we generate the selected SI via RSL */ |
| 159 | |
| 160 | for (n = 0; n < n_si; n++) { |
| 161 | i = gen_si[n]; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 162 | /* Only generate SI if this SI is not in "static" (user-defined) mode */ |
| 163 | if (!(bts->si_mode_static & (1 << i))) { |
Andreas Eversberg | aaf2970 | 2013-01-08 19:33:42 +0100 | [diff] [blame] | 164 | /* Set SI as being valid. gsm_generate_si() might unset |
| 165 | * it, if SI is not required. */ |
| 166 | bts->si_valid |= (1 << i); |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 167 | rc = gsm_generate_si(bts, i); |
| 168 | if (rc < 0) |
| 169 | goto err_out; |
| 170 | si_len[i] = rc; |
| 171 | } else { |
| 172 | if (i == SYSINFO_TYPE_5 || i == SYSINFO_TYPE_5bis |
| 173 | || i == SYSINFO_TYPE_5ter) |
| 174 | si_len[i] = 18; |
| 175 | else if (i == SYSINFO_TYPE_6) |
| 176 | si_len[i] = 11; |
| 177 | else |
| 178 | si_len[i] = 23; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /* Third, we send the selected SI via RSL */ |
| 183 | |
Andreas Eversberg | aaf2970 | 2013-01-08 19:33:42 +0100 | [diff] [blame] | 184 | for (n = 0; n < n_si; n++) { |
| 185 | i = gen_si[n]; |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 186 | if (!(bts->si_valid & (1 << i))) |
| 187 | continue; |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 188 | rc = rsl_si(trx, i, si_len[i]); |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 189 | if (rc < 0) |
Andreas Eversberg | 02de47d | 2012-02-29 09:04:07 +0100 | [diff] [blame] | 190 | return rc; |
Harald Welte | d8acf14 | 2010-07-30 11:50:09 +0200 | [diff] [blame] | 191 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 192 | |
| 193 | return 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 194 | err_out: |
Max | 88ddcaa | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 195 | LOGP(DRR, LOGL_ERROR, "Cannot generate SI%s for BTS %u: error <%s>," |
| 196 | "most likely a problem with neighbor cell list generation\n", |
| 197 | get_value_string(osmo_sitype_strs, i), bts->nr, strerror(-rc)); |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 198 | return rc; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Alexander Chemeris | 143ac5f | 2015-05-30 14:40:54 -0400 | [diff] [blame] | 201 | /* set all system information types for a BTS */ |
| 202 | int gsm_bts_set_system_infos(struct gsm_bts *bts) |
| 203 | { |
| 204 | struct gsm_bts_trx *trx; |
| 205 | |
| 206 | /* Generate a new ID */ |
| 207 | bts->bcch_change_mark += 1; |
| 208 | bts->bcch_change_mark %= 0x7; |
| 209 | |
| 210 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 211 | int rc; |
| 212 | |
| 213 | rc = gsm_bts_trx_set_system_infos(trx); |
| 214 | if (rc != 0) |
| 215 | return rc; |
| 216 | } |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 221 | /* Produce a MA as specified in 10.5.2.21 */ |
| 222 | static int generate_ma_for_ts(struct gsm_bts_trx_ts *ts) |
| 223 | { |
| 224 | /* we have three bitvecs: the per-timeslot ARFCNs, the cell chan ARFCNs |
| 225 | * and the MA */ |
| 226 | struct bitvec *cell_chan = &ts->trx->bts->si_common.cell_alloc; |
| 227 | struct bitvec *ts_arfcn = &ts->hopping.arfcns; |
| 228 | struct bitvec *ma = &ts->hopping.ma; |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 229 | unsigned int num_cell_arfcns, bitnum, n_chan; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 230 | int i; |
| 231 | |
| 232 | /* re-set the MA to all-zero */ |
| 233 | ma->cur_bit = 0; |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 234 | ts->hopping.ma_len = 0; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 235 | memset(ma->data, 0, ma->data_len); |
| 236 | |
| 237 | if (!ts->hopping.enabled) |
| 238 | return 0; |
| 239 | |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 240 | /* count the number of ARFCNs in the cell channel allocation */ |
| 241 | num_cell_arfcns = 0; |
Harald Welte | 09e4fad | 2012-01-29 13:24:12 +0100 | [diff] [blame] | 242 | for (i = 0; i < 1024; i++) { |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 243 | if (bitvec_get_bit_pos(cell_chan, i)) |
| 244 | num_cell_arfcns++; |
| 245 | } |
| 246 | |
| 247 | /* pad it to octet-aligned number of bits */ |
| 248 | ts->hopping.ma_len = num_cell_arfcns / 8; |
| 249 | if (num_cell_arfcns % 8) |
| 250 | ts->hopping.ma_len++; |
| 251 | |
| 252 | n_chan = 0; |
Harald Welte | 09e4fad | 2012-01-29 13:24:12 +0100 | [diff] [blame] | 253 | for (i = 0; i < 1024; i++) { |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 254 | if (!bitvec_get_bit_pos(cell_chan, i)) |
| 255 | continue; |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 256 | /* set the corresponding bit in the MA */ |
| 257 | bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 258 | if (bitvec_get_bit_pos(ts_arfcn, i)) |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 259 | bitvec_set_bit_pos(ma, bitnum, 1); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 260 | else |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 261 | bitvec_set_bit_pos(ma, bitnum, 0); |
laforge | 1dcdc95 | 2010-06-20 15:56:50 +0200 | [diff] [blame] | 262 | n_chan++; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* ARFCN 0 is special: It is coded last in the bitmask */ |
| 266 | if (bitvec_get_bit_pos(cell_chan, 0)) { |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 267 | n_chan++; |
| 268 | /* set the corresponding bit in the MA */ |
| 269 | bitnum = (ts->hopping.ma_len * 8) - 1 - n_chan; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 270 | if (bitvec_get_bit_pos(ts_arfcn, 0)) |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 271 | bitvec_set_bit_pos(ma, bitnum, 1); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 272 | else |
Harald Welte | 6332a8a | 2010-06-15 16:45:51 +0200 | [diff] [blame] | 273 | bitvec_set_bit_pos(ma, bitnum, 0); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 279 | static void bootstrap_rsl(struct gsm_bts_trx *trx) |
| 280 | { |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 281 | unsigned int i; |
| 282 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 283 | LOGP(DRSL, LOGL_NOTICE, "bootstrapping RSL for BTS/TRX (%u/%u) " |
Harald Welte | 7bb55f3 | 2015-11-20 10:43:31 +0100 | [diff] [blame] | 284 | "on ARFCN %u using MCC=%u MNC=%u LAC=%u CID=%u BSIC=%u\n", |
Harald Welte | 424873e | 2009-12-24 13:39:34 +0100 | [diff] [blame] | 285 | trx->bts->nr, trx->nr, trx->arfcn, bsc_gsmnet->country_code, |
| 286 | bsc_gsmnet->network_code, trx->bts->location_area_code, |
Harald Welte | 7bb55f3 | 2015-11-20 10:43:31 +0100 | [diff] [blame] | 287 | trx->bts->cell_identity, trx->bts->bsic); |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 288 | |
| 289 | if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) { |
| 290 | rsl_nokia_si_begin(trx); |
| 291 | } |
| 292 | |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 293 | gsm_bts_trx_set_system_infos(trx); |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 294 | |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 295 | if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) { |
| 296 | /* channel unspecific, power reduction in 2 dB steps */ |
| 297 | rsl_bs_power_control(trx, 0xFF, trx->max_power_red / 2); |
| 298 | rsl_nokia_si_end(trx); |
| 299 | } |
| 300 | |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 301 | for (i = 0; i < ARRAY_SIZE(trx->ts); i++) |
| 302 | generate_ma_for_ts(&trx->ts[i]); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 305 | /* Callback function to be called every time we receive a signal from INPUT */ |
| 306 | static int inp_sig_cb(unsigned int subsys, unsigned int signal, |
| 307 | void *handler_data, void *signal_data) |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 308 | { |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 309 | struct input_signal_data *isd = signal_data; |
| 310 | struct gsm_bts_trx *trx = isd->trx; |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 311 | int ts_no, lchan_no; |
| 312 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 313 | if (subsys != SS_L_INPUT) |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 314 | return -EINVAL; |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 315 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 316 | switch (signal) { |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 317 | case S_L_INP_TEI_UP: |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 318 | if (isd->link_type == E1INP_SIGN_OML) { |
| 319 | /* TODO: this is required for the Nokia BTS, hopping is configured |
| 320 | during OML, other MA is not set. */ |
| 321 | struct gsm_bts_trx *cur_trx; |
| 322 | /* was static in system_information.c */ |
| 323 | extern int generate_cell_chan_list(uint8_t *chan_list, struct gsm_bts *bts); |
| 324 | uint8_t ca[20]; |
| 325 | /* has to be called before generate_ma_for_ts to |
| 326 | set bts->si_common.cell_alloc */ |
| 327 | generate_cell_chan_list(ca, trx->bts); |
| 328 | |
| 329 | llist_for_each_entry(cur_trx, &trx->bts->trx_list, list) { |
| 330 | int i; |
| 331 | |
Neels Hofmeyr | a34ddc5 | 2016-06-02 01:18:02 +0200 | [diff] [blame] | 332 | for (i = 0; i < ARRAY_SIZE(cur_trx->ts); i++) |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 333 | generate_ma_for_ts(&cur_trx->ts[i]); |
| 334 | } |
| 335 | } |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 336 | if (isd->link_type == E1INP_SIGN_RSL) |
| 337 | bootstrap_rsl(trx); |
| 338 | break; |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 339 | case S_L_INP_TEI_DN: |
| 340 | LOGP(DLMI, LOGL_ERROR, "Lost some E1 TEI link: %d %p\n", isd->link_type, trx); |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 341 | |
| 342 | if (isd->link_type == E1INP_SIGN_OML) |
Alexander Couzens | d8aad3a | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 343 | rate_ctr_inc(&trx->bts->network->bsc_ctrs->ctr[BSC_CTR_BTS_OML_FAIL]); |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 344 | else if (isd->link_type == E1INP_SIGN_RSL) |
Alexander Couzens | d8aad3a | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 345 | rate_ctr_inc(&trx->bts->network->bsc_ctrs->ctr[BSC_CTR_BTS_RSL_FAIL]); |
Holger Hans Peter Freyther | 3e09b3f | 2010-04-12 10:45:52 +0200 | [diff] [blame] | 346 | |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 347 | /* |
| 348 | * free all allocated channels. change the nm_state so the |
| 349 | * trx and trx_ts becomes unusable and chan_alloc.c can not |
| 350 | * allocate from it. |
| 351 | */ |
| 352 | for (ts_no = 0; ts_no < ARRAY_SIZE(trx->ts); ++ts_no) { |
| 353 | struct gsm_bts_trx_ts *ts = &trx->ts[ts_no]; |
| 354 | |
| 355 | 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] | 356 | if (ts->lchan[lchan_no].state != LCHAN_S_NONE) |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 357 | lchan_free(&ts->lchan[lchan_no]); |
| 358 | lchan_reset(&ts->lchan[lchan_no]); |
| 359 | } |
Holger Hans Peter Freyther | 5a8b2b4 | 2010-04-15 11:21:02 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Harald Welte | 452119d | 2011-06-29 16:49:03 +0200 | [diff] [blame] | 362 | gsm_bts_mo_reset(trx->bts); |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 363 | |
| 364 | abis_nm_clear_queue(trx->bts); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 365 | break; |
| 366 | default: |
| 367 | break; |
| 368 | } |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 369 | |
| 370 | return 0; |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static int bootstrap_bts(struct gsm_bts *bts) |
| 374 | { |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 375 | int i, n; |
| 376 | |
Max | 0ae7153 | 2016-04-08 11:52:34 +0200 | [diff] [blame] | 377 | if (!bts->model) |
| 378 | return -EFAULT; |
| 379 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 380 | if (bts->model->start && !bts->model->started) { |
| 381 | int ret = bts->model->start(bts->network); |
| 382 | if (ret < 0) |
| 383 | return ret; |
| 384 | |
| 385 | bts->model->started = true; |
| 386 | } |
| 387 | |
Harald Welte | eee698b | 2010-05-26 17:14:42 +0200 | [diff] [blame] | 388 | /* FIXME: What about secondary TRX of a BTS? What about a BTS that has TRX |
| 389 | * 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] | 390 | switch (bts->band) { |
| 391 | case GSM_BAND_1800: |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 392 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 885) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 393 | 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] | 394 | return -EINVAL; |
| 395 | } |
| 396 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 397 | case GSM_BAND_1900: |
| 398 | if (bts->c0->arfcn < 512 || bts->c0->arfcn > 810) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 399 | LOGP(DNM, LOGL_ERROR, "GSM1900 channel must be between 512-810.\n"); |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 400 | return -EINVAL; |
| 401 | } |
| 402 | break; |
| 403 | case GSM_BAND_900: |
Holger Hans Peter Freyther | 1abf653 | 2015-06-20 18:45:35 +0200 | [diff] [blame] | 404 | if ((bts->c0->arfcn > 124 && bts->c0->arfcn < 955) || |
Holger Hans Peter Freyther | 2ba2b33 | 2010-02-09 15:44:14 +0100 | [diff] [blame] | 405 | bts->c0->arfcn > 1023) { |
Michael McTernan | 85b6731 | 2015-06-19 20:51:43 +0200 | [diff] [blame] | 406 | LOGP(DNM, LOGL_ERROR, "GSM900 channel must be between 0-124, 955-1023.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 407 | return -EINVAL; |
| 408 | } |
| 409 | break; |
Harald Welte | eee698b | 2010-05-26 17:14:42 +0200 | [diff] [blame] | 410 | case GSM_BAND_850: |
| 411 | if (bts->c0->arfcn < 128 || bts->c0->arfcn > 251) { |
| 412 | LOGP(DNM, LOGL_ERROR, "GSM850 channel must be between 128-251.\n"); |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | break; |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 416 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 417 | LOGP(DNM, LOGL_ERROR, "Unsupported frequency band.\n"); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 418 | return -EINVAL; |
| 419 | } |
| 420 | |
Harald Welte | 395cb6b | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 421 | if (bts->network->auth_policy == GSM_AUTH_POLICY_ACCEPT_ALL && |
Harald Welte | 8c973ba | 2009-12-21 23:08:18 +0100 | [diff] [blame] | 422 | !bts->si_common.rach_control.cell_bar) |
Harald Welte | 36ab545 | 2009-12-21 23:36:45 +0100 | [diff] [blame] | 423 | LOGP(DNM, LOGL_ERROR, "\nWARNING: You are running an 'accept-all' " |
Harald Welte | 395cb6b | 2009-12-12 13:44:19 +0100 | [diff] [blame] | 424 | "network on a BTS that is not barred. This " |
| 425 | "configuration is likely to interfere with production " |
| 426 | "GSM networks and should only be used in a RF " |
| 427 | "shielded environment such as a faraday cage!\n\n"); |
| 428 | |
Andreas Eversberg | 14e12f2 | 2012-10-13 07:27:47 +0200 | [diff] [blame] | 429 | /* Control Channel Description is set from vty/config */ |
Harald Welte | 961ac53 | 2011-01-13 23:20:45 +0100 | [diff] [blame] | 430 | |
Holger Hans Peter Freyther | 8c99434 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 431 | /* T3212 is set from vty/config */ |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 432 | |
Holger Hans Peter Freyther | 8c99434 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 433 | /* Set ccch config by looking at ts config */ |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 434 | for (n=0, i=0; i<8; i++) |
| 435 | n += bts->c0->ts[i].pchan == GSM_PCHAN_CCCH ? 1 : 0; |
| 436 | |
| 437 | switch (n) { |
| 438 | case 0: |
| 439 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_C; |
Max | d5e4ee9 | 2016-10-12 12:48:50 +0200 | [diff] [blame] | 440 | /* Limit reserved block to 2 on combined channel according to |
| 441 | 3GPP TS 44.018 Table 10.5.2.11.1 */ |
| 442 | if (bts->si_common.chan_desc.bs_ag_blks_res > 2) { |
| 443 | LOGP(DNM, LOGL_NOTICE, "CCCH is combined with SDCCHs, " |
| 444 | "reducing BS-AG-BLKS-RES value %d -> 2\n", |
| 445 | bts->si_common.chan_desc.bs_ag_blks_res); |
Andreas Eversberg | 14e12f2 | 2012-10-13 07:27:47 +0200 | [diff] [blame] | 446 | bts->si_common.chan_desc.bs_ag_blks_res = 2; |
Max | d5e4ee9 | 2016-10-12 12:48:50 +0200 | [diff] [blame] | 447 | } |
Sylvain Munaut | 63e014e | 2010-04-28 21:31:29 +0200 | [diff] [blame] | 448 | break; |
| 449 | case 1: |
| 450 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_1_NC; |
| 451 | break; |
| 452 | case 2: |
| 453 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_2_NC; |
| 454 | break; |
| 455 | case 3: |
| 456 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_3_NC; |
| 457 | break; |
| 458 | case 4: |
| 459 | bts->si_common.chan_desc.ccch_conf = RSL_BCCH_CCCH_CONF_4_NC; |
| 460 | break; |
| 461 | default: |
| 462 | LOGP(DNM, LOGL_ERROR, "Unsupported CCCH timeslot configuration\n"); |
| 463 | return -EINVAL; |
| 464 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 465 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 466 | bts->si_common.cell_options.pwrc = 0; /* PWRC not set */ |
| 467 | |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 468 | bts->si_common.cell_sel_par.acs = 0; |
Harald Welte | a54a2bb | 2009-12-01 18:04:30 +0530 | [diff] [blame] | 469 | |
| 470 | bts->si_common.ncc_permitted = 0xff; |
| 471 | |
Holger Hans Peter Freyther | 29cd72a | 2011-07-18 11:26:07 +0200 | [diff] [blame] | 472 | /* Initialize the BTS state */ |
| 473 | gsm_bts_mo_reset(bts); |
| 474 | |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
Neels Hofmeyr | 2ba6b73 | 2016-05-11 14:28:25 +0200 | [diff] [blame^] | 478 | int bsc_bootstrap_network(mncc_recv_cb_t mncc_recv, const char *config_file) |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 479 | { |
| 480 | struct gsm_bts *bts; |
| 481 | int rc; |
| 482 | |
| 483 | /* initialize our data structures */ |
Neels Hofmeyr | c1c4dc1 | 2016-05-09 19:12:44 +0200 | [diff] [blame] | 484 | bsc_gsmnet = gsm_network_init(tall_bsc_ctx, 1, 1, mncc_recv); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 485 | if (!bsc_gsmnet) |
| 486 | return -ENOMEM; |
| 487 | |
| 488 | bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 489 | bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC"); |
| 490 | |
Neels Hofmeyr | 9467a82 | 2016-05-11 13:39:33 +0200 | [diff] [blame] | 491 | rc = vty_read_config_file(config_file, NULL); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 492 | if (rc < 0) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 493 | 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] | 494 | return rc; |
| 495 | } |
| 496 | |
Neels Hofmeyr | 737252c | 2016-02-23 14:09:38 +0100 | [diff] [blame] | 497 | /* start telnet after reading config for vty_get_bind_addr() */ |
Neels Hofmeyr | 737252c | 2016-02-23 14:09:38 +0100 | [diff] [blame] | 498 | rc = telnet_init_dynif(tall_bsc_ctx, bsc_gsmnet, vty_get_bind_addr(), |
| 499 | OSMO_VTY_PORT_NITB_BSC); |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 500 | if (rc < 0) |
| 501 | return rc; |
| 502 | |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 503 | osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL); |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 504 | osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL); |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 505 | |
| 506 | llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) { |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 507 | rc = bootstrap_bts(bts); |
Pablo Neira Ayuso | 4726e7e | 2011-05-14 11:32:46 +0200 | [diff] [blame] | 508 | if (rc < 0) { |
| 509 | LOGP(DNM, LOGL_FATAL, "Error bootstrapping BTS\n"); |
| 510 | return rc; |
| 511 | } |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 512 | rc = e1_reconfig_bts(bts); |
Harald Welte | a849782 | 2011-02-05 15:41:24 +0100 | [diff] [blame] | 513 | if (rc < 0) { |
Pablo Neira Ayuso | 4726e7e | 2011-05-14 11:32:46 +0200 | [diff] [blame] | 514 | LOGP(DNM, LOGL_FATAL, "Error enabling E1 input driver\n"); |
| 515 | return rc; |
Harald Welte | a849782 | 2011-02-05 15:41:24 +0100 | [diff] [blame] | 516 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 517 | } |
Holger Hans Peter Freyther | cad370f | 2009-08-17 06:55:10 +0200 | [diff] [blame] | 518 | return 0; |
| 519 | } |