7904f4737cc6454417b5b03a669802f41e905c4c
[o-du/l2.git] / src / du_app / du_mgr.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 /* This file contains message handling functionality for DU cell management */
20 #ifndef __DU_MGR_H__
21 #define __DU_MGR_H__
22 #define DU_PROC  0
23
24 /* SAP IDs */
25 #define DU_MAC_SUID 0
26 #define DU_MAC_SPID 0
27
28 /* Instance */
29 #define RLC_UL_INST 0
30 #define RLC_DL_INST 1
31
32 /* SAP state */
33 #define DU_SAP_UNBOUND 1
34 #define DU_SAP_BINDING 2
35 #define DU_SAP_BOUND   3
36
37 #define DU_ZERO_VAL 0
38
39 /* Macros */
40 #define ADD 0
41 #define DEL 1
42
43 #define RLC_GEN_CFG      1
44 #define RLC_MAC_SAP_CFG  2
45 #define RLC_UDX_SAP_CFG  4
46
47 #define MAC_GEN_CFG   1
48 #define MAC_SAP_CFG   2
49 #define MAX_MAC_SAP   2
50
51 #define DU_RLC_UL_CONFIGURED  (RLC_GEN_CFG |  \
52       RLC_MAC_SAP_CFG | RLC_UDX_SAP_CFG)
53 #define DU_RLC_DL_CONFIGURED DU_RLC_UL_CONFIGURED
54
55 #define MAC_CONFIGURED (MAC_GEN_CFG | MAC_SAP_CFG)
56
57 #define DU_SET_ZERO(_buf, _size)   \
58    memset((_buf), 0, _size);
59
60 /*Refer Spec 38.331 Annexure A: maxNrofPageRec : 32 [Maximum number of page records]*/
61 #define MAX_PAGING_UE_RECORDS 32
62
63 typedef enum
64 {
65    SLICE_INFO_NOT_AVAILABLE,
66    SLICE_CONFIGURED,
67    SLICE_RECONFIGURED
68 }SliceCfgState;
69
70 typedef enum
71 {
72    CELL_OUT_OF_SERVICE,
73    ACTIVATION_IN_PROGRESS,
74    ACTIVATED,
75    DELETION_IN_PROGRESS
76 }CellStatus;
77
78 typedef enum
79 {
80    UE_INACTIVE,
81    UE_ACTIVE,
82    UE_HANDIN_IN_PROGRESS,
83    UE_DELETION_IN_PROGRESS,
84    UE_RESET_IN_PROGRESS
85 }UeState;
86
87 typedef enum
88 {
89    UE_CTXT_UNKNOWN,
90    UE_CTXT_SETUP,
91    UE_CTXT_MOD,
92    UE_CTXT_RRC_RECFG_COMPLETE,
93    UE_CTXT_CFG_QUERY,
94    UE_CTXT_RELEASE
95 }UeCtxtActionType;
96
97 /** F1AP Msg IE **/
98 typedef struct f1setupRsp
99 {
100    uint32_t transId; /* Uniquely identify transaction */
101    char     cuName[CU_DU_NAME_LEN_MAX];   /* CU Name */
102    F1RrcVersion    rrcVersion;  /* RRC version */
103 }F1SetupRsp;
104
105 typedef struct f1DlRrcMsg 
106 {
107    uint32_t gnbDuUeF1apId;
108    uint32_t gnbCuUeF1apId;
109    uint8_t  srbId;
110    bool     execDup;
111    bool     deliveryStatRpt;
112    uint16_t rrcMsgSize;
113    uint8_t  *rrcMsgPdu;
114 }F1DlRrcMsg;
115
116 typedef struct gtpTnlCfg
117 {
118    uint32_t ulTnlAddress;  /* remote Address */
119    uint32_t dlTnlAddress;  /* local Address */
120    uint32_t teId;
121 }GtpTnlCfg;
122
123 typedef struct upTnlCfg
124 {
125    ConfigType configType;
126    uint8_t cellId;
127    uint8_t ueId;
128    uint8_t drbId;
129    GtpTnlCfg *tnlCfg1; /* Tunnel 1 */
130    GtpTnlCfg *tnlCfg2; /* Tunnel 2 */
131 }UpTnlCfg;
132
133 #ifdef NR_DRX
134 /* This structures is taken from the DRX Cycle section of
135  * specification 33.473. */
136 typedef struct drxCycle
137 {
138    uint16_t drxLongCycleLength;
139    bool     shortDrxCyclePres;
140    ShortDrx shortDrxCycle;
141 }DrxCycle;
142 #endif
143
144 typedef struct duLcCfg
145 {
146    ConfigType configType;
147    LcCfg      lcConfig;
148 }DuLcCfg;
149
150 typedef struct duMacUeCfg
151 {
152    uint16_t               cellId;
153    uint8_t                ueId;
154    uint16_t               crnti;
155    bool                   macCellGrpCfgPres;
156    MacCellGrpCfg          macCellGrpCfg;
157    bool                   phyCellGrpCfgPres;
158    PhyCellGrpCfg          phyCellGrpCfg;
159    bool                   spCellCfgPres;
160    SpCellRecfg            spCellCfg;
161    AmbrCfg                *ambrCfg;
162    ModulationInfo         dlModInfo;    /* DL modulation info */ //TBD
163    ModulationInfo         ulModInfo;    /* UL modulation info */  //TBD
164    uint8_t                numLcs;
165    DuLcCfg                lcCfgList[MAX_NUM_LC];
166    UeCfgState             macUeCfgState;    /* InActive / Completed */ //TBD
167    DataTransmissionAction transmissionAction; //TBD
168 #ifdef NR_DRX
169    bool     drxConfigIndicatorRelease;
170 #endif
171 }DuMacUeCfg;
172
173 typedef struct duRlcBearerCfg
174 {
175    ConfigType   configType;
176    RlcBearerCfg rlcBearerCfg;
177 }DuRlcBearerCfg;
178
179 typedef struct duRlcUeCfg
180 {
181    uint16_t       cellId;
182    uint8_t        ueId;
183    uint8_t        numLcs;
184    DuRlcBearerCfg rlcLcCfg[MAX_NUM_LC];
185    UeCfgState     rlcUeCfgState; /* InActive / Completed */
186 }DuRlcUeCfg;
187
188
189 typedef struct duUeCfg
190 {
191    void *cellGrpCfg;
192    void *ueNrCapability;
193    uint8_t numRlcLcs;        /* Rlc Ue Cfg */
194    DuRlcBearerCfg rlcLcCfg[MAX_NUM_LC];
195    uint8_t numMacLcs;        /* Mac Ue Cfg */
196    DuLcCfg   macLcCfg[MAX_NUM_LC];
197    AmbrCfg *ambrCfg;
198    uint8_t numDrb;
199    UpTnlCfg upTnlInfo[MAX_NUM_DRB];  /* User plane TNL Info*/
200    uint8_t numDrbSetupMod;        /*No. of DRB Added during Modification*/
201    uint8_t numDrbModified;        /*No. of DRB Modified during Modification*/
202    DuMacUeCfg copyOfmacUeCfg;
203    DataTransmissionAction dataTransmissionAction;
204 #ifdef NR_DRX
205    bool     drxCyclePres;
206    DrxCycle drxCycle;
207    bool     drxConfigIndicatorRelease;
208 #endif
209 }DuUeCfg;
210
211 typedef struct f1UeContextSetup
212 {
213    UeCtxtActionType actionType;
214    uint8_t cellIdx;
215    DuUeCfg  duUeCfg;        
216    bool     dlRrcMsgPres;
217    F1DlRrcMsg  *dlRrcMsg;
218 }F1UeContextSetupDb;
219
220 typedef struct cellCfgParams
221 {
222    NrEcgi      nrEcgi;         /* ECGI */
223    uint16_t    nrPci;          /* PCI */
224    uint16_t    fiveGsTac;         /* 5gSTac */
225    Plmn        plmn[MAX_PLMN]; /* List of serving PLMN IDs */
226    uint32_t    maxUe;          /* max UE per slot */
227 }CellCfgParams;
228
229 typedef struct duUeCb
230 {
231    F1UeContextSetupDb *f1UeDb;
232    uint16_t crnti;
233    uint32_t gnbDuUeF1apId;   /* GNB DU UE F1AP ID */
234    uint32_t gnbCuUeF1apId;   /* GNB CU UE F1AP ID */
235    uint32_t drbBitMap;       /* Drb Bit Map */
236    UeState  ueState;         /* UE Active/ Ue Inactive state */
237    MacCfraResource cfraResource; /* CF-RA resource assigned by MAC/SCH */
238    DuMacUeCfg duMacUeCfg;        /* Mac Ue Cfg */
239    DuRlcUeCfg duRlcUeCfg;        /* Rlc Ue Cfg */
240 }DuUeCb;
241
242 typedef struct  slotInfo
243 {
244    uint16_t sfn;
245    uint16_t slot;
246 }SlotInfo;
247
248 typedef struct pagingMsg
249 {
250    /*Note: Paging UEID is extracted from 5gSTMSI as per Spec 38.304, Sec 7.1.
251     *This is not same as DU-UE_F1AP_ID or CU_UE_F1AP_ID*/
252    uint16_t  pagUeId;              /* UE Identifier from CU*/
253
254    /*TODO: When RAN Inititated Paging will be supported then I-RNTI will be
255     * added as a choice for UE Identity along with S-TMSI*/
256    uint64_t  sTmsi;             /* UE Paging Identity: S-TMSI */
257    bool      pagingDrxPres;     /* flag to indicate paging drx present or not */
258    uint16_t  pagingDrx;         /* UE specific paging drx */
259    uint8_t   pagPriority;       /* Paging priority */
260    uint16_t  pagingFrame;       /* paging frame */
261    uint16_t  pagingFrameOffset; /* paging offset */
262    uint8_t   i_s;               /* Index points to PO from the sub-frame pattern */
263    uint16_t  T;                 /* T is DRX cycle of the UE */
264 }DuPagingMsg;
265
266 typedef struct duPagUeRecord
267 {
268    uint16_t  pagUeId;           /*UEID calculated from 5gsTMSI as per Spec 38.304*/
269    uint64_t  sTmsi;             /* UE Paging Identity: S-TMSI */
270 }DuPagUeRecord;
271
272 typedef struct duPagInfo
273 {
274    uint8_t      i_s;          /*Index of PO*/
275    CmLListCp    pagUeList;    /*List of UEs to be paged in this Paging Frame/Paging Occ*/
276 }DuPagUeList;
277
278 typedef struct duPagInfoMap
279 {
280    uint16_t    pf;             /* Paging Frame*/
281    CmLListCp   pagInfoList;    /* Master List of Paging Identified by PF and i_s*/
282 }DuPagInfoList;
283
284 typedef struct duCellCb
285 {
286    uint16_t       cellId;                 /* Internal cell Id */
287    CellCfgParams  cellInfo;               /* Cell info */
288    /* pointer to store the address of macCellCfg params used to send du-app to MAC */
289    MacCellCfg     *duMacCellCfg;
290    CellStatus     cellStatus;             /* Cell status */
291    uint32_t       numActvUes;             /* Total Active UEs */
292    DuUeCb         ueCb[MAX_NUM_UE];       /* Stores UE context */
293    SlotInfo       currSlotInfo;
294    DuPagingMsg    tmpPagingInfoOfUe;      /* UE paging information */
295    CmHashListCp   pagingInfoMap;          /*Paging Map between PF and PagingInfoList*/
296 }DuCellCb;
297
298 typedef struct duLSapCb
299 {
300    Pst pst;
301    SuId        suId;
302    SpId        spId;
303    State       sapState;
304    Mem         mem;
305    CmTimer     timer;
306    uint8_t     bndRetryCnt;
307    uint8_t     maxBndRetry;
308    TmrCfg      bndTmr;
309 }DuLSapCb;
310
311 typedef struct ueCcchCtxt
312 {
313    uint32_t gnbDuUeF1apId; /* GNB DU UE F1AP ID */
314    uint16_t crnti;         /* CRNTI */
315    uint16_t cellId;        /* Cell Id */
316 }UeCcchCtxt;
317
318 /* This structure is added to store the information about the F1AP pdu and
319  * transId so that It can be used in future */
320 typedef struct reservedF1apPduInfo
321 {
322    uint8_t transId;               /* trans Id */
323    void *f1apMsg;              /* msg structure */
324 }ReservedF1apPduInfo;
325
326 /* DU APP DB */
327 typedef struct duCb
328 {
329    Mem           mem;                       /* Memory configs */
330    TskInit       init;                      /* DU Init */
331    bool          f1Status;                  /* Status of F1 connection */
332    bool          e2Status;                  /* Status of E2 connection */
333    E2apDb        e2apDb;                    /* E2AP database */
334    uint8_t       numCfgCells;               /* number of configured cells */ 
335    DuCellCb*     cfgCellLst[MAX_NUM_CELL];  /* List of cells at DU APP of type DuCellCb */
336    uint8_t       numActvCells;              /* Number of active cells */
337    DuCellCb*     actvCellLst[MAX_NUM_CELL]; /* List of cells activated/to be activated of type DuCellCb */
338    uint32_t      gnbDuUeF1apIdGenerator;    /* Generating Du Ue F1ap Id */
339    uint32_t      numUe;                     /* current number of UEs */
340    UeCcchCtxt    ueCcchCtxt[MAX_NUM_UE];    /* mapping of gnbDuUeF1apId to CRNTI required for CCCH processing*/
341    uint8_t       numTeId;                   /* current number of TEIDs configured in the system*/
342    UpTnlCfg*     upTnlCfg[MAX_TEID];        /* tunnel info for every Drb */
343    CmLListCp     reservedF1apPduList;       /*storing F1AP pdu infomation and transId */
344    SliceCfgState sliceState;
345    F1SetupMsg    f1SetupReqAndRspMsg;
346 }DuCb;
347
348
349 typedef struct duLSapCfg
350 {
351    SuId        suId;
352    SpId        spId;
353    Ent         srcEnt;
354    Inst        srcInst;
355    ProcId      dstProcId;
356    Ent         dstEnt;
357    Inst        dstInst;
358    Priority    dstPrior;
359    Route       dstRoute;
360    Selector    dstSel;
361    Mem         mem;
362    uint8_t          maxBndRetry;
363    TmrCfg      bndTmr;
364    TmrCfg      connTmr;
365 }DuLSapCfg;
366
367 /* global variables */
368 DuCb duCb;
369 //DuCfgParams duCfgParam;
370
371 /* DU Cell Functions */
372 uint8_t duActvInit(Ent entity, Inst inst, Region region, Reason reason);
373 uint8_t duActvTsk(Pst *pst, Buffer *mBuf);
374 uint8_t duSendRlcUlCfg();
375 uint8_t duSendRlcDlCfg();
376 uint8_t duBuildRlcCfg(Inst inst);
377 uint8_t duBuildRlcLsapCfg(Ent ent, Inst inst, uint8_t lsapInst);
378 uint8_t duBuildRlcUsapCfg(uint8_t elemId, Ent ent, Inst inst);
379 uint8_t DuHdlRlcCfgComplete(Pst *pst, RlcMngmt *cfm);
380 uint8_t duHdlRlcCntrlCfgComplete(Pst *pst, RlcMngmt *cfm);
381 uint8_t duProcRlcUlCfgComplete(Pst *pst, RlcMngmt *cfm);
382 uint8_t duProcRlcDlCfgComplete(Pst *pst, RlcMngmt *cfm);
383 uint8_t duSendMacCfg();
384 uint8_t duBuildMacGenCfg();
385 uint8_t duBuildMacUsapCfg(SpId sapId);
386 uint8_t duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm);
387 uint8_t duBindUnbindRlcToMacSap(uint8_t inst, uint8_t action);
388 uint8_t duProcCfgComplete();
389 uint8_t duSendSchCfg();
390 uint8_t duSctpStartReq();
391 uint8_t duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy);
392
393 uint8_t duBuildEgtpCfgReq();
394 uint8_t duHdlEgtpCfgComplete(CmStatus cfm);
395 uint8_t duSendEgtpSrvOpenReq();
396 uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm);
397 uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t teIdMod, GtpTnlCfg *tnlInfo);
398 uint8_t duSendEgtpDatInd(Buffer *mBuf);
399 uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm);
400 uint8_t duBuildAndSendMacCellStart();
401 uint8_t duBuildAndSendMacCellStop(uint16_t cellId);
402
403 #endif
404
405 /**********************************************************************
406   End of file
407  **********************************************************************/