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_VOID BST_SYS_MntnUpdateErrorNum(
    BST_UINT16  usType,
    BST_UINT16  usTaskId )
{
    OM_BST_APP_INFO_STRU               *pstAppInfo;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }
    tThreadLockCnt                      = BST_OS_ThreadLock();
    pstAppInfo                          = BST_SYS_MntnSrchAppByTask( usType, usTaskId );
    if ( BST_NULL_PTR == pstAppInfo )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }

    pstAppInfo->usErrorNum++;
    BST_RLS_LOG3("[Mntn] Task Run Fail: TypeId=, TaskId=",
                 usType, usTaskId, pstAppInfo->usErrorNum );
    BST_SYS_MntnChangedInd();
    BST_OS_ThreadUnLock( tThreadLockCnt );
}
BST_VOID BST_SYS_MntnUpdateRxFlow(
    BST_UINT16  usLocalPort,
    BST_UINT32  ulRxFlow )
{
    OM_BST_APP_INFO_STRU               *pstAppInfo;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }
    tThreadLockCnt                      = BST_OS_ThreadLock();
    pstAppInfo                          = BST_SYS_MntnSrchAppByPort( usLocalPort );
    if ( BST_NULL_PTR == pstAppInfo )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }

    pstAppInfo->ulRxFlow               += ulRxFlow;
    pstAppInfo->ulRxFlow               &= BST_SYS_MNTN_MAX_TRAFFIC_FLOW;
    BST_RLS_LOG4( "[Mntn] Local Port Rx Flow New:  TypeId=, TaskId=, PortNumber=, TrafficeFlow=",
                  pstAppInfo->usAppType, pstAppInfo->usTaskId, usLocalPort, ulRxFlow );
    BST_OS_ThreadUnLock( tThreadLockCnt );
}
BST_VOID BST_SYS_MntnUpdateCycleLen(
    BST_UINT16  usType,
    BST_UINT16  usTaskId,
    BST_UINT16  usCycleLen )
{
    OM_BST_APP_INFO_STRU               *pstAppInfo;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }
    tThreadLockCnt                      = BST_OS_ThreadLock();
    pstAppInfo                          = BST_SYS_MntnSrchAppByTask( usType, usTaskId );
    if ( BST_NULL_PTR == pstAppInfo )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }

    pstAppInfo->usCycleLen              = usCycleLen;
    BST_RLS_LOG3("[Mntn] Periodic Configed: TypeId=, TaskId=, Cycle=",
                 usType, usTaskId, usCycleLen );
    BST_SYS_MntnChangedInd();
    BST_OS_ThreadUnLock( tThreadLockCnt );
}
BST_VOID BST_SYS_MntnUpdateState(
    BST_UINT16  usType,
    BST_UINT16  usTaskId,
    BST_UINT16  usState )
{
    OM_BST_APP_INFO_STRU               *pstAppInfo;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }
    tThreadLockCnt                      = BST_OS_ThreadLock();
    pstAppInfo                          = BST_SYS_MntnSrchAppByTask( usType, usTaskId );
    if ( BST_NULL_PTR == pstAppInfo )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }
    pstAppInfo->usTaskState = usState;
    BST_RLS_LOG3( "[Mntn] State Updated: TypeId=, TaskId=, NewState=",
                  usType, usTaskId, usState );
    BST_SYS_MntnChangedInd();
    BST_OS_ThreadUnLock( tThreadLockCnt );
}
BST_OS_SEM_STRU *BST_OS_CreateSem( BST_VOID *pvArg, BST_UINT32 ulInitCnt )
{
    BST_OS_SEM_STRU                    *pstOsSem;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    pstOsSem                            = (BST_OS_SEM_STRU *)BST_OS_MALLOC( BST_OS_SIZEOF( BST_OS_SEM_STRU ) );

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

    tThreadLockCnt                      = BST_OS_ThreadLock();

    pstOsSem->pvArg                     = BST_OS_GetCurrentThreadId();
    pstOsSem->stHandle                  = BST_OS_PalCreateSem( ulInitCnt );
    if ( BST_OS_SYS_IsSemValid(pstOsSem->stHandle) )
    {
        BST_OS_FREE( pstOsSem );
        BST_OS_ThreadUnLock( tThreadLockCnt );
        /*lint -e438*/
        return BST_NULL_PTR;
        /*lint +e438*/
    }

#ifdef BST_OS_SIGNAL_COUNTER
    pstOsSem->ulCounter                 = ulInitCnt;
    if ( 0U != pstOsSem->ulCounter )
    {
        BST_OS_PalSendSem( pstOsSem->stHandle, pstOsSem->pvArg );
    }
#endif
    BST_OS_ThreadUnLock( tThreadLockCnt );
    return pstOsSem;
}
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_VOID BST_SYS_MntnUpdateIpInfo(
    BST_UINT16  usType,
    BST_UINT16  usTaskId,
    BST_VOID   *pstIpInfo )
{
    OM_BST_APP_INFO_STRU               *pstAppInfo;
    BST_IP_SOCKET_ADD_T                *pstSocketInfo;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }
    if ( BST_NULL_PTR == pstIpInfo )
    {
        return;
    }
    pstSocketInfo                       = ( BST_IP_SOCKET_ADD_T *)pstIpInfo;
    tThreadLockCnt                      = BST_OS_ThreadLock();
    pstAppInfo                          = BST_SYS_MntnSrchAppByTask( usType, usTaskId );
    if ( BST_NULL_PTR == pstAppInfo )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }

    pstAppInfo->usLocalPort             = pstSocketInfo->usLocalPort;
    pstAppInfo->usRemotePort            = pstSocketInfo->usRemotePort;

    BST_OS_MEMCPY( &pstAppInfo->aucLocalIp[0],
                   BST_SYS_MNTN_GetLocalIpHead(), OM_BST_IP_ADDR_LEN );

    BST_OS_MEMCPY( &pstAppInfo->aucRemoteIp[0],
                   &pstSocketInfo->aucRemoteIp[0], OM_BST_IP_ADDR_LEN );

    BST_RLS_LOG4( "[Mntn] Socket Configed_01: TypeId=, TaskId=, LocalPort=, RemotePort=",
            usType, usTaskId, (pstSocketInfo)->usLocalPort, (pstSocketInfo)->usRemotePort );

    BST_RLS_LOG4( "[Mntn] Socket Configed_02: Remote Ip Address",
            (pstAppInfo)->aucRemoteIp[3], (pstAppInfo)->aucRemoteIp[2],
            (pstAppInfo)->aucRemoteIp[1], (pstAppInfo)->aucRemoteIp[0]);

    BST_RLS_LOG4( "[Mntn] Socket Configed_02: Local Ip Address",
            (pstAppInfo)->aucLocalIp[3], (pstAppInfo)->aucLocalIp[2],
            (pstAppInfo)->aucLocalIp[1], (pstAppInfo)->aucLocalIp[0]);

    BST_SYS_MntnChangedInd();
    BST_OS_ThreadUnLock( tThreadLockCnt );
}
BST_ERR_ENUM_UINT8 BST_OS_DeleteMbx( BST_OS_MBX_T *pstMbx )
{
    BST_OS_MAIL_T                     *pstContent;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    BST_ASSERT_NULL_RTN( pstMbx,        BST_ERR_INVALID_PTR );
    BST_ASSERT_NULL_RTN( pstMbx->hSem,  BST_ERR_INVALID_PTR );

    BST_OS_DeleteSem( pstMbx->hSem );

    tThreadLockCnt                      = BST_OS_ThreadLock();    
    for (;;)
    {
        if( 0 == lstCount( &pstMbx->hList ) )
        {
            break;
        }
        pstContent                      = (BST_OS_MAIL_T *)lstGet( &pstMbx->hList );
        BST_OS_FREE( pstContent );
    }

    lstFree( &pstMbx->hList);
    
    BST_OS_FREE( pstMbx );

    BST_OS_ThreadUnLock( tThreadLockCnt );
/*lint -e438*/
    return( BST_NO_ERROR_MSG );
/*lint +e438*/
}
BST_VOID BST_IP_TcpErrCB( BST_VOID *arg, BST_IP_ERR_T err )
{
    BST_IP_CRcverMng                   *pcRcverMnger;
    BST_FD_T                            FdTmp;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    tThreadLockCnt                      = BST_OS_ThreadLock();
    pcRcverMnger                        = BST_IP_CRcverMng::GetInstance();
    if ( ( BST_NULL_PTR == pcRcverMnger ) || ( BST_IP_IsLwipNull(arg) ) )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }
    FdTmp.pFd                           = arg;
    pcRcverMnger->ErrMsgRcver( FdTmp, err );

    BST_OS_ThreadUnLock( tThreadLockCnt );
}
BST_VOID BST_SYS_MntnAddTask(
    BST_UINT16  usType,
    BST_UINT16  usTaskId )
{
    BST_SYS_MNTN_APP_NODE_STRU             *pstAppInfoNode;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }

    if ( (BST_UINT32)BST_SYS_MNTN_GetAppNumber() >= BST_SYS_MNTN_MAX_APP_NUMBER )
    {
        return;
    }

    tThreadLockCnt                      = BST_OS_ThreadLock();
    if ( BST_NULL_PTR != BST_SYS_MntnSrchAppByTask( usType, usTaskId ) )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }
    pstAppInfoNode                      = ( BST_SYS_MNTN_APP_NODE_STRU *)BST_OS_MALLOC
                                          ( BST_OS_SIZEOF(BST_SYS_MNTN_APP_NODE_STRU) );
    if ( BST_NULL_PTR == pstAppInfoNode )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }
    BST_OS_MEMSET( &(pstAppInfoNode->stAppInfo),
                   0,
                   BST_OS_SIZEOF(OM_BST_APP_INFO_STRU) );

    pstAppInfoNode->stAppInfo.usAppType = usType;
    pstAppInfoNode->stAppInfo.usTaskId  = usTaskId;

    lstAdd( BST_SYS_MNTN_GetAppListHead(), (NODE *)pstAppInfoNode );
    BST_RLS_LOG3( "[Mntn] Add Task: TypeId=, TaskId=, Total=",
                  usType, usTaskId, BST_SYS_MNTN_GetAppNumber() );
    BST_SYS_MntnChangedInd();
    BST_OS_ThreadUnLock( tThreadLockCnt );
