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