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> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 26 | |
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> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | 3b556f9 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 35 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 36 | #include <openbsc/osmo_msc_data.h> |
Holger Hans Peter Freyther | 3b556f9 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 37 | #include <openbsc/abis_nm.h> |
| 38 | |
Andreas Eversberg | e4d5146 | 2009-06-29 15:19:38 +0200 | [diff] [blame] | 39 | void *tall_bsc_ctx; |
| 40 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 41 | static LLIST_HEAD(bts_models); |
| 42 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 43 | void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr, |
| 44 | uint8_t e1_ts, uint8_t e1_ts_ss) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 45 | { |
| 46 | ts->e1_link.e1_nr = e1_nr; |
| 47 | ts->e1_link.e1_ts = e1_ts; |
| 48 | ts->e1_link.e1_ts_ss = e1_ts_ss; |
| 49 | } |
| 50 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 51 | static struct gsm_bts_model *bts_model_find(enum gsm_bts_type type) |
| 52 | { |
| 53 | struct gsm_bts_model *model; |
| 54 | |
| 55 | llist_for_each_entry(model, &bts_models, list) { |
| 56 | if (model->type == type) |
| 57 | return model; |
| 58 | } |
| 59 | |
| 60 | return NULL; |
| 61 | } |
| 62 | |
| 63 | int gsm_bts_model_register(struct gsm_bts_model *model) |
| 64 | { |
| 65 | if (bts_model_find(model->type)) |
| 66 | return -EEXIST; |
| 67 | |
Harald Welte | 306a889 | 2011-05-23 20:30:39 +0200 | [diff] [blame] | 68 | tlv_def_patch(&model->nm_att_tlvdef, &abis_nm_att_tlvdef); |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 69 | llist_add_tail(&model->list, &bts_models); |
| 70 | return 0; |
| 71 | } |
| 72 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 73 | struct gsm_network *gsm_network_init(uint16_t country_code, uint16_t network_code, |
Harald Welte | 5c05ed3 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 74 | int (*mncc_recv)(struct gsm_network *, struct msgb *)) |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 75 | { |
| 76 | struct gsm_network *net; |
| 77 | |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 78 | net = talloc_zero(tall_bsc_ctx, struct gsm_network); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 79 | if (!net) |
| 80 | return NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 81 | |
Holger Hans Peter Freyther | 4d61417 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 82 | net->bsc_data = talloc_zero(net, struct osmo_bsc_data); |
| 83 | if (!net->bsc_data) { |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 84 | talloc_free(net); |
| 85 | return NULL; |
| 86 | } |
| 87 | |
Daniel Willmann | 8f6e20d | 2011-03-03 13:48:28 +0100 | [diff] [blame] | 88 | /* Init back pointer */ |
Holger Hans Peter Freyther | 1b7fe0e | 2011-08-16 19:47:39 +0200 | [diff] [blame] | 89 | net->bsc_data->auto_off_timeout = -1; |
Holger Hans Peter Freyther | 4d61417 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 90 | net->bsc_data->network = net; |
Holger Hans Peter Freyther | 9c5dc14 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 91 | INIT_LLIST_HEAD(&net->bsc_data->mscs); |
Daniel Willmann | 8f6e20d | 2011-03-03 13:48:28 +0100 | [diff] [blame] | 92 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 93 | net->country_code = country_code; |
| 94 | net->network_code = network_code; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 95 | net->num_bts = 0; |
Holger Hans Peter Freyther | e0938e1 | 2010-01-07 16:08:42 +0100 | [diff] [blame] | 96 | net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED; |
Harald Welte | a963980 | 2009-12-01 17:36:54 +0530 | [diff] [blame] | 97 | net->T3101 = GSM_T3101_DEFAULT; |
Harald Welte | 9b77f61 | 2012-06-03 13:01:47 +0200 | [diff] [blame] | 98 | net->T3105 = GSM_T3105_DEFAULT; |
Harald Welte | a963980 | 2009-12-01 17:36:54 +0530 | [diff] [blame] | 99 | net->T3113 = GSM_T3113_DEFAULT; |
Andreas Eversberg | dee934a | 2013-02-07 11:51:16 +0100 | [diff] [blame^] | 100 | net->T3122 = GSM_T3122_DEFAULT; |
Harald Welte | a963980 | 2009-12-01 17:36:54 +0530 | [diff] [blame] | 101 | /* FIXME: initialize all other timers! */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 102 | |
Harald Welte | 92d8891 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 103 | /* default set of handover parameters */ |
| 104 | net->handover.win_rxlev_avg = 10; |
| 105 | net->handover.win_rxqual_avg = 1; |
| 106 | net->handover.win_rxlev_avg_neigh = 10; |
| 107 | net->handover.pwr_interval = 6; |
| 108 | net->handover.pwr_hysteresis = 3; |
| 109 | net->handover.max_distance = 9999; |
| 110 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 111 | INIT_LLIST_HEAD(&net->trans_list); |
| 112 | INIT_LLIST_HEAD(&net->upqueue); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 113 | INIT_LLIST_HEAD(&net->bts_list); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 114 | |
Pablo Neira Ayuso | 1c45074 | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 115 | net->stats.chreq.total = osmo_counter_alloc("net.chreq.total"); |
| 116 | net->stats.chreq.no_channel = osmo_counter_alloc("net.chreq.no_channel"); |
| 117 | net->stats.handover.attempted = osmo_counter_alloc("net.handover.attempted"); |
| 118 | net->stats.handover.no_channel = osmo_counter_alloc("net.handover.no_channel"); |
| 119 | net->stats.handover.timeout = osmo_counter_alloc("net.handover.timeout"); |
| 120 | net->stats.handover.completed = osmo_counter_alloc("net.handover.completed"); |
| 121 | net->stats.handover.failed = osmo_counter_alloc("net.handover.failed"); |
| 122 | net->stats.loc_upd_type.attach = osmo_counter_alloc("net.loc_upd_type.attach"); |
| 123 | net->stats.loc_upd_type.normal = osmo_counter_alloc("net.loc_upd_type.normal"); |
| 124 | net->stats.loc_upd_type.periodic = osmo_counter_alloc("net.loc_upd_type.periodic"); |
| 125 | net->stats.loc_upd_type.detach = osmo_counter_alloc("net.imsi_detach.count"); |
| 126 | net->stats.loc_upd_resp.reject = osmo_counter_alloc("net.loc_upd_resp.reject"); |
| 127 | net->stats.loc_upd_resp.accept = osmo_counter_alloc("net.loc_upd_resp.accept"); |
| 128 | net->stats.paging.attempted = osmo_counter_alloc("net.paging.attempted"); |
| 129 | net->stats.paging.detached = osmo_counter_alloc("net.paging.detached"); |
| 130 | net->stats.paging.completed = osmo_counter_alloc("net.paging.completed"); |
| 131 | net->stats.paging.expired = osmo_counter_alloc("net.paging.expired"); |
| 132 | net->stats.sms.submitted = osmo_counter_alloc("net.sms.submitted"); |
| 133 | net->stats.sms.no_receiver = osmo_counter_alloc("net.sms.no_receiver"); |
| 134 | net->stats.sms.delivered = osmo_counter_alloc("net.sms.delivered"); |
| 135 | net->stats.sms.rp_err_mem = osmo_counter_alloc("net.sms.rp_err_mem"); |
| 136 | net->stats.sms.rp_err_other = osmo_counter_alloc("net.sms.rp_err_other"); |
| 137 | net->stats.call.mo_setup = osmo_counter_alloc("net.call.mo_setup"); |
| 138 | net->stats.call.mo_connect_ack = osmo_counter_alloc("net.call.mo_connect_ack"); |
| 139 | net->stats.call.mt_setup = osmo_counter_alloc("net.call.mt_setup"); |
| 140 | net->stats.call.mt_connect = osmo_counter_alloc("net.call.mt_connect"); |
| 141 | net->stats.chan.rf_fail = osmo_counter_alloc("net.chan.rf_fail"); |
| 142 | net->stats.chan.rll_err = osmo_counter_alloc("net.chan.rll_err"); |
| 143 | net->stats.bts.oml_fail = osmo_counter_alloc("net.bts.oml_fail"); |
| 144 | net->stats.bts.rsl_fail = osmo_counter_alloc("net.bts.rsl_fail"); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 145 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 146 | net->mncc_recv = mncc_recv; |
| 147 | |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 148 | gsm_net_update_ctype(net); |
| 149 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 150 | return net; |
| 151 | } |
| 152 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 153 | struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num) |
| 154 | { |
| 155 | struct gsm_bts *bts; |
| 156 | |
| 157 | if (num >= net->num_bts) |
| 158 | return NULL; |
| 159 | |
| 160 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 161 | if (bts->nr == num) |
| 162 | return bts; |
| 163 | } |
| 164 | |
| 165 | return NULL; |
| 166 | } |
| 167 | |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 168 | /* Get reference to a neighbor cell on a given BCCH ARFCN */ |
Harald Welte | 792a1d4 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 169 | 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] | 170 | uint16_t arfcn, uint8_t bsic) |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 171 | { |
| 172 | struct gsm_bts *neigh; |
| 173 | /* FIXME: use some better heuristics here to determine which cell |
| 174 | * using this ARFCN really is closest to the target cell. For |
| 175 | * now we simply assume that each ARFCN will only be used by one |
| 176 | * cell */ |
| 177 | |
| 178 | llist_for_each_entry(neigh, &bts->network->bts_list, list) { |
Harald Welte | 792a1d4 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 179 | if (neigh->c0->arfcn == arfcn && |
| 180 | neigh->bsic == bsic) |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 181 | return neigh; |
| 182 | } |
| 183 | |
| 184 | return NULL; |
| 185 | } |
| 186 | |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 187 | const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1] = { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 188 | { GSM_BTS_TYPE_UNKNOWN, "unknown" }, |
| 189 | { GSM_BTS_TYPE_BS11, "bs11" }, |
| 190 | { GSM_BTS_TYPE_NANOBTS, "nanobts" }, |
Harald Welte | c2f27ba | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 191 | { GSM_BTS_TYPE_RBS2000, "rbs2000" }, |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 192 | { GSM_BTS_TYPE_HSL_FEMTO, "hsl_femto" }, |
Dieter Spaar | 49c843e | 2011-07-28 00:01:50 +0200 | [diff] [blame] | 193 | { GSM_BTS_TYPE_NOKIA_SITE, "nokia_site" }, |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 194 | { GSM_BTS_TYPE_OSMO_SYSMO, "sysmobts" }, |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 195 | { 0, NULL } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 196 | }; |
| 197 | |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 198 | const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1] = { |
| 199 | { GSM_BTS_TYPE_UNKNOWN, "Unknown BTS Type" }, |
| 200 | { GSM_BTS_TYPE_BS11, "Siemens BTS (BS-11 or compatible)" }, |
| 201 | { GSM_BTS_TYPE_NANOBTS, "ip.access nanoBTS or compatible" }, |
| 202 | { GSM_BTS_TYPE_RBS2000, "Ericsson RBS2000 Series" }, |
| 203 | { GSM_BTS_TYPE_HSL_FEMTO, "HSL 2.75G femto" }, |
| 204 | { GSM_BTS_TYPE_NOKIA_SITE, "Nokia {Metro,Ultra,In}Site" }, |
| 205 | { GSM_BTS_TYPE_OSMO_SYSMO, "sysmocom sysmoBTS" }, |
| 206 | { 0, NULL } |
| 207 | }; |
| 208 | |
Harald Welte | 498feae | 2009-08-08 15:38:29 +0200 | [diff] [blame] | 209 | enum gsm_bts_type parse_btstype(const char *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 210 | { |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 211 | return get_string_value(bts_type_names, arg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 212 | } |
| 213 | |
Holger Hans Peter Freyther | 56f59bb | 2009-06-12 17:39:38 +0200 | [diff] [blame] | 214 | const char *btstype2str(enum gsm_bts_type type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 215 | { |
Harald Welte | 85a77b1 | 2012-08-17 13:02:12 +0200 | [diff] [blame] | 216 | return get_value_string(bts_type_names, type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 217 | } |
| 218 | |
Harald Welte | c985a14 | 2010-01-07 20:44:32 +0100 | [diff] [blame] | 219 | struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr) |
| 220 | { |
| 221 | struct gsm_bts_trx *trx; |
| 222 | |
| 223 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 224 | if (trx->nr == nr) |
| 225 | return trx; |
| 226 | } |
| 227 | return NULL; |
| 228 | } |
| 229 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 230 | /* Search for a BTS in the given Location Area; optionally start searching |
| 231 | * with start_bts (for continuing to search after the first result) */ |
| 232 | struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac, |
| 233 | struct gsm_bts *start_bts) |
| 234 | { |
| 235 | int i; |
| 236 | struct gsm_bts *bts; |
| 237 | int skip = 0; |
| 238 | |
| 239 | if (start_bts) |
| 240 | skip = 1; |
| 241 | |
| 242 | for (i = 0; i < net->num_bts; i++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 243 | bts = gsm_bts_num(net, i); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 244 | |
| 245 | if (skip) { |
| 246 | if (start_bts == bts) |
| 247 | skip = 0; |
| 248 | continue; |
| 249 | } |
| 250 | |
Holger Hans Peter Freyther | 6c6ab86 | 2009-10-01 04:07:15 +0200 | [diff] [blame] | 251 | if (lac == GSM_LAC_RESERVED_ALL_BTS || bts->location_area_code == lac) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 252 | return bts; |
| 253 | } |
| 254 | return NULL; |
| 255 | } |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 256 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 257 | static const struct value_string auth_policy_names[] = { |
| 258 | { GSM_AUTH_POLICY_CLOSED, "closed" }, |
| 259 | { GSM_AUTH_POLICY_ACCEPT_ALL, "accept-all" }, |
| 260 | { GSM_AUTH_POLICY_TOKEN, "token" }, |
| 261 | { 0, NULL } |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | enum gsm_auth_policy gsm_auth_policy_parse(const char *arg) |
| 265 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 266 | return get_string_value(auth_policy_names, arg); |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | const char *gsm_auth_policy_name(enum gsm_auth_policy policy) |
| 270 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 271 | return get_value_string(auth_policy_names, policy); |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 274 | static const struct value_string rrlp_mode_names[] = { |
| 275 | { RRLP_MODE_NONE, "none" }, |
| 276 | { RRLP_MODE_MS_BASED, "ms-based" }, |
| 277 | { RRLP_MODE_MS_PREF, "ms-preferred" }, |
| 278 | { RRLP_MODE_ASS_PREF, "ass-preferred" }, |
| 279 | { 0, NULL } |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | enum rrlp_mode rrlp_mode_parse(const char *arg) |
| 283 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 284 | return get_string_value(rrlp_mode_names, arg); |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | const char *rrlp_mode_name(enum rrlp_mode mode) |
| 288 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 289 | return get_value_string(rrlp_mode_names, mode); |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 290 | } |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 291 | |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 292 | static const struct value_string bts_gprs_mode_names[] = { |
| 293 | { BTS_GPRS_NONE, "none" }, |
| 294 | { BTS_GPRS_GPRS, "gprs" }, |
| 295 | { BTS_GPRS_EGPRS, "egprs" }, |
| 296 | { 0, NULL } |
| 297 | }; |
| 298 | |
| 299 | enum bts_gprs_mode bts_gprs_mode_parse(const char *arg) |
| 300 | { |
| 301 | return get_string_value(bts_gprs_mode_names, arg); |
| 302 | } |
| 303 | |
| 304 | const char *bts_gprs_mode_name(enum bts_gprs_mode mode) |
| 305 | { |
| 306 | return get_value_string(bts_gprs_mode_names, mode); |
| 307 | } |
| 308 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 309 | struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan) |
| 310 | { |
| 311 | struct gsm_meas_rep *meas_rep; |
| 312 | |
| 313 | meas_rep = &lchan->meas_rep[lchan->meas_rep_idx]; |
| 314 | memset(meas_rep, 0, sizeof(*meas_rep)); |
| 315 | meas_rep->lchan = lchan; |
| 316 | lchan->meas_rep_idx = (lchan->meas_rep_idx + 1) |
| 317 | % ARRAY_SIZE(lchan->meas_rep); |
| 318 | |
| 319 | return meas_rep; |
| 320 | } |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 321 | |
Harald Welte | 20e275a | 2010-06-14 22:44:42 +0200 | [diff] [blame] | 322 | int gsm_btsmodel_set_feature(struct gsm_bts_model *bts, enum gsm_bts_features feat) |
| 323 | { |
| 324 | return bitvec_set_bit_pos(&bts->features, feat, 1); |
| 325 | } |
| 326 | |
| 327 | int gsm_bts_has_feature(struct gsm_bts *bts, enum gsm_bts_features feat) |
| 328 | { |
| 329 | return bitvec_get_bit_pos(&bts->model->features, feat); |
| 330 | } |
| 331 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 332 | 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] | 333 | { |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 334 | struct gsm_bts_model *model; |
| 335 | |
| 336 | model = bts_model_find(type); |
| 337 | if (!model) |
| 338 | return -EINVAL; |
| 339 | |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 340 | bts->type = type; |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 341 | bts->model = model; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 342 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 343 | if (model->start && !model->started) { |
| 344 | int ret = model->start(bts->network); |
| 345 | if (ret < 0) |
| 346 | return ret; |
| 347 | |
| 348 | model->started = true; |
| 349 | } |
| 350 | |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 351 | switch (bts->type) { |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 352 | case GSM_BTS_TYPE_HSL_FEMTO: |
| 353 | bts->c0->rsl_tei = 0; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 354 | case GSM_BTS_TYPE_NANOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 355 | case GSM_BTS_TYPE_OSMO_SYSMO: |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 356 | /* Set the default OML Stream ID to 0xff */ |
| 357 | bts->oml_tei = 0xff; |
| 358 | bts->c0->nominal_power = 23; |
| 359 | break; |
Harald Welte | 738310b | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 360 | case GSM_BTS_TYPE_RBS2000: |
| 361 | INIT_LLIST_HEAD(&bts->rbs2000.is.conn_groups); |
Harald Welte | a552655 | 2011-02-13 22:45:02 +0100 | [diff] [blame] | 362 | INIT_LLIST_HEAD(&bts->rbs2000.con.conn_groups); |
Harald Welte | 738310b | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 363 | break; |
Holger Hans Peter Freyther | ad51516 | 2012-02-03 19:44:37 +0100 | [diff] [blame] | 364 | case GSM_BTS_TYPE_BS11: |
| 365 | case GSM_BTS_TYPE_UNKNOWN: |
| 366 | case GSM_BTS_TYPE_NOKIA_SITE: |
Holger Hans Peter Freyther | dec95b3 | 2012-09-11 11:53:08 +0200 | [diff] [blame] | 367 | case _NUM_GSM_BTS_TYPE: |
Holger Hans Peter Freyther | ad51516 | 2012-02-03 19:44:37 +0100 | [diff] [blame] | 368 | break; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 369 | } |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 370 | |
| 371 | return 0; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 372 | } |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 373 | |
| 374 | struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net, enum gsm_bts_type type, |
| 375 | uint8_t tsc, uint8_t bsic) |
| 376 | { |
| 377 | struct gsm_bts_model *model = bts_model_find(type); |
| 378 | struct gsm_bts *bts; |
| 379 | |
Harald Welte | fe04bb9 | 2011-06-06 17:52:56 +0200 | [diff] [blame] | 380 | if (!model && type != GSM_BTS_TYPE_UNKNOWN) |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 381 | return NULL; |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 382 | |
| 383 | bts = gsm_bts_alloc(net); |
| 384 | if (!bts) |
| 385 | return NULL; |
| 386 | |
| 387 | bts->network = net; |
| 388 | bts->nr = net->num_bts++; |
| 389 | bts->type = type; |
| 390 | bts->model = model; |
| 391 | bts->tsc = tsc; |
| 392 | bts->bsic = bsic; |
| 393 | |
| 394 | bts->neigh_list_manual_mode = 0; |
| 395 | bts->si_common.cell_sel_par.cell_resel_hyst = 2; /* 4 dB */ |
| 396 | bts->si_common.cell_sel_par.rxlev_acc_min = 0; |
| 397 | bts->si_common.neigh_list.data = bts->si_common.data.neigh_list; |
| 398 | bts->si_common.neigh_list.data_len = |
| 399 | sizeof(bts->si_common.data.neigh_list); |
| 400 | bts->si_common.si5_neigh_list.data = bts->si_common.data.si5_neigh_list; |
| 401 | bts->si_common.si5_neigh_list.data_len = |
| 402 | sizeof(bts->si_common.data.si5_neigh_list); |
| 403 | bts->si_common.cell_alloc.data = bts->si_common.data.cell_alloc; |
| 404 | bts->si_common.cell_alloc.data_len = |
| 405 | sizeof(bts->si_common.data.cell_alloc); |
| 406 | bts->si_common.rach_control.re = 1; /* no re-establishment */ |
| 407 | bts->si_common.rach_control.tx_integer = 9; /* 12 slots spread - 217/115 slots delay */ |
| 408 | bts->si_common.rach_control.max_trans = 3; /* 7 retransmissions */ |
| 409 | bts->si_common.rach_control.t2 = 4; /* no emergency calls */ |
Andreas Eversberg | 14e12f2 | 2012-10-13 07:27:47 +0200 | [diff] [blame] | 410 | bts->si_common.chan_desc.att = 1; /* attachment required */ |
| 411 | bts->si_common.chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5; /* paging frames */ |
| 412 | 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] | 413 | bts->si_common.chan_desc.t3212 = 5; /* Use 30 min periodic update interval as sane default */ |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 414 | |
| 415 | llist_add_tail(&bts->list, &net->bts_list); |
| 416 | |
| 417 | INIT_LLIST_HEAD(&bts->abis_queue); |
| 418 | |
Daniel Willmann | 8c3483f | 2011-08-05 13:51:27 +0200 | [diff] [blame] | 419 | INIT_LLIST_HEAD(&bts->loc_list); |
| 420 | |
Harald Welte | c788128 | 2011-06-05 13:31:33 +0200 | [diff] [blame] | 421 | return bts; |
| 422 | } |
| 423 | |
| 424 | void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts) |
| 425 | { |
| 426 | raid->mcc = bts->network->country_code; |
| 427 | raid->mnc = bts->network->network_code; |
| 428 | raid->lac = bts->location_area_code; |
| 429 | raid->rac = bts->gprs.rac; |
| 430 | } |
| 431 | |
| 432 | int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts) |
| 433 | { |
| 434 | struct gprs_ra_id raid; |
| 435 | |
| 436 | gprs_ra_id_by_bts(&raid, bts); |
| 437 | |
| 438 | return gsm48_construct_ra(buf, &raid); |
| 439 | } |
Holger Hans Peter Freyther | 1c14d96 | 2011-06-09 21:48:49 +0200 | [diff] [blame] | 440 | |
| 441 | int gsm_parse_reg(void *ctx, regex_t *reg, char **str, int argc, const char **argv) |
| 442 | { |
| 443 | int ret; |
| 444 | |
| 445 | ret = 0; |
| 446 | if (*str) { |
| 447 | talloc_free(*str); |
| 448 | *str = NULL; |
| 449 | } |
| 450 | regfree(reg); |
| 451 | |
| 452 | if (argc > 0) { |
| 453 | *str = talloc_strdup(ctx, argv[0]); |
| 454 | ret = regcomp(reg, argv[0], 0); |
| 455 | |
| 456 | /* handle compilation failures */ |
| 457 | if (ret != 0) { |
| 458 | talloc_free(*str); |
| 459 | *str = NULL; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | return ret; |
| 464 | } |
| 465 | |