Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

dhcp.h File Reference

#include "lwip/opt.h"
#include "lwip/netif.h"
#include "lwip/udp.h"

Include dependency graph for dhcp.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dhcp
struct  dhcp_msg

Defines

#define DHCP_COARSE_TIMER_SECS   60
#define DHCP_FINE_TIMER_MSECS   500
#define DHCP_CHADDR_LEN   16U
#define DHCP_SNAME_LEN   64U
#define DHCP_FILE_LEN   128U
#define DHCP_MIN_OPTIONS_LEN   68U
#define DHCP_OPTIONS_LEN   DHCP_MIN_OPTIONS_LEN
#define DHCP_MSG_OFS   (UDP_DATA_OFS)
#define DHCP_OP_OFS   (DHCP_MSG_OFS + 0)
#define DHCP_HTYPE_OFS   (DHCP_MSG_OFS + 1)
#define DHCP_HLEN_OFS   (DHCP_MSG_OFS + 2)
#define DHCP_HOPS_OFS   (DHCP_MSG_OFS + 3)
#define DHCP_XID_OFS   (DHCP_MSG_OFS + 4)
#define DHCP_SECS_OFS   (DHCP_MSG_OFS + 8)
#define DHCP_FLAGS_OFS   (DHCP_MSG_OFS + 10)
#define DHCP_CIADDR_OFS   (DHCP_MSG_OFS + 12)
#define DHCP_YIADDR_OFS   (DHCP_MSG_OFS + 16)
#define DHCP_SIADDR_OFS   (DHCP_MSG_OFS + 20)
#define DHCP_GIADDR_OFS   (DHCP_MSG_OFS + 24)
#define DHCP_CHADDR_OFS   (DHCP_MSG_OFS + 28)
#define DHCP_SNAME_OFS   (DHCP_MSG_OFS + 44)
#define DHCP_FILE_OFS   (DHCP_MSG_OFS + 108)
#define DHCP_MSG_LEN   236
#define DHCP_COOKIE_OFS   (DHCP_MSG_OFS + DHCP_MSG_LEN)
#define DHCP_OPTIONS_OFS   (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
#define DHCP_CLIENT_PORT   68
#define DHCP_SERVER_PORT   67
#define DHCP_REQUESTING   1
#define DHCP_INIT   2
#define DHCP_REBOOTING   3
#define DHCP_REBINDING   4
#define DHCP_RENEWING   5
#define DHCP_SELECTING   6
#define DHCP_INFORMING   7
#define DHCP_CHECKING   8
#define DHCP_PERMANENT   9
#define DHCP_BOUND   10
#define DHCP_BACKING_OFF   12
#define DHCP_OFF   13
#define DHCP_BOOTREQUEST   1
#define DHCP_BOOTREPLY   2
#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
#define DHCP_HTYPE_ETH   1
#define DHCP_HLEN_ETH   6
#define DHCP_BROADCAST_FLAG   15
#define DHCP_BROADCAST_MASK   (1 << DHCP_FLAG_BROADCAST)
#define DHCP_OPTION_PAD   0
#define DHCP_OPTION_SUBNET_MASK   1
#define DHCP_OPTION_ROUTER   3
#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_END   255
#define DHCP_OPTION_REQUESTED_IP   50
#define DHCP_OPTION_LEASE_TIME   51
#define DHCP_OPTION_OVERLOAD   52
#define DHCP_OPTION_MESSAGE_TYPE   53
#define DHCP_OPTION_MESSAGE_TYPE_LEN   1
#define DHCP_OPTION_SERVER_ID   54
#define DHCP_OPTION_PARAMETER_REQUEST_LIST   55
#define DHCP_OPTION_MAX_MSG_SIZE   57
#define DHCP_OPTION_MAX_MSG_SIZE_LEN   2
#define DHCP_OPTION_T1   58
#define DHCP_OPTION_T2   59
#define DHCP_OPTION_CLIENT_ID   61
#define DHCP_OPTION_TFTP_SERVERNAME   66
#define DHCP_OPTION_BOOTFILE   67
#define DHCP_OVERLOAD_NONE   0
#define DHCP_OVERLOAD_FILE   1
#define DHCP_OVERLOAD_SNAME   2
#define DHCP_OVERLOAD_SNAME_FILE   3

