/[lwip]/lwip/src/core/dhcp.c
ViewVC logotype

Diff of /lwip/src/core/dhcp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.20 by likewise, Mon Mar 31 08:02:52 2003 UTC revision 1.21 by likewise, Mon Mar 31 10:32:35 2003 UTC
# Line 138  static void dhcp_option_trailer(struct d Line 138  static void dhcp_option_trailer(struct d
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 | DBG_TRACE, ("dhcp_handle_nak()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_handle_nak()\n"));
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 | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs", msecs));    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs\n", msecs));
144    dhcp_set_state(dhcp, DHCP_BACKING_OFF);    dhcp_set_state(dhcp, DHCP_BACKING_OFF);
145  }  }
146    
# Line 157  static void dhcp_check(struct netif *net Line 157  static void dhcp_check(struct netif *net
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 | DBG_TRACE, ("dhcp_check()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check()\n"));
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 | DBG_TRACE, ("dhcp_check(): sending ARP request len %u", p->tot_len));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check(): sending ARP request len %u\n", 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;
# Line 172  static void dhcp_check(struct netif *net Line 172  static void dhcp_check(struct netif *net
172    dhcp->tries++;    dhcp->tries++;
173    msecs = 500;    msecs = 500;
174    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;
175    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs", msecs));    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs\n", msecs));
176    dhcp_set_state(dhcp, DHCP_CHECKING);    dhcp_set_state(dhcp, DHCP_CHECKING);
177  }  }
178    
# Line 189  static void dhcp_handle_offer(struct net Line 189  static void dhcp_handle_offer(struct net
189    if (option_ptr != NULL)    if (option_ptr != NULL)
190    {    {
191      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]));
192      DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx", dhcp->server_ip_addr.addr));      DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx\n", dhcp->server_ip_addr.addr));
193      /* remember offered address */      /* remember offered address */
194      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);
195      DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr));      DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx\n", dhcp->offered_ip_addr.addr));
196      dhcp_select(netif);      dhcp_select(netif);
197    }    }
198  }  }
# Line 210  static err_t dhcp_select(struct netif *n Line 210  static err_t dhcp_select(struct netif *n
210    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
211    err_t result;    err_t result;
212    u32_t msecs;    u32_t msecs;
213    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_select()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_select()\n"));
214    
215    /* create and initialize the DHCP message header */    /* create and initialize the DHCP message header */
216    result = dhcp_create_request(netif);    result = dhcp_create_request(netif);
# Line 255  static err_t dhcp_select(struct netif *n Line 255  static err_t dhcp_select(struct netif *n
255    dhcp->tries++;    dhcp->tries++;
256    msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000;    msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000;
257    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;
258    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs", msecs));    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs\n", msecs));
259    return result;    return result;
260  }  }
261    
# Line 266  static err_t dhcp_select(struct netif *n Line 266  static err_t dhcp_select(struct netif *n
266  void dhcp_coarse_tmr()  void dhcp_coarse_tmr()
267  {  {
268    struct netif *netif = netif_list;    struct netif *netif = netif_list;
269    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr():"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr()\n"));
270    /* iterate through all network interfaces */    /* iterate through all network interfaces */
271    while (netif != NULL) {    while (netif != NULL) {
272      /* only act on DHCP configured interfaces */      /* only act on DHCP configured interfaces */
273      if (netif->dhcp != NULL) {      if (netif->dhcp != NULL) {
274        /* timer is active (non zero), and triggers (zeroes) now? */        /* timer is active (non zero), and triggers (zeroes) now? */
275        if (netif->dhcp->t2_timeout-- == 1) {        if (netif->dhcp->t2_timeout-- == 1) {
276          DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout\n"));
277          /* this clients' rebind timeout triggered */          /* this clients' rebind timeout triggered */
278          dhcp_t2_timeout(netif);          dhcp_t2_timeout(netif);
279        /* timer is active (non zero), and triggers (zeroes) now */        /* timer is active (non zero), and triggers (zeroes) now */
280        } else if (netif->dhcp->t1_timeout-- == 1) {        } else if (netif->dhcp->t1_timeout-- == 1) {
281          DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout\n"));
282          /* this clients' renewal timeout triggered */          /* this clients' renewal timeout triggered */
283          dhcp_t1_timeout(netif);          dhcp_t1_timeout(netif);
284        }        }
# Line 303  void dhcp_fine_tmr() Line 303  void dhcp_fine_tmr()
303      if (netif->dhcp != NULL) {      if (netif->dhcp != NULL) {
304        /* timer is active (non zero), and triggers (zeroes) now */        /* timer is active (non zero), and triggers (zeroes) now */
305        if (netif->dhcp->request_timeout-- == 1) {        if (netif->dhcp->request_timeout-- == 1) {
306          DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout\n"));
307          /* this clients' request timeout triggered */          /* this clients' request timeout triggered */
308          dhcp_timeout(netif);          dhcp_timeout(netif);
309        }        }
# Line 325  void dhcp_fine_tmr() Line 325  void dhcp_fine_tmr()
325  static void dhcp_timeout(struct netif *netif)  static void dhcp_timeout(struct netif *netif)
326  {  {
327    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
328    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()\n"));
329    /* back-off period has passed, or server selection timed out */    /* back-off period has passed, or server selection timed out */
330    if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) {    if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) {
331      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery\n"));
332      dhcp_discover(netif);      dhcp_discover(netif);
333    /* receiving the requested lease timed out */    /* receiving the requested lease timed out */
334    } else if (dhcp->state == DHCP_REQUESTING) {    } else if (dhcp->state == DHCP_REQUESTING) {
335      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out\n"));
336      if (dhcp->tries <= 5) {      if (dhcp->tries <= 5) {
337        dhcp_select(netif);        dhcp_select(netif);
338      } else {      } else {
339        DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting"));        DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
340        dhcp_release(netif);        dhcp_release(netif);
341        dhcp_discover(netif);        dhcp_discover(netif);
342      }      }
343    /* received no ARP reply for the offered address (which is good) */    /* received no ARP reply for the offered address (which is good) */
344    } else if (dhcp->state == DHCP_CHECKING) {    } else if (dhcp->state == DHCP_CHECKING) {
345      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out\n"));
346      if (dhcp->tries <= 1) {      if (dhcp->tries <= 1) {
347        dhcp_check(netif);        dhcp_check(netif);
348      /* no ARP replies on the offered address,      /* no ARP replies on the offered address,
# Line 354  static void dhcp_timeout(struct netif *n Line 354  static void dhcp_timeout(struct netif *n
354    }    }
355    /* did not get response to renew request? */    /* did not get response to renew request? */
356    else if (dhcp->state == DHCP_RENEWING) {    else if (dhcp->state == DHCP_RENEWING) {
357      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RENEWING, DHCP request timed out"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RENEWING, DHCP request timed out\n"));
358      /* just retry renewal */      /* just retry renewal */
359      /* 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 */
360      dhcp_renew(netif);      dhcp_renew(netif);
361    /* did not get response to rebind request? */    /* did not get response to rebind request? */
362    } else if (dhcp->state == DHCP_REBINDING) {    } else if (dhcp->state == DHCP_REBINDING) {
363      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REBINDING, DHCP request timed out"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REBINDING, DHCP request timed out\n"));
364      if (dhcp->tries <= 8) {      if (dhcp->tries <= 8) {
365        dhcp_rebind(netif);        dhcp_rebind(netif);
366      } else {      } else {
367        DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RELEASING, DISCOVERING"));        DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RELEASING, DISCOVERING\n"));
368        dhcp_release(netif);        dhcp_release(netif);
369        dhcp_discover(netif);        dhcp_discover(netif);
370      }      }
# Line 379  static void dhcp_timeout(struct netif *n Line 379  static void dhcp_timeout(struct netif *n
379  static void dhcp_t1_timeout(struct netif *netif)  static void dhcp_t1_timeout(struct netif *netif)
380  {  {
381    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
382    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_t1_timeout()"));    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_t1_timeout()\n"));
383    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)) {
384      /* just retry to renew */      /* just retry to renew */
385      /* 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 */
386      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t1_timeout(): must renew"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t1_timeout(): must renew\n"));
387      dhcp_renew(netif);      dhcp_renew(netif);
388    }    }
389  }  }
# Line 395  static void dhcp_t1_timeout(struct netif Line 395  static void dhcp_t1_timeout(struct netif
395  static void dhcp_t2_timeout(struct netif *netif)  static void dhcp_t2_timeout(struct netif *netif)
396  {  {
397    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
398    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout()\n"));
399    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)) {
400      /* just retry to rebind */      /* just retry to rebind */
401      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout(): must rebind"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout(): must rebind\n"));
402      dhcp_rebind(netif);      dhcp_rebind(netif);
403    }    }
404  }  }
# Line 485  err_t dhcp_start(struct netif *netif) Line 485  err_t dhcp_start(struct netif *netif)
485    err_t result = ERR_OK;    err_t result = ERR_OK;
486    
487    LWIP_ASSERT("netif != NULL", netif != NULL);    LWIP_ASSERT("netif != NULL", netif != NULL);
488    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("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\n", netif, netif->name[0], netif->name[1], netif->num));
489    
490    if (dhcp == NULL) {    if (dhcp == NULL) {
491      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client\n"));
492      dhcp = mem_malloc(sizeof(struct dhcp));      dhcp = mem_malloc(sizeof(struct dhcp));
493      if (dhcp == NULL) {      if (dhcp == NULL) {
494        DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp"));        DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp\n"));
495        netif->flags &= ~NETIF_FLAG_DHCP;        netif->flags &= ~NETIF_FLAG_DHCP;
496        return ERR_MEM;        return ERR_MEM;
497      }      }
# Line 500  err_t dhcp_start(struct netif *netif) Line 500  err_t dhcp_start(struct netif *netif)
500      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): allocated dhcp"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): allocated dhcp"));
501      dhcp->pcb = udp_new();      dhcp->pcb = udp_new();
502      if (dhcp->pcb == NULL) {      if (dhcp->pcb == NULL) {
503        DEBUGF(DHCP_DEBUG  | DBG_TRACE, ("dhcp_start(): could not obtain pcb"));        DEBUGF(DHCP_DEBUG  | DBG_TRACE, ("dhcp_start(): could not obtain pcb\n"));
504        mem_free((void *)dhcp);        mem_free((void *)dhcp);
505        dhcp = NULL;        dhcp = NULL;
506        netif->flags &= ~NETIF_FLAG_DHCP;        netif->flags &= ~NETIF_FLAG_DHCP;
# Line 508  err_t dhcp_start(struct netif *netif) Line 508  err_t dhcp_start(struct netif *netif)
508      }      }
509      /* store this dhcp client in the netif */      /* store this dhcp client in the netif */
510      netif->dhcp = dhcp;      netif->dhcp = dhcp;
511      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb\n"));
512      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n"));
513    } else {    } else {
514      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 3, ("dhcp_start(): restarting DHCP configuration\n"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 3, ("dhcp_start(): restarting DHCP configuration\n"));
515    }    }
# Line 538  void dhcp_inform(struct netif *netif) Line 538  void dhcp_inform(struct netif *netif)
538    err_t result = ERR_OK;    err_t result = ERR_OK;
539    dhcp = mem_malloc(sizeof(struct dhcp));    dhcp = mem_malloc(sizeof(struct dhcp));
540    if (dhcp == NULL) {    if (dhcp == NULL) {
541      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp\n"));
542      return;      return;
543    }      }  
544    memset(dhcp, 0, sizeof(struct dhcp));    memset(dhcp, 0, sizeof(struct dhcp));
545    
546    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp\n"));
547    dhcp->pcb = udp_new();    dhcp->pcb = udp_new();
548    if (dhcp->pcb == NULL) {    if (dhcp->pcb == NULL) {
549      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not obtain pcb"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not obtain pcb"));
550      mem_free((void *)dhcp);      mem_free((void *)dhcp);
551      return;      return;
552    }    }
553    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb\n"));
554    /* create and initialize the DHCP message header */    /* create and initialize the DHCP message header */
555    result = dhcp_create_request(netif);    result = dhcp_create_request(netif);
556    if (result == ERR_OK) {    if (result == ERR_OK) {
# Line 593  void dhcp_inform(struct netif *netif) Line 593  void dhcp_inform(struct netif *netif)
593   */   */
594  void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr)  void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr)
595  {  {
596    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()\n"));
597    /* is this DHCP client doing an ARP check? */    /* is this DHCP client doing an ARP check? */
598    if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) {    if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) {
599      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("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\n", addr->addr));
600      /* did a host respond with the address we      /* did a host respond with the address we
601         were offered by the DHCP server? */         were offered by the DHCP server? */
602      if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {      if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {
603        /* we will not accept the offered address */        /* we will not accept the offered address */
604        DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 1, ("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\n"));
605        dhcp_decline(netif);        dhcp_decline(netif);
606      }      }
607    }    }
# Line 619  static err_t dhcp_decline(struct netif * Line 619  static err_t dhcp_decline(struct netif *
619    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
620    err_t result = ERR_OK;    err_t result = ERR_OK;
621    u16_t msecs;    u16_t msecs;
622    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_decline()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_decline()\n"));
623    dhcp_set_state(dhcp, DHCP_BACKING_OFF);    dhcp_set_state(dhcp, DHCP_BACKING_OFF);
624    /* create and initialize the DHCP message header */    /* create and initialize the DHCP message header */
625    result = dhcp_create_request(netif);    result = dhcp_create_request(netif);
# Line 646  static err_t dhcp_decline(struct netif * Line 646  static err_t dhcp_decline(struct netif *
646    dhcp->tries++;    dhcp->tries++;
647    msecs = 10*1000;    msecs = 10*1000;
648    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;
649     DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs", msecs));     DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs\n", msecs));
650    return result;    return result;
651  }  }
652  #endif  #endif
# Line 661  static err_t dhcp_discover(struct netif Line 661  static err_t dhcp_discover(struct netif
661    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
662    err_t result = ERR_OK;    err_t result = ERR_OK;
663    u16_t msecs;    u16_t msecs;
664    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_discover()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_discover()\n"));
665    ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY);    ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY);
666    /* create and initialize the DHCP message header */    /* create and initialize the DHCP message header */
667    result = dhcp_create_request(netif);    result = dhcp_create_request(netif);
668    if (result == ERR_OK)    if (result == ERR_OK)
669    {    {
670      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: making request"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: making request\n"));
671      dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);      dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
672      dhcp_option_byte(dhcp, DHCP_DISCOVER);      dhcp_option_byte(dhcp, DHCP_DISCOVER);
673    
# Line 681  static err_t dhcp_discover(struct netif Line 681  static err_t dhcp_discover(struct netif
681    
682      dhcp_option_trailer(dhcp);      dhcp_option_trailer(dhcp);
683    
684      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: realloc()ing"));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: realloc()ing\n"));
685      pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);      pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
686    
687      /* set receive callback function with netif as user data */      /* set receive callback function with netif as user data */
# Line 706  static err_t dhcp_discover(struct netif Line 706  static err_t dhcp_discover(struct netif
706    dhcp->tries++;    dhcp->tries++;
707    msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000;    msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000;
708    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;
709    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs", msecs));    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs\n", msecs));
710    return result;    return result;
711  }  }
712    
# Line 724  static void dhcp_bind(struct netif *neti Line 724  static void dhcp_bind(struct netif *neti
724    /* temporary DHCP lease? */    /* temporary DHCP lease? */
725    if (dhcp->offered_t1_renew != 0xffffffffUL) {    if (dhcp->offered_t1_renew != 0xffffffffUL) {
726      /* set renewal period timer */      /* set renewal period timer */
727      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs", dhcp->offered_t1_renew));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs\n", dhcp->offered_t1_renew));
728      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;
729      if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1;      if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1;
730      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("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\n", dhcp->offered_t1_renew*1000));
731    }    }
732    /* set renewal period timer */    /* set renewal period timer */
733    if (dhcp->offered_t2_rebind != 0xffffffffUL) {    if (dhcp->offered_t2_rebind != 0xffffffffUL) {
734      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs", dhcp->offered_t2_rebind));      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs\n", dhcp->offered_t2_rebind));
735      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;
736      if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1;      if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1;
737      DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("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\n", dhcp->offered_t2_rebind*1000));
738    }    }
739    /* copy offered network mask */    /* copy offered network mask */
740    ip_addr_set(&sn_mask, &dhcp->offered_sn_mask);    ip_addr_set(&sn_mask, &dhcp->offered_sn_mask);
# Line 758  static void dhcp_bind(struct netif *neti Line 758  static void dhcp_bind(struct netif *neti
758      gw_addr.addr |= htonl(0x00000001);      gw_addr.addr |= htonl(0x00000001);
759    }    }
760    
761    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx", dhcp->offered_ip_addr.addr));    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx\n", dhcp->offered_ip_addr.addr));
762    netif_set_ipaddr(netif, &dhcp->offered_ip_addr);    netif_set_ipaddr(netif, &dhcp->offered_ip_addr);
763    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx", sn_mask.addr));    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx\n", sn_mask.addr));
764    netif_set_netmask(netif, &sn_mask);    netif_set_netmask(netif, &sn_mask);
765    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx", gw_addr.addr));    DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx\n", gw_addr.addr));
766    netif_set_gw(netif, &gw_addr);    netif_set_gw(netif, &gw_addr);
767    /* netif is now bound to DHCP leased address */    /* netif is now bound to DHCP leased address */
768    dhcp_set_state(dhcp, DHCP_BOUND);    dhcp_set_state(dhcp, DHCP_BOUND);
# Line 778  err_t dhcp_renew(struct netif *netif) Line 778  err_t dhcp_renew(struct netif *netif)
778    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
779    err_t result;    err_t result;
780    u16_t msecs;    u16_t msecs;
781    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()\n"));
782    dhcp_set_state(dhcp, DHCP_RENEWING);    dhcp_set_state(dhcp, DHCP_RENEWING);
783    
784    /* create and initialize the DHCP message header */    /* create and initialize the DHCP message header */
# Line 819  err_t dhcp_renew(struct netif *netif) Line 819  err_t dhcp_renew(struct netif *netif)
819    /* back-off on retries, but to a maximum of 20 seconds */    /* back-off on retries, but to a maximum of 20 seconds */
820    msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000;    msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000;
821    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;
822     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs", msecs));     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs\n", msecs));
823    return result;    return result;
824  }  }
825    
# Line 833  static err_t dhcp_rebind(struct netif *n Line 833  static err_t dhcp_rebind(struct netif *n
833    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
834    err_t result;    err_t result;
835    u16_t msecs;    u16_t msecs;
836    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind()\n"));
837    dhcp_set_state(dhcp, DHCP_REBINDING);    dhcp_set_state(dhcp, DHCP_REBINDING);
838    
839    /* create and initialize the DHCP message header */    /* create and initialize the DHCP message header */
# Line 871  static err_t dhcp_rebind(struct netif *n Line 871  static err_t dhcp_rebind(struct netif *n
871    dhcp->tries++;    dhcp->tries++;
872    msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;    msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
873    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;
874     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs", msecs));     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs\n", msecs));
875    return result;    return result;
876  }  }
877    
# Line 885  static err_t dhcp_release(struct netif * Line 885  static err_t dhcp_release(struct netif *
885    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
886    err_t result;    err_t result;
887    u16_t msecs;    u16_t msecs;
888    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_release()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_release()\n"));
889    
890    /* idle DHCP client */    /* idle DHCP client */
891    dhcp_set_state(dhcp, DHCP_OFF);    dhcp_set_state(dhcp, DHCP_OFF);
# Line 912  static err_t dhcp_release(struct netif * Line 912  static err_t dhcp_release(struct netif *
912    dhcp->tries++;    dhcp->tries++;
913    msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;    msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
914    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;
915     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs", msecs));     DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs\n", msecs));
916    /* remove IP address from interface */    /* remove IP address from interface */
917    netif_set_ipaddr(netif, IP_ADDR_ANY);    netif_set_ipaddr(netif, IP_ADDR_ANY);
918    netif_set_gw(netif, IP_ADDR_ANY);    netif_set_gw(netif, IP_ADDR_ANY);
# Line 928  static err_t dhcp_release(struct netif * Line 928  static err_t dhcp_release(struct netif *
928  void dhcp_stop(struct netif *netif)  void dhcp_stop(struct netif *netif)
929  {  {
930    struct dhcp *dhcp = netif->dhcp;    struct dhcp *dhcp = netif->dhcp;
931    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()\n"));
932    /* netif is DHCP configured? */    /* netif is DHCP configured? */
933    if (dhcp != NULL)    if (dhcp != NULL)
934    {    {
# Line 1027  static err_t dhcp_unfold_reply(struct dh Line 1027  static err_t dhcp_unfold_reply(struct dh
1027      dhcp->options_in = mem_malloc(dhcp->options_in_len);      dhcp->options_in = mem_malloc(dhcp->options_in_len);
1028      if (dhcp->options_in == NULL)      if (dhcp->options_in == NULL)
1029      {      {
1030        DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->options"));        DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->options\n"));
1031        return ERR_MEM;        return ERR_MEM;
1032      }      }
1033    }    }
1034    dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN);    dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN);
1035    if (dhcp->msg_in == NULL)    if (dhcp->msg_in == NULL)
1036    {    {
1037      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in\n"));
1038      mem_free((void *)dhcp->options_in);      mem_free((void *)dhcp->options_in);
1039      dhcp->options_in = NULL;      dhcp->options_in = NULL;
1040      return ERR_MEM;      return ERR_MEM;
# Line 1053  static err_t dhcp_unfold_reply(struct dh Line 1053  static err_t dhcp_unfold_reply(struct dh
1053        j = 0;        j = 0;
1054      }      }
1055    }    }
1056    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("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[]\n", i));
1057    if (dhcp->options_in != NULL) {    if (dhcp->options_in != NULL) {
1058      ptr = (u8_t *)dhcp->options_in;      ptr = (u8_t *)dhcp->options_in;
1059      /* proceed through options */      /* proceed through options */
# Line 1066  static err_t dhcp_unfold_reply(struct dh Line 1066  static err_t dhcp_unfold_reply(struct dh
1066          j = 0;          j = 0;
1067        }        }
1068      }      }
1069      DEBUGF(DHCP_DEBUG | DBG_TRACE, ("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[]\n", i));
1070    }    }
1071    return ERR_OK;    return ERR_OK;
1072  }  }
# Line 1087  static void dhcp_free_reply(struct dhcp Line 1087  static void dhcp_free_reply(struct dhcp
1087      dhcp->options_in = NULL;      dhcp->options_in = NULL;
1088      dhcp->options_in_len = 0;      dhcp->options_in_len = 0;
1089    }    }
1090    DEBUGF(DHCP_DEBUG, ("dhcp_free_reply(): freed"));    DEBUGF(DHCP_DEBUG, ("dhcp_free_reply(): free'd\n"));
1091  }  }
1092    
1093    
# Line 1102  static void dhcp_recv(void *arg, struct Line 1102  static void dhcp_recv(void *arg, struct
1102    u8_t *options_ptr;    u8_t *options_ptr;
1103    u8_t msg_type;    u8_t msg_type;
1104    u8_t i;    u8_t i;
1105    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_recv()"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_recv()\n"));
1106    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u", p->len));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u\n", p->len));
1107    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u", p->tot_len));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u\n", p->tot_len));
1108    dhcp->p = p;    dhcp->p = p;
1109    if (reply_msg->op != DHCP_BOOTREPLY) {    if (reply_msg->op != DHCP_BOOTREPLY) {
1110      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("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\n", reply_msg->op));
1111      pbuf_free(p);      pbuf_free(p);
1112    }    }
1113    /* iterate through hardware address and match against DHCP message */    /* iterate through hardware address and match against DHCP message */
1114    for (i = 0; i < netif->hwaddr_len; i++) {    for (i = 0; i < netif->hwaddr_len; i++) {
1115      if (netif->hwaddr[i] != reply_msg->chaddr[i]) {      if (netif->hwaddr[i] != reply_msg->chaddr[i]) {
1116        DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x",        DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x\n",
1117          i, netif->hwaddr[i], i, reply_msg->chaddr[i]));          i, netif->hwaddr[i], i, reply_msg->chaddr[i]));
1118        pbuf_free(p);        pbuf_free(p);
1119        return;        return;
# Line 1121  static void dhcp_recv(void *arg, struct Line 1121  static void dhcp_recv(void *arg, struct
1121    }    }
1122    /* match transaction ID against what we expected */    /* match transaction ID against what we expected */
1123    if (ntohl(reply_msg->xid) != dhcp->xid) {    if (ntohl(reply_msg->xid) != dhcp->xid) {
1124      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("transaction id mismatch"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("transaction id mismatch\n"));
1125      pbuf_free(p);      pbuf_free(p);
1126      return;      return;
1127    }    }
1128    /* option fields could be unfold? */    /* option fields could be unfold? */
1129    if (dhcp_unfold_reply(dhcp) != ERR_OK) {    if (dhcp_unfold_reply(dhcp) != ERR_OK) {
1130      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?\n"));
1131      pbuf_free(p);      pbuf_free(p);
1132      return;      return;
1133    }    }
1134        
1135    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE"));    DEBUGF(DHCP_DEBUG | DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE\n"));
1136    /* obtain pointer to DHCP message type */    /* obtain pointer to DHCP message type */
1137    options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE);    options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE);
1138    if (options_ptr == NULL) {    if (options_ptr == NULL) {
1139      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found\n"));
1140      pbuf_free(p);      pbuf_free(p);
1141      return;      return;
1142    }      }  
# Line 1145  static void dhcp_recv(void *arg, struct Line 1145  static void dhcp_recv(void *arg, struct
1145    msg_type = dhcp_get_option_byte(options_ptr + 2);    msg_type = dhcp_get_option_byte(options_ptr + 2);
1146    /* message type is DHCP ACK? */    /* message type is DHCP ACK? */
1147    if (msg_type == DHCP_ACK) {    if (msg_type == DHCP_ACK) {
1148      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_ACK received"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_ACK received\n"));
1149      /* in requesting state? */      /* in requesting state? */
1150      if (dhcp->state == DHCP_REQUESTING) {      if (dhcp->state == DHCP_REQUESTING) {
1151        dhcp_handle_ack(netif);        dhcp_handle_ack(netif);
# Line 1168  static void dhcp_recv(void *arg, struct Line 1168  static void dhcp_recv(void *arg, struct
1168    else if ((msg_type == DHCP_NAK) &&    else if ((msg_type == DHCP_NAK) &&
1169      ((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REQUESTING) ||      ((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REQUESTING) ||
1170       (dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING  ))) {       (dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING  ))) {
1171      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_NAK received"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_NAK received\n"));
1172      dhcp->request_timeout = 0;      dhcp->request_timeout = 0;
1173      dhcp_handle_nak(netif);      dhcp_handle_nak(netif);
1174    }    }
1175    /* received a DHCP_OFFER in DHCP_SELECTING state? */    /* received a DHCP_OFFER in DHCP_SELECTING state? */
1176    else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) {    else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) {
1177      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OFFER received in DHCP_SELECTING state"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OFFER received in DHCP_SELECTING state\n"));
1178      dhcp->request_timeout = 0;      dhcp->request_timeout = 0;
1179      /* remember offered lease */      /* remember offered lease */
1180      dhcp_handle_offer(netif);      dhcp_handle_offer(netif);
# Line 1191  static err_t dhcp_create_request(struct Line 1191  static err_t dhcp_create_request(struct
1191    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);
1192    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);
1193    if (dhcp->p_out == NULL) {    if (dhcp->p_out == NULL) {
1194      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_create_request(): could not allocate pbuf"));      DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_create_request(): could not allocate pbuf\n"));
1195      return ERR_MEM;      return ERR_MEM;
1196    }    }
1197    /* give unique transaction identifier to this request */    /* give unique transaction identifier to this request */
# Line 1244  static void dhcp_delete_request(struct n Line 1244  static void dhcp_delete_request(struct n
1244    
1245  static void dhcp_option_trailer(struct dhcp *dhcp)  static void dhcp_option_trailer(struct dhcp *dhcp)
1246  {  {
1247    LWIP_ASSERT("dhcp_option_trailer: dhcp->msg_out != NULL", dhcp->msg_out != NULL);    LWIP_ASSERT("dhcp_option_trailer: dhcp->msg_out != NULL\n", dhcp->msg_out != NULL);
1248    LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN", dhcp->options_out_len < DHCP_OPTIONS_LEN);    LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_len < DHCP_OPTIONS_LEN);
1249    dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END;    dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END;
1250    /* packet is too small, or not 4 byte aligned? */    /* packet is too small, or not 4 byte aligned? */
1251    while ((dhcp->options_out_len < DHCP_MIN_OPTIONS_LEN) || (dhcp->options_out_len & 3)) {    while ((dhcp->options_out_len < DHCP_MIN_OPTIONS_LEN) || (dhcp->options_out_len & 3)) {
1252      /* DEBUGF(DHCP_DEBUG, ("dhcp_option_trailer: dhcp->options_out_len=%u, DHCP_OPTIONS_LEN=%u", dhcp->options_out_len, DHCP_OPTIONS_LEN)); */      /* DEBUGF(DHCP_DEBUG, ("dhcp_option_trailer: dhcp->options_out_len=%u, DHCP_OPTIONS_LEN=%u", dhcp->options_out_len, DHCP_OPTIONS_LEN)); */
1253      LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN", dhcp->options_out_len < DHCP_OPTIONS_LEN);      LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_len < DHCP_OPTIONS_LEN);
1254      /* add a fill/padding byte */      /* add a fill/padding byte */
1255      dhcp->msg_out->options[dhcp->options_out_len++] = 0;      dhcp->msg_out->options[dhcp->options_out_len++] = 0;
1256    }    }
# Line 1279  static u8_t *dhcp_get_option_ptr(struct Line 1279  static u8_t *dhcp_get_option_ptr(struct
1279        /* 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)); */
1280        /* are the sname and/or file field overloaded with options? */        /* are the sname and/or file field overloaded with options? */
1281        if (options[offset] == DHCP_OPTION_OVERLOAD) {        if (options[offset] == DHCP_OPTION_OVERLOAD) {
1282          DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected\n"));
1283          /* skip option type and length */          /* skip option type and length */
1284          offset += 2;          offset += 2;
1285          overload = options[offset++];          overload = options[offset++];
1286        }        }
1287        /* requested option found */        /* requested option found */
1288        else if (options[offset] == option_type) {        else if (options[offset] == option_type) {
1289          DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options", offset));          DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options\n", offset));
1290          return &options[offset];          return &options[offset];
1291        /* skip option */        /* skip option */
1292        } else {        } else {
1293           DEBUGF(DHCP_DEBUG, ("skipping option %u in options", options[offset]));           DEBUGF(DHCP_DEBUG, ("skipping option %u in options\n", options[offset]));
1294          /* skip option type */          /* skip option type */
1295          offset++;          offset++;
1296          /* skip option length, and then length bytes */          /* skip option length, and then length bytes */
# Line 1301  static u8_t *dhcp_get_option_ptr(struct Line 1301  static u8_t *dhcp_get_option_ptr(struct
1301      if (overload != DHCP_OVERLOAD_NONE) {      if (overload != DHCP_OVERLOAD_NONE) {
1302        u16_t field_len;        u16_t field_len;
1303        if (overload == DHCP_OVERLOAD_FILE) {        if (overload == DHCP_OVERLOAD_FILE) {
1304          DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded file field"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded file field\n"));
1305          options = (u8_t *)&dhcp->msg_in->file;          options = (u8_t *)&dhcp->msg_in->file;
1306          field_len = DHCP_FILE_LEN;          field_len = DHCP_FILE_LEN;
1307        } else if (overload == DHCP_OVERLOAD_SNAME) {        } else if (overload == DHCP_OVERLOAD_SNAME) {
1308          DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname field"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname field\n"));
1309          options = (u8_t *)&dhcp->msg_in->sname;          options = (u8_t *)&dhcp->msg_in->sname;
1310          field_len = DHCP_SNAME_LEN;          field_len = DHCP_SNAME_LEN;
1311        /* TODO: check if else if () is necessary */        /* TODO: check if else if () is necessary */
1312        } else {        } else {
1313          DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname and file field"));          DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname and file field\n"));
1314          options = (u8_t *)&dhcp->msg_in->sname;          options = (u8_t *)&dhcp->msg_in->sname;
1315          field_len = DHCP_FILE_LEN + DHCP_SNAME_LEN;          field_len = DHCP_FILE_LEN + DHCP_SNAME_LEN;
1316        }        }
# Line 1319  static u8_t *dhcp_get_option_ptr(struct Line 1319  static u8_t *dhcp_get_option_ptr(struct
1319        /* at least 1 byte to read and no end marker */        /* at least 1 byte to read and no end marker */
1320        while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) {        while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) {
1321          if (options[offset] == option_type) {          if (options[offset] == option_type) {
1322             DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u", offset));             DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u\n", offset));
1323            return &options[offset];            return &options[offset];
1324          /* skip option */          /* skip option */
1325          } else {          } else {
1326            DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u", options[offset]));            DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u\n", options[offset]));
1327            /* skip option type */            /* skip option type */
1328            offset++;            offset++;
1329            offset += 1 + options[offset];            offset += 1 + options[offset];
# Line 1344  static u8_t *dhcp_get_option_ptr(struct Line 1344  static u8_t *dhcp_get_option_ptr(struct
1344   */   */
1345  static u8_t dhcp_get_option_byte(u8_t *ptr)  static u8_t dhcp_get_option_byte(u8_t *ptr)
1346  {  {
1347    DEBUGF(DHCP_DEBUG, ("option byte value=%u", *ptr));    DEBUGF(DHCP_DEBUG, ("option byte value=%u\n", *ptr));
1348    return *ptr;    return *ptr;
1349  }                              }                            
1350    
# Line 1361  static u16_t dhcp_get_option_short(u8_t Line 1361  static u16_t dhcp_get_option_short(u8_t
1361    u16_t value;    u16_t value;
1362    value = *ptr++ << 8;    value = *ptr++ << 8;
1363    value |= *ptr;    value |= *ptr;
1364    DEBUGF(DHCP_DEBUG, ("option short value=%u", value));    DEBUGF(DHCP_DEBUG, ("option short value=%u\n", value));
1365    return value;    return value;
1366  }                              }                            
1367    
# Line 1380  static u32_t dhcp_get_option_long(u8_t * Line 1380  static u32_t dhcp_get_option_long(u8_t *
1380    value |= (u32_t)(*ptr++) << 16;    value |= (u32_t)(*ptr++) << 16;
1381    value |= (u32_t)(*ptr++) << 8;    value |= (u32_t)(*ptr++) << 8;
1382    value |= (u32_t)(*ptr++);    value |= (u32_t)(*ptr++);
1383    DEBUGF(DHCP_DEBUG, ("option long value=%lu", value));    DEBUGF(DHCP_DEBUG, ("option long value=%lu\n", value));
1384    return value;    return value;
1385  }                              }                            

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26