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> |
| 32 | #include <osmocom/core/statistics.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 33 | |
Holger Hans Peter Freyther | 3b556f9 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 34 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 35 | #include <openbsc/osmo_msc_data.h> |
Holger Hans Peter Freyther | 3b556f9 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 36 | #include <openbsc/abis_nm.h> |
| 37 | |
Andreas Eversberg | e4d5146 | 2009-06-29 15:19:38 +0200 | [diff] [blame] | 38 | void *tall_bsc_ctx; |
| 39 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 40 | static LLIST_HEAD(bts_models); |
| 41 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 42 | void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr, |
| 43 | uint8_t e1_ts, uint8_t e1_ts_ss) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 44 | { |
| 45 | ts->e1_link.e1_nr = e1_nr; |
| 46 | ts->e1_link.e1_ts = e1_ts; |
| 47 | ts->e1_link.e1_ts_ss = e1_ts_ss; |
| 48 | } |
| 49 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 50 | static const struct value_string pchan_names[] = { |
| 51 | { GSM_PCHAN_NONE, "NONE" }, |
| 52 | { GSM_PCHAN_CCCH, "CCCH" }, |
| 53 | { GSM_PCHAN_CCCH_SDCCH4,"CCCH+SDCCH4" }, |
| 54 | { GSM_PCHAN_TCH_F, "TCH/F" }, |
| 55 | { GSM_PCHAN_TCH_H, "TCH/H" }, |
| 56 | { GSM_PCHAN_SDCCH8_SACCH8C, "SDCCH8" }, |
| 57 | { GSM_PCHAN_PDCH, "PDCH" }, |
| 58 | { GSM_PCHAN_TCH_F_PDCH, "TCH/F_PDCH" }, |
| 59 | { GSM_PCHAN_UNKNOWN, "UNKNOWN" }, |
| 60 | { 0, NULL } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | const char *gsm_pchan_name(enum gsm_phys_chan_config c) |
| 64 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 65 | return get_value_string(pchan_names, c); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 66 | } |
| 67 | |
Harald Welte | d433177 | 2009-08-07 00:24:39 +0200 | [diff] [blame] | 68 | enum gsm_phys_chan_config gsm_pchan_parse(const char *name) |
| 69 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 70 | return get_string_value(pchan_names, name); |
Harald Welte | d433177 | 2009-08-07 00:24:39 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 73 | static const struct value_string lchant_names[] = { |
| 74 | { GSM_LCHAN_NONE, "NONE" }, |
| 75 | { GSM_LCHAN_SDCCH, "SDCCH" }, |
| 76 | { GSM_LCHAN_TCH_F, "TCH/F" }, |
| 77 | { GSM_LCHAN_TCH_H, "TCH/H" }, |
| 78 | { GSM_LCHAN_UNKNOWN, "UNKNOWN" }, |
| 79 | { 0, NULL } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 80 | }; |
| 81 | |
Harald Welte (local) | 02204d0 | 2009-12-27 18:05:25 +0100 | [diff] [blame] | 82 | const char *gsm_lchant_name(enum gsm_chan_t c) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 83 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 84 | return get_value_string(lchant_names, c); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 85 | } |
| 86 | |
Harald Welte | ab2534c | 2009-12-29 10:52:38 +0100 | [diff] [blame] | 87 | static const struct value_string lchan_s_names[] = { |
| 88 | { LCHAN_S_NONE, "NONE" }, |
| 89 | { LCHAN_S_ACT_REQ, "ACTIVATION REQUESTED" }, |
| 90 | { LCHAN_S_ACTIVE, "ACTIVE" }, |
| 91 | { LCHAN_S_INACTIVE, "INACTIVE" }, |
| 92 | { LCHAN_S_REL_REQ, "RELEASE REQUESTED" }, |
Holger Hans Peter Freyther | 10ea12f | 2010-05-31 21:38:24 +0800 | [diff] [blame] | 93 | { LCHAN_S_REL_ERR, "RELEASE DUE ERROR" }, |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 94 | { 0, NULL } |
Harald Welte | ab2534c | 2009-12-29 10:52:38 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | const char *gsm_lchans_name(enum gsm_lchan_state s) |
| 98 | { |
| 99 | return get_value_string(lchan_s_names, s); |
| 100 | } |
| 101 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 102 | static const struct value_string chreq_names[] = { |
| 103 | { GSM_CHREQ_REASON_EMERG, "EMERGENCY" }, |
| 104 | { GSM_CHREQ_REASON_PAG, "PAGING" }, |
| 105 | { GSM_CHREQ_REASON_CALL, "CALL" }, |
| 106 | { GSM_CHREQ_REASON_LOCATION_UPD,"LOCATION_UPDATE" }, |
| 107 | { GSM_CHREQ_REASON_OTHER, "OTHER" }, |
| 108 | { 0, NULL } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | const char *gsm_chreq_name(enum gsm_chreq_reason_t c) |
| 112 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 113 | return get_value_string(chreq_names, c); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 114 | } |
| 115 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 116 | static struct gsm_bts_model *bts_model_find(enum gsm_bts_type type) |
| 117 | { |
| 118 | struct gsm_bts_model *model; |
| 119 | |
| 120 | llist_for_each_entry(model, &bts_models, list) { |
| 121 | if (model->type == type) |
| 122 | return model; |
| 123 | } |
| 124 | |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | int gsm_bts_model_register(struct gsm_bts_model *model) |
| 129 | { |
| 130 | if (bts_model_find(model->type)) |
| 131 | return -EEXIST; |
| 132 | |
| 133 | tlv_def_patch(&model->nm_att_tlvdef, &nm_att_tlvdef); |
| 134 | llist_add_tail(&model->list, &bts_models); |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 139 | struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 140 | { |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 141 | struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 142 | int k; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 143 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 144 | if (!trx) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 145 | return NULL; |
| 146 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 147 | trx->bts = bts; |
| 148 | trx->nr = bts->num_trx++; |
Holger Hans Peter Freyther | 677bb2f | 2009-12-31 03:05:52 +0100 | [diff] [blame] | 149 | trx->nm_state.administrative = NM_STATE_UNLOCKED; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 150 | |
| 151 | for (k = 0; k < TRX_NR_TS; k++) { |
| 152 | struct gsm_bts_trx_ts *ts = &trx->ts[k]; |
| 153 | int l; |
| 154 | |
| 155 | ts->trx = trx; |
| 156 | ts->nr = k; |
| 157 | ts->pchan = GSM_PCHAN_NONE; |
| 158 | |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 159 | ts->hopping.arfcns.data_len = sizeof(ts->hopping.arfcns_data); |
| 160 | ts->hopping.arfcns.data = ts->hopping.arfcns_data; |
Harald Welte | bf6624d | 2010-06-15 08:52:12 +0200 | [diff] [blame] | 161 | ts->hopping.ma.data_len = sizeof(ts->hopping.ma_data); |
| 162 | ts->hopping.ma.data = ts->hopping.ma_data; |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 163 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 164 | for (l = 0; l < TS_MAX_LCHAN; l++) { |
| 165 | struct gsm_lchan *lchan; |
| 166 | lchan = &ts->lchan[l]; |
| 167 | |
| 168 | lchan->ts = ts; |
| 169 | lchan->nr = l; |
| 170 | lchan->type = GSM_LCHAN_NONE; |
| 171 | } |
| 172 | } |
| 173 | |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 174 | if (trx->nr != 0) |
| 175 | trx->nominal_power = bts->c0->nominal_power; |
| 176 | |
Harald Welte | e84efce | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 177 | llist_add_tail(&trx->list, &bts->trx_list); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 178 | |
| 179 | return trx; |
| 180 | } |
| 181 | |
Harald Welte | a925176 | 2010-05-11 23:50:21 +0200 | [diff] [blame] | 182 | static const uint8_t bts_nse_timer_default[] = { 3, 3, 3, 3, 30, 3, 10 }; |
| 183 | static const uint8_t bts_cell_timer_default[] = |
| 184 | { 3, 3, 3, 3, 3, 10, 3, 10, 3, 10, 3 }; |
| 185 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 186 | struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 187 | uint8_t tsc, uint8_t bsic) |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 188 | { |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 189 | struct gsm_bts *bts = talloc_zero(net, struct gsm_bts); |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 190 | struct gsm_bts_model *model = bts_model_find(type); |
Harald Welte | 439e128 | 2009-10-24 10:19:14 +0200 | [diff] [blame] | 191 | int i; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 192 | |
| 193 | if (!bts) |
| 194 | return NULL; |
| 195 | |
laforge | f3f5829 | 2010-01-12 10:44:26 +0100 | [diff] [blame] | 196 | if (!model && type != GSM_BTS_TYPE_UNKNOWN) { |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 197 | talloc_free(bts); |
| 198 | return NULL; |
| 199 | } |
| 200 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 201 | bts->network = net; |
| 202 | bts->nr = net->num_bts++; |
| 203 | bts->type = type; |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 204 | bts->model = model; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 205 | bts->tsc = tsc; |
| 206 | bts->bsic = bsic; |
| 207 | bts->num_trx = 0; |
| 208 | INIT_LLIST_HEAD(&bts->trx_list); |
Harald Welte (local) | cbd4610 | 2009-08-13 10:14:26 +0200 | [diff] [blame] | 209 | bts->ms_max_power = 15; /* dBm */ |
Harald Welte | ca46eff | 2011-01-11 23:44:56 +0100 | [diff] [blame] | 210 | |
| 211 | bts->neigh_list_manual_mode = 0; |
Harald Welte | b761bf8 | 2009-12-12 18:17:25 +0100 | [diff] [blame] | 212 | bts->si_common.cell_sel_par.cell_resel_hyst = 2; /* 4 dB */ |
| 213 | bts->si_common.cell_sel_par.rxlev_acc_min = 0; |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 214 | bts->si_common.neigh_list.data = bts->si_common.data.neigh_list; |
| 215 | bts->si_common.neigh_list.data_len = |
| 216 | sizeof(bts->si_common.data.neigh_list); |
Harald Welte | f989b78 | 2011-02-15 11:43:27 +0100 | [diff] [blame] | 217 | bts->si_common.si5_neigh_list.data = bts->si_common.data.si5_neigh_list; |
| 218 | bts->si_common.si5_neigh_list.data_len = |
| 219 | sizeof(bts->si_common.data.si5_neigh_list); |
Harald Welte | 6ae6467 | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 220 | bts->si_common.cell_alloc.data = bts->si_common.data.cell_alloc; |
| 221 | bts->si_common.cell_alloc.data_len = |
| 222 | sizeof(bts->si_common.data.cell_alloc); |
Sylvain Munaut | 8e2d8de | 2009-12-22 13:43:26 +0100 | [diff] [blame] | 223 | bts->si_common.rach_control.re = 1; /* no re-establishment */ |
| 224 | bts->si_common.rach_control.tx_integer = 9; /* 12 slots spread - 217/115 slots delay */ |
| 225 | bts->si_common.rach_control.max_trans = 3; /* 7 retransmissions */ |
| 226 | bts->si_common.rach_control.t2 = 4; /* no emergency calls */ |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 227 | |
Harald Welte | 439e128 | 2009-10-24 10:19:14 +0200 | [diff] [blame] | 228 | for (i = 0; i < ARRAY_SIZE(bts->gprs.nsvc); i++) { |
| 229 | bts->gprs.nsvc[i].bts = bts; |
| 230 | bts->gprs.nsvc[i].id = i; |
| 231 | } |
Harald Welte | a925176 | 2010-05-11 23:50:21 +0200 | [diff] [blame] | 232 | memcpy(&bts->gprs.nse.timer, bts_nse_timer_default, |
| 233 | sizeof(bts->gprs.nse.timer)); |
| 234 | memcpy(&bts->gprs.cell.timer, bts_cell_timer_default, |
| 235 | sizeof(bts->gprs.cell.timer)); |
Harald Welte | 439e128 | 2009-10-24 10:19:14 +0200 | [diff] [blame] | 236 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 237 | /* create our primary TRX */ |
| 238 | bts->c0 = gsm_bts_trx_alloc(bts); |
| 239 | if (!bts->c0) { |
| 240 | talloc_free(bts); |
| 241 | return NULL; |
| 242 | } |
| 243 | bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4; |
| 244 | |
Holger Hans Peter Freyther | 697ed2b | 2010-04-25 23:08:39 +0800 | [diff] [blame] | 245 | bts->rach_b_thresh = -1; |
| 246 | bts->rach_ldavg_slots = -1; |
Holger Hans Peter Freyther | 3112f67 | 2010-09-06 10:11:25 +0800 | [diff] [blame] | 247 | bts->paging.free_chans_need = -1; |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 248 | INIT_LLIST_HEAD(&bts->abis_queue); |
| 249 | |
Harald Welte | e84efce | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 250 | llist_add_tail(&bts->list, &net->bts_list); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 251 | |
| 252 | return bts; |
| 253 | } |
| 254 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 255 | 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] | 256 | int (*mncc_recv)(struct gsm_network *, struct msgb *)) |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 257 | { |
| 258 | struct gsm_network *net; |
| 259 | |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 260 | net = talloc_zero(tall_bsc_ctx, struct gsm_network); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 261 | if (!net) |
| 262 | return NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 263 | |
Holger Hans Peter Freyther | 58b3df5 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 264 | net->msc_data = talloc_zero(net, struct osmo_msc_data); |
| 265 | if (!net->msc_data) { |
| 266 | talloc_free(net); |
| 267 | return NULL; |
| 268 | } |
| 269 | |
Daniel Willmann | 8f6e20d | 2011-03-03 13:48:28 +0100 | [diff] [blame] | 270 | /* Init back pointer */ |
| 271 | net->msc_data->network = net; |
| 272 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 273 | net->country_code = country_code; |
| 274 | net->network_code = network_code; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 275 | net->num_bts = 0; |
Holger Hans Peter Freyther | e0938e1 | 2010-01-07 16:08:42 +0100 | [diff] [blame] | 276 | net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED; |
Harald Welte | a963980 | 2009-12-01 17:36:54 +0530 | [diff] [blame] | 277 | net->T3101 = GSM_T3101_DEFAULT; |
| 278 | net->T3113 = GSM_T3113_DEFAULT; |
| 279 | /* FIXME: initialize all other timers! */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 280 | |
Harald Welte | 92d8891 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 281 | /* default set of handover parameters */ |
| 282 | net->handover.win_rxlev_avg = 10; |
| 283 | net->handover.win_rxqual_avg = 1; |
| 284 | net->handover.win_rxlev_avg_neigh = 10; |
| 285 | net->handover.pwr_interval = 6; |
| 286 | net->handover.pwr_hysteresis = 3; |
| 287 | net->handover.max_distance = 9999; |
| 288 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 289 | INIT_LLIST_HEAD(&net->trans_list); |
| 290 | INIT_LLIST_HEAD(&net->upqueue); |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 291 | INIT_LLIST_HEAD(&net->bts_list); |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 292 | |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 293 | net->stats.chreq.total = counter_alloc("net.chreq.total"); |
| 294 | net->stats.chreq.no_channel = counter_alloc("net.chreq.no_channel"); |
| 295 | net->stats.handover.attempted = counter_alloc("net.handover.attempted"); |
| 296 | net->stats.handover.no_channel = counter_alloc("net.handover.no_channel"); |
| 297 | net->stats.handover.timeout = counter_alloc("net.handover.timeout"); |
| 298 | net->stats.handover.completed = counter_alloc("net.handover.completed"); |
| 299 | net->stats.handover.failed = counter_alloc("net.handover.failed"); |
| 300 | net->stats.loc_upd_type.attach = counter_alloc("net.loc_upd_type.attach"); |
| 301 | net->stats.loc_upd_type.normal = counter_alloc("net.loc_upd_type.normal"); |
| 302 | net->stats.loc_upd_type.periodic = counter_alloc("net.loc_upd_type.periodic"); |
| 303 | net->stats.loc_upd_type.detach = counter_alloc("net.imsi_detach.count"); |
| 304 | net->stats.loc_upd_resp.reject = counter_alloc("net.loc_upd_resp.reject"); |
| 305 | net->stats.loc_upd_resp.accept = counter_alloc("net.loc_upd_resp.accept"); |
| 306 | net->stats.paging.attempted = counter_alloc("net.paging.attempted"); |
| 307 | net->stats.paging.detached = counter_alloc("net.paging.detached"); |
| 308 | net->stats.paging.completed = counter_alloc("net.paging.completed"); |
| 309 | net->stats.paging.expired = counter_alloc("net.paging.expired"); |
| 310 | net->stats.sms.submitted = counter_alloc("net.sms.submitted"); |
| 311 | net->stats.sms.no_receiver = counter_alloc("net.sms.no_receiver"); |
| 312 | net->stats.sms.delivered = counter_alloc("net.sms.delivered"); |
| 313 | net->stats.sms.rp_err_mem = counter_alloc("net.sms.rp_err_mem"); |
| 314 | net->stats.sms.rp_err_other = counter_alloc("net.sms.rp_err_other"); |
Harald Welte | c56006b | 2010-12-24 16:06:33 +0100 | [diff] [blame] | 315 | net->stats.call.mo_setup = counter_alloc("net.call.mo_setup"); |
| 316 | net->stats.call.mo_connect_ack = counter_alloc("net.call.mo_connect_ack"); |
| 317 | net->stats.call.mt_setup = counter_alloc("net.call.mt_setup"); |
| 318 | net->stats.call.mt_connect = counter_alloc("net.call.mt_connect"); |
Holger Hans Peter Freyther | 27942e9 | 2010-04-17 06:48:29 +0200 | [diff] [blame] | 319 | net->stats.chan.rf_fail = counter_alloc("net.chan.rf_fail"); |
| 320 | net->stats.chan.rll_err = counter_alloc("net.chan.rll_err"); |
Holger Hans Peter Freyther | 3e09b3f | 2010-04-12 10:45:52 +0200 | [diff] [blame] | 321 | net->stats.bts.oml_fail = counter_alloc("net.bts.oml_fail"); |
| 322 | net->stats.bts.rsl_fail = counter_alloc("net.bts.rsl_fail"); |
Harald Welte | bdbb744 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 323 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 324 | net->mncc_recv = mncc_recv; |
| 325 | |
Holger Hans Peter Freyther | 65a64e8 | 2010-09-16 02:00:01 +0800 | [diff] [blame] | 326 | net->msc_data->msc_ip = talloc_strdup(net, "127.0.0.1"); |
| 327 | net->msc_data->msc_port = 5000; |
| 328 | net->msc_data->ping_timeout = 20; |
| 329 | net->msc_data->pong_timeout = 5; |
Holger Hans Peter Freyther | 21a1cf3 | 2010-11-03 13:12:18 +0100 | [diff] [blame] | 330 | net->msc_data->core_ncc = -1; |
Holger Hans Peter Freyther | 3e0525f | 2010-11-05 19:43:07 +0100 | [diff] [blame] | 331 | net->msc_data->core_mcc = -1; |
Holger Hans Peter Freyther | 7dcd8e3 | 2010-11-03 13:32:48 +0100 | [diff] [blame] | 332 | net->msc_data->rtp_base = 4000; |
Holger Hans Peter Freyther | 65a64e8 | 2010-09-16 02:00:01 +0800 | [diff] [blame] | 333 | |
Holger Hans Peter Freyther | f0f37f1 | 2010-09-06 09:36:02 +0800 | [diff] [blame] | 334 | gsm_net_update_ctype(net); |
| 335 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 336 | return net; |
| 337 | } |
| 338 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 339 | struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num) |
| 340 | { |
| 341 | struct gsm_bts *bts; |
| 342 | |
| 343 | if (num >= net->num_bts) |
| 344 | return NULL; |
| 345 | |
| 346 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 347 | if (bts->nr == num) |
| 348 | return bts; |
| 349 | } |
| 350 | |
| 351 | return NULL; |
| 352 | } |
| 353 | |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 354 | /* Get reference to a neighbor cell on a given BCCH ARFCN */ |
Harald Welte | 792a1d4 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 355 | 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] | 356 | uint16_t arfcn, uint8_t bsic) |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 357 | { |
| 358 | struct gsm_bts *neigh; |
| 359 | /* FIXME: use some better heuristics here to determine which cell |
| 360 | * using this ARFCN really is closest to the target cell. For |
| 361 | * now we simply assume that each ARFCN will only be used by one |
| 362 | * cell */ |
| 363 | |
| 364 | llist_for_each_entry(neigh, &bts->network->bts_list, list) { |
Harald Welte | 792a1d4 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 365 | if (neigh->c0->arfcn == arfcn && |
| 366 | neigh->bsic == bsic) |
Harald Welte | 2a47086 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 367 | return neigh; |
| 368 | } |
| 369 | |
| 370 | return NULL; |
| 371 | } |
| 372 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 373 | struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num) |
| 374 | { |
| 375 | struct gsm_bts_trx *trx; |
| 376 | |
| 377 | if (num >= bts->num_trx) |
| 378 | return NULL; |
| 379 | |
| 380 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 381 | if (trx->nr == num) |
| 382 | return trx; |
| 383 | } |
| 384 | |
| 385 | return NULL; |
| 386 | } |
| 387 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 388 | static char ts2str[255]; |
| 389 | |
Harald Welte (local) | ab788cf | 2009-12-28 23:14:22 +0100 | [diff] [blame] | 390 | char *gsm_trx_name(struct gsm_bts_trx *trx) |
| 391 | { |
| 392 | snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d)", |
| 393 | trx->bts->nr, trx->nr); |
| 394 | |
| 395 | return ts2str; |
| 396 | } |
| 397 | |
| 398 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 399 | char *gsm_ts_name(struct gsm_bts_trx_ts *ts) |
| 400 | { |
| 401 | snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d)", |
Mike Haben | c0c5079 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 402 | ts->trx->bts->nr, ts->trx->nr, ts->nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 403 | |
| 404 | return ts2str; |
| 405 | } |
| 406 | |
Harald Welte (local) | c4e9c9c | 2009-12-27 18:16:36 +0100 | [diff] [blame] | 407 | char *gsm_lchan_name(struct gsm_lchan *lchan) |
| 408 | { |
| 409 | struct gsm_bts_trx_ts *ts = lchan->ts; |
| 410 | |
| 411 | snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d,ss=%d)", |
| 412 | ts->trx->bts->nr, ts->trx->nr, ts->nr, lchan->nr); |
| 413 | |
| 414 | return ts2str; |
| 415 | } |
| 416 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 417 | static const struct value_string bts_types[] = { |
| 418 | { GSM_BTS_TYPE_UNKNOWN, "unknown" }, |
| 419 | { GSM_BTS_TYPE_BS11, "bs11" }, |
| 420 | { GSM_BTS_TYPE_NANOBTS, "nanobts" }, |
Harald Welte | c2f27ba | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 421 | { GSM_BTS_TYPE_RBS2000, "rbs2000" }, |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 422 | { GSM_BTS_TYPE_HSL_FEMTO, "hsl_femto" }, |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 423 | { 0, NULL } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 424 | }; |
| 425 | |
Harald Welte | 498feae | 2009-08-08 15:38:29 +0200 | [diff] [blame] | 426 | enum gsm_bts_type parse_btstype(const char *arg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 427 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 428 | return get_string_value(bts_types, arg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 429 | } |
| 430 | |
Holger Hans Peter Freyther | 56f59bb | 2009-06-12 17:39:38 +0200 | [diff] [blame] | 431 | const char *btstype2str(enum gsm_bts_type type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 432 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 433 | return get_value_string(bts_types, type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 434 | } |
| 435 | |
Harald Welte | c985a14 | 2010-01-07 20:44:32 +0100 | [diff] [blame] | 436 | struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr) |
| 437 | { |
| 438 | struct gsm_bts_trx *trx; |
| 439 | |
| 440 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 441 | if (trx->nr == nr) |
| 442 | return trx; |
| 443 | } |
| 444 | return NULL; |
| 445 | } |
| 446 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 447 | /* Search for a BTS in the given Location Area; optionally start searching |
| 448 | * with start_bts (for continuing to search after the first result) */ |
| 449 | struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac, |
| 450 | struct gsm_bts *start_bts) |
| 451 | { |
| 452 | int i; |
| 453 | struct gsm_bts *bts; |
| 454 | int skip = 0; |
| 455 | |
| 456 | if (start_bts) |
| 457 | skip = 1; |
| 458 | |
| 459 | for (i = 0; i < net->num_bts; i++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 460 | bts = gsm_bts_num(net, i); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 461 | |
| 462 | if (skip) { |
| 463 | if (start_bts == bts) |
| 464 | skip = 0; |
| 465 | continue; |
| 466 | } |
| 467 | |
Holger Hans Peter Freyther | 6c6ab86 | 2009-10-01 04:07:15 +0200 | [diff] [blame] | 468 | if (lac == GSM_LAC_RESERVED_ALL_BTS || bts->location_area_code == lac) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 469 | return bts; |
| 470 | } |
| 471 | return NULL; |
| 472 | } |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 473 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 474 | static const struct value_string auth_policy_names[] = { |
| 475 | { GSM_AUTH_POLICY_CLOSED, "closed" }, |
| 476 | { GSM_AUTH_POLICY_ACCEPT_ALL, "accept-all" }, |
| 477 | { GSM_AUTH_POLICY_TOKEN, "token" }, |
| 478 | { 0, NULL } |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 479 | }; |
| 480 | |
| 481 | enum gsm_auth_policy gsm_auth_policy_parse(const char *arg) |
| 482 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 483 | return get_string_value(auth_policy_names, arg); |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | const char *gsm_auth_policy_name(enum gsm_auth_policy policy) |
| 487 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 488 | return get_value_string(auth_policy_names, policy); |
Harald Welte (local) | a59a27e | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 489 | } |
| 490 | |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 491 | void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts) |
| 492 | { |
| 493 | raid->mcc = bts->network->country_code; |
| 494 | raid->mnc = bts->network->network_code; |
| 495 | raid->lac = bts->location_area_code; |
| 496 | raid->rac = bts->gprs.rac; |
| 497 | } |
| 498 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 499 | int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts) |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 500 | { |
| 501 | struct gprs_ra_id raid; |
| 502 | |
| 503 | gprs_ra_id_by_bts(&raid, bts); |
| 504 | |
| 505 | return gsm48_construct_ra(buf, &raid); |
| 506 | } |
| 507 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 508 | static const struct value_string rrlp_mode_names[] = { |
| 509 | { RRLP_MODE_NONE, "none" }, |
| 510 | { RRLP_MODE_MS_BASED, "ms-based" }, |
| 511 | { RRLP_MODE_MS_PREF, "ms-preferred" }, |
| 512 | { RRLP_MODE_ASS_PREF, "ass-preferred" }, |
| 513 | { 0, NULL } |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 514 | }; |
| 515 | |
| 516 | enum rrlp_mode rrlp_mode_parse(const char *arg) |
| 517 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 518 | return get_string_value(rrlp_mode_names, arg); |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | const char *rrlp_mode_name(enum rrlp_mode mode) |
| 522 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 523 | return get_value_string(rrlp_mode_names, mode); |
Harald Welte | 52af195 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 524 | } |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 525 | |
Harald Welte | cb20b7a | 2010-04-18 15:51:20 +0200 | [diff] [blame] | 526 | static const struct value_string bts_gprs_mode_names[] = { |
| 527 | { BTS_GPRS_NONE, "none" }, |
| 528 | { BTS_GPRS_GPRS, "gprs" }, |
| 529 | { BTS_GPRS_EGPRS, "egprs" }, |
| 530 | { 0, NULL } |
| 531 | }; |
| 532 | |
| 533 | enum bts_gprs_mode bts_gprs_mode_parse(const char *arg) |
| 534 | { |
| 535 | return get_string_value(bts_gprs_mode_names, arg); |
| 536 | } |
| 537 | |
| 538 | const char *bts_gprs_mode_name(enum bts_gprs_mode mode) |
| 539 | { |
| 540 | return get_value_string(bts_gprs_mode_names, mode); |
| 541 | } |
| 542 | |
Harald Welte | f947681 | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 543 | struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan) |
| 544 | { |
| 545 | struct gsm_meas_rep *meas_rep; |
| 546 | |
| 547 | meas_rep = &lchan->meas_rep[lchan->meas_rep_idx]; |
| 548 | memset(meas_rep, 0, sizeof(*meas_rep)); |
| 549 | meas_rep->lchan = lchan; |
| 550 | lchan->meas_rep_idx = (lchan->meas_rep_idx + 1) |
| 551 | % ARRAY_SIZE(lchan->meas_rep); |
| 552 | |
| 553 | return meas_rep; |
| 554 | } |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 555 | |
Harald Welte | 20e275a | 2010-06-14 22:44:42 +0200 | [diff] [blame] | 556 | int gsm_btsmodel_set_feature(struct gsm_bts_model *bts, enum gsm_bts_features feat) |
| 557 | { |
| 558 | return bitvec_set_bit_pos(&bts->features, feat, 1); |
| 559 | } |
| 560 | |
| 561 | int gsm_bts_has_feature(struct gsm_bts *bts, enum gsm_bts_features feat) |
| 562 | { |
| 563 | return bitvec_get_bit_pos(&bts->model->features, feat); |
| 564 | } |
| 565 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 566 | 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] | 567 | { |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 568 | struct gsm_bts_model *model; |
| 569 | |
| 570 | model = bts_model_find(type); |
| 571 | if (!model) |
| 572 | return -EINVAL; |
| 573 | |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 574 | bts->type = type; |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 575 | bts->model = model; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 576 | |
| 577 | switch (bts->type) { |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 578 | case GSM_BTS_TYPE_HSL_FEMTO: |
| 579 | bts->c0->rsl_tei = 0; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 580 | case GSM_BTS_TYPE_NANOBTS: |
| 581 | /* Set the default OML Stream ID to 0xff */ |
| 582 | bts->oml_tei = 0xff; |
| 583 | bts->c0->nominal_power = 23; |
| 584 | break; |
| 585 | case GSM_BTS_TYPE_BS11: |
Holger Hans Peter Freyther | d7b35df | 2010-05-14 02:53:22 +0800 | [diff] [blame] | 586 | case GSM_BTS_TYPE_UNKNOWN: |
| 587 | break; |
Harald Welte | 738310b | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 588 | case GSM_BTS_TYPE_RBS2000: |
| 589 | INIT_LLIST_HEAD(&bts->rbs2000.is.conn_groups); |
Harald Welte | a552655 | 2011-02-13 22:45:02 +0100 | [diff] [blame] | 590 | INIT_LLIST_HEAD(&bts->rbs2000.con.conn_groups); |
Harald Welte | 738310b | 2011-02-13 22:13:28 +0100 | [diff] [blame] | 591 | break; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 592 | } |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 593 | |
| 594 | return 0; |
Harald Welte (local) | b709bfe | 2009-12-27 20:56:38 +0100 | [diff] [blame] | 595 | } |