Memory handling fixes
[o-du/l2.git] / src / 5gnrrlc / rlc_layer_mgr.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:    NR RLC - Layer Manager file
22
23         Type:    C source file
24
25         Desc:    It contains the following common  functions for processing
26                  the all the external interfaces.
27                     -- RlcMiRlcConfigReq
28                     -- RlcMiRlcConfigCfm 
29                     -- RlcMiLkwCntrlReq
30                     -- RlcMiLkwCntrlCfm
31                     -- RlcMiLkwStaReq
32                     -- RlcMiLkwStaCfm
33                     -- RlcMiLkwStaInd
34                     -- RlcMiLkwStsReq
35                     -- RlcMiLkwStsCfm
36                     -- RlcMiLkwTrcInd 
37
38         File:     kw_lmm.c
39
40 ************************************************************************/
41 /** @file rlc_layer_mgr.c
42 @brief RLC Layer Manager Module
43 **/
44
45 \f
46 /* header (.h) include files */
47 #include "common_def.h"
48 #include "lkw.h"           /* LKW defines */
49 #include "ckw.h"           /* CKW defines */
50 #include "kwu.h"           /* KWU defines */
51 #include "rgu.h"           /* RGU defines */
52 #include "rlc_err.h"        /* Err defines */
53 #include "rlc_env.h"        /* RLC environment options */
54
55
56 /* extern (.x) include files */
57 #include "lkw.x"           /* LKW */
58 #include "ckw.x"           /* CKW */
59 #include "kwu.x"           /* KWU */
60 #include "rgu.x"           /* RGU */
61
62 #include "rlc_utils.h"            /* RLC defines */
63 #include "rlc_dl_ul_inf.h"
64 #include "rlc_dl.h"
65 #include "rlc_ul.h"
66
67 #define RLC_MODULE RLC_DBGMASK_LMM
68
69 RLCStats gRlcStats;
70 \f
71 /*********************************************************************
72  *             Forward Declaration of LKW Porting Functions
73  ********************************************************************/
74 RlcCb *rlcCb[MAX_RLC_INSTANCES];
75 S16 rlcActvTmr ARGS ((Ent ent, Inst inst));
76
77 static Void rlcLmmSendCfm ARGS ((RlcCb *gCb,Pst *pst,RlcMngmt *cfm,uint8_t type,
78                                  Header *hdr));
79 static S16 rlcLmmGenCfg ARGS ((RlcCb *gCb, RlcGenCfg *cfg));
80 static S16 rlcLmmCfgKwuSap ARGS ((RlcCb *gCb,RlcSapCfg *cfg));
81 static S16 rlcLmmCfgUdxSap ARGS ((RlcCb *gCb,RlcSapCfg *cfg));
82 static S16 rlcLmmCfgCkwSap ARGS ((RlcCb *gCb,RlcSapCfg   *cfg));
83 static S16 rlcLmmCfgRguSap ARGS ((RlcCb *gCb,RlcSapCfg   *cfg));
84 static S16 rlcLmmGenCntrl ARGS ((RlcCb *gCb,RlcMngmt *cntrl));
85 static S16 rlcLmmUdxSapCntrl ARGS ((RlcCb *gCb,RlcMngmt *cntrl));
86 static S16 rlcLmmLSapCntrl ARGS ((RlcCb *gCb,RlcMngmt *cntrl));
87 static S16 rlcLmmGetKwuSapSta ARGS ((RlcCb *gCb,RlcKwuSapSta *sta));
88 static S16 rlcLmmGetRguSapSta ARGS ((RlcCb *gCb,RlcRguSapSta *sta));
89 static S16 rlcLmmGetCkwCntSapSta ARGS ((RlcCb *gCb,RlcCkwCntSapSta *sta));
90 static S16 rlcLmmGetGenSts ARGS ((RlcCb *gCb,RlcGenSts *sts,Action action));
91 static S16 rlcLmmGetSapSts ARGS ((RlcCb *gCb,RlcMngmt *sts,Elmnt elmnt,Action 
92                                   action));
93
94 \f
95 /*********************************************************************
96  *             Primitives for RGU interface 
97  ********************************************************************/
98 /**
99  * @brief
100  *    Stores the general RLC configuration. 
101  * @details
102  *    It calculates the memory requirement of the Saps  
103  *    It also initializes the control blocks, the hash lists and registers
104  *    the timers. In case of error it rolls back and reports error in the 
105  *    confirm.If the general configuration is already done it is treated as 
106  *    reconfiguration, but right now reconfiguration is not supported.
107  * 
108  * @param[in]  gCb   RLC Instance Control Block
109  * @param[in]  cfm   RLC LM general config structure
110  * 
111  * @return  S16
112  *    LCM_REASON_NOT_APPL  (SUCCESS) 
113  *    LCM_REASON_MEM_NOAVAIL
114  *    LCM_REASON_REGTMR_FAIL
115  *    LCM_REASON_INVALID_PAR_VAL
116  *    LCM_REASON_HASHING_FAILED
117  */
118 static S16 rlcLmmGenCfg(RlcCb  *gCb,RlcGenCfg *cfg)
119 {
120    Size     rlcSapSize;
121    Size     rlcUdxSapSize;
122    S16      ret;
123    CmTqCp   *rlcTqCp;
124    Size     rguSapSize;
125
126    if(cfg->maxUe > RLC_MAX_UE) 
127    {
128 #if (ERRCLASS & ERRCLS_INT_PAR)
129       DU_LOG("\nERROR  --> RLC : Invalid maxUe : Max [%lu] Received [%lu]", 
130             RLC_MAX_UE, 
131             cfg->maxUe);
132 #endif /* ERRCLASS & ERRCLS_INT_PAR */
133       return (LCM_REASON_INVALID_PAR_VAL);
134    }
135
136    if(cfg->maxKwuSaps > RLC_MAX_KWUSAPS)
137    {
138 #if (ERRCLASS & ERRCLS_INT_PAR)
139       DU_LOG("\nERROR  --> RLC : Invalid maxKwuSaps : Max [%lu] Received [%lu]", 
140             RLC_MAX_KWUSAPS, 
141             cfg->maxKwuSaps);
142 #endif /* ERRCLASS & ERRCLS_INT_PAR */
143       return (LCM_REASON_INVALID_PAR_VAL);
144    }
145
146    if(cfg->maxUdxSaps > RLC_MAX_UDXSAPS)
147    {
148 #if (ERRCLASS & ERRCLS_INT_PAR)
149       DU_LOG("\nERROR  --> RLC : Invalid maxUduSaps : Max [%lu] Received [%lu]", 
150             RLC_MAX_UDXSAPS, 
151             cfg->maxUdxSaps);
152 #endif /* ERRCLASS & ERRCLS_INT_PAR */
153       return (LCM_REASON_INVALID_PAR_VAL);
154    }
155    
156    if((cfg->maxRguSaps == 0) || (cfg->maxRguSaps > RLC_MAX_RGUSAPS))
157    {
158       
159
160       return (LCM_REASON_INVALID_PAR_VAL);
161    }
162    if(gCb->init.cfgDone == TRUE)
163    {
164       /* reconfiguration not supported */
165       return (LCM_REASON_RECONFIG_FAIL);
166    }
167
168    gCb->genCfg = *cfg;
169
170    /* Timer Queue Control point initialization */
171    rlcTqCp         = &(gCb->rlcTqCp);
172    rlcTqCp->tmrLen = RLC_TMR_LEN;
173    rlcTqCp->nxtEnt = 0;
174
175    gCb->rlcThpt.inst = gCb->init.inst;
176    gCb->rlcThpt.thptTmr.tmrEvnt = TMR_NONE;
177    gCb->rlcThpt.numActvUe = 0;
178    memset(gCb->rlcThpt.thptPerUe, 0, MAX_NUM_UE * sizeof(RlcThptPerUe));
179
180    if(gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
181    {
182       RLC_ALLOC(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
183       if (gCb->u.dlCb == NULLP)
184       {  
185          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
186          return (LCM_REASON_MEM_NOAVAIL);
187       
188       }
189       /* allocate memory to the KWU sap's */
190       rlcSapSize = (Size)((Size) gCb->genCfg.maxKwuSaps *
191                    (Size)sizeof(RlcKwuSapCb));
192
193       RLC_ALLOC(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
194
195 #if (ERRCLASS & ERRCLS_INT_PAR)
196       if(gCb->u.dlCb->rlcKwuDlSap == NULLP)
197       {
198          RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
199          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
200          return (LCM_REASON_MEM_NOAVAIL);
201       }
202 #endif /* ERRCLASS & ERRCLS_INT_PAR */
203
204       gCb->u.dlCb->numKwuSaps = gCb->genCfg.maxKwuSaps;
205
206       rlcUdxSapSize = (Size)((Size) gCb->genCfg.maxUdxSaps *
207                    (Size)sizeof(RlcUdxDlSapCb));
208
209       RLC_ALLOC(gCb,gCb->u.dlCb->udxDlSap, rlcUdxSapSize);
210 #if (ERRCLASS & ERRCLS_INT_PAR)
211       if(gCb->u.dlCb->udxDlSap == NULLP)
212       {
213          RLC_FREE(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
214          RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
215          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
216          return (LCM_REASON_MEM_NOAVAIL);
217       }
218 #endif /* ERRCLASS & ERRCLS_INT_PAR */
219
220       rguSapSize = (Size)((Size) gCb->genCfg.maxRguSaps *
221                    (Size)sizeof(RlcRguSapCb));
222       RLC_ALLOC(gCb,gCb->u.dlCb->rguDlSap, rguSapSize);
223 #if (ERRCLASS & ERRCLS_INT_PAR)
224       if(gCb->u.dlCb->rguDlSap == NULLP)
225       {
226          RLC_FREE(gCb,gCb->u.dlCb->udxDlSap, rlcSapSize);
227          RLC_FREE(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
228          RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
229       
230          RLCLOGERROR(gCb,ERRCLS_INT_PAR, EKW043, (ErrVal) cfg->maxUe,
231                    "rlcLmmGenCfg: SgetSBuf Failed for rguSap...!");
232          return (LCM_REASON_MEM_NOAVAIL);
233       }
234 #endif /* ERRCLASS & ERRCLS_INT_PAR */
235
236       
237       /* Initialize the Ue and Cell hash list */
238       ret = rlcDbmDlInit(gCb);
239       if (ret != ROK)
240       {
241          RLC_FREE(gCb,gCb->u.dlCb->udxDlSap, rlcSapSize);
242          RLC_FREE(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
243          RLC_FREE(gCb,gCb->u.dlCb->rguDlSap, rguSapSize);
244          RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
245          DU_LOG("\nERROR  --> RLC_DL : RLC DL Initialization failed");   
246          return (LCM_REASON_MEM_NOAVAIL);
247       }
248
249       /* Register the timer */
250       if(ODU_REG_TMR_MT(gCb->init.ent, gCb->init.inst, (uint16_t)cfg->timeRes,
251               rlcActvTmr) != ROK)
252       {
253          RLC_FREE(gCb,gCb->u.dlCb->udxDlSap, rlcUdxSapSize);
254          RLC_FREE(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
255          RLC_FREE(gCb,gCb->u.dlCb->rguDlSap, rguSapSize);
256          RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
257
258          return (LCM_REASON_REGTMR_FAIL);
259       }
260
261       /* initializations for background processing of freeing memory */
262       rlcUtlInitToBeFreed(gCb, &(gCb->u.dlCb->toBeFreed));
263       rlcUtlInitializeSelfPst(gCb);
264
265       if(ODU_GET_MSG_BUF(gCb->init.region, gCb->init.pool, &(gCb->u.dlCb->selfPstMBuf)) != ROK)
266       {
267          RLC_FREE(gCb,gCb->u.dlCb->udxDlSap, rlcSapSize);
268          RLC_FREE(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
269          RLC_FREE(gCb,gCb->u.dlCb->rguDlSap, rguSapSize);
270          RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
271
272          return (LCM_REASON_MEM_NOAVAIL);
273       
274       }
275 #ifdef LTE_L2_MEAS
276       rlcUtlL2MeasDlInit(gCb);
277 #endif
278    }
279    else if(gCb->genCfg.rlcMode == LKW_RLC_MODE_UL)
280    {
281       RLC_ALLOC(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
282       if (gCb->u.ulCb == NULLP)
283       {     
284          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
285          return (LCM_REASON_MEM_NOAVAIL);
286       
287       }
288       /* allocate memory to the KWU sap's */
289       rlcSapSize = (Size)((Size) gCb->genCfg.maxKwuSaps *
290                    (Size)sizeof(RlcKwuSapCb));
291
292       RLC_ALLOC(gCb,gCb->u.ulCb->rlcKwuUlSap, rlcSapSize);
293
294 #if (ERRCLASS & ERRCLS_INT_PAR)
295       if(gCb->u.ulCb->rlcKwuUlSap == NULLP)
296       {
297          RLC_FREE(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
298          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
299          return (LCM_REASON_MEM_NOAVAIL);
300       }
301 #endif /* ERRCLASS & ERRCLS_INT_PAR */
302
303       gCb->u.ulCb->numKwuSaps = gCb->genCfg.maxKwuSaps;
304
305       /* allocate memory to the KWU sap's */
306       rlcUdxSapSize = (Size)((Size) gCb->genCfg.maxUdxSaps *
307                    (Size)sizeof(RlcUdxUlSapCb));
308
309       RLC_ALLOC(gCb,gCb->u.ulCb->udxUlSap, rlcUdxSapSize);
310
311 #if (ERRCLASS & ERRCLS_INT_PAR)
312       if(gCb->u.ulCb->rlcKwuUlSap == NULLP)
313       {
314          RLC_FREE(gCb,gCb->u.ulCb->rlcKwuUlSap, rlcSapSize);
315          RLC_FREE(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
316          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
317          return (LCM_REASON_MEM_NOAVAIL);
318       }
319 #endif /* ERRCLASS & ERRCLS_INT_PAR */
320
321       rguSapSize = (Size)((Size) gCb->genCfg.maxRguSaps *
322                    (Size)sizeof(RlcRguSapCb));
323       RLC_ALLOC(gCb,gCb->u.ulCb->rguUlSap, rguSapSize);
324 #if (ERRCLASS & ERRCLS_INT_PAR)
325       if(gCb->u.ulCb->rguUlSap == NULLP)
326       {
327          RLC_FREE(gCb,gCb->u.ulCb->rlcKwuUlSap, rlcSapSize);
328          RLC_FREE(gCb,gCb->u.ulCb->rguUlSap, rlcSapSize);
329          RLC_FREE(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
330       
331          RLCLOGERROR(gCb,ERRCLS_INT_PAR, EKW043, (ErrVal) cfg->maxUe,
332                    "rlcLmmGenCfg: SgetSBuf Failed for rguSap...!");
333          return (LCM_REASON_MEM_NOAVAIL);
334       }
335 #endif /* ERRCLASS & ERRCLS_INT_PAR */
336
337       /* Initialize the Ue and Cell hash list */
338       ret = rlcDbmUlInit(gCb);
339       if (ret != ROK)
340       {
341          RLC_FREE(gCb,gCb->u.ulCb->udxUlSap, rlcUdxSapSize);
342          RLC_FREE(gCb,gCb->u.ulCb->rlcKwuUlSap, rlcSapSize);
343          RLC_FREE(gCb,gCb->u.ulCb->rguUlSap, rlcSapSize);
344          RLC_FREE(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
345          DU_LOG("\nERROR  --> RLC_DL : RLC DL Initialization failed");   
346       }
347
348       /* Register the timer */
349       if(ODU_REG_TMR_MT(gCb->init.ent, gCb->init.inst, (uint16_t)cfg->timeRes,
350               rlcActvTmr) != ROK)
351       {
352          RLC_FREE(gCb,gCb->u.ulCb->udxUlSap, rlcUdxSapSize);
353          RLC_FREE(gCb,gCb->u.ulCb->rlcKwuUlSap, rlcSapSize);
354          RLC_FREE(gCb,gCb->u.ulCb->rguUlSap, rlcSapSize);
355          RLC_FREE(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
356
357          return (LCM_REASON_REGTMR_FAIL);
358       }
359
360 #ifdef LTE_L2_MEAS
361       rlcUtlL2MeasUlInit(gCb);
362 #endif
363    }
364    else
365    {
366 #if (ERRCLASS & ERRCLS_INT_PAR)
367       DU_LOG("\nERROR  --> RLC : Received Invalid RLC Mode");
368 #endif /* ERRCLASS & ERRCLS_INT_PAR */
369
370       return (LCM_REASON_INVALID_PAR_VAL);
371    }
372    /* Timer Initialization  */
373    gCb->rlcTqCp.tmrLen = RLC_TMR_LEN;
374
375    memset(gCb->rlcTq, NULLP, sizeof(CmTqType) * RLC_TMR_LEN);
376
377    RLC_MEM_CPY(&(gCb->init.lmPst), &cfg->lmPst, sizeof(Pst));
378
379    gCb->init.lmPst.srcProcId = gCb->init.procId;
380    gCb->init.lmPst.srcEnt = gCb->init.ent;
381    gCb->init.lmPst.srcInst = gCb->init.inst;
382    gCb->init.lmPst.event = EVTNONE;
383
384    /* kw002.201 For multi core and multi region,no need to reinitiailize the 
385     * region again . This would be done with kwActvInit from SSI */
386 #if !defined(SS_MULTICORE_SUPPORT) && !defined(SS_M_PROTO_REGION)
387    gCb->init.region = cfg->lmPst.region;
388 #endif /* !defined(SS_MULTICORE_SUPPORT) && !defined(SS_M_PROTO_REGION) */
389    gCb->init.pool   = cfg->lmPst.pool;
390
391    gCb->init.cfgDone = TRUE;
392
393    /* TODO : make this generic for DL and UL after support for UL throughput calculation is added */
394    if(gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
395    {
396       /* Starting timer to print throughput */
397       if((rlcChkTmr(gCb, (PTR)(&gCb->rlcThpt), EVENT_RLC_THROUGHPUT_TMR)) == FALSE)
398       {
399          DU_LOG("\nINFO   --> RLC_DL : Starting Throughput timer");
400          rlcStartTmr(gCb, (PTR)(&gCb->rlcThpt), EVENT_RLC_THROUGHPUT_TMR);
401       }
402    }
403
404    return (LCM_REASON_NOT_APPL);
405
406
407 /**
408  * @brief
409  *     Sends confirmation message to LM Called by RlcMiRlcConfigReq function
410  * 
411  * @param[in] gCb    RLC Instance Control Block
412  * @param[in] pst    Post structure
413  * @param[in] cfm    RLC LM structure 
414  * @param[in] type   Type of LM message
415  * @param[in] hdr    Message header
416  * 
417  * @return  S16
418  *     -# ROK
419  */
420 static Void rlcLmmSendCfm
421 (
422 RlcCb      *gCb,
423 Pst        *pst,                
424 RlcMngmt   *cfm,               
425 uint8_t    type,              
426 Header     *hdr              
427 )
428 {
429    Pst   rPst;   /* Reply post structure */
430
431    RLC_MEM_SET(&rPst, 0, sizeof(Pst));   
432  
433    /* reply post structure for confirmation */
434    if (gCb)
435    {
436       rPst.srcEnt = gCb->init.ent;
437       rPst.srcInst = gCb->init.inst;
438       cfm->hdr.entId.ent = gCb->init.ent;
439       cfm->hdr.entId.inst = gCb->init.inst;
440    }
441    else
442    {
443       rPst.srcEnt = pst->dstEnt;
444       rPst.srcInst = pst->dstInst;
445       cfm->hdr.entId.ent = pst->dstEnt;
446       cfm->hdr.entId.inst = pst->dstInst;
447    }
448    rPst.srcProcId = SFndProcId();
449    rPst.dstEnt = pst->srcEnt;
450    rPst.dstInst = pst->srcInst;
451    rPst.dstProcId = pst->srcProcId;
452    rPst.selector = hdr->response.selector;
453    rPst.prior = hdr->response.prior;
454    rPst.route = hdr->response.route;
455    rPst.region = hdr->response.mem.region;
456    rPst.pool= hdr->response.mem.pool;
457
458    /* Fill the reply header */
459    cfm->hdr.elmId.elmnt = hdr->elmId.elmnt;
460    cfm->hdr.transId = hdr->transId;
461
462    switch(type)
463    {
464       case TCFG:
465          RlcMiRlcConfigCfm(&rPst,cfm);
466          break;
467       case TCNTRL:
468          SGetDateTime(&(cfm->t.cntrl.dt));
469          RlcMiLkwCntrlCfm(&rPst,cfm);
470          break;
471       case TSTS:
472          SGetDateTime(&(cfm->t.sts.dt));
473          RlcMiLkwStsCfm(&rPst,0,cfm);
474          break;
475       case TSSTA:
476          SGetDateTime(&(cfm->t.ssta.dt));
477          RlcMiLkwStaCfm(&rPst,cfm);
478          break;
479       default:
480 #if (ERRCLASS & ERRCLS_INT_PAR)
481          DU_LOG("\nERROR  --> RLC : Received Invalid Message Type");
482          if(!gCb)
483          {
484             fflush(stdout);
485          }
486 #endif /* ERRCLASS & ERRCLS_INT_PAR */
487          break;
488    }
489
490    return; 
491
492
493
494 /**
495  * @brief
496  *    This function processes configuration requests received from the layer 
497  *    manager.
498  *
499  * @details
500  *    The configuration requests can be for general configuration, or 
501  *    configuration of RGU, KWU, and CKW SAPs. The type of the configuration 
502  *    request can be determined from the elmId field in the header of the layer
503  *    manager message.This function is called by the layer manager to configure
504  *    RLC. 
505  *
506  *    This function implements the following logic: 
507  *
508  *    - if genCfg is not done, send negative Cfm to the layer manager; 
509  *
510  *    - switch (cfg->hdr.elmId.elmnt)
511  *       - case STGEN 
512  *          - update the genCfg field in RlCb; 
513  *          - allocate the maximum static memory required by the RLC product; 
514  *          - register the timer service by calling SReqTmr; 
515  *          - set CfgDone for not configuring again; 
516  *       - case STKWUSAP 
517  *          - if all the parameters are valid, then allocate the KwuSap control 
518  *            block; 
519  *          - update the SAP control block with the information provided in the 
520  *          - configuration request; 
521  *          - send configuration confirm with the status, success; 
522  *       - case STCKWSAP 
523  *          - if all the parametes are valid, then allocate the CkwSap control 
524  *            block; 
525  *          - update the SAP control block with the information provided in the
526  *            configuration request; 
527  *          - send configuration confirm with the status, success; 
528  *       - case STRGUSAP 
529  *          - if all the parametes are valid, then allocate the rguSap control 
530  *            block; 
531  *          - update the SAP control block with the information provided in the
532  *            configuration request; 
533  *          - send configuration confirm with the status, success; 
534  *       - case STUDXSAP 
535  *          - if all the parametes are valid, then allocate the udxSap control 
536  *            block; 
537  *          - update the SAP control block with the information provided in the
538  *            configuration request; 
539  *          - send configuration confirm with the status, success; 
540  *    - end switch;
541  *     
542  * @param[in] pst   post structure 
543  * @param[in] cfg   LM management structure 
544  * 
545  * @return S16
546  *    -# Success : ROK
547  *    -# Failure : RFAILED
548  */
549
550 uint8_t RlcMiRlcConfigReq (Pst *pst,RlcMngmt *cfg)
551 {
552    Reason   reason;   /* failure reason */
553    RlcCb     *tRlcCb=NULLP;
554
555 #if (ERRCLASS & ERRCLS_INT_PAR)
556    /* Check if the instance is configured */
557    if (pst->dstInst >= MAX_RLC_INSTANCES)
558    {
559       cfg->cfm.status = LCM_PRIM_NOK;
560       cfg->cfm.reason = LCM_REASON_INVALID_INSTANCE;
561       rlcLmmSendCfm(tRlcCb,pst, cfg, TCFG, &cfg->hdr);     
562       return (RFAILED);
563    }
564 #endif
565    
566    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
567
568    if (!tRlcCb)
569    {
570       cfg->cfm.status = LCM_PRIM_NOK;
571       cfg->cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
572       rlcLmmSendCfm(tRlcCb,pst, cfg, TCFG, &cfg->hdr);     
573       return (RFAILED);
574    }
575    /* check configuration is done or not */
576    if ((tRlcCb->init.cfgDone != TRUE) && 
577        (cfg->hdr.elmId.elmnt != STGEN))
578    {
579       /*
580        * if general config is not over then use pst structure
581        * in primitive to communicate to stack manager
582        */
583
584       cfg->cfm.status = LCM_PRIM_NOK;
585       cfg->cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
586       rlcLmmSendCfm(tRlcCb,pst, cfg, TCFG, &cfg->hdr);     
587       return (RFAILED);
588    }
589
590    DU_LOG("\nDEBUG  --> RLC : RlcMiRlcConfigReq elmId(%d)", cfg->hdr.elmId.elmnt);
591
592    switch(cfg->hdr.elmId.elmnt)
593    {
594       case STGEN:
595       {
596          reason = rlcLmmGenCfg(tRlcCb,&cfg->t.cfg.s.gen);
597          break;
598       }
599       case STKWUSAP:
600       {
601          reason = rlcLmmCfgKwuSap(tRlcCb,&cfg->t.cfg.s.sap);
602          break;
603       }
604       case STCKWSAP:
605       {
606          reason = rlcLmmCfgCkwSap(tRlcCb,&cfg->t.cfg.s.sap);
607          break;
608       }
609       case STRGUSAP:
610       {
611          reason = rlcLmmCfgRguSap(tRlcCb,&cfg->t.cfg.s.sap);
612          break;
613       }
614       case STUDXSAP:
615       {
616          reason = rlcLmmCfgUdxSap(tRlcCb,&cfg->t.cfg.s.sap);
617          break;
618       }
619       default:
620       {
621          reason = LCM_REASON_INVALID_ELMNT;
622          break;
623       }   
624    }
625
626    if (reason == LCM_REASON_NOT_APPL)
627    {
628       cfg->cfm.status = LCM_PRIM_OK;
629       cfg->cfm.reason = LCM_REASON_NOT_APPL;
630       rlcLmmSendCfm(tRlcCb,pst, cfg, TCFG, &cfg->hdr);
631       return (ROK);
632    }
633    else
634    {
635       cfg->cfm.status = LCM_PRIM_NOK;
636       cfg->cfm.reason = reason;
637       rlcLmmSendCfm(tRlcCb,pst, cfg, TCFG, &cfg->hdr);
638       return (RFAILED);
639    }
640
641
642 /**
643  * @brief 
644  *    The layer manager initiates and uses the management-control procedure to 
645  *    control RLC elements.The RLC control request primitive (RlcMiLkwCntrlReq) 
646  *    can be called more than once and at any time after the 
647  *    management-configuration procedure.The control request primitive 
648  *    is confirmed by a RlcMiLkwCntrlCfm primitive.
649  *
650  * @details
651  *    This function implements the following logic: 
652  *  
653  *    - if(cfgDone = FALSE) 
654  *       - send negative confirmation to the layer manager; 
655  *       - return; 
656  *    - else 
657  *    - switch(cntrl->hdr.elmId.elmnt) 
658  *       -  case STGEN 
659  *           - switch (action) 
660  *           - case AENA 
661  *                - switch(subAction) 
662  *                - case SAUSTA 
663  *                     - enable the unsolicited status flag; 
664  *                     - send the control Cfm with success; 
665  *                - case SADBG 
666  *                     - set the debug mask; 
667  *                     - send the control Cfm with success; 
668  *                - case SATRC 
669  *                     - enable the trace flag; 
670  *                     - send the control Cfm with success; 
671  *            - case ADISIMM 
672  *               - switch(subAction) 
673  *               - case SAUSTA 
674  *                    - disable the unsolicited status flag; 
675  *                    - send the control Cfm with success; 
676  *               - case SATRC 
677  *                    - disable the trace flag; 
678  *                    - send the control Cfm with success; 
679  *          - case ASHUTDOWN 
680  *     - case STRGUSAP 
681  *          - Call LSapCntrl
682  *     - case STUDXSAP 
683  *          - Call UdxSapCntrl
684  *     - default  
685  *    - end else  
686  * 
687  * @param[in] pst     post structure
688  * @param[in] cntrl   LM management structure
689  * 
690  * @return S16
691  *    -# ROK
692  *    -# RFAILED
693  */
694 uint8_t RlcMiLkwCntrlReq(Pst *pst, RlcMngmt *cntrl)
695 {
696    Reason   reason;   /* failure reason */
697    RlcCb     *tRlcCb=NULLP;
698
699 #if (ERRCLASS & ERRCLS_INT_PAR)
700    /* Check if the instance is configured */
701    if (pst->dstInst >= MAX_RLC_INSTANCES)
702    {
703       cntrl->cfm.status = LCM_PRIM_NOK;
704       cntrl->cfm.reason =  LCM_REASON_INVALID_INSTANCE;
705
706       rlcLmmSendCfm(tRlcCb,pst, cntrl, TCNTRL, &cntrl->hdr);
707       return (RFAILED);
708    }
709 #endif
710    
711    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
712
713    if(!tRlcCb)
714    {
715       cntrl->cfm.status = LCM_PRIM_NOK;
716       cntrl->cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
717       rlcLmmSendCfm(tRlcCb,pst, cntrl, TCNTRL, &cntrl->hdr);
718       return (RFAILED);
719    }
720
721    if (!(tRlcCb->init.cfgDone))
722    {
723       cntrl->cfm.status = LCM_PRIM_NOK;
724       cntrl->cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
725       rlcLmmSendCfm(tRlcCb,pst, cntrl, TCNTRL, &cntrl->hdr);
726       return (RFAILED);
727    }
728    DU_LOG("\nDEBUG  --> RLC : RlcMiLkwCntrlReq(elmId(%d))", cntrl->hdr.elmId.elmnt);
729
730    /* In normal cases, LCM_REASON_NOT_APPL is returned in cfm.
731     * In all error cases appropriate reason is returned
732     * by the functions below
733     */
734
735    switch (cntrl->hdr.elmId.elmnt)
736    {
737       case STGEN:
738       {
739          /* general control */
740          reason = rlcLmmGenCntrl(tRlcCb,cntrl);
741          break;
742       }
743       case STRGUSAP:
744       {
745          /* Lower SAP control */
746          reason = rlcLmmLSapCntrl(tRlcCb,cntrl);
747          break;
748       }
749       case STUDXSAP:
750       {
751          /* Udx Sap cntrl */
752          reason = rlcLmmUdxSapCntrl(tRlcCb,cntrl);
753          break;
754       }
755       default:
756       {
757          reason = LCM_REASON_INVALID_ELMNT;
758          break;
759       }
760    } /* end switch */
761    
762    if (reason == LCM_REASON_NOT_APPL)
763    {
764       cntrl->cfm.status = LCM_PRIM_OK;
765       cntrl->cfm.reason = LCM_REASON_NOT_APPL;
766    }
767    else
768    {
769       cntrl->cfm.status = LCM_PRIM_NOK;
770       cntrl->cfm.reason = reason;
771    }
772
773    rlcLmmSendCfm(tRlcCb,pst, cntrl, TCNTRL, &cntrl->hdr);
774
775    return ROK;
776
777
778 /**
779  * @brief 
780  *    This function processes solicited status requests received from the layer
781  *    manager. The layer manager can request status information regarding the
782  *    system ID, RGUSAP,KWUSAP, or CKWSAP.
783  *
784  * @param[in] pst   post structure
785  * @param[in] sta   LM management structure
786  * @return S16
787  *    -# ROK (SUCCESS)
788  *    -# RFAILED
789  */
790 S16 RlcMiLkwStaReq(Pst *pst,RlcMngmt *sta)
791 {
792    RlcMngmt   rSta;     /* Status */
793    Reason    reason;   /* Failure reason */
794    RlcCb      *tRlcCb=NULLP;
795
796 #if (ERRCLASS & ERRCLS_INT_PAR)
797    /* Check if the instance is configured */
798    if (pst->dstInst >= MAX_RLC_INSTANCES)
799    {
800       sta->cfm.status = LCM_PRIM_NOK;
801       sta->cfm.reason = LCM_REASON_INVALID_INSTANCE;
802
803       rlcLmmSendCfm(tRlcCb,pst, sta, TSSTA, &sta->hdr);
804       return (RFAILED);
805    }
806 #endif
807    
808    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
809    if (!tRlcCb)
810    {
811       sta->cfm.status = LCM_PRIM_NOK;
812       sta->cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
813
814       rlcLmmSendCfm(tRlcCb,pst, sta, TSSTA, &sta->hdr);
815       return (RFAILED);
816    }
817
818    DU_LOG("\nDEBUG  --> RLC : Status request for elmId(%d))", sta->hdr.elmId.elmnt);
819
820    reason = LCM_REASON_NOT_APPL;
821
822    RLC_MEM_SET(&rSta, 0, sizeof(RlcMngmt));
823    switch (sta->hdr.elmId.elmnt)
824    {
825       case STSID:
826       {
827          reason = LCM_REASON_NOT_APPL;
828          rlcGetSId(&rSta.t.ssta.s.sysId);
829          break;
830       }
831       case STKWUSAP:
832       {
833          RLC_MEM_CPY (&rSta.t.ssta.s.rlckwuSap, 
834                      &sta->t.ssta.s.rlckwuSap, 
835                      sizeof (RlcKwuSapSta));
836
837          reason = rlcLmmGetKwuSapSta (tRlcCb,&rSta.t.ssta.s.rlckwuSap);
838          break;
839       }
840       case STRGUSAP:
841       {
842          RLC_MEM_CPY (&rSta.t.ssta.s.rguSap, 
843                      &sta->t.ssta.s.rguSap,
844                      sizeof (RlcRguSapSta));
845
846          reason = rlcLmmGetRguSapSta (tRlcCb,&rSta.t.ssta.s.rguSap);
847          break;
848       }
849       case STCKWSAP:
850       {
851          RLC_MEM_CPY (&rSta.t.ssta.s.ckwSap, 
852                      &sta->t.ssta.s.ckwSap,
853                      sizeof (RlcCkwCntSapSta));
854
855          reason = rlcLmmGetCkwCntSapSta (tRlcCb,&rSta.t.ssta.s.ckwSap);
856          break;
857       }
858       default:
859       {
860          reason = LCM_REASON_INVALID_ELMNT;
861          break;
862       }
863    } /* end of switch */
864
865    if (reason == LCM_REASON_NOT_APPL)
866    {
867       rSta.cfm.status = LCM_PRIM_OK;
868       rSta.cfm.reason = LCM_REASON_NOT_APPL;
869    }
870    else
871    {
872       rSta.cfm.status = LCM_PRIM_NOK;
873       rSta.cfm.reason = reason;
874    }
875    rlcLmmSendCfm(tRlcCb,pst, &rSta, TSSTA, &sta->hdr);
876
877    return ROK;
878
879
880 /**
881  * @brief 
882  *    This function processes statistics requests received from the layer
883  *    manager.
884  *
885  * @details  
886  *    After collecting the statistics, ir calls the statistics confirm function
887  *    to send the statistics to the layer manager.
888  *
889  *    - switch(sts->hdr.elmId.elmnt) 
890  *    - case STGEN 
891  *       - get the general statistics from the KW control block; 
892  *       - if (action = RESET) 
893  *          - reset the general statistic field in the RlCb; 
894  *          - call RlcMiLkwStsCfm to send statistics back to layer manager; 
895  *    - case STCKWSAP 
896  *    - case STKWUSAP 
897  *    - case STRGUSAP 
898  *        - get the SAP specific statistics from KW control block; 
899  *        - if (action = RESET) 
900  *       - reset the general statistic field in the RlCb; 
901  *       - call RlcMiLkwStsCfm to send statistics to the layer manager; 
902  *  -end switch;
903  *
904  * @param[in] pst      post structure
905  * @param[in] action   action 
906  * @param[in] sts      LM management structure
907  * 
908  * @return S16
909  *    -# ROK
910  *    -# RFAILED
911  */
912 S16 RlcMiLkwStsReq (Pst *pst, Action action,RlcMngmt *sts)
913 {
914    RlcMngmt   rSts;     /* Statistics */
915    Reason    reason;   /* Reason for failure */
916    RlcCb     *tRlcCb=NULLP;
917
918 #if (ERRCLASS & ERRCLS_INT_PAR)
919    /* Check if the instance is configured */
920    if (pst->dstInst >= MAX_RLC_INSTANCES)
921    {
922       rSts.cfm.status = LCM_PRIM_NOK;
923       rSts.cfm.reason = LCM_REASON_INVALID_INSTANCE;
924
925       rlcLmmSendCfm(tRlcCb,pst, &rSts, TCNTRL, &sts->hdr);
926       return (RFAILED);
927    }
928 #endif
929    
930    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
931    if (!tRlcCb)
932    {
933       rSts.cfm.status = LCM_PRIM_NOK;
934       rSts.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
935
936       rlcLmmSendCfm(tRlcCb,pst, &rSts, TCNTRL, &sts->hdr);
937       return (RFAILED);
938    }
939
940    DU_LOG("\nDEBUG  --> RLC : RlcMiLkwStsReq(elmId(%d),action(%d))", 
941                        action, 
942                        sts->hdr.elmId.elmnt);
943
944    RLC_MEM_SET(&rSts, 0, sizeof(RlcMngmt));
945
946    switch (sts->hdr.elmId.elmnt)
947    {
948       case STGEN:
949       {
950          reason = rlcLmmGetGenSts(tRlcCb,&rSts.t.sts.s.gen, action);
951          break;
952       }
953       case STKWUSAP:
954       case STCKWSAP:
955       {
956          if( sts->hdr.elmId.elmnt == STKWUSAP)
957          {
958             /* kw005.201, modified the element of rlckwuSap from suId to spId */
959             rSts.t.sts.s.rlckwuSap.spId = sts->t.sts.s.rlckwuSap.spId;
960          }
961          reason = rlcLmmGetSapSts(tRlcCb,&rSts, sts->hdr.elmId.elmnt, action);
962          break;
963       }
964       default:
965       {
966          reason = LCM_REASON_INVALID_ELMNT;
967          break;
968       }
969    } /* end switch */
970
971    if (reason == LCM_REASON_NOT_APPL)
972    {
973       rSts.cfm.status = LCM_PRIM_OK;
974       rSts.cfm.reason = LCM_REASON_NOT_APPL;
975    }
976    else
977    {
978       rSts.cfm.status = LCM_PRIM_NOK;
979       rSts.cfm.reason = reason;
980    }
981    rlcLmmSendCfm(tRlcCb,pst, &rSts, TSTS, &sts->hdr);
982
983    return ROK;
984
985
986 /* kw005.201 added support for L2 Measurement */
987 #ifdef LTE_L2_MEAS
988 /**
989 @brief 
990 This function processes L2 Measurement requests received from the layer manager.
991 The L2 Measurement is start for a time period and after the timer expiry, the 
992 measurement confirm is sent.
993
994 -  Accept only one set of measurements.
995 -  Allocate and initialise RlcL2MeasEvtCb.
996 -  Validate if the measurement is already in progress.
997    -  Loop through the existing measEvtCb with matching measType
998       -  Check if measurement is running for any qci present in the measReq
999       -  If present, move the qCi to list of invalid qCIs.
1000 -  Set RlcL2MeasEvtCb.measOn to TRUE for QCIs to be measured.
1001 -  For the number of measurements requested.
1002    -  For all Ues with RBs matching qCI.
1003       -  Add RbCb to the RB linked list.
1004       -  Set rlcRbCb.measOn to measurement type.
1005       -  If Meas type is DL_DELAY
1006          -  Update COUNT to startCount.
1007 -  Start l2Timer
1008
1009  *  @param[in] pst      post structure
1010  *  @param[in] action   action 
1011  *  @param[in] cfg      LM management structure
1012  *  @return S16
1013  *      -# Success : ROK
1014  *      -# Failure : RFAILED
1015 */
1016 S16 RlcMiLkwL2MeasReq(Pst *pst, RlcL2MeasReqEvt *measReqEvt)
1017 {
1018    S16            ret = ROK;
1019    uint16_t       cntr;
1020    uint8_t        measType;
1021    RlcL2MeasCfmEvt measCfmEvt;
1022
1023    RlcCb     *tRlcCb;
1024
1025    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
1026
1027    /* Initialize measCfmEvt */
1028    RLC_MEM_ZERO(&measCfmEvt, sizeof(RlcL2MeasCfmEvt));
1029    /* validate the received measReqEvt */
1030    /*LTE_L2_MEAS_PHASE2*/
1031    if(measReqEvt->measPeriod != 0)
1032    {
1033       /* L2 MEAS AGHOSH */
1034       if((measReqEvt->measReq.measType & LKW_L2MEAS_DL_IP)|| 
1035             (measReqEvt->measReq.measType & LKW_L2MEAS_UL_IP))
1036       {
1037          ret = rlcUtlValidateIpThL2Meas(measReqEvt, &measCfmEvt);
1038       }
1039
1040       if(ret != ROK)
1041       {
1042 #if (ERRCLASS & ERRCLS_ADD_RES)
1043 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1044          rlcUtlSndUlL2MeasNCfm(tRlcCb, measReqEvt, &measCfmEvt);
1045          RLC_FREE(tRlcCb, measReqEvt, sizeof(RlcL2MeasReqEvt))
1046          return RFAILED;
1047       }
1048    }
1049
1050    measType = measReqEvt->measReq.measType;
1051
1052    if((measType != LKW_L2MEAS_DL_IP) &&
1053       (measType !=  LKW_L2MEAS_ACT_UE) &&
1054       (measType !=  LKW_L2MEAS_DL_DISC) &&
1055       (measType != LKW_L2MEAS_DL_DELAY) && 
1056       (measType != LKW_L2MEAS_UU_LOSS) &&
1057       (measType !=  LKW_L2MEAS_UL_IP))/* || (qci > LKW_MAX_QCI)*/
1058    {
1059       measCfmEvt.transId = measReqEvt->transId;
1060       measCfmEvt.measType = measType;
1061       measCfmEvt.status.status = LCM_PRIM_NOK;
1062       measCfmEvt.status.reason = LKW_CAUSE_INVALID_MEASTYPE;
1063       rlcUtlSndDlL2MeasNCfm(tRlcCb, measReqEvt, &measCfmEvt);
1064       RLC_FREE(tRlcCb, measReqEvt, sizeof(RlcL2MeasReqEvt))
1065       return ROK;
1066    }
1067
1068    /* for UL IP throughput meas enable for all QCIs */
1069    if(measType & LKW_L2MEAS_UL_IP)
1070    {
1071       for(cntr = 0; cntr < LKW_MAX_QCI; cntr++)
1072       {
1073          tRlcCb->u.ulCb->rlcL2Cb.measOn[cntr] |= LKW_L2MEAS_UL_IP;
1074       }
1075    }
1076   
1077    if(measType & 
1078       (LKW_L2MEAS_DL_IP | LKW_L2MEAS_DL_DISC | 
1079       LKW_L2MEAS_DL_DELAY | LKW_L2MEAS_UU_LOSS))
1080    {
1081       RlcL2MeasReqEvt *measEvt;
1082       Pst      *udxPst;
1083
1084       udxPst = &(RLC_GET_UDX_SAP(tRlcCb)->pst);
1085       
1086       RLC_ALLOC_SHRABL_BUF(udxPst->region, 
1087                           udxPst->pool,
1088                           measEvt, 
1089                           sizeof(RlcL2MeasReqEvt));
1090
1091 #if (ERRCLASS & ERRCLS_ADD_RES) /* KW_FIX */ 
1092       if(measEvt == NULLP)
1093       {
1094          DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
1095          return RFAILED;
1096       }   
1097 #endif      
1098       memcpy(measEvt, measReqEvt, sizeof(RlcL2MeasReqEvt));
1099       /*Redirect the request to DL task */
1100       /* NOTE:As of today, there are no cases where the Req will fail at DL
1101          as long as it reached the DL, so we don't wait for a confirmation from
1102          DL to send the confirmation to LM*/
1103       /* The interface for sending a confirmation back does not exist today;
1104          it needs to be created when the need arises */
1105       rlcUlUdxL2MeasReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),measEvt);
1106    }
1107
1108    /* We need to copy the transId for sending back confirms later */
1109    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
1110    {
1111       RlcL2MeasEvtCb* measEvtCb = &(tRlcCb->u.ulCb->rlcL2Cb.rlcL2EvtCb[cntr]);
1112       if(measEvtCb->measCb.measType & measType)
1113       {
1114          measEvtCb->transId= measReqEvt->transId;
1115       }
1116    }
1117    /*RLC_FREE(tRlcCb, measReqEvt, sizeof(RlcL2MeasReqEvt));*/
1118
1119    return (ret);
1120 } /* RlcMiLkwL2MeasReq */
1121
1122 /**
1123 @brief 
1124 This function processes L2 Measurement stop request received from the layer manager.
1125 After receving this request, RLC stops L2 Measurement
1126  *  @param[in] pst      post structure
1127  *  @param[in] measType meas Type 
1128  *  @return S16
1129  *      -# Success : ROK
1130  *      -# Failure : RFAILED
1131 */
1132
1133 S16 RlcMiLkwL2MeasStopReq(Pst *pst,uint8_t measType)
1134 {
1135    S16 ret = ROK;
1136    RlcL2MeasEvtCb *measEvtCb = NULLP;
1137
1138    uint16_t            cntr;
1139    uint8_t             status = ROK;
1140    RlcCb     *tRlcCb;
1141
1142    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
1143
1144    /* reset the counter values for the measurement that is stopped */
1145    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
1146    {
1147       measEvtCb = &(tRlcCb->u.ulCb->rlcL2Cb.rlcL2EvtCb[cntr]);
1148       if(measEvtCb->measCb.measType & measType)
1149       {
1150          rlcUtlResetUlL2MeasInRlcRb(tRlcCb, &measEvtCb->measCb, measType);
1151
1152       }
1153    }   
1154
1155    /* for UL IP throughput meas disable for all QCIs */
1156    if(measType & LKW_L2MEAS_UL_IP)
1157    {
1158       for(cntr = 0; cntr < LKW_MAX_QCI; cntr++)
1159       {
1160          tRlcCb->u.ulCb->rlcL2Cb.measOn[cntr] &= ~LKW_L2MEAS_UL_IP;
1161       }
1162    }
1163    
1164    if((measType & LKW_L2MEAS_DL_IP) || (measType & LKW_L2MEAS_DL_DISC)
1165        || (measType & LKW_L2MEAS_DL_DELAY))
1166    {
1167       /*Redirect the request to DL task */
1168       rlcUlUdxL2MeasStopReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),measType);
1169       /*return ROK;*/
1170    }
1171    /*memset(&measCfmEvt, 0, sizeof(RlcL2MeasCfmEvt)); */
1172
1173    status = LCM_PRIM_OK; 
1174    RlcMiLkwL2MeasStopCfm(&tRlcCb->genCfg.lmPst, measType,status); 
1175    
1176    return (ret);
1177 }
1178 /**
1179 @brief 
1180 This function processes L2 Measurement Send request received from the layer manager.
1181 After receving this request, RLC sends L2 Measurement
1182  *  @param[in] pst      post structure
1183  *  @param[in] measType meas Type 
1184  *  @return S16
1185  *      -# Success : ROK
1186  *      -# Failure : RFAILED
1187 */
1188
1189 S16 RlcMiLkwL2MeasSendReq(Pst *pst,uint8_t measType)
1190 {
1191    /*S16 ret = ROK;*/
1192    RlcL2MeasEvtCb *measEvtCb = NULLP;
1193    uint16_t            cntr;
1194    RlcCb     *tRlcCb;
1195
1196    tRlcCb =  RLC_GET_RLCCB(pst->dstInst);
1197    
1198    /* In case of addition of any new measType here ,appropriate handling 
1199     * has to be done in RLC DL (rlcUtlSndDlL2MeasCfm)*/
1200    if(measType & 
1201       (LKW_L2MEAS_DL_DISC | LKW_L2MEAS_DL_DELAY 
1202        | LKW_L2MEAS_UU_LOSS| LKW_L2MEAS_DL_IP))
1203    {
1204       /*Redirect the request to DL task */
1205       rlcUlUdxL2MeasSendReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),measType);
1206       /* L2 MEAS AGHOSH */
1207       /*return ROK;*/
1208    }
1209
1210    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
1211    {
1212       measEvtCb = &(tRlcCb->u.ulCb->rlcL2Cb.rlcL2EvtCb[cntr]);
1213       /* L2 MEAS AGHOSH */
1214       if(measEvtCb->measCb.measType & measType)
1215       {
1216          rlcUtlHdlL2TmrExp(tRlcCb, measEvtCb);
1217       }
1218    }
1219
1220    return ROK;
1221 }
1222 #endif /* LTE_L2_MEAS */
1223
1224 /**
1225  * @brief
1226  *    This function configures the RLC data sap
1227  *
1228  * @param[in]  gCb   RLC Instance Control Block
1229  * @param[in]  cfg   RLC LM Sap configuration structure
1230  *
1231  * @return  S16
1232  *    -# LCM_REASON_NOT_APPL  (SUCCESS)
1233  *    -# LCM_REASON_INVALID_SAP 
1234  *    -# LCM_REASON_MEM_NOAVAIL 
1235  *    -# LCM_REASON_RECONFIG_FAIL 
1236  */
1237 static S16 rlcLmmCfgKwuSap(RlcCb *gCb,RlcSapCfg *cfg)
1238 {
1239    RlcKwuSapCb   *rlcKwuSapCb;
1240
1241 #if (ERRCLASS & ERRCLS_INT_PAR)
1242    /* Validate the protocol parameters */
1243    if((cfg->sapId >= (S16)gCb->genCfg.maxKwuSaps) || (cfg->sapId < 0))
1244    {
1245       return (LCM_REASON_INVALID_PAR_VAL);
1246    }
1247 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1248
1249    rlcKwuSapCb = (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
1250               (RlcKwuSapCb*)(gCb->u.dlCb->rlcKwuDlSap + cfg->sapId):
1251               (RlcKwuSapCb*)(gCb->u.ulCb->rlcKwuUlSap + cfg->sapId);
1252
1253 #if (ERRCLASS & ERRCLS_INT_PAR)
1254    /* Check for reconfiguration */
1255    if (rlcKwuSapCb->state != RLC_SAP_NOT_CFG)
1256    {
1257       DU_LOG("\nERROR  --> RLC : RLC Mode [%d] : Invalid rlckwuSap State [%d]",
1258             gCb->genCfg.rlcMode, rlcKwuSapCb->state);
1259       /* reconfiguration not allowed */
1260       return (LCM_REASON_RECONFIG_FAIL);
1261    }
1262 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1263
1264    /* Fill the parameters */
1265    RLC_FILL_SAP_HELPER(rlcKwuSapCb, cfg, gCb);
1266
1267    return (LCM_REASON_NOT_APPL);
1268
1269
1270 /**
1271  * @brief
1272  *    This function configures the RLC control sap
1273  *
1274  * @param[in]  gCb   RLC Instance Control Block
1275  * @param[in]  cfg   RLC LM Sap configuration structure
1276  * 
1277  * @return  S16
1278  *    -# LCM_REASON_NOT_APPL (SUCCESS)
1279  *    -# LCM_REASON_INVALID_SAP
1280  *    -# LCM_REASON_INVALID_SAP 
1281  *    -# LCM_REASON_RECONFIG_FAIL 
1282  */
1283 static S16 rlcLmmCfgCkwSap(RlcCb  *gCb,RlcSapCfg *cfg)
1284 {
1285    RlcCkwSapCb  *ckwSap;
1286    
1287 #if (ERRCLASS & ERRCLS_INT_PAR)
1288    /* Validate config parameters */
1289    if ((cfg->sapId >= RLC_MAX_CKWSAPS) || (cfg->sapId < 0) )
1290    {
1291       return (LCM_REASON_INVALID_PAR_VAL);
1292    }
1293
1294    if (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
1295    {
1296       /* Get Sap control block */
1297       return (LCM_REASON_INVALID_PAR_VAL);
1298    }
1299 #endif
1300
1301    ckwSap = &(gCb->u.ulCb->ckwSap);
1302
1303 #if (ERRCLASS & ERRCLS_INT_PAR)
1304    /* Check for reconfiguration */
1305    if(ckwSap->state  != RLC_SAP_NOT_CFG)
1306    {
1307       DU_LOG("\nERROR  --> RLC : Invalid rlckwuSap State [%d]",ckwSap->state);
1308       return (LCM_REASON_RECONFIG_FAIL);
1309    }
1310 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1311    
1312    /* Fill the parameters */
1313    RLC_FILL_SAP_HELPER(ckwSap, cfg, gCb);
1314
1315    return (LCM_REASON_NOT_APPL);
1316
1317
1318 /**
1319  * @brief
1320  *    This function configures the UDX sap
1321  *
1322  * @param[in]  gCb   RLC Instance Control Block
1323  * @param[in]  cfg   RLC LM Sap configuration structure
1324  *
1325  * @return  S16
1326  *    -# LCM_REASON_NOT_APPL   (SUCCESS)
1327  *    -# LCM_REASON_INVALID_SAP
1328  *    -# LCM_REASON_INVALID_SAP
1329  *    -# LCM_REASON_RECONFIG_FAIL
1330  */
1331 static S16 rlcLmmCfgUdxSap(RlcCb *gCb,RlcSapCfg *cfg)
1332 {
1333    RlcUdxDlSapCb   *udxDlSap;
1334    RlcUdxUlSapCb   *udxUlSap;
1335
1336 #if (ERRCLASS & ERRCLS_INT_PAR)
1337    /* Validate the protocol parameters */
1338    if((cfg->sapId >= RLC_MAX_UDXSAPS) || (cfg->sapId < 0))
1339    {
1340       return (LCM_REASON_INVALID_PAR_VAL);
1341    }
1342 #endif
1343    /* Get Sap control block */
1344    if (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
1345    {
1346       udxDlSap = (gCb->u.dlCb->udxDlSap + cfg->sapId);
1347 #if (ERRCLASS & ERRCLS_INT_PAR)
1348       /* Check for reconfiguration */
1349       if(udxDlSap->state != RLC_SAP_NOT_CFG)
1350       {
1351          DU_LOG("\nERROR  --> RLC : Invalid udxDlSap State [%d]",udxDlSap->state);
1352          return (LCM_REASON_RECONFIG_FAIL);
1353       }
1354 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1355
1356       /* Fill the parameters */
1357       RLC_FILL_SAP_HELPER(udxDlSap, cfg, gCb);
1358    }
1359    else
1360    {
1361       udxUlSap = (gCb->u.ulCb->udxUlSap + cfg->sapId);
1362
1363 #if (ERRCLASS & ERRCLS_INT_PAR)
1364    /* Check for reconfiguration */
1365       if(udxUlSap->state != RLC_SAP_NOT_CFG)
1366       {
1367          DU_LOG("\nERROR  --> RLC : Invalid udxUlSap State [%d]", udxUlSap->state);
1368          return (LCM_REASON_RECONFIG_FAIL);
1369       }
1370 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1371
1372       /* Fill the parameters */
1373       RLC_FILL_SAP_HELPER(udxUlSap, cfg, gCb);
1374
1375       udxUlSap->bndTmrInt = cfg->bndTmrIntvl;
1376       udxUlSap->retryCnt = 0;
1377       cmInitTimers(&(udxUlSap->bndTmr), 1);
1378    }
1379
1380    return (LCM_REASON_NOT_APPL);
1381
1382
1383 /**
1384  * @brief
1385  *    This function configures the RGU sap
1386  *
1387  * @param[in]  gCb   RLC Instance Control Block
1388  * @param[in]  cfg   RLC LM Sap configuration structure
1389  * @return  S16
1390  *    -# LCM_REASON_NOT_APPL    (SUCCESS)
1391  *    -# LCM_REASON_INVALID_SAP
1392  *    -# LCM_REASON_INVALID_SAP
1393  *    -# LCM_REASON_RECONFIG_FAIL
1394  */
1395 static S16 rlcLmmCfgRguSap(RlcCb *gCb,RlcSapCfg *cfg)
1396 {
1397    RlcRguSapCb   *rguSap;
1398
1399 #if (ERRCLASS & ERRCLS_INT_PAR)
1400    /* Validate the protocol parameters */
1401    if((cfg->sapId >= gCb->genCfg.maxRguSaps) || \
1402       (cfg->sapId < 0))
1403    {
1404       RLCLOGERROR(gCb,ERRCLS_INT_PAR, EKW047, (ErrVal)cfg->sapId,
1405                "rlcLmmCfgRguSap: Invalid RGU sapId\n");
1406       return (LCM_REASON_INVALID_PAR_VAL);
1407    }
1408 #endif
1409
1410    rguSap = (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
1411             &(gCb->u.dlCb->rguDlSap[cfg->sapId]): &(gCb->u.ulCb->rguUlSap[cfg->sapId]);
1412
1413 #if (ERRCLASS & ERRCLS_INT_PAR)
1414    /* Check for reconfiguration */
1415    if(rguSap->state != RLC_SAP_NOT_CFG)
1416    {
1417       DU_LOG("\nERROR  --> RLC : RLC Mode [%d]: Invalid rguSap State [%d]",
1418             gCb->genCfg.rlcMode, rguSap->state);
1419       return (LCM_REASON_RECONFIG_FAIL);
1420    }
1421 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1422
1423    /* Fill the parameters */
1424    RLC_FILL_SAP_HELPER(rguSap, cfg, gCb);
1425    rguSap->suId = cfg->sapId;
1426    rguSap->bndTmrInt = cfg->bndTmrIntvl;
1427    rguSap->retryCnt = 0;
1428    rguSap->state = RLC_SAP_CFG;
1429
1430    cmInitTimers(&(rguSap->bndTmr), 1);
1431
1432    return (LCM_REASON_NOT_APPL);
1433
1434
1435 /**
1436  * @brief
1437  *    Validates the RLC general control parameters 
1438  *
1439  * @param[in] cntrl   RLC LM structure 
1440  * 
1441  * @return  S16
1442  *    -# LCM_REASON_NOT_APPL (SUCCESS)
1443  *    -# LCM_REASON_INVALID_SUBACTION
1444  *    -# LCM_REASON_INVALID_ACTION
1445  */
1446 static S16 rlcLmmValidateGenCntrl(RlcMngmt   *cntrl)
1447 {
1448    S16     reason;    /* reason for failure */
1449    uint8_t sAction;   /* subaction field */
1450
1451    reason = LCM_REASON_NOT_APPL;
1452    sAction = cntrl->t.cntrl.subAction;
1453
1454    switch (cntrl->t.cntrl.action)
1455    {
1456       case AENA:
1457       case ADISIMM:
1458          if ((sAction != SAUSTA) && 
1459              (sAction != SADBG) && 
1460              (sAction != SATRC))
1461          {
1462             reason = LCM_REASON_INVALID_SUBACTION;
1463          }
1464          break;
1465       case ASHUTDOWN:
1466          break;
1467       default:
1468          reason = LCM_REASON_INVALID_ACTION;
1469          break;
1470    }
1471    
1472    return (reason);
1473
1474
1475 /**
1476  * @brief
1477  *    it deregisters the timers and deregisters the rlckwuSap Control blocks 
1478  *
1479  * @param[in]  gCb   RLC Instance Control Block
1480  * 
1481  * @return  Void
1482  */
1483 static Void rlcLmmCleanGblRsrcs(RlcCb *gCb)
1484 {
1485    Size   rlcSapSize;
1486    Size   rlcUdxSapSize;
1487  
1488    if (gCb->init.cfgDone)
1489    {
1490       /* Deregister the timers */
1491 /*Pradeep: changing the SDeregTmrMt() to SDeregTmr*/
1492       (Void) SDeregTmrMt(gCb->init.ent, gCb->init.inst,
1493                         (S16)gCb->genCfg.timeRes, rlcActvTmr);
1494       /*(Void) SDeregTmr(gCb->init.ent, gCb->init.inst,
1495                         (S16)gCb->genCfg.timeRes, rlcActvTmr);*/
1496
1497       rlcSapSize = (Size)(gCb->genCfg.maxKwuSaps * sizeof(RlcKwuSapCb));
1498
1499       if (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
1500       {
1501          rlcUdxSapSize = (Size)(gCb->genCfg.maxUdxSaps * sizeof(RlcUdxDlSapCb));
1502          if (gCb->u.dlCb)
1503          {
1504             gCb->u.dlCb->shutdownReceived = TRUE;
1505             rlcUtlFreeDlMemory(gCb); 
1506             if (gCb->u.dlCb->rlcKwuDlSap != NULLP)
1507             {
1508                RLC_FREE(gCb,gCb->u.dlCb->rlcKwuDlSap, rlcSapSize);
1509             }
1510             
1511             if(gCb->u.dlCb->udxDlSap != NULLP)
1512             {
1513                RLC_FREE(gCb,gCb->u.dlCb->udxDlSap, rlcUdxSapSize);
1514             }
1515
1516             if(gCb->u.dlCb->rguDlSap != NULLP)
1517             {
1518                RLC_FREE(gCb,gCb->u.dlCb->rguDlSap, gCb->genCfg.maxRguSaps);
1519                gCb->genCfg.maxRguSaps = 0;
1520             }
1521              if (gCb->u.dlCb->shutdownReceived) 
1522             {
1523                if (gCb->u.dlCb->selfPstMBuf != NULL)
1524                {
1525                   ODU_PUT_MSG_BUF(gCb->u.dlCb->selfPstMBuf);
1526                }
1527                RLC_FREE(gCb,gCb->u.dlCb, sizeof (RlcDlCb));
1528             }
1529          }
1530          
1531       }
1532       else
1533       {
1534          rlcUdxSapSize = (Size)(gCb->genCfg.maxUdxSaps * sizeof(RlcUdxUlSapCb));
1535          if (gCb->u.ulCb)
1536          {
1537             if (gCb->u.ulCb->rlcKwuUlSap != NULLP)
1538             {
1539                RLC_FREE(gCb,gCb->u.ulCb->rlcKwuUlSap, rlcSapSize);
1540             }
1541             
1542             if(gCb->u.ulCb->udxUlSap != NULLP)
1543             {
1544                RLC_FREE(gCb,gCb->u.ulCb->udxUlSap, rlcUdxSapSize);
1545             }
1546          
1547             if(gCb->u.ulCb->rguUlSap != NULLP)
1548             {
1549                RLC_FREE(gCb,gCb->u.ulCb->rguUlSap, gCb->genCfg.maxRguSaps);
1550                gCb->genCfg.maxRguSaps = 0;
1551             }
1552          
1553             RLC_FREE(gCb,gCb->u.ulCb, sizeof (RlcUlCb));
1554          }
1555       }
1556
1557       gCb->init.cfgDone = FALSE;
1558       gCb->init.acnt = FALSE;
1559       gCb->init.trc = FALSE;
1560
1561       gCb->init.usta = FALSE;
1562    }
1563
1564    return;
1565 }
1566
1567 /**
1568  * @brief
1569  *    Delete all SAPs and Control Blocks
1570  *
1571  * @details
1572  *    Shutdown of RLC happens at modules level, tm, um and am modules will be
1573  *    shutdown using utility functin and dbm shutdown will clean up the SAPs,
1574  *    control blocks and lists. 
1575  *
1576  * @params[in] gCb   RLC instance control block   
1577  *
1578  * @return  S16
1579  *    -# LCM_REASON_NOT_APPL (SUCCESS)
1580  *    -# LCM_REASON_HASHING_FAILED 
1581  */
1582 static S16 rlcLmmShutdown(RlcCb *gCb)
1583 {
1584    RlcRguSapCb   *rguSap;
1585    uint32_t          idx;
1586
1587    if (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
1588    {
1589       for (idx = 0; idx < gCb->genCfg.maxRguSaps; idx++)
1590       {
1591          rguSap = &(gCb->u.dlCb->rguDlSap[idx]);
1592          if ((rguSap->state == RLC_SAP_BND) || (rguSap->state == RLC_SAP_BINDING))
1593          {
1594             RlcLiRguUbndReq(&(rguSap->pst), rguSap->spId, 0);
1595          }
1596       }
1597    }
1598    else
1599    {
1600       for (idx = 0; idx < gCb->genCfg.maxRguSaps; idx++)
1601       {
1602          rguSap = &(gCb->u.ulCb->rguUlSap[idx]); 
1603          if ((rguSap->state == RLC_SAP_BND) || (rguSap->state == RLC_SAP_BINDING))
1604          {
1605             RlcLiRguUbndReq(&(rguSap->pst), rguSap->spId, 0);
1606          }
1607       }
1608    }
1609    
1610    if(gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
1611    {
1612       rlcDbmDlShutdown(gCb); 
1613    }
1614    else
1615    {
1616       rlcDbmUlShutdown(gCb);
1617    }
1618
1619    rlcLmmCleanGblRsrcs(gCb);
1620
1621    RLC_MEM_SET (&(gCb->genSts), 0, sizeof (RlcGenSts));
1622
1623    return (LCM_REASON_NOT_APPL);
1624
1625
1626 /**
1627  * @brief
1628  *    Function processes the general control request 
1629  *
1630  * @param[in] gCb     RLC instance control block
1631  * @param[in] cntrl   RLC LM structure
1632  *
1633  * @return  S16
1634  *    -# LCM_REASON_NOT_APPL (SUCCESS)
1635  *    -# LCM_REASON_INVALID_SUBACTION
1636  *    -# LCM_REASON_INVALID_ACTION
1637  */
1638 static S16 rlcLmmGenCntrl(RlcCb *gCb,RlcMngmt *cntrl)
1639 {
1640    RlcTrcCntrl *trcCntrl; /* trace */
1641 #ifdef DEBUGP
1642    RlcDbgCntrl *dbgCntrl; /* debug */
1643 #endif /* DEBUGP */
1644    S16   reason;         /* reason for failure */
1645    
1646    /* Validate control parameters */
1647    reason = rlcLmmValidateGenCntrl (cntrl);
1648
1649    if (reason != LCM_REASON_NOT_APPL)
1650    {
1651       return (reason);
1652    }
1653
1654    switch(cntrl->t.cntrl.action)
1655    {
1656       case AENA:
1657       {
1658          switch(cntrl->t.cntrl.subAction)
1659          {
1660             case SAUSTA:
1661             {
1662                RLC_SET_USTA_FLAG(gCb, TRUE);
1663                break;
1664             }
1665             case SADBG:
1666             {
1667 #ifdef DEBUGP
1668                dbgCntrl = &cntrl->t.cntrl.s.dbgCntrl;
1669                RLC_GET_DBG_MASK(gCb) |= dbgCntrl->dbgMask;
1670 #endif /* DEBUGP */
1671                break;
1672             }
1673             case SATRC:
1674             {
1675                trcCntrl = &cntrl->t.cntrl.s.trcCntrl;
1676                gCb->init.trc = TRUE;
1677                gCb->trcLen = trcCntrl->trcLen;
1678                (gCb->trcMask) |= trcCntrl->trcMask;
1679                 break;
1680             }
1681          }
1682          break;
1683       }
1684       case ADISIMM:
1685       {
1686          switch(cntrl->t.cntrl.subAction)
1687          {
1688             case SAUSTA:
1689             {
1690                gCb->init.usta = FALSE;
1691             }
1692             break;
1693             case SADBG:
1694             {
1695 #ifdef DEBUGP
1696                dbgCntrl = &cntrl->t.cntrl.s.dbgCntrl;
1697                RLC_GET_DBG_MASK(gCb) &= ~(dbgCntrl->dbgMask);
1698 #endif /* DEBUGP */
1699             }
1700             break;
1701             case SATRC:
1702             {
1703                trcCntrl = &cntrl->t.cntrl.s.trcCntrl;
1704                gCb->init.trc = FALSE;
1705                gCb->trcMask &= ~(trcCntrl->trcMask);
1706             }
1707             break;
1708          }
1709          break;
1710       }
1711       case ASHUTDOWN:
1712       {
1713          reason = rlcLmmShutdown(gCb);
1714          break;
1715       }
1716    }
1717    return (reason);
1718
1719
1720 /**
1721  * @brief
1722  *    Bind/Unbind RLC UDX sap 
1723  *
1724  * @param[in]  gCb     RLC Instance Control Block
1725  * @param[in]  cntrl   RLC LM structure
1726  * 
1727  * @return  S16
1728  *    -# LCM_REASON_NOT_/PPL (SUCCESS)    
1729  *    -# LCM_REASON_INVALID_SAP 
1730  *    -# LCM_REASON_INVALID_STATE
1731  *    -# LCM_REASON_INVALID_ACTION 
1732  */
1733 static S16 rlcLmmUdxSapCntrl(RlcCb *gCb,RlcMngmt *cntrl)
1734 {
1735
1736 #if (ERRCLASS & ERRCLS_INT_PAR)
1737    if (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
1738    {
1739       return (LCM_REASON_INVALID_SAP);
1740    }
1741    /* validate SuId */
1742    if((cntrl->t.cntrl.s.sapCntrl.suId < 0) || 
1743       (cntrl->t.cntrl.s.sapCntrl.suId >= RLC_MAX_UDXSAPS))
1744    {
1745       return (LCM_REASON_INVALID_SAP);
1746    }
1747 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1748
1749 #define UDX_SAP  gCb->u.ulCb->udxUlSap[cntrl->t.cntrl.s.sapCntrl.suId]
1750 #if (ERRCLASS & ERRCLS_INT_PAR)
1751    /* validate SAP */
1752    if(UDX_SAP.state == RLC_SAP_NOT_CFG)
1753    {
1754       DU_LOG("\nERROR  --> RLC : udxUlSap not configured yet");
1755       return (LCM_REASON_INVALID_STATE);
1756    }
1757 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1758
1759    switch(cntrl->t.cntrl.action)
1760    {
1761       case ABND:
1762       {
1763          if(UDX_SAP.state != RLC_SAP_BND)
1764          {
1765             /* start timer to wait for bind confirm */
1766             rlcStartTmr(gCb,(PTR)(&UDX_SAP), EVENT_RLC_WAIT_BNDCFM);
1767             UDX_SAP.state = RLC_SAP_BINDING;
1768             rlcUlUdxBndReq(&(UDX_SAP.pst), UDX_SAP.suId, UDX_SAP.spId);
1769          }
1770          else
1771          {
1772             /* control request received for an already bound SAP */
1773             return (LCM_REASON_INVALID_STATE);
1774          }
1775       }
1776       break;
1777       case AUBND:
1778       {
1779          /* make the state of UDXSAP configured but not bound */
1780          UDX_SAP.state = RLC_SAP_CFG;
1781          rlcUlUdxUbndReq(&(UDX_SAP.pst), UDX_SAP.spId, 0);
1782       }
1783       break;
1784       default:
1785          return (LCM_REASON_INVALID_ACTION);
1786          break;
1787    } /* end of switch */
1788 #undef UDX_SAP
1789    return (LCM_REASON_NOT_APPL);
1790
1791
1792 /**
1793  * @brief
1794  *    Bind/Unbind RLC lower sap 
1795  *
1796  * @param[in]  gCb     RLC Instance Control Block
1797  * @param[in]  cntrl   RLC LM structure
1798  * @return  S16
1799  *    -# LCM_REASON_NOT_APPL       (SUCCESS)
1800  *    -# LCM_REASON_INVALID_SAP 
1801  *    -# LCM_REASON_INVALID_STATE
1802  *    -# LCM_REASON_INVALID_ACTION 
1803  */
1804 static S16 rlcLmmLSapCntrl(RlcCb *gCb,RlcMngmt *cntrl)
1805 {
1806    RlcRguSapCb   *rguSap;   /* rgu sap pointer */
1807
1808 #if (ERRCLASS & ERRCLS_INT_PAR)
1809    /* validate SuId */
1810    if((cntrl->t.cntrl.s.sapCntrl.suId < 0) || 
1811       (cntrl->t.cntrl.s.sapCntrl.suId >= gCb->genCfg.maxRguSaps))
1812    {
1813       RLCLOGERROR(gCb,ERRCLS_INT_PAR, EKW047, (ErrVal)cntrl->t.cntrl.s.sapCntrl.suId,
1814                "rlcLmmLSapCntrl: Invalid RGU suId\n");
1815       return (LCM_REASON_INVALID_SAP);
1816    }
1817 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1818    rguSap = (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
1819             &(gCb->u.dlCb->rguDlSap[cntrl->t.cntrl.s.sapCntrl.suId]): \
1820             &(gCb->u.ulCb->rguUlSap[cntrl->t.cntrl.s.sapCntrl.suId]);
1821
1822 #if (ERRCLASS & ERRCLS_INT_PAR)
1823    /* validate SAP */
1824    if(rguSap->state == RLC_SAP_NOT_CFG)
1825    {
1826       DU_LOG("\nERROR  --> RLC : RLC Mode [%d]:rguSap not configured yet", gCb->genCfg.rlcMode);
1827       return (LCM_REASON_INVALID_STATE);
1828    }
1829 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1830
1831    switch(cntrl->t.cntrl.action)
1832    {
1833       case ABND:
1834       {
1835          if(rguSap->state != RLC_SAP_BND)
1836          {
1837             /* start timer to wait for bind confirm */
1838             rlcStartTmr(gCb,(PTR)(rguSap), EVENT_RLC_WAIT_BNDCFM);
1839             rguSap->state = RLC_SAP_BINDING;
1840             rguSap->spId = cntrl->t.cntrl.s.sapCntrl.spId;
1841             rguSap->suId = cntrl->t.cntrl.s.sapCntrl.suId;
1842             RlcLiRguBndReq(&(rguSap->pst), rguSap->suId, rguSap->spId);
1843          }
1844          else
1845          {
1846             /* control request received for an already bound SAP */
1847             return (LCM_REASON_INVALID_STATE);
1848          }
1849       }
1850       break;
1851       case AUBND:
1852       {
1853          /* make the state of RGUSAP is configure but not bound */
1854          rguSap->state = RLC_SAP_CFG;
1855          RlcLiRguUbndReq(&(rguSap->pst), rguSap->spId, 0);
1856       }
1857       break;
1858       default:
1859          return (LCM_REASON_INVALID_ACTION);
1860          break;
1861    } /* end of switch */
1862
1863    return (LCM_REASON_NOT_APPL);
1864
1865
1866 /**
1867  * @brief
1868  *    Function gather the general KWU SAP status 
1869  *
1870  * @param[in] gCb   RLC Instance Control Block
1871  * @param[in] sta   LM KWU Sap Status structure 
1872  * 
1873  * @return  S16
1874  *    -# LCM_REASON_NOT_APPL       (SUCCESS)
1875  *    -# LCM_REASON_INVALID_PAR_VAL(FAILURE)
1876  */
1877 static S16 rlcLmmGetKwuSapSta (RlcCb *gCb,RlcKwuSapSta *sta)
1878 {
1879    RlcKwuSapCb   *rlcKwSapCb;
1880    
1881 #if (ERRCLASS & ERRCLS_INT_PAR)
1882    /* Validate the protocol parameters */
1883    if ((sta->spId >= (S16)gCb->genCfg.maxKwuSaps)||
1884        (sta->spId < 0))
1885    {
1886       return (LCM_REASON_INVALID_PAR_VAL);
1887    }
1888 #endif
1889
1890    /* Get Sap control block */
1891    rlcKwSapCb = (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)? 
1892              (RlcKwuSapCb*)(gCb->u.dlCb->rlcKwuDlSap + sta->spId):
1893              (RlcKwuSapCb*)(gCb->u.ulCb->rlcKwuUlSap + sta->spId);
1894
1895    sta->state = rlcKwSapCb->state;
1896
1897    return (LCM_REASON_NOT_APPL);
1898
1899
1900 /**
1901  * @brief
1902  *    Function gather the general RGU SAP status
1903  *
1904  * @param[in]  gCb   RLC Instance Control Block
1905  * @param[in]  sta   LM RGU Sap Status structure
1906  * @return  S16
1907  *    -# LCM_REASON_NOT_APPL       (SUCCESS) 
1908  *    -# LCM_REASON_INVALID_PAR_VAL(FAILURE) 
1909  */
1910 static S16 rlcLmmGetRguSapSta(RlcCb *gCb,RlcRguSapSta *sta)
1911 {
1912
1913 #if (ERRCLASS & ERRCLS_INT_PAR)
1914    /* Validate the protocol parameters */
1915    if((sta->suId >= RLC_MAX_RGUSAPS) || (sta->suId < 0))
1916    {
1917       return (LCM_REASON_INVALID_PAR_VAL);
1918    }
1919 #endif
1920
1921    sta->state = (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ? 
1922                  gCb->u.dlCb->rguDlSap[sta->suId].state : 
1923                  gCb->u.ulCb->rguUlSap[sta->suId].state ;
1924
1925    return (LCM_REASON_NOT_APPL);
1926
1927
1928 /**
1929  * @brief
1930  *    Function gather the general CKW SAP status
1931  *
1932  * @param[in]  gCb   RLC Instance Control Block
1933  * @param[in]  sta   LM CKW Sap Status structure
1934  * @return  S16
1935  *    -# LCM_REASON_NOT_APPL       (SUCCESS)
1936  *    -# LCM_REASON_INVALID_PAR_VAL(FAILURE)
1937  */
1938 static S16 rlcLmmGetCkwCntSapSta(RlcCb *gCb,RlcCkwCntSapSta *sta)
1939 {
1940
1941 #if (ERRCLASS & ERRCLS_INT_PAR)
1942    /* Validate config parameters */
1943    if ((sta->spId >= RLC_MAX_CKWSAPS ) ||
1944        (sta->spId < 0 ) ||
1945        (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL))
1946    {
1947       return (LCM_REASON_INVALID_PAR_VAL);
1948    }
1949 #endif
1950    sta->state =  gCb->u.ulCb->ckwSap.state;
1951
1952    return (LCM_REASON_NOT_APPL);
1953
1954
1955
1956 /**
1957  * @brief
1958  *    Gather the general statistics 
1959  *
1960  * @param[in]  gCb      RLC Instance Control Block
1961  * @param[in]  sts      LM general statistics structure
1962  * @param[in]  action   action
1963  * @return  S16
1964  *    -# LCM_REASON_NOT_APPL       (SUCCESS)
1965  *    -# LCM_REASON_INVALID_PAR_VAL(FAILURE)
1966  */
1967 static S16 rlcLmmGetGenSts(RlcCb *gCb,RlcGenSts *sts,Action action)
1968 {
1969
1970 #if (ERRCLASS & ERRCLS_INT_PAR)
1971    /* Validate protocol parameters */
1972    if ((action != LKW_ZEROSTS) && (action != LKW_NOZEROSTS))
1973    {
1974       return (LCM_REASON_INVALID_PAR_VAL);
1975    }
1976 #endif
1977
1978    *sts = gCb->genSts;
1979    
1980    if(action == LKW_ZEROSTS)
1981    {
1982       RLC_MEM_SET (&(gCb->genSts), 0, sizeof (RlcGenSts));
1983    }
1984
1985    return (LCM_REASON_NOT_APPL);
1986
1987
1988 /**
1989  * @brief
1990  *    Gather the SAP statistics
1991  *
1992  * @param[in]  gCb      RLC Instance Control Block
1993  * @param[in]  sts      LM general statistics structure
1994  * @param[in]  elmnt    element 
1995  * @param[in]  action   action 
1996  * 
1997  * @return  S16
1998  *    -# LCM_REASON_NOT_APPL (SUCCESS)
1999  *    -# LCM_REASON_INVALID_PAR_VAL (FAIL)
2000  */
2001 static S16 rlcLmmGetSapSts(RlcCb *gCb,RlcMngmt *sts,Elmnt elmnt, Action action)
2002 {
2003
2004    /* Validate protocol parameters */
2005    if (action != LKW_ZEROSTS && action != LKW_NOZEROSTS)
2006    {
2007       return (LCM_REASON_INVALID_PAR_VAL);
2008    }
2009    switch(elmnt)
2010    {
2011       case STKWUSAP:
2012       {
2013          RlcKwuSapSts  *rlckwuSap; 
2014          RlcKwuSapCb   *rlcKwuSapCb;    
2015          rlckwuSap = &sts->t.sts.s.rlckwuSap;
2016
2017          /* Get Sap control block */
2018          /* kw005.201, modified the element of rlckwuSap from suId to spId */
2019          rlcKwuSapCb = (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL)? 
2020               (RlcKwuSapCb*)(gCb->u.dlCb->rlcKwuDlSap + rlckwuSap->spId):
2021               (RlcKwuSapCb*)(gCb->u.ulCb->rlcKwuUlSap + rlckwuSap->spId);
2022
2023
2024          *rlckwuSap = rlcKwuSapCb->sts;
2025
2026          if (action == LKW_ZEROSTS)
2027          {
2028             RLC_MEM_SET (&rlcKwuSapCb->sts, 0, sizeof (RlcKwuSapSts));
2029          }
2030          break;
2031       }
2032       /* kw005.201 removed RGUSAP statistics support */
2033       case STCKWSAP:
2034       {
2035          RlcCkwCntSts  *ckwSap;  
2036          ckwSap = &sts->t.sts.s.ckwSap;
2037          if (gCb->genCfg.rlcMode == LKW_RLC_MODE_DL) 
2038          {
2039             return (LCM_REASON_INVALID_PAR_VAL);
2040          }
2041
2042          ckwSap->statMsgs = gCb->u.ulCb->ckwSap.sts.statMsgs;
2043
2044          if (action == LKW_ZEROSTS)
2045          {
2046             RLC_MEM_SET (&(gCb->u.ulCb->ckwSap.sts), 0, sizeof (RlcCkwCntSts));
2047          }
2048          break;
2049       }
2050       default:
2051          return (LCM_REASON_INVALID_ELMNT);
2052    }
2053
2054    SGetDateTime(&sts->t.sts.dt);
2055
2056    return (LCM_REASON_NOT_APPL);
2057
2058
2059 /**
2060  * @brief
2061  *    This function sends Unsolicited Status Indication to the Layer Management
2062  *    Entity. 
2063  *
2064  * @param[in]  gCb        RLC Instance Control Block
2065  * @param[in]  category   Category 
2066  * @param[in]  event      event
2067  * @param[in]  cause      cause
2068  * @param[in]  UeId       ueId 
2069  * @param[in]  Qci        qci 
2070  * 
2071  * @return  Void
2072  */
2073 #ifdef LTE_L2_MEAS
2074 Void rlcLmmSendAlarm
2075 (
2076 RlcCb      *gCb,
2077 uint16_t    category,  
2078 uint16_t    event,    
2079 uint16_t    cause,   
2080 SuId        suId,   
2081 uint32_t    ueId,  
2082 uint8_t     qci   
2083 )
2084 #else /* LTE_L2_MEAS */
2085 Void rlcLmmSendAlarm
2086 (
2087 RlcCb       *gCb,
2088 uint16_t    category, 
2089 uint16_t    event,   
2090 uint16_t    cause,  
2091 SuId        suId,  
2092 uint32_t    ueId  
2093 )
2094 #endif /* LTE_L2_MEAS */
2095 {
2096    RlcMngmt   usta;   /* Rlc Management Structure */
2097
2098    if(gCb->init.usta == FALSE)
2099    {
2100       return;
2101    }
2102
2103    usta.hdr.elmId.elmnt = STGEN;
2104    usta.hdr.entId.ent = gCb->init.ent;
2105    usta.hdr.entId.inst = gCb->init.inst;
2106
2107    /* fill in the event and category */
2108    usta.t.usta.alarm.category = category;
2109    usta.t.usta.alarm.event = event;
2110    usta.t.usta.alarm.cause = cause;
2111
2112    /* set the suId and ueId */
2113    usta.t.usta.ueId = ueId;
2114    usta.t.usta.suId = suId;
2115 /* kw005.201 added support for L2 Measurement */
2116 #ifdef LTE_L2_MEAS
2117    if(event == LKW_EVT_MEAS_HALT)
2118    {
2119       usta.t.usta.qci = qci;
2120    }
2121 #endif /* LTE_L2_MEAS */
2122    /* update the date and time */
2123    (Void) SGetDateTime(&usta.t.usta.alarm.dt);
2124
2125    RlcMiLkwStaInd(&(gCb->init.lmPst), &usta);
2126
2127    return;
2128
2129
2130
2131 /**
2132  * @brief
2133  *    This function sends trace indication to LM 
2134  *
2135  * @param[in]  gCb     RLC Instance Control Block
2136  * @param[in]  event   event
2137  * @param[in]  mBuf    meessage buffer
2138  *
2139  * @return S16
2140  *    -# ROK 
2141  *    -# RFAILED 
2142  */
2143 S16 rlcLmmSendTrc(RlcCb *gCb,Event event,Buffer *mBuf)
2144 {
2145    RlcMngmt   trc;              /* RLC management control block */
2146    Buffer    *dstMbuf;   
2147    MsgLen    bufLen;
2148    Data      *tempBuf;
2149    MsgLen    tempCnt;
2150    Pst       pst;
2151
2152    DU_LOG("\nDEBUG  --> RLC : rlcLmmSendTrc(): Trace for event=%d, gCb->trcLen=%d",
2153                      event,
2154                      gCb->trcLen);
2155
2156    memset(&trc, 0, sizeof(RlcMngmt));
2157
2158    pst = gCb->init.lmPst;
2159
2160    trc.t.trc.event = event;
2161    SGetDateTime(&trc.t.trc.dt);
2162    trc.cfm.status = LCM_PRIM_OK;
2163    trc.cfm.reason = LCM_REASON_NOT_APPL;
2164          
2165    if(mBuf != NULLP)
2166    {
2167      /* Check if the whole buffer is to be sent in Trace indication */
2168      if(gCb->trcLen == LKW_FULL_TRACE)
2169      {
2170         if (SCpyMsgMsg(mBuf, pst.region, pst.pool, &dstMbuf)
2171             != ROK)
2172         {
2173            /* rg005.201 removed SPutSBuf on error */
2174            DU_LOG("\nERROR  --> RLC : SCpyMsgMsg Failed");   
2175            return RFAILED;
2176         }
2177         /* Send Trace Indication to Layer manager */
2178         RlcMiLkwTrcInd(&pst, &trc, dstMbuf);
2179      }
2180      /* check if only a specified number of bytes are to be sent */
2181      else if(gCb->trcLen > 0)
2182      {
2183         /* Get the length of the recvd message buffer */
2184         if (SFndLenMsg(mBuf, &bufLen) != ROK)
2185         {
2186            DU_LOG("\nERROR  --> RLC : SFndLenMsg Failed");   
2187            return RFAILED;
2188         }
2189         /* Check if the recvd buffer size is less than request trace len */
2190         if(bufLen < gCb->trcLen)
2191         {
2192            /* Copy the whole of the recvd buffer in trace indication */
2193       
2194            if (SCpyMsgMsg(mBuf, pst.region, pst.pool, &dstMbuf)
2195               != ROK)
2196            {
2197               DU_LOG("\nERROR  --> RLC : SCpyMsgMsg Failed");   
2198               return RFAILED;
2199            }
2200          
2201            /* Send Trace Indication to Layer manager */
2202            RlcMiLkwTrcInd(&pst, &trc, dstMbuf);
2203         }
2204         else
2205         {
2206            /* if the recvd buffer size is greater than request trace len */
2207            /* Get a temporary buffer to store the msg */
2208            RLC_ALLOC(gCb,tempBuf, gCb->trcLen);
2209
2210 #if (ERRCLASS & ERRCLS_INT_PAR)
2211            if(tempBuf == NULLP)
2212            {
2213               (Void) SPutSMem(RLC_GET_MEM_REGION(gCb), RLC_GET_MEM_POOL(gCb));
2214       
2215                DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
2216                return (LCM_REASON_MEM_NOAVAIL);
2217            }
2218 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2219          
2220            /* Copy trcLen nos of bytes from the recvd message */
2221            if (SCpyMsgFix(mBuf,0,gCb->trcLen,tempBuf,&tempCnt) != ROK)   
2222            {
2223               DU_LOG("\nERROR  --> RLC : SCpyMsgFix Failed");   
2224               return RFAILED;
2225            }
2226
2227            if (ODU_GET_MSG_BUF(pst.region, pst.pool, &dstMbuf) != ROK)
2228            {
2229               DU_LOG("\nERROR  --> RLC : Memory Allocation failed");   
2230               return RFAILED;
2231            }
2232            /* Copy the tempBuf data to dst mBuf */
2233            if (SCpyFixMsg(tempBuf,dstMbuf,0,gCb->trcLen,&tempCnt) != ROK)
2234            {
2235               DU_LOG("\nERROR  --> RLC : SCpyMsgFix Failed");   
2236               return RFAILED;
2237            }
2238   
2239            /* Free the memory allocated for tempBuf */
2240            RLC_FREE(gCb,tempBuf, gCb->trcLen);
2241            /* Send Trace Indication to Layer manager */
2242            RlcMiLkwTrcInd(&pst, &trc, dstMbuf);
2243         }
2244      }
2245    }
2246    else
2247    {
2248       RlcMiLkwTrcInd(&pst, &trc, mBuf);
2249    }
2250
2251    return ROK;
2252
2253
2254 \f  
2255 /*
2256  * @brief
2257  *    Activate Task - timer
2258  *
2259  * @details     
2260  *    Invoked by system services to activate a task with a timer tick.
2261  *
2262  * @param[in] ent    entity
2263  * @param[in] inst   instance
2264  *
2265  * @return S16
2266  *    -# ROK
2267  *    -# RFAILED
2268  *
2269  */
2270  
2271 S16 rlcActvTmr(Ent ent,Inst inst)
2272 {
2273    RlcCb   *gCb; 
2274
2275    if (inst >= MAX_RLC_INSTANCES)
2276    {
2277       return  (RFAILED);
2278    }
2279    gCb = RLC_GET_RLCCB(inst); 
2280    cmPrcTmr(&(gCb->rlcTqCp), gCb->rlcTq, (PFV) rlcTmrExpiry);
2281    return (ROK);
2282
2283 } /* end of rlcActvTmr */
2284
2285  
2286 /********************************************************************30**
2287
2288          End of file
2289 **********************************************************************/