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