1 |
|
/** |
2 |
|
* @file |
3 |
|
* |
4 |
|
* Dynamic Host Configuration Protocol client |
5 |
|
*/ |
6 |
|
|
7 |
/* |
/* |
8 |
|
* |
9 |
* Copyright (c) 2001-2003 Leon Woestenberg <leon.woestenberg@gmx.net> |
* Copyright (c) 2001-2003 Leon Woestenberg <leon.woestenberg@gmx.net> |
10 |
* Copyright (c) 2001-2003 Axon Digital Design B.V., The Netherlands. |
* Copyright (c) 2001-2003 Axon Digital Design B.V., The Netherlands. |
11 |
* All rights reserved. |
* All rights reserved. |
138 |
static void dhcp_handle_nak(struct netif *netif) { |
static void dhcp_handle_nak(struct netif *netif) { |
139 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
140 |
u16_t msecs = 10 * 1000; |
u16_t msecs = 10 * 1000; |
141 |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_nak()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_handle_nak()")); |
142 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
143 |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_nak(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs", msecs)); |
144 |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
145 |
} |
} |
146 |
|
|
157 |
struct pbuf *p; |
struct pbuf *p; |
158 |
err_t result; |
err_t result; |
159 |
u16_t msecs; |
u16_t msecs; |
160 |
DEBUGF(DHCP_DEBUG, ("dhcp_check()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check()")); |
161 |
/* create an ARP query for the offered IP address, expecting that no host |
/* create an ARP query for the offered IP address, expecting that no host |
162 |
responds, as the IP address should not be in use. */ |
responds, as the IP address should not be in use. */ |
163 |
p = etharp_query(netif, &dhcp->offered_ip_addr, NULL); |
p = etharp_query(netif, &dhcp->offered_ip_addr, NULL); |
164 |
if (p != NULL) { |
if (p != NULL) { |
165 |
DEBUGF(DHCP_DEBUG, ("dhcp_check(): sending ARP request len %u", p->tot_len)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check(): sending ARP request len %u", p->tot_len)); |
166 |
result = netif->linkoutput(netif, p); |
result = netif->linkoutput(netif, p); |
167 |
pbuf_free(p); |
pbuf_free(p); |
168 |
p = NULL; |
p = NULL; |
170 |
dhcp->tries++; |
dhcp->tries++; |
171 |
msecs = 500; |
msecs = 500; |
172 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
173 |
DEBUGF(DHCP_DEBUG, ("dhcp_check(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs", msecs)); |
174 |
dhcp_set_state(dhcp, DHCP_CHECKING); |
dhcp_set_state(dhcp, DHCP_CHECKING); |
175 |
} |
} |
176 |
|
|
187 |
if (option_ptr != NULL) |
if (option_ptr != NULL) |
188 |
{ |
{ |
189 |
dhcp->server_ip_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2])); |
dhcp->server_ip_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2])); |
190 |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_offer(): server 0x%08lx", dhcp->server_ip_addr.addr)); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx", dhcp->server_ip_addr.addr)); |
191 |
/* remember offered address */ |
/* remember offered address */ |
192 |
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); |
193 |
DEBUGF(DHCP_DEBUG, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr)); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr)); |
194 |
dhcp_select(netif); |
dhcp_select(netif); |
195 |
} |
} |
196 |
} |
} |
208 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
209 |
err_t result; |
err_t result; |
210 |
u32_t msecs; |
u32_t msecs; |
211 |
DEBUGF(DHCP_DEBUG, ("dhcp_select()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_select()")); |
212 |
|
|
213 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
214 |
result = dhcp_create_request(netif); |
result = dhcp_create_request(netif); |
249 |
dhcp->tries++; |
dhcp->tries++; |
250 |
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000; |
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000; |
251 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
252 |
DEBUGF(DHCP_DEBUG, ("dhcp_select(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs", msecs)); |
253 |
dhcp_set_state(dhcp, DHCP_REQUESTING); |
dhcp_set_state(dhcp, DHCP_REQUESTING); |
254 |
return result; |
return result; |
255 |
} |
} |
261 |
void dhcp_coarse_tmr() |
void dhcp_coarse_tmr() |
262 |
{ |
{ |
263 |
struct netif *netif = netif_list; |
struct netif *netif = netif_list; |
264 |
DEBUGF(DHCP_DEBUG, ("dhcp_coarse_tmr():")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr():")); |
265 |
/* iterate through all network interfaces */ |
/* iterate through all network interfaces */ |
266 |
while (netif != NULL) { |
while (netif != NULL) { |
267 |
/* only act on DHCP configured interfaces */ |
/* only act on DHCP configured interfaces */ |
268 |
if (netif->dhcp != NULL) { |
if (netif->dhcp != NULL) { |
269 |
/* timer is active (non zero), and triggers (zeroes) now? */ |
/* timer is active (non zero), and triggers (zeroes) now? */ |
270 |
if (netif->dhcp->t2_timeout-- == 1) { |
if (netif->dhcp->t2_timeout-- == 1) { |
271 |
DEBUGF(DHCP_DEBUG, ("dhcp_coarse_tmr(): t2 timeout")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout")); |
272 |
/* this clients' rebind timeout triggered */ |
/* this clients' rebind timeout triggered */ |
273 |
dhcp_t2_timeout(netif); |
dhcp_t2_timeout(netif); |
274 |
/* timer is active (non zero), and triggers (zeroes) now */ |
/* timer is active (non zero), and triggers (zeroes) now */ |
275 |
} else if (netif->dhcp->t1_timeout-- == 1) { |
} else if (netif->dhcp->t1_timeout-- == 1) { |
276 |
DEBUGF(DHCP_DEBUG, ("dhcp_coarse_tmr(): t1 timeout")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout")); |
277 |
/* this clients' renewal timeout triggered */ |
/* this clients' renewal timeout triggered */ |
278 |
dhcp_t1_timeout(netif); |
dhcp_t1_timeout(netif); |
279 |
} |
} |
298 |
if (netif->dhcp != NULL) { |
if (netif->dhcp != NULL) { |
299 |
/* timer is active (non zero), and triggers (zeroes) now */ |
/* timer is active (non zero), and triggers (zeroes) now */ |
300 |
if (netif->dhcp->request_timeout-- == 1) { |
if (netif->dhcp->request_timeout-- == 1) { |
301 |
DEBUGF(DHCP_DEBUG, ("dhcp_fine_tmr(): request timeout")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout")); |
302 |
/* this clients' request timeout triggered */ |
/* this clients' request timeout triggered */ |
303 |
dhcp_timeout(netif); |
dhcp_timeout(netif); |
304 |
} |
} |
320 |
static void dhcp_timeout(struct netif *netif) |
static void dhcp_timeout(struct netif *netif) |
321 |
{ |
{ |
322 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
323 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()")); |
324 |
/* back-off period has passed, or server selection timed out */ |
/* back-off period has passed, or server selection timed out */ |
325 |
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) { |
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) { |
326 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): restarting discovery")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery")); |
327 |
dhcp_discover(netif); |
dhcp_discover(netif); |
328 |
/* receiving the requested lease timed out */ |
/* receiving the requested lease timed out */ |
329 |
} else if (dhcp->state == DHCP_REQUESTING) { |
} else if (dhcp->state == DHCP_REQUESTING) { |
330 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, DHCP request timed out")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out")); |
331 |
if (dhcp->tries <= 5) { |
if (dhcp->tries <= 5) { |
332 |
dhcp_select(netif); |
dhcp_select(netif); |
333 |
} else { |
} else { |
334 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, releasing, restarting")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting")); |
335 |
dhcp_release(netif); |
dhcp_release(netif); |
336 |
dhcp_discover(netif); |
dhcp_discover(netif); |
337 |
} |
} |
338 |
/* received no ARP reply for the offered address (which is good) */ |
/* received no ARP reply for the offered address (which is good) */ |
339 |
} else if (dhcp->state == DHCP_CHECKING) { |
} else if (dhcp->state == DHCP_CHECKING) { |
340 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): CHECKING, ARP request timed out")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out")); |
341 |
if (dhcp->tries <= 1) { |
if (dhcp->tries <= 1) { |
342 |
dhcp_check(netif); |
dhcp_check(netif); |
343 |
/* no ARP replies on the offered address, |
/* no ARP replies on the offered address, |
349 |
} |
} |
350 |
/* did not get response to renew request? */ |
/* did not get response to renew request? */ |
351 |
else if (dhcp->state == DHCP_RENEWING) { |
else if (dhcp->state == DHCP_RENEWING) { |
352 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RENEWING, DHCP request timed out")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RENEWING, DHCP request timed out")); |
353 |
/* just retry renewal */ |
/* just retry renewal */ |
354 |
/* 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 */ |
355 |
dhcp_renew(netif); |
dhcp_renew(netif); |
356 |
/* did not get response to rebind request? */ |
/* did not get response to rebind request? */ |
357 |
} else if (dhcp->state == DHCP_REBINDING) { |
} else if (dhcp->state == DHCP_REBINDING) { |
358 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REBINDING, DHCP request timed out")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REBINDING, DHCP request timed out")); |
359 |
if (dhcp->tries <= 8) { |
if (dhcp->tries <= 8) { |
360 |
dhcp_rebind(netif); |
dhcp_rebind(netif); |
361 |
} else { |
} else { |
362 |
DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RELEASING, DISCOVERING")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RELEASING, DISCOVERING")); |
363 |
dhcp_release(netif); |
dhcp_release(netif); |
364 |
dhcp_discover(netif); |
dhcp_discover(netif); |
365 |
} |
} |
374 |
static void dhcp_t1_timeout(struct netif *netif) |
static void dhcp_t1_timeout(struct netif *netif) |
375 |
{ |
{ |
376 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
377 |
DEBUGF(DHCP_DEBUG, ("dhcp_t1_timeout()")); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_t1_timeout()")); |
378 |
if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) { |
if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) { |
379 |
/* just retry to renew */ |
/* just retry to renew */ |
380 |
/* 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 */ |
381 |
DEBUGF(DHCP_DEBUG, ("dhcp_t1_timeout(): must renew")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t1_timeout(): must renew")); |
382 |
dhcp_renew(netif); |
dhcp_renew(netif); |
383 |
} |
} |
384 |
} |
} |
390 |
static void dhcp_t2_timeout(struct netif *netif) |
static void dhcp_t2_timeout(struct netif *netif) |
391 |
{ |
{ |
392 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
393 |
DEBUGF(DHCP_DEBUG, ("dhcp_t2_timeout()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout()")); |
394 |
if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) { |
if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) { |
395 |
/* just retry to rebind */ |
/* just retry to rebind */ |
396 |
DEBUGF(DHCP_DEBUG, ("dhcp_t2_timeout(): must rebind")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout(): must rebind")); |
397 |
dhcp_rebind(netif); |
dhcp_rebind(netif); |
398 |
} |
} |
399 |
} |
} |
480 |
err_t result = ERR_OK; |
err_t result = ERR_OK; |
481 |
|
|
482 |
LWIP_ASSERT("netif != NULL", netif != NULL); |
LWIP_ASSERT("netif != NULL", netif != NULL); |
483 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(netif=%p) %c%c%u", netif, netif->name[0], netif->name[1], netif->num)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_start(netif=%p) %c%c%u", netif, netif->name[0], netif->name[1], netif->num)); |
484 |
|
|
485 |
if (dhcp == NULL) { |
if (dhcp == NULL) { |
486 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): starting new DHCP client")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client")); |
487 |
dhcp = mem_malloc(sizeof(struct dhcp)); |
dhcp = mem_malloc(sizeof(struct dhcp)); |
488 |
if (dhcp == NULL) { |
if (dhcp == NULL) { |
489 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): could not allocate dhcp")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp")); |
490 |
netif->flags &= ~NETIF_FLAG_DHCP; |
netif->flags &= ~NETIF_FLAG_DHCP; |
491 |
return ERR_MEM; |
return ERR_MEM; |
492 |
} |
} |
493 |
/* clear data structure */ |
/* clear data structure */ |
494 |
memset(dhcp, 0, sizeof(struct dhcp)); |
memset(dhcp, 0, sizeof(struct dhcp)); |
495 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): allocated dhcp")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): allocated dhcp")); |
496 |
dhcp->pcb = udp_new(); |
dhcp->pcb = udp_new(); |
497 |
if (dhcp->pcb == NULL) { |
if (dhcp->pcb == NULL) { |
498 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): could not obtain pcb")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not obtain pcb")); |
499 |
mem_free((void *)dhcp); |
mem_free((void *)dhcp); |
500 |
dhcp = NULL; |
dhcp = NULL; |
501 |
netif->flags &= ~NETIF_FLAG_DHCP; |
netif->flags &= ~NETIF_FLAG_DHCP; |
503 |
} |
} |
504 |
/* store this dhcp client in the netif */ |
/* store this dhcp client in the netif */ |
505 |
netif->dhcp = dhcp; |
netif->dhcp = dhcp; |
506 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): created new udp pcb")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb")); |
507 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): starting DHCP configuration")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration")); |
508 |
} else { |
} else { |
509 |
DEBUGF(DHCP_DEBUG, ("dhcp_start(): restarting DHCP configuration")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): restarting DHCP configuration")); |
510 |
} |
} |
511 |
/* (re)start the DHCP negotiation */ |
/* (re)start the DHCP negotiation */ |
512 |
result = dhcp_discover(netif); |
result = dhcp_discover(netif); |
533 |
err_t result = ERR_OK; |
err_t result = ERR_OK; |
534 |
dhcp = mem_malloc(sizeof(struct dhcp)); |
dhcp = mem_malloc(sizeof(struct dhcp)); |
535 |
if (dhcp == NULL) { |
if (dhcp == NULL) { |
536 |
DEBUGF(DHCP_DEBUG, ("dhcp_inform(): could not allocate dhcp")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp")); |
537 |
return; |
return; |
538 |
} |
} |
539 |
memset(dhcp, 0, sizeof(struct dhcp)); |
memset(dhcp, 0, sizeof(struct dhcp)); |
540 |
|
|
541 |
DEBUGF(DHCP_DEBUG, ("dhcp_inform(): allocated dhcp")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp")); |
542 |
dhcp->pcb = udp_new(); |
dhcp->pcb = udp_new(); |
543 |
if (dhcp->pcb == NULL) { |
if (dhcp->pcb == NULL) { |
544 |
DEBUGF(DHCP_DEBUG, ("dhcp_inform(): could not obtain pcb")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not obtain pcb")); |
545 |
mem_free((void *)dhcp); |
mem_free((void *)dhcp); |
546 |
return; |
return; |
547 |
} |
} |
548 |
DEBUGF(DHCP_DEBUG, ("dhcp_inform(): created new udp pcb")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb")); |
549 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
550 |
result = dhcp_create_request(netif); |
result = dhcp_create_request(netif); |
551 |
if (result == ERR_OK) { |
if (result == ERR_OK) { |
585 |
*/ |
*/ |
586 |
void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr) |
void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr) |
587 |
{ |
{ |
588 |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()")); |
589 |
/* is this DHCP client doing an ARP check? */ |
/* is this DHCP client doing an ARP check? */ |
590 |
if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { |
if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { |
591 |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx", addr->addr)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx", addr->addr)); |
592 |
/* did a host respond with the address we |
/* did a host respond with the address we |
593 |
were offered by the DHCP server? */ |
were offered by the DHCP server? */ |
594 |
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { |
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { |
595 |
/* we will not accept the offered address */ |
/* we will not accept the offered address */ |
596 |
DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply(): arp reply matched with offered address, declining")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 1, ("dhcp_arp_reply(): arp reply matched with offered address, declining")); |
597 |
dhcp_decline(netif); |
dhcp_decline(netif); |
598 |
} |
} |
599 |
} |
} |
611 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
612 |
err_t result = ERR_OK; |
err_t result = ERR_OK; |
613 |
u16_t msecs; |
u16_t msecs; |
614 |
DEBUGF(DHCP_DEBUG, ("dhcp_decline()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_decline()")); |
615 |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
616 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
617 |
result = dhcp_create_request(netif); |
result = dhcp_create_request(netif); |
635 |
dhcp->tries++; |
dhcp->tries++; |
636 |
msecs = 10*1000; |
msecs = 10*1000; |
637 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
638 |
DEBUGF(DHCP_DEBUG, ("dhcp_decline(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs", msecs)); |
639 |
return result; |
return result; |
640 |
} |
} |
641 |
#endif |
#endif |
650 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
651 |
err_t result = ERR_OK; |
err_t result = ERR_OK; |
652 |
u16_t msecs; |
u16_t msecs; |
653 |
DEBUGF(DHCP_DEBUG, ("dhcp_discover()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_discover()")); |
654 |
ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY); |
ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY); |
655 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
656 |
result = dhcp_create_request(netif); |
result = dhcp_create_request(netif); |
684 |
dhcp->tries++; |
dhcp->tries++; |
685 |
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000; |
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000; |
686 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
687 |
DEBUGF(DHCP_DEBUG, ("dhcp_discover(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs", msecs)); |
688 |
dhcp_set_state(dhcp, DHCP_SELECTING); |
dhcp_set_state(dhcp, DHCP_SELECTING); |
689 |
return result; |
return result; |
690 |
} |
} |
703 |
/* temporary DHCP lease? */ |
/* temporary DHCP lease? */ |
704 |
if (dhcp->offered_t1_renew != 0xffffffffUL) { |
if (dhcp->offered_t1_renew != 0xffffffffUL) { |
705 |
/* set renewal period timer */ |
/* set renewal period timer */ |
706 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t1 renewal timer %lu secs", dhcp->offered_t1_renew)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs", dhcp->offered_t1_renew)); |
707 |
dhcp->t1_timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; |
dhcp->t1_timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; |
708 |
if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1; |
if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1; |
709 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): set request timeout %u msecs", dhcp->offered_t1_renew*1000)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs", dhcp->offered_t1_renew*1000)); |
710 |
} |
} |
711 |
/* set renewal period timer */ |
/* set renewal period timer */ |
712 |
if (dhcp->offered_t2_rebind != 0xffffffffUL) { |
if (dhcp->offered_t2_rebind != 0xffffffffUL) { |
713 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t2 rebind timer %lu secs", dhcp->offered_t2_rebind)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs", dhcp->offered_t2_rebind)); |
714 |
dhcp->t2_timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; |
dhcp->t2_timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; |
715 |
if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1; |
if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1; |
716 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): set request timeout %u msecs", dhcp->offered_t2_rebind*1000)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs", dhcp->offered_t2_rebind*1000)); |
717 |
} |
} |
718 |
/* copy offered network mask */ |
/* copy offered network mask */ |
719 |
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); |
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); |
737 |
gw_addr.addr |= htonl(0x00000001); |
gw_addr.addr |= htonl(0x00000001); |
738 |
} |
} |
739 |
|
|
740 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): IP: 0x%08lx", dhcp->offered_ip_addr.addr)); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx", dhcp->offered_ip_addr.addr)); |
741 |
netif_set_ipaddr(netif, &dhcp->offered_ip_addr); |
netif_set_ipaddr(netif, &dhcp->offered_ip_addr); |
742 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): SN: 0x%08lx", sn_mask.addr)); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx", sn_mask.addr)); |
743 |
netif_set_netmask(netif, &sn_mask); |
netif_set_netmask(netif, &sn_mask); |
744 |
DEBUGF(DHCP_DEBUG, ("dhcp_bind(): GW: 0x%08lx", gw_addr.addr)); |
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx", gw_addr.addr)); |
745 |
netif_set_gw(netif, &gw_addr); |
netif_set_gw(netif, &gw_addr); |
746 |
/* netif is now bound to DHCP leased address */ |
/* netif is now bound to DHCP leased address */ |
747 |
dhcp_set_state(dhcp, DHCP_BOUND); |
dhcp_set_state(dhcp, DHCP_BOUND); |
757 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
758 |
err_t result; |
err_t result; |
759 |
u16_t msecs; |
u16_t msecs; |
760 |
DEBUGF(DHCP_DEBUG, ("dhcp_renew()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()")); |
761 |
dhcp_set_state(dhcp, DHCP_RENEWING); |
dhcp_set_state(dhcp, DHCP_RENEWING); |
762 |
|
|
763 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
794 |
/* back-off on retries, but to a maximum of 20 seconds */ |
/* back-off on retries, but to a maximum of 20 seconds */ |
795 |
msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000; |
796 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
797 |
DEBUGF(DHCP_DEBUG, ("dhcp_renew(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs", msecs)); |
798 |
return result; |
return result; |
799 |
} |
} |
800 |
|
|
808 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
809 |
err_t result; |
err_t result; |
810 |
u16_t msecs; |
u16_t msecs; |
811 |
DEBUGF(DHCP_DEBUG, ("dhcp_rebind()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind()")); |
812 |
dhcp_set_state(dhcp, DHCP_REBINDING); |
dhcp_set_state(dhcp, DHCP_REBINDING); |
813 |
|
|
814 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
843 |
dhcp->tries++; |
dhcp->tries++; |
844 |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
845 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
846 |
DEBUGF(DHCP_DEBUG, ("dhcp_rebind(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs", msecs)); |
847 |
return result; |
return result; |
848 |
} |
} |
849 |
|
|
857 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
858 |
err_t result; |
err_t result; |
859 |
u16_t msecs; |
u16_t msecs; |
860 |
DEBUGF(DHCP_DEBUG, ("dhcp_release()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_release()")); |
861 |
/* idle DHCP client */ |
/* idle DHCP client */ |
862 |
dhcp_set_state(dhcp, DHCP_OFF); |
dhcp_set_state(dhcp, DHCP_OFF); |
863 |
|
|
879 |
dhcp->tries++; |
dhcp->tries++; |
880 |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
881 |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; |
882 |
DEBUGF(DHCP_DEBUG, ("dhcp_release(): set request timeout %u msecs", msecs)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs", msecs)); |
883 |
/* remove IP address from interface */ |
/* remove IP address from interface */ |
884 |
netif_set_ipaddr(netif, IP_ADDR_ANY); |
netif_set_ipaddr(netif, IP_ADDR_ANY); |
885 |
netif_set_gw(netif, IP_ADDR_ANY); |
netif_set_gw(netif, IP_ADDR_ANY); |
895 |
void dhcp_stop(struct netif *netif) |
void dhcp_stop(struct netif *netif) |
896 |
{ |
{ |
897 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
898 |
DEBUGF(DHCP_DEBUG, ("dhcp_stop()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()")); |
899 |
/* netif is DHCP configured? */ |
/* netif is DHCP configured? */ |
900 |
if (dhcp != NULL) |
if (dhcp != NULL) |
901 |
{ |
{ |
994 |
dhcp->options_in = mem_malloc(dhcp->options_in_len); |
dhcp->options_in = mem_malloc(dhcp->options_in_len); |
995 |
if (dhcp->options_in == NULL) |
if (dhcp->options_in == NULL) |
996 |
{ |
{ |
997 |
DEBUGF(DHCP_DEBUG, ("dhcp_unfold_reply(): could not allocate dhcp->options")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->options")); |
998 |
return ERR_MEM; |
return ERR_MEM; |
999 |
} |
} |
1000 |
} |
} |
1001 |
dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN); |
dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN); |
1002 |
if (dhcp->msg_in == NULL) |
if (dhcp->msg_in == NULL) |
1003 |
{ |
{ |
1004 |
DEBUGF(DHCP_DEBUG, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in")); |
1005 |
mem_free((void *)dhcp->options_in); |
mem_free((void *)dhcp->options_in); |
1006 |
dhcp->options_in = NULL; |
dhcp->options_in = NULL; |
1007 |
return ERR_MEM; |
return ERR_MEM; |
1020 |
j = 0; |
j = 0; |
1021 |
} |
} |
1022 |
} |
} |
1023 |
DEBUGF(DHCP_DEBUG, ("dhcp_unfold_reply(): copied %u bytes into dhcp->msg_in[]", i)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes into dhcp->msg_in[]", i)); |
1024 |
if (dhcp->options_in != NULL) { |
if (dhcp->options_in != NULL) { |
1025 |
ptr = (u8_t *)dhcp->options_in; |
ptr = (u8_t *)dhcp->options_in; |
1026 |
/* proceed through options */ |
/* proceed through options */ |
1033 |
j = 0; |
j = 0; |
1034 |
} |
} |
1035 |
} |
} |
1036 |
DEBUGF(DHCP_DEBUG, ("dhcp_unfold_reply(): copied %u bytes to dhcp->options_in[]", i)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes to dhcp->options_in[]", i)); |
1037 |
} |
} |
1038 |
return ERR_OK; |
return ERR_OK; |
1039 |
} |
} |
1069 |
u8_t *options_ptr; |
u8_t *options_ptr; |
1070 |
u8_t msg_type; |
u8_t msg_type; |
1071 |
u8_t i; |
u8_t i; |
1072 |
DEBUGF(DHCP_DEBUG, ("dhcp_recv()")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_recv()")); |
1073 |
DEBUGF(DHCP_DEBUG, ("pbuf->len = %u", p->len)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u", p->len)); |
1074 |
DEBUGF(DHCP_DEBUG, ("pbuf->tot_len = %u", p->tot_len)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u", p->tot_len)); |
1075 |
dhcp->p = p; |
dhcp->p = p; |
1076 |
if (reply_msg->op != DHCP_BOOTREPLY) { |
if (reply_msg->op != DHCP_BOOTREPLY) { |
1077 |
DEBUGF(DHCP_DEBUG, ("not a DHCP reply message, but type %u", reply_msg->op)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %u", reply_msg->op)); |
1078 |
pbuf_free(p); |
pbuf_free(p); |
1079 |
} |
} |
1080 |
/* iterate through hardware address and match against DHCP message */ |
/* iterate through hardware address and match against DHCP message */ |
1081 |
for (i = 0; i < netif->hwaddr_len; i++) { |
for (i = 0; i < netif->hwaddr_len; i++) { |
1082 |
if (netif->hwaddr[i] != reply_msg->chaddr[i]) { |
if (netif->hwaddr[i] != reply_msg->chaddr[i]) { |
1083 |
DEBUGF(DHCP_DEBUG, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x", |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x", |
1084 |
i, netif->hwaddr[i], i, reply_msg->chaddr[i])); |
i, netif->hwaddr[i], i, reply_msg->chaddr[i])); |
1085 |
pbuf_free(p); |
pbuf_free(p); |
1086 |
return; |
return; |
1088 |
} |
} |
1089 |
/* match transaction ID against what we expected */ |
/* match transaction ID against what we expected */ |
1090 |
if (ntohl(reply_msg->xid) != dhcp->xid) { |
if (ntohl(reply_msg->xid) != dhcp->xid) { |
1091 |
DEBUGF(DHCP_DEBUG, ("transaction id mismatch")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("transaction id mismatch")); |
1092 |
pbuf_free(p); |
pbuf_free(p); |
1093 |
return; |
return; |
1094 |
} |
} |
1095 |
/* option fields could be unfold? */ |
/* option fields could be unfold? */ |
1096 |
if (dhcp_unfold_reply(dhcp) != ERR_OK) { |
if (dhcp_unfold_reply(dhcp) != ERR_OK) { |
1097 |
DEBUGF(DHCP_DEBUG, ("problem unfolding DHCP message - too short on memory?")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?")); |
1098 |
pbuf_free(p); |
pbuf_free(p); |
1099 |
return; |
return; |
1100 |
} |
} |
1101 |
|
|
1102 |
DEBUGF(DHCP_DEBUG, ("searching DHCP_OPTION_MESSAGE_TYPE")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE")); |
1103 |
/* obtain pointer to DHCP message type */ |
/* obtain pointer to DHCP message type */ |
1104 |
options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE); |
options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE); |
1105 |
if (options_ptr == NULL) { |
if (options_ptr == NULL) { |
1106 |
DEBUGF(DHCP_DEBUG, ("DHCP_OPTION_MESSAGE_TYPE option not found")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found")); |
1107 |
pbuf_free(p); |
pbuf_free(p); |
1108 |
return; |
return; |
1109 |
} |
} |
1112 |
msg_type = dhcp_get_option_byte(options_ptr + 2); |
msg_type = dhcp_get_option_byte(options_ptr + 2); |
1113 |
/* message type is DHCP ACK? */ |
/* message type is DHCP ACK? */ |
1114 |
if (msg_type == DHCP_ACK) { |
if (msg_type == DHCP_ACK) { |
1115 |
DEBUGF(DHCP_DEBUG, ("DHCP_ACK received")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_ACK received")); |
1116 |
/* in requesting state? */ |
/* in requesting state? */ |
1117 |
if (dhcp->state == DHCP_REQUESTING) { |
if (dhcp->state == DHCP_REQUESTING) { |
1118 |
dhcp_handle_ack(netif); |
dhcp_handle_ack(netif); |
1135 |
else if ((msg_type == DHCP_NAK) && |
else if ((msg_type == DHCP_NAK) && |
1136 |
((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REQUESTING) || |
((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REQUESTING) || |
1137 |
(dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING ))) { |
(dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING ))) { |
1138 |
DEBUGF(DHCP_DEBUG, ("DHCP_NAK received")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_NAK received")); |
1139 |
dhcp->request_timeout = 0; |
dhcp->request_timeout = 0; |
1140 |
dhcp_handle_nak(netif); |
dhcp_handle_nak(netif); |
1141 |
} |
} |
1142 |
/* received a DHCP_OFFER in DHCP_SELECTING state? */ |
/* received a DHCP_OFFER in DHCP_SELECTING state? */ |
1143 |
else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) { |
else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) { |
1144 |
DEBUGF(DHCP_DEBUG, ("DHCP_OFFER received in DHCP_SELECTING state")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OFFER received in DHCP_SELECTING state")); |
1145 |
dhcp->request_timeout = 0; |
dhcp->request_timeout = 0; |
1146 |
/* remember offered lease */ |
/* remember offered lease */ |
1147 |
dhcp_handle_offer(netif); |
dhcp_handle_offer(netif); |
1158 |
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); |
1159 |
dhcp->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM); |
dhcp->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM); |
1160 |
if (dhcp->p_out == NULL) { |
if (dhcp->p_out == NULL) { |
1161 |
DEBUGF(DHCP_DEBUG, ("dhcp_create_request(): could not allocate pbuf")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_create_request(): could not allocate pbuf")); |
1162 |
return ERR_MEM; |
return ERR_MEM; |
1163 |
} |
} |
1164 |
/* give unique transaction identifier to this request */ |
/* give unique transaction identifier to this request */ |
1246 |
/* DEBUGF(DHCP_DEBUG, ("msg_offset=%u, q->len=%u", msg_offset, q->len)); */ |
/* DEBUGF(DHCP_DEBUG, ("msg_offset=%u, q->len=%u", msg_offset, q->len)); */ |
1247 |
/* are the sname and/or file field overloaded with options? */ |
/* are the sname and/or file field overloaded with options? */ |
1248 |
if (options[offset] == DHCP_OPTION_OVERLOAD) { |
if (options[offset] == DHCP_OPTION_OVERLOAD) { |
1249 |
DEBUGF(DHCP_DEBUG, ("overloaded message detected")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected")); |
1250 |
/* skip option type and length */ |
/* skip option type and length */ |
1251 |
offset += 2; |
offset += 2; |
1252 |
overload = options[offset++]; |
overload = options[offset++]; |
1253 |
} |
} |
1254 |
/* requested option found */ |
/* requested option found */ |
1255 |
else if (options[offset] == option_type) { |
else if (options[offset] == option_type) { |
1256 |
DEBUGF(DHCP_DEBUG, ("option found at offset %u in options", offset)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options", offset)); |
1257 |
return &options[offset]; |
return &options[offset]; |
1258 |
/* skip option */ |
/* skip option */ |
1259 |
} else { |
} else { |
1268 |
if (overload != DHCP_OVERLOAD_NONE) { |
if (overload != DHCP_OVERLOAD_NONE) { |
1269 |
u16_t field_len; |
u16_t field_len; |
1270 |
if (overload == DHCP_OVERLOAD_FILE) { |
if (overload == DHCP_OVERLOAD_FILE) { |
1271 |
DEBUGF(DHCP_DEBUG, ("overloaded file field")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded file field")); |
1272 |
options = (u8_t *)&dhcp->msg_in->file; |
options = (u8_t *)&dhcp->msg_in->file; |
1273 |
field_len = DHCP_FILE_LEN; |
field_len = DHCP_FILE_LEN; |
1274 |
} else if (overload == DHCP_OVERLOAD_SNAME) { |
} else if (overload == DHCP_OVERLOAD_SNAME) { |
1275 |
DEBUGF(DHCP_DEBUG, ("overloaded sname field")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname field")); |
1276 |
options = (u8_t *)&dhcp->msg_in->sname; |
options = (u8_t *)&dhcp->msg_in->sname; |
1277 |
field_len = DHCP_SNAME_LEN; |
field_len = DHCP_SNAME_LEN; |
1278 |
/* TODO: check if else if () is necessary */ |
/* TODO: check if else if () is necessary */ |
1279 |
} else { |
} else { |
1280 |
DEBUGF(DHCP_DEBUG, ("overloaded sname and file field")); |
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname and file field")); |
1281 |
options = (u8_t *)&dhcp->msg_in->sname; |
options = (u8_t *)&dhcp->msg_in->sname; |
1282 |
field_len = DHCP_FILE_LEN + DHCP_SNAME_LEN; |
field_len = DHCP_FILE_LEN + DHCP_SNAME_LEN; |
1283 |
} |
} |
1286 |
/* at least 1 byte to read and no end marker */ |
/* at least 1 byte to read and no end marker */ |
1287 |
while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) { |
while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) { |
1288 |
if (options[offset] == option_type) { |
if (options[offset] == option_type) { |
1289 |
DEBUGF(DHCP_DEBUG, ("option found at offset=%u", offset)); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u", offset)); |
1290 |
return &options[offset]; |
return &options[offset]; |
1291 |
/* skip option */ |
/* skip option */ |
1292 |
} else { |
} else { |
1293 |
DEBUGF(DHCP_DEBUG, ("skipping option %u", options[offset])); |
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u", options[offset])); |
1294 |
/* skip option type */ |
/* skip option type */ |
1295 |
offset++; |
offset++; |
1296 |
offset += 1 + options[offset]; |
offset += 1 + options[offset]; |