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