Modify licenses
[scp/ocu/5gnr.git] / Cu / CuUp / Sdap / sdap / Src / sdapDataProc.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 #include "msgb.h"
21 #include "bitsPack.h"
22 #include "pdcpuDlDataProc.h"
23 #include "nguUlDataProc.h"
24 #include "cuupTest.h"
25
26
27 INT8 sdapMatchQosFlowId(SdapInstance_t *pSdapInstance, INT64    qosFlowId, UINT64       *pDrbId, UINT8 *pFlag)
28 {
29         int i = 0;
30         int j = 0;
31         UINT64 drbId = 0;
32         SdapDrbCfg_t sdapDrbCfg = {0};
33
34         for(i = 0; i < pSdapInstance->drbNum; i++)
35         {
36                 drbId = pSdapInstance->drbId[i];
37
38                 VOS_MemCpy(&sdapDrbCfg, &pSdapInstance->drbCfg[drbId - 1], sizeof(SdapDrbCfg_t));
39
40                 for(j = 0; j < sdapDrbCfg.qfiNum; j++)
41                 {
42                         if(qosFlowId == sdapDrbCfg.qfi[j])
43                         {
44                                 *pDrbId = drbId;
45                                 break;
46                         }
47                 }
48         }
49
50         /* 没有查找到DRB,映射到默认的DRB */
51         if(0 == *pDrbId)
52         {
53                 for(i = 0; i < pSdapInstance->drbNum; i++)
54                 {
55                         drbId = pSdapInstance->drbId[i];
56
57                         /* 一个实例,即一个会话内,有且只有一个默认的DRB */
58                         if(DEFAULT_DRB_TRUE == pSdapInstance->drbCfg[drbId - 1].sdapCfg.defaultDrbInd)
59                         {
60                                 *pDrbId = drbId;
61                                 *pFlag = 1;
62                                 break;
63                         }
64                 }
65         }
66
67         return VOS_OK;
68 }
69
70 INT8 sdapPackPduHead(SdapInstance_t *pSdapInstance, INT64       qosFlowId, UINT64       *pDrbId, MsgbBuff_t *pMsgBuff, UINT8 rqi)
71 {
72         UINT8 *p= NULL;
73         UINT64 qosNum = 0;
74         UINT8  updateFlag = 0;
75         sdapDlHeader_t sdapHeader = {0};
76         INT8    pduHeadLen = 0;
77
78         if(VOS_OK != sdapMatchQosFlowId(pSdapInstance, qosFlowId, pDrbId, &updateFlag))
79         {
80                 return VOS_ERROR;
81         }
82
83         if(*pDrbId < 1 || *pDrbId > 32)
84         {
85                 return VOS_ERROR;
86         }
87
88         /*表明默认DRB上,增加了一条QOS的映射*/
89         if(1 == updateFlag)
90         {
91                 qosNum = pSdapInstance->drbCfg[*pDrbId -1].qfiNum;
92                 pSdapInstance->drbCfg[*pDrbId -1].qfi[qosNum] = qosFlowId;
93                 pSdapInstance->drbCfg[*pDrbId -1].qfiNum++;
94         }
95
96         if(SDAP_HEADER_PRESENT == pSdapInstance->drbCfg[*pDrbId - 1].sdapCfg.sdapDlHeaderInd)
97         {
98                 sdapHeader.QFI = qosFlowId;
99                 if(1 == updateFlag)
100                 {
101                         sdapHeader.RDI = 1;
102                 }
103
104                 sdapHeader.RQI = rqi;
105
106                 pduHeadLen = sizeof(sdapDlHeader_t);
107
108                 p = msgbHeadPush(pMsgBuff, pduHeadLen);
109                 VOS_MemCpy(p, &sdapHeader, pduHeadLen);
110
111                 return pduHeadLen;
112         }
113
114         /* 没有消息头的配置 */
115         return 0;
116 }
117
118 INT32 sdapDlDataProc(UINT64 upE1apId, UINT64 sessId, INT64      qosFlowId, MsgbBuff_t *pMsgBuff, UINT8 rqi)
119 {
120         int i = 0;
121         UINT8   flag = 0;
122         UINT16  sduLen = 0;
123         INT8    pduHeadLen = 0;
124         UINT64  drbId = 0;
125
126         SdapGlobalDtat_t        *pGlobalData = NULL;
127         SdapInstance_t          *pSdapInstance = NULL;
128         UINT8 *pMsgHead   = NULL;
129
130         if(NULL == pMsgBuff)
131         {
132                 return VOS_ERROR;
133         }
134
135         /* Get Instance */
136         pGlobalData = sdapGetUeGlobalData(upE1apId, &flag);
137
138         if(NULL == pGlobalData || 0 == flag)
139         {
140                 return VOS_ERROR;
141         }
142
143         for(i = 0; i < pGlobalData->sessNum; i++)
144         {
145                 if(sessId == pGlobalData->sessId[i])
146                 {
147                         pSdapInstance = &pGlobalData->sdapInstance[sessId];
148                         break;
149                 }
150         }
151
152         if(NULL == pSdapInstance)
153         {
154                 return VOS_ERROR;
155         }
156
157         sduLen = msgbDataUsedLen(pMsgBuff);     //length of sdap sdu, not include sdap pdu head
158         pMsgHead = msgbData(pMsgBuff);//start of sdap sdu, not include sdap pdu head
159
160         if(0 > sduLen || NULL == pMsgHead)
161         {
162                 return VOS_ERROR;
163         }
164
165         pduHeadLen = sdapPackPduHead(pSdapInstance, qosFlowId, &drbId, pMsgBuff, rqi);
166
167         if(VOS_ERROR == pduHeadLen)
168         {
169                 return VOS_ERROR;
170         }
171
172         /*传递到PDCP-U*/
173         pdcpuDlDataProc(upE1apId, drbId, pMsgBuff, 1);
174
175         return VOS_OK;
176 }
177
178 INT8 sdapUnPackPduHead(MsgbBuff_t *pMsgBuff)
179 {
180         BitOpt_t bit;
181         UINT32  bitSize = 0;
182
183         UINT8 *pMsgHead = msgbData(pMsgBuff);
184         UINT16 pduLen = msgbDataUsedLen(pMsgBuff);
185
186         initBits(&bit, pMsgHead, pduLen, 0);
187
188         /* SDAP头固定长度 1 */
189         bitSize = SDAP_HEADER_LEN*8;
190
191         if(-1 == unpackBits(&bit, bitSize))
192         {
193                 return VOS_ERROR;
194         }
195
196         return SDAP_HEADER_LEN;
197 }
198
199 INT32 sdapUlDataProc(UINT64 upE1apId, UINT64 sessId, UINT64 drbId, MsgbBuff_t *pMsgBuff)
200 {
201         int i = 0;
202         UINT8   flag = 0;
203         INT8    pduHeadLen = 0;
204
205         sdapUlHeader_t *pHead = NULL;
206         UINT8 qosFlowId = 0xff;
207         UINT8 pduType   = 0;
208
209         SdapGlobalDtat_t        *pGlobalData = NULL;
210         SdapInstance_t          *pSdapInstance = NULL;
211         SdapDrbCfg_t            *pDrbCfgInfo = NULL;
212
213         if(NULL == pMsgBuff)
214         {
215                 return VOS_ERROR;
216         }
217
218         /* Get Instance */
219         pGlobalData = sdapGetUeGlobalData(upE1apId, &flag);
220
221         if(NULL == pGlobalData || 0 == flag)
222         {
223                 return VOS_ERROR;
224         }
225
226         /* get instance */
227         for(i = 0; i < pGlobalData->sessNum; i++)
228         {
229                 if(sessId == pGlobalData->sessId[i])
230                 {
231                         pSdapInstance = &pGlobalData->sdapInstance[sessId];
232                         break;
233                 }
234         }
235
236         if(NULL == pSdapInstance)
237         {
238                 return VOS_ERROR;
239         }
240
241         /* get Drb Cfg */
242         for(i = 0; i < pSdapInstance->drbNum; i++)
243         {
244                 if(drbId == pSdapInstance->drbId[i])
245                 {
246                         pDrbCfgInfo = &pSdapInstance->drbCfg[drbId - 1];
247                         break;
248                 }
249         }
250
251         if(NULL == pDrbCfgInfo)
252         {
253                 return VOS_ERROR;
254         }
255
256         /* 有消息头的情况,去头 */
257         if(SDAP_HEADER_PRESENT == pDrbCfgInfo->sdapCfg.sdapUlHeaderInd)
258         {
259                 pduHeadLen = sdapUnPackPduHead(pMsgBuff);
260
261                 pHead     = (sdapUlHeader_t *)msgbData(pMsgBuff);
262                 qosFlowId = pHead->QFI;
263                 pduType   = pHead->TYPE;
264
265                 if(!pduType)
266                 {
267                         /* receive control pdu */
268                         return VOS_OK;
269                 }
270
271                 /* check qosFlowId */
272                 for(i = 0; i < pDrbCfgInfo->qfiNum; i++)
273                 {
274                         if(pDrbCfgInfo->qfi[i] == qosFlowId)
275                         {
276                                 break;
277                         }
278                 }
279
280                 if(i < pDrbCfgInfo->qfiNum)
281                 {
282                         /* qfi found */
283                         msgbHeadPull(pMsgBuff, pduHeadLen);
284                 }else
285                 {
286                         /* qfi not found */
287                         return VOS_ERROR;
288                 }
289
290         }
291
292
293         /* 调用NG-U的上行数据处理接口 */
294         return nguUlDataProc(upE1apId, sessId, qosFlowId, pMsgBuff);
295 }