Functions

PACK_STRUCT_END err_t dhcp_start (struct netif *netif)
void dhcp_stop (struct netif *netif)
err_t dhcp_renew (struct netif *netif)
void dhcp_inform (struct netif *netif)
void dhcp_coarse_tmr (void)
void dhcp_fine_tmr (void)

Variables

PACK_STRUCT_BEGIN struct dhcp_msg PACK_STRUCT_STRUCT


Detailed Description

Definition in file dhcp.h.


Define Documentation

#define DHCP_ACK   5
 

Definition at line 155 of file dhcp.h.

Referenced by dhcp_recv().

#define DHCP_BACKING_OFF   12
 

not yet implemented #define DHCP_RELEASING 11

Definition at line 145 of file dhcp.h.

Referenced by dhcp_handle_nak(), and dhcp_timeout().

#define DHCP_BOOTREPLY   2
 

Definition at line 149 of file dhcp.h.

Referenced by dhcp_recv().

#define DHCP_BOOTREQUEST   1
 

Definition at line 148 of file dhcp.h.

Referenced by dhcp_create_request().

#define DHCP_BOUND   10
 

Definition at line 143 of file dhcp.h.

Referenced by dhcp_bind(), dhcp_t1_timeout(), and dhcp_t2_timeout().

#define DHCP_BROADCAST_FLAG   15
 

Definition at line 164 of file dhcp.h.

#define DHCP_BROADCAST_MASK   (1 << DHCP_FLAG_BROADCAST)
 

Definition at line 165 of file dhcp.h.

#define DHCP_CHADDR_LEN   16U
 

Definition at line 70 of file dhcp.h.

Referenced by dhcp_create_request().

#define DHCP_CHADDR_OFS   (DHCP_MSG_OFS + 28)
 

Definition at line 122 of file dhcp.h.

#define DHCP_CHECKING   8
 

Definition at line 141 of file dhcp.h.

Referenced by dhcp_check(), and dhcp_timeout().

#define DHCP_CIADDR_OFS   (DHCP_MSG_OFS + 12)
 

Definition at line 118 of file dhcp.h.

#define DHCP_CLIENT_PORT   68
 

Definition at line 130 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_release(), dhcp_renew(), dhcp_select(), and ip_input().

#define DHCP_COARSE_TIMER_SECS   60
 

period (in seconds) of the application calling dhcp_coarse_tmr()

Definition at line 12 of file dhcp.h.

Referenced by dhcp_bind().

#define DHCP_COOKIE_OFS   (DHCP_MSG_OFS + DHCP_MSG_LEN)
 

Definition at line 127 of file dhcp.h.

#define DHCP_DECLINE   4
 

Definition at line 154 of file dhcp.h.

#define DHCP_DISCOVER   1
 

Definition at line 151 of file dhcp.h.

Referenced by dhcp_discover().

#define DHCP_FILE_LEN   128U
 

Definition at line 74 of file dhcp.h.

Referenced by dhcp_create_request(), and dhcp_get_option_ptr().

#define DHCP_FILE_OFS   (DHCP_MSG_OFS + 108)
 

Definition at line 124 of file dhcp.h.

#define DHCP_FINE_TIMER_MSECS   500
 

period (in milliseconds) of the application calling dhcp_fine_tmr()

Definition at line 14 of file dhcp.h.

Referenced by dhcp_check(), dhcp_discover(), dhcp_handle_nak(), dhcp_rebind(), dhcp_release(), dhcp_renew(), and dhcp_select().

#define DHCP_FLAGS_OFS   (DHCP_MSG_OFS + 10)
 

Definition at line 117 of file dhcp.h.

