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