84 #if LWIP_IPV4 && LWIP_DHCP 103 #ifndef DHCP_CREATE_RAND_XID 104 #define DHCP_CREATE_RAND_XID 1 112 #ifdef DHCP_GLOBAL_XID_HEADER 113 #include DHCP_GLOBAL_XID_HEADER 118 #define DHCP_MAX_MSG_LEN(netif) (netif->mtu) 119 #define DHCP_MAX_MSG_LEN_MIN_REQUIRED 576 121 #define DHCP_MIN_REPLY_LEN 44 123 #define REBOOT_TRIES 2 125 #if LWIP_DNS && LWIP_DHCP_MAX_DNS_SERVERS 126 #if DNS_MAX_SERVERS > LWIP_DHCP_MAX_DNS_SERVERS 127 #define LWIP_DHCP_PROVIDE_DNS_SERVERS LWIP_DHCP_MAX_DNS_SERVERS 129 #define LWIP_DHCP_PROVIDE_DNS_SERVERS DNS_MAX_SERVERS 132 #define LWIP_DHCP_PROVIDE_DNS_SERVERS 0 140 enum dhcp_option_idx {
141 DHCP_OPTION_IDX_OVERLOAD = 0,
142 DHCP_OPTION_IDX_MSG_TYPE,
143 DHCP_OPTION_IDX_SERVER_ID,
144 DHCP_OPTION_IDX_LEASE_TIME,
147 DHCP_OPTION_IDX_SUBNET_MASK,
148 DHCP_OPTION_IDX_ROUTER,
149 #if LWIP_DHCP_PROVIDE_DNS_SERVERS 150 DHCP_OPTION_IDX_DNS_SERVER,
151 DHCP_OPTION_IDX_DNS_SERVER_LAST = DHCP_OPTION_IDX_DNS_SERVER + LWIP_DHCP_PROVIDE_DNS_SERVERS - 1,
153 #if LWIP_DHCP_GET_NTP_SRV 154 DHCP_OPTION_IDX_NTP_SERVER,
162 u32_t dhcp_rx_options_val[DHCP_OPTION_IDX_MAX];
166 u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
168 static u8_t dhcp_discover_request_options[] = {
169 DHCP_OPTION_SUBNET_MASK,
171 DHCP_OPTION_BROADCAST
172 #if LWIP_DHCP_PROVIDE_DNS_SERVERS 173 , DHCP_OPTION_DNS_SERVER
175 #if LWIP_DHCP_GET_NTP_SRV 180 #ifdef DHCP_GLOBAL_XID 182 static u8_t xid_initialised;
185 #define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0) 186 #define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1) 187 #define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0) 188 #define dhcp_clear_all_options(dhcp) (memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given))) 189 #define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx]) 190 #define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val)) 192 static struct udp_pcb *dhcp_pcb;
193 static u8_t dhcp_pcb_refcount;
199 #if DHCP_DOES_ARP_CHECK 204 static void dhcp_set_state(
struct dhcp *dhcp, u8_t new_state);
207 static void dhcp_recv(
void *arg,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr, u16_t port);
210 static void dhcp_timeout(
struct netif *
netif);
211 static void dhcp_t1_timeout(
struct netif *
netif);
212 static void dhcp_t2_timeout(
struct netif *
netif);
216 static err_t dhcp_create_msg(
struct netif *
netif,
struct dhcp *dhcp, u8_t message_type);
218 static void dhcp_delete_msg(
struct dhcp *dhcp);
220 static void dhcp_option(
struct dhcp *dhcp, u8_t option_type, u8_t option_len);
222 static void dhcp_option_byte(
struct dhcp *dhcp, u8_t value);
223 static void dhcp_option_short(
struct dhcp *dhcp, u16_t value);
224 static void dhcp_option_long(
struct dhcp *dhcp, u32_t value);
225 #if LWIP_NETIF_HOSTNAME 226 static void dhcp_option_hostname(
struct dhcp *dhcp,
struct netif *
netif);
229 static void dhcp_option_trailer(
struct dhcp *dhcp);
233 dhcp_inc_pcb_refcount(
void)
235 if (dhcp_pcb_refcount == 0) {
236 LWIP_ASSERT(
"dhcp_inc_pcb_refcount(): memory leak", dhcp_pcb == NULL);
239 dhcp_pcb = udp_new();
241 if (dhcp_pcb == NULL) {
248 udp_bind(dhcp_pcb, IP4_ADDR_ANY, DHCP_CLIENT_PORT);
249 udp_connect(dhcp_pcb, IP4_ADDR_ANY, DHCP_SERVER_PORT);
250 udp_recv(dhcp_pcb, dhcp_recv, NULL);
260 dhcp_dec_pcb_refcount(
void)
262 LWIP_ASSERT(
"dhcp_pcb_refcount(): refcount error", (dhcp_pcb_refcount > 0));
265 if (dhcp_pcb_refcount == 0) {
266 udp_remove(dhcp_pcb);
286 struct dhcp *dhcp = netif_dhcp_data(netif);
289 (
void*)netif, netif->
name[0], netif->
name[1], (u16_t)netif->
num));
292 dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF);
294 netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
296 dhcp_discover(netif);
299 #if DHCP_DOES_ARP_CHECK 310 dhcp_check(
struct netif *netif)
312 struct dhcp *dhcp = netif_dhcp_data(netif);
316 (s16_t)netif->
name[1]));
317 dhcp_set_state(dhcp, DHCP_STATE_CHECKING);
320 result = etharp_query(netif, &dhcp->offered_ip_addr, NULL);
324 if (dhcp->tries < 255) {
328 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
339 dhcp_handle_offer(
struct netif *netif)
341 struct dhcp *dhcp = netif_dhcp_data(netif);
344 (
void*)netif, netif->
name[0], netif->
name[1], (u16_t)netif->
num));
346 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SERVER_ID)) {
347 ip_addr_set_ip4_u32(&dhcp->server_ip_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID)));
349 ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
351 ip4_addr_copy(dhcp->offered_ip_addr, dhcp->msg_in->yiaddr);
353 ip4_addr_get_u32(&dhcp->offered_ip_addr)));
358 (
"dhcp_handle_offer(netif=%p) did not get server ID!\n", (
void*)netif));
371 dhcp_select(
struct netif *netif)
373 struct dhcp *dhcp = netif_dhcp_data(netif);
379 dhcp_set_state(dhcp, DHCP_STATE_REQUESTING);
382 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
384 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
385 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
388 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
389 dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
391 dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
392 dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
394 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
395 for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
396 dhcp_option_byte(dhcp, dhcp_discover_request_options[i]);
399 #if LWIP_NETIF_HOSTNAME 400 dhcp_option_hostname(dhcp, netif);
403 dhcp_option_trailer(dhcp);
408 udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY);
409 dhcp_delete_msg(dhcp);
414 if (dhcp->tries < 255) {
417 msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000;
418 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
428 dhcp_coarse_tmr(
void)
433 while (netif != NULL) {
435 struct dhcp *dhcp = netif_dhcp_data(netif);
436 if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) {
438 if (dhcp->t0_timeout && (++dhcp->lease_used == dhcp->t0_timeout)) {
442 dhcp_discover(netif);
444 }
else if (dhcp->t2_rebind_time && (dhcp->t2_rebind_time-- == 1)) {
447 dhcp_t2_timeout(netif);
449 }
else if (dhcp->t1_renew_time && (dhcp->t1_renew_time-- == 1)) {
452 dhcp_t1_timeout(netif);
472 while (netif != NULL) {
473 struct dhcp *dhcp = netif_dhcp_data(netif);
477 if (dhcp->request_timeout > 1) {
478 dhcp->request_timeout--;
480 else if (dhcp->request_timeout == 1) {
481 dhcp->request_timeout--;
502 dhcp_timeout(
struct netif *netif)
504 struct dhcp *dhcp = netif_dhcp_data(netif);
508 if ((dhcp->state == DHCP_STATE_BACKING_OFF) || (dhcp->state == DHCP_STATE_SELECTING)) {
510 dhcp_discover(netif);
512 }
else if (dhcp->state == DHCP_STATE_REQUESTING) {
514 if (dhcp->tries <= 5) {
519 dhcp_discover(netif);
521 #if DHCP_DOES_ARP_CHECK 523 }
else if (dhcp->state == DHCP_STATE_CHECKING) {
525 if (dhcp->tries <= 1) {
534 }
else if (dhcp->state == DHCP_STATE_REBOOTING) {
535 if (dhcp->tries < REBOOT_TRIES) {
538 dhcp_discover(netif);
549 dhcp_t1_timeout(
struct netif *netif)
551 struct dhcp *dhcp = netif_dhcp_data(netif);
554 if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) ||
555 (dhcp->state == DHCP_STATE_RENEWING)) {
559 (
"dhcp_t1_timeout(): must renew\n"));
564 if (((dhcp->t2_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS))
566 dhcp->t1_renew_time = ((dhcp->t2_timeout - dhcp->lease_used) / 2);
577 dhcp_t2_timeout(
struct netif *netif)
579 struct dhcp *dhcp = netif_dhcp_data(netif);
582 if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) ||
583 (dhcp->state == DHCP_STATE_RENEWING) || (dhcp->state == DHCP_STATE_REBINDING)) {
586 (
"dhcp_t2_timeout(): must rebind\n"));
591 if (((dhcp->t0_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS))
593 dhcp->t2_rebind_time = ((dhcp->t0_timeout - dhcp->lease_used) / 2);
604 dhcp_handle_ack(
struct netif *netif)
606 struct dhcp *dhcp = netif_dhcp_data(netif);
608 #if LWIP_DHCP_PROVIDE_DNS_SERVERS || LWIP_DHCP_GET_NTP_SRV 611 #if LWIP_DHCP_GET_NTP_SRV 616 ip4_addr_set_zero(&dhcp->offered_sn_mask);
617 ip4_addr_set_zero(&dhcp->offered_gw_addr);
618 #if LWIP_DHCP_BOOTP_FILE 619 ip4_addr_set_zero(&dhcp->offered_si_addr);
623 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_LEASE_TIME)) {
625 dhcp->offered_t0_lease = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_LEASE_TIME);
628 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_T1)) {
630 dhcp->offered_t1_renew = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_T1);
633 dhcp->offered_t1_renew = dhcp->offered_t0_lease / 2;
637 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_T2)) {
639 dhcp->offered_t2_rebind = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_T2);
642 dhcp->offered_t2_rebind = (dhcp->offered_t0_lease * 7U) / 8U;
646 ip4_addr_copy(dhcp->offered_ip_addr, dhcp->msg_in->yiaddr);
648 #if LWIP_DHCP_BOOTP_FILE 651 ip4_addr_copy(dhcp->offered_si_addr, dhcp->msg_in->siaddr);
655 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)) {
657 ip4_addr_set_u32(&dhcp->offered_sn_mask, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)));
658 dhcp->subnet_mask_given = 1;
660 dhcp->subnet_mask_given = 0;
664 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_ROUTER)) {
665 ip4_addr_set_u32(&dhcp->offered_gw_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER)));
668 #if LWIP_DHCP_GET_NTP_SRV 671 ip4_addr_set_u32(&ntp_server_addrs[n], lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n)));
673 dhcp_set_ntp_servers(n, ntp_server_addrs);
676 #if LWIP_DHCP_PROVIDE_DNS_SERVERS 678 for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) {
680 ip_addr_set_ip4_u32(&dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
681 dns_setserver(n, &dns_addr);
695 dhcp_set_struct(
struct netif *netif,
struct dhcp *dhcp)
697 LWIP_ASSERT(
"netif != NULL", netif != NULL);
698 LWIP_ASSERT(
"dhcp != NULL", dhcp != NULL);
699 LWIP_ASSERT(
"netif already has a struct dhcp set", netif_dhcp_data(netif) == NULL);
702 memset(dhcp, 0,
sizeof(
struct dhcp));
704 netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp);
716 void dhcp_cleanup(
struct netif *netif)
718 LWIP_ASSERT(
"netif != NULL", netif != NULL);
720 if (netif_dhcp_data(netif) != NULL) {
722 netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, NULL);
740 dhcp_start(
struct netif *netif)
745 LWIP_ERROR(
"netif != NULL", (netif != NULL),
return ERR_ARG;);
747 dhcp = netif_dhcp_data(netif);
751 if (netif->
mtu < DHCP_MAX_MSG_LEN_MIN_REQUIRED) {
759 dhcp = (
struct dhcp *)
mem_malloc(
sizeof(
struct dhcp));
766 netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp);
771 LWIP_ASSERT(
"pbuf p_out wasn't freed", dhcp->p_out == NULL);
772 LWIP_ASSERT(
"reply wasn't freed", dhcp->msg_in == NULL );
774 if (dhcp->pcb_allocated != 0) {
775 dhcp_dec_pcb_refcount();
781 memset(dhcp, 0,
sizeof(
struct dhcp));
786 if (dhcp_inc_pcb_refcount() !=
ERR_OK) {
789 dhcp->pcb_allocated = 1;
791 #if LWIP_DHCP_CHECK_LINK_UP 794 dhcp_set_state(dhcp, DHCP_STATE_INIT);
801 result = dhcp_discover(netif);
821 dhcp_inform(
struct netif *netif)
826 LWIP_ERROR(
"netif != NULL", (netif != NULL),
return;);
828 if (dhcp_inc_pcb_refcount() !=
ERR_OK) {
832 memset(&dhcp, 0,
sizeof(
struct dhcp));
833 dhcp_set_state(&dhcp, DHCP_STATE_INFORMING);
836 result = dhcp_create_msg(netif, &dhcp, DHCP_INFORM);
838 dhcp_option(&dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
839 dhcp_option_short(&dhcp, DHCP_MAX_MSG_LEN(netif));
841 dhcp_option_trailer(&dhcp);
847 udp_sendto_if(dhcp_pcb, dhcp.p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
849 dhcp_delete_msg(&dhcp);
854 dhcp_dec_pcb_refcount();
863 dhcp_network_changed(
struct netif *netif)
865 struct dhcp *dhcp = netif_dhcp_data(netif);
869 switch (dhcp->state) {
870 case DHCP_STATE_REBINDING:
871 case DHCP_STATE_RENEWING:
872 case DHCP_STATE_BOUND:
873 case DHCP_STATE_REBOOTING:
884 #if LWIP_DHCP_AUTOIP_COOP 885 if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
887 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF;
892 dhcp_discover(netif);
897 #if DHCP_DOES_ARP_CHECK 906 dhcp_arp_reply(
struct netif *netif,
const ip4_addr_t *addr)
910 LWIP_ERROR(
"netif != NULL", (netif != NULL),
return;);
911 dhcp = netif_dhcp_data(netif);
914 if ((dhcp != NULL) && (dhcp->state == DHCP_STATE_CHECKING)) {
916 ip4_addr_get_u32(addr)));
919 if (ip4_addr_cmp(addr, &dhcp->offered_ip_addr)) {
922 (
"dhcp_arp_reply(): arp reply matched with offered address, declining\n"));
938 dhcp_decline(
struct netif *netif)
940 struct dhcp *dhcp = netif_dhcp_data(netif);
944 dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF);
946 result = dhcp_create_msg(netif, dhcp, DHCP_DECLINE);
948 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
949 dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
951 dhcp_option_trailer(dhcp);
956 udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY);
957 dhcp_delete_msg(dhcp);
961 (
"dhcp_decline: could not allocate DHCP request\n"));
963 if (dhcp->tries < 255) {
967 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
980 dhcp_discover(
struct netif *netif)
982 struct dhcp *dhcp = netif_dhcp_data(netif);
987 ip4_addr_set_any(&dhcp->offered_ip_addr);
988 dhcp_set_state(dhcp, DHCP_STATE_SELECTING);
990 result = dhcp_create_msg(netif, dhcp, DHCP_DISCOVER);
994 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
995 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
997 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
998 for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
999 dhcp_option_byte(dhcp, dhcp_discover_request_options[i]);
1001 dhcp_option_trailer(dhcp);
1007 udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY);
1009 dhcp_delete_msg(dhcp);
1014 if (dhcp->tries < 255) {
1017 #if LWIP_DHCP_AUTOIP_COOP 1019 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_ON;
1020 autoip_start(netif);
1023 msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000;
1024 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
1036 dhcp_bind(
struct netif *netif)
1040 ip4_addr_t sn_mask, gw_addr;
1041 LWIP_ERROR(
"dhcp_bind: netif != NULL", (netif != NULL),
return;);
1042 dhcp = netif_dhcp_data(netif);
1043 LWIP_ERROR(
"dhcp_bind: dhcp != NULL", (dhcp != NULL),
return;);
1047 dhcp->lease_used = 0;
1049 if (dhcp->offered_t0_lease != 0xffffffffUL) {
1052 timeout = (dhcp->offered_t0_lease + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
1053 if (timeout > 0xffff) {
1056 dhcp->t0_timeout = (u16_t)timeout;
1057 if (dhcp->t0_timeout == 0) {
1058 dhcp->t0_timeout = 1;
1064 if (dhcp->offered_t1_renew != 0xffffffffUL) {
1067 timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
1068 if (timeout > 0xffff) {
1071 dhcp->t1_timeout = (u16_t)timeout;
1072 if (dhcp->t1_timeout == 0) {
1073 dhcp->t1_timeout = 1;
1076 dhcp->t1_renew_time = dhcp->t1_timeout;
1079 if (dhcp->offered_t2_rebind != 0xffffffffUL) {
1081 timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
1082 if (timeout > 0xffff) {
1085 dhcp->t2_timeout = (u16_t)timeout;
1086 if (dhcp->t2_timeout == 0) {
1087 dhcp->t2_timeout = 1;
1090 dhcp->t2_rebind_time = dhcp->t2_timeout;
1094 if ((dhcp->t1_timeout >= dhcp->t2_timeout) && (dhcp->t2_timeout > 0)) {
1095 dhcp->t1_timeout = 0;
1098 if (dhcp->subnet_mask_given) {
1100 ip4_addr_copy(sn_mask, dhcp->offered_sn_mask);
1103 u8_t first_octet = ip4_addr1(&dhcp->offered_ip_addr);
1104 if (first_octet <= 127) {
1105 ip4_addr_set_u32(&sn_mask, PP_HTONL(0xff000000UL));
1106 }
else if (first_octet >= 192) {
1107 ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffffff00UL));
1109 ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffff0000UL));
1113 ip4_addr_copy(gw_addr, dhcp->offered_gw_addr);
1115 if (ip4_addr_isany_val(gw_addr)) {
1117 ip4_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
1119 ip4_addr_set_u32(&gw_addr, ip4_addr_get_u32(&gw_addr) | PP_HTONL(0x00000001UL));
1122 #if LWIP_DHCP_AUTOIP_COOP 1123 if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
1125 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF;
1130 ip4_addr_get_u32(&dhcp->offered_ip_addr), ip4_addr_get_u32(&sn_mask), ip4_addr_get_u32(&gw_addr)));
1133 dhcp_set_state(dhcp, DHCP_STATE_BOUND);
1135 netif_set_addr(netif, &dhcp->offered_ip_addr, &sn_mask, &gw_addr);
1146 dhcp_renew(
struct netif *netif)
1148 struct dhcp *dhcp = netif_dhcp_data(netif);
1153 dhcp_set_state(dhcp, DHCP_STATE_RENEWING);
1156 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
1158 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
1159 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
1161 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
1162 for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
1163 dhcp_option_byte(dhcp, dhcp_discover_request_options[i]);
1166 #if LWIP_NETIF_HOSTNAME 1167 dhcp_option_hostname(dhcp, netif);
1171 dhcp_option_trailer(dhcp);
1175 udp_sendto_if(dhcp_pcb, dhcp->p_out, &dhcp->server_ip_addr, DHCP_SERVER_PORT, netif);
1176 dhcp_delete_msg(dhcp);
1182 if (dhcp->tries < 255) {
1186 msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000;
1187 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
1198 dhcp_rebind(
struct netif *netif)
1200 struct dhcp *dhcp = netif_dhcp_data(netif);
1205 dhcp_set_state(dhcp, DHCP_STATE_REBINDING);
1208 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
1210 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
1211 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
1213 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
1214 for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
1215 dhcp_option_byte(dhcp, dhcp_discover_request_options[i]);
1218 #if LWIP_NETIF_HOSTNAME 1219 dhcp_option_hostname(dhcp, netif);
1222 dhcp_option_trailer(dhcp);
1227 udp_sendto_if(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
1228 dhcp_delete_msg(dhcp);
1233 if (dhcp->tries < 255) {
1236 msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
1237 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
1248 dhcp_reboot(
struct netif *netif)
1250 struct dhcp *dhcp = netif_dhcp_data(netif);
1255 dhcp_set_state(dhcp, DHCP_STATE_REBOOTING);
1258 result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST);
1260 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
1261 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN_MIN_REQUIRED);
1263 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
1264 dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
1266 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
1267 for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
1268 dhcp_option_byte(dhcp, dhcp_discover_request_options[i]);
1271 dhcp_option_trailer(dhcp);
1276 udp_sendto_if(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
1277 dhcp_delete_msg(dhcp);
1282 if (dhcp->tries < 255) {
1285 msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
1286 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
1299 dhcp_release(
struct netif *netif)
1301 struct dhcp *dhcp = netif_dhcp_data(netif);
1303 ip_addr_t server_ip_addr;
1304 u8_t is_dhcp_supplied_address;
1310 ip_addr_copy(server_ip_addr, dhcp->server_ip_addr);
1312 is_dhcp_supplied_address = dhcp_supplied_address(netif);
1315 dhcp_set_state(dhcp, DHCP_STATE_OFF);
1317 ip_addr_set_zero_ip4(&dhcp->server_ip_addr);
1318 ip4_addr_set_zero(&dhcp->offered_ip_addr);
1319 ip4_addr_set_zero(&dhcp->offered_sn_mask);
1320 ip4_addr_set_zero(&dhcp->offered_gw_addr);
1321 #if LWIP_DHCP_BOOTP_FILE 1322 ip4_addr_set_zero(&dhcp->offered_si_addr);
1324 dhcp->offered_t0_lease = dhcp->offered_t1_renew = dhcp->offered_t2_rebind = 0;
1325 dhcp->t1_renew_time = dhcp->t2_rebind_time = dhcp->lease_used = dhcp->t0_timeout = 0;
1327 if (!is_dhcp_supplied_address) {
1333 result = dhcp_create_msg(netif, dhcp, DHCP_RELEASE);
1335 dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
1336 dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr))));
1338 dhcp_option_trailer(dhcp);
1342 udp_sendto_if(dhcp_pcb, dhcp->p_out, &server_ip_addr, DHCP_SERVER_PORT, netif);
1343 dhcp_delete_msg(dhcp);
1350 netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
1362 dhcp_stop(
struct netif *netif)
1365 LWIP_ERROR(
"dhcp_stop: netif != NULL", (netif != NULL),
return;);
1366 dhcp = netif_dhcp_data(netif);
1371 #if LWIP_DHCP_AUTOIP_COOP 1372 if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
1374 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF;
1378 LWIP_ASSERT(
"reply wasn't freed", dhcp->msg_in == NULL);
1379 dhcp_set_state(dhcp, DHCP_STATE_OFF);
1381 if (dhcp->pcb_allocated != 0) {
1382 dhcp_dec_pcb_refcount();
1383 dhcp->pcb_allocated = 0;
1394 dhcp_set_state(
struct dhcp *dhcp, u8_t new_state)
1396 if (new_state != dhcp->state) {
1397 dhcp->state = new_state;
1399 dhcp->request_timeout = 0;
1409 dhcp_option(
struct dhcp *dhcp, u8_t option_type, u8_t option_len)
1411 LWIP_ASSERT(
"dhcp_option: dhcp->options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN", dhcp->options_out_len + 2U + option_len <=
DHCP_OPTIONS_LEN);
1412 dhcp->msg_out->options[dhcp->options_out_len++] = option_type;
1413 dhcp->msg_out->options[dhcp->options_out_len++] = option_len;
1420 dhcp_option_byte(
struct dhcp *dhcp, u8_t value)
1422 LWIP_ASSERT(
"dhcp_option_byte: dhcp->options_out_len < DHCP_OPTIONS_LEN", dhcp->options_out_len <
DHCP_OPTIONS_LEN);
1423 dhcp->msg_out->options[dhcp->options_out_len++] = value;
1427 dhcp_option_short(
struct dhcp *dhcp, u16_t value)
1429 LWIP_ASSERT(
"dhcp_option_short: dhcp->options_out_len + 2 <= DHCP_OPTIONS_LEN", dhcp->options_out_len + 2U <=
DHCP_OPTIONS_LEN);
1430 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0xff00U) >> 8);
1431 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t) (value & 0x00ffU);
1435 dhcp_option_long(
struct dhcp *dhcp, u32_t value)
1437 LWIP_ASSERT(
"dhcp_option_long: dhcp->options_out_len + 4 <= DHCP_OPTIONS_LEN", dhcp->options_out_len + 4U <=
DHCP_OPTIONS_LEN);
1438 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0xff000000UL) >> 24);
1439 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x00ff0000UL) >> 16);
1440 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x0000ff00UL) >> 8);
1441 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x000000ffUL));
1444 #if LWIP_NETIF_HOSTNAME 1446 dhcp_option_hostname(
struct dhcp *dhcp,
struct netif *netif)
1448 if (netif->hostname != NULL) {
1449 size_t namelen = strlen(netif->hostname);
1452 const char *p = netif->hostname;
1456 LWIP_ASSERT(
"DHCP: hostname is too long!", namelen <= available);
1457 len = LWIP_MIN(namelen, available);
1458 LWIP_ASSERT(
"DHCP: hostname is too long!", len <= 0xFF);
1459 dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, (u8_t)len);
1461 dhcp_option_byte(dhcp, *p++);
1479 dhcp_parse_reply(
struct dhcp *dhcp,
struct pbuf *p)
1485 u16_t options_idx_max;
1487 int parse_file_as_options = 0;
1488 int parse_sname_as_options = 0;
1491 dhcp_clear_all_options(dhcp);
1493 if (p->
len < DHCP_SNAME_OFS) {
1499 dhcp->boot_file_name[0] = 0;
1505 options_idx = DHCP_OPTIONS_OFS;
1510 while ((q != NULL) && (options_idx >= q->
len)) {
1511 options_idx -= q->
len;
1512 options_idx_max -= q->
len;
1518 offset = options_idx;
1519 offset_max = options_idx_max;
1522 while ((q != NULL) && (options[offset] != DHCP_OPTION_END) && (offset < offset_max)) {
1523 u8_t op = options[offset];
1525 u8_t decode_len = 0;
1526 int decode_idx = -1;
1527 u16_t val_offset = offset + 2;
1529 if ((offset + 1) < q->
len) {
1530 len = options[offset + 1];
1538 case(DHCP_OPTION_PAD):
1540 decode_len = len = 0;
1544 case(DHCP_OPTION_SUBNET_MASK):
1545 LWIP_ERROR(
"len == 4", len == 4,
return ERR_VAL;);
1546 decode_idx = DHCP_OPTION_IDX_SUBNET_MASK;
1548 case(DHCP_OPTION_ROUTER):
1550 LWIP_ERROR(
"len >= decode_len", len >= decode_len,
return ERR_VAL;);
1551 decode_idx = DHCP_OPTION_IDX_ROUTER;
1553 #if LWIP_DHCP_PROVIDE_DNS_SERVERS 1554 case(DHCP_OPTION_DNS_SERVER):
1556 LWIP_ERROR(
"len %% 4 == 0", len % 4 == 0,
return ERR_VAL;);
1559 LWIP_ERROR(
"len >= decode_len", len >= decode_len,
return ERR_VAL;);
1560 decode_idx = DHCP_OPTION_IDX_DNS_SERVER;
1563 case(DHCP_OPTION_LEASE_TIME):
1564 LWIP_ERROR(
"len == 4", len == 4,
return ERR_VAL;);
1565 decode_idx = DHCP_OPTION_IDX_LEASE_TIME;
1567 #if LWIP_DHCP_GET_NTP_SRV 1568 case(DHCP_OPTION_NTP):
1570 LWIP_ERROR(
"len %% 4 == 0", len % 4 == 0,
return ERR_VAL;);
1573 LWIP_ERROR(
"len >= decode_len", len >= decode_len,
return ERR_VAL;);
1574 decode_idx = DHCP_OPTION_IDX_NTP_SERVER;
1577 case(DHCP_OPTION_OVERLOAD):
1578 LWIP_ERROR(
"len == 1", len == 1,
return ERR_VAL;);
1580 LWIP_ERROR(
"overload in file/sname", options_idx == DHCP_OPTIONS_OFS,
return ERR_VAL;);
1581 decode_idx = DHCP_OPTION_IDX_OVERLOAD;
1583 case(DHCP_OPTION_MESSAGE_TYPE):
1584 LWIP_ERROR(
"len == 1", len == 1,
return ERR_VAL;);
1585 decode_idx = DHCP_OPTION_IDX_MSG_TYPE;
1587 case(DHCP_OPTION_SERVER_ID):
1588 LWIP_ERROR(
"len == 4", len == 4,
return ERR_VAL;);
1589 decode_idx = DHCP_OPTION_IDX_SERVER_ID;
1591 case(DHCP_OPTION_T1):
1592 LWIP_ERROR(
"len == 4", len == 4,
return ERR_VAL;);
1593 decode_idx = DHCP_OPTION_IDX_T1;
1595 case(DHCP_OPTION_T2):
1596 LWIP_ERROR(
"len == 4", len == 4,
return ERR_VAL;);
1597 decode_idx = DHCP_OPTION_IDX_T2;
1605 if (decode_len > 0) {
1609 LWIP_ASSERT(
"check decode_idx", decode_idx >= 0 && decode_idx < DHCP_OPTION_IDX_MAX);
1610 if (!dhcp_option_given(dhcp, decode_idx)) {
1611 copy_len = LWIP_MIN(decode_len, 4);
1615 if (decode_len > 4) {
1617 LWIP_ERROR(
"decode_len %% 4 == 0", decode_len % 4 == 0,
return ERR_VAL;);
1618 dhcp_got_option(dhcp, decode_idx);
1619 dhcp_set_option_value(dhcp, decode_idx, lwip_htonl(value));
1624 }
else if (decode_len == 4) {
1625 value = lwip_ntohl(value);
1627 LWIP_ERROR(
"invalid decode_len", decode_len == 1,
return ERR_VAL;);
1628 value = ((u8_t*)&value)[0];
1630 dhcp_got_option(dhcp, decode_idx);
1631 dhcp_set_option_value(dhcp, decode_idx, value);
1634 if (offset >= q->
len) {
1636 offset_max -= q->
len;
1637 if ((offset < offset_max) && offset_max) {
1639 LWIP_ASSERT(
"next pbuf was null", q);
1648 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_OVERLOAD)) {
1649 u32_t overload = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_OVERLOAD);
1650 dhcp_clear_option(dhcp, DHCP_OPTION_IDX_OVERLOAD);
1651 if (overload == DHCP_OVERLOAD_FILE) {
1652 parse_file_as_options = 1;
1654 }
else if (overload == DHCP_OVERLOAD_SNAME) {
1655 parse_sname_as_options = 1;
1657 }
else if (overload == DHCP_OVERLOAD_SNAME_FILE) {
1658 parse_sname_as_options = 1;
1659 parse_file_as_options = 1;
1664 #if LWIP_DHCP_BOOTP_FILE 1665 if (!parse_file_as_options) {
1667 if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE) &&
1668 (dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_MSG_TYPE) == DHCP_ACK))
1670 if (
pbuf_copy_partial(p, dhcp->boot_file_name, DHCP_FILE_LEN-1, DHCP_FILE_OFS) != (DHCP_FILE_LEN-1)) {
1674 dhcp->boot_file_name[DHCP_FILE_LEN-1] = 0;
1678 if (parse_file_as_options) {
1680 parse_file_as_options = 0;
1681 options_idx = DHCP_FILE_OFS;
1682 options_idx_max = DHCP_FILE_OFS + DHCP_FILE_LEN;
1684 }
else if (parse_sname_as_options) {
1685 parse_sname_as_options = 0;
1686 options_idx = DHCP_SNAME_OFS;
1687 options_idx_max = DHCP_SNAME_OFS + DHCP_SNAME_LEN;
1697 dhcp_recv(
void *arg,
struct udp_pcb *pcb,
struct pbuf *p,
const ip_addr_t *addr, u16_t port)
1700 struct dhcp *dhcp = netif_dhcp_data(netif);
1708 if ((dhcp == NULL) || (dhcp->pcb_allocated == 0)) {
1709 goto free_pbuf_and_return;
1712 LWIP_ASSERT(
"invalid server address type", IP_IS_V4(addr));
1715 ip4_addr1_16(ip_2_ip4(addr)), ip4_addr2_16(ip_2_ip4(addr)), ip4_addr3_16(ip_2_ip4(addr)), ip4_addr4_16(ip_2_ip4(addr)), port));
1723 LWIP_ASSERT(
"reply wasn't freed", dhcp->msg_in == NULL);
1725 if (p->
len < DHCP_MIN_REPLY_LEN) {
1727 goto free_pbuf_and_return;
1730 if (reply_msg->op != DHCP_BOOTREPLY) {
1732 goto free_pbuf_and_return;
1736 if (netif->
hwaddr[i] != reply_msg->chaddr[i]) {
1738 (
"netif->hwaddr[%"U16_F
"]==%02"X16_F
" != reply_msg->chaddr[%"U16_F
"]==%02"X16_F
"\n",
1739 (u16_t)i, (u16_t)netif->
hwaddr[i], (u16_t)i, (u16_t)reply_msg->chaddr[i]));
1740 goto free_pbuf_and_return;
1744 if (lwip_ntohl(reply_msg->xid) != dhcp->xid) {
1746 (
"transaction id mismatch reply_msg->xid(%"X32_F
")!=dhcp->xid(%"X32_F
")\n",lwip_ntohl(reply_msg->xid),dhcp->xid));
1747 goto free_pbuf_and_return;
1750 if (dhcp_parse_reply(dhcp, p) !=
ERR_OK) {
1752 (
"problem unfolding DHCP message - too short on memory?\n"));
1753 goto free_pbuf_and_return;
1758 if (!dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE)) {
1760 goto free_pbuf_and_return;
1764 msg_type = (u8_t)dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_MSG_TYPE);
1766 if (msg_type == DHCP_ACK) {
1769 if (dhcp->state == DHCP_STATE_REQUESTING) {
1770 dhcp_handle_ack(netif);
1771 #if DHCP_DOES_ARP_CHECK 1785 else if ((dhcp->state == DHCP_STATE_REBOOTING) || (dhcp->state == DHCP_STATE_REBINDING) ||
1786 (dhcp->state == DHCP_STATE_RENEWING)) {
1787 dhcp_handle_ack(netif);
1792 else if ((msg_type == DHCP_NAK) &&
1793 ((dhcp->state == DHCP_STATE_REBOOTING) || (dhcp->state == DHCP_STATE_REQUESTING) ||
1794 (dhcp->state == DHCP_STATE_REBINDING) || (dhcp->state == DHCP_STATE_RENEWING ))) {
1796 dhcp_handle_nak(netif);
1799 else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_STATE_SELECTING)) {
1801 dhcp->request_timeout = 0;
1803 dhcp_handle_offer(netif);
1806 free_pbuf_and_return:
1808 dhcp->msg_in = NULL;
1821 dhcp_create_msg(
struct netif *netif,
struct dhcp *dhcp, u8_t message_type)
1824 #ifndef DHCP_GLOBAL_XID 1829 #if DHCP_CREATE_RAND_XID && defined(LWIP_RAND) 1832 static u32_t xid = 0xABCD0000;
1835 if (!xid_initialised) {
1836 xid = DHCP_GLOBAL_XID;
1837 xid_initialised = !xid_initialised;
1840 LWIP_ERROR(
"dhcp_create_msg: netif != NULL", (netif != NULL),
return ERR_ARG;);
1841 LWIP_ERROR(
"dhcp_create_msg: dhcp != NULL", (dhcp != NULL),
return ERR_VAL;);
1842 LWIP_ASSERT(
"dhcp_create_msg: dhcp->p_out == NULL", dhcp->p_out == NULL);
1843 LWIP_ASSERT(
"dhcp_create_msg: dhcp->msg_out == NULL", dhcp->msg_out == NULL);
1845 if (dhcp->p_out == NULL) {
1847 (
"dhcp_create_msg(): could not allocate pbuf\n"));
1850 LWIP_ASSERT(
"dhcp_create_msg: check that first pbuf can hold struct dhcp_msg",
1851 (dhcp->p_out->len >=
sizeof(
struct dhcp_msg)));
1854 if (message_type != DHCP_REQUEST) {
1856 if (dhcp->tries == 0) {
1857 #if DHCP_CREATE_RAND_XID && defined(LWIP_RAND) 1866 (
"transaction id xid(%"X32_F
")\n", xid));
1868 dhcp->msg_out = (
struct dhcp_msg *)dhcp->p_out->payload;
1870 dhcp->msg_out->op = DHCP_BOOTREQUEST;
1874 dhcp->msg_out->hops = 0;
1875 dhcp->msg_out->xid = lwip_htonl(dhcp->xid);
1876 dhcp->msg_out->secs = 0;
1879 dhcp->msg_out->flags = 0;
1880 ip4_addr_set_zero(&dhcp->msg_out->ciaddr);
1882 if ((message_type == DHCP_INFORM) || (message_type == DHCP_DECLINE) || (message_type == DHCP_RELEASE) ||
1883 ((message_type == DHCP_REQUEST) &&
1884 ((dhcp->state== DHCP_STATE_RENEWING) || dhcp->state== DHCP_STATE_REBINDING))) {
1885 ip4_addr_copy(dhcp->msg_out->ciaddr, *netif_ip4_addr(netif));
1887 ip4_addr_set_zero(&dhcp->msg_out->yiaddr);
1888 ip4_addr_set_zero(&dhcp->msg_out->siaddr);
1889 ip4_addr_set_zero(&dhcp->msg_out->giaddr);
1890 for (i = 0; i < DHCP_CHADDR_LEN; i++) {
1894 for (i = 0; i < DHCP_SNAME_LEN; i++) {
1895 dhcp->msg_out->sname[i] = 0;
1897 for (i = 0; i < DHCP_FILE_LEN; i++) {
1898 dhcp->msg_out->file[i] = 0;
1900 dhcp->msg_out->cookie = PP_HTONL(DHCP_MAGIC_COOKIE);
1901 dhcp->options_out_len = 0;
1904 dhcp->msg_out->options[i] = (u8_t)i;
1907 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
1908 dhcp_option_byte(dhcp, message_type);
1918 dhcp_delete_msg(
struct dhcp *dhcp)
1920 LWIP_ERROR(
"dhcp_delete_msg: dhcp != NULL", (dhcp != NULL),
return;);
1921 LWIP_ASSERT(
"dhcp_delete_msg: dhcp->p_out != NULL", dhcp->p_out != NULL);
1922 LWIP_ASSERT(
"dhcp_delete_msg: dhcp->msg_out != NULL", dhcp->msg_out != NULL);
1923 if (dhcp->p_out != NULL) {
1927 dhcp->msg_out = NULL;
1939 dhcp_option_trailer(
struct dhcp *dhcp)
1941 LWIP_ERROR(
"dhcp_option_trailer: dhcp != NULL", (dhcp != NULL),
return;);
1942 LWIP_ASSERT(
"dhcp_option_trailer: dhcp->msg_out != NULL\n", dhcp->msg_out != NULL);
1943 LWIP_ASSERT(
"dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_len <
DHCP_OPTIONS_LEN);
1944 dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END;
1946 while (((dhcp->options_out_len < DHCP_MIN_OPTIONS_LEN) || (dhcp->options_out_len & 3)) &&
1949 dhcp->msg_out->options[dhcp->options_out_len++] = 0;
1960 dhcp_supplied_address(
const struct netif *netif)
1962 if ((netif != NULL) && (netif_dhcp_data(netif) != NULL)) {
1963 struct dhcp* dhcp = netif_dhcp_data(netif);
1964 return (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING);
#define LWIP_DHCP_AUTOIP_COOP_TRIES
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
#define LWIP_DHCP_BOOTP_FILE
void pbuf_realloc(struct pbuf *p, u16_t new_len)
struct netif * netif_list
void mem_free(void *rmem)
#define ip_current_input_netif()
#define LWIP_DHCP_MAX_NTP_SERVERS
#define netif_is_link_up(netif)
#define LWIP_DBG_LEVEL_SERIOUS
#define NETIF_MAX_HWADDR_LEN
#define LWIP_DEBUGF(debug, message)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
#define netif_is_up(netif)
#define LWIP_DBG_LEVEL_WARNING
#define NETIF_FLAG_ETHARP
#define LWIP_UNUSED_ARG(x)
u8_t pbuf_free(struct pbuf *p)
void * mem_malloc(mem_size_t size)
#define ip_set_option(pcb, opt)