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