From e8a4dc6b7048fbec5132b6f1323e4e354f3fa9ec Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 3 Jan 2016 17:16:07 +0100 Subject: move asn1helpers.[ch] to libasn1c Those helper functions are not specific to osmo-iuh, so I moved them to libasn1c, which also resolves the problem that libosmo-ranap is depending on those helpers (and subsequently external programs linking libosmo-ranap will need to have access to the helpers) --- src/Makefile.am | 2 +- src/asn1helpers.c | 151 -------------------------------------------------- src/asn1helpers.h | 26 --------- src/tests/Makefile.am | 11 ++-- 4 files changed, 6 insertions(+), 184 deletions(-) delete mode 100644 src/asn1helpers.c delete mode 100644 src/asn1helpers.h diff --git a/src/Makefile.am b/src/Makefile.am index 6dbd73e..9e0f59d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,7 +41,7 @@ noinst_HEADERS = hnbap_common.h hnbap_ies_defs.h \ osmo_hnbgw_SOURCES = hnbap_encoder.c hnbap_decoder.c hnbap_common.c \ rua_encoder.c rua_decoder.c rua_common.c \ - asn1helpers.c sccp_helpers.c \ + sccp_helpers.c \ hnbgw.c hnbgw_hnbap.c hnbgw_rua.c hnbgw_ranap.c \ context_map.c hnbgw_cn.c diff --git a/src/asn1helpers.c b/src/asn1helpers.c deleted file mode 100644 index 25f4af4..0000000 --- a/src/asn1helpers.c +++ /dev/null @@ -1,151 +0,0 @@ -/* helper functions to dela with asn1c data types */ - -/* (C) 2014-2015 by Harald Welte - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include -#include - -#include - -#include "asn1helpers.h" -#include "asn_internal.h" - -void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in) -{ - *buf = htonl(in); - bitstr->buf = (uint8_t *) buf; - bitstr->size = sizeof(uint32_t); - bitstr->bits_unused = 0; -} - -void asn1_u28_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in) -{ - *buf = htonl(in<<4); - bitstr->buf = (uint8_t *) buf; - bitstr->size = sizeof(uint32_t); - bitstr->bits_unused = 4; -} - -void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in) -{ - *buf = htonl(in<<8); - bitstr->buf = (uint8_t *) buf; - bitstr->size = 24/8; - bitstr->bits_unused = 0; -} - -int BIT_STRING_fromBuf(BIT_STRING_t *st, const uint8_t *str, unsigned int bit_len) -{ - void *buf; - unsigned int len = bit_len / 8; - - if (bit_len % 8) - len++; - - if (!st || (!str && len)) { - errno = EINVAL; - return -1; - } - - if (!str) { - FREEMEM(st->buf); - st->buf = 0; - st->size = 0; - st->bits_unused = 0; - return 0; - } - - if (len < 0) - len = strlen(str); - - buf = MALLOC(len); - if (!buf) { - errno = ENOMEM; - return -1; - } - - memcpy(buf, str, len); - FREEMEM(st->buf); - st->buf = buf; - st->size = len; - st->bits_unused = (len * 8) - bit_len; - - return 0; -} - -void asn1_u16_to_str(OCTET_STRING_t *str, uint16_t *buf, uint16_t in) -{ - *buf = htons(in); - str->buf = (uint8_t *) buf; - str->size = sizeof(uint16_t); -} - -void asn1_u8_to_str(OCTET_STRING_t *str, uint8_t *buf, uint8_t in) -{ - *buf = in; - str->buf = buf; - str->size = sizeof(uint8_t); -} - -int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n) -{ - size_t cpylen = n-1; - - if (in->size < cpylen) - cpylen = in->size; - - strncpy(out, (char *)in->buf, cpylen); - out[cpylen] = '\0'; - - return cpylen; -} - -uint16_t asn1str_to_u16(const OCTET_STRING_t *in) -{ - OSMO_ASSERT(in && in->size == sizeof(uint16_t)); - return ntohs(*(uint16_t *)in->buf); -} - -uint8_t asn1str_to_u8(const OCTET_STRING_t *in) -{ - OSMO_ASSERT(in && in->size == sizeof(uint8_t)); - return *(uint8_t *)in->buf; -} - -uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in) -{ - OSMO_ASSERT(in && in->size == sizeof(uint32_t)); - - return ntohl(*(uint32_t *)in->buf); -} - -uint32_t asn1bitstr_to_u28(const BIT_STRING_t *in) -{ - OSMO_ASSERT(in && in->size == sizeof(uint32_t) && in->bits_unused == 4); - - return ntohl(*(uint32_t *)in->buf) >> 4; -} - -uint32_t asn1bitstr_to_u24(const BIT_STRING_t *in) -{ - OSMO_ASSERT(in && in->size == 3); - - return ntohl(*(uint32_t *)in->buf) >> 8; -} diff --git a/src/asn1helpers.h b/src/asn1helpers.h deleted file mode 100644 index 007f207..0000000 --- a/src/asn1helpers.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include - -#include "asn_system.h" -#include "BIT_STRING.h" -#include "OCTET_STRING.h" - -void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in); -void asn1_u28_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in); -void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in); -int BIT_STRING_fromBuf(BIT_STRING_t *st, const uint8_t *str, unsigned int bit_len); -void asn1_u16_to_str(OCTET_STRING_t *str, uint16_t *buf, uint16_t in); -void asn1_u8_to_str(OCTET_STRING_t *str, uint8_t *buf, uint8_t in); -int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n); -uint16_t asn1str_to_u16(const OCTET_STRING_t *in); -uint8_t asn1str_to_u8(const OCTET_STRING_t *in); -uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in); -uint32_t asn1bitstr_to_u28(const BIT_STRING_t *in); -uint32_t asn1bitstr_to_u24(const BIT_STRING_t *in); - -static inline void OCTET_STRING_noalloc(OCTET_STRING_t *s, const uint8_t *str, int size) -{ - s->buf = str; - s->size = size; -} diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 43b63cc..bcab7d4 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -6,21 +6,20 @@ check_PROGRAMS = test-ranap test-helpers test-hnbap hnb-test dummy-cn HNBAP_FILES = $(top_builddir)/src/hnbap_common.c $(top_builddir)/src/hnbap_decoder.c $(top_builddir)/src/hnbap_encoder.c RUA_FILES = $(top_builddir)/src/rua_common.c $(top_builddir)/src/rua_decoder.c $(top_builddir)/src/rua_encoder.c -HELPER_FILES = $(top_builddir)/src/asn1helpers.c -test_helpers_SOURCES = $(HELPER_FILES) test-helpers.c +test_helpers_SOURCES = test-helpers.c test_helpers_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-ranap.la -test_hnbap_SOURCES = $(HELPER_FILES) $(top_builddir)/src/hnbap_common.c $(top_builddir)/src/hnbap_decoder.c test-hnbap.c test_common.c +test_hnbap_SOURCES = $(top_builddir)/src/hnbap_common.c $(top_builddir)/src/hnbap_decoder.c test-hnbap.c test_common.c test_hnbap_LDADD = $(COMMON_LIBS) $(top_builddir)/src/hnbap/libosmo-asn1-hnbap.a $(top_builddir)/src/libosmo-ranap.la -hnb_test_SOURCES = $(HELPER_FILES) $(HNBAP_FILES) $(RUA_FILES) hnb-test.c rua_helper.c test_common.c +hnb_test_SOURCES = $(HNBAP_FILES) $(RUA_FILES) hnb-test.c rua_helper.c test_common.c hnb_test_LDADD = $(COMMON_LIBS) $(top_builddir)/src/hnbap/libosmo-asn1-hnbap.a $(top_builddir)/src/rua/libosmo-asn1-rua.a $(top_builddir)/src/libosmo-ranap.la -test_ranap_SOURCES = $(HELPER_FILES) $(RANAP_FILES) test-ranap.c test_common.c +test_ranap_SOURCES = $(RANAP_FILES) test-ranap.c test_common.c test_ranap_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-ranap.la -dummy_cn_SOURCES = $(HELPER_FILES) $(RANAP_FILES) test_common.c dummy_cn_sua.c ranap_common_cn.c +dummy_cn_SOURCES = $(RANAP_FILES) test_common.c dummy_cn_sua.c ranap_common_cn.c dummy_cn_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-ranap.la # The `:;' works around a Bash 3.2 bug when the output is not writeable. -- cgit v1.2.3