*******************************************************************************/
/* This file contains E2AP message handler functions */
-
+#include "common_def.h"
+#include "OCTET_STRING.h"
+#include "BIT_STRING.h"
+#include "odu_common_codec.h"
+#include "ric_stub.h"
#include "ric_stub_sctp.h"
#include "ric_e2ap_msg_hdl.h"
#include "GlobalE2node-gNB-ID.h"
+#include "ProtocolIE-FieldE2.h"
+#include "InitiatingMessageE2.h"
+#include "SuccessfulOutcomeE2.h"
+#include "E2AP-PDU.h"
+#include "du_log.h"
-char encBuf[ENC_BUF_MAX_LEN];
Bool ricSubsStatus;
-S16 SendE2APMsg(Region , Pool );
-
-/*******************************************************************
- *
- * @brief Writes the encoded chunks into a buffer
- *
- * @details
- *
- * Function : PrepFinalEncBuf
- *
- * Functionality:Fills the encoded buffer
- *
- * @params[in] void *buffer,initial encoded data
- * @params[in] size_t size,size of buffer
- * @params[in] void *encodedBuf,final buffer
- * @return ROK - success
- * RFAILED - failure
- *
- * ****************************************************************/
-static int PrepFinalEncBuf(const void *buffer, size_t size, void *encodedBuf)
-{
- memcpy(encodedBuf + encBufSize, buffer, size);
- encBufSize += size;
- return 0;
-} /* PrepFinalEncBuf */
/*******************************************************************
*
{
Buffer *mBuf;
- if(SGetMsg(region, pool, &mBuf) == ROK)
+ if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
{
- if(SAddPstMsgMult((Data *)encBuf, encBufSize, mBuf) == ROK)
+ if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
{
- SPrntMsg(mBuf, 0,0);
+ ODU_PRINT_MSG(mBuf, 0,0);
if(sctpSend(mBuf) != ROK)
{
- DU_LOG("\nF1AP : SCTP Send for E2 failed");
- SPutMsg(mBuf);
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
+ ODU_PUT_MSG_BUF(mBuf);
+ return RFAILED;
}
}
else
{
- DU_LOG("\nF1AP : SAddPstMsgMult failed");
- SPutMsg(mBuf);
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
+ ODU_PUT_MSG_BUF(mBuf);
+ return RFAILED;
}
- SPutMsg(mBuf);
+ ODU_PUT_MSG_BUF(mBuf);
}
else
{
- DU_LOG("\nF1AP : Failed to allocate memory");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
} /* SendE2APMsg */
-/*******************************************************************
- *
- * @brief Builds PLMN ID
- *
- * @details
- *
- * Function : plmnBuildRic
- *
- * Functionality: Building the PLMN ID
- *
- * @params[in] PLMNID plmn
- * OCTET_STRING_t *octe
- * @return ROK - success
- * RFAILED - failure
- *
- * ****************************************************************/
-
-void plmnBuildRic(Plmn plmn, OCTET_STRING_t *octe)
-{
- U8 mncCnt;
- octe->size = 3;
- RIC_ALLOC(octe->buf, octe->size * sizeof(U8));
- if(octe->buf == NULLP)
- {
- RETVALUE(RFAILED);
- }
- mncCnt = 2;
- octe->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
- if(mncCnt == 2)
- {
- octe->buf[1] = ((0xf0) | (plmn.mcc[2]));
- octe->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
- }
- else
- {
- octe->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
- octe->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
- }
-}
-
-/*******************************************************************
- *
- * @brief Fills the RicId
- *
- * @details
- *
- * Function : FillRicId
- *
- * Functionality: Fills the RicId
- *
- * @params[in] BIT_STRING_t *nbid,
- * U8 unusedBits
- * U8 byteSize
- * U8 val
- *
- * @return ROK - success
- * RFAILED - failure
- *
- * ****************************************************************/
-
-S16 FillRicId(BIT_STRING_t *id, U8 unusedBits, U8 byteSize, U8 val)
-{
- U8 tmp;
- id->size = byteSize;
- RIC_ALLOC(id->buf, id->size * sizeof(U8));
- if(id->buf == NULLP)
- {
- RETVALUE(RFAILED);
- }
-
- for (tmp = 0 ; tmp < (byteSize-1); tmp++)
- {
- id->buf[tmp] = tmp;
- }
- id->buf[byteSize-1] = val; //change this
- id->bits_unused = unusedBits;
- RETVALUE(ROK);
-}
-
/*******************************************************************
*
* @brief Builds Global RIC Id Params
S16 BuildGlobalRicId(GlobalRIC_ID_t *ricId)
{
- U8 unused = 4;
- U8 byteSize = 3;
- U8 val = 1;
+ uint8_t unused = 4;
+ uint8_t byteSize = 3;
+ uint8_t val = 16;
if(ricId != NULLP)
{
- plmnBuildRic(cuCfgParams.plmn , &ricId->pLMN_Identity);
+ ricId->pLMN_Identity.size = byteSize * sizeof(uint8_t);
+ RIC_ALLOC(ricId->pLMN_Identity.buf, ricId->pLMN_Identity.size);
+ buildPlmnId(ricCfgParams.plmn , ricId->pLMN_Identity.buf);
/* fill ric Id */
- FillRicId(&ricId->ric_ID, unused, byteSize, val);
- }
- RETVALUE(ROK);
-}
-#if 0
-RANfunctionID_ItemIEs_t* FillRanFuncItems(RANfunctionID_ItemIEs_t *items)
-{
- if(items != NULLP)
- {
- items->id = ProtocolIE_IDE2_id_RANfunction_Item;
- items->criticality = CriticalityE2_reject;
- items->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item;
- items->value.choice.RANfunctionID_Item.ranFunctionID = 1;
- items->value.choice.RANfunctionID_Item.ranFunctionRevision = 4;
- }
- RETVALUE(items);
-}
-
-S16 BuildRANfuncIdList(RANfunctionsID_List_t *funcIdList)
-{
- U8 elementCnt;
- RANfunctionID_ItemIEs_t *funcIdItems;
-
- elementCnt = 1;
- funcIdList->list.count = elementCnt;
- funcIdList->list.size = elementCnt * sizeof(RANfunctionID_ItemIEs_t);
- RIC_ALLOC(funcIdList->list.array, funcIdList->list.size);
- if(funcIdList->list.array == NULLP)
- {
- DU_LOG("\nE2AP : Memory allocation for RAN Function List failed");
- RETVALUE(RFAILED);
+ ricId->ric_ID.size = byteSize * sizeof(uint8_t);
+ RIC_ALLOC(ricId->ric_ID.buf, ricId->ric_ID.size);
+ fillBitString(&ricId->ric_ID, unused, byteSize, val);
}
- RIC_ALLOC(funcIdList->list.array[0], sizeof(RANfunctionID_ItemIEs_t));
- FillRanFuncItems(funcIdList->list.array[0]);
- RETVALUE(ROK);
+ return ROK;
}
-#endif
/*******************************************************************
*
E2AP_PDU_t *e2apMsg = NULL;
E2setupResponse_t *e2SetupRsp;
asn_enc_rval_t encRetVal;
- U8 idx;
- U8 elementCnt;
+ uint8_t idx;
+ uint8_t elementCnt;
- DU_LOG("\nE2AP : Building E2 Setup Response\n");
+ DU_LOG("\nINFO --> E2AP : Building E2 Setup Response\n");
RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
if(e2apMsg == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ return RFAILED;
}
e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
if(e2apMsg->choice.successfulOutcome == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
e2SetupRsp->protocolIEs.list.size);
if(e2SetupRsp->protocolIEs.list.array == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for E2ResponseIEs failed");
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
for(idx=0; idx<elementCnt; idx++)
RIC_FREE(e2apMsg->choice.successfulOutcome, \
sizeof(SuccessfulOutcomeE2_t));
RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
}
/* Global RIC ID */
BuildGlobalRicId(&(e2SetupRsp->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID));
xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
- cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
encBufSize = 0;
encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
/* Check encode results */
if(encRetVal.encoded == ENCODE_FAIL)
{
- DU_LOG("\nE2AP : Could not encode E2SetupResponse structure (at %s)\n",\
+ DU_LOG("\nERROR --> E2AP : Could not encode E2SetupResponse structure (at %s)\n",\
encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
- RETVALUE(RFAILED);
+ return RFAILED;
}
else
{
- DU_LOG("\nE2AP : Created APER encoded buffer for E2SetupResponse\n");
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupResponse\n");
for(int i=0; i< encBufSize; i++)
{
- printf("%x",encBuf[i]);
+ DU_LOG("%x",encBuf[i]);
}
}
if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
{
- DU_LOG("\nF1AP : Sending E2 Setup Response failed");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : Sending E2 Setup Response failed");
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
ricReqId->ricRequestorID = 1;
ricReqId->ricInstanceID = 1;
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
setupItems->ricActionType = RICactionType_report;
}
- RETVALUE(setupItems);
+ return (setupItems);
}
/*******************************************************************
items->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
fillSetupItems(&(items->value.choice.RICaction_ToBeSetup_Item));
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
S16 BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails)
{
- U8 elementCnt;
+ uint8_t elementCnt;
if(subsDetails != NULLP)
{
- /* Plmn is not called */
- plmnBuildRic(cuCfgParams.plmn, &subsDetails->ricEventTriggerDefinition);
+ /* Octet string to be build here */
+ /* Sending PLMN as Octect string */
+ uint8_t byteSize = 3;
+ subsDetails->ricEventTriggerDefinition.size = byteSize * sizeof(uint8_t);
+ RIC_ALLOC(subsDetails->ricEventTriggerDefinition.buf, subsDetails->ricEventTriggerDefinition.size);
+ buildPlmnId(ricCfgParams.plmn, subsDetails->ricEventTriggerDefinition.buf);
elementCnt = 1;
subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt;
subsDetails->ricAction_ToBeSetup_List.list.size = \
subsDetails->ricAction_ToBeSetup_List.list.size);
if(subsDetails->ricAction_ToBeSetup_List.list.array == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for RICactionToBeSetup Items failed");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RICactionToBeSetup Items failed");
+ return RFAILED;
}
RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[0],\
sizeof(RICaction_ToBeSetup_ItemIEs_t));
fillSubsDetails(subsDetails->ricAction_ToBeSetup_List.list.array[0]);
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
S16 BuildAndSendRicSubscriptionReq()
{
- E2AP_PDU_t *e2apRicMsg = NULL;
+ E2AP_PDU_t *e2apRicMsg = NULL;
RICsubscriptionRequest_t *ricSubscriptionReq;
- U8 elementCnt;
- U8 idx;
- U8 ieId;
- S16 ret;
- asn_enc_rval_t encRetVal; /* Encoder return value */
+ uint8_t elementCnt;
+ uint8_t idx;
+ uint8_t ieId;
+ S16 ret;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
ricSubsStatus = TRUE;
- DU_LOG("\nE2AP : Building RIC Subscription Request\n");
+ DU_LOG("\nINFO --> E2AP : Building RIC Subscription Request\n");
RIC_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
if(e2apRicMsg == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ return RFAILED;
}
e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage;
RIC_ALLOC(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
if(e2apRicMsg->choice.initiatingMessage == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription;
e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
ricSubscriptionReq->protocolIEs.list.size);
if(ricSubscriptionReq->protocolIEs.list.array == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation for RICSubscriptionRequestIEs failed");
+ DU_LOG("\nERROR --> E2AP : Memory allocation for RICSubscriptionRequestIEs failed");
RIC_FREE(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
RIC_FREE(e2apRicMsg, (Size)sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
for(idx=0; idx<elementCnt; idx++)
RIC_FREE(e2apRicMsg->choice.initiatingMessage, \
sizeof(InitiatingMessageE2_t));
RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
}
/* Prints the Msg formed */
xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
- cmMemset((U8 *)encBuf, 0, ENC_BUF_MAX_LEN);
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
encBufSize = 0;
encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
encBuf);
if(encRetVal.encoded == ENCODE_FAIL)
{
- DU_LOG("\nE2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
+ DU_LOG("\nERROR --> E2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
- RETVALUE(RFAILED);
+ return RFAILED;
}
else
{
- DU_LOG("\nE2AP : Created APER encoded buffer for RicSubscriptionRequest\n");
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicSubscriptionRequest\n");
for(int i=0; i< encBufSize; i++)
{
- printf("%x",encBuf[i]);
+ DU_LOG("%x",encBuf[i]);
}
}
/* Sending msg */
if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
{
- DU_LOG("\nE2AP : Sending RIC subscription Request failed");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> E2AP : Sending RIC subscription Request failed");
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
}
* ****************************************************************/
void E2APMsgHdlr(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 ;
+ 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("\nE2AP : Received E2AP message buffer");
- SPrntMsg(mBuf, 0,0);
+ DU_LOG("\nINFO --> E2AP : Received E2AP message buffer");
+ ODU_PRINT_MSG(mBuf, 0,0);
/* Copy mBuf into char array to decode it */
- SFndLenMsg(mBuf, &recvBufLen);
- if(SGetSBuf(DFLT_REGION, DFLT_POOL, (Data **)&recvBuf, (Size)recvBufLen) != ROK)
+ ODU_GET_MSG_LEN(mBuf, &recvBufLen);
+ RIC_ALLOC(recvBuf, (Size)recvBufLen);
+
+ if(recvBuf == NULLP)
{
- DU_LOG("\nE2AP : Memory allocation failed");
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed");
return;
}
- if(SCpyMsgFix(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
+ if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
{
- DU_LOG("\nE2AP : Failed while copying %d", copyCnt);
+ DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
return;
}
- printf("\nE2AP : Received flat buffer to be decoded : ");
+ DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
for(i=0; i< recvBufLen; i++)
{
- printf("%x",recvBuf[i]);
+ DU_LOG("%x",recvBuf[i]);
}
- /* Decoding flat buffer into F1AP messsage */
+ /* 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);
- SPutSBuf(DFLT_REGION, DFLT_POOL, (Data *)recvBuf, (Size)recvBufLen);
+ RIC_FREE(recvBuf, (Size)recvBufLen);
+
if(rval.code == RC_FAIL || rval.code == RC_WMORE)
{
- DU_LOG("\nE2AP : ASN decode failed");
+ DU_LOG("\nERROR --> E2AP : ASN decode failed");
return;
}
- printf("\n");
+ DU_LOG("\n");
xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
switch(e2apMsg->present)
{
case InitiatingMessageE2__value_PR_E2setupRequest:
{
- DU_LOG("\nE2AP : E2 setup request received");
+ DU_LOG("\nINFO --> E2AP : E2 setup request received");
BuildAndSendE2SetupRsp();
break;
}
case InitiatingMessageE2__value_PR_RICindication:
{
- DU_LOG("\nE2AP : RIC Indication Acknowledged");
+ DU_LOG("\nINFO --> E2AP : RIC Indication Acknowledged");
break;
}
default:
{
- DU_LOG("\nE2AP : Invalid type of intiating message [%d]",e2apMsg->choice.initiatingMessage->value.present);
+ DU_LOG("\nERROR --> E2AP : Invalid type of intiating message [%d]",e2apMsg->choice.initiatingMessage->value.present);
return;
}
}/* End of switch(initiatingMessage) */
{
case SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse:
{
- DU_LOG("\nE2AP : RICsubscriptionResponse Msg Acknowledged");
+ DU_LOG("\nINFO --> E2AP : RICsubscriptionResponse Msg Acknowledged");
break;
}
default:
{
- DU_LOG("\nE2AP : Invalid type of successfulOutcome message [%d]",e2apMsg->choice.successfulOutcome->value.present);
+ DU_LOG("\nERROR --> E2AP : Invalid type of successfulOutcome message [%d]",e2apMsg->choice.successfulOutcome->value.present);
return;
}
break;
}
default:
{
- DU_LOG("\nE2AP : Invalid type message type ");
+ DU_LOG("\nERROR --> E2AP : Invalid type message type ");
return;
}