Harald Welte | 32201c1 | 2009-03-10 12:15:10 +0000 | [diff] [blame] | 1 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 2 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include <stdlib.h> |
Harald Welte | 51f3845 | 2009-02-24 22:36:40 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 24 | #include <string.h> |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 25 | #include <errno.h> |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 26 | #include <ctype.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 27 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 28 | #include <openbsc/gsm_data.h> |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 29 | #include <openbsc/talloc.h> |
Holger Hans Peter Freyther | 2d501ea | 2009-11-11 11:54:24 +0100 | [diff] [blame] | 30 | #include <openbsc/abis_nm.h> |
Harald Welte | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 31 | #include <openbsc/statistics.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 32 | |
Andreas Eversberg | 8226fa7 | 2009-06-29 15:19:38 +0200 | [diff] [blame] | 33 | void *tall_bsc_ctx; |
| 34 | |
Harald Welte | ccda965 | 2009-11-12 22:28:18 +0900 | [diff] [blame] | 35 | const char *get_value_string(const struct value_string *vs, u_int32_t val) |
| 36 | { |
| 37 | int i; |
| 38 | |
| 39 | for (i = 0;; i++) { |
| 40 | if (vs[i].value == 0 && vs[i].str == NULL) |
| 41 | break; |
| 42 | if (vs[i].value == val) |
| 43 | return vs[i].str; |
| 44 | } |
| 45 | return "unknown"; |
| 46 | } |
| 47 | |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 48 | void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr, |
| 49 | u_int8_t e1_ts, u_int8_t e1_ts_ss) |
| 50 | { |
| 51 | ts->e1_link.e1_nr = e1_nr; |
| 52 | ts->e1_link.e1_ts = e1_ts; |
| 53 | ts->e1_link.e1_ts_ss = e1_ts_ss; |
| 54 | } |
| 55 | |
Harald Welte | a72c98e | 2009-01-04 16:10:38 +0000 | [diff] [blame] | 56 | static const char *pchan_names[] = { |
| 57 | [GSM_PCHAN_NONE] = "NONE", |
| 58 | [GSM_PCHAN_CCCH] = "CCCH", |
| 59 | [GSM_PCHAN_CCCH_SDCCH4] = "CCCH+SDCCH4", |
| 60 | [GSM_PCHAN_TCH_F] = "TCH/F", |
| 61 | [GSM_PCHAN_TCH_H] = "TCH/H", |
| 62 | [GSM_PCHAN_SDCCH8_SACCH8C] = "SDCCH8", |
Harald Welte | a1499d0 | 2009-10-24 10:25:50 +0200 | [diff] [blame] | 63 | [GSM_PCHAN_PDCH] = "PDCH", |
| 64 | [GSM_PCHAN_TCH_F_PDCH] = "TCH/F_PDCH", |
Harald Welte | a72c98e | 2009-01-04 16:10:38 +0000 | [diff] [blame] | 65 | [GSM_PCHAN_UNKNOWN] = "UNKNOWN", |
| 66 | }; |
| 67 | |
| 68 | const char *gsm_pchan_name(enum gsm_phys_chan_config c) |
| 69 | { |
| 70 | if (c >= ARRAY_SIZE(pchan_names)) |
| 71 | return "INVALID"; |
| 72 | |
| 73 | return pchan_names[c]; |
| 74 | } |
| 75 | |
Harald Welte | a171a1b | 2009-08-07 00:24:39 +0200 | [diff] [blame] | 76 | enum gsm_phys_chan_config gsm_pchan_parse(const char *name) |
| 77 | { |
| 78 | int i; |
| 79 | |
| 80 | for (i = 0; i < ARRAY_SIZE(pchan_names); i++) { |
| 81 | if (!strcasecmp(name, pchan_names[i])) |
| 82 | return i; |
| 83 | } |
| 84 | |
| 85 | return -1; |
| 86 | } |
| 87 | |
Harald Welte | a72c98e | 2009-01-04 16:10:38 +0000 | [diff] [blame] | 88 | static const char *lchan_names[] = { |
| 89 | [GSM_LCHAN_NONE] = "NONE", |
| 90 | [GSM_LCHAN_SDCCH] = "SDCCH", |
| 91 | [GSM_LCHAN_TCH_F] = "TCH/F", |
| 92 | [GSM_LCHAN_TCH_H] = "TCH/H", |
| 93 | [GSM_LCHAN_UNKNOWN] = "UNKNOWN", |
| 94 | }; |
| 95 | |
| 96 | const char *gsm_lchan_name(enum gsm_chan_t c) |
| 97 | { |
| 98 | if (c >= ARRAY_SIZE(lchan_names)) |
| 99 | return "INVALID"; |
| 100 | |
| 101 | return lchan_names[c]; |
| 102 | } |
| 103 | |
| 104 | static const char *chreq_names[] = { |
| 105 | [GSM_CHREQ_REASON_EMERG] = "EMERGENCY", |
| 106 | [GSM_CHREQ_REASON_PAG] = "PAGING", |
| 107 | [GSM_CHREQ_REASON_CALL] = "CALL", |
| 108 | [GSM_CHREQ_REASON_LOCATION_UPD] = "LOCATION_UPDATE", |
| 109 | [GSM_CHREQ_REASON_OTHER] = "OTHER", |
| 110 | }; |
| 111 | |
| 112 | const char *gsm_chreq_name(enum gsm_chreq_reason_t c) |
| 113 | { |
| 114 | if (c >= ARRAY_SIZE(chreq_names)) |
| 115 | return "INVALID"; |
| 116 | |
| 117 | return chreq_names[c]; |
| 118 | } |
| 119 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 120 | struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 121 | { |
Holger Hans Peter Freyther | 5ea7313 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 122 | struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx); |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 123 | int k; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 124 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 125 | if (!trx) |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 126 | return NULL; |
| 127 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 128 | trx->bts = bts; |
| 129 | trx->nr = bts->num_trx++; |
| 130 | |
| 131 | for (k = 0; k < TRX_NR_TS; k++) { |
| 132 | struct gsm_bts_trx_ts *ts = &trx->ts[k]; |
| 133 | int l; |
| 134 | |
| 135 | ts->trx = trx; |
| 136 | ts->nr = k; |
| 137 | ts->pchan = GSM_PCHAN_NONE; |
| 138 | |
| 139 | for (l = 0; l < TS_MAX_LCHAN; l++) { |
| 140 | struct gsm_lchan *lchan; |
| 141 | lchan = &ts->lchan[l]; |
| 142 | |
| 143 | lchan->ts = ts; |
| 144 | lchan->nr = l; |
| 145 | lchan->type = GSM_LCHAN_NONE; |
| 146 | } |
| 147 | } |
| 148 | |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 149 | llist_add_tail(&trx->list, &bts->trx_list); |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 150 | |
| 151 | return trx; |
| 152 | } |
| 153 | |
| 154 | struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type, |
| 155 | u_int8_t tsc, u_int8_t bsic) |
| 156 | { |
Holger Hans Peter Freyther | 5ea7313 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 157 | struct gsm_bts *bts = talloc_zero(net, struct gsm_bts); |
Harald Welte | 55dd443 | 2009-10-24 10:19:14 +0200 | [diff] [blame] | 158 | int i; |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 159 | |
| 160 | if (!bts) |
| 161 | return NULL; |
| 162 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 163 | bts->network = net; |
| 164 | bts->nr = net->num_bts++; |
| 165 | bts->type = type; |
| 166 | bts->tsc = tsc; |
| 167 | bts->bsic = bsic; |
| 168 | bts->num_trx = 0; |
| 169 | INIT_LLIST_HEAD(&bts->trx_list); |
Harald Welte (local) | 0e451d0 | 2009-08-13 10:14:26 +0200 | [diff] [blame] | 170 | bts->ms_max_power = 15; /* dBm */ |
Harald Welte | 7322528 | 2009-12-12 18:17:25 +0100 | [diff] [blame] | 171 | bts->si_common.cell_sel_par.cell_resel_hyst = 2; /* 4 dB */ |
| 172 | bts->si_common.cell_sel_par.rxlev_acc_min = 0; |
Harald Welte | 6c40def | 2009-12-14 22:07:14 +0100 | [diff] [blame] | 173 | bts->si_common.neigh_list.data = bts->si_common.data.neigh_list; |
| 174 | bts->si_common.neigh_list.data_len = |
| 175 | sizeof(bts->si_common.data.neigh_list); |
| 176 | bts->si_common.cell_alloc.data = bts->si_common.data.cell_alloc; |
| 177 | bts->si_common.cell_alloc.data_len = |
| 178 | sizeof(bts->si_common.data.cell_alloc); |
Sylvain Munaut | 4010f1e | 2009-12-22 13:43:26 +0100 | [diff] [blame] | 179 | bts->si_common.rach_control.re = 1; /* no re-establishment */ |
| 180 | bts->si_common.rach_control.tx_integer = 9; /* 12 slots spread - 217/115 slots delay */ |
| 181 | bts->si_common.rach_control.max_trans = 3; /* 7 retransmissions */ |
| 182 | bts->si_common.rach_control.t2 = 4; /* no emergency calls */ |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 183 | |
Harald Welte | 55dd443 | 2009-10-24 10:19:14 +0200 | [diff] [blame] | 184 | for (i = 0; i < ARRAY_SIZE(bts->gprs.nsvc); i++) { |
| 185 | bts->gprs.nsvc[i].bts = bts; |
| 186 | bts->gprs.nsvc[i].id = i; |
| 187 | } |
| 188 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 189 | /* create our primary TRX */ |
| 190 | bts->c0 = gsm_bts_trx_alloc(bts); |
| 191 | if (!bts->c0) { |
| 192 | talloc_free(bts); |
| 193 | return NULL; |
| 194 | } |
| 195 | bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4; |
| 196 | |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 197 | llist_add_tail(&bts->list, &net->bts_list); |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 198 | |
| 199 | return bts; |
| 200 | } |
| 201 | |
| 202 | struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code, |
| 203 | int (*mncc_recv)(struct gsm_network *, int, void *)) |
| 204 | { |
| 205 | struct gsm_network *net; |
| 206 | |
Holger Hans Peter Freyther | 5ea7313 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 207 | net = talloc_zero(tall_bsc_ctx, struct gsm_network); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 208 | if (!net) |
| 209 | return NULL; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 210 | |
| 211 | net->country_code = country_code; |
| 212 | net->network_code = network_code; |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 213 | net->num_bts = 0; |
Harald Welte | b84ddfc | 2009-12-01 17:36:54 +0530 | [diff] [blame] | 214 | net->T3101 = GSM_T3101_DEFAULT; |
| 215 | net->T3113 = GSM_T3113_DEFAULT; |
| 216 | /* FIXME: initialize all other timers! */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 217 | |
Harald Welte | f7c28b0 | 2009-12-21 13:30:17 +0100 | [diff] [blame] | 218 | /* default set of handover parameters */ |
| 219 | net->handover.win_rxlev_avg = 10; |
| 220 | net->handover.win_rxqual_avg = 1; |
| 221 | net->handover.win_rxlev_avg_neigh = 10; |
| 222 | net->handover.pwr_interval = 6; |
| 223 | net->handover.pwr_hysteresis = 3; |
| 224 | net->handover.max_distance = 9999; |
| 225 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 226 | INIT_LLIST_HEAD(&net->trans_list); |
| 227 | INIT_LLIST_HEAD(&net->upqueue); |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 228 | INIT_LLIST_HEAD(&net->bts_list); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 229 | |
Harald Welte | ffa55a4 | 2009-12-22 19:07:32 +0100 | [diff] [blame] | 230 | net->stats.chreq.total = counter_alloc("net.chreq.total"); |
| 231 | net->stats.chreq.no_channel = counter_alloc("net.chreq.no_channel"); |
| 232 | net->stats.handover.attempted = counter_alloc("net.handover.attempted"); |
| 233 | net->stats.handover.no_channel = counter_alloc("net.handover.no_channel"); |
| 234 | net->stats.handover.timeout = counter_alloc("net.handover.timeout"); |
| 235 | net->stats.handover.completed = counter_alloc("net.handover.completed"); |
| 236 | net->stats.handover.failed = counter_alloc("net.handover.failed"); |
| 237 | net->stats.loc_upd_type.attach = counter_alloc("net.loc_upd_type.attach"); |
| 238 | net->stats.loc_upd_type.normal = counter_alloc("net.loc_upd_type.normal"); |
| 239 | net->stats.loc_upd_type.periodic = counter_alloc("net.loc_upd_type.periodic"); |
| 240 | net->stats.loc_upd_type.detach = counter_alloc("net.imsi_detach.count"); |
| 241 | net->stats.loc_upd_resp.reject = counter_alloc("net.loc_upd_resp.reject"); |
| 242 | net->stats.loc_upd_resp.accept = counter_alloc("net.loc_upd_resp.accept"); |
| 243 | net->stats.paging.attempted = counter_alloc("net.paging.attempted"); |
| 244 | net->stats.paging.detached = counter_alloc("net.paging.detached"); |
| 245 | net->stats.paging.completed = counter_alloc("net.paging.completed"); |
| 246 | net->stats.paging.expired = counter_alloc("net.paging.expired"); |
| 247 | net->stats.sms.submitted = counter_alloc("net.sms.submitted"); |
| 248 | net->stats.sms.no_receiver = counter_alloc("net.sms.no_receiver"); |
| 249 | net->stats.sms.delivered = counter_alloc("net.sms.delivered"); |
| 250 | net->stats.sms.rp_err_mem = counter_alloc("net.sms.rp_err_mem"); |
| 251 | net->stats.sms.rp_err_other = counter_alloc("net.sms.rp_err_other"); |
| 252 | net->stats.call.dialled = counter_alloc("net.call.dialled"); |
| 253 | net->stats.call.alerted = counter_alloc("net.call.alerted"); |
| 254 | net->stats.call.connected = counter_alloc("net.call.connected"); |
| 255 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 256 | net->mncc_recv = mncc_recv; |
| 257 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 258 | return net; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 259 | } |
Harald Welte | 23a6863 | 2009-02-19 17:06:42 +0000 | [diff] [blame] | 260 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 261 | struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num) |
| 262 | { |
| 263 | struct gsm_bts *bts; |
| 264 | |
| 265 | if (num >= net->num_bts) |
| 266 | return NULL; |
| 267 | |
| 268 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 269 | if (bts->nr == num) |
| 270 | return bts; |
| 271 | } |
| 272 | |
| 273 | return NULL; |
| 274 | } |
| 275 | |
Harald Welte | 84874c9 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 276 | /* Get reference to a neighbor cell on a given BCCH ARFCN */ |
Harald Welte | 0b12103 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 277 | struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts, |
| 278 | u_int16_t arfcn, u_int8_t bsic) |
Harald Welte | 84874c9 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 279 | { |
| 280 | struct gsm_bts *neigh; |
| 281 | /* FIXME: use some better heuristics here to determine which cell |
| 282 | * using this ARFCN really is closest to the target cell. For |
| 283 | * now we simply assume that each ARFCN will only be used by one |
| 284 | * cell */ |
| 285 | |
| 286 | llist_for_each_entry(neigh, &bts->network->bts_list, list) { |
Harald Welte | 0b12103 | 2009-12-15 00:21:31 +0100 | [diff] [blame] | 287 | if (neigh->c0->arfcn == arfcn && |
| 288 | neigh->bsic == bsic) |
Harald Welte | 84874c9 | 2009-12-14 22:33:02 +0100 | [diff] [blame] | 289 | return neigh; |
| 290 | } |
| 291 | |
| 292 | return NULL; |
| 293 | } |
| 294 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 295 | struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num) |
| 296 | { |
| 297 | struct gsm_bts_trx *trx; |
| 298 | |
| 299 | if (num >= bts->num_trx) |
| 300 | return NULL; |
| 301 | |
| 302 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 303 | if (trx->nr == num) |
| 304 | return trx; |
| 305 | } |
| 306 | |
| 307 | return NULL; |
| 308 | } |
| 309 | |
Harald Welte | 23a6863 | 2009-02-19 17:06:42 +0000 | [diff] [blame] | 310 | static char ts2str[255]; |
| 311 | |
| 312 | char *gsm_ts_name(struct gsm_bts_trx_ts *ts) |
| 313 | { |
| 314 | snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d)", |
Mike Haben | 2449b37 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 315 | ts->trx->bts->nr, ts->trx->nr, ts->nr); |
Harald Welte | 23a6863 | 2009-02-19 17:06:42 +0000 | [diff] [blame] | 316 | |
| 317 | return ts2str; |
| 318 | } |
Harald Welte | 32201c1 | 2009-03-10 12:15:10 +0000 | [diff] [blame] | 319 | |
| 320 | static const char *bts_types[] = { |
| 321 | [GSM_BTS_TYPE_UNKNOWN] = "unknown", |
| 322 | [GSM_BTS_TYPE_BS11] = "bs11", |
Mike Haben | e2d8227 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 323 | [GSM_BTS_TYPE_NANOBTS] = "nanobts", |
Harald Welte | 32201c1 | 2009-03-10 12:15:10 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
Harald Welte | 1d014a5 | 2009-08-08 15:38:29 +0200 | [diff] [blame] | 326 | enum gsm_bts_type parse_btstype(const char *arg) |
Harald Welte | 32201c1 | 2009-03-10 12:15:10 +0000 | [diff] [blame] | 327 | { |
| 328 | int i; |
| 329 | for (i = 0; i < ARRAY_SIZE(bts_types); i++) { |
| 330 | if (!strcmp(arg, bts_types[i])) |
| 331 | return i; |
| 332 | } |
| 333 | return GSM_BTS_TYPE_BS11; /* Default: BS11 */ |
| 334 | } |
| 335 | |
Holger Hans Peter Freyther | 2dceae6 | 2009-06-12 17:39:38 +0200 | [diff] [blame] | 336 | const char *btstype2str(enum gsm_bts_type type) |
Harald Welte | 32201c1 | 2009-03-10 12:15:10 +0000 | [diff] [blame] | 337 | { |
| 338 | if (type > ARRAY_SIZE(bts_types)) |
| 339 | return "undefined"; |
| 340 | return bts_types[type]; |
| 341 | } |
Harald Welte | be99149 | 2009-05-23 13:56:40 +0000 | [diff] [blame] | 342 | |
| 343 | /* Search for a BTS in the given Location Area; optionally start searching |
| 344 | * with start_bts (for continuing to search after the first result) */ |
| 345 | struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac, |
| 346 | struct gsm_bts *start_bts) |
| 347 | { |
| 348 | int i; |
| 349 | struct gsm_bts *bts; |
| 350 | int skip = 0; |
| 351 | |
| 352 | if (start_bts) |
| 353 | skip = 1; |
| 354 | |
| 355 | for (i = 0; i < net->num_bts; i++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 356 | bts = gsm_bts_num(net, i); |
Harald Welte | be99149 | 2009-05-23 13:56:40 +0000 | [diff] [blame] | 357 | |
| 358 | if (skip) { |
| 359 | if (start_bts == bts) |
| 360 | skip = 0; |
| 361 | continue; |
| 362 | } |
| 363 | |
Holger Hans Peter Freyther | e48b956 | 2009-10-01 04:07:15 +0200 | [diff] [blame] | 364 | if (lac == GSM_LAC_RESERVED_ALL_BTS || bts->location_area_code == lac) |
Harald Welte | be99149 | 2009-05-23 13:56:40 +0000 | [diff] [blame] | 365 | return bts; |
| 366 | } |
| 367 | return NULL; |
| 368 | } |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 369 | |
| 370 | char *gsm_band_name(enum gsm_band band) |
| 371 | { |
| 372 | switch (band) { |
| 373 | case GSM_BAND_400: |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 374 | return "GSM400"; |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 375 | case GSM_BAND_850: |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 376 | return "GSM850"; |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 377 | case GSM_BAND_900: |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 378 | return "GSM900"; |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 379 | case GSM_BAND_1800: |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 380 | return "DCS1800"; |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 381 | case GSM_BAND_1900: |
Harald Welte | 9fb3b8b | 2009-08-06 19:05:58 +0200 | [diff] [blame] | 382 | return "PCS1900"; |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 383 | } |
| 384 | return "invalid"; |
| 385 | } |
| 386 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 387 | enum gsm_band gsm_band_parse(const char* mhz) |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 388 | { |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 389 | while (*mhz && !isdigit(*mhz)) |
| 390 | mhz++; |
| 391 | |
| 392 | if (*mhz == '\0') |
| 393 | return -EINVAL; |
| 394 | |
| 395 | switch (atoi(mhz)) { |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 396 | case 400: |
| 397 | return GSM_BAND_400; |
| 398 | case 850: |
| 399 | return GSM_BAND_850; |
| 400 | case 900: |
| 401 | return GSM_BAND_900; |
| 402 | case 1800: |
| 403 | return GSM_BAND_1800; |
| 404 | case 1900: |
| 405 | return GSM_BAND_1900; |
| 406 | default: |
| 407 | return -EINVAL; |
| 408 | } |
| 409 | } |
| 410 | |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 411 | static const char *gsm_auth_policy_names[] = { |
| 412 | [GSM_AUTH_POLICY_CLOSED] = "closed", |
| 413 | [GSM_AUTH_POLICY_ACCEPT_ALL] = "accept-all", |
| 414 | [GSM_AUTH_POLICY_TOKEN] = "token", |
| 415 | }; |
| 416 | |
| 417 | enum gsm_auth_policy gsm_auth_policy_parse(const char *arg) |
| 418 | { |
| 419 | int i; |
| 420 | for (i = 0; i < ARRAY_SIZE(gsm_auth_policy_names); i++) { |
| 421 | if (!strcmp(arg, gsm_auth_policy_names[i])) |
| 422 | return i; |
| 423 | } |
| 424 | return GSM_AUTH_POLICY_CLOSED; |
| 425 | } |
| 426 | |
| 427 | const char *gsm_auth_policy_name(enum gsm_auth_policy policy) |
| 428 | { |
| 429 | if (policy > ARRAY_SIZE(gsm_auth_policy_names)) |
| 430 | return "undefined"; |
| 431 | return gsm_auth_policy_names[policy]; |
| 432 | } |
| 433 | |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 434 | static const char *rrlp_mode_names[] = { |
| 435 | [RRLP_MODE_NONE] = "none", |
| 436 | [RRLP_MODE_MS_BASED] = "ms-based", |
| 437 | [RRLP_MODE_MS_PREF] = "ms-preferred", |
| 438 | [RRLP_MODE_ASS_PREF] = "ass-preferred", |
| 439 | }; |
| 440 | |
| 441 | enum rrlp_mode rrlp_mode_parse(const char *arg) |
| 442 | { |
| 443 | int i; |
| 444 | for (i = 0; i < ARRAY_SIZE(rrlp_mode_names); i++) { |
| 445 | if (!strcmp(arg, rrlp_mode_names[i])) |
| 446 | return i; |
| 447 | } |
| 448 | return RRLP_MODE_NONE; |
| 449 | } |
| 450 | |
| 451 | const char *rrlp_mode_name(enum rrlp_mode mode) |
| 452 | { |
| 453 | if (mode > ARRAY_SIZE(rrlp_mode_names)) |
| 454 | return "none"; |
| 455 | return rrlp_mode_names[mode]; |
| 456 | } |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 457 | |
| 458 | struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan) |
| 459 | { |
| 460 | struct gsm_meas_rep *meas_rep; |
| 461 | |
| 462 | meas_rep = &lchan->meas_rep[lchan->meas_rep_idx]; |
| 463 | memset(meas_rep, 0, sizeof(*meas_rep)); |
| 464 | meas_rep->lchan = lchan; |
| 465 | lchan->meas_rep_idx = (lchan->meas_rep_idx + 1) |
| 466 | % ARRAY_SIZE(lchan->meas_rep); |
| 467 | |
| 468 | return meas_rep; |
| 469 | } |