patching: Get the struct ss7_application down to the patching routine
parent
6553f1b5e9
commit
b566c79d82
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -84,7 +84,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);
|
||||
|
@ -562,7 +562,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");
|
||||
|
|
|
@ -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)));
|
||||
|
|
Reference in New Issue