Initial commit
[o-du/l2.git] / src / 5gnrmac / rg_prg.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 packing/unpacking of MAC to MAC interface
26                primitives.
27   
28      File:     rg_prg.c 
29   
30 **********************************************************************/
31 /* header include files -- defines (.h) */
32 #include "envopt.h"        /* environment options */
33 #include "envdep.h"        /* environment dependent */
34 #include "envind.h"        /* environment independent */
35 #include "gen.h"           /* general layer */
36 #include "ssi.h"           /* system service interface */
37 #include "cm_hash.h"       /* common hash list */
38 #include "cm_mblk.h"       /* common memory link list library */
39 #include "cm_llist.h"      /* common linked list library */
40 #include "cm_err.h"        /* common error */
41 #include "cm_lte.h"        /* common LTE */
42 #include "lrg.h"
43 #include "crg.h"
44 #include "rgu.h"
45 #include "tfu.h"
46 #include "rg_sch_inf.h"
47 #include "rg_prg.h"
48 #include "rg_env.h"
49 #include "rg.h"
50 #include "rg_err.h"
51
52 /* header/extern include files (.x) */
53 #include "gen.x"           /* general layer typedefs */
54 #include "ssi.x"           /* system services typedefs */
55 #include "cm5.x"           /* common timers */
56 #include "cm_hash.x"       /* common hash list */
57 #include "cm_lib.x"        /* common library */
58 #include "cm_llist.x"      /* common linked list */
59 #include "cm_mblk.x"       /* memory management */
60 #include "cm_tkns.x"       /* common tokens */
61 #include "cm_lte.x"       /* common tokens */
62 #include "rgu.x"           /* RGU types */
63 #include "tfu.x"           /* RGU types */
64 #include "lrg.x"           /* layer management typedefs for MAC */
65 #include "crg.x"           /* layer management typedefs for MAC */
66 #include "rg_sch_inf.x"           /* layer management typedefs for MAC */
67 #include "rg_prg.x"           /* Prg(MAC-MAC)interface includes */
68 #include "rg.x"            /* typedefs for MAC */
69
70 #ifdef LTE_ADV
71 #ifdef LCPRG
72 /** 
73  * @brief Ue SCell Cfg Req from PMac to SMac.
74  * @details This primitive is used for light-weight loose coupling.
75  *
76  * @details
77  *
78  *     Function : cmPkPrgPMacSMacUeSCellCfgReq
79  *
80  *  @param[in]   Pst*  pst
81  *  @param[in]   RgPrgUeSCellCfgInfo   *ueSCellCfgInfo
82  *  @return   S16
83  *      -# ROK
84  **/
85 #ifdef ANSI
86 PUBLIC S16 cmPkPrgPMacSMacUeSCellCfgReq
87 (
88 Pst           *pst,
89 RgPrgUeSCellCfgInfo   *ueSCellCfgInfo
90 )
91 #else
92 PUBLIC S16 cmPkPrgPMacSMacUeSCellCfgReq(pst, ueSCellCfgInfo)
93 Pst            *pst;
94 RgPrgUeSCellCfgInfo    *ueSCellCfgInfo;
95 #endif
96 {
97    Buffer *mBuf = NULLP;
98
99    TRC2(cmPkPrgPMacSMacUeSCellCfgReq)
100
101    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
102    {
103       RETVALUE(RFAILED);
104    }
105    
106    if(SAddPstMsgMult((Data *)ueSCellCfgInfo, sizeof(RgPrgUeSCellCfgInfo),\
107             mBuf) != ROK)
108    {
109       RGPRG_FREE_MSG(mBuf);
110       RETVALUE(RFAILED);
111    }
112
113    pst->event = (Event) EVTPRGUESCELLCFGREQ;
114    RETVALUE(SPstTsk(pst,mBuf));
115 }
116
117 /** 
118  * @brief Ue SCell Cfg Req from PMac to SMac.
119  * @details This primitive is used for light-weight loose coupling.
120  *
121  * @details
122  *
123  *     Function : cmUnpkPrgPMacSMacUeSCellCfgReq
124  *
125  *  @param[in]   Pst*  pst
126  *  @param[in]   RgPrgUeSCellCfgInfo   *ueSCellCfgInfo
127  *  @return   S16
128  *      -# ROK
129  **/
130 #ifdef ANSI
131 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellCfgReq
132 (
133 RgPrgUeSCellCfgReq   func,
134 Pst                  *pst,
135 Buffer               *mBuf
136 )
137 #else
138 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellCfgReq(func, pst, mBuf)
139 RgPrgUeSCellCfgReq   func;
140 Pst                  *pst;
141 Buffer               *mBuf;
142 #endif
143 {
144    RgPrgUeSCellCfgInfo    ueSCellCfgInfo;
145    
146    TRC2(cmUnpkPrgPMacSMacUeSCellCfgReq)
147
148    if(SRemPreMsgMult((Data *)&ueSCellCfgInfo, sizeof(RgPrgUeSCellCfgInfo), mBuf) != ROK)
149    {
150       RGPRG_FREE_MSG(mBuf);
151       RETVALUE(RFAILED);
152    }
153
154    RGPRG_FREE_MSG(mBuf);
155    RETVALUE((*func)(pst, &ueSCellCfgInfo));
156 }
157
158 /** 
159  * @brief Config confirm for Ue SCell config Req.
160  * @details This primitive is used for light-weight loose coupling.
161  *
162  * @details
163  *
164  *     Function : cmPkPrgSMacPMacCfgCfm
165  *
166  *  @param[in]   Pst              *pst
167  *  @param[in]   RgPrgCfgCfmInfo  *cfgCfm
168  *  @return   S16
169  *      -# ROK
170  **/
171 #ifdef ANSI
172 PUBLIC S16 cmPkPrgSMacPMacCfgCfm
173 (
174 Pst               *pst,
175 RgPrgCfgCfmInfo   *cfgCfm
176 )
177 #else
178 PUBLIC S16 cmPkPrgSMacPMacCfgCfm(pst, cfgCfm)
179 Pst                *pst;
180 RgPrgCfgCfmInfo    *cfgCfm;
181 #endif
182 {
183    Buffer *mBuf = NULLP;
184
185    TRC2(cmPkPrgSMacPMacCfgCfm)
186
187    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
188    {
189       RETVALUE(RFAILED);
190    }
191    
192    if(SAddPstMsgMult((Data *)cfgCfm, sizeof(RgPrgCfgCfmInfo), mBuf) != ROK)
193    {
194       RGPRG_FREE_MSG(mBuf);
195       RETVALUE(RFAILED);
196    }
197    switch(cfgCfm->event)
198    {
199       case EVTPRGUESCELLLCHMODCFM : /*cfm for Lch recfg */ 
200       {
201          pst->event = (Event) EVTPRGUESCELLLCHMODCFM;
202       }
203       break;
204       case EVTPRGUESCELLCFGCFM : /*cfm for Adding Scell */ 
205       {
206          pst->event = (Event) EVTPRGUESCELLCFGCFM;
207       }
208       break;
209       case EVTPRGUESCELLLCHDELCFM : /* cfm for deleting Lch */
210       {
211          pst->event = (Event) EVTPRGUESCELLLCHDELCFM;
212       }
213       break;
214       case EVTPRGUESCELLLCHADDCFM: /* cfm for adding of LCh */
215       {
216          pst->event = (Event) EVTPRGUESCELLLCHADDCFM;
217       }
218       break;
219    }
220    RETVALUE(SPstTsk(pst,mBuf));
221 }
222
223 /** 
224  * @brief Config confirm for SCell addd Req.
225  * @details This primitive is used for light-weight loose coupling.
226  *
227  * @details
228  *
229  *     Function : cmUnpkPrgSMacPMacCfgCfm
230  *
231  *  @param[in]   CfgCfm          fun
232  *  @param[in]   Pst*            pst
233  *  @param[in]   RgPrgCfgCfmInfo *cfgCfm
234  *  @return   S16
235  *      -# ROK
236  **/
237 #ifdef ANSI
238 PUBLIC S16 cmUnpkPrgSMacPMacCfgCfm
239 (
240 RgSMacPMacCfgCfm    func,
241 Pst                 *pst,
242 Buffer              *mBuf
243 )
244 #else
245 PUBLIC S16 cmUnpkPrgSMacPMacCfgCfm(func, pst, mBuf)
246 RgSMacPMacCfgCfm    func;
247 Pst                 *pst;
248 Buffer              *mBuf;
249 #endif
250 {
251    RgPrgCfgCfmInfo   cfgCfm;
252    
253    TRC2(cmUnpkPrgSMacPMacCfgCfm)
254
255    if(SRemPreMsgMult((Data *)&cfgCfm, sizeof(RgPrgCfgCfmInfo), mBuf) != ROK)
256    {
257       RGPRG_FREE_MSG(mBuf);
258       RETVALUE(RFAILED);
259    }
260
261    RGPRG_FREE_MSG(mBuf);
262    RETVALUE((*func)(pst, &cfgCfm));
263 }
264
265 /** 
266  * @brief SCell Ue Delete Req/UeId change req from PMac to SMac.
267  * @details This primitive is used for light-weight loose coupling.
268  *
269  * @details
270  *
271  *     Function : cmPkPrgPMacSMacUeSCellDelReq
272  *
273  *  @param[in]   Pst                  *pst
274  *  @param[in]   RgPrgUeSCellDelInfo  *ueSCellDelInfo
275  *  @return   S16
276  *      -# ROK
277  **/
278 #ifdef ANSI
279 PUBLIC S16 cmPkPrgPMacSMacUeSCellDelReq
280 (
281 Pst                   *pst,
282 RgPrgUeSCellDelInfo   *ueSCellDelInfo
283 )
284 #else
285 PUBLIC S16 cmPkPrgPMacSMacUeSCellDelReq(pst, ueSCellDelInfo)
286 Pst                    *pst;
287 RgPrgUeSCellDelInfo    *ueSCellDelInfo;
288 #endif
289 {
290    Buffer *mBuf = NULLP;
291
292    TRC2(cmPkPrgPMacSMacUeSCellDelReq)
293
294    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
295    {
296       RETVALUE(RFAILED);
297    }
298    
299    if(SAddPstMsgMult((Data *)ueSCellDelInfo, sizeof(RgPrgUeSCellDelInfo), mBuf)\
300          != ROK)
301    {
302       RGPRG_FREE_MSG(mBuf);
303       RETVALUE(RFAILED);
304    }
305
306    pst->event = (Event) EVTPRGUESCELLDELREQ;
307    RETVALUE(SPstTsk(pst,mBuf));
308 }
309
310 /** 
311  * @brief Unpacking for SCell UE delete/Ue Id Change Req to SMAC.
312  * @details This primitive is used for light-weight loose coupling.
313  *
314  * @details
315  *
316  *     Function : cmUnpkPrgPMacSMacUeSCellDelReq
317  *
318  *  @param[in]   CfgCfm        fun
319  *  @param[in]   Pst*          pst
320  *  @param[in]   Buffer        *mBuf
321  *  @return   S16
322  *      -# ROK
323  **/
324 #ifdef ANSI
325 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellDelReq
326 (
327 RgUeSCellDelReq    func,
328 Pst                *pst,
329 Buffer             *mBuf
330 )
331 #else
332 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellDelReq(func, pst, mBuf)
333 RgUeSCellDelReq  func;
334 Pst              *pst;
335 Buffer           *mBuf;
336 #endif
337 {
338   RgPrgUeSCellDelInfo ueSCellDelInfo;
339    
340    TRC2(cmUnpkPrgPMacSMacUeSCellDelReq)
341
342    if(SRemPreMsgMult((Data *)&ueSCellDelInfo, sizeof(RgPrgUeSCellDelInfo),\
343             mBuf) != ROK)
344    {
345       RGPRG_FREE_MSG(mBuf);
346       RETVALUE(RFAILED);
347    }
348
349    RGPRG_FREE_MSG(mBuf);
350    RETVALUE((*func)(pst, &ueSCellDelInfo));
351 }
352
353 /** 
354  * @brief Ue Lch Addition  Req from PMac to SMac.
355  * @details This primitive is used for light-weight loose coupling.
356  *
357  * @details
358  *
359  *     Function : cmPkPrgPMacSMacUeSCellLchAddReq
360  *
361  *  @param[in]   Pst*                      pst
362  *  @param[in]   RgPrgUeSCellLchAddInfo   *lchCfgInfo
363  *  @return   S16
364  *      -# ROK
365  **/
366 #ifdef ANSI
367 PUBLIC S16 cmPkPrgPMacSMacUeSCellLchAddReq
368 (
369 Pst                      *pst,
370 RgPrgUeSCellLchAddInfo   *lchCfgInfo,
371 )
372 #else
373 PUBLIC S16 cmPkPrgPMacSMacUeSCellLchAddReq(pst, lchCfgInfo)
374 Pst                       *pst;
375 RgPrgUeSCellLchAddInfo    *lchCfgInfo;
376 #endif
377 {
378    Buffer *mBuf = NULLP;
379
380    TRC2(cmPkPrgPMacSMacUeSCellLchAddReq)
381
382    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
383    {
384       RETVALUE(RFAILED);
385    }
386    
387    if(SAddPstMsgMult((Data *)lchCfgInfo, sizeof(RgPrgUeSCellLchAddInfo),\
388             mBuf) != ROK)
389    {
390       RGPRG_FREE_MSG(mBuf);
391       RETVALUE(RFAILED);
392    }
393
394    pst->event = (Event) EVTPRGUESCELLLCHADDREQ;
395    RETVALUE(SPstTsk(pst,mBuf));
396 }
397
398 /** 
399  * @brief LCH Addition Req from PMac to SMac.
400  * @details This primitive is used for light-weight loose coupling.
401  *
402  * @details
403  *
404  *     Function : cmUnpkPrgPMacSMacUeSCellLchAddReq
405  *
406  *  @param[in]   Pst*                     pst
407  *  @param[in]   RgPrgUeSCellLchAddInfo   *lchCfgInfo
408  *  @param[in]Buffer                      *mBuf
409  *  @return   S16
410  *      -# ROK
411  **/
412 #ifdef ANSI
413 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellLchAddReq
414 (
415 RgPrgUeSCellLchAddInfo       func,
416 Pst                          *pst,
417 Buffer                       *mBuf
418 )
419 #else
420 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellLchAddReq(func, pst, mBuf)
421 RgPrgUeSCellLchAddInfo       func;
422 Pst                          *pst;
423 Buffer                       *mBuf;
424 #endif
425 {
426    RgPrgLchRecfgInfo    lchCfgInfo;
427    
428    TRC2(cmUnpkPrgPMacSMacUeSCellLchAddReq)
429
430    if(SRemPreMsgMult((Data *)&lchCfgInfo, sizeof(RgPrgUeSCellLchAddInfo), mBuf) != ROK)
431    {
432       RGPRG_FREE_MSG(mBuf);
433       RETVALUE(RFAILED);
434    }
435
436    RGPRG_FREE_MSG(mBuf);
437    RETVALUE((*func)(pst, &lchCfgInfo));
438 }
439
440 /** 
441  * @brief Ue SCell Delete Req from PMac to SMac.
442  * @details This primitive is used for light-weight loose coupling.
443  *
444  * @details
445  *
446  *     Function : cmPkPrgPMacSMacUeSCellLchDelReq
447  *
448  *  @param[in]   Pst                       *pst
449  *  @param[in]   RgPrgUeSCellLchDelInfo    *delLcCb
450  *  @return   S16
451  *      -# ROK
452  **/
453 #ifdef ANSI
454 PUBLIC S16 cmPkPrgPMacSMacUeSCellLchDelReq
455 (
456 Pst                       *pst,
457 RgPrgUeSCellLchDelInfo    *delLcCb
458 )
459 #else
460 PUBLIC S16 cmPkPrgPMacSMacUeSCellLchDelReq(pst, delLcCb)
461 Pst                       *pst;
462 RgPrgUeSCellLchDelInfo    *delLcCb;
463 #endif
464 {
465    Buffer *mBuf = NULLP;
466
467    TRC2(cmPkPrgPMacSMacUeSCellLchDelReq)
468
469    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
470    {
471       RETVALUE(RFAILED);
472    }
473    
474    if(SAddPstMsgMult((Data *)delLcCb, sizeof(RgPrgUeSCellLchDelInfo),\
475             mBuf) != ROK)
476    {
477       RGPRG_FREE_MSG(mBuf);
478       RETVALUE(RFAILED);
479    }
480
481    pst->event = (Event) EVTPRGUESCELLLCHDELREQ;
482    RETVALUE(SPstTsk(pst,mBuf));
483 }
484
485
486 /** 
487  * @brief Ue Lch reCfg Req from PMac to SMac.
488  * @details This primitive is used for light-weight loose coupling.
489  *
490  * @details
491  *
492  *     Function : cmPkPrgPMacSMacUeSCellLchModReq
493  *
494  *  @param[in]   Pst                      *pst
495  *  @param[in]   RgPrgUeSCellLchModInfo   *lchCfgInfo
496  *  @return   S16
497  *      -# ROK
498  **/
499 #ifdef ANSI
500 PUBLIC S16 cmPkPrgPMacSMacUeSCellLchModReq
501 (
502 Pst                      *pst,
503 RgPrgUeSCellLchModInfo   *lchCfgInfo
504 )
505 #else
506 PUBLIC S16 cmPkPrgPMacSMacUeSCellLchModReq(pst, lchCfgInfo)
507 Pst                       *pst;
508 RgPrgUeSCellLchModInfo    *lchCfgInfo;
509 #endif
510 {
511    Buffer *mBuf = NULLP;
512
513    TRC2(cmPkPrgPMacSMacUeSCellLchModReq)
514
515    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
516    {
517       RETVALUE(RFAILED);
518    }
519    
520    if(SAddPstMsgMult((Data *)lchCfgInfo, sizeof(RgPrgUeSCellLchModInfo),\
521             mBuf) != ROK)
522    {
523       RGPRG_FREE_MSG(mBuf);
524       RETVALUE(RFAILED);
525    }
526
527    pst->event = (Event) EVTPRGUESCELLLCHMODREQ;
528    RETVALUE(SPstTsk(pst,mBuf));
529 }
530
531
532 /** 
533  * @brief LCH Cfg Req from PMac to SMac.
534  * @details This primitive is used for light-weight loose coupling.
535  *
536  * @details
537  *
538  *     Function : cmUnpkPrgPMacSMacUeSCellLchModReq
539  *
540  *  @param[in]   Pst*                pst
541  *  @param[in]   RgPrgLchRecfgInfo   *lchCfgInfo
542  *  @param[in]   Buffer              *mBuf
543  *  @return   S16
544  *      -# ROK
545  **/
546 #ifdef ANSI
547 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellLchModReq
548 (
549 RgPrgUeScellModLchReq   func,
550 Pst                     *pst,
551 Buffer                  *mBuf
552 )
553 #else
554 PUBLIC S16 cmUnpkPrgPMacSMacAddLchCfgReq(func, pst, mBuf)
555 RgPrgUeScellModLchReq   func;
556 Pst                     *pst;
557 Buffer                  *mBuf;
558 #endif
559 {
560    RgPrgUeSCellLchModInfo   lchCfgInfo;
561    
562    TRC2(cmUnpkPrgPMacSMacAddLchCfgReq)
563
564    if(SRemPreMsgMult((Data *)&lchCfgInfo, sizeof(RgPrgUeSCellLchModInfo), mBuf) != ROK)
565    {
566       RGPRG_FREE_MSG(mBuf);
567       RETVALUE(RFAILED);
568    }
569
570    RGPRG_FREE_MSG(mBuf);
571    RETVALUE((*func)(pst, &lchCfgInfo));
572 }
573
574
575 /** 
576  * @brief LCH Del Req from PMac to SMac.
577  * @details This primitive is used for light-weight loose coupling.
578  *
579  * @details
580  *
581  *     Function : cmUnpkPrgPMacSMacUeSCellLchDelReq
582  *
583  *  @param[in]   Pst*                    pst
584  *  @param[in]   RgPrgUeScellDelLchReq   func;
585  *  @param[in]   Buffer                  *mBuf;
586  *  @return      S16
587  *      -# ROK
588  **/
589 #ifdef ANSI
590 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellLchDelReq
591 (
592 RgPrgUeScellDelLchReq   func,
593 Pst                     *pst,
594 Buffer                  *mBuf
595 )
596 #else
597 PUBLIC S16 cmUnpkPrgPMacSMacUeSCellLchDelReq(func, pst, mBuf)
598 RgPrgUeScellDelLchReq   func;
599 Pst                     *pst;
600 Buffer                  *mBuf;
601 #endif
602 {
603    RgPrgUeSCellLchDelInfo   lchCfgInfo;
604    
605    TRC2(cmUnpkPrgPMacSMacUeSCellLchDelReq)
606
607    if(SRemPreMsgMult((Data *)&lchCfgInfo, sizeof(RgPrgUeSCellLchDelInfo), mBuf) != ROK)
608    {
609       RGPRG_FREE_MSG(mBuf);
610       RETVALUE(RFAILED);
611    }
612
613    RGPRG_FREE_MSG(mBuf);
614    RETVALUE((*func)(pst, &lchCfgInfo));
615 }
616
617 #endif /*LCPRG*/ 
618 #endif /*LTE_ADV*/
619
620 /**********************************************************************
621  
622          End of file
623 **********************************************************************/