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