[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-425] Fixes in the CU stub for memory-related...
[o-du/l2.git] / src / cu_stub / cu_f1ap_msg_hdl.c
index 07fdaa7..e5bbb6e 100644 (file)
 /* MACRO Define for PUSCH Configuration */
 #define PUSCH_K2_CFG1  1
 #define PUSCH_K2_CFG2  2
+#define PUSCH_START_SYMBOL 3
 
 #define PUSCH_MSG3_DELTA_PREAMBLE 0
 #define PUSCH_P0_NOMINAL_WITH_GRANT -70
@@ -1827,25 +1828,28 @@ uint8_t setDlRRCMsgType(CuUeCb *ueCb)
    switch(ueCb->f1apMsgDb.dlRrcMsgCount)
    {
       case RRC_SETUP:
-        rrcMsgType = RRC_SETUP;
-        break;
+         rrcMsgType = RRC_SETUP;
+         break;
       case REGISTRATION_ACCEPT:
-        rrcMsgType = REGISTRATION_ACCEPT;
-        break;
+         rrcMsgType = REGISTRATION_ACCEPT;
+         break;
       case UE_CONTEXT_SETUP_REQ:
-        rrcMsgType = UE_CONTEXT_SETUP_REQ;
-        break;
+         rrcMsgType = UE_CONTEXT_SETUP_REQ;
+         break;
       case SECURITY_MODE_COMPLETE:
-        rrcMsgType = SECURITY_MODE_COMPLETE;
-        break;
+         rrcMsgType = SECURITY_MODE_COMPLETE;
+         break;
       case RRC_RECONFIG:
-        rrcMsgType = RRC_RECONFIG;
-        break;
+         rrcMsgType = RRC_RECONFIG;
+         break;
+      case RRC_RECONFIG_COMPLETE:
+         rrcMsgType = RRC_RECONFIG_COMPLETE;
+         break;
       case UE_CONTEXT_MOD_REQ:
-        rrcMsgType = UE_CONTEXT_MOD_REQ;
-        break;
+         rrcMsgType = UE_CONTEXT_MOD_REQ;
+         break;
       default:
-        break;
+         break;
    }
    return rrcMsgType;   
 }
@@ -1869,7 +1873,7 @@ uint8_t setDlRRCMsgType(CuUeCb *ueCb)
 
 uint8_t procInitULRRCMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
 {
-   uint8_t idx, rrcMsgType, gnbDuUeF1apId;
+   uint8_t idx,cellIdx=0, duIdx=0, rrcMsgType, gnbDuUeF1apId;
    uint8_t ret =ROK;
    uint32_t nrCellId, crnti;
    DuDb     *duDb;
@@ -1878,8 +1882,8 @@ uint8_t procInitULRRCMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
 
    DU_LOG("\nINFO   -->  F1AP : filling the required values in DB in procInitULRRCMsg");
-
-   duDb = getDuDb(duId);
+   
+   SEARCH_DU_DB(duIdx, duId, duDb); 
    initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
 
    for(idx=0; idx < initULRRCMsg->protocolIEs.list.count; idx++)
@@ -1893,7 +1897,7 @@ uint8_t procInitULRRCMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
          case ProtocolIE_ID_id_NRCGI:
             nrCellId = initULRRCMsg->protocolIEs.list.array[idx]->value.choice.NRCGI.nRCellIdentity.buf[4] >>
                initULRRCMsg->protocolIEs.list.array[idx]->value.choice.NRCGI.nRCellIdentity.bits_unused;
-            cellCb = getCellCb(duDb, nrCellId);
+            SEARCH_CELL_DB(cellIdx, duDb, nrCellId, cellCb);
             if(cellCb == NULLP)
                return RFAILED;
             break;
@@ -1908,6 +1912,7 @@ uint8_t procInitULRRCMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
                ueCb->crnti = crnti;
                ueCb->gnbDuUeF1apId = gnbDuUeF1apId;
                ueCb->gnbCuUeF1apId = ++cuCb.gnbCuUeF1apIdGenerator;
+               ueCb->state = UE_ATTACH_IN_PROGRESS;
                (duDb->numUe)++;
 
                cellCb->ueCb[cellCb->numUe] = ueCb;
@@ -4055,8 +4060,7 @@ uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *reso
    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
       = SRS_CYCLIC_SHIFT_N2;
 
-   resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
-                                                                     0;
+   resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = PUSCH_START_SYMBOL;
    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
                                                                     SRS_Resource__resourceMapping__nrofSymbols_n1;
    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
@@ -7040,12 +7044,12 @@ uint8_t procDrbSetupList(DRBs_Setup_List_t *drbSetupList)
  * ****************************************************************/
 uint8_t procUeContextSetupResponse(uint32_t duId, F1AP_PDU_t *f1apMsg)
 {
-   uint8_t idx, duUeF1apId;
+   uint8_t duIdx=0, idx, duUeF1apId;
    DuDb *duDb;
    CuUeCb *ueCb;
    UEContextSetupResponse_t *ueCtxtSetupRsp = NULLP;
 
-   duDb = getDuDb(duId);
+   SEARCH_DU_DB(duIdx, duId, duDb);
    ueCtxtSetupRsp = &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
    
    for(idx=0; idx < ueCtxtSetupRsp->protocolIEs.list.count; idx++)
@@ -7089,7 +7093,7 @@ uint8_t procUeContextSetupResponse(uint32_t duId, F1AP_PDU_t *f1apMsg)
 
 uint8_t procUlRrcMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
 {
-   uint8_t idx, ret, srbId, rrcMsgType;
+   uint8_t idx, ret, srbId, rrcMsgType, duIdx=0;
    uint8_t cuUeF1apId, duUeF1apId;
    uint8_t *rrcContainer = NULLP;
    uint16_t rrcContLen;
@@ -7098,7 +7102,7 @@ uint8_t procUlRrcMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
    ULRRCMessageTransfer_t *ulRrcMsg = NULLP;
 
    ret = ROK;
-   duDb = getDuDb(duId);
+   SEARCH_DU_DB(duIdx, duId, duDb);
    ulRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
 
    for(idx=0; idx < ulRrcMsg->protocolIEs.list.count; idx++)
@@ -7164,10 +7168,16 @@ uint8_t procUlRrcMsg(uint32_t duId, F1AP_PDU_t *f1apMsg)
             BuildAndSendDLRRCMessageTransfer(duId, ueCb, srbId, rrcMsgType);
          }
       }
-      if(rrcMsgType == UE_CONTEXT_MOD_REQ)
+      if(rrcMsgType == RRC_RECONFIG_COMPLETE)
       {
-         DU_LOG("\nINFO  -->  F1AP: Sending UE Context Modification Request");
-         BuildAndSendUeContextModificationReq(duId, ueCb);
+         ueCb->state = UE_ACTIVE;
+         ueCb->f1apMsgDb.dlRrcMsgCount++;
+         rrcMsgType = setDlRRCMsgType(ueCb);
+         if(rrcMsgType == UE_CONTEXT_MOD_REQ)
+         {
+            DU_LOG("\nINFO  -->  F1AP: Sending UE Context Modification Request");
+            BuildAndSendUeContextModificationReq(duId, ueCb, MODIFY_UE);
+         }
       }
    }
    return ret;
@@ -8222,7 +8232,7 @@ void FreeUeContextModicationRequest(F1AP_PDU_t *f1apMsg)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t BuildAndSendUeContextModificationReq(uint32_t duId, void *cuUeCb)
+uint8_t BuildAndSendUeContextModificationReq(uint32_t duId, void *cuUeCb, UeCtxtModAction action)
 {
    uint8_t    ieIdx = 0;
    uint8_t    elementCnt = 0;
@@ -8257,7 +8267,10 @@ uint8_t BuildAndSendUeContextModificationReq(uint32_t duId, void *cuUeCb)
 
       ueContextModifyReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
 
-      elementCnt = 4;
+      if(action == MODIFY_UE)
+         elementCnt = 4;
+      else if(action == QUERY_CONFIG)
+         elementCnt = 3;
       ueContextModifyReq->protocolIEs.list.count = elementCnt;
       ueContextModifyReq->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationRequest_t *);
 
@@ -8279,7 +8292,6 @@ uint8_t BuildAndSendUeContextModificationReq(uint32_t duId, void *cuUeCb)
          }
       }
 
-
       ieIdx=0;
       ueContextModifyReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
       ueContextModifyReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
@@ -8294,30 +8306,43 @@ uint8_t BuildAndSendUeContextModificationReq(uint32_t duId, void *cuUeCb)
                                                                        UEContextModificationRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
       ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
 
