2010-03-04 09:39:50 +00:00
|
|
|
/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
|
2008-12-25 23:28:35 +00:00
|
|
|
*
|
2008-12-23 20:25:15 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2009-02-24 22:36:40 +00:00
|
|
|
#include <stdio.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
#include <string.h>
|
2009-06-20 16:15:19 +00:00
|
|
|
#include <errno.h>
|
2009-08-08 14:12:58 +00:00
|
|
|
#include <ctype.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2010-03-14 07:37:43 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2010-06-28 10:20:22 +00:00
|
|
|
#include <osmocore/linuxlist.h>
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/talloc.h>
|
2010-03-04 09:39:50 +00:00
|
|
|
#include <osmocore/gsm_utils.h>
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/statistics.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2010-06-28 10:20:22 +00:00
|
|
|
#include <openbsc/gsm_data.h>
|
2010-09-15 14:29:25 +00:00
|
|
|
#include <openbsc/osmo_msc_data.h>
|
2010-06-28 10:20:22 +00:00
|
|
|
#include <openbsc/abis_nm.h>
|
|
|
|
|
2009-06-29 13:19:38 +00:00
|
|
|
void *tall_bsc_ctx;
|
|
|
|
|
2010-01-10 17:01:52 +00:00
|
|
|
static LLIST_HEAD(bts_models);
|
|
|
|
|
2009-02-10 17:33:56 +00:00
|
|
|
void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr,
|
|
|
|
u_int8_t e1_ts, u_int8_t e1_ts_ss)
|
|
|
|
{
|
|
|
|
ts->e1_link.e1_nr = e1_nr;
|
|
|
|
ts->e1_link.e1_ts = e1_ts;
|
|
|
|
ts->e1_link.e1_ts_ss = e1_ts_ss;
|
|
|
|
}
|
|
|
|
|
2010-03-25 03:45:30 +00:00
|
|
|
static const struct value_string pchan_names[] = {
|
|
|
|
{ GSM_PCHAN_NONE, "NONE" },
|
|
|
|
{ GSM_PCHAN_CCCH, "CCCH" },
|
|
|
|
{ GSM_PCHAN_CCCH_SDCCH4,"CCCH+SDCCH4" },
|
|
|
|
{ GSM_PCHAN_TCH_F, "TCH/F" },
|
|
|
|
{ GSM_PCHAN_TCH_H, "TCH/H" },
|
|
|
|
{ GSM_PCHAN_SDCCH8_SACCH8C, "SDCCH8" },
|
|
|
|
{ GSM_PCHAN_PDCH, "PDCH" },
|
|
|
|
{ GSM_PCHAN_TCH_F_PDCH, "TCH/F_PDCH" },
|
|
|
|
{ GSM_PCHAN_UNKNOWN, "UNKNOWN" },
|
|
|
|
{ 0, NULL }
|
2009-01-04 16:10:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *gsm_pchan_name(enum gsm_phys_chan_config c)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_value_string(pchan_names, c);
|
2009-01-04 16:10:38 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 22:24:39 +00:00
|
|
|
enum gsm_phys_chan_config gsm_pchan_parse(const char *name)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_string_value(pchan_names, name);
|
2009-08-06 22:24:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 03:45:30 +00:00
|
|
|
static const struct value_string lchant_names[] = {
|
|
|
|
{ GSM_LCHAN_NONE, "NONE" },
|
|
|
|
{ GSM_LCHAN_SDCCH, "SDCCH" },
|
|
|
|
{ GSM_LCHAN_TCH_F, "TCH/F" },
|
|
|
|
{ GSM_LCHAN_TCH_H, "TCH/H" },
|
|
|
|
{ GSM_LCHAN_UNKNOWN, "UNKNOWN" },
|
|
|
|
{ 0, NULL }
|
2009-01-04 16:10:38 +00:00
|
|
|
};
|
|
|
|
|
2009-12-27 17:05:25 +00:00
|
|
|
const char *gsm_lchant_name(enum gsm_chan_t c)
|
2009-01-04 16:10:38 +00:00
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_value_string(lchant_names, c);
|
2009-01-04 16:10:38 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 09:52:38 +00:00
|
|
|
static const struct value_string lchan_s_names[] = {
|
|
|
|
{ LCHAN_S_NONE, "NONE" },
|
|
|
|
{ LCHAN_S_ACT_REQ, "ACTIVATION REQUESTED" },
|
|
|
|
{ LCHAN_S_ACTIVE, "ACTIVE" },
|
|
|
|
{ LCHAN_S_INACTIVE, "INACTIVE" },
|
|
|
|
{ LCHAN_S_REL_REQ, "RELEASE REQUESTED" },
|
2010-05-31 13:38:24 +00:00
|
|
|
{ LCHAN_S_REL_ERR, "RELEASE DUE ERROR" },
|
2010-03-25 03:45:30 +00:00
|
|
|
{ 0, NULL }
|
2009-12-29 09:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *gsm_lchans_name(enum gsm_lchan_state s)
|
|
|
|
{
|
|
|
|
return get_value_string(lchan_s_names, s);
|
|
|
|
}
|
|
|
|
|
2010-03-25 03:45:30 +00:00
|
|
|
static const struct value_string chreq_names[] = {
|
|
|
|
{ GSM_CHREQ_REASON_EMERG, "EMERGENCY" },
|
|
|
|
{ GSM_CHREQ_REASON_PAG, "PAGING" },
|
|
|
|
{ GSM_CHREQ_REASON_CALL, "CALL" },
|
|
|
|
{ GSM_CHREQ_REASON_LOCATION_UPD,"LOCATION_UPDATE" },
|
|
|
|
{ GSM_CHREQ_REASON_OTHER, "OTHER" },
|
|
|
|
{ 0, NULL }
|
2009-01-04 16:10:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *gsm_chreq_name(enum gsm_chreq_reason_t c)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_value_string(chreq_names, c);
|
2009-01-04 16:10:38 +00:00
|
|
|
}
|
|
|
|
|
2010-01-10 17:01:52 +00:00
|
|
|
static struct gsm_bts_model *bts_model_find(enum gsm_bts_type type)
|
|
|
|
{
|
|
|
|
struct gsm_bts_model *model;
|
|
|
|
|
|
|
|
llist_for_each_entry(model, &bts_models, list) {
|
|
|
|
if (model->type == type)
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gsm_bts_model_register(struct gsm_bts_model *model)
|
|
|
|
{
|
|
|
|
if (bts_model_find(model->type))
|
|
|
|
return -EEXIST;
|
|
|
|
|
|
|
|
tlv_def_patch(&model->nm_att_tlvdef, &nm_att_tlvdef);
|
|
|
|
llist_add_tail(&model->list, &bts_models);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
|
2008-12-23 20:25:15 +00:00
|
|
|
{
|
2009-10-29 01:29:45 +00:00
|
|
|
struct gsm_bts_trx *trx = talloc_zero(bts, struct gsm_bts_trx);
|
2009-06-21 14:17:15 +00:00
|
|
|
int k;
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
if (!trx)
|
2008-12-23 20:25:15 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
trx->bts = bts;
|
|
|
|
trx->nr = bts->num_trx++;
|
2009-12-31 02:05:52 +00:00
|
|
|
trx->nm_state.administrative = NM_STATE_UNLOCKED;
|
2009-06-21 14:17:15 +00:00
|
|
|
|
|
|
|
for (k = 0; k < TRX_NR_TS; k++) {
|
|
|
|
struct gsm_bts_trx_ts *ts = &trx->ts[k];
|
|
|
|
int l;
|
|
|
|
|
|
|
|
ts->trx = trx;
|
|
|
|
ts->nr = k;
|
|
|
|
ts->pchan = GSM_PCHAN_NONE;
|
|
|
|
|
2010-06-14 20:26:10 +00:00
|
|
|
ts->hopping.arfcns.data_len = sizeof(ts->hopping.arfcns_data);
|
|
|
|
ts->hopping.arfcns.data = ts->hopping.arfcns_data;
|
2010-06-15 06:52:12 +00:00
|
|
|
ts->hopping.ma.data_len = sizeof(ts->hopping.ma_data);
|
|
|
|
ts->hopping.ma.data = ts->hopping.ma_data;
|
2010-06-14 20:26:10 +00:00
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
for (l = 0; l < TS_MAX_LCHAN; l++) {
|
|
|
|
struct gsm_lchan *lchan;
|
|
|
|
lchan = &ts->lchan[l];
|
|
|
|
|
|
|
|
lchan->ts = ts;
|
|
|
|
lchan->nr = l;
|
|
|
|
lchan->type = GSM_LCHAN_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-27 19:56:38 +00:00
|
|
|
if (trx->nr != 0)
|
|
|
|
trx->nominal_power = bts->c0->nominal_power;
|
|
|
|
|
2009-08-06 17:05:58 +00:00
|
|
|
llist_add_tail(&trx->list, &bts->trx_list);
|
2009-06-21 14:17:15 +00:00
|
|
|
|
|
|
|
return trx;
|
|
|
|
}
|
|
|
|
|
2010-05-11 21:50:21 +00:00
|
|
|
static const uint8_t bts_nse_timer_default[] = { 3, 3, 3, 3, 30, 3, 10 };
|
|
|
|
static const uint8_t bts_cell_timer_default[] =
|
|
|
|
{ 3, 3, 3, 3, 3, 10, 3, 10, 3, 10, 3 };
|
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
|
|
|
|
u_int8_t tsc, u_int8_t bsic)
|
|
|
|
{
|
2009-10-29 01:29:45 +00:00
|
|
|
struct gsm_bts *bts = talloc_zero(net, struct gsm_bts);
|
2010-01-10 17:01:52 +00:00
|
|
|
struct gsm_bts_model *model = bts_model_find(type);
|
2009-10-24 08:19:14 +00:00
|
|
|
int i;
|
2009-06-21 14:17:15 +00:00
|
|
|
|
|
|
|
if (!bts)
|
|
|
|
return NULL;
|
|
|
|
|
2010-01-12 09:44:26 +00:00
|
|
|
if (!model && type != GSM_BTS_TYPE_UNKNOWN) {
|
2010-01-10 17:01:52 +00:00
|
|
|
talloc_free(bts);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
bts->network = net;
|
|
|
|
bts->nr = net->num_bts++;
|
|
|
|
bts->type = type;
|
2010-01-10 17:01:52 +00:00
|
|
|
bts->model = model;
|
2009-06-21 14:17:15 +00:00
|
|
|
bts->tsc = tsc;
|
|
|
|
bts->bsic = bsic;
|
|
|
|
bts->num_trx = 0;
|
|
|
|
INIT_LLIST_HEAD(&bts->trx_list);
|
2009-08-13 08:14:26 +00:00
|
|
|
bts->ms_max_power = 15; /* dBm */
|
2009-12-12 17:17:25 +00:00
|
|
|
bts->si_common.cell_sel_par.cell_resel_hyst = 2; /* 4 dB */
|
|
|
|
bts->si_common.cell_sel_par.rxlev_acc_min = 0;
|
2009-12-14 21:07:14 +00:00
|
|
|
bts->si_common.neigh_list.data = bts->si_common.data.neigh_list;
|
|
|
|
bts->si_common.neigh_list.data_len =
|
|
|
|
sizeof(bts->si_common.data.neigh_list);
|
|
|
|
bts->si_common.cell_alloc.data = bts->si_common.data.cell_alloc;
|
|
|
|
bts->si_common.cell_alloc.data_len =
|
|
|
|
sizeof(bts->si_common.data.cell_alloc);
|
2009-12-22 12:43:26 +00:00
|
|
|
bts->si_common.rach_control.re = 1; /* no re-establishment */
|
|
|
|
bts->si_common.rach_control.tx_integer = 9; /* 12 slots spread - 217/115 slots delay */
|
|
|
|
bts->si_common.rach_control.max_trans = 3; /* 7 retransmissions */
|
|
|
|
bts->si_common.rach_control.t2 = 4; /* no emergency calls */
|
2009-06-21 14:17:15 +00:00
|
|
|
|
2009-10-24 08:19:14 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(bts->gprs.nsvc); i++) {
|
|
|
|
bts->gprs.nsvc[i].bts = bts;
|
|
|
|
bts->gprs.nsvc[i].id = i;
|
|
|
|
}
|
2010-05-11 21:50:21 +00:00
|
|
|
memcpy(&bts->gprs.nse.timer, bts_nse_timer_default,
|
|
|
|
sizeof(bts->gprs.nse.timer));
|
|
|
|
memcpy(&bts->gprs.cell.timer, bts_cell_timer_default,
|
|
|
|
sizeof(bts->gprs.cell.timer));
|
2009-10-24 08:19:14 +00:00
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
/* create our primary TRX */
|
|
|
|
bts->c0 = gsm_bts_trx_alloc(bts);
|
|
|
|
if (!bts->c0) {
|
|
|
|
talloc_free(bts);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
|
|
|
|
|
2010-04-25 15:08:39 +00:00
|
|
|
bts->rach_b_thresh = -1;
|
|
|
|
bts->rach_ldavg_slots = -1;
|
2010-09-06 02:11:25 +00:00
|
|
|
bts->paging.free_chans_need = -1;
|
2009-08-06 17:05:58 +00:00
|
|
|
llist_add_tail(&bts->list, &net->bts_list);
|
2009-06-21 14:17:15 +00:00
|
|
|
|
|
|
|
return bts;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_code,
|
|
|
|
int (*mncc_recv)(struct gsm_network *, int, void *))
|
|
|
|
{
|
|
|
|
struct gsm_network *net;
|
|
|
|
|
2009-10-29 01:29:45 +00:00
|
|
|
net = talloc_zero(tall_bsc_ctx, struct gsm_network);
|
2008-12-23 20:25:15 +00:00
|
|
|
if (!net)
|
|
|
|
return NULL;
|
|
|
|
|
2010-09-15 14:29:25 +00:00
|
|
|
net->msc_data = talloc_zero(net, struct osmo_msc_data);
|
|
|
|
if (!net->msc_data) {
|
|
|
|
talloc_free(net);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-23 20:25:15 +00:00
|
|
|
net->country_code = country_code;
|
|
|
|
net->network_code = network_code;
|
2009-06-21 14:17:15 +00:00
|
|
|
net->num_bts = 0;
|
2010-01-07 15:08:42 +00:00
|
|
|
net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED;
|
2009-12-01 12:06:54 +00:00
|
|
|
net->T3101 = GSM_T3101_DEFAULT;
|
|
|
|
net->T3113 = GSM_T3113_DEFAULT;
|
|
|
|
/* FIXME: initialize all other timers! */
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-12-21 12:30:17 +00:00
|
|
|
/* default set of handover parameters */
|
|
|
|
net->handover.win_rxlev_avg = 10;
|
|
|
|
net->handover.win_rxqual_avg = 1;
|
|
|
|
net->handover.win_rxlev_avg_neigh = 10;
|
|
|
|
net->handover.pwr_interval = 6;
|
|
|
|
net->handover.pwr_hysteresis = 3;
|
|
|
|
net->handover.max_distance = 9999;
|
|
|
|
|
2009-06-10 15:11:52 +00:00
|
|
|
INIT_LLIST_HEAD(&net->trans_list);
|
|
|
|
INIT_LLIST_HEAD(&net->upqueue);
|
2009-06-21 14:17:15 +00:00
|
|
|
INIT_LLIST_HEAD(&net->bts_list);
|
2009-06-10 15:11:52 +00:00
|
|
|
|
2009-12-22 18:07:32 +00:00
|
|
|
net->stats.chreq.total = counter_alloc("net.chreq.total");
|
|
|
|
net->stats.chreq.no_channel = counter_alloc("net.chreq.no_channel");
|
|
|
|
net->stats.handover.attempted = counter_alloc("net.handover.attempted");
|
|
|
|
net->stats.handover.no_channel = counter_alloc("net.handover.no_channel");
|
|
|
|
net->stats.handover.timeout = counter_alloc("net.handover.timeout");
|
|
|
|
net->stats.handover.completed = counter_alloc("net.handover.completed");
|
|
|
|
net->stats.handover.failed = counter_alloc("net.handover.failed");
|
|
|
|
net->stats.loc_upd_type.attach = counter_alloc("net.loc_upd_type.attach");
|
|
|
|
net->stats.loc_upd_type.normal = counter_alloc("net.loc_upd_type.normal");
|
|
|
|
net->stats.loc_upd_type.periodic = counter_alloc("net.loc_upd_type.periodic");
|
|
|
|
net->stats.loc_upd_type.detach = counter_alloc("net.imsi_detach.count");
|
|
|
|
net->stats.loc_upd_resp.reject = counter_alloc("net.loc_upd_resp.reject");
|
|
|
|
net->stats.loc_upd_resp.accept = counter_alloc("net.loc_upd_resp.accept");
|
|
|
|
net->stats.paging.attempted = counter_alloc("net.paging.attempted");
|
|
|
|
net->stats.paging.detached = counter_alloc("net.paging.detached");
|
|
|
|
net->stats.paging.completed = counter_alloc("net.paging.completed");
|
|
|
|
net->stats.paging.expired = counter_alloc("net.paging.expired");
|
|
|
|
net->stats.sms.submitted = counter_alloc("net.sms.submitted");
|
|
|
|
net->stats.sms.no_receiver = counter_alloc("net.sms.no_receiver");
|
|
|
|
net->stats.sms.delivered = counter_alloc("net.sms.delivered");
|
|
|
|
net->stats.sms.rp_err_mem = counter_alloc("net.sms.rp_err_mem");
|
|
|
|
net->stats.sms.rp_err_other = counter_alloc("net.sms.rp_err_other");
|
|
|
|
net->stats.call.dialled = counter_alloc("net.call.dialled");
|
|
|
|
net->stats.call.alerted = counter_alloc("net.call.alerted");
|
|
|
|
net->stats.call.connected = counter_alloc("net.call.connected");
|
2010-04-17 04:48:29 +00:00
|
|
|
net->stats.chan.rf_fail = counter_alloc("net.chan.rf_fail");
|
|
|
|
net->stats.chan.rll_err = counter_alloc("net.chan.rll_err");
|
2010-04-12 08:45:52 +00:00
|
|
|
net->stats.bts.oml_fail = counter_alloc("net.bts.oml_fail");
|
|
|
|
net->stats.bts.rsl_fail = counter_alloc("net.bts.rsl_fail");
|
2009-12-22 18:07:32 +00:00
|
|
|
|
2009-06-10 15:11:52 +00:00
|
|
|
net->mncc_recv = mncc_recv;
|
|
|
|
|
2010-09-15 18:00:01 +00:00
|
|
|
net->msc_data->msc_ip = talloc_strdup(net, "127.0.0.1");
|
|
|
|
net->msc_data->msc_port = 5000;
|
|
|
|
net->msc_data->ping_timeout = 20;
|
|
|
|
net->msc_data->pong_timeout = 5;
|
2010-11-03 12:12:18 +00:00
|
|
|
net->msc_data->core_ncc = -1;
|
2010-11-03 12:21:02 +00:00
|
|
|
net->msc_data->rtp_payload = 126;
|
2010-11-03 12:32:48 +00:00
|
|
|
net->msc_data->rtp_base = 4000;
|
2010-09-15 18:00:01 +00:00
|
|
|
|
2010-09-06 01:36:02 +00:00
|
|
|
gsm_net_update_ctype(net);
|
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
return net;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num)
|
|
|
|
{
|
|
|
|
struct gsm_bts *bts;
|
|
|
|
|
|
|
|
if (num >= net->num_bts)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
llist_for_each_entry(bts, &net->bts_list, list) {
|
|
|
|
if (bts->nr == num)
|
|
|
|
return bts;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-14 21:33:02 +00:00
|
|
|
/* Get reference to a neighbor cell on a given BCCH ARFCN */
|
2009-12-14 23:21:31 +00:00
|
|
|
struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
|
|
|
|
u_int16_t arfcn, u_int8_t bsic)
|
2009-12-14 21:33:02 +00:00
|
|
|
{
|
|
|
|
struct gsm_bts *neigh;
|
|
|
|
/* FIXME: use some better heuristics here to determine which cell
|
|
|
|
* using this ARFCN really is closest to the target cell. For
|
|
|
|
* now we simply assume that each ARFCN will only be used by one
|
|
|
|
* cell */
|
|
|
|
|
|
|
|
llist_for_each_entry(neigh, &bts->network->bts_list, list) {
|
2009-12-14 23:21:31 +00:00
|
|
|
if (neigh->c0->arfcn == arfcn &&
|
|
|
|
neigh->bsic == bsic)
|
2009-12-14 21:33:02 +00:00
|
|
|
return neigh;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
struct gsm_bts_trx *gsm_bts_trx_num(struct gsm_bts *bts, int num)
|
|
|
|
{
|
|
|
|
struct gsm_bts_trx *trx;
|
|
|
|
|
|
|
|
if (num >= bts->num_trx)
|
|
|
|
return NULL;
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-06-21 14:17:15 +00:00
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list) {
|
|
|
|
if (trx->nr == num)
|
|
|
|
return trx;
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
2009-06-21 14:17:15 +00:00
|
|
|
|
|
|
|
return NULL;
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
2009-02-19 17:06:42 +00:00
|
|
|
|
|
|
|
static char ts2str[255];
|
|
|
|
|
2009-12-28 22:14:22 +00:00
|
|
|
char *gsm_trx_name(struct gsm_bts_trx *trx)
|
|
|
|
{
|
|
|
|
snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d)",
|
|
|
|
trx->bts->nr, trx->nr);
|
|
|
|
|
|
|
|
return ts2str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 17:06:42 +00:00
|
|
|
char *gsm_ts_name(struct gsm_bts_trx_ts *ts)
|
|
|
|
{
|
|
|
|
snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d)",
|
2009-10-26 19:36:34 +00:00
|
|
|
ts->trx->bts->nr, ts->trx->nr, ts->nr);
|
2009-02-19 17:06:42 +00:00
|
|
|
|
|
|
|
return ts2str;
|
|
|
|
}
|
2009-03-10 12:15:10 +00:00
|
|
|
|
2009-12-27 17:16:36 +00:00
|
|
|
char *gsm_lchan_name(struct gsm_lchan *lchan)
|
|
|
|
{
|
|
|
|
struct gsm_bts_trx_ts *ts = lchan->ts;
|
|
|
|
|
|
|
|
snprintf(ts2str, sizeof(ts2str), "(bts=%d,trx=%d,ts=%d,ss=%d)",
|
|
|
|
ts->trx->bts->nr, ts->trx->nr, ts->nr, lchan->nr);
|
|
|
|
|
|
|
|
return ts2str;
|
|
|
|
}
|
|
|
|
|
2010-03-25 03:45:30 +00:00
|
|
|
static const struct value_string bts_types[] = {
|
|
|
|
{ GSM_BTS_TYPE_UNKNOWN, "unknown" },
|
|
|
|
{ GSM_BTS_TYPE_BS11, "bs11" },
|
|
|
|
{ GSM_BTS_TYPE_NANOBTS, "nanobts" },
|
|
|
|
{ 0, NULL }
|
2009-03-10 12:15:10 +00:00
|
|
|
};
|
|
|
|
|
2009-08-08 13:38:29 +00:00
|
|
|
enum gsm_bts_type parse_btstype(const char *arg)
|
2009-03-10 12:15:10 +00:00
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_string_value(bts_types, arg);
|
2009-03-10 12:15:10 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 15:39:38 +00:00
|
|
|
const char *btstype2str(enum gsm_bts_type type)
|
2009-03-10 12:15:10 +00:00
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_value_string(bts_types, type);
|
2009-03-10 12:15:10 +00:00
|
|
|
}
|
2009-05-23 13:56:40 +00:00
|
|
|
|
2010-01-07 19:44:32 +00:00
|
|
|
struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr)
|
|
|
|
{
|
|
|
|
struct gsm_bts_trx *trx;
|
|
|
|
|
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list) {
|
|
|
|
if (trx->nr == nr)
|
|
|
|
return trx;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-23 13:56:40 +00:00
|
|
|
/* Search for a BTS in the given Location Area; optionally start searching
|
|
|
|
* with start_bts (for continuing to search after the first result) */
|
|
|
|
struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
|
|
|
|
struct gsm_bts *start_bts)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct gsm_bts *bts;
|
|
|
|
int skip = 0;
|
|
|
|
|
|
|
|
if (start_bts)
|
|
|
|
skip = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < net->num_bts; i++) {
|
2009-06-21 14:17:15 +00:00
|
|
|
bts = gsm_bts_num(net, i);
|
2009-05-23 13:56:40 +00:00
|
|
|
|
|
|
|
if (skip) {
|
|
|
|
if (start_bts == bts)
|
|
|
|
skip = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-10-01 02:07:15 +00:00
|
|
|
if (lac == GSM_LAC_RESERVED_ALL_BTS || bts->location_area_code == lac)
|
2009-05-23 13:56:40 +00:00
|
|
|
return bts;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-06-20 16:15:19 +00:00
|
|
|
|
2010-03-25 03:45:30 +00:00
|
|
|
static const struct value_string auth_policy_names[] = {
|
|
|
|
{ GSM_AUTH_POLICY_CLOSED, "closed" },
|
|
|
|
{ GSM_AUTH_POLICY_ACCEPT_ALL, "accept-all" },
|
|
|
|
{ GSM_AUTH_POLICY_TOKEN, "token" },
|
|
|
|
{ 0, NULL }
|
2009-08-12 12:42:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum gsm_auth_policy gsm_auth_policy_parse(const char *arg)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_string_value(auth_policy_names, arg);
|
2009-08-12 12:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *gsm_auth_policy_name(enum gsm_auth_policy policy)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_value_string(auth_policy_names, policy);
|
2009-08-12 12:42:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 07:37:43 +00:00
|
|
|
void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
raid->mcc = bts->network->country_code;
|
|
|
|
raid->mnc = bts->network->network_code;
|
|
|
|
raid->lac = bts->location_area_code;
|
|
|
|
raid->rac = bts->gprs.rac;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gsm48_ra_id_by_bts(u_int8_t *buf, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct gprs_ra_id raid;
|
|
|
|
|
|
|
|
gprs_ra_id_by_bts(&raid, bts);
|
|
|
|
|
|
|
|
return gsm48_construct_ra(buf, &raid);
|
|
|
|
}
|
|
|
|
|
2010-03-25 03:45:30 +00:00
|
|
|
static const struct value_string rrlp_mode_names[] = {
|
|
|
|
{ RRLP_MODE_NONE, "none" },
|
|
|
|
{ RRLP_MODE_MS_BASED, "ms-based" },
|
|
|
|
{ RRLP_MODE_MS_PREF, "ms-preferred" },
|
|
|
|
{ RRLP_MODE_ASS_PREF, "ass-preferred" },
|
|
|
|
{ 0, NULL }
|
2009-12-13 09:53:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum rrlp_mode rrlp_mode_parse(const char *arg)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_string_value(rrlp_mode_names, arg);
|
2009-12-13 09:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *rrlp_mode_name(enum rrlp_mode mode)
|
|
|
|
{
|
2010-03-25 03:45:30 +00:00
|
|
|
return get_value_string(rrlp_mode_names, mode);
|
2009-12-13 09:53:12 +00:00
|
|
|
}
|
2009-12-15 20:36:05 +00:00
|
|
|
|
2010-04-18 13:51:20 +00:00
|
|
|
static const struct value_string bts_gprs_mode_names[] = {
|
|
|
|
{ BTS_GPRS_NONE, "none" },
|
|
|
|
{ BTS_GPRS_GPRS, "gprs" },
|
|
|
|
{ BTS_GPRS_EGPRS, "egprs" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
enum bts_gprs_mode bts_gprs_mode_parse(const char *arg)
|
|
|
|
{
|
|
|
|
return get_string_value(bts_gprs_mode_names, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *bts_gprs_mode_name(enum bts_gprs_mode mode)
|
|
|
|
{
|
|
|
|
return get_value_string(bts_gprs_mode_names, mode);
|
|
|
|
}
|
|
|
|
|
2009-12-15 20:36:05 +00:00
|
|
|
struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan)
|
|
|
|
{
|
|
|
|
struct gsm_meas_rep *meas_rep;
|
|
|
|
|
|
|
|
meas_rep = &lchan->meas_rep[lchan->meas_rep_idx];
|
|
|
|
memset(meas_rep, 0, sizeof(*meas_rep));
|
|
|
|
meas_rep->lchan = lchan;
|
|
|
|
lchan->meas_rep_idx = (lchan->meas_rep_idx + 1)
|
|
|
|
% ARRAY_SIZE(lchan->meas_rep);
|
|
|
|
|
|
|
|
return meas_rep;
|
|
|
|
}
|
2009-12-27 19:56:38 +00:00
|
|
|
|
2010-06-14 20:44:42 +00:00
|
|
|
int gsm_btsmodel_set_feature(struct gsm_bts_model *bts, enum gsm_bts_features feat)
|
|
|
|
{
|
|
|
|
return bitvec_set_bit_pos(&bts->features, feat, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gsm_bts_has_feature(struct gsm_bts *bts, enum gsm_bts_features feat)
|
|
|
|
{
|
|
|
|
return bitvec_get_bit_pos(&bts->model->features, feat);
|
|
|
|
}
|
|
|
|
|
2010-01-10 17:01:52 +00:00
|
|
|
int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type)
|
2009-12-27 19:56:38 +00:00
|
|
|
{
|
2010-01-10 17:01:52 +00:00
|
|
|
struct gsm_bts_model *model;
|
|
|
|
|
|
|
|
model = bts_model_find(type);
|
|
|
|
if (!model)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-12-27 19:56:38 +00:00
|
|
|
bts->type = type;
|
2010-01-10 17:01:52 +00:00
|
|
|
bts->model = model;
|
2009-12-27 19:56:38 +00:00
|
|
|
|
|
|
|
switch (bts->type) {
|
|
|
|
case GSM_BTS_TYPE_NANOBTS:
|
|
|
|
/* Set the default OML Stream ID to 0xff */
|
|
|
|
bts->oml_tei = 0xff;
|
|
|
|
bts->c0->nominal_power = 23;
|
|
|
|
break;
|
|
|
|
case GSM_BTS_TYPE_BS11:
|
|
|
|
break;
|
2010-05-13 18:53:22 +00:00
|
|
|
case GSM_BTS_TYPE_UNKNOWN:
|
|
|
|
break;
|
2009-12-27 19:56:38 +00:00
|
|
|
}
|
2010-01-10 17:01:52 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-12-27 19:56:38 +00:00
|
|
|
}
|