Release A code commit
[o-du/l2.git] / src / du_app / du_msg_hdl.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 /* This file contains message handling functionality for DU cell management */
20
21 #include "du_sctp.h"
22 #include "f1ap_msg_hdl.h"
23
24 U8 rlcDlCfg = 0;
25 U8 numRlcDlSaps = 0;
26 U8 rlcUlCfg = 0;
27 U8 numRlcMacSaps = 0;
28 U8 macCfg = 0;
29 U8 macCfgInst = 0;
30
31 extern S16 cmPkLkwCfgReq(Pst *pst, KwMngmt *cfg);
32 extern S16 cmPkLkwCntrlReq(Pst *pst, KwMngmt *cfg);
33 extern S16 cmPkLrgCfgReq(Pst *pst, RgMngmt *cfg);
34
35 /**************************************************************************
36  * @brief Function to fill configs required by RLC
37  *
38  * @details
39  *
40  *      Function : duBuildRlcCfg 
41  * 
42  *      Functionality:
43  *           Initiates general Configs towards RLC 
44  *     
45  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
46  * @return ROK     - success
47  *         RFAILED - failure
48  *
49  ***************************************************************************/
50 S16 duBuildRlcCfg(Inst inst)
51 {
52    KwMngmt   kwMngmt;
53    KwGenCfg  *genCfg = NULLP;
54    Pst pst;
55
56    DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
57    DU_SET_ZERO(&pst, sizeof(Pst));
58
59    genCfg   = &(kwMngmt.t.cfg.s.gen);
60
61    /*----------- Fill General Configuration Parameters ---------*/
62    genCfg->maxUe       = duCfgParam.maxUe;
63    genCfg->maxKwuSaps  = 2;
64    genCfg->maxUdxSaps  = 1; 
65    genCfg->rlcMode     = (inst == RLC_UL_INST) ?
66       LKW_RLC_MODE_UL : LKW_RLC_MODE_DL;
67    genCfg->timeRes     = 1; 
68    genCfg->maxRguSaps  = DEFAULT_CELLS;
69
70    /*----------- Fill lmPst
71     * Parameters ---------*/
72    genCfg->lmPst.dstProcId = DU_PROC;
73    genCfg->lmPst.srcProcId = DU_PROC;
74    genCfg->lmPst.dstEnt    = ENTDUAPP;
75    genCfg->lmPst.dstInst   = DU_INST;
76    genCfg->lmPst.srcEnt    = ENTKW;
77    genCfg->lmPst.srcInst   = inst;
78    genCfg->lmPst.prior     = PRIOR0;
79    genCfg->lmPst.route     = RTESPEC;
80    genCfg->lmPst.region    = (inst == RLC_UL_INST) ?
81       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
82    genCfg->lmPst.pool      = RLC_POOL;
83    genCfg->lmPst.selector  = DU_SELECTOR_LC;
84
85     /* Fill Header */
86    kwMngmt.hdr.msgType             = TCFG;
87    kwMngmt.hdr.msgLen              = 0;
88    kwMngmt.hdr.entId.ent           = ENTKW;
89    kwMngmt.hdr.entId.inst          = (Inst)0;
90    kwMngmt.hdr.elmId.elmnt         = STGEN;
91    kwMngmt.hdr.seqNmb              = 0;
92    kwMngmt.hdr.version             = 0;
93    kwMngmt.hdr.transId             = 0;
94    kwMngmt.hdr.response.prior      = PRIOR0;
95    kwMngmt.hdr.response.route      = RTESPEC;
96    kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
97       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
98    kwMngmt.hdr.response.mem.pool   = DU_POOL;
99    kwMngmt.hdr.response.selector   = DU_SELECTOR_LC;
100
101    /* Fill Pst */
102    pst.selector  = DU_SELECTOR_LC;
103    pst.srcEnt    = ENTDUAPP;
104    pst.dstEnt    = ENTKW;
105    pst.dstInst   = inst;
106    pst.dstProcId = DU_PROC;
107    pst.srcProcId = DU_PROC;
108    pst.region    = duCb.init.region;
109
110    printf("\nRLC Gen Cfg Req sent for inst %d", inst);
111
112    /* Send the request to RLC */
113    cmPkLkwCfgReq(&pst, &kwMngmt);
114
115    return ROK;
116 }
117
118 /**************************************************************************
119  * @brief Function to fill configs required by RLC
120  *
121  * @details
122  *
123  *      Function : duBuildRlcLsapCfg 
124  * 
125  *      Functionality:
126  *           Initiates general Configs towards RLC 
127  *     
128  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
129  * @return ROK     - success
130  *         RFAILED - failure
131  *
132  ***************************************************************************/
133 S16 duBuildRlcLsapCfg(Ent ent, Inst inst, U8 lsapInst)
134 {
135
136    KwMngmt    kwMngmt;
137    KwSapCfg   *lSap = NULLP;
138    Pst        pst;
139
140    DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
141    DU_SET_ZERO(&pst, sizeof(Pst));
142
143    /* Fill Header */
144    kwMngmt.hdr.msgType             = TCFG;
145    kwMngmt.hdr.entId.ent           = ENTKW;
146    kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
147       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
148
149    kwMngmt.hdr.response.mem.pool   = RLC_POOL;
150
151    /* Fill Pst */
152    pst.selector  = DU_SELECTOR_LC;
153    pst.srcEnt    = ENTDUAPP;
154    pst.dstEnt    = ENTKW;
155    pst.dstProcId = DU_PROC;
156    pst.dstInst   = inst;
157    pst.srcProcId = DU_PROC;
158    pst.region    = duCb.init.region;
159    lSap   = &(kwMngmt.t.cfg.s.sap);
160
161    lSap->mem.region = (inst == RLC_UL_INST) ?
162       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
163    lSap->mem.pool    = RLC_POOL;
164    lSap->mem.spare   = 0;
165    lSap->bndTmrIntvl = 10;
166    lSap->priority    = PRIOR0;
167    lSap->route       = RTESPEC;
168    if (ent == ENTRG)
169    {
170       lSap->procId      = DU_PROC;
171       lSap->ent         = ENTRG;
172       lSap->inst        = lsapInst;
173       lSap->sapId       = lsapInst;      /* SapId will be stored as suId in MAC */
174       lSap->selector    = (inst == RLC_UL_INST) ? DU_SELECTOR_LWLC : DU_SELECTOR_TC;
175       kwMngmt.hdr.elmId.elmnt  = STRGUSAP;
176       printf("\nRLC MAC Lower Sap Cfg Req sent for inst %d", inst);
177
178    }
179    else
180    {
181       lSap->procId    = DU_PROC;
182       lSap->ent       = ENTKW;
183       lSap->inst      = (inst == RLC_UL_INST) ?
184          RLC_DL_INST : RLC_UL_INST;
185       lSap->sapId       = 0;
186       lSap->selector = DU_SELECTOR_LC;
187       kwMngmt.hdr.elmId.elmnt  = STUDXSAP;
188       printf("\nRLC DL/UL Lower Sap Cfg Req sent for inst %d", inst);
189    }
190
191    cmPkLkwCfgReq(&pst, &kwMngmt);
192    return ROK;
193 }
194
195 /**************************************************************************
196  * @brief Function to fill configs required by RLC
197  *
198  * @details
199  *
200  *      Function : duBuildRlcUsapCfg 
201  * 
202  *      Functionality:
203  *           Initiates general Configs towards RLC 
204  *     
205  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
206  * @return ROK     - success
207  *         RFAILED - failure
208  *
209  ***************************************************************************/
210 S16 duBuildRlcUsapCfg(U8 elemId, Ent ent, Inst inst)
211 {
212    KwMngmt    kwMngmt;
213    KwSapCfg   *uSap = NULLP;
214    Pst        pst;
215
216    DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
217    DU_SET_ZERO(&pst, sizeof(Pst));
218
219    uSap   = &(kwMngmt.t.cfg.s.sap);
220
221    uSap->selector   = DU_SELECTOR_LC;
222    uSap->mem.region = (inst == RLC_UL_INST) ?
223       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
224    uSap->mem.pool = RLC_POOL;
225    uSap->mem.spare = 0;
226
227    uSap->procId = DU_PROC;
228    uSap->ent = ENTKW;
229    uSap->sapId = 0;
230
231    uSap->inst = (inst == RLC_UL_INST) ?
232       RLC_DL_INST : RLC_UL_INST;
233    uSap->bndTmrIntvl = 1000;
234    uSap->priority = PRIOR0;
235    uSap->route = RTESPEC;
236
237    /* Fill Header */
238    kwMngmt.hdr.msgType             = TCFG;
239    kwMngmt.hdr.entId.ent           = ENTKW;
240    kwMngmt.hdr.elmId.elmnt         = STUDXSAP;
241    kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
242       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
243
244    kwMngmt.hdr.response.mem.pool   = RLC_POOL;
245
246    /* Fill Pst */
247    pst.selector  = DU_SELECTOR_LC;
248    pst.srcEnt    = ENTDUAPP;
249    pst.dstEnt    = ENTKW;
250    pst.dstProcId = DU_PROC;
251    pst.dstInst = inst;
252    pst.srcProcId = DU_PROC;
253    pst.region = duCb.init.region;
254
255    printf("\nRLC Kwu Upper Sap Cfg Req sent for inst %d", inst);
256    cmPkLkwCfgReq(&pst, &kwMngmt);
257
258    return ROK;
259 }
260 /**************************************************************************
261  * @brief Function to invoke DU Layer Configs
262  *
263  * @details
264  *
265  *      Function : duSendRlcUlCfg 
266  * 
267  *      Functionality:
268  *           Initiates Configs towards layers of DU
269  *     
270  * @param[in]  void
271  * @return ROK     - success
272  *         RFAILED - failure
273  *
274  ***************************************************************************/
275 S16 duSendRlcUlCfg()
276 {
277    U8 cellIdx; 
278
279    duBuildRlcCfg((Inst)RLC_UL_INST);
280    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
281    {
282       duBuildRlcLsapCfg(ENTRG, (Inst)RLC_UL_INST, cellIdx);
283    }
284    duBuildRlcLsapCfg(ENTKW, (Inst)RLC_UL_INST, 0);
285    
286    return ROK;
287 }
288
289 /**************************************************************************
290  * @brief Function to invoke DU Layer Configs
291  *
292  * @details
293  *
294  *      Function : duSendRlcDlCfg 
295  * 
296  *      Functionality:
297  *           Initiates Configs towards layers of DU
298  *     
299  * @param[in]  void
300  * @return ROK     - success
301  *         RFAILED - failure
302  *
303  ***************************************************************************/
304 S16 duSendRlcDlCfg()
305 {
306    U8 cellIdx; 
307
308    duBuildRlcCfg((Inst)RLC_DL_INST);
309    duBuildRlcUsapCfg(STUDXSAP, ENTKW, (Inst)RLC_DL_INST);
310    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
311    {
312       duBuildRlcLsapCfg(ENTRG, (Inst)RLC_DL_INST, cellIdx);
313    }
314    
315    return ROK;
316 }
317 /**************************************************************************
318  * @brief Function to handle Config Confirm from RLC
319  *
320  * @details
321  *
322  *      Function : duHdlRlcCfgComplete 
323  * 
324  *      Functionality:
325  *           Handles Gen Config Confirm from RLC
326  *     
327  * @param[in]  Pst     *pst, Post structure of the primitive.     
328  * @param[in]  KwMngmt *cfm, Unpacked primitive info received from RLC
329  * @return ROK     - success
330  *         RFAILED - failure
331  *
332  ***************************************************************************/
333 S16 duHdlRlcCfgComplete(Pst *pst, KwMngmt *cfm)
334 {
335    S16 ret = ROK;
336    if (pst->srcInst == RLC_UL_INST)
337    {
338       ret = duProcRlcUlCfgComplete(pst, cfm);
339    }
340    else
341    {
342       ret = duProcRlcDlCfgComplete(pst, cfm);
343    }
344    return ret;
345 }
346
347 /**************************************************************************
348  * @brief Function to handle Control Config Confirm from RLC
349  *
350  * @details
351  *
352  *      Function : duHdlRlcCntrlCfgComplete 
353  * 
354  *      Functionality:
355  *           Handles Control Config Confirm from RLC
356  *     
357  * @param[in]  Pst     *pst, Post structure of the primitive.     
358  * @param[in]  KwMngmt *cfm, Unpacked primitive info received from RLC
359  * @return ROK     - success
360  *         RFAILED - failure
361  *
362  ***************************************************************************/
363 S16 duHdlRlcCntrlCfgComplete(Pst *pst, KwMngmt *cntrl)
364 {
365    S16 ret = ROK;
366
367    if (cntrl->cfm.status == LCM_PRIM_OK)
368    {
369       switch (cntrl->hdr.elmId.elmnt)
370       {
371          case  STRGUSAP:
372             {
373                if (pst->srcInst == RLC_DL_INST)
374                {
375                   printf("\nBIND OF RLC DL TO MAC (RGU) SAP SUCCESSFUL");
376                   macCfgInst++;
377                   if(macCfgInst < DEFAULT_CELLS)
378                   {
379                      macCfgInst = 0;
380                      duBindUnbindRlcToMacSap((Inst) RLC_DL_INST, ABND);
381                   }
382                   else
383                   {
384                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
385                   }
386                }
387                else
388                {
389                   printf("\nBIND OF RLC UL TO MAC (RGU) SAP SUCCESSFUL");
390                   macCfgInst++;
391                   if(macCfgInst < DEFAULT_CELLS)
392                   {
393                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
394                   }
395                   else
396                   {
397                      duSctpStartReq();
398                   }
399
400                   break;
401                }
402             }
403
404       }
405    }
406    return ret;
407 }
408 /**************************************************************************
409  * @brief Function to handle Config Confirm from RLC UL
410  *
411  * @details
412  *
413  *      Function : duHdlRlcUlCfgComplete 
414  * 
415  *      Functionality:
416  *           Handles Config Confirm from RLC UL
417  *     
418  * @param[in]  Pst     *pst, Post structure of the primitive.     
419  * @param[in]  KwMngmt *cfm, Unpacked primitive info received from RLC UL
420  * @return ROK     - success
421  *         RFAILED - failure
422  *
423  ***************************************************************************/
424 S16 duProcRlcUlCfgComplete(Pst *pst, KwMngmt *cfm)
425 {
426    S16 ret;
427
428    printf("\nRLC UL Cfg Status %d", cfm->cfm.status);
429    if (cfm->cfm.status == LCM_PRIM_OK)
430    {
431       switch(cfm->hdr.elmId.elmnt)
432       {
433          case STGEN:
434             {
435                rlcUlCfg |= RLC_GEN_CFG;
436                break;
437             }
438          case STRGUSAP:
439             {
440                numRlcMacSaps++;
441                if(numRlcMacSaps == DEFAULT_CELLS)
442                {
443                   rlcUlCfg |= RLC_MAC_SAP_CFG;
444                   numRlcMacSaps = 0;
445                }
446                break;
447             }
448          case STUDXSAP:
449             {
450                rlcUlCfg |= RLC_UDX_SAP_CFG;
451                break;
452
453             }
454          default:
455             break;
456       }
457       printf("\n RLC UL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
458       if(rlcUlCfg == DU_RLC_UL_CONFIGURED)
459       {
460           rlcUlCfg = 0;
461           numRlcMacSaps = 0;
462           //Start configuration of RLC DL
463           duSendRlcDlCfg();
464
465       }
466    }
467    else
468    {
469       printf("\nConfig confirm NOK from RLC UL");
470       ret = RFAILED;
471    }
472    return ret;
473 }
474
475 /**************************************************************************
476  * @brief Function to handle Config Confirm from RLC DL
477  *
478  * @details
479  *
480  *      Function : duHdlRlcDlCfgComplete 
481  * 
482  *      Functionality:
483  *           Handles Config Confirm from RLC DL
484  *     
485  * @param[in]  Pst     *pst, Post structure of the primitive.     
486  * @param[in]  KwMngmt *cfm, Unpacked primitive info received from RLC DL
487  * @return ROK     - success
488  *         RFAILED - failure
489  *
490  ***************************************************************************/
491 S16 duProcRlcDlCfgComplete(Pst *pst, KwMngmt *cfm)
492 {
493    printf("\nRLC DL Cfg Status %d", cfm->cfm.status);
494    if (cfm->cfm.status == LCM_PRIM_OK)
495    {
496       switch(cfm->hdr.elmId.elmnt)
497       {
498          case STGEN:
499             {
500                rlcDlCfg |= RLC_GEN_CFG;
501                break;
502             }
503          case STRGUSAP:
504             {
505                numRlcMacSaps++;
506                if(numRlcMacSaps == DEFAULT_CELLS)
507                {
508                   rlcDlCfg |= RLC_MAC_SAP_CFG;
509                   numRlcMacSaps = 0;
510                }
511                break;
512             }
513          case STUDXSAP:
514             {
515                rlcDlCfg |= RLC_UDX_SAP_CFG;
516                break;
517
518             }
519          default:
520             break;
521
522       }
523       printf("\n RLC DL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
524       if(rlcDlCfg == DU_RLC_DL_CONFIGURED)
525       {
526           rlcDlCfg = 0;
527           //Start configuration of MAC
528           duSendMacCfg();
529
530       }
531    }
532    else
533    {
534       printf("\nConfig confirm NOK from RLC DL");
535    }
536    return ROK;
537 }
538
539 /**************************************************************************
540  * @brief Function to send configs to MAC
541  *
542  * @details
543  *
544  *      Function : duSendMacCfg 
545  * 
546  *      Functionality:
547  *           Initiates Configs towards MAC layer
548  *     
549  * @param[in]  void
550  * @return ROK     - success
551  *         RFAILED - failure
552  *
553  ***************************************************************************/
554 S16 duSendMacCfg()
555 {
556    duBuildMacGenCfg();
557    duBuildMacUsapCfg(RLC_UL_INST);
558    duBuildMacUsapCfg(RLC_DL_INST);
559
560    return ROK;
561 }
562
563 /**************************************************************************
564  * @brief Function to fill gen config required by MAC
565  *
566  * @details
567  *
568  *      Function : duBuildMacGenCfg 
569  * 
570  *      Functionality:
571  *           Initiates general Configs towards MAC
572  *     
573  * @param[in] void
574  * @return ROK     - success
575  *         RFAILED - failure
576  *
577  ***************************************************************************/
578 S16 duBuildMacGenCfg()
579 {
580    RgMngmt       rgMngmt;
581    RgGenCfg      *genCfg=NULLP;
582    Pst           pst;
583
584    DU_SET_ZERO(&pst, sizeof(Pst));
585    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
586
587    genCfg   = &(rgMngmt.t.cfg.s.genCfg);
588    
589    /*----------- Fill General Configuration Parameters ---------*/
590    genCfg->mem.region = RG_MEM_REGION;
591    genCfg->mem.pool   = RG_POOL;
592    genCfg->tmrRes     = 10;
593    genCfg->numRguSaps = 2;
594
595    genCfg->lmPst.dstProcId = DU_PROC;
596    genCfg->lmPst.srcProcId = DU_PROC;
597    genCfg->lmPst.dstEnt    = ENTDUAPP;
598    genCfg->lmPst.dstInst   = 0;
599    genCfg->lmPst.srcEnt    = ENTRG;
600    genCfg->lmPst.srcInst   = macCfgInst;
601    genCfg->lmPst.prior     = PRIOR0;
602    genCfg->lmPst.route     = RTESPEC;
603    genCfg->lmPst.region    = RG_MEM_REGION;
604    genCfg->lmPst.pool      = RG_POOL;
605    genCfg->lmPst.selector  = DU_SELECTOR_LC;
606
607     /* Fill Header */
608    rgMngmt.hdr.msgType             = TCFG;
609    rgMngmt.hdr.msgLen              = 0;
610    rgMngmt.hdr.entId.ent           = ENTRG;
611    rgMngmt.hdr.entId.inst          = (Inst)0;
612    rgMngmt.hdr.elmId.elmnt         = STGEN;
613    rgMngmt.hdr.seqNmb              = 0;
614    rgMngmt.hdr.version             = 0;
615    rgMngmt.hdr.transId             = 0;
616
617    rgMngmt.hdr.response.prior      = PRIOR0;
618    rgMngmt.hdr.response.route      = RTESPEC;
619    rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
620    rgMngmt.hdr.response.mem.pool   = RG_POOL;
621    rgMngmt.hdr.response.selector   = DU_SELECTOR_LC;
622
623    /* Fill Pst */
624    pst.selector  = DU_SELECTOR_LC;
625    pst.srcEnt    = ENTDUAPP;
626    pst.dstEnt    = ENTRG;
627    pst.dstInst   = macCfgInst;
628    pst.dstProcId = DU_PROC;
629    pst.srcProcId = DU_PROC;
630    pst.region = duCb.init.region;
631
632    printf("\nMAC Gen Cfg Req sent");
633
634    /* Send the request to MAC */
635    cmPkLrgCfgReq(&pst, &rgMngmt);
636
637    return ROK;
638 }
639
640 /**************************************************************************
641  * @brief Function to fill USAP config required by MAC
642  *
643  * @details
644  *
645  *      Function : duBuildMacUsapCfg 
646  * 
647  *      Functionality:
648  *           Initiates USAP Configs towards MAC
649  *     
650  * @param[in] SpId  Specifies if RLC UL or RLC DL instance 
651  * @return ROK     - success
652  *         RFAILED - failure
653  *
654  ***************************************************************************/
655 S16 duBuildMacUsapCfg(SpId sapId)
656 {
657    RgMngmt     rgMngmt;
658    RgUpSapCfg  *uSap = NULLP;
659    Pst         pst;
660
661    DU_SET_ZERO(&pst, sizeof(Pst));
662    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
663
664    uSap   = &(rgMngmt.t.cfg.s.rguSap);
665
666    uSap->mem.region = RG_MEM_REGION;
667    uSap->mem.pool   = RG_POOL;
668    uSap->suId       = 0;
669    uSap->spId       = sapId;
670    uSap->procId     = DU_PROC;
671    uSap->ent        = ENTKW;
672    uSap->inst       = sapId;
673    uSap->prior      = PRIOR0;
674    uSap->route      = RTESPEC;
675    uSap->selector   = DU_SELECTOR_LC ;
676
677    /* fill header */
678    rgMngmt.hdr.msgType             = TCFG;
679    rgMngmt.hdr.entId.ent           = ENTRG;
680    rgMngmt.hdr.entId.inst          = (Inst)0;
681    rgMngmt.hdr.elmId.elmnt         = STRGUSAP;
682    rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
683    rgMngmt.hdr.response.mem.pool   = RG_POOL;
684    
685    /* fill pst */
686    pst.selector  = DU_SELECTOR_LC;
687    pst.srcEnt    = ENTDUAPP;
688    pst.dstEnt    = ENTRG;
689    pst.dstInst   = macCfgInst;
690    pst.dstProcId = DU_PROC;
691    pst.srcProcId = DU_PROC;
692    pst.region    = duCb.init.region;
693
694    printf("\nMAC Rgu USap Cfg Req sent");
695
696    /* Send the request to MAC */
697    cmPkLrgCfgReq(&pst, &rgMngmt);
698
699    return ROK;
700 }
701
702 /**************************************************************************
703  * @brief Function to handle Config Confirm from MAC
704  *
705  * @details
706  *
707  *      Function : duHdlMacCfgComplete 
708  * 
709  *      Functionality:
710  *           Handles Gen Config Confirm from MAC
711  *     
712  * @param[in]  Pst     *pst, Post structure of the primitive.     
713  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
714  * @return ROK     - success
715  *         RFAILED - failure
716  *
717  ***************************************************************************/
718 S16 duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm)
719 {
720    S16 ret = ROK;
721
722    if (cfm->cfm.status == LCM_PRIM_OK)
723    {
724       switch (cfm->hdr.elmId.elmnt)
725       {
726          case STGEN:
727             {
728                macCfg |= MAC_GEN_CFG;
729                break;
730             }
731          case STRGUSAP:
732             {
733                macCfg |= MAC_SAP_CFG;
734                numRlcMacSaps++;
735                break;
736             }
737          default:
738             break;
739       }
740       printf("\n MAC Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
741       if(macCfg == MAC_CONFIGURED && numRlcMacSaps == MAX_MAC_SAP)
742       {
743          macCfg = 0;
744          printf("\n Completed sending Configs");
745          macCfgInst = 0;
746          duBindUnbindRlcToMacSap(RLC_DL_INST, ABND);
747       }
748
749    }
750    else
751    {
752       printf("\nConfig confirm NOK from MAC");
753       ret = RFAILED;
754    }
755    return ret;
756 }
757
758 /**************************************************************************
759  * @brief Function to bind/unbind RLC to MAC SAP
760  *
761  * @details
762  *
763  *      Function : duBindUnbindRlcToMacSap 
764  * 
765  *      Functionality:
766  *           Initiates Bind/Unbind from RLC to MAC
767  *     
768  * @param[in] Inst   Specifies if RLC UL or RLC DL instance 
769  * @param[in] action Specifies if action is bind or unbind
770  * @return ROK     - success
771  *         RFAILED - failure
772  *
773  ***************************************************************************/
774 S16 duBindUnbindRlcToMacSap(U8 inst, U8 action)
775 {
776    KwCntrl  *cntrl = NULLP;
777    KwMngmt  kwMngmt;
778    Pst      pst;
779
780    TRC2(smBindKwToRguSap)
781
782    DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
783    DU_SET_ZERO(&pst, sizeof(Pst));
784
785    if (action == ABND)
786    {
787       printf("\nCntrl Req to RLC inst %d to bind MAC sap", inst);
788    }
789    else
790    {
791       printf("\nCntrl Req to RLC inst %d to unbind MAC sap", inst);
792    }
793    cntrl = &(kwMngmt.t.cntrl);
794
795    cntrl->action            =  action;
796    cntrl->subAction         =  DU_ZERO_VAL;
797    cntrl->s.sapCntrl.suId   =  macCfgInst;
798    cntrl->s.sapCntrl.spId   =  inst;
799
800    /* Fill header */
801    kwMngmt.hdr.msgType             = TCNTRL;
802    kwMngmt.hdr.entId.ent           = ENTKW;
803    kwMngmt.hdr.entId.inst          = inst;
804    kwMngmt.hdr.elmId.elmnt         = 186; /* ambiguous defines in lkw.h and lrg.h so direct hardcoded*/
805    kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
806       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
807    kwMngmt.hdr.response.mem.pool   = RLC_POOL;
808
809    /* Fill pst */
810    pst.selector  = DU_SELECTOR_LC;
811    pst.srcEnt    = ENTDUAPP;
812    pst.dstEnt    = ENTKW;
813    pst.dstProcId = DU_PROC;
814    pst.dstInst   = inst;
815    pst.srcProcId = DU_PROC;
816    pst.region    = duCb.init.region;
817
818    cmPkLkwCntrlReq(&pst, &kwMngmt);
819
820    return ROK;
821 }
822 /*******************************************************************
823  *
824  * @brief  Function to start SCTP
825  *
826  * @details
827  *
828  *    Function : duSctpStartReq
829  *
830  *    Functionality:
831  *       Function to start SCTP
832  *
833  * @params[in] 
834  * @return void
835  *
836  * ****************************************************************/
837 S16 duSctpStartReq()
838 {
839    Pst pst;
840    Buffer *mBuf;
841
842    cmMemset((U8 *)&(pst), 0, sizeof(Pst));
843    pst.srcEnt = (Ent)ENTDUAPP;
844    pst.srcInst = (Inst)DU_INST;
845    pst.srcProcId = DU_PROC;
846    pst.dstEnt = (Ent)ENTSCTP;
847    pst.dstInst = (Inst)SCTP_INST;
848    pst.dstProcId = pst.srcProcId;
849    pst.event = EVTSCTPSTRT;
850    pst.selector = DU_SELECTOR_LC;
851    pst.pool= DU_POOL;
852    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
853    {
854       printf("\nMemory allocation failed in duReadCfg");
855       return RFAILED;
856    }
857    SPstTsk(&pst, mBuf);
858
859    RETVALUE(ROK);
860 }
861
862 /*******************************************************************
863  *
864  * @brief Handles SCTP notifications
865  *
866  * @details
867  *
868  *    Function : duSctpNtfyHdl
869  *
870  *    Functionality:
871  *         Handles SCTP notification
872  *
873  * @params[in] Message Buffer
874  *             SCTP notification
875  *
876  * @return ROK     - success
877  *         RFAILED - failure
878  *
879  * ****************************************************************/
880
881 S16 duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
882 {
883    char *finalBuf;
884    int i,j;
885
886    switch(ntfy->header.nType)
887    {
888       case CM_INET_SCTP_ASSOC_CHANGE:
889          switch(ntfy->u.assocChange.state)
890          {
891             case CM_INET_SCTP_COMM_UP:
892                {
893                   printf("\nSCTP communication UP");
894                   duCb.sctpStatus = TRUE;
895                   //Setup F1-C
896                   if(!duCb.f1Status)
897                   {
898                      /* Build and send F1 Setup response */
899                           Buffer *f1SetupReq;
900                      MsgLen  copyCnt;
901
902                      BuildF1SetupReq();
903                      /* Reversing the encoded string */
904                      if(SGetSBuf(1, 1, (Data **)&finalBuf, (Size)encBufSize) != ROK)
905                      {
906                         printf("Memory allocation failed");
907                         RETVALUE(RFAILED);
908                      }
909                      for(i = 0, j = encBufSize-1; i<encBufSize; i++, j--)
910                      {
911                         finalBuf[j] = encBuf[i];
912                      }
913
914                      if(SGetMsg(1, 1, &f1SetupReq) == ROK)
915                      {
916                         if(SCpyFixMsg((Data *)finalBuf, f1SetupReq, 0, encBufSize, &copyCnt) == ROK)
917                         {
918                            printf("\nSending F1 setup request");
919                            SPrntMsg(f1SetupReq, 0,0);
920                            if(sctpOutMsgSend(f1SetupReq) != ROK)
921                            {
922                               printf("\nFailed Sending");
923                            }
924                         }
925                      }
926                   }
927                   else
928                   {
929                   }
930                   break;
931                }
932          }
933          break;
934    }
935    RETVALUE(ROK);
936 }
937
938 /**********************************************************************
939          End of file
940 **********************************************************************/