VOS_UINT32 USIMM_VsimConfidentialDataVerify(VOS_VOID) { VOS_UINT32 ulImsiLen; VOS_UINT32 ulSimkeyLen; VOS_INT32 lResult; VOS_UINT32 ulRecordNum; VOS_INT lDataLen; VOS_INT lHashLen; VOS_UINT8 *pucImsi; VOS_UINT8 aucData[USIMM_EF_IMSI_LEN * 2 + USIMM_VSIM_SECUR_MAX_LEN * 4]; VOS_UINT8 aucHashData[USIMM_VSIM_HASH_LEN]; VOS_UINT8 aucKey[VSIM_DH_AGREE_KEY] = {0}; VOS_UINT8 aucCipher[USIMM_VSIM_SIM_KEY_HASH_LEN/2]; VOS_UINT8 aucSimkey[USIMM_VSIM_SIM_KEY_HASH_LEN/2]; NVIM_VSIM_HVSDH_NV_STRU stNVDHKey; DH_KEY stDHPara; VSIM_KEYDATA_STRU stCPrivateKey; /* 单板私钥 */ VOS_MemSet(&stDHPara, 0, sizeof(stDHPara)); /* 查询文件位置,这里不能直接调用USIMM_GetCachedFile,服务状态的全局变量未设置 */ if (VOS_ERR == USIMM_PoolFindFile(EFIMSI, &ulRecordNum, USIMM_UNLIMIT_APP)) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: File Could not Found"); return VOS_ERR; } if (VOS_NULL_PTR == gstUSIMMPOOL.astpoolRecord[ulRecordNum].pucContent) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: File Content is Empty"); return VOS_ERR; } ulImsiLen = gstUSIMMPOOL.astpoolRecord[ulRecordNum].usLen; pucImsi = gstUSIMMPOOL.astpoolRecord[ulRecordNum].pucContent; USIMM_VsimBase16Encode(pucImsi, aucData, ulImsiLen); VOS_MemCpy(aucData + ulImsiLen * 2, g_stUSIMMVSimAuthInfo.stBase16Ki.aucData, g_stUSIMMVSimAuthInfo.stBase16Ki.ulLen); VOS_MemCpy(aucData + ulImsiLen * 2 + g_stUSIMMVSimAuthInfo.stBase16Ki.ulLen, g_stUSIMMVSimAuthInfo.stBase16Opc.aucData, g_stUSIMMVSimAuthInfo.stBase16Opc.ulLen); lDataLen = (VOS_INT)(ulImsiLen * 2 + g_stUSIMMVSimAuthInfo.stBase16Ki.ulLen + g_stUSIMMVSimAuthInfo.stBase16Opc.ulLen); /* 用IMSI+KI+OPC的长度和内容数据计算HASH */ lHashLen = USIMM_VSIM_HASH_LEN; lResult = CRYPTO_HASH((VOS_CHAR *)aucData, lDataLen, CRYPTO_ALGORITHM_SHA256, (VOS_CHAR *)aucHashData, &lHashLen); if ((VOS_OK != lResult) ||(USIMM_VSIM_HASH_LEN != lHashLen)) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: CRYPTO_HASH Failed"); return VOS_ERR; } if (NV_OK != NV_Read(en_NV_Item_VSIM_HVSDH_INFO, &stNVDHKey, sizeof(NVIM_VSIM_HVSDH_NV_STRU))) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: NV Read Key is Failed"); return VOS_ERR; } /* [false alarm]:fortify */ if (VOS_OK != USIMM_VsimHUKDecode(stNVDHKey.stCPrivateKey.aucKey, VSIM_DH_PRIVATE_KEY, stCPrivateKey.aucKey, &stCPrivateKey.ulKeyLen)) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: USIMM_VsimHUKDecode is Failed");/* [false alarm]:fortify */ return VOS_ERR; } VOS_MemCpy(stDHPara.privateValue, stCPrivateKey.aucKey, VSIM_DH_PRIVATE_KEY); stDHPara.priVallen = VSIM_DH_PRIVATE_KEY; DH_FillFixParams(&stDHPara); if (VOS_OK != DH_ComputeAgreedKey(aucKey, stNVDHKey.stSPublicKey.aucKey, &stDHPara)) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: DH_ComputeAgreedKey is Failed"); return VOS_ERR; } AESEncrypt(aucHashData, lHashLen, aucKey, sizeof(aucKey), aucCipher, USIMM_VSIM_SIM_KEY_HASH_LEN/2); if (VOS_OK != USIMM_VsimBase16Decode((VOS_CHAR *)g_stUSIMMVSimAuthInfo.aucSimKeyHash, USIMM_VSIM_SIM_KEY_HASH_LEN, aucSimkey, &ulSimkeyLen)) { USIMM_ERROR_LOG("USIMM_VsimConfidentialDataVerify: USIMM_VsimBase16Decode Failed"); return VOS_ERR; } #ifndef OAM_DMT if (VOS_OK == VOS_MemCmp(aucSimkey, aucCipher, USIMM_VSIM_SIM_KEY_HASH_LEN/2)) { return VOS_OK; } return VOS_ERR; #else return VOS_OK; #endif /*OAM_DMT*/ }
VOS_VOID TAF_MMA_USIMRefreshFileProc( VOS_UINT16 usEfId, VOS_UINT16 usEfLen, VOS_UINT8 *pucEf ) { USIMM_READFILE_CNF_STRU *pUsimTafMsg; VOS_UINT8 *pucImsi = VOS_NULL_PTR; MMA_GET_ICC_ID_ST *pstIccId = VOS_NULL_PTR; pucImsi = TAF_SDC_GetSimImsi(); pstIccId = TAF_MMA_GetIccIdInfo(); switch (usEfId) { case USIMM_GSM_EFONS_ID: /*lint -e961*/ pUsimTafMsg = (USIMM_READFILE_CNF_STRU *)PS_MEM_ALLOC(WUEPS_PID_MMA, (VOS_UINT32)(sizeof(USIMM_READFILE_CNF_STRU) - 4 + usEfLen)); /*lint +e961*/ if (VOS_NULL_PTR == pUsimTafMsg) { MMA_ERRORLOG("MMA_USIMReadRefreshFileProc():ERROR:MALLOC FAIL"); return; } /*lint -e961*/ PS_MEM_SET(pUsimTafMsg, 0, (VOS_UINT32)(sizeof(USIMM_READFILE_CNF_STRU) - 4 + usEfLen)); /*lint +e961*/ pUsimTafMsg->stCmdResult.ulResult = MMA_SUCCESS; pUsimTafMsg->usEfLen = usEfLen; PS_MEM_CPY(pUsimTafMsg->aucEf, pucEf, usEfLen); TAF_MMA_ReadCphsFileCnf(pUsimTafMsg); PS_MEM_FREE(WUEPS_PID_MMA, pUsimTafMsg); break; case USIMM_ICCID_ID: MMA_MEM_SET(&(pstIccId->stIccId), 0, sizeof(TAF_PH_ICC_ID_STRU)); MMA_MEM_CPY(pstIccId->stIccId.aucIccId, pucEf, usEfLen); pstIccId->stIccId.ucLen = (VOS_UINT8)usEfLen; TAF_MMA_ReadIccIdFileCnf(); break; case USIMM_USIM_EFIMSI_ID: case USIMM_GSM_EFIMSI_ID: /* 判断IMSI是否改变 */ if (0 != VOS_MemCmp(pucImsi, pucEf, NAS_MAX_IMSI_LENGTH)) { if (TAF_MMA_FSM_MAIN != TAF_MMA_GetCurrFsmId()) { TAF_MMA_SndInterUsimChangeInd(); break; } if (STA_FSM_NULL == g_StatusContext.ulFsmState) { break; } TAF_MMA_SndInterUsimChangeInd(); } MMA_WARNINGLOG("MMA_USIMReadRefreshFileProc():WARNING:Refresh File Id IMSI"); break; case USIMM_USIM_EFPNN_ID: case USIMM_USIM_EFPNNI_ID: MMA_INFOLOG("MMA_USIMReadRefreshFileProc():INFO:Refresh File PNN"); break; case USIMM_USIM_EFOPL_ID: case USIMM_GSM_EFOPL_ID: MMA_INFOLOG("MMA_USIMReadRefreshFileProc():INFO:Refresh File OPL"); break; case USIMM_GSM_EFCSP_ID: TAF_MMA_RcvCustomerServiceProfileFile(VOS_OK, usEfLen, pucEf); break; case USIMM_ATTUSIM_EFRATMODE_ID: TAF_MMA_RcvRatModeFileRefresh(usEfLen, pucEf); break; default: MMA_WARNINGLOG("MMA_USIMReadRefreshFileProc():WARNING:UNKNOW EFID RECEIVE!"); break; } }
VOS_VOID USIMM_VsimDecodeAuthType(VOS_CHAR *pucStr, VOS_UINT32 ulStrLen, USIMM_VSIM_AUTH_ENUM_UINT32*pulAuthType) { VOS_CHAR *pcTemp; VOS_UINT32 ulDataLen; *pulAuthType = USIMM_VSIM_AUTH_NULL; if(VOS_NULL == ulStrLen) { USIMM_ERROR_LOG("USIMM_VSIMDecodeAuthType: Auth Type is NULL!"); return; } pcTemp = (VOS_CHAR*)VOS_MemAlloc(WUEPS_PID_USIM, DYNAMIC_MEM_PT, ulStrLen); if(VOS_NULL_PTR == pcTemp) { USIMM_ERROR_LOG("USIMM_VSIMDecodeAuthType: VOS_MemAlloc is NULL!"); return; } OAM_XML_GetStrContent(pucStr, ulStrLen, pcTemp, &ulDataLen); if(VOS_NULL == ulDataLen) { USIMM_ERROR_LOG("USIMM_VSIMDecodeAuthType: Auth Type Content is NULL!"); VOS_MemFree(WUEPS_PID_USIM, pcTemp); return; } /*lint -e418*/ if(VOS_OK == VOS_MemCmp(USIMM_VSIM_AUTH_3G_STR, pcTemp, ulDataLen)) { *pulAuthType = USIMM_VSIM_MILENAGE; } else if(VOS_OK == VOS_MemCmp(USIMM_VSIM_AUTH_2GV1_STR, pcTemp, ulDataLen)) { *pulAuthType = USIMM_VSIM_COMPV1; } else if(VOS_OK == VOS_MemCmp(USIMM_VSIM_AUTH_2GV2_STR, pcTemp, ulDataLen)) { *pulAuthType = USIMM_VSIM_COMPV2; } else if(VOS_OK == VOS_MemCmp(USIMM_VSIM_AUTH_2GV3_STR, pcTemp, ulDataLen)) /*lint +e418*/ { *pulAuthType = USIMM_VSIM_COMPV3; } else { USIMM_ERROR_LOG("USIMM_VSIMDecodeAuthType: Auth Type is not support!"); } VOS_MemFree(WUEPS_PID_USIM, pcTemp); return; }
VOS_UINT32 USIMM_DecodeVsimEf(OAM_XML_NODE_STRU *pstXmlNode) { VOS_CHAR *pcTemp; VOS_UINT32 ulStrLen; VOS_UINT32 ulResult; OAM_XML_NODE_STRU *pstTmpNode; OAM_XML_NODE_ATTRIBUTE_STRU *pstAttr; if(POOLMAXNUM < OAM_XML_GetChildCount(pstXmlNode)) /*文件个数超过缓冲池,目前仅告警*/ { USIMM_WARNING_LOG("USIMM_AddVSIMFileToPoll: The EF Num is more than Pool Space!"); } pstTmpNode = pstXmlNode->pstFirstChild; if(VOS_NULL_PTR == pstTmpNode) /*当前无子节点,文件解析失败*/ { USIMM_WARNING_LOG("USIMM_AddVSIMFileToPoll: The EF Num is NULL!"); return VOS_ERR; } while (VOS_NULL_PTR != pstTmpNode) { if(VOS_NULL_PTR == pstTmpNode->pstFirstAttrib) /*需要依赖节点属性和节点值解析文件*/ { USIMM_WARNING_LOG("USIMM_AddVSIMFileToPoll: The EF Name is NULL!"); pstTmpNode = pstTmpNode->pstNexBrother; /*指向下一个节点*/ continue; /*空节点继续解析*/ } pstAttr = OAM_XML_SearchAttNodeByName(pstTmpNode->pstFirstAttrib, USIMM_VSIM_NAME_STR); if(VOS_NULL_PTR == pstAttr) { USIMM_WARNING_LOG("USIMM_AddVSIMFileToPoll: The XML item NAME Attr is NULL!"); pstTmpNode = pstTmpNode->pstNexBrother; /*指向下一个节点*/ continue; /*空节点继续解析*/ } /*申请文件名称的内存*/ pcTemp = (VOS_CHAR*)VOS_MemAlloc(WUEPS_PID_USIM, DYNAMIC_MEM_PT, pstAttr->ulValueLength); if(VOS_NULL_PTR == pcTemp) { USIMM_ERROR_LOG("USIMM_VSIMDecodeCardType: VOS_MemAlloc is NULL!"); return VOS_ERR; } /*过滤文件名称中特殊字符*/ OAM_XML_GetStrContent(pstAttr->pcAttribValue, pstAttr->ulValueLength, pcTemp, &ulStrLen); /*判断当前文件名称*/ /*lint -e960 -e418*/ if((VOS_OK == VOS_MemCmp(USIMM_VSIM_KI_STR, pcTemp, ulStrLen)) ||(VOS_OK == VOS_MemCmp(USIMM_VSIM_OPC_STR, pcTemp, ulStrLen))) /*lint +e960 +e418*/ { ulResult = USIMM_AddVsimAuthPara(pcTemp, ulStrLen, pstTmpNode->pcNodeValue, pstTmpNode->ulValueLength); } else if (VOS_OK == VOS_MemCmp(USIMM_VSIM_VERIFY_HASH_STR, pcTemp, ulStrLen)) { ulResult = USIMM_AddVsimVerifyHashPara(pcTemp, ulStrLen, pstTmpNode->pcNodeValue, pstTmpNode->ulValueLength); } else { ulResult = USIMM_AddVsimFileToPool(pcTemp, ulStrLen, pstTmpNode->pcNodeValue, pstTmpNode->ulValueLength); } VOS_MemFree(WUEPS_PID_USIM, pcTemp); /*释放文件名称的内存*/ if(VOS_OK != ulResult) { USIMM_ERROR_LOG("USIMM_VSIMDecodeCardType: Decode XML File Node is Failed!"); } pstTmpNode = pstTmpNode->pstNexBrother; /*指向下一个节点*/ } return VOS_OK; }
VOS_UINT32 USIMM_AddVsimAuthPara(VOS_CHAR *pucFileStr, VOS_UINT32 ulFileLen, VOS_CHAR *pcValue, VOS_UINT32 ulValueLen) { VOS_UINT32 ulContentLen; VOS_CHAR *pcContent; VOS_UINT8 aucAuthPara[USIMM_VSIM_SIM_KEY_HASH_LEN]; VOS_UINT32 ulAuthParaLen = 0; VOS_UINT32 ulResult; if((VOS_NULL_PTR == pcValue)||(VOS_NULL == ulValueLen)) { USIMM_ERROR_LOG("USIMM_AddVsimAuthPara: Para is NULL!"); return VOS_ERR; } pcContent = (VOS_CHAR*)VOS_MemAlloc(WUEPS_PID_USIM, DYNAMIC_MEM_PT, ulValueLen); if(VOS_NULL_PTR == pcContent) { USIMM_ERROR_LOG("USIMM_AddVsimAuthPara: VOS_MemAlloc is NULL!"); return VOS_ERR; } /*过滤特殊字符*/ OAM_XML_FilterStrInvalidChar(pcValue, ulValueLen, pcContent, &ulContentLen); if(VOS_NULL == ulContentLen) { USIMM_ERROR_LOG("USIMM_AddVsimAuthPara: OAM_XML_GetStrContent return 0!"); VOS_MemFree(WUEPS_PID_USIM, pcContent); return VOS_ERR; } if((USIMM_VSIM_SECUR_MAX_LEN*2) < ulContentLen) /*检查Base16编码长度,不能超过当前全局变量的最大值*/ { USIMM_ERROR_LOG("USIMM_AddVsimAuthPara: Base16Decode Result is too long!"); VOS_MemFree(WUEPS_PID_USIM, pcContent); return VOS_ERR; } ulResult = OAM_XML_GetIntArray(pcContent, ulContentLen, aucAuthPara, &ulAuthParaLen); if((VOS_ERR == ulResult) || (0 == ulAuthParaLen) || (USIMM_VSIM_SECUR_MAX_LEN < ulAuthParaLen)) /*检查转换后的结果*/ { USIMM_ERROR_LOG("USIMM_AddVsimAuthPara: Base16Decode is Failed!"); VOS_MemFree(WUEPS_PID_USIM, pcContent); return VOS_ERR; } /* 保存转换后的内容,转换前的内容也要保存下来 */ if (VOS_OK == VOS_MemCmp(USIMM_VSIM_KI_STR, pucFileStr, ulFileLen)) { g_stUSIMMVSimAuthInfo.ucKILen = (VOS_UINT8)ulAuthParaLen; VOS_MemCpy(g_stUSIMMVSimAuthInfo.aucKi, aucAuthPara, ulAuthParaLen); g_stUSIMMVSimAuthInfo.stBase16Ki.ulLen = ulContentLen; VOS_MemCpy(g_stUSIMMVSimAuthInfo.stBase16Ki.aucData, pcContent, ulContentLen); } else if(VOS_OK == VOS_MemCmp(USIMM_VSIM_OPC_STR, pucFileStr, ulFileLen)) { g_stUSIMMVSimAuthInfo.ucOpcLen = (VOS_UINT8)ulAuthParaLen; VOS_MemCpy(g_stUSIMMVSimAuthInfo.aucOpc, aucAuthPara, ulAuthParaLen); g_stUSIMMVSimAuthInfo.stBase16Opc.ulLen = ulContentLen; VOS_MemCpy(g_stUSIMMVSimAuthInfo.stBase16Opc.aucData, pcContent, ulContentLen); } else { VOS_MemCpy(g_stUSIMMVSimAuthInfo.aucSimKeyHash, aucAuthPara, USIMM_VSIM_SIM_KEY_HASH_LEN); } VOS_MemFree(WUEPS_PID_USIM, pcContent); return VOS_OK; }
VOS_UINT32 USIMM_AddVsimFileToPool(VOS_CHAR *pucFileStr, VOS_UINT32 ulStrLen, VOS_CHAR *pcValue, VOS_UINT32 ulValueLen) { VOS_UINT32 i; VOS_UINT32 ulFileIndex; VOS_UINT8 *pucContent; VOS_UINT32 ulContentLen; if((VOS_NULL_PTR == pcValue)||(VOS_NULL == ulValueLen)) { USIMM_WARNING_LOG("USIMM_AddVSIMFileToPool: Para is NULL!"); return VOS_OK; /*跳过节点插入后续文件*/ } for(i=0; i<ARRAYSIZE(g_astUSIMMVSimFileInfo); i++) { if(VOS_OK == VOS_MemCmp(g_astUSIMMVSimFileInfo[i].pcVSIMName, pucFileStr, ulStrLen)) { break; } } if(i >= ARRAYSIZE(g_astUSIMMVSimFileInfo)) { USIMM_WARNING_LOG("USIMM_AddVSIMFileToPoll: the File Name is not support!"); return VOS_OK; } pucContent = (VOS_UINT8*)VOS_MemAlloc(WUEPS_PID_USIM, DYNAMIC_MEM_PT, ulValueLen); if(VOS_NULL_PTR == pucContent) { USIMM_ERROR_LOG("USIMM_AddVSIMFileToPoll: VOS_MemAlloc is NULL!"); return VOS_ERR; } /*过滤特殊字符*/ if(VOS_OK != OAM_XML_GetIntArray(pcValue, ulValueLen, pucContent, &ulContentLen)) { USIMM_ERROR_LOG("USIMM_AddVSIMFileToPoll: OAM_XML_GetIntArray is Failed!"); VOS_MemFree(WUEPS_PID_USIM, pucContent); return VOS_OK; /*如果错误,继续解析后面的内容,最后由必选文件检查决定卡状态*/ } if(VOS_OK == USIMM_VsimPoolSearchFile(g_astUSIMMVSimFileInfo[i].usFileID, &ulFileIndex)) { USIMM_ERROR_LOG("USIMM_AddVSIMFileToPoll: File is Already Exist!"); VOS_MemFree(WUEPS_PID_USIM, pucContent); return VOS_OK; /*重复插入就保持之前的值不变*/ } /*插入失败认为是POOL已经满了*/ if(VOS_OK != USIMM_PoolInsertOneFile(g_astUSIMMVSimFileInfo[i].usFileID, (VOS_UINT16)ulContentLen, pucContent, USIMM_UNLIMIT_APP, USIMM_EFSTRUCTURE_TRANSPARENT)) { USIMM_ERROR_LOG("USIMM_AddVSIMFileToPoll: USIMM_PoolInsertOneFile Error"); /*如果错误,继续解析后面的内容,最后由必选文件检查决定卡状态*/ } VOS_MemFree(WUEPS_PID_USIM, pucContent); return VOS_OK; }
VOS_UINT32 TAF_SPM_IsAppCustomEmergencyNum( MN_CALL_CALLED_NUM_STRU *pstDialNum, VOS_UINT32 *pulEmerCatExist, VOS_UINT8 *pucEmerCategory ) { TAF_SDC_USIM_STATUS_ENUM_UINT8 enSimStatus; TAF_SDC_CUSTOM_ECC_CTX_STRU *pstCustomCallEmerNumCtx = VOS_NULL_PTR; VOS_UINT8 i; pstCustomCallEmerNumCtx = TAF_SDC_GetCustomCallEccNumCtx(); /* 获取卡的状态,根据卡的存在与否做不同处理 */ enSimStatus = TAF_SDC_GetSimStatus(); /* 检查是否APP定制紧急呼号码 */ for (i = 0; i < pstCustomCallEmerNumCtx->stCustomEccNumList.ucEccNumCount; i++) { if (pstDialNum->ucNumLen != pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].ucEccNumLen) { continue; } if (0 == VOS_MemCmp(pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].aucEccNum, pstDialNum->aucBcdNum, pstDialNum->ucNumLen) ) { if (TAF_SDC_USIM_STATUS_NO_PRESENT == enSimStatus) { /* 号码是有卡时的紧急呼号码 */ if ((MN_CALL_ECC_NUM_VALID_SIM_ABSENT != pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].ucValidSimPresent)) { continue; } } else { /* 号码是无卡时的紧急呼号码 */ if ((MN_CALL_ECC_NUM_VALID_SIM_PRESENT != pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].ucValidSimPresent)) { continue; } /* 有卡时,号码是仅非正常服务时的紧急呼号码,若当前CS正常服务则不作为紧急呼号码 */ if ( (VOS_TRUE == TAF_SDC_IsCsNormalService()) && (pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].ucAbnormalServiceFlg == VOS_TRUE) ) { continue; } } *pulEmerCatExist = TAF_SPM_IsValidEmerCategory(pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].ucCategory); if (VOS_TRUE == *pulEmerCatExist) { *pucEmerCategory = (pstCustomCallEmerNumCtx->stCustomEccNumList.astCustomEccNumList[i].ucCategory & MN_CALL_EMER_CATEGORG_VAL_MAX); } return VOS_TRUE; } } return VOS_FALSE; }