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