BST_IP_ERR_T BST_IP_SslSocket( BST_FD_T *pfd, BST_ARG_T *Arg, BST_UINT16 usProtocol )
{
    SSL                    *pstSsl;
    BST_INT32               lFd;
    BST_IP_ERR_T            lErrRtnVal;
    if ( BST_NULL_PTR == pfd )
    {
        return BST_IP_ERR_ARG;
    }

    lErrRtnVal               = BST_IP_BsdSocket( pfd, Arg, usProtocol );
    if ( BST_IP_ERR_OK != lErrRtnVal )
    {
        BST_RLS_LOG( "BST_IP_SslSocket BST_IP_BsdSocket error" );
        return BST_IP_ERR_ARG;
    }

    lFd                     = pfd->lFd;

    pstSsl                  = BST_IP_SslInit( Arg );

    if ( BST_NULL_PTR == pstSsl )
    {
        BST_RLS_LOG( "BST_IP_SslInit error" );
        return BST_IP_ERR_MEM;
    }

    if ( BST_FALSE == SSL_set_fd( pstSsl, lFd ) )
    {
        BST_RLS_LOG( "SSL_set_fd error" );
        return BST_IP_ERR_MEM;
    }
    pfd->pFd                = pstSsl;
    return BST_IP_ERR_OK;
}
BST_STATIC SSL *BST_IP_SslInit( BST_ARG_T *Arg )
{
    SSL_METHOD              *pstMethod;
    SSL_CTX                 *pstCtx;
    SSL                     *pstSsl;

    if ( BST_NULL_PTR == Arg )
    {
        return BST_NULL_PTR;
    }

    SSL_library_init();

    pstMethod               = ( SSL_METHOD * )TLSv1_client_method();

    if (BST_NULL_PTR == pstMethod)
    {
        BST_RLS_LOG( "BST_IP_SslInit TLSv1_client_method error" );
        return BST_NULL_PTR;
    }

    pstCtx                  = SSL_CTX_new( pstMethod );

    if ( BST_NULL_PTR == pstCtx)
    {
        BST_RLS_LOG( "BST_IP_SslInit SSL_CTX_new error" );
        return BST_NULL_PTR;
    }

    SSL_CTX_set_verify( pstCtx, SSL_VERIFY_NONE, BST_NULL_PTR );
    pstSsl                  = SSL_new( pstCtx );
    *Arg                    = pstCtx;
    return pstSsl;
}
BST_VOID BST_PAL_NetMsgEntry( MsgBlock  *pstMsg )
{
    BST_UINT32                  ulTrsFlg;
    if ( BST_NULL_PTR == pstMsg )
    {
        BST_RLS_LOG( "BST_PAL_NetMsgEntry : Input NULL PTR." );
        return;
    }
    BST_RLS_LOG1( "BST_PAL_NetMsgEntry : MsgId", TTF_GET_MSG_NAME(pstMsg) );
    switch( TTF_GET_MSG_NAME(pstMsg) )
    {
        /* CDS发给BASTET的消息原语: 有其他IP包在运行中 */
        case ID_BST_CDS_TX_RX_IND:
            ulTrsFlg            = BST_TRUE;
            BST_PalAsEventRcvCb( BST_AS_EVT_L3_AP_TRS_RCV_IND, 
                                 ( BST_UINT16 )BST_OS_SIZEOF(ulTrsFlg),
                                 &ulTrsFlg );
            break;

        /* CDS发给BASTET的消息原语: 当前MODEM数据业务使用的MODEM ID*/
        case ID_BST_CDS_CHANNEL_INFO_IND:
            BST_PAL_NetMsgCfgCallBack( (const BST_CDS_SEND_CB_INFO_STRU *)pstMsg );
            break;

        default:
            BST_RLS_LOG( "BST_PAL_NetMsgEntry : Unknown Message." );
            break;
    }
    return;
}
BST_UINT32 BST_CTaskSchdler::ChkTaskExist ( BST_CORE_CPTask *pC_PTask )
{
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNode;

    if ( BST_NULL_PTR == pC_PTask )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::ChkTaskExist pC_PTask=NULL" );
        return BST_FALSE;
    }

    if ( 0 == lstCount( &g_stPTaskList ) )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::ChkTaskExist g_stPTaskList count=0" );
        return BST_FALSE;
    }

    /*
     * 遍历任务表,对比pcPtask,相等的记为找到
     */
    for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList );
          pstPtaskNode!= BST_NULL_PTR;
          pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) )
    {
        if ( BST_NULL_PTR == pstPtaskNode->pcTask )
        {
            continue;
        }
        if ( pC_PTask == pstPtaskNode->pcTask )
        {
            return BST_TRUE;
        }
    }
    return BST_FALSE;
}
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 ) );
    }
}
VOS_VOID BST_FidTask ( VOS_UINT32 Para1, VOS_UINT32 Para2,
                       VOS_UINT32 Para3, VOS_UINT32 Para4 )
{
    MsgBlock       *pMsg                = VOS_NULL_PTR;
    VOS_UINT32      ulEvent             = 0;
    VOS_UINT32      ulTaskID            = 0;
    VOS_UINT32      ulEventMask         = 0;
    VOS_UINT32      ulExpectEvent       = 0;

    ulTaskID                = VOS_GetCurrentTaskID();

    if ( PS_NULL_UINT32 == ulTaskID )
    {
        BST_RLS_LOG ( "BST_FidTask: This Task Id is Error" );
        return;
    }

    if ( VOS_OK != VOS_CreateEvent(ulTaskID) )
    {
        BST_RLS_LOG ( "BST_FidTask:, Create Event Fail");
        return;
    }

    ulExpectEvent           = VOS_MSG_SYNC_EVENT|BST_CDS_EVENT_RCV_DL_PROC;
    ulEventMask             = (VOS_EVENT_ANY | VOS_EVENT_WAIT);
    g_ulBastetTaskId        = VOS_GetCurrentTaskID();
    g_ulBstTaskReadyFlag    = BST_TRUE;

    for (;;)
    {
        if ( VOS_OK != VOS_EventRead(ulExpectEvent,ulEventMask,0,&ulEvent) )
        {
            BST_RLS_LOG ( "BST_FidTask: BASTET Read Event Error" );
            continue;
        }
        /*事件处理*/
        if (VOS_MSG_SYNC_EVENT != ulEvent)
        {
            BST_SYS_EvtProcEntry(ulEvent);
            continue;
        }

        pMsg                = (MsgBlock *)VOS_GetMsg(ulTaskID);
        if ( VOS_NULL_PTR != pMsg )
        {
            switch ( TTF_GET_MSG_RECV_PID( pMsg ) )
            {
                case UEPS_PID_BASTET:
                    BST_SYS_MsgProcEntry( pMsg );
                    break;

                default:
                    BST_RLS_LOG1 ( "BST_FidTask: Recv Unkown Message %d\r\n", TTF_GET_MSG_NAME(pMsg) );
                    break;
            }
            PS_FREE_MSG ( UEPS_PID_BASTET, pMsg );
        }

    }
}
BST_UINT32 BST_PAL_NetApiPacketRcved( const BST_UINT8 *pData, const BST_UINT32 ulLen )
{
    BST_OS_LOCKCNT_T            tThreadLockCnt;
    BST_PAL_NET_ENTITY_STRU    *pstBstNetEntity;

    pstBstNetEntity             = BST_PAL_NetGetEntity();
    /*入参判断*/
    if ( ulLen != BST_OS_SIZEOF(TTF_MEM_ST) )
    {
        BST_RLS_LOG( "BST_EnQueueOtaData: Wrong Size" );
        return 0;
    }
    if ( BST_NULL_PTR == pData )
    {
        BST_RLS_LOG( "BST_EnQueueOtaData: NULL pData" );
        return 0;
    }

    /*入队*/
    tThreadLockCnt          = BST_OS_ThreadLock();
    if ( PS_SUCC != LUP_EnQue( pstBstNetEntity->pstDlDataQue,
                               (BST_VOID *)pData ) )
    {
        BST_PAL_NetApiPacketFree( (BST_VOID *)pData );
        BST_OS_ThreadUnLock( tThreadLockCnt );
        BST_RLS_LOG( "BST_EnQueueOtaData: EnQueue Fail" );
        return 0;
    }
    BST_OS_ThreadUnLock( tThreadLockCnt );
    /*wakeup cds*/
    BST_SYS_ApiSndEvtToBastet( BST_CDS_EVENT_RCV_DL_PROC );
    return ulLen;
}
BST_IP_ERR_T BST_IP_SslClose( BST_FD_T fd, BST_ARG_T Arg )
{
    SSL                                *pstSsl;
    SSL_CTX                            *pstCtx;
    BST_FD_T                            lSocketFd;

    if ( BST_NULL_PTR == fd.pFd )
    {
        BST_RLS_LOG("BST_IP_SslClose fd.pFd is NULL");
        return BST_IP_ERR_ARG;
    }
    if ( BST_NULL_PTR == Arg )
    {
        BST_RLS_LOG("BST_IP_SslClose Arg is NULL");
        return BST_IP_ERR_ARG;
    }
    pstSsl                              = (SSL *)fd.pFd;
    pstCtx                              = (SSL_CTX *)Arg;
    /*获取协议栈中socket的fd*/
    lSocketFd.lFd                       = SSL_get_fd( pstSsl );
    SSL_shutdown( pstSsl );
    if ( BST_IP_ERR_OK !=BST_IP_BsdClose( lSocketFd, BST_NULL_PTR ) )
    {
        BST_RLS_LOG( "BST_IP_SslClose BST_IP_BsdClose is not OK" );
        return BST_IP_ERR_MEM;
    }
    SSL_set_session( pstSsl, BST_NULL_PTR );
    SSL_free(pstSsl);
    SSL_CTX_free(pstCtx);

    return BST_IP_ERR_OK;
}
BST_VOID    BST_CTaskSchdler::TrigScheduleTask( BST_CORE_CPTask *pC_PTask)
{
    BST_SRV_CTaskMng           *pcTaskManager;
    BST_TASK_STATE_ENUM_UINT8   enTaskState;
    BST_UINT32                  ulRemainTickNum;

    pcTaskManager               = BST_SRV_CTaskMng::GetInstance ();
    BST_ASSERT_NULL( pcTaskManager );

    /*
     * 入口检查
     */
    if ( BST_NULL_PTR == pC_PTask )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::TrigScheduleTask pC_PTask=NULL" );
        return;
    }
    /*
     * 如果上次执行的事件尚未完成,本次不运行
     */
    if ( BST_TRUE == pC_PTask->IsBusy () )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::TrigScheduleTask pC_PTask Is Busy" );
        return;
    }
    /*
     * 如果系统TICK可以被任务周期整除,说明到了整数倍对齐时间
     */

    enTaskState                 = pC_PTask->GetState ();

    BST_DBG_LOG2( "BST_CTaskSchdler::TrigScheduleTask enTaskState:%d,m_ulTaskBlockState:%d",
                       enTaskState,pC_PTask->m_ulTaskBlockState );

    switch ( enTaskState )
    {
        case BST_TASK_STATE_START:
            if( BST_TASK_BLOCK_STATE_EXPIRED ==  pC_PTask->m_ulTaskBlockState )
            {
                Execute( pC_PTask );
                ulRemainTickNum = pC_PTask->m_ulCycle - (m_ulSystemTick % pC_PTask->m_ulCycle);
                if( ulRemainTickNum > BST_TASK_SYS_TICKS )
                {
                    pC_PTask->m_ulTaskBlockState    = BST_TASK_BLOCK_STATE_NORMAL;
                }
                else
                {
                    pC_PTask->m_ulTaskBlockState    = BST_TASK_BLOCK_STATE_IGNORE;
                }
                m_bTaskMissExec                     = BST_FALSE;
            }
            return;
        default:
            break;
    }
}
/*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_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_UINT32 BST_OS_StaticMemCtrlBlkFree( BST_MEM_CTRL_BLOCK *BST_MemCtrlBlock,
                               BST_MEM_HEAD_BLOCK *Block )
{
    BST_UINT32           ulLockLevel;

    if (( BST_NULL_PTR == BST_MemCtrlBlock )
        ||( BST_NULL_PTR == Block ))
    {
        return BST_MEM_ERROR;
    }

    ulLockLevel = BST_OS_SpinLock(&g_stBstMemSpinLock);

    if ( BST_NOT_USED == Block->ulMemUsedFlag )
    {
        BST_OS_SpinUnLock(&g_stBstMemSpinLock, ulLockLevel);

        BST_RLS_LOG("# Free Msg again.");

        return BST_MEM_ERROR;
    }

    Block->ulMemUsedFlag = BST_NOT_USED;
    Block->pstNext = BST_MemCtrlBlock->pstBlocks;
    BST_MemCtrlBlock->pstBlocks = Block;

    BST_MemCtrlBlock->lIdleBlockNumber++;

    BST_OS_MemStatusReport( BST_MemCtrlBlock->enType );

    BST_OS_SpinUnLock(&g_stBstMemSpinLock, ulLockLevel);

    return BST_MEM_OK;
}
BST_VOID BST_SYS_InitBastetNvFlag(BST_VOID)
{
    BASTET_SUPPORT_FLG_STRU                     stBastetFlag;

    PS_MEM_SET(&stBastetFlag, 0x00, sizeof(BASTET_SUPPORT_FLG_STRU));

    /* 读NV项en_NV_MODEM_RF_SHARE_CFG,失败,直接返回 */
    if (NV_OK != NV_Read(en_NV_Item_Bastet_CONFIG,
                         &stBastetFlag, sizeof(BASTET_SUPPORT_FLG_STRU)))
    {
        BST_RLS_LOG("BST_SYS_InitBastetNvFlag():WARNING: read en_NV_Item_Bastet_CONFIG Error");

        return;
    }

    if (BST_TRUE != stBastetFlag.ucActiveFlg)
    {
        /* NV内容异常保护 */
        g_BstBastetFlg  = BST_FALSE;
    }
    else
    {
        g_BstBastetFlg  = BST_TRUE;
    }


    return;
}
BST_IP_ERR_T BST_IP_SslConnect( BST_FD_T fd, BST_ARG_T Arg, BST_IP_SOCKET_ADD_T *pAdd )
{
    SSL                    *pstSsl;
    BST_INT32               ret;
    BST_FD_T                lSocketFd;

    pstSsl                  = (SSL *)fd.pFd;
    lSocketFd.lFd           = SSL_get_fd(pstSsl);

    if (BST_IP_ERR_OK != BST_IP_BsdConnect(lSocketFd, Arg, pAdd) )
    {
        BST_RLS_LOG( "BST_IP_SslConnect BST_IP_BsdConnect error" );
        return BST_IP_ERR_MEM;
    }

    ret                     = SSL_connect( pstSsl );

    /* 返回值等于1表示connect成功 */
    if ( 1 == ret )
    {
        return BST_IP_ERR_OK;
    }
    ret                     = SSL_get_error( pstSsl, ret );

    BST_RLS_LOG1( "BST_IP_SslConnect Err No. is %d", ret );
    return  BST_IP_ERR_VAL;
}
BST_VOID BST_CTaskSchdler::Suspend ( BST_VOID )
{
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNode;

    if ( 0 == lstCount( &g_stPTaskList ) )
    {
        BST_RLS_LOG( "BST_CTaskSchdler::Suspend g_stPTaskList count=0" );
        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 ( BST_NULL_PTR == pstPtaskNode->pcTask )
        {
            continue;
        }
        if ( BST_TASK_STATE_START == pstPtaskNode->pcTask->GetState () )
        {
            pstPtaskNode->pcTask->Suspend();
        }
    }
}
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_IP_ERR_T BST_IP_BsdClose( BST_FD_T fd, BST_ARG_T Arg )
{
    if( !BST_IP_IsBsdFdValid(fd) )
    {
        BST_RLS_LOG("BST_IP_BsdClose fd is invalid");
        return BST_IP_ERR_MEM;
    }
    return (BST_IP_ERR_T)lwip_close( fd.lFd );
}
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_VOID BST_CTaskSchdler::Execute( BST_CORE_CPTask *pC_PTask )
{
    BST_RUN_MODE_ENUM_UINT8     enTaskRunMode;
#if( 0 != BST_BLOCKED_THREAD_NUM )
    BST_STATIC BST_UINT32       ulUnblkedCnt = 0;
#endif

    enTaskRunMode               = pC_PTask->GetRunMode ();
    pC_PTask->m_ulSuspCounter   = 0;
    /*
     * 根据任务运行模式,调度执行相关任务
     */
    switch ( enTaskRunMode )
    {
        /*
         * 如果阻塞性任务,且没有单独线程,则直接执行,如果有任务则发邮件
         * 不同进程由ulUnblkedCnt统一分配,平均各线程任务负荷
         */
        case BST_TASK_RUN_BLOCKED:
#if( 0 != BST_BLOCKED_THREAD_NUM )
            if ( ulUnblkedCnt >= BST_BLOCKED_THREAD_NUM )
            {
                ulUnblkedCnt    = 0;
            }
            if ( BST_NULL_PTR == m_pastBlockTaskMbx[ulUnblkedCnt] )
            {
                BST_RLS_LOG1 ( "BST_CTaskSchdler::Execute Blocked Thread %d is not ready",
                               ulUnblkedCnt );
                return;
            }
            BST_OS_SendMail ( m_pastBlockTaskMbx[ulUnblkedCnt], pC_PTask );
            ulUnblkedCnt++;
#else
            pC_PTask->PEntry();
#endif
            break;
        /*
         * 如果非阻塞性任务,且没有单独线程,则直接执行,如果有任务则发邮件
         */
        case BST_TASK_RUN_UNBLOCKED:
#ifdef BST_UNBLOCKED_OWN_THREAD
            if ( BST_NULL_PTR == m_pstUnBlockTaskMbx )
            {
                BST_RLS_LOG ( "BST_CTaskSchdler::Execute UnBlocked Thread is not ready" );
                return;
            }
            BST_OS_SendMail ( m_pstUnBlockTaskMbx, pC_PTask );
#else
            pC_PTask->PEntry();
#endif
            break;

        default:
            break;
    }
}
BST_UINT32 BST_CTaskSchdler::NearRrcTrig ( BST_UINT32 const ulSysTimerRemainMs )
{
    BST_CORE_PTASK_NODE_STRU   *pstPtaskNode;
    BST_UINT32                  ulNextSysTick;
    BST_UINT32                  ulNextLongCycle;

    ulNextLongCycle             = 0;
    ulNextSysTick               = m_ulSystemTick + BST_TASK_SYS_TICKS;
    /*
     * 遍历任务列表,找出所有有效任务
     */
    for( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList );
         pstPtaskNode!= BST_NULL_PTR;
         pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) )
    {
        if( BST_NULL_PTR == pstPtaskNode->pcTask )
        {
            continue;
        }
        if( 0 == pstPtaskNode->pcTask->m_ulCycle )
        {
            continue;
        }
        if( BST_TRUE == pstPtaskNode->pcTask->IsBusy () )
        {
            continue;
        }
        if( BST_TASK_STATE_START != pstPtaskNode->pcTask->GetState () )
        {
            continue;
        }
        /*
         * 查看是否有任务周期与Tick整除项,代码周期到来
         */
        if( 0 == ( ulNextSysTick % pstPtaskNode->pcTask->m_ulCycle ) )
        {
            if( pstPtaskNode->pcTask->m_ulCycle > ulNextLongCycle )
            {
                ulNextLongCycle = pstPtaskNode->pcTask->m_ulCycle;
            }
        }
    }
    /*
     * 获取当前系统周期,并取比例,如果剩余时间低于该值,则说明足够靠近
     */
    ulNextLongCycle             = BST_CORE_GetCycleToMs( ulNextLongCycle );
    if( BST_TASK_IsNearEnough( ulSysTimerRemainMs, ulNextLongCycle ) )
    {
        BST_RLS_LOG("BST_CTaskSchdler::NearRrcTrig Closing To RRC Enough, Periodic Runing after 200Ms");
        return BST_TASK_RRC_SEND_TIMER;
    }
    else
    {
        return ulSysTimerRemainMs;
    }
}
BST_VOID BST_OS_PalTimerStop( BST_VOID )
{
    if ( VOS_NULL_PTR == g_BstTimer )
    {
        return;
    }
    if ( VOS_OK != PS_STOP_REL_TIMER( &g_BstTimer ) )
    {
        BST_RLS_LOG( "BST_OS_PalTimerStart : Start(Stop) Tmr Fail." );
    }
}
BST_VOID BST_OS_PalTimerStart( BST_UINT32 ulLength )
{
    BST_RLS_LOG1( "BST_OS_PalTimerStart : Length.", ulLength );
    if ( VOS_NULL_PTR != g_BstTimer )
    {
        if ( VOS_OK != PS_STOP_REL_TIMER( &g_BstTimer ) )
        {
            BST_RLS_LOG( "BST_OS_PalTimerStart : Start(Stop) Tmr Fail." );
            return;
        }
    }
    if ( VOS_OK != PS_START_REL_TIMER(  &g_BstTimer,
                                        UEPS_PID_BASTET,
                                        ulLength,
                                        0,
                                        0,
                                        VOS_RELTIMER_NOLOOP) )
    {
        BST_RLS_LOG( "BST_OS_PalTimerStart : Start Tmr Fail." );
        return ;
    }
}
BST_VOID BST_PAL_NetMsgCfgCallBack( const BST_CDS_SEND_CB_INFO_STRU *pstMsg  )
{
    BST_PAL_NET_ENTITY_STRU    *pstBstNetEntity;

    if ( BST_NULL_PTR == pstMsg )
    {
        BST_RLS_LOG( "BST_PAL_NetMsgCfgCallBack : pstMsg Is Null ." );
        return;
    }
    pstBstNetEntity             = BST_PAL_NetGetEntity();
    pstBstNetEntity->pfSndItf   = pstMsg->pSendCbFun;
    pstBstNetEntity->pfRsmItf   = pstMsg->pResmCbFun;
}
BST_ERR_ENUM_UINT8 BST_PAL_NetApiPacketResume( BST_VOID *pstItem )
{
    BST_PAL_NET_ENTITY_STRU            *pstBstNetEntity;

    pstBstNetEntity                     = BST_PAL_NetGetEntity();
    if ( BST_NULL_PTR == pstItem )
    {
        BST_RLS_LOG( "BST_PAL_NetApiPacketResume : Mst Pointer Is Null ." );
        return BST_ERR_INVALID_PTR;
    }
    if ( BST_NULL_PTR == pstBstNetEntity->pfRsmItf )
    {
        BST_RLS_LOG( "BST_PAL_NetApiPacketResume : pfRsmItf Pointer Is Null ." );
        return BST_ERR_INVALID_PTR;
    }
    if( 0 == pstBstNetEntity->pfRsmItf( (BST_UINT8 *)pstItem,
        (BST_UINT16)BST_OS_SIZEOF (TTF_MEM_ST ) ) )
    {
        BST_PAL_NetApiPacketFree( pstItem );
        return BST_ERR_ILLEGAL_PARAM;
    }
    return BST_NO_ERROR_MSG;
}
BST_BOOL BST_APP_CEmailIMAP::IsConfigOk( BST_VOID )
{
    if ( BST_FALSE == IsBasicConfigOk() )
    {
        return BST_FALSE;
    }
    if ( BST_NULL_PTR == m_pstLastUID )
    {
        BST_RLS_LOG("Email Box IMAP config is not OK: m_pstLastUID void");
        return BST_FALSE;
    }
    if ( !BST_LIB_IsStringInit( m_pstLastUID->pMailBoxFolder ))
    {
        BST_RLS_LOG("Email Box IMAP config is not OK: pMailBoxFolder->IsInited");
        return BST_FALSE;
    }
    if ( !BST_LIB_IsStringInit( m_pstLastUID->pLastUid ))
    {
        BST_RLS_LOG("Email Box IMAP config is not OK: pLastUid->IsInited");
        return BST_FALSE;
    }
    return BST_TRUE;
}
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_IP_ERR_T BST_IP_SslBind( BST_FD_T fd, BST_UINT16 usPort )
{
    SSL                                *pstSsl;
    BST_FD_T                           lSocketFd;

    if ( BST_NULL_PTR == fd.pFd )
    {
        BST_RLS_LOG("BST_IP_SslBind fd.pFd is NULL.");
        return BST_IP_ERR_ARG;
    }

    pstSsl                              = (SSL *)fd.pFd;
    lSocketFd.lFd                       = SSL_get_fd( pstSsl );

    return BST_IP_BsdBind( lSocketFd, usPort );
}
BST_VOID BST_SYS_MntnTimerExpired(
    BST_OS_TIMERID_T                ulTimerId,
    BST_VOID                       *pvArg )
{
    if ( BST_SYS_MNTN_IsMntnMsgChanged() )
    {
        BST_SYS_MNTN_ClrMntnMsgChgFlag();
        BST_OS_TimerStart( BST_SYS_MNTN_GetTimerId(),
                           BST_SYS_MNTN_REPORT_TIMER_LEN );
    }
    else
    {
        BST_RLS_LOG( "[Mntn] Send Maintain Message Triged" );
        BST_SYS_MntnTrigReport();
    }
}
BST_VOID BST_SYS_MntnInit( BST_VOID )
{
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    tThreadLockCnt                      = BST_OS_ThreadLock();
    g_stBstMntnEntity.stReportTimer     = BST_OS_TimerCreate
                                        ( BST_SYS_MntnTimerExpired,
                                          BST_NULL_PTR );
    lstInit( &g_stBstMntnEntity.stAppList );
    BST_OS_MEMSET( &g_stBstMntnEntity.aucLocalIp[0],
                   0, OM_BST_IP_ADDR_LEN );
    g_stBstMntnEntity.ucChanged         = BST_FALSE;
    g_stBstMntnEntity.ucIsInit          = BST_TRUE;
    BST_RLS_LOG( "[Mntn] Initial System" );
    BST_OS_ThreadUnLock( tThreadLockCnt );
    return;
}
BST_VOID BST_SYS_MntnCofigLoacalIpAddress(
    BST_UINT8      *aucLocalIp,
    BST_UINT16      usBufLen )
{
    if ( BST_NULL_PTR == aucLocalIp )
    {
        BST_RLS_LOG( "[Mntn] BST_SYS_MntnCofigLoacalIpAddress Error Pointer" );
        return;
    }
    if ( OM_BST_IP_ADDR_LEN > usBufLen )
    {
        BST_RLS_LOG1( "[Mntn] BST_SYS_MntnCofigLoacalIpAddress Error Size:", usBufLen );
        return;
    }
    BST_OS_MEMCPY( &g_stBstMntnEntity.aucLocalIp[0],
                   aucLocalIp, OM_BST_IP_ADDR_LEN );
    return;
}