blob: 1102ee686cfadf7284b6d57161d64464ab47e8eb [file] [log] [blame]
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +01001/* link management code */
2/*
3 * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010-2011 by On-Waves
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <bsc_data.h>
24#include <cellmgr_debug.h>
25#include <mtp_data.h>
26#include <snmp_mtp.h>
27
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010028#include <osmocore/talloc.h>
29
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010030extern struct bsc_data bsc;
31
Holger Hans Peter Freytherc8405692011-01-02 20:24:08 +010032void mtp_link_down(struct link_data *link)
33{
34 mtp_linkset_down(link->the_link);
35 link->clear_queue(link);
36}
37
38void mtp_link_up(struct link_data *link)
39{
40 mtp_linkset_up(link->the_link);
41}
42
Holger Hans Peter Freyther569f1e12011-01-02 18:47:49 +010043void mtp_link_set_sccp_down(struct mtp_link_set *link)
Holger Hans Peter Freyther016ba292010-12-20 16:21:18 +010044{
45}
46
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010047void mtp_link_set_submit(struct mtp_link_set *set, struct msgb *msg)
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010048{
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010049 set->link->write(set->link, msg);
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010050}
51
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010052void mtp_link_set_restart(struct mtp_link_set *set)
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010053{
54 LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n");
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010055 set->link->reset(set->link);
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010056}
57
58static void start_rest(void *start)
59{
60 bsc.setup = 1;
61
62 if (msc_init(&bsc, 1) != 0) {
63 fprintf(stderr, "Failed to init MSC part.\n");
64 exit(3);
65 }
66
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010067 bsc.link_set->link->start(bsc.link_set->link);
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010068}
69
70int link_init(struct bsc_data *bsc)
71{
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010072 bsc->link_set = mtp_link_set_alloc();
73 bsc->link_set->dpc = bsc->dpc;
74 bsc->link_set->opc = bsc->opc;
75 bsc->link_set->sccp_opc = bsc->sccp_opc > -1 ? bsc->sccp_opc : bsc->opc;
76 bsc->link_set->sltm_once = bsc->once;
77 bsc->link_set->ni = bsc->ni_ni;
78 bsc->link_set->spare = bsc->ni_spare;
79 bsc->link_set->bsc = bsc;
80
81 bsc->link_set->link = talloc_zero(bsc->link_set, struct link_data);
82 bsc->link_set->link->bsc = bsc;
83 bsc->link_set->link->udp.link_index = 1;
84 bsc->link_set->link->pcap_fd = bsc->pcap_fd;
85 bsc->link_set->link->udp.reset_timeout = bsc->udp_reset_timeout;
86 bsc->link_set->link->the_link = bsc->link_set;
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010087
88 if (!bsc->src_port) {
89 LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n");
90 return -1;
91 }
92
93 LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n");
94
95 /* setup SNMP first, it is blocking */
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010096 bsc->link_set->link->udp.session = snmp_mtp_session_create(bsc->udp_ip);
97 if (!bsc->link_set->link->udp.session)
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +010098 return -1;
99
100 /* now connect to the transport */
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +0100101 if (link_udp_init(bsc->link_set->link, bsc->src_port, bsc->udp_ip, bsc->udp_port) != 0)
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +0100102 return -1;
103
104 /*
105 * We will ask the MTP link to be taken down for two
106 * timeouts of the BSC to make sure we are missing the
107 * SLTM and it begins a reset. Then we will take it up
108 * again and do the usual business.
109 */
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +0100110 snmp_mtp_deactivate(bsc->link_set->link->udp.session,
111 bsc->link_set->link->udp.link_index);
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +0100112 bsc->start_timer.cb = start_rest;
113 bsc->start_timer.data = &bsc;
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +0100114 bsc_schedule_timer(&bsc->start_timer, bsc->link_set->link->udp.reset_timeout, 0);
Holger Hans Peter Freythera99b04b2011-01-02 11:23:54 +0100115 LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n");
116
117 return 0;
118}