Merge "replaced cmMemSet, cmMemcpy with memset and memcpy resp AND Removed TRC()...
[o-du/l2.git] / src / 5gnrmac / rg_uim.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_uim.c 
28   
29 **********************************************************************/
30
31 /** @file rg_uim.c.
32 @brief This module acts as an interface handler for upper interface and 
33 manages Pst and Sap related information for upper interface APIs.
34 */
35
36 static const char* RLOG_MODULE_NAME="MAC";
37 static int RLOG_MODULE_ID=4096;
38 static int RLOG_FILE_ID=178;
39
40 /* header include files -- defines (.h) */
41
42 /* header/extern include files (.x) */
43 /* header include files (.h) */
44 #include "common_def.h"
45 #include "crg.h"           /* CRG defines */
46 #include "lrg.h"           /* layer management defines for LTE-MAC */
47 #include "tfu.h"
48 #include "rgu.h"
49 #include "rg_sch_inf.h"
50 #include "rg_env.h"        /* customizable defines and macros for MAC */
51 #include "rg.h"            /* defines and macros for MAC */
52 #include "rg_err.h"        /* RG error defines */
53
54 /* header/extern include files (.x) */
55
56 #include "crg.x"           /* CRG types */
57 #include "lrg.x"           /* layer management typedefs for MAC */
58 #include "tfu.x"
59 #include "rgu.x"
60 #include "rg_sch_inf.x"
61 #include "rg_prg.x"        /* PRG interface typedefs*/
62 #include "du_app_mac_inf.h"
63 #include "rg.x"            /* typedefs for MAC */
64
65 #include "ss_rbuf.h"
66 #include "ss_rbuf.x"
67
68 /* local defines */
69
70 /* local typedefs */
71  
72 /* local externs */
73  
74 /* forward references */
75
76 #if defined(SPLIT_RLC_DL_TASK) && defined(RLC_MAC_STA_RSP_RBUF)
77 S16 rgBatchProc(Void);
78 #endif
79 U8 rgRguDlSap;
80 U8 rgRguUlSap;
81 /**
82  * @brief Handler for Bind request.
83  *
84  * @details
85  *
86  *     Function : RgUiRguBndReq
87  *     
88  *     This function handles the bind request from MAC Service User.
89  *     
90  *           
91  *  @param[in]  Pst  *pst
92  *  @param[in]  SuId suId
93  *  @param[in]  SpId spId
94  *  @return  S16
95  *      -# ROK 
96  *      -# RFAILED 
97  **/
98 #ifdef ANSI
99 S16 RgUiRguBndReq
100 (
101 Pst  *pst,
102 SuId suId,
103 SpId spId
104 )
105 #else
106 S16 RgUiRguBndReq(pst, suId, spId)
107 Pst  *pst;
108 SuId suId;
109 SpId spId;
110 #endif
111 {
112    Inst      inst; 
113    S16       ret = ROK;
114    Pst       tmpPst;   /* Temporary Post Structure */
115    RgUstaDgn dgn;      /* Alarm diagnostics structure */
116
117    RG_IS_INST_VALID(pst->dstInst);
118    inst = pst->dstInst - RG_INST_START;
119
120    tmpPst.prior       = pst->prior;
121    tmpPst.route       = pst->route;
122    tmpPst.selector    = pst->selector;
123    tmpPst.region      = rgCb[inst].rgInit.region;
124    tmpPst.pool        = rgCb[inst].rgInit.pool;
125    tmpPst.srcProcId   = rgCb[inst].rgInit.procId;
126    tmpPst.srcEnt      = rgCb[inst].rgInit.ent;
127    tmpPst.srcInst     = rgCb[inst].rgInit.inst;
128    tmpPst.event       = EVTNONE;
129    tmpPst.dstProcId   = pst->srcProcId;
130    tmpPst.dstEnt      = pst->srcEnt;
131    tmpPst.dstInst     = pst->srcInst;
132
133    if(spId == rgCb[inst].rguSap[spId].sapCfg.spId)
134    {
135       /* Check the state of the SAP */
136       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
137       {
138          case LRG_NOT_CFG: /* SAP Not configured */
139             RGDBGINFO(inst,(rgPBuf(inst), "SAP Not Configured\n"));
140             rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM); 
141             ret = rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE,LRG_NOT_CFG,
142                   LCM_CAUSE_INV_SAP, &dgn);
143             RLOG0(L_DEBUG,"SAP Not Configured");
144             ret = RgUiRguBndCfm(&tmpPst, suId, CM_BND_NOK);
145             break;
146          case LRG_UNBND: /* SAP is not bound */
147             RLOG0(L_DEBUG,"SAP Not yet bound");
148             rgCb[inst].rguSap[spId].sapSta.sapState = LRG_BND;
149             rgCb[inst].rguSap[spId].sapCfg.suId = suId;
150             /* Send Bind Confirm with status as SUCCESS */
151             /*T2K - Passing spId as it is required to access the SAP CB*/
152             ret = rgUIMRguBndCfm(inst,spId, CM_BND_OK);
153             /* Indicate to Layer manager */ 
154             rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM); 
155             ret = rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE,LRG_EVENT_RGUSAP_ENB,
156                   LCM_CAUSE_UNKNOWN, &dgn);
157             break;
158          case LRG_BND: /* SAP is already bound*/
159             RLOG0(L_DEBUG,"SAP already bound");
160             /*T2K - Passing spId as it is required to access the SAP CB*/
161             ret = rgUIMRguBndCfm(inst,spId, CM_BND_OK);
162             break;
163          default: /* Should Never Enter here */
164 #if (ERRCLASS & ERRCLS_ADD_RES)      
165             RGLOGERROR(inst,ERRCLS_INT_PAR, ERG008, (ErrVal)rgCb[inst].rguSap[spId].sapSta.sapState,
166                   "Invalid SAP State:RgUiRguBndReq failed\n");
167 #endif
168             /*T2K - Passing spId as it is required to access the SAP CB*/
169             ret = rgUIMRguBndCfm(inst,spId, CM_BND_NOK);
170             break;
171       }
172    }
173    else
174    {
175 #if (ERRCLASS & ERRCLS_ADD_RES)      
176       RGLOGERROR(inst,ERRCLS_INT_PAR, ERG009, (ErrVal)rgCb[inst].rguSap[spId].sapCfg.spId,
177             "Invalid SAP Id:RgUiRguBndReq failed\n");
178 #endif
179       /*T2K - Passing spId as it is required to access the SAP CB*/
180       ret = rgUIMRguBndCfm(inst,spId, CM_BND_NOK);
181    }
182    return (ret);
183 }  /* RgUiRguBndReq */
184
185
186 /**
187  * @brief Handler for Unbind request.
188  *
189  * @details
190  *
191  *     Function : RgUiRguUbndReq
192  *     
193  *     This function handles the unbind request from MAC Service User.
194  *     
195  *           
196  *  @param[in]  Pst    *pst
197  *  @param[in]  SpId   spId
198  *  @param[in]  Reason reason
199  *  @return  S16
200  *      -# ROK 
201  *      -# RFAILED 
202  **/
203 #ifdef ANSI
204 S16 RgUiRguUbndReq
205 (
206 Pst    *pst,
207 SpId   spId,
208 Reason reason
209 )
210 #else
211 S16 RgUiRguUbndReq(pst, spId, reason)
212 Pst    *pst;
213 SpId   spId;
214 Reason reason;
215 #endif
216 {
217    Inst      inst;
218
219    RG_IS_INST_VALID(pst->dstInst);
220    inst = pst->dstInst - RG_INST_START;
221    /* SAP Id validation */
222    if (spId == rgCb[inst].rguSap[spId].sapCfg.spId)
223    {
224       switch(rgCb[inst].rguSap[spId].sapSta.sapState)
225       {
226          case LRG_BND: /* SAP is already bound*/
227             RLOG0(L_DEBUG,"SAP already bound");
228             /* setting SAP state to UN BOUND */
229             rgCb[inst].rguSap[spId].sapSta.sapState = LRG_UNBND;
230             break;
231          default:
232 #if (ERRCLASS & ERRCLS_ADD_RES)      
233      RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguUbndReq failed",
234                   rgCb[inst].rguSap[spId].sapSta.sapState);
235        
236 #endif
237             break;
238       }
239    }
240    else
241    {
242 #if (ERRCLASS & ERRCLS_ADD_RES)      
243       RGLOGERROR(inst,ERRCLS_INT_PAR, ERG011, (ErrVal)rgCb[inst].rguSap[spId].sapCfg.spId,
244             "Invalid SAP Id:RgUiRguUbndReq failed\n");
245 #endif
246       return RFAILED;
247    }
248    return ROK;
249 }  /* RgUiRguUbndReq */
250 /**
251  * @brief API for sending bind confirm from MAC to RLC
252  *
253  * @details
254  *
255  *     Function: rgUIMRguBndCfm
256  *     
257  *     This API is invoked to send bind confirm from MAC to RLC.
258  *     This API fills in Pst structure and SAP Ids and invokes 
259  *     bind confirm API towards RLC.
260  *           
261  *  @param[in] Inst        inst
262  *  @param[in]  SuId          suId
263  *  @param[in]  U8            status
264  *  @return  S16
265  *      -# ROK 
266  *      -# RFAILED 
267  **/
268 #ifdef ANSI
269 S16 rgUIMRguBndCfm
270 (
271 Inst inst,
272 SpId spId,
273 U8 status
274 )
275 #else
276 S16 rgUIMRguBndCfm(inst,spId, status)
277 Inst          inst;
278 SpId          spId;
279 U8            status;
280 #endif
281 {
282    S16  ret = ROK;
283    
284    ret = RgUiRguBndCfm(&rgCb[inst].rguSap[spId].sapCfg.sapPst, 
285                       rgCb[inst].rguSap[spId].sapCfg.suId, status);
286    if (ret != ROK)
287    {
288       
289       RLOG0(L_ERROR,"RgUiRguBndCfm Failed ");
290       return (ret);
291    }
292    return (ret);
293 }  /* rgUIMRguBndCfm*/
294
295
296 /**
297  * @brief Handler for dedicated DatReq from RGU
298  *
299  * @details
300  *
301  *     Function : RgUiRguDDatReq
302  *     
303  *     This function validates SAP and invokes ROM for further processing
304  *     
305  *  @param[in]  Pst             *pst 
306  *  @param[in]  SpId            spId 
307  *  @param[in]  RguDDatReqInfo  *datReq
308  *  @return  S16
309  *      -# ROK 
310  *      -# RFAILED 
311  **/
312 #ifdef ANSI
313 S16 RgUiRguDDatReq
314 (
315 Pst             *pst,
316 SpId            spId,
317 RguDDatReqInfo  *datReq
318 )
319 #else
320 S16 RgUiRguDDatReq(pst, spId, datReq)
321 Pst             *pst;
322 SpId            spId;
323 RguDDatReqInfo  *datReq;
324 #endif
325 {
326    S16   ret = ROK;
327    Inst  inst;
328 #ifndef NO_ERRCLS 
329    U32   id;
330    U32   id1;
331    U32   id2;
332    U32   id3;
333 #endif
334    
335    RG_IS_INST_VALID(pst->dstInst);
336    inst = pst->dstInst - RG_INST_START;
337 #ifndef NO_ERRCLS
338    if (datReq == NULLP)
339    {
340       RLOG0(L_ERROR,"Input Message Buffer is NULL");
341       return RFAILED;
342    }
343    
344    if(rgCb[inst].rguSap[spId].sapCfg.spId == spId)
345    {
346       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
347       {
348          case LRG_BND: /* SAP is bound */
349             RLOG0(L_DEBUG,"SAP is already bound");
350             break;
351          default: /* Should never reach here */
352 #if (ERRCLASS & ERRCLS_ADD_RES)      
353             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguDDatReq failed",
354                   rgCb[inst].rguSap[spId].sapSta.sapState);
355 #endif
356 #ifndef L2_OPTMZ
357             for(id3 = 0; id3 < datReq->nmbOfUeGrantPerTti; id3++)
358             {
359                RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[id3]);
360             }
361 #endif
362             return RFAILED;
363       }
364    }
365    else
366    {
367 #if (ERRCLASS & ERRCLS_ADD_RES)      
368       RGLOGERROR(inst,ERRCLS_INT_PAR, ERG013, (ErrVal)spId,
369             "Invalid SAP Id:RgUiRguDDatReq failed\n");
370 #endif
371 #ifndef L2_OPTMZ
372       for(id3 = 0; id3 < datReq->nmbOfUeGrantPerTti; id3++)
373       {
374          RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[id3]);
375       }
376 #endif
377       return RFAILED;
378    }
379
380    /* Update RGU SAP statistics for received sdu count */
381    /*ccpu00118201 - ADD - Send trace only when its enabled*/
382    if(rgCb[inst].rgInit.trc)
383    {
384       for(id3 = 0; id3 < datReq->nmbOfUeGrantPerTti; id3++)
385       {
386          RguDDatReqPerUe *datReqPerUe = &datReq->datReq[id3];
387          for (id = 0; id < datReqPerUe->nmbOfTbs; id++)
388          {
389             for (id1 = 0; id1 < datReqPerUe->datReqTb[id].nmbLch; id1++)
390             {
391                /* rgCb.rguSap.sapSts.numPduRcvd is updated by 
392                 * rgROMDedDatReq -> rgUpdtRguDedSts function
393                 * So numPduRcvd updation is commented here */
394                /* rgCb.rguSap.sapSts.numPduRcvd +=
395                   datReq->datReqTb[id].lchData[id1].pdu.numPdu; */
396                for (id2 = 0; id2 < datReqPerUe->datReqTb[id].lchData[id1].pdu.numPdu; id2++)
397                {
398                   RG_SEND_TRC_IND(inst,datReqPerUe->datReqTb[id].
399                         lchData[id1].pdu.mBuf[id2], EVTRGUDDATREQ);
400                }
401             }
402          }
403       }
404    }
405 #endif
406
407    /* Call Ownership module for further processing */
408    ret = rgROMDedDatReq(inst,datReq);
409     SPutStaticBuffer(pst->region, pst->pool, (Data *)datReq,sizeof(RguDDatReqInfo), SS_SHARABLE_MEMORY);
410    datReq = NULLP;
411    return (ret);
412 }  /* RgUiRguDDatReq */
413
414
415 /**
416  * @brief Handler for common DatReq from RGU
417  *
418  * @details
419  *
420  *     Function : RgUiRguCDatReq
421  *     
422  *     This function validates SAP invokes ROM for further processing
423  *     
424  *  @param[in]  Pst             *pst 
425  *  @param[in]  SpId            spId 
426  *  @param[in]  RguCDatReqInfo  *datReq
427  *  @return  S16
428  *      -# ROK 
429  *      -# RFAILED 
430  **/
431 #ifdef ANSI
432 S16 RgUiRguCDatReq
433 (
434 Pst             *pst,
435 SpId            spId,
436 RguCDatReqInfo  *datReq
437 )
438 #else
439 S16 RgUiRguCDatReq(pst, spId, datReq)
440 Pst             *pst;
441 SpId            spId;
442 RguCDatReqInfo  *datReq;
443 #endif
444 {
445    Inst  inst;
446    S16   ret = ROK;
447    
448    RG_IS_INST_VALID(pst->dstInst);
449    inst = pst->dstInst - RG_INST_START;
450 #ifndef NO_ERRCLS
451    if (datReq == NULLP)
452    {
453       RLOG0(L_ERROR,"Input Message Buffer is NULL");
454       return RFAILED;
455    }
456    
457    if(rgCb[inst].rguSap[spId].sapCfg.spId == spId)
458    {
459       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
460       {
461          case LRG_BND: /* SAP is bound */
462             RLOG0(L_DEBUG,"SAP is already bound");
463             break;
464          default: /* Should never reach here */
465 #if (ERRCLASS & ERRCLS_ADD_RES)      
466             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguCDatReq failed",
467                   rgCb[inst].rguSap[spId].sapSta.sapState);
468 #endif
469             return RFAILED;
470       }
471    }
472    else
473    {
474 #if (ERRCLASS & ERRCLS_ADD_RES)      
475       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiRguCDatReq failed ",spId);
476 #endif
477       return RFAILED;
478    }
479 #endif
480
481    /* Update RGU SAP statistics for received sdu count */
482    /* rgCb.rguSap.sapSts.numPduRcvd is updated by 
483     * rgROMCmnDatReq ->rgUpdtRguCmnSts function
484     * So numPduRcvd updation is commented here */
485    /* rgCb.rguSap.sapSts.numPduRcvd++; */
486
487    ret = rgROMCmnDatReq(inst,datReq);
488    /*ccpu00118201 - ADD - Send trace only when its enabled*/
489    if(rgCb[inst].rgInit.trc)
490    {
491       RG_SEND_TRC_IND(inst,datReq->pdu, EVTRGUCDATREQ);
492    }
493    if (ret == RFAILED)
494    {
495       RG_DROP_RGUCDATREQ_MBUF(datReq);
496    }
497    ret = SPutStaticBuffer(pst->region, pst->pool,(Data *)datReq,sizeof(RguCDatReqInfo) , SS_SHARABLE_MEMORY);
498    datReq = NULLP;
499    return (ret);
500 }  /* RgUiRguCDatReq */
501
502
503 /**
504  * @brief Handler for dedicated StaRsp from RGU
505  *
506  * @details
507  *
508  *     Function : RgUiRguDStaRsp
509  *     
510  *     This function validates SAP and invokes ROM for further processing
511  *           
512  *  @param[in]  Pst             *pst 
513  *  @param[in]  SpId            spId 
514  *  @param[in]  RguDStaRspInfo  *staRsp
515  *  @return  S16
516  *      -# ROK 
517  *      -# RFAILED 
518  **/
519 #ifdef ANSI
520 S16 RgUiRguDStaRsp
521 (
522 Pst             *pst,
523 SpId            spId,
524 RguDStaRspInfo  *staRsp
525 )
526 #else
527 S16 RgUiRguDStaRsp(pst, spId, staRsp)
528 Pst             *pst;
529 SpId            spId;
530 RguDStaRspInfo  *staRsp;
531 #endif
532 {
533    Inst  inst;
534
535    S16              ret       = ROK;
536    VOLATILE U32     startTime = 0;
537
538    RG_IS_INST_VALID(pst->dstInst);
539    inst = pst->dstInst - RG_INST_START;
540    /*starting Task*/
541    SStartTask(&startTime, PID_MAC_STA_RSP);
542
543    ret = rgROMDedStaRsp(inst,staRsp);
544    if (ret != ROK)
545    {
546       RLOG_ARG0(L_ERROR,DBG_CELLID,staRsp->cellId,
547                 "Processing Of Status Response Failed");
548    }
549
550
551    /*stoping Task*/
552    SStopTask(startTime, PID_MAC_STA_RSP);
553    return (ret);
554 }  /* RgUiRguDStaRsp */
555
556
557 /**
558  * @brief Handler for common StaRsp from RGU
559  *
560  * @details
561  *
562  *     Function : RgUiRguCStaRsp
563  *     
564  *     This function validates SAP and invokes ROM 
565  *     for further processing
566  *     
567  *           
568  *  @param[in]  Pst             *pst 
569  *  @param[in]  SpId            spId 
570  *  @param[in]  RguCStaRspInfo  *staRsp
571  *  @return  S16
572  *      -# ROK 
573  *      -# RFAILED 
574  **/
575 #ifdef ANSI
576 S16 RgUiRguCStaRsp
577 (
578 Pst             *pst,
579 SpId            spId,
580 RguCStaRspInfo  *staRsp
581 )
582 #else
583 S16 RgUiRguCStaRsp(pst, spId, staRsp)
584 Pst             *pst;
585 SpId            spId;
586 RguCStaRspInfo  *staRsp;
587 #endif
588 {
589    Inst  inst;
590    S16   ret = ROK;
591
592    RG_IS_INST_VALID(pst->dstInst);
593    inst = pst->dstInst - RG_INST_START;
594 #ifndef NO_ERRCLS
595    if (staRsp == NULLP)
596    {
597       RLOG0(L_ERROR,"Input Response Buffer is NULL");
598       return RFAILED;
599    }
600
601    if (spId == rgCb[inst].rguSap[spId].sapCfg.spId)
602    {
603       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
604       {
605          case LRG_BND: /* SAP is bound */
606             RLOG0(L_DEBUG,"SAP is already bound");
607             break;
608          default: /* Should never reach here */
609 #if (ERRCLASS & ERRCLS_ADD_RES)      
610             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguCStaRsp failed",
611                   rgCb[inst].rguSap[spId].sapSta.sapState);
612 #endif
613             return RFAILED;
614       }
615    }
616    else
617    {
618 #if (ERRCLASS & ERRCLS_ADD_RES)      
619       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiRguCStaRsp failed",spId);
620 #endif
621       return RFAILED;
622    }
623 #endif
624
625    ret = rgROMCmnStaRsp(inst,staRsp);
626    if (ret != ROK)
627    {
628       RLOG_ARG0(L_ERROR,DBG_CELLID,staRsp->cellId,"Processing Of Status Response Failed");
629       return (ret);
630    }
631
632    ret = SPutStaticBuffer(pst->region, pst->pool, (Data *)staRsp,sizeof(RguCStaRspInfo) , SS_SHARABLE_MEMORY);
633    staRsp = NULLP;
634    return (ret);
635 }  /* RgUiRguCStaRsp */
636
637 #ifdef LTE_L2_MEAS
638
639 /**
640  * @brief Handler for L2M MeasReq from RGU
641  *
642  * @details
643  *
644  *     Function :RgUiRguL2MUlThrpMeasReq 
645  *     
646  *     This function validates SAP and invokes ROM for further processing
647  *           
648  *  @param[in]  Pst             *pst 
649  *  @param[in]  SpId            spId 
650  *  @param[in]  RguL2MUlThrpMeasReqInfo  *measReq
651  *  @return  S16
652  *      -# ROK 
653  *      -# RFAILED 
654  **/
655 #ifdef ANSI
656 S16 RgUiRguL2MUlThrpMeasReq 
657 (
658 Pst             *pst,
659 SpId            spId,
660 RguL2MUlThrpMeasReqInfo  *measReq
661 )
662 #else
663 S16 RgUiRguL2MUlThrpMeasReq(pst, spId, measReq)
664 Pst             *pst;
665 SpId            spId;
666 RguL2MUlThrpMeasReqInfo  *measReq;
667 #endif
668 {
669    Inst  inst;
670
671    S16   ret = ROK;
672
673    RG_IS_INST_VALID(pst->dstInst);
674    inst = pst->dstInst - RG_INST_START;
675 #ifndef NO_ERRCLS
676    if (measReq == NULLP)
677    {
678       RLOG0(L_ERROR,"Input Response Buffer is NULL");
679       return RFAILED;
680    }
681
682    if (spId == rgCb[inst].rguSap[spId].sapCfg.spId)
683    {
684       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
685       {
686          case LRG_BND: /* SAP is bound */
687             RLOG0(L_DEBUG,"SAP is already bound");
688             break;
689          default: /* Should never reach here */
690 #if (ERRCLASS & ERRCLS_ADD_RES)      
691             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguL2MUlThrpMeasReq failed",
692                   rgCb[inst].rguSap[spId].sapSta.sapState);
693 #endif
694             return RFAILED;
695       }
696    }
697    else
698    {
699 #if (ERRCLASS & ERRCLS_ADD_RES)      
700       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiRguL2MUlThrpMeasReq failed",spId);
701 #endif
702       return RFAILED;
703    }
704 #endif
705
706    ret = rgROML2MUlThrpMeasReq(inst,measReq);
707    if (ret != ROK)
708    {
709       RLOG_ARG0(L_ERROR,DBG_CELLID,measReq->cellId,"Processing Of Meas Request Failed");
710    }
711
712   SPutStaticBuffer(pst->region, pst->pool, (Data *)measReq,sizeof(RguL2MUlThrpMeasReqInfo) , SS_SHARABLE_MEMORY);
713    measReq= NULLP;
714    return (ret);
715 }  /* RgUiRguL2MUlThrpMeasReq */
716 #endif
717
718 /**
719  * @brief Handler for sending staInd to dedicated logical channels of a UE 
720  *
721  * @details
722  *
723  *     Function : rgUIMSndDedStaInd
724  *     
725  *     This function fills SAP and Pst information to send the staInd to
726  *     a UE.
727  *     
728  *           
729  *  @param[in] Inst        inst
730  *  @param[in] RgUpSapCb  *rguSap 
731  *  @param[in]  RgRguDedStaInd  *staInd
732  *  @return  S16
733  *      -# ROK 
734  *      -# RFAILED 
735  **/
736 #ifdef ANSI
737 S16 rgUIMSndDedStaInd
738 (
739 Inst         inst,
740 RgUpSapCb    *rguSap,
741 RgRguDedStaInd  *staInd
742 )
743 #else
744 S16 rgUIMSndDedStaInd(inst,rguSap,staInd)
745 Inst         inst;
746 RgUpSapCb    *rguSap;
747 RgRguDedStaInd  *staInd;
748 #endif
749 {
750    S16  ret = ROK;
751    
752    RGDBGPRM(inst,(rgPBuf(inst),"rgUIMSndDedStaInd(): staInd = %p;\n", (void *)staInd));
753    
754    ret = RgUiRguDStaInd(&(rguSap->sapCfg.sapPst), rguSap->sapCfg.suId, 
755          staInd);
756    if (ret != ROK)
757    {
758       RLOG_ARG0(L_ERROR,DBG_CELLID,staInd->cellId,"RgUiRguDStaInd Failed");
759       return (ret);
760    }
761    return (ret);
762 }  /* rgUIMSndDedStaInd */
763
764
765 /**
766  * @brief Handler for sending staInd to a common logical channel.
767  *
768  * @details
769  *
770  *     Function : rgUIMSndCmnStaInd
771  *     
772  *     This function fills SAP and Pst information to send the staInd to
773  *     a common logical channel.
774  *     
775  *           
776  *  @param[in] Inst        inst
777  *  @param[in] RgUpSapCb  *rguSap 
778  *  @param[in]  RgRguCmnStaInd  *staInd
779  *  @return  S16
780  *      -# ROK 
781  *      -# RFAILED 
782  **/
783 #ifdef ANSI
784 S16 rgUIMSndCmnStaInd
785 (
786 Inst            inst,
787 RgUpSapCb    *rguDlSap,
788 RgRguCmnStaInd  *staInd
789 )
790 #else
791 S16 rgUIMSndCmnStaInd(inst,rguDlSap,staInd)
792 Inst          inst,
793 RgUpSapCb    *rguDlSap,
794 RgRguCmnStaInd  *staInd;
795 #endif
796 {
797    S16  ret = ROK;
798
799    ret = RgUiRguCStaInd(&(rguDlSap->sapCfg.sapPst), rguDlSap->sapCfg.suId, 
800          staInd);
801    if (ret != ROK)
802    {
803       RLOG_ARG0(L_ERROR,DBG_CELLID,staInd->cellId,"RgUiRguCStaInd Failed");
804       return (ret);
805    }
806    return (ret);
807 }  /* rgUIMSndCmnStaInd */
808
809
810 /**
811  * @brief Handler for sending datInd to dedicated logical channels of a UE 
812  *
813  * @details
814  *
815  *     Function : rgUIMSndDedDatInd
816  *     
817  *     This function fills SAP and Pst information to send the datInd to
818  *     a UE.
819  *     
820  *           
821  *  @param[in] Inst        inst
822  *  @param[in] RgUpSapCb  *rguUlSap 
823  *  @param[in]  RgRguDedDatInd  *datInd
824  *  @return  S16
825  *      -# ROK 
826  *      -# RFAILED 
827  **/
828 #ifdef ANSI
829 S16 rgUIMSndDedDatInd
830 (
831 Inst         inst,
832 RgUpSapCb    *rguUlSap,
833 RgRguDedDatInd  *datInd
834 )
835 #else
836 S16 rgUIMSndDedDatInd(datInd)
837 Inst         inst;
838 RgUpSapCb    *rguUlSap;
839 RgRguDedDatInd  *datInd;
840 #endif
841 {
842    S16  ret = ROK;
843
844    rguUlSap->sapSts.numPduTxmit += datInd->numLch;
845 #ifndef SS_RBUF
846    ret = RgUiRguDDatInd(&(rguUlSap->sapCfg.sapPst), rguUlSap->sapCfg.suId, 
847          datInd);
848    if (ret != ROK)
849    {
850       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"RgUiRguDdatInd Failed");
851       return (ret);
852    }
853 #else
854    SRngIncrWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
855    SsRngInfoTbl[SS_RNG_BUF_ULMAC_TO_ULRLC].pktRate++;
856 #endif
857    return (ret);
858 }  /* rgUIMSndDedDatInd */
859
860
861 /**
862  * @brief Handler for sending datInd to a common logical channel.
863  *
864  * @details
865  *
866  *     Function : rgUIMSndCmnDatInd
867  *     
868  *     This function fills SAP and Pst information to send the datInd to
869  *     a common logical channel.
870  *     
871  *           
872  *  @param[in] Inst        inst
873  *  @param[in] RgUpSapCb  *rguSap 
874  *  @param[in]  RgRguCmnDatInd  *datInd
875  *  @return  S16
876  *      -# ROK 
877  *      -# RFAILED 
878  **/
879 #ifdef ANSI
880 S16 rgUIMSndCmnDatInd
881 (
882 Inst         inst,
883 RgUpSapCb    *rguUlSap,
884 RgRguCmnDatInd  *datInd
885 )
886 #else
887 S16 rgUIMSndCmnDatInd(datInd)
888 Inst         inst;
889 RgUpSapCb    *rguUlSap;
890 RgRguCmnDatInd  *datInd;
891 #endif
892 {
893    S16  ret = ROK;
894
895    RGDBGPRM(inst,(rgPBuf(inst),"rgUIMSndCmnDatInd(): staInd = %p;\n", (void *)datInd));
896
897    rguUlSap->sapSts.numPduTxmit++;
898
899    RGDBGPRM(inst,(rgPBuf(inst),"rgUIMSndCmnDatInd suId = %d\n", rguUlSap->sapCfg.suId));   
900    ret = RgUiRguCDatInd(&(rguUlSap->sapCfg.sapPst), rguUlSap->sapCfg.suId, 
901          datInd);
902    if (ret != ROK)
903    {
904       RGDBGERRNEW(inst,(rgPBuf(inst),"RgUiRguCDatInd Failed\n"));
905       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"RgUiRguCDatInd Failed");
906       return (ret);
907    }
908    return (ret);
909 }  /* rgUIMSndCmnDatInd */
910
911 /**
912
913  * @brief API for bind request from RRC towards MAC. 
914  *
915  * @details
916  *
917  *     Function: RgUiCrgBndReq
918  *     
919  *     This API is invoked by RRC towards MAC to bind CRG SAP. 
920  *     These API validates the Pst, spId, suId and sends the bind confirm to RRC.
921  *
922  *           
923  *  @param[in]  Pst   *pst
924  *  @param[in]  SuId  suId
925  *  @param[in]  SpId  spId
926  *  @return  S16
927  *      -# ROK 
928  *      -# RFAILED 
929  **/
930 #ifdef ANSI
931 S16 RgUiCrgBndReq
932 (
933 Pst   *pst, 
934 SuId  suId,
935 SpId  spId
936 )
937 #else
938 S16 RgUiCrgBndReq(pst, suId, spId)
939 Pst   *pst; 
940 SuId  suId;
941 SpId  spId;
942 #endif
943 {
944    S16       ret = ROK;
945    Pst       tmpPst;   /* Temporary Post Structure */
946    RgUstaDgn dgn;      /* Alarm diagnostics structure */
947    Inst      inst;
948
949    RG_IS_INST_VALID(pst->dstInst);
950    inst = pst->dstInst - RG_INST_START;
951
952    tmpPst.prior       = pst->prior;
953    tmpPst.route       = pst->route;
954    tmpPst.selector    = pst->selector;
955    tmpPst.region      = rgCb[inst].rgInit.region;
956    tmpPst.pool        = rgCb[inst].rgInit.pool;
957    tmpPst.srcProcId   = rgCb[inst].rgInit.procId;
958    tmpPst.srcEnt      = rgCb[inst].rgInit.ent;
959    tmpPst.srcInst     = rgCb[inst].rgInit.inst;
960    tmpPst.event       = EVTNONE;
961    tmpPst.dstProcId   = pst->srcProcId;
962    tmpPst.dstEnt      = pst->srcEnt;
963    tmpPst.dstInst     = pst->srcInst;
964
965
966    if(spId == rgCb[inst].crgSap.sapCfg.spId)
967    {
968       /* Check the state of the SAP */
969       switch (rgCb[inst].crgSap.sapSta.sapState)
970       {
971          case LRG_NOT_CFG: /* SAP Not configured */
972             
973             rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM); 
974             ret = rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE,LRG_NOT_CFG,
975                   LCM_CAUSE_INV_SAP, &dgn);
976             RLOG0(L_DEBUG,"SAP Not Configured");
977             ret = RgUiCrgBndCfm(&tmpPst, suId, CM_BND_NOK);
978             break;
979          case LRG_UNBND: /* SAP is not bound */
980             RLOG0(L_DEBUG,"SAP Not yet bound");
981             
982             rgCb[inst].crgSap.sapSta.sapState = LRG_BND;
983             rgCb[inst].crgSap.sapCfg.suId = suId;
984             /* Send Bind Confirm with status as SUCCESS */
985             ret = rgUIMCrgBndCfm(inst,suId, CM_BND_OK);
986             /* Indicate to Layer manager */
987             rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM); 
988             ret = rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE,LRG_EVENT_CRGSAP_ENB,
989                   LCM_CAUSE_UNKNOWN, &dgn);
990             break;
991          case LRG_BND: /* SAP is already bound*/
992             RLOG0(L_DEBUG,"SAP is already bound");
993             
994             ret = rgUIMCrgBndCfm(inst,suId, CM_BND_OK);
995             break;
996          default: /* Should Never Enter here */
997 #if (ERRCLASS & ERRCLS_ADD_RES)      
998             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiCrgBndReq failed",
999                   rgCb[inst].crgSap.sapSta.sapState);
1000 #endif
1001             ret = rgUIMCrgBndCfm(inst,suId, CM_BND_NOK);
1002             break;
1003       }
1004    }
1005    else
1006    {
1007 #if (ERRCLASS & ERRCLS_ADD_RES)      
1008       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiCrgBndReq failed",
1009            rgCb[inst].crgSap.sapCfg.spId);
1010 #endif
1011       ret = rgUIMCrgBndCfm(inst,suId, CM_BND_NOK);
1012    }
1013    return (ret);
1014 }  /* RgUiCrgBndReq */
1015
1016
1017 /**
1018  * @brief API for unbind request from RRC towards MAC. 
1019  *
1020  * @details
1021  *
1022  *     Function: RgUiCrgUbndReq
1023  *     
1024  *     This API is invoked by RRC towards MAC to unbind CRG SAP. 
1025  *     These API validates the Pst, spId, suId and sends the bind confirm to RRC.
1026  *
1027  *           
1028  *  @param[in]  Pst    *pst
1029  *  @param[in]  SuId   suId
1030  *  @param[in]  Reason reason
1031  *  @return  S16
1032  *      -# ROK 
1033  *      -# RFAILED 
1034  **/
1035 #ifdef ANSI
1036 S16 RgUiCrgUbndReq
1037 (
1038 Pst    *pst,
1039 SpId   spId,
1040 Reason reason
1041 )
1042 #else
1043 S16 RgUiCrgUbndReq(pst, spId, reason)
1044 Pst    *pst; 
1045 SpId   spId;
1046 Reason reason;
1047 #endif
1048 {
1049    Inst      inst;
1050
1051    RG_IS_INST_VALID(pst->dstInst);
1052    inst = pst->dstInst - RG_INST_START;
1053    /* SAP Id validation */
1054    if (spId == rgCb[inst].crgSap.sapCfg.spId)
1055    {
1056       switch(rgCb[inst].crgSap.sapSta.sapState)
1057       {
1058          case LRG_BND: /* SAP is already bound*/
1059             /* setting SAP state to UN BOUND */
1060             RLOG0(L_DEBUG, "SAP is already bound");
1061             
1062             rgCb[inst].crgSap.sapSta.sapState = LRG_UNBND;
1063             break;
1064          default:
1065 #if (ERRCLASS & ERRCLS_ADD_RES)
1066             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiCrgUbndReq failed",
1067                   rgCb[inst].crgSap.sapSta.sapState);
1068 #endif
1069             return RFAILED;
1070       }
1071    }
1072    else
1073    {
1074 #if (ERRCLASS & ERRCLS_ADD_RES)      
1075       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiCrgUbndReq failed",
1076             rgCb[inst].crgSap.sapCfg.spId);
1077 #endif
1078       return RFAILED;
1079    }
1080    return ROK;
1081 }  /* RgUiCrgUbndReq */
1082
1083 /**
1084  * @brief API for sending bind confirm from MAC to RRC
1085  *
1086  * @details
1087  *
1088  *     Function: rgUIMRgrBndCfm
1089  *     
1090  *     This API is invoked to send bind confirm from MAC to RRC.
1091  *     This API fills in Pst structure and SAP Ids and invokes 
1092  *     bind confirm API towards RRC.
1093  *           
1094  *  @param[in] Inst        inst
1095  *  @param[in]  SuId          suId
1096  *  @param[in]  U8            status
1097  *  @return  S16
1098  *      -# ROK 
1099  *      -# RFAILED 
1100  **/
1101 #ifdef ANSI
1102 S16 rgUIMCrgBndCfm
1103 (
1104 Inst  inst,
1105 SuId suId,
1106 U8 status
1107 )
1108 #else
1109 S16 rgUIMCrgBndCfm(inst,suId, status)
1110 Inst          inst;
1111 SuId          suId;
1112 U8            status;
1113 #endif
1114 {
1115
1116    if(RgUiCrgBndCfm(&(rgCb[inst].crgSap.sapCfg.sapPst), rgCb[inst].crgSap.sapCfg.suId, status) != ROK)
1117    {
1118       RLOG0(L_ERROR,"RgUiCrgBndCfm Failed ");
1119       return RFAILED;
1120    }
1121
1122    return ROK;
1123 }  /* rgUIMCrgBndCfm*/
1124
1125 /**
1126  * @brief API for configuration request from RRC towards MAC. 
1127  *
1128  * @details
1129  *
1130  *     Function: RgUiCrgCfgReq
1131  *     
1132  *     This API is invoked by RRC towards MAC to configure MAC. 
1133  *     These API validates the Pst, spId, suId and transfers the config request 
1134  *     specific information to corresponding ownership module (COM) API.
1135  *
1136  *           
1137  *  @param[in]  Pst           *pst
1138  *  @param[in]  SpId          spId
1139  *  @param[in]  CrgCfgTransId transId
1140  *  @param[in]  CrgCfgReqInfo *cfgReqInfo
1141  *  @return  S16
1142  *      -# ROK 
1143  *      -# RFAILED 
1144  **/
1145 #ifdef ANSI
1146 S16 RgUiCrgCfgReq
1147 (
1148 Pst           *pst, 
1149 SpId          spId,
1150 CrgCfgTransId transId,
1151 CrgCfgReqInfo *cfgReqInfo
1152 )
1153 #else
1154 S16 RgUiCrgCfgReq(pst, spId, transId, cfgReqInfo)
1155 Pst           *pst; 
1156 SpId          spId;
1157 CrgCfgTransId transId;
1158 CrgCfgReqInfo *cfgReqInfo;
1159 #endif
1160 {
1161    Inst      inst;
1162    S16       ret       = ROK;
1163    U8        cfmStatus = 0x00ff;
1164    U8        prntTrans[CRG_CFG_TRANSID_SIZE+1];
1165
1166    RG_IS_INST_VALID(pst->dstInst);
1167    inst = pst->dstInst - RG_INST_START;
1168    /* Ensuring transId is always Null terminated. */
1169    memcpy(prntTrans, transId.trans, CRG_CFG_TRANSID_SIZE);
1170    prntTrans[CRG_CFG_TRANSID_SIZE] = '\0';
1171
1172
1173    /* CrgCfgReqInfo Validation for NULLP */
1174    if (cfgReqInfo == NULLP)
1175    {
1176       RLOG0(L_ERROR,"Input Param crgReqInfo is NULL ");
1177       rgUIMCrgCfgCfm(inst,transId, cfmStatus); 
1178       return RFAILED;
1179    }
1180
1181    /* Upper SAP Id and State validation */
1182    if (spId == rgCb[inst].crgSap.sapCfg.spId)
1183    {
1184       switch(rgCb[inst].crgSap.sapSta.sapState)
1185       {
1186          case LRG_BND: /* SAP is already bound */
1187             RLOG0(L_DEBUG,"SAP is already bound");
1188             break;
1189          default: /* Should never reach here */
1190 #if (ERRCLASS & ERRCLS_ADD_RES)      
1191             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiCrgCfgReq failed",
1192                   rgCb[inst].crgSap.sapSta.sapState);
1193 #endif
1194          SPutSBuf (pst->region, pst->pool, (Data *)cfgReqInfo,
1195                sizeof(CrgCfgReqInfo));
1196          cfgReqInfo = NULLP;
1197
1198             rgUIMCrgCfgCfm(inst,transId, cfmStatus);
1199             return RFAILED;
1200       }
1201    }
1202    else
1203    {
1204 #if (ERRCLASS & ERRCLS_ADD_RES)      
1205       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiCrgCfgReq failed",
1206             rgCb[inst].crgSap.sapCfg.spId);
1207 #endif
1208       SPutSBuf (pst->region, pst->pool, (Data *)cfgReqInfo,
1209             sizeof(CrgCfgReqInfo));
1210       cfgReqInfo = NULLP;
1211       rgUIMCrgCfgCfm(inst,transId, cfmStatus); 
1212       return RFAILED;
1213    }
1214    ret = rgCOMCfgReq(inst,transId, cfgReqInfo);
1215    SPutSBuf (pst->region, pst->pool, (Data *)cfgReqInfo,
1216          sizeof(CrgCfgReqInfo));
1217    cfgReqInfo = NULLP;
1218    if (ret != ROK)
1219    {
1220       RLOG0(L_ERROR,"Configuration Request Handling Failed ");
1221       return RFAILED;
1222    }
1223
1224    return ROK;
1225 }  /* RgUiCrgCfgReq */
1226
1227 /**
1228  * @brief API for sending configuration confirm from MAC to RRC
1229  *
1230  * @details
1231  *
1232  *     Function: rgUIMCrgCfgCfm
1233  *     
1234  *     This API is invoked to send configuration confirm from MAC to RRC.
1235  *     This API fills in Pst structure and SAP Ids and invokes 
1236  *     config confirm API towards RRC.
1237  *           
1238  *  @param[in] Inst        inst
1239  *  @param[in]  CrgCfgTransId transId
1240  *  @param[in]  U8            status
1241  *  @return  S16
1242  *      -# ROK 
1243  *      -# RFAILED 
1244  **/
1245 #ifdef ANSI
1246 S16 rgUIMCrgCfgCfm
1247 (
1248 Inst      inst,
1249 CrgCfgTransId transId,
1250 U8            status
1251 )
1252 #else
1253 S16 rgUIMCrgCfgCfm(inst,transId, status)
1254 Inst      inst;
1255 CrgCfgTransId transId;
1256 U8            status;
1257 #endif
1258 {
1259    S16  ret = ROK;
1260    U8   prntTrans[CRG_CFG_TRANSID_SIZE+1];
1261
1262    memcpy(prntTrans, transId.trans, CRG_CFG_TRANSID_SIZE);
1263    prntTrans[CRG_CFG_TRANSID_SIZE] = '\0';
1264
1265
1266    ret = RgUiCrgCfgCfm(&(rgCb[inst].crgSap.sapCfg.sapPst), rgCb[inst].crgSap.sapCfg.suId, transId, status);
1267    if (ret != ROK)
1268    {
1269       RLOG0(L_ERROR,"RgUiCrgCfgCfm Failed ");
1270       return (ret);
1271    }
1272
1273    return (ret);
1274 }  /* rgUIMCrgCfgCfm */
1275 #if defined(SPLIT_RLC_DL_TASK) && defined(RLC_MAC_STA_RSP_RBUF)
1276
1277 #ifdef ANSI
1278 S16 rgBatchProc
1279 (
1280 Void
1281 )
1282 #else
1283 S16 rgBatchProc()
1284 Void;
1285 #endif
1286 {
1287 /* Read from Ring Buffer and process RLC BO Update */
1288    Pst pst = {0};
1289    SpId spId = 0;
1290    RguDStaRspInfo  *staRsp;
1291    U32 elmIndx = 0;
1292 #ifndef LTE_ADV
1293 /* Fill pst */
1294    pst.srcProcId = 1;
1295    pst.dstProcId = 1;
1296    pst.dstEnt = ENTMAC;
1297    pst.dstInst = 0;
1298    pst.srcEnt = ENTRLC;
1299    pst.srcInst = 1;
1300    pst.prior = PRIOR0;
1301    pst.route = RTESPEC;
1302    pst.event = EVTRGUDSTARSP;
1303    pst.region = 0;
1304    pst.pool = 0;
1305    pst.selector = 2; /*SM_SELECTOR_LC */
1306 #else
1307 #endif
1308   
1309    elmIndx = (U32)SRngGetRIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
1310    while(NULLP != elmIndx)
1311    {
1312       staRsp = (RguDStaRspInfo *)elmIndx;
1313 #ifdef LTE_ADV
1314       pst = staRsp->post;
1315 #endif
1316       RgUiRguDStaRsp(&pst, spId, staRsp);
1317
1318       elmIndx = NULLP;
1319       staRsp = NULLP;
1320       SRngIncrRIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
1321
1322       if((elmIndx = (U32)SRngGetRIndx(SS_RNG_BUF_DLRLC_TO_DLMAC)) == NULLP)
1323       break;
1324    }
1325    return ROK;
1326 }
1327 #endif
1328
1329 /**********************************************************************
1330  
1331          End of file
1332 **********************************************************************/