Fork for fixes
utility/uip_arp.h@1:01c2344f98a3, 2014-11-20 (annotated)
- Committer:
- hudakz
- Date:
- Thu Nov 20 21:26:54 2014 +0000
- Revision:
- 1:01c2344f98a3
- Parent:
- uitility/uip_arp.h@0:5350a66d5279
rev. 01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:5350a66d5279 | 1 | /** |
hudakz | 0:5350a66d5279 | 2 | * \addtogroup uip |
hudakz | 0:5350a66d5279 | 3 | * @{ |
hudakz | 0:5350a66d5279 | 4 | */ |
hudakz | 0:5350a66d5279 | 5 | /** |
hudakz | 0:5350a66d5279 | 6 | * \addtogroup uiparp |
hudakz | 0:5350a66d5279 | 7 | * @{ |
hudakz | 0:5350a66d5279 | 8 | */ |
hudakz | 0:5350a66d5279 | 9 | /** |
hudakz | 0:5350a66d5279 | 10 | * \file |
hudakz | 0:5350a66d5279 | 11 | * Macros and definitions for the ARP module. |
hudakz | 0:5350a66d5279 | 12 | * \author Adam Dunkels <adam@dunkels.com> |
hudakz | 0:5350a66d5279 | 13 | */ |
hudakz | 0:5350a66d5279 | 14 | /* |
hudakz | 0:5350a66d5279 | 15 | * Copyright (c) 2001-2003, Adam Dunkels. |
hudakz | 0:5350a66d5279 | 16 | * All rights reserved. |
hudakz | 0:5350a66d5279 | 17 | * |
hudakz | 0:5350a66d5279 | 18 | * Redistribution and use in source and binary forms, with or without |
hudakz | 0:5350a66d5279 | 19 | * modification, are permitted provided that the following conditions |
hudakz | 0:5350a66d5279 | 20 | * are met: |
hudakz | 0:5350a66d5279 | 21 | * 1. Redistributions of source code must retain the above copyright |
hudakz | 0:5350a66d5279 | 22 | * notice, this list of conditions and the following disclaimer. |
hudakz | 0:5350a66d5279 | 23 | * 2. Redistributions in binary form must reproduce the above copyright |
hudakz | 0:5350a66d5279 | 24 | * notice, this list of conditions and the following disclaimer in the |
hudakz | 0:5350a66d5279 | 25 | * documentation and/or other materials provided with the distribution. |
hudakz | 0:5350a66d5279 | 26 | * 3. The name of the author may not be used to endorse or promote |
hudakz | 0:5350a66d5279 | 27 | * products derived from this software without specific prior |
hudakz | 0:5350a66d5279 | 28 | * written permission. |
hudakz | 0:5350a66d5279 | 29 | * |
hudakz | 0:5350a66d5279 | 30 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
hudakz | 0:5350a66d5279 | 31 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
hudakz | 0:5350a66d5279 | 32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
hudakz | 0:5350a66d5279 | 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
hudakz | 0:5350a66d5279 | 34 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
hudakz | 0:5350a66d5279 | 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
hudakz | 0:5350a66d5279 | 36 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
hudakz | 0:5350a66d5279 | 37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
hudakz | 0:5350a66d5279 | 38 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
hudakz | 0:5350a66d5279 | 39 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
hudakz | 0:5350a66d5279 | 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
hudakz | 0:5350a66d5279 | 41 | * |
hudakz | 0:5350a66d5279 | 42 | * This file is part of the uIP TCP/IP stack. |
hudakz | 0:5350a66d5279 | 43 | * |
hudakz | 0:5350a66d5279 | 44 | * $Id: uip_arp.h,v 1.5 2006/06/11 21:46:39 adam Exp $ |
hudakz | 0:5350a66d5279 | 45 | * |
hudakz | 0:5350a66d5279 | 46 | */ |
hudakz | 0:5350a66d5279 | 47 | #ifndef __UIP_ARP_H__ |
hudakz | 0:5350a66d5279 | 48 | #define __UIP_ARP_H__ |
hudakz | 0:5350a66d5279 | 49 | |
hudakz | 0:5350a66d5279 | 50 | #include "uip.h" |
hudakz | 0:5350a66d5279 | 51 | |
hudakz | 0:5350a66d5279 | 52 | extern struct uip_eth_addr uip_ethaddr; |
hudakz | 0:5350a66d5279 | 53 | |
hudakz | 0:5350a66d5279 | 54 | /** |
hudakz | 0:5350a66d5279 | 55 | * The Ethernet header. |
hudakz | 0:5350a66d5279 | 56 | */ |
hudakz | 0:5350a66d5279 | 57 | struct uip_eth_hdr |
hudakz | 0:5350a66d5279 | 58 | { |
hudakz | 0:5350a66d5279 | 59 | struct uip_eth_addr dest; |
hudakz | 0:5350a66d5279 | 60 | struct uip_eth_addr src; |
hudakz | 0:5350a66d5279 | 61 | u16_t type; |
hudakz | 0:5350a66d5279 | 62 | }; |
hudakz | 0:5350a66d5279 | 63 | |
hudakz | 0:5350a66d5279 | 64 | #define UIP_ETHTYPE_ARP 0x0806 |
hudakz | 0:5350a66d5279 | 65 | #define UIP_ETHTYPE_IP 0x0800 |
hudakz | 0:5350a66d5279 | 66 | #define UIP_ETHTYPE_IP6 0x86dd |
hudakz | 0:5350a66d5279 | 67 | |
hudakz | 0:5350a66d5279 | 68 | /* The uip_arp_init() function must be called before any of the other |
hudakz | 0:5350a66d5279 | 69 | ARP functions. */ |
hudakz | 0:5350a66d5279 | 70 | void uip_arp_init(void); |
hudakz | 0:5350a66d5279 | 71 | |
hudakz | 0:5350a66d5279 | 72 | /* The uip_arp_ipin() function should be called whenever an IP packet |
hudakz | 0:5350a66d5279 | 73 | arrives from the Ethernet. This function refreshes the ARP table or |
hudakz | 0:5350a66d5279 | 74 | inserts a new mapping if none exists. The function assumes that an |
hudakz | 0:5350a66d5279 | 75 | IP packet with an Ethernet header is present in the uip_buf buffer |
hudakz | 0:5350a66d5279 | 76 | and that the length of the packet is in the uip_len variable. */ |
hudakz | 0:5350a66d5279 | 77 | void uip_arp_ipin(void); |
hudakz | 0:5350a66d5279 | 78 | |
hudakz | 0:5350a66d5279 | 79 | //#define uip_arp_ipin() |
hudakz | 0:5350a66d5279 | 80 | /* The uip_arp_arpin() should be called when an ARP packet is received |
hudakz | 0:5350a66d5279 | 81 | by the Ethernet driver. This function also assumes that the |
hudakz | 0:5350a66d5279 | 82 | Ethernet frame is present in the uip_buf buffer. When the |
hudakz | 0:5350a66d5279 | 83 | uip_arp_arpin() function returns, the contents of the uip_buf |
hudakz | 0:5350a66d5279 | 84 | buffer should be sent out on the Ethernet if the uip_len variable |
hudakz | 0:5350a66d5279 | 85 | is > 0. */ |
hudakz | 0:5350a66d5279 | 86 | void uip_arp_arpin(void); |
hudakz | 0:5350a66d5279 | 87 | |
hudakz | 0:5350a66d5279 | 88 | /* The uip_arp_out() function should be called when an IP packet |
hudakz | 0:5350a66d5279 | 89 | should be sent out on the Ethernet. This function creates an |
hudakz | 0:5350a66d5279 | 90 | Ethernet header before the IP header in the uip_buf buffer. The |
hudakz | 0:5350a66d5279 | 91 | Ethernet header will have the correct Ethernet MAC destination |
hudakz | 0:5350a66d5279 | 92 | address filled in if an ARP table entry for the destination IP |
hudakz | 0:5350a66d5279 | 93 | address (or the IP address of the default router) is present. If no |
hudakz | 0:5350a66d5279 | 94 | such table entry is found, the IP packet is overwritten with an ARP |
hudakz | 0:5350a66d5279 | 95 | request and we rely on TCP to retransmit the packet that was |
hudakz | 0:5350a66d5279 | 96 | overwritten. In any case, the uip_len variable holds the length of |
hudakz | 0:5350a66d5279 | 97 | the Ethernet frame that should be transmitted. */ |
hudakz | 0:5350a66d5279 | 98 | void uip_arp_out(void); |
hudakz | 0:5350a66d5279 | 99 | |
hudakz | 0:5350a66d5279 | 100 | /* The uip_arp_timer() function should be called every ten seconds. It |
hudakz | 0:5350a66d5279 | 101 | is responsible for flushing old entries in the ARP table. */ |
hudakz | 0:5350a66d5279 | 102 | void uip_arp_timer(void); |
hudakz | 0:5350a66d5279 | 103 | |
hudakz | 0:5350a66d5279 | 104 | /** @} */ |
hudakz | 0:5350a66d5279 | 105 | |
hudakz | 0:5350a66d5279 | 106 | /** |
hudakz | 0:5350a66d5279 | 107 | * \addtogroup uipconffunc |
hudakz | 0:5350a66d5279 | 108 | * @{ |
hudakz | 0:5350a66d5279 | 109 | */ |
hudakz | 0:5350a66d5279 | 110 | |
hudakz | 0:5350a66d5279 | 111 | /** |
hudakz | 0:5350a66d5279 | 112 | * Specifiy the Ethernet MAC address. |
hudakz | 0:5350a66d5279 | 113 | * |
hudakz | 0:5350a66d5279 | 114 | * The ARP code needs to know the MAC address of the Ethernet card in |
hudakz | 0:5350a66d5279 | 115 | * order to be able to respond to ARP queries and to generate working |
hudakz | 0:5350a66d5279 | 116 | * Ethernet headers. |
hudakz | 0:5350a66d5279 | 117 | * |
hudakz | 0:5350a66d5279 | 118 | * \note This macro only specifies the Ethernet MAC address to the ARP |
hudakz | 0:5350a66d5279 | 119 | * code. It cannot be used to change the MAC address of the Ethernet |
hudakz | 0:5350a66d5279 | 120 | * card. |
hudakz | 0:5350a66d5279 | 121 | * |
hudakz | 0:5350a66d5279 | 122 | * \param eaddr A pointer to a struct uip_eth_addr containing the |
hudakz | 0:5350a66d5279 | 123 | * Ethernet MAC address of the Ethernet card. |
hudakz | 0:5350a66d5279 | 124 | * |
hudakz | 0:5350a66d5279 | 125 | * \hideinitializer |
hudakz | 0:5350a66d5279 | 126 | */ |
hudakz | 0:5350a66d5279 | 127 | #define uip_setethaddr(eaddr) \ |
hudakz | 0:5350a66d5279 | 128 | do \ |
hudakz | 0:5350a66d5279 | 129 | { \ |
hudakz | 0:5350a66d5279 | 130 | uip_ethaddr.addr[0] = eaddr.addr[0]; \ |
hudakz | 0:5350a66d5279 | 131 | uip_ethaddr.addr[1] = eaddr.addr[1]; \ |
hudakz | 0:5350a66d5279 | 132 | uip_ethaddr.addr[2] = eaddr.addr[2]; \ |
hudakz | 0:5350a66d5279 | 133 | uip_ethaddr.addr[3] = eaddr.addr[3]; \ |
hudakz | 0:5350a66d5279 | 134 | uip_ethaddr.addr[4] = eaddr.addr[4]; \ |
hudakz | 0:5350a66d5279 | 135 | uip_ethaddr.addr[5] = eaddr.addr[5]; \ |
hudakz | 0:5350a66d5279 | 136 | } while(0) |
hudakz | 0:5350a66d5279 | 137 | |
hudakz | 0:5350a66d5279 | 138 | /** @} */ |
hudakz | 0:5350a66d5279 | 139 | |
hudakz | 0:5350a66d5279 | 140 | /** @} */ |
hudakz | 0:5350a66d5279 | 141 | #endif /* __UIP_ARP_H__ */ |
hudakz | 0:5350a66d5279 | 142 |