Initial commit
[o-du/l2.git] / src / 5gnrmac / rg_utl.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_utl.c
28   
29 **********************************************************************/
30
31 /** @file rg_utl.c
32 @brief This file implements utility functions for LTE MAC
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_MODULE_ID=4096;
37 static int RLOG_FILE_ID=179;
38
39 /* header include files (.h) */
40 #include "envopt.h"        /* environment options */
41 #include "envdep.h"        /* environment dependent */
42 #include "envind.h"        /* environment independent */
43   
44 #include "gen.h"           /* general */
45 #include "ssi.h"           /* system services */
46 #include "cm_tkns.h"       /* Common Token Defines */
47 #include "cm_llist.h"      /* Common Link List Defines */
48 #include "cm_hash.h"       /* Common Hash List Defines */
49 #include "cm_mblk.h"       /* common memory link list library */
50 #include "cm_lte.h"        /* Common LTE */
51
52 #include "rg_env.h"        /* MAC Environment Defines */
53 #include "crg.h"           /* CRG Interface defines */
54 #include "rgu.h"           /* RGU Interface defines */
55 #include "tfu.h"           /* TFU Interface defines */
56 #include "rg_sch_inf.h"    /* RGR Interface defines */
57 #include "lrg.h"           /* LRG Interface defines */
58
59 #include "rg_prg.h"        /* PRG(MAC-MAC) Interface includes */
60 #include "rg.h"            /* MAC defines */
61 #include "rg_err.h"        /* MAC error defines */
62
63 /* header/extern include files (.x) */
64 #include "gen.x"           /* general */
65 #include "ssi.x"           /* system services */
66 #include "cm5.x"           /* Timer */
67 #include "cm_tkns.x"       /* Common Token Definitions */
68 #include "cm_llist.x"      /* Common Link List Definitions */
69 #include "cm_lib.x"        /* Common Library Definitions */
70 #include "cm_hash.x"       /* Common Hash List Definitions */
71 #include "cm_mblk.x"       /* common memory link list library */
72 #include "cm_lte.x"        /* Common LTE */
73
74 #include "crg.x"           /* CRG Interface includes */
75 #include "rgu.x"           /* RGU Interface includes */
76 #include "tfu.x"           /* TFU Interface includes */
77 #include "rg_sch_inf.x"    /* RGR Interface includes */
78 #include "lrg.x"           /* LRG Interface includes */
79 #include "rg_prg.x"        /* PRG(MAC-MAC) Interface includes */
80
81 #include "rg.x"            /* MAC includes */
82
83 /* local defines */
84 #define RG_NON_MIMO_IDX 0
85
86 /* local typedefs */
87  
88 /* local externs */
89  
90 /* forward references */
91 PRIVATE S16 rgUtlHndlCrntiChng ARGS((
92          Inst            inst,
93          RgCellCb        *cell,
94          CmLteRnti       rnti,
95          CmLteRnti       newRnti
96          ));
97 PRIVATE Void rgUtlHndlCrntiRls ARGS((
98          RgCellCb        *cell,
99          RgInfRlsRnti    *rlsRnti
100          ));
101
102 PUBLIC S16 rgDelUeFrmAllSCell ARGS((
103          RgCellCb       *cell,
104          RgUeCb         *ue
105          ));
106
107 #ifdef LTE_ADV
108 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs ARGS((
109          RgCellCb        *cell,
110          CmLteRnti       rnti,
111          CmLteRnti       newRnti
112          ));
113 #endif
114 /***********************************************************
115  *
116  *     Func : rgAllocShrablSBuf
117  *
118  *     Desc : Utility Function to Allocate static buffer which is 
119  *            sharable among different layers if YYYY flag is enabled. 
120  *            else it allocates from normal static region
121  *            Memory allocated is assumed contiguous.
122  *            
123  *
124  *     Ret  : ROK
125  *            RFAILED
126  *
127  *     Notes: Caller doesnt need to raise the alarm in case of memory
128  *            allocation gets failed. 
129  *
130  *     File : rg_utl.c
131  *
132  **********************************************************/
133 #ifdef ANSI
134 PUBLIC S16 rgAllocShrablSBuf
135 (
136 Inst    inst,
137 Data    **pData,            /* Pointer of the data to be returned */
138 Size    size                /* size */
139 )
140 #else
141 PUBLIC S16 rgAllocShrablSBuf(inst,pData, size)
142 Inst    inst;
143 Data    **pData;            /* Pointer of the data to be returned */
144 Size    size;               /* size */
145 #endif
146 {
147    RgUstaDgn dgn;      /* Alarm diagnostics structure */
148
149    TRC2(rgAllocShrablSBuf)
150
151    /* Initialize the param to NULLP */
152    *pData = NULLP;
153
154    if (size == 0)
155    {
156       RETVALUE(RFAILED);
157    }
158
159    /* allocate buffer */
160    if (SGetStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size, 0) != ROK)
161    {
162      dgn.type = LRG_USTA_DGNVAL_MEM;
163      dgn.u.mem.region = rgCb[inst].rgInit.region;
164      dgn.u.mem.pool = rgCb[inst].rgInit.pool;
165      /*  Send an alarm to Layer Manager */
166      rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
167                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
168       RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
169       RETVALUE(RFAILED);
170    }
171
172 #ifndef ALIGN_64BIT
173    RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%ld)), Data (0x%p))\n",
174              rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
175 #else
176    RGDBGINFO(inst,(rgPBuf(inst), "SGetSBuf(Region (%d), Pool (%d), Size (%d)), Data (0x%p))\n",
177              rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, size, *pData));
178 #endif
179
180    /* zero out the allocated memory */
181    cmMemset((U8 *)*pData, 0x00, size);
182
183    RETVALUE(ROK);
184
185 } /* end of rgAllocSBuf */
186
187
188 /***********************************************************
189  *
190  *     Func : rgAllocSBuf
191  *
192  *     Desc : Utility Function to Allocate static buffer. 
193  *            Memory allocated is assumed contiguous.
194  *            
195  *
196  *     Ret  : ROK
197  *            RFAILED
198  *
199  *     Notes: Caller doesnt need to raise the alarm in case of memory
200  *            allocation gets failed. 
201  *
202  *     File : rg_utl.c
203  *
204  **********************************************************/
205 #ifdef ANSI
206 PUBLIC S16 rgAllocSBuf
207 (
208 Inst    inst,
209 Data    **pData,            /* Pointer of the data to be returned */
210 Size    size                /* size */
211 )
212 #else
213 PUBLIC S16 rgAllocSBuf(inst,pData, size)
214 Inst    inst;
215 Data    **pData;            /* Pointer of the data to be returned */
216 Size    size;               /* size */
217 #endif
218 {
219    RgUstaDgn dgn;      /* Alarm diagnostics structure */
220
221    TRC2(rgAllocSBuf)
222
223    /* Initialize the param to NULLP */
224    *pData = NULLP;
225
226    if (size == 0)
227    {
228       RETVALUE(RFAILED);
229    }
230
231    /* allocate buffer */
232 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
233    MS_BUF_ADD_ALLOC_CALLER();
234 #endif /* */
235    if (SGetSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, pData, size) != ROK)
236    {
237      dgn.type = LRG_USTA_DGNVAL_MEM;
238      dgn.u.mem.region = rgCb[inst].rgInit.region;
239      dgn.u.mem.pool = rgCb[inst].rgInit.pool;
240      /*  Send an alarm to Layer Manager */
241      rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
242                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
243       RGLOGERROR(inst,ERRCLS_DEBUG, ERG028, 0, "Unable to Allocate Buffer");
244       RETVALUE(RFAILED);
245    }
246
247    /* zero out the allocated memory */
248    cmMemset((U8 *)*pData, 0x00, size);
249
250    RETVALUE(ROK);
251
252 } /* end of rgAllocSBuf */
253
254 /*
255 *
256 *       Fun:   rgFreeSharableSBuf
257 *
258 *       Desc:  The argument to rgFreeSBuf() is a pointer to a block
259 *              previously allocated by rgAllocSBuf() and size. It 
260 *              deallocates the memory. 
261 *
262 *       Ret:   RETVOID
263 *
264 *       Notes: ccpu00117052 - MOD- changed the Data parameter from 
265 *                             pointer to address of pointer so that
266 *                             the freed memory could be set to NULLP
267 *
268 *       File:  rg_utl.c
269 */
270 #ifdef ANSI
271 PUBLIC Void rgFreeSharableSBuf
272 (
273 Inst inst,
274 Data **data,         /* address of pointer to data */
275 Size size            /* size */
276 )
277 #else
278 PUBLIC Void rgFreeSharableSBuf(inst,data, size)
279 Inst inst;
280 Data **data;         /* address of pointer to data */
281 Size size;          /* size */
282 #endif
283 {
284
285    S16 ret;
286
287    TRC2(rgFreeSharableBuf)
288
289    if ((data == NULLP) || (*data == NULLP) || (size == 0))
290    {
291       RETVOID;
292    }
293
294    /* Deallocate buffer */
295    ret = SPutStaticBuffer(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size, SS_SHARABLE_MEMORY);
296
297    if (ret != ROK)
298    {
299       RETVOID;
300    }
301
302    *data = NULLP;
303
304    RETVOID;
305
306 } /* end of rgFreeSharableBuf */
307
308
309
310 /*
311 *
312 *       Fun:   rgFreeSBuf
313 *
314 *       Desc:  The argument to rgFreeSBuf() is a pointer to a block
315 *              previously allocated by rgAllocSBuf() and size. It 
316 *              deallocates the memory. 
317 *
318 *       Ret:   RETVOID
319 *
320 *       Notes: ccpu00117052 - MOD- changed the Data parameter from 
321 *                             pointer to address of pointer so that
322 *                             the freed memory could be set to NULLP
323 *
324 *       File:  rg_utl.c
325 */
326 #ifdef ANSI
327 PUBLIC Void rgFreeSBuf
328 (
329 Inst inst,
330 Data **data,         /* address of pointer to data */
331 Size size            /* size */
332 )
333 #else
334 PUBLIC Void rgFreeSBuf(inst,data, size)
335 Inst  inst;
336 Data **data;         /* address of pointer to data */
337 Size size;          /* size */
338 #endif
339 {
340
341    S16 ret;
342
343    TRC2(rgFreeSBuf)
344
345    if ((data == NULLP) || (*data == NULLP) || (size == 0))
346    {
347       RETVOID;
348    }
349
350
351 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
352    MS_BUF_ADD_CALLER();
353 #endif /* */
354    /* Deallocate buffer */
355    ret = SPutSBuf(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
356
357    if (ret != ROK)
358    {
359       RGLOGERROR(inst,ERRCLS_DEBUG, ERG029, (ErrVal) 0, "rgFreeSBuf failed.\n");
360       RETVOID;
361    }
362
363    *data = NULLP;
364
365    RETVOID;
366
367 } /* end of rgFreeSBuf */
368
369
370 /***********************************************************
371  *
372  *     Func : rgGetMsg
373  *
374  *     Desc : Utility Function to Allocate message buffer. 
375  *            
376  *
377  *     Ret  : ROK
378  *            RFAILED
379  *
380  *     Notes: Caller doesnt need to raise the alarm in case of memory
381  *            allocation gets failed. 
382  *
383  *     File : rg_utl.c
384  *
385  **********************************************************/
386 #ifdef ANSI
387 PUBLIC S16 rgGetMsg
388 (
389 Inst    inst,
390 Buffer  **mBuf            /* Message Buffer pointer be returned */
391 )
392 #else
393 PUBLIC S16 rgGetMsg(inst,mBuf)
394 Inst    inst;
395 Buffer  **mBuf;           /* Message Buffer pointer be returned */
396 #endif
397 {
398    S16         ret;
399
400    TRC2(rgGetMsg)
401
402 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
403    MS_BUF_ADD_ALLOC_CALLER();
404 #endif /* */
405    ret = SGetMsg(RG_GET_MEM_REGION(rgCb[inst]), RG_GET_MEM_POOL(rgCb[inst]), mBuf);
406
407    if (ROK != ret) 
408    {
409       /* Moving diagnostics structure to limited scope for optimization */
410       RgUstaDgn   dgn;      /* Alarm diagnostics structure */
411
412       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
413
414       /*  Send an alarm to Layer Manager */
415       rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_DMEM_ALLOC_FAIL,
416                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
417       RGLOGERROR(inst,ERRCLS_DEBUG, ERG030, 0, "Unable to Allocate Buffer");
418       RETVALUE(RFAILED);
419    }
420
421    RETVALUE(ROK);
422
423 } /* end of rgGetMsg */
424
425
426 /***********************************************************
427  *
428  *     Func : rgFillDgnParams
429  *
430  *     Desc : Utility Function to Fill Diagonostic params. 
431  *
432  *     Ret  : None.
433  *
434  *     Notes: None.
435  *
436  *     File : rg_utl.c
437  *
438  **********************************************************/
439 #ifdef ANSI
440 PUBLIC Void rgFillDgnParams
441 (
442 Inst        inst,
443 RgUstaDgn   *dgn,
444 U8          dgnType
445 )
446 #else
447 PUBLIC Void rgFillDgnParams(inst,dgn, dgnType)
448 Inst        inst;
449 RgUstaDgn   *dgn;
450 U8          dgnType;
451 #endif
452 {
453
454    TRC2(rgFillDgnParams)
455
456    switch(dgnType)
457    {
458       case LRG_USTA_DGNVAL_MEM:
459          dgn->type = (U8) LRG_USTA_DGNVAL_MEM;
460          dgn->u.mem.region  = rgCb[inst].rgInit.region;
461          dgn->u.mem.pool    = rgCb[inst].rgInit.pool;
462       break;
463
464       default:
465       break;
466    }
467
468    RETVOID;
469 } /* end of rgFillDgnParams */
470
471
472 /***********************************************************
473  *
474  *     Func : rgUpdtRguDedSts
475  *
476  *     Desc : Utility Function to update rgu sap statistics for dedicated
477  *            DatReqs.
478  *            
479  *
480  *     Ret  : ROK
481  *            RFAILED
482  *
483  *     Notes: 
484  *
485  *     File : rg_utl.c
486  *
487  **********************************************************/
488 #ifdef ANSI
489 PUBLIC Void rgUpdtRguDedSts
490 (
491 Inst           inst,
492 RgUpSapCb     *rguDlSap,
493 U8             stsType,   /* Statistics type to update */
494 RgRguDedDatReq *datReq    /* DatReq pointer */
495 )
496 #else
497 PUBLIC Void rgUpdtRguDedSts(inst,rguDlSap,stsType, datReq)
498 Inst           inst;
499 RgUpSapCb     *rguDlSap;
500 U8             stsType;   /* Statistics type to update */
501 RgRguDedDatReq *datReq;   /* DatReq pointer */
502 #endif
503 {
504    U8 idx1,idx2;
505    U32 idx;
506
507
508    TRC2(rgUpdtRguDedSts)
509
510
511    switch(stsType)
512    {
513       case RG_RGU_SDU_RCVD:
514       for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
515       {
516          RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
517          for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++) 
518          {
519             for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++) 
520             {
521                rguDlSap->sapSts.numPduRcvd +=
522                   datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
523             }
524          }
525       }
526
527          break;
528       case RG_RGU_SDU_DROP:
529       for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
530       {
531          RguDDatReqPerUe *datReqPerUe = &datReq->datReq[idx];
532          for (idx1 = 0; idx1 < datReqPerUe->nmbOfTbs; idx1++) 
533          {
534             for(idx2 = 0; idx2 < datReqPerUe->datReqTb[idx1].nmbLch; idx2++) 
535             {
536                rguDlSap->sapSts.numPduRcvd +=
537                   datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
538                rguDlSap->sapSts.numPduDrop +=
539                   datReqPerUe->datReqTb[idx1].lchData[idx2].pdu.numPdu;
540             }
541          }
542       }
543
544          break;
545    }
546    
547    RETVOID;
548 } /* rgUpdtRguDedSts */
549
550
551 /***********************************************************
552  *
553  *     Func : rgUpdtRguCmnSts
554  *
555  *     Desc : Utility Function to update rgu sap statistics for common
556  *            DatReqs.
557  *            
558  *
559  *     Ret  : ROK
560  *            RFAILED
561  *
562  *     Notes: 
563  *
564  *     File : rg_utl.c
565  *
566  **********************************************************/
567 #ifdef ANSI
568 PUBLIC Void rgUpdtRguCmnSts
569 (
570 Inst           inst,
571 RgUpSapCb     *rguDlSap,
572 U8             stsType   /* Statistics type to update */
573 )
574 #else
575 PUBLIC Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
576 Inst           inst;
577 RgUpSapCb     *rguDlSap;
578 U8             stsType;   /* Statistics type to update */
579 #endif
580 {
581    TRC2(rgUpdtRguCmnSts)
582
583
584
585    switch(stsType)
586    {
587       case RG_RGU_SDU_RCVD:
588          rguDlSap->sapSts.numPduRcvd ++;
589          break;
590       case RG_RGU_SDU_DROP:
591          rguDlSap->sapSts.numPduRcvd ++;
592          rguDlSap->sapSts.numPduDrop ++;
593          break;
594    }
595    
596    RETVOID;
597 } /* rgUpdtRguCmnSts */
598
599
600 /***********************************************************
601  *
602  *     Func : rgUpdtCellCnt
603  *
604  *     Desc : Utility Function to update cell count. It gives number of active
605  *     cells
606  *            
607  *
608  *     Ret  : ROK
609  *            RFAILED
610  *
611  *     Notes: This function should be called only after cell is added/deleted 
612  *     from the globlal hashlist
613  *
614  *     File : rg_utl.c
615  *
616  **********************************************************/
617 #ifdef ANSI
618 PUBLIC Void rgUpdtCellCnt
619 (
620 Inst inst,
621 U8 updtType
622 )
623 #else
624 PUBLIC Void rgUpdtCellCnt(inst,updtType)
625 Inst inst;
626 U8 updtType;
627 #endif
628 {
629    TRC2(rgUpdtCellCnt);
630
631    switch (updtType)
632    {
633       case RG_CFG_ADD:
634          rgCb[inst].genSts.numCellCfg++;
635          break;
636       case RG_CFG_DEL:
637          rgCb[inst].genSts.numCellCfg--;
638          break;
639       default:
640          break;
641    }
642
643    RETVOID;
644 } /* rgUpdtCellCnt */
645
646
647 /***********************************************************
648  *
649  *     Func : rgUpdtUeCnt
650  *
651  *     Desc : Utility Function to update ue count. It gives number of active
652  *     Ues.
653  *            
654  *
655  *     Ret  : ROK
656  *            RFAILED
657  *
658  *     Notes: This function should be called only after ue is added/deleted 
659  *     from the globlal hashlist
660  *
661  *     File : rg_utl.c
662  *
663  **********************************************************/
664 #ifdef ANSI
665 PUBLIC Void rgUpdtUeCnt
666 (
667 Inst inst,
668 U8 updtType
669 )
670 #else
671 PUBLIC Void rgUpdtUeCnt (inst,updtType)
672 Inst inst;
673 U8 updtType;
674 #endif
675 {
676    TRC2(rgUpdtUeCnt);
677
678    switch (updtType)
679    {
680       case RG_CFG_ADD:
681          rgCb[inst].genSts.numUeCfg++;
682          break;
683       case RG_CFG_DEL:
684          rgCb[inst].genSts.numUeCfg--;
685          break;
686       default:
687          break;
688    }
689    RETVOID;
690 } /* rgUpdtUeCnt */
691
692 /*
693 *
694 *       Fun:   rgAllocEventMem
695 *
696 *       Desc:  This function allocates event memory 
697 *
698 *       Ret:   ROK      - on success
699 *              RFAILED  - on failure
700 *
701 *       Notes: None
702 *
703 *       File:  rg_utl.c
704 *
705 */
706 #ifdef ANSI
707 PUBLIC S16 rgAllocEventMem
708 (
709 Inst     inst,
710 Ptr       *memPtr,
711 Size      memSize
712 )
713 #else
714 PUBLIC S16 rgAllocEventMem(inst,memPtr, memSize)
715 Inst     inst;
716 Ptr       *memPtr;
717 Size      memSize;
718 #endif
719 {
720    Mem              sMem;
721    VOLATILE U32     startTime=0;
722
723    TRC2(rgAllocEventMem)
724
725    sMem.region = rgCb[inst].rgInit.region;
726    sMem.pool = rgCb[inst].rgInit.pool;
727
728 #if (ERRCLASS & ERRCLS_DEBUG)
729    if (memSize<= 0)
730    {
731       RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
732                    "rgAllocEventMem(): memSize invalid\n");
733       RETVALUE (RFAILED);
734    }
735 #endif /* ERRCLASS & ERRCLS_DEBUG */
736
737
738    /*starting Task*/
739    SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
740
741 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
742    MS_BUF_ADD_ALLOC_CALLER();
743 #endif /* */
744 #ifdef TFU_ALLOC_EVENT_NO_INIT
745    if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
746 #else
747    if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
748 #endif /* */
749    {
750       RLOG0(L_ERROR,"cmAllocEvnt Failed"); 
751       RETVALUE(RFAILED);
752    }
753
754    /*stoping Task*/
755    SStopTask(startTime, PID_MACUTL_CMALLCEVT);
756
757    RETVALUE(ROK);
758 } /* end of rgAllocEventMem*/
759
760 /*
761 *
762 *       Fun:   rgGetEventMem
763 *
764 *       Desc:  This function allocates event memory 
765 *
766 *       Ret:   ROK      - on success
767 *              RFAILED  - on failure
768 *
769 *       Notes: None
770 *
771 *       File:  rg_utl.c
772 *
773 */
774 #ifdef ANSI
775 PUBLIC S16 rgGetEventMem
776 (
777 Inst      inst,
778 Ptr       *ptr,
779 Size      len,
780 Ptr       memCp
781 )
782 #else
783 PUBLIC S16 rgGetEventMem(inst,ptr, len, memCp)
784 Inst      inst;
785 Ptr       *ptr;
786 Size      len;
787 Ptr       memCp;
788 #endif
789 {
790    S16   ret;
791
792    TRC2(rgGetEventMem)
793 #ifdef TFU_ALLOC_EVENT_NO_INIT
794    ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
795 #else
796    ret = cmGetMem(memCp, len, (Ptr *)ptr);
797 #endif /* */
798    RETVALUE(ret);
799 } /* end of rgGetEventMem*/
800
801 /***********************************************************
802  *
803  *     Func : rgGetPstToInst
804  *
805  *     Desc : Utility Function to get the pst structure to post a message to
806  *     scheduler instance
807  *            
808  *
809  *     Ret  : ROK
810  *            RFAILED
811  *
812  *     Notes: This function should be called while sending a msg from 
813  *     MAC to a scheduler instance
814  *
815  *     File : rg_utl.c
816  *
817  **********************************************************/
818 #ifdef ANSI
819 PUBLIC Void rgGetPstToInst
820 (
821 Pst           *pst,
822 Inst          srcInst,
823 Inst          dstInst
824 )
825 #else
826 PUBLIC Void rgGetPstToInst (pst, srcInst, dstInst)
827 Pst           *pst;
828 Inst          srcInst;
829 Inst          dstInst;
830 #endif
831 {
832    TRC2(rgGetPstToInst);
833
834    pst->srcEnt = rgCb[srcInst].rgInit.ent; 
835    pst->srcInst = rgCb[srcInst].rgInit.inst;
836    pst->srcProcId = rgCb[srcInst].rgInit.procId;
837    pst->region = rgCb[srcInst].rgInit.region;
838    pst->pool = rgCb[srcInst].rgInit.pool;
839
840    pst->dstProcId = rgCb[dstInst].rgInit.procId;
841    pst->dstEnt = rgCb[dstInst].rgInit.ent; 
842    pst->dstInst = dstInst;
843    pst->selector = 0;
844    pst->prior     = PRIOR0;
845    pst->intfVer   = 0;
846    pst->route   = RTESPEC;
847
848    RETVOID; 
849 } /* end of rgGetPstToInst */
850
851 /***********************************************************
852  *
853  *     Func : RgSchMacLcgRegReq
854  *
855  *     Desc : Utility Function to register the set of GBR LCG.
856  *        Invoked at the time of LCG configuration/Reconfiguration at Schedular.
857  * 
858  *     Processing Steps: 
859  *           - Fetch the ueCb using the crnti given in lcInfo            
860  *           - Store the if LCG is GBR or not.
861  *
862  *     Ret  : ROK
863  *            RFAILED
864  *
865  *     Notes: This function should be called at the time of LCG 
866  *     configuration/Reconfiguration at Schedular. 
867  *     
868  *
869  *     File : rg_utl.c
870  *
871  **********************************************************/
872 #ifdef ANSI
873 PUBLIC S16 RgSchMacLcgRegReq
874 (
875 Pst            *pst,
876 RgInfLcgRegReq *lcgRegReq
877 )
878 #else
879 PUBLIC S16 RgSchMacLcgRegReq (pst, lcgRegReq)
880 Pst            *pst;
881 RgInfLcgRegReq *lcgRegReq;
882 #endif
883 {
884    Inst       inst;
885    RgCellCb   *cell = NULLP;
886    RgUeCb     *ue;
887
888    TRC2(RgSchMacLcgRegReq);
889
890    RG_IS_INST_VALID(pst->dstInst);
891    inst   = pst->dstInst - RG_INST_START;
892    cell   = rgCb[inst].cell;
893    /* Fetch the cell and then the UE */
894    if((cell == NULLP) ||
895       (cell->cellId != lcgRegReq->cellId))
896    {
897       
898       RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
899       RETVALUE(RFAILED);
900    }
901
902    if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
903    {
904       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
905                          lcgRegReq->crnti);
906       RETVALUE(RFAILED);
907    }
908    ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
909
910    RETVALUE(ROK); 
911 } /* end of RgSchMacLcgRegReq */
912
913 #ifdef LTEMAC_SPS
914
915 /***********************************************************
916  *
917  *     Func : RgSchMacUlSpsResetReq
918  *
919  *     Desc : Utility Function to reset SPS params for a UE
920  * 
921  *     Processing Steps: 
922  *           - Fetch the ueCb using the crnti 
923  *           - reset implRelCnt and explRelCnt
924  *
925  *     Ret  : ROK
926  *            RFAILED
927  *
928  *     File : rg_utl.c
929  *
930  **********************************************************/
931 #ifdef ANSI
932 PUBLIC S16 RgSchMacUlSpsResetReq
933 (
934 Pst            *pst,
935 RgInfUlSpsReset *ulSpsResetInfo
936 )
937 #else
938 PUBLIC S16 RgSchMacUlSpsResetReq (pst, lcInfo)
939 Pst            *pst;
940 RgInfUlSpsReset *ulSpsResetInfo;
941 #endif
942 {
943    Inst       inst;
944    RgCellCb   *cell = NULLP;
945    RgUeCb     *ue;
946
947    TRC2(RgSchMacUlSpsResetReq);
948
949    RG_IS_INST_VALID(pst->dstInst);
950    inst   = pst->dstInst - RG_INST_START;
951    cell   = rgCb[inst].cell;
952    /* Fetch the cell and then the UE */
953    if((cell == NULLP)||
954       (cell->cellId != ulSpsResetInfo->cellId))
955    {
956       
957       RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
958       RETVALUE(RFAILED);
959    }
960
961    if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
962    {
963       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
964                       ulSpsResetInfo->crnti);
965       RETVALUE(RFAILED);
966    }
967
968    ue->ul.implRelCntr = 0;
969    ue->ul.explRelCntr = 0;
970
971    RETVALUE(ROK); 
972 } /* end of RgSchMacUlSpsResetReq */
973
974
975
976
977 /***********************************************************
978  *
979  *     Func : RgSchMacSpsLcRegReq
980  *
981  *     Desc : Utility Function to register the set of uplink SPS logical
982  *        channels for a SPS UE.
983  *        Invoked at the time of activation of a UE for UL-SPS.
984  *        Whenever there is data on these LCs MAC shall inform scheduler
985  * 
986  *     Processing Steps: 
987  *           - Fetch the ueCb using the crnti given in lcInfo            
988  *           - Store the sps-rnti and set the bits corresponding to the
989  *             logical channel ids in ueUlCb->spsLcMask.
990  *
991  *     Ret  : ROK
992  *            RFAILED
993  *
994  *     Notes: This function should be called at the time UL SPS is activated 
995  *     for a UE at scheduler
996  *     
997  *
998  *     File : rg_utl.c
999  *
1000  **********************************************************/
1001 #ifdef ANSI
1002 PUBLIC S16 RgSchMacSpsLcRegReq
1003 (
1004 Pst            *pst,
1005 RgInfSpsLcInfo *lcInfo
1006 )
1007 #else
1008 PUBLIC S16 RgSchMacSpsLcRegReq (pst, lcInfo)
1009 Pst            *pst;
1010 RgInfSpsLcInfo *lcInfo;
1011 #endif
1012 {
1013    Inst       inst;
1014    RgCellCb   *cell= NULLP;
1015    RgUeCb     *ue;
1016    U8         idx;
1017
1018    TRC2(RgSchMacSpsLcRegReq);
1019
1020    RG_IS_INST_VALID(pst->dstInst);
1021    inst   = pst->dstInst - RG_INST_START;
1022    cell   = rgCb[inst].cell;
1023    /* Fetch the cell and then the UE */
1024    if((cell == NULLP) ||
1025       (cell->cellId != lcInfo->cellId))
1026    {
1027       
1028       RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
1029       RETVALUE(RFAILED);
1030    }
1031
1032    if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
1033    {
1034       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
1035                       lcInfo->crnti);
1036       RETVALUE(RFAILED);
1037    }
1038
1039    /* Store the sps-rnti and SPS LC information in the UE */ 
1040    ue->spsRnti = lcInfo->spsRnti;
1041    for (idx=0; idx < lcInfo->spsLcCnt; idx++)
1042    {
1043       /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
1044       ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
1045    }
1046    ue->ul.implRelCnt = lcInfo->implRelCnt;
1047    ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
1048
1049    /* Insert the UE into SPS UE List */
1050    if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1051    {
1052       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1053                     "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1054       RETVALUE(RFAILED);
1055    } 
1056
1057    RETVALUE(ROK); 
1058 } /* end of RgSchMacSpsLcRegReq */
1059
1060
1061 /***********************************************************
1062  *
1063  *     Func : RgSchMacSpsLcDeregReq
1064  *
1065  *     Desc : Utility Function to deregister the set of uplink SPS 
1066  *        logical channels for a UE.
1067  *        Invoked at the time of release of UL-SPS for an activated UE.
1068  * 
1069  *     Processing Steps: 
1070  *           - Fetch the ueCb using the crnti given
1071  *           - Reset the bits corresponding to the logical channel ids in
1072  *             ueUlCb->spsLcMask.
1073  *
1074  *     Ret  : ROK
1075  *            RFAILED
1076  *
1077  *     Notes: This function should be called at the time UL SPS is released 
1078  *     for a UE at scheduler
1079  *     
1080  *
1081  *     File : rg_utl.c
1082  *
1083  **********************************************************/
1084 #ifdef ANSI
1085 PUBLIC S16 RgSchMacSpsLcDeregReq
1086 (
1087 Pst            *pst,
1088 CmLteCellId    cellId,
1089 CmLteRnti      crnti
1090 )
1091 #else
1092 PUBLIC S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1093 Pst            *pst;
1094 CmLteCellId    cellId;
1095 CmLteRnti      crnti;
1096 #endif
1097 {
1098    Inst       inst;
1099    RgCellCb   *cell = NULLP;
1100    RgUeCb      *ue;
1101
1102    TRC2(RgSchMacSpsLcDeregReq);
1103
1104    RG_IS_INST_VALID(pst->dstInst);
1105    inst   = pst->dstInst - RG_INST_START;
1106    cell   = rgCb[inst].cell;
1107    /* Fetch the cell and then the UE */
1108    if((cell == NULLP) ||
1109       (cell->cellId != cellId))
1110    {
1111       
1112       RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1113       RETVALUE(RFAILED);
1114    }
1115
1116    if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1117    {
1118       RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1119       RETVALUE(RFAILED);
1120    }
1121
1122    /* No need to reset the SPS LC Ids as they will not be looked at*/
1123
1124    /* Delete UE from the SPS UE List */
1125    rgDBMDelSpsUeCb(cell, ue);
1126    
1127    RETVALUE(ROK); 
1128 } /* end of RgSchMacSpsLcDeregReq */
1129
1130 #endif /* LTEMAC_SPS */
1131
1132 /**
1133  * @brief Function for handling CRNTI change request 
1134  * received from scheduler to MAC.
1135  *
1136  * @details
1137  *
1138  *     Function : rgUtlHndlCrntiChng
1139  *     
1140  *        - Delete old UE from the list.
1141  *        - Update the new rnti and re-insert the UE in the list.
1142  *     
1143  *           
1144  *  @param[in] Inst        inst
1145  *  @param[in] RgCellCb      *cell,
1146  *  @param[in] CmLteRnti     rnti,
1147  *  @param[in] CmLteRnti     newRnti
1148  *  @return  S16
1149  *      -# ROK 
1150  *      -# RFAILED
1151  **/
1152 #ifdef ANSI
1153 PRIVATE S16 rgUtlHndlCrntiChng 
1154 (
1155 Inst            inst,
1156 RgCellCb        *cell,
1157 CmLteRnti       rnti,
1158 CmLteRnti       newRnti
1159 )
1160 #else
1161 PRIVATE S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1162 Inst            inst;
1163 RgCellCb        *cell;
1164 CmLteRnti       rnti;
1165 CmLteRnti       newRnti;
1166 #endif
1167 {
1168    RgUeCb         *ue = NULLP;
1169    RgUeCb         *newUe = NULLP;
1170
1171    TRC3(rgUtlHndlCrntiChng)
1172
1173    ue = rgDBMGetUeCb(cell, rnti);
1174    newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1175    if ((ue == NULLP) || (newUe == NULLP))
1176    {
1177       RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1178                         "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d", 
1179                rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1180       RETVALUE(RFAILED);
1181    }
1182 #ifdef XEON_SPECIFIC_CHANGES
1183    CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1184 #endif
1185    rgDBMDelUeCb(cell, ue);
1186
1187    ue->ueId = newRnti;
1188
1189    cmMemcpy((U8*)&(ue->contResId), (U8*)&(newUe->contResId), 
1190                    sizeof(newUe->contResId));
1191    /* Fix : syed MSG4 might be RETXing need to store the
1192     * HARQ context. */
1193    rgDHMFreeUe(inst,&ue->dl.hqEnt);
1194    ue->dl.hqEnt = newUe->dl.hqEnt;
1195        
1196    rgDBMInsUeCb(cell, ue);
1197
1198    rgDBMDelUeCbFromRachLst(cell, newUe);
1199    rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1200
1201    RETVALUE(ROK);
1202 } /* end of rgUtlHndlCrntiChng */
1203
1204 #ifdef LTE_ADV
1205 /**
1206  * @brief Function for handling UE  release for SCELL
1207  * triggered from SCH to MAC.
1208  *
1209  * @details
1210  *
1211  *     Function : rgDelUeFrmAllSCell
1212  *     
1213  *        - This Function should be invoked by PCell of UE
1214  *        - Remove the UE context from SCELL corresponding to rnti.
1215  *           
1216  *  @param[in] Inst      *macInst,
1217  *  @param[in] RgUeCb    *ue
1218  *  @return  ROK is SUCCESS 
1219  **/
1220 #ifdef ANSI
1221 PUBLIC S16 rgDelUeFrmAllSCell
1222 (
1223 RgCellCb      *cell,
1224 RgUeCb        *ue
1225 )
1226 #else
1227 PUBLIC S16 rgDelUeFrmAllSCell(cell, ue)
1228 RgCellCb      *cell;
1229 RgUeCb        *ue;
1230 #endif
1231 {
1232    Inst        inst     = cell->macInst - RG_INST_START;
1233    U8          idx      = 0;
1234    Inst        sCellInstIdx;
1235    Pst         dstInstPst;
1236    RgPrgUeSCellDelInfo ueSCellDelInfo;
1237
1238    TRC2(rgDelUeFrmAllSCell)
1239
1240    /* To Delete the SCells if exisits for that UE */
1241    for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1242    {
1243       if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1244       {
1245          sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1246
1247          rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1248          ueSCellDelInfo.ueId = ue->ueId;
1249          ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1250
1251          /* Filling same ueId in newRnti so that SMAC will check if newRnti
1252           *and old UeId is same that means its a UeSCell delete request*/
1253          ueSCellDelInfo.newRnti = ue->ueId;
1254
1255          RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1256          ue->sCelInfo[idx].isSCellAdded = FALSE;
1257       } /* loop of if */
1258    } /* loop of for */
1259
1260    RETVALUE(ROK);
1261 } /* rgDelUeFrmAllSCell */
1262
1263 /**
1264  * @brief Function to validate AddSCellCfg.
1265  *
1266  * @details
1267  *
1268  *     Function : rgUtlVltdAddSCellCfg
1269  *     
1270  *           
1271  *  @param[in] ueSCellCb   secondary cell CB for validation
1272  *  @param[in] cell        cell control block
1273  *  @param[in] inst        instance number to fetch rgCb instance
1274  *  @return  S16
1275  *      -# ROK 
1276  **/
1277 #ifdef ANSI
1278 PUBLIC S16 rgUtlVltdAddSCellCfg
1279 (
1280  RgPrgUeSCellCfgInfo *ueSCellCb,
1281  RgCellCb    *cell,
1282  Inst        inst
1283 )
1284 #else
1285 PUBLIC S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1286  RgPrgUeSCellCfgInfo *ueSCellCb;
1287  RgCellCb    *cell;
1288  Inst        inst;
1289 #endif
1290 {
1291   S16 ret = ROK; 
1292   
1293   TRC3(rgUtlVltdAddSCellCfg)
1294   
1295      /* To Validate the CellID presence */
1296   if((cell == NULLP) ||
1297         (cell->cellId != ueSCellCb->cellId))
1298   {
1299      RGDBGERRNEW(inst, (rgPBuf(inst),
1300               "[%d]Sec Cell does not exit %d\n",
1301               ueSCellCb->ueId, ueSCellCb->cellId));
1302      ret = RFAILED;
1303   }
1304 #ifdef TENB_MULT_CELL_SUPPRT
1305    if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1306       (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1307    {
1308       RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1309                ueSCellCb->rguDlSapId,
1310                ueSCellCb->rguUlSapId,
1311                ueSCellCb->cellId));
1312      ret = RFAILED;
1313    }
1314 #endif
1315    RETVALUE(ret);
1316 } /* rgUtlVltdAddSCellCfg */
1317
1318 /**
1319  * @brief Function to build CrntiChangeReq and send to all SMACs.
1320  *
1321  * @details
1322  *
1323  *     Function : rgUtlSndCrntiChngReq2AllSMacs
1324  *     
1325  *        - This Function should be invoked by PCell of UE
1326  *        - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1327  *          by SCH. SMAC will check if newRnti is not equal to old UeId then it
1328  *          do only UeId change else it will delete the UeScell context
1329  *           
1330  *  @param[in] cell    Cell CB to get Ue control block
1331  *  @param[in] rnti    Ue Identifier used to fill in UeId Change req
1332  *  @param[in] newRnti UE new identifier, to be used in UeId Change req
1333  *  @return  S16
1334  *      -# ROK 
1335  **/
1336 #ifdef ANSI
1337 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs
1338 (
1339 RgCellCb        *cell,
1340 CmLteRnti       rnti,
1341 CmLteRnti       newRnti
1342 )
1343 #else
1344 PRIVATE S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1345 RgCellCb        *cell;
1346 CmLteRnti       rnti;
1347 CmLteRnti       newRnti;
1348 #endif
1349 {
1350    Inst                inst = cell->macInst - RG_INST_START;
1351    Inst                sCellInstIdx;
1352    Pst                 dstInstPst;
1353    RgPrgUeSCellDelInfo ueIdChngReq;
1354    RgUeCb              *ue;
1355    U8                  idx;
1356 #ifdef L2_OPTMZ
1357 TfuDelDatReqInfo delDatReq;
1358 #endif
1359
1360    TRC2(rgUtlSndCrntiChngReq2AllSMacs)
1361
1362    /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1363    ue = rgDBMGetUeCb(cell, newRnti);
1364    if (ue == NULLP)
1365    {
1366       RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1367                newRnti=%d\n", rnti, newRnti));
1368       RETVALUE(RFAILED);
1369    }
1370    /* For all added SCells, prepare and send ueIdChngReq */
1371    for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1372    {
1373       if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1374       {
1375          sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1376
1377          rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1378          /* fill old rnti*/
1379          ueIdChngReq.ueId = rnti;
1380          ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1381          
1382          /* Filling newRnti so that SMAC can check if old ueId and new UeId
1383           *(newRnti) is different then its a UeId change request from PMAC.
1384           * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1385           * from PMAC to SMAC*/
1386          ueIdChngReq.newRnti = newRnti;
1387          
1388          /* Re-using UeSCellDelReq API for UeId change*/
1389          RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1390 #ifdef L2_OPTMZ
1391       /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1392       delDatReq.cellId = ueIdChngReq.sCellId;
1393       delDatReq.ueId = ueIdChngReq.ueId;
1394       rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1395 #endif
1396
1397       } /* loop of if */
1398    } /* loop of for */
1399
1400    RETVALUE(ROK);
1401 } /* rgUtlSndCrntiChngReq2AllSMacs */
1402
1403 #endif /* LTE_ADV */
1404
1405 /**
1406  * @brief Function for handling CRNTI Context release 
1407  * triggered from SCH to MAC.
1408  *
1409  * @details
1410  *
1411  *     Function : rgUtlHndlCrntiRls
1412  *     
1413  *        - Remove the UE context from MAC corresponding to rnti.
1414  *     
1415  *           
1416  *  @param[in] RgCellCb      *cell,
1417  *  @param[in] CmLteRnti     rnti
1418  *  @return  Void 
1419  **/
1420 #ifdef ANSI
1421 PRIVATE Void rgUtlHndlCrntiRls
1422 (
1423 RgCellCb        *cell,
1424 RgInfRlsRnti    *rlsRnti
1425 )
1426 #else
1427 PRIVATE Void rgUtlHndlCrntiRls(cell, rlsRnti)
1428 RgCellCb        *cell;
1429 CmLteRnti       *rlsRnti;
1430 #endif
1431 {
1432    Inst           inst = cell->macInst - RG_INST_START;
1433    RgUeCb        *ue = NULLP;
1434 #ifdef LTEMAC_SPS
1435    RgUeCb         *spsUeCb = NULLP;
1436 #endif
1437
1438    TRC3(rgUtlHndlCrntiRls)
1439
1440    if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1441    {
1442       /* Check in RachLst */
1443       if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1444       {
1445          /* Delete Ue from the UE list */
1446          rgDBMDelUeCbFromRachLst(cell, ue);
1447
1448          /* Free Ue */
1449          rgRAMFreeUeCb(inst,ue);
1450       }
1451       else
1452       {
1453          RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1454                    "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1455       }
1456    }
1457    else
1458    {
1459 #ifdef LTE_ADV
1460       if(FALSE == rlsRnti->isUeSCellDel)
1461       {
1462          rgDelUeFrmAllSCell(cell, ue);
1463       }
1464 #endif /* LTE_ADV */
1465
1466       /* Delete Ue from the UE list */
1467       rgDBMDelUeCb(cell, ue);
1468 #ifdef LTEMAC_SPS
1469       spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1470       if (spsUeCb)
1471       {
1472          rgDBMDelSpsUeCb(cell, spsUeCb);
1473       }
1474 #endif
1475
1476       /* Free Ue */
1477       rgCFGFreeUeCb(cell, ue);     
1478       /* MS_REMOVE : syed Check in RachLst */
1479       {
1480          if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1481          {
1482             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1483                         "RNTI:%d STALE UE is still present", rlsRnti->rnti);         
1484          }
1485       }
1486    }
1487
1488    RETVOID;
1489 } /* end of rgUtlHndlCrntiRls */
1490
1491 /**
1492  * @brief Function for handling RaResp request received from scheduler to MAC.
1493  *
1494  * @details
1495  *
1496  *     Function : RgSchMacRlsRntiReq
1497  *     
1498  *     This function shall be invoked whenever scheduler is done with the
1499  *     allocations of random access responses for a subframe.
1500  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
1501  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
1502  *     
1503  *           
1504  *  @param[in] CmLteCellId         cellId,
1505  *  @param[in] CmLteTimingInfo     timingInfo,
1506  *  @param[in] RaRespInfo          *rarInfo
1507  *  @return  S16
1508  *      -# ROK 
1509  **/
1510 #ifdef ANSI
1511 PUBLIC S16 RgSchMacRlsRntiReq
1512 (
1513 Pst                 *pst,
1514 RgInfRlsRnti        *rlsRnti
1515 )
1516 #else
1517 PUBLIC S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1518 Pst                 *pst;
1519 RgInfRlsRnti        *rlsRnti;
1520 #endif
1521 {
1522    Pst            schPst;
1523    RgInfUeDelInd  ueDelInd;
1524    Inst           macInst;
1525    RgCellCb       *cell;
1526 #ifdef L2_OPTMZ
1527 TfuDelDatReqInfo delDatReq;
1528 #endif
1529
1530    TRC3(RgSchMacRlsRntiReq)
1531
1532    RG_IS_INST_VALID(pst->dstInst);
1533    macInst   = pst->dstInst - RG_INST_START;
1534    cell   = rgCb[macInst].cell;
1535
1536    if(NULLP == rlsRnti)
1537    {
1538       RETVALUE(RFAILED);
1539    }
1540
1541    if((cell == NULLP) ||
1542       (cell->cellId != rlsRnti->cellId))
1543    {
1544       
1545       RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1546                "No cellCb found with cellId for RNTI:%d", 
1547                          rlsRnti->rnti);
1548       RETVALUE(RFAILED);
1549    }
1550    /* Fix : syed Clearing UE context when SCH indicates to do so
1551     * UE DEL from CRG interface is now dummy. */
1552    if (rlsRnti->ueIdChng)
1553    {
1554       /* Fix : syed ueId change as part of reestablishment.
1555        * Now SCH to trigger this. CRG ueRecfg for ueId change 
1556        * is dummy */       
1557       if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)        
1558       {
1559          RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1560                         "CRNTI change failed for RNTI:%d new RNTI:%d",
1561                    rlsRnti->rnti,rlsRnti->newRnti);
1562          RETVALUE(RFAILED);
1563       }
1564
1565 #ifdef LTE_ADV
1566       /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1567        *rnti in all Scells
1568        */
1569       if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1570       {
1571          /* TODO: do we need to send DelInd to SCH in failure case*/ 
1572          RETVALUE(RFAILED);
1573       }
1574 #endif
1575 #ifdef L2_OPTMZ
1576       /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1577       delDatReq.cellId = cell->cellId;
1578       delDatReq.ueId = rlsRnti->rnti;
1579       rgLIMTfuDelDatReq(macInst, &delDatReq);
1580 #endif
1581    }
1582    else
1583    {
1584       rgUtlHndlCrntiRls(cell, rlsRnti);
1585    }
1586    /* Fix : syed Send delete confirmation to SCH */
1587    /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1588     * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1589 #ifdef LTE_ADV
1590    if(FALSE == rlsRnti->isUeSCellDel)
1591 #endif
1592    {
1593       ueDelInd.cellSapId  = cell->schInstMap.cellSapId;
1594       ueDelInd.cellId  = rlsRnti->cellId;
1595       ueDelInd.rnti    = rlsRnti->rnti; 
1596       rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1597       RgMacSchUeDel(&schPst, &ueDelInd);
1598    }
1599
1600    RETVALUE(ROK);
1601 } /* end of RgSchMacRlsRntiReq */
1602
1603 #ifdef L2_OPTMZ
1604 #ifdef ANSI
1605 PUBLIC Bool RgUtlIsTbMuxed
1606 (
1607  TfuDatReqTbInfo *tb
1608 )
1609 #else
1610 PUBLIC Bool RgUtlIsTbMuxed()
1611    TfuDatReqTbInfo *tb
1612 #endif
1613 {
1614    MsgLen len = 0;
1615    SFndLenMsg(tb->macHdr, &len);
1616    RETVALUE(len?TRUE : FALSE);
1617 }
1618 #endif
1619
1620 /**********************************************************************
1621  
1622          End of file
1623 **********************************************************************/