Merge "Added missing triggers and state params for cell up"
[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 #include "mac.h"
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 MacCb  macCb;
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
941    macCb.macInst = rgCb[inst].rgInit.inst;
942
943    /* Initialize SAP States */
944    rgCb[inst].crgSap.sapSta.sapState = LRG_NOT_CFG;
945
946    if(cfg->s.genCfg.numRguSaps == 0)
947    {
948       RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgGenCfg(): Invalid numRguSap.\n"));
949       RETVALUE(RFAILED);
950    }
951
952    /* allocate RGR saps */
953    if (SGetSBuf(rgCb[inst].rgInit.region,
954                 rgCb[inst].rgInit.pool,
955                 (Data **)&rgCb[inst].rguSap,
956                 (sizeof(RgUpSapCb) * cfg->s.genCfg.numRguSaps)) != ROK)
957    {
958       RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgGenCfg(): Failed to allocate mem for RGU SAP's.\n"));
959       RETVALUE(RFAILED);
960    }
961    rgCb[inst].numRguSaps = cfg->s.genCfg.numRguSaps;
962
963    for (int idx = 0; idx < rgCb[inst].numRguSaps; idx++)
964    {
965       rgCb[inst].rguSap[idx].sapSta.sapState = LRG_NOT_CFG;
966       cmMemset((U8 *)&rgCb[inst].rguSap[idx], 0, sizeof(RgUpSapCb));
967    }
968    rgCb[inst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
969    /* Initialize the timer blocks */
970    cmInitTimers(rgCb[inst].tmrBlk, RG_MAX_TIMER);
971    /* Initialzie the timer queue */   
972    cmMemset((U8 *)&rgCb[inst].tmrTq, 0, sizeof(CmTqType)*RG_TQ_SIZE);
973    /* Initialize the timer control point */
974    cmMemset((U8 *)&rgCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
975    rgCb[inst].tmrTqCp.tmrLen = RG_TQ_SIZE;
976 #if 0
977    /* Timer Registration request to SSI */
978    if (SRegTmrMt(rgCb[inst].rgInit.ent, rgCb[inst].rgInit.inst,
979             (S16)rgCb[inst].genCfg.tmrRes, rgActvTmr) != ROK)
980    {
981       
982       RLOG0(L_ERROR, "Failed to register timer");
983
984       SPutSBuf(rgCb[inst].rgInit.region,
985                 rgCb[inst].rgInit.pool,
986                 (Data *)rgCb[inst].rguSap,
987                 (sizeof(RgUpSapCb) * cfg->s.genCfg.numRguSaps));
988
989       RETVALUE(LCM_REASON_MEM_NOAVAIL);
990    }
991 #endif
992    /* Set Config done in TskInit */
993    rgCb[inst].rgInit.cfgDone = TRUE;
994
995    RETVALUE(ret);
996 }
997
998 \f
999 /***********************************************************
1000  *
1001  *     Func : rgLMMShutdown
1002  *        
1003  *
1004  *     Desc : Handles the MAC layer shutdown request. Calls 
1005  *     rgCFGFreeCellCb(RgCellCb*) to handle each cellCb deallocation.
1006  *            
1007  *
1008  *     Ret  : Void
1009  *
1010  *     Notes: 
1011  *
1012  *     File : rg_lmm.c 
1013  *
1014  **********************************************************/
1015 #ifdef ANSI
1016 PRIVATE Void rgLMMShutdown
1017 (
1018 Inst inst
1019 )
1020 #else
1021 PRIVATE Void rgLMMShutdown(inst)
1022 Inst inst;
1023 #endif
1024 {
1025    RgCellCb   *cell = rgCb[inst].cell;
1026    U8 idx;
1027
1028    TRC2(rgLMMShutdown)
1029
1030    /* Unbind the TFU Sap */
1031    if(rgCb[inst].tfuSap.sapSta.sapState == LRG_WAIT_BNDCFM)
1032    {
1033       rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, LRG_UNBND);
1034       if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1035       {
1036          rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap); 
1037       }
1038       rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1039    }
1040    if(rgCb[inst].tfuSap.sapSta.sapState == LRG_BND)
1041    {
1042       rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, LRG_UNBND);
1043       rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1044    }
1045
1046
1047    if(cell != NULLP)
1048    {
1049       for(idx=0;idx < RG_NUM_SUB_FRAMES; idx++)
1050       {
1051          rgTOMRlsSf(inst,&cell->subFrms[idx]);
1052       }
1053
1054       rgCFGFreeCellCb(cell);
1055    }
1056
1057    /* Deleting the RGU SAPs */
1058    SPutSBuf(rgCb[inst].rgInit.region,
1059                 rgCb[inst].rgInit.pool,
1060                 (Data *)rgCb[inst].rguSap,
1061                 (sizeof(RgUpSapCb) * rgCb[inst].numRguSaps));
1062    rgCb[inst].rguSap = NULLP;
1063
1064    rgCb[inst].inactiveCell = NULLP;
1065    rgCb[inst].cell         = NULLP;
1066
1067    /* De-register the Timer Service */
1068    (Void) SDeregTmrMt(rgCb[inst].rgInit.ent, rgCb[inst].rgInit.inst,
1069                      (S16)rgCb[inst].genCfg.tmrRes, rgActvTmr); 
1070
1071    /* call back the task initialization function to intialize
1072     * the global RgCb Struct */
1073    rgActvInit(rgCb[inst].rgInit.ent, rgCb[inst].rgInit.inst, rgCb[inst].rgInit.region, 
1074               rgCb[inst].rgInit.reason);
1075
1076    RETVOID;
1077 }
1078
1079 \f
1080 /***********************************************************
1081  *
1082  *     Func : rgLMMGenCntrl 
1083  *        
1084  *
1085  *     Desc : Processes the LM control request for STGEN elmnt.
1086  *            
1087  *
1088  *     Ret  : Void
1089  *
1090  *     Notes: 
1091  *
1092  *     File : rg_lmm.c 
1093  *
1094  **********************************************************/
1095 #ifdef ANSI
1096 PRIVATE Void rgLMMGenCntrl 
1097 (
1098 RgMngmt       *cntrl,
1099 RgMngmt       *cfm,
1100 Pst           *cfmPst
1101 )
1102 #else
1103 PRIVATE Void rgLMMGenCntrl(cntrl, cfm, cfmPst)
1104 RgMngmt       *cntrl;
1105 RgMngmt       *cfm;
1106 Pst           *cfmPst;
1107 #endif
1108 {
1109    Inst      inst = (cfmPst->srcInst - RG_INST_START);
1110    TRC2(rgLMMGenCntrl)
1111
1112    cfm->cfm.status = LCM_PRIM_OK;
1113    cfm->cfm.reason = LCM_REASON_NOT_APPL;
1114    
1115
1116    switch(cntrl->t.cntrl.action)
1117    {
1118       case AENA:
1119          /* Action is Enable */
1120          switch(cntrl->t.cntrl.subAction)
1121          {
1122             case SATRC:
1123             /* Enable Traces */
1124                rgCb[inst].rgInit.trc = TRUE;
1125                rgCb[inst].trcLen = cntrl->t.cntrl.s.trcLen;
1126                /*Store the response and TransId for sending the Traces */
1127                cmMemcpy((U8 *)&rgCb[inst].genCfg.trcResp.response, 
1128                (U8 *)&cntrl->hdr.response, sizeof(Resp));
1129                rgCb[inst].genCfg.trcResp.transId = cntrl->hdr.transId;
1130                
1131                break;
1132             case SAUSTA:   
1133             /* Enable Unsolicited Status (alarms) */
1134                rgCb[inst].rgInit.usta = TRUE;
1135                /*Store the response and TransId for sending the Alarms */
1136                cmMemcpy((U8 *)&rgCb[inst].genCfg.ustaResp.response, 
1137                (U8 *)&cntrl->hdr.response, sizeof(Resp));
1138                rgCb[inst].genCfg.ustaResp.transId = cntrl->hdr.transId;
1139                break;
1140             case SADBG:
1141             /* Enable Debug Printing */
1142 #ifdef DEBUGP
1143                rgCb[inst].rgInit.dbgMask |= cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
1144 #endif
1145                break;
1146 #ifdef SS_DIAG
1147             case SALOG:
1148                rgCb[inst].rgInit.logMask = cntrl->t.cntrl.s.logMask;
1149                break;
1150 #endif
1151
1152             default:
1153                cfm->cfm.status = LCM_PRIM_NOK;
1154                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1155                RLOG1(L_ERROR, "invalid subaction=%d",cntrl->t.cntrl.subAction);
1156                break;
1157          }
1158          break;
1159       case ADISIMM:
1160          /* Action is Diable immidiately */
1161          switch(cntrl->t.cntrl.subAction)
1162          {
1163             case SATRC:
1164             /* Disable Traces */
1165                rgCb[inst].rgInit.trc = FALSE;
1166                break;
1167             case SAUSTA:
1168             /* Disable Unsolicited Status (alarms) */
1169                rgCb[inst].rgInit.usta = FALSE;
1170                break;
1171             case SADBG:
1172             /* Disable Debug Printing */
1173 #ifdef DEBUGP
1174                rgCb[inst].rgInit.dbgMask &=~cntrl->t.cntrl.s.rgDbgCntrl.dbgMask;
1175 #endif
1176                break;
1177 #ifdef SS_DIAG
1178             case SALOG:
1179                rgCb[inst].rgInit.logMask = cntrl->t.cntrl.s.logMask;
1180                 break;
1181 #endif
1182
1183             default:
1184                cfm->cfm.status = LCM_PRIM_NOK;
1185                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1186                RLOG1(L_ERROR, "invalid subaction=%d",cntrl->t.cntrl.subAction);
1187                break;
1188          }
1189          break;
1190       case ASHUTDOWN:
1191          /* Free all the memory dynamically allocated by MAC */
1192          rgLMMShutdown(inst);
1193          break;
1194       default:
1195          cfm->cfm.status = LCM_PRIM_NOK;
1196          cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1197          RLOG1(L_ERROR, "invalid action=%d",cntrl->t.cntrl.action);
1198          break;
1199    }
1200    RgMiLrgCntrlCfm(cfmPst, cfm);
1201    RETVOID;
1202 }
1203
1204 \f
1205 /***********************************************************
1206  *
1207  *     Func : rgLMMSapCntrl 
1208  *        
1209  *
1210  *     Desc : Processes the LM control request for STxxxSAP elmnt.
1211  *            
1212  *
1213  *     Ret  : Void
1214  *
1215  *     Notes: 
1216  *
1217  *     File : rg_lmm.c 
1218  *
1219  **********************************************************/
1220 #ifdef ANSI
1221 PRIVATE Void rgLMMSapCntrl 
1222 (
1223 RgMngmt       *cntrl,
1224 RgMngmt       *cfm,
1225 Pst           *cfmPst
1226 )
1227 #else
1228 PRIVATE Void rgLMMSapCntrl(cntrl, cfm, cfmPst)
1229 RgMngmt       *cntrl;
1230 RgMngmt       *cfm;
1231 Pst           *cfmPst;
1232 #endif
1233 {
1234    Inst      inst = cfmPst->srcInst - RG_INST_START;
1235    TRC2(rgLMMSapCntrl)
1236
1237    /* Only TFU Sap can be controlled by LM */
1238    switch(cntrl->hdr.elmId.elmnt)
1239    {
1240       case STTFUSAP:
1241          switch(cntrl->t.cntrl.action)
1242          {
1243             case ABND:
1244             /* Bind Enable Request */
1245                if ((rgCb[inst].tfuSap.sapSta.sapState == LRG_NOT_CFG) ||
1246                    (rgCb[inst].tfuSap.sapSta.sapState == LRG_BND))
1247                {
1248                   cfm->cfm.status = LCM_PRIM_NOK;
1249                   cfm->cfm.reason = LCM_REASON_INVALID_SAP;
1250                }
1251                else
1252                {
1253                   if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1254                   {
1255                      rgLMMStartTmr(inst,RG_BNDREQ_TMR, rgCb[inst].tfuSap.sapCfg.bndTmr.val, 
1256                      (PTR)&rgCb[inst].tfuSap);
1257                   }
1258                   /* Change SAP state */
1259                   rgCb[inst].tfuSap.sapSta.sapState = LRG_WAIT_BNDCFM;
1260                   rgCb[inst].tfuSap.numBndRetries++;
1261                   /* Store the response and TransId for sending 
1262                    * the Control confirm */
1263                   cmMemcpy((U8 *)&rgCb[inst].genCfg.bndCfmResp.response,
1264                            (U8 *)&cntrl->hdr.response, sizeof(Resp));
1265                   rgCb[inst].genCfg.bndCfmResp.transId = cntrl->hdr.transId;
1266
1267                   /* Sending Status Indication to Layer Manager */
1268                   cfm->cfm.status = LCM_PRIM_OK_NDONE;
1269                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
1270                   RgMiLrgCntrlCfm(cfmPst, cfm);
1271
1272                   rgLIMTfuBndReq(inst,rgCb[inst].tfuSap.sapCfg.suId,
1273                                       rgCb[inst].tfuSap.sapCfg.spId);
1274                   RETVOID;
1275                }
1276                break;
1277             case AUBND:
1278             /* Unbind request */
1279
1280                /* Check if the SAP is configured */
1281                if( (rgCb[inst].tfuSap.sapSta.sapState == LRG_NOT_CFG) ||
1282                      (rgCb[inst].tfuSap.sapSta.sapState == LRG_UNBND))
1283                {
1284                   cfm->cfm.status = LCM_PRIM_NOK;
1285                   cfm->cfm.reason = LCM_REASON_INVALID_MSGTYPE;
1286                }
1287                else
1288                {
1289                   rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, TFU_UBNDREQ_MNGMT);
1290                   if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1291                   {
1292                      rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1293                   }
1294                   /* Change SAP state */
1295                   rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1296                   cfm->cfm.status = LCM_PRIM_OK;
1297                   cfm->cfm.reason = LCM_REASON_NOT_APPL;
1298                }
1299                break;
1300             case ADEL:
1301                /* Delete SAP, does initialization of SAP */
1302                if ((rgCb[inst].tfuSap.sapSta.sapState == LRG_WAIT_BNDCFM) ||
1303                    (rgCb[inst].tfuSap.sapSta.sapState == LRG_BND))
1304                {
1305                   rgLIMTfuUbndReq(inst,rgCb[inst].tfuSap.sapCfg.spId, TFU_UBNDREQ_MNGMT);
1306                   if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1307                   {
1308                      rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1309                   }
1310                }
1311                cmMemset((U8 *)&rgCb[inst].tfuSap, 0, sizeof(RgLowSapCb));
1312                rgCb[inst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
1313                cfm->cfm.status = LCM_PRIM_OK;
1314                cfm->cfm.reason = LCM_REASON_NOT_APPL;
1315                break;
1316             default:
1317                cfm->cfm.status = LCM_PRIM_NOK;
1318                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1319                RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgLMMSapCntrl(): invalid action=%d",
1320                cntrl->t.cntrl.action));
1321                break;
1322          }
1323          break;
1324       case STRGUSAP:
1325          switch(cntrl->t.cntrl.action)
1326          {
1327             case ADEL:
1328                cmMemset((U8 *)&rgCb[inst].rguSap[cntrl->t.cntrl.instId], 0, sizeof(RgUpSapCb));
1329                rgCb[inst].rguSap[cntrl->t.cntrl.instId].sapSta.sapState = LRG_NOT_CFG;
1330                cfm->cfm.status = LCM_PRIM_OK;
1331                cfm->cfm.reason = LCM_REASON_NOT_APPL;
1332                break;
1333             default:
1334                cfm->cfm.status = LCM_PRIM_NOK;
1335                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1336                RGDBGERRNEW(inst,(rgPBuf(inst), "\nrgLMMSapCntrl(): invalid action=%d",
1337                cntrl->t.cntrl.action));
1338                break;
1339          }
1340          break;
1341       case STCRGSAP:
1342          switch(cntrl->t.cntrl.action)
1343          {
1344             case ADEL:
1345                cmMemset((U8 *)&rgCb[inst].crgSap, 0, sizeof(RgUpSapCb));
1346                rgCb[inst].crgSap.sapSta.sapState = LRG_NOT_CFG;
1347                cfm->cfm.status = LCM_PRIM_OK;
1348                cfm->cfm.reason = LCM_REASON_NOT_APPL;
1349                break;
1350             default:
1351                cfm->cfm.status = LCM_PRIM_NOK;
1352                cfm->cfm.reason = LCM_REASON_INVALID_PAR_VAL;
1353                RLOG1(L_ERROR, "invalid action=%d",cntrl->t.cntrl.action);
1354                
1355                break;
1356          }
1357          break;
1358       default:
1359          /* Would never here. */
1360          RETVOID;
1361    }
1362    RgMiLrgCntrlCfm(cfmPst, cfm);
1363    RETVOID;
1364 }
1365
1366 \f
1367 /***********************************************************
1368  *
1369  *     Func : rgLMMFillCfmPst 
1370  *        
1371  *
1372  *     Desc : Fills the Confirmation Post Structure cfmPst using the reqPst 
1373  *            and the cfm->hdr.response.
1374  *            
1375  *
1376  *     Ret  : Void
1377  *
1378  *     Notes: 
1379  *
1380  *     File : rg_lmm.c 
1381  *
1382  **********************************************************/
1383 #ifdef ANSI
1384 PRIVATE Void rgLMMFillCfmPst
1385 (
1386 Pst           *reqPst,
1387 Pst           *cfmPst,
1388 RgMngmt       *cfm
1389 )
1390 #else
1391 PRIVATE Void rgLMMFillCfmPst(reqPst, cfmPst, cfm)
1392 Pst           *reqPst;
1393 Pst           *cfmPst;
1394 RgMngmt       *cfm;
1395 #endif
1396 {
1397    Inst inst;
1398    TRC2(rgLMMFillCfmPst)
1399    inst = (reqPst->dstInst - RG_INST_START);
1400
1401    cfmPst->srcEnt    = rgCb[inst].rgInit.ent;
1402    cfmPst->srcInst   = rgCb[inst].rgInit.inst;
1403    cfmPst->srcProcId = rgCb[inst].rgInit.procId;
1404    cfmPst->dstEnt    = reqPst->srcEnt;
1405    cfmPst->dstInst   = reqPst->srcInst;
1406    cfmPst->dstProcId = reqPst->srcProcId;
1407
1408    cfmPst->selector  = cfm->hdr.response.selector;
1409    cfmPst->prior     = cfm->hdr.response.prior;
1410    cfmPst->route     = cfm->hdr.response.route;
1411    cfmPst->region    = cfm->hdr.response.mem.region;
1412    cfmPst->pool      = cfm->hdr.response.mem.pool;
1413
1414    RETVOID;
1415 }
1416
1417 \f
1418 /**
1419  * @brief Timer start handler. 
1420  *
1421  * @details
1422  *
1423  *     Function : rgLMMStartTmr
1424  *     
1425  *     This function based on the input parameters starts the timer for 
1426  *     "tmrVal" duration. As of now MAC uses the timer functionality for 
1427  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
1428  *     
1429  *  @param[in]  Inst        inst
1430  *  @param[in]  S16   tmrEvnt, the Timer Event    
1431  *  @param[in]  U32   tmrVal,  the Wait Time
1432  *  @param[in]  PTR   cb,  Entry for which Timer expired
1433  *  @return  S16
1434  *      -# ROK
1435  **/
1436 #ifdef ANSI
1437 PUBLIC S16 rgLMMStartTmr
1438 (
1439 Inst               inst,
1440 S16                tmrEvnt,            /* Timer Event */
1441 U32                tmrVal,             /* Wait Time */
1442 PTR                cb                  /* Entry for which Timer Expired */
1443 )
1444 #else
1445 PUBLIC S16 rgLMMStartTmr(tmrEvnt, tmrVal, cb)
1446 Inst               inst;
1447 S16                tmrEvnt;            /* Timer Event */
1448 U32                tmrVal;             /* Wait Time */
1449 PTR                cb;                 /* Entry for which Timer Expired */
1450 #endif
1451 {
1452    CmTmrArg    arg;
1453
1454    TRC2(rgLMMStartTmr)
1455
1456    UNUSED(tmrEvnt);
1457
1458    /* Initialize the arg structure */
1459    cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1460
1461    arg.tqCp = &rgCb[inst].tmrTqCp;
1462    arg.tq = rgCb[inst].tmrTq;
1463    arg.timers = rgCb[inst].tmrBlk;
1464    arg.cb = cb;
1465    arg.tNum = 0;
1466    arg.max = RG_MAX_TIMER;
1467    arg.evnt = RG_BNDREQ_TMR;
1468    arg.wait = tmrVal;      
1469    cmPlcCbTq(&arg);
1470
1471    RETVALUE(ROK);
1472 }
1473
1474 \f
1475 /**
1476  * @brief Timer stop handler. 
1477  *
1478  * @details
1479  *
1480  *     Function : rgLMMStopTmr
1481  *     
1482  *     This function based on the input parameters stops the timer for 
1483  *     "tmrEvnt". As of now MAC uses the timer functionality for 
1484  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
1485  *     Once the bind happens and this timer is stopped, the timer functionality
1486  *     is deregistered with SSI. As there is no further use of timer processing.
1487  *     
1488  *  @param[in]  Inst        inst
1489  *  @param[in]  S16   tmrEvnt, the Timer Event    
1490  *  @param[in]  PTR   cb,  Entry for which Timer expired
1491  *  @return  S16
1492  *      -# ROK
1493  *      -# RFAILED
1494  **/
1495 #ifdef ANSI
1496 PUBLIC S16 rgLMMStopTmr
1497 (
1498 Inst               inst,             /* Scheduler instance */
1499 S16                tmrEvnt,            /* Timer Event */
1500 PTR                cb                  /* Entry for which Timer Expired */
1501 )
1502 #else
1503 PUBLIC S16 rgLMMStopTmr(inst,tmrEvnt, cb)
1504 Inst               inst;             /* Scheduler instance */
1505 S16                tmrEvnt;            /* Timer Event */
1506 PTR                cb;                 /* Entry for which Timer Expired */
1507 #endif
1508 {
1509    CmTmrArg   arg;
1510    U8         i;
1511    S16        ret; 
1512
1513    TRC2(rgLMMStopTmr)
1514
1515    ret = RFAILED;
1516
1517    for(i=0;i<RG_MAX_TIMER;i++)
1518    {
1519       /* Search for the Timer Blocks */
1520       if(rgCb[inst].tmrBlk[i].tmrEvnt == tmrEvnt)
1521       {
1522          /* Initialize the arg structure */
1523          cmMemset((U8 *)&arg, 0, sizeof(CmTmrArg));
1524
1525          arg.tqCp = &rgCb[inst].tmrTqCp;
1526          arg.tq = rgCb[inst].tmrTq;
1527          arg.timers = rgCb[inst].tmrBlk;
1528          arg.cb = cb;
1529          arg.max = RG_MAX_TIMER;
1530          arg.evnt = NOTUSED;
1531          arg.wait = NOTUSED;
1532
1533          arg.tNum = i;   
1534          cmRmvCbTq(&arg);
1535          ret = ROK;
1536          break;
1537       }
1538
1539    }
1540
1541
1542    RETVALUE(ret);
1543 }
1544
1545 \f
1546 /**
1547  * @brief Timer Expiry handler. 
1548  *
1549  * @details
1550  *
1551  *     Function : rgLMMTmrExpiry
1552  *     
1553  *     This is a callback function used as an input parameter to cmPrcTmr()
1554  *     to check expiry of any timer. In this function, the only concern is
1555  *     about tmrEvnt=Bind timer.
1556  *     
1557  *  @param[in]  PTR   cb,  Entry for which Timer expired
1558  *  @param[in]  S16   tmrEvnt, the Timer Event    
1559  *  @return  S16
1560  *      -# ROK
1561  **/
1562 #ifdef ANSI
1563 PUBLIC S16 rgLMMTmrExpiry
1564 (
1565 PTR cb,               /* Pointer to timer control block */
1566 S16 tmrEvnt           /* Timer Event */
1567 )
1568 #else
1569 PUBLIC S16 rgLMMTmrExpiry(cb,tmrEvnt)
1570 PTR cb;               /* Pointer to timer control block */
1571 S16 tmrEvnt;          /* Timer Event */
1572 #endif
1573 {
1574    S16        ret = ROK;
1575    RgLowSapCb *tfuSap = (RgLowSapCb *)cb;
1576    Inst          inst = tfuSap->sapCfg.sapPst.srcInst - RG_INST_START;
1577
1578    TRC2(rgLMMTmrExpiry)
1579
1580    
1581    switch(tmrEvnt)
1582    {
1583       case RG_BNDREQ_TMR:
1584          tfuSap->numBndRetries++;
1585          if(tfuSap->numBndRetries > RG_MAX_BNDRETRY)
1586          {
1587             rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE, LCM_EVENT_BND_FAIL,
1588                         LCM_CAUSE_TMR_EXPIRED, NULLP);
1589          }
1590          else
1591          {
1592             /* Restart the bind timer */
1593             if (tfuSap->sapCfg.bndTmr.enb == TRUE)
1594             {
1595                ret = rgLMMStartTmr(inst,RG_BNDREQ_TMR, tfuSap->sapCfg.bndTmr.val,
1596                cb);
1597             }
1598
1599             /* Send bind request */
1600             rgLIMTfuBndReq(inst,rgCb[inst].tfuSap.sapCfg.suId,
1601                                 rgCb[inst].tfuSap.sapCfg.spId);
1602          }
1603          break;
1604       default:
1605          RLOG1(L_ERROR, "Invalid tmrEvnt=%d",tmrEvnt);
1606          ret = RFAILED;
1607          break;
1608    }
1609    RETVALUE(ret);
1610 }
1611
1612
1613 \f
1614 /**
1615  * @brief Layer Manager Unsolicited Status Indication generation. 
1616  *
1617  * @details
1618  *
1619  *     Function : rgLMMStaInd 
1620  *     
1621  *     This API is used by the other modules of MAC to send a unsolicited
1622  *     status indication to the Layer Manager.
1623  *     
1624  *  @param[in]  Inst        inst
1625  *  @param[in]  U16 category, the Alarm category
1626  *  @param[in]  U16 event, the Alarm event
1627  *  @param[in]  U16 cause, the cause of the Alarm
1628  *  @param[in]  RgUstaDgn *dgn, Alarm Diagonostics
1629  *  @return  S16
1630  *      -# ROK
1631  **/
1632 #ifdef ANSI
1633 PUBLIC S16 rgLMMStaInd
1634 (
1635 Inst inst,
1636 U16 category,
1637 U16 event,
1638 U16 cause,
1639 RgUstaDgn *dgn
1640 )
1641 #else
1642 PUBLIC S16 rgLMMStaInd(inst,category, event, cause, dgn) 
1643 Inst inst;
1644 U16 category;
1645 U16 event;
1646 U16 cause;
1647 RgUstaDgn *dgn;
1648 #endif
1649 {
1650    RgMngmt    usta;
1651
1652    TRC2(rgLMMStaInd)
1653
1654    if(rgCb[inst].rgInit.usta == FALSE)
1655    {
1656       RETVALUE(ROK);
1657    }
1658
1659    cmMemset((U8 *)&usta, 0, sizeof(RgMngmt));
1660
1661    SGetDateTime(&usta.t.usta.cmAlarm.dt);
1662    usta.t.usta.cmAlarm.category = category;
1663    usta.t.usta.cmAlarm.event = event;
1664    usta.t.usta.cmAlarm.cause = cause;
1665    if (dgn != NULLP)
1666    {
1667       cmMemcpy((U8 *)&usta.t.usta.dgn, (U8 *)dgn, sizeof(RgUstaDgn));
1668    }
1669
1670    rgCb[inst].rgInit.lmPst.selector = rgCb[inst].genCfg.ustaResp.response.selector;
1671    rgCb[inst].rgInit.lmPst.prior = rgCb[inst].genCfg.ustaResp.response.prior;
1672    rgCb[inst].rgInit.lmPst.route = rgCb[inst].genCfg.ustaResp.response.route;
1673    rgCb[inst].rgInit.lmPst.region = rgCb[inst].genCfg.ustaResp.response.mem.region;
1674    rgCb[inst].rgInit.lmPst.pool = rgCb[inst].genCfg.ustaResp.response.mem.pool;
1675    usta.hdr.transId = rgCb[inst].genCfg.ustaResp.transId;
1676
1677    RETVALUE(RgMiLrgStaInd(&rgCb[inst].rgInit.lmPst, &usta));
1678 }
1679
1680 \f
1681 /**
1682  * @brief Layer Manager Trace Indication generation. 
1683  *
1684  * @details
1685  *
1686  *     Function : rgLMMTrcInd 
1687  *     
1688  *     This API is used by the other modules of MAC to send a 
1689  *     Trace indication to the Layer Manager.
1690  *     
1691  *  @param[in]  Inst        inst
1692  *  @param[in]   Buffer *srcMbuf, the Message Buffer .
1693  *  @param[in]   U8 event, the trace event.
1694  *  @return Void 
1695  **/
1696 #ifdef ANSI
1697 PUBLIC Void rgLMMTrcInd
1698 (
1699 Inst   inst,
1700 Buffer *srcMbuf,    /* Message Buffer */
1701 U8 event            /* event */
1702 )
1703 #else
1704 PUBLIC Void rgLMMTrcInd(inst,srcMbuf,event)
1705 Inst   inst;
1706 Buffer *srcMbuf;    /* Message Buffer */
1707 U8 event;           /* event */
1708 #endif
1709 {
1710    Buffer   *dstMbuf = NULLP;   
1711    MsgLen   bufLen  = 0;
1712    Data     *tempBuf;
1713    MsgLen   tempCnt;
1714    RgMngmt  trc;
1715    Pst      pst;
1716
1717    TRC2(rgLMMTrcInd)
1718
1719
1720    if ((rgCb[inst].trcLen == LRG_NO_TRACE) || (srcMbuf == NULLP))
1721    {
1722       RLOG0(L_ERROR, "Trace Disabled.");
1723       RETVOID;
1724    }
1725    
1726    cmMemset((U8 *)&trc, 0, sizeof(RgMngmt));
1727
1728    pst = rgCb[inst].rgInit.lmPst;
1729    pst.selector = rgCb[inst].genCfg.trcResp.response.selector;
1730    pst.prior = rgCb[inst].genCfg.trcResp.response.prior;
1731    pst.route = rgCb[inst].genCfg.trcResp.response.route;
1732    pst.region = rgCb[inst].genCfg.trcResp.response.mem.region;
1733    pst.pool = rgCb[inst].genCfg.trcResp.response.mem.pool;
1734
1735    trc.hdr.transId = rgCb[inst].genCfg.trcResp.transId;
1736
1737    SGetDateTime(&trc.t.trc.dt);
1738       
1739    /* Check if the whole buffer is to be sent in Trace indication */
1740    if(rgCb[inst].trcLen == LRG_FULL_TRACE)
1741    {
1742       if (SCpyMsgMsg(srcMbuf, pst.region, pst.pool, &dstMbuf)
1743          != ROK)
1744       {
1745          RLOG0(L_ERROR, "SCpyMsgMsg Failed.");
1746          RETVOID;
1747       }
1748       trc.cfm.status = LCM_PRIM_OK;
1749       trc.cfm.reason = LCM_REASON_NOT_APPL;
1750       trc.t.trc.evnt = event;
1751          
1752       /* Send Trace Indication to Layer manager */
1753       RgMiLrgTrcInd(&pst, &trc, dstMbuf);
1754    }
1755    /* check if only a specified number of bytes are to be sent */
1756    else if(rgCb[inst].trcLen > 0)
1757    {
1758       /* Get the length of the recvd message buffer */
1759       if (SFndLenMsg(srcMbuf, &bufLen) != ROK)
1760       {
1761          RLOG0(L_ERROR, "SFndLenMsg Failed.");
1762          RETVOID;
1763       }
1764       /* Check if the recvd buffer size is less than request trace len */
1765       if(bufLen < rgCb[inst].trcLen)
1766       {
1767          /* Copy the whole of the recvd buffer in trace indication */
1768       
1769          if (SCpyMsgMsg(srcMbuf, pst.region, pst.pool, &dstMbuf)
1770             != ROK)
1771          {
1772             RLOG0(L_ERROR, "SCpyMsgMsg Failed.");
1773             RETVOID;
1774          }
1775          
1776          trc.cfm.status = LCM_PRIM_OK;
1777          trc.cfm.reason = LCM_REASON_NOT_APPL;
1778          trc.t.trc.evnt = event;
1779
1780          /* Send Trace Indication to Layer manager */
1781          RgMiLrgTrcInd(&pst, &trc, dstMbuf);
1782       }
1783       /* if the recvd buffer size is greater than request trace len */
1784       if(bufLen >= rgCb[inst].trcLen)
1785       {
1786          /* Get a temporary buffer to store the msg */
1787          if (rgAllocSBuf(inst,&tempBuf, rgCb[inst].trcLen) != ROK)
1788          {
1789             RLOG0(L_ERROR, "rgAllocSBuf Failed.");
1790             RETVOID;
1791          }
1792          
1793          /* Copy trcLen nos of bytes from the recvd message */
1794          if (SCpyMsgFix(srcMbuf,0,rgCb[inst].trcLen,tempBuf,&tempCnt) != ROK)   
1795          {
1796             RLOG0(L_ERROR, "SCpyMsgFix Failed.");
1797             RETVOID;
1798          }
1799
1800          if (SGetMsg(pst.region, pst.pool, &dstMbuf) != ROK)
1801          {
1802             RLOG0(L_ERROR, "dstMbuf Allocation Failed");
1803             RETVOID;
1804          }
1805          /* Copy the tempBuf data to dst mBuf */
1806          if (SCpyFixMsg(tempBuf,dstMbuf,0,rgCb[inst].trcLen,&tempCnt) != ROK)
1807          {
1808             RLOG0(L_ERROR, "SCpyFixMsg Failed.");
1809             RETVOID;
1810          }
1811
1812          /*ccpu00117052 - MOD - Passing double pointer for proper NULLP 
1813                                assignment */
1814          /* Free the memory allocated for tempBuf */
1815          rgFreeSBuf(inst,&tempBuf, rgCb[inst].trcLen);
1816                
1817          trc.cfm.status = LCM_PRIM_OK;
1818          trc.cfm.reason = LCM_REASON_NOT_APPL;
1819          trc.t.trc.evnt = event;
1820       
1821          /* Send Trace Indication to Layer manager */
1822          RgMiLrgTrcInd(&pst, &trc, dstMbuf);
1823       }
1824    }
1825    RETVOID;
1826 }
1827
1828 \f
1829 /**
1830  * @brief Layer Manager Control Confirm generation handler
1831  *        for Bind Confirm reception at TFU interface.
1832  *        RgLiTfuBndCfm() forwards the confirmation to this 
1833  *        function. All SAP state related handling is restricted
1834  *        to LMM modules, hence the cfm forwarding.
1835  *
1836  * @details
1837  *
1838  *     Function : rgLMMBndCfm 
1839  *     
1840  *     This API is used by the LIM module of MAC to forward
1841  *     the Bind Confirm it receives over the TFU interface.
1842  *     
1843  *  @param[in]   Pst *pst, Post Structure
1844  *  @param[in]   SuId suId, Service user ID
1845  *  @param[in]   U8 status, Status
1846  *  @return  S16
1847  *      -# ROK
1848  **/
1849 #ifdef ANSI
1850 PUBLIC S16 rgLMMBndCfm
1851 (
1852 Pst *pst,               /* Post Structure */
1853 SuId suId,              /* Service user ID */
1854 U8 status               /* Status */
1855 )
1856 #else
1857 PUBLIC S16 rgLMMBndCfm(pst,suId,status)
1858 Pst *pst;               /* Post Structure */
1859 SuId suId;              /* Service user ID */
1860 U8 status;              /* Status */
1861 #endif
1862 {
1863    Inst      inst = pst->dstInst - RG_INST_START;
1864    S16       ret = ROK;
1865    RgMngmt   cntrlCfm;
1866    Pst       cfmPst;
1867
1868    TRC3(rgLMMBndCfm)
1869
1870    UNUSED(pst);
1871
1872    /* Check if the suId is valid */
1873    if(rgCb[inst].tfuSap.sapCfg.suId != suId)
1874    {
1875       RLOG0(L_ERROR, "Invalid SuId");
1876       RETVALUE(RFAILED);
1877    }
1878
1879    /* check the Sap State */
1880    switch(rgCb[inst].tfuSap.sapSta.sapState)
1881    {
1882       case LRG_WAIT_BNDCFM:
1883          break;
1884       case LRG_BND:
1885          /* SAP is already bound */
1886          RETVALUE(ROK);
1887       default:
1888          RETVALUE(RFAILED);
1889    }
1890
1891    cfmPst = rgCb[inst].rgInit.lmPst;
1892    cfmPst.selector = rgCb[inst].genCfg.bndCfmResp.response.selector;
1893    cfmPst.prior = rgCb[inst].genCfg.bndCfmResp.response.prior;
1894    cfmPst.route = rgCb[inst].genCfg.bndCfmResp.response.route;
1895    cfmPst.region = rgCb[inst].genCfg.bndCfmResp.response.mem.region;
1896    cfmPst.pool = rgCb[inst].genCfg.bndCfmResp.response.mem.pool;
1897    
1898    cmMemset((U8 *)&cntrlCfm, 0, sizeof(RgMngmt));
1899
1900    switch(status)
1901    {
1902       case CM_BND_OK: /* status is OK */
1903          /* Change SAP state to Bound */
1904          rgCb[inst].tfuSap.sapSta.sapState = LRG_BND;
1905          if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1906          {
1907             ret = rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1908          }
1909          /* Send Control Confirm with status as OK to Layer Manager */
1910          cntrlCfm.cfm.status = LCM_PRIM_OK;
1911          cntrlCfm.cfm.reason = LCM_REASON_NOT_APPL;
1912          break;
1913
1914       default:
1915          /* Change SAP state to UnBound */
1916          rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
1917          if (rgCb[inst].tfuSap.sapCfg.bndTmr.enb == TRUE)
1918          {
1919             ret = rgLMMStopTmr(inst,RG_BNDREQ_TMR, (PTR)&rgCb[inst].tfuSap);
1920          }
1921          /* Send Control Confirm with status as NOK to Layer Manager */
1922          cntrlCfm.cfm.status = LCM_PRIM_NOK;
1923          cntrlCfm.cfm.reason = LCM_REASON_NEG_CFM;
1924          break;
1925    }
1926    rgCb[inst].tfuSap.numBndRetries = 0;
1927    cntrlCfm.hdr.elmId.elmnt = STTFUSAP;
1928    cntrlCfm.hdr.transId = rgCb[inst].genCfg.bndCfmResp.transId;
1929
1930    ret = RgMiLrgCntrlCfm(&cfmPst, &cntrlCfm);
1931
1932    RETVALUE(ret);
1933 }
1934
1935 \f
1936 /**
1937  * @brief LTE MAC timer call back function registered with SSI. 
1938  *
1939  * @details
1940  *
1941  *     Function :  rgActvTmr
1942  *     
1943  *     This function is invoked by SSI for every timer activation
1944  *     period expiry.
1945  *     
1946  *  @return  S16
1947  *      -# ROK
1948  **/
1949 #ifdef ANSI
1950 PUBLIC S16 rgActvTmr
1951 (
1952  Ent     ent,
1953  Inst    inst
1954 )
1955 #else
1956 PUBLIC S16 rgActvTmr(ent, inst)
1957 Ent     ent;
1958 Inst    inst;
1959 #endif
1960 {
1961    Inst macInst = (inst  - RG_INST_START);
1962    TRC3(rgActvTmr)
1963
1964    /* Check if any MAC timer has expired */ 
1965    cmPrcTmr(&rgCb[macInst].tmrTqCp, rgCb[macInst].tmrTq, (PFV) rgLMMTmrExpiry);
1966  
1967    RETVALUE(ROK);
1968  
1969 } /* end of rgActvTmr */
1970
1971 /**
1972  * @brief Layer Manager  Configuration request handler for Scheduler
1973  *
1974  * @details
1975  *
1976  *     Function : MacSchGenCfgReq
1977  *     
1978  *     This function receives general configurations for Scheduler
1979  *     from DU APP and forwards to Scheduler.
1980  *     
1981  *  @param[in]  Pst *pst, the post structure     
1982  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
1983  *  @return  S16
1984  *      -# ROK
1985  **/
1986 #ifdef ANSI
1987 PUBLIC S16 MacSchGenCfgReq
1988 (
1989 Pst      *pst,    /* post structure  */
1990 RgMngmt  *cfg     /* config structure  */
1991 )
1992 #else
1993 PUBLIC S16 MacSchGenCfgReq(pst, cfg)
1994 Pst      *pst;    /* post structure  */
1995 RgMngmt  *cfg;    /* config structure  */
1996 #endif    
1997 {
1998    printf("\nReceived Scheduler gen config at MAC");
1999    pst->dstInst = DEFAULT_CELLS + 1;
2000    HandleSchGenCfgReq(pst, cfg);
2001
2002    return ROK;
2003 }
2004
2005 /**
2006  * @brief Layer Manager Configuration response from Scheduler
2007  *
2008  * @details
2009  *
2010  *     Function : SchSendCfgCfm
2011  *     
2012  *     This function sends general configurations response from
2013  *     Scheduler to DU APP.
2014  *     
2015  *  @param[in]  Pst *pst, the post structure     
2016  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
2017  *  @return  S16
2018  *      -# ROK
2019  **/
2020 #ifdef ANSI
2021 PUBLIC S16 SchSendCfgCfm 
2022 (
2023 Pst      *pst,    /* post structure  */
2024 RgMngmt  *cfm     /* config confirm structure  */
2025 )
2026 #else
2027 PUBLIC S16 SchSendCfgCfm(pst, cfm)
2028 Pst      *pst;    /* post structure  */
2029 RgMngmt  *cfm;    /* config confirm structure  */
2030 #endif    
2031 {
2032    printf("\nSending Scheduler config confirm to DU APP");
2033         pst->dstEnt = ENTDUAPP;
2034         pst->dstInst = 0;
2035         pst->srcInst = 0;
2036         pst->selector = MAC_SCH_LC_SELECTOR; 
2037    RgMiLrgSchCfgCfm(pst, cfm);
2038    
2039    RETVALUE(ROK);
2040 }
2041
2042 \f
2043 /***********************************************************
2044  *
2045  *     Func : macCellCfgFillCfmPst 
2046  *        
2047  *
2048  *     Desc : Fills the Confirmation Post Structure cfmPst 
2049  *
2050  *     Ret  : Void
2051  *
2052  *     Notes: 
2053  *
2054  *     File : rg_lmm.c 
2055  *
2056  **********************************************************/
2057 Void macCellCfgFillCfmPst
2058 (
2059 Pst           *reqPst,
2060 Pst           *cfmPst
2061 )
2062 {
2063    Inst inst;
2064    inst = reqPst->dstInst;
2065
2066    cfmPst->srcEnt    = rgCb[inst].rgInit.ent;
2067    cfmPst->srcInst   = rgCb[inst].rgInit.inst;
2068    cfmPst->srcProcId = rgCb[inst].rgInit.procId;
2069
2070    cfmPst->dstEnt    = ENTDUAPP;
2071    cfmPst->dstInst   = 0;
2072    cfmPst->dstProcId = cfmPst->srcProcId;
2073
2074    cfmPst->selector  = LRG_SEL_LC;
2075    cfmPst->prior     = reqPst->prior;
2076    cfmPst->route     = reqPst->route;
2077    cfmPst->region    = reqPst->region;
2078    cfmPst->pool      = reqPst->pool;
2079    cfmPst->event     = EVENT_MAC_CELL_CONFIG_CFM;
2080
2081    RETVOID;
2082 }
2083
2084 /**
2085  * @brief Layer Manager Configuration request handler. 
2086  *
2087  * @details
2088  *
2089  *     Function : MacHdlCellCfgReq 
2090  *     
2091  *     This function handles the gNB and cell configuration
2092  *     request received from DU APP.
2093  *     This API unapcks and forwards the config towards SCH
2094  *     
2095  *  @param[in]  Pst           *pst
2096  *  @param[in]  MacCellCfg    *macCellCfg 
2097  *  @return  S16
2098  *      -# ROK
2099  **/
2100 int MacHdlCellCfgReq
2101 (
2102  Pst           *pst,
2103  MacCellCfg    *macCellCfg
2104 )
2105 {
2106    Pst cfmPst;
2107    int ret = ROK;
2108    RgCellCb      *cellCb;
2109         MacCellCb     *macCellCb;
2110    Inst inst = pst->dstInst;
2111
2112    cmMemset((U8 *)&cfmPst, 0, sizeof(Pst));
2113    MAC_ALLOC(cellCb,sizeof(RgCellCb));
2114
2115    if(cellCb == NULLP)
2116    {
2117       DU_LOG("\nMAC : cellCb is NULL at handling of macCellCfg\n");
2118       return RFAILED;
2119    }
2120
2121    memcpy(&cellCb->macCellCfg,macCellCfg,sizeof(MacCellCfg));
2122    rgCb[inst].cell = cellCb;
2123
2124    MAC_ALLOC(macCellCb,sizeof(MacCellCb));
2125         if(macCellCb == NULLP)
2126         {
2127       DU_LOG("\nMAC : macCellCb is NULL at handling of macCellCfg\n");
2128       return RFAILED;
2129    }
2130    macCb.macCell = macCellCb;
2131    macCb.macCell->cellId = macCellCfg->cellId;
2132    /* Send cell cfg to scheduler */
2133    ret = MacSchCellCfgReq(pst, macCellCfg);
2134         if(ret != ROK)
2135         {
2136                 MacCellCfgCfm macCellCfgCfm;
2137                 macCellCfgCfm.rsp = RSP_NOK;
2138                 macCellCfgCfm.transId = macCellCfg->transId;
2139                 macCellCfgFillCfmPst(pst,&cfmPst);
2140                 ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
2141         }
2142    return ret;
2143 } /* end of MacHdlCellCfgReq */
2144
2145 /**
2146  * @brief Layer Manager Configuration request handler. 
2147  *
2148  * @details
2149  *
2150  *     Function : MacSchCellCfgReq 
2151  *     
2152  *     This function sends cell configuration to SCH
2153  *     
2154  *  @param[in]  Pst           *pst
2155  *  @param[in]  MacCellCfg    *macCellCfg 
2156  *  @return  S16
2157  *      -# ROK
2158  **/
2159 int MacSchCellCfgReq
2160 (
2161  Pst           *pst,
2162  MacCellCfg    *macCellCfg
2163 )
2164 {
2165    SchCellCfg schCellCfg;
2166         Pst        cfgPst;
2167         int ret;
2168
2169    cmMemset((U8 *)&cfgPst, 0, sizeof(Pst));
2170         schCellCfg.cellId = macCellCfg->cellId;
2171         schCellCfg.phyCellId = macCellCfg->phyCellId;
2172         schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
2173         schCellCfg.dupMode = macCellCfg->dupType;
2174
2175         /* fill ssb scheduler parameters */
2176         schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
2177         schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
2178         schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
2179         schCellCfg.ssbSchCfg.ssbPeriod = macCellCfg->ssbCfg.ssbPeriod;
2180         schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
2181         for(uint8_t idx=0; idx<SSB_MASK_SIZE; idx++)
2182         {
2183       schCellCfg.ssbSchCfg.nSSBMask[idx] = macCellCfg->ssbCfg.ssbMask[idx]; 
2184         }
2185
2186         /* fill SIB1 scheduler parameters */
2187         schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen; 
2188         schCellCfg.sib1SchCfg.sib1NewTxPeriod = macCellCfg->sib1Cfg.sib1NewTxPeriod; 
2189         schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod; 
2190         schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex; 
2191         schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex; 
2192         schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs; 
2193
2194    cfgPst.srcProcId = pst->dstProcId;
2195         cfgPst.dstProcId = pst->srcProcId;
2196         cfgPst.srcEnt    = ENTRG;
2197         cfgPst.srcInst   = 0;
2198         cfgPst.dstEnt    = ENTRG;
2199         cfgPst.dstInst   = 1;
2200         cfgPst.selector  = MAC_SCH_TC_SELECTOR;
2201         cfgPst.event     = EVENT_SCH_CELL_CFG;
2202
2203         ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
2204         return ret;
2205 } /* end of MacSchCellCfgReq */
2206
2207
2208 /*******************************************************************
2209  *
2210  * @brief Sends Cell config confirm to DU APP
2211  *
2212  * @details
2213  *
2214  *    Function : MacSendCellCfgCfm 
2215  *
2216  *    Functionality:
2217  *      Sends Cell config confirm to DU APP
2218  *
2219  * @params[in] Response status
2220  * @return void
2221  *
2222  * ****************************************************************/
2223 void MacSendCellCfgCfm(uint8_t response)
2224 {
2225    Pst pst;
2226    RgCellCb      *cellCb;
2227    MacCellCfgCfm macCellCfgCfm;
2228  
2229    cmMemset((U8 *)&pst, 0, sizeof(Pst));
2230    cellCb = rgCb[macCb.macInst].cell;
2231  
2232    macCellCfgCfm.transId = cellCb->macCellCfg.transId;
2233    macCellCfgCfm.rsp = response;
2234
2235    memcpy((void *)&pst, (void *)&rgCb[macCb.macInst].rgInit.lmPst, sizeof(Pst));
2236    pst.event = EVENT_MAC_CELL_CONFIG_CFM;
2237    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
2238 }
2239
2240
2241 /**
2242  * @brief Layer Manager Configuration response handler. 
2243  *
2244  * @details
2245  *
2246  *     Function : MacProcSchCellCfgCfm
2247  *     
2248  *     This function processes cell configuration to SCH
2249  *     
2250  *  @param[in]  Pst           *pst
2251  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
2252  *  @return  int
2253  *      -# ROK
2254  **/
2255 int MacProcSchCellCfgCfm 
2256 (
2257  Pst           *pst,
2258  SchCellCfgCfm *schCellCfgCfm
2259 )
2260 {
2261         if(schCellCfgCfm->rsp == RSP_OK)
2262         {
2263       sendToLowerMac(PARAM_REQUEST, 0, (void *)NULL);
2264         }
2265         else
2266         {
2267       MacSendCellCfgCfm(RSP_NOK);
2268         }
2269    return ROK;  
2270 }
2271
2272 /**********************************************************************
2273  
2274          End of file
2275 **********************************************************************/