Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_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 - PDCP - 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                     -- PjMiLpjCfgReq
28                     -- PjMiLpjCfgCfm 
29                     -- PjMiLpjCntrlReq
30                     -- PjMiLpjCntrlCfm
31                     -- PjMiLpjStaReq
32                     -- PjMiLpjStaCfm
33                     -- PjMiLpjStaInd
34                     -- PjMiLpjStsReq
35                     -- PjMiLpjStsCfm
36                     -- PjMiLpjTrcInd 
37
38         File:     pj_lmm.c
39
40 *********************************************************************21*/
41 static const char* RLOG_MODULE_NAME="PDCP";
42 static int RLOG_FILE_ID=135;
43 static int RLOG_MODULE_ID=1024;
44
45 /** @file pj_lmm.c
46 @brief PDCP Layer Manager Module
47 **/
48
49 \f
50 /* header (.h) include files */
51 #include "envopt.h"        /* environment options */
52 #include "envdep.h"        /* environment dependent */
53 #include "envind.h"        /* environment independent */
54
55 #include "gen.h"           /* general */
56 #include "ssi.h"           /* system services */
57 #include "cm5.h"           /* common timer defines */
58 #include "cm_tkns.h"       /* common tokens defines */
59 #include "cm_mblk.h"       /* common memory allocation library defines */
60 #include "cm_llist.h"      /* common link list  defines  */
61 #include "cm_hash.h"       /* common hash list  defines */
62 #include "cm_lte.h"        /* common LTE defines */
63 #include "kwu.h"
64 #include "lpj.h"           /* LPJ defines */
65 #include "cpj.h"           /* CPJ defines */
66 #include "pju.h"           /* PJU defines */
67 #include "lpj.h"           
68 #include "pj_err.h"        /* Err defines */
69 #include "pj_env.h"        /* PDCP environment options */
70 #include "pj.h"            /* PDCP defines */
71 #include "pj_udx.h"
72
73 /* extern (.x) include files */
74 #include "gen.x"           /* general */
75 #include "ssi.x"           /* system services */
76
77 #include "cm5.x"           /* common timer library */
78 #include "cm_tkns.x"       /* common tokens */
79 #include "cm_mblk.x"       /* common memory allocation */
80 #include "cm_llist.x"      /* common link list */
81 #include "cm_hash.x"       /* common hash list */
82 #include "cm_lte.x"        /* common LTE includes */
83 #include "cm_lib.x"        /* common memory allocation library */
84 #include "kwu.x"
85 #include "lpj.x"           /* LPJ */
86 #include "cpj.x"           /* CPJ */
87 #include "pju.x"           /* PJU */
88
89 #include "pj.x"
90 #include "pj_udx.h"
91 #include "pj_udx.x"
92 #include "pj_ul.x"
93 #include "pj_dl.x"
94 #include "pj_lib.x"
95
96 #ifdef __cplusplus
97 EXTERN "C" {
98 #endif /* CPLUSPLUS */
99
100 EXTERN S16 pjGetSId ARGS((SystemId *s));
101 #ifdef __cplusplus
102 }
103 #endif /* CPLUSPLUS */
104
105 U8 *gPoolId; 
106 PDCPStats gPdcpStats;
107
108 #ifdef TENB_AS_SECURITY
109 U8 isSecBatchMode;
110 #endif
111
112 \f
113 /*********************************************************************
114  *             Forward Declaration of LPJ Porting Functions
115  ********************************************************************/
116 PUBLIC PjCb  *pjCb[PJ_MAX_PDCP_INSTANCES];
117 EXTERN S16 pjActvTmr ARGS ((Ent ent, Inst inst));
118
119 PRIVATE S16 pjLmmSendCfm ARGS ((Pst *pst,PjMngmt *cfm,U8 type,Header *hdr));
120 PRIVATE S16 pjLmmGenCfg ARGS ((PjCb *gCb,PjGenCfg *cfg));
121 PRIVATE S16 pjLmmPjuSapCfg ARGS ((PjCb *gCb,PjSapCfg *cfg));
122 PRIVATE S16 pjLmmKwuSapCfg ARGS ((PjCb *gCb,PjSapCfg *cfg));
123 PRIVATE S16 pjLmmUdxSapCfg ARGS ((PjCb *gCb,PjSapCfg *cfg));
124 PRIVATE S16 pjLmmCpjSapCfg ARGS ((PjCb *gCb,PjSapCfg   *cfg));
125 PRIVATE S16 pjLmmGenCntrl ARGS ((PjCb *gCb,PjMngmt *cntrl));
126 PRIVATE S16 pjLmmUdxSapCntrl ARGS ((PjCb *gCb,PjMngmt *cntrl));
127 PRIVATE S16 pjLmmLSapCntrl ARGS ((PjCb *gCb,PjMngmt *cntrl));
128 PRIVATE S16 pjLmmFormLmCfm ARGS ((Pst *pst, Header *hdr, Reason reason));
129 PRIVATE S16 pjLmmGetPjuSapSta ARGS ((PjCb *gCb,PjPjuSapSta *sta));
130 PRIVATE S16 pjLmmGetKwuSapSta ARGS ((PjCb *gCb,PjKwuSapSta *sta));
131 PRIVATE S16 pjLmmGetUdxSapSta ARGS ((PjCb *gCb,PjUdxSapSta *sta));
132 PRIVATE S16 pjLmmGetCpjSapSta ARGS ((PjCb *gCb,PjCpjSapSta *sta));
133 PRIVATE S16 pjLmmGetGenSts ARGS ((PjCb *gCb,PjGenSts *sts,Action action));
134 PRIVATE S16 pjLmmGetSapSts ARGS ((PjCb *gCb,PjMngmt *sts,Elmnt elmnt,Action action));
135 PRIVATE Void pjLmmCleanGblRsrcs ARGS ((PjCb *gCb));
136 \f
137 /*********************************************************************
138  *             Primitives for LPJ interface 
139  ********************************************************************/
140 /**
141  * @brief
142       Stores the general PDCP configuration. It calculates the
143       memory requirement and reserves it. It also initializes the
144       control blocks, the hash lists and registers the timers. In
145       case of error it rolls back and reports error in the confirm.
146       If the general configuration is already done it is treated as
147       reconfiguration, but right now reconfiguration is not supported.
148  
149  *  @param[in] cfm         PDCP LM general config structure
150  *  @return  S16
151  *      -# Success : LCM_REASON_NOT_APPL 
152  *      -# Failure : LCM_REASON_MEM_NOAVAIL
153  *                   LCM_REASON_REGTMR_FAIL
154  *                   LCM_REASON_INVALID_PAR_VAL
155  *                   LCM_REASON_HASHING_FAILED
156  */
157 #ifdef ANSI
158 PRIVATE S16 pjLmmGenCfg
159 (
160 PjCb        *gCb,
161 PjGenCfg    *cfg
162 )
163 #else
164 PRIVATE S16 pjLmmGenCfg(gCb, cfg)
165 PjCb        *gCb;
166 PjGenCfg    *cfg;
167 #endif
168 {
169    Size       pjMemSize;
170    CmTqCp     *pjTqCp;
171    U16        cnt;
172    S16        ret;
173
174    TRC2(pjLmmGenCfg)
175
176    ret       =   ROK;
177    pjMemSize =   0;
178
179    if(cfg->maxUe > PJ_MAX_UE) 
180    {
181 #if (ERRCLASS & ERRCLS_INT_PAR)
182       RLOG2(L_ERROR, "Invalid maxUe : Max [%lu] Received [%lu]", 
183                         PJ_MAX_UE, cfg->maxUe);
184 #endif /* ERRCLASS & ERRCLS_INT_PAR */
185       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
186    }
187
188    if(cfg->maxPjuSaps > PJ_MAX_PJUSAPS)
189    {
190 #if (ERRCLASS & ERRCLS_INT_PAR)
191       RLOG2(L_ERROR, "Invalid maxPjuSaps : Max [%lu] Received [%lu]", 
192                        PJ_MAX_PJUSAPS, cfg->maxPjuSaps);
193 #endif /* ERRCLASS & ERRCLS_INT_PAR */
194       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
195    }
196
197    if(cfg->maxKwuSaps > PJ_MAX_KWUSAPS)
198    {
199 #if (ERRCLASS & ERRCLS_INT_PAR)
200       RLOG2(L_ERROR, "Invalid maxKwuSaps : Max [%lu] Received [%lu]", 
201                         PJ_MAX_KWUSAPS, cfg->maxKwuSaps);
202 #endif /* ERRCLASS & ERRCLS_INT_PAR */
203       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
204    }
205
206    if(cfg->maxUdxSaps > PJ_MAX_UDXSAPS)
207    {
208 #if (ERRCLASS & ERRCLS_INT_PAR)
209       RLOG2(L_ERROR, "Invalid maxUduSaps : Max [%lu] Received [%lu]", 
210                        PJ_MAX_UDXSAPS, cfg->maxUdxSaps);
211 #endif /* ERRCLASS & ERRCLS_INT_PAR */
212       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
213    }   
214
215    if(gCb->init.cfgDone & PJ_LMM_GENCFG_DONE)
216    {
217       /* reconfiguration is supported only for obdDiscTmrInt */
218 #if (defined(PJ_SEC_ASYNC) || defined(PJ_CMP_ASYNC))
219       gCb->pjGenCfg.obdTmrInt = cfg->obdTmrInt;
220       gCb->pjGenCfg.obdWtTmrInt = cfg->obdWtTmrInt;
221 #endif /* PJ_SEC_ASYNC || PJ_CMP_ASYNC */
222       RETVALUE(LCM_REASON_NOT_APPL);
223    }
224
225    PJ_MEM_CPY(&(gCb->pjGenCfg), cfg, sizeof(PjGenCfg));
226 #ifdef TENB_AS_SECURITY
227    isSecBatchMode = TRUE;
228    /* Rangeley Fix */
229 #ifdef INTEL_SW_SEC
230    isSecBatchMode = FALSE;
231 #endif
232
233 #endif
234
235    /* Timer Queue Control point initialization */
236    pjTqCp         = &(gCb->pjTqCp);
237    pjTqCp->tmrLen = PJ_TMR_LEN;
238    pjTqCp->nxtEnt = 0;
239
240    /* calculate the memory requirements */
241    pjMemSize += (Size)SBUFSIZE(PJ_UE_LIST_BUCKET_SIZE * sizeof(CmListEnt));
242
243    /* Cell Hash List Size */
244    pjMemSize += (Size)SBUFSIZE(PJ_CELL_LIST_BUCKET_SIZE * sizeof(CmListEnt));
245
246    /* Reserve the memory */
247    if(SGetSMem(PJ_GET_MEM_REGION(gCb), pjMemSize,
248               PJ_GET_MEM_POOL_ADDRESS(gCb)) != ROK)
249    {
250       RETVALUE(LCM_REASON_MEM_NOAVAIL);
251    }
252    cmMemset((U8 *)&gCb->pjTq, 0, sizeof(CmTqType)*PJ_TMR_LEN);
253    cmMemset((U8 *)&gCb->pjTqCp, 0, sizeof(CmTqCp));
254    gCb->pjTqCp.tmrLen = PJ_TMR_LEN;
255    /* Register the timer */
256    if(SRegTmrMt(gCb->init.ent, gCb->init.inst, (U16)cfg->timeRes,
257               pjActvTmr) != ROK)
258    {
259       (Void) SPutSMem(PJ_GET_MEM_REGION(gCb), PJ_GET_MEM_POOL(gCb));
260
261       RETVALUE(LCM_REASON_REGTMR_FAIL);
262    }
263
264    /* Timer Initialization  */
265    gCb->pjTqCp.tmrLen = PJ_TMR_LEN;
266    for(cnt = 0; cnt < PJ_TMR_LEN; cnt++)
267    {
268       gCb->pjTq[cnt].first = NULLP;
269       gCb->pjTq[cnt].tail = NULLP;
270    }
271
272
273    if (cfg->mode == LPJ_MODE_PDCP_UL)
274    {
275       PJ_ALLOC(gCb, gCb->u.ulCb, sizeof(PjUlgCb)); 
276       if (gCb->u.ulCb == NULLP)
277       {  
278         RLOG0(L_FATAL, "Memory Allocation failed.");
279         /* Do clean up */
280         RETVALUE(RFAILED);
281       }
282       
283       /* Initialize the Ue and Cell hash list */
284       ret = pjDbmUlInit(gCb); /*How would DbmDlInit be called? */
285       if (ret != ROK)
286       {
287          /* Do Clean up */
288          RETVALUE(LCM_REASON_HASHING_FAILED);
289       }
290     
291       /* Initialize the PJU SAP control blocks */
292       PJ_MEM_SET(&(gCb->u.ulCb->pjuSap[PJ_SRB_SAP]), 0, sizeof(PjPjuSapCb));
293       PJ_MEM_SET(&(gCb->u.ulCb->pjuSap[PJ_DRB_SAP]), 0, sizeof(PjPjuSapCb));
294
295       /* Initialize the KWU SAP Control blocks */
296       PJ_MEM_SET(&(gCb->u.ulCb->kwuSap), 0, (PJ_MAX_KWUSAPS * sizeof(PjPjuSapCb)));
297       PJ_MEM_SET(&(gCb->u.ulCb->udxUlSap), 0, (PJ_MAX_UDXSAPS * sizeof(PjUdxUlSapCb)));
298
299       /* Initialize CPJ SAP control block */
300       PJ_MEM_SET(&(gCb->u.ulCb->cpjSap), 0, sizeof(PjCpjSapCb)); 
301 #ifdef LTE_L2_MEAS
302       pjUtlL2MeasUlInit(gCb);
303 #endif
304    }
305    else
306    {
307       PJ_ALLOC(gCb, gCb->u.dlCb, sizeof(PjDlgCb)); 
308       if (gCb->u.dlCb == NULLP)
309       {
310         RLOG0(L_FATAL, "Memory Allocation failed.");
311         /* Do clean up */
312         RETVALUE(RFAILED);
313       }
314       
315       /* Initialize the Ue and Cell hash list */
316       ret = pjDbmDlInit(gCb);
317       if (ret != ROK)
318       {
319          RETVALUE(LCM_REASON_HASHING_FAILED);
320       }
321     
322
323       /* Initialize the PJU SAP control blocks */
324       PJ_MEM_SET(&(gCb->u.dlCb->pjuSap[PJ_SRB_SAP]), 0, sizeof(PjPjuSapCb));
325       PJ_MEM_SET(&(gCb->u.dlCb->pjuSap[PJ_DRB_SAP]), 0, sizeof(PjPjuSapCb));
326
327       /* Initialize the KWU SAP Control blocks */
328       PJ_MEM_SET(&(gCb->u.dlCb->kwuSap), 0, (PJ_MAX_KWUSAPS * sizeof(PjPjuSapCb)));
329       PJ_MEM_SET(&(gCb->u.dlCb->udxDlSap), 0, (PJ_MAX_UDXSAPS * sizeof(PjUdxDlSapCb)));
330 #ifdef LTE_L2_MEAS
331       pjUtlL2MeasDlInit(gCb);
332 #endif
333    }
334
335    PJ_MEM_CPY(&(gCb->init.lmPst), &cfg->lmPst,
336                       sizeof(Pst));
337
338    gCb->init.lmPst.srcProcId = gCb->init.procId;
339    gCb->init.lmPst.srcEnt = gCb->init.ent;
340    gCb->init.lmPst.srcInst = gCb->init.inst;
341    gCb->init.lmPst.event = EVTNONE;
342
343    /* pj002.201 For multi core and multi region, no need to reinitiailize the region again .
344       This would be done with pjActvInit from SSI */
345 #if !defined(SS_MULTICORE_SUPPORT) && !defined(SS_M_PROTO_REGION)
346    gCb->init.region = cfg->lmPst.region;
347 #endif
348    gCb->init.pool   = cfg->lmPst.pool;
349
350    gCb->init.cfgDone |= PJ_LMM_GENCFG_DONE;
351
352    gPoolId = &(gCb->u.dlCb->kwuSap->pst.pool);
353
354 #ifdef TENB_AS_SECURITY
355    /* Initialize UL fd for interfacing with SPAcc */
356    if (cfg->mode == LPJ_MODE_PDCP_UL)
357    {
358       if(PjLibObdUlInitReq(gCb) != ROK)
359       {
360          RETVALUE(LCM_REASON_MISC_FAILURE);
361       }
362    }
363    else
364    {
365       /* Initialize DL fd for interfacing with SPAcc */
366       if(PjLibObdDlInitReq(gCb) != ROK)
367       {
368          RETVALUE(LCM_REASON_MISC_FAILURE);
369       }
370    }
371 #endif
372
373
374    RETVALUE(LCM_REASON_NOT_APPL);
375 } /* pjLmmGenCfg */
376
377 /**
378  *
379  * @brief
380  *     Sends confirmation message to LM Called by Request function
381  *  @param[in] pst         Post structure
382  *  @param[in] cfm         PDCP LM structure 
383  *  @param[in] type        type of message
384  *  @param[in] hdr         message header
385  *  @return  S16
386  *      -# ROK
387  */
388 #ifdef ANSI
389 PRIVATE S16 pjLmmSendCfm
390 (
391 Pst *pst,                    /* Post structure */
392 PjMngmt *cfm,                /* PDCP LM structure */
393 U8 type,                     /* type of message */
394 Header *hdr                  /* message header */
395 )
396 #else
397 PRIVATE S16 pjLmmSendCfm(pst, cfm, type, hdr)
398 Pst *pst;                    /* Post structure */
399 PjMngmt *cfm;                /* PDCP LM structure */
400 U8 type;                     /* type of message */
401 Header *hdr;                 /* message header */
402 #endif
403 {
404    Pst rPst;                 /* Reply post structure */
405    PjCb   *tPjCb;
406    TRC2(pjLmmSendCfm);
407
408    tPjCb = PJ_GET_PJCB(pst->dstInst);
409    PJ_MEM_SET(&rPst, 0, sizeof(Pst));   
410  
411    /* reply post structure for confirmation */
412    rPst.srcEnt = tPjCb->init.ent;
413    rPst.srcInst = tPjCb->init.inst;
414    rPst.srcProcId = SFndProcId();
415    rPst.dstEnt = pst->srcEnt;
416    rPst.dstInst = pst->srcInst;
417    rPst.dstProcId = pst->srcProcId;
418    rPst.selector = hdr->response.selector;
419    rPst.prior = hdr->response.prior;
420    rPst.route = hdr->response.route;
421    rPst.region = hdr->response.mem.region;
422    rPst.pool= hdr->response.mem.pool;
423
424    /* Fill the reply header */
425    PJ_MEM_SET (&cfm->hdr, '\0', sizeof(cfm->hdr));
426    cfm->hdr.elmId.elmnt = hdr->elmId.elmnt;
427    cfm->hdr.entId.ent = tPjCb->init.ent;
428    cfm->hdr.entId.inst = tPjCb->init.inst;
429    cfm->hdr.transId = hdr->transId;
430
431    switch(type)
432    {
433       case TCFG:
434          PjMiLpjCfgCfm(&rPst,cfm);
435          break;
436       case TCNTRL:
437          SGetDateTime(&(cfm->t.cntrl.dt));
438          PjMiLpjCntrlCfm(&rPst,cfm);
439          break;
440       case TSTS:
441          SGetDateTime(&(cfm->t.sts.dt));
442          PjMiLpjStsCfm(&rPst,0,cfm);
443          break;
444       case TSSTA:
445          SGetDateTime(&(cfm->t.ssta.dt));
446          PjMiLpjStaCfm(&rPst,cfm);
447          break;
448       default:
449 #if (ERRCLASS & ERRCLS_INT_PAR)
450          RLOG0(L_ERROR, "Invalid message type");
451           
452 #endif /* ERRCLASS & ERRCLS_INT_PAR */
453          break;
454    }
455
456    RETVALUE(ROK);
457 } /* pjLmmSendCfm */
458
459
460 /**
461 @brief
462 This function processes configuration requests received from the layer manager.
463 The configuration requests can be for general configuration, or configuration
464 of PJU, and CPJ SAPs. The type of the configuration request can be determined
465 from the elmId field in the header of the layer manager message.This function
466 is called by the layer manager to configure PDCP. 
467
468 This function implements the following logic: \n
469
470 - switch (cfg->hdr.elmId.elmnt)
471    - case STGEN 
472       - update the genCfg field in RlCb; 
473       - allocate the maximum static memory required by the PDCP product; 
474       - register the timer service by calling SReqTmr; 
475       - set CfgDone for not configuring again; 
476    - case STPJUSAP 
477       - if genCfg is not done, send negative Cfm to the layer manager; 
478       - if all the parameters are valid, then allocate the RlSap control block;
479       - update the SAP control block with the information provided in the 
480       - configuration request; 
481       - send configuration confirm with the status, success; 
482    - case STCPJSAP 
483       - if genCfg is not done, send negative Cfm to the layer manager; 
484       - if all the parametes are valid, then allocate the CrSap control block; 
485       - update the SAP control block with the information provided in the
486          configuration request; 
487       - send configuration confirm with the status, success; 
488 - end switch;
489  
490  *  @param[in] pst      post structure 
491  *  @param[in] cfg      LM management structure 
492  *  @return S16
493  *      -# Success : ROK
494  *      -# Failure : RFAILED
495 */
496
497 #ifdef ANSI
498 PUBLIC S16 PjMiLpjCfgReq 
499 (
500 Pst *pst, 
501 PjMngmt *cfg
502 )
503 #else
504 PUBLIC S16 PjMiLpjCfgReq (pst, cfg)
505 Pst  *pst;
506 PjMngmt *cfg;
507 #endif
508 {
509    S16   ret;
510    Elmnt elmnt;          /* header element */
511    PjMngmt rCfm;         /* Reply cfm */
512    Reason reason;        /* failure reason */
513    PjCb   *tPjCb;
514
515    TRC3(PjMiLpjCfgReq);
516
517    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)     /* KW_FIX */
518    {
519        RETVALUE(RFAILED);
520    }
521
522    tPjCb = PJ_GET_PJCB(pst->dstInst);
523
524    RLOG1(L_DEBUG, "PjMiLpjCfgReq(post, elmId(%d))", cfg->hdr.elmId.elmnt);
525
526    ret = ROK;
527
528    /* check configuration is done or not */
529    if ((!(tPjCb->init.cfgDone & PJ_LMM_GENCFG_DONE)) &&
530          (cfg->hdr.elmId.elmnt != STGEN))
531    {
532       /*
533        * if general config is not over then use pst structure
534        * in primitive to communicate to stack manager
535        */
536
537       rCfm.cfm.status = LCM_PRIM_NOK;
538       rCfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
539       pjLmmSendCfm(pst, &rCfm, TCFG, &cfg->hdr);     
540       RETVALUE(RFAILED);
541    }
542
543    elmnt = cfg->hdr.elmId.elmnt;
544
545    switch(elmnt)
546    {
547       case STGEN:
548       {
549          reason = pjLmmGenCfg(tPjCb,&cfg->t.cfg.s.gen);
550          break;
551       }
552       case STPJUSAP:
553       {
554          reason = pjLmmPjuSapCfg(tPjCb,&cfg->t.cfg.s.sap);
555          break;
556       }
557       case STKWUSAP:
558       {
559          reason = pjLmmKwuSapCfg(tPjCb,&cfg->t.cfg.s.sap);
560          break;
561       }
562       case STCPJSAP:
563       {
564          reason = pjLmmCpjSapCfg(tPjCb,&cfg->t.cfg.s.sap);
565          break;
566       }
567       case STUDXSAP:
568       {
569          reason = pjLmmUdxSapCfg(tPjCb,&cfg->t.cfg.s.sap);
570          break;
571       }
572       default:
573       {
574          reason = LCM_REASON_INVALID_ELMNT;
575          break;
576       }   
577    }
578
579    if (reason == LCM_REASON_NOT_APPL)
580    {
581       rCfm.cfm.status = LCM_PRIM_OK;
582       rCfm.cfm.reason = LCM_REASON_NOT_APPL;
583
584       ret = ROK;
585    }
586    else
587    {
588       rCfm.cfm.status = LCM_PRIM_NOK;
589       rCfm.cfm.reason = reason;
590
591       ret = RFAILED;
592    }
593
594    RLOG2(L_DEBUG, "Cfg  Req processed : status(%d) reason(%d)",
595             rCfm.cfm.status, rCfm.cfm.reason);
596
597    ret = pjLmmSendCfm(pst, &rCfm, TCFG, &cfg->hdr);
598
599    RETVALUE(ret);
600 } /* PjMiLpjCfgReq */
601
602 /**
603 @brief 
604 The layer manager initiates and uses the management-control procedure to
605 control PDCP elements.The PDCP control request primitive (PjMiLpjCntrlReq)
606 can be called more than once and at any time after the management-configuration
607 procedure.The control request primitive is confirmed by a PjMiLpjCntrlCfm
608 primitive.
609
610 This function implements the following logic: \n
611
612 - if(cfgDone = FALSE) 
613    - send negative confirmation to the layer manager; 
614    - return; 
615 - else 
616 - switch(cntrl->hdr.elmId.elmnt) 
617    -  case STGEN 
618         - switch (action) 
619         - case AENA 
620              - switch(subAction) 
621              - case SAUSTA 
622                   - enable the unsolicited status flag; 
623                   - send the control Cfm with success; 
624              - case SADBG 
625                   - set the debug mask; 
626                   - send the control Cfm with success; 
627              - case SATRC 
628                   - enable the trace flag; 
629                   - send the control Cfm with success; 
630         - case ADISIMM 
631              - switch(subAction) 
632              - case SAUSTA 
633                   - disable the unsolicited status flag; 
634                   - send the control Cfm with success; 
635              - case SATRC 
636                   - disable the trace flag; 
637                   - send the control Cfm with success; 
638         - case ASHUTDOWN 
639    - case STMKSAP 
640         - switch (action) 
641         - case ABND 
642         - case AUBND 
643    - default  
644 - end else  
645  *  @param[in] pst      post structure
646  *  @param[in] cntrl    LM management structure
647  *  @return S16
648  *      -# Success : ROK
649  *      -# Failure : RFAILED
650 */
651 #ifdef ANSI
652 PUBLIC S16 PjMiLpjCntrlReq
653 (
654 Pst *pst, 
655 PjMngmt *cntrl
656 )
657 #else
658 PUBLIC S16 PjMiLpjCntrlReq(pst, cntrl)
659 Pst     *pst;
660 PjMngmt *cntrl;
661 #endif
662 {
663    Elmnt elmnt;          /* header element */
664    PjMngmt rCfm;         /* Reply cfm */
665    Reason reason;        /* failure reason */
666
667    S16 ret;
668    PjCb   *tPjCb;
669  
670    TRC3(PjMiLpjCntrlReq)
671
672    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)     /* KW_FIX */
673    {
674      RETVALUE(RFAILED);
675    }
676
677    tPjCb = PJ_GET_PJCB(pst->dstInst);
678
679    RLOG1(L_DEBUG,  "Cntrl Req Received (post, elmId(%d))", 
680                        cntrl->hdr.elmId.elmnt);
681
682    ret = ROK;
683
684    if (!(tPjCb->init.cfgDone & PJ_LMM_GENCFG_DONE))
685    {
686       rCfm.cfm.status = LCM_PRIM_NOK;
687       rCfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
688
689       pjLmmSendCfm(pst, &rCfm, TCNTRL, &cntrl->hdr);
690       RETVALUE(RFAILED);
691    }
692
693    /* In normal cases, LCM_REASON_NOT_APPL is returned in cfm.
694     * In all error cases appropriate reason is returned
695     * by the functions below
696     */
697
698    elmnt = cntrl->hdr.elmId.elmnt;
699
700    reason = LCM_REASON_NOT_APPL;
701
702
703    switch (elmnt)
704    {
705       case STGEN:
706       {
707          /* general control */
708          reason = pjLmmGenCntrl(tPjCb,cntrl);
709          break;
710       }
711
712       case STKWUSAP:
713       {
714          /* general control */
715          reason = pjLmmLSapCntrl(tPjCb,cntrl);
716          break;
717       }
718       case STUDXSAP:
719       {
720          /* general control */
721          reason = pjLmmUdxSapCntrl(tPjCb,cntrl);
722          break;
723       }
724
725       default:
726       {
727          reason = LCM_REASON_INVALID_ELMNT;
728          break;
729       }
730    } /* end switch */
731
732    RLOG1(L_DEBUG, "Cntrl Req  Processed sending cfm: reason(%d)", reason);
733
734    ret = pjLmmFormLmCfm(pst, &cntrl->hdr, reason);
735    RETVALUE(ret);
736 } /* PjMiLpjCntrlReq */
737
738 /**
739 @brief 
740 This function processes solicited status requests received from the layer
741 manager. The layer manager can request status information regarding the
742 system ID, PJUSAP, or CPJSAP.
743
744  *  @param[in] pst      post structure
745  *  @param[in] cfm    LM management structure
746  *  @return S16
747  *      -# Success : ROK
748  *      -# Failure : RFAILED
749 */
750 #ifdef ANSI
751 PUBLIC S16 PjMiLpjStaReq
752 (
753 Pst *pst, 
754 PjMngmt *sta
755 )
756 #else
757 PUBLIC S16 PjMiLpjStaReq(pst, sta)
758 Pst     *pst;
759 PjMngmt *sta;
760 #endif
761 {
762    S16      ret;
763    Elmnt    elmnt;            /* Header element */
764    PjMngmt  rSta;             /* Status */
765    Reason   reason;           /* Failure reason */
766    PjCb   *tPjCb;
767
768    TRC3(PjMiLpjStaReq);
769
770    tPjCb = PJ_GET_PJCB(pst->dstInst);
771    RLOG1(L_DEBUG, "Status  Req Received (post, elmId(%d))", 
772                          sta->hdr.elmId.elmnt);
773
774    PJ_MEM_SET(&rSta, 0, sizeof(PjMngmt));
775
776    reason = LCM_REASON_NOT_APPL;
777
778    elmnt = sta->hdr.elmId.elmnt;
779
780    switch (elmnt)
781    {
782       case STSID:
783       {
784          reason = LCM_REASON_NOT_APPL;
785          pjGetSId(&rSta.t.ssta.s.sysId);
786          break;
787       }
788       case STGEN:
789       {
790          break;
791       }
792       case STKWUSAP:
793       {
794          PJ_MEM_CPY (&rSta.t.ssta.s.kwuSap, &sta->t.ssta.s.kwuSap,
795                sizeof (PjKwuSapSta));
796          reason = pjLmmGetKwuSapSta (tPjCb,&rSta.t.ssta.s.kwuSap);
797          break;
798       }
799       case STUDXSAP:
800       {
801          PJ_MEM_CPY (&rSta.t.ssta.s.udxSap, &sta->t.ssta.s.udxSap,
802                sizeof (PjUdxSapSta));
803          reason = pjLmmGetUdxSapSta (tPjCb,&rSta.t.ssta.s.udxSap);
804          break;
805       }
806       case STPJUSAP:
807       {
808          PJ_MEM_CPY (&rSta.t.ssta.s.pjuSap, &sta->t.ssta.s.pjuSap,
809                sizeof (PjPjuSapSta));
810          reason = pjLmmGetPjuSapSta (tPjCb,&rSta.t.ssta.s.pjuSap);
811          break;
812       }
813       case STCPJSAP:
814       {
815          PJ_MEM_CPY (&rSta.t.ssta.s.cpjSap, &sta->t.ssta.s.cpjSap,
816                sizeof (PjCpjSapSta));
817          reason = pjLmmGetCpjSapSta (tPjCb,&rSta.t.ssta.s.cpjSap);
818          break;
819       }
820       default:
821       {
822          reason = LCM_REASON_INVALID_ELMNT;
823          break;
824       }
825    } /* end of switch */
826
827    if (reason == LCM_REASON_NOT_APPL)
828    {
829       rSta.cfm.status = LCM_PRIM_OK;
830       rSta.cfm.reason = LCM_REASON_NOT_APPL;
831
832       ret = ROK;
833    }
834    else
835    {
836       rSta.cfm.status = LCM_PRIM_NOK;
837       rSta.cfm.reason = reason;
838
839       ret = RFAILED;
840    }
841
842    RLOG2(L_DEBUG, "Sta Req processed - sending cfm: status(%d) reason(%d)",
843              rSta.cfm.status, rSta.cfm.reason);
844
845    ret = pjLmmSendCfm(pst, &rSta, TSSTA, &sta->hdr);
846
847    RETVALUE(ret);
848 } /* PjMiLpjStaReq */
849
850 /**
851 @brief 
852 This function processes statistics requests received from the layer manager.
853 After collecting the statistics, this function calls the statistics confirm
854 function to send the statistics to the layer manager.
855
856 - switch(sts->hdr.elmId.elmnt) 
857   - case STGEN 
858      - get the general statistics from the PJ control block; 
859      - if (action = RESET) 
860         - reset the general statistic field in the RlCb; 
861         - call PjMiLpjStsCfm to send statistics back to layer manager; 
862   - case STCPJSAP 
863   - case STPJUSAP 
864       - get the SAP specific statistics from PJ control block; 
865       - if (action = RESET) 
866       - reset the general statistic field in the RlCb; 
867       - call PjMiLpjStsCfm to send statistics to the layer manager; 
868 -end switch;
869
870  *  @param[in] pst      post structure
871  *  @param[in] action   action 
872  *  @param[in] cfg      LM management structure
873  *  @return S16
874  *      -# Success : ROK
875  *      -# Failure : RFAILED
876 */
877 #ifdef ANSI
878 PUBLIC S16 PjMiLpjStsReq 
879 (
880 Pst *pst, 
881 Action action, 
882 PjMngmt *sts
883 )
884 #else
885 PUBLIC S16 PjMiLpjStsReq (pst, action, sts)
886 Pst     *pst;
887 Action  action;
888 PjMngmt *sts;
889 #endif
890 {
891    S16      ret;
892    PjMngmt  rSts;             /* Statistics */
893    Reason   reason;           /* Reason for failure */
894    Elmnt    elmnt;            /* Element Id */
895    PjCb   *tPjCb;
896
897    TRC3(PjMiLpjStsReq);
898
899    tPjCb = PJ_GET_PJCB(pst->dstInst);
900    RLOG2(L_DEBUG,  "Sts Req (post, elmId(%d),action(%d))",
901             action, sts->hdr.elmId.elmnt);
902
903    PJ_MEM_SET(&rSts, 0, sizeof(PjMngmt));
904    elmnt = sts->hdr.elmId.elmnt;
905
906    switch (elmnt)
907    {
908       case STGEN:
909       {
910          reason = pjLmmGetGenSts(tPjCb,&rSts.t.sts.s.gen, action);
911          break;
912       }
913       case STPJUSAP:
914       {
915          reason = pjLmmGetSapSts(tPjCb,sts, elmnt, action);
916          PJ_MEM_CPY(&rSts.t.sts.s.pjuSap, &sts->t.sts.s.pjuSap, 
917                     sizeof(PjPjuSts));
918          break;
919       }
920       case STCPJSAP: /* No CPJ SAP statistics available */
921       default:
922       {
923          reason = LCM_REASON_INVALID_ELMNT;
924          break;
925       }
926    } /* end switch */
927
928    if (reason == LCM_REASON_NOT_APPL)
929    {
930       rSts.cfm.status = LCM_PRIM_OK;
931       rSts.cfm.reason = LCM_REASON_NOT_APPL;
932
933       ret = ROK;
934    }
935    else
936    {
937       rSts.cfm.status = LCM_PRIM_NOK;
938       rSts.cfm.reason = reason;
939
940       ret = RFAILED;
941    }
942
943    RLOG2(L_DEBUG, "Sts Req Processed - sending cfm: status(%d) reason(%d)",
944             rSts.cfm.status, rSts.cfm.reason);
945
946    ret = pjLmmSendCfm(pst, &rSts, TSTS, &sts->hdr);
947
948    RETVALUE(ret);
949 } /* PjMiLpjStsReq */
950 /* pj005.201 added support for L2 Measurement */
951 #ifdef LTE_L2_MEAS
952 /**
953  * @brief  Validates the measurement request parameters. 
954  *
955  * @details
956  *
957  *     Function :pjUtlValidateL2Meas 
958  *
959  *  @param[in]  PjL2MeasReqEvt measReqEvt
960  *  @param[out] PjL2MeasCfmEvt measCfmEvt
961  **/
962 #ifdef ANSI
963 PRIVATE S16 pjUtlValidateL2Meas
964 (
965 PjCb            *tPjCb, 
966 PjL2MeasReqEvt  *measReqEvt,
967 PjL2MeasCfmEvt  *measCfmEvt
968 )
969 #else
970 PRIVATE S16 pjUtlValidateL2Meas(tPjCb, measReqEvt, measCfmEvt)
971 PjCb             *tPjCb;   
972 PjL2MeasReqEvt  *measReqEvt;
973 PjL2MeasCfmEvt  *measCfmEvt;
974 #endif
975 {
976    U16      measType;
977    S16     ret;
978    U8      qciIdx, qciVal;
979
980    TRC3(pjUtlValidateL2Meas)
981    
982    ret = ROK;
983    measType = measReqEvt->measReq.measType;
984
985    if(measType == 0)
986    {
987       measCfmEvt->numQciCfm = 1;
988       measCfmEvt->measCfm[0].qci = measReqEvt->measReq.qci[0];
989       measCfmEvt->transId = measReqEvt->transId;
990       measCfmEvt->measType = measType;
991       measCfmEvt->status.status = LCM_PRIM_NOK;
992       measCfmEvt->status.reason = LPJ_CAUSE_INVALID_MEASTYPE;
993       RETVALUE(RFAILED);
994    }
995    if(((measReqEvt->measReq.measType & LPJ_L2CPU_PERCORE_STATS) || 
996        (measReqEvt->measReq.measType & LPJ_L2MEM_PERPOOL_STATS)) &&
997        (~(measReqEvt->measReq.measType & LPJ_L2MEAS_UL_LOSS))) 
998
999    {
1000       RETVALUE(ROK);
1001    }
1002    if(measReqEvt->measReq.numQci > LPJ_MAX_QCI || measReqEvt->measReq.numQci == 0)
1003    {
1004       measCfmEvt->numQciCfm = 1;
1005       measCfmEvt->transId = measReqEvt->transId;
1006       measCfmEvt->measType = measType;
1007       measCfmEvt->status.status = LCM_PRIM_NOK;
1008       measCfmEvt->status.reason = LPJ_CAUSE_EXCEED_NUMQCI;
1009       RETVALUE(RFAILED);
1010    }
1011    if(measReqEvt->measPeriod != 0)
1012    {
1013       measCfmEvt->numQciCfm = 1;
1014       measCfmEvt->transId = measReqEvt->transId;
1015       measCfmEvt->measType = measType;
1016       measCfmEvt->status.status = LCM_PRIM_NOK;
1017       measCfmEvt->status.reason = LPJ_CAUSE_INVALID_MEASTYPE;
1018       RETVALUE(RFAILED);
1019    }
1020    for(qciIdx = 0; qciIdx < measReqEvt->measReq.numQci; qciIdx++)
1021    {
1022       if(tPjCb->u.ulCb->pjL2Cb.measOn[measReqEvt->measReq.qci[qciIdx]] & 
1023             measReqEvt->measReq.measType)
1024       {
1025         /* Measurement is already ongoing */
1026         measCfmEvt->measCfm[measCfmEvt->numQciCfm].qci = qciIdx;
1027         measCfmEvt->measType = measType;
1028         measCfmEvt->numQciCfm++;
1029       }
1030    }
1031    if(measCfmEvt->numQciCfm > 0)
1032    {
1033       measCfmEvt->status.status = LCM_PRIM_NOK;
1034       measCfmEvt->status.reason = LPJ_CAUSE_MEAS_ALREADY_ENA;
1035       measCfmEvt->transId = measReqEvt->transId;
1036       RETVALUE(RFAILED);
1037    }
1038    for(qciIdx = 0; qciIdx < measReqEvt->measReq.numQci; qciIdx++)
1039    {
1040       qciVal = measReqEvt->measReq.qci[qciIdx];
1041       if(qciVal == 0 || qciVal > 9)
1042       {
1043          measCfmEvt->numQciCfm = 1;
1044          measCfmEvt->measCfm[0].qci = measReqEvt->measReq.qci[qciIdx];
1045          measCfmEvt->transId = measReqEvt->transId;
1046          measCfmEvt->measType = measReqEvt->measReq.measType;
1047          measCfmEvt->status.status = LCM_PRIM_NOK;
1048          measCfmEvt->status.reason = LPJ_CAUSE_INVALID_QCI;
1049          RETVALUE(RFAILED);
1050       }
1051    }
1052    
1053    
1054    RETVALUE(ROK);
1055 }/* pjUtlValidateL2Meas */
1056
1057 /**
1058 @brief 
1059 This function processes L2 Measurement requests received from the layer manager.
1060 The L2 Measurement is start for a time period and after the timer expiry, the 
1061 measurement confirm is sent.
1062
1063 -  Accept only one set of measurements.
1064 -  Allocate and initialise KwL2MeasEvtCb.
1065 -  Validate if the measurement is already in progress.
1066    -  Loop through the existing measEvtCb with matching measType
1067       -  Check if measurement is running for any qci present in the measReq
1068       -  If present, move the qCi to list of invalid qCIs.
1069 -  Set KwL2MeasEvtCb.measOn to TRUE for QCIs to be measured.
1070 -  For the number of measurements requested.
1071    -  For all Ues with RBs matching qCI.
1072       -  Add RbCb to the RB linked list.
1073       -  Set kwRbCb.measOn to measurement type.
1074       -  If Meas type is DL_DELAY
1075          -  Update COUNT to startCount.
1076 -  Start l2Timer
1077
1078  *  @param[in] pst      post structure
1079  *  @param[in] action   action 
1080  *  @param[in] cfg      LM management structure
1081  *  @return S16
1082  *      -# Success : ROK
1083  *      -# Failure : RFAILED
1084 */
1085 #ifdef ANSI
1086 PUBLIC S16 PjMiLpjL2MeasReq 
1087 (
1088 Pst            *pst, 
1089 PjL2MeasReqEvt *measReqEvt 
1090 )
1091 #else
1092 PUBLIC S16 PjMiLpjL2MeasReq (pst, measReqEvt)
1093 Pst            *pst; 
1094 PjL2MeasReqEvt *measReqEvt;
1095 #endif
1096 {
1097    S16            ret = ROK;
1098    U16             measType;
1099    PjL2MeasCfmEvt measCfmEvt;
1100    PjL2Cb   *pjL2Cb = NULLP;
1101    PjCb     *tPjCb = PJ_GET_PJCB(pst->dstInst);
1102
1103    TRC3(PjMiLpjL2MeasReq);
1104
1105    tPjCb =  PJ_GET_PJCB(pst->dstInst);
1106    
1107    measType = measReqEvt->measReq.measType;
1108    
1109    RLOG1(L_DEBUG, "L2_MEAS START Measurement type is %u\n", measType);
1110    /* Initialize measCfmEvt */
1111    memset(&measCfmEvt,0, sizeof(PjL2MeasCfmEvt));
1112
1113    ret = pjUtlValidateL2Meas(tPjCb, measReqEvt, &measCfmEvt);
1114    if(ret != ROK)
1115    {
1116       pjUtlSndUlL2MeasNCfm(tPjCb, &measCfmEvt);
1117       RETVALUE(RFAILED);
1118    }
1119
1120    RLOG1(L_DEBUG,"Measurement Start Req type is [%lu]", measType);
1121    if (measType & LPJ_L2MEAS_UL_LOSS)
1122    {
1123       U32      cntr    = 0;
1124
1125       pjL2Cb = &tPjCb->u.ulCb->pjL2Cb;
1126
1127       for(cntr = 1; cntr < LPJ_MAX_QCI; cntr++)
1128       {
1129          pjL2Cb->measOn[cntr] |= measType;
1130       }
1131    }
1132    if ((measType & LPJ_L2MEM_PERPOOL_STATS) || (measType & LPJ_L2CPU_PERCORE_STATS) )
1133    {
1134       /* starting measurement timer */
1135       ret = pjStartTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR); 
1136       if(ret == RFAILED) 
1137       {
1138          RETVALUE(ret);
1139       }  
1140    }
1141    if(measType & LPJ_L2MEM_PERPOOL_STATS)
1142    {   
1143       pjL2Cb->memUtilizationMask |= LPJ_L2MEM_PERPOOL_STATS;
1144    }
1145    if(measType & LPJ_L2CPU_PERCORE_STATS)
1146    {
1147       pjL2Cb->cpuUtilizationMask |= LPJ_L2CPU_PERCORE_STATS;
1148    }
1149    /* Use else for DL in future */
1150    RETVALUE(ret);
1151 } /* PjMiLpjL2MeasReq */
1152
1153 /**
1154 @brief 
1155 This function processes L2 Measurement stop request received from the layer manager.
1156 After receving this request, PDCP stops L2 Measurement
1157  *  @param[in] pst      post structure
1158  *  @param[in] measType meas Type 
1159  *  @return S16
1160  *      -# Success : ROK
1161  *      -# Failure : RFAILED
1162 */
1163
1164 #ifdef ANSI
1165 PUBLIC S16 PjMiLpjL2MeasStopReq
1166 (
1167 Pst            *pst,
1168 U16            measType
1169 )
1170 #else
1171 PUBLIC S16 PjMiLpjL2MeasStopReq (pst, measType)
1172 Pst            *pst;
1173 U16             measType;
1174 #endif
1175 {
1176    U16            cntr;
1177    PjCb             *tPjCb     = PJ_GET_PJCB(pst->dstInst);
1178    PjL2MeasEvtCb    *measEvtCb = NULLP;
1179    PjL2MeasCfmEvt          measCfmEvt;  
1180    TRC3(PjMiLpjL2MeasStopReq);
1181
1182
1183    RLOG1(L_DEBUG,"Meas Stop Req type is [%lu]", measType);
1184    /* For UL counters only */
1185    cmMemset((U8*)&measCfmEvt, 0, sizeof(PjL2MeasCfmEvt)); 
1186    
1187    if(measType & LPJ_L2MEM_PERPOOL_STATS || 
1188       measType & LPJ_L2CPU_PERCORE_STATS)
1189    {
1190         /* stopping timer */
1191         pjStopTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR);
1192    }
1193    if(measType & LPJ_L2MEM_PERPOOL_STATS)
1194    {   
1195       tPjCb->u.ulCb->pjL2Cb.memUtilizationMask = 0;
1196    }
1197    if(measType & LPJ_L2CPU_PERCORE_STATS)
1198    {
1199       tPjCb->u.ulCb->pjL2Cb.cpuUtilizationMask = 0;
1200    }
1201  
1202    for(cntr = 0; cntr < LPJ_MAX_L2MEAS; cntr++)
1203    {
1204       measEvtCb = &(tPjCb->u.ulCb->pjL2Cb.pjL2EvtCb[cntr]);
1205       if(measEvtCb->measCb.measType & measType)
1206       {
1207          pjUtlResetUlL2MeasCntr(tPjCb, &measEvtCb->measCb, measType);
1208       }
1209    }
1210    PjMiLpjL2MeasStopCfm(&tPjCb->pjGenCfg.lmPst, measType,LCM_PRIM_OK); 
1211    RETVALUE(ROK);
1212 }
1213
1214 \f
1215 /**
1216  *
1217  * @brief For reporting measurement.
1218  *
1219  *
1220  * @b Description
1221  *        This function is called when the l2 measurement report send request is received. 
1222  *        This function sends a consolidates the mesaurements taken during
1223  *        this time and sends the confirm .
1224  *
1225  *  @param[in] measEvtCb    Measurement Event Control Block.
1226  *
1227  *
1228  *  @return  S16
1229  *      -# ROK
1230  */
1231
1232 #ifdef ANSI
1233 PRIVATE S16 PjUtlPrepNSndL2MeasSendCfm
1234 (
1235 PjCb          *tPjCb,
1236 PjL2MeasEvtCb *measEvtCb
1237 )
1238 #else
1239 PRIVATE S16 PjUtlPrepNSndL2MeasSendCfm(tPjCb, measEvtCb)
1240 PjCb          *tPjCb;
1241 PjL2MeasEvtCb *measEvtCb;
1242 #endif
1243 {
1244    PjL2MeasCb     *measCb;
1245    PjL2MeasCfmEvt measCfmEvt;
1246    U8             qciIdx;
1247    U8             coreIdx;
1248    S16            ret;
1249    TRC3(PjUtlPrepNSndL2MeasSendCfm);
1250
1251    measCb = &measEvtCb->measCb;
1252    /* Initialize measCfmEvt */
1253    cmMemset((U8 *) &measCfmEvt, 0, sizeof(PjL2MeasCfmEvt));
1254    measCfmEvt.measType = measCb->measType;
1255    measCfmEvt.status.status = LCM_PRIM_OK;
1256    measCfmEvt.status.reason = LCM_REASON_NOT_APPL;
1257
1258    /* Filling Memory Utilzation structure */
1259    if(measCb->measType &  LPJ_L2MEM_PERPOOL_STATS)
1260    {
1261       if(tPjCb->u.ulCb->pjL2Cb.memUtilizationMask & LPJ_L2MEM_PERPOOL_STATS)
1262       {
1263          cmFillMemUtilizationMeas(&(measCfmEvt.memoryInfo),&(measCb->memInfo));
1264          cmClearMemUtilizationCounter(&(measCb->memInfo));
1265          if(FALSE == (pjChkTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR)))
1266          {
1267             /* starting measurement timer */
1268             ret = pjStartTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR); 
1269             if(ret == RFAILED) 
1270             {
1271                RETVALUE(ret);
1272             }
1273          }
1274       }
1275       else
1276       {
1277          RLOG0(L_DEBUG,"Meas Send  Req without configuring Memory meas");
1278       }
1279    }
1280    if(measCb->measType &  LPJ_L2MEAS_UL_LOSS)
1281    {
1282       /* Fill the measCfmEvt structure */
1283       for(qciIdx = 1; qciIdx < LPJ_MAX_QCI; qciIdx++)
1284       {
1285          U8 qci = measCb->qci[qciIdx];
1286          if(qci > 0)
1287          {   
1288             if(measCb->measType &  LPJ_L2MEAS_UL_LOSS)
1289             {
1290                U64 totPkts, lostPkts;
1291
1292                lostPkts = (U64)(measCb->measData[qci].ulLoss.val);
1293                totPkts = (U64)(measCb->measData[qci].ulLoss.numPkts);
1294
1295                measCfmEvt.measCfm[measCfmEvt.numQciCfm].qci = qci;
1296                measCfmEvt.measCfm[measCfmEvt.numQciCfm].ulLoss = 0;
1297                if (totPkts > 0)
1298                {
1299                   /* ul Loss  = num of Pkts lost * 10^6 / total no of pkts. */
1300                   measCfmEvt.measCfm[measCfmEvt.numQciCfm].ulLoss = (((U64)(lostPkts  * ((U64)1000000))) / totPkts);
1301
1302                   measCb->measData[qci].ulLoss.val     = 0;
1303                   measCb->measData[qci].ulLoss.numPkts = 0;
1304                }
1305             }
1306             if (measCb->measData[qci].totDrbsPerQci == 0)
1307             {
1308                measCb->qci[qciIdx] = 0;
1309             }
1310             measCfmEvt.numQciCfm++;
1311          }
1312       }
1313    }
1314    if((measCb->measType &  LPJ_L2CPU_PERCORE_STATS) &&(tPjCb->u.ulCb->pjL2Cb.cpuUtilizationMask & LPJ_L2CPU_PERCORE_STATS))
1315    {  
1316       CmCpuStatsInfo *cpuInfo = &measCb->cpuInfo;
1317       for(coreIdx = 0; (coreIdx < cpuInfo->numCores) && (coreIdx < CM_MAX_CPU_CORES); coreIdx++)
1318       {
1319          measCfmEvt.cmLteCpuInfo[coreIdx].avgCpuUtil = cpuInfo->cpuUtil[coreIdx].totCpuUtil / cpuInfo->cpuUtil[coreIdx].numSamples ;  
1320          measCfmEvt.cmLteCpuInfo[coreIdx].maxCpuUtil = cpuInfo->cpuUtil[coreIdx].maxCpuUtil ;
1321          cpuInfo->cpuUtil[coreIdx].totCpuUtil = 0;
1322          cpuInfo->cpuUtil[coreIdx].maxCpuUtil = 0; 
1323          cpuInfo->cpuUtil[coreIdx].numSamples = 0;
1324       }
1325       measCfmEvt.numCores = cpuInfo->numCores;
1326       cpuInfo->numCores = 0;
1327       if(FALSE == (pjChkTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR)))
1328       {
1329          /* starting measurement timer */
1330          ret = pjStartTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR); 
1331          if(ret == RFAILED) 
1332          {
1333             RETVALUE(ret);
1334          }
1335       }
1336    } 
1337    /* Send Measurement confirmation to layer manager */
1338    pjUtlSndUlL2MeasNCfm(tPjCb, &measCfmEvt);
1339
1340    RETVALUE(ROK);
1341 } /* PjUtlPrepNSndL2MeasSendCfm */
1342
1343 /**
1344 @brief 
1345 This function processes L2 Measurement Send request received from the layer manager.
1346 After receving this request, RLC sends L2 Measurement
1347  *  @param[in] pst      post structure
1348  *  @param[in] measType meas Type 
1349  *  @return S16
1350  *      -# Success : ROK
1351  *      -# Failure : RFAILED
1352 */
1353
1354 #ifdef ANSI
1355 PUBLIC S16 PjMiLpjL2MeasSendReq
1356 (
1357 Pst            *pst,
1358 U16            measType
1359 )
1360 #else
1361 PUBLIC S16 PjMiLpjL2MeasSendReq (pst, measType)
1362 Pst            *pst;
1363 U16            measType;
1364 #endif
1365 {
1366    TRC3(PjMiLpjL2MeasSendReq);
1367
1368    if((measType & LPJ_L2MEAS_UL_LOSS) || 
1369       (measType & LPJ_L2MEM_PERPOOL_STATS) || 
1370       (measType & LPJ_L2CPU_PERCORE_STATS))
1371    {
1372       U8             cntr;
1373       PjCb           *tPjCb     = PJ_GET_PJCB(pst->dstInst);
1374       PjL2MeasEvtCb  *measEvtCb = NULLP;
1375
1376       if((measType & LPJ_L2MEM_PERPOOL_STATS) && 
1377          (tPjCb->u.ulCb->pjL2Cb.memUtilizationMask & LPJ_L2MEM_PERPOOL_STATS))
1378       {
1379          if(TRUE == (pjChkTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR)))
1380          {
1381            /* stopping timer */
1382            pjStopTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR);
1383          }
1384       }
1385       if((measType & LPJ_L2CPU_PERCORE_STATS) && 
1386          (tPjCb->u.ulCb->pjL2Cb.cpuUtilizationMask & LPJ_L2CPU_PERCORE_STATS))
1387       {
1388          if(TRUE == (pjChkTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR)))
1389          {
1390            /* stopping timer */
1391            pjStopTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR);
1392          }
1393  
1394       }
1395       for(cntr = 0; cntr < PJ_MAX_L2MEAS_EVT; cntr++)
1396       {
1397          measEvtCb = &tPjCb->u.ulCb->pjL2Cb.pjL2EvtCb[cntr];
1398          if(measEvtCb->measCb.measType & measType)
1399          {
1400             PjUtlPrepNSndL2MeasSendCfm(tPjCb, measEvtCb);
1401          } 
1402       }
1403    }
1404    RETVALUE(ROK);
1405 }
1406 #ifdef ANSI
1407 PUBLIC Void UpdateMemInfo
1408 (
1409 PjL2Cb *tPjL2Cb
1410 )
1411 #else
1412 PUBLIC Void UpdateMemInfo(tPjL2Cb)
1413 PjL2Cb *tPjL2Cb;
1414 #endif
1415 {
1416    U8             cntr;
1417    PjL2MeasEvtCb  *measEvtCb = NULLP;
1418    for(cntr = 0; cntr < PJ_MAX_L2MEAS_EVT; cntr++)
1419    {
1420       measEvtCb = &tPjL2Cb->pjL2EvtCb[cntr];
1421       if(measEvtCb->measCb.measType & LPJ_L2MEM_PERPOOL_STATS)
1422       {
1423          /* Update Memory Info for SSI Memory */
1424          cmUpdateSsiMemInfo(&(measEvtCb->measCb.memInfo));
1425
1426 #ifdef SS_LOCKLESS_MEMORY
1427 #ifndef LTE_PAL_ENB
1428          UpdateSocMemInfo(CM_L2_MEM_UTIL_AREAIDX, &(measEvtCb->measCb.memInfo));
1429 #endif
1430 #endif
1431          break;
1432       } 
1433    }
1434 }
1435
1436 #ifdef ANSI
1437 PUBLIC S16 UpdateCpuInfo
1438 (
1439 PjL2Cb *tPjL2Cb
1440 )
1441 #else
1442 PUBLIC S16 UpdateCpuInfo(tPjL2Cb)
1443 PjL2Cb *tPjL2Cb;
1444 #endif
1445 {
1446    U8             cntr;
1447    PjL2MeasEvtCb  *measEvtCb = NULLP;
1448 #ifndef LTE_PAL_ENB
1449    for(cntr = 0; cntr < PJ_MAX_L2MEAS_EVT; cntr++)
1450    {
1451       measEvtCb = &tPjL2Cb->pjL2EvtCb[cntr];
1452       if(measEvtCb->measCb.measType & LPJ_L2CPU_PERCORE_STATS)
1453       {
1454          /* Update CpuUtilization Info */
1455          UpdateSocCpuInfo(&(measEvtCb->measCb.cpuInfo), CM_L2_CPU_UTIL);
1456          break;
1457       } 
1458    }
1459 #endif
1460    RETVALUE(ROK);
1461 }
1462
1463 #ifdef ANSI
1464 PUBLIC S16 pjUtlMemCpuHdlTmrExp 
1465 (
1466 PjCb          *tPjCb,
1467 PjL2Cb *tPjL2Cb
1468 )
1469 #else
1470 PUBLIC S16 pjUtlMemCpuHdlTmrExp(tPjCb,tPjL2Cb)
1471 PjCb   *tPjCb;
1472 PjL2Cb *tPjL2Cb;
1473 #endif
1474 {
1475    S16 ret = ROK;
1476    if(tPjCb->u.ulCb->pjL2Cb.memUtilizationMask & LPJ_L2MEM_PERPOOL_STATS)
1477    {
1478       /* calling memory Info */
1479       UpdateMemInfo(tPjL2Cb);
1480    }
1481    if(tPjCb->u.ulCb->pjL2Cb.cpuUtilizationMask & LPJ_L2CPU_PERCORE_STATS)
1482    {
1483       UpdateCpuInfo(tPjL2Cb);
1484    }
1485    /*TODO: call cpu util */
1486    /* starting measurement timer */
1487    ret = pjStartTmr(tPjCb, (PTR)tPjCb, PJ_EVT_L2_MEAS_TMR);
1488    if(ret == RFAILED) 
1489    {
1490       RETVALUE(ret);
1491    }
1492    RETVALUE(ROK);
1493 }
1494
1495
1496 #endif /* LTE_L2_MEAS */
1497 /**
1498  * @brief
1499       This function configures the PDCP data sap
1500  *
1501  *  @param[in] cfg         PDCP LM Sap structure
1502  *  @return  S16
1503  *      -# Success : LCM_REASON_NOT_APPL
1504  *      -# Failure : LCM_REASON_INVALID_SAP
1505  *                   LCM_REASON_INVALID_SAP 
1506  *                   LCM_REASON_RECONFIG_FAIL 
1507  */
1508 #ifdef ANSI
1509 PRIVATE S16 pjLmmPjuSapCfg
1510 (
1511 PjCb       *gCb,
1512 PjSapCfg   *cfg               /* SAP control block */
1513 )
1514 #else
1515 PRIVATE S16 pjLmmPjuSapCfg(gCb, cfg)
1516 PjCb       *gCb;
1517 PjSapCfg   *cfg;              /* SAP control block */
1518 #endif
1519 {
1520    PjPjuSapCb  *pjuSap;
1521    
1522    TRC2(pjLmmPjuSapCfg)
1523
1524    /* Validate config parameters */
1525    if (cfg->sapId >= PJ_MAX_PJUSAPS )
1526    {
1527       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
1528    }
1529
1530    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1531    {
1532       pjuSap = &(gCb->u.ulCb->pjuSap[cfg->sapId]);
1533    }
1534    else
1535    {
1536       pjuSap = &(gCb->u.dlCb->pjuSap[cfg->sapId]);
1537    }
1538
1539 #if (ERRCLASS & ERRCLS_INT_PAR)
1540    /* Check for reconfiguration */
1541    if(pjuSap->state  != PJ_SAP_NOT_CFG)
1542    {
1543       RLOG0(L_ERROR, "Invalid pjuSap State");
1544       RETVALUE(LCM_REASON_RECONFIG_FAIL);
1545    }
1546 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1547    
1548    /* Fill the parameters */
1549    pjuSap->pst.selector = cfg->selector;
1550    pjuSap->pst.route = cfg->route;
1551    pjuSap->pst.prior =  cfg->priority;
1552    /* pj002.201 With multicore support layer shall use the assigned region
1553       and pool from SSI */
1554 #if defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION)
1555    pjuSap->pst.region = gCb->init.region; 
1556    pjuSap->pst.pool = gCb->init.pool;
1557 #else
1558    pjuSap->pst.region = cfg->mem.region; 
1559    pjuSap->pst.pool = cfg->mem.pool;
1560 #endif
1561    pjuSap->pst.dstProcId = cfg->procId;
1562    pjuSap->pst.dstEnt = cfg->ent;
1563    pjuSap->pst.dstInst = cfg->inst;
1564    pjuSap->pst.srcProcId = gCb->init.procId;
1565    pjuSap->pst.srcEnt = gCb->init.ent;
1566    pjuSap->pst.srcInst = gCb->init.inst;
1567    pjuSap->pst.event = EVTNONE;
1568    pjuSap->spId = cfg->sapId;
1569
1570    /* make sap unbound initially */
1571    pjuSap->state = PJ_SAP_CFG;
1572
1573    RETVALUE(LCM_REASON_NOT_APPL);
1574 } /* pjLmmPjuSapCfg */
1575
1576 /**
1577  * @brief
1578       This function configures the PDCP / RLC data sap
1579  *
1580  *  @param[in] cfg         PDCP LM Sap structure
1581  *  @return  S16
1582  *      -# Success : LCM_REASON_NOT_APPL
1583  *      -# Failure : LCM_REASON_INVALID_SAP
1584  *                   LCM_REASON_INVALID_SAP 
1585  *                   LCM_REASON_RECONFIG_FAIL 
1586  */
1587 #ifdef ANSI
1588 PRIVATE S16 pjLmmKwuSapCfg
1589 (
1590 PjCb       *gCb,
1591 PjSapCfg   *cfg               /* SAP control block */
1592 )
1593 #else
1594 PRIVATE S16 pjLmmKwuSapCfg(gCb, cfg)
1595 PjCb       *gCb;
1596 PjSapCfg   *cfg;              /* SAP control block */
1597 #endif
1598 {
1599    PjKwuSapCb  *kwuSap;
1600    
1601    TRC2(pjLmmKwuSapCfg)
1602    
1603
1604    /* Validate config parameters */
1605    if (cfg->sapId >= PJ_MAX_KWUSAPS )
1606    {
1607       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
1608    }
1609
1610    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1611    {
1612       kwuSap = &(gCb->u.ulCb->kwuSap[cfg->sapId]);
1613    }
1614    else
1615    {
1616       kwuSap = &(gCb->u.dlCb->kwuSap[cfg->sapId]);
1617    }
1618
1619 #if (ERRCLASS & ERRCLS_INT_PAR)
1620    /* Check for reconfiguration */
1621    if(kwuSap->state  != PJ_SAP_NOT_CFG)
1622    {
1623       RLOG0(L_ERROR, "Invalid kwuSap State");
1624       RETVALUE(LCM_REASON_RECONFIG_FAIL);
1625    }
1626 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1627    
1628    /* Fill the parameters */
1629    kwuSap->pst.selector = cfg->selector;
1630    kwuSap->pst.route = cfg->route;
1631    kwuSap->pst.prior =  cfg->priority;
1632    /* pj002.201 With multicore support layer shall use the assigned region
1633       and pool from SSI */
1634 #if defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION)
1635    kwuSap->pst.region = gCb->init.region; 
1636    kwuSap->pst.pool = gCb->init.pool;
1637 #else
1638    kwuSap->pst.region = cfg->mem.region; 
1639    kwuSap->pst.pool = cfg->mem.pool;
1640 #endif
1641    kwuSap->pst.dstProcId = cfg->procId;
1642    kwuSap->pst.dstEnt = cfg->ent;
1643    kwuSap->pst.dstInst = cfg->inst;
1644    kwuSap->pst.srcProcId = gCb->init.procId;
1645    kwuSap->pst.srcEnt = gCb->init.ent;
1646    kwuSap->pst.srcInst = gCb->init.inst;
1647    kwuSap->pst.event = EVTNONE;
1648    kwuSap->suId = cfg->sapId;
1649
1650    /* make sap unbound initially */
1651    kwuSap->bndTmrInt = cfg->bndTmrIntvl;
1652    cmInitTimers(&kwuSap->bndTmr,PJ_MAX_KWUSAP_TMR); 
1653    kwuSap->state = PJ_SAP_CFG;
1654
1655    RETVALUE(LCM_REASON_NOT_APPL);
1656 } /* pjLmmKwuSapCfg */
1657
1658 /**
1659  * @brief
1660       This function configures the PDCP / RLC data sap
1661  *
1662  *  @param[in] cfg         PDCP LM Sap structure
1663  *  @return  S16
1664  *      -# Success : LCM_REASON_NOT_APPL
1665  *      -# Failure : LCM_REASON_INVALID_SAP
1666  *                   LCM_REASON_INVALID_SAP 
1667  *                   LCM_REASON_RECONFIG_FAIL 
1668  */
1669 #ifdef ANSI
1670 PRIVATE S16 pjLmmUdxSapCfg
1671 (
1672 PjCb       *gCb,
1673 PjSapCfg   *cfg               /* SAP control block */
1674 )
1675 #else
1676 PRIVATE S16 pjLmmUdxSapCfg(gCb, cfg)
1677 PjCb       *gCb;
1678 PjSapCfg   *cfg;              /* SAP control block */
1679 #endif
1680 {
1681
1682    TRC2(pjLmmUdxSapCfg)
1683    
1684
1685    /* Validate config parameters */
1686    if (cfg->sapId >= PJ_MAX_UDXSAPS )
1687    {
1688       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
1689    }
1690
1691    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1692    {
1693       PjUdxUlSapCb *udxSap;
1694       udxSap = (gCb->u.ulCb->udxUlSap + cfg->sapId);
1695 #if (ERRCLASS & ERRCLS_INT_PAR)
1696       /* Check for reconfiguration */
1697       if(udxSap->state  != PJ_SAP_NOT_CFG)
1698       {
1699          RLOG0(L_ERROR, "Invalid udxSap State");
1700          RETVALUE(LCM_REASON_RECONFIG_FAIL);
1701       }
1702 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1703    
1704       /* Fill the parameters */
1705       udxSap->pst.selector = cfg->selector;
1706       udxSap->pst.route = cfg->route;
1707       udxSap->pst.prior =  cfg->priority;
1708       /* pj002.201 With multicore support layer shall use the assigned region
1709          and pool from SSI */
1710 #if defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION)
1711       udxSap->pst.region = gCb->init.region; 
1712       udxSap->pst.pool = gCb->init.pool;
1713 #else
1714       udxSap->pst.region = cfg->mem.region; 
1715       udxSap->pst.pool = cfg->mem.pool;
1716 #endif
1717       udxSap->pst.dstProcId = cfg->procId;
1718       udxSap->pst.dstEnt = cfg->ent;
1719       udxSap->pst.dstInst = cfg->inst;
1720       udxSap->pst.srcProcId = gCb->init.procId;
1721       udxSap->pst.srcEnt = gCb->init.ent;
1722       udxSap->pst.srcInst = gCb->init.inst;
1723       udxSap->pst.event = EVTNONE;
1724       udxSap->suId = cfg->sapId;
1725
1726       /* make sap unbound initially */
1727       udxSap->bndTmrInt = cfg->bndTmrIntvl;
1728       cmInitTimers(&udxSap->bndTmr,PJ_MAX_UDXSAP_TMR); 
1729       udxSap->state = PJ_SAP_CFG;
1730
1731    }
1732    else
1733    {
1734       PjUdxDlSapCb *udxSap;
1735       udxSap = (gCb->u.dlCb->udxDlSap + cfg->sapId);
1736 #if (ERRCLASS & ERRCLS_INT_PAR)
1737       /* Check for reconfiguration */
1738       if(udxSap->state  != PJ_SAP_NOT_CFG)
1739       {
1740          RLOG0(L_ERROR, "Invalid udxSap State");
1741          RETVALUE(LCM_REASON_RECONFIG_FAIL);
1742       }
1743 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1744    
1745       /* Fill the parameters */
1746       udxSap->pst.selector = cfg->selector;
1747       udxSap->pst.route = cfg->route;
1748       udxSap->pst.prior =  cfg->priority;
1749       /* pj002.201 With multicore support layer shall use the assigned region
1750          and pool from SSI */
1751 #if defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION)
1752       udxSap->pst.region = gCb->init.region; 
1753       udxSap->pst.pool = gCb->init.pool;
1754 #else
1755       udxSap->pst.region = cfg->mem.region; 
1756       udxSap->pst.pool = cfg->mem.pool;
1757 #endif
1758       udxSap->pst.dstProcId = cfg->procId;
1759       udxSap->pst.dstEnt = cfg->ent;
1760       udxSap->pst.dstInst = cfg->inst;
1761       udxSap->pst.srcProcId = gCb->init.procId;
1762       udxSap->pst.srcEnt = gCb->init.ent;
1763       udxSap->pst.srcInst = gCb->init.inst;
1764       udxSap->pst.event = EVTNONE;
1765       udxSap->suId = cfg->sapId;
1766       udxSap->state = PJ_SAP_CFG;
1767    }
1768
1769    RETVALUE(LCM_REASON_NOT_APPL);
1770 } /* pjLmmUdxSapCfg */
1771
1772
1773
1774 /**
1775  * @brief
1776       This function configures the PDCP control sap
1777  *
1778  *  @param[in] cfg         PDCP LM Sap structure
1779  *  @return  S16
1780  *      -# Success : LCM_REASON_NOT_APPL
1781  *      -# Failure : LCM_REASON_INVALID_SAP
1782  *                   LCM_REASON_INVALID_SAP 
1783  *                   LCM_REASON_RECONFIG_FAIL 
1784  */
1785 #ifdef ANSI
1786 PRIVATE S16 pjLmmCpjSapCfg
1787 (
1788 PjCb       *gCb,
1789 PjSapCfg   *cfg               /* SAP control block */
1790 )
1791 #else
1792 PRIVATE S16 pjLmmCpjSapCfg(gCb,cfg)
1793 PjCb       *gCb;
1794 PjSapCfg   *cfg;              /* SAP control block */
1795 #endif
1796 {
1797    PjCpjSapCb  *cpjSap;
1798    
1799    TRC2(pjLmmCpjSapCfg)
1800
1801    /* Validate config parameters */
1802    if (cfg->sapId >= PJ_MAX_CPJSAPS )
1803    {
1804       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
1805    }
1806
1807    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1808    {
1809       cpjSap = &(gCb->u.ulCb->cpjSap);
1810    }
1811    else
1812    {
1813       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
1814    }
1815
1816 #if (ERRCLASS & ERRCLS_INT_PAR)
1817    /* Check for reconfiguration */
1818    if(cpjSap->state  != PJ_SAP_NOT_CFG)
1819    {
1820       RLOG0(L_ERROR, "Invalid cpjSap State");
1821       RETVALUE(LCM_REASON_RECONFIG_FAIL);
1822    }
1823 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1824    
1825    /* Fill the parameters */
1826    cpjSap->pst.selector = cfg->selector;
1827    cpjSap->pst.route = cfg->route;
1828    cpjSap->pst.prior =  cfg->priority;
1829    /* pj002.201 With multicore support layer shall use the assigned region
1830       and pool from SSI */
1831 #if defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION)
1832    cpjSap->pst.region = gCb->init.region; 
1833    cpjSap->pst.pool = gCb->init.pool;
1834 #else
1835    cpjSap->pst.region = cfg->mem.region; 
1836    cpjSap->pst.pool = cfg->mem.pool;
1837 #endif
1838    cpjSap->pst.dstProcId = cfg->procId;
1839    cpjSap->pst.dstEnt = cfg->ent;
1840    cpjSap->pst.dstInst = cfg->inst;
1841    cpjSap->pst.srcProcId = gCb->init.procId;
1842    cpjSap->pst.srcEnt = gCb->init.ent;
1843    cpjSap->pst.srcInst = gCb->init.inst;
1844    cpjSap->pst.event = EVTNONE;
1845    cpjSap->spId = cfg->sapId;
1846
1847    /* make sap unbound initially */
1848    cpjSap->state = PJ_SAP_CFG;
1849
1850    RETVALUE(LCM_REASON_NOT_APPL);
1851 } /* pjLmmCpjSapCfg */
1852
1853 /**
1854  * @brief
1855      Validates the PDCP general control parameters 
1856  *
1857  *  @param[in] cntrl PDCP LM structure 
1858  *  @return  S16
1859  *      -# Success : LCM_REASON_NOT_APPL
1860  *      -# Failure : LCM_REASON_INVALID_SUBACTION
1861  *                   LCM_REASON_INVALID_ACTION
1862  */
1863 #ifdef ANSI
1864 PRIVATE S16 pjLmmValidateGenCntrl
1865 (
1866 PjMngmt *cntrl                 /* PDCP LM structure */
1867 )
1868 #else
1869 PRIVATE S16 pjLmmValidateGenCntrl(cntrl)
1870 PjMngmt *cntrl;                /* PDCP LM structure */
1871 #endif
1872 {
1873    S16 reason;                 /* reason for failure */
1874    U8 action;                  /* action parameter */
1875    U8 sAction;                 /* subaction field */
1876
1877
1878    reason = LCM_REASON_NOT_APPL;
1879
1880    TRC2(pjLmmValidateGenCntrl);
1881
1882    action = cntrl->t.cntrl.action;
1883    sAction = cntrl->t.cntrl.subAction;
1884
1885    switch (action)
1886    {
1887       case AENA:
1888       case ADISIMM:
1889          if ((sAction != SAUSTA)
1890             && (sAction != SADBG)
1891             && (sAction != SATRC))
1892          {
1893             reason = LCM_REASON_INVALID_SUBACTION;
1894          }
1895          break;
1896       case ASHUTDOWN:
1897          break;
1898       default:
1899          reason = LCM_REASON_INVALID_ACTION;
1900          break;
1901    }
1902    
1903    RETVALUE(reason);
1904 } /* pjLmmValidateGenCntrl */
1905
1906 /**
1907  * @brief
1908       Delete all SAPs and Control Blocks
1909  *
1910  * @b Description
1911  *       Shutdown of PDCP happens at modules level, tm, um and am modules will
1912  *       be shutdown using utility functin and dbm shutdown will clean up the
1913  *       SAPs, control blocks and lists. 
1914  *
1915  *  @return  S16
1916  *      -# Success : LCM_REASON_NOT_APPL
1917  *      -# Failure : LCM_REASON_HASHING_FAILED 
1918  */
1919 #ifdef ANSI
1920 PRIVATE S16 pjLmmShutdown
1921 (
1922 PjCb   *gCb
1923 )
1924 #else
1925 PRIVATE S16 pjLmmShutdown(gCb)
1926 PjCb   *gCb;
1927 #endif
1928 {
1929    TRC2(pjLmmShutdown)
1930    S16 ret;
1931    /* Call PDCP DBM Cleanup function.
1932     * RLC LM shutdown takes care of cleanup of Gloabal and RLC resources */
1933    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1934    {
1935       ret = pjUtlUlShutdown(gCb);
1936     
1937 #ifdef TENB_AS_SECURITY
1938 #ifdef INTEL_QAT_DP
1939 #ifdef QAT_TWO_INSTANCE
1940       PjLibObdUlCloseReq(gCb->u.ulCb->instHndl);
1941 #else
1942       /* There is only one instance so its already freed as part of UL shutdown */
1943 #endif
1944 #else
1945       PjLibObdUlCloseReq();
1946 #endif
1947 #endif
1948    }
1949    else
1950    {
1951       ret = pjUtlDlShutdown(gCb);
1952       
1953 #ifdef TENB_AS_SECURITY
1954 #ifdef INTEL_QAT_DP
1955 #ifdef QAT_TWO_INSTANCE
1956       PjLibObdDlCloseReq(gCb->u.dlCb->instHndl);
1957 #else
1958       /* There is only one instance so its already freed as part of UL shutdown */
1959 #endif
1960 #else
1961       PjLibObdDlCloseReq();
1962 #endif
1963 #endif
1964    }
1965    pjLmmCleanGblRsrcs(gCb);
1966
1967    if(ret != ROK)
1968    {
1969       RETVALUE(ret);
1970    }
1971    else
1972    {   
1973    RETVALUE(LCM_REASON_NOT_APPL);
1974    }
1975 } /* end of pjLmmShutdown */
1976
1977 /**
1978  * @brief
1979      Function processes the general control request 
1980  *
1981  *  @param[in] cntrl PDCP LM structure
1982  *  @return  S16
1983  *      -# Success : LCM_REASON_NOT_APPL
1984  *      -# Failure : LCM_REASON_INVALID_SUBACTION
1985  *                   LCM_REASON_INVALID_ACTION
1986  */
1987 #ifdef ANSI
1988 PRIVATE S16 pjLmmGenCntrl
1989 (
1990 PjCb    *gCb,
1991 PjMngmt *cntrl                 /* PDCP LM structure */
1992 )
1993 #else
1994 PRIVATE S16 pjLmmGenCntrl(gCb,cntrl)
1995 PjCb    *gCb;
1996 PjMngmt *cntrl;                /* PDCP LM structure */
1997 #endif
1998 {
1999    U8 action;            /* action parameter */
2000    U8 sAction;           /* subaction field */
2001    PjTrcCntrl *trcCntrl; /* trace */
2002
2003 #ifdef DEBUGP
2004    PjDbgCntrl *dbgCntrl; /* debug */
2005 #endif /* DEBUGP */
2006
2007    S16   reason;         /* reason for failure */
2008    
2009    TRC2(pjLmmGenCntrl);
2010
2011    reason = LCM_REASON_NOT_APPL;
2012
2013    /* Validate control parameters */
2014    reason = pjLmmValidateGenCntrl (cntrl);
2015
2016    action = cntrl->t.cntrl.action;
2017    sAction = cntrl->t.cntrl.subAction;
2018
2019    if (reason != LCM_REASON_NOT_APPL)
2020    {
2021       RETVALUE(reason);
2022    }
2023
2024    switch(action)
2025    {
2026       case AENA:
2027       {
2028          switch(sAction)
2029          {
2030             case SAUSTA:
2031             {
2032                PJ_SET_USTA_FLAG(gCb, TRUE);
2033                break;
2034             }
2035             case SADBG:
2036             {
2037 #ifdef DEBUGP
2038                dbgCntrl = &cntrl->t.cntrl.s.dbgCntrl;
2039                PJ_GET_DBG_MASK(gCb) |= dbgCntrl->dbgMask;
2040 #endif /* DEBUGP */
2041                break;
2042             }
2043             case SATRC:
2044             {
2045                trcCntrl = &cntrl->t.cntrl.s.trcCntrl;
2046                gCb->init.trc = TRUE;
2047                gCb->trcLen = trcCntrl->trcLen;
2048                (gCb->trcMask) |= trcCntrl->trcMask;
2049                 break;
2050             }
2051          }
2052          break;
2053       }
2054       case ADISIMM:
2055       {
2056          switch(sAction)
2057          {
2058             case SAUSTA:
2059             {
2060                gCb->init.usta = FALSE;
2061             }
2062             break;
2063             case SADBG:
2064             {
2065 #ifdef DEBUGP
2066                dbgCntrl = &cntrl->t.cntrl.s.dbgCntrl;
2067                PJ_GET_DBG_MASK(gCb) &= ~(dbgCntrl->dbgMask);
2068 #endif /* DEBUGP */
2069             }
2070             break;
2071             case SATRC:
2072             {
2073                trcCntrl = &cntrl->t.cntrl.s.trcCntrl;
2074                gCb->init.trc = FALSE;
2075                gCb->trcMask &= ~(trcCntrl->trcMask);
2076             }
2077             break;
2078          }
2079          break;
2080       }
2081       case ASHUTDOWN:
2082       {
2083          reason = pjLmmShutdown(gCb);
2084          break;
2085       }
2086    }
2087    RETVALUE(reason);
2088 } /* pjLmmGenCntrl */
2089
2090 /**
2091  * @brief
2092      Bind/Unbind RLC upper sap 
2093  *
2094  *  @param[in] cntrl RLC LM structure
2095  *  @return  S16
2096  *      -# Success : LCM_REASON_NOT_APPL
2097  *      -# Failure : LCM_REASON_INVALID_SAP 
2098  *                   LCM_REASON_INVALID_STATE
2099  *                   LCM_REASON_INVALID_ACTION 
2100  */
2101 #ifdef ANSI
2102 PRIVATE S16 pjLmmUdxSapCntrl
2103 (
2104 PjCb    *gCb,
2105 PjMngmt *cntrl                 /* RLC LM structure */
2106 )
2107 #else
2108 PRIVATE S16 pjLmmUdxSapCntrl(gCb,cntrl)
2109 PjCb    *gCb;
2110 PjMngmt *cntrl;                /* RLC LM structure */
2111 #endif
2112 {
2113    U8         action;                  /* action parameter */
2114    S16        reason;                 /* reason for failure */
2115    PjUdxUlSapCb *udxSap;                /* udx sap pointer */
2116    
2117    TRC2(kwLmmUdxSapCntrl)
2118    
2119
2120    reason = LCM_REASON_NOT_APPL;
2121    action = cntrl->t.cntrl.action;
2122
2123    /* validate SuId */
2124    if((cntrl->t.cntrl.s.sapCntrl.suId < 0)
2125    || (cntrl->t.cntrl.s.sapCntrl.suId >= PJ_MAX_KWUSAPS))
2126    {
2127       reason = LCM_REASON_INVALID_SAP;
2128       RETVALUE(reason);
2129    }
2130
2131
2132    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
2133    {
2134       /*udxSap = &(gCb->u.ulCb->udxUlSap[cntrl->t.cntrl.s.sapCntrl.suId]);*/
2135       udxSap = (gCb->u.ulCb->udxUlSap + cntrl->t.cntrl.s.sapCntrl.suId);
2136    }
2137    else
2138    {
2139       reason = LCM_REASON_INVALID_SAP;
2140       RETVALUE(reason);
2141    }
2142
2143
2144 #if (ERRCLASS & ERRCLS_INT_PAR)
2145    /* validate SAP */
2146    if(udxSap->state == PJ_SAP_NOT_CFG)
2147    {
2148       RLOG0(L_ERROR, "Invalid udxSap State");
2149       reason = LCM_REASON_INVALID_STATE;
2150       RETVALUE(reason);
2151    }
2152 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2153
2154    switch(action)
2155    {
2156       case ABND:
2157       {
2158          if(udxSap->state != PJ_SAP_BND)
2159          {
2160             S16 ret;
2161             /* start timer to wait for bind confirm */
2162             ret = pjStartTmr(gCb, (PTR)udxSap, PJ_EVT_WAIT_UDX_BNDCFM); 
2163             if(ret == RFAILED) 
2164             {
2165                reason = LCM_REASON_REGTMR_FAIL; 
2166             } 
2167             else
2168             {
2169             udxSap->state = PJ_SAP_BINDING;
2170            /* udxSap->spId = cntrl->t.cntrl.s.sapCntrl.spId; */
2171             PjUlUdxBndReq(&(udxSap->pst), udxSap->suId, udxSap->spId);
2172          }
2173          }
2174          else
2175          {
2176             /* control request received for an already bound SAP */
2177             reason = LCM_REASON_INVALID_STATE;
2178          }
2179       }
2180       break;
2181       case AUBND:
2182       {
2183          /* make the state of RGUSAP is configure but not bound */
2184          udxSap->state = PJ_SAP_CFG;
2185          PjUlUdxUbndReq(&(udxSap->pst), udxSap->spId, 0);
2186       }
2187       break;
2188       default:
2189          reason = LCM_REASON_INVALID_ACTION;
2190          break;
2191    } /* end of switch */
2192
2193    RETVALUE(reason);
2194 } /* pjLmmUdxSapCntrl */
2195
2196
2197 /**
2198  * @brief
2199      Bind/Unbind RLC upper sap 
2200  *
2201  *  @param[in] cntrl RLC LM structure
2202  *  @return  S16
2203  *      -# Success : LCM_REASON_NOT_APPL
2204  *      -# Failure : LCM_REASON_INVALID_SAP 
2205  *                   LCM_REASON_INVALID_STATE
2206  *                   LCM_REASON_INVALID_ACTION 
2207  */
2208 #ifdef ANSI
2209 PRIVATE S16 pjLmmLSapCntrl
2210 (
2211 PjCb    *gCb,
2212 PjMngmt *cntrl                 /* RLC LM structure */
2213 )
2214 #else
2215 PRIVATE S16 pjLmmLSapCntrl(gCb,cntrl)
2216 PjCb    *gCb;
2217 PjMngmt *cntrl;                /* RLC LM structure */
2218 #endif
2219 {
2220    U8         action;                  /* action parameter */
2221    S16        reason;                 /* reason for failure */
2222    PjKwuSapCb *kwuSap;                /* rgu sap pointer */
2223
2224    TRC2(kwLmmLSapCntrl)
2225
2226    reason = LCM_REASON_NOT_APPL;
2227    action = cntrl->t.cntrl.action;
2228
2229    /* validate SuId */
2230    if((cntrl->t.cntrl.s.sapCntrl.suId < 0)
2231    || (cntrl->t.cntrl.s.sapCntrl.suId >= PJ_MAX_KWUSAPS))
2232    {
2233       reason = LCM_REASON_INVALID_SAP;
2234       RETVALUE(reason);
2235    }
2236
2237    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
2238    {
2239       kwuSap = &(gCb->u.ulCb->kwuSap[cntrl->t.cntrl.s.sapCntrl.suId]);
2240    }
2241    else  
2242    {
2243       kwuSap = &(gCb->u.dlCb->kwuSap[cntrl->t.cntrl.s.sapCntrl.suId]);
2244    }
2245
2246
2247 #if (ERRCLASS & ERRCLS_INT_PAR)
2248    /* validate SAP */
2249    if(kwuSap->state == PJ_SAP_NOT_CFG)
2250    {
2251       RLOG0(L_ERROR, "Invalid kwuSap State");
2252       reason = LCM_REASON_INVALID_STATE;
2253       RETVALUE(reason);
2254    }
2255 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2256
2257    switch(action)
2258    {
2259       case ABND:
2260       {
2261          if(kwuSap->state != PJ_SAP_BND)
2262          {
2263             S16 ret;
2264             /* start timer to wait for bind confirm */
2265             ret = pjStartTmr(gCb, (PTR)kwuSap, PJ_EVT_WAIT_KWU_BNDCFM);
2266             if(ret == RFAILED) 
2267             {
2268                reason = LCM_REASON_REGTMR_FAIL; 
2269             } 
2270             else
2271             {
2272             kwuSap->state = PJ_SAP_BINDING;
2273             kwuSap->spId = cntrl->t.cntrl.s.sapCntrl.spId;
2274             PjLiKwuBndReq(&(kwuSap->pst), kwuSap->suId, kwuSap->spId);
2275          }
2276          }
2277          else
2278          {
2279             /* control request received for an already bound SAP */
2280             reason = LCM_REASON_INVALID_STATE;
2281          }
2282       }
2283       break;
2284       case AUBND:
2285       {
2286          /* make the state of RGUSAP is configure but not bound */
2287          kwuSap->state = PJ_SAP_CFG;
2288          PjLiKwuUbndReq(&(kwuSap->pst), kwuSap->spId, 0);
2289       }
2290       break;
2291       default:
2292          reason = LCM_REASON_INVALID_ACTION;
2293          break;
2294    } /* end of switch */
2295
2296    RETVALUE(reason);
2297 } /* pjLmmLSapCntrl */
2298
2299
2300 /**
2301  * @brief
2302      forms Lm Cfm based on the return values 
2303  *
2304  *  @param[in] cntrl PDCP LM structure
2305  *  @return  S16
2306  *      -# Success : ROK 
2307  *      -# Failure : RFAILED
2308  */
2309 #ifdef ANSI
2310 PRIVATE S16 pjLmmFormLmCfm
2311 (
2312 Pst      *pst,
2313 Header   *hdr,
2314 Reason   reason
2315 )
2316 #else
2317 PRIVATE S16 pjLmmFormLmCfm(pst, hdr, reason)
2318 Pst      *pst;
2319 Header   *hdr;
2320 Reason   reason;
2321 #endif
2322 {
2323    PjMngmt  rCfm;
2324    S16      ret;
2325    TRC3(pjLmmFormLmCfm)
2326
2327    ret = ROK;
2328
2329    if (reason == LCM_REASON_NOT_APPL)
2330    {
2331       rCfm.cfm.status = LCM_PRIM_OK;
2332       rCfm.cfm.reason = LCM_REASON_NOT_APPL;
2333
2334       ret = ROK;
2335    }
2336    else
2337    {
2338       rCfm.cfm.status = LCM_PRIM_NOK;
2339       rCfm.cfm.reason = reason;
2340
2341       ret = RFAILED;
2342    }
2343
2344    pjLmmSendCfm(pst, &rCfm, TCNTRL, hdr);
2345
2346    RETVALUE(ret);
2347 } /* pjLmmFormLmCfm */
2348
2349 /**
2350  * @brief
2351      Function gather the general PJU SAP status 
2352  *
2353  *  @param[in] sta LM PJU Sap Status structure 
2354  *  @return  S16
2355  *      -# Success : LCM_REASON_NOT_APPL
2356  *      -# Failure : LCM_REASON_INVALID_PAR_VAL
2357  */
2358 #ifdef ANSI
2359 PRIVATE S16 pjLmmGetPjuSapSta 
2360 (
2361 PjCb        *gCb,
2362 PjPjuSapSta *sta                /* PJU SAP status */
2363 )
2364 #else
2365 PRIVATE S16 pjLmmGetPjuSapSta(gCb,sta)
2366 PjCb        *gCb;
2367 PjPjuSapSta *sta;               /* PJU SAP status */
2368 #endif
2369 {
2370    PjPjuSapCb *pjuSap;
2371    TRC2(pjLmmGetPjuSapSta);
2372
2373    /* Validate config parameters */
2374    if (sta->spId >= PJ_MAX_PJUSAPS )
2375    {
2376       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
2377    }
2378
2379    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
2380    {
2381       pjuSap = &(gCb->u.ulCb->pjuSap[sta->spId]);
2382    }
2383    else
2384    {
2385       pjuSap = &(gCb->u.dlCb->pjuSap[sta->spId]);
2386    }
2387
2388
2389    /* Get Sap control block */
2390    sta->state = pjuSap->state;
2391
2392    RETVALUE(LCM_REASON_NOT_APPL);
2393 } /* pjLmmGetPjuSapSta */
2394
2395 /**
2396  * @brief
2397      Function gather the general PJU SAP status 
2398  *
2399  *  @param[in] sta LM PJU Sap Status structure 
2400  *  @return  S16
2401  *      -# Success : LCM_REASON_NOT_APPL
2402  *      -# Failure : LCM_REASON_INVALID_PAR_VAL
2403  */
2404 #ifdef ANSI
2405 PRIVATE S16 pjLmmGetKwuSapSta 
2406 (
2407 PjCb        *gCb,
2408 PjKwuSapSta *sta                /* PJU SAP status */
2409 )
2410 #else
2411 PRIVATE S16 pjLmmGetKwuSapSta(gCb,sta)
2412 PjCb        *gCb;
2413 PjKwuSapSta *sta;               /* PJU SAP status */
2414 #endif
2415 {
2416    PjKwuSapCb *kwuSap;
2417    TRC2(pjLmmGetKwuSapSta);
2418
2419    /* Validate config parameters */
2420    if (sta->spId >= PJ_MAX_PJUSAPS )
2421    {
2422       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
2423    }
2424
2425    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
2426    {
2427       kwuSap = &(gCb->u.ulCb->kwuSap[sta->spId]);
2428    }
2429    else
2430    {
2431       kwuSap = &(gCb->u.dlCb->kwuSap[sta->spId]);
2432    }
2433
2434    /* Get Sap control block */
2435    sta->state = kwuSap->state;
2436
2437    RETVALUE(LCM_REASON_NOT_APPL);
2438 } /* pjLmmGetKwuSapSta */
2439
2440 /**
2441  * @brief
2442      Function gather the general PJU SAP status 
2443  *
2444  *  @param[in] sta LM PJU Sap Status structure 
2445  *  @return  S16
2446  *      -# Success : LCM_REASON_NOT_APPL
2447  *      -# Failure : LCM_REASON_INVALID_PAR_VAL
2448  */
2449 #ifdef ANSI
2450 PRIVATE S16 pjLmmGetUdxSapSta 
2451 (
2452 PjCb        *gCb,
2453 PjUdxSapSta *sta                /* PJU SAP status */
2454 )
2455 #else
2456 PRIVATE S16 pjLmmGetUdxSapSta(gCb,sta)
2457 PjCb        *gCb;
2458 PjUdxSapSta *sta;               /* PJU SAP status */
2459 #endif
2460 {
2461    PjUdxUlSapCb *udxUlSap;   
2462    PjUdxDlSapCb *udxDlSap;   
2463    TRC2(pjLmmGetUdxSapSta);
2464
2465    /* Validate config parameters */
2466    if (sta->spId >= PJ_MAX_UDXSAPS )   /* KW_FIX */
2467    {
2468       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
2469    }
2470
2471    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
2472    {
2473       udxUlSap = &(gCb->u.ulCb->udxUlSap[sta->spId]);
2474       /* Get Sap control block */
2475       sta->state = udxUlSap->state;
2476    }
2477    else
2478    {
2479       udxDlSap = &(gCb->u.dlCb->udxDlSap[sta->spId]);
2480       /* Get Sap control block */
2481       sta->state = udxDlSap->state;
2482    }
2483
2484
2485    RETVALUE(LCM_REASON_NOT_APPL);
2486 } /* pjLmmGetKwuSapSta */
2487
2488
2489 /**
2490  * @brief
2491      Function gather the general CPJ SAP status
2492  *
2493  *  @param[in] sta LM CPJ Sap Status structure
2494  *  @return  S16
2495  *      -# Success : LCM_REASON_NOT_APPL
2496  *      -# Failure : LCM_REASON_INVALID_PAR_VAL
2497  */
2498 #ifdef ANSI
2499 PRIVATE S16 pjLmmGetCpjSapSta
2500 (
2501 PjCb        *gCb,
2502 PjCpjSapSta *sta              /* RLU SAP status */
2503 )
2504 #else
2505 PRIVATE S16 pjLmmGetCpjSapSta(sta)
2506 PjCb        *gCb;
2507 PjCpjSapSta *sta;             /* RLU SAP status */
2508 #endif
2509 {
2510    PjCpjSapCb *cpjSap;
2511    TRC2(pjLmmGetCpjSapSta);
2512
2513    if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
2514    {
2515       cpjSap = &(gCb->u.ulCb->cpjSap);
2516    }
2517    else
2518    {
2519       RETVALUE(LCM_REASON_INVALID_SAP);
2520    }
2521
2522
2523    sta->state = cpjSap->state;
2524
2525    RETVALUE(LCM_REASON_NOT_APPL);
2526
2527 } /* pjLmmGetCpjSapSta */
2528
2529 /**
2530  * @brief
2531      Gather the general statistics 
2532  *
2533  *  @param[in] sts       LM general statistics structure
2534  *  @param[in] action    action
2535  *  @return  S16
2536  *      -# Success : LCM_REASON_NOT_APPL
2537  *      -# Failure : LCM_REASON_INVALID_PAR_VAL
2538  */
2539 #ifdef ANSI
2540 PRIVATE S16 pjLmmGetGenSts
2541 (
2542 PjCb     *gCb,
2543 PjGenSts *sts,              /* general statistics structure */
2544 Action action               /* Action */
2545 )
2546 #else
2547 PRIVATE S16 pjLmmGetGenSts(gCb, sts, action)
2548 PjCb     *gCb;
2549 PjGenSts *sts;              /* general statistics structure */
2550 Action action;              /* Action */
2551 #endif
2552 {
2553    PjGenSts *genSts;        /* General statistics */
2554
2555    TRC2(pjLmmGetGenSts);
2556
2557    /* Validate protocol parameters */
2558    if ((action != LPJ_ZEROSTS) && (action != LPJ_NOZEROSTS))
2559    {
2560       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
2561    }
2562
2563    PJ_MEM_CPY (sts, &(gCb->pjGenSts), sizeof (PjGenSts));
2564    
2565    if(action == LPJ_ZEROSTS)
2566    {
2567       genSts = &(gCb->pjGenSts);
2568       PJ_MEM_SET (genSts, 0, sizeof (PjGenSts));
2569    }
2570
2571    RETVALUE(LCM_REASON_NOT_APPL);
2572 } /* pjLmmGetGenSts */
2573
2574 /**
2575  * @brief
2576      Gather the SAP statistics
2577  *
2578  *  @param[in] sts     LM general statistics structure
2579  *  @param[in] elmnt   element 
2580  *  @param[in] action  action 
2581  *  @return  S16
2582  *      -# Success : LCM_REASON_NOT_APPL
2583  *      -# Failure : LCM_REASON_INVALID_PAR_VAL
2584  */
2585 #ifdef ANSI
2586 PRIVATE S16 pjLmmGetSapSts
2587 (
2588 PjCb    *gCb,
2589 PjMngmt *sts,               /* PDCP layer management */
2590 Elmnt elmnt,                /* element */
2591 Action action               /* Action */
2592 )
2593 #else
2594 PRIVATE S16 pjLmmGetSapSts(gCb, sts, elmnt, action)
2595 PjCb    *gCb;
2596 PjMngmt *sts;               /* PDCP layer management */
2597 Elmnt elmnt;                /* element */
2598 Action action;              /* Action */
2599 #endif
2600 {
2601    PjPjuSapCb   *pjuSapCb;      /* PDCP User SAP control block */
2602    PjPjuSts     *pjuSap;        /* place holder for SAP statistics */
2603
2604    TRC2(pjLmmGetSapSts);
2605
2606    /* Validate protocol parameters */
2607    if (action != LPJ_ZEROSTS && action != LPJ_NOZEROSTS)
2608    {
2609       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
2610    }
2611
2612    pjuSap = &sts->t.sts.s.pjuSap;
2613
2614    /* Get Sap control block */
2615    /* pj005.201, modified suId to spId */
2616    
2617    pjuSapCb = (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_DL)?               
2618        (PjPjuSapCb*)(gCb->u.dlCb->pjuSap + pjuSap->spId):          
2619        (PjPjuSapCb*)(gCb->u.ulCb->pjuSap + pjuSap->spId);          
2620
2621
2622    pjuSap->rxSdus = pjuSapCb->sts.rxSdus;
2623    pjuSap->txSdus = pjuSapCb->sts.txSdus;
2624
2625    if (action == LPJ_ZEROSTS)
2626    {
2627       PJ_MEM_SET (&pjuSapCb->sts, 0, sizeof (PjPjuSts));
2628    }
2629
2630    SGetDateTime(&sts->t.sts.dt);
2631
2632    RETVALUE(LCM_REASON_NOT_APPL);
2633 } /* pjLmmGetSapSts */
2634
2635
2636 /**
2637  * @brief
2638     This function sends Unsolicited Status Indication to the Layer Management
2639     Entity. 
2640  *
2641  *  @param[in] category  Category 
2642  *  @param[in] event     event
2643  *  @param[in] cause     cause
2644  *  @param[in] cause     ueId 
2645  *  @return  Void
2646  */
2647 /* pj005.201 added support for L2 Measurement */
2648 #ifdef LTE_L2_MEAS
2649 #ifdef ANSI
2650 PUBLIC Void pjLmmSendAlarm
2651 (
2652 PjCb     *gCb,
2653 U16      category,  /* Category */
2654 U16      event,     /* Alarm event */
2655 U16      cause,     /* Alarm cause */
2656 SuId     suId,      /* suId */
2657 U32      ueId,      /* ueId */
2658 U8       qci        /* qci */
2659 )
2660 #else
2661 PUBLIC Void pjLmmSendAlarm(gCb, category, event, cause, suId, ueId, qci)
2662 PjCb     *gCb;
2663 U16      category;  /* Category */
2664 U16      event;     /* Alarm event */
2665 U16      cause;     /* Alarm cause */
2666 SuId     suId;      /* suId */
2667 U32      ueId;      /* ueId */
2668 U8       qci;       /* qci */
2669 #endif
2670 #else
2671 #ifdef ANSI
2672 PUBLIC Void pjLmmSendAlarm
2673 (
2674 PjCb     *gCb,
2675 U16      category,  /* Category */
2676 U16      event,     /* Alarm event */
2677 U16      cause,     /* Alarm cause */
2678 SuId     suId,      /* suId */
2679 U32      ueId       /* ueId */
2680 )
2681 #else
2682 PUBLIC Void pjLmmSendAlarm(gCb, category, event, cause, suId, ueId)
2683 PjCb     *gCb;
2684 U16      category;  /* Category */
2685 U16      event;     /* Alarm event */
2686 U16      cause;     /* Alarm cause */
2687 SuId     suId;      /* suId */
2688 U32      ueId;      /* ueId */
2689 #endif
2690 #endif
2691 {
2692
2693    PjMngmt usta;    /* Rlc Management Structure */
2694
2695    TRC2(pjLmmSendAlarm);
2696
2697    if(gCb->init.usta == FALSE)
2698    {
2699       RETVOID;
2700    }
2701
2702    /* initialize the management structure */
2703    PJ_MEM_SET(&usta, 0, sizeof(PjMngmt));
2704
2705    usta.hdr.elmId.elmnt = STGEN;
2706    usta.hdr.entId.ent = gCb->init.ent;
2707    usta.hdr.entId.inst = gCb->init.inst;
2708
2709    /* fill in the event and category */
2710    usta.t.usta.alarm.category = category;
2711    usta.t.usta.alarm.event = event;
2712    usta.t.usta.alarm.cause = cause;
2713
2714    /* set the suId and ueId */
2715    usta.t.usta.ueId = ueId;
2716    usta.t.usta.suId = suId;
2717    /* pj005.201 added support for L2 Measurement */
2718 #ifdef LTE_L2_MEAS
2719    if(event == LPJ_EVT_MEAS_HALT)
2720    {
2721       usta.t.usta.qci = qci;
2722    }
2723 #endif
2724
2725    /* update the date and time */
2726    (Void) SGetDateTime(&usta.t.usta.alarm.dt);
2727
2728    PjMiLpjStaInd(&(gCb->init.lmPst), &usta);
2729
2730    RETVOID;
2731
2732 } /* pjLmmSendAlarm */
2733
2734 /**
2735  * @brief
2736     This function sends trace indication to LM 
2737  *
2738  *  @param[in] event    event
2739  *  @param[in] mBuf     meessage buffer
2740  *  @return S16
2741  *      -# Success : ROK 
2742  *      -# Failure : RFAILED 
2743  */
2744 #ifdef ANSI
2745 PUBLIC S16 pjLmmSendTrc
2746 (
2747 PjCb  *gCb,
2748 Event event,                 /* event */
2749 Buffer *mBuf                 /* message buffer */
2750 )
2751 #else
2752 PUBLIC S16 pjLmmSendTrc(gCb, event, mBuf)
2753 PjCb  *gCb;
2754 Event event;                 /* event */
2755 Buffer *mBuf;                /* message buffer */
2756 #endif
2757 {
2758    /* patch pj004.201 Corrected pjLmmSendTrc function definition */
2759    PjMngmt trc;              /* PDCP management control block */
2760    Buffer   *dstMbuf;   
2761    MsgLen   bufLen;
2762    Data     *tempBuf;
2763    MsgLen   tempCnt;
2764    Pst      pst;
2765
2766    TRC2(pjLmmSendTrc);
2767
2768    PJ_MEM_SET(&trc, 0, sizeof(PjMngmt));
2769
2770    cmMemset((U8 *)&trc, 0, sizeof(PjMngmt));
2771
2772    pst = gCb->init.lmPst;
2773
2774    trc.t.trc.event = event;
2775    SGetDateTime(&trc.t.trc.dt);
2776    trc.cfm.status = LCM_PRIM_OK;
2777    trc.cfm.reason = LCM_REASON_NOT_APPL;
2778     
2779    if(mBuf != NULLP)
2780    {
2781      /* Check if the whole buffer is to be sent in Trace indication */
2782      if(gCb->trcLen == LPJ_FULL_TRACE)
2783      {
2784         if (SCpyMsgMsg(mBuf, pst.region, pst.pool, &dstMbuf)
2785             != ROK)
2786         {
2787            /* rg005.201 removed SPutSBuf on error */
2788            RLOG0(L_DEBUG,"SCpyMsgMsg Failed.");
2789            RETVALUE(RFAILED);
2790         }
2791         /* Send Trace Indication to Layer manager */
2792         PjMiLpjTrcInd(&pst, &trc, dstMbuf);
2793      }
2794      /* check if only a specified number of bytes are to be sent */
2795      else if(gCb->trcLen > 0)
2796      {
2797         /* Get the length of the recvd message buffer */
2798         if (SFndLenMsg(mBuf, &bufLen) != ROK)
2799         {
2800            RLOG0(L_DEBUG, "SFndLenMsg Failed.");
2801            RETVALUE(RFAILED);
2802         }
2803         /* Check if the recvd buffer size is less than request trace len */
2804         if(bufLen < gCb->trcLen)
2805         {
2806            /* Copy the whole of the recvd buffer in trace indication */
2807       
2808            if (SCpyMsgMsg(mBuf, pst.region, pst.pool, &dstMbuf)
2809               != ROK)
2810            {
2811               RLOG0(L_DEBUG, "pjLmmSendTrc(): SCpyMsgMsg Failed.");
2812               RETVALUE(RFAILED);
2813            }
2814          
2815            /* Send Trace Indication to Layer manager */
2816            PjMiLpjTrcInd(&pst, &trc, dstMbuf);
2817         }
2818         /* if the recvd buffer size is greater than request trace len */
2819         if(bufLen >= gCb->trcLen)
2820         {
2821            /* Get a temporary buffer to store the msg */
2822            PJ_ALLOC(gCb, tempBuf, gCb->trcLen);
2823
2824 #if (ERRCLASS & ERRCLS_INT_PAR)
2825            if(tempBuf == NULLP)
2826            {
2827               (Void) SPutSMem(PJ_GET_MEM_REGION(gCb), PJ_GET_MEM_POOL(gCb));
2828                RLOG0(L_FATAL, "Memory Allocation failed.");
2829                RETVALUE(LCM_REASON_MEM_NOAVAIL);
2830            }
2831 #endif /* ERRCLASS & ERRCLS_INT_PAR */
2832          
2833            /* Copy trcLen nos of bytes from the recvd message */
2834            if (SCpyMsgFix(mBuf,0,gCb->trcLen,tempBuf,&tempCnt) != ROK)   
2835            {
2836               RLOG0(L_DEBUG, "SCpyMsgFix Failed.");
2837               RETVALUE(RFAILED);
2838            }
2839
2840            if (SGetMsg(pst.region, pst.pool, &dstMbuf) != ROK)
2841            {
2842               RLOG0(L_FATAL, "Memory Allocation failed.");
2843               RETVALUE(RFAILED);
2844            }
2845            /* Copy the tempBuf data to dst mBuf */
2846            if (SCpyFixMsg(tempBuf,dstMbuf,0,gCb->trcLen,&tempCnt) != ROK)
2847            {
2848               RLOG0(L_DEBUG, "SCpyFixMsg Failed.");
2849               RETVALUE(RFAILED);
2850            }
2851   
2852            /* Free the memory allocated for tempBuf */
2853            PJ_FREE(gCb, tempBuf, gCb->trcLen);
2854            /* Send Trace Indication to Layer manager */
2855            PjMiLpjTrcInd(&pst, &trc, dstMbuf);
2856         }
2857      }
2858    }
2859    else
2860    {
2861       PjMiLpjTrcInd(&pst, &trc, mBuf);
2862    }
2863
2864    RETVALUE(ROK);
2865
2866 } /* end of pjLmmSendTrc */
2867
2868 \f
2869 /*
2870 *
2871 *       Fun:   Activate Task - timer
2872 *
2873 *       Desc:  Invoked by system services to activate a task with
2874 *              a timer tick.
2875 *
2876 *       Ret:   ROK      - ok
2877 *
2878 *       Notes: None
2879 *
2880 *       File:  gp_lmm.c
2881 *
2882 */
2883 #ifdef ANSI
2884 PUBLIC S16 pjActvTmr
2885 (
2886 Ent     ent,
2887 Inst    inst
2888 )
2889 #else
2890 PUBLIC S16 pjActvTmr(ent,inst)
2891 Ent     ent;
2892 Inst    inst;
2893 #endif
2894 {
2895    PjCb  *gCb; 
2896    TRC2(pjActvTmr)
2897
2898    if (inst >= PJ_MAX_PDCP_INSTANCES) 
2899    {
2900       RETVALUE (RFAILED);
2901    }
2902    gCb = PJ_GET_PJCB(inst); 
2903    cmPrcTmr(&(gCb->pjTqCp), gCb->pjTq, (PFV) pjTmrExpiry);
2904
2905    RETVALUE(ROK);
2906
2907 } /* end of pjActvTmr */
2908
2909 /**
2910  * @brief
2911  it deregisters the timers and deregisters the kwuSap Control blocks
2912  *
2913  *  @return  Void
2914  */
2915 #ifdef ANSI
2916 PRIVATE Void pjLmmCleanGblRsrcs
2917 (
2918 PjCb *gCb
2919 )
2920 #else
2921 PRIVATE Void pjLmmCleanGblRsrcs(gCb)
2922 PjCb *gCb;
2923 #endif
2924 {
2925
2926     TRC2(pjLmmCleanGblRsrcs)
2927
2928         if (gCb->init.cfgDone)
2929         {
2930             /* Deregister the timers */
2931             (Void) SDeregTmrMt(gCb->init.ent, gCb->init.inst,
2932                     (S16)gCb->pjGenCfg.timeRes, pjActvTmr);
2933             /*(Void) SDeregTmr(gCb->init.ent, gCb->init.inst,
2934               (S16)gCb->genCfg.timeRes, kwActvTmr);*/
2935
2936             if (gCb->pjGenCfg.mode == LPJ_MODE_PDCP_DL)
2937             {
2938                 if (gCb->u.dlCb)
2939                 {
2940                     if (gCb->u.dlCb->kwuSap != (PjKwuSapCb *)NULLP)
2941                     {
2942                         /*PJ_FREE(gCb,gCb->u.dlCb->kwuSap, kwSapSize); */
2943                     }
2944
2945                     PJ_FREE(gCb,gCb->u.dlCb, sizeof (PjDlgCb));
2946                 }
2947
2948             }
2949             else
2950             {
2951                 if (gCb->u.ulCb)
2952                 {
2953                     if (gCb->u.ulCb->kwuSap != (PjKwuSapCb *)NULLP)
2954                     {
2955                         /*PJ_FREE(gCb,gCb->u.ulCb->kwuSap, kwSapSize);*/
2956                     }
2957
2958                     PJ_FREE(gCb,gCb->u.ulCb, sizeof (PjUlgCb));
2959                 }
2960             }
2961
2962             (Void) SPutSMem(gCb->init.region, gCb->init.pool);
2963             gCb->init.cfgDone = FALSE;
2964             gCb->init.acnt = FALSE;
2965             gCb->init.trc = FALSE;
2966             gCb->init.usta = FALSE;
2967         }
2968     
2969     RETVOID;
2970 } /* pjLmmCleanGblRsrcs */
2971
2972 /********************************************************************30**
2973
2974          End of file
2975 **********************************************************************/