/*lint -e961*/
VOS_UINT32  NAS_EMM_DeriveKasme(        const VOS_UINT8 *pucCK,
                                        const VOS_UINT8 *pucIK,
                                        VOS_UINT8 *pucKasme)
{
    VOS_UINT8                       aucAlgParam[NAS_EMM_SECU_MAX_ALG_PARAM_LEN];
    VOS_UINT8                       aucKeyParam[NAS_LMM_SECU_AUTH_KEY_ASME_LEN];
    VOS_UINT32                      ulIndex      = 0;
    VOS_UINT32                      ulRslt = NAS_EMM_SECU_FAIL;
    NAS_EMM_PLMN_ID_STRU           *pstSerPlmn = VOS_NULL_PTR;

    NAS_EMM_SECU_LOG_INFO("NAS_EMM_DeriveKasme is entered.");

    /*空指针*/
    if((VOS_NULL_PTR == pucCK) || (VOS_NULL_PTR == pucIK))
    {
         NAS_EMM_SECU_LOG_ERR("NAS_EMM_DeriveKasme:-> Input Pointer Null!");
         return NAS_EMM_SECU_FAIL;
    }

    /*获取 current PLMN作为计算Kasme的参数*/
    pstSerPlmn = NAS_LMM_GetEmmInfoPresentPlmnAddr();

    /* 编码KDF算法需要的参数 */

    /*encode FC*/
    aucAlgParam[ulIndex++] = NAS_EMM_SECU_ALG_PARAM_KASME_FC;

    /*encode PLMNID&Len*/
    aucAlgParam[ulIndex++] = pstSerPlmn->aucPlmnId[0];
    aucAlgParam[ulIndex++] = pstSerPlmn->aucPlmnId[1];
    aucAlgParam[ulIndex++] = pstSerPlmn->aucPlmnId[2];

    aucAlgParam[ulIndex++] = NAS_EMM_SECU_ALG_PARAM_KASME_PRE_LEN;
    aucAlgParam[ulIndex++] = NAS_EMM_SECU_ALG_PARAM_KASME_PLMNID_LEN;

    /* encode SQN&AK */
    NAS_LMM_MEM_CPY(                    &aucAlgParam[ulIndex],
                                        NAS_EMM_AuthReqAutnAddr(),
                                        NAS_EMM_SECU_SQN_LEN);

    ulIndex                             += NAS_EMM_SECU_SQN_LEN;

    aucAlgParam[ulIndex++]              = NAS_EMM_SECU_ALG_PARAM_KASME_PRE_LEN;
    aucAlgParam[ulIndex++]              = NAS_EMM_SECU_SQN_LEN;

    NAS_LMM_MEM_CPY((VOS_VOID *)aucKeyParam,pucCK,NAS_EMM_SECU_CKEY_LEN);

    NAS_LMM_MEM_CPY((VOS_VOID *)&aucKeyParam[NAS_EMM_SECU_CKEY_LEN],
                                      pucIK,NAS_EMM_SECU_IKEY_LEN);

    ulRslt = NAS_EMM_KDF_HmacSha256(aucAlgParam,ulIndex,aucKeyParam,pucKasme);

    return ulRslt;

}
VOS_VOID  NAS_EMM_UsimAuthSucc( const USIMM_AUTH_CNF_STRU  *pstUsimAuthCnf  )
{
    VOS_UINT32                          ulDeriveKeyRslt;
    USIMM_TELECOM_AUTH_CNF_STRU        *pstAuthCnf;

    NAS_EMM_SECU_LOG_INFO("NAS_EMM_UsimAuthSucc entered.");

    pstAuthCnf = (USIMM_TELECOM_AUTH_CNF_STRU*)&pstUsimAuthCnf->cnfdata.stTELECnf;

    /*1.更新新安全上下文:保存AuthReq消息携带的Ksi并计算新的Kasme*/
    NAS_EMM_ClearNonCurNativeSecuCntxt();
    NAS_EMM_SetSecuNewNativeKSIasme(NAS_EMM_AuthReqKsi());
    ulDeriveKeyRslt = NAS_EMM_DeriveKasme(&pstAuthCnf->aucCK[1],
                                          &pstAuthCnf->aucIK[1],
                                          NAS_EMM_GetSecuNewNativeKasmeAddr());
    if( NAS_EMM_SECU_FAIL == ulDeriveKeyRslt)
    {
        NAS_EMM_SECU_LOG_ERR("NAS_EMM_PreProcUsimAuthCnf: Caculate Kasme ERR.");
    }

    /*安全上下文状态迁移*/
    NAS_EMM_SecuStateConvert(NAS_LMM_GetSecuCurFsmCS() ,EMM_NEW_SECU_EXIST);

    /*2. 启动T3416,保存Rand 和 Res*/
    /*启动T3416*/
    NAS_LMM_StartPtlTimer(                TI_NAS_EMM_PTL_T3416);

    /*保存Rand*/
    NAS_EMM_GetSecuAuthOpRand() = NAS_EMM_BIT_SLCT;
    NAS_LMM_MEM_CPY(                    NAS_EMM_GetSecuAuthRandAddr(),
                                        NAS_EMM_AuthReqRandAddr(),
                                        NAS_EMM_SECU_AUTH_RAND_LEN);

    /*保存Res:pstUsimAuthCnf->u.aucAuthRes第一个字节为Res的长度*/
    NAS_EMM_GetSecuAuthResLen() = pstAuthCnf->aucAuthRes[NAS_EMM_USIM_CNF_RES_L_POS];
    NAS_LMM_MEM_CPY( NAS_EMM_GetSecuAuthResVAddr(),
                   &(pstAuthCnf->aucAuthRes[NAS_EMM_USIM_CNF_RES_V_POS]),
                     NAS_EMM_GetSecuAuthResLen());

    /*3. 如果AUTH失败次数不为零,出栈并将失败次数清零*/
    if(0 != NAS_EMM_GetAuthFailTimes())
    {
        NAS_EMM_FSM_PopState();
        NAS_EMM_GetAuthFailTimes() = 0;
    }

    /*4. 发送AUTH RSP*/
    NAS_EMM_SendAuthRsp();

    return;
}
VOS_VOID NAS_LMM_PreProcAnyStateUsimAuthCnf(const USIMM_AUTH_CNF_STRU  *pstUsimAuthCnf)
{
    VOS_UINT32                          ulDeriveKeyRslt;
    USIMM_TELECOM_AUTH_CNF_STRU        *pstAuthCnf;

    NAS_LMM_PUBM_LOG_INFO("NAS_LMM_PreProcUsimAuthCnf is entered");

    pstAuthCnf = (USIMM_TELECOM_AUTH_CNF_STRU*)&pstUsimAuthCnf->cnfdata.stTELECnf;

    if( USIMM_AUTH_UMTS_SUCCESS == pstUsimAuthCnf->enResult)
    {
        /*1.更新新安全上下文:保存AuthReq消息携带的Ksi并计算新的Kasme*/
        NAS_EMM_ClearNonCurNativeSecuCntxt();
        NAS_EMM_SetSecuNewNativeKSIasme(NAS_EMM_AuthReqKsi());
        ulDeriveKeyRslt = NAS_EMM_DeriveKasme(&pstAuthCnf->aucCK[1],
                                                  &pstAuthCnf->aucIK[1],
                                                  NAS_EMM_GetSecuNewNativeKasmeAddr());

        if( NAS_EMM_SECU_FAIL == ulDeriveKeyRslt)
        {
            NAS_EMM_SECU_LOG_ERR("NAS_EMM_PreProcUsimAuthCnf: Caculate Kasme ERR.");
        }

        /*安全上下文状态迁移*/
        NAS_EMM_SecuStateConvert(NAS_LMM_GetSecuCurFsmCS() ,EMM_NEW_SECU_EXIST);

        /*2. 启动T3416,保存Rand 和 Res*/
        /*启动T3416*/
        NAS_LMM_StartPtlTimer(TI_NAS_EMM_PTL_T3416);

        /* 鉴权成功,清空OpId */
        NAS_EMM_GetSecuAuthOpId() = 0;

        /*保存Rand*/
        NAS_EMM_GetSecuAuthOpRand() = NAS_EMM_BIT_SLCT;
        NAS_LMM_MEM_CPY(NAS_EMM_GetSecuAuthRandAddr(),
                            NAS_EMM_AuthReqRandAddr(),
                            NAS_EMM_SECU_AUTH_RAND_LEN);

        /*保存Res:pstUsimAuthCnf->u.aucAuthRes第一个字节为Res的长度*/
        NAS_EMM_GetSecuAuthResLen() = pstAuthCnf->aucAuthRes[NAS_EMM_USIM_CNF_RES_L_POS];
        NAS_LMM_MEM_CPY( NAS_EMM_GetSecuAuthResVAddr(),
                           &(pstAuthCnf->aucAuthRes[NAS_EMM_USIM_CNF_RES_V_POS]),
                             NAS_EMM_GetSecuAuthResLen());

    }

    return;
}
/*****************************************************************************
 Function Name  : NAS_LMM_DecodeSimImsi
 Discription    : 解码IMSI
 Input          : pstNvCtrlTbl:公共处理结构
 Output         : 解码后的数据
 Return         :
 History:
*****************************************************************************/
VOS_UINT32  NAS_LMM_DecodeSimImsi(const NAS_NVIM_CTRL_TBL *pstNvCtrlTbl)
{
    VOS_UINT8                           *pucImsi;
    NAS_EMM_UEID_STRU                   *pstUeId;

    pstUeId = (VOS_VOID *)NAS_EMM_GetEmmGlobleAddr(NAS_LMM_GLOBLE_PAEA_UEID);

    pucImsi = (VOS_VOID *)NAS_EMM_GetEmmGlobleAddr(NAS_LMM_GLOBLE_PAEA_IMSI);

    if((NAS_NVIM_NULL_PTR == pstUeId) || (NAS_NVIM_NULL_PTR == pucImsi))
    {
        /* 打印查询的 类型 */
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimImsi: Point is Null");
        return NAS_LMM_NVIM_FAIL;
    }

    if (NAS_LMM_NVIM_IMSI_FILE_LEN != pstNvCtrlTbl->usNvDataLen)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimImsi: USIM IMSI LENGTH ERR");

        return NAS_LMM_NVIM_FAIL;
    }

    pstUeId->bitOpImsi                  = NAS_NVIM_BIT_SLCT;

    NAS_LMM_MEM_CPY(                     pucImsi,
                                        pstNvCtrlTbl->pNvData,
                                        NAS_LMM_NVIM_IMSI_FILE_LEN);
