fix ODUHIGH-182 updating code to be compatible with latest available fapi_inetrface...
[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 "du_cfg.h"
26 #include "E2AP-PDU.h"
27 #include<ProtocolIE-Field.h>
28 #include "F1AP-PDU.h"
29 #include "du_cell_mgr.h"
30
31 extern DuCfgParams duCfgParam;
32 extern S16 duBuildAndSendMacCellCfg();
33
34 /*******************************************************************
35  *
36  * @brief Processes cells to be activated
37  *
38  * @details
39  *
40  *    Function : procCellsToBeActivated
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 S16 procCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
51 {
52    U16 idx = 0;
53    S16 ret = ROK;
54
55    for(idx=0; idx<cellsToActivate.list.count; idx++)
56    {
57       U16 nci = 0;
58       U16 pci = 0;
59       DuCellCb *cellCb = NULLP;
60
61       Cells_to_be_Activated_List_Item_t cell = cellsToActivate.list.array[idx]->\
62           value.choice.Cells_to_be_Activated_List_Item;
63
64       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
65       if(nci <= 0 || nci > DU_MAX_CELLS)
66       {
67          DU_LOG("\nDU APP : Invalid NCI %d", nci);
68          return RFAILED;
69       }
70
71       if(cell.nRPCI)
72       {
73          pci = *cell.nRPCI;
74       }
75
76       cellCb = duCb.cfgCellLst[nci-1];
77
78       if(!cellCb)
79       {
80          DU_LOG("\nDU APP : No Cell found for NCI %d", nci);
81          return RFAILED;
82       }
83       cellCb->cellStatus = ACTIVATION_IN_PROGRESS; 
84       cellCb->cellInfo.nrPci = pci;
85
86       /* Now remove this cell from configured list and move to active list */
87       duCb.cfgCellLst[nci-1] = NULL;
88       duCb.actvCellLst[nci-1] = cellCb;
89
90       /* Build and send Mac Cell Cfg for the number of active cells */
91       ret = duBuildAndSendMacCellCfg();
92       if(ret != ROK)
93       {
94          DU_LOG("\nDU APP : macCellCfg build and send failed");
95          return RFAILED;
96       }
97    }
98    return ret;
99 }
100
101 /******************************************************************
102 *
103 * @brief Processes F1 Setup Response sent by CU
104 *
105 * @details
106 *
107 *    Function : procF1SetupRsp
108 *
109 *    Functionality: Processes F1 Setup Response sent by CU
110 *
111 * @params[in] F1AP_PDU_t ASN decoded F1AP message
112 * @return ROK     - success
113 *         RFAILED - failure
114 *
115 * ****************************************************************/
116 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg)
117 {
118    uint8_t ret = ROK;
119
120    F1SetupResponse_t *f1SetRspMsg;
121    F1SetupRsp    f1SetRspDb;
122    GNB_CU_Name_t *cuName;
123    RRC_Version_t *rrc_Ver;
124    U16 idx;
125
126    DU_LOG("\nDU_APP : F1 Setup Response received"); 
127         printf("\nDU_APP : F1 Setup Response received");
128    duCb.f1Status = TRUE; //Set F1 status as true
129    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
130
131    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
132    {
133 //      F1SetupResponseIEs_t f1RspIe = f1SetRspMsg->protocolIEs.list.array[idx];
134       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
135       {
136          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
137          {
138             procCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
139                   value.choice.Cells_to_be_Activated_List);
140             break;
141          }
142          //TODO: where to store and how to use below variables?can they be skipped
143          case ProtocolIE_ID_id_TransactionID:
144          {
145             f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
146                                  value.choice.TransactionID;
147             break;
148          }
149          case ProtocolIE_ID_id_gNB_CU_Name:
150          {
151             cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
152                      value.choice.GNB_CU_Name;
153             strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
154             break;
155          }
156          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
157          {
158             rrc_Ver = &f1SetRspMsg->protocolIEs.list.array[idx]->\
159                       value.choice.RRC_Version;
160             strcpy(f1SetRspDb.rrcVersion.rrcVer,
161                   (const char*)rrc_Ver->latest_RRC_Version.buf);
162             break;
163          }
164          default:
165             DU_LOG("\nDU_APP : Invalid IE received in F1SetupRsp:%ld",
166                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
167       }
168    }
169  
170    /* TODO :Check the deallocation */
171 #if 0
172    SPutSBuf(DU_APP_MEM_REGION, DU_POOL,(Data *)&(f1SetupRsp->protocolIEs.list.array),\
173          (Size)elementCnt * sizeof(F1SetupResponseIEs_t *));
174    SPutSBuf(DU_APP_MEM_REGION, DU_POOL,(Data *)&(f1apMsg->choice.successfulOutcome),\
175          (Size)sizeof(SuccessfulOutcome_t));
176    SPutSBuf(DU_APP_MEM_REGION, DU_POOL,(Data *)&f1apMsg,(Size)sizeof(F1AP_PDU_t));
177 #endif
178  
179    return ret;
180 }
181
182 /*******************************************************************
183  *
184  * @brief Processes GNB DU config update ack
185  *
186  * @details
187  *
188  *    Function : procGNBDUCfgUpdAck
189  *
190  *    Functionality: Processes GNB DU config update ack
191  *
192  * @params[in] F1AP_PDU_t ASN decoded F1AP message
193  * @return ROK     - success
194  *         RFAILED - failure
195  *
196  * ****************************************************************/
197 S16 procGNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
198 {
199    DU_LOG("\nF1AP : GNB-DU config update acknowledgment received");
200 /* TODO :Check the deallocation */
201 #if 0
202    SPutSBuf(DU_APP_MEM_REGION,DU_POOL,(Data*)&(gNBDuCfgAck->protocolIEs.list.array),\
203            (Size)elementCnt * sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t
204 ));
205    SPutSBuf(DU_APP_MEM_REGION,DU_POOL,(Data*)&(f1apMsg->choice.successfulOutcome),\
206            (Size)sizeof(SuccessfulOutcome_t));
207    SPutSBuf(DU_APP_MEM_REGION,DU_POOL,(Data*)&f1apMsg,(Size)sizeof(F1AP_PDU_t));
208 #endif
209     return ROK;
210 }
211
212
213 /**********************************************************************
214   End of file
215  **********************************************************************/