VOS_VOID CNAS_HSM_WriteHrpdSessionInfoExNvim(VOS_VOID)
{
    CNAS_NVIM_HRPD_SESSION_INFO_EX_STRU                     stHrpdSessionInfoEx;
    CNAS_NVIM_HRPD_UE_REV_INFO_STRU                        *pstHrpdUERevInfo;

    NAS_MEM_SET_S(&stHrpdSessionInfoEx, sizeof(stHrpdSessionInfoEx), 0, sizeof(CNAS_NVIM_HRPD_SESSION_INFO_EX_STRU));

    stHrpdSessionInfoEx.ulSessionSeed = CNAS_HSM_GetSessionSeed();

    pstHrpdUERevInfo = CNAS_HSM_GetHrpdUERevInfoCtxAddr();

    NAS_MEM_CPY_S(&(stHrpdSessionInfoEx.stUERevInfo),
                  sizeof(stHrpdSessionInfoEx.stUERevInfo),
                  pstHrpdUERevInfo,
                  sizeof(CNAS_NVIM_HRPD_UE_REV_INFO_STRU));

    if (NV_OK != NV_Write(en_NV_Item_CNAS_HRPD_Session_Info_Ex,
                          &stHrpdSessionInfoEx, sizeof(CNAS_NVIM_HRPD_SESSION_INFO_EX_STRU)))
    {
        /* Make Error log is NV Write Fails */
        CNAS_ERROR_LOG(UEPS_PID_HSM, "CNAS_HSM_WriteHrpdSessionInfoNvimEx: Error in NV Write!");

        return;
    }

    CNAS_MNTN_LogWriteNVInfo(en_NV_Item_CNAS_HRPD_Session_Info_Ex,
                            sizeof(CNAS_NVIM_HRPD_SESSION_INFO_EX_STRU),
                            UEPS_PID_HSM,
                            (VOS_UINT8 *)&stHrpdSessionInfoEx);
}
VOS_VOID CNAS_HSM_WriteSessionKeepAliveInfoNvim(
    CNAS_HSM_SESSION_KEEP_ALIVE_INFO_STRU                  *pstSessionKeepAliveInfo
)
{
    CNAS_HSM_NVIM_SESSION_KEEP_ALIVE_INFO_STRU              stNvimKeepAliveInfo;

    NAS_MEM_SET_S(&stNvimKeepAliveInfo, sizeof(stNvimKeepAliveInfo), 0, sizeof(CNAS_HSM_NVIM_SESSION_KEEP_ALIVE_INFO_STRU));

    /* Update the values from Keep Alive Timer context to NV */
    stNvimKeepAliveInfo.usTsmpClose                  = pstSessionKeepAliveInfo->usTsmpClose;
    stNvimKeepAliveInfo.ucIsKeepAliveInfoValid       = pstSessionKeepAliveInfo->ucIsKeepAliveInfoValid;
    stNvimKeepAliveInfo.ulTsmpCloseRemainTime        = pstSessionKeepAliveInfo->ulTsmpCloseRemainTime;

    NAS_MEM_CPY_S(stNvimKeepAliveInfo.aulLastPowerOffSysTime,
                  sizeof(stNvimKeepAliveInfo.aulLastPowerOffSysTime),
                  pstSessionKeepAliveInfo->aulPowerOffSysTime,
                  sizeof(stNvimKeepAliveInfo.aulLastPowerOffSysTime));

    if (NV_OK != NV_Write(en_Nv_Item_CNAS_HRPD_Session_Keep_Alive_Info,
                         &stNvimKeepAliveInfo, sizeof(CNAS_HSM_SESSION_KEEP_ALIVE_INFO_STRU)))
    {
        /* Make Error log is NV Write Fails */
        CNAS_ERROR_LOG(UEPS_PID_HSM, "CNAS_HSM_WriteSessionKeepAliveInfoNvim: Error in NV Write!");

        return;
    }

    CNAS_MNTN_LogWriteNVInfo(en_Nv_Item_CNAS_HRPD_Session_Keep_Alive_Info,
                             sizeof(CNAS_HSM_SESSION_KEEP_ALIVE_INFO_STRU),
                             UEPS_PID_HSM,
                             (VOS_UINT8 *)&stNvimKeepAliveInfo);
}
VOS_VOID USIMM_VsimConfidentialDataVerifyErrHandle(VOS_VOID)
{
    NVIM_VSIM_HVSDH_NV_STRU             stDhNv = {0};
    VSIM_ALGORITHM_TYPE_ENUM_UINT32     enAlgorithm = {0};

    USIMM_ClearVsimGlobal();

    /* 清除公私钥 */
    if (NV_OK != NV_Read(en_NV_Item_VSIM_HVSDH_INFO, &stDhNv, sizeof(stDhNv)))
    {
        USIMM_WARNING_LOG("USIMM_VsimConfidentialDataVerify: Get HVSDT Info failed.");
    }

    enAlgorithm = stDhNv.enAlgorithm;

    VOS_MemSet(&stDhNv, 0, sizeof(NVIM_VSIM_HVSDH_NV_STRU));

    stDhNv.enAlgorithm = enAlgorithm;

    if (NV_OK != NV_Write(en_NV_Item_VSIM_HVSDH_INFO, &stDhNv, sizeof(stDhNv)))
    {
        USIMM_WARNING_LOG("USIMM_VsimConfidentialDataVerify: Clean HVSDT Info failed.");
    }

    USIMM_VsimReDhNegotiateInd();

    return;
}
VOS_VOID MN_CALL_LineInfo(
    MNPH_USIM_STATUS_ENUM_U32           enUsimStatus
)
{
    MN_CALL_ALS_LINE_INFO_STRU          stAlsInfo;
    VOS_UINT8                           aucMmaImsi[9];
    VOS_BOOL                            bWriteNvim;
    VOS_UINT32                          ulLength;

    ulLength = 0;
    stAlsInfo.enAlsLine = MN_CALL_ALS_LINE_NO_BUTT;
    PS_MEM_SET(stAlsInfo.aucMmaImsi, 0x00, sizeof(stAlsInfo.aucMmaImsi));

    if ( MNPH_USIM_STATUS_AVILABLE == enUsimStatus )
    {
        bWriteNvim = VOS_FALSE;

        if ( NV_OK != NV_Read(en_NV_Item_ALS_LINE_Config,&stAlsInfo,sizeof(stAlsInfo)))
        {
            return;
        }
        if ( USIMM_API_SUCCESS != NAS_USIMMAPI_GetCardIMSI(aucMmaImsi) )
        {
            return ;
        }

        /*线路号值不在取值范围内*/
        if  ( ( MN_CALL_ALS_LINE_NO_1 != stAlsInfo.enAlsLine )
           && ( MN_CALL_ALS_LINE_NO_2 != stAlsInfo.enAlsLine ) )
        {
            stAlsInfo.enAlsLine = MN_CALL_ALS_LINE_NO_1;
            bWriteNvim = VOS_TRUE;
        }

        /*判断NV中当前使用线路号对应的IMSI和SIM卡中IMSI是否相同,若不同则清NV
          项,并填入默认线路号1*/
        if ( 0 != VOS_StrCmp( (VOS_CHAR *)aucMmaImsi,
                               (VOS_CHAR *)stAlsInfo.aucMmaImsi) )
        {
            stAlsInfo.enAlsLine = MN_CALL_ALS_LINE_NO_1;
            PS_MEM_CPY(stAlsInfo.aucMmaImsi,aucMmaImsi,9);
            bWriteNvim = VOS_TRUE;
        }

        /*需要更新NVIM*/
        if ( VOS_TRUE == bWriteNvim )
        {
            NV_GetLength(en_NV_Item_ALS_LINE_Config, &ulLength);
            if (NV_OK != NV_Write(en_NV_Item_ALS_LINE_Config,
                     &stAlsInfo,
                     ulLength) )
            {
                TAF_WARNING_LOG(WUEPS_PID_TAF, "MN_CALL_LineInfo: en_NV_Item_ALS_LINE_Config NV Write Fail!");
            }
        }

        MN_CALL_UpdateAlsLineInfo(stAlsInfo.enAlsLine,VOS_FALSE);
    }
}
/*****************************************************************************
 函 数 名  : Taf_IndPhFreq
 功能描述  : 指定频点搜网
 输入参数  : MN_CLIENT_ID_T ClientId
             MN_OPERATION_ID_T   OpId
             TAF_IND_FREQ_STRU Freq
 输出参数  : TAF_SUCCESS or TAF_FAILURE
 返 回 值  :
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2006年10月24日
    作    者   : x51137
    修改内容   : 新生成函数

*****************************************************************************/
VOS_UINT32 Taf_IndPhFreq(MN_CLIENT_ID_T     ClientId,
                         MN_OPERATION_ID_T        OpId,
                         TAF_IND_FREQ_STRU        Freq)
{
    VOS_UINT16 temp_Freq;
    VOS_UINT16 temp_value;

    switch (Freq.RatType)
    {
    case TAF_SYS_SUBMODE_GSM:
        temp_value   = Freq.GsmBand;
        temp_value <<= 12;
        temp_Freq   = temp_value;
        temp_value  = Freq.IndFreq;
        temp_value &= 0x0fff;
        temp_Freq |= temp_value;

        /* write temp_GSM_Freq to NVIM */
        if (NV_OK != NV_Write( en_NV_Item_Gsm_Ind_Freq, &temp_Freq, sizeof(VOS_UINT16)))
        {
            return TAF_FAILURE;
        }

        break;

    case TAF_SYS_SUBMODE_WCDMA:

        /*write Freq to NVIM */
        temp_Freq = Freq.IndFreq;
        if (NV_OK != NV_Write( en_NV_Item_Wcdma_Ind_Freq, &temp_Freq, sizeof(VOS_UINT16)))
        {
            return TAF_FAILURE;
        }

        break;

    default:
        return TAF_FAILURE;
    }

    return TAF_SUCCESS;
}
uint8_t NVSettingsSave(NVSettings_t *settings)
{
    uint8_t failed;

    // Setup the checksum
    settings->checksum = NVSettingsChecksum(settings);
    
    // Open up the flash and save the settings
    NV_Open();
    NV_Erase(0, sizeof(*settings));
    failed = NV_Write(0, (uint8_t *)settings, sizeof(*settings));

    return failed;
}
VOS_VOID  TAF_APS_ClearDsFlowInfoInNv( VOS_VOID )
{
    TAF_APS_DSFLOW_NV_STRU              stApsDsflowNv;

    /* 初始化 */
    PS_MEM_SET(&stApsDsflowNv, 0, sizeof(TAF_APS_DSFLOW_NV_STRU));

    /* 刷新NV项 */
    if (NV_OK != NV_Write(en_NV_Item_DSFLOW_REPORT, &stApsDsflowNv, sizeof(TAF_APS_DSFLOW_NV_STRU)))
    {
        TAF_ERROR_LOG(WUEPS_PID_TAF, "TAF_APS_ClearDsFlowInfoInNv:Write NVIM Failed");
    }

    return;
}
VOS_VOID TAF_MMA_WritePlmnSelectionModeNvim(VOS_UINT8 ucReselMode)
{
    NAS_NVIM_SELPLMN_MODE_STRU          stPlmnSelMode;
    VOS_UINT32                          ulNvLength;

    ulNvLength                  = 0;
    stPlmnSelMode.usSelPlmnMode = ucReselMode;

    NV_GetLength(en_NV_Item_SelPlmn_Mode, &ulNvLength);

    if (NV_OK != NV_Write(en_NV_Item_SelPlmn_Mode,
                      &stPlmnSelMode,
                      ulNvLength))
    {
        MN_WARN_LOG("TAF_MMA_WritePlmnSelectionModeNvim:WARNING:  read en_NV_Item_SelPlmn_Mode fail");
    }

    return;
}
VOS_VOID NAS_UTRANCTRL_WriteUtranModeNvim(
    NAS_UTRANCTRL_UTRAN_MODE_ENUM_UINT8  enCurrentUtranMode
)
{
    NAS_UTRANCTRL_NVIM_UTRAN_MODE_STRU  stUtranMode;
    VOS_UINT32                          ulNvLength;

    stUtranMode.ucReserve   = 0;
    stUtranMode.ucUtranMode = enCurrentUtranMode;
    ulNvLength              = 0;

    /* 从NV中获取en_NV_Item_Utran_Mode NV项内容 */
    NV_GetLength(en_NV_Item_Utran_Mode, &ulNvLength);
    if ( NV_OK != NV_Write(en_NV_Item_Utran_Mode, &stUtranMode, ulNvLength) )
    {
        NAS_ERROR_LOG(WUEPS_PID_MMC, "NAS_UTRANCTRL_WriteUtranModeNvim:ERROR: NV_Write Error");

        return;
    }

    return;
}
VOS_VOID  TAF_APS_SaveDsFlowInfoToNv( VOS_VOID )
{
    TAF_APS_DSFLOW_STATS_CTX_STRU      *pstApsDsFlowCtx;
    TAF_APS_DSFLOW_NV_STRU              stApsDsflowNv;
    TAF_DSFLOW_QUERY_INFO_STRU          stDsFlowQryInfo;

    /* 初始化 */
    pstApsDsFlowCtx = TAF_APS_GetDsFlowCtxAddr();
    PS_MEM_SET(&stApsDsflowNv, 0, sizeof(TAF_APS_DSFLOW_NV_STRU));
    PS_MEM_SET(&stDsFlowQryInfo, 0, sizeof(TAF_DSFLOW_QUERY_INFO_STRU));

    if (VOS_TRUE == pstApsDsFlowCtx->ucApsDsFlowSave2NvFlg)
    {

        /* 获取历史流量信息项 */
        TAF_APS_QryAllRabDsFlowStats(&stDsFlowQryInfo);

        /* 刷新流量信息相关NV项 */
        stApsDsflowNv.ulDSLastLinkTime          = stDsFlowQryInfo.stCurrentFlowInfo.ulDSLinkTime;
        stApsDsflowNv.ulDSTotalLinkTime         = stDsFlowQryInfo.stTotalFlowInfo.ulDSLinkTime;
        stApsDsflowNv.ulDSTotalReceiveFluxHigh  = stDsFlowQryInfo.stTotalFlowInfo.ulDSReceiveFluxHigh;
        stApsDsflowNv.ulDSTotalReceiveFluxLow   = stDsFlowQryInfo.stTotalFlowInfo.ulDSReceiveFluxLow;
        stApsDsflowNv.ulDSTotalSendFluxHigh     = stDsFlowQryInfo.stTotalFlowInfo.ulDSSendFluxHigh;
        stApsDsflowNv.ulDSTotalSendFluxLow      = stDsFlowQryInfo.stTotalFlowInfo.ulDSSendFluxLow;

        /* 写NV项 */
        if (NV_OK != NV_Write(en_NV_Item_DSFLOW_REPORT, &stApsDsflowNv, sizeof(TAF_APS_DSFLOW_NV_STRU)))
        {
            TAF_ERROR_LOG(WUEPS_PID_TAF, "TAF_APS_SaveDsFlowInfoToNv: Write NVIM Failed");
        }
    }
    else
    {
        TAF_NORMAL_LOG(WUEPS_PID_TAF, "TAF_APS_SaveDsFlowInfoToNv: Save2NvFlg is not set.");
    }

    return;
}
VOS_VOID CNAS_HSM_WriteHrpdAccessAuthInfoNvim(VOS_VOID)
{
    CNAS_NVIM_HRPD_ACCESS_AUTH_INFO_STRU                    stHrpdAccessAuthInfo;
    CNAS_CCB_HRPD_ACCESS_AUTH_INFO_STRU                    *pstCurAccessAuthInfo = VOS_NULL_PTR;

    NAS_MEM_SET_S(&stHrpdAccessAuthInfo, sizeof(stHrpdAccessAuthInfo), 0, sizeof(CNAS_NVIM_HRPD_ACCESS_AUTH_INFO_STRU));

    pstCurAccessAuthInfo = CNAS_CCB_GetHrpdAccesAuthInfoAddr();
    if ((CNAS_HSM_SESSION_STATUS_OPEN == CNAS_HSM_GetSessionStatus())
     && (VOS_TRUE == pstCurAccessAuthInfo->ucAccessAuthAvailFlag))
    {
        stHrpdAccessAuthInfo.ucAccessAuthAvailFlag   = VOS_TRUE;
        stHrpdAccessAuthInfo.ucAccessAuthUserNameLen = pstCurAccessAuthInfo->ucAccessAuthUserNameLen;
        NAS_MEM_CPY_S(stHrpdAccessAuthInfo.aucAccessAuthUserName,
                      sizeof(stHrpdAccessAuthInfo.aucAccessAuthUserName),
                      pstCurAccessAuthInfo->aucAccessAuthUserName,
                      pstCurAccessAuthInfo->ucAccessAuthUserNameLen);
    }
    else
    {
        stHrpdAccessAuthInfo.ucAccessAuthAvailFlag   = VOS_FALSE;
    }

    if (NV_OK != NV_Write(en_Nv_Item_CNAS_HRPD_ACCESS_AUTH_INFO,
                          &stHrpdAccessAuthInfo, sizeof(CNAS_NVIM_HRPD_ACCESS_AUTH_INFO_STRU)))
    {
        /* Make Error log is NV Write Fails */
        CNAS_ERROR_LOG(UEPS_PID_HSM, "CNAS_HSM_WriteHrpdAccessAuthInfoNvim: Error in NV Write!");

        return;
    }

    CNAS_MNTN_LogWriteNVInfo(en_Nv_Item_CNAS_HRPD_ACCESS_AUTH_INFO,
                            sizeof(CNAS_NVIM_HRPD_ACCESS_AUTH_INFO_STRU),
                            UEPS_PID_HSM,
                            (VOS_UINT8 *)&stHrpdAccessAuthInfo);
}
/*****************************************************************************
 Function   : TF_NVAutoResume
 Description: resume NV
 Input      : void
 Return     : void
 Other      :
 *****************************************************************************/
