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