Changes for Multi-UE support and DL_MSG scheduling using K0 and K1 [Issue-ID: ODUHIGH...
[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
36 /* This file contains message handling functionality for MAC */
37
38 MacCb  macCb;
39
40 /* Function pointer for sending crc ind from MAC to SCH */
41 MacSchCrcIndFunc macSchCrcIndOpts[]=
42 {
43    packMacSchCrcInd,
44    MacSchCrcInd,
45    packMacSchCrcInd
46 };
47
48 /* Function pointer for sending DL RLC BO Info from MAC to SCH */
49 MacSchDlRlcBoInfoFunc macSchDlRlcBoInfoOpts[]=
50 {
51    packMacSchDlRlcBoInfo,
52    MacSchDlRlcBoInfo,
53    packMacSchDlRlcBoInfo
54 };
55
56 /* Function pointer for sending short BSR from MAC to SCH */
57 MacSchBsrFunc macSchBsrOpts[]=
58 {
59    packMacSchBsr,
60    MacSchBsr,
61    packMacSchBsr
62 };
63
64 /* Function pointer for sending SR Uci ind from MAC to SCH */
65 MacSchSrUciIndFunc macSchSrUciIndOpts[]=
66 {
67    packMacSchSrUciInd,
68    MacSchSrUciInd,
69    packMacSchSrUciInd
70 };
71
72 /*******************************************************************
73  *
74  * @brief Sends DL BO Info to SCH
75  *
76  * @details
77  *
78  *    Function : sendDlRlcBoInfoToSch
79  *
80  *    Functionality:
81  *       Sends DL BO Info to SCH
82  *
83  * @params[in] 
84  * @return ROK     - success
85  *         RFAILED - failure
86  *
87  ****************************************************************/
88 uint8_t sendDlRlcBoInfoToSch(DlRlcBoInfo *dlBoInfo)
89 {
90    Pst pst;
91
92    FILL_PST_MAC_TO_SCH(pst, EVENT_DL_RLC_BO_INFO_TO_SCH);
93    return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
94 }
95
96 /*******************************************************************
97  *
98  * @brief Sends CRC Indication to SCH
99  *
100  * @details
101  *
102  *    Function : sendCrcIndMacToSch 
103  *
104  *    Functionality:
105  *       Sends CRC Indication to SCH
106  *
107  * @params[in] 
108  * @return ROK     - success
109  *         RFAILED - failure
110  *
111  ****************************************************************/
112 uint8_t sendCrcIndMacToSch(CrcIndInfo *crcInd)
113 {
114    Pst pst;
115
116    FILL_PST_MAC_TO_SCH(pst, EVENT_CRC_IND_TO_SCH);
117    return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
118 }
119
120 /*******************************************************************
121  *
122  * @brief Processes CRC Indication from PHY
123  *
124  * @details
125  *
126  *    Function : fapiMacCrcInd
127  *
128  *    Functionality:
129  *       Processes CRC Indication from PHY
130  *
131  * @params[in] Post Structure Pointer
132  *             Crc Indication Pointer
133  * @return ROK     - success
134  *         RFAILED - failure
135  *
136  * ****************************************************************/
137 uint8_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
138 {
139    uint16_t     cellIdx;
140    CrcIndInfo   crcIndInfo;
141    DU_LOG("\nDEBUG  -->  MAC : Received CRC indication");
142    GET_CELL_IDX(crcInd->cellId, cellIdx);
143    /* Considering one pdu and one preamble */ 
144    crcIndInfo.cellId = macCb.macCell[cellIdx]->cellId;
145    crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
146    crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
147    crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
148    crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
149    crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
150
151    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, crcInd, sizeof(CrcInd));
152    return(sendCrcIndMacToSch(&crcIndInfo));
153 }
154
155 /*******************************************************************
156  *
157  * @brief Process Rx Data Ind at MAC
158  *
159  * @details
160  *
161  *    Function : fapiMacRxDataInd
162  *
163  *    Functionality:
164  *       Process Rx Data Ind at MAC
165  *
166  * @params[in] Post structure
167  *             Rx Data Indication
168  * @return ROK     - success
169  *         RFAILED - failure
170  *
171  * ****************************************************************/
172 uint8_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
173 {
174    uint16_t pduIdx;
175    DU_LOG("\nDEBUG  -->  MAC : Received Rx Data indication");
176    /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
177     * PDU, which is stored in raCb */
178
179    for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
180    {
181       unpackRxData(rxDataInd->cellId, rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
182       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd->pdus[pduIdx].pduData,\
183          rxDataInd->pdus[pduIdx].pduLength);
184    }
185    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd, sizeof(RxDataInd));
186    return ROK;
187 }
188
189 /*******************************************************************
190  *
191  * @brief Processes DL data from RLC
192  *
193  * @details
194  *
195  *    Function : MacProcRlcDlData 
196  *
197  *    Functionality:
198  *      Processes DL data from RLC
199  *
200  * @params[in] Post structure
201  *             DL data
202  * @return ROK     - success
203  *         RFAILED - failure
204  *
205  * ****************************************************************/
206 uint8_t MacProcRlcDlData(Pst* pstInfo, RlcData *dlData)
207 {
208    uint8_t   pduIdx = 0;
209    uint8_t   ueId  = 0;
210    uint8_t   lcIdx = 0;
211    uint8_t   *txPdu = NULLP;
212    uint8_t   pdschSlot = 0;
213    uint8_t   schInfoIdx = 0 ;
214    uint16_t  cellIdx = 0, txPduLen = 0;
215    MacDlData macDlData;
216    MacDlSlot *currDlSlot = NULLP;
217    DlRlcBoInfo dlBoInfo;
218
219    memset(&macDlData , 0, sizeof(MacDlData));
220    DU_LOG("\nDEBUG  -->  MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
221       dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
222
223    GET_UE_IDX(dlData->rnti, ueId);   
224
225    /* Copy the pdus to be muxed into mac Dl data */
226    macDlData.ueId = ueId;
227    macDlData.numPdu = dlData->numPdu;
228    for(pduIdx = 0;  pduIdx < dlData->numPdu; pduIdx++)
229    {
230       macDlData.pduInfo[pduIdx].lcId = dlData->pduInfo[pduIdx].lcId;
231       macDlData.pduInfo[pduIdx].pduLen = dlData->pduInfo[pduIdx].pduLen;
232       macDlData.pduInfo[pduIdx].dlPdu = dlData->pduInfo[pduIdx].pduBuf;
233    }
234
235    GET_CELL_IDX(dlData->cellId, cellIdx);
236    /* Store DL data in the scheduled slot */
237    if(macCb.macCell[cellIdx] ==NULLP)
238    {
239       DU_LOG("\nERROR  -->  MAC : MacProcRlcDlData(): macCell does not exists");
240       return RFAILED;
241    }
242    currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlData->slotInfo.slot];
243    if(currDlSlot->dlInfo.dlMsgAlloc[ueId-1])
244    {
245       for(schInfoIdx=0; schInfoIdx<currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->numSchedInfo; schInfoIdx++)
246       {
247          if((currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
248                (currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH))
249             break;
250       }
251
252       txPduLen = currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize\
253                  - TX_PAYLOAD_HDR_LEN;
254       MAC_ALLOC(txPdu, txPduLen);
255       if(!txPdu)
256       {
257          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in MacProcRlcDlData");
258          return RFAILED;
259       }
260       macMuxPdu(&macDlData, NULLP, txPdu, txPduLen);
261
262       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPduLen = txPduLen;
263       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPdu = txPdu;
264    }
265
266    for(lcIdx = 0; lcIdx < dlData->numLc; lcIdx++)
267    {
268       if(dlData->boStatus[lcIdx].bo)
269       {
270          memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
271          dlBoInfo.cellId = dlData->boStatus[lcIdx].cellId;
272          GET_CRNTI(dlBoInfo.crnti, dlData->boStatus[lcIdx].ueIdx);
273          dlBoInfo.lcId = dlData->boStatus[lcIdx].lcId;
274          dlBoInfo.dataVolume = dlData->boStatus[lcIdx].bo;
275          sendDlRlcBoInfoToSch(&dlBoInfo);
276       }
277    }
278
279    /* Free memory */
280    for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
281    {
282       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData->pduInfo[pduIdx].pduBuf,\
283             dlData->pduInfo[pduIdx].pduLen);
284    }
285    if(pstInfo->selector == ODU_SELECTOR_LWLC)
286    {
287       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData, sizeof(RlcData));
288    }
289    return ROK;
290 }
291
292 /*******************************************************************
293  *
294  * @brief Builds and Sends UL Data to RLC
295  *
296  * @details
297  *
298  *    Function : macProcUlData
299  *
300  *    Functionality: Builds and Sends UL Data to RLC
301  *
302  * @params[in] CellId
303  *             CRNTI
304  *             Slot information
305  *             LC Id on which payload was received
306  *             Pointer to the payload
307  *             Length of payload
308  * @return ROK     - success
309  *         RFAILED - failure
310  *
311  * ****************************************************************/
312 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
313 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
314 {
315    Pst         pst;
316    RlcData     *ulData;
317
318    /* Filling RLC Ul Data*/
319    MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcData));
320    if(!ulData)
321    {
322       DU_LOG("\nERROR  -->  MAC : Memory allocation failed while sending UL data to RLC");
323       return RFAILED;
324    }
325    memset(ulData, 0, sizeof(RlcData));
326    ulData->cellId = cellId; 
327    ulData->rnti = rnti;
328    memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotTimingInfo));
329    ulData->slotInfo.cellId = cellId;
330
331    /* Filling pdu info */
332    if(lcId == SRB1_LCID || lcId == SRB2_LCID)
333    {
334       ulData->pduInfo[ulData->numPdu].commCh = true;
335    }
336    ulData->pduInfo[ulData->numPdu].lcId = lcId;
337    ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
338    ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
339    ulData->numPdu++;
340
341    /* Filling Post and send to RLC */
342    memset(&pst, 0, sizeof(Pst));
343    FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
344    MacSendUlDataToRlc(&pst, ulData);
345
346    return ROK;
347 }
348
349
350 /*******************************************************************
351  *
352  * @brief Processes BO status from RLC
353  *
354  * @details
355  *
356  *    Function : MacProcRlcBOStatus
357  *
358  *    Functionality:
359  *      Processes BO status from RLC
360  *
361  * @params[in] Post structure
362  *             BO status
363  * @return ROK     - success
364  *         RFAILED - failure
365  *
366  * ****************************************************************/
367 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
368 {
369    DlRlcBoInfo  dlBoInfo;
370
371    dlBoInfo.cellId = boStatus->cellId;
372    GET_CRNTI(dlBoInfo.crnti, boStatus->ueIdx);
373    dlBoInfo.lcId = boStatus->lcId;
374    dlBoInfo.dataVolume = boStatus->bo;
375    
376    sendDlRlcBoInfoToSch(&dlBoInfo); 
377
378    if(pst->selector == ODU_SELECTOR_LWLC)
379    {
380       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
381    }
382
383    return ROK;
384 }
385
386 /*******************************************************************
387  *
388  * @brief Send LC schedule result report to RLC
389  *
390  * @details
391  *
392  *    Function : sendSchRptToRlc 
393  *
394  *    Functionality: Send LC schedule result report to RLC
395  *
396  * @params[in] 
397  * @return ROK     - success
398  *         RFAILED - failure
399  *
400  * ****************************************************************/
401 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx)
402 {
403    Pst      pst;
404    uint8_t  lcIdx;
405    RlcSchedResultRpt  *schedRpt = NULLP;
406    
407    MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
408    if(!schedRpt)
409    {
410       DU_LOG("\nERROR  -->  MAC: Memory allocation failure in sendSchResultRepToRlc");
411       return RFAILED;
412    }
413
414    DU_LOG("\nDEBUG  -->  MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
415    schedRpt->cellId = dlInfo.cellId;
416    schedRpt->slotInfo.sfn = slotInfo.sfn;
417    schedRpt->slotInfo.slot = slotInfo.slot;
418
419    if(dlInfo.dlMsgAlloc[ueIdx])
420    {
421       schedRpt->rnti = dlInfo.dlMsgAlloc[ueIdx]->crnti;
422       schedRpt->numLc = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].numLc;
423       for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
424       {
425          schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].lcId;
426          schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].schBytes;
427          schedRpt->lcSch[lcIdx].commCh = false;
428       }
429    }
430
431    /* Fill Pst */
432    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
433    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
434    {
435       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
436       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
437       return RFAILED;
438    }
439
440    return ROK;
441 }
442
443 /*******************************************************************
444  *
445  * @brief Handles cell start reuqest from DU APP
446  *
447  * @details
448  *
449  *    Function : MacProcCellStart
450  *
451  *    Functionality:
452  *      Handles cell start reuqest from DU APP
453  *
454  * @params[in] Post structure pointer
455  *             Cell Id 
456  * @return ROK     - success
457  *         RFAILED - failure
458  *
459  * ****************************************************************/
460 uint8_t MacProcCellStart(Pst *pst, OduCellId  *cellId)
461 {
462    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
463    gSlotCount = 0;
464    sendToLowerMac(START_REQUEST, 0, cellId);
465
466    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
467          sizeof(OduCellId));
468
469    return ROK;
470 }
471
472 /*******************************************************************
473  *
474  * @brief Handles cell stop from DU APP
475  *
476  * @details
477  *
478  *    Function : MacProcCellStop
479  *
480  *    Functionality:
481  *        Handles cell stop from DU APP
482  *
483  * @params[in] Post structure pointer
484  *             Cell Id
485  * @return ROK     - success
486  *         RFAILED - failure
487  *
488  * ****************************************************************/
489 uint8_t MacProcCellStop(Pst *pst, OduCellId  *cellId)
490 {
491 #ifdef INTEL_FAPI
492    uint16_t      cellIdx; 
493
494    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
495    GET_CELL_IDX(cellId->cellId, cellIdx);
496    if(macCb.macCell[cellIdx])
497    {
498       macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
499    }
500 #endif
501
502    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
503          sizeof(OduCellId));
504
505    return ROK;
506 }
507
508 /*******************************************************************
509  *
510  * @brief Handles DL CCCH Ind from DU APP
511  *
512  * @details
513  *
514  *    Function : MacProcDlCcchInd 
515  *
516  *    Functionality:
517  *      Handles DL CCCH Ind from DU APP
518  *
519  * @params[in] Post structure pointer
520  *             DL CCCH Ind pointer 
521  * @return ROK     - success
522  *         RFAILED - failure
523  *
524  * ****************************************************************/
525 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
526 {
527    uint8_t      ueIdx = 0;
528    uint16_t     cellIdx;
529    uint16_t     idx;
530    DlRlcBoInfo  dlBoInfo;
531    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
532
533    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
534
535    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
536
537    dlBoInfo.cellId = dlCcchIndInfo->cellId;
538    dlBoInfo.crnti = dlCcchIndInfo->crnti;
539
540    if(dlCcchIndInfo->msgType == RRC_SETUP)
541    {
542       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
543       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
544       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
545
546       /* storing Msg4 Pdu in raCb */
547       GET_UE_IDX(dlBoInfo.crnti, ueIdx);
548       ueIdx = ueIdx -1;
549       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
550       {
551          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
552          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
553             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
554          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
555          {
556             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
557             {
558                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
559                   dlCcchIndInfo->dlCcchMsg[idx];
560             }
561          }
562       }
563    }
564    sendDlRlcBoInfoToSch(&dlBoInfo);
565
566    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
567          dlCcchIndInfo->dlCcchMsgLen);
568    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
569    return ROK;
570
571 }
572
573 /*******************************************************************
574  *
575  * @brief Sends UL CCCH Ind to DU APP
576  *
577  * @details
578  *
579  *    Function : macProcUlCcchInd
580  *
581  *    Functionality:
582  *        MAC sends UL CCCH Ind to DU APP
583  *
584  * @params[in] Post structure pointer
585  *            
586  * @return ROK     - success
587  *         RFAILED - failure
588  *
589  * ****************************************************************/
590 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
591 {
592    Pst pst;
593    uint8_t ret = ROK;
594    UlCcchIndInfo *ulCcchIndInfo = NULLP;
595
596    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
597    if(!ulCcchIndInfo)
598    {
599       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
600       return RFAILED;
601    }
602
603    ulCcchIndInfo->cellId = cellId;
604    ulCcchIndInfo->crnti  = crnti;
605    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
606    ulCcchIndInfo->ulCcchMsg = rrcContainer;
607
608    /* Fill Pst */
609    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
610
611    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
612    {
613       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
614       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
615       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
616       ret = RFAILED;
617    }
618    return ret;
619 }
620
621 /*******************************************************************
622  *
623  * @brief Processes received short BSR
624  *
625  * @details
626  *
627  *    Function : macProcShortBsr
628  *
629  *    Functionality:
630  *        MAC sends Short BSR to SCH
631  *
632  * @params[in] cell ID
633  *             crnti
634  *             lcg ID
635  *             buffer size
636  *
637  *
638  * ****************************************************************/
639 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
640 {
641    Pst                  pst;
642    UlBufferStatusRptInd bsrInd;
643
644    memset(&pst, 0, sizeof(Pst));
645    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
646
647    bsrInd.cellId                 = cellId;
648    bsrInd.crnti                  = crnti;
649    bsrInd.bsrType                = SHORT_BSR;
650    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
651    bsrInd.dataVolInfo[0].lcgId   = lcgId;
652    bsrInd.dataVolInfo[0].dataVol = bufferSize;
653
654    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
655    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
656 }
657
658 /*******************************************************************
659  *
660  * @brief Builds and send SR UCI Indication to SCH
661  *
662  * @details
663  *
664  *    Function : buildAndSendSrInd
665  *
666  *    Functionality:
667  *       Builds and send SR UCI Indication to SCH
668  *
669  * @params[in] SrUciIndInfo Pointer
670  *             crnti value
671  * @return ROK     - success
672  *         RFAILED - failure
673  *
674  * ****************************************************************/
675 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
676 {
677    uint16_t cellIdx;
678    Pst pst;
679    SrUciIndInfo   srUciInd;
680    memset(&pst, 0, sizeof(Pst));
681    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
682
683    GET_CELL_IDX(macUciInd->cellId, cellIdx);
684    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
685    srUciInd.crnti        = crnti;
686    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
687    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
688    srUciInd.numSrBits++;
689    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
690
691    /* Fill Pst */
692    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
693
694    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
695 }
696
697 /*******************************************************************
698  *
699  * @brief Processes UCI Indication from PHY
700  *
701  * @details
702  *
703  *    Function : fapiMacUciInd
704  *
705  *    Functionality:
706  *       Processes UCI Indication from PHY
707  *
708  * @params[in] Post Structure Pointer
709  *             UCI Indication Pointer
710  * @return ROK     - success
711  *         RFAILED - failure
712  *
713  * ****************************************************************/
714 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
715 {
716    uint8_t     pduIdx = 0;
717    uint8_t     ret = ROK;
718    uint16_t    nPdus;
719    uint16_t    crnti;
720
721    if(macUciInd)
722    {
723       nPdus = macUciInd->numUcis;
724       while(nPdus)
725       {
726          switch(macUciInd->pdus[pduIdx].pduType)
727          {
728             case UCI_IND_PUSCH:
729                break;
730             case UCI_IND_PUCCH_F0F1:
731                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
732                {
733                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
734                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
735                   ret = buildAndSendSrInd(macUciInd, crnti);
736                }
737                break;
738             case UCI_IND_PUCCH_F2F3F4:
739                break;
740             default:
741                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
742                ret = RFAILED;
743                break;
744          }
745          pduIdx++;
746          nPdus--;
747       }
748    }
749    else
750    {
751       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
752       ret = RFAILED;
753    }
754    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
755    return ret;
756 }
757
758
759 /**********************************************************************
760   End of file
761  **********************************************************************/
762