aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-02-18 01:18:20 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-02-18 01:31:50 +0100
commit24105501a72629e79e6c4d697670c30aecfa3d2b (patch)
tree0238c56d464f2d3491ed769a4006111032618a75
parent8f7bf8ea65146b534f9251d3d63244f5d3347869 (diff)
hnb-test: decode NAS pdu when receiving RUA from CN
-rw-r--r--src/tests/Makefile.am2
-rw-r--r--src/tests/hnb-test-ranap.c48
-rw-r--r--src/tests/hnb-test-rua.c37
-rw-r--r--src/tests/hnb-test.c11
4 files changed, 97 insertions, 1 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index bcf4a46..1bf50d2 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -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 test_common.c
+hnb_test_SOURCES = $(HNBAP_FILES) $(RUA_FILES) hnb-test.c test_common.c hnb-test-ranap.c hnb-test-rua.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-ranap.c b/src/tests/hnb-test-ranap.c
new file mode 100644
index 0000000..eb90745
--- /dev/null
+++ b/src/tests/hnb-test-ranap.c
@@ -0,0 +1,48 @@
+#include <osmocom/core/msgb.h>
+#include <osmocom/ranap/ranap_ies_defs.h>
+
+static const char *printstr(OCTET_STRING_t *s)
+{
+ osmo_hexdump((char*)s->buf, s->size);
+}
+
+#define PP(octet_string_t) \
+ printf(#octet_string_t " = %s\n",\
+ printstr(&octet_string_t))
+
+void ranap_msg_dt_print(void *ctx, ranap_message *ranap_msg)
+{
+ OSMO_ASSERT(ranap_msg->procedureCode ==
+ RANAP_ProcedureCode_id_DirectTransfer);
+
+ printf("rx DirectTransfer: presence = %hx\n", ranap_msg->msg.directTransferIEs.presenceMask);
+ PP(ranap_msg->msg.directTransferIEs.nas_pdu);
+
+ // nas_pdu == '05 08 12' ==> IMEI Identity request
+ // '05 04 0d' ==> LU reject
+/*
+typedef struct RANAP_DirectTransferIEs_s {
+ uint16_t presenceMask;
+ RANAP_NAS_PDU_t nas_pdu;
+ RANAP_LAI_t lai; ///< Optional field
+ RANAP_RAC_t rac; ///< Optional field
+ RANAP_SAI_t sai; ///< Optional field
+ RANAP_SAPI_t sapi; ///< Optional field
+} RANAP_DirectTransferIEs_t;
+*/
+}
+
+void ranap_msg_dt_get(void *ctx, ranap_message *ranap_msg)
+{
+ struct msgb *m = ctx;
+ OSMO_ASSERT(ranap_msg->procedureCode ==
+ RANAP_ProcedureCode_id_DirectTransfer);
+
+ printf("rx DirectTransfer: presence = %hx\n", ranap_msg->msg.directTransferIEs.presenceMask);
+ PP(ranap_msg->msg.directTransferIEs.nas_pdu);
+
+ int len = ranap_msg->msg.directTransferIEs.nas_pdu.size;
+ char *data = ranap_msg->msg.directTransferIEs.nas_pdu.buf;
+
+ memcpy(msgb_put(m, len), data, len);
+}
diff --git a/src/tests/hnb-test-rua.c b/src/tests/hnb-test-rua.c
new file mode 100644
index 0000000..41df4f2
--- /dev/null
+++ b/src/tests/hnb-test-rua.c
@@ -0,0 +1,37 @@
+
+#include <asn1c/ANY.h>
+#include "../rua_ies_defs.h"
+
+struct ranap_message_s;
+
+typedef void (*ranap_handle_cb)(void *ctx, struct ranap_message_s *ranap_msg);
+
+extern void ranap_msg_dt_print(void *ctx, struct ranap_message_s *ranap_msg);
+extern void ranap_msg_dt_get(void *ctx, struct ranap_message_s *ranap_msg);
+
+static void direct_transfer_nas_pdu_handle(ANY_t *in, ranap_handle_cb handler, void *ctx)
+{
+ RUA_DirectTransferIEs_t ies;
+ int rc;
+
+ rc = rua_decode_directtransferies(&ies, in);
+ if (rc < 0) {
+ printf("print_rua_init_dt(): failed to decode rua IEs\n");
+ return;
+ }
+
+ rc = ranap_cn_rx_co(handler, ctx, ies.ranaP_Message.buf, ies.ranaP_Message.size);
+
+ /* FIXME: what to do with the asn1c-allocated memory */
+ rua_free_directtransferies(&ies);
+}
+
+void direct_transfer_nas_pdu_print(ANY_t *in)
+{
+ direct_transfer_nas_pdu_handle(in, ranap_msg_dt_print, NULL);
+}
+
+void direct_transfer_nas_pdu_get(ANY_t *in, struct msgb *m)
+{
+ direct_transfer_nas_pdu_handle(in, ranap_msg_dt_get, m);
+}
diff --git a/src/tests/hnb-test.c b/src/tests/hnb-test.c
index a58a5e8..4151fb7 100644
--- a/src/tests/hnb-test.c
+++ b/src/tests/hnb-test.c
@@ -208,6 +208,8 @@ int hnb_test_hnbap_rx(struct hnb_test *hnb, struct msgb *msg)
return rc;
}
+extern void direct_transfer_nas_pdu_print(ANY_t *in);
+
int hnb_test_rua_rx(struct hnb_test *hnb, struct msgb *msg)
{
RUA_RUA_PDU_t _pdu, *pdu = &_pdu;
@@ -249,6 +251,15 @@ int hnb_test_rua_rx(struct hnb_test *hnb, struct msgb *msg)
break;
case RUA_ProcedureCode_id_DirectTransfer:
printf("RUA rx DirectTransfer\n");
+ {
+ struct msgb *m = msgb_alloc(1500, "direct_transfer_nas_pdu");
+ direct_transfer_nas_pdu_get(&pdu->choice.successfulOutcome.value, m);
+
+ // evaluate
+
+ printf("got %s\n", osmo_hexdump(m->data, m->len));
+ msgb_free(m);
+ }
break;
case RUA_ProcedureCode_id_Disconnect:
printf("RUA rx Disconnect\n");