/*PC REPLAY MODIFY BY LEILI DELETE*/

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeSimImsi: IMSI IS ");
    NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(),pucImsi,NAS_LMM_NVIM_IMSI_FILE_LEN);

    return  NAS_LMM_NVIM_OK;
}
VOS_VOID NAS_EMM_AttSetMsId(VOS_VOID                *pstRcvMsg)
{
    NAS_EMM_CN_ATTACH_ACP_STRU          *pstAttAcp;

    if (NAS_EMM_NULL_PTR == pstRcvMsg)
    {
        /*打印错误*/
        NAS_EMM_ATTACH_LOG_ERR("NAS_EMM_AppSendAttSucc: Input para is invalid!");
        return;
    }

    pstAttAcp = (NAS_EMM_CN_ATTACH_ACP_STRU *)pstRcvMsg;

    if(pstAttAcp->ucBitOpMsId == NAS_EMM_AD_BIT_SLCT)
    {
        NAS_EMM_GLO_AD_OP_GetMsId()   = NAS_EMM_AD_BIT_SLCT;
        NAS_LMM_MEM_CPY(                NAS_EMM_GLO_AD_GetMsIdAddr(),
                                        &pstAttAcp->stMsId,
                                        sizeof(NAS_EMM_MSID_STRU));
    }
    else
    {
        NAS_EMM_GLO_AD_OP_GetMsId()   = NAS_EMM_AD_BIT_NO_SLCT;
        NAS_LMM_MEM_SET(                NAS_EMM_GLO_AD_GetMsIdAddr(),
                                        0,
                                        sizeof(NAS_EMM_MSID_STRU));
    }
    return;
}
VOS_VOID NAS_EMM_AttSetEplms(VOS_VOID                *pstRcvMsg)
{
    NAS_EMM_CN_ATTACH_ACP_STRU          *pstAttAcp;

    if (NAS_EMM_NULL_PTR == pstRcvMsg)
    {
        /*打印错误*/
        NAS_EMM_ATTACH_LOG_ERR("NAS_EMM_AppSendAttSucc: Input para is invalid!");
        return;
    }

    pstAttAcp = (NAS_EMM_CN_ATTACH_ACP_STRU *)pstRcvMsg;

    if(pstAttAcp->ucBitOpPlmnList == NAS_EMM_AD_BIT_SLCT)
    {
        NAS_LMM_GetEmmInfoNetInfoOpEplmnListAddr()   = NAS_EMM_AD_BIT_SLCT;
        NAS_LMM_MEM_CPY(                NAS_LMM_GetEmmInfoNetInfoEplmnListAddr(),
                                        &pstAttAcp->stPlmnList,
                                        sizeof(MMC_LMM_EPLMN_STRU));
    }
    else
    {
        NAS_LMM_GetEmmInfoNetInfoOpEplmnListAddr()   = NAS_EMM_AD_BIT_NO_SLCT;

        NAS_LMM_MEM_SET(                NAS_LMM_GetEmmInfoNetInfoEplmnListAddr(),
                                        0,
                                        sizeof(MMC_LMM_EPLMN_STRU));
    }
    return;
}
/*****************************************************************************
 Function Name   : NAS_EMM_TcSendDataInd
 Description     : 向TC发送ID_EMM_ETC_DATA_IND消息
 Input           : None
 Output          : None
 Return          : VOS_VOID

 History         :
    1.lihong00150010      2009-10-16  Draft Enact

*****************************************************************************/
VOS_VOID  NAS_EMM_TcSendDataInd
(
    const NAS_EMM_CN_MSGCON_STRU       *pstTcMsg
)
{
    EMM_ETC_DATA_IND_STRU               *pEmmTcDataIndMsg = VOS_NULL_PTR;
    VOS_UINT32                          ulTcMsgLen;
    VOS_UINT32                          ulDataIndLenNoHeader;


    ulTcMsgLen                          = pstTcMsg->ulMsgLen;
    ulDataIndLenNoHeader                = NAS_EMM_CountTcDataIndLen(ulTcMsgLen);


    /*申请消息内存*/
    if (ulTcMsgLen < 4)
    {
        pEmmTcDataIndMsg = (VOS_VOID *)NAS_LMM_ALLOC_MSG(sizeof(EMM_ETC_DATA_IND_STRU));

    }
    else
    {
        pEmmTcDataIndMsg = (VOS_VOID *)NAS_LMM_ALLOC_MSG(
                               ulDataIndLenNoHeader + NAS_EMM_LEN_VOS_MSG_HEADER);
    }

    /*判断申请结果,若失败打印错误并退出*/
    if (NAS_EMM_NULL_PTR == pEmmTcDataIndMsg)
    {
        /*打印错误*/
        NAS_EMM_ATTACH_LOG_ERR("NAS_EMM_TcSendDataInd: MSG ALLOC ERR!");
        return;

    }

    /*构造ID_EMM_ETC_DATA_IND消息*/
    /*填充消息头*/
    NAS_EMM_COMP_AD_TC_MSG_HEADER(pEmmTcDataIndMsg, ulDataIndLenNoHeader);

    /*填充消息ID*/
    pEmmTcDataIndMsg->ulMsgId         = ID_EMM_ETC_DATA_IND;

    /*填充消息内容*/
    pEmmTcDataIndMsg->stTcMsg.ulTcMsgSize = pstTcMsg->ulMsgLen;

    NAS_LMM_MEM_CPY(                 pEmmTcDataIndMsg->stTcMsg.aucTcMsg,
                                     pstTcMsg->aucMsg,
                                     pstTcMsg->ulMsgLen);

    /*向TC发送ID_EMM_ETC_DATA_IND消息*/
    NAS_LMM_SEND_MSG(                   pEmmTcDataIndMsg);

    /* 打印发送消息 */
    NAS_EMM_ATTACH_LOG_NORM("NAS_EMM_TcSendDataInd:NORM:Send ID_EMM_ETC_DATA_IND!");
}
VOS_UINT32  NAS_EMM_MsAnyStateSsAnyStateMsgUsimAuthCnf(  VOS_UINT32  ulMsgId,
                                                         VOS_VOID   *pMsg )
{
    USIMM_AUTH_CNF_STRU      *pstUsimAuthCnf = VOS_NULL_PTR;

    (VOS_VOID)ulMsgId;
    NAS_EMM_SECU_LOG_INFO("NAS_EMM_MsAnyStateSsAnyStateMsgUsimAuthCnf entered!");
    NAS_LMM_PrintFsmState(NAS_LMM_PARALLEL_FSM_EMM);

    pstUsimAuthCnf = (USIMM_AUTH_CNF_STRU *)pMsg;
    /* 如果OpId不同,说明在这个鉴权CNF之前又收到了网侧的鉴权请求 ,继续等待USIM回复*/
    if(pstUsimAuthCnf->ucOpId != NAS_EMM_GetSecuAuthOpId())
    {
        return NAS_LMM_MSG_HANDLED;
    }

    /* 鉴权成功,清空OpId */
    NAS_EMM_GetSecuAuthOpId() = 0;
    /*根据 USIM_AUTH_CNF中的结果进行不同处理*/
    switch(pstUsimAuthCnf->enResult)
    {
             /*USIM鉴权成功*/
        case USIMM_AUTH_UMTS_SUCCESS:
             NAS_EMM_UsimAuthSucc(pstUsimAuthCnf);
             break;

             /*USIM鉴权失败:MAC FAIL*/
        case USIMM_AUTH_MAC_FAILURE:
             NAS_EMM_SndMmcSimAuthFailInd(LMM_MMC_SIM_AUTH_FAIL_MAC_FAILURE);
             NAS_EMM_UsimAuthFail(NAS_EMM_AUTH_MAC_FAILURE);
             break;

             /*USIM鉴权失败:SYNCFAIL*/
        case USIMM_AUTH_SYNC_FAILURE:
             NAS_EMM_SndMmcSimAuthFailInd(LMM_MMC_SIM_AUTH_FAIL_SYNC_FAILURE);

             /*获取USIM_AUTH_CNF携带的AUTS:pstUsimAuthCnf->u.aucAuts第一个字节为Auts的长度*/
             NAS_LMM_MEM_CPY( NAS_EMM_GetSecuAuthAutsAddr(),
                            &(pstUsimAuthCnf->cnfdata.stTELECnf.aucAuts[NAS_EMM_USIM_CNF_AUTS_V_POS]),
                              pstUsimAuthCnf->cnfdata.stTELECnf.aucAuts[NAS_EMM_USIM_CNF_AUTS_L_POS]);

             /*调用失败处理函数*/
             NAS_EMM_UsimAuthFail(NAS_EMM_AUTH_SYNC_FAILURE);
             break;

        default:
             NAS_EMM_SECU_LOG_ERR("NAS_EMM_MsAnyStateSsAnyStateMsgUsimAuthCnf: USIM CNF RSLT ERR.");
             NAS_EMM_SndMmcSimAuthFailInd(LMM_MMC_SIM_AUTH_FAIL_OTHER);
             break;
    }

    return NAS_LMM_MSG_HANDLED;
}
VOS_VOID    NAS_EMM_EsmSendDataInd (const NAS_EMM_CN_MSGCON_STRU *pstEsmBearerReq)
{
    EMM_ESM_DATA_IND_STRU                *pEmmEsmBearerReqMsg;
    VOS_UINT32                          ulEsmMsgLen;
    VOS_UINT32                          ulDataIndLenNoHeader;


    ulEsmMsgLen                          = pstEsmBearerReq->ulMsgLen;
    ulDataIndLenNoHeader                = NAS_EMM_CountEsmDataIndLen(ulEsmMsgLen);


    /*申请消息内存*/
    if (ulEsmMsgLen < 4)
    {
        pEmmEsmBearerReqMsg = (VOS_VOID *)NAS_LMM_ALLOC_MSG(sizeof(EMM_ESM_DATA_IND_STRU));

    }
    else
    {
        pEmmEsmBearerReqMsg = (VOS_VOID *)NAS_LMM_ALLOC_MSG(
                                  ulDataIndLenNoHeader + NAS_EMM_LEN_VOS_MSG_HEADER);
    }

    /*判断申请结果,若失败打印错误并退出*/
    if (NAS_EMM_NULL_PTR == pEmmEsmBearerReqMsg)
    {
        /*打印错误*/
        NAS_EMM_ATTACH_LOG_ERR("NAS_EMM_EsmSendDataInd: MSG ALLOC ERR!");
        return;

    }

    /*构造ID_EMM_ESM_DATA_IND消息*/
    /*填充消息头*/
    NAS_EMM_COMP_AD_ESM_MSG_HEADER(pEmmEsmBearerReqMsg, ulDataIndLenNoHeader);

    /*填充消息ID*/
    pEmmEsmBearerReqMsg->ulMsgId         = ID_EMM_ESM_DATA_IND;

    /*填充消息内容*/
    pEmmEsmBearerReqMsg->stEsmMsg.ulEsmMsgSize = pstEsmBearerReq->ulMsgLen;

    NAS_LMM_MEM_CPY(                 pEmmEsmBearerReqMsg->stEsmMsg.aucEsmMsg,
                                     pstEsmBearerReq->aucMsg,
                                     pstEsmBearerReq->ulMsgLen);

    /*向ESM发送ID_EMM_ESM_DATA_IND消息*/
    NAS_LMM_SEND_MSG(                   pEmmEsmBearerReqMsg);

    return;

}
VOS_UINT32  NAS_LMM_EncodeNvUplmn( NAS_NVIM_CTRL_TBL *pstNvCtrlTbl )
{
#if 0
    LNAS_LMM_NV_PLMN_LIST_STRU      *pstNvplmnList;
    NAS_MM_PLMN_LIST_STRU           *pstUplmnList;
    VOS_UINT32                      i;
    VOS_UINT32                      ulIndex;
    VOS_UINT8                       *pucMsg;

    if(NAS_NVIM_NULL_PTR == pstNvCtrlTbl->pData)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_EncodeNvUplmn: WARNING->pData is Null");
        return NAS_LMM_NVIM_FAIL;
    }

    if(NAS_EMM_USIM_FEATURE_HARD        == NAS_LMM_GetUsimFeature())
    {
        pstNvplmnList   = (LNAS_LMM_NV_PLMN_LIST_STRU *)pstNvCtrlTbl->pData;
        pstUplmnList    = &(pstNvplmnList->stPlmnList);

        pucMsg          = (VOS_UINT8 *)pstNvCtrlTbl->pNvData;

        pstNvCtrlTbl->usNvDataLen = (VOS_UINT16)((pstUplmnList->ulPlmnNum) * NAS_LMM_PLMN_AND_ACT_LEN);
        for(i = 0; i < pstUplmnList->ulPlmnNum; i++)
        {
            ulIndex = i * NAS_LMM_PLMN_AND_ACT_LEN;
            NAS_LMM_MEM_CPY(           &pucMsg[ulIndex],
                                        &pstUplmnList->astPlmnId[i],
                                        NAS_LMM_NVIM_PLMN_ID_LEN);

            /* NAS_LMM_ACCESS_TECH_LTE 为 0x40   NAS_LMM_ACCESS_TECH_RSV 为 0x00*/
            pucMsg[ulIndex + 3] = NAS_LMM_ACCESS_TECH_LTE;
            pucMsg[ulIndex + 4] = NAS_LMM_ACCESS_TECH_RSV;
        }

        NAS_LMM_NVIM_LOG1_INFO("NAS_LMM_EncodeNvUplmn: LEN= ",
                                                  pstNvCtrlTbl->usNvDataLen);
        NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeNvUplmn: PLMN IS ");
        NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(),(VOS_UINT8 *)pstNvCtrlTbl->pNvData,pstNvCtrlTbl->usNvDataLen);

        return NAS_LMM_NVIM_OK;
    }
    else
    #endif
    {
        NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeNvUplmn is entered");

        return  NAS_LMM_EncodeOneNvItem(pstNvCtrlTbl);
    }

}
/*******************************************************************************
  Module   :
  Function : NAS_EMM_SER_SendMrrcDataReq_Tcdata
  Input    : pMsg------------TC消息
  Output   :
  NOTE     : 向RRC转发TC_DATA_REQ消息
  Return   : VOS_VOID
  History  :
      1.lihong00150010      2009-10-16  Draft Enact
*******************************************************************************/
VOS_VOID    NAS_EMM_SER_SendMrrcDataReq_Tcdata
(
    EMM_ETC_DATA_REQ_STRU               *pMsg
)
{
    VOS_UINT32                          ulMsgLenthNoHeader;
    NAS_EMM_MRRC_DATA_REQ_STRU         *pMrrcDataReqMsg    = NAS_EMM_NULL_PTR;

    /* 打印进入该函数, INFO_LEVEL */
    NAS_EMM_SER_LOG1_INFO( "NAS_EMM_SER_SendMrrcDataReq_Tcdata is entered.", pMsg);


    /*申请消息*/
    pMrrcDataReqMsg = (VOS_VOID *)NAS_LMM_MEM_ALLOC(NAS_EMM_INTRA_MSG_MAX_SIZE);
    if ( NAS_EMM_NULL_PTR == pMrrcDataReqMsg )
    {
        NAS_EMM_SER_LOG_ERR( "NAS_EMM_SER_SendMrrcDataReq_Tcdata: NAS_LMM_ALLOC_MSG err !!");
        return;
    }
    ulMsgLenthNoHeader                  = NAS_EMM_CountMrrcDataReqLen(pMsg->stTcMsg.ulTcMsgSize);

    /* 拷贝消息 */
    pMrrcDataReqMsg->stNasMsg.ulNasMsgSize = pMsg->stTcMsg.ulTcMsgSize;

    NAS_LMM_MEM_CPY(                        (pMrrcDataReqMsg->stNasMsg.aucNasMsg),
                                        (pMsg->stTcMsg.aucTcMsg),
                                        (pMsg->stTcMsg.ulTcMsgSize));
    /* 改写DOPRA消息头 */
    EMM_COMP_MM_MSG_HEADER(             (pMrrcDataReqMsg),
                                        ulMsgLenthNoHeader);

    /*改写消息ID*/
    pMrrcDataReqMsg->ulMsgId            = ID_NAS_LMM_INTRA_MRRC_DATA_REQ;

    /*填写 EST CAUSE*/
    pMrrcDataReqMsg->enEstCaue          = LRRC_LNAS_EST_CAUSE_MO_DATA;
    pMrrcDataReqMsg->enCallType         = LRRC_LNAS_CALL_TYPE_ORIGINATING_CALL;
    pMrrcDataReqMsg->enEmmMsgType       = NAS_EMM_MSG_TC;

    pMrrcDataReqMsg->enDataCnf          = LRRC_LMM_DATA_CNF_NOT_NEED;

    /* 向MRRC转发TC_DATA_REQ消息 */
    NAS_EMM_SndUplinkNasMsg(pMrrcDataReqMsg);

    NAS_LMM_MEM_FREE(pMrrcDataReqMsg);

    return;
}
/*****************************************************************************
 Function Name   : NAS_LMM_SmsSendDataInd
 Description     : 向SMS发送ID_LMM_SMS_DATA_IND
 Input           :
 Output          :
 Return          : 处理结果
 History         :
    1.FTY         2011-11-16  Draft Enact
    2.sunbing     2011-12-30  修改消息长度
*****************************************************************************/
VOS_VOID NAS_LMM_SndLmmSmsDataInd(const VOS_UINT8* aucMsg,VOS_UINT32 ulMsgLen)
{
    LMM_SMS_DATA_IND_STRU                  *pLmmSmsDataInd      = NAS_EMM_NULL_PTR;
    VOS_UINT32                              ulTmpLength         = 0;

    if( 0 == ulMsgLen)
    {
        NAS_EMM_PUBU_LOG_WARN("NAS_LMM_SndLmmSmsDataInd: WARNING: Msg Length is zero");
        return ;
    }
    else if(ulMsgLen > NAS_EMM_4BYTES_LEN)
    {
        ulTmpLength = ulMsgLen - NAS_EMM_4BYTES_LEN ;
        pLmmSmsDataInd = (VOS_VOID*)NAS_LMM_ALLOC_MSG(sizeof(LMM_SMS_DATA_IND_STRU) + ulTmpLength);
    }
    else/*如果长度小于NAS_EMM_4BYTES_LEN,分配的空间等于NAS_EMM_4BYTES_LEN*/
    {
        ulTmpLength = 0;
        pLmmSmsDataInd = (VOS_VOID*)NAS_LMM_ALLOC_MSG(sizeof(LMM_SMS_DATA_IND_STRU));
    }

    /*判断申请结果,若失败打印错误并退出*/
    if (NAS_EMM_NULL_PTR == pLmmSmsDataInd)
    {
        /*打印错误*/
        NAS_EMM_PUBU_LOG_ERR("NAS_LMM_SmsSendDataInd: MSG ALLOC ERR!");
        return ;
    }

    /*构造ID_EMM_ESM_DATA_IND消息*/
    /*填充消息头*/
    NAS_LMM_COMP_SMS_MSG_HEADER(pLmmSmsDataInd,
                                (sizeof(LMM_SMS_DATA_IND_STRU)+ ulTmpLength)-NAS_EMM_LEN_VOS_MSG_HEADER);
    /*填充消息ID*/
    pLmmSmsDataInd->ulMsgId = ID_LMM_SMS_DATA_IND;

    /*填充消息内容*/
    pLmmSmsDataInd->ulOpId = 0;
    pLmmSmsDataInd->stSmsMsg.ulSmsMsgSize = ulMsgLen;

    /*lint -e669*/
    NAS_LMM_MEM_CPY(pLmmSmsDataInd->stSmsMsg.aucSmsMsg,aucMsg,ulMsgLen);/*lint !e669 !e670*/
    /*lint +e669*/

    /*向SMS发送ID_LMM_SMS_DATA_IND消息*/
    NAS_LMM_SEND_MSG(pLmmSmsDataInd);

}
VOS_UINT32  NAS_LMM_EncodeOneNvItem(NAS_NVIM_CTRL_TBL *pstNvCtrlTbl)
{
    if(NAS_NVIM_NULL_PTR == pstNvCtrlTbl->pData)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_EncodeOneNvItem: WARNING->pData is Null");
          return NAS_LMM_NVIM_FAIL;
    }

    NAS_LMM_MEM_CPY(                   pstNvCtrlTbl->pNvData,
                                        pstNvCtrlTbl->pData,
                                        pstNvCtrlTbl->usDataLen);

    /*Data len after encode*/
    pstNvCtrlTbl->usNvDataLen           = pstNvCtrlTbl->usDataLen;
    return NAS_LMM_NVIM_OK;
}
VOS_UINT32  NAS_LMM_DecodeSimLRplmnSI(NAS_NVIM_CTRL_TBL *pstNvCtrlTbl )
{
    #if 0
    NAS_LMM_LRPLMNSI_ENUM_UINT8         *penRplmnSI;
    VOS_UINT8                           *pucMsg;

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeSimLRplmnSI is entered");

    pucMsg                           = (VOS_UINT8 *)pstNvCtrlTbl->pNvData;

    penRplmnSI = (NAS_LMM_LRPLMNSI_ENUM_UINT8 *)NAS_EMMC_GetMmcGlobleAddr(NAS_LMM_GLOBLE_PARA_LRPLMNSI);

    if(NAS_NVIM_NULL_PTR == pstNvCtrlTbl)
    {
        /* 打印查询的 类型 */
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimLRplmnSI: Point is Null");
        return NAS_LMM_NVIM_FAIL;
    }

    if(NAS_EMM_USIM_FEATURE_HARD == NAS_LMM_GetUsimFeature())
    {
        if (pstNvCtrlTbl->usNvDataLen == NAS_LMM_LRPLMNSI_LEN)
        {
            NAS_LMM_MEM_CPY(             penRplmnSI,
                                        pucMsg,
                                        pstNvCtrlTbl->usNvDataLen);

            return NAS_LMM_NVIM_OK;
        }
        else
        {
            NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimLRplmnSI: len is err!");

            return NAS_LMM_NVIM_FAIL;
        }
    }
    else
    #endif
    {
         return  NAS_LMM_DecodeOneNvItem(pstNvCtrlTbl);
    }

}
/*******************************************************************************
  Module   :
  Function : NAS_EMM_CompCnUplinkNasTransportMsg
  Input     : pMsg         :SMS透传过来的消息
                pulIndex     : 既作输入,也作输出
  Output   :pucCnNasMsg  : 指向 LRRC_LNAS_MSG_STRU.aucNasMsg
  NOTE     :
  Return   :VOS_VOID
  History  :
    1.  FTY  2011.11.15  新规作成

*******************************************************************************/
VOS_VOID NAS_EMM_SMS_CompCnUplinkNasTransportMsg
               (VOS_UINT8 *pucCnNasMsg, VOS_UINT32 *pulIndex, const LMM_SMS_MSG_STRU * pSmsMsg)
{
    VOS_UINT32 ulIndex = NAS_LMM_NULL;

    NAS_EMM_PUBU_LOG_NORM("NAS_EMM_SMS_CompCnUplinkNasTransportMsg enter!");

    /* 填充 Protocol Discriminator + Security header type */
    pucCnNasMsg[ulIndex++] = EMM_CN_MSG_PD_EMM;

    /* 填充UpLink nas transort message identity   */
    pucCnNasMsg[ulIndex++] = NAS_EMM_CN_MT_UPLINK_NAS_TRANSPORT;

    /*填充NAS msg*/
    pucCnNasMsg[ulIndex++] = (VOS_UINT8)pSmsMsg->ulSmsMsgSize;
    NAS_LMM_MEM_CPY(&(pucCnNasMsg[ulIndex]),
                      pSmsMsg->aucSmsMsg,
                      pSmsMsg->ulSmsMsgSize);
    ulIndex += pSmsMsg->ulSmsMsgSize;

    *pulIndex += ulIndex;

}
VOS_UINT32  NAS_LMM_DecodeNvOplmn(NAS_NVIM_CTRL_TBL *pstNvCtrlTbl)
{
    #if 0
    NAS_LMM_PLMN_ACT_LIST_STRU           *pstOplmnAct;
    VOS_UINT8                           *pucMsg;
    VOS_UINT32                          i;
    VOS_UINT32                          ulValidPlmnNum = NAS_LMM_NULL;
    NAS_MM_PLMN_ID_STRU                 stPlmnId;

    NAS_LMM_MEM_SET(&stPlmnId,(VOS_CHAR)0xff,sizeof(stPlmnId));
    NAS_LMM_UndefPlmn(&stPlmnId);

    if(NAS_EMM_USIM_FEATURE_HARD        == NAS_LMM_GetUsimFeature())
    {
        pucMsg                              = (VOS_UINT8 *)pstNvCtrlTbl->pNvData;

        pstOplmnAct = (VOS_VOID *)NAS_EMMC_GetMmcGlobleAddr(NAS_LMM_GLOBLE_PARA_OPLMNLIST);

        if((NAS_NVIM_NULL_PTR == pstOplmnAct)
            || (NAS_NVIM_NULL_PTR == pstNvCtrlTbl->pNvData))
        {
            /* 打印查询的 类型 */
            NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeNvOplmn: Point is Null");
            return NAS_LMM_NVIM_FAIL;
        }

        if ((NAS_USIM_MIN_PLMN_LEN > pstNvCtrlTbl->usNvDataLen)
            || (NAS_LMM_NULL != pstNvCtrlTbl->usNvDataLen % NAS_LMM_PLMN_AND_ACT_LEN))
        {
            NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeNvOplmn:len is err!");
            /*return NAS_LMM_NVIM_FAIL;*/
        }

        pstOplmnAct->ulPlmnNum = pstNvCtrlTbl->usNvDataLen / NAS_LMM_PLMN_AND_ACT_LEN;
        for(i= 0; i < pstOplmnAct->ulPlmnNum; i++ )
        {
            NAS_LMM_MEM_CPY(             &stPlmnId,
                                        &pucMsg[NAS_LMM_PLMN_AND_ACT_LEN*i],
                                        NAS_LMM_NVIM_PLMN_ID_LEN);

            if (VOS_FALSE == NAS_LMM_PlmnIsUndef(&stPlmnId))
            {
                NAS_LMM_MEM_CPY(&(pstOplmnAct->aucPlmnId[NAS_LMM_PLMN_AND_ACT_LEN*ulValidPlmnNum]),
                               &pucMsg[NAS_LMM_PLMN_AND_ACT_LEN*i],
                               NAS_LMM_PLMN_AND_ACT_LEN);
                ulValidPlmnNum ++;
            }

            if (NAS_EMMC_MAX_OPLMN_NUM == ulValidPlmnNum)
            {
                NAS_LMM_NVIM_LOG_ERR("pstOplmnAct: Valid PlmnNum is overflow");
                break;
            }
        }
        pstOplmnAct->ulPlmnNum = ulValidPlmnNum;

        NAS_LMM_NVIM_LOG1_INFO("NAS_LMM_DecodeNvOplmn: ulPlmnNum = ",
                                            pstOplmnAct->ulPlmnNum);
        NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeNvOplmn: PLMN IS ");
        NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(), (VOS_UINT8 *)pstOplmnAct->aucPlmnId,pstOplmnAct->ulPlmnNum * NAS_LMM_PLMN_AND_ACT_LEN);

        return  NAS_LMM_NVIM_OK;
    }
    else
    #endif
    {

        return  NAS_LMM_DecodeOneNvItem(pstNvCtrlTbl);
    }

}
VOS_VOID    NAS_EMM_ProcRejCauseVal15()
{
    NAS_MM_TA_STRU                      stTa;
    MMC_LMM_LTE_NO_SUBSCRIBE_PLMN_LIST_STRU  stLteNoSubsPlmnList;

    /* 获取当前TA */
    NAS_EMM_GetCurrentTa(&stTa);

    NAS_EMM_AttDataUpdate(NAS_EMM_NOT_DELETE_RPLMN);

    if (NAS_EMMC_USER_SPEC_PLMN_YES == NAS_EMMC_GetUserSpecPlmnFlag())
    {
        NAS_EMM_AddForbTa(&stTa,NAS_LMM_GetEmmInfoNetInfoForbTaForRej15Addr());
    }
    else
    {
        NAS_EMM_AddForbTa(&stTa,NAS_LMM_GetEmmInfoNetInfoForbTaForRoamAddr());
        NAS_EMMC_SendRrcCellSelectionReq(LRRC_LNAS_FORBTA_CHANGE);
    }

    if (EMM_ATTACH_CAUSE_ESM_ATTACH_FOR_INIT_EMC_BERER == NAS_EMM_GLO_AD_GetAttCau())
    {
        /* 通知ESM紧接着EMM还要做紧急注册,ESM不需要清除动态表中的紧急PDN建立记录 */
        NAS_EMM_AttSendEsmResult(EMM_ESM_ATTACH_STATUS_EMC_ATTACHING);
    }
    else
    {
        /*向ESM发送ATTACH结果*/
        NAS_EMM_AttSendEsmResult(EMM_ESM_ATTACH_STATUS_DETACHED);
    }

    /*修改状态:进入主状态DEREG子状态DEREG_LIMITED_SERVICE*/
    NAS_EMM_AdStateConvert(     EMM_MS_DEREG,
                                EMM_SS_DEREG_LIMITED_SERVICE,
                                TI_NAS_EMM_STATE_NO_TIMER);

    /* 向MMC发送结果 */
    NAS_EMM_AppSendAttRej();

    /*被15拒绝,当前PLMN只有一个*/
    stLteNoSubsPlmnList.ulPlmnNum = 1;
    /*拷贝当前PLMN*/
    NAS_LMM_MEM_CPY(&(stLteNoSubsPlmnList.astPlmnId[0]),
                     NAS_LMM_GetEmmInfoPresentPlmnAddr(),
                     sizeof(MMC_LMM_PLMN_ID_STRU));
    /*如果网络侧带了扩展原因值,而且当前对应值是EUTRAN NOT ALLOW,则走正常的协议流程*/
    if((NAS_EMM_BIT_SLCT == NAS_EMM_GLO_AD_OP_GetAttRejEmmExtCau())
        &&(NAS_EMM_EUTRAN_NOT_ALLOWED == NAS_EMM_GLO_AD_GetAttRejEmmExtCau()))
    {
        /*被15原因值拒绝而且当前有扩展原因值,指示USIM未在LTE开户,走正常的LTE未开户流程*/
        NAS_EMM_SetLteNoSubscribeExtCauseFlag(NAS_EMM_EUTRAN_NOT_ALLOWED);
        NAS_LMM_LteNoSubscribeWithExtCauseHandle(&stLteNoSubsPlmnList);
    }
    else
    {
        /*被15原因值拒绝但是没有带扩展原因值,走LTE未开户定制流程*/
        NAS_LMM_LteNoSubscribeWithOutExtCauseHandle(&stLteNoSubsPlmnList);
    }

    NAS_EMM_WaitNetworkRelInd();

    if (EMM_ATTACH_CAUSE_ESM_EMC_ATTACH == NAS_EMM_GLO_AD_GetAttCau())
    {
        /* 通知IMSA再尝试CS域 */
    }

    return;

}
Example #18
0
VOS_UINT32  NAS_EMM_PreProcMsgEmmInfo( NAS_EMM_CN_MSG_STRU_UNION  * pCnMsg )
{
    NAS_EMM_INFO_STRU                   *pstEmmInfo;
    NAS_EMM_CN_EMM_INFO_STRU            *pstTmpRcvMsg       = NAS_EMM_NULL_PTR;
    VOS_UINT8                           ucCount = 0;

    NAS_LMM_PUBM_LOG_NORM("NAS_EMM_PreProcMsgEmmInfo enter!");

    pstTmpRcvMsg               = (NAS_EMM_CN_EMM_INFO_STRU*)pCnMsg;
    pstEmmInfo                 = NAS_LMM_GetEmmInfoNasEmmInfoListAddr();

    NAS_LMM_MEM_SET(pstEmmInfo, 0, sizeof(NAS_EMM_INFO_STRU));

    /* 上报网络时间和网络名称,只要能收到,就可以上报给AT,对流程没有影响,可以不做限制;
    而且未注册时,网络也不会有下行消息下发*/
    if(NAS_EMM_BIT_SLCT == pstTmpRcvMsg->bitOpFullName)
    {
        pstEmmInfo->bitOpFullName           = NAS_EMM_BIT_SLCT;
        NAS_LMM_MEM_CPY(                   pstEmmInfo->aucOperatorNameLong,
                                           pstTmpRcvMsg->aucOperatorNameLong,
                                           MMC_LMM_MAX_OPER_LONG_NAME_LEN);
        ucCount++;
    }

    if(NAS_EMM_BIT_SLCT == pstTmpRcvMsg->bitOpShortName)
    {
        pstEmmInfo->bitOpShortName          = NAS_EMM_BIT_SLCT;
        NAS_LMM_MEM_CPY(                   pstEmmInfo->aucOperatorNameShort,
                                           pstTmpRcvMsg->aucOperatorNameShort,
                                           MMC_LMM_MAX_OPER_SHORT_NAME_LEN);
        ucCount++;
    }

    if(NAS_EMM_BIT_SLCT == pstTmpRcvMsg->bitOpLocTimeZone)
    {
        pstEmmInfo->bitOpLocTimeZone        = NAS_EMM_BIT_SLCT;
        NAS_LMM_MEM_CPY(                   &(pstEmmInfo->stLocTimeZone),
                                           &(pstTmpRcvMsg->stLocTimeZone),
                                           sizeof(NAS_EMM_CN_TIMEZONE_STRU));
        ucCount++;
    }

    if(NAS_EMM_BIT_SLCT == pstTmpRcvMsg->bitOpUniTimeLocTimeZone)
    {
        pstEmmInfo->bitOpUniTimeLocTimeZone = NAS_EMM_BIT_SLCT;
        NAS_LMM_MEM_CPY(                   &(pstEmmInfo->stTimeZoneAndTime),
                                           &(pstTmpRcvMsg->stTimeZoneAndTime),
                                           sizeof(NAS_EMM_CN_TIMEZONE_UNITIME_STRU));
	ucCount++;
    }

    if(NAS_EMM_BIT_SLCT == pstTmpRcvMsg->bitOpDaylightTime)
    {
        pstEmmInfo->bitOpDaylightTime       = NAS_EMM_BIT_SLCT;
        NAS_LMM_MEM_CPY(                   &(pstEmmInfo->enDaylightSavingTime),
                                           &(pstTmpRcvMsg->enDaylightSavingTime),
                                           sizeof(NAS_LMM_DAYLIGHT_SAVE_TIME_ENUM_UINT8));
        ucCount++;
    }
    if(0 != ucCount)
    {
        NAS_EMM_SendMmcEmmInfoInd(pstEmmInfo);
    }
    return NAS_LMM_MSG_HANDLED;
}
VOS_UINT32  NAS_LMM_DecodeSimSecContext( NAS_NVIM_CTRL_TBL *pstNvCtrlTbl )
{
    NAS_LMM_SECU_CONTEXT_STRU            stCurSecuContext;
    VOS_UINT16                          usIndex = 0;
    VOS_UINT8                          *pucMsg;

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeSimSecContext is entered");

    /*初始化stCurSecuContext*/
    NAS_LMM_MEM_SET(&(stCurSecuContext), 0, sizeof(NAS_LMM_SECU_CONTEXT_STRU));

    /*保存安全上下文的长度*/
    NAS_EMM_GET_USIM_SECU_FILE_LEN() = pstNvCtrlTbl->usNvDataLen;

    pucMsg     = (VOS_UINT8*)pstNvCtrlTbl->pNvData;


    NAS_LMM_MEM_SET(NAS_LMM_GET_USIM_EPS_SECU_CONTEXT_ADDR(),
                    0,
                    NAS_NVIM_SECU_CONTEXT_MAX_LEN);


    /* 检测文件Tag是否合法 */
    if ( NAS_LMM_NVIM_SECU_CONTEXT_TAG != pucMsg[usIndex++])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: File Tag Err ");
        return  NAS_LMM_NVIM_FAIL;
    }

    /* 检测文件Length是否合法 */
    if ( NAS_LMM_NVIM_SEC_MSG_LEN != pucMsg[usIndex++] )/*待确认*/
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: File LEN Err ");
        return  NAS_LMM_NVIM_FAIL;
    }

    /********************************* KSIASME *****************************************/
    if ( NAS_LMM_NVIM_SEC_KSI_TAG != pucMsg[usIndex++] )
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: KSI TAG Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    if (NAS_LMM_NVIM_SEC_KSI_LEN != pucMsg[usIndex++])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: KSI LEN Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    /* 检测KSI的合法性 */
    if ( NAS_LMM_NKSI_NO_KEY_IS_AVAILABLE < pucMsg[usIndex] )
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: KSI Content Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    stCurSecuContext.ucKSIasme = pucMsg[usIndex];

    usIndex                           += NAS_LMM_NVIM_SEC_KSI_LEN ;

    /*********************************** KASME ******************************************/
    if ( NAS_LMM_NVIM_SEC_KASME_TAG != pucMsg[usIndex++] )
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: KASME TAG Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    if (NAS_LMM_NVIM_SEC_KASME_LEN != pucMsg[usIndex++])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: KASME LEN Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    NAS_LMM_MEM_CPY(                   (stCurSecuContext.aucKasme),
                                      &(pucMsg[usIndex]),
                                      NAS_LMM_NVIM_SEC_KASME_LEN);

    usIndex                           += NAS_LMM_NVIM_SEC_KASME_LEN ;

    /**************************** Uplink NAS count ************************************/
    if ( NAS_LMM_NVIM_SEC_UPNASCOUNT_TAG != pucMsg[usIndex++] )
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: UPNASCOUNT TAG Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    if (NAS_LMM_NVIM_SEC_NAS_COUNT_LEN != pucMsg[usIndex++])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: UPNASCOUNT LEN Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    stCurSecuContext.ulUlNasCount = stCurSecuContext.ulUlNasCount | ((VOS_UINT32)pucMsg[usIndex++] << NAS_LMM_NVIM_MOVE_24_BIT);
    stCurSecuContext.ulUlNasCount = stCurSecuContext.ulUlNasCount | ((VOS_UINT32)pucMsg[usIndex++] << NAS_LMM_NVIM_MOVE_16_BIT);
    stCurSecuContext.ulUlNasCount = stCurSecuContext.ulUlNasCount | ((VOS_UINT32)pucMsg[usIndex++] << NAS_LMM_NVIM_MOVE_8_BIT);
    stCurSecuContext.ulUlNasCount = stCurSecuContext.ulUlNasCount | (VOS_UINT32)pucMsg[usIndex++];

    /* 检测NAS count的合法性 */
    if (NAS_LMM_NVIM_MAX_NASCOUNT < stCurSecuContext.ulUlNasCount)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: UPNASCOUNT Content Err ");

        return  NAS_LMM_NVIM_FAIL;
    }


    /*************************** Downlink NAS count ***********************************/
    if ( NAS_LMM_NVIM_SEC_DNNASCOUNT_TAG != pucMsg[usIndex++] )
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: DNNASCOUNT Tag Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    if (NAS_LMM_NVIM_SEC_NAS_COUNT_LEN != pucMsg[usIndex++])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: DNNASCOUNT Len Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    stCurSecuContext.ulDlNasCount = stCurSecuContext.ulDlNasCount | ((VOS_UINT32)pucMsg[usIndex++] << NAS_LMM_NVIM_MOVE_24_BIT);
    stCurSecuContext.ulDlNasCount = stCurSecuContext.ulDlNasCount | ((VOS_UINT32)pucMsg[usIndex++]<< NAS_LMM_NVIM_MOVE_16_BIT);
    stCurSecuContext.ulDlNasCount = stCurSecuContext.ulDlNasCount | ((VOS_UINT32)pucMsg[usIndex++]<< NAS_LMM_NVIM_MOVE_8_BIT);
    stCurSecuContext.ulDlNasCount = stCurSecuContext.ulDlNasCount | (VOS_UINT32)pucMsg[usIndex++];

    /* 检测NAS count的合法性 */
    if (NAS_LMM_NVIM_MAX_NASCOUNT < stCurSecuContext.ulDlNasCount)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: DNNASCOUNT Content Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    /******** Identifiers of selected NAS integrity and encryption algorithms *********/
    if ( NAS_LMM_NVIM_SEC_ALG_TAG != pucMsg[usIndex++] )
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: Alg Tag Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    if (NAS_LMM_NVIM_SEC_ENCINT_LEN != pucMsg[usIndex++])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: Alg LEN Err ");

        return  NAS_LMM_NVIM_FAIL;
    }

    stCurSecuContext.ucSecuAlg = pucMsg[usIndex];

    usIndex                           += NAS_LMM_NVIM_SEC_ENCINT_LEN;

    /*检测合法性*/
    if ( VOS_TRUE != NAS_LMM_CheckSecuAlgValid(stCurSecuContext.ucSecuAlg))
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimSecContext: Alg Content Err ");

        return  NAS_LMM_NVIM_FAIL;
    }


    /* 如果长度超过缓存区,则认为异常不保存读出的码流,如果短于缓存区,多出长度位置已初始化为0 */
    if(NAS_NVIM_SECU_CONTEXT_MAX_LEN >= pstNvCtrlTbl->usNvDataLen)
    {
        /* 保存从USIM卡中读取出的安全上下文码流*/
        NAS_LMM_MEM_CPY(NAS_LMM_GET_USIM_EPS_SECU_CONTEXT_ADDR(),
                        pucMsg,
                        pstNvCtrlTbl->usNvDataLen);
    }


    pstNvCtrlTbl->usDataLen           = usIndex;

    /*调用安全上下文更新函数,并计算NasCK ,NasIk*/
    NAS_EMM_SecuSetCurCntxt(&stCurSecuContext);

    return NAS_LMM_NVIM_OK;
}
VOS_VOID NAS_EMM_TAU_TAUReqRejectCasue10(VOS_VOID)
{
    VOS_UINT32                          ulAttachFlag    = VOS_TRUE;
    NAS_EMM_ESM_MSG_BUFF_STRU          *pstEsmMsg       = NAS_EMM_NULL_PTR;

    /* 打印进入该函数, INFO_LEVEL */
    NAS_EMM_TAU_LOG_INFO( "Nas_Emm_Tau_TAUReqRejectCasue10 is entered.");
	/* lihong00150010 emergency tau&service begin */
    if (NAS_EMM_TAU_START_CAUSE_ESM_EMC_PDN_REQ == NAS_EMM_TAU_GetEmmTAUStartCause())
    {
        NAS_EMM_TAU_SendEsmStatusInd(EMM_ESM_ATTACH_STATUS_EMC_ATTACHING);
    }
    else
    {
        NAS_EMM_TAU_SendEsmStatusInd(EMM_ESM_ATTACH_STATUS_DETACHED);
    }
	/* lihong00150010 emergency tau&service end */
    /* 状态迁移Dereg.Normal_Service,发送INTRA_ATTACH_REQ消息*/
    NAS_EMM_TAUSER_FSMTranState(EMM_MS_DEREG,
                                EMM_SS_DEREG_NORMAL_SERVICE,
                                TI_NAS_EMM_STATE_NO_TIMER);

    /* 进入DEREG态不再写统一写安全上下文,参照标杆,在TAU被#10拒绝,将安全上下文写卡 */
    NAS_LMM_WriteEpsSecuContext(NAS_NV_ITEM_UPDATE);

    switch(NAS_EMM_TAU_GetEmmCollisionCtrl())
    {

        case NAS_EMM_COLLISION_DETACH:

            /* 向MMC报TAU结果需在DETACH结果上报前 */
            NAS_EMM_MmcSendTauActionResultIndRej((VOS_VOID*)NAS_EMM_NULL_PTR);

            NAS_EMM_TAU_CollisionDetachProc();

            if (MMC_LMM_MO_DET_CS_ONLY != NAS_EMM_GLO_AD_GetDetTypeMo())
            {
                NAS_EMM_DETACH_LOG_INFO("NAS_EMM_TAU_TAUReqRejectCasue10:Process EPS Detach or EPS/IMSI Detach");

                /* 本地DETACH*/
                NAS_LMM_DeregReleaseResource();
                NAS_EMM_RelReq(NAS_LMM_NOT_BARRED);
                return;
            }

            NAS_EMM_DETACH_LOG_INFO("NAS_EMM_TAU_TAUReqRejectCasue10:Process IMSI Detach");

            /* IMSI DETACH后释放资源 */
            NAS_LMM_ImsiDetachReleaseResource();
            break;

        case NAS_EMM_COLLISION_SERVICE:

            /* 如果是紧急CSFB,则标识不发内部ATTACH */
            if(VOS_FALSE == NAS_EMM_SER_IsNotEmergencyCsfb())
            {
               ulAttachFlag = VOS_FALSE;
            }

            /* 上报TAU结果在SER冲突处理中执行 */
            NAS_EMM_TAU_CollisionServiceProc(NAS_EMM_MmcSendTauActionResultIndRej,
                         (VOS_VOID*)NAS_EMM_NULL_PTR,
                         NAS_EMM_TRANSFER_RAT_NOT_ALLOW);
            break;

        default:

            NAS_EMM_MmcSendTauActionResultIndRej((VOS_VOID*)NAS_EMM_NULL_PTR);
            break;
    }
	/* lihong00150010 emergency tau&service begin */
    pstEsmMsg = (NAS_EMM_ESM_MSG_BUFF_STRU*)(VOS_VOID*)NAS_LMM_GetEmmInfoEsmBuffAddr();
    if ((NAS_EMM_TAU_START_CAUSE_ESM_EMC_PDN_REQ == NAS_EMM_TAU_GetEmmTAUStartCause())
        && (NAS_EMM_NULL_PTR != pstEsmMsg))
    {
        NAS_EMM_TAU_LOG_INFO("NAS_EMM_TAU_RrcRelCause_TAUREJ9: CAUSE_ESM_EMC_PDN_REQ");

        /*保存ESM消息*/
        /*lint -e960*/
        NAS_LMM_MEM_CPY(        (VOS_VOID*)NAS_EMM_GLO_AD_GetEsmMsgAddr(),
                               &(pstEsmMsg->stEsmMsg),
                                (pstEsmMsg->stEsmMsg.ulEsmMsgSize)+4);
        /*lint +e960*/

        NAS_EMM_StartEmergencyAttach();
    }
    else if(VOS_TRUE == ulAttachFlag)
    {/* lihong00150010 emergency tau&service end */
        /* 延时发送attach请求 */
        NAS_EMM_ReattachDelay();
    }
    else
    {
        NAS_EMM_RelReq(NAS_LMM_NOT_BARRED);
    }

    /* 清空TAU和APP资源*/
    NAS_EMM_TAU_ClearResouce();
    NAS_EMM_ClearAppMsgPara();

    return;
}
VOS_VOID  NAS_EMM_MmSendCsfbSerPaingInd
(
    NAS_EMM_MT_CSFB_TYPE_ENUM_UINT8     enMtCsfbType,
    const NAS_EMM_CN_CS_SER_NOTIFICAIOTN_STRU *pstCsSerNotification,
    LRRC_LNAS_PAGING_UE_ID_ENUM_UINT32 enPagingUeId
)
{
    LMM_MM_CSFB_SERVICE_PAGING_IND_STRU   *pstMmCsfbSerPaingInd = VOS_NULL_PTR;

    /* 申请DOPRA消息 */
    pstMmCsfbSerPaingInd = (VOS_VOID *) NAS_LMM_GetLmmMmcMsgBuf(sizeof(LMM_MM_CSFB_SERVICE_PAGING_IND_STRU));
    if (NAS_LMM_NULL_PTR == pstMmCsfbSerPaingInd)
    {
        /* 打印异常,ERROR_LEVEL */
        NAS_EMM_SER_LOG_ERR("NAS_EMM_MmSendCsfbSerPaingInd: MSG ALLOC ERROR!!!");
        return ;
    }

    /* 清空 */
    NAS_LMM_MEM_SET(pstMmCsfbSerPaingInd, 0, sizeof(LMM_MM_CSFB_SERVICE_PAGING_IND_STRU));

    /* 打包VOS消息头 */
    EMM_PUBU_COMP_MM_MSG_HEADER((pstMmCsfbSerPaingInd),
                             NAS_EMM_GET_MSG_LENGTH_NO_HEADER(LMM_MM_CSFB_SERVICE_PAGING_IND_STRU));

    /* 填充消息ID */
    pstMmCsfbSerPaingInd->ulMsgId    = ID_LMM_MM_CSFB_SERVICE_PAGING_IND;

    /* 填充消息体 */
    pstMmCsfbSerPaingInd->ulOpId     = NAS_EMM_OPID_MM;

    if (NAS_EMM_MT_CSFB_TYPE_CS_SER_NOTIFICATION == enMtCsfbType)
    {
        /* 填充CLI */
        pstMmCsfbSerPaingInd->bitOpCli = pstCsSerNotification->bitOpCli;
        pstMmCsfbSerPaingInd->ucCliLength = pstCsSerNotification->ucCliLength;
        NAS_LMM_MEM_CPY(    pstMmCsfbSerPaingInd->aucCliValue,
                            pstCsSerNotification->aucCliValue,
                            pstCsSerNotification->ucCliLength);

        /* 填充SS CODE */
        pstMmCsfbSerPaingInd->bitOpSsCodeValue = pstCsSerNotification->bitOpSsCode;
        pstMmCsfbSerPaingInd->ucSsCodeValue = pstCsSerNotification->ucSsCodeValue;
        if (0 == pstCsSerNotification->ucPagingIdenity)
        {
            pstMmCsfbSerPaingInd->enPagingUeId = LMM_MM_PAGING_IND_UE_ID_IMSI;
        }
        else
        {
            pstMmCsfbSerPaingInd->enPagingUeId = LMM_MM_PAGING_IND_UE_ID_TMSI;
        }
        
    }
    else
    {
        if(LRRC_LNAS_S_TMSI_LTE == enPagingUeId)
        {
            pstMmCsfbSerPaingInd->enPagingUeId = LMM_MM_PAGING_IND_UE_ID_S_TMSI;
        }
        else if(LRRC_LNAS_IMSI_LTE == enPagingUeId)
        {
            pstMmCsfbSerPaingInd->enPagingUeId = LMM_MM_PAGING_IND_UE_ID_IMSI;
        }
        else
        {

        }
    }

    /* 发送DOPRA消息 */
    NAS_LMM_SendLmmMmcMsg((VOS_VOID*)pstMmCsfbSerPaingInd);

    return;
}
VOS_VOID NAS_EMM_TAU_TAUReqRejectCasue9( )
{
    VOS_UINT32                          ulAttachFlag    = VOS_TRUE;
    NAS_EMM_ESM_MSG_BUFF_STRU          *pstEsmMsg       = NAS_EMM_NULL_PTR;

    /* 打印进入该函数, INFO_LEVEL */
    NAS_EMM_TAU_LOG_INFO("Nas_Emm_Tau_TAUReqRejectCasue9 is entered.");

    /* 删除GUTI后会自动保存EPS_LOC,所以需要先设置STATUS */
    /*设置设置EU2 NOT UPDATED*/
    NAS_LMM_GetMmAuxFsmAddr()->ucEmmUpStat = EMM_US_NOT_UPDATED_EU2;

    /*删除GUTI,KSIasme,TAI list,GUTI*/
    NAS_EMM_ClearRegInfo(NAS_EMM_NOT_DELETE_RPLMN);

    /*删除equivalent PLMNs由MMC模块完成*/
	/* lihong00150010 emergency tau&service begin */
    if (NAS_EMM_TAU_START_CAUSE_ESM_EMC_PDN_REQ == NAS_EMM_TAU_GetEmmTAUStartCause())
    {
        NAS_EMM_TAU_SendEsmStatusInd(EMM_ESM_ATTACH_STATUS_EMC_ATTACHING);
    }
    else
    {
        NAS_EMM_TAU_SendEsmStatusInd(EMM_ESM_ATTACH_STATUS_DETACHED);
    }
	/* lihong00150010 emergency tau&service end */
    /*转换EMM状态机MS_DEREG+SS_DEREG_NORMAL_SERVICE*/
    NAS_EMM_TAUSER_FSMTranState(EMM_MS_DEREG,
                                EMM_SS_DEREG_NORMAL_SERVICE,
                                TI_NAS_EMM_STATE_NO_TIMER);

    /****检查冲突标志并做相应的处理********************************************/
    switch(NAS_EMM_TAU_GetEmmCollisionCtrl())
    {
        case    NAS_EMM_COLLISION_DETACH   :

                NAS_EMM_MmcSendTauActionResultIndRej((VOS_VOID*)NAS_EMM_NULL_PTR);
                NAS_EMM_TAU_CollisionDetachProc();
                if (MMC_LMM_MO_DET_CS_ONLY != NAS_EMM_GLO_AD_GetDetTypeMo())
                {
                    NAS_EMM_DETACH_LOG_INFO("NAS_EMM_TAU_TAUReqRejectCasue9:Process EPS/Combined Detach");

                    /* 本地DETACH*/
                    NAS_LMM_DeregReleaseResource();


                    NAS_EMM_RelReq(                 NAS_LMM_NOT_BARRED);
                    return;
                }

                NAS_EMM_DETACH_LOG_INFO("NAS_EMM_TAU_TAUReqRejectCasue9:Process IMSI Detach");

                /* IMSI DETACH后释放资源 */
                NAS_LMM_ImsiDetachReleaseResource();

                break;

        case    NAS_EMM_COLLISION_SERVICE    :

                /* 如果是紧急CSFB,则标识不发内部ATTACH */
                if(VOS_FALSE == NAS_EMM_SER_IsNotEmergencyCsfb())
                {
                   ulAttachFlag = VOS_FALSE;
                }

                NAS_EMM_TAU_CollisionServiceProc(NAS_EMM_MmcSendTauActionResultIndRej,
                                  (VOS_VOID*)NAS_EMM_NULL_PTR,
                                  NAS_EMM_TRANSFER_RAT_NOT_ALLOW);
                break;

        default :

                NAS_EMM_TAU_LOG_INFO( "NAS_EMM_TAU_RrcRelCause_TAUREJ9 : NO Emm Collision.");
                NAS_EMM_MmcSendTauActionResultIndRej((VOS_VOID*)NAS_EMM_NULL_PTR);
                break;
    }
	/* lihong00150010 emergency tau&service begin */
    pstEsmMsg = (NAS_EMM_ESM_MSG_BUFF_STRU*)(VOS_VOID*)NAS_LMM_GetEmmInfoEsmBuffAddr();
    if ((NAS_EMM_TAU_START_CAUSE_ESM_EMC_PDN_REQ == NAS_EMM_TAU_GetEmmTAUStartCause())
        && (NAS_EMM_NULL_PTR != pstEsmMsg))
    {
        NAS_EMM_TAU_LOG_INFO("NAS_EMM_TAU_RrcRelCause_TAUREJ9: CAUSE_ESM_EMC_PDN_REQ");

        /*保存ESM消息*/
        /*lint -e960*/
        NAS_LMM_MEM_CPY(        (VOS_VOID*)NAS_EMM_GLO_AD_GetEsmMsgAddr(),
                               &(pstEsmMsg->stEsmMsg),
                                (pstEsmMsg->stEsmMsg.ulEsmMsgSize)+4);
        /*lint +e960*/
        NAS_EMM_StartEmergencyAttach();
    }
    else if(VOS_TRUE == ulAttachFlag)
    {/* lihong00150010 emergency tau&service end */
        /* 延时发送attach请求 */
        NAS_EMM_ReattachDelay();
    }
    else
    {
        NAS_EMM_RelReq(NAS_LMM_NOT_BARRED);
    }

    /* 清空TAU流程所有资源*/
    NAS_EMM_TAU_ClearResouce();
    NAS_EMM_ClearAppMsgPara();

    return;

}
/*****************************************************************************
 Function Name  : NAS_LMM_DecodeNvFplmnList
 Discription    : 解码Forbidden PLMN List
 Input          : pstNvCtrlTbl:公共处理结构
 Output         : 解码后的数据
 Return         :
 History:
*****************************************************************************/
VOS_UINT32 NAS_LMM_DecodeNvFplmnList(NAS_NVIM_CTRL_TBL *pstNvCtrlTbl)
{
    #if 0
    VOS_UINT32                          i = 0;
    VOS_UINT32                          ulValidPlmnNum = NAS_LMM_NULL;
    VOS_UINT8                           *pucMsg;
    NAS_EMMC_PLMN_LIST_STRU              *pstFplmn;
    VOS_UINT32                          *pulMaxNumOfFplmnByUsim = VOS_NULL_PTR;
    NAS_EMMC_PLMN_ID_STRU                stPlmnId;

    if(NAS_EMM_USIM_FEATURE_HARD        == NAS_LMM_GetUsimFeature())
    {
        NAS_LMM_MEM_SET(&stPlmnId,0,sizeof(NAS_MM_PLMN_ID_STRU));
        pstFplmn                        = (VOS_VOID*)NAS_EMMC_GetMmcGlobleAddr(NAS_LMM_GLOBLE_PARA_FPLMNLIST);
        pucMsg                          = (VOS_UINT8*)pstNvCtrlTbl->pNvData;


        /* 获取存放USIM中的 FPLMN列表中 PLMN个数的 全局变量的地址 */
        pulMaxNumOfFplmnByUsim = (VOS_UINT32 *)NAS_EMMC_GetMmcGlobleAddr(NAS_LMM_GLOBLE_PARA_MAX_NUM_OF_FPLMN_BY_USIM);

        /* 计算USIM 中的 FPLMN列表中 PLMN的个数*/
        *pulMaxNumOfFplmnByUsim = pstNvCtrlTbl->usNvDataLen / NAS_LMM_NVIM_PLMN_ID_LEN;

        /* 若 USIM 中的 FPLMN列表中 PLMN的个数 超过NAS内存允许的最大值,则将此
        个数限制为NAS内存运行的最大值*/
        if (NAS_MM_MAX_PLMN_NUM < (*pulMaxNumOfFplmnByUsim))
        {
            (*pulMaxNumOfFplmnByUsim) = NAS_MM_MAX_PLMN_NUM;
        }

        for(i = 0; i < (*pulMaxNumOfFplmnByUsim); i++)
        {
            /* 顺序拷贝PLMN ID,接着判断是否有效 */
            NAS_LMM_MEM_CPY(             &stPlmnId,
                                        &pucMsg[NAS_LMM_NVIM_PLMN_ID_LEN*i],
                                        NAS_LMM_NVIM_PLMN_ID_LEN);

            /*如果PLMN ID有效,赋值给全局变量*/
            if (VOS_FALSE == NAS_LMM_PlmnIsUndef(&stPlmnId))
            {
                NAS_LMM_MEM_CPY(&(pstFplmn->astPlmnId[ulValidPlmnNum]),
                               &pucMsg[NAS_LMM_NVIM_PLMN_ID_LEN*i],
                               NAS_LMM_NVIM_PLMN_ID_LEN);
                ulValidPlmnNum ++;
            }

        }

        /* 赋值全局变量: 总有效FPLMN ID个数 */
        pstFplmn->ulPlmnNum             = ulValidPlmnNum;

        NAS_LMM_NVIM_LOG1_INFO("NAS_LMM_DecodeNvFplmnList: ulPlmnNum = ",
                                            pstFplmn->ulPlmnNum);
        NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeNvFplmnList: PLMN IS ");
        NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(), (VOS_UINT8*)pstFplmn->astPlmnId,(pstFplmn->ulPlmnNum) * 4);

        return  NAS_LMM_NVIM_OK;
    }
    else
    #endif
    {
        return  NAS_LMM_DecodeOneNvItem(pstNvCtrlTbl);
    }

}
VOS_VOID NAS_EMM_TAU_TAUReqRejectCasue40()
{
    VOS_UINT32                          ulAttachFlag    = VOS_TRUE;
    NAS_EMM_ESM_MSG_BUFF_STRU          *pstEsmMsg       = NAS_EMM_NULL_PTR;

    NAS_EMM_TAU_LOG_INFO( "NAS_EMM_TAU_TAUReqRejectCasue40 is entered.");
	/* lihong00150010 emergency tau&service begin */
    if (NAS_EMM_TAU_START_CAUSE_ESM_EMC_PDN_REQ == NAS_EMM_TAU_GetEmmTAUStartCause())
    {
        NAS_EMM_TAU_SendEsmStatusInd(EMM_ESM_ATTACH_STATUS_EMC_ATTACHING);
    }
    else
    {
        NAS_EMM_TAU_SendEsmStatusInd(EMM_ESM_ATTACH_STATUS_DETACHED);
    }
	/* lihong00150010 emergency tau&service end */
    /*转换EMM状态机MS_REG+SS_REG_LIMITED_SERVICE*/
    NAS_EMM_TAUSER_FSMTranState(EMM_MS_DEREG, EMM_SS_DEREG_NORMAL_SERVICE, TI_NAS_EMM_STATE_NO_TIMER);

    /* 上报TAU结果在冲突处理中执行 */
    /****检查冲突标志并做相应的处理********************************************/
    switch(NAS_EMM_TAU_GetEmmCollisionCtrl())
    {
        case    NAS_EMM_COLLISION_DETACH   :

                NAS_EMM_MmcSendTauActionResultIndRej((VOS_VOID*)NAS_EMM_NULL_PTR);

                if (MMC_LMM_MO_DET_CS_ONLY != NAS_EMM_GLO_AD_GetDetTypeMo())
                {
                    NAS_EMM_DETACH_LOG_INFO("NAS_EMM_TAU_TAUReqRejectCasue40:Process EPS Detach or EPS/IMSI Detach");

                    NAS_EMM_TAU_CollisionDetachProc();

                    /* 本地DETACH*/
                    NAS_LMM_DeregReleaseResource();

                    NAS_EMM_RelReq(NAS_LMM_NOT_BARRED);
                    return;
                }
                else
                {
                    NAS_EMM_DETACH_LOG_INFO("NAS_EMM_TAU_TAUReqRejectCasue40:Process IMSI Detach");

                    NAS_EMM_TAU_CollisionDetachProc();

                    /* IMSI DETACH后释放资源 */
                    NAS_LMM_ImsiDetachReleaseResource();
                }
                break;

        case    NAS_EMM_COLLISION_SERVICE    :

                /* 如果是紧急CSFB,则标识不发内部ATTACH */
                if(VOS_FALSE == NAS_EMM_SER_IsNotEmergencyCsfb())
                {
                   ulAttachFlag = VOS_FALSE;
                }

                NAS_EMM_TAU_CollisionServiceProc(NAS_EMM_MmcSendTauActionResultIndRej,
                                  (VOS_VOID*)NAS_EMM_NULL_PTR,
                                  NAS_EMM_TRANSFER_RAT_NOT_ALLOW);
                break;

        default :

                NAS_EMM_TAU_LOG_INFO( "NAS_EMM_TAU_TAUReqRejectCasue40 : NO Emm Collision.");
                NAS_EMM_MmcSendTauActionResultIndRej((VOS_VOID*)NAS_EMM_NULL_PTR);
                break;
    }
	/* lihong00150010 emergency tau&service begin */
    pstEsmMsg = (NAS_EMM_ESM_MSG_BUFF_STRU*)(VOS_VOID*)NAS_LMM_GetEmmInfoEsmBuffAddr();
    if ((NAS_EMM_TAU_START_CAUSE_ESM_EMC_PDN_REQ == NAS_EMM_TAU_GetEmmTAUStartCause())
        && (NAS_EMM_NULL_PTR != pstEsmMsg))
    {
        NAS_EMM_TAU_LOG_INFO("NAS_EMM_TAU_RrcRelCause_TAUREJ9: CAUSE_ESM_EMC_PDN_REQ");

        /*保存ESM消息*/
        /*lint -e960*/
        NAS_LMM_MEM_CPY(        (VOS_VOID*)NAS_EMM_GLO_AD_GetEsmMsgAddr(),
                               &(pstEsmMsg->stEsmMsg),
                                (pstEsmMsg->stEsmMsg.ulEsmMsgSize)+4);
        /*lint +e960*/
        NAS_EMM_StartEmergencyAttach();
    }
    else if (VOS_TRUE == ulAttachFlag)
    {/* lihong00150010 emergency tau&service end */
        /* 延时发送attach请求 */
        NAS_EMM_ReattachDelay();
    }
    else
    {
        NAS_EMM_RelReq(NAS_LMM_NOT_BARRED);
    }

    /* 清空TAU流程所有资源*/
    NAS_EMM_TAU_ClearResouce();
    NAS_EMM_ClearAppMsgPara();

    return;
}
/*****************************************************************************
 Function Name   : NAS_EMM_CompCnExtendedSerReqMoNasMsg
 Description     : 组装EXTENDED SERVICE REQ消息
 Input           : pulIndex
 Output          : pucCnMsg
                   pulIndex
 Return          : VOS_VOID

 History         :
    1.lihong      2012-02-23  Draft Enact

*****************************************************************************/
VOS_VOID    NAS_EMM_CompCnExtendedSerReqMoNasMsg
(
    VOS_UINT8                          *pucCnMsg,
    VOS_UINT32                         *pulIndex
)
{
    VOS_UINT32                          ulIndex      = NAS_EMM_NULL;
    VOS_UINT8                           ucKsi        = NAS_EMM_NULL;
    NAS_LMM_PUB_INFO_STRU              *pstEmmInfo   = VOS_NULL_PTR;
    VOS_UINT32                          ulIeLength          = 0;

    ulIndex                 = *pulIndex;
    pstEmmInfo              = NAS_LMM_GetEmmInfoAddr();

    /* 填充 Protocol Discriminator + Security header type*/
    pucCnMsg[ulIndex++]     = EMM_CN_MSG_PD_EMM;

    /* 填充 Detach request message identity */
    pucCnMsg[ulIndex++]     = NAS_EMM_CN_MT_EXT_SER_REQ;

    /* 填充service type */
    if (NAS_EMM_SER_START_CAUSE_MO_CSFB_REQ == NAS_EMM_SER_GetEmmSERStartCause())
    {
        pucCnMsg[ulIndex]   = MMC_LMM_SERVICE_MO_CSFB_1XCSFB;
    }
    else if (NAS_EMM_SER_START_CAUSE_MO_EMERGENCY_CSFB_REQ == NAS_EMM_SER_GetEmmSERStartCause())
    {
        pucCnMsg[ulIndex]   = MMC_LMM_SERVICR_MO_CSFB_1XCSFB_EMERGENCY;
    }
    else
    {
        pucCnMsg[ulIndex]   = MMC_LMM_SERVICR_MT_CSFB_1XCSFB;
    }

    /*填充KSIasme*/
    ucKsi = NAS_EMM_SecuGetKSIValue();
    pucCnMsg[ulIndex++]     |= (ucKsi & 0x0F)<<4;

    /*填充M-TSMI*/

    /* 填写LENGTH为5 */
    pucCnMsg[ulIndex++]     = 5;

    /*  填写TYPE OF IDENTITY,和EVEN/ODD标识,根据协议前4BIT为'1111' */
    pucCnMsg[ulIndex]       = NAS_EMM_TYPE_OF_IDENTITY_TMSI_PTMSI_MTMSI;
    pucCnMsg[ulIndex++]     |= NAS_EMM_HIGH_4_BIT;

    NAS_LMM_MEM_CPY(        &(pucCnMsg[ulIndex]),
                            &pstEmmInfo->stMmUeId.stGuti.stMTmsi,
                            sizeof(NAS_EMM_MTMSI_STRU));
    ulIndex                 += sizeof(NAS_EMM_MTMSI_STRU);

    /* 只有MT CSFB才填充CSFB RESPONSE */
    if (NAS_EMM_SER_START_CAUSE_MT_CSFB_REQ == NAS_EMM_SER_GetEmmSERStartCause())
    {
        pucCnMsg[ulIndex++] = NAS_EMM_EXTENDED_SER_REQ_CSFB_RSP_IEI | NAS_EMM_SER_GetEmmSerCsfbRsp();
    }

    /* 填充EPS bearer context status */
    /*leili modify for isr begin*/
    NAS_EMM_EncodeEpsBearStatus(        &(pucCnMsg[ulIndex]),
                                        &ulIeLength);
    ulIndex                             += ulIeLength;
    /*leili modify for isr end*/
    #if 0
    pucCnMsg[ulIndex++]     = NAS_EMM_TAU_REQ_EPS_STATUS_IEI;
    pucCnMsg[ulIndex++]     = NAS_EMM_CN_EPS_CONTEXT_LEN;

    for(ulLoop = 0; ulLoop < NAS_EMM_GetEpsIdNum(); ulLoop++)
    {
        ucEsmEPSNum         = (VOS_UINT8)(NAS_EMM_GetEpsId(ulLoop));
        if( NAS_EMM_EPS_BEARER_STATUS_NUM_SEVEN < ucEsmEPSNum)
        {
            ucEsmEPSNum     = ucEsmEPSNum - NAS_EMM_EPS_BEARER_STATUS_NUM_EIGNT;
            ucEsmEPS2       = ucEsmEPS2 | NAS_EMM_TAU_ESM_BEARER_LEFT_N(ucEsmEPSNum);
        }
        else
        {
            ucEsmEPS1       = ucEsmEPS1 | NAS_EMM_TAU_ESM_BEARER_LEFT_N(ucEsmEPSNum);
        }
    }
    pucCnMsg[ulIndex++]     = ucEsmEPS1;
    pucCnMsg[ulIndex++]     = ucEsmEPS2;
    #endif
    *pulIndex               = ulIndex;

    return;

}
VOS_UINT32  NAS_LMM_StoreMsgToQue(
                NAS_LMM_PARALLEL_FSM_ENUM_UINT16   enParalFsmId,
                VOS_UINT32                        ulBufPriLevel,
                VOS_UINT32                        ulMsgType,
                const VOS_VOID                    *pMsg )
{
    VOS_UINT32                          ulLength;
    VOS_UINT8                          *pucMsgBuff          = NAS_LMM_NULL_PTR;
    NAS_LMM_BUFF_MSG_STRU			   *pstBuffer           = NAS_LMM_NULL_PTR;
    NAS_LMM_FSM_MSG_BUF_STRU            *pstFsmMsgBuffAddr   = NAS_LMM_NULL_PTR;
    VOS_UINT32                          ulRslt;

    /* 入口检查 ,为了避免内存泄漏,当前只支持EMM,如果需要支持MMC,可以修改以下条件即可,
    ** 并且在对应的模块需要添加相应的处理;另外对于中优先级的缓存,也不支持;*/
    if ( enParalFsmId != NAS_LMM_PARALLEL_FSM_EMM )
    {
        NAS_LMM_PUBM_LOG1_ERR("NAS_LMM_StoreMsgToQue, FsmId error, FsmId:", enParalFsmId);
        return  NAS_LMM_ERR_CODE_ARRAY_OVERFLOW;
    }

    if ( NAS_LMM_NULL_PTR == pMsg )
    {
        NAS_LMM_PUBM_LOG_WARN("NAS_LMM_StoreMsgToQue, Msg is NULL!");
        return  NAS_LMM_ERR_CODE_PTR_NULL;
    }
    if( (NAS_LMM_STORE_HIGH_PRIO_MSG != ulBufPriLevel) &&
        (NAS_LMM_STORE_LOW_PRIO_MSG  != ulBufPriLevel))
    {
        NAS_LMM_PUBM_LOG1_WARN("NAS_LMM_StoreMsgToQue, Prio err!",ulBufPriLevel);
        return  NAS_LMM_ERR_CODE_PARA_INVALID;
    }

    /* 获取缓存Buffer的地址 */
    pstFsmMsgBuffAddr                   = NAS_LMM_GetFsmBufAddr( enParalFsmId );
    if(NAS_LMM_NULL_PTR                  == pstFsmMsgBuffAddr)
    {
        NAS_LMM_PUBM_LOG_WARN(           "NAS_LMM_StoreMsgToQue, Get pstFsmMsgBuffAddr Fail!");
        return  NAS_LMM_ERR_CODE_PTR_NULL;

    }

    /*如果消息存在,移去该消息 */
    NAS_LMM_RemoveMsgFromFsmQue( pstFsmMsgBuffAddr, ulMsgType, ulBufPriLevel );


    pstBuffer = NAS_LMM_GetStoreBufMsgAddr( pstFsmMsgBuffAddr, ulBufPriLevel );
    if(NAS_LMM_NULL_PTR                  == pstBuffer)
    {
        NAS_LMM_PUBM_LOG_WARN(           "NAS_LMM_StoreMsgToQue, GetStoreBufMsgAddr Fail!");
        return  NAS_LMM_ERR_CODE_PTR_NULL;

    }

    /* 获取消息长度  */
    ulLength  = ((NAS_LMM_MSG_HEADER_STRU *)pMsg)->ulLength
                            + NAS_EMM_PUB_VOS_MSG_HEADER_LEN;

    /* 动态分配缓存空间 */
    pucMsgBuff                          = NAS_COMM_AllocBuffItem(NAS_COMM_BUFF_TYPE_EMM, ulLength);
    if(NAS_LMM_NULL_PTR                  == pucMsgBuff )
    {
        NAS_LMM_PUBM_LOG_WARN(           "NAS_LMM_StoreMsgToQue, Msg Allocate Fail!");
        return  NAS_LMM_ERR_CODE_PTR_NULL;
    }

    /* 把需要缓存的消息拷贝到申请到的地址中 */
    NAS_LMM_MEM_CPY( pucMsgBuff, pMsg, ulLength );

    /* 消息入队 */
    pstBuffer->pBuffMsg                 = (VOS_VOID*)(pucMsgBuff);
    pstBuffer->ulEvtType                = ulMsgType;
    ulRslt                              = NAS_LMM_BufMsgInQue( pstFsmMsgBuffAddr,ulBufPriLevel );

    if( NAS_LMM_FAIL                     == ulRslt)
    {
        NAS_LMM_PUBM_LOG_WARN(           "NAS_LMM_StoreMsgToQue, In Queue Fail!");
        ulRslt = NAS_COMM_FreeBuffItem(NAS_COMM_BUFF_TYPE_EMM, pucMsgBuff);

        if (NAS_COMM_BUFF_SUCCESS != ulRslt)
        {
            NAS_LMM_PUBM_LOG_WARN("NAS_LMM_StoreMsgToQue, Memory Free is not succ");
        }

        pstBuffer->pBuffMsg             = NAS_LMM_NULL_PTR;
        pstBuffer->ulEvtType            = 0;
        return  NAS_LMM_ERR_CODE_PTR_NULL;
    }

    return  NAS_LMM_SUCC;
}
VOS_UINT32  NAS_LMM_EncodeSimSecContext( NAS_NVIM_CTRL_TBL *pstNvCtrlTbl )
{
    VOS_UINT8                          *pucNvData = VOS_NULL_PTR;
    LNAS_LMM_NV_EPS_SEC_CONTEXT_STRU   *pstNvSecContext = VOS_NULL_PTR;
    VOS_UINT16                          usIndex = 0;

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeSimSecContext is entered");

    if(NAS_NVIM_NULL_PTR == pstNvCtrlTbl->pData)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_EncodeSimSecContext: WARNING->pData is Null");
        return NAS_LMM_NVIM_FAIL;
    }

    pstNvSecContext                     = (LNAS_LMM_NV_EPS_SEC_CONTEXT_STRU *)pstNvCtrlTbl->pData;
    pucNvData                           = (VOS_UINT8 *)pstNvCtrlTbl->pNvData;

    /*初始化安全上下文为全FF*/
    NAS_LMM_SetArrayAllBytesFF(pucNvData,NAS_EMM_GET_USIM_SECU_FILE_LEN());

    /*EPS NAS Security Context Tag    SMC 长度*/
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SECU_CONTEXT_TAG;

    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_MSG_LEN;

    /*********** KSIASME ************/
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_KSI_TAG;
    pucNvData[usIndex ++]               = sizeof(VOS_UINT8);
    pucNvData[usIndex ++]               = pstNvSecContext->ucKSIasme;

    /*********** KASME **************/
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_KASME_TAG;
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_KASME_LEN;
    NAS_LMM_MEM_CPY(                   &(pucNvData[usIndex]),
                                        pstNvSecContext->aucKasme,
                                        NAS_LMM_NVIM_SEC_KASME_LEN);

    usIndex                             += NAS_LMM_NVIM_SEC_KASME_LEN;

    /*********** Uplink NAS count **************/
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_UPNASCOUNT_TAG;
    pucNvData[usIndex ++]               = sizeof(VOS_UINT32);

    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulUlNasCount >> NAS_LMM_NVIM_MOVE_24_BIT)
                                                      & NAS_LMM_NVIM_BYTE_FF);
    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulUlNasCount >> NAS_LMM_NVIM_MOVE_16_BIT)
                                                      & NAS_LMM_NVIM_BYTE_FF);
    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulUlNasCount >> NAS_LMM_NVIM_MOVE_8_BIT)
                                                      & NAS_LMM_NVIM_BYTE_FF);
    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulUlNasCount)
                                                      & NAS_LMM_NVIM_BYTE_FF);

    /*********** Downlink NAS count **************/
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_DNNASCOUNT_TAG;
    pucNvData[usIndex ++]               = sizeof(VOS_UINT32);

    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulDlNasCount >> NAS_LMM_NVIM_MOVE_24_BIT)
                                                      & NAS_LMM_NVIM_BYTE_FF);
    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulDlNasCount >> NAS_LMM_NVIM_MOVE_16_BIT)
                                                      & NAS_LMM_NVIM_BYTE_FF);
    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulDlNasCount >> NAS_LMM_NVIM_MOVE_8_BIT)
                                                      & NAS_LMM_NVIM_BYTE_FF);
    pucNvData[usIndex ++]               = (VOS_UINT8)((pstNvSecContext->ulDlNasCount)
                                                      & NAS_LMM_NVIM_BYTE_FF);


    /*********** Identifiers of selected NAS integrity and encryption algorithms **************/
    pucNvData[usIndex ++]               = NAS_LMM_NVIM_SEC_ALG_TAG;
    pucNvData[usIndex ++]               = sizeof(VOS_UINT8);
    pucNvData[usIndex ++]               = pstNvSecContext->ucSecuAlg;

    pstNvCtrlTbl->usNvDataLen           = (VOS_UINT16)NAS_EMM_GET_USIM_SECU_FILE_LEN();

    NAS_LMM_NVIM_LOG1_INFO("NAS_LMM_EncodeSimSecContext: ESP SEC CONTEXT",pstNvCtrlTbl->usNvDataLen);

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeSimSecContext: ESP SEC CONTEXT");
    NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(),pucNvData,pstNvCtrlTbl->usNvDataLen);

    /* 如果上次写卡的码流与本次要写入的完全相同,则无需写入 */
    if((0 == NAS_LMM_MEM_CMP( (const VOS_VOID *)NAS_LMM_GET_USIM_EPS_SECU_CONTEXT_ADDR(),
                              (const VOS_VOID *)pucNvData,
                              pstNvCtrlTbl->usNvDataLen)))
    {
        NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeSimPsLoc:  Equal  value!");
        return NAS_LMM_NVIM_WRITTEN_UNNEEDED;
    }

    /* 不相同,更新为本次写卡码流 */
    NAS_LMM_MEM_SET(NAS_LMM_GET_USIM_EPS_SECU_CONTEXT_ADDR(),
                    0,
                    NAS_NVIM_SECU_CONTEXT_MAX_LEN);

    /* 如果长度大于缓存区,则认为异常不保存上次写卡码流 */
    if(NAS_NVIM_SECU_CONTEXT_MAX_LEN >= pstNvCtrlTbl->usNvDataLen)
    {
        NAS_LMM_MEM_CPY(NAS_LMM_GET_USIM_EPS_SECU_CONTEXT_ADDR(),
                        pucNvData,
                        pstNvCtrlTbl->usNvDataLen);
    }

    return NAS_LMM_NVIM_OK;

}
/*****************************************************************************
 Function Name  : NAS_LMM_DecodeSimPsLoc
 Discription    : 解码PS_LOC_FILE
 Input          : pstNvCtrlTbl:公共处理结构
 Output         : 解码后的数据
 Return         :
 History:
*****************************************************************************/
VOS_UINT32  NAS_LMM_DecodeSimPsLoc( NAS_NVIM_CTRL_TBL *pstNvCtrlTbl)
{
    VOS_UINT8                           *pucMsg;
    NAS_LMM_UEID_STRU                    *pstUeId;
    VOS_UINT32                          usIndex = 0;
    VOS_UINT32                          ulRslt = VOS_TRUE;
    VOS_UINT32                          ulRslt2 = VOS_TRUE;
    NAS_LMM_GUTI_STRU                    stGuti;
    NAS_MM_NETWORK_ID_STRU              stLrvTai;
    VOS_UINT8                           ucUpdataSta;
    VOS_UINT8                          *pstLastPsLoc;
    NAS_MM_PLMN_ID_STRU                 stPlmnId;


    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeSimPsLoc is entered ");

    NAS_LMM_MEM_SET(&stGuti, 0, sizeof(NAS_LMM_GUTI_STRU));
    NAS_LMM_MEM_SET(&stLrvTai, 0, sizeof(NAS_MM_NETWORK_ID_STRU));

    pstUeId  = NAS_LMM_GetEmmInfoUeidAddr();
    pstLastPsLoc  = NAS_LMM_GetEmmInfoLastWriteUsimPsLocAddr();

    pucMsg                              = (VOS_UINT8*)pstNvCtrlTbl->pNvData;

    /* 读出卡中的码流保存到上次写卡的全局变量中*/
    NAS_LMM_MEM_CPY( pstLastPsLoc,
                     pucMsg,
                     pstNvCtrlTbl->usNvDataLen);

    /*****************GUTI*********************/
    /*检测文件GUTI头的有效性*/
    if ( NAS_LMM_NVIM_GUTI_AND_OETOI_LEN != pucMsg[usIndex])
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimPsLoc: GUTI HEAD ERR");
        usIndex += NAS_LMM_NVIM_GUTI_AND_OETOI_LEN;
        usIndex ++;
        pstUeId->bitOpGuti                  = NAS_NVIM_BIT_NO_SLCT;

    }
    else
    {
        stGuti.stGutiHead.ucLenth  = NAS_LMM_NVIM_GUTI_AND_OETOI_LEN;

        usIndex ++;

        stGuti.stGutiHead.ucOeToi  = pucMsg[usIndex] & NAS_EMM_LOW_HALF_BYTE_F;

        if (NAS_LMM_NVIM_GUTI_OETOI != stGuti.stGutiHead.ucOeToi)
        {
            NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimPsLoc: GUTI OETOI ERR");
            usIndex += NAS_LMM_NVIM_GUTI_AND_OETOI_LEN;
            pstUeId->bitOpGuti                  = NAS_NVIM_BIT_NO_SLCT;

        }
        else
        {
            usIndex ++;

            /*检测GUTI内容的合法性*/
            ulRslt = NAS_EMM_CheckSimGutiValid(pucMsg, usIndex, NAS_LMM_NVIM_GUTI_LEN);


            /*检测GUTI中PLMN ID的合法性 */
            stPlmnId.aucPlmnId[0] = pucMsg[0 + usIndex];

            stPlmnId.aucPlmnId[1] = pucMsg[1 + usIndex];

            stPlmnId.aucPlmnId[2] = pucMsg[2 + usIndex];

            ulRslt2 &= NAS_LMM_CheckPlmnIsInvalid(&stPlmnId);


            /*检测内容的有效性*/
            if ((VOS_FALSE == ulRslt) || (VOS_TRUE == ulRslt2))
            {
                NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimPsLoc: GUTI Content ERR");

                usIndex = usIndex + NAS_LMM_NVIM_GUTI_LEN;

                pstUeId->bitOpGuti                  = NAS_NVIM_BIT_NO_SLCT;
            }
            else
            {
                NAS_LMM_MEM_CPY(    &stGuti.stPlmnId,
                                    &stPlmnId,
                                    sizeof(NAS_MM_PLMN_ID_STRU));

                usIndex += 3;

                stGuti.stMmeGroupId.ucGroupId = pucMsg[usIndex];
                usIndex ++;

                stGuti.stMmeGroupId.ucGroupIdCnt = pucMsg[usIndex];
                usIndex ++;

                stGuti.stMmeCode.ucMmeCode = pucMsg[usIndex];
                usIndex ++;

                NAS_LMM_MEM_CPY(                    &(stGuti.stMTmsi),
                                                    &(pucMsg[usIndex]),
                                                    sizeof(NAS_LMM_MTMSI_STRU));
                usIndex += sizeof(NAS_LMM_MTMSI_STRU);


                pstUeId->bitOpGuti                  = NAS_NVIM_BIT_SLCT;
                NAS_LMM_MEM_CPY(                    &(pstUeId->stGuti),
                                                    &stGuti,
                                                    sizeof(NAS_LMM_GUTI_STRU));
            }
        }
    }
    /****************L.R.V TAI******************/
    /* 检测LRV TAI中 PLMN合法性 */
    /*检查PLMN中MCC和MNC是否有效*/
    NAS_LMM_MEM_CPY(                    &(stLrvTai.stPlmnId),
                                        &(pucMsg[usIndex]),
                                        NAS_LMM_NVIM_PLMN_ID_LEN);
    usIndex += NAS_LMM_NVIM_PLMN_ID_LEN;

    ulRslt = NAS_LMM_CheckPlmnIsInvalid(&(stLrvTai.stPlmnId));
    /*ulRslt = NAS_LMM_CheckWhetherAllBytesAreFF(pucMsg, usIndex, NAS_LMM_NVIM_PLMN_ID_LEN);*/
    /*plmn无效,设置全局变量中PLMN为0XFFFFFF,TAC为0xfffe*/
    if (VOS_TRUE == ulRslt)
    {
        NAS_EMM_ClearLVRTai();
        usIndex = usIndex + NAS_LMM_NVIM_TAC_LEN;
    }
    else
    {
        NAS_LMM_MEM_CPY(                     &(stLrvTai.stTac),
                                            &(pucMsg[usIndex]),
                                            NAS_LMM_NVIM_TAC_LEN);
        usIndex += NAS_LMM_NVIM_TAC_LEN;

        if (VOS_TRUE == NAS_LMM_TacIsUnexist(&(stLrvTai.stTac)))
        {
            NAS_LMM_UndefTac(&(stLrvTai.stTac));
        }

        NAS_EMM_SetLVRTai(&stLrvTai);
    }
    /***************UPDATE STATUS**************/
    /*检测文件UPDATE STATUS项的有效性*/
    ucUpdataSta = (pucMsg[usIndex])& NAS_LMM_NVIM_LOW_3_BIT_1;

    if ( NAS_LMM_NVIM_VALID_UPDATESTA < ucUpdataSta)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_DecodeSimPsLoc: UPDATE STATUS Content ERR");
    }
    else
    {
        NAS_EMM_MAIN_CONTEXT_SET_AUX_UPDATE_STAE(pucMsg[usIndex]);
    }

    usIndex ++;

    pstNvCtrlTbl->usNvDataLen           = (VOS_UINT16)(usIndex);

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeSimPsLoc:GUTI IS: ");
    NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(),(VOS_UINT8 *)&pstUeId->stGuti,20);
    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_DecodeSimPsLoc:L.R.V TAI IS: ");
    NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(),(VOS_UINT8*)NAS_LMM_GetEmmInfoLastRegPlmnAddr(),4);
    NAS_COMM_PrintArray(NAS_COMM_GET_MM_PRINT_BUF(),(VOS_UINT8*)NAS_LMM_GetEmmInfoLastRegTacAddr(),4);
    NAS_LMM_NVIM_LOG1_INFO("NAS_LMM_DecodeSimPsLoc:UPDATE STATUS IS: ",NAS_EMM_UPDATE_STAE);

    return  NAS_LMM_NVIM_OK;
}
/*****************************************************************************
 Function Name   : NAS_EMM_SaveAttachAcpIe
 Description     : 存储ATTACH ACCPET中携带的信元
 Input           : pMsgStru------------ATTACH ACCEPT消息指针
 Output          : None
 Return          : VOS_VOID

 History         :
    1.lihong00150010      2012-02-27  Draft Enact

*****************************************************************************/
VOS_VOID  NAS_EMM_SaveAttachAcpIe
(
    VOS_VOID                           *pMsgStru
)
{
    NAS_EMM_CN_ATTACH_ACP_STRU         *pRcvEmmMsg = VOS_NULL_PTR;
    VOS_UINT32                          ulTimerLen = NAS_EMM_NULL;

    pRcvEmmMsg                          = (NAS_EMM_CN_ATTACH_ACP_STRU *)pMsgStru;

    /*保存ATTACH结果*/
    NAS_EMM_GLO_AD_SetAttRslt(pRcvEmmMsg->ucAttachRst);

    /*保存T3412 VALUE*/
    ulTimerLen = NAS_EMM_TimerValTransfer(pRcvEmmMsg->stT3412Value.ucUnit,
                                          pRcvEmmMsg->stT3412Value.ucTimerVal);
    NAS_LMM_ModifyPtlTimer(TI_NAS_EMM_PTL_T3412,ulTimerLen);

    /*保存TAI LIST*/
    NAS_LMM_MEM_CPY(                    NAS_EMM_GLO_AD_GetTaiListAddr(),
                                        &(pRcvEmmMsg->stTaiList),
                                        sizeof(NAS_EMM_TA_LIST_STRU));

    /*保存新的TAI List的同时更新ForbTA for Roaming和ForbTA for RPOS*/
    NAS_EMMC_UpdateForbTaList();

    /*向ESM发送ACTIVATE DEFAULT EPS BEARER REQUEST消息*/
    NAS_EMM_EsmSendDataInd(              &(pRcvEmmMsg->stMsgCon));

    /* ATTACH ACP携带GUTI,更新GUTI到EMM的全局变量中*/
    if(NAS_EMM_BIT_SLCT == pRcvEmmMsg->ucBitOpGuti)
    {
        NAS_EMM_SetGuti(&(pRcvEmmMsg->stGuti));

    }

    /* Location area identification,MS identity,EMM cause,EPLMNS收到ATTACH ACCEPT保存,
        发出ATTACH COMPLETE或后续ATTACH失败从本地保存的读取,携带给MMC */

    NAS_EMM_AttSetLai(pMsgStru);

    NAS_EMM_AttSetEplms(pMsgStru);

    NAS_EMM_AttSetMsId(pMsgStru);

    if(pRcvEmmMsg->ucBitOpEmmCau == NAS_EMM_AD_BIT_SLCT)
    {
        NAS_EMM_GLO_AD_OP_GetEmmCau() = NAS_EMM_AD_BIT_SLCT;
        NAS_EMM_GLO_AD_GetEmmCau()    = pRcvEmmMsg->ucEMMCause;
    }
    else
    {
        NAS_EMM_GLO_AD_OP_GetEmmCau()   = NAS_EMM_AD_BIT_NO_SLCT;
        NAS_EMM_GLO_AD_GetEmmCau()      = 0;
    }

    /*ATTACH ACP携带T3402,修改定时器时长*/
    if(pRcvEmmMsg->ucBitOpT3402 == NAS_EMM_AD_BIT_SLCT)
    {
        ulTimerLen = NAS_EMM_TimerValTransfer(pRcvEmmMsg->stT3402Value.ucUnit,
                                              pRcvEmmMsg->stT3402Value.ucTimerVal);
        NAS_LMM_ModifyPtlTimer(TI_NAS_EMM_PTL_T3402,ulTimerLen);

    }
    else
    {
        /*如果ATTACH ACP消息中不携带T3402信元,则恢复默认值12min*/
        NAS_LMM_ModifyPtlTimer(TI_NAS_EMM_PTL_T3402,NAS_LMM_TIMER_T3402_LEN);
    }
    /*leili modify for isr begin*/
    /*ATTACH ACP携带T3423,修改定时器时长*/
    if(pRcvEmmMsg->ucBitOpT3423 == NAS_EMM_AD_BIT_SLCT)
    {
        ulTimerLen = NAS_EMM_TimerValTransfer(pRcvEmmMsg->stT3423Value.ucUnit,
                                              pRcvEmmMsg->stT3423Value.ucTimerVal);
        NAS_LMM_ModifyPtlTimer(TI_NAS_EMM_PTL_T3423,ulTimerLen);

    }
    else
    {
        /*如果ATTACH ACP消息中不携带T3423信元,则恢复默认值为T3412时长*/
        NAS_LMM_GetPtlTimerLen(TI_NAS_EMM_PTL_T3412, &ulTimerLen);
        NAS_LMM_ModifyPtlTimer(TI_NAS_EMM_PTL_T3423,ulTimerLen);
    }
    /*leili modify for isr end*/

    /*更新Emergency number list到全局变量中*/
    NAS_EMM_SetEmergencyList(   pRcvEmmMsg->ucBitOpEmergencyList,
                                &(pRcvEmmMsg->stEmergencyNumList));

    /*更新EPS network feature support到全局变量中*/
    NAS_EMM_SetEpsNetFeature(   pRcvEmmMsg->ucBitOpEpsNetFeature,
                                pRcvEmmMsg->ucEpsNetFeature);

    /*更新Additional update result到全局变量中*/
    if(EMM_ATTACH_RST_PS == pRcvEmmMsg->ucAttachRst)
    {
        /* 仅EPS ONLY成功 则ulAdditionUpRslt保存为NAS_LMM_ADDITIONAL_UPDATE_NOT_ATTACHED */
        NAS_EMM_SetAddUpdateRslt(NAS_EMM_BIT_SLCT, NAS_LMM_ADDITIONAL_UPDATE_NOT_ATTACHED);
    }
    else
    {
        NAS_EMM_SetAddUpdateRslt(   pRcvEmmMsg->ucBitOpAdditionalUpRslt,
                                    pRcvEmmMsg->ulAdditionUpRslt);
    }

    /* lihong00150010 ims begin */
    /* 通知MMC紧急呼号码列表,网侧是否支持IMS VOICE和紧急呼,以及LTE的CS域能力 */
    /* NAS_EMM_SendGmmInfoChangeNotify(); */
    NAS_EMM_SendMmcInfoChangeNotify();
    /*NAS_EMM_SendMmInfoChangeNotify();*/
    /* lihong00150010 ims end */
}
VOS_UINT32  NAS_LMM_EncodeSimPsLoc( NAS_NVIM_CTRL_TBL *pstNvCtrlTbl )
{
    NAS_LMM_GUTI_STRU                    stGuti;
    NAS_MM_TA_STRU                      stTai;
    VOS_UINT8                           *pucNvData;
    VOS_UINT8                           *pucData;
    VOS_UINT16                           usIndex = 0;
    VOS_UINT32                           ulLen = 0;
    VOS_UINT8                          *pstLastPsLoc;

    NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeSimPsLoc is entered");

    pstLastPsLoc                        = NAS_LMM_GetEmmInfoLastWriteUsimPsLocAddr();

    if(NAS_NVIM_NULL_PTR == pstNvCtrlTbl->pData)
    {
        NAS_LMM_NVIM_LOG_ERR("NAS_LMM_EncodeSimPsLoc: WARNING->pData is Null");
        return NAS_LMM_NVIM_FAIL;
    }

    pucData                             = (VOS_UINT8 *)pstNvCtrlTbl->pData;
    pucNvData                           = (VOS_UINT8 *)pstNvCtrlTbl->pNvData;

    /*****************GUTI*******************/
    ulLen                               = sizeof(VOS_UINT32);
    NAS_LMM_MEM_CPY(                     &stGuti,
                                        &(pucData[ulLen]),
                                        sizeof(NAS_LMM_GUTI_STRU));

    pucNvData[usIndex ++]               = NAS_LMM_NVIM_GUTI_AND_OETOI_LEN;
    pucNvData[usIndex ++]               = (stGuti.stGutiHead.ucOeToi |
                                           NAS_EMM_HIGH_HALF_BYTE_F);
    pucNvData[usIndex ++]               = stGuti.stPlmnId.aucPlmnId[0];
    pucNvData[usIndex ++]               = stGuti.stPlmnId.aucPlmnId[1];
    pucNvData[usIndex ++]               = stGuti.stPlmnId.aucPlmnId[2];
    pucNvData[usIndex ++]               = stGuti.stMmeGroupId.ucGroupId;
    pucNvData[usIndex ++]               = stGuti.stMmeGroupId.ucGroupIdCnt;
    pucNvData[usIndex ++]               = stGuti.stMmeCode.ucMmeCode;
    /*pucNvData[usIndex ++]               = stGuti.stMTmsi.ucMTmsi;*/
    NAS_LMM_MEM_CPY(                     &(pucNvData[usIndex]),
                                        &(stGuti.stMTmsi),
                                        sizeof(NAS_LMM_MTMSI_STRU));
    usIndex                             += sizeof(NAS_EMM_MTMSI_STRU);

    /*L.V.R TAI*/
    ulLen                               += sizeof(NAS_LMM_GUTI_STRU);
    NAS_LMM_MEM_CPY(                     &stTai,
                                        &(pucData[ulLen]),
                                        sizeof(NAS_MM_TA_STRU));

    pucNvData[usIndex ++]               = stTai.stPlmnId.aucPlmnId[0];
    pucNvData[usIndex ++]               = stTai.stPlmnId.aucPlmnId[1];
    pucNvData[usIndex ++]               = stTai.stPlmnId.aucPlmnId[2];
    pucNvData[usIndex ++]               = stTai.stTac.ucTac;
    pucNvData[usIndex ++]               = stTai.stTac.ucTacCnt;

    /*UPDATE STATUS*/
    ulLen                               += sizeof(NAS_MM_TA_STRU);
    pucNvData[usIndex++]                = pucData[ulLen];

    pstNvCtrlTbl->usNvDataLen           = usIndex;

    /* 如果上次写卡的码流与本次要写入的完全相同,则无需写入 */
    if((0 == NAS_LMM_MEM_CMP( (const VOS_VOID *)pstLastPsLoc,
                              (const VOS_VOID *)pucNvData,
                              pstNvCtrlTbl->usNvDataLen)))
    {
        NAS_LMM_NVIM_LOG_INFO("NAS_LMM_EncodeSimPsLoc:  Equal  value!");
        return NAS_LMM_NVIM_WRITTEN_UNNEEDED;
    }

    /* 不相同,更新为本次写卡码流 */
    NAS_LMM_MEM_SET( pstLastPsLoc,
                      0,
                      sizeof(LNAS_LMM_NV_EPS_LOC_STRU));

     NAS_LMM_MEM_CPY( pstLastPsLoc,
                      pucNvData,
                      pstNvCtrlTbl->usNvDataLen);

    return NAS_LMM_NVIM_OK;
}