Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_uim.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /********************************************************************20**
20   
21         Name:    LTE-PDCP Layer - Upper Interface Functions
22     
23         Type:    C file
24   
25         Desc:    Source code for PDCP Upper Interface Module
26                  This file contains following functions
27       
28         --PjUiCpjBndReq
29         --PjUiCpjUbndReq
30         --PjUiCpjCfgReq
31         --PjUiCpjUeIdChgReq
32         --PjUiCpjReEstReq
33         --PjUiCpjSecCfgReq
34         --PjUiCpjSduStaReq
35      
36
37         --PjUiPjuBndReq
38         --PjUiPjuUbndReq
39         --PjUiPjuDatReq
40         --PjUiPjuSduStaReq 
41
42      File:     pj_uim.c
43
44 **********************************************************************/
45 static const char* RLOG_MODULE_NAME="PDCP";
46 static int RLOG_MODULE_ID=1024;
47 static int RLOG_FILE_ID=227;
48 /** @file pj_uim.c
49 @brief PDCP Upper Interface Module 
50 */
51
52 \f
53 /* header (.h) include files */
54 #include "envopt.h"        /* environment options */
55 #include "envdep.h"        /* environment dependent */
56 #include "envind.h"        /* environment independent */
57
58 #include "gen.h"           /* general */
59 #include "ssi.h"           /* system services */
60 #include "cm5.h"           /* common timer defines */
61 #include "cm_tkns.h"       /* common tokens defines */
62 #include "cm_mblk.h"       /* common memory allocation library defines */
63 #include "cm_llist.h"      /* common link list  defines  */
64 #include "cm_hash.h"       /* common hash list  defines */
65 #include "cm_lte.h"        /* common LTE defines */
66 #include "lpj.h"           /* LPJ define */
67 #include "cpj.h"           /* RRC layer */
68 #include "pju.h"           /* PDCP service user */
69 #include "pj_env.h"        /* RLC environment options */
70 #include "pj.h"            /* RLC defines */
71 #include "pj_ul.h"
72 #include "pj_dl.h"
73 #include "pj_err.h"
74 #include "pj_udx.h"  /* udx interface */
75
76 /* extern (.x) include files */
77 #include "gen.x"           /* general */
78 #include "ssi.x"           /* system services */
79
80 #include "cm5.x"           /* common timer library */
81 #include "cm_tkns.x"       /* common tokens */
82 #include "cm_mblk.x"       /* common memory allocation */
83 #include "cm_llist.x"      /* common link list */
84 #include "cm_hash.x"       /* common hash list */
85 #include "cm_lte.x"        /* common LTE includes */
86 #include "cm_lib.x"        /* common memory allocation library */
87 #include "lpj.x"           /* LM(PDCP) */
88 #include "cpj.x"           /* RRC layer */
89 #include "pju.x"           /* PDCP service user */
90 #include "pj.x"
91 #include "pj_udx.h"
92 #include "pj_udx.x"
93 #include "pj_ul.x"
94 #include "pj_dl.x"
95 #include "pj_lib.x"
96 /* kw004.201 Assigned build issue in LTE RLC pj_uim.c */
97
98 #ifdef __cplusplus
99 EXTERN "C" {
100 #endif /* __cplusplus */
101
102 \f
103
104 /*****************************************************************************
105  *                          CPJ INTERFACE
106  ****************************************************************************/
107 /**
108  *
109  * @brief 
110  *
111  *        Handler for binding the PDCP upper layer service user with 
112  *        the PDCP layer.
113  *
114  * @b Description:
115  *
116  *        1. This function is used by PDCP user to request for binding to 
117  *        PDCP. @n
118  *        2. This function is called by the CPJ interface to bind 
119  *        PDCP's SAP (identified by spId) with the service user's
120  *        SAP (identified by suId). @n
121  *
122  *  @param[in] pst   Post structure  
123  *  @param[in] suId  Service user SAP ID 
124  *  @param[in] spId  Service provider ID
125  *
126  *  @return  S16
127  *      -# ROK 
128  *
129  */
130 #ifdef ANSI
131 PUBLIC S16 PjUiCpjBndReq 
132 (
133 Pst  *pst,   
134 SuId suId,  
135 SpId spId   
136 )
137 #else
138 PUBLIC S16 PjUiCpjBndReq (pst, suId, spId)
139 Pst *pst;    
140 SuId suId;   
141 SpId spId;   
142 #endif
143 {
144    PjCpjSapCb      *cpjSap;            /* pointer to session SAP */
145    S16             ret;                /* return value */
146    PjCb            *tPjCb;
147
148    TRC3(PjUiCpjBndReq)
149
150    ret = ROK;
151
152    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)   /* KW_FIX */
153    {
154        RETVALUE(RFAILED);
155    }
156
157    tPjCb = PJ_GET_PJCB(pst->dstInst);
158
159    RLOG2(L_DEBUG, "PjUiCpjBndReq(pst, spId(%d), suId(%d))", spId, suId);
160
161   
162
163    cpjSap = &(tPjCb->u.ulCb->cpjSap);
164
165    /* Verify CPJ SAP State */
166    switch(cpjSap->state)
167    {
168       /* SAP is configured but not bound */
169       case PJ_SAP_CFG:
170       case PJ_SAP_UBND:
171       {
172          /* copy bind configuration parameters in SSAP sap */
173          cpjSap->suId = suId;
174          cpjSap->pst.dstProcId = pst->srcProcId;
175          cpjSap->pst.dstEnt = pst->srcEnt;
176          cpjSap->pst.dstInst = pst->srcInst;
177
178          /* Update the State */
179          cpjSap->state = PJ_SAP_BND;
180
181          RLOG1(L_DEBUG, "PjUiCpjBndReq: state (%d)", cpjSap->state);
182          break;
183       }
184
185       /* SAP is already bound */
186       case PJ_SAP_BND:
187       {
188          /* 
189           * Sap is already bound check source, destination Entity and 
190           * Proc Id
191           */
192          if (cpjSap->pst.dstProcId != pst->srcProcId 
193                || cpjSap->pst.dstEnt != pst->srcEnt
194                || cpjSap->pst.dstInst != pst->srcInst
195                || cpjSap->suId != suId)
196          {
197             PJ_SEND_SAPID_ALARM(tPjCb, spId, LPJ_EVENT_CPJ_BND_REQ, LCM_CAUSE_INV_PAR_VAL);
198
199             RLOG1(L_DEBUG, "PjUiCpjBndReq: SAP already bound -- state(%d)", cpjSap->state);
200             ret = RFAILED;
201          }
202          break;
203       }
204
205      default:
206       {
207          PJ_SEND_SAPID_ALARM(tPjCb,spId, LPJ_EVENT_CPJ_BND_REQ, LCM_CAUSE_INV_STATE);
208          RLOG0(L_ERROR, "Invalid CPJ SAP State in Bind Req");
209          ret = RFAILED;
210          break;
211       }
212    }
213
214    if (ret == ROK)
215    {
216       PjUiCpjBndCfm(&(cpjSap->pst), cpjSap->suId, CM_BND_OK);
217    }
218    else
219    {
220       PjUiCpjBndCfm(&(cpjSap->pst), cpjSap->suId, CM_BND_NOK);
221    }
222
223    RETVALUE(ROK);
224 } /* PjUiCpjBndReq */
225
226 \f
227 /**
228  *
229  * @brief 
230  *
231  *        Handler for unbinding the RLC upper layer service user CPJ with 
232  *        the RLC layer.
233  *
234  * @b Description:
235  *
236  *        1. This function is used by RLC user to request for unbinding  
237  *        with RLC. @n
238  *        2. This function is called by the CPJ interface to 
239  *        unbind with RLC. @n
240  *
241  *  @param[in] pst     Post structure  
242  *  @param[in] spId    Service provider SAP ID 
243  *  @param[in] reason  Reason for Unbinding 
244  *
245  *  @return  S16
246  *      -# ROK 
247  *
248  */
249 #ifdef ANSI
250 PUBLIC S16 PjUiCpjUbndReq
251 (
252 Pst      *pst,            
253 SpId     spId,           
254 Reason   reason           
255 )
256 #else
257 PUBLIC S16 PjUiCpjUbndReq(pst, spId, reason)
258 Pst      *pst;       
259 SpId     spId;      
260 Reason   reason;      
261 #endif
262 {
263    PjCpjSapCb  *cpjSap;            /* CPJ SAP control block */
264 #if (ERRCLASS & ERRCLS_INT_PAR)
265    S16         ret;                /* Return Value */
266 #endif
267    PjCb   *tPjCb;
268
269    TRC3(PjUiCpjUbndReq)
270
271    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)   /* KW_FIX */
272    {
273        RETVALUE(RFAILED);
274    }
275
276    tPjCb = PJ_GET_PJCB(pst->dstInst);
277    RLOG2(L_DEBUG, "PjUiCpjUbndReq(pst, spId(%d), reason(%d))", spId, reason);
278
279    UNUSED(pst);
280    UNUSED(reason);
281
282    /* disable upper sap (CPJ) */
283    cpjSap = &(tPjCb->u.ulCb->cpjSap);
284
285
286 #if (ERRCLASS & ERRCLS_INT_PAR)
287    ret    = ROK;
288    PJ_GET_AND_VALIDATE_CPJSAP(tPjCb,cpjSap, EPJXXX, "PjUiCPjUbndReq", ret);
289    if ( ret != ROK )
290    {
291       RETVALUE(RFAILED);
292    }
293 #endif /* ERRCLASS & ERRCLS_INT_PAR */
294
295    cpjSap->state = PJ_SAP_CFG;
296
297    RETVALUE(ROK);
298 } /* CpUiCpjUbndReq */
299
300
301 /**
302  *
303  * @brief 
304  *
305  *        Handler for configuring PDCP entities.
306  *
307  * @b Description:
308  *
309  *        This function is used by RRC to configure(add/delete/modify/
310  *        reestalish/delete all RB in a UE) one or more PDCP entities. 
311  *
312  *        - CPJ_CFG_ADD          => pjCfgAddRb
313  *        - CPJ_CFG_MODIFY       => pjCfgReCfgRb
314  *        - CPJ_CFG_DELETE       => pjCfgDelRb
315  *        - CPJ_CFG_REESTABLISH  => pjCfgReEstRb
316  *        - CPJ_CFG_DELETE_UE    => pjCfgDelUe
317  *
318  *  @param[in] pst   -  Post structure  
319  *  @param[in] spId  -  Serive Provider ID 
320  *  @param[in] cfg   -  Configuration information for one or more PDCP entities. 
321  *
322  *  @return  S16
323  *      -# ROK 
324  *
325  */
326 #ifdef ANSI
327 PUBLIC S16 PjUiCpjCfgReq
328 (
329 Pst             *pst,
330 SpId            spId,
331 CpjCfgReqInfo   *cfg
332 )
333 #else
334 PUBLIC S16 PjUiCpjCfgReq(pst, spId, cfg)
335 Pst            *pst;
336 SpId           spId;
337 CpjCfgReqInfo  *cfg;
338 #endif
339 {
340    PjCpjSapCb           *cpjSap;       /* CPJ SAP Control Block */
341    PjUdxUlSapCb         *udxSap;       /* UDX SAP Control Block */ 
342    S16                  ret;           /* Return Value */
343    PjCb                 *tPjCb;
344    PjCfgInfo            *cfgInfo;      /* added here n below */
345    UdxCfgReqInfo        *udxCfgReqInfo;       
346    
347
348    TRC3(PjUiCpjCfgReq)
349
350    ret       = ROK;
351
352    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)   /* KW_FIX */
353    {
354        RETVALUE(RFAILED);
355    }
356    tPjCb = PJ_GET_PJCB(pst->dstInst);
357 #ifndef ALIGN_64BIT
358    RLOG2(L_DEBUG, "PjUiPjuCfgReq(pst, spId(%d), TransId(%ld))", spId, cfg->transId);
359 #else
360    RLOG2(L_DEBUG, "PjUiPjuCfgReq(pst, spId(%d), TransId(%d))", spId, cfg->transId);
361 #endif
362
363    /* Get the cpjSap */
364    cpjSap = &(tPjCb->u.ulCb->cpjSap);
365
366    /* Validate SAP ID under ERRORCLS */
367    PJ_VALDATE_SAP(tPjCb, spId, cpjSap, ret);
368    if (ret != ROK)
369    {
370       /* pj002.201 Freeing from proper region */
371       PJ_PST_FREE(pst->region, pst->pool, cfg, sizeof(CpjCfgReqInfo));
372       RETVALUE(RFAILED);
373    }
374
375    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
376    PJ_ALLOC_BUF_SHRABL(udxSap->pst,udxCfgReqInfo,sizeof (UdxCfgReqInfo),ret);
377    if(ret != ROK)
378    {
379       RLOG0(L_FATAL, "Memory Allocation failed.");
380       PJ_PST_FREE(pst->region, pst->pool, cfg, sizeof(CpjCfgReqInfo));
381       RETVALUE(RFAILED);
382    }
383
384
385    PJ_MEM_CPY(udxCfgReqInfo,cfg,sizeof(UdxCfgReqInfo));
386    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
387
388    if (cfgInfo == NULLP)
389    {
390       RLOG0(L_FATAL, "Memory Allocation failed.");
391       PJ_PST_FREE(pst->region, pst->pool, cfg, sizeof(CpjCfgReqInfo));
392       PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, udxCfgReqInfo, sizeof(UdxCfgReqInfo));
393       RETVALUE(RFAILED);
394    }
395
396    cfgInfo->uprLyrTransId = cfg->transId;
397    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
398    udxCfgReqInfo->transId = cfgInfo->transId;
399    cfgInfo->cfgInfo  = cfg;
400  
401    ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo);
402    if (ret != ROK)
403    {
404       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
405       PJ_PST_FREE(pst->region, pst->pool, cfg, sizeof(CpjCfgReqInfo));
406       PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, udxCfgReqInfo, sizeof(UdxCfgReqInfo));
407       PJ_FREE(tPjCb, cfgInfo, sizeof (PjCfgInfo));
408
409       RETVALUE(RFAILED);
410    }
411
412    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
413    
414    PjUlUdxCfgReq(&(udxSap->pst), udxSap->spId,udxCfgReqInfo); 
415
416    RETVALUE(ret);
417 } /* PjUiPjuCfgReq */
418
419 /**
420  *@details This primitive is used by RRC to change the UeId for the existing UE
421            context.
422
423  * @param pst     -  Point to the pst structure
424  * @param spId    -  The ID of the service provider SAP in the PDCP layer 
425  * @param transId -  Transaction ID. This field uniquily identifies
426  *                   transaction between RRC and PDCP.
427  * @param ueInfo    -  Old UE Id Info for which the change request has come 
428  * @param newUeInfo -  New UE Id Info for existing UE context 
429  * @return ROK
430  */
431 #ifdef ANSI
432 PUBLIC S16 PjUiCpjUeIdChgReq
433 (
434 Pst        *pst, 
435 SpId       spId, 
436 U32        transId, 
437 CpjUeInfo  *ueInfo,
438 CpjUeInfo  *newUeInfo
439 )
440 #else
441 PUBLIC S16 PjUiCpjUeIdChgReq(pst,spId,transId,ueInfo,newUeInfo)
442 Pst        *pst;
443 SpId       spId;
444 U32        transId;
445 CpjUeInfo  *ueInfo;
446 CpjUeInfo  *newUeInfo;
447 #endif
448 {
449    S16         ret;           /* Return Value */
450    PjCpjSapCb  *cpjSap;       /* CPJ SAP Control Block */
451    PjUdxUlSapCb  *udxSap;     /* UDX SAP Control Block */ 
452    PjCfgInfo   *cfgInfo;      
453
454    UdxUeInfo  *udxUeInfo;        
455    UdxUeInfo  *udxNewUeInfo;
456    PjCb         *tPjCb;
457    
458    TRC3(PjUiCpjUeIdChgReq)
459
460    tPjCb = PJ_GET_PJCB(pst->dstInst);
461
462 #ifndef ALIGN_64BIT
463    RLOG2(L_DEBUG, "PjUiCpjUeIdChgReq(pst, spId(%d), transId(%ld))", spId, transId);
464 #else
465    RLOG2(L_DEBUG, "PjUiCpjUeIdChgReq(pst, spId(%d), transId(%d))", spId, transId);
466 #endif
467
468    ret = ROK;
469    cpjSap = &(tPjCb->u.ulCb->cpjSap);
470    
471    /* Validate SAP ID under ERRORCLS */
472    PJ_VALDATE_SAP(tPjCb, spId, cpjSap, ret);
473    if (ret != ROK)
474    {
475       /* kw002.201 Freeing from proper region */
476       PJ_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CpjUeInfo));
477       PJ_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CpjUeInfo));
478       RETVALUE(RFAILED);
479    }
480
481    /* Allocate memory for CkwUeInfo */
482    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
483    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxUeInfo, 
484                      sizeof (UdxUeInfo), ret);
485     if(ret != ROK)
486    {
487       RLOG0(L_FATAL, "Memory Allocation failed.");
488       /* Free memory for CkwUeInfo */
489       /* Freeing from proper region */
490       PJ_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CpjUeInfo));
491       PJ_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CpjUeInfo));
492       RETVALUE(RFAILED);
493    }
494    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxNewUeInfo, 
495       sizeof (UdxUeInfo), ret);
496    if(ret != ROK)
497    {
498       RLOG0(L_FATAL, "Memory Allocation failed.");
499       /* Free memory for CkwUeInfo */
500       /* Freeing from proper region */
501       PJ_FREE_SHRABL_BUF_PST(udxSap->pst.region,udxSap->pst.pool, udxUeInfo, sizeof(UdxUeInfo));
502       PJ_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CpjUeInfo));
503       PJ_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CpjUeInfo));
504       RETVALUE(RFAILED);
505    }
506
507    PJ_MEM_CPY(udxUeInfo,ueInfo, sizeof(UdxUeInfo)); 
508    PJ_MEM_CPY(udxNewUeInfo,newUeInfo, sizeof (UdxUeInfo));
509
510    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
511    if (cfgInfo == NULLP)
512    {
513       RLOG0(L_FATAL, "Memory Allocation failed.");
514       PJ_FREE_SHRABL_BUF_PST(udxSap->pst.region,udxSap->pst.pool, udxUeInfo, sizeof(UdxUeInfo));
515       PJ_FREE_SHRABL_BUF_PST(udxSap->pst.region,udxSap->pst.pool, udxNewUeInfo, sizeof(UdxUeInfo));
516       PJ_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CpjUeInfo));
517       PJ_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CpjUeInfo));
518       RETVALUE(RFAILED);
519    }
520
521    cfgInfo->uprLyrTransId = transId;
522    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
523    cfgInfo->ueInfo  = ueInfo;
524    cfgInfo->newUeInfo  = newUeInfo; 
525
526    if((ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo)) != ROK)
527    {
528       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
529       PJ_FREE_SHRABL_BUF_PST(udxSap->pst.region,udxSap->pst.pool, udxUeInfo, sizeof(UdxUeInfo));
530       PJ_FREE_SHRABL_BUF_PST(udxSap->pst.region,udxSap->pst.pool, udxNewUeInfo, sizeof(UdxUeInfo));
531       PJ_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CpjUeInfo));
532       PJ_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CpjUeInfo));
533       RETVALUE(RFAILED);
534    }
535
536    
537    PjUlUdxUeIdChgReq(&(udxSap->pst),udxSap->spId,cfgInfo->transId,
538                                          udxUeInfo,udxNewUeInfo);
539
540    RETVALUE(ROK);
541 } /* PjUiCpjUeIdChgReq */
542
543
544 /**
545  *@details  
546  * 1. RRC uses this primitive to configure PDCP security parameters.
547  * Integrity protection and/or Ciphering are configured by RRC based on the
548  * selSecAct flag.  @n
549  * 2. Integirty Protection/Ciphering are configured per UE and applicable
550  * to all pdcp entities in that UE. Both Integrity protection and ciphering are
551  * re-configured during re-establishment.  @n
552  *
553  * @param pst     -  Point to the pst structure
554  * @param spId    -  The ID of the service provider SAP in the PDCP layer 
555  * @param secCfg  -  Security Configuration Info per UE.
556  *
557  * @return 
558  *       -# ROK
559  *       -# RFAILED
560  */
561 #ifdef ANSI
562 PUBLIC S16 PjUiCpjSecCfgReq
563 (
564 Pst              *pst,
565 SpId             spId,
566 CpjSecCfgReqInfo *secCfg
567 )
568 #else
569 PUBLIC S16 PjUiCpjSecCfgReq(pst,spId,secCfg)
570 Pst              *pst;
571 SpId             spId;
572 CpjSecCfgReqInfo *secCfg;
573 #endif
574 {
575    S16               ret;           /* Return Value */
576    PjUdxUlSapCb      *udxSap;       /* UDX SAP Control Block */ 
577    PjCb   *tPjCb;
578    PjCfgInfo        *cfgInfo;      
579    UdxSecCfgReqInfo *udxSecCfgReqInfo;
580
581    TRC2(PjUiCpjSecCfgReq)
582
583    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)    /* KW_FIX */
584    {
585        RETVALUE(RFAILED);
586    }
587    tPjCb = PJ_GET_PJCB(pst->dstInst);
588
589 #ifndef ALIGN_64BIT 
590    RLOG2(L_DEBUG, "PjUiCpjSecCfgReq(pst, spId(%d), TransId(%ld))", spId,
591                secCfg->transId);
592 #else
593    RLOG2(L_DEBUG, "PjUiCpjSecCfgReq(pst, spId(%d), TransId(%d))", spId,
594                secCfg->transId);
595 #endif
596
597    ret = ROK;
598
599    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
600    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxSecCfgReqInfo,sizeof (UdxSecCfgReqInfo), ret);
601    if(ret != ROK)
602    {
603       RLOG0(L_FATAL, "Memory Allocation failed.");
604       RETVALUE(RFAILED);
605    }
606
607    PJ_MEM_CPY(udxSecCfgReqInfo,secCfg,sizeof(UdxSecCfgReqInfo));
608    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
609
610    if (cfgInfo == NULLP)
611    {
612       RLOG0(L_FATAL, "Memory Allocation failed.");
613       RETVALUE(RFAILED);
614    }
615    
616    cfgInfo->uprLyrTransId = secCfg->transId;
617    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
618    udxSecCfgReqInfo->transId = cfgInfo->transId;
619    cfgInfo->secCfgInfo  = secCfg;
620  
621    ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo);
622    if (ret != ROK)
623    {
624       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
625       RETVALUE(RFAILED);
626    }
627
628    PjUlUdxSecCfgReq(&(udxSap->pst), udxSap->spId,udxSecCfgReqInfo); 
629
630    RETVALUE(ret); 
631 }
632
633 /**
634  * @details
635  * 1. RRC uses this primitive to re-establish the PDCP entity. @n
636  * 2. This primitive is initiation of re-establishment procedure. @n
637  * 3. This prmitive and corresponding confirmation shall be followed by
638  *    PjUiCpjCfgReq procedure for entire re-establishment procedure to complete.
639  *
640  * @param[in] pst    - Pointer to post structure.
641  * @param[in] spId   - Service provider ID. This is the reference number used by
642  *                     PDCP to identify its SAP.
643  * @param[in] reEstReq - PDCP re-establishment request structure. 
644  *
645  */
646 #ifdef ANSI
647 PUBLIC S16 PjUiCpjReEstReq 
648 (
649 Pst             *pst, 
650 SpId            spId, 
651 CpjReEstReqInfo *reEstReq
652 )
653 #else 
654 PUBLIC S16 PjUiCpjReEstReq(pst,spId,reEstReq)
655 Pst             *pst;
656 SpId            spId;
657 CpjReEstReqInfo *reEstReq;
658 #endif
659 {
660    S16               ret;           /* Return Value */
661    PjCpjSapCb        *cpjSap;       /* CPJ SAP Control Block */
662    PjUdxUlSapCb      *udxSap;     /* UDX SAP Control Block */ 
663    PjCb   *tPjCb;
664    PjCfgInfo         *cfgInfo;      
665    UdxReEstReqInfo   *udxReEstReqInfo;
666    
667    TRC2(PjUiCpjReEstReq);
668
669    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)        /* KW_FIX */
670    {
671       PJ_PST_FREE(pst->region, pst->pool, reEstReq, sizeof(CpjReEstReqInfo));
672       RETVALUE(RFAILED);
673    }
674    tPjCb = PJ_GET_PJCB(pst->dstInst);
675    RLOG1(L_DEBUG, "PjUiCpjReEstReq(pst, spId(%d))", spId);
676
677    ret = ROK;
678    cpjSap = &(tPjCb->u.ulCb->cpjSap);
679
680    /* Validate SAP ID under ERRORCLS */
681    PJ_VALDATE_SAP(tPjCb, spId, cpjSap, ret);
682    if (ret != ROK)
683    {
684       /* pj002.201 Freeing from proper region */  
685       PJ_PST_FREE(pst->region, pst->pool, reEstReq, sizeof(CpjReEstReqInfo));
686       RETVALUE(RFAILED);
687    }
688
689    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
690    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxReEstReqInfo, 
691       sizeof (UdxReEstReqInfo), ret);
692    if(ret != ROK)
693    {
694       RLOG0(L_FATAL, "Memory Allocation failed.");
695       PJ_PST_FREE(pst->region, pst->pool, reEstReq, sizeof(CpjReEstReqInfo));
696       RETVALUE(RFAILED);
697    }
698
699    PJ_MEM_CPY(udxReEstReqInfo,reEstReq,sizeof(UdxReEstReqInfo));
700
701    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
702    if (cfgInfo == NULLP)
703    {
704       RLOG0(L_FATAL, "Memory Allocation failed.");
705       PJ_PST_FREE(pst->region, pst->pool, reEstReq, sizeof(CpjReEstReqInfo));
706       RETVALUE(RFAILED);
707    }
708
709    cfgInfo->uprLyrTransId = reEstReq->transId;
710    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
711    udxReEstReqInfo->transId = cfgInfo->transId;
712    cfgInfo->reEstReq  = reEstReq;
713  
714    ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo);
715    if (ret != ROK)
716    {
717       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
718       PJ_PST_FREE(pst->region, pst->pool, reEstReq, sizeof(CpjReEstReqInfo));
719       PJ_FREE(tPjCb, cfgInfo, sizeof (PjCfgInfo));
720       RETVALUE(RFAILED);
721    }
722
723    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
724    PjUlUdxReEstReq(&(udxSap->pst), udxSap->spId,udxReEstReqInfo); 
725
726    RETVALUE(ROK); 
727 }
728
729
730 /**
731  * @details
732  * 1. RRC uses this primitive to request count value for all DRBs in a UE. @n
733  * 2. PDCP sends the UL and DL count values in the confirmation of this request. 
734  *
735  * @param[in] pst    - Pointer to post structure.
736  * @param[in] spId   - Service provider ID. This is the reference number used
737  * by PDCP to identify its SAP.
738  * @param[in] countReq - PDCP Count Request Information. 
739  *
740  * @return ROK
741  */
742 #ifdef ANSI
743 PUBLIC S16 PjUiCpjCountReq 
744 (
745 Pst             *pst, 
746 SpId            spId, 
747 CpjCountReqInfo *countReq
748 )
749 #else
750 PUBLIC S16 PjUiCpjCountReq(pst,spId,countReq)
751 Pst             *pst;
752 SpId            spId;
753 CpjCountReqInfo *countReq;
754 #endif
755 {
756    S16               ret;           /* Return Value */
757    PjUdxUlSapCb      *udxSap;       /* UDX SAP Control Block */ 
758    PjCb   *tPjCb;
759    PjCfgInfo       *cfgInfo;     
760    UdxCountReqInfo *udxCountReqInfo;  
761
762    TRC2(PjUiCpjCountReq);
763
764    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)    /* KW_FIX */
765    {
766       PJ_PST_FREE(pst->region, pst->pool, countReq, sizeof(CpjCountReqInfo));
767       RETVALUE(RFAILED);
768    }
769   
770
771    tPjCb = PJ_GET_PJCB(pst->dstInst);
772    RLOG1(L_DEBUG, "PjUiCpjCountReq(pst, spId(%d))", spId);
773
774    ret = ROK;
775   
776    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
777    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxCountReqInfo, sizeof (UdxCountReqInfo), ret);
778    if(ret != ROK)
779    {
780       RLOG0(L_FATAL, "Memory Allocation failed.");
781       RETVALUE(RFAILED);
782    }
783
784    PJ_MEM_CPY(udxCountReqInfo,countReq,sizeof(UdxCountReqInfo));
785    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
786
787    if (cfgInfo == NULLP)
788    {
789       RLOG0(L_FATAL, "Memory Allocation failed.");
790       PJ_PST_FREE(pst->region, pst->pool, countReq, sizeof(CpjCountReqInfo));
791       RETVALUE(RFAILED);
792    }
793
794    cfgInfo->uprLyrTransId = countReq->transId;
795    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
796    udxCountReqInfo->transId = cfgInfo->transId;
797    cfgInfo->cntReq  = countReq;
798  
799    ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo);
800    if (ret != ROK)
801    {
802       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
803       PJ_PST_FREE(udxSap->pst.region, udxSap->pst.pool, udxCountReqInfo, sizeof(UdxCountReqInfo));
804       PJ_PST_FREE(pst->region, pst->pool, countReq, sizeof(CpjCountReqInfo));
805       PJ_FREE(tPjCb, cfgInfo, sizeof (PjCfgInfo));
806       RETVALUE(RFAILED);
807    }
808
809    
810    PjUlUdxCountReq(&(udxSap->pst), udxSap->spId,udxCountReqInfo); 
811
812    RETVALUE(ROK);
813 }
814
815 /**
816  * 
817  * @details
818  * 1. RRC uses this primitive to request the status of the SDUs for DRBs in an UE. @n
819  * 2. Its used as a reestablishment request during handover.  @n
820  * 3. This primitive is used to forward the handover control Information to the target
821  * eNodeB.
822  *
823  * @param[in] pst    - Pointer to post structure.
824  * @param[in] spId   - Service provider ID. This is the reference number used
825  * by PDCP to identify its SAP.
826  * @param[in] sduStaReq - PDCP SDU Status Request Information. 
827  *
828  * @return ROK
829  */
830 #ifdef ANSI
831 PUBLIC S16 PjUiCpjSduStaReq 
832 (
833 Pst              *pst, 
834 SpId             spId, 
835 CpjSduStaReqInfo *staReq
836 )
837 #else
838 PUBLIC S16 PjUiCpjSduStaReq(pst,spId,staReq)
839 Pst              *pst;
840 SpId             spId;
841 CpjSduStaReqInfo *staReq;
842 #endif
843 {
844
845    S16               ret;           /* Return Value */
846    PjCpjSapCb        *cpjSap;       /* CPJ SAP Control Block */
847    PjUlUeCb          *ueCb;
848    PjUdxUlSapCb      *udxSap;       /* UDX SAP Control Block */ 
849    PjCb              *tPjCb;
850    PjCfgInfo         *cfgInfo;      /* added here n below */
851    UdxSduStaReqInfo  *udxSduStaReq;
852
853    TRC2(PjUiCpjSduStaReq);
854
855    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)       /* KW_FIX */
856    {
857       PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));    
858       RETVALUE(RFAILED);
859    }
860
861    tPjCb = PJ_GET_PJCB(pst->dstInst);
862
863    RLOG1(L_DEBUG, "PjUiCpjSduStaReq(pst, spId(%d))", spId);
864
865    ret = ROK;
866    cpjSap = NULLP;
867
868    cpjSap = &(tPjCb->u.ulCb->cpjSap);
869
870    /* Validate SAP ID under ERRORCLS */
871    PJ_VALDATE_SAP(tPjCb, spId, cpjSap, ret);
872    if (ret != ROK)
873    {
874       /* kw002.201 Freeing from proper region */
875       PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));
876       RETVALUE(RFAILED);
877    }
878
879    ret = pjDbmFetchUlUeCb(tPjCb, staReq->ueId, staReq->cellId, &ueCb);
880    /* UeCb is not present */
881    if( ROK != ret || NULLP == ueCb)
882    { 
883       RLOG_ARG1(L_ERROR, DBG_CELLID, staReq->cellId,"UL UeId[%u] not found",
884             staReq->ueId);
885       CpjSduStaCfmInfo  *cfmInfo;
886       /* Memory leak fix ccpu00135359 */
887       cpjSap = &tPjCb->u.ulCb->cpjSap;
888       if(SGetSBuf(cpjSap->pst.region,cpjSap->pst.pool,(Data **)&cfmInfo, 
889          sizeof (CpjSduStaCfmInfo)) != ROK)
890       {
891          RLOG0(L_FATAL, "Memory Allocation failed.");
892          PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));
893          RETVALUE(RFAILED);
894       }
895       cfmInfo->ueId = staReq->ueId;
896       cfmInfo->cellId = staReq->cellId;
897       cfmInfo->transId = staReq->transId;
898       cfmInfo->status = CPJ_CFG_CFM_NOK; 
899       cfmInfo->reason = CPJ_CFG_REAS_UE_UNKWN;
900
901       /* Caller should return cfm with failure */
902       RLOG_ARG1(L_DEBUG,DBG_UEID,staReq->ueId, "Prc Sdu Sta Req - UE Cb is not"
903             " found in cellId(%d)", staReq->cellId);
904
905       /* Send Failure SduStaCfm */
906       PjUiCpjSduStaCfm(&tPjCb->u.ulCb->cpjSap.pst, 
907                         tPjCb->u.ulCb->cpjSap.suId, cfmInfo);
908
909       PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));
910
911       RETVALUE(RFAILED);
912    }
913  
914    /* Updating UE state to REEST during HO */
915    ueCb->libInfo.numReEstDrb = 0;
916    ueCb->libInfo.state = PJ_STATE_REEST_HO;
917
918    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
919    ret = ROK;
920    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxSduStaReq, 
921       sizeof (UdxSduStaReqInfo), ret);
922    if(ret != ROK)
923    {
924       RLOG0(L_FATAL, "Memory Allocation failed.");
925       PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));
926       RETVALUE(RFAILED);
927    }
928
929    PJ_MEM_CPY(udxSduStaReq,staReq,sizeof(UdxSduStaReqInfo));
930
931    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
932    if (cfgInfo == NULLP)
933    {
934       RLOG0(L_FATAL, "Memory Allocation failed.");
935       PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));
936       PJ_PST_FREE(pst->region, pst->pool, udxSduStaReq, sizeof(UdxSduStaReqInfo));
937       RETVALUE(RFAILED);
938    }
939
940    cfgInfo->uprLyrTransId = staReq->transId;
941    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
942    udxSduStaReq->transId = cfgInfo->transId;
943    cfgInfo->staReq  = staReq;
944  
945    ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo);
946    if (ret != ROK)
947    {
948       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
949       PJ_PST_FREE(pst->region, pst->pool, staReq, sizeof(CpjSduStaReqInfo));
950       PJ_PST_FREE(udxSap->pst.region, udxSap->pst.pool, udxSduStaReq, sizeof(UdxSduStaReqInfo));
951       PJ_FREE(tPjCb, cfgInfo, sizeof(PjCfgInfo));
952
953       RETVALUE(RFAILED);
954    }
955
956    
957    PjUlUdxSduStaReq(&(udxSap->pst), udxSap->spId,udxSduStaReq); 
958
959    RETVALUE(ret);
960 }
961
962
963 /**
964  * 
965  * @details
966  * 1. RRC uses this primitive to resume data during Re-establishment and
967  * handover  
968  *
969  * @param[in] pst    - Pointer to post structure.
970  * @param[in] spId   - Service provider ID. This is the reference number used
971  * by PDCP to identify its SAP.
972  * @param[in] sduStaReq - PDCP SDU Status Request Information. 
973  *
974  * @return ROK
975  */
976 #ifdef ANSI
977 PUBLIC S16 PjUiCpjDatResumeReq 
978 (
979 Pst                   *pst, 
980 SpId                  spId, 
981 CpjDatResumeReqInfo   *datResReq
982 )
983 #else
984 PUBLIC S16 PjUiCpjDatResumeReq(pst,spId, *dataResReq)
985 Pst                   *pst;
986 SpId                  spId;
987 CpjDatResumeReqInfo   *datResReq;
988 #endif
989 {
990
991    S16               ret;           /* Return Value */
992    PjCpjSapCb        *cpjSap;       /* CPJ SAP Control Block */
993    PjUdxUlSapCb      *udxSap;       /* UDX SAP Control Block */ 
994    PjUlUeCb          *ueCb;
995    PjCfgInfo         *cfgInfo;      
996    PjCb              *tPjCb;
997    UdxDatResumeInfo  *udxDatResumeInfo;
998    TRC2(PjUiCpjDatResumeReq);
999
1000    tPjCb = PJ_GET_PJCB(pst->dstInst);
1001
1002    RLOG1(L_DEBUG, "PjUiCpjDatResumeReq(pst, spId(%d))", spId);
1003
1004    ret = ROK;
1005    cpjSap = NULLP;
1006
1007    cpjSap = &(tPjCb->u.ulCb->cpjSap);
1008
1009    /* Validate SAP ID under ERRORCLS */
1010    PJ_VALDATE_SAP(tPjCb, spId, cpjSap, ret);
1011    if (ret != ROK)
1012    {
1013       RETVALUE(RFAILED);
1014    }
1015    ret = pjDbmFetchUlUeCb(tPjCb, datResReq->ueId,
1016                                  datResReq->cellId, &ueCb);
1017    if (ret != ROK)
1018    {
1019       RLOG_ARG1(L_ERROR, DBG_CELLID, datResReq->cellId,"UL UeId[%u] not found",
1020             datResReq->ueId);
1021       PJ_PST_FREE(pst->region, pst->pool, datResReq, sizeof(CpjDatResumeReqInfo));
1022       RETVALUE(RFAILED);
1023    }
1024
1025     /* Memory leak fix ccpu00135359 */
1026    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
1027    ret = ROK;
1028    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxDatResumeInfo, 
1029       sizeof (UdxDatResumeInfo), ret);
1030    if(ret != ROK)
1031    {
1032       RLOG0(L_FATAL, "Memory Allocation failed.");
1033       PJ_PST_FREE(pst->region, pst->pool, datResReq, sizeof(CpjDatResumeReqInfo));
1034       RETVALUE(RFAILED);
1035    }
1036
1037    PJ_ALLOC(tPjCb, cfgInfo, sizeof (PjCfgInfo));
1038    if (cfgInfo == NULLP)
1039    {
1040       RLOG0(L_FATAL, "Memory Allocation failed.");
1041       PJ_PST_FREE(pst->region, pst->pool, datResReq, sizeof(CpjDatResumeReqInfo));
1042       PJ_PST_FREE(udxSap->pst.region, udxSap->pst.pool, udxDatResumeInfo, sizeof(UdxDatResumeInfo));
1043       RETVALUE(RFAILED);
1044    }
1045
1046    cfgInfo->uprLyrTransId = datResReq->transId;
1047    cfgInfo->transId = ++tPjCb->u.ulCb->transId; 
1048    udxDatResumeInfo->transId = cfgInfo->transId;
1049    cfgInfo->datResReq  = datResReq;
1050    udxDatResumeInfo->ueId = datResReq->ueId;
1051    udxDatResumeInfo->cellId = datResReq->cellId;
1052  
1053    ret = pjDbmAddUlTransIdLst(tPjCb, cfgInfo);
1054    if (ret != ROK)
1055    {
1056       RLOG0(L_ERROR, "Addition to UL transId List Failed.");
1057       PJ_PST_FREE(pst->region, pst->pool, datResReq, sizeof(CpjDatResumeReqInfo));
1058       PJ_FREE(tPjCb, cfgInfo, sizeof(PjCfgInfo));
1059       PJ_PST_FREE(udxSap->pst.region, udxSap->pst.pool, udxDatResumeInfo, sizeof(UdxDatResumeInfo));
1060
1061       RETVALUE(RFAILED);
1062    }
1063    
1064    PjUlUdxDatResumeReq(&(udxSap->pst), udxDatResumeInfo); 
1065
1066    RETVALUE(ret);
1067 }
1068
1069 /**
1070  * 
1071  * @details
1072  * 1. RRC uses this primitive to start data forwarding during
1073  * handover  
1074  *
1075  * @param[in] pst    - Pointer to post structure.
1076  * @param[in] spId   - Service provider ID. This is the reference number used
1077  * by PDCP to identify its SAP.
1078  * @param[in] sduStaReq - PDCP SDU Status Request Information. 
1079  *
1080  * @return ROK
1081  */
1082 #ifdef ANSI
1083 PUBLIC S16 PjUiCpjDatForwardReq 
1084 (
1085 Pst                 *pst, 
1086 SpId                spId, 
1087 CpjDataFwdReqInfo   *dataFwdReq
1088 )
1089 #else
1090 PUBLIC S16 PjUiCpjDatForwardReq(pst,spId, *dataFwdReq)
1091 Pst                 *pst;
1092 SpId                spId;
1093 CpjDataFwdReqInfo   *dataFwdReq;
1094 #endif
1095 {
1096
1097    S16               ret;           /* Return Value */
1098    PjCpjSapCb        *cpjSap;       /* CPJ SAP Control Block */
1099    PjUdxUlSapCb      *udxSap;       /* UDX SAP Control Block */ 
1100    PjUlUeCb          *ueCb;
1101    CmLteRnti     ueId;                   /*!< UE ID */
1102    CmLteCellId   cellId;                 /*!< Cell ID */
1103    UdxDatForwardInfo  *udxDatForwardInfo;
1104
1105    PjCb              *tPjCb;
1106    TRC2(PjUiCpjDatForwardReq);
1107
1108    tPjCb = PJ_GET_PJCB(pst->dstInst);
1109
1110    RLOG1(L_DEBUG, "PjUiCpjDatForwardReq(pst, spId(%d))", spId);
1111
1112    ret = ROK;
1113    cpjSap = NULLP;
1114
1115    ueId = dataFwdReq->ueId;
1116    cellId = dataFwdReq->cellId;
1117    cpjSap = &(tPjCb->u.ulCb->cpjSap);
1118
1119    /* Validate SAP ID under ERRORCLS */
1120    PJ_VALDATE_SAP(tPjCb, spId, cpjSap, ret);
1121    if (ret != ROK)
1122    {
1123       PJ_PST_FREE(pst->region, pst->pool, dataFwdReq, sizeof(CpjDataFwdReqInfo));
1124       RETVALUE(RFAILED);
1125    }
1126
1127    ret = pjDbmFetchUlUeCb(tPjCb, ueId, cellId, &ueCb);
1128    if (ret != ROK)
1129    {
1130       RLOG_ARG1(L_ERROR, DBG_CELLID, cellId,"UL UeId[%u] not found",ueId);
1131       PJ_PST_FREE(pst->region, pst->pool, dataFwdReq, sizeof(CpjDataFwdReqInfo));
1132       RETVALUE(RFAILED);
1133    }
1134    /* Store the UL Data Forwarding Req or not in ueCb */
1135    ueCb->isUlDatFwdReqd = dataFwdReq->isUlDatFwdReq;
1136   
1137    ret = ROK;
1138    /* Memory leak fix ccpu00135359 */
1139    udxSap = PJ_GET_UL_UDX_SAP(tPjCb);
1140    PJ_ALLOC_BUF_SHRABL(udxSap->pst, udxDatForwardInfo, 
1141       sizeof (UdxDatForwardInfo), ret);
1142    if(ret != ROK)
1143    {
1144       RLOG0(L_FATAL, "Memory Allocation failed.");
1145       PJ_PST_FREE(pst->region, pst->pool, dataFwdReq, sizeof(CpjDataFwdReqInfo));
1146       RETVALUE(RFAILED);
1147    }
1148
1149    /* TODO :- Need to add code for handling request */
1150
1151    /* Forwarding request to DL over UDX interface */
1152    udxDatForwardInfo->ueId = ueId;
1153    udxDatForwardInfo->cellId = cellId;
1154    udxDatForwardInfo->transId = dataFwdReq->transId;
1155   
1156    PJ_PST_FREE(pst->region, pst->pool, dataFwdReq, sizeof(CpjDataFwdReqInfo)); 
1157    if(ueCb->isUlDatFwdReqd == TRUE)
1158    {
1159       /* Snd ULFwd - TRUE to DL 
1160        * So that DL will not send isLastDatInd Flag to DAM */
1161       udxDatForwardInfo->ulFwding = TRUE;
1162    }
1163    PjUlUdxDatForwardReq(&(udxSap->pst), udxDatForwardInfo); 
1164
1165    RETVALUE(ret);
1166 }
1167
1168 \f
1169 /*****************************************************************************
1170  *                          PJU INTERFACE
1171  ****************************************************************************/
1172 /**
1173  *
1174  * @brief 
1175  *
1176  *        Handler for binding the PDCP upper layer service user with 
1177  *        the PDCP layer.
1178  *
1179  * @b Description:
1180  *
1181  *        1. This function is used by PDCP user to request for binding to 
1182  *        PDCP. @n
1183  *        2. This function is called by the PJU interface to bind 
1184  *        PDCP's SAP (identified by spId) with the service user's
1185  *        SAP (identified by suId). 
1186  *
1187  *  @param[in] pst   Post structure  
1188  *  @param[in] suId  Service user SAP ID 
1189  *  @param[in] spId  Service provider ID
1190  *
1191  *  @return  S16
1192  *      -# ROK 
1193  *      -# RFAILED
1194  */
1195 #ifdef ANSI
1196 PUBLIC S16 PjUiPjuBndReq 
1197 (
1198 Pst       *pst,    
1199 SuId      suId,   
1200 SpId      spId     
1201 )
1202 #else
1203 PUBLIC S16 PjUiPjuBndReq (pst, suId, spId)
1204 Pst       *pst;    
1205 SuId      suId;    
1206 SpId      spId;    
1207 #endif
1208 {
1209    S16            ret;           /* Return Value */
1210    PjPjuSapCb     *pjuSap;       /* SAP Config Block */
1211    PjCb   *tPjCb;
1212    
1213    TRC3(PjUiPjuBndReq)
1214
1215    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)  /* KW_FIX */
1216    {
1217       RETVALUE(RFAILED);
1218    }
1219
1220    tPjCb = PJ_GET_PJCB(pst->dstInst);
1221    RLOG2(L_DEBUG, "PjUiPjuBndReq(pst, spId(%d), suId(%d))", spId, suId);
1222
1223    ret = ROK;
1224    pjuSap = NULLP;
1225
1226    /* Validation of input parameters */
1227 #if (ERRCLASS & ERRCLS_INT_PAR)
1228    if(!((spId < (S16) tPjCb->pjGenCfg.maxPjuSaps) && (spId >=0))) 
1229    {
1230       if(pjuSap != NULLP) 
1231       {
1232          RLOG0(L_ERROR, "Invalid PJU SAP State in Bind Req");
1233          PJ_SEND_SAPID_ALARM(tPjCb,spId, LPJ_EVENT_PJU_BND_REQ, LCM_CAUSE_INV_SAP);
1234          RETVALUE(RFAILED); 
1235       }
1236    }
1237 #endif
1238
1239    /* Get Sap control block */
1240    if (tPjCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1241    {
1242       pjuSap = (PjPjuSapCb*)(tPjCb->u.ulCb->pjuSap + spId);
1243    }
1244    else
1245    {
1246       pjuSap = (PjPjuSapCb*)(tPjCb->u.dlCb->pjuSap + spId);
1247    }
1248
1249    /* Verify PJU SAP State */
1250    switch(pjuSap->state)
1251    {
1252       /* SAP is configured but not bound */
1253       case PJ_SAP_CFG:
1254       case PJ_SAP_UBND:
1255       {
1256          /* copy bind configuration parameters in SSAP sap */
1257          pjuSap->suId          = suId;
1258          pjuSap->pst.dstProcId = pst->srcProcId;
1259          pjuSap->pst.dstEnt    = pst->srcEnt;
1260          pjuSap->pst.dstInst   = pst->srcInst;
1261
1262          /* Update the State */
1263          pjuSap->state = PJ_SAP_BND;
1264
1265          /* DEBUG_PRINT */
1266          RLOG1(L_DEBUG, "PjUiPjuBndReq: state (%d)", pjuSap->state);
1267          break;
1268       }
1269
1270       /* SAP is already bound */
1271       case PJ_SAP_BND:
1272       {
1273          /* 
1274           * Sap is already bound check source, destination Entity and 
1275           * Proc Id
1276           */
1277          if (pjuSap->pst.dstProcId != pst->srcProcId 
1278                || pjuSap->pst.dstEnt != pst->srcEnt
1279                || pjuSap->pst.dstInst != pst->srcInst
1280                || pjuSap->suId != suId)
1281          {
1282             RLOG4(L_DEBUG, "Ui Pju Bnd Req suId(%d)<>suId(%d),"
1283                   "pst->srcProcId(%d)<>pjuSap->pst.dstProcId(%d)",
1284                   suId, pjuSap->suId, pst->srcProcId, pjuSap->pst.dstProcId);
1285
1286             RLOG4(L_DEBUG,"Ui Pju Bnd Req pst->srcEnt(%d)<>pjuSap->pst.dstEnt"
1287                   "(%d),pst->srcInst(%d)<>pjuSap->pst.dstInst(%d))",
1288               pst->srcEnt,pjuSap->pst.dstEnt,pst->srcInst,pjuSap->pst.dstInst);
1289
1290             PJ_SEND_SAPID_ALARM(tPjCb, spId, LPJ_EVENT_PJU_BND_REQ, LCM_CAUSE_INV_PAR_VAL);
1291             ret = RFAILED;
1292          }
1293          break;
1294       }
1295
1296      default:
1297       {
1298          /* LOG ERROR */
1299          RLOG0(L_ERROR, "Invalid PJU SAP State in Bind Req");
1300          PJ_SEND_SAPID_ALARM(tPjCb,spId, LPJ_EVENT_PJU_BND_REQ, LCM_CAUSE_INV_STATE);
1301          ret = RFAILED;
1302          break;
1303       }
1304    }
1305
1306    if (ret == ROK)
1307    {
1308       PjUiPjuBndCfm(&(pjuSap->pst), pjuSap->suId, CM_BND_OK);
1309    }
1310    else
1311    {
1312       PjUiPjuBndCfm(&(pjuSap->pst), pjuSap->suId, CM_BND_NOK);
1313    }
1314
1315    RETVALUE(ROK);
1316
1317 } /* PjUiPjuBndReq */
1318
1319 \f
1320 /**
1321  *
1322  * @brief 
1323  *
1324  *        Handler for unbinding the PDCP upper layer service user with 
1325  *        the PDCP layer.
1326  *
1327  * @b Description:
1328  *
1329  *        1. This function is used by PDCP user to request for unbinding  
1330  *        with PDCP. @n
1331  *        2. This function is called by the PJU interface to 
1332  *        unbind with PDCP. 
1333  *
1334  *  @param[in] pst     Post structure  
1335  *  @param[in] suId    Service user SAP ID 
1336  *  @param[in] reason  Reason for Unbinding 
1337  *
1338  *  @return  S16
1339  *      -# ROK 
1340  *      -# RFAILED
1341  *
1342  */
1343 #ifdef ANSI
1344 PUBLIC S16 PjUiPjuUbndReq
1345 (
1346 Pst      *pst,   
1347 SpId     spId,    
1348 Reason   reason     
1349 )
1350 #else
1351 PUBLIC S16 PjUiPjuUbndReq(pst, spId, reason)
1352 Pst      *pst;       
1353 SpId     spId;     
1354 Reason   reason;      
1355 #endif
1356 {
1357    PjPjuSapCb  *pjuSap;            /* PJU SAP control block */
1358 #if (ERRCLASS & ERRCLS_INT_PAR)
1359    S16         ret; 
1360 #endif
1361    PjCb   *tPjCb;
1362
1363    TRC3(PjUiPjuUbndReq)
1364
1365    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)      /* KW_FIX */
1366    {
1367       RETVALUE(RFAILED);
1368    }
1369
1370    tPjCb = PJ_GET_PJCB(pst->dstInst);
1371    /* DEBUG_PRINT */
1372    RLOG2(L_DEBUG, "PjUiPjuUbndReq(pst, spId(%d), reason(%d))", spId, reason);
1373
1374    pjuSap = NULLP;
1375
1376    UNUSED(pst);
1377    UNUSED(reason);
1378
1379    /* Get Sap control block */
1380    if (tPjCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
1381    {
1382       pjuSap = (PjPjuSapCb*)(tPjCb->u.ulCb->pjuSap + spId);
1383    }
1384    else
1385    {
1386       pjuSap = (PjPjuSapCb*)(tPjCb->u.dlCb->pjuSap + spId);
1387    }
1388
1389
1390 #if (ERRCLASS & ERRCLS_INT_PAR)
1391    PJ_GET_AND_VALIDATE_PJUSAP(tPjCb, pjuSap, EPJXXX, "PjUiPjuUbndReq", ret);
1392    if (ret != ROK )
1393    {
1394       RETVALUE(RFAILED);
1395    }
1396 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1397
1398    pjuSap->state = PJ_SAP_CFG;
1399
1400    RETVALUE(ROK);
1401 } /* PjUiPjuUbndReq */
1402
1403 /**
1404  * @details
1405  * This primitive is used by the PDCP service user to request PDCP
1406  * for data transfer.
1407  *
1408  * @param[in] pst    - Pointer to Pst structure.
1409  * @param[in] spId  - Service provider ID. This is the reference number
1410  * used by PDCP service user (Relay) to identify its SAP. This reference number
1411  * will be provided by PDCP in any further primitives sent by PDCP
1412  * to the service user.
1413  * @param[in] pdcpId - Pointer to CmLtePdcpId structure, PDCP id is used to 
1414  * uniquely identify an PDCP entity. 
1415  * @param[in] sduId  - SDU ID. 
1416  * @param[in] mBuf   - Pointer to data buffer.
1417  *
1418  * @return ROK
1419  */
1420 #ifdef ANSI
1421 PUBLIC S16 PjUiPjuDatReq
1422 (
1423 Pst            *pst,            
1424 SpId           spId,               
1425 CmLtePdcpId    *pdcpId,         
1426 PjuSduId       sduId,           
1427 Buffer         *mBuf          
1428 )
1429 #else
1430 PUBLIC S16 PjUiPjuDatReq(pst, spId, pdcpId, sduId, mBuf)
1431 Pst             *pst;       
1432 SpId            spId;           
1433 CmLtePdcpId     *pdcpId;     
1434 PjuSduId         sduId;   
1435 Buffer          *mBuf;          
1436 #endif
1437 {
1438 #ifndef NO_ERRCLS
1439    S16         ret;           /* Return Value */
1440 #endif
1441    PjDlRbCb   *pjRbCb;       /* RB Control Block */
1442    PjDlUeCb   *ueCb;         /* UE Control Block */
1443 #ifndef CCPU_OPT
1444    MsgLen      len;           /* Size of the SDU */
1445 #endif
1446 #ifndef NO_ERRCLS
1447    PjPjuSapCb  *pjuSap;       /* SAP Config Block */
1448 #endif
1449    PjCb   *tPjCb;
1450    U32   count;         /* count for the PDU */
1451 #ifndef CCPU_OPT
1452    PjuDatCfmInfo *datCfm;
1453    CmLtePdcpId *tPdcpId;
1454    PjPjuSapCb  *tPjuSap;
1455 #endif /*CCPU_OPT */
1456    TRC3(PjUiPjuDatReq)
1457
1458 #ifdef CA_PHY_BRDCM_61765 
1459    EXTERN U32 dlrate_pju1;
1460    MsgLen len;
1461    SFndLenMsg(mBuf, (MsgLen *) &len);
1462    dlrate_pju1 += len;
1463 #endif
1464
1465    if ((pst->dstInst >= PJ_MAX_PDCP_INSTANCES) || (mBuf == NULLP))      /* KW_FIX */
1466    {
1467       PJ_PST_FREE(pst->region, pst->pool, pdcpId, sizeof(CmLtePdcpId));
1468       PJ_FREE_BUF(mBuf);
1469       RETVALUE(RFAILED);
1470    }
1471
1472    tPjCb = PJ_GET_PJCB(pst->dstInst);
1473
1474 #ifndef NO_ERRCLS
1475    pjuSap = NULLP;
1476 #endif
1477
1478 #ifndef NO_ERRCLS
1479    ret = ROK;
1480    pjuSap = (PjPjuSapCb*)(tPjCb->u.dlCb->pjuSap + spId);
1481    /* Validate SAP ID under ERRORCLS */
1482    PJ_VALDATE_SAP(tPjCb, spId, pjuSap, ret);
1483    if (ret != ROK)
1484    {
1485       PJ_FREE_BUF(mBuf);
1486       RETVALUE(RFAILED);
1487    }
1488 #endif
1489    /* Fetch the RbCb */
1490    if (pjDbmFetchDlUeCb(tPjCb, pdcpId->ueId, pdcpId->cellId, &ueCb) != ROK)
1491    {
1492       RLOG_ARG1(L_ERROR, DBG_CELLID, pdcpId->cellId,"DL UeId[%u] not found",
1493             pdcpId->ueId);
1494       PJ_FREE_BUF(mBuf);
1495       RETVALUE(RFAILED);
1496    }
1497    /* Fetch the RbCb */
1498    
1499    PJ_DBM_FETCH_DL_RBCB(pdcpId->rbId, pdcpId->rbType, ueCb,pjRbCb);
1500    if (pjRbCb == NULLP)
1501    {     
1502       RLOG_ARG2(L_ERROR, DBG_UEID,pdcpId->ueId, "CellId[%u]: DL RbId[%d] not found",
1503             pdcpId->cellId, pdcpId->rbId);
1504       PJ_FREE_BUF(mBuf);
1505       RETVALUE(RFAILED);
1506    }
1507
1508    /* Update the total packets received for L2 Measurements */
1509    PJ_UPD_L2_DLDISC_PKT_STS(tPjCb,pjRbCb);
1510    
1511 #ifdef PTPJLIB 
1512    /* kw003.201 Control for packet administration */
1513    if (pjLibPktAdmCtrl(pjRbCb, mBuf) != ROK)
1514    {
1515       RLOG_ARG2(L_DEBUG,DBG_UEID,pdcpId->ueId, "Pju Dat Req: PDCP pkt dropped for"
1516            " cellId(%d),rbId(%d)", pdcpId->cellId, pdcpId->rbId);
1517       PJ_FREE_BUF(mBuf);
1518       gPdcpStats.numPdcpSdusDiscarded++;
1519       PJ_UPD_L2_DLDISC_STS(tPjCb, pjRbCb);
1520       {
1521 #ifdef CA_PHY_BRDCM_61765
1522          EXTERN U32 gDbgPdcpDropCnt;
1523          gDbgPdcpDropCnt++;
1524 #endif
1525       }
1526       RETVALUE(RFAILED);
1527    }
1528 #endif
1529 #ifndef CCPU_OPT
1530    SFndLenMsg(mBuf, &len);
1531    if ( len > PJ_MAX_SDU_SIZE )
1532    {
1533 #if (ERRCLASS & ERRCLS_INT_PAR)
1534       RLOG_ARG2(L_ERROR, DBG_RBID, pjRbCb->rbId , "Processing DL Sdu failed, PDU size [%lu] > MAX_LEN [%lu]",
1535          len, PJ_MAX_SDU_SIZE);
1536 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1537
1538       if ( pjRbCb->dlCb.cfmReqd)
1539       {
1540          if (pjRbCb->rbType == PJ_SRB)
1541             tPjuSap   = (PjPjuSapCb*)(tPjCb->pjuSap + PJ_SRB_SAP);
1542          else
1543             tPjuSap   = (PjPjuSapCb*)(tPjCb->pjuSap + PJ_DRB_SAP);
1544
1545     datCfm = &datCfmTmp;
1546     tpdcpId = &tpdcpIdTmp;
1547
1548          datCfm->cfmSta[datCfm->numSdus].sduId = sduId;
1549          datCfm->cfmSta[datCfm->numSdus].status = PJU_MAX_SDU_SIZ_EXCEED;
1550          datCfm->numSdus++;
1551          tPdcpId->rbId   = pjRbCb->rbId;
1552          tPdcpId->rbType = pjRbCb->rbType;
1553          tPdcpId->ueId   = pjRbCb->ueCb->key.ueId;
1554          tPdcpId->cellId = pjRbCb->ueCb->key.cellId;
1555          PjUiPjuDatCfm(&(tPjuSap->pst), tPjuSap->suId, tPdcpId, datCfm);
1556       }
1557
1558       tPjCb->pjGenSts.numCmpFails++;
1559
1560       PJ_FREE_BUF(mBuf);
1561       RETVALUE(RFAILED);
1562    }   
1563 #endif
1564
1565    if((pjRbCb->state != PJ_STATE_NORMAL) && (pjRbCb->rbType != PJ_SRB))
1566    {
1567 #ifdef PRE_DEF_UE_CTX_HO      
1568       pjRbCb->state = PJ_STATE_NORMAL;
1569 #endif       
1570       if(pjRbCb->dlCb.dlPktQ.count < 500)
1571       {
1572 /*         MSPD_DBG(" Queuing the Packets in Reestablish/Ho state ");*/
1573          pjDlmEnqueueDlPkt(tPjCb, pjRbCb, PJ_DATA_NRM_PKT, NULL, sduId, mBuf); 
1574          RETVALUE(ROK);
1575       }
1576       else
1577       {
1578          PJ_FREE_BUF(mBuf);
1579          gPdcpStats.numPdcpSdusDiscarded++;
1580          PJ_UPD_L2_DLDISC_STS(tPjCb, pjRbCb);
1581          RETVALUE(RFAILED);
1582       }
1583    }
1584    PJ_DLM_UPD_VAR(pjRbCb,count);
1585    pjDlmProcessSdus(tPjCb, pjRbCb, mBuf, sduId,count);
1586
1587    /* kw005.201 ccpu00117318, updated statistics */
1588    RETVALUE(ROK);
1589 } /* PjUiPjuDatReq */
1590
1591
1592 #ifdef FLAT_BUFFER_OPT
1593 /**
1594  * @details
1595  * This primitive is used by the PDCP service user to request PDCP
1596  * for data transfer.
1597  *
1598  * @param[in] pst    - Pointer to Pst structure.
1599  * @param[in] spId  - Service provider ID. This is the reference number
1600  * used by PDCP service user (Relay) to identify its SAP. This reference number
1601  * will be provided by PDCP in any further primitives sent by PDCP
1602  * to the service user.
1603  * @param[in] pdcpId - Pointer to CmLtePdcpId structure, PDCP id is used to 
1604  * uniquely identify an PDCP entity. 
1605  * @param[in] sduId  - SDU ID. 
1606  * @param[in] mBuf   - Pointer to Flat buffer.
1607  *
1608  * @return ROK
1609  */
1610
1611 #ifdef ANSI
1612 PUBLIC S16 PjUiPjuDatReqFB
1613 (
1614 Pst            *pst,            
1615 SpId           spId,               
1616 CmLtePdcpId    *pdcpId,         
1617 PjuSduId       sduId,           
1618 FlatBuffer         *mBuf          
1619 )
1620 #else
1621 PUBLIC S16 PjUiPjuDatReqFB(pst, spId, pdcpId, sduId, mBuf)
1622 Pst             *pst;       
1623 SpId            spId;           
1624 CmLtePdcpId     *pdcpId;     
1625 PjuSduId         sduId;   
1626 FlatBuffer          *mBuf;          
1627 #endif
1628 {
1629    PjDlRbCb   *pjRbCb;       /* RB Control Block */
1630    PjDlUeCb   *ueCb;         /* UE Control Block */
1631 #ifndef CCPU_OPT
1632    MsgLen      len;          /* Size of the SDU */
1633 #endif
1634 #ifndef NO_ERRCLS
1635    PjPjuSapCb     *pjuSap;       /* SAP Config Block */
1636 #endif
1637    PjCb           *tPjCb = NULLP;/* KW_FIX */
1638    PjTxEnt        *txEnt=NULLP;
1639 #ifndef NO_ERRCLS
1640    S16         ret;          /* Return Value */
1641    PjUeKey  key;
1642 #endif
1643
1644 #ifdef L2_PDCP_OPTMZ   
1645    U8       hashKey;          /* Computed HashKey */
1646    PjBuf       *buf; 
1647 #endif 
1648    TRC3(PjUiPjuDatReqFB)
1649
1650    if ((pst->dstInst >= PJ_MAX_PDCP_INSTANCES) || (mBuf == NULLP))      /* KW_FIX */
1651    {
1652       /* PJ_FREE_FLAT_BUF(tPjCb, mBuf); */
1653       RETVALUE(RFAILED);
1654    }
1655
1656    tPjCb = PJ_GET_PJCB(pst->dstInst);
1657
1658 #ifndef NO_ERRCLS
1659    ret = ROK;
1660    pjuSap = NULLP;
1661 #endif
1662
1663 #ifdef DEBUGP
1664    /* DEBUG_PRINT */
1665    RLOG1(L_DEBUG, "PjUiPjuDatReq(pst, spId(%d))", spId);
1666 #endif
1667
1668 #ifndef NO_ERRCLS
1669    pjuSap = (PjPjuSapCb*)(tPjCb->u.dlCb->pjuSap + spId);
1670    /* Validate SAP ID under ERRORCLS */
1671    PJ_VALDATE_SAP(tPjCb, spId, pjuSap, ret);
1672    if (ret != ROK)
1673    {
1674       PJ_FREE_FLAT_BUF(tPjCb, mBuf);
1675       RETVALUE(RFAILED);
1676    }
1677 #endif
1678    /* Fetch the UeCb */
1679    if (pjDbmFetchDlUeCb(tPjCb, pdcpId->ueId, pdcpId->cellId, &ueCb) != ROK)
1680    {
1681       RLOG_ARG1(L_ERROR, DBG_CELLID, pdcpId->cellId,"DL UeId[%u] not found",
1682             pdcpId->ueId);
1683       PJ_FREE_FLAT_BUF(tPjCb, mBuf);
1684       RETVALUE(RFAILED);
1685    }
1686    /* Fetch the RbCb */
1687    PJ_DBM_FETCH_DL_RBCB(pdcpId->rbId, pdcpId->rbType, ueCb,pjRbCb);
1688    
1689    if (pjRbCb == NULLP)
1690    {     
1691       RLOG_ARG2(L_ERROR, DBG_UEID,pdcpId->ueId, "CellId[%u]: DL RbId[%d] not found",
1692             pdcpId->cellId, pdcpId->rbId);
1693       PJ_FREE_FLAT_BUF(tPjCb, mBuf);
1694       RETVALUE(RFAILED);
1695    }
1696
1697    /* Update the total packets received for L2 Measurements */
1698    PJ_UPD_L2_DLDISC_PKT_STS(tPjCb,pjRbCb);
1699
1700 #ifdef PTPJLIB 
1701    /* kw003.201 Control for packet administration */
1702    
1703    if (pjLibPktAdmCtrl(pjRbCb, NULL) != ROK)
1704    {
1705       RLOG_ARG2(L_DEBUG,DBG_UEID,pdcpId->ueId,"PDCP pkt Q is Full & pkt dropped"
1706             " for cellId(%d), rbId(%d)", pdcpId->cellId, pdcpId->rbId);
1707       PJ_FREE_FLAT_BUF(tPjCb, mBuf);
1708       gPdcpStats.numPdcpSdusDiscarded++;
1709       PJ_UPD_L2_DLDISC_STS(tPjCb, pjRbCb);
1710       RETVALUE(RFAILED);
1711    }
1712 #endif
1713
1714    if((ueCb->libInfo.state != PJ_STATE_NORMAL) && (pjRbCb->rbType != PJ_SRB))
1715    {
1716       if(pjRbCb->dlCb.dlPktQ.count < 500)
1717       {
1718          pjDlmEnqueueDlPktFB(tPjCb, pjRbCb, PJ_DATA_NRM_PKT, NULL, sduId, mBuf); 
1719          RETVALUE(ROK);
1720       }
1721       else
1722       {
1723          PJ_FREE_FLAT_BUF(tPjCb, mBuf);
1724          gPdcpStats.numPdcpSdusDiscarded++;
1725          PJ_UPD_L2_DLDISC_STS(tPjCb, pjRbCb);
1726          RETVALUE(RFAILED);
1727       }
1728    }
1729
1730    PJ_ALLOC(tPjCb, txEnt, sizeof(PjTxEnt));
1731 #if (ERRCLASS & ERRCLS_ADD_RES)
1732    if (txEnt == NULLP)
1733    {
1734       RLOG0(L_FATAL, "Memory Allocation failed.");
1735       PJ_FREE_FLAT_BUF(gCb,sdu);
1736       RETVALUE(RFAILED);
1737    }
1738 #endif /* ERRCLASS & ERRCLS_RES */ 
1739    PJ_DLM_UPD_VAR(pjRbCb,txEnt->count);     
1740    PJ_DLM_GET_SN(pjRbCb,txEnt->count,txEnt->sn);
1741    pjRbCb->dlCb.count = txEnt->count; 
1742    txEnt->state = PJ_SDU_RECEIVED;
1743    txEnt->sduId = sduId;
1744    txEnt->fb   = *mBuf;
1745    txEnt->pdu   = NULLP;
1746    txEnt->sdu   = NULLP;
1747    /* Insert TxEnt into the transmission buffer */
1748 #ifndef L2_PDCP_OPTMZ
1749    pjDbmInsTxEnt(tPjCb, &(pjRbCb->dlCb.txBuf), txEnt); 
1750    /* kw005.201 added support for L2 Measurement */
1751 #else
1752    if (pjRbCb->ueCb->secInfo.secAct &&  pjRbCb->ueCb->secInfo.cipherInfo.algoType != 0)   /* If its not NULL Ciphering and Security is enabled */
1753    {
1754    txEnt->datCfmEnt.node = NULLP;
1755    txEnt->reEstPktEnt.node = NULLP;
1756    txEnt->sduSubmitEnt.node = (PTR)NULLP;
1757
1758    buf=&(pjRbCb->dlCb.txBuf);
1759    hashKey = (U8)PJ_HASH_FN(buf, txEnt->count); /*KW_FIX*/
1760
1761    txEnt->lstEnt.node = (PTR)txEnt;
1762    cmLListAdd2Tail(&buf->datQ[hashKey], &txEnt->lstEnt);
1763    buf->numEntries ++;
1764    /* No Need to add TxEnt in DataCfm Quee as no Cfm from RLC */
1765    if (pjRbCb->mode == PJ_DRB_AM) 
1766    {
1767       txEnt->datCfmEnt.node = (PTR)txEnt;
1768       cmLListAdd2Tail(&pjRbCb->dlCb.txBuf.datCfmQ, &txEnt->datCfmEnt);
1769    }
1770    txEnt->state  = PJ_PDU_SUBMITTED;
1771    }
1772    else 
1773    {
1774    pjDbmInsTxEnt(tPjCb, &(pjRbCb->dlCb.txBuf), txEnt); 
1775    }
1776 #endif 
1777
1778 #ifndef RGL_SPECIFIC_CHANGES
1779 #ifdef MSPD
1780    {
1781       extern U32 dlrate_pju;
1782       dlrate_pju += mBuf->len;
1783    }
1784 #endif
1785 #endif
1786    pjDlmHdlCmp(tPjCb, pjRbCb, txEnt);
1787    /*pjDlmProcessSdusFB(tPjCb, pjRbCb, mBuf, sduId, sn, txHfn);*/
1788
1789    /* kw005.201 ccpu00117318, updated statistics */
1790    RETVALUE(ROK);
1791 } /* PjUiPjuDatReqFB */
1792 #endif
1793
1794 /**
1795  * 
1796  * @details
1797  * This primitive is used by PDCP user to forward the SDUs along with its SN
1798  * as part of handover (SDUs forwarded from PDCP on source eNB via X2-U 
1799  * Interface to the PDCP on target eNB)
1800  *
1801  * @param[in] pst    - Pointer to Pst structure.
1802  * @param[in] spId   - Service provider ID. This is the reference number
1803  * used by PDCP service user (Relay) to identify its SAP. This reference number
1804  * will be provided by PDCP in any further primitives sent by PDCP
1805  * to the service user.
1806  * @param[in] pdcpId - Pointer to CmLtePdcpId structure, PDCP id is used to 
1807  * uniquely identify a PDCP entity. 
1808  * @param[in] datFwdReq - Pointer to data forward information structure.
1809  *
1810  *  @return ROK.
1811  */
1812 #ifdef ANSI
1813 PUBLIC S16 PjUiPjuDatFwdReq 
1814 (
1815 Pst              *pst, 
1816 SpId             spId, 
1817 CmLtePdcpId      *pdcpId, 
1818 PjuDatFwdReqInfo *datFwdReq
1819 )
1820 #else
1821 PUBLIC S16 PjUiPjuDatFwdReq(pst,spId,pdcpId,datFwdReq)
1822 Pst              *pst;
1823 SpId             spId;
1824 CmLtePdcpId      *pdcpId;
1825 PjuDatFwdReqInfo *datFwdReq;
1826 #endif
1827 {
1828
1829    S16         ret;           /* Return Value */
1830    PjPjuSapCb  *pjuSap;       /* SAP Config Block */
1831    PjCb   *tPjCb;
1832
1833    TRC3(PjUiPjuDatFwdReq)
1834    /* ccpu00137221 : KW Fix */
1835    if ( NULLP == datFwdReq )
1836    {
1837       /* Log an error */
1838 #if (ERRCLASS & ERRCLS_INT_PAR)
1839       if (pst->dstInst < PJ_MAX_PDCP_INSTANCES)
1840       {
1841          tPjCb = PJ_GET_PJCB(pst->dstInst);
1842          if (tPjCb != NULLP)
1843          {
1844             RLOG0(L_ERROR, "Hndl DatFwdReq failed ,tPjCb is NULLP");
1845          }
1846       }
1847 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1848       RETVALUE(RFAILED);
1849    }
1850    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)
1851    {
1852       PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1853                  (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1854       PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1855       RETVALUE(RFAILED);
1856    }
1857    tPjCb = PJ_GET_PJCB(pst->dstInst);
1858
1859    ret = ROK;
1860    pjuSap = NULLP;
1861  
1862    RLOG1(L_DEBUG, "PjUiPjuDatFwdReq(pst, spId(%d))", spId);
1863
1864    if (( datFwdReq->dir == PJ_DIR_DL )  &&
1865        (tPjCb->pjGenCfg.mode == LPJ_MODE_PDCP_DL))
1866      
1867    {
1868       PjDlUeCb      *dlUeCb;         /* UE Control Block */
1869       PjDlRbCb      *dlRbCb;       /* RB Control Block */
1870       pjuSap = (PjPjuSapCb*)(tPjCb->u.dlCb->pjuSap + spId);
1871       /* Validate SAP ID under ERRORCLS */
1872       PJ_VALDATE_SAP(tPjCb, spId, pjuSap, ret);
1873       if (ret != ROK)
1874       {
1875          /* Freeing from proper region */
1876          PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1877                     (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1878          PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1879          RETVALUE(RFAILED);
1880       }
1881
1882       if (pjDbmFetchDlUeCb(tPjCb, pdcpId->ueId, pdcpId->cellId, &dlUeCb) != ROK)
1883       {
1884          RLOG_ARG1(L_ERROR, DBG_CELLID, pdcpId->cellId,"DL UeId[%u] not found",
1885             pdcpId->ueId);
1886          /* Freeing from proper region */
1887          PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1888                     (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1889          PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1890          RETVALUE(RFAILED);
1891       }
1892       /* Fetch the RbCb */
1893       PJ_DBM_FETCH_DL_RBCB(pdcpId->rbId, pdcpId->rbType, dlUeCb,dlRbCb);
1894       if (dlRbCb == NULLP) 
1895       {
1896          RLOG_ARG2(L_ERROR, DBG_UEID,pdcpId->ueId, "CellId[%u]: DL RbId[%d] not found",
1897             pdcpId->cellId, pdcpId->rbId);
1898          /* Freeing from proper region */
1899          PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1900                     (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1901          PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1902
1903          RETVALUE(RFAILED);
1904       }
1905      
1906       if (dlRbCb->state == PJ_STATE_HO)
1907       {
1908           pjDlmEnqueueDlPkt(tPjCb,dlRbCb, PJ_DATA_FWD_PKT, datFwdReq, 0, NULLP);
1909       }
1910       else
1911       {
1912         ret = pjDlmHndlDatFwdReq(tPjCb, dlRbCb, datFwdReq); 
1913       }
1914
1915       PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1916                  (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1917       PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1918
1919    }
1920    else  if (( datFwdReq->dir == PJ_DIR_UL )  &&
1921              (tPjCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL))
1922    {
1923       PjUlRbCb      *ulRbCb;       /* RB Control Block */
1924       PjUlUeCb      *ulUeCb;
1925       pjuSap = (PjPjuSapCb*)(tPjCb->u.ulCb->pjuSap + spId);
1926       /* Validate SAP ID under ERRORCLS */
1927       pjuSap->state = PJ_SAP_BND;
1928       PJ_VALDATE_SAP(tPjCb, spId, pjuSap, ret);
1929       if (ret != ROK)
1930       {
1931          /* Freeing from proper region */
1932          PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1933                     (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1934          PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1935          RETVALUE(RFAILED);
1936       }
1937
1938       if (pjDbmFetchUlUeCb(tPjCb, pdcpId->ueId, pdcpId->cellId, &ulUeCb) != ROK)
1939       {
1940          RLOG_ARG1(L_ERROR, DBG_CELLID, pdcpId->cellId,"UL UeId[%u] not found",
1941             pdcpId->ueId);
1942          /* Freeing from proper region */
1943          PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1944                     (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1945          PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1946          RETVALUE(RFAILED);
1947       }
1948       /* Fetch the RbCb */
1949       PJ_DBM_FETCH_UL_RBCB(pdcpId->rbId, pdcpId->rbType, ulUeCb,ulRbCb);
1950       if (ulRbCb == NULLP)
1951       {
1952          RLOG_ARG2(L_ERROR, DBG_UEID,pdcpId->ueId, "CellId[%u]: UL RbId[%d] not found",
1953             pdcpId->cellId, pdcpId->rbId);
1954          /* Freeing from proper region */
1955          PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1956                     (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1957          PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1958
1959          RETVALUE(RFAILED);
1960       }
1961      
1962       ret = pjUlmHdlDatFwdReq(tPjCb, ulRbCb, datFwdReq);
1963       PJ_PST_FREE(pst->region, pst->pool, datFwdReq->datFwdInfo, 
1964                    (datFwdReq->numSdus * sizeof(PjuDatFwdInfo)));
1965       PJ_PST_FREE(pst->region, pst->pool, datFwdReq, sizeof(PjuDatFwdReqInfo));
1966    }
1967   
1968    /* Freeing from proper region */
1969
1970    if ( ret != ROK )
1971    {
1972         /* Log an error */
1973 #if (ERRCLASS & ERRCLS_INT_PAR)
1974       RLOG0(L_ERROR, "pjDlm/pjUlm HndlDatFwdReq failed");
1975 #endif /* ERRCLASS & ERRCLS_INT_PAR */
1976
1977    }
1978    RETVALUE(ret);
1979 }
1980
1981
1982 /**
1983  * @brief Handler for Bind request from RRM towards CL.
1984  *
1985  * @details
1986  *
1987  *     Function : YsUiCpjKdfReq
1988  *     
1989  *     This function handles the bind request from RRM.
1990  *     
1991  *           
1992  *  @param[in]  Pst  *pst
1993  *  @param[in]  SuId suId
1994  *  @param[in]  SpId spId
1995  *  @return  S16
1996  *      -# ROK 
1997  *      -# RFAILED 
1998  **/
1999 #ifdef ANSI
2000 PUBLIC S16 PjUiCpjKdfReq
2001 (
2002 Pst  *pst,
2003 SpId spId,
2004 CpjCfgTransId        transId,
2005 CpjKdfReqInfo  *kdfReqInfo
2006 )
2007 #else
2008 PUBLIC S16 PjUiCpjKdfReq(pst, suId, spId)
2009 Pst  *pst;
2010 SuId suId;
2011 SpId spId;
2012 #endif
2013 {
2014    S16           ret;
2015    CpjKdfCfmInfo *kdfCfmInf;
2016    PjCb          *tPjCb;
2017    Pst           cfmPst;
2018    PjCpjSapCb    *cpjSap;
2019
2020
2021    TRC2(PjUiCpjKdfReq)
2022
2023    ret = ROK;
2024
2025    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)      /* KW_FIX */
2026    {
2027       RETVALUE(RFAILED);
2028    }
2029    tPjCb = PJ_GET_PJCB(pst->dstInst);
2030
2031    /* Memory leak fix ccpu00135359 */
2032    cpjSap = &(tPjCb->u.ulCb->cpjSap);
2033    if(SGetSBuf(cpjSap->pst.region,cpjSap->pst.pool,(Data **)&kdfCfmInf, 
2034       sizeof (CpjKdfCfmInfo)) != ROK)
2035    {
2036       RLOG0(L_FATAL, "Memory Allocation failed.");
2037       RETVALUE(RFAILED);
2038    }
2039
2040    cfmPst.dstInst = pst->srcInst;
2041    cfmPst.dstEnt  = pst->srcEnt;
2042    cfmPst.dstProcId = pst->srcProcId;
2043    cfmPst.srcInst = pst->dstInst;
2044    cfmPst.srcEnt = pst->dstEnt;
2045    cfmPst.srcProcId = pst->dstProcId;
2046    cfmPst.selector = 0;
2047    cfmPst.region = tPjCb->init.region;
2048    cfmPst.pool = tPjCb->init.pool;
2049    cfmPst.prior = PRIOR0;
2050    cfmPst.route = RTESPEC;
2051
2052    RLOG1(L_DEBUG, "Key derivation request for Key type %d",
2053             kdfReqInfo->keyDerType);
2054
2055    switch(kdfReqInfo->keyDerType)
2056    {
2057       case CPJ_KDF_TYPE1:
2058          kdfCfmInf->keyDerType = CPJ_KDF_TYPE1;
2059          ret = pjLibObdPrcKenbCfg(tPjCb, &(kdfReqInfo->u.kEnbInf), 
2060                &(kdfCfmInf->u.kEnbInf));
2061          break;
2062
2063       case CPJ_KDF_TYPE2:
2064          kdfCfmInf->keyDerType = CPJ_KDF_TYPE2;
2065          ret = pjLibObdPrcKenbStarCfg(tPjCb, &(kdfReqInfo->u.kEnbStarInf),
2066                &(kdfCfmInf->u.kEnbStarInf));
2067          break;
2068
2069       case CPJ_KDF_TYPE3:
2070          break;
2071       default:
2072          break;
2073    }
2074    /* Send Cfg confirm */
2075    if(ret != ROK)
2076    {
2077       PjUiCpjKdfCfm(&cfmPst, PJ_KDF_SAP,
2078             transId, kdfCfmInf, CPJ_CFG_CFM_NOK);
2079    }// Sudhanshu WR Change
2080    else
2081    {
2082       PjUiCpjKdfCfm(&cfmPst, PJ_KDF_SAP,
2083             transId, kdfCfmInf, CPJ_CFG_CFM_OK);
2084    }
2085
2086
2087    SPutSBuf (pst->region, pst->pool, (Data *)kdfReqInfo,
2088          sizeof(CpjKdfReqInfo));
2089    kdfReqInfo = NULLP;
2090
2091    RETVALUE(ret);
2092
2093 }  /* PjUiCpjKdfReq */
2094
2095
2096 #ifdef __cplusplus
2097 }
2098 #endif /* __cplusplus */
2099 /********************************************************************30**
2100          End of file
2101 **********************************************************************/