Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_lim.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 - Lower Interface Functions
22     
23      Type:    C file
24   
25      Desc:     Source code for PDCP Lower Interface Module.
26                This file contains following functions
27       
28                     --pjLimDatInd
29                     --pjLimDatCfm
30                     --pjLimStaInd
31
32      File:     pj_lim.c
33
34 **********************************************************************/
35      
36 static const char* RLOG_MODULE_NAME="PDCP";
37 static int RLOG_MODULE_ID=1024;
38 static int RLOG_FILE_ID=219;
39 /** @file pj_lim.c
40 @brief PDCP Lower Interface Module
41 */
42
43 \f
44 /* header (.h) include files */
45 #include "envopt.h"             /* environment options */
46 #include "envdep.h"             /* environment dependent */
47 #include "envind.h"             /* environment independent */
48
49 #include "gen.h"                /* general */
50 #include "ssi.h"                /* system services interface */
51 #include "cm5.h"                /* Timer Functions */
52 #include "cm_lte.h"             /* common LTE header file */
53 #include "cm_hash.h"            /* common hash module  file */
54 #include "cm_llist.h"           /* common list header file */
55 #include "cpj.h"                /* RRC layer */
56 #include "kwu.h"
57 #include "pju.h"                /* PDCP service user */
58 #include "lpj.h"                /* RRC layer */
59 #include "pj_env.h"             /* RLC environment options */
60 #include "pj.h"                 /* RLC layer */
61 #include "pj_err.h"
62
63 /* header/extern include files (.x) */
64
65 #include "gen.x"                /* general */
66 #include "ssi.x"                /* system services interface */
67 #include "cm_lib.x"             /* common library */
68 #include "cm5.x"                /* Timer Functions */
69 #include "cm_hash.x"            /* common hash module */
70 #include "cm_lte.x"             /* common LTE file */
71 #include "cm_llist.x"           /* common list header file */
72 #include "kwu.x"
73 #include "cpj.x"                /* RRC layer */
74 #include "pju.x"                /* PDCP service user */
75 #include "lpj.x"                /* LM Interface */
76 #include "pj.x"                 /* RLC layer */
77 #include "pj_udx.h"
78 #include "pj_udx.x"
79 #include "pj_ul.x" 
80 #include "pj_dl.x" 
81
82 #ifdef __cplusplus
83 EXTERN "C" {
84 #endif /* __cplusplus */
85 PRIVATE S16 pjLimDiscSduCfm ARGS((PjCb *gCb, 
86                                   PjDlRbCb *pjRbCb, 
87                                   KwuDiscSduInfo *discSduCfm));
88
89 /**
90  *
91  * @brief Handler for Sending sdu to Rlc.
92  *       
93  *
94  * @b Description
95  *
96  *
97  *  @param[in] pjRbCb      PDCP control block.
98  *  @param[in] sduId         PDCP SDU id.
99  *  @param[in] mBuf        Pointer to PDCP Sdu
100  *
101  * 
102  *  @return  S16
103  *      -# ROK 
104  *      -# RFAILED 
105  */
106
107 #ifdef ANSI
108 PUBLIC S16 pjDlmSendDatReq
109 (
110 PjCb       *gCb,
111 PjDlRbCb   *pjRbCb,
112 U32        sduId,
113 Buffer     *mBuf
114 )
115 #else
116 PUBLIC S16 pjDlmSendDatReq(gCb,pjRbCb,sduId, mBuf)
117 PjCb       *gCb;
118 PjDlRbCb   *pjRbCb;
119 U32        sduId;
120 Buffer     *mBuf;
121 #endif
122 {
123    PjKwuSapCb     *pjSapCb;
124    KwuDatReqInfo datReq;
125    TRC2(pjDlmSendDatReq);
126
127    pjSapCb = gCb->u.dlCb->kwuSap;
128    datReq.rlcId.rbId = pjRbCb->rbId;
129    datReq.rlcId.rbType = pjRbCb->rbType;
130    datReq.rlcId.ueId   = pjRbCb->ueCb->key.ueId;
131    datReq.rlcId.cellId = pjRbCb->ueCb->key.cellId;
132 #ifdef CCPU_OPT
133    datReq.lcType = (U8)((pjRbCb->rbType == CM_LTE_SRB) ?
134                      CM_LTE_LCH_DCCH : CM_LTE_LCH_DTCH);  /*KW_FIX*/
135 #endif
136
137    datReq.sduId  = sduId;
138
139    RETVALUE(PjLiKwuDatReq(&(pjSapCb->pst),pjSapCb->spId, &datReq, mBuf));
140 }
141
142 /**
143  *
144  * @brief Handler for Discarding SDU  to Rlc.
145  *       
146  *
147  * @b Description
148  *
149  *
150  *  @param[in] pjRbCb      PDCP control block.
151  *  @param[in] sduId         PDCP SDU id.
152  *
153  * 
154  *  @return  S16
155  *      -# ROK 
156  *      -# RFAILED 
157  */
158
159 #ifdef ANSI
160 PUBLIC S16 pjDlmSendDiscSdu
161 (
162 PjCb    *gCb,
163 PjDlRbCb  *pjRbCb,
164 U32      sduId
165 )
166 #else
167 PUBLIC S16 pjDlmSendDiscSdu(gCb,pjRbCb,sduId)
168 PjCb    *gCb;
169 PjDlRbCb  *pjRbCb;
170 U32      sduId;
171 #endif
172 {
173    KwuDiscSduInfo  *discSdu;
174    PjKwuSapCb     *pjSapCb;
175    TRC2(pjDlmSendDiscSdu);
176
177    pjSapCb = gCb->u.dlCb->kwuSap;
178    KwuDiscSduInfo discSduTmp;
179    discSdu = &discSduTmp;
180
181    discSdu->rlcId.rbId = pjRbCb->rbId;
182    discSdu->rlcId.rbType = pjRbCb->rbType;
183    discSdu->rlcId.ueId   = pjRbCb->ueCb->key.ueId;
184    discSdu->rlcId.cellId = pjRbCb->ueCb->key.cellId; 
185   
186    discSdu->sduIds[0]  = sduId;
187    discSdu->numSduIds  = 1;
188
189    PjLiKwuDiscSduReq(&(pjSapCb->pst),pjSapCb->spId, discSdu);
190
191    RETVALUE(ROK);
192 }
193
194
195 \f
196 /*****************************************************************************
197  *                          PDCP LOWER INTERFACE
198  ****************************************************************************/
199 /**
200  *
201  * @brief 
202  *
203  *        Handler for getting the BndCfm from RLC.
204  *
205  * @b Description:
206  *
207  *        This function receives the PDU from RLC 
208  *        and invokes the handler for processing the PDU.
209  *
210  *  @param[in] pjRbCb    -   PDCP RB Control Block
211  *  @param[in] mBuf    -   PDU
212  *
213  *  @return  S16
214  *      -# ROK 
215  *      -# RFAILED
216  *
217  */
218 #ifdef ANSI
219 PUBLIC S16 PjLiKwuBndCfm
220 (
221 Pst           *pst,       /* Post */
222 SuId          suId,       /* Service User Id */
223 U8            status     /* Status */
224 )
225 #else
226 PUBLIC Void PjLiKwuBndCfm (pst, suId, datCfm)
227 Pst           *pst;        /* Post */
228 SuId          suId;        /* Service User Id */
229 U8          status;     /* Status */
230 #endif
231 {
232    U16             event;              /* Event */
233    U16             cause;              /* Cause */
234    PjKwuSapCb      *kwuSap;            /* RGU SAP Control Block */ 
235    PjCb   *tPjCb;
236    
237    TRC1(PjLiKwuBndCfm);
238
239    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)     /* KW_FIX */
240    {
241        RETVALUE(RFAILED);
242    }
243    tPjCb = PJ_GET_PJCB(pst->dstInst);
244
245    RLOG2(L_DEBUG, "PjLiKwuBndCfm(SuId (%d), status (%d) ",suId, status);  
246    UNUSED(pst);
247
248 #if (ERRCLASS & ERRCLS_INT_PAR)
249    if (!(tPjCb->init.cfgDone & PJ_LMM_GENCFG_DONE))
250    {
251       /* INNC: ERROR CLASS */
252       RLOG0(L_FATAL, "General configuration not done");
253       /*PJ_SEND_SAPID_ALARM(tPjCb,suId, LPJ_EVENT_LI_BND_CFM, LPJ_CAUSE_INV_STATE);*/
254
255       RETVALUE(RFAILED);
256    }
257
258    if (suId < 0)
259    {
260       /* INNC: ERROR CLASS */
261       RLOG0(L_ERROR, "Invalid suId");
262       /*PJ_SEND_SAPID_ALARM(tPjCb,suId, LPJ_EVENT_LI_BND_CFM, LPJ_CAUSE_INV_SUID);*/
263
264       RETVALUE(RFAILED);
265    }
266 #endif /* ERRCLASS & ERRCLS_INT_PAR */
267
268    if (tPjCb->pjGenCfg.mode == LPJ_MODE_PDCP_UL)
269    {
270       kwuSap = tPjCb->u.ulCb->kwuSap;
271    }
272    else
273    {
274       kwuSap = tPjCb->u.dlCb->kwuSap;
275    }
276
277 #ifdef DEBUGP
278    RLOG1(L_DEBUG, "PjLiKwuBndCfm: For KWU SAP state=%d",
279                   kwuSap->state);
280 #endif
281
282    /* Check rguSap state */
283    switch (kwuSap->state)
284    {
285       case PJ_SAP_BINDING:
286       {
287          pjStopTmr (tPjCb, (PTR)kwuSap, PJ_EVT_WAIT_KWU_BNDCFM);
288
289          kwuSap->retryCnt = 0;
290           
291          if (status == CM_BND_OK)
292          {
293             kwuSap->state = PJ_SAP_BND;
294             event = LCM_EVENT_BND_OK;
295             cause = LPJ_CAUSE_SAP_BNDENB;
296          }
297          else
298          {
299             kwuSap->state = PJ_SAP_CFG;
300             event = LCM_EVENT_BND_FAIL;
301             cause = LPJ_CAUSE_UNKNOWN;
302          }
303       }
304       break;
305      default:
306         event = LPJ_EVENT_RGU_BND_CFM;
307         cause = LCM_CAUSE_INV_STATE;
308         break;
309    }
310
311    /* Send an alarm with proper event and cause */
312  /*  PJ_SEND_SAPID_ALARM(tPjCb, suId, event, cause);*/
313 #ifdef LTE_L2_MEAS
314    pjLmmSendAlarm(tPjCb,LCM_CATEGORY_INTERFACE, event, cause, suId, 0,0);
315 #else
316    pjLmmSendAlarm(tPjCb,LCM_CATEGORY_INTERFACE, event, cause, suId, 0);
317 #endif
318
319    RETVALUE(ROK);
320 } /* pjLimDatInd */
321
322 /**
323  *
324  * @brief 
325  *
326  *        Handler for getting the PDU from RLC.
327  *
328  * @b Description:
329  *
330  *        This function receives the PDU from RLC 
331  *        and invokes the handler for processing the PDU.
332  *
333  *  @param[in] pjRbCb    -   PDCP RB Control Block
334  *  @param[in] mBuf    -   PDU
335  *
336  *  @return  S16
337  *      -# ROK 
338  *      -# RFAILED
339  *
340  */
341 #ifdef ANSI
342 PUBLIC S16 PjLiKwuDatInd
343 (
344 Pst           *pst,        /* Post */
345 SuId          suId,        /* Service User Id */
346 KwuDatIndInfo *datInd,     /* Data Indication Info */
347 Buffer        *mBuf        /* Buffer */
348 )
349 #else
350 PUBLIC Void PjLiKwuDatInd(pst, suId, datInd, mBuf)
351 Pst           *pst;        /* Post */
352 SuId          suId;        /* Service User Id */
353 KwuDatIndInfo *datInd;     /* Data Indication Info */
354 Buffer        *mBuf;       /* Buffer */
355 #endif
356 {
357    S16         ret;           /* Return Value */
358    PjUlRbCb     *pjRbCb;
359    PjCb   *tPjCb;
360
361    TRC1(PjLiKwuDatInd);
362
363    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)     /* KW_FIX*/
364    {
365        RETVALUE(RFAILED);
366    }
367    tPjCb = PJ_GET_PJCB(pst->dstInst);
368
369    ret = pjDbmFetchUlRbCb (tPjCb,datInd->rlcId,&pjRbCb);
370    if (ret != ROK)
371    {
372       RLOG_ARG2(L_ERROR, DBG_UEID,datInd->rlcId.ueId, "CellId[%u]:UL RbId[%d] not found",
373             datInd->rlcId.cellId, datInd->rlcId.rbId);
374       PJ_FREE_BUF(mBuf);
375       RETVALUE(RFAILED);
376    }
377   
378    pjLimDatInd(tPjCb, pjRbCb, mBuf, datInd->isOutOfSeq);  
379
380
381    RETVALUE(ROK);
382 } /* pjLimDatInd */
383
384    PUBLIC int pdcpDatCfmsReceived = 0;
385 /**
386  *
387  * @brief 
388  *
389  *        Handler for getting the datCfm from RLC.
390  *
391  * @b Description:
392  *
393  *        This function receives the PDU from RLC 
394  *        and invokes the handler for processing the PDU.
395  *
396  *  @param[in] pjRbCb    -   PDCP RB Control Block
397  *  @param[in] mBuf    -   PDU
398  *
399  *  @return  S16
400  *      -# ROK 
401  *      -# RFAILED
402  *
403  */
404 #ifdef ANSI
405 PUBLIC S16 PjLiKwuDatCfm
406 (
407 Pst           *pst,       /* Post */
408 SuId          suId,       /* Service User Id */
409 KwuDatCfmInfo *datCfm     /* Data Confirm Info */
410 )
411 #else
412 PUBLIC Void PjLiKwuDatCfm(pst, suId, datCfm)
413 Pst           *pst;        /* Post */
414 SuId          suId;        /* Service User Id */
415 KwuDatCfmInfo *datCfm;     /* Data Confirm Info */
416 #endif
417 {
418    S16         ret;           /* Return Value */
419    PjDlRbCb     *pjRbCb;      
420    PjDatCfm   pjCfm;
421    PjCb   *tPjCb;
422
423    TRC1(PjLiKwuDatCfm);
424
425    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)    /* KW_FIX */
426    {
427        RETVALUE(RFAILED);
428    }
429
430    tPjCb = PJ_GET_PJCB(pst->dstInst);
431
432    RLOG2(L_DEBUG, "PjLiKwuDatCfm(rbId(%d),rbType (%d), mBuf)",
433                     datCfm->rlcId.rbId,datCfm->rlcId.rbType);
434
435    ret = pjDbmFetchDlRbCb (tPjCb,datCfm->rlcId,&pjRbCb);
436    if (ret != ROK)
437    {
438       RLOG_ARG2(L_ERROR, DBG_UEID,datCfm->rlcId.ueId, "CellId[%u]:DL RbId[%d] not found",
439             datCfm->rlcId.cellId, datCfm->rlcId.rbId);
440       PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, datCfm, sizeof(KwuDatCfmInfo));
441       RETVALUE(RFAILED);
442    }
443
444    pdcpDatCfmsReceived++; 
445
446    pjCfm.rlcId = datCfm->rlcId;
447    pjCfm.numSdu = (U16)(datCfm->numSduIds); /*KW_FIX*/
448    cmMemcpy((U8*)pjCfm.sduId, (U8*)datCfm->sduIds, sizeof(U32)*datCfm->numSduIds);
449    pjLimDatCfm (tPjCb, pjRbCb, &pjCfm);
450
451    PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, datCfm, sizeof(KwuDatCfmInfo));
452    RETVALUE(ROK);
453 } /* pjLimDatInd */
454
455 /**
456  *
457  * @brief 
458  *
459  *        Handler for flow control indication from RLC.
460  *
461  * @b Description:
462  *
463  *        TODO
464  *
465  *  @param[in] pst           - Pointer to post structure
466  *  @param[in] suId          - Service user Id
467  *  @param[in] flowCntrlInfo - Flow control information
468  *
469  *  @return  S16
470  *      -# ROK 
471  *      -# RFAILED
472  *
473  */
474 #ifdef ANSI
475 PUBLIC S16 PjLiKwuFlowCntrlInd
476 (
477 Pst           *pst,       
478 SuId          suId,       
479 KwuFlowCntrlIndInfo *flowCntrlInfo
480 )
481 #else
482 PUBLIC Void PjLiKwuFlowCntrlInd(pst, suId, flowCntrlInfo)
483 Pst           *pst;       
484 SuId          suId;       
485 KwuFlowCntrlIndInfo *flowCntrlInfo;
486 #endif
487 {
488    S16        ret;       
489    PjDlRbCb   *pjRbCb;      
490    PjCb       *tPjCb;
491
492    TRC1(PjLiKwuFlowCntrlInd);
493
494    if (pst->dstInst >= PJ_MAX_PDCP_INSTANCES)
495    {
496        RETVALUE(RFAILED);
497    }
498
499    tPjCb = PJ_GET_PJCB(pst->dstInst);
500
501    RLOG2(L_DEBUG, "PjLiKwuFlowCntrlInd(rbId(%d),rbType (%d), mBuf)",
502                      flowCntrlInfo->rlcId.rbId,flowCntrlInfo->rlcId.rbType);
503
504    ret = pjDbmFetchDlRbCb (tPjCb,flowCntrlInfo->rlcId,&pjRbCb);
505    if (ret != ROK)
506    {
507       RLOG_ARG2(L_ERROR, DBG_UEID,flowCntrlInfo->rlcId.ueId, "CellId[%u]:DL RbId[%d] not found",
508             flowCntrlInfo->rlcId.cellId, flowCntrlInfo->rlcId.rbId);
509       PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, flowCntrlInfo, sizeof(KwuFlowCntrlIndInfo));
510       RETVALUE(RFAILED);
511    }
512
513    /* if RLC is requesting to stop the flow means RB is overloaded */
514    if (flowCntrlInfo->pktAdmitCnt) 
515    {
516       if (pjRbCb->mode == PJ_DRB_AM)
517       {
518          pjRbCb->dropOnlyOne = 1;
519          pjRbCb->pktAdmitCnt= 0;
520       }
521       else
522       {
523          pjRbCb->dropOnlyOne = 0;
524          pjRbCb->pktAdmitCnt = flowCntrlInfo->pktAdmitCnt;
525       }
526    }
527    else
528    {
529       /*  flowCntrlInfo->pktAdmitCnt = 0 indicates PDB Recovered and no FC required
530        *  reset FC state  */
531       pjRbCb->dropOnlyOne = 0;
532       pjRbCb->pktAdmitCnt = 0;
533    }
534    pjRbCb->pktCnt = 0;
535
536    PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, flowCntrlInfo, sizeof(KwuFlowCntrlIndInfo));
537    RETVALUE(ROK);
538 } /* PjLiKwuFlowCntrlInd */
539 /**
540  *
541  * @brief 
542  *
543  *        Handler for getting the Status Ind from RLC.
544  *
545  * @b Description:
546  *
547  *        This function receives the PDU from RLC 
548  *        and invokes the handler for processing the PDU.
549  *
550  *  @param[in] pjRbCb    -   PDCP RB Control Block
551  *  @param[in] mBuf    -   PDU
552  *
553  *  @return  S16
554  *      -# ROK 
555  *      -# RFAILED
556  *
557  */
558 #ifdef ANSI
559 PUBLIC S16 PjLiKwuStaInd
560 (
561 Pst           *pst,       /* Post */
562 SuId          suId,       /* Service User Id */
563 KwuStaIndInfo *staInd     /* StatusIndication Info */
564 )
565 #else
566 PUBLIC Void PjLiKwuStaInd(pst, suId, datCfm)
567 Pst           *pst;        /* Post */
568 SuId          suId;        /* Service User Id */
569 KwuStaIndInfo *staInd;     /* Status Indication Info */
570 #endif
571 {
572    S16         ret;           /* Return Value */
573    PjDlRbCb     *pjRbCb;
574    PjCb   *tPjCb;
575    U32 minSduCnt;
576
577    TRC1(PjLiKwuStaInd);
578
579    tPjCb = PJ_GET_PJCB(pst->dstInst);
580    if ((pst->dstInst >= PJ_MAX_PDCP_INSTANCES) || (tPjCb->init.cfgDone == FALSE))
581    {
582        PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, staInd, sizeof(KwuStaIndInfo));
583        RETVALUE(RFAILED);
584    }
585
586
587    RLOG2(L_DEBUG, "PjLiKwuStaInd(rbId(%d),rbType (%d), mBuf)",
588                          staInd->rlcId.rbId,staInd->rlcId.rbType);
589
590    ret = pjDbmFetchDlRbCb (tPjCb,staInd->rlcId,&pjRbCb);
591    if (ret != ROK)
592    {
593       RLOG_ARG2(L_ERROR, DBG_UEID,staInd->rlcId.ueId, "CellId[%u]:DL RbId[%d] not found",
594             staInd->rlcId.cellId, staInd->rlcId.rbId);
595 /* To confirm :: BRDCM team */
596       PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, staInd, sizeof(KwuStaIndInfo));
597       RETVALUE(RFAILED);
598   }
599   minSduCnt = (KWU_MAX_STA_IND_SDU < PJ_MAX_DAT_CFM)?KWU_MAX_STA_IND_SDU:PJ_MAX_DAT_CFM;
600   if(staInd->numSdu > minSduCnt)
601   {
602            staInd->numSdu = (U16)minSduCnt;    /*KW_FIX*/
603            RLOG_ARG2(L_ERROR, DBG_RBID , pjRbCb->rbId , "numSdu [%u] in StaInd is more than acceptable limit [%lu]",
604               staInd->numSdu , minSduCnt);
605   }
606   pjLimStaInd(tPjCb, pjRbCb, (PjDatCfm *) staInd);
607 /* To confirm :: BRDCM team */
608    PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, staInd, sizeof(KwuStaIndInfo));
609    RETVALUE(ROK);
610 } /* pjLimKwuStaInd */
611
612
613
614 /**
615  *
616  * @brief 
617  *
618  *        Handler for getting the ReEstablish Ind from RLC.
619  *
620  * @b Description:
621  *
622  *        This function receives the PDU from RLC 
623  *        and invokes the handler for processing the PDU.
624  *
625  *  @param[in] pjRbCb    -   PDCP RB Control Block
626  *  @param[in] mBuf    -   PDU
627  *
628  *  @return  S16
629  *      -# ROK 
630  *      -# RFAILED
631  *
632  */
633 #ifdef ANSI
634 PUBLIC S16 PjLiKwuReEstCmpInd
635 (
636 Pst           *pst,       /* Post */
637 SuId          suId,       /* Service User Id */
638 CmLteRlcId    rlcId       /* RlcId */
639 )
640 #else
641 PUBLIC Void PjLiKwuReEstCmpInd(pst, suId, rlcId)
642 Pst           *pst;        /* Post */
643 SuId          suId;        /* Service User Id */
644 CmLteRlcId    rlcId;       /* RlcId */
645 #endif
646 {
647    S16        ret;           /* Return Value */
648    PjUlRbCb   *ulRbCb;
649    PjCb   *tPjCb;
650
651    TRC1(PjLiKwuReEstCmpInd);
652
653    tPjCb = PJ_GET_PJCB(pst->dstInst);
654    if ((pst->dstInst >= PJ_MAX_PDCP_INSTANCES) || (tPjCb->init.cfgDone == FALSE))
655    {
656        RETVALUE(RFAILED);
657    }
658
659
660    RLOG2(L_DEBUG, "PjLiKwuReEstCmpInd(rbId(%d),rbType (%d), mBuf)",
661                          rlcId.rbId,rlcId.rbType);
662
663    ret = pjDbmFetchUlRbCb (tPjCb,rlcId,&ulRbCb);
664    if (ret != ROK)
665    {
666       RLOG_ARG2(L_ERROR, DBG_UEID,rlcId.ueId, "CellId[%u]:UL RbId[%d] not found",
667             rlcId.cellId, rlcId.rbId);
668       RETVALUE(RFAILED);
669    }
670    pjUlmReEstCmpInd(tPjCb,ulRbCb);
671
672    RETVALUE(ROK);
673 } /* pjLimDatInd */
674
675 #ifdef LTE_L2_MEAS
676 /**
677  *
678  * @brief 
679  *
680  *        Handler for getting the Ack Ind from RLC.
681  *
682  * @b Description:
683  *
684  *        This function receives the PDU from RLC 
685  *        and invokes the handler for processing the PDU.
686  *
687  *  @param[in] pjRbCb    -   PDCP RB Control Block
688  *  @param[in] mBuf    -   PDU
689  *
690  *  @return  S16
691  *      -# ROK 
692  *      -# RFAILED
693  *
694  */
695 #ifdef ANSI
696 PUBLIC S16 PjLiKwuDatAckInd
697 (
698 Pst           *pst,       /* Post */
699 SuId           suId,      /* Service User Id */
700 KwuDatAckInfo *ackInfo    /* Data Ack  Info */
701 )
702 #else
703 PUBLIC Void PjLiKwuDatAckInd(pst, suId, datCfm)
704 Pst           *pst;        /* Post */
705 SuId          suId;        /* Service User Id */
706 KwuDatAckInfo *ackInfo;    /* Data Ack Info */
707 #endif
708 {
709    RETVALUE(ROK);
710 } /* pjLimDatInd */
711 #endif
712
713 /**
714  *
715  * @brief 
716  *
717  *        Handler for getting the DiscSdu Cfm from RLC.
718  *
719  * @b Description:
720  *
721  *        This function receives the PDU from RLC 
722  *        and invokes the handler for processing the PDU.
723  *
724  *  @param[in] pjRbCb    -   PDCP RB Control Block
725  *  @param[in] mBuf    -   PDU
726  *
727  *  @return  S16
728  *      -# ROK 
729  *      -# RFAILED
730  *
731  */
732 #ifdef ANSI
733 PUBLIC S16 PjLiKwuDiscSduCfm
734 (
735 Pst           *pst,       /* Post */
736 SuId           suId,      /* Service User Id */
737 KwuDiscSduInfo *discInfo    /* Data Ack  Info */
738 )
739 #else
740 PUBLIC Void PjLiKwuDiscSduCfm(pst, suId, discInfo)
741 Pst           *pst;        /* Post */
742 SuId          suId;        /* Service User Id */
743 KwuDiscSduInfo *discInfo;    /* Data Ack Info */
744 #endif
745 {
746    S16         ret;           /* Return Value */
747    PjDlRbCb     *pjRbCb;
748    PjCb   *tPjCb;
749
750    TRC1(PjLiKwuDiscSduCfm);
751    tPjCb = PJ_GET_PJCB(pst->dstInst);
752
753
754    RLOG2(L_DEBUG, "PjLiKwuDiscSduCfm (rbId(%d),rbType (%d), mBuf)",
755                       discInfo->rlcId.rbId,discInfo->rlcId.rbType);
756
757    ret = pjDbmFetchDlRbCb (tPjCb,discInfo->rlcId,&pjRbCb);
758    if (ret != ROK)
759    {
760       RLOG_ARG2(L_ERROR, DBG_UEID,discInfo->rlcId.ueId, "CellId[%u]:DL RbId[%d] not found",
761             discInfo->rlcId.cellId, discInfo->rlcId.rbId);
762       PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, discInfo, sizeof(KwuDiscSduInfo));
763       RETVALUE(RFAILED);
764   }
765
766    pjLimDiscSduCfm(tPjCb, pjRbCb, discInfo);
767
768    PJ_FREE_SHRABL_BUF_PST(pst->region, pst->pool, discInfo, sizeof(KwuDiscSduInfo));
769
770    RETVALUE(ROK);
771 } /* pjLimDatInd */
772 \f
773 /**
774  *
775  * @brief 
776  *
777  *        Handler for getting the PDU from RLC.
778  *
779  * @b Description:
780  *
781  *        This function receives the PDU from RLC 
782  *        and invokes the handler for processing the PDU.
783  *
784  *  @param[in] pjRbCb    -   PDCP RB Control Block
785  *  @param[in] mBuf    -   PDU
786  *
787  *  @return  S16
788  *      -# ROK 
789  *      -# RFAILED
790  *
791  */
792 #ifdef ANSI
793 PUBLIC Void pjLimDatInd
794 (
795 PjCb          *gCb,
796 PjUlRbCb        *pjRbCb,        /* RB Control Block */
797 Buffer        *mBuf,           /* RLC PDU */
798 Bool          isOutOfSeq
799 )
800 #else
801 PUBLIC Void pjLimDatInd(gCb, pjRbCb, mBuf, isOutOfSeq)
802 PjCb          *gCb;
803 PjUlRbCb      *pjRbCb;        /* RB Control Block */
804 Buffer        *mBuf;          /* RLC PDU */
805 Bool           isOutOfSeq;
806 #endif
807 {
808 #if (ERRCLASS & ERRCLS_DEBUG)
809    S16         ret;           /* Return Value */
810 #endif
811
812    TRC3(pjLimDatInd);
813
814    PJ_STS_INC_GEN_CNT(gCb, rxPdus);
815
816    /* Extract the header */
817    if(pjRbCb->rbType == PJ_SRB)
818    {
819       if((pjRbCb->rbId == 1) || (pjRbCb->ueCb->libInfo.state == PJ_STATE_NORMAL))
820       {
821 #if (ERRCLASS & ERRCLS_DEBUG)
822          ret = pjUlmHdlSrbPkt(gCb, pjRbCb, mBuf);
823 #else
824          pjUlmHdlSrbPkt(gCb, pjRbCb, mBuf);
825 #endif
826       }
827       else
828       {
829          /* in reestablishment state */
830          PJ_FREE_BUF(mBuf);
831       }
832    }
833    else if(pjRbCb->rbType == PJ_DRB)
834    {
835 #if (ERRCLASS & ERRCLS_DEBUG)
836       ret = pjUlmHdlDrbPkt(gCb, pjRbCb, mBuf, isOutOfSeq);
837 #else
838       pjUlmHdlDrbPkt(gCb, pjRbCb, mBuf, isOutOfSeq);
839 #endif
840    }
841
842 #if (ERRCLASS & ERRCLS_DEBUG)
843    if (ret != ROK)
844    {
845       RLOG_ARG0(L_ERROR, DBG_RBID,pjRbCb->rbId, "pjLimDatInd: pjHdlProcessPdu Failed");
846    }
847 #endif
848
849    RETVOID;
850 } /* pjLimDatInd */
851
852 \f
853 /**
854  *
855  * @brief 
856  *
857  *        Handler for getting the Data Cfm from RLC.
858  *
859  * @b Description:
860  *
861  *        This function receives the Data Cfm from RLC 
862  *        and invokes the handler for processing it.
863  *
864  *  @param[in] pjRbCb    -   PDCP RB Control Block
865  *  @param[in] datCfm    -   Data Confirmation Information 
866  *
867  *  @return  S16
868  *      -# ROK 
869  *      -# RFAILED
870  *
871  */
872 #ifdef ANSI
873 PUBLIC Void pjLimDatCfm
874 (
875 PjCb          *gCb,
876 PjDlRbCb        *pjRbCb,     /* RB Control Block */
877 PjDatCfm      *datCfm      /* Data Confirmation Information */
878 )
879 #else
880 PUBLIC Void pjLimDatCfm(gCb, pjRbCb, datCfm)
881 PjCb          *gCb;
882 PjDlRbCb        *pjRbCb;     /* RB Control Block */
883 PjDatCfm      *datCfm;     /* Data Confirmation Information */
884 #endif
885 {
886 #if (ERRCLASS & ERRCLS_DEBUG)
887    S16         ret = ROK;  /* Return Value */
888 #endif
889
890    TRC3(pjLimDatCfm);
891
892
893    /* Process the PDU */
894 #if (ERRCLASS & ERRCLS_DEBUG)
895    ret = pjDlmProcessCfm(gCb, pjRbCb, datCfm, PJ_CFM_OK);
896    if (ret != ROK)
897    {
898       RLOG_ARG0(L_ERROR, DBG_RBID,pjRbCb->rbId, "pjLimDatCfm: pjDlmProcessCfm Failed");
899    }
900 #else
901    pjDlmProcessCfm(gCb, pjRbCb, datCfm, PJ_CFM_OK);
902 #endif
903    /* pj002.201 : Removed freeing and allocation of datCfm */
904    RETVOID;
905 } /* pjLimDatCfm */
906
907 \f
908 /**
909  *
910  * @brief 
911  *
912  *        Handler for trigerring the error indication when RLC times out
913  *        for sending AM data.
914  *
915  * @b Description:
916  *
917  *        This function receives the pduIds of the PDU that were not
918  *        successfully sent to the layer.
919  *
920  *  @param[in] pjRbCb  -   PDCP RB Control Block
921  *  @param[in] staInd  -   Status Indication Information.
922  *
923  *  @return  S16
924  *      -# ROK 
925  *      -# RFAILED
926  *
927  */
928 #ifdef ANSI
929 PUBLIC Void pjLimStaInd
930 (
931 PjCb         *gCb,
932 PjDlRbCb       *pjRbCb,            /* PDCP RB Control Block */
933 PjDatCfm     *staInd             /* Status Indication Information */
934 )
935 #else
936 PUBLIC Void pjLimStaInd(gCb, pjRbCb, staInd)
937 PjCb         *gCb;
938 PjDlRbCb       *pjRbCb;           /* PDCP RB control Block */
939 PjDatCfm     *staInd;           /* Status Indication Information */
940 #endif
941 {
942 #if (ERRCLASS & ERRCLS_DEBUG)
943    S16         ret = ROK;       /* Return Value */
944 #endif
945
946    TRC3(pjLimStaInd)
947
948    if (gCb->init.cfgDone == FALSE)
949    {
950       RETVOID;
951    }
952    RLOG1(L_DEBUG, "pjLimStaInd(pjRbCb(%d), staInd)", pjRbCb->rbId);
953
954    /* Call the confirm code */
955 #if (ERRCLASS & ERRCLS_DEBUG)
956    ret = pjDlmProcessCfm(gCb, pjRbCb, staInd, PJ_CFM_NOK);
957    if (ret != ROK)
958    {
959       RLOG_ARG0(L_ERROR, DBG_RBID,pjRbCb->rbId, "pjLimStaInd: pjDlmProcessCfm Failed");
960    }
961 #else
962    pjDlmProcessCfm(gCb, pjRbCb, staInd, PJ_CFM_NOK);
963 #endif
964    /* pj002.201 : Removed freeing and allocation of staInd */
965    RETVOID;
966 } /* pjLimStaInd */
967
968 \f
969 /**
970  *
971  * @brief 
972  *
973  *        Handler for informing the PDCP that RLC has successfully discarded
974  *        certain PDUs.
975  *
976  * @b Description:
977  *
978  *        This function receives the pointer to the PDCP control block of the
979  *        RB that has finished transmitting its data to PDCP.
980  *
981  *  @param[in] pjRbCb       -   PDCP RB Control Block
982  *  @param[in] discSduCfm   -   Info about the discarded SDUs
983  *
984  *  @return  S16
985  *      -# ROK 
986  *      -# RFAILED
987  *
988  */
989 #ifdef ANSI
990 PRIVATE S16 pjLimDiscSduCfm
991 (
992 PjCb       *gCb,
993 PjDlRbCb   *pjRbCb,        /* PDCP RB Control Block */
994 KwuDiscSduInfo *discSduCfm /* Info about the discarded SDUs*/
995 )
996 #else
997 PRIVATE S16 pjLimDiscSduCfm(gCb, pjRbCb, count)
998 PjCb       *gCb;
999 PjDlRbCb   *pjRbCb;         /* PDCP RB control Block */
1000 KwuDiscSduInfo *discSduCfm; /* Info about the discarded SDUs*/
1001 #endif
1002 {
1003    PjuDatCfmInfo datCfm;       /* DatCfm structure */
1004    CmLtePdcpId   pdcpId;       /* PDCP ID */
1005    PjTxEnt       *txEnt;        /* Transmission Entity */
1006    U32           count = 0;
1007    U16           cfmsToUpperLayer = 0;    /*KW_FIX*/
1008
1009    TRC3(pjLimDiscSduCfm);
1010
1011    RLOG1(L_DEBUG, "pjLimDiscSduCfm(pjRbCb(%d))", pjRbCb->rbId);
1012
1013    if((gCb->init.cfgDone == FALSE) || (discSduCfm->numSduIds == 0))
1014    {
1015       RETVALUE(ROK);
1016    }
1017    
1018    while(count < discSduCfm->numSduIds)
1019    {
1020       txEnt = pjDbmGetTxEnt(gCb, &(pjRbCb->dlCb.txBuf), discSduCfm->sduIds[count]); 
1021
1022       if(txEnt != NULLP)
1023       {
1024          if( pjRbCb->dlCb.cfmReqd)
1025          {
1026             datCfm.cfmSta[cfmsToUpperLayer].sduId  = txEnt->sduId;
1027             datCfm.cfmSta[cfmsToUpperLayer++].status = PJU_DISCARD_TMR_EXP;
1028          }
1029
1030          if( txEnt->pdu == txEnt->sdu )
1031          {
1032             txEnt->sdu = NULLP;
1033          }
1034
1035          /* if the PDU being discarded was a one for which confirm was expected
1036             then we need to set the confirm expectation correctly */
1037
1038          if(pjRbCb->dlCb.cfmExp < txEnt->count)
1039          {
1040             /* need to check if count should be just incremented by one or should the txHfn
1041                also need to be considered */
1042             pjRbCb->dlCb.cfmExp = txEnt->count + 1;
1043          }
1044          
1045          pjDbmDelTxEnt(gCb, &(pjRbCb->dlCb.txBuf), txEnt->count);
1046
1047 #ifdef LTE_L2_MEAS 
1048          PJ_UPD_L2_DLDISC_STS(gCb,pjRbCb);
1049 #endif
1050       }
1051
1052       count++;
1053    }
1054
1055    if(pjRbCb->dlCb.cfmReqd)
1056    {
1057       PjPjuSapCb    *pjuSap;       /* PJU SAP */
1058
1059       datCfm.numSdus = cfmsToUpperLayer;
1060
1061       pdcpId.rbId   = pjRbCb->rbId;
1062       pdcpId.rbType = pjRbCb->rbType;
1063       pdcpId.ueId   = pjRbCb->ueCb->key.ueId;
1064       pdcpId.cellId = pjRbCb->ueCb->key.cellId;
1065
1066       if (pjRbCb->rbType == PJ_SRB)
1067       {
1068          pjuSap = &(gCb->u.dlCb->pjuSap[PJ_SRB_SAP]);
1069       }
1070       else
1071       {
1072          pjuSap = &(gCb->u.dlCb->pjuSap[PJ_DRB_SAP]);
1073       }
1074
1075       /* If trace flag is enabled send the trace indication */
1076       if(gCb->init.trc == TRUE)
1077       {
1078          /* Populate the trace params */
1079          pjLmmSendTrc(gCb, EVTPJUDATCFM, NULLP);
1080       }
1081
1082       PjUiPjuDatCfm(&pjuSap->pst, pjuSap->suId, &pdcpId, &datCfm);
1083    }
1084
1085
1086    RETVALUE(ROK);
1087 } /* pjLimDiscSduCfm */
1088 #ifdef __cplusplus
1089 }
1090 #endif /* __cplusplus */
1091
1092 /********************************************************************30**
1093          End of file
1094 **********************************************************************/