dexter has uploaded this change for review.

View Change

ranap_common: add function to determine procedure code

In some cases it is helpful to know the procedure code of a RANAP PDU.
Lets add a function that decodes the procedure code from a RANAP PDU.

Change-Id: I531dfbdd80606462b481f1a16815ec7d81000121
Related: OS#5152
---
M include/osmocom/ranap/ranap_common.h
M src/ranap_common.c
M src/tests/test-ranap.c
3 files changed, 61 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-iuh refs/changes/00/26900/1
diff --git a/include/osmocom/ranap/ranap_common.h b/include/osmocom/ranap/ranap_common.h
index 0343a57..e9e7a2e 100644
--- a/include/osmocom/ranap/ranap_common.h
+++ b/include/osmocom/ranap/ranap_common.h
@@ -648,3 +648,6 @@
int ranap_decode_rab_setupormodifyitemfirst(
RANAP_RAB_SetupOrModifyItemFirst_t *raB_SetupOrModifyItemFirst,
ANY_t *any_p);
+
+int ranap_decode_procedure_code(const uint8_t *ranap_pdu_encoded,
+ unsigned int len);
diff --git a/src/ranap_common.c b/src/ranap_common.c
index 6c6d97c..b361eb1 100644
--- a/src/ranap_common.c
+++ b/src/ranap_common.c
@@ -607,3 +607,42 @@

return decoded;
}
+
+int ranap_decode_procedure_code(const uint8_t *ranap_pdu_encoded, unsigned int len)
+{
+ int rc;
+ asn_dec_rval_t dec_ret;
+ RANAP_RANAP_PDU_t _ranap_pdu;
+ RANAP_RANAP_PDU_t *ranap_pdu = &_ranap_pdu;
+
+ memset(ranap_pdu, 0, sizeof(*ranap_pdu));
+
+ /* Decode the RANAP PDU */
+ dec_ret = aper_decode(NULL, &asn_DEF_RANAP_RANAP_PDU, (void **)&ranap_pdu, ranap_pdu_encoded, len, 0, 0);
+ if (dec_ret.code != RC_OK) {
+ RANAP_DEBUG("Error in RANAP ASN.1 decode\n");
+ return -EINVAL;
+ }
+
+ switch (ranap_pdu->present) {
+ case RANAP_RANAP_PDU_PR_initiatingMessage:
+ rc = ranap_pdu->choice.initiatingMessage.procedureCode;
+ break;
+ case RANAP_RANAP_PDU_PR_successfulOutcome:
+ rc = ranap_pdu->choice.successfulOutcome.procedureCode;
+ break;
+ case RANAP_RANAP_PDU_PR_unsuccessfulOutcome:
+ rc = ranap_pdu->choice.unsuccessfulOutcome.procedureCode;
+ break;
+ case RANAP_RANAP_PDU_PR_outcome:
+ rc = ranap_pdu->choice.outcome.procedureCode;
+ break;
+ default:
+ rc = -1;
+ break;
+ }
+
+ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, ranap_pdu);
+
+ return rc;
+}
diff --git a/src/tests/test-ranap.c b/src/tests/test-ranap.c
index 73987f6..c3cdb35 100644
--- a/src/tests/test-ranap.c
+++ b/src/tests/test-ranap.c
@@ -173,6 +173,24 @@
}
}

+static void test_ranap_decode_procedure_code(void)
+{
+ int rc;
+ /* Encoded RAB AssignmentResponse as testvector */
+ uint8_t testvec[] = {
+ 0x60, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x01, 0x00,
+ 0x34, 0x40, 0x23, 0x00, 0x00, 0x01, 0x00, 0x33,
+ 0x40, 0x1c, 0x60, 0x3a, 0x7c, 0x35, 0x00, 0x01,
+ 0x0a, 0x09, 0x01, 0xa4, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x40, 0x04, 0x0a, 0x00, 0x00
+ };
+
+ rc = ranap_decode_procedure_code(testvec, sizeof(testvec));
+
+ OSMO_ASSERT(rc == RANAP_ProcedureCode_id_RAB_Assignment);
+}
+
int main(int argc, char **argv)
{
asn1_xer_print = 1;
@@ -195,6 +213,7 @@
test_aper_int(16000000);
test_aper_causemisc(RANAP_CauseMisc_unspecified_failure, 0x42);
test_ranap_messages();
+ test_ranap_decode_procedure_code();

printf("report\n");
talloc_report(talloc_asn1_ctx, stdout);

To view, visit change 26900. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Change-Id: I531dfbdd80606462b481f1a16815ec7d81000121
Gerrit-Change-Number: 26900
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier@sysmocom.de>
Gerrit-MessageType: newchange