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