Fix for RAR and DL dedicated PDU length [Issue-Id: ODUHIGH-348]
[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("\nDEBUG  -->  MAC : 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("\nDEBUG  -->  MAC : 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 = 0;
214    uint8_t   lcIdx = 0;
215    uint8_t   *txPdu = NULLP;
216    uint16_t  cellIdx = 0, txPduLen = 0;
217    MacDlData macDlData;
218    MacDlSlot *currDlSlot = NULLP;
219    DlRlcBoInfo dlBoInfo;
220
221    memset(&macDlData , 0, sizeof(MacDlData));
222    DU_LOG("\nDEBUG  -->  MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
223       dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
224    /* Copy the pdus to be muxed into mac Dl data */
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)
242    {
243       txPduLen = currDlSlot->dlInfo.dlMsgAlloc->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->dlMsgInfo.dlMsgPduLen = txPduLen;
253       currDlSlot->dlInfo.dlMsgAlloc->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, SlotIndInfo 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(SlotIndInfo));
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, SlotIndInfo slotInfo)
392 {
393    Pst      pst;
394    uint8_t  lcIdx;
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->rnti = dlInfo.dlMsgAlloc->crnti;
407    schedRpt->numLc = dlInfo.dlMsgAlloc->numLc;
408    schedRpt->slotInfo.sfn = slotInfo.sfn;
409    schedRpt->slotInfo.slot = slotInfo.slot;
410
411    for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
412    {
413       schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc->lcSchInfo[lcIdx].lcId;
414       schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc->lcSchInfo[lcIdx].schBytes;
415       schedRpt->lcSch[lcIdx].commCh = false;
416    }
417
418    /* Fill Pst */
419    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
420    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
421    {
422       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
423       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
424       return RFAILED;
425    }
426
427    return ROK;
428 }
429
430 /*******************************************************************
431  *
432  * @brief Handles cell start reuqest from DU APP
433  *
434  * @details
435  *
436  *    Function : MacProcCellStart
437  *
438  *    Functionality:
439  *      Handles cell start reuqest from DU APP
440  *
441  * @params[in] Post structure pointer
442  *             Cell Id 
443  * @return ROK     - success
444  *         RFAILED - failure
445  *
446  * ****************************************************************/
447 uint8_t MacProcCellStart(Pst *pst, OduCellId  *cellId)
448 {
449    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
450    gSlotCount = 0;
451    sendToLowerMac(START_REQUEST, 0, cellId);
452
453    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
454          sizeof(OduCellId));
455
456    return ROK;
457 }
458
459 /*******************************************************************
460  *
461  * @brief Handles cell stop from DU APP
462  *
463  * @details
464  *
465  *    Function : MacProcCellStop
466  *
467  *    Functionality:
468  *        Handles cell stop from DU APP
469  *
470  * @params[in] Post structure pointer
471  *             Cell Id
472  * @return ROK     - success
473  *         RFAILED - failure
474  *
475  * ****************************************************************/
476 uint8_t MacProcCellStop(Pst *pst, OduCellId  *cellId)
477 {
478 #ifdef INTEL_FAPI
479    uint16_t      cellIdx; 
480    SlotIndInfo   slotInfo;
481
482    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
483    GET_CELL_IDX(cellId->cellId, cellIdx);
484    if(macCb.macCell[cellIdx])
485    {
486       slotInfo.cellId = cellId->cellId;
487       slotInfo.sfn = macCb.macCell[cellIdx]->currTime.sfn;
488       slotInfo.slot = macCb.macCell[cellIdx]->currTime.slot;
489       sendToLowerMac(FAPI_STOP_REQUEST, 0, &slotInfo);
490    }
491 #endif
492
493    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
494          sizeof(OduCellId));
495
496    return ROK;
497 }
498
499 /*******************************************************************
500  *
501  * @brief Handles DL CCCH Ind from DU APP
502  *
503  * @details
504  *
505  *    Function : MacProcDlCcchInd 
506  *
507  *    Functionality:
508  *      Handles DL CCCH Ind from DU APP
509  *
510  * @params[in] Post structure pointer
511  *             DL CCCH Ind pointer 
512  * @return ROK     - success
513  *         RFAILED - failure
514  *
515  * ****************************************************************/
516 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
517 {
518    uint8_t      ueIdx = 0;
519    uint16_t     cellIdx;
520    uint16_t     idx;
521    DlRlcBoInfo  dlBoInfo;
522    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
523
524    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
525
526    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
527
528    dlBoInfo.cellId = dlCcchIndInfo->cellId;
529    dlBoInfo.crnti = dlCcchIndInfo->crnti;
530
531    if(dlCcchIndInfo->msgType == RRC_SETUP)
532    {
533       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
534       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
535       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
536
537       /* storing Msg4 Pdu in raCb */
538       GET_UE_IDX(dlBoInfo.crnti, ueIdx);
539       ueIdx = ueIdx -1;
540       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
541       {
542          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
543          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
544             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
545          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
546          {
547             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
548             {
549                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
550                   dlCcchIndInfo->dlCcchMsg[idx];
551             }
552          }
553       }
554    }
555    sendDlRlcBoInfoToSch(&dlBoInfo);
556
557    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
558          dlCcchIndInfo->dlCcchMsgLen);
559    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
560    return ROK;
561
562 }
563
564 /*******************************************************************
565  *
566  * @brief Sends UL CCCH Ind to DU APP
567  *
568  * @details
569  *
570  *    Function : macProcUlCcchInd
571  *
572  *    Functionality:
573  *        MAC sends UL CCCH Ind to DU APP
574  *
575  * @params[in] Post structure pointer
576  *            
577  * @return ROK     - success
578  *         RFAILED - failure
579  *
580  * ****************************************************************/
581 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
582 {
583    Pst pst;
584    uint8_t ret = ROK;
585    UlCcchIndInfo *ulCcchIndInfo = NULLP;
586
587    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
588    if(!ulCcchIndInfo)
589    {
590       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
591       return RFAILED;
592    }
593
594    ulCcchIndInfo->cellId = cellId;
595    ulCcchIndInfo->crnti  = crnti;
596    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
597    ulCcchIndInfo->ulCcchMsg = rrcContainer;
598
599    /* Fill Pst */
600    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
601
602    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
603    {
604       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
605       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
606       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
607       ret = RFAILED;
608    }
609    return ret;
610 }
611
612 /*******************************************************************
613  *
614  * @brief Processes received short BSR
615  *
616  * @details
617  *
618  *    Function : macProcShortBsr
619  *
620  *    Functionality:
621  *        MAC sends Short BSR to SCH
622  *
623  * @params[in] cell ID
624  *             crnti
625  *             lcg ID
626  *             buffer size
627  *
628  *
629  * ****************************************************************/
630 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
631 {
632    Pst                  pst;
633    UlBufferStatusRptInd bsrInd;
634
635    memset(&pst, 0, sizeof(Pst));
636    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
637
638    bsrInd.cellId                 = cellId;
639    bsrInd.crnti                  = crnti;
640    bsrInd.bsrType                = SHORT_BSR;
641    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
642    bsrInd.dataVolInfo[0].lcgId   = lcgId;
643    bsrInd.dataVolInfo[0].dataVol = bufferSize;
644
645    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
646    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
647 }
648
649 /*******************************************************************
650  *
651  * @brief Builds and send SR UCI Indication to SCH
652  *
653  * @details
654  *
655  *    Function : buildAndSendSrInd
656  *
657  *    Functionality:
658  *       Builds and send SR UCI Indication to SCH
659  *
660  * @params[in] SrUciIndInfo Pointer
661  *             crnti value
662  * @return ROK     - success
663  *         RFAILED - failure
664  *
665  * ****************************************************************/
666 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
667 {
668    uint16_t cellIdx;
669    Pst pst;
670    SrUciIndInfo   srUciInd;
671    memset(&pst, 0, sizeof(Pst));
672    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
673
674    GET_CELL_IDX(macUciInd->cellId, cellIdx);
675    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
676    srUciInd.crnti        = crnti;
677    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
678    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
679    srUciInd.numSrBits++;
680    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
681
682    /* Fill Pst */
683    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
684
685    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
686 }
687
688 /*******************************************************************
689  *
690  * @brief Processes UCI Indication from PHY
691  *
692  * @details
693  *
694  *    Function : fapiMacUciInd
695  *
696  *    Functionality:
697  *       Processes UCI Indication from PHY
698  *
699  * @params[in] Post Structure Pointer
700  *             UCI Indication Pointer
701  * @return ROK     - success
702  *         RFAILED - failure
703  *
704  * ****************************************************************/
705 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
706 {
707    uint8_t     pduIdx = 0;
708    uint8_t     ret = ROK;
709    uint16_t    nPdus;
710    uint16_t    crnti;
711
712    if(macUciInd)
713    {
714       nPdus = macUciInd->numUcis;
715       while(nPdus)
716       {
717          switch(macUciInd->pdus[pduIdx].pduType)
718          {
719             case UCI_IND_PUSCH:
720                break;
721             case UCI_IND_PUCCH_F0F1:
722                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
723                {
724                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
725                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
726                   ret = buildAndSendSrInd(macUciInd, crnti);
727                }
728                break;
729             case UCI_IND_PUCCH_F2F3F4:
730                break;
731             default:
732                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
733                ret = RFAILED;
734                break;
735          }
736          pduIdx++;
737          nPdus--;
738       }
739    }
740    else
741    {
742       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
743       ret = RFAILED;
744    }
745    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
746    return ret;
747 }
748
749
750 /**********************************************************************
751   End of file
752  **********************************************************************/
753