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
This commit is contained in:
Philipp Maier 2022-01-13 12:02:19 +01:00
parent 03c24fe24f
commit 07ab2ee04d
3 changed files with 61 additions and 0 deletions

View File

@ -648,3 +648,6 @@ int ranap_decode_rab_setupormodifieditemies_fromlist(
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);

View File

@ -607,3 +607,42 @@ int ranap_decode_rab_setupormodifyitemfirst(
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;
}

View File

@ -173,6 +173,24 @@ static void test_ranap_messages(void)
}
}
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 @@ int main(int argc, char **argv)
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);