1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 #include "common_def.h"
24 #include "du_app_mac_inf.h"
26 /**************************************************************************
27 * @brief Function to pack Loose Coupled
28 * MAC cell config parameters required by MAC
32 * Function : packMacCellCfg
35 * packs the macCellCfg parameters
37 * @param[in] Pst *pst, Post structure of the primitive.
38 * @param[in] MacCellCfg *macCellCfg, mac cell config parameters.
39 * @return ROK - success
42 ***************************************************************************/
43 int packMacCellCfg(Pst *pst, MacCellCfg *macCellCfg)
45 if(pst->selector == ODU_SELECTOR_LC)
47 /* we are now implemented only light wieght lossely coupled interface */
50 else if(pst->selector == ODU_SELECTOR_LWLC)
54 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
59 /* pack the address of the structure */
60 CMCHKPK(cmPkPtr,(PTR)macCellCfg, mBuf);
62 DU_LOG("\nDU-APP : MAC CELL config sent");
63 return SPstTsk(pst,mBuf);
68 /**************************************************************************
69 * @brief Function to pack Loose Coupled
70 * MAC cell config parameters required by MAC
74 * Function : unpackDuMacCellCfg
77 * packs the macCellCfg parameters
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
85 ***************************************************************************/
86 int unpackDuMacCellCfg(
92 MacCellCfg *macCellCfg;
94 if(pst->selector == ODU_SELECTOR_LWLC)
96 /* unpack the address of the structure */
97 CMCHKUNPK(cmUnpkPtr, (PTR *)&macCellCfg, mBuf);
98 ret = (*func)(pst, macCellCfg);
102 /* only LWLC is implemented now */
109 /**************************************************************************
110 * @brief Function to pack Loose Coupled
111 * MAC cell config confirm message
115 * Function : packMacCellCfgCfm
118 * packs the transaction ID
120 * @param[in] Pst *pst, Post structure of the primitive.
121 * @param[in] MacCellCfgCfm *macCellCfgCfm, mac cell config confirm.
122 * @return ROK - success
125 ***************************************************************************/
126 int packMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
128 if(pst->selector == ODU_SELECTOR_LC)
130 Buffer *mBuf = NULLP;
131 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
136 /* pack the transaction ID in CNF structure */
137 CMCHKPK(SPkU16, macCellCfgCfm->cellId, mBuf);
138 CMCHKPK(SPkU8, macCellCfgCfm->rsp, mBuf);
140 return SPstTsk(pst,mBuf);
142 else if(pst->selector == ODU_SELECTOR_LWLC)
144 /* only LC is supported */
150 /**************************************************************************
151 * @brief Function to pack MAC cell config confirm message
155 * Function : unpackMacCellCfgCfm
158 * packs the transaction ID
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
166 ***************************************************************************/
167 int unpackMacCellCfgCfm(
168 DuMacCellCfgCfm func,
172 MacCellCfgCfm macCellCfgCfm;
174 if(pst->selector == ODU_SELECTOR_LC)
176 /* unpack the transaction ID in CNF structure */
177 CMCHKUNPK(SUnpkU8, &(macCellCfgCfm.rsp), mBuf);
178 CMCHKUNPK(SUnpkU16, &(macCellCfgCfm.cellId), mBuf);
179 return (*func)(pst, &macCellCfgCfm);
183 /* only loose coupling is suported */
188 /*******************************************************************
190 * @brief Packs and Send Cell Start Request to MAC
194 * Function : packMacCellStartReq
197 * Packs and Sends Cell Start Request to MAC
199 * @params[in] Post structure pointer
200 * MacCellStartInfo pointer
201 * @return ROK - success
204 * ****************************************************************/
205 uint16_t packMacCellStartReq(Pst *pst, MacCellStartInfo *cellStartInfo)
207 Buffer *mBuf = NULLP;
209 if(pst->selector == ODU_SELECTOR_LC)
211 /* Loose coupling not supported */
214 else if(pst->selector == ODU_SELECTOR_LWLC)
217 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
219 DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
223 /* pack the address of the structure */
224 CMCHKPK(cmPkPtr,(PTR)cellStartInfo, mBuf);
227 return SPstTsk(pst,mBuf);
230 /*******************************************************************
232 * @brief Unpacks MAC Cell Start Request from DU APP
236 * Function : unpackMaCellStartReq
239 * Unpacks MAC Cell Start Request from DU APP
241 * @params[in] Function pointer of cell start request handler
242 * Post structure pointer
243 * Cell Start Request Info Pointer
244 * @return ROK - success
247 * ****************************************************************/
248 uint16_t unpackMacCellStartReq(DuMacCellStartReq func, Pst *pst, Buffer *mBuf)
250 MacCellStartInfo *cellStartInfo;
252 if(pst->selector == ODU_SELECTOR_LWLC)
254 /* unpack the address of the structure */
255 CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStartInfo, mBuf);
257 return (*func)(pst, cellStartInfo);
261 /* Nothing to do for loose coupling */
267 /*******************************************************************
269 * @brief Packs and Send cell stop request to MAC
273 * Function : packMacCellStopReq
276 * Packs and Send cell stop request to MAC
278 * @params[in] Post structure pointer
279 * Cell stop info structure
280 * @return ROK - success
283 * ****************************************************************/
284 uint16_t packMacCellStopReq(Pst *pst, MacCellStopInfo *cellStopInfo)
286 if(pst->selector == ODU_SELECTOR_LC)
288 /* Loose coupling not supported */
291 else if(pst->selector == ODU_SELECTOR_LWLC)
293 Buffer *mBuf = NULLP;
295 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
297 DU_LOG("\nDU APP : Memory allocation failed for cell stop req pack");
301 /* pack the address of the structure */
302 CMCHKPK(cmPkPtr,(PTR)cellStopInfo, mBuf);
304 return SPstTsk(pst,mBuf);
309 /*******************************************************************
311 * @brief Unpacks cell stop request from DU APP
315 * Function : unpackMaCellStopReq
318 * Unpacks cell stop request from DU APP
320 * @params[in] Handler function pointer
321 * Post structure pointer
323 * @return ROK - success
326 * ****************************************************************/
327 uint16_t unpackMacCellStopReq(DuMacCellStopReq func, Pst *pst, Buffer *mBuf)
329 MacCellStopInfo *cellStopInfo;
331 if(pst->selector == ODU_SELECTOR_LWLC)
333 /* unpack the address of the structure */
334 CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStopInfo, mBuf);
336 return (*func)(pst, cellStopInfo);
340 /* Nothing to do for loose coupling */
346 /*******************************************************************
348 * @brief Packs and Sends slot ind from MAC to DUAPP
352 * Function : packMacSlotInd
355 * Packs and Sends slot ind from MAC to DUAPP
357 * @params[in] Post structure pointer
359 * @return ROK - success
362 * ****************************************************************/
363 uint16_t packMacSlotInd(Pst *pst, SlotInfo *slotInfo )
365 Buffer *mBuf = NULLP;
367 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
369 DU_LOG("\nDU APP : Memory allocation failed for cell start req pack");
373 if(pst->selector == ODU_SELECTOR_LC)
375 CMCHKPK(SPkU16, slotInfo->cellId, mBuf);
376 CMCHKPK(SPkU16, slotInfo->sfn, mBuf);
377 CMCHKPK(SPkU16, slotInfo->slot, mBuf);
379 CM_FREE_SHRABL_BUF(pst->region, pst->pool, slotInfo, sizeof(SlotInfo));
382 else if(pst->selector == ODU_SELECTOR_LWLC)
384 /* pack the address of the structure */
385 CMCHKPK(cmPkPtr,(PTR)slotInfo, mBuf);
392 return SPstTsk(pst,mBuf);
395 /*******************************************************************
397 * @brief Unpacks slot indication from MAC
401 * Function : unpackMacSlotInd
404 * Unpacks slot indication from MAC
406 * @params[in] Pointer to Handler
407 * Post structure pointer
409 * @return ROK - success
412 * ****************************************************************/
413 uint16_t unpackMacSlotInd(DuMacSlotInd func, Pst *pst, Buffer *mBuf)
415 if(pst->selector == ODU_SELECTOR_LWLC)
419 /* unpack the address of the structure */
420 CMCHKUNPK(cmUnpkPtr, (PTR *)&slotInfo, mBuf);
422 return (*func)(pst, slotInfo);
424 else if(pst->selector == ODU_SELECTOR_LC)
428 CMCHKUNPK(SUnpkU16, &(slotInfo.slot), mBuf);
429 CMCHKUNPK(SUnpkU16, &(slotInfo.sfn), mBuf);
430 CMCHKUNPK(SUnpkU16, &(slotInfo.cellId), mBuf);
433 return (*func)(pst, &slotInfo);
438 /* Nothing to do for loose coupling */
445 /*******************************************************************
447 * @brief Packs and Sends stop ind from MAC to DUAPP
451 * Function : packMacStopInd
454 * Packs and Sends stop ind from MAC to DUAPP
456 * @params[in] Post structure pointer
457 * @return ROK - success
460 * ****************************************************************/
461 uint16_t packMacStopInd(Pst *pst, MacCellStopInfo *cellStopId)
463 Buffer *mBuf = NULLP;
465 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
467 DU_LOG("\nDU APP : Memory allocation failed for stop Ind pack");
471 if(pst->selector == ODU_SELECTOR_LC)
473 /*pack the payload here*/
474 DU_LOG("\nDU APP : Packed CellId");
475 CMCHKPK(SPkU16, cellStopId->cellId, mBuf);
476 CM_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopId, sizeof(MacCellStopInfo));
479 else if(pst->selector == ODU_SELECTOR_LWLC)
481 /* pack the address of the structure */
482 CMCHKPK(cmPkPtr,(PTR)cellStopId, mBuf);
489 return SPstTsk(pst,mBuf);
492 /*******************************************************************
494 * @brief Unpacks stop indication from MAC
498 * Function : unpackMacStopInd
501 * Unpacks stop indication from MAC
503 * @params[in] Pointer to Handler
504 * Post structure pointer
506 * @return ROK - success
509 * ****************************************************************/
510 uint16_t unpackMacStopInd(DuMacStopInd func, Pst *pst, Buffer *mBuf)
512 if(pst->selector == ODU_SELECTOR_LWLC)
514 MacCellStopInfo *cellStopId;
515 /* unpack the address of the structure */
516 CMCHKUNPK(cmUnpkPtr, (PTR *)&cellStopId, mBuf);
518 return (*func)(pst, cellStopId);
520 else if(pst->selector == ODU_SELECTOR_LC)
522 MacCellStopInfo cellStopId;
523 CMCHKUNPK(SUnpkU16, &(cellStopId.cellId), mBuf);
526 return (*func)(pst, &cellStopId);
531 /* Nothing to do for loose coupling */
538 /*******************************************************************
540 * @brief Packs and Sends UL CCCH Ind from MAC to DUAPP
544 * Function : packMacUlCcchInd
547 * Packs and Sends UL CCCH Ind from MAC to DUAPP
549 * @params[in] Post structure pointer
550 * UL CCCH Ind pointer
551 * @return ROK - success
554 * ****************************************************************/
555 uint16_t packMacUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
557 Buffer *mBuf = NULLP;
559 if(pst->selector == ODU_SELECTOR_LWLC)
561 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
563 DU_LOG("\nMAC : Memory allocation failed at packMacUlCcchInd");
566 /* pack the address of the structure */
567 CMCHKPK(cmPkPtr,(PTR)ulCcchIndInfo, mBuf);
571 DU_LOG("\nMAC: Only LWLC supported for UL CCCH Ind ");
575 return SPstTsk(pst,mBuf);
578 /*******************************************************************
580 * @brief Unpacks UL CCCH indication from MAC
584 * Function : unpackMacUlCcchInd
587 * Unpacks UL CCCH indication from MAC
589 * @params[in] Pointer to Handler
590 * Post structure pointer
592 * @return ROK - success
595 * ****************************************************************/
596 uint16_t unpackMacUlCcchInd(DuMacUlCcchInd func, Pst *pst, Buffer *mBuf)
598 if(pst->selector == ODU_SELECTOR_LWLC)
600 UlCcchIndInfo *ulCcchIndInfo;
602 /* unpack the address of the structure */
603 CMCHKUNPK(cmUnpkPtr, (PTR *)&ulCcchIndInfo, mBuf);
605 return (*func)(pst, ulCcchIndInfo);
609 /* Nothing to do for other selectors */
610 DU_LOG("\n Only LWLC supported for UL CCCH Ind ");
616 /*******************************************************************
618 * @brief Packs and Sends DL CCCH Ind from DUAPP to MAC
622 * Function : packMacDlCcchInd
625 * Packs and Sends DL CCCH Ind from DUAPP to MAC
628 * @params[in] Post structure pointer
629 * DL CCCH Ind pointer
630 * @return ROK - success
633 * ****************************************************************/
634 uint16_t packMacDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
636 Buffer *mBuf = NULLP;
638 if(pst->selector == ODU_SELECTOR_LWLC)
640 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
642 DU_LOG("\nMAC : Memory allocation failed at packMacDlCcchInd");
645 /* pack the address of the structure */
646 CMCHKPK(cmPkPtr,(PTR)dlCcchIndInfo, mBuf);
650 DU_LOG("\nDU APP: Only LWLC supported for DL CCCH Ind ");
654 return SPstTsk(pst,mBuf);
657 /*******************************************************************
659 * @brief Unpacks DL CCCH indication from DU APP
663 * Function : unpackMacDlCcchInd
666 * Unpacks DL CCCH indication from DU APP
668 * @params[in] Pointer to Handler
669 * Post structure pointer
671 * @return ROK - success
674 * ****************************************************************/
675 uint16_t unpackMacDlCcchInd(DuMacDlCcchInd func, Pst *pst, Buffer *mBuf)
677 if(pst->selector == ODU_SELECTOR_LWLC)
679 DlCcchIndInfo *dlCcchIndInfo;
681 /* unpack the address of the structure */
682 CMCHKUNPK(cmUnpkPtr, (PTR *)&dlCcchIndInfo, mBuf);
684 return (*func)(pst, dlCcchIndInfo);
688 /* Nothing to do for other selectors */
689 DU_LOG("\n Only LWLC supported for DL CCCH Ind ");
696 /*******************************************************************
698 * @brief Packs and Sends UE create Request from DUAPP to MAC
702 * Function : packDuMacUeCreateReq
705 * Packs and Sends UE Create Request from DUAPP to MAC
708 * @params[in] Post structure pointer
710 * @return ROK - success
713 * ****************************************************************/
714 uint8_t packDuMacUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
716 Buffer *mBuf = NULLP;
718 if(pst->selector == ODU_SELECTOR_LWLC)
720 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
722 DU_LOG("\nMAC : Memory allocation failed at packDuMacUeCreateReq");
725 /* pack the address of the structure */
726 CMCHKPK(cmPkPtr,(PTR)ueCfg, mBuf);
730 DU_LOG("\nMAC: Only LWLC supported for packDuMacUeCreateReq");
734 return SPstTsk(pst,mBuf);
737 /*******************************************************************
739 * @brief Unpacks UE Create Request received from DU APP
743 * Function : unpackMacUeCreateReq
746 * Unpacks UE Create Request received from DU APP
748 * @params[in] Pointer to Handler
749 * Post structure pointer
751 * @return ROK - success
754 * ****************************************************************/
755 uint8_t unpackMacUeCreateReq(DuMacUeCreateReq func, Pst *pst, Buffer *mBuf)
757 if(pst->selector == ODU_SELECTOR_LWLC)
761 /* unpack the address of the structure */
762 CMCHKUNPK(cmUnpkPtr, (PTR *)&ueCfg, mBuf);
764 return (*func)(pst, ueCfg);
768 /* Nothing to do for other selectors */
769 DU_LOG("\n Only LWLC supported for UE Create Request ");
776 /*******************************************************************
778 * @brief Pack and send UE config response from MAC to DU APP
782 * Function : packDuMacUeCreateRsp
785 * Pack and send UE config response from MAC to DU APP
788 * @return ROK - success
791 * ****************************************************************/
792 uint8_t packDuMacUeCreateRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
794 Buffer *mBuf = NULLP;
796 if(pst->selector == ODU_SELECTOR_LWLC)
798 if (SGetMsg(pst->region, pst->pool, &mBuf) != ROK)
800 DU_LOG("\nMAC : Memory allocation failed at packDuMacUeCfgRsp");
803 /* pack the address of the structure */
804 CMCHKPK(cmPkPtr,(PTR)cfgRsp, mBuf);
808 DU_LOG("\nMAC: Only LWLC supported for packDuMacUeCfgRsp");
812 return SPstTsk(pst,mBuf);
815 /*******************************************************************
817 * @brief Unpack UE Config Response from MAC to DU APP
821 * Function : unpackDuMacUeCreateRsp
823 * Functionality: Unpack UE Config Response from MAC to DU APP
826 * @return ROK - success
829 * ****************************************************************/
830 uint8_t unpackDuMacUeCreateRsp(DuMacUeCreateRspFunc func, Pst *pst, Buffer *mBuf)
832 if(pst->selector == ODU_SELECTOR_LWLC)
836 /* unpack the address of the structure */
837 CMCHKUNPK(cmUnpkPtr, (PTR *)&cfgRsp, mBuf);
839 return (*func)(pst, cfgRsp);
846 /**********************************************************************
848 **********************************************************************/