/*lint -e429*/
}
BST_CTask::BST_CTask ( BST_PROCID_T in_usProcId, BST_TASKID_T in_usTaskId )
          :m_usProcId ( in_usProcId ), m_usTaskId ( in_usTaskId )
{
    BST_OS_LOCKCNT_T                    tThreadLockCnt;
    tThreadLockCnt                      = BST_OS_ThreadLock ();
    m_enState                           = BST_TASK_STATE_STOPED;
    m_enRunMode                         = BST_TASK_RUN_UNBLOCKED;
    BST_OS_ThreadUnLock ( tThreadLockCnt );
    BST_DBG_ADD_TASK( m_usProcId, m_usTaskId );
}
BST_VOID BST_SYS_MntnRemoveTask(
    BST_UINT16  usType,
    BST_UINT16  usTaskId )
{
    BST_SYS_MNTN_APP_NODE_STRU             *pstAppNode;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( !BST_SYS_MNTN_IsMntnInited() )
    {
        return;
    }
    tThreadLockCnt                      = BST_OS_ThreadLock();
    /* 查找链表中是否已经存在该Task信息 */
    for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead());
          pstAppNode != BST_NULL_PTR;
          pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) )
    {
        if ( ( usTaskId == pstAppNode->stAppInfo.usTaskId )
          && ( usType == pstAppNode->stAppInfo.usAppType ) )
        {
            break;
        }
    }

    if ( BST_NULL_PTR == pstAppNode )
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return;
    }

    lstDelete( BST_SYS_MNTN_GetAppListHead(), (NODE *)pstAppNode );
    BST_OS_FREE( pstAppNode );
    BST_RLS_LOG3( "[Mntn] Remove Task: TypeId=, TaskId=, Total=",
                  usType, usTaskId, BST_SYS_MNTN_GetAppNumber() );
    BST_SYS_MntnChangedInd();
    BST_OS_ThreadUnLock( tThreadLockCnt );
