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