diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2017-12-19 17:42:36 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-12-20 16:03:19 +0000 |
commit | ee03876dd171375d827cbec6d3c24d8ad9128671 (patch) | |
tree | 5c4ca51f7f0c743369a0f83cb06f5d262fee8c3b /src | |
parent | ade7e8b19bf423e9090dca67c906bc4bf8242df2 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/iu_helpers.c | 53 |
1 files changed, 52 insertions, 1 deletions
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 @@ int ranap_imsi_encode(uint8_t *out, size_t out_len, const char *in) } 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; +} |