1 /******************************************************************************
3 * Copyright (c) 2020 ICT/CAS.
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
9 * https://www.o-ran.org/software
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.
17 *******************************************************************************/
19 #include "vos_types.h"
20 #include "vos_linklist.h"
21 #include "vos_module.h"
23 #include "cuupCommon.h"
27 #include "gnbCommon.h"
28 #include "pdcpCommon.h"
29 #include "pdcpuCore.h"
30 #include "cuupUeIdTransf.h"
34 extern PdcpuUeInfo_t *gPdcpuUeInfo[MAX_UE_NUM];
35 extern CuupUeIdxTable_t gPdcpuUeIdxTable;
36 extern ULONG gPdcpuModuleId;
37 ULONG gPdcpuUlModuleId;
39 extern INT32 sdapUlDataProc(UINT64 upE1apId, UINT64 sessId, UINT64 drbId, MsgbBuff_t *pMsgBuff);
40 INT32 pdcpuUlInit(ULONG userModuleId)
42 gPdcpuUlModuleId = userModuleId;
47 INT32 pdcpuUnpackPduHead(MsgbBuff_t *pMsgBuff, PdcpSnSize_e snSize,
48 UINT8 *pPdutype, UINT32 *pSn)
51 UINT8 *pMsgHead = msgbData(pMsgBuff);
52 UINT16 pduLen = msgbDataUsedLen(pMsgBuff);
54 initBits(&bit, pMsgHead, pduLen, 0);
55 *pPdutype = unpackBits(&bit, 1);
56 if(PDCP_CTRL_PDU == *pPdutype)
58 //*pCtrlPduType = unpackBits(&bit, 3);
62 }else if(PDCP_DATA_PDU == *pPdutype)
64 if(LEN12BITS == snSize)
66 /*************D/C + 3R + PDCP SN = 16bits*************/
67 skipBits(&bit, 3, BIT_UNPACKED);
68 *pSn = unpackBits(&bit, LEN12BITS);
70 return PDCP_SN_12_HEAD_LEN;
72 }else if(LEN18BITS == snSize)
74 /*************D/C + 5R + PDCP SN =24bits*************/
75 skipBits(&bit, 5, BIT_UNPACKED);
76 *pSn = unpackBits(&bit, LEN18BITS);
78 return PDCP_SN_18_HEAD_LEN;
82 pdcpuLog(LOG_ERR,"[PDCPU] sn size is wrong!\n");
91 INT32 pdcpuDecideCountAndHFN(PdcpStateVar_t *pStateVar, INT32 rcvdSn, PdcpSnSize_e snSize)
94 UINT32 rxDeliv = pStateVar->rxDelivery;
97 if(LEN12BITS == snSize)
99 tmp = GET_SN_12_SN(rxDeliv) - SN_12_WINDOW_SIZE;
102 rcvdHFN = GET_HFN_12_SN(rxDeliv) + 1;
103 }else if(rcvdSn >= GET_SN_12_SN(rxDeliv) + SN_12_WINDOW_SIZE)
105 rcvdHFN = GET_HFN_12_SN(rxDeliv) - 1;
108 rcvdHFN = GET_HFN_12_SN(rxDeliv);
110 pStateVar->rxCount = GET_COUNT_12_SN(rcvdHFN, rcvdSn);
112 }else if(LEN18BITS == snSize)
114 tmp = GET_SN_18_SN(rxDeliv) - SN_18_WINDOW_SIZE;
117 rcvdHFN = GET_HFN_18_SN(rxDeliv) + 1;
119 }else if(rcvdSn >= GET_SN_18_SN(rxDeliv) + SN_18_WINDOW_SIZE)
121 rcvdHFN = GET_HFN_18_SN(rxDeliv) - 1;
124 rcvdHFN = GET_HFN_18_SN(rxDeliv);
126 pStateVar->rxCount = GET_COUNT_18_SN(rcvdHFN, rcvdSn);
129 pdcpuLog(LOG_ERR,"[PDCPU] sn size is wrong!\n");
137 INT32 pdcpuCtrlPduProc(MsgbBuff_t *pMsgBuff, PdcpCtrlPduType_e ctrlPduType, PdcpDrbEntity_t *pPdcpDrbEntity)
139 pdcpuMsgbFree(pMsgBuff);
145 INT32 pdcpuDelivUldata(PdcpDrbEntity_t *pDrbEntity)
147 /* traverse list and send data to SDAP */
148 struct cl_lib_listnode *pNode = NULL;
149 PdcpuDataBuffNode_t *pDataInBuff1 = NULL;
150 PdcpuDataBuffNode_t *pDataInBuff2 = NULL;
154 pNode = cl_lib_listhead(pDrbEntity->pRxSduList);
157 /* There is no data in buffer */
158 VOS_Printf("there is no data in buffer\n");
161 pDataInBuff1 = (PdcpuDataBuffNode_t *)cl_lib_getdata(pNode);
163 if(pDataInBuff1->count == pDrbEntity->stateVar.rxDelivery)
167 cl_lib_nextnode (pNode);
168 count = pDataInBuff1->count;
170 /*+++++++++++++++++++++++++++test+++++++++++++++++++++++++++*/
171 //VOS_Printf("\n[pdcp ul data] pdcpuDelivUldata ueIdx:%d ueE1apId:%d drbId:%d count:%d \n",
172 // pDrbEntity->ueIdx,pDrbEntity->ueE1apId,pDrbEntity->drbId,count);
173 //printfMsgbBuff(pDataInBuff1->pData);
174 /*---------------------------test----------------------------*/
176 /* delivery to sdap,if sdapUlDataProc return VOS_OK,free the data
177 else, also free the data */
178 sdapUlDataProc(pDrbEntity->ueE1apId,pDrbEntity->pduSessionId,pDrbEntity->drbId,pDataInBuff1->pData);
180 /* update stateVar */
181 pDrbEntity->stateVar.rxDelivery = count + 1;
183 /* delete rx buffer */
184 cl_lib_listnode_delete(pDrbEntity->pRxSduList, pDataInBuff1);
185 pdcpuFreeDataBuffNode(pDataInBuff1);
189 /* There is no more data in buffer */
192 pDataInBuff2 = (PdcpuDataBuffNode_t *)cl_lib_getdata(pNode);
193 if(NULL == pDataInBuff2)
195 /* There is no more data in buffer */
196 pdcpuLog(LOG_ERR,"[PDCPU] data is null\n");
200 if(pDataInBuff2->count == count + 1)
202 /* The data is continuously */
203 pDataInBuff1 = pDataInBuff2;
205 }else if(pDataInBuff2->count > count + 1)
207 /* The data is not continuously */
211 pdcpuLog(LOG_ERR,"[PDCPU] out of order in receiving buffer!\n");
219 }else if(pDataInBuff1->count > pDrbEntity->stateVar.rxDelivery)
221 /* the data whose count value is equal to rxDelivery,is still waited for */
225 pdcpuLog(LOG_ERR,"[PDCPU] rxbuff is wrong!\n");
233 /*******************************************************************************
234 * pdcp-u ul data process
236 * ueE1apId: E1AP ID of the UE
237 * drbId: ID of data radio bearer
242 *******************************************************************************/
243 INT32 pdcpuUlDataProc(UINT64 ueE1apId, UINT8 drbId, MsgbBuff_t *pMsgBuff)
249 UINT16 ueIdx = 0xffff;
252 PdcpDrbEntity_t *pPdcpDrbEntity = NULL;
253 PdcpStateVar_t *pStateVar = NULL;
255 pdcpuNullCheck(pMsgBuff);
256 UINT8 *pMsgHead = msgbData(pMsgBuff);
257 UINT16 pduLen = msgbDataUsedLen(pMsgBuff);
260 pdcpuMsgbFree(pMsgBuff);
261 pdcpuLog(LOG_ERR,"[PDCPU] data len is too small!\n");
265 if(VOS_ERROR == cuupGetUeIdx(ueE1apId, &ueIdx, &gPdcpuUeIdxTable))
267 pdcpuLog(LOG_ERR,"[PDCPU] add ueE1apId failed\n");
268 pdcpuMsgbFree(pMsgBuff);
271 pdcpuGetEntity(ueIdx, drbId, pPdcpDrbEntity);
272 pdcpuNullCheck(pPdcpDrbEntity);
273 snSize = pPdcpDrbEntity->pdcpSnSizeUl;
274 pStateVar = &pPdcpDrbEntity->stateVar;
276 /* get pdcp pdu type */
278 initBits(&bit, pMsgHead, pduLen, 0);
279 pduType = unpackBits(&bit, 1);
281 if(PDCP_DATA_PDU == pduType)
283 //1.analysis pdcp header: shall not move the data start pointer
284 pduHeadLen = pdcpuUnpackPduHead(pMsgBuff, snSize, &pduType, &rcvdSn);
285 if(VOS_ERROR == pduHeadLen)
287 pdcpuLog(LOG_ERR,"[PDCPU] unpack pdu head wrong!\n");
288 pdcpuMsgbFree(pMsgBuff);
292 //make sure received HFN and received Count
293 if(VOS_ERROR == pdcpuDecideCountAndHFN(pStateVar, rcvdSn, snSize))
295 pdcpuLog(LOG_ERR,"[PDCPU] get count wrong!\n");
296 pdcpuMsgbFree(pMsgBuff);
300 count = pStateVar->rxCount;
302 //2.deciphering : except pdcp pdu head, the SDAP header and the SDAP Control PDU
304 BitOpt_t SdapHeadbit;
305 UINT8 *pSdapPduHead = msgbData(pMsgBuff) + pduHeadLen;
306 initBits(&SdapHeadbit, pSdapPduHead, 1, 0);
307 //5.remove pdcp pdu head
308 msgbHeadPull(pMsgBuff, pduHeadLen);
309 ret = sdapUlDataProc(ueE1apId,pPdcpDrbEntity->pduSessionId,drbId,pMsgBuff);
310 pPdcpDrbEntity->stateVar.rxDelivery = count + 1;
313 pdcpuMsgbFree(pMsgBuff);
317 pdcpuMsgbFree(pMsgBuff);
318 pdcpuLog(LOG_ERR,"[PDCPU] ul proc failed\n");