mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
started with bug #48728: move protocol definitions to 'include/prot/*.h' files (started with some IPv4 protocols)
This commit is contained in:
parent
d95ab511d0
commit
dc7340bbd5
@ -66,34 +66,11 @@
|
|||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
#include "lwip/autoip.h"
|
#include "lwip/autoip.h"
|
||||||
#include "lwip/etharp.h"
|
#include "lwip/etharp.h"
|
||||||
|
#include "lwip/prot/autoip.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 169.254.0.0 */
|
|
||||||
#define AUTOIP_NET 0xA9FE0000
|
|
||||||
/* 169.254.1.0 */
|
|
||||||
#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100)
|
|
||||||
/* 169.254.254.255 */
|
|
||||||
#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF)
|
|
||||||
|
|
||||||
/* RFC 3927 Constants */
|
|
||||||
#define PROBE_WAIT 1 /* second (initial random delay) */
|
|
||||||
#define PROBE_MIN 1 /* second (minimum delay till repeated probe) */
|
|
||||||
#define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */
|
|
||||||
#define PROBE_NUM 3 /* (number of probe packets) */
|
|
||||||
#define ANNOUNCE_NUM 2 /* (number of announcement packets) */
|
|
||||||
#define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */
|
|
||||||
#define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */
|
|
||||||
#define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */
|
|
||||||
#define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */
|
|
||||||
#define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */
|
|
||||||
|
|
||||||
/* AutoIP client states */
|
|
||||||
#define AUTOIP_STATE_OFF 0
|
|
||||||
#define AUTOIP_STATE_PROBING 1
|
|
||||||
#define AUTOIP_STATE_ANNOUNCING 2
|
|
||||||
#define AUTOIP_STATE_BOUND 3
|
|
||||||
|
|
||||||
/** Pseudo random macro based on netif informations.
|
/** Pseudo random macro based on netif informations.
|
||||||
* You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */
|
* You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#include "lwip/autoip.h"
|
#include "lwip/autoip.h"
|
||||||
#include "lwip/dns.h"
|
#include "lwip/dns.h"
|
||||||
#include "lwip/etharp.h"
|
#include "lwip/etharp.h"
|
||||||
|
#include "lwip/prot/dhcp.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -384,6 +385,7 @@ dhcp_select(struct netif *netif)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The DHCP timer that checks for lease renewal/rebind timeouts.
|
* The DHCP timer that checks for lease renewal/rebind timeouts.
|
||||||
|
* Must be called once a minute (see @ref DHCP_COARSE_TIMER_SECS).
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
dhcp_coarse_tmr(void)
|
dhcp_coarse_tmr(void)
|
||||||
@ -419,7 +421,8 @@ dhcp_coarse_tmr(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DHCP transaction timeout handling
|
* DHCP transaction timeout handling (this function must be called every 500ms,
|
||||||
|
* see @ref DHCP_FINE_TIMER_MSECS).
|
||||||
*
|
*
|
||||||
* A DHCP server is expected to respond within a short period of time.
|
* A DHCP server is expected to respond within a short period of time.
|
||||||
* This timer checks whether an outstanding DHCP request is timed out.
|
* This timer checks whether an outstanding DHCP request is timed out.
|
||||||
@ -850,7 +853,8 @@ dhcp_network_changed(struct netif *netif)
|
|||||||
|
|
||||||
#if DHCP_DOES_ARP_CHECK
|
#if DHCP_DOES_ARP_CHECK
|
||||||
/**
|
/**
|
||||||
* Match an ARP reply with the offered IP address.
|
* Match an ARP reply with the offered IP address:
|
||||||
|
* check whether the offered IP address is not in use using ARP
|
||||||
*
|
*
|
||||||
* @param netif the network interface on which the reply was received
|
* @param netif the network interface on which the reply was received
|
||||||
* @param addr The IP address we received a reply from
|
* @param addr The IP address we received a reply from
|
||||||
@ -1241,7 +1245,7 @@ dhcp_reboot(struct netif *netif)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup dhcp4
|
* @ingroup dhcp4
|
||||||
* Release a DHCP lease.
|
* Release a DHCP lease (usually called before @ref dhcp_stop).
|
||||||
*
|
*
|
||||||
* @param netif network interface which must release its lease
|
* @param netif network interface which must release its lease
|
||||||
*/
|
*/
|
||||||
|
@ -53,9 +53,9 @@
|
|||||||
#include "lwip/raw.h"
|
#include "lwip/raw.h"
|
||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
#include "lwip/priv/tcp_priv.h"
|
#include "lwip/priv/tcp_priv.h"
|
||||||
#include "lwip/dhcp.h"
|
|
||||||
#include "lwip/autoip.h"
|
#include "lwip/autoip.h"
|
||||||
#include "lwip/stats.h"
|
#include "lwip/stats.h"
|
||||||
|
#include "lwip/prot/dhcp.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@
|
|||||||
* This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
|
* This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
|
||||||
* with RFC 3927.
|
* with RFC 3927.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* Please coordinate changes and requests with Dominik Spies
|
|
||||||
* <kontakt@dspies.de>
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LWIP_HDR_AUTOIP_H
|
#ifndef LWIP_HDR_AUTOIP_H
|
||||||
|
@ -50,15 +50,13 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** period (in seconds) of the application calling dhcp_coarse_tmr() */
|
/** period (in seconds) of the application calling dhcp_coarse_tmr() */
|
||||||
#define DHCP_COARSE_TIMER_SECS 60
|
#define DHCP_COARSE_TIMER_SECS 60
|
||||||
/** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
|
/** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
|
||||||
#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
|
#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
|
||||||
/** period (in milliseconds) of the application calling dhcp_fine_tmr() */
|
/** period (in milliseconds) of the application calling dhcp_fine_tmr() */
|
||||||
#define DHCP_FINE_TIMER_MSECS 500
|
#define DHCP_FINE_TIMER_MSECS 500
|
||||||
|
|
||||||
#define DHCP_CHADDR_LEN 16U
|
#define DHCP_BOOT_FILE_LEN 128U
|
||||||
#define DHCP_SNAME_LEN 64U
|
|
||||||
#define DHCP_FILE_LEN 128U
|
|
||||||
|
|
||||||
struct dhcp
|
struct dhcp
|
||||||
{
|
{
|
||||||
@ -97,181 +95,30 @@ struct dhcp
|
|||||||
u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */
|
u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */
|
||||||
#if LWIP_DHCP_BOOTP_FILE
|
#if LWIP_DHCP_BOOTP_FILE
|
||||||
ip_addr_t offered_si_addr;
|
ip_addr_t offered_si_addr;
|
||||||
char boot_file_name[DHCP_FILE_LEN];
|
char boot_file_name[DHCP_BOOT_FILE_LEN];
|
||||||
#endif /* LWIP_DHCP_BOOTPFILE */
|
#endif /* LWIP_DHCP_BOOTPFILE */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* MUST be compiled with "pack structs" or equivalent! */
|
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
|
||||||
# include "arch/bpstruct.h"
|
|
||||||
#endif
|
|
||||||
PACK_STRUCT_BEGIN
|
|
||||||
/** minimum set of fields of any DHCP message */
|
|
||||||
struct dhcp_msg
|
|
||||||
{
|
|
||||||
PACK_STRUCT_FLD_8(u8_t op);
|
|
||||||
PACK_STRUCT_FLD_8(u8_t htype);
|
|
||||||
PACK_STRUCT_FLD_8(u8_t hlen);
|
|
||||||
PACK_STRUCT_FLD_8(u8_t hops);
|
|
||||||
PACK_STRUCT_FIELD(u32_t xid);
|
|
||||||
PACK_STRUCT_FIELD(u16_t secs);
|
|
||||||
PACK_STRUCT_FIELD(u16_t flags);
|
|
||||||
PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr);
|
|
||||||
PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr);
|
|
||||||
PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr);
|
|
||||||
PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr);
|
|
||||||
PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]);
|
|
||||||
PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]);
|
|
||||||
PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]);
|
|
||||||
PACK_STRUCT_FIELD(u32_t cookie);
|
|
||||||
#define DHCP_MIN_OPTIONS_LEN 68U
|
|
||||||
/** make sure user does not configure this too small */
|
|
||||||
#if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
|
|
||||||
# undef DHCP_OPTIONS_LEN
|
|
||||||
#endif
|
|
||||||
/** allow this to be configured in lwipopts.h, but not too small */
|
|
||||||
#if (!defined(DHCP_OPTIONS_LEN))
|
|
||||||
/** set this to be sufficient for your options in outgoing DHCP msgs */
|
|
||||||
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
|
|
||||||
#endif
|
|
||||||
PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]);
|
|
||||||
} PACK_STRUCT_STRUCT;
|
|
||||||
PACK_STRUCT_END
|
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
|
||||||
# include "arch/epstruct.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
|
void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
|
||||||
/** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */
|
/** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */
|
||||||
#define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0)
|
#define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0)
|
||||||
void dhcp_cleanup(struct netif *netif);
|
void dhcp_cleanup(struct netif *netif);
|
||||||
/** start DHCP configuration */
|
|
||||||
err_t dhcp_start(struct netif *netif);
|
err_t dhcp_start(struct netif *netif);
|
||||||
/** enforce early lease renewal (not needed normally)*/
|
|
||||||
err_t dhcp_renew(struct netif *netif);
|
err_t dhcp_renew(struct netif *netif);
|
||||||
/** release the DHCP lease, usually called before dhcp_stop()*/
|
|
||||||
err_t dhcp_release(struct netif *netif);
|
err_t dhcp_release(struct netif *netif);
|
||||||
/** stop DHCP configuration */
|
|
||||||
void dhcp_stop(struct netif *netif);
|
void dhcp_stop(struct netif *netif);
|
||||||
/** inform server of our manual IP address */
|
|
||||||
void dhcp_inform(struct netif *netif);
|
void dhcp_inform(struct netif *netif);
|
||||||
/** Handle a possible change in the network configuration */
|
|
||||||
void dhcp_network_changed(struct netif *netif);
|
void dhcp_network_changed(struct netif *netif);
|
||||||
|
|
||||||
/** if enabled, check whether the offered IP address is not in use, using ARP */
|
|
||||||
#if DHCP_DOES_ARP_CHECK
|
#if DHCP_DOES_ARP_CHECK
|
||||||
void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr);
|
void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** check if DHCP supplied netif->ip_addr */
|
|
||||||
u8_t dhcp_supplied_address(const struct netif *netif);
|
u8_t dhcp_supplied_address(const struct netif *netif);
|
||||||
|
/* to be called every minute */
|
||||||
/** to be called every minute */
|
|
||||||
void dhcp_coarse_tmr(void);
|
void dhcp_coarse_tmr(void);
|
||||||
/** to be called every half second */
|
/* to be called every half second */
|
||||||
void dhcp_fine_tmr(void);
|
void dhcp_fine_tmr(void);
|
||||||
|
|
||||||
/** DHCP message item offsets and length */
|
|
||||||
#define DHCP_OP_OFS 0
|
|
||||||
#define DHCP_HTYPE_OFS 1
|
|
||||||
#define DHCP_HLEN_OFS 2
|
|
||||||
#define DHCP_HOPS_OFS 3
|
|
||||||
#define DHCP_XID_OFS 4
|
|
||||||
#define DHCP_SECS_OFS 8
|
|
||||||
#define DHCP_FLAGS_OFS 10
|
|
||||||
#define DHCP_CIADDR_OFS 12
|
|
||||||
#define DHCP_YIADDR_OFS 16
|
|
||||||
#define DHCP_SIADDR_OFS 20
|
|
||||||
#define DHCP_GIADDR_OFS 24
|
|
||||||
#define DHCP_CHADDR_OFS 28
|
|
||||||
#define DHCP_SNAME_OFS 44
|
|
||||||
#define DHCP_FILE_OFS 108
|
|
||||||
#define DHCP_MSG_LEN 236
|
|
||||||
|
|
||||||
#define DHCP_COOKIE_OFS DHCP_MSG_LEN
|
|
||||||
#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4)
|
|
||||||
|
|
||||||
#define DHCP_CLIENT_PORT 68
|
|
||||||
#define DHCP_SERVER_PORT 67
|
|
||||||
|
|
||||||
/** DHCP client states */
|
|
||||||
#define DHCP_STATE_OFF 0
|
|
||||||
#define DHCP_STATE_REQUESTING 1
|
|
||||||
#define DHCP_STATE_INIT 2
|
|
||||||
#define DHCP_STATE_REBOOTING 3
|
|
||||||
#define DHCP_STATE_REBINDING 4
|
|
||||||
#define DHCP_STATE_RENEWING 5
|
|
||||||
#define DHCP_STATE_SELECTING 6
|
|
||||||
#define DHCP_STATE_INFORMING 7
|
|
||||||
#define DHCP_STATE_CHECKING 8
|
|
||||||
/** not yet implemented \#define DHCP_STATE_PERMANENT 9 */
|
|
||||||
#define DHCP_STATE_BOUND 10
|
|
||||||
/** not yet implemented \#define DHCP_STATE_RELEASING 11 */
|
|
||||||
#define DHCP_STATE_BACKING_OFF 12
|
|
||||||
|
|
||||||
/** AUTOIP cooperation flags */
|
|
||||||
#define DHCP_AUTOIP_COOP_STATE_OFF 0
|
|
||||||
#define DHCP_AUTOIP_COOP_STATE_ON 1
|
|
||||||
|
|
||||||
#define DHCP_BOOTREQUEST 1
|
|
||||||
#define DHCP_BOOTREPLY 2
|
|
||||||
|
|
||||||
/** DHCP message types */
|
|
||||||
#define DHCP_DISCOVER 1
|
|
||||||
#define DHCP_OFFER 2
|
|
||||||
#define DHCP_REQUEST 3
|
|
||||||
#define DHCP_DECLINE 4
|
|
||||||
#define DHCP_ACK 5
|
|
||||||
#define DHCP_NAK 6
|
|
||||||
#define DHCP_RELEASE 7
|
|
||||||
#define DHCP_INFORM 8
|
|
||||||
|
|
||||||
/** DHCP hardware type, currently only ethernet is supported */
|
|
||||||
#define DHCP_HTYPE_ETH 1
|
|
||||||
|
|
||||||
#define DHCP_MAGIC_COOKIE 0x63825363UL
|
|
||||||
|
|
||||||
/* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */
|
|
||||||
|
|
||||||
/** BootP options */
|
|
||||||
#define DHCP_OPTION_PAD 0
|
|
||||||
#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
|
|
||||||
#define DHCP_OPTION_ROUTER 3
|
|
||||||
#define DHCP_OPTION_DNS_SERVER 6
|
|
||||||
#define DHCP_OPTION_HOSTNAME 12
|
|
||||||
#define DHCP_OPTION_IP_TTL 23
|
|
||||||
#define DHCP_OPTION_MTU 26
|
|
||||||
#define DHCP_OPTION_BROADCAST 28
|
|
||||||
#define DHCP_OPTION_TCP_TTL 37
|
|
||||||
#define DHCP_OPTION_NTP 42
|
|
||||||
#define DHCP_OPTION_END 255
|
|
||||||
|
|
||||||
/** DHCP options */
|
|
||||||
#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
|
|
||||||
#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
|
|
||||||
#define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
|
|
||||||
|
|
||||||
#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
|
|
||||||
#define DHCP_OPTION_MESSAGE_TYPE_LEN 1
|
|
||||||
|
|
||||||
#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
|
|
||||||
#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
|
|
||||||
|
|
||||||
#define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
|
|
||||||
#define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
|
|
||||||
|
|
||||||
#define DHCP_OPTION_T1 58 /* T1 renewal time */
|
|
||||||
#define DHCP_OPTION_T2 59 /* T2 rebinding time */
|
|
||||||
#define DHCP_OPTION_US 60
|
|
||||||
#define DHCP_OPTION_CLIENT_ID 61
|
|
||||||
#define DHCP_OPTION_TFTP_SERVERNAME 66
|
|
||||||
#define DHCP_OPTION_BOOTFILE 67
|
|
||||||
|
|
||||||
/** possible combinations of overloading the file and sname fields with options */
|
|
||||||
#define DHCP_OVERLOAD_NONE 0
|
|
||||||
#define DHCP_OVERLOAD_FILE 1
|
|
||||||
#define DHCP_OVERLOAD_SNAME 2
|
|
||||||
#define DHCP_OVERLOAD_SNAME_FILE 3
|
|
||||||
|
|
||||||
#if LWIP_DHCP_GET_NTP_SRV
|
#if LWIP_DHCP_GET_NTP_SRV
|
||||||
/** This function must exist, in other to add offered NTP servers to
|
/** This function must exist, in other to add offered NTP servers to
|
||||||
|
@ -46,20 +46,12 @@
|
|||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
#include "lwip/ip4.h"
|
#include "lwip/ip4.h"
|
||||||
#include "lwip/ip6.h"
|
#include "lwip/ip6.h"
|
||||||
|
#include "lwip/prot/ip.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IP_PROTO_ICMP 1
|
|
||||||
#define IP_PROTO_IGMP 2
|
|
||||||
#define IP_PROTO_UDP 17
|
|
||||||
#define IP_PROTO_UDPLITE 136
|
|
||||||
#define IP_PROTO_TCP 6
|
|
||||||
|
|
||||||
/** This operates on a void* by loading the first byte */
|
|
||||||
#define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4)
|
|
||||||
|
|
||||||
/* This is passed as the destination address to ip_output_if (not
|
/* This is passed as the destination address to ip_output_if (not
|
||||||
to ip_output), meaning that an IP header already is constructed
|
to ip_output), meaning that an IP header already is constructed
|
||||||
in the pbuf. This is used when TCP retransmits. */
|
in the pbuf. This is used when TCP retransmits. */
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include "lwip/ip4_addr.h"
|
#include "lwip/ip4_addr.h"
|
||||||
#include "lwip/err.h"
|
#include "lwip/err.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
|
#include "lwip/prot/ip4.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -60,62 +61,6 @@ extern "C" {
|
|||||||
/** Currently, the function ip_output_if_opt() is only used with IGMP */
|
/** Currently, the function ip_output_if_opt() is only used with IGMP */
|
||||||
#define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP)
|
#define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP)
|
||||||
|
|
||||||
#define IP_HLEN 20
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
|
||||||
# include "arch/bpstruct.h"
|
|
||||||
#endif
|
|
||||||
PACK_STRUCT_BEGIN
|
|
||||||
struct ip_hdr {
|
|
||||||
/* version / header length */
|
|
||||||
PACK_STRUCT_FLD_8(u8_t _v_hl);
|
|
||||||
/* type of service */
|
|
||||||
PACK_STRUCT_FLD_8(u8_t _tos);
|
|
||||||
/* total length */
|
|
||||||
PACK_STRUCT_FIELD(u16_t _len);
|
|
||||||
/* identification */
|
|
||||||
PACK_STRUCT_FIELD(u16_t _id);
|
|
||||||
/* fragment offset field */
|
|
||||||
PACK_STRUCT_FIELD(u16_t _offset);
|
|
||||||
#define IP_RF 0x8000U /* reserved fragment flag */
|
|
||||||
#define IP_DF 0x4000U /* don't fragment flag */
|
|
||||||
#define IP_MF 0x2000U /* more fragments flag */
|
|
||||||
#define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */
|
|
||||||
/* time to live */
|
|
||||||
PACK_STRUCT_FLD_8(u8_t _ttl);
|
|
||||||
/* protocol*/
|
|
||||||
PACK_STRUCT_FLD_8(u8_t _proto);
|
|
||||||
/* checksum */
|
|
||||||
PACK_STRUCT_FIELD(u16_t _chksum);
|
|
||||||
/* source and destination IP addresses */
|
|
||||||
PACK_STRUCT_FLD_S(ip4_addr_p_t src);
|
|
||||||
PACK_STRUCT_FLD_S(ip4_addr_p_t dest);
|
|
||||||
} PACK_STRUCT_STRUCT;
|
|
||||||
PACK_STRUCT_END
|
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
|
||||||
# include "arch/epstruct.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IPH_V(hdr) ((hdr)->_v_hl >> 4)
|
|
||||||
#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
|
|
||||||
#define IPH_TOS(hdr) ((hdr)->_tos)
|
|
||||||
#define IPH_LEN(hdr) ((hdr)->_len)
|
|
||||||
#define IPH_ID(hdr) ((hdr)->_id)
|
|
||||||
#define IPH_OFFSET(hdr) ((hdr)->_offset)
|
|
||||||
#define IPH_TTL(hdr) ((hdr)->_ttl)
|
|
||||||
#define IPH_PROTO(hdr) ((hdr)->_proto)
|
|
||||||
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
|
|
||||||
|
|
||||||
#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl)))
|
|
||||||
#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
|
|
||||||
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
|
|
||||||
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
|
|
||||||
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
|
|
||||||
#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
|
|
||||||
#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
|
|
||||||
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
|
|
||||||
|
|
||||||
#define ip_init() /* Compatibility define, no init needed. */
|
#define ip_init() /* Compatibility define, no init needed. */
|
||||||
struct netif *ip4_route(const ip4_addr_t *dest);
|
struct netif *ip4_route(const ip4_addr_t *dest);
|
||||||
#if LWIP_IPV4_SRC_ROUTING
|
#if LWIP_IPV4_SRC_ROUTING
|
||||||
|
82
src/include/lwip/prot/autoip.h
Normal file
82
src/include/lwip/prot/autoip.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* AutoIP protocol definitions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2007 Dominik Spies <kontakt@dspies.de>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||||
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* Author: Dominik Spies <kontakt@dspies.de>
|
||||||
|
*
|
||||||
|
* This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
|
||||||
|
* with RFC 3927.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LWIP_HDR_PROT_AUTOIP_H
|
||||||
|
#define LWIP_HDR_PROT_AUTOIP_H
|
||||||
|
|
||||||
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
|
#if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 169.254.0.0 */
|
||||||
|
#define AUTOIP_NET 0xA9FE0000
|
||||||
|
/* 169.254.1.0 */
|
||||||
|
#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100)
|
||||||
|
/* 169.254.254.255 */
|
||||||
|
#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF)
|
||||||
|
|
||||||
|
/* RFC 3927 Constants */
|
||||||
|
#define PROBE_WAIT 1 /* second (initial random delay) */
|
||||||
|
#define PROBE_MIN 1 /* second (minimum delay till repeated probe) */
|
||||||
|
#define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */
|
||||||
|
#define PROBE_NUM 3 /* (number of probe packets) */
|
||||||
|
#define ANNOUNCE_NUM 2 /* (number of announcement packets) */
|
||||||
|
#define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */
|
||||||
|
#define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */
|
||||||
|
#define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */
|
||||||
|
#define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */
|
||||||
|
#define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */
|
||||||
|
|
||||||
|
/* AutoIP client states */
|
||||||
|
#define AUTOIP_STATE_OFF 0
|
||||||
|
#define AUTOIP_STATE_PROBING 1
|
||||||
|
#define AUTOIP_STATE_ANNOUNCING 2
|
||||||
|
#define AUTOIP_STATE_BOUND 3
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* LWIP_IPV4 && LWIP_AUTOIP */
|
||||||
|
|
||||||
|
#endif /* LWIP_HDR_PROT_AUTOIP_H */
|
192
src/include/lwip/prot/dhcp.h
Normal file
192
src/include/lwip/prot/dhcp.h
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* DHCP protocol definitions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2001-2004 Leon Woestenberg <leon.woestenberg@gmx.net>
|
||||||
|
* Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||||
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the lwIP TCP/IP stack.
|
||||||
|
*
|
||||||
|
* Author: Leon Woestenberg <leon.woestenberg@gmx.net>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_HDR_PROT_DHCP_H
|
||||||
|
#define LWIP_HDR_PROT_DHCP_H
|
||||||
|
|
||||||
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
|
#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
|
||||||
|
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "lwip/udp.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DHCP_CLIENT_PORT 68
|
||||||
|
#define DHCP_SERVER_PORT 67
|
||||||
|
|
||||||
|
|
||||||
|
/* DHCP message item offsets and length */
|
||||||
|
#define DHCP_CHADDR_LEN 16U
|
||||||
|
#define DHCP_SNAME_OFS 44U
|
||||||
|
#define DHCP_SNAME_LEN 64U
|
||||||
|
#define DHCP_FILE_OFS 108U
|
||||||
|
#define DHCP_FILE_LEN 128U
|
||||||
|
#define DHCP_MSG_LEN 236U
|
||||||
|
#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U) /* 4 byte: cookie */
|
||||||
|
|
||||||
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
|
# include "arch/bpstruct.h"
|
||||||
|
#endif
|
||||||
|
PACK_STRUCT_BEGIN
|
||||||
|
/** minimum set of fields of any DHCP message */
|
||||||
|
struct dhcp_msg
|
||||||
|
{
|
||||||
|
PACK_STRUCT_FLD_8(u8_t op);
|
||||||
|
PACK_STRUCT_FLD_8(u8_t htype);
|
||||||
|
PACK_STRUCT_FLD_8(u8_t hlen);
|
||||||
|
PACK_STRUCT_FLD_8(u8_t hops);
|
||||||
|
PACK_STRUCT_FIELD(u32_t xid);
|
||||||
|
PACK_STRUCT_FIELD(u16_t secs);
|
||||||
|
PACK_STRUCT_FIELD(u16_t flags);
|
||||||
|
PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr);
|
||||||
|
PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr);
|
||||||
|
PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr);
|
||||||
|
PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr);
|
||||||
|
PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]);
|
||||||
|
PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]);
|
||||||
|
PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]);
|
||||||
|
PACK_STRUCT_FIELD(u32_t cookie);
|
||||||
|
#define DHCP_MIN_OPTIONS_LEN 68U
|
||||||
|
/** make sure user does not configure this too small */
|
||||||
|
#if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
|
||||||
|
# undef DHCP_OPTIONS_LEN
|
||||||
|
#endif
|
||||||
|
/** allow this to be configured in lwipopts.h, but not too small */
|
||||||
|
#if (!defined(DHCP_OPTIONS_LEN))
|
||||||
|
/** set this to be sufficient for your options in outgoing DHCP msgs */
|
||||||
|
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
|
||||||
|
#endif
|
||||||
|
PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]);
|
||||||
|
} PACK_STRUCT_STRUCT;
|
||||||
|
PACK_STRUCT_END
|
||||||
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
|
# include "arch/epstruct.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* DHCP client states */
|
||||||
|
#define DHCP_STATE_OFF 0
|
||||||
|
#define DHCP_STATE_REQUESTING 1
|
||||||
|
#define DHCP_STATE_INIT 2
|
||||||
|
#define DHCP_STATE_REBOOTING 3
|
||||||
|
#define DHCP_STATE_REBINDING 4
|
||||||
|
#define DHCP_STATE_RENEWING 5
|
||||||
|
#define DHCP_STATE_SELECTING 6
|
||||||
|
#define DHCP_STATE_INFORMING 7
|
||||||
|
#define DHCP_STATE_CHECKING 8
|
||||||
|
/* not yet implemented \#define DHCP_STATE_PERMANENT 9 */
|
||||||
|
#define DHCP_STATE_BOUND 10
|
||||||
|
/* not yet implemented \#define DHCP_STATE_RELEASING 11 */
|
||||||
|
#define DHCP_STATE_BACKING_OFF 12
|
||||||
|
|
||||||
|
/* AutoIP cooperation flags */
|
||||||
|
#define DHCP_AUTOIP_COOP_STATE_OFF 0
|
||||||
|
#define DHCP_AUTOIP_COOP_STATE_ON 1
|
||||||
|
|
||||||
|
/* DHCP op codes */
|
||||||
|
#define DHCP_BOOTREQUEST 1
|
||||||
|
#define DHCP_BOOTREPLY 2
|
||||||
|
|
||||||
|
/* DHCP message types */
|
||||||
|
#define DHCP_DISCOVER 1
|
||||||
|
#define DHCP_OFFER 2
|
||||||
|
#define DHCP_REQUEST 3
|
||||||
|
#define DHCP_DECLINE 4
|
||||||
|
#define DHCP_ACK 5
|
||||||
|
#define DHCP_NAK 6
|
||||||
|
#define DHCP_RELEASE 7
|
||||||
|
#define DHCP_INFORM 8
|
||||||
|
|
||||||
|
/** DHCP hardware type, currently only ethernet is supported */
|
||||||
|
#define DHCP_HTYPE_ETH 1
|
||||||
|
|
||||||
|
#define DHCP_MAGIC_COOKIE 0x63825363UL
|
||||||
|
|
||||||
|
/* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */
|
||||||
|
|
||||||
|
/* BootP options */
|
||||||
|
#define DHCP_OPTION_PAD 0
|
||||||
|
#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
|
||||||
|
#define DHCP_OPTION_ROUTER 3
|
||||||
|
#define DHCP_OPTION_DNS_SERVER 6
|
||||||
|
#define DHCP_OPTION_HOSTNAME 12
|
||||||
|
#define DHCP_OPTION_IP_TTL 23
|
||||||
|
#define DHCP_OPTION_MTU 26
|
||||||
|
#define DHCP_OPTION_BROADCAST 28
|
||||||
|
#define DHCP_OPTION_TCP_TTL 37
|
||||||
|
#define DHCP_OPTION_NTP 42
|
||||||
|
#define DHCP_OPTION_END 255
|
||||||
|
|
||||||
|
/* DHCP options */
|
||||||
|
#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
|
||||||
|
#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
|
||||||
|
#define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
|
||||||
|
|
||||||
|
#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
|
||||||
|
#define DHCP_OPTION_MESSAGE_TYPE_LEN 1
|
||||||
|
|
||||||
|
#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
|
||||||
|
#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
|
||||||
|
|
||||||
|
#define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
|
||||||
|
#define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
|
||||||
|
|
||||||
|
#define DHCP_OPTION_T1 58 /* T1 renewal time */
|
||||||
|
#define DHCP_OPTION_T2 59 /* T2 rebinding time */
|
||||||
|
#define DHCP_OPTION_US 60
|
||||||
|
#define DHCP_OPTION_CLIENT_ID 61
|
||||||
|
#define DHCP_OPTION_TFTP_SERVERNAME 66
|
||||||
|
#define DHCP_OPTION_BOOTFILE 67
|
||||||
|
|
||||||
|
/* possible combinations of overloading the file and sname fields with options */
|
||||||
|
#define DHCP_OVERLOAD_NONE 0
|
||||||
|
#define DHCP_OVERLOAD_FILE 1
|
||||||
|
#define DHCP_OVERLOAD_SNAME 2
|
||||||
|
#define DHCP_OVERLOAD_SNAME_FILE 3
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
|
|
||||||
|
#endif /*LWIP_HDR_PROT_DHCP_H*/
|
54
src/include/lwip/prot/ip.h
Normal file
54
src/include/lwip/prot/ip.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* IP protocol definitions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||||
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the lwIP TCP/IP stack.
|
||||||
|
*
|
||||||
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_HDR_PROT_IP_H
|
||||||
|
#define LWIP_HDR_PROT_IP_H
|
||||||
|
|
||||||
|
#include "lwip/opt.h"
|
||||||
|
#include "lwip/arch.h"
|
||||||
|
|
||||||
|
#define IP_PROTO_ICMP 1
|
||||||
|
#define IP_PROTO_IGMP 2
|
||||||
|
#define IP_PROTO_UDP 17
|
||||||
|
#define IP_PROTO_UDPLITE 136
|
||||||
|
#define IP_PROTO_TCP 6
|
||||||
|
|
||||||
|
/** This operates on a void* by loading the first byte */
|
||||||
|
#define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4)
|
||||||
|
|
||||||
|
#endif /* LWIP_HDR_PROT_IP_H */
|
||||||
|
|
||||||
|
|
119
src/include/lwip/prot/ip4.h
Normal file
119
src/include/lwip/prot/ip4.h
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* IPv4 protocol definitions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||||
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the lwIP TCP/IP stack.
|
||||||
|
*
|
||||||
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_HDR_PROT_IP4_H
|
||||||
|
#define LWIP_HDR_PROT_IP4_H
|
||||||
|
|
||||||
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
|
#if LWIP_IPV4
|
||||||
|
|
||||||
|
#include "lwip/arch.h"
|
||||||
|
#include "lwip/ip4_addr.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */
|
||||||
|
#define IP_HLEN 20
|
||||||
|
|
||||||
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
|
# include "arch/bpstruct.h"
|
||||||
|
#endif
|
||||||
|
PACK_STRUCT_BEGIN
|
||||||
|
/* The IPv4 header */
|
||||||
|
struct ip_hdr {
|
||||||
|
/* version / header length */
|
||||||
|
PACK_STRUCT_FLD_8(u8_t _v_hl);
|
||||||
|
/* type of service */
|
||||||
|
PACK_STRUCT_FLD_8(u8_t _tos);
|
||||||
|
/* total length */
|
||||||
|
PACK_STRUCT_FIELD(u16_t _len);
|
||||||
|
/* identification */
|
||||||
|
PACK_STRUCT_FIELD(u16_t _id);
|
||||||
|
/* fragment offset field */
|
||||||
|
PACK_STRUCT_FIELD(u16_t _offset);
|
||||||
|
#define IP_RF 0x8000U /* reserved fragment flag */
|
||||||
|
#define IP_DF 0x4000U /* don't fragment flag */
|
||||||
|
#define IP_MF 0x2000U /* more fragments flag */
|
||||||
|
#define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */
|
||||||
|
/* time to live */
|
||||||
|
PACK_STRUCT_FLD_8(u8_t _ttl);
|
||||||
|
/* protocol*/
|
||||||
|
PACK_STRUCT_FLD_8(u8_t _proto);
|
||||||
|
/* checksum */
|
||||||
|
PACK_STRUCT_FIELD(u16_t _chksum);
|
||||||
|
/* source and destination IP addresses */
|
||||||
|
PACK_STRUCT_FLD_S(ip4_addr_p_t src);
|
||||||
|
PACK_STRUCT_FLD_S(ip4_addr_p_t dest);
|
||||||
|
} PACK_STRUCT_STRUCT;
|
||||||
|
PACK_STRUCT_END
|
||||||
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
|
# include "arch/epstruct.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Macros to get struct ip_hdr fields: */
|
||||||
|
#define IPH_V(hdr) ((hdr)->_v_hl >> 4)
|
||||||
|
#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
|
||||||
|
#define IPH_TOS(hdr) ((hdr)->_tos)
|
||||||
|
#define IPH_LEN(hdr) ((hdr)->_len)
|
||||||
|
#define IPH_ID(hdr) ((hdr)->_id)
|
||||||
|
#define IPH_OFFSET(hdr) ((hdr)->_offset)
|
||||||
|
#define IPH_TTL(hdr) ((hdr)->_ttl)
|
||||||
|
#define IPH_PROTO(hdr) ((hdr)->_proto)
|
||||||
|
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
|
||||||
|
|
||||||
|
/* Macros to set struct ip_hdr fields: */
|
||||||
|
#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl)))
|
||||||
|
#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
|
||||||
|
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
|
||||||
|
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
|
||||||
|
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
|
||||||
|
#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
|
||||||
|
#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
|
||||||
|
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* LWIP_IPV4 */
|
||||||
|
|
||||||
|
#endif /* LWIP_HDR_PROT_IP4_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user