Lines Matching refs:dhcp

123 static void dhcp_set_state(struct dhcp *dhcp, u8_t new_state);
127 static err_t dhcp_unfold_reply(struct dhcp *dhcp, struct pbuf *p);
128 static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type);
134 static void dhcp_free_reply(struct dhcp *dhcp);
147 static void dhcp_option(struct dhcp *dhcp, u8_t option_type, u8_t option_len);
149 static void dhcp_option_byte(struct dhcp *dhcp, u8_t value);
150 static void dhcp_option_short(struct dhcp *dhcp, u16_t value);
151 static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
153 static void dhcp_option_trailer(struct dhcp *dhcp);
170 struct dhcp *dhcp = netif->dhcp; in dhcp_handle_nak() local
180 dhcp_set_state(dhcp, DHCP_BACKING_OFF); in dhcp_handle_nak()
198 struct dhcp *dhcp = netif->dhcp; in dhcp_check() local
203 dhcp_set_state(dhcp, DHCP_CHECKING); in dhcp_check()
206 result = etharp_query(netif, &dhcp->offered_ip_addr, NULL); in dhcp_check()
210 dhcp->tries++; in dhcp_check()
212 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_check()
225 struct dhcp *dhcp = netif->dhcp; in dhcp_handle_offer() local
227 u8_t *option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_SERVER_ID); in dhcp_handle_offer()
231 dhcp->server_ip_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2])); in dhcp_handle_offer()
232 …LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n", dhcp->serv… in dhcp_handle_offer()
234 ip_addr_set(&dhcp->offered_ip_addr, (struct ip_addr *)&dhcp->msg_in->yiaddr); in dhcp_handle_offer()
235 …LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08"X32_F"\n", dhcp->o… in dhcp_handle_offer()
252 struct dhcp *dhcp = netif->dhcp; in dhcp_select() local
260 dhcp_set_state(dhcp, DHCP_REQUESTING); in dhcp_select()
265 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_select()
266 dhcp_option_byte(dhcp, DHCP_REQUEST); in dhcp_select()
268 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); in dhcp_select()
269 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); in dhcp_select()
272 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); in dhcp_select()
273 dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr)); in dhcp_select()
275 dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); in dhcp_select()
276 dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr)); in dhcp_select()
278 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/); in dhcp_select()
279 dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); in dhcp_select()
280 dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); in dhcp_select()
281 dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); in dhcp_select()
282 dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); in dhcp_select()
287 dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); in dhcp_select()
289 dhcp_option_byte(dhcp, *p++); in dhcp_select()
294 dhcp_option_trailer(dhcp); in dhcp_select()
296 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_select()
299 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); in dhcp_select()
305 dhcp->tries++; in dhcp_select()
306 msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000; in dhcp_select()
307 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_select()
324 if (netif->dhcp != NULL) { in dhcp_coarse_tmr()
326 if (netif->dhcp->t2_timeout-- == 1) { in dhcp_coarse_tmr()
331 } else if (netif->dhcp->t1_timeout-- == 1) { in dhcp_coarse_tmr()
356 if (netif->dhcp != NULL) { in dhcp_fine_tmr()
358 if (netif->dhcp->request_timeout > 1) { in dhcp_fine_tmr()
359 netif->dhcp->request_timeout--; in dhcp_fine_tmr()
361 else if (netif->dhcp->request_timeout == 1) { in dhcp_fine_tmr()
362 netif->dhcp->request_timeout--; in dhcp_fine_tmr()
385 struct dhcp *dhcp = netif->dhcp; in dhcp_timeout() local
388 if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) { in dhcp_timeout()
392 } else if (dhcp->state == DHCP_REQUESTING) { in dhcp_timeout()
394 if (dhcp->tries <= 5) { in dhcp_timeout()
403 } else if (dhcp->state == DHCP_CHECKING) { in dhcp_timeout()
405 if (dhcp->tries <= 1) { in dhcp_timeout()
416 else if (dhcp->state == DHCP_RENEWING) { in dhcp_timeout()
422 } else if (dhcp->state == DHCP_REBINDING) { in dhcp_timeout()
424 if (dhcp->tries <= 8) { in dhcp_timeout()
431 } else if (dhcp->state == DHCP_REBOOTING) { in dhcp_timeout()
432 if (dhcp->tries < REBOOT_TRIES) { in dhcp_timeout()
448 struct dhcp *dhcp = netif->dhcp; in dhcp_t1_timeout() local
450 …if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWI… in dhcp_t1_timeout()
466 struct dhcp *dhcp = netif->dhcp; in dhcp_t2_timeout() local
468 …if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWI… in dhcp_t2_timeout()
483 struct dhcp *dhcp = netif->dhcp; in dhcp_handle_ack() local
486 dhcp->offered_sn_mask.addr = 0; in dhcp_handle_ack()
487 dhcp->offered_gw_addr.addr = 0; in dhcp_handle_ack()
488 dhcp->offered_bc_addr.addr = 0; in dhcp_handle_ack()
491 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_LEASE_TIME); in dhcp_handle_ack()
494 dhcp->offered_t0_lease = dhcp_get_option_long(option_ptr + 2); in dhcp_handle_ack()
497 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_T1); in dhcp_handle_ack()
500 dhcp->offered_t1_renew = dhcp_get_option_long(option_ptr + 2); in dhcp_handle_ack()
503 dhcp->offered_t1_renew = dhcp->offered_t0_lease / 2; in dhcp_handle_ack()
507 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_T2); in dhcp_handle_ack()
510 dhcp->offered_t2_rebind = dhcp_get_option_long(option_ptr + 2); in dhcp_handle_ack()
513 dhcp->offered_t2_rebind = dhcp->offered_t0_lease; in dhcp_handle_ack()
517 ip_addr_set(&dhcp->offered_ip_addr, &dhcp->msg_in->yiaddr); in dhcp_handle_ack()
525 ip_addr_set(&dhcp->offered_si_addr, &dhcp->msg_in->siaddr); in dhcp_handle_ack()
527 if (dhcp->msg_in->file[0]) { in dhcp_handle_ack()
528 dhcp->boot_file_name = mem_malloc(strlen(dhcp->msg_in->file) + 1); in dhcp_handle_ack()
529 strcpy(dhcp->boot_file_name, dhcp->msg_in->file); in dhcp_handle_ack()
534 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_SUBNET_MASK); in dhcp_handle_ack()
537 dhcp->offered_sn_mask.addr = htonl(dhcp_get_option_long(&option_ptr[2])); in dhcp_handle_ack()
541 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_ROUTER); in dhcp_handle_ack()
543 dhcp->offered_gw_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2])); in dhcp_handle_ack()
547 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_BROADCAST); in dhcp_handle_ack()
549 dhcp->offered_bc_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2])); in dhcp_handle_ack()
553 option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_DNS_SERVER); in dhcp_handle_ack()
556 dhcp->dns_count = dhcp_get_option_byte(&option_ptr[1]) / (u32_t)sizeof(struct ip_addr); in dhcp_handle_ack()
558 if (dhcp->dns_count > DHCP_MAX_DNS) in dhcp_handle_ack()
559 dhcp->dns_count = DHCP_MAX_DNS; in dhcp_handle_ack()
560 for (n = 0; n < dhcp->dns_count; n++) { in dhcp_handle_ack()
561 dhcp->offered_dns_addr[n].addr = htonl(dhcp_get_option_long(&option_ptr[2 + n * 4])); in dhcp_handle_ack()
563 dns_setserver( n, (struct ip_addr *)(&(dhcp->offered_dns_addr[n].addr))); in dhcp_handle_ack()
587 struct dhcp *dhcp; in dhcp_start() local
591 dhcp = netif->dhcp; in dhcp_start()
604 if (dhcp == NULL) { in dhcp_start()
606 dhcp = mem_malloc(sizeof(struct dhcp)); in dhcp_start()
607 if (dhcp == NULL) { in dhcp_start()
612 netif->dhcp = dhcp; in dhcp_start()
617 if (dhcp->pcb != NULL) { in dhcp_start()
618 udp_remove(dhcp->pcb); in dhcp_start()
620 LWIP_ASSERT("pbuf p_out wasn't freed", dhcp->p_out == NULL); in dhcp_start()
621 LWIP_ASSERT("reply wasn't freed", dhcp->msg_in == NULL && in dhcp_start()
622 dhcp->options_in == NULL && dhcp->options_in_len == 0); in dhcp_start()
626 memset(dhcp, 0, sizeof(struct dhcp)); in dhcp_start()
628 dhcp->pcb = udp_new(); in dhcp_start()
629 if (dhcp->pcb == NULL) { in dhcp_start()
631 mem_free((void *)dhcp); in dhcp_start()
632 netif->dhcp = dhcp = NULL; in dhcp_start()
636 dhcp->pcb->so_options|=SOF_BROADCAST; in dhcp_start()
639 udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); in dhcp_start()
640 udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); in dhcp_start()
642 udp_recv(dhcp->pcb, dhcp_recv, netif); in dhcp_start()
668 struct dhcp *dhcp, *old_dhcp; in dhcp_inform() local
670 dhcp = mem_malloc(sizeof(struct dhcp)); in dhcp_inform()
671 if (dhcp == NULL) { in dhcp_inform()
675 memset(dhcp, 0, sizeof(struct dhcp)); in dhcp_inform()
678 dhcp->pcb = udp_new(); in dhcp_inform()
679 if (dhcp->pcb == NULL) { in dhcp_inform()
683 old_dhcp = netif->dhcp; in dhcp_inform()
684 netif->dhcp = dhcp; in dhcp_inform()
690 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_inform()
691 dhcp_option_byte(dhcp, DHCP_INFORM); in dhcp_inform()
693 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); in dhcp_inform()
694 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); in dhcp_inform()
696 dhcp_option_trailer(dhcp); in dhcp_inform()
698 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_inform()
701 dhcp->pcb->so_options|=SOF_BROADCAST; in dhcp_inform()
703 udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); in dhcp_inform()
705 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); in dhcp_inform()
711 udp_remove(dhcp->pcb); in dhcp_inform()
712 dhcp->pcb = NULL; in dhcp_inform()
713 netif->dhcp = old_dhcp; in dhcp_inform()
715 mem_free((void *)dhcp); in dhcp_inform()
726 struct dhcp *dhcp = netif->dhcp; in dhcp_network_changed() local
727 if (!dhcp) in dhcp_network_changed()
729 switch (dhcp->state) { in dhcp_network_changed()
735 dhcp->tries = 0; in dhcp_network_changed()
742 dhcp->tries = 0; in dhcp_network_changed()
760 if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { in dhcp_arp_reply()
764 if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { in dhcp_arp_reply()
785 struct dhcp *dhcp = netif->dhcp; in dhcp_decline() local
789 dhcp_set_state(dhcp, DHCP_BACKING_OFF); in dhcp_decline()
793 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_decline()
794 dhcp_option_byte(dhcp, DHCP_DECLINE); in dhcp_decline()
796 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); in dhcp_decline()
797 dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr)); in dhcp_decline()
799 dhcp_option_trailer(dhcp); in dhcp_decline()
801 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_decline()
804 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); in dhcp_decline()
811 dhcp->tries++; in dhcp_decline()
813 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_decline()
828 struct dhcp *dhcp = netif->dhcp; in dhcp_discover() local
832 ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY); in dhcp_discover()
833 dhcp_set_state(dhcp, DHCP_SELECTING); in dhcp_discover()
838 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_discover()
839 dhcp_option_byte(dhcp, DHCP_DISCOVER); in dhcp_discover()
841 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); in dhcp_discover()
842 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); in dhcp_discover()
844 dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/); in dhcp_discover()
845 dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); in dhcp_discover()
846 dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); in dhcp_discover()
847 dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); in dhcp_discover()
848 dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); in dhcp_discover()
850 dhcp_option_trailer(dhcp); in dhcp_discover()
853 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_discover()
856 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); in dhcp_discover()
863 dhcp->tries++; in dhcp_discover()
865 …if(dhcp->tries >= LWIP_DHCP_AUTOIP_COOP_TRIES && dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE… in dhcp_discover()
866 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_ON; in dhcp_discover()
870 msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000; in dhcp_discover()
871 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_discover()
886 struct dhcp *dhcp; in dhcp_bind() local
889 dhcp = netif->dhcp; in dhcp_bind()
890 LWIP_ERROR("dhcp_bind: dhcp != NULL", (dhcp != NULL), return;); in dhcp_bind()
894 if (dhcp->offered_t1_renew != 0xffffffffUL) { in dhcp_bind()
896 …LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t1 renewal timer %"U32_F" secs\n", dhcp->o… in dhcp_bind()
897 timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; in dhcp_bind()
901 dhcp->t1_timeout = (u16_t)timeout; in dhcp_bind()
902 if (dhcp->t1_timeout == 0) { in dhcp_bind()
903 dhcp->t1_timeout = 1; in dhcp_bind()
905 …E | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t1_renew*1… in dhcp_bind()
908 if (dhcp->offered_t2_rebind != 0xffffffffUL) { in dhcp_bind()
909 …LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t2 rebind timer %"U32_F" secs\n", dhcp->of… in dhcp_bind()
910 timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; in dhcp_bind()
914 dhcp->t2_timeout = (u16_t)timeout; in dhcp_bind()
915 if (dhcp->t2_timeout == 0) { in dhcp_bind()
916 dhcp->t2_timeout = 1; in dhcp_bind()
918 …E | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t2_rebind*… in dhcp_bind()
921 ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); in dhcp_bind()
937 ip_addr_set(&gw_addr, &dhcp->offered_gw_addr); in dhcp_bind()
941 gw_addr.addr = (dhcp->offered_ip_addr.addr & sn_mask.addr); in dhcp_bind()
947 if(dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { in dhcp_bind()
949 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF; in dhcp_bind()
953 …LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n", dhcp->offered_ip_addr… in dhcp_bind()
954 netif_set_ipaddr(netif, &dhcp->offered_ip_addr); in dhcp_bind()
962 dhcp_set_state(dhcp, DHCP_BOUND); in dhcp_bind()
973 struct dhcp *dhcp = netif->dhcp; in dhcp_renew() local
980 dhcp_set_state(dhcp, DHCP_RENEWING); in dhcp_renew()
986 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_renew()
987 dhcp_option_byte(dhcp, DHCP_REQUEST); in dhcp_renew()
989 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); in dhcp_renew()
990 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); in dhcp_renew()
995 dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); in dhcp_renew()
997 dhcp_option_byte(dhcp, *p++); in dhcp_renew()
1003 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); in dhcp_renew()
1004 dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr)); in dhcp_renew()
1008 dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); in dhcp_renew()
1009 dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr)); in dhcp_renew()
1012 dhcp_option_trailer(dhcp); in dhcp_renew()
1014 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_renew()
1016 udp_sendto_if(dhcp->pcb, dhcp->p_out, &dhcp->server_ip_addr, DHCP_SERVER_PORT, netif); in dhcp_renew()
1023 dhcp->tries++; in dhcp_renew()
1025 msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000; in dhcp_renew()
1026 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_renew()
1039 struct dhcp *dhcp = netif->dhcp; in dhcp_rebind() local
1046 dhcp_set_state(dhcp, DHCP_REBINDING); in dhcp_rebind()
1052 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_rebind()
1053 dhcp_option_byte(dhcp, DHCP_REQUEST); in dhcp_rebind()
1055 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); in dhcp_rebind()
1056 dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); in dhcp_rebind()
1061 dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); in dhcp_rebind()
1063 dhcp_option_byte(dhcp, *p++); in dhcp_rebind()
1069 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); in dhcp_rebind()
1070 dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr)); in dhcp_rebind()
1072 dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); in dhcp_rebind()
1073 dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr)); in dhcp_rebind()
1076 dhcp_option_trailer(dhcp); in dhcp_rebind()
1078 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_rebind()
1081 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); in dhcp_rebind()
1087 dhcp->tries++; in dhcp_rebind()
1088 msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; in dhcp_rebind()
1089 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_rebind()
1102 struct dhcp *dhcp = netif->dhcp; in dhcp_reboot() local
1106 dhcp_set_state(dhcp, DHCP_REBOOTING); in dhcp_reboot()
1112 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_reboot()
1113 dhcp_option_byte(dhcp, DHCP_REQUEST); in dhcp_reboot()
1115 dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); in dhcp_reboot()
1116 dhcp_option_short(dhcp, 576); in dhcp_reboot()
1118 dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); in dhcp_reboot()
1119 dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr)); in dhcp_reboot()
1121 dhcp_option_trailer(dhcp); in dhcp_reboot()
1123 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_reboot()
1126 udp_sendto_if(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); in dhcp_reboot()
1132 dhcp->tries++; in dhcp_reboot()
1133 msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; in dhcp_reboot()
1134 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_reboot()
1148 struct dhcp *dhcp = netif->dhcp; in dhcp_release() local
1154 dhcp_set_state(dhcp, DHCP_OFF); in dhcp_release()
1156 dhcp->server_ip_addr.addr = 0; in dhcp_release()
1157 dhcp->offered_ip_addr.addr = dhcp->offered_sn_mask.addr = 0; in dhcp_release()
1158 dhcp->offered_gw_addr.addr = dhcp->offered_bc_addr.addr = 0; in dhcp_release()
1159 dhcp->offered_t0_lease = dhcp->offered_t1_renew = dhcp->offered_t2_rebind = 0; in dhcp_release()
1160 dhcp->dns_count = 0; in dhcp_release()
1165 dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); in dhcp_release()
1166 dhcp_option_byte(dhcp, DHCP_RELEASE); in dhcp_release()
1168 dhcp_option_trailer(dhcp); in dhcp_release()
1170 pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); in dhcp_release()
1172 udp_sendto_if(dhcp->pcb, dhcp->p_out, &dhcp->server_ip_addr, DHCP_SERVER_PORT, netif); in dhcp_release()
1178 dhcp->tries++; in dhcp_release()
1179 msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000; in dhcp_release()
1180 dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; in dhcp_release()
1201 struct dhcp *dhcp = netif->dhcp; in dhcp_stop() local
1208 if (dhcp != NULL) { in dhcp_stop()
1210 if(dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { in dhcp_stop()
1212 dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF; in dhcp_stop()
1216 if (dhcp->pcb != NULL) { in dhcp_stop()
1217 udp_remove(dhcp->pcb); in dhcp_stop()
1218 dhcp->pcb = NULL; in dhcp_stop()
1220 LWIP_ASSERT("reply wasn't freed", dhcp->msg_in == NULL && in dhcp_stop()
1221 dhcp->options_in == NULL && dhcp->options_in_len == 0); in dhcp_stop()
1222 mem_free((void *)dhcp); in dhcp_stop()
1223 netif->dhcp = NULL; in dhcp_stop()
1235 dhcp_set_state(struct dhcp *dhcp, u8_t new_state) in dhcp_set_state() argument
1237 if (new_state != dhcp->state) { in dhcp_set_state()
1238 dhcp->state = new_state; in dhcp_set_state()
1239 dhcp->tries = 0; in dhcp_set_state()
1249 dhcp_option(struct dhcp *dhcp, u8_t option_type, u8_t option_len) in dhcp_option() argument
1251 …LWIP_ASSERT("dhcp_option: dhcp->options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN", dhcp->optio… in dhcp_option()
1252 dhcp->msg_out->options[dhcp->options_out_len++] = option_type; in dhcp_option()
1253 dhcp->msg_out->options[dhcp->options_out_len++] = option_len; in dhcp_option()
1260 dhcp_option_byte(struct dhcp *dhcp, u8_t value) in dhcp_option_byte() argument
1262 …LWIP_ASSERT("dhcp_option_byte: dhcp->options_out_len < DHCP_OPTIONS_LEN", dhcp->options_out_len < … in dhcp_option_byte()
1263 dhcp->msg_out->options[dhcp->options_out_len++] = value; in dhcp_option_byte()
1267 dhcp_option_short(struct dhcp *dhcp, u16_t value) in dhcp_option_short() argument
1269 …LWIP_ASSERT("dhcp_option_short: dhcp->options_out_len + 2 <= DHCP_OPTIONS_LEN", dhcp->options_out_… in dhcp_option_short()
1270 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0xff00U) >> 8); in dhcp_option_short()
1271 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t) (value & 0x00ffU); in dhcp_option_short()
1275 dhcp_option_long(struct dhcp *dhcp, u32_t value) in dhcp_option_long() argument
1277 …LWIP_ASSERT("dhcp_option_long: dhcp->options_out_len + 4 <= DHCP_OPTIONS_LEN", dhcp->options_out_l… in dhcp_option_long()
1278 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0xff000000UL) >> 24); in dhcp_option_long()
1279 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x00ff0000UL) >> 16); in dhcp_option_long()
1280 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x0000ff00UL) >> 8); in dhcp_option_long()
1281 dhcp->msg_out->options[dhcp->options_out_len++] = (u8_t)((value & 0x000000ffUL)); in dhcp_option_long()
1295 dhcp_unfold_reply(struct dhcp *dhcp, struct pbuf *p) in dhcp_unfold_reply() argument
1298 LWIP_ERROR("dhcp != NULL", (dhcp != NULL), return ERR_ARG;); in dhcp_unfold_reply()
1300 dhcp_free_reply(dhcp); in dhcp_unfold_reply()
1303 dhcp->options_in_len = p->tot_len - (sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN); in dhcp_unfold_reply()
1304 dhcp->options_in = mem_malloc(dhcp->options_in_len); in dhcp_unfold_reply()
1305 if (dhcp->options_in == NULL) { in dhcp_unfold_reply()
1308 dhcp->options_in_len = 0; in dhcp_unfold_reply()
1312 dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN); in dhcp_unfold_reply()
1313 if (dhcp->msg_in == NULL) { in dhcp_unfold_reply()
1316 if (dhcp->options_in != NULL) { in dhcp_unfold_reply()
1317 mem_free(dhcp->options_in); in dhcp_unfold_reply()
1318 dhcp->options_in = NULL; in dhcp_unfold_reply()
1319 dhcp->options_in_len = 0; in dhcp_unfold_reply()
1325 ret = pbuf_copy_partial(p, dhcp->msg_in, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN, 0); in dhcp_unfold_reply()
1330 if (dhcp->options_in != NULL) { in dhcp_unfold_reply()
1332 …ret = pbuf_copy_partial(p, dhcp->options_in, dhcp->options_in_len, sizeof(struct dhcp_msg) - DHCP_… in dhcp_unfold_reply()
1333 LWIP_ASSERT("ret == dhcp->options_in_len", ret == dhcp->options_in_len); in dhcp_unfold_reply()
1335 dhcp->options_in_len)); in dhcp_unfold_reply()
1345 static void dhcp_free_reply(struct dhcp *dhcp) in dhcp_free_reply() argument
1347 if (dhcp->msg_in != NULL) { in dhcp_free_reply()
1348 mem_free((void *)dhcp->msg_in); in dhcp_free_reply()
1349 dhcp->msg_in = NULL; in dhcp_free_reply()
1351 if (dhcp->options_in) { in dhcp_free_reply()
1352 mem_free(dhcp->options_in); in dhcp_free_reply()
1353 dhcp->options_in = NULL; in dhcp_free_reply()
1354 dhcp->options_in_len = 0; in dhcp_free_reply()
1365 struct dhcp *dhcp = netif->dhcp; in dhcp_recv() local
1380 LWIP_ASSERT("reply wasn't freed", dhcp->msg_in == NULL && in dhcp_recv()
1381 dhcp->options_in == NULL && dhcp->options_in_len == 0); in dhcp_recv()
1402 if (ntohl(reply_msg->xid) != dhcp->xid) { in dhcp_recv()
1404 …ion id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n",ntohl(reply_msg->xid),dhcp->xid)); in dhcp_recv()
1408 if (dhcp_unfold_reply(dhcp, p) != ERR_OK) { in dhcp_recv()
1416 options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE); in dhcp_recv()
1428 if (dhcp->state == DHCP_REQUESTING) { in dhcp_recv()
1430 dhcp->request_timeout = 0; in dhcp_recv()
1440 …else if ((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REBINDING) || (dhcp->state == DHC… in dhcp_recv()
1441 dhcp->request_timeout = 0; in dhcp_recv()
1447 ((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REQUESTING) || in dhcp_recv()
1448 (dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING ))) { in dhcp_recv()
1450 dhcp->request_timeout = 0; in dhcp_recv()
1454 else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) { in dhcp_recv()
1456 dhcp->request_timeout = 0; in dhcp_recv()
1461 dhcp_free_reply(dhcp); in dhcp_recv()
1473 struct dhcp *dhcp; in dhcp_create_request() local
1490 dhcp = netif->dhcp; in dhcp_create_request()
1491 LWIP_ERROR("dhcp_create_request: dhcp != NULL", (dhcp != NULL), return ERR_VAL;); in dhcp_create_request()
1492 LWIP_ASSERT("dhcp_create_request: dhcp->p_out == NULL", dhcp->p_out == NULL); in dhcp_create_request()
1493 LWIP_ASSERT("dhcp_create_request: dhcp->msg_out == NULL", dhcp->msg_out == NULL); in dhcp_create_request()
1494 dhcp->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM); in dhcp_create_request()
1495 if (dhcp->p_out == NULL) { in dhcp_create_request()
1501 (dhcp->p_out->len >= sizeof(struct dhcp_msg))); in dhcp_create_request()
1504 if (dhcp->tries==0) in dhcp_create_request()
1506 dhcp->xid = xid; in dhcp_create_request()
1510 dhcp->msg_out = (struct dhcp_msg *)dhcp->p_out->payload; in dhcp_create_request()
1512 dhcp->msg_out->op = DHCP_BOOTREQUEST; in dhcp_create_request()
1514 dhcp->msg_out->htype = DHCP_HTYPE_ETH; in dhcp_create_request()
1516 dhcp->msg_out->hlen = DHCP_HLEN_ETH; in dhcp_create_request()
1517 dhcp->msg_out->hops = 0; in dhcp_create_request()
1518 dhcp->msg_out->xid = htonl(dhcp->xid); in dhcp_create_request()
1519 dhcp->msg_out->secs = 0; in dhcp_create_request()
1520 dhcp->msg_out->flags = 0; in dhcp_create_request()
1521 dhcp->msg_out->ciaddr.addr = 0; in dhcp_create_request()
1522 if (dhcp->state==DHCP_BOUND || dhcp->state==DHCP_RENEWING || dhcp->state==DHCP_REBINDING) { in dhcp_create_request()
1523 dhcp->msg_out->ciaddr.addr = netif->ip_addr.addr; in dhcp_create_request()
1525 dhcp->msg_out->yiaddr.addr = 0; in dhcp_create_request()
1526 dhcp->msg_out->siaddr.addr = 0; in dhcp_create_request()
1527 dhcp->msg_out->giaddr.addr = 0; in dhcp_create_request()
1530 dhcp->msg_out->chaddr[i] = (i < netif->hwaddr_len) ? netif->hwaddr[i] : 0/* pad byte*/; in dhcp_create_request()
1533 dhcp->msg_out->sname[i] = 0; in dhcp_create_request()
1536 dhcp->msg_out->file[i] = 0; in dhcp_create_request()
1538 dhcp->msg_out->cookie = htonl(0x63825363UL); in dhcp_create_request()
1539 dhcp->options_out_len = 0; in dhcp_create_request()
1542 dhcp->msg_out->options[i] = (u8_t)i; /* for debugging only, no matter if truncated */ in dhcp_create_request()
1555 struct dhcp *dhcp; in dhcp_delete_request() local
1557 dhcp = netif->dhcp; in dhcp_delete_request()
1558 LWIP_ERROR("dhcp_delete_request: dhcp != NULL", (dhcp != NULL), return;); in dhcp_delete_request()
1559 LWIP_ASSERT("dhcp_delete_request: dhcp->p_out != NULL", dhcp->p_out != NULL); in dhcp_delete_request()
1560 LWIP_ASSERT("dhcp_delete_request: dhcp->msg_out != NULL", dhcp->msg_out != NULL); in dhcp_delete_request()
1561 if (dhcp->p_out != NULL) { in dhcp_delete_request()
1562 pbuf_free(dhcp->p_out); in dhcp_delete_request()
1564 dhcp->p_out = NULL; in dhcp_delete_request()
1565 dhcp->msg_out = NULL; in dhcp_delete_request()
1577 dhcp_option_trailer(struct dhcp *dhcp) in dhcp_option_trailer() argument
1579 LWIP_ERROR("dhcp_option_trailer: dhcp != NULL", (dhcp != NULL), return;); in dhcp_option_trailer()
1580 LWIP_ASSERT("dhcp_option_trailer: dhcp->msg_out != NULL\n", dhcp->msg_out != NULL); in dhcp_option_trailer()
1581 …LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_l… in dhcp_option_trailer()
1582 dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END; in dhcp_option_trailer()
1584 while ((dhcp->options_out_len < DHCP_MIN_OPTIONS_LEN) || (dhcp->options_out_len & 3)) { in dhcp_option_trailer()
1586 …LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_l… in dhcp_option_trailer()
1588 dhcp->msg_out->options[dhcp->options_out_len++] = 0; in dhcp_option_trailer()
1601 static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type) in dhcp_get_option_ptr() argument
1606 if ((dhcp->options_in != NULL) && (dhcp->options_in_len > 0)) { in dhcp_get_option_ptr()
1608 u8_t *options = (u8_t *)dhcp->options_in; in dhcp_get_option_ptr()
1611 while ((offset < dhcp->options_in_len) && (options[offset] != DHCP_OPTION_END)) { in dhcp_get_option_ptr()
1638 options = (u8_t *)&dhcp->msg_in->file; in dhcp_get_option_ptr()
1642 options = (u8_t *)&dhcp->msg_in->sname; in dhcp_get_option_ptr()
1647 options = (u8_t *)&dhcp->msg_in->sname; in dhcp_get_option_ptr()