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