2016-10-26 13:19:41 +00:00
|
|
|
/* pcu_sock.c: Connect from PCU via unix domain socket */
|
|
|
|
|
|
|
|
/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* (C) 2009-2012 by Andreas Eversberg <jolly@eversberg.eu>
|
|
|
|
* (C) 2012 by Holger Hans Peter Freyther
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
2020-09-21 16:35:24 +00:00
|
|
|
#include <osmocom/core/byteswap.h>
|
2016-10-26 13:19:41 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
|
|
|
#include <osmocom/core/select.h>
|
|
|
|
#include <osmocom/core/socket.h>
|
|
|
|
#include <osmocom/core/logging.h>
|
|
|
|
#include <osmocom/gsm/l1sap.h>
|
|
|
|
#include <osmocom/gsm/gsm0502.h>
|
2023-01-05 14:43:36 +00:00
|
|
|
#include <osmocom/bsc/abis_nm.h>
|
2016-10-26 13:19:41 +00:00
|
|
|
|
2017-09-04 13:15:32 +00:00
|
|
|
#include <osmocom/bsc/gsm_data.h>
|
|
|
|
#include <osmocom/bsc/pcu_if.h>
|
|
|
|
#include <osmocom/bsc/pcuif_proto.h>
|
|
|
|
#include <osmocom/bsc/signal.h>
|
|
|
|
#include <osmocom/bsc/debug.h>
|
|
|
|
#include <osmocom/bsc/abis_rsl.h>
|
2018-07-24 14:18:15 +00:00
|
|
|
#include <osmocom/bsc/gsm_04_08_rr.h>
|
2020-07-15 18:53:16 +00:00
|
|
|
#include <osmocom/bsc/bts.h>
|
2020-12-01 16:25:28 +00:00
|
|
|
#include <osmocom/bsc/bts_sm.h>
|
2023-02-24 13:50:11 +00:00
|
|
|
#include <osmocom/bsc/timeslot_fsm.h>
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
static int pcu_sock_send(struct gsm_bts *bts, struct msgb *msg);
|
|
|
|
|
|
|
|
static const char *sapi_string[] = {
|
|
|
|
[PCU_IF_SAPI_RACH] = "RACH",
|
|
|
|
[PCU_IF_SAPI_AGCH] = "AGCH",
|
|
|
|
[PCU_IF_SAPI_PCH] = "PCH",
|
|
|
|
[PCU_IF_SAPI_BCCH] = "BCCH",
|
|
|
|
[PCU_IF_SAPI_PDTCH] = "PDTCH",
|
|
|
|
[PCU_IF_SAPI_PRACH] = "PRACH",
|
2023-02-03 10:18:39 +00:00
|
|
|
[PCU_IF_SAPI_PTCCH] = "PTCCH",
|
2023-02-02 15:13:45 +00:00
|
|
|
[PCU_IF_SAPI_PCH_DT] = "PCH_DT",
|
2016-10-26 13:19:41 +00:00
|
|
|
};
|
|
|
|
|
2023-02-24 13:50:11 +00:00
|
|
|
bool pcu_connected(struct gsm_bts *bts)
|
2016-10-26 13:19:41 +00:00
|
|
|
{
|
|
|
|
struct pcu_sock_state *state = bts->pcu_state;
|
|
|
|
|
2023-02-24 13:50:11 +00:00
|
|
|
/* BSC co-located PCU is only supported for Ericsson RBS */
|
|
|
|
if (!is_ericsson_bts(bts))
|
|
|
|
return false;
|
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
if (!state)
|
|
|
|
return false;
|
|
|
|
if (state->conn_bfd.fd <= 0)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCU messages
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Set up an message buffer to package an pcu interface message */
|
|
|
|
struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
|
|
|
|
msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx");
|
|
|
|
if (!msg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
msgb_put(msg, sizeof(struct gsm_pcu_if));
|
|
|
|
pcu_prim = (struct gsm_pcu_if *) msg->data;
|
|
|
|
pcu_prim->msg_type = msg_type;
|
|
|
|
pcu_prim->bts_nr = bts_nr;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2023-01-05 14:51:55 +00:00
|
|
|
/* Check if the timeslot can be utilized as PDCH now
|
|
|
|
* (PDCH is currently active on BTS) */
|
|
|
|
static bool ts_now_usable_as_pdch(const struct gsm_bts_trx_ts *ts)
|
|
|
|
{
|
|
|
|
switch (ts->pchan_is) {
|
|
|
|
case GSM_PCHAN_PDCH:
|
|
|
|
/* NOTE: We currently only support Ericsson RBS as a BSC
|
|
|
|
* co-located BTS. This BTS only supports dynamic channels. */
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-01 12:00:24 +00:00
|
|
|
/* Check if it is possible to use the TS as PDCH (not now, but maybe later) */
|
|
|
|
static bool ts_usable_as_pdch(const struct gsm_bts_trx_ts *ts)
|
|
|
|
{
|
|
|
|
switch (ts->pchan_from_config) {
|
|
|
|
case GSM_PCHAN_TCH_F_PDCH:
|
|
|
|
case GSM_PCHAN_OSMO_DYN:
|
|
|
|
case GSM_PCHAN_PDCH:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-26 21:52:45 +00:00
|
|
|
/* Fill the frequency hopping parameter */
|
|
|
|
static void info_ind_fill_fhp(struct gsm_pcu_if_info_trx_ts *ts_info,
|
|
|
|
const struct gsm_bts_trx_ts *ts)
|
|
|
|
{
|
|
|
|
ts_info->maio = ts->hopping.maio;
|
|
|
|
ts_info->hsn = ts->hopping.hsn;
|
|
|
|
ts_info->hopping = 0x1;
|
|
|
|
|
|
|
|
memcpy(&ts_info->ma, ts->hopping.ma_data, ts->hopping.ma_len);
|
|
|
|
ts_info->ma_bit_len = ts->hopping.ma_len * 8 - ts->hopping.ma.cur_bit;
|
|
|
|
}
|
|
|
|
|
2023-01-05 13:41:13 +00:00
|
|
|
/* Fill the TRX parameter */
|
|
|
|
static void info_ind_fill_trx(struct gsm_pcu_if_info_trx *trx_info, const struct gsm_bts_trx *trx)
|
|
|
|
{
|
|
|
|
unsigned int tn;
|
|
|
|
const struct gsm_bts_trx_ts *ts;
|
|
|
|
|
|
|
|
trx_info->hlayer1 = 0x2342;
|
|
|
|
trx_info->pdch_mask = 0;
|
|
|
|
trx_info->arfcn = trx->arfcn;
|
|
|
|
|
2023-01-05 14:43:36 +00:00
|
|
|
if (trx->mo.nm_state.operational != NM_OPSTATE_ENABLED ||
|
|
|
|
trx->mo.nm_state.administrative != NM_STATE_UNLOCKED) {
|
|
|
|
LOG_TRX(trx, DPCU, LOGL_INFO, "unavailable for PCU (op=%s adm=%s)\n",
|
|
|
|
abis_nm_opstate_name(trx->mo.nm_state.operational),
|
|
|
|
abis_nm_admin_name(trx->mo.nm_state.administrative));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-05 13:41:13 +00:00
|
|
|
for (tn = 0; tn < ARRAY_SIZE(trx->ts); tn++) {
|
|
|
|
ts = &trx->ts[tn];
|
2023-01-05 14:51:55 +00:00
|
|
|
if (ts->mo.nm_state.operational != NM_OPSTATE_ENABLED)
|
|
|
|
continue;
|
|
|
|
if (!ts_now_usable_as_pdch(ts))
|
2023-01-05 13:41:13 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
trx_info->pdch_mask |= (1 << tn);
|
|
|
|
trx_info->ts[tn].tsc =
|
|
|
|
(ts->tsc >= 0) ? ts->tsc : trx->bts->bsic & 7;
|
|
|
|
|
|
|
|
if (ts->hopping.enabled)
|
|
|
|
info_ind_fill_fhp(&trx_info->ts[tn], ts);
|
|
|
|
|
2023-01-05 13:49:07 +00:00
|
|
|
LOG_TRX(trx, DPCU, LOGL_INFO, "PDCH on ts=%u is available (tsc=%u ", ts->nr,
|
|
|
|
trx_info->ts[tn].tsc);
|
2023-01-05 13:41:13 +00:00
|
|
|
if (ts->hopping.enabled)
|
|
|
|
LOGPC(DPCU, LOGL_INFO, "hopping=yes hsn=%u maio=%u ma_bit_len=%u)\n",
|
2023-01-05 13:49:07 +00:00
|
|
|
ts->hopping.hsn, ts->hopping.maio, trx_info->ts[tn].ma_bit_len);
|
2023-01-05 13:41:13 +00:00
|
|
|
else
|
|
|
|
LOGPC(DPCU, LOGL_INFO, "hopping=no arfcn=%u)\n", trx->arfcn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
/* Send BTS properties to the PCU */
|
|
|
|
static int pcu_tx_info_ind(struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
struct gsm_pcu_if_info_ind *info_ind;
|
|
|
|
struct gprs_rlc_cfg *rlcc;
|
2020-12-01 16:25:28 +00:00
|
|
|
struct gsm_bts_sm *bts_sm;
|
|
|
|
struct gsm_gprs_nsvc *nsvc;
|
2016-10-26 13:19:41 +00:00
|
|
|
struct gsm_bts_trx *trx;
|
2023-01-05 13:41:13 +00:00
|
|
|
int i;
|
2016-10-26 13:19:41 +00:00
|
|
|
|
2020-12-01 16:25:28 +00:00
|
|
|
bts_sm = bts->site_mgr;
|
2016-10-26 13:19:41 +00:00
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_INFO, "Sending info for BTS\n");
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
rlcc = &bts->gprs.cell.rlc_cfg;
|
|
|
|
|
|
|
|
msg = pcu_msgb_alloc(PCU_IF_MSG_INFO_IND, bts->nr);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pcu_prim = (struct gsm_pcu_if *) msg->data;
|
|
|
|
info_ind = &pcu_prim->u.info_ind;
|
|
|
|
info_ind->version = PCU_IF_VERSION;
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_ACTIVE;
|
2023-01-03 12:53:38 +00:00
|
|
|
info_ind->flags |= PCU_IF_FLAG_SYSMO;
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
/* RAI */
|
2018-03-05 01:09:40 +00:00
|
|
|
info_ind->mcc = bts->network->plmn.mcc;
|
|
|
|
info_ind->mnc = bts->network->plmn.mnc;
|
2018-02-22 05:15:58 +00:00
|
|
|
info_ind->mnc_3_digits = bts->network->plmn.mnc_3_digits;
|
2016-10-26 13:19:41 +00:00
|
|
|
info_ind->lac = bts->location_area_code;
|
|
|
|
info_ind->rac = bts->gprs.rac;
|
|
|
|
|
|
|
|
/* NSE */
|
2020-12-01 16:25:28 +00:00
|
|
|
info_ind->nsei = bts_sm->gprs.nse.nsei;
|
|
|
|
memcpy(info_ind->nse_timer, bts_sm->gprs.nse.timer, 7);
|
2016-10-26 13:19:41 +00:00
|
|
|
memcpy(info_ind->cell_timer, bts->gprs.cell.timer, 11);
|
|
|
|
|
|
|
|
/* cell attributes */
|
2023-02-01 11:29:33 +00:00
|
|
|
info_ind->bsic = bts->bsic;
|
2016-10-26 13:19:41 +00:00
|
|
|
info_ind->cell_id = bts->cell_identity;
|
|
|
|
info_ind->repeat_time = rlcc->paging.repeat_time;
|
|
|
|
info_ind->repeat_count = rlcc->paging.repeat_count;
|
|
|
|
info_ind->bvci = bts->gprs.cell.bvci;
|
|
|
|
info_ind->t3142 = rlcc->parameter[RLC_T3142];
|
|
|
|
info_ind->t3169 = rlcc->parameter[RLC_T3169];
|
|
|
|
info_ind->t3191 = rlcc->parameter[RLC_T3191];
|
|
|
|
info_ind->t3193_10ms = rlcc->parameter[RLC_T3193];
|
|
|
|
info_ind->t3195 = rlcc->parameter[RLC_T3195];
|
|
|
|
info_ind->n3101 = rlcc->parameter[RLC_N3101];
|
|
|
|
info_ind->n3103 = rlcc->parameter[RLC_N3103];
|
|
|
|
info_ind->n3105 = rlcc->parameter[RLC_N3105];
|
|
|
|
info_ind->cv_countdown = rlcc->parameter[CV_COUNTDOWN];
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_CS1))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_CS1;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_CS2))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_CS2;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_CS3))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_CS3;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_CS4))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_CS4;
|
|
|
|
if (bts->gprs.mode == BTS_GPRS_EGPRS) {
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS1))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS1;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS2))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS2;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS3))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS3;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS4))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS4;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS5))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS5;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS6))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS6;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS7))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS7;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS8))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS8;
|
|
|
|
if (rlcc->cs_mask & (1 << GPRS_MCS9))
|
|
|
|
info_ind->flags |= PCU_IF_FLAG_MCS9;
|
|
|
|
}
|
2022-04-18 08:49:23 +00:00
|
|
|
/* TODO: isn't dl_tbf_ext wrong?: * 10 and no ntohs */
|
2016-10-26 13:19:41 +00:00
|
|
|
info_ind->dl_tbf_ext = rlcc->parameter[T_DL_TBF_EXT];
|
2022-04-18 08:49:23 +00:00
|
|
|
/* TODO: isn't ul_tbf_ext wrong?: * 10 and no ntohs */
|
2016-10-26 13:19:41 +00:00
|
|
|
info_ind->ul_tbf_ext = rlcc->parameter[T_UL_TBF_EXT];
|
|
|
|
info_ind->initial_cs = rlcc->initial_cs;
|
|
|
|
info_ind->initial_mcs = rlcc->initial_mcs;
|
|
|
|
|
|
|
|
/* NSVC */
|
2016-11-17 17:39:36 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(info_ind->nsvci); i++) {
|
2020-12-01 16:25:28 +00:00
|
|
|
nsvc = &bts->site_mgr->gprs.nsvc[i];
|
2020-09-21 16:35:24 +00:00
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
info_ind->nsvci[i] = nsvc->nsvci;
|
|
|
|
info_ind->local_port[i] = nsvc->local_port;
|
2020-09-26 22:04:37 +00:00
|
|
|
switch (nsvc->remote.u.sas.ss_family) {
|
|
|
|
case AF_INET:
|
|
|
|
info_ind->address_type[i] = PCU_IF_ADDR_TYPE_IPV4;
|
|
|
|
info_ind->remote_ip[i].v4 = nsvc->remote.u.sin.sin_addr;
|
2023-01-31 16:57:25 +00:00
|
|
|
info_ind->remote_port[i] = ntohs(nsvc->remote.u.sin.sin_port);
|
2020-09-26 22:04:37 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
info_ind->address_type[i] = PCU_IF_ADDR_TYPE_IPV6;
|
|
|
|
memcpy(&info_ind->remote_ip[i].v6,
|
|
|
|
&nsvc->remote.u.sin6.sin6_addr,
|
|
|
|
sizeof(struct in6_addr));
|
2023-01-31 16:57:25 +00:00
|
|
|
info_ind->remote_port[i] = ntohs(nsvc->remote.u.sin6.sin6_port);
|
2020-09-26 22:04:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info_ind->address_type[i] = PCU_IF_ADDR_TYPE_UNSPEC;
|
|
|
|
break;
|
|
|
|
}
|
2016-10-26 13:19:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 17:39:36 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(info_ind->trx); i++) {
|
2016-11-17 17:10:10 +00:00
|
|
|
trx = gsm_bts_trx_num(bts, i);
|
2016-10-26 13:19:41 +00:00
|
|
|
if (!trx)
|
2016-11-28 23:21:18 +00:00
|
|
|
continue;
|
2023-01-05 12:04:21 +00:00
|
|
|
if (trx->nr >= ARRAY_SIZE(info_ind->trx)) {
|
|
|
|
LOG_TRX(trx, DPCU, LOGL_NOTICE, "PCU interface (version %u) "
|
|
|
|
"cannot handle more than %zu transceivers => skipped\n",
|
|
|
|
PCU_IF_VERSION, ARRAY_SIZE(info_ind->trx));
|
|
|
|
break;
|
|
|
|
}
|
2023-01-05 13:41:13 +00:00
|
|
|
info_ind_fill_trx(&info_ind->trx[trx->nr], trx);
|
2016-10-26 13:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pcu_sock_send(bts, msg);
|
|
|
|
}
|
|
|
|
|
2023-02-01 12:00:24 +00:00
|
|
|
static int pcu_tx_e1_ccu_ind(struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct gsm_bts_trx *trx;
|
|
|
|
|
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list) {
|
|
|
|
struct gsm_pcu_if_e1_ccu_ind *e1_ccu_ind;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (trx->nr >= PCU_IF_NUM_TRX) {
|
|
|
|
LOG_TRX(trx, DPCU, LOGL_NOTICE, "PCU interface (version %u) "
|
|
|
|
"cannot handle more than %u transceivers => skipped\n",
|
|
|
|
PCU_IF_VERSION, PCU_IF_NUM_TRX);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
struct gsm_bts_trx_ts *ts;
|
|
|
|
struct msgb *msg;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
ts = &trx->ts[i];
|
|
|
|
|
|
|
|
if (ts->mo.nm_state.operational != NM_OPSTATE_ENABLED)
|
|
|
|
continue;
|
|
|
|
if (!ts_usable_as_pdch(ts))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
msg = pcu_msgb_alloc(PCU_IF_MSG_E1_CCU_IND, bts->nr);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
pcu_prim = (struct gsm_pcu_if *)msg->data;
|
|
|
|
e1_ccu_ind = &pcu_prim->u.e1_ccu_ind;
|
|
|
|
e1_ccu_ind->ts_nr = ts->nr;
|
|
|
|
e1_ccu_ind->trx_nr = trx->nr;
|
|
|
|
e1_ccu_ind->e1_nr = ts->e1_link.e1_nr;
|
|
|
|
e1_ccu_ind->e1_ts = ts->e1_link.e1_ts;
|
|
|
|
e1_ccu_ind->e1_ts_ss = ts->e1_link.e1_ts_ss;
|
|
|
|
|
|
|
|
LOG_TRX(trx, DPCU, LOGL_INFO, "Sending E1 CCU info for TS %d\n", e1_ccu_ind->ts_nr);
|
|
|
|
rc = pcu_sock_send(bts, msg);
|
|
|
|
if (rc < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-05 17:10:56 +00:00
|
|
|
/* Allow test to overwrite it */
|
|
|
|
__attribute__((weak)) void pcu_info_update(struct gsm_bts *bts)
|
2016-10-26 13:19:41 +00:00
|
|
|
{
|
2023-02-01 12:00:24 +00:00
|
|
|
if (pcu_connected(bts)) {
|
2023-03-09 13:41:53 +00:00
|
|
|
if (bsc_co_located_pcu(bts)) {
|
|
|
|
/* In cases where the CCU is connected via an E1 line, we transmit the connection parameters for the
|
|
|
|
* PDCH before we announce the other BTS related parameters. */
|
|
|
|
if (is_e1_bts(bts))
|
|
|
|
pcu_tx_e1_ccu_ind(bts);
|
|
|
|
pcu_tx_info_ind(bts);
|
|
|
|
}
|
2023-02-01 12:00:24 +00:00
|
|
|
}
|
2016-10-26 13:19:41 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 11:50:56 +00:00
|
|
|
static int pcu_tx_data_ind(struct gsm_bts_trx_ts *ts, uint8_t sapi, uint32_t fn,
|
|
|
|
uint16_t arfcn, uint8_t block_nr, uint8_t *data, uint8_t len,
|
|
|
|
int8_t rssi, uint16_t ber10k, int16_t bto, int16_t lqual)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
struct gsm_pcu_if_data *data_ind;
|
|
|
|
struct gsm_bts *bts = ts->trx->bts;
|
|
|
|
|
|
|
|
LOGP(DPCU, LOGL_DEBUG, "Sending data indication: sapi=%s arfcn=%d block=%d data=%s\n",
|
|
|
|
sapi_string[sapi], arfcn, block_nr, osmo_hexdump(data, len));
|
|
|
|
|
|
|
|
msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_IND, bts->nr);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
pcu_prim = (struct gsm_pcu_if *) msg->data;
|
|
|
|
data_ind = &pcu_prim->u.data_ind;
|
|
|
|
|
|
|
|
data_ind->sapi = sapi;
|
|
|
|
data_ind->rssi = rssi;
|
|
|
|
data_ind->fn = fn;
|
|
|
|
data_ind->arfcn = arfcn;
|
|
|
|
data_ind->trx_nr = ts->trx->nr;
|
|
|
|
data_ind->ts_nr = ts->nr;
|
|
|
|
data_ind->block_nr = block_nr;
|
|
|
|
data_ind->ber10k = ber10k;
|
|
|
|
data_ind->ta_offs_qbits = bto;
|
|
|
|
data_ind->lqual_cb = lqual;
|
|
|
|
if (len)
|
|
|
|
memcpy(data_ind->data, data, len);
|
|
|
|
data_ind->len = len;
|
|
|
|
|
|
|
|
return pcu_sock_send(bts, msg);
|
|
|
|
}
|
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
/* Forward rach indication to PCU */
|
|
|
|
int pcu_tx_rach_ind(struct gsm_bts *bts, int16_t qta, uint16_t ra, uint32_t fn,
|
|
|
|
uint8_t is_11bit, enum ph_burst_type burst_type)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
struct gsm_pcu_if_rach_ind *rach_ind;
|
|
|
|
|
|
|
|
/* Bail if no PCU is connected */
|
|
|
|
if (!pcu_connected(bts)) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DRSL, LOGL_ERROR, "CHAN RQD(GPRS) but PCU not connected!\n");
|
2016-10-26 13:19:41 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_INFO, "Sending RACH indication: qta=%d, ra=%d, "
|
2016-10-26 13:19:41 +00:00
|
|
|
"fn=%d\n", qta, ra, fn);
|
|
|
|
|
|
|
|
msg = pcu_msgb_alloc(PCU_IF_MSG_RACH_IND, bts->nr);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
pcu_prim = (struct gsm_pcu_if *) msg->data;
|
|
|
|
rach_ind = &pcu_prim->u.rach_ind;
|
|
|
|
|
|
|
|
rach_ind->sapi = PCU_IF_SAPI_RACH;
|
|
|
|
rach_ind->ra = ra;
|
|
|
|
rach_ind->qta = qta;
|
|
|
|
rach_ind->fn = fn;
|
|
|
|
rach_ind->is_11bit = is_11bit;
|
|
|
|
rach_ind->burst_type = burst_type;
|
|
|
|
|
|
|
|
return pcu_sock_send(bts, msg);
|
|
|
|
}
|
|
|
|
|
2016-12-02 18:04:34 +00:00
|
|
|
/* Confirm the sending of an immediate assignment to the pcu */
|
|
|
|
int pcu_tx_imm_ass_sent(struct gsm_bts *bts, uint32_t tlli)
|
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
struct gsm_pcu_if_data_cnf_dt *data_cnf_dt;
|
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_INFO, "Sending PCH confirm with direct TLLI\n");
|
2016-12-02 18:04:34 +00:00
|
|
|
|
|
|
|
msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_CNF_DT, bts->nr);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
pcu_prim = (struct gsm_pcu_if *) msg->data;
|
|
|
|
data_cnf_dt = &pcu_prim->u.data_cnf_dt;
|
|
|
|
|
|
|
|
data_cnf_dt->sapi = PCU_IF_SAPI_PCH;
|
|
|
|
data_cnf_dt->tlli = tlli;
|
|
|
|
|
|
|
|
return pcu_sock_send(bts, msg);
|
|
|
|
}
|
|
|
|
|
2019-11-13 21:10:41 +00:00
|
|
|
/* we need to decode the raw RR paging message (see PCU code
|
2016-11-17 19:54:47 +00:00
|
|
|
* Encoding::write_paging_request) and extract the mobile identity
|
|
|
|
* (P-TMSI) from it */
|
|
|
|
static int pcu_rx_rr_paging(struct gsm_bts *bts, uint8_t paging_group,
|
|
|
|
const uint8_t *raw_rr_msg)
|
|
|
|
{
|
2017-01-17 13:46:56 +00:00
|
|
|
struct gsm48_paging1 *p1 = (struct gsm48_paging1 *) raw_rr_msg;
|
2016-11-17 19:54:47 +00:00
|
|
|
uint8_t chan_needed;
|
2020-05-29 01:53:59 +00:00
|
|
|
struct osmo_mobile_identity mi;
|
2016-11-17 19:54:47 +00:00
|
|
|
int rc;
|
|
|
|
|
2017-01-17 13:46:56 +00:00
|
|
|
switch (p1->msg_type) {
|
2016-11-17 19:54:47 +00:00
|
|
|
case GSM48_MT_RR_PAG_REQ_1:
|
|
|
|
chan_needed = (p1->cneed2 << 2) | p1->cneed1;
|
2020-05-29 01:53:59 +00:00
|
|
|
rc = osmo_mobile_identity_decode(&mi, p1->data+1, p1->data[0], false);
|
|
|
|
if (rc) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "PCU Sends paging "
|
|
|
|
"request type %02x (chan_needed=%02x): Unable to decode Mobile Identity\n",
|
2020-05-29 01:53:59 +00:00
|
|
|
p1->msg_type, chan_needed);
|
|
|
|
rc = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "PCU Sends paging "
|
|
|
|
"request type %02x (chan_needed=%02x, mi=%s)\n",
|
2020-05-29 01:53:59 +00:00
|
|
|
p1->msg_type, chan_needed, osmo_mobile_identity_to_str_c(OTC_SELECT, &mi));
|
2017-01-17 13:46:56 +00:00
|
|
|
/* NOTE: We will have to add 2 to mi_len and subtract 2 from
|
|
|
|
* the mi pointer because rsl_paging_cmd() will perform the
|
|
|
|
* reverse operations. This is because rsl_paging_cmd() is
|
|
|
|
* normally expected to chop off the element identifier (0xC0)
|
|
|
|
* and the length field. In our parameter, we do not have
|
|
|
|
* those fields included. */
|
2020-05-29 01:53:59 +00:00
|
|
|
rc = rsl_paging_cmd(bts, paging_group, &mi, chan_needed, true);
|
2016-11-17 19:54:47 +00:00
|
|
|
break;
|
|
|
|
case GSM48_MT_RR_PAG_REQ_2:
|
|
|
|
case GSM48_MT_RR_PAG_REQ_3:
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "PCU Sends unsupported paging "
|
2017-01-17 13:46:56 +00:00
|
|
|
"request type %02x\n", p1->msg_type);
|
|
|
|
rc = -EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "PCU Sends unknown paging "
|
2017-01-17 13:46:56 +00:00
|
|
|
"request type %02x\n", p1->msg_type);
|
2016-11-17 19:54:47 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2023-01-31 15:16:01 +00:00
|
|
|
/* Helper function for pcu_rx_data_req() to extract paging group info (3 byte) */
|
|
|
|
static uint8_t extract_paging_group(struct gsm_bts *bts, uint8_t *data)
|
|
|
|
{
|
|
|
|
char imsi_digit_buf[4];
|
|
|
|
uint8_t pag_grp;
|
|
|
|
|
|
|
|
/* the first three bytes are the last three digits of the IMSI, which we need to compute the paging group */
|
|
|
|
imsi_digit_buf[0] = data[0];
|
|
|
|
imsi_digit_buf[1] = data[1];
|
|
|
|
imsi_digit_buf[2] = data[2];
|
|
|
|
imsi_digit_buf[3] = '\0';
|
|
|
|
|
|
|
|
pag_grp = gsm0502_calc_paging_group(&bts->si_common.chan_desc,
|
|
|
|
str_to_imsi(imsi_digit_buf));
|
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_DEBUG, "Calculating paging group: imsi_digit_buf=%s ==> pag_grp=0x%02x\n",
|
|
|
|
imsi_digit_buf, pag_grp);
|
2023-01-31 15:16:01 +00:00
|
|
|
|
|
|
|
return pag_grp;
|
|
|
|
}
|
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
static int pcu_rx_data_req(struct gsm_bts *bts, uint8_t msg_type,
|
|
|
|
struct gsm_pcu_if_data *data_req)
|
|
|
|
{
|
2016-11-17 19:54:47 +00:00
|
|
|
uint8_t pag_grp;
|
2016-10-26 13:19:41 +00:00
|
|
|
int rc = 0;
|
2023-02-27 19:14:08 +00:00
|
|
|
struct gsm_pcu_if_pch_dt *pch_dt;
|
2016-10-26 13:19:41 +00:00
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_DEBUG, "Data request received: sapi=%s arfcn=%d "
|
2016-10-26 13:19:41 +00:00
|
|
|
"block=%d data=%s\n", sapi_string[data_req->sapi],
|
|
|
|
data_req->arfcn, data_req->block_nr,
|
|
|
|
osmo_hexdump(data_req->data, data_req->len));
|
|
|
|
|
|
|
|
switch (data_req->sapi) {
|
|
|
|
case PCU_IF_SAPI_PCH:
|
2023-02-03 11:14:02 +00:00
|
|
|
/* Extract 3 byte paging group */
|
|
|
|
pag_grp = extract_paging_group(bts, data_req->data);
|
2016-11-17 19:54:47 +00:00
|
|
|
pcu_rx_rr_paging(bts, pag_grp, data_req->data+3);
|
2016-10-26 13:19:41 +00:00
|
|
|
break;
|
|
|
|
case PCU_IF_SAPI_AGCH:
|
2023-03-06 10:15:22 +00:00
|
|
|
if (rsl_imm_assign_cmd(bts, data_req->len, data_req->data))
|
2016-10-26 13:19:41 +00:00
|
|
|
rc = -EIO;
|
|
|
|
break;
|
2023-02-02 15:13:45 +00:00
|
|
|
case PCU_IF_SAPI_PCH_DT:
|
2023-01-31 15:16:01 +00:00
|
|
|
/* DT = direct TLLI. A tlli is prefixed so that the BSC/BTS can confirm the sending of the downlink
|
|
|
|
* IMMEDIATE ASSIGNMENT towards the PCU using this TLLI as a reference. */
|
2016-12-02 17:27:01 +00:00
|
|
|
|
2023-02-27 19:14:08 +00:00
|
|
|
if (data_req->len < sizeof(struct gsm_pcu_if_pch_dt)) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Received PCU data request with invalid/small length %d\n",
|
|
|
|
data_req->len);
|
2016-12-02 17:27:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-01-31 15:16:01 +00:00
|
|
|
|
2023-02-27 19:14:08 +00:00
|
|
|
pch_dt = (struct gsm_pcu_if_pch_dt *)data_req->data;
|
|
|
|
pag_grp = gsm0502_calc_paging_group(&bts->si_common.chan_desc, str_to_imsi(pch_dt->imsi));
|
2016-12-02 17:27:01 +00:00
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_DEBUG, "PCU Sends immediate assignment via PCH (TLLI=0x%08x, IMSI=%s, Paging group=0x%02x)\n",
|
|
|
|
pch_dt->tlli, pch_dt->imsi, pag_grp);
|
2023-01-31 15:16:01 +00:00
|
|
|
|
|
|
|
/* NOTE: Sending an IMMEDIATE ASSIGNMENT via PCH became necessary with GPRS in order to be able to
|
|
|
|
* assign downlink TBFs directly through the paging channel. However, this method never became part
|
|
|
|
* of the RSL specs. This means that each BTS vendor has to come up with a proprietary method. At
|
|
|
|
* the moment we only support Ericsson RBS here. */
|
2023-03-09 13:39:31 +00:00
|
|
|
if (is_ericsson_bts(bts)) {
|
2023-02-27 19:14:08 +00:00
|
|
|
rc = rsl_ericsson_imm_assign_cmd(bts, pch_dt->tlli, sizeof(pch_dt->data),
|
|
|
|
pch_dt->data, pag_grp);
|
2023-01-31 15:16:01 +00:00
|
|
|
} else {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "BTS model does not support sending immediate assignment via PCH!\n");
|
2023-01-31 15:16:01 +00:00
|
|
|
rc = -ENOTSUP;
|
|
|
|
}
|
2016-12-02 17:27:01 +00:00
|
|
|
|
2023-03-06 10:15:22 +00:00
|
|
|
if (rc)
|
2016-12-02 17:27:01 +00:00
|
|
|
rc = -EIO;
|
|
|
|
break;
|
2016-10-26 13:19:41 +00:00
|
|
|
default:
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Received PCU data request with "
|
2016-10-26 13:19:41 +00:00
|
|
|
"unsupported sapi %d\n", data_req->sapi);
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2023-02-01 11:50:56 +00:00
|
|
|
static int pcu_tx_si(const struct gsm_bts *bts, enum osmo_sysinfo_type si_type, bool enable)
|
|
|
|
{
|
|
|
|
/* the SI is per-BTS so it doesn't matter which TRX we use */
|
|
|
|
struct gsm_bts_trx *trx = bts->c0;
|
|
|
|
|
|
|
|
uint8_t si_buf[GSM_MACBLOCK_LEN];
|
|
|
|
uint8_t len;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
memcpy(si_buf, GSM_BTS_SI(bts, si_type), GSM_MACBLOCK_LEN);
|
|
|
|
len = GSM_MACBLOCK_LEN;
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_DEBUG, "Updating SI%s to PCU: %s\n",
|
2023-02-01 11:50:56 +00:00
|
|
|
get_value_string(osmo_sitype_strs, si_type),
|
|
|
|
osmo_hexdump_nospc(si_buf, GSM_MACBLOCK_LEN));
|
|
|
|
} else {
|
|
|
|
si_buf[0] = si_type;
|
|
|
|
len = 1;
|
|
|
|
|
|
|
|
/* Note: SI13 is the only system information type that is revked
|
|
|
|
* by just sending a completely empty message. This is due to
|
|
|
|
* historical reasons */
|
|
|
|
if (si_type != SYSINFO_TYPE_13)
|
|
|
|
len = 0;
|
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_DEBUG, "Revoking SI%s from PCU\n",
|
|
|
|
get_value_string(osmo_sitype_strs, si_buf[0]));
|
2023-02-01 11:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The low-level data like FN, ARFCN etc will be ignored but we have to
|
|
|
|
* set lqual high enough to bypass the check at lower levels */
|
|
|
|
rc = pcu_tx_data_ind(&trx->ts[0], PCU_IF_SAPI_BCCH, 0, 0, 0, si_buf, len,
|
|
|
|
0, 0, 0, INT16_MAX);
|
|
|
|
if (rc < 0)
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_NOTICE, "Failed to send SI%s to PCU: rc=%d\n",
|
|
|
|
get_value_string(osmo_sitype_strs, si_type), rc);
|
2023-02-01 11:50:56 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcu_tx_si_all(struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
const enum osmo_sysinfo_type si_types[] = { SYSINFO_TYPE_1, SYSINFO_TYPE_2, SYSINFO_TYPE_3, SYSINFO_TYPE_13 };
|
|
|
|
unsigned int i;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(si_types); i++) {
|
|
|
|
if (GSM_BTS_HAS_SI(bts, si_types[i])) {
|
|
|
|
rc = pcu_tx_si(bts, si_types[i], true);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
} else {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_INFO,
|
|
|
|
"SI%s is not available on PCU connection\n",
|
|
|
|
get_value_string(osmo_sitype_strs, si_types[i]));
|
2023-02-01 11:50:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcu_rx_txt_ind(struct gsm_bts *bts,
|
|
|
|
const struct gsm_pcu_if_txt_ind *txt)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
switch (txt->type) {
|
|
|
|
case PCU_VERSION:
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_INFO, "OsmoPCU version %s connected\n",
|
2023-02-01 11:50:56 +00:00
|
|
|
txt->text);
|
|
|
|
rc = pcu_tx_si_all(bts);
|
|
|
|
if (rc < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
2023-02-24 15:01:54 +00:00
|
|
|
case PCU_OML_ALERT:
|
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "PCU external alarm: %s\n", txt->text);
|
|
|
|
break;
|
2023-02-01 11:50:56 +00:00
|
|
|
default:
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Unknown TXT_IND type %u received\n",
|
2023-02-01 11:50:56 +00:00
|
|
|
txt->type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-15 10:03:43 +00:00
|
|
|
#define CHECK_IF_MSG_SIZE(prim_len, prim_msg) \
|
|
|
|
do { \
|
|
|
|
size_t _len = PCUIF_HDR_SIZE + sizeof(prim_msg); \
|
|
|
|
if (prim_len < _len) { \
|
|
|
|
LOGP(DPCU, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive %s " \
|
|
|
|
"size is %zu, discarding\n", prim_len, #prim_msg, _len); \
|
|
|
|
return -EINVAL; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2016-10-26 13:19:41 +00:00
|
|
|
static int pcu_rx(struct gsm_network *net, uint8_t msg_type,
|
2022-09-15 10:03:43 +00:00
|
|
|
struct gsm_pcu_if *pcu_prim, size_t prim_len)
|
2016-10-26 13:19:41 +00:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct gsm_bts *bts;
|
|
|
|
|
|
|
|
/* FIXME: allow multiple BTS */
|
|
|
|
bts = llist_entry(net->bts_list.next, struct gsm_bts, list);
|
|
|
|
|
|
|
|
switch (msg_type) {
|
|
|
|
case PCU_IF_MSG_DATA_REQ:
|
|
|
|
case PCU_IF_MSG_PAG_REQ:
|
2022-09-15 10:03:43 +00:00
|
|
|
CHECK_IF_MSG_SIZE(prim_len, pcu_prim->u.data_req);
|
2016-10-26 13:19:41 +00:00
|
|
|
rc = pcu_rx_data_req(bts, msg_type, &pcu_prim->u.data_req);
|
|
|
|
break;
|
2023-02-01 11:50:56 +00:00
|
|
|
case PCU_IF_MSG_TXT_IND:
|
|
|
|
CHECK_IF_MSG_SIZE(prim_len, pcu_prim->u.txt_ind);
|
|
|
|
rc = pcu_rx_txt_ind(bts, &pcu_prim->u.txt_ind);
|
|
|
|
break;
|
2016-10-26 13:19:41 +00:00
|
|
|
default:
|
2019-07-16 19:13:12 +00:00
|
|
|
LOGP(DPCU, LOGL_ERROR, "Received unknown PCU msg type %d\n",
|
2016-10-26 13:19:41 +00:00
|
|
|
msg_type);
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCU socket interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int pcu_sock_send(struct gsm_bts *bts, struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct pcu_sock_state *state = bts->pcu_state;
|
|
|
|
struct osmo_fd *conn_bfd;
|
|
|
|
struct gsm_pcu_if *pcu_prim = (struct gsm_pcu_if *) msg->data;
|
|
|
|
|
|
|
|
if (!state) {
|
|
|
|
if (pcu_prim->msg_type != PCU_IF_MSG_TIME_IND)
|
|
|
|
LOGP(DPCU, LOGL_INFO, "PCU socket not created, "
|
|
|
|
"dropping message\n");
|
|
|
|
msgb_free(msg);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
conn_bfd = &state->conn_bfd;
|
|
|
|
if (conn_bfd->fd <= 0) {
|
|
|
|
if (pcu_prim->msg_type != PCU_IF_MSG_TIME_IND)
|
|
|
|
LOGP(DPCU, LOGL_NOTICE, "PCU socket not connected, "
|
|
|
|
"dropping message\n");
|
|
|
|
msgb_free(msg);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
msgb_enqueue(&state->upqueue, msg);
|
2020-10-18 20:25:26 +00:00
|
|
|
osmo_fd_write_enable(conn_bfd);
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcu_sock_close(struct pcu_sock_state *state)
|
|
|
|
{
|
|
|
|
struct osmo_fd *bfd = &state->conn_bfd;
|
|
|
|
struct gsm_bts *bts;
|
|
|
|
struct gsm_bts_trx *trx;
|
2023-02-24 13:50:11 +00:00
|
|
|
int j;
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
/* FIXME: allow multiple BTS */
|
|
|
|
bts = llist_entry(state->net->bts_list.next, struct gsm_bts, list);
|
|
|
|
|
|
|
|
LOGP(DPCU, LOGL_NOTICE, "PCU socket has LOST connection\n");
|
|
|
|
|
2023-03-14 10:26:55 +00:00
|
|
|
osmo_fd_unregister(bfd);
|
2016-10-26 13:19:41 +00:00
|
|
|
close(bfd->fd);
|
|
|
|
bfd->fd = -1;
|
|
|
|
|
|
|
|
/* re-enable the generation of ACCEPT for new connections */
|
2020-10-18 20:25:26 +00:00
|
|
|
osmo_fd_read_enable(&state->listen_bfd);
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* remove si13, ... */
|
|
|
|
bts->si_valid &= ~(1 << SYSINFO_TYPE_13);
|
|
|
|
osmo_signal_dispatch(SS_GLOBAL, S_NEW_SYSINFO, bts);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* release PDCH */
|
2023-02-24 13:50:11 +00:00
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list) {
|
|
|
|
for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
|
|
|
|
struct gsm_bts_trx_ts *ts = &trx->ts[j];
|
|
|
|
/* BSC co-located PCU applies only to Ericsson RBS, which supports only GSM_PCHAN_OSMO_DYN.
|
|
|
|
* So we need to deact only on this pchan kind. */
|
2016-10-26 13:19:41 +00:00
|
|
|
if (ts->mo.nm_state.operational == NM_OPSTATE_ENABLED
|
2023-02-24 13:50:11 +00:00
|
|
|
&& ts->pchan_on_init == GSM_PCHAN_OSMO_DYN) {
|
|
|
|
ts_pdch_deact(ts);
|
2016-10-26 13:19:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush the queue */
|
|
|
|
while (!llist_empty(&state->upqueue)) {
|
|
|
|
struct msgb *msg = msgb_dequeue(&state->upqueue);
|
|
|
|
msgb_free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcu_sock_read(struct osmo_fd *bfd)
|
|
|
|
{
|
|
|
|
struct pcu_sock_state *state = (struct pcu_sock_state *)bfd->data;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
struct msgb *msg;
|
|
|
|
int rc;
|
|
|
|
|
2022-09-15 10:19:43 +00:00
|
|
|
msg = msgb_alloc(sizeof(*pcu_prim) + 1000, "pcu_sock_rx");
|
2016-10-26 13:19:41 +00:00
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pcu_prim = (struct gsm_pcu_if *) msg->tail;
|
|
|
|
|
|
|
|
rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
|
|
|
|
if (rc == 0)
|
|
|
|
goto close;
|
|
|
|
|
|
|
|
if (rc < 0) {
|
2022-09-15 10:10:32 +00:00
|
|
|
if (errno == EAGAIN) {
|
|
|
|
msgb_free(msg);
|
2016-10-26 13:19:41 +00:00
|
|
|
return 0;
|
2022-09-15 10:10:32 +00:00
|
|
|
}
|
2016-10-26 13:19:41 +00:00
|
|
|
goto close;
|
|
|
|
}
|
|
|
|
|
2022-09-15 10:03:43 +00:00
|
|
|
if (rc < PCUIF_HDR_SIZE) {
|
|
|
|
LOGP(DPCU, LOGL_ERROR, "Received %d bytes on PCU Socket, but primitive hdr size "
|
|
|
|
"is %zu, discarding\n", rc, PCUIF_HDR_SIZE);
|
|
|
|
msgb_free(msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = pcu_rx(state->net, pcu_prim->msg_type, pcu_prim, rc);
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
/* as we always synchronously process the message in pcu_rx() and
|
|
|
|
* its callbacks, we can free the message here. */
|
|
|
|
msgb_free(msg);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
close:
|
|
|
|
msgb_free(msg);
|
|
|
|
pcu_sock_close(state);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcu_sock_write(struct osmo_fd *bfd)
|
|
|
|
{
|
|
|
|
struct pcu_sock_state *state = bfd->data;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
while (!llist_empty(&state->upqueue)) {
|
|
|
|
struct msgb *msg, *msg2;
|
|
|
|
struct gsm_pcu_if *pcu_prim;
|
|
|
|
|
|
|
|
/* peek at the beginning of the queue */
|
|
|
|
msg = llist_entry(state->upqueue.next, struct msgb, list);
|
|
|
|
pcu_prim = (struct gsm_pcu_if *)msg->data;
|
|
|
|
|
2020-10-18 20:25:26 +00:00
|
|
|
osmo_fd_write_disable(bfd);
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
/* bug hunter 8-): maybe someone forgot msgb_put(...) ? */
|
|
|
|
if (!msgb_length(msg)) {
|
|
|
|
LOGP(DPCU, LOGL_ERROR, "message type (%d) with ZERO "
|
|
|
|
"bytes!\n", pcu_prim->msg_type);
|
|
|
|
goto dontsend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to send it over the socket */
|
|
|
|
rc = write(bfd->fd, msgb_data(msg), msgb_length(msg));
|
|
|
|
if (rc == 0)
|
|
|
|
goto close;
|
|
|
|
if (rc < 0) {
|
|
|
|
if (errno == EAGAIN) {
|
2020-10-18 20:25:26 +00:00
|
|
|
osmo_fd_write_enable(bfd);
|
2016-10-26 13:19:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto close;
|
|
|
|
}
|
|
|
|
|
|
|
|
dontsend:
|
|
|
|
/* _after_ we send it, we can deueue */
|
|
|
|
msg2 = msgb_dequeue(&state->upqueue);
|
|
|
|
assert(msg == msg2);
|
|
|
|
msgb_free(msg);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
close:
|
|
|
|
pcu_sock_close(state);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pcu_sock_cb(struct osmo_fd *bfd, unsigned int flags)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2020-05-09 17:17:12 +00:00
|
|
|
if (flags & OSMO_FD_READ)
|
2016-10-26 13:19:41 +00:00
|
|
|
rc = pcu_sock_read(bfd);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2020-05-09 17:17:12 +00:00
|
|
|
if (flags & OSMO_FD_WRITE)
|
2016-10-26 13:19:41 +00:00
|
|
|
rc = pcu_sock_write(bfd);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-11-13 21:10:41 +00:00
|
|
|
/* accept connection coming from PCU */
|
2016-10-26 13:19:41 +00:00
|
|
|
static int pcu_sock_accept(struct osmo_fd *bfd, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct pcu_sock_state *state = (struct pcu_sock_state *)bfd->data;
|
|
|
|
struct osmo_fd *conn_bfd = &state->conn_bfd;
|
|
|
|
struct sockaddr_un un_addr;
|
2023-02-24 13:50:11 +00:00
|
|
|
struct gsm_bts *bts;
|
|
|
|
struct gsm_bts_trx *trx;
|
|
|
|
int j;
|
2016-10-26 13:19:41 +00:00
|
|
|
socklen_t len;
|
2023-03-06 13:26:31 +00:00
|
|
|
int fd;
|
2016-10-26 13:19:41 +00:00
|
|
|
|
2023-02-24 13:50:11 +00:00
|
|
|
/* FIXME: allow multiple BTS */
|
|
|
|
bts = llist_entry(state->net->bts_list.next, struct gsm_bts, list);
|
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
len = sizeof(un_addr);
|
2023-03-06 13:35:07 +00:00
|
|
|
fd = accept(bfd->fd, (struct sockaddr *)&un_addr, &len);
|
2023-03-06 13:26:31 +00:00
|
|
|
if (fd < 0) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Failed to accept a new connection\n");
|
2016-10-26 13:19:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn_bfd->fd >= 0) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_NOTICE, "PCU connects but we already have another active connection ?!?\n");
|
2016-10-26 13:19:41 +00:00
|
|
|
/* We already have one PCU connected, this is all we support */
|
2020-10-18 20:25:26 +00:00
|
|
|
osmo_fd_read_disable(&state->listen_bfd);
|
2023-03-06 13:26:31 +00:00
|
|
|
close(fd);
|
2016-10-26 13:19:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-03-06 13:26:31 +00:00
|
|
|
osmo_fd_setup(conn_bfd, fd, OSMO_FD_READ, pcu_sock_cb, state, 0);
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
if (osmo_fd_register(conn_bfd) != 0) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Failed to register new connection fd\n");
|
2016-10-26 13:19:41 +00:00
|
|
|
close(conn_bfd->fd);
|
|
|
|
conn_bfd->fd = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_NOTICE, "PCU socket connected to external PCU\n");
|
2016-10-26 13:19:41 +00:00
|
|
|
|
2023-02-24 13:50:11 +00:00
|
|
|
/* activate PDCH */
|
|
|
|
llist_for_each_entry(trx, &bts->trx_list, list) {
|
|
|
|
for (j = 0; j < ARRAY_SIZE(trx->ts); j++) {
|
|
|
|
struct gsm_bts_trx_ts *ts = &trx->ts[j];
|
|
|
|
/* (See comment in pcu_sock_close above) */
|
|
|
|
if (ts->mo.nm_state.operational == NM_OPSTATE_ENABLED
|
|
|
|
&& ts->pchan_on_init == GSM_PCHAN_OSMO_DYN) {
|
|
|
|
ts_pdch_act(ts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open connection to PCU */
|
|
|
|
int pcu_sock_init(const char *path, struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct pcu_sock_state *state;
|
|
|
|
struct osmo_fd *bfd;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
state = talloc_zero(NULL, struct pcu_sock_state);
|
|
|
|
if (!state)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
INIT_LLIST_HEAD(&state->upqueue);
|
|
|
|
state->net = bts->network;
|
|
|
|
state->conn_bfd.fd = -1;
|
|
|
|
|
|
|
|
bfd = &state->listen_bfd;
|
|
|
|
|
2020-10-18 20:19:28 +00:00
|
|
|
rc = osmo_sock_unix_init(SOCK_SEQPACKET, 0, path, OSMO_SOCK_F_BIND);
|
|
|
|
if (rc < 0) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Could not create unix socket: %s\n",
|
2016-10-26 13:19:41 +00:00
|
|
|
strerror(errno));
|
|
|
|
talloc_free(state);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:19:28 +00:00
|
|
|
osmo_fd_setup(bfd, rc, OSMO_FD_READ, pcu_sock_accept, state, 0);
|
2016-10-26 13:19:41 +00:00
|
|
|
|
|
|
|
rc = osmo_fd_register(bfd);
|
|
|
|
if (rc < 0) {
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_ERROR, "Could not register listen fd: %d\n",
|
2016-10-26 13:19:41 +00:00
|
|
|
rc);
|
|
|
|
close(bfd->fd);
|
|
|
|
talloc_free(state);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2023-02-27 19:41:45 +00:00
|
|
|
LOG_BTS(bts, DPCU, LOGL_INFO, "Started listening on PCU socket: %s\n", path);
|
2018-06-15 08:34:10 +00:00
|
|
|
|
2016-10-26 13:19:41 +00:00
|
|
|
bts->pcu_state = state;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close connection to PCU */
|
|
|
|
void pcu_sock_exit(struct gsm_bts *bts)
|
|
|
|
{
|
|
|
|
struct pcu_sock_state *state = bts->pcu_state;
|
|
|
|
struct osmo_fd *bfd, *conn_bfd;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
conn_bfd = &state->conn_bfd;
|
|
|
|
if (conn_bfd->fd > 0)
|
|
|
|
pcu_sock_close(state);
|
|
|
|
bfd = &state->listen_bfd;
|
|
|
|
osmo_fd_unregister(bfd);
|
2023-03-20 09:26:07 +00:00
|
|
|
close(bfd->fd);
|
2016-10-26 13:19:41 +00:00
|
|
|
talloc_free(state);
|
|
|
|
bts->pcu_state = NULL;
|
|
|
|
}
|