Merge "Deleted the rlog folder"
[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 typedef struct macCellCb MacCellCb;
54
55 typedef enum
56 {
57    UE_STATE_INACTIVE,
58    UE_STATE_ACTIVE
59 }UeState;
60
61 typedef enum
62 {
63    MAC_LC_STATE_INACTIVE,
64    MAC_LC_STATE_ACTIVE
65 }MacLcState;
66
67 typedef struct macDlSlot
68 {
69    DlSchedInfo dlInfo;
70 }MacDlSlot;
71
72 typedef struct macUlSlot
73 {
74    UlSchedInfo  ulInfo;
75 }MacUlSlot;
76
77 typedef struct macCbInfo
78 {
79    uint16_t    cellId;
80    uint16_t    crnti;
81    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
82    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
83    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
84    uint8_t     *msg4TxPdu;  /* muxed Pdu used for re-transmission */
85    uint16_t    msg4TbSize;  /* size required for msg4TxPdu */
86 }MacRaCbInfo;
87
88 typedef struct macCe
89 {
90    uint16_t macCeLcid;
91    uint8_t  macCeValue[6];
92 }MacCe;
93
94 typedef struct macCeInfo
95 {
96    uint16_t numCes;
97    MacCe macCe[MAX_MAC_CE];
98 }MacCeInfo;
99
100 typedef struct macDlInfo
101 {
102    uint16_t  lcId;
103    uint16_t  pduLen;
104    uint8_t  *dlPdu;
105 }MacDlInfo;
106
107 typedef struct macDlData
108 {
109    uint16_t numPdu;
110    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
111 }MacDlData;
112
113 /* HARQ Process Info */
114 typedef struct dlHarqProcCb
115 {
116    uint8_t   procId;    /* HARQ Process Id */
117 }DlHarqProcCb;
118
119 /* DL HARQ entity */
120 typedef struct dlHarqEnt
121 {
122    uint8_t        maxReTx;            /* MAX HARQ retransmission */
123    uint8_t        numHarqProcs;       /* Number of HARQ procs */
124    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
125 }DlHarqEnt;
126
127 /* Uplink deidcated logical channel info */
128 typedef struct ulLcCb
129 {
130    uint8_t   lcId;      /* Logical Channel Id */
131    uint8_t   lcGrpId;   /* Logical Channel group */
132    MacLcState lcActive;  /* Is LC active ? */
133 }UlLcCb;
134
135 /* Downlink dedicated logical channel info */
136 typedef struct dlLcCb
137 {
138    uint8_t   lcId;      /* Logical channel Id */ 
139    MacLcState   lcState;  /* Is LC active ? */
140 }DlLcCb;
141
142 /* BSR Information */
143 typedef struct macBsrTmrCfg
144 {
145    uint16_t   periodicTimer;
146    uint16_t   retxTimer;
147    uint16_t   srDelayTimer;
148 }MacBsrTmrCfg;
149
150 /* UE specific UL info */
151 typedef struct ueUlCb
152 {
153    uint8_t    maxReTx;     /* MAX HARQ retransmission */
154    uint8_t    numUlLc;     /* Number of uplink logical channels */       
155    UlLcCb     lcCb[MAX_NUM_LC];    /* Uplink dedicated logocal channels */
156 }UeUlCb;
157
158 /* UE specific DL Info */
159 typedef struct ueDlCb
160 {
161    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
162    uint8_t    numDlLc;        /* Number of downlink logical channels */
163    DlLcCb     lcCb[MAX_NUM_LC];  /* Downlink dedicated logical channels */
164 }UeDlCb;
165
166 /* UE Cb */
167 typedef struct macUeCb
168 {
169    uint16_t     ueIdx;    /* UE Idx assigned by DU APP */
170    uint16_t     crnti;    /* UE CRNTI */
171    MacCellCb    *cellCb;  /* Pointer to cellCb to whihc this UE belongs */
172    UeState      state;    /* Is UE active ? */
173    MacRaCbInfo  *raCb;    /* RA info */
174    MacBsrTmrCfg bsrTmrCfg;  /* BSR Timer Info */
175    UeUlCb       ulInfo;   /* UE specific UL info */
176    UeDlCb       dlInfo;   /* UE specific DL info */
177 }MacUeCb;
178
179 struct macCellCb
180 {
181    uint16_t    cellId;
182    uint8_t     crntiMap;
183    MacRaCbInfo macRaCb[MAX_NUM_UE];
184    MacDlSlot   dlSlot[MAX_SLOTS];
185    MacUlSlot   ulSlot[MAX_SLOTS];
186    uint16_t    numActvUe;
187    MacUeCfg    *ueCfgTmpData[MAX_NUM_UE];
188    MacUeCb     ueCb[MAX_NUM_UE];
189    MacCellCfg  macCellCfg;
190    SlotIndInfo currTime;
191 };
192
193 typedef struct macCb
194 {
195    Inst       macInst;
196    ProcId     procId;
197    uint8_t    tmrRes;                    /*!< Timer resolution */
198    CmTqCp     tmrTqCp;                   /*!< Timer Task Queue Cntrl Point */
199    CmTqType   tmrTq[MAC_TQ_SIZE];        /*!< Timer Task Queue */
200    CmTimer    tmrBlk[MAX_NUM_TIMER];     /*!< Timer Block */
201    MacCellCb  *macCell[MAX_NUM_CELL];
202 }MacCb;
203
204 /* global variable */
205 MacCb macCb;
206
207 /* Function declarations */
208 short int macActvTmr(Ent ent,Inst inst);
209 void fillRarPdu(RarInfo *rarInfo);
210 void createMacRaCb(RachIndInfo *rachIndInfo);
211 void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu);
212 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
213 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
214 uint8_t unpackRxData(uint16_t cellId, SlotIndInfo slotInfo, RxDataIndPdu *rxDataIndPdu);
215 void fillMg4Pdu(DlMsgAlloc *msg4Alloc);
216 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo);
217 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer);
218 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize);
219 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotIndInfo slotInfo, \
220    uint8_t lcId, uint16_t pduLen, uint8_t *pdu);
221 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotIndInfo slotInfo);
222 #endif
223 /**********************************************************************
224   End of file
225  **********************************************************************/