#define DHCP_GIADDR_OFS   (DHCP_MSG_OFS + 24)
 

Definition at line 121 of file dhcp.h.

#define DHCP_HLEN_ETH   6
 

Definition at line 162 of file dhcp.h.

Referenced by dhcp_create_request().

#define DHCP_HLEN_OFS   (DHCP_MSG_OFS + 2)
 

Definition at line 113 of file dhcp.h.

#define DHCP_HOPS_OFS   (DHCP_MSG_OFS + 3)
 

Definition at line 114 of file dhcp.h.

#define DHCP_HTYPE_ETH   1
 

Definition at line 160 of file dhcp.h.

Referenced by dhcp_create_request().

#define DHCP_HTYPE_OFS   (DHCP_MSG_OFS + 1)
 

Definition at line 112 of file dhcp.h.

#define DHCP_INFORM   8
 

Definition at line 158 of file dhcp.h.

Referenced by dhcp_inform().

#define DHCP_INFORMING   7
 

Definition at line 140 of file dhcp.h.

#define DHCP_INIT   2
 

Definition at line 135 of file dhcp.h.

#define DHCP_MIN_OPTIONS_LEN   68U
 

Definition at line 77 of file dhcp.h.

Referenced by dhcp_option_trailer().

#define DHCP_MSG_LEN   236
 

Definition at line 125 of file dhcp.h.

#define DHCP_MSG_OFS   (UDP_DATA_OFS)
 

DHCP message item offsets and length

Definition at line 110 of file dhcp.h.

#define DHCP_NAK   6
 

Definition at line 156 of file dhcp.h.

Referenced by dhcp_recv().

#define DHCP_OFF   13
 

Definition at line 146 of file dhcp.h.

Referenced by dhcp_release().

#define DHCP_OFFER   2
 

Definition at line 152 of file dhcp.h.

Referenced by dhcp_recv().

#define DHCP_OP_OFS   (DHCP_MSG_OFS + 0)
 

Definition at line 111 of file dhcp.h.

#define DHCP_OPTION_BOOTFILE   67
 

Definition at line 197 of file dhcp.h.

#define DHCP_OPTION_BROADCAST   28
 

Definition at line 174 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_handle_ack(), and dhcp_select().

#define DHCP_OPTION_CLIENT_ID   61
 

Definition at line 195 of file dhcp.h.

#define DHCP_OPTION_END   255
 

Definition at line 176 of file dhcp.h.

Referenced by dhcp_get_option_ptr(), and dhcp_option_trailer().

#define DHCP_OPTION_HOSTNAME   12
 

Definition at line 171 of file dhcp.h.

#define DHCP_OPTION_IP_TTL   23
 

Definition at line 172 of file dhcp.h.

#define DHCP_OPTION_LEASE_TIME   51
 

Definition at line 180 of file dhcp.h.

Referenced by dhcp_handle_ack().

#define DHCP_OPTION_MAX_MSG_SIZE   57
 

Definition at line 190 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_renew(), and dhcp_select().

#define DHCP_OPTION_MAX_MSG_SIZE_LEN   2
 

Definition at line 191 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_renew(), and dhcp_select().

#define DHCP_OPTION_MESSAGE_TYPE   53
 

Definition at line 183 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_recv(), dhcp_release(), dhcp_renew(), and dhcp_select().

#define DHCP_OPTION_MESSAGE_TYPE_LEN   1
 

Definition at line 184 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_release(), dhcp_renew(), and dhcp_select().

#define DHCP_OPTION_MTU   26
 

Definition at line 173 of file dhcp.h.

#define DHCP_OPTION_OVERLOAD   52
 

Definition at line 181 of file dhcp.h.

Referenced by dhcp_get_option_ptr().

#define DHCP_OPTION_PAD   0
 

BootP options

Definition at line 168 of file dhcp.h.

#define DHCP_OPTION_PARAMETER_REQUEST_LIST   55
 

Definition at line 188 of file dhcp.h.

