100 |
static void dhcp_bind(struct netif *netif); |
static void dhcp_bind(struct netif *netif); |
101 |
static err_t dhcp_decline(struct netif *netif); |
static err_t dhcp_decline(struct netif *netif); |
102 |
static err_t dhcp_rebind(struct netif *netif); |
static err_t dhcp_rebind(struct netif *netif); |
103 |
static void dhcp_set_state(struct dhcp *dhcp, unsigned char new_state); |
static void dhcp_set_state(struct dhcp *dhcp, u8_t new_state); |
104 |
|
|
105 |
/** receive, unfold, parse and free incoming messages */ |
/** receive, unfold, parse and free incoming messages */ |
106 |
static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port); |
static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port); |
144 |
static void dhcp_handle_nak(struct netif *netif) { |
static void dhcp_handle_nak(struct netif *netif) { |
145 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
146 |
u16_t msecs = 10 * 1000; |
u16_t msecs = 10 * 1000; |
147 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_handle_nak(netif=%p) %c%c%u\n", netif, |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n", |
148 |
netif->name[0], netif->name[1], (unsigned int)netif->num)); |
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); |
149 |
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; |
150 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %"U16_F" msecs\n", msecs)); |
151 |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
dhcp_set_state(dhcp, DHCP_BACKING_OFF); |
152 |
} |
} |
153 |
|
|
163 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
164 |
err_t result; |
err_t result; |
165 |
u16_t msecs; |
u16_t msecs; |
166 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (unsigned int)netif->name[0], |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0], |
167 |
(unsigned int)netif->name[1])); |
(s16_t)netif->name[1])); |
168 |
/* 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 |
169 |
responds, as the IP address should not be in use. */ |
responds, as the IP address should not be in use. */ |
170 |
result = etharp_query(netif, &dhcp->offered_ip_addr, NULL); |
result = etharp_query(netif, &dhcp->offered_ip_addr, NULL); |
174 |
dhcp->tries++; |
dhcp->tries++; |
175 |
msecs = 500; |
msecs = 500; |
176 |
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; |
177 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %"U16_F" msecs\n", msecs)); |
178 |
dhcp_set_state(dhcp, DHCP_CHECKING); |
dhcp_set_state(dhcp, DHCP_CHECKING); |
179 |
} |
} |
180 |
|
|
188 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
189 |
/* obtain the server address */ |
/* obtain the server address */ |
190 |
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); |
191 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_handle_offer(netif=%p) %c%c%u\n", netif, |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n", |
192 |
netif->name[0], netif->name[1], netif->num)); |
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); |
193 |
if (option_ptr != NULL) |
if (option_ptr != NULL) |
194 |
{ |
{ |
195 |
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])); |
196 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx\n", dhcp->server_ip_addr.addr)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n", dhcp->server_ip_addr.addr)); |
197 |
/* remember offered address */ |
/* remember offered address */ |
198 |
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); |
199 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx\n", dhcp->offered_ip_addr.addr)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08"X32_F"\n", dhcp->offered_ip_addr.addr)); |
200 |
|
|
201 |
dhcp_select(netif); |
dhcp_select(netif); |
202 |
} |
} |
215 |
struct dhcp *dhcp = netif->dhcp; |
struct dhcp *dhcp = netif->dhcp; |
216 |
err_t result; |
err_t result; |
217 |
u32_t msecs; |
u32_t msecs; |
218 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_select(netif=%p) %c%c%u\n", netif, netif->name[0], netif->name[1], netif->num)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_select(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); |
219 |
|
|
220 |
/* create and initialize the DHCP message header */ |
/* create and initialize the DHCP message header */ |
221 |
result = dhcp_create_request(netif); |
result = dhcp_create_request(netif); |
261 |
dhcp->tries++; |
dhcp->tries++; |
262 |
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000; |
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000; |
263 |
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; |
264 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %"U32_F" msecs\n", msecs)); |
265 |
return result; |
return result; |
266 |
} |
} |
267 |
|
|
519 |
err_t result = ERR_OK; |
err_t result = ERR_OK; |
520 |
|
|
521 |
LWIP_ASSERT("netif != NULL", netif != NULL); |
LWIP_ASSERT("netif != NULL", netif != NULL); |
522 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_start(netif=%p) %c%c%u\n", netif, netif->name[0], netif->name[1], netif->num)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); |
523 |
netif->flags &= ~NETIF_FLAG_DHCP; |
netif->flags &= ~NETIF_FLAG_DHCP; |
524 |
|
|
525 |
/* no DHCP client attached yet? */ |
/* no DHCP client attached yet? */ |
637 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()\n")); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()\n")); |
638 |
/* is a DHCP client doing an ARP check? */ |
/* is a DHCP client doing an ARP check? */ |
639 |
if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { |
if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { |
640 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx\n", addr->addr)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08"X32_F"\n", addr->addr)); |
641 |
/* did a host respond with the address we |
/* did a host respond with the address we |
642 |
were offered by the DHCP server? */ |
were offered by the DHCP server? */ |
643 |
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { |
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { |
692 |
dhcp->tries++; |
dhcp->tries++; |
693 |
msecs = 10*1000; |
msecs = 10*1000; |
694 |
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; |
695 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %"U16_F" msecs\n", msecs)); |
696 |
return result; |
return result; |
697 |
} |
} |
698 |
#endif |
#endif |
747 |
dhcp->tries++; |
dhcp->tries++; |
748 |
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000; |
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000; |
749 |
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; |
750 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs)); |
751 |
return result; |
return result; |
752 |
} |
} |
753 |
|
|
763 |
struct ip_addr sn_mask, gw_addr; |
struct ip_addr sn_mask, gw_addr; |
764 |
LWIP_ASSERT("dhcp_bind: netif != NULL", netif != NULL); |
LWIP_ASSERT("dhcp_bind: netif != NULL", netif != NULL); |
765 |
LWIP_ASSERT("dhcp_bind: dhcp != NULL", dhcp != NULL); |
LWIP_ASSERT("dhcp_bind: dhcp != NULL", dhcp != NULL); |
766 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_bind(netif=%p) %c%c%u\n", netif, netif->name[0], netif->name[1], netif->num)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); |
767 |
|
|
768 |
/* temporary DHCP lease? */ |
/* temporary DHCP lease? */ |
769 |
if (dhcp->offered_t1_renew != 0xffffffffUL) { |
if (dhcp->offered_t1_renew != 0xffffffffUL) { |
770 |
/* set renewal period timer */ |
/* set renewal period timer */ |
771 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs\n", dhcp->offered_t1_renew)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %"U32_F" secs\n", dhcp->offered_t1_renew)); |
772 |
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; |
773 |
if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1; |
if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1; |
774 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs\n", dhcp->offered_t1_renew*1000)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t1_renew*1000)); |
775 |
} |
} |
776 |
/* set renewal period timer */ |
/* set renewal period timer */ |
777 |
if (dhcp->offered_t2_rebind != 0xffffffffUL) { |
if (dhcp->offered_t2_rebind != 0xffffffffUL) { |
778 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs\n", dhcp->offered_t2_rebind)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %"U32_F" secs\n", dhcp->offered_t2_rebind)); |
779 |
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; |
780 |
if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1; |
if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1; |
781 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs\n", dhcp->offered_t2_rebind*1000)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t2_rebind*1000)); |
782 |
} |
} |
783 |
/* copy offered network mask */ |
/* copy offered network mask */ |
784 |
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); |
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); |
802 |
gw_addr.addr |= htonl(0x00000001); |
gw_addr.addr |= htonl(0x00000001); |
803 |
} |
} |
804 |
|
|
805 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx\n", dhcp->offered_ip_addr.addr)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n", dhcp->offered_ip_addr.addr)); |
806 |
netif_set_ipaddr(netif, &dhcp->offered_ip_addr); |
netif_set_ipaddr(netif, &dhcp->offered_ip_addr); |
807 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx\n", sn_mask.addr)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08"X32_F"\n", sn_mask.addr)); |
808 |
netif_set_netmask(netif, &sn_mask); |
netif_set_netmask(netif, &sn_mask); |
809 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx\n", gw_addr.addr)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n", gw_addr.addr)); |
810 |
netif_set_gw(netif, &gw_addr); |
netif_set_gw(netif, &gw_addr); |
811 |
/* bring the interface up */ |
/* bring the interface up */ |
812 |
netif_set_up(netif); |
netif_set_up(netif); |
865 |
/* back-off on retries, but to a maximum of 20 seconds */ |
/* back-off on retries, but to a maximum of 20 seconds */ |
866 |
msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000; |
867 |
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; |
868 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %"U16_F" msecs\n", msecs)); |
869 |
return result; |
return result; |
870 |
} |
} |
871 |
|
|
918 |
dhcp->tries++; |
dhcp->tries++; |
919 |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
920 |
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; |
921 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %"U16_F" msecs\n", msecs)); |
922 |
return result; |
return result; |
923 |
} |
} |
924 |
|
|
964 |
dhcp->tries++; |
dhcp->tries++; |
965 |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; |
966 |
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; |
967 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs\n", msecs)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %"U16_F" msecs\n", msecs)); |
968 |
/* bring the interface down */ |
/* bring the interface down */ |
969 |
netif_set_down(netif); |
netif_set_down(netif); |
970 |
/* remove IP address from interface */ |
/* remove IP address from interface */ |
1013 |
* |
* |
1014 |
* TODO: we might also want to reset the timeout here? |
* TODO: we might also want to reset the timeout here? |
1015 |
*/ |
*/ |
1016 |
static void dhcp_set_state(struct dhcp *dhcp, unsigned char new_state) |
static void dhcp_set_state(struct dhcp *dhcp, u8_t new_state) |
1017 |
{ |
{ |
1018 |
if (new_state != dhcp->state) |
if (new_state != dhcp->state) |
1019 |
{ |
{ |
1109 |
j = 0; |
j = 0; |
1110 |
} |
} |
1111 |
} |
} |
1112 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes into dhcp->msg_in[]\n", i)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %"U16_F" bytes into dhcp->msg_in[]\n", i)); |
1113 |
if (dhcp->options_in != NULL) { |
if (dhcp->options_in != NULL) { |
1114 |
ptr = (u8_t *)dhcp->options_in; |
ptr = (u8_t *)dhcp->options_in; |
1115 |
/* proceed through options */ |
/* proceed through options */ |
1122 |
j = 0; |
j = 0; |
1123 |
} |
} |
1124 |
} |
} |
1125 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes to dhcp->options_in[]\n", i)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %"U16_F" bytes to dhcp->options_in[]\n", i)); |
1126 |
} |
} |
1127 |
return ERR_OK; |
return ERR_OK; |
1128 |
} |
} |
1158 |
u8_t *options_ptr; |
u8_t *options_ptr; |
1159 |
u8_t msg_type; |
u8_t msg_type; |
1160 |
u8_t i; |
u8_t i; |
1161 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_recv(pbuf = %p) from DHCP server %u.%u.%u.%u port %u\n", p, |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_recv(pbuf = %p) from DHCP server %"U16_F".%"U16_F".%"U16_F".%"U16_F" port %"U16_F"\n", (void*)p, |
1162 |
(unsigned int)(ntohl(addr->addr) >> 24 & 0xff), (unsigned int)(ntohl(addr->addr) >> 16 & 0xff), |
(u16_t)(ntohl(addr->addr) >> 24 & 0xff), (u16_t)(ntohl(addr->addr) >> 16 & 0xff), |
1163 |
(unsigned int)(ntohl(addr->addr) >> 8 & 0xff), (unsigned int)(ntohl(addr->addr) & 0xff), port)); |
(u16_t)(ntohl(addr->addr) >> 8 & 0xff), (u16_t)(ntohl(addr->addr) & 0xff), port)); |
1164 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u\n", p->len)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %"U16_F"\n", p->len)); |
1165 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u\n", p->tot_len)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %"U16_F"\n", p->tot_len)); |
1166 |
/* prevent warnings about unused arguments */ |
/* prevent warnings about unused arguments */ |
1167 |
(void)pcb; (void)addr; (void)port; |
(void)pcb; (void)addr; (void)port; |
1168 |
dhcp->p = p; |
dhcp->p = p; |
1169 |
/* TODO: check packet length before reading them */ |
/* TODO: check packet length before reading them */ |
1170 |
if (reply_msg->op != DHCP_BOOTREPLY) { |
if (reply_msg->op != DHCP_BOOTREPLY) { |
1171 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %u\n", reply_msg->op)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %"U16_F"\n", (u16_t)reply_msg->op)); |
1172 |
pbuf_free(p); |
pbuf_free(p); |
1173 |
dhcp->p = NULL; |
dhcp->p = NULL; |
1174 |
return; |
return; |
1176 |
/* iterate through hardware address and match against DHCP message */ |
/* iterate through hardware address and match against DHCP message */ |
1177 |
for (i = 0; i < netif->hwaddr_len; i++) { |
for (i = 0; i < netif->hwaddr_len; i++) { |
1178 |
if (netif->hwaddr[i] != reply_msg->chaddr[i]) { |
if (netif->hwaddr[i] != reply_msg->chaddr[i]) { |
1179 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x\n", |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%"U16_F"]==%02"X16_F" != reply_msg->chaddr[%"U16_F"]==%02"X16_F"\n", |
1180 |
i, netif->hwaddr[i], i, reply_msg->chaddr[i])); |
(u16_t)i, (u16_t)netif->hwaddr[i], (u16_t)i, (u16_t)reply_msg->chaddr[i])); |
1181 |
pbuf_free(p); |
pbuf_free(p); |
1182 |
dhcp->p = NULL; |
dhcp->p = NULL; |
1183 |
return; |
return; |
1317 |
dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END; |
dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END; |
1318 |
/* packet is too small, or not 4 byte aligned? */ |
/* packet is too small, or not 4 byte aligned? */ |
1319 |
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)) { |
1320 |
/* LWIP_DEBUGF(DHCP_DEBUG, ("dhcp_option_trailer: dhcp->options_out_len=%u, DHCP_OPTIONS_LEN=%u", dhcp->options_out_len, DHCP_OPTIONS_LEN)); */ |
/* LWIP_DEBUGF(DHCP_DEBUG,("dhcp_option_trailer:dhcp->options_out_len=%"U16_F", DHCP_OPTIONS_LEN=%"U16_F, dhcp->options_out_len, DHCP_OPTIONS_LEN)); */ |
1321 |
LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", 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); |
1322 |
/* add a fill/padding byte */ |
/* add a fill/padding byte */ |
1323 |
dhcp->msg_out->options[dhcp->options_out_len++] = 0; |
dhcp->msg_out->options[dhcp->options_out_len++] = 0; |
1344 |
u16_t offset = 0; |
u16_t offset = 0; |
1345 |
/* at least 1 byte to read and no end marker, then at least 3 bytes to read? */ |
/* at least 1 byte to read and no end marker, then at least 3 bytes to read? */ |
1346 |
while ((offset < dhcp->options_in_len) && (options[offset] != DHCP_OPTION_END)) { |
while ((offset < dhcp->options_in_len) && (options[offset] != DHCP_OPTION_END)) { |
1347 |
/* LWIP_DEBUGF(DHCP_DEBUG, ("msg_offset=%u, q->len=%u", msg_offset, q->len)); */ |
/* LWIP_DEBUGF(DHCP_DEBUG, ("msg_offset=%"U16_F", q->len=%"U16_F, msg_offset, q->len)); */ |
1348 |
/* are the sname and/or file field overloaded with options? */ |
/* are the sname and/or file field overloaded with options? */ |
1349 |
if (options[offset] == DHCP_OPTION_OVERLOAD) { |
if (options[offset] == DHCP_OPTION_OVERLOAD) { |
1350 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected\n")); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected\n")); |
1354 |
} |
} |
1355 |
/* requested option found */ |
/* requested option found */ |
1356 |
else if (options[offset] == option_type) { |
else if (options[offset] == option_type) { |
1357 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options\n", offset)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %"U16_F" in options\n", offset)); |
1358 |
return &options[offset]; |
return &options[offset]; |
1359 |
/* skip option */ |
/* skip option */ |
1360 |
} else { |
} else { |
1361 |
LWIP_DEBUGF(DHCP_DEBUG, ("skipping option %u in options\n", options[offset])); |
LWIP_DEBUGF(DHCP_DEBUG, ("skipping option %"U16_F" in options\n", options[offset])); |
1362 |
/* skip option type */ |
/* skip option type */ |
1363 |
offset++; |
offset++; |
1364 |
/* skip option length, and then length bytes */ |
/* skip option length, and then length bytes */ |
1387 |
/* at least 1 byte to read and no end marker */ |
/* at least 1 byte to read and no end marker */ |
1388 |
while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) { |
while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) { |
1389 |
if (options[offset] == option_type) { |
if (options[offset] == option_type) { |
1390 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u\n", offset)); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%"U16_F"\n", offset)); |
1391 |
return &options[offset]; |
return &options[offset]; |
1392 |
/* skip option */ |
/* skip option */ |
1393 |
} else { |
} else { |
1394 |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u\n", options[offset])); |
LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %"U16_F"\n", options[offset])); |
1395 |
/* skip option type */ |
/* skip option type */ |
1396 |
offset++; |
offset++; |
1397 |
offset += 1 + options[offset]; |
offset += 1 + options[offset]; |
1412 |
*/ |
*/ |
1413 |
static u8_t dhcp_get_option_byte(u8_t *ptr) |
static u8_t dhcp_get_option_byte(u8_t *ptr) |
1414 |
{ |
{ |
1415 |
LWIP_DEBUGF(DHCP_DEBUG, ("option byte value=%u\n", *ptr)); |
LWIP_DEBUGF(DHCP_DEBUG, ("option byte value=%"U16_F"\n", (u16_t)(*ptr))); |
1416 |
return *ptr; |
return *ptr; |
1417 |
} |
} |
1418 |
|
|
1429 |
u16_t value; |
u16_t value; |
1430 |
value = *ptr++ << 8; |
value = *ptr++ << 8; |
1431 |
value |= *ptr; |
value |= *ptr; |
1432 |
LWIP_DEBUGF(DHCP_DEBUG, ("option short value=%u\n", value)); |
LWIP_DEBUGF(DHCP_DEBUG, ("option short value=%"U16_F"\n", value)); |
1433 |
return value; |
return value; |
1434 |
} |
} |
1435 |
|
|
1448 |
value |= (u32_t)(*ptr++) << 16; |
value |= (u32_t)(*ptr++) << 16; |
1449 |
value |= (u32_t)(*ptr++) << 8; |
value |= (u32_t)(*ptr++) << 8; |
1450 |
value |= (u32_t)(*ptr++); |
value |= (u32_t)(*ptr++); |
1451 |
LWIP_DEBUGF(DHCP_DEBUG, ("option long value=%lu\n", value)); |
LWIP_DEBUGF(DHCP_DEBUG, ("option long value=%"U32_F"\n", value)); |
1452 |
return value; |
return value; |
1453 |
} |
} |
1454 |
|
|