Change in osmo-sgsn[master]: gbproxy: Avoid depending on any of the SGSN code

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

daniel gerrit-no-reply at lists.osmocom.org
Thu Jan 28 19:44:04 UTC 2021


daniel has submitted this change. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/22516 )

Change subject: gbproxy: Avoid depending on any of the SGSN code
......................................................................

gbproxy: Avoid depending on any of the SGSN code

The last remaining functin of the SGSN code base we used was
gprs_gb_parse_tlli().

Let's simply copy this function over and become  self-contained.

This would allow migrating osmo-gbproxy to a separate repository.

Change-Id: I6f3f86581b47ad71a3d97f07611a2e2709876d69
---
M src/gbproxy/Makefile.am
M src/gbproxy/gb_proxy.c
2 files changed, 41 insertions(+), 4 deletions(-)

Approvals:
  daniel: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/gbproxy/Makefile.am b/src/gbproxy/Makefile.am
index f8a8773..1500e11 100644
--- a/src/gbproxy/Makefile.am
+++ b/src/gbproxy/Makefile.am
@@ -30,10 +30,6 @@
 	gb_proxy_peer.c \
 	$(NULL)
 osmo_gbproxy_LDADD = \
-	$(top_builddir)/src/gprs/gprs_gb_parse.o \
-	$(top_builddir)/src/gprs/gprs_llc_parse.o \
-	$(top_builddir)/src/gprs/crc24.o \
-	$(top_builddir)/src/gprs/gprs_utils.o \
 	$(LIBOSMOCORE_LIBS) \
 	$(LIBOSMOGSM_LIBS) \
 	$(LIBOSMOVTY_LIBS) \
diff --git a/src/gbproxy/gb_proxy.c b/src/gbproxy/gb_proxy.c
index 1d29b64..c882eb0 100644
--- a/src/gbproxy/gb_proxy.c
+++ b/src/gbproxy/gb_proxy.c
@@ -136,6 +136,47 @@
 }
 #endif
 
+/*! Determine the TLLI from the given BSSGP message.
+ *  \param[in] bssgp pointer to start of BSSGP header
+ *  \param[in] bssgp_len length of BSSGP message in octets
+ *  \param[out] tlli TLLI (if any) in host byte order
+ *  \returns 1 if TLLI found; 0 if none found; negative on parse error */
+int gprs_gb_parse_tlli(const uint8_t *bssgp, size_t bssgp_len, uint32_t *tlli)
+{
+	const struct bssgp_normal_hdr *bgph;
+	uint8_t pdu_type;
+
+	if (bssgp_len < sizeof(struct bssgp_normal_hdr))
+		return -EINVAL;
+
+	bgph = (struct bssgp_normal_hdr *)bssgp;
+	pdu_type = bgph->pdu_type;
+
+	if (pdu_type == BSSGP_PDUT_UL_UNITDATA ||
+	    pdu_type == BSSGP_PDUT_DL_UNITDATA) {
+		const struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *)bssgp;
+		if (bssgp_len < sizeof(struct bssgp_ud_hdr))
+			return -EINVAL;
+		*tlli = osmo_load32be((const uint8_t *)&budh->tlli);
+		return 1;
+	} else {
+		const uint8_t *data = bgph->data;
+		size_t data_len = bssgp_len - sizeof(*bgph);
+		struct tlv_parsed tp;
+
+		if (bssgp_tlv_parse(&tp, data, data_len) < 0)
+			return -EINVAL;
+
+		if (TLVP_PRESENT(&tp, BSSGP_IE_TLLI)) {
+			*tlli = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TLLI));
+			return 1;
+		}
+	}
+
+	/* No TLLI present in message */
+	return 0;
+}
+
 /* feed a message down the NSE */
 static int gbprox_relay2nse(struct msgb *old_msg, struct gbproxy_nse *nse,
 			     uint16_t ns_bvci)

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/22516
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: I6f3f86581b47ad71a3d97f07611a2e2709876d69
Gerrit-Change-Number: 22516
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210128/576acf6b/attachment.htm>


More information about the gerrit-log mailing list