Referenced by dhcp_discover(), and dhcp_select().

#define DHCP_OPTION_REQUESTED_IP   50
 

DHCP options

Definition at line 179 of file dhcp.h.

Referenced by dhcp_rebind(), dhcp_renew(), and dhcp_select().

#define DHCP_OPTION_ROUTER   3
 

Definition at line 170 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_handle_ack(), and dhcp_select().

#define DHCP_OPTION_SERVER_ID   54
 

Definition at line 187 of file dhcp.h.

Referenced by dhcp_handle_offer(), dhcp_rebind(), dhcp_renew(), and dhcp_select().

#define DHCP_OPTION_SUBNET_MASK   1
 

Definition at line 169 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_handle_ack(), and dhcp_select().

#define DHCP_OPTION_T1   58
 

Definition at line 193 of file dhcp.h.

Referenced by dhcp_handle_ack().

#define DHCP_OPTION_T2   59
 

Definition at line 194 of file dhcp.h.

Referenced by dhcp_handle_ack().

#define DHCP_OPTION_TCP_TTL   37
 

Definition at line 175 of file dhcp.h.

#define DHCP_OPTION_TFTP_SERVERNAME   66
 

Definition at line 196 of file dhcp.h.

#define DHCP_OPTIONS_LEN   DHCP_MIN_OPTIONS_LEN
 

set this to be sufficient for your options in outgoing DHCP msgs

Definition at line 81 of file dhcp.h.

Referenced by dhcp_create_request(), dhcp_discover(), dhcp_inform(), dhcp_option(), dhcp_option_byte(), dhcp_option_long(), dhcp_option_short(), dhcp_option_trailer(), dhcp_rebind(), dhcp_release(), dhcp_renew(), dhcp_select(), and dhcp_unfold_reply().

#define DHCP_OPTIONS_OFS   (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
 

Definition at line 128 of file dhcp.h.

#define DHCP_OVERLOAD_FILE   1
 

Definition at line 201 of file dhcp.h.

Referenced by dhcp_get_option_ptr().

#define DHCP_OVERLOAD_NONE   0
 

possible combinations of overloading the file and sname fields with options

Definition at line 200 of file dhcp.h.

Referenced by dhcp_get_option_ptr().

#define DHCP_OVERLOAD_SNAME   2
 

Definition at line 202 of file dhcp.h.

Referenced by dhcp_get_option_ptr().

#define DHCP_OVERLOAD_SNAME_FILE   3
 

Definition at line 203 of file dhcp.h.

#define DHCP_PERMANENT   9
 

Definition at line 142 of file dhcp.h.

#define DHCP_REBINDING   4
 

Definition at line 137 of file dhcp.h.

Referenced by dhcp_rebind(), dhcp_recv(), and dhcp_timeout().

#define DHCP_REBOOTING   3
 

Definition at line 136 of file dhcp.h.

Referenced by dhcp_recv().

#define DHCP_RELEASE   7
 

Definition at line 157 of file dhcp.h.

Referenced by dhcp_release().

#define DHCP_RENEWING   5
 

Definition at line 138 of file dhcp.h.

Referenced by dhcp_recv(), dhcp_renew(), dhcp_t1_timeout(), dhcp_t2_timeout(), and dhcp_timeout().

#define DHCP_REQUEST   3
 

Definition at line 153 of file dhcp.h.

Referenced by dhcp_rebind(), dhcp_renew(), and dhcp_select().

#define DHCP_REQUESTING   1
 

DHCP client states

Definition at line 134 of file dhcp.h.

Referenced by dhcp_recv(), dhcp_select(), dhcp_t1_timeout(), dhcp_t2_timeout(), and dhcp_timeout().

#define DHCP_SECS_OFS   (DHCP_MSG_OFS + 8)
 

Definition at line 116 of file dhcp.h.

#define DHCP_SELECTING   6
 

Definition at line 139 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_recv(), and dhcp_timeout().

#define DHCP_SERVER_PORT   67
 

