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>
|
2018-02-24 11:36:52 +00:00
|
|
|
#include <osmocom/core/stats.h>
|
|
|
|
#include <osmocom/core/rate_ctr.h>
|
2011-05-22 18:26:58 +00:00
|
|
|
#include <osmocom/gsm/protocol/gsm_12_21.h>
|
2018-06-08 14:23:35 +00:00
|
|
|
#include <osmocom/gsm/gsm48.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>
|
2016-10-28 14:52:48 +00:00
|
|
|
#include <osmo-bts/dtx_dl_amr_fsm.h>
|
2018-02-27 13:52:50 +00:00
|
|
|
#include <osmo-bts/pcuif_proto.h>
|
2011-03-04 13:18:23 +00:00
|
|
|
#include <osmo-bts/rsl.h>
|
|
|
|
#include <osmo-bts/oml.h>
|
2014-02-14 15:42:49 +00:00
|
|
|
#include <osmo-bts/signal.h>
|
2016-12-28 11:43:09 +00:00
|
|
|
#include <osmo-bts/dtx_dl_amr_fsm.h>
|
2019-05-21 00:38:43 +00:00
|
|
|
#include <osmo-bts/cbch.h>
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2016-01-20 21:50:06 +00:00
|
|
|
#define MIN_QUAL_RACH 5.0f /* at least 5 dB C/I */
|
|
|
|
#define MIN_QUAL_NORM -0.5f /* at least -1 dB C/I */
|
|
|
|
|
2016-01-09 12:13:37 +00:00
|
|
|
static void bts_update_agch_max_queue_length(struct gsm_bts *bts);
|
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;
|
|
|
|
|
2014-02-14 15:42:49 +00:00
|
|
|
/* Table 3.1 TS 04.08: Values of parameter S */
|
|
|
|
static const uint8_t tx_integer[] = {
|
|
|
|
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 25, 32, 50,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t s_values[][2] = {
|
|
|
|
{ 55, 41 }, { 76, 52 }, { 109, 58 }, { 163, 86 }, { 217, 115 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bts_signal_cbfn(unsigned int subsys, unsigned int signal,
|
|
|
|
void *hdlr_data, void *signal_data)
|
|
|
|
{
|
|
|
|
if (subsys == SS_GLOBAL && signal == S_NEW_SYSINFO) {
|
|
|
|
struct gsm_bts *bts = signal_data;
|
|
|
|
|
|
|
|
bts_update_agch_max_queue_length(bts);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-24 11:36:52 +00:00
|
|
|
static const struct rate_ctr_desc bts_ctr_desc[] = {
|
|
|
|
[BTS_CTR_PAGING_RCVD] = {"paging:rcvd", "Received paging requests (Abis)"},
|
|
|
|
[BTS_CTR_PAGING_DROP] = {"paging:drop", "Dropped paging requests (Abis)"},
|
|
|
|
[BTS_CTR_PAGING_SENT] = {"paging:sent", "Sent paging requests (Um)"},
|
|
|
|
|
|
|
|
[BTS_CTR_RACH_RCVD] = {"rach:rcvd", "Received RACH requests (Um)"},
|
2018-02-26 07:49:59 +00:00
|
|
|
[BTS_CTR_RACH_DROP] = {"rach:drop", "Dropped RACH requests (Um)"},
|
|
|
|
[BTS_CTR_RACH_HO] = {"rach:handover", "Received RACH requests (Handover)"},
|
|
|
|
[BTS_CTR_RACH_CS] = {"rach:cs", "Received RACH requests (CS/Abis)"},
|
|
|
|
[BTS_CTR_RACH_PS] = {"rach:ps", "Received RACH requests (PS/PCU)"},
|
2018-02-24 11:36:52 +00:00
|
|
|
|
|
|
|
[BTS_CTR_AGCH_RCVD] = {"agch:rcvd", "Received AGCH requests (Abis)"},
|
|
|
|
[BTS_CTR_AGCH_SENT] = {"agch:sent", "Sent AGCH requests (Abis)"},
|
|
|
|
[BTS_CTR_AGCH_DELETED] = {"agch:delete", "Sent AGCH DELETE IND (Abis)"},
|
|
|
|
};
|
|
|
|
static const struct rate_ctr_group_desc bts_ctrg_desc = {
|
|
|
|
"bts",
|
|
|
|
"base transceiver station",
|
|
|
|
OSMO_STATS_CLASS_GLOBAL,
|
|
|
|
ARRAY_SIZE(bts_ctr_desc),
|
|
|
|
bts_ctr_desc
|
|
|
|
};
|
|
|
|
|
2019-05-21 00:38:43 +00:00
|
|
|
static const struct rate_ctr_desc cbch_ctr_desc[] = {
|
|
|
|
[CBCH_CTR_RCVD_QUEUED] = {"cbch:rcvd_queued", "Received + queued CBCH messages (Abis)" },
|
|
|
|
[CBCH_CTR_RCVD_DROPPED] = {"cbch:rcvd_dropped", "Received + dropped CBCH messages (Abis)" },
|
|
|
|
|
|
|
|
[CBCH_CTR_SENT_SINGLE] = {"cbch:sent_single", "Sent single CBCH messages (Um)" },
|
|
|
|
[CBCH_CTR_SENT_DEFAULT] = {"cbch:sent_default", "Sent default CBCH messages (Um)" },
|
|
|
|
[CBCH_CTR_SENT_NULL] = {"cbch:sent_null", "Sent NULL CBCH messages (Um)" },
|
|
|
|
};
|
|
|
|
static const struct rate_ctr_group_desc cbch_ctrg_desc = {
|
|
|
|
"cbch",
|
|
|
|
"cell broadcast channel",
|
|
|
|
OSMO_STATS_CLASS_GLOBAL,
|
|
|
|
ARRAY_SIZE(cbch_ctr_desc),
|
|
|
|
cbch_ctr_desc
|
|
|
|
};
|
|
|
|
|
2018-11-12 11:50:23 +00:00
|
|
|
/* Initialize the BTS data structures, called before config
|
2016-01-09 12:13:37 +00:00
|
|
|
* file reading */
|
2011-06-27 09:25:35 +00:00
|
|
|
int bts_init(struct gsm_bts *bts)
|
|
|
|
{
|
2016-01-17 20:08:20 +00:00
|
|
|
int rc, i;
|
2014-02-14 15:42:49 +00:00
|
|
|
static int initialized = 0;
|
2015-12-06 20:31:39 +00:00
|
|
|
void *tall_rtp_ctx;
|
2011-09-04 20:42:03 +00:00
|
|
|
|
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
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
INIT_LLIST_HEAD(&bts->agch_queue.queue);
|
|
|
|
bts->agch_queue.length = 0;
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2018-02-24 11:36:52 +00:00
|
|
|
bts->ctrs = rate_ctr_group_alloc(bts, &bts_ctrg_desc, bts->nr);
|
2019-05-08 12:03:11 +00:00
|
|
|
if (!bts->ctrs) {
|
|
|
|
llist_del(&bts->list);
|
|
|
|
return -1;
|
|
|
|
}
|
2018-02-24 11:36:52 +00:00
|
|
|
|
2014-02-14 20:15:31 +00:00
|
|
|
/* enable management with default levels,
|
|
|
|
* raise threshold to GSM_BTS_AGCH_QUEUE_THRESH_LEVEL_DISABLE to
|
|
|
|
* disable this feature.
|
|
|
|
*/
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.low_level = GSM_BTS_AGCH_QUEUE_LOW_LEVEL_DEFAULT;
|
|
|
|
bts->agch_queue.high_level = GSM_BTS_AGCH_QUEUE_HIGH_LEVEL_DEFAULT;
|
|
|
|
bts->agch_queue.thresh_level = GSM_BTS_AGCH_QUEUE_THRESH_LEVEL_DEFAULT;
|
2014-02-14 20:15:31 +00:00
|
|
|
|
2012-11-13 04:20:47 +00:00
|
|
|
/* configurable via VTY */
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->paging_state = paging_init(bts, 200, 0);
|
|
|
|
bts->ul_power_target = -75; /* dBm default */
|
|
|
|
bts->rtp_jitter_adaptive = false;
|
2018-05-22 15:35:49 +00:00
|
|
|
bts->rtp_port_range_start = 16384;
|
|
|
|
bts->rtp_port_range_end = 17407;
|
|
|
|
bts->rtp_port_range_next = bts->rtp_port_range_start;
|
2012-11-13 04:20:47 +00:00
|
|
|
|
|
|
|
/* configurable via OML */
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->load.ccch.load_ind_period = 112;
|
2012-06-04 15:27:13 +00:00
|
|
|
load_timer_start(bts);
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->rtp_jitter_buf_ms = 100;
|
|
|
|
bts->max_ta = 63;
|
|
|
|
bts->ny1 = 4;
|
|
|
|
bts->t3105_ms = 300;
|
|
|
|
bts->min_qual_rach = MIN_QUAL_RACH;
|
|
|
|
bts->min_qual_norm = MIN_QUAL_NORM;
|
|
|
|
bts->max_ber10k_rach = 1707; /* 7 of 41 bits is Eb/N0 of 0 dB = 0.1707 */
|
|
|
|
bts->pcu.sock_path = talloc_strdup(bts, PCU_SOCK_DEFAULT);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bts->t200_ms); i++)
|
|
|
|
bts->t200_ms[i] = oml_default_t200_ms[i];
|
2011-09-08 13:18:43 +00:00
|
|
|
|
2013-02-05 08:06:49 +00:00
|
|
|
/* default RADIO_LINK_TIMEOUT */
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->radio_link_timeout = 32;
|
2013-02-05 08:06:49 +00:00
|
|
|
|
2014-11-10 14:09:52 +00:00
|
|
|
/* Start with the site manager */
|
|
|
|
oml_mo_state_init(&bts->site_mgr.mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
|
|
|
|
|
2011-07-01 16:09:34 +00:00
|
|
|
/* set BTS to dependency */
|
2013-06-30 13:05:09 +00:00
|
|
|
oml_mo_state_init(&bts->mo, -1, NM_AVSTATE_DEPENDENCY);
|
|
|
|
oml_mo_state_init(&bts->gprs.nse.mo, -1, NM_AVSTATE_DEPENDENCY);
|
|
|
|
oml_mo_state_init(&bts->gprs.cell.mo, -1, NM_AVSTATE_DEPENDENCY);
|
|
|
|
oml_mo_state_init(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_DEPENDENCY);
|
2014-11-10 12:18:59 +00:00
|
|
|
oml_mo_state_init(&bts->gprs.nsvc[1].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE);
|
2011-07-01 16:09:34 +00:00
|
|
|
|
2015-12-06 20:31:39 +00:00
|
|
|
/* allocate a talloc pool for ORTP to ensure it doesn't have to go back
|
|
|
|
* to the libc malloc all the time */
|
|
|
|
tall_rtp_ctx = talloc_pool(tall_bts_ctx, 262144);
|
|
|
|
osmo_rtp_init(tall_rtp_ctx);
|
2011-09-03 13:41:12 +00:00
|
|
|
|
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
|
|
|
|
2018-11-21 18:49:12 +00:00
|
|
|
/* TRX0 was allocated early during gsm_bts_alloc, not later through VTY */
|
|
|
|
bts_trx_init(bts->c0);
|
2011-09-04 20:42:03 +00:00
|
|
|
bts_gsmnet.num_bts++;
|
|
|
|
|
2014-02-14 15:42:49 +00:00
|
|
|
if (!initialized) {
|
|
|
|
osmo_signal_register_handler(SS_GLOBAL, bts_signal_cbfn, NULL);
|
|
|
|
initialized = 1;
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:59:08 +00:00
|
|
|
INIT_LLIST_HEAD(&bts->smscb_basic.queue);
|
2019-05-21 00:38:43 +00:00
|
|
|
bts->smscb_basic.ctrs = rate_ctr_group_alloc(bts, &cbch_ctrg_desc, 0);
|
|
|
|
OSMO_ASSERT(bts->smscb_basic.ctrs);
|
2019-05-20 18:59:08 +00:00
|
|
|
INIT_LLIST_HEAD(&bts->smscb_extended.queue);
|
2019-05-21 00:38:43 +00:00
|
|
|
bts->smscb_extended.ctrs = rate_ctr_group_alloc(bts, &cbch_ctrg_desc, 1);
|
|
|
|
OSMO_ASSERT(bts->smscb_extended.ctrs);
|
|
|
|
bts->smscb_queue_max_len = 15;
|
|
|
|
bts->smscb_queue_tgt_len = 2;
|
|
|
|
bts->smscb_queue_hyst = 2;
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
INIT_LLIST_HEAD(&bts->oml_queue);
|
2014-12-29 00:02:29 +00:00
|
|
|
|
2016-10-28 14:52:48 +00:00
|
|
|
/* register DTX DL FSM */
|
2017-10-24 16:42:30 +00:00
|
|
|
rc = osmo_fsm_register(&dtx_dl_amr_fsm);
|
|
|
|
OSMO_ASSERT(rc == 0);
|
|
|
|
|
2019-06-02 15:36:21 +00:00
|
|
|
bts->fn_stats.min = INT32_MAX;
|
|
|
|
bts->fn_stats.max = INT32_MIN;
|
|
|
|
bts->fn_stats.avg_count = 0;
|
|
|
|
bts->fn_stats.avg_window = 256;
|
|
|
|
|
2011-09-04 20:42:03 +00:00
|
|
|
return rc;
|
2011-06-27 09:25:35 +00:00
|
|
|
}
|
2011-03-04 13:05:20 +00:00
|
|
|
|
2018-11-12 11:50:23 +00:00
|
|
|
/* Initialize the TRX data structures, called before config
|
|
|
|
* file reading */
|
|
|
|
int bts_trx_init(struct gsm_bts_trx *trx)
|
|
|
|
{
|
|
|
|
/* initialize bts data structure */
|
|
|
|
struct trx_power_params *tpp = &trx->power_params;
|
|
|
|
int rc, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Default values for the power adjustments */
|
|
|
|
tpp->ramp.max_initial_pout_mdBm = to_mdB(0);
|
|
|
|
tpp->ramp.step_size_mdB = to_mdB(2);
|
|
|
|
tpp->ramp.step_interval_sec = 1;
|
|
|
|
|
|
|
|
rc = bts_model_trx_init(trx);
|
|
|
|
if (rc < 0) {
|
|
|
|
llist_del(&trx->list);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-01-25 17:43:20 +00:00
|
|
|
if (osmo_timer_pending(&shutdown_timer)) {
|
|
|
|
LOGP(DOML, LOGL_NOTICE,
|
|
|
|
"BTS is already being shutdown.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2017-03-06 13:22:51 +00:00
|
|
|
llist_for_each_entry_reverse(trx, &bts->trx_list, list) {
|
2011-06-29 18:42:14 +00:00
|
|
|
bts_model_trx_deact_rf(trx);
|
2013-01-25 10:07:12 +00:00
|
|
|
bts_model_trx_close(trx);
|
|
|
|
}
|
2011-06-29 18:42:14 +00:00
|
|
|
|
|
|
|
/* 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");
|
|
|
|
|
2014-11-10 12:01:33 +00:00
|
|
|
/* BTS and SITE MGR are EANBLED, BTS is DEPENDENCY */
|
2011-07-01 16:09:34 +00:00
|
|
|
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-24 07:33:35 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-30 19:19:27 +00:00
|
|
|
return bts_model_oml_estab(bts);
|
2011-03-04 13:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2013-02-10 09:21:12 +00:00
|
|
|
struct e1inp_sign_link *link = trx->rsl_link;
|
|
|
|
uint8_t radio_state = link ? NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
|
2017-01-02 20:42:56 +00:00
|
|
|
int rc;
|
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",
|
2013-02-10 09:21:12 +00:00
|
|
|
trx->nr, link ? "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
|
|
|
|
2013-02-10 09:21:12 +00:00
|
|
|
if (link)
|
2017-01-02 20:42:56 +00:00
|
|
|
rc = rsl_tx_rf_res(trx);
|
2013-02-05 15:47:57 +00:00
|
|
|
else
|
2017-01-02 20:42:56 +00:00
|
|
|
rc = bts_model_trx_deact_rf(trx);
|
2019-03-15 11:08:05 +00:00
|
|
|
if (rc < 0) {
|
2019-05-25 08:19:00 +00:00
|
|
|
oml_tx_failure_event_rep(&trx->bb_transc.mo, NM_SEVER_MAJOR, OSMO_EVT_MAJ_RSL_FAIL,
|
2019-03-15 11:08:05 +00:00
|
|
|
link ?
|
|
|
|
"Failed to establish RSL link (%d)" :
|
|
|
|
"Failed to deactivate RF (%d)", rc);
|
|
|
|
}
|
|
|
|
|
2011-03-04 13:05:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-09 12:13:37 +00:00
|
|
|
/* set the availability of the TRX (used by PHY driver) */
|
|
|
|
int trx_set_available(struct gsm_bts_trx *trx, int avail)
|
|
|
|
{
|
|
|
|
int tn;
|
|
|
|
|
|
|
|
LOGP(DSUM, LOGL_INFO, "TRX(%d): Setting available = %d\n",
|
|
|
|
trx->nr, avail);
|
|
|
|
if (avail) {
|
2018-11-13 20:04:31 +00:00
|
|
|
int op_state = trx->rsl_link ? NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
|
|
|
|
oml_mo_state_chg(&trx->mo, op_state, NM_AVSTATE_OK);
|
|
|
|
oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
|
2016-01-09 12:13:37 +00:00
|
|
|
for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)
|
2018-11-13 20:04:31 +00:00
|
|
|
oml_mo_state_chg(&trx->ts[tn].mo, op_state, NM_AVSTATE_OK);
|
2016-01-09 12:13:37 +00:00
|
|
|
} else {
|
2016-01-18 10:23:38 +00:00
|
|
|
oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
|
|
|
|
oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_NOT_INSTALLED);
|
2016-01-09 12:13:37 +00:00
|
|
|
|
|
|
|
for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++)
|
2016-01-18 10:23:38 +00:00
|
|
|
oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
|
2016-01-09 12:13:37 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-02 20:00:25 +00:00
|
|
|
/* prepare the per-SAPI T200 arrays for a given lchan */
|
|
|
|
static int t200_by_lchan(int *t200_ms_dcch, int *t200_ms_acch, struct gsm_lchan *lchan)
|
|
|
|
{
|
|
|
|
struct gsm_bts *bts = lchan->ts->trx->bts;
|
|
|
|
|
|
|
|
/* we have to compensate for the "RTS advance" due to the asynchronous interface between
|
|
|
|
* the BTS (LAPDm) and the PHY/L1 (OsmoTRX or DSP in case of osmo-bts-{sysmo,lc15,oc2g,octphy} */
|
|
|
|
int32_t fn_advance = bts_get_avg_fn_advance(bts);
|
|
|
|
int32_t fn_advance_us = fn_advance * 4615;
|
|
|
|
int fn_advance_ms = fn_advance_us / 1000;
|
|
|
|
|
|
|
|
t200_ms_acch[DL_SAPI0] = bts->t200_ms[T200_SACCH_SDCCH] + fn_advance_ms;
|
|
|
|
t200_ms_acch[DL_SAPI3] = bts->t200_ms[T200_SACCH_SDCCH] + fn_advance_ms;
|
|
|
|
|
|
|
|
switch (lchan->type) {
|
|
|
|
case GSM_LCHAN_SDCCH:
|
|
|
|
t200_ms_dcch[DL_SAPI0] = bts->t200_ms[T200_SDCCH] + fn_advance_ms;
|
|
|
|
t200_ms_dcch[DL_SAPI3] = bts->t200_ms[T200_SDCCH_SAPI3] + fn_advance_ms;
|
|
|
|
break;
|
|
|
|
case GSM_LCHAN_TCH_F:
|
|
|
|
t200_ms_dcch[DL_SAPI0] = bts->t200_ms[T200_FACCH_F] + fn_advance_ms;
|
|
|
|
t200_ms_dcch[DL_SAPI3] = bts->t200_ms[T200_FACCH_F] + fn_advance_ms;
|
|
|
|
break;
|
|
|
|
case GSM_LCHAN_TCH_H:
|
|
|
|
t200_ms_dcch[DL_SAPI0] = bts->t200_ms[T200_FACCH_H] + fn_advance_ms;
|
|
|
|
t200_ms_dcch[DL_SAPI3] = bts->t200_ms[T200_FACCH_H] + fn_advance_ms;
|
|
|
|
break;
|
|
|
|
default:
|
2019-06-21 17:03:01 +00:00
|
|
|
/* Channels such as CCCH don't use lapdm DL, and hence no T200 is needed */
|
2019-06-02 20:00:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
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;
|
2019-06-02 20:00:25 +00:00
|
|
|
int t200_ms_dcch[_NR_DL_SAPI], t200_ms_acch[_NR_DL_SAPI];
|
|
|
|
|
2019-06-21 17:03:01 +00:00
|
|
|
if (t200_by_lchan(t200_ms_dcch, t200_ms_acch, lchan) == 0) {
|
|
|
|
LOGPLCHAN(lchan, DLLAPD, LOGL_DEBUG,
|
|
|
|
"Setting T200 D0=%u, D3=%u, S0=%u, S3=%u (all in ms)\n",
|
|
|
|
t200_ms_dcch[DL_SAPI0], t200_ms_dcch[DL_SAPI3],
|
|
|
|
t200_ms_acch[DL_SAPI0], t200_ms_acch[DL_SAPI3]);
|
|
|
|
lapdm_channel_init2(lc, LAPDM_MODE_BTS, t200_ms_dcch, t200_ms_acch, lchan->type);
|
|
|
|
lapdm_channel_set_flags(lc, LAPDM_ENT_F_POLLING_ONLY);
|
|
|
|
lapdm_channel_set_l1(lc, NULL, lchan);
|
|
|
|
}
|
|
|
|
/* We still need to set Rx callback to receive RACH requests: */
|
2011-06-27 09:25:35 +00:00
|
|
|
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
|
|
|
|
2014-02-14 15:42:49 +00:00
|
|
|
#define CCCH_RACH_RATIO_COMBINED256 (256*1/9)
|
|
|
|
#define CCCH_RACH_RATIO_SEPARATE256 (256*10/55)
|
|
|
|
|
|
|
|
int bts_agch_max_queue_length(int T, int bcch_conf)
|
|
|
|
{
|
|
|
|
int S, ccch_rach_ratio256, i;
|
|
|
|
int T_group = 0;
|
|
|
|
int is_ccch_comb = 0;
|
|
|
|
|
|
|
|
if (bcch_conf == RSL_BCCH_CCCH_CONF_1_C)
|
|
|
|
is_ccch_comb = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The calculation is based on the ratio of the number RACH slots and
|
|
|
|
* CCCH blocks per time:
|
|
|
|
* Lmax = (T + 2*S) / R_RACH * R_CCCH
|
|
|
|
* where
|
|
|
|
* T3126_min = (T + 2*S) / R_RACH, as defined in GSM 04.08, 11.1.1
|
|
|
|
* R_RACH is the RACH slot rate (e.g. RACHs per multiframe)
|
|
|
|
* R_CCCH is the CCCH block rate (same time base like R_RACH)
|
|
|
|
* S and T are defined in GSM 04.08, 3.3.1.1.2
|
|
|
|
* The ratio is mainly influenced by the downlink only channels
|
|
|
|
* (BCCH, FCCH, SCH, CBCH) that can not be used for CCCH.
|
|
|
|
* An estimation with an error of < 10% is used:
|
|
|
|
* ~ 1/9 if CCCH is combined with SDCCH, and
|
|
|
|
* ~ 1/5.5 otherwise.
|
|
|
|
*/
|
|
|
|
ccch_rach_ratio256 = is_ccch_comb ?
|
|
|
|
CCCH_RACH_RATIO_COMBINED256 :
|
|
|
|
CCCH_RACH_RATIO_SEPARATE256;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tx_integer); i++) {
|
|
|
|
if (tx_integer[i] == T) {
|
|
|
|
T_group = i % 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
S = s_values[T_group][is_ccch_comb];
|
|
|
|
|
|
|
|
return (T + 2 * S) * ccch_rach_ratio256 / 256;
|
|
|
|
}
|
|
|
|
|
2016-01-09 12:13:37 +00:00
|
|
|
static void bts_update_agch_max_queue_length(struct gsm_bts *bts)
|
2014-02-14 15:42:49 +00:00
|
|
|
{
|
|
|
|
struct gsm48_system_information_type_3 *si3;
|
2018-03-17 11:22:40 +00:00
|
|
|
int old_max_length = bts->agch_queue.max_length;
|
2014-02-14 15:42:49 +00:00
|
|
|
|
|
|
|
if (!(bts->si_valid & (1<<SYSINFO_TYPE_3)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
si3 = GSM_BTS_SI(bts, SYSINFO_TYPE_3);
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.max_length =
|
2014-02-14 15:42:49 +00:00
|
|
|
bts_agch_max_queue_length(si3->rach_control.tx_integer,
|
|
|
|
si3->control_channel_desc.ccch_conf);
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
if (bts->agch_queue.max_length != old_max_length)
|
2014-02-14 15:42:49 +00:00
|
|
|
LOGP(DRSL, LOGL_INFO, "Updated AGCH max queue length to %d\n",
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.max_length);
|
2014-02-14 15:42:49 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 17:45:45 +00:00
|
|
|
#define REQ_REFS_PER_IMM_ASS_REJ 4
|
|
|
|
static int store_imm_ass_rej_refs(struct gsm48_imm_ass_rej *rej,
|
|
|
|
struct gsm48_req_ref *req_refs,
|
|
|
|
uint8_t *wait_inds,
|
|
|
|
int count)
|
|
|
|
{
|
|
|
|
switch (count) {
|
|
|
|
case 0:
|
|
|
|
/* TODO: Warning ? */
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
count = 4;
|
|
|
|
rej->req_ref4 = req_refs[3];
|
|
|
|
rej->wait_ind4 = wait_inds[3];
|
|
|
|
/* fall through */
|
|
|
|
case 3:
|
|
|
|
rej->req_ref3 = req_refs[2];
|
|
|
|
rej->wait_ind3 = wait_inds[2];
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
|
|
|
rej->req_ref2 = req_refs[1];
|
|
|
|
rej->wait_ind2 = wait_inds[1];
|
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
rej->req_ref1 = req_refs[0];
|
|
|
|
rej->wait_ind1 = wait_inds[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (count) {
|
|
|
|
case 1:
|
|
|
|
rej->req_ref2 = req_refs[0];
|
|
|
|
rej->wait_ind2 = wait_inds[0];
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
|
|
|
rej->req_ref3 = req_refs[0];
|
|
|
|
rej->wait_ind3 = wait_inds[0];
|
|
|
|
/* fall through */
|
|
|
|
case 3:
|
|
|
|
rej->req_ref4 = req_refs[0];
|
|
|
|
rej->wait_ind4 = wait_inds[0];
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extract_imm_ass_rej_refs(struct gsm48_imm_ass_rej *rej,
|
|
|
|
struct gsm48_req_ref *req_refs,
|
|
|
|
uint8_t *wait_inds)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
req_refs[count] = rej->req_ref1;
|
|
|
|
wait_inds[count] = rej->wait_ind1;
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (memcmp(&rej->req_ref1, &rej->req_ref2, sizeof(rej->req_ref2))) {
|
|
|
|
req_refs[count] = rej->req_ref2;
|
|
|
|
wait_inds[count] = rej->wait_ind2;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(&rej->req_ref1, &rej->req_ref3, sizeof(rej->req_ref3)) &&
|
|
|
|
memcmp(&rej->req_ref2, &rej->req_ref3, sizeof(rej->req_ref3))) {
|
|
|
|
req_refs[count] = rej->req_ref3;
|
|
|
|
wait_inds[count] = rej->wait_ind3;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(&rej->req_ref1, &rej->req_ref4, sizeof(rej->req_ref4)) &&
|
|
|
|
memcmp(&rej->req_ref2, &rej->req_ref4, sizeof(rej->req_ref4)) &&
|
|
|
|
memcmp(&rej->req_ref3, &rej->req_ref4, sizeof(rej->req_ref4))) {
|
|
|
|
req_refs[count] = rej->req_ref4;
|
|
|
|
wait_inds[count] = rej->wait_ind4;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int try_merge_imm_ass_rej(struct gsm48_imm_ass_rej *old_rej,
|
|
|
|
struct gsm48_imm_ass_rej *new_rej)
|
|
|
|
{
|
|
|
|
struct gsm48_req_ref req_refs[2 * REQ_REFS_PER_IMM_ASS_REJ];
|
|
|
|
uint8_t wait_inds[2 * REQ_REFS_PER_IMM_ASS_REJ];
|
|
|
|
int count = 0;
|
|
|
|
int stored = 0;
|
|
|
|
|
|
|
|
if (new_rej->msg_type != GSM48_MT_RR_IMM_ASS_REJ)
|
|
|
|
return 0;
|
|
|
|
if (old_rej->msg_type != GSM48_MT_RR_IMM_ASS_REJ)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* GSM 08.58, 5.7
|
|
|
|
* -> The BTS may combine serveral IMM.ASS.REJ messages
|
|
|
|
* -> Identical request refs in one message may be squeezed
|
|
|
|
*
|
|
|
|
* GSM 04.08, 9.1.20.2
|
|
|
|
* -> Request ref and wait ind are duplicated to fill the message
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Extract all entries */
|
|
|
|
count = extract_imm_ass_rej_refs(old_rej,
|
|
|
|
&req_refs[count], &wait_inds[count]);
|
|
|
|
if (count == REQ_REFS_PER_IMM_ASS_REJ)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
count += extract_imm_ass_rej_refs(new_rej,
|
|
|
|
&req_refs[count], &wait_inds[count]);
|
|
|
|
|
|
|
|
/* Store entries into old message */
|
|
|
|
stored = store_imm_ass_rej_refs(old_rej,
|
|
|
|
&req_refs[stored], &wait_inds[stored],
|
|
|
|
count);
|
|
|
|
count -= stored;
|
|
|
|
if (count == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Store remaining entries into new message */
|
|
|
|
stored += store_imm_ass_rej_refs(new_rej,
|
|
|
|
&req_refs[stored], &wait_inds[stored],
|
|
|
|
count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
bts_agch_enqueue: Decrease queue len hard_limit from 1000 to 100
In a prod setup, complete channel saturation at the bsc was detected,
and Immediate Assignments were not being answered by the MS once sent by
the BTS.
Further investigation showed that the BTS was all the time printing
messages like this:
"bts.c:540 AGCH: too many messages in queue, refusing message type 0x3f, length = 1001/10"
So it seems the AGCH queue was becoming incredibly full (1000, hard
limit triggered the log), while acgch_queue.max_length was set to 10.
As a result, most probably the Immediate Assignments being sent to the
MS are super old in time, and the MS doesn't known about them anymore
once they are receivied, so no answer is sent back.
Let's try to avoid that by decreasing the hard limit so we never reach
that big queue_len scenario.
The number 100 is selected from data gatherered in agch_test.c which
prints a table of max_length values based on different setups. Some
values can reach around 80 messages, so let's use a slightly bigger hard
limit.
Related: SYS#2695
Change-Id: I272798c959abec123776d2fa8dad5685ec512fbd
2018-06-08 13:48:01 +00:00
|
|
|
int hard_limit = 100;
|
2014-02-20 17:45:45 +00:00
|
|
|
struct gsm48_imm_ass_rej *imm_ass_cmd = msgb_l3(msg);
|
2014-02-14 20:15:31 +00:00
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
if (bts->agch_queue.length > hard_limit) {
|
2014-02-14 20:15:31 +00:00
|
|
|
LOGP(DSUM, LOGL_ERROR,
|
|
|
|
"AGCH: too many messages in queue, "
|
2018-06-06 17:46:25 +00:00
|
|
|
"refusing message type %s, length = %d/%d\n",
|
|
|
|
gsm48_rr_msg_name(((struct gsm48_imm_ass *)msgb_l3(msg))->msg_type),
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.length, bts->agch_queue.max_length);
|
2014-02-14 20:15:31 +00:00
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.rejected_msgs++;
|
2014-02-14 20:15:31 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-06-27 09:25:35 +00:00
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
if (bts->agch_queue.length > 0) {
|
2014-02-20 17:45:45 +00:00
|
|
|
struct msgb *last_msg =
|
2018-03-17 11:22:40 +00:00
|
|
|
llist_entry(bts->agch_queue.queue.prev, struct msgb, list);
|
2014-02-20 17:45:45 +00:00
|
|
|
struct gsm48_imm_ass_rej *last_imm_ass_rej = msgb_l3(last_msg);
|
|
|
|
|
|
|
|
if (try_merge_imm_ass_rej(last_imm_ass_rej, imm_ass_cmd)) {
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.merged_msgs++;
|
2014-02-20 17:45:45 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
msgb_enqueue(&bts->agch_queue.queue, msg);
|
|
|
|
bts->agch_queue.length++;
|
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)
|
|
|
|
{
|
2018-03-17 11:22:40 +00:00
|
|
|
struct msgb *msg = msgb_dequeue(&bts->agch_queue.queue);
|
2014-02-21 14:09:14 +00:00
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
2011-06-27 09:25:35 +00:00
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.length--;
|
2014-02-21 14:09:14 +00:00
|
|
|
return msg;
|
2011-06-27 09:25:35 +00:00
|
|
|
}
|
2012-12-26 17:55:54 +00:00
|
|
|
|
2014-02-14 20:15:31 +00:00
|
|
|
/*
|
|
|
|
* Remove lower prio messages if the queue has grown too long.
|
|
|
|
*
|
|
|
|
* \return 0 iff the number of messages in the queue would fit into the AGCH
|
|
|
|
* reserved part of the CCCH.
|
|
|
|
*/
|
|
|
|
static void compact_agch_queue(struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct msgb *msg, *msg2;
|
|
|
|
int max_len, slope, offs;
|
2018-03-17 11:22:40 +00:00
|
|
|
int level_low = bts->agch_queue.low_level;
|
|
|
|
int level_high = bts->agch_queue.high_level;
|
|
|
|
int level_thres = bts->agch_queue.thresh_level;
|
2014-02-14 20:15:31 +00:00
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
max_len = bts->agch_queue.max_length;
|
2014-02-14 20:15:31 +00:00
|
|
|
|
|
|
|
if (max_len == 0)
|
|
|
|
max_len = 1;
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
if (bts->agch_queue.length < max_len * level_thres / 100)
|
2014-02-14 20:15:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* p^
|
|
|
|
* 1+ /'''''
|
|
|
|
* | /
|
|
|
|
* | /
|
|
|
|
* 0+---/--+----+--> Q length
|
|
|
|
* low high max_len
|
|
|
|
*/
|
|
|
|
|
|
|
|
offs = max_len * level_low / 100;
|
|
|
|
if (level_high > level_low)
|
|
|
|
slope = 0x10000 * 100 / (level_high - level_low);
|
|
|
|
else
|
|
|
|
slope = 0x10000 * max_len; /* p_drop >= 1 if len > offs */
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
llist_for_each_entry_safe(msg, msg2, &bts->agch_queue.queue, list) {
|
2014-02-14 20:15:31 +00:00
|
|
|
struct gsm48_imm_ass *imm_ass_cmd = msgb_l3(msg);
|
|
|
|
int p_drop;
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
p_drop = (bts->agch_queue.length - offs) * slope / max_len;
|
2014-02-14 20:15:31 +00:00
|
|
|
|
|
|
|
if ((random() & 0xffff) >= p_drop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
llist_del(&msg->list);
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.length--;
|
2018-06-08 14:15:57 +00:00
|
|
|
rsl_tx_delete_ind(bts, (uint8_t *)imm_ass_cmd, msgb_l3len(msg));
|
|
|
|
rate_ctr_inc2(bts->ctrs, BTS_CTR_AGCH_DELETED);
|
2014-02-14 20:15:31 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.dropped_msgs++;
|
2014-02-14 20:15:31 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 14:09:15 +00:00
|
|
|
int bts_ccch_copy_msg(struct gsm_bts *bts, uint8_t *out_buf, struct gsm_time *gt,
|
|
|
|
int is_ag_res)
|
|
|
|
{
|
2014-02-14 20:15:31 +00:00
|
|
|
struct msgb *msg = NULL;
|
|
|
|
int rc = 0;
|
|
|
|
int is_empty = 1;
|
|
|
|
|
|
|
|
/* Do queue house keeping.
|
|
|
|
* This needs to be done every time a CCCH message is requested, since
|
|
|
|
* the queue max length is calculated based on the CCCH block rate and
|
|
|
|
* PCH messages also reduce the drain of the AGCH queue.
|
|
|
|
*/
|
|
|
|
compact_agch_queue(bts);
|
2014-02-21 14:09:15 +00:00
|
|
|
|
2014-02-14 20:15:31 +00:00
|
|
|
/* Check for paging messages first if this is PCH */
|
|
|
|
if (!is_ag_res)
|
2018-03-17 11:22:40 +00:00
|
|
|
rc = paging_gen_msg(bts->paging_state, out_buf, gt, &is_empty);
|
2014-02-14 13:18:51 +00:00
|
|
|
|
2014-02-14 20:15:31 +00:00
|
|
|
/* Check whether the block may be overwritten */
|
|
|
|
if (!is_empty)
|
|
|
|
return rc;
|
2014-02-21 14:09:15 +00:00
|
|
|
|
|
|
|
msg = bts_agch_dequeue(bts);
|
|
|
|
if (!msg)
|
2014-02-14 20:15:31 +00:00
|
|
|
return rc;
|
2014-02-21 14:09:15 +00:00
|
|
|
|
2018-02-24 11:36:52 +00:00
|
|
|
rate_ctr_inc2(bts->ctrs, BTS_CTR_AGCH_SENT);
|
|
|
|
|
2014-02-14 20:15:31 +00:00
|
|
|
/* Copy AGCH message */
|
2014-02-21 14:09:15 +00:00
|
|
|
memcpy(out_buf, msgb_l3(msg), msgb_l3len(msg));
|
|
|
|
rc = msgb_l3len(msg);
|
|
|
|
msgb_free(msg);
|
2014-02-14 13:18:51 +00:00
|
|
|
|
|
|
|
if (is_ag_res)
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.agch_msgs++;
|
2014-02-14 13:18:51 +00:00
|
|
|
else
|
2018-03-17 11:22:40 +00:00
|
|
|
bts->agch_queue.pch_msgs++;
|
2014-02-21 14:09:15 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-03-17 11:22:40 +00:00
|
|
|
int bts_supports_cipher(struct gsm_bts *bts, int rsl_cipher)
|
2012-12-26 17:55:54 +00:00
|
|
|
{
|
|
|
|
int sup;
|
|
|
|
|
|
|
|
if (rsl_cipher < 1 || rsl_cipher > 8)
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
|
|
|
/* No encryption is always supported */
|
|
|
|
if (rsl_cipher == 1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sup = (1 << (rsl_cipher - 2)) & bts->support.ciphers;
|
|
|
|
return sup > 0;
|
|
|
|
}
|
2014-12-06 19:30:52 +00:00
|
|
|
|
|
|
|
int trx_ms_pwr_ctrl_is_osmo(struct gsm_bts_trx *trx)
|
|
|
|
{
|
|
|
|
return trx->ms_power_control == 1;
|
|
|
|
}
|
2013-09-01 07:02:24 +00:00
|
|
|
|
|
|
|
struct gsm_time *get_time(struct gsm_bts *bts)
|
|
|
|
{
|
2018-03-17 11:22:40 +00:00
|
|
|
return &bts->gsm_time;
|
2013-09-01 07:02:24 +00:00
|
|
|
}
|
2018-01-25 17:59:42 +00:00
|
|
|
|
2018-02-21 15:58:08 +00:00
|
|
|
int bts_supports_cm(struct gsm_bts *bts, enum gsm_phys_chan_config pchan,
|
|
|
|
enum gsm48_chan_mode cm)
|
2018-01-25 17:59:42 +00:00
|
|
|
{
|
2018-02-21 15:58:08 +00:00
|
|
|
enum gsm_bts_features feature = _NUM_BTS_FEAT;
|
|
|
|
|
2019-06-02 17:12:40 +00:00
|
|
|
/* We assume that signalling support is mandatory,
|
|
|
|
* there is no BTS_FEAT_* definition to check that. */
|
|
|
|
if (cm == GSM48_CMODE_SIGN)
|
|
|
|
return 1;
|
|
|
|
|
2018-02-21 15:58:08 +00:00
|
|
|
/* Before the requested pchan/cm combination can be checked, we need to
|
|
|
|
* convert it to a feature identifier we can check */
|
2018-09-10 13:15:52 +00:00
|
|
|
switch (pchan) {
|
|
|
|
case GSM_PCHAN_TCH_F:
|
2018-02-21 15:58:08 +00:00
|
|
|
switch(cm) {
|
|
|
|
case GSM48_CMODE_SPEECH_V1:
|
|
|
|
feature = BTS_FEAT_SPEECH_F_V1;
|
|
|
|
break;
|
|
|
|
case GSM48_CMODE_SPEECH_EFR:
|
|
|
|
feature = BTS_FEAT_SPEECH_F_EFR;
|
|
|
|
break;
|
|
|
|
case GSM48_CMODE_SPEECH_AMR:
|
|
|
|
feature = BTS_FEAT_SPEECH_F_AMR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Invalid speech codec type => Not supported! */
|
2018-01-25 17:59:42 +00:00
|
|
|
return 0;
|
2018-02-21 15:58:08 +00:00
|
|
|
}
|
2018-09-10 13:15:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GSM_PCHAN_TCH_H:
|
2018-02-21 15:58:08 +00:00
|
|
|
switch(cm) {
|
|
|
|
case GSM48_CMODE_SPEECH_V1:
|
|
|
|
feature = BTS_FEAT_SPEECH_H_V1;
|
|
|
|
break;
|
|
|
|
case GSM48_CMODE_SPEECH_AMR:
|
|
|
|
feature = BTS_FEAT_SPEECH_H_AMR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Invalid speech codec type => Not supported! */
|
|
|
|
return 0;
|
|
|
|
}
|
2018-09-10 13:15:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LOGP(DRSL, LOGL_ERROR, "BTS %u: unhandled pchan %s when checking mode %s\n",
|
|
|
|
bts->nr, gsm_pchan_name(pchan), gsm48_chan_mode_name(cm));
|
|
|
|
return 0;
|
2018-01-25 17:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-02-21 15:58:08 +00:00
|
|
|
/* Check if the feature is supported by this BTS */
|
|
|
|
if (gsm_bts_has_feature(bts, feature))
|
|
|
|
return 1;
|
|
|
|
|
2018-01-25 17:59:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|