Merge "RLC DL UMD PDU changes [Issue-ID: ODUHIGH-271]"
[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_SLOT_SUPPORTED    10 /* numerology 0 15Khz */
27 #define MAX_ZERO_CORR_CFG_IDX 16 /* max zero correlation config index */
28
29 #define DEFAULT_CELLS 1
30 #define SI_RNTI 0xFFFF
31 #define P_RNTI 0xFFFE
32
33 #define MAC_LCID_CCCH              0
34 #define MAC_LCID_MIN               1
35 #define MAC_LCID_MAX               32
36 #define MAC_LCID_RESERVED_MIN      33
37 #define MAC_LCID_RESERVED_MAX      51
38 #define MAC_LCID_CCCH_48BIT        52
39 #define MAC_LCID_BIT_RATE_QUERY    53
40 #define MAC_LCID_MULT_PHR_FOUR_OCT 54
41 #define MAC_LCID_CFG_GRANT_CFM     55
42 #define MAC_LCID_MULT_PHR_ONE_OCT  56
43 #define MAC_LCID_SINGLE_PHR        57
44 #define MAC_LCID_CRNTI             58
45 #define MAC_LCID_SHORT_TRUNC_BSR   59
46 #define MAC_LCID_LONG_TRUNC_BSR    60
47 #define MAC_LCID_SHORT_BSR         61
48 #define MAC_LCID_LONG_BSR          62
49 #define MAC_LCID_CRI               62
50 #define MAC_LCID_PADDING           63
51
52 typedef struct macCellCb MacCellCb;
53
54 typedef enum
55 {
56    UE_STATE_INACTIVE,
57    UE_STATE_ACTIVE
58 }UeState;
59
60 typedef enum
61 {
62    MAC_LC_STATE_INACTIVE,
63    MAC_LC_STATE_ACTIVE
64 }MacLcState;
65
66 typedef struct macDlSlot
67 {
68    DlSchedInfo dlInfo;
69 }MacDlSlot;
70
71 typedef struct macUlSlot
72 {
73    UlSchedInfo  ulInfo;
74 }MacUlSlot;
75
76 typedef struct macCbInfo
77 {
78    uint16_t    cellId;
79    uint16_t    crnti;
80    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
81    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
82    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
83    uint8_t     *msg4TxPdu;  /* muxed Pdu used for re-transmission */
84    uint16_t    msg4TbSize;  /* size required for msg4TxPdu */
85 }MacRaCbInfo;
86
87 typedef struct macCe
88 {
89    uint16_t macCeLcid;
90    uint8_t  macCeValue[6];
91 }MacCe;
92
93 typedef struct macCeInfo
94 {
95    uint16_t numCes;
96    MacCe macCe[MAX_MAC_CE];
97 }MacCeInfo;
98
99 typedef struct macDlInfo
100 {
101    uint16_t  lcId;
102    uint16_t  pduLen;
103    uint8_t  *dlPdu;
104 }MacDlInfo;
105
106 typedef struct macDlData
107 {
108    uint16_t numPdu;
109    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
110 }MacDlData;
111
112 /* HARQ Process Info */
113 typedef struct dlHarqProcCb
114 {
115    uint8_t   procId;    /* HARQ Process Id */
116 }DlHarqProcCb;
117
118 /* DL HARQ entity */
119 typedef struct dlHarqEnt
120 {
121    uint8_t        maxReTx;            /* MAX HARQ retransmission */
122    uint8_t        numHarqProcs;       /* Number of HARQ procs */
123    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
124 }DlHarqEnt;
125
126 /* Uplink deidcated logical channel info */
127 typedef struct ulLcCb
128 {
129    uint8_t   lcId;      /* Logical Channel Id */
130    uint8_t   lcGrpId;   /* Logical Channel group */
131    MacLcState lcActive;  /* Is LC active ? */
132 }UlLcCb;
133
134 /* Downlink dedicated logical channel info */
135 typedef struct dlLcCb
136 {
137    uint8_t   lcId;      /* Logical channel Id */ 
138    MacLcState   lcState;  /* Is LC active ? */
139 }DlLcCb;
140
141 /* BSR Information */
142 typedef struct macBsrTmrCfg
143 {
144    uint16_t   periodicTimer;
145    uint16_t   retxTimer;
146    uint16_t   srDelayTimer;
147 }MacBsrTmrCfg;
148
149 /* UE specific UL info */
150 typedef struct ueUlCb
151 {
152    uint8_t    maxReTx;     /* MAX HARQ retransmission */
153    uint8_t    numUlLc;     /* Number of uplink logical channels */       
154    UlLcCb     lcCb[MAX_NUM_LC];    /* Uplink dedicated logocal channels */
155 }UeUlCb;
156
157 /* UE specific DL Info */
158 typedef struct ueDlCb
159 {
160    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
161    uint8_t    numDlLc;        /* Number of downlink logical channels */
162    DlLcCb     lcCb[MAX_NUM_LC];  /* Downlink dedicated logical channels */
163 }UeDlCb;
164
165 /* UE Cb */
166 typedef struct macUeCb
167 {
168    uint16_t     ueIdx;    /* UE Idx assigned by DU APP */
169    uint16_t     crnti;    /* UE CRNTI */
170    MacCellCb    *cellCb;  /* Pointer to cellCb to whihc this UE belongs */
171    UeState      state;    /* Is UE active ? */
172    MacRaCbInfo  *raCb;    /* RA info */
173    MacBsrTmrCfg bsrTmrCfg;  /* BSR Timer Info */
174    UeUlCb       ulInfo;   /* UE specific UL info */
175    UeDlCb       dlInfo;   /* UE specific DL info */
176 }MacUeCb;
177
178 struct macCellCb
179 {
180    uint16_t    cellId;
181    uint8_t     crntiMap;
182    MacRaCbInfo macRaCb[MAX_NUM_UE];
183    MacDlSlot   dlSlot[MAX_SLOT_SUPPORTED];
184    MacUlSlot   ulSlot[MAX_SLOT_SUPPORTED];
185    uint16_t    numActvUe;
186    MacUeCfg    *ueCfgTmpData[MAX_NUM_UE];
187    MacUeCb     ueCb[MAX_NUM_UE];
188    MacCellCfg  macCellCfg;
189    SlotIndInfo currTime;
190 };
191
192 typedef struct macCb
193 {
194    Inst       macInst;
195    ProcId     procId;
196    MacCellCb  *macCell[MAX_NUM_CELL];
197 }MacCb;
198
199 /* global variable */
200 MacCb macCb;
201
202 /* Function declarations */
203 void fillRarPdu(RarInfo *rarInfo);
204 void createMacRaCb(RachIndInfo *rachIndInfo);
205 void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu);
206 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
207 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
208 uint8_t unpackRxData(uint16_t cellId, SlotIndInfo slotInfo, RxDataIndPdu *rxDataIndPdu);
209 void fillMg4Pdu(DlMsgAlloc *msg4Alloc);
210 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo);
211 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer);
212 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize);
213 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotIndInfo slotInfo, \
214    uint8_t lcId, uint16_t pduLen, uint8_t *pdu);
215 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotIndInfo slotInfo);
216 #endif
217 /**********************************************************************
218   End of file
219  **********************************************************************/