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