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
This commit is contained in:
Philipp Maier 2017-12-19 17:42:36 +01:00 committed by Harald Welte
parent ade7e8b19b
commit ee03876dd1
2 changed files with 58 additions and 1 deletions

View File

@ -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);

View File

@ -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;
}