U8, U16, U32 data type changes
[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 uint8_t rgRguDlSap;
80 uint8_t 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]  uint8_t            status
264  *  @return  S16
265  *      -# ROK 
266  *      -# RFAILED 
267  **/
268 #ifdef ANSI
269 S16 rgUIMRguBndCfm
270 (
271 Inst inst,
272 SpId spId,
273 uint8_t status
274 )
275 #else
276 S16 rgUIMRguBndCfm(inst,spId, status)
277 Inst          inst;
278 SpId          spId;
279 uint8_t       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    uint32_t   id;
330    uint32_t   id1;
331    uint32_t   id2;
332    uint32_t   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    S16   ret       = ROK;
535    VOLATILE uint32_t     startTime = 0;
536
537    RG_IS_INST_VALID(pst->dstInst);
538    inst = pst->dstInst - RG_INST_START;
539    /*starting Task*/
540    SStartTask(&startTime, PID_MAC_STA_RSP);
541
542    ret = rgROMDedStaRsp(inst,staRsp);
543    if (ret != ROK)
544    {
545       RLOG_ARG0(L_ERROR,DBG_CELLID,staRsp->cellId,
546                 "Processing Of Status Response Failed");
547    }
548
549
550    /*stoping Task*/
551    SStopTask(startTime, PID_MAC_STA_RSP);
552    return (ret);
553 }  /* RgUiRguDStaRsp */
554
555
556 /**
557  * @brief Handler for common StaRsp from RGU
558  *
559  * @details
560  *
561  *     Function : RgUiRguCStaRsp
562  *     
563  *     This function validates SAP and invokes ROM 
564  *     for further processing
565  *     
566  *           
567  *  @param[in]  Pst             *pst 
568  *  @param[in]  SpId            spId 
569  *  @param[in]  RguCStaRspInfo  *staRsp
570  *  @return  S16
571  *      -# ROK 
572  *      -# RFAILED 
573  **/
574 #ifdef ANSI
575 S16 RgUiRguCStaRsp
576 (
577 Pst             *pst,
578 SpId            spId,
579 RguCStaRspInfo  *staRsp
580 )
581 #else
582 S16 RgUiRguCStaRsp(pst, spId, staRsp)
583 Pst             *pst;
584 SpId            spId;
585 RguCStaRspInfo  *staRsp;
586 #endif
587 {
588    Inst  inst;
589    S16   ret = ROK;
590
591    RG_IS_INST_VALID(pst->dstInst);
592    inst = pst->dstInst - RG_INST_START;
593 #ifndef NO_ERRCLS
594    if (staRsp == NULLP)
595    {
596       RLOG0(L_ERROR,"Input Response Buffer is NULL");
597       return RFAILED;
598    }
599
600    if (spId == rgCb[inst].rguSap[spId].sapCfg.spId)
601    {
602       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
603       {
604          case LRG_BND: /* SAP is bound */
605             RLOG0(L_DEBUG,"SAP is already bound");
606             break;
607          default: /* Should never reach here */
608 #if (ERRCLASS & ERRCLS_ADD_RES)      
609             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguCStaRsp failed",
610                   rgCb[inst].rguSap[spId].sapSta.sapState);
611 #endif
612             return RFAILED;
613       }
614    }
615    else
616    {
617 #if (ERRCLASS & ERRCLS_ADD_RES)      
618       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiRguCStaRsp failed",spId);
619 #endif
620       return RFAILED;
621    }
622 #endif
623
624    ret = rgROMCmnStaRsp(inst,staRsp);
625    if (ret != ROK)
626    {
627       RLOG_ARG0(L_ERROR,DBG_CELLID,staRsp->cellId,"Processing Of Status Response Failed");
628       return (ret);
629    }
630
631    ret = SPutStaticBuffer(pst->region, pst->pool, (Data *)staRsp,sizeof(RguCStaRspInfo) , SS_SHARABLE_MEMORY);
632    staRsp = NULLP;
633    return (ret);
634 }  /* RgUiRguCStaRsp */
635
636 #ifdef LTE_L2_MEAS
637
638 /**
639  * @brief Handler for L2M MeasReq from RGU
640  *
641  * @details
642  *
643  *     Function :RgUiRguL2MUlThrpMeasReq 
644  *     
645  *     This function validates SAP and invokes ROM for further processing
646  *           
647  *  @param[in]  Pst             *pst 
648  *  @param[in]  SpId            spId 
649  *  @param[in]  RguL2MUlThrpMeasReqInfo  *measReq
650  *  @return  S16
651  *      -# ROK 
652  *      -# RFAILED 
653  **/
654 #ifdef ANSI
655 S16 RgUiRguL2MUlThrpMeasReq 
656 (
657 Pst             *pst,
658 SpId            spId,
659 RguL2MUlThrpMeasReqInfo  *measReq
660 )
661 #else
662 S16 RgUiRguL2MUlThrpMeasReq(pst, spId, measReq)
663 Pst             *pst;
664 SpId            spId;
665 RguL2MUlThrpMeasReqInfo  *measReq;
666 #endif
667 {
668    Inst  inst;
669
670    S16   ret = ROK;
671
672    RG_IS_INST_VALID(pst->dstInst);
673    inst = pst->dstInst - RG_INST_START;
674 #ifndef NO_ERRCLS
675    if (measReq == NULLP)
676    {
677       RLOG0(L_ERROR,"Input Response Buffer is NULL");
678       return RFAILED;
679    }
680
681    if (spId == rgCb[inst].rguSap[spId].sapCfg.spId)
682    {
683       switch (rgCb[inst].rguSap[spId].sapSta.sapState)
684       {
685          case LRG_BND: /* SAP is bound */
686             RLOG0(L_DEBUG,"SAP is already bound");
687             break;
688          default: /* Should never reach here */
689 #if (ERRCLASS & ERRCLS_ADD_RES)      
690             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiRguL2MUlThrpMeasReq failed",
691                   rgCb[inst].rguSap[spId].sapSta.sapState);
692 #endif
693             return RFAILED;
694       }
695    }
696    else
697    {
698 #if (ERRCLASS & ERRCLS_ADD_RES)      
699       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiRguL2MUlThrpMeasReq failed",spId);
700 #endif
701       return RFAILED;
702    }
703 #endif
704
705    ret = rgROML2MUlThrpMeasReq(inst,measReq);
706    if (ret != ROK)
707    {
708       RLOG_ARG0(L_ERROR,DBG_CELLID,measReq->cellId,"Processing Of Meas Request Failed");
709    }
710
711   SPutStaticBuffer(pst->region, pst->pool, (Data *)measReq,sizeof(RguL2MUlThrpMeasReqInfo) , SS_SHARABLE_MEMORY);
712    measReq= NULLP;
713    return (ret);
714 }  /* RgUiRguL2MUlThrpMeasReq */
715 #endif
716
717 /**
718  * @brief Handler for sending staInd to dedicated logical channels of a UE 
719  *
720  * @details
721  *
722  *     Function : rgUIMSndDedStaInd
723  *     
724  *     This function fills SAP and Pst information to send the staInd to
725  *     a UE.
726  *     
727  *           
728  *  @param[in] Inst        inst
729  *  @param[in] RgUpSapCb  *rguSap 
730  *  @param[in]  RgRguDedStaInd  *staInd
731  *  @return  S16
732  *      -# ROK 
733  *      -# RFAILED 
734  **/
735 #ifdef ANSI
736 S16 rgUIMSndDedStaInd
737 (
738 Inst         inst,
739 RgUpSapCb    *rguSap,
740 RgRguDedStaInd  *staInd
741 )
742 #else
743 S16 rgUIMSndDedStaInd(inst,rguSap,staInd)
744 Inst         inst;
745 RgUpSapCb    *rguSap;
746 RgRguDedStaInd  *staInd;
747 #endif
748 {
749    S16  ret = ROK;
750    
751    RGDBGPRM(inst,(rgPBuf(inst),"rgUIMSndDedStaInd(): staInd = %p;\n", (void *)staInd));
752    
753    ret = RgUiRguDStaInd(&(rguSap->sapCfg.sapPst), rguSap->sapCfg.suId, 
754          staInd);
755    if (ret != ROK)
756    {
757       RLOG_ARG0(L_ERROR,DBG_CELLID,staInd->cellId,"RgUiRguDStaInd Failed");
758       return (ret);
759    }
760    return (ret);
761 }  /* rgUIMSndDedStaInd */
762
763
764 /**
765  * @brief Handler for sending staInd to a common logical channel.
766  *
767  * @details
768  *
769  *     Function : rgUIMSndCmnStaInd
770  *     
771  *     This function fills SAP and Pst information to send the staInd to
772  *     a common logical channel.
773  *     
774  *           
775  *  @param[in] Inst        inst
776  *  @param[in] RgUpSapCb  *rguSap 
777  *  @param[in]  RgRguCmnStaInd  *staInd
778  *  @return  S16
779  *      -# ROK 
780  *      -# RFAILED 
781  **/
782 #ifdef ANSI
783 S16 rgUIMSndCmnStaInd
784 (
785 Inst            inst,
786 RgUpSapCb    *rguDlSap,
787 RgRguCmnStaInd  *staInd
788 )
789 #else
790 S16 rgUIMSndCmnStaInd(inst,rguDlSap,staInd)
791 Inst          inst,
792 RgUpSapCb    *rguDlSap,
793 RgRguCmnStaInd  *staInd;
794 #endif
795 {
796    S16  ret = ROK;
797
798    ret = RgUiRguCStaInd(&(rguDlSap->sapCfg.sapPst), rguDlSap->sapCfg.suId, 
799          staInd);
800    if (ret != ROK)
801    {
802       RLOG_ARG0(L_ERROR,DBG_CELLID,staInd->cellId,"RgUiRguCStaInd Failed");
803       return (ret);
804    }
805    return (ret);
806 }  /* rgUIMSndCmnStaInd */
807
808
809 /**
810  * @brief Handler for sending datInd to dedicated logical channels of a UE 
811  *
812  * @details
813  *
814  *     Function : rgUIMSndDedDatInd
815  *     
816  *     This function fills SAP and Pst information to send the datInd to
817  *     a UE.
818  *     
819  *           
820  *  @param[in] Inst        inst
821  *  @param[in] RgUpSapCb  *rguUlSap 
822  *  @param[in]  RgRguDedDatInd  *datInd
823  *  @return  S16
824  *      -# ROK 
825  *      -# RFAILED 
826  **/
827 #ifdef ANSI
828 S16 rgUIMSndDedDatInd
829 (
830 Inst         inst,
831 RgUpSapCb    *rguUlSap,
832 RgRguDedDatInd  *datInd
833 )
834 #else
835 S16 rgUIMSndDedDatInd(datInd)
836 Inst         inst;
837 RgUpSapCb    *rguUlSap;
838 RgRguDedDatInd  *datInd;
839 #endif
840 {
841    S16  ret = ROK;
842
843    rguUlSap->sapSts.numPduTxmit += datInd->numLch;
844 #ifndef SS_RBUF
845    ret = RgUiRguDDatInd(&(rguUlSap->sapCfg.sapPst), rguUlSap->sapCfg.suId, 
846          datInd);
847    if (ret != ROK)
848    {
849       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"RgUiRguDdatInd Failed");
850       return (ret);
851    }
852 #else
853    SRngIncrWIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
854    SsRngInfoTbl[SS_RNG_BUF_ULMAC_TO_ULRLC].pktRate++;
855 #endif
856    return (ret);
857 }  /* rgUIMSndDedDatInd */
858
859
860 /**
861  * @brief Handler for sending datInd to a common logical channel.
862  *
863  * @details
864  *
865  *     Function : rgUIMSndCmnDatInd
866  *     
867  *     This function fills SAP and Pst information to send the datInd to
868  *     a common logical channel.
869  *     
870  *           
871  *  @param[in] Inst        inst
872  *  @param[in] RgUpSapCb  *rguSap 
873  *  @param[in]  RgRguCmnDatInd  *datInd
874  *  @return  S16
875  *      -# ROK 
876  *      -# RFAILED 
877  **/
878 #ifdef ANSI
879 S16 rgUIMSndCmnDatInd
880 (
881 Inst         inst,
882 RgUpSapCb    *rguUlSap,
883 RgRguCmnDatInd  *datInd
884 )
885 #else
886 S16 rgUIMSndCmnDatInd(datInd)
887 Inst         inst;
888 RgUpSapCb    *rguUlSap;
889 RgRguCmnDatInd  *datInd;
890 #endif
891 {
892    S16  ret = ROK;
893
894    RGDBGPRM(inst,(rgPBuf(inst),"rgUIMSndCmnDatInd(): staInd = %p;\n", (void *)datInd));
895
896    rguUlSap->sapSts.numPduTxmit++;
897
898    RGDBGPRM(inst,(rgPBuf(inst),"rgUIMSndCmnDatInd suId = %d\n", rguUlSap->sapCfg.suId));   
899    ret = RgUiRguCDatInd(&(rguUlSap->sapCfg.sapPst), rguUlSap->sapCfg.suId, 
900          datInd);
901    if (ret != ROK)
902    {
903       RGDBGERRNEW(inst,(rgPBuf(inst),"RgUiRguCDatInd Failed\n"));
904       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"RgUiRguCDatInd Failed");
905       return (ret);
906    }
907    return (ret);
908 }  /* rgUIMSndCmnDatInd */
909
910 /**
911
912  * @brief API for bind request from RRC towards MAC. 
913  *
914  * @details
915  *
916  *     Function: RgUiCrgBndReq
917  *     
918  *     This API is invoked by RRC towards MAC to bind CRG SAP. 
919  *     These API validates the Pst, spId, suId and sends the bind confirm to RRC.
920  *
921  *           
922  *  @param[in]  Pst   *pst
923  *  @param[in]  SuId  suId
924  *  @param[in]  SpId  spId
925  *  @return  S16
926  *      -# ROK 
927  *      -# RFAILED 
928  **/
929 #ifdef ANSI
930 S16 RgUiCrgBndReq
931 (
932 Pst   *pst, 
933 SuId  suId,
934 SpId  spId
935 )
936 #else
937 S16 RgUiCrgBndReq(pst, suId, spId)
938 Pst   *pst; 
939 SuId  suId;
940 SpId  spId;
941 #endif
942 {
943    S16       ret = ROK;
944    Pst       tmpPst;   /* Temporary Post Structure */
945    RgUstaDgn dgn;      /* Alarm diagnostics structure */
946    Inst      inst;
947
948    RG_IS_INST_VALID(pst->dstInst);
949    inst = pst->dstInst - RG_INST_START;
950
951    tmpPst.prior       = pst->prior;
952    tmpPst.route       = pst->route;
953    tmpPst.selector    = pst->selector;
954    tmpPst.region      = rgCb[inst].rgInit.region;
955    tmpPst.pool        = rgCb[inst].rgInit.pool;
956    tmpPst.srcProcId   = rgCb[inst].rgInit.procId;
957    tmpPst.srcEnt      = rgCb[inst].rgInit.ent;
958    tmpPst.srcInst     = rgCb[inst].rgInit.inst;
959    tmpPst.event       = EVTNONE;
960    tmpPst.dstProcId   = pst->srcProcId;
961    tmpPst.dstEnt      = pst->srcEnt;
962    tmpPst.dstInst     = pst->srcInst;
963
964
965    if(spId == rgCb[inst].crgSap.sapCfg.spId)
966    {
967       /* Check the state of the SAP */
968       switch (rgCb[inst].crgSap.sapSta.sapState)
969       {
970          case LRG_NOT_CFG: /* SAP Not configured */
971             
972             rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM); 
973             ret = rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE,LRG_NOT_CFG,
974                   LCM_CAUSE_INV_SAP, &dgn);
975             RLOG0(L_DEBUG,"SAP Not Configured");
976             ret = RgUiCrgBndCfm(&tmpPst, suId, CM_BND_NOK);
977             break;
978          case LRG_UNBND: /* SAP is not bound */
979             RLOG0(L_DEBUG,"SAP Not yet bound");
980             
981             rgCb[inst].crgSap.sapSta.sapState = LRG_BND;
982             rgCb[inst].crgSap.sapCfg.suId = suId;
983             /* Send Bind Confirm with status as SUCCESS */
984             ret = rgUIMCrgBndCfm(inst,suId, CM_BND_OK);
985             /* Indicate to Layer manager */
986             rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM); 
987             ret = rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE,LRG_EVENT_CRGSAP_ENB,
988                   LCM_CAUSE_UNKNOWN, &dgn);
989             break;
990          case LRG_BND: /* SAP is already bound*/
991             RLOG0(L_DEBUG,"SAP is already bound");
992             
993             ret = rgUIMCrgBndCfm(inst,suId, CM_BND_OK);
994             break;
995          default: /* Should Never Enter here */
996 #if (ERRCLASS & ERRCLS_ADD_RES)      
997             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiCrgBndReq failed",
998                   rgCb[inst].crgSap.sapSta.sapState);
999 #endif
1000             ret = rgUIMCrgBndCfm(inst,suId, CM_BND_NOK);
1001             break;
1002       }
1003    }
1004    else
1005    {
1006 #if (ERRCLASS & ERRCLS_ADD_RES)      
1007       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiCrgBndReq failed",
1008            rgCb[inst].crgSap.sapCfg.spId);
1009 #endif
1010       ret = rgUIMCrgBndCfm(inst,suId, CM_BND_NOK);
1011    }
1012    return (ret);
1013 }  /* RgUiCrgBndReq */
1014
1015
1016 /**
1017  * @brief API for unbind request from RRC towards MAC. 
1018  *
1019  * @details
1020  *
1021  *     Function: RgUiCrgUbndReq
1022  *     
1023  *     This API is invoked by RRC towards MAC to unbind CRG SAP. 
1024  *     These API validates the Pst, spId, suId and sends the bind confirm to RRC.
1025  *
1026  *           
1027  *  @param[in]  Pst    *pst
1028  *  @param[in]  SuId   suId
1029  *  @param[in]  Reason reason
1030  *  @return  S16
1031  *      -# ROK 
1032  *      -# RFAILED 
1033  **/
1034 #ifdef ANSI
1035 S16 RgUiCrgUbndReq
1036 (
1037 Pst    *pst,
1038 SpId   spId,
1039 Reason reason
1040 )
1041 #else
1042 S16 RgUiCrgUbndReq(pst, spId, reason)
1043 Pst    *pst; 
1044 SpId   spId;
1045 Reason reason;
1046 #endif
1047 {
1048    Inst      inst;
1049
1050    RG_IS_INST_VALID(pst->dstInst);
1051    inst = pst->dstInst - RG_INST_START;
1052    /* SAP Id validation */
1053    if (spId == rgCb[inst].crgSap.sapCfg.spId)
1054    {
1055       switch(rgCb[inst].crgSap.sapSta.sapState)
1056       {
1057          case LRG_BND: /* SAP is already bound*/
1058             /* setting SAP state to UN BOUND */
1059             RLOG0(L_DEBUG, "SAP is already bound");
1060             
1061             rgCb[inst].crgSap.sapSta.sapState = LRG_UNBND;
1062             break;
1063          default:
1064 #if (ERRCLASS & ERRCLS_ADD_RES)
1065             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiCrgUbndReq failed",
1066                   rgCb[inst].crgSap.sapSta.sapState);
1067 #endif
1068             return RFAILED;
1069       }
1070    }
1071    else
1072    {
1073 #if (ERRCLASS & ERRCLS_ADD_RES)      
1074       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiCrgUbndReq failed",
1075             rgCb[inst].crgSap.sapCfg.spId);
1076 #endif
1077       return RFAILED;
1078    }
1079    return ROK;
1080 }  /* RgUiCrgUbndReq */
1081
1082 /**
1083  * @brief API for sending bind confirm from MAC to RRC
1084  *
1085  * @details
1086  *
1087  *     Function: rgUIMRgrBndCfm
1088  *     
1089  *     This API is invoked to send bind confirm from MAC to RRC.
1090  *     This API fills in Pst structure and SAP Ids and invokes 
1091  *     bind confirm API towards RRC.
1092  *           
1093  *  @param[in] Inst        inst
1094  *  @param[in]  SuId          suId
1095  *  @param[in]  uint8_t            status
1096  *  @return  S16
1097  *      -# ROK 
1098  *      -# RFAILED 
1099  **/
1100 #ifdef ANSI
1101 S16 rgUIMCrgBndCfm
1102 (
1103 Inst  inst,
1104 SuId suId,
1105 uint8_t status
1106 )
1107 #else
1108 S16 rgUIMCrgBndCfm(inst,suId, status)
1109 Inst          inst;
1110 SuId          suId;
1111 uint8_t       status;
1112 #endif
1113 {
1114
1115    if(RgUiCrgBndCfm(&(rgCb[inst].crgSap.sapCfg.sapPst), rgCb[inst].crgSap.sapCfg.suId, status) != ROK)
1116    {
1117       RLOG0(L_ERROR,"RgUiCrgBndCfm Failed ");
1118       return RFAILED;
1119    }
1120
1121    return ROK;
1122 }  /* rgUIMCrgBndCfm*/
1123
1124 /**
1125  * @brief API for configuration request from RRC towards MAC. 
1126  *
1127  * @details
1128  *
1129  *     Function: RgUiCrgCfgReq
1130  *     
1131  *     This API is invoked by RRC towards MAC to configure MAC. 
1132  *     These API validates the Pst, spId, suId and transfers the config request 
1133  *     specific information to corresponding ownership module (COM) API.
1134  *
1135  *           
1136  *  @param[in]  Pst           *pst
1137  *  @param[in]  SpId          spId
1138  *  @param[in]  CrgCfgTransId transId
1139  *  @param[in]  CrgCfgReqInfo *cfgReqInfo
1140  *  @return  S16
1141  *      -# ROK 
1142  *      -# RFAILED 
1143  **/
1144 #ifdef ANSI
1145 S16 RgUiCrgCfgReq
1146 (
1147 Pst           *pst, 
1148 SpId          spId,
1149 CrgCfgTransId transId,
1150 CrgCfgReqInfo *cfgReqInfo
1151 )
1152 #else
1153 S16 RgUiCrgCfgReq(pst, spId, transId, cfgReqInfo)
1154 Pst           *pst; 
1155 SpId          spId;
1156 CrgCfgTransId transId;
1157 CrgCfgReqInfo *cfgReqInfo;
1158 #endif
1159 {
1160    Inst      inst;
1161    S16       ret       = ROK;
1162    uint8_t   cfmStatus = 0x00ff;
1163    uint8_t   prntTrans[CRG_CFG_TRANSID_SIZE+1];
1164
1165    RG_IS_INST_VALID(pst->dstInst);
1166    inst = pst->dstInst - RG_INST_START;
1167    /* Ensuring transId is always Null terminated. */
1168    memcpy(prntTrans, transId.trans, CRG_CFG_TRANSID_SIZE);
1169    prntTrans[CRG_CFG_TRANSID_SIZE] = '\0';
1170
1171
1172    /* CrgCfgReqInfo Validation for NULLP */
1173    if (cfgReqInfo == NULLP)
1174    {
1175       RLOG0(L_ERROR,"Input Param crgReqInfo is NULL ");
1176       rgUIMCrgCfgCfm(inst,transId, cfmStatus); 
1177       return RFAILED;
1178    }
1179
1180    /* Upper SAP Id and State validation */
1181    if (spId == rgCb[inst].crgSap.sapCfg.spId)
1182    {
1183       switch(rgCb[inst].crgSap.sapSta.sapState)
1184       {
1185          case LRG_BND: /* SAP is already bound */
1186             RLOG0(L_DEBUG,"SAP is already bound");
1187             break;
1188          default: /* Should never reach here */
1189 #if (ERRCLASS & ERRCLS_ADD_RES)      
1190             RLOG1(L_ERROR,"Invalid SAP State:%d RgUiCrgCfgReq failed",
1191                   rgCb[inst].crgSap.sapSta.sapState);
1192 #endif
1193          SPutSBuf (pst->region, pst->pool, (Data *)cfgReqInfo,
1194                sizeof(CrgCfgReqInfo));
1195          cfgReqInfo = NULLP;
1196
1197             rgUIMCrgCfgCfm(inst,transId, cfmStatus);
1198             return RFAILED;
1199       }
1200    }
1201    else
1202    {
1203 #if (ERRCLASS & ERRCLS_ADD_RES)      
1204       RLOG1(L_ERROR,"Invalid SAP Id:%d RgUiCrgCfgReq failed",
1205             rgCb[inst].crgSap.sapCfg.spId);
1206 #endif
1207       SPutSBuf (pst->region, pst->pool, (Data *)cfgReqInfo,
1208             sizeof(CrgCfgReqInfo));
1209       cfgReqInfo = NULLP;
1210       rgUIMCrgCfgCfm(inst,transId, cfmStatus); 
1211       return RFAILED;
1212    }
1213    ret = rgCOMCfgReq(inst,transId, cfgReqInfo);
1214    SPutSBuf (pst->region, pst->pool, (Data *)cfgReqInfo,
1215          sizeof(CrgCfgReqInfo));
1216    cfgReqInfo = NULLP;
1217    if (ret != ROK)
1218    {
1219       RLOG0(L_ERROR,"Configuration Request Handling Failed ");
1220       return RFAILED;
1221    }
1222
1223    return ROK;
1224 }  /* RgUiCrgCfgReq */
1225
1226 /**
1227  * @brief API for sending configuration confirm from MAC to RRC
1228  *
1229  * @details
1230  *
1231  *     Function: rgUIMCrgCfgCfm
1232  *     
1233  *     This API is invoked to send configuration confirm from MAC to RRC.
1234  *     This API fills in Pst structure and SAP Ids and invokes 
1235  *     config confirm API towards RRC.
1236  *           
1237  *  @param[in] Inst        inst
1238  *  @param[in]  CrgCfgTransId transId
1239  *  @param[in]  uint8_t            status
1240  *  @return  S16
1241  *      -# ROK 
1242  *      -# RFAILED 
1243  **/
1244 #ifdef ANSI
1245 S16 rgUIMCrgCfgCfm
1246 (
1247 Inst      inst,
1248 CrgCfgTransId transId,
1249 uint8_t       status
1250 )
1251 #else
1252 S16 rgUIMCrgCfgCfm(inst,transId, status)
1253 Inst      inst;
1254 CrgCfgTransId transId;
1255 uint8_t       status;
1256 #endif
1257 {
1258    S16  ret = ROK;
1259    uint8_t   prntTrans[CRG_CFG_TRANSID_SIZE+1];
1260
1261    memcpy(prntTrans, transId.trans, CRG_CFG_TRANSID_SIZE);
1262    prntTrans[CRG_CFG_TRANSID_SIZE] = '\0';
1263
1264
1265    ret = RgUiCrgCfgCfm(&(rgCb[inst].crgSap.sapCfg.sapPst), rgCb[inst].crgSap.sapCfg.suId, transId, status);
1266    if (ret != ROK)
1267    {
1268       RLOG0(L_ERROR,"RgUiCrgCfgCfm Failed ");
1269       return (ret);
1270    }
1271
1272    return (ret);
1273 }  /* rgUIMCrgCfgCfm */
1274 #if defined(SPLIT_RLC_DL_TASK) && defined(RLC_MAC_STA_RSP_RBUF)
1275
1276 #ifdef ANSI
1277 S16 rgBatchProc
1278 (
1279 Void
1280 )
1281 #else
1282 S16 rgBatchProc()
1283 Void;
1284 #endif
1285 {
1286 /* Read from Ring Buffer and process RLC BO Update */
1287    Pst pst = {0};
1288    SpId spId = 0;
1289    RguDStaRspInfo  *staRsp;
1290    uint32_t elmIndx = 0;
1291 #ifndef LTE_ADV
1292 /* Fill pst */
1293    pst.srcProcId = 1;
1294    pst.dstProcId = 1;
1295    pst.dstEnt = ENTMAC;
1296    pst.dstInst = 0;
1297    pst.srcEnt = ENTRLC;
1298    pst.srcInst = 1;
1299    pst.prior = PRIOR0;
1300    pst.route = RTESPEC;
1301    pst.event = EVTRGUDSTARSP;
1302    pst.region = 0;
1303    pst.pool = 0;
1304    pst.selector = 2; /*SM_SELECTOR_LC */
1305 #else
1306 #endif
1307   
1308    elmIndx = (uint32_t)SRngGetRIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
1309    while(NULLP != elmIndx)
1310    {
1311       staRsp = (RguDStaRspInfo *)elmIndx;
1312 #ifdef LTE_ADV
1313       pst = staRsp->post;
1314 #endif
1315       RgUiRguDStaRsp(&pst, spId, staRsp);
1316
1317       elmIndx = NULLP;
1318       staRsp = NULLP;
1319       SRngIncrRIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
1320
1321       if((elmIndx = (uint32_t)SRngGetRIndx(SS_RNG_BUF_DLRLC_TO_DLMAC)) == NULLP)
1322       break;
1323    }
1324    return ROK;
1325 }
1326 #endif
1327
1328 /**********************************************************************
1329  
1330          End of file
1331 **********************************************************************/