SAMV71 Xplained Ultra Software Package 1.5

MiniIp.h

00001 /* ----------------------------------------------------------------------------
00002 *         SAM Software Package License
00003 * ----------------------------------------------------------------------------
00004 * Copyright (c) 2015, 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 
00031 #ifndef _MINIIP_H
00032 #define _MINIIP_H
00033 
00034 /*---------------------------------------------------------------------------
00035  *         Include
00036  *---------------------------------------------------------------------------*/
00037 
00038 #include <stdint.h>
00039 
00040 /*---------------------------------------------------------------------------
00041  *         Define
00042  *---------------------------------------------------------------------------*/
00043 
00044 /** Ethernet types */
00045 #define ETH_PROT_IP             0x0800 /**< 2048  (0x0800) IPv4 */
00046 #define ETH_PROT_ARP            0x0806 /**< 2054  (0x0806) ARP */
00047 #define ETH_PROT_APPLETALK      0x8019 /**< 32923 (0x8019) Appletalk */
00048 #define ETH_PROT_IPV6           0x86DD /**< 34525 (0x86DD) IPv6 */
00049 
00050 /** ARP OP codes */
00051 #define ARP_REQUEST             0x0001 /**< ARP Request packet */
00052 #define ARP_REPLY               0x0002 /**< ARP Reply packet */
00053 
00054 /** IP protocols code */
00055 /* http://www.iana.org/assignments/protocol-numbers */
00056 #define IP_PROT_ICMP            1
00057 #define IP_PROT_IP              4
00058 #define IP_PROT_TCP             6
00059 #define IP_PROT_UDP             17
00060 
00061 /** ICMP types */
00062 /* http://www.iana.org/assignments/icmp-parameters */
00063 #define ICMP_ECHO_REPLY         0x00 /**< Echo reply (used to ping) */
00064 /* 1 and 2  Reserved */
00065 #define ICMP_DEST_UNREACHABLE   0x03 /**< Destination Unreachable */
00066 #define ICMP_SOURCE_QUENCH      0x04 /**< Source Quench */
00067 #define ICMP_REDIR_MESSAGE      0x05 /**< Redirect Message */
00068 #define ICMP_ALT_HOST_ADD       0x06 /**< Alternate Host Address */
00069 /*  0x07    Reserved */
00070 #define ICMP_ECHO_REQUEST       0x08 /**< Echo Request */
00071 #define ICMP_ROUTER_ADV         0x09 /**< Router Advertisement */
00072 #define ICMP_ROUTER_SOL         0x0A /**< Router Solicitation */
00073 #define ICMP_TIME_EXC           0x0B /**< Time Exceeded */
00074 #define ICMP_PARAM_PB           0x0C /**< Parameter Problem: Bad IP header */
00075 #define ICMP_TIMESTAMP          0x0D /**< Timestamp */
00076 #define ICMP_TIMESTAMP_REP      0x0E /**< Timestamp Reply */
00077 #define ICMP_INFO_REQ           0x0F /**< Information Request */
00078 #define ICMP_INFO_REPLY         0x10 /**< Information Reply */
00079 #define ICMP_ADD_MASK_REQ       0x11 /**< Address Mask Request */
00080 #define ICMP_ADD_MASK_REP       0x12 /**< Address Mask Reply */
00081 /*  0x13    Reserved for security */
00082 /*  0X14 through 0x1D Reserved for robustness experiment */
00083 #define ICMP_TRACEROUTE         0x1E /**< Traceroute */
00084 #define ICMP_DAT_CONV_ERROR     0x1F /**< Datagram Conversion Error */
00085 #define ICMP_MOB_HOST_RED       0x20 /**< Mobile Host Redirect */
00086 #define ICMP_W_A_Y              0x21 /**< Where-Are-You (originally meant for
00087                                           IPv6) */
00088 #define ICMP_H_I_A              0x22 /**< Here-I-Am (originally meant for IPv6)
00089                                       */
00090 #define ICMP_MOB_REG_REQ        0x23 /**< Mobile Registration Request */
00091 #define ICMP_MOB_REG_REP        0x24 /**< Mobile Registration Reply */
00092 #define ICMP_DOM_NAME_REQ       0x25 /**< Domain Name Request */
00093 #define ICMP_DOM_NAME_REP       0x26 /**< Domain Name Reply */
00094 #define ICMP_SKIP_ALGO_PROT     0x27 /**< SKIP Algorithm Discovery Protocol,
00095                                           Simple Key-Management for
00096                                           Internet Protocol */
00097 #define ICMP_PHOTURIS           0x28 /**< Photuris, Security failures */
00098 #define ICMP_EXP_MOBIL          0x29 /**< ICMP for experimental mobility
00099                                           protocols such as Seamoby [RFC4065] */
00100 /* 0x2A through 0xFF  Reserved */
00101 
00102 /*---------------------------------------------------------------------------
00103  *         Macros
00104  *---------------------------------------------------------------------------*/
00105 
00106 /** Swap 2 bytes of a word */
00107 #define SWAP16(x)   (((x & 0xff) << 8) | (x >> 8))
00108 
00109 /*---------------------------------------------------------------------------
00110  *         Types
00111  *---------------------------------------------------------------------------*/
00112 
00113 #pragma pack(1)
00114 
00115 /** Ethernet header structure */
00116 typedef struct _EthHdr {
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     uint16_t      ar_hrd;     /**< Format of hardware address */
00125     uint16_t      ar_pro;     /**< Format of protocol address */
00126     uint8_t       ar_hln;     /**< Length of hardware address */
00127     uint8_t       ar_pln;     /**< Length of protocol address */
00128     uint16_t      ar_op;      /**< Operation */
00129     uint8_t       ar_sha[6];  /**< Sender hardware address */
00130     uint8_t       ar_spa[4];  /**< Sender protocol address */
00131     uint8_t       ar_tha[6];  /**< Target hardware address */
00132     uint8_t       ar_tpa[4];  /**< Target protocol address */
00133 } ArpHeader, *PArpHeader;  /* GCC */
00134 
00135 /** IP Header structure */
00136 typedef struct _IPheader {
00137     uint8_t       ip_hl_v;    /**< header length and version */
00138     uint8_t       ip_tos;     /**< type of service */
00139     uint16_t      ip_len;     /**< total length */
00140     uint16_t      ip_id;      /**< identification */
00141     uint16_t      ip_off;     /**< fragment offset field */
00142     uint8_t       ip_ttl;     /**< time to live */
00143     uint8_t       ip_p;       /**< protocol */
00144     uint16_t      ip_sum;     /**< checksum */
00145     uint8_t       ip_src[4];  /**< Source IP address */
00146     uint8_t       ip_dst[4];  /**< Destination IP address */
00147     uint16_t      udp_src;    /**< UDP source port */
00148     uint16_t      udp_dst;    /**< UDP destination port */
00149     uint16_t      udp_len;    /**< Length of UDP packet */
00150     uint16_t      udp_xsum;   /**< Checksum */
00151 } IpHeader, *PIpHeader;    /* GCC */
00152 
00153 /** ICMP echo header structure */
00154 typedef struct _IcmpEchoHdr {
00155     uint8_t       type;       /**< type of message */
00156     uint8_t       code;       /**< type subcode */
00157     uint16_t      cksum;      /**< ones complement cksum of struct */
00158     uint16_t      id;         /**< identifier */
00159     uint16_t      seq;        /**< sequence number */
00160 } IcmpEchoHeader, *PIcmpEchoHeader;    /* GCC */
00161 
00162 /** Ethernet packet structure */
00163 typedef struct _EthPacket {
00164     EthHeader           EthHdr;
00165     ArpHeader           ArpHdr;
00166 } EthPacket, *PEthPacket;  /* GCC */
00167 
00168 #pragma pack()
00169 
00170 /*----------------------------------------------------------------------------
00171  *         Global functions
00172  *----------------------------------------------------------------------------*/
00173 
00174 extern uint16_t IcmpChksum(uint16_t *p, uint32_t len);
00175 
00176 
00177 #endif /*  #ifndef _MINIIP_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines