Merge "Cleanup of message sib1"
[o-du/l2.git] / src / cm / du_app_mac_inf.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 #include "envopt.h"        /* Environment options */
20 #include "envdep.h"        /* Environment dependent */
21 #include "envind.h"        /* Environment independent */
22 #include "gen.h"           /* General */
23 #include "ssi.h"           /* System services */
24 #include "ss_queue.h"
25 #include "ss_task.h"
26 #include "ss_msg.h"
27
28 #include "gen.x"           /* general */
29 #include "ssi.x"           /* system services */
30 #include "cm_tkns.x"       /* Common Token Definitions */
31 #include "cm_llist.x"      /* Common Link List Definitions */
32 #include "cm_lib.x"        /* Common Library Definitions */
33 #include "cm_hash.x"       /* Common Hash List Definitions */
34 #include "cm_lte.x"        /* Common LTE Defines */
35
36 #include "du_cfg.h"
37 #include "du_app_mac_inf.h"
38 #include "cm.h"
39
40 /**************************************************************************
41  * @brief Function to pack Loose Coupled 
42  *        MAC cell config parameters required by MAC
43  *
44  * @details
45  *
46  *      Function : packMacCellCfg
47  *
48  *      Functionality:
49  *           packs the macCellCfg parameters
50  *
51  * @param[in] Pst     *pst, Post structure of the primitive.
52  * @param[in] MacCellCfg  *macCellCfg, mac cell config parameters.
53  * @return ROK     - success
54  *         RFAILED - failure
55  *
56  ***************************************************************************/
57 int  packMacCellCfg(Pst *pst, MacCellCfg *macCellCfg)
58 {
59    if(pst->selector == DU_SELECTOR_LC)
60    {
61       /* we are now implemented only light wieght lossely coupled interface */
62       return RFAILED;
63    }
64    else if(pst->selector == DU_SELECTOR_LWLC)
65    {
66       Buffer *mBuf = NULLP;
67
68       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
69       {
70          return RFAILED;
71       }
72
73       /* pack the address of the structure */
74       CMCHKPK(cmPkPtr,(PTR)macCellCfg, mBuf);
75
76       DU_LOG("\nDU-APP : MAC CELL config sent");
77       return SPstTsk(pst,mBuf);
78    } 
79    return ROK;
80 }
81
82 /**************************************************************************
83  * @brief Function to pack Loose Coupled 
84  *        MAC cell config parameters required by MAC
85  *
86  * @details
87  *
88  *      Function : unpackDuMacCellCfg
89  *
90  *      Functionality:
91  *           packs the macCellCfg parameters
92  *
93  * @param[in] DuMacCellCfgReq func; function pointer
94  * @param[in] Pst     *pst, Post structure of the primitive.
95  * @param[in] Buffer *mBuf
96  * @return ROK     - success
97  *         RFAILED - failure
98  *
99  ***************************************************************************/
100 int  unpackDuMacCellCfg(
101    DuMacCellCfgReq func,
102    Pst *pst,
103    Buffer *mBuf)
104 {
105    U16 ret = ROK;
106    MacCellCfg *macCellCfg;
107
108    if(pst->selector == DU_SELECTOR_LWLC)
109    {
110       /* unpack the address of the structure */
111       CMCHKUNPK(cmUnpkPtr, (PTR *)&macCellCfg, mBuf);
112       ret = (*func)(pst, macCellCfg);
113    }
114    else
115    {
116       /* only LWLC is implemented now */
117       ret = ROK;
118    }
119  
120    return ret;
121 }
122
123 /**************************************************************************
124  * @brief Function to pack Loose Coupled 
125  *        MAC cell config confirm message
126  *
127  * @details
128  *
129  *      Function : packMacCellCfgCfm
130  *
131  *      Functionality:
132  *           packs the transaction ID  
133  *
134  * @param[in] Pst     *pst, Post structure of the primitive.
135  * @param[in] MacCellCfgCfm  *macCellCfgCfm, mac cell config confirm.
136  * @return ROK     - success
137  *         RFAILED - failure
138  *
139  ***************************************************************************/
140 int  packMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
141 {
142    if(pst->selector == DU_SELECTOR_LC)
143    {
144       Buffer *mBuf = NULLP;
145       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK) 
146       {
147          return RFAILED;
148       }
149
150       /* pack the transaction ID in CNF structure */
151                 CMCHKPK(SPkU8, macCellCfgCfm->rsp, mBuf);
152       CMCHKPK(SPkU16, macCellCfgCfm->transId, mBuf);
153
154       return SPstTsk(pst,mBuf);
155    }
156    else if(pst->selector == DU_SELECTOR_LWLC)
157    {
158       /* only LC is supported */
159       return RFAILED;
160    }
161    return ROK;
162 }
163
164 /**************************************************************************
165  * @brief Function to pack MAC cell config confirm message
166  *
167  * @details
168  *
169  *      Function : unpackMacCellCfgCfm
170  *
171  *      Functionality:
172  *           packs the transaction ID  
173  *
174  * @param[in] DuMacCellCfgCfm func; function pointer
175  * @param[in] Pst     *pst, Post structure of the primitive.
176  * @param[in] Buffer *mBuf
177  * @return ROK     - success
178  *         RFAILED - failure
179  *
180  ***************************************************************************/
181 int unpackMacCellCfgCfm(
182    DuMacCellCfgCfm func, 
183    Pst *pst,
184    Buffer *mBuf)
185 {
186    MacCellCfgCfm macCellCfgCfm;
187
188    if(pst->selector == DU_SELECTOR_LC)
189    {
190       /* unpack the transaction ID in CNF structure */
191       CMCHKUNPK(SUnpkU16, &(macCellCfgCfm.transId), mBuf);
192       CMCHKUNPK(SUnpkU8, &(macCellCfgCfm.rsp), mBuf);
193
194       return (*func)(pst, &macCellCfgCfm);
195    }
196    else
197    {
198       /* only loose coupling is suported */
199                 return ROK;
200    }
201 }
202
203 /*******************************************************************
204  *
205  * @brief Packs and Send Cell Start Request to MAC
206  *
207  * @details
208  *
209  *    Function : packMacCellStartReq
210  *
211  *    Functionality:
212  *      Packs and Sends Cell Start Request to MAC
213  *
214  * @params[in] Post structure pointer
215  *             MacCellStartInfo pointer
216  * @return ROK     - success
217  *         RFAILED - failure
218  *
219  * ****************************************************************/
220 uint16_t packMacCellStartReq(Pst *pst, MacCellStartInfo  *cellStartInfo)
221 {
222         Buffer *mBuf = NULLP;
223
224    if(pst->selector == DU_SELECTOR_LC)
225    {
226       /* Loose coupling not supported */
227       return RFAILED;
228    }
229    else if(pst->selector == DU_SELECTOR_LWLC)
230    {
231
232       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
233       {
234          DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
235          return RFAILED;
236       }
237
238       /* pack the address of the structure */
239       CMCHKPK(cmPkPtr,(PTR)cellStartInfo, mBuf);
240
241    }
242         return SPstTsk(pst,mBuf);
243 }
244
245 /*******************************************************************
246  *
247  * @brief Unpacks MAC Cell Start Request from DU APP
248  *
249  * @details
250  *
251  *    Function : unpackMaCellStartReq
252  *
253  *    Functionality:
254  *      Unpacks MAC Cell Start Request from DU APP
255  *
256  * @params[in] Function pointer of cell start request handler
257  *             Post structure pointer
258  *             Cell Start Request Info Pointer
259  * @return ROK     - success
260  *         RFAILED - failure
261  *
262  * ****************************************************************/
263 uint16_t unpackMacCellStartReq(DuMacCellStartReq func, Pst *pst, Buffer *mBuf)
264 {
265    MacCellStartInfo  *cellStartInfo;
266  
267    if(pst->selector == DU_SELECTOR_LWLC)
268    {
269       /* unpack the address of the structure */
270       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStartInfo, mBuf);
271       SPutMsg(mBuf); 
272       return (*func)(pst, cellStartInfo);
273    }
274    else
275    {
276       /* Nothing to do for loose coupling */
277       SPutMsg(mBuf);
278       return ROK;
279    }
280 }
281
282 /*******************************************************************
283  *
284  * @brief Packs and Send cell stop request to MAC
285  *
286  * @details
287  *
288  *    Function : packMacCellStopReq
289  *
290  *    Functionality:
291  *       Packs and Send cell stop request to MAC
292  *
293  * @params[in] Post structure pointer
294  *             Cell stop info structure 
295  * @return ROK     - success
296  *         RFAILED - failure
297  *
298  * ****************************************************************/
299 uint16_t packMacCellStopReq(Pst *pst, MacCellStopInfo  *cellStopInfo)
300 {
301    if(pst->selector == DU_SELECTOR_LC)
302    {
303       /* Loose coupling not supported */
304       return RFAILED;
305    }
306    else if(pst->selector == DU_SELECTOR_LWLC)
307    {
308       Buffer *mBuf = NULLP;
309  
310       if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
311       {
312          DU_LOG("\nDU APP : Memory allocation failed for cell stop req pack");
313          return RFAILED;
314       }
315  
316       /* pack the address of the structure */
317       CMCHKPK(cmPkPtr,(PTR)cellStopInfo, mBuf);
318
319       return SPstTsk(pst,mBuf);
320    }
321    return ROK;
322 }
323
324 /*******************************************************************
325  *
326  * @brief Unpacks cell stop request from DU APP 
327  *
328  * @details
329  *
330  *    Function : unpackMaCellStopReq 
331  *
332  *    Functionality:
333  *       Unpacks cell stop request from DU APP 
334  *
335  * @params[in] Handler function pointer
336  *             Post structure pointer
337  *             Message Buffer
338  * @return ROK     - success
339  *         RFAILED - failure
340  *
341  * ****************************************************************/
342 uint16_t unpackMacCellStopReq(DuMacCellStopReq func, Pst *pst, Buffer *mBuf)
343 {
344    MacCellStopInfo  *cellStopInfo;
345   
346    if(pst->selector == DU_SELECTOR_LWLC)
347    {
348       /* unpack the address of the structure */
349       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStopInfo, mBuf);
350       SPutMsg(mBuf);
351       return (*func)(pst, cellStopInfo);
352    }
353    else
354    {
355       /* Nothing to do for loose coupling */
356       SPutMsg(mBuf);
357       return ROK;
358    }
359 }
360
361 /*******************************************************************
362  *
363  * @brief Packs and Sends slot ind from MAC to DUAPP
364  *
365  * @details
366  *
367  *    Function : packMacSlotInd
368  *
369  *    Functionality:
370  *       Packs and Sends slot ind from MAC to DUAPP
371  *
372  * @params[in] Post structure pointer
373  *             Slot Info pointer              
374  * @return ROK     - success
375  *         RFAILED - failure
376  *
377  * ****************************************************************/
378 uint16_t packMacSlotInd(Pst *pst, SlotInfo *slotInfo )
379 {
380    Buffer *mBuf = NULLP;
381  
382    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
383    {
384       DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
385       return RFAILED;
386    }
387  
388    if(pst->selector == DU_SELECTOR_LC)
389    {
390       CMCHKPK(SPkU16, slotInfo->cellId, mBuf);
391       CMCHKPK(SPkU16, slotInfo->sfn, mBuf);
392       CMCHKPK(SPkU16, slotInfo->slot, mBuf);
393
394       CM_FREE_SHRABL_BUF(pst->region, pst->pool, slotInfo, sizeof(SlotInfo));
395                 slotInfo = NULL;
396    }
397    else if(pst->selector == DU_SELECTOR_LWLC)
398    {
399       /* pack the address of the structure */
400       CMCHKPK(cmPkPtr,(PTR)slotInfo, mBuf);
401    }
402    else
403    {
404       SPutMsg(mBuf);
405    }
406
407    return SPstTsk(pst,mBuf);
408 }
409
410 /*******************************************************************
411  *
412  * @brief Unpacks slot indication from MAC
413  *
414  * @details
415  *
416  *    Function : unpackMacSlotInd
417  *
418  *    Functionality:
419  *         Unpacks slot indication from MAC
420  *
421  * @params[in] Pointer to Handler
422  *             Post structure pointer
423  *             Message Buffer
424  * @return ROK     - success
425  *         RFAILED - failure
426  *
427  * ****************************************************************/
428 uint16_t unpackMacSlotInd(DuMacSlotInd func, Pst *pst, Buffer *mBuf)
429 {
430    if(pst->selector == DU_SELECTOR_LWLC)
431    {
432       SlotInfo *slotInfo;
433
434       /* unpack the address of the structure */
435       CMCHKUNPK(cmUnpkPtr, (PTR *)&slotInfo, mBuf);
436       SPutMsg(mBuf);
437       return (*func)(pst, slotInfo);
438    }
439    else if(pst->selector == DU_SELECTOR_LC)
440    {
441       SlotInfo slotInfo;
442
443       CMCHKUNPK(SUnpkU16, &(slotInfo.slot), mBuf);
444       CMCHKUNPK(SUnpkU16, &(slotInfo.sfn), mBuf);
445       CMCHKUNPK(SUnpkU16, &(slotInfo.cellId), mBuf);
446
447       SPutMsg(mBuf);
448       return (*func)(pst, &slotInfo);
449
450    }
451    else
452    {
453       /* Nothing to do for loose coupling */
454       SPutMsg(mBuf);
455       return ROK;
456    }
457    return ROK;
458 }
459
460 /*******************************************************************
461  *
462  * @brief Packs and Sends stop ind from MAC to DUAPP
463  *
464  * @details
465  *
466  *    Function : packMacStopInd
467  *
468  *    Functionality:
469  *       Packs and Sends stop ind from MAC to DUAPP
470  *
471  * @params[in] Post structure pointer
472  * @return ROK     - success
473  *         RFAILED - failure
474  *
475  * ****************************************************************/
476 uint16_t packMacStopInd(Pst *pst, MacCellStopInfo *cellStopId)
477 {
478    Buffer *mBuf = NULLP;
479
480    if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
481    {
482       DU_LOG("\nDU APP : Memory allocation failed for stop Ind pack");
483       return RFAILED;
484    }
485
486    if(pst->selector == DU_SELECTOR_LC)
487    {
488       /*pack the payload here*/
489       DU_LOG("\nDU APP : Packed CellId");
490       CMCHKPK(SPkU16, cellStopId->cellId, mBuf);
491       CM_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopId, sizeof(MacCellStopInfo));
492       cellStopId = NULL;
493    }
494    else if(pst->selector == DU_SELECTOR_LWLC)
495    {
496       /* pack the address of the structure */
497       CMCHKPK(cmPkPtr,(PTR)cellStopId, mBuf);
498    }
499    else
500    {
501       SPutMsg(mBuf);
502    }
503
504    return SPstTsk(pst,mBuf);
505 }
506
507 /*******************************************************************
508  *
509  * @brief Unpacks stop indication from MAC
510  *
511  * @details
512  *
513  *    Function : unpackMacStopInd
514  *
515  *    Functionality:
516  *         Unpacks stop indication from MAC
517  *
518  * @params[in] Pointer to Handler
519  *             Post structure pointer
520  *             Message Buffer
521  * @return ROK     - success
522  *         RFAILED - failure
523  *
524  * ****************************************************************/
525 uint16_t unpackMacStopInd(DuMacStopInd func, Pst *pst, Buffer *mBuf)
526 {
527    if(pst->selector == DU_SELECTOR_LWLC)
528    {
529       MacCellStopInfo *cellStopId;
530       /* unpack the address of the structure */
531       CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStopId, mBuf);
532       SPutMsg(mBuf);
533       return (*func)(pst, cellStopId);
534    }
535    else if(pst->selector == DU_SELECTOR_LC)
536    {
537       MacCellStopInfo cellStopId;
538       CMCHKUNPK(SUnpkU16, &(cellStopId.cellId), mBuf);
539
540       SPutMsg(mBuf);
541       return (*func)(pst, &cellStopId);
542
543    }
544    else
545    {
546       /* Nothing to do for loose coupling */
547       SPutMsg(mBuf);
548       return ROK;
549    }
550    return ROK;
551 }
552
553 /*******************************************************************
554  *
555  * @brief Packs and Sends UL CCCH Ind from MAC to DUAPP
556  *
557  * @details
558  *
559  *    Function : packMacUlCcchInd
560  *
561  *    Functionality:
562  *       Packs and Sends UL CCCH Ind from MAC to DUAPP
563  *
564  * @params[in] Post structure pointer
565  *             UL CCCH Ind pointer              
566  * @return ROK     - success
567  *         RFAILED - failure
568  *
569  * ****************************************************************/
570 uint16_t packMacUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
571 {
572    Buffer *mBuf = NULLP;
573  
574         if(pst->selector == DU_SELECTOR_LWLC)
575         {
576                 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
577                 {
578                         DU_LOG("\nMAC : Memory allocation failed at packMacUlCcchInd");
579                         return RFAILED;
580                 }
581                 /* pack the address of the structure */
582                 CMCHKPK(cmPkPtr,(PTR)ulCcchIndInfo, mBuf);
583         }
584         else
585         {
586                 DU_LOG("\nMAC: Only LWLC supported for UL CCCH Ind ");
587                 return RFAILED;
588         }
589
590         return SPstTsk(pst,mBuf);
591 }
592
593 /*******************************************************************
594  *
595  * @brief Unpacks UL CCCH indication from MAC
596  *
597  * @details
598  *
599  *    Function : unpackMacUlCcchInd
600  *
601  *    Functionality:
602  *         Unpacks UL CCCH indication from MAC
603  *
604  * @params[in] Pointer to Handler
605  *             Post structure pointer
606  *             Message Buffer
607  * @return ROK     - success
608  *         RFAILED - failure
609  *
610  * ****************************************************************/
611 uint16_t unpackMacUlCcchInd(DuMacUlCcchInd func, Pst *pst, Buffer *mBuf)
612 {
613    if(pst->selector == DU_SELECTOR_LWLC)
614    {
615       UlCcchIndInfo *ulCcchIndInfo;
616
617       /* unpack the address of the structure */
618                 CMCHKUNPK(cmUnpkPtr, (PTR *)&ulCcchIndInfo, mBuf);
619                 SPutMsg(mBuf);
620                 return (*func)(pst, ulCcchIndInfo);
621         }
622         else
623         {
624                 /* Nothing to do for other selectors */
625                 DU_LOG("\n Only LWLC supported for UL CCCH Ind ");
626                 SPutMsg(mBuf);
627         }
628         return RFAILED;
629 }
630
631 /*******************************************************************
632  *
633  * @brief Packs and Sends DL CCCH Ind from DUAPP to MAC
634  *
635  * @details
636  *
637  *    Function : packMacDlCcchInd
638  *
639  *    Functionality:
640  *       Packs and Sends DL CCCH Ind from DUAPP to MAC
641  *
642  *
643  * @params[in] Post structure pointer
644  *             DL CCCH Ind pointer              
645  * @return ROK     - success
646  *         RFAILED - failure
647  *
648  * ****************************************************************/
649 uint16_t packMacDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
650 {
651         Buffer *mBuf = NULLP;
652
653         if(pst->selector == DU_SELECTOR_LWLC)
654         {
655                 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
656                 {
657                         DU_LOG("\nMAC : Memory allocation failed at packMacDlCcchInd");
658                         return RFAILED;
659                 }
660                 /* pack the address of the structure */
661                 CMCHKPK(cmPkPtr,(PTR)dlCcchIndInfo, mBuf);
662         }
663         else
664         {
665                 DU_LOG("\nDU APP: Only LWLC supported for DL CCCH Ind ");
666                 return RFAILED;
667         }
668
669         return SPstTsk(pst,mBuf);
670 }
671
672 /*******************************************************************
673  *
674  * @brief Unpacks DL CCCH indication from DU APP
675  *
676  * @details
677  *
678  *    Function : unpackMacDlCcchInd
679  *
680  *    Functionality:
681  *         Unpacks DL CCCH indication from DU APP
682  *
683  * @params[in] Pointer to Handler
684  *             Post structure pointer
685  *             Message Buffer
686  * @return ROK     - success
687  *         RFAILED - failure
688  *
689  * ****************************************************************/
690 uint16_t unpackMacDlCcchInd(DuMacDlCcchInd func, Pst *pst, Buffer *mBuf)
691 {
692         if(pst->selector == DU_SELECTOR_LWLC)
693         {
694                 DlCcchIndInfo *dlCcchIndInfo;
695
696                 /* unpack the address of the structure */
697                 CMCHKUNPK(cmUnpkPtr, (PTR *)&dlCcchIndInfo, mBuf);
698                 SPutMsg(mBuf);
699                 return (*func)(pst, dlCcchIndInfo);
700         }
701         else
702         {
703                 /* Nothing to do for other selectors */
704                 DU_LOG("\n Only LWLC supported for DL CCCH Ind ");
705                 SPutMsg(mBuf);
706         }
707
708         return RFAILED;
709 }
710
711
712
713 /**********************************************************************
714          End of file
715 **********************************************************************/