[PATCH] osmo-iuh[master]: iu: iu_helpers: add functions to decode ip/port from rab-ass

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/.

dexter gerrit-no-reply at lists.osmocom.org
Wed Dec 20 13:29:19 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5498

to look at the new patch set (#2).

iu: iu_helpers: add functions to decode ip/port from rab-ass

add ranap_transp_assoc_decode() to decode the port information from
an  RANAP_IuTransportAssociation_t field.

add ranap_transp_layer_addr_decode() to decode the ip-address from
an RANAP_TransportLayerAddress_t field.

Change-Id: I3c1a0455c5f25cae41ee19229d6daf299e023062
---
M include/osmocom/ranap/iu_helpers.h
M src/iu_helpers.c
2 files changed, 58 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-iuh refs/changes/98/5498/2

diff --git a/include/osmocom/ranap/iu_helpers.h b/include/osmocom/ranap/iu_helpers.h
index 109b6da..9d801be 100644
--- a/include/osmocom/ranap/iu_helpers.h
+++ b/include/osmocom/ranap/iu_helpers.h
@@ -3,5 +3,11 @@
 #include <stdint.h>
 #include <sys/types.h>
 
+#include <osmocom/ranap/RANAP_IuTransportAssociation.h>
+#include <osmocom/ranap/RANAP_TransportLayerAddress.h>
+
 int ranap_bcd_decode(char *out, size_t out_len, const uint8_t *in, size_t in_len);
 int ranap_imsi_encode(uint8_t *out, size_t out_len, const char *in);
+int ranap_transp_assoc_decode(uint16_t *port, const RANAP_IuTransportAssociation_t *transp_assoc);
+int ranap_transp_layer_addr_decode(char *addr, unsigned int addr_len,
+				   const RANAP_TransportLayerAddress_t *trasp_layer_addr);
diff --git a/src/iu_helpers.c b/src/iu_helpers.c
index 2f44e93..5e78293 100644
--- a/src/iu_helpers.c
+++ b/src/iu_helpers.c
@@ -20,8 +20,12 @@
 
 #include <stdint.h>
 #include <string.h>
-
+#include <errno.h>
+#include <arpa/inet.h>
+#include "asn1helpers.h"
 #include <osmocom/core/utils.h>
+#include <osmocom/ranap/RANAP_IuTransportAssociation.h>
+#include <osmocom/ranap/RANAP_TransportLayerAddress.h>
 
 /* decode a BCD-string as used inside ASN.1 encoded Iu interface protocols */
 int ranap_bcd_decode(char *out, size_t out_len, const uint8_t *in, size_t in_len)
@@ -70,3 +74,50 @@
 	}
 	return i;
 }
+
+/* decode a network port as used inside ASN.1 encoded Iu interface protocols */
+int ranap_transp_assoc_decode(uint16_t *port, const RANAP_IuTransportAssociation_t *transp_assoc)
+{
+	uint32_t result;
+
+	if (!transp_assoc)
+		return -EINVAL;
+
+	result = asn1bitstr_to_u32((BIT_STRING_t *) & transp_assoc->choice.bindingID);
+
+	/* The lower 16 bits should be zero, otherwise the decoding may
+	 * have yielded some odd result */
+	if (result & 0xFFFF)
+		return -EINVAL;
+
+	*port = (uint16_t) ((result >> 16) & 0xFFFF);
+
+	if (*port == 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+/* decode a network address as used inside ASN.1 encoded Iu interface protocols */
+int ranap_transp_layer_addr_decode(char *addr, unsigned int addr_len,
+				   const RANAP_TransportLayerAddress_t *trasp_layer_addr)
+{
+	unsigned char *buf;
+	int len;
+	const char *rc;
+
+	buf = trasp_layer_addr->buf;
+	len = trasp_layer_addr->size;
+
+	if (buf[0] == 0x35 && len > 7)
+		rc = inet_ntop(AF_INET, buf + 3, addr, addr_len);
+	else if (len > 3)
+		rc = inet_ntop(AF_INET, buf, addr, addr_len);
+	else
+		return -EINVAL;
+
+	if (!rc)
+		return -EINVAL;
+
+	return 0;
+}

-- 
To view, visit https://gerrit.osmocom.org/5498
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I3c1a0455c5f25cae41ee19229d6daf299e023062
Gerrit-PatchSet: 2
Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list