Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_ptlib.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:    RLC service user (PDCP) lower interface
22     
23         Type:    C file
24   
25         Desc:    This file Contains the RLC service user lower interface
26                   primitive implementain
27  
28         File:    pj_ptlib.c
29   
30 *********************************************************************21*/
31
32 /* header (.h) include files */
33 #include "envopt.h"        /* environment options */
34 #include "envdep.h"        /* environment dependent */
35 #include "envind.h"        /* environment independent */
36
37 #include "gen.h"           /* general */
38 #include "ssi.h"           /* system services */
39 #include "cm5.h"           /* common timer defines */
40 #include "cm_tkns.h"       /* common tokens defines */
41 #include "cm_mblk.h"       /* common memory allocation library defines */
42 #include "cm_llist.h"      /* common link list  defines  */
43 #include "cm_hash.h"       /* common hash list  defines */
44 #include "cm_lte.h"        /* common LTE defines */
45 #include "kwu.h"           /* KWU defines */
46 #include "pju.h"           /* PJU defines */
47 /*#include "rgu.h"*/           /* RGU defines */
48 #include "cpj.h"           /* CPJ defines */
49 #include "lpj.h"           /* LPJ defines */
50 #include "pju.h"           /* PJU defines */
51 #include "pj_env.h"        /* RLC environment options */
52 #include "pj.h"            /* RLC defines */
53 #include "pj_dl.h"
54 #include "pj_ptsec.h"
55 #ifdef INTEL_NATIVE_SPACC
56 #include "elpspaccusr.h"
57 #endif
58
59 /* extern (.x) include files */
60 #include "gen.x"           /* general */
61 #include "ssi.x"           /* system services */
62
63 #if (defined(L2_L3_SPLIT) && defined(ICC_RECV_TSK_RBUF))
64 #include "ss_rbuf.h"
65 #include "ss_rbuf.x"
66 #include "kwu.h"                /* PJU */
67 #include "ss_queue.h"
68 #include "ss_queue.x"
69 #include "ss_task.h"
70 #include "ss_task.x"
71 #include "ss_timer.x"           /* System services */
72 #include "ss_msg.h"           /* System services */
73 #include "ss_msg.x"           /* System services */
74 #include "ss_mem.h"           /* System services */
75 #include "ss_mem.x"           /* System services */
76 #include "ss_drvr.x"
77 #include "ss_gen.h"
78 #include "ss_gen.x"
79 #endif
80
81 #include "cm5.x"           /* common timer library */
82 #include "cm_tkns.x"       /* common tokens */
83 #include "cm_mblk.x"       /* common memory allocation */
84 #include "cm_llist.x"      /* common link list */
85 #include "cm_hash.x"       /* common hash list */
86 #include "cm_lte.x"        /* common LTE includes */
87 #include "cm_lib.x"        /* common memory allocation library */
88 #ifdef TENB_AS_SECURITY
89 #include "mt_plat_t33.h"
90 #include "mt_plat_t33.x"
91 #endif
92 #include "kwu.x"           /* KWU */
93 #include "pju.x"           /* PJU */
94 /*#include "rgu.x" */          /* RGU */
95 #include "cpj.x"           /* CPJ */
96 #include "lpj.x"           /* LPJ */
97 #include "pju.x"           /* PJU */
98 #include "pj.x"
99 #include "pj_udx.h"          /* LIB */
100 #include "pj_udx.x"          /* LIB */
101 #include "pj_dl.x"
102 #include "pj_ul.x"
103 #include "pj_ptsec.x"
104 #include "pj_lib.x"     /* LIB */
105
106 #ifdef TENB_AS_SECURITY
107 static const char* RLOG_MODULE_NAME="PDCP";
108 static int RLOG_FILE_ID=293;
109 static int RLOG_MODULE_ID=1024;
110 #endif
111
112 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
113 extern U32 isMemThreshReached(Region region);
114 #endif
115 #ifdef TENB_AS_SECURITY
116 PUBLIC U32 pjMsSpaccHdlOpenReq(PTR *fd);
117 PUBLIC U32 pjMsSpaccHdlCloseReq(PTR *fd);
118 PUBLIC U32 pjMsSpaccCipherPkt(PjMsSecInfo *pSec, Buffer *mBuf);
119 PUBLIC U32 pjMsSpaccIntegProtPkt(PjLibTrans *libTrans, Buffer **mBuf);
120
121 PRIVATE S16 pjExtractTxEntRbCbUsingSpaccMappingInfo ARGS ((
122 PjMsSPACCOutputMapInfo *spaccInfo,
123 PjCb   **gCb,
124 PjDlRbCb **pjRbCb,
125 PjTxEnt  **txEnt
126 ));
127
128
129
130 PRIVATE Void pjMsSpaccProcessDlBatchOutput ARGS ((Void));
131 PRIVATE Void pjMsSpaccProcessUlBatchOutput ARGS((Void));
132 PUBLIC U32 pjMsCheckSpaccQueue(Bool isUl);
133 PUBLIC Void pjSpaccDeInitCiphQ(Void);
134 PUBLIC Void pjSpaccDeInitDeCipherQ(Void);
135 #endif
136
137 #ifdef PTPJLIB
138 #ifdef PJ_CMP_ASYNC
139 /************************************************************************
140                              PJU Interface Matrices
141 ************************************************************************/
142 \f
143 /****************************************************************************
144  *                         PJU Interface Mt functions
145  ***************************************************************************/
146
147 #ifdef ANSI
148 PUBLIC S16 PjLibObdCmpInitReq
149 (
150 Pst * pst,
151 PjCmpCxt cmpCxt,
152 PjRohc rohc
153 )
154 #else
155 PUBLIC S16 PjLibObdCmpInitReq(pst, cmpCxt, rohc)
156 Pst * pst;
157 PjCmpCxt cmpCxt;
158 PjRohc rohc;
159 #endif
160 {
161
162    TRC3(PjLibObdCmpInitReq)
163
164    RETVALUE(ROK);
165 }
166
167 #ifdef ANSI
168 PUBLIC S16 PjLibObdCmpReq
169 (
170 Pst * pst,
171 PTR cmpCxtId,
172 PjLibTrans libTrans,
173 Buffer * mBuf
174 )
175 #else
176 PUBLIC S16 PjLibObdCmpReq(pst, cmpCxtId, libTrans, mBuf)
177 Pst * pst;
178 PTR cmpCxtId;
179 PjLibTrans libTrans;
180 Buffer * mBuf;
181 #endif
182 {
183
184    TRC3(PjLibObdCmpReq)
185
186    RETVALUE(ROK);
187
188 }
189
190 #ifdef ANSI
191 PUBLIC S16 PjLibObdDecmpReq
192 (
193 Pst * pst,
194 PTR cmpCxtId,
195 PjLibTrans libTrans,
196 Buffer * mBuf
197 )
198 #else
199 PUBLIC S16 PjLibObdDecmpReq(pst, cmpCxtId, libTrans, mBuf)
200 Pst * pst;
201 PTR cmpCxtId;
202 PjLibTrans libTrans;
203 Buffer * mBuf;
204 #endif
205 {
206
207    TRC3(PjLibObdDecmpReq)
208
209    RETVALUE(ROK);
210
211 }
212
213 #ifdef ANSI
214 PUBLIC S16 PjLibObdCmpCloseReq
215 (
216 Pst * pst,
217 PTR cmpCxtId
218 )
219 #else
220 PUBLIC S16 PjLibObdCmpCloseReq(pst, cmpCxtId)
221 Pst * pst;
222 PTR cmpCxtId;
223 #endif
224 {
225
226    TRC3(PjLibObdCmpCloseReq)
227
228    RETVALUE(ROK);
229
230 }
231
232 #ifdef ANSI
233 PUBLIC S16 PjLibObdCmpResetReq
234 (
235 Pst * pst,
236 PTR cmpCxtId
237 )
238 #else
239 PUBLIC S16 PjLibObdCmpResetReq(pst, cmpCxtId)
240 Pst * pst;
241 PTR cmpCxtId;
242 #endif
243 {
244
245    TRC3(PjLibObdCmpResetReq)
246
247    RETVALUE(ROK);
248
249 }
250
251 #ifdef ANSI
252 PUBLIC S16 PjLibObdCmpFbReq
253 (
254 Pst * pst,
255 PTR cmpCxtId,
256 PjLibTrans libTrans,
257 Buffer *feedback
258 )
259 #else
260 PUBLIC S16 PjLibObdCmpFbReq(pst, cmpCxtId, libTrans, feedback)
261 Pst * pst;
262 PTR cmpCxtId;
263 PjLibTrans libTrans;
264 Buffer *feedback;
265 #endif
266 {
267
268    TRC3(PjLibObdCmpFbReq)
269
270    RETVALUE(ROK);
271
272 }
273
274 #else
275 #ifdef ANSI
276 PUBLIC S16 PjLibObdCipherCloseReq
277 (
278 Void *cpCxtId
279 )
280 #else
281 PUBLIC S16 PjLibObdCipherCloseReq(cpCxtId)
282 Void *cpCxtId
283 #endif
284 {
285    TRC3(PjLibObdCipherCloseReq)
286
287 #ifdef INTEL_SPACC_IV_OPTIMIZATION
288    pjNSpaccReturnStreamIdToPool(cpCxtId);
289 #endif
290    RETVALUE(ROK);
291
292 }
293
294 #ifdef ANSI
295 PUBLIC S16 pjLibCmpInitReq 
296 (
297 PjCmpCxt cmpCxt,                  /* Context for ROHC */
298 PjRohc   rohc,                    /* ROHC Config Info */
299 PTR      *cmpCxtId                /* Compression Context ID */
300 )
301 #else
302 PUBLIC S16 pjLibCmpInitReq(cmpCxt, rohc, cmpCxtId)
303 PjCmpCxt cmpCxt;                  /* Context for ROHC */
304 PjRohc   rohc;                    /* ROHC Config Info */
305 PTR      *cmpCxtId;               /* Compression Context ID */
306 #endif
307 {
308    TRC3(pjLibCmpInitReq)
309
310    RETVALUE(ROK);
311
312 } /* end of pjLibCmpInitReq */
313
314 #ifdef ANSI
315 PUBLIC S16 pjLibCmpReq 
316 (
317 PTR      cmpCxtId,                /* Context Id for compression */
318 Buffer   *mBuf,                   /* SDU to be compressed */
319 Buffer   **opSdu                  /* Compressed SDU */
320 )
321 #else
322 PUBLIC S16 pjLibCmpReq(cmpCxtId, mBuf, opSdu)
323 PTR      cmpCxtId;                /* Context Id for compression */
324 Buffer   *mBuf;                   /* SDU to be compressed */
325 Buffer   **opSdu;                 /* Compressed SDU */
326 #endif
327 {
328    TRC3(pjLibCmpReq)
329
330    RETVALUE(ROK);
331
332 } /* end of pjLibCmpReq */
333
334 #ifdef ANSI
335 PUBLIC S16 pjLibDecmpReq 
336 (
337 PTR      cmpCxtId,                /* Context Id for compression */
338 Buffer   *mBuf,                   /* SDU to be decompressed */
339 Buffer   **feedback,                 /* Decompressed SDU */
340 Buffer   **opSdu               /* ROHC feedback buffer */
341 )
342 #else
343 PUBLIC S16 pjLibDecmpReq(cmpCxtId, mBuf, feedback, opSdu)
344 PTR      cmpCxtId;                /* Context Id for compression */
345 Buffer   *mBuf;                   /* SDU to be decompressed */
346 Buffer   **feedback;                 /* Decompressed SDU */
347 Buffer   **opSdu;              /* ROHC feedback buffer */
348 #endif
349 {
350    TRC3(pjLibDecmpReq)
351
352    RETVALUE(ROK);
353
354 } /* end of pjLibDecmpReq */
355
356 #ifdef ANSI
357 PUBLIC S16 pjLibCmpCloseReq
358 (
359 PTR      cmpCxtId                 /* ROHC Context to be closed */
360 )
361 #else
362 PUBLIC S16 pjLibCmpCloseReq(cmpCxtId)
363 PTR      cmpCxtId;                /* ROHC Context to be closed */
364 #endif
365 {
366    TRC3(pjLibCmpCloseReq)
367
368    RETVALUE(ROK);
369
370 } /* end of pjLibCmpCloseReq */
371
372 #ifdef ANSI
373 PUBLIC S16 pjLibCmpResetReq
374 (
375 PTR      cmpCxtId                 /* ROHC Context to be closed */
376 )
377 #else
378 PUBLIC S16 pjLibCmpResetReq(cmpCxtId)
379 PTR      cmpCxtId;                /* ROHC Context to be closed */
380 #endif
381 {
382    TRC3(pjLibCmpResetReq)
383
384    RETVALUE(ROK);
385
386 } /* end of pjLibCmpResetReq */
387
388 #ifdef ANSI
389 PUBLIC S16 pjLibCmpFbReq
390 (
391 PTR      cmpCxtId,                /* ROHC Context to be closed */
392 Buffer   *feedback                /* Feed back */
393 )
394 #else
395 PUBLIC S16 pjLibCmpFbReq(cmpCxtId, feedback)
396 PTR      cmpCxtId;                /* ROHC Context to be closed */
397 Buffer   *feedback;               /* Feed back */
398 #endif
399 {
400    TRC3(pjLibCmpFbReq)
401
402    RETVALUE(ROK);
403
404 } /* end of pjLibCmpFbReq */
405
406 #endif /* PJ_CMP_ASYNC */
407
408 #ifdef ANSI
409 PUBLIC S16 pjLibIntInitReq 
410 (
411 PjSecCxt secCxt,                  /* Context for Intg protection/verification */
412 PjIntInfo intInfo,                /* Integrity Cfg Info */
413 Void      **cxtId                 /* FD */
414 )
415 #else
416 PUBLIC S16 pjLibIntInitReq(secCxt, intInfo, cxtId)
417 PjSecCxt secCxt;                  /* Context for Intg protection/verification */
418 PjIntInfo intInfo;                /* Integrity Cfg Info */
419 Void      **cxtId;                /* FD */
420 #endif
421 {
422    S16   ret = ROK;
423
424    TRC3(pjLibIntInitReq)
425
426    RETVALUE(ret);
427
428 } /* end of pjLibIntInitReq */
429
430 #ifdef ANSI
431 PUBLIC S16 pjLibCpInitReq
432 (
433 PjSecCxt secCxt,                  /* Context for Intg protection/verificatino */
434 U8       algoType,                /* Type of the algorithm */
435 U8       *cpKey,                  /* Control plane ciphering key */
436 Void     **cxtId                  /* FD */
437 )
438 #else
439 PUBLIC S16 pjLibCpInitReq(secCxt, algoType, cpKey, cxtId)
440 PjSecCxt secCxt;                  /* Context for Intg protection/verificatino */
441 U8       algoType;                /* Type of the algorithm */
442 U8       *cpKey;                  /* Control plane ciphering key */
443 Void     **cxtId;                 /* FD */
444 #endif
445 {
446    S16   ret = ROK;
447
448    TRC3(pjLibCpInitReq)
449
450    RETVALUE(ret);
451
452 } /* end of pjLibCpInitReq */
453
454 #ifdef ANSI
455 PUBLIC S16 pjLibUpInitReq
456 (
457 PjSecCxt secCxt,                  /* Context for Intg protection/verificatino */
458 U8       algoType,                /* Type of the algorithm */
459 U8       *upKey,                  /* User plane ciphering key */
460 Void     **cxtId                  /* FD */
461 )
462 #else
463 PUBLIC S16 pjLibUpInitReq(secCxt, algoType, upKey, cxtId)
464 PjSecCxt secCxt;                  /* Context for Intg protection/verificatino */
465 U8       algoType;                /* Type of the algorithm */
466 U8       *upKey;                  /* User plane ciphering key */
467 Void     **cxtId;                 /* FD */
468 #endif
469 {
470    TRC3(pjLibUpInitReq)
471
472 #ifdef INTEL_SPACC_IV_OPTIMIZATION
473    if(PJ_SEC_DIR_DL == secCxt.dir)
474    {
475       pjMsNSpaccIVPrepStreamIdForDl(cxtId);
476    }
477    else
478    {
479       pjMsNSpaccIVPrepStreamIdForUl(cxtId);
480    }   
481 #endif
482    RETVALUE(ROK);
483
484 } /* end of pjLibUpInitReq */
485
486
487
488 #ifdef ANSI
489 PUBLIC S16 PjLibObdCpInitReq
490 (
491 PjSec *secInp
492 )
493 #else
494 PUBLIC S16 PjLibObdCpInitReq(*secInp)
495 PjSec *secInp;
496 #endif
497 {
498    TRC3(PjLibObdCpInitReq)
499    RETVALUE(ROK);
500 }
501
502 #ifdef ANSI
503 PUBLIC S16 PjLibObdUpInitReq
504 (
505 PjSec *secInp
506 )
507 #else
508 PUBLIC S16 PjLibObdUpInitReq(*secInp)
509 PjSec *secInp
510 #endif
511 {
512    TRC3(PjLibObdUpInitReq)
513    RETVALUE(ROK);
514 }
515
516 #ifdef TENB_AS_SECURITY
517
518 /**
519  *
520  * @brief Extracting gCb, rbCb, txEnt from SPAcc Mapping Information.
521  *       
522  *
523  * @b Description: This function extracts gCb, rbCb, txEnt from SPAcc mapping
524  * info which is passed as one of the input params.
525  *
526  *
527  *  @param[in] spaccInfo : Information required to map o/p PDU from SPACc to
528  *  PDCP TxEnt.
529  *  @param[in] gCb       : PDCP Control Block
530  *  @param[in] pjRbCb    : PDCP rbCb
531  *  @param[in] txEnt     : PDCP TxEnt
532  *
533  * 
534  *  @return  Void
535  */
536
537 #ifdef ANSI
538 PRIVATE S16 pjExtractTxEntRbCbUsingSpaccMappingInfo 
539 (
540 PjMsSPACCOutputMapInfo *spaccInfo,
541 PjCb   **gCb,
542 PjDlRbCb **pjRbCb,
543 PjTxEnt  **txEnt
544 )
545 #else
546 PRIVATE S16 pjExtractTxEntRbCbUsingSpaccMappingInfo(spaccInfo, gCb, pjRbCb, txEnt)
547 PjMsSPACCOutputMapInfo *spaccInfo;
548 PjCb   **gCb;
549 PjDlRbCb **pjRbCb;
550 PjTxEnt  **txEnt;
551 #endif
552 {
553    PjDlUeCb   *ueCb = NULLP;
554
555    *gCb = PJ_GET_PJCB(spaccInfo->pdcpInstance);
556
557    pjDbmFetchDlUeCb(*gCb, spaccInfo->pdcpId.ueId,spaccInfo->pdcpId.cellId, &ueCb);
558
559    if(ueCb  == NULLP)
560    {
561       RLOG_ARG0(L_ERROR,DBG_UEID,spaccInfo->pdcpId.ueId,"UECB not found !!!! ");
562       RETVALUE(RFAILED);
563    }
564
565
566    pjDbmFetchPjDlRbCb(ueCb, spaccInfo->pdcpId.rbId, spaccInfo->pdcpId.rbType, pjRbCb);
567    if(*pjRbCb  == NULLP)
568    {
569       RLOG_ARG2(L_ERROR, DBG_UEID,spaccInfo->pdcpId.ueId, 
570             "CellId[%u]:RbId[%d] not found",
571             spaccInfo->pdcpId.cellId, spaccInfo->pdcpId.rbId);
572       RETVALUE(RFAILED);
573    }
574
575    *txEnt = (PjTxEnt *)pjDbmGetTxEnt(*gCb, &((*pjRbCb)->dlCb.txBuf),
576          spaccInfo->count);
577
578    if(*txEnt == NULLP)
579    {
580       RLOG_ARG0(L_ERROR,DBG_UEID,spaccInfo->pdcpId.ueId,"!!!!rxEnt is NULL!!!!");
581       RETVALUE(RFAILED);
582    }
583
584    RETVALUE(ROK);
585 }
586
587
588 /**
589  *
590  * @brief Handler for Processing Ciphered PDU's from SPAcc.
591  *       
592  *
593  * @b Description: This function processes and extracts the required control
594  * blocks for the ciphered PDU  and calls the function for to be processed
595  * further.
596  *
597  *  @param[in] spaccOpInfo : Information required to process PDU
598  *  @param[in] opSdu    : Ciphered buffer
599  *
600  *  @return  S16
601  *      -# ROK 
602  *      -# RFAILED 
603  */
604
605 #ifdef ANSI
606 PUBLIC S16 pjProcCiphPdu 
607 (
608 Buffer *opSdu,
609 PjMsSPACCOutputMapInfo *spaccOpInfo
610 )
611 #else
612 PUBLIC S16 pjProcCiphPdu(opSdu, spaccOpInfo)
613 Buffer *opSdu;
614 PjMsSPACCOutputMapInfo *spaccOpInfo;
615 #endif
616 {
617    U32 ret;
618    PjCb   *gCb = NULLP;
619    PjDlRbCb *pjRbCb = NULLP;
620    PjTxEnt  *txEnt = NULLP;
621
622    /* Extract gCb, rbCb and txEnt for further processing */
623    ret = pjExtractTxEntRbCbUsingSpaccMappingInfo(spaccOpInfo, &gCb, &pjRbCb, &txEnt);
624
625    if(ret != ROK)
626    {
627       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,
628             "pjExtractTxEntRbCbUsingSpaccMappingInfo: returned failure ");
629       PJ_FREE_BUF(opSdu);
630       RETVALUE(RFAILED);
631    }
632    else
633    {
634       if(pjRbCb->rbType == PJ_SRB)
635       {
636         if(txEnt->pdu != NULLP)
637         {
638             PJ_FREE_BUF(txEnt->pdu);
639         }
640       }
641       /* In case of Reestablish/HO , dropping the ciphered packets. These packets
642        * are processed again when events EVTCPJDATRESUMEREQ/EVTPJUDATFWDREQ are 
643        * received from upper layer */ 
644       if((pjRbCb->ueCb->libInfo.state != PJ_STATE_NORMAL) && (pjRbCb->rbType != PJ_SRB))
645       {
646               RLOG_ARG0(L_INFO,DBG_UEID,spaccOpInfo->pdcpId.ueId,
647                "Dropping the packet in reestablish state "); 
648               PJ_FREE_BUF(opSdu);
649               RETVALUE(RFAILED);
650       }
651       txEnt->pdu = opSdu;
652
653       /* Call to deliver PDU to RLC */
654       ret = pjDlmDeliverPdu(gCb, pjRbCb, txEnt);
655       if(ret != ROK)
656       {
657          RETVALUE(RFAILED);
658          RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,
659                "pjProcCiphPdu: pjDlmDeliverPdu failed !!!!");   
660       }
661    }
662
663    RETVALUE(ROK);
664 }
665
666
667 /**
668  *
669  * @brief Handler for Ciphering failure 
670  *       
671  *
672  * @b Description: This function handles the steps to be taken on failure of
673  *                 ciphering 
674  *
675  *
676  *  @param[in] procInfo : Information required to process PDU
677  *
678  * 
679  *  @return  Void
680  */
681
682 #ifdef ANSI
683 PUBLIC S16 pjHndlCiphFail 
684 (
685 PjMsSPACCOutputMapInfo *spaccInfo
686 )
687 #else
688 PUBLIC S16 pjHndlCiphFail(spaccInfo)
689 PjMsSPACCOutputMapInfo *spaccInfo;
690 #endif
691 {
692    PjCb   *gCb = NULLP;
693    PjDlRbCb *pjRbCb = NULLP;
694    PjTxEnt  *txEnt = NULLP;
695
696    /* Extract gCb, rbCb and txEnt for further processing */
697    if((pjExtractTxEntRbCbUsingSpaccMappingInfo(spaccInfo, &gCb, &pjRbCb, &txEnt)) != ROK)
698    {
699       RETVALUE(RFAILED);
700    }
701    else
702    {
703        PJ_UPD_DL_VAR(gCb, pjRbCb, txEnt->count);
704        if ( pjRbCb->dlCb.cfmReqd)
705        {
706           PJ_SND_CFM(gCb,pjRbCb, txEnt,
707                      PJU_CIPHER_FAILED);
708        }
709        else
710        {
711           pjDbmDelTxEnt(gCb, &(pjRbCb->dlCb.txBuf), txEnt->count);   
712        }
713        gCb->pjGenSts.numCiphFails++;
714    }
715
716    RETVALUE(ROK);
717 }
718 #ifdef SPACC_THREADED
719 PRIVATE U32 globPollCount = 50;
720
721 /**
722  *
723  * @brief Handler for SPACC Reset 
724  *       
725  *
726  * @b Description: This is triggeres when the processing of batch at SPACC
727  *                 is delayed
728  *
729  *
730  * 
731  *  @return  Void
732  */
733
734
735 #ifdef ANSI
736 PRIVATE Void pjMsSpaccReset(Void)
737 #else
738 PRIVATE Void pjMsSpaccReset()
739 #endif
740 {
741    U32 ret=ROK;
742    U32 jobNum=1;
743    Buffer *opSdu=NULLP;
744    PjMsSPACCOutputMapInfo spaccInfo;
745
746    RLOG0(L_DEBUG,"Restarting SPACC");
747 //   PjLibObdDlCloseReq();
748    pjMsSPAccRestart();
749    RLOG0(L_DEBUG,"SPACC Restarted");
750
751    for(;;)
752    {
753       ret = pjMsSpaccFetchDlPduInfo(&spaccInfo, &opSdu, jobNum, RFAILED);
754       if(ret == ROKDNA)
755       {
756          RLOG1(L_ERROR, "NUM DL jobs at failure:%ld",jobNum);
757          break;
758       }
759       pjHndlCiphFail(&spaccInfo);
760       jobNum++;
761    }
762
763    pjMsSetQFreeDl();
764
765    jobNum = 1;
766
767    for(;;)
768    {
769       ret = pjMsSpaccFetchUlPduInfo(&spaccInfo, &opSdu, jobNum, RFAILED);
770       if(ret == ROKDNA)
771       {
772          RLOG1(L_ERROR,"NUM UL jobs at failure:%ld",jobNum);
773          break;
774       }
775       pjHdlDecipherFailure(&spaccInfo);
776       jobNum++;
777    }
778
779    pjMsSetQFreeUl();
780
781    //RLOG0(L_DEBUG, "pjMsSetQFreeUl done");
782    //RLOG0(L_DEBUG, "Reopening SPACC DL");
783    //pjMsSpaccHdlDlfdOpenReq();
784   // RLOG0(L_DEBUG, "Reopened SPACC DL");
785
786    RETVOID;
787 }
788 #endif
789 /**
790  *
791  * @brief Handler for NRT TTI Indication to PDCP for DL batch processing 
792  *       
793  *
794  * @b Description: Triggers batch processing to SPAcc. Fetches the ciphered PDUs
795  *                 from SPAcc and triggers sending the PDU's RLC.
796  *
797  *
798  * 
799  *  @return  Void
800  */
801
802
803 #ifdef ANSI
804 PUBLIC Void PjDlSpaccTrigger(Void)
805 #else
806 PUBLIC Void PjDlSpaccTrigger()
807 #endif
808 {
809
810    U32 ret=ROK;
811    U32 jobNum=1;
812    Buffer *opSdu=NULLP;
813    PjMsSPACCOutputMapInfo spaccInfo;
814
815 #ifdef SPACC_NONBLOCKING
816    static U32 dlPollCount = 0;
817
818    S32 pollop;
819    pollop = pjMsSpaccPollDlQueue();
820    if(PJ_MS_POLL_NOT_REQUIRED == pollop)
821    {
822       ret = pjMsSpaccBatchAndCipherPackets();
823 //      pjMsSpaccSetResetDlQueueFree(0);  /* Set to FALSE */
824    }
825    else
826    {
827       if(PJ_MS_POLL_COMPLETE == pollop)
828       {
829          dlPollCount = 0;
830          /* Process the o/p from SPAcc */
831          pjMsSpaccProcessDlBatchOutput();
832 //         pjMsSpaccSetResetDlQueueFree(1);  /* Set to TRUE */
833
834          /* Send next set of data to SPAcc after processing */
835          ret = pjMsSpaccBatchAndCipherPackets();
836 //         pjMsSpaccSetResetDlQueueFree(0);  /* Set to FALSE */
837       }
838       else
839       {
840 #ifdef SPACC_THREADED
841          /*Workaround for the SPACC issue of "unexpected job"*/
842          dlPollCount++;
843          if(dlPollCount >= globPollCount)
844          {
845             U32 numUnexpJobs = 0;
846             dlPollCount = 0;
847             numUnexpJobs = pjMsCheckUnExpJobs();
848             if(numUnexpJobs != 0)
849             {
850                pjMsSpaccReset();
851             }
852          }
853 #endif 
854          /* Do nothing as SPAcc is not done with processing */
855       }
856    }
857
858    /* This condition is executed when SPAcc returns failure for whatever
859    * reason.So once failure is returned, we fetch all the PDU's we had sent
860    * for ciphering and process them as failure */
861    if(ret != ROK)
862    {
863       RLOG0(L_ERROR,"Error leg in DL Spacc trigger hit ");
864       for(;;)
865       {
866          ret = pjMsSpaccFetchDlPduInfo(&spaccInfo, &opSdu, jobNum, ret);
867          if(ret == ROKDNA)
868          {
869             break;
870          }
871          pjHndlCiphFail(&spaccInfo);
872          jobNum++;
873       }
874    }
875
876 #else
877
878    ret = pjMsSpaccBatchAndCipherPackets();
879
880    /* This condition is executed when SPAcc returns failure for whatever
881     * reason.So once failure is returned, we fetch all the PDU's we had sent
882     * for ciphering and process them as failure */
883    if(ret != ROK)
884    {
885       for(;;)
886       {
887          ret = pjMsSpaccFetchDlPduInfo(&spaccInfo, &opSdu, jobNum, ret);
888          if(ret == ROKDNA)
889          {
890             break;
891          }
892          pjHndlCiphFail(&spaccInfo);
893          RETVOID;
894       }
895    }
896
897    pjMsSpaccProcessDlBatchOutput();
898
899 #endif
900
901    RETVOID;
902 }
903
904 /**
905  *
906  * @brief Handler for processing of Decipher Failure
907  *       
908  *
909  * @b Description: This function handles decipher failures by deleting the
910  * RxEnt,  send STA_IND to upper layer and updation of general statistics.
911  *
912  *
913  *  @param[in] spaccOpInfo : Information required to process PDU
914  *
915  * 
916  *  @return  Void
917  */
918
919 #ifdef ANSI
920 PUBLIC S16 pjHdlDecipherFailure 
921 (
922 PjMsSPACCOutputMapInfo *spaccOpInfo
923 )
924 #else
925 PUBLIC S16 pjHdlDecipherFailure()
926 PjMsSPACCOutputMapInfo *spaccOpInfo;
927 #endif
928 {
929    PjCb   *gCb;
930    PjUlUeCb   *ueCb = NULLP;
931    PjUlRbCb *pjRbCb = NULLP;
932    PjRxEnt  *rxEnt = NULLP; 
933
934    gCb = PJ_GET_PJCB(spaccOpInfo->pdcpInstance);
935
936    pjDbmFetchUlUeCb(gCb, 
937                     spaccOpInfo->pdcpId.ueId,
938                     spaccOpInfo->pdcpId.cellId, 
939                     &ueCb);
940
941    if(ueCb  == NULLP)
942    {
943       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,"UECB not found !!!! ");
944       RETVALUE(RFAILED);
945    }
946
947    /*     RLOG_ARG4(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,
948     *     "At PDCP: : RBTYPE:%d, CELLID:%d, RBID:%d, 
949          COUNT:%d", spaccOpInfo->pdcpId.rbType, spaccOpInfo->pdcpId.cellId,  
950          spaccOpInfo->pdcpId.rbId, spaccOpInfo->count);*/
951    /*   RLOG_ARG2(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,
952           "SNLEN:%d, numjobs %d "spaccOpInfo->pdcpId.ueId,  \
953           spaccOpInfo->snLen,  numJobs); */
954
955    pjDbmFetchPjUlRbCb(ueCb, spaccOpInfo->pdcpId.rbId, spaccOpInfo->pdcpId.rbType, &pjRbCb);
956    if(pjRbCb  == NULLP)
957    {
958       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,"RBCB not found !!!!");
959       RETVALUE(RFAILED);
960    }
961
962    rxEnt = (PjRxEnt *)pjDbmGetRxEnt(gCb, 
963                                     &(pjRbCb->ulCb.recBuf),
964                                     spaccOpInfo->count);
965
966    if(rxEnt == NULLP)
967    {
968       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,"!!!!rxEnt is NULL!!!!");
969       RETVALUE(RFAILED);
970    }
971
972    PJ_SND_PJU_STA_IND(gCb,pjRbCb, rxEnt);
973    pjDbmDelRxEnt(gCb, &(pjRbCb->ulCb.recBuf), rxEnt->count);
974    PJ_STS_INC_GEN_CNT(gCb,numDeciphFails);
975
976    RETVALUE(ROK);
977 }
978
979 /**
980  *
981  * @brief Handler for processing deciphered PDU 
982  *       
983  *
984  * @b Description: This function processes and sends the ciphered PDU to RLC
985  *
986  *
987  *  @param[in] spaccOpInfo : Information required to process PDU
988  *  @param[in] opSdu    : Deciphered buffer
989  *
990  * 
991  *  @return  S16
992  *      -# ROK 
993  *      -# RFAILED 
994  */
995
996 #ifdef ANSI
997 PUBLIC S16 pjProcDeCipherPdu 
998 (
999 PjMsSPACCOutputMapInfo *spaccOpInfo,
1000 Buffer *opSdu
1001 )
1002 #else
1003 PUBLIC S16 pjProcDeCipherPdu()
1004 PjMsSPACCOutputMapInfo *spaccOpInfo;
1005 Buffer *opSdu;
1006 #endif
1007 {
1008    U32 ret;
1009    PjCb   *gCb;
1010    PjUlUeCb   *ueCb = NULLP;
1011    PjUlRbCb *pjRbCb = NULLP;
1012    PjRxEnt  *rxEnt = NULLP; 
1013
1014    gCb = PJ_GET_PJCB(spaccOpInfo->pdcpInstance);
1015
1016    pjDbmFetchUlUeCb(gCb, 
1017                     spaccOpInfo->pdcpId.ueId,
1018                     spaccOpInfo->pdcpId.cellId, 
1019                     &ueCb);
1020    
1021    if(ueCb  == NULLP)
1022    {
1023       RLOG_ARG0(L_WARNING,DBG_UEID,spaccOpInfo->pdcpId.ueId,"UECB not found !!!! ");
1024       RETVALUE(RFAILED);
1025    }
1026
1027 /*     RLOG_ARG4(L_ERROR, DBG_UEID,spaccOpInfo->pdcpId.ueId,
1028        "UDAY: At PDCP: : RBTYPE:%d, CELLID:%d, RBID:%d,  COUNT:%d", 
1029        spaccOpInfo->pdcpId.rbType, spaccOpInfo->pdcpId.cellId, 
1030        spaccOpInfo->pdcpId.rbId, spaccOpInfo->count,);*/
1031 /*     RLOG_ARG2(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,
1032        " SNLEN:%d, numjobs %d ",spaccOpInfo->snLen,  numJobs); */
1033
1034    pjDbmFetchPjUlRbCb(ueCb, spaccOpInfo->pdcpId.rbId, spaccOpInfo->pdcpId.rbType, &pjRbCb);
1035    if(pjRbCb  == NULLP)
1036    {
1037       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,"RBCB not found !!!! ");
1038       RETVALUE(RFAILED);
1039    }
1040
1041    rxEnt = (PjRxEnt *)pjDbmGetRxEnt(gCb, &(pjRbCb->ulCb.recBuf),
1042          spaccOpInfo->count);
1043
1044 /* To be used for debugging. Will be removed once verified */
1045
1046    if(rxEnt == NULLP)
1047    {
1048       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,"!!!!rxEnt is NULL!!!!");
1049       RETVALUE(RFAILED);
1050    }  
1051
1052    /*Free the source buffer here*/
1053    if(rxEnt->mBuf)
1054    {
1055       PJ_FREE_BUF(rxEnt->mBuf);
1056    }
1057  
1058    rxEnt->mBuf = opSdu;
1059
1060
1061    if(pjRbCb->rbType == PJ_DRB)
1062    {
1063       rxEnt->state   =  PJ_RDY_TO_DCOMP;
1064       ret = pjUlmHdlDeCmp(gCb, pjRbCb, rxEnt);
1065    }
1066    else
1067    {
1068       rxEnt->state   =  PJ_RDY_TO_INTVER;
1069       ret = pjUlmHdlIntVer(gCb, pjRbCb, rxEnt);
1070    }   
1071
1072    if(rxEnt->dupEntry == TRUE)
1073    {
1074       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId," 3. Deleting RxEnt");
1075       /* duplicate entry */
1076       PJ_FREE_BUF(rxEnt->mBuf);
1077       PJ_FREE(gCb,rxEnt, sizeof(PjRxEnt));
1078    }
1079    else if(rxEnt->discFlag == TRUE)
1080    {
1081       RLOG_ARG0(L_ERROR,DBG_UEID,spaccOpInfo->pdcpId.ueId,"4. Deleting RxEnt");
1082       /* duplicate entry */
1083       pjDbmDelRxEnt(gCb, &pjRbCb->ulCb.recBuf, rxEnt->count);
1084    }   
1085    RETVALUE(ROK);
1086
1087 }
1088
1089 /**
1090  *
1091  * @brief Handler for NRT TTI Indication to PDCP for UL batch processing 
1092  *       
1093  *
1094  * @b Description: Triggers batch processing of packets lined up for 
1095  *                 deciphering. Fetches the ciphered PDUs
1096  *                 and triggers further processing at PDCP. 
1097  *
1098  *
1099  * 
1100  *  @return  Void
1101  */
1102
1103
1104 #ifdef ANSI
1105 PUBLIC Void PjUlSpaccTrigger(Void)
1106 #else
1107 PUBLIC Void PjUlSpaccTrigger(Void)
1108 #endif
1109 {
1110
1111    U32 ret=ROK;
1112    U32 jobNum=1;
1113    Buffer *opSdu=NULLP;
1114    PjMsSPACCOutputMapInfo spaccInfo;
1115
1116 #ifdef SPACC_NONBLOCKING
1117    static U32 ulPollCount = 0;
1118
1119    S32 pollop;
1120    pollop = pjMsSpaccPollUlQueue();
1121    if(PJ_MS_POLL_NOT_REQUIRED == pollop)
1122    {
1123       ret = pjMsSpaccBatchAndDeCipherPackets();
1124    }
1125    else
1126    {
1127       if(PJ_MS_POLL_COMPLETE == pollop)
1128       {
1129          ulPollCount = 0;
1130          /* Process the o/p from SPAcc */
1131          pjMsSpaccProcessUlBatchOutput();
1132          pjMsSpaccSetResetUlQueueFree(1);  /* Set to TRUE */
1133
1134          /* Send next set of data to SPAcc after processing */
1135          ret = pjMsSpaccBatchAndDeCipherPackets();
1136       }
1137       else
1138       {
1139 #ifdef SPACC_THREADED
1140          /*SPACC Workaround when SPACC is not able to complete BATCH*/
1141          ulPollCount++;
1142          if(ulPollCount >= globPollCount)
1143          {
1144             U32 numUnexpJobs = 0;
1145             ulPollCount = 0;
1146             numUnexpJobs = pjMsCheckUnExpJobs();
1147             if(numUnexpJobs != 0)
1148             {
1149                pjMsSpaccReset();
1150             }
1151          }
1152 #endif 
1153       }
1154    }
1155
1156    /* This condition is executed when SPAcc returns failure for whatever
1157     * reason.So once failure is returned, we fetch all the PDU's we had sent
1158     * for Deciphering and process them as failure */
1159    if(ret != ROK)
1160    {
1161       RLOG0(L_ERROR, "Error leg in uL Spacc trigger hit ");
1162       for(;;)
1163       {
1164          ret = pjMsSpaccFetchUlPduInfo(&spaccInfo, &opSdu, jobNum, ret);
1165          if(ret == ROKDNA)
1166          {
1167             break;
1168          }
1169          pjHdlDecipherFailure(&spaccInfo);
1170          jobNum++;
1171       }
1172    }
1173
1174 #else
1175
1176    ret = pjMsSpaccBatchAndDeCipherPackets();
1177
1178    /* This condition is executed when SPAcc returns failure for whatever
1179     * reason.So once failure is returned, we fetch all the PDU's we had sent
1180     * for Deciphering and process them as failure */
1181    if(ret != ROK)
1182    {
1183       for(;;)
1184       {
1185          ret = pjMsSpaccFetchUlPduInfo(&spaccInfo, &opSdu, jobNum, ret);
1186          if(ret == ROKDNA)
1187          {
1188             break;
1189          }
1190          pjHdlDecipherFailure(&spaccInfo);
1191       }
1192
1193       RETVOID;
1194    }
1195
1196    pjMsSpaccProcessUlBatchOutput();
1197
1198
1199 #endif
1200
1201    RETVOID;
1202 }
1203
1204
1205
1206 /**
1207 *@brief
1208 * This function calls the function which interfaces with SPAcc
1209 * for opening of the fd. Also, it initializes the SPAcc DL Queues.
1210 *
1211 *@inparam[in] gCb  PDCP Instance Control Block
1212 *@return S16
1213 */
1214
1215 #ifdef ANSI
1216 PUBLIC S16 PjLibObdDlInitReq
1217 (
1218 PjCb    *gCb
1219 )
1220 #else
1221 PUBLIC S16 PjLibObdDlInitReq(gCb)
1222 PjCb    *gCb;
1223 #endif
1224 {
1225    TRC3(PjLibObdDlInitReq)
1226
1227 #ifdef INTEL_NATIVE_SPACC
1228    S32 ret = RFAILED;
1229    ret = pjMsSpaccRegIccDlHndl();
1230    if(ret != ROK)
1231    {
1232       printf("Registration of ICC DL handle has failed\n");
1233       RETVALUE(ret);
1234    }
1235    printf("Registration of ICC DL handle has succeeded\n");
1236    ret = pjMsSpaccThreadActivation(appContext.hUAII_Dl);
1237    if(ret != 0)
1238    {
1239       printf("Spacc thread activation has failed\n");
1240       RETVALUE(ret);
1241    }
1242    printf("Spacc thread activation is done again\n");
1243    /* Init Mem region and Pool */
1244    pjMsSPAccInitDlMemRegionPool(gCb->init.region, gCb->init.pool);
1245 #ifdef INTEL_SPACC_IV_OPTIMIZATION
1246    pjMsNSpaccDlInitForSpaccIV(gCb);
1247 #endif
1248 #else
1249    /*Call to open file descriptors for interfacing with SPACC*/
1250    if(pjMsSpaccHdlDlfdOpenReq() != ROK)
1251    {
1252       RETVALUE(RFAILED);
1253    }
1254
1255    /*Call to initialise the DL/UL SPAcc queues*/
1256    pjMsSPAccInitDlQue();
1257
1258    /* Init Mem region and Pool */
1259    pjMsSPAccInitDlMemRegionPool(gCb->init.region, gCb->init.pool);
1260 #endif
1261    RETVALUE(ROK);
1262 }
1263
1264 /**
1265 *@brief
1266 * This function calls the function which interfaces with SPAcc
1267 * for opening of the fd. Also, it initializes the SPAcc UL Queues.
1268 *
1269 *@inparam[in] gCb  PDCP Instance Control Block
1270 *@return S16
1271 *
1272 */
1273
1274 #ifdef ANSI
1275 PUBLIC S16 PjLibObdUlInitReq
1276 (
1277 PjCb    *gCb
1278 )
1279 #else
1280 PUBLIC S16 PjLibObdUlInitReq(gCb)
1281 PjCb    *gCb;
1282 #endif
1283 {
1284    TRC3(PjLibObdUlInitReq)
1285
1286 #ifdef INTEL_NATIVE_SPACC
1287    S32 ret = RFAILED;
1288    ret = pjMsSpaccRegIccUlHndl();
1289    if(ret != ROK)
1290    {
1291       printf("Registration of ICC UL handle has failed\n");
1292       RETVALUE(ret);
1293    }
1294    printf("Registration of ICC UL handle has succeeded\n");
1295    ret = pjMsSpaccThreadActivation(appContext.hUAII_Ul);
1296    if(ret != 0)
1297    {
1298       printf("Spacc thread activation has failed\n");
1299       RETVALUE(ret);
1300    }
1301    printf("Spacc thread activation is done\n");
1302    /* Init Mem region and Pool */
1303    pjMsSPAccInitUlMemRegionPool(gCb->init.region, gCb->init.pool);
1304 #ifdef INTEL_SPACC_IV_OPTIMIZATION
1305    pjMsNSpaccUlInitForSpaccIV(gCb);
1306 #endif
1307 #else
1308    /*Call to open file descriptors for interfacing with SPACC*/
1309    if(pjMsSpaccHdlUlfdOpenReq() != ROK)
1310    {
1311       RETVALUE(RFAILED);
1312    }
1313
1314    /*Call to initialise the UL SPAcc queues*/
1315    pjMsSPAccInitUlQue();
1316
1317    /* Init Mem region and Pool */
1318    pjMsSPAccInitUlMemRegionPool(gCb->init.region, gCb->init.pool);
1319 #endif
1320    RETVALUE(ROK);
1321 }
1322
1323
1324 /**
1325  *
1326  * @brief Handler for invoking key derivation function for KeNB*. This is used
1327  * for Handover cases.
1328  *       
1329  *
1330  * @Description: When the eNB decides to perform an intra-eNB handover it
1331  * shall derive KeNB* using target PCI, its frequency EARFCN-DL, and 
1332  * either NH or the current KeNB.
1333  *
1334  * @input: gCb  - Control Block
1335  *         kenbInf - Input structure for KeNB* derivation.
1336  *         kdfCfm  - Output filled into this structure after derivation.
1337  *
1338  *  @return  S16
1339  */
1340 #ifdef ANSI
1341 PUBLIC S16 pjLibObdPrcKenbStarCfg
1342 (
1343 PjCb                   *gCb,
1344 CpjKenbStarInfo*       kenbInf,
1345 CpjKenbStarCfmInfo     *kdfCfm
1346 )
1347 #else
1348 PUBLIC S16 pjLibObdPrcKenbStarCfg(gCb, kenbInf, kdfCfm)
1349 PjCb                   *gCb;
1350 CpjKenbStarInfo*       kenbInf;
1351 CpjKenbStarCfmInfo     *kdfCfm;
1352 #endif
1353 {
1354    PjMsSecInfo  *pSecInfo;
1355    U32 ret=ROK;
1356
1357    TRC2(pjLibObdPrcKenbStarCfg)
1358
1359    PJ_ALLOC(gCb, pSecInfo , sizeof(PjMsSecInfo));
1360    if(pSecInfo == NULLP)
1361    {
1362       RLOG1(L_ERROR, "YsMsUlmPrcKenbStarCfg failed line %d ", __LINE__);
1363       RETVALUE(RFAILED);
1364    }
1365
1366
1367    cmMemcpy(pSecInfo->hash_key, kenbInf->secKey, CPJ_SEC_KEY_LEN);
1368
1369    /* Building the String S = FC || P0 || L0 || P1 || L1 */
1370
1371    /*Values are initialized as per section A7 33.401*/
1372    pSecInfo->strS[0] = 0x13; 
1373    pSecInfo->strS[3] = 0x00;
1374    pSecInfo->strS[4] = 0x02;
1375    pSecInfo->strS[7] = 0x00;
1376    pSecInfo->strS[8] = 0x02;
1377
1378
1379    RLOG2(L_DEBUG,"Value of Cellid, dl Freq is %d %d ", 
1380          kenbInf->physCellId, kenbInf->dlCarrFreq);
1381    /*******************************************
1382     *************kENB* from kENB*************
1383     *******************************************/
1384
1385    /*PCI*/
1386    pSecInfo->strS[1] = kenbInf->physCellId >> 8;
1387    pSecInfo->strS[2] = (U8)kenbInf->physCellId;
1388
1389    /*DL frequency*/
1390    pSecInfo->strS[5] = kenbInf->dlCarrFreq >> 8;
1391    pSecInfo->strS[6] = (U8)kenbInf->dlCarrFreq;
1392
1393    pSecInfo->strSlen = 9;
1394
1395    if((pjSendToKeyDeriveFunc(pSecInfo, kdfCfm->secKey)) != ROK)
1396    {
1397       RLOG0(L_ERROR, "In pjLibObdPrcKenbStarCfg: pjMsKDF failed");
1398       ret = RFAILED;
1399    }/*End of if(ret!=ROK)*/
1400
1401    PJ_FREE(gCb, pSecInfo, sizeof(PjMsSecInfo));
1402
1403    RETVALUE(ret);
1404 }/*End of function*/
1405
1406 /**
1407  *
1408  * @brief Handler for invoking key derivation function for KeNB. KeNB is Key
1409  * derivation funtion. This is normal Ciphering/Integrity Key derivation at
1410  * eNB.
1411  *       
1412  *
1413  * @Description: For Security to be enabled, Integrity and Ciphering keys need
1414  * to be derived. These are applied on SRB/DRB data and the Ciphered/Integrity
1415  * protected PDU are sent to UE.
1416  *
1417  * @input: gCb  - Control Block
1418  *         kenbInf - Input structure for KeNB* derivation.
1419  *         kdfCfm  - Output filled into this structure after derivation.
1420  *
1421  *  @return  S16
1422  */
1423 #ifdef ANSI
1424 PUBLIC S16 pjLibObdPrcKenbCfg
1425 (
1426 PjCb                   *gCb,
1427 CpjAsKeyInfo*       kenbInf,
1428 CpjAskeyCfmInfo     *kdfCfm
1429 )
1430 #else
1431 PUBLIC S16 pjLibObdPrcKenbCfg(kenbInf)
1432 PjCb                   *gCb;
1433 CpjAsKeyInfo*       kenbInf;
1434 CpjAskeyCfmInfo     *kdfCfm;
1435 #endif
1436 {
1437
1438    S16       ret;
1439    PjMsSecInfo  *pSecInfo;
1440
1441
1442    TRC2(pjLibObdPrcKenbCfg)
1443    ret = ROK;
1444
1445    PJ_ALLOC(gCb, pSecInfo, sizeof(PjMsSecInfo));
1446    if(pSecInfo == NULLP)
1447    {
1448       RLOG1(L_ERROR, "YsMsUlmPrcKenbCfg failed line %d ", __LINE__);
1449       RETVALUE(RFAILED);
1450    }
1451
1452
1453    cmMemcpy(pSecInfo->hash_key, kenbInf->secKey, CPJ_SEC_KEY_LEN);
1454
1455    /* Building the String S = FC || P0 || L0 || P1 || L1 */
1456
1457    /*Values are initialized as per section A7 33.401*/
1458    pSecInfo->strS[0] = 0x15;  
1459    pSecInfo->strS[2] = 0x00; 
1460    pSecInfo->strS[3] = 0x01;
1461    pSecInfo->strS[5] = 0x00; 
1462    pSecInfo->strS[6] = 0x01;
1463
1464    pSecInfo->strSlen = 7;
1465
1466    /*******************************************
1467     *************CP Ciphering key*************
1468     *******************************************/
1469    pSecInfo->strS[1] = 0x3;
1470    pSecInfo->strS[4] = kenbInf->ciphAlgoType;
1471
1472    ret = pjSendToKeyDeriveFunc(pSecInfo, kdfCfm->cpCiphKey);
1473    if(ret!=ROK)
1474    {
1475       RLOG0(L_ERROR, "Control Plane Cipher Key derivation failed");
1476       PJ_FREE(gCb, pSecInfo, sizeof(PjMsSecInfo));
1477       RETVALUE(RFAILED);
1478    }/*End of if(ret!=ROK)*/
1479
1480
1481    /*******************************************
1482     *************UP Ciphering key*************
1483     *******************************************/
1484    pSecInfo->strS[1] = 0x5;
1485    pSecInfo->strS[4] = kenbInf->ciphAlgoType;
1486
1487    ret = pjSendToKeyDeriveFunc(pSecInfo, kdfCfm->upCiphKey);
1488    if(ret!=ROK)
1489    {
1490       RLOG0(L_ERROR, "User Plane Cipher Key derivation failed");
1491       PJ_FREE(gCb, pSecInfo, sizeof(PjMsSecInfo));
1492       RETVALUE(RFAILED);
1493    }/*End of if(ret!=ROK)*/
1494
1495    RLOG0(L_DEBUG, "Ciphering Key (UP) Derived");
1496
1497    /*******************************************
1498     ************RRC Integrity key*************
1499     *******************************************/
1500    pSecInfo->strS[1] = 0x4;
1501    pSecInfo->strS[4] = kenbInf->intgAlgoType;
1502
1503    ret = pjSendToKeyDeriveFunc(pSecInfo, kdfCfm->intKey);
1504    if(ret!=ROK)
1505    {
1506       RLOG0(L_ERROR, "Integrity Key derivation failed");
1507       PJ_FREE(gCb, pSecInfo, sizeof(PjMsSecInfo));
1508       RETVALUE(RFAILED);
1509    }/*End of if(ret!=ROK)*/
1510
1511    RLOG0(L_DEBUG, "Integrity Key Derived");
1512
1513    PJ_FREE(gCb, pSecInfo, sizeof(PjMsSecInfo));
1514
1515
1516    RETVALUE(ROK);
1517 }/*End of function*/
1518
1519
1520 /**
1521  *
1522  * @brief 
1523  *
1524  *        Provides input params like Keys, RbId, direction which would be used
1525  *        as input for creation of SPAcc i/p structure..
1526  *
1527  * @b Description:
1528  *
1529  *        This function sends Intergrity protection request with elevant input parameters.
1530  *
1531  *  @param[in]   pjRbCb       PDCP RbCb 
1532  *  @param[in]   intCxtId       Input parameters for integrity 
1533  *  @param[in]   mBuf         SDU to be compressed 
1534  *  @param[out]  libTrans      Input to integrity algo (RbId, Count, Direction) 
1535  *
1536  *  @return  S16
1537  *      -# ROK 
1538  *
1539  */
1540
1541 #ifdef ANSI
1542 PUBLIC S16 PjLibObdIntProtReq
1543 (
1544 PjLibTrans  *libTrans,
1545 Buffer      **mBuf
1546 )
1547 #else
1548 PUBLIC S16 PjLibObdIntProtReq(libTrans, mBuf)
1549 PjLibTrans  *libTrans;
1550 Buffer      **mBuf;
1551 #endif
1552 {
1553
1554    U32 ret = ROK;
1555    U32 dummyMacI =0 ;
1556    TRC3(PjLibObdIntProtReq)
1557
1558    if(libTrans->intAlgoType == PJ_SPACC_EIA1)
1559    {
1560       ret = pjMsSpaccIntegProtPkt(libTrans, mBuf);
1561    }
1562    else if (libTrans->intAlgoType == PJ_SPACC_EIA2)
1563    {
1564       ret = pjMsSpaccAesIntegProtPkt(libTrans, mBuf);
1565    }
1566    else if (libTrans->intAlgoType == PJ_SPACC_EIA3)
1567    {
1568       ret = pjMsSpaccIntegProtPkt(libTrans, mBuf);
1569    }
1570    else
1571    {
1572       /* NULL Algorithm */
1573       PJ_PACK_MACI(*mBuf, dummyMacI);
1574    }
1575
1576    RETVALUE(ret);
1577 }
1578
1579 /**
1580  *
1581  * @brief 
1582  *
1583  *        Handler for redirecing Integration request to SPAcc module.
1584  *
1585  * @b Description:
1586  *
1587  *        This function sends Intergrity verification request along with relevant input parameters.
1588  *
1589  *  @param[in]   PjCb        PDCP Cb 
1590  *  @param[in]   PTR        Handle for Integrity verification (handle opened during spacc_dev_open)  
1591  *  @param[in]   PjLibTrans        Input parameters for integrity 
1592  *  @param[in]   mBuf          SDU to be compressed 
1593  *  @param[out]  macI        MAC-I 
1594  *
1595  *  @return  S16
1596  *      -# ROK 
1597  *
1598  */
1599 #ifdef ANSI
1600 PUBLIC S16 PjLibObdIntVerReq
1601 (
1602 PjLibTrans  *libTrans,
1603 Buffer      *mBuf,
1604 U32         macI
1605 )
1606 #else
1607 PUBLIC S16 PjLibObdIntVerReq(libTrans, mBuf, macI)
1608 PjLibTrans  *libTrans;
1609 Buffer      *mBuf;
1610 U32         macI;
1611 #endif
1612 {
1613    U32 ret = ROK;
1614    TRC3(PjLibObdIntVerReq)
1615
1616    if(libTrans->intAlgoType != 0)
1617    {
1618       ret = pjMsSpaccIntegVerifyPkt(libTrans, &mBuf, macI);
1619    }
1620    else
1621    {
1622      RLOG_ARG0(L_ERROR,DBG_UEID,libTrans->ueId,"Integrity protection Algo type is == 0 ");
1623    }
1624
1625    RETVALUE(ret);
1626 }
1627
1628
1629 /**
1630 *@brief
1631 * This function calls the function which interfaces with SPAcc
1632 * for closing the DL fd. 
1633 *
1634 *@return S16
1635 *        -ROK
1636 *
1637 */
1638 #ifdef ANSI
1639 PUBLIC S16 PjLibObdDlCloseReq(Void)
1640 #else
1641 PUBLIC S16 PjLibObdDlCloseReq(Void)
1642 #endif
1643 {
1644
1645    TRC3(PjLibObdDlCloseReq)
1646    pjSpaccDeInitCiphQ();
1647    pjMsSPAccDlfdCloseReq();
1648    RETVALUE(ROK);
1649
1650 }
1651
1652 /**
1653 *@brief
1654 * This function calls the function which interfaces with SPAcc
1655 * for closing the UL fd. 
1656 *
1657 *@return S16
1658 *        -ROK
1659 *
1660 */
1661 #ifdef ANSI
1662 PUBLIC S16 PjLibObdUlCloseReq(Void)
1663 #else
1664 PUBLIC S16 PjLibObdUlCloseReq(Void)
1665 #endif
1666 {
1667
1668    TRC3(PjLibObdUlCloseReq)
1669    pjSpaccDeInitDeCipherQ();
1670    pjMsSPAccUlfdCloseReq();
1671    RETVALUE(ROK);
1672
1673 }
1674
1675
1676 /**
1677  *
1678  * @brief 
1679  *
1680  *        Handler for redirecing ciphering request to SPAcc Module.
1681  *
1682  * @b Description:
1683  *
1684  *        This function sends ciphering protection request along with relevant input parameters.
1685  *
1686  *  @param[in]   PjCb           PDCP Cb 
1687  *  @param[in]   PjLibTrans      libTrans( Input parameters for deciphering )
1688  *  @param[in]   mBuf             Data to be deciphered 
1689  *  @param[in]   opSdu            Deciphered SDU 
1690  *  @param[in]   cxtId          Handle for ciphering either for User/Control plane.
1691  *
1692  *  @return  S16
1693  *      -# ROK 
1694  *
1695  */
1696
1697 #ifdef ANSI
1698 PUBLIC S16 PjLibObdCipherReq
1699 (
1700 PjLibTrans  *libTrans,
1701 Buffer      *mBuf,
1702 Buffer      **opSdu
1703 )
1704 #else
1705 PUBLIC S16 PjLibObdCipherReq(libTrans, mBuf, opSdu)
1706 PjLibTrans  *libTrans;
1707 Buffer      *mBuf;
1708 Buffer      **opSdu;
1709 #endif
1710 {
1711    U32 ret = ROK;
1712
1713    TRC3(PjLibObdCipherReq)
1714
1715    ret = pjSendToCipher(libTrans, mBuf);
1716
1717    RETVALUE(ret);
1718 }
1719
1720
1721 #ifdef FLAT_BUFFER_OPT
1722 /**
1723  *
1724  * @brief 
1725  *
1726  *        Handler for redirecing ciphering request to SPAcc Module.
1727  *
1728  * @b Description:
1729  *
1730  *        This function sends ciphering protection request along with relevant input parameters.
1731  *
1732  *  @param[in]   PjCb           PDCP Cb 
1733  *  @param[in]   PjLibTrans     libTrans( Input parameters for deciphering )
1734  *  @param[in]   mBuf           Flat Buffer to be deciphered 
1735  *  @param[in]   opSdu          Deciphered SDU 
1736  *  @param[in]   cxtId          Handle for ciphering either for User/Control plane.
1737  *
1738  *  @return  S16
1739  *      -# ROK 
1740  *
1741  */
1742
1743 #ifdef ANSI
1744 PUBLIC S16 PjLibObdCipherReqFB
1745 (
1746 PjLibTrans  *libTrans,
1747 FlatBuffer  *mBuf,
1748 Buffer      **opSdu
1749 )
1750 #else
1751 PUBLIC S16 PjLibObdCipherReqFB(libTrans, mBuf, opSdu)
1752 PjLibTrans  *libTrans;
1753 FlatBuffer  *mBuf;
1754 Buffer      **opSdu;
1755 #endif
1756 {
1757
1758    U32 ret = ROK;
1759
1760    TRC3(PjLibObdCipherReqFB)
1761
1762    ret = pjSendToCipherFB(libTrans, mBuf);
1763
1764    RETVALUE(ret);
1765 }
1766 #endif
1767
1768
1769 /**
1770  *
1771  * @brief 
1772  *
1773  *        Handler for redirecing deciphering request to SPAcc module.
1774  *
1775  * @b Description:
1776  *
1777  *        This function sends deciphering request along with relevant input parameters.
1778  *
1779  *  @param[in]   PjCb           PDCP Cb 
1780  *  @param[in]   PTR            Handle for Deciphering (stored during spacc_dev_open) 
1781  *  @param[in]   PjLibTrans           Input parameters for deciphering 
1782  *  @param[in]   mBuf             Data to be deciphered 
1783  *  @param[in]   opSdu            Deciphered SDU 
1784  *
1785  *  @return  S16
1786  *      -# ROK 
1787  *
1788  */
1789 #ifdef ANSI
1790 PUBLIC S16 PjLibObdDecipherReq
1791 (
1792 PjLibTrans  *libTrans,
1793 Buffer      *mBuf,
1794 Buffer      **opSdu
1795 )
1796 #else
1797 PUBLIC S16 PjLibObdDecipherReq(libTrans, mBuf, opSdu)
1798 PjLibTrans  *libTrans;
1799 Buffer      *mBuf;
1800 Buffer      **opSdu;
1801 #endif
1802 {
1803    U32 ret = ROK;
1804
1805    TRC3(PjLibObdDecipherReq)
1806
1807    ret = pjSendToDeCipher(libTrans, mBuf);
1808
1809    RETVALUE(ret);
1810
1811 }
1812 #else
1813
1814 #ifdef ANSI
1815 PUBLIC S16 pjLibObdPrcKenbCfg
1816 (
1817 PjCb                   *gCb,
1818 CpjAsKeyInfo*       kenbInf,
1819 CpjAskeyCfmInfo     *kdfCfm
1820 )
1821 #else
1822 PUBLIC S16 pjLibObdPrcKenbCfg(gCb, kenbInf, kdfCfm)
1823 PjCb                   *gCb;
1824 CpjAsKeyInfo*       kenbInf;
1825 CpjAskeyCfmInfo     *kdfCfm;
1826 #endif
1827 {
1828    TRC2(pjLibObdPrcKenbCfg);
1829    RETVALUE(ROK);
1830 }
1831
1832 #ifdef ANSI
1833 PUBLIC S16 pjLibObdPrcKenbStarCfg
1834 (
1835 PjCb                   *gCb,
1836 CpjKenbStarInfo*       kenbInf,
1837 CpjKenbStarCfmInfo     *kdfCfm
1838 )
1839 #else
1840 PUBLIC S16 pjLibObdPrcKenbStarCfg(gCb, kenbInf, kdfCfm)
1841 PjCb                   *gCb;
1842 CpjKenbStarInfo*       kenbInf;
1843 CpjKenbStarCfmInfo     *kdfCfm;
1844 #endif
1845 {
1846
1847    TRC2(pjLibObdPrcKenbStarCfg);
1848    RETVALUE(ROK);
1849
1850 }
1851
1852
1853 #ifdef ANSI
1854 PUBLIC S16 pjLibDecipherReq
1855 (
1856 PTR         intCxtId,           /* Context Id for compression */
1857 PjSecInp    secInp,             /* Input for Deciphering */
1858 Buffer      *mBuf,              /* SDU to be deciphered */
1859 Buffer      **opSdu             /* deciphered SDU */
1860 )
1861 #else
1862 PUBLIC S16 pjLibDecipherReq(intCxtId, secInp, mBuf, opSdu)
1863 PTR         intCxtId;           /* Context Id for Deciphering */
1864 PjSecInp    secInp;             /* Input for Deciphering */
1865 Buffer      *mBuf;              /* SDU to be Deciphering */
1866 Buffer      **opSdu;            /* Deciphering SDU */
1867 #endif
1868 {
1869    TRC3(pjLibDecipherReq)
1870 #ifdef LTE_PAL_ENB
1871    *opSdu = mBuf;
1872 #endif
1873    RETVALUE(ROK);
1874
1875 } /* end of pjLibDecipherReq */
1876
1877
1878 #ifdef ANSI
1879 PUBLIC S16 pjLibIntVerReq 
1880 (
1881 PTR        intCxtId,                /* Context Id for compression */
1882 PjSecInp   secInp,                  /* Input for Integrity protection */                  
1883 Buffer     *mBuf,                   /* SDU to be compressed */
1884 U32        macI,                    /* Message authentication code for the SDU */
1885 Status     *status                  /* Status of the Integrity verification */
1886 )
1887 #else
1888 PUBLIC S16 pjLibIntVerReq(intCxtId, secInp, mBuf, macI, status)
1889 PTR        intCxtId;                /* Context Id for compression */
1890 PjSecInp   secInp;                  /* Input for Integrity protection */
1891 Buffer     *mBuf;                   /* SDU to be compressed */
1892 U32        macI;                    /* Message authentication code for the SDU */
1893 Status     *status;                 /* Status of the Integrity verification */
1894 #endif
1895 {
1896    TRC3(pjLibIntVerReq)
1897    RETVALUE(ROK);
1898
1899 } /* end of pjLibIntVerReq */
1900
1901 #ifdef ANSI
1902 PUBLIC S16 PjLibObdIntProtReq
1903 (
1904 PjLibTrans  *libTrans,
1905 Buffer      **mBuf
1906 )
1907 #else
1908 PUBLIC S16 PjLibObdIntProtReq(libTrans, mBuf)
1909 PjLibTrans  *libTrans;
1910 Buffer      **mBuf;
1911 #endif
1912 {
1913 #ifdef LTE_PAL_ENB
1914    Buffer *mBuf1;
1915 #endif
1916    TRC3(PjLibObdIntProtReq);
1917 #ifdef LTE_PAL_ENB
1918    SAddMsgRef(*mBuf, 0,0, &mBuf1);
1919
1920    *mBuf = mBuf1;
1921 #endif
1922    RETVALUE(ROK);
1923 }
1924
1925
1926 #ifdef ANSI
1927 PUBLIC S16 PjLibObdCipherReq
1928 (
1929 PjLibTrans  *libTrans,
1930 Buffer      *mBuf,
1931 Buffer      **opSdu
1932 )
1933 #else
1934 PUBLIC S16 PjLibObdCipherReq(libTrans, mBuf, opSdu)
1935 PjLibTrans  *libTrans;
1936 Buffer      *mBuf;
1937 Buffer      **opSdu;
1938 #endif
1939 {
1940
1941    TRC3(PjLibObdCipherReq);
1942 #ifdef LTE_PAL_ENB
1943    SAddMsgRef(mBuf, 0,0, opSdu);
1944
1945 #endif
1946    RETVALUE(ROK);
1947
1948 }
1949 #endif
1950
1951 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
1952 #define PJ_MAX_SDUS_TO_WAIT_FOR_ACK  1200 
1953 PRIVATE U32 gMemoryAlarm;
1954 /* 384MB => 768M total 
1955 cat /sys/devices/virtual/icc/iccserv/mm
1956 ============
1957 Partition_7f1c7890 - type: LOCAL PART
1958 Split logic is currently disabled
1959 Part start address_9a200000, end address_ca1fffff
1960 Size ...................... 786432 KiB
1961 nBlocks ................... 304085
1962 Number of pools ........... 4
1963 GAP (between sectors) ..... 128 Bytes
1964 Pools info:
1965 Pool_0: BlkSize_(useful_384, total_512), BlkCnt_104856, FreeBlkCnt_97177
1966 Pool_1: BlkSize_(useful_1920, total_2048), BlkCnt_157285, FreeBlkCnt_130668
1967 Pool_2: BlkSize_(useful_3968, total_4096), BlkCnt_20970, FreeBlkCnt_11245
1968 Pool_3: BlkSize_(useful_16256, total_16384), BlkCnt_20970, FreeBlkCnt_12122
1969 ============*/
1970 #endif
1971
1972 PUBLIC U32 dbgSpaccThreshHoldDropCnt = 0;
1973 PUBLIC U32 dbgPdcpQSizeThreshHoldDropCnt = 0;
1974 PUBLIC U32 dbgPdcpMemCount = 0;
1975 PUBLIC U32 pdcpDropMemTh = 0;
1976 PUBLIC U32 dbgICCMemThreshHoldDropCnt = 0;
1977 PUBLIC U32 dbgSSIMemThreshHoldDropCnt = 0;
1978 PUBLIC U32 dbgICCMemAlarm;
1979 PUBLIC U32 dbgPdcpQMsSpaccQFull = 0;
1980 PUBLIC U32 dbgPdcpRbOverload = 0;
1981 /* kw003.201 This function is for admission control at packet level */
1982 #ifdef ANSI
1983 PUBLIC S16 pjLibPktAdmCtrl
1984 (
1985 PjDlRbCb        *pjRbCb,
1986 Buffer        *pkt
1987
1988 #else
1989 PUBLIC S16 pjLibPktAdmCtrl(pjRbCb, pkt)
1990 PjDlRbCb        *pjRbCb;
1991 Buffer        *pkt;
1992 #endif 
1993 {
1994    TRC3(pjLibPktAdmCtrl)
1995    /* Patch kw004.201 */
1996 #ifdef SS_CAVIUM
1997       if(pjRbCb->dlCb.txBuf.numEntries > 450)
1998       {
1999          RETVALUE(RFAILED);
2000       }
2001 #endif
2002 #ifdef LTE_PAL_ENB
2003       if(pjRbCb->dlCb.txBuf.numEntries > 1200)
2004       {
2005          RETVALUE(RFAILED);
2006       }
2007 #endif
2008 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
2009    if(pjRbCb->dlCb.txBuf.numEntries > PJ_MAX_SDUS_TO_WAIT_FOR_ACK)
2010    {
2011       dbgPdcpQSizeThreshHoldDropCnt++;
2012       /*This is for AM bearers only.  FC for UDP on AM will also
2013         be taken care here. */
2014 #ifdef TENB_STATS
2015       if (pjRbCb->ueCb->tenbStats)
2016       {
2017          pjRbCb->ueCb->tenbStats->stats.nonPersistent.pdcp.dlPdcpAckWaitDropCnt++;
2018       }
2019 #endif
2020       RETVALUE(RFAILED);
2021    }
2022
2023    /* Check the SPAcc queue too as we need to start dropping the PDUs in case
2024     * if SPAcc queue is waiting more number of PDUs
2025     */
2026    if(FALSE == (pjMsCheckSpaccQueue(FALSE)))
2027    {
2028       dbgSpaccThreshHoldDropCnt++;
2029       dbgPdcpQMsSpaccQFull++;
2030       RETVALUE(RFAILED);
2031    }
2032    /* Memory threshold is reached then drop the packet  */
2033    if(isMemThreshReached(pjCb[1]->init.region) != ROK)
2034    {
2035       {
2036          extern U32 pdcpdrop;
2037          pdcpdrop++;
2038          //MSPD_LOG("at PDCPdrop %d new %d\n",pdcpdrop);
2039       }
2040       RETVALUE(RFAILED);
2041    }
2042
2043       dbgICCMemAlarm=gMemoryAlarm;
2044 #endif
2045    if (pjRbCb->dropOnlyOne)
2046    {
2047 #ifdef TENB_STATS
2048       /*FC for AM bearers*/
2049       if (pjRbCb->ueCb->tenbStats)
2050       {
2051          pjRbCb->ueCb->tenbStats->stats.nonPersistent.pdcp.dlPdcpDropCnt++;
2052       }
2053
2054 #endif
2055
2056       dbgPdcpMemCount++;
2057       pjRbCb->dropOnlyOne = 0;
2058       RETVALUE(RFAILED);
2059    }
2060    if ((pjRbCb->pktAdmitCnt) && (pjRbCb->pktCnt > pjRbCb->pktAdmitCnt))
2061    {
2062      /* FC for UM bearers */
2063 #ifdef TENB_STATS
2064       /*FC for AM bearers*/
2065       if (pjRbCb->ueCb->tenbStats)
2066       {
2067          pjRbCb->ueCb->tenbStats->stats.nonPersistent.pdcp.dlPdcpDropCnt++;
2068       }
2069 #endif
2070       RETVALUE(RFAILED);
2071    }
2072    /* Pkt admitted. Counting it in.*/
2073    pjRbCb->pktCnt++;
2074    RETVALUE(ROK);
2075
2076 } /* end of pjLibPktAdmCtrl */
2077
2078 #ifdef TENB_AS_SECURITY
2079 /**
2080  * @brief This function is used to Process the o/p from SPAcc.
2081  *
2082  * @details This function is used to Process ciphered PDU's from SPAcc. We
2083  * check if SPAcc has ciphered all PDU's successfully or not. If success we
2084  * pass it to lower layers. If Failure, we initimate failure.
2085  *
2086  * @param[in]         - Void
2087
2088  *
2089  * @return            - Void
2090  */
2091 #ifdef ANSI
2092 PUBLIC Void pjMsSpaccProcessDlBatchOutput(Void)
2093 #else
2094 PUBLIC Void pjMsSpaccProcessDlBatchOutput(Void)
2095 #endif
2096 {
2097    U32 ret=ROK;
2098    U32 jobNum=1;
2099    Buffer *opSdu=NULLP;
2100    PjMsSPACCOutputMapInfo spaccInfo;
2101
2102
2103    for(;;)
2104    {
2105       /* Fetch Ciphered PDU's one by one from SPAcc */
2106       ret = pjMsSpaccFetchDlPduInfo(&spaccInfo, &opSdu, jobNum, ROK);
2107
2108       /*No further packets for processing so break from here*/
2109       if(ret == ROKDNA)
2110       {
2111          break;
2112       }
2113
2114       if(ret == RFAILED)
2115       {
2116          /* Handling of failure of any of the Deciphered PDU's */
2117          if((pjHndlCiphFail(&spaccInfo)) != ROK)
2118          {
2119             /* We get to this scenario when ueCb/RbCb/TxEnt is deleted already
2120            due to either re-establishment or any other scenario. So we just
2121            drop the packets for these */
2122            PJ_FREE_BUF(opSdu);
2123          }
2124       }
2125       else
2126       {
2127          /*Send the packet to RLC*/
2128          pjProcCiphPdu(opSdu, &spaccInfo);
2129       }
2130
2131       jobNum++;
2132
2133       /* Num PDU's sent to SPAcc cant be greater than the below condition.
2134        * Hence break */
2135       if(jobNum > (PJ_MS_MAX_JOBS_IN_QUEUE + 2))
2136       {
2137          RLOG1(L_ERROR, "Num Jobs in pjMsSpaccProcessDlBatchOutput "
2138                "exceeds %ld, hence exiting!!!!", jobNum);
2139          break;
2140       }   
2141    }
2142 }
2143
2144 /**
2145  * @brief This function is used to Process the o/p from SPAcc.
2146  *
2147  * @details This function is used to Process Deciphered PDU's from SPAcc. We
2148  * check if SPAcc has deciphered all PDU's successfully or not. If success we
2149  * pass it to lower layers. If Failure, we initimate failure.
2150  *
2151  * @param[in]         - Void
2152
2153  *
2154  * @return            - Void
2155  */
2156 #ifdef ANSI
2157 PUBLIC Void pjMsSpaccProcessUlBatchOutput(Void)
2158 #else
2159 PUBLIC Void pjMsSpaccProcessUlBatchOutput(Void)
2160 #endif
2161 {
2162    U32 ret=ROK;
2163    U32 retval = ROK;
2164    U32 jobNum=1;
2165    Buffer *opSdu=NULLP;
2166    PjMsSPACCOutputMapInfo spaccInfo;
2167
2168    for(;;)
2169    {
2170       ret = pjMsSpaccFetchUlPduInfo(&spaccInfo, &opSdu, jobNum, ROK);
2171       if(ret == ROKDNA)
2172       {
2173          break;
2174       }
2175
2176       if(ret == RFAILED)
2177       {
2178          /* If one of the packets sent to SPAcc returns a failure, trigger
2179          * handling of this failure scenario */
2180          retval = pjHdlDecipherFailure(&spaccInfo);
2181       }
2182       else
2183       {
2184          /* Success case */
2185          retval = pjProcDeCipherPdu(&spaccInfo, opSdu);
2186       }
2187
2188       if(retval != ROK)
2189       {
2190          /* Drop o/p pdu's as either ueCb/RbCb/RxEnt is already deleted
2191          due to reestablishment or other scenario */
2192          PJ_FREE_BUF(opSdu);
2193       }
2194
2195       jobNum++;
2196
2197       if(jobNum > (PJ_MS_MAX_JOBS_IN_QUEUE + 2))
2198       {
2199          RLOG1(L_ERROR, "Num Jobs in PjUlSpaccTrigger exceeds %ld,"
2200                " hence aborting!!!!", jobNum);
2201          break;
2202       }   
2203    }
2204 }
2205
2206
2207 /**
2208  * @brief This function is used to deInit the CipherQ
2209  *
2210  * @details 
2211  *
2212  * @param[in]         - Void
2213
2214  *
2215  * @return            - Void
2216  */
2217 #ifdef ANSI
2218 PUBLIC Void pjSpaccDeInitCiphQ(Void)
2219 #else
2220 PUBLIC Void pjSpaccDeInitCiphQ(Void)
2221 #endif
2222 {
2223 #ifdef INTEL_NATIVE_SPACC
2224    pjMsNativeSpaccDeInitCiphQ();
2225 #else
2226    pjMsSpaccDeInitCiphQ();
2227 #endif
2228    RETVOID;
2229 }
2230
2231 /**
2232  * @brief This function is used to deInit the DeCipherQ
2233  *
2234  * @details 
2235  *
2236  * @param[in]         - Void
2237
2238  *
2239  * @return            - Void
2240  */
2241 #ifdef ANSI
2242 PUBLIC Void pjSpaccDeInitDeCipherQ(Void)
2243 #else
2244 PUBLIC Void pjSpaccDeInitDeCipherQ(Void)
2245 #endif
2246 {
2247 #ifdef INTEL_NATIVE_SPACC
2248    pjMsNativeSpaccDeInitDeCiphQ();
2249 #else
2250    /*pjMsSpaccDeInitCiphQ();*/
2251    pjMsSpaccDeInitDeCipherQ();
2252 #endif
2253    RETVOID;
2254 }
2255
2256 #endif
2257
2258 /**
2259  *
2260  * @brief 
2261  *
2262  *        pjUlBatchProcSplit- Process rbuf messages
2263  *
2264  *  @return  S16
2265  *      -# ROK 
2266  */
2267 #if defined(L2_L3_SPLIT) && defined(ICC_RECV_TSK_RBUF)
2268 #ifdef ANSI
2269 PUBLIC S16 pjUlBatchProcSplit 
2270 (
2271 Void
2272 )
2273 #else
2274 PUBLIC S16 pjUlBatchProcSplit()
2275 Void;
2276 #endif
2277 {
2278   S16 ret1;
2279 /* Read from Ring Buffer and process PDCP packets */
2280    Void *elmIndx = NULLP;
2281    RxmBufReq *datInd = NULLP;
2282    elmIndx = SRngGetRIndx(SS_RNG_BUF_RX_TO_ULPDCP);
2283    while(NULLP != elmIndx)
2284    {
2285       datInd = (RxmBufReq *)elmIndx;
2286       if(datInd->mBuf != NULLP)
2287       {
2288           ret1 = cmUnpkKwuDatInd(PjLiKwuDatInd, &datInd->pst, datInd->mBuf);
2289           if(ret1 != ROK)
2290           {
2291 #if (ERRCLASS & ERRCLS_DEBUG)
2292               SLogError(ENTPJ, 0, SFndProcId(),
2293                       __FILE__, __LINE__, (ErrCls)ERRCLS_DEBUG,
2294                       (ErrVal)EPJXXX, (ErrVal)ERRZERO, "UNPACK ERROR\n");
2295 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2296           }
2297       }
2298       else
2299       {
2300 #if (ERRCLASS & ERRCLS_DEBUG)
2301           SLogError(ENTPJ, 0, SFndProcId(),
2302                   __FILE__, __LINE__, (ErrCls)ERRCLS_DEBUG,
2303                   (ErrVal)EPJXXX, (ErrVal)ERRZERO, "pjUlBatchProcSplit: mBuf NULL\n");
2304 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
2305           if(datInd->mBuf)
2306               cmUnpkKwuDatInd(PjLiKwuDatInd, &datInd->pst, datInd->mBuf);
2307       }
2308       
2309       SsRngInfoTbl[SS_RNG_BUF_RX_TO_ULPDCP].nPktProc++;;//Number of pkt processed in tti
2310       datInd->mBuf = NULLP;
2311       SRngIncrRIndx(SS_RNG_BUF_RX_TO_ULPDCP);
2312
2313       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_RX_TO_ULPDCP)) == NULLP)
2314       break;
2315    }
2316
2317    RETVALUE(ROK);
2318 }
2319 #endif
2320
2321 #endif /* PTPJLIB */
2322
2323
2324 #ifdef ANSI
2325 PUBLIC S16 PjLibObdIntCloseReq
2326 (
2327 Void *intCxtId
2328 )
2329 #else
2330 PUBLIC S16 PjLibObdIntCloseReq(*intCxtId)
2331 Void *intCxtId;
2332 #endif
2333 {
2334    TRC3(PjLibObdIntCloseReq)
2335    RETVALUE(ROK);
2336 }
2337
2338
2339
2340 \f  
2341 /********************************************************************30**
2342          End of file
2343 **********************************************************************/