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