Definition at line 131 of file dhcp.h.

Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_release(), dhcp_renew(), and dhcp_select().

#define DHCP_SIADDR_OFS   (DHCP_MSG_OFS + 20)
 

Definition at line 120 of file dhcp.h.

#define DHCP_SNAME_LEN   64U
 

Definition at line 72 of file dhcp.h.

Referenced by dhcp_create_request(), and dhcp_get_option_ptr().

#define DHCP_SNAME_OFS   (DHCP_MSG_OFS + 44)
 

Definition at line 123 of file dhcp.h.

#define DHCP_XID_OFS   (DHCP_MSG_OFS + 4)
 

Definition at line 115 of file dhcp.h.

#define DHCP_YIADDR_OFS   (DHCP_MSG_OFS + 16)
 

Definition at line 119 of file dhcp.h.


Function Documentation

void dhcp_coarse_tmr void   ) 
 

The DHCP timer that checks for lease renewal/rebind timeouts.

Definition at line 268 of file dhcp.c.

References DBG_STATE, DBG_TRACE, DEBUGF, DHCP_DEBUG, dhcp_t1_timeout(), dhcp_t2_timeout(), netif_list, and NULL.

00269 {
00270   struct netif *netif = netif_list;
00271   DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr()\n"));
00272   /* iterate through all network interfaces */
00273   while (netif != NULL) {
00274     /* only act on DHCP configured interfaces */
00275     if (netif->dhcp != NULL) {
00276       /* timer is active (non zero), and triggers (zeroes) now? */
00277       if (netif->dhcp->t2_timeout-- == 1) {
00278         DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout\n"));
00279         /* this clients' rebind timeout triggered */
00280         dhcp_t2_timeout(netif);
00281       /* timer is active (non zero), and triggers (zeroes) now */
00282       } else if (netif->dhcp->t1_timeout-- == 1) {
00283         DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout\n"));
00284         /* this clients' renewal timeout triggered */
00285         dhcp_t1_timeout(netif);
00286       }
00287     }
00288     /* proceed to next netif */
00289     netif = netif->next;
00290   }
00291 }

Here is the call graph for this function:

void dhcp_fine_tmr void   ) 
 

DHCP transaction timeout handling

A DHCP server is expected to respond within a short period of time.

Definition at line 299 of file dhcp.c.

References DBG_STATE, DBG_TRACE, DEBUGF, DHCP_DEBUG, dhcp_timeout(), netif_list, and NULL.

00300 {
00301   struct netif *netif = netif_list;
00302   /* loop through clients */
00303   while (netif != NULL) {
00304     /* only act on DHCP configured interfaces */
00305     if (netif->dhcp != NULL) {
00306       /* timer is active (non zero), and triggers (zeroes) now */
00307       if (netif->dhcp->request_timeout-- == 1) {
00308         DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout\n"));
00309         /* this clients' request timeout triggered */
00310         dhcp_timeout(netif);
00311       }
00312     }
00313     /* proceed to next network interface */
00314     netif = netif->next;
00315   }
00316 }

Here is the call graph for this function:

void dhcp_inform struct netif netif  ) 
 

Inform a DHCP server of our manual configuration.

This informs DHCP servers of our fixed IP address configuration by sending an INFORM message. It does not involve DHCP address configuration, it is just here to be nice to the network.

Parameters:
netif The lwIP network interface

Definition at line 537 of file dhcp.c.

