⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcm_drv.c

📁 abstract rtos
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifdef __cplusplusextern "C"{#endif #include "syscfg.h"#include "aos.h"#include "trace/trace_pub.h"#include "ifnet/if_pub.h"#include "ip/ip_pub.h"#include "nat/nat_pub.h"#include "mgc_pub.h"#include "mgcp_pub.h"#include "p2p_include.h"#include "rtp_pub.h"#include "../ker/ssp_msg.h"#include "../ker/ssp_debug.h"#include "lcm_q921.h"#include "lcm_if.h"#include "sip_pub.h"#include "ht_include.h"#include "st_pub.h"extern VOID aping_hook4lcm( VOID *aping, VOID *addr , U32 tcpflag );extern U32 tunnel_get_true_iad_ip(U16 usTunnelId, U32 * ulIp);extern BOOL_T ht_is_tunneludp(U32 ulIp, U16 usPort);extern U16 g_lcm_rel_udp_port;extern BOOL_T g_blIsDbMaster;extern U32    m_ulMsgEnable;#if( CONFIG_BOARD_GMPU == TRUE )extern U32 g_lcm_tcp_signal_disable;#endifextern U16    	g_usIpId;extern IPSTAT_S  g_stIpStat;#if CONFIG_BOARD_EIA == TRUEextern BOOL_T rtp_check_packet_valid(void *ip);#endif#if( CONFIG_BOARD_GMPU == TRUE ) || (CONFIG_BOARD_EIA == TRUE )#if (AOS_INCLUDE_SERVICE_ROUTE_SRV_SERVER == TRUE || AOS_INCLUDE_SERVICE_ROUTE_SRV_CLIENT == TRUE)#define IS_RS_UDPPORT(udp_port) ( (udp_port) == rs_get_local_port() )#endif#if( AOS_INCLUDE_SERVICE_MGCP_STACK == TRUE )#define IS_MGCP_STACK_UDPPORT(udp_port) ( (udp_port) == mgcp_get_local_udp_port() )#else#define IS_MGCP_STACK_UDPPORT(udp_port) (FALSE)#endif#if (AOS_INCLUDE_SERVICE_SIP_UA_CLIENT == TRUE || AOS_INCLUDE_SERVICE_SIP_UA_SERVER == TRUE||AOS_INCLUDE_SERVICE_SIP_UA_PROXY == TRUE)#define IS_SIP_UDPPORT(udp_port) ( sip_get_local_transport()== (udp_port) )#else#define IS_SIP_UDPPORT(udp_port) (0)#endif#define IS_LCM_UDPPORT(udp_port) ( g_lcm_rel_udp_port == (udp_port) )#define IS_APING_UDPPORT(udp_port) ( (g_lcm_rel_udp_port+1) == (udp_port) )#if (AOS_INCLUDE_SERVICE_P2P_NN== TRUE || AOS_INCLUDE_SERVICE_P2P_SN_CN== TRUE)#define IS_P2P_MNGT_PORT(p) (p2p_mngt_local_port() == (p))#else#define IS_P2P_MNGT_PORT(p) (0)#endif#else#define IS_MGCP_STACK_UDPPORT(udp_port) ( 0 )#define IS_LCM_UDPPORT(udp_port) (0)#define IS_SIP_UDPPORT(udp_port) (0)#define IS_APING_UDPPORT(udp_port) ( 0 )#define IS_P2P_MNGT_PORT(p) (0)#endif#if (AOS_INCLUDE_SERVICE_ST == TRUE)#define IS_RC_PORT(p) (rc_get_listen_port() == (p))#else#define IS_RC_PORT(p) (0)#endif#define LCM_IS_UDP_PKT(ip) ((ip)->ip_chPr == 0x11)#define LCM_IS_TCP_PKT(ip) ((ip)->ip_chPr == 0x06)#define LCM_RAPID_PKT_LIST_SIZE   (300)MBUF_QUEUE_S	lcm_rapid_pkt_list = {NULL,NULL,0,LCM_RAPID_PKT_LIST_SIZE};#if( AOS_INCLUDE_SERVICE_MGCP_STACK == TRUE )extern U16 mgcp_get_local_udp_port( );#endif#if (CONFIG_BOARD_EIA == TRUE)extern U32 ht_istunnelmode();#endif#if (CONFIG_BOARD_EIA == TRUE) || (CONFIG_BOARD_GMPU == TRUE)extern int ht_send_msg_rapid(struct msg_blk * mb, U16 usSrcPort, U16 usDstPort);extern U32 ht_istunneludp(U16 usPort);#endifBOOL_T lcm_is_reservport(U16 usPort){#if CONFIG_BOARD_EIA == TRUE     if( TRUE == lcm_is_reservport_without_rsock(usPort) )     {        return TRUE;     }          if( TRUE == rsock_is_reservport(usPort) )     {        return TRUE;     }#else    (void)usPort;#endif    return FALSE;}BOOL_T lcm_is_reservport_without_rsock(U16 usPort){#if CONFIG_BOARD_EIA == TRUE    if(g_lcm_rel_udp_port == usPort    || g_lcm_rel_udp_port+1 == usPort)    {        return TRUE;    }#else    (void)usPort;#endif    return FALSE;}void lcm_set_localport(U16 usPort){#if( CONFIG_BOARD_GMPU == TRUE || CONFIG_BOARD_EIA == TRUE )    g_lcm_rel_udp_port = usPort;#endif}U32 lcm_get_mpe_by_port(U16 usPort){#if (AOS_INCLUDE_SERVICE_ROUTE_SRV_SERVER == TRUE || AOS_INCLUDE_SERVICE_ROUTE_SRV_CLIENT == TRUE)    if( IS_RS_UDPPORT(usPort) )    {		return MPE_RS;    }#endif    if( IS_MGCP_STACK_UDPPORT(usPort) )    {		return MPE_MGCP_STACK;    }    else if( IS_LCM_UDPPORT(usPort) )	{  		return MPE_LCM;	}	else if(IS_SIP_UDPPORT(usPort))	{  		return MPE_SIP;	}    else if( IS_APING_UDPPORT(usPort) )    {  		return MPE_APING;    }    else if(IS_P2P_MNGT_PORT(usPort))    {  		return MPE_P2P_MNGT;    }    else    {        return U32_BUTT;    }}U16 lcm_get_port_by_mpe(U32 ulMpeNo){    U16 usPort = U16_BUTT;    switch( ulMpeNo )    {#if (AOS_INCLUDE_SERVICE_ROUTE_SRV_SERVER == TRUE || AOS_INCLUDE_SERVICE_ROUTE_SRV_CLIENT == TRUE)        case MPE_RS:            usPort = rs_get_local_port();            break;#endif#if( AOS_INCLUDE_SERVICE_MGCP_STACK == TRUE )        case MPE_MGCP_STACK:            usPort = mgcp_get_local_udp_port();            break;#endif#if (AOS_INCLUDE_SERVICE_SIP_UA_CLIENT == TRUE || AOS_INCLUDE_SERVICE_SIP_UA_SERVER == TRUE|| AOS_INCLUDE_SERVICE_SIP_UA_PROXY == TRUE)        case MPE_SIP:            usPort = sip_get_local_transport();            break;#endif#if( CONFIG_BOARD_GMPU == TRUE || CONFIG_BOARD_EIA == TRUE )        case MPE_LCM:            usPort = g_lcm_rel_udp_port;            break;        case MPE_APING:            usPort = g_lcm_rel_udp_port + 1;            break;#endif#if (AOS_INCLUDE_SERVICE_P2P_NN == TRUE || AOS_INCLUDE_SERVICE_P2P_SN_CN== TRUE)        case MPE_P2P_MNGT:            usPort = p2p_mngt_local_port();            break;#endif        default:            break;    }    return usPort;}#if( CONFIG_BOARD_GMPU == TRUE || CONFIG_BOARD_EIA == TRUE )U32 lcm_get_src_nat_ip(U32 ulSrcIp, U16 usSrcPort){#if( CONFIG_BOARD_GMPU == TRUE )    U32 NatIp;#endif    if( ulSrcIp == if_get_out_ipaddr() )    {        if( p2p_is_p2p_logic_port(usSrcPort) )        {            return p2p_get_src_nat_ip( ulSrcIp, usSrcPort );        }#if( CONFIG_BOARD_GMPU == TRUE && AOS_INCLUDE_SERVICE_TUNNEL_SERVER == TRUE)        else if( ht_is_tunneludp( ulSrcIp,usSrcPort ) )        {            if( AOS_SUCC == tunnel_get_true_iad_ip( usSrcPort, &NatIp ) )            {                return NatIp;            }        }#endif    }    return ulSrcIp;}#endifU32 if_get_out_ip_by_dstip(U32 ulDstIp){#if( CONFIG_BOARD_GMPU == TRUE )    ROUTE_S	    route;    IFNET_S	    *ifp;        ifp = g_pstIfnet[SERVICE_ETHNET_PORT];    if( ifp && ifp->if_ulIpAddr)    {        if((ulDstIp&ifp->if_ulIpMask) ==             (ifp->if_ulIpAddr &ifp->if_ulIpMask) )        {            return ifp->if_ulIpAddr;        }    }    ifp = g_pstIfnet[NMS_ETHNET_PORT];    if( ifp && ifp->if_ulIpAddr )    {        if((ulDstIp&ifp->if_ulIpMask) ==             (ifp->if_ulIpAddr &ifp->if_ulIpMask) )        {            return ifp->if_ulIpAddr;        }    }    ((SOCKADDRIN_S *)&(route.ro_stDst))->sin_stAddr.s_ulAddr = ulDstIp;    rt_alloc(&route);    if (NULL == route.ro_pRt)    {		return 0;    }	ifp = if_get_if_by_index(route.ro_pRt->rt_ulIfIndex);	if (NULL != ifp )	{		return ifp->if_ulIpAddr;	}    return 0;#else    return if_get_out_ipaddr();#endif}U32 if_get_out_ip_by_ifindex(U32 if_index){    IFNET_S *pIf;    pIf = if_get_if_by_index(if_index);    if( NULL != pIf )    {        return pIf->if_ulIpAddr;    }    return 0;}U32 if_get_ipaddr_by_port(U32 eth_port){    if( eth_port < IF_MAX_ETH_NUM )    {        if( g_pstIfnet[eth_port] )        {            return g_pstIfnet[eth_port]->if_ulIpAddr;        }    }    return 0;}#if( CONFIG_BOARD_GMPU == TRUE )U32 lcm_get_local_ip_for_device( U32 devIp, U16 devPort ){	if(devIp == AOS_HTONL(0x7F000001)	|| devIp == if_get_out_ipaddr() )	{        if( p2p_is_p2p_logic_port(devPort) )        {            return p2p_trans_get_local_ip_for_device(devPort);        }        else if( ht_istunneludp(devPort) )        {            if( AOS_SUCC == tunnel_get_true_iad_ip( devPort, &devIp ) )            {                return if_get_out_ip_by_dstip(devIp);            }        }        AOS_ASSERT(0);        return if_get_out_ipaddr();	}    return if_get_out_ip_by_dstip( devIp );}#elseU32 lcm_get_local_ip_for_device( U32 devIp, U16 devPort ){    return if_get_out_ipaddr();}#endifVOID lcm_default_drv( U32 port, struct msg_blk *mb ){	#ifdef LCM_DEBUG    aos_printf( MPE_LCM, "default driver for lcm, just discard the frame!" );	#endif    if( NULL == mb || NULL == mb->head )    {        return;    }    aos_dmem_free((VOID*)mb->head);    msg_free( mb );    port=port;}VOID lcm_drv_send( U32 phy, U32 portno, struct msg_blk *mb ){    U32 comport;    U8 slot, hdlc_no=0, subc;    MBUF_S *mbuf = NULL;    struct msg_blk *mb2send = mb;    AOS_ASSERT_FUNC( NULL != mb && NULL != mb->data, if(NULL!=mb) msg_free(mb);return );    AOS_ASSERT_FUNC( LCM_DRV_BUTT >= phy, goto lcm_drv_send_fail );        comport = portno;    switch( phy )    {        case LCM_DRV_HDLC:                        LCM_TRACE_L2_MSG( mb, comport, TRACE_DIRECTION_UP );            #ifdef CONFIG_SIMULATE_E1			(void)hdlc_no;			break;#else            if( TRUE == dev_get_slot_hdlc_by_commport( (U16)comport, &slot, &hdlc_no ) )            {                L2_LINK_S *linkp_2;                LCM_UI_FRAME_S *ui_framep ;                U32 proc_id;                if( slot == (U8)dev_get_local_slot() )                {					comport = hdlc_no;                    break;                }                                if( NULL == m_links[LCM_DRV_ETH]                 || FALSE == dev_get_processorid_by_slot_subc( slot, 0, &proc_id ) )                {                    goto lcm_drv_send_fail;                }                #ifdef LCM_DEBUG                aos_printf( MPE_LCM, "q921->:lcm_drv_send,trans v5 msg to le, slot=%d,hdlc=%d",                            slot, hdlc_no );                #endif                linkp_2 = &m_links[LCM_DRV_ETH][proc_id-processor_id_base];                                ui_framep = (LCM_UI_FRAME_S*)msg_push( mb, ELEMENT_OFFSET( LCM_UI_FRAME_S, info ) );                ui_framep->srcProcessorId = LOCAL_PROCESSOR_ID;                ui_framep->srcMpe = MPE_LCM;                ui_framep->dstProcessorId = proc_id;                ui_framep->dstMpe = MPE_LCM;                                ui_framep->ulSize = mb->len-L3_MSG_HEAD_LEN;                                ui_framep->type    = TRANS_V5_MSG_TO_LE;                ui_framep->slot    = slot;                ui_framep->hdlc_no = hdlc_no;                q921_unit_data_request( linkp_2, mb );                return;            }            else            {                goto lcm_drv_send_fail;            }#endif        case LCM_DRV_ETH:            if( FALSE == dev_get_slot_subc_by_processorid                           ( portno, &slot, &subc ) )            {                goto lcm_drv_send_fail;            }            comport = subc;            comport <<= 8;            comport |= slot;            AOS_ASSERT_FUNC( mb->len <= U16_BUTT, goto lcm_drv_send_fail );                        *(U16*)mb->data = AOS_HTONS((U16)mb->len);            break;        case LCM_DRV_UDP4EIA:        case LCM_DRV_SERIAL:        case LCM_DRV_UDP4SIPTRUNK:        	        	msg_pull( mb, sizeof(U16) );            break;        default:            AOS_ASSERT_FUNC(0, goto lcm_drv_send_fail);            break;    }        if( TRUE == lcm_phy_drv[phy].is_use_mbuf )    {                mbuf = (MBUF_S*)aos_dmem_alloc( MPE_LCM, SID_MBUF, MBUF_MBUF_SIZE );        if( NULL == mbuf )        {            goto lcm_drv_send_fail;        }        mbuf->ulMbufMagic = MBUF_MAGIC_NUMBER;        mbuf->stDataBlockDescriptor.ulDBMagic = DBES_MAGIC_NUMBER;        mbuf->stDataBlockDescriptor.ulType = MBUF_TYPE_DATA;        mbuf->stDataBlockDescriptor.ulOption = 0;        mbuf->stDataBlockDescriptor.pstNextDataBlockDescriptor = NULL;        mbuf->stDataBlockDescriptor.pucDataBlock = mb->head;        mbuf->stDataBlockDescriptor.ulDataBlockLength = mb->truelen;        mbuf->stDataBlockDescriptor.pucData = mb->data;        mbuf->stDataBlockDescriptor.ulDataLength = mb->len;        mbuf->ulTotalDataLength = mb->len;        mbuf->ulDataBlockNumber = 1;        mbuf->pstNextMBuf = NULL;                        msg_free(mb);        mb2send = (struct msg_blk*)mbuf;    }                    (lcm_phy_drv[phy].tx.send)( comport, mb2send );    return;lcm_drv_send_fail:    aos_dmem_free( (VOID*)mb->head );    msg_free( mb );    }VOID lcm_recv_phy_data( U32 phy_type, U32 port_no, struct msg_blk* mb ){    U32 *pU32;    #ifdef LCM_DEBUG    aos_printf( MPE_LCM, "q921<-:lcm_recv_phy_data, phy=%s,portno=%d",                PHY_STRING(phy_type), port_no );    #endif    if( NULL == mb || NULL == mb->head )    {        goto lcm_recv_err_ret;    }    if( lcm_phy_que.qlen >= CONFIG_LCM_QUEUE_LEN )    {        goto lcm_recv_err_ret;    }    if( LCM_DRV_HDLC == phy_type )    {#ifndef CONFIG_SIMULATE_E1        U32 active_mpu_id;        active_mpu_id = EIG_MASTER_MPU_PROCESSOR_ID;                if( LOCAL_PROCESSOR_ID != active_mpu_id )        {                        L2_LINK_S *linkp_2;            LCM_UI_FRAME_S *ui_framep;            if( NULL == m_links[LCM_DRV_ETH] )            {                goto lcm_recv_err_ret;            }            #ifdef LCM_DEBUG

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -