[Task-ID: ODUHIGH-455] Changes to support new L1 20.11
[o-du/l2.git] / src / 5gnrmac / mac_ue_mgr.c
index 0ee59e2..cbabb28 100644 (file)
@@ -1539,7 +1539,7 @@ uint8_t fillLogicalChannelCfg(SchLcCfg *schLcCfg, LcCfg *macLcCfg)
       {
          if(!schLcCfg->snssai)
          {
-            MAC_ALLOC(schLcCfg->snssai, sizeof(SchSnssai));
+            MAC_ALLOC(schLcCfg->snssai, sizeof(Snssai));
             if(!schLcCfg->snssai)
             {
                DU_LOG("\nERROR  -->  MAC : Memory alloc failed at snssai at fillLogicalChannelCfg()");
@@ -1616,8 +1616,9 @@ uint8_t fillSchUeCfg(Pst *pst, SchUeCfg *schUeCfg, MacUeCfg *ueCfg)
    uint8_t ret = ROK;
 
    schUeCfg->cellId = ueCfg->cellId;
+   schUeCfg->ueId = ueCfg->ueId;
    schUeCfg->crnti = ueCfg->crnti;
-
+   schUeCfg->dataTransmissionInfo = ueCfg->transmissionAction;
    /* Copy MAC cell group config */
    if(ueCfg->macCellGrpCfgPres == true)
    {
@@ -1985,7 +1986,7 @@ uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
 {
    uint8_t ret = ROK;
 
-   ueCb->ueIdx = ueCfg->ueIdx;
+   ueCb->ueId = ueCfg->ueId;
    ueCb->crnti = ueCfg->crnti;
    ueCb->cellCb = macCb.macCell[cellIdx];
    if(ueCfg->spCellCfgPres)
@@ -1993,7 +1994,7 @@ uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
       ueCb->dlInfo.dlHarqEnt.numHarqProcs = \
       ueCfg->spCellCfg.servCellCfg.pdschServCellCfg.numHarqProcForPdsch; 
    }
-   ueCb->state = UE_STATE_ACTIVE;
+
    /*TODO: To check the bsr value during implementation */
    if(ueCfg->macCellGrpCfgPres)
    {
@@ -2006,6 +2007,8 @@ uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
    {
       DU_LOG("\nERROR  -->  MAC: Failed while filing MAC LC List at fillMacUeCb()");
    }
+   ueCb->transmissionAction = ueCfg->transmissionAction;
+
    return ret;
 }
 
@@ -2027,15 +2030,15 @@ uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
 
 uint8_t updateMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
 {
-   uint8_t ueIdx;
    /* Copy RA Cb */
-   for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
+   if(macCb.macCell[cellIdx]->macRaCb[ueCb->ueId-1].crnti == ueCb->crnti)
    {
-      if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
-      {
-         ueCb->raCb = &macCb.macCell[cellIdx]->macRaCb[ueIdx];
-         break;
-      }
+      ueCb->raCb = &macCb.macCell[cellIdx]->macRaCb[ueCb->ueId-1];
+   }
+   else
+   {
+      DU_LOG("\nERROR  -->  MAC : No RA CB found for UE ID [%d]", ueCb->ueId);
+      return RFAILED;
    }
    return ROK;
 }
@@ -2057,27 +2060,21 @@ uint8_t updateMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
 
 void deleteMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
 {
-   uint8_t ueIdx;
+   uint8_t tbIdx;
+   MacRaCbInfo *raCb = ueCb->raCb;
+   DlHarqProcCb *hqProcCb;
 
-   for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
+   if(raCb && (raCb->crnti == ueCb->crnti))
    {
-      if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
+      hqProcCb = &raCb->msg4HqInfo;
+      MAC_FREE(raCb->msg4Pdu, raCb->msg4PduLen);
+      for(tbIdx = 0; tbIdx < raCb->msg4HqInfo.numTb; tbIdx++)
       {
-         if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
-        {
-          MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
-                    macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
-         }
-        if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
-        {
-            MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
-                      macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
-         }
-        memset(&macCb.macCell[cellIdx]->macRaCb[ueIdx], 0, sizeof(MacRaCbInfo));
-         break;
+         MAC_FREE(raCb->msg4HqInfo.tbInfo[tbIdx].tb, \
+               raCb->msg4HqInfo.tbInfo[tbIdx].tbSize - TX_PAYLOAD_HDR_LEN);
       }
+      memset(raCb, 0, sizeof(MacRaCbInfo));
    }
-                 
 }
 
 /*******************************************************************
@@ -2097,9 +2094,10 @@ void deleteMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
  * ****************************************************************/
 uint8_t createUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
 {
-   uint8_t ret =ROK;
+   uint8_t ret = ROK;
+   uint8_t hqProcIdx = 0;
 
-   if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti)\
+   if((ueCb->ueId == ueCfg->ueId) && (ueCb->crnti == ueCfg->crnti)\
       &&(ueCb->state == UE_STATE_ACTIVE))
    {
       DU_LOG("\nERROR  -->  MAC : CRNTI %d already configured ", ueCfg->crnti);
@@ -2116,13 +2114,27 @@ uint8_t createUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
       }
       else
       {
-         macCb.macCell[cellIdx]->numActvUe++;
-         updateMacRaCb(cellIdx, ueCb);
-        return ROK;
-      }
+         /* Initialize all DL HARQ PROC ID to MAX NUM OF HARQ PROC */
+         for(hqProcIdx = 0; hqProcIdx <  MAX_NUM_HARQ_PROC; hqProcIdx++)
+         {
+            ueCb->dlInfo.dlHarqEnt.harqProcCb[hqProcIdx].procId = MAX_NUM_HARQ_PROC;
+         }
 
-   }
+         /* If UE has not requested for RACH yet, it means UE context is created for a
+          * UE in handover */
+         if(macCb.macCell[cellIdx]->macRaCb[ueCb->ueId-1].crnti == ueCb->crnti)
+         {
+            ueCb->state = UE_STATE_ACTIVE;
+            macCb.macCell[cellIdx]->numActvUe++;
+            updateMacRaCb(cellIdx, ueCb);
+         }
+         else
+            ueCb->state = UE_HANDIN_IN_PROGRESS;
 
+         return ROK;
+      }
+   }
+   return ROK;
 }
 
 /*******************************************************************
@@ -2144,8 +2156,8 @@ uint8_t modifyUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
 {
    uint8_t ret = ROK;
 
-   if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti)\
-      &&(ueCb->state == UE_STATE_ACTIVE))
+   if((ueCb->ueId == ueCfg->ueId) && (ueCb->crnti == ueCfg->crnti)\
+         &&(ueCb->state == UE_STATE_ACTIVE))
    {
       DU_LOG("\nINFO  -->  MAC : Modifying Ue config Req for CRNTI %d ", ueCfg->crnti);
       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
@@ -2156,8 +2168,7 @@ uint8_t modifyUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
       }
       else
       {
-         deleteMacRaCb(cellIdx, ueCb);
-        return ROK;
+         return ROK;
       }
    }
    return RFAILED;
@@ -2204,21 +2215,28 @@ uint8_t procMacUeCfgData(Pst *pst, MacUeCfg *ueCfg)
    }
 
    /* Check if UE already configured */
