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