[EPIC-ID: ODUHIGH-488][TASK-ID: ODUHIGH-494]SCH framework update to support different...
[o-du/l2.git] / src / 5gnrmac / mac_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 /* header include files -- defines (.h)  */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "lrg.x"
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "rlc_mac_inf.h"
26 #include "mac_upr_inf_api.h"
27 #include "lwr_mac.h"
28 #ifdef INTEL_FAPI
29 #include "fapi_interface.h"
30 #endif
31 #include "lwr_mac_fsm.h"
32 #include "lwr_mac_upr_inf.h"
33 #include "mac.h"
34 #include "mac_utils.h"
35 #include "mac_harq_dl.h"
36
37 /* This file contains message handling functionality for MAC */
38
39 MacCb  macCb;
40
41 /*******************************************************************
42  *
43  * @brief Sends DL BO Info to SCH
44  *
45  * @details
46  *
47  *    Function : sendDlRlcBoInfoToSch
48  *
49  *    Functionality:
50  *       Sends DL BO Info to SCH
51  *
52  * @params[in] 
53  * @return ROK     - success
54  *         RFAILED - failure
55  *
56  ****************************************************************/
57 uint8_t sendDlRlcBoInfoToSch(DlRlcBoInfo *dlBoInfo)
58 {
59    Pst pst;
60
61    FILL_PST_MAC_TO_SCH(pst, EVENT_DL_RLC_BO_INFO_TO_SCH);
62    return(SchMessageRouter(&pst, (void *)dlBoInfo));
63 }
64
65 /*******************************************************************
66  *
67  * @brief Sends CRC Indication to SCH
68  *
69  * @details
70  *
71  *    Function : sendCrcIndMacToSch 
72  *
73  *    Functionality:
74  *       Sends CRC Indication to SCH
75  *
76  * @params[in] 
77  * @return ROK     - success
78  *         RFAILED - failure
79  *
80  ****************************************************************/
81 uint8_t sendCrcIndMacToSch(CrcIndInfo *crcInd)
82 {
83    Pst pst;
84
85    FILL_PST_MAC_TO_SCH(pst, EVENT_CRC_IND_TO_SCH);
86    return(SchMessageRouter(&pst, (void *)crcInd));
87 }
88
89 /*******************************************************************
90  *
91  * @brief Processes CRC Indication from PHY
92  *
93  * @details
94  *
95  *    Function : fapiMacCrcInd
96  *
97  *    Functionality:
98  *       Processes CRC Indication from PHY
99  *
100  * @params[in] Post Structure Pointer
101  *             Crc Indication Pointer
102  * @return ROK     - success
103  *         RFAILED - failure
104  *
105  * ****************************************************************/
106 uint8_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
107 {
108    uint16_t     cellIdx;
109    CrcIndInfo   crcIndInfo;
110    DU_LOG("\nDEBUG  -->  MAC : Received CRC indication");
111    GET_CELL_IDX(crcInd->cellId, cellIdx);
112    /* Considering one pdu and one preamble */ 
113    crcIndInfo.cellId = macCb.macCell[cellIdx]->cellId;
114    crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
115    crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
116    crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
117    crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
118    crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
119
120    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, crcInd, sizeof(CrcInd));
121    return(sendCrcIndMacToSch(&crcIndInfo));
122 }
123
124 /*******************************************************************
125  *
126  * @brief Process Rx Data Ind at MAC
127  *
128  * @details
129  *
130  *    Function : fapiMacRxDataInd
131  *
132  *    Functionality:
133  *       Process Rx Data Ind at MAC
134  *
135  * @params[in] Post structure
136  *             Rx Data Indication
137  * @return ROK     - success
138  *         RFAILED - failure
139  *
140  * ****************************************************************/
141 uint8_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
142 {
143    uint8_t ueId = 0;
144    uint16_t pduIdx, cellIdx = 0;
145    DU_LOG("\nDEBUG  -->  MAC : Received Rx Data indication");
146    /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
147     * PDU, which is stored in raCb */
148
149    for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
150    {
151
152       GET_CELL_IDX(rxDataInd->cellId, cellIdx);
153       GET_UE_ID(rxDataInd->pdus[pduIdx].rnti, ueId);
154       
155       if(macCb.macCell[cellIdx] && macCb.macCell[cellIdx]->ueCb[ueId -1].transmissionAction == STOP_TRANSMISSION)
156       {
157          DU_LOG("\nINFO   -->  MAC : UL data transmission not allowed for UE %d", macCb.macCell[cellIdx]->ueCb[ueId -1].ueId);
158       }
159       else
160       {
161          unpackRxData(rxDataInd->cellId, rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
162       }
163       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd->pdus[pduIdx].pduData,\
164          rxDataInd->pdus[pduIdx].pduLength);
165    }
166    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd, sizeof(RxDataInd));
167    return ROK;
168 }
169
170 /*******************************************************************
171  *
172  * @brief Processes DL data from RLC
173  *
174  * @details
175  *
176  *    Function : MacProcRlcDlData 
177  *
178  *    Functionality:
179  *      Processes DL data from RLC
180  *
181  * @params[in] Post structure
182  *             DL data
183  * @return ROK     - success
184  *         RFAILED - failure
185  *
186  * ****************************************************************/
187 uint8_t MacProcRlcDlData(Pst* pstInfo, RlcDlData *dlData)
188 {
189    uint8_t   pduIdx = 0;
190    uint8_t   ueId  = 0;
191    uint8_t   lcIdx = 0;
192    uint8_t   *txPdu = NULLP;
193    uint8_t   schInfoIdx = 0 ;
194    uint16_t  cellIdx = 0, txPduLen = 0;
195    MacDlData macDlData;
196    MacDlSlot *currDlSlot = NULLP;
197    DlRlcBoInfo dlBoInfo;
198
199    memset(&macDlData , 0, sizeof(MacDlData));
200    DU_LOG("\nDEBUG  -->  MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
201       dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
202
203    GET_UE_ID(dlData->rnti, ueId);   
204
205    /* Copy the pdus to be muxed into mac Dl data */
206    macDlData.ueId = ueId;
207    macDlData.numPdu = dlData->numPdu;
208    for(pduIdx = 0;  pduIdx < dlData->numPdu; pduIdx++)
209    {
210       macDlData.pduInfo[pduIdx].lcId = dlData->pduInfo[pduIdx].lcId;
211       macDlData.pduInfo[pduIdx].pduLen = dlData->pduInfo[pduIdx].pduLen;
212       macDlData.pduInfo[pduIdx].dlPdu = dlData->pduInfo[pduIdx].pduBuf;
213    }
214
215    GET_CELL_IDX(dlData->cellId, cellIdx);
216    /* Store DL data in the scheduled slot */
217    if(macCb.macCell[cellIdx] ==NULLP)
218    {
219       DU_LOG("\nERROR  -->  MAC : MacProcRlcDlData(): macCell does not exists");
220       return RFAILED;
221    }
222    currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlData->slotInfo.slot];
223    if(currDlSlot->dlInfo.dlMsgAlloc[ueId-1])
224    {
225       for(schInfoIdx=0; schInfoIdx<currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->numSchedInfo; schInfoIdx++)
226       {
227          if((currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
228                (currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH))
229             break;
230       }
231
232       txPduLen = currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize\
233                  - TX_PAYLOAD_HDR_LEN;
234       MAC_ALLOC(txPdu, txPduLen);
235       if(!txPdu)
236       {
237          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in MacProcRlcDlData");
238          return RFAILED;
239       }
240       macMuxPdu(&macDlData, NULLP, txPdu, txPduLen);
241
242       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPduLen = txPduLen;
243       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPdu = txPdu;
244       /* Add muxed TB to DL HARQ Proc CB. This will be used if retranmission of
245        * TB is requested in future. */
246       updateNewTbInDlHqProcCb(dlData->slotInfo, &macCb.macCell[cellIdx]->ueCb[ueId -1], \
247          currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize, txPdu);
248    }
249
250    for(lcIdx = 0; lcIdx < dlData->numLc; lcIdx++)
251    {
252       if(dlData->boStatus[lcIdx].bo)
253       {
254          memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
255          dlBoInfo.cellId = dlData->boStatus[lcIdx].cellId;
256          GET_CRNTI(dlBoInfo.crnti, dlData->boStatus[lcIdx].ueId);
257          dlBoInfo.lcId = dlData->boStatus[lcIdx].lcId;
258          dlBoInfo.dataVolume = dlData->boStatus[lcIdx].bo;
259          sendDlRlcBoInfoToSch(&dlBoInfo);
260       }
261    }
262
263    /* Free memory */
264    for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
265    {
266       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData->pduInfo[pduIdx].pduBuf,\
267             dlData->pduInfo[pduIdx].pduLen);
268    }
269    if(pstInfo->selector == ODU_SELECTOR_LWLC)
270    {
271       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData, sizeof(RlcDlData));
272    }
273    return ROK;
274 }
275
276 /*******************************************************************
277  *
278  * @brief Builds and Sends UL Data to RLC
279  *
280  * @details
281  *
282  *    Function : macProcUlData
283  *
284  *    Functionality: Builds and Sends UL Data to RLC
285  *
286  * @params[in] CellId
287  *             CRNTI
288  *             Slot information
289  *             LC Id on which payload was received
290  *             Pointer to the payload
291  *             Length of payload
292  * @return ROK     - success
293  *         RFAILED - failure
294  *
295  * ****************************************************************/
296 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
297 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
298 {
299    Pst         pst;
300    RlcUlData     *ulData;
301
302    /* Filling RLC Ul Data*/
303    MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcUlData));
304    if(!ulData)
305    {
306       DU_LOG("\nERROR  -->  MAC : Memory allocation failed while sending UL data to RLC");
307       return RFAILED;
308    }
309    memset(ulData, 0, sizeof(RlcUlData));
310    ulData->cellId = cellId; 
311    ulData->rnti = rnti;
312    memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotTimingInfo));
313    ulData->slotInfo.cellId = cellId;
314
315    /* Filling pdu info */
316    ulData->pduInfo[ulData->numPdu].lcId = lcId;
317    ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
318    ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
319    ulData->numPdu++;
320
321    /* Filling Post and send to RLC */
322    memset(&pst, 0, sizeof(Pst));
323    FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
324    MacSendUlDataToRlc(&pst, ulData);
325
326    return ROK;
327 }
328
329
330 /*******************************************************************
331  *
332  * @brief Processes BO status from RLC
333  *
334  * @details
335  *
336  *    Function : MacProcRlcBOStatus
337  *
338  *    Functionality:
339  *      Processes BO status from RLC
340  *
341  * @params[in] Post structure
342  *             BO status
343  * @return ROK     - success
344  *         RFAILED - failure
345  *
346  * ****************************************************************/
347 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
348 {
349    DlRlcBoInfo  dlBoInfo;
350
351    dlBoInfo.cellId = boStatus->cellId;
352    GET_CRNTI(dlBoInfo.crnti, boStatus->ueId);
353    dlBoInfo.lcId = boStatus->lcId;
354    dlBoInfo.dataVolume = boStatus->bo;
355    
356    sendDlRlcBoInfoToSch(&dlBoInfo); 
357
358    if(pst->selector == ODU_SELECTOR_LWLC)
359    {
360       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
361    }
362
363    return ROK;
364 }
365
366 /*******************************************************************
367  *
368  * @brief Send LC schedule result report to RLC
369  *
370  * @details
371  *
372  *    Function : sendSchRptToRlc 
373  *
374  *    Functionality: Send LC schedule result report to RLC
375  *
376  * @params[in] 
377  * @return ROK     - success
378  *         RFAILED - failure
379  *
380  * ****************************************************************/
381 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx)
382 {
383    Pst      pst;
384    uint8_t  lcIdx;
385    RlcSchedResultRpt  *schedRpt = NULLP;
386    
387    MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
388    if(!schedRpt)
389    {
390       DU_LOG("\nERROR  -->  MAC: Memory allocation failure in sendSchResultRepToRlc");
391       return RFAILED;
392    }
393
394    DU_LOG("\nDEBUG  -->  MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
395    schedRpt->cellId = dlInfo.cellId;
396    schedRpt->slotInfo.sfn = slotInfo.sfn;
397    schedRpt->slotInfo.slot = slotInfo.slot;
398
399    if(dlInfo.dlMsgAlloc[ueIdx])
400    {
401       schedRpt->rnti = dlInfo.dlMsgAlloc[ueIdx]->crnti;
402       schedRpt->numLc = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].numLc;
403       for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
404       {
405          schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].lcId;
406          schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].schBytes;
407       }
408    }
409
410    /* Fill Pst */
411    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
412    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
413    {
414       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
415       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
416       return RFAILED;
417    }
418
419    return ROK;
420 }
421
422 /*******************************************************************
423  *
424  * @brief Handles cell start reuqest from DU APP
425  *
426  * @details
427  *
428  *    Function : MacProcCellStart
429  *
430  *    Functionality:
431  *      Handles cell start reuqest from DU APP
432  *
433  * @params[in] Post structure pointer
434  *             Cell Id 
435  * @return ROK     - success
436  *         RFAILED - failure
437  *
438  * ****************************************************************/
439 uint8_t MacProcCellStart(Pst *pst, CellStartInfo  *cellStart)
440 {
441    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
442    gSlotCount = 0;
443    sendToLowerMac(START_REQUEST, 0, cellStart);
444
445    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStart, \
446          sizeof(CellStartInfo));
447
448    return ROK;
449 }
450
451 /*******************************************************************
452  *
453  * @brief Handles cell stop from DU APP
454  *
455  * @details
456  *
457  *    Function : MacProcCellStop
458  *
459  *    Functionality:
460  *        Handles cell stop from DU APP
461  *
462  * @params[in] Post structure pointer
463  *             Cell Id
464  * @return ROK     - success
465  *         RFAILED - failure
466  *
467  * ****************************************************************/
468 uint8_t MacProcCellStop(Pst *pst, CellStopInfo  *cellStop)
469 {
470 #ifdef INTEL_FAPI
471    uint16_t      cellIdx; 
472
473    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
474    GET_CELL_IDX(cellStop->cellId, cellIdx);
475    if(macCb.macCell[cellIdx])
476    {
477       macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
478    }
479 #endif
480
481    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStop, \
482          sizeof(CellStopInfo));
483
484    return ROK;
485 }
486
487 /*******************************************************************
488  *
489  * @brief Handles DL CCCH Ind from DU APP
490  *
491  * @details
492  *
493  *    Function : MacProcDlCcchInd 
494  *
495  *    Functionality:
496  *      Handles DL CCCH Ind from DU APP
497  *
498  * @params[in] Post structure pointer
499  *             DL CCCH Ind pointer 
500  * @return ROK     - success
501  *         RFAILED - failure
502  *
503  * ****************************************************************/
504 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
505 {
506    uint8_t      ueId = 0, ueIdx = 0;
507    uint16_t     cellIdx;
508    uint16_t     idx;
509    DlRlcBoInfo  dlBoInfo;
510    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
511
512    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
513
514    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
515
516    dlBoInfo.cellId = dlCcchIndInfo->cellId;
517    dlBoInfo.crnti = dlCcchIndInfo->crnti;
518
519    if(dlCcchIndInfo->msgType == RRC_SETUP)
520    {
521       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
522       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
523       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
524
525       /* storing Msg4 Pdu in raCb */
526       GET_UE_ID(dlBoInfo.crnti, ueId);
527       ueIdx = ueId -1;
528       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
529       {
530          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
531          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
532             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
533          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
534          {
535             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
536             {
537                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
538                   dlCcchIndInfo->dlCcchMsg[idx];
539             }
540          }
541       }
542    }
543    sendDlRlcBoInfoToSch(&dlBoInfo);
544
545    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
546          dlCcchIndInfo->dlCcchMsgLen);
547    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
548    return ROK;
549
550 }
551
552 /*******************************************************************
553  *
554  * @brief Sends UL CCCH Ind to DU APP
555  *
556  * @details
557  *
558  *    Function : macProcUlCcchInd
559  *
560  *    Functionality:
561  *        MAC sends UL CCCH Ind to DU APP
562  *
563  * @params[in] Post structure pointer
564  *            
565  * @return ROK     - success
566  *         RFAILED - failure
567  *
568  * ****************************************************************/
569 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
570 {
571    Pst pst;
572    uint8_t ret = ROK;
573    UlCcchIndInfo *ulCcchIndInfo = NULLP;
574
575    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
576    if(!ulCcchIndInfo)
577    {
578       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
579       return RFAILED;
580    }
581
582    ulCcchIndInfo->cellId = cellId;
583    ulCcchIndInfo->crnti  = crnti;
584    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
585    ulCcchIndInfo->ulCcchMsg = rrcContainer;
586
587    /* Fill Pst */
588    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
589
590    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
591    {
592       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
593       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
594       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
595       ret = RFAILED;
596    }
597    return ret;
598 }
599
600 /*******************************************************************
601  *
602  * @brief Processes received short BSR
603  *
604  * @details
605  *
606  *    Function : macProcShortBsr
607  *
608  *    Functionality:
609  *        MAC sends Short BSR to SCH
610  *
611  * @params[in] cell ID
612  *             crnti
613  *             lcg ID
614  *             buffer size
615  *
616  * @return ROK     - success
617  *         RFAILED - failure
618  *
619  * ****************************************************************/
620 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
621 {
622    Pst                  pst;
623    UlBufferStatusRptInd bsrInd;
624
625    memset(&pst, 0, sizeof(Pst));
626    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
627
628    bsrInd.cellId                 = cellId;
629    bsrInd.crnti                  = crnti;
630    bsrInd.bsrType                = SHORT_BSR;
631    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
632    bsrInd.dataVolInfo[0].lcgId   = lcgId;
633    bsrInd.dataVolInfo[0].dataVol = bufferSize;
634
635    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
636    return(SchMessageRouter(&pst, (void *)&bsrInd));
637 }
638
639 /*******************************************************************
640  *
641  * @brief Processes received short BSR
642  *
643  * @details
644  *
645  *    Function : macProcShortBsr
646  *
647  *    Functionality:
648  *        MAC sends Short BSR to SCH
649  *
650  * @params[in] cell ID
651  *             crnti
652  *             lcg ID
653  *             buffer size
654  *
655  * @return ROK     - success
656  *         RFAILED - failure
657  *
658  * ****************************************************************/
659 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg,\
660                          DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
661 {
662    Pst                  pst;
663    UlBufferStatusRptInd bsrInd;
664    uint8_t lcgIdx = 0;
665
666    memset(&pst, 0, sizeof(Pst));
667    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
668
669    bsrInd.cellId                 = cellId;
670    bsrInd.crnti                  = crnti;
671    bsrInd.bsrType                = LONG_BSR;
672    bsrInd.numLcg                 = numLcg; 
673
674    for(lcgIdx = 0; lcgIdx < numLcg; lcgIdx++)
675       memcpy(&(bsrInd.dataVolInfo[lcgIdx]), &(dataVolInfo[lcgIdx]), sizeof(DataVolInfo));
676
677    FILL_PST_MAC_TO_SCH(pst, EVENT_LONG_BSR);
678    return(SchMessageRouter(&pst, (void *)&bsrInd));
679 }
680
681 /*******************************************************************
682  *
683  * @brief Builds and send DL HARQ Indication to SCH
684  *
685  * @details
686  *
687  *    Function : buildAndSendHarqInd
688  *
689  *    Functionality:
690  *       Builds and send HARQ UCI Indication to SCH
691  *
692  * @params[in] harqInfo Pointer
693  *             crnti value
694  *             cell Index value
695  *             slot Ind Pointer
696  * @return ROK     - success
697  *         RFAILED - failure
698  *
699  * ****************************************************************/
700 uint8_t buildAndSendHarqInd(HarqInfoF0F1 *harqInfo, uint8_t crnti, uint16_t cellIdx, SlotTimingInfo *slotInd)
701 {
702    uint16_t harqCounter=0;
703    Pst pst;
704    DlHarqInd   dlHarqInd;
705    memset(&pst, 0, sizeof(Pst));
706    memset(&dlHarqInd, 0, sizeof(DlHarqInd));
707
708    dlHarqInd.cellId       = macCb.macCell[cellIdx]->cellId;
709    dlHarqInd.crnti        = crnti;
710    dlHarqInd.slotInd.sfn  = slotInd->sfn;
711    dlHarqInd.slotInd.slot = slotInd->slot;
712    dlHarqInd.numHarq      = harqInfo->numHarq;
713    memset(dlHarqInd.harqPayload, 0, MAX_SR_BITS_IN_BYTES);
714    for(harqCounter = 0; harqCounter < harqInfo->numHarq; harqCounter++)
715    {
716       dlHarqInd.harqPayload[harqCounter] = harqInfo->harqValue[harqCounter];
717    }
718    
719    /* Fill Pst */
720    FILL_PST_MAC_TO_SCH(pst, EVENT_DL_HARQ_IND_TO_SCH);
721
722    return SchMessageRouter(&pst, (void *)&dlHarqInd);
723 }
724
725
726 /*******************************************************************
727  *
728  * @brief Builds and send SR UCI Indication to SCH
729  *
730  * @details
731  *
732  *    Function : buildAndSendSrInd
733  *
734  *    Functionality:
735  *       Builds and send SR UCI Indication to SCH
736  *
737  * @params[in] SrUciIndInfo Pointer
738  *             crnti value
739  * @return ROK     - success
740  *         RFAILED - failure
741  *
742  * ****************************************************************/
743 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
744 {
745    uint16_t cellIdx;
746    Pst pst;
747    SrUciIndInfo   srUciInd;
748    memset(&pst, 0, sizeof(Pst));
749    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
750
751    GET_CELL_IDX(macUciInd->cellId, cellIdx);
752    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
753    srUciInd.crnti        = crnti;
754    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
755    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
756    srUciInd.numSrBits++;
757    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
758
759    /* Fill Pst */
760    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
761
762    return(SchMessageRouter(&pst, (void *)&srUciInd));
763 }
764
765 /*******************************************************************
766  *
767  * @brief Processes UCI Indication from PHY
768  *
769  * @details
770  *
771  *    Function : fapiMacUciInd
772  *
773  *    Functionality:
774  *       Processes UCI Indication from PHY
775  *
776  * @params[in] Post Structure Pointer
777  *             UCI Indication Pointer
778  * @return ROK     - success
779  *         RFAILED - failure
780  *
781  * ****************************************************************/
782 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
783 {
784    uint8_t     pduIdx = 0, ret = ROK;
785    uint16_t    nPdus = 0, crnti = 0, cellIdx = 0;
786
787    if(macUciInd)
788    {
789       nPdus = macUciInd->numUcis;
790       while(nPdus)
791       {
792          switch(macUciInd->pdus[pduIdx].pduType)
793          {
794             case UCI_IND_PUSCH:
795                break;
796             case UCI_IND_PUCCH_F0F1:
797             {
798                {
799                   DU_LOG("\nDEBUG  -->  MAC : Received HARQ UCI Indication\n");
800                   GET_CELL_IDX(macUciInd->cellId, cellIdx);
801                   buildAndSendHarqInd(&macUciInd->pdus[pduIdx].uci.uciPucchF0F1.harqInfo, macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti, cellIdx, &macUciInd->slotInd);
802                }
803                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
804                {
805                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
806                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
807                   ret = buildAndSendSrInd(macUciInd, crnti);
808                }
809             }
810                break;
811             case UCI_IND_PUCCH_F2F3F4:
812                break;
813             default:
814                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
815                ret = RFAILED;
816                break;
817          }
818          pduIdx++;
819          nPdus--;
820       }
821    }
822    else
823    {
824       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
825       ret = RFAILED;
826    }
827    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
828    return ret;
829 }
830
831 /*******************************************************************
832  *
833  * @brief fill Slice Cfg Request info in shared structre
834  * 
835  * @details
836  *
837  *    Function : fillSliceCfgInfo 
838  *
839  *    Functionality:
840  *       fill Slice Cfg Request info in shared structre
841  *
842  * @params[in] SchSliceCfgReq *schSliceCfgReq 
843  *             MacSliceCfgReq *macSliceCfgReq;
844  * @return ROK     - success
845  *         RFAILED - failure
846  *
847  **********************************************************************/
848  uint8_t fillSliceCfgInfo(SchSliceCfgReq *schSliceCfgReq, MacSliceCfgReq *macSliceCfgReq)
849  {
850     uint8_t cfgIdx = 0;
851     
852     if(macSliceCfgReq->listOfSliceCfg)
853     {
854        schSliceCfgReq->numOfConfiguredSlice =  macSliceCfgReq->numOfConfiguredSlice;
855        MAC_ALLOC(schSliceCfgReq->listOfConfirguration, schSliceCfgReq->numOfConfiguredSlice *sizeof(SchRrmPolicyOfSlice*));
856        if(schSliceCfgReq->listOfConfirguration == NULLP)
857        {
858           DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
859           return RFAILED;
860        }
861        for(cfgIdx = 0; cfgIdx<schSliceCfgReq->numOfConfiguredSlice; cfgIdx++)
862        {
863           MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx], sizeof(SchRrmPolicyOfSlice));
864           if(schSliceCfgReq->listOfConfirguration[cfgIdx] == NULLP)
865           {
866              DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
867              return RFAILED;
868           }
869           
870           memcpy(&schSliceCfgReq->listOfConfirguration[cfgIdx]->snssai, &macSliceCfgReq->listOfSliceCfg[cfgIdx]->snssai, sizeof(Snssai));
871
872           if(macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio)
873           {
874              MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo, sizeof(SchRrmPolicyRatio));
875              if(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo == NULLP)
876              {
877                 DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
878                 return RFAILED;
879              }
880              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMaxRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMaxRatio;
881              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMinRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMinRatio;
882              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyDedicatedRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyDedicatedRatio;
883           }
884        }
885     }
886     return ROK;
887  }
888 /*******************************************************************
889  *
890  * @brief Processes Slice Cfg Request recived from DU
891  *
892  * @details
893  *
894  *    Function : MacProcSliceCfgReq 
895  *
896  *    Functionality:
897  *       Processes Processes Slice Cfg Request recived from DU
898  *
899  * @params[in] Post Structure Pointer
900  *             MacSliceCfgReq *macSliceCfgReq;
901  * @return ROK     - success
902  *         RFAILED - failure
903  *
904  **********************************************************************/
905 uint8_t MacProcSliceCfgReq(Pst *pst, MacSliceCfgReq *macSliceCfgReq)
906 {
907    uint8_t ret = ROK;
908    Pst schPst;
909    SchSliceCfgReq *schSliceCfgReq;
910
911    DU_LOG("\nINFO  -->  MAC : Received Slice Cfg request from DU APP");
912    if(macSliceCfgReq)
913    {
914       MAC_ALLOC(schSliceCfgReq, sizeof(SchSliceCfgReq));
915       if(schSliceCfgReq == NULLP)
916       {
917          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceCfgReq");
918          ret = RFAILED;
919       }
920       else
921       {
922          if(fillSliceCfgInfo(schSliceCfgReq, macSliceCfgReq) == ROK)
923          {
924             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_CFG_REQ_TO_SCH);
925             ret = SchMessageRouter(&schPst, (void *)schSliceCfgReq);
926          }
927       }
928       freeMacSliceCfgReq(macSliceCfgReq, pst); 
929    }
930    else
931    {
932       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
933    }
934    return ret;
935 }
936
937 /*******************************************************************
938  *
939  * @brief Processes Slice ReCfg Request recived from DU
940  *
941  * @details
942  *
943  *    Function : MacProcSliceRecfgReq 
944  *
945  *    Functionality:
946  *       Processes Processes Slice ReCfg Request recived from DU
947  *
948  * @params[in] Post Structure Pointer
949  *             MacSliceCfgReq *macSliceRecfgReq;
950  * @return ROK     - success
951  *         RFAILED - failure
952  *
953  **********************************************************************/
954 uint8_t MacProcSliceRecfgReq(Pst *pst, MacSliceRecfgReq *macSliceRecfgReq)
955 {
956    uint8_t ret = ROK;
957    Pst schPst;
958    SchSliceRecfgReq *schSliceRecfgReq;
959
960    DU_LOG("\nINFO  -->  MAC : Received Slice ReCfg request from DU APP");
961    if(macSliceRecfgReq)
962    {
963       MAC_ALLOC(schSliceRecfgReq, sizeof(SchSliceRecfgReq));
964       if(schSliceRecfgReq == NULLP)
965       {
966          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceRecfgReq");
967          ret = RFAILED;
968       }
969       else
970       {
971          if(fillSliceCfgInfo(schSliceRecfgReq, macSliceRecfgReq) == ROK)
972          {
973             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_RECFG_REQ_TO_SCH);
974             ret = SchMessageRouter(&schPst, (void *)schSliceRecfgReq);
975          }
976
977       }
978       freeMacSliceCfgReq(macSliceRecfgReq, pst);
979    }
980    else
981    {
982       DU_LOG("\nINFO  -->  MAC : Received MacSliceRecfgReq is NULL");
983    }
984    return ret;
985 }
986
987 /**********************************************************************
988   End of file
989  **********************************************************************/
990