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