[Task-ID: ODUHIGH-432]Fix to send correct RLC header and PDCP SN for RRC messages...
[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].ueId);
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 != SRB0_LCID)
347       ulData->pduInfo[ulData->numPdu].commCh = false;
348    else
349       ulData->pduInfo[ulData->numPdu].commCh = true;
350
351    ulData->pduInfo[ulData->numPdu].lcId = lcId;
352    ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
353    ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
354    ulData->numPdu++;
355
356    /* Filling Post and send to RLC */
357    memset(&pst, 0, sizeof(Pst));
358    FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
359    MacSendUlDataToRlc(&pst, ulData);
360
361    return ROK;
362 }
363
364
365 /*******************************************************************
366  *
367  * @brief Processes BO status from RLC
368  *
369  * @details
370  *
371  *    Function : MacProcRlcBOStatus
372  *
373  *    Functionality:
374  *      Processes BO status from RLC
375  *
376  * @params[in] Post structure
377  *             BO status
378  * @return ROK     - success
379  *         RFAILED - failure
380  *
381  * ****************************************************************/
382 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
383 {
384    DlRlcBoInfo  dlBoInfo;
385
386    dlBoInfo.cellId = boStatus->cellId;
387    GET_CRNTI(dlBoInfo.crnti, boStatus->ueId);
388    dlBoInfo.lcId = boStatus->lcId;
389    dlBoInfo.dataVolume = boStatus->bo;
390    
391    sendDlRlcBoInfoToSch(&dlBoInfo); 
392
393    if(pst->selector == ODU_SELECTOR_LWLC)
394    {
395       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
396    }
397
398    return ROK;
399 }
400
401 /*******************************************************************
402  *
403  * @brief Send LC schedule result report to RLC
404  *
405  * @details
406  *
407  *    Function : sendSchRptToRlc 
408  *
409  *    Functionality: Send LC schedule result report to RLC
410  *
411  * @params[in] 
412  * @return ROK     - success
413  *         RFAILED - failure
414  *
415  * ****************************************************************/
416 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx)
417 {
418    Pst      pst;
419    uint8_t  lcIdx;
420    RlcSchedResultRpt  *schedRpt = NULLP;
421    
422    MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
423    if(!schedRpt)
424    {
425       DU_LOG("\nERROR  -->  MAC: Memory allocation failure in sendSchResultRepToRlc");
426       return RFAILED;
427    }
428
429    DU_LOG("\nDEBUG  -->  MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
430    schedRpt->cellId = dlInfo.cellId;
431    schedRpt->slotInfo.sfn = slotInfo.sfn;
432    schedRpt->slotInfo.slot = slotInfo.slot;
433
434    if(dlInfo.dlMsgAlloc[ueIdx])
435    {
436       schedRpt->rnti = dlInfo.dlMsgAlloc[ueIdx]->crnti;
437       schedRpt->numLc = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].numLc;
438       for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
439       {
440          schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].lcId;
441          schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].schBytes;
442          schedRpt->lcSch[lcIdx].commCh = false;
443       }
444    }
445
446    /* Fill Pst */
447    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
448    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
449    {
450       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
451       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
452       return RFAILED;
453    }
454
455    return ROK;
456 }
457
458 /*******************************************************************
459  *
460  * @brief Handles cell start reuqest from DU APP
461  *
462  * @details
463  *
464  *    Function : MacProcCellStart
465  *
466  *    Functionality:
467  *      Handles cell start reuqest from DU APP
468  *
469  * @params[in] Post structure pointer
470  *             Cell Id 
471  * @return ROK     - success
472  *         RFAILED - failure
473  *
474  * ****************************************************************/
475 uint8_t MacProcCellStart(Pst *pst, OduCellId  *cellId)
476 {
477    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
478    gSlotCount = 0;
479    sendToLowerMac(START_REQUEST, 0, cellId);
480
481    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
482          sizeof(OduCellId));
483
484    return ROK;
485 }
486
487 /*******************************************************************
488  *
489  * @brief Handles cell stop from DU APP
490  *
491  * @details
492  *
493  *    Function : MacProcCellStop
494  *
495  *    Functionality:
496  *        Handles cell stop from DU APP
497  *
498  * @params[in] Post structure pointer
499  *             Cell Id
500  * @return ROK     - success
501  *         RFAILED - failure
502  *
503  * ****************************************************************/
504 uint8_t MacProcCellStop(Pst *pst, OduCellId  *cellId)
505 {
506 #ifdef INTEL_FAPI
507    uint16_t      cellIdx; 
508
509    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
510    GET_CELL_IDX(cellId->cellId, cellIdx);
511    if(macCb.macCell[cellIdx])
512    {
513       macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
514    }
515 #endif
516
517    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
518          sizeof(OduCellId));
519
520    return ROK;
521 }
522
523 /*******************************************************************
524  *
525  * @brief Handles DL CCCH Ind from DU APP
526  *
527  * @details
528  *
529  *    Function : MacProcDlCcchInd 
530  *
531  *    Functionality:
532  *      Handles DL CCCH Ind from DU APP
533  *
534  * @params[in] Post structure pointer
535  *             DL CCCH Ind pointer 
536  * @return ROK     - success
537  *         RFAILED - failure
538  *
539  * ****************************************************************/
540 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
541 {
542    uint8_t      ueId = 0, ueIdx = 0;
543    uint16_t     cellIdx;
544    uint16_t     idx;
545    DlRlcBoInfo  dlBoInfo;
546    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
547
548    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
549
550    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
551
552    dlBoInfo.cellId = dlCcchIndInfo->cellId;
553    dlBoInfo.crnti = dlCcchIndInfo->crnti;
554
555    if(dlCcchIndInfo->msgType == RRC_SETUP)
556    {
557       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
558       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
559       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
560
561       /* storing Msg4 Pdu in raCb */
562       GET_UE_ID(dlBoInfo.crnti, ueId);
563       ueIdx = ueId -1;
564       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
565       {
566          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
567          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
568             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
569          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
570          {
571             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
572             {
573                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
574                   dlCcchIndInfo->dlCcchMsg[idx];
575             }
576          }
577       }
578    }
579    sendDlRlcBoInfoToSch(&dlBoInfo);
580
581    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
582          dlCcchIndInfo->dlCcchMsgLen);
583    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
584    return ROK;
585
586 }
587
588 /*******************************************************************
589  *
590  * @brief Sends UL CCCH Ind to DU APP
591  *
592  * @details
593  *
594  *    Function : macProcUlCcchInd
595  *
596  *    Functionality:
597  *        MAC sends UL CCCH Ind to DU APP
598  *
599  * @params[in] Post structure pointer
600  *            
601  * @return ROK     - success
602  *         RFAILED - failure
603  *
604  * ****************************************************************/
605 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
606 {
607    Pst pst;
608    uint8_t ret = ROK;
609    UlCcchIndInfo *ulCcchIndInfo = NULLP;
610
611    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
612    if(!ulCcchIndInfo)
613    {
614       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
615       return RFAILED;
616    }
617
618    ulCcchIndInfo->cellId = cellId;
619    ulCcchIndInfo->crnti  = crnti;
620    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
621    ulCcchIndInfo->ulCcchMsg = rrcContainer;
622
623    /* Fill Pst */
624    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
625
626    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
627    {
628       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
629       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
630       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
631       ret = RFAILED;
632    }
633    return ret;
634 }
635
636 /*******************************************************************
637  *
638  * @brief Processes received short BSR
639  *
640  * @details
641  *
642  *    Function : macProcShortBsr
643  *
644  *    Functionality:
645  *        MAC sends Short BSR to SCH
646  *
647  * @params[in] cell ID
648  *             crnti
649  *             lcg ID
650  *             buffer size
651  *
652  * @return ROK     - success
653  *         RFAILED - failure
654  *
655  * ****************************************************************/
656 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
657 {
658    Pst                  pst;
659    UlBufferStatusRptInd bsrInd;
660
661    memset(&pst, 0, sizeof(Pst));
662    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
663
664    bsrInd.cellId                 = cellId;
665    bsrInd.crnti                  = crnti;
666    bsrInd.bsrType                = SHORT_BSR;
667    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
668    bsrInd.dataVolInfo[0].lcgId   = lcgId;
669    bsrInd.dataVolInfo[0].dataVol = bufferSize;
670
671    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
672    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
673 }
674
675 /*******************************************************************
676  *
677  * @brief Processes received short BSR
678  *
679  * @details
680  *
681  *    Function : macProcShortBsr
682  *
683  *    Functionality:
684  *        MAC sends Short BSR to SCH
685  *
686  * @params[in] cell ID
687  *             crnti
688  *             lcg ID
689  *             buffer size
690  *
691  * @return ROK     - success
692  *         RFAILED - failure
693  *
694  * ****************************************************************/
695 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg,\
696                          DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
697 {
698    Pst                  pst;
699    UlBufferStatusRptInd bsrInd;
700    uint8_t lcgIdx = 0;
701
702    memset(&pst, 0, sizeof(Pst));
703    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
704
705    bsrInd.cellId                 = cellId;
706    bsrInd.crnti                  = crnti;
707    bsrInd.bsrType                = LONG_BSR;
708    bsrInd.numLcg                 = numLcg; 
709
710    for(lcgIdx = 0; lcgIdx < numLcg; lcgIdx++)
711       memcpy(&(bsrInd.dataVolInfo[lcgIdx]), &(dataVolInfo[lcgIdx]), sizeof(DataVolInfo));
712
713    FILL_PST_MAC_TO_SCH(pst, EVENT_LONG_BSR);
714    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
715 }
716
717 /*******************************************************************
718  *
719  * @brief Builds and send SR UCI Indication to SCH
720  *
721  * @details
722  *
723  *    Function : buildAndSendSrInd
724  *
725  *    Functionality:
726  *       Builds and send SR UCI Indication to SCH
727  *
728  * @params[in] SrUciIndInfo Pointer
729  *             crnti value
730  * @return ROK     - success
731  *         RFAILED - failure
732  *
733  * ****************************************************************/
734 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
735 {
736    uint16_t cellIdx;
737    Pst pst;
738    SrUciIndInfo   srUciInd;
739    memset(&pst, 0, sizeof(Pst));
740    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
741
742    GET_CELL_IDX(macUciInd->cellId, cellIdx);
743    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
744    srUciInd.crnti        = crnti;
745    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
746    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
747    srUciInd.numSrBits++;
748    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
749
750    /* Fill Pst */
751    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
752
753    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
754 }
755
756 /*******************************************************************
757  *
758  * @brief Processes UCI Indication from PHY
759  *
760  * @details
761  *
762  *    Function : fapiMacUciInd
763  *
764  *    Functionality:
765  *       Processes UCI Indication from PHY
766  *
767  * @params[in] Post Structure Pointer
768  *             UCI Indication Pointer
769  * @return ROK     - success
770  *         RFAILED - failure
771  *
772  * ****************************************************************/
773 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
774 {
775    uint8_t     pduIdx = 0;
776    uint8_t     ret = ROK;
777    uint16_t    nPdus;
778    uint16_t    crnti;
779
780    if(macUciInd)
781    {
782       nPdus = macUciInd->numUcis;
783       while(nPdus)
784       {
785          switch(macUciInd->pdus[pduIdx].pduType)
786          {
787             case UCI_IND_PUSCH:
788                break;
789             case UCI_IND_PUCCH_F0F1:
790                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
791                {
792                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
793                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
794                   ret = buildAndSendSrInd(macUciInd, crnti);
795                }
796                break;
797             case UCI_IND_PUCCH_F2F3F4:
798                break;
799             default:
800                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
801                ret = RFAILED;
802                break;
803          }
804          pduIdx++;
805          nPdus--;
806       }
807    }
808    else
809    {
810       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
811       ret = RFAILED;
812    }
813    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
814    return ret;
815 }
816
817 /*******************************************************************
818  *
819  * @brief fill Slice Cfg Request info in shared structre
820  * 
821  * @details
822  *
823  *    Function : fillSliceCfgInfo 
824  *
825  *    Functionality:
826  *       fill Slice Cfg Request info in shared structre
827  *
828  * @params[in] SchSliceCfgReq *schSliceCfgReq 
829  *             MacSliceCfgReq *macSliceCfgReq;
830  * @return ROK     - success
831  *         RFAILED - failure
832  *
833  **********************************************************************/
834  uint8_t fillSliceCfgInfo(SchSliceCfgReq *schSliceCfgReq, MacSliceCfgReq *macSliceCfgReq)
835  {
836     uint8_t cfgIdx = 0;
837     
838     if(macSliceCfgReq->listOfSliceCfg)
839     {
840        schSliceCfgReq->numOfConfiguredSlice =  macSliceCfgReq->numOfConfiguredSlice;
841        MAC_ALLOC(schSliceCfgReq->listOfConfirguration, schSliceCfgReq->numOfConfiguredSlice *sizeof(SchRrmPolicyOfSlice*));
842        if(schSliceCfgReq->listOfConfirguration == NULLP)
843        {
844           DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
845           return RFAILED;
846        }
847        for(cfgIdx = 0; cfgIdx<schSliceCfgReq->numOfConfiguredSlice; cfgIdx++)
848        {
849           MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx], sizeof(SchRrmPolicyOfSlice));
850           if(schSliceCfgReq->listOfConfirguration[cfgIdx] == NULLP)
851           {
852              DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
853              return RFAILED;
854           }
855           
856           memcpy(&schSliceCfgReq->listOfConfirguration[cfgIdx]->snssai, &macSliceCfgReq->listOfSliceCfg[cfgIdx]->snssai, sizeof(Snssai));
857
858           if(macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio)
859           {
860              MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo, sizeof(SchRrmPolicyRatio));
861              if(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo == NULLP)
862              {
863                 DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
864                 return RFAILED;
865              }
866              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMaxRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMaxRatio;
867              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMinRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMinRatio;
868              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyDedicatedRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyDedicatedRatio;
869           }
870        }
871     }
872     return ROK;
873  }
874 /*******************************************************************
875  *
876  * @brief Processes Slice Cfg Request recived from DU
877  *
878  * @details
879  *
880  *    Function : MacProcSliceCfgReq 
881  *
882  *    Functionality:
883  *       Processes Processes Slice Cfg Request recived from DU
884  *
885  * @params[in] Post Structure Pointer
886  *             MacSliceCfgReq *macSliceCfgReq;
887  * @return ROK     - success
888  *         RFAILED - failure
889  *
890  **********************************************************************/
891 uint8_t MacProcSliceCfgReq(Pst *pst, MacSliceCfgReq *macSliceCfgReq)
892 {
893    uint8_t ret = ROK;
894    Pst schPst;
895    SchSliceCfgReq *schSliceCfgReq;
896
897    DU_LOG("\nINFO  -->  MAC : Received Slice Cfg request from DU APP");
898    if(macSliceCfgReq)
899    {
900       MAC_ALLOC(schSliceCfgReq, sizeof(SchSliceCfgReq));
901       if(schSliceCfgReq == NULLP)
902       {
903          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceCfgReq");
904          ret = RFAILED;
905       }
906       else
907       {
908          if(fillSliceCfgInfo(schSliceCfgReq, macSliceCfgReq) == ROK)
909          {
910             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_CFG_REQ_TO_SCH);
911             ret = (*macSchSliceCfgReqOpts[schPst.selector])(&schPst, schSliceCfgReq);
912          }
913       }
914       freeMacSliceCfgReq(macSliceCfgReq, pst); 
915    }
916    else
917    {
918       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
919    }
920    return ret;
921 }
922
923 /*******************************************************************
924  *
925  * @brief Processes Slice ReCfg Request recived from DU
926  *
927  * @details
928  *
929  *    Function : MacProcSliceReCfgReq 
930  *
931  *    Functionality:
932  *       Processes Processes Slice ReCfg Request recived from DU
933  *
934  * @params[in] Post Structure Pointer
935  *             MacSliceCfgReq *macSliceReCfgReq;
936  * @return ROK     - success
937  *         RFAILED - failure
938  *
939  **********************************************************************/
940 uint8_t MacProcSliceReCfgReq(Pst *pst, MacSliceCfgReq *macSliceReCfgReq)
941 {
942    uint8_t ret = ROK;
943    Pst schPst;
944    SchSliceCfgReq *schSliceReCfgReq;
945
946    DU_LOG("\nINFO  -->  MAC : Received Slice ReCfg request from DU APP");
947    if(macSliceReCfgReq)
948    {
949       MAC_ALLOC(schSliceReCfgReq, sizeof(SchSliceCfgReq));
950       if(schSliceReCfgReq == NULLP)
951       {
952          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceReCfgReq");
953          ret = RFAILED;
954       }
955       else
956       {
957          if(fillSliceCfgInfo(schSliceReCfgReq, macSliceReCfgReq) == ROK)
958          {
959             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_RECFG_REQ_TO_SCH);
960             ret = (*macSchSliceReCfgReqOpts[schPst.selector])(&schPst, schSliceReCfgReq);
961          }
962
963       }
964       freeMacSliceCfgReq(macSliceReCfgReq, pst);
965    }
966    else
967    {
968       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
969    }
970    return ret;
971 }
972
973 /**********************************************************************
974   End of file
975  **********************************************************************/
976