Removed EGTP_TEST flag and Modified algorithm for pumping DL data [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   lcIdx = 0;
210    uint8_t   *txPdu = NULLP;
211    uint16_t  cellIdx = 0, txPduLen = 0;
212    MacDlData macDlData;
213    MacDlSlot *currDlSlot = NULLP;
214    DlRlcBoInfo dlBoInfo;
215
216    memset(&macDlData , 0, sizeof(MacDlData));
217    DU_LOG("\nDEBUG  -->  MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
218       dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
219    /* Copy the pdus to be muxed into mac Dl data */
220    macDlData.numPdu = dlData->numPdu;
221    for(pduIdx = 0;  pduIdx < dlData->numPdu; pduIdx++)
222    {
223       macDlData.pduInfo[pduIdx].lcId = dlData->pduInfo[pduIdx].lcId;
224       macDlData.pduInfo[pduIdx].pduLen = dlData->pduInfo[pduIdx].pduLen;
225       macDlData.pduInfo[pduIdx].dlPdu = dlData->pduInfo[pduIdx].pduBuf;
226    }
227
228    GET_CELL_IDX(dlData->cellId, cellIdx);
229    /* Store DL data in the scheduled slot */
230    if(macCb.macCell[cellIdx] ==NULLP)
231    {
232       DU_LOG("\nERROR  -->  MAC : MacProcRlcDlData(): macCell does not exists");
233       return RFAILED;
234    }
235    currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlData->slotInfo.slot];
236    if(currDlSlot->dlInfo.dlMsgAlloc)
237    {
238       txPduLen = currDlSlot->dlInfo.dlMsgAlloc->dlMsgPdschCfg.codeword[0].tbSize - TX_PAYLOAD_HDR_LEN;
239       MAC_ALLOC(txPdu, txPduLen);
240       if(!txPdu)
241       {
242          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in MacProcRlcDlData");
243          return RFAILED;
244       }
245       macMuxPdu(&macDlData, NULLP, txPdu, txPduLen);
246
247       currDlSlot->dlInfo.dlMsgAlloc->dlMsgInfo.dlMsgPduLen = txPduLen;
248       currDlSlot->dlInfo.dlMsgAlloc->dlMsgInfo.dlMsgPdu = txPdu;
249    }
250
251    for(lcIdx = 0; lcIdx < dlData->numLc; lcIdx++)
252    {
253       if(dlData->boStatus[lcIdx].bo)
254       {
255          memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
256          dlBoInfo.cellId = dlData->boStatus[lcIdx].cellId;
257          GET_CRNTI(dlBoInfo.crnti, dlData->boStatus[lcIdx].ueIdx);
258          dlBoInfo.lcId = dlData->boStatus[lcIdx].lcId;
259          dlBoInfo.dataVolume = dlData->boStatus[lcIdx].bo;
260          sendDlRlcBoInfoToSch(&dlBoInfo);
261       }
262    }
263
264    /* Free memory */
265    for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
266    {
267       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData->pduInfo[pduIdx].pduBuf,\
268             dlData->pduInfo[pduIdx].pduLen);
269    }
270    if(pstInfo->selector == ODU_SELECTOR_LWLC)
271    {
272       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData, sizeof(RlcData));
273    }
274    return ROK;
275 }
276
277 /*******************************************************************
278  *
279  * @brief Builds and Sends UL Data to RLC
280  *
281  * @details
282  *
283  *    Function : macProcUlData
284  *
285  *    Functionality: Builds and Sends UL Data to RLC
286  *
287  * @params[in] CellId
288  *             CRNTI
289  *             Slot information
290  *             LC Id on which payload was received
291  *             Pointer to the payload
292  *             Length of payload
293  * @return ROK     - success
294  *         RFAILED - failure
295  *
296  * ****************************************************************/
297 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
298 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
299 {
300    Pst         pst;
301    RlcData     *ulData;
302
303    /* Filling RLC Ul Data*/
304    MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcData));
305    if(!ulData)
306    {
307       DU_LOG("\nERROR  -->  MAC : Memory allocation failed while sending UL data to RLC");
308       return RFAILED;
309    }
310    memset(ulData, 0, sizeof(RlcData));
311    ulData->cellId = cellId; 
312    ulData->rnti = rnti;
313    memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotTimingInfo));
314    ulData->slotInfo.cellId = cellId;
315
316    /* Filling pdu info */
317    if(lcId == SRB1_LCID || lcId == SRB2_LCID)
318    {
319       ulData->pduInfo[ulData->numPdu].commCh = true;
320    }
321    ulData->pduInfo[ulData->numPdu].lcId = lcId;
322    ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
323    ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
324    ulData->numPdu++;
325
326    /* Filling Post and send to RLC */
327    memset(&pst, 0, sizeof(Pst));
328    FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
329    MacSendUlDataToRlc(&pst, ulData);
330
331    return ROK;
332 }
333
334
335 /*******************************************************************
336  *
337  * @brief Processes BO status from RLC
338  *
339  * @details
340  *
341  *    Function : MacProcRlcBOStatus
342  *
343  *    Functionality:
344  *      Processes BO status from RLC
345  *
346  * @params[in] Post structure
347  *             BO status
348  * @return ROK     - success
349  *         RFAILED - failure
350  *
351  * ****************************************************************/
352 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
353 {
354    DlRlcBoInfo  dlBoInfo;
355
356    dlBoInfo.cellId = boStatus->cellId;
357    GET_CRNTI(dlBoInfo.crnti, boStatus->ueIdx);
358    dlBoInfo.lcId = boStatus->lcId;
359    dlBoInfo.dataVolume = boStatus->bo;
360
361    sendDlRlcBoInfoToSch(&dlBoInfo); 
362
363    if(pst->selector == ODU_SELECTOR_LWLC)
364    {
365       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
366    }
367
368    return ROK;
369 }
370
371 /*******************************************************************
372  *
373  * @brief Send LC schedule result report to RLC
374  *
375  * @details
376  *
377  *    Function : sendSchRptToRlc 
378  *
379  *    Functionality: Send LC schedule result report to RLC
380  *
381  * @params[in] 
382  * @return ROK     - success
383  *         RFAILED - failure
384  *
385  * ****************************************************************/
386 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo)
387 {
388    Pst      pst;
389    uint8_t  lcIdx;
390    RlcSchedResultRpt  *schedRpt = NULLP;
391    
392    MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
393    if(!schedRpt)
394    {
395       DU_LOG("\nERROR  -->  MAC: Memory allocation failure in sendSchResultRepToRlc");
396       return RFAILED;
397    }
398
399    DU_LOG("\nDEBUG  -->  MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
400    schedRpt->cellId = dlInfo.cellId;
401    schedRpt->rnti = dlInfo.dlMsgAlloc->crnti;
402    schedRpt->numLc = dlInfo.dlMsgAlloc->numLc;
403    schedRpt->slotInfo.sfn = slotInfo.sfn;
404    schedRpt->slotInfo.slot = slotInfo.slot;
405
406    for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
407    {
408       schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc->lcSchInfo[lcIdx].lcId;
409       schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc->lcSchInfo[lcIdx].schBytes;
410       schedRpt->lcSch[lcIdx].commCh = false;
411    }
412
413    /* Fill Pst */
414    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
415    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
416    {
417       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
418       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
419       return RFAILED;
420    }
421
422    return ROK;
423 }
424
425 /*******************************************************************
426  *
427  * @brief Handles cell start reuqest from DU APP
428  *
429  * @details
430  *
431  *    Function : MacProcCellStart
432  *
433  *    Functionality:
434  *      Handles cell start reuqest from DU APP
435  *
436  * @params[in] Post structure pointer
437  *             Cell Id 
438  * @return ROK     - success
439  *         RFAILED - failure
440  *
441  * ****************************************************************/
442 uint8_t MacProcCellStart(Pst *pst, OduCellId  *cellId)
443 {
444    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
445    gSlotCount = 0;
446    sendToLowerMac(START_REQUEST, 0, cellId);
447
448    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
449          sizeof(OduCellId));
450
451    return ROK;
452 }
453
454 /*******************************************************************
455  *
456  * @brief Handles cell stop from DU APP
457  *
458  * @details
459  *
460  *    Function : MacProcCellStop
461  *
462  *    Functionality:
463  *        Handles cell stop from DU APP
464  *
465  * @params[in] Post structure pointer
466  *             Cell Id
467  * @return ROK     - success
468  *         RFAILED - failure
469  *
470  * ****************************************************************/
471 uint8_t MacProcCellStop(Pst *pst, OduCellId  *cellId)
472 {
473 #ifdef INTEL_FAPI
474    uint16_t      cellIdx; 
475
476    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
477    GET_CELL_IDX(cellId->cellId, cellIdx);
478    if(macCb.macCell[cellIdx])
479    {
480       macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
481    }
482 #endif
483
484    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
485          sizeof(OduCellId));
486
487    return ROK;
488 }
489
490 /*******************************************************************
491  *
492  * @brief Handles DL CCCH Ind from DU APP
493  *
494  * @details
495  *
496  *    Function : MacProcDlCcchInd 
497  *
498  *    Functionality:
499  *      Handles DL CCCH Ind from DU APP
500  *
501  * @params[in] Post structure pointer
502  *             DL CCCH Ind pointer 
503  * @return ROK     - success
504  *         RFAILED - failure
505  *
506  * ****************************************************************/
507 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
508 {
509    uint8_t      ueIdx = 0;
510    uint16_t     cellIdx;
511    uint16_t     idx;
512    DlRlcBoInfo  dlBoInfo;
513    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
514
515    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
516
517    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
518
519    dlBoInfo.cellId = dlCcchIndInfo->cellId;
520    dlBoInfo.crnti = dlCcchIndInfo->crnti;
521
522    if(dlCcchIndInfo->msgType == RRC_SETUP)
523    {
524       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
525       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
526       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
527
528       /* storing Msg4 Pdu in raCb */
529       GET_UE_IDX(dlBoInfo.crnti, ueIdx);
530       ueIdx = ueIdx -1;
531       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
532       {
533          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
534          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
535             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
536          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
537          {
538             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
539             {
540                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
541                   dlCcchIndInfo->dlCcchMsg[idx];
542             }
543          }
544       }
545    }
546    sendDlRlcBoInfoToSch(&dlBoInfo);
547
548    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
549          dlCcchIndInfo->dlCcchMsgLen);
550    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
551    return ROK;
552
553 }
554
555 /*******************************************************************
556  *
557  * @brief Sends UL CCCH Ind to DU APP
558  *
559  * @details
560  *
561  *    Function : macProcUlCcchInd
562  *
563  *    Functionality:
564  *        MAC sends UL CCCH Ind to DU APP
565  *
566  * @params[in] Post structure pointer
567  *            
568  * @return ROK     - success
569  *         RFAILED - failure
570  *
571  * ****************************************************************/
572 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
573 {
574    Pst pst;
575    uint8_t ret = ROK;
576    UlCcchIndInfo *ulCcchIndInfo = NULLP;
577
578    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
579    if(!ulCcchIndInfo)
580    {
581       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
582       return RFAILED;
583    }
584
585    ulCcchIndInfo->cellId = cellId;
586    ulCcchIndInfo->crnti  = crnti;
587    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
588    ulCcchIndInfo->ulCcchMsg = rrcContainer;
589
590    /* Fill Pst */
591    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
592
593    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
594    {
595       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
596       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
597       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
598       ret = RFAILED;
599    }
600    return ret;
601 }
602
603 /*******************************************************************
604  *
605  * @brief Processes received short BSR
606  *
607  * @details
608  *
609  *    Function : macProcShortBsr
610  *
611  *    Functionality:
612  *        MAC sends Short BSR to SCH
613  *
614  * @params[in] cell ID
615  *             crnti
616  *             lcg ID
617  *             buffer size
618  *
619  *
620  * ****************************************************************/
621 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
622 {
623    Pst                  pst;
624    UlBufferStatusRptInd bsrInd;
625
626    memset(&pst, 0, sizeof(Pst));
627    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
628
629    bsrInd.cellId                 = cellId;
630    bsrInd.crnti                  = crnti;
631    bsrInd.bsrType                = SHORT_BSR;
632    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
633    bsrInd.dataVolInfo[0].lcgId   = lcgId;
634    bsrInd.dataVolInfo[0].dataVol = bufferSize;
635
636    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
637    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
638 }
639
640 /*******************************************************************
641  *
642  * @brief Builds and send SR UCI Indication to SCH
643  *
644  * @details
645  *
646  *    Function : buildAndSendSrInd
647  *
648  *    Functionality:
649  *       Builds and send SR UCI Indication to SCH
650  *
651  * @params[in] SrUciIndInfo Pointer
652  *             crnti value
653  * @return ROK     - success
654  *         RFAILED - failure
655  *
656  * ****************************************************************/
657 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
658 {
659    uint16_t cellIdx;
660    Pst pst;
661    SrUciIndInfo   srUciInd;
662    memset(&pst, 0, sizeof(Pst));
663    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
664
665    GET_CELL_IDX(macUciInd->cellId, cellIdx);
666    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
667    srUciInd.crnti        = crnti;
668    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
669    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
670    srUciInd.numSrBits++;
671    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
672
673    /* Fill Pst */
674    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
675
676    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
677 }
678
679 /*******************************************************************
680  *
681  * @brief Processes UCI Indication from PHY
682  *
683  * @details
684  *
685  *    Function : fapiMacUciInd
686  *
687  *    Functionality:
688  *       Processes UCI Indication from PHY
689  *
690  * @params[in] Post Structure Pointer
691  *             UCI Indication Pointer
692  * @return ROK     - success
693  *         RFAILED - failure
694  *
695  * ****************************************************************/
696 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
697 {
698    uint8_t     pduIdx = 0;
699    uint8_t     ret = ROK;
700    uint16_t    nPdus;
701    uint16_t    crnti;
702
703    if(macUciInd)
704    {
705       nPdus = macUciInd->numUcis;
706       while(nPdus)
707       {
708          switch(macUciInd->pdus[pduIdx].pduType)
709          {
710             case UCI_IND_PUSCH:
711                break;
712             case UCI_IND_PUCCH_F0F1:
713                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
714                {
715                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
716                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
717                   ret = buildAndSendSrInd(macUciInd, crnti);
718                }
719                break;
720             case UCI_IND_PUCCH_F2F3F4:
721                break;
722             default:
723                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
724                ret = RFAILED;
725                break;
726          }
727          pduIdx++;
728          nPdus--;
729       }
730    }
731    else
732    {
733       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
734       ret = RFAILED;
735    }
736    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
737    return ret;
738 }
739
740
741 /**********************************************************************
742   End of file
743  **********************************************************************/
744