Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 1 | /* 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 | |
| 28 | extern struct bsc_data bsc; |
| 29 | |
Holger Hans Peter Freyther | c840569 | 2011-01-02 20:24:08 +0100 | [diff] [blame^] | 30 | void mtp_link_down(struct link_data *link) |
| 31 | { |
| 32 | mtp_linkset_down(link->the_link); |
| 33 | link->clear_queue(link); |
| 34 | } |
| 35 | |
| 36 | void mtp_link_up(struct link_data *link) |
| 37 | { |
| 38 | mtp_linkset_up(link->the_link); |
| 39 | } |
| 40 | |
Holger Hans Peter Freyther | 569f1e1 | 2011-01-02 18:47:49 +0100 | [diff] [blame] | 41 | void mtp_link_set_sccp_down(struct mtp_link_set *link) |
Holger Hans Peter Freyther | 016ba29 | 2010-12-20 16:21:18 +0100 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Holger Hans Peter Freyther | 569f1e1 | 2011-01-02 18:47:49 +0100 | [diff] [blame] | 45 | void mtp_link_set_submit(struct mtp_link_set *link, struct msgb *msg) |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 46 | { |
| 47 | bsc.link.write(&bsc.link, msg); |
| 48 | } |
| 49 | |
Holger Hans Peter Freyther | 569f1e1 | 2011-01-02 18:47:49 +0100 | [diff] [blame] | 50 | void mtp_link_set_restart(struct mtp_link_set *link) |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 51 | { |
| 52 | LOGP(DINP, LOGL_ERROR, "Need to restart the SS7 link.\n"); |
| 53 | bsc.link.reset(&bsc.link); |
| 54 | } |
| 55 | |
| 56 | static void start_rest(void *start) |
| 57 | { |
| 58 | bsc.setup = 1; |
| 59 | |
| 60 | if (msc_init(&bsc, 1) != 0) { |
| 61 | fprintf(stderr, "Failed to init MSC part.\n"); |
| 62 | exit(3); |
| 63 | } |
| 64 | |
| 65 | bsc.link.start(&bsc.link); |
| 66 | } |
| 67 | |
| 68 | int link_init(struct bsc_data *bsc) |
| 69 | { |
Holger Hans Peter Freyther | 569f1e1 | 2011-01-02 18:47:49 +0100 | [diff] [blame] | 70 | bsc->link.the_link = mtp_link_set_alloc(); |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 71 | bsc->link.the_link->dpc = bsc->dpc; |
| 72 | bsc->link.the_link->opc = bsc->opc; |
| 73 | bsc->link.the_link->sccp_opc = bsc->sccp_opc > -1 ? bsc->sccp_opc : bsc->opc; |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 74 | bsc->link.the_link->sltm_once = bsc->once; |
| 75 | bsc->link.the_link->ni = bsc->ni_ni; |
| 76 | bsc->link.the_link->spare = bsc->ni_spare; |
Holger Hans Peter Freyther | c840569 | 2011-01-02 20:24:08 +0100 | [diff] [blame^] | 77 | bsc->link.the_link->bsc = bsc; |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 78 | bsc->link.bsc = bsc; |
Holger Hans Peter Freyther | b6edf97 | 2011-01-02 16:41:11 +0100 | [diff] [blame] | 79 | bsc->link.udp.link_index = 1; |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 80 | |
| 81 | if (!bsc->src_port) { |
| 82 | LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n"); |
| 83 | return -1; |
| 84 | } |
| 85 | |
| 86 | LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n"); |
| 87 | |
| 88 | /* setup SNMP first, it is blocking */ |
| 89 | bsc->link.udp.session = snmp_mtp_session_create(bsc->udp_ip); |
| 90 | if (!bsc->link.udp.session) |
| 91 | return -1; |
| 92 | |
| 93 | /* now connect to the transport */ |
| 94 | if (link_udp_init(&bsc->link, bsc->src_port, bsc->udp_ip, bsc->udp_port) != 0) |
| 95 | return -1; |
| 96 | |
| 97 | /* |
| 98 | * We will ask the MTP link to be taken down for two |
| 99 | * timeouts of the BSC to make sure we are missing the |
| 100 | * SLTM and it begins a reset. Then we will take it up |
| 101 | * again and do the usual business. |
| 102 | */ |
Holger Hans Peter Freyther | b6edf97 | 2011-01-02 16:41:11 +0100 | [diff] [blame] | 103 | snmp_mtp_deactivate(bsc->link.udp.session, |
| 104 | bsc->link.udp.link_index); |
Holger Hans Peter Freyther | a99b04b | 2011-01-02 11:23:54 +0100 | [diff] [blame] | 105 | bsc->start_timer.cb = start_rest; |
| 106 | bsc->start_timer.data = &bsc; |
| 107 | bsc_schedule_timer(&bsc->start_timer, bsc->link.udp.reset_timeout, 0); |
| 108 | LOGP(DMSC, LOGL_NOTICE, "Making sure SLTM will timeout.\n"); |
| 109 | |
| 110 | return 0; |
| 111 | } |