Reveiw fixes added
Wrapper code fix added.
Review fixes added.

Change-Id: Ic59f47402895a2bc30802946328722653e228415
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
diff --git a/e2ap/wrapper.c b/e2ap/wrapper.c
index 9e535c8..78c43f7 100644
--- a/e2ap/wrapper.c
+++ b/e2ap/wrapper.c
@@ -5,7 +5,7 @@
 {
     asn_enc_rval_t encode_result;
     encode_result = aper_encode_to_buffer(&asn_DEF_E2AP_PDU, NULL, pdu, buffer, buf_size);
-    if(encode_result.encoded == -1) {
+    if (encode_result.encoded == -1) {
         return -1;
     }
     return encode_result.encoded;
@@ -16,7 +16,7 @@
     asn_dec_rval_t decode_result;
     E2AP_PDU_t *pdu = 0;
     decode_result = aper_decode_complete(NULL, &asn_DEF_E2AP_PDU, (void **)&pdu, buffer, buf_size);
-    if(decode_result.code == RC_OK) {
+    if (decode_result.code == RC_OK) {
         return pdu;
     } else {
         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
@@ -26,275 +26,371 @@
 
 long e2ap_get_ric_subscription_request_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
+    if  (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
             && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionRequest)
         {
             RICsubscriptionRequest_t *ric_subscription_request = &(initiatingMessage->value.choice.RICsubscriptionRequest);
-            for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i)
             {
-                if ( ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_request_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
             && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionRequest)
         {
             RICsubscriptionRequest_t *ricSubscriptionRequest = &initiatingMessage->value.choice.RICsubscriptionRequest;
-            for (int i = 0; i < ricSubscriptionRequest->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ricSubscriptionRequest->protocolIEs.list.count; ++i)
             {
-                if ( ricSubscriptionRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ricSubscriptionRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     ricSubscriptionRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            return -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 /* RICsubscriptionResponse */
 long e2ap_get_ric_subscription_response_sequence_number(void *buffer, size_t buf_size)
 {
-    E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    int errorCode = -1;
+     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
             && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionResponse)
         {
             RICsubscriptionResponse_t *ricSubscriptionResponse = &successfulOutcome->value.choice.RICsubscriptionResponse;
-            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i)
             {
-                if ( ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_response_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
             && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionResponse)
         {
             RICsubscriptionResponse_t *ricSubscriptionResponse = &successfulOutcome->value.choice.RICsubscriptionResponse;
-            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i)
             {
-                if ( ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 /* RICsubscriptionDeleteRequest */
 long e2ap_get_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest )
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest)
         {
             RICsubscriptionDeleteRequest_t *subscriptionDeleteRequest = &initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
-            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest )
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest)
         {
             RICsubscriptionDeleteRequest_t* subscriptionDeleteRequest = &initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
-            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 /* RICsubscriptionDeleteResponse */
 long e2ap_get_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse )
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse)
         {
             RICsubscriptionDeleteResponse_t* subscriptionDeleteResponse = &successfulOutcome->value.choice.RICsubscriptionDeleteResponse;
-            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse )
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse)
         {
             RICsubscriptionDeleteResponse_t* subscriptionDeleteResponse = &successfulOutcome->value.choice.RICsubscriptionDeleteResponse;
-            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 // This function is not used currently. Can be deleted if not needed
 ssize_t  e2ap_set_ric_subscription_failure_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure)
         {
             RICsubscriptionFailure_t* subscriptionFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
-            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 long e2ap_get_ric_subscription_failure_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure)
         {
             RICsubscriptionFailure_t* subscriptionFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionFailure;;
-            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 // This function is not used currently. Can be deleted if not needed
 ssize_t  e2ap_set_ric_subscription_delete_failure_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure)
         {
             RICsubscriptionDeleteFailure_t* subscriptionDeleteFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionDeleteFailure;
-            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionDeleteFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 long e2ap_get_ric_subscription_delete_failure_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure)
         {
             RICsubscriptionDeleteFailure_t* subscriptionDeleteFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionDeleteFailure;;
-            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionDeleteFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionDeleteFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
diff --git a/pkg/control/client.go b/pkg/control/client.go
index d377d8e..adbe48f 100644
--- a/pkg/control/client.go
+++ b/pkg/control/client.go
@@ -61,7 +61,7 @@
 			return nil
 		}
 	default:
-		xapp.Logger.Debug("Unknown subRouteAction.Command: %v, subID: %v", subRouteAction.Command, subRouteAction.Address, subRouteAction.Port, subID)
+		xapp.Logger.Debug("Unknown subRouteAction.Command: %v, Address %s, Port %v, subID: %v", subRouteAction.Command, subRouteAction.Address, subRouteAction.Port, subID)
 		return nil
 	}
 }
diff --git a/pkg/control/control.go b/pkg/control/control.go
index af629a1..7e2d673 100644
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -172,7 +172,7 @@
 		return 
 	}
 
-	_, err = c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, newSubId)
+	err = c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, newSubId)
 	if err != nil {
 		err = errors.New("Unable to set Subscription Sequence Number in Payload due to: " + err.Error())
 		return
@@ -214,7 +214,7 @@
 }
 
 func (c *Control) handleSubscriptionResponse(params *xapp.RMRParams) (err error) {
-	xapp.Logger.Info("Subscription Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Xid, params.Meid)
+	xapp.Logger.Info("Subscription Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid)
 	xapp.Rmr.Free(params.Mbuf)
 	params.Mbuf = nil
 
@@ -297,7 +297,7 @@
 	time.Sleep(3 * time.Second)
 
 	xapp.Logger.Info("Starting routing manager update")
-	subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
+	subRouteAction := SubRouteInfo{CREATE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
 	c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
 
 	xapp.Logger.Info("Deleting trancaction record")
diff --git a/pkg/control/e2ap.go b/pkg/control/e2ap.go
index f9580d9..8f9f7c9 100644
--- a/pkg/control/e2ap.go
+++ b/pkg/control/e2ap.go
@@ -27,139 +27,144 @@
 import "C"
 
 import (
-	"errors"
 	"unsafe"
+	"fmt"
 )
 
 type E2ap struct {
 }
 
+/* RICsubscriptionRequest */
+
+// Used by e2t test stub
 func (c *E2ap) GetSubscriptionRequestSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by submgr, rco test stub
+func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Request Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
+// Used by submgr, rco test stub
 func (c *E2ap) GetSubscriptionResponseSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by e2t test stub
+func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Response Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionDeleteRequest */
 
+// Used by submgr, e2t test stub
 func (c *E2ap) GetSubscriptionDeleteRequestSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Request Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionDeleteRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by rco test stub
+func (c *E2ap) SetSubscriptionDeleteRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Request Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionDeleteResponse */
 
+// Used by submgr, rco test stub
 func (c *E2ap) GetSubscriptionDeleteResponseSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Response Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionDeleteResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by e2t test stub
+func (c *E2ap) SetSubscriptionDeleteResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Response Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionRequestFailure */
 
+// Used by submgr
 func (c *E2ap) GetSubscriptionFailureSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-// This function is not used currently. Can be deleted if not needed
-func (c *E2ap) SetSubscriptionFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by submgr
+func (c *E2ap) SetSubscriptionFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Failure Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionDeleteFailure */
 
+// Used by submgr
 func (c *E2ap) GetSubscriptionDeleteFailureSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Failure Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
-
-// This function is not used currently. Can be deleted if not needed
-func (c *E2ap) SetSubscriptionDeleteFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by submgr
+func (c *E2ap) SetSubscriptionDeleteFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Failure Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }