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