From b66c5d0e623c3283ac2221cb0f3d6d23004b438d Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 3 Jan 2016 18:04:28 +0100 Subject: move tests/rua_helper.[ch] to src directory The RUA Helper is not test-specific. --- src/Makefile.am | 2 +- src/rua_msg_factory.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++ src/rua_msg_factory.h | 9 +++ src/tests/Makefile.am | 4 +- src/tests/hnb-test.c | 2 +- src/tests/rua_helper.c | 151 ------------------------------------------------ src/tests/rua_helper.h | 9 --- 7 files changed, 167 insertions(+), 164 deletions(-) create mode 100644 src/rua_msg_factory.c create mode 100644 src/rua_msg_factory.h delete mode 100644 src/tests/rua_helper.c delete mode 100644 src/tests/rua_helper.h diff --git a/src/Makefile.am b/src/Makefile.am index 0a54e01..c6bb440 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,7 +42,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 \ - sccp_helpers.c \ + rua_msg_factory.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/rua_msg_factory.c b/src/rua_msg_factory.c new file mode 100644 index 0000000..b664509 --- /dev/null +++ b/src/rua_msg_factory.c @@ -0,0 +1,154 @@ +#include +#include + +#include "rua_common.h" +#include "rua_ies_defs.h" +#include "rua_msg_factory.h" +#include "asn1helpers.h" +#include "hnbgw.h" + + +struct msgb *rua_new_udt(struct msgb *inmsg) +{ + RUA_ConnectionlessTransfer_t out; + RUA_ConnectionlessTransferIEs_t ies; + struct msgb *msg; + int rc; + + memset(&ies, 0, sizeof(ies)); + OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); + msgb_free(inmsg); + + memset(&out, 0, sizeof(out)); + rc = rua_encode_connectionlesstransferies(&out, &ies); + if (rc < 0) + return NULL; + + msg = rua_generate_initiating_message(RUA_ProcedureCode_id_ConnectionlessTransfer, + RUA_Criticality_reject, + &asn_DEF_RUA_ConnectionlessTransfer, + &out); + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out); + + DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + + msgb_sctp_ppid(msg) = IUH_PPI_RUA; + + return msg; +} + +struct msgb *rua_new_conn(int is_ps, uint32_t context_id, struct msgb *inmsg) +{ + RUA_Connect_t out; + RUA_ConnectIEs_t ies; + struct msgb *msg; + uint32_t ctxidbuf; + int rc; + + memset(&ies, 0, sizeof(ies)); + if (is_ps) + ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; + else + ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; + asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); + ies.establishment_Cause = RUA_Establishment_Cause_normal_call; + OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); + msgb_free(inmsg); + + memset(&out, 0, sizeof(out)); + rc = rua_encode_connecties(&out, &ies); + if (rc < 0) + return NULL; + + msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Connect, + RUA_Criticality_reject, + &asn_DEF_RUA_Connect, + &out); + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Connect, &out); + + DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + + msgb_sctp_ppid(msg) = IUH_PPI_RUA; + + return msg; +} + +struct msgb *rua_new_dt(int is_ps, uint32_t context_id, struct msgb *inmsg) +{ + RUA_DirectTransfer_t out; + RUA_DirectTransferIEs_t ies; + struct msgb *msg; + uint32_t ctxidbuf; + int rc; + + memset(&ies, 0, sizeof(ies)); + if (is_ps) + ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; + else + ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; + asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); + OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); + msgb_free(inmsg); + + memset(&out, 0, sizeof(out)); + rc = rua_encode_directtransferies(&out, &ies); + if (rc < 0) + return NULL; + + msg = rua_generate_initiating_message(RUA_ProcedureCode_id_DirectTransfer, + RUA_Criticality_reject, + &asn_DEF_RUA_DirectTransfer, + &out); + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out); + + DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + + msgb_sctp_ppid(msg) = IUH_PPI_RUA; + + return msg; +} + +struct msgb *rua_new_disc(int is_ps, uint32_t context_id, struct msgb *inmsg) +{ + RUA_Disconnect_t out; + RUA_DisconnectIEs_t ies; + struct msgb *msg; + uint32_t ctxidbuf; + int rc; + + memset(&ies, 0, sizeof(ies)); + if (is_ps) + ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; + else + ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; + asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); + /* FIXME: make cause configurable */ + ies.cause.present = RUA_Cause_PR_radioNetwork; + ies.cause.choice.radioNetwork = RUA_CauseRadioNetwork_normal; + if (inmsg && inmsg->data&& msgb_length(inmsg)) { + ies.presenceMask |= DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT; + OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); + } + msgb_free(inmsg); + + memset(&out, 0, sizeof(out)); + rc = rua_encode_disconnecties(&out, &ies); + if (rc < 0) + return NULL; + + msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Disconnect, + RUA_Criticality_reject, + &asn_DEF_RUA_Disconnect, + &out); + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out); + + DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); + + msgb_sctp_ppid(msg) = IUH_PPI_RUA; + + return msg; +} diff --git a/src/rua_msg_factory.h b/src/rua_msg_factory.h new file mode 100644 index 0000000..ca2f4e8 --- /dev/null +++ b/src/rua_msg_factory.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +struct msgb *rua_new_udt(struct msgb *inmsg); +struct msgb *rua_new_conn(int is_ps, uint32_t context_id, struct msgb *inmsg); +struct msgb *rua_new_dt(int is_ps, uint32_t context_id, struct msgb *inmsg); +struct msgb *rua_new_disc(int is_ps, uint32_t context_id, struct msgb *inmsg); diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 122c663..6a4e4dc 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -5,7 +5,7 @@ COMMON_LIBS = $(OSMOVTY_LIBS) $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(ASN1C_LIBS) $(O check_PROGRAMS = test-ranap test-helpers test-hnbap hnb-test dummy-cn HNBAP_FILES = $(top_srcdir)/src/hnbap_common.c $(top_srcdir)/src/hnbap_decoder.c $(top_srcdir)/src/hnbap_encoder.c -RUA_FILES = $(top_srcdir)/src/rua_common.c $(top_srcdir)/src/rua_decoder.c $(top_srcdir)/src/rua_encoder.c +RUA_FILES = $(top_srcdir)/src/rua_common.c $(top_srcdir)/src/rua_decoder.c $(top_srcdir)/src/rua_encoder.c $(top_srcdir)/src/rua_msg_factory.c test_helpers_SOURCES = test-helpers.c test_helpers_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-ranap.la @@ -13,7 +13,7 @@ test_helpers_LDADD = $(COMMON_LIBS) $(top_builddir)/src/libosmo-ranap.la test_hnbap_SOURCES = $(top_srcdir)/src/hnbap_common.c $(top_srcdir)/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 = $(HNBAP_FILES) $(RUA_FILES) hnb-test.c rua_helper.c test_common.c +hnb_test_SOURCES = $(HNBAP_FILES) $(RUA_FILES) hnb-test.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 = $(RANAP_FILES) test-ranap.c test_common.c diff --git a/src/tests/hnb-test.c b/src/tests/hnb-test.c index f26e222..b4a30f8 100644 --- a/src/tests/hnb-test.c +++ b/src/tests/hnb-test.c @@ -49,7 +49,7 @@ #include "hnb-test.h" #include "hnbap_common.h" #include "hnbap_ies_defs.h" -#include "rua_helper.h" +#include "rua_msg_factory.h" #include "asn1helpers.h" #include "iu_helpers.h" #include "test_common.h" diff --git a/src/tests/rua_helper.c b/src/tests/rua_helper.c deleted file mode 100644 index d1dcbf6..0000000 --- a/src/tests/rua_helper.c +++ /dev/null @@ -1,151 +0,0 @@ -#include "rua_common.h" -#include "rua_ies_defs.h" -#include - -#include "hnbgw.h" -#include "asn1helpers.h" - -struct msgb *rua_new_udt(struct msgb *inmsg) -{ - RUA_ConnectionlessTransfer_t out; - RUA_ConnectionlessTransferIEs_t ies; - struct msgb *msg; - int rc; - - memset(&ies, 0, sizeof(ies)); - OCTET_STRING_fromBuf(&ies.ranaP_Message.buf, inmsg->data, msgb_length(inmsg)); - msgb_free(inmsg); - - memset(&out, 0, sizeof(out)); - rc = rua_encode_connectionlesstransferies(&out, &ies); - if (rc < 0) - return NULL; - - msg = rua_generate_initiating_message(RUA_ProcedureCode_id_ConnectionlessTransfer, - RUA_Criticality_reject, - &asn_DEF_RUA_ConnectionlessTransfer, - &out); - - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out); - - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); - - msgb_sctp_ppid(msg) = IUH_PPI_RUA; - - return msg; -} - -struct msgb *rua_new_conn(int is_ps, uint32_t context_id, struct msgb *inmsg) -{ - RUA_Connect_t out; - RUA_ConnectIEs_t ies; - struct msgb *msg; - uint32_t ctxidbuf; - int rc; - - memset(&ies, 0, sizeof(ies)); - if (is_ps) - ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; - else - ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; - asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); - ies.establishment_Cause = RUA_Establishment_Cause_normal_call; - OCTET_STRING_fromBuf(&ies.ranaP_Message.buf, inmsg->data, msgb_length(inmsg)); - msgb_free(inmsg); - - memset(&out, 0, sizeof(out)); - rc = rua_encode_connecties(&out, &ies); - if (rc < 0) - return NULL; - - msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Connect, - RUA_Criticality_reject, - &asn_DEF_RUA_Connect, - &out); - - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Connect, &out); - - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); - - msgb_sctp_ppid(msg) = IUH_PPI_RUA; - - return msg; -} - -struct msgb *rua_new_dt(int is_ps, uint32_t context_id, struct msgb *inmsg) -{ - RUA_DirectTransfer_t out; - RUA_DirectTransferIEs_t ies; - struct msgb *msg; - uint32_t ctxidbuf; - int rc; - - memset(&ies, 0, sizeof(ies)); - if (is_ps) - ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; - else - ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; - asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); - OCTET_STRING_fromBuf(&ies.ranaP_Message.buf, inmsg->data, msgb_length(inmsg)); - msgb_free(inmsg); - - memset(&out, 0, sizeof(out)); - rc = rua_encode_directtransferies(&out, &ies); - if (rc < 0) - return NULL; - - msg = rua_generate_initiating_message(RUA_ProcedureCode_id_DirectTransfer, - RUA_Criticality_reject, - &asn_DEF_RUA_DirectTransfer, - &out); - - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out); - - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); - - msgb_sctp_ppid(msg) = IUH_PPI_RUA; - - return msg; -} - -struct msgb *rua_new_disc(int is_ps, uint32_t context_id, struct msgb *inmsg) -{ - RUA_Disconnect_t out; - RUA_DisconnectIEs_t ies; - struct msgb *msg; - uint32_t ctxidbuf; - int rc; - - memset(&ies, 0, sizeof(ies)); - if (is_ps) - ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; - else - ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; - asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); - /* FIXME: make cause configurable */ - ies.cause.present = RUA_Cause_PR_radioNetwork; - ies.cause.choice.radioNetwork = RUA_CauseRadioNetwork_normal; - if (inmsg && inmsg->data&& msgb_length(inmsg)) { - ies.presenceMask |= DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT; - OCTET_STRING_fromBuf(&ies.ranaP_Message.buf, inmsg->data, msgb_length(inmsg)); - } - msgb_free(inmsg); - - memset(&out, 0, sizeof(out)); - rc = rua_encode_disconnecties(&out, &ies); - if (rc < 0) - return NULL; - - msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Disconnect, - RUA_Criticality_reject, - &asn_DEF_RUA_Disconnect, - &out); - - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out); - - DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); - - msgb_sctp_ppid(msg) = IUH_PPI_RUA; - - return msg; -} diff --git a/src/tests/rua_helper.h b/src/tests/rua_helper.h deleted file mode 100644 index ca2f4e8..0000000 --- a/src/tests/rua_helper.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include -#include - -struct msgb *rua_new_udt(struct msgb *inmsg); -struct msgb *rua_new_conn(int is_ps, uint32_t context_id, struct msgb *inmsg); -struct msgb *rua_new_dt(int is_ps, uint32_t context_id, struct msgb *inmsg); -struct msgb *rua_new_disc(int is_ps, uint32_t context_id, struct msgb *inmsg); -- cgit v1.2.3