-   ueCb = &macCb.macCell[cellIdx]->ueCb[ueCfg->ueIdx -1];
+   ueCb = &macCb.macCell[cellIdx]->ueCb[ueCfg->ueId -1];
+
    switch(pst->event)
    {
       case EVENT_UE_CONFIG_RSP_TO_MAC:
-        ret = createUeCb(cellIdx, ueCb, ueCfg);
-        if(ret != ROK)
-            DU_LOG("\nERROR  -->  MAC: AddUeConfigReq for cellIdx :%d failed in procMacUeCfgData()", cellIdx);
-        break;
+         {
+            ret = createUeCb(cellIdx, ueCb, ueCfg);
+            if(ret != ROK)
+               DU_LOG("\nERROR  -->  MAC: AddUeConfigReq for cellIdx :%d failed in procMacUeCfgData()", cellIdx);
+            break;
+         }
+
       case EVENT_UE_RECONFIG_RSP_TO_MAC:
-        ret = modifyUeCb(cellIdx, ueCb, ueCfg);
-        if(ret != ROK)
-            DU_LOG("\nERROR  -->  MAC: ModifyUeConfigReq for cellIdx :%d failed at procMacUeCfgData()", cellIdx);
-        break;
+         {
+            ret = modifyUeCb(cellIdx, ueCb, ueCfg);
+            if(ret != ROK)
+               DU_LOG("\nERROR  -->  MAC: ModifyUeConfigReq for cellIdx :%d failed at procMacUeCfgData()", cellIdx);
+            break;
+         }
+
       default:
-        break;
+         break;
    }
 
    return ret;
@@ -2253,7 +2271,7 @@ uint8_t copyToTmpData(MacUeCfg *ueCfg)
    }
    memcpy(tmpData, ueCfg, sizeof(MacUeCfg));
    GET_CELL_IDX(ueCfg->cellId, cellIdx);
-   macCb.macCell[cellIdx]->ueCfgTmpData[ueCfg->ueIdx-1] = tmpData;
+   macCb.macCell[cellIdx]->ueCfgTmpData[ueCfg->ueId-1] = tmpData;
    return ROK;
 }
 
