ecb665675e9004a1c9316c7c93a3372ddac560b9
[scp/ocu/5gnr.git] / Cu / CuUp / Pdcp / PdcpUp / Src / pdcpuCore.c
1 /******************************************************************************
2 ###############################################################################
3 #   Copyright (c) [2017-2020] [ICT/CAS]                                        #
4 #   Licensed under the ORAN Software License v1.0 (License)             #
5 ###############################################################################
6 ******************************************************************************/
7 #include "vos_types.h"
8 #include "vos_string.h"
9 #include "vos_linklist.h"
10 #include "vos_sem.h"
11 #include "pdcpu.h"
12 #include "cuupCommon.h"
13 #include "cuModuleInterface.h"
14 #include "gnbCommon.h"
15 #include "upcContext.h"
16 #include "cuupTest.h"
17
18 PdcpuUeInfo_t *gPdcpuUeInfo[MAX_UE_NUM];
19 extern ULONG gPdcpuModuleId;
20
21 /* not used at the moment */
22 /*void pdcpuSetLessCountFun(const void* cpv_first, const void* cpv_second, void* pv_output)
23 {       
24         assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL);
25         
26    *(bool_t*)pv_output = (((PdcpuDataBuffNode_t *)cpv_first)->count) < (((PdcpuDataBuffNode_t *)cpv_second)->count) ? true : false;
27 }*/
28
29
30 /** 释放一个 PdcpuDataBuffNode_t 数据,赋值给plist->del */
31 VOID pdcpuFreeDataBuffNode(VOID *p)
32 {
33         PdcpuDataBuffNode_t *pNode = NULL;
34         if(NULL == p)
35         {
36                 return ;
37         }
38
39         pNode = (PdcpuDataBuffNode_t *)p;
40         if(NULL != pNode->pData)
41         {
42                 msgbFree(pNode->pData);
43                 pNode->pData = NULL;
44         }
45         VOS_Free(p);
46         p = NULL;
47         
48         return ;
49 }
50
51 /*******************************************************************************
52  * discard all stored PDCP PDUs in the transmitting buffer 
53  * INPUT:
54  *              pTxPduList: transmitting buffer list
55  * OUTPUT:
56  *              0: success
57  *              -1:failed
58  *******************************************************************************/
59 INT32 pdcpuDiscardTransmitBuff(plist pTxPduList)
60 {
61         return VOS_OK;
62 }
63
64 /*******************************************************************************
65  * transmit or retransmit all stored PDCP PDUs in the transmitting buffer 
66  * INPUT:
67  *              pTxPduList: transmitting buffer list
68  * OUTPUT:
69  *              0: success
70  *              -1:failed
71  *******************************************************************************/
72 INT32 pdcpuDeliverTransmitBuff(PdcpDrbEntity_t *pPdcpuEntity)
73 {
74         return VOS_OK;
75 }
76
77 /*******************************************************************************
78  * deliver the PDCP SDUs stored in the receiving buffer to upper layers 
79  * in ascending order of associated COUNT values 
80  * INPUT:
81  *              pTxPduList: transmitting buffer list
82  * OUTPUT:
83  *              0: success
84  *              -1:failed
85  *******************************************************************************/
86 INT32 pdcpuDeliverRecvBuff(PdcpDrbEntity_t *pPdcpuEntity)
87 {
88         return VOS_OK;
89 }
90
91
92 /*******************************************************************************
93  * To construct and send a PDCP status report 
94  * INPUT:
95  *              pPdcpuEntity: pdcpu entity
96  * OUTPUT:
97  *              0: success
98  *              -1:failed
99  *******************************************************************************/
100 INT32 pdcpuConstructStatusReport(PdcpDrbEntity_t *pPdcpuEntity)
101 {
102         return VOS_OK;
103 }
104
105 /*******************************************************************************
106  * To perform PDCP data recovery 
107  * INPUT:
108  *              ueE1apId: UE E1AP ID
109  *              drbId : DRB ID
110  * OUTPUT:
111  *              0: success
112  *              -1:failed
113  *******************************************************************************/
114 INT32 pdcpuDataRecovery(PdcpDrbEntity_t *pPdcpuEntity)
115 {
116         return VOS_OK;
117 }
118
119 INT32 pdcpuRecfgRohc(PdcpDrbEntity_t *pPdcpuEntity, upcTempDrbInfo_t *pDrbItem)
120 {
121     return VOS_OK;
122 }
123
124
125
126 INT32 pdcpuSetSn(PdcpSnSize_e *pSn, PdcpSNSize_e snCfg)
127 {
128         if(PDCP_SN_SIZE_S12 == snCfg)
129         {
130                 *pSn = LEN12BITS;
131                 
132         }else if(PDCP_SN_SIZE_S18 == snCfg)
133         {
134                 *pSn = LEN18BITS;
135                 
136         }else
137         {
138                 pdcpuLog(LOG_ERR,"[PDCPU] input sn size is wrong!\n");
139                 return VOS_ERROR;
140         }
141         
142         return VOS_OK;
143 }
144
145 INT32 pdcpuSetRlcMode(PdcpRlcMode_e *pRlcMode, CuRlcMode_e rlcCfg)
146 {
147         switch(rlcCfg)
148         {
149                 case RLCMODE_TM:
150                         pdcpuLog(LOG_ERR,"[PDCPU] input-TM MODE is wrong!\n");
151                         return VOS_ERROR;
152                 
153                 case RLCMODE_AM:
154                         *pRlcMode = AM_MODE;
155                         return VOS_OK;
156
157                 case RLCMODE_UM_BIDIRECTIONAL:
158                 case RLCMODE_UM_UNIDIRECTIONAL_UL:
159                 case RLCMODE_UM_UNIDIRECTIONAL_DL:
160                         *pRlcMode = UM_MODE;
161                         return VOS_OK;
162
163                 default:
164                         pdcpuLog(LOG_ERR,"[PDCPU] input-rlc mode is wrong\n");
165                         return VOS_ERROR;
166         }
167 }
168
169 /*******************************************************************************
170  * To get SDAP DATA PDU header length configuration 
171  * INPUT:
172  *              sdapHeadInd : 
173  *              sdapHeadLen : 
174  * OUTPUT:
175  *              none
176  *******************************************************************************/
177 INT32 pdcpuGetSdapHeadLen(SdapHeader_e sdapHeadInd, UINT8 *sdapHeadLen)
178 {
179         if(SDAP_HEADER_PRESENT == sdapHeadInd)
180         {
181                 *sdapHeadLen = 1;       /*Data PDU with SDAP header*/
182                 
183         }else if(SDAP_HEADER_ABSENT == sdapHeadInd)
184         {
185                 *sdapHeadLen = 0;       /*Data PDU without SDAP header*/
186                 
187         }else
188         {       
189                 pdcpuLog(LOG_ERR,"[PDCPU] sdap head cfg is wrong\n");
190                 return VOS_ERROR;
191         }
192         
193         return VOS_OK;
194 }
195
196
197 /*******************************************************************************
198  * To create PDCP-U entity 
199  * INPUT:
200  *              ueE1apId: UE E1AP ID
201  *              pDrbItem : DRB to setup item
202  * OUTPUT:
203  *              0: success
204  *              -1:failed
205  *******************************************************************************/
206 INT32 pdcpuCreateEntity(UINT64 ueE1apId, UINT16 ueIdx, UINT16 pduSessionId, upcTempDrbInfo_t *pDrbItem)
207 {               
208         UINT8 drbId = pDrbItem->drbId;  
209         PdcpuUeInfo_t   *pPdcpUeInfo  = NULL;
210         PdcpDrbEntity_t *pPdcpuEntity = NULL;
211         INT8 ret = 0;
212
213         pdcpuCheckUeIdx(ueIdx);
214         pdcpuCheckDrbId(drbId);
215         
216         /* examine ue info */   
217         if(NULL == gPdcpuUeInfo[ueIdx])
218         {
219                 pPdcpUeInfo = VOS_Malloc(sizeof(PdcpuUeInfo_t), gPdcpuModuleId);
220                 pdcpuNullCheck(pPdcpUeInfo);
221                 VOS_MemZero(pPdcpUeInfo, sizeof(PdcpuUeInfo_t));
222                 gPdcpuUeInfo[ueIdx] = pPdcpUeInfo;              
223         }else
224         {
225                 pPdcpUeInfo = gPdcpuUeInfo[ueIdx];
226         }
227         
228         /* examine drb info */
229         if(NULL != pPdcpUeInfo->pdcpDrbEntity[drbId])
230         {
231                 pPdcpuEntity = pPdcpUeInfo->pdcpDrbEntity[drbId];
232
233         }       
234         pPdcpuEntity = VOS_Malloc(sizeof(PdcpDrbEntity_t), gPdcpuModuleId);     
235         pdcpuNullCheck(pPdcpuEntity);
236         VOS_MemZero(pPdcpuEntity, sizeof(PdcpDrbEntity_t));
237         pPdcpUeInfo->pdcpDrbEntity[drbId] = pPdcpuEntity;
238                 
239         PDCPConfiguration_t *pPdcpCfg   = &(pDrbItem->pdcpConfig);
240         pPdcpuEntity->ueE1apId                  = ueE1apId;
241         pPdcpuEntity->ueIdx                             = ueIdx;
242         pPdcpuEntity->pduSessionId              = pduSessionId;
243         pPdcpuEntity->drbId                             = drbId;
244
245         if(0 != ((pPdcpCfg->bitMask)&PDCP_CONFIGURATION_OUT_OF_ORDER_DELIVERY_PRESENT))
246         {
247                 pdcpuLog(LOG_INFO,"[PDCPU] 乱序递交已设置\n");
248                 pPdcpuEntity->outOfOrderDelivery= TRUE;
249         }
250
251         /* set rlc mode */
252         ret += pdcpuSetRlcMode(&pPdcpuEntity->rlcMode, pPdcpCfg->rlcMode);
253
254         /* set sn size- Cond Setup2(38.331) */
255         ret += pdcpuSetSn(&pPdcpuEntity->pdcpSnSizeUl, pPdcpCfg->pdcpSNSizeUl);
256         ret += pdcpuSetSn(&pPdcpuEntity->pdcpSnSizeDl, pPdcpCfg->pdcpSNSizeDl);
257
258
259         /* set sdap head length */
260         ret += pdcpuGetSdapHeadLen(pDrbItem->sdapConfig.sdapDlHeaderInd, &pPdcpuEntity->sdapDlHeadLen);
261         ret += pdcpuGetSdapHeadLen(pDrbItem->sdapConfig.sdapUlHeaderInd, &pPdcpuEntity->sdapUlHeadLen);
262
263         /* check the above return results */
264         if(0 != ret)
265         {
266                 pdcpuLog(LOG_ERR,"[PDCPU] input parameter is wrong\n");
267                 VOS_Free(pPdcpuEntity);
268                 pPdcpUeInfo->pdcpDrbEntity[drbId] = NULL;
269                 return VOS_ERROR;               
270         }
271         
272
273         /* set security enable information */
274         PdcpuSecEnableInfo_t *pEnableInfo = gPdcpuUeInfo[ueIdx]->secEnableInfo[pduSessionId];
275         pdcpuNullCheck(pEnableInfo);    
276         pPdcpuEntity->integrityProtection = pEnableInfo->integrityEnableFlag;
277         pPdcpuEntity->ciperingEnabled = pEnableInfo->cipherEnableFlag;
278
279         /* not support: ulDataSplitThreshold, pdcpDuplication */
280
281         /* set state variable */
282         VOS_MemZero(&(pPdcpuEntity->stateVar), sizeof(PdcpStateVar_t));
283
284
285         /* initial transmitting buffer */
286         pPdcpuEntity->txListLock = VOS_SemMCreate(VOS_SEM_Q_FIFO);
287         pPdcpuEntity->pTxPduList = cl_lib_list_new("pdcpuTxPduList", gPdcpuModuleId);
288
289         /* initial receiving buffer */
290         pPdcpuEntity->rxListLock = VOS_SemMCreate(VOS_SEM_Q_FIFO);
291         pPdcpuEntity->pRxSduList = cl_lib_list_new("pdcpuRxSduList", gPdcpuModuleId);
292
293         printfDrbEntity(pPdcpuEntity);
294
295         return VOS_OK;
296 }
297