OSDN Git Service

uip_arpをNYLPC_CIPV4ARPへ分離
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Fri, 25 Jan 2013 09:24:15 +0000 (09:24 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Fri, 25 Jan 2013 09:24:15 +0000 (09:24 +0000)
git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@187 47198e57-cb75-475f-84c4-a814cd6f29e0

15 files changed:
lib/src/driver/uip/EtherDev_DP83848C.c
lib/src/driver/uip/EtherDev_DP83848C_protected.h
lib/src/driver/uip/EtherDev_LAN8720.c
lib/src/driver/uip/EtherDev_LAN8720_protected.h
lib/src/driver/uip/uip_arp.c [deleted file]
lib/src/driver/uip/uip_arp.h [deleted file]
lib/src/uip/NyLPC_cIPv4Arp.c
lib/src/uip/NyLPC_cIPv4Arp.h [new file with mode: 0644]
lib/src/uip/NyLPC_cUipService.c
lib/src/uip/NyLPC_cUipService.h
lib/src/uip/NyLPC_cUipService_protected.h
lib/src/uip/NyLPC_uip.c
lib/src/uip/NyLPC_uip.h
lib/src/uip/NyLPC_uip_ethernet.c
lib/src/uip/NyLPC_uip_ethernet.h

index ecd0032..2f0c2f8 100644 (file)
 #include "EtherDev_DP83848C_protected.h"\r
 #include "../os/NyLPC_cThread.h"\r
 \r
+#define DP83848C_ID         0x20005C90  /* PHY Identifier                    */\r
+\r
+/* DP83848C PHY Registers */\r
+#define PHY_REG_BMCR        0x00        /* Basic Mode Control Register       */\r
+#define PHY_REG_BMSR        0x01        /* Basic Mode Status Register        */\r
+#define PHY_REG_IDR1        0x02        /* PHY Identifier 1                  */\r
+#define PHY_REG_IDR2        0x03        /* PHY Identifier 2                  */\r
+#define PHY_REG_ANAR        0x04        /* Auto-Negotiation Advertisement    */\r
+#define PHY_REG_ANLPAR      0x05        /* Auto-Neg. Link Partner Abitily    */\r
+#define PHY_REG_ANER        0x06        /* Auto-Neg. Expansion Register      */\r
+#define PHY_REG_ANNPTR      0x07        /* Auto-Neg. Next Page TX            */\r
+\r
+/* PHY Extended Registers */\r
+#define PHY_REG_STS         0x10        /* Status Register                   */\r
+#define PHY_REG_MICR        0x11        /* MII Interrupt Control Register    */\r
+#define PHY_REG_MISR        0x12        /* MII Interrupt Status Register     */\r
+#define PHY_REG_FCSCR       0x14        /* False Carrier Sense Counter       */\r
+#define PHY_REG_RECR        0x15        /* Receive Error Counter             */\r
+#define PHY_REG_PCSR        0x16        /* PCS Sublayer Config. and Status   */\r
+#define PHY_REG_RBR         0x17        /* RMII and Bypass Register          */\r
+#define PHY_REG_LEDCR       0x18        /* LED Direct Control Register       */\r
+#define PHY_REG_PHYCR       0x19        /* PHY Control Register              */\r
+#define PHY_REG_10BTSCR     0x1A        /* 10Base-T Status/Control Register  */\r
+#define PHY_REG_CDCTRL1     0x1B        /* CD Test Control and BIST Extens.  */\r
+#define PHY_REG_EDCR        0x1D        /* Energy Detect Control Register    */\r
+\r
+#define PHY_FULLD_100M      0x2100      /* Full Duplex 100Mbit               */\r
+#define PHY_HALFD_100M      0x2000      /* Half Duplex 100Mbit               */\r
+#define PHY_FULLD_10M       0x0100      /* Full Duplex 10Mbit                */\r
+#define PHY_HALFD_10M       0x0000      /* Half Duplex 10MBit                */\r
+#define PHY_AUTO_NEG        0x3000      /* Select Auto Negotiation           */\r
+#define PHY_AUTO_NEG_COMPLETE 0x0020   /* Auto negotiation have finished.   */\r
+#define ETHDEV_PHY_DEF_ADR    0x0100      /* Default PHY device address        */\r
+\r
+\r
+\r
+\r
+\r
 /* Time to wait between each inspection of the link status. */\r
 #define emacWAIT_FOR_LINK_TO_ESTABLISH_MS 500\r
 \r
index c1c8dcb..e5757a0 100644 (file)
 extern "C" {\r
 #endif /* __cplusplus */\r
 \r
-#define DP83848C_ID         0x20005C90  /* PHY Identifier                    */\r
-\r
-/* DP83848C PHY Registers */\r
-#define PHY_REG_BMCR        0x00        /* Basic Mode Control Register       */\r
-#define PHY_REG_BMSR        0x01        /* Basic Mode Status Register        */\r
-#define PHY_REG_IDR1        0x02        /* PHY Identifier 1                  */\r
-#define PHY_REG_IDR2        0x03        /* PHY Identifier 2                  */\r
-#define PHY_REG_ANAR        0x04        /* Auto-Negotiation Advertisement    */\r
-#define PHY_REG_ANLPAR      0x05        /* Auto-Neg. Link Partner Abitily    */\r
-#define PHY_REG_ANER        0x06        /* Auto-Neg. Expansion Register      */\r
-#define PHY_REG_ANNPTR      0x07        /* Auto-Neg. Next Page TX            */\r
-\r
-/* PHY Extended Registers */\r
-#define PHY_REG_STS         0x10        /* Status Register                   */\r
-#define PHY_REG_MICR        0x11        /* MII Interrupt Control Register    */\r
-#define PHY_REG_MISR        0x12        /* MII Interrupt Status Register     */\r
-#define PHY_REG_FCSCR       0x14        /* False Carrier Sense Counter       */\r
-#define PHY_REG_RECR        0x15        /* Receive Error Counter             */\r
-#define PHY_REG_PCSR        0x16        /* PCS Sublayer Config. and Status   */\r
-#define PHY_REG_RBR         0x17        /* RMII and Bypass Register          */\r
-#define PHY_REG_LEDCR       0x18        /* LED Direct Control Register       */\r
-#define PHY_REG_PHYCR       0x19        /* PHY Control Register              */\r
-#define PHY_REG_10BTSCR     0x1A        /* 10Base-T Status/Control Register  */\r
-#define PHY_REG_CDCTRL1     0x1B        /* CD Test Control and BIST Extens.  */\r
-#define PHY_REG_EDCR        0x1D        /* Energy Detect Control Register    */\r
-\r
-#define PHY_FULLD_100M      0x2100      /* Full Duplex 100Mbit               */\r
-#define PHY_HALFD_100M      0x2000      /* Half Duplex 100Mbit               */\r
-#define PHY_FULLD_10M       0x0100      /* Full Duplex 10Mbit                */\r
-#define PHY_HALFD_10M       0x0000      /* Half Duplex 10MBit                */\r
-#define PHY_AUTO_NEG        0x3000      /* Select Auto Negotiation           */\r
-#define PHY_AUTO_NEG_COMPLETE 0x0020   /* Auto negotiation have finished.   */\r
-#define ETHDEV_PHY_DEF_ADR    0x0100      /* Default PHY device address        */\r
-\r
 const NyLPC_TBool EthDev_DP83848C_getInterface(\r
        const struct TiEthernetDevice** o_dev);\r
 \r
index 76a9568..bfd4ddf 100644 (file)
 #include "EtherDev_LAN8720_protected.h"\r
 #include "../os/NyLPC_cThread.h"\r
 \r
+#define LAN8720_ID          0x0007C0F0  /* PHY Identifier                    */\r
+\r
+/* LAN8720 PHY Registers */\r
+#define PHY_REG_BMCR        0x00        /* Basic Mode Control Register       */\r
+#define PHY_REG_BMSR        0x01        /* Basic Mode Status Register        */\r
+#define PHY_REG_IDR1        0x02        /* PHY Identifier 1                  */\r
+#define PHY_REG_IDR2        0x03        /* PHY Identifier 2                  */\r
+#define PHY_REG_ANAR        0x04        /* Auto-Negotiation Advertisement    */\r
+#define PHY_REG_ANLPAR      0x05        /* Auto-Neg. Link Partner Abitily    */\r
+#define PHY_REG_ANER        0x06        /* Auto-Neg. Expansion Register      */\r
+\r
+/* PHY Extended Registers */\r
+#define        PHY_REG_MODE_CTRL           17\r
+#define        PHY_REG_SPECIAL_MODE    18\r
+#define        PHY_REG_SYMBOL_ERR_CNT  26\r
+#define        PHY_REG_SPECIAL_CTRL    27\r
+#define        PHY_REG_INT_SOURCE          29\r
+#define        PHY_REG_INT_MASK            30\r
+#define        PHY_REG_PHY_CTRL            31\r
+\r
+#define PHY_AUTO_NEG           0x3000  /* Select Auto Negotiation           */\r
+#define PHY_AUTO_NEG_COMPLETE  0x1000  /* Auto negotiation have finished.   */\r
+\r
+#define PHY_SPEED_FDUPLX               0x0010  /* Full Duplex   */\r
+#define PHY_SPEED_100                  0x0008  /* 100Mbit   */\r
+#define ETHDEV_PHY_DEF_ADR             0x0100  /* Default PHY device address        */\r
+\r
+\r
 /* Time to wait between each inspection of the link status. */\r
 #define emacWAIT_FOR_LINK_TO_ESTABLISH_MS 500\r
 \r
index 15324a2..424cacc 100644 (file)
 extern "C" {\r
 #endif /* __cplusplus */\r
 \r
-#define LAN8720_ID          0x0007C0F0  /* PHY Identifier                    */\r
-\r
-/* LAN8720 PHY Registers */\r
-#define PHY_REG_BMCR        0x00        /* Basic Mode Control Register       */\r
-#define PHY_REG_BMSR        0x01        /* Basic Mode Status Register        */\r
-#define PHY_REG_IDR1        0x02        /* PHY Identifier 1                  */\r
-#define PHY_REG_IDR2        0x03        /* PHY Identifier 2                  */\r
-#define PHY_REG_ANAR        0x04        /* Auto-Negotiation Advertisement    */\r
-#define PHY_REG_ANLPAR      0x05        /* Auto-Neg. Link Partner Abitily    */\r
-#define PHY_REG_ANER        0x06        /* Auto-Neg. Expansion Register      */\r
-\r
-/* PHY Extended Registers */\r
-#define        PHY_REG_MODE_CTRL           17\r
-#define        PHY_REG_SPECIAL_MODE    18\r
-#define        PHY_REG_SYMBOL_ERR_CNT  26\r
-#define        PHY_REG_SPECIAL_CTRL    27\r
-#define        PHY_REG_INT_SOURCE          29\r
-#define        PHY_REG_INT_MASK            30\r
-#define        PHY_REG_PHY_CTRL            31\r
-\r
-#define PHY_AUTO_NEG           0x3000  /* Select Auto Negotiation           */\r
-#define PHY_AUTO_NEG_COMPLETE  0x1000  /* Auto negotiation have finished.   */\r
-\r
-#define PHY_SPEED_FDUPLX               0x0010  /* Full Duplex   */\r
-#define PHY_SPEED_100                  0x0008  /* 100Mbit   */\r
-#define ETHDEV_PHY_DEF_ADR             0x0100  /* Default PHY device address        */\r
-\r
 const NyLPC_TBool EthDev_LAN8720_getInterface(\r
        const struct TiEthernetDevice** o_dev);\r
 \r
diff --git a/lib/src/driver/uip/uip_arp.c b/lib/src/driver/uip/uip_arp.c
deleted file mode 100644 (file)
index 3d59071..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/*\r
- * Copyright (c) 2001-2003, Adam Dunkels.\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote\r
- *    products derived from this software without specific prior\r
- *    written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * This file is part of the uIP TCP/IP stack.\r
- *\r
- * $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $\r
- *\r
- */\r
-\r
-\r
-#include "uip_arp.h"\r
-\r
-\r
-#include <string.h>\r
-\r
-#ifdef __ICCARM__\r
-       #pragma pack(1)\r
-#endif\r
-\r
-struct arp_hdr\r
-{\r
-  struct uip_eth_hdr ethhdr;\r
-  u16_t hwtype;\r
-  u16_t protocol;\r
-  u8_t hwlen;\r
-  u8_t protolen;\r
-  u16_t opcode;\r
-  struct NyLPC_TEthAddr shwaddr;\r
-  struct NyLPC_TIPv4Addr sipaddr;\r
-  struct NyLPC_TEthAddr dhwaddr;\r
-  struct NyLPC_TIPv4Addr dipaddr;\r
-} PACK_STRUCT_END;\r
-\r
-#ifdef __ICCARM__\r
-       #pragma pack()\r
-#endif\r
-\r
-#ifdef __ICCARM__\r
-       #pragma pack(1)\r
-#endif\r
-\r
-struct ethip_hdr {\r
-  struct uip_eth_hdr ethhdr;\r
-  /* IP header. */\r
-  u8_t vhl,\r
-    tos,\r
-    len[2],\r
-    ipid[2],\r
-    ipoffset[2],\r
-    ttl,\r
-    proto;\r
-  u16_t ipchksum;\r
-  struct NyLPC_TIPv4Addr srcipaddr;\r
-  struct NyLPC_TIPv4Addr destipaddr;\r
-} PACK_STRUCT_END;\r
-\r
-#ifdef __ICCARM__\r
-       #pragma pack()\r
-#endif\r
-\r
-#define ARP_REQUEST 1\r
-#define ARP_REPLY   2\r
-\r
-#define ARP_HWTYPE_ETH 1\r
-\r
-struct arp_entry {\r
-       struct NyLPC_TIPv4Addr ipaddr;\r
-       struct NyLPC_TEthAddr ethaddr;\r
-       u8_t time;\r
-};\r
-\r
-static const struct NyLPC_TEthAddr broadcast_ethaddr =\r
-  {{0xff,0xff,0xff,0xff,0xff,0xff}};\r
-static const struct NyLPC_TIPv4Addr broadcast_ipaddr = {0xfffffff};\r
-\r
-static struct arp_entry arp_table[UIP_ARPTAB_SIZE];\r
-static u8_t i, c;\r
-\r
-static u8_t arptime;\r
-static u8_t tmpage;\r
-const static NyLPC_TcIPv4Config_t* cfg;\r
-/*-----------------------------------------------------------------------------------*/\r
-/**\r
- * Initialize the ARP module.\r
- *\r
- */\r
-/*-----------------------------------------------------------------------------------*/\r
-void\r
-uip_arp_init(const NyLPC_TcIPv4Config_t* i_ref_config)\r
-{\r
-       cfg=i_ref_config;\r
-       for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
-               memset(&(arp_table[i].ipaddr), 0, sizeof(struct NyLPC_TIPv4Addr));\r
-       }\r
-}\r
-/*-----------------------------------------------------------------------------------*/\r
-/**\r
- * Periodic ARP processing function.\r
- *\r
- * This function performs periodic timer processing in the ARP module\r
- * and should be called at regular intervals. The recommended interval\r
- * is 10 seconds between the calls.\r
- *\r
- */\r
-/*-----------------------------------------------------------------------------------*/\r
-void\r
-uip_arp_timer(void)\r
-{\r
-  struct arp_entry *tabptr;\r
-\r
-  ++arptime;\r
-  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
-    tabptr = &arp_table[i];\r
-    if(tabptr->ipaddr.v!=0 && arptime - tabptr->time >= UIP_ARP_MAXAGE) {\r
-       tabptr->ipaddr.v=0;\r
-    }\r
-  }\r
-\r
-}\r
-/*-----------------------------------------------------------------------------------*/\r
-static void\r
-uip_arp_update(const struct NyLPC_TIPv4Addr* ipaddr, const struct NyLPC_TEthAddr *ethaddr)\r
-{\r
-       register struct arp_entry *tabptr;\r
-       /* Walk through the ARP mapping table and try to find an entry to\r
-       update. If none is found, the IP -> MAC address mapping is\r
-       inserted in the ARP table. */\r
-       for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
-               tabptr = &arp_table[i];\r
-               /* Only check those entries that are actually in use. */\r
-               if(tabptr->ipaddr.v != 0)\r
-               {\r
-                       /* Check if the source IP address of the incoming packet matches\r
-                       the IP address in this ARP table entry. */\r
-                       if(ipaddr->v == tabptr->ipaddr.v) {\r
-                               /* An old entry found, update this and return. */\r
-                               memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
-                               tabptr->time = arptime;\r
-\r
-                               return;\r
-                       }\r
-               }\r
-       }\r
-\r
-       /* If we get here, no existing ARP table entry was found, so we\r
-       create one. */\r
-       /* First, we try to find an unused entry in the ARP table. */\r
-       for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
-               tabptr = &arp_table[i];\r
-               if(tabptr->ipaddr.v==0)\r
-               {\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /* If no unused entry is found, we try to find the oldest entry and\r
-       throw it away. */\r
-       if(i == UIP_ARPTAB_SIZE) {\r
-               tmpage = 0;\r
-               c = 0;\r
-               for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {\r
-                       tabptr = &arp_table[i];\r
-                       if(arptime - tabptr->time > tmpage) {\r
-                               tmpage = arptime - tabptr->time;\r
-                               c = i;\r
-                       }\r
-               }\r
-               i = c;\r
-               tabptr = &arp_table[i];\r
-       }\r
-       \r
-       /* Now, i is the ARP table entry which we will fill with the new information. */\r
-       tabptr->ipaddr=*ipaddr;\r
-       memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
-       tabptr->time = arptime;\r
-}\r
-/*-----------------------------------------------------------------------------------*/\r
-/**\r
- * ARP processing for incoming IP packets\r
- *\r
- * This function should be called by the device driver when an IP\r
- * packet has been received. The function will check if the address is\r
- * in the ARP cache, and if so the ARP cache entry will be\r
- * refreshed. If no ARP cache entry was found, a new one is created.\r
- *\r
- * This function expects an IP packet with a prepended Ethernet header\r
- * in the uip_buf[] buffer, and the length of the packet in the global\r
- * variable uip_len.\r
- */\r
-/*-----------------------------------------------------------------------------------*/\r
-#if 1\r
-void\r
-uip_arp_ipin(const struct NyLPC_TEthernetIIHeader* i_eth,struct NyLPC_TIPv4Addr i_ip_src)\r
-{\r
-       //EtherとIPv4の値よ読みだす。\r
-       /* Only insert/update an entry if the source IP address of the\r
-       incoming IP packet comes from a host on the local network. */\r
-       if((i_ip_src.v & cfg->netmask.v) != (cfg->ip_addr.v & cfg->netmask.v))\r
-       {\r
-               return;\r
-       }\r
-       uip_arp_update(&(i_ip_src), &(i_eth->src));\r
-       return;\r
-}\r
-#endif /* 0 */\r
-/*-----------------------------------------------------------------------------------*/\r
-/**\r
- * ARP processing for incoming ARP packets.\r
- *\r
- * This function should be called by the device driver when an ARP\r
- * packet has been received. The function will act differently\r
- * depending on the ARP packet type: if it is a reply for a request\r
- * that we previously sent out, the ARP cache will be filled in with\r
- * the values from the ARP reply. If the incoming ARP packet is an ARP\r
- * request for our IP address, an ARP reply packet is created and put\r
- * into the uip_buf[] buffer.\r
- *\r
- * When the function returns, the value of the global variable uip_len\r
- * indicates whether the device driver should send out a packet or\r
- * not. If uip_len is zero, no packet should be sent. If uip_len is\r
- * non-zero, it contains the length of the outbound packet that is\r
- * present in the uip_buf[] buffer.\r
- *\r
- * This function expects an ARP packet with a prepended Ethernet\r
- * header in the uip_buf[] buffer, and the length of the packet in the\r
- * global variable uip_len.\r
- */\r
-/*-----------------------------------------------------------------------------------*/\r
-\r
-\r
-\r
-\r
-\r
-\r
-/**\r
- * arpパケットを処理します。
- */\r
-NyLPC_TBool uip_arp_arpin(struct NyLPC_TArpHeader* i_arp,u16_t i_len)\r
-{\r
-       if(i_len<sizeof(struct NyLPC_TArpHeader))\r
-       {\r
-               return 0;\r
-       }\r
-       switch(i_arp->opcode) {\r
-       case NyLPC_HTONS(ARP_REQUEST):\r
-               /* ARP request. If it asked for our address, we send out a reply. */\r
-               if(NyLPC_TIPv4Addr_isEqual(&(i_arp->dipaddr), &(cfg->ip_addr)))\r
-               {\r
-                       /* First, we register the one who made the request in our ARP\r
-                       table, since it is likely that we will do more communication\r
-                       with this host in the future. */\r
-                       uip_arp_update(&(i_arp->sipaddr), &i_arp->shwaddr);\r
-\r
-                       /* The reply opcode is 2. */\r
-                       i_arp->opcode = NyLPC_HTONS(2);\r
-\r
-                       memcpy(i_arp->dhwaddr.addr, i_arp->shwaddr.addr, 6);\r
-                       memcpy(i_arp->shwaddr.addr, cfg->eth_mac.addr, 6);\r
-\r
-                       i_arp->dipaddr = i_arp->sipaddr;\r
-                       i_arp->sipaddr = cfg->ip_addr;\r
-\r
-                       return NyLPC_TBool_TRUE;\r
-               }\r
-               break;\r
-       case NyLPC_HTONS(ARP_REPLY):\r
-               // ARP reply. We insert or update the ARP table if it was meant for us.\r
-               if(NyLPC_TIPv4Addr_isEqual(&(i_arp->dipaddr),&(cfg->ip_addr))) {\r
-                       uip_arp_update(&(i_arp->sipaddr), &i_arp->shwaddr);\r
-               }\r
-               return NyLPC_TBool_TRUE;\r
-       }\r
-       return NyLPC_TBool_FALSE;\r
-}\r
-/*-----------------------------------------------------------------------------------*/\r
-/**\r
- * Prepend Ethernet header to an outbound IP packet and see if we need\r
- * to send out an ARP request.\r
- *\r
- * This function should be called before sending out an IP packet. The\r
- * function checks the destination IP address of the IP packet to see\r
- * what Ethernet MAC address that should be used as a destination MAC\r
- * address on the Ethernet.\r
- *\r
- * If the destination IP address is in the local network (determined\r
- * by logical ANDing of netmask and our IP address), the function\r
- * checks the ARP cache to see if an entry for the destination IP\r
- * address is found. If so, an Ethernet header is prepended and the\r
- * function returns. If no ARP cache entry is found for the\r
- * destination IP address, the packet in the uip_buf[] is replaced by\r
- * an ARP request packet for the IP address. The IP packet is dropped\r
- * and it is assumed that they higher level protocols (e.g., TCP)\r
- * eventually will retransmit the dropped packet.\r
- *\r
- * If the destination IP address is not on the local network, the IP\r
- * address of the default router is used instead.\r
- *\r
- * When the function returns, a packet is present in the uip_buf[]\r
- * buffer, and the length of the packet is in the global variable\r
- * uip_len.\r
- */\r
-/*-----------------------------------------------------------------------------------*/\r
-\r
-/**\r
- * IPアドレス-MACアドレス交換
- */\r
-const struct NyLPC_TEthAddr* uip_arp_IPv4toEthAddr(\r
-       const struct NyLPC_TIPv4Addr i_ip_addr)\r
-{\r
-       int i;\r
-       struct NyLPC_TIPv4Addr ip;\r
-       struct arp_entry *tabptr;\r
-       //ブロードキャストならそのまま\r
-       if(NyLPC_TIPv4Addr_isEqual(&i_ip_addr,&broadcast_ipaddr))\r
-       {\r
-               return &broadcast_ethaddr;\r
-       }\r
-       //LocalIPでなければ、デフォルトゲートウェイのアドレスに設定。\r
-       if(!NyLPC_cIPv4Config_isLocalIP(cfg,&i_ip_addr)){\r
-               ip=cfg->dr_addr;\r
-       }else{\r
-               ip=i_ip_addr;\r
-       }\r
-       //ARPテーブルから検索\r
-       for(i = UIP_ARPTAB_SIZE-1; i>=0 ;i--) {\r
-               tabptr = &arp_table[i];\r
-               if(NyLPC_TIPv4Addr_isEqual(&ip,&(tabptr->ipaddr))) {\r
-                       return &tabptr->ethaddr;\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-/*-----------------------------------------------------------------------------------*/\r
-\r
-/** @} */\r
-/** @} */\r
diff --git a/lib/src/driver/uip/uip_arp.h b/lib/src/driver/uip/uip_arp.h
deleted file mode 100644 (file)
index f753783..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-/**\r
- * \addtogroup uip\r
- * @{\r
- */\r
-\r
-/**\r
- * \addtogroup uiparp\r
- * @{\r
- */\r
-\r
-/**\r
- * \file\r
- * Macros and definitions for the ARP module.\r
- * \author Adam Dunkels <adam@dunkels.com>\r
- */\r
-\r
-\r
-/*\r
- * Copyright (c) 2001-2003, Adam Dunkels.\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote\r
- *    products derived from this software without specific prior\r
- *    written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * This file is part of the uIP TCP/IP stack.\r
- *\r
- * $Id: uip_arp.h,v 1.5 2006/06/11 21:46:39 adam Exp $\r
- *\r
- */\r
-\r
-#ifndef __UIP_ARP_H__\r
-#define __UIP_ARP_H__\r
-#include "uip-conf.h"\r
-#include "../../uip/NyLPC_uip.h"\r
-#include "../../uip/NyLPC_cIPv4Config.h"\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif /* __cplusplus */\r
-\r
-/**\r
- * The size of the ARP table.\r
- *\r
- * This option should be set to a larger value if this uIP node will\r
- * have many connections from the local network.\r
- *\r
- * \hideinitializer\r
- */\r
-#ifdef UIP_CONF_ARPTAB_SIZE\r
-#define UIP_ARPTAB_SIZE UIP_CONF_ARPTAB_SIZE\r
-#else\r
-#define UIP_ARPTAB_SIZE 8\r
-#endif\r
-\r
-/**\r
- * The maxium age of ARP table entries measured in 10ths of seconds.\r
- *\r
- * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD\r
- * default).\r
- */\r
-#define UIP_ARP_MAXAGE 120\r
-\r
-extern struct NyLPC_TEthAddr uip_ethaddr;\r
-\r
-/**\r
- * The Ethernet header.\r
- */\r
-#ifdef __ICCARM__\r
-       #pragma pack(1)\r
-#endif\r
-\r
-struct uip_eth_hdr\r
-{\r
-       struct NyLPC_TEthAddr dest;\r
-       struct NyLPC_TEthAddr src;\r
-       u16_t type;\r
-}PACK_STRUCT_END;\r
-\r
-#ifdef __ICCARM__\r
-       #pragma pack()\r
-#endif\r
-\r
-#define UIP_ETHTYPE_ARP 0x0806\r
-#define UIP_ETHTYPE_IP  0x0800\r
-#define UIP_ETHTYPE_IP6 0x86dd\r
-\r
-\r
-/* The uip_arp_init() function must be called before any of the other\r
-   ARP functions. */\r
-void uip_arp_init(const NyLPC_TcIPv4Config_t* i_ref_config);\r
-\r
-\r
-/* The uip_arp_ipin() function should be called whenever an IP packet\r
-   arrives from the Ethernet. This function refreshes the ARP table or\r
-   inserts a new mapping if none exists. The function assumes that an\r
-   IP packet with an Ethernet header is present in the uip_buf buffer\r
-   and that the length of the packet is in the uip_len variable. */\r
-void uip_arp_ipin(const struct NyLPC_TEthernetIIHeader* i_eth,struct NyLPC_TIPv4Addr i_ip_src);\r
-\r
-//#define uip_arp_ipin()\r
-\r
-\r
-/* The uip_arp_out() function should be called when an IP packet\r
-   should be sent out on the Ethernet. This function creates an\r
-   Ethernet header before the IP header in the uip_buf buffer. The\r
-   Ethernet header will have the correct Ethernet MAC destination\r
-   address filled in if an ARP table entry for the destination IP\r
-   address (or the IP address of the default router) is present. If no\r
-   such table entry is found, the IP packet is overwritten with an ARP\r
-   request and we rely on TCP to retransmit the packet that was\r
-   overwritten. In any case, the uip_len variable holds the length of\r
-   the Ethernet frame that should be transmitted. */\r
-\r
-NyLPC_TBool uip_arp_setEthernetAddress(\r
-       struct NyLPC_TEthernetIIHeader* i_eth,\r
-       struct NyLPC_TIPv4Header* i_iph);\r
-\r
-/**\r
- * ARPパケットを処理します。\r
- * 戻り値は、応答パケットの有無です。\r
- * 戻り値が真の場合は、レスポンスデータをi_arpのポインタに書き込みます。\r
- * そのときのデータサイズは、sizeof(struct NyLPC_TArpHeader)です。\r
- */\r
-NyLPC_TBool uip_arp_arpin(struct NyLPC_TArpHeader* i_arp,u16_t i_len);\r
-\r
-\r
-/* The uip_arp_timer() function should be called every ten seconds. It\r
-   is responsible for flushing old entries in the ARP table. */\r
-void uip_arp_timer(void);\r
-\r
-/** @} */\r
-\r
-/**\r
- * \addtogroup uipconffunc\r
- * @{\r
- */\r
-\r
-\r
-/**\r
- * Specifiy the Ethernet MAC address.\r
- *\r
- * The ARP code needs to know the MAC address of the Ethernet card in\r
- * order to be able to respond to ARP queries and to generate working\r
- * Ethernet headers.\r
- *\r
- * \note This macro only specifies the Ethernet MAC address to the ARP\r
- * code. It cannot be used to change the MAC address of the Ethernet\r
- * card.\r
- *\r
- * \param eaddr A pointer to a struct NyLPC_TEthAddr containing the\r
- * Ethernet MAC address of the Ethernet card.\r
- *\r
- * \hideinitializer\r
- */\r
-#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \\r
-                              uip_ethaddr.addr[1] = eaddr.addr[1];\\r
-                              uip_ethaddr.addr[2] = eaddr.addr[2];\\r
-                              uip_ethaddr.addr[3] = eaddr.addr[3];\\r
-                              uip_ethaddr.addr[4] = eaddr.addr[4];\\r
-                              uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)\r
-\r
-/**\r
- * ARPテーブルで変換する。
- */\r
-const struct NyLPC_TEthAddr* uip_arp_IPv4toEthAddr(\r
-       const struct NyLPC_TIPv4Addr i_ip_addr);\r
-\r
-/** @} */\r
-/** @} */\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif /* __cplusplus */\r
-\r
-#endif /* __UIP_ARP_H__ */\r
index aeae321..5fef050 100644 (file)
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
  */\r
+#include "NyLPC_cIPv4Arp.h"\r
+#include "NyLPC_uip.h"\r
+#include <string.h>\r
+\r
+\r
+/**\r
+ * The maxium age of ARP table entries measured in 10ths of seconds.\r
+ *\r
+ * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD\r
+ * default).\r
+ */\r
+#define UIP_ARP_MAXAGE 120\r
+\r
+\r
+//static const struct NyLPC_TEthAddr broadcast_ethaddr = { { 0xff, 0xff, 0xff,0xff, 0xff, 0xff } };\r
+//static const struct NyLPC_TIPv4Addr broadcast_ipaddr = { 0xfffffff };\r
+\r
+\r
+\r
+\r
+static void uip_arp_update(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TIPv4Addr* ipaddr,const struct NyLPC_TEthAddr *ethaddr);\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Initialize the ARP module.\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void NyLPC_cIPv4Arp_initialize(NyLPC_TcIPv4Arp_t* i_inst,const NyLPC_TcIPv4Config_t* i_ref_config)\r
+{\r
+       int i;\r
+       struct NyLPC_TArpTableItem* tbl=i_inst->arp_table;\r
+       i_inst->_cfg = i_ref_config;\r
+       i_inst->arptime = 0;\r
+       i_inst->tmpage = 0;\r
+       for (i = 0; i < NyLPC_TcIPv4Arp_ARPTAB_SIZE; ++i) {\r
+               memset(&(tbl[i].ipaddr), 0, sizeof(struct NyLPC_TIPv4Addr));\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * Periodic ARP processing function.\r
+ *\r
+ * This function performs periodic timer processing in the ARP module\r
+ * and should be called at regular intervals. The recommended interval\r
+ * is 10 seconds between the calls.\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void NyLPC_cIPv4Arp_periodic(NyLPC_TcIPv4Arp_t* i_inst)\r
+{\r
+       struct NyLPC_TArpTableItem* tbl=i_inst->arp_table;\r
+       struct NyLPC_TArpTableItem* tabptr;\r
+       int i;\r
+       i_inst->arptime++;\r
+       for (i = 0; i < NyLPC_TcIPv4Arp_ARPTAB_SIZE; ++i) {\r
+               tabptr = &tbl[i];\r
+               if (tabptr->ipaddr.v != 0 && i_inst->arptime - tabptr->time >= UIP_ARP_MAXAGE)\r
+               {\r
+                       tabptr->ipaddr.v = 0;\r
+               }\r
+       }\r
+\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * ARP processing for incoming IP packets\r
+ *\r
+ * This function should be called by the device driver when an IP\r
+ * packet has been received. The function will check if the address is\r
+ * in the ARP cache, and if so the ARP cache entry will be\r
+ * refreshed. If no ARP cache entry was found, a new one is created.\r
+ *\r
+ * This function expects an IP packet with a prepended Ethernet header\r
+ * in the uip_buf[] buffer, and the length of the packet in the global\r
+ * variable uip_len.\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+void NyLPC_cIPv4Arp_incomingIp(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TEthernetIIHeader* i_eth,struct NyLPC_TIPv4Addr i_ip_src)\r
+{\r
+       //EtherとIPv4の値を読みだす。\r
+       /* Only insert/update an entry if the source IP address of the\r
+        incoming IP packet comes from a host on the local network. */\r
+       if ((i_ip_src.v & i_inst->_cfg->netmask.v) != (i_inst->_cfg->ip_addr.v & i_inst->_cfg->netmask.v)) {\r
+               return;\r
+       }\r
+       uip_arp_update(i_inst,&(i_ip_src), &(i_eth->src));\r
+       return;\r
+}\r
+/**\r
+ * ARP processing for incoming ARP packets.\r
+ *\r
+ * This function should be called by the device driver when an ARP\r
+ * packet has been received. The function will act differently\r
+ * depending on the ARP packet type: if it is a reply for a request\r
+ * that we previously sent out, the ARP cache will be filled in with\r
+ * the values from the ARP reply. If the incoming ARP packet is an ARP\r
+ * request for our IP address, an ARP reply packet is created and put\r
+ * into the uip_buf[] buffer.\r
+ *\r
+ * When the function returns, the value of the global variable uip_len\r
+ * indicates whether the device driver should send out a packet or\r
+ * not. If uip_len is zero, no packet should be sent. If uip_len is\r
+ * non-zero, it contains the length of the outbound packet that is\r
+ * present in the uip_buf[] buffer.\r
+ *\r
+ * This function expects an ARP packet with a prepended Ethernet\r
+ * header in the uip_buf[] buffer, and the length of the packet in the\r
+ * global variable uip_len.\r
+ */\r
+\r
+/**\r
+ * arpパケットを処理します。\r
+ */\r
+NyLPC_TBool NyLPC_cIPv4Arp_incomingArp(NyLPC_TcIPv4Arp_t* i_inst,struct NyLPC_TArpHeader* i_arp, NyLPC_TUInt16 i_len)\r
+{\r
+       if (i_len < sizeof(struct NyLPC_TArpHeader)) {\r
+               return 0;\r
+       }\r
+       const NyLPC_TcIPv4Config_t* cfg=i_inst->_cfg;\r
+       switch (i_arp->opcode) {\r
+       case NyLPC_HTONS(ARP_REQUEST):\r
+               /* ARP request. If it asked for our address, we send out a reply. */\r
+               if (NyLPC_TIPv4Addr_isEqual(&(i_arp->dipaddr), &(cfg->ip_addr))) {\r
+                       /* First, we register the one who made the request in our ARP\r
+                        table, since it is likely that we will do more communication\r
+                        with this host in the future. */\r
+                       uip_arp_update(i_inst,&(i_arp->sipaddr), &i_arp->shwaddr);\r
+\r
+                       /* The reply opcode is 2. */\r
+                       i_arp->opcode = NyLPC_HTONS(2);\r
+\r
+                       memcpy(i_arp->dhwaddr.addr, i_arp->shwaddr.addr, 6);\r
+                       memcpy(i_arp->shwaddr.addr, cfg->eth_mac.addr, 6);\r
+\r
+                       i_arp->dipaddr = i_arp->sipaddr;\r
+                       i_arp->sipaddr = cfg->ip_addr;\r
+\r
+                       return NyLPC_TBool_TRUE;\r
+               }\r
+               break;\r
+       case NyLPC_HTONS(ARP_REPLY):\r
+               // ARP reply. We insert or update the ARP table if it was meant for us.\r
+               if (NyLPC_TIPv4Addr_isEqual(&(i_arp->dipaddr),&(cfg->ip_addr))) {\r
+                       uip_arp_update(i_inst,&(i_arp->sipaddr), &i_arp->shwaddr);\r
+               }\r
+               return NyLPC_TBool_TRUE;\r
+       }\r
+       return NyLPC_TBool_FALSE;\r
+}\r
+/**\r
+ * Prepend Ethernet header to an outbound IP packet and see if we need\r
+ * to send out an ARP request.\r
+ *\r
+ * This function should be called before sending out an IP packet. The\r
+ * function checks the destination IP address of the IP packet to see\r
+ * what Ethernet MAC address that should be used as a destination MAC\r
+ * address on the Ethernet.\r
+ *\r
+ * If the destination IP address is in the local network (determined\r
+ * by logical ANDing of netmask and our IP address), the function\r
+ * checks the ARP cache to see if an entry for the destination IP\r
+ * address is found. If so, an Ethernet header is prepended and the\r
+ * function returns. If no ARP cache entry is found for the\r
+ * destination IP address, the packet in the uip_buf[] is replaced by\r
+ * an ARP request packet for the IP address. The IP packet is dropped\r
+ * and it is assumed that they higher level protocols (e.g., TCP)\r
+ * eventually will retransmit the dropped packet.\r
+ *\r
+ * If the destination IP address is not on the local network, the IP\r
+ * address of the default router is used instead.\r
+ *\r
+ * When the function returns, a packet is present in the uip_buf[]\r
+ * buffer, and the length of the packet is in the global variable\r
+ * uip_len.\r
+ */\r
+\r
+/**\r
+ * IPアドレス-MACアドレス交換\r
+ */\r
+const struct NyLPC_TEthAddr* NyLPC_cIPv4Arp_IPv4toEthAddr(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TIPv4Addr i_ip_addr)\r
+{\r
+       int i;\r
+       struct NyLPC_TIPv4Addr ip;\r
+       struct NyLPC_TArpTableItem *tabptr;\r
+       //ブロードキャストならそのまま\r
+       if (NyLPC_TIPv4Addr_isEqual(&i_ip_addr,&NyLPC_TIPv4Addr_BROADCAST)) {\r
+               return &NyLPC_TEthAddr_BROADCAST;\r
+       }\r
+       //LocalIPでなければ、デフォルトゲートウェイのアドレスに設定。\r
+       if (!NyLPC_cIPv4Config_isLocalIP(i_inst->_cfg, &i_ip_addr)) {\r
+               ip = i_inst->_cfg->dr_addr;\r
+       } else {\r
+               ip = i_ip_addr;\r
+       }\r
+       //ARPテーブルから検索\r
+       for (i = NyLPC_TcIPv4Arp_ARPTAB_SIZE - 1; i >= 0; i--) {\r
+               tabptr = &i_inst->arp_table[i];\r
+               if (NyLPC_TIPv4Addr_isEqual(&ip,&(tabptr->ipaddr))) {\r
+                       return &tabptr->ethaddr;\r
+               }\r
+       }\r
+       return NULL;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+static void uip_arp_update(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TIPv4Addr* ipaddr,const struct NyLPC_TEthAddr *ethaddr)\r
+{\r
+       register struct NyLPC_TArpTableItem *tabptr;\r
+       int i,c;\r
+       /* Walk through the ARP mapping table and try to find an entry to\r
+        update. If none is found, the IP -> MAC address mapping is\r
+        inserted in the ARP table. */\r
+       for (i = 0; i < NyLPC_TcIPv4Arp_ARPTAB_SIZE; ++i) {\r
+               tabptr = &i_inst->arp_table[i];\r
+               /* Only check those entries that are actually in use. */\r
+               if (tabptr->ipaddr.v != 0) {\r
+                       /* Check if the source IP address of the incoming packet matches\r
+                        the IP address in this ARP table entry. */\r
+                       if (ipaddr->v == tabptr->ipaddr.v) {\r
+                               /* An old entry found, update this and return. */\r
+                               memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
+                               tabptr->time = i_inst->arptime;\r
+\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+\r
+       /* If we get here, no existing ARP table entry was found, so we\r
+        create one. */\r
+       /* First, we try to find an unused entry in the ARP table. */\r
+       for (i = 0; i < NyLPC_TcIPv4Arp_ARPTAB_SIZE; ++i) {\r
+               tabptr = &i_inst->arp_table[i];\r
+               if (tabptr->ipaddr.v == 0) {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /* If no unused entry is found, we try to find the oldest entry and\r
+        throw it away. */\r
+       if (i == NyLPC_TcIPv4Arp_ARPTAB_SIZE) {\r
+               i_inst->tmpage = 0;\r
+               c = 0;\r
+               for (i = 0; i < NyLPC_TcIPv4Arp_ARPTAB_SIZE; ++i) {\r
+                       tabptr = &i_inst->arp_table[i];\r
+                       if (i_inst->arptime - tabptr->time > i_inst->tmpage) {\r
+                               i_inst->tmpage = i_inst->arptime - tabptr->time;\r
+                               c = i;\r
+                       }\r
+               }\r
+               i = c;\r
+               tabptr = &i_inst->arp_table[i];\r
+       }\r
+\r
+       /* Now, i is the ARP table entry which we will fill with the new information. */\r
+       tabptr->ipaddr = *ipaddr;\r
+       memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);\r
+       tabptr->time = i_inst->arptime;\r
+}\r
+\r
+\r
diff --git a/lib/src/uip/NyLPC_cIPv4Arp.h b/lib/src/uip/NyLPC_cIPv4Arp.h
new file mode 100644 (file)
index 0000000..536bf2c
--- /dev/null
@@ -0,0 +1,108 @@
+/*********************************************************************************\r
+ * PROJECT: MiMic\r
+ * --------------------------------------------------------------------------------\r
+ *\r
+ * This file is part of MiMic\r
+ * Copyright (C)2011 Ryo Iizuka\r
+ *\r
+ * MiMic is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published\r
+ * by the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * For further information please contact.\r
+ *     http://nyatla.jp/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ *\r
+ *\r
+ * Parts of this file were leveraged from uIP:\r
+ *\r
+ * Copyright (c) 2001-2003, Adam Dunkels.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote\r
+ *    products derived from this software without specific prior\r
+ *    written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+#ifndef NYLPC_CIPV4ARP_H_\r
+#define NYLPC_CIPV4ARP_H_\r
+#include "NyLPC_cIPv4Config.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+\r
+struct NyLPC_TArpTableItem\r
+{\r
+       struct NyLPC_TIPv4Addr ipaddr;\r
+       struct NyLPC_TEthAddr ethaddr;\r
+       NyLPC_TUInt8 time;\r
+};\r
+\r
+/**********************************************************************\r
+ *\r
+ * class NyLPC_TcIPv4Config\r
+ *\r
+ **********************************************************************/\r
+\r
+\r
+#define NyLPC_TcIPv4Arp_ARPTAB_SIZE 8\r
+\r
+\r
+typedef struct NyLPC_TcIPv4Arp NyLPC_TcIPv4Arp_t;\r
+\r
+/**\r
+ * NyLPC_TcIPv4クラスの構造体です。\r
+ */\r
+struct NyLPC_TcIPv4Arp\r
+{\r
+       const NyLPC_TcIPv4Config_t* _cfg;\r
+       NyLPC_TUInt8 arptime;\r
+       NyLPC_TUInt8 tmpage;\r
+       struct NyLPC_TArpTableItem arp_table[NyLPC_TcIPv4Arp_ARPTAB_SIZE];\r
+};\r
+\r
+void NyLPC_cIPv4Arp_initialize(NyLPC_TcIPv4Arp_t* i_inst,const NyLPC_TcIPv4Config_t* i_ref_config);\r
+#define NyLPC_cIPv4Arp_finalize(i_inst)\r
+void NyLPC_cIPv4Arp_periodic(NyLPC_TcIPv4Arp_t* i_inst);\r
+void NyLPC_cIPv4Arp_incomingIp(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TEthernetIIHeader* i_eth,struct NyLPC_TIPv4Addr i_ip_src);\r
+NyLPC_TBool NyLPC_cIPv4Arp_incomingArp(NyLPC_TcIPv4Arp_t* i_inst,struct NyLPC_TArpHeader* i_arp, NyLPC_TUInt16 i_len);\r
+const struct NyLPC_TEthAddr* NyLPC_cIPv4Arp_IPv4toEthAddr(NyLPC_TcIPv4Arp_t* i_inst,const struct NyLPC_TIPv4Addr i_ip_addr);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+\r
+\r
+#endif /* NYLPC_CIPV4ARP_H_ */\r
index 69445ce..b357edf 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
  */\r
 \r
-#include "NyLPC_cUipService_protected.h"\r
 #include "NyLPC_cTcpListener_protected.h"\r
 #include "NyLPC_cTcpSocket_protected.h"\r
 #include "NyLPC_stdlib.h"\r
 #include "NyLPC_uip.h"\r
-#include "../driver/uip/uip_arp.h"\r
 \r
 \r
 \r
@@ -299,7 +297,8 @@ static void updateTaskStatus()
                //TCP,ICOMPの初期化\r
                NyLPC_cIPv4_start(&(inst->_tcpv4),inst->_ref_config);\r
                NyLPC_cIPv4IComp_initialize(&(inst->_icomp),inst->_ref_config);\r
-               uip_arp_init(msg->start.ref_config);\r
+               //uip_arp_init(msg->start.ref_config);\r
+               NyLPC_cIPv4Arp_initialize(&(inst->_arp),inst->_ref_config);\r
                NyLPC_cStopwatch_startExpire(&(inst->_arp_sw),1);//1度ARPを起動するため。\r
                NyLPC_cStopwatch_startExpire(&(inst->_periodic_sw),PERIODIC_TIMER);\r
                while(!inst->_ethif->start(&(inst->_ref_config->eth_mac)));\r
@@ -360,7 +359,8 @@ static void uipTask(void *pvParameters)
                                {\r
                                case NyLPC_HTONS(NyLPC_TEthernetIIHeader_TYPE_IP):\r
                                        //ARPテーブルの更新\r
-                                       uip_arp_ipin(&(ethbuf->header),ethbuf->data.ipv4.srcipaddr);\r
+                                       //uip_arp_ipin(&(ethbuf->header),ethbuf->data.ipv4.srcipaddr);\r
+                                       NyLPC_cIPv4Arp_incomingIp(&inst->_arp,&(ethbuf->header),ethbuf->data.ipv4.srcipaddr);\r
                                        //Ethernet Device UnLock(パケット解析の為に一時的な解除)\r
                                        NyLPC_cMutex_unlock(&(inst->_mutex));\r
                                        //IPパケットの処理\r
@@ -376,7 +376,8 @@ static void uipTask(void *pvParameters)
                                        ethbuf=NULL;\r
                                        break;\r
                                case NyLPC_HTONS(NyLPC_TEthernetIIHeader_TYPE_ARP):\r
-                                       if(uip_arp_arpin(&(ethbuf->data.arp),rx_len)){\r
+                                       //if(uip_arp_arpin(&(ethbuf->data.arp),rx_len)){\r
+                                       if(NyLPC_cIPv4Arp_incomingArp(&inst->_arp,&(ethbuf->data.arp),rx_len)){\r
                                                tx_len=NyLPC_TEthernetIIHeader_setArpTx(&(ethbuf->header),&(inst->_ref_config->eth_mac));\r
                                        }\r
                                        if(tx_len>0){\r
@@ -397,7 +398,8 @@ static void uipTask(void *pvParameters)
                }\r
                //データが無い。\r
                if(NyLPC_cStopwatch_isExpired(&(inst->_arp_sw))){\r
-                       uip_arp_timer();\r
+                       //uip_arp_timer();\r
+                       NyLPC_cIPv4Arp_periodic(&inst->_arp);\r
                        NyLPC_cStopwatch_startExpire(&(inst->_arp_sw),ARP_TIMER);\r
                }\r
                if(NyLPC_cStopwatch_isExpired(&(inst->_periodic_sw))){\r
@@ -568,7 +570,8 @@ static NyLPC_TBool sendIPv4Tx(struct NyLPC_TTxBufferHeader* i_eth_buf)
        struct TEthPacket* ethbuf=(struct TEthPacket*)(i_eth_buf+1);\r
 NyLPC_Trace();\r
        //ペイロードのアドレスから、イーサネットフレームバッファのアドレスを復元\r
-       const struct NyLPC_TEthAddr* eth_dest=uip_arp_IPv4toEthAddr(ethbuf->data.ipv4.destipaddr);\r
+       //const struct NyLPC_TEthAddr* eth_dest=uip_arp_IPv4toEthAddr(ethbuf->data.ipv4.destipaddr);\r
+       const struct NyLPC_TEthAddr* eth_dest=NyLPC_cIPv4Arp_IPv4toEthAddr(&inst->_arp,ethbuf->data.ipv4.destipaddr);\r
        //IP->MAC変換をテスト。\r
        if(eth_dest==NULL){\r
                //失敗\r
index ab4b72c..641b80a 100644 (file)
@@ -64,6 +64,7 @@
 #include "NyLPC_cIPv4IComp_protected.h"\r
 #include "NyLPC_cTcpListener.h"\r
 #include "NyLPC_cIPv4IComp.h"\r
+#include "NyLPC_cIPv4Arp.h"\r
 #include "NyLPC_cIPv4.h"\r
 \r
 #ifdef __cplusplus\r
index 6072ae1..3ec5aa2 100644 (file)
@@ -50,7 +50,8 @@ struct NyLPC_TcUipService
        NyLPC_TcSemaphore_t _emac_semapho;      /** EMACの制御用セマフォです。*/\r
        NyLPC_TcStopwatch_t _arp_sw;            /**<ARP用のストップウォッチ*/\r
        NyLPC_TcStopwatch_t _periodic_sw;       /**<周期実行用のストップウォッチ*/\r
-\r
+       /** ARP処理インスタンス*/\r
+       NyLPC_TcIPv4Arp_t _arp;\r
        /** TCPv4処理インスタンス*/\r
        NyLPC_TcIPv4_t _tcpv4;\r
        /** ICOMP処理インスタンス*/\r
index 03c9d52..3121598 100644 (file)
 \r
 \r
 \r
-\r
-#define ARP_REQUEST 1\r
-#define ARP_REPLY   2\r
-#define ARP_HWTYPE_ETH 1\r
-\r
 const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_ZERO={0x00000000};\r
 const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_ALL ={0xffffffff};\r
+const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_BROADCAST = { 0xfffffff };\r
 \r
 \r
 \r
index 0afc80c..210faf4 100644 (file)
@@ -67,6 +67,10 @@ extern "C" {
 #define UIP_PROTO_UDP   17\r
 #define UIP_PROTO_ICMP6 58\r
 \r
+#define ARP_REQUEST 1\r
+#define ARP_REPLY   2\r
+#define ARP_HWTYPE_ETH 1\r
+\r
 \r
 #ifndef PACK_STRUCT_END\r
        #define PACK_STRUCT_END __attribute((packed))\r
@@ -88,6 +92,7 @@ struct NyLPC_TIPv4Addr
 }PACK_STRUCT_END;\r
 extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_ZERO;\r
 extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_ALL;\r
+extern const struct NyLPC_TIPv4Addr NyLPC_TIPv4Addr_BROADCAST;\r
 \r
 /**\r
  * addr1とaddr2が全く同じであるかをテストします。\r
index f847822..d6aca30 100644 (file)
@@ -55,3 +55,5 @@
 #include "NyLPC_uip_ethernet.h"\r
 #include "NyLPC_uip.h"\r
 \r
+const struct NyLPC_TEthAddr NyLPC_TEthAddr_BROADCAST = { { 0xff, 0xff, 0xff,0xff, 0xff, 0xff } };\r
+\r
index b4000c8..8da17ff 100644 (file)
@@ -98,6 +98,8 @@ struct NyLPC_TEthAddr
  */\r
 #define NyLPC_TEthAddr_set(v,a1,a2,a3,a4,a5,a6) {v->addr[0]=(a1);v->addr[1]=(a2);v->addr[2]=(a3);v->addr[3]=(a4);v->addr[4]=(a5);v->addr[5]=(a6);}\r
 \r
+extern const struct NyLPC_TEthAddr NyLPC_TEthAddr_BROADCAST;\r
+\r
 \r
 #ifdef __cplusplus\r
 }\r