2010-04-30 18:26:32 +00:00
|
|
|
/* NS-over-IP proxy */
|
|
|
|
|
|
|
|
/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
2013-10-23 09:24:17 +00:00
|
|
|
* (C) 2010-2013 by On-Waves
|
|
|
|
* (C) 2013 by Holger Hans Peter Freyther
|
2010-04-30 18:26:32 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +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
|
2010-04-30 18:26:32 +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
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-04-30 18:26:32 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +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/>.
|
2010-04-30 18:26:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
2010-05-11 08:15:42 +00:00
|
|
|
#include <arpa/inet.h>
|
2014-06-06 16:49:23 +00:00
|
|
|
#include <time.h>
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
|
|
|
#include <osmocom/core/select.h>
|
2013-10-18 12:34:55 +00:00
|
|
|
#include <osmocom/core/rate_ctr.h>
|
|
|
|
|
2012-06-16 06:59:56 +00:00
|
|
|
#include <osmocom/gprs/gprs_ns.h>
|
|
|
|
#include <osmocom/gprs/gprs_bssgp.h>
|
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
#include <osmocom/gsm/gsm_utils.h>
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
#include <openbsc/signal.h>
|
|
|
|
#include <openbsc/debug.h>
|
2014-08-19 10:21:01 +00:00
|
|
|
#include <openbsc/gprs_gb_parse.h>
|
2010-05-03 16:54:58 +00:00
|
|
|
#include <openbsc/gb_proxy.h>
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
#include <openbsc/gprs_llc.h>
|
|
|
|
#include <openbsc/gsm_04_08.h>
|
|
|
|
#include <openbsc/gsm_04_08_gprs.h>
|
2014-08-04 09:52:52 +00:00
|
|
|
#include <openbsc/gprs_utils.h>
|
2014-05-19 08:14:58 +00:00
|
|
|
|
2013-10-18 12:34:55 +00:00
|
|
|
static const struct rate_ctr_desc global_ctr_description[] = {
|
|
|
|
{ "inv-bvci", "Invalid BVC Identifier " },
|
2014-06-02 08:49:00 +00:00
|
|
|
{ "inv-lai", "Invalid Location Area Identifier" },
|
|
|
|
{ "inv-rai", "Invalid Routing Area Identifier " },
|
2013-10-18 12:34:55 +00:00
|
|
|
{ "inv-nsei", "No BVC established for NSEI " },
|
|
|
|
{ "proto-err.bss", "BSSGP protocol error (BSS )" },
|
|
|
|
{ "proto-err.sgsn", "BSSGP protocol error (SGSN)" },
|
|
|
|
{ "not-supp.bss", "Feature not supported (BSS )" },
|
|
|
|
{ "not-supp.sgsn", "Feature not supported (SGSN)" },
|
|
|
|
{ "restart.sgsn", "Restarted RESET procedure (SGSN)" },
|
|
|
|
{ "tx-err.sgsn", "NS Transmission error (SGSN)" },
|
|
|
|
{ "error", "Other error " },
|
2014-05-27 11:49:04 +00:00
|
|
|
{ "mod-peer-err", "Patch error: no peer " },
|
2013-10-18 12:34:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct rate_ctr_group_desc global_ctrg_desc = {
|
|
|
|
.group_name_prefix = "gbproxy.global",
|
|
|
|
.group_description = "GBProxy Global Statistics",
|
|
|
|
.num_ctr = ARRAY_SIZE(global_ctr_description),
|
|
|
|
.ctr_desc = global_ctr_description,
|
|
|
|
};
|
|
|
|
|
2014-08-22 15:10:01 +00:00
|
|
|
static int gbprox_relay2peer(struct msgb *old_msg, struct gbproxy_peer *peer,
|
|
|
|
uint16_t ns_bvci);
|
|
|
|
static int gbprox_relay2sgsn(struct gbproxy_config *cfg, struct msgb *old_msg,
|
2014-08-26 12:47:15 +00:00
|
|
|
uint16_t ns_bvci, uint16_t sgsn_nsei);
|
2014-09-22 11:30:46 +00:00
|
|
|
static void gbproxy_reset_imsi_acquisition(struct gbproxy_link_info* link_info);
|
2014-08-22 15:10:01 +00:00
|
|
|
|
2014-08-04 09:35:32 +00:00
|
|
|
static int check_peer_nsei(struct gbproxy_peer *peer, uint16_t nsei)
|
2013-10-18 12:34:55 +00:00
|
|
|
{
|
|
|
|
if (peer->nsei != nsei) {
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "Peer entry doesn't match current NSEI "
|
|
|
|
"BVCI=%u via NSEI=%u (expected NSEI=%u)\n",
|
|
|
|
peer->bvci, nsei, peer->nsei);
|
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_INV_NSEI]);
|
2013-10-24 10:48:56 +00:00
|
|
|
return 0;
|
2013-10-18 12:34:55 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 10:48:56 +00:00
|
|
|
return 1;
|
2013-10-18 12:34:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-03 17:05:10 +00:00
|
|
|
/* strip off the NS header */
|
|
|
|
static void strip_ns_hdr(struct msgb *msg)
|
|
|
|
{
|
|
|
|
int strip_len = msgb_bssgph(msg) - msg->data;
|
|
|
|
msgb_pull(msg, strip_len);
|
|
|
|
}
|
|
|
|
|
2014-08-22 15:10:01 +00:00
|
|
|
/* Transmit Chapter 9.2.10 Identity Request */
|
|
|
|
static void gprs_put_identity_req(struct msgb *msg, uint8_t id_type)
|
|
|
|
{
|
|
|
|
struct gsm48_hdr *gh;
|
|
|
|
|
|
|
|
id_type &= GSM_MI_TYPE_MASK;
|
|
|
|
|
|
|
|
gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
|
|
|
|
gh->proto_discr = GSM48_PDISC_MM_GPRS;
|
|
|
|
gh->msg_type = GSM48_MT_GMM_ID_REQ;
|
|
|
|
gh->data[0] = id_type;
|
|
|
|
}
|
|
|
|
|
2014-09-12 10:12:31 +00:00
|
|
|
/* Transmit Chapter 9.4.6.2 Detach Accept (mobile originated detach) */
|
|
|
|
static void gprs_put_mo_detach_acc(struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct gsm48_hdr *gh;
|
|
|
|
|
|
|
|
gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
|
|
|
|
gh->proto_discr = GSM48_PDISC_MM_GPRS;
|
|
|
|
gh->msg_type = GSM48_MT_GMM_DETACH_ACK;
|
|
|
|
gh->data[0] = 0; /* no force to standby */
|
|
|
|
}
|
|
|
|
|
2014-08-22 15:10:01 +00:00
|
|
|
static void gprs_push_llc_ui(struct msgb *msg,
|
|
|
|
int is_uplink, unsigned sapi, unsigned nu)
|
|
|
|
{
|
|
|
|
const uint8_t e_bit = 0;
|
|
|
|
const uint8_t pm_bit = 1;
|
|
|
|
const uint8_t cr_bit = is_uplink ? 0 : 1;
|
|
|
|
uint8_t *llc;
|
|
|
|
uint8_t *fcs_field;
|
|
|
|
uint32_t fcs;
|
|
|
|
|
|
|
|
nu &= 0x01ff; /* 9 Bit */
|
|
|
|
|
|
|
|
llc = msgb_push(msg, 3);
|
|
|
|
llc[0] = (cr_bit << 6) | (sapi & 0x0f);
|
|
|
|
llc[1] = 0xc0 | (nu >> 6); /* UI frame */
|
|
|
|
llc[2] = (nu << 2) | ((e_bit & 1) << 1) | (pm_bit & 1);
|
|
|
|
|
|
|
|
fcs = gprs_llc_fcs(llc, msgb_length(msg));
|
|
|
|
fcs_field = msgb_put(msg, 3);
|
|
|
|
fcs_field[0] = (uint8_t)(fcs >> 0);
|
|
|
|
fcs_field[1] = (uint8_t)(fcs >> 8);
|
|
|
|
fcs_field[2] = (uint8_t)(fcs >> 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gprs_push_bssgp_dl_unitdata(struct msgb *msg,
|
|
|
|
uint32_t tlli)
|
|
|
|
{
|
|
|
|
struct bssgp_ud_hdr *budh;
|
|
|
|
uint8_t *llc = msgb_data(msg);
|
|
|
|
size_t llc_size = msgb_length(msg);
|
|
|
|
const size_t llc_ie_hdr_size = 3;
|
|
|
|
const uint8_t qos_profile[] = {0x00, 0x50, 0x20}; /* hard-coded */
|
|
|
|
const uint8_t lifetime[] = {0x02, 0x58}; /* 6s hard-coded */
|
|
|
|
|
|
|
|
const size_t bssgp_overhead = sizeof(*budh) +
|
|
|
|
TVLV_GROSS_LEN(sizeof(lifetime)) + llc_ie_hdr_size;
|
|
|
|
uint8_t *ie;
|
|
|
|
uint32_t tlli_be = htonl(tlli);
|
|
|
|
|
|
|
|
budh = (struct bssgp_ud_hdr *)msgb_push(msg, bssgp_overhead);
|
|
|
|
|
|
|
|
budh->pdu_type = BSSGP_PDUT_DL_UNITDATA;
|
|
|
|
memcpy(&budh->tlli, &tlli_be, sizeof(budh->tlli));
|
|
|
|
memcpy(&budh->qos_profile, qos_profile, sizeof(budh->qos_profile));
|
|
|
|
|
|
|
|
ie = budh->data;
|
|
|
|
tvlv_put(ie, BSSGP_IE_PDU_LIFETIME, sizeof(lifetime), lifetime);
|
|
|
|
ie += TVLV_GROSS_LEN(sizeof(lifetime));
|
|
|
|
|
|
|
|
/* Note: Add alignment before the LLC IE if inserting other IE */
|
|
|
|
|
|
|
|
*(ie++) = BSSGP_IE_LLC_PDU;
|
|
|
|
*(ie++) = llc_size / 256;
|
|
|
|
*(ie++) = llc_size % 256;
|
|
|
|
|
|
|
|
OSMO_ASSERT(ie == llc);
|
|
|
|
|
|
|
|
msgb_bssgph(msg) = (uint8_t *)budh;
|
|
|
|
msgb_tlli(msg) = tlli;
|
|
|
|
}
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
/* update peer according to the BSS message */
|
|
|
|
static void gbprox_update_current_raid(uint8_t *raid_enc,
|
|
|
|
struct gbproxy_peer *peer,
|
|
|
|
const char *log_text)
|
2014-07-01 10:41:13 +00:00
|
|
|
{
|
2014-08-19 10:21:01 +00:00
|
|
|
struct gbproxy_patch_state *state = &peer->patch_state;
|
|
|
|
const int old_local_mcc = state->local_mcc;
|
|
|
|
const int old_local_mnc = state->local_mnc;
|
|
|
|
struct gprs_ra_id raid;
|
2014-07-01 10:41:13 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!raid_enc)
|
|
|
|
return;
|
2014-07-01 10:41:13 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
gsm48_parse_ra(&raid, raid_enc);
|
2014-07-01 10:41:13 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
/* save source side MCC/MNC */
|
|
|
|
if (!peer->cfg->core_mcc || raid.mcc == peer->cfg->core_mcc) {
|
|
|
|
state->local_mcc = 0;
|
|
|
|
} else {
|
|
|
|
state->local_mcc = raid.mcc;
|
|
|
|
}
|
2014-07-01 10:41:13 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!peer->cfg->core_mnc || raid.mnc == peer->cfg->core_mnc) {
|
|
|
|
state->local_mnc = 0;
|
|
|
|
} else {
|
|
|
|
state->local_mnc = raid.mnc;
|
|
|
|
}
|
2014-07-01 10:41:13 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (old_local_mcc != state->local_mcc ||
|
|
|
|
old_local_mnc != state->local_mnc)
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE,
|
|
|
|
"Patching RAID %sactivated, msg: %s, "
|
|
|
|
"local: %d-%d, core: %d-%d\n",
|
|
|
|
state->local_mcc || state->local_mnc ?
|
|
|
|
"" : "de",
|
|
|
|
log_text,
|
|
|
|
state->local_mcc, state->local_mnc,
|
|
|
|
peer->cfg->core_mcc, peer->cfg->core_mnc);
|
2014-07-01 10:41:13 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_peer *peer,
|
|
|
|
uint32_t sgsn_ptmsi)
|
2014-06-27 16:10:53 +00:00
|
|
|
{
|
2014-08-19 10:21:01 +00:00
|
|
|
uint32_t bss_ptmsi;
|
2014-09-19 07:28:42 +00:00
|
|
|
int max_retries = 23;
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!peer->cfg->patch_ptmsi) {
|
|
|
|
bss_ptmsi = sgsn_ptmsi;
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
bss_ptmsi = rand_r(&peer->cfg->bss_ptmsi_state);
|
|
|
|
bss_ptmsi = bss_ptmsi | 0xC0000000;
|
2014-06-27 16:10:53 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (gbproxy_link_info_by_ptmsi(peer, bss_ptmsi))
|
2014-08-19 10:21:01 +00:00
|
|
|
bss_ptmsi = GSM_RESERVED_TMSI;
|
2014-09-19 07:28:42 +00:00
|
|
|
} while (bss_ptmsi == GSM_RESERVED_TMSI && max_retries--);
|
2014-08-19 10:21:01 +00:00
|
|
|
}
|
2014-08-05 13:53:43 +00:00
|
|
|
|
2014-09-19 07:28:42 +00:00
|
|
|
if (bss_ptmsi == GSM_RESERVED_TMSI)
|
|
|
|
LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI\n");
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
return bss_ptmsi;
|
2014-08-05 13:53:43 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
uint32_t gbproxy_make_sgsn_tlli(struct gbproxy_peer *peer,
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info *link_info,
|
2014-08-19 10:21:01 +00:00
|
|
|
uint32_t bss_tlli)
|
2014-08-06 13:16:45 +00:00
|
|
|
{
|
2014-08-19 10:21:01 +00:00
|
|
|
uint32_t sgsn_tlli;
|
2014-09-19 07:28:42 +00:00
|
|
|
int max_retries = 23;
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!peer->cfg->patch_ptmsi) {
|
|
|
|
sgsn_tlli = bss_tlli;
|
2014-09-19 13:07:27 +00:00
|
|
|
} else if (link_info->sgsn_tlli.ptmsi != GSM_RESERVED_TMSI) {
|
|
|
|
sgsn_tlli = gprs_tmsi2tlli(link_info->sgsn_tlli.ptmsi,
|
2014-08-19 10:21:01 +00:00
|
|
|
TLLI_FOREIGN);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
/* create random TLLI, 0b01111xxx... */
|
|
|
|
sgsn_tlli = rand_r(&peer->cfg->sgsn_tlli_state);
|
|
|
|
sgsn_tlli = (sgsn_tlli & 0x7fffffff) | 0x78000000;
|
2014-08-06 13:16:45 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (gbproxy_link_info_by_any_sgsn_tlli(peer, sgsn_tlli))
|
2014-08-19 10:21:01 +00:00
|
|
|
sgsn_tlli = 0;
|
2014-09-19 07:28:42 +00:00
|
|
|
} while (!sgsn_tlli && max_retries--);
|
2014-08-19 10:21:01 +00:00
|
|
|
}
|
2014-09-19 07:28:42 +00:00
|
|
|
|
|
|
|
if (!sgsn_tlli)
|
|
|
|
LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI\n");
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
return sgsn_tlli;
|
2014-08-06 13:16:45 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 11:30:46 +00:00
|
|
|
void gbproxy_reset_link(struct gbproxy_link_info *link_info)
|
|
|
|
{
|
|
|
|
gbproxy_reset_imsi_acquisition(link_info);
|
|
|
|
}
|
|
|
|
|
2014-09-03 09:59:48 +00:00
|
|
|
/* Returns != 0 iff IMSI acquisition was in progress */
|
2014-09-19 13:07:27 +00:00
|
|
|
static int gbproxy_restart_imsi_acquisition(struct gbproxy_link_info* link_info)
|
2014-09-03 09:59:48 +00:00
|
|
|
{
|
|
|
|
int in_progress = 0;
|
2014-09-19 13:07:27 +00:00
|
|
|
if (!link_info)
|
2014-09-03 09:59:48 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-09-22 13:41:21 +00:00
|
|
|
if (link_info->imsi_acq_pending)
|
2014-09-03 09:59:48 +00:00
|
|
|
in_progress = 1;
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_link_info_discard_messages(link_info);
|
|
|
|
link_info->imsi_acq_pending = 0;
|
2014-09-03 09:59:48 +00:00
|
|
|
|
|
|
|
return in_progress;
|
|
|
|
}
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
static void gbproxy_reset_imsi_acquisition(struct gbproxy_link_info* link_info)
|
2014-09-11 08:30:21 +00:00
|
|
|
{
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_restart_imsi_acquisition(link_info);
|
2014-09-22 13:41:21 +00:00
|
|
|
link_info->vu_gen_tx_bss = GBPROXY_INIT_VU_GEN_TX;
|
2014-09-11 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gbproxy_flush_stored_messages(struct gbproxy_peer *peer,
|
|
|
|
struct msgb *msg,
|
|
|
|
time_t now,
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info* link_info,
|
2014-09-11 08:30:21 +00:00
|
|
|
struct gprs_gb_parse_context *parse_ctx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct msgb *stored_msg;
|
|
|
|
/* Got identity response with IMSI, assuming the request had
|
|
|
|
* been generated by the gbproxy */
|
|
|
|
|
|
|
|
LOGP(DLLC, LOGL_DEBUG,
|
|
|
|
"NSEI=%d(BSS) IMSI acquisition succeeded, "
|
|
|
|
"flushing stored messages\n",
|
|
|
|
msgb_nsei(msg));
|
|
|
|
|
|
|
|
/* Patch and flush stored messages towards the SGSN */
|
2014-09-19 13:07:27 +00:00
|
|
|
while ((stored_msg = msgb_dequeue(&link_info->stored_msgs))) {
|
2014-09-11 08:30:21 +00:00
|
|
|
struct gprs_gb_parse_context tmp_parse_ctx = {0};
|
|
|
|
tmp_parse_ctx.to_bss = 0;
|
2014-09-17 08:56:38 +00:00
|
|
|
tmp_parse_ctx.peer_nsei = msgb_nsei(stored_msg);
|
2014-09-11 08:30:21 +00:00
|
|
|
int len_change = 0;
|
|
|
|
|
|
|
|
gprs_gb_parse_bssgp(msgb_bssgph(stored_msg),
|
|
|
|
msgb_bssgp_len(stored_msg),
|
|
|
|
&tmp_parse_ctx);
|
|
|
|
gbproxy_patch_bssgp(msg, msgb_bssgph(stored_msg),
|
|
|
|
msgb_bssgp_len(stored_msg),
|
2014-09-19 13:07:27 +00:00
|
|
|
peer, link_info, &len_change,
|
2014-09-11 08:30:21 +00:00
|
|
|
&tmp_parse_ctx);
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_update_link_state_after(peer, link_info, now,
|
2014-09-11 08:30:21 +00:00
|
|
|
&tmp_parse_ctx);
|
|
|
|
|
|
|
|
rc = gbprox_relay2sgsn(peer->cfg, stored_msg,
|
2014-09-19 13:07:27 +00:00
|
|
|
msgb_bvci(msg), link_info->sgsn_nsei);
|
2014-09-11 08:30:21 +00:00
|
|
|
|
|
|
|
if (rc < 0)
|
|
|
|
LOGP(DLLC, LOGL_ERROR,
|
|
|
|
"NSEI=%d(BSS) failed to send stored message "
|
|
|
|
"(%s)\n",
|
|
|
|
msgb_nsei(msg),
|
|
|
|
parse_ctx->llc_msg_name ?
|
|
|
|
parse_ctx->llc_msg_name : "BSSGP");
|
|
|
|
msgb_free(stored_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 13:41:21 +00:00
|
|
|
static int gbproxy_gsm48_to_peer(struct gbproxy_peer *peer,
|
|
|
|
struct gbproxy_link_info* link_info,
|
|
|
|
uint16_t bvci,
|
|
|
|
struct msgb *msg /* Takes msg ownership */)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Workaround to avoid N(U) collisions and to enable a restart
|
|
|
|
* of the IMSI acquisition procedure. This will work unless the
|
|
|
|
* SGSN has an initial V(UT) within [256-32, 256+n_retries]
|
|
|
|
* (see GSM 04.64, 8.4.2). */
|
|
|
|
gprs_push_llc_ui(msg, 0, GPRS_SAPI_GMM, link_info->vu_gen_tx_bss);
|
|
|
|
link_info->vu_gen_tx_bss = (link_info->vu_gen_tx_bss + 1) % 512;
|
|
|
|
|
|
|
|
gprs_push_bssgp_dl_unitdata(msg, link_info->tlli.current);
|
|
|
|
rc = gbprox_relay2peer(msg, peer, bvci);
|
|
|
|
msgb_free(msg);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-09-11 08:30:21 +00:00
|
|
|
static void gbproxy_acquire_imsi(struct gbproxy_peer *peer,
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info* link_info,
|
2014-09-11 08:30:21 +00:00
|
|
|
uint16_t bvci)
|
|
|
|
{
|
|
|
|
struct msgb *idreq_msg;
|
|
|
|
|
|
|
|
/* Send IDENT REQ */
|
|
|
|
idreq_msg = gsm48_msgb_alloc();
|
|
|
|
gprs_put_identity_req(idreq_msg, GSM_MI_TYPE_IMSI);
|
2014-09-22 13:41:21 +00:00
|
|
|
gbproxy_gsm48_to_peer(peer, link_info, bvci, idreq_msg);
|
2014-09-11 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-12 10:12:31 +00:00
|
|
|
static void gbproxy_tx_detach_acc(struct gbproxy_peer *peer,
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info* link_info,
|
2014-09-12 10:12:31 +00:00
|
|
|
uint16_t bvci)
|
|
|
|
{
|
|
|
|
struct msgb *detacc_msg;
|
|
|
|
|
|
|
|
/* Send DETACH ACC */
|
|
|
|
detacc_msg = gsm48_msgb_alloc();
|
|
|
|
gprs_put_mo_detach_acc(detacc_msg);
|
2014-09-22 13:41:21 +00:00
|
|
|
gbproxy_gsm48_to_peer(peer, link_info, bvci, detacc_msg);
|
2014-09-12 10:12:31 +00:00
|
|
|
}
|
2014-09-11 08:30:21 +00:00
|
|
|
|
|
|
|
/* Return != 0 iff msg still needs to be processed */
|
|
|
|
static int gbproxy_imsi_acquisition(struct gbproxy_peer *peer,
|
|
|
|
struct msgb *msg,
|
|
|
|
time_t now,
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info* link_info,
|
2014-09-11 08:30:21 +00:00
|
|
|
struct gprs_gb_parse_context *parse_ctx)
|
|
|
|
{
|
2014-09-11 09:35:17 +00:00
|
|
|
struct msgb *stored_msg;
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (!link_info)
|
2014-09-11 08:30:21 +00:00
|
|
|
return 1;
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (!link_info->imsi_acq_pending && link_info->imsi_len > 0)
|
2014-09-11 09:35:17 +00:00
|
|
|
return 1;
|
|
|
|
|
2014-09-12 10:12:31 +00:00
|
|
|
if (parse_ctx->g48_hdr)
|
|
|
|
switch (parse_ctx->g48_hdr->msg_type)
|
|
|
|
{
|
2014-09-18 08:08:27 +00:00
|
|
|
case GSM48_MT_GMM_RA_UPD_REQ:
|
2014-09-12 10:12:31 +00:00
|
|
|
case GSM48_MT_GMM_ATTACH_REQ:
|
2014-09-19 13:07:27 +00:00
|
|
|
if (gbproxy_restart_imsi_acquisition(link_info)) {
|
2014-09-12 10:12:31 +00:00
|
|
|
LOGP(DLLC, LOGL_INFO,
|
|
|
|
"NSEI=%d(BSS) IMSI acquisition was in progress "
|
2014-09-18 08:08:27 +00:00
|
|
|
"when receiving an %s.\n",
|
|
|
|
msgb_nsei(msg), parse_ctx->llc_msg_name);
|
2014-09-12 10:12:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GSM48_MT_GMM_DETACH_REQ:
|
|
|
|
/* Nothing has been sent to the SGSN yet */
|
2014-09-19 13:07:27 +00:00
|
|
|
if (link_info->imsi_acq_pending) {
|
2014-09-12 10:12:31 +00:00
|
|
|
LOGP(DLLC, LOGL_INFO,
|
|
|
|
"NSEI=%d(BSS) IMSI acquisition was in progress "
|
|
|
|
"when receiving a DETACH_REQ.\n",
|
|
|
|
msgb_nsei(msg));
|
|
|
|
}
|
|
|
|
if (!parse_ctx->invalidate_tlli) {
|
|
|
|
LOGP(DLLC, LOGL_INFO,
|
|
|
|
"NSEI=%d(BSS) IMSI not yet acquired, "
|
|
|
|
"faking a DETACH_ACC.\n",
|
|
|
|
msgb_nsei(msg));
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_tx_detach_acc(peer, link_info, msgb_bvci(msg));
|
2014-09-12 10:12:31 +00:00
|
|
|
parse_ctx->invalidate_tlli = 1;
|
|
|
|
}
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_reset_imsi_acquisition(link_info);
|
|
|
|
gbproxy_update_link_state_after(peer, link_info, now,
|
2014-09-12 10:12:31 +00:00
|
|
|
parse_ctx);
|
|
|
|
return 0;
|
2014-09-11 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (link_info->imsi_acq_pending && link_info->imsi_len > 0) {
|
2014-09-11 09:35:17 +00:00
|
|
|
int is_ident_resp =
|
|
|
|
parse_ctx->g48_hdr &&
|
|
|
|
parse_ctx->g48_hdr->proto_discr == GSM48_PDISC_MM_GPRS &&
|
|
|
|
parse_ctx->g48_hdr->msg_type == GSM48_MT_GMM_ID_RESP;
|
|
|
|
|
2014-09-11 08:30:21 +00:00
|
|
|
/* The IMSI is now available */
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_flush_stored_messages(peer, msg, now, link_info,
|
2014-09-19 11:23:21 +00:00
|
|
|
parse_ctx);
|
2014-09-11 08:30:21 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_reset_imsi_acquisition(link_info);
|
2014-09-11 08:30:21 +00:00
|
|
|
|
2014-09-11 09:35:17 +00:00
|
|
|
/* This message is most probably the response to the ident
|
|
|
|
* request sent by gbproxy_acquire_imsi(). Don't forward it to
|
|
|
|
* the SGSN. */
|
|
|
|
return !is_ident_resp;
|
|
|
|
}
|
2014-09-11 08:30:21 +00:00
|
|
|
|
2014-09-11 09:35:17 +00:00
|
|
|
/* The message cannot be processed since the IMSI is still missing */
|
2014-09-11 08:30:21 +00:00
|
|
|
|
2014-09-11 09:35:17 +00:00
|
|
|
/* Enqueue unpatched messages */
|
|
|
|
LOGP(DLLC, LOGL_INFO,
|
|
|
|
"NSEI=%d(BSS) IMSI acquisition in progress, "
|
|
|
|
"storing message (%s)\n",
|
|
|
|
msgb_nsei(msg),
|
|
|
|
parse_ctx->llc_msg_name ? parse_ctx->llc_msg_name : "BSSGP");
|
2014-09-11 08:30:21 +00:00
|
|
|
|
2014-09-11 09:35:17 +00:00
|
|
|
stored_msg = gprs_msgb_copy(msg, "process_bssgp_ul");
|
2014-09-19 13:07:27 +00:00
|
|
|
msgb_enqueue(&link_info->stored_msgs, stored_msg);
|
2014-09-11 08:30:21 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (!link_info->imsi_acq_pending) {
|
2014-09-11 09:35:17 +00:00
|
|
|
LOGP(DLLC, LOGL_INFO,
|
2014-09-11 08:30:21 +00:00
|
|
|
"NSEI=%d(BSS) IMSI is required but not available, "
|
2014-09-11 09:35:17 +00:00
|
|
|
"initiating identification procedure (%s)\n",
|
2014-09-11 08:30:21 +00:00
|
|
|
msgb_nsei(msg),
|
|
|
|
parse_ctx->llc_msg_name ? parse_ctx->llc_msg_name : "BSSGP");
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_acquire_imsi(peer, link_info, msgb_bvci(msg));
|
2014-09-11 08:30:21 +00:00
|
|
|
|
|
|
|
/* There is no explicit retransmission handling, the
|
|
|
|
* implementation relies on the MS doing proper retransmissions
|
|
|
|
* of the triggering message instead */
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
link_info->imsi_acq_pending = 1;
|
2014-09-11 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 09:35:17 +00:00
|
|
|
return 0;
|
2014-09-11 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct gbproxy_peer *gbproxy_find_peer(struct gbproxy_config *cfg,
|
|
|
|
struct msgb *msg,
|
|
|
|
struct gprs_gb_parse_context *parse_ctx)
|
|
|
|
{
|
|
|
|
struct gbproxy_peer *peer = NULL;
|
|
|
|
|
|
|
|
if (msgb_bvci(msg) >= 2)
|
|
|
|
peer = gbproxy_peer_by_bvci(cfg, msgb_bvci(msg));
|
|
|
|
|
|
|
|
if (!peer && !parse_ctx->to_bss)
|
|
|
|
peer = gbproxy_peer_by_nsei(cfg, msgb_nsei(msg));
|
|
|
|
|
|
|
|
if (!peer)
|
|
|
|
peer = gbproxy_peer_by_bssgp_tlv(cfg, &parse_ctx->bssgp_tp);
|
|
|
|
|
|
|
|
if (!peer) {
|
|
|
|
LOGP(DLLC, LOGL_INFO,
|
|
|
|
"NSEI=%d(%s) patching: didn't find peer for message, "
|
|
|
|
"PDU %d\n",
|
|
|
|
msgb_nsei(msg), parse_ctx->to_bss ? "BSS" : "SGSN",
|
|
|
|
parse_ctx->pdu_type);
|
|
|
|
/* Increment counter */
|
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_PATCH_PEER_ERR]);
|
|
|
|
}
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
/* patch BSSGP message */
|
2014-08-22 15:10:01 +00:00
|
|
|
static int gbprox_process_bssgp_ul(struct gbproxy_config *cfg,
|
|
|
|
struct msgb *msg,
|
|
|
|
struct gbproxy_peer *peer)
|
2014-08-05 13:53:43 +00:00
|
|
|
{
|
2014-08-19 10:21:01 +00:00
|
|
|
struct gprs_gb_parse_context parse_ctx = {0};
|
|
|
|
int rc;
|
|
|
|
int len_change = 0;
|
|
|
|
time_t now;
|
2014-09-19 14:34:01 +00:00
|
|
|
struct timespec ts = {0,};
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info *link_info = NULL;
|
2014-08-27 10:51:07 +00:00
|
|
|
uint32_t sgsn_nsei = cfg->nsip_sgsn_nsei;
|
2014-06-27 17:00:45 +00:00
|
|
|
|
2014-08-22 15:10:01 +00:00
|
|
|
if (!cfg->core_mcc && !cfg->core_mnc && !cfg->core_apn &&
|
2014-09-04 09:42:08 +00:00
|
|
|
!cfg->acquire_imsi && !cfg->patch_ptmsi && !cfg->route_to_sgsn2)
|
2014-08-22 15:10:01 +00:00
|
|
|
return 1;
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
parse_ctx.to_bss = 0;
|
2014-09-17 08:56:38 +00:00
|
|
|
parse_ctx.peer_nsei = msgb_nsei(msg);
|
2014-08-12 14:30:30 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
/* Parse BSSGP/LLC */
|
|
|
|
rc = gprs_gb_parse_bssgp(msgb_bssgph(msg), msgb_bssgp_len(msg),
|
|
|
|
&parse_ctx);
|
2014-08-12 14:30:30 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!rc) {
|
|
|
|
if (!parse_ctx.need_decryption) {
|
|
|
|
LOGP(DGPRS, LOGL_ERROR,
|
|
|
|
"NSEI=%u(BSS) patching: "
|
|
|
|
"failed to parse BSSGP/GMM message\n",
|
|
|
|
msgb_nsei(msg));
|
2014-08-22 15:10:01 +00:00
|
|
|
return 0;
|
2014-08-19 10:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 17:12:24 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
/* Get peer */
|
|
|
|
if (!peer)
|
2014-09-11 08:30:21 +00:00
|
|
|
peer = gbproxy_find_peer(cfg, msg, &parse_ctx);
|
2014-08-11 17:12:24 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!peer)
|
2014-08-22 15:10:01 +00:00
|
|
|
return 0;
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-09-19 14:34:01 +00:00
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
now = ts.tv_sec;
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
gbprox_update_current_raid(parse_ctx.bssgp_raid_enc, peer,
|
|
|
|
parse_ctx.llc_msg_name);
|
2014-08-06 16:55:15 +00:00
|
|
|
|
2014-09-03 09:59:48 +00:00
|
|
|
gprs_gb_log_parse_context(&parse_ctx, "BSSGP");
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
link_info = gbproxy_update_link_state_ul(peer, now, &parse_ctx);
|
2014-09-03 09:59:48 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (parse_ctx.g48_hdr) {
|
|
|
|
switch (parse_ctx.g48_hdr->msg_type) {
|
|
|
|
case GSM48_MT_GMM_ATTACH_REQ:
|
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_ATTACH_REQS]);
|
|
|
|
break;
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-06-06 16:49:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (link_info && cfg->route_to_sgsn2) {
|
|
|
|
if (cfg->acquire_imsi && link_info->imsi_len == 0)
|
2014-09-17 08:56:38 +00:00
|
|
|
sgsn_nsei = 0xffff;
|
2014-09-25 11:21:48 +00:00
|
|
|
else if (gbproxy_imsi_matches(cfg, GBPROX_MATCH_ROUTING,
|
2014-09-25 09:17:31 +00:00
|
|
|
link_info))
|
2014-09-17 08:56:38 +00:00
|
|
|
sgsn_nsei = cfg->nsip_sgsn2_nsei;
|
2014-08-27 10:51:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
if (link_info)
|
|
|
|
link_info->sgsn_nsei = sgsn_nsei;
|
2014-09-17 08:56:38 +00:00
|
|
|
|
2014-09-11 08:30:21 +00:00
|
|
|
/* Handle IMSI acquisition */
|
|
|
|
if (cfg->acquire_imsi) {
|
2014-09-19 13:07:27 +00:00
|
|
|
rc = gbproxy_imsi_acquisition(peer, msg, now, link_info,
|
2014-09-19 11:23:21 +00:00
|
|
|
&parse_ctx);
|
2014-09-11 08:30:21 +00:00
|
|
|
if (rc <= 0)
|
|
|
|
return rc;
|
2014-08-22 15:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
gbproxy_patch_bssgp(msg, msgb_bssgph(msg), msgb_bssgp_len(msg),
|
2014-09-19 13:07:27 +00:00
|
|
|
peer, link_info, &len_change, &parse_ctx);
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_update_link_state_after(peer, link_info, now, &parse_ctx);
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-09-17 08:56:38 +00:00
|
|
|
if (sgsn_nsei != cfg->nsip_sgsn_nsei) {
|
2014-08-27 10:51:07 +00:00
|
|
|
/* Send message directly to the selected SGSN */
|
|
|
|
rc = gbprox_relay2sgsn(cfg, msg, msgb_bvci(msg), sgsn_nsei);
|
|
|
|
/* Don't let the calling code handle the transmission */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-22 15:10:01 +00:00
|
|
|
return 1;
|
2014-08-14 06:57:04 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
/* patch BSSGP message to use core_mcc/mnc on the SGSN side */
|
|
|
|
static void gbprox_process_bssgp_dl(struct gbproxy_config *cfg,
|
|
|
|
struct msgb *msg,
|
|
|
|
struct gbproxy_peer *peer)
|
2014-06-06 16:49:23 +00:00
|
|
|
{
|
2014-08-19 10:21:01 +00:00
|
|
|
struct gprs_gb_parse_context parse_ctx = {0};
|
2014-06-06 16:49:23 +00:00
|
|
|
int rc;
|
2014-08-19 10:21:01 +00:00
|
|
|
int len_change = 0;
|
|
|
|
time_t now;
|
2014-09-19 14:34:01 +00:00
|
|
|
struct timespec ts = {0,};
|
2014-09-19 13:07:27 +00:00
|
|
|
struct gbproxy_link_info *link_info = NULL;
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-09-04 09:42:08 +00:00
|
|
|
if (!cfg->core_mcc && !cfg->core_mnc && !cfg->core_apn &&
|
|
|
|
!cfg->acquire_imsi && !cfg->patch_ptmsi && !cfg->route_to_sgsn2)
|
|
|
|
return;
|
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
parse_ctx.to_bss = 1;
|
2014-09-17 08:56:38 +00:00
|
|
|
parse_ctx.peer_nsei = msgb_nsei(msg);
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
rc = gprs_gb_parse_bssgp(msgb_bssgph(msg), msgb_bssgp_len(msg),
|
|
|
|
&parse_ctx);
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!rc) {
|
|
|
|
if (!parse_ctx.need_decryption) {
|
|
|
|
LOGP(DGPRS, LOGL_ERROR,
|
|
|
|
"NSEI=%u(SGSN) patching: "
|
|
|
|
"failed to parse BSSGP/GMM message\n",
|
|
|
|
msgb_nsei(msg));
|
|
|
|
return;
|
|
|
|
}
|
2014-06-06 16:49:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 08:30:21 +00:00
|
|
|
/* Get peer */
|
2014-08-19 10:21:01 +00:00
|
|
|
if (!peer)
|
2014-09-11 08:30:21 +00:00
|
|
|
peer = gbproxy_find_peer(cfg, msg, &parse_ctx);
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-09-11 08:30:21 +00:00
|
|
|
if (!peer)
|
2014-08-19 10:21:01 +00:00
|
|
|
return;
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-09-19 14:34:01 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
now = ts.tv_sec;
|
2014-08-07 15:23:00 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
if (parse_ctx.g48_hdr) {
|
|
|
|
switch (parse_ctx.g48_hdr->msg_type) {
|
|
|
|
case GSM48_MT_GMM_ATTACH_REJ:
|
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_ATTACH_REJS]);
|
|
|
|
break;
|
2014-07-03 13:52:49 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-08-07 16:35:30 +00:00
|
|
|
}
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
gprs_gb_log_parse_context(&parse_ctx, "BSSGP");
|
2014-08-08 06:37:37 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
link_info = gbproxy_update_link_state_dl(peer, now, &parse_ctx);
|
2014-08-07 14:07:24 +00:00
|
|
|
|
2014-08-19 10:21:01 +00:00
|
|
|
gbproxy_patch_bssgp(msg, msgb_bssgph(msg), msgb_bssgp_len(msg),
|
2014-09-19 13:07:27 +00:00
|
|
|
peer, link_info, &len_change, &parse_ctx);
|
2014-08-07 14:07:24 +00:00
|
|
|
|
2014-09-19 13:07:27 +00:00
|
|
|
gbproxy_update_link_state_after(peer, link_info, now, &parse_ctx);
|
2014-08-07 14:07:24 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-03 16:54:58 +00:00
|
|
|
/* feed a message down the NS-VC associated with the specified peer */
|
2014-08-04 13:42:36 +00:00
|
|
|
static int gbprox_relay2sgsn(struct gbproxy_config *cfg, struct msgb *old_msg,
|
2014-08-26 12:47:15 +00:00
|
|
|
uint16_t ns_bvci, uint16_t sgsn_nsei)
|
2010-05-03 16:54:58 +00:00
|
|
|
{
|
2010-05-12 18:10:25 +00:00
|
|
|
/* create a copy of the message so the old one can
|
|
|
|
* be free()d safely when we return from gbprox_rcvmsg() */
|
2014-08-04 09:52:52 +00:00
|
|
|
struct msgb *msg = gprs_msgb_copy(old_msg, "msgb_relay2sgsn");
|
2013-10-18 12:34:55 +00:00
|
|
|
int rc;
|
2010-05-12 18:10:25 +00:00
|
|
|
|
2010-05-11 18:20:13 +00:00
|
|
|
DEBUGP(DGPRS, "NSEI=%u proxying BTS->SGSN (NS_BVCI=%u, NSEI=%u)\n",
|
2014-08-26 12:47:15 +00:00
|
|
|
msgb_nsei(msg), ns_bvci, sgsn_nsei);
|
2010-05-03 17:22:32 +00:00
|
|
|
|
2010-05-03 16:54:58 +00:00
|
|
|
msgb_bvci(msg) = ns_bvci;
|
2014-08-26 12:47:15 +00:00
|
|
|
msgb_nsei(msg) = sgsn_nsei;
|
2010-05-03 16:54:58 +00:00
|
|
|
|
2010-05-03 17:05:10 +00:00
|
|
|
strip_ns_hdr(msg);
|
|
|
|
|
2013-10-18 12:34:55 +00:00
|
|
|
rc = gprs_ns_sendmsg(bssgp_nsi, msg);
|
|
|
|
if (rc < 0)
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_TX_ERR_SGSN]);
|
2013-10-18 12:34:55 +00:00
|
|
|
|
|
|
|
return rc;
|
2010-05-03 16:54:58 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
/* feed a message down the NS-VC associated with the specified peer */
|
2014-08-04 09:35:32 +00:00
|
|
|
static int gbprox_relay2peer(struct msgb *old_msg, struct gbproxy_peer *peer,
|
2010-04-30 18:26:32 +00:00
|
|
|
uint16_t ns_bvci)
|
|
|
|
{
|
2010-05-12 18:10:25 +00:00
|
|
|
/* create a copy of the message so the old one can
|
|
|
|
* be free()d safely when we return from gbprox_rcvmsg() */
|
2014-08-04 09:52:52 +00:00
|
|
|
struct msgb *msg = gprs_msgb_copy(old_msg, "msgb_relay2peer");
|
2013-10-18 12:34:55 +00:00
|
|
|
int rc;
|
2010-05-12 18:10:25 +00:00
|
|
|
|
2010-05-13 08:34:56 +00:00
|
|
|
DEBUGP(DGPRS, "NSEI=%u proxying SGSN->BSS (NS_BVCI=%u, NSEI=%u)\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
msgb_nsei(msg), ns_bvci, peer->nsei);
|
2010-05-03 17:22:32 +00:00
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
msgb_bvci(msg) = ns_bvci;
|
2013-10-15 10:00:27 +00:00
|
|
|
msgb_nsei(msg) = peer->nsei;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2010-05-13 08:34:56 +00:00
|
|
|
/* Strip the old NS header, it will be replaced with a new one */
|
2010-05-03 17:05:10 +00:00
|
|
|
strip_ns_hdr(msg);
|
|
|
|
|
2013-10-18 12:34:55 +00:00
|
|
|
rc = gprs_ns_sendmsg(bssgp_nsi, msg);
|
|
|
|
if (rc < 0)
|
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_TX_ERR]);
|
|
|
|
|
|
|
|
return rc;
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 13:42:36 +00:00
|
|
|
static int block_unblock_peer(struct gbproxy_config *cfg, uint16_t ptp_bvci, uint8_t pdu_type)
|
2011-02-06 12:09:29 +00:00
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2011-02-06 12:09:29 +00:00
|
|
|
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_bvci(cfg, ptp_bvci);
|
2011-02-06 12:09:29 +00:00
|
|
|
if (!peer) {
|
|
|
|
LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n",
|
|
|
|
ptp_bvci);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_INV_BVCI]);
|
2011-02-06 12:09:29 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pdu_type) {
|
|
|
|
case BSSGP_PDUT_BVC_BLOCK_ACK:
|
|
|
|
peer->blocked = 1;
|
2013-10-18 12:34:55 +00:00
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_BLOCKED]);
|
2011-02-06 12:09:29 +00:00
|
|
|
break;
|
|
|
|
case BSSGP_PDUT_BVC_UNBLOCK_ACK:
|
|
|
|
peer->blocked = 0;
|
2013-10-18 12:34:55 +00:00
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_UNBLOCKED]);
|
2011-02-06 12:09:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
/* Send a message to a peer identified by ptp_bvci but using ns_bvci
|
|
|
|
* in the NS hdr */
|
2014-08-04 13:42:36 +00:00
|
|
|
static int gbprox_relay2bvci(struct gbproxy_config *cfg, struct msgb *msg, uint16_t ptp_bvci,
|
2010-04-30 18:26:32 +00:00
|
|
|
uint16_t ns_bvci)
|
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_bvci(cfg, ptp_bvci);
|
2010-05-03 19:37:11 +00:00
|
|
|
if (!peer) {
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n",
|
2010-05-03 19:37:11 +00:00
|
|
|
ptp_bvci);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_INV_BVCI]);
|
2010-04-30 18:26:32 +00:00
|
|
|
return -ENOENT;
|
2010-05-03 19:37:11 +00:00
|
|
|
}
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2010-05-03 17:05:10 +00:00
|
|
|
return gbprox_relay2peer(msg, peer, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 04:16:31 +00:00
|
|
|
int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-21 11:45:04 +00:00
|
|
|
/* Receive an incoming PTP message from a BSS-side NS-VC */
|
|
|
|
static int gbprox_rx_ptp_from_bss(struct gbproxy_config *cfg,
|
|
|
|
struct msgb *msg, uint16_t nsei,
|
|
|
|
uint16_t nsvci, uint16_t ns_bvci)
|
|
|
|
{
|
|
|
|
struct gbproxy_peer *peer;
|
2014-08-28 11:20:39 +00:00
|
|
|
struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg);
|
|
|
|
uint8_t pdu_type = bgph->pdu_type;
|
2014-08-22 15:10:01 +00:00
|
|
|
int rc;
|
2014-08-21 11:45:04 +00:00
|
|
|
|
|
|
|
peer = gbproxy_peer_by_bvci(cfg, ns_bvci);
|
|
|
|
|
|
|
|
if (peer)
|
|
|
|
check_peer_nsei(peer, nsei);
|
|
|
|
|
2014-08-22 15:10:01 +00:00
|
|
|
rc = gbprox_process_bssgp_ul(cfg, msg, peer);
|
|
|
|
if (!rc)
|
|
|
|
return 0;
|
2014-08-21 11:45:04 +00:00
|
|
|
|
2014-08-28 11:20:39 +00:00
|
|
|
switch (pdu_type) {
|
|
|
|
case BSSGP_PDUT_FLOW_CONTROL_BVC:
|
|
|
|
if (!cfg->route_to_sgsn2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Send a copy to the secondary SGSN */
|
|
|
|
gbprox_relay2sgsn(cfg, msg, ns_bvci, cfg->nsip_sgsn2_nsei);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
return gbprox_relay2sgsn(cfg, msg, ns_bvci, cfg->nsip_sgsn_nsei);
|
2014-08-21 11:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive an incoming PTP message from a SGSN-side NS-VC */
|
|
|
|
static int gbprox_rx_ptp_from_sgsn(struct gbproxy_config *cfg,
|
|
|
|
struct msgb *msg, uint16_t nsei,
|
|
|
|
uint16_t nsvci, uint16_t ns_bvci)
|
|
|
|
{
|
|
|
|
struct gbproxy_peer *peer;
|
2014-08-28 11:20:39 +00:00
|
|
|
struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg);
|
|
|
|
uint8_t pdu_type = bgph->pdu_type;
|
2014-08-21 11:45:04 +00:00
|
|
|
|
|
|
|
peer = gbproxy_peer_by_bvci(cfg, ns_bvci);
|
|
|
|
|
2014-08-21 13:07:11 +00:00
|
|
|
/* Send status messages before patching */
|
|
|
|
|
2014-08-21 11:45:04 +00:00
|
|
|
if (!peer) {
|
|
|
|
LOGP(DGPRS, LOGL_INFO, "Didn't find peer for "
|
|
|
|
"BVCI=%u for message from NSVC=%u/NSEI=%u (SGSN)\n",
|
|
|
|
ns_bvci, nsvci, nsei);
|
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
|
|
|
ctr[GBPROX_GLOB_CTR_INV_BVCI]);
|
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI,
|
|
|
|
&ns_bvci, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->blocked) {
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "Dropping PDU for "
|
|
|
|
"blocked BVCI=%u via NSVC=%u/NSEI=%u\n",
|
|
|
|
ns_bvci, nsvci, nsei);
|
|
|
|
rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_DROPPED]);
|
2014-08-29 10:20:15 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &ns_bvci, msg);
|
2014-08-21 11:45:04 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 11:20:39 +00:00
|
|
|
switch (pdu_type) {
|
|
|
|
case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK:
|
|
|
|
case BSSGP_PDUT_BVC_BLOCK_ACK:
|
|
|
|
case BSSGP_PDUT_BVC_UNBLOCK_ACK:
|
|
|
|
if (cfg->route_to_sgsn2 && nsei == cfg->nsip_sgsn2_nsei)
|
|
|
|
/* Hide ACKs from the secondary SGSN, the primary SGSN
|
|
|
|
* is responsible to send them. */
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-21 13:07:11 +00:00
|
|
|
/* Optionally patch the message */
|
|
|
|
gbprox_process_bssgp_dl(cfg, msg, peer);
|
|
|
|
|
2014-08-21 11:45:04 +00:00
|
|
|
return gbprox_relay2peer(msg, peer, ns_bvci);
|
|
|
|
}
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
/* Receive an incoming signalling message from a BSS-side NS-VC */
|
2014-08-04 13:42:36 +00:00
|
|
|
static int gbprox_rx_sig_from_bss(struct gbproxy_config *cfg,
|
|
|
|
struct msgb *msg, uint16_t nsei,
|
2010-04-30 18:26:32 +00:00
|
|
|
uint16_t ns_bvci)
|
|
|
|
{
|
2010-05-03 14:30:59 +00:00
|
|
|
struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
struct tlv_parsed tp;
|
|
|
|
uint8_t pdu_type = bgph->pdu_type;
|
2010-05-03 14:30:59 +00:00
|
|
|
int data_len = msgb_bssgp_len(msg) - sizeof(*bgph);
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *from_peer = NULL;
|
2010-05-01 10:10:57 +00:00
|
|
|
struct gprs_ra_id raid;
|
2014-08-28 11:20:39 +00:00
|
|
|
int copy_to_sgsn2 = 0;
|
2014-09-08 07:04:01 +00:00
|
|
|
int rc;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2011-02-06 16:13:12 +00:00
|
|
|
if (ns_bvci != 0 && ns_bvci != 1) {
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u BVCI=%u is not signalling\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we actually should never see those two for BVCI == 0, but double-check
|
|
|
|
* just to make sure */
|
|
|
|
if (pdu_type == BSSGP_PDUT_UL_UNITDATA ||
|
|
|
|
pdu_type == BSSGP_PDUT_DL_UNITDATA) {
|
2010-05-03 17:22:32 +00:00
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u UNITDATA not allowed in "
|
2013-10-15 10:00:27 +00:00
|
|
|
"signalling\n", nsei);
|
2010-04-30 18:26:32 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bssgp_tlv_parse(&tp, bgph->data, data_len);
|
|
|
|
|
|
|
|
switch (pdu_type) {
|
|
|
|
case BSSGP_PDUT_SUSPEND:
|
|
|
|
case BSSGP_PDUT_RESUME:
|
2014-06-02 08:49:00 +00:00
|
|
|
/* We implement RAI snooping during SUSPEND/RESUME, since it
|
|
|
|
* establishes a relationsip between BVCI/peer and the routeing
|
|
|
|
* area identification. The snooped information is then used
|
|
|
|
* for routing the {SUSPEND,RESUME}_[N]ACK back to the correct
|
|
|
|
* BSSGP */
|
2010-04-30 18:26:32 +00:00
|
|
|
if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA))
|
|
|
|
goto err_mand_ie;
|
2014-08-21 08:01:30 +00:00
|
|
|
from_peer = gbproxy_peer_by_nsei(cfg, nsei);
|
2010-04-30 18:26:32 +00:00
|
|
|
if (!from_peer)
|
|
|
|
goto err_no_peer;
|
2010-05-11 22:07:29 +00:00
|
|
|
memcpy(from_peer->ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA),
|
|
|
|
sizeof(from_peer->ra));
|
2010-05-11 08:15:42 +00:00
|
|
|
gsm48_parse_ra(&raid, from_peer->ra);
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGP(DGPRS, LOGL_INFO, "NSEI=%u BSSGP SUSPEND/RESUME "
|
2014-06-02 08:49:00 +00:00
|
|
|
"RAI snooping: RAI %u-%u-%u-%u behind BVCI=%u\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei, raid.mcc, raid.mnc, raid.lac,
|
|
|
|
raid.rac , from_peer->bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
/* FIXME: This only supports one BSS per RA */
|
|
|
|
break;
|
2010-05-03 17:22:32 +00:00
|
|
|
case BSSGP_PDUT_BVC_RESET:
|
|
|
|
/* If we receive a BVC reset on the signalling endpoint, we
|
|
|
|
* don't want the SGSN to reset, as the signalling endpoint
|
|
|
|
* is common for all point-to-point BVCs (and thus all BTS) */
|
|
|
|
if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) {
|
2012-09-04 18:42:20 +00:00
|
|
|
uint16_t bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI));
|
2010-05-11 22:20:41 +00:00
|
|
|
LOGP(DGPRS, LOGL_INFO, "NSEI=%u Rx BVC RESET (BVCI=%u)\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei, bvci);
|
2010-05-03 17:22:32 +00:00
|
|
|
if (bvci == 0) {
|
|
|
|
/* FIXME: only do this if SGSN is alive! */
|
2010-05-11 18:20:13 +00:00
|
|
|
LOGP(DGPRS, LOGL_INFO, "NSEI=%u Tx fake "
|
2013-10-15 10:00:27 +00:00
|
|
|
"BVC RESET ACK of BVCI=0\n", nsei);
|
2010-05-03 17:22:32 +00:00
|
|
|
return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK,
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei, 0, ns_bvci);
|
2010-05-11 22:07:29 +00:00
|
|
|
}
|
2014-08-21 08:01:30 +00:00
|
|
|
from_peer = gbproxy_peer_by_bvci(cfg, bvci);
|
2010-05-11 22:07:29 +00:00
|
|
|
if (!from_peer) {
|
2010-05-03 19:37:11 +00:00
|
|
|
/* if a PTP-BVC is reset, and we don't know that
|
|
|
|
* PTP-BVCI yet, we should allocate a new peer */
|
|
|
|
LOGP(DGPRS, LOGL_INFO, "Allocationg new peer for "
|
2013-10-15 10:00:27 +00:00
|
|
|
"BVCI=%u via NSEI=%u\n", bvci, nsei);
|
2014-08-04 15:10:08 +00:00
|
|
|
from_peer = gbproxy_peer_alloc(cfg, bvci);
|
2013-10-15 10:00:27 +00:00
|
|
|
from_peer->nsei = nsei;
|
2010-05-03 17:22:32 +00:00
|
|
|
}
|
2013-10-24 10:48:56 +00:00
|
|
|
|
|
|
|
if (!check_peer_nsei(from_peer, nsei))
|
|
|
|
from_peer->nsei = nsei;
|
|
|
|
|
2010-05-11 22:07:29 +00:00
|
|
|
if (TLVP_PRESENT(&tp, BSSGP_IE_CELL_ID)) {
|
|
|
|
struct gprs_ra_id raid;
|
|
|
|
/* We have a Cell Identifier present in this
|
|
|
|
* PDU, this means we can extend our local
|
|
|
|
* state information about this particular cell
|
|
|
|
* */
|
|
|
|
memcpy(from_peer->ra,
|
|
|
|
TLVP_VAL(&tp, BSSGP_IE_CELL_ID),
|
|
|
|
sizeof(from_peer->ra));
|
|
|
|
gsm48_parse_ra(&raid, from_peer->ra);
|
|
|
|
LOGP(DGPRS, LOGL_INFO, "NSEI=%u/BVCI=%u "
|
2013-10-15 10:00:27 +00:00
|
|
|
"Cell ID %u-%u-%u-%u\n", nsei,
|
2010-05-11 22:07:29 +00:00
|
|
|
bvci, raid.mcc, raid.mnc, raid.lac,
|
|
|
|
raid.rac);
|
|
|
|
}
|
2014-08-28 11:20:39 +00:00
|
|
|
if (cfg->route_to_sgsn2)
|
|
|
|
copy_to_sgsn2 = 1;
|
2010-05-03 17:22:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 18:20:13 +00:00
|
|
|
/* Normally, we can simply pass on all signalling messages from BSS to
|
|
|
|
* SGSN */
|
2014-09-08 07:04:01 +00:00
|
|
|
rc = gbprox_process_bssgp_ul(cfg, msg, from_peer);
|
|
|
|
if (!rc)
|
|
|
|
return 0;
|
2014-08-28 11:20:39 +00:00
|
|
|
|
|
|
|
if (copy_to_sgsn2)
|
|
|
|
gbprox_relay2sgsn(cfg, msg, ns_bvci, cfg->nsip_sgsn2_nsei);
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
return gbprox_relay2sgsn(cfg, msg, ns_bvci, cfg->nsip_sgsn_nsei);
|
2010-04-30 18:26:32 +00:00
|
|
|
err_no_peer:
|
2013-10-18 11:04:48 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(BSS) cannot find peer based on NSEI\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_INV_NSEI]);
|
2014-08-29 10:20:15 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
err_mand_ie:
|
2010-05-11 08:01:17 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(BSS) missing mandatory RA IE\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_PROTO_ERR_BSS]);
|
2010-05-11 08:01:17 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive paging request from SGSN, we need to relay to proper BSS */
|
2014-08-04 13:42:36 +00:00
|
|
|
static int gbprox_rx_paging(struct gbproxy_config *cfg, struct msgb *msg, struct tlv_parsed *tp,
|
2013-10-15 10:00:27 +00:00
|
|
|
uint32_t nsei, uint16_t ns_bvci)
|
2010-04-30 18:26:32 +00:00
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer = NULL;
|
2013-10-18 12:34:55 +00:00
|
|
|
int errctr = GBPROX_GLOB_CTR_PROTO_ERR_SGSN;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGP(DGPRS, LOGL_INFO, "NSEI=%u(SGSN) BSSGP PAGING ",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei);
|
2010-04-30 18:26:32 +00:00
|
|
|
if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) {
|
2012-09-04 18:42:20 +00:00
|
|
|
uint16_t bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI));
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGPC(DGPRS, LOGL_INFO, "routing by BVCI to peer BVCI=%u\n",
|
|
|
|
bvci);
|
2013-10-18 12:34:55 +00:00
|
|
|
errctr = GBPROX_GLOB_CTR_OTHER_ERR;
|
2010-04-30 18:26:32 +00:00
|
|
|
} else if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) {
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_rai(cfg, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA));
|
2014-06-02 08:49:00 +00:00
|
|
|
LOGPC(DGPRS, LOGL_INFO, "routing by RAI to peer BVCI=%u\n",
|
2010-06-08 08:30:24 +00:00
|
|
|
peer ? peer->bvci : -1);
|
2014-06-02 08:49:00 +00:00
|
|
|
errctr = GBPROX_GLOB_CTR_INV_RAI;
|
2010-04-30 18:26:32 +00:00
|
|
|
} else if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) {
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_lai(cfg, TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA));
|
2014-06-02 08:49:00 +00:00
|
|
|
LOGPC(DGPRS, LOGL_INFO, "routing by LAI to peer BVCI=%u\n",
|
2010-06-08 08:30:24 +00:00
|
|
|
peer ? peer->bvci : -1);
|
2014-06-02 08:49:00 +00:00
|
|
|
errctr = GBPROX_GLOB_CTR_INV_LAI;
|
2010-04-30 18:26:32 +00:00
|
|
|
} else
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGPC(DGPRS, LOGL_INFO, "\n");
|
|
|
|
|
|
|
|
if (!peer) {
|
|
|
|
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) BSSGP PAGING: "
|
2013-10-15 10:00:27 +00:00
|
|
|
"unable to route, missing IE\n", nsei);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->ctr[errctr]);
|
2010-04-30 18:26:32 +00:00
|
|
|
return -EINVAL;
|
2010-05-13 12:14:56 +00:00
|
|
|
}
|
|
|
|
return gbprox_relay2peer(msg, peer, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 08:01:17 +00:00
|
|
|
/* Receive an incoming BVC-RESET message from the SGSN */
|
2014-08-04 13:42:36 +00:00
|
|
|
static int rx_reset_from_sgsn(struct gbproxy_config *cfg,
|
2014-08-21 13:07:11 +00:00
|
|
|
struct msgb *orig_msg,
|
2014-08-04 13:42:36 +00:00
|
|
|
struct msgb *msg, struct tlv_parsed *tp,
|
|
|
|
uint32_t nsei, uint16_t ns_bvci)
|
2010-05-11 08:01:17 +00:00
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2010-05-11 08:01:17 +00:00
|
|
|
uint16_t ptp_bvci;
|
|
|
|
|
|
|
|
if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) {
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_PROTO_ERR_SGSN]);
|
2010-05-11 08:01:17 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE,
|
2014-08-21 13:07:11 +00:00
|
|
|
NULL, orig_msg);
|
2010-05-11 08:01:17 +00:00
|
|
|
}
|
2012-09-04 18:42:20 +00:00
|
|
|
ptp_bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI));
|
2010-05-11 08:01:17 +00:00
|
|
|
|
|
|
|
if (ptp_bvci >= 2) {
|
|
|
|
/* A reset for a PTP BVC was received, forward it to its
|
|
|
|
* respective peer */
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_bvci(cfg, ptp_bvci);
|
2010-05-11 08:01:17 +00:00
|
|
|
if (!peer) {
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u BVCI=%u: Cannot find BSS\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei, ptp_bvci);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_INV_BVCI]);
|
2010-05-11 08:01:17 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI,
|
2014-08-29 10:20:15 +00:00
|
|
|
&ptp_bvci, orig_msg);
|
2010-05-11 08:01:17 +00:00
|
|
|
}
|
|
|
|
return gbprox_relay2peer(msg, peer, ns_bvci);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A reset for the Signalling entity has been received
|
|
|
|
* from the SGSN. As the signalling BVCI is shared
|
|
|
|
* among all the BSS's that we multiplex, it needs to
|
|
|
|
* be relayed */
|
2014-08-04 13:42:36 +00:00
|
|
|
llist_for_each_entry(peer, &cfg->bts_peers, list)
|
2010-05-11 08:01:17 +00:00
|
|
|
gbprox_relay2peer(msg, peer, ns_bvci);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
/* Receive an incoming signalling message from the SGSN-side NS-VC */
|
2014-08-04 13:42:36 +00:00
|
|
|
static int gbprox_rx_sig_from_sgsn(struct gbproxy_config *cfg,
|
2014-08-21 13:07:11 +00:00
|
|
|
struct msgb *orig_msg, uint32_t nsei,
|
2014-08-04 13:42:36 +00:00
|
|
|
uint16_t ns_bvci)
|
2010-04-30 18:26:32 +00:00
|
|
|
{
|
2014-08-21 13:07:11 +00:00
|
|
|
struct bssgp_normal_hdr *bgph =
|
|
|
|
(struct bssgp_normal_hdr *) msgb_bssgph(orig_msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
struct tlv_parsed tp;
|
|
|
|
uint8_t pdu_type = bgph->pdu_type;
|
2014-08-21 13:07:11 +00:00
|
|
|
int data_len;
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2010-04-30 18:26:32 +00:00
|
|
|
uint16_t bvci;
|
2014-08-21 13:07:11 +00:00
|
|
|
struct msgb *msg;
|
2010-04-30 18:26:32 +00:00
|
|
|
int rc = 0;
|
2014-08-29 11:32:17 +00:00
|
|
|
int cause;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2011-02-06 16:13:12 +00:00
|
|
|
if (ns_bvci != 0 && ns_bvci != 1) {
|
2010-05-13 12:14:56 +00:00
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) BVCI=%u is not "
|
2013-10-15 10:00:27 +00:00
|
|
|
"signalling\n", nsei, ns_bvci);
|
2010-05-11 08:01:17 +00:00
|
|
|
/* FIXME: Send proper error message */
|
2010-04-30 18:26:32 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we actually should never see those two for BVCI == 0, but double-check
|
|
|
|
* just to make sure */
|
|
|
|
if (pdu_type == BSSGP_PDUT_UL_UNITDATA ||
|
|
|
|
pdu_type == BSSGP_PDUT_DL_UNITDATA) {
|
2010-05-03 17:22:32 +00:00
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) UNITDATA not allowed in "
|
2013-10-15 10:00:27 +00:00
|
|
|
"signalling\n", nsei);
|
2014-08-21 13:07:11 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-21 13:07:11 +00:00
|
|
|
msg = gprs_msgb_copy(orig_msg, "rx_sig_from_sgsn");
|
|
|
|
gbprox_process_bssgp_dl(cfg, msg, NULL);
|
|
|
|
/* Update message info */
|
|
|
|
bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg);
|
|
|
|
data_len = msgb_bssgp_len(orig_msg) - sizeof(*bgph);
|
2010-04-30 18:26:32 +00:00
|
|
|
rc = bssgp_tlv_parse(&tp, bgph->data, data_len);
|
|
|
|
|
|
|
|
switch (pdu_type) {
|
2010-05-11 08:01:17 +00:00
|
|
|
case BSSGP_PDUT_BVC_RESET:
|
2014-08-21 13:07:11 +00:00
|
|
|
rc = rx_reset_from_sgsn(cfg, msg, orig_msg, &tp, nsei, ns_bvci);
|
2010-05-11 08:01:17 +00:00
|
|
|
break;
|
2010-04-30 18:26:32 +00:00
|
|
|
case BSSGP_PDUT_BVC_RESET_ACK:
|
2014-08-28 11:20:39 +00:00
|
|
|
if (cfg->route_to_sgsn2 && nsei == cfg->nsip_sgsn2_nsei)
|
|
|
|
break;
|
|
|
|
/* fall through */
|
|
|
|
case BSSGP_PDUT_FLUSH_LL:
|
2010-04-30 18:26:32 +00:00
|
|
|
/* simple case: BVCI IE is mandatory */
|
|
|
|
if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI))
|
|
|
|
goto err_mand_ie;
|
2012-09-04 18:42:20 +00:00
|
|
|
bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI));
|
2014-08-04 13:42:36 +00:00
|
|
|
rc = gbprox_relay2bvci(cfg, msg, bvci, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
break;
|
|
|
|
case BSSGP_PDUT_PAGING_PS:
|
|
|
|
case BSSGP_PDUT_PAGING_CS:
|
2014-06-02 08:49:00 +00:00
|
|
|
/* process the paging request (LAI/RAI lookup) */
|
2014-08-04 13:42:36 +00:00
|
|
|
rc = gbprox_rx_paging(cfg, msg, &tp, nsei, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
break;
|
|
|
|
case BSSGP_PDUT_STATUS:
|
2010-05-11 08:01:17 +00:00
|
|
|
/* Some exception has occurred */
|
2010-05-03 17:22:32 +00:00
|
|
|
LOGP(DGPRS, LOGL_NOTICE,
|
2013-10-15 10:00:27 +00:00
|
|
|
"NSEI=%u(SGSN) BSSGP STATUS ", nsei);
|
2010-05-11 08:01:17 +00:00
|
|
|
if (!TLVP_PRESENT(&tp, BSSGP_IE_CAUSE)) {
|
|
|
|
LOGPC(DGPRS, LOGL_NOTICE, "\n");
|
|
|
|
goto err_mand_ie;
|
|
|
|
}
|
2014-08-29 11:32:17 +00:00
|
|
|
cause = *TLVP_VAL(&tp, BSSGP_IE_CAUSE);
|
2010-05-11 08:01:17 +00:00
|
|
|
LOGPC(DGPRS, LOGL_NOTICE,
|
|
|
|
"cause=0x%02x(%s) ", *TLVP_VAL(&tp, BSSGP_IE_CAUSE),
|
2014-08-29 11:32:17 +00:00
|
|
|
bssgp_cause_str(cause));
|
2010-05-11 08:01:17 +00:00
|
|
|
if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) {
|
2014-08-29 11:32:17 +00:00
|
|
|
bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI));
|
|
|
|
LOGPC(DGPRS, LOGL_NOTICE, "BVCI=%u\n", bvci);
|
|
|
|
|
|
|
|
if (cause == BSSGP_CAUSE_UNKNOWN_BVCI)
|
|
|
|
rc = gbprox_relay2bvci(cfg, msg, bvci, ns_bvci);
|
2010-05-11 08:01:17 +00:00
|
|
|
} else
|
|
|
|
LOGPC(DGPRS, LOGL_NOTICE, "\n");
|
2010-04-30 18:26:32 +00:00
|
|
|
break;
|
|
|
|
/* those only exist in the SGSN -> BSS direction */
|
|
|
|
case BSSGP_PDUT_SUSPEND_ACK:
|
|
|
|
case BSSGP_PDUT_SUSPEND_NACK:
|
|
|
|
case BSSGP_PDUT_RESUME_ACK:
|
|
|
|
case BSSGP_PDUT_RESUME_NACK:
|
2014-06-02 08:49:00 +00:00
|
|
|
/* RAI IE is mandatory */
|
2010-04-30 18:26:32 +00:00
|
|
|
if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA))
|
|
|
|
goto err_mand_ie;
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_rai(cfg, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA));
|
2010-04-30 18:26:32 +00:00
|
|
|
if (!peer)
|
|
|
|
goto err_no_peer;
|
2010-05-03 17:05:10 +00:00
|
|
|
rc = gbprox_relay2peer(msg, peer, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
break;
|
2011-02-06 12:09:29 +00:00
|
|
|
case BSSGP_PDUT_BVC_BLOCK_ACK:
|
|
|
|
case BSSGP_PDUT_BVC_UNBLOCK_ACK:
|
|
|
|
if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI))
|
|
|
|
goto err_mand_ie;
|
2012-09-04 18:42:20 +00:00
|
|
|
bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI));
|
2011-02-06 12:09:29 +00:00
|
|
|
if (bvci == 0) {
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) BSSGP "
|
2013-10-15 10:00:27 +00:00
|
|
|
"%sBLOCK_ACK for signalling BVCI ?!?\n", nsei,
|
2011-02-06 12:09:29 +00:00
|
|
|
pdu_type == BSSGP_PDUT_BVC_UNBLOCK_ACK ? "UN":"");
|
|
|
|
/* should we send STATUS ? */
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_INV_BVCI]);
|
2011-02-06 12:09:29 +00:00
|
|
|
} else {
|
|
|
|
/* Mark BVC as (un)blocked */
|
2014-08-04 13:42:36 +00:00
|
|
|
block_unblock_peer(cfg, bvci, pdu_type);
|
2011-02-06 12:09:29 +00:00
|
|
|
}
|
2014-08-04 13:42:36 +00:00
|
|
|
rc = gbprox_relay2bvci(cfg, msg, bvci, ns_bvci);
|
2011-02-06 12:09:29 +00:00
|
|
|
break;
|
2010-04-30 18:26:32 +00:00
|
|
|
case BSSGP_PDUT_SGSN_INVOKE_TRACE:
|
2010-05-03 17:22:32 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR,
|
2013-10-15 10:00:27 +00:00
|
|
|
"NSEI=%u(SGSN) BSSGP INVOKE TRACE not supported\n",nsei);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_NOT_SUPPORTED_SGSN]);
|
2014-08-21 13:07:11 +00:00
|
|
|
rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, orig_msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-05-11 22:20:41 +00:00
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "BSSGP PDU type 0x%02x unknown\n",
|
|
|
|
pdu_type);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_PROTO_ERR_SGSN]);
|
2014-08-21 13:07:11 +00:00
|
|
|
rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-21 13:07:11 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
return rc;
|
|
|
|
err_mand_ie:
|
2010-05-03 19:37:11 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) missing mandatory IE\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_PROTO_ERR_SGSN]);
|
2014-08-21 13:07:11 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, orig_msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
err_no_peer:
|
2014-06-02 08:49:00 +00:00
|
|
|
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) cannot find peer based on RAI\n",
|
2013-10-15 10:00:27 +00:00
|
|
|
nsei);
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg-> ctr[GBPROX_GLOB_CTR_INV_RAI]);
|
2014-08-21 13:07:11 +00:00
|
|
|
msgb_free(msg);
|
2014-08-29 10:20:15 +00:00
|
|
|
return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, orig_msg);
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
static int gbproxy_is_sgsn_nsei(struct gbproxy_config *cfg, uint16_t nsei)
|
|
|
|
{
|
|
|
|
return nsei == cfg->nsip_sgsn_nsei ||
|
|
|
|
(cfg->route_to_sgsn2 && nsei == cfg->nsip_sgsn2_nsei);
|
|
|
|
}
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
/* Main input function for Gb proxy */
|
2014-08-04 13:42:36 +00:00
|
|
|
int gbprox_rcvmsg(struct gbproxy_config *cfg, struct msgb *msg, uint16_t nsei,
|
|
|
|
uint16_t ns_bvci, uint16_t nsvci)
|
2010-04-30 18:26:32 +00:00
|
|
|
{
|
2010-05-03 16:54:58 +00:00
|
|
|
int rc;
|
2014-08-26 12:47:15 +00:00
|
|
|
int remote_end_is_sgsn = gbproxy_is_sgsn_nsei(cfg, nsei);
|
2010-04-30 18:26:32 +00:00
|
|
|
|
|
|
|
/* Only BVCI=0 messages need special treatment */
|
|
|
|
if (ns_bvci == 0 || ns_bvci == 1) {
|
2013-10-15 10:00:27 +00:00
|
|
|
if (remote_end_is_sgsn)
|
2014-08-04 13:42:36 +00:00
|
|
|
rc = gbprox_rx_sig_from_sgsn(cfg, msg, nsei, ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
else
|
2014-08-04 13:42:36 +00:00
|
|
|
rc = gbprox_rx_sig_from_bss(cfg, msg, nsei, ns_bvci);
|
2010-05-03 16:54:58 +00:00
|
|
|
} else {
|
2014-08-21 11:45:04 +00:00
|
|
|
/* All other BVCI are PTP */
|
|
|
|
if (remote_end_is_sgsn)
|
|
|
|
rc = gbprox_rx_ptp_from_sgsn(cfg, msg, nsei, nsvci,
|
|
|
|
ns_bvci);
|
|
|
|
else
|
|
|
|
rc = gbprox_rx_ptp_from_bss(cfg, msg, nsei, nsvci,
|
|
|
|
ns_bvci);
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-03 16:54:58 +00:00
|
|
|
return rc;
|
2010-04-30 18:26:32 +00:00
|
|
|
}
|
2010-05-11 03:49:43 +00:00
|
|
|
|
2010-05-14 11:53:08 +00:00
|
|
|
int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi)
|
|
|
|
{
|
|
|
|
struct gprs_nsvc *nsvc;
|
|
|
|
|
|
|
|
llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
|
|
|
|
if (!nsvc->persistent)
|
|
|
|
continue;
|
|
|
|
gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-11 04:34:24 +00:00
|
|
|
/* Signal handler for signals from NS layer */
|
|
|
|
int gbprox_signal(unsigned int subsys, unsigned int signal,
|
|
|
|
void *handler_data, void *signal_data)
|
|
|
|
{
|
2014-08-04 13:42:36 +00:00
|
|
|
struct gbproxy_config *cfg = handler_data;
|
2010-05-11 04:34:24 +00:00
|
|
|
struct ns_signal_data *nssd = signal_data;
|
|
|
|
struct gprs_nsvc *nsvc = nssd->nsvc;
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2014-08-26 12:47:15 +00:00
|
|
|
int remote_end_is_sgsn = gbproxy_is_sgsn_nsei(cfg, nsvc->nsei);
|
2010-05-11 04:34:24 +00:00
|
|
|
|
2012-06-16 08:40:42 +00:00
|
|
|
if (subsys != SS_L_NS)
|
2010-05-11 04:34:24 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
if (signal == S_NS_RESET && remote_end_is_sgsn) {
|
2010-05-11 16:29:44 +00:00
|
|
|
/* We have received a NS-RESET from the NSEI and NSVC
|
|
|
|
* of the SGSN. This might happen with SGSN that start
|
|
|
|
* their own NS-RESET procedure without waiting for our
|
|
|
|
* NS-RESET */
|
|
|
|
nsvc->remote_end_is_sgsn = 1;
|
|
|
|
}
|
|
|
|
|
2010-05-12 13:28:25 +00:00
|
|
|
if (signal == S_NS_ALIVE_EXP && nsvc->remote_end_is_sgsn) {
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "Tns alive expired too often, "
|
|
|
|
"re-starting RESET procedure\n");
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_inc(&cfg->ctrg->
|
2013-10-18 12:34:55 +00:00
|
|
|
ctr[GBPROX_GLOB_CTR_RESTART_RESET_SGSN]);
|
2012-06-17 04:25:53 +00:00
|
|
|
gprs_ns_nsip_connect(nsvc->nsi, &nsvc->ip.bts_addr,
|
|
|
|
nsvc->nsei, nsvc->nsvci);
|
2010-05-12 13:28:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-06 15:33:29 +00:00
|
|
|
if (!nsvc->remote_end_is_sgsn) {
|
|
|
|
/* from BSS to SGSN */
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_nsei(cfg, nsvc->nsei);
|
2011-02-06 15:33:29 +00:00
|
|
|
if (!peer) {
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "signal %u for unknown peer "
|
|
|
|
"NSEI=%u/NSVCI=%u\n", signal, nsvc->nsei,
|
|
|
|
nsvc->nsvci);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-11 04:34:24 +00:00
|
|
|
switch (signal) {
|
|
|
|
case S_NS_RESET:
|
|
|
|
case S_NS_BLOCK:
|
2011-02-06 15:33:29 +00:00
|
|
|
if (!peer->blocked)
|
|
|
|
break;
|
|
|
|
LOGP(DGPRS, LOGL_NOTICE, "Converting NS_RESET from "
|
|
|
|
"NSEI=%u/NSVCI=%u into BSSGP_BVC_BLOCK to SGSN\n",
|
|
|
|
nsvc->nsei, nsvc->nsvci);
|
|
|
|
bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK, nsvc->nsei,
|
|
|
|
peer->bvci, 0);
|
2010-05-11 04:34:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-02-06 15:33:29 +00:00
|
|
|
} else {
|
2013-10-15 10:00:27 +00:00
|
|
|
/* Forward this message to all NS-VC to BSS */
|
2014-08-04 13:42:36 +00:00
|
|
|
struct gprs_ns_inst *nsi = cfg->nsi;
|
2013-10-15 10:00:27 +00:00
|
|
|
struct gprs_nsvc *next_nsvc;
|
|
|
|
|
|
|
|
llist_for_each_entry(next_nsvc, &nsi->gprs_nsvcs, list) {
|
|
|
|
if (next_nsvc->remote_end_is_sgsn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Note that the following does not start the full
|
|
|
|
* procedures including timer based retransmissions. */
|
2011-02-06 15:33:29 +00:00
|
|
|
switch (signal) {
|
|
|
|
case S_NS_RESET:
|
2013-10-15 10:00:27 +00:00
|
|
|
gprs_ns_tx_reset(next_nsvc, nssd->cause);
|
2011-02-06 15:33:29 +00:00
|
|
|
break;
|
|
|
|
case S_NS_BLOCK:
|
2013-10-15 10:00:27 +00:00
|
|
|
gprs_ns_tx_block(next_nsvc, nssd->cause);
|
2011-02-06 15:33:29 +00:00
|
|
|
break;
|
|
|
|
case S_NS_UNBLOCK:
|
2013-10-15 10:00:27 +00:00
|
|
|
gprs_ns_tx_unblock(next_nsvc);
|
2011-02-06 15:33:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-11 04:34:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-04 13:42:36 +00:00
|
|
|
void gbprox_reset(struct gbproxy_config *cfg)
|
2013-10-24 10:48:55 +00:00
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer, *tmp;
|
2013-10-24 10:48:55 +00:00
|
|
|
|
2014-08-04 13:42:36 +00:00
|
|
|
llist_for_each_entry_safe(peer, tmp, &cfg->bts_peers, list)
|
2014-08-04 15:10:08 +00:00
|
|
|
gbproxy_peer_free(peer);
|
2013-10-24 10:48:55 +00:00
|
|
|
|
2014-08-04 13:42:36 +00:00
|
|
|
rate_ctr_group_free(cfg->ctrg);
|
|
|
|
gbproxy_init_config(cfg);
|
2013-10-24 10:48:55 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 09:10:09 +00:00
|
|
|
int gbproxy_init_config(struct gbproxy_config *cfg)
|
2013-10-24 10:48:23 +00:00
|
|
|
{
|
2014-08-11 17:12:24 +00:00
|
|
|
struct timespec tp;
|
2014-09-25 09:17:31 +00:00
|
|
|
|
2014-08-04 09:10:09 +00:00
|
|
|
INIT_LLIST_HEAD(&cfg->bts_peers);
|
2014-08-04 09:19:56 +00:00
|
|
|
cfg->ctrg = rate_ctr_group_alloc(tall_bsc_ctx, &global_ctrg_desc, 0);
|
2014-08-11 17:12:24 +00:00
|
|
|
clock_gettime(CLOCK_REALTIME, &tp);
|
|
|
|
cfg->bss_ptmsi_state = tp.tv_sec + tp.tv_nsec;
|
|
|
|
cfg->sgsn_tlli_state = tp.tv_sec - tp.tv_nsec;
|
2014-09-25 09:17:31 +00:00
|
|
|
|
2014-08-04 09:10:09 +00:00
|
|
|
return 0;
|
2014-06-19 08:15:27 +00:00
|
|
|
}
|