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