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