Modify licenses
[scp/ocu/5gnr.git] / Cu / CuUp / Sdap / sdap / Src / sdapCore.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 ICT/CAS.
4 *
5 *   Licensed under the O-RAN Software License, Version 1.0 (the "Software 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 *       https://www.o-ran.org/software
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 #include "sdapCore.h"
20
21 SdapGlobalDtat_t        s_SdapGlobalData[UPC_MAX_UE_NUM] = {{0}};
22
23 void sdapResortDrbId(SdapInstance_t *pSdapInstance, int idx)
24 {
25         int i = 0;
26         int j = 0;
27
28         for(i = 0; i < pSdapInstance->drbNum; i++)
29         {
30                 if(i == idx)
31                 {
32                         continue;
33                 }
34
35                 pSdapInstance->drbId[j] = pSdapInstance->drbId[i];
36                 j++;
37         }
38 }
39
40 void sdapResortSessionId(SdapGlobalDtat_t       *pGlobalData, int idx)
41 {
42         int i = 0;
43         int j = 0;
44
45         for(i = 0; i < pGlobalData->sessNum; i++)
46         {
47                 if(i == idx)
48                 {
49                         continue;
50                 }
51
52                 pGlobalData->sessId[j] = pGlobalData->sessId[i];
53                 j++;
54         }
55 }
56
57 SdapGlobalDtat_t* sdapGetUeGlobalData(UINT64    upE1apId, UINT8 *flag)
58 {
59         int i = 0;
60
61         for(i = 0; i < UPC_MAX_UE_NUM; i++)
62         {
63                 if(upE1apId == s_SdapGlobalData[i].upE1apId)
64                 {
65                         *flag = 1;
66                         return &s_SdapGlobalData[i];
67                 }
68         }
69
70         for(i = 0; i < UPC_MAX_UE_NUM; i++)
71         {
72                 if(0 == s_SdapGlobalData[i].upE1apId)
73                 {
74                         *flag = 0;
75                         return &s_SdapGlobalData[i];
76                 }
77         }
78
79         return NULL;
80 }
81 #if CONCEPT('Create Instance')
82 INT32 sdapCreateQosInfo(SdapDrbCfg_t *pDrbCfg, upcTempDrbInfo_t *pTempDrb, SdapDrbCfgRet_t *pDrbCfgRet)
83 {
84         int i = 0;
85         INT64   qosFlowId = 0;
86         upcTempQosInfo_t *pTempQos;
87
88         for(i = 0; i < pTempDrb->qosSetupNum; i++)
89         {
90                 pTempQos = &pTempDrb->pQosSetupList[i];
91
92                 if((NULL == pTempQos) || (TRUE != pTempQos->qosSetupAllowed))
93                 {
94                         continue;
95                 }
96
97                 qosFlowId = pTempQos->qosFlowId;
98                 pDrbCfg->qfi[pDrbCfg->qfiNum] = qosFlowId;
99                 pDrbCfg->qosFlowInfo[qosFlowId].qosFlowLevelQosPar = pTempQos->qosPara;
100                 if(pTempQos->qosMapFlag)
101                 {
102                         pDrbCfg->qosFlowInfo[qosFlowId].qosFlowMapInd = pTempQos->qosFlowMapInd;
103                 }
104                 pDrbCfg->qfiNum++;
105
106                 pDrbCfgRet->Qfi[pDrbCfgRet->QosNum] = qosFlowId;
107                 pDrbCfgRet->QosNum++;
108         }
109
110         if(0 == pDrbCfg->qfiNum)
111         {
112                 return VOS_ERROR;
113         }
114
115         return VOS_OK;
116 }
117
118 INT32 sdapCreateDrbInfo(SdapInstance_t *pInstance, upcTempSessInfo_t *pSessTempInfo, sdapSessCfgRet_t *pCfgRet)
119 {
120         int i = 0;
121         UINT64  drbId = 0;
122
123         upcTempDrbInfo_t        *pTempDrb = NULL;
124
125         pInstance->sessId = pSessTempInfo->pduSessId;
126         pCfgRet->sessId = pInstance->sessId;
127
128         for(i = 0; i < pSessTempInfo->drbSetupNum; i++)
129         {
130                 pTempDrb = &pSessTempInfo->pTempDrbSetupList[i];
131
132                 if((NULL == pTempDrb) || (TRUE != pTempDrb->drbSetupAllowed))
133                 {
134                         continue;
135                 }
136
137                 drbId = pTempDrb->drbId;
138
139                 if(VOS_OK != sdapCreateQosInfo(&pInstance->drbCfg[drbId - 1], pTempDrb, &pCfgRet->actDrbCfg[drbId - 1]))
140                 {
141                         pCfgRet->failDrbId[pCfgRet->failDrbNum] = drbId;
142                         pCfgRet->failDrbNum++;
143                         pCfgRet->cause[drbId - 1] = RNL_UNSPECIFIED;
144                         continue;
145                 }
146                 pCfgRet->actDrbId[pCfgRet->actDrbNum] = drbId;
147                 pCfgRet->actDrbCfg[drbId - 1].drbId = drbId;
148                 pCfgRet->actDrbNum++;
149
150                 VOS_MemCpy(&pInstance->drbCfg[drbId - 1].sdapCfg, &pTempDrb->sdapConfig, sizeof(SdapCfg_t));
151
152                 pInstance->drbCfg[drbId - 1].drbId = drbId;
153                 pInstance->drbId[pInstance->drbNum] = drbId;
154                 pInstance->drbNum++;
155         }
156
157         if(0 == pCfgRet->actDrbNum)
158         {
159                 pCfgRet->sessFailCause = RNL_UNSPECIFIED;
160                 return VOS_ERROR;
161         }
162
163         return VOS_OK;
164 }
165
166
167 extern INT32 printfSdapNewInstance(SdapGlobalDtat_t *pGlobalData);
168 extern INT32 sdapInactiveDetectSet(UINT64 ueE1apId);
169
170 INT32 sdapCreateNewInstance
171 (
172         SdapGlobalDtat_t        *pGlobalData,
173         UINT64  upE1apId,
174         upcTempSessInfo_t *pSessTempInfo,
175         sdapSessCfgRet_t *pCfgRet
176 )
177 {
178         int idx = 0;
179         UINT64  sessId = 0;
180
181         pGlobalData->upE1apId = upE1apId;
182         sessId = pSessTempInfo->pduSessId;
183         idx = pGlobalData->sessNum;
184
185         if(VOS_OK != sdapCreateDrbInfo(&pGlobalData->sdapInstance[sessId], pSessTempInfo, pCfgRet))
186         {
187                 pCfgRet->sessFailCause = RNL_UNSPECIFIED;
188                 return VOS_ERROR;
189         }
190
191         pGlobalData->sessId[idx] = sessId;
192         pGlobalData->sessNum++;
193
194         printfSdapNewInstance(pGlobalData);
195
196         return VOS_OK;
197 }
198
199 INT32 sdapCreateInstance(UINT64 upE1apId, upcTempSessInfo_t *pSessTempInfo, sdapSessCfgRet_t *pCfgRet)
200 {
201         INT32   ret = VOS_OK;
202         UINT8   flag = 0;
203         SdapGlobalDtat_t        *pGlobalData = NULL;
204
205         pGlobalData = sdapGetUeGlobalData(upE1apId, &flag);
206
207         if(NULL == pGlobalData)
208         {
209                 pCfgRet->sessFailCause = RNL_UNSPECIFIED;
210                 return VOS_ERROR;
211         }
212
213         /* 1、首次创建,初始化数据
214            2、只针对E1接口BearerContextSetupReq*/
215         if(0 == flag)
216         {
217                 VOS_MemZero(pGlobalData, sizeof(SdapGlobalDtat_t));
218         }
219
220         ret = sdapCreateNewInstance(pGlobalData, upE1apId, pSessTempInfo, pCfgRet);
221
222         return ret;
223 }
224 #endif
225
226 #if CONCEPT('Delete Instance')
227 INT32 sdapDeleteDrbInfo(SdapInstance_t *pSdapInstance, UINT8 drbId)
228 {
229         int i = 0;
230
231         for(i = 0; i < pSdapInstance->drbNum; i++)
232         {
233                 if(drbId == pSdapInstance->drbId[i])
234                 {
235                         sdapResortDrbId(pSdapInstance, i);
236                         pSdapInstance->drbNum--;
237                         VOS_MemZero(&pSdapInstance->drbCfg[drbId - 1], sizeof(SdapDrbCfg_t));
238                         return VOS_OK;
239                 }
240         }
241
242         return VOS_OK;
243 }
244
245 INT32 sdapDeleteDrbInfoOfInstance(UINT64 upE1apId, UINT8 sessId, UINT8 drbId)
246 {
247         int i = 0;
248         UINT8   flag = 0;
249         SdapGlobalDtat_t        *pGlobalData = NULL;
250
251         pGlobalData = sdapGetUeGlobalData(upE1apId, &flag);
252
253         /* 查找失败也认为是成功的 */
254         if(NULL == pGlobalData || 0 == flag)
255         {
256                 return VOS_OK;
257         }
258
259         for(i = 0; i < pGlobalData->sessNum; i++)
260         {
261                 if(sessId == pGlobalData->sessId[i])
262                 {
263                         sdapDeleteDrbInfo(&pGlobalData->sdapInstance[sessId], drbId);
264
265                         return VOS_OK;
266                 }
267         }
268
269         return VOS_OK;
270 }
271
272 INT32 sdapDeleteInstance(UINT64 upE1apId, UINT16 sessId)
273 {
274         int i = 0;
275         UINT8   flag = 0;
276         SdapGlobalDtat_t        *pGlobalData = NULL;
277
278         pGlobalData = sdapGetUeGlobalData(upE1apId, &flag);
279
280         /* 查找失败也认为是成功的 */
281         if(NULL == pGlobalData || 0 == flag)
282         {
283                 return VOS_OK;
284         }
285
286         for(i = 0; i < pGlobalData->sessNum; i++)
287         {
288                 if(sessId == pGlobalData->sessId[i])
289                 {
290                         sdapResortSessionId(pGlobalData, i);
291                         pGlobalData->sessNum--;
292                         VOS_MemZero(&pGlobalData->sdapInstance[sessId], sizeof(SdapInstance_t));
293                         return VOS_OK;
294                 }
295         }
296
297         return VOS_OK;
298 }
299 #endif