-      /* DRB to be setup list */
-      ieIdx++;
-      ueContextModifyReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_ToBeSetupMod_List;
-      ueContextModifyReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
-      ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present =\
-                                                                        UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List;
-      ret = BuildDrbToBeSetupList(ueCb->gnbCuUeF1apId, &(ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
-               value.choice.DRBs_ToBeSetupMod_List));
-
-      /* DRB to be modified list */
-      ieIdx++;
-      ueContextModifyReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_ToBeModified_List;
-      ueContextModifyReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
-      ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present =\
-                                                                        UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List;
-      ret = BuildDrbToBeModifiedList(ueCb->gnbCuUeF1apId, &(ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
-               value.choice.DRBs_ToBeModified_List));
-
-      /* TODO: DRB to be release list */
-
-      if(ret != ROK)
+      if(action == MODIFY_UE)
+      {
+         /* DRB to be setup list */
+         ieIdx++;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_ToBeSetupMod_List;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present =\
+                                                                           UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List;
+         ret = BuildDrbToBeSetupList(ueCb->gnbCuUeF1apId, &(ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
+                  value.choice.DRBs_ToBeSetupMod_List));
+
+         /* DRB to be modified list */
+         ieIdx++;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_ToBeModified_List;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present =\
+                                                                           UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List;
+         ret = BuildDrbToBeModifiedList(ueCb->gnbCuUeF1apId, &(ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
+                  value.choice.DRBs_ToBeModified_List));
+
+         /* TODO: DRB to be release list */
+
+         if(ret != ROK)
+         {
+            break;
+         }
+      }
+      else if(action == QUERY_CONFIG)
       {
-         break;
+         ieIdx++;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_GNB_DUConfigurationQuery;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present = \
+            UEContextModificationRequestIEs__value_PR_GNB_DUConfigurationQuery;
+         ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DUConfigurationQuery = GNB_DUConfigurationQuery_true;
       }
+
       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
 
       /* Encode the F1SetupRequest type as APER */
