WLS code changes at Lower Mac - PHY inteface
[o-du/l2.git] / src / 5gnrmac / rg_lmm.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 Layer Manager Interface Module 
26   
27      File:     rg_lmm.c 
28   
29 **********************************************************************/
30
31 /** @file rg_lmm.c
32 @brief This file contains the Layer Management interface module implementation.
33        The functions for the configuration, control, status and statistics 
34        request primitives are defined here.
35 */
36 static const char* RLOG_MODULE_NAME="MAC";
37 static int RLOG_FILE_ID=220;
38 static int RLOG_MODULE_ID=4096;
39
40 /* header include files (.h) */
41 #include "envopt.h"        /* environment options */
42 #include "envdep.h"        /* environment dependent */
43 #include "envind.h"        /* environment independent */
44 #include "gen.h"           /* general */
45 #include "ssi.h"           /* system services */
46 #include "cm_tkns.h"       /* Common Token Defines */
47 #include "cm_llist.h"      /* Common Link List Defines */
48 #include "cm_hash.h"       /* Common Hash List Defines */
49 #include "cm_mblk.h"       /* common memory link list library */
50 #include "cm_lte.h"        /* Common LTE Defines */
51 #include "rg_env.h"        /* MAC Environment Defines */
52 #include "crg.h"           /* CRG Interface defines */
53 #include "rgu.h"           /* RGU Interface defines */
54 #include "tfu.h"           /* RGU Interface defines */
55 #include "rg_sch_inf.h"    /* RGR Interface defines */
56 #include "lrg.h"           /* LRG Interface defines */
57 #include "rgr.h"           /* LRG Interface defines */
58 #include "rg.h"            /* MAC defines */
59 #include "rg_err.h"        /* MAC error defines */
60 #include "du_log.h"
61
62 /* header/extern include files (.x) */
63 #include "gen.x"           /* general */
64 #include "ssi.x"           /* system services */
65 #include "cm5.x"           /* system services */
66 #include "cm_tkns.x"       /* Common Token Definitions */
67 #include "cm_llist.x"      /* Common Link List Definitions */
68 #include "cm_lib.x"        /* Common Library Definitions */
69 #include "cm_hash.x"       /* Common Hash List Definitions */
70 #include "cm_mblk.x"       /* common memory link list library */
71 #include "cm_lte.x"        /* Common LTE Defines */
72 #include "crg.x"           /* CRG Interface includes */
73 #include "rgu.x"           /* RGU Interface includes */
74 #include "tfu.x"           /* RGU Interface includes */
75 #include "rg_sch_inf.x"    /* SCH Interface includes */
76 #include "rg_prg.x"    /* PRG Interface includes */
77 #include "lrg.x"           /* LRG Interface includes */
78 #include "rgr.x"           /* LRG Interface includes */
79 #include "du_app_mac_inf.h"
80 #include "rg.x"            /* MAC includes */
81 #ifdef SS_DIAG
82 #include "ss_diag.h"        /* Common log file */
83 #endif
84 #include "ss_rbuf.h"
85 #include "ss_rbuf.x"
86
87 #include "mac.h"
88 #include "lwr_mac_phy.h"
89 #include "lwr_mac_fsm.h"
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif /* __cplusplus */
94 EXTERN Void rgGetSId ARGS((SystemId *s));
95 #ifdef __cplusplus
96 }
97 #endif /* __cplusplus */
98
99 /* Public variable declaration */
100 ClCb   clGlobalCp;
101 MacCb  macCb;
102
103 /* forward references */
104 PRIVATE U16 rgLMMGenCfg ARGS((
105    Inst           inst,
106    RgCfg          *cfg           
107 ));
108
109 PRIVATE U16 rgLMMSapCfg ARGS((
110    Inst           inst,
111    RgCfg          *cfg,
112    Elmnt          sapType
113 ));
114
115 PRIVATE Void rgLMMShutdown ARGS((
116    Inst           inst
117 ));
118
119 PRIVATE Void rgLMMFillCfmPst ARGS((
120    Pst           *reqPst,
121    Pst           *cfmPst,
122    RgMngmt       *cfm
123 ));
124
125 PRIVATE Void rgLMMGenCntrl ARGS((
126 RgMngmt       *cntrl,
127 RgMngmt       *cfm,
128 Pst           *cfmPst
129 ));
130
131 PRIVATE Void rgLMMSapCntrl ARGS((
132 RgMngmt       *cntrl,
133 RgMngmt       *cfm,
134 Pst           *cfmPst
135 ));
136
137 extern U16 packMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm);
138
139 packMacCellCfgConfirm packMacCellCfmOpts[] =
140 {
141    packMacCellCfgCfm,      /* packing for loosely coupled */
142    duHandleMacCellCfgCfm,      /* packing for tightly coupled */
143    packMacCellCfgCfm,    /* packing for light weight loosly coupled */
144 };
145
146 SchCellCfgFunc SchCellCfgOpts[] = 
147 {
148    packSchCellCfg,   /* packing for loosely coupled */
149         SchHdlCellCfgReq, /* packing for tightly coupled */
150    packSchCellCfg    /* packing for light weight loosly coupled */
151 };
152
153 \f
154 /**
155  * @brief Task Initiation callback function. 
156  *
157  * @details
158  *
159  *     Function : rgActvInit
160  *     
161  *     This function is supplied as one of parameters during MAC's 
162  *     task registration. SSI will invoke this function once, after
163  *     it creates and attaches this TAPA Task to a system task.
164  *     
165  *  @param[in]  Ent entity, the entity ID of this task.     
166  *  @param[in]  Inst inst, the instance ID of this task.
167  *  @param[in]  Region region, the region ID registered for memory 
168  *              usage of this task.
169  *  @param[in]  Reason reason.
170  *  @return  S16
171  *      -# ROK
172  **/
173 #ifdef ANSI
174 PUBLIC S16 rgActvInit
175 (
176 Ent entity,            /* entity */
177 Inst inst,             /* instance */
178 Region region,         /* region */
179 Reason reason          /* reason */
180 )
181 #else
182 PUBLIC S16 rgActvInit(entity, inst, region, reason)
183 Ent entity;            /* entity */
184 Inst inst;             /* instance */
185 Region region;         /* region */
186 Reason reason;         /* reason */
187 #endif
188 {
189    Inst macInst ;
190    TRC2(rgActvInit);
191
192    RG_IS_INST_VALID(inst);
193
194    macInst = inst - RG_INST_START;
195    /* Initialize the MAC TskInit structure to zero */
196    cmMemset ((U8 *)&rgCb[macInst], 0, sizeof(RgCb));
197
198    /* Initialize the MAC TskInit with received values */
199    rgCb[macInst].rgInit.ent = entity;
200    rgCb[macInst].rgInit.inst = inst;
201    rgCb[macInst].rgInit.region = region;
202    rgCb[macInst].rgInit.pool = 0;
203    rgCb[macInst].rgInit.reason = reason;
204    rgCb[macInst].rgInit.cfgDone = FALSE;
205    rgCb[macInst].rgInit.acnt = FALSE;
206    rgCb[macInst].rgInit.usta = FALSE;
207    rgCb[macInst].rgInit.trc = FALSE;
208    rgCb[macInst].trcLen = 0; 
209 #ifdef DEBUGP
210 #ifdef RG_DEBUG
211    /* disabling debugs by default */
212     rgCb[macInst].rgInit.dbgMask = 0xffffffff; 
213 #endif
214 #endif /* DEBUGP */
215 #ifdef SS_DIAG
216    rgCb[macInst].rgInit.logMask = 0x0;
217 #endif
218    rgCb[macInst].rgInit.procId = SFndProcId();
219    rgCb[macInst].tfuSap.numBndRetries = 0;
220
221    /* Initialize Sap state */
222    rgCb[macInst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
223    rgCb[macInst].crgSap.sapSta.sapState = LRG_NOT_CFG;
224    rgCb[macInst].rguSap = NULLP;
225    rgCb[macInst].crgSap.sapSta.sapState = LRG_NOT_CFG;
226
227    rgCb[macInst].inactiveCell = NULLP;
228    rgCb[macInst].cell         = NULLP;
229 #ifdef SS_RBUF
230    SAttachSRngBuf(SS_RNG_BUF_ULMAC_TO_ULRLC, SS_RBUF_ENT_ULMAC,SS_RNG_TX);
231    SAttachSRngBuf(SS_RNG_BUF_ULMAC_TO_ULRLC, SS_RBUF_ENT_ULRLC,SS_RNG_RX);
232 #endif
233
234    /* Initializing CL control block */
235    clGlobalCp.region = region;
236    clGlobalCp.pool = 0;
237    clGlobalCp.clCfgDone = FALSE;
238    clGlobalCp.numOfCells = 0;
239    clGlobalCp.phyState = PHY_STATE_IDLE; 
240
241    if( cmHashListInit(&clGlobalCp.cellCbLst, MAX_NUM_CELL_SUPP, 0x0, FALSE, 
242                   CM_HASH_KEYTYPE_DEF, clGlobalCp.region, clGlobalCp.pool ) != ROK )
243    {
244       printf("\n Cellcb hash list initialization failed for MAC CL");
245       RETVALUE(RFAILED);
246    }
247
248    /* Initialize Scheduler as well */
249    schActvInit(ENTRG, (DEFAULT_CELLS + SCH_INST_START), DFLT_REGION, PWR_UP);
250
251    /* Initialize lower mac */
252    lwrMacInit();
253
254    RETVALUE(ROK);
255
256 } /* rgActvInit */
257 \f
258 /**
259  * @brief Layer Manager Configuration request handler. 
260  *
261  * @details
262  *
263  *     Function : RgMiLrgCfgReq
264  *     
265  *     This function handles the configuration
266  *     request received from the Layer Manager.
267  *     -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
268  *        functions rgHdlGenCfg() or rgHdlSapCfg().
269  *     -# Invokes RgMiLrgCfgCfm() to send back the confirmation to the LM.
270  *     
271  *  @param[in]  Pst *pst, the post structure     
272  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
273  *  @return  S16
274  *      -# ROK
275  **/
276 #ifdef ANSI
277 PUBLIC S16 RgMiLrgCfgReq
278 (
279 Pst      *pst,    /* post structure  */
280 RgMngmt  *cfg     /* config structure  */
281 )
282 #else
283 PUBLIC S16 RgMiLrgCfgReq(pst, cfg)
284 Pst      *pst;    /* post structure  */
285 RgMngmt  *cfg;    /* config structure  */
286 #endif    
287 {
288    U16       ret = LCM_PRIM_OK;
289    U16       reason = LCM_REASON_NOT_APPL;
290    RgMngmt   cfm;
291    Pst       cfmPst;
292    Inst      inst;
293
294    TRC2(RgMiLrgCfgReq)
295    
296
297    RG_DIAG_LVL0(inst,0x0a0b0001, RG_DIAG_NA, SS_DIAG_INV_ARG,
298               "Received CfgReq for MAC layer, Entity = %d, Instance = %d\n",
299               pst->srcEnt, pst->srcInst,0,0);
300
301    RG_IS_INST_VALID(pst->dstInst);
302    inst = pst->dstInst - RG_INST_START;
303
304    /* Fill the post structure for sending the confirmation */
305    rgLMMFillCfmPst(pst, &cfmPst, cfg);
306
307    cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
308
309 #ifdef LMINT3
310    cfm.hdr.transId = cfg->hdr.transId;
311 #endif
312
313
314    cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
315    switch(cfg->hdr.elmId.elmnt)
316    {
317       case STGEN:
318          reason = rgLMMGenCfg(inst,&cfg->t.cfg); 
319          break;
320       case STRGUSAP:
321       case STCRGSAP:
322       case STTFUSAP:
323          reason = rgLMMSapCfg(inst,&cfg->t.cfg, cfg->hdr.elmId.elmnt);
324          break;
325       default:
326          ret = LCM_PRIM_NOK;
327          reason = LCM_REASON_INVALID_ELMNT;
328          RLOG1(L_ERROR, "Invalid Elmnt=%d",
329                   cfg->hdr.elmId.elmnt);
330          break;
331    }
332
333    if (reason != LCM_REASON_NOT_APPL)
334    {
335       ret = LCM_PRIM_NOK;
336    }
337
338    cfm.cfm.status = ret;
339    cfm.cfm.reason = reason;
340
341    RgMiLrgCfgCfm(&cfmPst, &cfm);
342    
343    RETVALUE(ROK);
344 }/*-- RgMiLrgCfgReq --*/
345
346 \f
347 /**
348  * @brief Layer Manager Statistics request handler. 
349  *
350  * @details
351  *
352  *     Function : RgMiLrgStsReq
353  *     
354  *     This function handles the statistics
355  *     request received from the Layer Manager.
356  *      -# Based on sts->hdr.elmId.elmnt, it retrieves either general or SAP
357  *      statistics from the rgCb global control block.
358  *      -# If action=ARST, it will reset the statistics parameters in rgCb to 0.
359  *      -# Invokes the RgMiLrgStsCfm to send back the confirmation to LM.
360  *     
361  *  @param[in]  Pst *pst, the post structure     
362  *  @param[in]  RgMngmt *sts, the statistics parameter's structure
363  *  @return  S16
364  *      -# ROK
365  **/
366 #ifdef ANSI
367 PUBLIC S16 RgMiLrgStsReq
368 (
369 Pst      *pst,    /* post structure  */
370 RgMngmt  *sts     /* statistics structure  */
371 )
372 #else
373 PUBLIC S16 RgMiLrgStsReq(pst, sts)
374 Pst      *pst;    /* post structure  */
375 RgMngmt  *sts;    /* statistics structure  */
376 #endif    
377 {
378    Pst       cfmPst;
379    RgMngmt   cfm;
380    Inst      inst;
381
382    TRC2(RgMiLrgStsReq)
383    
384
385    RG_IS_INST_VALID(pst->dstInst);
386    inst = pst->dstInst - RG_INST_START;
387    /* Fill the post structure for sending the confirmation */
388    rgLMMFillCfmPst(pst, &cfmPst, sts);
389
390    cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
391
392 #ifdef LMINT3
393    cfm.hdr.transId = sts->hdr.transId;
394 #endif
395    SGetDateTime(&cfm.t.sts.dt);
396    cfm.cfm.status = LCM_PRIM_OK;
397    cfm.cfm.reason = LCM_REASON_NOT_APPL;
398    cfm.hdr.elmId.elmnt = sts->hdr.elmId.elmnt;
399    cfm.t.sts.action = sts->t.sts.action;
400
401    /* Check if General Config Done */
402    if(rgCb[inst].rgInit.cfgDone != TRUE) 
403    {
404       cfm.cfm.status = LCM_PRIM_NOK;
405       cfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
406       RgMiLrgStsCfm(&cfmPst,&cfm);
407       RLOG0(L_ERROR, "Gen Cfg not done");
408       RETVALUE(ROK);
409    }
410
411    switch(sts->hdr.elmId.elmnt)
412    {
413       case STGEN:
414          {
415             cmMemcpy((U8 *)&(cfm.t.sts.s.genSts), (U8 *)&rgCb[inst].genSts,
416                   sizeof(RgGenSts));
417             /* check if action is read and reset */
418             if(sts->t.sts.action == ARST)
419             {
420                rgCb[inst].genSts.numHarqFail = 0;
421             }
422             /* L2 statistics */
423 #ifdef MAC_SCH_STATS
424             {
425                RgGenSts *genSts = &(cfm.t.sts.s.genSts);
426                U8       cqi = 0;
427                for(cqi=0; cqi <= 14; cqi++)
428                {
429                   /* Filling DL ACK/NACK stats */
430                   genSts->nackAckStats.dlCqiStat[cqi].mcs = \
431                      hqFailStats.dlCqiStat[cqi].mcs;
432                   genSts->nackAckStats.dlCqiStat[cqi].numOfNacks = \
433                      hqFailStats.dlCqiStat[cqi].numOfNacks;
434                   genSts->nackAckStats.dlCqiStat[cqi].numOfAcks = 
435                      hqFailStats.dlCqiStat[cqi].numOfAcks;
436
437                   /* Filling UL ACK/NACK stats */
438                   genSts->nackAckStats.ulCqiStat[cqi].mcs = \
439                      hqFailStats.ulCqiStat[cqi].mcs;
440                   genSts->nackAckStats.ulCqiStat[cqi].numOfNacks = \
441                      hqFailStats.ulCqiStat[cqi].numOfNacks;
442                   genSts->nackAckStats.ulCqiStat[cqi].numOfAcks = \
443                      hqFailStats.ulCqiStat[cqi].numOfAcks;
444
445                   /* Filling DL HQ Retx stats */
446                   genSts->hqRetxStats.dlCqiStat[cqi].mcs = \
447                      hqRetxStats.dlCqiStat[cqi].mcs;
448                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_1 = \
449                      hqRetxStats.dlCqiStat[cqi].numOfHQ_1;
450                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_2 = \
451                      hqRetxStats.dlCqiStat[cqi].numOfHQ_2;
452                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_3 = \
453                      hqRetxStats.dlCqiStat[cqi].numOfHQ_3;
454                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_4 = \
455                      hqRetxStats.dlCqiStat[cqi].numOfHQ_4;
456                   genSts->hqRetxStats.dlCqiStat[cqi].totalTx = \
457                      hqRetxStats.dlCqiStat[cqi].totalTx;
458
459                   /* Filling UL HQ Retx stats */
460                   genSts->hqRetxStats.ulCqiStat[cqi].mcs = \
461                      hqRetxStats.ulCqiStat[cqi].mcs;
462                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_1 = \
463                      hqRetxStats.ulCqiStat[cqi].numOfHQ_1;
464                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_2 = \
465                      hqRetxStats.ulCqiStat[cqi].numOfHQ_2;
466                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_3 = \
467                      hqRetxStats.ulCqiStat[cqi].numOfHQ_3;
468                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_4 = \
469                      hqRetxStats.ulCqiStat[cqi].numOfHQ_4;
470                   genSts->hqRetxStats.ulCqiStat[cqi].totalTx = \
471                      hqRetxStats.ulCqiStat[cqi].totalTx;
472                }
473                /* Reset statistics */
474                if(sts->t.sts.action == ZEROSTS)
475                {
476                   cmMemset((U8 *)&hqRetxStats, 0, \
477                         sizeof(RgSchHqRetxStats));
478                   cmMemset((U8 *)&hqFailStats, 0, \
479                         sizeof(RgSchNackAckStats));
480                }
481             }
482 #endif /* MAC_SCH_STATS*/
483          }
484          break;
485       case STRGUSAP:
486          cmMemcpy((U8 *)&(cfm.t.sts.s.rguSts), (U8 *)&rgCb[inst].rguSap[sts->t.sts.sapInst].sapSts,
487                   sizeof(RgSapSts));
488
489          /* check if action is read and reset */
490          if(sts->t.sts.action == ARST)
491             cmMemset((U8 *)&rgCb[inst].rguSap[sts->t.sts.sapInst].sapSts, 0, sizeof(RgSapSts));
492
493          break;
494       case STCRGSAP:
495          cmMemcpy((U8 *)&(cfm.t.sts.s.crgSts), (U8 *)&rgCb[inst].crgSap.sapSts,
496                   sizeof(RgSapSts));
497
498          /* check if action is read and reset */
499          if(sts->t.sts.action == ARST)
500             cmMemset((U8 *)&rgCb[inst].crgSap.sapSts, 0, sizeof(RgSapSts));
501
502          break;
503       case STTFUSAP:
504          cmMemcpy((U8 *)&(cfm.t.sts.s.tfuSts), (U8 *)&rgCb[inst].tfuSap.sapSts,
505                   sizeof(RgSapSts));
506
507          /* check if action is read and reset */
508          if(sts->t.sts.action == ARST)
509             cmMemset((U8 *)&rgCb[inst].tfuSap.sapSts, 0, sizeof(RgSapSts));
510
511          break;
512       default:
513          cfm.cfm.status = LCM_PRIM_NOK;
514          cfm.cfm.reason = LCM_REASON_INVALID_ELMNT;
515          RLOG1(L_ERROR, "Invalid Elmnt = %d",sts->hdr.elmId.elmnt);
516          break;     
517    }
518    RgMiLrgStsCfm(&cfmPst,&cfm);
519    RETVALUE(ROK);
520 }/*-- RgMiLrgStsReq --*/
521
522 \f
523 /**
524  * @brief Layer Manager Status request handler. 
525  *
526  * @details
527  *
528  *     Function : RgMiLrgStaReq
529  *     
530  *     This function handles the solicited status
531  *     request received from the Layer Manager.
532  *      -# Based on sta->hdr.elmId.elmnt, it retrieves the status of a
533  *      particular SAP from the rgCb global control block.
534  *      -# Invokes the RgMiLrgStaCfm to send back the confirmation to LM.
535  *     
536  *  @param[in]  Pst *pst, the post structure     
537  *  @param[in]  RgMngmt *sta, the status parameter's structure
538  *  @return  S16
539  *      -# ROK
540  **/
541 #ifdef ANSI
542 PUBLIC S16 RgMiLrgStaReq
543 (
544 Pst      *pst,    /* post structure  */
545 RgMngmt  *sta     /* status structure  */
546 )
547 #else
548 PUBLIC S16 RgMiLrgStaReq(pst, sta)
549 Pst      *pst;    /* post structure  */
550 RgMngmt  *sta;    /* status structure  */
551 #endif    
552 {
553    Pst       cfmPst;
554    RgMngmt   cfm;
555    Inst      inst ;
556
557    TRC2(RgMiLrgStaReq)
558    
559
560    RG_IS_INST_VALID(pst->dstInst);
561    inst = pst->dstInst - RG_INST_START;
562
563
564    /* Fill the post structure for sending the confirmation */
565    rgLMMFillCfmPst(pst, &cfmPst, sta);
566
567    if (sta->t.ssta.s.sysId.ptNmb != NULLP)
568    {
569       SPutSBuf(pst->region, pst->pool, (Data *)sta->t.ssta.s.sysId.ptNmb, LRG_MAX_PT_NUM_SIZE);
570    }
571    
572    cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
573    cfm.hdr.elmId.elmnt = sta->hdr.elmId.elmnt;
574
575 #ifdef LMINT3
576    cfm.hdr.transId = sta->hdr.transId;
577 #endif
578    /* Check if General Config Done */
579    if(rgCb[inst].rgInit.cfgDone != TRUE) 
580    {
581       SGetDateTime(&cfm.t.ssta.dt);
582       if (SGetSBuf(cfmPst.region, cfmPst.pool, 
583           (Data **)&(cfm.t.ssta.s.sysId.ptNmb), LRG_MAX_PT_NUM_SIZE)
584          != ROK)
585       {
586          RLOG0(L_ERROR, "Memory Unavailable for Confirmation");
587          RETVALUE(ROK);
588       } 
589       cmMemset((U8 *)(cfm.t.ssta.s.sysId.ptNmb), 0, LRG_MAX_PT_NUM_SIZE);
590       rgGetSId(&cfm.t.ssta.s.sysId);
591       cfm.cfm.status = LCM_PRIM_NOK;
592       cfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
593       cfm.hdr.elmId.elmnt = sta->hdr.elmId.elmnt;
594       RgMiLrgStaCfm(&cfmPst, &cfm);
595       RLOG0(L_ERROR, "Gen Cfg not done");
596       RETVALUE(ROK);
597    }
598
599    switch(sta->hdr.elmId.elmnt)
600    {
601       case STGEN:
602          SGetDateTime(&cfm.t.ssta.dt);
603          if (SGetSBuf(cfmPst.region, cfmPst.pool, 
604              (Data **)&(cfm.t.ssta.s.sysId.ptNmb), LRG_MAX_PT_NUM_SIZE)
605             != ROK)
606          {
607             RLOG0(L_ERROR, "Memory Unavailable for Confirmation");
608             RETVALUE(ROK);
609          } 
610          cmMemset((U8 *)(cfm.t.ssta.s.sysId.ptNmb), 0, LRG_MAX_PT_NUM_SIZE);
611          rgGetSId(&cfm.t.ssta.s.sysId);
612          cfm.cfm.status = LCM_PRIM_OK;
613          cfm.cfm.reason = LCM_REASON_NOT_APPL;
614          RgMiLrgStaCfm(&cfmPst, &cfm);
615          break;
616       case STRGUSAP:
617          cfm.cfm.status = LCM_PRIM_OK;
618          cfm.cfm.reason = LCM_REASON_NOT_APPL;
619          SGetDateTime(&cfm.t.ssta.dt);
620          cmMemcpy((U8 *)&(cfm.t.ssta.s.rguSapSta), 
621                                 (U8 *)&rgCb[inst].rguSap[sta->t.ssta.sapInst].sapSta,
622             sizeof(RgSapSta));
623          RgMiLrgStaCfm(&cfmPst, &cfm);
624          break;
625       case STCRGSAP:
626          cfm.cfm.status = LCM_PRIM_OK;
627          cfm.cfm.reason = LCM_REASON_NOT_APPL;
628          SGetDateTime(&cfm.t.ssta.dt);
629          cmMemcpy((U8 *)&(cfm.t.ssta.s.crgSapSta), (U8 *)&rgCb[inst].crgSap.sapSta,
630          sizeof(RgSapSta));
631          RgMiLrgStaCfm(&cfmPst, &cfm);
632          break;
633       case STTFUSAP:
634          cfm.cfm.status = LCM_PRIM_OK;
635          cfm.cfm.reason = LCM_REASON_NOT_APPL;
636          SGetDateTime(&cfm.t.ssta.dt);
637          cmMemcpy((U8 *)&(cfm.t.ssta.s.tfuSapSta), (U8 *)&rgCb[inst].tfuSap.sapSta,
638          sizeof(RgSapSta));
639          RgMiLrgStaCfm(&cfmPst, &cfm);
640          break;
641       default:
642          cfm.cfm.status = LCM_PRIM_NOK;
643          cfm.cfm.reason = LCM_REASON_INVALID_ELMNT;
644          RgMiLrgStaCfm(&cfmPst, &cfm);
645          RLOG1(L_ERROR, "Invalid elmnt=%d",sta->hdr.elmId.elmnt);
646          break;     
647    }
648    RETVALUE(ROK);
649 }/*-- RgMiLrgStaReq --*/
650
651 \f
652 /**
653  * @brief Layer Manager Control request handler. 
654  *
655  * @details
656  *
657  *     Function : RgMiLrgCntrlReq
658  *     
659  *     This function handles the control
660  *     request received from the Layer Manager.
661  *      -# Based on cntrl->hdr.elmId.elmnt, cntrl->t.cntrl.action
662  *      and cntrl->t.cntrl.subAction, it performs the appropriate control action
663  *      of SAP (enable/disable), Debug (enable/disable), Trace (enable/disable)
664  *      and layer shutdown.
665  *      -# Invokes the RgMiLrgCntrlCfm to send back the confirmation to LM.
666  *     
667  *  @param[in]  Pst *pst, the post structure     
668  *  @param[in]  RgMngmt *cntrl, the control parameter's structure
669  *  @return  S16
670  *      -# ROK
671  **/
672 #ifdef ANSI
673 PUBLIC S16 RgMiLrgCntrlReq
674 (
675 Pst      *pst,    /* post structure  */
676 RgMngmt  *cntrl   /* control structure  */
677 )
678 #else
679 PUBLIC S16 RgMiLrgCntrlReq(pst, cntrl)
680 Pst      *pst;    /* post structure  */
681 RgMngmt  *cntrl;  /* control structure  */
682 #endif    
683 {
684    S16       ret = ROK;            /* return value */
685    Pst       cfmPst;
686    RgMngmt   cfm;
687    Inst      inst;
688    
689    TRC2(RgMiLrgCntrlReq)
690    
691    /* Fill the post structure for sending the confirmation */
692
693    RG_IS_INST_VALID(pst->dstInst);
694    inst = pst->dstInst - RG_INST_START;
695
696    rgLMMFillCfmPst(pst, &cfmPst, cntrl);
697
698    cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
699 #ifdef LMINT3
700    cfm.hdr.transId = cntrl->hdr.transId;
701 #endif
702    cfm.hdr.elmId.elmnt = cntrl->hdr.elmId.elmnt;
703    cfm.t.cntrl.action = cntrl->t.cntrl.action;
704    cfm.t.cntrl.subAction = cntrl->t.cntrl.subAction;
705
706    /* Check if General Config Done*/
707    if(rgCb[inst].rgInit.cfgDone != TRUE)
708    {
709       cfm.cfm.status = LCM_PRIM_NOK;
710       cfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
711       cfm.hdr.elmId.elmnt = cntrl->hdr.elmId.elmnt;
712       RgMiLrgCntrlCfm(&cfmPst, &cfm);
713       RLOG0(L_ERROR, "Gen Cfg not done");
714       RETVALUE(ROK);
715    }
716  
717    /* General Config done, process the Control request */   
718    switch(cntrl->hdr.elmId.elmnt)
719    {
720       case STGEN:
721          rgLMMGenCntrl(cntrl, &cfm, &cfmPst);
722          break;
723       case STTFUSAP:
724       case STRGUSAP:
725       case STCRGSAP:
726          rgLMMSapCntrl(cntrl, &cfm, &cfmPst);
727          break;
728       default:
729          cfm.cfm.status = LCM_PRIM_NOK;
730          cfm.cfm.reason = LCM_REASON_INVALID_PAR_VAL;
731          RgMiLrgCntrlCfm(&cfmPst, &cfm);
732          RLOG1(L_ERROR, "invalid elmnt=%d",cntrl->hdr.elmId.elmnt);
733          break;
734    }
735    RETVALUE(ret);
736 }/*-- RgMiLrgCntrlReq --*/
737
738 \f
739 /**
740  * @brief SAP Configuration Handler. 
741  *
742  * @details
743  *
744  *     Function : rgLMMSapCfg
745  *     
746  *     This function in called by RgMiLrgCfgReq(). It handles the
747  *     interface SAP configuration of the LTE MAC layer. It 
748  *     initializes the sapState to LRG_UNBND. Returns
749  *     reason for success/failure of this function.
750  *     
751  *  @param[in]  Inst        inst
752  *  @param[in]  RgCfg *cfg, the Configuaration information 
753  *  @return  U16
754  *      -# LCM_REASON_GENCFG_NOT_DONE
755  *      -# LCM_REASON_INVALID_SAP
756  *      -# LCM_REASON_NOT_APPL
757  **/
758 #ifdef ANSI
759 PRIVATE U16 rgLMMSapCfg
760 (
761 Inst  inst,
762 RgCfg *cfg,            /* Configuaration information */
763 Elmnt sapType             /* Sap Type */
764 )
765 #else
766 PRIVATE U16 rgLMMSapCfg(inst,cfg,sapType)
767 Inst  inst;
768 RgCfg *cfg;            /* Configuaration information */
769 Elmnt sapType;            /* Sap Type */
770 #endif
771 {
772    U16               ret = LCM_REASON_NOT_APPL;
773    RgLowSapCfgInfo   *lowSapCfg = NULLP;
774    RgUpSapCfgInfo    *upSapCfg = NULLP;
775    RgUpSapCb          *upSapCb  = NULLP;
776
777    TRC2(rgLMMSapCfg)
778
779    /* Check if Gen Config has been done */
780    if(rgCb[inst].rgInit.cfgDone != TRUE)
781       RETVALUE(LCM_REASON_GENCFG_NOT_DONE);
782
783    switch(sapType)
784    {   
785       case STRGUSAP:
786          if ((cfg->s.rguSap.spId > LRG_MAX_RGU_SAPS) &&
787              (cfg->s.rguSap.selector != RGU_SEL_TC) &&
788              (cfg->s.rguSap.selector != RGU_SEL_LC))
789          {
790             ret = LCM_REASON_INVALID_PAR_VAL;
791             RLOG0(L_ERROR, "unsupported Selector value for RGU");
792             break;
793          }
794          upSapCb = &(rgCb[inst].rguSap[cfg->s.rguSap.spId]);
795          if(upSapCb->sapSta.sapState == LRG_NOT_CFG)
796          { 
797             upSapCb->sapSta.sapState = LRG_UNBND;
798          }
799          upSapCfg = &(upSapCb->sapCfg);
800          upSapCfg->sapPst.dstEnt = cfg->s.rguSap.ent;
801          upSapCfg->sapPst.dstInst = cfg->s.rguSap.inst;
802          upSapCfg->sapPst.dstProcId = cfg->s.rguSap.procId;
803          upSapCfg->sapPst.srcEnt = rgCb[inst].rgInit.ent;
804          upSapCfg->sapPst.srcInst = rgCb[inst].rgInit.inst;
805          upSapCfg->sapPst.srcProcId = rgCb[inst].rgInit.procId;
806          upSapCfg->sapPst.region = cfg->s.rguSap.mem.region;
807          upSapCfg->sapPst.pool = cfg->s.rguSap.mem.pool;
808          upSapCfg->sapPst.selector = cfg->s.rguSap.selector;
809          upSapCfg->sapPst.route = cfg->s.rguSap.route;
810          upSapCfg->sapPst.intfVer = 0; 
811          upSapCfg->sapPst.prior = cfg->s.rguSap.prior;
812          upSapCfg->suId = cfg->s.rguSap.suId;
813          upSapCfg->spId = cfg->s.rguSap.spId;
814          /*T2K uses 2 saps, T3K uses 1 sap. change the rgRguDlSap to 1 only if
815           * there is cfg request with sap is 1*/
816          break;
817       case STCRGSAP:
818          if ((cfg->s.crgSap.selector != CRG_SEL_TC) &&
819              (cfg->s.crgSap.selector != CRG_SEL_LC))
820          {
821             ret = LCM_REASON_INVALID_PAR_VAL;
822             RLOG0(L_ERROR, "unsupported Selector value for CRG");
823             break;
824          }
825          if(rgCb[inst].crgSap.sapSta.sapState == LRG_NOT_CFG)
826          { 
827             rgCb[inst].crgSap.sapSta.sapState = LRG_UNBND;
828          }
829          upSapCfg = &rgCb[inst].crgSap.sapCfg;
830
831          upSapCfg->sapPst.dstEnt = cfg->s.crgSap.ent;
832          upSapCfg->sapPst.dstInst = cfg->s.crgSap.inst;
833          upSapCfg->sapPst.dstProcId = cfg->s.crgSap.procId;
834          upSapCfg->sapPst.srcEnt = rgCb[inst].rgInit.ent;
835          upSapCfg->sapPst.srcInst = rgCb[inst].rgInit.inst;
836          upSapCfg->sapPst.srcProcId = rgCb[inst].rgInit.procId;
837          upSapCfg->sapPst.region = cfg->s.crgSap.mem.region;
838          upSapCfg->sapPst.pool = cfg->s.crgSap.mem.pool;
839          upSapCfg->sapPst.selector = cfg->s.crgSap.selector;
840          upSapCfg->sapPst.route = cfg->s.crgSap.route;
841          upSapCfg->sapPst.intfVer = 0; 
842          upSapCfg->sapPst.prior = cfg->s.crgSap.prior;
843          upSapCfg->suId = cfg->s.crgSap.suId;
844          upSapCfg->spId = cfg->s.crgSap.spId;
845          break;
846       case STTFUSAP:
847 #ifndef CL_MAC_LWLC 
848          if ((cfg->s.tfuSap.selector != TFU_SEL_TC) &&
849              (cfg->s.tfuSap.selector != TFU_SEL_LC))
850          {
851             ret = LCM_REASON_INVALID_PAR_VAL;
852             RLOG0(L_ERROR, "unsupported Selector value for TFU");
853             break;
854          }
855 #endif
856          if (rgCb[inst].tfuSap.sapSta.sapState == LRG_NOT_CFG) 
857          { 
858             rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
859          }
860          lowSapCfg = &rgCb[inst].tfuSap.sapCfg;
861
862          lowSapCfg->sapPst.dstEnt = cfg->s.tfuSap.ent;
863          lowSapCfg->sapPst.dstInst = cfg->s.tfuSap.inst;
864          lowSapCfg->sapPst.dstProcId = rgCb[inst].rgInit.procId;
865          lowSapCfg->sapPst.srcEnt = rgCb[inst].rgInit.ent;
866          lowSapCfg->sapPst.srcInst = rgCb[inst].rgInit.inst;
867          lowSapCfg->sapPst.srcProcId = rgCb[inst].rgInit.procId;
868          lowSapCfg->sapPst.region = cfg->s.tfuSap.mem.region;
869          lowSapCfg->sapPst.pool = cfg->s.tfuSap.mem.pool;
870          lowSapCfg->sapPst.selector = cfg->s.tfuSap.selector;
871          lowSapCfg->sapPst.route = cfg->s.tfuSap.route;
872          lowSapCfg->sapPst.intfVer = 0; 
873          lowSapCfg->sapPst.prior = cfg->s.tfuSap.prior;
874          lowSapCfg->suId = cfg->s.tfuSap.suId;
875          lowSapCfg->spId = cfg->s.tfuSap.spId;
876          cmMemcpy((U8 *)&lowSapCfg->bndTmr, (U8 *)&cfg->s.tfuSap.bndTmr,
877                    sizeof(TmrCfg));
878          break;
879       default:
880          /* would never reach here */
881          break;
882    }
883    RETVALUE(ret);
884 }
885
886 \f
887 /**
888  * @brief General Configuration Handler. 
889  *
890  * @details
891  *
892  *     Function : rgLMMGenCfg
893  *     
894  *     This function in called by RgMiLrgCfgReq(). It handles the
895  *     general configuration of the LTE MAC layer. It initializes 
896  *     the hash lists of RgCb. Returns
897  *     reason for success/failure of this function.
898  *     
899  *  @param[in]  Inst        inst
900  *  @param[in]  RgCfg *cfg, the Configuaration information 
901  *  @return  U16
902  *      -# LCM_REASON_NOT_APPL 
903  *      -# LCM_REASON_INVALID_MSGTYPE
904  *      -# LCM_REASON_MEM_NOAVAIL
905  **/
906 #ifdef ANSI
907 PRIVATE U16 rgLMMGenCfg
908 (
909 Inst inst,
910 RgCfg *cfg            /* Configuaration information */
911 )
912 #else
913 PRIVATE U16 rgLMMGenCfg(inst,cfg)
914 Inst inst;
915 RgCfg *cfg;            /* Configuaration information */
916 #endif
917 {
918    U16    ret = LCM_REASON_NOT_APPL;
919
920    TRC2(rgLMMGenCfg)
921
922    /* Check if General Configuration is done already */
923    if (rgCb[inst].rgInit.cfgDone == TRUE)
924    {
925       RETVALUE(LCM_REASON_INVALID_MSGTYPE);
926    }
927    if ((cfg->s.genCfg.lmPst.selector != LRG_SEL_TC) &&
928        (cfg->s.genCfg.lmPst.selector != LRG_SEL_LC))
929    {
930       RLOG0(L_ERROR, "unsupported Selector value for RGU");
931       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
932    }
933    /* Update the Pst structure for LM interface */
934    cmMemcpy((U8 *)&rgCb[inst].rgInit.lmPst, (U8 *)&cfg->s.genCfg.lmPst,
935              sizeof(Pst));
936
937    rgCb[inst].rgInit.lmPst.srcProcId = rgCb[inst].rgInit.procId;
938    rgCb[inst].rgInit.lmPst.srcEnt = rgCb[inst].rgInit.ent;
939    rgCb[inst].rgInit.lmPst.srcInst = rgCb[inst].rgInit.inst;
940    rgCb[inst].rgInit.lmPst.event = EVTNONE;
941
942    rgCb[inst].rgInit.region = cfg->s.genCfg.mem.region;
943    rgCb[inst].rgInit.pool = cfg->s.genCfg.mem.pool;
944    rgCb[inst].genCfg.tmrRes = cfg->s.genCfg.tmrRes;
945
946    macCb.macInst = rgCb[inst].rgInit.inst;
947
948    /* Initialize SAP States */
949    rgCb[inst].crgSap.sapSta.sapState = LRG_NOT_CFG;
950
951    if(cfg->s.genCfg.numRguSaps == 0)
952    {
953       RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgGenCfg(): Invalid numRguSap.\n"));
954       RETVALUE(RFAILED);
955    }
956
957    /* allocate RGR saps */
958    if (SGetSBuf(rgCb[inst].rgInit.region,
959                 rgCb[inst].rgInit.pool,
960                 (Data **)&rgCb[inst].rguSap,
961                 (sizeof(RgUpSapCb) * cfg->s.genCfg.numRguSaps)) != ROK)
962    {
963       RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgGenCfg(): Failed to allocate mem for RGU SAP's.\n"));
964       RETVALUE(RFAILED);
965    }
966    rgCb[inst].numRguSaps = cfg->s.genCfg.numRguSaps;
967
968    for (int idx = 0; idx < rgCb[inst].numRguSaps; idx++)
969    {
970       rgCb[inst].rguSap[idx].sapSta.sapState = LRG_NOT_CFG;
971       cmMemset((U8 *)&rgCb[inst].rguSap[idx], 0, sizeof(RgUpSapCb));
972    }
973    rgCb[inst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
974    /* Initialize the timer blocks */
975    cmInitTimers(rgCb[inst].tmrBlk, RG_MAX_TIMER);
976    /* Initialzie the timer queue */   
977    cmMemset((U8 *)&rgCb[inst].tmrTq, 0, sizeof(CmTqType)*RG_TQ_SIZE);
978    /* Initialize the timer control point */
979    cmMemset((U8 *)&rgCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
980    rgCb[inst].tmrTqCp.tmrLen = RG_TQ_SIZE;
981 #if 0
982    /* Timer Registration request to SSI */
983    if (SRegTmrMt(rgCb[inst].rgInit.ent, rgCb[inst].rgInit.inst,
984             (S16)rgCb[inst].genCfg.tmrRes, rgActvTmr) != ROK)
985    {
986       
987       RLOG0(L_ERROR, "Failed to register timer");
988
989       SPutSBuf(rgCb[inst].rgInit.region,
990                 rgCb[inst].rgInit.pool,
991                 (Data *)rgCb[inst].rguSap,
992                 (sizeof(RgUpSapCb) * cfg->s.genCfg.numRguSaps));
993
994       RETVALUE(LCM_REASON_MEM_NOAVAIL);
995    }
996 #endif
997    /* Set Config done in TskInit */
998    rgCb[inst].rgInit.cfgDone = TRUE;
999
1000    RETVALUE(ret);
1001 }
1002
1003 \f
1004 /***********************************************************
1005  *
1006  *     Func : rgLMMShutdown
1007  *        
1008  *
1009  *     Desc : Handles the MAC layer shutdown request. Calls 
1010  *     rgCFGFreeCellCb(RgCellCb*) to handle each cellCb deallocation.
1011  *            
1012  *
1013  *     Ret  : Void
1014  *
1015  *     Notes: 
1016  *
1017  *     File : rg_lmm.c 
1018  *
1019  **********************************************************/
1020 #ifdef ANSI
1021 PRIVATE Void rgLMMShutdown
1022 (
1023 Inst inst
1024 )
1025 #else
1026 PRIVATE Void rgLMMShutdown(inst)
1027 Inst inst;
1028 #endif
1029 {
1030    RgCellCb   *cell = rgCb[inst].cell;
1031    U8 idx;
1032
1033    TRC2(rgLMMShutdown)
1034
1035    /* Unbind the TFU Sap */
1036    if(rgCb[inst].tfuSap.sapSta.sapState == LRG_WAIT_BNDCFM)
1037    {
1038       rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, LRG_UNBND);
1039       if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1040       {
1041          rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap); 
1042       }
1043       rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1044    }
1045    if(rgCb[inst].tfuSap.sapSta.sapState == LRG_BND)
1046    {
1047       rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, LRG_UNBND);
1048       rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1049    }
1050
1051
1052    if(cell != NULLP)
1053    {
1054       for(idx=0;idx < RG_NUM_SUB_FRAMES; idx++)
1055       {
1056          rgTOMRlsSf(inst,&cell->subFrms[idx]);
1057       }
1058
1059       rgCFGFreeCellCb(cell);
1060    }
1061
1062    /* Deleting the RGU SAPs */
1063    SPutSBuf(rgCb[inst].rgInit.region,
1064                 rgCb[inst].rgInit.pool,
1065                 (Data *)rgCb[inst].rguSap,
1066                 (sizeof(RgUpSapCb) * rgCb[inst].numRguSaps));
1067    rgCb[inst].rguSap = NULLP;
1068
1069    rgCb[inst].inactiveCell = NULLP;
1070    rgCb[inst].cell         = NULLP;
1071
1072    /* De-register the Timer Service */
1073    (Void) SDeregTmrMt(rgCb[inst].rgInit.ent, rgCb[inst].rgInit.inst,
1074                      (S16)rgCb[inst].genCfg.tmrRes, rgActvTmr); 
1075
1076    /* call back the task initialization function to intialize
1077     * the global RgCb Struct */
1078    rgActvInit(rgCb[inst].rgInit.ent, rgCb[inst].rgInit.inst, rgCb[inst].rgInit.region, 
1079               rgCb[inst].rgInit.reason);
1080
1081    RETVOID;
1082 }
1083
1084 \f
1085 /***********************************************************
1086  *
1087  *     Func : rgLMMGenCntrl 
1088  *        
1089  *
1090  *     Desc : Processes the LM control request for STGEN elmnt.
1091  *            
1092  *
1093  *     Ret  : Void
1094  *
1095  *     Notes: 
1096  *
1097  *     File : rg_lmm.c 
1098  *
1099  **********************************************************/
1100 #ifdef ANSI
1101 PRIVATE Void rgLMMGenCntrl 
1102 (
1103 RgMngmt       *cntrl,
1104 RgMngmt       *cfm,
1105 Pst           *cfmPst
1106 )
1107 #else
1108 PRIVATE Void rgLMMGenCntrl(cntrl, cfm, cfmPst)
1109 RgMngmt       *cntrl;
1110 RgMngmt       *cfm;
1111 Pst           *cfmPst;
1112 #endif
1113 {
1114    Inst      inst = (cfmPst->srcInst - RG_INST_START);
1115    TRC2(rgLMMGenCntrl)
1116
1117    cfm->cfm.status = LCM_PRIM_OK;
1118    cfm->cfm.reason = LCM_REASON_NOT_APPL;
1119    
1120
1121    switch(cntrl->t.cntrl.action)
1122    {
1123       case AENA:
1124          /* Action is Enable */
1125          switch(cntrl->t.cntrl.subAction)
1126          {
1127             case SATRC:
1128             /* Enable Traces */
1129                rgCb[inst].rgInit.trc = TRUE;
1130                rgCb[inst].trcLen = cntrl->t.cntrl.s.trcLen;
1131                /*Store the response and TransId for sending the Traces */
1132                cmMemcpy((U8 *)&rgCb[inst].genCfg.trcResp.response, 
1133                (U8 *)&cntrl->hdr.response, sizeof(Resp));
1134                rgCb[inst].genCfg.trcResp.transId = cntrl->hdr.transId;
1135                
1136                break;
1137             case SAUSTA:   
1138             /* Enable Unsolicited Status (alarms) */
1139                rgCb[inst].rgInit.usta = TRUE;
1140                /*Store the response and TransId for sending the Alarms */
1141                cmMemcpy((U8 *)&rgCb[inst].genCfg.ustaResp.response, 
1142                (U8 *)&cntrl->hdr.response, sizeof(Resp));
1143                rgCb[inst].genCfg.ustaResp.transId = cntrl->hdr.transId;
1144                break;
1145             case SADBG:
1146             /* Enable Debug Printing */
1147 #ifdef DEBUGP
1148                rgCb[inst].rgInit.dbgMask |= cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
1149 #endif
1150                break;
1151 #ifdef SS_DIAG
1152             case SALOG:
1153                rgCb[inst].rgInit.logMask = cntrl->t.cntrl.s.logMask;
1154                break;
1155 #endif
1156
1157             default:
1158                cfm->cfm.status = LCM_PRIM_NOK;
1159                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1160                RLOG1(L_ERROR, "invalid subaction=%d",cntrl->t.cntrl.subAction);
1161                break;
1162          }
1163          break;
1164       case ADISIMM:
1165          /* Action is Diable immidiately */
1166          switch(cntrl->t.cntrl.subAction)
1167          {
1168             case SATRC:
1169             /* Disable Traces */
1170                rgCb[inst].rgInit.trc = FALSE;
1171                break;
1172             case SAUSTA:
1173             /* Disable Unsolicited Status (alarms) */
1174                rgCb[inst].rgInit.usta = FALSE;
1175                break;
1176             case SADBG:
1177             /* Disable Debug Printing */
1178 #ifdef DEBUGP
1179                rgCb[inst].rgInit.dbgMask &=~cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
1180 #endif
1181                break;
1182 #ifdef SS_DIAG
1183             case SALOG:
1184                rgCb[inst].rgInit.logMask = cntrl->t.cntrl.s.logMask;
1185                 break;
1186 #endif
1187
1188             default:
1189                cfm->cfm.status = LCM_PRIM_NOK;
1190                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1191                RLOG1(L_ERROR, "invalid subaction=%d",cntrl->t.cntrl.subAction);
1192                break;
1193          }
1194          break;
1195       case ASHUTDOWN:
1196          /* Free all the memory dynamically allocated by MAC */
1197          rgLMMShutdown(inst);
1198          break;
1199       default:
1200          cfm->cfm.status = LCM_PRIM_NOK;
1201          cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1202          RLOG1(L_ERROR, "invalid action=%d",cntrl->t.cntrl.action);
1203          break;
1204    }
1205    RgMiLrgCntrlCfm(cfmPst, cfm);
1206    RETVOID;
1207 }
1208
1209 \f
1210 /***********************************************************
1211  *
1212  *     Func : rgLMMSapCntrl 
1213  *        
1214  *
1215  *     Desc : Processes the LM control request for STxxxSAP elmnt.
1216  *            
1217  *
1218  *     Ret  : Void
1219  *
1220  *     Notes: 
1221  *
1222  *     File : rg_lmm.c 
1223  *
1224  **********************************************************/
1225 #ifdef ANSI
1226 PRIVATE Void rgLMMSapCntrl 
1227 (
1228 RgMngmt       *cntrl,
1229 RgMngmt       *cfm,
1230 Pst           *cfmPst
1231 )
1232 #else
1233 PRIVATE Void rgLMMSapCntrl(cntrl, cfm, cfmPst)
1234 RgMngmt       *cntrl;
1235 RgMngmt       *cfm;
1236 Pst           *cfmPst;
1237 #endif
1238 {
1239    Inst      inst = cfmPst->srcInst - RG_INST_START;
1240    TRC2(rgLMMSapCntrl)
1241
1242    /* Only TFU Sap can be controlled by LM */
1243    switch(cntrl->hdr.elmId.elmnt)
1244    {
1245       case STTFUSAP:
1246          switch(cntrl->t.cntrl.action)
1247          {
1248             case ABND:
1249             /* Bind Enable Request */
1250                if ((rgCb[inst].tfuSap.sapSta.sapState == LRG_NOT_CFG) ||
1251                    (rgCb[inst].tfuSap.sapSta.sapState == LRG_BND))
1252                {
1253                   cfm->cfm.status = LCM_PRIM_NOK;
1254                   cfm->cfm.reason = LCM_REASON_INVALID_SAP;
1255                }
1256                else
1257                {
1258                   if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1259                   {
1260                      rgLMMStartTmr(inst,RG_BNDREQ_TMR, rgCb[inst].tfuSap.sapCfg.bndTmr.val, 
1261                      (PTR)&rgCb[inst].tfuSap);
1262                   }
1263                   /* Change SAP state */
1264                   rgCb[inst].tfuSap.sapSta.sapState = LRG_WAIT_BNDCFM;
1265                   rgCb[inst].tfuSap.numBndRetries++;
1266                   /* Store the response and TransId for sending 
1267                    * the Control confirm */
1268                   cmMemcpy((U8 *)&rgCb[inst].genCfg.bndCfmResp.response,
1269                            (U8 *)&cntrl->hdr.response, sizeof(Resp));
1270                   rgCb[inst].genCfg.bndCfmResp.transId = cntrl->hdr.transId;
1271
1272                   /* Sending Status Indication to Layer Manager */
1273                   cfm->cfm.status = LCM_PRIM_OK_NDONE;
1274                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
1275                   RgMiLrgCntrlCfm(cfmPst, cfm);
1276
1277                   rgLIMTfuBndReq(inst,rgCb[inst].tfuSap.sapCfg.suId,
1278                                       rgCb[inst].tfuSap.sapCfg.spId);
1279                   RETVOID;
1280                }
1281                break;
1282             case AUBND:
1283             /* Unbind request */
1284
1285                /* Check if the SAP is configured */
1286                if( (rgCb[inst].tfuSap.sapSta.sapState == LRG_NOT_CFG) ||
1287                      (rgCb[inst].tfuSap.sapSta.sapState == LRG_UNBND))
1288                {
1289                   cfm->cfm.status = LCM_PRIM_NOK;
1290                   cfm->cfm.reason = LCM_REASON_INVALID_MSGTYPE;
1291                }
1292                else
1293                {
1294                   rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, TFU_UBNDREQ_MNGMT);
1295                   if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1296                   {
1297                      rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1298                   }
1299                   /* Change SAP state */
1300                   rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1301                   cfm->cfm.status = LCM_PRIM_OK;
1302                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
1303                }
1304                break;
1305             case ADEL:
1306                /* Delete SAP, does initialization of SAP */
1307                if ((rgCb[inst].tfuSap.sapSta.sapState == LRG_WAIT_BNDCFM) ||
1308                    (rgCb[inst].tfuSap.sapSta.sapState == LRG_BND))
1309                {
1310                   rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, TFU_UBNDREQ_MNGMT);
1311                   if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1312                   {
1313                      rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1314                   }
1315                }
1316                cmMemset((U8 *)&rgCb[inst].tfuSap, 0, sizeof(RgLowSapCb));
1317                rgCb[inst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
1318                cfm->cfm.status = LCM_PRIM_OK;
1319                cfm->cfm.reason = LCM_REASON_NOT_APPL;
1320                break;
1321             default:
1322                cfm->cfm.status = LCM_PRIM_NOK;
1323                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1324                RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgLMMSapCntrl(): invalid action=%d",
1325                cntrl->t.cntrl.action));
1326                break;
1327          }
1328          break;
1329       case STRGUSAP:
1330          switch(cntrl->t.cntrl.action)
1331          {
1332             case ADEL:
1333                cmMemset((U8 *)&rgCb[inst].rguSap[cntrl->t.cntrl.instId], 0, sizeof(RgUpSapCb));
1334                rgCb[inst].rguSap[cntrl->t.cntrl.instId].sapSta.sapState = LRG_NOT_CFG;
1335                cfm->cfm.status = LCM_PRIM_OK;
1336                cfm->cfm.reason = LCM_REASON_NOT_APPL;
1337                break;
1338             default:
1339                cfm->cfm.status = LCM_PRIM_NOK;
1340                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1341                RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgLMMSapCntrl(): invalid action=%d",
1342                cntrl->t.cntrl.action));
1343                break;
1344          }
1345          break;
1346       case STCRGSAP:
1347          switch(cntrl->t.cntrl.action)
1348          {
1349             case ADEL:
1350                cmMemset((U8 *)&rgCb[inst].crgSap, 0, sizeof(RgUpSapCb));
1351                rgCb[inst].crgSap.sapSta.sapState = LRG_NOT_CFG;
1352                cfm->cfm.status = LCM_PRIM_OK;
1353                cfm->cfm.reason = LCM_REASON_NOT_APPL;
1354                break;
1355             default:
1356                cfm->cfm.status = LCM_PRIM_NOK;
1357                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1358                RLOG1(L_ERROR, "invalid action=%d",cntrl->t.cntrl.action);
1359                
1360                break;
1361          }
1362          break;
1363       default:
1364          /* Would never here. */
1365          RETVOID;
1366    }
1367    RgMiLrgCntrlCfm(cfmPst, cfm);
1368    RETVOID;
1369 }
1370
1371 \f
1372 /***********************************************************
1373  *
1374  *     Func : rgLMMFillCfmPst 
1375  *        
1376  *
1377  *     Desc : Fills the Confirmation Post Structure cfmPst using the reqPst 
1378  *            and the cfm->hdr.response.
1379  *            
1380  *
1381  *     Ret  : Void
1382  *
1383  *     Notes: 
1384  *
1385  *     File : rg_lmm.c 
1386  *
1387  **********************************************************/
1388 #ifdef ANSI
1389 PRIVATE Void rgLMMFillCfmPst
1390 (
1391 Pst           *reqPst,
1392 Pst           *cfmPst,
1393 RgMngmt       *cfm
1394 )
1395 #else
1396 PRIVATE Void rgLMMFillCfmPst(reqPst, cfmPst, cfm)
1397 Pst           *reqPst;
1398 Pst           *cfmPst;
1399 RgMngmt       *cfm;
1400 #endif
1401 {
1402    Inst inst;
1403    TRC2(rgLMMFillCfmPst)
1404    inst = (reqPst->dstInst - RG_INST_START);
1405
1406    cfmPst->srcEnt    = rgCb[inst].rgInit.ent;
1407    cfmPst->srcInst   = rgCb[inst].rgInit.inst;
1408    cfmPst->srcProcId = rgCb[inst].rgInit.procId;
1409    cfmPst->dstEnt    = reqPst->srcEnt;
1410    cfmPst->dstInst   = reqPst->srcInst;
1411    cfmPst->dstProcId = reqPst->srcProcId;
1412
1413    cfmPst->selector  = cfm->hdr.response.selector;
1414    cfmPst->prior     = cfm->hdr.response.prior;
1415    cfmPst->route     = cfm->hdr.response.route;
1416    cfmPst->region    = cfm->hdr.response.mem.region;
1417    cfmPst->pool      = cfm->hdr.response.mem.pool;
1418
1419    RETVOID;
1420 }
1421
1422 \f
1423 /**
1424  * @brief Timer start handler. 
1425  *
1426  * @details
1427  *
1428  *     Function : rgLMMStartTmr
1429  *     
1430  *     This function based on the input parameters starts the timer for 
1431  *     "tmrVal" duration. As of now MAC uses the timer functionality for 
1432  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
1433  *     
1434  *  @param[in]  Inst        inst
1435  *  @param[in]  S16   tmrEvnt, the Timer Event    
1436  *  @param[in]  U32   tmrVal,  the Wait Time
1437  *  @param[in]  PTR   cb,  Entry for which Timer expired
1438  *  @return  S16
1439  *      -# ROK
1440  **/
1441 #ifdef ANSI
1442 PUBLIC S16 rgLMMStartTmr
1443 (
1444 Inst               inst,
1445 S16                tmrEvnt,            /* Timer Event */
1446 U32                tmrVal,             /* Wait Time */
1447 PTR                cb                  /* Entry for which Timer Expired */
1448 )
1449 #else
1450 PUBLIC S16 rgLMMStartTmr(tmrEvnt, tmrVal, cb)
1451 Inst               inst;
1452 S16                tmrEvnt;            /* Timer Event */
1453 U32                tmrVal;             /* Wait Time */
1454 PTR                cb;                 /* Entry for which Timer Expired */
1455 #endif
1456 {
1457    CmTmrArg    arg;
1458
1459    TRC2(rgLMMStartTmr)
1460
1461    UNUSED(tmrEvnt);
1462
1463    /* Initialize the arg structure */
1464    cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1465
1466    arg.tqCp = &rgCb[inst].tmrTqCp;
1467    arg.tq = rgCb[inst].tmrTq;
1468    arg.timers = rgCb[inst].tmrBlk;
1469    arg.cb = cb;
1470    arg.tNum = 0;
1471    arg.max = RG_MAX_TIMER;
1472    arg.evnt = RG_BNDREQ_TMR;
1473    arg.wait = tmrVal;      
1474    cmPlcCbTq(&arg);
1475
1476    RETVALUE(ROK);
1477 }
1478
1479 \f
1480 /**
1481  * @brief Timer stop handler. 
1482  *
1483  * @details
1484  *
1485  *     Function : rgLMMStopTmr
1486  *     
1487  *     This function based on the input parameters stops the timer for 
1488  *     "tmrEvnt". As of now MAC uses the timer functionality for 
1489  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
1490  *     Once the bind happens and this timer is stopped, the timer functionality
1491  *     is deregistered with SSI. As there is no further use of timer processing.
1492  *     
1493  *  @param[in]  Inst        inst
1494  *  @param[in]  S16   tmrEvnt, the Timer Event    
1495  *  @param[in]  PTR   cb,  Entry for which Timer expired
1496  *  @return  S16
1497  *      -# ROK
1498  *      -# RFAILED
1499  **/
1500 #ifdef ANSI
1501 PUBLIC S16 rgLMMStopTmr
1502 (
1503 Inst               inst,             /* Scheduler instance */
1504 S16                tmrEvnt,            /* Timer Event */
1505 PTR                cb                  /* Entry for which Timer Expired */
1506 )
1507 #else
1508 PUBLIC S16 rgLMMStopTmr(inst,tmrEvnt, cb)
1509 Inst               inst;             /* Scheduler instance */
1510 S16                tmrEvnt;            /* Timer Event */
1511 PTR                cb;                 /* Entry for which Timer Expired */
1512 #endif
1513 {
1514    CmTmrArg   arg;
1515    U8         i;
1516    S16        ret; 
1517
1518    TRC2(rgLMMStopTmr)
1519
1520    ret = RFAILED;
1521
1522    for(i=0;i<RG_MAX_TIMER;i++)
1523    {
1524       /* Search for the Timer Blocks */
1525       if(rgCb[inst].tmrBlk[i].tmrEvnt == tmrEvnt)
1526       {
1527          /* Initialize the arg structure */
1528          cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1529
1530          arg.tqCp = &rgCb[inst].tmrTqCp;
1531          arg.tq = rgCb[inst].tmrTq;
1532          arg.timers = rgCb[inst].tmrBlk;
1533          arg.cb = cb;
1534          arg.max = RG_MAX_TIMER;
1535          arg.evnt = NOTUSED;
1536          arg.wait = NOTUSED;
1537
1538          arg.tNum = i;   
1539          cmRmvCbTq(&arg);
1540          ret = ROK;
1541          break;
1542       }
1543
1544    }
1545
1546
1547    RETVALUE(ret);
1548 }
1549
1550 \f
1551 /**
1552  * @brief Timer Expiry handler. 
1553  *
1554  * @details
1555  *
1556  *     Function : rgLMMTmrExpiry
1557  *     
1558  *     This is a callback function used as an input parameter to cmPrcTmr()
1559  *     to check expiry of any timer. In this function, the only concern is
1560  *     about tmrEvnt=Bind timer.
1561  *     
1562  *  @param[in]  PTR   cb,  Entry for which Timer expired
1563  *  @param[in]  S16   tmrEvnt, the Timer Event    
1564  *  @return  S16
1565  *      -# ROK
1566  **/
1567 #ifdef ANSI
1568 PUBLIC S16 rgLMMTmrExpiry
1569 (
1570 PTR cb,               /* Pointer to timer control block */
1571 S16 tmrEvnt           /* Timer Event */
1572 )
1573 #else
1574 PUBLIC S16 rgLMMTmrExpiry(cb,tmrEvnt)
1575 PTR cb;               /* Pointer to timer control block */
1576 S16 tmrEvnt;          /* Timer Event */
1577 #endif
1578 {
1579    S16        ret = ROK;
1580    RgLowSapCb *tfuSap = (RgLowSapCb *)cb;
1581    Inst          inst = tfuSap->sapCfg.sapPst.srcInst - RG_INST_START;
1582
1583    TRC2(rgLMMTmrExpiry)
1584
1585    
1586    switch(tmrEvnt)
1587    {
1588       case RG_BNDREQ_TMR:
1589          tfuSap->numBndRetries++;
1590          if(tfuSap->numBndRetries > RG_MAX_BNDRETRY)
1591          {
1592             rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE, LCM_EVENT_BND_FAIL,
1593                         LCM_CAUSE_TMR_EXPIRED, NULLP);
1594          }
1595          else
1596          {
1597             /* Restart the bind timer */
1598             if (tfuSap->sapCfg.bndTmr.enb == TRUE)
1599             {
1600                ret = rgLMMStartTmr(inst,RG_BNDREQ_TMR, tfuSap->sapCfg.bndTmr.val,
1601                cb);
1602             }
1603
1604             /* Send bind request */
1605             rgLIMTfuBndReq(inst,rgCb[inst].tfuSap.sapCfg.suId,
1606                                 rgCb[inst].tfuSap.sapCfg.spId);
1607          }
1608          break;
1609       default:
1610          RLOG1(L_ERROR, "Invalid tmrEvnt=%d",tmrEvnt);
1611          ret = RFAILED;
1612          break;
1613    }
1614    RETVALUE(ret);
1615 }
1616
1617
1618 \f
1619 /**
1620  * @brief Layer Manager Unsolicited Status Indication generation. 
1621  *
1622  * @details
1623  *
1624  *     Function : rgLMMStaInd 
1625  *     
1626  *     This API is used by the other modules of MAC to send a unsolicited
1627  *     status indication to the Layer Manager.
1628  *     
1629  *  @param[in]  Inst        inst
1630  *  @param[in]  U16 category, the Alarm category
1631  *  @param[in]  U16 event, the Alarm event
1632  *  @param[in]  U16 cause, the cause of the Alarm
1633  *  @param[in]  RgUstaDgn *dgn, Alarm Diagonostics
1634  *  @return  S16
1635  *      -# ROK
1636  **/
1637 #ifdef ANSI
1638 PUBLIC S16 rgLMMStaInd
1639 (
1640 Inst inst,
1641 U16 category,
1642 U16 event,
1643 U16 cause,
1644 RgUstaDgn *dgn
1645 )
1646 #else
1647 PUBLIC S16 rgLMMStaInd(inst,category, event, cause, dgn) 
1648 Inst inst;
1649 U16 category;
1650 U16 event;
1651 U16 cause;
1652 RgUstaDgn *dgn;
1653 #endif
1654 {
1655    RgMngmt    usta;
1656
1657    TRC2(rgLMMStaInd)
1658
1659    if(rgCb[inst].rgInit.usta == FALSE)
1660    {
1661       RETVALUE(ROK);
1662    }
1663
1664    cmMemset((U8 *)&usta, 0, sizeof(RgMngmt));
1665
1666    SGetDateTime(&usta.t.usta.cmAlarm.dt);
1667    usta.t.usta.cmAlarm.category = category;
1668    usta.t.usta.cmAlarm.event = event;
1669    usta.t.usta.cmAlarm.cause = cause;
1670    if (dgn != NULLP)
1671    {
1672       cmMemcpy((U8 *)&usta.t.usta.dgn, (U8 *)dgn, sizeof(RgUstaDgn));
1673    }
1674
1675    rgCb[inst].rgInit.lmPst.selector = rgCb[inst].genCfg.ustaResp.response.selector;
1676    rgCb[inst].rgInit.lmPst.prior = rgCb[inst].genCfg.ustaResp.response.prior;
1677    rgCb[inst].rgInit.lmPst.route = rgCb[inst].genCfg.ustaResp.response.route;
1678    rgCb[inst].rgInit.lmPst.region = rgCb[inst].genCfg.ustaResp.response.mem.region;
1679    rgCb[inst].rgInit.lmPst.pool = rgCb[inst].genCfg.ustaResp.response.mem.pool;
1680    usta.hdr.transId = rgCb[inst].genCfg.ustaResp.transId;
1681
1682    RETVALUE(RgMiLrgStaInd(&rgCb[inst].rgInit.lmPst, &usta));
1683 }
1684
1685 \f
1686 /**
1687  * @brief Layer Manager Trace Indication generation. 
1688  *
1689  * @details
1690  *
1691  *     Function : rgLMMTrcInd 
1692  *     
1693  *     This API is used by the other modules of MAC to send a 
1694  *     Trace indication to the Layer Manager.
1695  *     
1696  *  @param[in]  Inst        inst
1697  *  @param[in]   Buffer *srcMbuf, the Message Buffer .
1698  *  @param[in]   U8 event, the trace event.
1699  *  @return Void 
1700  **/
1701 #ifdef ANSI
1702 PUBLIC Void rgLMMTrcInd
1703 (
1704 Inst   inst,
1705 Buffer *srcMbuf,    /* Message Buffer */
1706 U8 event            /* event */
1707 )
1708 #else
1709 PUBLIC Void rgLMMTrcInd(inst,srcMbuf,event)
1710 Inst   inst;
1711 Buffer *srcMbuf;    /* Message Buffer */
1712 U8 event;           /* event */
1713 #endif
1714 {
1715    Buffer   *dstMbuf = NULLP;   
1716    MsgLen   bufLen  = 0;
1717    Data     *tempBuf;
1718    MsgLen   tempCnt;
1719    RgMngmt  trc;
1720    Pst      pst;
1721
1722    TRC2(rgLMMTrcInd)
1723
1724
1725    if ((rgCb[inst].trcLen == LRG_NO_TRACE) || (srcMbuf == NULLP))
1726    {
1727       RLOG0(L_ERROR, "Trace Disabled.");
1728       RETVOID;
1729    }
1730    
1731    cmMemset((U8 *)&trc, 0, sizeof(RgMngmt));
1732
1733    pst = rgCb[inst].rgInit.lmPst;
1734    pst.selector = rgCb[inst].genCfg.trcResp.response.selector;
1735    pst.prior = rgCb[inst].genCfg.trcResp.response.prior;
1736    pst.route = rgCb[inst].genCfg.trcResp.response.route;
1737    pst.region = rgCb[inst].genCfg.trcResp.response.mem.region;
1738    pst.pool = rgCb[inst].genCfg.trcResp.response.mem.pool;
1739
1740    trc.hdr.transId = rgCb[inst].genCfg.trcResp.transId;
1741
1742    SGetDateTime(&trc.t.trc.dt);
1743       
1744    /* Check if the whole buffer is to be sent in Trace indication */
1745    if(rgCb[inst].trcLen == LRG_FULL_TRACE)
1746    {
1747       if (SCpyMsgMsg(srcMbuf, pst.region, pst.pool, &dstMbuf)
1748          != ROK)
1749       {
1750          RLOG0(L_ERROR, "SCpyMsgMsg Failed.");
1751          RETVOID;
1752       }
1753       trc.cfm.status = LCM_PRIM_OK;
1754       trc.cfm.reason = LCM_REASON_NOT_APPL;
1755       trc.t.trc.evnt = event;
1756          
1757       /* Send Trace Indication to Layer manager */
1758       RgMiLrgTrcInd(&pst, &trc, dstMbuf);
1759    }
1760    /* check if only a specified number of bytes are to be sent */
1761    else if(rgCb[inst].trcLen > 0)
1762    {
1763       /* Get the length of the recvd message buffer */
1764       if (SFndLenMsg(srcMbuf, &bufLen) != ROK)
1765       {
1766          RLOG0(L_ERROR, "SFndLenMsg Failed.");
1767          RETVOID;
1768       }
1769       /* Check if the recvd buffer size is less than request trace len */
1770       if(bufLen < rgCb[inst].trcLen)
1771       {
1772          /* Copy the whole of the recvd buffer in trace indication */
1773       
1774          if (SCpyMsgMsg(srcMbuf, pst.region, pst.pool, &dstMbuf)
1775             != ROK)
1776          {
1777             RLOG0(L_ERROR, "SCpyMsgMsg Failed.");
1778             RETVOID;
1779          }
1780          
1781          trc.cfm.status = LCM_PRIM_OK;
1782          trc.cfm.reason = LCM_REASON_NOT_APPL;
1783          trc.t.trc.evnt = event;
1784
1785          /* Send Trace Indication to Layer manager */
1786          RgMiLrgTrcInd(&pst, &trc, dstMbuf);
1787       }
1788       /* if the recvd buffer size is greater than request trace len */
1789       if(bufLen >= rgCb[inst].trcLen)
1790       {
1791          /* Get a temporary buffer to store the msg */
1792          if (rgAllocSBuf(inst,&tempBuf, rgCb[inst].trcLen) != ROK)
1793          {
1794             RLOG0(L_ERROR, "rgAllocSBuf Failed.");
1795             RETVOID;
1796          }
1797          
1798          /* Copy trcLen nos of bytes from the recvd message */
1799          if (SCpyMsgFix(srcMbuf,0,rgCb[inst].trcLen,tempBuf,&tempCnt) != ROK)   
1800          {
1801             RLOG0(L_ERROR, "SCpyMsgFix Failed.");
1802             RETVOID;
1803          }
1804
1805          if (SGetMsg(pst.region, pst.pool, &dstMbuf) != ROK)
1806          {
1807             RLOG0(L_ERROR, "dstMbuf Allocation Failed");
1808             RETVOID;
1809          }
1810          /* Copy the tempBuf data to dst mBuf */
1811          if (SCpyFixMsg(tempBuf,dstMbuf,0,rgCb[inst].trcLen,&tempCnt) != ROK)
1812          {
1813             RLOG0(L_ERROR, "SCpyFixMsg Failed.");
1814             RETVOID;
1815          }
1816
1817          /*ccpu00117052 - MOD - Passing double pointer for proper NULLP 
1818                                assignment */
1819          /* Free the memory allocated for tempBuf */
1820          rgFreeSBuf(inst,&tempBuf, rgCb[inst].trcLen);
1821                
1822          trc.cfm.status = LCM_PRIM_OK;
1823          trc.cfm.reason = LCM_REASON_NOT_APPL;
1824          trc.t.trc.evnt = event;
1825       
1826          /* Send Trace Indication to Layer manager */
1827          RgMiLrgTrcInd(&pst, &trc, dstMbuf);
1828       }
1829    }
1830    RETVOID;
1831 }
1832
1833 \f
1834 /**
1835  * @brief Layer Manager Control Confirm generation handler
1836  *        for Bind Confirm reception at TFU interface.
1837  *        RgLiTfuBndCfm() forwards the confirmation to this 
1838  *        function. All SAP state related handling is restricted
1839  *        to LMM modules, hence the cfm forwarding.
1840  *
1841  * @details
1842  *
1843  *     Function : rgLMMBndCfm 
1844  *     
1845  *     This API is used by the LIM module of MAC to forward
1846  *     the Bind Confirm it receives over the TFU interface.
1847  *     
1848  *  @param[in]   Pst *pst, Post Structure
1849  *  @param[in]   SuId suId, Service user ID
1850  *  @param[in]   U8 status, Status
1851  *  @return  S16
1852  *      -# ROK
1853  **/
1854 #ifdef ANSI
1855 PUBLIC S16 rgLMMBndCfm
1856 (
1857 Pst *pst,               /* Post Structure */
1858 SuId suId,              /* Service user ID */
1859 U8 status               /* Status */
1860 )
1861 #else
1862 PUBLIC S16 rgLMMBndCfm(pst,suId,status)
1863 Pst *pst;               /* Post Structure */
1864 SuId suId;              /* Service user ID */
1865 U8 status;              /* Status */
1866 #endif
1867 {
1868    Inst      inst = pst->dstInst - RG_INST_START;
1869    S16       ret = ROK;
1870    RgMngmt   cntrlCfm;
1871    Pst       cfmPst;
1872
1873    TRC3(rgLMMBndCfm)
1874
1875    UNUSED(pst);
1876
1877    /* Check if the suId is valid */
1878    if(rgCb[inst].tfuSap.sapCfg.suId != suId)
1879    {
1880       RLOG0(L_ERROR, "Invalid SuId");
1881       RETVALUE(RFAILED);
1882    }
1883
1884    /* check the Sap State */
1885    switch(rgCb[inst].tfuSap.sapSta.sapState)
1886    {
1887       case LRG_WAIT_BNDCFM:
1888          break;
1889       case LRG_BND:
1890          /* SAP is already bound */
1891          RETVALUE(ROK);
1892       default:
1893          RETVALUE(RFAILED);
1894    }
1895
1896    cfmPst = rgCb[inst].rgInit.lmPst;
1897    cfmPst.selector = rgCb[inst].genCfg.bndCfmResp.response.selector;
1898    cfmPst.prior = rgCb[inst].genCfg.bndCfmResp.response.prior;
1899    cfmPst.route = rgCb[inst].genCfg.bndCfmResp.response.route;
1900    cfmPst.region = rgCb[inst].genCfg.bndCfmResp.response.mem.region;
1901    cfmPst.pool = rgCb[inst].genCfg.bndCfmResp.response.mem.pool;
1902    
1903    cmMemset((U8 *)&cntrlCfm, 0, sizeof(RgMngmt));
1904
1905    switch(status)
1906    {
1907       case CM_BND_OK: /* status is OK */
1908          /* Change SAP state to Bound */
1909          rgCb[inst].tfuSap.sapSta.sapState = LRG_BND;
1910          if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1911          {
1912             ret = rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1913          }
1914          /* Send Control Confirm with status as OK to Layer Manager */
1915          cntrlCfm.cfm.status = LCM_PRIM_OK;
1916          cntrlCfm.cfm.reason = LCM_REASON_NOT_APPL;
1917          break;
1918
1919       default:
1920          /* Change SAP state to UnBound */
1921          rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1922          if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1923          {
1924             ret = rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1925          }
1926          /* Send Control Confirm with status as NOK to Layer Manager */
1927          cntrlCfm.cfm.status = LCM_PRIM_NOK;
1928          cntrlCfm.cfm.reason = LCM_REASON_NEG_CFM;
1929          break;
1930    }
1931    rgCb[inst].tfuSap.numBndRetries = 0;
1932    cntrlCfm.hdr.elmId.elmnt = STTFUSAP;
1933    cntrlCfm.hdr.transId = rgCb[inst].genCfg.bndCfmResp.transId;
1934
1935    ret = RgMiLrgCntrlCfm(&cfmPst, &cntrlCfm);
1936
1937    RETVALUE(ret);
1938 }
1939
1940 \f
1941 /**
1942  * @brief LTE MAC timer call back function registered with SSI. 
1943  *
1944  * @details
1945  *
1946  *     Function :  rgActvTmr
1947  *     
1948  *     This function is invoked by SSI for every timer activation
1949  *     period expiry.
1950  *     
1951  *  @return  S16
1952  *      -# ROK
1953  **/
1954 #ifdef ANSI
1955 PUBLIC S16 rgActvTmr
1956 (
1957  Ent     ent,
1958  Inst    inst
1959 )
1960 #else
1961 PUBLIC S16 rgActvTmr(ent, inst)
1962 Ent     ent;
1963 Inst    inst;
1964 #endif
1965 {
1966    Inst macInst = (inst  - RG_INST_START);
1967    TRC3(rgActvTmr)
1968
1969    /* Check if any MAC timer has expired */ 
1970    cmPrcTmr(&rgCb[macInst].tmrTqCp, rgCb[macInst].tmrTq, (PFV) rgLMMTmrExpiry);
1971  
1972    RETVALUE(ROK);
1973  
1974 } /* end of rgActvTmr */
1975
1976 /**
1977  * @brief Layer Manager  Configuration request handler for Scheduler
1978  *
1979  * @details
1980  *
1981  *     Function : MacSchGenCfgReq
1982  *     
1983  *     This function receives general configurations for Scheduler
1984  *     from DU APP and forwards to Scheduler.
1985  *     
1986  *  @param[in]  Pst *pst, the post structure     
1987  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
1988  *  @return  S16
1989  *      -# ROK
1990  **/
1991 #ifdef ANSI
1992 PUBLIC S16 MacSchGenCfgReq
1993 (
1994 Pst      *pst,    /* post structure  */
1995 RgMngmt  *cfg     /* config structure  */
1996 )
1997 #else
1998 PUBLIC S16 MacSchGenCfgReq(pst, cfg)
1999 Pst      *pst;    /* post structure  */
2000 RgMngmt  *cfg;    /* config structure  */
2001 #endif    
2002 {
2003    printf("\nReceived Scheduler gen config at MAC");
2004    pst->dstInst = DEFAULT_CELLS + 1;
2005    HandleSchGenCfgReq(pst, cfg);
2006
2007    return ROK;
2008 }
2009
2010 /**
2011  * @brief Layer Manager Configuration response from Scheduler
2012  *
2013  * @details
2014  *
2015  *     Function : SchSendCfgCfm
2016  *     
2017  *     This function sends general configurations response from
2018  *     Scheduler to DU APP.
2019  *     
2020  *  @param[in]  Pst *pst, the post structure     
2021  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
2022  *  @return  S16
2023  *      -# ROK
2024  **/
2025 #ifdef ANSI
2026 PUBLIC S16 SchSendCfgCfm 
2027 (
2028 Pst      *pst,    /* post structure  */
2029 RgMngmt  *cfm     /* config confirm structure  */
2030 )
2031 #else
2032 PUBLIC S16 SchSendCfgCfm(pst, cfm)
2033 Pst      *pst;    /* post structure  */
2034 RgMngmt  *cfm;    /* config confirm structure  */
2035 #endif    
2036 {
2037    printf("\nSending Scheduler config confirm to DU APP");
2038         pst->dstEnt = ENTDUAPP;
2039         pst->dstInst = 0;
2040         pst->srcInst = 0;
2041         pst->selector = MAC_SCH_LC_SELECTOR; 
2042    RgMiLrgSchCfgCfm(pst, cfm);
2043    
2044    RETVALUE(ROK);
2045 }
2046
2047 \f
2048 /***********************************************************
2049  *
2050  *     Func : macCellCfgFillCfmPst 
2051  *        
2052  *
2053  *     Desc : Fills the Confirmation Post Structure cfmPst 
2054  *
2055  *     Ret  : Void
2056  *
2057  *     Notes: 
2058  *
2059  *     File : rg_lmm.c 
2060  *
2061  **********************************************************/
2062 Void macCellCfgFillCfmPst
2063 (
2064 Pst           *reqPst,
2065 Pst           *cfmPst
2066 )
2067 {
2068    Inst inst;
2069    inst = reqPst->dstInst;
2070
2071    cfmPst->srcEnt    = rgCb[inst].rgInit.ent;
2072    cfmPst->srcInst   = rgCb[inst].rgInit.inst;
2073    cfmPst->srcProcId = rgCb[inst].rgInit.procId;
2074
2075    cfmPst->dstEnt    = ENTDUAPP;
2076    cfmPst->dstInst   = 0;
2077    cfmPst->dstProcId = cfmPst->srcProcId;
2078
2079    cfmPst->selector  = LRG_SEL_LC;
2080    cfmPst->prior     = reqPst->prior;
2081    cfmPst->route     = reqPst->route;
2082    cfmPst->region    = reqPst->region;
2083    cfmPst->pool      = reqPst->pool;
2084    cfmPst->event     = EVENT_MAC_CELL_CONFIG_CFM;
2085
2086    RETVOID;
2087 }
2088
2089 /**
2090  * @brief Layer Manager Configuration request handler. 
2091  *
2092  * @details
2093  *
2094  *     Function : MacHdlCellCfgReq 
2095  *     
2096  *     This function handles the gNB and cell configuration
2097  *     request received from DU APP.
2098  *     This API unapcks and forwards the config towards SCH
2099  *     
2100  *  @param[in]  Pst           *pst
2101  *  @param[in]  MacCellCfg    *macCellCfg 
2102  *  @return  S16
2103  *      -# ROK
2104  **/
2105 int MacHdlCellCfgReq
2106 (
2107  Pst           *pst,
2108  MacCellCfg    *macCellCfg
2109 )
2110 {
2111    Pst cfmPst;
2112    int ret = ROK;
2113    RgCellCb      *cellCb;
2114         MacCellCb     *macCellCb;
2115    Inst inst = pst->dstInst;
2116
2117    cmMemset((U8 *)&cfmPst, 0, sizeof(Pst));
2118    MAC_ALLOC(cellCb,sizeof(RgCellCb));
2119
2120    if(cellCb == NULLP)
2121    {
2122       DU_LOG("\nMAC : cellCb is NULL at handling of macCellCfg\n");
2123       return RFAILED;
2124    }
2125
2126    memcpy(&cellCb->macCellCfg,macCellCfg,sizeof(MacCellCfg));
2127    rgCb[inst].cell = cellCb;
2128
2129    MAC_ALLOC(macCellCb,sizeof(MacCellCb));
2130         if(macCellCb == NULLP)
2131         {
2132       DU_LOG("\nMAC : macCellCb is NULL at handling of macCellCfg\n");
2133       return RFAILED;
2134    }
2135    macCb.macCell = macCellCb;
2136    macCb.macCell->cellId = macCellCfg->cellId;
2137    /* Send cell cfg to scheduler */
2138    ret = MacSchCellCfgReq(pst, macCellCfg);
2139         if(ret != ROK)
2140         {
2141                 MacCellCfgCfm macCellCfgCfm;
2142                 macCellCfgCfm.rsp = RSP_NOK;
2143                 macCellCfgCfm.transId = macCellCfg->transId;
2144                 macCellCfgFillCfmPst(pst,&cfmPst);
2145                 ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
2146         }
2147 #ifdef INTEL_WLS
2148    LwrMacEnqueueWlsBlock();
2149 #endif
2150    return ret;
2151 } /* end of MacHdlCellCfgReq */
2152
2153 /**
2154  * @brief Layer Manager Configuration request handler. 
2155  *
2156  * @details
2157  *
2158  *     Function : MacSchCellCfgReq 
2159  *     
2160  *     This function sends cell configuration to SCH
2161  *     
2162  *  @param[in]  Pst           *pst
2163  *  @param[in]  MacCellCfg    *macCellCfg 
2164  *  @return  S16
2165  *      -# ROK
2166  **/
2167 int MacSchCellCfgReq
2168 (
2169  Pst           *pst,
2170  MacCellCfg    *macCellCfg
2171 )
2172 {
2173    SchCellCfg schCellCfg;
2174         Pst        cfgPst;
2175         int ret;
2176
2177    cmMemset((U8 *)&cfgPst, 0, sizeof(Pst));
2178         schCellCfg.cellId = macCellCfg->cellId;
2179         schCellCfg.phyCellId = macCellCfg->phyCellId;
2180         schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
2181         schCellCfg.dupMode = macCellCfg->dupType;
2182
2183         /* fill ssb scheduler parameters */
2184         schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
2185         schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
2186         schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2187         schCellCfg.ssbSchCfg.ssbPeriod = macCellCfg->ssbCfg.ssbPeriod;
2188         schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
2189         for(uint8_t idx=0; idx<SSB_MASK_SIZE; idx++)
2190         {
2191       schCellCfg.ssbSchCfg.nSSBMask[idx] = macCellCfg->ssbCfg.ssbMask[idx]; 
2192         }
2193
2194         /* fill SIB1 scheduler parameters */
2195         schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen; 
2196         schCellCfg.sib1SchCfg.sib1NewTxPeriod = macCellCfg->sib1Cfg.sib1NewTxPeriod; 
2197         schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod; 
2198         schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex; 
2199         schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex; 
2200         schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs; 
2201
2202    cfgPst.srcProcId = pst->dstProcId;
2203         cfgPst.dstProcId = pst->srcProcId;
2204         cfgPst.srcEnt    = ENTRG;
2205         cfgPst.srcInst   = 0;
2206         cfgPst.dstEnt    = ENTRG;
2207         cfgPst.dstInst   = 1;
2208         cfgPst.selector  = MAC_SCH_TC_SELECTOR;
2209         cfgPst.event     = EVENT_SCH_CELL_CFG;
2210
2211         ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
2212         return ret;
2213 } /* end of MacSchCellCfgReq */
2214
2215
2216 /*******************************************************************
2217  *
2218  * @brief Sends Cell config confirm to DU APP
2219  *
2220  * @details
2221  *
2222  *    Function : MacSendCellCfgCfm 
2223  *
2224  *    Functionality:
2225  *      Sends Cell config confirm to DU APP
2226  *
2227  * @params[in] Response status
2228  * @return void
2229  *
2230  * ****************************************************************/
2231 void MacSendCellCfgCfm(uint8_t response)
2232 {
2233    Pst pst;
2234    RgCellCb      *cellCb;
2235    MacCellCfgCfm macCellCfgCfm;
2236  
2237    cmMemset((U8 *)&pst, 0, sizeof(Pst));
2238    cellCb = rgCb[macCb.macInst].cell;
2239  
2240    macCellCfgCfm.transId = cellCb->macCellCfg.transId;
2241    macCellCfgCfm.rsp = response;
2242
2243    memcpy((void *)&pst, (void *)&rgCb[macCb.macInst].rgInit.lmPst, sizeof(Pst));
2244    pst.event = EVENT_MAC_CELL_CONFIG_CFM;
2245    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
2246 }
2247
2248
2249 /**
2250  * @brief Layer Manager Configuration response handler. 
2251  *
2252  * @details
2253  *
2254  *     Function : MacProcSchCellCfgCfm
2255  *     
2256  *     This function processes cell configuration to SCH
2257  *     
2258  *  @param[in]  Pst           *pst
2259  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
2260  *  @return  int
2261  *      -# ROK
2262  **/
2263 int MacProcSchCellCfgCfm 
2264 (
2265  Pst           *pst,
2266  SchCellCfgCfm *schCellCfgCfm
2267 )
2268 {
2269         if(schCellCfgCfm->rsp == RSP_OK)
2270         {
2271       sendToLowerMac(PARAM_REQUEST, 0, (void *)NULL);
2272         }
2273         else
2274         {
2275       MacSendCellCfgCfm(RSP_NOK);
2276         }
2277    return ROK;  
2278 }
2279
2280 /**********************************************************************
2281  
2282          End of file
2283 **********************************************************************/