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