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