From e833478898850aad99fe5b9b1efee34e6ec1ca64 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 11 Dec 2012 14:19:03 +0100 Subject: isup: Hook the reset scanner before we forward the ISUP message Scan for two kind of reset messages in the ISUP messages. Forward them to the mgcp_ss7. --- include/Makefile.am | 3 +- include/bsc_data.h | 8 +++-- include/isup_filter.h | 29 +++++++++++++++++ src/Makefile.am | 4 +-- src/isup_filter.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main_stp.c | 13 ++++++++ src/ss7_application.c | 2 ++ src/vty_interface.c | 4 ++- 8 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 include/isup_filter.h create mode 100644 src/isup_filter.c diff --git a/include/Makefile.am b/include/Makefile.am index c46e698..aff4e37 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -2,6 +2,7 @@ noinst_HEADERS = mtp_level3.h mtp_data.h ipaccess.h thread.h mtp_pcap.h \ mgcp_ss7.h bss_patch.h bssap_sccp.h bsc_data.h udp_input.h \ snmp_mtp.h cellmgr_debug.h bsc_sccp.h bsc_ussd.h sctp_m2ua.h \ isup_types.h counter.h msc_connection.h ss7_application.h \ - mgcp_patch.h ss7_vty.h dtmf_scheduler.h mgcp_callagent.h + mgcp_patch.h ss7_vty.h dtmf_scheduler.h mgcp_callagent.h \ + isup_filter.h SUBDIRS = mgcp diff --git a/include/bsc_data.h b/include/bsc_data.h index ecd0747..b1e0fbe 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -1,7 +1,7 @@ /* Everything related to the BSC connection */ /* - * (C) 2010-2011 by Holger Hans Peter Freyther - * (C) 2010-2011 by On-Waves + * (C) 2010-2012 by Holger Hans Peter Freyther + * (C) 2010-2012 by On-Waves * All Rights Reserved * * This program is free software: you can redistribute it and/or modify @@ -23,6 +23,7 @@ #define BSC_DATA_H #include "mtp_data.h" +#include "mgcp_callagent.h" #include #include @@ -92,6 +93,9 @@ struct bsc_data { struct llist_head mscs; int num_mscs; + /* Simple send only mgcp agent */ + struct mgcp_callagent mgcp_agent; + /* application */ struct llist_head apps; int num_apps; diff --git a/include/isup_filter.h b/include/isup_filter.h new file mode 100644 index 0000000..2c56f73 --- /dev/null +++ b/include/isup_filter.h @@ -0,0 +1,29 @@ +/* + * (C) 2012 by Holger Hans Peter Freyther + * (C) 2012 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 Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#ifndef isup_filter_h +#define isup_filter_h + +struct ss7_application; +struct msgb; + +int isup_scan_for_reset(struct ss7_application *app, struct msgb *msg); + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 4d6061c..d2e211d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ cellmgr_ng_SOURCES = main.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \ msc_conn.c link_udp.c snmp_mtp.c debug.c isup.c \ mtp_link.c counter.c sccp_state.c bsc.c ss7_application.c \ vty_interface_legacy.c vty_interface_cmds.c mgcp_patch.c \ - mgcp_callagent.c + mgcp_callagent.c isup_filter.c cellmgr_ng_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \ $(LIBOSMOSCCP_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto @@ -26,7 +26,7 @@ osmo_stp_SOURCES = main_stp.c mtp_layer3.c thread.c pcap.c link_udp.c snmp_mtp.c bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c input/ipaccess.c \ mtp_link.c counter.c bsc.c ss7_application.c \ vty_interface.c vty_interface_cmds.c mgcp_patch.c \ - mgcp_callagent.c + mgcp_callagent.c isup_filter.c osmo_stp_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \ $(LIBOSMOSCCP_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto -lm2ua -lsctp diff --git a/src/isup_filter.c b/src/isup_filter.c new file mode 100644 index 0000000..db023b6 --- /dev/null +++ b/src/isup_filter.c @@ -0,0 +1,86 @@ +/* + * (C) 2012 by Holger Hans Peter Freyther + * (C) 2012 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 Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include +#include + + +#include + +#include +#include + +static void send_reset(struct ss7_application *app, int endp, int range) +{ + char buf[1024]; + + snprintf(buf, sizeof(buf) - 1, + "RSIP 2 %s/%d@127.0.0.1 MGCP 1.0\r\n" + "R: %d\n", app->trunk_name, endp, range); + buf[sizeof(buf) - 1] = '\0'; + mgcp_forward(&app->bsc->mgcp_agent, + (const uint8_t *) buf, strlen(buf)); +} + + +static void reset_cic(struct ss7_application *app, int cic) +{ + return send_reset(app, cic, 1); +} + +static void reset_cics(struct ss7_application *app, int cic, int range) +{ + return send_reset(app, cic, range); +} + +/** + * Discover resets and forward them to the local MGCP gateway + */ +int isup_scan_for_reset(struct ss7_application *app, struct msgb *msg) +{ + struct isup_msg_hdr *hdr; + int range; + + /* too small for an isup message? */ + if (msgb_l3len(msg) < sizeof(*hdr)) + return -1; + + /* no trunk name, don't bother forwarding */ + if (!app->trunk_name) + return 0; + + hdr = (struct isup_msg_hdr *) msg->l3h; + switch (hdr->msg_type) { + case ISUP_MSG_GRS: + range = isup_parse_status(&hdr->data[0], + msgb_l3len(msg) - sizeof(*hdr)); + if (range >= 0) + reset_cics(app, hdr->cic, range); + break; + case ISUP_MSG_RSC: + reset_cic(app, hdr->cic); + break; + } + + return 0; +} diff --git a/src/main_stp.c b/src/main_stp.c index fd20eb3..11f6255 100644 --- a/src/main_stp.c +++ b/src/main_stp.c @@ -70,6 +70,12 @@ struct bsc_data *bsc; extern void cell_vty_init(void); extern void handle_options(int argc, char **argv); +static void mgcp_destroy_cb(struct mgcp_callagent *agent, struct msgb *msg) +{ + /* we do not care about potential responses here */ + msgb_free(msg); +} + static struct mtp_link_set *find_link_set(struct bsc_data *bsc, int len, const char *buf) { @@ -261,6 +267,13 @@ int main(int argc, char **argv) return -1; } + if (mgcp_create_port(&bsc->mgcp_agent) != 0) { + LOGP(DINP, LOGL_ERROR, + "Failed to create the MGCP call agent.\n"); + return -1; + } + bsc->mgcp_agent.read_cb = mgcp_destroy_cb; + /* start all apps */ llist_for_each_entry(app, &bsc->apps, entry) { LOGP(DINP, LOGL_NOTICE, diff --git a/src/ss7_application.c b/src/ss7_application.c index b28c376..cedc2d0 100644 --- a/src/ss7_application.c +++ b/src/ss7_application.c @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -45,6 +46,7 @@ static void forward_isup_stp(struct mtp_link_set *set, struct msgb *msg, int sls struct mtp_link_set *other; other = set->app->route_src.set == set ? set->app->route_dst.set : set->app->route_src.set; + isup_scan_for_reset(set->app, msg); mtp_link_set_submit_isup_data(other, sls, msg->l3h, msgb_l3len(msg)); } diff --git a/src/vty_interface.c b/src/vty_interface.c index 48e150e..001ba44 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -298,7 +298,9 @@ static void write_application(struct vty *vty, struct ss7_application *app) if (app->type == APP_STP) { vty_out(vty, " isup-pass-through %d%s", app->isup_pass, VTY_NEWLINE); - vty_out(vty, " trunk-name %s%s", app->trunk_name, VTY_NEWLINE); + if (app->trunk_name) + vty_out(vty, " trunk-name %s%s", + app->trunk_name, VTY_NEWLINE); } if (app->type == APP_CELLMGR && app->mgcp_domain_name) { -- cgit v1.2.3