BST_VOID BST_SRV_CHNL_Set_LinkProp( 
    BST_SRV_CHNL_LINK_STRU     *pstChnlLink,
    BST_SRV_CHNL_HEAD_STRU     *pstPktItem )
{
    BST_IP_ERR_T                enIpErrMsg;

    BST_ASSERT_NULL( pstChnlLink );
    BST_ASSERT_NULL( pstPktItem );
    BST_ASSERT_NULL( pstChnlLink->pcSocket );

    enIpErrMsg                  = BST_IP_ERR_OK;
    BST_DBG_LOG1("BST_SRV_CHNL_Set_LinkProp pstPktItem->ucPropType",
            pstPktItem->ucPropType);
    BST_DBG_LOG4("BST_SRV_CHNL_Set_LinkProp seq,ack,sndwnd,sndscale",
        pstPktItem->stProp.ulSeqNum,
        pstPktItem->stProp.ulAckNum,
        pstPktItem->stProp.ulSndWnd,
        pstPktItem->stProp.usSndWscale);

    switch( pstPktItem->ucPropType )
    {
        case BST_IP_SKT_PROP_NONE:        /* 0 没有property */
            return;

        case BST_IP_SKT_PROP_SEQNO:       /* 1 只有seqno */
            enIpErrMsg          = pstChnlLink->pcSocket->IoCtrl 
                                ( BST_SCKT_CMD_SET_SEQNO,
                                ( BST_VOID  *)&(pstPktItem->stProp) );
        break;

        case BST_IP_SKT_PROP_SEQNO_TS:    /* 2 只有seqno+timestamp */
            enIpErrMsg          = pstChnlLink->pcSocket->IoCtrl 
                                ( BST_SCKT_CMD_SET_SEQNO_TS,
                                ( BST_VOID  *)&(pstPktItem->stProp) );
        break;

        case BST_IP_SKT_PROP_TOTAL:       /* 3 完整property */
            if( BST_TRUE == pstChnlLink->ulIsPropSet )
            {
                enIpErrMsg      = pstChnlLink->pcSocket->IoCtrl 
                                ( BST_SCKT_CMD_SET_SEQNO_TS,
                                ( BST_VOID  *)&(pstPktItem->stProp) );
                break;
            }
            enIpErrMsg          = pstChnlLink->pcSocket->IoCtrl 
                                ( BST_SCKT_CMD_DBL_PROPERTY,
                                ( BST_VOID  *)&(pstPktItem->stProp) );
            if( BST_IP_ERR_OK == enIpErrMsg )
            {
                pstChnlLink->ulIsPropSet
                                = BST_TRUE;
            }
        break;

        default:                            /*4 无效*/
             return;
    }
    BST_DBG_LOG1( "BST_SRV_CHNL_Set_LinkProp enIpErrMsg=%d",
                  enIpErrMsg );
}
BST_VOID BST_SYS_MntnTrigReport( BST_VOID )
{
    OM_BST_MSG_STRU                    *pstBstOmIndMsg;
    OM_BST_AGENT_APP_NUM_STRU          *pstBstAppNum;
    BST_UINT32                          ulRslt;
    BST_UINT32                          ulLength;
    BST_UINT16                          usAppNum;
    OM_BST_APP_INFO_STRU               *pstAppInfo;

    ulRslt                              = BST_TRUE;

    /* 申请的大小等于消息头BST_OM_MSG_STRU -4个字节的指针占位 + 实际代理信息大小 */
    usAppNum                            = (BST_UINT16)BST_SYS_MNTN_GetAppNumber();
    ulLength                            = (BST_OS_SIZEOF(OM_BST_MSG_STRU) - 4)
                                          + (BST_OS_SIZEOF(OM_BST_AGENT_APP_NUM_STRU));
    pstBstOmIndMsg                      = (OM_BST_MSG_STRU *)BST_SYS_MntnGetSendExternalMsgBuffAddr(UEPS_PID_BASTET, ulLength);
    if (BST_NULL_PTR == pstBstOmIndMsg)
    {
        BST_DBG_LOG1("BST_SYS_MntnTrigReport, Agent Info Msg Alloc Mem Fail",
                      0);
        return;
    }

    /* 填写消息头 */
    BST_SYS_MntnFillBstOmMsgHead( pstBstOmIndMsg,
                                  ulLength,
                                  ID_BST_OM_AGENT_INFO_IND,
                                  0 );

    pstBstAppNum                        = (OM_BST_AGENT_APP_NUM_STRU *)(pstBstOmIndMsg->aucData);
    pstBstAppNum->usAgentAppNum         = usAppNum;
    pstAppInfo                          = ( (OM_BST_APP_INFO_STRU *)(pstBstAppNum->stBstAppList ) );

    ulRslt                              = BST_SYS_MntnBuildAgentInfoInd( pstAppInfo, usAppNum );

    if (BST_TRUE != ulRslt)
    {
        BST_DBG_LOG1("BST_SYS_MntnTrigReport, Get Bst Agent Info Error: ulRslt",
                      ulRslt);
        return;
    }

    /* 发送IND消息 */
    ulRslt = OM_SendData( (OM_RSP_PACKET_STRU *)pstBstOmIndMsg, (BST_UINT16)ulLength );

    /* 释放传入的消息包 */
    BST_FREE_MSG( UEPS_PID_BASTET, pstBstOmIndMsg );

    if (VOS_OK != ulRslt)
    {
        BST_RLS_LOG1( "[Mntn] Send Maintain Message Fail:", ulRslt );
        return;
    }
    BST_RLS_LOG( "[Mntn] Send Maintain Message Success" );
    return;
}
BST_ERR_ENUM_UINT8  BST_CORE_CNPTask::Report ( BST_ERR_ENUM_UINT8  enErrVal )
{
    if ( BST_NULL_PTR == m_pExptReport )
    {
        BST_RLS_LOG( "BST_CORE_CNPTask::Report m_pExptReport=NULL" );
        return BST_ERR_INVALID_PTR;
    }
    if ( BST_NULL_PTR == m_pSocket )
    {
        BST_RLS_LOG( "BST_CORE_CNPTask::Report m_pSocket=NULL" );
        return BST_ERR_INVALID_PTR;
    }
    if ( !IsValidReportException ( enErrVal ))
    {
        BST_RLS_LOG( "BST_CORE_CNPTask::Report enErrVal is invalid" );
        return BST_ERR_ILLEGAL_PARAM;
    }
    BST_DBG_LOG1( "BST_CORE_CNPTask::Report enErrVal=%d",
                  enErrVal );
    if ( BST_NOT_HEARTBEAT_PACK == enErrVal )
    {
        return ReportNoneHb();
    }
    else if ( BST_TRAFFIC_FLOW_REPORT == enErrVal )
    {
        return ReportTrafficFlow();
    }
    else
    {
        return ( m_pExptReport->Report ( enErrVal ) );
    }
}
BST_VOID * BST_OS_StaticMemAlloc(BST_MEM_TYPE_ENUM_UINT8 enType, BST_UINT32 ulSize )
{
    BST_INT32                  i;
    BST_UINT_PTR         *pulSpace;
    BST_MEM_BLOCK_INFO   *pstMemInfo;
    BST_MEM_CTRL_BLOCK   *pstMemCtrl;
    BST_INT32             lCycle;

    if( 0 == ulSize )
    {
        BST_RLS_LOG("# BST_OS_StaticMemAlloc size is 0");

        return BST_NULL_PTR;
    }

    if(BST_MEM_TYPE_DYNAMIC == enType)
    {
        pstMemInfo = g_BstMemBlockInfo;
        lCycle = BST_MEM_CTRL_BLOCK_NUMBER;
        pstMemCtrl = g_BstMemCtrlBlk;
    }
    else if(BST_MEM_TYPE_PBUF == enType)
    {
        pstMemInfo = g_BstBufBlockInfo;
        lCycle = BST_BUF_CTRL_BLOCK_NUMBER;
        pstMemCtrl = g_BstBufCtrlBlk;
    }
    else
    {
        
        BST_RLS_LOG1("# V_MemAlloc wrong type:%d", enType);
        return BST_NULL_PTR;      
    }

    for ( i=0; i<lCycle; i++ )
    {
        if(ulSize <= pstMemInfo[i].ulSize )
        {
            pulSpace = (BST_UINT_PTR *)BST_OS_StaticMemCtrlBlkMalloc(&(pstMemCtrl[i]));
            if( BST_NULL_PTR != pulSpace )
            {
                /*如果当前申请的内存块是最大size的内存块,需要检查内存是否达到低内存上报的门限*/
                if( i== ( lCycle - 1 ))
                {
                    BST_OS_MemStatusReport( enType );
                }
                /* offset space which be reserved of OSA */
                pulSpace += BST_MEMORY_RESERVED_WORD_HEAD;
                BST_DBG_LOG1("BST_MemAlloc" ,pulSpace);

                return (BST_VOID *)pulSpace;
            }
        }
    }

    BST_RLS_LOG1("# alloce memory fail size %d.", (BST_INT32)ulSize);


    return BST_NULL_PTR;
}
BST_IP_ERR_T BST_SRV_CChnlIpRcver::Connectd( BST_IP_CSocket *pcSocket )
{
    BST_DBG_LOG("BST_SRV_CChnlIpRcver Connectd. ");
#if ( ( BST_OS_VER == BST_WIN32 && BST_VER_TYPE == BST_DBG_VER ) || (BST_MODEM_SELF == 1) )
    BST_SRV_CHNL_LINK_STRU     *pstLinkItem = BST_NULL_PTR;
    BST_SRV_CHNL_LINK_STRU     *pstLinkItem2;
    BST_SRV_CHNL_HEAD_STRU     *pstPktItem;
    BST_ERR_ENUM_UINT8          enRtnVal;
    
    pstLinkItem                 = BST_SRV_Q_PeekHead( g_lstChnlMng );
    pstPktItem                  = BST_SRV_Q_PeekHead( pstLinkItem->pUnsendList );
    pstPktItem->ucPropType      = BST_IP_SKT_PROP_NONE; /*不使用包中的socket属性*/
    enRtnVal                    = BST_SRV_CHNL_Send_Runing( pstLinkItem, pstPktItem );
    if( BST_ERR_ILLEGAL_PARAM == enRtnVal )
    {
        BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&g_lstChnlMng,
                           (BST_SRV_CHNL_Q *)pstLinkItem,
                           (BST_SRV_CHNL_Q **)&pstLinkItem2 );
        BST_OS_TimerRemove( pstLinkItem->ulTimerId );
        BST_DBG_LOG1( "tiger BST_OS_FREE 10,", pstLinkItem );
        BST_OS_FREE( pstLinkItem );
    }
