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