References DBG_STATE, DBG_TRACE, DEBUGF, DHCP_CLIENT_PORT, dhcp_create_request(), DHCP_DEBUG, dhcp_delete_request(), DHCP_INFORM, dhcp_option(), dhcp_option_byte(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, dhcp_option_short(), dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_SERVER_PORT, ERR_OK, err_t, IP_ADDR_ANY, IP_ADDR_BROADCAST, mem_free(), mem_malloc(), NULL, pbuf_realloc(), udp_bind(), udp_connect(), udp_new(), udp_remove(), and udp_send().

00538 {
00539   struct dhcp *dhcp;
00540   err_t result = ERR_OK;
00541   dhcp = mem_malloc(sizeof(struct dhcp));
00542   if (dhcp == NULL) {
00543     DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp\n"));
00544     return;
00545   }  
00546   memset(dhcp, 0, sizeof(struct dhcp));
00547 
00548   DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp\n"));
00549   dhcp->pcb = udp_new();
00550   if (dhcp->pcb == NULL) {
00551     DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not obtain pcb"));
00552     mem_free((void *)dhcp);
00553     return;
00554   }
00555   DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb\n"));
00556   /* create and initialize the DHCP message header */
00557   result = dhcp_create_request(netif);
00558   if (result == ERR_OK) {
00559 
00560     dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
00561     dhcp_option_byte(dhcp, DHCP_INFORM);
00562 
00563     dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
00564     /* TODO: use netif->mtu ?! */
00565     dhcp_option_short(dhcp, 576);
00566 
00567     dhcp_option_trailer(dhcp);
00568 
00569     pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
00570 
00571     udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
00572     udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT);
00573     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_inform: INFORMING\n"));
00574     udp_send(dhcp->pcb, dhcp->p_out);
00575     udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT);
00576     dhcp_delete_request(netif);
00577   } else {
00578     DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform: could not allocate DHCP request\n"));
00579   }
00580 
00581   if (dhcp != NULL)
00582   {
00583     if (dhcp->pcb != NULL) udp_remove(dhcp->pcb);
00584     dhcp->pcb = NULL;
00585     mem_free((void *)dhcp);
00586   }
00587 }

Here is the call graph for this function:

err_t dhcp_renew struct netif netif  ) 
 

Renew an existing DHCP lease at the involved DHCP server.

Parameters:
netif network interface which must renew its lease

Definition at line 778 of file dhcp.c.

References DBG_STATE, DBG_TRACE, DEBUGF, DHCP_CLIENT_PORT, dhcp_create_request(), DHCP_DEBUG, dhcp_delete_request(), DHCP_FINE_TIMER_MSECS, dhcp_option(), dhcp_option_byte(), dhcp_option_long(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, DHCP_OPTION_REQUESTED_IP, DHCP_OPTION_SERVER_ID, dhcp_option_short(), dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_RENEWING, DHCP_REQUEST, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, err_t, IP_ADDR_ANY, ntohl, pbuf_realloc(), u16_t, udp_bind(), udp_connect(), and udp_send().

Referenced by dhcp_t1_timeout(), and dhcp_timeout().

00779 {
00780   struct dhcp *dhcp = netif->dhcp;
00781   err_t result;
00782   u16_t msecs;
00783   DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()\n"));
00784   dhcp_set_state(dhcp, DHCP_RENEWING);
00785 
00786   /* create and initialize the DHCP message header */
00787   result = dhcp_create_request(netif);
00788   if (result == ERR_OK) {
00789 
00790     dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
00791     dhcp_option_byte(dhcp, DHCP_REQUEST);
00792 
00793     dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
00794     /* TODO: use netif->mtu in some way */
00795     dhcp_option_short(dhcp, 576);
00796 
00797 #if 0
00798     dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
00799     dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));
00800 #endif
00801 
00802 #if 0
00803     dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
00804     dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr));
00805 #endif
00806     /* append DHCP message trailer */
00807     dhcp_option_trailer(dhcp);
00808 
00809     pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
00810 
00811     udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
00812     udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT);
00813     udp_send(dhcp->pcb, dhcp->p_out);
00814     dhcp_delete_request(netif);
00815 
00816     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew: RENEWING\n"));
00817   } else {
00818     DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_renew: could not allocate DHCP request\n"));
00819   }
00820   dhcp->tries++;
00821   /* back-off on retries, but to a maximum of 20 seconds */
00822   msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000;
00823   dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
00824    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs\n", msecs));
00825   return result;
00826 }

