#include "E2SM-KPM-EventTriggerDefinition-Format1.h"
#include "E2SM-KPM-EventTriggerDefinition.h"
+/*******************************************************************
+ *
+ * @brief Printing Type and Cause of failure
+ *
+ * @details
+ *
+ * Function : printE2ErrorCause
+ *
+ * Functionality: Printing Type and Cause of failure
+ *
+ * @params[in] E2 Cause
+ * @return void
+ *
+ ******************************************************************/
+
+void printE2ErrorCause(CauseE2_t *cause)
+{
+ switch(cause->present)
+ {
+ case CauseE2_PR_ricRequest:
+ {
+ DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Request", cause->choice.ricRequest);
+ break;
+ }
+ case CauseE2_PR_ricService:
+ {
+ DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Service", cause->choice.ricService);
+ break;
+ }
+ case CauseE2_PR_e2Node:
+ {
+ DU_LOG("Failure_Type [%s] Cause [%ld]", "E2_Node", cause->choice.e2Node);
+ break;
+ }
+ case CauseE2_PR_transport:
+ {
+ DU_LOG("Failure_Type [%s] Cause [%ld]", "Transport", cause->choice.transport);
+ break;
+ }
+ case CauseE2_PR_protocol:
+ {
+ DU_LOG("Failure_Type [%s] Cause [%ld]", "Protocol", cause->choice.protocol);
+ break;
+ }
+ case CauseE2_PR_misc:
+ {
+ DU_LOG("Failure_Type [%s] Cause [%ld]", "Miscellaneous", cause->choice.misc);
+ break;
+ }
+ default:
+ {
+ DU_LOG("Failure_Type and Cause unknown");
+ break;
+ }
+ }
+}
+
/*******************************************************************
*
* @brief fill E2 failure cause
return ROK;
} /* SendE2APMsg */
+/*******************************************************************
+ *
+ * @brief Deallocate the memory allocated for RemovalRequest msg
+ *
+ * @details
+ *
+ * Function : FreeRemovalRequest
+ *
+ * Functionality:
+ * - freeing the memory allocated for RemovalRequest
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void FreeRemovalRequest(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t ieIdx =0;
+ E2RemovalRequest_t *removalReq = NULLP;
+
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.initiatingMessage != NULLP)
+ {
+ removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
+ if(removalReq->protocolIEs.list.array)
+ {
+ for(ieIdx = 0; ieIdx < removalReq->protocolIEs.list.count; ieIdx++)
+ {
+ RIC_FREE(removalReq->protocolIEs.list.array[ieIdx], sizeof(E2RemovalRequestIEs_t));
+ }
+ RIC_FREE(removalReq->protocolIEs.list.array, removalReq->protocolIEs.list.size);
+ }
+ RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Build and send the removal request msg
+ *
+ * @details
+ *
+ * Function : BuildAndSendRemovalRequest
+ *
+ * Functionality:
+ * - Buld and send the removal request msg to E2 node
+ *
+ * @params[in]
+ * DU database
+ * Type of failure
+ * Cause of failure
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t BuildAndSendRemovalRequest(DuDb *duDb)
+{
+ uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
+ uint8_t ret = RFAILED;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ E2RemovalRequest_t *removalReq = NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ DU_LOG("\nINFO --> E2AP : Building Removal Request\n");
+
+ do
+ {
+ RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+ if(e2apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
+ RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2removal;
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2RemovalRequest;
+ removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
+
+ elementCnt = 1;
+ removalReq->protocolIEs.list.count = elementCnt;
+ removalReq->protocolIEs.list.size = elementCnt * sizeof(E2RemovalRequestIEs_t *);
+
+ RIC_ALLOC(removalReq->protocolIEs.list.array, removalReq->protocolIEs.list.size);
+ if(!removalReq->protocolIEs.list.array)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
+ {
+ RIC_ALLOC(removalReq->protocolIEs.list.array[ieIdx], sizeof(E2RemovalRequestIEs_t));
+ if(!removalReq->protocolIEs.list.array[ieIdx])
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+ }
+
+ /* In case of failure */
+ if(ieIdx < elementCnt)
+ break;
+
+ ieIdx = 0;
+ removalReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ removalReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
+ removalReq->protocolIEs.list.array[ieIdx]->value.present = E2RemovalRequestIEs__value_PR_TransactionID;
+ transId = assignTransactionId(duDb);
+ removalReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
+
+ /* Prints the Msg formed */
+ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
+ encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode removal request structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for removal request\n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Sending removal request failed");
+ break;
+ }
+
+
+ ret = ROK;
+ break;
+ }while(true);
+
+ /* Free all memory */
+ FreeRemovalRequest(e2apMsg);
+ return ret;
+}
+
/*******************************************************************
*
* @brief Fetches RAN Function DB
return ret;
}
-/*******************************************************************
-*
-* @brief Handles received E2AP message and sends back response
-*
-* @details
-*
-* Function : E2APMsgHdlr
-*
-* Functionality:
-* - Decodes received E2AP control message
-* - Prepares response message, encodes and sends to SCTP
-*
-* @params[in]
-* @return ROK - success
-* RFAILED - failure
-*
-* ****************************************************************/
-void E2APMsgHdlr(uint32_t *duId, Buffer *mBuf)
+
+/******************************************************************
+ *
+ * @brief Processes the E2 removal failure msg
+ *
+ * @details
+ *
+ * Function : procE2RemovalFailure
+ *
+ * Functionality: Processes the E2 removal failure msg
+ *
+ * @params[in]
+ * E2 Removal Failure information
+ *
+ * @return void
+ *
+ * ****************************************************************/
+void ProcE2RemovalFailure(E2RemovalFailure_t *e2RemovalFailure)
{
- int i;
- char *recvBuf;
- MsgLen copyCnt;
- MsgLen recvBufLen;
- E2AP_PDU_t *e2apMsg;
- asn_dec_rval_t rval; /* Decoder return value */
- E2AP_PDU_t e2apasnmsg ;
-
- DU_LOG("\nINFO --> E2AP : Received E2AP message buffer");
- ODU_PRINT_MSG(mBuf, 0,0);
-
- /* Copy mBuf into char array to decode it */
- ODU_GET_MSG_LEN(mBuf, &recvBufLen);
- RIC_ALLOC(recvBuf, (Size)recvBufLen);
+ uint8_t ieIdx = 0, transId=0;
+ CauseE2_t *cause = NULLP;
- if(recvBuf == NULLP)
+ if(!e2RemovalFailure)
{
- DU_LOG("\nERROR --> E2AP : Memory allocation failed");
+ DU_LOG("\nERROR --> E2AP : e2RemovalFailure pointer is null");
return;
}
- if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
+
+ if(!e2RemovalFailure->protocolIEs.list.array)
{
- DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
+ DU_LOG("\nERROR --> E2AP : e2RemovalFailure array pointer is null");
return;
}
-
- DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
- for(i=0; i< recvBufLen; i++)
+
+ for(ieIdx=0; ieIdx < e2RemovalFailure->protocolIEs.list.count; ieIdx++)
{
- DU_LOG("%x",recvBuf[i]);
+ if(e2RemovalFailure->protocolIEs.list.array[ieIdx])
+ {
+ switch(e2RemovalFailure->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ {
+ transId = e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
+ DU_LOG("\nERROR --> E2AP : Received transID %d", transId);
+ break;
+ }
+ case ProtocolIE_IDE2_id_CauseE2:
+ {
+ cause = &e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2;
+ printE2ErrorCause(cause);
+ break;
+ }
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Received Invalid Ie [%d]", e2RemovalFailure->protocolIEs.list.array[ieIdx]->id);
+ break;
+ }
+ }
+ }
}
+}
- /* Decoding flat buffer into E2AP messsage */
- e2apMsg = &e2apasnmsg;
- memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
+/*******************************************************************
+ *
+ * @brief process the E2 node information from ric db
+ *
+ * @details
+ *
+ * Function : deleteE2NodeInfo
+ *
+ * Functionality: process the E2 node information from ric db
+ *
+ * @params[in]
+ * du Id
+ *
+ * @return void
+ *
+ ******************************************************************/
+void deleteE2NodeInfo(DuDb *duDb)
+{
+ uint16_t ranFuncIdx =0;
+ RanFunction *ranFuncDb=NULLP;
+
+ DU_LOG("\nINFO --> E2AP : Removing all the E2 node information");
+ for(ranFuncIdx = 0; ranFuncIdx < MAX_RAN_FUNCTION; ranFuncIdx++)
+ {
+ ranFuncDb = &duDb->ranFunction[ranFuncIdx];
+ if(ranFuncDb->id > 0)
+ {
+ deleteRicSubscriptionList(&ranFuncDb->subscriptionList);
+ }
+ }
+
+ cmInetClose(&sctpCb.e2LstnSockFd);
+}
+
+/*******************************************************************
+ *
+ * @brief process the E2 Removal Response
+ *
+ * @details
+ *
+ * Function : ProcE2RemovalResponse
+ *
+ * Functionality: Process E2 Removal Response
+ *
+ * @params[in]
+ * du Id
+ * Pointer to removal response
+ * @return void
+ *
+ ******************************************************************/
+
+void ProcE2RemovalResponse(uint32_t duId, E2RemovalResponse_t *removalRsp)
+{
+ uint8_t ieIdx = 0, duIdx =0;
+ DuDb *duDb = NULLP;
+
+ SEARCH_DU_DB(duIdx, duId, duDb);
+ if(duDb == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
+ return;
+ }
+
+ if(!removalRsp)
+ {
+ DU_LOG("\nERROR --> E2AP : removalRsp pointer is null");
+ return;
+ }
+
+ if(!removalRsp->protocolIEs.list.array)
+ {
+ DU_LOG("\nERROR --> E2AP : removalRsp array pointer is null");
+ return;
+ }
+
+ for(ieIdx=0; ieIdx < removalRsp->protocolIEs.list.count; ieIdx++)
+ {
+ if(removalRsp->protocolIEs.list.array[ieIdx])
+ {
+ switch(removalRsp->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ {
+ deleteE2NodeInfo(duDb);
+ break;
+ }
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Received Invalid Ie [%ld]", removalRsp->protocolIEs.list.array[ieIdx]->id);
+ break;
+ }
+ }
+ }
+ }
+}
+/*******************************************************************
+ *
+ * @brief Deallocate the memory allocated for E2 Removal Failure
+ *
+ * @details
+ *
+ * Function : FreeE2RemovalFailure
+ *
+ * Functionality:
+ * - freeing the memory allocated for E2RemovalFailure
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ * @return void
+ *
+ * ****************************************************************/
+void FreeE2RemovalFailure(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t ieIdx =0;
+ E2RemovalFailure_t *e2RemovalFailure=NULLP;
+
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.unsuccessfulOutcome != NULLP)
+ {
+ e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
+ if(e2RemovalFailure->protocolIEs.list.array)
+ {
+ for(ieIdx=0; ieIdx < e2RemovalFailure->protocolIEs.list.count; ieIdx++)
+ {
+ if(e2RemovalFailure->protocolIEs.list.array[ieIdx])
+ {
+ RIC_FREE(e2RemovalFailure->protocolIEs.list.array[ieIdx], sizeof(E2RemovalFailureIEs_t));
+ }
+ }
+ RIC_FREE(e2RemovalFailure->protocolIEs.list.array, e2RemovalFailure->protocolIEs.list.size);
+ }
+ RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
+ }
+ RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Buld and send the E2 Removal Failure msg
+ *
+ * @details
+ *
+ * Function : BuildAndSendE2RemovalFailure
+ *
+ * Functionality:
+ * - Buld and send the E2 Removal Failure Message
+ * @params[in]
+ * DU Id
+ * Trans Id
+ * Type of failure
+ * Cause of failure
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t BuildAndSendRemovalFailure(uint32_t duId, uint16_t transId, CauseE2_PR causePresent, uint8_t reason)
+{
+ uint8_t ieIdx = 0, elementCnt = 0;
+ uint8_t ret = RFAILED;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ E2RemovalFailure_t *e2RemovalFailure=NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ DU_LOG("\nINFO --> E2AP : Building E2 Removal Failure Message\n");
+ do
+ {
+ RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+ if(e2apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+ e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
+
+ RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
+ if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2removal;
+ e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
+ e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2RemovalFailure;
+ e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
+
+ elementCnt = 2;
+ e2RemovalFailure->protocolIEs.list.count = elementCnt;
+ e2RemovalFailure->protocolIEs.list.size = elementCnt * sizeof(E2RemovalFailureIEs_t *);
+ RIC_ALLOC(e2RemovalFailure->protocolIEs.list.array, e2RemovalFailure->protocolIEs.list.size);
+ if(!e2RemovalFailure->protocolIEs.list.array)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
+ {
+ RIC_ALLOC(e2RemovalFailure->protocolIEs.list.array[ieIdx], sizeof(E2RemovalFailureIEs_t));
+ if(!e2RemovalFailure->protocolIEs.list.array[ieIdx])
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+ }
+ if(ieIdx < elementCnt)
+ break;
+
+ ieIdx = 0;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.present = E2RemovalFailureIEs__value_PR_TransactionID;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
+
+ /* Cause */
+ ieIdx++;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
+ e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
+ fillE2FailureCause(&e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, causePresent, reason);
+
+ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode E2 removal failure structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Removal Failure \n");
+ for(int i=0; i< encBufSize; i++)
+ {
+ DU_LOG("%x",encBuf[i]);
+ }
+ }
+
+ /* Sending msg */
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to send E2 Removal Failure");
+ break;
+ }
+
+ ret = ROK;
+ break;
+ }while(true);
+
+ FreeE2RemovalFailure(e2apMsg);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Deallocate the memory allocated for E2 Removal Response
+ *
+ * @details
+ *
+ * Function : FreeE2RemovalResponse
+ *
+ * Functionality:
+ * - freeing the memory allocated for E2RemovalResponse
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void FreeE2RemovalResponse(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t ieIdx =0;
+ E2RemovalResponse_t *e2RemovalResponse=NULLP;
+
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.successfulOutcome != NULLP)
+ {
+ e2RemovalResponse = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
+ if(e2RemovalResponse->protocolIEs.list.array)
+ {
+ for(ieIdx=0; ieIdx < e2RemovalResponse->protocolIEs.list.count; ieIdx++)
+ {
+ if(e2RemovalResponse->protocolIEs.list.array[ieIdx])
+ {
+ RIC_FREE(e2RemovalResponse->protocolIEs.list.array[ieIdx], sizeof(E2RemovalResponseIEs_t));
+ }
+ }
+ RIC_FREE(e2RemovalResponse->protocolIEs.list.array, e2RemovalResponse->protocolIEs.list.size);
+ }
+ RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
+ }
+ RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Buld and send the E2 Removal Response msg
+ *
+ * @details
+ *
+ * Function : BuildAndSendE2RemovalResponse
+ *
+ * Functionality:
+ * - Buld and send the E2 Removal Response Message
+ * @params[in]
+ * Du Id
+ * Trans Id
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t BuildAndSendRemovalResponse(uint32_t duId, uint16_t transId)
+{
+ uint8_t ieIdx = 0, elementCnt = 0;
+ uint8_t ret = RFAILED, duIdx =0;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ DuDb *duDb = NULLP;
+ E2RemovalResponse_t *e2RemovalResponse=NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ DU_LOG("\nINFO --> E2AP : Building E2 Removal Response Message\n");
+ do
+ {
+ SEARCH_DU_DB(duIdx, duId, duDb);
+ if(duDb == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
+ return;
+ }
+
+ RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+ if(e2apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+ e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
+
+ RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
+ if(e2apMsg->choice.successfulOutcome == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2removal;
+ e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
+ e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_E2RemovalResponse;
+ e2RemovalResponse = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
+
+ elementCnt = 1;
+ e2RemovalResponse->protocolIEs.list.count = elementCnt;
+ e2RemovalResponse->protocolIEs.list.size = elementCnt * sizeof(E2RemovalResponseIEs_t *);
+ RIC_ALLOC(e2RemovalResponse->protocolIEs.list.array, e2RemovalResponse->protocolIEs.list.size);
+ if(!e2RemovalResponse->protocolIEs.list.array)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+
+ for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
+ {
+ RIC_ALLOC(e2RemovalResponse->protocolIEs.list.array[ieIdx], sizeof(E2RemovalResponseIEs_t));
+ if(!e2RemovalResponse->protocolIEs.list.array[ieIdx])
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
+ break;
+ }
+ }
+ if(ieIdx < elementCnt)
+ break;
+
+ ieIdx = 0;
+ e2RemovalResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ e2RemovalResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
+ e2RemovalResponse->protocolIEs.list.array[ieIdx]->value.present = E2RemovalResponseIEs__value_PR_TransactionID;
+ e2RemovalResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
+
+ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode E2 removal response structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Removal Response \n");
+ for(int i=0; i< encBufSize; i++)
+ {
+ DU_LOG("%x",encBuf[i]);
+ }
+ }
+
+ /* Sending msg */
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to send E2 Removal Response");
+ break;
+ }
+
+ ret = ROK;
+ break;
+ }while(true);
+
+ FreeE2RemovalResponse(e2apMsg);
+ deleteE2NodeInfo(duDb);
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Process Removal req received from RIC
+ *
+ * @details
+ *
+ * Function : procE2RemovalRequest
+ *
+ * Functionality: Process Removal req received from RIC
+ *
+ * @param
+ * DU id
+ * E2 Removal Request
+ * @return void
+ *
+ ******************************************************************/
+
+void procE2RemovalRequest(uint32_t duId, E2RemovalRequest_t *removalReq)
+{
+ uint8_t arrIdx =0;
+ uint16_t transId =0;
+
+ DU_LOG("\nINFO --> E2AP : E2 Removal request received");
+
+ for(arrIdx=0; arrIdx<removalReq->protocolIEs.list.count; arrIdx++)
+ {
+ switch(removalReq->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_TransactionID:
+ {
+ transId = removalReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
+ break;
+ }
+ default:
+ {
+ DU_LOG("\nERROR --> E2AP : Invalid IE recevied [%d]", transId);
+ break;
+ }
+ }
+ }
+
+ if(transId>=0 && transId<=255)
+ {
+ if(BuildAndSendRemovalResponse(duId, transId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to build and send Removal response");
+ }
+ }
+ else
+ {
+ if(BuildAndSendRemovalFailure(duId, transId, CauseE2_PR_protocol, CauseE2Protocol_abstract_syntax_error_falsely_constructed_message) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to build and send Removal response");
+ }
+ }
+}
+
+/*******************************************************************
+*
+* @brief Handles received E2AP message and sends back response
+*
+* @details
+*
+* Function : E2APMsgHdlr
+*
+* Functionality:
+* - Decodes received E2AP control message
+* - Prepares response message, encodes and sends to SCTP
+*
+* @params[in]
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+void E2APMsgHdlr(uint32_t *duId, Buffer *mBuf)
+{
+ int i;
+ char *recvBuf;
+ MsgLen copyCnt;
+ MsgLen recvBufLen;
+ E2AP_PDU_t *e2apMsg;
+ asn_dec_rval_t rval; /* Decoder return value */
+ E2AP_PDU_t e2apasnmsg ;
+
+ DU_LOG("\nINFO --> E2AP : Received E2AP message buffer");
+ ODU_PRINT_MSG(mBuf, 0,0);
+
+ /* Copy mBuf into char array to decode it */
+ ODU_GET_MSG_LEN(mBuf, &recvBufLen);
+ RIC_ALLOC(recvBuf, (Size)recvBufLen);
+
+ if(recvBuf == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed");
+ return;
+ }
+ if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
+ return;
+ }
+
+ DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
+ for(i=0; i< recvBufLen; i++)
+ {
+ DU_LOG("%x",recvBuf[i]);
+ }
+
+ /* Decoding flat buffer into E2AP messsage */
+ e2apMsg = &e2apasnmsg;
+ memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
RIC_FREE(recvBuf, (Size)recvBufLen);
DU_LOG("\nINFO --> E2AP : Error indication received");
break;
}
+ case InitiatingMessageE2__value_PR_E2RemovalRequest:
+ {
+ DU_LOG("\nINFO --> E2AP : E2 Removal request received");
+ procE2RemovalRequest(*duId,\
+ &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest);
+ break;
+ }
default:
{
DU_LOG("\nERROR --> E2AP : Invalid type of intiating message [%d]", \
&e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse);
break;
}
+ case SuccessfulOutcomeE2__value_PR_E2RemovalResponse:
+ {
+ ProcE2RemovalResponse(*duId, &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse);
+ break;
+ }
default:
{
DU_LOG("\nERROR --> E2AP : Invalid type of successfulOutcome message [%d]", \
&e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure);
break;
}
+ case UnsuccessfulOutcomeE2__value_PR_E2RemovalFailure:
+ {
+ ProcE2RemovalFailure(&e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure);
+ break;
+ }
default:
{
DU_LOG("\nERROR --> E2AP : Invalid type of unsuccessfulOutcome message [%d]", \