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