[Epic-ID: ODUHIGH-402][Task-ID: ODUHIGH-418] Harq feature changes
[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 #include "mac_harq_dl.h"
36
37 /* This file contains message handling functionality for MAC */
38
39 MacCb  macCb;
40
41 /* Function pointer for sending crc ind from MAC to SCH */
42 MacSchCrcIndFunc macSchCrcIndOpts[]=
43 {
44    packMacSchCrcInd,
45    MacSchCrcInd,
46    packMacSchCrcInd
47 };
48
49 /* Function pointer for sending DL RLC BO Info from MAC to SCH */
50 MacSchDlRlcBoInfoFunc macSchDlRlcBoInfoOpts[]=
51 {
52    packMacSchDlRlcBoInfo,
53    MacSchDlRlcBoInfo,
54    packMacSchDlRlcBoInfo
55 };
56
57 /* Function pointer for sending short BSR from MAC to SCH */
58 MacSchBsrFunc macSchBsrOpts[]=
59 {
60    packMacSchBsr,
61    MacSchBsr,
62    packMacSchBsr
63 };
64
65 /* Function pointer for sending SR Uci ind from MAC to SCH */
66 MacSchSrUciIndFunc macSchSrUciIndOpts[]=
67 {
68    packMacSchSrUciInd,
69    MacSchSrUciInd,
70    packMacSchSrUciInd
71 };
72
73 /* Function pointer for sending HARQ Uci ind from MAC to SCH */
74 MacSchHarqUciIndFunc macSchHarqUciIndOpts[]=
75 {
76    packMacSchHarqUciInd,
77    MacSchHarqUciInd,
78    packMacSchHarqUciInd
79 };
80
81 /* Function pointer for sending Slice cfg  ind from MAC to SCH */
82 MacSchSliceCfgReqFunc macSchSliceCfgReqOpts[]=
83 {
84    packMacSchSliceCfgReq,
85    MacSchSliceCfgReq,
86    packMacSchSliceCfgReq
87 };
88
89 /* Function pointer for sending Slice cfg  ind from MAC to SCH */
90 MacSchSliceReCfgReqFunc macSchSliceReCfgReqOpts[]=
91 {
92    packMacSchSliceReCfgReq,
93    MacSchSliceReCfgReq,
94    packMacSchSliceReCfgReq
95 };
96 /*******************************************************************
97  *
98  * @brief Sends DL BO Info to SCH
99  *
100  * @details
101  *
102  *    Function : sendDlRlcBoInfoToSch
103  *
104  *    Functionality:
105  *       Sends DL BO Info to SCH
106  *
107  * @params[in] 
108  * @return ROK     - success
109  *         RFAILED - failure
110  *
111  ****************************************************************/
112 uint8_t sendDlRlcBoInfoToSch(DlRlcBoInfo *dlBoInfo)
113 {
114    Pst pst;
115
116    FILL_PST_MAC_TO_SCH(pst, EVENT_DL_RLC_BO_INFO_TO_SCH);
117    return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
118 }
119
120 /*******************************************************************
121  *
122  * @brief Sends CRC Indication to SCH
123  *
124  * @details
125  *
126  *    Function : sendCrcIndMacToSch 
127  *
128  *    Functionality:
129  *       Sends CRC Indication to SCH
130  *
131  * @params[in] 
132  * @return ROK     - success
133  *         RFAILED - failure
134  *
135  ****************************************************************/
136 uint8_t sendCrcIndMacToSch(CrcIndInfo *crcInd)
137 {
138    Pst pst;
139
140    FILL_PST_MAC_TO_SCH(pst, EVENT_CRC_IND_TO_SCH);
141    return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
142 }
143
144 /*******************************************************************
145  *
146  * @brief Processes CRC Indication from PHY
147  *
148  * @details
149  *
150  *    Function : fapiMacCrcInd
151  *
152  *    Functionality:
153  *       Processes CRC Indication from PHY
154  *
155  * @params[in] Post Structure Pointer
156  *             Crc Indication Pointer
157  * @return ROK     - success
158  *         RFAILED - failure
159  *
160  * ****************************************************************/
161 uint8_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
162 {
163    uint16_t     cellIdx;
164    CrcIndInfo   crcIndInfo;
165    DU_LOG("\nDEBUG  -->  MAC : Received CRC indication");
166    GET_CELL_IDX(crcInd->cellId, cellIdx);
167    /* Considering one pdu and one preamble */ 
168    crcIndInfo.cellId = macCb.macCell[cellIdx]->cellId;
169    crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
170    crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
171    crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
172    crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
173    crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
174
175    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, crcInd, sizeof(CrcInd));
176    return(sendCrcIndMacToSch(&crcIndInfo));
177 }
178
179 /*******************************************************************
180  *
181  * @brief Process Rx Data Ind at MAC
182  *
183  * @details
184  *
185  *    Function : fapiMacRxDataInd
186  *
187  *    Functionality:
188  *       Process Rx Data Ind at MAC
189  *
190  * @params[in] Post structure
191  *             Rx Data Indication
192  * @return ROK     - success
193  *         RFAILED - failure
194  *
195  * ****************************************************************/
196 uint8_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
197 {
198    uint8_t ueId = 0;
199    uint16_t pduIdx, cellIdx = 0;
200    DU_LOG("\nDEBUG  -->  MAC : Received Rx Data indication");
201    /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
202     * PDU, which is stored in raCb */
203
204    for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
205    {
206
207       GET_CELL_IDX(rxDataInd->cellId, cellIdx);
208       GET_UE_ID(rxDataInd->pdus[pduIdx].rnti, ueId);
209       
210       if(macCb.macCell[cellIdx] && macCb.macCell[cellIdx]->ueCb[ueId -1].transmissionAction == STOP_TRANSMISSION)
211       {
212          DU_LOG("\nINFO   -->  MAC : UL data transmission not allowed for UE %d", macCb.macCell[cellIdx]->ueCb[ueId -1].ueId);
213       }
214       else
215       {
216          unpackRxData(rxDataInd->cellId, rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
217       }
218       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd->pdus[pduIdx].pduData,\
219          rxDataInd->pdus[pduIdx].pduLength);
220    }
221    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd, sizeof(RxDataInd));
222    return ROK;
223 }
224
225 /*******************************************************************
226  *
227  * @brief Processes DL data from RLC
228  *
229  * @details
230  *
231  *    Function : MacProcRlcDlData 
232  *
233  *    Functionality:
234  *      Processes DL data from RLC
235  *
236  * @params[in] Post structure
237  *             DL data
238  * @return ROK     - success
239  *         RFAILED - failure
240  *
241  * ****************************************************************/
242 uint8_t MacProcRlcDlData(Pst* pstInfo, RlcData *dlData)
243 {
244    uint8_t   pduIdx = 0;
245    uint8_t   ueId  = 0;
246    uint8_t   lcIdx = 0;
247    uint8_t   *txPdu = NULLP;
248    uint8_t   schInfoIdx = 0 ;
249    uint16_t  cellIdx = 0, txPduLen = 0;
250    MacDlData macDlData;
251    MacDlSlot *currDlSlot = NULLP;
252    DlRlcBoInfo dlBoInfo;
253
254    memset(&macDlData , 0, sizeof(MacDlData));
255    DU_LOG("\nDEBUG  -->  MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
256       dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
257
258    GET_UE_ID(dlData->rnti, ueId);   
259
260    /* Copy the pdus to be muxed into mac Dl data */
261    macDlData.ueId = ueId;
262    macDlData.numPdu = dlData->numPdu;
263    for(pduIdx = 0;  pduIdx < dlData->numPdu; pduIdx++)
264    {
265       macDlData.pduInfo[pduIdx].lcId = dlData->pduInfo[pduIdx].lcId;
266       macDlData.pduInfo[pduIdx].pduLen = dlData->pduInfo[pduIdx].pduLen;
267       macDlData.pduInfo[pduIdx].dlPdu = dlData->pduInfo[pduIdx].pduBuf;
268    }
269
270    GET_CELL_IDX(dlData->cellId, cellIdx);
271    /* Store DL data in the scheduled slot */
272    if(macCb.macCell[cellIdx] ==NULLP)
273    {
274       DU_LOG("\nERROR  -->  MAC : MacProcRlcDlData(): macCell does not exists");
275       return RFAILED;
276    }
277    currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlData->slotInfo.slot];
278    if(currDlSlot->dlInfo.dlMsgAlloc[ueId-1])
279    {
280       for(schInfoIdx=0; schInfoIdx<currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->numSchedInfo; schInfoIdx++)
281       {
282          if((currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
283                (currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH))
284             break;
285       }
286
287       txPduLen = currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize\
288                  - TX_PAYLOAD_HDR_LEN;
289       MAC_ALLOC(txPdu, txPduLen);
290       if(!txPdu)
291       {
292          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in MacProcRlcDlData");
293          return RFAILED;
294       }
295       macMuxPdu(&macDlData, NULLP, txPdu, txPduLen);
296
297       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPduLen = txPduLen;
298       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPdu = txPdu;
299       /* Add muxed TB to DL HARQ Proc CB. This will be used if retranmission of
300        * TB is requested in future. */
301       updateNewTbInDlHqProcCb(dlData->slotInfo, &macCb.macCell[cellIdx]->ueCb[ueId -1], \
302          currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize, txPdu);
303    }
304
305    for(lcIdx = 0; lcIdx < dlData->numLc; lcIdx++)
306    {
307       if(dlData->boStatus[lcIdx].bo)
308       {
309          memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
310          dlBoInfo.cellId = dlData->boStatus[lcIdx].cellId;
311          GET_CRNTI(dlBoInfo.crnti, dlData->boStatus[lcIdx].ueId);
312          dlBoInfo.lcId = dlData->boStatus[lcIdx].lcId;
313          dlBoInfo.dataVolume = dlData->boStatus[lcIdx].bo;
314          sendDlRlcBoInfoToSch(&dlBoInfo);
315       }
316    }
317
318    /* Free memory */
319    for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
320    {
321       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData->pduInfo[pduIdx].pduBuf,\
322             dlData->pduInfo[pduIdx].pduLen);
323    }
324    if(pstInfo->selector == ODU_SELECTOR_LWLC)
325    {
326       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData, sizeof(RlcData));
327    }
328    return ROK;
329 }
330
331 /*******************************************************************
332  *
333  * @brief Builds and Sends UL Data to RLC
334  *
335  * @details
336  *
337  *    Function : macProcUlData
338  *
339  *    Functionality: Builds and Sends UL Data to RLC
340  *
341  * @params[in] CellId
342  *             CRNTI
343  *             Slot information
344  *             LC Id on which payload was received
345  *             Pointer to the payload
346  *             Length of payload
347  * @return ROK     - success
348  *         RFAILED - failure
349  *
350  * ****************************************************************/
351 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
352 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
353 {
354    Pst         pst;
355    RlcData     *ulData;
356
357    /* Filling RLC Ul Data*/
358    MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcData));
359    if(!ulData)
360    {
361       DU_LOG("\nERROR  -->  MAC : Memory allocation failed while sending UL data to RLC");
362       return RFAILED;
363    }
364    memset(ulData, 0, sizeof(RlcData));
365    ulData->cellId = cellId; 
366    ulData->rnti = rnti;
367    memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotTimingInfo));
368    ulData->slotInfo.cellId = cellId;
369
370    /* Filling pdu info */
371    if(lcId != SRB0_LCID)
372       ulData->pduInfo[ulData->numPdu].commCh = false;
373    else
374       ulData->pduInfo[ulData->numPdu].commCh = true;
375
376    ulData->pduInfo[ulData->numPdu].lcId = lcId;
377    ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
378    ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
379    ulData->numPdu++;
380
381    /* Filling Post and send to RLC */
382    memset(&pst, 0, sizeof(Pst));
383    FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
384    MacSendUlDataToRlc(&pst, ulData);
385
386    return ROK;
387 }
388
389
390 /*******************************************************************
391  *
392  * @brief Processes BO status from RLC
393  *
394  * @details
395  *
396  *    Function : MacProcRlcBOStatus
397  *
398  *    Functionality:
399  *      Processes BO status from RLC
400  *
401  * @params[in] Post structure
402  *             BO status
403  * @return ROK     - success
404  *         RFAILED - failure
405  *
406  * ****************************************************************/
407 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
408 {
409    DlRlcBoInfo  dlBoInfo;
410
411    dlBoInfo.cellId = boStatus->cellId;
412    GET_CRNTI(dlBoInfo.crnti, boStatus->ueId);
413    dlBoInfo.lcId = boStatus->lcId;
414    dlBoInfo.dataVolume = boStatus->bo;
415    
416    sendDlRlcBoInfoToSch(&dlBoInfo); 
417
418    if(pst->selector == ODU_SELECTOR_LWLC)
419    {
420       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
421    }
422
423    return ROK;
424 }
425
426 /*******************************************************************
427  *
428  * @brief Send LC schedule result report to RLC
429  *
430  * @details
431  *
432  *    Function : sendSchRptToRlc 
433  *
434  *    Functionality: Send LC schedule result report to RLC
435  *
436  * @params[in] 
437  * @return ROK     - success
438  *         RFAILED - failure
439  *
440  * ****************************************************************/
441 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx)
442 {
443    Pst      pst;
444    uint8_t  lcIdx;
445    RlcSchedResultRpt  *schedRpt = NULLP;
446    
447    MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
448    if(!schedRpt)
449    {
450       DU_LOG("\nERROR  -->  MAC: Memory allocation failure in sendSchResultRepToRlc");
451       return RFAILED;
452    }
453
454    DU_LOG("\nDEBUG  -->  MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
455    schedRpt->cellId = dlInfo.cellId;
456    schedRpt->slotInfo.sfn = slotInfo.sfn;
457    schedRpt->slotInfo.slot = slotInfo.slot;
458
459    if(dlInfo.dlMsgAlloc[ueIdx])
460    {
461       schedRpt->rnti = dlInfo.dlMsgAlloc[ueIdx]->crnti;
462       schedRpt->numLc = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].numLc;
463       for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
464       {
465          schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].lcId;
466          schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].schBytes;
467          schedRpt->lcSch[lcIdx].commCh = false;
468       }
469    }
470
471    /* Fill Pst */
472    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
473    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
474    {
475       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
476       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
477       return RFAILED;
478    }
479
480    return ROK;
481 }
482
483 /*******************************************************************
484  *
485  * @brief Handles cell start reuqest from DU APP
486  *
487  * @details
488  *
489  *    Function : MacProcCellStart
490  *
491  *    Functionality:
492  *      Handles cell start reuqest from DU APP
493  *
494  * @params[in] Post structure pointer
495  *             Cell Id 
496  * @return ROK     - success
497  *         RFAILED - failure
498  *
499  * ****************************************************************/
500 uint8_t MacProcCellStart(Pst *pst, OduCellId  *cellId)
501 {
502    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
503    gSlotCount = 0;
504    sendToLowerMac(START_REQUEST, 0, cellId);
505
506    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
507          sizeof(OduCellId));
508
509    return ROK;
510 }
511
512 /*******************************************************************
513  *
514  * @brief Handles cell stop from DU APP
515  *
516  * @details
517  *
518  *    Function : MacProcCellStop
519  *
520  *    Functionality:
521  *        Handles cell stop from DU APP
522  *
523  * @params[in] Post structure pointer
524  *             Cell Id
525  * @return ROK     - success
526  *         RFAILED - failure
527  *
528  * ****************************************************************/
529 uint8_t MacProcCellStop(Pst *pst, OduCellId  *cellId)
530 {
531 #ifdef INTEL_FAPI
532    uint16_t      cellIdx; 
533
534    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
535    GET_CELL_IDX(cellId->cellId, cellIdx);
536    if(macCb.macCell[cellIdx])
537    {
538       macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
539    }
540 #endif
541
542    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
543          sizeof(OduCellId));
544
545    return ROK;
546 }
547
548 /*******************************************************************
549  *
550  * @brief Handles DL CCCH Ind from DU APP
551  *
552  * @details
553  *
554  *    Function : MacProcDlCcchInd 
555  *
556  *    Functionality:
557  *      Handles DL CCCH Ind from DU APP
558  *
559  * @params[in] Post structure pointer
560  *             DL CCCH Ind pointer 
561  * @return ROK     - success
562  *         RFAILED - failure
563  *
564  * ****************************************************************/
565 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
566 {
567    uint8_t      ueId = 0, ueIdx = 0;
568    uint16_t     cellIdx;
569    uint16_t     idx;
570    DlRlcBoInfo  dlBoInfo;
571    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
572
573    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
574
575    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
576
577    dlBoInfo.cellId = dlCcchIndInfo->cellId;
578    dlBoInfo.crnti = dlCcchIndInfo->crnti;
579
580    if(dlCcchIndInfo->msgType == RRC_SETUP)
581    {
582       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
583       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
584       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
585
586       /* storing Msg4 Pdu in raCb */
587       GET_UE_ID(dlBoInfo.crnti, ueId);
588       ueIdx = ueId -1;
589       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
590       {
591          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
592          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
593             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
594          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
595          {
596             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
597             {
598                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
599                   dlCcchIndInfo->dlCcchMsg[idx];
600             }
601          }
602       }
603    }
604    sendDlRlcBoInfoToSch(&dlBoInfo);
605
606    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
607          dlCcchIndInfo->dlCcchMsgLen);
608    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
609    return ROK;
610
611 }
612
613 /*******************************************************************
614  *
615  * @brief Sends UL CCCH Ind to DU APP
616  *
617  * @details
618  *
619  *    Function : macProcUlCcchInd
620  *
621  *    Functionality:
622  *        MAC sends UL CCCH Ind to DU APP
623  *
624  * @params[in] Post structure pointer
625  *            
626  * @return ROK     - success
627  *         RFAILED - failure
628  *
629  * ****************************************************************/
630 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
631 {
632    Pst pst;
633    uint8_t ret = ROK;
634    UlCcchIndInfo *ulCcchIndInfo = NULLP;
635
636    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
637    if(!ulCcchIndInfo)
638    {
639       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
640       return RFAILED;
641    }
642
643    ulCcchIndInfo->cellId = cellId;
644    ulCcchIndInfo->crnti  = crnti;
645    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
646    ulCcchIndInfo->ulCcchMsg = rrcContainer;
647
648    /* Fill Pst */
649    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
650
651    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
652    {
653       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
654       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
655       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
656       ret = RFAILED;
657    }
658    return ret;
659 }
660
661 /*******************************************************************
662  *
663  * @brief Processes received short BSR
664  *
665  * @details
666  *
667  *    Function : macProcShortBsr
668  *
669  *    Functionality:
670  *        MAC sends Short BSR to SCH
671  *
672  * @params[in] cell ID
673  *             crnti
674  *             lcg ID
675  *             buffer size
676  *
677  * @return ROK     - success
678  *         RFAILED - failure
679  *
680  * ****************************************************************/
681 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
682 {
683    Pst                  pst;
684    UlBufferStatusRptInd bsrInd;
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                = SHORT_BSR;
692    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
693    bsrInd.dataVolInfo[0].lcgId   = lcgId;
694    bsrInd.dataVolInfo[0].dataVol = bufferSize;
695
696    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
697    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
698 }
699
700 /*******************************************************************
701  *
702  * @brief Processes received short BSR
703  *
704  * @details
705  *
706  *    Function : macProcShortBsr
707  *
708  *    Functionality:
709  *        MAC sends Short BSR to SCH
710  *
711  * @params[in] cell ID
712  *             crnti
713  *             lcg ID
714  *             buffer size
715  *
716  * @return ROK     - success
717  *         RFAILED - failure
718  *
719  * ****************************************************************/
720 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg,\
721                          DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
722 {
723    Pst                  pst;
724    UlBufferStatusRptInd bsrInd;
725    uint8_t lcgIdx = 0;
726
727    memset(&pst, 0, sizeof(Pst));
728    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
729
730    bsrInd.cellId                 = cellId;
731    bsrInd.crnti                  = crnti;
732    bsrInd.bsrType                = LONG_BSR;
733    bsrInd.numLcg                 = numLcg; 
734
735    for(lcgIdx = 0; lcgIdx < numLcg; lcgIdx++)
736       memcpy(&(bsrInd.dataVolInfo[lcgIdx]), &(dataVolInfo[lcgIdx]), sizeof(DataVolInfo));
737
738    FILL_PST_MAC_TO_SCH(pst, EVENT_LONG_BSR);
739    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
740 }
741
742 /*******************************************************************
743  *
744  * @brief Builds and send HARQ UCI Indication to SCH
745  *
746  * @details
747  *
748  *    Function : buildAndSendHarqInd
749  *
750  *    Functionality:
751  *       Builds and send HARQ UCI Indication to SCH
752  *
753  * @params[in] harqInfo Pointer
754  *             crnti value
755  *             cell Index value
756  *             slot Ind Pointer
757  * @return ROK     - success
758  *         RFAILED - failure
759  *
760  * ****************************************************************/
761 uint8_t buildAndSendHarqInd(HarqInfoF0F1 *harqInfo, uint8_t crnti, uint16_t cellIdx, SlotTimingInfo *slotInd)
762 {
763    uint16_t harqCounter=0;
764    Pst pst;
765    HarqUciIndInfo   harqUciInd;
766    memset(&pst, 0, sizeof(Pst));
767    memset(&harqUciInd, 0, sizeof(HarqUciIndInfo));
768
769    harqUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
770    harqUciInd.crnti        = crnti;
771    harqUciInd.slotInd.sfn  = slotInd->sfn;
772    harqUciInd.slotInd.slot = slotInd->slot;
773    harqUciInd.numHarq = harqInfo->numHarq;
774    memset(harqUciInd.harqPayload, 0, MAX_SR_BITS_IN_BYTES);
775    for(harqCounter = 0; harqCounter < harqInfo->numHarq; harqCounter++)
776    {
777       harqUciInd.harqPayload[harqCounter] = harqInfo->harqValue[harqCounter];
778    }
779    
780    /* Fill Pst */
781    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
782
783    return(*macSchHarqUciIndOpts[pst.selector])(&pst, &harqUciInd);
784 }
785
786
787 /*******************************************************************
788  *
789  * @brief Builds and send SR UCI Indication to SCH
790  *
791  * @details
792  *
793  *    Function : buildAndSendSrInd
794  *
795  *    Functionality:
796  *       Builds and send SR UCI Indication to SCH
797  *
798  * @params[in] SrUciIndInfo Pointer
799  *             crnti value
800  * @return ROK     - success
801  *         RFAILED - failure
802  *
803  * ****************************************************************/
804 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
805 {
806    uint16_t cellIdx;
807    Pst pst;
808    SrUciIndInfo   srUciInd;
809    memset(&pst, 0, sizeof(Pst));
810    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
811
812    GET_CELL_IDX(macUciInd->cellId, cellIdx);
813    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
814    srUciInd.crnti        = crnti;
815    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
816    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
817    srUciInd.numSrBits++;
818    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
819
820    /* Fill Pst */
821    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
822
823    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
824 }
825
826 /*******************************************************************
827  *
828  * @brief Processes UCI Indication from PHY
829  *
830  * @details
831  *
832  *    Function : fapiMacUciInd
833  *
834  *    Functionality:
835  *       Processes UCI Indication from PHY
836  *
837  * @params[in] Post Structure Pointer
838  *             UCI Indication Pointer
839  * @return ROK     - success
840  *         RFAILED - failure
841  *
842  * ****************************************************************/
843 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
844 {
845    uint8_t     pduIdx = 0, ret = ROK;
846    uint16_t    nPdus = 0, crnti = 0, cellIdx = 0;
847
848    if(macUciInd)
849    {
850       nPdus = macUciInd->numUcis;
851       while(nPdus)
852       {
853          switch(macUciInd->pdus[pduIdx].pduType)
854          {
855             case UCI_IND_PUSCH:
856                break;
857             case UCI_IND_PUCCH_F0F1:
858             {
859                {
860                   DU_LOG("\nDEBUG  -->  MAC : Received HARQ UCI Indication\n");
861                   GET_CELL_IDX(macUciInd->cellId, cellIdx);
862                   buildAndSendHarqInd(&macUciInd->pdus[pduIdx].uci.uciPucchF0F1.harqInfo, macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti, cellIdx, &macUciInd->slotInd);
863                }
864                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
865                {
866                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
867                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
868                   ret = buildAndSendSrInd(macUciInd, crnti);
869                }
870             }
871                break;
872             case UCI_IND_PUCCH_F2F3F4:
873                break;
874             default:
875                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
876                ret = RFAILED;
877                break;
878          }
879          pduIdx++;
880          nPdus--;
881       }
882    }
883    else
884    {
885       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
886       ret = RFAILED;
887    }
888    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
889    return ret;
890 }
891
892 /*******************************************************************
893  *
894  * @brief fill Slice Cfg Request info in shared structre
895  * 
896  * @details
897  *
898  *    Function : fillSliceCfgInfo 
899  *
900  *    Functionality:
901  *       fill Slice Cfg Request info in shared structre
902  *
903  * @params[in] SchSliceCfgReq *schSliceCfgReq 
904  *             MacSliceCfgReq *macSliceCfgReq;
905  * @return ROK     - success
906  *         RFAILED - failure
907  *
908  **********************************************************************/
909  uint8_t fillSliceCfgInfo(SchSliceCfgReq *schSliceCfgReq, MacSliceCfgReq *macSliceCfgReq)
910  {
911     uint8_t cfgIdx = 0;
912     
913     if(macSliceCfgReq->listOfSliceCfg)
914     {
915        schSliceCfgReq->numOfConfiguredSlice =  macSliceCfgReq->numOfConfiguredSlice;
916        MAC_ALLOC(schSliceCfgReq->listOfConfirguration, schSliceCfgReq->numOfConfiguredSlice *sizeof(SchRrmPolicyOfSlice*));
917        if(schSliceCfgReq->listOfConfirguration == NULLP)
918        {
919           DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
920           return RFAILED;
921        }
922        for(cfgIdx = 0; cfgIdx<schSliceCfgReq->numOfConfiguredSlice; cfgIdx++)
923        {
924           MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx], sizeof(SchRrmPolicyOfSlice));
925           if(schSliceCfgReq->listOfConfirguration[cfgIdx] == NULLP)
926           {
927              DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
928              return RFAILED;
929           }
930           
931           memcpy(&schSliceCfgReq->listOfConfirguration[cfgIdx]->snssai, &macSliceCfgReq->listOfSliceCfg[cfgIdx]->snssai, sizeof(Snssai));
932
933           if(macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio)
934           {
935              MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo, sizeof(SchRrmPolicyRatio));
936              if(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo == NULLP)
937              {
938                 DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
939                 return RFAILED;
940              }
941              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMaxRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMaxRatio;
942              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMinRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMinRatio;
943              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyDedicatedRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyDedicatedRatio;
944           }
945        }
946     }
947     return ROK;
948  }
949 /*******************************************************************
950  *
951  * @brief Processes Slice Cfg Request recived from DU
952  *
953  * @details
954  *
955  *    Function : MacProcSliceCfgReq 
956  *
957  *    Functionality:
958  *       Processes Processes Slice Cfg Request recived from DU
959  *
960  * @params[in] Post Structure Pointer
961  *             MacSliceCfgReq *macSliceCfgReq;
962  * @return ROK     - success
963  *         RFAILED - failure
964  *
965  **********************************************************************/
966 uint8_t MacProcSliceCfgReq(Pst *pst, MacSliceCfgReq *macSliceCfgReq)
967 {
968    uint8_t ret = ROK;
969    Pst schPst;
970    SchSliceCfgReq *schSliceCfgReq;
971
972    DU_LOG("\nINFO  -->  MAC : Received Slice Cfg request from DU APP");
973    if(macSliceCfgReq)
974    {
975       MAC_ALLOC(schSliceCfgReq, sizeof(SchSliceCfgReq));
976       if(schSliceCfgReq == NULLP)
977       {
978          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceCfgReq");
979          ret = RFAILED;
980       }
981       else
982       {
983          if(fillSliceCfgInfo(schSliceCfgReq, macSliceCfgReq) == ROK)
984          {
985             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_CFG_REQ_TO_SCH);
986             ret = (*macSchSliceCfgReqOpts[schPst.selector])(&schPst, schSliceCfgReq);
987          }
988       }
989       freeMacSliceCfgReq(macSliceCfgReq, pst); 
990    }
991    else
992    {
993       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
994    }
995    return ret;
996 }
997
998 /*******************************************************************
999  *
1000  * @brief Processes Slice ReCfg Request recived from DU
1001  *
1002  * @details
1003  *
1004  *    Function : MacProcSliceReCfgReq 
1005  *
1006  *    Functionality:
1007  *       Processes Processes Slice ReCfg Request recived from DU
1008  *
1009  * @params[in] Post Structure Pointer
1010  *             MacSliceCfgReq *macSliceReCfgReq;
1011  * @return ROK     - success
1012  *         RFAILED - failure
1013  *
1014  **********************************************************************/
1015 uint8_t MacProcSliceReCfgReq(Pst *pst, MacSliceCfgReq *macSliceReCfgReq)
1016 {
1017    uint8_t ret = ROK;
1018    Pst schPst;
1019    SchSliceCfgReq *schSliceReCfgReq;
1020
1021    DU_LOG("\nINFO  -->  MAC : Received Slice ReCfg request from DU APP");
1022    if(macSliceReCfgReq)
1023    {
1024       MAC_ALLOC(schSliceReCfgReq, sizeof(SchSliceCfgReq));
1025       if(schSliceReCfgReq == NULLP)
1026       {
1027          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceReCfgReq");
1028          ret = RFAILED;
1029       }
1030       else
1031       {
1032          if(fillSliceCfgInfo(schSliceReCfgReq, macSliceReCfgReq) == ROK)
1033          {
1034             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_RECFG_REQ_TO_SCH);
1035             ret = (*macSchSliceReCfgReqOpts[schPst.selector])(&schPst, schSliceReCfgReq);
1036          }
1037
1038       }
1039       freeMacSliceCfgReq(macSliceReCfgReq, pst);
1040    }
1041    else
1042    {
1043       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
1044    }
1045    return ret;
1046 }
1047
1048 /**********************************************************************
1049   End of file
1050  **********************************************************************/
1051