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