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