aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-01-28 19:13:19 +0100
committerHarald Welte <laforge@osmocom.org>2021-01-28 19:14:32 +0100
commite0876bda2689015109e57abe38ade9c6ebb5a211 (patch)
treeec82fe46fba7a901a62f91af26bc03d0ff8acc5f
parent21afdf9a32be2b61a31f1ec0ecbd9bc76135cb17 (diff)
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
-rw-r--r--src/gbproxy/Makefile.am4
-rw-r--r--src/gbproxy/gb_proxy.c41
2 files changed, 41 insertions, 4 deletions
diff --git a/src/gbproxy/Makefile.am b/src/gbproxy/Makefile.am
index f8a877328..1500e1173 100644
--- a/src/gbproxy/Makefile.am
+++ b/src/gbproxy/Makefile.am
@@ -30,10 +30,6 @@ osmo_gbproxy_SOURCES = \
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 1d29b6436..c882eb068 100644
--- a/src/gbproxy/gb_proxy.c
+++ b/src/gbproxy/gb_proxy.c
@@ -136,6 +136,47 @@ static int gbprox_relay2sgsn(struct gbproxy_config *cfg, struct msgb *old_msg,
}
#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)