2010-06-15 10:44:42 +00:00
|
|
|
/* BSC Multiplexer/NAT */
|
|
|
|
|
|
|
|
/*
|
2013-04-16 11:23:43 +00:00
|
|
|
* (C) 2010-2013 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2010-2013 by On-Waves
|
2010-01-12 20:34:54 +00:00
|
|
|
* (C) 2009 by Harald Welte <laforge@gnumonks.org>
|
2010-06-15 10:44:42 +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-06-15 10:44:42 +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-06-15 10:44:42 +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-06-15 10:44:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2010-05-05 10:58:13 +00:00
|
|
|
#include <netinet/tcp.h>
|
2010-06-15 10:44:42 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2010-01-12 20:34:54 +00:00
|
|
|
#include <errno.h>
|
2010-01-12 20:15:08 +00:00
|
|
|
#include <signal.h>
|
2010-06-15 10:44:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-01-12 20:36:08 +00:00
|
|
|
#include <time.h>
|
2010-06-15 10:44:42 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include <openbsc/debug.h>
|
2010-01-12 20:15:08 +00:00
|
|
|
#include <openbsc/bsc_msc.h>
|
2010-06-15 10:45:26 +00:00
|
|
|
#include <openbsc/bsc_nat.h>
|
2010-07-30 21:17:17 +00:00
|
|
|
#include <openbsc/bsc_nat_sccp.h>
|
2010-01-12 20:15:08 +00:00
|
|
|
#include <openbsc/ipaccess.h>
|
|
|
|
#include <openbsc/abis_nm.h>
|
2010-10-12 21:28:28 +00:00
|
|
|
#include <openbsc/socket.h>
|
2010-06-15 12:14:08 +00:00
|
|
|
#include <openbsc/vty.h>
|
2010-06-15 10:46:11 +00:00
|
|
|
|
2014-08-20 21:47:15 +00:00
|
|
|
#include <osmocom/ctrl/control_cmd.h>
|
|
|
|
#include <osmocom/ctrl/control_if.h>
|
2011-07-22 15:55:42 +00:00
|
|
|
|
2011-05-12 14:02:07 +00:00
|
|
|
#include <osmocom/core/application.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2010-06-15 11:06:18 +00:00
|
|
|
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
#include <osmocom/gsm/tlv.h>
|
2011-05-12 14:02:07 +00:00
|
|
|
#include <osmocom/gsm/gsm0808.h>
|
2011-03-23 17:26:56 +00:00
|
|
|
#include <osmocom/gsm/protocol/gsm_08_08.h>
|
2010-06-15 10:44:42 +00:00
|
|
|
|
2010-06-15 12:14:08 +00:00
|
|
|
#include <osmocom/vty/telnet_interface.h>
|
|
|
|
#include <osmocom/vty/vty.h>
|
2011-03-09 12:36:32 +00:00
|
|
|
#include <osmocom/vty/logging.h>
|
2014-08-24 15:54:49 +00:00
|
|
|
#include <osmocom/vty/ports.h>
|
2010-06-15 12:14:08 +00:00
|
|
|
|
2010-08-03 13:11:51 +00:00
|
|
|
#include <osmocom/sccp/sccp.h>
|
2010-06-15 10:45:26 +00:00
|
|
|
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
#include <osmocom/abis/ipa.h>
|
|
|
|
|
2010-06-15 12:14:08 +00:00
|
|
|
#include "../../bscconfig.h"
|
|
|
|
|
2010-06-15 10:51:56 +00:00
|
|
|
#define SCCP_CLOSE_TIME 20
|
|
|
|
#define SCCP_CLOSE_TIME_TIMEOUT 19
|
|
|
|
|
2010-06-15 10:46:11 +00:00
|
|
|
static const char *config_file = "bsc-nat.cfg";
|
2010-06-15 10:44:42 +00:00
|
|
|
static struct in_addr local_addr;
|
2011-05-06 10:11:23 +00:00
|
|
|
static struct osmo_fd bsc_listen;
|
2010-06-15 10:51:04 +00:00
|
|
|
static const char *msc_ip = NULL;
|
2011-05-06 10:11:06 +00:00
|
|
|
static struct osmo_timer_list sccp_close;
|
2010-08-25 17:43:54 +00:00
|
|
|
static int daemonize = 0;
|
2010-01-12 20:15:08 +00:00
|
|
|
|
2010-06-15 12:14:08 +00:00
|
|
|
const char *openbsc_copyright =
|
2010-09-11 05:32:30 +00:00
|
|
|
"Copyright (C) 2010 Holger Hans Peter Freyther and On-Waves\r\n"
|
2011-01-01 14:25:50 +00:00
|
|
|
"License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
|
2010-09-11 05:32:30 +00:00
|
|
|
"This is free software: you are free to change and redistribute it.\r\n"
|
|
|
|
"There is NO WARRANTY, to the extent permitted by law.\r\n";
|
2010-01-13 08:28:12 +00:00
|
|
|
|
2010-06-15 10:46:11 +00:00
|
|
|
static struct bsc_nat *nat;
|
2010-07-23 11:08:55 +00:00
|
|
|
static void bsc_send_data(struct bsc_connection *bsc, const uint8_t *data, unsigned int length, int);
|
2010-04-07 09:20:36 +00:00
|
|
|
static void msc_send_reset(struct bsc_msc_connection *con);
|
2010-09-25 09:58:22 +00:00
|
|
|
static void bsc_stat_reject(int filter, struct bsc_connection *bsc, int normal);
|
2010-06-15 10:46:11 +00:00
|
|
|
|
|
|
|
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num)
|
|
|
|
{
|
|
|
|
struct bsc_config *conf;
|
|
|
|
|
|
|
|
llist_for_each_entry(conf, &nat->bsc_configs, entry)
|
|
|
|
if (conf->nr == num)
|
|
|
|
return conf;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-13 08:28:12 +00:00
|
|
|
|
2010-04-22 11:11:37 +00:00
|
|
|
static void queue_for_msc(struct bsc_msc_connection *con, struct msgb *msg)
|
|
|
|
{
|
2010-10-05 16:24:28 +00:00
|
|
|
if (!con) {
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
LOGP(DLINP, LOGL_ERROR, "No MSC Connection assigned. Check your code.\n");
|
2010-10-05 16:24:28 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-06 10:09:47 +00:00
|
|
|
if (osmo_wqueue_enqueue(&con->write_queue, msg) != 0) {
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
LOGP(DLINP, LOGL_ERROR, "Failed to enqueue the write.\n");
|
2010-04-22 11:11:37 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-26 08:18:02 +00:00
|
|
|
static void send_reset_ack(struct bsc_connection *bsc)
|
2010-01-30 11:45:10 +00:00
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t gsm_reset_ack[] = {
|
2010-01-30 11:45:10 +00:00
|
|
|
0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
|
|
|
|
0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
|
|
|
|
0x00, 0x01, 0x31,
|
|
|
|
};
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
bsc_send_data(bsc, gsm_reset_ack, sizeof(gsm_reset_ack), IPAC_PROTO_SCCP);
|
2010-01-30 11:45:10 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 11:28:59 +00:00
|
|
|
static void send_ping(struct bsc_connection *bsc)
|
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t id_ping[] = {
|
2010-05-02 11:28:59 +00:00
|
|
|
IPAC_MSGT_PING,
|
|
|
|
};
|
|
|
|
|
|
|
|
bsc_send_data(bsc, id_ping, sizeof(id_ping), IPAC_PROTO_IPACCESS);
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:51:33 +00:00
|
|
|
static void send_pong(struct bsc_connection *bsc)
|
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t id_pong[] = {
|
2010-06-15 10:51:33 +00:00
|
|
|
IPAC_MSGT_PONG,
|
|
|
|
};
|
|
|
|
|
|
|
|
bsc_send_data(bsc, id_pong, sizeof(id_pong), IPAC_PROTO_IPACCESS);
|
|
|
|
}
|
|
|
|
|
2010-05-02 11:28:59 +00:00
|
|
|
static void bsc_pong_timeout(void *_bsc)
|
|
|
|
{
|
|
|
|
struct bsc_connection *bsc = _bsc;
|
|
|
|
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "BSC Nr: %d PONG timeout.\n", bsc->cfg->nr);
|
|
|
|
bsc_close_connection(bsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bsc_ping_timeout(void *_bsc)
|
|
|
|
{
|
|
|
|
struct bsc_connection *bsc = _bsc;
|
|
|
|
|
2010-05-05 08:57:38 +00:00
|
|
|
if (bsc->nat->ping_timeout < 0)
|
|
|
|
return;
|
|
|
|
|
2010-05-02 11:28:59 +00:00
|
|
|
send_ping(bsc);
|
|
|
|
|
|
|
|
/* send another ping in 20 seconds */
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&bsc->ping_timeout, bsc->nat->ping_timeout, 0);
|
2010-05-02 11:28:59 +00:00
|
|
|
|
|
|
|
/* also start a pong timer */
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&bsc->pong_timeout, bsc->nat->pong_timeout, 0);
|
2010-05-02 11:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void start_ping_pong(struct bsc_connection *bsc)
|
|
|
|
{
|
|
|
|
bsc->pong_timeout.data = bsc;
|
|
|
|
bsc->pong_timeout.cb = bsc_pong_timeout;
|
|
|
|
bsc->ping_timeout.data = bsc;
|
|
|
|
bsc->ping_timeout.cb = bsc_ping_timeout;
|
|
|
|
|
|
|
|
bsc_ping_timeout(bsc);
|
|
|
|
}
|
|
|
|
|
2010-03-26 08:18:02 +00:00
|
|
|
static void send_id_ack(struct bsc_connection *bsc)
|
2010-03-26 06:41:54 +00:00
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t id_ack[] = {
|
2010-04-08 08:24:57 +00:00
|
|
|
IPAC_MSGT_ID_ACK
|
2010-03-26 06:41:54 +00:00
|
|
|
};
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
bsc_send_data(bsc, id_ack, sizeof(id_ack), IPAC_PROTO_IPACCESS);
|
2010-03-26 06:41:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 08:18:02 +00:00
|
|
|
static void send_id_req(struct bsc_connection *bsc)
|
2010-03-26 06:41:54 +00:00
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t id_req[] = {
|
2010-04-08 08:24:57 +00:00
|
|
|
IPAC_MSGT_ID_GET,
|
2010-03-26 06:41:54 +00:00
|
|
|
0x01, IPAC_IDTAG_UNIT,
|
|
|
|
0x01, IPAC_IDTAG_MACADDR,
|
|
|
|
0x01, IPAC_IDTAG_LOCATION1,
|
|
|
|
0x01, IPAC_IDTAG_LOCATION2,
|
|
|
|
0x01, IPAC_IDTAG_EQUIPVERS,
|
|
|
|
0x01, IPAC_IDTAG_SWVERSION,
|
|
|
|
0x01, IPAC_IDTAG_UNITNAME,
|
|
|
|
0x01, IPAC_IDTAG_SERNR,
|
|
|
|
};
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
bsc_send_data(bsc, id_req, sizeof(id_req), IPAC_PROTO_IPACCESS);
|
2010-03-26 06:41:54 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static struct msgb *nat_create_rlsd(struct nat_sccp_connection *conn)
|
2010-04-06 15:32:58 +00:00
|
|
|
{
|
|
|
|
struct sccp_connection_released *rel;
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
msg = msgb_alloc_headroom(4096, 128, "rlsd");
|
|
|
|
if (!msg) {
|
2011-04-16 15:01:47 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate released.\n");
|
|
|
|
return NULL;
|
2010-04-06 15:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*rel));
|
|
|
|
rel = (struct sccp_connection_released *) msg->l2h;
|
|
|
|
rel->type = SCCP_MSG_TYPE_RLSD;
|
|
|
|
rel->release_cause = SCCP_RELEASE_CAUSE_SCCP_FAILURE;
|
|
|
|
rel->destination_local_reference = conn->remote_ref;
|
|
|
|
rel->source_local_reference = conn->patched_ref;
|
|
|
|
|
2011-04-16 15:01:47 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static void nat_send_rlsd_ussd(struct bsc_nat *nat, struct nat_sccp_connection *conn)
|
2011-04-16 15:01:47 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
if (!nat->ussd_con)
|
|
|
|
return;
|
|
|
|
|
|
|
|
msg = nat_create_rlsd(conn);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
2010-04-06 15:32:58 +00:00
|
|
|
|
2011-04-16 15:01:47 +00:00
|
|
|
bsc_do_write(&nat->ussd_con->queue, msg, IPAC_PROTO_SCCP);
|
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static void nat_send_rlsd_msc(struct nat_sccp_connection *conn)
|
2011-04-16 15:01:47 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
msg = nat_create_rlsd(conn);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
2014-08-20 21:46:40 +00:00
|
|
|
ipa_prepend_header(msg, IPAC_PROTO_SCCP);
|
2010-07-05 05:58:40 +00:00
|
|
|
queue_for_msc(conn->msc_con, msg);
|
2010-04-06 15:32:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static void nat_send_rlsd_bsc(struct nat_sccp_connection *conn)
|
2010-10-27 09:01:55 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
2011-04-16 15:01:47 +00:00
|
|
|
struct sccp_connection_released *rel;
|
2010-10-27 09:01:55 +00:00
|
|
|
|
|
|
|
msg = msgb_alloc_headroom(4096, 128, "rlsd");
|
|
|
|
if (!msg) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*rel));
|
|
|
|
rel = (struct sccp_connection_released *) msg->l2h;
|
|
|
|
rel->type = SCCP_MSG_TYPE_RLSD;
|
|
|
|
rel->release_cause = SCCP_RELEASE_CAUSE_SCCP_FAILURE;
|
|
|
|
rel->destination_local_reference = conn->real_ref;
|
|
|
|
rel->source_local_reference = conn->remote_ref;
|
|
|
|
|
|
|
|
bsc_write(conn->bsc, msg, IPAC_PROTO_SCCP);
|
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static struct msgb *nat_creat_clrc(struct nat_sccp_connection *conn, uint8_t cause)
|
2010-10-27 09:58:04 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg;
|
|
|
|
struct msgb *sccp;
|
|
|
|
|
2010-10-29 15:05:28 +00:00
|
|
|
msg = gsm0808_create_clear_command(cause);
|
2010-10-27 09:58:04 +00:00
|
|
|
if (!msg) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
|
2010-10-29 15:05:28 +00:00
|
|
|
return NULL;
|
2010-10-27 09:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sccp = sccp_create_dt1(&conn->real_ref, msg->data, msg->len);
|
|
|
|
if (!sccp) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate SCCP msg.\n");
|
|
|
|
msgb_free(msg);
|
2010-10-29 15:05:28 +00:00
|
|
|
return NULL;
|
2010-10-27 09:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msgb_free(msg);
|
2010-10-29 15:05:28 +00:00
|
|
|
return sccp;
|
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static int nat_send_clrc_bsc(struct nat_sccp_connection *conn)
|
2010-10-29 15:05:28 +00:00
|
|
|
{
|
|
|
|
struct msgb *sccp;
|
|
|
|
|
|
|
|
sccp = nat_creat_clrc(conn, 0x20);
|
|
|
|
if (!sccp)
|
|
|
|
return -1;
|
|
|
|
return bsc_write(conn->bsc, sccp, IPAC_PROTO_SCCP);
|
2010-10-27 09:58:04 +00:00
|
|
|
}
|
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
static void nat_send_rlc(struct bsc_msc_connection *msc_con,
|
|
|
|
struct sccp_source_reference *src,
|
2010-04-08 09:28:12 +00:00
|
|
|
struct sccp_source_reference *dst)
|
|
|
|
{
|
|
|
|
struct sccp_connection_release_complete *rlc;
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
msg = msgb_alloc_headroom(4096, 128, "rlc");
|
|
|
|
if (!msg) {
|
2013-09-03 09:25:16 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to sccp rlc.\n");
|
2010-04-08 09:28:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*rlc));
|
|
|
|
rlc = (struct sccp_connection_release_complete *) msg->l2h;
|
|
|
|
rlc->type = SCCP_MSG_TYPE_RLC;
|
|
|
|
rlc->destination_local_reference = *dst;
|
|
|
|
rlc->source_local_reference = *src;
|
|
|
|
|
2014-08-20 21:46:40 +00:00
|
|
|
ipa_prepend_header(msg, IPAC_PROTO_SCCP);
|
2010-04-08 09:28:12 +00:00
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
queue_for_msc(msc_con, msg);
|
2010-04-08 09:28:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 05:30:58 +00:00
|
|
|
static void send_mgcp_reset(struct bsc_connection *bsc)
|
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t mgcp_reset[] = {
|
2010-03-31 05:30:58 +00:00
|
|
|
"RSIP 1 13@mgw MGCP 1.0\r\n"
|
|
|
|
};
|
|
|
|
|
|
|
|
bsc_write_mgcp(bsc, mgcp_reset, sizeof mgcp_reset - 1);
|
|
|
|
}
|
|
|
|
|
2012-11-05 13:54:56 +00:00
|
|
|
void bsc_nat_send_mgcp_to_msc(struct bsc_nat *nat, struct msgb *msg)
|
|
|
|
{
|
2014-08-20 21:46:40 +00:00
|
|
|
ipa_prepend_header(msg, IPAC_PROTO_MGCP_OLD);
|
2012-11-05 13:54:56 +00:00
|
|
|
queue_for_msc(nat->msc_con, msg);
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:15:08 +00:00
|
|
|
/*
|
|
|
|
* Below is the handling of messages coming
|
|
|
|
* from the MSC and need to be forwarded to
|
|
|
|
* a real BSC.
|
|
|
|
*/
|
2010-07-05 06:14:18 +00:00
|
|
|
static void initialize_msc_if_needed(struct bsc_msc_connection *msc_con)
|
2010-01-12 20:15:08 +00:00
|
|
|
{
|
2010-07-05 06:14:18 +00:00
|
|
|
if (msc_con->first_contact)
|
2010-04-07 09:20:36 +00:00
|
|
|
return;
|
2010-01-12 20:15:08 +00:00
|
|
|
|
2010-07-05 06:14:18 +00:00
|
|
|
msc_con->first_contact = 1;
|
|
|
|
msc_send_reset(msc_con);
|
2010-01-12 20:15:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
static void send_id_get_response(struct bsc_msc_connection *msc_con)
|
2010-05-14 16:14:58 +00:00
|
|
|
{
|
|
|
|
struct msgb *msg = bsc_msc_id_get_resp(nat->token);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
2014-08-20 21:46:40 +00:00
|
|
|
ipa_prepend_header(msg, IPAC_PROTO_IPACCESS);
|
2010-07-05 05:58:40 +00:00
|
|
|
queue_for_msc(msc_con, msg);
|
2010-05-14 16:14:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 08:18:02 +00:00
|
|
|
/*
|
|
|
|
* Currently we are lacking refcounting so we need to copy each message.
|
|
|
|
*/
|
2010-07-23 11:08:55 +00:00
|
|
|
static void bsc_send_data(struct bsc_connection *bsc, const uint8_t *data, unsigned int length, int proto)
|
2010-03-26 06:20:59 +00:00
|
|
|
{
|
2010-03-26 08:18:02 +00:00
|
|
|
struct msgb *msg;
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
if (length > 4096 - 128) {
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
LOGP(DLINP, LOGL_ERROR, "Can not send message of that size.\n");
|
2010-03-26 08:18:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
msg = msgb_alloc_headroom(4096, 128, "to-bsc");
|
2010-03-26 08:18:02 +00:00
|
|
|
if (!msg) {
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
LOGP(DLINP, LOGL_ERROR, "Failed to allocate memory for BSC msg.\n");
|
2010-03-26 08:18:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
msg->l2h = msgb_put(msg, length);
|
2010-03-26 08:18:02 +00:00
|
|
|
memcpy(msg->data, data, length);
|
2010-04-08 08:24:57 +00:00
|
|
|
|
|
|
|
bsc_write(bsc, msg, proto);
|
2010-03-26 06:20:59 +00:00
|
|
|
}
|
|
|
|
|
2010-09-25 09:58:22 +00:00
|
|
|
/*
|
|
|
|
* Update the release statistics
|
|
|
|
*/
|
|
|
|
static void bsc_stat_reject(int filter, struct bsc_connection *bsc, int normal)
|
|
|
|
{
|
|
|
|
if (!bsc->cfg) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "BSC is not authenticated.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter >= 0) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Connection was not rejected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter == -1)
|
|
|
|
rate_ctr_inc(&bsc->cfg->stats.ctrg->ctr[BCFG_CTR_ILL_PACKET]);
|
|
|
|
else if (normal)
|
|
|
|
rate_ctr_inc(&bsc->cfg->stats.ctrg->ctr[BCFG_CTR_REJECTED_MSG]);
|
|
|
|
else
|
|
|
|
rate_ctr_inc(&bsc->cfg->stats.ctrg->ctr[BCFG_CTR_REJECTED_CR]);
|
|
|
|
}
|
|
|
|
|
2010-09-14 23:43:59 +00:00
|
|
|
/*
|
|
|
|
* Release an established connection. We will have to release it to the BSC
|
|
|
|
* and to the network and we do it the following way.
|
|
|
|
* 1.) Give up on the MSC side
|
|
|
|
* 1.1) Send a RLSD message, it is a bit non standard but should work, we
|
|
|
|
* ignore the RLC... we might complain about it. Other options would
|
|
|
|
* be to send a Release Request, handle the Release Complete..
|
|
|
|
* 1.2) Mark the data structure to be con_local and wait for 2nd
|
|
|
|
*
|
|
|
|
* 2.) Give up on the BSC side
|
|
|
|
* 2.1) Depending on the con type reject the service, or just close it
|
|
|
|
*/
|
2012-12-17 13:35:03 +00:00
|
|
|
static void bsc_send_con_release(struct bsc_connection *bsc,
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *con,
|
2012-12-17 13:35:03 +00:00
|
|
|
struct bsc_nat_reject_cause *cause)
|
2010-09-14 23:43:59 +00:00
|
|
|
{
|
|
|
|
struct msgb *rlsd;
|
|
|
|
/* 1. release the network */
|
|
|
|
rlsd = sccp_create_rlsd(&con->patched_ref, &con->remote_ref,
|
|
|
|
SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
|
|
|
|
if (!rlsd)
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to create RLSD message.\n");
|
|
|
|
else {
|
2014-08-20 21:46:40 +00:00
|
|
|
ipa_prepend_header(rlsd, IPAC_PROTO_SCCP);
|
2010-09-14 23:43:59 +00:00
|
|
|
queue_for_msc(con->msc_con, rlsd);
|
|
|
|
}
|
2011-04-16 14:02:59 +00:00
|
|
|
con->con_local = NAT_CON_END_LOCAL;
|
2010-09-15 22:41:09 +00:00
|
|
|
con->msc_con = NULL;
|
2010-09-14 23:43:59 +00:00
|
|
|
|
|
|
|
/* 2. release the BSC side */
|
|
|
|
if (con->con_type == NAT_CON_TYPE_LU) {
|
|
|
|
struct msgb *payload, *udt;
|
2012-12-17 13:35:03 +00:00
|
|
|
payload = gsm48_create_loc_upd_rej(cause->lu_reject_cause);
|
2010-09-14 23:43:59 +00:00
|
|
|
|
|
|
|
if (payload) {
|
|
|
|
gsm0808_prepend_dtap_header(payload, 0);
|
|
|
|
udt = sccp_create_dt1(&con->real_ref, payload->data, payload->len);
|
|
|
|
if (udt)
|
|
|
|
bsc_write(bsc, udt, IPAC_PROTO_SCCP);
|
|
|
|
else
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to create DT1\n");
|
|
|
|
|
|
|
|
msgb_free(payload);
|
|
|
|
} else {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate LU Reject.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-29 15:05:28 +00:00
|
|
|
nat_send_clrc_bsc(con);
|
|
|
|
|
2010-09-14 23:43:59 +00:00
|
|
|
rlsd = sccp_create_rlsd(&con->remote_ref, &con->real_ref,
|
|
|
|
SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
|
|
|
|
if (!rlsd) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate RLSD for the BSC.\n");
|
|
|
|
sccp_connection_destroy(con);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
con->con_type = NAT_CON_TYPE_LOCAL_REJECT;
|
|
|
|
bsc_write(bsc, rlsd, IPAC_PROTO_SCCP);
|
|
|
|
}
|
|
|
|
|
2010-05-15 18:20:26 +00:00
|
|
|
static void bsc_send_con_refuse(struct bsc_connection *bsc,
|
2012-12-17 13:35:03 +00:00
|
|
|
struct bsc_nat_parsed *parsed, int con_type,
|
|
|
|
struct bsc_nat_reject_cause *cause)
|
2010-05-15 18:20:26 +00:00
|
|
|
{
|
2010-06-15 10:52:24 +00:00
|
|
|
struct msgb *payload;
|
2010-05-15 18:20:26 +00:00
|
|
|
struct msgb *refuse;
|
2010-06-15 10:52:24 +00:00
|
|
|
|
2010-05-16 12:43:52 +00:00
|
|
|
if (con_type == NAT_CON_TYPE_LU)
|
2012-12-17 13:35:03 +00:00
|
|
|
payload = gsm48_create_loc_upd_rej(cause->lu_reject_cause);
|
2013-01-01 15:50:40 +00:00
|
|
|
else if (con_type == NAT_CON_TYPE_CM_SERV_REQ || con_type == NAT_CON_TYPE_SSA)
|
2012-12-17 13:35:03 +00:00
|
|
|
payload = gsm48_create_mm_serv_rej(cause->cm_reject_cause);
|
2010-07-23 11:43:12 +00:00
|
|
|
else {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Unknown connection type: %d\n", con_type);
|
|
|
|
payload = NULL;
|
|
|
|
}
|
2010-05-16 12:43:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some BSCs do not handle the payload inside a SCCP CREF msg
|
|
|
|
* so we will need to:
|
|
|
|
* 1.) Allocate a local connection and mark it as local..
|
|
|
|
* 2.) queue data for downstream.. and the RLC should delete everything
|
|
|
|
*/
|
|
|
|
if (payload) {
|
2010-10-29 15:05:28 +00:00
|
|
|
struct msgb *cc, *udt, *clear, *rlsd;
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *con;
|
2010-05-16 12:43:52 +00:00
|
|
|
con = create_sccp_src_ref(bsc, parsed);
|
|
|
|
if (!con)
|
|
|
|
goto send_refuse;
|
|
|
|
|
|
|
|
/* declare it local and assign a unique remote_ref */
|
|
|
|
con->con_type = NAT_CON_TYPE_LOCAL_REJECT;
|
2011-04-16 14:02:59 +00:00
|
|
|
con->con_local = NAT_CON_END_LOCAL;
|
2010-05-16 12:43:52 +00:00
|
|
|
con->has_remote_ref = 1;
|
|
|
|
con->remote_ref = con->patched_ref;
|
|
|
|
|
|
|
|
/* 1. create a confirmation */
|
|
|
|
cc = sccp_create_cc(&con->remote_ref, &con->real_ref);
|
|
|
|
if (!cc)
|
|
|
|
goto send_refuse;
|
|
|
|
|
|
|
|
/* 2. create the DT1 */
|
2010-06-15 10:52:24 +00:00
|
|
|
gsm0808_prepend_dtap_header(payload, 0);
|
2010-05-16 12:43:52 +00:00
|
|
|
udt = sccp_create_dt1(&con->real_ref, payload->data, payload->len);
|
|
|
|
if (!udt) {
|
|
|
|
msgb_free(cc);
|
|
|
|
goto send_refuse;
|
|
|
|
}
|
|
|
|
|
2010-10-29 15:05:28 +00:00
|
|
|
/* 3. send a Clear Command */
|
|
|
|
clear = nat_creat_clrc(con, 0x20);
|
|
|
|
if (!clear) {
|
|
|
|
msgb_free(cc);
|
|
|
|
msgb_free(udt);
|
|
|
|
goto send_refuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 4. send a RLSD */
|
2010-05-16 12:43:52 +00:00
|
|
|
rlsd = sccp_create_rlsd(&con->remote_ref, &con->real_ref,
|
|
|
|
SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
|
|
|
|
if (!rlsd) {
|
|
|
|
msgb_free(cc);
|
|
|
|
msgb_free(udt);
|
2010-10-29 15:05:28 +00:00
|
|
|
msgb_free(clear);
|
2010-05-16 12:43:52 +00:00
|
|
|
goto send_refuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
bsc_write(bsc, cc, IPAC_PROTO_SCCP);
|
|
|
|
bsc_write(bsc, udt, IPAC_PROTO_SCCP);
|
2010-10-29 15:05:28 +00:00
|
|
|
bsc_write(bsc, clear, IPAC_PROTO_SCCP);
|
2010-05-16 12:43:52 +00:00
|
|
|
bsc_write(bsc, rlsd, IPAC_PROTO_SCCP);
|
|
|
|
msgb_free(payload);
|
|
|
|
return;
|
2010-06-15 10:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 12:43:52 +00:00
|
|
|
send_refuse:
|
2010-06-15 10:52:24 +00:00
|
|
|
if (payload)
|
|
|
|
msgb_free(payload);
|
|
|
|
|
2010-05-16 12:43:52 +00:00
|
|
|
refuse = sccp_create_refuse(parsed->src_local_ref,
|
|
|
|
SCCP_REFUSAL_SCCP_FAILURE, NULL, 0);
|
2010-05-15 18:20:26 +00:00
|
|
|
if (!refuse) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR,
|
|
|
|
"Creating refuse msg failed for SCCP 0x%x on BSC Nr: %d.\n",
|
|
|
|
sccp_src_ref_to_int(parsed->src_local_ref), bsc->cfg->nr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bsc_write(bsc, refuse, IPAC_PROTO_SCCP);
|
|
|
|
}
|
|
|
|
|
2011-05-02 14:20:32 +00:00
|
|
|
static void bsc_nat_send_paging(struct bsc_connection *bsc, struct msgb *msg)
|
|
|
|
{
|
|
|
|
if (bsc->cfg->forbid_paging) {
|
|
|
|
LOGP(DNAT, LOGL_DEBUG, "Paging forbidden for BTS: %d\n", bsc->cfg->nr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bsc_send_data(bsc, msg->l2h, msgb_l2len(msg), IPAC_PROTO_SCCP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bsc_nat_handle_paging(struct bsc_nat *nat, struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct bsc_connection *bsc;
|
|
|
|
const uint8_t *paging_start;
|
2011-05-02 18:03:17 +00:00
|
|
|
int paging_length, i, ret;
|
2011-05-02 14:20:32 +00:00
|
|
|
|
2011-05-02 18:03:17 +00:00
|
|
|
ret = bsc_nat_find_paging(msg, &paging_start, &paging_length);
|
|
|
|
if (ret != 0) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Could not parse paging message: %d\n", ret);
|
2011-05-02 14:20:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is quite expensive now */
|
|
|
|
for (i = 0; i < paging_length; i += 2) {
|
|
|
|
unsigned int _lac = ntohs(*(unsigned int *) &paging_start[i]);
|
|
|
|
unsigned int paged = 0;
|
|
|
|
llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
|
|
|
|
if (!bsc->cfg)
|
|
|
|
continue;
|
|
|
|
if (!bsc->authenticated)
|
|
|
|
continue;
|
|
|
|
if (!bsc_config_handles_lac(bsc->cfg, _lac))
|
|
|
|
continue;
|
|
|
|
bsc_nat_send_paging(bsc, msg);
|
|
|
|
paged += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* highlight a possible config issue */
|
|
|
|
if (paged == 0)
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "No BSC for LAC %d/0x%d\n", _lac, _lac);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-06 09:27:52 +00:00
|
|
|
/*
|
|
|
|
* Update the auth status. This can be either a CIPHER MODE COMAMND or
|
|
|
|
* a CM Serivce Accept. Maybe also LU Accept or such in the future.
|
|
|
|
*/
|
2013-04-16 07:53:13 +00:00
|
|
|
static void update_con_authorize(struct nat_sccp_connection *con,
|
2011-04-06 09:27:52 +00:00
|
|
|
struct bsc_nat_parsed *parsed,
|
|
|
|
struct msgb *msg)
|
|
|
|
{
|
|
|
|
if (!con)
|
|
|
|
return;
|
|
|
|
if (con->authorized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (parsed->bssap == BSSAP_MSG_BSS_MANAGEMENT &&
|
|
|
|
parsed->gsm_type == BSS_MAP_MSG_CIPHER_MODE_CMD) {
|
|
|
|
con->authorized = 1;
|
|
|
|
} else if (parsed->bssap == BSSAP_MSG_DTAP) {
|
2011-04-13 16:56:13 +00:00
|
|
|
uint8_t msg_type, proto;
|
2011-04-06 09:27:52 +00:00
|
|
|
uint32_t len;
|
|
|
|
struct gsm48_hdr *hdr48;
|
|
|
|
hdr48 = bsc_unpack_dtap(parsed, msg, &len);
|
|
|
|
if (!hdr48)
|
|
|
|
return;
|
|
|
|
|
2011-04-13 16:56:13 +00:00
|
|
|
proto = hdr48->proto_discr & 0x0f;
|
2011-04-06 09:27:52 +00:00
|
|
|
msg_type = hdr48->msg_type & 0xbf;
|
2011-04-13 16:56:13 +00:00
|
|
|
if (proto == GSM48_PDISC_MM &&
|
2011-04-06 09:27:52 +00:00
|
|
|
msg_type == GSM48_MT_MM_CM_SERV_ACC)
|
|
|
|
con->authorized = 1;
|
|
|
|
}
|
|
|
|
}
|
2010-05-15 18:20:26 +00:00
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
static int forward_sccp_to_bts(struct bsc_msc_connection *msc_con, struct msgb *msg)
|
2010-01-12 20:15:08 +00:00
|
|
|
{
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *con = NULL;
|
2010-06-15 10:48:55 +00:00
|
|
|
struct bsc_connection *bsc;
|
2010-06-15 10:45:38 +00:00
|
|
|
struct bsc_nat_parsed *parsed;
|
2010-04-08 08:24:57 +00:00
|
|
|
int proto;
|
2010-01-13 08:28:12 +00:00
|
|
|
|
2010-01-12 20:15:08 +00:00
|
|
|
/* filter, drop, patch the message? */
|
2010-06-15 10:45:38 +00:00
|
|
|
parsed = bsc_nat_parse(msg);
|
|
|
|
if (!parsed) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
|
2010-01-31 08:46:21 +00:00
|
|
|
return -1;
|
2010-06-15 10:45:38 +00:00
|
|
|
}
|
|
|
|
|
2010-01-30 10:53:30 +00:00
|
|
|
if (bsc_nat_filter_ipa(DIR_BSC, msg, parsed))
|
2010-06-15 10:45:38 +00:00
|
|
|
goto exit;
|
2010-06-15 10:45:26 +00:00
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
proto = parsed->ipa_proto;
|
|
|
|
|
2010-01-31 08:46:21 +00:00
|
|
|
/* Route and modify the SCCP packet */
|
2010-04-08 08:24:57 +00:00
|
|
|
if (proto == IPAC_PROTO_SCCP) {
|
2010-01-31 08:46:21 +00:00
|
|
|
switch (parsed->sccp_type) {
|
|
|
|
case SCCP_MSG_TYPE_UDT:
|
|
|
|
/* forward UDT messages to every BSC */
|
|
|
|
goto send_to_all;
|
|
|
|
break;
|
|
|
|
case SCCP_MSG_TYPE_RLSD:
|
|
|
|
case SCCP_MSG_TYPE_CREF:
|
|
|
|
case SCCP_MSG_TYPE_DT1:
|
2010-04-06 08:22:34 +00:00
|
|
|
case SCCP_MSG_TYPE_IT:
|
2010-06-15 10:48:55 +00:00
|
|
|
con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
|
2010-06-15 10:49:53 +00:00
|
|
|
if (parsed->gsm_type == BSS_MAP_MSG_ASSIGMENT_RQST) {
|
2011-05-06 10:13:10 +00:00
|
|
|
osmo_counter_inc(nat->stats.sccp.calls);
|
2010-04-12 10:17:09 +00:00
|
|
|
|
2010-06-15 10:49:53 +00:00
|
|
|
if (con) {
|
2010-06-17 10:16:00 +00:00
|
|
|
struct rate_ctr_group *ctrg;
|
|
|
|
ctrg = con->bsc->cfg->stats.ctrg;
|
|
|
|
rate_ctr_inc(&ctrg->ctr[BCFG_CTR_SCCP_CALLS]);
|
2010-08-28 10:22:14 +00:00
|
|
|
if (bsc_mgcp_assign_patch(con, msg) != 0)
|
2010-06-15 10:49:53 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to assign...\n");
|
|
|
|
} else
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Assignment command but no BSC.\n");
|
2011-04-21 15:13:51 +00:00
|
|
|
} else if (con && con->con_local == NAT_CON_END_USSD &&
|
|
|
|
parsed->gsm_type == BSS_MAP_MSG_CLEAR_CMD) {
|
|
|
|
LOGP(DNAT, LOGL_NOTICE, "Clear Command for USSD Connection. Ignoring.\n");
|
|
|
|
con = NULL;
|
2010-06-15 10:49:53 +00:00
|
|
|
}
|
2010-03-29 15:18:42 +00:00
|
|
|
break;
|
2010-01-31 08:46:21 +00:00
|
|
|
case SCCP_MSG_TYPE_CC:
|
2010-06-15 10:48:55 +00:00
|
|
|
con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
|
|
|
|
if (!con || update_sccp_src_ref(con, parsed) != 0)
|
2010-03-29 15:18:42 +00:00
|
|
|
goto exit;
|
2010-01-31 08:46:21 +00:00
|
|
|
break;
|
|
|
|
case SCCP_MSG_TYPE_RLC:
|
2010-06-15 10:47:49 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Unexpected release complete from MSC.\n");
|
|
|
|
goto exit;
|
|
|
|
break;
|
|
|
|
case SCCP_MSG_TYPE_CR:
|
2010-01-31 08:46:21 +00:00
|
|
|
/* MSC never opens a SCCP connection, fall through */
|
|
|
|
default:
|
|
|
|
goto exit;
|
|
|
|
}
|
2010-04-06 14:07:44 +00:00
|
|
|
|
2010-04-08 09:28:12 +00:00
|
|
|
if (!con && parsed->sccp_type == SCCP_MSG_TYPE_RLSD) {
|
|
|
|
LOGP(DNAT, LOGL_NOTICE, "Sending fake RLC on RLSD message to network.\n");
|
|
|
|
/* Exchange src/dest for the reply */
|
2013-09-03 12:35:33 +00:00
|
|
|
nat_send_rlc(msc_con, &parsed->original_dest_ref,
|
|
|
|
parsed->src_local_ref);
|
2010-04-08 09:28:12 +00:00
|
|
|
} else if (!con)
|
2010-05-15 11:13:52 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Unknown connection for msg type: 0x%x from the MSC.\n", parsed->sccp_type);
|
2010-01-31 08:46:21 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 18:50:28 +00:00
|
|
|
if (!con) {
|
|
|
|
talloc_free(parsed);
|
2010-01-31 08:46:21 +00:00
|
|
|
return -1;
|
2013-05-12 18:50:28 +00:00
|
|
|
}
|
2010-06-15 10:48:55 +00:00
|
|
|
if (!con->bsc->authenticated) {
|
2013-05-12 18:50:28 +00:00
|
|
|
talloc_free(parsed);
|
2010-06-15 11:06:18 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Selected BSC not authenticated.\n");
|
2010-02-08 22:24:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-06 09:27:52 +00:00
|
|
|
update_con_authorize(con, parsed, msg);
|
2013-05-12 18:50:28 +00:00
|
|
|
talloc_free(parsed);
|
2011-04-06 09:27:52 +00:00
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
bsc_send_data(con->bsc, msg->l2h, msgb_l2len(msg), proto);
|
2010-03-26 08:18:02 +00:00
|
|
|
return 0;
|
2010-01-31 08:46:21 +00:00
|
|
|
|
|
|
|
send_to_all:
|
2010-06-15 10:46:36 +00:00
|
|
|
/*
|
|
|
|
* Filter Paging from the network. We do not want to send a PAGING
|
|
|
|
* Command to every BSC in our network. We will analys the PAGING
|
|
|
|
* message and then send it to the authenticated messages...
|
|
|
|
*/
|
|
|
|
if (parsed->ipa_proto == IPAC_PROTO_SCCP && parsed->gsm_type == BSS_MAP_MSG_PAGING) {
|
2011-05-02 14:20:32 +00:00
|
|
|
bsc_nat_handle_paging(nat, msg);
|
2010-06-15 10:46:36 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2010-01-13 08:28:12 +00:00
|
|
|
/* currently send this to every BSC connected */
|
2010-06-15 10:46:11 +00:00
|
|
|
llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
|
2010-02-08 22:24:32 +00:00
|
|
|
if (!bsc->authenticated)
|
|
|
|
continue;
|
|
|
|
|
2010-04-08 08:24:57 +00:00
|
|
|
bsc_send_data(bsc, msg->l2h, msgb_l2len(msg), parsed->ipa_proto);
|
2010-01-13 08:28:12 +00:00
|
|
|
}
|
2010-06-15 10:45:38 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
talloc_free(parsed);
|
2010-01-31 08:46:21 +00:00
|
|
|
return 0;
|
2010-01-12 20:15:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 10:47:29 +00:00
|
|
|
static void msc_connection_was_lost(struct bsc_msc_connection *con)
|
|
|
|
{
|
2010-03-29 06:04:09 +00:00
|
|
|
struct bsc_connection *bsc, *tmp;
|
|
|
|
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Closing all connections downstream.\n");
|
|
|
|
llist_for_each_entry_safe(bsc, tmp, &nat->bsc_connections, list_entry)
|
2010-04-27 05:21:39 +00:00
|
|
|
bsc_close_connection(bsc);
|
2010-03-29 06:04:09 +00:00
|
|
|
|
2010-03-31 07:16:56 +00:00
|
|
|
bsc_mgcp_free_endpoints(nat);
|
2010-03-29 06:04:09 +00:00
|
|
|
bsc_msc_schedule_connect(con);
|
2010-06-15 10:47:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 18:31:55 +00:00
|
|
|
static void msc_connection_connected(struct bsc_msc_connection *con)
|
|
|
|
{
|
2011-05-06 10:13:10 +00:00
|
|
|
osmo_counter_inc(nat->stats.msc.reconn);
|
2010-08-03 18:31:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 08:31:07 +00:00
|
|
|
static void msc_send_reset(struct bsc_msc_connection *msc_con)
|
2010-04-07 08:46:30 +00:00
|
|
|
{
|
2010-07-23 11:08:55 +00:00
|
|
|
static const uint8_t reset[] = {
|
2010-04-07 09:11:11 +00:00
|
|
|
0x00, 0x12, 0xfd,
|
2010-04-07 08:46:30 +00:00
|
|
|
0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
|
|
|
|
0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
|
|
|
|
0x01, 0x20
|
|
|
|
};
|
|
|
|
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
msg = msgb_alloc_headroom(4096, 128, "08.08 reset");
|
|
|
|
if (!msg) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to allocate reset msg.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(reset));
|
|
|
|
memcpy(msg->l2h, reset, msgb_l2len(msg));
|
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
queue_for_msc(msc_con, msg);
|
2010-04-07 08:46:30 +00:00
|
|
|
|
|
|
|
LOGP(DMSC, LOGL_NOTICE, "Scheduled GSM0808 reset msg for the MSC.\n");
|
|
|
|
}
|
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
static int ipaccess_msc_read_cb(struct osmo_fd *bfd)
|
2010-01-12 20:15:08 +00:00
|
|
|
{
|
2010-07-05 06:14:18 +00:00
|
|
|
struct bsc_msc_connection *msc_con;
|
2014-03-31 11:42:11 +00:00
|
|
|
struct msgb *msg = NULL;
|
2010-01-12 20:15:08 +00:00
|
|
|
struct ipaccess_head *hh;
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
int ret;
|
2010-01-12 20:15:08 +00:00
|
|
|
|
2010-07-05 06:14:18 +00:00
|
|
|
msc_con = (struct bsc_msc_connection *) bfd->data;
|
|
|
|
|
2014-03-31 11:42:11 +00:00
|
|
|
ret = ipa_msg_recv_buffered(bfd->fd, &msg, &msc_con->pending_msg);
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
if (ret <= 0) {
|
2014-03-31 11:42:11 +00:00
|
|
|
if (ret == -EAGAIN)
|
|
|
|
return 0;
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
if (ret == 0)
|
2013-09-02 11:07:45 +00:00
|
|
|
LOGP(DNAT, LOGL_FATAL,
|
|
|
|
"The connection the MSC(%s) was lost, exiting\n",
|
|
|
|
msc_con->name);
|
2010-04-22 16:23:03 +00:00
|
|
|
else
|
2013-09-02 11:07:45 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR,
|
|
|
|
"Failed to parse ip access message on %s: %d\n",
|
|
|
|
msc_con->name, ret);
|
2010-01-12 20:15:08 +00:00
|
|
|
|
2010-07-05 06:14:18 +00:00
|
|
|
bsc_msc_lost(msc_con);
|
2010-01-12 20:15:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-02 11:07:45 +00:00
|
|
|
LOGP(DNAT, LOGL_DEBUG,
|
|
|
|
"MSG from MSC(%s): %s proto: %d\n", msc_con->name,
|
|
|
|
osmo_hexdump(msg->data, msg->len), msg->l2h[0]);
|
2010-01-12 20:15:08 +00:00
|
|
|
|
|
|
|
/* handle base message handling */
|
|
|
|
hh = (struct ipaccess_head *) msg->data;
|
|
|
|
|
|
|
|
/* initialize the networking. This includes sending a GSM08.08 message */
|
2010-05-14 16:14:58 +00:00
|
|
|
if (hh->proto == IPAC_PROTO_IPACCESS) {
|
2014-08-20 21:46:40 +00:00
|
|
|
ipa_ccm_rcvmsg_base(msg, bfd);
|
2010-05-14 16:14:58 +00:00
|
|
|
if (msg->l2h[0] == IPAC_MSGT_ID_ACK)
|
2010-07-05 06:14:18 +00:00
|
|
|
initialize_msc_if_needed(msc_con);
|
2010-05-14 16:14:58 +00:00
|
|
|
else if (msg->l2h[0] == IPAC_MSGT_ID_GET)
|
2010-07-05 06:14:18 +00:00
|
|
|
send_id_get_response(msc_con);
|
2012-11-05 13:54:56 +00:00
|
|
|
} else if (hh->proto == IPAC_PROTO_SCCP) {
|
2010-07-05 06:14:18 +00:00
|
|
|
forward_sccp_to_bts(msc_con, msg);
|
2012-11-05 13:54:56 +00:00
|
|
|
} else if (hh->proto == IPAC_PROTO_MGCP_OLD) {
|
|
|
|
bsc_nat_handle_mgcp(nat, msg);
|
|
|
|
}
|
2010-01-12 20:15:08 +00:00
|
|
|
|
2010-06-15 10:46:48 +00:00
|
|
|
msgb_free(msg);
|
2010-01-12 20:15:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-06-15 10:44:42 +00:00
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
static int ipaccess_msc_write_cb(struct osmo_fd *bfd, struct msgb *msg)
|
2010-06-15 10:47:02 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
rc = write(bfd->fd, msg->data, msg->len);
|
|
|
|
|
|
|
|
if (rc != msg->len) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to write MSG to MSC.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:34:54 +00:00
|
|
|
/*
|
|
|
|
* Below is the handling of messages coming
|
|
|
|
* from the BSC and need to be forwarded to
|
|
|
|
* a real BSC.
|
|
|
|
*/
|
2010-01-13 08:28:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the connection from the connections list,
|
|
|
|
* remove it from the patching of SCCP header lists
|
|
|
|
* as well. Maybe in the future even close connection..
|
|
|
|
*/
|
2010-04-27 05:21:39 +00:00
|
|
|
void bsc_close_connection(struct bsc_connection *connection)
|
2010-01-13 08:28:12 +00:00
|
|
|
{
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *sccp_patch, *tmp;
|
2011-02-18 13:32:56 +00:00
|
|
|
struct bsc_cmd_list *cmd_entry, *cmd_tmp;
|
2010-06-17 10:29:42 +00:00
|
|
|
struct rate_ctr *ctr = NULL;
|
2010-01-31 08:46:21 +00:00
|
|
|
|
2010-06-15 10:46:19 +00:00
|
|
|
/* stop the timeout timer */
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_del(&connection->id_timeout);
|
|
|
|
osmo_timer_del(&connection->ping_timeout);
|
|
|
|
osmo_timer_del(&connection->pong_timeout);
|
2010-06-15 10:46:19 +00:00
|
|
|
|
2010-06-17 10:29:42 +00:00
|
|
|
if (connection->cfg)
|
|
|
|
ctr = &connection->cfg->stats.ctrg->ctr[BCFG_CTR_DROPPED_SCCP];
|
|
|
|
|
2010-01-31 08:46:21 +00:00
|
|
|
/* remove all SCCP connections */
|
2010-06-15 10:46:11 +00:00
|
|
|
llist_for_each_entry_safe(sccp_patch, tmp, &nat->sccp_connections, list_entry) {
|
2010-01-31 08:46:21 +00:00
|
|
|
if (sccp_patch->bsc != connection)
|
|
|
|
continue;
|
|
|
|
|
2010-06-17 10:29:42 +00:00
|
|
|
if (ctr)
|
|
|
|
rate_ctr_inc(ctr);
|
2011-04-16 15:01:47 +00:00
|
|
|
if (sccp_patch->has_remote_ref) {
|
|
|
|
if (sccp_patch->con_local == NAT_CON_END_MSC)
|
|
|
|
nat_send_rlsd_msc(sccp_patch);
|
|
|
|
else if (sccp_patch->con_local == NAT_CON_END_USSD)
|
|
|
|
nat_send_rlsd_ussd(nat, sccp_patch);
|
|
|
|
}
|
|
|
|
|
2010-03-30 08:45:48 +00:00
|
|
|
sccp_connection_destroy(sccp_patch);
|
2010-01-31 08:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 13:32:56 +00:00
|
|
|
/* Reply to all outstanding commands */
|
|
|
|
llist_for_each_entry_safe(cmd_entry, cmd_tmp, &connection->cmd_pending, list_entry) {
|
|
|
|
cmd_entry->cmd->type = CTRL_TYPE_ERROR;
|
|
|
|
cmd_entry->cmd->reply = "BSC closed the connection";
|
|
|
|
ctrl_cmd_send(&cmd_entry->ccon->write_queue, cmd_entry->cmd);
|
2012-11-05 15:04:10 +00:00
|
|
|
bsc_nat_ctrl_del_pending(cmd_entry);
|
2011-02-18 13:32:56 +00:00
|
|
|
}
|
|
|
|
|
2010-04-05 21:09:27 +00:00
|
|
|
/* close endpoints allocated by this BSC */
|
|
|
|
bsc_mgcp_clear_endpoints_for(connection);
|
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
osmo_fd_unregister(&connection->write_queue.bfd);
|
2010-04-22 04:04:36 +00:00
|
|
|
close(connection->write_queue.bfd.fd);
|
2011-05-06 10:09:47 +00:00
|
|
|
osmo_wqueue_clear(&connection->write_queue);
|
2010-04-22 04:04:36 +00:00
|
|
|
llist_del(&connection->list_entry);
|
|
|
|
|
2014-03-31 11:42:11 +00:00
|
|
|
if (connection->pending_msg) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Dropping partial message on connection %d.\n",
|
2014-04-03 10:10:24 +00:00
|
|
|
connection->cfg ? connection->cfg->nr : -1);
|
2014-03-31 11:42:11 +00:00
|
|
|
msgb_free(connection->pending_msg);
|
|
|
|
connection->pending_msg = NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-13 08:28:12 +00:00
|
|
|
talloc_free(connection);
|
|
|
|
}
|
|
|
|
|
2011-04-23 21:55:14 +00:00
|
|
|
static void bsc_maybe_close(struct bsc_connection *bsc)
|
|
|
|
{
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *sccp;
|
2011-04-23 21:55:14 +00:00
|
|
|
if (!bsc->nat->blocked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* are there any connections left */
|
|
|
|
llist_for_each_entry(sccp, &bsc->nat->sccp_connections, list_entry)
|
|
|
|
if (sccp->bsc == bsc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* nothing left, close the BSC */
|
|
|
|
LOGP(DNAT, LOGL_NOTICE, "Cleaning up BSC %d in blocking mode.\n",
|
|
|
|
bsc->cfg ? bsc->cfg->nr : -1);
|
|
|
|
bsc_close_connection(bsc);
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:46:19 +00:00
|
|
|
static void ipaccess_close_bsc(void *data)
|
|
|
|
{
|
2010-04-17 05:58:17 +00:00
|
|
|
struct sockaddr_in sock;
|
|
|
|
socklen_t len = sizeof(sock);
|
2010-06-15 10:46:19 +00:00
|
|
|
struct bsc_connection *conn = data;
|
|
|
|
|
2010-04-17 05:58:17 +00:00
|
|
|
|
|
|
|
getpeername(conn->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "BSC on %s didn't respond to identity request. Closing.\n",
|
|
|
|
inet_ntoa(sock.sin_addr));
|
2010-04-27 05:21:39 +00:00
|
|
|
bsc_close_connection(conn);
|
2010-06-15 10:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc)
|
|
|
|
{
|
|
|
|
struct bsc_config *conf;
|
2010-09-17 22:44:24 +00:00
|
|
|
const char *token = (const char *) TLVP_VAL(tvp, IPAC_IDTAG_UNITNAME);
|
2010-10-14 15:19:58 +00:00
|
|
|
const int len = TLVP_LEN(tvp, IPAC_IDTAG_UNITNAME);
|
2010-06-15 10:46:19 +00:00
|
|
|
|
2010-05-02 10:58:10 +00:00
|
|
|
if (bsc->cfg) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Reauth on fd %d bsc nr %d\n",
|
|
|
|
bsc->write_queue.bfd.fd, bsc->cfg->nr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-19 19:50:36 +00:00
|
|
|
if (len <= 0) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Token with length zero on fd: %d\n",
|
|
|
|
bsc->write_queue.bfd.fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token[len - 1] != '\0') {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Token not null terminated on fd: %d\n",
|
|
|
|
bsc->write_queue.bfd.fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:46:19 +00:00
|
|
|
llist_for_each_entry(conf, &bsc->nat->bsc_configs, entry) {
|
2013-03-19 19:50:36 +00:00
|
|
|
/*
|
|
|
|
* Add the '\0' of the token for the memcmp, the IPA messages
|
|
|
|
* for some reason added null termination.
|
|
|
|
*/
|
|
|
|
const int token_len = strlen(conf->token) + 1;
|
|
|
|
|
|
|
|
if (token_len == len && memcmp(conf->token, token, token_len) == 0) {
|
2010-06-17 10:16:00 +00:00
|
|
|
rate_ctr_inc(&conf->stats.ctrg->ctr[BCFG_CTR_NET_RECONN]);
|
2010-06-15 10:46:19 +00:00
|
|
|
bsc->authenticated = 1;
|
2010-04-06 13:11:34 +00:00
|
|
|
bsc->cfg = conf;
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_del(&bsc->id_timeout);
|
2010-10-08 14:08:29 +00:00
|
|
|
LOGP(DNAT, LOGL_NOTICE, "Authenticated bsc nr: %d on fd %d\n",
|
|
|
|
conf->nr, bsc->write_queue.bfd.fd);
|
2010-05-02 11:28:59 +00:00
|
|
|
start_ping_pong(bsc);
|
2010-04-17 05:59:57 +00:00
|
|
|
return;
|
2010-06-15 10:46:19 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-17 05:59:57 +00:00
|
|
|
|
2013-03-19 19:50:36 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "No bsc found for token '%s' on fd: %d.\n", token,
|
2010-05-05 09:03:44 +00:00
|
|
|
bsc->write_queue.bfd.fd);
|
2010-06-15 10:46:19 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 07:53:13 +00:00
|
|
|
static void handle_con_stats(struct nat_sccp_connection *con)
|
2010-10-03 11:41:42 +00:00
|
|
|
{
|
|
|
|
struct rate_ctr_group *ctrg;
|
|
|
|
int id = bsc_conn_type_to_ctr(con);
|
|
|
|
|
|
|
|
if (id == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!con->bsc || !con->bsc->cfg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ctrg = con->bsc->cfg->stats.ctrg;
|
|
|
|
rate_ctr_inc(&ctrg->ctr[id]);
|
|
|
|
}
|
|
|
|
|
2010-03-26 06:24:34 +00:00
|
|
|
static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg)
|
2010-01-13 08:28:12 +00:00
|
|
|
{
|
2010-05-16 08:36:36 +00:00
|
|
|
int con_filter = 0;
|
2010-09-28 17:19:42 +00:00
|
|
|
char *imsi = NULL;
|
2010-07-05 05:58:40 +00:00
|
|
|
struct bsc_msc_connection *con_msc = NULL;
|
2010-05-16 08:30:42 +00:00
|
|
|
struct bsc_connection *con_bsc = NULL;
|
2010-05-15 18:00:40 +00:00
|
|
|
int con_type;
|
2010-06-15 10:45:38 +00:00
|
|
|
struct bsc_nat_parsed *parsed;
|
2012-12-17 13:35:03 +00:00
|
|
|
struct bsc_nat_reject_cause cause;
|
2010-01-13 08:28:12 +00:00
|
|
|
|
2010-06-15 10:45:38 +00:00
|
|
|
/* Parse and filter messages */
|
|
|
|
parsed = bsc_nat_parse(msg);
|
|
|
|
if (!parsed) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
|
2010-03-30 05:35:46 +00:00
|
|
|
msgb_free(msg);
|
2010-06-15 10:45:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-30 10:53:30 +00:00
|
|
|
if (bsc_nat_filter_ipa(DIR_MSC, msg, parsed))
|
2010-06-15 10:45:38 +00:00
|
|
|
goto exit;
|
2010-06-15 10:45:26 +00:00
|
|
|
|
2010-04-02 01:42:44 +00:00
|
|
|
/*
|
|
|
|
* check authentication after filtering to not reject auth
|
|
|
|
* responses coming from the BSC. We have to make sure that
|
|
|
|
* nothing from the exit path will forward things to the MSC
|
|
|
|
*/
|
|
|
|
if (!bsc->authenticated) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "BSC is not authenticated.\n");
|
|
|
|
msgb_free(msg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-31 08:46:21 +00:00
|
|
|
/* modify the SCCP entries */
|
|
|
|
if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
|
2010-09-14 16:38:54 +00:00
|
|
|
int filter;
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *con;
|
2010-01-31 08:46:21 +00:00
|
|
|
switch (parsed->sccp_type) {
|
|
|
|
case SCCP_MSG_TYPE_CR:
|
2012-12-17 13:35:03 +00:00
|
|
|
memset(&cause, 0, sizeof(cause));
|
|
|
|
filter = bsc_nat_filter_sccp_cr(bsc, msg, parsed,
|
|
|
|
&con_type, &imsi, &cause);
|
2010-09-25 09:58:22 +00:00
|
|
|
if (filter < 0) {
|
|
|
|
bsc_stat_reject(filter, bsc, 0);
|
2010-05-13 19:39:56 +00:00
|
|
|
goto exit3;
|
2010-09-25 09:58:22 +00:00
|
|
|
}
|
|
|
|
|
2010-05-16 08:51:31 +00:00
|
|
|
if (!create_sccp_src_ref(bsc, parsed))
|
2010-01-31 08:46:21 +00:00
|
|
|
goto exit2;
|
2010-04-21 10:56:12 +00:00
|
|
|
con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
|
2010-07-05 05:33:18 +00:00
|
|
|
con->msc_con = bsc->nat->msc_con;
|
2010-07-05 05:58:40 +00:00
|
|
|
con_msc = con->msc_con;
|
2010-05-15 18:06:11 +00:00
|
|
|
con->con_type = con_type;
|
2010-09-14 16:41:19 +00:00
|
|
|
con->imsi_checked = filter;
|
2013-04-16 11:23:43 +00:00
|
|
|
bsc_nat_extract_lac(bsc, con, parsed, msg);
|
2010-09-28 17:19:42 +00:00
|
|
|
if (imsi)
|
|
|
|
con->imsi = talloc_steal(con, imsi);
|
|
|
|
imsi = NULL;
|
2010-05-16 08:30:42 +00:00
|
|
|
con_bsc = con->bsc;
|
2010-10-03 11:41:42 +00:00
|
|
|
handle_con_stats(con);
|
2010-01-31 08:46:21 +00:00
|
|
|
break;
|
|
|
|
case SCCP_MSG_TYPE_RLSD:
|
|
|
|
case SCCP_MSG_TYPE_CREF:
|
|
|
|
case SCCP_MSG_TYPE_DT1:
|
|
|
|
case SCCP_MSG_TYPE_CC:
|
2010-04-06 08:22:34 +00:00
|
|
|
case SCCP_MSG_TYPE_IT:
|
2010-04-21 10:56:12 +00:00
|
|
|
con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
|
2010-05-16 08:30:42 +00:00
|
|
|
if (con) {
|
2010-10-05 16:48:36 +00:00
|
|
|
/* only filter non local connections */
|
|
|
|
if (!con->con_local) {
|
2012-12-17 13:35:03 +00:00
|
|
|
memset(&cause, 0, sizeof(cause));
|
|
|
|
filter = bsc_nat_filter_dt(bsc, msg,
|
|
|
|
con, parsed, &cause);
|
2010-10-05 16:48:36 +00:00
|
|
|
if (filter < 0) {
|
|
|
|
bsc_stat_reject(filter, bsc, 1);
|
2012-12-17 13:35:03 +00:00
|
|
|
bsc_send_con_release(bsc, con, &cause);
|
2010-10-05 16:48:36 +00:00
|
|
|
con = NULL;
|
|
|
|
goto exit2;
|
|
|
|
}
|
2010-09-29 11:32:55 +00:00
|
|
|
|
|
|
|
/* hand data to a side channel */
|
2013-08-26 12:04:43 +00:00
|
|
|
if (bsc_ussd_check(con, parsed, msg) == 1)
|
2011-04-16 14:02:59 +00:00
|
|
|
con->con_local = NAT_CON_END_USSD;
|
2010-10-21 10:12:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Optionally rewrite setup message. This can
|
|
|
|
* replace the msg and the parsed structure becomes
|
|
|
|
* invalid.
|
|
|
|
*/
|
2011-05-27 12:09:55 +00:00
|
|
|
msg = bsc_nat_rewrite_msg(bsc->nat, msg, parsed, con->imsi);
|
2010-10-21 10:12:57 +00:00
|
|
|
talloc_free(parsed);
|
|
|
|
parsed = NULL;
|
2011-04-16 12:06:18 +00:00
|
|
|
} else if (con->con_local == NAT_CON_END_USSD) {
|
2013-08-26 12:04:43 +00:00
|
|
|
bsc_ussd_check(con, parsed, msg);
|
2010-09-14 17:11:08 +00:00
|
|
|
}
|
2010-10-05 16:48:36 +00:00
|
|
|
|
|
|
|
con_bsc = con->bsc;
|
|
|
|
con_msc = con->msc_con;
|
|
|
|
con_filter = con->con_local;
|
2010-05-16 08:30:42 +00:00
|
|
|
}
|
2010-09-29 11:32:55 +00:00
|
|
|
|
2010-01-31 08:46:21 +00:00
|
|
|
break;
|
|
|
|
case SCCP_MSG_TYPE_RLC:
|
2010-04-21 10:56:12 +00:00
|
|
|
con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
|
2010-05-16 08:30:42 +00:00
|
|
|
if (con) {
|
|
|
|
con_bsc = con->bsc;
|
2010-07-05 05:58:40 +00:00
|
|
|
con_msc = con->msc_con;
|
2010-05-16 08:36:36 +00:00
|
|
|
con_filter = con->con_local;
|
2010-05-16 08:30:42 +00:00
|
|
|
}
|
2010-03-31 07:15:05 +00:00
|
|
|
remove_sccp_src_ref(bsc, msg, parsed);
|
2011-04-23 21:55:14 +00:00
|
|
|
bsc_maybe_close(bsc);
|
2010-01-31 08:46:21 +00:00
|
|
|
break;
|
|
|
|
case SCCP_MSG_TYPE_UDT:
|
|
|
|
/* simply forward everything */
|
2010-06-15 10:48:55 +00:00
|
|
|
con = NULL;
|
2010-01-31 08:46:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-06-15 10:47:49 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Not forwarding to msc sccp type: 0x%x\n", parsed->sccp_type);
|
2010-06-15 10:48:55 +00:00
|
|
|
con = NULL;
|
2010-01-31 08:46:21 +00:00
|
|
|
goto exit2;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-07 15:54:46 +00:00
|
|
|
} else if (parsed->ipa_proto == IPAC_PROTO_MGCP_OLD) {
|
2010-04-01 08:16:28 +00:00
|
|
|
bsc_mgcp_forward(bsc, msg);
|
|
|
|
goto exit2;
|
2010-06-15 10:48:55 +00:00
|
|
|
} else {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Not forwarding unknown stream id: 0x%x\n", parsed->ipa_proto);
|
|
|
|
goto exit2;
|
2010-01-31 08:46:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
if (con_msc && con_bsc != bsc) {
|
2010-04-21 10:49:55 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "The connection belongs to a different BTS: input: %d con: %d\n",
|
2010-05-16 08:30:42 +00:00
|
|
|
bsc->cfg->nr, con_bsc->cfg->nr);
|
2010-01-31 08:46:21 +00:00
|
|
|
goto exit2;
|
|
|
|
}
|
|
|
|
|
2010-09-15 09:39:44 +00:00
|
|
|
/* do not forward messages to the MSC */
|
|
|
|
if (con_filter)
|
|
|
|
goto exit2;
|
|
|
|
|
2010-07-05 05:58:40 +00:00
|
|
|
if (!con_msc) {
|
2010-09-14 16:14:48 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Not forwarding data bsc_nr: %d ipa: %d type: 0x%x\n",
|
|
|
|
bsc->cfg->nr,
|
|
|
|
parsed ? parsed->ipa_proto : -1,
|
|
|
|
parsed ? parsed->sccp_type : -1);
|
2010-07-05 05:58:40 +00:00
|
|
|
goto exit2;
|
|
|
|
}
|
|
|
|
|
2010-01-13 08:28:12 +00:00
|
|
|
/* send the non-filtered but maybe modified msg */
|
2010-07-05 05:58:40 +00:00
|
|
|
queue_for_msc(con_msc, msg);
|
2010-10-21 10:12:57 +00:00
|
|
|
if (parsed)
|
|
|
|
talloc_free(parsed);
|
2010-06-15 10:47:02 +00:00
|
|
|
return 0;
|
2010-06-15 10:45:38 +00:00
|
|
|
|
|
|
|
exit:
|
2010-01-30 11:45:10 +00:00
|
|
|
/* if we filter out the reset send an ack to the BSC */
|
|
|
|
if (parsed->bssap == 0 && parsed->gsm_type == BSS_MAP_MSG_RESET) {
|
2010-03-26 06:24:34 +00:00
|
|
|
send_reset_ack(bsc);
|
|
|
|
send_reset_ack(bsc);
|
2010-06-15 10:46:19 +00:00
|
|
|
} else if (parsed->ipa_proto == IPAC_PROTO_IPACCESS) {
|
|
|
|
/* do we know who is handling this? */
|
|
|
|
if (msg->l2h[0] == IPAC_MSGT_ID_RESP) {
|
|
|
|
struct tlv_parsed tvp;
|
2011-04-11 14:32:50 +00:00
|
|
|
int ret;
|
2014-08-20 21:46:40 +00:00
|
|
|
ret = ipa_ccm_idtag_parse(&tvp,
|
2010-06-15 10:46:19 +00:00
|
|
|
(unsigned char *) msg->l2h + 2,
|
|
|
|
msgb_l2len(msg) - 2);
|
2011-04-11 14:32:50 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "ignoring IPA response "
|
|
|
|
"message with malformed TLVs\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2010-06-15 10:46:19 +00:00
|
|
|
if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME))
|
|
|
|
ipaccess_auth_bsc(&tvp, bsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto exit2;
|
2010-01-30 11:45:10 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 16:29:50 +00:00
|
|
|
exit2:
|
2010-09-28 17:19:42 +00:00
|
|
|
if (imsi)
|
|
|
|
talloc_free(imsi);
|
2010-05-14 16:29:50 +00:00
|
|
|
talloc_free(parsed);
|
|
|
|
msgb_free(msg);
|
|
|
|
return -1;
|
|
|
|
|
2010-05-13 19:39:56 +00:00
|
|
|
exit3:
|
|
|
|
/* send a SCCP Connection Refused */
|
2010-09-28 17:19:42 +00:00
|
|
|
if (imsi)
|
|
|
|
talloc_free(imsi);
|
2012-12-17 13:35:03 +00:00
|
|
|
bsc_send_con_refuse(bsc, parsed, con_type, &cause);
|
2010-06-15 10:45:38 +00:00
|
|
|
talloc_free(parsed);
|
2010-06-15 10:47:02 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return -1;
|
2010-01-13 08:28:12 +00:00
|
|
|
}
|
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
static int ipaccess_bsc_read_cb(struct osmo_fd *bfd)
|
2010-01-13 08:28:12 +00:00
|
|
|
{
|
2010-03-26 06:24:34 +00:00
|
|
|
struct bsc_connection *bsc = bfd->data;
|
2014-03-31 11:42:11 +00:00
|
|
|
struct msgb *msg = NULL;
|
2010-06-15 10:51:33 +00:00
|
|
|
struct ipaccess_head *hh;
|
2011-02-18 13:32:56 +00:00
|
|
|
struct ipaccess_head_ext *hh_ext;
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
int ret;
|
2010-01-13 08:28:12 +00:00
|
|
|
|
2014-03-31 11:42:11 +00:00
|
|
|
ret = ipa_msg_recv_buffered(bfd->fd, &msg, &bsc->pending_msg);
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
if (ret <= 0) {
|
2014-03-31 11:42:11 +00:00
|
|
|
if (ret == -EAGAIN)
|
|
|
|
return 0;
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
if (ret == 0)
|
2010-05-01 02:37:15 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR,
|
|
|
|
"The connection to the BSC Nr: %d was lost. Cleaning it\n",
|
|
|
|
bsc->cfg ? bsc->cfg->nr : -1);
|
2010-04-22 16:23:03 +00:00
|
|
|
else
|
2010-05-01 02:37:15 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR,
|
|
|
|
"Stream error on BSC Nr: %d. Failed to parse ip access message: %d\n",
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
bsc->cfg ? bsc->cfg->nr : -1, ret);
|
2010-04-22 16:23:03 +00:00
|
|
|
|
2010-04-27 05:21:39 +00:00
|
|
|
bsc_close_connection(bsc);
|
2010-01-13 08:28:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-07 10:12:48 +00:00
|
|
|
LOGP(DNAT, LOGL_DEBUG, "MSG from BSC: %s proto: %d\n", osmo_hexdump(msg->data, msg->len), msg->l2h[0]);
|
2010-01-13 08:28:12 +00:00
|
|
|
|
|
|
|
/* Handle messages from the BSC */
|
2010-06-15 10:51:33 +00:00
|
|
|
hh = (struct ipaccess_head *) msg->data;
|
2010-05-02 11:28:59 +00:00
|
|
|
|
2010-06-15 10:51:33 +00:00
|
|
|
/* stop the pong timeout */
|
|
|
|
if (hh->proto == IPAC_PROTO_IPACCESS) {
|
|
|
|
if (msg->l2h[0] == IPAC_MSGT_PONG) {
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_del(&bsc->pong_timeout);
|
2010-05-02 11:28:59 +00:00
|
|
|
msgb_free(msg);
|
|
|
|
return 0;
|
2010-06-15 10:51:33 +00:00
|
|
|
} else if (msg->l2h[0] == IPAC_MSGT_PING) {
|
|
|
|
send_pong(bsc);
|
|
|
|
msgb_free(msg);
|
|
|
|
return 0;
|
2010-05-02 11:28:59 +00:00
|
|
|
}
|
2011-02-18 13:32:56 +00:00
|
|
|
/* Message contains the ipaccess_head_ext header, investigate further */
|
|
|
|
} else if (hh->proto == IPAC_PROTO_OSMO &&
|
|
|
|
msg->len > sizeof(*hh) + sizeof(*hh_ext)) {
|
|
|
|
|
|
|
|
hh_ext = (struct ipaccess_head_ext *) hh->data;
|
|
|
|
/* l2h is where the actual command data is expected */
|
|
|
|
msg->l2h = hh_ext->data;
|
|
|
|
|
2011-07-13 12:43:37 +00:00
|
|
|
if (hh_ext->proto == IPAC_PROTO_EXT_CTRL)
|
2012-11-05 15:04:10 +00:00
|
|
|
return bsc_nat_handle_ctrlif_msg(bsc, msg);
|
2010-05-02 11:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-13 08:28:12 +00:00
|
|
|
/* FIXME: Currently no PONG is sent to the BSC */
|
|
|
|
/* FIXME: Currently no ID ACK is sent to the BSC */
|
2010-03-26 06:24:34 +00:00
|
|
|
forward_sccp_to_msc(bsc, msg);
|
2010-01-13 08:28:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
static int ipaccess_listen_bsc_cb(struct osmo_fd *bfd, unsigned int what)
|
2010-01-12 20:34:54 +00:00
|
|
|
{
|
2010-01-13 08:28:12 +00:00
|
|
|
struct bsc_connection *bsc;
|
2010-05-05 12:33:34 +00:00
|
|
|
int fd, rc, on;
|
2010-01-12 20:34:54 +00:00
|
|
|
struct sockaddr_in sa;
|
|
|
|
socklen_t sa_len = sizeof(sa);
|
|
|
|
|
|
|
|
if (!(what & BSC_FD_READ))
|
|
|
|
return 0;
|
|
|
|
|
2010-05-05 12:33:34 +00:00
|
|
|
fd = accept(bfd->fd, (struct sockaddr *) &sa, &sa_len);
|
|
|
|
if (fd < 0) {
|
2010-01-12 20:34:54 +00:00
|
|
|
perror("accept");
|
2010-05-05 12:33:34 +00:00
|
|
|
return fd;
|
2010-01-12 20:34:54 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 10:17:09 +00:00
|
|
|
/* count the reconnect */
|
2011-05-06 10:13:10 +00:00
|
|
|
osmo_counter_inc(nat->stats.bsc.reconn);
|
2010-04-12 10:17:09 +00:00
|
|
|
|
2010-03-29 06:04:09 +00:00
|
|
|
/*
|
|
|
|
* if we are not connected to a msc... just close the socket
|
|
|
|
*/
|
2010-07-05 06:39:44 +00:00
|
|
|
if (!bsc_nat_msc_is_connected(nat)) {
|
2010-03-29 06:04:09 +00:00
|
|
|
LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due lack of MSC connection.\n");
|
2010-05-05 12:33:34 +00:00
|
|
|
close(fd);
|
2010-03-29 06:04:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-23 21:55:14 +00:00
|
|
|
if (nat->blocked) {
|
|
|
|
LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due NAT being blocked.\n");
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-05 10:58:13 +00:00
|
|
|
on = 1;
|
2010-05-05 12:42:14 +00:00
|
|
|
rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
|
2010-05-05 12:33:34 +00:00
|
|
|
if (rc != 0)
|
2010-05-05 10:58:13 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
|
|
|
|
|
2010-05-31 02:36:35 +00:00
|
|
|
rc = setsockopt(fd, IPPROTO_IP, IP_TOS,
|
2010-07-27 11:21:53 +00:00
|
|
|
&nat->bsc_ip_dscp, sizeof(nat->bsc_ip_dscp));
|
2010-05-31 02:36:35 +00:00
|
|
|
if (rc != 0)
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to set IP_TOS: %s\n", strerror(errno));
|
|
|
|
|
2010-01-12 20:34:54 +00:00
|
|
|
/* todo... do something with the connection */
|
2010-01-12 20:35:32 +00:00
|
|
|
/* todo... use GNUtls to see if we want to trust this as a BTS */
|
2010-01-12 20:34:54 +00:00
|
|
|
|
2010-01-13 08:28:12 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
2010-06-15 10:48:01 +00:00
|
|
|
bsc = bsc_connection_alloc(nat);
|
2010-01-13 08:28:12 +00:00
|
|
|
if (!bsc) {
|
2010-01-29 04:58:43 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate BSC struct.\n");
|
2010-05-05 12:33:34 +00:00
|
|
|
close(fd);
|
2010-01-13 08:28:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:47:10 +00:00
|
|
|
bsc->write_queue.bfd.data = bsc;
|
2010-05-05 12:33:34 +00:00
|
|
|
bsc->write_queue.bfd.fd = fd;
|
2010-06-15 10:47:10 +00:00
|
|
|
bsc->write_queue.read_cb = ipaccess_bsc_read_cb;
|
2010-10-13 18:37:13 +00:00
|
|
|
bsc->write_queue.write_cb = bsc_write_cb;
|
2010-06-15 10:47:10 +00:00
|
|
|
bsc->write_queue.bfd.when = BSC_FD_READ;
|
2011-05-06 10:11:23 +00:00
|
|
|
if (osmo_fd_register(&bsc->write_queue.bfd) < 0) {
|
2010-01-29 04:58:43 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to register BSC fd.\n");
|
2010-05-05 12:33:34 +00:00
|
|
|
close(fd);
|
2010-01-13 08:28:12 +00:00
|
|
|
talloc_free(bsc);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2010-05-05 09:03:44 +00:00
|
|
|
LOGP(DNAT, LOGL_NOTICE, "BSC connection on %d with IP: %s\n",
|
2010-05-05 12:33:34 +00:00
|
|
|
fd, inet_ntoa(sa.sin_addr));
|
2011-02-18 13:32:56 +00:00
|
|
|
|
2010-06-15 10:46:11 +00:00
|
|
|
llist_add(&bsc->list_entry, &nat->bsc_connections);
|
2011-02-18 13:32:56 +00:00
|
|
|
bsc->last_id = 0;
|
|
|
|
|
2010-03-26 06:41:54 +00:00
|
|
|
send_id_ack(bsc);
|
|
|
|
send_id_req(bsc);
|
2010-03-31 05:30:58 +00:00
|
|
|
send_mgcp_reset(bsc);
|
2010-06-15 10:46:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* start the hangup timer
|
|
|
|
*/
|
|
|
|
bsc->id_timeout.data = bsc;
|
|
|
|
bsc->id_timeout.cb = ipaccess_close_bsc;
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&bsc->id_timeout, nat->auth_timeout, 0);
|
2010-01-12 20:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:44:42 +00:00
|
|
|
static void print_usage()
|
|
|
|
{
|
|
|
|
printf("Usage: bsc_nat\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_help()
|
|
|
|
{
|
|
|
|
printf(" Some useful help...\n");
|
|
|
|
printf(" -h --help this text\n");
|
|
|
|
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
|
2010-08-25 17:43:54 +00:00
|
|
|
printf(" -D --daemonize Fork the process into a background daemon\n");
|
2010-06-15 10:44:42 +00:00
|
|
|
printf(" -s --disable-color\n");
|
|
|
|
printf(" -c --config-file filename The config file to use.\n");
|
|
|
|
printf(" -m --msc=IP. The address of the MSC.\n");
|
2010-01-12 20:34:54 +00:00
|
|
|
printf(" -l --local=IP. The local address of this BSC.\n");
|
2010-06-15 10:44:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 22:44:24 +00:00
|
|
|
static void handle_options(int argc, char **argv)
|
2010-06-15 10:44:42 +00:00
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
int option_index = 0, c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"debug", 1, 0, 'd'},
|
2013-01-15 13:37:51 +00:00
|
|
|
{"daemonize", 0, 0, 'D'},
|
2010-06-15 10:44:42 +00:00
|
|
|
{"config-file", 1, 0, 'c'},
|
|
|
|
{"disable-color", 0, 0, 's'},
|
|
|
|
{"timestamp", 0, 0, 'T'},
|
|
|
|
{"msc", 1, 0, 'm'},
|
|
|
|
{"local", 1, 0, 'l'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2013-01-15 13:37:51 +00:00
|
|
|
c = getopt_long(argc, argv, "hd:sTPc:m:l:D",
|
2010-06-15 10:44:42 +00:00
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
print_usage();
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
case 's':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_use_color(osmo_stderr_target, 0);
|
2010-06-15 10:44:42 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_parse_category_mask(osmo_stderr_target, optarg);
|
2010-06-15 10:44:42 +00:00
|
|
|
break;
|
2013-01-15 13:37:51 +00:00
|
|
|
case 'D':
|
|
|
|
daemonize = 1;
|
|
|
|
break;
|
2010-06-15 10:44:42 +00:00
|
|
|
case 'c':
|
2015-02-08 08:25:38 +00:00
|
|
|
config_file = optarg;
|
2010-06-15 10:44:42 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_print_timestamp(osmo_stderr_target, 1);
|
2010-06-15 10:44:42 +00:00
|
|
|
break;
|
|
|
|
case 'm':
|
2010-06-15 10:51:04 +00:00
|
|
|
msc_ip = optarg;
|
2010-06-15 10:44:42 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
inet_aton(optarg, &local_addr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:15:08 +00:00
|
|
|
static void signal_handler(int signal)
|
|
|
|
{
|
|
|
|
switch (signal) {
|
|
|
|
case SIGABRT:
|
|
|
|
/* in case of abort, we want to obtain a talloc report
|
|
|
|
* and then return to the caller, who will abort the process */
|
|
|
|
case SIGUSR1:
|
|
|
|
talloc_report_full(tall_bsc_ctx, stderr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:51:56 +00:00
|
|
|
static void sccp_close_unconfirmed(void *_data)
|
|
|
|
{
|
2011-04-23 21:55:14 +00:00
|
|
|
int destroyed = 0;
|
|
|
|
struct bsc_connection *bsc, *bsc_tmp;
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *conn, *tmp1;
|
2010-06-15 10:51:56 +00:00
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
|
|
|
|
llist_for_each_entry_safe(conn, tmp1, &nat->sccp_connections, list_entry) {
|
|
|
|
if (conn->has_remote_ref)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int diff = (now.tv_sec - conn->creation_time.tv_sec) / 60;
|
|
|
|
if (diff < SCCP_CLOSE_TIME_TIMEOUT)
|
|
|
|
continue;
|
|
|
|
|
2014-04-03 10:28:14 +00:00
|
|
|
LOGP(DNAT, LOGL_ERROR,
|
|
|
|
"SCCP connection 0x%x/0x%x was never confirmed on bsc nr. %d\n",
|
|
|
|
sccp_src_ref_to_int(&conn->real_ref),
|
|
|
|
sccp_src_ref_to_int(&conn->patched_ref),
|
|
|
|
conn->bsc->cfg->nr);
|
2010-06-15 10:51:56 +00:00
|
|
|
sccp_connection_destroy(conn);
|
2011-04-23 21:55:14 +00:00
|
|
|
destroyed = 1;
|
2010-06-15 10:51:56 +00:00
|
|
|
}
|
|
|
|
|
2011-04-23 21:55:14 +00:00
|
|
|
if (!destroyed)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* now close out any BSC */
|
|
|
|
llist_for_each_entry_safe(bsc, bsc_tmp, &nat->bsc_connections, list_entry)
|
|
|
|
bsc_maybe_close(bsc);
|
|
|
|
|
|
|
|
out:
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&sccp_close, SCCP_CLOSE_TIME, 0);
|
2010-06-15 10:51:56 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 10:51:25 +00:00
|
|
|
extern void *tall_msgb_ctx;
|
|
|
|
extern void *tall_ctr_ctx;
|
|
|
|
static void talloc_init_ctx()
|
|
|
|
{
|
|
|
|
tall_bsc_ctx = talloc_named_const(NULL, 0, "nat");
|
|
|
|
tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb");
|
|
|
|
tall_ctr_ctx = talloc_named_const(tall_bsc_ctx, 0, "counter");
|
|
|
|
}
|
|
|
|
|
2010-06-15 12:14:08 +00:00
|
|
|
extern enum node_type bsc_vty_go_parent(struct vty *vty);
|
|
|
|
|
|
|
|
static struct vty_app_info vty_info = {
|
2011-02-24 22:57:06 +00:00
|
|
|
.name = "OsmoBSCNAT",
|
2010-06-15 12:14:08 +00:00
|
|
|
.version = PACKAGE_VERSION,
|
|
|
|
.go_parent_cb = bsc_vty_go_parent,
|
2010-09-04 03:00:01 +00:00
|
|
|
.is_config_node = bsc_vty_is_config_node,
|
2010-06-15 12:14:08 +00:00
|
|
|
};
|
|
|
|
|
2013-06-14 17:10:28 +00:00
|
|
|
|
2010-09-17 22:44:24 +00:00
|
|
|
int main(int argc, char **argv)
|
2010-06-15 10:44:42 +00:00
|
|
|
{
|
2010-08-25 17:43:54 +00:00
|
|
|
int rc;
|
2010-06-15 10:51:25 +00:00
|
|
|
|
2010-08-25 17:43:54 +00:00
|
|
|
talloc_init_ctx();
|
2010-06-15 10:51:18 +00:00
|
|
|
|
2011-05-12 14:02:07 +00:00
|
|
|
osmo_init_logging(&log_info);
|
2010-06-15 11:06:18 +00:00
|
|
|
|
2010-06-15 10:46:11 +00:00
|
|
|
nat = bsc_nat_alloc();
|
|
|
|
if (!nat) {
|
|
|
|
fprintf(stderr, "Failed to allocate the BSC nat.\n");
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
|
2010-08-05 10:08:36 +00:00
|
|
|
nat->mgcp_cfg = mgcp_config_alloc();
|
2010-06-15 10:51:04 +00:00
|
|
|
if (!nat->mgcp_cfg) {
|
|
|
|
fprintf(stderr, "Failed to allocate MGCP cfg.\n");
|
|
|
|
return -5;
|
|
|
|
}
|
|
|
|
|
2010-06-15 12:14:08 +00:00
|
|
|
vty_info.copyright = openbsc_copyright;
|
|
|
|
vty_init(&vty_info);
|
2011-03-09 12:36:32 +00:00
|
|
|
logging_vty_add_cmds(&log_info);
|
2010-06-15 12:14:08 +00:00
|
|
|
bsc_nat_vty_init(nat);
|
|
|
|
|
|
|
|
|
2010-06-15 10:51:04 +00:00
|
|
|
/* parse options */
|
|
|
|
local_addr.s_addr = INADDR_ANY;
|
|
|
|
handle_options(argc, argv);
|
2010-06-15 10:50:26 +00:00
|
|
|
|
2010-06-17 10:16:00 +00:00
|
|
|
rate_ctr_init(tall_bsc_ctx);
|
|
|
|
|
2010-06-15 10:46:11 +00:00
|
|
|
/* init vty and parse */
|
2014-08-24 15:54:49 +00:00
|
|
|
telnet_init(tall_bsc_ctx, NULL, OSMO_VTY_PORT_BSC_NAT);
|
2013-08-02 19:14:14 +00:00
|
|
|
if (mgcp_parse_config(config_file, nat->mgcp_cfg, MGCP_BSC_NAT) < 0) {
|
2010-06-15 10:46:11 +00:00
|
|
|
fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:51:04 +00:00
|
|
|
/* over rule the VTY config */
|
|
|
|
if (msc_ip)
|
|
|
|
bsc_nat_set_msc_ip(nat, msc_ip);
|
|
|
|
|
2010-06-15 10:44:42 +00:00
|
|
|
/* seed the PRNG */
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2013-06-14 17:10:28 +00:00
|
|
|
|
|
|
|
|
2010-03-31 11:02:22 +00:00
|
|
|
/*
|
|
|
|
* Setup the MGCP code..
|
|
|
|
*/
|
2010-04-22 04:08:17 +00:00
|
|
|
if (bsc_mgcp_nat_init(nat) != 0)
|
2010-03-31 11:02:22 +00:00
|
|
|
return -4;
|
|
|
|
|
2010-01-12 20:34:54 +00:00
|
|
|
/* connect to the MSC */
|
2011-04-23 21:31:31 +00:00
|
|
|
nat->msc_con = bsc_msc_create(nat, &nat->dests);
|
2010-05-11 11:07:39 +00:00
|
|
|
if (!nat->msc_con) {
|
2010-06-15 10:47:29 +00:00
|
|
|
fprintf(stderr, "Creating a bsc_msc_connection failed.\n");
|
2010-01-12 20:15:08 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-11-05 15:04:10 +00:00
|
|
|
nat->ctrl = bsc_nat_controlif_setup(nat, 4250);
|
2013-01-15 12:48:18 +00:00
|
|
|
if (!nat->ctrl) {
|
|
|
|
fprintf(stderr, "Creating the control interface failed.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-02-18 13:32:56 +00:00
|
|
|
|
2013-09-02 11:07:45 +00:00
|
|
|
nat->msc_con->name = "main MSC";
|
2010-05-11 11:07:39 +00:00
|
|
|
nat->msc_con->connection_loss = msc_connection_was_lost;
|
2010-08-03 18:31:55 +00:00
|
|
|
nat->msc_con->connected = msc_connection_connected;
|
2010-05-11 11:07:39 +00:00
|
|
|
nat->msc_con->write_queue.read_cb = ipaccess_msc_read_cb;
|
|
|
|
nat->msc_con->write_queue.write_cb = ipaccess_msc_write_cb;;
|
2010-07-05 06:14:18 +00:00
|
|
|
nat->msc_con->write_queue.bfd.data = nat->msc_con;
|
2010-05-11 11:07:39 +00:00
|
|
|
bsc_msc_connect(nat->msc_con);
|
2010-06-15 10:47:29 +00:00
|
|
|
|
2010-01-12 20:34:54 +00:00
|
|
|
/* wait for the BSC */
|
2010-10-19 15:48:13 +00:00
|
|
|
rc = make_sock(&bsc_listen, IPPROTO_TCP, ntohl(local_addr.s_addr),
|
2011-04-07 20:14:58 +00:00
|
|
|
5000, 0, ipaccess_listen_bsc_cb, nat);
|
2010-10-12 21:28:28 +00:00
|
|
|
if (rc != 0) {
|
2010-01-12 20:34:54 +00:00
|
|
|
fprintf(stderr, "Failed to listen for BSC.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:22:36 +00:00
|
|
|
rc = bsc_ussd_init(nat);
|
|
|
|
if (rc != 0) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to bind the USSD socket.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-01-12 20:15:08 +00:00
|
|
|
signal(SIGABRT, &signal_handler);
|
|
|
|
signal(SIGUSR1, &signal_handler);
|
2011-05-12 14:02:07 +00:00
|
|
|
osmo_init_ignore_signals();
|
2010-01-12 20:15:08 +00:00
|
|
|
|
2010-08-25 17:43:54 +00:00
|
|
|
if (daemonize) {
|
|
|
|
rc = osmo_daemonize();
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error during daemonize");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:51:56 +00:00
|
|
|
/* recycle timer */
|
2010-07-29 18:53:14 +00:00
|
|
|
sccp_set_log_area(DSCCP);
|
2010-06-15 10:51:56 +00:00
|
|
|
sccp_close.cb = sccp_close_unconfirmed;
|
|
|
|
sccp_close.data = NULL;
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&sccp_close, SCCP_CLOSE_TIME, 0);
|
2010-06-15 10:51:56 +00:00
|
|
|
|
2010-01-12 20:15:08 +00:00
|
|
|
while (1) {
|
2011-05-06 10:11:23 +00:00
|
|
|
osmo_select_main(0);
|
2010-01-12 20:15:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 10:44:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-10-27 09:01:55 +00:00
|
|
|
|
|
|
|
/* Close all connections handed out to the USSD module */
|
2013-08-26 12:04:43 +00:00
|
|
|
int bsc_ussd_close_connections(struct bsc_nat *nat)
|
2010-10-27 09:01:55 +00:00
|
|
|
{
|
2013-04-16 07:53:13 +00:00
|
|
|
struct nat_sccp_connection *con;
|
2010-10-27 09:01:55 +00:00
|
|
|
llist_for_each_entry(con, &nat->sccp_connections, list_entry) {
|
2011-04-16 14:02:59 +00:00
|
|
|
if (con->con_local != NAT_CON_END_USSD)
|
2010-10-27 09:01:55 +00:00
|
|
|
continue;
|
|
|
|
if (!con->bsc)
|
|
|
|
continue;
|
|
|
|
|
2010-10-27 09:58:04 +00:00
|
|
|
nat_send_clrc_bsc(con);
|
2010-10-27 09:01:55 +00:00
|
|
|
nat_send_rlsd_bsc(con);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|