/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void ethernetif_input(struct netif *netif) { if(eth_trylock(netif)) { //fail return; } eth_lock(netif); struct pbuf *p = low_level_input(netif); while( p != NULL ) { netif -> input(p, netif); p = low_level_input(netif); } eth_unlock(netif); }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ err_t ethernetif_input(struct netif *netif) { err_t err; struct pbuf *p; SYS_ARCH_DECL_PROTECT(sr); SYS_ARCH_PROTECT(sr); /* move received packet into a new pbuf */ p = low_level_input(netif); SYS_ARCH_UNPROTECT(sr); /* no packet could be read, silently ignore this */ if (p == NULL) return ERR_MEM; err = netif->input(p, netif); // 将pbuf传递给上层协议栈 if (err != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } return err; }
/** * This function is the ethernetif_input task, it is processed when a packet * is ready to be read from the interface. It uses the function low_level_input() * that should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void ethernetif_input(void * pvParameters) { struct pbuf *p; for( ;; ) { if(xSemaphoreTake(Ethernet_xSemaphore, emacBLOCK_TIME_WAITING_FOR_INPUT)==pdTRUE) { TRY_GET_NEXT_FRAGMENT: p = low_level_input( s_pxNetIf ); if (p != NULL) { if (ERR_OK != s_pxNetIf->input( p, s_pxNetIf)) { pbuf_free(p); p=NULL; } else { xSemaphoreTake( Ethernet_xSemaphore, 0); goto TRY_GET_NEXT_FRAGMENT; } } } } }
static void ethernetif_input( void *pParams ) { struct netif *netif; struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; netif = (struct netif*) pParams; ethernetif = netif->state; for( ;; ) { do { // move received packet into a new pbuf p = low_level_input( netif ); if ( p == NULL ) { // No packet could be read. Wait for an interrupt to tell us // there is more data available. xSemaphoreTake( s_xSemaphore, enc28j60BLOCK_TIME_WAITING_FOR_INPUT ); } } while( p == NULL ); // points to packet payload, which starts with an Ethernet header ethhdr = p->payload; switch ( htons( ethhdr->type ) ) { // IP or ARP packet? case ETHTYPE_IP: // full packet send to tcpip_thread to process if ( netif->input( p, netif ) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free( p ); p = NULL; } break; case ETHTYPE_ARP: #if ETHARP_TRUST_IP_MAC etharp_ip_input( netif, p ); #endif etharp_arp_input( netif, ethernetif->ethaddr, p ); break; default: pbuf_free( p ); p = NULL; break; } } }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ static void ethernetif_input(void * pvParameters) { struct netif *netif = (struct netif *)pvParameters; struct pbuf *p; for( ;; ) { do { /* move received packet into a new pbuf */ p = low_level_input( netif ); if( p == NULL ) { /* No packet could be read. Wait a for an interrupt to tell us there is more data available. */ vMACBWaitForInput(100); } }while( p == NULL ); if( ERR_OK != netif->input( p, netif ) ) { pbuf_free(p); p = NULL; } } }
static void s_ipal_sys_rxpkt_process(void) { struct pbuf *pbuf_ptr; err_t err; ipal_eth_hid_netif *netif_ptr = ipal_eth_hid_getnetif(); pbuf_ptr = low_level_input(&(netif_ptr->netif)); if(NULL == pbuf_ptr) { return; //ok, no problem. no pkt received!!! } // uint64_t timecurr = 0; //eov_sys_LifeTimeGet(eov_sys_GetHandle()); // char str[60]; // sprintf(str, "ipal_sys_rxpkt_process: time=%llu", (timecurr)); // hal_trace_puts(str); /* entry point to the LwIP stack */ err = netif_ptr->netif.input(pbuf_ptr, &(netif_ptr->netif)); pbuf_free(pbuf_ptr); //se esco con errore riprovo a spedire il pkt??e quindi non faccio qui la free?? if(ERR_OK!=err) { ipal_base_hid_on_fatalerror(ipal_error_internal0, "error in process rx pkt by lwip"); return; } }
/** * \brief This function should be called when a packet is ready to be * read from the interface. It uses the function low_level_input() * that should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * \param pv_parameters the lwip network interface structure for this * ethernetif. */ void ethernetif_input(void * pvParameters) { struct netif *netif = (struct netif *)pvParameters; struct pbuf *p; #ifdef FREERTOS_USED for( ;; ) { do { #endif /* move received packet into a new pbuf */ p = low_level_input( netif ); if( p == NULL ) { #ifdef FREERTOS_USED /* No packet could be read. Wait a for an interrupt to tell us there is more data available. */ vTaskDelay(100); } }while( p == NULL ); #else return; } #endif if( ERR_OK != netif->input( p, netif ) ) { pbuf_free(p); p = NULL; } #ifdef FREERTOS_USED }
/*-----------------------------------------------------------------------------------*/ static void tunif_input(struct netif *netif) { struct tunif *tunif; struct pbuf *p; tunif = (struct tunif *)netif->state; p = low_level_input(tunif); if (p == NULL) { LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_input: low_level_input returned NULL\n")); return; } #if 0 /* CS: ip_lookup() was removed */ if (ip_lookup(p->payload, netif)) { #endif netif->input(p, netif); #if 0 } #endif }
static void ethernetif_input( void * pvParameters ) { struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; for( ;; ) { do { ethernetif = s_pxNetIf->state; /* move received packet into a new pbuf */ p = low_level_input( s_pxNetIf ); if( p == NULL ) { /* No packet could be read. Wait a for an interrupt to tell us there is more data available. */ vEMACWaitForInput(); } } while( p == NULL ); /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; #if LINK_STATS lwip_stats.link.recv++; #endif /* LINK_STATS */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP packet? */ case ETHTYPE_IP: /* update ARP table */ etharp_ip_input(s_pxNetIf, p); /* skip Ethernet header */ pbuf_header(p, (s16_t)-sizeof(struct eth_hdr)); /* pass to network layer */ s_pxNetIf->input(p, s_pxNetIf); break; case ETHTYPE_ARP: /* pass p to ARP module */ etharp_arp_input(s_pxNetIf, ethernetif->ethaddr, p); break; default: pbuf_free(p); p = NULL; break; } } }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ static void ethernetif_input( void* notused ) //ethernetif_input(struct netif *netif) { (void)notused; // MakingThings struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; for( ;; ) { do { // ethernetif = netif->state; ethernetif = xNetIf->state; // MakingThings /* move received packet into a new pbuf */ p = low_level_input(xNetIf); // MakingThings /* no packet could be read, silently ignore this */ // if (p == NULL) return; // MakingThings if( p == NULL ) { /* No packet could be read. Wait a for an interrupt to tell us there is more data available. */ vEMACWaitForInput(); } } while( p == NULL ); /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ //if (netif->input(p, netif)!=ERR_OK) if (xNetIf->input(p, xNetIf)!=ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } } }
static void ethernetif_input(void *pReserved) { struct ethernetif *__pstEthernetif; struct pbuf *__pstPbuf; struct eth_hdr *__pstEthhdr; struct netif *__pstNetif; /* 传进来的网卡资料 */ __pstNetif = (struct netif*)pReserved; while(1) { __pstEthernetif = (struct ethernetif*)__pstNetif->state; //Uart_Printf(" into ethernetif_inputTask "); //* 从EMAC循环读取数据 do { __pstPbuf = low_level_input(__pstNetif); if(__pstPbuf == NULL) ///*采用查询的方式工作,一直在查看底层的网卡是否有新的数据过来了 OSAPISemWait(EthernetInput, 300); } while(__pstPbuf == NULL); //*如果底层有数据过来了,那么进入相应的处理阶段 __pstEthhdr = __pstPbuf->payload; //*查看是那种数据包,然后再将其向上传送 switch(htons(__pstEthhdr->type)) { case ETHTYPE_IP: //* 更新ARP表 etharp_ip_input(__pstNetif, __pstPbuf); //* 跳过以太网头部字段 pbuf_header(__pstPbuf, -sizeof(struct eth_hdr) ); //* 传递到网络层 __pstNetif->input(__pstPbuf, __pstNetif); break; case ETHTYPE_ARP: //* 将__pstPbuf传递到ARP模块 etharp_arp_input(__pstNetif, __pstEthernetif->ethaddr, __pstPbuf); break; default: pbuf_free(__pstPbuf); __pstPbuf = NULL; break; } } }
/** * @brief This function is the ethernetif_input task, it is processed when a packet * is ready to be read from the interface. It uses the function low_level_input() * that should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void ethernetif_input( void const * argument ) { struct pbuf *p; /* move received packet into a new pbuf */ p = low_level_input(netif); /* full packet send to tcpip_thread to process */ if (netif->input(p, netif)!= ERR_OK) { pbuf_free(p); p = NULL; } }
err_t ethernetif_input(struct netif *netif) { err_t err; struct pbuf *p; p=low_level_input(netif); if(p==NULL) return ERR_MEM; err=netif->input(p, netif); if(err!=ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG,("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } return err; }
static void ethernetif_input(struct netif *netif) { struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; ethernetif = netif->state; /* move received packet into a new pbuf */ while (TRUE) { p = low_level_input(netif); if (p == NULL) continue; ethhdr = p->payload; switch (htons(ethhdr->type)) { case ETHTYPE_IP: /* update ARP table */ etharp_ip_input(netif, p); /* skip Ethernet header */ //pbuf_header(p, -(14+ETH_PAD_SIZE)); /* pass to network layer */ netif->input(p, netif); break; case ETHTYPE_ARP: etharp_arp_input(netif, ethernetif->ethaddr, p); break; #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif)!=ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } } }
int xlltemacif_input(struct netif *netif) { struct eth_hdr *ethhdr; struct pbuf *p; SYS_ARCH_DECL_PROTECT(lev); /* move received packet into a new pbuf */ SYS_ARCH_PROTECT(lev); p = low_level_input(netif); SYS_ARCH_UNPROTECT(lev); /* no packet could be read, silently ignore this */ if (p == NULL) return 0; /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; #if LINK_STATS lwip_stats.link.recv++; #endif /* LINK_STATS */ switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("xlltemacif_input: IP input error\r\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } return 1; }
/** * This function is the ethernetif_input task, it is processed when a packet * is ready to be read from the interface. It uses the function low_level_input() * that should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void ethernetif_input( void * pvParameters ) { struct pbuf *p; for( ;; ) { if (xSemaphoreTake( s_xSemaphore, emacBLOCK_TIME_WAITING_FOR_INPUT)==pdTRUE) { p = low_level_input( s_pxNetIf ); if (ERR_OK != s_pxNetIf->input( p, s_pxNetIf)) { pbuf_free(p); p=NULL; } } } }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void ethernetif_input(void *pParams) { //struct ethernetif *ethernetif; struct netif *netif; struct eth_hdr *ethhdr; struct pbuf *p; netif = (struct netif*) pParams; //ethernetif = netif->state; for(;;) { if (xSemaphoreTake(semEthRx, portMAX_DELAY) == pdTRUE ) { /* move received packet into a new pbuf */ p = low_level_input(netif); /* no packet could be read, silently ignore this */ if (p != NULL) { /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } } } } }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ static void ethernetif_input(struct netif *netif) { struct eth_hdr *ethhdr; struct pbuf *p; EMAC_IntCmd(EMAC_INT_RX_DONE, ENABLE); for (;;) { sys_sem_wait(&sem_recv); /* no packet could be read, silently ignore this */ while ((p = low_level_input(netif)) != NULL) { /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif)!=ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } } EMAC_IntCmd(EMAC_INT_RX_DONE, ENABLE); } }
s32_t ethernetif_input(struct netif *netif) { //struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; //ethernetif = netif->state; /* move received packet into a new pbuf */ p = low_level_input(netif); /* no packet could be read, silently ignore this */ if (p == NULL) { return 0; } /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif)!=ERR_OK) // netif->input(p, netif) ==> ethernet_input(struct pbuf *p, struct netif *netif) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } return 1; }
static void ethernetif_input(struct netif *netif) { struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; ethernetif = netif->state; /* move received packet into a new pbuf */ p = low_level_input(netif); /* no packet could be read, silently ignore this */ if (p == NULL) return; /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; #if LINK_STATS lwip_stats.link.recv++; #endif /* LINK_STATS */ ethhdr = p->payload; // dprintf("ethernetif_input: type 0x%x\n", htons(ethhdr->type)); switch (htons(ethhdr->type)) { /* IP packet? */ case ETHTYPE_IP: /* update ARP table */ etharp_ip_input(netif, p); /* skip Ethernet header */ pbuf_header(p, -sizeof(struct eth_hdr)); /* pass to network layer */ netif->input(p, netif); break; case ETHTYPE_ARP: /* pass p to ARP module */ etharp_arp_input(netif, ethernetif->ethaddr, p); break; default: pbuf_free(p); p = NULL; break; } }
/** * \brief This function should be called when a packet is ready to be * read from the interface. It uses the function low_level_input() * that should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * \param args the lwip network interface structure for this * ethernetif. */ int ethernetif_input(u8 *buf, u32 buf_len) { struct netif *netif = tls_get_netif(); struct pbuf *p; /* move received packet into a new pbuf */ p = low_level_input(netif, buf, buf_len); if (p) { if (ERR_OK != netif->input(p, netif)) { //LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } return 0; } else { return -1; } }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void enc28j60_if_input(struct netif *netif) { struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; ethernetif = netif->state; /* move received packet into a new pbuf */ p = low_level_input(netif); /* no packet could be read, silently ignore this */ if (p == NULL) return; /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch(htons(ethhdr->type)) { /* IP packet? */ case ETHTYPE_IP: #if 0 /* CSi disabled ARP table update on ingress IP packets. This seems to work but needs thorough testing. */ /* update ARP table */ etharp_ip_input(netif, p); #endif /* skip Ethernet header */ pbuf_header(p, -(s16_t)sizeof(struct eth_hdr)); LWIP_DEBUGF(NETIF_DEBUG,("enc28j60_if_input: passing packet up to IP\n")); // pbuf_free(p); /* pass to network layer */ netif->input(p, netif); break; /* ARP packet? */ case ETHTYPE_ARP: /* pass p to ARP module */ ethernet_input(p, netif); break; /* unsupported Ethernet packet type */ default: /* free pbuf */ pbuf_free(p); p = NULL; break; } }
void ethernetif_input(struct netif *netif,void *p_buf,int size) { // struct ethernetif *ethernetif; struct eth_hdr *ethhdr; struct pbuf *p; if(size > ETH_FRAME_LEN) { p_err("ethernetif_input to long:%d\n",size); return; } p = low_level_input(netif, p_buf, size); if (p == NULL) { return; } /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: // case ETH_P_EAPOL: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ INC_MONITOR_ITEM_VALUE(recv_packets_cnt); if (netif->input(p, netif)!=ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } }
/** * @brief This function is the ethernetif_input task, it is processed when a packet * is ready to be read from the interface. It uses the function low_level_input() * that should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ void ethernetif_input( void const *argument ) { struct pbuf *p; struct netif *netif = (struct netif *) argument; for (;; ) { if ( osSemaphoreWait( s_xSemaphore, TIME_WAITING_FOR_INPUT ) == osOK ) { do { p = low_level_input( netif ); if ( p != NULL ) { if ( netif->input( p, netif ) != ERR_OK ) { pbuf_free( p ); } } } while ( p != NULL ); } } }
/*-----------------------------------------------------------------------------------*/ static void tapif_input(struct netif *netif) { struct tapif *tapif; struct eth_hdr *ethhdr; struct pbuf *p; tapif = netif->state; p = low_level_input(tapif); if(p == NULL) { DEBUGF(TAPIF_DEBUG, ("tapif_input: low_level_input returned NULL\n")); return; } ethhdr = p->payload; switch(htons(ethhdr->type)) { case ETHTYPE_IP: DEBUGF(TAPIF_DEBUG, ("tapif_input: IP packet\n")); arp_ip_input(netif, p); pbuf_header(p, -14); if(ip_lookup(p->payload, netif)) { netif->input(p, netif); } else { printf("tapif_input: lookup failed!\n"); } break; case ETHTYPE_ARP: DEBUGF(TAPIF_DEBUG, ("tapif_input: ARP packet\n")); p = arp_arp_input(netif, tapif->ethaddr, p); if(p != NULL) { DEBUGF(TAPIF_DEBUG, ("tapif_input: Sending ARP reply\n")); low_level_output(tapif, p); pbuf_free(p); } break; default: pbuf_free(p); break; } }
/*-----------------------------------------------------------------------------------*/ static void ethernetif_input(struct netif *netif, void *packet, int packet_len) { struct eth_hdr *ethhdr; struct pbuf *p; if (packet_len <= 0) { return; } /* move received packet into a new pbuf */ p = low_level_input(netif, packet, packet_len); /* no packet could be read, silently ignore this */ if (p == NULL) { return; } /* points to packet payload, which starts with an Ethernet header */ ethhdr = (struct eth_hdr *)p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: LINK_STATS_INC(link.proterr); LINK_STATS_INC(link.drop); pbuf_free(p); p = NULL; break; } }
/** * This function should be called when a packet is ready to be read * from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network * interface. Then the type of the received packet is determined and * the appropriate input function is called. * * @param netif the lwip network interface structure for this ethernetif */ static void ethernetif_input(void *pdata) { struct netif *netif = (struct netif*)pdata; struct eth_hdr *ethhdr; struct pbuf *p; while (1) { do { /* move received packet into a new pbuf */ p = low_level_input(netif); /* no packet could be read, silently ignore this */ if (p == NULL) { /* No packet could be read. Wait a for an interrupt to tell us there is more data available. */ CoPendSem( sem_rx, BLOCK_TIME_WAITING_FOR_INPUT); } } while (NULL == p); /* points to packet payload, which starts with an Ethernet header */ ethhdr = p->payload; switch (htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (ERR_OK != netif->input(p, netif)) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); p = NULL; break; } } }
/*-----------------------------------------------------------------------------------*/ static void tapif_input(struct netif *netif) { struct tapif *tapif; struct eth_hdr *ethhdr; struct pbuf *p; tapif = (struct tapif *)netif->state; p = low_level_input(tapif); if(p == NULL) { LWIP_DEBUGF(TAPIF_DEBUG, ("tapif_input: low_level_input returned NULL\n")); return; } ethhdr = (struct eth_hdr *)p->payload; switch(htons(ethhdr->type)) { /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: #if LWIP_IPV6 case ETHTYPE_IPV6: #endif /* LWIP_IPV6 */ #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ /* full packet send to tcpip_thread to process */ if (netif->input(p, netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; } break; default: pbuf_free(p); break; } }
/*-----------------------------------------------------------------------------------*/ static err_t ibvif_thread(struct netif *netif) { struct ibvif *ibvif; int ne, i; struct ibv_wc wc[PBUF_READ_DEPTH]; ibvif = (struct ibvif *)netif->state; ne = ibv_poll_cq(ibvif->send_cq, PBUF_READ_DEPTH, wc); for (i=0; i<ne; i++) { if (wc[i].status != IBV_WC_SUCCESS) { perror("tapif: write 2"); } } /* Wait for a packet to arrive. */ low_level_input(netif); }
/* * ethernetif_input(): This function should be called when a packet is ready to * be read from the interface. It uses the function low_level_input() that * should handle the actual reception of bytes from the network interface. */ err_t ethernetif_input(struct netif *netif) { err_t err = ERR_OK; struct pbuf *p = NULL; /* move received packet into a new pbuf */ p = low_level_input(netif); if (p == NULL) return ERR_MEM; err = netif->input(p, netif); if (err != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\r\n")); pbuf_free(p); p = NULL; } return err; }