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