📄 lcm_udpdrv.c
字号:
else { diff_t = 0; pEia->is_rcving = TRUE; pEia->rx_timestamp = headp->timestamp; } if( pEia->rx_serialno == headp->tx_serialno ) { pEia->rx_serialno++; DRV_EIA_DEBUG( "Direct Recv, eiano=%d, tx_s=%u",eia_no,MB_TX_SERIALNO(mb),0,0 ); if( headp->is_new_ver ) { msg_pull( mb, sizeof(struct new_eia_msg_hdr) ); } else { msg_pull( mb, sizeof(struct eia_msg_hdr) ); } if( pEia->is_eia ) { (*eia_rcv)( LCM_DRV_UDP4EIA, pEia->port_no, mb ); }#if( CONFIG_BOARD_GMPU == TRUE ) else { (*siptrunk_rcv)( LCM_DRV_UDP4SIPTRUNK, pEia->port_no, mb ); }#endif goto continuous_recv; } else if( 0 == pEia->rx_delay_que.qlen ) { DRV_EIA_DEBUG( "Que Head 0, eiano=%d, tx_s=%u",eia_no,MB_TX_SERIALNO(mb),0,0 ); msg_que_head( &pEia->rx_delay_que, mb ); return; } mb_t = pEia->rx_delay_que.next; diff_s = 0; while( mb_t != (struct msg_blk*)&pEia->rx_delay_que ) { diff_s = (S32)(MB_TX_SERIALNO(mb_t) - MB_TX_SERIALNO(mb)); if( diff_s > 0 ) { break; } mb_t = mb_t->next; } if( diff_s > MAX_DELAY_PKT_NUM ) { DRV_EIA_DEBUG( "Edrv:eia %d packet arrived too later," "at least %d packets delay", eia_no, -diff_s, 0, 0 ); goto drv_eia_recv_fail; } else if( (-diff_s) > MAX_DELAY_PKT_NUM ) { DRV_EIA_DEBUG( "Edrv:eia %d new window comes," "at least %d packets discard", eia_no, diff_s, 0, 0 ); while( NULL != (mb_t=msg_deque(&pEia->rx_delay_que)) ) { DRV_EIA_DEBUG( "Que Drop 0, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb_t), 0, 0 ); aos_dmem_free( mb_t->head ); msg_free( mb_t ); pEia->rx_drop++; } DRV_EIA_DEBUG( "Que head 1, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb), 0, 0 ); msg_que_head( &pEia->rx_delay_que, mb ); } else { if( mb_t == pEia->rx_delay_que.next ) { DRV_EIA_DEBUG( "Que head 2, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb), 0, 0 ); msg_que_head( &pEia->rx_delay_que, mb ); } else if( mb_t == (struct msg_blk*)&pEia->rx_delay_que ) { DRV_EIA_DEBUG( "Que tail, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb), 0, 0 ); msg_que_tail( &pEia->rx_delay_que, mb ); } else { DRV_EIA_DEBUG( "Que Insert, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb), 0, 0 ); mb->prev = mb_t->prev; mb->next = mb_t; mb_t->prev->next = mb; mb_t->prev = mb; pEia->rx_delay_que.qlen++; } }continuous_recv: while( pEia->rx_delay_que.qlen ) { if( pEia->rx_serialno != MB_TX_SERIALNO(pEia->rx_delay_que.next) ) { break; } mb_t = msg_deque( &pEia->rx_delay_que ); DRV_EIA_DEBUG( "Que Recv 0, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb_t), 0, 0 ); if( headp->is_new_ver ) { msg_pull( mb_t, sizeof(struct new_eia_msg_hdr) ); } else { msg_pull( mb_t, sizeof(struct eia_msg_hdr) ); } pEia->rx_serialno++; if( pEia->is_eia ) { (*eia_rcv)( LCM_DRV_UDP4EIA, pEia->port_no, mb_t ); }#if( CONFIG_BOARD_GMPU == TRUE ) else { (*siptrunk_rcv)( LCM_DRV_UDP4SIPTRUNK, pEia->port_no, mb_t ); }#endif } return;drv_eia_recv_fail: DRV_EIA_DEBUG( "Edrv:eia %d discard packet,tx_s=%u", eia_no,MB_TX_SERIALNO(mb), 0, 0 ); aos_dmem_free( mb->head ); msg_free( mb ); if( NULL!=pEia ) { pEia->rx_drop++; }}VOID edrv_recv_pkt( struct msg_blk *mb, SOCKADDRIN_S *addr, U32 tcpflag, U32 tcpSeq, U32 tcpAck ){ struct eia_msg_hdr *headp; EIA_TABLE_S *pEia; U32 eia_no=0;#ifdef ENABLE_DRV_EIA_DEBUG S8 str[20]; aos_ipaddrtostr( AOS_NTOHL(addr.sin_stAddr.s_ulAddr), str ); DRV_DEBUG_2( "Edrv:Recv msg from ip=%s port=%d", str, AOS_NTOHS(addr.sin_usPort) ); #endif if( mb->len <= sizeof( struct eia_msg_hdr ) ) { AOS_ASSERT(0); aos_dmem_free( (VOID*)mb->head ); msg_free( mb ); return; } if(tcpflag) { tcpflag = 1; } headp = (struct eia_msg_hdr*)mb->data; if( LCM_MSG == headp->msg_type ) { if( !headp->is_siptrunk ) { if( headp->is_new_ver ) { eia_no = ((struct new_eia_msg_hdr*)headp)->eia_no; eia_no = AOS_NTOHS(eia_no); } else { eia_no = headp->eia_no_hi; eia_no <<= 8; eia_no |= headp->eia_no_lo; } pEia = drv_get_eia_cb(eia_no); } else {#if( CONFIG_BOARD_GMPU == TRUE && AOS_INCLUDE_SERVICE_ST == TRUE) eia_no = sst_trunkno_for_ip( addr->sin_stAddr.s_ulAddr ); if( U32_BUTT != eia_no ) { pEia = drv_get_siptrunk_cb(eia_no); eia_no += MAX_DEV_EIA_NUM; } else#endif { pEia = NULL; } } if( (NULL != pEia) && (TRUE == pEia->status) ) { if( pEia->is_tcp_mode != tcpflag ) { aos_printf( MPE_LCM, "EIA %u ip protocol changes from %u to %u", (pEia - eia_table), pEia->is_tcp_mode, tcpflag ); pEia->is_tcp_mode = tcpflag; if( tcpflag ) { pEia->tcpSeq = tcpAck; pEia->tcpAck = tcpSeq; } } if( tcpflag ) { if( (S32)(tcpSeq + mb->len - pEia->tcpAck) > 0 ) { pEia->tcpAck = tcpSeq + mb->len; } } #if( CONFIG_BOARD_GMPU == TRUE ) if( (pEia->addr.sin_stAddr.s_ulAddr != addr->sin_stAddr.s_ulAddr) ||(pEia->addr.sin_usPort != addr->sin_usPort) ) { pEia->addr.sin_stAddr.s_ulAddr = addr->sin_stAddr.s_ulAddr; pEia->addr.sin_usPort = addr->sin_usPort; } #endif SYS_HANDLE_LOCK(); drv_udp_recv( pEia, eia_no, mb ); SYS_HANDLE_UNLOCK(); } else { #ifdef ENABLE_DRV_EIA_DEBUG { S8 str[20]; aos_ipaddrtostr( AOS_NTOHL(addr->sin_stAddr.s_ulAddr), str ); DRV_DEBUG_2( "Edrv:eia not authenticated,ip=%s,port=%d", str, addr->sin_usPort ); } #endif if( NULL!=pEia ) { pEia->rx_drop++; } aos_dmem_free( (VOID*)mb->head ); msg_free( mb ); } } else if( EIA_AUTHEN == headp->msg_type ) { SOCKADDRIN_S *ip_addr_fromp; L3_MSG_HEAD_S *pL3Msg; U32 *pU32; U32 is_new_ver; is_new_ver = headp->is_new_ver; msg_pull( mb, sizeof( struct eia_msg_hdr ) ); ip_addr_fromp = (SOCKADDRIN_S*)msg_put( mb, sizeof(*addr) ); aos_memcpy( ip_addr_fromp, addr, sizeof(*addr) ); if( ( mb->tail + 4*sizeof(U32) ) >= mb->end ) { aos_memmove( mb->data - 4*sizeof(U32), mb->data, mb->len ); mb->data -= 4*sizeof(U32); mb->tail = mb->data + mb->len; } pU32 = (U32*)msg_put( mb , 4*sizeof(U32) ); aos_memcpy( pU32++, &tcpflag, sizeof(U32) ); aos_memcpy( pU32++, &tcpSeq, sizeof(U32) ); aos_memcpy( pU32++, &tcpAck, sizeof(U32) ); aos_memcpy( pU32++, &is_new_ver, sizeof(U32) ); msg_align( mb ); pL3Msg = (L3_MSG_HEAD_S*)msg_push( mb, L3_MSG_HEAD_LEN ); #if( CONFIG_MANUAL_ALIGN == TRUE ) if( ( (U32)pL3Msg) & 0x3 ) { U8 *cp= (U8*)( (U32)pL3Msg &0xFFFFFFFC ); aos_memcpy( (U8*)cp,(U8*)pL3Msg, mb->len); mb->data = (U8*)cp; pL3Msg = (L3_MSG_HEAD_S*) cp; } #endif pL3Msg->srcProcessorId = U32_BUTT; pL3Msg->srcMpe = MPE_EDRV; pL3Msg->dstProcessorId = LOCAL_PROCESSOR_ID; pL3Msg->dstMpe = MPE_DEV; pL3Msg->ulSize = mb->len - L3_MSG_HEAD_LEN; MSG_QUE_SEND( MPE_DEV, mb, MSG_PRIO_NORMAL ); } else { #ifdef ENABLE_DRV_EIA_DEBUG { S8 str[20]; aos_ipaddrtostr( AOS_NTOHL(addr->sin_stAddr.s_ulAddr), str ); DRV_DEBUG_2( "Edrv:Unknown msg type,ip=%s,port=%d", str, AOS_NTOHS(addr->sin_usPort) ); } #endif aos_dmem_free( (VOID*)mb->head ); msg_free( mb ); }}VOID edrv_recv_tcp_signal( struct msg_blk *mb, SOCKADDRIN_S *addr, U32 tcpflag, U32 tcpSeq, U32 tcpAck ){ if( LCM_TCP_SYN == tcpflag ) { U32 localSeq = lcm_get_tcp_iss(); lcm_send_tcp_signal_to_eth( LCM_TCP_SYN_ACK, g_lcm_rel_udp_port, localSeq, tcpSeq+1, addr ); } else if( LCM_TCP_SYN_ACK == tcpflag ) { lcm_send_tcp_signal_to_eth( LCM_TCP_ACK, g_lcm_rel_udp_port, tcpAck, tcpSeq+1, addr );#if( CONFIG_BOARD_EIA == TRUE ) eia_table[0].is_tcp_connected = 1; eia_table[0].tcpSeq = tcpAck; eia_table[0].tcpAck = tcpSeq+1;#endif } aos_dmem_free( (VOID*)mb->head ); msg_free( mb );}VOID drv_eia_delay_recv( ){ static U32 eia_no = 0; EIA_TABLE_S *pEia; U32 eia_loop_no, n_tick, d_tick; struct msg_blk *mb, *mb_out; n_tick = aos_tick_get( ); for( eia_loop_no = 0; eia_loop_no < DRV_EIA_LOOP_NUM; eia_loop_no++, eia_no++, eia_no %= DRV_EIA_NUM ) { pEia = &eia_table[eia_no];#if(CONFIG_BOARD_EIA==TRUE) eia_no = dev_get_mpu_master_processorid();#endif if( pEia->status ) { if( pEia->rx_delay_que.qlen ) { mb = pEia->rx_delay_que.prev; mb_out = NULL; while( mb != (struct msg_blk*)&pEia->rx_delay_que ) { d_tick = n_tick - *(U32*)mb->tail; if( d_tick >= m_ulMaxDelayTick ) { mb_out = mb; break; } mb = mb->prev; } if( NULL != mb_out ) { do { mb = msg_deque(&pEia->rx_delay_que); DRV_EIA_DEBUG( "Que Recv 1, eiano=%d, tx_s=%u",eia_no, MB_TX_SERIALNO(mb), 0, 0 ); pEia->rx_serialno = MB_TX_SERIALNO(mb); pEia->rx_serialno++; if( ((struct eia_msg_hdr*)mb->data)->is_new_ver ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -