2011-06-27 09:25:35 +00:00
|
|
|
/* BTS support code common to all supported BTS models */
|
|
|
|
|
2011-03-04 13:05:20 +00:00
|
|
|
/* (C) 2011 by Andreas Eversberg <jolly@eversberg.eu>
|
2011-06-27 09:25:35 +00:00
|
|
|
* (C) 2011 by Harald Welte <laforge@gnumonks.org>
|
2011-03-04 13:05:20 +00:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-06-27 09:25:35 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2011-03-04 13:05:20 +00:00
|
|
|
* (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.
|
|
|
|
*
|
2011-06-27 09:25:35 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-03-04 13:05:20 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-03-04 13:18:23 +00:00
|
|
|
#include <errno.h>
|
2011-07-01 17:03:30 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
2011-03-04 13:18:23 +00:00
|
|
|
|
2011-03-04 13:05:20 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2011-05-22 18:26:58 +00:00
|
|
|
#include <osmocom/core/select.h>
|
|
|
|
#include <osmocom/core/timer.h>
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/talloc.h>
|
|
|
|
#include <osmocom/gsm/protocol/gsm_12_21.h>
|
2011-06-27 09:25:35 +00:00
|
|
|
#include <osmocom/gsm/lapdm.h>
|
2011-09-03 13:41:12 +00:00
|
|
|
#include <osmocom/trau/osmo_ortp.h>
|
2011-06-27 09:25:35 +00:00
|
|
|
|
2011-03-04 13:18:23 +00:00
|
|
|
#include <osmo-bts/logging.h>
|
|
|
|
#include <osmo-bts/abis.h>
|
|
|
|
#include <osmo-bts/bts.h>
|
2011-07-01 16:22:01 +00:00
|
|
|
#include <osmo-bts/bts_model.h>
|
2011-03-04 13:18:23 +00:00
|
|
|
#include <osmo-bts/rsl.h>
|
|
|
|
#include <osmo-bts/oml.h>
|
2011-03-04 13:05:20 +00:00
|
|
|
|
|
|
|
|
2011-09-04 20:42:03 +00:00
|
|
|
struct gsm_network bts_gsmnet = {
|
|
|
|
.bts_list = { &bts_gsmnet.bts_list, &bts_gsmnet.bts_list },
|
|
|
|
.num_bts = 0,
|
|
|
|
};
|
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
void *tall_bts_ctx;
|
2012-07-08 18:50:02 +00:00
|
|
|
extern int gprs_enabled;
|
2011-06-27 09:25:35 +00:00
|
|
|
|
|
|
|
int bts_init(struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct gsm_bts_role_bts *btsb;
|
2011-09-03 13:41:12 +00:00
|
|
|
struct gsm_bts_trx *trx;
|
2011-09-04 20:42:03 +00:00
|
|
|
int rc;
|
|
|
|
|
2012-07-08 18:20:51 +00:00
|
|
|
/* add to list of BTSs */
|
|
|
|
llist_add_tail(&bts->list, &bts_gsmnet.bts_list);
|
|
|
|
|
2011-09-04 20:42:03 +00:00
|
|
|
bts->band = GSM_BAND_1800;
|
2011-06-27 09:25:35 +00:00
|
|
|
|
|
|
|
bts->role = btsb = talloc_zero(bts, struct gsm_bts_role_bts);
|
|
|
|
|
|
|
|
INIT_LLIST_HEAD(&btsb->agch_queue);
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
/* FIXME: make those parameters configurable */
|
|
|
|
btsb->paging_state = paging_init(btsb, 200, 0);
|
2012-06-21 14:46:05 +00:00
|
|
|
btsb->load.ccch.load_ind_period = 60*100;
|
2012-06-04 15:27:13 +00:00
|
|
|
load_timer_start(bts);
|
|
|
|
|
2011-09-08 13:18:43 +00:00
|
|
|
btsb->rtp_jitter_buf_ms = 100;
|
2012-06-15 15:22:26 +00:00
|
|
|
btsb->max_ta = 63;
|
2011-09-08 13:18:43 +00:00
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
/* set BTS to dependency */
|
|
|
|
oml_mo_state_chg(&bts->mo, -1, NM_AVSTATE_DEPENDENCY);
|
2012-06-28 06:59:48 +00:00
|
|
|
oml_mo_state_chg(&bts->gprs.nse.mo, -1, NM_AVSTATE_DEPENDENCY);
|
|
|
|
oml_mo_state_chg(&bts->gprs.cell.mo, -1, NM_AVSTATE_DEPENDENCY);
|
|
|
|
oml_mo_state_chg(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_DEPENDENCY);
|
|
|
|
oml_mo_state_chg(&bts->gprs.nsvc[1].mo, -1, NM_AVSTATE_DEPENDENCY);
|
2011-07-01 16:09:34 +00:00
|
|
|
|
2011-09-03 13:41:12 +00:00
|
|
|
/* initialize bts data structure */
|
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
|
|
|
|
struct gsm_bts_trx_ts *ts = &trx->ts[i];
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for (k = 0; k < ARRAY_SIZE(ts->lchan); k++) {
|
|
|
|
struct gsm_lchan *lchan = &ts->lchan[k];
|
|
|
|
INIT_LLIST_HEAD(&lchan->dl_tch_queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osmo_rtp_init(tall_bts_ctx);
|
|
|
|
|
2011-09-04 20:42:03 +00:00
|
|
|
rc = bts_model_init(bts);
|
2012-07-08 18:20:51 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
llist_del(&bts->list);
|
2011-09-04 20:42:03 +00:00
|
|
|
return rc;
|
2012-07-08 18:20:51 +00:00
|
|
|
}
|
2011-09-04 20:42:03 +00:00
|
|
|
|
|
|
|
bts_gsmnet.num_bts++;
|
|
|
|
|
|
|
|
return rc;
|
2011-06-27 09:25:35 +00:00
|
|
|
}
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2011-06-29 18:42:14 +00:00
|
|
|
static void shutdown_timer_cb(void *data)
|
|
|
|
{
|
2011-07-01 17:03:30 +00:00
|
|
|
fprintf(stderr, "Shutdown timer expired\n");
|
2011-06-29 18:42:14 +00:00
|
|
|
exit(42);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct osmo_timer_list shutdown_timer = {
|
|
|
|
.cb = &shutdown_timer_cb,
|
|
|
|
};
|
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
void bts_shutdown(struct gsm_bts *bts, const char *reason)
|
2011-06-29 18:42:14 +00:00
|
|
|
{
|
|
|
|
struct gsm_bts_trx *trx;
|
|
|
|
|
2011-07-01 17:03:30 +00:00
|
|
|
LOGP(DOML, LOGL_NOTICE, "Shutting down BTS %u, Reason %s\n",
|
2011-07-01 16:09:34 +00:00
|
|
|
bts->nr, reason);
|
|
|
|
|
2011-06-29 18:42:14 +00:00
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list)
|
|
|
|
bts_model_trx_deact_rf(trx);
|
|
|
|
|
|
|
|
/* shedule a timer to make sure select loop logic can run again
|
|
|
|
* to dispatch any pending primitives */
|
|
|
|
osmo_timer_schedule(&shutdown_timer, 3, 0);
|
|
|
|
}
|
|
|
|
|
2011-03-04 13:05:20 +00:00
|
|
|
/* main link is established, send status report */
|
2011-06-27 09:25:35 +00:00
|
|
|
int bts_link_estab(struct gsm_bts *bts)
|
2011-03-04 13:05:20 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
LOGP(DSUM, LOGL_INFO, "Main link established, sending Status'.\n");
|
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
/* BTS and SITE MGR are EAABLED, BTS is DEPENDENCY */
|
|
|
|
oml_tx_state_changed(&bts->site_mgr.mo);
|
|
|
|
oml_tx_state_changed(&bts->mo);
|
2011-06-27 09:25:35 +00:00
|
|
|
|
2012-06-28 06:59:48 +00:00
|
|
|
/* those should all be in DEPENDENCY */
|
2012-07-08 18:50:02 +00:00
|
|
|
if (gprs_enabled) {
|
|
|
|
oml_tx_state_changed(&bts->gprs.nse.mo);
|
|
|
|
oml_tx_state_changed(&bts->gprs.cell.mo);
|
|
|
|
oml_tx_state_changed(&bts->gprs.nsvc[0].mo);
|
|
|
|
oml_tx_state_changed(&bts->gprs.nsvc[1].mo);
|
|
|
|
}
|
2012-06-28 06:59:48 +00:00
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
/* All other objects start off-line until the BTS Model code says otherwise */
|
2011-03-04 13:05:20 +00:00
|
|
|
for (i = 0; i < bts->num_trx; i++) {
|
2011-06-27 09:25:35 +00:00
|
|
|
struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, i);
|
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
oml_tx_state_changed(&trx->mo);
|
|
|
|
oml_tx_state_changed(&trx->bb_transc.mo);
|
2011-06-27 09:25:35 +00:00
|
|
|
|
|
|
|
for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
|
|
|
|
struct gsm_bts_trx_ts *ts = &trx->ts[j];
|
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
oml_tx_state_changed(&ts->mo);
|
2011-03-04 13:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RSL link is established, send status report */
|
2011-06-27 09:25:35 +00:00
|
|
|
int trx_link_estab(struct gsm_bts_trx *trx)
|
2011-03-04 13:05:20 +00:00
|
|
|
{
|
2011-06-27 09:25:35 +00:00
|
|
|
struct ipabis_link *link = (struct ipabis_link *) trx->rsl_link;
|
|
|
|
uint8_t radio_state = (link->state == LINK_STATE_CONNECT) ? NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
LOGP(DSUM, LOGL_INFO, "RSL link (TRX %02x) state changed to %s, sending Status'.\n",
|
|
|
|
trx->nr, (link->state == LINK_STATE_CONNECT) ? "up" : "down");
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
oml_mo_state_chg(&trx->mo, radio_state, NM_AVSTATE_OK);
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
if (link->state == LINK_STATE_CONNECT)
|
2011-03-04 13:05:20 +00:00
|
|
|
rsl_tx_rf_res(trx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
int lchan_init_lapdm(struct gsm_lchan *lchan)
|
2011-03-04 13:05:20 +00:00
|
|
|
{
|
2011-06-27 09:25:35 +00:00
|
|
|
struct lapdm_channel *lc = &lchan->lapdm_ch;
|
|
|
|
|
|
|
|
lapdm_channel_init(lc, LAPDM_MODE_BTS);
|
|
|
|
lapdm_channel_set_flags(lc, LAPDM_ENT_F_POLLING_ONLY);
|
|
|
|
lapdm_channel_set_l1(lc, NULL, lchan);
|
|
|
|
lapdm_channel_set_l3(lc, lapdm_rll_tx_cb, lchan);
|
|
|
|
|
|
|
|
return 0;
|
2011-03-04 13:05:20 +00:00
|
|
|
}
|
2011-06-27 09:25:35 +00:00
|
|
|
|
|
|
|
int bts_agch_enqueue(struct gsm_bts *bts, struct msgb *msg)
|
2011-03-04 13:05:20 +00:00
|
|
|
{
|
2012-01-12 23:40:04 +00:00
|
|
|
struct gsm_bts_role_bts *btsb = bts_role_bts(bts);
|
2011-06-27 09:25:35 +00:00
|
|
|
|
|
|
|
/* FIXME: implement max queue length */
|
2012-01-12 23:40:04 +00:00
|
|
|
msgb_enqueue(&btsb->agch_queue, msg);
|
2011-06-27 09:25:35 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-03-04 13:05:20 +00:00
|
|
|
}
|
|
|
|
|
2011-06-27 09:25:35 +00:00
|
|
|
struct msgb *bts_agch_dequeue(struct gsm_bts *bts)
|
|
|
|
{
|
2012-01-12 23:40:04 +00:00
|
|
|
struct gsm_bts_role_bts *btsb = bts_role_bts(bts);
|
2011-06-27 09:25:35 +00:00
|
|
|
|
2012-01-12 23:40:04 +00:00
|
|
|
return msgb_dequeue(&btsb->agch_queue);
|
2011-06-27 09:25:35 +00:00
|
|
|
}
|