Merged with leon-dhcp branch. Tagged as POST_leon-dhcp afterwards.

This commit is contained in:
likewise 2003-02-20 08:41:59 +00:00
parent 0a51d72098
commit d8d787545e
6 changed files with 985 additions and 1035 deletions

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@
#include "lwip/snmp.h"
#if LWIP_DHCP
#include "lwip/dhcp.h"
# include "lwip/dhcp.h"
#endif /* LWIP_DHCP */
/*-----------------------------------------------------------------------------------*/

View File

@ -13,19 +13,24 @@
// period (in milliseconds) of the application calling dhcp_fine_tmr()
#define DHCP_FINE_TIMER_MSECS 500
struct dhcp_state
struct dhcp
{
struct dhcp_state *next; // for linked list purposes
u8_t state; // current DHCP state (of DHCP state machine)
u8_t tries; // retries of current request
u32_t xid; // id of last sent request
struct netif *netif; // interface to be configured
struct udp_pcb *pcb; // our connection
struct pbuf *p; // (first) pbuf of incoming msg
struct dhcp_msg *msg_in; // incoming msg
struct dhcp_msg *options_in; // incoming msg options
u16_t options_in_len; // ingoing msg options length
/** current DHCP state machine state */
u8_t state;
/** retries of current request */
u8_t tries;
/** transaction identifier of last sent request */
u32_t xid;
/** our connection to the DHCP server */
struct udp_pcb *pcb;
/** (first) pbuf of incoming msg */
struct pbuf *p;
/** incoming msg */
struct dhcp_msg *msg_in;
/** incoming msg options */
struct dhcp_msg *options_in;
** ingoing msg options length */
u16_t options_in_len;
struct pbuf *p_out; // pbuf of outcoming msg
struct dhcp_msg *msg_out; // outgoing msg
@ -48,7 +53,7 @@ struct dhcp_state
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
// minimum set of fields of any DHCP message
/** minimum set of fields of any DHCP message */
struct dhcp_msg
{
PACK_STRUCT_FIELD(u8_t op);
@ -70,9 +75,9 @@ struct dhcp_msg
PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
PACK_STRUCT_FIELD(u32_t cookie);
#define DHCP_MIN_OPTIONS_LEN 68U
// allow this to be configured in lwipopts.h, but not too small
/** allow this to be configured in lwipopts.h, but not too small */
#if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
// set this to be sufficient for your options in outgoing DHCP msgs
/** set this to be sufficient for your options in outgoing DHCP msgs */
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
#endif
PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
@ -82,28 +87,28 @@ PACK_STRUCT_END
# include "arch/epstruct.h"
#endif
// initialize DHCP client
/** initialize DHCP client */
void dhcp_init(void);
// start DHCP configuration
/** start DHCP configuration */
struct dhcp_state *dhcp_start(struct netif *netif);
// stop DHCP configuration
void dhcp_stop(struct dhcp_state *state);
// enforce lease renewal
err_t dhcp_renew(struct dhcp_state *state);
// inform server of our IP address
/** stop DHCP configuration */
void dhcp_stop(struct netif *netif);
/** enforce lease renewal */
err_t dhcp_renew(struct netif *netif);
/** inform server of our IP address */
void dhcp_inform(struct netif *netif);
// if enabled, check whether the offered IP address is not in use, using ARP
/** if enabled, check whether the offered IP address is not in use, using ARP */
#if DHCP_DOES_ARP_CHECK
void dhcp_arp_reply(struct ip_addr *addr);
void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
#endif
// to be called every minute
/** to be called every minute */
void dhcp_coarse_tmr(void);
// to be called every half second
/** to be called every half second */
void dhcp_fine_tmr(void);
// DHCP message item offsets and length
/** DHCP message item offsets and length */
#define DHCP_MSG_OFS (UDP_DATA_OFS)
#define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
#define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
@ -127,7 +132,7 @@ void dhcp_fine_tmr(void);
#define DHCP_CLIENT_PORT 68
#define DHCP_SERVER_PORT 67
// DHCP client states
/** DHCP client states */
#define DHCP_REQUESTING 1
#define DHCP_INIT 2
#define DHCP_REBOOTING 3
@ -160,7 +165,7 @@ void dhcp_fine_tmr(void);
#define DHCP_BROADCAST_FLAG 15
#define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
// BootP options
/** BootP options */
#define DHCP_OPTION_PAD 0
#define DHCP_OPTION_SUBNET_MASK 1 // RFC 2132 3.3
#define DHCP_OPTION_ROUTER 3
@ -171,7 +176,7 @@ void dhcp_fine_tmr(void);
#define DHCP_OPTION_TCP_TTL 37
#define DHCP_OPTION_END 255
// DHCP options
/** 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
@ -192,7 +197,7 @@ void dhcp_fine_tmr(void);
#define DHCP_OPTION_TFTP_SERVERNAME 66
#define DHCP_OPTION_BOOTFILE 67
// possible combinations of overloading the file and sname fields with options
/** 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

View File

@ -32,6 +32,7 @@
#ifndef __LWIP_NETIF_H__
#define __LWIP_NETIF_H__
#include "lwipopts.h"
#include "lwip/opt.h"
#include "lwip/err.h"
@ -40,39 +41,66 @@
#include "lwip/inet.h"
#include "lwip/pbuf.h"
#include "lwip/dhcp.h"
/** must be the maximum of all used hardware address lengths */
#define NETIF_HWADDR_LEN 6
/** must be the maximum of all used hardware address lengths
across all types of interfaces in use */
#define NETIF_MAX_HWADDR_LEN 6
/** whether the network interface is 'up'. this is
* a software flag used to control whether this network
* interface is enabled and processes traffic */
#define NETIF_FLAG_UP 1
/** if set, the netif has broadcast capability */
#define NETIF_FLAG_BROADCAST 2
/** if set, the netif is one end of a point-to-point connection */
#define NETIF_FLAG_POINTTOPOINT 4
/** if set, the interface is configured using DHCP */
#define NETIF_FLAG_DHCP 8
/** generic data structure used for all lwIP network interfaces */
struct netif {
/** pointer to next in linked list */
struct netif *next;
u8_t num;
u16_t mtu;
/** The following fields should be filled in by the
initialization function for the device driver. */
/** IP address configuration in network byte order */
struct ip_addr ip_addr;
struct ip_addr netmask; /* netmask in network byte order */
struct ip_addr netmask;
struct ip_addr gw;
unsigned char hwaddr[NETIF_HWADDR_LEN];
/* This function is called by the network device driver
when it wants to pass a packet to the TCP/IP stack. */
/** This function is called by the network device driver
to pass a packet up the TCP/IP stack. */
err_t (* input)(struct pbuf *p, struct netif *inp);
/** The following two fields should be filled in by the
initialization function for the device driver. */
char name[2];
/** This function is called by the IP module when it wants
to send a packet on the interface. This function typically
first resolves the hardware address, then sends the packet. */
to send a packet on the interface. This function typically
first resolves the hardware address, then sends the packet. */
err_t (* output)(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr);
/** This function is called by the ARP module when it wants
to send a packet on the interface. This function outputs
the pbuf on the link medium. */
to send a packet on the interface. This function outputs
the pbuf as-is on the link medium. */
err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
/** This field can be set by the device driver and could point
to state information for the device. */
void *state;
#if LWIP_DHCP
/** the DHCP client state information for this netif */
struct dhcp *dhcp;
#endif
/** number of bytes used in hwaddr */
unsigned char hwaddr_len;
/** link level hardware address of this interface */
unsigned char hwaddr[NETIF_MAX_HWADDR_LEN];
/** maximum transfer unit (in bytes) */
u16_t mtu;
/** descriptive abbreviation */
char name[2];
/** number of this interface */
u8_t num;
/** NETIF_FLAG_* */
u8_t flags;
};
/** The list of network interfaces. */

View File

@ -3,6 +3,12 @@
* Address Resolution Protocol module for IP over Ethernet
*
* $Log: etharp.c,v $
* Revision 1.25 2003/02/20 08:42:04 likewise
* Merged with leon-dhcp branch. Tagged as POST_leon-dhcp afterwards.
*
* Revision 1.24.2.1 2003/02/10 22:42:59 likewise
* Massive amount of refactoring DHCP code.
*
* Revision 1.24 2003/02/06 22:18:57 davidhaas
* Add the following features and bugfixes:
*
@ -533,7 +539,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
DEBUGF(ETHARP_DEBUG, ("etharp_arp_input: incoming ARP reply\n"));
#if (LWIP_DHCP && DHCP_DOES_ARP_CHECK)
/* DHCP needs to know about ARP replies */
dhcp_arp_reply(&hdr->sipaddr);
dhcp_arp_reply(struct netif *netif, &hdr->sipaddr);
#endif
/* ARP reply directed to us? */
if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) {

View File

@ -73,11 +73,20 @@ low_level_init(struct netif *netif)
ethernetif = netif->state;
/* Obtain MAC address from network interface. */
ethernetif->ethaddr->addr[0] = ;
ethernetif->ethaddr->addr[1] = ;
ethernetif->ethaddr->addr[2] = ;
/* set MAC hardware address length */
netif->hwaddr_len = 6;
/* set MAC hardware address */
netif->hwaddr[0] = ;
...
netif->hwaddr[6] = ;
/* maximum transfer unit */
netif->mtu = 1500;
/* broadcast capability */
netif->flags = NETIF_FLAG_BROADCAST;
/* Do whatever else is needed to initialize interface. */
}
/*-----------------------------------------------------------------------------------*/