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