Free (GPLv2) TCP/IP stack developed by TASS Belgium

Dependents:   lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pico_icmp6.h Source File

pico_icmp6.h

00001 /*********************************************************************
00002    PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
00003    See LICENSE and COPYING for usage.
00004 
00005    .
00006 
00007  *********************************************************************/
00008 #ifndef _INCLUDE_PICO_ICMP6
00009 #define _INCLUDE_PICO_ICMP6
00010 #include "pico_addressing.h"
00011 #include "pico_protocol.h"
00012 #include "pico_mld.h"
00013 /* ICMP header sizes */
00014 #define PICO_ICMP6HDR_DRY_SIZE          4
00015 #define PICO_ICMP6HDR_ECHO_REQUEST_SIZE 8
00016 #define PICO_ICMP6HDR_DEST_UNREACH_SIZE 8
00017 #define PICO_ICMP6HDR_TIME_XCEEDED_SIZE 8
00018 #define PICO_ICMP6HDR_PARAM_PROBLEM_SIZE 8
00019 #define PICO_ICMP6HDR_NEIGH_SOL_SIZE    24
00020 #define PICO_ICMP6HDR_NEIGH_ADV_SIZE    24
00021 #define PICO_ICMP6HDR_ROUTER_SOL_SIZE   8
00022 #define PICO_ICMP6HDR_ROUTER_ADV_SIZE   16
00023 #define PICO_ICMP6HDR_REDIRECT_SIZE     40
00024 
00025 /* ICMP types */
00026 #define PICO_ICMP6_DEST_UNREACH        1
00027 #define PICO_ICMP6_PKT_TOO_BIG         2
00028 #define PICO_ICMP6_TIME_EXCEEDED       3
00029 #define PICO_ICMP6_PARAM_PROBLEM       4
00030 #define PICO_ICMP6_ECHO_REQUEST        128
00031 #define PICO_ICMP6_ECHO_REPLY          129
00032 #define PICO_ICMP6_ROUTER_SOL          133
00033 #define PICO_ICMP6_ROUTER_ADV          134
00034 #define PICO_ICMP6_NEIGH_SOL           135
00035 #define PICO_ICMP6_NEIGH_ADV           136
00036 #define PICO_ICMP6_REDIRECT            137
00037 
00038 /* destination unreachable codes */
00039 #define PICO_ICMP6_UNREACH_NOROUTE     0
00040 #define PICO_ICMP6_UNREACH_ADMIN       1
00041 #define PICO_ICMP6_UNREACH_SRCSCOPE    2
00042 #define PICO_ICMP6_UNREACH_ADDR        3
00043 #define PICO_ICMP6_UNREACH_PORT        4
00044 #define PICO_ICMP6_UNREACH_SRCFILTER   5
00045 #define PICO_ICMP6_UNREACH_REJROUTE    6
00046 
00047 /* time exceeded codes */
00048 #define PICO_ICMP6_TIMXCEED_INTRANS    0
00049 #define PICO_ICMP6_TIMXCEED_REASS      1
00050 
00051 /* parameter problem codes */
00052 #define PICO_ICMP6_PARAMPROB_HDRFIELD  0
00053 #define PICO_ICMP6_PARAMPROB_NXTHDR    1
00054 #define PICO_ICMP6_PARAMPROB_IPV6OPT   2
00055 
00056 /* ping error codes */
00057 #define PICO_PING6_ERR_REPLIED         0
00058 #define PICO_PING6_ERR_TIMEOUT         1
00059 #define PICO_PING6_ERR_UNREACH         2
00060 #define PICO_PING6_ERR_ABORTED         3
00061 #define PICO_PING6_ERR_PENDING         0xFFFF
00062 
00063 /* ND configuration */
00064 #define PICO_ND_MAX_FRAMES_QUEUED      4 /* max frames queued while awaiting address resolution */
00065 
00066 /* ND RFC constants */
00067 #define PICO_ND_MAX_SOLICIT            3
00068 #define PICO_ND_MAX_NEIGHBOR_ADVERT    3
00069 #define PICO_ND_DELAY_INCOMPLETE       1000 /* msec */
00070 #define PICO_ND_DELAY_FIRST_PROBE_TIME 5000 /* msec */
00071 
00072 /* neighbor discovery options */
00073 #define PICO_ND_OPT_LLADDR_SRC         1
00074 #define PICO_ND_OPT_LLADDR_TGT         2
00075 #define PICO_ND_OPT_PREFIX             3
00076 #define PICO_ND_OPT_REDIRECT           4
00077 #define PICO_ND_OPT_MTU                5
00078 #define PICO_ND_OPT_RDNSS             25 /* RFC 5006 */
00079 
00080 /* ND advertisement flags */
00081 #define PICO_ND_ROUTER             0x80000000
00082 #define PICO_ND_SOLICITED          0x40000000
00083 #define PICO_ND_OVERRIDE           0x20000000
00084 #define IS_ROUTER(x) (long_be(x->msg.info.neigh_adv.rsor) & (PICO_ND_ROUTER))           /* router flag set? */
00085 #define IS_SOLICITED(x) (long_be(x->msg.info.neigh_adv.rsor) & (PICO_ND_SOLICITED))     /* solicited flag set? */
00086 #define IS_OVERRIDE(x) (long_be(x->msg.info.neigh_adv.rsor) & (PICO_ND_OVERRIDE))   /* override flag set? */
00087 
00088 #define PICO_ND_PREFIX_LIFETIME_INF    0xFFFFFFFFu
00089 /* #define PICO_ND_DESTINATION_LRU_TIME   600000u / * msecs (10min) * / */
00090 
00091 /* custom defines */
00092 #define PICO_ICMP6_ND_UNICAST          0
00093 #define PICO_ICMP6_ND_ANYCAST          1
00094 #define PICO_ICMP6_ND_SOLICITED        2
00095 #define PICO_ICMP6_ND_DAD              3
00096 
00097 #define PICO_ICMP6_MAX_RTR_SOL_DELAY   1000
00098 
00099 #define PICO_SIZE_ICMP6HDR ((sizeof(struct pico_icmp6_hdr)))
00100 #define PICO_ICMP6_OPT_LLADDR_SIZE (8)
00101 
00102 extern struct pico_protocol pico_proto_icmp6;
00103 
00104 PACKED_STRUCT_DEF pico_icmp6_hdr {
00105     uint8_t type;
00106     uint8_t code;
00107     uint16_t crc;
00108 
00109     PACKED_UNION_DEF icmp6_msg_u {
00110         /* error messages */
00111         PACKED_UNION_DEF icmp6_err_u {
00112             PEDANTIC_STRUCT_DEF dest_unreach_s {
00113                 uint32_t unused;
00114             } dest_unreach;
00115             PEDANTIC_STRUCT_DEF pkt_too_big_s {
00116                 uint32_t mtu;
00117             } pkt_too_big;
00118             PEDANTIC_STRUCT_DEF time_exceeded_s {
00119                 uint32_t unused;
00120             } time_exceeded;
00121             PEDANTIC_STRUCT_DEF param_problem_s {
00122                 uint32_t ptr;
00123             } param_problem;
00124         } err;
00125 
00126         /* informational messages */
00127         PACKED_UNION_DEF icmp6_info_u {
00128             PEDANTIC_STRUCT_DEF echo_request_s {
00129                 uint16_t id;
00130                 uint16_t seq;
00131             } echo_request;
00132             PEDANTIC_STRUCT_DEF echo_reply_s {
00133                 uint16_t id;
00134                 uint16_t seq;
00135             } echo_reply;
00136             PEDANTIC_STRUCT_DEF router_sol_s {
00137                 uint32_t unused;
00138             } router_sol;
00139             PEDANTIC_STRUCT_DEF router_adv_s {
00140                 uint8_t hop;
00141                 uint8_t mor;
00142                 uint16_t life_time;
00143                 uint32_t reachable_time;
00144                 uint32_t retrans_time;
00145             } router_adv;
00146             PEDANTIC_STRUCT_DEF neigh_sol_s {
00147                 uint32_t unused;
00148                 struct pico_ip6 target;
00149             } neigh_sol;
00150             PEDANTIC_STRUCT_DEF neigh_adv_s {
00151                 uint32_t rsor;
00152                 struct pico_ip6 target;
00153             } neigh_adv;
00154             PEDANTIC_STRUCT_DEF redirect_s {
00155                 uint32_t reserved;
00156                 struct pico_ip6 target;
00157                 struct pico_ip6 dest;
00158             } redirect;
00159             PEDANTIC_STRUCT_DEF mld_s { 
00160                 uint16_t max_resp_time;
00161                 uint16_t reserved;
00162                 struct pico_ip6 mmcast_group;
00163                 /*MLDv2*/
00164                 uint8_t reserverd; // With S and QRV
00165                 uint8_t QQIC;
00166                 uint16_t nbr_src;
00167                 struct pico_ip6 src[0];
00168             } mld;          
00169         } info;
00170     } msg;
00171 };
00172 
00173 PACKED_STRUCT_DEF pico_icmp6_opt_lladdr
00174 {
00175     uint8_t type;
00176     uint8_t len;
00177     PACKED_UNION_DEF icmp6_opt_hw_addr_u {
00178         struct pico_eth mac;
00179     } addr;
00180 };
00181 
00182 PACKED_STRUCT_DEF pico_icmp6_opt_prefix
00183 {
00184     uint8_t type;
00185     uint8_t len;
00186     uint8_t prefix_len;
00187     uint8_t res : 6;
00188     uint8_t aac : 1;
00189     uint8_t onlink : 1;
00190     uint32_t val_lifetime;
00191     uint32_t pref_lifetime;
00192     uint32_t reserved;
00193     struct pico_ip6 prefix;
00194 };
00195 
00196 PACKED_STRUCT_DEF pico_icmp6_opt_mtu
00197 {
00198     uint8_t type;
00199     uint8_t len;
00200     uint16_t res;
00201     uint32_t mtu;
00202 };
00203 
00204 PACKED_STRUCT_DEF pico_icmp6_opt_redirect
00205 {
00206     uint8_t type;
00207     uint8_t len;
00208     uint16_t res0;
00209     uint32_t res1;
00210 };
00211 
00212 PACKED_STRUCT_DEF pico_icmp6_opt_rdnss
00213 {
00214     uint8_t type;
00215     uint8_t len;
00216     uint16_t res0;
00217     uint32_t lifetime;
00218     struct pico_ip6 *addr;
00219 };
00220 
00221 PACKED_STRUCT_DEF pico_icmp6_opt_na
00222 {
00223     uint8_t type;
00224     uint8_t len;
00225 };
00226 
00227 struct pico_icmp6_stats
00228 {
00229     unsigned long size;
00230     unsigned long seq;
00231     pico_time time;
00232     unsigned long ttl;
00233     int err;
00234     struct pico_ip6 dst;
00235 };
00236 
00237 int pico_icmp6_ping(char *dst, int count, int interval, int timeout, int size, void (*cb)(struct pico_icmp6_stats *), struct pico_device *dev);
00238 int pico_icmp6_ping_abort(int id);
00239 
00240 int pico_icmp6_neighbor_solicitation(struct pico_device *dev, struct pico_ip6 *dst, uint8_t type);
00241 int pico_icmp6_neighbor_advertisement(struct pico_frame *f, struct pico_ip6 *target);
00242 int pico_icmp6_router_solicitation(struct pico_device *dev, struct pico_ip6 *src);
00243 
00244 int pico_icmp6_port_unreachable(struct pico_frame *f);
00245 int pico_icmp6_proto_unreachable(struct pico_frame *f);
00246 int pico_icmp6_dest_unreachable(struct pico_frame *f);
00247 int pico_icmp6_ttl_expired(struct pico_frame *f);
00248 int pico_icmp6_packet_filtered(struct pico_frame *f);
00249 int pico_icmp6_parameter_problem(struct pico_frame *f, uint8_t problem, uint32_t ptr);
00250 int pico_icmp6_pkt_too_big(struct pico_frame *f);
00251 int pico_icmp6_frag_expired(struct pico_frame *f);
00252 
00253 uint16_t pico_icmp6_checksum(struct pico_frame *f);
00254 int pico_icmp6_router_advertisement(struct pico_device *dev, struct pico_ip6 *dst);
00255 
00256 #endif