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