Harald Welte | 709d38f | 2010-03-04 10:39:50 +0100 | [diff] [blame] | 1 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 13 | * GNU Affero General Public License for more details. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 14 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 24 | #include <errno.h> |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 25 | #include <ctype.h> |
Max | 3d94aca | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 26 | #include <stdbool.h> |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 27 | #include <netinet/in.h> |
| 28 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 29 | #include <osmocom/core/linuxlist.h> |
| 30 | #include <osmocom/core/talloc.h> |
| 31 | #include <osmocom/gsm/gsm_utils.h> |
Harald Welte | 306a889 | 2011-05-23 20:30:39 +0200 | [diff] [blame] | 32 | #include <osmocom/gsm/abis_nm.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 33 | #include <osmocom/core/statistics.h> |
Max | 3d94aca | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 34 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 35 | |
Holger Hans Peter Freyther | 3b556f9 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 36 | #include <openbsc/gsm_data.h> |
Neels Hofmeyr | 3863935 | 2017-02-23 21:49:55 +0100 | [diff] [blame] | 37 | #include <openbsc/bsc_msc_data.h> |
Holger Hans Peter Freyther | 3b556f9 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 38 | #include <openbsc/abis_nm.h> |
| 39 | |
Andreas Eversberg | e4d5146 | 2009-06-29 15:19:38 +0200 | [diff] [blame] | 40 | void *tall_bsc_ctx; |
| 41 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 42 | static LLIST_HEAD(bts_models); |
| 43 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 44 | void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr, |
| 45 | uint8_t e1_ts, uint8_t e1_ts_ss) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 46 | { |
| 47 | ts->e1_link.e1_nr = e1_nr; |
| 48 | ts->e1_link.e1_ts = e1_ts; |
| 49 | ts->e1_link.e1_ts_ss = e1_ts_ss; |
| 50 | } |
| 51 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 52 | static struct gsm_bts_model *bts_model_find(enum gsm_bts_type type) |
| 53 | { |
| 54 | struct gsm_bts_model *model; |
| 55 | |
| 56 | llist_for_each_entry(model, &bts_models, list) { |
| 57 | if (model->type == type) |
| 58 | return model; |
| 59 | } |
| 60 | |
| 61 | return NULL; |
| 62 | } |
| 63 | |
| 64 | int gsm_bts_model_register(struct gsm_bts_model *model) |
| 65 | { |
| 66 | if (bts_model_find(model->type)) |
| 67 | return -EEXIST; |
| 68 | |
Harald Welte | 306a889 | 2011-05-23 20:30:39 +0200 | [diff] [blame] | 69 | tlv_def_patch(&model->nm_att_tlvdef, &abis_nm_att_tlvdef); |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 70 | llist_add_tail(&model->list, &bts_models); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 74 | /* Get reference to a neighbor cell on a given BCCH ARFCN */ |
Harald Welte | 792a1d4 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 75 | struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 76 | uint16_t arfcn, uint8_t bsic) |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 77 | { |
| 78 | struct gsm_bts *neigh; |
| 79 | /* FIXME: use some better heuristics here to determine which cell |
| 80 | * using this ARFCN really is closest to the target cell. For |
| 81 | * now we simply assume that each ARFCN will only be used by one |
| 82 | * cell */ |
| 83 | |
| 84 | llist_for_each_entry(neigh, &bts->network->bts_list, list) { |
Harald Welte | 792a1d4 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 85 | if (neigh->c0->arfcn == arfcn && |
| 86 | neigh->bsic == bsic) |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 87 | return neigh; |
| 88 | } |
| 89 | |
| 90 | return NULL; |
| 91 | } |
| 92 | |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 93 | const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1] = { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 94 | { GSM_BTS_TYPE_UNKNOWN, "unknown" }, |
| 95 | { GSM_BTS_TYPE_BS11, "bs11" }, |
| 96 | { GSM_BTS_TYPE_NANOBTS, "nanobts" }, |
Harald Welte | c2f27ba | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 97 | { GSM_BTS_TYPE_RBS2000, "rbs2000" }, |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 98 | { GSM_BTS_TYPE_NOKIA_SITE, "nokia_site" }, |
Max | abf3eb1 | 2017-03-23 12:01:07 +0100 | [diff] [blame] | 99 | { GSM_BTS_TYPE_OSMOBTS, "sysmobts" }, |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 100 | { 0, NULL } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 101 | }; |
| 102 | |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 103 | const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1] = { |
| 104 | { GSM_BTS_TYPE_UNKNOWN, "Unknown BTS Type" }, |
| 105 | { GSM_BTS_TYPE_BS11, "Siemens BTS (BS-11 or compatible)" }, |
| 106 | { GSM_BTS_TYPE_NANOBTS, "ip.access nanoBTS or compatible" }, |
| 107 | { GSM_BTS_TYPE_RBS2000, "Ericsson RBS2000 Series" }, |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 108 | { GSM_BTS_TYPE_NOKIA_SITE, "Nokia {Metro,Ultra,In}Site" }, |
Max | abf3eb1 | 2017-03-23 12:01:07 +0100 | [diff] [blame] | 109 | { GSM_BTS_TYPE_OSMOBTS, "sysmocom sysmoBTS" }, |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 110 | { 0, NULL } |
| 111 | }; |
| 112 | |
Harald Welte | 498feae | 2009-08-08 15:38:29 +0200 | [diff] [blame] | 113 | enum gsm_bts_type parse_btstype(const char *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 114 | { |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 115 | return get_string_value(bts_type_names, arg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 116 | } |
| 117 | |
Holger Hans Peter Freyther | 56f59bb | 2009-06-12 17:39:38 +0200 | [diff] [blame] | 118 | const char *btstype2str(enum gsm_bts_type type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 119 | { |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 120 | return get_value_string(bts_type_names, type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 121 | } |
| 122 | |
Harald Welte | c985a14 | 2010-01-07 20:44:32 +0100 | [diff] [blame] | 123 | struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr) |
| 124 | { |
| 125 | struct gsm_bts_trx *trx; |
| 126 | |
| 127 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 128 | if (trx->nr == nr) |
| 129 | return trx; |
| 130 | } |
| 131 | return NULL; |
| 132 | } |
| 133 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 134 | /* Search for a BTS in the given Location Area; optionally start searching |
| 135 | * with start_bts (for continuing to search after the first result) */ |
| 136 | struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac, |
| 137 | struct gsm_bts *start_bts) |
| 138 | { |
| 139 | int i; |
| 140 | struct gsm_bts *bts; |
| 141 | int skip = 0; |
| 142 | |
| 143 | if (start_bts) |
| 144 | skip = 1; |
| 145 | |
| 146 | for (i = 0; i < net->num_bts; i++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 147 | bts = gsm_bts_num(net, i); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 148 | |
| 149 | if (skip) { |
| 150 | if (start_bts == bts) |
| 151 | skip = 0; |
| 152 | continue; |
| 153 | } |
| 154 | |
Holger Hans Peter Freyther | 6c6ab86 | 2009-10-01 04:07:15 +0200 | [diff] [blame] | 155 | if (lac == GSM_LAC_RESERVED_ALL_BTS || bts->location_area_code == lac) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 156 | return bts; |
| 157 | } |
| 158 | return NULL; |
| 159 | } |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 160 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 161 | static const struct value_string auth_policy_names[] = { |
| 162 | { GSM_AUTH_POLICY_CLOSED, "closed" }, |
| 163 | { GSM_AUTH_POLICY_ACCEPT_ALL, "accept-all" }, |
| 164 | { GSM_AUTH_POLICY_TOKEN, "token" }, |
Max | 0a378ba | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 165 | { GSM_AUTH_POLICY_REGEXP, "regexp" }, |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 166 | { 0, NULL } |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | enum gsm_auth_policy gsm_auth_policy_parse(const char *arg) |
| 170 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 171 | return get_string_value(auth_policy_names, arg); |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | const char *gsm_auth_policy_name(enum gsm_auth_policy policy) |
| 175 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 176 | return get_value_string(auth_policy_names, policy); |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 179 | static const struct value_string rrlp_mode_names[] = { |
| 180 | { RRLP_MODE_NONE, "none" }, |
| 181 | { RRLP_MODE_MS_BASED, "ms-based" }, |
| 182 | { RRLP_MODE_MS_PREF, "ms-preferred" }, |
| 183 | { RRLP_MODE_ASS_PREF, "ass-preferred" }, |
| 184 | { 0, NULL } |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | enum rrlp_mode rrlp_mode_parse(const char *arg) |
| 188 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 189 | return get_string_value(rrlp_mode_names, arg); |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | const char *rrlp_mode_name(enum rrlp_mode mode) |
| 193 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 194 | return get_value_string(rrlp_mode_names, mode); |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 195 | } |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 196 | |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 197 | static const struct value_string bts_gprs_mode_names[] = { |
| 198 | { BTS_GPRS_NONE, "none" }, |
| 199 | { BTS_GPRS_GPRS, "gprs" }, |
| 200 | { BTS_GPRS_EGPRS, "egprs" }, |
| 201 | { 0, NULL } |
| 202 | }; |
| 203 | |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 204 | enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid) |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 205 | { |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 206 | int rc; |
| 207 | |
| 208 | rc = get_string_value(bts_gprs_mode_names, arg); |
| 209 | if (valid) |
| 210 | *valid = rc != -EINVAL; |
| 211 | return rc; |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | const char *bts_gprs_mode_name(enum bts_gprs_mode mode) |
| 215 | { |
| 216 | return get_value_string(bts_gprs_mode_names, mode); |
| 217 | } |
| 218 | |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 219 | int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode) |
| 220 | { |
| 221 | if (mode != BTS_GPRS_NONE && |
| 222 | !gsm_bts_has_feature(bts, BTS_FEAT_GPRS)) { |
| 223 | return 0; |
| 224 | } |
| 225 | if (mode == BTS_GPRS_EGPRS && |
| 226 | !gsm_bts_has_feature(bts, BTS_FEAT_EGPRS)) { |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | return 1; |
| 231 | } |
| 232 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 233 | struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan) |
| 234 | { |
| 235 | struct gsm_meas_rep *meas_rep; |
| 236 | |
| 237 | meas_rep = &lchan->meas_rep[lchan->meas_rep_idx]; |
| 238 | memset(meas_rep, 0, sizeof(*meas_rep)); |
| 239 | meas_rep->lchan = lchan; |
| 240 | lchan->meas_rep_idx = (lchan->meas_rep_idx + 1) |
| 241 | % ARRAY_SIZE(lchan->meas_rep); |
| 242 | |
| 243 | return meas_rep; |
| 244 | } |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 245 | |
Harald Welte | 20e275a | 2010-06-14 22:44:42 +0200 | [diff] [blame] | 246 | int gsm_btsmodel_set_feature(struct gsm_bts_model *bts, enum gsm_bts_features feat) |
| 247 | { |
| 248 | return bitvec_set_bit_pos(&bts->features, feat, 1); |
| 249 | } |
| 250 | |
| 251 | int gsm_bts_has_feature(struct gsm_bts *bts, enum gsm_bts_features feat) |
| 252 | { |
| 253 | return bitvec_get_bit_pos(&bts->model->features, feat); |
| 254 | } |
| 255 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 256 | int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type) |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 257 | { |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 258 | struct gsm_bts_model *model; |
| 259 | |
| 260 | model = bts_model_find(type); |
| 261 | if (!model) |
| 262 | return -EINVAL; |
| 263 | |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 264 | bts->type = type; |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 265 | bts->model = model; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 266 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 267 | if (model->start && !model->started) { |
| 268 | int ret = model->start(bts->network); |
| 269 | if (ret < 0) |
| 270 | return ret; |
| 271 | |
| 272 | model->started = true; |
| 273 | } |
| 274 | |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 275 | switch (bts->type) { |
| 276 | case GSM_BTS_TYPE_NANOBTS: |
Max | abf3eb1 | 2017-03-23 12:01:07 +0100 | [diff] [blame] | 277 | case GSM_BTS_TYPE_OSMOBTS: |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 278 | /* Set the default OML Stream ID to 0xff */ |
| 279 | bts->oml_tei = 0xff; |
| 280 | bts->c0->nominal_power = 23; |
| 281 | break; |
Harald Welte | 738310b | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 282 | case GSM_BTS_TYPE_RBS2000: |
| 283 | INIT_LLIST_HEAD(&bts->rbs2000.is.conn_groups); |
Harald Welte | a552655 | 2011-02-13 22:45:02 +0100 | [diff] [blame] | 284 | INIT_LLIST_HEAD(&bts->rbs2000.con.conn_groups); |
Harald Welte | 738310b | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 285 | break; |
Holger Hans Peter Freyther | ad51516 | 2012-02-03 19:44:37 +0100 | [diff] [blame] | 286 | case GSM_BTS_TYPE_BS11: |
| 287 | case GSM_BTS_TYPE_UNKNOWN: |
| 288 | case GSM_BTS_TYPE_NOKIA_SITE: |
Sipos Csaba | def87b4 | 2015-02-07 13:27:36 +0100 | [diff] [blame] | 289 | /* Set default BTS reset timer */ |
| 290 | bts->nokia.bts_reset_timer_cnf = 15; |
Holger Hans Peter Freyther | dec95b3 | 2012-09-11 11:53:08 +0200 | [diff] [blame] | 291 | case _NUM_GSM_BTS_TYPE: |
Holger Hans Peter Freyther | ad51516 | 2012-02-03 19:44:37 +0100 | [diff] [blame] | 292 | break; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 293 | } |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 294 | |
| 295 | return 0; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 296 | } |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 297 | |
| 298 | struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, |
Harald Welte | 7bb55f3 | 2015-11-20 10:43:31 +0100 | [diff] [blame] | 299 | uint8_t bsic) |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 300 | { |
| 301 | struct gsm_bts_model *model = bts_model_find(type); |
| 302 | struct gsm_bts *bts; |
| 303 | |
Harald Welte | fe04bb9 | 2011-06-06 17:52:56 +0200 | [diff] [blame] | 304 | if (!model && type != GSM_BTS_TYPE_UNKNOWN) |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 305 | return NULL; |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 306 | |
| 307 | bts = gsm_bts_alloc(net); |
| 308 | if (!bts) |
| 309 | return NULL; |
| 310 | |
| 311 | bts->network = net; |
| 312 | bts->nr = net->num_bts++; |
| 313 | bts->type = type; |
| 314 | bts->model = model; |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 315 | bts->bsic = bsic; |
Max | 3d94aca | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 316 | bts->dtxu = GSM48_DTX_SHALL_NOT_BE_USED; |
| 317 | bts->dtxd = false; |
Max | 88bdcd4 | 2016-07-28 11:55:37 +0200 | [diff] [blame] | 318 | bts->gprs.ctrl_ack_type_use_block = true; /* use RLC/MAC control block */ |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 319 | bts->neigh_list_manual_mode = 0; |
| 320 | bts->si_common.cell_sel_par.cell_resel_hyst = 2; /* 4 dB */ |
| 321 | bts->si_common.cell_sel_par.rxlev_acc_min = 0; |
Max | 88ddcaa | 2016-04-15 16:04:46 +0200 | [diff] [blame] | 322 | bts->si_common.si2quater_neigh_list.arfcn = bts->si_common.data.earfcn_list; |
| 323 | bts->si_common.si2quater_neigh_list.meas_bw = bts->si_common.data.meas_bw_list; |
| 324 | bts->si_common.si2quater_neigh_list.length = MAX_EARFCN_LIST; |
| 325 | bts->si_common.si2quater_neigh_list.thresh_hi = 0; |
| 326 | osmo_earfcn_init(&bts->si_common.si2quater_neigh_list); |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 327 | bts->si_common.neigh_list.data = bts->si_common.data.neigh_list; |
| 328 | bts->si_common.neigh_list.data_len = |
| 329 | sizeof(bts->si_common.data.neigh_list); |
| 330 | bts->si_common.si5_neigh_list.data = bts->si_common.data.si5_neigh_list; |
| 331 | bts->si_common.si5_neigh_list.data_len = |
| 332 | sizeof(bts->si_common.data.si5_neigh_list); |
| 333 | bts->si_common.cell_alloc.data = bts->si_common.data.cell_alloc; |
| 334 | bts->si_common.cell_alloc.data_len = |
| 335 | sizeof(bts->si_common.data.cell_alloc); |
| 336 | bts->si_common.rach_control.re = 1; /* no re-establishment */ |
| 337 | bts->si_common.rach_control.tx_integer = 9; /* 12 slots spread - 217/115 slots delay */ |
| 338 | bts->si_common.rach_control.max_trans = 3; /* 7 retransmissions */ |
| 339 | bts->si_common.rach_control.t2 = 4; /* no emergency calls */ |
Andreas Eversberg | 14e12f2 | 2012-10-13 07:27:47 +0200 | [diff] [blame] | 340 | bts->si_common.chan_desc.att = 1; /* attachment required */ |
| 341 | bts->si_common.chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5; /* paging frames */ |
| 342 | bts->si_common.chan_desc.bs_ag_blks_res = 1; /* reserved AGCH blocks */ |
Daniel Willmann | 3e7db9e | 2012-12-27 00:02:01 +0100 | [diff] [blame] | 343 | bts->si_common.chan_desc.t3212 = 5; /* Use 30 min periodic update interval as sane default */ |
Andreas Eversberg | f9248d9 | 2013-03-10 11:49:35 +0100 | [diff] [blame] | 344 | set_radio_link_timeout(&bts->si_common.cell_options, 32); |
| 345 | /* Use RADIO LINK TIMEOUT of 32 seconds */ |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 346 | |
| 347 | llist_add_tail(&bts->list, &net->bts_list); |
| 348 | |
| 349 | INIT_LLIST_HEAD(&bts->abis_queue); |
| 350 | |
Daniel Willmann | 8c3483f | 2011-08-05 13:51:27 +0200 | [diff] [blame] | 351 | INIT_LLIST_HEAD(&bts->loc_list); |
| 352 | |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 353 | return bts; |
| 354 | } |
| 355 | |
| 356 | void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts) |
| 357 | { |
| 358 | raid->mcc = bts->network->country_code; |
| 359 | raid->mnc = bts->network->network_code; |
| 360 | raid->lac = bts->location_area_code; |
| 361 | raid->rac = bts->gprs.rac; |
| 362 | } |
| 363 | |
| 364 | int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts) |
| 365 | { |
| 366 | struct gprs_ra_id raid; |
| 367 | |
| 368 | gprs_ra_id_by_bts(&raid, bts); |
| 369 | |
| 370 | return gsm48_construct_ra(buf, &raid); |
| 371 | } |
Holger Hans Peter Freyther | 1c14d96 | 2011-06-09 21:48:49 +0200 | [diff] [blame] | 372 | |
| 373 | int gsm_parse_reg(void *ctx, regex_t *reg, char **str, int argc, const char **argv) |
| 374 | { |
| 375 | int ret; |
| 376 | |
| 377 | ret = 0; |
| 378 | if (*str) { |
| 379 | talloc_free(*str); |
| 380 | *str = NULL; |
| 381 | } |
| 382 | regfree(reg); |
| 383 | |
| 384 | if (argc > 0) { |
| 385 | *str = talloc_strdup(ctx, argv[0]); |
| 386 | ret = regcomp(reg, argv[0], 0); |
| 387 | |
| 388 | /* handle compilation failures */ |
| 389 | if (ret != 0) { |
| 390 | talloc_free(*str); |
| 391 | *str = NULL; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | return ret; |
| 396 | } |
| 397 | |
Holger Hans Peter Freyther | 1515261 | 2014-12-17 14:46:17 +0100 | [diff] [blame] | 398 | /* Assume there are only 256 possible bts */ |
| 399 | osmo_static_assert(sizeof(((struct gsm_bts *) 0)->nr) == 1, _bts_nr_is_256); |
| 400 | static void depends_calc_index_bit(int bts_nr, int *idx, int *bit) |
| 401 | { |
| 402 | *idx = bts_nr / (8 * 4); |
| 403 | *bit = bts_nr % (8 * 4); |
| 404 | } |
| 405 | |
| 406 | void bts_depend_mark(struct gsm_bts *bts, int dep) |
| 407 | { |
| 408 | int idx, bit; |
| 409 | depends_calc_index_bit(dep, &idx, &bit); |
| 410 | |
| 411 | bts->depends_on[idx] |= 1 << bit; |
| 412 | } |
| 413 | |
| 414 | void bts_depend_clear(struct gsm_bts *bts, int dep) |
| 415 | { |
| 416 | int idx, bit; |
| 417 | depends_calc_index_bit(dep, &idx, &bit); |
| 418 | |
| 419 | bts->depends_on[idx] &= ~(1 << bit); |
| 420 | } |
| 421 | |
Holger Hans Peter Freyther | c38653e | 2014-12-17 15:44:32 +0100 | [diff] [blame] | 422 | int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other) |
Holger Hans Peter Freyther | 1515261 | 2014-12-17 14:46:17 +0100 | [diff] [blame] | 423 | { |
| 424 | int idx, bit; |
| 425 | depends_calc_index_bit(other->nr, &idx, &bit); |
| 426 | |
| 427 | /* Check if there is a depends bit */ |
| 428 | return (base->depends_on[idx] & (1 << bit)) > 0; |
| 429 | } |
| 430 | |
| 431 | static int bts_is_online(struct gsm_bts *bts) |
| 432 | { |
| 433 | /* TODO: support E1 BTS too */ |
| 434 | if (!is_ipaccess_bts(bts)) |
| 435 | return 1; |
| 436 | |
| 437 | if (!bts->oml_link) |
| 438 | return 0; |
| 439 | |
| 440 | return bts->mo.nm_state.operational == NM_OPSTATE_ENABLED; |
| 441 | } |
| 442 | |
| 443 | int bts_depend_check(struct gsm_bts *bts) |
| 444 | { |
| 445 | struct gsm_bts *other_bts; |
| 446 | |
| 447 | llist_for_each_entry(other_bts, &bts->network->bts_list, list) { |
| 448 | if (!bts_depend_is_depedency(bts, other_bts)) |
| 449 | continue; |
| 450 | if (bts_is_online(other_bts)) |
| 451 | continue; |
| 452 | return 0; |
| 453 | } |
| 454 | return 1; |
| 455 | } |