aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranap_common.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-12-16 20:27:14 +0100
committerHarald Welte <laforge@gnumonks.org>2015-12-16 20:27:14 +0100
commit8dacb07bafad4e2b2966453f9eb97696c0747124 (patch)
tree8bd999d78e83bad94ccb8eb778d6ff39d259ff4b /src/ranap_common.c
parentcbaaeefe008a2ace0eb3d6287c12f33d521cbf23 (diff)
{hnbap,rua,ranap}_common.c: Reduce code duplicatioon
There used to be a lot of code duplication between the code to generate initiating, successfulOutcome and unsuccessfulOutcome messages. Try to reduce that by callign a generic function.
Diffstat (limited to 'src/ranap_common.c')
-rw-r--r--src/ranap_common.c68
1 files changed, 25 insertions, 43 deletions
diff --git a/src/ranap_common.c b/src/ranap_common.c
index e3472ea..0e2ef6a 100644
--- a/src/ranap_common.c
+++ b/src/ranap_common.c
@@ -35,13 +35,32 @@ static struct msgb *ranap_msgb_alloc(void)
return msgb_alloc(1024, "RANAP Tx");
}
+static struct msgb *_ranap_gen_msg(RANAP_RANAP_PDU_t *pdu)
+{
+ struct msgb *msg = ranap_msgb_alloc();
+ asn_enc_rval_t rval;
+
+ if (!msg)
+ return NULL;
+
+ rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, pdu,
+ msg->data, msgb_tailroom(msg));
+ if (rval.encoded < 0) {
+ LOGP(DMAIN, LOGL_ERROR, "Error encoding type: %s\n",
+ rval.failed_type->name);
+
+ }
+
+ msgb_put(msg, rval.encoded/8);
+
+ return msg;
+}
+
struct msgb *ranap_generate_initiating_message(e_RANAP_ProcedureCode procedureCode,
RANAP_Criticality_t criticality,
asn_TYPE_descriptor_t *td, void *sptr)
{
RANAP_RANAP_PDU_t pdu;
- struct msgb *msg = ranap_msgb_alloc();
- asn_enc_rval_t rval;
int rc;
memset(&pdu, 0, sizeof(pdu));
@@ -52,21 +71,10 @@ struct msgb *ranap_generate_initiating_message(e_RANAP_ProcedureCode procedureCo
rc = ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr);
if (rc < 0) {
LOGP(DMAIN, LOGL_ERROR, "Error in ANY_fromType_aper\n");
- msgb_free(msg);
return NULL;
}
- rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, &pdu,
- msg->data, msgb_tailroom(msg));
- if (rval.encoded < 0) {
- LOGP(DMAIN, LOGL_ERROR, "Error encoding type: %s\n",
- rval.failed_type->name);
-
- }
-
- msgb_put(msg, rval.encoded/8);
-
- return msg;
+ return _ranap_gen_msg(&pdu);
}
struct msgb *ranap_generate_successful_outcome(
@@ -75,34 +83,21 @@ struct msgb *ranap_generate_successful_outcome(
asn_TYPE_descriptor_t * td,
void *sptr)
{
-
RANAP_RANAP_PDU_t pdu;
- struct msgb *msg = ranap_msgb_alloc();
- asn_enc_rval_t rval;
int rc;
memset(&pdu, 0, sizeof(pdu));
+
pdu.present = RANAP_RANAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome.procedureCode = procedureCode;
pdu.choice.successfulOutcome.criticality = criticality;
rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
if (rc < 0) {
LOGP(DMAIN, LOGL_ERROR, "Error in ANY_fromType_aper\n");
- msgb_free(msg);
- return NULL;
- }
-
- rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, &pdu,
- msg->data, msgb_tailroom(msg));
- if (rval.encoded < 0) {
- LOGP(DMAIN, LOGL_ERROR, "Error encoding type %s\n", rval.failed_type->name);
- msgb_free(msg);
return NULL;
}
- msgb_put(msg, rval.encoded/8);
-
- return msg;
+ return _ranap_gen_msg(&pdu);
}
struct msgb *ranap_generate_unsuccessful_outcome(
@@ -112,8 +107,6 @@ struct msgb *ranap_generate_unsuccessful_outcome(
void *sptr)
{
RANAP_RANAP_PDU_t pdu;
- struct msgb *msg = ranap_msgb_alloc();
- asn_enc_rval_t rval;
int rc;
memset(&pdu, 0, sizeof(pdu));
@@ -124,21 +117,10 @@ struct msgb *ranap_generate_unsuccessful_outcome(
rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
if (rc < 0) {
LOGP(DMAIN, LOGL_ERROR, "Error in ANY_fromType_aper\n");
- msgb_free(msg);
- return NULL;
- }
-
- rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, &pdu,
- msg->data, msgb_tailroom(msg));
- if (rval.encoded < 0) {
- LOGP(DMAIN, LOGL_ERROR, "Error encoding type %s\n", rval.failed_type->name);
- msgb_free(msg);
return NULL;
}
- msgb_put(msg, rval.encoded/8);
-
- return msg;
+ return _ranap_gen_msg(&pdu);
}
RANAP_IE_t *ranap_new_ie(RANAP_ProtocolIE_ID_t id,