feat(lwip): update lwip component according to IDF

commit ID: 79a5b0b5
This commit is contained in:
yuanjm
2020-07-16 20:23:43 +08:00
parent da3362ecab
commit ef2c714c06
23 changed files with 613 additions and 435 deletions

View File

@ -81,12 +81,19 @@ typedef struct _list_node {
static const u32_t magic_cookie = 0x63538263;
static struct udp_pcb *pcb_dhcps = NULL;
static struct netif *dhcps_netif = NULL;
static ip4_addr_t broadcast_dhcps;
static ip4_addr_t server_address;
static ip4_addr_t dns_server = {0};
static ip4_addr_t client_address; //added
static ip4_addr_t client_address_plus;
static ip4_addr_t s_dhcps_mask = {
#ifdef USE_CLASS_B_NET
.addr = PP_HTONL(LWIP_MAKEU32(255, 240, 0, 0))
#else
.addr = PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0))
#endif
};
static list_node *plist = NULL;
static bool renew = false;
@ -136,7 +143,12 @@ void *dhcps_option_info(u8_t op_id, u32_t opt_len)
}
break;
case SUBNET_MASK:
if (opt_len == sizeof(s_dhcps_mask)) {
option_arg = &s_dhcps_mask;
}
break;
default:
break;
}
@ -185,6 +197,12 @@ void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len)
}
break;
case SUBNET_MASK:
if (opt_len == sizeof(s_dhcps_mask)) {
s_dhcps_mask = *(ip4_addr_t *)opt_info;
}
default:
break;
}
@ -253,11 +271,13 @@ void node_remove_from_list(list_node **phead, list_node *pdelete)
*phead = NULL;
} else {
if (plist == pdelete) {
*phead = plist->pnext;
// Note: Ignoring the "use after free" warnings, as it could only happen
// if the linked list contains loops
*phead = plist->pnext; // NOLINT(clang-analyzer-unix.Malloc)
pdelete->pnext = NULL;
} else {
while (plist != NULL) {
if (plist->pnext == pdelete) {
if (plist->pnext == pdelete) { // NOLINT(clang-analyzer-unix.Malloc)
plist->pnext = pdelete->pnext;
pdelete->pnext = NULL;
}
@ -294,21 +314,12 @@ static u8_t *add_offer_options(u8_t *optptr)
ipadd.addr = *((u32_t *) &server_address);
#ifdef USE_CLASS_B_NET
*optptr++ = DHCP_OPTION_SUBNET_MASK;
*optptr++ = 4; //length
*optptr++ = 255;
*optptr++ = 240;
*optptr++ = 0;
*optptr++ = 0;
#else
*optptr++ = DHCP_OPTION_SUBNET_MASK;
*optptr++ = 4;
*optptr++ = 255;
*optptr++ = 255;
*optptr++ = 255;
*optptr++ = 0;
#endif
*optptr++ = ip4_addr1(&s_dhcps_mask);
*optptr++ = ip4_addr2(&s_dhcps_mask);
*optptr++ = ip4_addr3(&s_dhcps_mask);
*optptr++ = ip4_addr4(&s_dhcps_mask);
*optptr++ = DHCP_OPTION_LEASE_TIME;
*optptr++ = 4;
@ -355,21 +366,13 @@ static u8_t *add_offer_options(u8_t *optptr)
*optptr++ = ip4_addr4(&ipadd);
}
#ifdef CLASS_B_NET
ip4_addr_t broadcast_addr = { .addr = (ipadd.addr & s_dhcps_mask.addr) | ~s_dhcps_mask.addr };
*optptr++ = DHCP_OPTION_BROADCAST_ADDRESS;
*optptr++ = 4;
*optptr++ = ip4_addr1(&ipadd);
*optptr++ = 255;
*optptr++ = 255;
*optptr++ = 255;
#else
*optptr++ = DHCP_OPTION_BROADCAST_ADDRESS;
*optptr++ = 4;
*optptr++ = ip4_addr1(&ipadd);
*optptr++ = ip4_addr2(&ipadd);
*optptr++ = ip4_addr3(&ipadd);
*optptr++ = 255;
#endif
*optptr++ = ip4_addr1(&broadcast_addr);
*optptr++ = ip4_addr2(&broadcast_addr);
*optptr++ = ip4_addr3(&broadcast_addr);
*optptr++ = ip4_addr4(&broadcast_addr);
*optptr++ = DHCP_OPTION_INTERFACE_MTU;
*optptr++ = 2;
@ -525,6 +528,7 @@ static void send_offer(struct dhcps_msg *m, u16_t len)
ip_addr_t ip_temp = IPADDR4_INIT(0x0);
ip4_addr_set(ip_2_ip4(&ip_temp), &broadcast_dhcps);
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
#if DHCPS_DEBUG
SendOffer_err_t = udp_sendto(pcb_dhcps, p, &ip_temp, DHCPS_CLIENT_PORT);
DHCPS_LOG("dhcps: send_offer>>udp_sendto result %x\n", SendOffer_err_t);
@ -602,6 +606,7 @@ static void send_nak(struct dhcps_msg *m, u16_t len)
ip_addr_t ip_temp = IPADDR4_INIT(0x0);
ip4_addr_set(ip_2_ip4(&ip_temp), &broadcast_dhcps);
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
#if DHCPS_DEBUG
SendNak_err_t = udp_sendto(pcb_dhcps, p, &ip_temp, DHCPS_CLIENT_PORT);
DHCPS_LOG("dhcps: send_nak>>udp_sendto result %x\n", SendNak_err_t);
@ -678,6 +683,7 @@ static void send_ack(struct dhcps_msg *m, u16_t len)
ip_addr_t ip_temp = IPADDR4_INIT(0x0);
ip4_addr_set(ip_2_ip4(&ip_temp), &broadcast_dhcps);
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
SendAck_err_t = udp_sendto(pcb_dhcps, p, &ip_temp, DHCPS_CLIENT_PORT);
#if DHCPS_DEBUG
DHCPS_LOG("dhcps: send_ack>>udp_sendto result %x\n", SendAck_err_t);
@ -1135,19 +1141,20 @@ void dhcps_set_new_lease_cb(dhcps_cb_t cb)
*******************************************************************************/
void dhcps_start(struct netif *netif, ip4_addr_t ip)
{
struct netif *apnetif = netif;
dhcps_netif = netif;
if (apnetif->dhcps_pcb != NULL) {
udp_remove(apnetif->dhcps_pcb);
if (dhcps_netif->dhcps_pcb != NULL) {
udp_remove(dhcps_netif->dhcps_pcb);
}
pcb_dhcps = udp_new();
dhcps_netif->dhcps_pcb = udp_new();
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");
}
apnetif->dhcps_pcb = pcb_dhcps;
dhcps_netif->dhcps_pcb = pcb_dhcps;
IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
@ -1212,6 +1219,7 @@ static void kill_oldest_dhcps_pool(void)
list_node *minpre = NULL, *minp = NULL;
struct dhcps_pool *pdhcps_pool = NULL, *pmin_pool = NULL;
pre = plist;
assert(pre != NULL && pre->pnext != NULL); // Expect the list to have at least 2 nodes
p = pre->pnext;
minpre = pre;
minp = p;
@ -1326,5 +1334,5 @@ dhcps_dns_getserver(void)
{
return dns_server;
}
#endif
#endif // ESP_DHCP

View File

@ -103,10 +103,10 @@ static int esp_ping_receive(esp_ping_t *ep)
int len = 0;
struct sockaddr_storage from;
int fromlen = sizeof(from);
uint16_t data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr));
while ((len = recvfrom(ep->sock, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)&fromlen)) > 0) {
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
ep->recv_len = (uint32_t)len;
if (len >= data_head) {
if (from.ss_family == AF_INET) {
// IPv4
struct sockaddr_in *from4 = (struct sockaddr_in *)&from;
@ -128,6 +128,7 @@ static int esp_ping_receive(esp_ping_t *ep)
if ((iecho->id == ep->packet_hdr->id) && (iecho->seqno == ep->packet_hdr->seqno)) {
ep->received++;
ep->ttl = iphdr->_ttl;
ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP
return len;
}
}

View File

@ -18,12 +18,14 @@
#include <sys/time.h>
#include "esp_log.h"
#include "sntp.h"
#include "lwip/apps/sntp.h"
static const char *TAG = "sntp";
static volatile sntp_sync_mode_t sntp_sync_mode = SNTP_SYNC_MODE_IMMED;
static volatile sntp_sync_status_t sntp_sync_status = SNTP_SYNC_STATUS_RESET;
static sntp_sync_time_cb_t time_sync_notification_cb = NULL;
static uint32_t s_sync_interval = CONFIG_LWIP_SNTP_UPDATE_DELAY;
inline void sntp_set_sync_status(sntp_sync_status_t sync_status)
{
@ -91,3 +93,27 @@ sntp_sync_status_t sntp_get_sync_status(void)
}
return ret_sync_status;
}
void sntp_set_sync_interval(uint32_t interval_ms)
{
if (interval_ms < 15000) {
// SNTPv4 RFC 4330 enforces a minimum update time of 15 seconds
interval_ms = 15000;
}
s_sync_interval = interval_ms;
}
uint32_t sntp_get_sync_interval(void)
{
return s_sync_interval;
}
bool sntp_restart(void)
{
if (sntp_enabled()) {
sntp_stop();
sntp_init();
return true;
}
return false;
}