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