SAMV71 Xplained Ultra Software Package 1.3

MiniIp.h

00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 #ifndef _MINIIP_H
00031 #define _MINIIP_H
00032 
00033 /*---------------------------------------------------------------------------
00034  *         Include
00035  *---------------------------------------------------------------------------*/
00036 
00037 #include <stdint.h>
00038 
00039 /*---------------------------------------------------------------------------
00040  *         Define
00041  *---------------------------------------------------------------------------*/
00042 
00043 /** Ethernet types */
00044 #define ETH_PROT_IP             0x0800 /**< 2048  (0x0800) IPv4 */
00045 #define ETH_PROT_ARP            0x0806 /**< 2054  (0x0806) ARP */
00046 #define ETH_PROT_APPLETALK      0x8019 /**< 32923 (0x8019) Appletalk */
00047 #define ETH_PROT_IPV6           0x86DD /**< 34525 (0x86DD) IPv6 */
00048 
00049 /** ARP OP codes */
00050 #define ARP_REQUEST             0x0001 /**< ARP Request packet */
00051 #define ARP_REPLY               0x0002 /**< ARP Reply packet */
00052 
00053 /** IP protocols code */
00054 /* http://www.iana.org/assignments/protocol-numbers */
00055 #define IP_PROT_ICMP            1
00056 #define IP_PROT_IP              4
00057 #define IP_PROT_TCP             6
00058 #define IP_PROT_UDP             17
00059 
00060 /** ICMP types */
00061 /* http://www.iana.org/assignments/icmp-parameters */
00062 #define ICMP_ECHO_REPLY         0x00 /**< Echo reply (used to ping) */
00063                     /* 1 and 2  Reserved */
00064 #define ICMP_DEST_UNREACHABLE   0x03 /**< Destination Unreachable */
00065 #define ICMP_SOURCE_QUENCH      0x04 /**< Source Quench */
00066 #define ICMP_REDIR_MESSAGE      0x05 /**< Redirect Message */
00067 #define ICMP_ALT_HOST_ADD       0x06 /**< Alternate Host Address */
00068                     /*  0x07    Reserved */
00069 #define ICMP_ECHO_REQUEST       0x08 /**< Echo Request */
00070 #define ICMP_ROUTER_ADV         0x09 /**< Router Advertisement */
00071 #define ICMP_ROUTER_SOL         0x0A /**< Router Solicitation */
00072 #define ICMP_TIME_EXC           0x0B /**< Time Exceeded */
00073 #define ICMP_PARAM_PB           0x0C /**< Parameter Problem: Bad IP header */
00074 #define ICMP_TIMESTAMP          0x0D /**< Timestamp */
00075 #define ICMP_TIMESTAMP_REP      0x0E /**< Timestamp Reply */
00076 #define ICMP_INFO_REQ           0x0F /**< Information Request */
00077 #define ICMP_INFO_REPLY         0x10 /**< Information Reply */
00078 #define ICMP_ADD_MASK_REQ       0x11 /**< Address Mask Request */
00079 #define ICMP_ADD_MASK_REP       0x12 /**< Address Mask Reply */
00080                              /*  0x13    Reserved for security */
00081                              /*  0X14 through 0x1D Reserved for robustness experiment */
00082 #define ICMP_TRACEROUTE         0x1E /**< Traceroute */
00083 #define ICMP_DAT_CONV_ERROR     0x1F /**< Datagram Conversion Error */
00084 #define ICMP_MOB_HOST_RED       0x20 /**< Mobile Host Redirect */
00085 #define ICMP_W_A_Y              0x21 /**< Where-Are-You (originally meant for
00086                                           IPv6) */
00087 #define ICMP_H_I_A              0x22 /**< Here-I-Am (originally meant for IPv6)
00088                                       */
00089 #define ICMP_MOB_REG_REQ        0x23 /**< Mobile Registration Request */
00090 #define ICMP_MOB_REG_REP        0x24 /**< Mobile Registration Reply */
00091 #define ICMP_DOM_NAME_REQ       0x25 /**< Domain Name Request */
00092 #define ICMP_DOM_NAME_REP       0x26 /**< Domain Name Reply */
00093 #define ICMP_SKIP_ALGO_PROT     0x27 /**< SKIP Algorithm Discovery Protocol,
00094                                           Simple Key-Management for
00095                                           Internet Protocol */
00096 #define ICMP_PHOTURIS           0x28 /**< Photuris, Security failures */
00097 #define ICMP_EXP_MOBIL          0x29 /**< ICMP for experimental mobility
00098                                           protocols such as Seamoby [RFC4065] */
00099                      /* 0x2A through 0xFF  Reserved */
00100 
00101 /*---------------------------------------------------------------------------
00102  *         Macros
00103  *---------------------------------------------------------------------------*/
00104 
00105 /** Swap 2 bytes of a word */
00106 #define SWAP16(x)   (((x & 0xff) << 8) | (x >> 8))
00107 
00108 /*---------------------------------------------------------------------------
00109  *         Types
00110  *---------------------------------------------------------------------------*/
00111 
00112 #pragma pack(1)
00113 
00114 /** Ethernet header structure */
00115 typedef struct _EthHdr
00116 {
00117     uint8_t       et_dest[6]; /**< Destination node */
00118     uint8_t       et_src[6];  /**< Source node */
00119     uint16_t      et_protlen; /**< Protocol or length */
00120 } EthHeader, *PEthHeader;  /* GCC */
00121 
00122 /** ARP header structure */
00123 typedef struct _ArpHdr
00124 {
00125     uint16_t      ar_hrd;     /**< Format of hardware address */
00126     uint16_t      ar_pro;     /**< Format of protocol address */
00127     uint8_t       ar_hln;     /**< Length of hardware address */
00128     uint8_t       ar_pln;     /**< Length of protocol address */
00129     uint16_t      ar_op;      /**< Operation */
00130     uint8_t       ar_sha[6];  /**< Sender hardware address */
00131     uint8_t       ar_spa[4];  /**< Sender protocol address */
00132     uint8_t       ar_tha[6];  /**< Target hardware address */
00133     uint8_t       ar_tpa[4];  /**< Target protocol address */
00134 } ArpHeader, *PArpHeader;  /* GCC */
00135 
00136 /** IP Header structure */
00137 typedef struct _IPheader {
00138     uint8_t       ip_hl_v;    /**< header length and version */
00139     uint8_t       ip_tos;     /**< type of service */
00140     uint16_t      ip_len;     /**< total length */
00141     uint16_t      ip_id;      /**< identification */
00142     uint16_t      ip_off;     /**< fragment offset field */
00143     uint8_t       ip_ttl;     /**< time to live */
00144     uint8_t       ip_p;       /**< protocol */
00145     uint16_t      ip_sum;     /**< checksum */
00146     uint8_t       ip_src[4];  /**< Source IP address */
00147     uint8_t       ip_dst[4];  /**< Destination IP address */
00148     uint16_t      udp_src;    /**< UDP source port */
00149     uint16_t      udp_dst;    /**< UDP destination port */
00150     uint16_t      udp_len;    /**< Length of UDP packet */
00151     uint16_t      udp_xsum;   /**< Checksum */
00152 } IpHeader, *PIpHeader;    /* GCC */
00153 
00154 /** ICMP echo header structure */
00155 typedef struct _IcmpEchoHdr {
00156     uint8_t       type;       /**< type of message */
00157     uint8_t       code;       /**< type subcode */
00158     uint16_t      cksum;      /**< ones complement cksum of struct */
00159     uint16_t      id;         /**< identifier */
00160     uint16_t      seq;        /**< sequence number */
00161 } IcmpEchoHeader, *PIcmpEchoHeader;    /* GCC */
00162 
00163 /** Ethernet packet structure */
00164 typedef struct _EthPacket
00165 {
00166     EthHeader           EthHdr;
00167     ArpHeader           ArpHdr;
00168 } EthPacket, *PEthPacket;  /* GCC */
00169 
00170 #pragma pack()
00171 
00172 /*----------------------------------------------------------------------------
00173  *         Global functions
00174  *----------------------------------------------------------------------------*/
00175 
00176 extern uint16_t IcmpChksum(uint16_t * p, uint32_t len);
00177 
00178 
00179 #endif /*  #ifndef _MINIIP_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines