75 |
static u32_t xid = 0xABCD0000; |
static u32_t xid = 0xABCD0000; |
76 |
|
|
77 |
/** DHCP client state machine functions */ |
/** DHCP client state machine functions */ |
78 |
static void dhcp_handle_ack(struct dhcp *dhcp); |
static void dhcp_handle_ack(struct netif *netif); |
79 |
static void dhcp_handle_nak(struct dhcp *dhcp); |
static void dhcp_handle_nak(struct netif *netif); |
80 |
static void dhcp_handle_offer(struct dhcp *dhcp); |
static void dhcp_handle_offer(struct netif *netif); |
81 |
|
|
82 |
static err_t dhcp_discover(struct netif *netif); |
static err_t dhcp_discover(struct netif *netif); |
83 |
static err_t dhcp_select(struct netif *netif); |
static err_t dhcp_select(struct netif *netif); |
99 |
|
|
100 |
/** set the DHCP timers */ |
/** set the DHCP timers */ |
101 |
static void dhcp_timeout(struct netif *netif); |
static void dhcp_timeout(struct netif *netif); |
102 |
static void dhcp_t1_timeout(struct dhcp *dhcp); |
static void dhcp_t1_timeout(struct netif *netif); |
103 |
static void dhcp_t2_timeout(struct dhcp *dhcp); |
static void dhcp_t2_timeout(struct netif *netif); |
104 |
|
|
105 |
/** build outgoing messages */ |
/** build outgoing messages */ |
106 |
static err_t dhcp_create_request(struct dhcp *dhcp); |
static err_t dhcp_create_request(struct netif *netif); |
107 |
static void dhcp_delete_request(struct dhcp *dhcp); |
static void dhcp_delete_request(struct netif *netif); |
108 |
static void dhcp_option(struct dhcp *dhcp, u8_t option_type, u8_t option_len); |
static void dhcp_option(struct dhcp *dhcp, u8_t option_type, u8_t option_len); |
109 |
static void dhcp_option_byte(struct dhcp *dhcp, u8_t value); |
static void dhcp_option_byte(struct dhcp *dhcp, u8_t value); |
110 |
static void dhcp_option_short(struct dhcp *dhcp, u16_t value); |
static void dhcp_option_short(struct dhcp *dhcp, u16_t value); |
122 |
* |
* |
123 |
* @param state pointer to DHCP state structure |
* @param state pointer to DHCP state structure |
124 |
*/ |
*/ |
125 |
static void dhcp_handle_nak(struct dhcp *dhcp) { |
static void dhcp_handle_nak(struct netif *netif) { |
126 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
127 |
u16_t msecs = 10 * 1000; |
u16_t msecs = 10 * 1000; |
128 |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_nak()")); |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_nak()")); |
150 |
p = etharp_query(netif, &dhcp->offered_ip_addr, NULL); |
p = etharp_query(netif, &dhcp->offered_ip_addr, NULL); |
151 |
if (p != NULL) { |
if (p != NULL) { |
152 |
DEBUGF(DHCP_DEBUG, ("dhcp_check(): sending ARP request len %u", p->tot_len)); |
DEBUGF(DHCP_DEBUG, ("dhcp_check(): sending ARP request len %u", p->tot_len)); |
153 |
result = dhcp->netif->linkoutput(netif, p); |
result = netif->linkoutput(netif, p); |
154 |
pbuf_free(p); |
pbuf_free(p); |
155 |
p = NULL; |
p = NULL; |
156 |
} |
} |
166 |
* |
* |
167 |
* @param state pointer to DHCP state structure |
* @param state pointer to DHCP state structure |
168 |
*/ |
*/ |
169 |
static void dhcp_handle_offer(struct dhcp *dhcp) |
static void dhcp_handle_offer(struct netif *netif) |
170 |
{ |
{ |
171 |
|
struct dhcp *dhcp = netif->dhcp; |
172 |
/* obtain the server address */ |
/* obtain the server address */ |
173 |
u8_t *option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_SERVER_ID); |
u8_t *option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_SERVER_ID); |
174 |
if (option_ptr != NULL) |
if (option_ptr != NULL) |
178 |
/* remember offered address */ |
/* remember offered address */ |
179 |
ip_addr_set(&dhcp->offered_ip_addr, (struct ip_addr *)&dhcp->msg_in->yiaddr); |
ip_addr_set(&dhcp->offered_ip_addr, (struct ip_addr *)&dhcp->msg_in->yiaddr); |
180 |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr)); |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr)); |
181 |
dhcp_select(dhcp); |
dhcp_select(netif); |
182 |
} |
} |
183 |
} |
} |
184 |
|
|
190 |
* @param dhcp pointer to DHCP state structure |
* @param dhcp pointer to DHCP state structure |
191 |
* @return lwIP specific error (see error.h) |
* @return lwIP specific error (see error.h) |
192 |
*/ |
*/ |
193 |
static err_t dhcp_select(struct dhcp *dhcp) |
static err_t dhcp_select(struct netif *netif) |
194 |
{ |
{ |
195 |
|
struct dhcp *dhcp = netif->dhcp; |
196 |
err_t result; |
err_t result; |
197 |
u32_t msecs; |
u32_t msecs; |
198 |
DEBUGF(DHCP_DEBUG, ("dhcp_select()")); |
DEBUGF(DHCP_DEBUG, ("dhcp_select()")); |
199 |
|
|
200 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
201 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
202 |
if (result == ERR_OK) |
if (result == ERR_OK) |
203 |
{ |
{ |
204 |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
231 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
232 |
/* reconnect to any (or to server here?!) */ |
/* reconnect to any (or to server here?!) */ |
233 |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
234 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
235 |
} |
} |
236 |
dhcp->tries++; |
dhcp->tries++; |
237 |
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000; |
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000; |
304 |
*/ |
*/ |
305 |
static void dhcp_timeout(struct netif *netif) |
static void dhcp_timeout(struct netif *netif) |
306 |
{ |
{ |
307 |
|
struct dhcp *dhcp = netif->dhcp; |
308 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout()")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout()")); |
309 |
/* back-off period has passed, or server selection timed out */ |
/* back-off period has passed, or server selection timed out */ |
310 |
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) { |
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) { |
311 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): restarting discovery")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): restarting discovery")); |
312 |
dhcp_discover(dhcp); |
dhcp_discover(netif); |
313 |
/* receiving the requested lease timed out */ |
/* receiving the requested lease timed out */ |
314 |
} else if (dhcp->state == DHCP_REQUESTING) { |
} else if (dhcp->state == DHCP_REQUESTING) { |
315 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, DHCP request timed out")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, DHCP request timed out")); |
316 |
if (dhcp->tries <= 5) { |
if (dhcp->tries <= 5) { |
317 |
dhcp_select(dhcp); |
dhcp_select(netif); |
318 |
} else { |
} else { |
319 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, releasing, restarting")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, releasing, restarting")); |
320 |
dhcp_release(dhcp); |
dhcp_release(netif); |
321 |
dhcp_discover(dhcp); |
dhcp_discover(netif); |
322 |
} |
} |
323 |
/* received no ARP reply for the offered address (which is good) */ |
/* received no ARP reply for the offered address (which is good) */ |
324 |
} else if (dhcp->state == DHCP_CHECKING) { |
} else if (dhcp->state == DHCP_CHECKING) { |
337 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RENEWING, DHCP request timed out")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RENEWING, DHCP request timed out")); |
338 |
/* just retry renewal */ |
/* just retry renewal */ |
339 |
/* note that the rebind timer will eventually time-out if renew does not work */ |
/* note that the rebind timer will eventually time-out if renew does not work */ |
340 |
dhcp_renew(dhcp); |
dhcp_renew(netif); |
341 |
/* did not get response to rebind request? */ |
/* did not get response to rebind request? */ |
342 |
} else if (dhcp->state == DHCP_REBINDING) { |
} else if (dhcp->state == DHCP_REBINDING) { |
343 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REBINDING, DHCP request timed out")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REBINDING, DHCP request timed out")); |
344 |
if (dhcp->tries <= 8) { |
if (dhcp->tries <= 8) { |
345 |
dhcp_rebind(dhcp); |
dhcp_rebind(netif); |
346 |
} else { |
} else { |
347 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RELEASING, DISCOVERING")); |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RELEASING, DISCOVERING")); |
348 |
dhcp_release(dhcp); |
dhcp_release(netif); |
349 |
dhcp_discover(dhcp); |
dhcp_discover(netif); |
350 |
} |
} |
351 |
} |
} |
352 |
} |
} |
388 |
* |
* |
389 |
* @param dhcp pointer to DHCP state structure |
* @param dhcp pointer to DHCP state structure |
390 |
*/ |
*/ |
391 |
static void dhcp_handle_ack(struct dhcp *dhcp) |
static void dhcp_handle_ack(struct netif *netif) |
392 |
{ |
{ |
393 |
|
struct dhcp *dhcp = netif->dhcp; |
394 |
u8_t *option_ptr; |
u8_t *option_ptr; |
395 |
/* clear options we might not get from the ACK */ |
/* clear options we might not get from the ACK */ |
396 |
dhcp->offered_sn_mask.addr = 0; |
dhcp->offered_sn_mask.addr = 0; |
460 |
* (due to unavailable memory or network resources). |
* (due to unavailable memory or network resources). |
461 |
* |
* |
462 |
*/ |
*/ |
463 |
struct dhcp *dhcp_start(struct netif *netif) |
err_t dhcp_start(struct netif *netif) |
464 |
{ |
{ |
465 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
466 |
err_t result = ERR_OK; |
err_t result = ERR_OK; |
467 |
|
|
468 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(netif=%c%c%u)", netif->, netif->, netif->num)); |
DEBUGF(DHCP_DEBUG, ("dhcp_start(netif=%c%c%u)", netif->name[0], netif->name[1], netif->num)); |
469 |
|
|
470 |
if (dhcp == NULL) { |
if (dhcp == NULL) { |
471 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): starting new DHCP client")); |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): starting new DHCP client")); |
532 |
} |
} |
533 |
DEBUGF(DHCP_DEBUG, ("dhcp_inform(): created new udp pcb")); |
DEBUGF(DHCP_DEBUG, ("dhcp_inform(): created new udp pcb")); |
534 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
535 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
536 |
if (result == ERR_OK) { |
if (result == ERR_OK) { |
537 |
|
|
538 |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
550 |
udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT); |
551 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
552 |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
553 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
554 |
} |
} |
555 |
|
|
556 |
if (dhcp != NULL) |
if (dhcp != NULL) |
576 |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx", addr->addr)); |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx", addr->addr)); |
577 |
/* did a host respond with the address we |
/* did a host respond with the address we |
578 |
were offered by the DHCP server? */ |
were offered by the DHCP server? */ |
579 |
if (ip_addr_cmp(addr, &dhcp->offered_ip_addr)) { |
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { |
580 |
/* we will not accept the offered address */ |
/* we will not accept the offered address */ |
581 |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply(): arp reply matched with offered address, declining")); |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply(): arp reply matched with offered address, declining")); |
582 |
dhcp_decline(netif); |
dhcp_decline(netif); |
599 |
DEBUGF(DHCP_DEBUG, ("dhcp_decline()")); |
DEBUGF(DHCP_DEBUG, ("dhcp_decline()")); |
600 |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
601 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
602 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
603 |
if (result == ERR_OK) |
if (result == ERR_OK) |
604 |
{ |
{ |
605 |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
615 |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
616 |
udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); |
617 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
618 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
619 |
} |
} |
620 |
dhcp->tries++; |
dhcp->tries++; |
621 |
msecs = 10*1000; |
msecs = 10*1000; |
638 |
DEBUGF(DHCP_DEBUG, ("dhcp_discover()")); |
DEBUGF(DHCP_DEBUG, ("dhcp_discover()")); |
639 |
ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY); |
ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY); |
640 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
641 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
642 |
if (result == ERR_OK) |
if (result == ERR_OK) |
643 |
{ |
{ |
644 |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
664 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
665 |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
666 |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
667 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
668 |
} |
} |
669 |
dhcp->tries++; |
dhcp->tries++; |
670 |
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000; |
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000; |
704 |
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); |
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); |
705 |
|
|
706 |
/* subnet mask not given? */ |
/* subnet mask not given? */ |
707 |
/* TODO: this is not a valid check. what if the network mask is 0??!! */ |
/* TODO: this is not a valid check. what if the network mask is 0? */ |
708 |
if (sn_mask.addr == 0) { |
if (sn_mask.addr == 0) { |
709 |
/* choose a safe subnet mask given the network class */ |
/* choose a safe subnet mask given the network class */ |
710 |
u8_t first_octet = ip4_addr1(&sn_mask); |
u8_t first_octet = ip4_addr1(&sn_mask); |
717 |
/* gateway address not given? */ |
/* gateway address not given? */ |
718 |
if (gw_addr.addr == 0) { |
if (gw_addr.addr == 0) { |
719 |
/* copy network address */ |
/* copy network address */ |
720 |
gw_addr.addr = (&dhcp->offered_ip_addr & sn_mask.addr); |
gw_addr.addr = (dhcp->offered_ip_addr.addr & sn_mask.addr); |
721 |
/* use first host address on network as gateway */ |
/* use first host address on network as gateway */ |
722 |
gw_addr.addr |= htonl(0x00000001); |
gw_addr.addr |= htonl(0x00000001); |
723 |
} |
} |
746 |
dhcp_set_state(dhcp, DHCP_RENEWING); |
dhcp_set_state(dhcp, DHCP_RENEWING); |
747 |
|
|
748 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
749 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
750 |
if (result == ERR_OK) { |
if (result == ERR_OK) { |
751 |
|
|
752 |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
773 |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
774 |
udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); |
775 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
776 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
777 |
} |
} |
778 |
dhcp->tries++; |
dhcp->tries++; |
779 |
/* back-off on retries, but to a maximum of 20 seconds */ |
/* back-off on retries, but to a maximum of 20 seconds */ |
797 |
dhcp_set_state(dhcp, DHCP_REBINDING); |
dhcp_set_state(dhcp, DHCP_REBINDING); |
798 |
|
|
799 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
800 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
801 |
if (result == ERR_OK) |
if (result == ERR_OK) |
802 |
{ |
{ |
803 |
|
|
823 |
udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT); |
824 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
825 |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); |
826 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
827 |
} |
} |
828 |
dhcp->tries++; |
dhcp->tries++; |
829 |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
847 |
dhcp_set_state(dhcp, DHCP_OFF); |
dhcp_set_state(dhcp, DHCP_OFF); |
848 |
|
|
849 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
850 |
result = dhcp_create_request(dhcp); |
result = dhcp_create_request(netif); |
851 |
if (result == ERR_OK) { |
if (result == ERR_OK) { |
852 |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); |
853 |
dhcp_option_byte(dhcp, DHCP_RELEASE); |
dhcp_option_byte(dhcp, DHCP_RELEASE); |
859 |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); |
860 |
udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); |
udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); |
861 |
udp_send(dhcp->pcb, dhcp->p_out); |
udp_send(dhcp->pcb, dhcp->p_out); |
862 |
dhcp_delete_request(dhcp); |
dhcp_delete_request(netif); |
863 |
} |
} |
864 |
dhcp->tries++; |
dhcp->tries++; |
865 |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
1094 |
DEBUGF(DHCP_DEBUG, ("DHCP_ACK received")); |
DEBUGF(DHCP_DEBUG, ("DHCP_ACK received")); |
1095 |
/* in requesting state? */ |
/* in requesting state? */ |
1096 |
if (dhcp->state == DHCP_REQUESTING) { |
if (dhcp->state == DHCP_REQUESTING) { |
1097 |
dhcp_handle_ack(dhcp); |
dhcp_handle_ack(netif); |
1098 |
dhcp->request_timeout = 0; |
dhcp->request_timeout = 0; |
1099 |
#if DHCP_DOES_ARP_CHECK |
#if DHCP_DOES_ARP_CHECK |
1100 |
/* check if the acknowledged lease address is already in use */ |
/* check if the acknowledged lease address is already in use */ |
1116 |
(dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING ))) { |
(dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING ))) { |
1117 |
DEBUGF(DHCP_DEBUG, ("DHCP_NAK received")); |
DEBUGF(DHCP_DEBUG, ("DHCP_NAK received")); |
1118 |
dhcp->request_timeout = 0; |
dhcp->request_timeout = 0; |
1119 |
dhcp_handle_nak(dhcp); |
dhcp_handle_nak(netif); |
1120 |
} |
} |
1121 |
/* received a DHCP_OFFER in DHCP_SELECTING state? */ |
/* received a DHCP_OFFER in DHCP_SELECTING state? */ |
1122 |
else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) { |
else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) { |
1123 |
DEBUGF(DHCP_DEBUG, ("DHCP_OFFER received in DHCP_SELECTING state")); |
DEBUGF(DHCP_DEBUG, ("DHCP_OFFER received in DHCP_SELECTING state")); |
1124 |
dhcp->request_timeout = 0; |
dhcp->request_timeout = 0; |
1125 |
/* remember offered lease */ |
/* remember offered lease */ |
1126 |
dhcp_handle_offer(dhcp); |
dhcp_handle_offer(netif); |
1127 |
} |
} |
1128 |
pbuf_free(p); |
pbuf_free(p); |
1129 |
} |
} |
1130 |
|
|
1131 |
|
|
1132 |
static err_t dhcp_create_request(struct dhcp *dhcp) |
static err_t dhcp_create_request(struct netif *netif) |
1133 |
{ |
{ |
1134 |
|
struct dhcp *dhcp = netif->dhcp; |
1135 |
u16_t i; |
u16_t i; |
1136 |
LWIP_ASSERT("dhcp_create_request: dhcp->p_out == NULL", dhcp->p_out == NULL); |
LWIP_ASSERT("dhcp_create_request: dhcp->p_out == NULL", dhcp->p_out == NULL); |
1137 |
LWIP_ASSERT("dhcp_create_request: dhcp->msg_out == NULL", dhcp->msg_out == NULL); |
LWIP_ASSERT("dhcp_create_request: dhcp->msg_out == NULL", dhcp->msg_out == NULL); |
1171 |
return ERR_OK; |
return ERR_OK; |
1172 |
} |
} |
1173 |
|
|
1174 |
static void dhcp_delete_request(struct dhcp *dhcp) |
static void dhcp_delete_request(struct netif *netif) |
1175 |
{ |
{ |
1176 |
|
struct dhcp *dhcp = netif->dhcp; |
1177 |
LWIP_ASSERT("dhcp_free_msg: dhcp->p_out != NULL", dhcp->p_out != NULL); |
LWIP_ASSERT("dhcp_free_msg: dhcp->p_out != NULL", dhcp->p_out != NULL); |
1178 |
LWIP_ASSERT("dhcp_free_msg: dhcp->msg_out != NULL", dhcp->msg_out != NULL); |
LWIP_ASSERT("dhcp_free_msg: dhcp->msg_out != NULL", dhcp->msg_out != NULL); |
1179 |
pbuf_free(dhcp->p_out); |
pbuf_free(dhcp->p_out); |