[Epic-ID: ODUHIGH-488][Task-ID: ODUHIGH-501] Ue Create and Rsp correction in DUAPP...
[o-du/l2.git] / src / 5gnrmac / mac.h
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 #ifndef _MAC_H_
19 #define _MAC_H_
20
21 /* MAX values */
22 #define MAX_MAC_CE 6
23 #define MAX_CRI_SIZE 6
24 #define MAX_MAC_DL_PDU 16
25 #define MAX_NUM_HARQ_PROC  16
26 #define MAX_ZERO_CORR_CFG_IDX 16 /* max zero correlation config index */
27 #define MAC_TQ_SIZE    10        /* Timing Queue Size */
28 #define MAX_NUM_TIMER  1         /* MAX number of MAC timers */
29
30 #define DEFAULT_CELLS 1
31 #define SI_RNTI 0xFFFF
32 #define P_RNTI 0xFFFE
33
34 #define MAC_LCID_CCCH              0
35 #define MAC_LCID_MIN               1
36 #define MAC_LCID_MAX               32
37 #define MAC_LCID_RESERVED_MIN      33
38 #define MAC_LCID_RESERVED_MAX      51
39 #define MAC_LCID_CCCH_48BIT        52
40 #define MAC_LCID_BIT_RATE_QUERY    53
41 #define MAC_LCID_MULT_PHR_FOUR_OCT 54
42 #define MAC_LCID_CFG_GRANT_CFM     55
43 #define MAC_LCID_MULT_PHR_ONE_OCT  56
44 #define MAC_LCID_SINGLE_PHR        57
45 #define MAC_LCID_CRNTI             58
46 #define MAC_LCID_SHORT_TRUNC_BSR   59
47 #define MAC_LCID_LONG_TRUNC_BSR    60
48 #define MAC_LCID_SHORT_BSR         61
49 #define MAC_LCID_LONG_BSR          62
50 #define MAC_LCID_CRI               62
51 #define MAC_LCID_PADDING           63
52
53 /* Definitions for size of RAR PDU contents (in bits).
54  * Refer spec 38.321, sections 6.1.4, 6.2.2 and 6.2.3*/
55 #define E_BIT_SIZE 1
56 #define T_BIT_SIZE 1
57 #define R_BIT_SIZE 1
58 #define RAPID_SIZE 6
59 #define LC_ID_SIZE 6
60 #define TIMING_ADVANCE_SIZE 12
61 #define T_CRNTI_SIZE 16
62 /*  UL Grant is of size = 27 bits. Refer to Spec 38.213, Table 8.2-1 for
63  *  contents of UL grant in RAR */
64 #define FREQ_HOP_FLAG_SIZE 1
65 #define FREQ_RSRC_ALLOC_SIZE 14
66 #define TIME_RSRC_ALLOC_SIZE 4
67 #define MCS_SIZE 4
68 #define TPC_COMMAND_SIZE 3
69 #define CSI_REQUEST_SIZE 1
70
71 typedef struct macCellCb MacCellCb;
72
73 typedef enum
74 {
75    CELL_STATE_UP,
76    CELL_TO_BE_STOPPED,
77    CELL_STOP_IN_PROGRESS,
78 }MacCellStatus;    
79
80 typedef enum
81 {
82    UE_STATE_INACTIVE,
83    UE_STATE_ACTIVE,
84    UE_HANDIN_IN_PROGRESS
85 }UeState;
86
87 typedef enum
88 {
89    MAC_LC_STATE_INACTIVE,
90    MAC_LC_STATE_ACTIVE
91 }MacLcState;
92
93 typedef struct dlTbInfo
94 {
95    SlotTimingInfo  txTime;  
96    uint16_t        tbSize;
97    uint8_t         *tb;
98 }DlTbInfo;
99
100 /* DL HARQ Process Info */
101 typedef struct dlHarqProcCb
102 {
103    uint8_t     procId;                 /* HARQ Process Id */
104    uint8_t     numTb;                  /* Number of TB */
105    DlTbInfo    tbInfo[MAX_NUM_TB_PER_UE];  /* TB information */
106 }DlHarqProcCb;
107
108 typedef struct macDlSlot
109 {
110    DlSchedInfo dlInfo;
111    DlPageAlloc *pageAllocInfo;
112 }MacDlSlot;
113
114 typedef struct macUlSlot
115 {
116    UlSchedInfo  ulInfo;
117 }MacUlSlot;
118
119 typedef struct macCbInfo
120 {
121    uint16_t    cellId;
122    uint16_t    crnti;
123    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
124    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
125    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
126    DlHarqProcCb msg4HqInfo; /* HARQ process info for msg 4 */
127    bool         *macMsg4Status;
128 }MacRaCbInfo;
129
130 typedef struct macCe
131 {
132    uint16_t macCeLcid;
133    uint8_t  macCeValue[6];
134 }MacCe;
135
136 typedef struct macCeInfo
137 {
138    uint16_t numCes;
139    MacCe macCe[MAX_MAC_CE];
140 }MacCeInfo;
141
142 typedef struct macDlInfo
143 {
144    uint16_t  lcId;
145    uint16_t  pduLen;
146    uint8_t  *dlPdu;
147 }MacDlInfo;
148
149 typedef struct macDlData
150 {
151    uint8_t  ueId;
152    uint16_t numPdu;
153    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
154 }MacDlData;
155
156 /* DL HARQ entity */
157 typedef struct dlHarqEnt
158 {
159    uint8_t        maxReTx;            /* MAX HARQ retransmission */
160    uint8_t        numHarqProcs;       /* Number of HARQ procs */
161    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
162 }DlHarqEnt;
163
164 /* Uplink deidcated logical channel info */
165 typedef struct ulLcCb
166 {
167    uint8_t    lcId;         /* Logical Channel Id */
168    uint8_t    lcGrpId;      /* Logical Channel group */
169    MacLcState lcActive;     /* Is LC active ? */
170    /*Commenting as S-NSSAI and PDU session will be used in future scope*/
171    /*For eg: When we have to send these for AMBR cases*/
172    #if 0
173    uint16_t   pduSessionId; /*Pdu Session Id*/
174    Snssai     *snssai;      /*S-NSSAI assoc with LCID*/
175    #endif
176 }UlLcCb;
177
178 /* Downlink dedicated logical channel info */
179 typedef struct dlLcCb
180 {
181    uint8_t    lcId;        /* Logical channel Id */ 
182    MacLcState lcState;     /* Is LC active ? */
183    /*Commenting as S-NSSAI and PDU session will be used in future scope*/
184    /*For eg: When we have to send these info via FAPI to phy layer*/
185    #if 0
186    uint16_t   pduSessionId;/*Pdu Session Id*/
187    Snssai     *snssai;    /*S-NSSAI assoc with LCID*/
188    #endif
189 }DlLcCb;
190
191 /* BSR Information */
192 typedef struct macBsrTmrCfg
193 {
194    uint16_t   periodicTimer;
195    uint16_t   retxTimer;
196    uint16_t   srDelayTimer;
197 }MacBsrTmrCfg;
198
199 /* UE specific UL info */
200 typedef struct ueUlCb
201 {
202    uint8_t    maxReTx;     /* MAX HARQ retransmission */
203    uint8_t    numUlLc;     /* Number of uplink logical channels */       
204    UlLcCb     lcCb[MAX_NUM_LC];    /* Uplink dedicated logocal channels */
205 }UeUlCb;
206
207 /* UE specific DL Info */
208 typedef struct ueDlCb
209 {
210    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
211    uint8_t    numDlLc;        /* Number of downlink logical channels */
212    DlLcCb     lcCb[MAX_NUM_LC];  /* Downlink dedicated logical channels */
213 }UeDlCb;
214
215 /* UE Cb */
216 typedef struct macUeCb
217 {
218    uint16_t         ueId;           /* UE Id from DU APP */
219    uint16_t         crnti;          /* UE CRNTI */
220    MacCellCb        *cellCb;        /* Pointer to cellCb to whihc this UE belongs */
221    UeState          state;          /* Is UE active ? */
222    MacCfraResource  cfraResource;   /* CF-RA resource */
223    MacRaCbInfo      *raCb;          /* RA info */
224    MacBsrTmrCfg     bsrTmrCfg;      /* BSR Timer Info */
225    UeUlCb           ulInfo;         /* UE specific UL info */
226    UeDlCb           dlInfo;         /* UE specific DL info */
227    DataTransmissionAction transmissionAction;
228 }MacUeCb;
229
230 struct macCellCb
231 {
232    uint16_t        cellId;
233    uint16_t        numOfSlots;
234    MacCellStatus   state;
235    uint16_t        crntiMap;
236    MacRaCbInfo     macRaCb[MAX_NUM_UE];
237    MacDlSlot       dlSlot[MAX_SLOTS];
238    MacUlSlot       ulSlot[MAX_SLOTS];
239    uint16_t        numActvUe;
240    MacUeCreateReq  *ueCfgTmpData[MAX_NUM_UE];
241    MacUeRecfg      *ueRecfgTmpData[MAX_NUM_UE];
242    MacUeCb         ueCb[MAX_NUM_UE];
243    MacCellCfg      macCellCfg;
244    SlotTimingInfo  currTime;
245 };
246
247 typedef struct macCb
248 {
249    Inst        macInst;
250    ProcId      procId;
251    uint8_t     tmrRes;                    /*!< Timer resolution */
252    CmTqCp      tmrTqCp;                   /*!< Timer Task Queue Cntrl Point */
253    CmTqType    tmrTq[MAC_TQ_SIZE];        /*!< Timer Task Queue */
254    CmTimer     tmrBlk[MAX_NUM_TIMER];     /*!< Timer Block */
255    MacCellCb   *macCell[MAX_NUM_CELL];
256 }MacCb;
257
258 /* global variable */
259 MacCb macCb;
260
261 /* Function declarations */
262 uint8_t macActvInit ARGS((Ent entity, Inst inst, Region region, Reason reason));
263 uint8_t macActvTsk(Pst *pst, Buffer *mBuf);
264 short int macActvTmr(Ent ent,Inst inst);
265
266 void fillRarPdu(RarInfo *rarInfo);
267 void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu);
268 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
269 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
270 uint8_t unpackRxData(uint16_t cellId, SlotTimingInfo slotInfo, RxDataIndPdu *rxDataIndPdu);
271 void fillMg4Pdu(DlMsgSchInfo *msg4Alloc);
272 void buildAndSendMuxPdu(SlotTimingInfo currTimingInfo);
273 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer);
274 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize);
275 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, uint8_t lcId, uint16_t pduLen, uint8_t *pdu);
276 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx);
277 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg, DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS]);
278 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst);
279 void deleteMacRaCb(uint16_t cellIdx, MacUeCb *ueCb);
280
281 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp);
282 uint8_t MacProcSchSliceRecfgRsp(Pst *pst, SchSliceRecfgRsp *sliceRecfgrsp);
283 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm  *schCellCfgCfm);
284 uint8_t MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo);
285 uint8_t MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo);
286 uint8_t MacProcSchRachRsrcRsp(Pst *pst, SchRachRsrcRsp *schRachRsrcRsp);
287 uint8_t MacProcDlPageAlloc(Pst *pst, DlPageAlloc *dlPageAlloc);
288 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDeleteRsp);
289 #endif
290 /**********************************************************************
291   End of file
292  **********************************************************************/