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