remove/replaced PRIVATE and EXTERN keywords
[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 static S16 rgUtlHndlCrntiChng ARGS((
74          Inst            inst,
75          RgCellCb        *cell,
76          CmLteRnti       rnti,
77          CmLteRnti       newRnti
78          ));
79 static 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 static 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:   void
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       return;
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       return;
276    }
277
278    *data = NULLP;
279
280    return;
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:   void
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       return;
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       return;
335    }
336
337    *data = NULLP;
338
339    return;
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 uint8_t          dgnType
417 )
418 #else
419 Void rgFillDgnParams(inst,dgn, dgnType)
420 Inst        inst;
421 RgUstaDgn   *dgn;
422 uint8_t          dgnType;
423 #endif
424 {
425
426    switch(dgnType)
427    {
428       case LRG_USTA_DGNVAL_MEM:
429          dgn->type = (uint8_t) 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    return;
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 uint8_t        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 uint8_t        stsType;   /* Statistics type to update */
471 RgRguDedDatReq *datReq;   /* DatReq pointer */
472 #endif
473 {
474    uint8_t idx1,idx2;
475    uint32_t 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    return;
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 uint8_t       stsType   /* Statistics type to update */
539 )
540 #else
541 Void rgUpdtRguCmnSts(inst,rguDlSap,stsType)
542 Inst           inst;
543 RgUpSapCb     *rguDlSap;
544 uint8_t       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    return;
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 uint8_t updtType
585 )
586 #else
587 Void rgUpdtCellCnt(inst,updtType)
588 Inst inst;
589 uint8_t 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    return;
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 uint8_t updtType
631 )
632 #else
633 Void rgUpdtUeCnt (inst,updtType)
634 Inst inst;
635 uint8_t 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    return;
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 uint32_t startTime=0;
682
683
684    sMem.region = rgCb[inst].rgInit.region;
685    sMem.pool = rgCb[inst].rgInit.pool;
686
687 #if (ERRCLASS & ERRCLS_DEBUG)
688    if (memSize<= 0)
689    {
690       RGLOGERROR(inst,ERRCLS_INT_PAR, ERG031, memSize,
691                    "rgAllocEventMem(): memSize invalid\n");
692       return  (RFAILED);
693    }
694 #endif /* ERRCLASS & ERRCLS_DEBUG */
695
696
697    /*starting Task*/
698    SStartTask(&startTime, PID_MACUTL_CMALLCEVT);
699
700 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
701    MS_BUF_ADD_ALLOC_CALLER();
702 #endif /* */
703 #ifdef TFU_ALLOC_EVENT_NO_INIT
704    if(ROK != cmAllocEvntNoInit(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
705 #else
706    if(ROK != cmAllocEvnt(memSize, TFU_MAX_MEMBLK_SIZE, &sMem, memPtr))
707 #endif /* */
708    {
709       RLOG0(L_ERROR,"cmAllocEvnt Failed"); 
710       return RFAILED;
711    }
712
713    /*stoping Task*/
714    SStopTask(startTime, PID_MACUTL_CMALLCEVT);
715
716    return ROK;
717 } /* end of rgAllocEventMem*/
718
719 /*
720 *
721 *       Fun:   rgGetEventMem
722 *
723 *       Desc:  This function allocates event memory 
724 *
725 *       Ret:   ROK      - on success
726 *              RFAILED  - on failure
727 *
728 *       Notes: None
729 *
730 *       File:  rg_utl.c
731 *
732 */
733 #ifdef ANSI
734 S16 rgGetEventMem
735 (
736 Inst      inst,
737 Ptr       *ptr,
738 Size      len,
739 Ptr       memCp
740 )
741 #else
742 S16 rgGetEventMem(inst,ptr, len, memCp)
743 Inst      inst;
744 Ptr       *ptr;
745 Size      len;
746 Ptr       memCp;
747 #endif
748 {
749    S16   ret;
750
751 #ifdef TFU_ALLOC_EVENT_NO_INIT
752    ret = cmGetMemNoInit(memCp, len, (Ptr *)ptr);
753 #else
754    ret = cmGetMem(memCp, len, (Ptr *)ptr);
755 #endif /* */
756    return (ret);
757 } /* end of rgGetEventMem*/
758
759 /***********************************************************
760  *
761  *     Func : rgGetPstToInst
762  *
763  *     Desc : Utility Function to get the pst structure to post a message to
764  *     scheduler instance
765  *            
766  *
767  *     Ret  : ROK
768  *            RFAILED
769  *
770  *     Notes: This function should be called while sending a msg from 
771  *     MAC to a scheduler instance
772  *
773  *     File : rg_utl.c
774  *
775  **********************************************************/
776 #ifdef ANSI
777 Void rgGetPstToInst
778 (
779 Pst           *pst,
780 Inst          srcInst,
781 Inst          dstInst
782 )
783 #else
784 Void rgGetPstToInst (pst, srcInst, dstInst)
785 Pst           *pst;
786 Inst          srcInst;
787 Inst          dstInst;
788 #endif
789 {
790
791    pst->srcEnt = rgCb[srcInst].rgInit.ent; 
792    pst->srcInst = rgCb[srcInst].rgInit.inst;
793    pst->srcProcId = rgCb[srcInst].rgInit.procId;
794    pst->region = rgCb[srcInst].rgInit.region;
795    pst->pool = rgCb[srcInst].rgInit.pool;
796
797    pst->dstProcId = rgCb[dstInst].rgInit.procId;
798    pst->dstEnt = rgCb[dstInst].rgInit.ent; 
799    pst->dstInst = dstInst;
800    pst->selector = 0;
801    pst->prior     = PRIOR0;
802    pst->intfVer   = 0;
803    pst->route   = RTESPEC;
804
805    return; 
806 } /* end of rgGetPstToInst */
807
808 /***********************************************************
809  *
810  *     Func : RgSchMacLcgRegReq
811  *
812  *     Desc : Utility Function to register the set of GBR LCG.
813  *        Invoked at the time of LCG configuration/Reconfiguration at Schedular.
814  * 
815  *     Processing Steps: 
816  *           - Fetch the ueCb using the crnti given in lcInfo            
817  *           - Store the if LCG is GBR or not.
818  *
819  *     Ret  : ROK
820  *            RFAILED
821  *
822  *     Notes: This function should be called at the time of LCG 
823  *     configuration/Reconfiguration at Schedular. 
824  *     
825  *
826  *     File : rg_utl.c
827  *
828  **********************************************************/
829 #ifdef ANSI
830 S16 RgSchMacLcgRegReq
831 (
832 Pst            *pst,
833 RgInfLcgRegReq *lcgRegReq
834 )
835 #else
836 S16 RgSchMacLcgRegReq (pst, lcgRegReq)
837 Pst            *pst;
838 RgInfLcgRegReq *lcgRegReq;
839 #endif
840 {
841    Inst       inst;
842    RgCellCb   *cell = NULLP;
843    RgUeCb     *ue;
844
845    RG_IS_INST_VALID(pst->dstInst);
846    inst   = pst->dstInst - RG_INST_START;
847    cell   = rgCb[inst].cell;
848    /* Fetch the cell and then the UE */
849    if((cell == NULLP) ||
850       (cell->cellId != lcgRegReq->cellId))
851    {
852       
853       RLOG_ARG0(L_ERROR,DBG_CELLID,lcgRegReq->cellId,"Cell does not exist ");
854       return RFAILED;
855    }
856
857    if ((ue = rgDBMGetUeCb(cell, lcgRegReq->crnti)) == NULLP)
858    {
859       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
860                          lcgRegReq->crnti);
861       return RFAILED;
862    }
863    ue->ul.lcgArr[lcgRegReq->lcgId].isGbr = lcgRegReq->isGbr;
864
865    return ROK; 
866 } /* end of RgSchMacLcgRegReq */
867
868 #ifdef LTEMAC_SPS
869
870 /***********************************************************
871  *
872  *     Func : RgSchMacUlSpsResetReq
873  *
874  *     Desc : Utility Function to reset SPS params for a UE
875  * 
876  *     Processing Steps: 
877  *           - Fetch the ueCb using the crnti 
878  *           - reset implRelCnt and explRelCnt
879  *
880  *     Ret  : ROK
881  *            RFAILED
882  *
883  *     File : rg_utl.c
884  *
885  **********************************************************/
886 #ifdef ANSI
887 S16 RgSchMacUlSpsResetReq
888 (
889 Pst            *pst,
890 RgInfUlSpsReset *ulSpsResetInfo
891 )
892 #else
893 S16 RgSchMacUlSpsResetReq (pst, lcInfo)
894 Pst            *pst;
895 RgInfUlSpsReset *ulSpsResetInfo;
896 #endif
897 {
898    Inst       inst;
899    RgCellCb   *cell = NULLP;
900    RgUeCb     *ue;
901
902    RG_IS_INST_VALID(pst->dstInst);
903    inst   = pst->dstInst - RG_INST_START;
904    cell   = rgCb[inst].cell;
905    /* Fetch the cell and then the UE */
906    if((cell == NULLP)||
907       (cell->cellId != ulSpsResetInfo->cellId))
908    {
909       
910       RLOG_ARG0(L_ERROR, DBG_CELLID,ulSpsResetInfo->cellId,"Cell does not exist ");
911       return RFAILED;
912    }
913
914    if ((ue = rgDBMGetUeCb(cell, ulSpsResetInfo->crnti)) == NULLP)
915    {
916       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
917                       ulSpsResetInfo->crnti);
918       return RFAILED;
919    }
920
921    ue->ul.implRelCntr = 0;
922    ue->ul.explRelCntr = 0;
923
924    return ROK; 
925 } /* end of RgSchMacUlSpsResetReq */
926
927
928
929
930 /***********************************************************
931  *
932  *     Func : RgSchMacSpsLcRegReq
933  *
934  *     Desc : Utility Function to register the set of uplink SPS logical
935  *        channels for a SPS UE.
936  *        Invoked at the time of activation of a UE for UL-SPS.
937  *        Whenever there is data on these LCs MAC shall inform scheduler
938  * 
939  *     Processing Steps: 
940  *           - Fetch the ueCb using the crnti given in lcInfo            
941  *           - Store the sps-rnti and set the bits corresponding to the
942  *             logical channel ids in ueUlCb->spsLcMask.
943  *
944  *     Ret  : ROK
945  *            RFAILED
946  *
947  *     Notes: This function should be called at the time UL SPS is activated 
948  *     for a UE at scheduler
949  *     
950  *
951  *     File : rg_utl.c
952  *
953  **********************************************************/
954 #ifdef ANSI
955 S16 RgSchMacSpsLcRegReq
956 (
957 Pst            *pst,
958 RgInfSpsLcInfo *lcInfo
959 )
960 #else
961 S16 RgSchMacSpsLcRegReq (pst, lcInfo)
962 Pst            *pst;
963 RgInfSpsLcInfo *lcInfo;
964 #endif
965 {
966    Inst       inst;
967    RgCellCb   *cell= NULLP;
968    RgUeCb     *ue;
969    uint8_t    idx;
970
971    RG_IS_INST_VALID(pst->dstInst);
972    inst   = pst->dstInst - RG_INST_START;
973    cell   = rgCb[inst].cell;
974    /* Fetch the cell and then the UE */
975    if((cell == NULLP) ||
976       (cell->cellId != lcInfo->cellId))
977    {
978       
979       RLOG_ARG0(L_ERROR,DBG_CELLID,lcInfo->cellId, "Cell does not exist ");
980       return RFAILED;
981    }
982
983    if ((ue = rgDBMGetUeCb(cell, lcInfo->crnti)) == NULLP)
984    {
985       RLOG_ARG1(L_ERROR, DBG_CELLID,cell->cellId,"CRNTI:%d does not exist", 
986                       lcInfo->crnti);
987       return RFAILED;
988    }
989
990    /* Store the sps-rnti and SPS LC information in the UE */ 
991    ue->spsRnti = lcInfo->spsRnti;
992    for (idx=0; idx < lcInfo->spsLcCnt; idx++)
993    {
994       /* KWORK_FIX: Modified the index from lcId to lcId-1 for handling lcId 10 properly */
995       ue->ul.spsLcId[(lcInfo->spsLcId[idx])-1] = TRUE;
996    }
997    ue->ul.implRelCnt = lcInfo->implRelCnt;
998    ue->ul.explRelCnt = ue->ul.implRelCnt + 1; /*(lcInfo->implRelCnt * lcInfo->spsPrd);*/
999
1000    /* Insert the UE into SPS UE List */
1001    if (rgDBMInsSpsUeCb(cell, ue) == RFAILED)
1002    {
1003       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1004                     "Ue insertion into SPS list failed SPS CRNTI:%d", ue->spsRnti);
1005       return RFAILED;
1006    } 
1007
1008    return ROK; 
1009 } /* end of RgSchMacSpsLcRegReq */
1010
1011
1012 /***********************************************************
1013  *
1014  *     Func : RgSchMacSpsLcDeregReq
1015  *
1016  *     Desc : Utility Function to deregister the set of uplink SPS 
1017  *        logical channels for a UE.
1018  *        Invoked at the time of release of UL-SPS for an activated UE.
1019  * 
1020  *     Processing Steps: 
1021  *           - Fetch the ueCb using the crnti given
1022  *           - Reset the bits corresponding to the logical channel ids in
1023  *             ueUlCb->spsLcMask.
1024  *
1025  *     Ret  : ROK
1026  *            RFAILED
1027  *
1028  *     Notes: This function should be called at the time UL SPS is released 
1029  *     for a UE at scheduler
1030  *     
1031  *
1032  *     File : rg_utl.c
1033  *
1034  **********************************************************/
1035 #ifdef ANSI
1036 S16 RgSchMacSpsLcDeregReq
1037 (
1038 Pst            *pst,
1039 CmLteCellId    cellId,
1040 CmLteRnti      crnti
1041 )
1042 #else
1043 S16 RgSchMacSpsLcDeregReq (pst, cellId, crnti)
1044 Pst            *pst;
1045 CmLteCellId    cellId;
1046 CmLteRnti      crnti;
1047 #endif
1048 {
1049    Inst       inst;
1050    RgCellCb   *cell = NULLP;
1051    RgUeCb      *ue;
1052
1053    RG_IS_INST_VALID(pst->dstInst);
1054    inst   = pst->dstInst - RG_INST_START;
1055    cell   = rgCb[inst].cell;
1056    /* Fetch the cell and then the UE */
1057    if((cell == NULLP) ||
1058       (cell->cellId != cellId))
1059    {
1060       
1061       RLOG_ARG0(L_ERROR,DBG_CELLID,cellId, "Cell does not exist ");
1062       return RFAILED;
1063    }
1064
1065    if ((ue = rgDBMGetUeCb(cell, crnti)) == NULLP)
1066    {
1067       RLOG_ARG1(L_ERROR, DBG_CELLID,cellId,"CRNTI:%d Ue does not exist", crnti);
1068       return RFAILED;
1069    }
1070
1071    /* No need to reset the SPS LC Ids as they will not be looked at*/
1072
1073    /* Delete UE from the SPS UE List */
1074    rgDBMDelSpsUeCb(cell, ue);
1075    
1076    return ROK; 
1077 } /* end of RgSchMacSpsLcDeregReq */
1078
1079 #endif /* LTEMAC_SPS */
1080
1081 /**
1082  * @brief Function for handling CRNTI change request 
1083  * received from scheduler to MAC.
1084  *
1085  * @details
1086  *
1087  *     Function : rgUtlHndlCrntiChng
1088  *     
1089  *        - Delete old UE from the list.
1090  *        - Update the new rnti and re-insert the UE in the list.
1091  *     
1092  *           
1093  *  @param[in] Inst        inst
1094  *  @param[in] RgCellCb      *cell,
1095  *  @param[in] CmLteRnti     rnti,
1096  *  @param[in] CmLteRnti     newRnti
1097  *  @return  S16
1098  *      -# ROK 
1099  *      -# RFAILED
1100  **/
1101 #ifdef ANSI
1102 static S16 rgUtlHndlCrntiChng 
1103 (
1104 Inst            inst,
1105 RgCellCb        *cell,
1106 CmLteRnti       rnti,
1107 CmLteRnti       newRnti
1108 )
1109 #else
1110 static S16 rgUtlHndlCrntiChng(inst,cell, rnti, newRnti)
1111 Inst            inst;
1112 RgCellCb        *cell;
1113 CmLteRnti       rnti;
1114 CmLteRnti       newRnti;
1115 #endif
1116 {
1117    RgUeCb         *ue = NULLP;
1118    RgUeCb         *newUe = NULLP;
1119
1120    ue = rgDBMGetUeCb(cell, rnti);
1121    newUe = rgDBMGetUeCbFromRachLst(cell, newRnti);
1122    if ((ue == NULLP) || (newUe == NULLP))
1123    {
1124       RLOG_ARG4(L_ERROR,DBG_CELLID,cell->cellId,
1125                         "RNTI:%d Failed to get UECB[%lu:%lu] or NEW RNTI:%d", 
1126                rnti, ((PTR)ue), ((PTR)newUe), newRnti);
1127       return RFAILED;
1128    }
1129 #ifdef XEON_SPECIFIC_CHANGES
1130    CM_LOG_DEBUG(CM_LOG_ID_MAC, "MAC:UE[%d] id changed to %d\n", rnti, newRnti);
1131 #endif
1132    rgDBMDelUeCb(cell, ue);
1133
1134    ue->ueId = newRnti;
1135
1136    memcpy(&(ue->contResId), &(newUe->contResId), 
1137                    sizeof(newUe->contResId));
1138    /* Fix : syed MSG4 might be RETXing need to store the
1139     * HARQ context. */
1140    rgDHMFreeUe(inst,&ue->dl.hqEnt);
1141    ue->dl.hqEnt = newUe->dl.hqEnt;
1142        
1143    rgDBMInsUeCb(cell, ue);
1144
1145    rgDBMDelUeCbFromRachLst(cell, newUe);
1146    rgFreeSBuf(inst,(Data **)&newUe, sizeof(*newUe));
1147
1148    return ROK;
1149 } /* end of rgUtlHndlCrntiChng */
1150
1151 #ifdef LTE_ADV
1152 /**
1153  * @brief Function for handling UE  release for SCELL
1154  * triggered from SCH to MAC.
1155  *
1156  * @details
1157  *
1158  *     Function : rgDelUeFrmAllSCell
1159  *     
1160  *        - This Function should be invoked by PCell of UE
1161  *        - Remove the UE context from SCELL corresponding to rnti.
1162  *           
1163  *  @param[in] Inst      *macInst,
1164  *  @param[in] RgUeCb    *ue
1165  *  @return  ROK is SUCCESS 
1166  **/
1167 #ifdef ANSI
1168 S16 rgDelUeFrmAllSCell
1169 (
1170 RgCellCb      *cell,
1171 RgUeCb        *ue
1172 )
1173 #else
1174 S16 rgDelUeFrmAllSCell(cell, ue)
1175 RgCellCb      *cell;
1176 RgUeCb        *ue;
1177 #endif
1178 {
1179    Inst        inst     = cell->macInst - RG_INST_START;
1180    uint8_t     idx      = 0;
1181    Inst        sCellInstIdx;
1182    Pst         dstInstPst;
1183    RgPrgUeSCellDelInfo ueSCellDelInfo;
1184
1185    /* To Delete the SCells if exisits for that UE */
1186    for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1187    {
1188       if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1189       {
1190          sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1191
1192          rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1193          ueSCellDelInfo.ueId = ue->ueId;
1194          ueSCellDelInfo.sCellId = ue->sCelInfo[idx].sCellId;
1195
1196          /* Filling same ueId in newRnti so that SMAC will check if newRnti
1197           *and old UeId is same that means its a UeSCell delete request*/
1198          ueSCellDelInfo.newRnti = ue->ueId;
1199
1200          RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueSCellDelInfo);
1201          ue->sCelInfo[idx].isSCellAdded = FALSE;
1202       } /* loop of if */
1203    } /* loop of for */
1204
1205    return ROK;
1206 } /* rgDelUeFrmAllSCell */
1207
1208 /**
1209  * @brief Function to validate AddSCellCfg.
1210  *
1211  * @details
1212  *
1213  *     Function : rgUtlVltdAddSCellCfg
1214  *     
1215  *           
1216  *  @param[in] ueSCellCb   secondary cell CB for validation
1217  *  @param[in] cell        cell control block
1218  *  @param[in] inst        instance number to fetch rgCb instance
1219  *  @return  S16
1220  *      -# ROK 
1221  **/
1222 #ifdef ANSI
1223 S16 rgUtlVltdAddSCellCfg
1224 (
1225  RgPrgUeSCellCfgInfo *ueSCellCb,
1226  RgCellCb    *cell,
1227  Inst        inst
1228 )
1229 #else
1230 S16 rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst)
1231  RgPrgUeSCellCfgInfo *ueSCellCb;
1232  RgCellCb    *cell;
1233  Inst        inst;
1234 #endif
1235 {
1236   S16 ret = ROK; 
1237   
1238   /* To Validate the CellID presence */
1239   if((cell == NULLP) ||
1240         (cell->cellId != ueSCellCb->cellId))
1241   {
1242      RGDBGERRNEW(inst, (rgPBuf(inst),
1243               "[%d]Sec Cell does not exit %d\n",
1244               ueSCellCb->ueId, ueSCellCb->cellId));
1245      ret = RFAILED;
1246   }
1247 #ifdef TENB_MULT_CELL_SUPPRT
1248    if((ueSCellCb->rguDlSapId > rgCb[inst].numRguSaps) ||
1249       (ueSCellCb->rguUlSapId > rgCb[inst].numRguSaps))
1250    {
1251       RGDBGERRNEW(inst,(rgPBuf(inst), "Invald Sap Id: DL %d UL %d for ueId %d failed\n",
1252                ueSCellCb->rguDlSapId,
1253                ueSCellCb->rguUlSapId,
1254                ueSCellCb->cellId));
1255      ret = RFAILED;
1256    }
1257 #endif
1258    return (ret);
1259 } /* rgUtlVltdAddSCellCfg */
1260
1261 /**
1262  * @brief Function to build CrntiChangeReq and send to all SMACs.
1263  *
1264  * @details
1265  *
1266  *     Function : rgUtlSndCrntiChngReq2AllSMacs
1267  *     
1268  *        - This Function should be invoked by PCell of UE
1269  *        - It sends RgPrgPMacSMacUeSCellDelReq to all SMACs with newRnti sent
1270  *          by SCH. SMAC will check if newRnti is not equal to old UeId then it
1271  *          do only UeId change else it will delete the UeScell context
1272  *           
1273  *  @param[in] cell    Cell CB to get Ue control block
1274  *  @param[in] rnti    Ue Identifier used to fill in UeId Change req
1275  *  @param[in] newRnti UE new identifier, to be used in UeId Change req
1276  *  @return  S16
1277  *      -# ROK 
1278  **/
1279 #ifdef ANSI
1280 static S16 rgUtlSndCrntiChngReq2AllSMacs
1281 (
1282 RgCellCb        *cell,
1283 CmLteRnti       rnti,
1284 CmLteRnti       newRnti
1285 )
1286 #else
1287 static S16 rgUtlSndCrntiChngReq2AllSMacs(cell, rnti, newRnti)
1288 RgCellCb        *cell;
1289 CmLteRnti       rnti;
1290 CmLteRnti       newRnti;
1291 #endif
1292 {
1293    Inst                inst = cell->macInst - RG_INST_START;
1294    Inst                sCellInstIdx;
1295    Pst                 dstInstPst;
1296    RgPrgUeSCellDelInfo ueIdChngReq;
1297    RgUeCb              *ue;
1298    uint8_t                  idx;
1299 #ifdef L2_OPTMZ
1300 TfuDelDatReqInfo delDatReq;
1301 #endif
1302
1303    /* use newRnti to get UeCb in PMac because rnti is already changed in PMac*/
1304    ue = rgDBMGetUeCb(cell, newRnti);
1305    if (ue == NULLP)
1306    {
1307       RGDBGERRNEW(inst,(rgPBuf(inst),"[%d]RNTI:Failed to get ueCb \
1308                newRnti=%d\n", rnti, newRnti));
1309       return RFAILED;
1310    }
1311    /* For all added SCells, prepare and send ueIdChngReq */
1312    for(idx = 0; idx < RG_MAX_SCELL_PER_UE ; idx++)
1313    {
1314       if(TRUE == ue->sCelInfo[idx].isSCellAdded)
1315       {
1316          sCellInstIdx = ue->sCelInfo[idx].macInst - RG_INST_START;
1317
1318          rgGetPstToInst(&dstInstPst, inst, sCellInstIdx);
1319          /* fill old rnti*/
1320          ueIdChngReq.ueId = rnti;
1321          ueIdChngReq.sCellId = ue->sCelInfo[idx].sCellId;
1322          
1323          /* Filling newRnti so that SMAC can check if old ueId and new UeId
1324           *(newRnti) is different then its a UeId change request from PMAC.
1325           * RgPrgPMacSMacUeSCellDelReq is being reused for UeId change req
1326           * from PMAC to SMAC*/
1327          ueIdChngReq.newRnti = newRnti;
1328          
1329          /* Re-using UeSCellDelReq API for UeId change*/
1330          RgPrgPMacSMacUeSCellDel(&dstInstPst, &ueIdChngReq);
1331 #ifdef L2_OPTMZ
1332       /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1333       delDatReq.cellId = ueIdChngReq.sCellId;
1334       delDatReq.ueId = ueIdChngReq.ueId;
1335       rgLIMTfuDelDatReq(sCellInstIdx, &delDatReq);
1336 #endif
1337
1338       } /* loop of if */
1339    } /* loop of for */
1340
1341    return ROK;
1342 } /* rgUtlSndCrntiChngReq2AllSMacs */
1343
1344 #endif /* LTE_ADV */
1345
1346 /**
1347  * @brief Function for handling CRNTI Context release 
1348  * triggered from SCH to MAC.
1349  *
1350  * @details
1351  *
1352  *     Function : rgUtlHndlCrntiRls
1353  *     
1354  *        - Remove the UE context from MAC corresponding to rnti.
1355  *     
1356  *           
1357  *  @param[in] RgCellCb      *cell,
1358  *  @param[in] CmLteRnti     rnti
1359  *  @return  Void 
1360  **/
1361 #ifdef ANSI
1362 static Void rgUtlHndlCrntiRls
1363 (
1364 RgCellCb        *cell,
1365 RgInfRlsRnti    *rlsRnti
1366 )
1367 #else
1368 static Void rgUtlHndlCrntiRls(cell, rlsRnti)
1369 RgCellCb        *cell;
1370 CmLteRnti       *rlsRnti;
1371 #endif
1372 {
1373    Inst           inst = cell->macInst - RG_INST_START;
1374    RgUeCb        *ue = NULLP;
1375 #ifdef LTEMAC_SPS
1376    RgUeCb         *spsUeCb = NULLP;
1377 #endif
1378
1379    if ((ue = rgDBMGetUeCb(cell, rlsRnti->rnti)) == NULLP)
1380    {
1381       /* Check in RachLst */
1382       if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1383       {
1384          /* Delete Ue from the UE list */
1385          rgDBMDelUeCbFromRachLst(cell, ue);
1386
1387          /* Free Ue */
1388          rgRAMFreeUeCb(inst,ue);
1389       }
1390       else
1391       {
1392          RLOG_ARG1(L_WARNING,DBG_CELLID,cell->cellId,
1393                    "RNTI:%d No ueCb found in RachLst",rlsRnti->rnti);
1394       }
1395    }
1396    else
1397    {
1398 #ifdef LTE_ADV
1399       if(FALSE == rlsRnti->isUeSCellDel)
1400       {
1401          rgDelUeFrmAllSCell(cell, ue);
1402       }
1403 #endif /* LTE_ADV */
1404
1405       /* Delete Ue from the UE list */
1406       rgDBMDelUeCb(cell, ue);
1407 #ifdef LTEMAC_SPS
1408       spsUeCb = rgDBMGetSpsUeCb (cell, ue->spsRnti);
1409       if (spsUeCb)
1410       {
1411          rgDBMDelSpsUeCb(cell, spsUeCb);
1412       }
1413 #endif
1414
1415       /* Free Ue */
1416       rgCFGFreeUeCb(cell, ue);     
1417       /* MS_REMOVE : syed Check in RachLst */
1418       {
1419          if((ue=rgDBMGetUeCbFromRachLst (cell, rlsRnti->rnti)) != NULLP)
1420          {
1421             RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
1422                         "RNTI:%d STALE UE is still present", rlsRnti->rnti);         
1423          }
1424       }
1425    }
1426
1427    return;
1428 } /* end of rgUtlHndlCrntiRls */
1429
1430 /**
1431  * @brief Function for handling RaResp request received from scheduler to MAC.
1432  *
1433  * @details
1434  *
1435  *     Function : RgSchMacRlsRntiReq
1436  *     
1437  *     This function shall be invoked whenever scheduler is done with the
1438  *     allocations of random access responses for a subframe.
1439  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
1440  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
1441  *     
1442  *           
1443  *  @param[in] CmLteCellId         cellId,
1444  *  @param[in] CmLteTimingInfo     timingInfo,
1445  *  @param[in] RaRespInfo          *rarInfo
1446  *  @return  S16
1447  *      -# ROK 
1448  **/
1449 #ifdef ANSI
1450 S16 RgSchMacRlsRntiReq
1451 (
1452 Pst                 *pst,
1453 RgInfRlsRnti        *rlsRnti
1454 )
1455 #else
1456 S16 RgSchMacRlsRntiReq(pst, rlsRnti)
1457 Pst                 *pst;
1458 RgInfRlsRnti        *rlsRnti;
1459 #endif
1460 {
1461 //   Pst            schPst;
1462 //   RgInfUeDelInd  ueDelInd;
1463    Inst           macInst;
1464    RgCellCb       *cell;
1465 #ifdef L2_OPTMZ
1466 TfuDelDatReqInfo delDatReq;
1467 #endif
1468
1469    RG_IS_INST_VALID(pst->dstInst);
1470    macInst   = pst->dstInst - RG_INST_START;
1471    cell   = rgCb[macInst].cell;
1472
1473    if(NULLP == rlsRnti)
1474    {
1475       return RFAILED;
1476    }
1477
1478    if((cell == NULLP) ||
1479       (cell->cellId != rlsRnti->cellId))
1480    {
1481       
1482       RLOG_ARG1(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1483                "No cellCb found with cellId for RNTI:%d", 
1484                          rlsRnti->rnti);
1485       return RFAILED;
1486    }
1487    /* Fix : syed Clearing UE context when SCH indicates to do so
1488     * UE DEL from CRG interface is now dummy. */
1489    if (rlsRnti->ueIdChng)
1490    {
1491       /* Fix : syed ueId change as part of reestablishment.
1492        * Now SCH to trigger this. CRG ueRecfg for ueId change 
1493        * is dummy */       
1494       if (rgUtlHndlCrntiChng(macInst,cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)        
1495       {
1496          RLOG_ARG2(L_ERROR,DBG_CELLID,rlsRnti->cellId,
1497                         "CRNTI change failed for RNTI:%d new RNTI:%d",
1498                    rlsRnti->rnti,rlsRnti->newRnti);
1499          return RFAILED;
1500       }
1501
1502 #ifdef LTE_ADV
1503       /*PMAC_Reest: Prepare CrntiChngReq and then send to all SMACs to change
1504        *rnti in all Scells
1505        */
1506       if(rgUtlSndCrntiChngReq2AllSMacs(cell, rlsRnti->rnti, rlsRnti->newRnti) != ROK)
1507       {
1508          /* TODO: do we need to send DelInd to SCH in failure case*/ 
1509          return RFAILED;
1510       }
1511 #endif
1512 #ifdef L2_OPTMZ
1513       /* Sending delDatReq to CL to clear the Pdus for old UeId present in CL*/
1514       delDatReq.cellId = cell->cellId;
1515       delDatReq.ueId = rlsRnti->rnti;
1516       rgLIMTfuDelDatReq(macInst, &delDatReq);
1517 #endif
1518    }
1519    else
1520    {
1521       rgUtlHndlCrntiRls(cell, rlsRnti);
1522    }
1523    /* Fix : syed Send delete confirmation to SCH */
1524    /* Send RgMacSchUeDelInd to SCH only if it is Rnti release to PMAC.
1525     * Basically dont send DelInd to SCH incase of Ue SCell Del*/
1526 #ifdef LTE_ADV
1527    if(FALSE == rlsRnti->isUeSCellDel)
1528 #endif
1529    {
1530       //TODO: commented for compilation without SCH 
1531 #if 0
1532       ueDelInd.cellSapId  = cell->schInstMap.cellSapId;
1533       ueDelInd.cellId  = rlsRnti->cellId;
1534       ueDelInd.rnti    = rlsRnti->rnti; 
1535       rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
1536       RgMacSchUeDel(&schPst, &ueDelInd);
1537 #endif
1538    }
1539
1540    return ROK;
1541 } /* end of RgSchMacRlsRntiReq */
1542
1543 #ifdef L2_OPTMZ
1544 #ifdef ANSI
1545 Bool RgUtlIsTbMuxed
1546 (
1547  TfuDatReqTbInfo *tb
1548 )
1549 #else
1550 Bool RgUtlIsTbMuxed()
1551    TfuDatReqTbInfo *tb
1552 #endif
1553 {
1554    MsgLen len = 0;
1555    SFndLenMsg(tb->macHdr, &len);
1556    return (len?TRUE : FALSE);
1557 }
1558 #endif
1559
1560 /**********************************************************************
1561  
1562          End of file
1563 **********************************************************************/