X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fdu_app%2Fdu_e2ap_msg_hdl.c;h=b01fcb2fb3aacd78554ab57fcdba32b25dc26606;hb=52ca0cf30806914e2f44054932cd2300f12aded8;hp=57a89f9000ddda6cb4a076f7da3a6ca83ba9a836;hpb=875cd839a3fe1efddd284433868449add3b0b82a;p=o-du%2Fl2.git diff --git a/src/du_app/du_e2ap_msg_hdl.c b/src/du_app/du_e2ap_msg_hdl.c index 57a89f900..b01fcb2fb 100644 --- a/src/du_app/du_e2ap_msg_hdl.c +++ b/src/du_app/du_e2ap_msg_hdl.c @@ -34,9 +34,9 @@ #include "E2AP-PDU.h" #include "du_e2ap_msg_hdl.h" #include "odu_common_codec.h" +#include "E2nodeComponentInterfaceF1.h" +#include "E2setupRequest.h" -/* Global variable */ -DuCfgParams duCfgParam; /******************************************************************* * * @brief Builds Global gNodeB Params @@ -57,7 +57,7 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId) { uint8_t unused = 0; uint8_t byteSize = 4; - uint8_t val = 1; + uint8_t gnbId = 1; uint8_t ret = ROK; /* Allocate Buffer size */ @@ -72,27 +72,130 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId) else { buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \ - gNbId->global_gNB_ID.plmn_id.buf); + gNbId->global_gNB_ID.plmn_id.buf); /* 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(uint8_t); gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP; DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \ - gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); + gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP) { - DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer"); - ret = RFAILED; + DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer"); + ret = RFAILED; } else { - fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val); + fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId); } } return ret; } +/******************************************************************* + * + * @brief Builds E2 node config addition list + * + * @details + * + * Function : BuildE2NodeConfigAddList + * + * Functionality: Building E2 node config addition list + * + * @params[in] E2nodeComponentConfigAddition_List_t *e2NodeAddList + * @return ROK - success + * RFAILED - failure + * + ******************************************************************/ + +uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList) +{ + uint8_t arrIdx = 0; + E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe; + E2nodeComponentConfigAddition_Item_t *e2NodeAddItem; + + e2NodeAddList->list.count = 1; + e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *); + DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size); + if(e2NodeAddList->list.array == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__); + return RFAILED; + } + + for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++) + { + DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t)); + if(e2NodeAddList->list.array[arrIdx] == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__); + return RFAILED; + } + } + + arrIdx = 0; + e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx]; + e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item; + e2NodeAddItemIe->criticality = CriticalityE2_reject; + e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item; + e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item; + + /* E2nodeComponentInterfaceType */ + e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1; + + /* E2 Node Component Request Part */ + e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize; + DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\ + e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size); + if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__); + return RFAILED; + } + + memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\ + duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, e2NodeAddItem->e2nodeComponentConfiguration.\ + e2nodeComponentRequestPart.size); + DU_FREE(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf,duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize); + + /* E2 Node Component Response Part */ + e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize; + DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \ + e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size); + if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__); + return RFAILED; + } + memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \ + duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, e2NodeAddItem->e2nodeComponentConfiguration.\ + e2nodeComponentResponsePart.size); + DU_FREE(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize); + + /* E2 Node Component ID */ + e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1; + DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\ + sizeof(E2nodeComponentInterfaceF1_t)); + if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP) + { + DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__); + return RFAILED; + } + e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t); + DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\ + e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size); + + if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP) + { + DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__); + return RFAILED; + } + e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx] = duCfgParam.duId; + return ROK; + +} + /******************************************************************* * * @brief Fills the initiating IE for E2 Setup Request @@ -114,75 +217,196 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId) uint8_t fillE2SetupReq(E2setupRequest_t **e2SetupReq, uint8_t *idx) { uint8_t elementCnt = 0; - uint8_t idx2 = 0; + uint8_t arrIdx = 0; uint8_t ret = ROK; if(*e2SetupReq != NULLP) { - elementCnt = 1; + elementCnt = 3; (*e2SetupReq)->protocolIEs.list.count = elementCnt; - (*e2SetupReq)->protocolIEs.list.size = \ - elementCnt * sizeof(E2setupRequestIEs_t); + (*e2SetupReq)->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*); /* Initialize the E2Setup members */ DU_ALLOC((*e2SetupReq)->protocolIEs.list.array, \ - (*e2SetupReq)->protocolIEs.list.size); + (*e2SetupReq)->protocolIEs.list.size); if((*e2SetupReq)->protocolIEs.list.array == NULLP) { - DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements"); - ret = RFAILED; + DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements"); + return RFAILED; + } + for(*idx = 0; *idx < elementCnt; (*idx)++) + { + DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[*idx],\ + sizeof(E2setupRequestIEs_t)); + if((*e2SetupReq)->protocolIEs.list.array[*idx] == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayidx [%d]", *idx); + return RFAILED; + } + } + arrIdx = 0; + + /* TransactionID */ + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID; + + arrIdx++; + /* GlobalE2node_gNB_ID */ + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB; + + DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.\ + GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t)); + if((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.\ + GlobalE2node_ID.choice.gNB == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId"); + return RFAILED; } else { - for(*idx = 0; *idx < elementCnt; (*idx)++) - { - DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[*idx],\ - sizeof(E2setupRequestIEs_t)); - if((*e2SetupReq)->protocolIEs.list.array[*idx] == NULLP) - { - DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayidx [%d]", *idx); - ret = RFAILED; - } - else - { - /* GlobalE2node_gNB_ID */ - (*e2SetupReq)->protocolIEs.list.array[idx2]->id = \ - ProtocolIE_IDE2_id_GlobalE2node_ID; - (*e2SetupReq)->protocolIEs.list.array[idx2]->criticality = \ - CriticalityE2_reject; - (*e2SetupReq)->protocolIEs.list.array[idx2]->value.present =\ - E2setupRequestIEs__value_PR_GlobalE2node_ID; - (*e2SetupReq)->protocolIEs.list.array[idx2]->value.choice.\ - GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB; - - DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[idx2]->value.choice.\ - GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t)); - if((*e2SetupReq)->protocolIEs.list.array[idx2]->value.choice.\ - GlobalE2node_ID.choice.gNB == NULLP) - { - DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId"); - ret = RFAILED; - } - else - { - ret = BuildGlobalgNBId((*e2SetupReq)->protocolIEs.list.array[idx2]->value.\ - choice.GlobalE2node_ID.choice.gNB); - if(ret != ROK) - { - ret = RFAILED; - } - } - - } - } + ret = BuildGlobalgNBId((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.\ + choice.GlobalE2node_ID.choice.gNB); + if(ret != ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id"); + return RFAILED; + } } + + arrIdx++; + /* E2 Node Component Configuration Addition List */ + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List; + if(BuildE2NodeConfigAddList(&((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK) + { + DU_LOG("\nERROR --> E2AP : Failed to E2 Node config addition list"); + return RFAILED; + } + } else { - ret = RFAILED; DU_LOG("\nERROR --> E2AP : received e2SetupReq is NULL"); + return RFAILED; + } + return ROK; +} + + +/******************************************************************* + * + * @brief De Allocate E2 Setup Request Message + * + * @details + * + * Function : FreeE2SetupReq + * + * Functionality: De-Allocating E2 Setup request Message + * + * @params[in] E2AP_PDU_t *e2apMsg + + * @return void + * + * ****************************************************************/ + +void FreeE2SetupReq(E2AP_PDU_t *e2apMsg) +{ + uint8_t arrIdx = 0; + uint8_t e2NodeAddListIdx =0; + E2setupRequest_t *e2SetupReq; + E2nodeComponentConfigAddition_List_t *e2NodeAddList; + E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem; + + /* De-allocating Memory */ + if(e2apMsg != NULLP) + { + if(e2apMsg->choice.initiatingMessage != NULLP) + { + e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest; + if(e2SetupReq->protocolIEs.list.array != NULLP) + { + for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++) + { + if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP) + { + switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id) + { + case ProtocolIE_IDE2_id_TransactionID: + break; + case ProtocolIE_IDE2_id_GlobalE2node_ID: + { + if(e2SetupReq->protocolIEs.list.array[arrIdx]->\ + value.choice.GlobalE2node_ID.choice.gNB != NULLP) + { + GlobalE2node_gNB_ID_t *gNbId = NULLP; + gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\ + value.choice.GlobalE2node_ID.choice.gNB; + if(gNbId->global_gNB_ID.plmn_id.buf != NULLP) + { + DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\ + gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); + DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\ + gNbId->global_gNB_ID.plmn_id.size); + } + DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\ + choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t)); + } + break; + } + case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition: + { + e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List; + if(e2NodeAddList->list.array) + { + for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++) + { + e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx]; + + /* Free E2 Node Component Request Part */ + DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\ + e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size); + + /* Free E2 Node Component Response Part */ + DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\ + e2nodeComponentResponsePart.buf, \ + e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size); + + /* Free E2 Node Component ID */ + if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1) + { + DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\ + e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\ + e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\ + e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size); + DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\ + sizeof(E2nodeComponentInterfaceF1_t)); + } + DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t)); + } + DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size); + } + break; + } + default: + DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\ + (e2SetupReq->protocolIEs.list.array[arrIdx]->id)); + break; + } + DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t)); + } + } + DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size); + } + DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); + } + DU_FREE(e2apMsg, sizeof(E2AP_PDU_t)); } - return ret; } /******************************************************************* @@ -214,16 +438,16 @@ uint8_t BuildAndSendE2SetupReq() DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); if(e2apMsg == NULLP) { - DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); - break; + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; } e2apMsg->present = E2AP_PDU_PR_initiatingMessage; DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); if(e2apMsg->choice.initiatingMessage == NULLP) { - DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); - DU_FREE(e2apMsg, sizeof(E2AP_PDU_t)); - return RFAILED; + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + DU_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + return RFAILED; } e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject; e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup; @@ -233,8 +457,8 @@ uint8_t BuildAndSendE2SetupReq() ret = fillE2SetupReq(&e2SetupReq, &idx); if(ret != ROK) { - DU_LOG("\nERROR --> E2AP : fillE2SetupReq() failed"); - break; + DU_LOG("\nERROR --> E2AP : fillE2SetupReq() failed"); + break; } /* Prints the Msg formed */ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg); @@ -242,108 +466,35 @@ uint8_t BuildAndSendE2SetupReq() memset(encBuf, 0, ENC_BUF_MAX_LEN); encBufSize = 0; encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\ - encBuf); + encBuf); if(encRetVal.encoded == ENCODE_FAIL) { - DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\ - encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); - break; + DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + break; } else { - DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n"); - for(int i=0; i< encBufSize; i++) - { - printf("%x",encBuf[i]); - } + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n"); +#ifdef DEBUG_ASN_PRINT + for(int i=0; i< encBufSize; i++) + { + printf("%x",encBuf[i]); + } +#endif } if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK) { - DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed"); + DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed"); } break; }while(true); - deAllocateE2SetupReqMsg(e2apMsg, e2SetupReq, idx); + FreeE2SetupReq(e2apMsg); return ret; }/* End of BuildAndSendE2SetupReq */ -/******************************************************************* - * - * @brief De Allocate E2 Setup Request Message - * - * @details - * - * Function : deAllocateE2SetupReqMsg - * - * Functionality: De-Allocating E2 Setup request Message - * - * @params[in] E2AP_PDU_t *e2apMsg - * E2setupRequest_t *e2SetupReq - * @return ROK - success - * RFAILED - failure - * - * ****************************************************************/ - -uint8_t deAllocateE2SetupReqMsg(E2AP_PDU_t *e2apMsg, \ - E2setupRequest_t *e2SetupReq, uint8_t idx) -{ - uint8_t idx2; - uint8_t ret = ROK; - /* De-allocating Memory */ - if(e2apMsg != NULLP) - { - if(e2apMsg->choice.initiatingMessage != NULLP) - { - if(e2SetupReq->protocolIEs.list.array != NULLP) - { - for(idx2 = 0; idx2 < idx; idx2++) - { - if(e2SetupReq->protocolIEs.list.array[idx2] != NULLP) - { - switch(e2SetupReq->protocolIEs.list.array[idx2]->id) - { - case ProtocolIE_IDE2_id_GlobalE2node_ID: - { - if(e2SetupReq->protocolIEs.list.array[idx2]->\ - value.choice.GlobalE2node_ID.choice.gNB != NULLP) - { - GlobalE2node_gNB_ID_t *gNbId = NULLP; - gNbId = e2SetupReq->protocolIEs.list.array[idx2]->\ - value.choice.GlobalE2node_ID.choice.gNB; - if(gNbId->global_gNB_ID.plmn_id.buf != NULLP) - { - if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf != NULLP) - { - DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\ - gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size); - } - DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\ - gNbId->global_gNB_ID.plmn_id.size); - } - DU_FREE(e2SetupReq->protocolIEs.list.array[idx2]->value.\ - choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t)); - } - DU_FREE(e2SetupReq->protocolIEs.list.array[idx2],\ - sizeof(E2setupRequestIEs_t)); - break; - } - default: - DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\ - (e2SetupReq->protocolIEs.list.array[idx2]->id)); - break; - } - } - } - DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size); - } - DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); - } - DU_FREE(e2apMsg, sizeof(E2AP_PDU_t)); - } - return ret; -} /******************************************************************* * * @brief Builds Ric Request Id @@ -692,10 +843,12 @@ uint8_t BuildAndSendRicSubscriptionRsp() else { DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n"); +#ifdef DEBUG_ASN_PRINT for(int i=0; i< encBufSize; i++) { printf("%x",encBuf[i]); } +#endif } if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK) @@ -712,6 +865,77 @@ uint8_t BuildAndSendRicSubscriptionRsp() return ret; } + +/****************************************************************** + * + * @brief Deallocation of memory allocated bu aper decoder for e2 setup response + * + * @details + * + * Function : freeAperDecodingOfE2SetupRsp + * + * Functionality: Deallocation of memory allocated bu aper decoder for e2 + * setup response + * + * @params[in] E2setupResponse_t *e2SetRspMsg; + * @return void + * + * ****************************************************************/ +void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg) +{ + uint8_t arrIdx, e2NodeConfigAddAckListIdx; + E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem; + E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList; + + if(e2SetRspMsg) + { + if(e2SetRspMsg->protocolIEs.list.array) + { + for(arrIdx=0; arrIdxprotocolIEs.list.count; arrIdx++) + { + if(e2SetRspMsg->protocolIEs.list.array[arrIdx]) + { + switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id) + { + case ProtocolIE_IDE2_id_TransactionID: + break; + + case ProtocolIE_IDE2_id_GlobalRIC_ID: + { + free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf); + free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf); + break; + } + + case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck: + { + e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List; + if(e2NodeConfigAddAckList->list.array ) + { + for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++) + { + if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]) + { + e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]; + free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\ + e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf); + free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\ + e2nodeComponentInterfaceTypeF1); + free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]); + } + } + free(e2NodeConfigAddAckList->list.array); + } + break; + } + } + free(e2SetRspMsg->protocolIEs.list.array[arrIdx]); + } + } + free(e2SetRspMsg->protocolIEs.list.array); + } + } +} /****************************************************************** * * @brief Processes E2 Setup Response sent by RIC @@ -729,7 +953,7 @@ uint8_t BuildAndSendRicSubscriptionRsp() * ****************************************************************/ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg) { - uint8_t idx; + uint8_t arrIdx =0; uint32_t recvBufLen; E2setupResponse_t *e2SetRspMsg; @@ -737,38 +961,41 @@ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg) duCb.e2Status = TRUE; //Set E2 status as true e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse; - for(idx=0; idxprotocolIEs.list.count; idx++) + for(arrIdx=0; arrIdxprotocolIEs.list.count; arrIdx++) { - switch(e2SetRspMsg->protocolIEs.list.array[idx]->id) + switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id) { - case ProtocolIE_IDE2_id_GlobalRIC_ID: - { - /* To store the Ric Id Params */ - recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[idx]->value\ - .choice.GlobalRIC_ID.pLMN_Identity.size); - e2apMsgDb.plmn = NULLP; - DU_ALLOC(e2apMsgDb.plmn, recvBufLen); - if(e2apMsgDb.plmn) - { - memcpy(e2apMsgDb.plmn, e2SetRspMsg->protocolIEs.list.array[idx]\ - ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen); - free(e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.\ - GlobalRIC_ID.pLMN_Identity.buf); - } - bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID.ric_ID, &e2apMsgDb.ricId); - free(e2SetRspMsg->protocolIEs.list.array[idx]->value.choice.\ - GlobalRIC_ID.ric_ID.buf); - /*TODO : e2apMsgDb.plmn memory to be deallocated after the usage */ - break; - } - default: - DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld", - e2SetRspMsg->protocolIEs.list.array[idx]->id); - break; + case ProtocolIE_IDE2_id_TransactionID: + break; + + case ProtocolIE_IDE2_id_GlobalRIC_ID: + { + /* To store the Ric Id Params */ + recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\ + .choice.GlobalRIC_ID.pLMN_Identity.size); + e2apMsgDb.plmn = NULLP; + DU_ALLOC(e2apMsgDb.plmn, recvBufLen); + if(e2apMsgDb.plmn) + { + memcpy(e2apMsgDb.plmn, e2SetRspMsg->protocolIEs.list.array[arrIdx]\ + ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen); + } + bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &e2apMsgDb.ricId); + /*TODO : e2apMsgDb.plmn memory to be deallocated after the usage */ + break; + } + + case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck: + break; + + default: + DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld", + e2SetRspMsg->protocolIEs.list.array[arrIdx]->id); + break; } - free(e2SetRspMsg->protocolIEs.list.array[idx]); } - free(e2SetRspMsg->protocolIEs.list.array); + freeAperDecodingOfE2SetupRsp(e2SetRspMsg); + BuildAndSendE2NodeConfigUpdate(); return ROK; } @@ -1144,10 +1371,12 @@ uint8_t BuildAndSendRicIndication() else { DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n"); +#ifdef DEBUG_ASN_PRINT for(int i=0; i< encBufSize; i++) { printf("%x",encBuf[i]); } +#endif } if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK) @@ -1213,6 +1442,160 @@ uint8_t SendE2APMsg(Region region, Pool pool) return ROK; } /* SendE2APMsg */ +/******************************************************************* + * + * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg + * + * @details + * + * Function : FreeE2NodeConfigUpdate + * + * Functionality: + * - freeing the memory allocated for E2nodeConfigurationUpdate + * + * @params[in] E2AP_PDU_t *e2apMsg + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg) +{ + uint8_t arrIdx =0; + E2nodeConfigurationUpdate_t *e2NodeConfigUpdate; + + if(e2apMsg != NULLP) + { + if(e2apMsg->choice.initiatingMessage != NULLP) + { + e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate; + if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP) + { + for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++) + { + DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t)); + } + DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size); + } + DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); + } + DU_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + } +} + +/******************************************************************* + * + * @brief Buld and send the E2 node config update msg + * + * @details + * + * Function : BuildAndSendE2NodeConfigUpdate + * + * Functionality: + * - Buld and send the E2 node config update msg + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ + +uint8_t BuildAndSendE2NodeConfigUpdate() +{ + uint8_t arrIdx = 0,elementCnt = 1; + uint8_t ret = ROK; + E2AP_PDU_t *e2apMsg = NULLP; + E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP; + asn_enc_rval_t encRetVal; /* Encoder return value */ + + DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n"); + do + { + DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t)); + if(e2apMsg == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + break; + } + e2apMsg->present = E2AP_PDU_PR_initiatingMessage; + DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t)); + if(e2apMsg->choice.initiatingMessage == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed"); + DU_FREE(e2apMsg, sizeof(E2AP_PDU_t)); + return RFAILED; + } + e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject; + e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate; + e2apMsg->choice.initiatingMessage->value.present = \ + InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate; + e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate; + + e2NodeConfigUpdate->protocolIEs.list.count = elementCnt; + e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*); + /* Initialize the Ric Indication members */ + DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \ + e2NodeConfigUpdate->protocolIEs.list.size); + if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP) + { + DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed"); + break; + } + + for(arrIdx =0; arrIdxprotocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t)); + if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP) + { + + DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed"); + break; + } + } + + arrIdx = 0; + /* TransactionID */ + e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID; + e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject; + e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID; + e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID; + + + /* 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 E2nodeConfigurationUpdate structure (at %s)\n",\ + encRetVal.failed_type ? encRetVal.failed_type->name : "unknown"); + break; + } + else + { + DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n"); +#ifdef DEBUG_ASN_PRINT + for(int i=0; i< encBufSize; i++) + { + printf("%x",encBuf[i]); + } +#endif + } + if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK) + { + DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed"); + return RFAILED; + } + + break; + }while(true); + + FreeE2NodeConfigUpdate(e2apMsg); + return ret; +} + /******************************************************************* * * @brief Handles received E2AP message and sends back response @@ -1258,11 +1641,13 @@ void E2APMsgHdlr(Buffer *mBuf) return; } +#ifdef DEBUG_ASN_PRINT printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : "); for(i=0; i< recvBufLen; i++) { printf("%x",recvBuf[i]); } +#endif /* Decoding flat buffer into E2AP messsage */ e2apMsg = &e2apasnmsg; @@ -1282,50 +1667,55 @@ void E2APMsgHdlr(Buffer *mBuf) switch(e2apMsg->present) { case E2AP_PDU_PR_successfulOutcome: - { - switch(e2apMsg->choice.successfulOutcome->value.present) - { - case SuccessfulOutcomeE2__value_PR_E2setupResponse: - { - if(!duCb.e2Status) - { - DU_LOG("\nDEBUG --> E2AP : Store E2 setup response Params"); - procE2SetupRsp(e2apMsg); - } - break; - } - default: - { - DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\ - e2apMsg->choice.successfulOutcome->value.present); - return; - } - }/* End of switch(successfulOutcome) */ - free(e2apMsg->choice.successfulOutcome); - break; - } + { + switch(e2apMsg->choice.successfulOutcome->value.present) + { + case SuccessfulOutcomeE2__value_PR_E2setupResponse: + { + if(!duCb.e2Status) + { + DU_LOG("\nDEBUG --> E2AP : Store E2 setup response Params"); + procE2SetupRsp(e2apMsg); + } + break; + } + case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge: + { + DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied"); + break; + } + default: + { + DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\ + e2apMsg->choice.successfulOutcome->value.present); + return; + } + }/* End of switch(successfulOutcome) */ + free(e2apMsg->choice.successfulOutcome); + break; + } case E2AP_PDU_PR_initiatingMessage: - { - switch(e2apMsg->choice.initiatingMessage->value.present) - { - case InitiatingMessageE2__value_PR_RICsubscriptionRequest: - { - if(procRicSubsReq(e2apMsg) == ROK) - { - BuildAndSendRicIndication(); - } - break; - } - default: - { - DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\ - e2apMsg->choice.initiatingMessage->value.present); - return; - } - }/* End of switch(initiatingMessage) */ - free(e2apMsg->choice.initiatingMessage); - break; - } + { + switch(e2apMsg->choice.initiatingMessage->value.present) + { + case InitiatingMessageE2__value_PR_RICsubscriptionRequest: + { + if(procRicSubsReq(e2apMsg) == ROK) + { + BuildAndSendRicIndication(); + } + break; + } + default: + { + DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\ + e2apMsg->choice.initiatingMessage->value.present); + return; + } + }/* End of switch(initiatingMessage) */ + free(e2apMsg->choice.initiatingMessage); + break; + } default: { DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);