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