Here is the call graph for this function:

PACK_STRUCT_END err_t dhcp_start struct netif netif  ) 
 

Start DHCP negotiation for a network interface.

If no DHCP client instance was attached to this interface, a new client is created first. If a DHCP client instance was already present, it restarts negotiation.

Parameters:
netif The lwIP network interface
Returns:
lwIP error code
  • ERR_OK - No error
  • ERR_MEM - Out of memory

Definition at line 484 of file dhcp.c.

References DBG_STATE, DBG_TRACE, DEBUGF, DHCP_DEBUG, dhcp_discover(), dhcp_stop(), ERR_MEM, ERR_OK, err_t, netif::flags, LWIP_ASSERT, mem_free(), mem_malloc(), netif::name, NETIF_FLAG_DHCP, NULL, netif::num, and udp_new().

00485 {
00486   struct dhcp *dhcp = netif->dhcp;
00487   err_t result = ERR_OK;
00488 
00489   LWIP_ASSERT("netif != NULL", netif != NULL);
00490   DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_start(netif=%p) %c%c%u\n", netif, netif->name[0], netif->name[1], netif->num));
00491 
00492   if (dhcp == NULL) {
00493     DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client\n"));
00494     dhcp = mem_malloc(sizeof(struct dhcp));
00495     if (dhcp == NULL) {
00496       DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp\n"));
00497       netif->flags &= ~NETIF_FLAG_DHCP;
00498       return ERR_MEM;
00499     }
00500     /* clear data structure */
00501     memset(dhcp, 0, sizeof(struct dhcp));
00502     DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): allocated dhcp"));
00503     dhcp->pcb = udp_new();
00504     if (dhcp->pcb == NULL) {
00505       DEBUGF(DHCP_DEBUG  | DBG_TRACE, ("dhcp_start(): could not obtain pcb\n"));
00506       mem_free((void *)dhcp);
00507       dhcp = NULL;
00508       netif->flags &= ~NETIF_FLAG_DHCP;
00509       return ERR_MEM;
00510     }
00511     /* store this dhcp client in the netif */
00512     netif->dhcp = dhcp;
00513     DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb\n"));
00514     DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n"));
00515   } else {
00516     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 3, ("dhcp_start(): restarting DHCP configuration\n"));
00517   }
00518   /* (re)start the DHCP negotiation */
00519   result = dhcp_discover(netif);
00520   if (result != ERR_OK) {
00521     /* free resources allocated above */
00522     dhcp_stop(netif);
00523   }
00524   return result;
00525 }

Here is the call graph for this function:

void dhcp_stop struct netif netif  ) 
 

Remove the DHCP client from the interface.

Parameters:
netif The network interface to stop DHCP on

Definition at line 930 of file dhcp.c.

References DBG_TRACE, DEBUGF, DHCP_DEBUG, dhcp_free_reply(), mem_free(), NULL, pbuf_free(), and udp_remove().

Referenced by dhcp_start().

00931 {
00932   struct dhcp *dhcp = netif->dhcp;
00933   DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()\n"));
00934   /* netif is DHCP configured? */
00935   if (dhcp != NULL)
00936   {
00937     if (dhcp->pcb != NULL)
00938     {
00939       udp_remove(dhcp->pcb);
00940       dhcp->pcb = NULL;
00941     }
00942     if (dhcp->p != NULL)
00943     {
00944       pbuf_free(dhcp->p);
00945       dhcp->p = NULL;
00946     }
00947     /* free unfolded reply */
00948     dhcp_free_reply(dhcp);
00949     mem_free((void *)dhcp);
00950     netif->dhcp = NULL;
00951   }
00952 }

Here is the call graph for this function:


Variable Documentation

PACK_STRUCT_BEGIN struct dhcp_msg PACK_STRUCT_STRUCT
 

minimum set of fields of any DHCP message


Generated on Wed Jan 14 12:59:03 2004 for RTL-lwIP-0.4 by doxygen 1.3.4