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