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