[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-425] Changes in Ue Context Modification
[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    uint8_t ueId = 0;
190    uint16_t pduIdx, cellIdx = 0;
191    DU_LOG("\nDEBUG  -->  MAC : Received Rx Data indication");
192    /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
193     * PDU, which is stored in raCb */
194
195    for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
196    {
197      
198       GET_CELL_IDX(rxDataInd->cellId, cellIdx);
199       GET_UE_ID(rxDataInd->pdus[pduIdx].rnti, ueId);
200       
201       if(macCb.macCell[cellIdx] && macCb.macCell[cellIdx]->ueCb[ueId -1].transmissionAction == STOP_TRANSMISSION)
202       {
203          DU_LOG("\nINFO   -->  MAC : UL data transmission not allowed for UE %d", macCb.macCell[cellIdx]->ueCb[ueId -1].duUeF1apId);
204       }
205       else
206       {
207          unpackRxData(rxDataInd->cellId, rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
208       }
209       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd->pdus[pduIdx].pduData,\
210          rxDataInd->pdus[pduIdx].pduLength);
211    }
212    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd, sizeof(RxDataInd));
213    return ROK;
214 }
215
216 /*******************************************************************
217  *
218  * @brief Processes DL data from RLC
219  *
220  * @details
221  *
222  *    Function : MacProcRlcDlData 
223  *
224  *    Functionality:
225  *      Processes DL data from RLC
226  *
227  * @params[in] Post structure
228  *             DL data
229  * @return ROK     - success
230  *         RFAILED - failure
231  *
232  * ****************************************************************/
233 uint8_t MacProcRlcDlData(Pst* pstInfo, RlcData *dlData)
234 {
235    uint8_t   pduIdx = 0;
236    uint8_t   ueId  = 0;
237    uint8_t   lcIdx = 0;
238    uint8_t   *txPdu = NULLP;
239    uint8_t   schInfoIdx = 0 ;
240    uint16_t  cellIdx = 0, txPduLen = 0;
241    MacDlData macDlData;
242    MacDlSlot *currDlSlot = NULLP;
243    DlRlcBoInfo dlBoInfo;
244
245    memset(&macDlData , 0, sizeof(MacDlData));
246    DU_LOG("\nDEBUG  -->  MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
247       dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
248
249    GET_UE_ID(dlData->rnti, ueId);   
250
251    /* Copy the pdus to be muxed into mac Dl data */
252    macDlData.ueId = ueId;
253    macDlData.numPdu = dlData->numPdu;
254    for(pduIdx = 0;  pduIdx < dlData->numPdu; pduIdx++)
255    {
256       macDlData.pduInfo[pduIdx].lcId = dlData->pduInfo[pduIdx].lcId;
257       macDlData.pduInfo[pduIdx].pduLen = dlData->pduInfo[pduIdx].pduLen;
258       macDlData.pduInfo[pduIdx].dlPdu = dlData->pduInfo[pduIdx].pduBuf;
259    }
260
261    GET_CELL_IDX(dlData->cellId, cellIdx);
262    /* Store DL data in the scheduled slot */
263    if(macCb.macCell[cellIdx] ==NULLP)
264    {
265       DU_LOG("\nERROR  -->  MAC : MacProcRlcDlData(): macCell does not exists");
266       return RFAILED;
267    }
268    currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlData->slotInfo.slot];
269    if(currDlSlot->dlInfo.dlMsgAlloc[ueId-1])
270    {
271       for(schInfoIdx=0; schInfoIdx<currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->numSchedInfo; schInfoIdx++)
272       {
273          if((currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
274                (currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH))
275             break;
276       }
277
278       txPduLen = currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize\
279                  - TX_PAYLOAD_HDR_LEN;
280       MAC_ALLOC(txPdu, txPduLen);
281       if(!txPdu)
282       {
283          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in MacProcRlcDlData");
284          return RFAILED;
285       }
286       macMuxPdu(&macDlData, NULLP, txPdu, txPduLen);
287
288       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPduLen = txPduLen;
289       currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.dlMsgPdu = txPdu;
290    }
291
292    for(lcIdx = 0; lcIdx < dlData->numLc; lcIdx++)
293    {
294       if(dlData->boStatus[lcIdx].bo)
295       {
296          memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
297          dlBoInfo.cellId = dlData->boStatus[lcIdx].cellId;
298          GET_CRNTI(dlBoInfo.crnti, dlData->boStatus[lcIdx].ueId);
299          dlBoInfo.lcId = dlData->boStatus[lcIdx].lcId;
300          dlBoInfo.dataVolume = dlData->boStatus[lcIdx].bo;
301          sendDlRlcBoInfoToSch(&dlBoInfo);
302       }
303    }
304
305    /* Free memory */
306    for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
307    {
308       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData->pduInfo[pduIdx].pduBuf,\
309             dlData->pduInfo[pduIdx].pduLen);
310    }
311    if(pstInfo->selector == ODU_SELECTOR_LWLC)
312    {
313       MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData, sizeof(RlcData));
314    }
315    return ROK;
316 }
317
318 /*******************************************************************
319  *
320  * @brief Builds and Sends UL Data to RLC
321  *
322  * @details
323  *
324  *    Function : macProcUlData
325  *
326  *    Functionality: Builds and Sends UL Data to RLC
327  *
328  * @params[in] CellId
329  *             CRNTI
330  *             Slot information
331  *             LC Id on which payload was received
332  *             Pointer to the payload
333  *             Length of payload
334  * @return ROK     - success
335  *         RFAILED - failure
336  *
337  * ****************************************************************/
338 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
339 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
340 {
341    Pst         pst;
342    RlcData     *ulData;
343
344    /* Filling RLC Ul Data*/
345    MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcData));
346    if(!ulData)
347    {
348       DU_LOG("\nERROR  -->  MAC : Memory allocation failed while sending UL data to RLC");
349       return RFAILED;
350    }
351    memset(ulData, 0, sizeof(RlcData));
352    ulData->cellId = cellId; 
353    ulData->rnti = rnti;
354    memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotTimingInfo));
355    ulData->slotInfo.cellId = cellId;
356
357    /* Filling pdu info */
358    if(lcId == SRB1_LCID || lcId == SRB2_LCID)
359    {
360       ulData->pduInfo[ulData->numPdu].commCh = true;
361    }
362    ulData->pduInfo[ulData->numPdu].lcId = lcId;
363    ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
364    ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
365    ulData->numPdu++;
366
367    /* Filling Post and send to RLC */
368    memset(&pst, 0, sizeof(Pst));
369    FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
370    MacSendUlDataToRlc(&pst, ulData);
371
372    return ROK;
373 }
374
375
376 /*******************************************************************
377  *
378  * @brief Processes BO status from RLC
379  *
380  * @details
381  *
382  *    Function : MacProcRlcBOStatus
383  *
384  *    Functionality:
385  *      Processes BO status from RLC
386  *
387  * @params[in] Post structure
388  *             BO status
389  * @return ROK     - success
390  *         RFAILED - failure
391  *
392  * ****************************************************************/
393 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
394 {
395    DlRlcBoInfo  dlBoInfo;
396
397    dlBoInfo.cellId = boStatus->cellId;
398    GET_CRNTI(dlBoInfo.crnti, boStatus->ueId);
399    dlBoInfo.lcId = boStatus->lcId;
400    dlBoInfo.dataVolume = boStatus->bo;
401    
402    sendDlRlcBoInfoToSch(&dlBoInfo); 
403
404    if(pst->selector == ODU_SELECTOR_LWLC)
405    {
406       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
407    }
408
409    return ROK;
410 }
411
412 /*******************************************************************
413  *
414  * @brief Send LC schedule result report to RLC
415  *
416  * @details
417  *
418  *    Function : sendSchRptToRlc 
419  *
420  *    Functionality: Send LC schedule result report to RLC
421  *
422  * @params[in] 
423  * @return ROK     - success
424  *         RFAILED - failure
425  *
426  * ****************************************************************/
427 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx)
428 {
429    Pst      pst;
430    uint8_t  lcIdx;
431    RlcSchedResultRpt  *schedRpt = NULLP;
432    
433    MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
434    if(!schedRpt)
435    {
436       DU_LOG("\nERROR  -->  MAC: Memory allocation failure in sendSchResultRepToRlc");
437       return RFAILED;
438    }
439
440    DU_LOG("\nDEBUG  -->  MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
441    schedRpt->cellId = dlInfo.cellId;
442    schedRpt->slotInfo.sfn = slotInfo.sfn;
443    schedRpt->slotInfo.slot = slotInfo.slot;
444
445    if(dlInfo.dlMsgAlloc[ueIdx])
446    {
447       schedRpt->rnti = dlInfo.dlMsgAlloc[ueIdx]->crnti;
448       schedRpt->numLc = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].numLc;
449       for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
450       {
451          schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].lcId;
452          schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].lcSchInfo[lcIdx].schBytes;
453          schedRpt->lcSch[lcIdx].commCh = false;
454       }
455    }
456
457    /* Fill Pst */
458    FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
459    if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
460    {
461       DU_LOG("\nERROR  -->  MAC: Failed to send Schedule result report to RLC");
462       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
463       return RFAILED;
464    }
465
466    return ROK;
467 }
468
469 /*******************************************************************
470  *
471  * @brief Handles cell start reuqest from DU APP
472  *
473  * @details
474  *
475  *    Function : MacProcCellStart
476  *
477  *    Functionality:
478  *      Handles cell start reuqest from DU APP
479  *
480  * @params[in] Post structure pointer
481  *             Cell Id 
482  * @return ROK     - success
483  *         RFAILED - failure
484  *
485  * ****************************************************************/
486 uint8_t MacProcCellStart(Pst *pst, OduCellId  *cellId)
487 {
488    DU_LOG("\nINFO  -->  MAC : Handling cell start request");
489    gSlotCount = 0;
490    sendToLowerMac(START_REQUEST, 0, cellId);
491
492    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
493          sizeof(OduCellId));
494
495    return ROK;
496 }
497
498 /*******************************************************************
499  *
500  * @brief Handles cell stop from DU APP
501  *
502  * @details
503  *
504  *    Function : MacProcCellStop
505  *
506  *    Functionality:
507  *        Handles cell stop from DU APP
508  *
509  * @params[in] Post structure pointer
510  *             Cell Id
511  * @return ROK     - success
512  *         RFAILED - failure
513  *
514  * ****************************************************************/
515 uint8_t MacProcCellStop(Pst *pst, OduCellId  *cellId)
516 {
517 #ifdef INTEL_FAPI
518    uint16_t      cellIdx; 
519
520    DU_LOG("\nINFO  -->  MAC : Sending cell stop request to Lower Mac");
521    GET_CELL_IDX(cellId->cellId, cellIdx);
522    if(macCb.macCell[cellIdx])
523    {
524       macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
525    }
526 #endif
527
528    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, \
529          sizeof(OduCellId));
530
531    return ROK;
532 }
533
534 /*******************************************************************
535  *
536  * @brief Handles DL CCCH Ind from DU APP
537  *
538  * @details
539  *
540  *    Function : MacProcDlCcchInd 
541  *
542  *    Functionality:
543  *      Handles DL CCCH Ind from DU APP
544  *
545  * @params[in] Post structure pointer
546  *             DL CCCH Ind pointer 
547  * @return ROK     - success
548  *         RFAILED - failure
549  *
550  * ****************************************************************/
551 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
552 {
553    uint8_t      ueId = 0, ueIdx = 0;
554    uint16_t     cellIdx;
555    uint16_t     idx;
556    DlRlcBoInfo  dlBoInfo;
557    memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
558
559    DU_LOG("\nDEBUG  -->  MAC : Handling DL CCCH IND");
560
561    GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
562
563    dlBoInfo.cellId = dlCcchIndInfo->cellId;
564    dlBoInfo.crnti = dlCcchIndInfo->crnti;
565
566    if(dlCcchIndInfo->msgType == RRC_SETUP)
567    {
568       dlBoInfo.lcId = SRB0_LCID;    // SRB ID 0 for msg4
569       /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
570       dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
571
572       /* storing Msg4 Pdu in raCb */
573       GET_UE_ID(dlBoInfo.crnti, ueId);
574       ueIdx = ueId -1;
575       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
576       {
577          macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
578          MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
579             macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
580          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
581          {
582             for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
583             {
584                macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
585                   dlCcchIndInfo->dlCcchMsg[idx];
586             }
587          }
588       }
589    }
590    sendDlRlcBoInfoToSch(&dlBoInfo);
591
592    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
593          dlCcchIndInfo->dlCcchMsgLen);
594    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
595    return ROK;
596
597 }
598
599 /*******************************************************************
600  *
601  * @brief Sends UL CCCH Ind to DU APP
602  *
603  * @details
604  *
605  *    Function : macProcUlCcchInd
606  *
607  *    Functionality:
608  *        MAC sends UL CCCH Ind to DU APP
609  *
610  * @params[in] Post structure pointer
611  *            
612  * @return ROK     - success
613  *         RFAILED - failure
614  *
615  * ****************************************************************/
616 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
617 {
618    Pst pst;
619    uint8_t ret = ROK;
620    UlCcchIndInfo *ulCcchIndInfo = NULLP;
621
622    MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
623    if(!ulCcchIndInfo)
624    {
625       DU_LOG("\nERROR  -->  MAC: Memory failed in macProcUlCcchInd");
626       return RFAILED;
627    }
628
629    ulCcchIndInfo->cellId = cellId;
630    ulCcchIndInfo->crnti  = crnti;
631    ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
632    ulCcchIndInfo->ulCcchMsg = rrcContainer;
633
634    /* Fill Pst */
635    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
636
637    if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
638    {
639       DU_LOG("\nERROR  -->  MAC: Failed to send UL CCCH Ind to DU APP");
640       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
641       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
642       ret = RFAILED;
643    }
644    return ret;
645 }
646
647 /*******************************************************************
648  *
649  * @brief Processes received short BSR
650  *
651  * @details
652  *
653  *    Function : macProcShortBsr
654  *
655  *    Functionality:
656  *        MAC sends Short BSR to SCH
657  *
658  * @params[in] cell ID
659  *             crnti
660  *             lcg ID
661  *             buffer size
662  *
663  * @return ROK     - success
664  *         RFAILED - failure
665  *
666  * ****************************************************************/
667 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
668 {
669    Pst                  pst;
670    UlBufferStatusRptInd bsrInd;
671
672    memset(&pst, 0, sizeof(Pst));
673    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
674
675    bsrInd.cellId                 = cellId;
676    bsrInd.crnti                  = crnti;
677    bsrInd.bsrType                = SHORT_BSR;
678    bsrInd.numLcg                 = 1; /* short bsr reports one lcg at a time */
679    bsrInd.dataVolInfo[0].lcgId   = lcgId;
680    bsrInd.dataVolInfo[0].dataVol = bufferSize;
681
682    FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
683    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
684 }
685
686 /*******************************************************************
687  *
688  * @brief Processes received short BSR
689  *
690  * @details
691  *
692  *    Function : macProcShortBsr
693  *
694  *    Functionality:
695  *        MAC sends Short BSR to SCH
696  *
697  * @params[in] cell ID
698  *             crnti
699  *             lcg ID
700  *             buffer size
701  *
702  * @return ROK     - success
703  *         RFAILED - failure
704  *
705  * ****************************************************************/
706 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg,\
707                          DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
708 {
709    Pst                  pst;
710    UlBufferStatusRptInd bsrInd;
711    uint8_t lcgIdx = 0;
712
713    memset(&pst, 0, sizeof(Pst));
714    memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
715
716    bsrInd.cellId                 = cellId;
717    bsrInd.crnti                  = crnti;
718    bsrInd.bsrType                = LONG_BSR;
719    bsrInd.numLcg                 = numLcg; 
720
721    for(lcgIdx = 0; lcgIdx < numLcg; lcgIdx++)
722       memcpy(&(bsrInd.dataVolInfo[lcgIdx]), &(dataVolInfo[lcgIdx]), sizeof(DataVolInfo));
723
724    FILL_PST_MAC_TO_SCH(pst, EVENT_LONG_BSR);
725    return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
726 }
727
728 /*******************************************************************
729  *
730  * @brief Builds and send SR UCI Indication to SCH
731  *
732  * @details
733  *
734  *    Function : buildAndSendSrInd
735  *
736  *    Functionality:
737  *       Builds and send SR UCI Indication to SCH
738  *
739  * @params[in] SrUciIndInfo Pointer
740  *             crnti value
741  * @return ROK     - success
742  *         RFAILED - failure
743  *
744  * ****************************************************************/
745 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
746 {
747    uint16_t cellIdx;
748    Pst pst;
749    SrUciIndInfo   srUciInd;
750    memset(&pst, 0, sizeof(Pst));
751    memset(&srUciInd, 0, sizeof(SrUciIndInfo));
752
753    GET_CELL_IDX(macUciInd->cellId, cellIdx);
754    srUciInd.cellId       = macCb.macCell[cellIdx]->cellId;
755    srUciInd.crnti        = crnti;
756    srUciInd.slotInd.sfn  = macUciInd->slotInd.sfn;
757    srUciInd.slotInd.slot = macUciInd->slotInd.slot;
758    srUciInd.numSrBits++;
759    memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
760
761    /* Fill Pst */
762    FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
763
764    return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
765 }
766
767 /*******************************************************************
768  *
769  * @brief Processes UCI Indication from PHY
770  *
771  * @details
772  *
773  *    Function : fapiMacUciInd
774  *
775  *    Functionality:
776  *       Processes UCI Indication from PHY
777  *
778  * @params[in] Post Structure Pointer
779  *             UCI Indication Pointer
780  * @return ROK     - success
781  *         RFAILED - failure
782  *
783  * ****************************************************************/
784 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
785 {
786    uint8_t     pduIdx = 0, ret = ROK;
787    uint16_t    nPdus = 0, crnti = 0;
788
789    if(macUciInd)
790    {
791       nPdus = macUciInd->numUcis;
792       while(nPdus)
793       {
794          switch(macUciInd->pdus[pduIdx].pduType)
795          {
796             case UCI_IND_PUSCH:
797                break;
798             case UCI_IND_PUCCH_F0F1:
799                if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
800                {
801                   DU_LOG("\nDEBUG  -->  MAC : Received SR UCI indication");
802                   crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti; 
803                   ret = buildAndSendSrInd(macUciInd, crnti);
804                }
805                break;
806             case UCI_IND_PUCCH_F2F3F4:
807                break;
808             default:
809                DU_LOG("\nERROR  -->  MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
810                ret = RFAILED;
811                break;
812          }
813          pduIdx++;
814          nPdus--;
815       }
816    }
817    else
818    {
819       DU_LOG("\nERROR  -->  MAC: Received Uci Ind is NULL at FapiMacUciInd()");
820       ret = RFAILED;
821    }
822    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
823    return ret;
824 }
825
826 /*******************************************************************
827  *
828  * @brief fill Slice Cfg Request info in shared structre
829  * 
830  * @details
831  *
832  *    Function : fillSliceCfgInfo 
833  *
834  *    Functionality:
835  *       fill Slice Cfg Request info in shared structre
836  *
837  * @params[in] SchSliceCfgReq *schSliceCfgReq 
838  *             MacSliceCfgReq *macSliceCfgReq;
839  * @return ROK     - success
840  *         RFAILED - failure
841  *
842  **********************************************************************/
843  uint8_t fillSliceCfgInfo(SchSliceCfgReq *schSliceCfgReq, MacSliceCfgReq *macSliceCfgReq)
844  {
845     uint8_t cfgIdx = 0;
846     
847     if(macSliceCfgReq->listOfSliceCfg)
848     {
849        schSliceCfgReq->numOfConfiguredSlice =  macSliceCfgReq->numOfConfiguredSlice;
850        MAC_ALLOC(schSliceCfgReq->listOfConfirguration, schSliceCfgReq->numOfConfiguredSlice *sizeof(SchRrmPolicyOfSlice*));
851        if(schSliceCfgReq->listOfConfirguration == NULLP)
852        {
853           DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
854           return RFAILED;
855        }
856        for(cfgIdx = 0; cfgIdx<schSliceCfgReq->numOfConfiguredSlice; cfgIdx++)
857        {
858           MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx], sizeof(SchRrmPolicyOfSlice));
859           if(schSliceCfgReq->listOfConfirguration[cfgIdx] == NULLP)
860           {
861              DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
862              return RFAILED;
863           }
864           
865           memcpy(&schSliceCfgReq->listOfConfirguration[cfgIdx]->snssai, &macSliceCfgReq->listOfSliceCfg[cfgIdx]->snssai, sizeof(Snssai));
866
867           if(macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio)
868           {
869              MAC_ALLOC(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo, sizeof(SchRrmPolicyRatio));
870              if(schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo == NULLP)
871              {
872                 DU_LOG("\nERROR  -->  MAC : Memory allocation failed in fillSliceCfgInfo");
873                 return RFAILED;
874              }
875              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMaxRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMaxRatio;
876              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyMinRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMinRatio;
877              schSliceCfgReq->listOfConfirguration[cfgIdx]->rrmPolicyRatioInfo->policyDedicatedRatio = macSliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyDedicatedRatio;
878           }
879        }
880     }
881     return ROK;
882  }
883 /*******************************************************************
884  *
885  * @brief Processes Slice Cfg Request recived from DU
886  *
887  * @details
888  *
889  *    Function : MacProcSliceCfgReq 
890  *
891  *    Functionality:
892  *       Processes Processes Slice Cfg Request recived from DU
893  *
894  * @params[in] Post Structure Pointer
895  *             MacSliceCfgReq *macSliceCfgReq;
896  * @return ROK     - success
897  *         RFAILED - failure
898  *
899  **********************************************************************/
900 uint8_t MacProcSliceCfgReq(Pst *pst, MacSliceCfgReq *macSliceCfgReq)
901 {
902    uint8_t ret = ROK;
903    Pst schPst;
904    SchSliceCfgReq *schSliceCfgReq;
905
906    DU_LOG("\nINFO  -->  MAC : Received Slice Cfg request from DU APP");
907    if(macSliceCfgReq)
908    {
909       MAC_ALLOC(schSliceCfgReq, sizeof(SchSliceCfgReq));
910       if(schSliceCfgReq == NULLP)
911       {
912          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceCfgReq");
913          ret = RFAILED;
914       }
915       else
916       {
917          if(fillSliceCfgInfo(schSliceCfgReq, macSliceCfgReq) == ROK)
918          {
919             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_CFG_REQ_TO_SCH);
920             ret = (*macSchSliceCfgReqOpts[schPst.selector])(&schPst, schSliceCfgReq);
921          }
922       }
923       freeMacSliceCfgReq(macSliceCfgReq, pst); 
924    }
925    else
926    {
927       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
928    }
929    return ret;
930 }
931
932 /*******************************************************************
933  *
934  * @brief Processes Slice ReCfg Request recived from DU
935  *
936  * @details
937  *
938  *    Function : MacProcSliceReCfgReq 
939  *
940  *    Functionality:
941  *       Processes Processes Slice ReCfg Request recived from DU
942  *
943  * @params[in] Post Structure Pointer
944  *             MacSliceCfgReq *macSliceReCfgReq;
945  * @return ROK     - success
946  *         RFAILED - failure
947  *
948  **********************************************************************/
949 uint8_t MacProcSliceReCfgReq(Pst *pst, MacSliceCfgReq *macSliceReCfgReq)
950 {
951    uint8_t ret = ROK;
952    Pst schPst;
953    SchSliceCfgReq *schSliceReCfgReq;
954
955    DU_LOG("\nINFO  -->  MAC : Received Slice ReCfg request from DU APP");
956    if(macSliceReCfgReq)
957    {
958       MAC_ALLOC(schSliceReCfgReq, sizeof(SchSliceCfgReq));
959       if(schSliceReCfgReq == NULLP)
960       {
961          DU_LOG("\nERROR -->  MAC : Memory allocation failed in MacProcSliceReCfgReq");
962          ret = RFAILED;
963       }
964       else
965       {
966          if(fillSliceCfgInfo(schSliceReCfgReq, macSliceReCfgReq) == ROK)
967          {
968             FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_RECFG_REQ_TO_SCH);
969             ret = (*macSchSliceReCfgReqOpts[schPst.selector])(&schPst, schSliceReCfgReq);
970          }
971
972       }
973       freeMacSliceCfgReq(macSliceReCfgReq, pst);
974    }
975    else
976    {
977       DU_LOG("\nINFO  -->  MAC : Received MacSliceCfgReq is NULL");
978    }
979    return ret;
980 }
981
982 /**********************************************************************
983   End of file
984  **********************************************************************/
985