Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_ul_utl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /**********************************************************************
20
21      Name:     LTE-PDCP Layer 
22   
23      Type:     C file
24   
25      Desc:     Source code for PDCP Utility Module
26
27                This file contains following functions:
28
29                   --PjLibObdCmpCfm
30                   --PjLibObdIntProtCfm
31                   --PjLibObdCipherCfm
32                   --PjLibObdDecipherCfm
33                   --PjLibObdIntVerCfm
34                   --PjLibObdDecmpCfm
35                   -- pjUtlCmpReq
36                   -- pjUtlCipherReq
37                   -- pjUtlIntProtReq
38   
39      File:     pj_ul_utl.c
40
41 **********************************************************************/
42 static const char* RLOG_MODULE_NAME="PDCP";
43 static int RLOG_FILE_ID=251;
44 static int RLOG_MODULE_ID=1024;
45
46 /** @file gp_pj_utl.c
47 @brief PDCP Utility Module 
48 */
49
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 "cpj.h"                /* CPJ defines */
64 #include "pju.h"                /* PJU defines */
65 #include "lpj.h"                /* LPJ defines */
66
67 #include "pj_env.h"        /* RLC environment options */
68 #include "pj.h"            /* RLC defines */
69 #include "pj_ul.h"
70 #include "pj_dl.h"
71 #include "pj_err.h"        /* Error defines */
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 "cpj.x"                /* CPJ */
85 #include "pju.x"                /* PJU */
86 #include "lpj.x"                /* LPJ */
87 #include "pj.x"
88 #include "pj_udx.h"          /* LIB */
89 #include "pj_udx.x"          /* LIB */
90 #include "pj_ul.x"
91 #include "pj_dl.x"
92 #include "pj_lib.x"          /* LIB */
93
94 #ifdef __cplusplus
95 EXTERN "C" {
96 #endif /* __cplusplus */
97
98 PRIVATE S16 pjUtlUlHdlSecInitCfm ARGS((PjCb *gCb,PjUlUeCb *ueCb, 
99               U16 txIdx,PjAsyncCfm *asyncCfm, CpjSecCfgCfmInfo *secCfgCfm,CpjReEstCfmInfo *reEstCfm));
100 PRIVATE S16 pjUtlUlHdlCmpInitCfm ARGS((PjCb *gCb,PjUlUeCb *ueCb, 
101               U16 txIdx,PjAsyncCfm *asyncCfm, CpjCfgCfmInfo *cfgCfm));
102 #ifdef INTEL_SW_SEC
103 EXTERN S16 PjLibObdSwDecipherReq(PjLibTrans *libTrans, Buffer *mBuf, PjCb *gCb, Buffer **opSdu);
104 #endif
105 /********************************************************************
106  *    Utility Handler for Sending to Offboarding unit               *
107  *******************************************************************/
108 \f
109 /**
110  *
111  * @brief 
112  *
113  *        Handler for opening the context with the compression unit (either 
114  *        synchronous or asynchronous) for RB within an UE.
115  *
116  * @b Description:
117  *
118  *        This function opens the context with the compression unit per RB per
119  *        UE, by sending ROHC configuration elements using synchronous / asynchronous 
120  *        function calls with relevant input parameters.
121  *
122  *
123  *  @param[in]  pjRbCb   PDCP RbCb
124  *
125  *  @return  S16
126  *      -# ROK 
127  *
128  */
129 #ifdef ANSI
130 PUBLIC S16 pjUtlUlCmpInit
131 (
132 PjCb       *gCb,
133 PjUlRbCb   *pjRbCb                  /* PDCP RbCb */
134 )
135 #else
136 PUBLIC S16 pjUtlUlCmpInit(pjRbCb)
137 PjCb       *gCb;
138 PjUlRbCb   *pjRbCb;                 /* PDCP RbCb */
139 #endif
140 {
141    TRC3(pjUtlUlCmpInit)
142
143    RLOG2(L_DEBUG, "pjUtlUlCmpInit(pjRbCb(%d,%d))",
144                     pjRbCb->rbId, pjRbCb->rbType);
145 #ifdef PJ_CMP_ASYNC
146
147    pjRbCb->ueCb->libInfo.tCmpInitBitMask |= (1 << (pjRbCb->rbId - 1));
148    pjRbCb->ueCb->libInfo.tLibInitBitMask |= PJ_LIB_COMP_BIT_MASK;
149    pjRbCb->cmpCxt.cfgTxId  =  pjRbCb->ueCb->libInfo.nxtAvlbTxId;
150
151    PjLibObdCmpInitReq(&gCb->pjGenCfg.obdPst.cmpPst, 
152                                     pjRbCb->cmpCxt, pjRbCb->rohc);
153 #else
154    pjLibCmpInitReq(pjRbCb->cmpCxt, pjRbCb->rohc, &(pjRbCb->cmpCxtId));
155 #endif  /* PJ_CMP_ASYNC */
156
157    RETVALUE(ROK);
158
159 } /* end of pjUtlCmpInit */
160 \f
161
162
163 /**
164  *
165  * @brief 
166  *
167  *        Handler for opening the context with the Integration unit (either 
168  *        synchronous or asynchronous) for all SRBs of an UE.
169  *
170  * @b Description:
171  *
172  *        This function opens the context with the security algo unit per UE
173  *        for Integration protection/verification by sending the configured
174  *        Integrity Info using synchronous / asynchronous function calls with 
175  *        relevant input parameters.
176  *
177  *  @param[in]  pjRbCb     Pointer to RB control Block
178  *
179  *
180  *  @return  S16
181  *      -# ROK 
182  *
183  */
184 #ifdef ANSI
185 PUBLIC S16 pjUtlUlIntInit
186 (
187 PjCb     *gCb,
188 PjUlUeCb   *ueCb                   /* UE CB Ptr */
189 )
190 #else
191 PUBLIC S16 pjUtlUlIntInit(ueCb)
192 PjCb     *gCb;
193 PjUlUeCb   *ueCb;                   /* UE CB Ptr */
194 #endif
195 {
196
197 #ifndef PJ_SEC_ASYNC
198    Void *ctxId = NULL;   /* KW_FIX */
199 #else
200    U8  txIdx;
201    U32 *libInitBitMask = NULLP;
202 #endif
203    S32 ret=ROK;
204
205    TRC3(pjUtlUlIntInit)
206
207    RLOG2(L_DEBUG, "pjUtlUlIntInit(ueCb(%d,%d))",
208                     ueCb->key.ueId, ueCb->key.cellId);
209
210 #ifdef PJ_SEC_ASYNC
211
212    if(ueCb->libInfo.state == PJ_STATE_REEST)
213    {
214       for(txIdx = 0; txIdx < PJ_MAX_ASYNC_CFM; txIdx++)
215       {
216          if((ueCb->libInfo.asyncCfm[txIdx] != NULLP) &&
217                (ueCb->libInfo.asyncCfm[txIdx]->cfmType == PJ_REEST_ASYNC_CFM))
218          {
219             libInitBitMask =  &ueCb->libInfo.asyncCfm[txIdx]->libInitBitMask;
220             break;
221          }
222       }
223    }
224    else if(ueCb->libInfo.state == PJ_STATE_NORMAL)
225    {
226       libInitBitMask =  &ueCb->libInfo.tLibInitBitMask;
227    }
228
229    if(libInitBitMask)
230    {
231       (*libInitBitMask) = (*libInitBitMask) | PJ_LIB_INT_BIT_MASK;
232    }
233
234    ret = PjLibObdIntInitReq(&gCb->pjGenCfg.obdPst.secPst, 
235                            ueCb->secInfo.secCxt, ueCb->secInfo.intInfo);
236 #else
237 #ifdef INTEL_QAT_DP
238 #ifdef QAT_TWO_INSTNACES
239    pjLibIntInitReq(gCb->u.ulCb->instHndl, ueCb->secInfo.intInfo,&ctxId);
240 #else
241    pjLibIntInitReq(gCb, ueCb->secInfo.intInfo,&ctxId);
242 #endif
243    ueCb->secInfo.cpIntSessCxtId =  ctxId;
244 #else
245    pjLibIntInitReq(ueCb->secInfo.secCxt, ueCb->secInfo.intInfo,&(ctxId));
246    ueCb->secInfo.intCxtId    =  ctxId;
247 #endif   
248 #endif /* PJ_SEC_ASYNC */
249
250    RETVALUE(ret);
251
252 } /* end of pjUtlIntInit */
253 \f
254 /**
255  *
256  * @brief 
257  *
258  *        Handler for opening the context with the Ciphering unit (either 
259  *        synchronous or asynchronous) for SRBs of an UE.
260  *
261  * @b Description:
262  *
263  *        This function opens the context with the security algo unit per UE
264  *        for ciphering / deciphering by key by sending the configured
265  *        Ciphering Info with control plane key using synchronous / asynchronous 
266  *        function calls with relevant input parameters.
267  *
268  *  @param[in]  pjRbCb     Pointer to RB control Block
269  *
270  *  @return  S16
271  *      -# ROK 
272  *
273  */
274 #ifdef ANSI
275 PUBLIC S16 pjUtlUlCpInit
276 (
277 PjCb     *gCb,
278 PjUlUeCb   *ueCb                    /* UE CB Ptr */
279 )
280 #else
281 PUBLIC S16 pjUtlUlCpInit(ueCb)
282 PjCb     *gCb;
283 PjUlUeCb   *ueCb;                   /* UE CB Ptr */
284 #endif
285 {
286
287 #ifndef PJ_SEC_ASYNC
288    Void *ctxId = NULL;       /* KW_FIX */
289 #else
290    U8  txIdx;
291    U32 *libInitBitMask = NULLP;
292 #endif
293    S16   ret = ROK;
294
295    TRC3(pjUtlUlCpInit)
296
297    RLOG2(L_DEBUG, "pjUtlCpInit(ueCb(%d,%d))",
298                     ueCb->key.ueId, ueCb->key.cellId);
299
300 #ifdef PJ_SEC_ASYNC
301
302    if(ueCb->libInfo.state == PJ_STATE_REEST)
303    {
304       for(txIdx = 0; txIdx < PJ_MAX_ASYNC_CFM; txIdx++)
305       {
306          if((ueCb->libInfo.asyncCfm[txIdx] != NULLP) &&
307                (ueCb->libInfo.asyncCfm[txIdx]->cfmType == PJ_REEST_ASYNC_CFM))
308          {
309             libInitBitMask =  &ueCb->libInfo.asyncCfm[txIdx]->libInitBitMask;
310             break;
311          }
312       }
313    }
314    else if(ueCb->libInfo.state == PJ_STATE_NORMAL)
315    {
316       libInitBitMask =  &ueCb->libInfo.tLibInitBitMask;
317    }
318
319    if(libInitBitMask)
320    {
321       (*libInitBitMask) = (*libInitBitMask) | PJ_LIB_CP_CIP_BIT_MASK;
322    }
323    ret = PjLibObdCpInitReq(&gCb->pjGenCfg.obdPst.secPst, ueCb->secInfo.secCxt, 
324          ueCb->secInfo.cipherInfo.algoType, ueCb->secInfo.cipherInfo.cpKey);
325 #else
326 #ifdef INTEL_QAT_DP
327 #ifdef QAT_TWO_INSTANCE
328    ret = pjLibCpInitReq(gCb->u.ulCb->instHndl, ueCb->secInfo.secCxt, ueCb->secInfo.cipherInfo.algoType,
329                   ueCb->secInfo.cipherInfo.cpKey, &ctxId);
330 #else
331    ret = pjLibCpInitReq(gCb, ueCb->secInfo.secCxt, ueCb->secInfo.cipherInfo.algoType,
332                   ueCb->secInfo.cipherInfo.cpKey, &ctxId);
333 #endif
334    ueCb->secInfo.cpCiphSessCxtId = ctxId;
335 #else
336    ret = pjLibCpInitReq(ueCb->secInfo.secCxt, (U8)ueCb->secInfo.cipherInfo.algoType,
337                   ueCb->secInfo.cipherInfo.cpKey, &ctxId);  /*KW_FIX*/
338    ueCb->secInfo.cpCxtId = ctxId;
339 #endif /* INTEL_QAT_DP */
340 #endif /* PJ_SEC_ASYNC */
341
342    RETVALUE(ret);
343
344 } /* end of pjUtlCpInit */
345
346 /**
347  *
348  * @brief 
349  *
350  *        Handler for opening the context with the Ciphering unit (either 
351  *        synchronous or asynchronous) for DRBs of an UE.
352  *
353  * @b Description:
354  *
355  *        This function opens the context with the security algo unit per UE
356  *        for ciphering / deciphering by sending the configured
357  *        Ciphering Info with user plane key using synchronous / asynchronous 
358  *        function calls with relevant input parameters.
359  *
360  *  @param[in]  pjRbCb     Pointer to RB control Block
361  *
362  *  @return  S16
363  *      -# ROK 
364  *
365  */
366 #ifdef ANSI
367 PUBLIC S16 pjUtlUlUpInit
368 (
369 PjCb     *gCb,
370 PjUlUeCb   *ueCb                    /* UE CB Ptr */
371 )
372 #else
373 PUBLIC S16 pjUtlUpInit(gCb,ueCb)
374 PjCb     *gCb;
375 PjUlUeCb   *ueCb;                   /* UE CB Ptr */
376 #endif
377 {
378
379 #ifndef PJ_SEC_ASYNC
380    Void* ctxId = NULL;  /* KW_FIX */
381 #else
382    U8  txIdx;
383    U32 *libInitBitMask = NULLP;
384 #endif
385
386    TRC3(pjUtlUlUpInit)
387
388    RLOG2(L_DEBUG, "pjUtlUpInit(ueCb(%d,%d))",
389                     ueCb->key.ueId, ueCb->key.cellId);
390
391 #ifdef PJ_SEC_ASYNC
392
393    if(ueCb->libInfo.state == PJ_STATE_REEST)
394    {
395       for(txIdx = 0; txIdx < PJ_MAX_ASYNC_CFM; txIdx++)
396       {
397          if((ueCb->libInfo.asyncCfm[txIdx] != NULLP) &&
398                (ueCb->libInfo.asyncCfm[txIdx]->cfmType == PJ_REEST_ASYNC_CFM))
399          {
400             libInitBitMask =  &ueCb->libInfo.asyncCfm[txIdx]->libInitBitMask;
401             break;
402          }
403       }
404    }
405    else if(ueCb->libInfo.state == PJ_STATE_NORMAL)
406    {
407       libInitBitMask =  &ueCb->libInfo.tLibInitBitMask;
408    }
409
410    if(libInitBitMask)
411       (*libInitBitMask) = (*libInitBitMask) | PJ_LIB_UP_CIP_BIT_MASK;
412
413    ret = PjLibObdUpInitReq(&gCb->pjGenCfg.obdPst.secPst, ueCb->secInfo.secCxt, 
414          ueCb->secInfo.cipherInfo.algoType, ueCb->secInfo.cipherInfo.upKey);
415 #else
416 #ifdef INTEL_QAT_DP
417 #ifdef QAT_TWO_INSTANCE
418    pjLibUpInitReq(gCb->u.ulCb->instHndl, ueCb->secInfo.secCxt, ueCb->secInfo.cipherInfo.algoType, 
419                               ueCb->secInfo.cipherInfo.upKey, &ctxId);
420 #else
421    pjLibUpInitReq(gCb, ueCb->secInfo.secCxt, ueCb->secInfo.cipherInfo.algoType, 
422                               ueCb->secInfo.cipherInfo.upKey, &ctxId);
423 #endif
424    ueCb->secInfo.upCiphSessCxtId= ctxId; 
425 #else
426    pjLibUpInitReq(ueCb->secInfo.secCxt, (U8)ueCb->secInfo.cipherInfo.algoType, 
427                               ueCb->secInfo.cipherInfo.upKey, &ctxId); /*KW_FIX*/
428    ueCb->secInfo.upCxtId = ctxId;
429 #endif /* INTEL_QAT_DP */
430 #endif /* PJ_SEC_ASYNC */
431
432    RETVALUE(ROK);
433
434 } /* end of pjUtlUpInit */
435
436
437 /**
438  *
439  * @brief 
440  *
441  *        Handler for resetting the context with the compression unit (either 
442  *        synchronous or asynchronous) for RB within an UE.
443  *
444  * @b Description:
445  *
446  *        This function resets the context with the compression unit per RB per
447  *        UE by using synchronous / asynchronous function calls.
448  *
449  *
450  *  @param[in] cmpCxtId     Context to be reset for compression 
451  *
452  *  @return  S16
453  *      -# ROK 
454  *
455  */
456 #ifdef ANSI
457 PUBLIC S16 pjUtlUlCmpReset
458 (
459 PjCb        *gCb,
460 PjUlRbCb      *pjRbCb                 /* Context to be reset for compression */
461 )
462 #else
463 PUBLIC S16 pjUtlUlCmpReset(pjRbCb)
464 PjCb        *gCb;
465 PjUlRbCb      *pjRbCb;                 /* Context to be reset for compression */
466 #endif
467 {
468    TRC3(pjUtlUlCmpReset)
469
470    RLOG2(L_DEBUG, "pjUtlUlCmpReset(pjRbCb(%d,%d))",
471                     pjRbCb->rbId, pjRbCb->rbType);
472
473 #ifdef PJ_CMP_ASYNC
474    PjLibObdCmpResetReq(&gCb->pjGenCfg.obdPst.cmpPst, pjRbCb->cmpCxtId);
475 #else
476    pjLibCmpResetReq(pjRbCb->cmpCxtId);
477 #endif
478
479    RETVALUE(ROK);
480
481 } /* end of pjUtlCmpReset */
482
483
484 /**
485  *
486  * @brief 
487  *
488  *        Handler for closing the UL context with the Ciphering unit (either 
489  *        synchronous or asynchronous) for SRBs of an UE.
490  *
491  * @b Description:
492  *
493  *        This function closes an existing UL context with the security algo unit per UE
494  *        for ciphering / deciphering with control plane key using synchronous / asynchronous 
495  *        function calls with relevant input parameters.
496  *
497  *
498  *  @param[in] cpCxtId          Context Id for Ciphering to be closed 
499  *
500  *  @return  S16
501  *      -# ROK 
502  *
503  */
504 #ifdef ANSI      
505 PUBLIC S16 pjUtlUlCipherClose
506 (
507 PjCb     *gCb,
508 Void      *cpCxtId                  /* Context Id for Ciphering to be closed */
509 )
510 #else
511 PUBLIC S16 pjUtlUlCipherClose(cpCxtId)
512 PjCb     *gCb;
513 Void     *cpCxtId;                 /* Context Id for Ciphering to be closed */
514 #endif
515 {
516    S16   ret = ROK;
517    TRC3(pjUtlUlCipherClose)
518    RLOG0(L_DEBUG, "pjUtlUlCipherClose");
519 #ifndef PJ_SEC_ASYNC
520 #ifdef INTEL_QAT_DP
521 #ifdef QAT_TWO_INSTANCE
522    ret = PjLibObdCipherCloseReq(gCb->u.ulCb->instHndl, cpCxtId);
523 #else
524    ret = PjLibObdCipherCloseReq(gCb->instHndl, cpCxtId); 
525 #endif
526 #else
527    PjLibObdCipherCloseReq(cpCxtId);
528 #endif
529 #else
530 #ifdef INTEL_QAT_DP
531 #ifdef QAT_TWO_INSTANCE
532    ret = PjLibObdCipherCloseReq(gCb->u.ulCb->instHndl, cpCxtId);
533 #else
534    ret = PjLibObdCipherCloseReq(gCb->instHndl, cpCxtId); 
535 #endif
536 #else
537    PjLibObdCipherCloseReq(&gCb->pjGenCfg.obdPst.secPst, cpCxtId);
538 #endif
539 #endif
540    RETVALUE(ret);
541 } /* end of pjUtlCipherClose */
542 /**
543  *
544  * @brief 
545  *
546  *        Handler for closing the UL context with the Integration unit (either 
547  *        synchronous or asynchronous) for all RBs of an UE.
548  *
549  * @b Description:
550  *
551  *        This function closes an existing UL context with the security algo unit per UE
552  *        for Integration protection/verification using synchronous / asynchronous function 
553  *        calls with relevant input parameters.
554  *
555  *
556  *  @param[in] intCxtId        Integration CxtId to be closed 
557  *
558  *  @return  S16
559  *      -# ROK 
560  *
561  */
562 #ifdef ANSI   
563 PUBLIC S16 pjUtlUlIntClose
564 (
565 PjCb     *gCb,
566 Void      *intCxtId                 /* Integration CxtId to be closed */
567 )
568 #else
569 PUBLIC S16 pjUtlUlIntClose(intCxtId)
570 PjCb     *gCb;
571 Void     *intCxtId;                /* Integration CxtId to be closed */
572 #endif
573 {
574    S16   ret = ROK;
575    TRC3(pjUtlUlIntClose)
576    RLOG0(L_DEBUG, "pjUtlUlIntClose");
577    
578 #ifdef TENB_AS_SECURITY
579 #ifdef INTEL_QAT_DP
580 #ifdef QAT_TWO_INSTANCE
581    ret = PjLibObdIntCloseReq(gCb->u.ulCb->instHndl,intCxtId);
582 #else
583    ret = PjLibObdIntCloseReq(gCb->instHndl,intCxtId);
584 #endif
585 #endif
586 #else
587 #ifdef PJ_SEC_ASYNC
588    PjLibObdIntCloseReq(&gCb->pjGenCfg.obdPst.secPst,intCxtId);
589 #else   
590    PjLibObdIntCloseReq(intCxtId);
591 #endif
592 #endif
593    RETVALUE(ret);
594 } /* end of pjUtlIntClose */
595
596 /**
597  *
598  * @brief 
599  *
600  *        Handler for redirecing deciphering request to either synchronous
601  *        or asynchronous module.
602  *
603  * @b Description:
604  *
605  *        This function sends deciphering request as either synchronous or
606  *        asynchronous function calls with relevant input parameters.
607  *
608  *  @param[in]   pjRbCb           PDCP RbCb 
609  *  @param[in]   secInp           Input parameters for deciphering 
610  *  @param[in]   mBuf             Data to be deciphered 
611  *  @param[in]   opSdu            Deciphered SDU 
612  *
613  *  @return  S16
614  *      -# ROK 
615  *
616  */
617 /* Uday */
618 #ifdef TENB_AS_SECURITY
619 #ifdef ANSI
620 PUBLIC S16 pjUtlDecipherReq
621 (
622 PjCb       *gCb,
623 PjUlRbCb   *pjRbCb,                 /* PDCP RbCb */
624 U32        count,
625 Buffer     *mBuf,                    /* Data to be deciphered */
626 Buffer   **opSdu                  /* Deciphered SDU */
627 )
628 #else
629 PUBLIC S16 pjUtlDecipherReq(gCb, pjRbCb, count, mBuf, opSdu)
630 PjCb       *gCb;
631 PjUlRbCb   *pjRbCb;                 /* PDCP RbCb */
632 U32        count;
633 Buffer     *mBuf;                   /* Data to be deciphered */
634 Buffer   **opSdu;                  /* Deciphered SDU */
635 #endif
636 {
637    S16 ret = ROK;
638    PjUlUeCb *ulUeCb;
639    PjLibTrans  libTrans;
640 #ifdef PJ_SEC_ASYNC
641    Void      *cxtId = NULLP;    /* Context Identifier */
642 #endif
643    TRC3(pjUtlDecipherReq)
644
645 #ifdef PJ_SEC_ASYNC
646    if (pjRbCb->rbType == PJ_SRB)
647    {
648       cxtId = pjRbCb->ueCb->secInfo.cpCxtId;
649    }
650    else
651    {
652       cxtId = pjRbCb->ueCb->secInfo.upCxtId;
653    } 
654 #endif
655    ulUeCb = pjRbCb->ueCb;
656    libTrans.pdcpInstance = gCb->init.inst;
657    libTrans.count = count;
658    libTrans.rbId = pjRbCb->rbId - 1;
659    libTrans.dir = PJ_SEC_DIR_UL;
660    libTrans.rbType = pjRbCb->rbType;
661    libTrans.snLen = pjRbCb->snLen;
662    libTrans.ciphAlgoType = ulUeCb->secInfo.cipherInfo.algoType;
663    libTrans.ueCb = (PTR)ulUeCb;
664    libTrans.ueId = ulUeCb->key.ueId;
665    libTrans.cellId = ulUeCb->key.cellId;
666    if(PJ_SRB == pjRbCb->rbType)
667    {
668       libTrans.key = ulUeCb->secInfo.cipherInfo.cpKey;
669 #ifdef INTEL_QAT_DP
670       libTrans.sessCxtId = ulUeCb->secInfo.cpCiphSessCxtId;
671 #ifdef QAT_TWO_INSTANCE
672       libTrans.instHndl = gCb->u.ulCb->instHndl;
673 #else
674       libTrans.instHndl = gCb->instHndl;
675 #endif
676 #endif
677    }
678    else
679    {
680       libTrans.key = ulUeCb->secInfo.cipherInfo.upKey;
681 #ifdef INTEL_QAT_DP
682       libTrans.sessCxtId = ulUeCb->secInfo.upCiphSessCxtId;
683 #ifdef QAT_TWO_INSTANCE
684       libTrans.instHndl = gCb->u.ulCb->instHndl;
685 #else
686       libTrans.instHndl = gCb->instHndl;
687 #endif
688 #endif
689    }
690    
691 #ifdef PJ_SEC_ASYNC
692    /* Start the timer if it is not started already */
693    if((pjChkTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR)) == FALSE)
694    {
695       pjRbCb->ulCb.obdPdu   =  secInp.count;
696       pjStartTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR);
697    }
698    ret = PjLibObdDecipherReq(&(gCb->pjGenCfg.obdPst.secPst), 
699                                  cxtId, secInp, libTrans, mBuf);  
700 #else
701 #ifdef INTEL_QAT_DP
702     /* TODO: 3rd arg is unused can be removed */
703         ret = PjLibObdDecipherReq(&libTrans, mBuf, opSdu);
704 #else
705 #ifndef INTEL_SW_SEC
706    ret = PjLibObdDecipherReq(&libTrans, mBuf, opSdu);
707 #else
708    ret = PjLibObdSwDecipherReq(&libTrans, mBuf, gCb,opSdu);
709 #endif
710 #endif
711 #endif
712    RETVALUE(ret);
713 } /* end of pjUtlDecipherReq */
714 #else
715 #ifdef ANSI
716 PUBLIC S16 pjUtlDecipherReq
717 (
718 PjCb       *gCb,                   /* Cell Cb */
719 PjUlRbCb   *pjRbCb,                 /* PDCP RbCb */
720 U32        count,
721 Buffer   *mBuf,                   /* Data to be deciphered */
722 Buffer   **opSdu                  /* Deciphered SDU */
723 )
724 #else
725 PUBLIC S16 pjUtlDecipherReq(gCb, pjRbCb, count, mBuf, opSdu)
726 PjCb       *gCb;
727 PjUlRbCb   *pjRbCb;                 /* PDCP RbCb */
728 U32        count;
729 Buffer   *mBuf;                   /* Data to be deciphered */
730 Buffer   **opSdu;                 /* Deciphered SDU */
731 #endif
732 {
733    S16 ret = ROK;
734 #ifdef PJ_SEC_ASYNC
735    PjLibTrans libTrans; /* Transaction Id for deciphering */
736 #else
737    PjSecInp   secInp;
738 #endif /* PJ_SEC_ASYNC */
739    PTR        cxtId;    /* Context Identifier */
740    TRC3(pjUtlDecipherReq)
741    if (pjRbCb->rbType == PJ_SRB)
742    {
743       cxtId = (PTR)pjRbCb->ueCb->secInfo.cpCxtId;
744    }
745    else
746    {
747       cxtId = (PTR)pjRbCb->ueCb->secInfo.upCxtId;
748    } 
749 #ifdef PJ_SEC_ASYNC
750    /* Assign transId and cxtId */
751    libTrans.count  = count;
752    /* kw005.201 ccpu00114955 corrected the RB ID calculation */
753    libTrans.rbId   = pjRbCb->rbId - 1;
754    libTrans.rbType = pjRbCb->rbType;
755    libTrans.ueCb   = pjRbCb->ueCb;
756    /* Start the timer if it is not started already */
757    if((pjChkTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR)) == FALSE)
758    {
759       pjRbCb->ulCb.obdPdu   =  secInp.count;
760       pjStartTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR);
761    }
762    ret = PjLibObdDecipherReq(&gCb->pjGenCfg.obdPst.secPst, 
763                                  cxtId, secInp, libTrans, mBuf);  
764 #else
765    secInp.count = count;
766    secInp.rbId  = pjRbCb->rbId - 1;
767    secInp.dir = 0;
768    ret = pjLibDecipherReq(cxtId, secInp, mBuf, opSdu);
769 #endif
770    RETVALUE(ret);
771 } /* end of pjUtlDecipherReq */
772 #endif
773 /**
774  *
775  * @brief 
776  *
777  *        Handler for redirecing Integration request to either synchronous
778  *        or asynchronous module.
779  *
780  * @b Description:
781  *
782  *        This function sends Intergrity verification request as either synchronous or
783  *        asynchronous function calls with relevant input parameters.
784  *
785  *  @param[in]   pjRbCb        PDCP RbCb 
786  *  @param[in]   secInp        Input parameters for integrity 
787  *  @param[in]   mBuf          SDU to be compressed 
788  *  @param[out]  status        Integrity verification status 
789  *
790  *  @return  S16
791  *      -# ROK 
792  *
793  */
794 #ifdef TENB_AS_SECURITY
795 #ifdef ANSI
796 PUBLIC S16 pjUtlIntVerReq
797 (
798 PjCb     *gCb,
799 PjUlRbCb   *pjRbCb,                 /* PDCP RbCb */
800 PjSecInp secInp ,                 /* Input parameters for integrity */ 
801 Buffer   *mBuf,                   /* SDU to be compressed */
802 U32      macI,                    /* MAC-I to be verified with */
803 Status   *status                  /* Integrity verification status */
804 )
805 #else
806 PUBLIC S16 pjUtlIntVerReq(pjRbCb, secInp, mBuf, macI, status)
807 PjCb     *gCb;
808 PjUlRbCb   *pjRbCb;                 /* PDCP RbCb */
809 PjSecInp secInp;                 /* Input parameters for integrity */ 
810 Buffer   *mBuf;                   /* SDU to be compressed */
811 U32      macI;                    /* MAC-I to be verified with */
812 Status   *status;                 /* Integrity verification status */
813 #endif
814 {
815    S16 ret = ROK;
816    PjUlUeCb *ulUeCb;
817    PjLibTrans  libTrans;
818 #ifdef PJ_SEC_ASYNC
819    Void       *cxtId;    /* Context Identifier */
820 #endif
821    TRC3(pjUtlIntVerReq)
822
823 #ifdef PJ_SEC_ASYNC
824    cxtId = pjRbCb->ueCb->secInfo.intCxtId;
825 #endif
826    ulUeCb = pjRbCb->ueCb;
827    libTrans.pdcpInstance = gCb->init.inst;
828    libTrans.count = secInp.count;
829    libTrans.rbId = pjRbCb->rbId - 1;
830    libTrans.dir = secInp.dir;
831    libTrans.rbType = pjRbCb->rbType;
832    libTrans.intAlgoType = ulUeCb->secInfo.intInfo.algoType;
833    libTrans.ueCb = (PTR)ulUeCb;
834    libTrans.ueId = ulUeCb->key.ueId;
835    libTrans.cellId = ulUeCb->key.cellId;
836    libTrans.key = (U8*)&ulUeCb->secInfo.intInfo.intKey[0];
837    PJ_SEC_FILL_FRESH(libTrans.fresh, libTrans.rbId);
838
839 #ifdef INTEL_QAT_DP
840    libTrans.sessCxtId = ulUeCb->secInfo.cpIntSessCxtId;
841 #ifdef QAT_TWO_INSTANCE
842    libTrans.instHndl = gCb->u.ulCb->instHndl;
843 #else
844    libTrans.instHndl = gCb->instHndl;
845 #endif
846 #endif
847 #ifdef PJ_SEC_ASYNC
848    /* Start the timer if it is not started already */
849    if((pjChkTmr(gCb, (PTR)pjRbCb, PJ_EVT_UL_OBD_TMR)) == FALSE)
850    {
851       pjRbCb->ulCb.obdPdu   =  secInp.count;
852       pjStartTmr(gCb, (PTR)pjRbCb, PJ_EVT_UL_OBD_TMR);
853    }
854    ret = PjLibObdIntVerReq(&(gCb->pjGenCfg.obdPst.secPst), cxtId, 
855                                        secInp, libTrans, mBuf, macI);  
856 #else
857 #ifdef INTEL_SW_INTEG
858    ret = PjLibObdIntVerReq(gCb, &libTrans, mBuf, macI);
859 #else
860    ret = PjLibObdIntVerReq(&libTrans, mBuf, macI);
861 #endif
862 #endif
863    RETVALUE(ret);
864
865 } /* end of pjUtlIntVerReq */
866 #else
867 #ifdef ANSI
868 PUBLIC S16 pjUtlIntVerReq
869 (
870 PjCb     *gCb,
871 PjUlRbCb   *pjRbCb,                 /* PDCP RbCb */
872 PjSecInp secInp ,                 /* Input parameters for integrity */ 
873 Buffer   *mBuf,                   /* SDU to be compressed */
874 U32      macI,                    /* MAC-I to be verified with */
875 Status   *status                  /* Integrity verification status */
876 )
877 #else
878 PUBLIC S16 pjUtlIntVerReq(gCb, pjRbCb, secInp, mBuf, macI, status)
879 PjCb     *gCb;
880 PjUlRbCb   *pjRbCb;                 /* PDCP RbCb */
881 PjSecInp secInp;                 /* Input parameters for integrity */ 
882 Buffer   *mBuf;                   /* SDU to be compressed */
883 U32      macI;                    /* MAC-I to be verified with */
884 Status   *status;                 /* Integrity verification status */
885 #endif
886 {
887    S16 ret = ROK;
888 #ifdef PJ_SEC_ASYNC
889    PjLibTrans libTrans; /* Transaction Id for deciphering */
890 #endif /* PJ_SEC_ASYNC */
891    PTR cxtId;    /* Context Identifier */
892
893    TRC3(pjUtlIntVerReq)
894
895    cxtId = (PTR)pjRbCb->ueCb->secInfo.intCxtId;
896
897 #ifdef PJ_SEC_ASYNC
898    /* Assign transId and cxtId */
899    libTrans.count  = secInp.count;
900    libTrans.rbId   = pjRbCb->rbId - 1;
901    libTrans.rbType = pjRbCb->rbType;
902    libTrans.ueCb   = pjRbCb->ueCb;
903
904    /* Start the timer if it is not started already */
905    if((pjChkTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR)) == FALSE)
906    {
907       pjRbCb->ulCb.obdPdu   =  secInp.count;
908       pjStartTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR);
909    }
910
911    ret = PjLibObdIntVerReq(&gCb->pjGenCfg.obdPst.secPst, cxtId, 
912                                        secInp, libTrans, mBuf, macI);  
913 #else
914    /* ccpu00142570 */
915    ret = pjLibIntVerReq(cxtId, secInp, mBuf, macI, status);
916 #endif
917
918    RETVALUE(ret);
919
920 } /* end of pjUtlIntVerReq */
921 #endif
922
923
924
925
926 /**
927  *
928  * @brief 
929  *
930  *        Utility function that processes the CfgReq with type as
931  *        REESTABLISH sent from RRC.
932  *
933  * @b Description:
934  *
935  *        This function 
936  *        1. Marks the state of the RBs as PJ_STATE_REEST.
937  *        2. Calculates the number of RBs undergoing reestablishment.
938  *
939  *  @param[in] ueCb     UE Control Block Pointer.
940  *  @param[in] numEnt   Number of entities undergoing reestablishment
941  *  @param[in] cfgEnt   List of entities configured.
942  *
943  *  @return  S16
944  *      -# ROK 
945  *      -# RFAILED
946  *
947  */
948 #ifdef ANSI
949 PUBLIC S16 pjUtlUlReEstSrb1
950 (
951 PjCb       *gCb,
952 PjUlRbCb   *pjRbCb                    /* PDCP Control Block Pointer */
953 )
954 #else
955 PUBLIC S16 pjUtlUlReEstSrb1(pjRbCb)
956 PjCb       *gCb;
957 PjUlRbCb   *pjRbCb;                   /* PDCP Control Block Pointer */
958 #endif
959 {
960    PjUlUeCb   *ueCb;
961
962    TRC2(pjUtlReEstSrb1)
963
964    RLOG2(L_DEBUG, "pjUtlReEstSrb1(pjRbCb(%d,%d))",
965                     pjRbCb->rbId, pjRbCb->rbType);
966
967    ueCb     = pjRbCb->ueCb;
968
969    ueCb->libInfo.state  =  PJ_STATE_REEST;
970
971    /* SRB Reconfiguration we can update the control Plane keys and
972       the Integrity Keys in the OBD module */
973
974    pjUtlUlUpdCpSecKeys(gCb,ueCb);
975
976    /* Perform  uplink reestablishment of SRB1 */
977    pjUlmReEstSrb(gCb,pjRbCb);
978
979    /* Start security reconfiguration if SRB1 is the only RB */
980    if ((ueCb->numSrbs == 1) && (ueCb->numDrbs == 0))
981    {
982      pjUtlUlUpdUpSecKeys(gCb,ueCb);
983    }
984
985    RETVALUE(ROK);
986 } /* pjUtlReEstSrb1 */
987 \f
988 /**
989  *
990  * @brief 
991  *
992  *        Handler to start reestablishment processing
993  *
994  * @b Description:
995  *
996  *        This function 
997  *        1. Marks the state of the RBs as PJ_STATE_REEST_HO.
998  *        2. Calculates the number of RBs undergoing reestablishment.
999  *
1000  *  @param[in] ueCb    Number of RBs undergoing reestablishment
1001  *
1002  *  @return  S16
1003  *      -# ROK 
1004  *      -# RFAILED
1005  *
1006  */
1007 #ifdef ANSI
1008 PUBLIC S16 pjUtlUlReEstHO
1009 (
1010 PjCb          *gCb,
1011 PjUlUeCb      *ueCb           /* Number of RBs undergoing reestablishment*/ 
1012 )
1013 #else
1014 PUBLIC S16 pjUtlUlReEstHO(gCb,ueCb) 
1015 PjCb          *gCb;
1016 PjUlUeCb      *ueCb;           /* Number of RBs undergoing reestablishment*/ 
1017 #endif
1018 {
1019    U8             rbCnt;
1020    PjUlRbCb     **rbCbLst;
1021    PjUlRbCb      *pjRbCb;
1022
1023    TRC2(pjUtlUlReEstHO); 
1024
1025 #ifdef ALIGN_64BIT
1026    RLOG2(L_DEBUG, "pjUtlReEstHOStart(ueCb(%d,%d)))",
1027                 ueCb->key.ueId, ueCb->key.cellId);
1028 #else
1029    RLOG2(L_DEBUG, "pjUtlReEstHOStart(ueCb(%d,%d))",
1030                 ueCb->key.ueId, ueCb->key.cellId);
1031 #endif
1032
1033    /* Perform initialisations on the HO Info structure */
1034    PJ_ALLOC(gCb,ueCb->hoInfo, sizeof(PjUlHoInfo));
1035 #if (ERRCLASS & ERRCLS_ADD_RES)
1036    if (ueCb->hoInfo == NULLP)
1037    {
1038       RLOG0(L_FATAL, "Memory Allocation failed.");
1039       RETVALUE(RFAILED);
1040    }
1041 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1042    PJ_ALLOC(gCb,ueCb->hoInfo->hoCfmInfo, 
1043               sizeof(PjUlHoCfmInfo) *  PJ_MAX_DRB_PER_UE );
1044  
1045 #if (ERRCLASS & ERRCLS_ADD_RES)
1046    if (ueCb->hoInfo->hoCfmInfo == NULLP )
1047    {
1048       RLOG0(L_FATAL, "Memory Allocation failed.");
1049       /*ccpu00136858 */      
1050       PJ_PST_FREE(gCb->u.ulCb->cpjSap.pst.region, gCb->u.ulCb->cpjSap.pst.pool, ueCb->hoInfo, sizeof(PjUlHoInfo));
1051       RETVALUE(RFAILED);
1052    }
1053 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1054  
1055    /* Initialise the reestablishment states for the RBs */
1056    rbCbLst      = ueCb->drbCb;
1057    for(rbCnt = 0; rbCnt < PJ_MAX_DRB_PER_UE; rbCnt ++)
1058    {
1059       /* Check of rbCb available */
1060       if( (pjRbCb = rbCbLst[rbCnt]) == NULLP)
1061       {
1062          continue;
1063       }
1064       /* Fetch the rbCb and intialise the states */
1065       pjRbCb->state  =  PJ_STATE_REEST_HO;
1066       ueCb->libInfo.numReEstDrb++;
1067
1068 #if (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC))
1069        pjRbCb->ulCb.obdCnt   = 0;
1070        pjRbCb->ulCb.transCmp = 0;
1071        if(pjRbCb->mode == PJ_DRB_AM)
1072        {
1073           pjRbCb->ulCb.firstReEstCnt   =   pjRbCb->ulCb.rxDeliv;
1074        }
1075 #endif /* (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC)) */
1076
1077    }/* for(rbCnt .. */ 
1078
1079    RETVALUE(ROK);
1080
1081 } /* pjUtlReEstHOStart */
1082
1083 /**
1084  *
1085  * @brief 
1086  *
1087  *        Handler to apply the new security algorithms and 
1088  *        reset the compression unit.
1089  *
1090  * @b Description:
1091  *
1092  *        This function 
1093  *        1. Creates new contexts for Control Plane Ciphering and Integrity.
1094  *        2. Closes the old contexts for Control Plane Ciphering and Integrity.
1095  *
1096  *  @param[in] ueCb   UE Control Block
1097  *
1098  *  @return  S16
1099  *      -# ROK 
1100  *      -# RFAILED
1101  *
1102  */
1103 #ifdef ANSI
1104 PUBLIC S16 pjUtlUlUpdUpSecKeys
1105 (
1106 PjCb       *gCb,
1107 PjUlUeCb   *ueCb           /* UE Control Block */ 
1108 )
1109 #else
1110 PUBLIC S16 pjUtlUlUpdUpSecKeys(gCb,ueCb)
1111 PjCb         *gCb;
1112 PjUlUeCb     *ueCb;           /* UE Control Block */ 
1113 #endif
1114 {
1115    Void     *tmpUpCxt;
1116
1117    TRC2(pjUtlUlUpdUpSecKeys);
1118
1119    RLOG2(L_DEBUG, "pjUtlUlUpdUpSecKeys(ueCb(%d,%d))",
1120                 ueCb->key.ueId, ueCb->key.cellId);
1121
1122    if(ueCb->secInfo.secAct == TRUE)
1123    {
1124       /* Initialisation is done first followed by closure since we
1125        * do not want the same ctxId to be returned for the new init.
1126        * In ASYNC case, we drop packets if they are returned from a
1127        * different ctxId. */
1128
1129 #ifdef INTEL_QAT_DP
1130       tmpUpCxt  = ueCb->secInfo.upCiphSessCxtId; 
1131 #else
1132       tmpUpCxt  = ueCb->secInfo.upCxtId; 
1133 #endif
1134       pjUtlUlUpInit(gCb,ueCb);
1135       pjUtlUlCipherClose(gCb,tmpUpCxt);
1136    }
1137
1138    RETVALUE(ROK);
1139 } /* pjUtlUlUpdUpSecKeys */
1140
1141 /**
1142  *
1143  * @brief 
1144  *
1145  *        Handler to apply the new security algorithms and 
1146  *        reset the compression unit.
1147  *
1148  * @b Description:
1149  *
1150  *        This function 
1151  *        1. Creates new contexts for Control Plane Ciphering and Integrity.
1152  *        2. Closes the old contexts for Control Plane Ciphering and Integrity.
1153  *
1154  *  @param[in] ueCb   UE Control Block
1155  *
1156  *  @return  S16
1157  *      -# ROK 
1158  *      -# RFAILED
1159  *
1160  */
1161 #ifdef ANSI
1162 PUBLIC S16 pjUtlUlUpdCpSecKeys
1163 (
1164 PjCb       *gCb,
1165 PjUlUeCb   *ueCb           /* UE Control Block */ 
1166 )
1167 #else
1168 PUBLIC S16 pjUtlUlUpdCpSecKeys(gCb,ueCb)
1169 PjCb         *gCb;
1170 PjDlUeCb     *ueCb;           /* UE Control Block */ 
1171 #endif
1172 {
1173    Void     *tmpIntCxt;
1174    Void     *tmpCpCxt;
1175
1176    TRC2(pjUtlDlUpdCpSecKeys);
1177
1178    RLOG2(L_DEBUG, "pjUtlUlUpdCpSecKeys(ueCb(%d,%d))",
1179                 ueCb->key.ueId, ueCb->key.cellId);
1180
1181    if(ueCb->secInfo.secAct == TRUE)
1182    {
1183       /* Initialisation is done first followed by closure since we
1184        * do not want the same ctxId to be returned for the new init.
1185        * In ASYNC case, we drop packets if they are returned from a
1186        * different ctxId. */
1187 #ifdef INTEL_QAT_DP
1188       tmpIntCxt = ueCb->secInfo.cpIntSessCxtId;  
1189       tmpCpCxt  = ueCb->secInfo.cpCiphSessCxtId;          
1190
1191 #else
1192       tmpIntCxt = ueCb->secInfo.intCxtId;  
1193       tmpCpCxt  = ueCb->secInfo.cpCxtId;    
1194 #endif
1195
1196       pjUtlUlCpInit(gCb,ueCb);
1197       pjUtlUlIntInit(gCb,ueCb);
1198
1199       pjUtlUlIntClose(gCb,tmpIntCxt);
1200       pjUtlUlCipherClose(gCb,tmpCpCxt);
1201    }
1202
1203    RETVALUE(ROK);
1204 } /* pjUtlDlUpdCpSecKeys */
1205
1206 /**
1207  *
1208  * @brief 
1209  *
1210  *        Function to handle the REESTABLISHMENT COMPLETE 
1211  *        for each uplink RB
1212  *
1213  * @b Description:
1214  *
1215  *        This function 
1216  *
1217  *  @param[in] ueCb   UE Control Block
1218  *
1219  *  @return  S16
1220  *      -# ROK 
1221  *      -# RFAILED
1222  *
1223  */
1224 #ifdef ANSI
1225 PUBLIC S16 pjUtlUlHdlRbReEstComplete
1226 (
1227 PjCb         *gCb,
1228 PjUlRbCb     *pjRbCb           /*RB Control Block */ 
1229 )
1230 #else
1231 PUBLIC S16 pjUtlUlHdlRbReEstComplete(ueCb, pjRbCb)
1232 PjCb         *gCb;
1233 PjUlRbCb     *pjRbCb;          /* RB Control Block */ 
1234 #endif
1235 {
1236    PjUlUeCb      *ueCb;
1237
1238    TRC2(pjUtlUlHdlRbReEstComplete);
1239
1240    RLOG1(L_DEBUG, "pjUtlUlHdlRbReEstComplete(rbCb(%d)",
1241                 pjRbCb->rbId);
1242
1243    ueCb = pjRbCb->ueCb;
1244    if (ueCb->libInfo.numReEstDrb == 0)
1245    {
1246       ueCb->libInfo.numReEstCmp++;
1247       RETVALUE(ROK);
1248    }
1249    else
1250    {
1251       ueCb->libInfo.numReEstDrb--;  
1252    }
1253
1254    if (ueCb->libInfo.numReEstDrb == 0)
1255    {
1256       if (ueCb->libInfo.state == PJ_STATE_REEST)
1257       {
1258          /* Since we have received all the packets in uplink
1259             we can update the user keys */
1260          pjUtlUlUpdUpSecKeys(gCb, ueCb);
1261
1262 #ifdef PJ_ASYNC_CFM
1263         RETVALUE(ROK);
1264 #endif
1265         pjUtlUlSndReEstCfgCfm(gCb,ueCb);
1266       }
1267       else if (ueCb->libInfo.state == PJ_STATE_REEST_HO)
1268       {
1269          pjUtlUlSndSduStaCfm(gCb,ueCb);
1270       }
1271    }
1272    RETVALUE(ROK);
1273
1274 } /* pjUtlUlHdlRbReEstComplete */
1275
1276 /**
1277  *
1278  * @brief 
1279  *
1280  *        Function to sent the REESTABLISHMENT COMPPLETE 
1281  *        to the RRC.
1282  *
1283  * @b Description:
1284  *
1285  *        This function 
1286  *        1. Sends a ReEstablishment Confirm for normal reestablishment.
1287  *        2. Sends a SDU status confirm for handover reestablishment.
1288  *
1289  *  @param[in] ueCb   UE Control Block
1290  *
1291  *  @return  S16
1292  *      -# ROK 
1293  *      -# RFAILED
1294  *
1295  */
1296 #ifdef ANSI
1297 PUBLIC S16 pjUtlUlSndReEstCfgCfm
1298 (
1299 PjCb         *gCb,
1300 PjUlUeCb       *ueCb           /* UE Control Block */ 
1301 )
1302 #else
1303 PUBLIC S16 pjUtlUlSndReEstCfgCfm(ueCb)
1304 PjCb         *gCb;
1305 PjUlUeCb       *ueCb;           /* UE Control Block */ 
1306 #endif
1307 {
1308    CpjCfgCfmInfo *cfgCfmInfo;
1309    U8             txIdx;
1310    PjAsyncCfm    *asyncCfm    = NULLP;
1311    PjCpjSapCb    *cpjSap;
1312
1313    TRC2(pjUtlSndReEstCfgCfm);
1314
1315    RLOG2(L_DEBUG, "pjUtlSndReEstCfgCfm(ueCb(%d,%d))",
1316                 ueCb->key.ueId, ueCb->key.cellId);
1317
1318    /* Pick up the confirm info */
1319    for(txIdx = 0; txIdx < PJ_MAX_ASYNC_CFM; txIdx++)
1320    {
1321       if((ueCb->libInfo.asyncCfm[txIdx] != NULLP) &&
1322          (ueCb->libInfo.asyncCfm[txIdx]->cfmType & PJ_CFG_REEST_ASYNC_CFM))
1323       {
1324          asyncCfm =  ueCb->libInfo.asyncCfm[txIdx];
1325          break;
1326       }
1327    }
1328
1329    /* its a reestablishment with only srb1 configured */
1330    if(asyncCfm == NULLP)
1331    {
1332       RETVALUE(ROK);
1333    }
1334    /* Memory leak fix ccpu00135359 */
1335    cpjSap = &(gCb->u.ulCb->cpjSap);
1336    if(SGetSBuf(cpjSap->pst.region,cpjSap->pst.pool,(Data **)&cfgCfmInfo,
1337       sizeof (CpjCfgCfmInfo)) != ROK)
1338    {
1339       RLOG0(L_FATAL, "Memory Allocation failed.");
1340       RETVALUE(RFAILED);
1341    }
1342
1343    PJ_FILL_REEST_CFG_CFM_INFO(cfgCfmInfo, asyncCfm);
1344    PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
1345
1346    PjUiCpjCfgCfm(&gCb->u.ulCb->cpjSap.pst, gCb->u.ulCb->cpjSap.suId, cfgCfmInfo);         
1347
1348    RETVALUE(ROK);
1349 } /* pjUtlSndReEstCfgCfm */
1350 /**
1351  *
1352  * @brief Handler to store the confirms while we wait for the init
1353  *        confirms from the off-board.
1354  *       
1355  *
1356  * @b Description
1357  *        This function is invoked during security config request,
1358  *        reestablishment request and config request if the libraries
1359  *        are off-boarded. This stores the entries in a confirm list
1360  *        while waiting for the confirm from the offboard.
1361  *
1362  *  @return  S16
1363  *      -# ROK 
1364  *      -# RFAILED 
1365  *
1366 */
1367
1368 #ifdef ANSI
1369 PUBLIC S16 pjUtlUlSaveCfmInfo
1370 (
1371 PjCb        *gCb,
1372 PjUlUeCb      *ueCb,           /* Pointer to UeCb */ 
1373 U8          cfmType,         /* Confirm type */
1374 Bool        startTmr,        /* Start Timer */
1375 U8          entity,          /* Confirm type */
1376 PTR         cfmPtr,          /* Pointer to the structure for confirm */
1377 PTR         cfgPtr           /* Pointer to the structure for request */
1378 )
1379 #else
1380 PUBLIC S16 pjUtlUlSaveCfmInfo(ueCb, cfmType, startTmr, entity, cfmPtr, cfgPtr)
1381 PjCb        *gCb;
1382 PjUlUeCb      *ueCb;           /* Pointer to UeCb */ 
1383 U8          cfmType;         /* Confirm type */
1384 Bool        startTmr;        /* Start Timer */
1385 U8          entity;          /* Confirm type */
1386 PTR         cfmPtr;          /* Pointer to the structure for confirm */
1387 PTR         cfgPtr;          /* Pointer to the structure for request */
1388 #endif
1389 {
1390    S16               ret;        /* Return value            */
1391    CpjSecCfgCfmInfo  *secCfm;    /* Security confirm        */
1392    CpjReEstCfmInfo   *reEstCfm;  /* Reestablishment confirm */
1393    CpjCfgCfmInfo     *cfgCfm;    /* Config confirm          */
1394    U16               txId;       /* Transaction Id          */
1395    PjAsyncCfm        *tAsyncCfm; /* Pointer to the async Cfm*/
1396    CpjCfgReqInfo     *cfgReq;    /* Pointer to the config request */
1397    U8                cfmIdx;     /* index for loopoing */
1398
1399
1400    TRC3(pjUtlSaveCfmInfo)
1401
1402    RLOG_ARG4(L_DEBUG,DBG_UEID,  ueCb->key.ueId,
1403          "pjUtlSaveCfmInfo cellId(%d),cfmType(%d),startTmr(%d),entity(%d))",
1404          ueCb->key.cellId, cfmType, startTmr, entity);
1405
1406    /* Initialisations */
1407    ret      = ROK;
1408    secCfm   = NULLP;
1409    reEstCfm = NULLP;
1410    cfgCfm   = NULLP;
1411    cfgReq   = NULLP;
1412    txId     = ueCb->libInfo.nxtAvlbTxId;
1413
1414    if(txId == PJ_MAX_ASYNC_CFM)
1415    {
1416       /* The entire list is full, have to return negative confirms */
1417       RETVALUE(RFAILED);
1418    }
1419
1420    /* is entry already present */
1421    if(ueCb->libInfo.asyncCfm[txId] != NULLP)
1422    {
1423       RETVALUE(RFAILED);
1424    }
1425
1426    /* Allocate the structure */
1427    PJ_ALLOC(gCb,ueCb->libInfo.asyncCfm[txId],  sizeof(PjAsyncCfm));
1428    if(ueCb->libInfo.asyncCfm[txId]== NULLP)
1429    {
1430       RLOG0(L_FATAL, "Memory Allocation failed.");
1431       RETVALUE(RFAILED);
1432    }
1433
1434    /* Initialise the structure */
1435    tAsyncCfm   =   ueCb->libInfo.asyncCfm[txId];
1436    tAsyncCfm->libInitBitMask   =   ueCb->libInfo.tLibInitBitMask;
1437    tAsyncCfm->cmpInitBitMask   =   ueCb->libInfo.tCmpInitBitMask;
1438    tAsyncCfm->entity           =   entity;
1439    tAsyncCfm->startTmr         =   startTmr;
1440
1441    ueCb->libInfo.tLibInitBitMask =  0; 
1442    ueCb->libInfo.tCmpInitBitMask =  0; 
1443    
1444    /* Assign the values */
1445    if(cfmType  ==   PJ_SEC_ASYNC_CFM)
1446    {
1447       secCfm   =  (CpjSecCfgCfmInfo *)cfmPtr;
1448       tAsyncCfm->cfmType =  cfmType;
1449       tAsyncCfm->ueId    = secCfm->ueId;
1450       tAsyncCfm->cellId  = secCfm->cellId;
1451       tAsyncCfm->transId = secCfm->transId;
1452    }
1453    else if(cfmType  ==   PJ_REEST_ASYNC_CFM)
1454    {
1455       reEstCfm   =  (CpjReEstCfmInfo *)cfmPtr;
1456       tAsyncCfm->cfmType =  cfmType;
1457       tAsyncCfm->ueId    = reEstCfm->ueId;
1458       tAsyncCfm->cellId  = reEstCfm->cellId;
1459       tAsyncCfm->transId = reEstCfm->transId;
1460    }
1461    else if((cfmType  & PJ_CFG_ASYNC_CFM)  ||
1462            (cfmType  & PJ_CFG_REEST_ASYNC_CFM)||
1463            (cfmType  & PJ_CFG_UEDEL_ASYNC_CFM))
1464    {
1465       if(entity   == ENTPJ)
1466       {
1467          cfgCfm   =  (CpjCfgCfmInfo *)cfmPtr;
1468          cfgReq   =  (CpjCfgReqInfo *)cfgPtr;
1469
1470          tAsyncCfm->cfmType = cfmType;
1471          tAsyncCfm->ueId    = cfgCfm->ueId;
1472          tAsyncCfm->cellId  = cfgCfm->cellId;
1473          tAsyncCfm->transId = cfgCfm->transId;
1474          tAsyncCfm->numEnt  = cfgReq->numEnt;
1475
1476          for ( cfmIdx = 0; cfmIdx < cfgReq->numEnt; cfmIdx++ )
1477          {
1478             tAsyncCfm->cfmEnt[cfmIdx].status  = cfgCfm->cfmEnt[cfmIdx].status;
1479             tAsyncCfm->cfmEnt[cfmIdx].reason  = cfgCfm->cfmEnt[cfmIdx].reason;
1480             tAsyncCfm->cfmEnt[cfmIdx].rbId    = cfgCfm->cfmEnt[cfmIdx].rbId;
1481             tAsyncCfm->cfmEnt[cfmIdx].rbType  = cfgCfm->cfmEnt[cfmIdx].rbType;
1482             tAsyncCfm->cfmEnt[cfmIdx].cfgType = cfgReq->cfgEnt[cfmIdx].cfgType;
1483          }
1484       }
1485       else if(entity == ENTPJ)
1486       {
1487          CpjCfgCfmInfo  *pjCfgCfm;       /* Configuraiton Confirm */
1488          pjCfgCfm   =  (CpjCfgCfmInfo *)cfmPtr;
1489
1490          tAsyncCfm->cfmType = cfmType;
1491          tAsyncCfm->transId = pjCfgCfm->transId;
1492          tAsyncCfm->ueId    = pjCfgCfm->ueId;
1493          tAsyncCfm->cellId  = pjCfgCfm->cellId;
1494          tAsyncCfm->numEnt  = pjCfgCfm->numEnt;
1495
1496          for ( cfmIdx = 0; cfmIdx < pjCfgCfm->numEnt; cfmIdx++ )
1497          {
1498             tAsyncCfm->cfmEnt[cfmIdx].status  = 
1499                                  pjCfgCfm->cfmEnt[cfmIdx].status;
1500             tAsyncCfm->cfmEnt[cfmIdx].reason  = 
1501                                  pjCfgCfm->cfmEnt[cfmIdx].reason;
1502             tAsyncCfm->cfmEnt[cfmIdx].rbId    = 
1503                                  pjCfgCfm->cfmEnt[cfmIdx].rbId;
1504             tAsyncCfm->cfmEnt[cfmIdx].rbType  = 
1505                                  pjCfgCfm->cfmEnt[cfmIdx].rbType;
1506          }
1507       }
1508    }
1509
1510    /* Start timer */
1511    /* Timer should not be started when SEC is SYNC for ReEst Req
1512     * and for the subsequent config req for REEST. The config req
1513     * after reest req can still start the timer in the case comp being
1514     * async and sec being sync if it also adds a RB and a compInit has
1515     * to be sent . 
1516     * */
1517
1518    if(tAsyncCfm->startTmr  == TRUE)
1519    {
1520       if((pjChkTmr(gCb,(PTR)ueCb, PJ_EVT_OBD_WAIT_TMR)) == FALSE)
1521       {
1522          pjStartTmr(gCb,(PTR)ueCb, PJ_EVT_OBD_WAIT_TMR);
1523          ueCb->libInfo.crntTmrTxId  =  ueCb->libInfo.nxtAvlbTxId;
1524       }
1525    }
1526
1527    /* update nxtAvlbTxId to the next empty slot */
1528    for(cfmIdx = 0; cfmIdx < PJ_MAX_ASYNC_CFM; cfmIdx++)
1529    {
1530       ueCb->libInfo.nxtAvlbTxId = 
1531         (U16)((ueCb->libInfo.nxtAvlbTxId + 1) % PJ_MAX_ASYNC_CFM); /*KW_FIX*/
1532
1533       if(ueCb->libInfo.asyncCfm[ueCb->libInfo.nxtAvlbTxId] == NULLP)
1534       {
1535          break;
1536       }
1537    }
1538
1539    /* Cant find an empty slot ? */
1540    if(cfmIdx == PJ_MAX_ASYNC_CFM)
1541    {
1542       ueCb->libInfo.nxtAvlbTxId = PJ_MAX_ASYNC_CFM;
1543    }
1544
1545    RETVALUE(ret);
1546 }/* pjUtlSaveCfmInfo */
1547 \f
1548 /**
1549  *
1550  * @brief Handler to store update the bitmaks and send confirms if necessary.
1551  *       
1552  *
1553  * @b Description
1554  *        This function is invoked when receiving a InitCfm from Offboard.
1555  *        It updates the bit masks and checks if it is necesary to send a 
1556  *        confirm.
1557  *
1558  *  @return  S16
1559  *      -# ROK 
1560  *      -# RFAILED 
1561  *
1562 */
1563
1564 #ifdef ANSI
1565 PUBLIC S16 pjUtlUlHdlObdInitCfm
1566 (
1567 PjCb        *gCb,
1568 PjUlUeCb      *ueCb,           /* Pointer to UeCb */ 
1569 U16         txIdx,           /* Transaction Index for UeCb */
1570 U8          cfmType,         /* Confirm type */
1571 U8          maskVal          /* mask value */
1572 )
1573 #else
1574 PUBLIC S16 pjUtlUlHdlObdInitCfm(ueCb, txIdx, cfmType, maskVal)
1575 PjCb        *gCb;
1576 PjUlUeCb      *ueCb;           /* Pointer to UeCb */ 
1577 U16         txIdx;           /* Transaction Index for UeCb */
1578 U8          cfmType;         /* Confirm type */
1579 U8          maskVal;         /* mask value */
1580 #endif
1581 {
1582    CpjSecCfgCfmInfo *secCfgCfm;   /* Security config confirm */
1583    CpjReEstCfmInfo  *reEstCfm;    /* Reest config confirm */
1584    PjAsyncCfm       *asyncCfm;
1585    CpjCfgCfmInfo    *cfgCfm;
1586    U8               idx;
1587    S16              ret;
1588    TRC3(pjUtlUlHdlObdInitCfm)
1589
1590    RLOG_ARG4(L_DEBUG,DBG_UEID,  ueCb->key.ueId, 
1591          "pjUtlHdlUlObdInitCfm(ueCb(%d,%d),txIdx(%d),cfmType(%d),maskVal(%d))",
1592            ueCb->key.cellId, txIdx, cfmType, maskVal);
1593
1594    /* Initialisations */
1595    secCfgCfm   =  NULLP;
1596    reEstCfm    =  NULLP;
1597    cfgCfm      =  NULLP;
1598    asyncCfm    =  NULLP;
1599    ret         =  ROK;
1600
1601    if((txIdx  == PJ_MAX_ASYNC_CFM) ||
1602       (ueCb->libInfo.asyncCfm[txIdx] == NULLP))
1603    {
1604       RETVALUE(RFAILED);
1605    }
1606
1607    asyncCfm =  ueCb->libInfo.asyncCfm[txIdx];
1608
1609    if(cfmType & PJ_SEC_INIT_CFM)
1610    {
1611       /* Update bit mask and check if all confirms have been received */
1612       asyncCfm->libInitBitMask ^= (maskVal);
1613       ret = pjUtlUlHdlSecInitCfm(gCb,ueCb,txIdx,asyncCfm,secCfgCfm,reEstCfm);
1614    }
1615    else if(cfmType  & PJ_CMP_INIT_CFM)
1616    {
1617       /* Check if all confirms have been received */
1618       asyncCfm->cmpInitBitMask &= ~(1 << (maskVal - 1));
1619
1620       /* Update the status and reason for the received CmpInitCfm */
1621       for ( idx = 0; idx < asyncCfm->numEnt; idx++ )
1622       {
1623          if ( asyncCfm->cfmEnt[idx].rbId == maskVal)
1624          {
1625             asyncCfm->cfmEnt[idx].status = CPJ_CFG_CFM_OK;
1626             asyncCfm->cfmEnt[idx].reason = CPJ_CFG_REAS_NONE;
1627             break;
1628          }
1629       }
1630
1631       ret = pjUtlUlHdlCmpInitCfm(gCb,ueCb,txIdx,asyncCfm,cfgCfm);
1632    }
1633
1634    RETVALUE(ret);
1635 }/* pjUtlHdlUlObdInitCfm */
1636 \f
1637 /**
1638  *
1639  * @brief Handler for init off-board timer expiry.
1640  *
1641  *
1642  * @b Description
1643  *        This function is called when the off-board timer expires for
1644  *        a Init Req of a channel (either for ciphering/integrity/compression).
1645  *        This function sends a confirm with failure for SecCfgReq if the
1646  *        state of the RB is normal. It sends a confirm with failure
1647  *        for config request(only for RBs with Re-establishment Req, a failure 
1648  *        is stored in the confirm) if the state of the RB is re-establishment.
1649  *
1650  *  @param[in] ueCb    UE control block.
1651  *
1652  *
1653  *  @return  S16
1654  *      -# ROK
1655  */
1656
1657 #ifdef ANSI
1658 PUBLIC S16 pjUtlUlHdlInitObdTmrExp
1659 (
1660 PjCb     *gCb,
1661 PjUlUeCb *ueCb
1662 )
1663 #else
1664 PUBLIC S16 pjUtlUlHdlInitObdTmrExp(ueCb)
1665 PjCb     *gCb;
1666 PjUlUeCb *ueCb;
1667 #endif
1668 {
1669    S16               ret;           /* Return Value */
1670    CpjSecCfgCfmInfo  *secCfgCfm;    /* Security Cfg Confirm Info */
1671    CpjCfgCfmInfo     *cfgCfm;       /* Config Confirm Info */
1672    CpjReEstCfmInfo   *reEstCfm;     /* Reest config confirm */
1673    CpjCfgCfmInfo     *pjCfgCfm;
1674    PjLibInfo         *libInfo;      /* Off-board Info */
1675    PjAsyncCfm        *asyncCfm;     /* Async Cfm Info */
1676    PjCpjSapCb        *cpjSap;       /* CPJ SAP Control Block */
1677    U16               txIdx;         /* Tx Idx */
1678    U16               idx;           /* Index for looping */
1679    U16               cfgIdx;
1680
1681    TRC3(pjUtlHdlInitObdTmrExp)
1682
1683    RLOG2(L_DEBUG, "pjUtlHdlInitObdTmrExp(ueCb(%d,%d))",
1684                 ueCb->key.ueId, ueCb->key.cellId);
1685
1686    ret       = ROK;
1687    cpjSap    = &(gCb->u.ulCb->cpjSap);
1688    secCfgCfm = NULLP;
1689    libInfo   = &ueCb->libInfo;
1690    txIdx     = libInfo->crntTmrTxId;
1691
1692    /* Restart the timer */
1693    PJ_CHK_RESTART_OBD_TIMER(gCb,ueCb, txIdx);
1694
1695    /* Shouldnt happen, nevertheless, check */
1696    if( txIdx >= PJ_MAX_ASYNC_CFM || libInfo->asyncCfm[txIdx] == NULLP)
1697    {
1698       RETVALUE(ROK);
1699    }
1700
1701    asyncCfm =  libInfo->asyncCfm[txIdx];
1702
1703    /* Security confirm */
1704    if(asyncCfm->cfmType & PJ_SEC_ASYNC_CFM)
1705    {
1706       PJ_ALLOC(gCb,secCfgCfm, sizeof(CpjSecCfgCfmInfo));
1707 #if (ERRCLASS & ERRCLS_ADD_RES)
1708       if (secCfgCfm == NULLP)
1709       {
1710          RLOG0(L_FATAL, "Memory Allocation failed.");
1711          RETVALUE(RFAILED);
1712    }
1713 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1714       PJ_FILL_SEC_CFM_INFO(secCfgCfm, asyncCfm);
1715       secCfgCfm->status = CPJ_CFG_CFM_NOK;
1716       secCfgCfm->reason = CPJ_CFG_REAS_OBD_TIMEOUT;
1717
1718       PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
1719
1720       PjUiCpjSecCfgCfm(&(cpjSap->pst), cpjSap->suId, secCfgCfm);
1721    }
1722
1723    /* Configuration confirms */
1724    else if ((asyncCfm->cfmType & PJ_CFG_ASYNC_CFM) ||
1725             (asyncCfm->cfmType & PJ_CFG_REEST_ASYNC_CFM))
1726    {
1727       PJ_FILL_TIMEOUT_CFG_CFM_INFO(gCb,cfgCfm, asyncCfm);
1728
1729       PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
1730
1731       PjUiCpjCfgCfm(&(cpjSap->pst), cpjSap->suId, cfgCfm);
1732    }
1733    else if (asyncCfm->cfmType & PJ_REEST_ASYNC_CFM)
1734    {
1735       /* Send ReEstCfm */
1736       PJ_ALLOC(gCb,reEstCfm, sizeof(CpjReEstCfmInfo));
1737 #if (ERRCLASS & ERRCLS_ADD_RES)
1738       if (reEstCfm == NULLP)
1739       {
1740          RLOG0(L_FATAL, "Memory Allocation failed.");
1741          RETVALUE(RFAILED);
1742       }
1743 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1744       PJ_FILL_REEST_CFM_INFO(reEstCfm, asyncCfm, LCM_PRIM_NOK);
1745
1746       PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
1747
1748       PjUiCpjReEstCfm(&gCb->u.ulCb->cpjSap.pst, 
1749                        gCb->u.ulCb->cpjSap.suId, reEstCfm);
1750
1751       /* Send the config confirm also if any exists */
1752       cfgIdx   =  (U16)(txIdx + 1);  /*KW_FIX*/
1753
1754       for(idx = 0; idx < PJ_MAX_ASYNC_CFM; idx++, cfgIdx++)
1755       {
1756          cfgIdx %=   PJ_MAX_ASYNC_CFM;
1757          if((libInfo->asyncCfm[cfgIdx] != NULLP) &&
1758             (libInfo->asyncCfm[cfgIdx]->cfmType & PJ_CFG_REEST_ASYNC_CFM))
1759          {
1760             break;
1761          }
1762       }
1763
1764       /* This scenario occurs when only SRB1 is configured */
1765       if(idx == PJ_MAX_ASYNC_CFM)
1766       {
1767          RETVALUE(ROK);
1768       }
1769
1770       PJ_CHK_RESTART_OBD_TIMER(gCb,ueCb, cfgIdx);
1771       asyncCfm =  libInfo->asyncCfm[cfgIdx];
1772
1773       PJ_FILL_TIMEOUT_CFG_CFM_INFO(gCb,cfgCfm, asyncCfm);
1774
1775       PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
1776
1777       PjUiCpjCfgCfm(&(cpjSap->pst), cpjSap->suId, cfgCfm);
1778    }
1779    else if(asyncCfm->cfmType & PJ_CFG_UEDEL_ASYNC_CFM)
1780    {
1781       /* Delete ueCb entry from ueLstCp */
1782       pjStopTmr(gCb,(PTR)ueCb, PJ_EVT_OBD_WAIT_TMR);
1783       ret = cmHashListDelete(&(gCb->u.ulCb->ueLstCp), (PTR) ueCb);
1784       if (ret != ROK)
1785       {
1786
1787 #ifdef DEBUGP
1788          RLOG_ARG0(L_DEBUG,DBG_UEID,ueCb->key.ueId, 
1789                "pjUtlHdlInitObdTmrExp: cmHashListDelete Failed for ueCb.");
1790 #endif
1791       }
1792
1793       if ( asyncCfm->entity == ENTPJ )
1794       {
1795          PJ_ALLOC(gCb,cfgCfm, sizeof(CpjCfgCfmInfo));
1796 #if (ERRCLASS & ERRCLS_ADD_RES)
1797          if (cfgCfm == NULLP)
1798          {
1799             RLOG0(L_FATAL, "Memory Allocation failed.");
1800             RETVALUE(RFAILED);
1801          }
1802 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1803
1804          for ( idx = 0; idx < asyncCfm->numEnt; idx++)
1805          {
1806             cfgCfm->cfmEnt[idx].status = asyncCfm->cfmEnt[idx].status;
1807             cfgCfm->cfmEnt[idx].reason = asyncCfm->cfmEnt[idx].reason;
1808             cfgCfm->cfmEnt[idx].rbId   = asyncCfm->cfmEnt[idx].rbId;
1809             cfgCfm->cfmEnt[idx].rbType = asyncCfm->cfmEnt[idx].rbType;
1810          }
1811          cfgCfm->ueId    = asyncCfm->ueId;
1812          cfgCfm->cellId  = asyncCfm->cellId;
1813          cfgCfm->transId = asyncCfm->transId;
1814          cfgCfm->numEnt  = asyncCfm->numEnt;
1815
1816          /* delete all confirms present there */
1817          for(idx = 0; idx < PJ_MAX_ASYNC_CFM; idx++)
1818          {
1819             if(libInfo->asyncCfm[idx] != NULLP)
1820             {
1821                PJ_FREE(gCb,ueCb->libInfo.asyncCfm[idx], sizeof(PjAsyncCfm)); 
1822                ueCb->libInfo.asyncCfm[idx] = NULLP; 
1823             }
1824          }
1825
1826          PJ_FREE(gCb,ueCb, sizeof(PjUlUeCb));
1827          PjUiCpjCfgCfm(&(cpjSap->pst), cpjSap->suId, cfgCfm);
1828       }
1829       else if ( asyncCfm->entity == ENTPJ )
1830       {
1831          PJ_ALLOC(gCb,pjCfgCfm, sizeof(CpjCfgCfmInfo));
1832 #if (ERRCLASS & ERRCLS_ADD_RES)
1833          if (pjCfgCfm == NULLP)
1834          {
1835             RLOG0(L_FATAL, "Memory Allocation failed.");
1836             RETVALUE(RFAILED);
1837          }
1838 #endif /* ERRCLASS & ERRCLS_ADD_RES */
1839          for ( idx = 0; idx < asyncCfm->numEnt; idx++)
1840          {
1841             pjCfgCfm->cfmEnt[idx].status = asyncCfm->cfmEnt[idx].status;
1842             pjCfgCfm->cfmEnt[idx].reason = asyncCfm->cfmEnt[idx].reason;
1843             pjCfgCfm->cfmEnt[idx].rbId          = asyncCfm->cfmEnt[idx].rbId;
1844             pjCfgCfm->cfmEnt[idx].rbType        = asyncCfm->cfmEnt[idx].rbType;
1845          }
1846          pjCfgCfm->ueId    = asyncCfm->ueId;
1847          pjCfgCfm->cellId  = asyncCfm->cellId;
1848          pjCfgCfm->transId = asyncCfm->transId;
1849          pjCfgCfm->numEnt  = asyncCfm->numEnt;
1850
1851          /* delete all confirms present there */
1852          for(idx = 0; idx < PJ_MAX_ASYNC_CFM; idx++)
1853          {
1854             if(libInfo->asyncCfm[idx] != NULLP)
1855             {
1856                PJ_FREE(gCb,ueCb->libInfo.asyncCfm[idx], sizeof(PjAsyncCfm)); 
1857                ueCb->libInfo.asyncCfm[idx] = NULLP; 
1858             }
1859          }
1860
1861          PJ_FREE(gCb,ueCb, sizeof(PjUlUeCb));
1862          PjUiCpjCfgCfm(&(cpjSap->pst), cpjSap->suId, pjCfgCfm);
1863       }
1864    }
1865
1866    RETVALUE(ret);
1867 } /* pjHdlUeDelWaitTmrExp */
1868
1869 \f
1870 /**
1871  *
1872  * @brief 
1873  *
1874  *        Function to sent the REESTABLISHMENT COMPPLETE 
1875  *        to the RRC.
1876  *
1877  * @b Description:
1878  *
1879  *        This function 
1880  *        1. Sends a ReEstablishment Confirm for normal reestablishment.
1881  *        2. Sends a SDU status confirm for handover reestablishment.
1882  *
1883  *  @param[in] ueCb   UE Control Block
1884  *
1885  *  @return  S16
1886  *      -# ROK 
1887  *      -# RFAILED
1888  *
1889  */
1890 #ifdef ANSI
1891 PUBLIC S16 pjUtlUlSndSduStaCfm
1892 (
1893 PjCb         *gCb,
1894 PjUlUeCb     *ueCb           /* UE Control Block */ 
1895 )
1896 #else
1897 PUBLIC S16 pjUtlUlSndSduStaCfm(gCb, ueCb)  
1898 PjCb         *gCb;
1899 PjUlUeCb     *ueCb;           /* UE Control Block */ 
1900 #endif
1901 {
1902    U8       rbCnt;
1903    CpjSduStaCfmInfo  *cfmInfo;
1904    UdxSduStaCfmInfo  *udxCfmInfo;
1905    UdxSduStaInfo tempDlStaInfo[PJ_MAX_DRB_PER_UE] = {{0}};
1906    U8 rbId;
1907    U8 numRb = 0;
1908    PjUlHoCfmInfo *hoCfmInfo;
1909    CpjSduStaInfo  *staInfo;
1910    Bool rbPres;
1911    PjCpjSapCb     *cpjSap;
1912    PjUdxUlSapCb   *udxSap;
1913    
1914
1915    TRC2(pjUtlUlSndSduStaCfm); 
1916
1917    RLOG2(L_DEBUG, "pjUtlUlSndSduStaCfm(ueCb(%d,%d))",
1918                 ueCb->key.ueId, ueCb->key.cellId);
1919
1920    cpjSap = &(gCb->u.ulCb->cpjSap);
1921    if(SGetSBuf(cpjSap->pst.region,cpjSap->pst.pool,(Data **)&cfmInfo,
1922       sizeof (CpjSduStaCfmInfo)) != ROK)
1923    {
1924       RLOG0(L_FATAL, "Memory Allocation failed.");
1925       RETVALUE(RFAILED);
1926    }
1927
1928    cfmInfo->ueId = ueCb->key.ueId;
1929    cfmInfo->cellId = ueCb->key.cellId;
1930    cfmInfo->transId = ueCb->hoInfo->transId;
1931    cfmInfo->reason = CPJ_CFG_REAS_NONE;
1932    udxCfmInfo      = ueCb->hoInfo->staCfm;
1933
1934    for(rbCnt = 0; rbCnt < udxCfmInfo->numRb; rbCnt++)
1935    {
1936       /*
1937       - Check for rbId and copy the info to index=(rbId)
1938       */
1939       rbId = udxCfmInfo->sduStaInfo[rbCnt].rbId;
1940       if(udxCfmInfo->sduStaInfo[rbCnt].dlSduStaInfo.hoPres == TRUE)
1941       {
1942          tempDlStaInfo[rbId].rbId = udxCfmInfo->sduStaInfo[rbCnt].rbId;
1943          tempDlStaInfo[rbId].dir = udxCfmInfo->sduStaInfo[rbCnt].dir;
1944          tempDlStaInfo[rbId].dlSduStaInfo.count = udxCfmInfo->sduStaInfo[rbCnt].dlSduStaInfo.count;
1945          tempDlStaInfo[rbId].dlSduStaInfo.hoPres = TRUE;
1946       }
1947    } 
1948
1949    for(rbCnt = 0;
1950       ((rbCnt < PJ_MAX_DRB_PER_UE) && (numRb < CPJ_MAX_DRB)); rbCnt++)
1951    {
1952       rbPres     = FALSE;
1953       hoCfmInfo   =  &ueCb->hoInfo->hoCfmInfo[rbCnt];
1954       staInfo     =  &cfmInfo->sduStaInfo[numRb];
1955       memset((void *)staInfo,0,sizeof(CpjSduStaInfo));
1956       if(hoCfmInfo->pres == TRUE)
1957       {                          
1958          rbPres = TRUE;
1959          staInfo->rbId  =  hoCfmInfo->rbId;
1960          staInfo->dir   |= hoCfmInfo->dir;
1961          staInfo->snLen = ueCb->drbCb[hoCfmInfo->rbId]->snLen;
1962          staInfo->ulSduStaInfo.numBits   =  hoCfmInfo->numBits;
1963          if (hoCfmInfo->numBits > 0) 
1964          {
1965             /* numBits is always filled as multiple's of 8 */
1966             cpjSap = &(gCb->u.ulCb->cpjSap);
1967             if(SGetSBuf(cpjSap->pst.region,cpjSap->pst.pool,
1968                         (Data **)&staInfo->ulSduStaInfo.ulBitMap,
1969                         sizeof (U8) * (hoCfmInfo->numBits / 8)) != ROK)
1970             {
1971                RLOG0(L_FATAL, "Memory Allocation failed.");
1972                RETVALUE(RFAILED);
1973             }
1974             PJ_MEM_CPY(staInfo->ulSduStaInfo.ulBitMap, hoCfmInfo->ulBitMap, (hoCfmInfo->numBits / 8));
1975             PJ_FREE(gCb, hoCfmInfo->ulBitMap, sizeof(U8) * (hoCfmInfo->numBits / 8));
1976          }
1977          staInfo->ulSduStaInfo.count     =  hoCfmInfo->count;
1978       }
1979       if(tempDlStaInfo[rbCnt].dlSduStaInfo.hoPres == TRUE)
1980       { 
1981          rbPres = TRUE;
1982          staInfo->rbId  =  tempDlStaInfo[rbCnt].rbId;
1983          staInfo->dir   |=  tempDlStaInfo[rbCnt].dir;
1984          staInfo->snLen = ueCb->drbCb[staInfo->rbId]->snLen;
1985          staInfo->dlSduStaInfo.count = tempDlStaInfo[rbCnt].dlSduStaInfo.count;
1986       }
1987       if(rbPres != TRUE)
1988       {
1989          continue;
1990       }
1991       else
1992       {
1993         numRb++;
1994       }
1995    }
1996
1997    cfmInfo->numRb = numRb; 
1998    cfmInfo->status = ROK;
1999    cfmInfo->reason = CPJ_CFG_REAS_NONE;
2000    PJ_FREE(gCb,ueCb->hoInfo->hoCfmInfo,
2001               (PJ_MAX_DRB_PER_UE * sizeof(PjUlHoCfmInfo)));
2002    /* Memory leak fix ccpu00135359 */
2003    udxSap = PJ_GET_UL_UDX_SAP(gCb);
2004    PJ_PST_FREE(udxSap->pst.region, udxSap->pst.pool,ueCb->hoInfo->staCfm,
2005                 sizeof (UdxSduStaCfmInfo));
2006    PJ_FREE(gCb,ueCb->hoInfo, sizeof(PjUlHoInfo));
2007    
2008    PjUiCpjSduStaCfm(&gCb->u.ulCb->cpjSap.pst, 
2009                      gCb->u.ulCb->cpjSap.suId, cfmInfo);
2010     
2011    RETVALUE(ROK);
2012 } /* pjUtlSndSduStaCfm */
2013
2014 /**
2015  *
2016  * @brief Handler to clean up all the PDCP Control Blocks.
2017  *       
2018  *
2019  * @b Description
2020  *        This function is invoked by LMM to shutdown the
2021  *        layer. This cleans up recBuf and txBuf of all the
2022  *        PDCP RBs in all the UEs.
2023  *
2024  *  @return  S16
2025  *      -# ROK 
2026  *      -# RFAILED 
2027  *
2028 */
2029
2030 #ifdef ANSI
2031 PUBLIC S16 pjUtlUlShutdown
2032 (
2033 PjCb  *gCb
2034 )
2035 #else
2036 PUBLIC S16 pjUtlUlShutdown()
2037 PjCb   *gCb;
2038 #endif
2039 {
2040    S16         ret;              /* Return Value */
2041    PjUlUeCb      *ueCb;            /* UE Control Block */
2042    PjUlUeCb      *prevUeCb;        /* Previos UE Control Block */
2043    PjUlRbCb        *rbCb;            /* RB Control Block */
2044    PjUlRbCb        **rbCbLst;        /* RB Control Block List */
2045    PjSec       *secInfo;          /* Security info of UE */
2046    U8          idx;              /* Index for RBs */
2047 #ifdef LTE_L2_MEAS_COMMENT
2048    PjL2MeasEvtCb  *measEvtCb = NULLP;
2049 #endif
2050    TRC3(pjUtlShutdown)
2051
2052    RLOG0(L_DEBUG, "pjUtlShutdown()");
2053
2054    ret      = ROK;
2055    ueCb     = NULLP;
2056    prevUeCb = NULLP;
2057    rbCb     = NULLP;
2058    rbCbLst  = NULLP;
2059    idx      = 0;
2060
2061    /* Until no more ueCb is ueLstCp hash list get and delete ueCb */
2062    while (cmHashListGetNext(&(gCb->u.ulCb->ueLstCp), (PTR) prevUeCb, (PTR *)&ueCb) == ROK)
2063    {
2064       if ( ueCb != NULLP )
2065       {
2066 #if (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC))
2067          if (ueCb->libInfo.obdTmr.tmrEvnt == PJ_EVT_OBD_TMR)
2068          {
2069             pjStopTmr(gCb,(PTR)ueCb, PJ_EVT_OBD_TMR);
2070          }
2071 #endif
2072          rbCbLst = ueCb->srbCb;
2073          for (idx = 0; idx < PJ_MAX_SRB_PER_UE; idx++)
2074          {
2075              rbCb = rbCbLst[idx];
2076              if (rbCb != NULLP)
2077              {
2078                /* Free the Buffers of RbCb */
2079                pjUtlUlFreeRb(gCb,rbCb);
2080              }
2081          }
2082          rbCbLst = ueCb->drbCb;
2083          for (idx = 0; idx < PJ_MAX_DRB_PER_UE; idx++)
2084          {
2085              rbCb = rbCbLst[idx];
2086              if (rbCb != NULLP)
2087              {
2088                 pjUtlUlFreeRb(gCb,rbCb);
2089              }
2090          }
2091          /* Close all the context info for offboarding */
2092          secInfo = &(ueCb->secInfo);
2093 #ifdef INTEL_QAT_DP
2094                  pjUtlUlIntClose(gCb,ueCb->secInfo.cpIntSessCxtId); 
2095                  pjUtlUlCipherClose(gCb,ueCb->secInfo.cpCiphSessCxtId);
2096                  pjUtlUlCipherClose(gCb,ueCb->secInfo.upCiphSessCxtId);
2097 #else
2098          pjUtlUlCipherClose(gCb,secInfo->cpCxtId);
2099          pjUtlUlCipherClose(gCb,secInfo->upCxtId);
2100          pjUtlUlIntClose(gCb,secInfo->intCxtId);
2101 #endif
2102          /* Delete hoInfo if present */
2103          if (ueCb->hoInfo != NULLP)
2104          {
2105             for (idx = 0; idx < PJ_MAX_DRB_PER_UE; idx++)
2106             {
2107                if (ueCb->hoInfo->hoCfmInfo[idx].pres == TRUE)
2108                {
2109                   PJ_FREE(gCb,ueCb->hoInfo->hoCfmInfo[idx].ulBitMap,
2110                         (ueCb->hoInfo->hoCfmInfo[idx].numBits % 8)?
2111                         ((ueCb->hoInfo->hoCfmInfo[idx].numBits / 8) + 1):
2112                         (ueCb->hoInfo->hoCfmInfo[idx].numBits / 8 ));
2113                }
2114             }
2115
2116             PJ_FREE(gCb,ueCb->hoInfo->hoCfmInfo,                         \
2117                            (PJ_MAX_DRB_PER_UE * sizeof(PjUlHoCfmInfo)));
2118             PJ_FREE(gCb,ueCb->hoInfo, sizeof(PjUlHoInfo));                 
2119          }
2120       }
2121       prevUeCb = ueCb;
2122    }
2123 #ifdef LTE_L2_MEAS_COMMENT
2124    for(idx = 0; idx < PJ_MAX_L2MEAS_EVT; idx++)
2125    {
2126       if(pjCb.pjL2Cb.pjMeasEvtCb[idx] != NULLP)
2127       {
2128          measEvtCb = pjCb.pjL2Cb.pjMeasEvtCb[idx];
2129          pjStopTmr(gCb,(PTR)measEvtCb, PJ_EVT_L2_TMR);
2130          gCb.pjL2Cb.pjNumMeas--;
2131          PJ_FREE(gCb,measEvtCb, sizeof(PjL2MeasEvtCb));
2132          pjCb.pjL2Cb.pjMeasEvtCb[idx] = NULLP;
2133       }
2134    }
2135 #endif
2136    ret = pjDbmUlDeInit(gCb);
2137 #if (ERRCLASS & ERRCLS_DEBUG)
2138    if (ret != ROK)
2139    {
2140       RLOG0(L_FATAL, "PDCP UL DeInitialization Failed.\n");
2141    }
2142 #endif /* ERRCLASS & ERRCLS_DEBUG */
2143    RETVALUE(ret);
2144 }
2145
2146 /**
2147  * 
2148  * @brief 
2149  *
2150  *        Handler to free a PDCP Control Block.
2151  *
2152  * @b Description:
2153  * 
2154  *        This function frees the txBuf and rxBuf in a PDCP control block.
2155  *        and closes the compression channel opened. It stops the timers 
2156  *        of this control block if they are running.
2157  *
2158  *  @param[in]  pst        Post structure 
2159  *  @param[in]  secCxt     Context for Integrity protection/verification 
2160  *  @param[in]  ctxId      Integrity Context Id
2161  *
2162  *
2163  *  @return  S16
2164  *      -# ROK 
2165  *
2166  */
2167
2168 #ifdef ANSI
2169 PUBLIC Void pjUtlUlFreeRb
2170 (
2171 PjCb     *gCb,
2172 PjUlRbCb *pjRbCb
2173 )
2174 #else
2175 PUBLIC Void pjUtlUlFreeRb(pjRbCb)
2176 PjCb     *gCb;
2177 PjUlRbCb *pjRbCb;
2178 #endif
2179 {
2180    TRC3(pjUtlFreeUlRb)
2181
2182    RLOG0(L_DEBUG, "pjUtlFreeRb()");
2183
2184 #if (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC))
2185    if (pjRbCb->ulCb.obdTmr.tmrEvnt == PJ_EVT_UL_OBD_TMR)
2186    {
2187        pjStopTmr(gCb,(PTR)pjRbCb, PJ_EVT_UL_OBD_TMR);
2188    }
2189 #endif
2190    pjDbmRxDeInit(gCb,&(pjRbCb->ulCb.recBuf));
2191    
2192    pjUtlCmpClose(gCb,pjRbCb->cmpCxtId);
2193    /*pj004.201 Adding of Missing Trace in LTE RLC PDCP*/
2194    RETVOID;
2195 }
2196
2197 /* pj005.201 added function to send data forward indication message */
2198 /**
2199  * 
2200  * @brief 
2201  *
2202  *        Handler to send Data Fwd Indication
2203  *
2204  * @b Description:
2205  *      This function sends Data Fwd Indication message to PDCP user 
2206  *
2207  *  @param[in]  pjRbCb     PDCP RbCb
2208  *  @param[in]  datFwdInd  Data forward indication
2209  *
2210  *
2211  *  @return  S16
2212  *      -# ROK 
2213  *
2214  */
2215
2216 #ifdef ANSI
2217 PUBLIC S16 pjUtlUlSndDatFwdInd
2218 (
2219 PjCb             *gCb,
2220 PjUlRbCb           *pjRbCb,
2221 PjuDatFwdIndInfo *datFwdInd
2222 )
2223 #else
2224 PUBLIC S16 pjUtlUlSndDatFwdInd(pjRbCb, datFwdInd)
2225 PjCb             *gCb;
2226 PjUlRbCb           *pjRbCb;
2227 PjuDatFwdIndInfo *datFwdInd;
2228 #endif
2229 {
2230    CmLtePdcpId  *pdcpId;
2231    PjPjuSapCb   *pjuSap;
2232    CmLtePdcpId   pdcpIdTmp;
2233
2234    TRC3(pjUtlUlSndDatFwdInd)
2235    
2236    RLOG0(L_DEBUG, "pjUtlSndDatFwdInd()");
2237
2238    pjuSap   = &(gCb->u.ulCb->pjuSap[PJ_DRB_SAP]);
2239    pdcpId = &pdcpIdTmp;
2240
2241    if(pdcpId != NULLP)
2242    {
2243       pdcpId->ueId   =  pjRbCb->ueCb->key.ueId;
2244       pdcpId->cellId =  pjRbCb->ueCb->key.cellId;
2245       pdcpId->rbId   =  pjRbCb->rbId;
2246       pdcpId->rbType =  pjRbCb->rbType;
2247       
2248       gCb->pjGenSts.numPktsFrwd += datFwdInd->numSdus;
2249       /* If trace flag is enabled send the trace indication */
2250       if(gCb->init.trc == TRUE)
2251       {                       
2252          /* Populate the trace params */
2253          pjLmmSendTrc(gCb,EVTPJUDATFWDIND, NULLP);
2254       }
2255       PjUiPjuDatFwdInd(&(pjuSap->pst), pjuSap->suId, pdcpId, datFwdInd);
2256    }
2257
2258   RETVALUE(ROK);
2259
2260 }/* end of pjUtlSndDatFwdInd */
2261
2262 /**
2263  * 
2264  * @brief 
2265  *
2266  *        Handler to send Data Fwd Indication
2267  *
2268  * @b Description:
2269  *      This function sends Data Fwd Indication message to PDCP user 
2270  *
2271  *  @param[in]  pjRbCb     PDCP RbCb
2272  *  @param[in]  datFwdInd  Data forward indication
2273  *
2274  *
2275  *  @return  S16
2276  *      -# ROK 
2277  *
2278  */
2279
2280 #ifdef ANSI
2281 PUBLIC S16 pjUtlUlSndUlStaRep
2282 (
2283 PjCb             *gCb,
2284 PjUlRbCb         *pjRbCb,
2285 Buffer           *sta
2286 )
2287 #else
2288 PUBLIC S16 pjUtlUlSndUlStaRep(pjRbCb, sta)
2289 PjCb             *gCb;
2290 PjUlRbCb         *pjRbCb;
2291 Buffer           *sta;
2292 #endif
2293 {
2294    PjUdxUlSapCb *udxSap;
2295    UdxUlStaRepInfo   *staRep;
2296    S16               ret = ROK;           /* Return Value */
2297    
2298    udxSap = PJ_GET_UL_UDX_SAP(gCb);
2299
2300    TRC3(pjUtlUlSndUlStaRep)
2301    
2302    RLOG0(L_DEBUG, "pjUtlUlSndUlStaRep()");
2303
2304    PJ_ALLOC_BUF_SHRABL(udxSap->pst, staRep,
2305                      sizeof (UdxUlStaRepInfo), ret);
2306                      
2307    if(ret != ROK)
2308    {
2309      staRep = NULLP;
2310    }
2311
2312    if(staRep != NULLP)
2313    {
2314       staRep->pdcpId.ueId   =  pjRbCb->ueCb->key.ueId;
2315       staRep->pdcpId.cellId =  pjRbCb->ueCb->key.cellId;
2316       staRep->pdcpId.rbId   =  pjRbCb->rbId;
2317       staRep->pdcpId.rbType =  pjRbCb->rbType;
2318       staRep->sta = sta;
2319
2320       PjUlUdxUlStaRep(&(udxSap->pst), udxSap->spId, staRep);
2321    }
2322    else
2323    {
2324       PJ_FREE_BUF(sta);
2325    }
2326
2327    RETVALUE(ROK);
2328 }/* end of pjUtlSndDatFwdInd */
2329
2330
2331 /**
2332  * 
2333  * @brief 
2334  *
2335  *        Handler to send Feedback packet to DL-PDCP
2336  *
2337  * @b Description:
2338  *      This function sends Feedback packet to DL-PDCP 
2339  *
2340  *  @param[in]  pjCb       PDCP global control block
2341  *  @param[in]  pjRbCb     PDCP RbCb
2342  *  @param[in]  fbPkt      Feedback packet
2343  *
2344  *
2345  *  @return  S16
2346  *      -# ROK 
2347  *
2348  */
2349
2350 #ifdef ANSI
2351 PUBLIC S16 pjUtlUlSndUlRohcFdbk
2352 (
2353 PjCb             *gCb,
2354 PjUlRbCb         *pjRbCb,
2355 Buffer           *fbPkt
2356 )
2357 #else
2358 PUBLIC S16 pjUtlUlSndUlRohcFdbk(gCb, pjRbCb, fbPkt)
2359 PjCb             *gCb;
2360 PjUlRbCb         *pjRbCb;
2361 Buffer           *fbPkt;
2362 #endif
2363 {
2364    PjUdxUlSapCb      *udxSap;
2365    UdxUlFdbkPktInfo  *fdbkPktInfo;
2366    S16               ret = ROK;
2367    
2368    udxSap = PJ_GET_UL_UDX_SAP(gCb);
2369
2370    TRC3(pjUtlUlSndUlRohcFdbk)
2371    
2372    RLOG0(L_DEBUG, "pjUtlUlSndUlRohcFdbk()");
2373
2374    PJ_ALLOC_BUF_SHRABL(udxSap->pst, fdbkPktInfo,
2375       sizeof (UdxUlFdbkPktInfo), ret);
2376    if(ret != ROK)
2377    {
2378       fdbkPktInfo= NULLP;
2379    }
2380
2381    if(fdbkPktInfo != NULLP)
2382    {
2383       fdbkPktInfo->pdcpId.ueId   =  pjRbCb->ueCb->key.ueId;
2384       fdbkPktInfo->pdcpId.cellId =  pjRbCb->ueCb->key.cellId;
2385       fdbkPktInfo->pdcpId.rbId   =  pjRbCb->rbId;
2386       fdbkPktInfo->pdcpId.rbType =  pjRbCb->rbType;
2387       fdbkPktInfo->fbPkt = fbPkt;
2388
2389       PjUlUdxUlFdbkPktInfo(&(udxSap->pst), udxSap->spId, fdbkPktInfo);
2390    }
2391    else
2392    {
2393       PJ_FREE_BUF(fbPkt);
2394    }
2395
2396    RETVALUE(ROK);
2397 }/* end of pjUtlUlSndUlRohcFdbk */
2398
2399 /* pj005.201 added support for L2 Measurement */
2400 #ifdef LTE_L2_MEAS
2401 /**
2402  *
2403  * @brief Function to initialise measurement
2404  *
2405  * @b Description
2406  *
2407  * @param[in]  gCb     PDCP Instance Control Block
2408  *
2409  *  @return  Void
2410  *
2411  */
2412 S16 pjUtlL2MeasUlInit(PjCb *gCb)
2413 {
2414    U16   cntr;
2415
2416    gCb->u.ulCb->pjL2Cb.pjNumMeas=0;
2417    for(cntr = 0; cntr < LPJ_MAX_L2MEAS; cntr++)
2418    {
2419       cmMemset((U8 *)&(gCb->u.ulCb->pjL2Cb.pjL2EvtCb[cntr]), 0, sizeof(PjL2MeasEvtCb));
2420    }
2421    gCb->u.ulCb->pjL2Cb.pjL2EvtCb[PJ_L2MEAS_UL_LOSS].measCb.measType = LPJ_L2MEAS_UL_LOSS;
2422    gCb->u.ulCb->pjL2Cb.pjL2EvtCb[PJ_L2CPU_PERCORE_STATS].measCb.measType = LPJ_L2CPU_PERCORE_STATS;
2423    gCb->u.ulCb->pjL2Cb.pjL2EvtCb[PJ_L2MEM_PERPOOL_STATS].measCb.measType = LPJ_L2MEM_PERPOOL_STATS;
2424    /* initialize the timer value for memory and CPU utilization */
2425    gCb->u.ulCb->pjL2Cb.measTmrCfg.enb = TRUE;
2426    gCb->u.ulCb->pjL2Cb.measTmrCfg.val = CM_MEM_CPU_UITL_INFO_TMR_VAL;
2427    cmInitTimers(&gCb->u.ulCb->pjL2Cb.measTmr,PJ_L2_MAX_TIMERS); 
2428    
2429    RETVALUE(ROK);
2430 }
2431 /**
2432  *
2433  * @brief Handler for resetting the DL measurement counters 
2434  *
2435  *
2436  * @b Description
2437  *
2438  * @param[in] measCb    Measurement Control Block.
2439  *
2440  *
2441  * @return  Void
2442  */
2443 #ifdef ANSI
2444
2445 PUBLIC Void pjUtlResetUlL2MeasCntr
2446 (
2447 PjCb         *tPjCb,
2448 PjL2MeasCb   *measCb,
2449 U8           measType
2450 )
2451 #else
2452 PUBLIC Void pjUtlResetUlL2MeasCntr(tPjCb, measCb, measType)
2453 PjCb         *tPjCb;
2454 PjL2MeasCb   *measCb;
2455 U8           measType;
2456 #endif
2457 {
2458    if (measCb->measType & LPJ_L2MEAS_UL_LOSS)
2459    {
2460       U32 qciIdx;
2461       for(qciIdx = 1; qciIdx < LPJ_MAX_QCI; qciIdx++)
2462       {
2463          U8 qci = measCb->qci[qciIdx];
2464
2465          measCb->measData[qci].ulLoss.val = 0;
2466          measCb->measData[qci].ulLoss.numPkts = 0;
2467          tPjCb->u.ulCb->pjL2Cb.measOn[qci] &= ~LPJ_L2MEAS_UL_LOSS;
2468       }
2469    }
2470    if (measCb->measType & LPJ_L2MEM_PERPOOL_STATS)
2471    {
2472      tPjCb->u.ulCb->pjL2Cb.memUtilizationMask = 0;
2473      /* Clear Memory Statistics */
2474      cmClearMemUtilizationCounter(&(measCb->memInfo));
2475    }
2476    if(measCb->measType & LPJ_L2CPU_PERCORE_STATS )
2477    {
2478      tPjCb->u.ulCb->pjL2Cb.cpuUtilizationMask = 0;
2479    }
2480
2481 }
2482
2483 \f
2484 /**
2485  *
2486  * @brief Handler for Sending Negative confirm .
2487  *
2488  *
2489  * @b Description
2490  *        This function is called when the l2 measurement cannot be started
2491  *        This function sends  negative confirm for all the requests
2492  *
2493  *  @param[in] measReqEvt    Measurement Req Structure
2494  *
2495  *
2496  *  @return  S16
2497  *      -# ROK
2498  */
2499
2500 #ifdef ANSI
2501 PUBLIC S16 pjUtlSndUlL2MeasNCfm
2502 (
2503 PjCb            *gCb,
2504 PjL2MeasCfmEvt  *measCfmEvt
2505 )
2506 #else
2507 PUBLIC S16 pjUtlSndUlL2MeasNCfm(gCb, measCfmEvt)
2508 PjCb            *gCb;
2509 PjL2MeasCfmEvt  *measCfmEvt;
2510 #endif
2511 {
2512
2513    TRC3(pjUtlSndL2MeasNCfm)
2514
2515    PjMiLpjL2MeasCfm(&gCb->pjGenCfg.lmPst, measCfmEvt);
2516
2517    RETVALUE(ROK);
2518 } /* pjUtlSndL2MeasNCfm */
2519
2520 /**
2521  *
2522  * @brief Handler for storing address of MeasData in rbCb at right index
2523  *
2524  *
2525  * @b Description
2526  *        Handler for storing address of MeasData in rbCb at right index.
2527  *
2528  *  @param[in] 
2529  *  @param[out] 
2530  *  @param[in] 
2531  *
2532  *
2533  *  @return  S16
2534  *      -# ROK
2535  */
2536 #ifdef ANSI
2537 PUBLIC Void pjUtlPlcMeasDatInUlL2Sts
2538 (
2539 PjL2Cntr       *measData, 
2540 PjL2MeasRbCb   *rbL2Cb,
2541 U8             measType
2542 )
2543 #else
2544 PUBLIC Void pjUtlPlcMeasDatInUlL2Sts(measData, rbL2Cb, measType)
2545 PjL2Cntr       *measData; 
2546 PjL2MeasRbCb   *rbL2Cb;
2547 U8             measType;
2548 #endif
2549 {
2550    TRC3(pjUtlPlcMeasDatInUlL2Sts)
2551    
2552    /* We should check the number of measType in the request. This can be done 
2553     * by looking at each bit in the measType. Also store the measData in the 
2554     * correct index of l2Sts in RbCb.
2555     * */
2556
2557     if(measType & LPJ_L2MEAS_UL_LOSS)
2558     {
2559          rbL2Cb->l2Sts[PJ_L2MEAS_UL_LOSS] = measData;
2560     }
2561
2562 }/* End of pjUtlPlcMeasDatInUlL2Sts */
2563 #endif /* LTE_L2_MEAS */
2564
2565
2566 /**
2567 @brief 
2568 This function processes Data Resume request received from the Application.
2569  *  @param[in] gCb      PDCP Instance Control block 
2570  *  @param[in] ueCb     Uplink UeCb 
2571  *  @return S16
2572  *      -# Success : ROK
2573  *      -# Failure : RFAILED
2574 */
2575 #ifdef ANSI
2576 PUBLIC S16 pjUtlUlPrcsDatResume
2577 (
2578 PjCb                 *gCb,
2579 CpjDatResumeReqInfo  *datResReq
2580 )
2581 #else
2582 PUBLIC S16 pjUtlUlPrcsDatResume(gCb, datResReq)
2583 PjCb                 *gCb;
2584 CpjDatResumeReqInfo  *datResReq;
2585 #endif
2586 {
2587    U8 rbCnt;
2588    PjUlRbCb *pjRbCb = NULLP;
2589    PjUlUeCb *ueCb= NULLP;
2590    
2591    pjDbmFetchUlUeCb(gCb, datResReq->ueId, datResReq->cellId, &ueCb);
2592    if(!ueCb)
2593    {
2594       RLOG_ARG1(L_ERROR, DBG_CELLID, datResReq->cellId,"UeId[%u] not found",
2595             datResReq->ueId);
2596       RETVALUE(RFAILED);
2597    }   
2598
2599    for(rbCnt = 0; rbCnt < PJ_MAX_DRB_PER_UE; rbCnt ++)
2600    {
2601       /* Check of rbCb available */
2602       if( (pjRbCb = ueCb->drbCb[rbCnt]) == NULLP)
2603       {
2604          continue;
2605       }
2606 #ifdef LTE_L2_MEAS
2607       pjRbCb->ulCb.nxtSubSn = (pjRbCb->ulCb.rxNext % (1 << pjRbCb->snLen));
2608 #endif
2609
2610       /* Process the packets in dlPktQ */
2611       pjUlmProcessUlPktQ(gCb, pjRbCb);
2612       pjRbCb->state = PJ_STATE_NORMAL;
2613    }
2614    ueCb->libInfo.state = PJ_STATE_NORMAL;
2615    RETVALUE(ROK);
2616 }
2617
2618 PUBLIC Void pjUtlEmptyUlPktList(PjCb *gCb, PjUlRbCb *pjRbCb)
2619 {
2620    PjUlPkt *ulPkt;
2621    CmLListCp *ulPktLst = &pjRbCb->ulCb.ulPktLst;
2622    while(ulPktLst->first)
2623    {
2624       ulPkt = (PjUlPkt *)(ulPktLst->first->node);
2625       cmLListDelFrm(ulPktLst, ulPktLst->first);
2626       PJ_FREE_BUF(ulPkt->pdu);
2627       PJ_FREE(gCb, ulPkt, sizeof(PjUlPkt));
2628    }
2629    RETVOID;
2630 }
2631
2632 void dumpPDCPUlRbInformation(PjUlRbCb* ulRbCb, U16 ueId)
2633 {
2634    PjUlCb* ulCb = &ulRbCb->ulCb;
2635
2636 #ifndef ALIGN_64BIT
2637    RTLIN_DUMP_DEBUG("UE [%u] PDCP UL RB numEntries = %lu\n",ueId, ulCb->recBuf.numEntries);
2638 #else
2639    RTLIN_DUMP_DEBUG("UE [%u] PDCP UL RB numEntries = %u\n",ueId, ulCb->recBuf.numEntries);
2640 #endif
2641 }
2642
2643
2644 void DumpPDCPUlDebugInformation(void)
2645 {
2646    PjCb* ulInst = pjCb[0]; /* TODO: check whether UL is 0 or 1 */
2647
2648    PjUlgCb* ulgCb = ulInst->u.ulCb;
2649
2650    PjUlUeCb *ueCb = NULLP; 
2651    RTLIN_DUMP_DEBUG("PDCP UL Information\n");
2652    RTLIN_DUMP_DEBUG("===================\n");
2653    
2654    /* Until no more ueCb is ueLstCp hash list get and delete ueCb */
2655    while (ROK == cmHashListGetNext(&ulgCb->ueLstCp, 
2656                                    (PTR) ueCb, 
2657                                    (PTR *)&ueCb))
2658    {
2659       U32 i;
2660       for(i = 0; i < PJ_MAX_SRB_PER_UE; i++)
2661       {
2662          PjUlRbCb* rbCb = ueCb->srbCb[i];
2663          if(rbCb != NULLP)
2664          {
2665             dumpPDCPUlRbInformation(rbCb, ueCb->key.ueId);
2666          }
2667       }
2668       for(i = 0; i < PJ_MAX_DRB_PER_UE; i++)
2669       {
2670          PjUlRbCb* rbCb = ueCb->drbCb[i];
2671          if(rbCb != NULLP)
2672          {
2673             dumpPDCPUlRbInformation(rbCb, ueCb->key.ueId);
2674          }
2675       }
2676    }/* end while */   
2677 }
2678
2679 #ifdef TENB_DPDK_BUF
2680
2681 #ifdef ANSI
2682 PUBLIC S16 pjUpdRxEntBuf
2683 (
2684 PjRxEnt    *rxEnt
2685 )
2686 #else
2687 PUBLIC S16 pjUpdRxEntBuf(rxEnt)
2688 PjRxEnt    *rxEnt;
2689 #endif
2690 {
2691    MsgLen    msgLen;
2692    Data      *dpdkFBuf;
2693
2694 #define PDCP_NW_OFFSET 8
2695
2696    TRC2(pjUpdRxEntBuf)
2697
2698
2699    RETVALUE(ROK);
2700 }
2701
2702 #endif  /* TENB_DPDK_BUF */
2703 #ifdef ANSI
2704 PRIVATE S16 pjUtlUlHdlSecInitCfm
2705 (
2706 PjCb        *gCb,              /* Pointer to PJ DL Control Block */
2707 PjUlUeCb      *ueCb,           /* Pointer to UeCb */ 
2708 U16         txIdx,             /* Transaction Index for UeCb */
2709 PjAsyncCfm       *asyncCfm,    /* Async Confirm */
2710 CpjSecCfgCfmInfo *secCfgCfm,   /* Security config confirm */
2711 CpjReEstCfmInfo  *reEstCfm     /* Reest config confirm */
2712 )
2713 #else
2714 PRIVATE S16 pjUtlUlHdlSecInitCfm(gCb,ueCb,txIdx, asyncCfm,secCfgCfm,reEstCfm)
2715 (                              
2716 PjCb        *gCb;              /* Pointer to PJ DL Control Block */
2717 PjUlUeCb      *ueCb;           /* Pointer to UeCb */ 
2718 U16         txIdx;             /* Transaction Index for UeCb */
2719 PjAsyncCfm       *asyncCfm;    /* Async Confirm */
2720 CpjSecCfgCfmInfo *secCfgCfm;   /* Security config confirm */
2721 CpjReEstCfmInfo  *reEstCfm;    /* Reest config confirm */
2722 )
2723 #endif   
2724 {
2725    TRC3(pjUtlUlHdlSecInitCfm)
2726
2727    if(asyncCfm->libInitBitMask == 0)
2728    {
2729       PJ_CHK_RESTART_OBD_TIMER(gCb,ueCb, txIdx);
2730       if(ueCb->libInfo.state == PJ_STATE_NORMAL)
2731       {
2732          /* Send security config confirm */
2733          PJ_ALLOC(gCb,secCfgCfm, sizeof(CpjSecCfgCfmInfo));
2734 #if (ERRCLASS & ERRCLS_DEBUG)
2735          if (secCfgCfm == NULLP)
2736          {
2737             RLOG0(L_FATAL, "Memory Allocation failed.");
2738             RETVALUE(RFAILED);
2739          }
2740 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2741          PJ_FILL_SEC_CFM_INFO(secCfgCfm, asyncCfm);
2742
2743          PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
2744
2745          PjUiCpjSecCfgCfm(&gCb->u.ulCb->cpjSap.pst, gCb->u.ulCb->cpjSap.suId, secCfgCfm);
2746       }
2747       else if(ueCb->libInfo.state == PJ_STATE_REEST)
2748       {
2749          /* Send ReEstCfm */
2750          PJ_ALLOC(gCb,reEstCfm, sizeof(CpjReEstCfmInfo));
2751 #if (ERRCLASS & ERRCLS_DEBUG)
2752          if (reEstCfm == NULLP)
2753          {
2754             RLOG0(L_FATAL, "Memory Allocation failed.");
2755             RETVALUE(RFAILED);
2756          }
2757 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2758
2759          PJ_FILL_REEST_CFM_INFO(reEstCfm, asyncCfm, LCM_PRIM_OK);
2760
2761          /* Some house keeping work */
2762          PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
2763
2764 #ifdef PJ_SEC_ASYNC            
2765          /*Change the state from REEST to NORMAL*/
2766          ueCb->libInfo.reEstCfmSent = TRUE;
2767 #endif
2768          PjUiCpjReEstCfm(&gCb->u.ulCb->cpjSap.pst, gCb->u.ulCb->cpjSap.suId, reEstCfm);
2769       }
2770    }
2771
2772  RETVALUE(ROK);
2773 }
2774
2775
2776 #ifdef ANSI
2777 PRIVATE S16 pjUtlUlHdlCmpInitCfm
2778 (
2779 PjCb           *gCb,            /* Pointer to PJ DL Control Block */
2780 PjUlUeCb       *ueCb,           /* Pointer to UeCb */ 
2781 U16            txIdx,           /* Transaction Index for UeCb */
2782 PjAsyncCfm     *asyncCfm,       /* Async Confirm */
2783 CpjCfgCfmInfo  *cfgCfm         /* UDX Config Confirm */
2784 )
2785 #else
2786 PRIVATE S16 pjUtlUlHdlCmpInitCfm(gCb,ueCb,txIdx,asyncCfm,cfgCfm)
2787 (                              
2788 PjCb           *gCb;            /* Pointer to PJ DL Control Block */
2789 PjUlUeCb       *ueCb;           /* Pointer to UeCb */ 
2790 U16            txIdx;           /* Transaction Index for UeCb */
2791 PjAsyncCfm     *asyncCfm;       /* Async Confirm */
2792 CpjCfgCfmInfo  *cfgCfm;         /* UDX Config Confirm */
2793 )
2794 #endif   
2795 {
2796    U32               idx;
2797
2798    TRC3(pjUtlUlHdlCmpInitCfm)
2799
2800       if(asyncCfm->cmpInitBitMask == 0)
2801       {
2802          asyncCfm->libInitBitMask ^= (PJ_LIB_COMP_BIT_MASK);
2803
2804          if((asyncCfm->libInitBitMask == 0) &&
2805                !(asyncCfm->cfmType & PJ_CFG_REEST_ASYNC_CFM))
2806          {
2807
2808             /* Send config confirm */
2809             PJ_ALLOC(gCb,cfgCfm, sizeof(CpjCfgCfmInfo));
2810 #if (ERRCLASS & ERRCLS_ADD_RES)
2811             if (cfgCfm == NULLP)
2812             {
2813                RLOG0(L_FATAL, "Memory Allocation failed.");
2814                RETVALUE(RFAILED);
2815             }
2816 #endif /* ERRCLASS & ERRCLS_ADD_RES */
2817             cfgCfm->transId = asyncCfm->transId;
2818             cfgCfm->ueId    = asyncCfm->ueId;
2819             cfgCfm->cellId  = asyncCfm->cellId;
2820             cfgCfm->numEnt  = asyncCfm->numEnt; 
2821             for ( idx = 0; idx < asyncCfm->numEnt; idx++ )
2822             {
2823                cfgCfm->cfmEnt[idx].status = asyncCfm->cfmEnt[idx].status;  
2824                cfgCfm->cfmEnt[idx].reason = asyncCfm->cfmEnt[idx].reason;  
2825                cfgCfm->cfmEnt[idx].rbId   = asyncCfm->cfmEnt[idx].rbId;
2826                cfgCfm->cfmEnt[idx].rbType = asyncCfm->cfmEnt[idx].rbType;
2827             }
2828
2829             /* Some house keeping work */
2830             PJ_CHK_RESTART_OBD_TIMER(gCb,ueCb, txIdx);
2831             PJ_CLEAN_AND_UPD_ASYNCINFO(gCb,ueCb, txIdx);
2832
2833             /* Send confirmtion to the User */
2834             PjUiCpjCfgCfm(&(gCb->u.ulCb->cpjSap.pst), gCb->u.ulCb->cpjSap.suId, cfgCfm);
2835          }
2836       }
2837    RETVALUE(ROK);
2838 }   
2839 #ifdef __cplusplus
2840 }
2841 #endif /* __cplusplus */
2842 /********************************************************************30**
2843          End of file
2844 **********************************************************************/