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