laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-iuh/+/27002 )
Change subject: ranap_common_cn: add functions for direct access to decoder
......................................................................
ranap_common_cn: add functions for direct access to decoder
The message encoder functions that decode a message to a struct
ranap_message are only accessible via a callback function that is passed
to ranap_cn_rx_cx The decoded ranap_message only lives inside the callback
since it is freed by ranap_cn_rx_cx when the callback is done. In some
situations this might make using the decoder incredibly difficult since
it is not possible to keep the decoding results for an extended amount
of time. Lets put the decoding into a separate function and use this
function in ranap_cn_rx_cx. Then lets make the decoder and the free
function public so that the decoder can be used in a more open way.
Change-Id: I14d2ed8e597a5d12024a6a6c72ff011dbeb2549d
Related: OS#5152
---
M include/osmocom/ranap/ranap_common_cn.h
M src/ranap_common_cn.c
2 files changed, 58 insertions(+), 26 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
laforge: Looks good to me, approved
diff --git a/include/osmocom/ranap/ranap_common_cn.h
b/include/osmocom/ranap/ranap_common_cn.h
index dfce358..90ff6da 100644
--- a/include/osmocom/ranap/ranap_common_cn.h
+++ b/include/osmocom/ranap/ranap_common_cn.h
@@ -7,8 +7,20 @@
typedef void (*ranap_handle_cb)(void *ctx, ranap_message *ranap_msg);
+/* free a decoded connection-less RANAP message */
+void ranap_cn_rx_cl_free(ranap_message *message);
+
+/* decode a connection-less RANAP message */
+int ranap_cn_rx_cl_decode(void *ctx, ranap_message *message, uint8_t *data, size_t len);
+
/* receive a connection-less RANAP message */
int ranap_cn_rx_cl(ranap_handle_cb cb, void *ctx, uint8_t *data, size_t len);
+/* free a decoded connection-oriented RANAP message */
+void ranap_cn_rx_co_free(ranap_message *message);
+
+/* decode a connection-oriented RANAP message */
+int ranap_cn_rx_co_decode(void *ctx, ranap_message *message, uint8_t *data, size_t len);
+
/* receive a connection-oriented RANAP message */
int ranap_cn_rx_co(ranap_handle_cb cb, void *ctx, uint8_t *data, size_t len);
diff --git a/src/ranap_common_cn.c b/src/ranap_common_cn.c
index 03ce9ea..e7b8339 100644
--- a/src/ranap_common_cn.c
+++ b/src/ranap_common_cn.c
@@ -257,7 +257,8 @@
return rc;
}
-static void _cn_ranap_free_co(ranap_message *message)
+/* free a decoded connection-oriented RANAP message */
+void ranap_cn_rx_co_free(ranap_message *message)
{
switch (message->direction) {
case RANAP_RANAP_PDU_PR_initiatingMessage:
@@ -281,27 +282,38 @@
}
}
-/* receive a connection-oriented RANAP message and call
- * cn_ranap_handle_co() with the resulting ranap_message struct */
-int ranap_cn_rx_co(ranap_handle_cb cb, void *ctx, uint8_t *data, size_t len)
+/* decode a connection-oriented RANAP message */
+int ranap_cn_rx_co_decode(void *ctx, ranap_message *message, uint8_t *data, size_t len)
{
RANAP_RANAP_PDU_t *pdu = NULL;
- ranap_message message;
asn_dec_rval_t dec_ret;
int rc;
- memset(&message, 0, sizeof(message));
+ memset(message, 0, sizeof(*message));
- dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu,
- data, len, 0, 0);
+ dec_ret = aper_decode(NULL, &asn_DEF_RANAP_RANAP_PDU, (void **)&pdu, data, len,
0, 0);
if (dec_ret.code != RC_OK) {
LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n");
return -1;
}
- message.direction = pdu->present;
+ message->direction = pdu->present;
- rc = _cn_ranap_rx_co(ctx, pdu, &message);
+ rc = _cn_ranap_rx_co(ctx, pdu, message);
+
+ ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
+
+ return rc;
+}
+
+/* receive a connection-oriented RANAP message and call
+ * cn_ranap_handle_co() with the resulting ranap_message struct */
+int ranap_cn_rx_co(ranap_handle_cb cb, void *ctx, uint8_t *data, size_t len)
+{
+ ranap_message message;
+ int rc;
+
+ rc = ranap_cn_rx_co_decode(ctx, &message, data, len);
if (rc == 0)
(*cb)(ctx, &message);
@@ -309,9 +321,7 @@
LOGP(DRANAP, LOGL_ERROR, "Not calling cn_ranap_handle_co() due to rc=%d\n",
rc);
/* Free the asn1 structs in message */
- _cn_ranap_free_co(&message);
-
- ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
+ ranap_cn_rx_co_free(&message);
return rc;
}
@@ -496,7 +506,8 @@
return rc;
}
-static void _cn_ranap_free_cl(ranap_message *message)
+/* free a decoded connection-less RANAP message */
+void ranap_cn_rx_cl_free(ranap_message *message)
{
switch (message->direction) {
case RANAP_RANAP_PDU_PR_initiatingMessage:
@@ -516,27 +527,38 @@
}
}
-/* receive a connection-less RANAP message and call
- * cn_ranap_handle_co() with the resulting ranap_message struct */
-int ranap_cn_rx_cl(ranap_handle_cb cb, void *ctx, uint8_t *data, size_t len)
+/* decode a connection-less RANAP message */
+int ranap_cn_rx_cl_decode(void *ctx, ranap_message *message, uint8_t *data, size_t len)
{
RANAP_RANAP_PDU_t *pdu = NULL;
- ranap_message message;
asn_dec_rval_t dec_ret;
int rc;
- memset(&message, 0, sizeof(message));
+ memset(message, 0, sizeof(*message));
- dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu,
- data, len, 0, 0);
+ dec_ret = aper_decode(NULL, &asn_DEF_RANAP_RANAP_PDU, (void **)&pdu, data, len,
0, 0);
if (dec_ret.code != RC_OK) {
LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n");
return -1;
}
- message.direction = pdu->present;
+ message->direction = pdu->present;
- rc = _cn_ranap_rx_cl(ctx, pdu, &message);
+ rc = _cn_ranap_rx_cl(ctx, pdu, message);
+
+ ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
+
+ return rc;
+}
+
+/* receive a connection-less RANAP message and call
+ * cn_ranap_handle_co() with the resulting ranap_message struct */
+int ranap_cn_rx_cl(ranap_handle_cb cb, void *ctx, uint8_t *data, size_t len)
+{
+ ranap_message message;
+ int rc;
+
+ rc = ranap_cn_rx_cl_decode(ctx, &message, data, len);
if (rc == 0)
(*cb)(ctx, &message);
@@ -544,9 +566,7 @@
LOGP(DRANAP, LOGL_ERROR, "Not calling cn_ranap_handle_cl() due to rc=%d\n",
rc);
/* Free the asn1 structs in message */
- _cn_ranap_free_cl(&message);
-
- ASN_STRUCT_FREE(asn_DEF_RANAP_RANAP_PDU, pdu);
+ ranap_cn_rx_cl_free(&message);
return rc;
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-iuh/+/27002
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Change-Id: I14d2ed8e597a5d12024a6a6c72ff011dbeb2549d
Gerrit-Change-Number: 27002
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged