f0b851cfbdc3e3ef6b7f94fa3bd8b1a1441f92b8
[o-du/l2.git] / src / cu_stub / cu_stub.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
19 #ifndef __CU_MGR_MAIN_H__
20 #define __CU_MGR_MAIN_H__
21
22 #define CU_ID 1
23 #define CU_NAME "ORAN OAM CU"
24
25 #define DU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0001"
26 #define CU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0011"
27
28 #ifndef O1_ENABLE
29 #define DU_IP_V4_ADDR (char*[]){"192.168.130.81", "192.168.130.83"}
30 #define DU_SCTP_PORT (int[]){38472, 38473}
31
32 #define CU_IP_V4_ADDR "192.168.130.82"
33 #define CU_SCTP_PORT_TO_DU (int[]){38472, 38473}
34 #endif
35
36 #define DU_EGTP_PORT  (int[]){39001, 39002}
37 #define CU_EGTP_PORT (int[]){39003, 39004}
38 #define RRC_VER 0
39 #define EXT_RRC_VER 5
40 #define PLMN_MCC0 3
41 #define PLMN_MCC1 1
42 #define PLMN_MCC2 1
43 #define PLMN_MNC0 4
44 #define PLMN_MNC1 8
45 #define PLMN_MNC2 0
46
47 #define CU_DU_NAME_LEN_MAX 30      /* Max length of CU/DU name string */
48
49 #define CU_APP_MEM_REG 1
50 #define CU_POOL 1
51
52 #define MAX_NUM_OF_SLICE 1024 /* As per the spec 38.473, maxnoofSliceItems = 1024*/
53 #define MAX_QOS_FLOWS 64 /* As per the spec 38.331, maxNrofQFIs = 64 */
54
55 /* allocate and zero out a static buffer */
56
57 #define CU_ALLOC(_datPtr, _size)                             \
58 {                                                            \
59    S16 _ret;                                                 \
60    _ret = SGetSBuf(CU_APP_MEM_REG, CU_POOL,                  \
61                      (Data **)&_datPtr, _size);              \
62    if(_ret == ROK)                                           \
63       memset(_datPtr, 0, _size);                      \
64    else                                                      \
65       _datPtr = NULLP;                                       \
66 }
67  
68 /* free a static buffer */
69 #define CU_FREE(_datPtr, _size)                              \
70    if(_datPtr)                                               \
71    SPutSBuf(CU_APP_MEM_REG, CU_POOL,                         \
72          (Data *)_datPtr, _size);
73
74 #define SEARCH_DU_DB(_duIdx, _duId, _duDb){\
75    _duDb = NULLP; \
76    for(_duIdx=0; _duIdx < cuCb.numDu; _duIdx++)\
77    {\
78       if(cuCb.duInfo[_duIdx].duId == _duId)\
79       {\
80          _duDb =  (&cuCb.duInfo[_duIdx]);\
81          break; \
82      }\
83    }\
84 }
85
86 #define SEARCH_CELL_DB(_cellIdx, _duDb, _nrCellId, _cellCb){\
87    _cellCb = NULLP; \
88    for(_cellIdx=0; _cellIdx < _duDb->numCells; _cellIdx++)\
89    {\
90       if(_duDb->cellCb[_cellIdx].nrCellId == _nrCellId)\
91       {\
92          _cellCb = (&(_duDb->cellCb[_cellIdx]));\
93          break;\
94       }\
95    }\
96 }
97
98 #ifdef NR_DRX
99 /* Set this parameter true of false as per the need to enable or disable drx of
100  * a particular UE */
101 #define DRX_TO_BE_RELEASE true 
102 #endif
103
104 typedef enum
105 {
106    CELL_INACTIVE,
107    CELL_ACTIVE,
108    CELL_DELETION_IN_PROGRESS
109 }CellStatusInfo;
110
111 typedef enum
112 {
113    UE_IDLE,
114    UE_ATTACH_IN_PROGRESS,
115    UE_ACTIVE,
116    UE_HANDOVER_IN_PROGRESS
117 }UeState;
118
119 typedef struct RrcVersion
120 {
121   uint8_t    rrcVer;     /* Latest RRC Version */
122   uint32_t   extRrcVer;  /* Latest RRC version extended */
123 }RrcVersion;
124
125 typedef struct cuCfgParams
126 {
127    uint32_t         cuId;
128    char             cuName[CU_DU_NAME_LEN_MAX];
129    CuSctpParams     sctpParams;
130    Plmn             plmn;
131    CuEgtpParams     egtpParams;
132    RrcVersion       rrcVersion;
133 }CuCfgParams;
134
135 typedef struct handoverInfo
136 {
137    uint32_t sourceDuId;
138    uint32_t targetDuId;
139 }HandoverInfo;
140
141 typedef struct dlAmCfg
142 {
143    uint8_t        snLenDl;              /* Sequence Number length in bits. Allowed values are 12 and 18 */
144    int8_t         reAssemTmr;           /* T_reassembling Timer in msec*/
145    int16_t        statProhTmr;          /* T_status_prohibit Timer in msec*/
146 }DlAmCfg;
147
148 typedef struct ulAmCfg
149 {
150    uint8_t      snLenUl;             /* Sequence Number length in bits. Allowed values are 12 and 18 */
151    uint16_t     pollRetxTmr;         /* T_poll_retransmit Timer in msec */
152    int16_t      pollPdu;             /* Used to trigger a poll for every pollPdu.*/
153    int32_t      pollByte;            /* Poll_Byte in bytes. */
154    uint8_t      maxRetxTh;           /* Max_Retx_Threshold */
155 }UlAmCfg;
156
157 typedef struct amBearerCfg
158 {
159    UlAmCfg  ulAmCfg;
160    DlAmCfg  dlAmCfg;
161 }AmBearerCfg;
162
163 typedef struct ulUmCfg
164 {
165    uint8_t        snLenUlUm;             /* Sequence Number length in bits. Allowed values are 6 and 12 */
166 }UlUmCfg;
167
168 typedef struct dlUmCfg
169 {
170    uint8_t        snLenDlUm;             /* Sequence Number length in bits. Allowed values are 6 and 12 */
171    int8_t         reAssemTmr;            /* T_reassembling Timer in msec*/
172 }DlUmCfg;
173
174 typedef struct umBiDirBearerCfg
175 {
176    UlUmCfg  ulUmCfg;
177    DlUmCfg  dlUmCfg;
178 }UmBiDirBearerCfg;
179
180 typedef struct umUniDirUlBearerCfg
181 {
182    UlUmCfg  ulUmCfg;
183 }UmUniDirUlBearerCfg;
184
185 typedef struct umUniDirDlBearerCfg
186 {
187    DlUmCfg  dlUmCfg;
188 }UmUniDirDlBearerCfg;
189
190 typedef struct rlcLcCfg
191 {
192    uint8_t rlcMode;
193    union
194    {   
195       AmBearerCfg         amCfg;
196       UmBiDirBearerCfg    umBiDirCfg;
197       UmUniDirUlBearerCfg umUniDirUlCfg;
198       UmUniDirDlBearerCfg umUniDirDlCfg;
199    }u; 
200 }RlcLcCfg;
201
202 typedef struct macLcCfg
203 {
204    uint8_t priority;
205    uint8_t lcGroup;
206    uint8_t schReqId;
207    uint8_t pbr;        // prioritisedBitRate
208    uint8_t bsd;        // bucketSizeDuration
209 }MacLcCfg;
210
211 typedef struct srbInfo
212 {
213    uint8_t   srbId;
214    uint8_t   lcId;
215    RlcLcCfg  rlcLcCfg;
216    MacLcCfg  macLcCfg;
217    bool      cfgSentToUe;
218 }SrbInfo;
219
220 typedef struct qosInfo
221 {
222    uint8_t nonDynFiveQI;
223    uint16_t avgWindow;
224    uint16_t maxBurstDataVol;
225    uint8_t priorityLevel;
226    uint8_t preemptionCapability;
227    uint8_t preemptionVulnerability;
228    uint8_t pduSessionId;
229 }QosInfo;
230
231 typedef struct flowsMapped
232 {
233    uint8_t qosFlowId;
234    QosInfo qos;
235 }FlowsMapped;
236
237 typedef struct TnlInfo
238 {
239    uint8_t address[4];
240    uint8_t teId[4];
241 }TnlInfo;
242
243 typedef struct drbInfo
244 {
245    uint8_t drbId;
246    uint8_t lcId;
247    QosInfo qos;
248    Snssai *snssai;
249    uint8_t numFlowMap;
250    FlowsMapped flowMapList[MAX_QOS_FLOWS];
251    TnlInfo ulUpTnlInfo;
252    TnlInfo dlUpTnlInfo;
253    uint8_t rlcMode;
254    RlcLcCfg  rlcLcCfg;
255    MacLcCfg  macLcCfg;
256    bool      cfgSentToUe;
257 }DrbInfo;
258
259 typedef struct cuCellCb CuCellCb;
260
261 #ifdef NR_DRX
262 /* The following list of structures is taken from the DRX-Config section of specification 33.331. */
263 typedef struct drxOnDurationTimer
264 {
265    bool  onDurationTimerValInMs;
266    union
267    {
268       uint8_t  subMilliSeconds;
269       uint16_t milliSeconds;
270    }onDurationtimerValue;
271 }DrxOnDurationTimer;
272
273 typedef struct drxLongCycleStartOffset
274 {
275    uint16_t drxLongCycleStartOffsetChoice;
276    uint16_t drxLongCycleStartOffsetVal;
277 }DrxLongCycleStartOffset;
278
279 typedef struct shortDrx
280 {
281    uint16_t   drxShortCycle;
282    uint8_t    drxShortCycleTimer;
283 }ShortDrx;
284
285 typedef struct drxCfg
286 {
287    DrxOnDurationTimer       drxOnDurationTimer;
288    uint16_t                 drxInactivityTimer;
289    uint8_t                  drxHarqRttTimerDl;
290    uint8_t                  drxHarqRttTimerUl;
291    uint16_t                 drxRetransmissionTimerDl;
292    uint16_t                 drxRetransmissionTimerUl;
293    DrxLongCycleStartOffset  drxLongCycleStartOffset;
294    bool                     shortDrxPres;
295    ShortDrx                 shortDrx;
296    uint8_t                  drxSlotOffset;
297 }DrxCfg;
298 #endif
299
300 typedef struct cuUeCb
301 {
302    CuCellCb  *cellCb;
303    uint32_t  crnti;
304    uint8_t   gnbDuUeF1apId;
305    uint8_t   gnbCuUeF1apId;
306    uint16_t  pdcpSn;
307    uint8_t   numSrb;
308    SrbInfo   srbList[MAX_NUM_SRB];
309    uint8_t   numDrb;
310    DrbInfo   drbList[MAX_NUM_DRB];
311    F1apMsgDb f1apMsgDb;
312    UeState   state;
313 #ifdef NR_DRX
314    bool      drxCfgPresent;
315    DrxCfg    drxCfg;
316 #endif
317    HandoverInfo hoInfo;
318 }CuUeCb;
319
320 struct cuCellCb
321 {
322    uint32_t nrCellId;
323    uint8_t  numUe;
324    CuUeCb   *ueCb[MAX_NUM_UE];
325    CellStatusInfo cellStatus;
326 };
327
328 typedef struct duDb
329 {
330    uint32_t duId;
331    char     duName[CU_DU_NAME_LEN_MAX];
332    uint8_t  numCells;
333    CuCellCb cellCb[MAX_NUM_CELL];  
334    uint8_t  numUe;
335    CuUeCb   ueCb[MAX_NUM_CELL * MAX_NUM_UE];
336 }DuDb;
337
338 typedef struct cuGlobalCb
339 {
340    CuCfgParams cuCfgParams;
341    uint8_t     numSnssaiSupported;
342    Snssai      *snssaiList[MAX_NUM_OF_SLICE];
343    uint8_t     numDu;
344    DuDb        duInfo[MAX_DU_SUPPORTED];
345    uint32_t    gnbCuUeF1apIdGenerator;   /* Generating CU UE F1AP ID */
346 }CuGlobalCb;
347
348 CuGlobalCb cuCb;
349
350 void readCuCfg();
351 void cuAppInmsgHdlr(Buffer *mBuf);
352 void sctpNtfyInd(CmInetSctpNotification *ntfy);
353 uint8_t egtpInitReq();
354 void *cuConsoleHandler(void *);
355
356 #endif
357
358 /**********************************************************************
359          End of file
360 **********************************************************************/