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
Review at https://gerrit.osmocom.org/5498
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, 52 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-iuh refs/changes/98/5498/1
diff --git a/include/osmocom/ranap/iu_helpers.h b/include/osmocom/ranap/iu_helpers.h
index 109b6da..56791b8 100644
--- a/include/osmocom/ranap/iu_helpers.h
+++ b/include/osmocom/ranap/iu_helpers.h
@@ -3,5 +3,10 @@
#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, RANAP_IuTransportAssociation_t *transp_assoc);
+int ranap_transp_layer_addr_decode(char *addr, unsigned int addr_len, RANAP_TransportLayerAddress_t *trasp_layer_addr);
diff --git a/src/iu_helpers.c b/src/iu_helpers.c
index 2f44e93..f038da2 100644
--- a/src/iu_helpers.c
+++ b/src/iu_helpers.c
@@ -20,8 +20,11 @@
#include <stdint.h>
#include <string.h>
-
+#include <errno.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 +73,46 @@
}
return i;
}
+
+/* decode a network port as used inside ASN.1 encoded Iu interface protocols */
+int ranap_transp_assoc_decode(uint16_t *port, 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, RANAP_TransportLayerAddress_t * trasp_layer_addr)
+{
+ unsigned char *buf;
+ int len;
+
+ buf = trasp_layer_addr->buf;
+ len = trasp_layer_addr->size;
+
+ if (addr_len > INET_ADDRSTRLEN)
+ return -EINVAL;
+
+ if (buf[0] == 0x35 && len > 7)
+ snprintf(addr, addr_len, "%u.%u.%u.%u", buf[3], buf[4], buf[5], buf[6]);
+ else if (len > 3)
+ snprintf(addr, addr_len, "%u.%u.%u.%u", buf[0], buf[1], buf[2], buf[3]);
+
+ return 0;
+}
--
To view, visit https://gerrit.osmocom.org/5498
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c1a0455c5f25cae41ee19229d6daf299e023062
Gerrit-PatchSet: 1
Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>