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