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