aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2013-05-13 18:18:02 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2013-05-13 21:17:07 +0200
commitfe1550fed4146fd016f0d2cffc07f6ae8ed6b7fe (patch)
treee98a9d56e130cb3f0673eae80a1522b8685a2a3d
parentd2fdb2afbf1c495e3ab455dd90058501c14f57d4 (diff)
patching: Get the struct ss7_application down to the patching routine
-rw-r--r--include/bss_patch.h4
-rw-r--r--src/bss_patch.c14
-rw-r--r--src/sccp_state.c4
-rw-r--r--tests/patching/patching_test.c13
4 files changed, 23 insertions, 12 deletions
diff --git a/include/bss_patch.h b/include/bss_patch.h
index d9a055b..c950d55 100644
--- a/include/bss_patch.h
+++ b/include/bss_patch.h
@@ -36,6 +36,8 @@
#define BSS_DIR_MSC 2
#define BSS_DIR_ANY (BSS_DIR_MSC | BSS_DIR_BSC)
+struct ss7_application;
+
/**
* Error is < 0
* Success is == 0
@@ -43,7 +45,7 @@
*
* Direction...
*/
-int bss_patch_filter_msg(struct msgb *msg, struct sccp_parse_result *result, int dir);
+int bss_patch_filter_msg(struct ss7_application *app, struct msgb *msg, struct sccp_parse_result *result, int dir);
/*
* Copy inpt->l2h to target->l2h but rewrite the SCCP header on the way
diff --git a/src/bss_patch.c b/src/bss_patch.c
index 9d89d87..cc897b6 100644
--- a/src/bss_patch.c
+++ b/src/bss_patch.c
@@ -34,7 +34,7 @@
#include <arpa/inet.h>
-static int handle_bss_mgmt(struct msgb *msg, struct sccp_parse_result *sccp);
+static int handle_bss_mgmt(struct ss7_application *, struct msgb *msg, struct sccp_parse_result *sccp);
static int handle_bss_dtap(struct msgb *msg, struct sccp_parse_result *sccp, int dir);
static void patch_ass_rqst(struct msgb *msg, int length)
@@ -66,7 +66,7 @@ static void patch_ass_rqst(struct msgb *msg, int length)
}
}
-static void patch_ass_cmpl(struct msgb *msg, int length)
+static void patch_ass_cmpl(struct ss7_application *app, struct msgb *msg, int length)
{
struct tlv_parsed tp;
uint8_t *data;
@@ -103,7 +103,8 @@ static void patch_ass_cmpl(struct msgb *msg, int length)
}
}
-int bss_patch_filter_msg(struct msgb *msg, struct sccp_parse_result *sccp, int dir)
+int bss_patch_filter_msg(struct ss7_application *app, struct msgb *msg,
+ struct sccp_parse_result *sccp, int dir)
{
int type;
memset(sccp, 0, sizeof(*sccp));
@@ -145,7 +146,7 @@ int bss_patch_filter_msg(struct msgb *msg, struct sccp_parse_result *sccp, int d
}
if (msg->l3h[0] == BSSAP_MSG_BSS_MANAGEMENT)
- return handle_bss_mgmt(msg, sccp);
+ return handle_bss_mgmt(app, msg, sccp);
if (msg->l3h[0] == BSSAP_MSG_DTAP)
return handle_bss_dtap(msg, sccp, dir);
@@ -153,7 +154,8 @@ int bss_patch_filter_msg(struct msgb *msg, struct sccp_parse_result *sccp, int d
return -1;
}
-static int handle_bss_mgmt(struct msgb *msg, struct sccp_parse_result *sccp)
+static int handle_bss_mgmt(struct ss7_application *app, struct msgb *msg,
+ struct sccp_parse_result *sccp)
{
switch (msg->l3h[2]) {
case BSS_MAP_MSG_ASSIGMENT_RQST:
@@ -162,7 +164,7 @@ static int handle_bss_mgmt(struct msgb *msg, struct sccp_parse_result *sccp)
break;
case BSS_MAP_MSG_ASSIGMENT_COMPLETE:
msg->l3h = &msg->l3h[2];
- patch_ass_cmpl(msg, sccp->data_len - 2);
+ patch_ass_cmpl(app, msg, sccp->data_len - 2);
break;
case BSS_MAP_MSG_RESET:
return BSS_FILTER_RESET;
diff --git a/src/sccp_state.c b/src/sccp_state.c
index c2b3834..e961fdd 100644
--- a/src/sccp_state.c
+++ b/src/sccp_state.c
@@ -71,7 +71,7 @@ void app_forward_sccp(struct ss7_application *app, struct msgb *_msg, int sls)
return;
}
- rc = bss_patch_filter_msg(_msg, &result, BSS_DIR_MSC);
+ rc = bss_patch_filter_msg(app, _msg, &result, BSS_DIR_MSC);
if (rc == BSS_FILTER_RESET) {
LOGP(DMSC, LOGL_NOTICE, "Filtering BSS Reset from the BSC\n");
msc_mgcp_reset(msc);
@@ -549,7 +549,7 @@ void msc_dispatch_sccp(struct msc_connection *msc, struct msgb *msg)
struct sccp_parse_result result;
int rc;
- rc = bss_patch_filter_msg(msg, &result, BSS_DIR_BSC);
+ rc = bss_patch_filter_msg(msc->app, msg, &result, BSS_DIR_BSC);
if (rc == BSS_FILTER_RESET_ACK) {
LOGP(DMSC, LOGL_NOTICE, "Filtering reset ack from the MSC\n");
diff --git a/tests/patching/patching_test.c b/tests/patching/patching_test.c
index 16ba879..e97d568 100644
--- a/tests/patching/patching_test.c
+++ b/tests/patching/patching_test.c
@@ -1,6 +1,7 @@
#include <bss_patch.h>
#include <cellmgr_debug.h>
+#include <ss7_application.h>
#include <osmocom/core/application.h>
#include <osmocom/core/utils.h>
@@ -243,6 +244,9 @@ static void test_patch_filter(void)
{
int i;
+ struct ss7_application app;
+ memset(&app, 0, sizeof(app));
+
printf("Testing patching of GSM messages to the MSC.\n");
for (i = 0; i < sizeof(results)/sizeof(results[0]); ++i) {
@@ -254,7 +258,7 @@ static void test_patch_filter(void)
msgb_put(msg, 1);
msg->l2h = msgb_put(msg, results[i].inp_len);
memcpy(msg->l2h, results[i].input, msgb_l2len(msg));
- rc = bss_patch_filter_msg(msg, &result, BSS_DIR_ANY);
+ rc = bss_patch_filter_msg(&app, msg, &result, BSS_DIR_ANY);
if (memcmp(msg->l2h, results[i].expected, results[i].exp_len) != 0) {
printf("Failed to patch the packet.\n");
@@ -273,6 +277,9 @@ static void test_rewrite_msc(void)
{
int i;
+ struct ss7_application app;
+ memset(&app, 0, sizeof(app));
+
printf("Testing rewriting the SCCP header.\n");
for (i = 0; i < sizeof(rewrite_results_to_msc)/sizeof(rewrite_results_to_msc[0]); ++i) {
struct sccp_parse_result result;
@@ -286,7 +293,7 @@ static void test_rewrite_msc(void)
inp->l2h = msgb_put(inp, rewrite_results_to_msc[i].inp_len);
memcpy(inp->l2h, rewrite_results_to_msc[i].input, msgb_l2len(inp));
- rc = bss_patch_filter_msg(inp, &result, BSS_DIR_MSC);
+ rc = bss_patch_filter_msg(&app, inp, &result, BSS_DIR_MSC);
if (rc < 0) {
printf("Failed to parse header msg: %d\n", i);
abort();
@@ -295,7 +302,7 @@ static void test_rewrite_msc(void)
bss_rewrite_header_for_msc(rc, outp, inp, &result);
memset(&result, 0, sizeof(result));
- rc = bss_patch_filter_msg(outp, &result, BSS_DIR_MSC);
+ rc = bss_patch_filter_msg(&app, outp, &result, BSS_DIR_MSC);
if (rc < 0) {
printf("Patched message doesn't work: %d\n", i);
printf("hex: %s\n", osmo_hexdump(outp->l2h, msgb_l2len(outp)));