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