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