[Epic-ID: ODUHIGH-556][Task-ID: ODUHIGH-570] UL Candidate Sel and Res Alloc for Multi UE
[o-du/l2.git] / src / 5gnrsch / sch_crc.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17  *******************************************************************************/
18 #include "common_def.h"
19 #include "tfu.h"
20 #include "lrg.h"
21 #include "tfu.x"
22 #include "lrg.x"
23 #include "du_log.h"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
26 #include "sch.h"
27 #include "sch_tmr.h"
28 #include "sch_utils.h"
29
30 /**
31  * @brief Process CRC indication
32  *
33  * @details
34  *
35  *     Function : SchProcCrcInd
36  *      
37  *      This function process CRC indication
38  *           
39  *  @param[in]  CrcIndInfo *crcInd, recvd crc indication
40  *  @param[in]  Inst schInst, scheduler inst
41  *  @return  
42  *      -# ROK
43  *      -# RFAILED
44  **/
45 uint8_t SchProcCrcInd(Pst *pst, CrcIndInfo *crcInd)
46 {
47    uint16_t crcCnt=0;
48    uint8_t  ueId=0;
49    SchUlHqProcCb *hqP = NULLP;
50    Inst  schInst = pst->dstInst - SCH_INST_START;
51    SchCellCb *cell = schCb[schInst].cells[schInst];
52    
53    while(crcCnt < crcInd->numCrcInd)
54    {
55       GET_UE_ID(crcInd->crnti, ueId);
56       if (cell->raCb[ueId-1].raState == SCH_RA_STATE_MSG3_PENDING)
57       {
58          if (crcInd->crcInd[crcCnt])
59          {
60             /* failure case*/
61             if (cell->raCb[ueId-1].msg3HqProc.tbInfo.txCntr < cell->maxMsg3Tx)
62             {
63                cell->api->SchCrcInd(cell, ueId);
64                cell->raCb[ueId - 1].retxMsg3HqProc = &cell->raCb[ueId - 1].msg3HqProc;
65             }
66             else
67             {
68                /*Release all contexts of the UE RA*/
69             }
70          }
71          else
72          {
73             /* pass case*/
74             /*Dedicated preamble case need to be added*/
75             cell->raCb[ueId-1].raState = SCH_RA_STATE_MSG4_PENDING;
76             /*HARQ init part is in ADD UE CONFIG now, could be moved here*/
77          }         
78       }
79       else
80       {
81          if (cell->ueCb[ueId-1].hqUlmap[crcInd->timingInfo.slot]->hqList.count == 0)
82          {
83             crcCnt++;
84             continue;
85          }
86          if (cell->ueCb[ueId-1].hqUlmap[crcInd->timingInfo.slot]->hqList.first == 0)
87          {
88             DU_LOG("\nERROR  --> SCH: NULL harq stored in ul hq map at slot %d ue id %d\n",\
89                                crcInd->timingInfo.slot, ueId);
90             crcCnt++;
91             continue;
92          }
93          hqP = (SchUlHqProcCb*) cell->ueCb[ueId-1].hqUlmap[crcInd->timingInfo.slot]->hqList.first->node;
94          if(hqP == NULLP)
95          {
96             crcCnt++;
97             continue;
98          }
99          else
100          {
101             if (crcInd->crcInd[crcCnt])
102             {             
103                /* failure case*/
104                schUlHqProcessNack(hqP);
105             }
106             else
107             {
108                /* pass case*/
109                schUlHqProcessAck(hqP);
110             }
111          }
112          cmLListDelFrm(&(cell->ueCb[ueId-1].hqUlmap[crcInd->timingInfo.slot]->hqList), &hqP->ulSlotLnk);
113       }
114       crcCnt++;
115    }
116    return ROK;
117 }
118 /**********************************************************************
119   End of file
120  **********************************************************************/