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