68#if LWIP_IPV4 && LWIP_DHCP
86#ifdef LWIP_HOOK_FILENAME
87#include LWIP_HOOK_FILENAME
89#ifndef LWIP_HOOK_DHCP_APPEND_OPTIONS
90#define LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, options_len_ptr)
92#ifndef LWIP_HOOK_DHCP_PARSE_OPTION
93#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) do { LWIP_UNUSED_ARG(msg); } while(0)
104#ifndef DHCP_ADD_EXTRA_REQUEST_OPTIONS
105#define DHCP_ADD_EXTRA_REQUEST_OPTIONS
115#ifndef DHCP_DEFINE_CUSTOM_TIMEOUTS
116#define SET_TIMEOUT_FROM_OFFERED(result, offered, min, max) do { \
117 u32_t timeout = (offered + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; \
118 if (timeout > max) { \
121 if (timeout == min) { \
124 result = (dhcp_timeout_t)timeout; \
127#define DHCP_SET_TIMEOUT_FROM_OFFERED_T0_LEASE(res, dhcp) SET_TIMEOUT_FROM_OFFERED(res, (dhcp)->offered_t0_lease, 0, 0xffff)
128#define DHCP_SET_TIMEOUT_FROM_OFFERED_T1_RENEW(res, dhcp) SET_TIMEOUT_FROM_OFFERED(res, (dhcp)->offered_t1_renew, 0, 0xffff)
129#define DHCP_SET_TIMEOUT_FROM_OFFERED_T2_REBIND(res, dhcp) SET_TIMEOUT_FROM_OFFERED(res, (dhcp)->offered_t2_rebind, 0, 0xffff)
131#define DHCP_NEXT_TIMEOUT_THRESHOLD ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)
132#define DHCP_REQUEST_BACKOFF_SEQUENCE(tries) (u16_t)(( (tries) < 6 ? 1 << (tries) : 60) * 1000)
139#ifndef DHCP_CREATE_RAND_XID
140#define DHCP_CREATE_RAND_XID 1
148#ifdef DHCP_GLOBAL_XID_HEADER
149#include DHCP_GLOBAL_XID_HEADER
154#define DHCP_MAX_MSG_LEN(netif) (netif->mtu)
155#define DHCP_MAX_MSG_LEN_MIN_REQUIRED 576
157#define DHCP_MIN_REPLY_LEN 44
159#define REBOOT_TRIES 2
161#if LWIP_DNS && LWIP_DHCP_MAX_DNS_SERVERS
162#if DNS_MAX_SERVERS > LWIP_DHCP_MAX_DNS_SERVERS
163#define LWIP_DHCP_PROVIDE_DNS_SERVERS LWIP_DHCP_MAX_DNS_SERVERS
165#define LWIP_DHCP_PROVIDE_DNS_SERVERS DNS_MAX_SERVERS
168#define LWIP_DHCP_PROVIDE_DNS_SERVERS 0
171#ifndef LWIP_DHCP_INPUT_ERROR
172#define LWIP_DHCP_INPUT_ERROR(message, expression, handler) do { if (!(expression)) { \
181enum dhcp_option_idx {
182 DHCP_OPTION_IDX_OVERLOAD = 0,
183 DHCP_OPTION_IDX_MSG_TYPE,
184 DHCP_OPTION_IDX_SERVER_ID,
185 DHCP_OPTION_IDX_LEASE_TIME,
188 DHCP_OPTION_IDX_SUBNET_MASK,
189 DHCP_OPTION_IDX_ROUTER,
190#if LWIP_DHCP_PROVIDE_DNS_SERVERS
191 DHCP_OPTION_IDX_DNS_SERVER,
192 DHCP_OPTION_IDX_DNS_SERVER_LAST = DHCP_OPTION_IDX_DNS_SERVER + LWIP_DHCP_PROVIDE_DNS_SERVERS - 1,
194#if LWIP_DHCP_GET_NTP_SRV
195 DHCP_OPTION_IDX_NTP_SERVER,
203static u32_t dhcp_rx_options_val[DHCP_OPTION_IDX_MAX];
207static u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
209static u8_t dhcp_discover_request_options[] = {
213#if LWIP_DHCP_PROVIDE_DNS_SERVERS
216#if LWIP_DHCP_GET_NTP_SRV
219 DHCP_ADD_EXTRA_REQUEST_OPTIONS
222#ifdef DHCP_GLOBAL_XID
224static u8_t xid_initialised;
227#define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0)
228#define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1)
229#define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0)
230#define dhcp_clear_all_options(dhcp) (memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given)))
231#define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx])
232#define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val))
234static struct udp_pcb *dhcp_pcb;
235static u8_t dhcp_pcb_refcount;
241#if LWIP_DHCP_DOES_ACD_CHECK
246static void dhcp_set_state(
struct dhcp *
dhcp,
u8_t new_state);
253static void dhcp_t1_timeout(
struct netif *
netif);
254static void dhcp_t2_timeout(
struct netif *
netif);
265#if LWIP_NETIF_HOSTNAME
273dhcp_inc_pcb_refcount(
void)
275 if (dhcp_pcb_refcount == 0) {
279 dhcp_pcb = udp_new();
281 if (dhcp_pcb ==
NULL) {
290 udp_recv(dhcp_pcb, dhcp_recv,
NULL);
300dhcp_dec_pcb_refcount(
void)
302 LWIP_ASSERT(
"dhcp_pcb_refcount(): refcount error", (dhcp_pcb_refcount > 0));
305 if (dhcp_pcb_refcount == 0) {
306 udp_remove(dhcp_pcb);
334 netif_set_addr(
netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
336 dhcp_discover(
netif);
339#if LWIP_DHCP_DOES_ACD_CHECK
352 LWIP_ASSERT(
"DHCP should be enabled at this point, but it is not!",
369 dhcp->request_timeout = (
u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
375 netif_set_addr(
netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
419 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_SERVER_ID)) {
420 dhcp->request_timeout = 0;
422 ip_addr_set_ip4_u32(&
dhcp->server_ip_addr,
lwip_htonl(dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_SERVER_ID)));
424 ip4_addr_get_u32(ip_2_ip4(&
dhcp->server_ip_addr))));
426 ip4_addr_copy(
dhcp->offered_ip_addr, msg_in->yiaddr);
428 ip4_addr_get_u32(&
dhcp->offered_ip_addr)));
433 (
"dhcp_handle_offer(netif=%p) did not get server ID!\n", (
void *)
netif));
453 u16_t options_out_len;
467 options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(
netif));
471 options_out_len = dhcp_option_long(options_out_len, msg_out->options,
lwip_ntohl(ip4_addr_get_u32(&
dhcp->offered_ip_addr)));
474 options_out_len = dhcp_option_long(options_out_len, msg_out->options,
lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&
dhcp->server_ip_addr))));
478 options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[
i]);
481#if LWIP_NETIF_HOSTNAME
482 options_out_len = dhcp_option_hostname(options_out_len, msg_out->options,
netif);
486 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
496 if (
dhcp->tries < 255) {
499 msecs = (
u16_t)((
dhcp->tries < 6 ? 1 <<
dhcp->tries : 60) * 1000);
500 dhcp->request_timeout = (
u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
520 if (
dhcp->t0_timeout && (++
dhcp->lease_used ==
dhcp->t0_timeout)) {
523 dhcp_release_and_stop(
netif);
526 }
else if (
dhcp->t2_rebind_time && (
dhcp->t2_rebind_time-- == 1)) {
529 dhcp_t2_timeout(
netif);
531 }
else if (
dhcp->t1_renew_time && (
dhcp->t1_renew_time-- == 1)) {
534 dhcp_t1_timeout(
netif);
557 if (
dhcp->request_timeout > 1) {
558 dhcp->request_timeout--;
559 }
else if (
dhcp->request_timeout == 1) {
560 dhcp->request_timeout--;
587 dhcp_discover(
netif);
591 if (
dhcp->tries <= 5) {
595 dhcp_release_and_stop(
netif);
599 if (
dhcp->tries < REBOOT_TRIES) {
602 dhcp_discover(
netif);
623 (
"dhcp_t1_timeout(): must renew\n"));
628 if (((
dhcp->t2_timeout -
dhcp->lease_used) / 2) >= DHCP_NEXT_TIMEOUT_THRESHOLD) {
629 dhcp->t1_renew_time = (dhcp_timeout_t)((
dhcp->t2_timeout -
dhcp->lease_used) / 2);
649 (
"dhcp_t2_timeout(): must rebind\n"));
654 if (((
dhcp->t0_timeout -
dhcp->lease_used) / 2) >= DHCP_NEXT_TIMEOUT_THRESHOLD) {
655 dhcp->t2_rebind_time = (dhcp_timeout_t)((
dhcp->t0_timeout -
dhcp->lease_used) / 2);
670#if LWIP_DHCP_PROVIDE_DNS_SERVERS || LWIP_DHCP_GET_NTP_SRV
673#if LWIP_DHCP_GET_NTP_SRV
678 ip4_addr_set_zero(&
dhcp->offered_sn_mask);
679 ip4_addr_set_zero(&
dhcp->offered_gw_addr);
680#if LWIP_DHCP_BOOTP_FILE
681 ip4_addr_set_zero(&
dhcp->offered_si_addr);
685 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_LEASE_TIME)) {
687 dhcp->offered_t0_lease = dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_LEASE_TIME);
690 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_T1)) {
692 dhcp->offered_t1_renew = dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_T1);
695 dhcp->offered_t1_renew =
dhcp->offered_t0_lease / 2;
699 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_T2)) {
701 dhcp->offered_t2_rebind = dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_T2);
704 dhcp->offered_t2_rebind = (
dhcp->offered_t0_lease * 7U) / 8U;
708 ip4_addr_copy(
dhcp->offered_ip_addr, msg_in->yiaddr);
710#if LWIP_DHCP_BOOTP_FILE
713 ip4_addr_copy(
dhcp->offered_si_addr, msg_in->siaddr);
717 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_SUBNET_MASK)) {
719 ip4_addr_set_u32(&
dhcp->offered_sn_mask,
lwip_htonl(dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_SUBNET_MASK)));
720 dhcp->flags |= DHCP_FLAG_SUBNET_MASK_GIVEN;
722 dhcp->flags &= ~DHCP_FLAG_SUBNET_MASK_GIVEN;
726 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_ROUTER)) {
727 ip4_addr_set_u32(&
dhcp->offered_gw_addr,
lwip_htonl(dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_ROUTER)));
730#if LWIP_DHCP_GET_NTP_SRV
733 ip4_addr_set_u32(&ntp_server_addrs[
n],
lwip_htonl(dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_NTP_SERVER +
n)));
735 dhcp_set_ntp_servers(
n, ntp_server_addrs);
738#if LWIP_DHCP_PROVIDE_DNS_SERVERS
740 for (
n = 0; (
n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(
dhcp, DHCP_OPTION_IDX_DNS_SERVER +
n);
n++) {
742 ip_addr_set_ip4_u32_val(dns_addr,
lwip_htonl(dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_DNS_SERVER +
n)));
743 dns_setserver(
n, &dns_addr);
767 dhcp->flags |= DHCP_FLAG_EXTERNAL_MEM;
769 netif_set_client_data(
netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
dhcp);
789 if (!(
dhcp->flags & DHCP_FLAG_EXTERNAL_MEM)) {
792 netif_set_client_data(
netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
NULL);
822 if (
netif->
mtu < DHCP_MAX_MSG_LEN_MIN_REQUIRED) {
837 netif_set_client_data(
netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
dhcp);
843 if (
dhcp->pcb_allocated != 0) {
844 dhcp_dec_pcb_refcount();
854#if LWIP_DHCP_DOES_ACD_CHECK
856 acd_add(
netif, &
dhcp->acd, dhcp_conflict_callback);
862 if (dhcp_inc_pcb_refcount() !=
ERR_OK) {
865 dhcp->pcb_allocated = 1;
877 dhcp_release_and_stop(
netif);
898 u16_t options_out_len;
903 if (dhcp_inc_pcb_refcount() !=
ERR_OK) {
915 options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(
netif));
918 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
929 dhcp_dec_pcb_refcount();
938dhcp_network_changed_link_up(
struct netif *
netif)
945 switch (
dhcp->state) {
963 dhcp_discover(
netif);
968#if LWIP_DHCP_DOES_ACD_CHECK
984 u16_t options_out_len;
994 options_out_len = dhcp_option_long(options_out_len, msg_out->options,
lwip_ntohl(ip4_addr_get_u32(&
dhcp->offered_ip_addr)));
997 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
1005 (
"dhcp_decline: could not allocate DHCP request\n"));
1026 u16_t options_out_len;
1030#if LWIP_DHCP_AUTOIP_COOP
1032 autoip_start(
netif);
1036 ip4_addr_set_any(&
dhcp->offered_ip_addr);
1040 if (p_out !=
NULL) {
1045 options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(
netif));
1047#if LWIP_NETIF_HOSTNAME && LWIP_DHCP_DISCOVER_ADD_HOSTNAME
1048 options_out_len = dhcp_option_hostname(options_out_len, msg_out->options,
netif);
1053 options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[
i]);
1056 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
1067 if (
dhcp->tries < 255) {
1070 msecs = DHCP_REQUEST_BACKOFF_SEQUENCE(
dhcp->tries);
1071 dhcp->request_timeout = (
u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
1086 ip4_addr_t sn_mask, gw_addr;
1093 dhcp->lease_used = 0;
1095 if (
dhcp->offered_t0_lease != 0xffffffffUL) {
1098 DHCP_SET_TIMEOUT_FROM_OFFERED_T0_LEASE(
dhcp->t0_timeout,
dhcp);
1103 if (
dhcp->offered_t1_renew != 0xffffffffUL) {
1106 DHCP_SET_TIMEOUT_FROM_OFFERED_T1_RENEW(
dhcp->t1_timeout,
dhcp);
1108 dhcp->t1_renew_time =
dhcp->t1_timeout;
1111 if (
dhcp->offered_t2_rebind != 0xffffffffUL) {
1113 DHCP_SET_TIMEOUT_FROM_OFFERED_T2_REBIND(
dhcp->t2_timeout,
dhcp);
1115 dhcp->t2_rebind_time =
dhcp->t2_timeout;
1119 if ((
dhcp->t1_timeout >=
dhcp->t2_timeout) && (
dhcp->t2_timeout > 0)) {
1120 dhcp->t1_timeout = 0;
1123 if (
dhcp->flags & DHCP_FLAG_SUBNET_MASK_GIVEN) {
1125 ip4_addr_copy(sn_mask,
dhcp->offered_sn_mask);
1128 u8_t first_octet = ip4_addr1(&
dhcp->offered_ip_addr);
1129 if (first_octet <= 127) {
1130 ip4_addr_set_u32(&sn_mask,
PP_HTONL(0xff000000UL));
1131 }
else if (first_octet >= 192) {
1132 ip4_addr_set_u32(&sn_mask,
PP_HTONL(0xffffff00UL));
1134 ip4_addr_set_u32(&sn_mask,
PP_HTONL(0xffff0000UL));
1138 ip4_addr_copy(gw_addr,
dhcp->offered_gw_addr);
1141 ip4_addr_get_u32(&
dhcp->offered_ip_addr), ip4_addr_get_u32(&sn_mask), ip4_addr_get_u32(&gw_addr)));
1146 netif_set_addr(
netif, &
dhcp->offered_ip_addr, &sn_mask, &gw_addr);
1164 u16_t options_out_len;
1172 if (p_out !=
NULL) {
1175 options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(
netif));
1179 options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[
i]);
1182#if LWIP_NETIF_HOSTNAME
1183 options_out_len = dhcp_option_hostname(options_out_len, msg_out->options,
netif);
1187 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
1197 if (
dhcp->tries < 255) {
1201 msecs = (
u16_t)(
dhcp->tries < 10 ?
dhcp->tries * 2000 : 20 * 1000);
1202 dhcp->request_timeout = (
u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
1220 u16_t options_out_len;
1227 if (p_out !=
NULL) {
1230 options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(
netif));
1234 options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[
i]);
1237#if LWIP_NETIF_HOSTNAME
1238 options_out_len = dhcp_option_hostname(options_out_len, msg_out->options,
netif);
1242 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
1252 if (
dhcp->tries < 255) {
1255 msecs = (
u16_t)(
dhcp->tries < 10 ?
dhcp->tries * 1000 : 10 * 1000);
1256 dhcp->request_timeout = (
u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
1274 u16_t options_out_len;
1281 if (p_out !=
NULL) {
1284 options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN_MIN_REQUIRED);
1287 options_out_len = dhcp_option_long(options_out_len, msg_out->options,
lwip_ntohl(ip4_addr_get_u32(&
dhcp->offered_ip_addr)));
1291 options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[
i]);
1294#if LWIP_NETIF_HOSTNAME
1295 options_out_len = dhcp_option_hostname(options_out_len, msg_out->options,
netif);
1299 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
1309 if (
dhcp->tries < 255) {
1312 msecs = (
u16_t)(
dhcp->tries < 10 ?
dhcp->tries * 1000 : 10 * 1000);
1313 dhcp->request_timeout = (
u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
1344 ip_addr_set_zero_ip4(&
dhcp->server_ip_addr);
1345 ip4_addr_set_zero(&
dhcp->offered_ip_addr);
1346 ip4_addr_set_zero(&
dhcp->offered_sn_mask);
1347 ip4_addr_set_zero(&
dhcp->offered_gw_addr);
1348#if LWIP_DHCP_BOOTP_FILE
1349 ip4_addr_set_zero(&
dhcp->offered_si_addr);
1351 dhcp->offered_t0_lease =
dhcp->offered_t1_renew =
dhcp->offered_t2_rebind = 0;
1352 dhcp->t1_renew_time =
dhcp->t2_rebind_time =
dhcp->lease_used =
dhcp->t0_timeout = 0;
1355 if (dhcp_supplied_address(
netif)) {
1358 u16_t options_out_len;
1361 if (p_out !=
NULL) {
1364 options_out_len = dhcp_option_long(options_out_len, msg_out->options,
lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr))));
1367 dhcp_option_trailer(options_out_len, msg_out->options, p_out);
1378 netif_set_addr(
netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
1383#if LWIP_DHCP_DOES_ACD_CHECK
1388 if (
dhcp->pcb_allocated != 0) {
1389 dhcp_dec_pcb_refcount();
1390 dhcp->pcb_allocated = 0;
1402 dhcp_release_and_stop(
netif);
1414 dhcp_release_and_stop(
netif);
1425 if (new_state !=
dhcp->state) {
1426 dhcp->state = new_state;
1428 dhcp->request_timeout = 0;
1440 LWIP_ASSERT(
"dhcp_option: options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN", options_out_len + 2U + option_len <=
DHCP_OPTIONS_LEN);
1441 options[options_out_len++] = option_type;
1442 options[options_out_len++] = option_len;
1443 return options_out_len;
1454 return options_out_len;
1463 return options_out_len;
1474 return options_out_len;
1477#if LWIP_NETIF_HOSTNAME
1485 const char *
p =
netif->hostname;
1494 options_out_len = dhcp_option_byte(options_out_len,
options, *
p++);
1498 return options_out_len;
1518 u16_t options_offset;
1520 u16_t options_idx_max;
1522 int parse_file_as_options = 0;
1523 int parse_sname_as_options = 0;
1525#if LWIP_DHCP_BOOTP_FILE
1526 int file_overloaded = 0;
1532 dhcp_clear_all_options(
dhcp);
1540 dhcp->boot_file_name[0] = 0;
1548 options_idx_max =
p->tot_len;
1551 options_offset = options_idx;
1553 options_idx = (
u16_t)(options_idx -
q->len);
1554 options_idx_max = (
u16_t)(options_idx_max -
q->len);
1561 offset_max = options_idx_max;
1567 u8_t decode_len = 0;
1568 int decode_idx = -1;
1570 if (val_offset <
offset) {
1578 len = (
q->next !=
NULL ? ((
u8_t *)
q->next->payload)[0] : 0);
1586 decode_len =
len = 0;
1590 LWIP_DHCP_INPUT_ERROR(
"len == 4",
len == 4,
return ERR_VAL;);
1591 decode_idx = DHCP_OPTION_IDX_SUBNET_MASK;
1595 LWIP_DHCP_INPUT_ERROR(
"len >= decode_len",
len >= decode_len,
return ERR_VAL;);
1596 decode_idx = DHCP_OPTION_IDX_ROUTER;
1598#if LWIP_DHCP_PROVIDE_DNS_SERVERS
1601 LWIP_DHCP_INPUT_ERROR(
"len %% 4 == 0",
len % 4 == 0,
return ERR_VAL;);
1604 LWIP_DHCP_INPUT_ERROR(
"len >= decode_len",
len >= decode_len,
return ERR_VAL;);
1605 decode_idx = DHCP_OPTION_IDX_DNS_SERVER;
1609 LWIP_DHCP_INPUT_ERROR(
"len == 4",
len == 4,
return ERR_VAL;);
1610 decode_idx = DHCP_OPTION_IDX_LEASE_TIME;
1612#if LWIP_DHCP_GET_NTP_SRV
1615 LWIP_DHCP_INPUT_ERROR(
"len %% 4 == 0",
len % 4 == 0,
return ERR_VAL;);
1618 LWIP_DHCP_INPUT_ERROR(
"len >= decode_len",
len >= decode_len,
return ERR_VAL;);
1619 decode_idx = DHCP_OPTION_IDX_NTP_SERVER;
1623 LWIP_DHCP_INPUT_ERROR(
"len == 1",
len == 1,
return ERR_VAL;);
1626 decode_idx = DHCP_OPTION_IDX_OVERLOAD;
1629 LWIP_DHCP_INPUT_ERROR(
"len == 1",
len == 1,
return ERR_VAL;);
1630 decode_idx = DHCP_OPTION_IDX_MSG_TYPE;
1633 LWIP_DHCP_INPUT_ERROR(
"len == 4",
len == 4,
return ERR_VAL;);
1634 decode_idx = DHCP_OPTION_IDX_SERVER_ID;
1637 LWIP_DHCP_INPUT_ERROR(
"len == 4",
len == 4,
return ERR_VAL;);
1638 decode_idx = DHCP_OPTION_IDX_T1;
1641 LWIP_DHCP_INPUT_ERROR(
"len == 4",
len == 4,
return ERR_VAL;);
1642 decode_idx = DHCP_OPTION_IDX_T2;
1648 dhcp_option_given(
dhcp, DHCP_OPTION_IDX_MSG_TYPE) ? (
u8_t)dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_MSG_TYPE) : 0,
1660 if (decode_len > 0) {
1664 LWIP_ASSERT(
"check decode_idx", decode_idx >= 0 && decode_idx < DHCP_OPTION_IDX_MAX);
1665 if (!dhcp_option_given(
dhcp, decode_idx)) {
1666 copy_len =
LWIP_MIN(decode_len, 4);
1670 if (decode_len > 4) {
1672 u16_t next_val_offset;
1673 LWIP_DHCP_INPUT_ERROR(
"decode_len %% 4 == 0", decode_len % 4 == 0,
return ERR_VAL;);
1674 dhcp_got_option(
dhcp, decode_idx);
1676 decode_len = (
u8_t)(decode_len - 4);
1677 next_val_offset = (
u16_t)(val_offset + 4);
1678 if (next_val_offset < val_offset) {
1682 val_offset = next_val_offset;
1685 }
else if (decode_len == 4) {
1688 LWIP_DHCP_INPUT_ERROR(
"invalid decode_len", decode_len == 1,
return ERR_VAL;);
1691 dhcp_got_option(
dhcp, decode_idx);
1692 dhcp_set_option_value(
dhcp, decode_idx,
value);
1698 offset_max = (
u16_t)(offset_max -
q->len);
1699 if (
offset < offset_max) {
1701 LWIP_DHCP_INPUT_ERROR(
"next pbuf was null",
q !=
NULL,
return ERR_VAL;);
1710 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_OVERLOAD)) {
1711 u32_t overload = dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_OVERLOAD);
1712 dhcp_clear_option(
dhcp, DHCP_OPTION_IDX_OVERLOAD);
1714 parse_file_as_options = 1;
1717 parse_sname_as_options = 1;
1720 parse_sname_as_options = 1;
1721 parse_file_as_options = 1;
1727 if (parse_file_as_options) {
1729 parse_file_as_options = 0;
1732#if LWIP_DHCP_BOOTP_FILE
1733 file_overloaded = 1;
1736 }
else if (parse_sname_as_options) {
1737 parse_sname_as_options = 0;
1742#if LWIP_DHCP_BOOTP_FILE
1743 if (!file_overloaded) {
1745 if (dhcp_option_given(
dhcp, DHCP_OPTION_IDX_MSG_TYPE) &&
1746 (dhcp_get_option_value(
dhcp, DHCP_OPTION_IDX_MSG_TYPE) ==
DHCP_ACK))
1775 goto free_pbuf_and_return;
1781 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));
1789 if (
p->len < DHCP_MIN_REPLY_LEN) {
1791 goto free_pbuf_and_return;
1796 goto free_pbuf_and_return;
1804 goto free_pbuf_and_return;
1810 (
"transaction id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n",
lwip_ntohl(reply_msg->xid),
dhcp->xid));
1811 goto free_pbuf_and_return;
1816 (
"problem unfolding DHCP message - too short on memory?\n"));
1817 goto free_pbuf_and_return;
1822 if (!dhcp_option_given(
dhcp, DHCP_OPTION_IDX_MSG_TYPE)) {
1824 goto free_pbuf_and_return;
1836 dhcp_handle_ack(
netif, msg_in);
1837#if LWIP_DHCP_DOES_ACD_CHECK
1853 dhcp_handle_ack(
netif, msg_in);
1862 dhcp_handle_nak(
netif);
1868 dhcp_handle_offer(
netif, msg_in);
1871free_pbuf_and_return:
1888 u16_t options_out_len_loc;
1890#ifndef DHCP_GLOBAL_XID
1895#if DHCP_CREATE_RAND_XID && defined(LWIP_RAND)
1901 if (!xid_initialised) {
1902 xid = DHCP_GLOBAL_XID;
1903 xid_initialised = !xid_initialised;
1909 if (p_out ==
NULL) {
1911 (
"dhcp_create_msg(): could not allocate pbuf\n"));
1914 LWIP_ASSERT(
"dhcp_create_msg: check that first pbuf can hold struct dhcp_msg",
1915 (p_out->len >=
sizeof(
struct dhcp_msg)));
1920 if (
dhcp->tries == 0) {
1921#if DHCP_CREATE_RAND_XID && defined(LWIP_RAND)
1930 (
"transaction id xid(%"X32_F")\n",
xid));
1932 msg_out = (
struct dhcp_msg *)p_out->payload;
1946 ip4_addr_copy(msg_out->ciaddr, *netif_ip4_addr(
netif));
1955 options_out_len_loc = dhcp_option_byte(options_out_len_loc, msg_out->options, message_type);
1956 if (options_out_len) {
1957 *options_out_len = options_out_len_loc;
1976 options[options_out_len++] = 0;
1989dhcp_supplied_address(
const struct netif *
netif)
ACPI_SIZE strlen(const char *String)
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define LWIP_ARRAYSIZE(x)
void dhcp(struct packet *packet)
#define mem_free(ptr, bsize)
static WCHAR available[MAX_STRING_RESOURCE_LEN]
void * mem_malloc(mem_size_t size_in)
#define LWIP_DEBUGF(debug, message)
#define LWIP_ERROR(message, expression, handler)
#define LWIP_ASSERT(message, assertion)
#define ip_set_option(pcb, opt)
#define ip_current_netif()
#define ip_current_input_netif()
#define DHCP_OVERLOAD_FILE
#define DHCP_OVERLOAD_SNAME_FILE
#define DHCP_OPTION_REQUESTED_IP
#define DHCP_OPTION_SERVER_ID
#define DHCP_OPTION_LEASE_TIME
#define DHCP_MIN_OPTIONS_LEN
#define DHCP_OPTION_ROUTER
#define DHCP_OPTION_MAX_MSG_SIZE_LEN
#define DHCP_OVERLOAD_SNAME
#define DHCP_OPTION_HOSTNAME
#define DHCP_OPTION_PARAMETER_REQUEST_LIST
#define DHCP_OPTION_DNS_SERVER
#define DHCP_OPTION_MESSAGE_TYPE_LEN
#define DHCP_OPTION_MAX_MSG_SIZE
#define DHCP_OPTION_MESSAGE_TYPE
#define DHCP_MAGIC_COOKIE
#define DHCP_OPTION_BROADCAST
#define DHCP_OPTION_SUBNET_MASK
#define DHCP_OPTION_OVERLOAD
GLdouble GLdouble GLdouble GLdouble q
GLenum const GLvoid * addr
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define LWIP_UNUSED_ARG(x)
#define LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DBG_LEVEL_WARNING
@ LWIP_IANA_HWTYPE_ETHERNET
@ LWIP_IANA_PORT_DHCP_CLIENT
@ LWIP_IANA_PORT_DHCP_SERVER
#define LWIP_DHCP_AUTOIP_COOP_TRIES
#define LWIP_DHCP_BOOTP_FILE
#define LWIP_DHCP_MAX_NTP_SERVERS
#define LWIP_ASSERT_CORE_LOCKED()
#define NETIF_FLAG_ETHARP
#define netif_is_up(netif)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u8_t pbuf_free(struct pbuf *p)
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
#define ip_addr_copy(dest, src)
#define netif_is_link_up(netif)
#define NETIF_FOREACH(netif)
#define NETIF_MAX_HWADDR_LEN
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]