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