Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_cfg_dl.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 - Configuration Manager file
22
23         Type:    C source file
24
25         Desc:    It contains the following configuraiton primtives
26                     -- pjCfgAddRb 
27                     -- pjCfgReCfgRb 
28                     -- pjCfgDelRb 
29                     -- pjCfgReEstRb 
30                     -- pjCfgDelUe 
31                     -- pjCfgPrcSecCfg 
32                     -- pjCfgUeIdChng 
33                     -- pjCfgPrcCount 
34                     -- pjCfgPrcSduSta 
35
36 *********************************************************************21*/
37 static const char* RLOG_MODULE_NAME="PDCP";
38 static int RLOG_MODULE_ID=1024;
39 static int RLOG_FILE_ID=212;
40 /** @file gp_pj_cfg.c
41 @brief LTE PDCP Configuration Module
42 **/
43
44 \f
45 /* header (.h) include files */
46 #include "envopt.h"             /* environment options */
47 #include "envdep.h"             /* environment dependent */
48 #include "envind.h"             /* environment independent */
49
50 #include "gen.h"                /* general */
51 #include "ssi.h"                /* system services interface */
52 #include "cm5.h"                /* Timer Functions */
53 #include "cm_lte.h"             /* common LTE header file */
54 #include "cm_hash.h"            /* common hash module  file */
55 #include "cm_llist.h"           /* common list header file */
56 #include "cpj.h"                /* RRC layer */
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_dl.h"
62 #include "pj_udx.h"
63 #include "pj_err.h"
64
65
66
67 /* header/extern include files (.x) */
68
69 #include "gen.x"                /* general */
70 #include "ssi.x"                /* system services interface */
71 #include "cm_lib.x"             /* common library */
72 #include "cm5.x"                /* Timer Functions */
73 #include "cm_hash.x"            /* common hash module */
74 #include "cm_lte.x"             /* common LTE file */
75 #include "cm_llist.x"           /* common list header file */
76 #include "cpj.x"                /* RRC layer */
77 #include "pju.x"                /* PDCP service user */
78 #include "lpj.x"                /* LM Interface */
79 #include "pj.x"                 /* RLC layer */
80 #include "pj_udx.x"
81 #include "pj_dl.x"
82
83 /* Proto types declarations for local functions */
84  
85 PRIVATE S16 pjCfgFillPjDlRbCb ARGS ((
86 PjCb                *gCb,
87 PjDlRbCb            *rbCb,
88 PjDlUeCb          *ueCb,
89 U8                 isHo,
90 UdxCfgEnt       *cfgEnt,
91 UdxCfmEnt       *cfmEnt
92 ));
93
94 PRIVATE S16 pjCfgUpdDlCompInfo  ARGS ((
95 PjCb                   *gCb, 
96 PjDlRbCb               *rbCb,
97 PjDlUeCb               *ueCb,
98 UdxHdrCompCfg        *rohcCfg
99 ));
100
101 #ifdef LTE_L2_MEAS
102 PRIVATE S16 pjAddToDlL2Meas ARGS ((
103 PjCb *gCb, 
104 PjDlRbCb *kwRbCb,
105 U8 cellId,
106 U16 ueId
107 ));
108 #endif
109 /* Store the Profile ID into array index */
110 /* RRC is not sending the profile id directly. It will give
111    the for all the profiles with True/False. PDCP will derive the profile
112    based on this profile Id list */
113
114 PRIVATE U16  rohcProfId[CPJ_MAX_ROHC_PROF_LIST]=    { 0x0001, 0x0002, 0x0003, 0x0004,
115                                               0x0006, 0x0101, 0x0102, 0x0103, 
116                                               0x0104};
117 /** @addtogroup cfgdata */
118 /*@{*/
119 /** 
120 * @brief
121
122 *   Hanlder to process the configuration recieved from the upper layer and update the pdcp
123 *   data base.
124 *
125 * @b Description: 
126 *     1. This function create a new  PDCP RB Cb. @n
127 *     2. Newly created PDCP RB Cb will be placed in Data base with the  configuration
128 *     informtion received.  @n
129 *     3. Return Success or Failure to the caller with reason and status
130 *     information. @n
131  
132  * @param [in]    ueId     -  UE Identifier
133  * @param [in]    cellId   -  CELL Identifier
134  * @param [in]    entCfg   -  Entity Configuration to be done.
135  * @param [out]   entCfm   -  Entity Confirmation.
136  * 
137  * @return  ROK
138  */
139 #ifdef ANSI
140 PUBLIC S16 pjCfgAddDlRb
141 (
142 PjCb              *gCb,
143 CmLteRnti         ueId,
144 CmLteCellId       cellId,
145 U8                 isHo,
146 UdxCfgEnt         *entCfg,
147 PjDlUeCb          **ueCb,
148 UdxCfmEnt         *entCfm
149 )
150 #else
151 PUBLIC S16 pjCfgAddDlRb (gCb, ueId, cellId,isHo, entCfg, ueCb, entCfm)
152 PjCb              *gCb;
153 CmLteRnti         ueId;
154 CmLteCellId       cellId;
155 U8                 isHo;
156 CpjCfgEnt         *entCfg;
157 PjDlUeCb          **ueCb; 
158 CpjCfmEnt         *entCfm;
159 #endif
160 {
161    S16               ret;
162    PjDlRbCb          *rbCb;  /* Rb Cb Pointer */
163
164    TRC3(pjCfgAddDlRb);  
165
166    /* Initialization */
167    ret  = ROK;
168
169    RLOG2(L_DEBUG, "pjCfgAddRb- Received with -- cellId(%d),ueId(%d)",
170                    cellId, ueId);
171
172    if( NULLP == *ueCb)
173    { 
174       /* Ue Cb is not present, Create Ue Cb */   
175       if ( pjDbmCreateDlUeCb(gCb, ueId, cellId, ueCb) != ROK)
176       {
177          /* Ue Cb allocation failed  */   
178          PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
179                CPJ_CFG_REAS_UE_CREAT_FAIL);
180
181          RLOG_ARG1(L_ERROR,DBG_UEID,ueId, "CellId[%d] Creating DL UeCb Failed",
182                             cellId);
183          RETVALUE(ret);
184       } 
185    }
186  
187    (*ueCb)->inst = gCb->init.inst;
188
189    /* Rb Id is allowed range or not */   
190    PJ_VALIDATE_RBID(ueId, entCfg->rbId, entCfg->rbType, ret);
191    if ( ROK != ret)
192    { 
193       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
194          CPJ_CFG_REAS_INVALID_RBID);
195
196       RLOG_ARG2(L_ERROR,DBG_UEID,ueId, "CellId[%u]:RbId[%d] - "
197             "Invalid RB ID,RbCb Creation Failed ", cellId, entCfg->rbId);
198       RETVALUE(ret);
199    }
200
201    /* Find Rb Cb already exist or not */   
202    PJ_DBM_FETCH_DL_RBCB(entCfg->rbId, entCfg->rbType, (*ueCb), rbCb);
203    if (NULLP != rbCb)
204    {
205       RLOG_ARG2(L_WARNING, DBG_UEID,ueId, "CellId [%u]:RbId[%d] already exists",
206             cellId,entCfg->rbId);
207       /* Rb Cb already exist for pdpcp */   
208       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
209             CPJ_CFG_REAS_SAME_RBID);
210
211       RLOG_ARG2(L_ERROR,DBG_UEID,ueId, "RB Id already present-- cellId(%d), rbId(%d)",
212                       cellId, entCfg->rbId);
213       RETVALUE(RFAILED);
214    }
215    else if (NULLP == rbCb)
216    {
217       /* Create Rb Cb and place in Ue Cb */   
218       rbCb =   pjDbmCreateDlRbCb(gCb, entCfg->rbId, entCfg->rbType, *ueCb, PJ_CFG_PDCP); 
219       if(NULLP == rbCb)
220       {
221          /* Create Rb Cb Failed*/   
222          PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
223                CPJ_CFG_REAS_ENT_CREAT_FAIL);
224
225          RLOG_ARG2(L_ERROR,DBG_UEID,ueId, "Failed to Create RB CB -- cellId(%d) rbId(%d)",
226                          cellId, entCfg->rbId);
227          RETVALUE(RFAILED);
228       } 
229    }
230
231    /* Copy the Recived information into RbCb */ 
232    ret = pjCfgFillPjDlRbCb(gCb, rbCb, *ueCb,isHo, entCfg , entCfm);
233
234    /* Fill the Cfm status and Reason */
235    PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_OK,\
236          CPJ_CFG_REAS_NONE);
237
238    RETVALUE(ret);
239 } /* pjCfgAddRb */
240
241 /**
242 * @brief 
243 *
244 *   Hanlder to update the PJRB with the received infromation during
245 *   configuration or re configuration. 
246 *
247 * @b Description: 
248 *     1. update the data base with the  new configuration informtion received.  @n
249 *     2. update the data base with the  new re-configuration informtion received.  @n
250 *     3. If required Initiliaze the tx/rx Buffers and Timers. @n
251 *     4. Return Success or Failure to the caller with reason and status
252 *     information. @n
253 *
254  * @param [out]   rbCb     -  RB Control Block
255  * @param [out]   entCfm   -  PDCP Entiry Confirmation 
256  * @param [in]    ueCb     -  UE Control Block
257  * @param [in]    entCfg   -  PDCP Entity Configuration
258  *
259  * @return  ROK
260  */
261 #ifdef ANSI
262 PRIVATE S16 pjCfgFillPjDlRbCb
263 (
264 PjCb            *gCb,
265 PjDlRbCb        *pjRbCb,
266 PjDlUeCb        *ueCb,
267 U8              isHo,
268 UdxCfgEnt       *cfgEnt,
269 UdxCfmEnt       *cfmEnt
270 )
271 #else
272 PRIVATE S16 pjCfgFillPjDlRbCb(gCb, pjRbCb, ueCb,isHo, cfgEnt, cfmEnt)
273 PjCb            *gCb;
274 PjDlRbCb        *pjRbCb;
275 PjDlUeCb        *ueCb;
276 U8              isHo,
277 CpjCfgEnt       *cfgEnt;
278 CpjCfmEnt       *cfmEnt;
279 #endif
280 {
281    S16            tmrVal;    /* Timer Value */
282    /* kw005.201 added support for L2 measurement */
283    TRC3(pjCfgFillPjDlRbCb);
284
285    /* Initialization */
286    tmrVal  = 0; 
287
288    RLOG_ARG3(L_DEBUG,DBG_UEID,ueCb->key.ueId, "Received Fill Req cellId(%d), rbId(%d),cfgType(%d)",
289                            ueCb->key.cellId,
290                        cfgEnt->rbId, cfgEnt->cfgType);
291
292    switch (cfgEnt->cfgType)
293    {
294       /* Cfg Type received as ADD RB */
295       case CPJ_CFG_ADD:
296          {
297             pjRbCb->state  =   PJ_STATE_NORMAL;
298             pjRbCb->rbId   =   cfgEnt->rbId;
299             pjRbCb->rbType =   cfgEnt->rbType;
300             pjRbCb->mode   =   cfgEnt->m.addCfg.rlcInfo.mode;
301             pjRbCb->dir    =   cfgEnt->m.addCfg.rlcInfo.dir;
302             pjRbCb->ueCb   =   ueCb;
303
304             if(PJ_SRB == pjRbCb->rbType)
305             {
306                /* SN length is fixed for SRB */
307                pjRbCb->snLen  = PJ_SRB_SN_LEN;
308                ueCb->numSrbs++;
309             }
310             else
311             {
312                if (CM_LTE_MODE_UM == pjRbCb->mode)
313                {
314                   /* SN length can be 12 bit or 18 bit in UM mode */
315                   pjRbCb->snLen  =   cfgEnt->m.addCfg.rlcInfo.m.rlcUm.pdcpSNSize;
316 #ifdef NR_PDCP_DRB_SN_18_BIT
317                   pjRbCb->snLen  =   PJ_18_BIT_SN;
318 #else
319                   pjRbCb->snLen  =   PJ_12_BIT_SN;
320 #endif
321                }
322                else
323                {
324                   /* SN length can be 12/18 bit for AM mode */
325                   pjRbCb->snLen  =   cfgEnt->m.addCfg.rlcInfo.m.rlcAm.pdcpSNSize;
326 #ifdef NR_PDCP_DRB_SN_18_BIT
327                   pjRbCb->snLen  =   PJ_18_BIT_SN;
328 #else
329                   pjRbCb->snLen  =   PJ_12_BIT_SN;
330 #endif
331                   if (isHo)
332                   {
333                      pjRbCb->state  =   PJ_STATE_HO;
334                   }
335                }
336                ueCb->numDrbs++;
337             }
338             pjRbCb->maxTxSn = (1 << pjRbCb->snLen);
339             /* Initialize all off board  timers */
340 #if (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC))
341             cmInitTimers(&pjRbCb->dlCb.obdTmr,PJ_RB_MAX_TIMERS); 
342 #endif                  
343
344             RLOG_ARG2(L_DEBUG,DBG_UEID,ueCb->key.ueId, 
345                   "Received RB Req with -- Dir(%d), mode(%d)",
346                        pjRbCb->dir, pjRbCb->mode);
347
348            
349             if (PJ_DIR_DL &  pjRbCb->dir)
350             {
351                pjRbCb->dlCb.discTmrInt = cfgEnt->m.addCfg.discardTmr;
352                pjRbCb->dlCb.cfmReqd    = cfgEnt->m.addCfg.cfmReqd;
353                /* pjRbCb->dlCb.count      = 0xffffffff; */
354
355                /* Discard Timer is Enabled */
356                if(pjRbCb->dlCb.discTmrInt > 0 )
357                {
358                   cmInitTimers(&pjRbCb->dlCb.discTmr,PJ_RB_MAX_TIMERS); 
359                   /* 1. The discTmr value is absolute value in ms units 
360                      2. Store the DiscardTmr value in terms of Layer resolution
361                      ie discTmrVal = dicTrmVal/(SS_TICKS*Layer Resolution) 
362                      and round to next integer value.
363                    */
364                   tmrVal = (S16)(pjRbCb->dlCb.discTmrInt % (SS_TICKS_SEC
365                         * gCb->pjGenCfg.timeRes));  /*KW_FIX*/
366                   pjRbCb->dlCb.discTmrInt = (S16)(pjRbCb->dlCb.discTmrInt / 
367                                             (SS_TICKS_SEC * gCb->pjGenCfg.timeRes));
368                   if(tmrVal)
369                      pjRbCb->dlCb.discTmrInt +=1; /* Round to next integer value if
370                                                      required */          
371                }
372
373                /*Initialization for Tx Buf */
374                gCb->pjGenCfg.nmbDlBins = PJ_MAX_HASH_BINS;
375                pjDbmDlBufInit(gCb, &pjRbCb->dlCb.txBuf,gCb->pjGenCfg.nmbDlBins);
376                cmLListInit(&pjRbCb->dlCb.dlPktQ);
377             }
378
379             /* Update the Compressor Informatio in Rb Cb */
380             if(cfgEnt->rbType == CM_LTE_DRB)
381             {
382                pjCfgUpdDlCompInfo(gCb, pjRbCb, ueCb,&(cfgEnt->m.addCfg.hdrCompCfg));
383 /* kw005.201 added support for L2 measurement */
384 #ifdef LTE_L2_MEAS
385                pjRbCb->qci =  cfgEnt->m.addCfg.qci;
386                pjAddToDlL2Meas(gCb,pjRbCb,
387                                ueCb->key.cellId,ueCb->key.ueId); 
388 #endif
389             }
390
391             break;
392          }
393
394          /* Cfg Type received as Modify RB */
395       case CPJ_CFG_MODIFY:
396          {
397             if(CPJ_RECFG_CFMREQ & cfgEnt->m.modCfg.bitFlag)
398                pjRbCb->dlCb.cfmReqd    = cfgEnt->m.modCfg.cfmReqd;
399
400             /* Header Compression profile has been modified */
401
402             if(TRUE == cfgEnt->m.modCfg.hdrCompCfg.hdrCompUsed)
403             {
404                /* Close All the channels */
405                pjUtlDlCmpReset(gCb, pjRbCb); 
406                pjCfgUpdDlCompInfo(gCb, pjRbCb, ueCb, &cfgEnt->m.modCfg.hdrCompCfg);
407             }
408
409             /* In case of Hand off scenario: At Target eNode-B, 
410                Handoff information will send in re-cfg req */
411
412             if(TRUE  & cfgEnt->m.modCfg.hoInfo.isHoPres)
413             {
414                /* Store the HO information  and call for Status Report
415                 * Generation also */
416                if(CPJ_HO_DL & cfgEnt->m.modCfg.hoInfo.isHoPres)
417                {
418                   pjRbCb->dlCb.count = cfgEnt->m.modCfg.hoInfo.dlCount - 1;
419                   if (pjRbCb->snLen != cfgEnt->m.modCfg.hoInfo.snLen)
420                   {
421                      pjRbCb->snLen = cfgEnt->m.modCfg.hoInfo.snLen;
422                   }
423                }
424                pjDlmProcessDlPktQ(gCb, pjRbCb);
425                pjRbCb->state = PJ_STATE_NORMAL;
426             }
427
428             break;
429          }
430
431          /* Un Expected cfg type */
432       default:
433          {
434             RLOG_ARG1(L_ERROR,DBG_CELLID, ueCb->key.cellId, 
435                   "pjCfgFillRbCb Failed -- for the invalid cfgType(%d)",
436                      cfgEnt->cfgType);
437          }
438    }
439    RETVALUE(ROK);
440 } /* pjCfgFillPjRbCb */
441
442
443 \f
444 /**
445 * @brief 
446 *
447 *   Hanlder to process the re-configuration for existing PJRB from the upper
448 *   layer.
449 *
450 * @b Description: 
451 *     1. This function fetch the PJRB from pdcp data base. @n
452 *     2. update the data base with the  new configuration informtion received.  @n
453 *     3. Return Success or Failure to the caller with reason and status
454 *     information. @n
455 *
456 * @param [in]    gCb      -  PDCP Instance Control block
457 * @param [in]    ueId     -  UE Identifier
458 * @param [in]    cellId   -  CELL Identifier
459 * @param [in]    entCfg   -  Entity Configuration to be done.
460 * @param [out]   entCfm   -  Entity Confirmation.
461
462 * @return  ROK
463 *
464 */
465 #ifdef ANSI
466 PUBLIC S16 pjCfgReCfgDlRb
467 (
468 PjCb              *gCb,
469 PjDlUeCb          *ueCb,
470 UdxCfgEnt         *entCfg,
471 UdxCfmEnt         *entCfm
472 )
473 #else
474 PUBLIC S16 pjCfgReCfgDlRb (gCb,ueCb, entCfg, entCfm)
475 PjCb              *gCb;
476 PjDlUeCb          *ueCb;
477 UdxCfgEnt         *entCfg;
478 UdxCfmEnt         *entCfm;
479 #endif
480 {
481    S16       ret;
482    PjDlRbCb     *rbCb;    /* Rb Cb */
483
484    TRC3(pjCfgReCfgDlRb);
485
486    /* Initialization */
487    ret  = ROK;
488
489    RLOG2(L_DEBUG, "pjCfgReCfgRb - Received for -- cellId(%d),ueId(%d)",
490                           ueCb->key.cellId, ueCb->key.ueId);
491
492    /* Fetch Rb Cb */
493    PJ_DBM_FETCH_DL_RBCB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
494    /* Rb Cb is not present or Rb Cb is not configured for PDCP */
495    if( NULLP == rbCb)
496    { 
497       RLOG_ARG2(L_ERROR, DBG_UEID,ueCb->key.ueId, "CellId [%u]:RbId[%d] already exists",
498             ueCb->key.cellId,entCfg->rbId);
499       /* Fill entCfm structure */
500       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
501             CPJ_CFG_REAS_PDCPID_UNKWN);
502
503       RLOG_ARG2(L_ERROR,DBG_UEID,ueCb->key.ueId, 
504             "RB Cb is not present -- cellId(%d), rbId(%d)",
505                           ueCb->key.cellId, entCfg->rbId);
506       RETVALUE(RFAILED);
507    }
508
509    /* Copy the received infromation in to Rb Cb */
510    ret = pjCfgFillPjDlRbCb(gCb, rbCb, ueCb,FALSE, entCfg , entCfm);
511
512    /* Fill the Cfm status and Reason */
513    PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_OK,\
514          CPJ_CFG_REAS_NONE);
515
516
517    RETVALUE(ret);
518 } /* pjCfgReCfgRb */
519
520 \f
521 /**
522 * @brief
523 *  This function deletes the existing RB(PDCP and RLC) from  Ue Cb.
524 *
525 * @b Description:
526 *    1. Stop the timers and deallocate tx/rx Buffs for PJRB CB. @n
527 *    2. Delete the existing RB Cb(PDCP and RLC)  from Ue Cb. @n
528 *
529 * @param [in]    ueId     -  UE Identifier
530 * @param [in]    cellId   -  CELL Identifier
531 * @param [in]    entCfg   -  Entity Configuration to be done.
532 * @param [out]   entCfm   -  Entity Confirmation.
533
534 * @return  ROK
535 *
536 */
537 #ifdef ANSI
538 PUBLIC S16 pjCfgDelDlRb
539 (
540 PjCb              *gCb,
541 PjDlUeCb          *ueCb,
542 UdxCfgEnt         *entCfg,
543 UdxCfmEnt         *entCfm
544 )
545 #else
546 PUBLIC S16 pjCfgDelDlRb (gCb, ueCb, entCfg, entCfm)
547 PjCb              *gCb;
548 PjDlUeCb          *ueCb;
549 UdxCfgEnt         *entCfg;
550 UdxCfmEnt         *entCfm;
551 #endif
552 {
553    S16      ret;
554    PjDlRbCb     *rbCb;    /* Rb Cb */
555
556    TRC3(pjCfgDelDlRb);
557
558    /* Initialization */
559    ret = ROK;
560
561    RLOG2(L_DEBUG, "pjCfgDelRb- Received for -- cellId(%d),ueId(%d)",
562                           ueCb->key.cellId,ueCb->key.ueId);
563
564    /* Fetch RB Cb */
565    PJ_DBM_FETCH_DL_RBCB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
566
567    /* RB Cb is not present   or not configured for PDCP */
568    if (NULLP == rbCb) 
569    { 
570       RLOG_ARG2(L_ERROR, DBG_UEID,ueCb->key.ueId, "CellId [%u]:RbId[%d] already exists",
571             ueCb->key.cellId,entCfg->rbId);
572       /* Fill entCfm structure with invalid pdcp Id */
573       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
574             CPJ_CFG_REAS_INVALID_PDCPID);
575
576       RLOG_ARG2(L_ERROR,DBG_UEID,ueCb->key.ueId, 
577             "RB Cb is not found, Deletion Failed -- cellId(%d), rbId(%d)",
578                           ueCb->key.cellId, entCfg->rbId);
579       RETVALUE(RFAILED);
580    }
581    /* Delete PDCP Related infromation from RB CB */
582    ret= pjCfgDelPjDlRbCb(gCb, ueCb, rbCb); 
583
584    if(ROK != ret)
585    {
586       /* Fill entCfm structure with invalid pdcp Id */
587       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
588             CPJ_CFG_REAS_INVALID_PDCPID);
589
590       RLOG_ARG2(L_ERROR,DBG_UEID,ueCb->key.ueId, 
591             "RB Cb Deletion Failed -- cellId(%d), rbId(%d)",
592                           ueCb->key.cellId, entCfg->rbId);
593       RETVALUE(ret);
594    }
595    rbCb->pktAdmitCnt= 0;
596    /* Fill the Cfm status and Reason */
597    PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_OK,\
598          CPJ_CFG_REAS_NONE);
599
600
601    RETVALUE(ret);
602 } /* pjCfgDelRb */
603
604
605
606 \f
607 /**
608 *  @brief
609 *
610 *   This primitive is used to re-establish downlink SRB2 and/or DRB'S during RRC connection
611 *   re-configuration procedure.
612 *  
613 *  @b Description:
614 *  1. This function will trigger re-establishment for SRB2 and/or DRB's
615 *
616 * @param [in]    gCb      -  PDCP Instance Control block
617 * @param [in]    ueId     -  UE Identifier
618 * @param [in]    cellId   -  CELL Identifier
619 * @param [in]    entCfg   -  Entity Configuration to be done.
620 * @param [out]   entCfm   -  Entity Configuration cfm.
621
622 * @return  ROK
623 *
624 */
625 #ifdef ANSI
626 PUBLIC S16 pjCfgReEstDlRb
627 (
628 PjCb              *gCb,
629 PjDlUeCb          *ueCb,
630 UdxCfgEnt         *entCfg,
631 UdxCfmEnt         *entCfm
632 )
633 #else
634 PUBLIC S16 pjCfgReEstDlRb (gCb,ueCb, entCfg, entCfm)
635 PjCb              *gCb;
636 PjDlUeCb          *ueCb;
637 UdxCfgEnt         *entCfg;
638 UdxCfmEnt         *entCfm;
639 #endif
640 {
641    S16    ret;
642    PjDlRbCb   *rbCb;   /* Rb Cb */
643
644    TRC3(pjCfgReEstDlRb); 
645
646    /* Initialization */
647    ret  = ROK;
648
649    RLOG2(L_DEBUG, "pjCfgReEstRb- Received for -- cellId(%d),ueId(%d)",
650                          ueCb->key.cellId, ueCb->key.ueId);
651
652    /* Fetch Rb Cb */
653    PJ_DBM_FETCH_DL_RBCB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
654    /* Rb Cb is not present or Rb Cb is not configured for PDCP */
655    if( NULLP == rbCb )
656    { 
657       RLOG_ARG2(L_ERROR, DBG_UEID,ueCb->key.ueId, "CellId [%u]:RbId[%d] already exists",
658             ueCb->key.cellId,entCfg->rbId);
659       /* Fill entCfm structure with invalid PDCP Id*/
660       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
661             CPJ_CFG_REAS_PDCPID_UNKWN);
662
663       RLOG_ARG1(L_ERROR,DBG_UEID,ueCb->key.ueId, 
664             "Re-Est Failed : DL RB CB is not present -- cellId(%d)",
665                           ueCb->key.cellId);
666
667       RETVALUE(RFAILED);
668    }
669
670    /* A Cfm with failure is sent if the re-establishment comes when RBs are not in
671       re-est state */
672    if (ueCb->libInfo.state != PJ_STATE_REEST )
673    {
674       /* Fill entCfm structure with invalid PDCP Id*/
675       PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_NOK,\
676             CPJ_CFG_REAS_INVALID_STATE);
677
678       RLOG_ARG1(L_ERROR,DBG_UEID,ueCb->key.ueId, 
679             "Re-Est Failed : RB State is Not REEST -- cellId(%d)",
680                           ueCb->key.cellId);
681       RETVALUE(RFAILED);
682    }
683
684    /* 5. Call the respective reestablishment functions for SRB */
685    if(rbCb->rbType == PJ_SRB)
686    {
687       pjDlmReEstSrb(gCb,rbCb);
688    }
689    else /* PJ_DRBs */
690    {
691       /* During Re-Establishment DL RAB state is assumed to be in PJ_STATE_NORMAL
692        * and the Status Report is sent only if this is the state.
693        * But if the Reestablishment happens during HO(PJ_STATE_REEST_HO) 
694        * due to the state change during HO no Status Report is sent after successful
695        * Re-establishment
696        */
697       rbCb->state = PJ_STATE_NORMAL;
698       rbCb->pktAdmitCnt = 0;
699       if (rbCb->mode == PJ_DRB_UM)
700       {
701           pjDlmReEstDrbUm(gCb,rbCb);
702       }
703       else
704       {
705         pjDlmReEstDrbAm(gCb,rbCb);
706       }
707    }/* if(rbType == .... */
708
709    RETVALUE(ret);
710 } /* pjCfgReEstRb */
711
712
713 \f
714 /**
715 * @brief
716 * This primitive Delete Ue Cb from PDCP/RLC data base.
717 *
718 * @b Description:
719 *  1. This primitive Delete the Ue Cb from PDCP/RLC Data base.
720 *
721 * @param [in]    ueId     -  UE Identifier
722 * @param [in]    cellId   -  CELL Identifier
723 * @param [in]    entCfg   -  Entity Configuration to be done.
724 * @param [out]   entCfm   -  Entity Confirmation.
725
726 * @return  ROK
727 *
728 */
729 #ifdef ANSI
730 PUBLIC S16 pjCfgDelDlUe
731 (
732 PjCb              *gCb,
733 PjDlUeCb          *ueCb,
734 UdxCfgEnt         *entCfg,
735 UdxCfmEnt         *entCfm
736 )
737 #else
738 PUBLIC S16 pjCfgDelDlUe (gCb, ueCb, entCfg, entCfm)
739 PjCb              *gCb;
740 PjDlUeCb          *ueCb;
741 UdxCfgEnt         *entCfg;
742 UdxCfmEnt         *entCfm;
743 #endif
744 {
745    TRC3(pjCfgDelDlUe);
746
747    RLOG_ARG1(L_DEBUG,DBG_UEID,ueCb->key.ueId, 
748          "pjCfgDelUe- Received for -- cellId(%d)",
749                           ueCb->key.cellId);
750
751    /* Delete Ue Cb */
752    pjDbmDelDlUeCb(gCb, ueCb, FALSE);
753
754    /* Fill the Cfm */
755    PJ_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CPJ_CFG_CFM_OK,\
756          CPJ_CFG_REAS_NONE);
757
758    RETVALUE(ROK);
759 } /* pjCfgDelUe */
760
761 \f
762 /**
763 * @brief
764 * This primitive configure the security information of an Ue Cb.
765 *
766 * @b Description:
767 *  1. This primitive  configure the security information of an Ue Cb.
768 *  2. Initilize  the  Integrity/Ciphering Channels if required.
769 *
770 * @param [in]    secCfg   -  Entity Configuration to be done.
771 * @param [out]   secCfm   -  Entity Configuration Cfm done.
772
773 * @return  ROK
774 *
775 */
776 #ifdef ANSI
777 PUBLIC S16 pjCfgPrcSecDlCfg
778 (
779 PjCb             *gCb,
780 UdxSecCfgReqInfo *secCfg,
781 UdxSecCfgCfmInfo *cfgCfm
782 )
783 #else
784 PUBLIC S16 pjCfgPrcSecDlCfg (gCb, secCfg, cfgCfm)
785 PjCb              *gCb;
786 UdxSecCfgReqInfo  *secCfg;
787 UdxSecCfgCfmInfo  *cfgCfm;
788 #endif
789 {
790    S16     ret;
791    PjDlUeCb *ueCb;
792
793    TRC3(pjCfgPrcSecDlCfg);
794
795    /* Initialization */
796    ret  = ROK;
797    ueCb = NULLP;
798
799    RLOG2(L_DEBUG, "pjCfgPrcSecCfg- Received for -- cellId(%d),ueId(%d)",
800                           secCfg->cellId, secCfg->ueId);
801
802    /* Fetch Ue Cb */
803    ret = pjDbmFetchDlUeCb(gCb, secCfg->ueId, secCfg->cellId, &ueCb);
804
805    /* Ue Cb is not present */
806    if( ROK != ret || NULLP == ueCb)
807    { 
808       RLOG_ARG1(L_ERROR, DBG_CELLID, secCfg->cellId,"UeId[%u] not found",
809             secCfg->ueId);
810       /* Fill entCfm structure */
811       PJ_CFG_FILL_SECCFG_CFM(cfgCfm, secCfg->ueId,secCfg->cellId,secCfg->transId,\
812             CPJ_CFG_CFM_NOK,CPJ_CFG_REAS_UE_UNKWN);
813       RETVALUE(ret);
814    }
815
816    ueCb->secInfo.selSecAct= secCfg->secCfg.selSecAct;
817
818    /* Store Integrity Information */
819    ueCb->secInfo.intInfo.algoType=secCfg->secCfg.integInfo.algoType;
820    cmMemcpy(&ueCb->secInfo.intInfo.intKey[0], &secCfg->secCfg.integInfo.intKey[0], CPJ_INTG_KEY_LEN);
821
822    /* Store Ciphering Informaiton */
823    ueCb->secInfo.cipherInfo.algoType=secCfg->secCfg.cipherInfo.algoType; 
824
825    cmMemcpy(ueCb->secInfo.cipherInfo.cpKey,
826          &secCfg->secCfg.cipherInfo.ctrlplnKey[0],CPJ_CIPHER_KEY_LEN);
827
828    cmMemcpy(ueCb->secInfo.cipherInfo.upKey,
829          &secCfg->secCfg.cipherInfo.usrplnKey[0],CPJ_CIPHER_KEY_LEN);
830
831    /* Security Activation Done */
832    ueCb->secInfo.secAct = TRUE;
833
834    if(TRUE == secCfg->secCfg.isHo)
835    {
836       ueCb->secInfo.firstMsg   =  FALSE;
837    }
838    else
839    {
840       ueCb->secInfo.firstMsg   =  TRUE;
841    }
842
843    ueCb->secInfo.secCxt.cellId = secCfg->cellId;
844    ueCb->secInfo.secCxt.ueId   = secCfg->ueId;
845    ueCb->secInfo.secCxt.dir    = PJ_SEC_DIR_DL;
846
847 #ifndef ALIGN_64BIT
848    RLOG_ARG3(L_DEBUG,DBG_UEID,secCfg->ueId, 
849          "Security Paramters stored in UE CB are -- cellId(%d)"  
850          "Integrity Algo(%ld), cipherAlgoType(%ld) ",
851          secCfg->cellId, ueCb->secInfo.intInfo.algoType,
852          ueCb->secInfo.cipherInfo.algoType);
853 #else
854    RLOG_ARG3(L_DEBUG,DBG_UEID,secCfg->ueId, 
855          "Security Paramters stored in UE CB are -- cellId(%d)"  
856          "Integrity Algo(%d), cipherAlgoType(%d) ",
857          secCfg->cellId, ueCb->secInfo.intInfo.algoType,
858          ueCb->secInfo.cipherInfo.algoType);
859 #endif
860    /* Open the Security Channels */
861
862    if(ueCb->secInfo.secAct)
863    {
864
865 #ifdef PJ_SEC_ASYNC
866       ueCb->secInfo.secCxt.cfgTxId = ueCb->libInfo.nxtAvlbTxId;
867 #endif 
868
869       ret = pjUtlDlIntInit(gCb, ueCb);
870
871       /* Integrity Init failed */
872       if(ROK != ret)
873       {
874          PJ_CFG_FILL_SECCFG_CFM(cfgCfm, secCfg->ueId,secCfg->cellId,secCfg->transId,\
875                CPJ_CFG_CFM_NOK,CPJ_CFG_REAS_INTINIT_FAILED);
876
877          RETVALUE(ret);
878
879       }
880       ret = pjUtlDlCpInit(gCb, ueCb);
881       /* Ciphering Control Plane Init failed */
882       if(ROK != ret)
883       {
884          PJ_CFG_FILL_SECCFG_CFM(cfgCfm, secCfg->ueId,secCfg->cellId,secCfg->transId,\
885                CPJ_CFG_CFM_NOK,CPJ_CFG_REAS_CCIPHR_FAILED);
886
887          RETVALUE(ret);
888
889       }
890       ret = pjUtlDlUpInit(gCb, ueCb);
891
892       /* Ciphering User Plane Init failed */
893       if(ROK != ret)
894       {
895          PJ_CFG_FILL_SECCFG_CFM(cfgCfm, secCfg->ueId,secCfg->cellId,secCfg->transId,\
896                CPJ_CFG_CFM_NOK,CPJ_CFG_REAS_UCIPHR_FAILED);
897
898          RETVALUE(ret);
899       }
900    }
901
902    /* Fill Cfg Cfm with Status OK */
903    PJ_CFG_FILL_SECCFG_CFM(cfgCfm, secCfg->ueId,secCfg->cellId,secCfg->transId,\
904          CPJ_CFG_CFM_OK,CPJ_CFG_REAS_NONE);
905
906    RETVALUE(ROK);
907 } /* pjCfgPrcSecCfg */
908
909 \f
910 /**
911 * @brief
912 * This primitive changes the ueId of existing Ue Cb.
913
914 * @b Description:
915 *
916 *    1. This function delete the UeCb from hashList. @n
917 *    2. Update the Ue Cb with the new Keys. @n
918 *    3. Insert the UeCb in hash list with new Key.  @n
919 *
920 * @param [in]    ueInfo      -  Old UE Information
921 * @param [in]    newUeInfo   -  New UE Information
922 * @param [out]   status      -  Status
923
924 * @return  ROK
925 *
926 */
927 #ifdef ANSI
928 PUBLIC S16 pjCfgDlUeIdChng
929 (
930 PjCb      *gCb,
931 UdxUeInfo *ueInfo,
932 UdxUeInfo *newUeInfo,
933 CmStatus  *status
934 )
935 #else
936 PUBLIC S16 pjCfgDlUeIdChng (gCb, ueInfo, newUeInfo, status)
937 PjCb      *gCb;
938 UdxUeInfo *ueInfo;
939 UdxUeInfo *newUeInfo;
940 CmStatus  *status;
941 #endif
942 {
943    PjDlUeCb *ueCb;
944    S16    ret;
945
946    TRC3(pjCfgDlUeIdChng)
947
948    ueCb = NULLP;
949    ret= ROK;
950
951    RLOG2(L_DEBUG, "pjCfgUeIdChng- Recived for -- cellId(%d),ueId(%d)",
952                           ueInfo->cellId, ueInfo->ueId);
953
954    if ( (ueInfo->ueId == newUeInfo->ueId) && 
955         (ueInfo->cellId == newUeInfo->cellId))
956    {
957       status->reason = CPJ_CFG_REAS_SAME_UEID;
958       status->status = CPJ_CFG_CFM_NOK; 
959       RLOG_ARG2(L_ERROR,DBG_CELLID,ueInfo->cellId,"Old UeId[%d] same as new UeId[%d]",
960             ueInfo->ueId,newUeInfo->ueId);
961       RETVALUE(RFAILED);
962    } 
963    
964    ret = pjDbmFetchDlUeCb(gCb, newUeInfo->ueId, newUeInfo->cellId, &ueCb);
965    if (ret == ROK)
966    {
967       RLOG_ARG1(L_ERROR, DBG_CELLID, newUeInfo->cellId, "NewUeId[%d]:ueCb already exists",
968             newUeInfo->ueId);
969       status->reason = CPJ_CFG_REAS_SAME_UEID;
970       status->status = CPJ_CFG_CFM_NOK;
971       RETVALUE(RFAILED);
972    }
973   
974    ret = pjDbmFetchDlUeCb(gCb, ueInfo->ueId, ueInfo->cellId, &ueCb);
975    if (ret != ROK)
976    {
977       RLOG_ARG1(L_ERROR,DBG_CELLID,ueInfo->cellId,"UeId [%d]: UeCb not found",
978             ueInfo->ueId);
979       status->reason = CPJ_CFG_REAS_UE_UNKWN;
980       status->status = CPJ_CFG_CFM_NOK;
981       RETVALUE(RFAILED);
982    }
983   
984    ret = cmHashListDelete(&(gCb->u.dlCb->ueLstCp), (PTR) ueCb);
985    if (ret != ROK)
986    {
987       RLOG_ARG1(L_ERROR,DBG_CELLID,ueInfo->cellId,"UeId[%u] HashList Deletion Failed",
988             ueInfo->ueId);
989       status->reason = CPJ_CFG_REAS_UE_CREAT_FAIL;
990       status->status = CPJ_CFG_CFM_NOK;
991       RETVALUE(RFAILED);
992    }
993    
994    /* update the hash key with new values */ 
995    ueCb->key.ueId = newUeInfo->ueId;
996    ueCb->key.cellId = newUeInfo->cellId;
997
998    ret = cmHashListInsert(&(gCb->u.dlCb->ueLstCp), (PTR)ueCb, 
999                             (U8 *)&(ueCb->key), (U16) sizeof(PjUeKey));
1000
1001    if (ret != ROK)
1002    {
1003       RLOG_ARG1(L_ERROR,DBG_CELLID,newUeInfo->cellId,"UeId[%u] HashList Insertion Failed",
1004             newUeInfo->ueId);
1005       status->reason = CPJ_CFG_REAS_UE_CREAT_FAIL;
1006       status->status = CPJ_CFG_CFM_NOK;
1007    }  
1008   
1009    RETVALUE(ret);
1010 } /* pjCfgUeIdChng */
1011
1012 \f
1013 /**
1014 * @brief
1015 * This primitive reports the Count informatin of all RBs of an Ue Cb.
1016 *
1017 * @b Description:
1018 * 1. This function reports the count information of all the RBs of an UE. 
1019 *
1020 * @param [in]    ueId     -  UE Identifier
1021 * @param [in]    cellId   -  CELL Identifier
1022 * @param [out]   countCfm -  Count Information
1023
1024 * @return  ROK
1025 *
1026 */
1027 #ifdef ANSI
1028 PUBLIC S16 pjCfgPrcDlCount
1029 (
1030 PjCb            *gCb,
1031 UdxCountReqInfo *countReq,
1032 UdxCountCfmInfo       *countCfm
1033 )
1034 #else
1035 PUBLIC S16 pjCfgPrcDlCount (gCb, countReq, countCfm)
1036 PjCb            *gCb;
1037 UdxCountReqInfo *countReq;
1038 UdxCountCfmInfo       *countCfm;
1039 #endif
1040 {
1041    S16     ret;
1042    PjDlUeCb  *ueCb;
1043    PjDlRbCb    *rbCb;
1044    U8      numRb;
1045    U8      idx;
1046
1047    TRC3(pjCfgPrcDlCount); 
1048
1049    /* Initialization */
1050    ueCb   = NULLP;
1051    rbCb   = NULLP;
1052    ret    = ROK;
1053    numRb  = 0;
1054    idx  = 0;
1055
1056    RLOG2(L_DEBUG, "pjCfgPrcCount - Count Request Received for - cellId(%d),ueId(%d)",
1057                           countReq->cellId, countReq->ueId);
1058
1059    /* Fetch  ue Cb */
1060    ret = pjDbmFetchDlUeCb(gCb, countReq->ueId, countReq->cellId, &ueCb);
1061    countCfm->ueId = countReq->ueId;
1062    countCfm->cellId = countReq->cellId;
1063    countCfm->transId = countReq->transId;
1064
1065    /* Ue Cb is not present */
1066    if( ROK != ret || NULLP == ueCb)
1067    { 
1068       RLOG_ARG1(L_ERROR, DBG_CELLID, countCfm->cellId,"UeId[%u] not found",countCfm->ueId);
1069       /* Fill entCfm structure */
1070       countCfm->numRb  = numRb;
1071       countCfm->status = CPJ_CFG_CFM_NOK;
1072       countCfm->reason = CPJ_CFG_REAS_UE_UNKWN;
1073       RETVALUE(ret);
1074    }
1075
1076    /* Loop through all DRBs  */
1077    for(numRb=0, idx=0; idx < PJ_MAX_DRB_PER_UE && numRb < UDX_MAX_DRB; idx++)  /* KW_FIX */
1078    {
1079       rbCb = ueCb->drbCb[idx];
1080       /* RB is present and configured for PDCP Layer */
1081       if(NULLP != rbCb)
1082       {
1083          countCfm->countInfo[numRb].rbId= rbCb->rbId; 
1084          countCfm->countInfo[numRb].dir = rbCb->dir; 
1085          countCfm->countInfo[numRb].dlCount= rbCb->dlCb.count; 
1086          countCfm->countInfo[numRb].ulCount= 0; 
1087          numRb++;
1088       }
1089    }
1090
1091    /* Fill CountCfm with status and reason */
1092    countCfm->numRb  = numRb;
1093    if(numRb)
1094    {
1095       countCfm->status =CPJ_CFG_CFM_OK;
1096       countCfm->reason =CPJ_CFG_REAS_NONE;
1097    }
1098    else
1099    {
1100       countCfm->status =CPJ_CFG_CFM_NOK;
1101       countCfm->reason =CPJ_CFG_REAS_NO_DRBS;
1102
1103    }
1104
1105    RETVALUE(ret);
1106 } /* pjCfgPrcCount */
1107
1108 /**
1109 * @brief
1110 * This primitive reports SDU status information of all RBs of an Ue Cb.
1111 *
1112 * @b Description:
1113 *  1. This primitive Trigger the Handoff Request procedure 
1114 *
1115 * @param [in]    ueId      -  UE Identifier
1116 * @param [in]    cellId    -  CELL Identifier
1117 * @param [out]   sduStaCfm -  SDU Status Information
1118
1119 * @return  ROK
1120 *
1121 */
1122 #ifdef ANSI
1123 PUBLIC S16 pjCfgPrcDlSduSta
1124 (
1125 PjCb                 *gCb,
1126 UdxSduStaReqInfo     *staReq
1127 )
1128 #else
1129 PUBLIC S16 pjCfgPrcDlSduSta (gCb, staReq)
1130 PjCb                 *gCb;
1131 UdxSduStaReqInfo     *staReq;
1132 #endif
1133 {
1134    S16      ret;
1135    PjDlUeCb  *ueCb;
1136    U8 rbCnt;
1137    U8 numRb = 0;
1138    UdxSduStaInfo  *staInfo;
1139    PjDlHoCfmInfo *hoCfmInfo;
1140    UdxSduStaCfmInfo *cfmInfo;
1141    PjUdxDlSapCb      *udxSap; 
1142
1143    TRC3(pjCfgPrcDlSduSta);
1144
1145    /* Initialization */
1146    ret  = ROK;
1147    ueCb = NULLP;
1148
1149    RLOG2(L_DEBUG, "pjCfgPrcSduSta - Received for -- cellId(%d),ueId(%d)",
1150                           staReq->cellId, staReq->ueId);
1151
1152    /* Memory leak fix ccpu00135359 */
1153    udxSap = &(gCb->u.dlCb->udxDlSap[0]);
1154    PJ_ALLOC_BUF_SHRABL(udxSap->pst, cfmInfo, 
1155       sizeof (UdxSduStaCfmInfo), ret);
1156    if(ret != ROK)
1157    {  
1158 #if (ERRCLASS & ERRCLS_DEBUG)    /*KW_FIX*/
1159       RLOG0(L_FATAL, "Memory Allocation failed.");
1160       /*ccpu00136858 */      
1161       PJ_PST_FREE(gCb->u.dlCb->udxDlSap[0].pst.region,
1162                   gCb->u.dlCb->udxDlSap[0].pst.pool, 
1163                    staReq, sizeof(UdxSduStaReqInfo));
1164 #endif
1165          RETVALUE(RFAILED);
1166    }
1167    cfmInfo->ueId = staReq->ueId;
1168    cfmInfo->cellId = staReq->cellId;
1169    cfmInfo->transId = staReq->transId;
1170    cfmInfo->status = CPJ_CFG_CFM_OK; 
1171
1172    /* Fetch Ue Cb */
1173    ret = pjDbmFetchDlUeCb(gCb, staReq->ueId, staReq->cellId, &ueCb);
1174
1175    /* UeCb is not present */
1176    if( ROK != ret || NULLP == ueCb)
1177    { 
1178       RLOG_ARG1(L_ERROR, DBG_CELLID, staReq->cellId,"UeId[%u] not found",staReq->ueId);
1179       cfmInfo->status = CPJ_CFG_CFM_NOK; 
1180       cfmInfo->reason = CPJ_CFG_REAS_UE_UNKWN;
1181       cfmInfo->numRb = numRb;
1182
1183       /* Caller should return cfm with failure */
1184       RLOG_ARG1(L_ERROR,DBG_UEID,staReq->ueId,
1185                   "UE Cb is not found -- cellId(%d)",
1186                           staReq->cellId);
1187
1188       /* Send Failure SduStaCfm */
1189       PjDlUdxSduStaCfm(&gCb->u.dlCb->udxDlSap[0].pst, 
1190                         gCb->u.dlCb->udxDlSap[0].suId, cfmInfo);
1191
1192       RETVALUE(RFAILED);
1193    }
1194
1195    /* Call Ho Start handler for this UE */
1196    pjUtlDlReEstHO(gCb, ueCb);
1197
1198    for(rbCnt=0, numRb=0; rbCnt < PJ_MAX_DRB_PER_UE && numRb < CPJ_MAX_DRB; rbCnt++)
1199    {
1200       hoCfmInfo   =  &ueCb->hoInfo->hoCfmInfo[rbCnt];
1201       staInfo     =  &cfmInfo->sduStaInfo[numRb];
1202       if(hoCfmInfo->pres != TRUE)
1203       {
1204          continue;
1205       }
1206       
1207       staInfo->rbId  = hoCfmInfo->rbId;
1208       staInfo->dir   =  hoCfmInfo->dir;
1209       staInfo->dlSduStaInfo.count     =  hoCfmInfo->count;
1210       staInfo->dlSduStaInfo.hoPres    =  TRUE;
1211       numRb++;
1212    } 
1213    cfmInfo->numRb = numRb;
1214    cfmInfo->status = ROK;
1215    cfmInfo->reason = CPJ_CFG_REAS_NONE; 
1216    PJ_FREE(gCb,ueCb->hoInfo->hoCfmInfo,
1217               (PJ_MAX_DRB_PER_UE * sizeof(PjDlHoCfmInfo)));
1218    PJ_FREE(gCb,ueCb->hoInfo, sizeof(PjDlHoInfo));             
1219
1220    PjDlUdxSduStaCfm(&gCb->u.dlCb->udxDlSap[0].pst, 
1221                      gCb->u.dlCb->udxDlSap[0].suId, cfmInfo);
1222    RETVALUE(ROK);
1223 } /* pjCfgPrcSduSta */
1224
1225    
1226 \f
1227 /**
1228  * @brief
1229  * This primitive to update the ROHC Comp details in PJRB  Cb.
1230  *
1231  * @b Description:
1232  *  1. This primitive to update  the ROHC comp detils in PJRB Cb.
1233  *
1234  * @param [in]    pjRbCb    -  RB Control Block  
1235  * @param [in]    ueCb      -  Ue Control Block 
1236  * @param [in]    hdrCompCfg-  Comp Cfg Information 
1237  * 
1238  * @return  ROK
1239  *
1240  */
1241 #ifdef ANSI
1242 PRIVATE S16 pjCfgUpdDlCompInfo 
1243 (
1244 PjCb                   *gCb,
1245 PjDlRbCb               *rbCb,
1246 PjDlUeCb               *ueCb,
1247 UdxHdrCompCfg        *rohcCfg
1248 )
1249 #else
1250 PRIVATE S16 pjCfgUpdDlCompInfo(gCb, rbCb, ueCb, rohcCfg)
1251 PjCb                   *gCb;
1252 PjDlRbCb               *rbCb;
1253 PjDlUeCb               *ueCb;
1254 UdxHdrCompCfg        *rohcCfg;
1255 #endif
1256 {
1257    U16   profId;
1258    U8    idx;
1259    S16   ret;
1260
1261    TRC3(pjCfgUpdDlCompInfo);
1262
1263    /* Initialization */   
1264    ret    = ROK;
1265    profId = 0;
1266    idx  = 0; 
1267
1268    RLOG2(L_DEBUG, "pjCfgUpdCompInfo - Received for -- cellId(%d),RbId(%d)",
1269                           rbCb->rbId, ueCb->key.ueId);
1270
1271    /* Header Compresion information present */
1272    if(rohcCfg->hdrCompUsed)
1273    {
1274       /* Header Compression is enabled */ 
1275       rbCb->rohc.hdrCmpUsed = TRUE;
1276
1277       /* User Can Configure multipel profiles. Maximum profile ID should be used */  
1278       for(; idx<CPJ_MAX_ROHC_PROF_LIST; idx++)
1279       {
1280          if((rohcCfg->rohcInfo.profLst[idx] )&&
1281                (profId < rohcProfId[idx]))
1282             profId = rohcProfId[idx];
1283       } 
1284    }
1285    else
1286    {
1287       /* Header Compression is disabled */
1288       rbCb->rohc.hdrCmpUsed = FALSE;
1289       profId = 0x0000;
1290    }
1291
1292    /* Store the profile Id and MaxCid */
1293
1294    rbCb->rohc.profId = profId;
1295    rbCb->rohc.maxCid = rohcCfg->rohcInfo.maxCid;
1296
1297    /* Store the ue Details in Compressor Context */
1298    rbCb->cmpCxt.ueId   = ueCb->key.ueId;
1299    rbCb->cmpCxt.cellId = ueCb->key.cellId;
1300    rbCb->cmpCxt.rbId   = rbCb->rbId;
1301    rbCb->cmpCxt.rbType = rbCb->rbType;
1302
1303    RLOG2(L_DEBUG, "pjCfgUpdCompInfo - Selected   -- profId(%d),maxCid(%d)",
1304                           rbCb->rohc.profId, rbCb->rohc.maxCid);
1305
1306
1307    /* Compress Init */
1308    if(rbCb->rohc.hdrCmpUsed)
1309    {
1310       ret=pjUtlDlCmpInit(gCb, rbCb); 
1311    }
1312
1313    RETVALUE(ret);
1314 } /* pjCfgUpdCompInfo */
1315
1316 \f
1317 /**
1318  * @brief
1319  * This primitive to delete RB from Ue Cb.
1320  *
1321  * @b Description:
1322  * 1. To delete the PJRB Cb from  UeCb.
1323  *
1324  * @param [in]    ueCb      -  Ue Control Block 
1325  * @param [in]    rbCb      -  Rb Control Block  
1326  * 
1327  * @return  ROK
1328  *
1329  */
1330 #ifdef ANSI
1331 PUBLIC S16  pjCfgDelPjDlRbCb 
1332 (
1333 PjCb                 *gCb,
1334 PjDlUeCb             *ueCb,
1335 PjDlRbCb             *rbCb
1336 )
1337 #else
1338 PUBLIC S16 pjCfgDelPjDlRbCb(gCb,ueCb,rbCb)
1339 PjCb                  *gCb;
1340 PjDlUeCb              *ueCb;
1341 PjDlRbCb              *rbCb;
1342 #endif
1343 {   
1344    S16  ret;
1345 /* kw005.201 added support for L2 measurement */
1346 #ifdef LTE_L2_MEAS
1347 #endif
1348    TRC3(pjCfgDelPjDlRbCb);
1349
1350    /* Initialization */
1351    ret = ROK;
1352
1353    /* RbCb is present and Configured for PDCP */
1354    if(NULLP != rbCb) 
1355    {
1356       RLOG_ARG1(L_DEBUG, DBG_UEID,ueCb->key.ueId, 
1357             "Delete RB Req Received for -- rbId (%d)",rbCb->rbId);
1358
1359 #ifdef LTE_L2_MEAS
1360       PJ_UPD_L2_DECR_PER_QCI_RB_COUNT(gCb, rbCb); 
1361 #endif
1362       rbCb->ueCb   = NULLP;
1363 #if (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC))
1364       /* Stop off board timers */
1365       if(PJ_DIR_DL & rbCb->dir)
1366          pjStopTmr(gCb, (PTR)rbCb, PJ_EVT_DL_OBD_TMR);  
1367 #endif
1368       /* Deinit Tx Buffers */
1369       pjDbmTxDeInit(gCb, &rbCb->dlCb.txBuf);
1370       pjUtlEmptyDlPktList(gCb, rbCb);
1371
1372       if (rbCb->dlCb.staRep != NULL)
1373       {
1374         PJ_FREE_BUF(rbCb->dlCb.staRep);
1375       }
1376
1377       if (PJ_SRB == rbCb->rbType)
1378       {
1379          ueCb->numSrbs--;
1380       }
1381       else if(PJ_DRB == rbCb->rbType) 
1382       {
1383          ueCb->numDrbs--;
1384          if (rbCb->rohc.hdrCmpUsed)
1385          {
1386             pjUtlCmpClose(gCb,rbCb->cmpCxtId);
1387          }
1388       }
1389
1390       /* Free the rbCb */
1391       pjDbmDelDlRbCb(gCb,rbCb->rbId, rbCb->rbType, &rbCb, PJ_CFG_PDCP,ueCb);
1392    } 
1393    RETVALUE(ret);
1394 } /* pjCfgDelPjRBCb */
1395
1396 \f
1397 /**
1398  * @brief
1399  * Handler to process the downlink re-establishment Request for SRB1 during
1400  * RRC Re-Establishment request.
1401  *
1402  * @b Description:
1403  * 1. This primitive is used to re-establish SRB1 only during RRC Re-establishment 
1404  * 2. New Security Algo will applied 
1405  *
1406  * @param [in]    gCb        -  PDCP Instance Control block.
1407  * @param [in]    reEstReq   -  Entity Configuration to be done.
1408  * @param [out]   reEstCfm   -  Entity Configuration cfm.
1409  * 
1410  * @return  ROK
1411  *
1412  */
1413 #ifdef ANSI
1414 PUBLIC S16 pjCfgDlReEstReq
1415 (
1416 PjCb            *gCb,
1417 UdxReEstReqInfo *reEstReq,
1418 UdxReEstCfmInfo *reEstCfm
1419 )
1420 #else
1421 PUBLIC S16 pjCfgDlReEstReq (gCb, reEstReq, reEstCfm)
1422 PjCb            *gCb;
1423 UdxReEstReqInfo *reEstReq;
1424 UdxReEstCfmInfo *reEstCfm;
1425 #endif
1426 {
1427    S16     ret;
1428    PjDlRbCb    *rbCb;
1429    CmLteRlcId  rlcId;
1430
1431    TRC3(pjCfgDlReEstReq);
1432  
1433    /* Initialization */
1434    rlcId.cellId  =  reEstReq->pdcpId.cellId;
1435    rlcId.ueId  =  reEstReq->pdcpId.ueId;
1436    rlcId.rbId  =  reEstReq->pdcpId.rbId;
1437    rlcId.rbType  =  reEstReq->pdcpId.rbType;
1438
1439    RLOG2(L_DEBUG, "ReEst Req Received for -- cellId(%d),ueId(%d)",
1440                  reEstReq->pdcpId.cellId, reEstReq->pdcpId.ueId);
1441
1442    ret = pjDbmFetchDlRbCb(gCb,rlcId,&rbCb);
1443    
1444    /* Ue Cb is not present */
1445    if( ROK != ret || NULLP == rbCb)
1446    {
1447       RLOG_ARG2(L_ERROR, DBG_UEID,rlcId.ueId, "CellId[%u]:RbId[%d] not found",
1448             rlcId.cellId, rlcId.rbId);
1449       /* Fill entCfm structure */
1450       PJ_CFG_FILL_REESTREQ_CFM(reEstCfm, reEstReq->pdcpId.ueId,reEstReq->pdcpId.cellId,
1451             reEstReq->transId, CPJ_CFG_CFM_NOK);
1452       RETVALUE(ret);
1453    }
1454
1455    /* Copy Security Information */ 
1456    cmMemcpy(&rbCb->ueCb->secInfo.intInfo.intKey[0], &reEstReq->intKey[0], PJ_INTG_KEY_LEN);
1457    cmMemcpy(&rbCb->ueCb->secInfo.cipherInfo.cpKey[0], &reEstReq->ctrlplnKey[0], PJ_CIPHER_KEY_LEN);
1458    cmMemcpy(&rbCb->ueCb->secInfo.cipherInfo.upKey[0], &reEstReq->usrplnKey[0], PJ_CIPHER_KEY_LEN);
1459
1460    /* Mark Security Action Done */
1461    rbCb->ueCb->secInfo.secAct = TRUE;
1462    
1463    /* update the status as success. Chances of failure after this is minimal*/
1464    PJ_CFG_FILL_REESTREQ_CFM(reEstCfm, reEstReq->pdcpId.ueId,reEstReq->pdcpId.cellId,
1465             reEstReq->transId, CPJ_CFG_CFM_OK);
1466
1467 #ifdef PJ_SEC_ASYNC
1468    /* In case of Async need to save the cfm information */
1469    pjUtlDlSaveCfmInfo(gCb, rbCb->ueCb, PJ_REEST_ASYNC_CFM, TRUE, ENTPJ, 
1470                                           (PTR)reEstCfm, NULLP);
1471    PJ_FREE(gCb,reEstCfm, sizeof(CpjReEstCfmInfo));
1472 #endif
1473
1474    /* Call ReEst for SRB1 */
1475    pjUtlDlReEstSrb1(gCb, rbCb);
1476
1477    RETVALUE(ROK);
1478 } /* pjCfgReEstReq */
1479
1480 #ifdef LTE_L2_MEAS
1481
1482 PRIVATE S16 pjAddToDlL2Meas(PjCb *gCb, PjDlRbCb *pjRbCb,U8 cellId,U16 ueId)
1483 {
1484    PjL2MeasEvtCb *measEvtCb = NULLP;
1485    PjL2MeasCb    *measCb    = NULLP;
1486    U16           cntr;
1487
1488
1489    for(cntr = 0; cntr < LPJ_MAX_L2MEAS; cntr++)
1490    {
1491       measEvtCb = &gCb->u.dlCb->pjL2Cb.pjL2EvtCb[cntr];
1492       measCb = &(measEvtCb->measCb);
1493
1494       if (measCb->measType & LPJ_L2MEAS_DL_DISC)
1495       {
1496          pjUtlPlcMeasDatInDlL2Sts(&measCb->measData[pjRbCb->qci],
1497                &pjRbCb->rbL2Cb, measCb->measType);
1498          measCb->qci[pjRbCb->qci] = pjRbCb->qci;
1499
1500          measCb->measData[pjRbCb->qci].totDrbsPerQci++;
1501       }
1502    }
1503    RETVALUE(ROK);
1504 }/*pjAddToDlL2Meas*/ 
1505 #endif /*LTE_L2_MEAS*/
1506
1507 /*@}*/
1508 \f
1509 /********************************************************************30**
1510
1511          End of file
1512 **********************************************************************/