1 /******************************************************************************
2 ###############################################################################
3 # Copyright (c) [2017-2020] [ICT/CAS] #
4 # Licensed under the ORAN Software License v1.0 (License) #
5 ###############################################################################
6 ******************************************************************************/
8 #include "vos_string.h"
11 #include "pdcpuCore.h"
12 #include "pdcpCommon.h"
13 #include "cuupCommon.h"
14 #include "cuModuleInterface.h"
15 #include "pdcpComprohc.h"
17 #include "cuupUeIdTransf.h"
18 #include "upcContext.h"
20 extern PdcpuUeInfo_t *gPdcpuUeInfo[MAX_UE_NUM];
22 CuupUeIdxTable_t gPdcpuUeIdxTable;
25 /*******************************************************************************
32 *******************************************************************************/
33 INT32 pdcpuInit(ULONG userModuleId)
35 /* get pdcpu moduleId */
36 gPdcpuModuleId = userModuleId;
38 /* init ueIdx table */
40 for(i=0; i<MAX_UE_NUM; i++)
42 gPdcpuUeIdxTable.ueIdxInfo[i].isUsed = FALSE;
46 for(i=0; i<MAX_UE_NUM; i++)
48 gPdcpuUeInfo[i] = NULL;
55 INT32 pdcpuFreeSecInfo(UINT16 ueIdx)
57 PdcpuSecInfo_t *pDrbSecInfo = gPdcpuUeInfo[ueIdx]->secInfo;
58 if(NULL != pDrbSecInfo)
60 VOS_Free(pDrbSecInfo);
61 gPdcpuUeInfo[ueIdx]->secInfo = NULL;
67 /*******************************************************************************
68 * To deal with security indication
69 * Security Result indicates whether the security policy indicated as "preferred"
70 * in the Security Indication IE is performed or not.
72 * ueE1apId : UE E1AP ID
73 * pduSessionId : pdu session id
74 * pSecInd : security indication
75 * pSecResult : security result
79 *******************************************************************************/
80 INT32 pdcpuDealSecurityInd(PdcpuSecInfo_t *pSec, PdcpuSecEnableInfo_t *pEnableInfo, SecuInd_t *pSecInd, PdcpuCfgResult_t *pResult)
82 /* get security enable information global variable */
84 pdcpuNullCheck(pEnableInfo);
85 pdcpuNullCheck(pSecInd);
87 /* for integrity protection */
88 if(ACTIVE_INT_STATE == pSec->intActiveFlag)
90 /* integrity protection is active for the UE, apply the indication */
91 if(IP_REQUIRED == pSecInd->IPIndication)
93 pEnableInfo->integrityEnableFlag = TRUE;
94 pEnableInfo->maxIPDataRate = pSecInd->maxIPdataRate;
95 pResult->secResPresent = FALSE;
97 }else if(IP_PREFERRED == pSecInd->IPIndication)
99 pEnableInfo->integrityEnableFlag = TRUE;
100 pEnableInfo->maxIPDataRate = pSecInd->maxIPdataRate;
101 pResult->secResPresent = TRUE;
102 pResult->secuResult.integrityProtectionResult= IP_RESULT_PERFORMED;
106 pEnableInfo->integrityEnableFlag = FALSE;
107 pResult->secResPresent = FALSE;
113 /* integrity protection is inactive for the UE */
114 pEnableInfo->integrityEnableFlag = FALSE;
115 if(IP_PREFERRED == pSecInd->IPIndication)
117 pResult->secResPresent = TRUE;
118 pResult->secuResult.integrityProtectionResult= IP_RESULT_NOT_PERFORMED;
123 if(ACTIVE_ENC_STATE == pSec->encActiveFlag)
125 /* ciphering is active for the UE, apply the indication */
126 if(CP_REQUIRED == pSecInd->CPIndication)
128 pEnableInfo->cipherEnableFlag = TRUE;
129 pResult->secResPresent = FALSE;
131 }else if(CP_PREFERRED == pSecInd->CPIndication)
133 pEnableInfo->cipherEnableFlag = TRUE;
134 pResult->secResPresent = TRUE;
135 pResult->secuResult.confidentialityProtectionResult = CP_RESULT_PERFORMED;
139 pEnableInfo->cipherEnableFlag = FALSE;
140 pResult->secResPresent = FALSE;
146 /* ciphering is inactive for the UE */
147 pEnableInfo->cipherEnableFlag = FALSE;
148 if(CP_PREFERRED == pSecInd->CPIndication)
150 pResult->secResPresent = TRUE;
151 pResult->secuResult.confidentialityProtectionResult= CP_RESULT_NOT_PERFORMED;
158 INT32 pdcpuRetFailResult(UpcCfgType_e cfgType, upcTempSessInfo_t *pCfgInfo, PdcpuCfgResult_t *pResult)
160 pdcpuLog(LOG_ERR,"[PDCPU] pdu session config failed\n");
163 if(PDU_SESSION_ADD == cfgType)
165 /* drb to setup list */
166 for(i=0; i<pCfgInfo->drbSetupNum; i++)
168 pResult->drbSetupFailedArray[i].drbId = pCfgInfo->pTempDrbSetupList[i].drbId;
169 pResult->drbSetupFailedArray[i].cause = RNL_UNSPECIFIED;
171 pResult->drbSetupFailNum = pCfgInfo->drbSetupNum;
172 pResult->pduSessionCause = RNL_UNSPECIFIED;
180 /*******************************************************************************
181 * To deal with PDU session to setup config
183 * ueE1apId : UE E1AP ID
184 * pPduSessionCfg : PDU session to setup config
185 * pResult : PDU session to setup result
188 *******************************************************************************/
189 INT32 pdcpuSessionAddProc(UINT64 ueE1apId, VOID *pCfgInfo, PdcpuCfgResult_t *pResult)
191 upcTempSessInfo_t *pSetupInfo = (upcTempSessInfo_t *)pCfgInfo;
192 upcTempDrbInfo_t *pDrbTemp = NULL;
193 PdcpuSecInfo_t *pSec = NULL;
194 PdcpuSecEnableInfo_t *pEnableInfo = NULL;
196 UINT16 pduSessionId = pSetupInfo->pduSessId;
197 pResult->pduSessionId = pduSessionId;
201 if(VOS_ERROR == cuupAddUeE1apid(ueE1apId, &ueIdx, &gPdcpuUeIdxTable))
203 pdcpuLog(LOG_ERR,"[PDCPU] add ueE1apId failed\n");
204 return pdcpuRetFailResult(PDU_SESSION_ADD,pCfgInfo,pResult);
207 /* check ue and security context block */
208 if((NULL == gPdcpuUeInfo[ueIdx]) || (NULL == gPdcpuUeInfo[ueIdx]->secInfo))
210 pdcpuLog(LOG_ERR,"[PDCPU] ue and security context block not exist\n");
211 return pdcpuRetFailResult(PDU_SESSION_ADD,pCfgInfo,pResult);
213 pSec = gPdcpuUeInfo[ueIdx]->secInfo;
215 /* alloc pdu session information */
216 pEnableInfo = gPdcpuUeInfo[ueIdx]->secEnableInfo[pduSessionId];
217 if(NULL == pEnableInfo)
219 pEnableInfo = VOS_Malloc(sizeof(PdcpuSecEnableInfo_t), gPdcpuModuleId);
220 if(NULL == pEnableInfo)
222 pdcpuLog(LOG_ERR,"[PDCPU] vos_malloc failed\n");
223 return pdcpuRetFailResult(PDU_SESSION_ADD,pCfgInfo,pResult);
225 VOS_MemZero(pEnableInfo, sizeof(PdcpuSecEnableInfo_t));
226 gPdcpuUeInfo[ueIdx]->secEnableInfo[pduSessionId] = pEnableInfo;
228 pEnableInfo->pduSessionId = pduSessionId;
230 /* deal with security indication */
231 if(VOS_ERROR == pdcpuDealSecurityInd(pSec, pEnableInfo, &pSetupInfo->secuIndi, pResult))
233 pdcpuLog(LOG_ERR,"[PDCPU] deal security indication failed\n");
234 return pdcpuRetFailResult(PDU_SESSION_ADD,pCfgInfo,pResult);
237 /* create pdcp entity */
239 for(i = 0; i < pSetupInfo->drbSetupNum; i++)
241 pDrbTemp = &pSetupInfo->pTempDrbSetupList[i];
243 if((NULL == pDrbTemp) || (FALSE == pDrbTemp->drbSetupAllowed))
248 if(VOS_OK == pdcpuCreateEntity(ueE1apId, ueIdx, pduSessionId, pDrbTemp))
250 pResult->drbSetupSuccessArray[pResult->drbSetupSuccessNum] = pDrbTemp->drbId;
251 pResult->drbSetupSuccessNum += 1;
254 pResult->drbSetupFailedArray[pResult->drbSetupFailNum].drbId = pDrbTemp->drbId;
255 pResult->drbSetupFailedArray[pResult->drbSetupFailNum].cause = RNL_PDCP_CONFIG_NOT_SUPPORT;
256 pResult->drbSetupFailNum += 1;
262 if(0 != pResult->drbSetupSuccessNum)
267 pResult->pduSessionCause = RNL_UNSPECIFIED;
268 pdcpuLog(LOG_ERR,"[PDCPU] all drbs setup failed\n");
273 /*******************************************************************************
274 * To manage pdcp-u entity
276 * ueE1apId : UE E1AP ID
277 * pPduSessionCfg : PDU Session Resource to setup item
278 * cfgType : configuration type
279 * pResult : result which will return to upc
281 * result: PDCP config result
282 *******************************************************************************/
283 INT32 pdcpuConfig(UINT64 ueE1apId, VOID *pCfgInfo, UpcCfgType_e cfgType, PdcpuCfgResult_t *pResult)
287 case PDU_SESSION_ADD:
289 pdcpuNullCheck(pCfgInfo);
290 pdcpuNullCheck(pResult);
291 VOS_MemZero(pResult, sizeof(PdcpuCfgResult_t));
292 pResult->cfgType = cfgType;
293 return pdcpuSessionAddProc(ueE1apId, pCfgInfo, pResult);
297 pdcpuLog(LOG_ERR,"[PDCPU] cfgType error\n");
305 /*******************************************************************************
306 * To get ue security information pointer
310 * pDrbSecInfo: ue security information pointer
311 *******************************************************************************/
312 PdcpuSecInfo_t *pdcpuAllocUeSecInfo(UINT16 ueIdx)
314 PdcpuSecInfo_t *pSecInfo = NULL;
315 PdcpuUeInfo_t *pPdcpUeInfo = NULL;
318 if(NULL == gPdcpuUeInfo[ueIdx])
320 pPdcpUeInfo = VOS_Malloc(sizeof(PdcpuUeInfo_t), gPdcpuModuleId);
321 pdcpuNullCheckRp(pPdcpUeInfo);
322 VOS_MemZero(pPdcpUeInfo, sizeof(PdcpuUeInfo_t));
323 gPdcpuUeInfo[ueIdx] = pPdcpUeInfo;
326 pPdcpUeInfo = gPdcpuUeInfo[ueIdx];
329 if(NULL == pPdcpUeInfo->secInfo)
331 pSecInfo = VOS_Malloc(sizeof(PdcpuSecInfo_t), gPdcpuModuleId);
332 pdcpuNullCheckRp(pSecInfo);
333 VOS_MemZero(pSecInfo, sizeof(PdcpuSecInfo_t));
334 pPdcpUeInfo->secInfo = pSecInfo;
337 pSecInfo = pPdcpUeInfo->secInfo;
340 VOS_MemZero(pSecInfo, sizeof(PdcpuSecInfo_t));
346 /*******************************************************************************
347 * To set ue security parameters. When receiving security information,
348 * pdcp-u shall save AS keys, AS algorithm and active integrity and ciphering.
350 * ueE1apId: UE E1AP ID
351 * secInfo: security information
355 *******************************************************************************/
356 INT32 pdcpuSetSecParam(UINT64 ueE1apId, SecuInfo_t *secInfo)
358 pdcpuNullCheck(secInfo);
361 if(VOS_ERROR == cuupAddUeE1apid(ueE1apId, &ueIdx, &gPdcpuUeIdxTable))
363 pdcpuLog(LOG_ERR,"[PDCPU] add ueE1apId failed\n");
367 /* find ue security struct */
368 PdcpuSecInfo_t *pDrbSecInfo = pdcpuAllocUeSecInfo(ueIdx);
369 pdcpuNullCheck(pDrbSecInfo);
371 /* activate integrity */
372 if(secInfo->secuAlgorithm.bitMask & SECURITY_ALGORITHM_INTERGRITY_PROTECTION_ALGORITHM)
374 UINT8 intAlgorithm = secInfo->secuAlgorithm.integrityProtectionAlgorithm;
375 UINT8 *pIntKey = secInfo->upSecukey.integrityProtectionKey.buffer;
376 UINT8 intKeyLen = secInfo->upSecukey.integrityProtectionKey.size; /* 128 bits */
378 if(intKeyLen < AS_KEY_LEN)
380 pdcpuLog(LOG_ERR,"[PDCPU] integrity parameter is wrong!\n");
381 pdcpuFreeSecInfo(ueIdx);
385 pDrbSecInfo->intActiveFlag = ACTIVE_INT_STATE; /* 0-inactive, 1-active */
386 if(intAlgorithm == NIA0 || intAlgorithm == NIA1 || intAlgorithm == NIA2)
388 pDrbSecInfo->intAlgorithm = intAlgorithm;
389 VOS_MemCpy(pDrbSecInfo->kUpInt, pIntKey, AS_KEY_LEN); /* 128 bits */
392 pDrbSecInfo->intActiveFlag = INACTIVE_INT_STATE;
393 pdcpuLog(LOG_ERR,"[PDCPU] integrity algorithm is %d, not supported!\n",intAlgorithm);
394 pdcpuFreeSecInfo(ueIdx);
399 pDrbSecInfo->intActiveFlag = INACTIVE_INT_STATE;
400 pdcpuLog(LOG_INFO,"[PDCPU] integrity is not config\n");
403 /* activate encryption */
404 UINT8 encAlgorithm = secInfo->secuAlgorithm.cipheringAlgorithm;
405 UINT8 *pEncKey = secInfo->upSecukey.encryptionKey.buffer;
406 UINT8 encKeyLen = secInfo->upSecukey.encryptionKey.size; /* 128 bits */
408 if(encKeyLen < AS_KEY_LEN)
410 pdcpuLog(LOG_ERR,"[PDCPU] encryption parameter is wrong!\n");
411 pdcpuFreeSecInfo(ueIdx);
415 pDrbSecInfo->encActiveFlag = ACTIVE_ENC_STATE; /* 0-inactive, 1-active */
416 if(encAlgorithm == NEA0 || encAlgorithm == NEA1 || encAlgorithm == NEA2)
418 pDrbSecInfo->encAlgorithm = encAlgorithm;
419 VOS_MemCpy(pDrbSecInfo->kUpEnc, pEncKey, AS_KEY_LEN); /* 128 bits */
422 pDrbSecInfo->encActiveFlag = INACTIVE_ENC_STATE;
423 pdcpuLog(LOG_ERR,"[PDCPU] encryption algorithm:%d, is not supported!\n", encAlgorithm);
424 pdcpuFreeSecInfo(ueIdx);
428 pDrbSecInfo->ueE1apId = ueE1apId;
429 pDrbSecInfo->ueIdx = ueIdx;
430 pDrbSecInfo->nhInd = FALSE;