Merge "ASN Structure filling for SRS-Config : ODUHIGH-182"
[o-du/l2.git] / src / 5gnrmac / rg_tom.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_tom.c 
28   
29 **********************************************************************/
30
31 static const char* RLOG_MODULE_NAME="MAC";
32 static int RLOG_FILE_ID=237;
33 static int RLOG_MODULE_ID=4096;
34 /** @file rg_tom.c 
35 @brief This module does processing related to handling of lower interface APIs 
36 invoked by PHY towards MAC
37 */
38 /* header include files -- defines (.h) */
39 #include <stdbool.h>
40 #include "envopt.h"        /* environment options */
41 #include "envdep.h"        /* environment dependent */
42 #include "envind.h"        /* environment independent */
43 #include "gen.h"           /* general layer */
44 #include "ssi.h"           /* system services */
45 #include "cm5.h"           /* common timers defines */
46 #include "cm_hash.h"       /* common hash list defines */
47 #include "cm_llist.h"      /* common linked list defines */
48 #include "cm_mblk.h"       /* memory management */
49 #include "cm_tkns.h"       /* common tokens */
50 #include "cm_lte.h"       /* common tokens */
51 #include "rgu.h"           /* RGU defines */
52 #include "tfu.h"           /* RGU defines */
53 #include "lrg.h"           /* layer management defines for LTE-MAC */
54 #include "crg.h"           /* layer management defines for LTE-MAC */
55 #include "rg_sch_inf.h"           /* layer management defines for LTE-MAC */
56 #include "rg.h"            /* defines and macros for MAC */
57 #include "rg_env.h"            /* defines and macros for MAC */
58 #include "rg_err.h"            /* defines and macros for MAC */
59
60
61 /* header/extern include files (.x) */
62 #include "gen.x"           /* general layer typedefs */
63 #include "ssi.x"           /* system services typedefs */
64 #include "cm5.x"           /* common timers */
65 #include "cm_hash.x"       /* common hash list */
66 #include "cm_lib.x"        /* common library */
67 #include "cm_llist.x"      /* common linked list */
68 #include "cm_mblk.x"       /* memory management */
69 #include "cm_tkns.x"       /* common tokens */
70 #include "cm_lte.x"       /* common tokens */
71 #include "rgu.x"           /* RGU types */
72 #include "tfu.x"           /* RGU types */
73 #include "lrg.x"           /* layer management typedefs for MAC */
74 #include "crg.x"           /* CRG interface typedefs */
75 #include "rg_sch_inf.x"    /* SCH interface typedefs */
76 #include "rg_prg.x"        /* PRG interface typedefs */
77 #include "rgm.x"           /* layer management typedefs for MAC */
78 #include "rgm.h"           /* layer management typedefs for MAC */
79 #include "du_app_mac_inf.h"
80 #include "mac.h"
81 #include "rg.x"            /* typedefs for MAC */
82 #include "lwr_mac_fsm.h"
83 #ifdef MAC_RLC_UL_RBUF
84 #include "ss_rbuf.h"
85 #include "ss_rbuf.x"
86 #endif
87
88 /* ADD Changes for Downlink UE Timing Optimization */
89 #ifndef LTEMAC_DLUE_TMGOPTMZ 
90 PRIVATE S16 rgTOMUtlProcDlSf ARGS(( RgDlSf *dlSf, RgCellCb   *cellCb,
91                                     RgErrInfo  *err));
92 #else
93 PUBLIC S16 rgTOMUtlProcDlSf ARGS((RgDlSf *dlSf, RgCellCb *cellCb,
94                                   RgErrInfo  *err));
95 #endif
96 PRIVATE S16 rgTOMProcCrntiCEInDatInd ARGS((
97 RgMacPdu          *pdu,
98 RgUeCb            *prevUeCb,
99 RgCellCb          *cellCb,
100 TfuDatInfo        *datInfo,
101 RgInfCeInfo       *ceInfo,
102 U16               slot
103 ));
104
105 PRIVATE S16 rgTOMProcCCCHSduInDatInd ARGS((
106 RgMacPdu          *pdu,
107 RgUeCb            *prevUeCb,
108 RgCellCb          *cellCb,
109 TfuDatInfo        *datInfo,
110 RgInfCeInfo       *ceInfo,
111 U16               slot
112 ));
113
114 PUBLIC S16 rgHndlFlowCntrl
115 (
116 RgCellCb       *cell,
117 RgInfSfAlloc        *sfInfo
118 );
119
120 EXTERN S16 RgUiRguFlowCntrlInd(Pst* pst, SuId suId, RguFlowCntrlInd *flowCntrlInd);
121 #ifdef EMTC_ENABLE
122 EXTERN S16 rgEmtcHndl(RgCellCb *cell,RgInfSfAlloc  *sfInfo);  
123 EXTERN S16 rgTOMEmtcUtlFillDatReqPdus(TfuDatReqInfo *datInfo, RgDlSf *dlSf, RgCellCb *cell, RgErrInfo *err);  
124 EXTERN Void rgTOMEmtcRlsSf(RgDlSf *dlSf);  
125 #endif
126 #ifdef LTE_L2_MEAS
127 PRIVATE Void rgTOML2MCompileActiveLCs ARGS
128 ((
129  RgCellCb      *cellCb, 
130  RgUeCb        *ueCb,
131  RgMacPdu      *pdu,
132  RgInfCeInfo   *ceInfo 
133  ));
134 PRIVATE S16 rgTOMUtlL2MStoreBufSz ARGS
135 ((
136  RgUeCb      *ueCb,
137  RgInfCeInfo *ceInfo
138  ));
139
140 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo ARGS
141 ((
142    RgCellCb *cellCb,
143    RgUeCb  *ueCb,
144    RgRguDedDatInd  *dDatInd
145 ));
146
147
148 /* The below table takes lower values of BSR Range for a BSR value
149      This is to ensure that outstanding can be decrease to zero upon reception of
150      TB, which is not guaranteed if higher Range values are used */
151    /* Note: taking value 10 for BSR index 1 */
152 #ifndef MAC_5GTF_UPDATE
153 PRIVATE U32 rgLwrBsrTbl[64] = {
154    0, 10, 10, 12, 14, 17, 19, 22, 26,
155    31, 36, 42, 49, 57, 67, 78, 91,
156    107, 125, 146, 171, 200, 234, 274, 321,
157    376, 440, 515, 603, 706, 826, 967, 1132,
158    1326, 1552, 1817, 2127, 2490, 2915, 3413, 3995,
159    4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099,
160    16507, 19325, 22624, 26487, 31009, 36304, 42502, 49759,
161    58255, 68201, 79846, 93479, 109439, 128125, 150000
162 };
163 #else
164
165 PRIVATE U32 rgLwrBsrTbl[64] = {
166 0,10,13,16,19,23,29,35,43,53,65,80,98,120,147,181,223,274,337,414,
167 509,625,769,945,1162,1429,1757,2161,2657,3267,4017,4940,6074,7469,
168 9185,11294,13888,17077,20999,25822,31752,39045,48012,59039,72598,
169 89272,109774,134986,165989,204111,250990,308634,379519,466683,
170 573866,705666,867737,1067031,1312097,1613447,1984009,2439678,
171 3000000};
172
173 #endif
174
175 #endif
176
177 /* local defines */
178 #define RG_TOM_INF_ALLOC(_pdu, _size, _dataPtr, _ret) {\
179    _ret = cmGetMem((Ptr)&_pdu->memCp, _size, (Ptr *)&_dataPtr); \
180 }
181
182 /* global variables */
183 PUBLIC U32 rgUlrate_tfu;
184 #ifdef EMTC_ENABLE
185 EXTERN U32 grgUlrate_tfu;
186 #endif
187
188 /** @brief This function fills the PDSCH data of a downlink subframe 
189  *
190  * @details
191  *
192  *     Function: rgTOMUtlFillDatReqPdus 
193  *
194  *         Processing steps:
195  *         - Fill BCCH on DLSCH data using datInfo
196  *         - Fill PCCH on DLSCH data using datInfo
197  *         - Fill Dedicated data on DLSCH data using datInfo
198  *         - Fill RA RSP data using datInfo
199  *
200  * @param  [out] TfuDatReqInfo *datInfo 
201  * @param  [in]  RgDlSf     *dlSf
202  * @param  [in]  RgCellCb   *cellCb
203  * @param  [out] RgErrInfo *err
204  * @return  S16
205  *      -# ROK 
206  *      -# RFAILED 
207  */
208 #ifdef ANSI
209 PRIVATE S16 rgTOMUtlFillDatReqPdus 
210 (
211  TfuDatReqInfo *datInfo,
212  RgDlSf        *dlSf,
213  RgCellCb      *cellCb,
214  RgErrInfo     *err
215  )
216 #else
217 PRIVATE S16 rgTOMUtlFillDatReqPdus(datInfo, dlSf, cellCb, err)
218  TfuDatReqInfo *datInfo;
219  RgDlSf        *dlSf;
220  RgCellCb      *cellCb;
221  RgErrInfo     *err;
222 #endif
223 {
224    S16              ret;
225    TfuDatReqPduInfo *datReq=NULLP;
226  /* Moving node declaration to limited scope for optimization */
227    RgDlHqProcCb     *hqCb;
228    U8               idx;
229    Inst             inst = cellCb->macInst - RG_INST_START;
230
231    TRC2(rgTOMUtlFillDatReqPdus)
232
233       /* first lets send the BCCH data down to PHY */
234    if (dlSf->bcch.tb != NULLP)
235    {
236       if ((ret = rgGetEventMem(inst,(Ptr *)&datReq, sizeof(TfuDatReqPduInfo),
237                                 &(datInfo->memCp))) != ROK)
238       {
239          err->errCause = RGERR_TOM_MEM_EXHAUST;
240          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Memory Exhaustion ");
241          RETVALUE(ret);
242       }
243 #ifdef TFU_ALLOC_EVENT_NO_INIT
244 #ifndef L2_OPTMZ      
245       datReq->mBuf[1] = 0;
246 #else 
247      datReq->tbInfo[0].lchInfo[0].mBuf[0]=NULLP;
248 #endif
249 #endif
250       datReq->rnti                   =  RG_SI_RNTI;
251       datReq->dciInfo                =  dlSf->bcch.pdcch.dci;
252       /* Note: SCpyMsgMsg is not done since free of unsent buffer 
253        * has been taken care through cell delete by invoking rgTomRlsSf
254        * during shutdown */
255       datReq->nmbOfTBs               =  1;
256 #ifndef L2_OPTMZ
257       datReq->mBuf[0]                =  dlSf->bcch.tb;
258 #else
259       SFndLenMsg((Buffer *)dlSf->bcch.tb, &(datReq->tbInfo[0].tbSize));
260       datReq->tbInfo[0].tbPres             = TRUE;
261       datReq->tbInfo[0].lchInfo[0].mBuf[0] = dlSf->bcch.tb;
262       datReq->tbInfo[0].numLch             = 1;
263       datReq->tbInfo[0].lchInfo[0].numPdu  = 1;
264
265 #ifdef TFU_ALLOC_EVENT_NO_INIT
266       datReq->tbInfo[1].tbPres             = FALSE;
267       datReq->tbInfo[1].lchInfo[0].mBuf[0] = NULLP;
268 #endif
269 #endif
270       cmLListAdd2Tail(&datInfo->pdus, &(datReq->lnk));
271       datReq->lnk.node = (PTR)datReq;
272 #ifdef TFU_UPGRADE      
273       /* ccpu00132314-ADD- Adding txPower offset for the PDSCH transmission */
274       datReq->txPwrOffset            = dlSf->bcch.txPwrOffset;
275 #endif      
276       /* Setting the pointer to NULL post transmission */
277       dlSf->bcch.tb = NULLP;
278    }
279    /* Fill PCCH data */
280    if (dlSf->pcch.tb != NULLP)
281    {
282       if ((ret = rgGetEventMem(inst,(Ptr *)&datReq, sizeof(TfuDatReqPduInfo),
283                                 &(datInfo->memCp))) != ROK)
284       {
285          err->errCause = RGERR_TOM_MEM_EXHAUST;
286          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"Memory Exhaustion CRNTI:%d",datReq->rnti);
287          RETVALUE(ret);
288       }
289 #ifdef TFU_ALLOC_EVENT_NO_INIT
290 #ifndef L2_OPTMZ      
291       datReq->mBuf[1] = 0;
292 #endif     
293 #endif     
294       datReq->rnti                   =  RG_P_RNTI;
295       datReq->dciInfo                = dlSf->pcch.pdcch.dci;
296       datReq->nmbOfTBs               =  1;
297 #ifndef L2_OPTMZ
298       datReq->mBuf[0]                =  dlSf->pcch.tb;
299 #else
300       SFndLenMsg((Buffer *)dlSf->pcch.tb, &datReq->tbInfo[0].tbSize);
301       datReq->tbInfo[0].tbPres             = TRUE;
302       datReq->tbInfo[0].lchInfo[0].mBuf[0] =  dlSf->pcch.tb;
303 #ifdef TFU_ALLOC_EVENT_NO_INIT
304       datReq->tbInfo[1].tbPres             = FALSE;
305       datReq->tbInfo[1].lchInfo[0].mBuf[0] = NULLP;
306 #endif
307       datReq->tbInfo[0].numLch             = 1;
308       datReq->tbInfo[0].lchInfo[0].numPdu  = 1;
309 #endif
310       cmLListAdd2Tail(&datInfo->pdus, &(datReq->lnk));
311       datReq->lnk.node = (PTR)datReq;
312 #ifdef TFU_UPGRADE      
313       /* ccpu00132314-ADD- Adding txPower offset for the PDSCH transmission */
314       datReq->txPwrOffset            = dlSf->pcch.txPwrOffset;
315 #endif      
316       dlSf->pcch.tb = NULLP;
317    }
318
319    for(idx=0; idx < dlSf->numRaRsp; idx++)
320    {
321       if ((ret = rgGetEventMem(inst,(Ptr *)&datReq, sizeof(TfuDatReqPduInfo),
322                                 &(datInfo->memCp))) != ROK)
323       {
324          err->errCause = RGERR_TOM_MEM_EXHAUST;
325          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"Memory Exhaustion CRNTI:%d",
326                          datReq->rnti);
327          RETVALUE(ret);
328       }
329 #ifdef TFU_ALLOC_EVENT_NO_INIT
330 #ifndef L2_OPTMZ      
331       datReq->mBuf[1] = 0;
332 #endif    
333 #endif    
334       datReq->rnti                   =  dlSf->raRsp[idx].pdcch.rnti;
335       datReq->dciInfo                = dlSf->raRsp[idx].pdcch.dci;
336       datReq->nmbOfTBs               =  1;
337 #ifndef L2_OPTMZ
338       datReq->mBuf[0]                =  dlSf->raRsp[idx].rar;
339 #else
340       SFndLenMsg((Buffer *)dlSf->raRsp[idx].rar, &datReq->tbInfo[0].tbSize);
341       datReq->tbInfo[0].tbPres             = TRUE;
342       datReq->tbInfo[0].lchInfo[0].mBuf[0] =  dlSf->raRsp[idx].rar;
343 #ifdef TFU_ALLOC_EVENT_NO_INIT
344       datReq->tbInfo[1].lchInfo[0].mBuf[0] = NULLP;
345       datReq->tbInfo[1].tbPres             = FALSE;
346 #endif
347       datReq->tbInfo[0].numLch             = 1;
348       datReq->tbInfo[0].lchInfo[0].numPdu  = 1;
349    //   prc_trace_format_string(0x40,3,"UE Id=(%d) tbSz=(%d)",datReq->rnti, datReq->tbInfo[0].tbSize);
350 #endif
351       cmLListAdd2Tail(&datInfo->pdus, &(datReq->lnk));
352       datReq->lnk.node = (PTR)datReq;
353 #ifdef TFU_UPGRADE      
354       /* ccpu00132314-ADD- Adding txPower offset for the PDSCH transmission */
355       datReq->txPwrOffset            = dlSf->raRsp[idx].txPwrOffset;
356 #endif
357       dlSf->raRsp[idx].rar = NULLP;
358    }
359
360    /* Fill Dedicated UE data */
361    if (dlSf->tbs.count != 0) 
362    {
363       CmLList          *node;
364       while (dlSf->tbs.first)
365       {
366          node = dlSf->tbs.first;
367          hqCb = (RgDlHqProcCb*)node->node;
368          if ((ret = rgDHMSndDatReq (cellCb, dlSf, datInfo, hqCb, err)) != ROK)
369          {
370             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
371                             "DHM unable to fill DATA request");
372             err->errType = RGERR_TOM_TTIIND;
373             continue;
374          }
375       } /* end of while */
376    } 
377
378    RETVALUE(ROK);
379 } /* end of rgTOMUtlFillDatReqPdus*/ 
380
381 /** @brief This function does all the processing related to a single downlink
382  * subframe.
383  *
384  * @details 
385  *
386  *     Function: rgTOMUtlProcDlSf
387  *
388  *         Processing steps:
389  *         - collate control data for all UEs and send to PHY 
390  *         - collate data buffers for all UEs and send to PHY 
391  *
392  * @param  [in] RgDlSf     *dlSf
393  * @param  [in] RgCellCb   *cellCb
394  * @param  [out] RgErrInfo *err
395  * @return S16
396  */
397 /* ADD Changes for Downlink UE Timing Optimization */
398 #ifndef LTEMAC_DLUE_TMGOPTMZ 
399 #ifdef ANSI
400 PRIVATE S16 rgTOMUtlProcDlSf
401 (
402  RgDlSf     *dlSf,
403  RgCellCb   *cellCb,
404  RgErrInfo  *err
405  )
406 #else
407 PRIVATE S16 rgTOMUtlProcDlSf (dlSf, cellCb, err)
408  RgDlSf     *dlSf;
409  RgCellCb   *cellCb;
410  RgErrInfo  *err;
411 #endif
412 #else
413 #ifdef ANSI
414 PUBLIC S16 rgTOMUtlProcDlSf
415 (
416  RgDlSf     *dlSf,
417  RgCellCb   *cellCb,
418  RgErrInfo  *err
419  )
420 #else
421 PUBLIC S16 rgTOMUtlProcDlSf (dlSf, cellCb, err)
422  RgDlSf     *dlSf;
423  RgCellCb   *cellCb;
424  RgErrInfo  *err;
425 #endif
426 #endif
427 {
428    S16               ret;
429    TfuDatReqInfo     *datInfo;
430    Inst              inst = cellCb->macInst - RG_INST_START;
431
432    TRC2(rgTOMUtlProcDlSf);
433
434    /* Fill Data Request Info from scheduler to PHY */   
435    if ((ret = rgAllocEventMem(inst,(Ptr *)&datInfo, 
436                             sizeof(TfuDatReqInfo))) != ROK)
437    {
438       RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to Allocate TfuDatReqInfo");
439       RETVALUE(ret);
440    }
441    else
442    {
443       cmLListInit(&datInfo->pdus);
444 #ifdef LTE_TDD
445       RGADDTOCRNTTIME(dlSf->schdTime, datInfo->timingInfo, TFU_DELTA);
446 #else
447       RGADDTOCRNTTIME(dlSf->schdTime, datInfo->timingInfo, TFU_DLDATA_DLDELTA);
448 #endif
449       datInfo->cellId = cellCb->cellId;
450       if((0 == (datInfo->timingInfo.sfn % 30)) && (0 == datInfo->timingInfo.slot))
451       {
452          //printf("5GTF_CHECK rgTOMUtlProcDlSf dat (%d : %d)\n", datInfo->timingInfo.sfn, datInfo->timingInfo.slot);
453       }
454 #ifdef TFU_ALLOC_EVENT_NO_INIT
455       datInfo->bchDat.pres = 0;
456 #endif
457
458       /* Fill BCH data */
459       if (dlSf->bch.tb != NULLP)
460       {
461          datInfo->bchDat.pres = PRSNT_NODEF;
462          datInfo->bchDat.val  = dlSf->bch.tb;
463          dlSf->bch.tb = NULLP;
464       }
465 #ifdef EMTC_ENABLE
466       /* Fill the DLSCH PDUs of BCCH, PCCH and Dedicated Channels */
467       if ((ret = rgTOMEmtcUtlFillDatReqPdus(datInfo, dlSf, cellCb, err)) != ROK)
468       {
469          RG_FREE_MEM(datInfo);
470          RETVALUE(ret);
471       }
472 #endif 
473       /* Fill the DLSCH PDUs of BCCH, PCCH and Dedicated Channels */
474       if ((ret = rgTOMUtlFillDatReqPdus(datInfo, dlSf, cellCb, err)) != ROK)
475       {
476          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to send data for cell");
477          RG_FREE_MEM(datInfo);
478          RETVALUE(ret);
479       }
480       if((datInfo->pdus.count) || (datInfo->bchDat.pres == TRUE))
481       {
482          /* sending the data to Phy */
483          if (rgLIMTfuDatReq(inst,datInfo) != ROK)
484          {
485             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to send data info for cell");               
486          }
487       }
488       else
489       {
490          /* Nothing to send: free the allocated datInfo */
491          RG_FREE_MEM(datInfo);
492       }
493    }
494    RETVALUE(ROK);
495 } /* end of */
496
497 U32  rgMacGT;
498
499 /**
500  * @brief Handler for processing TTI indication recieved from 
501  * PHY for a cell.
502  *
503  * @details
504  *
505  *     Function: macProcessSlotInd
506  *
507  *     Handler for processing slot indication recieved from PHY
508  *     for a cell.
509  *
510  *     Invoked by: macProcessSlotInd
511  *
512  *     Processing Steps:
513  *     - Get cell and update the cell's current time with the timing value given
514  *     by PHY
515  *     - Invoke the cmPrcTmr to process the timing queue.
516  *     - Append the PHICH information to the downlink subframe that needs to go
517  *       out to PHY in this subframe.
518  *     - Invoke DHM to release the downlink subframe that occured earlier
519  *     rgDHMRlsDlsfHqProc.
520  *     - Invoke the TTI handler of scheduler. 
521  *     - Invoke the TTI handler of RAM module. 
522  *     - Get the downlink subframe that has to go out to PHY in this subframe
523  *     rgSCHSubFrmGet.
524  *     - Invoke rgTOMUtlProcTA to perform and timing advance processing. 
525  *     - Invoke rgTOMUtlProcDlSf to do further processing on the downlink
526  *     subframe.
527  *     - Get the downlink subframe that would occur after RG_DL_DELTA and 
528  *     invoke rgTOMUtlProcDlSfStaInd to send status indications to the higher
529  *     layer.
530  *     - Invoke GOM's TTI handler rgGOMTtiHndlr
531  *     - Invoke COM's TTI handler rgCOMTtiHndlr
532  *           
533  *  @param[in]  Inst        inst
534  *  @param[in] SlotIndInfo slotInd
535  *  @return  S16
536  *      -# ROK 
537  *      -# RFAILED 
538  **/
539 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
540 pthread_t gMacTId = 0;
541 #endif
542 PUBLIC S16 macProcessSlotInd
543 (
544 Inst          inst,
545 SlotIndInfo slotInd
546 )
547 {
548    RgCellCb             *cellCb;
549    RgErrInfo            err;
550    RgDlSf               *dlSf;
551 /* ADD Changes for Downlink UE Timing Optimization */
552 #ifdef LTEMAC_DLUE_TMGOPTMZ
553    RgDlSf               *prevDlSf;
554    CmLteTimingInfo       prevTmInfo;  
555 #endif
556    //SlotIndInfo *slotInd = &ttiInfo->cells[0];
557
558    TRC2(macProcessSlotInd);
559
560 #ifdef MAC_FREE_RING_BUF
561    gMacTId = pthread_self();
562 #endif
563
564    cellCb = rgCb[inst].cell;
565    if (cellCb == NULLP)
566    {
567       err.errType = RGERR_TOM_TTIIND;
568       err.errCause = RGERR_TOM_INV_CELL_ID;
569       RETVALUE(RFAILED);
570    }
571
572    RGCPYTIMEINFO(slotInd, cellCb->crntTime);
573
574    rgMacGT = (slotInd.sfn * RG_NUM_SUB_FRAMES_5G) + slotInd.slot;
575 #ifdef LTE_L2_MEAS
576    rgL2Meas(cellCb);
577    /*Included to track the number of 10240 cycles completed */
578
579   if((cellCb->crntTime.sfn == 0) && (cellCb->crntTime.slot==0))
580   {
581      cellCb->ttiCycle += 1;
582   }
583
584 #endif
585
586    /*Check if we have transmitted the previous DL SF, it could be the
587      case that we haven't received all the DATA from RLC as yet
588      and thus we would not have transmitted previous DL SF yet.*/
589 /* ADD Changes for Downlink UE Timing Optimization */
590 #ifdef LTEMAC_DLUE_TMGOPTMZ
591    RGSUBFRMCRNTTIME(slotInd, prevTmInfo, 1);
592    prevDlSf = &cellCb->subFrms[(prevTmInfo.slot % RG_NUM_SUB_FRAMES)];
593    if(FALSE == prevDlSf->txDone)
594    {
595       if (ROK != rgTOMUtlProcDlSf (prevDlSf, cellCb, &err))
596       {
597          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,"Unable to process "
598                 "previous downlink subframe for cell");
599          err.errType = RGERR_TOM_TTIIND;
600       }
601
602       /* Mark this frame as sent */
603       prevDlSf->txDone = TRUE;
604
605       if(prevDlSf->remDatReqCnt)
606       {
607          /*We have not received 1 or more data requests from RLC, this is
608            error scenario. MAC & SCH need to discard the allocations for
609            which data request hasn't been received as yet. And MAC
610            needs to inform SCH about the list of UEs for which 
611            allocation need to be discarded. */
612          prevDlSf->remDatReqCnt = 0;
613       }
614    }
615 #endif
616
617
618    /* Trigger for DL TTI REQ */
619    handleDlTtiReq(slotInd);
620
621    /* Trigger for UL TTI REQ */
622    handleUlTtiReq(slotInd);
623
624    dlSf = &cellCb->subFrms[(slotInd.slot % RG_NUM_SUB_FRAMES)];
625
626    if((dlSf->txDone == TRUE) ||
627       (!RG_TIMEINFO_SAME(slotInd,dlSf->schdTime)))
628    {
629    /* MS_WORKAROUND */
630 #ifndef LTEMAC_DLUE_TMGOPTMZ
631       TfuDatReqInfo     *datInfo;
632      CmLteTimingInfo   timingInfo;
633 #ifdef TFU_DL_DELTA_CHANGE
634          RGADDTOCRNTTIME(cellCb->crntTime, timingInfo, TFU_DLDATA_DLDELTA);
635 #else
636          RGADDTOCRNTTIME(cellCb->crntTime, timingInfo, TFU_DELTA);
637 #endif
638      /* Fill Data Request from MAC for BCH  */
639      if ((timingInfo.sfn % 4 == 0) && (timingInfo.slot == 0))
640      {
641          if (ROK != rgAllocEventMem(inst,(Ptr *)&datInfo, 
642                             sizeof(TfuDatReqInfo)))
643          {
644             RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
645                 "rgTOMUtlProcDlSf() Unable to Allocate TfuDatReqInfo for cell");
646             RETVALUE(RFAILED);
647          }
648          else
649          {
650             cmLListInit(&datInfo->pdus);
651             datInfo->cellId = cellCb->cellId;
652             datInfo->bchDat.pres = NOTPRSNT;
653             datInfo->timingInfo = timingInfo;
654             
655                                    
656           /* sending the dummy data req to Phy */
657             if (rgLIMTfuDatReq(inst,datInfo) != ROK)
658             {
659                RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
660                          "rgTOMUtlProcDlSf() Unable to send data info for cell");
661             }
662          
663          }
664      }      
665 #endif
666       /* Freeing as the part of CL Non RT Indication */
667       /* TDOD : Generalize for all SOCs */
668 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
669       rgDHMFreeTbBufs(inst);
670 #endif
671       RETVALUE(ROK);
672    }
673
674    /*Return if there is still some data to be received
675      from RLC for this DL SF. */
676 /* ADD Changes for Downlink UE Timing Optimization */
677 #ifdef LTEMAC_DLUE_TMGOPTMZ
678    if(0 != dlSf->remDatReqCnt) 
679    {
680       /* Freeing as the part of CL Non RT Indication */
681       /* TODO : Generalize for all SOCs and remove this flag */
682 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
683       rgDHMFreeTbBufs(inst);
684 #endif
685       RETVALUE(ROK);
686    }
687 #endif
688
689 #ifdef XEON_SPECIFIC_CHANGES
690    CM_MEAS_TIME((slotInd.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_DL_BR_PRC);
691 #endif
692
693    if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
694    {
695       //RLOG_ARG0(L_ERROR,DBG_CELLID,slotInd->cellId,
696       //              "Unable to process downlink subframe for cell");
697       err.errType = RGERR_TOM_TTIIND;
698    }
699 #ifdef XEON_SPECIFIC_CHANGES
700    CM_MEAS_TIME((slotInd->slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_DL_AFTER_PRC);
701 #endif
702
703    /* Mark this frame as sent */
704    dlSf->txDone = TRUE;
705
706    /* Freeing as the part of CL Non RT Indication */
707    /* TODO : Generalize for all SOCs and remove this flag */
708 #if !(defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD))
709    rgDHMFreeTbBufs(inst);
710 #endif 
711    RETVALUE(ROK);
712 }  /* macProcessSlotInd */
713
714 /** @brief This function allocates the RgMacPdu that will be populated by DEMUX
715  * with the SubHeaders list and the values of the Control elements.
716  *
717  * @details
718  *
719  *     Function: rgTOMUtlAllocPduEvnt
720  *
721  *         Processing steps:
722  *  @param[in]  Inst        inst
723  * @param  [out] RgMacPdu   **pdu
724  *
725  *  @return  S16
726  *      -# ROK 
727  *      -# RFAILED 
728  */
729 #ifdef ANSI
730 PRIVATE S16 rgTOMUtlAllocPduEvnt 
731 (
732 Inst             inst,
733  RgMacPdu         **pdu
734  )
735 #else
736 PRIVATE S16 rgTOMUtlAllocPduEvnt (inst,pdu)
737 Inst             inst;
738    RgMacPdu         **pdu;
739 #endif
740 {
741
742    Mem               evntMem;
743    RgUstaDgn         dgn;      /* Alarm diagnostics structure */
744    VOLATILE U32      startTime=0;
745
746    TRC2(rgTOMUtlAllocPduEvnt);
747
748    evntMem.region = rgCb[inst].rgInit.region;
749    evntMem.pool   = rgCb[inst].rgInit.pool;
750
751    /*starting Task*/
752    SStartTask(&startTime, PID_TOMUTL_CMALLCEVT);
753
754 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
755    MS_BUF_ADD_ALLOC_CALLER();
756 #endif /* */
757
758    if (cmAllocEvnt (sizeof (RgMacPdu), RG_BLKSZ, &evntMem, (Ptr*)pdu) != ROK)
759    {
760       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
761       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
762                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
763       RLOG0(L_ERROR,"Allocation of DUX event failed");
764       RETVALUE(RFAILED);
765    }
766
767    /*stoping Task*/
768    SStopTask(startTime, PID_TOMUTL_CMALLCEVT);
769
770    RETVALUE(ROK);
771 } /* end of */ 
772
773 /** @brief This function frees up the RgMacPdu structure that has been
774  * populated by demux.
775  *
776  * @details
777  *
778  *     Function: rgTOMUtlFreePduEvnt
779  *       - Function frees up the RgMacPdu structure, in case of error it shall
780  *       free up the buffer's present in the different sdu.
781  *
782  *         Processing steps:
783  * @param  [in]  Inst        inst
784  * @param  [in] RgMacPdu   *pdu
785  * @param  [in] Bool       *error
786  * @return 
787  */
788 #ifdef ANSI
789 PRIVATE Void rgTOMUtlFreePduEvnt
790 (
791  RgMacPdu *pdu,
792  Bool      error
793  )
794 #else
795 PRIVATE Void rgTOMUtlFreePduEvnt (pdu, error)
796    RgMacPdu *pdu;
797    Bool      error;
798 #endif
799 {
800
801    RgMacSdu       *sdu;
802    CmLList        *node;
803
804    TRC2(rgTOMUtlFreePduEvnt);
805    /* Steps of freeing up the PDU.
806     * 1. loop through the subHdrLst and free up all the buffers.
807     * 2. free up the whole event
808     */
809    if ((error == TRUE) && (pdu->sduLst.count > 0))
810    {
811       node =  pdu->sduLst.first;
812       while (node)
813       {
814          sdu = (RgMacSdu*)node->node;
815          RG_FREE_MSG(sdu->mBuf);
816          node = node->next;
817       }
818    }
819    RG_FREE_MEM(pdu);
820    RETVOID;
821 } /* end of rgTOMUtlFreePduEvnt */ 
822
823 /** @brief This function allocates the RgMacPdu that will be populated by DEMUX
824  * with the SubHeaders list and the values of the Control elements.
825  *
826  * @details
827  *
828  *     Function: rgTOMInfAllocPduEvnt
829  *
830  *         Processing steps:
831  * @param  [in] Inst        inst
832  * @param  [out] RgMacPdu   **pdu
833  *
834  *  @return  S16
835  *      -# ROK 
836  *      -# RFAILED 
837  */
838 #ifdef ANSI
839 PRIVATE S16 rgTOMInfAllocPduEvnt 
840 (
841 Inst           inst,
842 RgInfSfDatInd **sfInfo
843  )
844 #else
845 PRIVATE S16 rgTOMInfAllocPduEvnt (inst,sfInfo)
846 Inst             inst;
847 RgInfSfDatInd **sfInfo;
848 #endif
849 {
850
851    Mem               evntMem;
852    RgUstaDgn         dgn;      /* Alarm diagnostics structure */
853    VOLATILE U32      startTime=0;
854
855    TRC2(rgTOMInfAllocPduEvnt);
856
857    evntMem.region = rgCb[inst].rgInit.region;
858    evntMem.pool   = rgCb[inst].rgInit.pool;
859
860    /*starting Task*/
861    SStartTask(&startTime, PID_TOMINF_CMALLCEVT);
862
863 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
864    MS_BUF_ADD_ALLOC_CALLER();
865 #endif /* */
866    if (cmAllocEvnt (sizeof (RgInfSfDatInd), RG_BLKSZ, &evntMem, (Ptr*)sfInfo) != ROK)
867    {
868       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
869       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
870                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
871       RLOG0(L_ERROR,"Allocation failed");
872       RETVALUE(RFAILED);
873    }
874
875    /*stoping Task*/
876    SStopTask(startTime, PID_TOMINF_CMALLCEVT);
877
878    RETVALUE(ROK);
879 } /* end of */ 
880
881 /** @brief This function frees up the RgMacPdu structure that has been
882  * populated by demux.
883  *
884  * @details
885  *
886  *     Function: rgTOMInfFreePduEvnt
887  *       - Function frees up the RgMacPdu structure, in case of error it shall
888  *       free up the buffer's present in the different sdu.
889  *
890  *         Processing steps:
891  * @param  [in] RgMacPdu   *pdu
892  * @param  [in] Bool       *error
893  * @return 
894  */
895 #ifdef ANSI
896 PRIVATE Void rgTOMInfFreePduEvnt
897 (
898 RgInfSfDatInd *sfInfo
899  )
900 #else
901 PRIVATE Void rgTOMInfFreePduEvnt (sfInfo)
902 RgInfSfDatInd *sfInfo;
903 #endif
904 {
905    TRC2(rgTOMInfFreePduEvnt);
906
907    RG_FREE_MEM(sfInfo);
908    RETVOID;
909 } /* end of rgTOMUtlFreePduEvnt */
910
911 #ifdef LTE_L2_MEAS
912
913 /** @brief This function performs the preparation of information needed to set
914  * L2M Scheduled UL Throughput Information for a particular UE.
915  *
916  * @details
917  *
918  *     Function: rgTomUtlPrepareL2MUlThrpInfo
919  *      This function performs the preparation of information needed to set
920  *       L2M Scheduled UL Throughput Information for a particular UE.
921  *
922  *
923  *         Processing steps:
924  * @param  [in] RgCellCb   *cellCb
925  * @param  [in] RgUeCb       *ueCb
926  * @param  [out] RgRguDedDatInd *dDatInd
927  * @return 
928  */
929 #ifdef ANSI
930 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo
931 (
932    RgCellCb *cellCb,
933    RgUeCb  *ueCb,
934    RgRguDedDatInd  *dDatInd
935  )
936 #else
937 PRIVATE S16 rgTomUtlPrepareL2MUlThrpInfo(cellCb,ueCb,dDatInd)
938    RgCellCb *cellCb;
939    RgUeCb *ueCb;
940    RgRguDedDatInd    *dDatInd;
941 #endif
942 {
943    U8 lcId;
944    U8 lcgId;
945    U8 loop;
946    TRC2(rgTomUtlPrepareL2MUlThrpInfo);
947
948    dDatInd->burstInd = RGU_L2M_UL_BURST_END;
949    for(loop=0;loop<dDatInd->numLch;loop++)
950    {
951       lcId=dDatInd->lchData[loop].lcId;
952       if (lcId)
953       {
954          lcgId = ueCb->ul.lcCb[lcId - 1].lcgId;
955          if(ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs > 0)
956          {
957             dDatInd->burstInd = RGU_L2M_UL_BURST_START;
958             break;
959                   }
960                }
961    }
962
963    RETVALUE(ROK);
964 }
965
966 #endif
967
968 /** @brief This function is called by rgTOMDatInd. This function invokes the
969  * scheduler with the information of the received Data and any Control Elements
970  * if present. Also it generates Data indications towards the higher layers.
971  *
972  * @details
973  *
974  *     Function: 
975  *
976  *         Processing steps:
977  *         - Retrieves the RaCb with the rnti provided, if it doesnt exist
978  *         return failure. 
979  *         - If UE exists then update the Schduler with any MAC CEs if present. 
980  *         - Invoke RAM module to do Msg3 related processing rgRAMProcMsg3
981  *         - Loop through the SDU subheaders and invoke either a common data
982  *         indication (rgUIMSndCmnDatInd) or dedicated data indication
983  *         (rgUIMSndDedDatInd) towards the higher layers. 
984  *
985  * @param  [in] RgCellCb   *cellCb
986  * @param  [in] RgUeCb     *ueCb
987  * @param  [in] CmLteRnti  rnti
988  * @param  [in] RgMacPdu   *pdu
989  * @param  [out] U32       *lcgBytes
990  *  
991  *  @return  S16
992  *      -# ROK 
993  *      -# RFAILED 
994  */
995  RgUeCb  *glblueCb4;
996  RgUeCb  *glblueCb5;
997
998 #ifdef LTEMAC_SPS
999 #ifdef ANSI
1000 PRIVATE S16 rgTOMUtlProcMsg
1001 (
1002  RgCellCb      *cellCb, 
1003  RgUeCb        *ueCb,
1004  RgMacPdu      *pdu,
1005  Bool          isSpsRnti,
1006  Bool          *spsToBeActvtd,
1007  U16           *sduSize,
1008  U16           slot,
1009  U32           *lcgBytes
1010  )
1011 #else
1012 PRIVATE S16 rgTOMUtlProcMsg(cellCb, ueCb, pdu, isSpsRnti,spsToBeActvtd,sduSize, slot, lcgBytes)
1013    RgCellCb      *cellCb; 
1014    RgUeCb        *ueCb;
1015    RgMacPdu      *pdu;
1016    Bool          isSpsRnti;
1017    Bool          *spsToBeActvtd;
1018    U16           *sduSize;
1019    U16           slot;
1020    U32           *lcgBytes;
1021 #endif   
1022 #else /* LTEMAC_SPS */
1023 #ifdef ANSI
1024 PRIVATE S16 rgTOMUtlProcMsg
1025 (
1026  RgCellCb      *cellCb, 
1027  RgUeCb        *ueCb,
1028  RgMacPdu      *pdu,
1029  U16           slot,
1030  U32           *lcgBytes
1031  )
1032 #else
1033 PRIVATE S16 rgTOMUtlProcMsg(cellCb, ueCb, pdu, slot, lcgBytes)
1034    RgCellCb      *cellCb; 
1035    RgUeCb        *ueCb;
1036    RgMacPdu      *pdu;
1037    U16           slot;
1038    U32           *lcgByes;
1039 #endif  
1040 #endif
1041 {
1042    Inst              inst = cellCb->macInst - RG_INST_START;
1043    S16               ret;
1044    RgRguCmnDatInd    *cDatInd;
1045    RgRguDedDatInd    *dDatInd;
1046    CmLList           *node;
1047    RgMacSdu          *sdu;
1048    MsgLen            ccchSz;
1049    MsgLen            cpySz;
1050 #ifdef LTEMAC_SPS
1051    Pst               schPst1;  
1052 //   RgInfSpsRelInfo   relInfo;
1053 #endif
1054
1055 #ifdef LTE_L2_MEAS
1056    U8                idx1;
1057    U8                idx2;
1058    RgUlSf            *ulSf;
1059    U16               totalBytesRcvd = 0;
1060    U16               sduLen[RGU_MAX_LC] = {0};
1061    U8                qciVal[RGU_MAX_LC] = {0};
1062    U8                numPrb = 0;
1063
1064 #endif
1065    U8                lcgId;
1066    MsgLen            bufSz;
1067
1068   /* Moved outside of LTE_L2_MEAS
1069     *          scope as this pointer will now be used to 
1070     *          check for valid Logical Channel ID
1071    */
1072    RgUlLcCb          *ulLcCb;
1073    
1074    cDatInd  = NULLP;
1075    dDatInd  = NULLP;
1076 #ifdef LTE_L2_MEAS
1077    ulSf   = NULLP;
1078    idx1   = 0;
1079    idx2   = 0;
1080 #endif
1081 #ifdef SS_RBUF 
1082    Void *elem = NULLP;
1083 #endif
1084   
1085    ulLcCb = NULLP;
1086    
1087    TRC2(rgTOMUtlProcMsg)
1088
1089 #ifndef LTE_L2_MEAS      
1090       UNUSED(slot);
1091 #endif
1092
1093    if(pdu->sduLst.first)
1094    {
1095       sdu = (RgMacSdu*)(pdu->sduLst.first->node);
1096                         glblueCb4 = ueCb;
1097       if ((sdu->lcId == RG_CCCH_LCID))
1098       {
1099          /* code for common channel dat indications */
1100          if ((ret = rgAllocShrablSBuf (inst,(Data**)&cDatInd, sizeof(RgRguCmnDatInd))) != ROK)
1101          {
1102             RETVALUE(RFAILED);
1103          }
1104          cDatInd->cellId   = cellCb->cellId;
1105          cDatInd->rnti     = ueCb->ueId;
1106          /* rg001.101: Corrected lcId value for common data indication */
1107          cDatInd->lcId     = cellCb->ulCcchId;
1108          cDatInd->pdu      = sdu->mBuf;
1109          SFndLenMsg (sdu->mBuf, &ccchSz);
1110          /* Fix : syed Contention resolution ID copy should consider only
1111           * 6 bytes of information from sdu->mBuf. Incase of CCCH sdu for reest
1112           * message/psuedo reest message, ccchSz can go beyond 6 and can corrupt 
1113           * other fields of ueCb. */
1114          if (ccchSz >= RG_CRES_LEN)
1115          {
1116             SCpyMsgFix (sdu->mBuf, (MsgLen)0, RG_CRES_LEN, ueCb->contResId.resId,
1117                         &cpySz);
1118          }
1119 #ifdef XEON_SPECIFIC_CHANGES
1120          CM_LOG_DEBUG(CM_LOG_ID_MAC, "CCCH SDU of size(%d) received for UE(%d) CRES[0x%x 0x%x 0x%x 0x%x 0x%x 0x%x] Time[%d %d]\n",  ((S16)ccchSz), ueCb->ueId,ueCb->contResId.resId[0], ueCb->contResId.resId[1], ueCb->contResId.resId[2], ueCb->contResId.resId[3], ueCb->contResId.resId[4], ueCb->contResId.resId[5], cellCb->crntTime.sfn,  cellCb->crntTime.slot);
1121 #endif
1122          sdu->mBuf = NULLP;
1123          rgUIMSndCmnDatInd(inst,cellCb->rguUlSap,cDatInd);
1124          RETVALUE(ROK);
1125       } /* end of common channel processing */
1126 #ifndef SS_RBUF 
1127       if ((ret = rgAllocShrablSBuf (inst,(Data**)&dDatInd, sizeof(RgRguDedDatInd))) != ROK)
1128       {
1129          RETVALUE(RFAILED);
1130       }
1131 #else
1132                         glblueCb5 = ueCb;
1133       elem = SRngGetWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
1134       if (NULLP == elem)
1135       { 
1136          RETVALUE(RFAILED);
1137       }
1138       dDatInd = (RgRguDedDatInd *)elem;
1139       cmMemset((U8 *)dDatInd, 0x00, sizeof(RgRguDedDatInd));
1140 #endif
1141       dDatInd->cellId   = cellCb->cellId;
1142       dDatInd->rnti     = ueCb->ueId;
1143       dDatInd->numLch   = 0;
1144    }
1145 #ifdef LTE_L2_MEAS
1146    ulSf = &cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)];
1147    if(ulSf->ueUlAllocInfo != NULLP)
1148    {
1149      for(idx1 = 0; idx1 < ulSf->numUe; idx1++)
1150      {
1151         if(ulSf->ueUlAllocInfo[idx1].rnti == ueCb->ueId)
1152         {
1153            numPrb = ulSf->ueUlAllocInfo[idx1].numPrb;
1154            break;
1155         }
1156      }
1157    }
1158 #endif
1159    node =  pdu->sduLst.first;
1160    while (node)
1161    {
1162       sdu = (RgMacSdu*)node->node;
1163       
1164       ulLcCb = rgDBMGetUlDedLcCb (ueCb, sdu->lcId);
1165       
1166       if(ulLcCb == NULLP)
1167       {
1168          RLOG_ARG2(L_ERROR,DBG_CELLID,cellCb->cellId,"Unconfigured LCID:%d CRNTI:%d"
1169                          ,sdu->lcId,ueCb->ueId);
1170          /* ccpu00128443: Fix for memory leak */
1171          /* Fix : syed Neccessary to set sdu->mBuf = NULLP */
1172          RG_FREE_MSG(sdu->mBuf);         
1173          node = node->next;
1174          continue;
1175       }
1176 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
1177       {
1178          extern S16 kwProcDlStatusPdu(Pst       *udxPst,SuId      suId,
1179                CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu);
1180
1181          if(ROK == kwProcDlStatusPdu(&(cellCb->rguDlSap->sapCfg.sapPst),
1182                   cellCb->rguDlSap->sapCfg.suId,
1183                   cellCb->cellId,ueCb->ueId,sdu->lcId,sdu->mBuf))
1184          {
1185             RG_FREE_MSG(sdu->mBuf);           
1186             node = node->next;
1187             continue;
1188          }
1189       }
1190 #endif
1191
1192       /* ccpu00116477- Fixed the rgUIMSndDedDatInd condition when we receive 11 sdus in the 
1193        * list we are losing 11th sdu and sending the first 10 sdus again which
1194        * is causing the duplicate packets and eNB crashing due to access
1195        * of the freed memory */
1196       if (dDatInd->numLch >= RGU_MAX_LC)
1197       {
1198          if ((ret = rgUIMSndDedDatInd(inst,ueCb->rguUlSap,dDatInd)) != ROK)
1199          {
1200             RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
1201                 "Failed to send datIndication to RGU CRNTI:%d",ueCb->ueId);
1202             RETVALUE(ret);
1203          }
1204 #ifndef SS_RBUF
1205          if ((ret = rgAllocShrablSBuf (inst,(Data**)&dDatInd, sizeof(RgRguDedDatInd))) != ROK)
1206          {
1207             RETVALUE(RFAILED);
1208          }
1209 #else
1210       elem = SRngGetWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
1211       if (NULLP == elem)
1212       { 
1213          RETVALUE(RFAILED);
1214       }
1215       dDatInd = (RgRguDedDatInd *)elem;
1216       cmMemset((U8 *)dDatInd, 0x00, sizeof(RgRguDedDatInd));
1217 #endif
1218          dDatInd->cellId   = cellCb->cellId;
1219          dDatInd->rnti     = ueCb->ueId;
1220          dDatInd->numLch   = 0;
1221       }
1222       dDatInd->lchData[dDatInd->numLch].lcId = sdu->lcId;
1223       dDatInd->lchData[dDatInd->numLch].pdu.mBuf[dDatInd->lchData[dDatInd->numLch].pdu.numPdu] = sdu->mBuf;
1224       dDatInd->lchData[dDatInd->numLch].pdu.numPdu++;
1225       lcgId = ulLcCb->lcgId;
1226       SFndLenMsg(sdu->mBuf, &bufSz);
1227 #ifdef LTE_L2_MEAS
1228       if(ulLcCb->measOn)
1229       {
1230          ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs -= bufSz; 
1231       }
1232 #endif
1233       //if ((lcgBytes != NULLP) && (ueCb->ul.lcgArr[lcgId].isGbr == TRUE))
1234       if (lcgBytes != NULLP)
1235       {
1236          lcgBytes[lcgId] += bufSz;
1237       }
1238       sdu->mBuf = NULLP;
1239       dDatInd->numLch++;
1240 #ifdef LTEMAC_SPS
1241       /* Check if data has come on SPS LC */
1242       /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1243       if (ueCb->ul.spsLcId[sdu->lcId-1] == TRUE)
1244       {
1245          ueCb->ul.spsDatRcvd++;
1246       }
1247             
1248       if(isSpsRnti)
1249       {
1250          /* Data rcvd on CRNTI*/
1251          /* Retrieve the LCG ID of the LCID*/
1252          /* SPS LCG has data whose size > SID Size */
1253          /* Activate SPS if data recvd on SPS LCID and size > SID Packet Size */
1254          if((ueCb->ul.spsLcId[sdu->lcId-1] == TRUE) &&
1255             (sdu->len > RG_SPS_SID_PACKET_SIZE))
1256          {
1257              *spsToBeActvtd = TRUE;
1258              *sduSize = sdu->len;
1259          }
1260       }
1261       
1262 #endif  
1263
1264 #ifdef LTE_L2_MEAS
1265       if(cellCb->qciArray[ulLcCb->qci].mask == TRUE)
1266       {
1267            sduLen[ulLcCb->qci] = sdu->len;
1268            totalBytesRcvd += sdu->len;
1269            qciVal[ulLcCb->qci] = ulLcCb->qci;
1270       }
1271 #endif
1272       node = node->next;
1273    } /* end of while for SubHeaders */
1274 #ifdef LTE_L2_MEAS
1275    for(idx2 = 0; idx2 < RGU_MAX_LC; idx2++)
1276    {
1277       if((cellCb->qciArray[qciVal[idx2]].mask == TRUE) &&
1278           totalBytesRcvd > 0)
1279       {
1280          cellCb->qciArray[qciVal[idx2]].prbCount += 
1281          ((numPrb * sduLen[idx2]) / totalBytesRcvd);
1282       }
1283       
1284       /* RRM_RBC_X */
1285       if(totalBytesRcvd > 0 && qciVal[idx2] > 0)
1286       {
1287          RG_UPD_GBR_PRB(cellCb, qciVal[idx2], ((numPrb * sduLen[idx2])/totalBytesRcvd));
1288       }
1289       /* RRM_RBC_Y */
1290    }
1291 #endif
1292 /*Added for explicit release - start*/
1293 #ifdef LTEMAC_SPS
1294
1295    if(isSpsRnti && dDatInd && dDatInd->numLch)
1296    {
1297       if(ueCb->ul.spsDatRcvd != 0)
1298       {
1299          ueCb->ul.explRelCntr = 0;
1300          ueCb->ul.spsDatRcvd = 0;
1301       }
1302       else
1303       {
1304          ueCb->ul.explRelCntr++;
1305          if (ueCb->ul.explRelCntr == ueCb->ul.explRelCnt)
1306          {
1307             ueCb->ul.explRelCntr = 0;
1308             /* Indicate scheduler for explicit release */
1309             cmMemset((U8*)&schPst1, (U8)0, sizeof(Pst));
1310             rgGetPstToInst(&schPst1,inst, cellCb->schInstMap.schInst);
1311            //TODO: commented for compilation without SCH 
1312 #if 0
1313             relInfo.cellSapId = cellCb->schInstMap.cellSapId;
1314             relInfo.cRnti = ueCb->ueId;
1315             relInfo.isExplRel = TRUE;
1316             /* Release indicator is called now through the matrix in the function below */
1317             //TODO: commented for compilation without SCH RgMacSchSpsRel( &schPst1, &relInfo );
1318 #endif
1319             ueCb->ul.implRelCntr = 0;
1320          }
1321       }
1322    } 
1323    else
1324    {
1325       /* SPS_FIX */
1326       if(ueCb->ul.spsDatRcvd != 0)
1327       {
1328          //ueCb->ul.implRelCntr = 0;
1329          ueCb->ul.explRelCntr = 0;
1330          ueCb->ul.spsDatRcvd = 0;
1331       }
1332    }
1333 #endif
1334    /*Added for explicit release - end */
1335
1336    if((dDatInd) && (dDatInd->numLch))
1337    {
1338 #ifdef LTE_L2_MEAS
1339       rgTomUtlPrepareL2MUlThrpInfo(cellCb, ueCb,dDatInd);
1340
1341       RG_CALC_TTI_CNT(cellCb, dDatInd->ttiCnt); 
1342 #endif
1343       if ((ret = rgUIMSndDedDatInd(inst,ueCb->rguUlSap,dDatInd)) != ROK)
1344       {
1345          RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
1346                 "Failed to send datIndication to RGU CRNTI:%d",ueCb->ueId);
1347          RETVALUE(ret);
1348       }
1349    }
1350 #ifndef SS_RBUF
1351    else if((dDatInd) && (0 == dDatInd->numLch))
1352    {
1353       /* Free the memory allocated for dDatInd if we 
1354        * have no valid LCH PDU to send to RLC.*/
1355       rgFreeSharableSBuf(inst,(Data **)&dDatInd,sizeof(RgRguDedDatInd)); 
1356    }
1357 #endif
1358    RETVALUE(ROK);
1359 } /* end of */ 
1360
1361 /** @brief This function frees up the RgMacPdu structure that has been
1362  * populated by demux.
1363  *
1364  * @details
1365  *
1366  *     Function: rgTOMUtlInsSchInfo
1367  *       - Function frees up the RgMacPdu structure, in case of error it shall
1368  *       free up the buffer's present in the different sdu.
1369  *
1370  *         Processing steps:
1371  * @param  [in] RgMacPdu   *pdu
1372  * @param  [in] Bool       *error
1373  * @return 
1374  */
1375 #ifdef LTEMAC_SPS
1376 #ifdef ANSI
1377 PRIVATE S16 rgTOMUtlInsSchInfo
1378 (
1379 RgMacPdu *pdu,
1380 RgInfSfDatInd *sfInfo,
1381 RgInfCeInfo *ceInfo,
1382 CmLteRnti   rnti,
1383 Bool        spsToBeActvtd,
1384 U16         sduSize,
1385 U32         *lcgBytes
1386 )
1387 #else
1388 PRIVATE S16 rgTOMUtlInsSchInfo (pdu, sfInfo, ceInfo, rnti,spsToBeActvtd,sduSize, lcgBytes)
1389 RgMacPdu *pdu;
1390 RgInfSfDatInd *sfInfo;
1391 RgInfCeInfo *ceInfo;
1392 CmLteRnti   rnti;
1393 Bool        spsToBeActvtd;
1394 U16         sduSize;
1395 U32         *lcgBytes;
1396 #endif
1397
1398 #else
1399 #ifdef ANSI
1400 PRIVATE S16 rgTOMUtlInsSchInfo
1401 (
1402 RgMacPdu *pdu,
1403 RgInfSfDatInd *sfInfo,
1404 RgInfCeInfo *ceInfo,
1405 CmLteRnti   rnti,
1406 U32         *lcgBytes
1407 )
1408 #else
1409 PRIVATE S16 rgTOMUtlInsSchInfo (pdu, sfInfo, ceInfo, rnti, lcgBytes)
1410 RgMacPdu *pdu;
1411 RgInfSfDatInd *sfInfo;
1412 RgInfCeInfo *ceInfo;
1413 CmLteRnti   rnti;
1414 U32         *lcgBytes;
1415 #endif
1416 #endif
1417 {
1418    S16            ret;
1419    RgInfUeDatInd *ueInfo;
1420    U32           lcgId = 0;
1421    U32           idx = 0;
1422
1423    TRC2(rgTOMUtlInsSchInfo);
1424
1425    RG_TOM_INF_ALLOC(sfInfo, sizeof(RgInfUeDatInd), ueInfo, ret);
1426
1427    if(ROK != ret)
1428    {
1429       RETVALUE(RFAILED);
1430    }
1431
1432    ueInfo->rnti = rnti; 
1433       
1434    ueInfo->ceInfo = *ceInfo;
1435    ueInfo->ueLstEnt.node = (PTR)ueInfo;
1436    for (lcgId = 1, idx = 0; lcgId < RGINF_MAX_LCG_PER_UE; lcgId++)
1437    {
1438       if (lcgBytes[lcgId] != 0)
1439       {
1440          /* Only GBR bytes */
1441          ueInfo->lcgInfo[idx].lcgId     = lcgId;
1442          ueInfo->lcgInfo[idx++].bytesRcvd = lcgBytes[lcgId];
1443          lcgBytes[lcgId] = 0;
1444       }
1445    }
1446    cmLListAdd2Tail(&sfInfo->ueLst, &ueInfo->ueLstEnt);
1447    RETVALUE(ROK);
1448 } /* end of rgTOMUtlInsSchInfo */
1449
1450 #include <stdlib.h>
1451 /**
1452  * @brief Handler for processing data indication recieved from PHY for UEs.
1453  *
1454  * @details
1455  *
1456  *     Function: rgTOMDatInd
1457  *
1458  *     Handler for processing data indication recieved from PHY for UEs.
1459  *
1460  *     Invoked by: RgLiTfuDatInd of LIM 
1461  *
1462  *     Processing Steps: 
1463  *     For each DataInfo recieved
1464  *      - Validate the information received and retrieve cellCb 
1465  *        Validate cellId, rnti 
1466  *      - Call De-Mux module to decode the data rgDUXDemuxData
1467  *      - If  received a CRNTI control element 
1468  *          - Check if a CCCH SDU is present, if it is return failure
1469  *          - Check for the existence of UE, if its isnt present return failure.
1470  *          - Delegate the remaining processing to rgTOMUtlProcMsg3 which
1471  *          primarily informs the scheduler about the data received and
1472  *          generates Data indications towards the higher layer.
1473  *      - If only CCCH SDU is present
1474  *        - Invoke rgTOMUtlProcMsg3 for further processing.
1475  *      - If its a non-Msg3 PDU i.e. received outside of a RA procedure
1476  *        - Retrieve the UeCB 
1477  *        - Validate that the received PDU contains only configured Logical
1478  *        Channels.
1479  *        - Invoke rgTOMUtlProcDatPdu for further processing. It informs the
1480  *        scheduler with the information of the received Data and generates
1481  *        DatIndications towards the higher layers. 
1482  *           
1483  * @param  [in] Inst        inst
1484  *  @param[in]  TfuDatIndInfo *datInd
1485  *  @return  S16
1486  *      -# ROK 
1487  *      -# RFAILED 
1488  **/
1489 #ifdef ANSI
1490 PUBLIC S16 rgTOMDatInd
1491 (
1492 Inst           inst,
1493  TfuDatIndInfo *datInd
1494  )
1495 #else
1496 PUBLIC S16 rgTOMDatInd(inst,datInd)
1497 Inst             inst;
1498  TfuDatIndInfo *datInd;
1499 #endif
1500 {
1501    S16               ret = ROK;
1502    RgErrInfo         err;
1503    RgUeCb            *ueCb;
1504    RgUeCb            *prevUeCb = NULLP;
1505    RgCellCb          *cellCb;
1506    RgMacPdu          *pdu;
1507    RgInfSfDatInd     *sfInfo;
1508    RgInfCeInfo       ceInfo; 
1509    Pst               schPst;
1510    CmLList           *node;
1511    TfuDatInfo        *datInfo;
1512    RgLowSapCb        *tfuSap;
1513    U16               slot;
1514 #ifdef LTEMAC_SPS
1515    Bool              isSpsRnti=FALSE;
1516    Pst               schPst1;  
1517   // RgInfSpsRelInfo   relInfo;
1518         Bool              spsToBeActvtd = FALSE;
1519    U16               sduSize = 0;
1520 #endif
1521    U32               lcgBytes[RGINF_MAX_LCG_PER_UE];
1522
1523
1524    TRC2(rgTOMDatInd);
1525 #ifdef STUB_TTI_HANDLING_5GTF 
1526    node =  datInd->datIndLst.first;
1527    for (;node; node=node->next)
1528    {
1529       datInfo = (TfuDatInfo*)node->node;
1530       {
1531          MsgLen len;
1532          SFndLenMsg(datInfo->mBuf, &len);
1533          rgUlrate_tfu += len;
1534          if (rgUlrate_tfu > 100000)
1535          {
1536          printf("Sowmya:rgTOMDatInd datInfo->mBuf len =%d rgUlrate_tfu=%d",len,rgUlrate_tfu);
1537          rgUlrate_tfu = 0;
1538          }
1539       }
1540    }
1541       return(RFAILED);
1542 #endif      
1543
1544    cmMemset((U8 *)&lcgBytes, 0, sizeof(lcgBytes));
1545
1546    tfuSap = &(rgCb[inst].tfuSap);
1547    ueCb = NULLP;
1548    cellCb = rgCb[inst].cell;
1549    if((cellCb == NULLP) ||
1550       (cellCb->cellId != datInd->cellId))   
1551    {
1552        
1553       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to get the cellCb for cell");
1554       RETVALUE(RFAILED);
1555    }
1556    /* Avoiding memset as all the fields are getting initialized further */
1557
1558    if (rgTOMInfAllocPduEvnt (inst,&sfInfo) != ROK)
1559    {
1560       err.errType = RGERR_TOM_DATIND;
1561       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to Allocate PDU for DUX cell");
1562       node =  datInd->datIndLst.first;
1563       RETVALUE(RFAILED);
1564    }
1565    cmLListInit(&sfInfo->ueLst);
1566    sfInfo->cellId = datInd->cellId;
1567    sfInfo->timingInfo = datInd->timingInfo;
1568    slot = datInd->timingInfo.slot;
1569
1570    node =  datInd->datIndLst.first;
1571    for (;node; node=node->next)
1572    {
1573       datInfo = (TfuDatInfo*)node->node;
1574       {
1575          //extern U32 ulrate_tfu;
1576          MsgLen len;
1577          SFndLenMsg(datInfo->mBuf, &len);
1578 #ifdef STUB_TTI_HANDLING_5GTF         
1579        //  printf("Sowmya:rgTOMDatInd datInfo->mBuf len =%d",len);
1580 #endif
1581          rgUlrate_tfu += len;
1582 #ifdef EMTC_ENABLE
1583          grgUlrate_tfu += len;
1584 #endif
1585       }
1586 #ifdef STUB_TTI_HANDLING_5GTF         
1587       rgLIMUtlFreeDatIndEvnt(datInd,TRUE);
1588 #endif
1589       /* We shall call De-Mux to process the received buffer. We shall try and find
1590        * out the RaCb based on the following - 
1591        * 1. If the incoming PDU contained a CCCH SDU i.e. this is message 3.
1592        * 2. If the incoming PDU contained a CRNTI control element, i.e. we should
1593        * have a ueCb also for this 
1594        */
1595       /* Lets allocate the event that needs to be passed to DUX */
1596       if (rgTOMUtlAllocPduEvnt (inst,&pdu) != ROK)
1597       {
1598          err.errType = RGERR_TOM_DATIND;
1599          RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"Unable to Allocate PDU for DUX cell");
1600          rgTOMInfFreePduEvnt (sfInfo);
1601          RETVALUE(RFAILED);
1602       }
1603
1604       if ((ret = rgDUXDemuxData (inst,pdu, &ceInfo, 
1605                            &datInfo->mBuf, &err)) != ROK)
1606       {
1607          //exit(1);
1608          /* Fix: sriky memory corruption precautions */
1609          rgTOMUtlFreePduEvnt (pdu, TRUE);
1610          err.errType = RGERR_TOM_DATIND;
1611          RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"DUX processing failed");
1612          tfuSap->sapSts.numPduDrop++;
1613          continue; 
1614       }
1615       /* It could be that a non-msg3 pdu contains a CRNTI Control element. We
1616        * should check for CRNTI CE and if it exists the UECb must exist, also an
1617        * if the CRNTI in the CE and the one with which the message came in are
1618        * different we shall look for an raCb as well. 
1619        */
1620
1621       if (ceInfo.bitMask & RG_CCCH_SDU_PRSNT)
1622       {
1623         ret = rgTOMProcCCCHSduInDatInd(pdu, prevUeCb, \
1624                 cellCb, datInfo, &ceInfo, slot);
1625         if (ret == RFAILED)
1626         {
1627             rgTOMUtlFreePduEvnt (pdu, TRUE);
1628             err.errType = RGERR_TOM_DATIND;
1629             tfuSap->sapSts.numPduDrop++;
1630             continue; 
1631         }
1632       } /* end of Msg3 processing */
1633
1634       else if (ceInfo.bitMask & RG_CRNTI_CE_PRSNT)
1635       {
1636         ret = rgTOMProcCrntiCEInDatInd(pdu, prevUeCb, \
1637                 cellCb, datInfo, &ceInfo, slot);
1638         if (ret == RFAILED)
1639         {
1640             rgTOMUtlFreePduEvnt (pdu, TRUE);
1641             err.errType = RGERR_TOM_DATIND;
1642             tfuSap->sapSts.numPduDrop++;
1643             continue; 
1644         }
1645
1646       } /* end of CRNTI based message */
1647       else
1648       {
1649          ueCb = rgDBMGetUeCb (cellCb, datInfo->rnti);
1650          if (ueCb == NULLP)
1651          {
1652 #ifdef LTEMAC_SPS
1653             /* Try getting the UE using SPS-RNTI. */
1654             ueCb = rgDBMGetSpsUeCb (cellCb, datInfo->rnti);
1655             if (ueCb != NULLP)
1656             {
1657                isSpsRnti = TRUE;
1658                /* Increment implrelCntr for an empty transmission */
1659                if (pdu->sduLst.count == 0)
1660                {
1661                   ueCb->ul.implRelCntr++;
1662                   if (ueCb->ul.implRelCntr == ueCb->ul.implRelCnt)
1663                   {
1664                      /* Indicate scheduler for implicit release */
1665                      cmMemset((U8*)&schPst1, (U8)0, sizeof(Pst));
1666                      rgGetPstToInst(&schPst1,inst, cellCb->schInstMap.schInst);
1667
1668                      ueCb->ul.implRelCntr = 0;
1669                      ueCb->ul.explRelCntr = 0;
1670 #if 0                     
1671                                                         relInfo.cellSapId = cellCb->schInstMap.cellSapId;
1672                      relInfo.cRnti = ueCb->ueId;
1673                                                         relInfo.isExplRel= FALSE;
1674                      //TODO: commented for compilation without SCH RgMacSchSpsRel(&schPst1, &relInfo);
1675 #endif  
1676                   }
1677                }
1678                else
1679                {
1680                   /* Reset the implrelCntr */
1681                   ueCb->ul.implRelCntr = 0;
1682                }
1683             }
1684             else
1685 #endif 
1686             {
1687                /* Perform failure if ueCb is still NULLP */
1688                rgTOMUtlFreePduEvnt (pdu, TRUE);
1689                err.errType = RGERR_TOM_DATIND;
1690                RLOG_ARG1(L_ERROR,DBG_CELLID,datInd->cellId,"RNTI:%d Unable to get the UE CB", 
1691                   datInfo->rnti);
1692                tfuSap->sapSts.numPduDrop++;
1693                continue;
1694             }
1695          }
1696 #ifdef LTE_L2_MEAS         
1697      rgTOMUtlL2MStoreBufSz(ueCb, &ceInfo);
1698      rgTOML2MCompileActiveLCs (cellCb, ueCb, pdu, &ceInfo);
1699 #endif
1700 #ifdef LTEMAC_SPS
1701          if ((ret = rgTOMUtlProcMsg(cellCb, ueCb, pdu, isSpsRnti,&spsToBeActvtd,&sduSize, slot, (U32 *)&lcgBytes)) != ROK)
1702 #else
1703          if ((ret = rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, (U32 *)&lcgBytes)) != ROK)
1704 #endif /* LTEMAC_SPS */
1705          {
1706             rgTOMUtlFreePduEvnt (pdu, TRUE);
1707             err.errType = RGERR_TOM_DATIND;
1708             RLOG_ARG1(L_ERROR,DBG_CELLID,datInd->cellId,
1709                             "Unable to handle Data Indication CRNTI:%d",ueCb->ueId);
1710             tfuSap->sapSts.numPduDrop++;
1711             continue;
1712          }
1713       }
1714
1715       
1716 #ifdef LTEMAC_SPS
1717       if(rgTOMUtlInsSchInfo(pdu, sfInfo, &ceInfo, datInfo->rnti,spsToBeActvtd,sduSize, (U32 *)&lcgBytes) != ROK)
1718 #else
1719       if(rgTOMUtlInsSchInfo(pdu, sfInfo, &ceInfo, datInfo->rnti, (U32 *)&lcgBytes) != ROK)
1720 #endif
1721       
1722       {
1723          rgTOMInfFreePduEvnt (sfInfo);
1724          rgTOMUtlFreePduEvnt (pdu, FALSE);
1725          RETVALUE(RFAILED);
1726       }
1727       /* free up the PDU memory */
1728       rgTOMUtlFreePduEvnt (pdu, FALSE);
1729    }
1730    /* Free the allocated memory for ueUlAllocInfo here */
1731 #ifdef LTE_L2_MEAS
1732    if(cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].ueUlAllocInfo != NULLP)
1733    {
1734       /*ccpu00117052 - MOD - Passing double for proper NULLP
1735                              assignment */
1736       rgFreeSBuf(inst,(Data **)&(cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].ueUlAllocInfo), 
1737       ((cellCb->ulSf[(slot % RG_NUM_SUB_FRAMES)].numUe) * sizeof(RgUeUlAlloc)));
1738    }
1739 #endif
1740    /* RRM_RBC_X */
1741    /* Update PRB used for all GBR QCIs to scheduler */
1742     cmMemcpy((U8*) &sfInfo->qcisUlPrbCnt[0],
1743              (U8*) &cellCb->qcisUlPrbCnt[0],
1744              (RGM_MAX_QCI_REPORTS * sizeof(U32)));
1745     /* clear the cellCb ul prb value */
1746     cmMemset((U8*)&cellCb->qcisUlPrbCnt[0], 0, 
1747              (RGM_MAX_QCI_REPORTS * sizeof(U32)));
1748
1749    /* RRM_RBC_Y */
1750
1751    rgGetPstToInst(&schPst, inst,cellCb->schInstMap.schInst);
1752    sfInfo->cellSapId = cellCb->schInstMap.cellSapId;
1753    //TODO: commented for compilation without SCH RgMacSchSfRecp(&schPst, sfInfo);
1754    RETVALUE(ROK);
1755 }  /* rgTOMDatInd */
1756
1757 /**
1758  * @brief Function handles allocation for common channels i.e. BCCH-BCH,
1759  * BCCH-DLSCH, PCCH-DLSCH.
1760  *
1761  * @details
1762  *
1763  *     Function : rgHndlCmnChnl
1764  *     
1765  *     This function is invoked from RgSchMacSfAllocReq. This function handles
1766  *     allocations made for common channels like BCCH and PCCH. 
1767  *
1768  *     Processing steps:
1769  *     1. If BCCH on BCH has been scheduled, send StatusIndication on RGU.
1770  *     2. If PCCH is scheduled, send StatusIndication on RGU.
1771  *     3. If BCCH on DLSCH has been scheduled and sndStatInd is TRUE, send
1772  *     StatusIndication on RGU, else copy the bcch buffer onto the downlink
1773  *     subframe. 
1774  *     
1775  *           
1776  *  @param[in] RgCellCb          *cell,
1777  *  @param[in] CmLteTimingInfo   timingInfo,
1778  *  @param[in] RgInfCmnLcInfo    *cmnLcInfo,
1779  *  @param[in/out] RgErrInfo     *err,
1780  *  @return  S16
1781  *      -# ROK 
1782  *      -# RFAILED
1783  **/
1784 #ifdef ANSI
1785 PRIVATE S16 rgHndlCmnChnl
1786 (
1787 RgCellCb            *cell,
1788 CmLteTimingInfo     timingInfo,
1789 RgInfCmnLcInfo      *cmnLcInfo,
1790 RgErrInfo           *err
1791 )
1792 #else
1793 PRIVATE S16 rgHndlCmnChnl(cell, timingInfo, cmnLcInfo, err)
1794 RgCellCb            *cell;
1795 CmLteTimingInfo     timingInfo;
1796 RgInfCmnLcInfo      *cmnLcInfo;
1797 RgErrInfo           *err;
1798 #endif
1799 {
1800    #if (ERRCLASS & ERRCLS_DEBUG)
1801    RgPcchLcCb           *pcch;
1802    #endif
1803 #ifndef RGR_SI_SCH
1804    RgBcchDlschLcCb      *bcch;
1805 #if (ERRCLASS & ERRCLS_DEBUG)
1806    RgBcchBchLcCb        *bch;
1807 #endif
1808 #endif/*RGR_SI_SCH*/
1809    RguCStaIndInfo       *staInd;
1810    RgDlSf               *dlSf;
1811    Inst                 inst = cell->macInst - RG_INST_START;
1812
1813    TRC2(rgHndlCmnChnl)
1814
1815    dlSf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
1816
1817    if(cmnLcInfo->bitMask & RGINF_BCH_INFO)
1818    {
1819 #ifndef RGR_SI_SCH
1820       #if (ERRCLASS & ERRCLS_DEBUG) 
1821       if(NULLP == (bch = rgDBMGetBcchOnBch(cell)))
1822       {
1823          RETVALUE(RFAILED);
1824       }
1825       if(cmnLcInfo->bchInfo.lcId != bch->lcId)
1826       {
1827          RETVALUE(RFAILED);
1828       }
1829       #endif
1830
1831       if (rgAllocShrablSBuf (inst,(Data**)&staInd, sizeof(RguCStaIndInfo)) != ROK)
1832       {
1833          err->errCause = RGERR_TOM_MEM_EXHAUST;
1834          RETVALUE(RFAILED);
1835       }
1836       staInd->cellId = cell->cellId;
1837       staInd->rnti   = RG_INVALID_RNTI;
1838       staInd->lcId   = cmnLcInfo->bchInfo.lcId;
1839       staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1840 /* ADD Changes for Downlink UE Timing Optimization */
1841 #ifdef LTEMAC_DLUE_TMGOPTMZ
1842       dlSf->remDatReqCnt++;
1843 #endif
1844       if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1845       {
1846          RETVALUE(RFAILED);
1847       }
1848 #else
1849       /*Store the received BCH Data in the scheduled subframe*/
1850       dlSf->bch.tb = cmnLcInfo->bchInfo.pdu;
1851 #endif/*RGR_SI_SCH*/
1852    }
1853
1854    if(cmnLcInfo->bitMask & RGINF_PCCH_INFO)
1855    {
1856       #if (ERRCLASS & ERRCLS_DEBUG) 
1857       if(NULLP == (pcch = rgDBMGetPcch(cell)))
1858       {
1859          RETVALUE(RFAILED);
1860       }
1861       if(cmnLcInfo->pcchInfo.lcId != pcch->lcId)
1862       {
1863          RETVALUE(RFAILED);
1864       }
1865       #endif
1866
1867       dlSf->pcch.pdcch.rnti = 
1868                cmnLcInfo->pcchInfo.rnti;
1869       dlSf->pcch.pdcch.dci = 
1870                cmnLcInfo->pcchInfo.dciInfo;
1871 #ifdef TFU_UPGRADE               
1872       /* ccpu00132314-ADD-Fill the tx Pwr offset from scheduler */         
1873       dlSf->pcch.txPwrOffset = cmnLcInfo->pcchInfo.txPwrOffset;         
1874 #endif
1875       if (rgAllocShrablSBuf (inst,(Data**)&staInd, sizeof(RguCStaIndInfo)) != ROK)
1876       {
1877          err->errCause = RGERR_TOM_MEM_EXHAUST;
1878          RETVALUE(RFAILED);
1879       }
1880       staInd->cellId = cell->cellId;
1881       staInd->rnti   = RG_INVALID_RNTI;
1882       staInd->lcId   = cmnLcInfo->pcchInfo.lcId;
1883       staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1884 /* ADD Changes for Downlink UE Timing Optimization */
1885 #ifdef LTEMAC_DLUE_TMGOPTMZ
1886       dlSf->remDatReqCnt++;
1887 #endif
1888       /* for consolidated CmnStaInd calling below function from function 
1889        * rgHndlSchedUe once CmnStaInd prepared for all UEs
1890        */
1891       if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1892       {
1893          RETVALUE(RFAILED);
1894       }
1895    }
1896
1897    if(cmnLcInfo->bitMask & RGINF_BCCH_INFO)
1898    {
1899       dlSf->bcch.pdcch.rnti = 
1900                cmnLcInfo->bcchInfo.rnti;
1901       dlSf->bcch.pdcch.dci = 
1902                cmnLcInfo->bcchInfo.dciInfo;
1903 #ifdef TFU_UPGRADE               
1904       /* ccpu00132314-ADD-Fill the tx Pwr offset from scheduler */         
1905       dlSf->bcch.txPwrOffset = cmnLcInfo->bcchInfo.txPwrOffset;         
1906 #endif      
1907 #ifndef RGR_SI_SCH
1908       if(NULLP == 
1909          (bcch=rgDBMGetBcchOnDlsch(cell,cmnLcInfo->bcchInfo.lcId)))
1910       {
1911          RETVALUE(RFAILED);
1912       }
1913       if(TRUE == cmnLcInfo->bcchInfo.sndStatInd)
1914       {
1915          RG_FREE_MSG(bcch->tb);
1916          if (rgAllocShrablSBuf (inst,(Data**)&staInd, 
1917                   sizeof(RguCStaIndInfo)) != ROK)
1918          {
1919             err->errCause = RGERR_TOM_MEM_EXHAUST;
1920             RETVALUE(RFAILED);
1921          }
1922          staInd->cellId = cell->cellId;
1923          staInd->rnti   = RG_INVALID_RNTI;
1924          staInd->lcId   = cmnLcInfo->bcchInfo.lcId;
1925          staInd->transId = (timingInfo.sfn << 8) | (timingInfo.slot);
1926 /* ADD Changes for Downlink UE Timing Optimization */
1927 #ifdef LTEMAC_DLUE_TMGOPTMZ
1928          dlSf->remDatReqCnt++;
1929 #endif
1930          if (rgUIMSndCmnStaInd (inst,cell->rguDlSap,staInd) != ROK)
1931          {
1932             RETVALUE(RFAILED);
1933          }
1934       }
1935       else
1936       {
1937          SCpyMsgMsg(bcch->tb, RG_GET_MEM_REGION(rgCb[inst]),
1938                   RG_GET_MEM_POOL(rgCb[inst]), &dlSf->bcch.tb);
1939       }
1940 #else
1941       /*Store the received BCCH Data in the scheduled subframe*/
1942       dlSf->bcch.tb = cmnLcInfo->bcchInfo.pdu;
1943 #endif/*RGR_SI_SCH*/
1944    }
1945
1946    RETVALUE(ROK);
1947 } /* end of rgHndlCmnChnl */
1948
1949 /**
1950  * @brief Function for handling allocations for dedicated channels for a
1951  * subframe.
1952  *
1953  * @details
1954  *
1955  *     Function : rgHndlSchdUe
1956  *     
1957  *     This function shall be invoked whenever scheduler is done with the
1958  *     allocations of dedicated channels for a subframe. Invoked by the function
1959  *     RgSchMacSfAllocReq.
1960  *
1961  *     Processing steps :
1962  *     1. Loops through the list of UE's scheduled looking for the corresponding
1963  *     ueCb/raCb. 
1964  *     2. Finds the corresponding HARQ process.
1965  *     3. Invokes the DHM function to issue StatusIndications on RGU.
1966  *
1967  *           
1968  *  @param[in] RgCellCb            *cell,
1969  *  @param[in] CmLteTimingInfo     timingInfo,
1970  *  @param[in] RgInfUeInfo         *ueInfo
1971  *  @param[in/out] RgErrInfo       *err
1972  *  @return  S16
1973  *      -# ROK 
1974  *      -# RFAILED 
1975  **/
1976 #ifdef ANSI
1977 PRIVATE S16 rgHndlSchdUe
1978 (
1979 RgCellCb            *cell,
1980 CmLteTimingInfo     timingInfo,
1981 RgInfUeInfo         *ueInfo,
1982 RgErrInfo           *err
1983 )
1984 #else
1985 PRIVATE S16 rgHndlSchdUe(cell, timingInfo, ueInfo, err) /* laa_ut_fix */
1986 RgCellCb            *cell;
1987 CmLteTimingInfo     timingInfo;
1988 RgInfUeInfo         *ueInfo;
1989 RgErrInfo           *err;
1990 #endif
1991 {
1992
1993    TRC2(rgHndlSchdUe);
1994
1995    if(NULLP == ueInfo->allocInfo)
1996    {
1997       RETVALUE(RFAILED);
1998    }
1999
2000    rgDHMSndConsolidatedStaInd(cell, ueInfo, timingInfo, err);
2001
2002    RETVALUE(ROK);
2003 } /* end of rgHndlSchdUe */
2004
2005 #ifdef LTE_L2_MEAS
2006 /**
2007  * @brief Function for handling Uplink allocations for Ue for a
2008  * subframe.
2009  *
2010  * @details
2011  *
2012  *     Function : rgHndlUlUeInfo
2013  *     
2014  *  @param[in] RgCellCb            *cell,
2015  *  @param[in] CmLteTimingInfo     timingInfo,
2016  *  @param[in] RgInfUlUeInfo       *ueInfo
2017  *  @return  S16
2018  *      -# ROK 
2019  *      -# RFAILED 
2020  **/
2021 #ifdef ANSI
2022 PRIVATE S16 rgHndlUlUeInfo
2023 (
2024 RgCellCb            *cell,
2025 CmLteTimingInfo     timingInfo,
2026 RgInfUlUeInfo       *ueInfo
2027 )
2028 #else
2029 PRIVATE S16 rgHndlUlUeInfo(cell, timingInfo, ueInfo)
2030 RgCellCb            *cell;
2031 CmLteTimingInfo     timingInfo;
2032 RgInfUlUeInfo       *ueInfo;
2033 #endif
2034 {
2035    Inst           inst = cell->macInst - RG_INST_START;
2036    U8             idx;
2037    RgUlSf         *ulSf;
2038    S16            ret;
2039
2040    TRC2(rgHndlUlUeInfo)
2041    
2042    ulSf = &cell->ulSf[(timingInfo.slot % RGSCH_NUM_SUB_FRAMES)];
2043
2044    /* rg003.301-MOD- Corrected the purifier memory leak */
2045    if (ulSf->numUe != ueInfo->numUes)
2046    {
2047       if (ulSf->ueUlAllocInfo)
2048       {
2049          rgFreeSBuf(inst,(Data **)&(ulSf->ueUlAllocInfo),
2050                ulSf->numUe * sizeof(RgUeUlAlloc));
2051       }
2052    }
2053 #ifdef XEON_SPECIFIC_CHANGES
2054    CM_MEAS_TIME((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MEAS_FREE);
2055    CM_ADD_INFO((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES),  CM_DBG_MEAS_FREE, ulSf->numUe);
2056 #endif
2057    ulSf->numUe         = ueInfo->numUes;
2058    if((ulSf->ueUlAllocInfo == NULLP) && (ueInfo->numUes > 0))
2059    {
2060        /* Allocate memory for ulAllocInfo */
2061        if((ret = rgAllocSBuf(inst,(Data**)&(cell->ulSf[(timingInfo.slot % RGSCH_NUM_SUB_FRAMES)].
2062                  ueUlAllocInfo), ueInfo->numUes *  sizeof(RgUeUlAlloc))) != ROK)
2063        {
2064           RETVALUE(ret);
2065        }
2066    }
2067 #ifdef XEON_SPECIFIC_CHANGES
2068    CM_MEAS_TIME((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MEAS_ALLOC);
2069    CM_ADD_INFO((cell->crntTime.slot % RGSCH_NUM_SUB_FRAMES), CM_DBG_MEAS_ALLOC, ueInfo->numUes);
2070 #endif
2071    if (ulSf->ueUlAllocInfo != NULLP)
2072    {
2073       for(idx = 0; idx < ueInfo->numUes; idx++)
2074       {
2075          ulSf->ueUlAllocInfo[idx].rnti   = ueInfo->ulAllocInfo[idx].rnti;
2076          ulSf->ueUlAllocInfo[idx].numPrb = ueInfo->ulAllocInfo[idx].numPrb;
2077       }
2078    }
2079    RGCPYTIMEINFO(timingInfo, ulSf->schdTime);
2080    RETVALUE(ROK);
2081 } /* end of rgHndlUlUeInfo */
2082 #endif
2083 /**
2084  * @brief Function for handling RaResp request received from scheduler to MAC
2085  *
2086  * @details
2087  *
2088  *     Function : rgTOMRlsSf
2089  *     
2090  *     This function shall be invoked whenever scheduler is done with the
2091  *     allocations of random access responses for a subframe.
2092  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
2093  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
2094  *     
2095  *           
2096  *  @param[in] Inst        inst
2097  *  @param[in] CmLteCellId         cellId,
2098  *  @param[in] CmLteTimingInfo     timingInfo,
2099  *  @param[in] RaRespInfo          *rarInfo
2100  *  @return  S16
2101  *      -# ROK 
2102  **/
2103 #ifdef ANSI
2104 PUBLIC Void rgTOMRlsSf
2105 (
2106 Inst                inst,
2107 RgDlSf              *dlSf
2108 )
2109 #else
2110 PUBLIC Void rgTOMRlsSf(dlSf)
2111 Inst                inst;
2112 RgDlSf              *dlSf;
2113 #endif
2114 {
2115    U8               idx;
2116
2117    TRC2(rgTOMRlsSf)
2118
2119    if(dlSf->txDone == FALSE)
2120    {
2121       RLOG0(L_ERROR, "SUBFRAME Not pushed to the PHY");
2122
2123       if (dlSf->bch.tb != NULLP)
2124       {
2125          RG_FREE_MSG(dlSf->bch.tb);
2126       }
2127       if (dlSf->bcch.tb != NULLP)
2128       {
2129          RG_FREE_MSG(dlSf->bcch.tb);
2130       }
2131       if (dlSf->pcch.tb != NULLP)
2132       {
2133          RG_FREE_MSG(dlSf->pcch.tb);
2134       }
2135 #ifdef EMTC_ENABLE
2136       rgTOMEmtcRlsSf(dlSf);
2137 #endif
2138       for(idx=0; idx < dlSf->numRaRsp; idx++)
2139       {
2140          RG_FREE_MSG(dlSf->raRsp[idx].rar);
2141       }
2142    }
2143 /* ADD Changes for Downlink UE Timing Optimization */
2144 #ifdef LTEMAC_DLUE_TMGOPTMZ
2145    dlSf->remDatReqCnt = 0;
2146    /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2147       RLC-MAC */
2148    dlSf->statIndDone = FALSE;
2149 #endif
2150          if (dlSf->tbs.count)
2151          {
2152       U8           i;
2153       CmLList      *node;
2154       RgDlHqProcCb *hqP;
2155        RGDBGERRNEW(inst, (rgPBuf(inst),
2156                 "Error Stale TBs in Subframes TBS list\n"));
2157       node = dlSf->tbs.first;
2158                   while(node)
2159                   {
2160          hqP = (RgDlHqProcCb*)node->node;
2161          node = node->next;
2162           if (hqP)
2163           {
2164                      for(i=0;i< RG_MAX_TB_PER_UE;i++)
2165                      {
2166                                     if (hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sf == dlSf)
2167                                     {
2168                                              cmLListDelFrm(&dlSf->tbs, &(hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sfLnk));
2169                                              hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sfLnk.node = NULLP;
2170                     printf("\n rgTOMRlsSf:: hqP %p \n", (Void *)hqP);
2171                                     }
2172                                     hqP->tbInfo[i].sfLnkInfo[dlSf->schdTime.slot % 2].sf = NULLP;
2173                            }
2174                         }
2175          }
2176     }
2177     /*arjun: check if dlSf laaTb list has to be freed???*/
2178    cmLListInit(&dlSf->tbs);
2179    dlSf->txDone = FALSE;
2180    dlSf->numRaRsp = 0;
2181    RETVOID;
2182 }
2183
2184 /**
2185  * @brief Function is called by the scheduler once it has completed the
2186  * allocation for the subframe. 
2187  *
2188  * @details
2189  *
2190  *     Function : rgHndlFlowCntrl
2191  *     This function should fill and send Flow control 
2192  *     indication to RLC
2193  *
2194  *           
2195  *  @param[in] Pst                 *cell       
2196  *  @param[in] RgInfSfAlloc        *sfInfo   Carries all the allocation
2197  *  information.
2198  *  @return  S16
2199  *      -# ROK 
2200  **/
2201 #ifdef ANSI
2202 PUBLIC S16 rgHndlFlowCntrl
2203 (
2204 RgCellCb       *cell,
2205 RgInfSfAlloc        *sfInfo
2206 )
2207 #else
2208 PUBLIC S16 rgHndlFlowCntrl(cell, sfInfo)
2209 RgCellCb            *cell;
2210 RgInfSfAlloc        *sfInfo;
2211 #endif
2212 {
2213    RguFlowCntrlInd  *flowCntrlInd;
2214    Pst              *pst;
2215    U32              ueIdx;
2216    U32              lcIdx;
2217    TRC3(rgHndlFlowCntrl);
2218
2219    pst = &cell->rguDlSap->sapCfg.sapPst;
2220    /* flowCntrlInd is alloced in cell init time and will be re-used throughout */
2221    flowCntrlInd = cell->flowCntrlInd;
2222    flowCntrlInd->cellId = sfInfo->cellId;
2223    flowCntrlInd->numUes = sfInfo->flowCntrlInfo.numUes; 
2224   
2225    for (ueIdx = 0; ueIdx < sfInfo->flowCntrlInfo.numUes; ueIdx++)
2226    {
2227       flowCntrlInd->ueFlowCntrlInfo[ueIdx].ueId = sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].ueId;
2228       flowCntrlInd->ueFlowCntrlInfo[ueIdx].numLcs = sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].numLcs;
2229       
2230       for (lcIdx = 0; lcIdx < RGINF_MAX_NUM_DED_LC; lcIdx++)
2231       {
2232          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].lcId =
2233          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].lcId;
2234          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].pktAdmitCnt = 
2235          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].pktAdmitCnt;
2236         
2237          flowCntrlInd->ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].maxBo4FlowCtrl = 
2238          sfInfo->flowCntrlInfo.ueFlowCntrlInfo[ueIdx].lcInfo[lcIdx].maxBo4FlowCtrl;
2239       }
2240    }
2241    RgUiRguFlowCntrlInd(pst, cell->rguDlSap->sapCfg.spId,flowCntrlInd); /* TODO: Rishi confirm if the suId and pst pointer is correct */
2242    RETVALUE(ROK);
2243 }
2244 /**
2245  * @brief Function is called by the scheduler once it has completed the
2246  * allocation for the subframe. 
2247  *
2248  * @details
2249  *
2250  *     Function : RgSchMacSfAllocReq
2251  *     
2252  *     This function shall be invoked whenever scheduler is done with the
2253  *     allocations of for a subframe. The sfInfo carries all the allocation
2254  *     details for the common channels, RA responses and dedicated channel
2255  *     allocations. 
2256  *
2257  *     Processing steps :
2258  *     1. Reset the information present in the downlink subframe that is
2259  *     scheduled.
2260  *     2. Handle common channel allocations
2261  *     3. Handle RA Response allocations
2262  *     4. Handle dedicated channel allocations.
2263  *           
2264  *  @param[in] Pst                 *pst       
2265  *  @param[in] RgInfSfAlloc        *sfInfo   Carries all the allocation
2266  *  information.
2267  *  @return  S16
2268  *      -# ROK 
2269  **/
2270 #ifdef ANSI
2271 PUBLIC S16 RgSchMacSfAllocReq
2272 (
2273 Pst                 *pst,
2274 RgInfSfAlloc        *sfInfo
2275 )
2276 #else
2277 PUBLIC S16 RgSchMacSfAllocReq(pst, sfInfo)
2278 Pst                 *pst;
2279 RgInfSfAlloc        *sfInfo;
2280 #endif
2281 {
2282    RgCellCb       *cell;
2283    RgDlSf         *dlSf;
2284    RgErrInfo      err;
2285    VOLATILE U32   startTime=0;
2286    Inst           inst;
2287
2288    TRC2(RgSchMacSfAllocReq)
2289
2290    RG_IS_INST_VALID(pst->dstInst);
2291    inst = pst->dstInst - RG_INST_START;
2292    /*starting Task*/
2293    SStartTask(&startTime, PID_MAC_SF_ALLOC_REQ);
2294
2295    if(NULLP == sfInfo)
2296    {
2297       RETVALUE(RFAILED);
2298    }
2299
2300    if((cell = rgCb[inst].cell) == NULLP)
2301    {
2302       RLOG_ARG0(L_ERROR,DBG_CELLID,sfInfo->cellId, "No cellCb found with cell");
2303       RETVALUE(RFAILED);
2304    }
2305
2306    dlSf = &cell->subFrms[(sfInfo->timingInfo.slot % RG_NUM_SUB_FRAMES)];
2307
2308    rgTOMRlsSf(inst,dlSf);
2309    dlSf->schdTime = sfInfo->timingInfo;
2310
2311 #ifdef LTE_ADV
2312    rgLaaInitTbInfoLst(cell);
2313 #endif
2314
2315    /* Fix : syed Ignore Failure Returns and continue processing.
2316     * Incomplete processing results in state sync loss between MAC-SCH. */
2317 #ifdef EMTC_ENABLE
2318     if(TRUE == cell->emtcEnable)
2319     {
2320        rgEmtcHndl(cell, sfInfo);
2321     }
2322 #endif
2323    rgHndlCmnChnl(cell, sfInfo->timingInfo, &sfInfo->cmnLcInfo, &err);
2324
2325    rgHndlRaResp(cell, sfInfo->timingInfo, &sfInfo->rarInfo, &err);
2326
2327 #ifdef LTE_ADV
2328 #ifdef XEON_SPECIFIC_CHANGES
2329    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_B4_UE_SCHD);
2330 #endif
2331    rgHndlSchdUe(cell, sfInfo->timingInfo, &sfInfo->ueInfo, &err);
2332 #ifdef XEON_SPECIFIC_CHANGES
2333    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_UE_SCHD);
2334 #endif
2335    rgLaaChkAndReqTbs(dlSf,cell, inst);
2336
2337 #else
2338    rgHndlSchdUe(cell, sfInfo->timingInfo, &sfInfo->ueInfo, &err);
2339 #endif
2340
2341 #ifdef LTE_L2_MEAS
2342    if(rgHndlUlUeInfo(cell, sfInfo->ulUeInfo.timingInfo, 
2343                      &sfInfo->ulUeInfo) != ROK)
2344    {
2345       RETVALUE(RFAILED);
2346    }
2347 #endif
2348 #ifdef XEON_SPECIFIC_CHANGES
2349    CM_MEAS_TIME((cell->crntTime.slot % RG_NUM_SUB_FRAMES), CM_DBG_MAC_TTI_IND, CM_DBG_MAC_MEAS);
2350 #endif
2351    /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2352       RLC-MAC */
2353
2354
2355    /* Added the handling for pushing down
2356     * TFU Data request in the retransmission only scenario.*/ 
2357 #ifdef LTEMAC_DLUE_TMGOPTMZ
2358    dlSf->statIndDone = TRUE;
2359    /* Fix [ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
2360       RLC-MAC */
2361    if(!(dlSf->txDone) && 
2362 #ifdef LTE_ADV
2363          (TRUE == rgLaaChkAllRxTbs(dlSf)) && 
2364 #endif
2365          (0 == dlSf->remDatReqCnt) && (dlSf->statIndDone) && 
2366         (RG_TIMEINFO_SAME(cell->crntTime, dlSf->schdTime)))
2367    {
2368       /*This is the case of rettransmission, so no need
2369        * to wait for TTI Ind to push TFU Data Request. Send
2370        * it right away.*/
2371       if (ROK != rgTOMUtlProcDlSf (dlSf, cell, &err))
2372       {
2373          RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Unable to process downlink subframe for cell");
2374          err.errType = RGERR_ROM_DEDDATREQ;
2375       }
2376       /* Mark this frame as sent */
2377       dlSf->txDone = TRUE;
2378    }
2379 #endif
2380    if (sfInfo->flowCntrlInfo.numUes > 0)
2381    {
2382      rgHndlFlowCntrl(cell,sfInfo);
2383    }
2384    /*stoping Task*/
2385    SStopTask(startTime, PID_MAC_SF_ALLOC_REQ);
2386    RETVALUE(ROK);
2387 } /* end of RgSchMacSfAllocReq */
2388 /**
2389  * @brief Handler for processing data indication recieved from PHY for UEs.
2390  *
2391  * @details
2392  *
2393  *     Function: rgTOMProcCrntiCEInDatInd
2394  *
2395  *     Handler for processing data indication recieved from PHY for UEs.
2396  *
2397  *     Invoked by: RgLiTfuDatInd of LIM 
2398  *
2399  *     Processing Steps: 
2400  *     For each DataInfo recieved
2401  *      - If  received a CRNTI control element 
2402  *          - Check if a CCCH SDU is present, if it is return failure
2403  *          - Check for the existence of UE, if its isnt present return failure.
2404  *          - Delegate the remaining processing to rgTOMUtlProcMsg3 which
2405  *          primarily informs the scheduler about the data received and
2406  *          generates Data indications towards the higher layer.
2407  *           
2408  *  @param      RgMacPdu          *pdu,
2409  *  @param      RgUeCb            *prevUeCb,
2410  *  @param      RgCellCb          *cellCb,
2411  *  @param      TfuDatInfo        *datInfo,
2412  *  @param      RgInfCeInfo       *ceInfo
2413  *  @return  S16
2414  *      -# ROK 
2415  *      -# RFAILED 
2416  **/
2417 #ifdef ANSI
2418 PRIVATE S16 rgTOMProcCrntiCEInDatInd
2419 (
2420 RgMacPdu          *pdu,
2421 RgUeCb            *prevUeCb,
2422 RgCellCb          *cellCb,
2423 TfuDatInfo        *datInfo,
2424 RgInfCeInfo       *ceInfo,
2425 U16               slot
2426 )
2427 #else
2428 PRIVATE S16 rgTOMProcCrntiCEInDatInd( pdu, prevUeCb, cellCb, datInfo, ceInfo, slot)
2429 RgMacPdu          *pdu;
2430 RgUeCb            *prevUeCb;
2431 RgCellCb          *cellCb;
2432 TfuDatInfo        *datInfo;
2433 RgInfCeInfo       *ceInfo;
2434 U16               slot;
2435 #endif
2436 {
2437    RgUeCb *ueCb = NULLP;
2438    Inst   inst  = cellCb->macInst - RG_INST_START;
2439
2440
2441 #ifdef LTEMAC_SPS
2442    Bool spsToBeActvtd;
2443    U16  sduSize;
2444 #endif
2445
2446    TRC2(rgTOMProcCrntiCEInDatInd)
2447
2448 #ifndef LTE_L2_MEAS      
2449       UNUSED(slot);
2450 #endif
2451
2452    ueCb = rgDBMGetUeCbFromRachLst (cellCb, datInfo->rnti);
2453
2454    if (ueCb == NULLP)
2455    {
2456        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2457                 "RNTI:%d Received MSG3 with CRNTI,unable to find ueCb", ceInfo->ces.cRnti);
2458        RETVALUE(RFAILED);
2459    }
2460
2461    prevUeCb = rgDBMGetUeCb (cellCb, ceInfo->ces.cRnti);
2462    if (prevUeCb == NULLP)
2463    {
2464        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2465                  "RNTI:%d Received MSG3 with CRNTI,unable to find ueCb", ceInfo->ces.cRnti);
2466        RETVALUE(RFAILED);
2467    }
2468    RLOG_ARG2(L_DEBUG,DBG_CELLID,cellCb->cellId,
2469             "CRNTI CE(%d) received through tmpCrnti(%d)",
2470             ceInfo->ces.cRnti, datInfo->rnti);
2471    rgDBMDelUeCbFromRachLst(cellCb, ueCb);
2472    rgRAMFreeUeCb(inst,ueCb);
2473    ueCb = prevUeCb;
2474 #ifdef LTEMAC_SPS
2475    if ((rgTOMUtlProcMsg(cellCb, ueCb, pdu, FALSE,&spsToBeActvtd,&sduSize, slot, NULLP)) != ROK)
2476 #else
2477    if ((rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, NULLP)) != ROK)
2478 #endif /* LTEMAC_SPS */
2479    {
2480        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2481                        "RNTI:%d Processing for MSG3 failed",datInfo->rnti);
2482        RETVALUE(RFAILED);
2483    }
2484    RETVALUE(ROK);
2485 }
2486 /**
2487  * @brief Handler for processing data indication recieved from PHY for UEs.
2488  *
2489  * @details
2490  *
2491  *     Function: rgTOMProcCCCHSduInDatInd
2492  *
2493  *     Handler for processing data indication recieved from PHY for UEs.
2494  *
2495  *     Invoked by: RgLiTfuDatInd of LIM 
2496  *
2497  *     Processing Steps: 
2498  *     For each DataInfo recieved
2499  *      - If only CCCH SDU is present
2500  *        - Invoke rgTOMUtlProcMsg3 for further processing.
2501  *      - If its a non-Msg3 PDU i.e. received outside of a RA procedure
2502  *        - Retrieve the UeCB 
2503  *        - Validate that the received PDU contains only configured Logical
2504  *        Channels.
2505  *        - Invoke rgTOMUtlProcDatPdu for further processing. It informs the
2506  *        scheduler with the information of the received Data and generates
2507  *        DatIndications towards the higher layers. 
2508  *           
2509  *  @param  TfuDatIndInfo *datInd
2510  *  @param  RgMacPdu          *pdu,
2511  *  @param  RgUeCb            *prevUeCb,
2512  *  @param  RgCellCb          *cellCb,
2513  *  @param  TfuDatInfo        *datInfo,
2514  *  @param  RgInfCeInfo       *ceInfo
2515  *  @return  S16
2516  *      -# ROK 
2517  *      -# RFAILED 
2518  **/
2519 #ifdef ANSI
2520 PRIVATE S16 rgTOMProcCCCHSduInDatInd
2521 (
2522 RgMacPdu          *pdu,
2523 RgUeCb            *prevUeCb,
2524 RgCellCb          *cellCb,
2525 TfuDatInfo        *datInfo,
2526 RgInfCeInfo       *ceInfo,
2527 U16               slot 
2528 )
2529 #else
2530 PRIVATE S16 rgTOMProcCCCHSduInDatInd( pdu, prevUeCb, cellCb, datInfo, ceInfo, slot)
2531 RgMacPdu          *pdu;
2532 RgUeCb            *prevUeCb;
2533 RgCellCb          *cellCb;
2534 TfuDatInfo        *datInfo;
2535 RgInfCeInfo       *ceInfo;
2536 U16               slot;
2537 #endif
2538 {
2539    RgUeCb *ueCb = NULLP;
2540    Inst   inst  = cellCb->macInst - RG_INST_START;
2541
2542 #ifdef LTEMAC_SPS
2543    Bool spsToBeActvtd;
2544    U16  sduSize;
2545 #endif
2546
2547
2548    TRC2(rgTOMProcCCCHSduInDatInd)
2549
2550 #ifndef LTE_L2_MEAS      
2551       UNUSED(slot);
2552 #endif
2553
2554    if (ceInfo->bitMask & RG_CRNTI_CE_PRSNT)
2555    {
2556        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2557                        "CRNTI:%d Received MSG3 with CCCH",ceInfo->ces.cRnti);
2558        RETVALUE(RFAILED);
2559    }
2560    
2561    ueCb = rgDBMGetUeCbFromRachLst (cellCb, datInfo->rnti);
2562    
2563    if (ueCb == NULLP)
2564    {
2565        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,
2566                        "RNTI:%d Processing for MSG3 failed", datInfo->rnti);
2567        RETVALUE(RFAILED);
2568    }
2569    /* Fix: syed Drop any duplicate Msg3(CCCH Sdu) */
2570    if (ueCb->dl.hqEnt.numHqProcs)
2571    {
2572       /* HqE is already initialized by a previuos Msg3 */ 
2573        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Processing for MSG3 failed. Duplicate "
2574           "MSG3 received. Dropping", datInfo->rnti);
2575        RETVALUE(RFAILED);
2576    }
2577    
2578    if(rgDHMHqEntInit(inst,&ueCb->dl.hqEnt,
2579                      cellCb->maxDlHqProcPerUe) != ROK)
2580    {
2581        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Harq Initialization failed ", 
2582           datInfo->rnti);
2583        RETVALUE(RFAILED);
2584    }
2585     RLOG_ARG1(L_DEBUG,DBG_CELLID,cellCb->cellId,
2586              "CCCH SDU received through tmpCrnti(%d)",datInfo->rnti);
2587 #ifdef LTEMAC_SPS
2588    if ((rgTOMUtlProcMsg(cellCb, ueCb, pdu, FALSE,&spsToBeActvtd,&sduSize, slot, NULLP)) != ROK)
2589 #else
2590    if ((rgTOMUtlProcMsg (cellCb, ueCb, pdu, slot, NULLP)) != ROK)
2591 #endif /* LTEMAC_SPS */
2592    {
2593        RLOG_ARG1(L_ERROR,DBG_CELLID,cellCb->cellId,"RNTI:%d Processing for MSG3 failed", 
2594           datInfo->rnti);
2595        RETVALUE(RFAILED);
2596    }
2597    RETVALUE(ROK);
2598 }
2599
2600 #ifdef LTE_L2_MEAS
2601
2602 /** @brief This function captures the BSR value from Control Element
2603  *  Info structure and updates the effective Buffer size into the 
2604  *  corresponding LCG ID. 
2605  *
2606  * @details 
2607  *
2608  *     Function: rgTOMUtlL2MStoreBufSz
2609  *
2610  *         Processing steps:
2611  *         - update/append the Data structure based on BSR type 
2612  *
2613  * @param  [in] RgUeCb     *ueCb
2614  * @param  [in] RgInfCeInfo *ceInfo
2615  * @return S16
2616  */
2617
2618 #ifdef ANSI
2619 PRIVATE S16 rgTOMUtlL2MStoreBufSz
2620 (
2621  RgUeCb      *ueCb,
2622  RgInfCeInfo *ceInfo
2623  )
2624 #else
2625 PRIVATE S16 rgTOMUtlL2MStoreBufSz (ueCb, ceInfo)
2626  RgUeCb      *ueCb;
2627  RgInfCeInfo *ceInfo;
2628 #endif
2629 {
2630    U8 lcgId;
2631    U8 bsr;
2632    TRC2(rgTOMUtlL2MStoreBufSz);
2633
2634    if(ceInfo->bitMask & RG_TRUNC_BSR_CE_PRSNT)
2635    {
2636       lcgId = ((ceInfo->ces.bsr.truncBsr >> 6) & 0x03);
2637       bsr = ceInfo->ces.bsr.truncBsr & 0x3F;
2638       ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = rgLwrBsrTbl[bsr];
2639    }
2640    else if(ceInfo->bitMask & RG_SHORT_BSR_CE_PRSNT)
2641    {
2642       lcgId = ((ceInfo->ces.bsr.shortBsr >> 6) & 0x03);
2643       bsr = ceInfo->ces.bsr.shortBsr & 0x3F;
2644       ueCb->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = rgLwrBsrTbl[bsr];
2645
2646    }
2647    else if(ceInfo->bitMask & RG_LONG_BSR_CE_PRSNT)
2648    {
2649       ueCb->ul.lcgArr[0].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs1];
2650       ueCb->ul.lcgArr[1].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs2];
2651       ueCb->ul.lcgArr[2].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs3];
2652       ueCb->ul.lcgArr[3].lcgBsInfo.outStndngBs = rgLwrBsrTbl[ceInfo->ces.bsr.longBsr.bs4];
2653    }
2654    RETVALUE(ROK);
2655 } /* end of rgTOMUtlL2MStoreBufSz*/
2656
2657 /** @brief : Compiles list of LCs received in UL data for DTCH RBs
2658  *
2659  * @details
2660  *
2661  * @param  [in] RgCellCb   *cellCb
2662  * @param  [in] RgUeCb     *ueCb
2663  * @param  [in] CmLteRnti  rnti
2664  * @param  [in] RgMacPdu   *pdu
2665  * @param 
2666  *  @return  S16
2667  *      -# ROK 
2668  *      -# RFAILED 
2669  */
2670 #ifdef ANSI
2671 PRIVATE Void rgTOML2MCompileActiveLCs
2672 (
2673  RgCellCb      *cellCb, 
2674  RgUeCb        *ueCb,
2675  RgMacPdu      *pdu,
2676  RgInfCeInfo   *ceInfo 
2677  )
2678 #else
2679 PRIVATE Void rgTOML2MCompileActiveLCs(cellCb, ueCb, pdu, ceInfo)
2680    RgCellCb      *cellCb; 
2681    RgUeCb        *ueCb;
2682    RgMacPdu      *pdu;
2683    RgInfCeInfo   *ceInfo; 
2684 #endif 
2685 {
2686    CmLList           *node;
2687    RgMacSdu          *sdu;
2688    RgUlLcCb          *ulLcCb;
2689
2690    TRC2(rgTOML2MCompileActiveLCs)
2691
2692    node =  pdu->sduLst.first;
2693    while (node)
2694    {
2695       sdu = (RgMacSdu*)node->node;
2696       
2697       if ((ulLcCb = rgDBMGetUlDedLcCb(ueCb, sdu->lcId)), ulLcCb != NULLP)
2698       {
2699          if (ulLcCb->lcgId != 0)
2700          {
2701             ceInfo->bitMask |= RG_ACTIVE_LC_PRSNT;
2702             ceInfo->ulActLCs[ulLcCb->lcId - 1] = TRUE;
2703          }
2704       }
2705       node = node->next;
2706    }
2707
2708 } /* end of */ 
2709
2710
2711
2712 #endif
2713 /**********************************************************************
2714  
2715          End of file
2716 **********************************************************************/