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