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