@@ -2282,25 +2300,32 @@ uint8_t MacProcUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
 
    if(ueCfg)
    {
+      /* If CRNTI = 0, MAC must allot a CRNTI to this UE. This scenario hits in
+       * case of UE in handover */
+      if(ueCfg->crnti == 0)
+      {
+         GET_CRNTI(ueCfg->crnti, ueCfg->ueId);
+      }
+
       /*Storing received ueCfg in ueCfgTmpData */
       ret = copyToTmpData(ueCfg);
       if(ret == ROK)
       {
          /*Sending Cfg Req to SCH */
-        ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
-        if(ret != ROK)
-           DU_LOG("\nERROR  -->  MAC : Failed to fill Sch Ue Cfg at MacProcUeCreateReq()");
-        else
-        {
+         ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
+         if(ret != ROK)
+            DU_LOG("\nERROR  -->  MAC : Failed to fill Sch Ue Cfg at MacProcUeCreateReq()");
+         else
+         {
             /* Fill event and send UE create request to SCH */
             ret = sendUeReqToSch(pst, &schUeCfg);
-           if(ret != ROK)
-              DU_LOG("\nERROR  -->  MAC : Failed to send UE Create request to SCH");
-        }
+            if(ret != ROK)
+               DU_LOG("\nERROR  -->  MAC : Failed to send UE Create request to SCH");
+         }
       }
       else 
       {
-        DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE CFG ");
+         DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE CFG ");
       }
    }
    else
@@ -2345,7 +2370,7 @@ uint8_t MacSendUeCreateRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
    /* Filling UE Config response */
    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
    cfgRsp->cellId = schCfgRsp->cellId;
-   cfgRsp->ueIdx = schCfgRsp->ueIdx;
+   cfgRsp->ueId = schCfgRsp->ueId;
    cfgRsp->result = result;
 
    /* Fill Post structure and send UE Create response*/
@@ -2385,7 +2410,7 @@ uint8_t MacSendUeReconfigRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
    /* Filling UE Config response */
    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
    cfgRsp->cellId = schCfgRsp->cellId;
-   cfgRsp->ueIdx = schCfgRsp->ueIdx;
+   cfgRsp->ueId = schCfgRsp->ueId;
    cfgRsp->result = result;
 
    /* Fill Post structure and send UE Create response*/
@@ -2405,19 +2430,19 @@ uint8_t MacSendUeReconfigRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
  *    Functionality:
  *      Function to return Mac Ue Cfg pointer
  *
- * @params[in] cellIdx, ueIdx
+ * @params[in] cellIdx, ueId
  *
  * @return MacUeCfg pointer - success
  *         NULLP - failure
  *
  * ****************************************************************/
 
-MacUeCfg *getMacUeCfg(uint16_t cellIdx, uint8_t ueIdx)
+MacUeCfg *getMacUeCfg(uint16_t cellIdx, uint8_t ueId)
 {
    MacUeCfg *ueCfg = NULLP;
    if(macCb.macCell[cellIdx])
    {
-      ueCfg = macCb.macCell[cellIdx]->ueCfgTmpData[ueIdx-1];
+      ueCfg = macCb.macCell[cellIdx]->ueCfgTmpData[ueId-1];
    }
    else
    {
@@ -2467,7 +2492,7 @@ uint8_t MacProcSchUeCfgRsp(Pst *pst, SchUeCfgRsp *schCfgRsp)
 #endif
    
    GET_CELL_IDX(schCfgRsp->cellId, cellIdx);
-   ueCfg = getMacUeCfg(cellIdx, schCfgRsp->ueIdx);
+   ueCfg = getMacUeCfg(cellIdx, schCfgRsp->ueId);
    if(ueCfg == NULLP)
    {
       DU_LOG("\nERROR  -->  MAC : Failed to find the Mac Ue Cfg for event [%d] in MacProcSchUeCfgRsp()", pst->event);
@@ -2615,7 +2640,7 @@ uint8_t MacSendUeDeleteRsp(uint16_t cellId, uint16_t crnti, UeDeleteStatus resul
 
    /* Filling UE delete response */
    deleteRsp->cellId = cellId;
-   GET_UE_IDX(crnti,deleteRsp->ueId);
+   GET_UE_ID(crnti, deleteRsp->ueId);
    deleteRsp->result = result;
 
    /* Fill Post structure and send UE delete response*/
@@ -2683,10 +2708,10 @@ void deletePucchResourcesCfg(PucchResrcCfg *resrcCfg)
 *
 * @details
 *
-*    Function : MacProcSchUeCfgRsp
+*    Function : MacProcSchUeDeleteRsp 
 *
 *    Functionality:
-*      Processes UE create delete from scheduler
+*      Processes UE delete from scheduler
 *
 * @params[in] Pst : Post structure
 *             schUeDelRsp : Scheduler UE delete respons
@@ -2697,10 +2722,11 @@ void deletePucchResourcesCfg(PucchResrcCfg *resrcCfg)
 
 uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
 {
-   uint8_t ueIdx =0, lcIdx = 0, isCrntiValid = 0;
+   uint8_t ueId =0, isCrntiValid = 0, tbIdx =0, idx=0;
    uint16_t cellIdx=0;
    uint8_t ret = RFAILED;
    UeDeleteStatus result;
+   DlHarqEnt  *dlHarqEnt;
 
 #ifdef CALL_FLOW_DEBUG_LOG
    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_DELETE_RSP_TO_MAC\n");
@@ -2719,35 +2745,47 @@ uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
             {
                /*C-RNTI value is out of Acceptable range*/
                DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): Invalid crnti[%d] ",schUeDelRsp->crnti);
-               result = UEIDX_INVALID;
+               result = UEID_INVALID;
             }
             else
             {
-               GET_UE_IDX(schUeDelRsp->crnti, ueIdx);
-               if(macCb.macCell[cellIdx]->ueCb[ueIdx -1].crnti == schUeDelRsp->crnti)
+               GET_UE_ID(schUeDelRsp->crnti, ueId);
+               if(macCb.macCell[cellIdx]->ueCb[ueId -1].crnti == schUeDelRsp->crnti)
                {
 
                   /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
 #if 0
                   /*Looping around LCs to free S-NSSAI memory*/
-                  for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueIdx -1].ulInfo.numUlLc); lcIdx++)
+                  for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueId -1].ulInfo.numUlLc); lcIdx++)
                   {
-                     MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueIdx -1].ulInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
+                     MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueId -1].ulInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
                   }
-                  for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueIdx -1].dlInfo.numDlLc); lcIdx++)
+                  for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.numDlLc); lcIdx++)
                   {
-                     MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueIdx -1].dlInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
+                     MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
                   }
 #endif
-                  memset(&macCb.macCell[cellIdx]->ueCb[ueIdx -1], 0, sizeof(MacUeCb));
+                  dlHarqEnt = &macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.dlHarqEnt;
+                  for(idx =0 ; idx<MAX_NUM_HARQ_PROC; idx++)
+                  {
+                     tbIdx = 0;
+                     while(dlHarqEnt->harqProcCb[idx].numTb)
+                     {
+
+                        MAC_FREE(dlHarqEnt->harqProcCb[idx].tbInfo[tbIdx].tb, dlHarqEnt->harqProcCb[idx].tbInfo[tbIdx].tbSize);
+                        dlHarqEnt->harqProcCb[idx].numTb--;
+                        tbIdx++;
+                     }
+                  }
+                  memset(&macCb.macCell[cellIdx]->ueCb[ueId -1], 0, sizeof(MacUeCb));
                   macCb.macCell[cellIdx]->numActvUe--;
-                  result = SUCCESS;
+                  result = DEL_SUCCESSFUL;
                   ret = ROK;
                }
                else
                {
                   DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): crnti[%d] does not exist ",schUeDelRsp->crnti);
-                  result = UEIDX_INVALID;
+                  result = UEID_INVALID;
                }
             }
          }
@@ -2759,7 +2797,7 @@ uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
       }
       else
       {
-         result = (schUeDelRsp->cause == INVALID_CELLID) ? CELLID_INVALID : UEIDX_INVALID;
+         result = (schUeDelRsp->cause == INVALID_CELLID) ? CELLID_INVALID : UEID_INVALID;
       }
       if(MacSendUeDeleteRsp(schUeDelRsp->cellId, schUeDelRsp->crnti, result) != ROK)
       {
@@ -2832,7 +2870,7 @@ uint8_t MacProcUeDeleteReq(Pst *pst, MacUeDelete *ueDelete)
 {
    uint8_t ret = ROK;
    uint8_t cellIdx=0;
-   UeDeleteStatus result=SUCCESS;
+   UeDeleteStatus result=DEL_SUCCESSFUL;
    MacUeCb  *ueCb = NULLP;
    MacCellCb *cellCb = NULLP;
 
@@ -2857,16 +2895,16 @@ uint8_t MacProcUeDeleteReq(Pst *pst, MacUeDelete *ueDelete)
          else
          {
             DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): CRNTI is not matched");
-            result = UEIDX_INVALID;
+            result = UEID_INVALID;
          }
       }
       else
       {
-         DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to find the MacUeCb of UeIdx = %d",ueDelete->ueId);
+         DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to find the MacUeCb of UeId = %d",ueDelete->ueId);
          result = CELLID_INVALID;
       }
 
-      if(result != SUCCESS)
+      if(result != DEL_SUCCESSFUL)
       {
          MacSendUeDeleteRsp(ueDelete->cellId, ueDelete->crnti, result);
          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));