Initial commit for Bronze release
[o-du/l2.git] / src / 5gnrmac / rg_cl_cfg.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 handles the cell configurtaion for MAC CL */
20
21 #include "envdep.h"
22 #include "gen.h"
23 #include "ssi.h"
24 #include "cm_hash.h"
25
26 #include "gen.x"
27 #include "ssi.x"
28 #include "cm_hash.x"
29 #include "cm_lib.x"
30
31 #include "lcl.h"
32 #include "lwr_mac.h"
33
34 EXTERN S16 rgClBldAndSndFAPICfgReq ARGS((ClCellCb *cellCb));
35
36 /*******************************************************************
37  *
38  * @brief Validates CL cell configuration
39  *
40  * @details
41  *
42  *    Function : rgClVldtCellCfg
43  *
44  *    Functionality:
45  *       - Validates all PHY cell configuration patameters
46  *
47  * @params[in] cell config
48  * @return ROK     - success
49  *         RFAILED - failure
50  *
51  * ****************************************************************/
52 PRIVATE S16 rgClVldtCellCfg
53 (
54 ClCellCfg   *cellCfg
55 )
56 {
57   RETVALUE(ROK);
58 }
59
60
61 /*******************************************************************
62  *
63  * @brief Cell configuration handler at MAC CL
64  *
65  * @details
66  *
67  *    Function : RgClCellCfgReq
68  *
69  *    Functionality:
70  *        -Handler for new cell addition request from du_app
71  *
72  * @params[in] cell cfg 
73  * @return ROK     - success
74  *         RFAILED - failure
75  *
76  * ****************************************************************/
77 PUBLIC U16 RgClCellCfgReq
78 (
79 ClCellCfg   *cellCfg
80 )
81 {
82    ClCellCb   *cellCb = NULLP;
83
84    printf("\nReceived cell configuration request. Adding cellId[%d] phyCellId[%d]", cellCfg->cellId, cellCfg->phyCellId);
85
86    if(clGlobalCp.numOfCells >= MAX_NUM_CELL_SUPP)
87    {
88       printf("\nMaximum number of cells [%d] already configured", MAX_NUM_CELL_SUPP);
89       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
90    }
91
92    if(rgClVldtCellCfg(cellCfg) != ROK)
93    {
94       printf("\nCell configuration failure. Cell Id [%d]", cellCfg->cellId);
95       RETVALUE(LCM_REASON_INVALID_PAR_VAL);
96    }
97
98    if((cellCb = (ClCellCb *)rgClUtlGetCellCb(cellCfg->cellId)) == NULLP)
99    {
100       if((SGetSBuf(clGlobalCp.region, clGlobalCp.pool, (Data **)&cellCb, sizeof(ClCellCb)) != ROK) || (cellCb == NULLP))
101       {
102          printf("\nFailed to allocate memory for new cell");
103          RETVALUE(LCM_REASON_MEM_NOAVAIL);
104       }
105       cmMemset((U8 *)cellCb, 0, sizeof(ClCellCb));
106       cellCb->cellId = cellCfg->cellId;
107       cellCb->phyState = PHY_STATE_IDLE;
108    
109       if((cmHashListInsert(&(clGlobalCp.cellCbLst), (PTR)cellCb, (U8 *)&cellCb->cellId, sizeof(U16))) != ROK)
110       {
111          printf("\nFailed to insert cell into list.");
112          RETVALUE(RFAILED);
113       }
114
115       clGlobalCp.numOfCells++;
116    }
117
118    cmMemcpy((U8 *)&cellCb->cellCfg, (U8 *)cellCfg, sizeof(ClCellCfg));
119
120    /* Build and send CONFIG request to PHY */
121    if(rgClBldAndSndFAPICfgReq(cellCb) != ROK )
122    {
123       printf("\nrgClBldAndSndPhyCfgReq failed");
124       RETVALUE(LCM_REASON_NEG_CFM);
125    }
126
127    RETVALUE(LCM_REASON_NOT_APPL);
128 }
129
130 /**********************************************************************
131          End of file
132 **********************************************************************/