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