summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-03 14:43:52 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-03 16:16:41 +0200
commitedd0d5966a2f3fcc57de485c9766ec19b01d9f53 (patch)
treea92008e05b6e1695b8283357f8a1ebae88635b7c
parent0b6c8e0e73e5728666fdf75d79e1060ce3ee89bc (diff)
nat: Implement forwarding data to the local MSC
-rw-r--r--openbsc/include/openbsc/bsc_nat.h3
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c61
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_ussd.c3
3 files changed, 62 insertions, 5 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 2cb07156c..e40186e3f 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -38,6 +38,9 @@
#define DIR_BSC 1
#define DIR_MSC 2
+#define USSD_LAC_IE 0
+#define USSD_CI_IE 1
+
#define PAGIN_GROUP_UNASSIGNED -1
struct sccp_source_reference;
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c b/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c
index 00b306490..9e94da074 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c
@@ -24,6 +24,7 @@
#include <openbsc/bsc_msc.h>
#include <openbsc/ipaccess.h>
#include <openbsc/vty.h>
+#include <openbsc/ipaccess.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/gsm/gsm48.h>
@@ -177,13 +178,69 @@ int bsc_cc_initialize(struct bsc_nat *nat)
return 0;
}
-static int cc_new_connection(struct nat_sccp_connection *con, struct msgb *msg)
+static int cc_new_connection(struct nat_sccp_connection *con, struct msgb *input)
{
+ struct ipac_msgt_sccp_state *state;
+ struct msgb *msg, *copy;
+ struct osmo_wqueue *queue;
+ uint16_t lac, ci;
+
+ msg = msgb_alloc_headroom(4096, 128, "forward ussd");
+ if (!msg) {
+ LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n");
+ return -1;
+ }
+
+ copy = msgb_alloc_headroom(4096, 128, "forward bts");
+ if (!copy) {
+ LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n");
+ msgb_free(msg);
+ return -1;
+ }
+
+ copy->l2h = msgb_put(copy, msgb_l2len(input));
+ memcpy(copy->l2h, input->l2h, msgb_l2len(input));
+
+ msg->l2h = msgb_put(msg, 1);
+ msg->l2h[0] = IPAC_MSGT_SCCP_OLD;
+
+ /* fill out the data */
+ state = (struct ipac_msgt_sccp_state *) msgb_put(msg, sizeof(*state));
+ state->trans_id = con->cc_ti;
+ state->invoke_id = 0;
+ memcpy(&state->src_ref, &con->remote_ref, sizeof(con->remote_ref));
+ memcpy(&state->dst_ref, &con->real_ref, sizeof(con->real_ref));
+ memcpy(state->imsi, con->imsi, strlen(con->imsi));
+
+ /* add additional tag/values */
+ lac = htons(con->lac);
+ ci = htons(con->ci);
+ msgb_tv_fixed_put(msg, USSD_LAC_IE, sizeof(lac), (const uint8_t *) &lac);
+ msgb_tv_fixed_put(msg, USSD_CI_IE, sizeof(ci), (const uint8_t *) &ci);
+
+ queue = &con->bsc->nat->local_conn->write_queue;
+ bsc_do_write(queue, msg, IPAC_PROTO_IPACCESS);
+ bsc_do_write(queue, copy, IPAC_PROTO_SCCP);
+
return 0;
}
-static int cc_forward(struct nat_sccp_connection *con, struct msgb *msg)
+static int cc_forward(struct nat_sccp_connection *con, struct msgb *input)
{
+ struct msgb *copy;
+
+ copy = msgb_alloc_headroom(4096, 128, "forward to local MSC");
+ if (!copy) {
+ LOGP(DNAT, LOGL_ERROR, "Allocation failed, not forwarding.\n");
+ return -1;
+ }
+
+ /* copy the data into the copy */
+ copy->l2h = msgb_put(copy, msgb_l2len(input));
+ memcpy(copy->l2h, input->l2h, msgb_l2len(input));
+
+ /* send it out */
+ bsc_do_write(&con->bsc->nat->local_conn->write_queue, copy, IPAC_PROTO_SCCP);
return 0;
}
diff --git a/openbsc/src/osmo-bsc_nat/bsc_ussd.c b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
index 8da818119..d9903663e 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_ussd.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
@@ -38,9 +38,6 @@
#include <string.h>
#include <unistd.h>
-#define USSD_LAC_IE 0
-#define USSD_CI_IE 1
-
static void ussd_auth_con(struct tlv_parsed *, struct bsc_nat_ussd_con *);
static struct bsc_nat_ussd_con *bsc_nat_ussd_alloc(struct bsc_nat *nat)