Merge "RAR and MSG3 scheduling in TDD [Issue-ID: ODUHIGH-342]"
[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 typedef enum
61 {
62    CELL_OUT_OF_SERVICE,
63    ACTIVATION_IN_PROGRESS,
64    ACTIVATED,
65    DELETION_IN_PROGRESS
66 }CellStatus;
67
68 typedef enum
69 {
70    UE_INACTIVE,
71    UE_ACTIVE,
72    UE_DELETION_IN_PROGRESS
73 }UeState;
74
75 typedef enum
76 {
77    UE_CTXT_UNKNOWN,
78    UE_CTXT_SETUP,
79    UE_CTXT_MOD,
80    UE_CTXT_RELEASE
81 }UeCtxtActionType;
82
83 /** F1AP Msg IE **/
84 typedef struct f1setupRsp
85 {
86    uint32_t transId; /* Uniquely identify transaction */
87    char     cuName[CU_DU_NAME_LEN_MAX];   /* CU Name */
88    F1RrcVersion    rrcVersion;  /* RRC version */
89 }F1SetupRsp;
90
91 typedef struct f1DlRrcMsg 
92 {
93    uint32_t gnbDuUeF1apId;
94    uint32_t gnbCuUeF1apId;
95    uint8_t  srbId;
96    bool     execDup;
97    bool     deliveryStatRpt;
98    uint16_t rrcMsgSize;
99    uint8_t  *rrcMsgPdu;
100 }F1DlRrcMsg;
101
102 typedef struct gtpTnlCfg
103 {
104    uint32_t ulTnlAddress;  /* remote Address */
105    uint32_t dlTnlAddress;  /* local Address */
106    uint32_t teId;
107 }GtpTnlCfg;
108
109 typedef struct upTnlCfg
110 {
111    ConfigType configType;
112    uint8_t cellId;
113    uint8_t ueIdx;
114    uint8_t drbId;
115    GtpTnlCfg *tnlCfg1; /* Tunnel 1 */
116    GtpTnlCfg *tnlCfg2; /* Tunnel 2 */
117 }UpTnlCfg;
118
119 typedef struct duUeCfg
120 {
121    void *cellGrpCfg;
122    void *ueNrCapability;
123    uint8_t numRlcLcs;        /* Rlc Ue Cfg */
124    RlcBearerCfg rlcLcCfg[MAX_NUM_LC];
125    uint8_t numMacLcs;        /* Mac Ue Cfg */
126    LcCfg   macLcCfg[MAX_NUM_LC];
127    AmbrCfg *ambrCfg;
128    uint8_t numDrb;
129    UpTnlCfg upTnlInfo[MAX_NUM_DRB];  /* User plane TNL Info*/
130    MacUeCfg copyOfmacUeCfg;
131 }DuUeCfg;
132
133 typedef struct f1UeContextSetup
134 {
135    UeCtxtActionType actionType;
136    uint8_t cellIdx;
137    DuUeCfg  duUeCfg;        
138    bool     dlRrcMsgPres;
139    F1DlRrcMsg  *dlRrcMsg;
140 }F1UeContextSetupDb;
141
142 typedef struct cellCfgParams
143 {
144    NrEcgi      nrEcgi;         /* ECGI */
145    uint16_t    nrPci;          /* PCI */
146    uint16_t    fiveGsTac;         /* 5gSTac */
147    Plmn        plmn[MAX_PLMN]; /* List of serving PLMN IDs */
148    uint32_t    maxUe;          /* max UE per slot */
149 }CellCfgParams;
150
151 typedef struct duUeCb
152 {
153    F1UeContextSetupDb *f1UeDb;
154    uint16_t crnti;
155    uint32_t gnbDuUeF1apId;   /* GNB DU UE F1AP ID */
156    uint32_t gnbCuUeF1apId;   /* GNB CU UE F1AP ID */
157    uint32_t drbBitMap;       /* Drb Bit Map */
158    UeState  ueState;         /* UE Active/ Ue Inactive state */
159    MacUeCfg macUeCfg;        /* Mac Ue Cfg */
160    RlcUeCfg rlcUeCfg;        /* Rlc Ue Cfg */
161 }DuUeCb;
162
163 typedef struct duCellCb
164 {
165    uint16_t       cellId;                 /* Internal cell Id */
166    CellCfgParams  cellInfo;               /* Cell info */
167    /* pointer to store the address of macCellCfg params used to send du-app to MAC */
168    MacCellCfg     *duMacCellCfg;
169    CellStatus     cellStatus;             /* Cell status */
170    uint32_t       gnbDuUeF1apIdGenerator; /* Generating Du Ue F1ap Id */
171    uint32_t       numActvUes;             /* Total Active UEs */
172    DuUeCb         ueCb[MAX_NUM_UE];       /* UE CONTEXT */
173 }DuCellCb;
174
175 typedef struct duLSapCb
176 {
177    Pst pst;
178    SuId        suId;
179    SpId        spId;
180    State       sapState;
181    Mem         mem;
182    CmTimer     timer;
183    uint8_t     bndRetryCnt;
184    uint8_t     maxBndRetry;
185    TmrCfg      bndTmr;
186 }DuLSapCb;
187
188 typedef struct ueCcchCtxt
189 {
190    uint32_t gnbDuUeF1apId; /* GNB DU UE F1AP ID */
191    uint16_t crnti;         /* CRNTI */
192    uint16_t cellId;        /* Cell Id */
193 }UeCcchCtxt;
194
195 /* This structure is added to store the information about the F1AP pdu and
196  * transId so that It can be used in future */
197 typedef struct reservedF1apPduInfo
198 {
199    uint8_t transId;               /* trans Id */
200    void *f1apMsg;              /* msg structure */
201 }ReservedF1apPduInfo;
202
203 /* DU APP DB */
204 typedef struct duCb
205 {
206    Mem           mem;                       /* Memory configs */
207    TskInit       init;                      /* DU Init */
208    bool          f1Status;                  /* Status of F1 connection */
209    bool          e2Status;                  /* Status of E2 connection */
210    uint8_t       numCfgCells;               /* number of configured cells */ 
211    DuCellCb*     cfgCellLst[MAX_NUM_CELL];  /* List of cells at DU APP of type DuCellCb */
212    uint8_t       numActvCells;              /* Number of active cells */
213    DuCellCb*     actvCellLst[MAX_NUM_CELL]; /* List of cells activated/to be activated of type DuCellCb */
214    uint32_t      numUe;                     /* current number of UEs */
215    UeCcchCtxt    ueCcchCtxt[MAX_NUM_UE];    /* mapping of gnbDuUeF1apId to CRNTI required for CCCH processing*/
216    uint8_t       numDrb;                    /* current number of DRbs*/
217    UpTnlCfg*     upTnlCfg[MAX_NUM_DRB];     /* tunnel info for every Drb */
218    CmLListCp     reservedF1apPduList;       /*storing F1AP pdu infomation and transId */
219 }DuCb;
220
221
222 typedef struct duLSapCfg
223 {
224    SuId        suId;
225    SpId        spId;
226    Ent         srcEnt;
227    Inst        srcInst;
228    ProcId      dstProcId;
229    Ent         dstEnt;
230    Inst        dstInst;
231    Priority    dstPrior;
232    Route       dstRoute;
233    Selector    dstSel;
234    Mem         mem;
235    uint8_t          maxBndRetry;
236    TmrCfg      bndTmr;
237    TmrCfg      connTmr;
238 }DuLSapCfg;
239
240 /* global variables */
241 DuCb duCb;
242 //DuCfgParams duCfgParam;
243
244 /* DU Cell Functions */
245 uint8_t duActvInit(Ent entity, Inst inst, Region region, Reason reason);
246 uint8_t duActvTsk(Pst *pst, Buffer *mBuf);
247 uint8_t duSendRlcUlCfg();
248 uint8_t duSendRlcDlCfg();
249 uint8_t duBuildRlcCfg(Inst inst);
250 uint8_t duBuildRlcLsapCfg(Ent ent, Inst inst, uint8_t lsapInst);
251 uint8_t duBuildRlcUsapCfg(uint8_t elemId, Ent ent, Inst inst);
252 uint8_t DuHdlRlcCfgComplete(Pst *pst, RlcMngmt *cfm);
253 uint8_t duHdlRlcCntrlCfgComplete(Pst *pst, RlcMngmt *cfm);
254 uint8_t duProcRlcUlCfgComplete(Pst *pst, RlcMngmt *cfm);
255 uint8_t duProcRlcDlCfgComplete(Pst *pst, RlcMngmt *cfm);
256 uint8_t duSendMacCfg();
257 uint8_t duBuildMacGenCfg();
258 uint8_t duBuildMacUsapCfg(SpId sapId);
259 uint8_t duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm);
260 uint8_t duBindUnbindRlcToMacSap(uint8_t inst, uint8_t action);
261 uint8_t duProcCfgComplete();
262 uint8_t duSendSchCfg();
263 uint8_t duSctpStartReq();
264 uint8_t duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy);
265
266 uint8_t duBuildEgtpCfgReq();
267 uint8_t duHdlEgtpCfgComplete(CmStatus cfm);
268 uint8_t duSendEgtpSrvOpenReq();
269 uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm);
270 uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t teIdMod, GtpTnlCfg *tnlInfo);
271 uint8_t duSendEgtpDatInd(Buffer *mBuf);
272 uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm);
273 uint8_t duBuildAndSendMacCellStart();
274 uint8_t duBuildAndSendMacCellStop(uint16_t cellId);
275 #endif
276
277 /**********************************************************************
278   End of file
279  **********************************************************************/