EGTP receiver thread creation
[o-du/l2.git] / src / du_app / du_cell_mgr.c
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 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lrg.x"
24 #include "lkw.x"
25 #include "rgr.h"
26 #include "rgr.x"
27 #include "du_app_mac_inf.h"
28 #include "du_app_rlc_inf.h"
29 #include "du_cfg.h"
30 #include "du_mgr.h"
31 #include "du_utils.h"
32 #include "du_cell_mgr.h"
33
34 /*******************************************************************
35  *
36  * @brief Processes cells to be activated
37  *
38  * @details
39  *
40  *    Function : duProcCellsToBeActivated
41  *
42  *    Functionality:
43  *      - Processes cells to be activated list received in F1SetupRsp
44  *
45  * @params[in] void
46  * @return ROK     - success
47  *         RFAILED - failure
48  *
49  * ****************************************************************/
50 uint8_t duProcCellsToBeActivated(uint8_t *plmnStr, uint16_t nci, uint16_t nRPci)
51 {
52    uint8_t ret = ROK;
53    DuCellCb *cellCb = NULLP;
54    uint8_t cfgIdx, tmpPlmn[4];
55
56    for(cfgIdx=0; cfgIdx<duCb.numCfgCells; cfgIdx++)
57    {
58       memset(tmpPlmn, 0, 4);
59       buildPlmnId(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.plmn, tmpPlmn);
60       if(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.cellId == nci &&
61             (strcmp((const char*)tmpPlmn, (const char*)plmnStr) == 0))
62       {
63          cellCb = duCb.cfgCellLst[cfgIdx];
64          break;
65       }
66       else
67       {
68          DU_LOG("\nDU APP : No Cell found for NCI %d", nci);
69          return RFAILED;
70       }
71    }
72
73    cellCb->cellStatus = ACTIVATION_IN_PROGRESS; 
74    cellCb->cellInfo.nrPci = nRPci;
75
76    duCb.actvCellLst[duCb.numActvCells++] = cellCb;
77
78    if(duBuildAndSendMacCellCfg(cellCb->cellId) != ROK)
79    {
80       DU_LOG("\nDU APP : macCellCfg build and send failed");
81       /* Delete cell from actvCellList */
82       duCb.actvCellLst[--(duCb.numActvCells)] = NULLP;
83       ret = RFAILED;
84    }
85    return ret;
86 }
87
88 /*******************************************************************
89  *
90  * @brief Handles DU F1Setup Rsp received in F1AP
91  *
92  * @details
93  *
94  *    Function : duProcF1SetupRsp
95  *
96  *    Functionality:
97  *      - Handles DU F1Setup Rsp received in F1AP
98  *
99  * @params[in] Pointer to F1SetupRsp 
100  * @return void
101  *
102  ******************************************************************/
103 void duProcF1SetupRsp()
104 {
105    DU_LOG("\nDU_APP : F1 Setup Response received");
106    duCb.f1Status = TRUE; //Set F1 status as true
107 }
108
109 /*******************************************************************
110  *
111  * @brief Handles GNB DU Cfg Update Ack received in F1AP
112  *
113  * @details
114  *
115  *    Function : duProcGnbDuCfgUpdAckMsg
116  *
117  *    Functionality:
118  *      - Handles GNB DU Cfg Update Ack received in F1AP
119  *
120  * @params[in] Pointer to F1GnbDuCfgUpdAck
121  * @return void
122  *  
123  ******************************************************************/
124 void duProcGnbDuCfgUpdAckMsg()
125 {
126    DU_LOG("\nDU APP: GNB-DU config update Ack received ");
127 }
128 /*******************************************************************
129 *
130 * @brief Returns cellCb based on cell ID
131 *
132 * @details
133 *
134 *    Function : duGetCellCb
135 *
136 *    Functionality: Returns DU APP CellCb based on cell ID
137 *
138 * @params[in] F1AP_PDU_t ASN decoded F1AP message
139 * @return ROK     - success
140 *         RFAILED - failure
141 *
142 * ****************************************************************/
143 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
144 {
145    uint8_t cellIdx;
146    for(cellIdx=0; cellIdx<duCb.numActvCells; cellIdx++)
147    {
148       if(duCb.actvCellLst[cellIdx]->cellId == cellId)
149          *cellCb = duCb.actvCellLst[cellIdx];
150          break;
151    }
152
153    if(!*cellCb)
154    {
155       DU_LOG("\nDU APP : Cell Id %d not found in DU APP", cellId);
156       return RFAILED;
157    }
158
159    return ROK;
160 }
161
162 /*******************************************************************
163  *
164  * @brief Handles cell up indication from MAC
165  *
166  * @details
167  *
168  *    Function : duHandleCellUpInd
169  *
170  *    Functionality:
171  *      Handles cell up indication from MAC
172  *
173  * @params[in] Post structure pointer
174  *             cell Up info
175  * @return ROK     - success
176  *         RFAILED - failure
177  *
178  * ****************************************************************/
179 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
180 {
181    DuCellCb *cellCb = NULLP;
182
183    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
184    {
185       DU_LOG("\nDU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
186       return RFAILED;
187    }
188
189    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
190       return RFAILED;
191
192    if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
193    {
194       DU_LOG("\nDU APP : 5G-NR Cell %d is UP", cellId->cellId);
195       cellCb->cellStatus = ACTIVATED;
196
197 #ifdef O1_ENABLE
198       DU_LOG("\nDU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
199       raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
200 #endif
201    }
202
203    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
204       DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
205    return ROK;
206 }
207
208 /**********************************************************************
209   End of file
210  **********************************************************************/