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