#endif
    return BST_IP_ERR_OK;
}
BST_IP_ERR_T BST_IP_RawTcpClose( BST_FD_T fd, BST_ARG_T Arg )
{
    struct tcp_pcb                     *pstPcb;

    if( !BST_IP_IsRawFdValid(fd) )
    {
        return BST_IP_ERR_MEM;
    }
    pstPcb                              = ( struct tcp_pcb * )fd.pFd;
    /****************************************************************************\
    | If the Socket is in TIME_WAIT or CLOSING, It means the Client has sent FIN |
    | and get the FIN_ACK successfully, We don't need to close it one more time. |
    \****************************************************************************/
    BST_DBG_LOG1( "Lwip BST_IP_RawTcpClose, state=%u", pstPcb->state );
    if ( ( TIME_WAIT == pstPcb->state )
       ||( CLOSING   == pstPcb->state ) )
    {
        return BST_IP_ERR_CONN;
    }

    /* When Pcb in SYN_SENT state, double close would cause serious memory leak!
     * Return BST_IP_ERR_CLR to notice upper layer not close again. */
    if ( SYN_SENT == pstPcb->state )
    {
        tcp_close( pstPcb );
        return BST_IP_ERR_CLR;
    }
    else
    {
        return tcp_close( pstPcb );
    }
}
BST_IP_PKTPROC_MODE_ENUM BST_SRV_CChnlIpRcver::Received(
    BST_IP_CSocket             *pcSocket,
    const BST_UINT8            *const pucData,
    const BST_UINT16            usLength )
{
    BST_DBG_LOG1( "BST_SRV_CChnlIpRcver::Received len", usLength );
    return BST_IP_PKT_REMOVE_PROC;/*CDS已经拷贝,因此这里删除*/
}
BST_VOID BST_CTaskSchdler::TimerExpired(
    BST_OS_TIMERID_T    ulId,
    BST_VOID           *pvPara)
{
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNode;
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNodeNext;

    if ( !BST_OS_IsTimerValid (m_ulTimerId) )
    {
        BST_RLS_LOG1( "BST_CTaskSchdler::TimerExpired m_ulTimerId=%u is invalid",
                      m_ulTimerId );
        return;
    }
    if ( ulId != m_ulTimerId )
    {
        BST_RLS_LOG2( "BST_CTaskSchdler::TimerExpired ulId=%u,m_ulTimerId=%u",
                      ulId, m_ulTimerId );
        return;
    }
    /*
     * 如果没有任务,则直接返回,不做任何操作
     */
    if ( 0 == lstCount( &g_stPTaskList ) )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::TimerExpired g_stPTaskList count=0" );
        return;
    }

    /*
     * 更新系统TICK值
     */
    m_ulSystemTick         += BST_TASK_SYS_TICKS;
    BST_DBG_LOG1 ( "BST_CTaskSchdler::TimerExpired Scheduler TimeOut, Tick=%d ",
                   m_ulSystemTick );

    /*
     * 遍历任务列表,获取任务并进行相应调度
     */
    for ( pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList );
          pstPtaskNode!= BST_NULL_PTR;
          pstPtaskNode = pstPtaskNodeNext )
    {
        pstPtaskNodeNext    = ( BST_CORE_PTASK_NODE_STRU *)
                              lstNext((NODE *)pstPtaskNode);
        if ( BST_NULL_PTR == pstPtaskNode->pcTask )
        {
            continue;
        }
        /*
         * 如果任务不为空,则根据状态进行调度
         */
        ScheduleTask ( pstPtaskNode->pcTask );
    }
    /*
     * 再次启动系统TICK定时器
     */
    BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN );
}
BST_VOID BST_SRV_CHNL_Clear(
    BST_SRV_CHNL_LINK_STRU     *pstChnlLink )
{
    BST_SRV_CHNL_SENT_STRU     *pSentItem;
    BST_SRV_CHNL_SENT_STRU     *pSentItem2;
    BST_SRV_CHNL_HEAD_STRU     *pstPktItem;
    BST_SRV_CHNL_HEAD_STRU     *pstPktItem2;
    BST_DRV_STRU               *pNetDrvHandle;
    BST_UINT8                   ucUnused;
    BST_UINT32                  ulSpinlockCnt;

    BST_ASSERT_NULL( pstChnlLink );
    pstChnlLink->ulIsPropSet    = BST_FALSE;
    for(;;)
    {
        pSentItem               = BST_SRV_Q_PeekHead(pstChnlLink->pSentList);
        if( BST_NULL_PTR == pSentItem )
        {
            break;
        }
        if( BST_DSPP_FLG_LVLTYPE_HS == pSentItem->usProcLevel )
        {
            ulSpinlockCnt       = BST_OS_SpinLock( &g_HighPriCntSpinLock );
            if ( g_ulHighPriCnt > 0 )
            {
                g_ulHighPriCnt--;
                if ( 0 == g_ulHighPriCnt )
                {
                    pNetDrvHandle= BST_DRV_NetGetDvcHandle();
                    ucUnused     = 0;
                    pNetDrvHandle->pfIoCtrl( BST_DRV_CMD_HPR_DATA_FINISH, (BST_VOID *)&ucUnused );
                }
            }
            BST_OS_SpinUnLock( &g_HighPriCntSpinLock , ulSpinlockCnt );
        }
        BST_DBG_LOG1("BST_SRV_CHNL_Clear,g_ulHighPriCnt--",g_ulHighPriCnt);
        BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&pstChnlLink->pSentList,
                           (BST_SRV_CHNL_Q *)pSentItem,
                           (BST_SRV_CHNL_Q **)&pSentItem2 );
        BST_OS_FREE( pSentItem );
    }
    for(;;)
    {
        pstPktItem              = BST_SRV_Q_PeekHead(pstChnlLink->pUnsendList);
        if( BST_NULL_PTR == pstPktItem )
        {
            break;
        }
        BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&pstChnlLink->pUnsendList,
                           (BST_SRV_CHNL_Q *)pstPktItem,
                           (BST_SRV_CHNL_Q **)&pstPktItem2 );
        BST_SRV_FreeIpBlock( pstPktItem );
    }

}
BST_ERR_ENUM_UINT8 BST_APP_CEmailIMAP::FirstTrsProc( BST_VOID )
{
    /*Imap client donot do anything immediately after connected*/
    if( !BST_OS_IsTimerValid(m_ulTimerId) )
    {
        return BST_ERR_ILLEGAL_PARAM;
    }
    BST_DBG_LOG1("start timerId = %u", m_ulTimerId);
    BST_OS_TimerStart( m_ulTimerId, BST_APP_RX_TIME_OUT );
    return BST_NO_ERROR_MSG;
}
/*lint -e429*/
BST_VOID BST_CTaskSchdler::Attach ( BST_CORE_CPTask *pC_PTask )
{
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNode;

    if ( !BST_OS_IsTimerValid (m_ulTimerId) )
    {
        BST_RLS_LOG1( "BST_CTaskSchdler::Attach m_ulTimerId=%u is invalid",
                      m_ulTimerId );
        return;
    }
    if ( BST_NULL_PTR == pC_PTask )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::Attach pC_PTask=NULL" );
        return;
    }
    for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList );
          pstPtaskNode!= BST_NULL_PTR;
          pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) )
    {
        if( pstPtaskNode->pcTask == pC_PTask )
        {
            return;
        }
    }
    /*
     * 申请链表节点资源,用于存储任务
     */
    pstPtaskNode                = ( BST_CORE_PTASK_NODE_STRU *)BST_OS_MALLOC
                                  ( BST_OS_SIZEOF( BST_CORE_PTASK_NODE_STRU ) );
    if( BST_NULL_PTR == pstPtaskNode )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::Attach pstPtaskNode=NULL" );
        return;
    }
    /*
     * 初始化任务数据,添加如任务列表
     */
    pC_PTask->m_ulSuspCounter   = 0;
    pstPtaskNode->pcTask        = pC_PTask;
    lstAdd( &g_stPTaskList, (NODE *)pstPtaskNode );
    /*
     * 如果此时系统TICK定时已经关闭,且PS域服务状态正常,那么需要再次启动定时
     */
    if(  BST_TRUE == BST_OS_TimerIsStop( m_ulTimerId ) )
    {
        m_ulSystemTick          = 0;
        BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN );
        BST_DBG_LOG1( "BST_CTaskSchdler::Attach Start Scheduler Timer:%u",
                      BST_TASK_SYS_BASE_TIMELEN );
    }
}
BST_CORE_CNPTask::~BST_CORE_CNPTask ( BST_VOID )
{
    BST_CORE_CRegedit                  *pcRegedit;
    BST_APP_CMainTask                  *pcMainTask;

    BST_ERR_ENUM_UINT8                  ucRtnVal;
#if ( BST_OS_VER != BST_QCOM_ROS )
    try
    {
#endif
        BST_DBG_LOG( "BST_CORE_CNPTask::~BST_CORE_CNPTask in" );
        pcRegedit                       = BST_CORE_CRegedit::GetInstance();
        pcMainTask                      = BST_APP_CMainTask::GetInstance();

        if ( BST_NULL_PTR != m_pExptReport )
        {
            ucRtnVal                    = Report ( BST_TRAFFIC_FLOW_REPORT );
            if ( BST_NO_ERROR_MSG != ucRtnVal )
            {
                BST_RLS_LOG1( "BST_CORE_CNPTask::~BST_CORE_CNPTask Report Traffic Error: %u", ucRtnVal );
            }
            ucRtnVal                    = Report ( BST_ERR_TASK_REMOVED );
            if ( BST_NO_ERROR_MSG != ucRtnVal )
            {
                BST_RLS_LOG1( "BST_CORE_CNPTask::~BST_CORE_CNPTask Report Removed Error: %u", ucRtnVal );
            }
            delete m_pExptReport;
        }
        if ( BST_NULL_PTR != pcRegedit )
        {
            pcRegedit->unRegist ( this );
        }
        if ( BST_NULL_PTR != pcMainTask )
        {
            pcMainTask->Detach ( this );
        }
        BST_DBG_LOG1( "BST_CORE_CNPTask::~BST_CORE_CNPTask m_pSocket=%p",
                      m_pSocket );
        if ( BST_NULL_PTR != m_pSocket )
        {
            delete m_pSocket;
        }
#if ( BST_OS_VER != BST_QCOM_ROS )
    }
    catch (...)
    {
        BST_RLS_LOG("BST_CORE_CNPTask destructor exception!");
    }
#endif
}
BST_VOID BST_SRV_CHNL_ThreadEntry( BST_VOID *pvArg )
{
    BST_OS_MBX_T      **pstMailBox;
    BST_OS_LOCKCNT_T    tThreadLockCnt;
    BST_EVT_HEAD_STRU  *pstEvent;
    BST_UINT32          ulRtnVal;

    if ( BST_NULL_PTR == pvArg )
    {
        return;
    }
    /*
     * 线程参数初始化,包括邮箱,运行标识
     */
    tThreadLockCnt      = BST_OS_ThreadLock ();
    pstMailBox          = (BST_OS_MBX_T **)pvArg;
   *pstMailBox          = BST_OS_CreateMbx
                        ( BST_OS_GetCurrentThreadId(), BST_L_MBOX_SIZE );
    if ( BST_NULL_PTR == *pstMailBox )
    {
        BST_OS_ThreadUnLock ( tThreadLockCnt );
        return;
    }

    BST_SetThreadInitFlag( BST_CHNL_CTRL_THREAD_FLAG );
    g_lstChnlMng        = BST_NULL_PTR;
    BST_OS_InitSpinLock( &g_HighPriCntSpinLock );
    BST_OS_ThreadUnLock ( tThreadLockCnt );

    /*
     * 进入线程主循环,等待邮件,邮件内容为即将执行的任务
     */
    for(;;)
    {
        ulRtnVal        = BST_OS_RecvMail
                       ( *pstMailBox, (BST_VOID **)&pstEvent, BST_OS_SYS_FOREVER );
        BST_ASSERT_NORM( BST_OS_SYS_TIMEOUT == ulRtnVal );
        BST_SRV_ProcChnlCtrEvent( pstEvent );
        /*这里判断指针不为空再次释放,因此需要传递指针的指针*/
        if( BST_NULL_PTR != pstEvent->pucData )
        {
            BST_DBG_LOG1( "tiger BST_OS_FREE 8,", pstEvent->pucData );
            BST_OS_FREE( pstEvent->pucData );
        }
        BST_OS_FREE( pstEvent );
#if ( BST_VER_TYPE == BST_UT_VER )
        break;
#endif
     }
}
BST_UINT8* BST_SYS_MntnGetSendExternalMsgBuffAddr( BST_UINT32  ulPid,
                                                   BST_UINT32  ulBuffSize )
{
    BST_VOID                   *pMsgBuff;

    BST_ALLOC_MSG(ulPid, pMsgBuff, ulBuffSize);

    if( BST_NULL_PTR == pMsgBuff )
    {
        BST_DBG_LOG1("BST_SYS_MNTN_BuildMntnAgentInfoInd, Alloc Msg Buff Fail, buffersize",
                     ulBuffSize);
        return BST_NULL_PTR;
    }

    return (BST_UINT8 *)pMsgBuff;
}
BST_ERR_ENUM_UINT8  BST_APP_CEmailIMAP::RunStateMachine( BST_VOID )
{
    BST_ERR_ENUM_UINT8          enErrMsg;

    BST_DBG_LOG1( "CEmailIMAP::RunStateMachine m_lServerState =%d",
                  m_lServerState );

    BST_ASSERT_NULL_RTN( m_pcServerResponse0, BST_ERR_INVALID_PTR );
    BST_ASSERT_NULL_RTN( m_pcServerResponse1, BST_ERR_INVALID_PTR );
    BST_ASSERT_NULL_RTN( m_pcServerResponse2, BST_ERR_INVALID_PTR );

    enErrMsg                    = BST_NO_ERROR_MSG;
    switch ( m_lServerState )
    {
        case BST_EMAIL_UNCONNECT:
            enErrMsg            = HandleWelcomResp();
            break;
        case BST_EMAIL_CONNECTED:
            enErrMsg            = HandleImapIDResp();
            break;

        case BST_EMAIL_IMAP_ID:
            enErrMsg            = HandleAuthResp();
            break;

        case BST_EMAIL_IMAP_LOGINED:
            enErrMsg            = HandleSelectResp();
            break;

        case BST_EMAIL_IMAP_SELECTED:
            enErrMsg            = HandleQueryResp();
            break;

        case BST_EMAIL_IMAP_QUERYED:
            enErrMsg            = HandleQuitResp();
            break;
        default:
            break;
    }
    BST_OS_MEMSET( m_pcServerResponse0, 0, BST_IMAP_COLUMN_MAX );
    BST_OS_MEMSET( m_pcServerResponse1, 0, BST_IMAP_COLUMN_MAX );
    BST_OS_MEMSET( m_pcServerResponse2, 0, BST_IMAP_COLUMN_MAX );
    return enErrMsg;
}
BST_VOID BST_SRV_CHNL_Send_Suspend( 
    BST_SRV_CHNL_LINK_STRU     *pstChnlLink,
    BST_SRV_CHNL_HEAD_STRU     *pstPktItem )
{
    BST_ASSERT_NULL( pstChnlLink );
    BST_ASSERT_NULL( pstPktItem );

    BST_DBG_LOG1("BST_SRV_CHNL_Send_Suspend state",pstChnlLink->enState);
    BST_SRV_Q_PushToTail( (BST_SRV_CHNL_Q **)&pstChnlLink->pUnsendList,
                          (BST_SRV_CHNL_Q *)pstPktItem );
    if( BST_SRV_CHNL_STATE_RUN == pstChnlLink->enState )
    {
        pstChnlLink->ulRetryTimes   = 0;
    }
    if( BST_OS_TimerIsStop( pstChnlLink->ulTimerId ) )
    {
        BST_OS_TimerStart( pstChnlLink->ulTimerId, BST_SRV_CHNL_RTX_INTERVAL );
    }
}
BST_IP_ERR_T BST_IP_RawTcpSocket( BST_FD_T *pfd )
{
    struct tcp_pcb                     *pstPcb;

    pstPcb                              = tcp_new();
    BST_DBG_LOG1( "BST_IP_RawTcpSocket, pstPcb = %p", pstPcb );
    if ( !BST_IP_IsLwipNull(pstPcb) )
    {
        tcp_recv( pstPcb, LWIP_NULL_PTR );
        tcp_err( pstPcb, LWIP_NULL_PTR );
        tcp_arg( pstPcb, pstPcb );
        pstPcb->flags                  |= TF_NODELAY;
        pfd->pFd                        = pstPcb;
        return BST_IP_ERR_OK;
    }
    else
    {
        return BST_IP_ERR_MEM;
    }
}
BST_UINT32 BST_OS_StaticMemFree(BST_VOID **ppAddr)
{
    BST_UINT_PTR                        ulBlockAdd;
    BST_UINT_PTR                        ulCtrlkAdd;
    
    BST_DBG_LOG1("BST_OS_StaticMemFree",*ppAddr);

    if( BST_NULL_PTR == ppAddr )
    {
        return BST_MEM_ERROR;
    }

    if ( BST_MEM_OK != BST_OS_StaticMemCheck( *ppAddr, &ulBlockAdd, &ulCtrlkAdd) )
    {
        BST_RLS_LOG("BST_MemFree error");
        return BST_MEM_ERROR;
    }

    return BST_OS_StaticMemCtrlBlkFree( (BST_MEM_CTRL_BLOCK *)ulCtrlkAdd,
            (BST_MEM_HEAD_BLOCK *)ulBlockAdd );
}
err_t BST_IP_TcpConnectedCB( BST_VOID *arg, struct tcp_pcb *tpcb, err_t err )
{
    err_t                               lErrType;
    BST_IP_CRcverMng                   *pcRcverMnger;
    BST_FD_T                            fd;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    BST_ASSERT_NULL_RTN( tpcb, ERR_ARG );

    tThreadLockCnt                      = BST_OS_ThreadLock();
    pcRcverMnger                        = BST_IP_CRcverMng::GetInstance();
    BST_DBG_LOG1( "BST_IP_Tcp connect successfully , err: %d", err );

    if ( BST_NULL_PTR == pcRcverMnger )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return ERR_MEM;
    }
    fd.pFd                              = tpcb;
    lErrType                            = pcRcverMnger->CnctedRcver( fd, err );
    BST_OS_ThreadUnLock( tThreadLockCnt );
    return lErrType;
}
BST_VOID BST_SYS_MntnFillBstOmMsgHead(
    OM_BST_MSG_STRU             *pstBstOmTransMsg,
    BST_UINT32                   ulTotalLen,
    OM_BST_MSG_TYPE_ENUM_UINT16  enMsgType,
    BST_UINT16                   usToolId )
{
    if (BST_NULL_PTR == pstBstOmTransMsg)
    {
        BST_DBG_LOG1("BST_SYS_MNTN_FillBstOmMsgHead, Null Ptr", 0);
        return;
    }

    pstBstOmTransMsg->stBstOmHead.usLength   = (BST_UINT16)(ulTotalLen - BST_OM_HEADER_LEN);

    pstBstOmTransMsg->stBstOmHead.ucFuncType = OM_TRANS_FUNC;

    OM_AddSNTime(&(pstBstOmTransMsg->stBstOmHead.ulSn),
                 &(pstBstOmTransMsg->stBstOmHead.ulTimeStamp));

    pstBstOmTransMsg->usPrimId = enMsgType;
    pstBstOmTransMsg->usToolId = usToolId;

    return;
}
BST_ERR_ENUM_UINT8 BST_CORE_CNPTask::ConfigedSockeProperty(
    BST_UINT16                  usLen,
    const BST_VOID             *const pData,
    BST_UINT8                 **pucNewAddr )
{
    BST_IP_ERR_T                        enIpErrMsg;
    BST_ERR_ENUM_UINT8                  ucRtnVal;

    if ( BST_NULL_PTR == m_pSocket )
    {
        BST_RLS_LOG( "BST_CORE_CNPTask::ConfigedSockeProperty m_pSocket=NULL" );
        return BST_ERR_ILLEGAL_PARAM;
    }

    if ( usLen < BST_OS_SIZEOF ( BST_IP_SKT_PROPTY_STRU ) )
    {
        BST_RLS_LOG1( "BST_CORE_CNPTask::ConfigedSockeProperty usLen=%u",
                      usLen );
        return BST_ERR_PAR_LEN;
    }
    
    enIpErrMsg                  = m_pSocket->IoCtrl ( BST_SCKT_CMD_SET_PROPERTY,
                                                    ( BST_VOID  *)pData );
    BST_DBG_LOG1( "BST_CORE_CNPTask::ConfigedSockeProperty enIpErrMsg=%d",
                  enIpErrMsg );
    if( BST_IP_ERR_OK == enIpErrMsg )
    {
        BST_SetConfigFlag ( BST_CFGFLG_PRTY );
        ucRtnVal                = BST_NO_ERROR_MSG;
    }
    else
    {
        ucRtnVal                = BST_ERR_ILLEGAL_PARAM;
    }
    return ucRtnVal;
}
BST_VOID BST_SRV_CEvent::RcvThread( BST_VOID *pvArg )
{
    BST_OS_MBX_T                      **pstMailBox;
    BST_EVT_HEAD_STRU                  *pstEvtMsg;
    BST_AS_EVT_STRU                    *pstAsEvt;
    BST_ACOM_EVT_STRU                  *pstAcomEvt;
    BST_TIMER_EVT_STRU                 *pstTimerEvt;
    BST_NET_EVENT_STRU                 *pstNetEvt;
    BST_DSPP_CTrsDlVa                  *pcTrslayer;
    BST_SRV_CAsEvt                     *pcAsMng;
    BST_OS_TIMERID_T                    ulTimerId;
    BST_UINT32                          ulRtnVal;

    BST_ASSERT_NULL( pvArg );
    pstMailBox                          = (BST_OS_MBX_T **)pvArg;
   *pstMailBox                          = BST_OS_CreateMbx( BST_OS_GetCurrentThreadId(), BST_M_MBOX_SIZE );
    BST_ASSERT_NULL( *pstMailBox );
    BST_SetThreadInitFlag( BST_MAIN_THREAD_FLAG );

    for (;;)
    {
        ulRtnVal                        = BST_OS_RecvMail( *pstMailBox, (BST_VOID **)&pstEvtMsg, BST_OS_SYS_FOREVER );

        if( BST_OS_SYS_TIMEOUT == ulRtnVal )
        {
            continue;
        }
        if( BST_NULL_PTR == pstEvtMsg )
        {
            continue;
        }
        BST_DBG_LOG1( "BST_SRV_CEvent::RcvThread pstEvtMsg->enId=%d",
                      pstEvtMsg->enId );
        switch( pstEvtMsg->enId )
        {
        case BST_SRV_ACOM_EVENT:
            pcTrslayer                  = BST_DSPP_CTrsDlVa::GetInstance();
            if ( BST_NULL_PTR == pcTrslayer )
            {
                break;
            }
            pstAcomEvt                  = (BST_ACOM_EVT_STRU *)pstEvtMsg;
            pcTrslayer->RxApi( pstAcomEvt->pucData, (BST_UINT16)pstAcomEvt->ulLength );
            break;

        case BST_SRV_AS_EVENT:
            pcAsMng                     = BST_SRV_CAsEvt::GetInstance();
            if ( BST_NULL_PTR == pcAsMng )
            {
                break;
            }
            pstAsEvt                    = (BST_AS_EVT_STRU *)pstEvtMsg;
            pcAsMng->AsEventRcv( pstAsEvt->enAsEvent, pstAsEvt->ulLength,(BST_VOID *)pstAsEvt->pucData );
            break;

        case BST_SRV_TIMER_EVENT:
            pstTimerEvt                 = (BST_TIMER_EVT_STRU *)pstEvtMsg;
            if( BST_OS_SIZEOF(ulTimerId) != pstTimerEvt->ulLength )
            {
                break;
            }
            BST_OS_MEMCPY( &ulTimerId, pstTimerEvt->pucData, BST_OS_SIZEOF(ulTimerId) );
            BST_OS_TimerDoCallBack( ulTimerId );
            break;

        case BST_SRV_TCPIP_EVENT:
            pstNetEvt                   = (BST_NET_EVENT_STRU *)pstEvtMsg;
            if( BST_OS_SIZEOF(BST_IP_EVENT_STRU) != pstNetEvt->ulLength )
            {
                break;
            }
            BST_IP_CallBackEntry ( ( BST_IP_EVENT_STRU * )pstNetEvt->pucData );
            break;

        default:
            break;
        }

        if( BST_NULL_PTR != pstEvtMsg->pucData )
        {
            BST_OS_FREE( pstEvtMsg->pucData );
        }
        BST_OS_FREE( pstEvtMsg );

#if ( BST_VER_TYPE == BST_UT_VER )
        break;
#endif

    }
}
BST_ERR_ENUM_UINT8 BST_SRV_CHNL_Itf(
    BST_SRV_CHNL_HEAD_STRU     *pstPktItem )
{
    BST_SRV_CHNL_LINK_STRU     *pstLinkItem = BST_NULL_PTR;
    BST_SRV_CHNL_LINK_STRU     *pstLinkItem2;
    BST_IP_CSocket             *pcSocket;
    BST_OS_TIMERID_T            ulTimerId;
    BST_ERR_ENUM_UINT8          enRtnVal;

    BST_ASSERT_NULL_RTN( pstPktItem, BST_ERR_INVALID_PTR );
    pstLinkItem                 = BST_SRV_Q_PeekHead( g_lstChnlMng );
    enRtnVal                    = BST_NO_ERROR_MSG;
    for(;;)
    {
        if( BST_NULL_PTR == pstLinkItem )
        {
            break;
        }
        if( ( pstLinkItem->stLink.ulMainLinkId == pstPktItem->ulMainLinkId )
          &&( pstLinkItem->stLink.ulAuxLinkId == pstPktItem->ulAuxLinkId ) )
        {
            break;
        }
        pstLinkItem             = pstLinkItem->pNext;
    }

    BST_DBG_LOG1( "CPC_PACKET_DROP pstPktItem->usCmdId", pstPktItem->usCmdId );
    switch( pstPktItem->usCmdId )
    {
        case BST_DSPP_FLG_CMD_CLEAR:
            if( BST_NULL_PTR != pstLinkItem )
            {
                BST_SRV_CHNL_Close( pstLinkItem );
                delete pstLinkItem->pcSocket;
                BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&g_lstChnlMng,
                                   (BST_SRV_CHNL_Q *)pstLinkItem,
                                   (BST_SRV_CHNL_Q **)&pstLinkItem2 );
                BST_OS_TimerRemove( pstLinkItem->ulTimerId );
                BST_OS_FREE( pstLinkItem );
            }
            else
            {
                enRtnVal        = BST_ERR_UNKNOW_OBJ;
            }
        break;

        case BST_DSPP_FLG_CMD_CLOSE:
            if( BST_NULL_PTR != pstLinkItem )
            {
                BST_SRV_CHNL_Close( pstLinkItem );
                delete pstLinkItem->pcSocket;
                BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&g_lstChnlMng,
                                   (BST_SRV_CHNL_Q *)pstLinkItem,
                                   (BST_SRV_CHNL_Q **)&pstLinkItem2 );
                BST_OS_TimerRemove( pstLinkItem->ulTimerId );
                BST_OS_FREE( pstLinkItem );
            }
            else
            {
                enRtnVal        = BST_ERR_UNKNOW_OBJ;
            }
        break;

        case BST_DSPP_FLG_CMD_SEND:
            BST_DBG_LOG1("BST_SRV_CHNL_Itf send pstLinkItem",pstLinkItem);
            if( BST_NULL_PTR == pstLinkItem )
            {
                pstLinkItem     = (BST_SRV_CHNL_LINK_STRU *)BST_OS_MALLOC
                                  ( BST_OS_SIZEOF(BST_SRV_CHNL_LINK_STRU) );
                if( BST_NULL_PTR == pstLinkItem )
                {
                    enRtnVal    = BST_ERR_NO_MEMORY;
                    break;
                }
                pcSocket        = BST_SRV_CHNL_CreateSocket( pstPktItem );
                if ( BST_NULL_PTR == pcSocket )
                {
                    BST_RLS_LOG("BST_SRV_CHNL_CreateSocket error");
                    enRtnVal    = BST_ERR_PAR_UNKNOW;
                    break;
                }
                ulTimerId       = BST_OS_TimerCreate
                                ( BST_SRV_CHNL_SysTimerExpired, BST_NULL_PTR, 
                                  BST_SRV_GetChnlCtrlHandle( 0 ) );
                BST_SRV_CHNL_InitLink( pstLinkItem, pcSocket, ulTimerId );
                pstLinkItem->ulAddrType             = BST_DSPP_FLG_ADDTYPE_INET;
                pstLinkItem->stLink.ulMainLinkId    = pstPktItem->ulMainLinkId;
                pstLinkItem->stLink.ulAuxLinkId     = pstPktItem->ulAuxLinkId;
                BST_SRV_Q_PushToTail( (BST_SRV_CHNL_Q **)&g_lstChnlMng,
                                      (BST_SRV_CHNL_Q *)pstLinkItem );
            }

            enRtnVal            = BST_SRV_CHNL_Send( pstLinkItem, pstPktItem );
            if( BST_ERR_ILLEGAL_PARAM == enRtnVal )
            {
                BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&g_lstChnlMng,
                                   (BST_SRV_CHNL_Q *)pstLinkItem,
                                   (BST_SRV_CHNL_Q **)&pstLinkItem2 );
                BST_OS_FREE( pstLinkItem );
            }

            return enRtnVal;

        default:
        break;
    }
    BST_SRV_FreeIpBlock( pstPktItem );
    return enRtnVal;
}
BST_VOID BST_CTaskSchdler::UtranBlockInfoChgProc( BST_UINT32 *pulBlockInfo )
{
    BST_INT32                   lTaskCnt;
    BST_UINT32                  ulNextTickRemainTime;
    BST_UINT32                  ulBlockInfo;
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNode;
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNodeNext;
    BST_BOOL                    bTimerStop;

    if( BST_NULL_PTR == pulBlockInfo)
    {
        return;
    }
    ulBlockInfo     = (BST_UINT32 )*pulBlockInfo;
    BST_DBG_LOG2( "BST_CTaskSchdler::UtranBlockInfoChgProc blockold=u%, blockNew=u%",
                  m_ulBlockInfo,ulBlockInfo);

    if ( m_ulBlockInfo == ulBlockInfo )
    {
        return;
    }
    m_ulBlockInfo           = ulBlockInfo;

    if ( BST_AS_UNBLOCKED == m_ulBlockInfo )
    {

        BST_DBG_LOG1( "BST_CTaskSchdler::UtranBlockInfoChgProc :%d", m_bTaskMissExec );
        if(BST_FALSE == m_bTaskMissExec)
        {
            return;
        }
        lTaskCnt            = lstCount( &g_stPTaskList );

        BST_DBG_LOG1( "BST_CTaskSchdler::UtranBlockInfoChgProc TaskNum=u%", lTaskCnt );

        if ( 0 == lTaskCnt )
        {
            return;
        }
        ulNextTickRemainTime = 0;
        bTimerStop      = BST_OS_TimerIsStop( m_ulTimerId );
        if ( BST_FALSE == bTimerStop )
        {
            ulNextTickRemainTime      = BST_OS_TimeGetRemain( m_ulTimerId );
            BST_OS_TimerStop ( m_ulTimerId );
        }

        BST_DBG_LOG2( "BST_CTaskSchdler::UtranBlockInfoChgProc stop:%d,timerremain=u%", bTimerStop,ulNextTickRemainTime );
        /*
         * 遍历任务列表,获取任务并进行相应调度
         */
        for ( pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList );
              pstPtaskNode!= BST_NULL_PTR;
              pstPtaskNode = pstPtaskNodeNext )
        {
            pstPtaskNodeNext    = ( BST_CORE_PTASK_NODE_STRU *)
                                  lstNext((NODE *)pstPtaskNode);
            if ( BST_NULL_PTR == pstPtaskNode->pcTask )
            {
                continue;
            }
            /*
             * 如果任务不为空,则根据状态进行调度
             */
            TrigScheduleTask ( pstPtaskNode->pcTask);
        }

        if((0 == ulNextTickRemainTime) || (ulNextTickRemainTime > BST_TASK_SYS_BASE_TIMELEN))
        {
            ulNextTickRemainTime = BST_TASK_SYS_BASE_TIMELEN;
        }

        BST_OS_TimerStart ( m_ulTimerId, ulNextTickRemainTime );

    }

}
BST_ERR_ENUM_UINT8 BST_SRV_CHNL_Acked (
    BST_SRV_CHNL_LINK_STRU     *pstLinkItem,
    const BST_UINT32            ulMinNumber,
    const BST_UINT32            ulMaxNumber )
{
    BST_SRV_CHNL_SENT_STRU             *pSentItem;
    BST_SRV_CHNL_SENT_STRU             *pSentItem2;
    BST_SRV_CHNL_HEAD_STRU             *pstPktItem;
    BST_SRV_CHNL_HEAD_STRU             *pstPktItem2;
    BST_UINT32                          ulSpinlockCnt;
    BST_UINT32                          ulOrigCounter;
    BST_DRV_STRU                       *pNetDrvHandle;
    BST_ERR_ENUM_UINT8                  enRtnVal;

    BST_ASSERT_NULL_RTN( pstLinkItem, BST_ERR_INVALID_PTR );
    BST_ASSERT_NORM_RTN( ulMaxNumber < ulMinNumber, BST_ERR_ILLEGAL_PARAM );

    BST_DBG_LOG2( "BST_SRV_CHNL_Acked ulMinNumber, ulMaxNumber",
                  ulMinNumber, ulMaxNumber );
    /*查找已发送的数据包的*/
    pSentItem                           = BST_SRV_Q_PeekHead(pstLinkItem->pSentList);
    ulOrigCounter                       = g_ulHighPriCnt;
    pSentItem2                          = BST_NULL_PTR;
    pstPktItem2                         = BST_NULL_PTR;
    while( pSentItem != BST_NULL_PTR )
    {
        if ( ( pSentItem->ulAckNo > ulMinNumber )
           &&( pSentItem->ulAckNo <=ulMaxNumber ) )
        {
            if( BST_DSPP_FLG_LVLTYPE_HS == pSentItem->usProcLevel )
            {
                ulSpinlockCnt           = BST_OS_SpinLock( &g_HighPriCntSpinLock );
                if ( g_ulHighPriCnt > 0 )
                {
                    g_ulHighPriCnt--;
                }
                BST_OS_SpinUnLock( &g_HighPriCntSpinLock , ulSpinlockCnt );
            }
            BST_DBG_LOG1("BST_SRV_CHNL_Acked,g_ulHighPriCnt--",g_ulHighPriCnt);
            BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&pstLinkItem->pSentList,
                               (BST_SRV_CHNL_Q *)pSentItem,
                               (BST_SRV_CHNL_Q **)&pSentItem2 );
            BST_OS_FREE( pSentItem );
        }
        else
        {
            pSentItem2                  = pSentItem->pNext;
        }
        pSentItem                       = pSentItem2;
    }

    pstPktItem                          = BST_SRV_Q_PeekHead(pstLinkItem->pUnsendList);
    while ( pstPktItem != BST_NULL_PTR )
    {
        if( BST_IP_SKT_PROP_NONE != pstPktItem->ucPropType )
        {
            if( ( ( pstPktItem->stProp.ulSeqNum + pstPktItem->ulUsed  ) > ulMinNumber )
              &&( ( pstPktItem->stProp.ulSeqNum + pstPktItem->ulUsed  ) <=ulMaxNumber ) )
            {
                BST_SRV_Q_RmvItem( (BST_SRV_CHNL_Q **)&pstLinkItem->pUnsendList,
                                   (BST_SRV_CHNL_Q *)pstPktItem,
                                   (BST_SRV_CHNL_Q **)&pstPktItem2 );
                BST_SRV_FreeIpBlock( pstPktItem );
            }
            else
            {
                pstPktItem2             = pstPktItem->pNext;
            }
        }
        else
        {
            pstPktItem2                 = pstPktItem->pNext;
        }
        pstPktItem                      = pstPktItem2;
    }
    enRtnVal                            = BST_NO_ERROR_MSG;
    if( BST_NULL_PTR != pstLinkItem->pUnsendList )
    {
        BST_OS_TimerStop( pstLinkItem->ulTimerId );
        BST_DBG_LOG( "BST_SRV_CHNL_Acked, Proc Unsent List" );
        enRtnVal                        = BST_SRV_CHNL_ProcInCB( pstLinkItem );
    }

    /**
     * 刚刚有值,现在无值,那么说明全部高优先数据发送完成
     */
    if( ( 0 != ulOrigCounter ) && ( 0 == g_ulHighPriCnt ) )
    {
        pNetDrvHandle   = BST_DRV_NetGetDvcHandle();
        enRtnVal        = 0;
        pNetDrvHandle->pfIoCtrl( BST_DRV_CMD_HPR_DATA_FINISH, (BST_VOID *)&enRtnVal );
        BST_DBG_LOG( "BST_SRV_CHNL_Acked, BST_DRV_CMD_HPR_DATA_FINISH" );
    }

    return enRtnVal;
}
BST_VOID BST_PAL_NetProcDlPacket( const TTF_MEM_ST  *pstTtfPacket )
{
    BST_IP_PKT_PROC_ENUM_INT8           enPktProcMode;
    BST_UINT8                          *pucTmpdata;
    BST_UINT32                          ulIsMalloced;
    BST_UINT32                          ulTotalBytes;

    pucTmpdata                          = BST_NULL_PTR;
    ulTotalBytes                        = 0x00U;
    ulIsMalloced                        = BST_FALSE;
    if ( BST_NULL_PTR == pstTtfPacket )
    {
        BST_RLS_LOG( "BST_PAL_NetProcDlPacket: pstTtfPacket Invalide" );
        return;
    }

    if( ( 0 == pstTtfPacket->usUsed )
      ||( BST_NULL_PTR == pstTtfPacket->pData ) )
    {
        BST_RLS_LOG2( "BST_PAL_NetProcDlPacket: No Data tot=%u, used=%u, pData=%p",
        pstTtfPacket->usUsed, pstTtfPacket->pData );
        return;
    }

    ulTotalBytes                        = BST_PAL_NetApiPacketLen( (BST_VOID*)pstTtfPacket );
    if ( BST_NULL_PTR == pstTtfPacket->pNext )
    {
        pucTmpdata                      = pstTtfPacket->pData;
        ulIsMalloced                    = BST_FALSE;
    }
    else
    {
        pucTmpdata                      = (BST_UINT8 *)BST_OS_MALLOC( ulTotalBytes );
        BST_ASSERT_NULL( pucTmpdata );
        if( TTF_MemGet( UEPS_PID_BASTET, ( TTF_MEM_ST *)pstTtfPacket,
                        0U, pucTmpdata, (BST_UINT16)ulTotalBytes ) )
        {
        /*lint -e438*/
            BST_OS_FREE( pucTmpdata );
            return;
        /*lint +e438*/
        }
        ulIsMalloced                    = BST_TRUE;
    }
    BST_DBG_LOG1( "BST_PAL_NetProcDlPacket: TolLen=%u", ulTotalBytes );
    enPktProcMode                       = BST_IP_ApiFastCheckDL( pucTmpdata, ulTotalBytes );
    if ( BST_IP_PKT_TO_AP == enPktProcMode)
    {
        BST_RLS_LOG( "BST_PAL_NetProcDlPacket: NOT Bastet Packet" );
        BST_PAL_NetApiPacketResume( (BST_VOID*)pstTtfPacket );
    }
    else
    {
        if ( BST_IP_PKT_FREE == enPktProcMode )
        {
            BST_RLS_LOG( "BST_PAL_NetProcDlPacket: Free Packet" );
            BST_PAL_NetApiPacketFree( (BST_VOID*)pstTtfPacket );
        }
        else
        {
            BST_RLS_LOG1( "BST_PAL_NetProcDlPacket: Bastet Packet, Length=", ulTotalBytes );
            if ( ulTotalBytes != BST_PAL_NetIpStackInput( ulTotalBytes, pucTmpdata, pstTtfPacket ) )
            {
                BST_RLS_LOG( "BST_PAL_NetProcDlPacket: BST_PAL_NetIpStackInput Error" );
                BST_PAL_NetApiPacketFree( (BST_VOID*)pstTtfPacket );
            }
        }
    }
    if ( BST_TRUE == ulIsMalloced )
    {
        BST_OS_FREE( pucTmpdata );
    }
/*lint -e429 -e438 */
}   /*pucTmpdata 是否free需要判断ulIsMalloced,如果指针不是Malloc的,则不需FREE*/
BST_IP_ERR_T BST_IP_SslReceive( BST_FD_T fd, BST_UINT8* pData, BST_UINT16 usLength )
{
    SSL                *pstSsl;
    BST_UINT8          *pucTmpBuf;
    BST_INT32           lRtnVal;
    BST_INT32           lCopyedLen;
    BST_INT32           lSelect;
    BST_INT32           lSockFd;
    fd_set              stRdFds;
    timeval             stTval;
    stTval.tv_sec       = 0;
    stTval.tv_usec      = 0;
    if ( BST_NULL_PTR == fd.pFd )
    {
        return BST_IP_ERR_ARG;
    }
    if ( BST_NULL_PTR == pData )
    {
        return BST_IP_ERR_ARG;
    }

    lCopyedLen          = 0;
    pstSsl              = (SSL *)fd.pFd;
    lSockFd             = SSL_get_fd( pstSsl );

    pucTmpBuf           = (BST_UINT8 *)BST_OS_MALLOC( usLength );

    if ( BST_NULL_PTR == pucTmpBuf )
    {
        return BST_IP_ERR_MEM;
    }
    
    do {
        FD_ZERO( &stRdFds );
        FD_SET( lSockFd, &stRdFds );

        lRtnVal         = SSL_read( pstSsl, pucTmpBuf, usLength );

        
        if ( lRtnVal <= 0 )
        {
            BST_RLS_LOG( "BST_IP_SslReceive SSL_read error" );
            break;
        }
        if ( 0 == lCopyedLen )
        {
            BST_OS_MEMCPY( pData, pucTmpBuf, lRtnVal );
            lCopyedLen  = lRtnVal;
            BST_DBG_LOG1( "BST_IP_SslReceive lCopyedLen", lCopyedLen );
        }
        /*如果ssl内部缓冲区没有数据可读,则判断IP协议栈是否有数据可读*/
        if ( !SSL_pending( pstSsl ) )
        {
            lSelect     = lwip_select( lSockFd + 1, &stRdFds, NULL, NULL, &stTval );
            if ( lSelect < 0)
            {
                BST_RLS_LOG( "BST_IP_SslReceive lwip_select error" );
                break;
            }

            /*如果协议栈也没有数据可读,则说明这次读取完毕,退出*/
            if ( !FD_ISSET( lSockFd,&stRdFds ) )
            {
                BST_DBG_LOG( "BST_IP_SslReceive socket is not data" );
                break;
            }
        }
    } while( 1 );

    BST_OS_FREE( pucTmpBuf );
    return lCopyedLen;
}