@@ -8618,8 +8643,8 @@ uint8_t procUeContextReleaseReq(uint32_t duId, F1AP_PDU_t *f1apMsg)
 uint8_t procGnbDuUpdate(uint32_t duId, F1AP_PDU_t *f1apMsg)
 {
    bool cellToBeDelete = false;
-   uint8_t ieIdx = 0, ueIdx = 0;
-   uint16_t cellId;
+   uint8_t ieIdx = 0, ueIdx = 0, duIdx = 0, cellIdx=0;
+   uint16_t nrCellId;
    DuDb *duDb;
    CuCellCb *cellCb;
    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
@@ -8638,7 +8663,7 @@ uint8_t procGnbDuUpdate(uint32_t duId, F1AP_PDU_t *f1apMsg)
                struct Served_Cells_To_Delete_ItemIEs *deleteItemIe = \
                   (struct Served_Cells_To_Delete_ItemIEs *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
                   Served_Cells_To_Delete_List.list.array[0];
-               cellId = deleteItemIe->value.choice.Served_Cells_To_Delete_Item.oldNRCGI.nRCellIdentity.buf[4] >>\
+               nrCellId = deleteItemIe->value.choice.Served_Cells_To_Delete_Item.oldNRCGI.nRCellIdentity.buf[4] >>\
                   deleteItemIe->value.choice.Served_Cells_To_Delete_Item.oldNRCGI.nRCellIdentity.bits_unused;
                cellToBeDelete = true;
                break;
@@ -8668,8 +8693,8 @@ uint8_t procGnbDuUpdate(uint32_t duId, F1AP_PDU_t *f1apMsg)
 #endif
    if(cellToBeDelete == true) 
    {
-      duDb = getDuDb(duId);
-      cellCb = getCellCb(duDb, cellId);
+      SEARCH_DU_DB(duIdx, duId, duDb);
+      SEARCH_CELL_DB(cellIdx, duDb, nrCellId, cellCb);
       for(ueIdx = 0; ueIdx < cellCb->numUe; ueIdx++)
       {
          CU_FREE(cellCb->ueCb[ueIdx]->f1apMsgDb.duToCuContainer.buf, cellCb->ueCb[ueIdx]->f1apMsgDb.duToCuContainer.size);
@@ -8852,10 +8877,14 @@ uint8_t procServedCellPlmnList(ServedPLMNs_List_t *srvPlmn)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t procUeContextModificationResponse(F1AP_PDU_t *f1apMsg)
+uint8_t procUeContextModificationResponse(uint32_t duId, F1AP_PDU_t *f1apMsg)
 {
-   uint8_t idx, duUeF1apId;
-       UEContextModificationResponse_t *ueCtxtModRsp = NULLP;
+   uint8_t idx=0, duIdx=0, duUeF1apId;
+   DuDb *duDb;
+   CuUeCb *ueCb;
+   UEContextModificationResponse_t *ueCtxtModRsp = NULLP;
+
+   SEARCH_DU_DB(duIdx, duId, duDb);
    ueCtxtModRsp = &f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
    
    for(idx=0; idx < ueCtxtModRsp->protocolIEs.list.count; idx++)
@@ -8865,6 +8894,13 @@ uint8_t procUeContextModificationResponse(F1AP_PDU_t *f1apMsg)
           case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
              {
                 duUeF1apId = ueCtxtModRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
+                ueCb = &duDb->ueCb[duUeF1apId-1];
+                if(ueCb->state == UE_HANDOVER_IN_PROGRESS)
+                {
+                   /* TODO : Next procedure i.e. UE context setup request to
+                    * target DU should be triggerred here */
+                   return ROK;
+                }
                 break;
              }
           case ProtocolIE_ID_id_DRBs_SetupMod_List:
@@ -8876,6 +8912,7 @@ uint8_t procUeContextModificationResponse(F1AP_PDU_t *f1apMsg)
              }
       }
    }
+   
    return ROK;
 }
 
@@ -8898,7 +8935,7 @@ uint8_t procUeContextModificationResponse(F1AP_PDU_t *f1apMsg)
 void procF1SetupReq(uint32_t *destDuId, F1AP_PDU_t *f1apMsg)
 {
    uint8_t ieIdx = 0, plmnidx=0, duIdx = 0, ret=ROK, cellIdx = 0;
-   uint32_t duId, cellId;
+   uint32_t duId = 0, nrCellId = 0;
    DuDb     *duDb = NULLP;
    CuCellCb *cellCb = NULLP;
    BIT_STRING_t nrcellIdentity;
@@ -8914,7 +8951,7 @@ void procF1SetupReq(uint32_t *destDuId, F1AP_PDU_t *f1apMsg)
          case ProtocolIE_ID_id_gNB_DU_ID:
            {
               duId = f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0];
-              duDb = getDuDb(duId);
+              SEARCH_DU_DB(duIdx, duId, duDb); 
               if(duDb == NULLP)
               {
                  duDb = &cuCb.duInfo[cuCb.numDu];
@@ -8949,13 +8986,13 @@ void procF1SetupReq(uint32_t *destDuId, F1AP_PDU_t *f1apMsg)
                               ret = procServedCellPlmnList(&srvCellItem->served_Cell_Information.servedPLMNs);
                               memcpy(&nrcellIdentity, &srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity, sizeof(BIT_STRING_t));
 
-                              cellId = nrcellIdentity.buf[4] >> nrcellIdentity.bits_unused;
-                              cellCb = getCellCb(duDb, cellId);
+                              nrCellId = nrcellIdentity.buf[4] >> nrcellIdentity.bits_unused;
+                              SEARCH_CELL_DB(cellIdx, duDb, nrCellId, cellCb);
                               if(cellCb == NULLP)
                               {
                                  cellCb = &duDb->cellCb[duDb->numCells];
                                  memset(cellCb, 0, sizeof(CuCellCb));
-                                 cellCb->nrCellId = cellId;
+                                 cellCb->nrCellId = nrCellId;
                                  duDb->numCells++;
                               }
                            }
@@ -9120,7 +9157,7 @@ void F1APMsgHdlr(uint32_t *duId, Buffer *mBuf)
                case SuccessfulOutcome__value_PR_UEContextModificationResponse:
                   {
                      DU_LOG("\nINFO  -->  F1AP : UE Context Modification Response received");
-                     procUeContextModificationResponse(f1apMsg);
+                     procUeContextModificationResponse(*duId, f1apMsg);
                      break;
                   }
                case SuccessfulOutcome__value_PR_UEContextReleaseComplete: