2011-01-02 10:23:54 +00:00
|
|
|
/* link management code */
|
|
|
|
/*
|
|
|
|
* (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2010-2011 by On-Waves
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bsc_data.h>
|
|
|
|
#include <cellmgr_debug.h>
|
2011-02-15 19:01:47 +00:00
|
|
|
#include <msc_connection.h>
|
2011-01-02 10:23:54 +00:00
|
|
|
#include <mtp_data.h>
|
2015-03-24 18:24:22 +00:00
|
|
|
#include <osmocom/mtp/mtp_level3.h>
|
2011-01-22 16:36:01 +00:00
|
|
|
#include <mtp_pcap.h>
|
2011-01-02 10:23:54 +00:00
|
|
|
#include <snmp_mtp.h>
|
|
|
|
|
2011-05-08 08:29:23 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2011-01-03 22:51:07 +00:00
|
|
|
|
2011-02-15 19:25:10 +00:00
|
|
|
extern struct bsc_data *bsc;
|
2011-01-02 10:23:54 +00:00
|
|
|
|
2011-01-04 12:33:57 +00:00
|
|
|
int is_one_up(struct mtp_link_set *set)
|
|
|
|
{
|
2011-01-17 10:54:39 +00:00
|
|
|
struct mtp_link *entry;
|
2011-01-04 12:33:57 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(entry, &set->links, entry)
|
|
|
|
if (entry->available)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-17 10:54:39 +00:00
|
|
|
void mtp_link_down(struct mtp_link *link)
|
2011-01-02 19:24:08 +00:00
|
|
|
{
|
2011-01-04 12:33:57 +00:00
|
|
|
int one_up;
|
|
|
|
int was_up;
|
|
|
|
|
|
|
|
was_up = link->available;
|
|
|
|
link->available = 0;
|
2011-01-20 15:30:24 +00:00
|
|
|
link->was_up = 0;
|
2011-01-20 14:42:13 +00:00
|
|
|
one_up = is_one_up(link->set);
|
2011-01-04 12:33:57 +00:00
|
|
|
|
|
|
|
/* our linkset is now unsuable */
|
|
|
|
if (was_up && !one_up)
|
2011-01-20 14:42:13 +00:00
|
|
|
mtp_linkset_down(link->set);
|
2011-01-02 19:24:08 +00:00
|
|
|
link->clear_queue(link);
|
2011-01-20 15:30:24 +00:00
|
|
|
mtp_link_stop_link_test(link);
|
2011-01-20 14:42:13 +00:00
|
|
|
mtp_link_set_init_slc(link->set);
|
2011-01-02 19:24:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 10:54:39 +00:00
|
|
|
void mtp_link_up(struct mtp_link *link)
|
2011-01-02 19:24:08 +00:00
|
|
|
{
|
2011-01-04 12:33:57 +00:00
|
|
|
int one_up;
|
|
|
|
|
2011-01-28 17:26:20 +00:00
|
|
|
if (link->blocked) {
|
2011-02-17 02:23:42 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR,
|
|
|
|
"Ignoring link up on blocked link %d/%s of linkset %d/%s.\n",
|
|
|
|
link->nr, link->name, link->set->nr, link->set->name);
|
2011-01-28 17:26:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-20 14:42:13 +00:00
|
|
|
one_up = is_one_up(link->set);
|
2011-01-04 12:33:57 +00:00
|
|
|
link->available = 1;
|
2011-01-20 15:30:24 +00:00
|
|
|
link->was_up = 0;
|
2011-01-04 12:33:57 +00:00
|
|
|
|
2011-01-20 14:42:13 +00:00
|
|
|
mtp_link_set_init_slc(link->set);
|
2011-01-04 12:33:57 +00:00
|
|
|
if (!one_up)
|
2011-01-20 14:42:13 +00:00
|
|
|
mtp_linkset_up(link->set);
|
2011-01-20 15:30:24 +00:00
|
|
|
else
|
|
|
|
mtp_link_start_link_test(link);
|
2011-01-02 19:24:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 10:54:39 +00:00
|
|
|
void mtp_link_restart(struct mtp_link *link)
|
2011-01-02 10:23:54 +00:00
|
|
|
{
|
|
|
|
LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n");
|
2011-01-04 12:21:52 +00:00
|
|
|
link->reset(link);
|
2011-01-02 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 19:32:09 +00:00
|
|
|
struct mtp_link_set *link_set_create(struct bsc_data *bsc)
|
2011-01-02 10:23:54 +00:00
|
|
|
{
|
2011-02-10 17:26:07 +00:00
|
|
|
struct mtp_link_set *set;
|
|
|
|
|
2011-02-15 10:18:38 +00:00
|
|
|
set = mtp_link_set_alloc(bsc);
|
2011-02-10 17:26:07 +00:00
|
|
|
set->name = talloc_strdup(set, "MTP");
|
2011-01-03 22:51:07 +00:00
|
|
|
|
2011-02-17 19:32:09 +00:00
|
|
|
set->ni = MTP_NI_NATION_NET;
|
|
|
|
set->spare = 0;
|
|
|
|
|
2011-02-17 00:48:42 +00:00
|
|
|
set->supported_ssn[1] = 1;
|
|
|
|
set->supported_ssn[7] = 1;
|
|
|
|
set->supported_ssn[8] = 1;
|
|
|
|
set->supported_ssn[146] = 1;
|
|
|
|
set->supported_ssn[254] = 1;
|
|
|
|
|
2011-02-17 19:32:09 +00:00
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
int link_init(struct bsc_data *bsc, struct mtp_link_set *set)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct mtp_udp_link *lnk;
|
|
|
|
struct mtp_link *blnk;
|
|
|
|
|
|
|
|
|
2011-02-22 19:57:08 +00:00
|
|
|
if (!bsc->udp_src_port) {
|
2011-01-02 10:23:54 +00:00
|
|
|
LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n");
|
2011-02-17 19:32:09 +00:00
|
|
|
return -1;
|
2011-01-02 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n");
|
|
|
|
|
2011-02-22 19:57:08 +00:00
|
|
|
if (link_global_init(&bsc->udp_data) != 0)
|
2011-02-17 19:32:09 +00:00
|
|
|
return -1;
|
2011-01-02 10:23:54 +00:00
|
|
|
|
2011-02-22 19:57:08 +00:00
|
|
|
if (link_global_bind(&bsc->udp_data, bsc->udp_src_port) != 0)
|
|
|
|
return -1;
|
2011-01-02 10:23:54 +00:00
|
|
|
|
2011-01-22 16:06:34 +00:00
|
|
|
for (i = 1; i <= bsc->udp_nr_links; ++i) {
|
2011-02-17 01:18:38 +00:00
|
|
|
blnk = mtp_link_alloc(set);
|
2011-02-22 19:57:08 +00:00
|
|
|
lnk = mtp_udp_link_init(blnk);
|
|
|
|
|
2011-02-25 15:29:45 +00:00
|
|
|
lnk->link_index = i;
|
2011-01-22 16:06:34 +00:00
|
|
|
|
|
|
|
/* now connect to the transport */
|
2011-02-22 19:57:08 +00:00
|
|
|
if (snmp_mtp_peer_name(lnk->session, bsc->udp_ip) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-22 16:06:34 +00:00
|
|
|
if (link_udp_init(lnk, bsc->udp_ip, bsc->udp_port) != 0)
|
2011-02-17 19:32:09 +00:00
|
|
|
return -1;
|
2011-01-22 16:06:34 +00:00
|
|
|
}
|
2011-01-02 10:23:54 +00:00
|
|
|
|
2011-02-17 19:32:09 +00:00
|
|
|
return 0;
|
2011-01-02 10:23:54 +00:00
|
|
|
}
|
2011-01-04 12:21:52 +00:00
|
|
|
|
|
|
|
int link_shutdown_all(struct mtp_link_set *set)
|
|
|
|
{
|
2011-01-17 10:54:39 +00:00
|
|
|
struct mtp_link *lnk;
|
2011-01-04 12:21:52 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(lnk, &set->links, entry)
|
|
|
|
lnk->shutdown(lnk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int link_reset_all(struct mtp_link_set *set)
|
|
|
|
{
|
2011-01-17 10:54:39 +00:00
|
|
|
struct mtp_link *lnk;
|
2011-01-04 12:21:52 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(lnk, &set->links, entry)
|
|
|
|
lnk->reset(lnk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int link_clear_all(struct mtp_link_set *set)
|
|
|
|
{
|
2011-01-17 10:54:39 +00:00
|
|
|
struct mtp_link *lnk;
|
2011-01-04 12:21:52 +00:00
|
|
|
|
|
|
|
llist_for_each_entry(lnk, &set->links, entry)
|
|
|
|
lnk->clear_queue(lnk);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-22 16:36:01 +00:00
|
|
|
|
2011-01-22 16:37:56 +00:00
|
|
|
int mtp_handle_pcap(struct mtp_link *link, int dir, const uint8_t *data, int len)
|
2011-01-22 16:36:01 +00:00
|
|
|
{
|
2011-01-23 15:18:18 +00:00
|
|
|
if (link->pcap_fd >= 0)
|
2011-01-22 20:01:23 +00:00
|
|
|
mtp_pcap_write_msu(link->pcap_fd, data, len);
|
2011-01-23 15:18:18 +00:00
|
|
|
if (link->set->pcap_fd >= 0)
|
2011-01-22 20:01:23 +00:00
|
|
|
mtp_pcap_write_msu(link->set->pcap_fd, data, len);
|
2011-01-22 22:19:27 +00:00
|
|
|
|
|
|
|
/* This might be too expensive? */
|
2011-05-08 08:29:23 +00:00
|
|
|
LOGP(DPCAP, LOGL_NOTICE, "Packet: %s\n", osmo_hexdump(data, len));
|
2011-01-22 16:36:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|