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