/*lint -e438*/
}
BST_UINT32 BST_OS_PeekMail( BST_OS_MBX_T *pstMbx, BST_VOID **pMsg )
{
    BST_OS_MAIL_T                      *pstContent;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    BST_ASSERT_NULL_RTN( pstMbx,        BST_ERR_INVALID_PTR );
    BST_ASSERT_NULL_RTN( pstMbx->hSem,  BST_ERR_INVALID_PTR );
    BST_ASSERT_NULL_RTN( pMsg,          BST_ERR_INVALID_PTR );

    *pMsg                               = BST_NULL_PTR;

    if( BST_OS_SYS_TIMEOUT == BST_OS_RecvSem( pstMbx->hSem, BST_OS_SYS_NOWAIT ) )
    {
        return BST_OS_SYS_TIMEOUT;
    }

    tThreadLockCnt                      = BST_OS_ThreadLock();

    pstContent                          = (BST_OS_MAIL_T *)lstGet( &pstMbx->hList );

    if ( BST_NULL_PTR == pstContent )        
    {
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return BST_OS_SYS_TIMEOUT;
    }
    *pMsg                               = pstContent->ulContent;
#ifdef BST_OS_SIGNAL_COUNTER
    if ( pstMbx->hSem->ulCounter > 0U )
    {
        pstMbx->hSem->ulCounter--;
    }
#endif
    BST_OS_FREE( pstContent );
    BST_OS_ThreadUnLock( tThreadLockCnt );
    /*lint -e438*/
    return( BST_NO_ERROR_MSG );
    /*lint +e438*/
}
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_PAL_NetDLEvtProc( BST_VOID )
{
    BST_UINT32                  ulCnt;
    BST_OS_LOCKCNT_T            tThreadLockCnt;
    TTF_MEM_ST                 *pstIpPkt;
    BST_PAL_NET_ENTITY_STRU    *pstBstNetEntity;

    tThreadLockCnt              = BST_OS_ThreadLock();
    pstBstNetEntity             = BST_PAL_NetGetEntity();

    for ( ulCnt = 0; ulCnt < BST_PAL_DL_QUE_SIZE; ulCnt ++ )
    {
        if ( LUP_DeQue( pstBstNetEntity->pstDlDataQue,
                        ( BST_VOID **)&pstIpPkt) )
        {
            BST_OS_ThreadUnLock( tThreadLockCnt );
            return;
        }
        BST_PAL_NetProcDlPacket( pstIpPkt );
    }
    BST_OS_ThreadUnLock( tThreadLockCnt );
    return;
}
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_CTaskSchdler::AppThread ( BST_VOID* arg )
{
    BST_CORE_CPTask    *pcTask;
    BST_OS_MBX_T      **pstMailBox;
    BST_OS_LOCKCNT_T    tThreadLockCnt;
    BST_UINT32          ulRtnVal;

    if ( BST_NULL_PTR == arg )
    {
        return;
    }
    /*
     * 线程参数初始化,包括邮箱,运行标识
     */
    tThreadLockCnt      = BST_OS_ThreadLock ();
    pstMailBox          = (BST_OS_MBX_T **)arg;
   *pstMailBox          = BST_OS_CreateMbx
                        ( BST_OS_GetCurrentThreadId (), BST_MAX_APP_NUMBER );
    BST_SetThreadInitFlag ( BST_APP_THREAD_FLAG << g_ucAppInitCnt );
    g_ucAppInitCnt++;
    BST_OS_ThreadUnLock ( tThreadLockCnt );

    /*
     * 进入线程主循环,等待邮件,邮件内容为即将执行的任务
     */
    for(;;)
    {
        ulRtnVal        = BST_OS_RecvMail
                       ( *pstMailBox, (BST_VOID **)&pcTask, BST_OS_SYS_FOREVER );
        BST_ASSERT_NORM( BST_OS_SYS_TIMEOUT == ulRtnVal );
        if ( BST_NULL_PTR == pcTask )
        {
            continue;
        }
        if ( BST_FALSE == ChkTaskExist (pcTask) )
        {
            continue;
        }
        if ( BST_TRUE == pcTask->IsBusy () )
        {
            continue;
        }
        pcTask->PEntry ();
    }
}
BST_UINT32 BST_SYS_MntnBuildAgentInfoInd(
    OM_BST_APP_INFO_STRU   *pstAgentInfo,
    const BST_UINT16        usAppNumber )
{
    BST_SYS_MNTN_APP_NODE_STRU             *pstAppNode;
    BST_UINT16                          usAppCounter;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    if ( BST_NULL_PTR == pstAgentInfo )
    {
        return BST_FALSE;
    }

    tThreadLockCnt                      = BST_OS_ThreadLock();
    usAppCounter                        = 0;
    /* 查找链表中是否已经存在该Task信息 */
    for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead());
          pstAppNode != BST_NULL_PTR;
          pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) )
    {
        if ( ID_BST_OM_TASK_TYPE_MAIN == pstAppNode->stAppInfo.usAppType )
        {
            continue;
        }

        BST_OS_MEMCPY( &pstAgentInfo[usAppCounter],
                       &(pstAppNode->stAppInfo),
                       BST_OS_SIZEOF(OM_BST_APP_INFO_STRU) );
        usAppCounter++;
        if ( usAppCounter >= usAppNumber )
        {
            break;
        }
    }
    BST_OS_ThreadUnLock( tThreadLockCnt );
    return BST_TRUE;
}
/*lint -e438*/
err_t BST_IP_TcpRecvCB( BST_VOID *arg, struct tcp_pcb * tpcb, struct pbuf *p, BST_IP_ERR_T err )
{
    err_t                               ucErrMsg;
    BST_UINT16                          usCopyedLength;
    BST_IP_CRcverMng                   *pcRcverMnger;
    BST_IP_PKTPROC_MODE_ENUM            enProcMode;
    struct pbuf                        *q;
    BST_UINT8                          *pucSdu;
    BST_FD_T                            FdTmp;
    BST_OS_LOCKCNT_T                    tThreadLockCnt;

    BST_ASSERT_NULL_RTN( tpcb, ERR_ARG );

    tThreadLockCnt                      = BST_OS_ThreadLock();
    FdTmp.pFd                           = tpcb;
    pcRcverMnger                        = BST_IP_CRcverMng::GetInstance();
    pucSdu                              = BST_NULL_PTR;
    q                                   = BST_NULL_PTR;
    usCopyedLength                      = 0;
    ucErrMsg                            = ERR_OK;
    enProcMode                          = BST_IP_PKT_REMOVE_PROC;

    if( BST_NULL_PTR == pcRcverMnger )
    {
        ucErrMsg                        = ERR_MEM;
        BST_IP_TCP_RCVAPI_FREE();
    }

   /*                                          *
    * p=NULL means this pcb is closed by Remote*
    *                                          */
    if( BST_IP_IsLwipNull(p) )
    {
        pcRcverMnger->ClosedRcver ( FdTmp );
        BST_OS_ThreadUnLock( tThreadLockCnt );
        return ERR_OK;
    }

    if ( p->tot_len > 0 )
    {
        pucSdu = ( BST_UINT8 * )BST_OS_MALLOC( p->tot_len );
    }
    else
    {
        ucErrMsg                        = ERR_BUF;
        tcp_recved( tpcb, p->tot_len );
        BST_IP_TCP_RCVAPI_FREE();
    }

    if ( BST_NULL_PTR == pucSdu )
    {
        ucErrMsg                        = ERR_BUF;
        tcp_recved( tpcb, p->tot_len );
        BST_IP_TCP_RCVAPI_FREE();
    }

    q                                   = p;
    usCopyedLength                      = 0;

    while ( BST_NULL_PTR != q )
    {
        if ( ( q->len > 0 ) && ( BST_NULL_PTR != q->payload )
             && ( q->len + usCopyedLength <= p->tot_len ) )
        {
            BST_OS_MEMCPY( pucSdu + usCopyedLength, q->payload, q->len );
        }
        else
        {
            break;
        }

        usCopyedLength                 += q->len;
        q                               = q->next;
    }

    if ( usCopyedLength > 0 )
    {
        BST_IP_ApiRecordLastSktProp( (BST_IP_PKT_ID_T)p );
        /*                                                                       *
        *The Received Message must put it here where is before call Application CB.
        *This can avoid app close socket in callback when the rcv_wnd != TCP_WND.
        *                                                                        */
        tcp_recved( tpcb, p->tot_len );
        enProcMode                      = pcRcverMnger->PacketRcver( FdTmp,
                                                                     ( BST_UINT8 * )pucSdu,
                                                                     usCopyedLength );
        if( BST_IP_PKT_FORWARD_PROC == enProcMode )
        {
            BST_IP_ApiForwordPacket( (BST_IP_PKT_ID_T)p );
        }

        ucErrMsg                        = ERR_OK;
    }
    else
    {
        ucErrMsg                        = ERR_BUF;
    }
    BST_OS_FREE( pucSdu );
    BST_IP_TCP_RCVAPI_FREE();
}