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