diff --git a/components/esp_phy/include/esp_phy_init.h b/components/esp_phy/include/esp_phy_init.h index 1422b43245..2bb6f6d824 100644 --- a/components/esp_phy/include/esp_phy_init.h +++ b/components/esp_phy/include/esp_phy_init.h @@ -95,7 +95,7 @@ const esp_phy_init_data_t* esp_phy_get_init_data(void); void esp_phy_release_init_data(const esp_phy_init_data_t* data); /** - * @brief Function called by esp_phy_init to load PHY calibration data + * @brief Function called by esp_phy_load_cal_and_init to load PHY calibration data * * This is a convenience function which can be used to load PHY calibration * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs @@ -106,13 +106,6 @@ void esp_phy_release_init_data(const esp_phy_init_data_t* data); * or obtained for a different version of software), this function will * return an error. * - * If "Initialize PHY in startup code" option is set in menuconfig, this - * function will be used to load calibration data. To provide a different - * mechanism for loading calibration data, disable - * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init - * function from the application. For an example usage of esp_phy_init and - * this function, see esp_phy_store_cal_data_to_nvs function in cpu_start.c - * * @param out_cal_data pointer to calibration data structure to be filled with * loaded data. * @return ESP_OK on success @@ -120,19 +113,13 @@ void esp_phy_release_init_data(const esp_phy_init_data_t* data); esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data); /** - * @brief Function called by esp_phy_init to store PHY calibration data + * @brief Function called by esp_phy_load_cal_and_init to store PHY calibration data * * This is a convenience function which can be used to store PHY calibration - * data to the NVS. Calibration data is returned by esp_phy_init function. + * data to the NVS. Calibration data is returned by esp_phy_load_cal_and_init function. * Data saved using this function to the NVS can later be loaded using * esp_phy_store_cal_data_to_nvs function. * - * If "Initialize PHY in startup code" option is set in menuconfig, this - * function will be used to store calibration data. To provide a different - * mechanism for storing calibration data, disable - * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init - * function from the application. - * * @param cal_data pointer to calibration data which has to be saved. * @return ESP_OK on success */ diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 842700ba4d..bb64992ea5 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -78,6 +78,19 @@ } \ } while (0) +#define DHCP_CHECK_IP_MATCH_SUBNET_MASK(mask, ip) \ + u32_t start_ip = 0; \ + u32_t end_ip = 0; \ + do { \ + start_ip = ip & mask; \ + end_ip = start_ip | ~mask; \ + if (ip == end_ip || ip == start_ip) \ + { \ + DHCPS_LOG("dhcps: ip address and subnet mask do not match.\n"); \ + return ERR_ARG; \ + } \ + } while (0) + #define MAX_STATION_NUM CONFIG_LWIP_DHCPS_MAX_STATION_NUM #define DHCPS_STATE_OFFER 1 @@ -1091,50 +1104,48 @@ static void handle_dhcp(void *arg, *******************************************************************************/ static void dhcps_poll_set(u32_t ip) { - u32_t softap_ip = 0, local_ip = 0; + u32_t server_ip = 0; u32_t start_ip = 0; u32_t end_ip = 0; - u32_t temp_local_ip = 0; - u32_t host_num = 0; + u32_t range_start_ip = 0; + u32_t range_end_ip = 0; if (dhcps_poll.enable == true) { - softap_ip = htonl(ip); + server_ip = htonl(ip); start_ip = htonl(dhcps_poll.start_ip.addr); end_ip = htonl(dhcps_poll.end_ip.addr); /*config ip information can't contain local ip*/ - if ((start_ip <= softap_ip) && (softap_ip <= end_ip)) { + if ((start_ip <= server_ip) && (server_ip <= end_ip)) { dhcps_poll.enable = false; } else { /*config ip information must be in the same segment as the local ip*/ - softap_ip >>= 8; - - if (((start_ip >> 8 != softap_ip) || (end_ip >> 8 != softap_ip)) - || (end_ip - start_ip > DHCPS_MAX_LEASE)) { + if (!ip4_addr_netcmp(&dhcps_poll.start_ip, &server_address, &s_dhcps_mask) + || !ip4_addr_netcmp(&dhcps_poll.end_ip, &server_address, &s_dhcps_mask) + || (end_ip - start_ip + 1 > DHCPS_MAX_LEASE)) { dhcps_poll.enable = false; } } } if (dhcps_poll.enable == false) { - local_ip = softap_ip = htonl(ip); - softap_ip &= 0xFFFFFF00; - temp_local_ip = local_ip &= 0xFF; + server_ip = htonl(ip); + range_start_ip = server_ip & htonl(s_dhcps_mask.addr); + range_end_ip = range_start_ip | ~htonl(s_dhcps_mask.addr); - if (local_ip >= 0x80) { - local_ip -= DHCPS_MAX_LEASE; - temp_local_ip -= DHCPS_MAX_LEASE; + if (server_ip - range_start_ip > range_end_ip - server_ip) { + range_start_ip = range_start_ip + 1; + range_end_ip = server_ip - 1; } else { - local_ip ++; + range_start_ip = server_ip + 1; + range_end_ip = range_end_ip - 1; + } + if (range_end_ip - range_start_ip + 1 > DHCPS_MAX_LEASE) { + range_end_ip = range_start_ip + DHCPS_MAX_LEASE - 1; } - bzero(&dhcps_poll, sizeof(dhcps_poll)); - host_num = IP_CLASS_HOST_NUM(htonl(s_dhcps_mask.addr)); - if (host_num > DHCPS_MAX_LEASE) { - host_num = DHCPS_MAX_LEASE; - } - dhcps_poll.start_ip.addr = softap_ip | local_ip; - dhcps_poll.end_ip.addr = softap_ip | (temp_local_ip + host_num - 1); + dhcps_poll.start_ip.addr = range_start_ip; + dhcps_poll.end_ip.addr = range_end_ip; dhcps_poll.start_ip.addr = htonl(dhcps_poll.start_ip.addr); dhcps_poll.end_ip.addr = htonl(dhcps_poll.end_ip.addr); } @@ -1176,7 +1187,7 @@ err_t dhcps_start(struct netif *netif, ip4_addr_t ip) struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb; if (pcb_dhcps == NULL || ip4_addr_isany_val(ip)) { - printf("dhcps_start(): could not obtain pcb\n"); + DHCPS_LOG("dhcps_start(): could not obtain pcb\n"); return ERR_ARG; } @@ -1186,6 +1197,7 @@ err_t dhcps_start(struct netif *netif, ip4_addr_t ip) server_address.addr = ip.addr; DHCP_CHECK_SUBNET_MASK_IP(htonl(s_dhcps_mask.addr)); + DHCP_CHECK_IP_MATCH_SUBNET_MASK(htonl(s_dhcps_mask.addr), htonl(ip.addr)); dhcps_poll_set(server_address.addr); client_address_plus.addr = dhcps_poll.start_ip.addr; diff --git a/components/lwip/lwip b/components/lwip/lwip index 8290c3b8f2..4f24c9baf9 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 8290c3b8f2adaf82aa45ec992b87f16205f2689b +Subproject commit 4f24c9baf9101634b7c690802f424b197b3bb685 diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index 565341c98c..eb51b9e73b 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -263,11 +263,9 @@ extern "C" #define DHCP_DEFINE_CUSTOM_TIMEOUTS 1 /* Since for embedded devices it's not that hard to miss a discover packet, so lower - * the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s. + * the discover and request retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,4,4,4)s. */ - #define DHCP_REQUEST_TIMEOUT_SEQUENCE(state, tries) (state == DHCP_STATE_REQUESTING ? \ - (uint16_t)(1 * 1000) : \ - (uint16_t)(((tries) < 6 ? 1 << (tries) : 60) * 250)) +#define DHCP_REQUEST_TIMEOUT_SEQUENCE(tries) ((uint16_t)(((tries) < 5 ? 1 << (tries) : 16) * 250)) #define DHCP_COARSE_TIMER_SECS CONFIG_LWIP_DHCP_COARSE_TIMER_SECS