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