osmith submitted this change.

View Change

Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved
Reply to BSC's RESET with RESET ACK directly

Let the BSCNAT directly reply to RESET sent from BSC with RESET ACK.
bssap_ran_handle_reset() is a bit empty right now but will be used in a
future patch to store the BSC.

Related: SYS#5560
Related: https://osmocom.org/projects/osmo-bscnat/wiki/AoIP_OsmoBSCNAT#RESET
Change-Id: I3223409e25c93b625d67634caf68efe9772e2558
---
M include/osmocom/bsc_nat/Makefile.am
A include/osmocom/bsc_nat/bssap.h
M src/osmo-bsc-nat/Makefile.am
M src/osmo-bsc-nat/bsc_nat_fsm.c
A src/osmo-bsc-nat/bssap.c
5 files changed, 130 insertions(+), 1 deletion(-)

diff --git a/include/osmocom/bsc_nat/Makefile.am b/include/osmocom/bsc_nat/Makefile.am
index 90f44a7..76aada0 100644
--- a/include/osmocom/bsc_nat/Makefile.am
+++ b/include/osmocom/bsc_nat/Makefile.am
@@ -1,6 +1,7 @@
noinst_HEADERS = \
bsc_nat.h \
bsc_nat_fsm.h \
+ bssap.h \
logging.h \
vty.h \
$(NULL)
diff --git a/include/osmocom/bsc_nat/bssap.h b/include/osmocom/bsc_nat/bssap.h
new file mode 100644
index 0000000..996cb69
--- /dev/null
+++ b/include/osmocom/bsc_nat/bssap.h
@@ -0,0 +1,25 @@
+/* (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ * Author: Oliver Smith <osmith@sysmocom.de>
+ * 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/lienses/>.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/bsc_nat/bsc_nat.h>
+
+int bssap_handle_udt(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr, struct msgb *msgb,
+ unsigned int length);
diff --git a/src/osmo-bsc-nat/Makefile.am b/src/osmo-bsc-nat/Makefile.am
index 6a759cb..445c098 100644
--- a/src/osmo-bsc-nat/Makefile.am
+++ b/src/osmo-bsc-nat/Makefile.am
@@ -27,6 +27,7 @@
osmo_bsc_nat_SOURCES = \
bsc_nat.c \
bsc_nat_fsm.c \
+ bssap.c \
logging.c \
main.c \
vty.c \
diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index 4ce60ce..0c36607 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -27,6 +27,7 @@
#include <osmocom/sigtran/sccp_helpers.h>
#include <osmocom/bsc_nat/bsc_nat.h>
#include <osmocom/bsc_nat/bsc_nat_fsm.h>
+#include <osmocom/bsc_nat/bssap.h>
#include <osmocom/bsc_nat/logging.h>

#define DEFAULT_PC_RAN "0.23.1" /* same as default for OsmoMSC */
@@ -299,6 +300,10 @@

case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION):
/* connection-less data received */
+ rc = bssap_handle_udt(sccp_inst, &prim->u.unitdata.calling_addr, oph->msg, msgb_l2len(oph->msg));
+
+ /* FIXME: don't forward this to the MSC anymore, as soon as the
+ * BSCNAT is able to do the RESET to MSC by itself. */
addr = &prim->u.unitdata.calling_addr;

if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
@@ -314,7 +319,6 @@
&peer_addr_out,
oph->msg->data,
msgb_length(oph->msg));
- rc = 0;
break;

default:
diff --git a/src/osmo-bsc-nat/bssap.c b/src/osmo-bsc-nat/bssap.c
new file mode 100644
index 0000000..c054db6
--- /dev/null
+++ b/src/osmo-bsc-nat/bssap.c
@@ -0,0 +1,98 @@
+/* (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ * Author: Oliver Smith <osmith@sysmocom.de>
+ * 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/lienses/>.
+ *
+ */
+
+#include "config.h"
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/gsm0808.h>
+#include <osmocom/sigtran/sccp_helpers.h>
+#include <osmocom/sigtran/sccp_sap.h>
+#include <osmocom/bsc_nat/bsc_nat.h>
+#include <osmocom/bsc_nat/logging.h>
+
+static int bssap_ran_handle_reset(struct osmo_sccp_addr *addr, struct msgb *msg, unsigned int length)
+{
+ struct bsc_nat_sccp_inst *sccp_inst = g_bsc_nat->ran;
+
+ LOGP(DMAIN, LOGL_NOTICE, "Rx RESET from %s\n", bsc_nat_print_addr(sccp_inst, addr));
+
+ LOGP(DMAIN, LOGL_NOTICE, "Tx RESET ACK to %s\n", bsc_nat_print_addr(sccp_inst, addr));
+ msg = gsm0808_create_reset_ack();
+ return osmo_sccp_tx_unitdata_msg(sccp_inst->scu, &sccp_inst->addr, addr, msg);
+}
+
+static int bssap_ran_rcvmsg_udt(struct osmo_sccp_addr *addr, struct msgb *msg, unsigned int length)
+{
+ int ret = 0;
+
+ switch (msg->l3h[0]) {
+ case BSS_MAP_MSG_RESET:
+ ret = bssap_ran_handle_reset(addr, msg, length);
+ break;
+ default:
+ LOGP(DMAIN, LOGL_NOTICE, "Unimplemented BSSMAP UDT %s\n", gsm0808_bssap_name(msg->l3h[0]));
+ break;
+ }
+
+ return ret;
+}
+
+static int bssap_rcvmsg_udt(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr, struct msgb *msg,
+ unsigned int length)
+{
+ if (length < 1) {
+ LOGP(DMAIN, LOGL_ERROR, "Not enough room: %u\n", length);
+ return -1;
+ }
+
+ LOGP(DMAIN, LOGL_NOTICE, "Rx UDT BSSMAP %s\n", gsm0808_bssap_name(msg->l3h[0]));
+
+ /* NOTE: bssap_cn_rcvmsg_udt() will be added in a future patch */
+ return bssap_ran_rcvmsg_udt(addr, msg, length);
+}
+
+int bssap_handle_udt(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr, struct msgb *msgb,
+ unsigned int length)
+{
+ struct bssmap_header *bs;
+ int rc = -1;
+
+ LOGP(DMAIN, LOGL_DEBUG, "Rx UDT: %s\n", osmo_hexdump(msgb->l2h, length));
+
+ if (length < sizeof(*bs)) {
+ LOGP(DMAIN, LOGL_ERROR, "The header is too short\n");
+ return -1;
+ }
+
+ bs = (struct bssmap_header *)msgb->l2h;
+ if (bs->length < length - sizeof(*bs)) {
+ LOGP(DMAIN, LOGL_ERROR, "Failed to parse BSSMAP header\n");
+ return -1;
+ }
+
+ switch (bs->type) {
+ case BSSAP_MSG_BSS_MANAGEMENT:
+ msgb->l3h = &msgb->l2h[sizeof(*bs)];
+ rc = bssap_rcvmsg_udt(sccp_inst, addr, msgb, length - sizeof(*bs));
+ break;
+ default:
+ LOGP(DMAIN, LOGL_NOTICE, "Unimplemented msg type: %s\n", gsm0808_bssap_name(bs->type));
+ }
+
+ return rc;
+}

To view, visit change 27471. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: I3223409e25c93b625d67634caf68efe9772e2558
Gerrit-Change-Number: 27471
Gerrit-PatchSet: 4
Gerrit-Owner: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged