Modify licenses
[scp/ocu/5gnr.git] / Cu / CuUp / Pdcp / PdcpUp / Src / pdcpuDlDataProc.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 <sys/time.h>
20 #include "vos_types.h"
21 #include "vos_linklist.h"
22 #include "vos_sem.h"
23 #include "cuupCommon.h"
24 #include "msgb.h"
25 #include "bitsPack.h"
26 #include "pdcpu.h"
27 #include "gnbCommon.h"
28 #include "cuupUeIdTransf.h"
29
30 #include "cuupTest.h"   //for test
31
32 extern PdcpuUeInfo_t    *gPdcpuUeInfo[MAX_UE_NUM];
33 extern CuupUeIdxTable_t gPdcpuUeIdxTable;
34 extern ULONG gPdcpuModuleId;
35
36 ULONG gPdcpuDlModuleId;
37
38 INT32 pdcpuDlInit(ULONG userModuleId)
39 {
40         gPdcpuDlModuleId = userModuleId;
41
42         return VOS_OK;
43 }
44
45 INT32 pdcpuPackPduHead(PdcpRlcMode_e rlc_mode,PdcpSnSize_e snSize, UINT32 sn, MsgbBuff_t *msgb)
46 {
47         BitOpt_t bit;
48         UINT8   *p                       = NULL;
49         UINT8   *pPduHead        = NULL;
50         UINT8    pduHeadLen  = 0;
51
52         if(LEN12BITS == snSize)
53         {
54                 pduHeadLen = PDCP_SN_12_HEAD_LEN;
55         }else if(LEN18BITS == snSize)
56         {
57                 pduHeadLen = PDCP_SN_18_HEAD_LEN;
58         }else
59         {
60                 pdcpuLog(LOG_ERR,"[PDCPU] sn size is wrong!\n");
61                 return VOS_ERROR;
62         }
63         pPduHead  =  VOS_Malloc(pduHeadLen,gPdcpuDlModuleId);
64         pdcpuNullCheck(pPduHead);
65         VOS_MemZero(pPduHead, pduHeadLen);
66
67         if(snSize == LEN12BITS)
68         {
69                 if(sn >= MAX_PDCP_SN_12)
70                 {
71                         pdcpuLog(LOG_ERR,"[PDCPU] sn too big\n");
72                         return VOS_ERROR;
73                 }
74                 initBits(&bit, pPduHead, 16, 0);
75                 packBits(&bit, 1, 1);
76                 skipBits(&bit, 3, BIT_PACKED);
77                 packBits(&bit, 4, ((sn & 0xf00)>>8));
78                 packBits(&bit, 8, sn & 0x0ff);
79         }else if(snSize == LEN18BITS)
80         {
81                 if(sn >= MAX_PDCP_SN_18)
82                 {
83                         pdcpuLog(LOG_ERR,"[PDCPU] sn too big\n");
84                         return VOS_ERROR;
85                 }
86                 initBits(&bit, pPduHead, 24, 0);
87                 packBits(&bit, 1, 1);
88                 skipBits(&bit, 5, BIT_PACKED);
89                 packBits(&bit, 2, ((sn & 0x00030000)>>16));
90                 packBits(&bit, 8, ((sn & 0x0000ff00)>>8));
91                 packBits(&bit, 8, sn & 0x000000ff);
92         }else
93         {
94                 pdcpuLog(LOG_ERR,"[PDCPU] sn size error\n");
95                 return VOS_ERROR;
96         }
97
98         p = msgbHeadPush(msgb, pduHeadLen);
99         if(NULL != p)
100         {
101                 VOS_MemCpy(p, pPduHead, pduHeadLen);
102         }else
103         {
104                 pdcpuLog(LOG_ERR,"[PDCPU] msgbHeadPush failed!\n");
105                 return VOS_ERROR;
106         }
107
108         if(NULL != pPduHead)
109         {
110                 VOS_Free(pPduHead);
111                 pPduHead= NULL;
112         }
113
114         return pduHeadLen;
115 }
116
117
118 /*******************************************************************************
119  * pdcp-u dl data process
120  * INPUT:
121  *              ueE1apId: E1AP ID of the UE
122  *              drbId: ID of data radio bearer
123  *              pMsgBuff: PDCP PDU
124  * OUTPUT:
125  *              0: success
126  *              -1:failed
127  *******************************************************************************/
128 INT32 pdcpuDlDataProc(UINT64 ueE1apId, UINT8 drbId, MsgbBuff_t *pMsgBuff, UINT8 sdapPduType)
129 {
130         UINT32 sn                 = 0;
131         INT8   pduHeadLen = 0;
132
133         PdcpSnSize_e            snSize;
134         PdcpRlcMode_e           rlcMode;
135         PdcpDrbEntity_t         *pPdcpDrbEntity = NULL;
136
137         UINT16 ueIdx;
138         if(VOS_ERROR == cuupGetUeIdx(ueE1apId, &ueIdx, &gPdcpuUeIdxTable))
139         {
140                 pdcpuLog(LOG_ERR,"[PDCPU] get ueIdx failed,ueE1apId:%d\n",ueE1apId);
141                 return VOS_ERROR;
142         }
143         pdcpuCheckUeIdx(ueIdx);
144         pdcpuCheckDrbId(drbId);
145
146         pdcpuGetEntity(ueIdx, drbId, pPdcpDrbEntity);
147         pdcpuNullCheck(pPdcpDrbEntity);
148         rlcMode = pPdcpDrbEntity->rlcMode;
149
150         //1.check data
151         pdcpuNullCheck(pMsgBuff);
152
153         //2.assign the sn
154         UINT32 count = pPdcpDrbEntity->stateVar.txNext++;
155
156         // check out count wrapping around whether or not
157         if(0xffffffff == count)
158         {
159                 pdcpuLog(LOG_ERR,"[PDCPU] count value is going to wrap around!\n");
160                 return VOS_ERROR;
161         }
162
163         snSize = pPdcpDrbEntity->pdcpSnSizeDl;
164         if(snSize == LEN12BITS)
165         {
166                 sn = GET_SN_12_SN(count);
167         }else if(snSize == LEN18BITS)
168         {
169                 sn = GET_SN_18_SN(count);
170         }else
171         {
172                 pdcpuLog(LOG_ERR,"[PDCPU] sn size is wrong!\n");
173                 return VOS_ERROR;
174         }
175
176         //4.add pdu head
177         pduHeadLen = pdcpuPackPduHead(rlcMode, snSize, sn, pMsgBuff);
178         if(VOS_ERROR == pduHeadLen)
179         {
180                 pdcpuLog(LOG_ERR,"[PDCPU] pack pdcp pdu head failed!\n");
181                 return VOS_ERROR;
182         }
183
184         //8. 否则:cuf1u将数据发送成功后,释放
185         if(VOS_OK == cuf1uDlDataProc(ueE1apId, drbId, pMsgBuff, NULL))
186         {
187                 //vos_info_print("there is no buffer\n");
188                 msgbFree(pMsgBuff);
189                 pMsgBuff = NULL;
190                 return VOS_OK;
191         }else
192         {
193                 pdcpuLog(LOG_ERR,"[PDCPU] cuf1u send failed\n");
194                 return VOS_ERROR;
195         }
196
197 }