[JIRA ID - ODUHIGH-275] Part -1 classifying of logs of sch folder
[o-du/l2.git] / src / 5gnrsch / rg_sch_gom.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 fucntions
26   
27      File:     rg_sch_gom.c 
28   
29 **********************************************************************/
30
31 /** @file rg_sch_gom.c 
32 @brief This module does processing related to handling of upper interface APIs 
33 invoked by RRM towards MAC.
34 */
35
36
37 /* header include files -- defines (.h) */
38 #include "common_def.h"
39 #include "lrg.h"
40 #include "rgr.h"
41 #include "tfu.h"
42 #include "rg_env.h"
43 #include "rg_sch_inf.h"
44 #include "rg_sch.h"
45 #include "rg_sch_err.h"
46 #include "rl_interface.h"
47 #include "rl_common.h"
48
49 /* header/extern include files (.x) */
50 #include "lrg.x"
51 #include "rgr.x"
52 #include "tfu.x"
53 #include "rg_sch_inf.x"
54 #include "rg_sch.x"
55
56 /* local defines */
57 static S16 rgSCHGomHndlCfgReq ARGS((RgSchCb *instCb, SpId spId,
58          RgrCfg  *cfg, RgSchErrInfo *errInfo));
59 static S16 rgSCHGomHndlRecfgReq ARGS((RgSchCb *instCb, SpId spId,
60          RgrRecfg  *recfg, RgSchErrInfo *errInfo));
61 static S16 rgSCHGomHndlResetReq ARGS((RgSchCb *instCb,SpId spId,RgrRst *reset,
62          RgSchErrInfo  *errInfo));
63 static S16 rgSCHGomGetCellIdFrmCfgReq ARGS((RgrCfgReqInfo *rgrCfgReq,
64          CmLteCellId *cellId));
65 static S16 rgSCHGomCfgReq ARGS((Region reg, Pool pool, RgSchCb *instCb,
66          RgrCfgTransId transId, RgrCfgReqInfo *cfgReqInfo));
67 static S16 rgSCHGomEnqCfgReq ARGS((Region reg, Pool pool, RgSchCellCb *cell,
68          RgrCfgTransId transId, RgrCfgReqInfo *rgrCfgReq));
69 static S16 rgSCHGomHndlDelReq ARGS((RgSchCb  *instCb,SpId spId, 
70          RgrDel  *del,RgSchErrInfo  *errInfo));
71 #ifdef LTE_ADV
72 static S16 rgSCHGomHndlSCellActDeactReq ARGS((RgSchCb *instCb, SpId spId,
73          RgrSCellActDeactEvnt  *sCellActDeactEvnt, RgSchErrInfo *errInfo, uint8_t action));
74 #endif /* LTE_ADV */
75 #ifdef EMTC_ENABLE
76 S16 rgSchEmtcGetSiWinPerd ARGS((
77 RgSchCellCb   *cell,
78 uint16_t  *siWinSize,
79 uint16_t  *minPeriod 
80 ));
81 extern S16 rgSCHEmtcUtlCalMcsAndNPrb
82 (
83  RgSchCellCb         *cell,
84  uint8_t                  cfgType,
85  MsgLen              msgLen,
86  uint8_t                  siId
87  );
88
89 S32 rgSCHEmtcUtlGetAllwdCchTbSzForSI ARGS(
90 (
91 uint32_t bo
92 ));
93
94 Void rgSCHEmtcWarningSiCfg ARGS(
95 (
96 RgSchCellCb             *cell,
97 RgrWarningSiCfgReqInfo  *warningSiCfgReqInfo,
98 uint16_t                     idx
99 ));
100 #endif
101
102
103 /* local typedefs */
104  
105 /* local externs */
106  
107 /* forward references */
108
109 \f
110
111 /**
112  * @brief Handler for config request from RRM to Schedular.
113  *
114  * @details
115  *
116  *     Function: rgSCHGomHndlCfg
117  *     
118  *     This API is called from schedulers UIM and it handles config request
119  *     from RRM to Scheduler.
120  *     
121  *     Processing Steps:
122  *      - If the request is for the inactive cell, 
123  *       - Handle request.Call rgSCHGomCfgReq.
124  *      - Else,
125  *       - Enqueue the request. Call rgSCHGomEnqCfgReq.
126  *         
127  *  @param[in]  Pst           *pst
128  *  @param[in]  RgSchCb       *instCb
129  *  @param[in]  RgrCfgTransId transId
130  *  @param[in]  RgrCfgReqInfo *cfgReqInfo
131  *  @return  S16
132  *      -# ROK 
133  *      -# RFAILED 
134  **/
135 S16 rgSCHGomHndlCfg(Pst *pst,RgSchCb  *instCb,RgrCfgTransId transId,RgrCfgReqInfo *cfgReqInfo)
136 {
137    S16           ret;
138    SpId          spId = 0;
139    CmLteCellId   cellId;
140    RgSchCellCb   *cell = NULLP;    
141    uint8_t       cfmStatus = RGR_CFG_CFM_NOK;
142
143    /* Apply the configuration for Cell Configuration or Delete */
144    if (cfgReqInfo->action != RGR_RECONFIG)
145    {
146       ret = rgSCHGomCfgReq (pst->region, pst->pool, instCb, 
147             transId, cfgReqInfo);
148       return (ret);
149    }
150
151    /* Fetch the cell Id for the recieved request */
152    if((rgSCHGomGetCellIdFrmCfgReq(cfgReqInfo, &cellId)) != ROK)
153    {
154       DU_LOG("\nERROR  -->  SCH : Action.Config Type Error");
155
156       SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo, 
157             (Size)sizeof(*cfgReqInfo));
158       cfgReqInfo = NULLP;
159       schSendCfgCfm(pst->region, pst->pool, transId, cfmStatus); 
160       return RFAILED;
161    }
162    /* Extract the cell and Enquee Config Request */
163    if(NULLP != instCb->rgrSap[spId].cell)
164    {
165       if(cellId != instCb->rgrSap[spId].cell->cellId) 
166       {
167          DU_LOG("\nERROR  -->  SCH : Cell with Id %d already exists "
168            "on sap %d", instCb->rgrSap[spId].cell->cellId, spId);  
169
170          SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo, 
171                (Size)sizeof(*cfgReqInfo));
172          cfgReqInfo = NULLP;
173          schSendCfgCfm(pst->region, pst->pool, transId, cfmStatus); 
174          return RFAILED;
175       }
176       cell = instCb->rgrSap[spId].cell;
177
178       /* Enqueue the configuration */
179       ret = rgSCHGomEnqCfgReq(pst->region, pst->pool, cell, transId, cfgReqInfo);
180       if (ret != ROK)
181       {
182          DU_LOG("\nERROR  -->  SCH : rgSCHGomHndlCfg: Enqueuing CfgReq "
183               "Failed ");
184
185          SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo, 
186                (Size)sizeof(*cfgReqInfo));
187          cfgReqInfo = NULLP;
188          schSendCfgCfm(pst->region, pst->pool, transId, cfmStatus); 
189          return RFAILED;
190       }
191
192       return ROK;
193    }
194    SPutSBuf(pst->region, pst->pool, (Data *)cfgReqInfo, 
195          (Size)sizeof(*cfgReqInfo));
196    cfgReqInfo = NULLP;
197    schSendCfgCfm(pst->region, pst->pool, transId, cfmStatus); 
198    return RFAILED;
199
200 }/* rgSCHGomHndlCfg */
201
202
203 /**
204  * @brief Handler to handle config request from RRM to Scheduler.
205  *
206  * @details
207  *
208  *     Function: rgSCHGomCfgReq
209  *     
210  *     This API handles processing for config request from RRM to Scheduler.
211  *     
212  *     Processing Steps: 
213  *      - If Configuration request, call rgSCHGomHndlCfgReq.
214  *      - Else if Reconfiguration request, call rgSCHGomHndlRecfgReq.
215  *      - If successful, send configuration confirm to RRM.
216  *        Call schSendCfgCfm else FAIL.
217  *
218  *  @param[in]  Region        reg
219  *  @param[in]  Pool          pool
220  *  @param[in]  RgSchCb       *instCb
221  *  @param[in]  RgrCfgTransId transId
222  *  @param[in]  RgrCfgReqInfo *cfgReqInfo
223  *  @return  S16
224  *      -# ROK 
225  *      -# RFAILED 
226  **/
227 static S16 rgSCHGomCfgReq(Region  reg,Pool  pool,RgSchCb *instCb,RgrCfgTransId transId,RgrCfgReqInfo *cfgReqInfo)
228 {
229    SpId            spId = 0;
230    uint8_t         cfmStatus = RGR_CFG_CFM_OK;
231    S16             ret;
232    RgSchErrInfo    errInfo;
233 #ifdef EMTC_ENABLE
234 printf("\nDEBUG  -->  SCH: AT MAC rgSCHGomCfgReq \n");
235 #endif
236
237    /* Process Config/Reconfig/Delete request from RRM */
238    switch (cfgReqInfo->action)
239    {
240       case SCH_CONFIG:
241          {
242             ret = rgSCHGomHndlCfgReq(instCb, spId, 
243                              &cfgReqInfo->u.cfgInfo, &errInfo);
244             break;
245          }
246       case RGR_RECONFIG:
247          {
248             ret = rgSCHGomHndlRecfgReq(instCb, spId, 
249                              &cfgReqInfo->u.recfgInfo, &errInfo);
250             break;
251          }
252       case RGR_RESET:
253          {
254             ret = rgSCHGomHndlResetReq(instCb, spId, 
255                              &cfgReqInfo->u.rstInfo, &errInfo);
256             break;
257          }
258       case RGR_DELETE:
259          {
260             ret = rgSCHGomHndlDelReq(instCb, spId,
261                              &cfgReqInfo->u.delInfo, &errInfo);
262             break;
263          } 
264 #ifdef LTE_ADV
265       case RGR_SCELL_ACT:
266       case RGR_SCELL_DEACT: 
267       case RGR_SCELL_READY: 
268          {
269             ret = rgSCHGomHndlSCellActDeactReq(instCb, spId,
270                              &cfgReqInfo->u.sCellActDeactEvnt, &errInfo, cfgReqInfo->action);
271             break;
272          }
273 #endif /* LTE_ADV */
274       default:
275          {
276             DU_LOG("\nERROR  -->  SCH : Invalid configuration "
277                "action %d", cfgReqInfo->action);
278             ret = RFAILED;
279          }
280    } /* End of switch */
281
282    if (ret != ROK)
283    {
284       cfmStatus = RGR_CFG_CFM_NOK;
285    }
286
287    SPutSBuf(reg, pool, (Data *)cfgReqInfo, 
288          (Size)sizeof(*cfgReqInfo));
289    cfgReqInfo = NULLP;
290 #ifdef EMTC_ENABLE
291 printf("\nDEBUG  -->  SCH: AT MAC sending RGR cfg cfm \n");
292 #endif
293
294    /* Send back confirmation status to RRM */   
295    schSendCfgCfm(reg, pool, transId, cfmStatus); 
296 #ifdef EMTC_ENABLE
297 printf("\nDEBUG  -->  SCH: AT MAC RGR cfg cfm sent\n");
298 #endif
299
300    return (ret);
301 }  /* rgSCHGomCfgReq */
302
303
304 /**
305  * @brief Handler to enqueuing config request from RRM to Scheduler.
306  *
307  * @details
308  *
309  *     Function: rgSCHGomEnqCfgReq
310  *     
311  *     This API enqueues config request from RRM to MAC. 
312  *     
313  *     Processing Steps:
314  *      - Allocate the configuration request element.
315  *      - Copy the contents of the recieved configuration to config request
316  *        element and free the recieved configuration pointer.
317  *      - If the configuration is without activation time,
318  *         - Enqueue the request in crntRgrCfgLst of the cell at the end of 
319  *           the list.
320  *      - Else
321  *         - Enqueue the request in pndngRgrCfgLst of the cell.
322  *         
323  *  @param[in]  Region        reg,
324  *  @param[in]  Pool          pool
325  *  @param[in]  RgSchCellCb   *cell
326  *  @param[in]  RgrCfgTransId transId
327  *  @param[in]  RgrCfgReqInfo *rgrCfgReq
328  *  @return  S16
329  *      -# ROK 
330  *      -# RFAILED 
331  **/
332 static S16 rgSCHGomEnqCfgReq(Region reg,Pool pool,RgSchCellCb *cell,RgrCfgTransId transId,RgrCfgReqInfo *rgrCfgReq)
333 {
334    S16                ret;
335    uint32_t           sfDiff;
336    RgSchCfgElem       *rgrCfgElem  = NULLP;
337    CmLteTimingInfo    actvTime; 
338    Inst               inst = cell->instIdx;
339
340    /* Allocate memory for config Element */
341    ret = rgSCHUtlAllocSBuf(inst, (Data **)&rgrCfgElem, sizeof(RgSchCfgElem));
342    if ((ret != ROK) || ((uint8_t *)rgrCfgElem == NULLP))
343    {
344       return RFAILED;
345    }
346
347    /* Initialize the configuration element */
348    memcpy(rgrCfgElem->rgrCfg.transId.trans,transId.trans,
349          sizeof(transId.trans));
350    rgrCfgElem->rgrCfg.reg = reg;
351    rgrCfgElem->rgrCfg.pool = pool;
352    rgrCfgElem->rgrCfg.rgrCfgReq = rgrCfgReq;
353    rgrCfgElem->cfgReqLstEnt.prev = NULLP;
354    rgrCfgElem->cfgReqLstEnt.next = NULLP;
355    rgrCfgElem->cfgReqLstEnt.node = (PTR )rgrCfgElem;
356
357    /* Add configuration element to current/pending cfgLst */
358    if (((rgrCfgReq->action == RGR_RECONFIG) &&
359             (rgrCfgReq->u.recfgInfo.recfgType == RGR_CELL_CFG) &&
360             (rgrCfgReq->u.recfgInfo.u.cellRecfg.recfgActvTime.pres == TRUE)))
361
362    {
363       actvTime = 
364          rgrCfgReq->u.recfgInfo.u.cellRecfg.recfgActvTime.actvTime;
365
366       /* Check if the activation time is valid */
367       if (actvTime.sfn >= RGSCH_MAX_SFN 
368             || actvTime.slot >= RGSCH_NUM_SUB_FRAMES_5G)
369       {
370          DU_LOG("\nERROR  -->  SCH : Invalid activation time for RGR "
371            "config request: activation sfn %d activation slot %d current "
372            "sfn %d current slot %d", actvTime.sfn, actvTime.slot, 
373            cell->crntTime.sfn, cell->crntTime.slot);
374          /* ccpu00117052 - MOD - Passing double pointer
375          for proper NULLP assignment*/
376          rgSCHUtlFreeSBuf(inst, (Data **)&rgrCfgElem, sizeof(*rgrCfgElem));
377          return RFAILED;
378       }
379
380       sfDiff = RGSCH_CALC_SF_DIFF(actvTime, cell->crntTime);
381
382       if (sfDiff > (RGR_ACTV_WIN_SIZE * RGSCH_NUM_SUB_FRAMES_5G))
383       {
384          DU_LOG("\nERROR  -->  SCH : Invalid activation time for RGR"
385               " config request: activation sfn %d activation slot %d "
386               "current sfn %d current slot %d", actvTime.sfn,
387               actvTime.slot, cell->crntTime.sfn, cell->crntTime.slot);
388          /* ccpu00117052 - MOD - Passing double pointer
389          for proper NULLP assignment*/
390          rgSCHUtlFreeSBuf(inst, (Data **)&rgrCfgElem, sizeof(*rgrCfgElem));
391          return RFAILED;
392       }
393
394       if (sfDiff)
395       {
396          /* Add to pending cfgReqLst */
397          rgrCfgElem->actvTime = actvTime; 
398          rgSCHDbmInsPndngRgrCfgElem(cell, rgrCfgElem);
399          /* Cfm to be sent only after applying request */
400          return ROK;
401       }
402    }
403
404    /* Add to current cfgReq list */
405    rgSCHDbmInsCrntRgrCfgElem(cell, rgrCfgElem);
406    /* Cfm to be sent only after applying request */
407    return ROK;
408 }  /* rgSCHGomEnqCfgReq */
409
410
411 /**
412  * @brief Handler for TTI processing for configurations recieved from RRM.
413  *
414  * @details
415  *
416  *     Function: rgSCHGomTtiHndlr
417  *     
418  *     This API does TTI processing for configurations recieved from RRM.
419  *     
420  *     Processing Steps:
421  *      - It dequeues config request from the current configuration list.
422  *        For each config request in the list: 
423  *        - Processes the request. Call rgSCHGomCfgReq.
424  *      - It dequeues config request for the current tti from the pending 
425  *        configuration list. For each config request in the list:
426  *        - Processes the request. Call rgSCHGomCfgReq.
427  *
428  *  @param[in]  RgSchCellCb *cell
429  *  @return  S16
430  *      -# ROK 
431  *      -# RFAILED 
432  **/
433 S16 rgSCHGomTtiHndlr(RgSchCellCb *cell,SpId  spId)
434 {
435    RgSchCfgElem       *cfgElem;
436    Inst               inst= cell->instIdx;
437
438    /* Dequeue from current config list */
439    while ((cfgElem = rgSCHDbmGetNextCrntRgrCfgElem(cell, NULLP)) != NULLP)
440    {
441       rgSCHDbmDelCrntRgrCfgElem(cell, cfgElem);
442       rgSCHGomCfgReq(cfgElem->rgrCfg.reg,cfgElem->rgrCfg.pool,
443             &rgSchCb[inst], cfgElem->rgrCfg.transId, 
444             cfgElem->rgrCfg.rgrCfgReq);
445       /* ccpu00117052 - MOD - Passing double pointer
446       for proper NULLP assignment*/
447       rgSCHUtlFreeSBuf(inst, (Data **)&cfgElem, sizeof(*cfgElem));
448    }
449
450    /* Handle config requests from pending config list */
451    while((cfgElem = rgSCHDbmGetPndngRgrCfgElemByKey(cell, cell->crntTime)) != NULLP)
452    {
453       rgSCHDbmDelPndngRgrCfgElem(cell, cfgElem);
454       rgSCHGomCfgReq(cfgElem->rgrCfg.reg, cfgElem->rgrCfg.pool, 
455             &rgSchCb[inst], cfgElem->rgrCfg.transId, 
456             cfgElem->rgrCfg.rgrCfgReq);
457       /* ccpu00117052 - MOD - Passing double pointer
458       for proper NULLP assignment*/
459       rgSCHUtlFreeSBuf(inst, (Data **)&cfgElem, sizeof(*cfgElem));
460    } 
461
462    return ROK;
463 }
464
465
466 /**
467  * @brief Handler to handle configuration request from RRM to MAC.
468  *
469  * @details
470  *
471  *     Function: rgSCHGomHndlCfgReq
472  *     
473  *     This API handles processing for configuration request from RRM to MAC.
474  *     
475  *     - Processing Steps: 
476  *        - Validate configuration request parameters at CFG module. 
477  *          Call rgSCHCfgVldtRgrCellCfg for cell configuration.
478  *        - If validated successfully, send configuration request to CFG.
479  *          Call rgSCHCfgRgrCellCfg else FAIL.
480  *          
481  *  @param[in]  RgSchCb      *instCb
482  *  @param[in]  SpId         spId
483  *  @param[in]  RgrCfg       *cfg
484  *  @param[out] RgSchErrInfo *errInfo
485  *  @return  S16
486  *      -# ROK 
487  *      -# RFAILED 
488  **/
489 static S16 rgSCHGomHndlCfgReq(RgSchCb *instCb,SpId spId,RgrCfg *cfg,RgSchErrInfo *errInfo)
490 {
491    S16          ret;
492    RgSchCellCb  *cell = instCb->rgrSap[spId].cell;
493    Inst         inst = (instCb->rgSchInit.inst );
494    RgSchUeCb    *ue;
495
496    errInfo->errType = RGSCHERR_GOM_CFG_REQ;
497    
498    /* Validate and process the configuration request */ 
499    switch (cfg->cfgType)
500    {
501       case RGR_CELL_CFG:
502       {
503          ret = rgSCHCfgVldtRgrCellCfg(inst, &cfg->u.cellCfg, cell, errInfo);
504             if (ret != ROK)
505             {
506                DU_LOG("\nERROR  -->  SCH : Rgr Cell configuration "
507                   "validation FAILED: Cell %d", cfg->u.cellCfg.cellId);
508                return RFAILED;
509             }
510          ret = rgSCHCfgRgrCellCfg(instCb, spId, &cfg->u.cellCfg, errInfo);
511          break;
512       }
513       case RGR_UE_CFG:
514       case RGR_SCELL_UE_CFG:
515       {
516          ret = rgSCHCfgVldtRgrUeCfg(inst, &cfg->u.ueCfg, &cell, errInfo);
517          if (ret != ROK)
518          {
519             DU_LOG("\nERROR  -->  SCH : Ue configuration validation"
520                " FAILED: CRNTI:%d", cfg->u.ueCfg.crnti);
521             return RFAILED;
522          }
523          ret = rgSCHCfgRgrUeCfg(cell, &cfg->u.ueCfg, errInfo);
524          break;
525       }
526       case RGR_LCH_CFG:
527       {
528          ret = rgSCHCfgVldtRgrLcCfg(inst, &cfg->u.lchCfg, &cell, &ue, errInfo);
529          if (ret != ROK)
530          {
531             DU_LOG("\nERROR  -->  SCH : LC configuration validation "
532               "FAILED: LCID:%d", cfg->u.lchCfg.lcId);
533             return RFAILED;
534          }
535          ret = rgSCHCfgRgrLchCfg(cell, ue, &cfg->u.lchCfg, errInfo); 
536          break;
537       }
538       case RGR_LCG_CFG:
539       {
540          ret = rgSCHCfgVldtRgrLcgCfg(inst, &cfg->u.lcgCfg, &cell, &ue, errInfo);
541          if (ret != ROK)
542          {
543             DU_LOG("\nERROR  -->  SCH : LCG configuration validation "
544               "FAILED: LCGID:%d", cfg->u.lcgCfg.ulInfo.lcgId);
545             return RFAILED;
546          }
547          ret = rgSCHCfgRgrLcgCfg(cell, ue, &cfg->u.lcgCfg, errInfo); 
548          break;
549       }
550       case MAC_GNB_CFG:
551       {
552          ret = rgSCHCfgVldtRgrSchedEnbCfg(inst, &cfg->u.schedEnbCfg, errInfo);
553          if (ret != ROK)
554          {
555             DU_LOG("\nERROR  -->  SCH : SCH ENB configuration validation FAILED: \n");
556             return RFAILED;
557          }
558          ret = rgSCHCfgRgrSchedEnbCfg(inst, spId, &cfg->u.schedEnbCfg, errInfo); 
559          break;
560       }
561       default:
562       {
563 #if(ERRCLASS & ERRCLS_INT_PAR)
564             DU_LOG("\nERROR  -->  SCH : Should never come here: "
565                 "cfgType %d", cfg->cfgType);
566 #endif
567             return RFAILED;
568       }
569    }
570    
571    return (ret);
572 }  /* rgSCHGomHndlCfgReq */
573
574 #ifdef LTE_ADV
575 /**
576  * @brief Handler to handle re-configuration request from RRM to MAC.
577  *
578  * @details
579  *
580  *     Function: rgSCHGomHndlSCellActDeactReq
581  *     
582  *     This API handles processing for SCell Activation Request from RRM to SCH.
583  *     
584  *     - Processing Steps: 
585  *        - Validate sCell Actication request parameters at CFG module. 
586  *        - If validated successfully, send configuration request to CFG.
587  *        - call activation function for each SCells configured
588  *
589  *  @param[in]  RgSchCb      *instCb
590  *  @param[in]  SpId         spId
591  *  @param[in]  RgrSCellActDeactEvnt  *sCellActDeactEvnt
592  *  @param[in]  uint8_t action
593  *  @param[out] RgSchErrInfo *errInfo
594  *  @return  S16
595  *      -# ROK 
596  *      -# RFAILED 
597  **/
598 static S16 rgSCHGomHndlSCellActDeactReq(RgSchCb  *instCb,SpId  spId,RgrSCellActDeactEvnt  *sCellActDeactEvnt,RgSchErrInf *errInfo,uint8_t action)
599 {
600    RgSchUeCb    *ue = NULLP;
601    uint16_t     idx = 0;
602    uint16_t     sCellIdx = 0;
603    RgSchCellCb  *cell = instCb->rgrSap[spId].cell;
604    Inst         inst = (instCb->rgSchInit.inst);
605
606    DU_LOG(("\nDEBUG  -->  SCH : Processing RGR SCell Actication request:"
607                   "%d\n", sCellActDeactEvnt->crnti));
608
609    errInfo->errType = RGSCHERR_GOM_SCELL_REQ;
610
611    /* Fetch the Ue */
612    if ((ue = rgSCHDbmGetUeCb(cell, sCellActDeactEvnt->crnti)) == NULLP)
613    {
614       DU_LOG(("\nERROR  -->  SCH : [%d]UE: does not exist\n", 
615             sCellActDeactEvnt->crnti));
616       return RFAILED;
617    }
618    
619    for(idx = 0; idx < sCellActDeactEvnt->numOfSCells; idx++)
620    {
621       sCellIdx = sCellActDeactEvnt->sCellActDeactInfo[idx].sCellIdx;
622
623       if (ROK != (rgSCHSCellTrigActDeact(cell, ue, sCellIdx, action)))
624       {
625             DU_LOG("\nERROR  -->  SCH : SCell Actication failed"
626                      "for UE [%d] with SCellIdx [%d]\n", 
627                      sCellActDeactEvnt->crnti, idx);
628             return RFAILED;
629
630       }
631
632    DU_LOG("\nINFO  -->  SCH : RGR Reconfiguration processed\n");
633    return ROK;
634 }  /* rgSCHGomHndlSCellActDeactReq */
635
636 #endif /* LTE_ADV */
637 /**
638  * @brief Handler to handle re-configuration request from RRM to MAC.
639  *
640  * @details
641  *
642  *     Function: rgSCHGomHndlRecfgReq
643  *     
644  *     This API handles processing for re-configuration request from RRM to MAC.
645  *     
646  *     - Processing Steps: 
647  *        - Validate re-configuration request parameters at CFG module. 
648  *          Call rgSCHCfgVldtRgrCellRecfg for cell re-configuration.
649  *        - If validated successfully, send configuration request to CFG.
650  *          Call rgSCHCfgRgrCellRecfg else FAIL.
651  *
652  *  @param[in]  RgSchCb      *instCb
653  *  @param[in]  SpId         spId
654  *  @param[in]  RgrRecfg     *recfg
655  *  @param[out] RgSchErrInfo *errInfo
656  *  @return  S16
657  *      -# ROK 
658  *      -# RFAILED 
659  **/
660 static S16 rgSCHGomHndlRecfgReq(RgSchCb  *instCb,SpId  spId,RgrRecfg *recfg,RgSchErrInfo  *errInfo)
661 {
662    RgSchUeCb    *ue = NULLP;
663    RgSchDlLcCb  *dlLc = NULLP; /* PURIFY_FIX:UMR */
664    S16          ret; 
665    RgSchCellCb  *cell = instCb->rgrSap[spId].cell;
666    Inst         inst = (instCb->rgSchInit.inst );
667
668    errInfo->errType = RGSCHERR_GOM_RECFG_REQ;
669    
670    /* Validate and process the re-configuration request */
671    switch (recfg->recfgType)
672    {
673       case RGR_CELL_CFG:
674       {
675          ret = rgSCHCfgVldtRgrCellRecfg(inst, &recfg->u.cellRecfg, &cell,
676                errInfo);
677          if (ret != ROK) 
678          {
679             DU_LOG("\nERROR  -->  SCH : Rgr Cell Recfg Validation "
680                      "FAILED");
681             return RFAILED;
682          }
683          ret = rgSCHCfgRgrCellRecfg(cell, &recfg->u.cellRecfg, errInfo);
684          break;
685       }
686       case RGR_UE_CFG:
687       case RGR_SCELL_UE_CFG:
688       {
689          ret = rgSCHCfgVldtRgrUeRecfg(inst, &recfg->u.ueRecfg, &cell, &ue, errInfo);
690          if ( ret != ROK)
691          {
692             DU_LOG("\nERROR  -->  SCH : Ue Recfg Validation FAILED"
693                       "OLD CRNTI:%d",recfg->u.ueRecfg.oldCrnti);
694             return RFAILED;
695          }
696          ret = rgSCHCfgRgrUeRecfg(cell, ue, &recfg->u.ueRecfg, errInfo);
697          break;
698       }
699       case RGR_LCH_CFG:
700       {
701          ret = rgSCHCfgVldtRgrLchRecfg(inst, &recfg->u.lchRecfg, &cell, &ue, 
702                &dlLc, errInfo);
703          if (ret != ROK)
704          {
705             DU_LOG("\nERROR  -->  SCH : Lc Recfg Validation FAILED"
706                       "LCID:%d",recfg->u.lchRecfg.lcId);
707             return RFAILED;
708          }
709          ret = rgSCHCfgRgrLchRecfg(cell, ue, dlLc, &recfg->u.lchRecfg, errInfo);
710          break;
711       }
712       case RGR_LCG_CFG:
713       {
714          ret = rgSCHCfgVldtRgrLcgRecfg(inst, &recfg->u.lcgRecfg, cell, &ue,
715                errInfo);
716          if (ret != ROK)
717          {
718             DU_LOG("\nERROR  -->  SCH : Lcg Recfg Validation FAILED"
719                       "LCGID:%d",recfg->u.lcgRecfg.ulRecfg.lcgId);
720             return RFAILED;
721          }
722          ret = rgSCHCfgRgrLcgRecfg(cell, ue, &recfg->u.lcgRecfg, errInfo);
723          break;
724       }
725       default:
726       {
727 #if(ERRCLASS & ERRCLS_INT_PAR)
728          DU_LOG("\nERROR  -->  SCH : Should never come here: recfgType %d", recfg->recfgType);
729 #endif
730          return RFAILED;
731       }
732    }
733
734    return (ret);
735 }  /* rgSCHGomHndlRecfgReq */
736
737 /**
738  * @brief Handler to handle UE reset request from RRM to Scheduler.
739  *
740  * @details
741  *
742  *     Function: rgSCHGomHndlResetReq
743  *     
744  *     This API handles processing for UE reset request from RRM to Scheduler.
745  *     
746  *     - Processing Steps: 
747  *        - Validate UE reset request parameters at CFG module. 
748  *          Call rgSCHCfgVldtRgrUeReset for UE reset.
749  *        - If validated successfully, send UE reset request to CFG.
750  *          Call rgSCHCfgRgrUeReset else FAIL.
751  *
752  *  @param[in]  RgrRst   *rstInfo
753  *  @param[out] RgSchErrInfo *errInfo
754  *  @return  S16
755  *      -# ROK 
756  *      -# RFAILED 
757  **/
758 static S16 rgSCHGomHndlResetReq(RgSchCb  *instCb,SpId spId,RgrRst *reset,RgSchErrInfo  *errInfo)
759 {
760    S16          ret; 
761    RgSchCellCb  *cell= instCb->rgrSap[spId].cell;
762    Inst         inst = (instCb->rgSchInit.inst );
763    RgSchUeCb    *ue = NULLP;
764
765    errInfo->errType = RGSCHERR_GOM_RESET_REQ;
766    
767    /* Validate and process the UE reset request */
768    ret = rgSCHCfgVldtRgrUeReset(inst, reset, cell, &ue, errInfo);
769    if (ret != ROK) 
770    {
771       DU_LOG("\nERROR  -->  SCH : Rgr UE Reset Validation FAILED"
772                "CRNTI:%d",reset->crnti);
773       return RFAILED;
774    }
775    
776    ret = rgSCHCfgRgrUeReset(cell, ue, reset, errInfo);
777    if (ret != ROK) 
778    {
779       DU_LOG("\nERROR  -->  SCH : Rgr UE Reset FAILED"
780                "CRNTI:%d",reset->crnti);
781       return RFAILED;
782    }
783
784    return (ret);
785 }  /* rgSCHGomHndlResetReq */
786
787
788 /**
789  * @brief Handler for processing Cell/Ue/Logical channel delete request
790  * recieved from RRM.
791  *
792  * @details
793  *
794  *     Function: rgSCHGomHndlDelReq
795  *     
796  *     This API handles processing of delete request from RRM to MAC. 
797  *     
798  *     Processing Steps:
799  *        - Fetch corresponding control block and pass it to CFG module.
800  *        - If control block does not exist, FAIL.
801  *
802  *  @param[in]  RgSchCb      *instCb
803  *  @param[in]  SpId         spId
804  *  @param[in]  RgrDel       *del
805  *  @param[out] RgSchErrInfo *errInfo
806  *  @return  S16
807  *      -# ROK 
808  *      -# RFAILED 
809  **/
810 static S16 rgSCHGomHndlDelReq(RgSchCb *instCb,SpId spId,RgrDel *del,RgSchErrInfo  *errInfo)
811 {
812
813    S16       ret;
814    volatile uint32_t     startTime=0;
815
816    errInfo->errType = RGSCHERR_GOM_DEL_REQ;
817
818    if(instCb->rgrSap[spId].cell == NULLP)
819    {
820       DU_LOG("\nERROR  -->  SCH : Cell doesnt exist");
821       return RFAILED; 
822    }
823    
824    /* Process the delete request */ 
825    switch (del->delType)
826    {
827       case RGR_CELL_CFG:
828       {
829          ret = rgSCHCfgRgrCellDel(instCb->rgrSap[spId].cell, del, errInfo);
830          if(ret == ROK)
831          {
832             /* TODO::Needs to be revisited after tti flow CaDev Start */
833             uint8_t idx = (uint8_t)((instCb->rgrSap[spId].cell->cellId - instCb->genCfg.startCellId)&(CM_LTE_MAX_CELLS-1));
834             instCb->cells[idx] = NULLP;
835             /* CaDev End */
836             instCb->rgrSap[spId].cell = NULLP;
837             instCb->tfuSap[spId].cell = NULLP;
838          }
839          break;
840       }
841       case RGR_UE_CFG:
842       case RGR_SCELL_UE_CFG:
843       {
844
845          /*starting Task*/
846          SStartTask(&startTime, PID_SCH_UE_DEL);
847
848          ret = rgSCHCfgRgrUeDel(instCb->rgrSap[spId].cell, del, errInfo);
849
850          /*stoping Task*/
851          SStopTask(startTime, PID_SCH_UE_DEL);
852
853          break;
854       }
855       case RGR_LCH_CFG:
856       {
857          ret = rgSCHCfgRgrLcDel(instCb->rgrSap[spId].cell, del, errInfo);
858          break;
859       }
860       case RGR_LCG_CFG:
861       {
862          ret = rgSCHCfgRgrLcgDel(instCb->rgrSap[spId].cell, del, errInfo);
863          break;
864       }
865       default:
866       {
867 #if(ERRCLASS & ERRCLS_INT_PAR)
868          DU_LOG("\nERROR  -->  SCH : Should never come here: delType %d", del->delType);
869 #endif
870          return RFAILED;
871       }
872    }
873
874    return (ret);
875 }  /* rgSCHGomHndlDelReq */
876
877
878
879
880 /***********************************************************
881  *
882  *     Func : rgSCHGomGetCellIdFrmCfgReq
883  *        
884  *
885  *     Desc : 
886  *     - Processing Steps: 
887  *        - Retrieves the cell Id for a config request.
888  *
889  *  @param[in]  RgrCfgReqInfo *rgrCfgReq
890  *  @param[out] CmLteCellId   *cellId
891  *     Ret  : ROK on fetching cellId
892  *            RFAILED on failure
893  *
894  *     Notes: 
895  *
896  *     File : rg_sch_gom.c 
897  *
898  **********************************************************/
899 static S16 rgSCHGomGetCellIdFrmCfgReq(RgrCfgReqInfo *rgrCfgReq,CmLteCellId   *cellId)
900 {
901
902    /* Extract CellId depending on the action and Config Type in the Request 
903     * As of now this function is called for only re configuration so removed
904     * othe CASES below if needed we can add them*/
905    switch (rgrCfgReq->action)
906    {
907       case RGR_RECONFIG:
908          {
909             if (rgrCfgReq->u.recfgInfo.recfgType ==RGR_CELL_CFG)
910             {
911                *cellId = rgrCfgReq->u.recfgInfo.u.cellRecfg.cellId;
912             }
913             else if ((rgrCfgReq->u.recfgInfo.recfgType ==  RGR_SCELL_UE_CFG) || 
914                   (rgrCfgReq->u.recfgInfo.recfgType == RGR_UE_CFG))
915             {
916                *cellId = rgrCfgReq->u.recfgInfo.u.ueRecfg.cellId;
917             }
918             else if (rgrCfgReq->u.recfgInfo.recfgType == RGR_LCH_CFG)
919             {
920                *cellId = rgrCfgReq->u.recfgInfo.u.lchRecfg.cellId;
921             }
922             else if (rgrCfgReq->u.recfgInfo.recfgType == RGR_LCG_CFG) 
923             {
924                *cellId = rgrCfgReq->u.recfgInfo.u.lcgRecfg.cellId;
925             }
926             else
927             {
928                return RFAILED;
929             }
930             break;
931          }
932       default:
933       {
934          return RFAILED;
935       }
936    }  /* End of Switch */
937
938    return ROK;
939 }  /* rgSCHGomGetCellIdFrmCfgReq */
940
941 #ifdef RGR_SI_SCH
942 /**
943  * @brief Handler to handle SI configuration request from RRM to MAC.
944  *
945  * @details
946  *
947  *     Function: rgSCHGomHndlSiCfg
948  *     
949  *     This API handles processing for SI configuration request from RRM to MAC.
950  *     
951  *     - Processing Steps: 
952  *        - Validate SI configuration request parameters at CFG module. 
953  *          Call rgSCHCfgVldtSiCfg for SI configuration.
954  *        - If validated successfully, send configuration request to CFG.
955  *          Call rgSCHCfgRgrCellCfg else FAIL.
956  *          
957  *  @param[in]  Region        reg
958  *  @param[in]  Pool          pool
959  *  @param[in]  RgSchCb       *instCb
960  *  @param[in]  SpId          spId
961  *  @param[in]  RgrCfgTransId transId
962  *  @param[in]  RgrSiCfgReqInfo *cfgReqInfo
963  *  @return  S16
964  *      -# ROK 
965  *      -# RFAILED 
966  **/
967 S16 rgSCHGomHndlSiCfg(Region reg,Pool pool,RgSchCb *instCb,SpId spId,RgrCfgTransId transId,RgrSiCfgReqInfo *cfgReqInfo)
968 {
969    S16          ret;
970    RgSchCellCb  *cell = instCb->rgrSap[spId].cell;
971    Inst         inst = (instCb->rgSchInit.inst );
972    RgSchErrInfo errInfo;
973    uint8_t      cfmStatus = RGR_CFG_CFM_NOK;
974    MsgLen       msgLen = 0, pduLen;
975    S32          tbSz   = 0;
976    uint8_t      nPrb   = 0; 
977    uint8_t      mcs    = 0;
978
979
980    /* check if cell does not exists */
981    if (((uint8_t *)cell == NULLP) || (cell->cellId != cfgReqInfo->cellId))
982    {
983       DU_LOG("\nERROR  -->  SCH : Cell Control block does not exist");
984       RGSCH_FREE_MSG(cfgReqInfo->pdu);
985       SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
986       cfgReqInfo = NULLP;
987       rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, cfmStatus); 
988       return RFAILED;
989    }
990
991    /*Validate the received SI configuration */
992    ret = rgSCHCfgVldtRgrSiCfg(inst, cfgReqInfo, cell, &errInfo);
993    if (ret != ROK)
994    {
995       DU_LOG("\nERROR  -->  SCH : Rgr SI configuration "
996                "validation FAILED");
997       RGSCH_FREE_MSG(cfgReqInfo->pdu);
998       SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
999       cfgReqInfo = NULLP;
1000       rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, cfmStatus); 
1001       return RFAILED;
1002    }
1003    /*ccpu00140789: Stopping SI scheduling*/
1004    if(RGR_SI_STOP == cfgReqInfo->cfgType)
1005    {
1006       if((cell->siCb.crntSiInfo.siInfo[cfgReqInfo->siId-1].si != NULLP)&&
1007                       (cell->siCb.siArray[cfgReqInfo->siId-1].si != NULLP))
1008       {
1009          cell->siCb.crntSiInfo.siInfo[cfgReqInfo->siId-1].si = NULLP;
1010          RGSCH_FREE_MSG(cell->siCb.siArray[cfgReqInfo->siId-1].si);
1011          cell->siCb.siArray[cfgReqInfo->siId-1].si = NULLP;
1012          if(cell->siCb.newSiInfo.siInfo[cfgReqInfo->siId-1].si != NULLP)
1013          {
1014             RGSCH_FREE_MSG(cell->siCb.newSiInfo.siInfo[cfgReqInfo->siId-1].si);
1015             cell->siCb.newSiInfo.siInfo[cfgReqInfo->siId-1].si = NULLP;
1016          }
1017          SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo));
1018          cfgReqInfo = NULLP;   
1019          cfmStatus = RGR_CFG_CFM_OK;
1020          rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, cfmStatus);
1021          return ROK; 
1022        }
1023        else
1024        {
1025           SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo));
1026           cfgReqInfo = NULLP;
1027           rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, cfmStatus);
1028           return RFAILED; 
1029        }
1030    }
1031
1032    /* Check if the pdu sent from application
1033     * matches a transport block size. if not,
1034     * add padding bytes. This is usually done
1035     * by RRC but since we are bypassing RRC,
1036     * MAC is taking over that responsibility
1037     */
1038    if ( RGR_SI_CFG_TYPE_MIB != cfgReqInfo->cfgType )
1039    {
1040       SFndLenMsg(cfgReqInfo->pdu, &msgLen);
1041
1042       /* check if the application pdu matches a tb size */
1043       tbSz = rgSCHUtlGetAllwdCchTbSz(msgLen*8, &nPrb, &mcs);
1044
1045       if ( tbSz != (msgLen*8) )
1046       {
1047          MsgLen  nmPadBytes = 0;
1048          Data*   padding    = NULLP;
1049
1050          /* need to add padding bytes */
1051          nmPadBytes = (tbSz - (msgLen*8))/8;
1052
1053          if ( SGetSBuf(reg,pool,&padding,nmPadBytes) != ROK)
1054          {
1055             DU_LOG("\nERROR  -->  SCH : Rgr SI configuration "
1056                      "SGetSBuf failed for padding failed");
1057             SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1058             cfgReqInfo = NULLP;
1059             rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1060                                                            cfmStatus); 
1061             return RFAILED;
1062          }
1063
1064          memset(padding,0,nmPadBytes);
1065
1066 #ifdef MS_MBUF_CORRUPTION 
1067    MS_BUF_ADD_ALLOC_CALLER();
1068 #endif 
1069          if ( SAddPstMsgMult((Data*)padding,nmPadBytes,cfgReqInfo->pdu) != ROK)
1070          {
1071             DU_LOG("\nERROR  -->  SCH : Rgr SI configuration "
1072                      "Failed to add padding bytes");
1073             SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1074             cfgReqInfo = NULLP;
1075             SPutSBuf(reg, pool, (Data* )padding,(Size)nmPadBytes);
1076             padding = NULLP;
1077             rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1078                                                             cfmStatus); 
1079             return RFAILED;
1080          }
1081          SPutSBuf(reg, pool, (Data* )padding,(Size)nmPadBytes);
1082          padding = NULLP;
1083       }/* if (tbSz != ...*/
1084    }/* if (RGR_SI_CFG_TYPE_SI...*/
1085
1086    /*Set the received pdu at the appropriate place */
1087    switch(cfgReqInfo->cfgType)
1088    {
1089       case RGR_SI_CFG_TYPE_MIB:   /* SI CFG Type MIB */
1090          RGSCHCHKNUPDSIPDU(cell->siCb.crntSiInfo.mib, 
1091                cell->siCb.newSiInfo.mib, 
1092                cfgReqInfo->pdu, cell->siCb.siBitMask, 
1093                RGSCH_SI_MIB_UPD);
1094          break;
1095
1096       case RGR_SI_CFG_TYPE_SIB1_PWS:
1097          {
1098             SFndLenMsg(cfgReqInfo->pdu, &pduLen);
1099             ret = rgSCHUtlCalMcsAndNPrb(cell, cfgReqInfo->cfgType, pduLen,0);
1100             if (ret != ROK)
1101             {
1102                DU_LOG("\nERROR  -->  SCH : Failed to get MCS and NPRB" 
1103                      "value");
1104                RGSCH_FREE_MSG(cfgReqInfo->pdu);
1105                SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1106                cfgReqInfo = NULLP;
1107                rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1108                      cfmStatus); 
1109                return RFAILED;
1110             }
1111
1112             RGSCHCHKNUPDSIPDU(cell->siCb.crntSiInfo.sib1Info.sib1, 
1113                   cell->siCb.newSiInfo.sib1Info.sib1, 
1114                   cfgReqInfo->pdu, cell->siCb.siBitMask, 
1115                   RGSCH_SI_SIB1_PWS_UPD);
1116          }
1117          break;
1118
1119       case RGR_SI_CFG_TYPE_SIB1:
1120          SFndLenMsg(cfgReqInfo->pdu, &pduLen);
1121          ret = rgSCHUtlCalMcsAndNPrb(cell, cfgReqInfo->cfgType, pduLen,0);
1122          if (ret != ROK)
1123          {
1124             DU_LOG("\nERROR  -->  SCH : Failed to get MCS and NPRB" 
1125                      "value");
1126             RGSCH_FREE_MSG(cfgReqInfo->pdu);
1127             SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1128             cfgReqInfo = NULLP;
1129             rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1130                                                                  cfmStatus); 
1131             return RFAILED;
1132          }
1133          RGSCHCHKNUPDSIPDU(cell->siCb.crntSiInfo.sib1Info.sib1, 
1134                cell->siCb.newSiInfo.sib1Info.sib1, 
1135                cfgReqInfo->pdu, cell->siCb.siBitMask, 
1136                RGSCH_SI_SIB1_UPD);
1137          break;
1138
1139       case RGR_SI_CFG_TYPE_SI:    /* SI CFG TYPE SI */
1140          SFndLenMsg(cfgReqInfo->pdu, &pduLen);
1141          ret = rgSCHUtlCalMcsAndNPrb(cell, cfgReqInfo->cfgType, pduLen, 
1142                                                      cfgReqInfo->siId);
1143          if (ret != ROK)
1144          {
1145             DU_LOG("\nERROR  -->  SCH : Failed to get MCS and NPRB" 
1146                      "value");
1147             RGSCH_FREE_MSG(cfgReqInfo->pdu);
1148             SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1149             cfgReqInfo = NULLP;
1150             rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1151                                                                  cfmStatus); 
1152             return RFAILED;
1153          }
1154          /* Si recfg, where numSi changes */
1155          if (cell->siCb.siBitMask & RGSCH_SI_SICFG_UPD) 
1156          {
1157             Buffer **newSiPdu = &cell->siCb.newSiInfo.siInfo[cfgReqInfo->siId-1].si;
1158             if(*newSiPdu != NULLP)
1159             {
1160                RGSCH_FREE_MSG(*newSiPdu);
1161             }
1162             *newSiPdu = (Buffer *)cfgReqInfo->pdu;
1163             cell->siCb.siBitMask |= RGSCH_SI_SI_UPD;
1164          }
1165          else /* Initial Si cfg  or si recfg where numSi did not change */
1166          {
1167             uint8_t bitMask;
1168             /* Initial Si cfg */
1169             if (cell->siCb.crntSiInfo.siInfo[cfgReqInfo->siId-1].si == NULLP)
1170             {
1171                cell->siCb.siArray[cfgReqInfo->siId-1].si = cfgReqInfo->pdu;
1172                cell->siCb.siArray[cfgReqInfo->siId-1].isWarningSi = FALSE;
1173                bitMask = RGSCH_SI_DFLT;
1174             }
1175             else
1176             {
1177                bitMask = RGSCH_SI_SI_UPD;
1178             }
1179
1180             RGSCHCHKNUPDSIPDU(cell->siCb.crntSiInfo.siInfo[cfgReqInfo->siId-1].si, 
1181                 cell->siCb.newSiInfo.siInfo[cfgReqInfo->siId-1].si, 
1182                 cfgReqInfo->pdu, 
1183                 cell->siCb.siBitMask, bitMask);
1184          }
1185          break;
1186
1187       case RGR_SI_CFG_TYPE_SIB8_CDMA:    /* SI CFG TYPE SIB 8 CDMA */
1188          SFndLenMsg(cfgReqInfo->pdu, &pduLen);
1189          ret = rgSCHUtlCalMcsAndNPrb(cell, cfgReqInfo->cfgType, pduLen, 
1190                                                      cfgReqInfo->siId);
1191          if (ret != ROK)
1192          {
1193             DU_LOG("\nERROR  -->  SCH : Failed to get MCS and NPRB" 
1194                      "value");
1195             RGSCH_FREE_MSG(cfgReqInfo->pdu);
1196             SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1197             cfgReqInfo = NULLP;
1198             rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1199                                                                  cfmStatus); 
1200             return RFAILED;
1201          }
1202          /* No need to wait for Modification period boundary */
1203          cell->siCb.siArray[cfgReqInfo->siId-1].si = cfgReqInfo->pdu;
1204          RGSCH_SET_SI_INFO(cell->siCb.crntSiInfo.siInfo[cfgReqInfo->siId-1].si,
1205                cfgReqInfo->pdu);
1206          cell->siCb.siArray[cfgReqInfo->siId-1].isWarningSi = FALSE;
1207          break;
1208       default:
1209          DU_LOG("\nERROR  -->  SCH : Invalid cfgType "
1210                   "parameter value");
1211          RGSCH_FREE_MSG(cfgReqInfo->pdu);
1212          SPutSBuf(reg, pool, (Data *)cfgReqInfo, 
1213                (Size)sizeof(*cfgReqInfo)); 
1214          cfgReqInfo = NULLP;
1215          rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, 
1216                cfmStatus); 
1217          return RFAILED;
1218    }
1219
1220    SPutSBuf(reg, pool, (Data *)cfgReqInfo, (Size)sizeof(*cfgReqInfo)); 
1221    cfgReqInfo = NULLP;
1222    cfmStatus = RGR_CFG_CFM_OK;
1223    rgSCHUtlRgrSiCfgCfm(instCb->rgSchInit.inst, spId, transId, cfmStatus); 
1224
1225
1226    return ROK;
1227 }  /* rgSCHGomHndlSiCfg */
1228
1229
1230 /**
1231  * @brief Handler to handle Warning SI configuration request from RRM to MAC.
1232  *
1233  * @details
1234  *
1235  *     Function: rgSCHGomHndlWarningSiCfg
1236  *     
1237  *     This API handles processing for Warning SI configuration request from 
1238  *     RRM to MAC.
1239  *     
1240  *          
1241  *  @param[in]  Region        reg
1242  *  @param[in]  Pool          pool
1243  *  @param[in]  RgSchCb       *instCb
1244  *  @param[in]  SpId          spId
1245  *  @param[in]  RgrWarningSiCfgReqInfo  *warningSiCfgReqInfo
1246  *  @return  S16
1247  *      -# ROK 
1248  *      -# RFAILED 
1249  **/
1250 S16 rgSCHGomHndlWarningSiCfg
1251 (
1252 Region        reg,
1253 Pool          pool,
1254 RgSchCb       *instCb,
1255 SpId          spId,
1256 RgrCfgTransId transId,
1257 RgrWarningSiCfgReqInfo *warningSiCfgReqInfo
1258 )
1259 {
1260    RgSchCellCb       *cell = instCb->rgrSap[spId].cell;
1261    uint8_t           cfmStatus = RGR_CFG_CFM_NOK;
1262    uint16_t          idx;
1263    uint8_t           siId = warningSiCfgReqInfo->siId; 
1264    uint8_t           j, mcs=0, nPrb=0;
1265    RgSchWarningSiSeg *warningSiMsg;
1266    RgSchWarningSiPdu *pduNode;
1267    CmLList           *node;
1268    MsgLen            msgLen = 0;
1269    Bool              freeNodeFound = FALSE;
1270    uint16_t          siWinSize = 0;
1271    uint16_t          minPeriod = 0;
1272 #ifdef EMTC_ENABLE
1273    uint8_t           isEmtc = warningSiCfgReqInfo->emtcEnable;
1274 #endif
1275
1276 #ifdef EMTC_ENABLE
1277    if(TRUE == isEmtc)
1278    {
1279       rgSchEmtcGetSiWinPerd(cell, &siWinSize, &minPeriod);
1280    }
1281    else
1282 #endif
1283    {
1284       siWinSize = cell->siCfg.siWinSize;
1285       minPeriod = cell->siCfg.minPeriodicity;
1286    }
1287    /* check if cell does not exists */
1288    if (((uint8_t *)cell == NULLP) || 
1289          (cell->cellId != warningSiCfgReqInfo->cellId) ||
1290          (warningSiCfgReqInfo->siId > 
1291           ((minPeriod * 10)/siWinSize)))
1292    {
1293       DU_LOG("\nERROR  -->  SCH : Warning SI Cfg Failed for siId = %d"
1294                 "warning cellID:%d",warningSiCfgReqInfo->siId,warningSiCfgReqInfo->cellId);
1295       rgSCHUtlFreeWarningSiSeg(reg, pool, &warningSiCfgReqInfo->siPduLst);
1296       SPutSBuf(reg, pool, (Data *)warningSiCfgReqInfo, 
1297             sizeof(RgrWarningSiCfgReqInfo)); 
1298       warningSiCfgReqInfo = NULLP;
1299       rgSCHUtlRgrWarningSiCfgCfm(instCb->rgSchInit.inst, spId, siId, transId, 
1300             cfmStatus); 
1301       return RFAILED;
1302    }
1303
1304    /* Search for free index in WarningSi */
1305    for(idx = 0; idx < RGR_MAX_NUM_WARNING_SI; idx++)
1306    {
1307       if((cell->siCb.warningSi[idx].siId == 0 ||
1308                cell->siCb.warningSi[idx].siId == warningSiCfgReqInfo->siId))
1309       {
1310          warningSiMsg = (RgSchWarningSiSeg *)&cell->siCb.warningSi[idx].warningSiMsg; 
1311
1312          /* Search for free SI node */
1313          /* ccpu00136659: CMAS ETWS design changes */
1314          if (warningSiMsg->segLstCp.first == NULLP) /* Free SI Node */
1315          {
1316             warningSiMsg->transId = transId;
1317             pduNode = (RgSchWarningSiPdu *)&cell->siCb.warningSi[idx].
1318                warningSiMsg.pduNode;
1319             CM_LLIST_FIRST_NODE(&warningSiCfgReqInfo->siPduLst, node);
1320             j = 0;
1321
1322             /* Get the PDUs one by one from the received pduLst of warning 
1323              * message and calculate the MCS and nPrb of each pdu once.
1324              * Store the pdu in warningSiMsg pduLst, which will be scheduled 
1325              * later while sending warning message as part of SIB11/SIB12 
1326              */   
1327             while((node != NULLP) && (j < RGR_MAX_WARNING_SI_SEG))
1328
1329             {
1330                pduNode[j].pdu = (Buffer *)node->node;
1331                if(pduNode[j].pdu != NULLP)
1332                {
1333                   SFndLenMsg(pduNode[j].pdu, &msgLen);
1334                   /*Get the nPrb and mcs parametr values */
1335 #ifdef EMTC_ENABLE
1336                   if (rgSCHEmtcUtlGetAllwdCchTbSzForSI(msgLen*8) != (msgLen*8))
1337 #else
1338                   if (rgSCHUtlGetAllwdCchTbSz(msgLen*8, &nPrb, &mcs) != (msgLen*8))
1339 #endif
1340
1341                   {
1342                      DU_LOG("\nERROR  -->  SCH : rgSCHGomHndlWarningSiCfg():msgLen does not match\
1343                            any valid TB Size.");
1344                      DU_LOG("\nERROR  -->  SCH : Warning SI Cfg Failed" 
1345                            "for siId = %d", warningSiCfgReqInfo->siId);
1346                      rgSCHUtlFreeWarningSiSeg(reg, pool, 
1347                            &warningSiCfgReqInfo->siPduLst);
1348                      SPutSBuf(reg, pool, (Data *)warningSiCfgReqInfo, 
1349                            sizeof(RgrWarningSiCfgReqInfo)); 
1350                      warningSiCfgReqInfo = NULLP;
1351                      rgSCHUtlRgrWarningSiCfgCfm(instCb->rgSchInit.inst, spId,
1352                            siId, transId,cfmStatus); 
1353                      return RFAILED;
1354
1355                   }
1356                }
1357                pduNode[j].mcs = mcs;
1358                pduNode[j].nPrb = nPrb;
1359                pduNode[j].msgLen = msgLen;
1360                /* ccpu00136659: CMAS ETWS design changes */
1361                cmLListAdd2Tail(&warningSiMsg->segLstCp, &pduNode[j].lnk);
1362                pduNode[j].lnk.node = (PTR)&pduNode[j];
1363                j++;
1364                node = node->next;
1365             }
1366
1367             /* ccpu00132385-  nodes in received SI config linked list should 
1368              * be freed after processing the config.*/
1369             while(warningSiCfgReqInfo->siPduLst.first != NULLP)
1370             {
1371                node = warningSiCfgReqInfo->siPduLst.first;
1372                cmLListDelFrm(&(warningSiCfgReqInfo->siPduLst), node);
1373                SPutSBuf(reg, pool, (Data *)node,sizeof(CmLList));
1374                node = NULLP;
1375             } 
1376
1377             cell->siCb.warningSi[idx].siId = warningSiCfgReqInfo->siId;
1378             cell->siCb.warningSi[idx].idx = idx;
1379 #ifdef EMTC_ENABLE
1380             if(TRUE == isEmtc)
1381             {
1382                rgSCHEmtcWarningSiCfg(cell,warningSiCfgReqInfo,idx);
1383             }
1384             else
1385 #endif
1386             {
1387                cell->siCb.siArray[warningSiCfgReqInfo->siId-1].si = 
1388                   &cell->siCb.warningSi[idx];
1389                cell->siCb.siArray[warningSiCfgReqInfo->siId-1].isWarningSi =
1390                   TRUE;
1391             }
1392             freeNodeFound = TRUE;
1393             break;
1394          }
1395       }
1396    }
1397
1398    if (freeNodeFound == FALSE)
1399    {
1400       DU_LOG("\nDEBUG  -->  SCH : No SI Index is free");
1401       rgSCHUtlFreeWarningSiSeg(reg, pool, &warningSiCfgReqInfo->siPduLst);
1402       SPutSBuf(reg, pool, (Data *)warningSiCfgReqInfo, 
1403             sizeof(RgrWarningSiCfgReqInfo)); 
1404       warningSiCfgReqInfo = NULLP;
1405       rgSCHUtlRgrWarningSiCfgCfm(instCb->rgSchInit.inst, spId, siId, transId, 
1406             cfmStatus); 
1407       return RFAILED;
1408    }
1409
1410    SPutSBuf(reg, pool, (Data *)warningSiCfgReqInfo, 
1411          sizeof(RgrWarningSiCfgReqInfo)); 
1412    warningSiCfgReqInfo = NULLP;
1413    return ROK;
1414 }
1415
1416 \f
1417 /**
1418  * @brief Handler to handle SI Stop request from RRM to MAC.
1419  *
1420  * @details
1421  *
1422  *     Function: rgSCHGomHndlWarningSiStopReq
1423  *     
1424  *     This API handles processing for SI stop request from RRM to MAC.
1425  *     
1426  *  @param[in]  Region        reg
1427  *  @param[in]  Pool          pool
1428  *  @param[in]  RgSchCb       *instCb
1429  *  @param[in]  SpId          siId
1430  *  @return  void
1431  **/
1432 Void rgSCHGomHndlWarningSiStopReq(Region reg,Pool pool,RgSchCb *instCb,uint8_t siId,RgrCfgTransId transId,SpId spId)
1433 {
1434    RgSchCellCb        *cell = instCb->rgrSap[spId].cell;
1435    uint16_t           idx;
1436    CmLList            *node;
1437    RgSchWarningSiPdu  *warningSiPdu;
1438    Buffer             *pdu;
1439
1440    for(idx = 0; idx < RGR_MAX_NUM_WARNING_SI; idx++)
1441    {
1442       if(cell->siCb.warningSi[idx].siId == siId)
1443       {
1444          if ((cmMemcmp ((uint8_t *)&cell->siCb.warningSi[idx].warningSiMsg.transId, 
1445                      (uint8_t *)&transId, sizeof(RgrCfgTransId))) == 0)
1446          {
1447             /* ccpu00136659: CMAS ETWS design changes */
1448             CM_LLIST_FIRST_NODE(&cell->siCb.warningSi[idx].warningSiMsg.segLstCp, node);
1449             while(node != NULLP)
1450             {
1451                /* On receiving the warning stop message, remove one by one
1452                 * each PDU from the warning SI list
1453                 */  
1454                /* ccpu00136659: CMAS ETWS design changes */
1455                node = (CmLList *)&cell->siCb.warningSi[idx].warningSiMsg.segLstCp.first;
1456                warningSiPdu = (RgSchWarningSiPdu *)node->node;
1457                pdu = warningSiPdu->pdu;
1458                cmLListDelFrm(&cell->siCb.warningSi[idx].warningSiMsg.segLstCp, node);
1459                RGSCH_FREE_MSG(pdu);
1460                node = node->next;
1461             }
1462          }
1463       }
1464    }
1465    return;
1466 }
1467
1468 #endif/*RGR_SI_SCH */
1469 \f
1470 /* LTE_ADV_FLAG_REMOVED_START */
1471
1472 /**
1473  * @brief This function sets the Phigh range for CC users corresponding to the CC Pool
1474  * @details
1475  *
1476  *     Function: rgSchUpdtRNTPInfo
1477  *
1478  *     Invoked by: rgSCHGomHndlLoadInf
1479  *
1480  *  @param[in]  RgSchCellCb*     cell
1481  *  @param[in]  RgSubFrm*     subFrm
1482  *  @param[in]  RgrLoadInfReqInfo   *loadInfReq
1483  *  @return  S16
1484  *
1485  **/
1486 S16 rgSchUpdtRNTPInfo(RgSchCellCb *cell,RgSchDlSf *sf,RgrLoadInfReqInfo *loadInfReq)
1487 {
1488    /*  Initialise the variables */
1489    RgSchSFRPoolInfo *sfrCCPool;
1490    CmLListCp   *l;
1491    CmLList     *n;
1492    S16 ret = RFAILED;
1493
1494    l = &sf->sfrTotalPoolInfo.ccPool;
1495
1496    /*Get the first node from the CC Pool*/
1497    n = cmLListFirst(l);
1498    while(n)
1499    {
1500       sfrCCPool = (RgSchSFRPoolInfo*)n->node;
1501       if (sfrCCPool->poolendRB == loadInfReq->rgrCcPHighEndRb)
1502       {
1503          sfrCCPool->pwrHiCCRange.endRb   = loadInfReq->rgrCcPHighEndRb;
1504          sfrCCPool->pwrHiCCRange.startRb = loadInfReq->rgrCcPHighStartRb;
1505          return ROK;
1506       }
1507       else
1508       {
1509          n = cmLListNext(l);
1510       }
1511    }
1512    return (ret);
1513 }
1514 /**
1515  * @brief Handler to handle LOAD INF request from RRM to MAC.
1516  *
1517  * @details
1518  *
1519  *     Function: rgSCHGomHndlLoadInf
1520  *
1521  *     This API handles processing for LOAD INF request from RRM to MAC.
1522  *
1523  *     - Processing Steps:
1524  *        - Validate LOAD INF request parameters at CFG module.
1525  *          Call rgSCHCfgVldtRgrLoadInf for SI configuration.
1526  *        - If validated successfully, send configuration request.
1527  *
1528  *  @param[in]  Region            reg
1529  *  @param[in]  Pool              pool
1530  *  @param[in]  RgSchCb           *instCb
1531  *  @param[in]  SpId              spId
1532  *  @param[in]  RgrCfgTransId     transId
1533  *  @param[in]  RgrLoadInfReqInfo *loadInfReq
1534  *  @return  S16
1535  *      -# ROK
1536  *      -# RFAILED
1537  **/
1538 S16 rgSCHGomHndlLoadInf(Region reg,Pool pool,RgSchCb *instCb,SpId spId,RgrCfgTransId transId,RgrLoadInfReqInfo *loadInfReq)
1539 {
1540    S16          ret;
1541    RgSchCellCb  *cell = instCb->rgrSap[spId].cell;
1542    Inst         inst  = (instCb->rgSchInit.inst );
1543    RgSchErrInfo errInfo;
1544    uint16_t i;
1545
1546    /* check if cell does not exists */
1547    if (((uint8_t *)cell == NULLP) || (cell->cellId != loadInfReq->cellId))
1548    {
1549       DU_LOG("\nERROR  -->  SCH : Cell Control block does not exist"
1550              "for load cellId:%d",loadInfReq->cellId);
1551       SPutSBuf(reg, pool, (Data *)loadInfReq, (Size)sizeof(*loadInfReq));
1552       return RFAILED;
1553    }
1554
1555    if (cell->lteAdvCb.dsfrCfg.status == RGR_DISABLE)
1556    {
1557       DU_LOG("\nERROR  -->  SCH : rgSCHGomHndlLoadInf(): DSFR Feature not enabled");
1558       SPutSBuf(reg, pool, (Data *)loadInfReq, (Size)sizeof(*loadInfReq));
1559       return RFAILED;
1560    }
1561    /* Validate the received LOAD INF Configuration */
1562    ret = rgSCHCfgVldtRgrLoadInf(inst, loadInfReq, cell, &errInfo);
1563    if (ret != ROK)
1564    {
1565       DU_LOG("\nERROR  -->  SCH : Rgr LOAD INF Configuration "
1566                "validation FAILED");
1567       SPutSBuf(reg, pool, (Data *)loadInfReq, (Size)sizeof(*loadInfReq));
1568       return RFAILED;
1569    }
1570    /* Update the RNTP info rcvd in the respective cell centre pool so that Phigh can be
1571       sent for the UEs scheduled in that particular RB range*/
1572    for(i = 0; i < RGSCH_NUM_DL_slotS; i++)
1573    {
1574       if((rgSchUpdtRNTPInfo(cell, cell->subFrms[i], loadInfReq) != ROK))
1575       {
1576          return RFAILED;
1577       }
1578    }
1579
1580    SPutSBuf(reg, pool, (Data *)loadInfReq, (Size)sizeof(*loadInfReq));
1581
1582
1583    return ROK;
1584 }  /* rgSCHGomHndlLoadInf */
1585 /* LTE_ADV_FLAG_REMOVED_END */
1586 \f
1587 /**********************************************************************
1588  
1589          End of file
1590 **********************************************************************/