Mbed library for ENC28J60 Ethernet modules. Full support for TCP/IP and UDP Server, Client and HTTP server (webserver). DHCP and DNS is included.

Dependents:   mBuino_ENC28_MQTT Nucleo_Web_ENC28J60 Nucleo_Web_ENC28J60_ADC Serial_over_Ethernet ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uip_arp.h Source File

uip_arp.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup uip
00003  * @{
00004  */
00005 /**
00006  * \addtogroup uiparp
00007  * @{
00008  */
00009 /**
00010  * \file
00011  * Macros and definitions for the ARP module.
00012  * \author Adam Dunkels <adam@dunkels.com>
00013  */
00014 /*
00015  * Copyright (c) 2001-2003, Adam Dunkels.
00016  * All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions
00020  * are met:
00021  * 1. Redistributions of source code must retain the above copyright
00022  *    notice, this list of conditions and the following disclaimer.
00023  * 2. Redistributions in binary form must reproduce the above copyright
00024  *    notice, this list of conditions and the following disclaimer in the
00025  *    documentation and/or other materials provided with the distribution.
00026  * 3. The name of the author may not be used to endorse or promote
00027  *    products derived from this software without specific prior
00028  *    written permission.
00029  *
00030  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00031  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00032  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00033  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00034  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00035  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00036  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00037  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00038  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00039  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00040  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041  *
00042  * This file is part of the UIP TCP/IP stack.
00043  *
00044  * $Id: uip_arp.h,v 1.5 2006/06/11 21:46:39 adam Exp $
00045  *
00046  */
00047 #ifndef __UIP_ARP_H__
00048 #define __UIP_ARP_H__
00049 
00050 #include "uip.h"
00051 
00052 extern struct uip_eth_addr  uip_ethaddr;
00053 
00054 /**
00055  * The Ethernet header.
00056  */
00057 struct uip_eth_hdr
00058 {
00059     struct uip_eth_addr dest;
00060     struct uip_eth_addr src;
00061     u16_t               type;
00062 };
00063 
00064 #define UIP_ETHTYPE_ARP 0x0806
00065 #define UIP_ETHTYPE_IP  0x0800
00066 #define UIP_ETHTYPE_IP6 0x86dd
00067 
00068 /* The uip_arp_init() function must be called before any of the other
00069    ARP functions. */
00070 void    uip_arp_init(void);
00071 
00072 /* The uip_arp_ipin() function should be called whenever an IP packet
00073    arrives from the Ethernet. This function refreshes the ARP table or
00074    inserts a new mapping if none exists. The function assumes that an
00075    IP packet with an Ethernet header is present in the uip_buf buffer
00076    and that the length of the packet is in the uip_len variable. */
00077 void    uip_arp_ipin(void);
00078 
00079 //#define uip_arp_ipin()
00080 /* The uip_arp_arpin() should be called when an ARP packet is received
00081    by the Ethernet driver. This function also assumes that the
00082    Ethernet frame is present in the uip_buf buffer. When the
00083    uip_arp_arpin() function returns, the contents of the uip_buf
00084    buffer should be sent out on the Ethernet if the uip_len variable
00085    is > 0. */
00086 void    uip_arp_arpin(void);
00087 
00088 /* The uip_arp_out() function should be called when an IP packet
00089    should be sent out on the Ethernet. This function creates an
00090    Ethernet header before the IP header in the uip_buf buffer. The
00091    Ethernet header will have the correct Ethernet MAC destination
00092    address filled in if an ARP table entry for the destination IP
00093    address (or the IP address of the default router) is present. If no
00094    such table entry is found, the IP packet is overwritten with an ARP
00095    request and we rely on TCP to retransmit the packet that was
00096    overwritten. In any case, the uip_len variable holds the length of
00097    the Ethernet frame that should be transmitted. */
00098 void    uip_arp_out(void);
00099 
00100 /* The uip_arp_timer() function should be called every ten seconds. It
00101    is responsible for flushing old entries in the ARP table. */
00102 void    uip_arp_timer(void);
00103 
00104 /** @} */
00105 
00106 /**
00107  * \addtogroup uipconffunc
00108  * @{
00109  */
00110 
00111 /**
00112  * Specifiy the Ethernet MAC address.
00113  *
00114  * The ARP code needs to know the MAC address of the Ethernet card in
00115  * order to be able to respond to ARP queries and to generate working
00116  * Ethernet headers.
00117  *
00118  * \note This macro only specifies the Ethernet MAC address to the ARP
00119  * code. It cannot be used to change the MAC address of the Ethernet
00120  * card.
00121  *
00122  * \param eaddr A pointer to a struct uip_eth_addr containing the
00123  * Ethernet MAC address of the Ethernet card.
00124  *
00125  * \hideinitializer
00126  */
00127 #define uip_setethaddr(eaddr) \
00128     do { \
00129         uip_ethaddr.addr[0] = eaddr.addr[0]; \
00130         uip_ethaddr.addr[1] = eaddr.addr[1]; \
00131         uip_ethaddr.addr[2] = eaddr.addr[2]; \
00132         uip_ethaddr.addr[3] = eaddr.addr[3]; \
00133         uip_ethaddr.addr[4] = eaddr.addr[4]; \
00134         uip_ethaddr.addr[5] = eaddr.addr[5]; \
00135     } while (0)
00136 
00137     /** @} */
00138 
00139     /** @} */
00140 #endif /* __UIP_ARP_H__ */
00141