From 3e726f7a99026d8160df5cc8a63547215b3a50b7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 30 May 2014 12:13:06 -0600 Subject: Move include/nuttx/net/uip/uip-arch.h to include/nuttx/net/arp.h; rename all uip_arp_ functions to arp_ --- apps/examples/discover/discover_main.c | 2 +- apps/examples/tcpecho/tcpecho_main.c | 2 +- apps/examples/thttpd/thttpd_main.c | 2 +- apps/examples/uip/uip_main.c | 2 +- apps/examples/xmlrpc/xmlrpc_main.c | 2 +- apps/netutils/dhcpd/dhcpd.c | 4 +- nuttx/arch/arm/src/c5471/c5471_ethernet.c | 10 +- nuttx/arch/arm/src/kinetis/kinetis_enet.c | 10 +- nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c | 10 +- nuttx/arch/arm/src/sam34/sam_emac.c | 10 +- nuttx/arch/arm/src/sama5/sam_emac.c | 10 +- nuttx/arch/arm/src/sama5/sam_gmac.c | 10 +- nuttx/arch/arm/src/stm32/stm32_eth.c | 10 +- nuttx/arch/arm/src/tiva/tiva_ethernet.c | 10 +- nuttx/arch/hc/src/m9s12/m9s12_ethernet.c | 10 +- nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c | 10 +- nuttx/arch/sim/src/up_uipdriver.c | 10 +- nuttx/arch/z80/src/ez80/ez80_emac.c | 10 +- nuttx/drivers/net/cs89x0.c | 10 +- nuttx/drivers/net/dm90x0.c | 10 +- nuttx/drivers/net/e1000.c | 10 +- nuttx/drivers/net/enc28j60.c | 10 +- nuttx/drivers/net/encx24j600.c | 10 +- nuttx/drivers/net/skeleton.c | 12 +- nuttx/drivers/net/vnet.c | 10 +- nuttx/include/netinet/arp.h | 2 +- nuttx/include/nuttx/net/arp.h | 283 ++++++++++++++++ nuttx/include/nuttx/net/uip/uip-arch.h | 10 +- nuttx/include/nuttx/net/uip/uip-arp.h | 262 --------------- nuttx/net/arp/arp_inout.c | 444 +++++++++++++++++++++++++ nuttx/net/arp/arp_table.c | 260 +++++++++++++++ nuttx/net/arp/arp_timer.c | 134 ++++++++ nuttx/net/arp/uip_arp.c | 444 ------------------------- nuttx/net/arp/uip_arptab.c | 260 --------------- nuttx/net/net_arptimer.c | 134 -------- nuttx/net/net_internal.h | 8 - nuttx/net/net_send_buffered.c | 8 +- nuttx/net/net_send_unbuffered.c | 8 +- nuttx/net/net_sendfile.c | 4 +- nuttx/net/net_sockets.c | 2 +- 40 files changed, 1237 insertions(+), 1232 deletions(-) create mode 100644 nuttx/include/nuttx/net/arp.h delete mode 100644 nuttx/include/nuttx/net/uip/uip-arp.h create mode 100644 nuttx/net/arp/arp_inout.c create mode 100644 nuttx/net/arp/arp_table.c create mode 100644 nuttx/net/arp/arp_timer.c delete mode 100644 nuttx/net/arp/uip_arp.c delete mode 100644 nuttx/net/arp/uip_arptab.c delete mode 100644 nuttx/net/net_arptimer.c diff --git a/apps/examples/discover/discover_main.c b/apps/examples/discover/discover_main.c index 00c8e7fba..0fc6e7b7b 100644 --- a/apps/examples/discover/discover_main.c +++ b/apps/examples/discover/discover_main.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include #include diff --git a/apps/examples/tcpecho/tcpecho_main.c b/apps/examples/tcpecho/tcpecho_main.c index 8b26656f4..88b931def 100644 --- a/apps/examples/tcpecho/tcpecho_main.c +++ b/apps/examples/tcpecho/tcpecho_main.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include diff --git a/apps/examples/thttpd/thttpd_main.c b/apps/examples/thttpd/thttpd_main.c index 71fc8de6a..da040a218 100644 --- a/apps/examples/thttpd/thttpd_main.c +++ b/apps/examples/thttpd/thttpd_main.c @@ -51,7 +51,7 @@ #include #include -#include +#include #include #include diff --git a/apps/examples/uip/uip_main.c b/apps/examples/uip/uip_main.c index 3dbf0eb82..68fc20bf5 100644 --- a/apps/examples/uip/uip_main.c +++ b/apps/examples/uip/uip_main.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include diff --git a/apps/examples/xmlrpc/xmlrpc_main.c b/apps/examples/xmlrpc/xmlrpc_main.c index d28d6eae6..5d4e52299 100644 --- a/apps/examples/xmlrpc/xmlrpc_main.c +++ b/apps/examples/xmlrpc/xmlrpc_main.c @@ -64,7 +64,7 @@ #include #include -#include +#include #include #include diff --git a/apps/netutils/dhcpd/dhcpd.c b/apps/netutils/dhcpd/dhcpd.c index c600be2fa..edc9195d0 100644 --- a/apps/netutils/dhcpd/dhcpd.c +++ b/apps/netutils/dhcpd/dhcpd.c @@ -56,7 +56,7 @@ # include /* For ndbg, vdbg */ # include /* For CONFIG_CPP_HAVE_WARNING */ # include /* For irqstore() and friends -- REVISIT */ -# include /* For low-level ARP interfaces -- REVISIT */ +# include /* For low-level ARP interfaces -- REVISIT */ # include /* Advertised DHCPD APIs */ #endif @@ -277,7 +277,7 @@ static inline void dhcpd_arpupdate(uint16_t *pipaddr, uint8_t *phwaddr) */ flags = uip_lock(); - uip_arp_update(pipaddr, phwaddr); + arp_update(pipaddr, phwaddr); uip_unlock(flags); } #else diff --git a/nuttx/arch/arm/src/c5471/c5471_ethernet.c b/nuttx/arch/arm/src/c5471/c5471_ethernet.c index 94b392153..4a6ff9bde 100644 --- a/nuttx/arch/arm/src/c5471/c5471_ethernet.c +++ b/nuttx/arch/arm/src/c5471/c5471_ethernet.c @@ -59,7 +59,7 @@ #include #include -#include +#include #include #include "chip.h" @@ -984,7 +984,7 @@ static int c5471_uiptxpoll(struct uip_driver_s *dev) if (c5471->c_dev.d_len > 0) { - uip_arp_out(&c5471->c_dev); + arp_out(&c5471->c_dev); c5471_transmit(c5471); /* Check if the ESM has let go of the RX descriptor giving us access @@ -1238,7 +1238,7 @@ static void c5471_receive(struct c5471_driver_s *c5471) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(dev); + arp_ipin(dev); uip_input(dev); /* If the above function invocation resulted in data that should be @@ -1250,13 +1250,13 @@ static void c5471_receive(struct c5471_driver_s *c5471) if (dev->d_len > 0 && (EIM_TXDESC_OWN_HOST & getreg32(c5471->c_rxcpudesc)) == 0) { - uip_arp_out(dev); + arp_out(dev); c5471_transmit(c5471); } } else if (BUF->type == HTONS(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(dev); + arp_arpin(dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/kinetis/kinetis_enet.c b/nuttx/arch/arm/src/kinetis/kinetis_enet.c index 2607b6bdf..096ff54a3 100644 --- a/nuttx/arch/arm/src/kinetis/kinetis_enet.c +++ b/nuttx/arch/arm/src/kinetis/kinetis_enet.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include "up_arch.h" @@ -444,7 +444,7 @@ static int kinetis_uiptxpoll(struct uip_driver_s *dev) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); kinetis_transmit(priv); /* Check if there is room in the device to hold another packet. If not, @@ -522,7 +522,7 @@ static void kinetis_receive(FAR struct kinetis_driver_s *priv) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -531,13 +531,13 @@ static void kinetis_receive(FAR struct kinetis_driver_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); kinetis_transmit(priv); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should * be sent out on the network, the field d_len will set to a diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c b/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c index 360b6acc9..60dee4a8e 100644 --- a/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c +++ b/nuttx/arch/arm/src/lpc17xx/lpc17_ethernet.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include "up_arch.h" @@ -681,7 +681,7 @@ static int lpc17_uiptxpoll(struct uip_driver_s *dev) * at least one more packet in the descriptor list. */ - uip_arp_out(&priv->lp_dev); + arp_out(&priv->lp_dev); lpc17_transmit(priv); /* Check if there is room in the device to hold another packet. If not, @@ -867,7 +867,7 @@ static void lpc17_rxdone(struct lpc17_driver_s *priv) /* Handle the incoming Rx packet */ EMAC_STAT(priv, rx_ip); - uip_arp_ipin(&priv->lp_dev); + arp_ipin(&priv->lp_dev); uip_input(&priv->lp_dev); /* If the above function invocation resulted in data that @@ -877,14 +877,14 @@ static void lpc17_rxdone(struct lpc17_driver_s *priv) if (priv->lp_dev.d_len > 0) { - uip_arp_out(&priv->lp_dev); + arp_out(&priv->lp_dev); lpc17_response(priv); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { EMAC_STAT(priv, rx_arp); - uip_arp_arpin(&priv->lp_dev); + arp_arpin(&priv->lp_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the field d_len will diff --git a/nuttx/arch/arm/src/sam34/sam_emac.c b/nuttx/arch/arm/src/sam34/sam_emac.c index d2c134c90..3bdd288ee 100644 --- a/nuttx/arch/arm/src/sam34/sam_emac.c +++ b/nuttx/arch/arm/src/sam34/sam_emac.c @@ -64,7 +64,7 @@ #include #include #include -#include +#include #include #include "up_arch.h" @@ -820,7 +820,7 @@ static int sam_uiptxpoll(struct uip_driver_s *dev) { /* Send the packet */ - uip_arp_out(&priv->dev); + arp_out(&priv->dev); sam_transmit(priv); /* Check if the there are any free TX descriptors. We cannot perform @@ -1139,7 +1139,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1148,7 +1148,7 @@ static void sam_receive(struct sam_emac_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); sam_transmit(priv); } } @@ -1158,7 +1158,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP packet */ - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/sama5/sam_emac.c b/nuttx/arch/arm/src/sama5/sam_emac.c index b20446ec7..b62f39b63 100644 --- a/nuttx/arch/arm/src/sama5/sam_emac.c +++ b/nuttx/arch/arm/src/sama5/sam_emac.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include "up_arch.h" @@ -824,7 +824,7 @@ static int sam_uiptxpoll(struct uip_driver_s *dev) { /* Send the packet */ - uip_arp_out(&priv->dev); + arp_out(&priv->dev); sam_transmit(priv); /* Check if the there are any free TX descriptors. We cannot perform @@ -1171,7 +1171,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1180,7 +1180,7 @@ static void sam_receive(struct sam_emac_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); sam_transmit(priv); } } @@ -1190,7 +1190,7 @@ static void sam_receive(struct sam_emac_s *priv) /* Handle ARP packet */ - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/sama5/sam_gmac.c b/nuttx/arch/arm/src/sama5/sam_gmac.c index 453dca9c0..096405573 100644 --- a/nuttx/arch/arm/src/sama5/sam_gmac.c +++ b/nuttx/arch/arm/src/sama5/sam_gmac.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include "up_arch.h" @@ -762,7 +762,7 @@ static int sam_uiptxpoll(struct uip_driver_s *dev) { /* Send the packet */ - uip_arp_out(&priv->dev); + arp_out(&priv->dev); sam_transmit(priv); /* Check if the there are any free TX descriptors. We cannot perform @@ -1109,7 +1109,7 @@ static void sam_receive(struct sam_gmac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1118,7 +1118,7 @@ static void sam_receive(struct sam_gmac_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); sam_transmit(priv); } } @@ -1128,7 +1128,7 @@ static void sam_receive(struct sam_gmac_s *priv) /* Handle ARP packet */ - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c index 7cd5d6a13..60187bcff 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.c +++ b/nuttx/arch/arm/src/stm32/stm32_eth.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include "up_internal.h" @@ -1167,7 +1167,7 @@ static int stm32_uiptxpoll(struct uip_driver_s *dev) { /* Send the packet */ - uip_arp_out(&priv->dev); + arp_out(&priv->dev); stm32_transmit(priv); DEBUGASSERT(dev->d_len == 0 && dev->d_buf == NULL); @@ -1610,7 +1610,7 @@ static void stm32_receive(FAR struct stm32_ethmac_s *priv) /* Handle ARP on input then give the IP packet to uIP */ - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1619,7 +1619,7 @@ static void stm32_receive(FAR struct stm32_ethmac_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); stm32_transmit(priv); } } @@ -1629,7 +1629,7 @@ static void stm32_receive(FAR struct stm32_ethmac_s *priv) /* Handle ARP packet */ - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/arm/src/tiva/tiva_ethernet.c b/nuttx/arch/arm/src/tiva/tiva_ethernet.c index 070236827..a3a282111 100644 --- a/nuttx/arch/arm/src/tiva/tiva_ethernet.c +++ b/nuttx/arch/arm/src/tiva/tiva_ethernet.c @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include "chip.h" @@ -610,7 +610,7 @@ static int tiva_uiptxpoll(struct uip_driver_s *dev) */ DEBUGASSERT((tiva_ethin(priv, TIVA_MAC_TR_OFFSET) & MAC_TR_NEWTX) == 0) - uip_arp_out(&priv->ld_dev); + arp_out(&priv->ld_dev); ret = tiva_transmit(priv); } @@ -766,7 +766,7 @@ static void tiva_receive(struct tiva_driver_s *priv) nllvdbg("IP packet received (%02x)\n", ETHBUF->type); EMAC_STAT(priv, rx_ip); - uip_arp_ipin(&priv->ld_dev); + arp_ipin(&priv->ld_dev); uip_input(&priv->ld_dev); /* If the above function invocation resulted in data that should be @@ -775,7 +775,7 @@ static void tiva_receive(struct tiva_driver_s *priv) if (priv->ld_dev.d_len > 0) { - uip_arp_out(&priv->ld_dev); + arp_out(&priv->ld_dev); tiva_transmit(priv); } } @@ -784,7 +784,7 @@ static void tiva_receive(struct tiva_driver_s *priv) nllvdbg("ARP packet received (%02x)\n", ETHBUF->type); EMAC_STAT(priv, rx_arp); - uip_arp_arpin(&priv->ld_dev); + arp_arpin(&priv->ld_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c b/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c index b01bc1284..857469b28 100644 --- a/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c +++ b/nuttx/arch/hc/src/m9s12/m9s12_ethernet.c @@ -52,7 +52,7 @@ #include #include -#include +#include #include /**************************************************************************** @@ -212,7 +212,7 @@ static int emac_uiptxpoll(struct uip_driver_s *dev) if (priv->d_dev.d_len > 0) { - uip_arp_out(&priv->d_dev); + arp_out(&priv->d_dev); emac_transmit(priv); /* Check if there is room in the device to hold another packet. If not, @@ -264,7 +264,7 @@ static void emac_receive(FAR struct emac_driver_s *priv) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&priv->d_dev); + arp_ipin(&priv->d_dev); uip_input(&priv->d_dev); /* If the above function invocation resulted in data that should be @@ -273,13 +273,13 @@ static void emac_receive(FAR struct emac_driver_s *priv) if (priv->d_dev.d_len > 0) { - uip_arp_out(&priv->d_dev); + arp_out(&priv->d_dev); emac_transmit(priv); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&priv->d_dev); + arp_arpin(&priv->d_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c b/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c index fedf20b04..5af9e7452 100644 --- a/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c +++ b/nuttx/arch/mips/src/pic32mx/pic32mx-ethernet.c @@ -57,7 +57,7 @@ #include #include -#include +#include #include #include @@ -1147,7 +1147,7 @@ static int pic32mx_uiptxpoll(struct uip_driver_s *dev) * at least one more packet in the descriptor list. */ - uip_arp_out(&priv->pd_dev); + arp_out(&priv->pd_dev); pic32mx_transmit(priv); /* Check if the next TX descriptor is available. If not, return a @@ -1435,7 +1435,7 @@ static void pic32mx_rxdone(struct pic32mx_driver_s *priv) /* Handle the incoming IP packet */ EMAC_STAT(priv, rx_ip); - uip_arp_ipin(&priv->pd_dev); + arp_ipin(&priv->pd_dev); uip_input(&priv->pd_dev); /* If the above function invocation resulted in data that @@ -1445,7 +1445,7 @@ static void pic32mx_rxdone(struct pic32mx_driver_s *priv) if (priv->pd_dev.d_len > 0) { - uip_arp_out(&priv->pd_dev); + arp_out(&priv->pd_dev); pic32mx_response(priv); } } @@ -1454,7 +1454,7 @@ static void pic32mx_rxdone(struct pic32mx_driver_s *priv) /* Handle the incoming ARP packet */ EMAC_STAT(priv, rx_arp); - uip_arp_arpin(&priv->pd_dev); + arp_arpin(&priv->pd_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the field d_len will diff --git a/nuttx/arch/sim/src/up_uipdriver.c b/nuttx/arch/sim/src/up_uipdriver.c index 99f37b22f..3bc0bf9df 100644 --- a/nuttx/arch/sim/src/up_uipdriver.c +++ b/nuttx/arch/sim/src/up_uipdriver.c @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include "up_internal.h" @@ -123,7 +123,7 @@ static int sim_uiptxpoll(struct uip_driver_s *dev) if (g_sim_dev.d_len > 0) { - uip_arp_out(&g_sim_dev); + arp_out(&g_sim_dev); netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } @@ -166,7 +166,7 @@ void uipdriver_loop(void) if (BUF->ether_type == htons(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&g_sim_dev); + arp_ipin(&g_sim_dev); uip_input(&g_sim_dev); /* If the above function invocation resulted in data that @@ -176,13 +176,13 @@ void uipdriver_loop(void) if (g_sim_dev.d_len > 0) { - uip_arp_out(&g_sim_dev); + arp_out(&g_sim_dev); netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } else if (BUF->ether_type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&g_sim_dev); + arp_arpin(&g_sim_dev); /* If the above function invocation resulted in data that * should be sent out on the network, the global variable diff --git a/nuttx/arch/z80/src/ez80/ez80_emac.c b/nuttx/arch/z80/src/ez80/ez80_emac.c index 4957a5bd8..5787303eb 100644 --- a/nuttx/arch/z80/src/ez80/ez80_emac.c +++ b/nuttx/arch/z80/src/ez80/ez80_emac.c @@ -59,7 +59,7 @@ #include #include -#include +#include #include #include "chip.h" @@ -1080,7 +1080,7 @@ static int ez80emac_uiptxpoll(struct uip_driver_s *dev) * packet was successfully handled. */ - uip_arp_out(&priv->dev); + arp_out(&priv->dev); ret = ez80emac_transmit(priv); } @@ -1274,7 +1274,7 @@ static int ez80emac_receive(struct ez80emac_driver_s *priv) nvdbg("IP packet received (%02x)\n", ETHBUF->type); EMAC_STAT(priv, rx_ip); - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1283,7 +1283,7 @@ static int ez80emac_receive(struct ez80emac_driver_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); ez80emac_transmit(priv); } } @@ -1292,7 +1292,7 @@ static int ez80emac_receive(struct ez80emac_driver_s *priv) nvdbg("ARP packet received (%02x)\n", ETHBUF->type); EMAC_STAT(priv, rx_arp); - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/cs89x0.c b/nuttx/drivers/net/cs89x0.c index 8b431eb66..860830777 100644 --- a/nuttx/drivers/net/cs89x0.c +++ b/nuttx/drivers/net/cs89x0.c @@ -52,7 +52,7 @@ #include #include -#include +#include #include /**************************************************************************** @@ -337,7 +337,7 @@ static int cs89x0_uiptxpoll(struct uip_driver_s *dev) if (cs89x0->cs_dev.d_len > 0) { - uip_arp_out(&cs89x0->cs_dev); + arp_out(&cs89x0->cs_dev); cs89x0_transmit(cs89x0); /* Check if there is room in the CS89x0 to hold another packet. If not, @@ -438,7 +438,7 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&cs89x0->cs_dev); + arp_ipin(&cs89x0->cs_dev); uip_input(&cs89x0->cs_dev); /* If the above function invocation resulted in data that should be @@ -447,13 +447,13 @@ static void cs89x0_receive(struct cs89x0_driver_s *cs89x0, uint16_t isq) if (cs89x0->cs_dev.d_len > 0) { - uip_arp_out(&cs89x0->cs_dev); + arp_out(&cs89x0->cs_dev); cs89x0_transmit(cs89x0); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&cs89x0->cs_dev); + arp_arpin(&cs89x0->cs_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/dm90x0.c b/nuttx/drivers/net/dm90x0.c index 33d294532..0f4fb0e49 100644 --- a/nuttx/drivers/net/dm90x0.c +++ b/nuttx/drivers/net/dm90x0.c @@ -65,7 +65,7 @@ #include #include -#include +#include #include /**************************************************************************** @@ -849,7 +849,7 @@ static int dm9x_uiptxpoll(struct uip_driver_s *dev) if (dm9x->dm_dev.d_len > 0) { - uip_arp_out(&dm9x->dm_dev); + arp_out(&dm9x->dm_dev); dm9x_transmit(dm9x); /* Check if there is room in the DM90x0 to hold another packet. In 100M mode, @@ -988,7 +988,7 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&dm9x->dm_dev); + arp_ipin(&dm9x->dm_dev); uip_input(&dm9x->dm_dev); /* If the above function invocation resulted in data that should be @@ -997,13 +997,13 @@ static void dm9x_receive(struct dm9x_driver_s *dm9x) if (dm9x->dm_dev.d_len > 0) { - uip_arp_out(&dm9x->dm_dev); + arp_out(&dm9x->dm_dev); dm9x_transmit(dm9x); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&dm9x->dm_dev); + arp_arpin(&dm9x->dm_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/e1000.c b/nuttx/drivers/net/e1000.c index dda9692b7..255bd01d1 100644 --- a/nuttx/drivers/net/e1000.c +++ b/nuttx/drivers/net/e1000.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include #include @@ -487,7 +487,7 @@ static int e1000_uiptxpoll(struct uip_driver_s *dev) if (e1000->uip_dev.d_len > 0) { - uip_arp_out(&e1000->uip_dev); + arp_out(&e1000->uip_dev); e1000_transmit(e1000); /* Check if there is room in the device to hold another packet. If not, @@ -573,7 +573,7 @@ static void e1000_receive(struct e1000_dev *e1000) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&e1000->uip_dev); + arp_ipin(&e1000->uip_dev); uip_input(&e1000->uip_dev); /* If the above function invocation resulted in data that should be @@ -582,13 +582,13 @@ static void e1000_receive(struct e1000_dev *e1000) if (e1000->uip_dev.d_len > 0) { - uip_arp_out(&e1000->uip_dev); + arp_out(&e1000->uip_dev); e1000_transmit(e1000); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&e1000->uip_dev); + arp_arpin(&e1000->uip_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/enc28j60.c b/nuttx/drivers/net/enc28j60.c index 113411bc7..374821914 100644 --- a/nuttx/drivers/net/enc28j60.c +++ b/nuttx/drivers/net/enc28j60.c @@ -62,7 +62,7 @@ #include #include -#include +#include #include #include "enc28j60.h" @@ -1195,7 +1195,7 @@ static int enc_uiptxpoll(struct uip_driver_s *dev) nllvdbg("Poll result: d_len=%d\n", priv->dev.d_len); if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); enc_transmit(priv); /* Stop the poll now because we can queue only one packet */ @@ -1378,7 +1378,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) #endif { nllvdbg("IP packet received (%02x)\n", BUF->type); - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); uip_input(&priv->dev); /* If the above function invocation resulted in data that should be @@ -1387,14 +1387,14 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); enc_transmit(priv); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { nllvdbg("ARP packet received (%02x)\n", BUF->type); - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/encx24j600.c b/nuttx/drivers/net/encx24j600.c index 548340e97..28c49469e 100644 --- a/nuttx/drivers/net/encx24j600.c +++ b/nuttx/drivers/net/encx24j600.c @@ -68,7 +68,7 @@ #include #include -#include +#include #include #include "encx24j600.h" @@ -1209,7 +1209,7 @@ static int enc_uiptxpoll(struct uip_driver_s *dev) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); ret = enc_txenqueue(priv); } @@ -1496,7 +1496,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) { nllvdbg("Try to process IP packet (%02x)\n", BUF->type); - uip_arp_ipin(&priv->dev); + arp_ipin(&priv->dev); ret = uip_input(&priv->dev); if (ret == OK || (clock_systimer() - descr->ts) > ENC_RXTIMEOUT) @@ -1514,14 +1514,14 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) if (priv->dev.d_len > 0) { - uip_arp_out(&priv->dev); + arp_out(&priv->dev); enc_txenqueue(priv); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { nllvdbg("ARP packet received (%02x)\n", BUF->type); - uip_arp_arpin(&priv->dev); + arp_arpin(&priv->dev); /* ARP packets are freed immediately */ diff --git a/nuttx/drivers/net/skeleton.c b/nuttx/drivers/net/skeleton.c index b4d4811a8..6dd17958d 100644 --- a/nuttx/drivers/net/skeleton.c +++ b/nuttx/drivers/net/skeleton.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/skeleton.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,7 +52,7 @@ #include #include -#include +#include #include /**************************************************************************** @@ -212,7 +212,7 @@ static int skel_uiptxpoll(struct uip_driver_s *dev) if (skel->sk_dev.d_len > 0) { - uip_arp_out(&skel->sk_dev); + arp_out(&skel->sk_dev); skel_transmit(skel); /* Check if there is room in the device to hold another packet. If not, @@ -264,7 +264,7 @@ static void skel_receive(FAR struct skel_driver_s *skel) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&skel->sk_dev); + arp_ipin(&skel->sk_dev); uip_input(&skel->sk_dev); /* If the above function invocation resulted in data that should be @@ -273,13 +273,13 @@ static void skel_receive(FAR struct skel_driver_s *skel) if (skel->sk_dev.d_len > 0) { - uip_arp_out(&skel->sk_dev); + arp_out(&skel->sk_dev); skel_transmit(skel); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&skel->sk_dev); + arp_arpin(&skel->sk_dev); /* If the above function invocation resulted in data that should be * sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/drivers/net/vnet.c b/nuttx/drivers/net/vnet.c index 5ca63e3c0..671ece432 100644 --- a/nuttx/drivers/net/vnet.c +++ b/nuttx/drivers/net/vnet.c @@ -56,7 +56,7 @@ #include #include -#include +#include #include #include @@ -231,7 +231,7 @@ static int vnet_uiptxpoll(struct uip_driver_s *dev) if (vnet->sk_dev.d_len > 0) { - uip_arp_out(&vnet->sk_dev); + arp_out(&vnet->sk_dev); vnet_transmit(vnet); /* Check if there is room in the device to hold another packet. If not, @@ -293,18 +293,18 @@ void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif { - uip_arp_ipin(&vnet->sk_dev); + arp_ipin(&vnet->sk_dev); uip_input(&vnet->sk_dev); // If the above function invocation resulted in data that should be // sent out on the network, the field d_len will set to a value > 0. if (vnet->sk_dev.d_len > 0) { - uip_arp_out(&vnet->sk_dev); + arp_out(&vnet->sk_dev); vnet_transmit(vnet); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&vnet->sk_dev); + arp_arpin(&vnet->sk_dev); // If the above function invocation resulted in data that should be // sent out on the network, the field d_len will set to a value > 0. diff --git a/nuttx/include/netinet/arp.h b/nuttx/include/netinet/arp.h index e318945aa..5a041f4f0 100644 --- a/nuttx/include/netinet/arp.h +++ b/nuttx/include/netinet/arp.h @@ -102,7 +102,7 @@ extern "C" { /* If CONFIG_NET_ARPIOCTLS is defined then the semi-standard ioctl commands * described above are supported. If not, you can call the uIP ARP interfaces - * directly in a very non-standard way. See include/nuttx/net/uip/uip-arp.h for + * directly in a very non-standard way. See include/nuttx/net/arp.h for * prototypes. */ diff --git a/nuttx/include/nuttx/net/arp.h b/nuttx/include/nuttx/net/arp.h new file mode 100644 index 000000000..52051a52e --- /dev/null +++ b/nuttx/include/nuttx/net/arp.h @@ -0,0 +1,283 @@ +/**************************************************************************** + * include/nuttx/net/arp.h + * Macros and definitions for the ARP module. + * + * Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Derived from uIP with has a similar BSD-styple license: + * + * Author: Adam Dunkels + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NET_ARP_H +#define __INCLUDE_NUTTX_NET_ARP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Recognized values of the type bytes in the Ethernet header */ + +#define UIP_ETHTYPE_ARP 0x0806 +#define UIP_ETHTYPE_IP 0x0800 +#define UIP_ETHTYPE_IP6 0x86dd + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* The Ethernet header -- 14 bytes. The first two fields are type 'struct + * ether_addr but are represented as a simple byte array here because + * some compilers refuse to pack 6 byte structures. + */ + +struct uip_eth_hdr +{ + uint8_t dest[6]; /* Ethernet destination address (6 bytes) */ + uint8_t src[6]; /* Ethernet source address (6 bytes) */ + uint16_t type; /* Type code (2 bytes) */ +}; + +/* One entry in the ARP table (volatile!) */ + +struct arp_entry +{ + in_addr_t at_ipaddr; /* IP address */ + struct ether_addr at_ethaddr; /* Hardware address */ + uint8_t at_time; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_NET_ARP +/**************************************************************************** + * Name: arp_init + * + * Description: + * Initialize the ARP module. This function must be called before any of + * the other ARP functions. + * + ****************************************************************************/ + +void arp_init(void); + +/**************************************************************************** + * Name: arp_ipin + * + * Description: + * The arp_ipin() function should be called whenever an IP packet + * arrives from the Ethernet. This function refreshes the ARP table or + * inserts a new mapping if none exists. The function assumes that an + * IP packet with an Ethernet header is present in the d_buf buffer + * and that the length of the packet is in the d_len field. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_ARP_IPIN +void arp_ipin(struct uip_driver_s *dev); +#else +# define arp_ipin(dev) +#endif + +/**************************************************************************** + * Name: arp_arpin + * + * Description: + * The arp_arpin() should be called when an ARP packet is received + * by the Ethernet driver. This function also assumes that the + * Ethernet frame is present in the d_buf buffer. When the + * arp_arpin() function returns, the contents of the d_buf + * buffer should be sent out on the Ethernet if the d_len field + * is > 0. + * + ****************************************************************************/ + +void arp_arpin(struct uip_driver_s *dev); + +/**************************************************************************** + * Name: arp_arpin + * + * Description: + * The arp_out() function should be called when an IP packet + * should be sent out on the Ethernet. This function creates an + * Ethernet header before the IP header in the d_buf buffer. The + * Ethernet header will have the correct Ethernet MAC destination + * address filled in if an ARP table entry for the destination IP + * address (or the IP address of the default router) is present. If no + * such table entry is found, the IP packet is overwritten with an ARP + * request and we rely on TCP to retransmit the packet that was + * overwritten. In any case, the d_len field holds the length of + * the Ethernet frame that should be transmitted. + * + ****************************************************************************/ + +void arp_out(struct uip_driver_s *dev); + +/**************************************************************************** + * Function: arp_timer_init + * + * Description: + * Initialized the 10 second timer that is need by uIP to age ARP + * associations + * + * Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * Called once at system initialization time + * + ****************************************************************************/ + +void arp_timer_init(void); + +/**************************************************************************** + * Name: arp_timer + * + * Description: + * This function performs periodic timer processing in the ARP module + * and should be called at regular intervals. The recommended interval + * is 10 seconds between the calls. It is responsible for flushing old + * entries in the ARP table. + * + ****************************************************************************/ + +void arp_timer(void); + +/**************************************************************************** + * Name: arp_update + * + * Description: + * Add the IP/HW address mapping to the ARP table -OR- change the IP + * address of an existing association. + * + * Input parameters: + * pipaddr - Refers to an IP address uint16_t[2] in network order + * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] + * + * Assumptions + * Interrupts are disabled + * + ****************************************************************************/ + +void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr); + +/**************************************************************************** + * Name: arp_find + * + * Description: + * Find the ARP entry corresponding to this IP address. + * + * Input parameters: + * ipaddr - Refers to an IP address in network order + * + * Assumptions + * Interrupts are disabled; Returned value will become unstable when + * interrupts are re-enabled or if any other uIP APIs are called. + * + ****************************************************************************/ + +struct arp_entry *arp_find(in_addr_t ipaddr); + +/**************************************************************************** + * Name: arp_delete + * + * Description: + * Remove an IP association from the ARP table + * + * Input parameters: + * ipaddr - Refers to an IP address in network order + * + * Assumptions + * Interrupts are disabled + * + ****************************************************************************/ + +#define arp_delete(ipaddr) \ +{ \ + struct arp_entry *tabptr = arp_find(ipaddr); \ + if (tabptr) \ + { \ + tabptr->at_ipaddr = 0; \ + } \ +} + +#else /* CONFIG_NET_ARP */ + +/* If ARP is disabled, stub out all ARP interfaces */ + +# define arp_init() +# define arp_ipin(dev) +# define arp_arpin(dev) +# define arp_out(dev) +# define arp_timer() +# define arp_update(pipaddr,ethaddr) +# define arp_find(ipaddr) NULL +# define arp_delete(ipaddr) +# define arp_timer_init(void); + +#endif /* CONFIG_NET_ARP */ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_NET_ARP_H */ diff --git a/nuttx/include/nuttx/net/uip/uip-arch.h b/nuttx/include/nuttx/net/uip/uip-arch.h index 9dffdcede..c6b664d7f 100644 --- a/nuttx/include/nuttx/net/uip/uip-arch.h +++ b/nuttx/include/nuttx/net/uip/uip-arch.h @@ -242,17 +242,17 @@ struct uip_driver_s * { * if (BUF->type == HTONS(UIP_ETHTYPE_IP)) * { - * uip_arp_ipin(); + * arp_ipin(); * uip_input(dev); * if (dev->d_len > 0) * { - * uip_arp_out(); + * arp_out(); * devicedriver_send(); * } * } * else if (BUF->type == HTONS(UIP_ETHTYPE_ARP)) * { - * uip_arp_arpin(); + * arp_arpin(); * if (dev->d_len > 0) * { * devicedriver_send(); @@ -297,14 +297,14 @@ int uip_input(struct uip_driver_s *dev); * * Note: If you are writing a uIP device driver that needs ARP (Address * Resolution Protocol), e.g., when running uIP over Ethernet, you will - * need to call the uip_arp_out() function in the callback function + * need to call the arp_out() function in the callback function * before sending the packet: * * int driver_callback(struct uip_driver_dev *dev) * { * if (dev->d_len > 0) * { - * uip_arp_out(); + * arp_out(); * devicedriver_send(); * return 1; <-- Terminates polling if necessary * } diff --git a/nuttx/include/nuttx/net/uip/uip-arp.h b/nuttx/include/nuttx/net/uip/uip-arp.h deleted file mode 100644 index ba704cc13..000000000 --- a/nuttx/include/nuttx/net/uip/uip-arp.h +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** - * include/nuttx/net/uip/uip-arch.h - * Macros and definitions for the ARP module. - * - * Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Derived from uIP with has a similar BSD-styple license: - * - * Author: Adam Dunkels - * Copyright (c) 2001-2003, Adam Dunkels. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_NET_UIP_UIP_ARP_H -#define __INCLUDE_NUTTX_NET_UIP_UIP_ARP_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -#include - -#include -#include -#include - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/* Recognized values of the type bytes in the Ethernet header */ - -#define UIP_ETHTYPE_ARP 0x0806 -#define UIP_ETHTYPE_IP 0x0800 -#define UIP_ETHTYPE_IP6 0x86dd - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* The Ethernet header -- 14 bytes. The first two fields are type 'struct - * ether_addr but are represented as a simple byte array here because - * some compilers refuse to pack 6 byte structures. - */ - -struct uip_eth_hdr -{ - uint8_t dest[6]; /* Ethernet destination address (6 bytes) */ - uint8_t src[6]; /* Ethernet source address (6 bytes) */ - uint16_t type; /* Type code (2 bytes) */ -}; - -/* One entry in the ARP table (volatile!) */ - -struct arp_entry -{ - in_addr_t at_ipaddr; /* IP address */ - struct ether_addr at_ethaddr; /* Hardware address */ - uint8_t at_time; -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_NET_ARP -/**************************************************************************** - * Name: uip_arp_init - * - * Description: - * Initialize the ARP module. This function must be called before any of - * the other ARP functions. - * - ****************************************************************************/ - -EXTERN void uip_arp_init(void); - -/**************************************************************************** - * Name: uip_arp_ipin - * - * Description: - * The uip_arp_ipin() function should be called whenever an IP packet - * arrives from the Ethernet. This function refreshes the ARP table or - * inserts a new mapping if none exists. The function assumes that an - * IP packet with an Ethernet header is present in the d_buf buffer - * and that the length of the packet is in the d_len field. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_ARP_IPIN -EXTERN void uip_arp_ipin(struct uip_driver_s *dev); -#else -# define uip_arp_ipin(dev) -#endif - -/**************************************************************************** - * Name: uip_arp_arpin - * - * Description: - * The uip_arp_arpin() should be called when an ARP packet is received - * by the Ethernet driver. This function also assumes that the - * Ethernet frame is present in the d_buf buffer. When the - * uip_arp_arpin() function returns, the contents of the d_buf - * buffer should be sent out on the Ethernet if the d_len field - * is > 0. - * - ****************************************************************************/ - -EXTERN void uip_arp_arpin(struct uip_driver_s *dev); - -/**************************************************************************** - * Name: uip_arp_arpin - * - * Description: - * The uip_arp_out() function should be called when an IP packet - * should be sent out on the Ethernet. This function creates an - * Ethernet header before the IP header in the d_buf buffer. The - * Ethernet header will have the correct Ethernet MAC destination - * address filled in if an ARP table entry for the destination IP - * address (or the IP address of the default router) is present. If no - * such table entry is found, the IP packet is overwritten with an ARP - * request and we rely on TCP to retransmit the packet that was - * overwritten. In any case, the d_len field holds the length of - * the Ethernet frame that should be transmitted. - * - ****************************************************************************/ - -EXTERN void uip_arp_out(struct uip_driver_s *dev); - -/**************************************************************************** - * Name: uip_arp_timer - * - * Description: - * This function performs periodic timer processing in the ARP module - * and should be called at regular intervals. The recommended interval - * is 10 seconds between the calls. It is responsible for flushing old - * entries in the ARP table. - * - ****************************************************************************/ - -EXTERN void uip_arp_timer(void); - -/**************************************************************************** - * Name: uip_arp_update - * - * Description: - * Add the IP/HW address mapping to the ARP table -OR- change the IP - * address of an existing association. - * - * Input parameters: - * pipaddr - Refers to an IP address uint16_t[2] in network order - * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] - * - * Assumptions - * Interrupts are disabled - * - ****************************************************************************/ - -EXTERN void uip_arp_update(uint16_t *pipaddr, uint8_t *ethaddr); - -/**************************************************************************** - * Name: uip_arp_find - * - * Description: - * Find the ARP entry corresponding to this IP address. - * - * Input parameters: - * ipaddr - Refers to an IP address in network order - * - * Assumptions - * Interrupts are disabled; Returned value will become unstable when - * interrupts are re-enabled or if any other uIP APIs are called. - * - ****************************************************************************/ - -EXTERN struct arp_entry *uip_arp_find(in_addr_t ipaddr); - -/**************************************************************************** - * Name: uip_arp_delete - * - * Description: - * Remove an IP association from the ARP table - * - * Input parameters: - * ipaddr - Refers to an IP address in network order - * - * Assumptions - * Interrupts are disabled - * - ****************************************************************************/ - -#define uip_arp_delete(ipaddr) \ -{ \ - struct arp_entry *tabptr = uip_arp_find(ipaddr); \ - if (tabptr) \ - { \ - tabptr->at_ipaddr = 0; \ - } \ -} - -#else /* CONFIG_NET_ARP */ - -/* If ARP is disabled, stub out all ARP interfaces */ - -# define uip_arp_init() -# define uip_arp_ipin(dev) -# define uip_arp_arpin(dev) -# define uip_arp_out(dev) -# define uip_arp_timer() -# define uip_arp_update(pipaddr,ethaddr) -# define uip_arp_find(ipaddr) NULL -# define uip_arp_delete(ipaddr) - -#endif /* CONFIG_NET_ARP */ - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __INCLUDE_NUTTX_NET_UIP_UIP_ARP_H */ diff --git a/nuttx/net/arp/arp_inout.c b/nuttx/net/arp/arp_inout.c new file mode 100644 index 000000000..78bebae6d --- /dev/null +++ b/nuttx/net/arp/arp_inout.c @@ -0,0 +1,444 @@ +/**************************************************************************** + * net/arp/arm_inout.c + * Implementation of the ARP Address Resolution Protocol. + * + * Copyright (C) 2007-2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based on uIP which also has a BSD style license: + * + * Author: Adam Dunkels + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* The Address Resolution Protocol ARP is used for mapping between IP + * addresses and link level addresses such as the Ethernet MAC + * addresses. ARP uses broadcast queries to ask for the link level + * address of a known IP address and the host which is configured with + * the IP address for which the query was meant, will respond with its + * link level address. + * + * Note: This ARP implementation only supports Ethernet. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#ifdef CONFIG_NET + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#ifdef CONFIG_NET_ARP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ARP_REQUEST 1 +#define ARP_REPLY 2 + +#define ARP_HWTYPE_ETH 1 + +#define RASIZE 4 /* Size of ROUTER ALERT */ + +#define ETHBUF ((struct uip_eth_hdr *)&dev->d_buf[0]) +#define ARPBUF ((struct arp_hdr_s *)&dev->d_buf[UIP_LLH_LEN]) +#define IPBUF ((struct arp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* ARP header -- Size 28 bytes */ + +struct arp_hdr_s +{ + uint16_t ah_hwtype; /* 16-bit Hardware type (Ethernet=0x001) */ + uint16_t ah_protocol; /* 16-bit Protocol type (IP=0x0800) */ + uint8_t ah_hwlen; /* 8-bit Hardware address size (6) */ + uint8_t ah_protolen; /* 8-bit Procotol address size (4) */ + uint16_t ah_opcode; /* 16-bit Operation */ + uint8_t ah_shwaddr[6]; /* 48-bit Sender hardware address */ + uint16_t ah_sipaddr[2]; /* 32-bit Sender IP adress */ + uint8_t ah_dhwaddr[6]; /* 48-bit Target hardware address */ + uint16_t ah_dipaddr[2]; /* 32-bit Target IP address */ +}; + +/* IP header -- Size 20 or 24 bytes */ + +struct arp_iphdr_s +{ + uint8_t eh_vhl; /* 8-bit Version (4) and header length (5 or 6) */ + uint8_t eh_tos; /* 8-bit Type of service (e.g., 6=TCP) */ + uint8_t eh_len[2]; /* 16-bit Total length */ + uint8_t eh_ipid[2]; /* 16-bit Identification */ + uint8_t eh_ipoffset[2]; /* 16-bit IP flags + fragment offset */ + uint8_t eh_ttl; /* 8-bit Time to Live */ + uint8_t eh_proto; /* 8-bit Protocol */ + uint16_t eh_ipchksum; /* 16-bit Header checksum */ + uint16_t eh_srcipaddr[2]; /* 32-bit Source IP address */ + uint16_t eh_destipaddr[2]; /* 32-bit Destination IP address */ + uint16_t eh_ipoption[2]; /* (optional) */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Support for broadcast address */ + +static const struct ether_addr g_broadcast_ethaddr = + {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +static const uint16_t g_broadcast_ipaddr[2] = {0xffff, 0xffff}; + +/* Support for IGMP multicast addresses. + * + * Well-known ethernet multicast address: + * + * ADDRESS TYPE USAGE + * 01-00-0c-cc-cc-cc 0x0802 CDP (Cisco Discovery Protocol), VTP (Virtual Trunking Protocol) + * 01-00-0c-cc-cc-cd 0x0802 Cisco Shared Spanning Tree Protocol Address + * 01-80-c2-00-00-00 0x0802 Spanning Tree Protocol (for bridges) IEEE 802.1D + * 01-80-c2-00-00-02 0x0809 Ethernet OAM Protocol IEEE 802.3ah + * 01-00-5e-xx-xx-xx 0x0800 IPv4 IGMP Multicast Address + * 33-33-00-00-00-00 0x86DD IPv6 Neighbor Discovery + * 33-33-xx-xx-xx-xx 0x86DD IPv6 Multicast Address (RFC3307) + * + * The following is the first three octects of the IGMP address: + */ + +#if defined(CONFIG_NET_IGMP) && !defined(CONFIG_NET_IPv6) +static const uint8_t g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#if defined(CONFIG_NET_DUMPARP) && defined(CONFIG_DEBUG) +static void arp_dump(struct arp_hdr_s *arp) +{ + nlldbg(" HW type: %04x Protocol: %04x\n", + arp->ah_hwtype, arp->ah_protocol);\ + nlldbg(" HW len: %02x Proto len: %02x Operation: %04x\n", + arp->ah_hwlen, arp->ah_protolen, arp->ah_opcode); + nlldbg(" Sender MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", + arp->ah_shwaddr[0], arp->ah_shwaddr[1], arp->ah_shwaddr[2], + arp->ah_shwaddr[3], arp->ah_shwaddr[4], arp->ah_shwaddr[5], + arp->ah_sipaddr[0] & 0xff, arp->ah_sipaddr[0] >> 8, + arp->ah_sipaddr[1] & 0xff, arp->ah_sipaddr[1] >> 8); + nlldbg(" Dest MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", + arp->ah_dhwaddr[0], arp->ah_dhwaddr[1], arp->ah_dhwaddr[2], + arp->ah_dhwaddr[3], arp->ah_dhwaddr[4], arp->ah_dhwaddr[5], + arp->ah_dipaddr[0] & 0xff, arp->ah_dipaddr[0] >> 8, + arp->ah_dipaddr[1] & 0xff, arp->ah_dipaddr[1] >> 8); +} +#else +# define arp_dump(arp) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/* ARP processing for incoming IP packets + * + * This function should be called by the device driver when an IP packet has + * been received. The function will check if the address is in the ARP cache, + * and if so the ARP cache entry will be refreshed. If no ARP cache entry was + * found, a new one is created. + * + * This function expects an IP packet with a prepended Ethernet header in the + * d_buf[] buffer, and the length of the packet in the variable d_len. + */ + +#ifdef CONFIG_NET_ARP_IPIN +void arp_ipin(struct uip_driver_s *dev) +{ + in_addr_t srcipaddr; + + /* Only insert/update an entry if the source IP address of the incoming IP + * packet comes from a host on the local network. + */ + + srcipaddr = uip_ip4addr_conv(IPBUF->eh_srcipaddr); + if (uip_ipaddr_maskcmp(srcipaddr, dev->d_ipaddr, dev->d_netmask)) + { + arp_update(IPBUF->eh_srcipaddr, ETHBUF->src); + } +} +#endif /* CONFIG_NET_ARP_IPIN */ + +/* ARP processing for incoming ARP packets. + * + * This function should be called by the device driver when an ARP + * packet has been received. The function will act differently + * depending on the ARP packet type: if it is a reply for a request + * that we previously sent out, the ARP cache will be filled in with + * the values from the ARP reply. If the incoming ARP packet is an ARP + * request for our IP address, an ARP reply packet is created and put + * into the d_buf[] buffer. + * + * When the function returns, the value of the field d_len + * indicates whether the device driver should send out a packet or + * not. If d_len is zero, no packet should be sent. If d_len is + * non-zero, it contains the length of the outbound packet that is + * present in the d_buf[] buffer. + * + * This function expects an ARP packet with a prepended Ethernet + * header in the d_buf[] buffer, and the length of the packet in the + * variable d_len. + */ + +void arp_arpin(struct uip_driver_s *dev) +{ + struct arp_hdr_s *parp = ARPBUF; + in_addr_t ipaddr; + + if (dev->d_len < (sizeof(struct arp_hdr_s) + UIP_LLH_LEN)) + { + nlldbg("Too small\n"); + dev->d_len = 0; + return; + } + + dev->d_len = 0; + + ipaddr = uip_ip4addr_conv(parp->ah_dipaddr); + switch(parp->ah_opcode) + { + case HTONS(ARP_REQUEST): + nllvdbg("ARP request for IP %04lx\n", (long)ipaddr); + + /* ARP request. If it asked for our address, we send out a reply. */ + + if (uip_ipaddr_cmp(ipaddr, dev->d_ipaddr)) + { + struct uip_eth_hdr *peth = ETHBUF; + + /* First, we register the one who made the request in our ARP + * table, since it is likely that we will do more communication + * with this host in the future. + */ + + arp_update(parp->ah_sipaddr, parp->ah_shwaddr); + + parp->ah_opcode = HTONS(ARP_REPLY); + memcpy(parp->ah_dhwaddr, parp->ah_shwaddr, ETHER_ADDR_LEN); + memcpy(parp->ah_shwaddr, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); + memcpy(peth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); + memcpy(peth->dest, parp->ah_dhwaddr, ETHER_ADDR_LEN); + + parp->ah_dipaddr[0] = parp->ah_sipaddr[0]; + parp->ah_dipaddr[1] = parp->ah_sipaddr[1]; + uiphdr_ipaddr_copy(parp->ah_sipaddr, &dev->d_ipaddr); + arp_dump(parp); + + peth->type = HTONS(UIP_ETHTYPE_ARP); + dev->d_len = sizeof(struct arp_hdr_s) + UIP_LLH_LEN; + } + break; + + case HTONS(ARP_REPLY): + nllvdbg("ARP reply for IP %04lx\n", (long)ipaddr); + + /* ARP reply. We insert or update the ARP table if it was meant + * for us. + */ + + if (uip_ipaddr_cmp(ipaddr, dev->d_ipaddr)) + { + arp_update(parp->ah_sipaddr, parp->ah_shwaddr); + } + break; + } +} + +/* Prepend Ethernet header to an outbound IP packet and see if we need + * to send out an ARP request. + * + * This function should be called before sending out an IP packet. The + * function checks the destination IP address of the IP packet to see + * what Ethernet MAC address that should be used as a destination MAC + * address on the Ethernet. + * + * If the destination IP address is in the local network (determined + * by logical ANDing of netmask and our IP address), the function + * checks the ARP cache to see if an entry for the destination IP + * address is found. If so, an Ethernet header is prepended and the + * function returns. If no ARP cache entry is found for the + * destination IP address, the packet in the d_buf[] is replaced by + * an ARP request packet for the IP address. The IP packet is dropped + * and it is assumed that they higher level protocols (e.g., TCP) + * eventually will retransmit the dropped packet. + * + * If the destination IP address is not on the local network, the IP + * address of the default router is used instead. + * + * When the function returns, a packet is present in the d_buf[] + * buffer, and the length of the packet is in the field d_len. + */ + +void arp_out(struct uip_driver_s *dev) +{ + const struct arp_entry *tabptr = NULL; + struct arp_hdr_s *parp = ARPBUF; + struct uip_eth_hdr *peth = ETHBUF; + struct arp_iphdr_s *pip = IPBUF; + in_addr_t ipaddr; + in_addr_t destipaddr; + + /* Find the destination IP address in the ARP table and construct + * the Ethernet header. If the destination IP address isn't on the + * local network, we use the default router's IP address instead. + * + * If not ARP table entry is found, we overwrite the original IP + * packet with an ARP request for the IP address. + */ + + /* First check if destination is a local broadcast. */ + + if (uiphdr_ipaddr_cmp(pip->eh_destipaddr, g_broadcast_ipaddr)) + { + memcpy(peth->dest, g_broadcast_ethaddr.ether_addr_octet, ETHER_ADDR_LEN); + } + +#if defined(CONFIG_NET_IGMP) && !defined(CONFIG_NET_IPv6) + /* Check if the destination address is a multicast address + * + * - IPv4: multicast addresses lie in the class D group -- The address range + * 224.0.0.0 to 239.255.255.255 (224.0.0.0/4) + * + * - IPv6 multicast addresses are have the high-order octet of the + * addresses=0xff (ff00::/8.) + */ + + else if (NTOHS(pip->eh_destipaddr[0]) >= 0xe000 && + NTOHS(pip->eh_destipaddr[0]) <= 0xefff) + { + /* Build the well-known IPv4 IGMP Ethernet address. The first + * three bytes are fixed; the final three variable come from the + * last three bytes of the IP address. + */ + + const uint8_t *ip = ((uint8_t*)pip->eh_destipaddr) + 1; + memcpy(peth->dest, g_multicast_ethaddr, 3); + memcpy(&peth->dest[3], ip, 3); + } +#endif + else + { + /* Check if the destination address is on the local network. */ + + destipaddr = uip_ip4addr_conv(pip->eh_destipaddr); + if (!uip_ipaddr_maskcmp(destipaddr, dev->d_ipaddr, dev->d_netmask)) + { + /* Destination address is not on the local network */ + +#ifdef CONFIG_NET_ROUTE + /* We have a routing table.. find the correct router to use in + * this case (or, as a fall-back, use the device's default router + * address). We will use the router IP address instead of the + * destination address when determining the MAC address. + */ + + netdev_router(dev, destipaddr, &ipaddr); +#else + /* Use the device's default router IP address instead of the + * destination address when determining the MAC address. + */ + + uip_ipaddr_copy(ipaddr, dev->d_draddr); +#endif + } + else + { + /* Else, we use the destination IP address. */ + + uip_ipaddr_copy(ipaddr, destipaddr); + } + + /* Check if we already have this destination address in the ARP table */ + + tabptr = arp_find(ipaddr); + if (!tabptr) + { + nllvdbg("ARP request for IP %04lx\n", (long)ipaddr); + + /* The destination address was not in our ARP table, so we + * overwrite the IP packet with an ARP request. + */ + + memset(peth->dest, 0xff, ETHER_ADDR_LEN); + memset(parp->ah_dhwaddr, 0x00, ETHER_ADDR_LEN); + memcpy(peth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); + memcpy(parp->ah_shwaddr, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); + + uiphdr_ipaddr_copy(parp->ah_dipaddr, &ipaddr); + uiphdr_ipaddr_copy(parp->ah_sipaddr, &dev->d_ipaddr); + + parp->ah_opcode = HTONS(ARP_REQUEST); + parp->ah_hwtype = HTONS(ARP_HWTYPE_ETH); + parp->ah_protocol = HTONS(UIP_ETHTYPE_IP); + parp->ah_hwlen = ETHER_ADDR_LEN; + parp->ah_protolen = 4; + arp_dump(parp); + + peth->type = HTONS(UIP_ETHTYPE_ARP); + dev->d_len = sizeof(struct arp_hdr_s) + UIP_LLH_LEN; + return; + } + + /* Build an Ethernet header. */ + + memcpy(peth->dest, tabptr->at_ethaddr.ether_addr_octet, ETHER_ADDR_LEN); + } + + /* Finish populating the Ethernet header */ + + memcpy(peth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); + peth->type = HTONS(UIP_ETHTYPE_IP); + dev->d_len += UIP_LLH_LEN; +} + +#endif /* CONFIG_NET_ARP */ +#endif /* CONFIG_NET */ diff --git a/nuttx/net/arp/arp_table.c b/nuttx/net/arp/arp_table.c new file mode 100644 index 000000000..b4d7ac684 --- /dev/null +++ b/nuttx/net/arp/arp_table.c @@ -0,0 +1,260 @@ +/**************************************************************************** + * net/arp/arp_table.c + * Implementation of the ARP Address Resolution Protocol. + * + * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based originally on uIP which also has a BSD style license: + * + * Author: Adam Dunkels + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#ifdef CONFIG_NET + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#ifdef CONFIG_NET_ARP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* The table of known address mappings */ + +static struct arp_entry g_arptable[CONFIG_NET_ARPTAB_SIZE]; +static uint8_t g_arptime; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arp_init + * + * Description: + * Initialize the ARP module. This function must be called before any of + * the other ARP functions. + * + ****************************************************************************/ + +void arp_init(void) +{ + int i; + for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) + { + memset(&g_arptable[i].at_ipaddr, 0, sizeof(in_addr_t)); + } +} + +/**************************************************************************** + * Name: arp_timer + * + * Description: + * This function performs periodic timer processing in the ARP module + * and should be called at regular intervals. The recommended interval + * is 10 seconds between the calls. It is responsible for flushing old + * entries in the ARP table. + * + ****************************************************************************/ + +void arp_timer(void) +{ + struct arp_entry *tabptr; + int i; + + ++g_arptime; + for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) + { + tabptr = &g_arptable[i]; + if (tabptr->at_ipaddr != 0 && g_arptime - tabptr->at_time >= UIP_ARP_MAXAGE) + { + tabptr->at_ipaddr = 0; + } + } +} + +/**************************************************************************** + * Name: arp_update + * + * Description: + * Add the IP/HW address mapping to the ARP table -OR- change the IP + * address of an existing association. + * + * Input parameters: + * pipaddr - Refers to an IP address uint16_t[2] + * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] + * + * Assumptions + * Interrupts are disabled + * + ****************************************************************************/ + +void arp_update(uint16_t *pipaddr, uint8_t *ethaddr) +{ + struct arp_entry *tabptr = NULL; + in_addr_t ipaddr = uip_ip4addr_conv(pipaddr); + int i; + + /* Walk through the ARP mapping table and try to find an entry to + * update. If none is found, the IP -> MAC address mapping is + * inserted in the ARP table. + */ + + for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) + { + tabptr = &g_arptable[i]; + + /* Only check those entries that are actually in use. */ + + if (tabptr->at_ipaddr != 0) + { + /* Check if the source IP address of the incoming packet matches + * the IP address in this ARP table entry. + */ + + if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr)) + { + /* An old entry found, update this and return. */ + + memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); + tabptr->at_time = g_arptime; + return; + } + } + } + + /* If we get here, no existing ARP table entry was found, so we create one. */ + + /* First, we try to find an unused entry in the ARP table. */ + + for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) + { + tabptr = &g_arptable[i]; + if (tabptr->at_ipaddr == 0) + { + break; + } + } + + /* If no unused entry is found, we try to find the oldest entry and + * throw it away. + */ + + if (i == CONFIG_NET_ARPTAB_SIZE) + { + uint8_t tmpage = 0; + int j = 0; + + for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) + { + tabptr = &g_arptable[i]; + if (g_arptime - tabptr->at_time > tmpage) + { + tmpage = g_arptime - tabptr->at_time; + j = i; + } + } + + i = j; + tabptr = &g_arptable[i]; + } + + /* Now, i is the ARP table entry which we will fill with the new + * information. + */ + + tabptr->at_ipaddr = ipaddr; + memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); + tabptr->at_time = g_arptime; +} + +/**************************************************************************** + * Name: arp_find + * + * Description: + * Find the ARP entry corresponding to this IP address. + * + * Input parameters: + * ipaddr - Refers to an IP address in network order + * + * Assumptions + * Interrupts are disabled; Returned value will become unstable when + * interrupts are re-enabled or if any other uIP APIs are called. + * + ****************************************************************************/ + +struct arp_entry *arp_find(in_addr_t ipaddr) +{ + struct arp_entry *tabptr; + int i; + + for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) + { + tabptr = &g_arptable[i]; + if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr)) + { + return tabptr; + } + } + + return NULL; +} + +#endif /* CONFIG_NET_ARP */ +#endif /* CONFIG_NET */ diff --git a/nuttx/net/arp/arp_timer.c b/nuttx/net/arp/arp_timer.c new file mode 100644 index 000000000..d6f105ac1 --- /dev/null +++ b/nuttx/net/arp/arp_timer.c @@ -0,0 +1,134 @@ +/**************************************************************************** + * net/arp/arp_timer.c + * + * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#ifdef CONFIG_NET + +#include +#include +#include +#include + +#include +#include + +#include "net_internal.h" + +#ifdef CONFIG_NET_ARP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* ARP timer interval = 10 seconds. CLK_TCK is the number of clock ticks + * per second + */ + +#define ARPTIMER_WDINTERVAL (10*CLK_TCK) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static WDOG_ID g_arptimer; /* ARP timer */ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: arptimer_poll + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void arptimer_poll(int argc, uint32_t arg, ...) +{ + /* Call the ARP timer function every 10 seconds. */ + + arp_timer(); + + /* Setup the watchdog timer again */ + + (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: arp_timer_init + * + * Description: + * Initialized the 10 second timer that is need by uIP to age ARP + * associations + * + * Parameters: + * None + * + * Returned Value: + * None + * + * Assumptions: + * Called once at system initialization time + * + ****************************************************************************/ + +void arp_timer_init(void) +{ + /* Create and start the ARP timer */ + + g_arptimer = wd_create(); + (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); +} + +#endif /* CONFIG_NET_ARP */ +#endif /* CONFIG_NET */ diff --git a/nuttx/net/arp/uip_arp.c b/nuttx/net/arp/uip_arp.c deleted file mode 100644 index a58a1560a..000000000 --- a/nuttx/net/arp/uip_arp.c +++ /dev/null @@ -1,444 +0,0 @@ -/**************************************************************************** - * net/arp/uip_arp.c - * Implementation of the ARP Address Resolution Protocol. - * - * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Based on uIP which also has a BSD style license: - * - * Author: Adam Dunkels - * Copyright (c) 2001-2003, Adam Dunkels. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/* The Address Resolution Protocol ARP is used for mapping between IP - * addresses and link level addresses such as the Ethernet MAC - * addresses. ARP uses broadcast queries to ask for the link level - * address of a known IP address and the host which is configured with - * the IP address for which the query was meant, will respond with its - * link level address. - * - * Note: This ARP implementation only supports Ethernet. - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#ifdef CONFIG_NET - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#ifdef CONFIG_NET_ARP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ARP_REQUEST 1 -#define ARP_REPLY 2 - -#define ARP_HWTYPE_ETH 1 - -#define RASIZE 4 /* Size of ROUTER ALERT */ - -#define ETHBUF ((struct uip_eth_hdr *)&dev->d_buf[0]) -#define ARPBUF ((struct arp_hdr_s *)&dev->d_buf[UIP_LLH_LEN]) -#define IPBUF ((struct arp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* ARP header -- Size 28 bytes */ - -struct arp_hdr_s -{ - uint16_t ah_hwtype; /* 16-bit Hardware type (Ethernet=0x001) */ - uint16_t ah_protocol; /* 16-bit Protocol type (IP=0x0800) */ - uint8_t ah_hwlen; /* 8-bit Hardware address size (6) */ - uint8_t ah_protolen; /* 8-bit Procotol address size (4) */ - uint16_t ah_opcode; /* 16-bit Operation */ - uint8_t ah_shwaddr[6]; /* 48-bit Sender hardware address */ - uint16_t ah_sipaddr[2]; /* 32-bit Sender IP adress */ - uint8_t ah_dhwaddr[6]; /* 48-bit Target hardware address */ - uint16_t ah_dipaddr[2]; /* 32-bit Target IP address */ -}; - -/* IP header -- Size 20 or 24 bytes */ - -struct arp_iphdr_s -{ - uint8_t eh_vhl; /* 8-bit Version (4) and header length (5 or 6) */ - uint8_t eh_tos; /* 8-bit Type of service (e.g., 6=TCP) */ - uint8_t eh_len[2]; /* 16-bit Total length */ - uint8_t eh_ipid[2]; /* 16-bit Identification */ - uint8_t eh_ipoffset[2]; /* 16-bit IP flags + fragment offset */ - uint8_t eh_ttl; /* 8-bit Time to Live */ - uint8_t eh_proto; /* 8-bit Protocol */ - uint16_t eh_ipchksum; /* 16-bit Header checksum */ - uint16_t eh_srcipaddr[2]; /* 32-bit Source IP address */ - uint16_t eh_destipaddr[2]; /* 32-bit Destination IP address */ - uint16_t eh_ipoption[2]; /* (optional) */ -}; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Support for broadcast address */ - -static const struct ether_addr g_broadcast_ethaddr = - {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -static const uint16_t g_broadcast_ipaddr[2] = {0xffff, 0xffff}; - -/* Support for IGMP multicast addresses. - * - * Well-known ethernet multicast address: - * - * ADDRESS TYPE USAGE - * 01-00-0c-cc-cc-cc 0x0802 CDP (Cisco Discovery Protocol), VTP (Virtual Trunking Protocol) - * 01-00-0c-cc-cc-cd 0x0802 Cisco Shared Spanning Tree Protocol Address - * 01-80-c2-00-00-00 0x0802 Spanning Tree Protocol (for bridges) IEEE 802.1D - * 01-80-c2-00-00-02 0x0809 Ethernet OAM Protocol IEEE 802.3ah - * 01-00-5e-xx-xx-xx 0x0800 IPv4 IGMP Multicast Address - * 33-33-00-00-00-00 0x86DD IPv6 Neighbor Discovery - * 33-33-xx-xx-xx-xx 0x86DD IPv6 Multicast Address (RFC3307) - * - * The following is the first three octects of the IGMP address: - */ - -#if defined(CONFIG_NET_IGMP) && !defined(CONFIG_NET_IPv6) -static const uint8_t g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e}; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -#if defined(CONFIG_NET_DUMPARP) && defined(CONFIG_DEBUG) -static void uip_arp_dump(struct arp_hdr_s *arp) -{ - nlldbg(" HW type: %04x Protocol: %04x\n", - arp->ah_hwtype, arp->ah_protocol);\ - nlldbg(" HW len: %02x Proto len: %02x Operation: %04x\n", - arp->ah_hwlen, arp->ah_protolen, arp->ah_opcode); - nlldbg(" Sender MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", - arp->ah_shwaddr[0], arp->ah_shwaddr[1], arp->ah_shwaddr[2], - arp->ah_shwaddr[3], arp->ah_shwaddr[4], arp->ah_shwaddr[5], - arp->ah_sipaddr[0] & 0xff, arp->ah_sipaddr[0] >> 8, - arp->ah_sipaddr[1] & 0xff, arp->ah_sipaddr[1] >> 8); - nlldbg(" Dest MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", - arp->ah_dhwaddr[0], arp->ah_dhwaddr[1], arp->ah_dhwaddr[2], - arp->ah_dhwaddr[3], arp->ah_dhwaddr[4], arp->ah_dhwaddr[5], - arp->ah_dipaddr[0] & 0xff, arp->ah_dipaddr[0] >> 8, - arp->ah_dipaddr[1] & 0xff, arp->ah_dipaddr[1] >> 8); -} -#else -# define uip_arp_dump(arp) -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* ARP processing for incoming IP packets - * - * This function should be called by the device driver when an IP packet has - * been received. The function will check if the address is in the ARP cache, - * and if so the ARP cache entry will be refreshed. If no ARP cache entry was - * found, a new one is created. - * - * This function expects an IP packet with a prepended Ethernet header in the - * d_buf[] buffer, and the length of the packet in the variable d_len. - */ - -#ifdef CONFIG_NET_ARP_IPIN -void uip_arp_ipin(struct uip_driver_s *dev) -{ - in_addr_t srcipaddr; - - /* Only insert/update an entry if the source IP address of the incoming IP - * packet comes from a host on the local network. - */ - - srcipaddr = uip_ip4addr_conv(IPBUF->eh_srcipaddr); - if (uip_ipaddr_maskcmp(srcipaddr, dev->d_ipaddr, dev->d_netmask)) - { - uip_arp_update(IPBUF->eh_srcipaddr, ETHBUF->src); - } -} -#endif /* CONFIG_NET_ARP_IPIN */ - -/* ARP processing for incoming ARP packets. - * - * This function should be called by the device driver when an ARP - * packet has been received. The function will act differently - * depending on the ARP packet type: if it is a reply for a request - * that we previously sent out, the ARP cache will be filled in with - * the values from the ARP reply. If the incoming ARP packet is an ARP - * request for our IP address, an ARP reply packet is created and put - * into the d_buf[] buffer. - * - * When the function returns, the value of the field d_len - * indicates whether the device driver should send out a packet or - * not. If d_len is zero, no packet should be sent. If d_len is - * non-zero, it contains the length of the outbound packet that is - * present in the d_buf[] buffer. - * - * This function expects an ARP packet with a prepended Ethernet - * header in the d_buf[] buffer, and the length of the packet in the - * variable d_len. - */ - -void uip_arp_arpin(struct uip_driver_s *dev) -{ - struct arp_hdr_s *parp = ARPBUF; - in_addr_t ipaddr; - - if (dev->d_len < (sizeof(struct arp_hdr_s) + UIP_LLH_LEN)) - { - nlldbg("Too small\n"); - dev->d_len = 0; - return; - } - - dev->d_len = 0; - - ipaddr = uip_ip4addr_conv(parp->ah_dipaddr); - switch(parp->ah_opcode) - { - case HTONS(ARP_REQUEST): - nllvdbg("ARP request for IP %04lx\n", (long)ipaddr); - - /* ARP request. If it asked for our address, we send out a reply. */ - - if (uip_ipaddr_cmp(ipaddr, dev->d_ipaddr)) - { - struct uip_eth_hdr *peth = ETHBUF; - - /* First, we register the one who made the request in our ARP - * table, since it is likely that we will do more communication - * with this host in the future. - */ - - uip_arp_update(parp->ah_sipaddr, parp->ah_shwaddr); - - parp->ah_opcode = HTONS(ARP_REPLY); - memcpy(parp->ah_dhwaddr, parp->ah_shwaddr, ETHER_ADDR_LEN); - memcpy(parp->ah_shwaddr, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); - memcpy(peth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); - memcpy(peth->dest, parp->ah_dhwaddr, ETHER_ADDR_LEN); - - parp->ah_dipaddr[0] = parp->ah_sipaddr[0]; - parp->ah_dipaddr[1] = parp->ah_sipaddr[1]; - uiphdr_ipaddr_copy(parp->ah_sipaddr, &dev->d_ipaddr); - uip_arp_dump(parp); - - peth->type = HTONS(UIP_ETHTYPE_ARP); - dev->d_len = sizeof(struct arp_hdr_s) + UIP_LLH_LEN; - } - break; - - case HTONS(ARP_REPLY): - nllvdbg("ARP reply for IP %04lx\n", (long)ipaddr); - - /* ARP reply. We insert or update the ARP table if it was meant - * for us. - */ - - if (uip_ipaddr_cmp(ipaddr, dev->d_ipaddr)) - { - uip_arp_update(parp->ah_sipaddr, parp->ah_shwaddr); - } - break; - } -} - -/* Prepend Ethernet header to an outbound IP packet and see if we need - * to send out an ARP request. - * - * This function should be called before sending out an IP packet. The - * function checks the destination IP address of the IP packet to see - * what Ethernet MAC address that should be used as a destination MAC - * address on the Ethernet. - * - * If the destination IP address is in the local network (determined - * by logical ANDing of netmask and our IP address), the function - * checks the ARP cache to see if an entry for the destination IP - * address is found. If so, an Ethernet header is prepended and the - * function returns. If no ARP cache entry is found for the - * destination IP address, the packet in the d_buf[] is replaced by - * an ARP request packet for the IP address. The IP packet is dropped - * and it is assumed that they higher level protocols (e.g., TCP) - * eventually will retransmit the dropped packet. - * - * If the destination IP address is not on the local network, the IP - * address of the default router is used instead. - * - * When the function returns, a packet is present in the d_buf[] - * buffer, and the length of the packet is in the field d_len. - */ - -void uip_arp_out(struct uip_driver_s *dev) -{ - const struct arp_entry *tabptr = NULL; - struct arp_hdr_s *parp = ARPBUF; - struct uip_eth_hdr *peth = ETHBUF; - struct arp_iphdr_s *pip = IPBUF; - in_addr_t ipaddr; - in_addr_t destipaddr; - - /* Find the destination IP address in the ARP table and construct - * the Ethernet header. If the destination IP address isn't on the - * local network, we use the default router's IP address instead. - * - * If not ARP table entry is found, we overwrite the original IP - * packet with an ARP request for the IP address. - */ - - /* First check if destination is a local broadcast. */ - - if (uiphdr_ipaddr_cmp(pip->eh_destipaddr, g_broadcast_ipaddr)) - { - memcpy(peth->dest, g_broadcast_ethaddr.ether_addr_octet, ETHER_ADDR_LEN); - } - -#if defined(CONFIG_NET_IGMP) && !defined(CONFIG_NET_IPv6) - /* Check if the destination address is a multicast address - * - * - IPv4: multicast addresses lie in the class D group -- The address range - * 224.0.0.0 to 239.255.255.255 (224.0.0.0/4) - * - * - IPv6 multicast addresses are have the high-order octet of the - * addresses=0xff (ff00::/8.) - */ - - else if (NTOHS(pip->eh_destipaddr[0]) >= 0xe000 && - NTOHS(pip->eh_destipaddr[0]) <= 0xefff) - { - /* Build the well-known IPv4 IGMP Ethernet address. The first - * three bytes are fixed; the final three variable come from the - * last three bytes of the IP address. - */ - - const uint8_t *ip = ((uint8_t*)pip->eh_destipaddr) + 1; - memcpy(peth->dest, g_multicast_ethaddr, 3); - memcpy(&peth->dest[3], ip, 3); - } -#endif - else - { - /* Check if the destination address is on the local network. */ - - destipaddr = uip_ip4addr_conv(pip->eh_destipaddr); - if (!uip_ipaddr_maskcmp(destipaddr, dev->d_ipaddr, dev->d_netmask)) - { - /* Destination address is not on the local network */ - -#ifdef CONFIG_NET_ROUTE - /* We have a routing table.. find the correct router to use in - * this case (or, as a fall-back, use the device's default router - * address). We will use the router IP address instead of the - * destination address when determining the MAC address. - */ - - netdev_router(dev, destipaddr, &ipaddr); -#else - /* Use the device's default router IP address instead of the - * destination address when determining the MAC address. - */ - - uip_ipaddr_copy(ipaddr, dev->d_draddr); -#endif - } - else - { - /* Else, we use the destination IP address. */ - - uip_ipaddr_copy(ipaddr, destipaddr); - } - - /* Check if we already have this destination address in the ARP table */ - - tabptr = uip_arp_find(ipaddr); - if (!tabptr) - { - nllvdbg("ARP request for IP %04lx\n", (long)ipaddr); - - /* The destination address was not in our ARP table, so we - * overwrite the IP packet with an ARP request. - */ - - memset(peth->dest, 0xff, ETHER_ADDR_LEN); - memset(parp->ah_dhwaddr, 0x00, ETHER_ADDR_LEN); - memcpy(peth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); - memcpy(parp->ah_shwaddr, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); - - uiphdr_ipaddr_copy(parp->ah_dipaddr, &ipaddr); - uiphdr_ipaddr_copy(parp->ah_sipaddr, &dev->d_ipaddr); - - parp->ah_opcode = HTONS(ARP_REQUEST); - parp->ah_hwtype = HTONS(ARP_HWTYPE_ETH); - parp->ah_protocol = HTONS(UIP_ETHTYPE_IP); - parp->ah_hwlen = ETHER_ADDR_LEN; - parp->ah_protolen = 4; - uip_arp_dump(parp); - - peth->type = HTONS(UIP_ETHTYPE_ARP); - dev->d_len = sizeof(struct arp_hdr_s) + UIP_LLH_LEN; - return; - } - - /* Build an Ethernet header. */ - - memcpy(peth->dest, tabptr->at_ethaddr.ether_addr_octet, ETHER_ADDR_LEN); - } - - /* Finish populating the Ethernet header */ - - memcpy(peth->src, dev->d_mac.ether_addr_octet, ETHER_ADDR_LEN); - peth->type = HTONS(UIP_ETHTYPE_IP); - dev->d_len += UIP_LLH_LEN; -} - -#endif /* CONFIG_NET_ARP */ -#endif /* CONFIG_NET */ diff --git a/nuttx/net/arp/uip_arptab.c b/nuttx/net/arp/uip_arptab.c deleted file mode 100644 index 96a0f19b5..000000000 --- a/nuttx/net/arp/uip_arptab.c +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** - * net/arp/uip_arptab.c - * Implementation of the ARP Address Resolution Protocol. - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Based originally on uIP which also has a BSD style license: - * - * Author: Adam Dunkels - * Copyright (c) 2001-2003, Adam Dunkels. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#ifdef CONFIG_NET - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#ifdef CONFIG_NET_ARP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* The table of known address mappings */ - -static struct arp_entry g_arptable[CONFIG_NET_ARPTAB_SIZE]; -static uint8_t g_arptime; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_arp_init - * - * Description: - * Initialize the ARP module. This function must be called before any of - * the other ARP functions. - * - ****************************************************************************/ - -void uip_arp_init(void) -{ - int i; - for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) - { - memset(&g_arptable[i].at_ipaddr, 0, sizeof(in_addr_t)); - } -} - -/**************************************************************************** - * Name: uip_arp_timer - * - * Description: - * This function performs periodic timer processing in the ARP module - * and should be called at regular intervals. The recommended interval - * is 10 seconds between the calls. It is responsible for flushing old - * entries in the ARP table. - * - ****************************************************************************/ - -void uip_arp_timer(void) -{ - struct arp_entry *tabptr; - int i; - - ++g_arptime; - for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) - { - tabptr = &g_arptable[i]; - if (tabptr->at_ipaddr != 0 && g_arptime - tabptr->at_time >= UIP_ARP_MAXAGE) - { - tabptr->at_ipaddr = 0; - } - } -} - -/**************************************************************************** - * Name: uip_arp_update - * - * Description: - * Add the IP/HW address mapping to the ARP table -OR- change the IP - * address of an existing association. - * - * Input parameters: - * pipaddr - Refers to an IP address uint16_t[2] - * ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN] - * - * Assumptions - * Interrupts are disabled - * - ****************************************************************************/ - -void uip_arp_update(uint16_t *pipaddr, uint8_t *ethaddr) -{ - struct arp_entry *tabptr = NULL; - in_addr_t ipaddr = uip_ip4addr_conv(pipaddr); - int i; - - /* Walk through the ARP mapping table and try to find an entry to - * update. If none is found, the IP -> MAC address mapping is - * inserted in the ARP table. - */ - - for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) - { - tabptr = &g_arptable[i]; - - /* Only check those entries that are actually in use. */ - - if (tabptr->at_ipaddr != 0) - { - /* Check if the source IP address of the incoming packet matches - * the IP address in this ARP table entry. - */ - - if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr)) - { - /* An old entry found, update this and return. */ - - memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); - tabptr->at_time = g_arptime; - return; - } - } - } - - /* If we get here, no existing ARP table entry was found, so we create one. */ - - /* First, we try to find an unused entry in the ARP table. */ - - for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) - { - tabptr = &g_arptable[i]; - if (tabptr->at_ipaddr == 0) - { - break; - } - } - - /* If no unused entry is found, we try to find the oldest entry and - * throw it away. - */ - - if (i == CONFIG_NET_ARPTAB_SIZE) - { - uint8_t tmpage = 0; - int j = 0; - - for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) - { - tabptr = &g_arptable[i]; - if (g_arptime - tabptr->at_time > tmpage) - { - tmpage = g_arptime - tabptr->at_time; - j = i; - } - } - - i = j; - tabptr = &g_arptable[i]; - } - - /* Now, i is the ARP table entry which we will fill with the new - * information. - */ - - tabptr->at_ipaddr = ipaddr; - memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); - tabptr->at_time = g_arptime; -} - -/**************************************************************************** - * Name: uip_arp_find - * - * Description: - * Find the ARP entry corresponding to this IP address. - * - * Input parameters: - * ipaddr - Refers to an IP address in network order - * - * Assumptions - * Interrupts are disabled; Returned value will become unstable when - * interrupts are re-enabled or if any other uIP APIs are called. - * - ****************************************************************************/ - -struct arp_entry *uip_arp_find(in_addr_t ipaddr) -{ - struct arp_entry *tabptr; - int i; - - for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) - { - tabptr = &g_arptable[i]; - if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr)) - { - return tabptr; - } - } - - return NULL; -} - -#endif /* CONFIG_NET_ARP */ -#endif /* CONFIG_NET */ diff --git a/nuttx/net/net_arptimer.c b/nuttx/net/net_arptimer.c deleted file mode 100644 index 2c5d33c91..000000000 --- a/nuttx/net/net_arptimer.c +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** - * net/net_arptimer.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#ifdef CONFIG_NET - -#include -#include -#include -#include - -#include -#include - -#include "net_internal.h" - -#ifdef CONFIG_NET_ARP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* ARP timer interval = 10 seconds. CLK_TCK is the number of clock ticks - * per second - */ - -#define ARPTIMER_WDINTERVAL (10*CLK_TCK) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static WDOG_ID g_arptimer; /* ARP timer */ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: arptimer_poll - * - * Description: - * Periodic timer handler. Called from the timer interrupt handler. - * - * Parameters: - * argc - The number of available arguments - * arg - The first argument - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static void arptimer_poll(int argc, uint32_t arg, ...) -{ - /* Call the ARP timer function every 10 seconds. */ - - uip_arp_timer(); - - /* Setup the watchdog timer again */ - - (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: arptimer_init - * - * Description: - * Initialized the 10 second timer that is need by uIP to age ARP - * associations - * - * Parameters: - * None - * - * Returned Value: - * None - * - * Assumptions: - * Called once at system initialization time - * - ****************************************************************************/ - -void arptimer_init(void) -{ - /* Create and start the ARP timer */ - - g_arptimer = wd_create(); - (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0); -} - -#endif /* CONFIG_NET_ARP */ -#endif /* CONFIG_NET */ diff --git a/nuttx/net/net_internal.h b/nuttx/net/net_internal.h index abea7ccfe..d8691aaee 100644 --- a/nuttx/net/net_internal.h +++ b/nuttx/net/net_internal.h @@ -225,14 +225,6 @@ void netdev_rxnotify(const uip_ipaddr_t addr); int netdev_count(void); #endif -/* net_arptimer.c ************************************************************/ - -#ifdef CONFIG_NET_ARP -void arptimer_init(void); -#else -# define arptimer_init() -#endif - /* send.c ********************************************************************/ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, diff --git a/nuttx/net/net_send_buffered.c b/nuttx/net/net_send_buffered.c index c7263a675..f54079f39 100644 --- a/nuttx/net/net_send_buffered.c +++ b/nuttx/net/net_send_buffered.c @@ -56,13 +56,9 @@ #include #include -#include +#include #include -#ifdef CONFIG_NET_ARP_IPIN -# include -#endif - #include "net_internal.h" #include "uip/uip_internal.h" @@ -275,7 +271,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, */ #if defined(CONFIG_NET_ETHERNET) && !defined(CONFIG_NET_ARP_IPIN) - if (uip_arp_find(conn->ripaddr) != NULL) + if (arp_find(conn->ripaddr) != NULL) #endif { FAR struct uip_wrbuffer_s *segment; diff --git a/nuttx/net/net_send_unbuffered.c b/nuttx/net/net_send_unbuffered.c index 7d5a3e33a..db192d48f 100644 --- a/nuttx/net/net_send_unbuffered.c +++ b/nuttx/net/net_send_unbuffered.c @@ -52,13 +52,9 @@ #include #include -#include +#include #include -#ifdef CONFIG_NET_ARP_IPIN -# include -#endif - #include "net_internal.h" #include "uip/uip_internal.h" @@ -392,7 +388,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, */ #if defined(CONFIG_NET_ETHERNET) && !defined(CONFIG_NET_ARP_IPIN) - if (pstate->snd_sent != 0 || uip_arp_find(conn->ripaddr) != NULL) + if (pstate->snd_sent != 0 || arp_find(conn->ripaddr) != NULL) #endif { /* Update the amount of data sent (but not necessarily ACKed) */ diff --git a/nuttx/net/net_sendfile.c b/nuttx/net/net_sendfile.c index 81dbbada9..124336b73 100644 --- a/nuttx/net/net_sendfile.c +++ b/nuttx/net/net_sendfile.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include "net_internal.h" @@ -321,7 +321,7 @@ static uint16_t sendfile_interrupt(FAR struct uip_driver_s *dev, FAR void *pvcon */ #if defined(CONFIG_NET_ETHERNET) && !defined (CONFIG_NET_ARP_IPIN) - if (pstate->snd_sent != 0 || uip_arp_find(conn->ripaddr) != NULL) + if (pstate->snd_sent != 0 || arp_find(conn->ripaddr) != NULL) #endif { /* Update the amount of data sent (but not necessarily ACKed) */ diff --git a/nuttx/net/net_sockets.c b/nuttx/net/net_sockets.c index a81620a71..ae5463352 100644 --- a/nuttx/net/net_sockets.c +++ b/nuttx/net/net_sockets.c @@ -118,7 +118,7 @@ void net_initialize(void) /* Initialize the periodic ARP timer */ - arptimer_init(); + arp_timer_init(); } #if CONFIG_NSOCKET_DESCRIPTORS > 0 -- cgit v1.2.3