4e15d764db71323f9f6f4c031432d1f4f7d47285
[o-du/l2.git] / src / 5gnrmac / rg_com.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point functions
26   
27      File:     rg_com.c 
28   
29 **********************************************************************/
30
31 /** @file rg_com.c
32 @brief This module does processing related to handling of upper interface APIs 
33 invoked by RRC towards MAC.
34 */
35
36 static const char* RLOG_MODULE_NAME="MAC";
37 static int RLOG_FILE_ID=181;
38 static int RLOG_MODULE_ID=4096;
39 /* header include files -- defines (.h) */
40 #include "envopt.h"        /* environment options */
41 #include "envdep.h"        /* environment dependent */
42 #include "envind.h"        /* environment independent */
43 #include "gen.h"           /* general layer */
44 #include "ssi.h"           /* system service interface */
45 #include "cm_hash.h"       /* common hash list */
46 #include "cm_mblk.h"       /* common memory link list library */
47 #include "cm_llist.h"      /* common linked list library */
48 #include "cm_err.h"        /* common error */
49 #include "cm_lte.h"        /* common LTE */
50 #include "lrg.h"
51 #include "crg.h"
52 #include "rgu.h"
53 #include "tfu.h"
54 #include "rg_sch_inf.h"
55 #include "rg_prg.h"       /* PRG interface includes*/
56 #include "rg_env.h"
57 #include "rg.h"
58 #include "rg_err.h"
59
60 /* header/extern include files (.x) */
61 #include "gen.x"           /* general layer */
62 #include "ssi.x"           /* system service interface */
63 #include "cm5.x"           /* common timers */
64 #include "cm_lib.x"        /* common library */
65 #include "cm_hash.x"       /* common hash list */
66 #include "cm_mblk.x"       /* common memory link list library */
67 #include "cm_llist.x"      /* common linked list library */
68 #include "cm_tkns.x"       /* common tokens */
69 #include "cm_lte.x"        /* common LTE */
70 #include "lrg.x"
71 #include "crg.x"
72 #include "rgu.x"
73 #include "tfu.x"
74 #include "rg_sch_inf.x"
75 #include "rg_prg.x"       /* PRG interface typedefs*/
76 #include "du_app_mac_inf.h"
77 #include "rg.x"
78 #ifdef LTE_ADV
79 #include "rg_pom_scell.x"
80 #endif
81 /* local defines */
82 PRIVATE S16 rgCOMHndlCfgReq ARGS((Inst inst,CrgCfg  *cfg, RgErrInfo *errInfo,Bool *isCfmRqrd,CrgCfgTransId transId));
83 PRIVATE S16 rgCOMHndlRecfgReq ARGS((Inst inst,CrgRecfg *recfg, RgErrInfo *errInfo, \
84          CrgCfgTransId transId,Bool *isCfmRqrd));
85 PRIVATE S16 rgCOMHndlDelReq ARGS((Inst inst,CrgDel *del, RgErrInfo *errInfo, Bool *isCfmRqrd, CrgCfgTransId transId));
86 PRIVATE S16 rgCOMHndlResetReq ARGS((Inst inst,CrgRst *reset,RgErrInfo *errInfo));
87 /* local typedefs */
88  
89 /* local externs */
90  
91 /* forward references */
92
93 /**
94  * @brief Handler to handle config request from RRC to MAC.
95  *
96  * @details
97  *
98  *     Function: rgCOMCfgReq
99  *     
100  *     This API handles processing for config request from RRC to MAC. 
101  *     
102  *     Processing Steps:
103  *      - If configuration, process configuration request. Call rgCOMHndlCfgReq.
104  *      - else If re-configuration, process re-configuration request. 
105  *        Call rgCOMHndlRecfgReq.
106  *      - else If reset, process reset request. Call rgCOMHndlResetReq.
107  *      - else If delete, process delete request. Call rgCOMHndlDelReq.
108  *      - If successful, send confirmation to RRC. Call rgUIMCrgCfgCfm.
109  *      - If failed, FAIL.
110  *
111  *  @param[in]  Inst        inst
112  *  @param[in]  CrgCfgTransId transId
113  *  @param[in]  CrgCfgReqInfo *crgCfgReq
114  *  @return  S16
115  *      -# ROK 
116  *      -# RFAILED 
117  **/
118 #ifdef ANSI
119 PUBLIC S16 rgCOMCfgReq
120 (
121 Inst          inst,
122 CrgCfgTransId transId,
123 CrgCfgReqInfo *crgCfgReq
124 )
125 #else
126 PUBLIC S16 rgCOMCfgReq(inst,transId, crgCfgReq)
127 Inst          inst;
128 CrgCfgTransId transId;
129 CrgCfgReqInfo *crgCfgReq;
130 #endif
131 {
132    S16             ret;
133    U8              cfmStatus = CRG_CFG_CFM_OK;
134    RgErrInfo       errInfo;
135    Bool            isCfmRqrd = TRUE;
136
137    TRC2(rgCOMCfgReq);
138
139    /* Process Config/Reconfig/Delete request from RRC */
140    switch (crgCfgReq->action)
141    {
142       case CRG_CONFIG:
143          {
144             ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
145             break;
146          }
147       case CRG_RECONFIG:
148          {
149             ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
150             break;
151          }
152          /* Start: LTEMAC_2.1_DEV_CFG */
153       case CRG_RESET:
154          {
155             ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
156             break;
157          }
158          /* End: LTEMAC_2.1_DEV_CFG */
159       case CRG_DELETE:
160          {
161             ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
162             break;
163          }
164       default:
165          {
166             RLOG1(L_ERROR, "Invalid configuration action %d",
167                      crgCfgReq->action);
168
169             ret = RFAILED;
170          }
171    }
172
173    if (ret != ROK)
174    {
175       cfmStatus = CRG_CFG_CFM_NOK;
176    }
177
178    /* When UeSCellCfg is present then confirmation will be sent later once
179       confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
180       confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
181 #ifdef LTE_ADV
182 if(TRUE == isCfmRqrd)
183    {
184 #endif
185       /* Send back confirmation status to RRC */
186       rgUIMCrgCfgCfm(inst,transId, cfmStatus); 
187 #ifdef LTE_ADV
188    }
189 #endif
190    RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
191    RETVALUE(ret);
192 }  /* rgCOMCfgReq */
193 /**
194  * @brief Handler for processing Cell/Ue/Logical channel configuration request
195  * recieved from RRC.
196  *
197  * @details
198  *
199  *     Function: rgCOMHndlCfgReq
200  *     
201  *     This API handles processing of configuration request from RRC to MAC. 
202  *     
203  *     Processing Steps:
204  *        - Validate configuration request parameters at CFG module. 
205  *          Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg 
206  *          for Cell, UE and Logical channel configuration respectively.
207  *        - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg, 
208  *          rgCFGCrgLcCfg for Cell, UE and Logical channel configuration 
209  *          respectively, else FAIL.
210  *
211  *  @param[in]  Inst        inst
212  *  @param[in]  CrgCfg    *cfg
213  *  @param[out] RgErrInfo *errInfo
214  *  @return  S16
215  *      -# ROK 
216  *      -# RFAILED 
217  **/
218 #ifdef ANSI
219 PRIVATE S16 rgCOMHndlCfgReq
220 (
221 Inst             inst,
222 CrgCfg           *cfg,
223 RgErrInfo        *errInfo,
224 Bool             *isCfmRqrd,
225 CrgCfgTransId    transId
226 )
227 #else
228 PRIVATE S16 rgCOMHndlCfgReq(inst,cfg, errInfo,isCfmRqrd,transId)
229 Inst            inst;
230 CrgCfg          *cfg;
231 RgErrInfo       *errInfo;
232 Bool            *isCfmRqrd;
233 CrgCfgTransId   transId;
234 #endif
235 {
236    S16       ret;
237    RgCellCb  *cell = NULLP;
238    RgUeCb    *ue   = NULLP;
239
240    TRC2(rgCOMHndlCfgReq);
241
242    errInfo->errType = RGERR_COM_CFG_REQ;
243
244    /* Validate and process the configuration request */ 
245    switch (cfg->cfgType)
246    {
247       case CRG_CELL_CFG:
248       {
249          ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
250          if (ret != ROK)
251          {
252               RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId, "Cell configuration validation FAILED\n");
253               RETVALUE(RFAILED);
254          }
255          ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
256          break;
257       }
258       case CRG_UE_CFG:
259       {
260          {
261             ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
262             if (ret != ROK)
263             {
264                RLOG_ARG0(L_ERROR,DBG_CRNTI,cfg->u.ueCfg.crnti, "Ue configuration validation FAILED\n");
265                RETVALUE(RFAILED);
266             }
267             ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
268          }
269          break;
270       }
271       case CRG_LCH_CFG:
272       {
273
274          ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
275          if (ret != ROK)
276          {
277             
278             RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId,
279                          "LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
280             RETVALUE(RFAILED);
281          }
282          ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
283          break;
284       }
285       default:
286       {
287          RLOG1(L_ERROR, "Should never come here: cfgType %d",cfg->cfgType);
288          RETVALUE(RFAILED);
289       }
290    }
291
292    RETVALUE(ret);
293 }  /* rgCOMHndlCfgReq */
294
295
296 /**
297  * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
298  * recieved from RRC.
299  *
300  * @details
301  *
302  *     Function: rgCOMHndlRecfgReq
303  *     
304  *     This API handles processing of reconfiguration request from RRC to MAC. 
305  *     
306  *     Processing Steps:
307  *      - Validate reconfiguration request parameters at CFG module. Call 
308  *        rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for 
309  *        Cell, UE and logical channel reconfiguration respectively.
310  *      - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg, 
311  *        rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration 
312  *        respectively else FAIL.
313  *
314  *  @param[in]  Inst        inst
315  *  @param[in]  CrgRecfg   *recfg
316  *  @param[out] RgErrInfo  *errInfo
317  *  @return  S16
318  *      -# ROK 
319  *      -# RFAILED 
320  **/
321 #ifdef ANSI
322 PRIVATE S16 rgCOMHndlRecfgReq
323 (
324 Inst             inst,
325 CrgRecfg         *recfg,
326 RgErrInfo        *errInfo,
327 CrgCfgTransId    transId,
328 Bool             *isCfmRqrd
329 )
330 #else
331 PRIVATE S16 rgCOMHndlRecfgReq(inst,recfg, errInfo, transId, isCfmRqrd)
332 Inst            inst;
333 CrgRecfg        *recfg;
334 RgErrInfo       *errInfo;
335 CrgCfgTransId   transId;
336 Bool            *isCfmRqrd;
337 #endif
338 {
339    S16       ret;
340    RgCellCb  *cell = rgCb[inst].cell;
341    RgUeCb    *ue   = NULLP;
342    RgUlLcCb  *ulLc = NULLP;
343
344    TRC2(rgCOMHndlRecfgReq);
345
346    errInfo->errType = RGERR_COM_RECFG_REQ;
347    
348    /* Validate and process the re-configuration request */ 
349    switch (recfg->recfgType)
350    {
351       case CRG_CELL_CFG:
352       {
353          ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
354             if (ret != ROK) 
355             {
356                RLOG_ARG0(L_ERROR,DBG_CELLID,recfg->u.cellRecfg.cellId,
357                          "Cell Recfg Validation FAILED");
358                RETVALUE(RFAILED);
359             }
360          ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
361          break;
362       }
363       case CRG_UE_CFG:
364       {
365          /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
366           * having a possibility of sending NOK */
367          if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
368          {
369             errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
370             ret = ROK;
371          }    
372          else
373          {
374 #ifdef LTE_ADV
375          /* Check for isSCellCfgPres */
376          if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
377          {
378             ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
379             if (ret != ROK)
380             {
381                RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Ue SCell configuration FAILED for inst [%d]\n",
382                         recfg->u.ueRecfg.oldCrnti, inst));
383                RETVALUE(RFAILED);
384             }
385
386          }
387          else
388          {
389 #endif /* LTE_ADV */
390             ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
391             if ( ret != ROK)
392             {
393                RLOG_ARG1(L_ERROR,DBG_CELLID,recfg->u.ueRecfg.cellId,
394                       "Ue Re-configuration validation FAILED OLD CRNTI:%d",
395                       recfg->u.ueRecfg.oldCrnti);
396                RETVALUE(RFAILED);
397             }
398             ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
399          }
400 #ifdef LTE_ADV
401          }
402 #endif
403          break;
404       }
405       case CRG_LCH_CFG:
406       {
407          ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue, 
408                &ulLc, errInfo);
409          if (ret != ROK)
410          {
411             RLOG_ARG2(L_ERROR,DBG_CELLID,recfg->u.lchRecfg.cellId,
412                       "LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
413                       recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
414             RETVALUE(RFAILED);
415          }
416
417 #ifdef LTE_ADV
418          /*ERAB- multicell fix*/
419          cmMemcpy( (U8*)&(ue->cfgCfmInfo.transId), (U8*)&transId,
420                sizeof(CrgCfgTransId));
421 #endif
422          ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
423                &recfg->u.lchRecfg, errInfo,isCfmRqrd);
424
425          break;
426       }
427       default:
428       {
429          RLOG1(L_ERROR, "Should never come here: recfgType %d",
430                   recfg->recfgType);
431          RETVALUE(RFAILED);
432       }
433    }
434
435    RETVALUE(ret);
436 }  /* rgCOMHndlRecfgReq */
437
438 /*Start: LTEMAC_2.1_DEV_CFG */
439 /**
440  * @brief Handler for processing UE Reset request recieved from RRC.
441  *
442  * @details
443  *
444  *     Function: rgCOMHndlResetReq
445  *     
446  *     This API handles processing of Reset request from RRC to MAC. 
447  *     
448  *     Processing Steps:
449  *      - Validate reset request parameters at CFG module. Call 
450  *        rgCFGVldtCrgUeReset for UE reset.
451  *      - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
452  *
453  *  @param[in]  Inst        inst
454  *  @param[in]  CrgRst     *reset
455  *  @param[out] RgErrInfo  *errInfo
456  *  @return  S16
457  *      -# ROK 
458  *      -# RFAILED 
459  **/
460 #ifdef ANSI
461 PRIVATE S16 rgCOMHndlResetReq
462 (
463 Inst       inst,
464 CrgRst     *reset,
465 RgErrInfo  *errInfo
466 )
467 #else
468 PRIVATE S16 rgCOMHndlResetReq(inst,reset, errInfo)
469 Inst       inst;
470 CrgRst     *reset;
471 RgErrInfo  *errInfo;
472 #endif
473 {
474    TRC2(rgCOMHndlResetReq);
475
476    /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
477    
478    errInfo->errCause = RGERR_NONE;
479    RGDBGINFO(inst,(rgPBuf(inst), "CRG UE Reset processed \n"));
480    RETVALUE(ROK);
481 }  /* rgCOMHndlResetReq */
482 /*End: LTEMAC_2.1_DEV_CFG */
483
484 /**
485  * @brief Handler for processing Cell/UE/Logical channel delete request
486  * recieved from RRC.
487  *
488  * @details
489  *
490  *     Function: rgCOMHndlDelReq
491  *     
492  *     This API handles processing of delete request from RRC to MAC. 
493  *     
494  *     Processing Steps:
495  *        - Fetch corresponding control block and pass it to CFG module.
496  *        - If control block does not exist, FAIL.
497  *
498  *  @param[in]  Inst        inst
499  *  @param[in]  CrgDel    *del
500  *  @param[out] RgErrInfo *errInfo
501     @param[out] Bool      *isCfmRqrd
502  *  @return  S16
503  *      -# ROK 
504  *      -# RFAILED 
505  **/
506 #ifdef ANSI
507 PRIVATE S16 rgCOMHndlDelReq
508 (
509 Inst        inst,
510 CrgDel      *del,
511 RgErrInfo   *errInfo,
512 Bool        *isCfmRqrd,
513 CrgCfgTransId transId
514 )
515 #else
516 PRIVATE S16 rgCOMHndlDelReq(inst,del, errInfo,isCfmRqrd,transId)
517 Inst        inst;
518 CrgDel      *del;
519 RgErrInfo   *errInfo;
520 Bool        *isCfmRqrd;
521 CrgCfgTransId transId;
522 #endif
523 {
524
525    S16            ret;
526    VOLATILE U32   startTime=0;
527
528    TRC2(rgCOMHndlDelReq);
529    
530    errInfo->errType = RGERR_COM_DEL_REQ;
531    
532    /* Process the delete request */ 
533    switch (del->delType)
534    {
535       case CRG_CELL_CFG:
536       {
537          ret = rgCFGCrgCellDel(inst,del, errInfo);
538          break;
539       }
540       case CRG_UE_CFG:
541       {
542          /*starting Task*/ 
543          SStartTask(&startTime,PID_MAC_UE_DEL);
544
545
546          ret = rgCFGCrgUeDel(inst,del, errInfo);
547          RGDBGINFONEW(inst,(rgPBuf(inst),"[%d] Delete UE Done \n", del->u.ueDel.crnti));
548
549          /*stoping Task*/ 
550          SStopTask(startTime,PID_MAC_UE_DEL);
551
552          break;
553       }
554       case CRG_LCH_CFG:
555       {
556          ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
557          break;
558       }
559       default:
560       {
561          RLOG1(L_ERROR, "Should never come here: delType %d",
562                   del->delType);
563          RETVALUE(RFAILED);
564       }
565    }
566
567    RETVALUE(ret);
568 }  /* rgCOMHndlDelReq */
569
570 #ifdef LTE_ADV
571 /**
572  * @brief Handler for the SCell configuration request from RRC to MAC.
573  *
574  * @details
575  *
576  *     Function : RgPrgPMacSMacUeSCellCfgReq
577  *
578  *     Processing Steps:
579  *      - Allocate and create UE control block.
580  *      - Update UE control block with the values recieved in the
581  *        configuration.
582  *      - If successful, add the control block to hash list of UEs for the cell
583  *        else Rollback and FAIL.
584  *
585  *  @param[in]  Pst          *pst
586  *  @param[in]  RgPrgUeSCellCfgInfo *ueSCellCb
587  *  @return  S16
588  *      -# ROK
589  *      -# RFAILED
590  **/
591 #ifdef ANSI
592 PUBLIC S16 RgPrgPMacSMacUeSCellCfgReq
593 (
594 Pst         *pst,    
595 RgPrgUeSCellCfgInfo *ueSCellCb
596 )
597 #else
598 PUBLIC S16 RgPrgPMacSMacUeSCellCfgReq(pst, ueSCellCb)
599 Pst         *pst;    
600 RgPrgUeSCellCfgInfo *ueSCellCb;
601 #endif
602 {
603    RgPrgCfgCfmInfo  cfgCfm;
604    Inst             inst = pst->dstInst;
605    RgCellCb         *cell = rgCb[inst].cell;
606    S16              ret;
607    Pst              cfmPst;    
608
609    TRC2(RgPrgPMacSMacUeSCellCfgReq);
610    
611    RGDBGPRM(inst,(rgPBuf(inst),
612             "APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
613             ueSCellCb->cellId, ueSCellCb->ueId));
614
615    cfgCfm.ueId = ueSCellCb->ueId;
616    cfgCfm.sCellId = ueSCellCb->cellId;
617    cfgCfm.status = PRG_CFG_CFM_OK;
618    cfgCfm.event = EVTPRGUESCELLCFGCFM;
619    rgGetPstToInst(&cfmPst, inst, pst->srcInst);
620
621   ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
622   if(ret != ROK)
623   {
624      RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
625               cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
626      /* Set status as Not OK*/
627      cfgCfm.status = PRG_CFG_CFM_NOK;
628   }
629   else
630   {
631      ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
632      if(ret != ROK)
633      {
634         RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
635                  cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
636         /* Set status as Not OK*/
637         cfgCfm.status = PRG_CFG_CFM_NOK;
638      }
639   }
640   
641   RGDBGINFONEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell Config done:\
642            cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
643
644   /* Send positive confirmation to primary cell*/
645   RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
646   RETVALUE(ROK);
647 }  /* RgPrgPMacSMacUeSCellCfgReq */
648
649 /**
650  * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
651  *
652  * @details
653  *
654  *     Function : RgPrgSMacPMacCfgCfm
655  *
656  *     Processing Steps:
657  *      - Allocate and create UE control block.
658  *      - If cfm event is lch recfg then send the confirmation to RRC for
659  *        that event.
660  *      - If cfm event is Scell addition then send the confirmation to RRC for
661  *        the same.
662  *         - Update UE control block with the values received in the
663  *           configuration.
664  *         - If successful, add the control block to hash list of UEs for the cell
665  *           else Rollback and FAIL.
666  *
667  *  @param[in]  Inst        dstMacInst
668  *  @param[in]  RgUrSCellCb  *ueSCellCb
669  *  @return  S16
670  *      -# ROK
671  *      -# RFAILED
672  **/
673 #ifdef ANSI
674 PUBLIC S16 RgPrgSMacPMacCfgCfm
675 (
676 Pst             *pst,    
677 RgPrgCfgCfmInfo *cfgCfm
678 )
679 #else
680 PUBLIC S16 RgPrgSMacPMacCfgCfm(pst, cfgCfm)
681 Pst             *pst;    
682 RgPrgCfgCfmInfo *cfgCfm;
683 #endif
684 {
685    Inst      inst = pst->dstInst;
686    RgCellCb *cell;
687    RgUeCb   *ue;
688    TRC2(RgPrgSMacPMacCfgCfm);
689
690
691    RG_IS_INST_VALID(inst);
692
693    RGDBGPRM(pst->dstInst,(rgPBuf(pst->dstInst),
694             "Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
695             pst->srcInst, cfgCfm->ueId, cfgCfm->cellId));
696
697    cell = rgCb[inst].cell;
698
699    if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
700    {
701       RGDBGERRNEW(inst,(rgPBuf(inst), 
702                "[%d]Ue does not exist\n", cfgCfm->ueId));
703       RETVALUE(RFAILED);
704    }
705    switch(cfgCfm->event)
706    {
707       /* cfgCount increment for all cases */
708       case EVTPRGUESCELLLCHMODCFM:
709       case EVTPRGUESCELLLCHDELCFM:
710       case EVTPRGUESCELLLCHADDCFM:
711          {
712             ue->cfgCfmInfo.cfgCfgCount++;
713             ue->cfgCfmInfo.mask |= cfgCfm->status;
714             if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
715             {
716                ue->cfgCfmInfo.cfgCfgCount = 0;
717                /* Send back confirmation status to RRC */
718                rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
719                ue->cfgCfmInfo.mask = 0;
720                RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
721             }
722          }
723          break;
724       case EVTPRGUESCELLCFGCFM:
725          {
726             /*Commit Added SCell info to UeCb as we confirmation received */
727             if(PRG_CFG_CFM_OK == cfgCfm->status)
728             {
729                ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
730                ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
731                ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
732             }
733
734             ue->cfgCfmInfo.cfgCfgCount++;
735             ue->cfgCfmInfo.mask |= cfgCfm->status;
736             if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
737             {
738                ue->cfgCfmInfo.cfgCfgCount = 0;
739                /* Send back confirmation status to RRC */
740                rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
741                ue->cfgCfmInfo.mask = 0;
742                RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
743             }
744          }
745          break;
746       default:
747          {
748             RGDBGERRNEW(inst,(rgPBuf(inst), "Invalid configuration confirm event %d\n",
749                      cfgCfm->event));
750
751             RETVALUE(RFAILED);
752          }
753
754    }
755    RETVALUE(ROK);
756 }  /* RgPrgSMacPMacCfgCfm */
757
758 /**
759  * @brief Function for handling UE release for SCELL
760  * triggered from Primary Cell
761  *
762  * @details
763  *
764  *     Function : RgPrgPMacSMacUeSCellDelReq
765  *     
766  *        - This Function should be invoked by PCell of UE
767  *        - Remove the UE context from SCELL corresponding to rnti.
768  *           
769  *  @param[in] Pst                 *pst
770  *  @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
771  *  @return  ROK is SUCCESS 
772  **/
773 #ifdef ANSI
774 PUBLIC S16 RgPrgPMacSMacUeSCellDelReq
775 (
776 Pst                 *pst,
777 RgPrgUeSCellDelInfo *ueSCellDelInfo
778 )
779 #else
780 PUBLIC S16 RgPrgPMacSMacUeSCellDelReq(pst, ueSCellDelInfo)
781 Pst                 *pst;
782 RgPrgUeSCellDelInfo *ueSCellDelInfo;
783 #endif
784 {
785    Inst        inst     = pst->dstInst - RG_INST_START;
786    RgCellCb    *sCell   = rgCb[inst].cell;
787    RgUeCb      *sCellUe = NULLP;
788
789    TRC2(RgPrgPMacSMacUeSCellDelReq)
790
791    /* Checking for cell Cb because in case of shutdownReq it is possible that
792     * cell is already deleted for this cell*/
793    if(sCell == NULLP)
794    {
795       RETVALUE(ROK);
796    }
797    /* Retrive the UeCb from sec cell*/
798    if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
799    {
800       RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:does not exist in sCell(%d)\n",
801                ueSCellDelInfo->ueId, sCell->cellId));
802       RETVALUE(RFAILED);
803    }
804    
805    /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
806     *request from PMAC to SMAC during PCell reestablishment
807     */
808   if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
809   {
810      /* Retrive the UeCb from sec cell*/
811      if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
812      {
813         RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:UE context already exist in\
814                  sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId));
815         RETVALUE(RFAILED);
816      }
817
818      rgDBMDelUeCb(sCell, sCellUe);
819
820      sCellUe->ueId = ueSCellDelInfo->newRnti;
821
822      /* Reset harq procs*/
823      rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
824
825      rgDBMInsUeCb(sCell, sCellUe);
826   }
827   else
828   {
829      rgDBMDelUeCb(sCell, sCellUe);
830      rgCFGFreeUeCb(sCell, sCellUe);
831   }
832
833    RETVALUE(ROK);
834 } /* RgPrgPMacSMacUeSCellDelReq */
835 #endif /*LTE_ADV */
836 /**********************************************************************
837  
838          End of file
839 **********************************************************************/