Merge "O-DU High Architecture updated"
[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 : MacProcCellStartReq
419  *
420  *    Functionality:
421  *      Handles cell start reuqest from DU APP
422  *
423  * @params[in] Post structure pointer
424  *             Cell Start Request info pointer 
425  * @return ROK     - success
426  *         RFAILED - failure
427  *
428  * ****************************************************************/
429 uint8_t MacProcCellStartReq(Pst *pst, MacCellStartInfo  *cellStartInfo)
430 {
431    DU_LOG("\nMAC : Handling cell start request");
432    sendToLowerMac(START_REQUEST, 0, cellStartInfo);
433
434    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
435          sizeof(MacCellStartInfo));
436
437    return ROK;
438 }
439
440 /*******************************************************************
441  *
442  * @brief Handles cell stop request from DU APP
443  *
444  * @details
445  *
446  *    Function : MacProcCellStartReq
447  *
448  *    Functionality:
449  *        Handles cell stop request from DU APP
450  *
451  * @params[in] Post structure pointer
452  *             Mac Cell stop information
453  * @return ROK     - success
454  *         RFAILED - failure
455  *
456  * ****************************************************************/
457 uint8_t MacProcCellStopReq(Pst *pst, MacCellStopInfo  *cellStopInfo)
458 {
459 #ifdef INTEL_FAPI
460    uint16_t      cellIdx; 
461    SlotIndInfo   slotInfo;
462
463    DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
464    GET_CELL_IDX(cellStopInfo->cellId, cellIdx);
465    slotInfo.cellId = cellStopInfo->cellId;
466    slotInfo.sfn = macCb.macCell[cellIdx]->currTime.sfn;
467    slotInfo.slot = macCb.macCell[cellIdx]->currTime.slot;
468    sendToLowerMac(FAPI_STOP_REQUEST, 0, &slotInfo);
469 #endif
470
471    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
472          sizeof(MacCellStopInfo));
473
474    return ROK;
475 }
476
477 /*******************************************************************
478  *
479  * @brief Handles DL CCCH Ind from DU APP
480  *
481  * @details
482  *
483  *    Function : MacProcDlCcchInd 
484  *
485  *    Functionality:
486  *      Handles DL CCCH Ind from DU APP
487  *
488  * @params[in] Post structure pointer
489  *             DL CCCH Ind pointer 
490  * @return ROK     - success
491  *         RFAILED - failure
492  *
493  * ****************************************************************/
494 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
495 {
496    uint8_t      ueIdx = 0;
497    uint16_t     cellIdx;
498    uint16_t     idx;
499    DlRlcBoInfo  dlBoInfo;
500    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
501
502    DU_LOG("\nMAC : Handling DL CCCH IND");
503
504    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
505
506    dlBoInfo.cellId = dlCcchIndInfo->cellId;
507    dlBoInfo.crnti = dlCcchIndInfo->crnti;
508
509    if(dlCcchIndInfo->msgType == RRC_SETUP)
510    {
511       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
512       dlBoInfo.dataVolume = dlCcchIndInfo->dlCcchMsgLen;
513
514       /* storing Msg4 Pdu in raCb */
515       GET_UE_IDX(dlBoInfo.crnti, ueIdx);
516       ueIdx = ueIdx -1;
517       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
518       {
519          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
520          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
521             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
522          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
523          {
524             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
525             {
526                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
527                   dlCcchIndInfo->dlCcchMsg[idx];
528             }
529          }
530       }
531    }
532    sendDlRlcBoInfoToSch(&dlBoInfo);
533
534    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
535          dlCcchIndInfo->dlCcchMsgLen);
536    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
537    return ROK;
538
539 }
540
541 /*******************************************************************
542  *
543  * @brief Sends UL CCCH Ind to DU APP
544  *
545  * @details
546  *
547  *    Function : macProcUlCcchInd
548  *
549  *    Functionality:
550  *        MAC sends UL CCCH Ind to DU APP
551  *
552  * @params[in] Post structure pointer
553  *            
554  * @return ROK     - success
555  *         RFAILED - failure
556  *
557  * ****************************************************************/
558 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
559 {
560    Pst pst;
561    uint8_t ret = ROK;
562    UlCcchIndInfo *ulCcchIndInfo = NULLP;
563
564    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
565    if(!ulCcchIndInfo)
566    {
567       DU_LOG("\nMAC: Memory failed in macProcUlCcchInd");
568       return RFAILED;
569    }
570
571    ulCcchIndInfo->cellId = cellId;
572    ulCcchIndInfo->crnti  = crnti;
573    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
574    ulCcchIndInfo->ulCcchMsg = rrcContainer;
575
576    /* Fill Pst */
577    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
578
579    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
580    {
581       DU_LOG("\nMAC: Failed to send UL CCCH Ind to DU APP");
582       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
583       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
584       ret = RFAILED;
585    }
586    return ret;
587 }
588
589 /*******************************************************************
590  *
591  * @brief Processes received short BSR
592  *
593  * @details
594  *
595  *    Function : macProcShortBsr
596  *
597  *    Functionality:
598  *        MAC sends Short BSR to SCH
599  *
600  * @params[in] cell ID
601  *             crnti
602  *             lcg ID
603  *             buffer size
604  *
605  *
606  * ****************************************************************/
607 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
608 {
609    Pst                  pst;
610    UlBufferStatusRptInd bsrInd;
611
612    memset(&pst, 0, sizeof(Pst));
613    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
614
615    bsrInd.cellId                 = cellId;
616    bsrInd.crnti                  = crnti;
617    bsrInd.bsrType                = SHORT_BSR;
618    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
619    bsrInd.dataVolInfo[0].lcgId   = lcgId;
620    bsrInd.dataVolInfo[0].dataVol = bufferSize;
621
622    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
623    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
624 }
625
626 /*******************************************************************
627  *
628  * @brief Builds and send SR UCI Indication to SCH
629  *
630  * @details
631  *
632  *    Function : buildAndSendSrInd
633  *
634  *    Functionality:
635  *       Builds and send SR UCI Indication to SCH
636  *
637  * @params[in] SrUciIndInfo Pointer
638  *             crnti value
639  * @return ROK     - success
640  *         RFAILED - failure
641  *
642  * ****************************************************************/
643 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
644 {
645    uint16_t cellIdx;
646    Pst pst;
647    SrUciIndInfo   srUciInd;
648    memset(&pst, 0, sizeof(Pst));
649    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
650
651    GET_CELL_IDX(macUciInd->cellId, cellIdx);
652    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
653    srUciInd.crnti        = crnti;
654    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
655    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
656    srUciInd.numSrBits++;
657    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
658
659    /* Fill Pst */
660    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
661
662    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
663 }
664
665 /*******************************************************************
666  *
667  * @brief Processes UCI Indication from PHY
668  *
669  * @details
670  *
671  *    Function : fapiMacUciInd
672  *
673  *    Functionality:
674  *       Processes UCI Indication from PHY
675  *
676  * @params[in] Post Structure Pointer
677  *             UCI Indication Pointer
678  * @return ROK     - success
679  *         RFAILED - failure
680  *
681  * ****************************************************************/
682 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
683 {
684    uint8_t     pduIdx = 0;
685    uint8_t     ret = ROK;
686    uint16_t    nPdus;
687    uint16_t    crnti;
688
689    if(macUciInd)
690    {
691       nPdus = macUciInd->numUcis;
692       while(nPdus)
693       {
694          switch(macUciInd->pdus[pduIdx].pduType)
695          {
696             case UCI_IND_PUSCH:
697                break;
698             case UCI_IND_PUCCH_F0F1:
699                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
700                {
701                   DU_LOG("\nMAC : Received SR UCI indication");
702                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
703                   ret = buildAndSendSrInd(macUciInd, crnti);
704                }
705                break;
706             case UCI_IND_PUCCH_F2F3F4:
707                break;
708             default:
709                DU_LOG("\nMAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
710                ret = RFAILED;
711                break;
712          }
713          pduIdx++;
714          nPdus--;
715       }
716    }
717    else
718    {
719       DU_LOG("\nMAC: Received Uci Ind is NULL at FapiMacUciInd()");
720       ret = RFAILED;
721    }
722    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
723    return ret;
724 }
725
726
727 /**********************************************************************
728   End of file
729  **********************************************************************/
730