1 /******************************************************************************
2 ###############################################################################
3 # Copyright (c) [2017-2020] [ICT/CAS] #
4 # Licensed under the ORAN Software License v1.0 (License) #
5 ###############################################################################
6 ******************************************************************************/
8 #include "vos_linklist.h"
9 #include "vos_module.h"
11 #include "cuupCommon.h"
15 #include "gnbCommon.h"
16 #include "pdcpCommon.h"
17 #include "pdcpuCore.h"
18 #include "cuupUeIdTransf.h"
22 extern PdcpuUeInfo_t *gPdcpuUeInfo[MAX_UE_NUM];
23 extern CuupUeIdxTable_t gPdcpuUeIdxTable;
24 extern ULONG gPdcpuModuleId;
25 ULONG gPdcpuUlModuleId;
27 extern INT32 sdapUlDataProc(UINT64 upE1apId, UINT64 sessId, UINT64 drbId, MsgbBuff_t *pMsgBuff);
28 INT32 pdcpuUlInit(ULONG userModuleId)
30 gPdcpuUlModuleId = userModuleId;
35 INT32 pdcpuUnpackPduHead(MsgbBuff_t *pMsgBuff, PdcpSnSize_e snSize,
36 UINT8 *pPdutype, UINT32 *pSn)
39 UINT8 *pMsgHead = msgbData(pMsgBuff);
40 UINT16 pduLen = msgbDataUsedLen(pMsgBuff);
42 initBits(&bit, pMsgHead, pduLen, 0);
43 *pPdutype = unpackBits(&bit, 1);
44 if(PDCP_CTRL_PDU == *pPdutype)
46 //*pCtrlPduType = unpackBits(&bit, 3);
50 }else if(PDCP_DATA_PDU == *pPdutype)
52 if(LEN12BITS == snSize)
54 /*************D/C + 3R + PDCP SN = 16bits*************/
55 skipBits(&bit, 3, BIT_UNPACKED);
56 *pSn = unpackBits(&bit, LEN12BITS);
58 return PDCP_SN_12_HEAD_LEN;
60 }else if(LEN18BITS == snSize)
62 /*************D/C + 5R + PDCP SN =24bits*************/
63 skipBits(&bit, 5, BIT_UNPACKED);
64 *pSn = unpackBits(&bit, LEN18BITS);
66 return PDCP_SN_18_HEAD_LEN;
70 pdcpuLog(LOG_ERR,"[PDCPU] sn size is wrong!\n");
79 INT32 pdcpuDecideCountAndHFN(PdcpStateVar_t *pStateVar, INT32 rcvdSn, PdcpSnSize_e snSize)
82 UINT32 rxDeliv = pStateVar->rxDelivery;
85 if(LEN12BITS == snSize)
87 tmp = GET_SN_12_SN(rxDeliv) - SN_12_WINDOW_SIZE;
90 rcvdHFN = GET_HFN_12_SN(rxDeliv) + 1;
91 }else if(rcvdSn >= GET_SN_12_SN(rxDeliv) + SN_12_WINDOW_SIZE)
93 rcvdHFN = GET_HFN_12_SN(rxDeliv) - 1;
96 rcvdHFN = GET_HFN_12_SN(rxDeliv);
98 pStateVar->rxCount = GET_COUNT_12_SN(rcvdHFN, rcvdSn);
100 }else if(LEN18BITS == snSize)
102 tmp = GET_SN_18_SN(rxDeliv) - SN_18_WINDOW_SIZE;
105 rcvdHFN = GET_HFN_18_SN(rxDeliv) + 1;
107 }else if(rcvdSn >= GET_SN_18_SN(rxDeliv) + SN_18_WINDOW_SIZE)
109 rcvdHFN = GET_HFN_18_SN(rxDeliv) - 1;
112 rcvdHFN = GET_HFN_18_SN(rxDeliv);
114 pStateVar->rxCount = GET_COUNT_18_SN(rcvdHFN, rcvdSn);
117 pdcpuLog(LOG_ERR,"[PDCPU] sn size is wrong!\n");
125 INT32 pdcpuCtrlPduProc(MsgbBuff_t *pMsgBuff, PdcpCtrlPduType_e ctrlPduType, PdcpDrbEntity_t *pPdcpDrbEntity)
127 pdcpuMsgbFree(pMsgBuff);
133 INT32 pdcpuDelivUldata(PdcpDrbEntity_t *pDrbEntity)
135 /* traverse list and send data to SDAP */
136 struct cl_lib_listnode *pNode = NULL;
137 PdcpuDataBuffNode_t *pDataInBuff1 = NULL;
138 PdcpuDataBuffNode_t *pDataInBuff2 = NULL;
142 pNode = cl_lib_listhead(pDrbEntity->pRxSduList);
145 /* There is no data in buffer */
146 VOS_Printf("there is no data in buffer\n");
149 pDataInBuff1 = (PdcpuDataBuffNode_t *)cl_lib_getdata(pNode);
151 if(pDataInBuff1->count == pDrbEntity->stateVar.rxDelivery)
155 cl_lib_nextnode (pNode);
156 count = pDataInBuff1->count;
158 /*+++++++++++++++++++++++++++test+++++++++++++++++++++++++++*/
159 //VOS_Printf("\n[pdcp ul data] pdcpuDelivUldata ueIdx:%d ueE1apId:%d drbId:%d count:%d \n",
160 // pDrbEntity->ueIdx,pDrbEntity->ueE1apId,pDrbEntity->drbId,count);
161 //printfMsgbBuff(pDataInBuff1->pData);
162 /*---------------------------test----------------------------*/
164 /* delivery to sdap,if sdapUlDataProc return VOS_OK,free the data
165 else, also free the data */
166 sdapUlDataProc(pDrbEntity->ueE1apId,pDrbEntity->pduSessionId,pDrbEntity->drbId,pDataInBuff1->pData);
168 /* update stateVar */
169 pDrbEntity->stateVar.rxDelivery = count + 1;
171 /* delete rx buffer */
172 cl_lib_listnode_delete(pDrbEntity->pRxSduList, pDataInBuff1);
173 pdcpuFreeDataBuffNode(pDataInBuff1);
177 /* There is no more data in buffer */
180 pDataInBuff2 = (PdcpuDataBuffNode_t *)cl_lib_getdata(pNode);
181 if(NULL == pDataInBuff2)
183 /* There is no more data in buffer */
184 pdcpuLog(LOG_ERR,"[PDCPU] data is null\n");
188 if(pDataInBuff2->count == count + 1)
190 /* The data is continuously */
191 pDataInBuff1 = pDataInBuff2;
193 }else if(pDataInBuff2->count > count + 1)
195 /* The data is not continuously */
199 pdcpuLog(LOG_ERR,"[PDCPU] out of order in receiving buffer!\n");
207 }else if(pDataInBuff1->count > pDrbEntity->stateVar.rxDelivery)
209 /* the data whose count value is equal to rxDelivery,is still waited for */
213 pdcpuLog(LOG_ERR,"[PDCPU] rxbuff is wrong!\n");
221 /*******************************************************************************
222 * pdcp-u ul data process
224 * ueE1apId: E1AP ID of the UE
225 * drbId: ID of data radio bearer
230 *******************************************************************************/
231 INT32 pdcpuUlDataProc(UINT64 ueE1apId, UINT8 drbId, MsgbBuff_t *pMsgBuff)
237 UINT16 ueIdx = 0xffff;
240 PdcpDrbEntity_t *pPdcpDrbEntity = NULL;
241 PdcpStateVar_t *pStateVar = NULL;
243 pdcpuNullCheck(pMsgBuff);
244 UINT8 *pMsgHead = msgbData(pMsgBuff);
245 UINT16 pduLen = msgbDataUsedLen(pMsgBuff);
248 pdcpuMsgbFree(pMsgBuff);
249 pdcpuLog(LOG_ERR,"[PDCPU] data len is too small!\n");
253 if(VOS_ERROR == cuupGetUeIdx(ueE1apId, &ueIdx, &gPdcpuUeIdxTable))
255 pdcpuLog(LOG_ERR,"[PDCPU] add ueE1apId failed\n");
256 pdcpuMsgbFree(pMsgBuff);
259 pdcpuGetEntity(ueIdx, drbId, pPdcpDrbEntity);
260 pdcpuNullCheck(pPdcpDrbEntity);
261 snSize = pPdcpDrbEntity->pdcpSnSizeUl;
262 pStateVar = &pPdcpDrbEntity->stateVar;
264 /* get pdcp pdu type */
266 initBits(&bit, pMsgHead, pduLen, 0);
267 pduType = unpackBits(&bit, 1);
269 if(PDCP_DATA_PDU == pduType)
271 //1.analysis pdcp header: shall not move the data start pointer
272 pduHeadLen = pdcpuUnpackPduHead(pMsgBuff, snSize, &pduType, &rcvdSn);
273 if(VOS_ERROR == pduHeadLen)
275 pdcpuLog(LOG_ERR,"[PDCPU] unpack pdu head wrong!\n");
276 pdcpuMsgbFree(pMsgBuff);
280 //make sure received HFN and received Count
281 if(VOS_ERROR == pdcpuDecideCountAndHFN(pStateVar, rcvdSn, snSize))
283 pdcpuLog(LOG_ERR,"[PDCPU] get count wrong!\n");
284 pdcpuMsgbFree(pMsgBuff);
288 count = pStateVar->rxCount;
290 //2.deciphering : except pdcp pdu head, the SDAP header and the SDAP Control PDU
292 BitOpt_t SdapHeadbit;
293 UINT8 *pSdapPduHead = msgbData(pMsgBuff) + pduHeadLen;
294 initBits(&SdapHeadbit, pSdapPduHead, 1, 0);
295 //5.remove pdcp pdu head
296 msgbHeadPull(pMsgBuff, pduHeadLen);
297 ret = sdapUlDataProc(ueE1apId,pPdcpDrbEntity->pduSessionId,drbId,pMsgBuff);
298 pPdcpDrbEntity->stateVar.rxDelivery = count + 1;
301 pdcpuMsgbFree(pMsgBuff);
305 pdcpuMsgbFree(pMsgBuff);
306 pdcpuLog(LOG_ERR,"[PDCPU] ul proc failed\n");