aboutsummaryrefslogtreecommitdiffstats
path: root/src/isup_filter.c
blob: db023b64d70cde969ccb6b25fd3080dfb63d5d26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 <http://www.gnu.org/licenses/>.
 *
 */

#include <isup_filter.h>
#include <isup_types.h>
#include <mgcp_callagent.h>
#include <ss7_application.h>
#include <bsc_data.h>


#include <osmocom/core/msgb.h>

#include <stdio.h>
#include <string.h>

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;
}