*******************************************************************************/
#include "du_e2ap_msg_hdl.h"
#include "du_mgr_main.h"
-#include "du_cfg.h"
#include "GlobalE2node-gNB-ID.h"
#define ENC_BUF_MAX_LEN 100
/* Global variable */
DuCfgParams duCfgParam;
-char encBuf[ENC_BUF_MAX_LEN];
-int encBufSize;
-
-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 */
-
-/*******************************************************************
- *
- * @brief Builds PLMN ID
- *
- * @details
- *
- * Function : BuildPlmnId
- *
- * Functionality: Building the PLMN ID
- *
- * @params[in] PLMNID plmn
- * OCTET_STRING_t *plmnid
- * @return ROK - success
- * RFAILED - failure
- *
- * ****************************************************************/
-
-S16 BuildPlmnId(PlmnId plmn, OCTET_STRING_t *plmnid)
-{
- U8 mncCnt;
- plmnid->size = 3;
- DU_ALLOC(plmnid->buf, plmnid->size * sizeof(U8));
- if(plmnid->buf == NULLP)
- {
- RETVALUE(RFAILED);
- }
- mncCnt = 2;
- plmnid->buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
- if(mncCnt == 2)
- {
- plmnid->buf[1] = ((0xf0) | (plmn.mcc[2]));
- plmnid->buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
- }
- else
- {
- plmnid->buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
- plmnid->buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
- }
- RETVALUE(ROK);
-}
-
-/*******************************************************************
- *
- * @brief Builds NodeB Id
- *
- * @details
- *
- * Function : BuildNodeBId
- *
- * Functionality: Building the NodeBId
- *
- * @params[in] BIT_STRING_t *nbid,
- * U8 unusedBits
- * U8 byteSize
- * U8 val
- *
- * @return ROK - success
- * RFAILED - failure
- *
- * ****************************************************************/
-
-S16 BuildNodeBId(BIT_STRING_t *nbid, U8 unusedBits, U8 byteSize, U8 val)
-{
- U8 tmp;
- nbid->size = byteSize;
- DU_ALLOC(nbid->buf, nbid->size * sizeof(U8));
- if(nbid->buf == NULLP)
- {
- RETVALUE(RFAILED);
- }
-
- for (tmp = 0 ; tmp < ((nbid->size)-1); tmp++)
- {
- nbid->buf[tmp] = 0;
- }
- nbid->buf[byteSize-1] = val;
- nbid->bits_unused = unusedBits;
- RETVALUE(ROK);
-}
/*******************************************************************
*
U8 val = 1;
if(gNbId != NULLP)
{
- BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+ /* Allocate Buffer size */
+ gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(U8);
+ DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
+ buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
&gNbId->global_gNB_ID.plmn_id);
- /* fill gND Id */
- gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
- BuildNodeBId(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
- }
- RETVALUE(ROK);
-}
-
-#if 0
-RANfunction_ItemIEs_t* BuildRanFuncItems(RANfunction_ItemIEs_t *items)
-{
- U8 byteSize;
- U8 tmp;
- byteSize = 3;
-
- items->id = ProtocolIE_IDE2_id_RANfunctionID;
- items->criticality = CriticalityE2_ignore;
- items->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
- items->value.choice.RANfunction_Item.ranFunctionID = 1;
- BuildPlmn(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, &items->value.choice.RANfunction_Item.ranFunctionDefinition);
- items->value.choice.RANfunction_Item.ranFunctionRevision = 4;
-
- RETVALUE(items);
-}
-
-S16 BuildRANList(RANfunctions_List_t *ranFuncList)
-{
- U8 elementCnt;
- U8 eleidx;
- S16 ret;
- RANfunction_ItemIEs_t *funcItems;
-
- elementCnt = 1;
- ranFuncList->list.count = elementCnt;
- ranFuncList->list.size = elementCnt * sizeof(RANfunction_ItemIEs_t);
- DU_ALLOC(ranFuncList->list.array, \
- ranFuncList->list.size);
- if(ranFuncList->list.array == NULLP)
- {
- DU_LOG("\nE2AP : Memory allocation for RAN Function List failed");
- RETVALUE(RFAILED);
+ /* fill gND Id */
+ gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
+ /* Allocate Buffer size */
+ gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(U8);
+ DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+ fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
}
- /* Fill RAN function Params */
- DU_ALLOC(ranFuncList->list.array[0], sizeof(RANfunction_ItemIEs_t));
- BuildRanFuncItems(ranFuncList->list.array[0]);
-
- RETVALUE(ROK);
+ return ROK;
}
-#endif
/*******************************************************************
*
U8 elementCnt;
U8 idx;
U8 ieId;
- S16 ret;
asn_enc_rval_t encRetVal; /* Encoder return value */
DU_LOG("\nE2AP : Building E2 Setup Request\n");
if(e2apMsg == NULLP)
{
DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
{
DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
DU_LOG("\nE2AP : Memory allocation for E2RequestIEs failed");
DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
DU_FREE(e2apMsg, (Size)sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
for(idx=0; idx<elementCnt; idx++)
DU_FREE(e2apMsg->choice.initiatingMessage, \
sizeof(InitiatingMessageE2_t));
DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
}
{
DU_LOG("\nE2AP : Could not encode E2SetupRequest structure (at %s)\n",\
encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
- RETVALUE(RFAILED);
+ return RFAILED;
}
else
{
if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
{
DU_LOG("\nE2AP : Sending E2 Setup request failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
}/* End of BuildAndSendE2SetupReq */
/*******************************************************************
ricReqId->ricRequestorID = 1;
ricReqId->ricInstanceID = 1;
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1;
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
*
if(admitListPtr->list.array == NULLP)
{
DU_LOG("\nE2AP : Memory allocation for RIC Admit List failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
DU_ALLOC(admitListPtr->list.array[0], sizeof(RICaction_Admitted_ItemIEs_t));
fillRicAdmitList(admitListPtr->list.array[0]);
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
if(e2apRicMsg == NULLP)
{
DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
{
DU_LOG("\nE2AP : Memory allocation for Ric subscription Response failed");
DU_FREE(e2apRicMsg, sizeof(RICsubscriptionResponse_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
DU_LOG("\nE2AP : Memory allocation for RICsubscriptionResponseIE failed");
DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
for(idx=0; idx<elementCnt; idx++)
DU_FREE(e2apRicMsg->choice.successfulOutcome, \
sizeof(SuccessfulOutcomeE2_t));
DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
}
idx = 0;
{
DU_LOG("\nE2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
- RETVALUE(RFAILED);
+ return RFAILED;
}
else
{
if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
{
DU_LOG("\nE2AP : Sending RIC Subscription Response failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
+}
+/******************************************************************
+*
+* @brief Processes E2 Setup Response sent by RIC
+*
+* @details
+*
+* Function : procE2SetupRsp
+*
+* Functionality: Processes E2 Setup Response sent by RIC
+*
+* @params[in] E2AP_PDU_t ASN decoded E2AP message
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+S16 procE2SetupRsp(E2AP_PDU_t *e2apMsg)
+{
+ E2setupResponse_t *e2SetRspMsg;
+ E2apMsgDb e2SetupRspDb;
+ U8 idx;
+
+ DU_LOG("\nE2AP : E2 Setup Response received");
+ duCb.e2Status = TRUE; //Set E2 status as true
+ e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
+
+ for(idx=0; idx<e2SetRspMsg->protocolIEs.list.count; idx++)
+ {
+ switch(e2SetRspMsg->protocolIEs.list.array[idx]->id)
+ {
+ case ProtocolIE_IDE2_id_GlobalRIC_ID:
+ {
+ /* To store the Ric Id Params */
+ U32 recvBufLen;
+ memset(&e2SetupRspDb.plmn, 0, sizeof(PLMN_IdentityE2_t));
+
+ recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity);
+
+ bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.ric_ID, &e2SetupRspDb.ricId);
+ aper_decode(0, &asn_DEF_PLMN_IdentityE2, (void **)&e2SetupRspDb.plmn, \
+ &e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.pLMN_Identity, recvBufLen, 0, 0);
+
+ xer_fprint(stdout, &asn_DEF_PLMN_IdentityE2, &e2SetupRspDb.plmn);
+ break;
+ }
+ default:
+ DU_LOG("\nE2AP : Invalid IE received in E2SetupRsp:%ld",
+ e2SetRspMsg->protocolIEs.list.array[idx]->id);
+ break;
+ }
+ }
+ return ROK;
}
+/******************************************************************
+*
+* @brief Processes RIC Subscription Req sent by RIC
+*
+* @details
+*
+* Function : procRicSubsReq
+*
+* Functionality: Processes E2 Setup Response sent by CU
+*
+* @params[in] E2AP_PDU_t ASN decoded E2AP message
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+
+S16 procRicSubsReq(E2AP_PDU_t *e2apMsg)
+{
+ S16 ret = ROK;
+ U8 idx;
+ U8 ied;
+ RICsubscriptionRequest_t *ricSubsReq;
+ RICaction_ToBeSetup_ItemIEs_t *actionItem;
+ E2apMsgDb ricReqDb;
+
+ DU_LOG("\nE2AP : Ric Subscription request received");
+ ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
+
+ for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
+ {
+ switch(ricSubsReq->protocolIEs.list.array[idx]->id)
+ {
+ case ProtocolIE_IDE2_id_RICrequestID:
+ {
+ ricReqDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->\
+ value.choice.RICrequestID.ricRequestorID;
+ ricReqDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]-> \
+ value.choice.RICrequestID.ricInstanceID;
+ break;
+ }
+ case ProtocolIE_IDE2_id_RANfunctionID:
+ {
+ ricReqDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]-> \
+ value.choice.RANfunctionID;
+ break;
+ }
+ case ProtocolIE_IDE2_id_RICsubscriptionDetails:
+ {
+ U32 recvBufLen;
+ memset(&ricReqDb.ricEventTrigger, 0, sizeof(RICeventTriggerDefinition_t));
+
+ recvBufLen = sizeof(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition);
+
+ aper_decode(0, &asn_DEF_RICeventTriggerDefinition, (void **)&ricReqDb.ricEventTrigger, &(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition), recvBufLen, 0, 0);
+ xer_fprint(stdout, &asn_DEF_RICeventTriggerDefinition, &ricReqDb.ricEventTrigger);
+
+ actionItem = *ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list.array;
+
+ for(ied = 0; ied < ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
+ RICsubscriptionDetails.ricAction_ToBeSetup_List.list.count; ied++)
+ {
+ switch(actionItem->id)
+ {
+ case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
+ {
+ ricReqDb.ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
+ ricReqDb.ricActionType = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType;
+ break;
+ }
+ default:
+ DU_LOG("\nE2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
+ break;
+ }
+ }
+
+ break;
+ }
+
+ default:
+ DU_LOG("\nE2AP : Invalid IE received in Ric SubsReq:%ld",
+ ricSubsReq->protocolIEs.list.array[idx]->id);
+ break;
+ }
+ }
+ ret = BuildAndSendRicSubscriptionRsp();
+
+ RETVALUE(ret);
+}
+
+
/*******************************************************************
*
* @brief Builds and Send the RicIndication Message
U8 elementCnt;
U8 idx;
U8 ieId;
- S16 ret;
asn_enc_rval_t encRetVal; /* Encoder return value */
DU_LOG("\nE2AP : Building Ric Indication Message\n");
if(e2apMsg == NULLP)
{
DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
{
DU_LOG("\nE2AP : Memory allocation for E2AP-PDU failed");
DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
DU_LOG("\nE2AP : Memory allocation for RICindicationIEs failed");
DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
DU_FREE(e2apMsg, (Size)sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
for(idx=0; idx<elementCnt; idx++)
DU_FREE(e2apMsg->choice.initiatingMessage, \
sizeof(InitiatingMessageE2_t));
DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
- RETVALUE(RFAILED);
+ return RFAILED;
}
}
idx = 0;
ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
RICindication_IEs__value_PR_RICindicationHeader;
- BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 * sizeof(U8);
+ DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
+ buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader);
/* TO BE CHANGED: RIC INDICATION DATA */
- /* Foe now filling a dummy octect data, need to tested with PRBs*/
+ /* For now filling a dummy octect data, need to tested with PRBs*/
idx++;
ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
RICindication_IEs__value_PR_RICindicationMessage;
- BuildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 * sizeof(U8);
+ DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
+ ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
+ buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage);
/* Prints the Msg formed */
{
DU_LOG("\nE2AP : Could not encode RIC Indication Message (at %s)\n",\
encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
- RETVALUE(RFAILED);
+ return RFAILED;
}
else
{
if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
{
DU_LOG("\nE2AP : Sending RIC Indication Message");
- RETVALUE(RFAILED);
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
{
SPrntMsg(mBuf, 0,0);
- if(sctpSend(mBuf, duCfgParam.sctpParams.itfType.e2Itf) != ROK)
+ if(sctpSend(mBuf, E2_INTERFACE) != ROK)
{
DU_LOG("\nE2AP : SCTP Send for E2 failed");
SPutMsg(mBuf);
- RETVALUE(RFAILED);
+ return RFAILED;
}
}
else
{
- DU_LOG("\nF1AP : SAddPstMsgMult failed");
+ DU_LOG("\nE2AP : SAddPstMsgMult failed");
SPutMsg(mBuf);
- RETVALUE(RFAILED);
+ return RFAILED;
}
SPutMsg(mBuf);
}
else
{
- DU_LOG("\nF1AP : Failed to allocate memory");
- RETVALUE(RFAILED);
+ DU_LOG("\nE2AP : Failed to allocate memory");
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
} /* SendE2APMsg */
/*******************************************************************
}/* End of switch(e2apMsg->present) */
} /* End of E2APMsgHdlr */
+
+/**********************************************************************
+ End of file
+**********************************************************************/