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