VOS_VOID TF_NVAutoResume(VOS_VOID)
{
    VOS_INT                             lNVResumeFlag;
    VOS_UINT16                          usNVResumeFlag = VOS_FALSE;
    OAM_MNTN_NV_ERRLOG_EVENT_STRU       stErrLog;

    /* get the flag from DRV */
    lNVResumeFlag = DRV_GET_CDROM_FLAG();

    if ( DRV_ISO_NOT_LOAD == lNVResumeFlag )/* need to do */
    {
        /* clear DRV's flag */
        DRV_SET_CDROM_FLAG(DRV_ISO_LOAD);
    }

    /* Get Flag */
    if ( VOS_OK != NV_Read(en_NV_Resume_Flag,
                    (VOS_VOID *)(&usNVResumeFlag), sizeof(VOS_UINT16)) )
    {
        Print("TF can't read NV resume flag.\r\n");
    }

    if ( VOS_TRUE != usNVResumeFlag )
    {
        return;
    }

    /* light LED updating */
    PS_TURN_ON_UPDATE_VERSION_LED();

    /*lint -e534*/
    VOS_TaskLock();
    /*lint +e534*/

    if ( VOS_FALSE == DRV_BOOT_FORCELOAD_MODE_CHECK() )/* noraml update */
    {
        if ( VOS_OK != NV_RestoreAll() )
        {
            /* light LED.fail. */
            PS_TURN_ON_UPDATE_VERSION_NVFAIL_LED();

            Print("TF can't resume All NV.\r\n");

            DRV_SDMMC_CLEAR_WHOLE_SCREEN();
            DRV_SDMMC_UPDATE_DISPLAY(VOS_FALSE);

            /*lint -e534*/
            VOS_TaskUnlock();
            /*lint +e534*/

            return;
        }
        else
        {
            /* clear flag */
            usNVResumeFlag = VOS_FALSE;

            if ( VOS_OK != NV_Write(en_NV_Resume_Flag,
                            (VOS_VOID *)(&usNVResumeFlag), sizeof(VOS_UINT16)))
            {
                Print("TF can't write NV resume flag.\r\n");
            }

            /* light LED sucess. */
            PS_TURN_ON_UPDATE_VERSION_SUCCESS_LED();

            DRV_SDMMC_CLEAR_WHOLE_SCREEN();
            DRV_SDMMC_UPDATE_DISPLAY(VOS_TRUE);
        }
    }
    else    /* force update */
    {
        if ( VOS_OK != NV_RestoreManufacture() )
        {
            /* light LED.fail. */
            PS_TURN_ON_UPDATE_VERSION_NVFAIL_LED();

            Print("TF can't resume Manufacture NV.\r\n");

            DRV_SDMMC_CLEAR_WHOLE_SCREEN();
            DRV_SDMMC_UPDATE_DISPLAY(VOS_FALSE);

            /*lint -e534*/
            VOS_TaskUnlock();
            /*lint +e534*/

            return;
        }
        else
        {
            /* clear flag */
            usNVResumeFlag = VOS_FALSE;

            if ( VOS_OK != NV_Write(en_NV_Resume_Flag,
                            (VOS_VOID *)(&usNVResumeFlag), sizeof(VOS_UINT16)))
            {
                Print("TF can't write NV resume flag.\r\n");
            }

            /* light LED sucess. */
            PS_TURN_ON_UPDATE_VERSION_SUCCESS_LED();

            DRV_SDMMC_CLEAR_WHOLE_SCREEN();
            DRV_SDMMC_UPDATE_DISPLAY(VOS_TRUE);
        }
    }

    /* NV Backup*/
    if ( VOS_OK != NV_Backup() )
    {
        MNTN_RecordErrorLog(MNTN_OAM_MNTN_NV_ERRLOG_EVENT, (void *)&stErrLog,
                    sizeof(OAM_MNTN_NV_ERRLOG_EVENT_STRU));
    }

    /*lint -e534*/
    VOS_TaskUnlock();
    /*lint +e534*/

    return;
}
VOS_VOID CNAS_HSM_WriteHrpdSessionInfoNvim(VOS_VOID)
{
    VOS_UINT8                          *pucIccid;
    CNAS_HSM_HARDWARE_ID_INFO_STRU     *pstHwid;
    CNAS_HSM_UATI_INFO_STRU            *pstUatiInfo;
    CNAS_HSM_LOC_INFO_STRU             *pstLocInfo;
    CNAS_NVIM_HRPD_SESSION_INFO_STRU    stHrpdSessionInfo;

    NAS_MEM_SET_S(&stHrpdSessionInfo, sizeof(stHrpdSessionInfo), 0, sizeof(CNAS_NVIM_HRPD_SESSION_INFO_STRU));

    /* Update the values ucIsSessionOpen */
    if (CNAS_HSM_SESSION_STATUS_CLOSE == CNAS_HSM_GetSessionStatus())
    {
        stHrpdSessionInfo.enSessionStatus = CNAS_NVIM_HRPD_SESSION_STATUS_CLOSE;
    }
    else
    {
        stHrpdSessionInfo.enSessionStatus = CNAS_NVIM_HRPD_SESSION_STATUS_OPEN;
    }

    /* Update the values sesstype */
    stHrpdSessionInfo.enSessionType = (CNAS_NVIM_HRPD_SESSION_TYPE_ENUM_UINT8)CNAS_HSM_GetNegoSessionType();

    /* Update the values ICCID to NV */
    pucIccid = CNAS_CCB_GetCardIccIdAddr();

    NAS_MEM_CPY_S(stHrpdSessionInfo.aucIccid,
                  sizeof(stHrpdSessionInfo.aucIccid),
                  pucIccid,
                  sizeof(stHrpdSessionInfo.aucIccid));

    /* Update the values hardware id to NV */
    pstHwid = CNAS_HSM_GetHardwareIdInfo();

    stHrpdSessionInfo.stHwid.enHwidType    = (CNAS_NVIM_HARDWARE_ID_TYPE_ENUM_UINT32)pstHwid->enHwidType;
    stHrpdSessionInfo.stHwid.enHwidSrcType = (CNAS_NVIM_HARDWARE_ID_SRC_TYPE_ENUM_UINT32)pstHwid->enHwidSrcType;
    stHrpdSessionInfo.stHwid.ulEsn         = pstHwid->ulEsn;

    NAS_MEM_CPY_S(stHrpdSessionInfo.stHwid.aucMeId,
                  sizeof(stHrpdSessionInfo.stHwid.aucMeId),
                  pstHwid->aucMeId,
                  sizeof(VOS_UINT8) * CNAS_NVIM_MEID_OCTET_NUM);

    /* Update the uata values to nv */
    pstUatiInfo = CNAS_HSM_GetUatiInfoAddr();
    stHrpdSessionInfo.stUatiInfo.ucUATISubnetMask = pstUatiInfo->ucUATISubnetMask;
    stHrpdSessionInfo.stUatiInfo.ucUATIColorCode  = pstUatiInfo->ucUATIColorCode;

    stHrpdSessionInfo.stUatiInfo.ucUATIAssignMsgSeq = CNAS_HSM_GetCurrUATIAssignMsgSeqNum();
    NAS_MEM_CPY_S(stHrpdSessionInfo.stUatiInfo.aucCurUATI,
                  sizeof(stHrpdSessionInfo.stUatiInfo.aucCurUATI),
                  pstUatiInfo->aucCurUATI,
                  sizeof(VOS_UINT8) * CNAS_NVIM_UATI_OCTET_LENGTH);

    /* Update the loc info values to nv */
    pstLocInfo     = CNAS_HSM_GetLocInfoAddr();

    stHrpdSessionInfo.stLocInfo.lLatitude  = pstLocInfo->lLatitude;
    stHrpdSessionInfo.stLocInfo.lLongitude = pstLocInfo->lLongitude;

    if (NV_OK != NV_Write(en_Nv_Item_CNAS_HRPD_Session_Info,
                          &stHrpdSessionInfo, sizeof(CNAS_NVIM_HRPD_SESSION_INFO_STRU)))
    {
        /* Make Error log is NV Write Fails */
        CNAS_ERROR_LOG(UEPS_PID_HSM, "CNAS_HSM_WriteHrpdSessionInfoNvim: Error in NV Write!");

        return;
    }

    CNAS_MNTN_LogWriteNVInfo(en_Nv_Item_CNAS_HRPD_Session_Info,
                             sizeof(CNAS_NVIM_HRPD_SESSION_INFO_STRU),
                             UEPS_PID_HSM,
                             (VOS_UINT8 *)&stHrpdSessionInfo);
}
VOS_UINT32 PPM_LogPortSwitch(VOS_UINT32  ulPhyPort, VOS_BOOL ulEffect)
{
    CPM_PHY_PORT_ENUM_UINT32            enPhyCfgPort;
    CPM_PHY_PORT_ENUM_UINT32            enPhyIndPort;
    VOS_ULONG                           ulLockLevel;
    VOS_BOOL                            ulSndMsg;

    if ((CPM_OM_PORT_TYPE_USB != ulPhyPort) && (CPM_OM_PORT_TYPE_VCOM != ulPhyPort))
    {
        vos_printf("\r\n PPM_LogPortSwitch: enPhyPort is error.port %d\n", ulPhyPort);

        g_stPpmPortSwitchInfo.ulPortTypeErr++;

        return VOS_ERR;
    }

    /* 切换的端口与当前端口一致不切换 */
    if (ulPhyPort == g_stPortCfg.enPortNum)
    {
        DRV_SOCP_VOTE(SOCP_VOTE_PPM_RCV, SOCP_VOTE_FOR_WAKE);
        /* 切换到VCOM输出时在LOG延迟写入开启情况下需要重新设置SOCP的超时中断 */
        if (CPM_OM_PORT_TYPE_VCOM == g_stPortCfg.enPortNum)
        {
            (VOS_VOID)DRV_SOCP_SET_TIMEOUT(SOCP_TIMEOUT_TRF, 0);
        }

        /* 为了规避USB输出时开启了延时写入无法连接工具,切换到USB输出时需要重新设置SOCP的超时中断到默认值 */
        if (CPM_OM_PORT_TYPE_USB == g_stPortCfg.enPortNum)
        {
            (VOS_VOID)DRV_SOCP_SET_TIMEOUT(SOCP_TIMEOUT_TRF, 0x17);
        }
        DRV_SOCP_VOTE(SOCP_VOTE_PPM_RCV, SOCP_VOTE_FOR_SLEEP);
        return VOS_OK;
    }

    g_stPpmPortSwitchInfo.ulStartSlice = OM_GetSlice();

    enPhyCfgPort = CPM_QueryPhyPort(CPM_OM_CFG_COMM);
    enPhyIndPort = CPM_QueryPhyPort(CPM_OM_IND_COMM);

    ulSndMsg = VOS_FALSE;

    VOS_SpinLockIntLock(&g_stPpmPortSwitchSpinLock, ulLockLevel);

    /* 切换到VCOM输出 */
    if (CPM_OM_PORT_TYPE_VCOM == ulPhyPort)
    {
        /* 当前是USB输出 */
        if ((CPM_CFG_PORT == enPhyCfgPort) && (CPM_IND_PORT == enPhyIndPort))
        {
            /* 需要断开连接 */
            ulSndMsg = VOS_TRUE;

            CPM_DisconnectPorts(CPM_CFG_PORT, CPM_OM_CFG_COMM);
            CPM_DisconnectPorts(CPM_IND_PORT, CPM_OM_IND_COMM);
        }

        /* 当前OM走VCOM上报 */
        CPM_ConnectPorts(CPM_VCOM_CFG_PORT, CPM_OM_CFG_COMM);
        CPM_ConnectPorts(CPM_VCOM_IND_PORT, CPM_OM_IND_COMM);

        g_stPortCfg.enPortNum = CPM_OM_PORT_TYPE_VCOM;
    }
    /* 切换到USB输出 */
    else
    {
        /* 当前是VCOM输出 */
        if ((CPM_VCOM_CFG_PORT == enPhyCfgPort) && (CPM_VCOM_IND_PORT == enPhyIndPort))
        {
            /* 断开连接 */
            ulSndMsg = VOS_TRUE;

            CPM_DisconnectPorts(CPM_VCOM_CFG_PORT, CPM_OM_CFG_COMM);
            CPM_DisconnectPorts(CPM_VCOM_IND_PORT, CPM_OM_IND_COMM);
        }

        /* OM走USB上报 */
        CPM_ConnectPorts(CPM_CFG_PORT, CPM_OM_CFG_COMM);
        CPM_ConnectPorts(CPM_IND_PORT, CPM_OM_IND_COMM);

        g_stPortCfg.enPortNum = CPM_OM_PORT_TYPE_USB;
    }

    VOS_SpinUnlockIntUnlock(&g_stPpmPortSwitchSpinLock, ulLockLevel);

    if (VOS_TRUE == ulSndMsg)
    {
        PPM_DisconnectAllPort(OM_LOGIC_CHANNEL_CNF);
    }
    DRV_SOCP_VOTE(SOCP_VOTE_PPM_RCV, SOCP_VOTE_FOR_WAKE);
    /* 切换到VCOM输出时在LOG延迟写入开启情况下需要重新设置SOCP的超时中断 */
    if (CPM_OM_PORT_TYPE_VCOM == g_stPortCfg.enPortNum)
    {
        (VOS_VOID)DRV_SOCP_SET_TIMEOUT(SOCP_TIMEOUT_TRF, 0);
    }

    /* 为了规避USB输出时开启了延时写入无法连接工具,切换到USB输出时需要重新设置SOCP的超时中断到默认值 */
    if (CPM_OM_PORT_TYPE_USB == g_stPortCfg.enPortNum)
    {
        (VOS_VOID)DRV_SOCP_SET_TIMEOUT(SOCP_TIMEOUT_TRF, 0x17);
    }
    DRV_SOCP_VOTE(SOCP_VOTE_PPM_RCV, SOCP_VOTE_FOR_SLEEP);


    g_stPpmPortSwitchInfo.ulSwitchSucc++;
    g_stPpmPortSwitchInfo.ulEndSlice = OM_GetSlice();

    if (VOS_TRUE == ulEffect)
    {
        if (VOS_OK != NV_Write(en_NV_Item_Om_Port_Type, &g_stPortCfg, sizeof(OM_CHANNLE_PORT_CFG_STRU)))
        {
            vos_printf("\r\n PPM_LogPortSwitch: NV_Write fail\n");
        }
    }

    return VOS_OK;
}
VOS_VOID MN_CALL_LineInfo(
    MNPH_USIM_STATUS_ENUM_U32           enUsimStatus
)
{
    MN_CALL_ALS_LINE_INFO_STRU          stAlsInfo;
    VOS_UINT8                           aucMmaImsi[9];
    VOS_BOOL                            bWriteNvim;
    VOS_UINT32                          ulLength;
    VOS_UINT32                          ulGetCardImsiRslt;

    ulGetCardImsiRslt   = USIMM_API_RESULT_BUTT;

    ulLength = 0;
    stAlsInfo.enAlsLine = MN_CALL_ALS_LINE_NO_BUTT;
    PS_MEM_SET(stAlsInfo.aucMmaImsi, 0x00, sizeof(stAlsInfo.aucMmaImsi));

    if ( MNPH_USIM_STATUS_AVILABLE == enUsimStatus )
    {
        bWriteNvim = VOS_FALSE;

        if ( NV_OK != NV_Read(en_NV_Item_ALS_LINE_Config,&stAlsInfo,sizeof(stAlsInfo)))
        {
            return;
        }

        ulGetCardImsiRslt   = NAS_USIMMAPI_GetCardIMSI(aucMmaImsi);
        if ( USIMM_API_SUCCESS !=  ulGetCardImsiRslt)
        {
            if (VOS_TRUE == TAF_SDC_IsImsiAvailableInCurrSimStatus(TAF_SDC_GetSimStatus()))
            {

#if (FEATURE_ON == FEATURE_PTM)
                /* 记录获取卡IMSI异常log */
                TAF_SDC_GetCardImsiFailRecord(ulGetCardImsiRslt, aucMmaImsi);
#endif
            }

            return ;
        }

        /*线路号值不在取值范围内*/
        if  ( ( MN_CALL_ALS_LINE_NO_1 != stAlsInfo.enAlsLine )
           && ( MN_CALL_ALS_LINE_NO_2 != stAlsInfo.enAlsLine ) )
        {
            stAlsInfo.enAlsLine = MN_CALL_ALS_LINE_NO_1;
            bWriteNvim = VOS_TRUE;
        }

        /*判断NV中当前使用线路号对应的IMSI和SIM卡中IMSI是否相同,若不同则清NV
          项,并填入默认线路号1*/
        if ( 0 != VOS_StrCmp( (VOS_CHAR *)aucMmaImsi,
                               (VOS_CHAR *)stAlsInfo.aucMmaImsi) )
        {
            stAlsInfo.enAlsLine = MN_CALL_ALS_LINE_NO_1;
            PS_MEM_CPY(stAlsInfo.aucMmaImsi,aucMmaImsi,9);
            bWriteNvim = VOS_TRUE;
        }

        /*需要更新NVIM*/
        if ( VOS_TRUE == bWriteNvim )
        {
            (VOS_VOID)NV_GetLength(en_NV_Item_ALS_LINE_Config, &ulLength);
            if (NV_OK != NV_Write(en_NV_Item_ALS_LINE_Config,
                     &stAlsInfo,
                     ulLength) )
            {
                TAF_WARNING_LOG(WUEPS_PID_TAF, "MN_CALL_LineInfo: en_NV_Item_ALS_LINE_Config NV Write Fail!");
            }
        }

        (VOS_VOID)MN_CALL_UpdateAlsLineInfo(stAlsInfo.enAlsLine,VOS_FALSE);
    }
}
VOS_VOID TAF_MTA_RcvAtNvwrSecCtrlSetReq( VOS_VOID *pMsg )
{
    AT_MTA_MSG_STRU                    *pstAtMtaReqMsg;
    AT_MTA_NVWRSECCTRL_SET_REQ_STRU    *pstNvwrSecCtrlReq;
    MTA_AT_RESULT_CNF_STRU              stNvwrSecCtrlCnf;
    TAF_NV_NVWR_SEC_CTRL_STRU           stNvwrSecCtrlNV;
    IMEI_STRU                           stImeiSrc;
    IMEI_STRU                           stImeiPara;
    VOS_UINT32                          ulResult;
    VOS_UINT32                          ulImeiLen;
    MODEM_ID_ENUM_UINT16                enModemId;
    VOS_UINT8                           aucImeiStr[TAF_NVIM_ITEM_IMEI_SIZE + 1];

    /* 局部变量初始化 */
    pstAtMtaReqMsg          = (AT_MTA_MSG_STRU *)pMsg;
    pstNvwrSecCtrlReq       = (AT_MTA_NVWRSECCTRL_SET_REQ_STRU *)pstAtMtaReqMsg->aucContent;

    /* SC提供的RSA封装需要调用者将解密后结果的预期长度传入 */
    ulImeiLen               = MTA_IMEI_LEN;

    PS_MEM_SET(&stNvwrSecCtrlNV, 0x00, sizeof(stNvwrSecCtrlNV));
    PS_MEM_SET(&stNvwrSecCtrlCnf, 0x00, sizeof(stNvwrSecCtrlCnf));
    PS_MEM_SET(&stImeiSrc, 0x00, sizeof(stImeiSrc));
    PS_MEM_SET(&stImeiPara, 0x00, sizeof(stImeiPara));
    PS_MEM_SET(aucImeiStr, 0x00, sizeof(aucImeiStr));

    /* 如果单板没有HUK则不作安全校验 */
    if (VOS_TRUE == DRV_CHECK_HUK_IS_VALID())
    {
        /* 单板已经写入HUK但未下发安全密文则返回失败 */
        if (VOS_TRUE != pstNvwrSecCtrlReq->ucSecStrFlg)
        {
            stNvwrSecCtrlCnf.enResult = MTA_AT_RESULT_DEVICE_SEC_SIGNATURE_FAIL;

            /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
            TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                              ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                              sizeof(stNvwrSecCtrlCnf),
                              (VOS_UINT8*)&stNvwrSecCtrlCnf );

            return;
        }

        /* 由PID获取MODEMID */
        enModemId = VOS_GetModemIDFromPid(UEPS_PID_MTA);

        /* 调用SC接口读取IMEI号码 */
        ulResult = SC_PERS_NvRead(enModemId, en_NV_Item_IMEI, stImeiSrc.aucImei, TAF_NVIM_ITEM_IMEI_SIZE);

        if (SC_ERROR_CODE_NO_ERROR != ulResult)
        {
            /* 异常,返回结果给AT模块 */
            stNvwrSecCtrlCnf.enResult = TAF_MTA_ConvertScErr(ulResult);

            /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
            TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                              ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                              sizeof(stNvwrSecCtrlCnf),
                              (VOS_UINT8*)&stNvwrSecCtrlCnf );

            return;
        }

        /* 调用SC模块接口, 对密文进行RSA解密 */
        ulResult = SC_FAC_RsaDecrypt(pstNvwrSecCtrlReq->aucSecString,
                                     AT_RSA_CIPHERTEXT_LEN,
                                     aucImeiStr,
                                     &ulImeiLen);

        if (MTA_IMEI_LEN != ulImeiLen)
        {
            ulResult = SC_ERROR_CODE_RSA_DECRYPT_FAIL;
        }

        if (SC_ERROR_CODE_NO_ERROR != ulResult)
        {
            /* 异常,返回结果给AT模块 */
            stNvwrSecCtrlCnf.enResult = TAF_MTA_ConvertScErr(ulResult);

            /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
            TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                              ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                              sizeof(stNvwrSecCtrlCnf),
                              (VOS_UINT8*)&stNvwrSecCtrlCnf );

            return;
        }

        /* 数字字符串转换为数字串 */
        if (VOS_OK != TAF_MTA_AcNums2DecNums(aucImeiStr, stImeiPara.aucImei, ulImeiLen))
        {
            stNvwrSecCtrlCnf.enResult = MTA_AT_RESULT_DEVICE_SEC_SIGNATURE_FAIL;

            /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
            TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                              ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                              sizeof(stNvwrSecCtrlCnf),
                              (VOS_UINT8*)&stNvwrSecCtrlCnf );

            return;
        }

        /* 校验IMEI码 */
        if (0 != PS_MEM_CMP(stImeiPara.aucImei, stImeiSrc.aucImei, ulImeiLen))
        {
            stNvwrSecCtrlCnf.enResult = MTA_AT_RESULT_DEVICE_SEC_SIGNATURE_FAIL;

            /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
            TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                              ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                              sizeof(stNvwrSecCtrlCnf),
                              (VOS_UINT8*)&stNvwrSecCtrlCnf );

            return;
        }
    }

    /* 修改安全控制NV */
    if (NV_OK == NV_Read(en_NV_Item_NVWR_SEC_CTRL, &stNvwrSecCtrlNV, sizeof(stNvwrSecCtrlNV)))
    {
        stNvwrSecCtrlNV.ucSecType = pstNvwrSecCtrlReq->ucSecType;

        if (NV_OK == NV_Write(en_NV_Item_NVWR_SEC_CTRL, &stNvwrSecCtrlNV, sizeof(stNvwrSecCtrlNV)))
        {
            /* 设置成功 */
            stNvwrSecCtrlCnf.enResult = MTA_AT_RESULT_NO_ERROR;

            /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
            TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                              ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                              sizeof(stNvwrSecCtrlCnf),
                              (VOS_UINT8*)&stNvwrSecCtrlCnf );

            return;
        }
    }

    /* NV修改失败 */
    stNvwrSecCtrlCnf.enResult = MTA_AT_RESULT_ERROR;

    /* 返回跨核消息ID_MTA_AT_APSEC_SET_CNF到AT模块 */
    TAF_MTA_SndAtMsg( &pstAtMtaReqMsg->stAppCtrl,
                      ID_MTA_AT_NVWRSECCTRL_SET_CNF,
                      sizeof(stNvwrSecCtrlCnf),
                      (VOS_UINT8*)&stNvwrSecCtrlCnf );

    return;
}