提交 b9ca9bf6 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

lwIP if input

上级 a800fbca
...@@ -41,12 +41,6 @@ netalloc(void) ...@@ -41,12 +41,6 @@ netalloc(void)
} }
void void
netrx(void *va, u16 len)
{
cprintf("netrx %lx len %x\n", va, len);
}
void
nettest(void) nettest(void)
{ {
void *ping; void *ping;
...@@ -62,6 +56,8 @@ nettest(void) ...@@ -62,6 +56,8 @@ nettest(void)
#ifdef LWIP #ifdef LWIP
static struct netif nif;
struct timer_thread { struct timer_thread {
u64 nsec; u64 nsec;
struct condvar waitcv; struct condvar waitcv;
...@@ -71,6 +67,13 @@ struct timer_thread { ...@@ -71,6 +67,13 @@ struct timer_thread {
int errno; int errno;
void
netrx(void *va, u16 len)
{
extern void if_input(struct netif *netif, void *buf, u16 len);
if_input(&nif, va, len);
}
static void __attribute__((noreturn)) static void __attribute__((noreturn))
net_timer(void *x) net_timer(void *x)
{ {
...@@ -139,7 +142,6 @@ void ...@@ -139,7 +142,6 @@ void
initnet_worker(void *x) initnet_worker(void *x)
{ {
static struct timer_thread t_arp, t_tcpf, t_tcps, t_dhcpf, t_dhcpc; static struct timer_thread t_arp, t_tcpf, t_tcps, t_dhcpf, t_dhcpc;
static struct netif nif;
volatile long tcpip_done = 0; volatile long tcpip_done = 0;
tcpip_init(&tcpip_init_done, (void*)&tcpip_done); tcpip_init(&tcpip_init_done, (void*)&tcpip_done);
...@@ -157,6 +159,8 @@ initnet_worker(void *x) ...@@ -157,6 +159,8 @@ initnet_worker(void *x)
start_timer(&t_dhcpf, &dhcp_fine_tmr, "dhcp f timer", DHCP_FINE_TIMER_MSECS); start_timer(&t_dhcpf, &dhcp_fine_tmr, "dhcp f timer", DHCP_FINE_TIMER_MSECS);
start_timer(&t_dhcpc, &dhcp_coarse_tmr, "dhcp c timer", DHCP_COARSE_TIMER_MSECS); start_timer(&t_dhcpc, &dhcp_coarse_tmr, "dhcp c timer", DHCP_COARSE_TIMER_MSECS);
} }
void void
...@@ -178,4 +182,10 @@ void ...@@ -178,4 +182,10 @@ void
initnet(void) initnet(void)
{ {
} }
void
netrx(void *va, u16 len)
{
cprintf("netrx: %u\n", len);
}
#endif #endif
...@@ -81,6 +81,110 @@ low_level_output(struct netif *netif, struct pbuf *p) ...@@ -81,6 +81,110 @@ low_level_output(struct netif *netif, struct pbuf *p)
return ERR_OK; return ERR_OK;
} }
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @param netif the lwip network interface structure for this ethernetif
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
static struct pbuf *
low_level_input(struct netif *netif, void *buf, u16_t len)
{
struct pbuf *p, *q;
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
int copied = 0;
/* We iterate over the pbuf chain until we have read the entire
* packet into the pbuf. */
for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len
* variable.
* This does not necessarily have to be a memcpy, you can also preallocate
* pbufs for a DMA-enabled MAC and after receiving truncate it to the
* actually received size. In this case, ensure the tot_len member of the
* pbuf is the sum of the chained pbuf len members.
*/
int bytes = q->len;
if (bytes > (len - copied))
bytes = len - copied;
memmove(q->payload, buf + copied, bytes);
copied += bytes;
}
#if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
LINK_STATS_INC(link.recv);
} else {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
}
return p;
}
/**
* 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
if_input(struct netif *netif, void *buf, u16 len)
{
struct eth_hdr *ethhdr;
struct pbuf *p;
/* move received packet into a new pbuf */
p = low_level_input(netif, buf, len);
netfree(buf);
/* 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 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;
}
}
/** /**
* Should be called at the beginning of the program to set up the * Should be called at the beginning of the program to set up the
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论