Merge "Removed ANSI from multiple folder Part - 1 [JIRA ID - ODUHIGH-249]"
[o-du/l2.git] / src / 5gnrmac / rg_rom.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
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point fucntions.
26   
27      File:     rg_rom.c
28   
29 **********************************************************************/
30
31 /** @file rg_rom.c
32 @brief APIs to handle all the primitives invoked on RGU interface.
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=184;
37 static int RLOG_MODULE_ID=4096;
38
39 /* header include files (.h) */
40 #include "common_def.h"
41 #include "rg_env.h"        /* MAC Environment Defines */
42 #include "crg.h"           /* CRG Interface defines */
43 #include "rgu.h"           /* RGU Interface defines */
44 #include "tfu.h"           /* TFU Interface defines */
45 #include "rg_sch_inf.h"           /* RGR Interface defines */
46 #include "lrg.h"           /* LRG Interface defines */
47
48 #include "rg.h"            /* MAC defines */
49 #include "rg_err.h"        /* MAC error defines */
50
51 /* header/extern include files (.x) */
52
53 #include "crg.x"           /* CRG Interface includes */
54 #include "rgu.x"           /* RGU Interface includes */
55 #include "tfu.x"           /* TFU Interface includes */
56 #include "rg_sch_inf.x"    /* SCH Interface includes */
57 #include "rg_prg.x"        /* PRG Interface includes */
58 #include "lrg.x"           /* LRG Interface includes */
59
60 #include "du_app_mac_inf.h"
61 #include "rg.x"            /* MAC includes */
62
63 /* local defines */
64 #define RG_NON_MIMO_IDX 0
65
66 /* local typedefs */
67  
68 S16 RgMacSchBrdcmDedBoUpdtReq ARGS((Inst inst, CmLteCellId cellId, CmLteRnti rnti, CmLteLcId lcId, S32 bo ));
69 static S16 rgROMHndlCcchDatReq     ARGS((RgCellCb *cell,
70                                     RgRguCmnDatReq *datReq, RgErrInfo *err));
71 static S16 rgROMHndlBcchPcchDatReq ARGS((RgCellCb *cell,
72                                     RgRguCmnDatReq *datReq, RgErrInfo *err));
73 static S16 rgROMHndlCcchStaRsp     ARGS((RgCellCb *cell, 
74                                     RgRguCmnStaRsp *staRsp, RgErrInfo *err));
75 static S16 rgROMHndlBcchPcchStaRsp ARGS((RgCellCb *cell, 
76                                     RgRguCmnStaRsp *staRsp, RgErrInfo *err));
77
78 /* ADD Changes for Downlink UE Timing Optimization */
79 #ifdef LTEMAC_DLUE_TMGOPTMZ
80 static S16 rgROMUpdDlSfRemDataCnt ARGS((RgCellCb  *cellCb,
81                                     RgDlSf    *dlSf));
82 S16 rgTOMUtlProcDlSf ARGS(( RgDlSf     *dlSf,
83                                    RgCellCb   *cellCb,
84                                    RgErrInfo  *err));
85 #endif
86
87 /* forward references */
88
89 /**
90  * @brief Handler for dedicated DatReq received on RGU for an UE.
91  *
92  * @details
93  *
94  *     Function : rgROMDedDatReq
95  *     
96  *     This function shall
97  *      -# store the BO reported for the given logical channels.
98  *      -# invoke DL HARQ for further processing.
99  *     
100  *           
101  *  @param[in]  Inst        inst
102  *  @param[in]  RgRguDedDatReq *datReq 
103  *  @return  S16
104  *      -# ROK 
105  *      -# RFAILED 
106  **/
107 S16 rgROMDedDatReq(Inst inst,RgRguDedDatReq *datReq)
108 {
109 #if 0
110    RgCellCb     *cell;
111    RgUeCb       *ue;
112    uint8_t           idx1,idx2;
113    RgDlHqProcCb *hqProc;
114    uint8_t           hqPId;
115    RgErrInfo    err;
116    Pst          schPst;
117    RgInfDedBoRpt boRpt;
118    CmLteTimingInfo timingInfo;
119    RgDlSf       *sf;
120 #if (ERRCLASS & ERRCLS_DEBUG)
121    RgUstaDgn   dgn;      /* Alarm diagnostics structure */
122 #endif
123 /* ADD Changes for Downlink UE Timing Optimization */
124 #ifdef LTEMAC_DLUE_TMGOPTMZ
125    S16 ret;
126 #endif
127    uint32_t idx;
128    //uint8_t  datReqFailCnt = 0;
129
130
131    if (((cell = rgCb[inst].cell) == NULLP) 
132        || (cell->cellId != datReq->cellId))
133    {
134 #if (ERRCLASS & ERRCLS_INT_PAR)
135       /* Handle Cell fetch failure */
136       RGLOGERROR(inst,ERRCLS_INT_PAR,ERG001,(ErrVal)datReq->cellId,
137             "rgROMDedDatReq(): Invalid cell Id");
138 #endif
139       err.errType = RGERR_ROM_DEDDATREQ;
140       err.errCause = RGERR_ROM_INV_CELL_ID;
141       if(cell != NULLP)
142       {
143          /* Update stats */
144          rgUpdtRguDedSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP, datReq);
145       }
146       return RFAILED;
147    }
148
149 /* Add loop here to scan for all UEs in the consolidated DDatReq*/
150    for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
151    {
152
153       timingInfo.slot = (uint8_t)((datReq->datReq[idx].transId >> 8) & 0XFF);
154       timingInfo.sfn = (uint16_t)((datReq->datReq[idx].transId >> 16) & 0xFFFF);
155       sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
156
157       if( (sf->txDone == TRUE) ||
158             (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
159       {
160 #if (ERRCLASS & ERRCLS_DEBUG)
161          /* Transmission is already done for this slot. This is a delayed
162           * datReq. So discard */
163          rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
164          rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
165                LRG_CAUSE_DELAYED_DATREQ, &dgn);
166 #endif
167          err.errType = RGERR_ROM_DEDDATREQ;
168          err.errCause = RGERR_ROM_DELAYED_DATREQ;
169          /* Update stats */
170          rgUpdtRguDedSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP, datReq);
171 #ifdef CA_DBG
172          {
173             uint32_t dbgDelayedDatReqInMac;
174             dbgDelayedDatReqInMac++;
175          }
176 #endif /* CA_DBG */         
177 #ifndef L2_OPTMZ
178          RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
179 #endif
180          continue;
181         // return RFAILED;
182       }
183
184       if ((ue = rgDBMGetUeCb(cell, datReq->datReq[idx].rnti)) == NULLP)
185       {
186 #if (ERRCLASS & ERRCLS_INT_PAR)
187             /* Handle Ue fetch failure */
188             RGLOGERROR(inst,ERRCLS_INT_PAR,ERG002,(ErrVal)datReq->datReq[idx].rnti,
189                   "rgROMDedDatReq(): Invalid ue Id");
190 #endif
191             err.errType = RGERR_ROM_DEDDATREQ;
192             err.errCause = RGERR_ROM_INV_UE_ID;
193             /* Update stats */
194             rgUpdtRguDedSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP, datReq);
195             /* ADD Changes for Downlink UE Timing Optimization */
196 #ifdef LTEMAC_DLUE_TMGOPTMZ
197             /* Trying to send the prev successful PDU's 
198              * if present */
199             ret = rgROMUpdDlSfRemDataCnt(cell, sf);
200             if(ret == RFAILED)
201             {
202                RLOG0(L_INFO, "Dropping due to no ue \n");
203 #ifndef L2_OPTMZ
204                RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
205 #endif
206                /* Return from here as above functions found more datReq than expected*/
207               /* return (ret); */
208             }
209 #endif
210             /* Conitnue for next UE */
211             continue;
212       }
213
214       hqPId = (uint8_t)(datReq->datReq[idx].transId);
215       hqPId = hqPId >> 2;
216       /* get harq process and invoke DHM */
217       rgDHMGetHqProcFrmId(ue, hqPId, &hqProc);
218
219       if (rgDHMHndlDedDatReq(inst,hqProc, &datReq->datReq[idx], sf, &err) == RFAILED)
220       {
221          RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,
222                    "Handling of Data request in DHM failedi RNTI:%d",
223                     datReq->datReq[idx].rnti);
224          err.errType = RGERR_ROM_DEDDATREQ;
225          /* errcause shall be filled in appropriately by DHM */
226          /* Update stats */
227          rgUpdtRguDedSts(inst,ue->rguDlSap,RG_RGU_SDU_DROP, datReq);
228          /* ADD Changes for Downlink UE Timing Optimization */
229 #ifdef LTEMAC_DLUE_TMGOPTMZ
230          /* Trying to send the prev successful PDU's 
231           * if present */
232          ret = rgROMUpdDlSfRemDataCnt(cell, sf);
233          if(ret == RFAILED)
234          {
235          RLOG0(L_INFO, "Dropping due to no failure of remCnt update");
236 #ifndef L2_OPTMZ
237             RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
238 #endif
239             /* Return from here as above functions found more datReq than expected*/
240             //return (ret);
241          }
242 #endif
243          continue;
244       }
245
246       /* Merging the updation of statistics of SDUs with for loop below */ 
247
248       rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
249       schPst.event = 0;
250       boRpt.cellSapId  = cell->schInstMap.cellSapId;
251       boRpt.cellId  = datReq->cellId;
252
253       boRpt.rnti    = datReq->datReq[idx].rnti; 
254
255
256       /* Fill the DStaRsp struct and send it to scheduler */
257       for (idx1 = 0; idx1 < datReq->datReq[idx].nmbOfTbs; idx1++)
258       {
259          for(idx2 = 0; idx2 < datReq->datReq[idx].datReqTb[idx1].nmbLch; idx2++)
260          {
261             /* Updating dedicated SDUs received statistics without 
262                additional function above for optimization */
263             ue->rguDlSap->sapSts.numPduRcvd +=
264                datReq->datReq[idx].datReqTb[idx1].lchData[idx2].pdu.numPdu;
265
266             boRpt.lcId    = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].lcId; 
267             boRpt.bo      = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.bo;
268             boRpt.oldestSduArrTime 
269                = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.oldestSduArrTime;
270             boRpt.staPduBo = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.staPduBo;
271             
272             boRpt.setMaxUlPrio= datReq->datReq[idx].datReqTb[idx1].lchData[idx2].setMaxUlPrio;
273 #ifdef CCPU_OPT
274             boRpt.setMaxDlPrio= datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.staPduPrsnt;
275 #endif
276             RgMacSchDedBoUpdt(&schPst, &boRpt);
277          }
278       }
279
280       /* ADD Changes for Downlink UE Timing Optimization */
281 #ifdef LTEMAC_DLUE_TMGOPTMZ
282 //       sf->remDatReqCnt -= datReqFailCnt;
283       /*Presently this function is not returning RFAILED, thus not checking
284         for failure condition.*/
285       ret = rgROMUpdDlSfRemDataCnt(cell, sf);
286       if(ret == RFAILED)
287       {
288          RLOG0(L_INFO, "\n Dropping due to no failure of remCnt update(1) \n");
289 #ifndef L2_OPTMZ
290          RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
291 #endif
292          /* Return from here as above functions found more datReq than expected*/
293         // return (ret);
294       }
295 #endif
296    } /* for loop for num of Ue per TTI*/
297
298 #endif
299    /* Data send successfully to PHY. lets retuns ROK*/
300    return ROK;
301 }  /* rgROMDedDatReq */
302
303
304 /**
305  * @brief Handler for DatReq received on RGU for a common logical channel.
306  *
307  * @details
308  *
309  *     Function : rgROMCmnDatReq
310  *     
311  *     This function shall invoke rgROMHndlCcchDatReq() if datReq is on CCCH
312  *     If not, it shall invoke rgROMHndlBcchPcchDatReq().
313  *     
314  *           
315  *  @param[in]  Inst        inst
316  *  @param[in]  RgRguCmnDatReq *datReq 
317  *  @return  S16
318  *      -# ROK 
319  *      -# RFAILED 
320  **/
321 S16 rgROMCmnDatReq(Inst inst, RgRguCmnDatReq *datReq)
322 {
323    RgCellCb    *cell;
324    RgErrInfo   err;
325    S16         ret;
326 /* ADD Changes for Downlink UE Timing Optimization */
327 #ifdef LTEMAC_DLUE_TMGOPTMZ
328    CmLteTimingInfo timingInfo;
329    RgDlSf   *sf;
330 #endif
331
332    ret = ROK;
333    err.errType = RGERR_ROM_CMNDATREQ;
334    if(((cell = rgCb[inst].cell) == NULLP)
335       ||(cell->cellId != datReq->cellId))
336    {
337 #if (ERRCLASS & ERRCLS_INT_PAR)
338       /* Handle Cell fetch failure */
339       RGLOGERROR(inst,ERRCLS_INT_PAR,ERG003,(ErrVal)datReq->cellId,
340                             "rgROMCmnDatReq(): Invalid cell Id");
341 #endif
342       err.errCause = RGERR_ROM_INV_CELL_ID;
343       /* Update stats */
344       if(cell != NULLP)
345       {
346          rgUpdtRguCmnSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP);
347       }
348       return RFAILED;
349    }
350
351    if (datReq->lcId == cell->dlCcchId)
352    {
353       ret = rgROMHndlCcchDatReq(cell, datReq, &err);
354
355       /*Get the timing Info*/
356       /* ADD Changes for Downlink UE Timing Optimization */
357 #ifdef LTEMAC_DLUE_TMGOPTMZ
358       timingInfo.slot = (uint8_t)((datReq->transId >> 8) & 0XFF);
359       timingInfo.sfn = (uint16_t)((datReq->transId >> 16) & 0xFFFF);
360 #endif
361    } 
362    else
363    {
364       ret = rgROMHndlBcchPcchDatReq(cell, datReq, &err);
365
366       /*Get the timing Info*/
367       /* ADD Changes for Downlink UE Timing Optimization */
368 #ifdef LTEMAC_DLUE_TMGOPTMZ
369       timingInfo.slot = (uint8_t)(datReq->transId & 0XFF);
370       timingInfo.sfn = (uint16_t)((datReq->transId >> 8) & 0xFFFF);
371 #endif
372    }
373
374    /* Update stats */
375    if (ret == RFAILED)
376    {
377       rgUpdtRguCmnSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP);
378    }
379    else
380    {
381       /* Update stats with number of SDUs received */
382       rgUpdtRguCmnSts(inst,cell->rguDlSap,RG_RGU_SDU_RCVD);
383    }
384
385    /* ADD Changes for Downlink UE Timing Optimization */
386 #ifdef LTEMAC_DLUE_TMGOPTMZ
387    RG_ARRAY_BOUND_CHECK(0, cell->subFrms, (timingInfo.slot % RG_NUM_SUB_FRAMES));
388    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
389
390    ret = rgROMUpdDlSfRemDataCnt(cell, sf);
391    /*Added check for RFAILED as above function can return RFAILED*/
392 #endif
393
394    return (ret);
395 }  /* rgROMCmnDatReq */
396
397 /**
398  * @brief Handler for DatReq received on RGU for CCCH.
399  *
400  * @details
401  *
402  *     Function : rgROMHndlCcchDatReq
403  *     
404  *     This function shall fetch the raCb with the given rnti and indicate msg4
405  *     arrival to RAM.
406  *     
407  *           
408  *  @param[in]  RgCellCb       *cell
409  *  @param[in]  RgRguCmnDatReq *datReq 
410  *  @param[out] RgErrInfo      *err
411  *  @return  S16
412  *      -# ROK 
413  *      -# RFAILED 
414  **/
415 static S16 rgROMHndlCcchDatReq(RgCellCb *cell, RgRguCmnDatReq *datReq, RgErrInfo *err)
416 {
417    Inst     inst = cell->macInst - RG_INST_START;
418    RgUeCb   *ue;
419    uint8_t   hqPId;
420    RgDlHqProcCb *hqProc;
421    CmLteTimingInfo timingInfo;
422    RgDlSf   *sf;
423 #if (ERRCLASS & ERRCLS_DEBUG)
424    RgUstaDgn   dgn;      /* Alarm diagnostics structure */
425 #endif
426
427    err->errType = RGERR_ROM_CMNDATREQ;
428
429    if ((ue = rgDBMGetUeCb(cell, datReq->u.rnti)) == NULLP)
430    {
431       if ((ue = rgDBMGetUeCbFromRachLst(cell, datReq->u.rnti)) == NULLP)
432       {
433    #if (ERRCLASS & ERRCLS_INT_PAR)
434          /* Handle Ue fetch failure */
435          RGLOGERROR(inst,ERRCLS_INT_PAR,ERG004,(ErrVal)datReq->u.rnti,
436                               "rgROMHndlCcchDatReq(): Invalid ue Id");
437    #endif
438          err->errCause = RGERR_ROM_INV_UE_ID;
439          return RFAILED;
440       }
441    }
442
443    timingInfo.slot = (uint8_t)((datReq->transId >> 8) & 0XFF);
444    timingInfo.sfn = (uint16_t)((datReq->transId >> 16) & 0xFFFF);
445    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
446
447    if( (sf->txDone == TRUE) ||
448        (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
449    {
450 #if (ERRCLASS & ERRCLS_DEBUG)
451       /* Transmission is already done for this slot. This is a delayed
452        * datReq. So discard */
453       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
454       rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
455                               LRG_CAUSE_DELAYED_DATREQ, &dgn);
456 #endif
457       err->errCause = RGERR_ROM_DELAYED_DATREQ;
458       return RFAILED;
459    }
460
461    hqPId = (uint8_t)(datReq->transId);
462    hqPId = hqPId >> 2;
463
464    /* get harq process and invoke DHM */
465    rgDHMGetHqProcFrmId(ue, hqPId, &hqProc);
466  
467    /* Changed for CR timer implementation*/
468    /* invoke DHM to process CCCH data */
469    if (rgDHMHndlCmnDatReq(inst,hqProc, datReq, err) == RFAILED)
470    {
471       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
472             "Handling of Data request in DHM failed RNTI:%d LCID:%d",
473             datReq->u.rnti,datReq->lcId);
474       /* Release First TB */
475       rgDHMRlsHqProcTB(cell, hqProc, 1);
476       /* err shall be filled in appropriately by DHM */
477       return RFAILED;
478    }
479  
480    return ROK; 
481 } /* rgROMHndlCcchDatReq */
482
483
484 /**
485  * @brief Handler for DatReq received on RGU for BCCH or PCCH.
486  *
487  * @details
488  *
489  *     Function : rgROMHndlBcchPcchDatReq
490  *     
491  *     This function shall store the buffer and time to transmit in lcCb.
492  *     
493  *           
494  *  @param[in]  RgCellCb       *cell
495  *  @param[in]  RgRguCmnDatReq *datReq 
496  *  @param[out] RgErrInfo      *err
497  *  @return  S16
498  *      -# ROK 
499  *      -# RFAILED 
500  **/
501 static S16 rgROMHndlBcchPcchDatReq(RgCellCb *cell, RgRguCmnDatReq *datReq, RgErrInfo *err)
502 {
503    Inst            inst = cell->macInst - RG_INST_START;
504    RgPcchLcCb      *pcch;
505    /* Modified for SI Enhancement*/
506 #ifndef RGR_SI_SCH
507    RgBcchBchLcCb   *bch;
508    RgBcchDlschLcCb *bcch;
509 #endif/*RGR_SI_SCH*/
510    RgDlSf          *sf;
511    CmLteTimingInfo timingInfo;
512 #if (ERRCLASS & ERRCLS_DEBUG)
513    RgUstaDgn   dgn;      /* Alarm diagnostics structure */
514 #endif
515
516
517    timingInfo.slot = (uint8_t)(datReq->transId & 0XFF);
518    timingInfo.sfn = (uint16_t)((datReq->transId >> 8) & 0xFFFF);
519    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
520
521    if( (sf->txDone == TRUE) ||
522        (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
523    {
524 #if (ERRCLASS & ERRCLS_DEBUG)
525       /* Transmission is already done for this slot. This is a delayed
526        * datReq. So discard */
527       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
528       rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
529                               LRG_CAUSE_DELAYED_DATREQ, &dgn);
530 #endif
531       err->errCause = RGERR_ROM_DELAYED_DATREQ;
532       return RFAILED;
533    }
534
535 #ifndef RGR_SI_SCH
536    bcch = rgDBMGetBcchOnDlsch(cell,datReq->lcId);
537    if (bcch )
538    {
539       /* Store BCCH-DLSCH data received in Scheduled slot */
540       sf->bcch.tb = datReq->pdu;
541
542       SCpyMsgMsg(datReq->pdu, RG_GET_MEM_REGION(rgCb[inst]),
543                RG_GET_MEM_POOL(rgCb[inst]), &bcch->tb);
544
545       return ROK;
546    }
547
548    bch = rgDBMGetBcchOnBch(cell);
549    if ((bch) && (bch->lcId == datReq->lcId))
550    {
551       /* Store BCH data received in Scheduled slot */
552       sf->bch.tb = datReq->pdu;
553       return ROK;
554    }
555 #endif/*RGR_SI_SCH*/
556
557    pcch = rgDBMGetPcch(cell);
558    if ((pcch) && (pcch->lcId == datReq->lcId))
559    {
560       /* Store PCCH-DLSCH data received in Scheduled slot */
561       sf->pcch.tb = datReq->pdu;
562       return ROK;
563    }
564
565    /* Handle lcCb fetch failure */
566    RGLOGERROR(inst,ERRCLS_INT_PAR,ERG005,(ErrVal)datReq->lcId,
567                   "rgROMHndlBcchPcchDatReq(): Invalid Lc Id");
568    err->errCause = RGERR_ROM_INV_LC_ID;
569
570    return RFAILED;
571 } /* rgROMHndlBcchPcchDatReq */
572
573 /**
574  * @brief Handler for StaRsp received on RGU for a dedicated logical channel.
575  *
576  * @details
577  *
578  *     Function : rgROMDedStaRsp
579  *     
580  *     This fucntion shall store the BO reported for the given logical
581  *     channel.
582  *     
583  *           
584  *  @param[in]  Inst        inst
585  *  @param[in]  RgRguDedStaRsp *staRsp 
586  *  @return  S16
587  *      -# ROK 
588  *      -# RFAILED 
589  **/
590 S16 rgROMDedStaRsp(Inst inst, RgRguDedStaRsp *staRsp)
591 {
592    RgCellCb   *cell;
593
594    /* Moving the error variables and assignments to available scope */
595
596    /* Avoiding memset, as the variables of this are getting 
597       initialized */
598
599
600    if(((cell = rgCb[inst].cell) != NULLP)
601       && (cell->cellId == staRsp->cellId))
602    {
603             Pst        schPst;
604 #ifdef UNUSED_VAR
605     RgInfDedBoRpt boRpt
606          boRpt.cellSapId  = cell->schInstMap.cellSapId;
607     boRpt.cellId  = staRsp->cellId;
608          boRpt.rnti    = staRsp->rnti; 
609     boRpt.lcId    = staRsp->lcId; 
610          boRpt.bo      = staRsp->boReport.bo;
611     boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
612     boRpt.staPduBo = staRsp->boReport.staPduBo;
613     boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
614 #endif
615                                 rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
616             schPst.event = 0;
617             //TODO: commented for compilation without SCH RgMacSchDedBoUpdt(&schPst, &boRpt);
618             return ROK;
619    }
620    RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,"Invalid cell for CRNTI:%d LCID:%d ",
621              staRsp->rnti,staRsp->lcId);
622
623    return RFAILED;
624 }  /* rgROMDedStaRsp */
625
626 S16 RgMacSchBrdcmDedBoUpdtReq(
627 Inst inst,
628 CmLteCellId cellId,
629 CmLteRnti rnti, 
630 CmLteLcId lcId, 
631 S32 bo 
632 )
633 {
634
635   RgCellCb   *cell;
636   //if ((cell = rgDBMGetCellCb(cellId)) != NULLP)
637   if (((cell = rgCb[inst].cell) != NULLP) &&
638         (cell->cellId == cellId))
639  {
640      Pst        schPst;
641 #ifdef UNUSED_VAR
642     RgInfDedBoRpt  boRpt;
643     boRpt.cellSapId  = cell->schInstMap.cellSapId;
644     boRpt.cellId     = cellId;
645     boRpt.rnti       = rnti; 
646     boRpt.lcId       = lcId; 
647     boRpt.bo         = bo;
648 #endif
649      rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
650      schPst.event = 0;
651      //TODO: commented for compilation without SCH RgMacSchDedBoUpdtReq (&schPst,&boRpt);
652   }
653   return ROK;
654 }
655 /**
656  * @brief Handler for StaRsp received on RGU for a common logical channel.
657  *
658  * @details
659  *
660  *     Function : rgROMCmnStaRsp
661  *     
662  *     This fucntion shall invoke rgROMHndlCcchStaRsp() for status response on
663  *     CCCH and shall invoke rgROMHndlBcchPcchStaRsp() for status response on
664  *     BCCH or PCCH.
665  *     
666  *           
667  *  @param[in]  Inst        inst
668  *  @param[in]  RgRguCmnStaRsp *staRsp 
669  *  @return  S16
670  *      -# ROK 
671  *      -# RFAILED 
672  **/
673 S16 rgROMCmnStaRsp(Inst inst, RgRguCmnStaRsp *staRsp)
674 {
675    RgCellCb   *cell;
676    RgErrInfo  err;
677
678    if(((cell = rgCb[inst].cell) == NULLP)
679       || (cell->cellId != staRsp->cellId))
680    {
681       /* Handle Cell fetch failure */
682       RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,
683                 "Invalid cell for CRNTI:%d LCID:%d",staRsp->u.rnti,staRsp->lcId);
684       err.errType = RGERR_ROM_CMNSTARSP;
685       err.errCause = RGERR_ROM_INV_CELL_ID;
686       return RFAILED;
687    }
688
689    /* handle status response on CCCH */
690    if(staRsp->lcId == cell->dlCcchId)
691    {
692       rgROMHndlCcchStaRsp(cell, staRsp, &err); 
693    }
694    else
695    {
696       rgROMHndlBcchPcchStaRsp(cell, staRsp, &err); 
697    }
698    
699    return ROK;
700 }  /* rgROMCmnStaRsp */
701
702 #ifdef LTE_L2_MEAS
703
704 /**
705  * @brief Handler for Request received on RGU for a UL Throughput measurement
706  * enabled logical channel.
707  *
708  * @details
709  *
710  *     Function :rgROML2MUlThrpMeasReq 
711  *     
712  *     This function shall store the L2M UL Throughput Measurement status  information 
713  *     for the given logical channel.
714  *     
715  *           
716  *  @param[in]  Inst        inst
717  *  @param[in]  RgRguL2MUlThrpMeasReq *measReq 
718  *  @return  S16
719  *      -# ROK 
720  *      -# RFAILED 
721  **/
722 S16 rgROML2MUlThrpMeasReq(Inst inst, RgRguL2MUlThrpMeasReq *measReq)
723 {
724    RgCellCb   *cell;
725    RgUeCb     *ue;
726    uint8_t    lcgId;
727    uint8_t    loop;
728
729    if(((cell = rgCb[inst].cell) != NULLP)
730       &&(cell->cellId == measReq->cellId))
731    {
732       if ((ue = rgDBMGetUeCb(cell, measReq->rnti)) != NULLP)
733       {
734          for(loop=0; loop<measReq->numLcId;loop++)
735          {
736             if ((rgDBMGetUlDedLcCb(ue, measReq->lcId[loop])) != NULLP)
737             {
738                ue->ul.lcCb[measReq->lcId[loop]].measOn = measReq->enbMeas;
739                if(ue->ul.lcCb[measReq->lcId[loop]].measOn == FALSE)
740                {
741                   lcgId=ue->ul.lcCb[measReq->lcId[loop]].lcgId;
742                   ue->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = 0;
743                   ue->ul.lcgArr[lcgId].lcgBsInfo.firstDatSegRcvd = FALSE;
744                }
745             }
746          }
747          return ROK;
748       }
749    }
750    RLOG_ARG1(L_ERROR,DBG_CELLID,measReq->cellId,"Invalid cell CRNTI:%d",
751              measReq->rnti);
752    return RFAILED;
753 }  /* rgROML2MUlThrpMeasReq */
754
755 #endif
756
757 /**
758  * @brief Handler for StaRsp received on RGU for CCCH.
759  *
760  * @details
761  *
762  *     Function : rgROMHndlCcchStaRsp
763  *     
764  *     This function shall fetch the raCb with the given RNTI and ask RAM to
765  *     update BO. 
766  *     
767  *           
768  *  @param[in]  RgCellCb       *cell
769  *  @param[in]  RgRguCmnStaRsp *staRsp
770  *  @param[out] RgErrInfo      *err
771  *  @return  S16
772  *      -# ROK 
773  *      -# RFAILED 
774  **/
775 static S16 rgROMHndlCcchStaRsp(RgCellCb *cell,RgRguCmnStaRsp *staRsp, RgErrInfo *err)
776 {
777    Pst      schPst;
778    Inst     macInst = cell->macInst - RG_INST_START;
779    //RgInfCmnBoRpt boRpt;
780
781 #ifdef UNUSED_VAR
782    RgInfCmnBoRpt boRpt;
783    boRpt.cellSapId  = cell->schInstMap.cellSapId;
784    boRpt.cellId  = staRsp->cellId;
785    boRpt.u.rnti    = staRsp->u.rnti; 
786    boRpt.lcId    = staRsp->lcId; 
787    boRpt.lcType  = staRsp->lcType; 
788    boRpt.bo      = staRsp->bo;
789 #endif
790    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
791    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
792
793    return ROK;
794 } /* rgROMHndlCcchStaRsp */
795
796
797 /**
798  * @brief Handler for StaRsp received on RGU for BCCH or PCCH.
799  *
800  * @details
801  *
802  *     Function : rgROMHndlBcchPcchStaRsp
803  *     
804  *     This function shall store the buffer and time to transmit in lcCb.
805  *     
806  *           
807  *  @param[in]  RgCellCb       *cell
808  *  @param[in]  RgRguCmnStaRsp *staRsp
809  *  @param[out] RgErrInfo      *err
810  *  @return  S16
811  *      -# ROK 
812  *      -# RFAILED 
813  **/
814 static S16 rgROMHndlBcchPcchStaRsp(RgCellCb *cell,RgRguCmnStaRsp *staRsp,RgErrInfo *err)
815 {
816    Pst      schPst;
817    //RgInfCmnBoRpt boRpt;
818    Inst     macInst = cell->macInst - RG_INST_START;
819
820    memset(&schPst, 0, sizeof(Pst));
821
822    if (rgDBMChkCmnLcCb(cell, staRsp->lcId) != ROK)
823    {
824       /* Handle lcCb fetch failure */
825       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid LCID:%d",staRsp->lcId);
826       err->errCause = RGERR_ROM_INV_LC_ID;
827       return RFAILED;
828    }
829    /* MS_WORKAROUND : This is to ensure that the queue for BCH is not filled with old BO requests :
830          This assumes that BO is not received more than 4 frames in advance from the enodeb application */
831    if (cell->bcchBchInfo.lcId == staRsp->lcId)
832    {
833       uint16_t nextBchSfn;
834
835       nextBchSfn = (cell->crntTime.sfn + 4 - (cell->crntTime.sfn%4)) % RG_MAX_SFN;
836       if ((staRsp->u.timeToTx.sfn != nextBchSfn) ||
837          ((staRsp->u.timeToTx.sfn == cell->crntTime.sfn) && (cell->crntTime.slot >= 7)))
838       {
839         return ROK;
840       }
841    }
842 /*
843    boRpt.cellSapId     = cell->schInstMap.cellSapId;
844    boRpt.cellId     = staRsp->cellId;
845    boRpt.u.timeToTx = staRsp->u.timeToTx; 
846    boRpt.lcId       = staRsp->lcId; 
847    boRpt.lcType     = staRsp->lcType; 
848    boRpt.bo         = staRsp->bo;*/     
849 #ifdef EMTC_ENABLE
850   if(cell->emtcEnable)
851   {
852      if(boRpt.lcType == CM_LTE_LCH_PCCH)
853      {
854         boRpt.emtcDIReason = staRsp->emtcDiReason;
855         boRpt.pnb = staRsp->pnb;
856      }
857   }
858 #endif
859    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
860    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
861
862    return ROK;
863 } /* rgROMHndlBcchPcchStaRsp */
864
865 /* ADD Changes for Downlink UE Timing Optimization */
866 #ifdef LTEMAC_DLUE_TMGOPTMZ
867 /**
868  * @brief Handler for updating DL SF information on receiving
869  *  DL dedicated data, CCCH, BCCH/PCCH data request.
870  *
871  * @details
872  *
873  *     Function : rgROMUpdDLSfRemDataCnt
874  *     
875  *           
876  *  @param[in]  RgCellCb       *cell
877  *  @param[in]  RgDlSf         *dlSf;
878  *  @return  S16
879  *      -# ROK 
880  *      -# RFAILED 
881  **/
882 static S16 rgROMUpdDlSfRemDataCnt(RgCellCb *cellCb, RgDlSf *dlSf)
883 {
884    RgErrInfo            err;
885    //Inst                 inst = cellCb->macInst - RG_INST_START;
886
887    if(!dlSf->remDatReqCnt)
888    {
889        /*This is an error scenario of RLC generating more data          
890         * request than the allocation. Do nothing for this. */
891       RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
892             "RX new data while remDatReqCnt is 0 for cell");
893       return RFAILED;
894    }
895
896    /*Decrement the remaining data request to be received countter
897      for this SF.
898      Check if this was the last pending data request for this DL SF.*/
899     /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
900      RLC-MAC */
901    if((0 == --dlSf->remDatReqCnt) && !(dlSf->txDone) &&
902       (RG_TIMEINFO_SAME(cellCb->crntTime, dlSf->schdTime)) && (dlSf->statIndDone))
903    {
904       /*Check if we have already received a TTI for this Data,
905         if that is the case then we need to send TFU Data request 
906         to PHY */
907
908       if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
909       {
910          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
911                "Unable to process downlink slot for cell");
912          err.errType = RGERR_ROM_DEDDATREQ;
913       }
914
915       /* Mark this frame as sent */
916       dlSf->txDone = TRUE;
917    }
918
919    return ROK;
920 } /* rgROMUpdDlSfRemDataCnt*/
921 #endif
922
923 /**********************************************************************
924  
925          End of file
926 **********************************************************************/