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