Commit c674d191 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Upgraded open-source LWIP.

From Espressif's lwip_open_src_template_proj_for_v1.3.0.zip
parent c1cd58e0
/******************************************************************************
* FunctionName : espconn_init
* Description : dummy the espconn_init
* Parameters : none
* Returns : none
*******************************************************************************/
void espconn_init()
{
// dummy function, do nothing.
}
This diff is collapsed.
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: espconn_mdns.c
*
* Description: udp proto interface
*
* Modification history:
* 2014/3/31, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "os_type.h"
#include "lwip/mdns.h"
/******************************************************************************
* FunctionName : espconn_mdns_enable
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_enable(void)
{
mdns_enable();
}
/******************************************************************************
* FunctionName : espconn_mdns_disable
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_disable(void)
{
mdns_disable();
}
/******************************************************************************
* FunctionName : espconn_mdns_set_hostname
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_set_hostname(char *name)
{
mdns_set_hostname(name);
}
/******************************************************************************
* FunctionName : espconn_mdns_init
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
char* ICACHE_FLASH_ATTR
espconn_mdns_get_hostname(void)
{
return (char *)mdns_get_hostname();
}
/******************************************************************************
* FunctionName : espconn_mdns_get_servername
* Description : join a multicast group
* Parameters : info -- the info of mdns
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_set_servername(const char *name)
{
mdns_set_servername(name);
}
/******************************************************************************
* FunctionName : espconn_mdns_get_servername
* Description : join a multicast group
* Parameters : info -- the info of mdns
* Returns : none
*******************************************************************************/
char* ICACHE_FLASH_ATTR
espconn_mdns_get_servername(void)
{
return (char *)mdns_get_servername();
}
/******************************************************************************
* FunctionName : mdns_server_register
* Description : join a multicast group
* Parameters : info -- the info of mdns
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_server_register(void)
{
mdns_server_register();
}
/******************************************************************************
* FunctionName : mdns_server_register
* Description : join a multicast group
* Parameters : info -- the info of mdns
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_server_unregister(void)
{
mdns_server_unregister();
}
/******************************************************************************
* FunctionName : espconn_mdns_init
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_close(void)
{
mdns_close();
}
/******************************************************************************
* FunctionName : espconn_mdns_init
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
espconn_mdns_init(struct mdns_info *info)
{
mdns_init(info);
}
This diff is collapsed.
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
#include "lwip/app/espconn_udp.h" #include "lwip/app/espconn_udp.h"
//#include "net80211/ieee80211_var.h"
extern espconn_msg *plink_active; extern espconn_msg *plink_active;
extern uint8 default_interface;
static void ICACHE_FLASH_ATTR espconn_data_sentcb(struct espconn *pespconn) static void ICACHE_FLASH_ATTR espconn_data_sentcb(struct espconn *pespconn)
{ {
if (pespconn == NULL) { if (pespconn == NULL) {
...@@ -45,7 +46,8 @@ static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg) ...@@ -45,7 +46,8 @@ static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg)
if (psent->pcommon.cntr == 0) { if (psent->pcommon.cntr == 0) {
psent->pespconn->state = ESPCONN_CONNECT; psent->pespconn->state = ESPCONN_CONNECT;
sys_timeout(TCP_FAST_INTERVAL, espconn_data_sentcb, psent->pespconn); // sys_timeout(10, espconn_data_sentcb, psent->pespconn);
espconn_data_sentcb(psent->pespconn);
} else { } else {
espconn_udp_sent(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr); espconn_udp_sent(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr);
} }
...@@ -57,14 +59,18 @@ static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg) ...@@ -57,14 +59,18 @@ static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg)
* Parameters : void *arg -- client or server to send * Parameters : void *arg -- client or server to send
* uint8* psent -- Data to send * uint8* psent -- Data to send
* uint16 length -- Length of data to send * uint16 length -- Length of data to send
* Returns : none * Returns : return espconn error code.
* - ESPCONN_OK. Successful. No error occured.
* - ESPCONN_MEM. Out of memory.
* - ESPCONN_RTE. Could not find route to destination address.
* - More errors could be returned by lower protocol layers.
*******************************************************************************/ *******************************************************************************/
void ICACHE_FLASH_ATTR err_t ICACHE_FLASH_ATTR
espconn_udp_sent(void *arg, uint8 *psent, uint16 length) espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
{ {
espconn_msg *pudp_sent = arg; espconn_msg *pudp_sent = arg;
struct udp_pcb *upcb = pudp_sent->pcommon.pcb; struct udp_pcb *upcb = pudp_sent->pcommon.pcb;
struct pbuf *p, *q; struct pbuf *p, *q ,*p_temp;
u8_t *data = NULL; u8_t *data = NULL;
u16_t cnt = 0; u16_t cnt = 0;
u16_t datalen = 0; u16_t datalen = 0;
...@@ -73,11 +79,11 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length) ...@@ -73,11 +79,11 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb)); LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));
if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) { if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
return; return ESPCONN_ARG;
} }
if (1024 < length) { if (TCP_MSS < length) {
datalen = 1024; datalen = TCP_MSS;
} else { } else {
datalen = length; datalen = length;
} }
...@@ -99,7 +105,7 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length) ...@@ -99,7 +105,7 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
q = q->next; q = q->next;
} }
} else { } else {
return; return ESPCONN_MEM;
} }
upcb->remote_port = pudp_sent->pespconn->proto.udp->remote_port; upcb->remote_port = pudp_sent->pespconn->proto.udp->remote_port;
...@@ -109,7 +115,29 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length) ...@@ -109,7 +115,29 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
pudp_sent->pespconn->proto.udp->remote_ip[3]); pudp_sent->pespconn->proto.udp->remote_ip[3]);
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port)); LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));
struct netif *sta_netif = (struct netif *)eagle_lwip_getif(0x00);
struct netif *ap_netif = (struct netif *)eagle_lwip_getif(0x01);
if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL)
{
if(netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \
ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) {
p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
if (pbuf_copy (p_temp,p) != ERR_OK) {
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent: copying to new pbuf failed\n"));
return ESPCONN_ARG;
}
netif_set_default(sta_netif);
err = udp_send(upcb, p_temp);
pbuf_free(p_temp);
netif_set_default(ap_netif);
}
}
err = udp_send(upcb, p); err = udp_send(upcb, p);
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d\n", __LINE__, err)); LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d\n", __LINE__, err));
if (p->ref != 0) { if (p->ref != 0) {
...@@ -118,6 +146,10 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length) ...@@ -118,6 +146,10 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
pudp_sent->pcommon.ptrbuf = psent + datalen; pudp_sent->pcommon.ptrbuf = psent + datalen;
pudp_sent->pcommon.cntr = length - datalen; pudp_sent->pcommon.cntr = length - datalen;
espconn_data_sent(pudp_sent); espconn_data_sent(pudp_sent);
return err;
} else {
pbuf_free(p);
return ESPCONN_RTE;
} }
} }
...@@ -164,11 +196,11 @@ espconn_udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, ...@@ -164,11 +196,11 @@ espconn_udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
} else { } else {
wifi_get_ip_info(0, &ipconfig); wifi_get_ip_info(0, &ipconfig);
} }
upcb->local_ip = ipconfig.ip; // upcb->local_ip = ipconfig.ip;
precv->pespconn->proto.udp->local_ip[0] = ip4_addr1_16(&upcb->local_ip); precv->pespconn->proto.udp->local_ip[0] = ip4_addr1_16(&ipconfig.ip);
precv->pespconn->proto.udp->local_ip[1] = ip4_addr2_16(&upcb->local_ip); precv->pespconn->proto.udp->local_ip[1] = ip4_addr2_16(&ipconfig.ip);
precv->pespconn->proto.udp->local_ip[2] = ip4_addr3_16(&upcb->local_ip); precv->pespconn->proto.udp->local_ip[2] = ip4_addr3_16(&ipconfig.ip);
precv->pespconn->proto.udp->local_ip[3] = ip4_addr4_16(&upcb->local_ip); precv->pespconn->proto.udp->local_ip[3] = ip4_addr4_16(&ipconfig.ip);
if (p != NULL) { if (p != NULL) {
// q = p; // q = p;
......
...@@ -93,6 +93,9 @@ ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len) ...@@ -93,6 +93,9 @@ ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
iecho->chksum = 0; iecho->chksum = 0;
iecho->id = PING_ID; iecho->id = PING_ID;
++ ping_seq_num; ++ ping_seq_num;
if (ping_seq_num == 0x7fff)
ping_seq_num = 0;
iecho->seqno = htons(ping_seq_num); iecho->seqno = htons(ping_seq_num);
/* fill the additional data buffer with some data */ /* fill the additional data buffer with some data */
...@@ -233,7 +236,7 @@ ping_coarse_tmr(void *arg) ...@@ -233,7 +236,7 @@ ping_coarse_tmr(void *arg)
} else { } else {
uint32 delay = system_relative_time(pingmsg->ping_start); uint32 delay = system_relative_time(pingmsg->ping_start);
delay /= PING_COARSE; delay /= PING_COARSE;
ping_seq_num = 0; // ping_seq_num = 0;
if (ping_opt->sent_function == NULL){ if (ping_opt->sent_function == NULL){
os_printf("ping %d, timeout %d, total payload %d bytes, %d ms\n", os_printf("ping %d, timeout %d, total payload %d bytes, %d ms\n",
pingmsg->max_count, pingmsg->timeout_count, PING_DATA_SIZE*(pingmsg->max_count - pingmsg->timeout_count),delay); pingmsg->max_count, pingmsg->timeout_count, PING_DATA_SIZE*(pingmsg->max_count - pingmsg->timeout_count),delay);
......
...@@ -129,7 +129,7 @@ u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX]; ...@@ -129,7 +129,7 @@ u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
#define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0) #define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0)
#define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1) #define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1)
#define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0) #define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0)
#define dhcp_clear_all_options(dhcp) (memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given))) #define dhcp_clear_all_options(dhcp) (os_memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given)))
#define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx]) #define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx])
#define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val)) #define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val))
...@@ -288,16 +288,24 @@ dhcp_select(struct netif *netif) ...@@ -288,16 +288,24 @@ dhcp_select(struct netif *netif)
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr))); dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr)));
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/); dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/);
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS);
dhcp_option_byte(dhcp, DHCP_OPTION_PRD);
dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_VSN);
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) { if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname; const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)strlen(p); u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) { if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
...@@ -587,7 +595,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) ...@@ -587,7 +595,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL); LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL);
/* clear data structure */ /* clear data structure */
memset(dhcp, 0, sizeof(struct dhcp)); os_memset(dhcp, 0, sizeof(struct dhcp));
/* dhcp_set_state(&dhcp, DHCP_OFF); */ /* dhcp_set_state(&dhcp, DHCP_OFF); */
netif->dhcp = dhcp; netif->dhcp = dhcp;
} }
...@@ -626,7 +634,6 @@ dhcp_start(struct netif *netif) ...@@ -626,7 +634,6 @@ dhcp_start(struct netif *netif)
{ {
struct dhcp *dhcp; struct dhcp *dhcp;
err_t result = ERR_OK; err_t result = ERR_OK;
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;); LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
dhcp = netif->dhcp; dhcp = netif->dhcp;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
...@@ -668,7 +675,7 @@ dhcp_start(struct netif *netif) ...@@ -668,7 +675,7 @@ dhcp_start(struct netif *netif)
} }
/* clear data structure */ /* clear data structure */
memset(dhcp, 0, sizeof(struct dhcp)); os_memset(dhcp, 0, sizeof(struct dhcp));
/* dhcp_set_state(&dhcp, DHCP_OFF); */ /* dhcp_set_state(&dhcp, DHCP_OFF); */
/* allocate UDP PCB */ /* allocate UDP PCB */
dhcp->pcb = udp_new(); dhcp->pcb = udp_new();
...@@ -713,7 +720,7 @@ dhcp_inform(struct netif *netif) ...@@ -713,7 +720,7 @@ dhcp_inform(struct netif *netif)
LWIP_ERROR("netif != NULL", (netif != NULL), return;); LWIP_ERROR("netif != NULL", (netif != NULL), return;);
memset(&dhcp, 0, sizeof(struct dhcp)); os_memset(&dhcp, 0, sizeof(struct dhcp));
dhcp_set_state(&dhcp, DHCP_INFORM); dhcp_set_state(&dhcp, DHCP_INFORM);
if ((netif->dhcp != NULL) && (netif->dhcp->pcb != NULL)) { if ((netif->dhcp != NULL) && (netif->dhcp->pcb != NULL)) {
...@@ -881,11 +888,32 @@ dhcp_discover(struct netif *netif) ...@@ -881,11 +888,32 @@ dhcp_discover(struct netif *netif)
dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif));
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/); #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
while (*p) {
dhcp_option_byte(dhcp, *p++);
}
}
}
#endif /* LWIP_NETIF_HOSTNAME */
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 12/*num options*/);
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER); dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
dhcp_option_byte(dhcp, DHCP_OPTION_DOMAIN_NAME);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINS);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TINT);
dhcp_option_byte(dhcp, DHCP_OPTION_NB_TIS);
dhcp_option_byte(dhcp, DHCP_OPTION_PRD);
dhcp_option_byte(dhcp, DHCP_OPTION_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_CLASSLESS_STATIC_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_VSN);
dhcp_option_trailer(dhcp); dhcp_option_trailer(dhcp);
...@@ -994,6 +1022,12 @@ dhcp_bind(struct netif *netif) ...@@ -994,6 +1022,12 @@ dhcp_bind(struct netif *netif)
} }
#endif /* LWIP_DHCP_AUTOIP_COOP */ #endif /* LWIP_DHCP_AUTOIP_COOP */
// wjg:back up old ip/netmask/gw
ip_addr_t ip, mask, gw;
ip = netif->ip_addr;
mask = netif->netmask;
gw = netif->gw;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n", LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n",
ip4_addr_get_u32(&dhcp->offered_ip_addr))); ip4_addr_get_u32(&dhcp->offered_ip_addr)));
netif_set_ipaddr(netif, &dhcp->offered_ip_addr); netif_set_ipaddr(netif, &dhcp->offered_ip_addr);
...@@ -1002,12 +1036,14 @@ dhcp_bind(struct netif *netif) ...@@ -1002,12 +1036,14 @@ dhcp_bind(struct netif *netif)
netif_set_netmask(netif, &sn_mask); netif_set_netmask(netif, &sn_mask);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n", LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n",
ip4_addr_get_u32(&gw_addr))); ip4_addr_get_u32(&gw_addr)));
system_station_got_ip_set(&dhcp->offered_ip_addr, &sn_mask, &gw_addr);
netif_set_gw(netif, &gw_addr); netif_set_gw(netif, &gw_addr);
/* bring the interface up */ /* bring the interface up */
netif_set_up(netif); netif_set_up(netif);
// wjg: use old ip/mask/gw to check whether ip/mask/gw changed
system_station_got_ip_set(&ip, &mask, &gw);
/* netif is now bound to DHCP leased address */ /* netif is now bound to DHCP leased address */
dhcp_set_state(dhcp, DHCP_BOUND); dhcp_set_state(dhcp, DHCP_BOUND);
} }
...@@ -1035,7 +1071,7 @@ dhcp_renew(struct netif *netif) ...@@ -1035,7 +1071,7 @@ dhcp_renew(struct netif *netif)
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) { if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname; const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)strlen(p); u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) { if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
...@@ -1098,7 +1134,7 @@ dhcp_rebind(struct netif *netif) ...@@ -1098,7 +1134,7 @@ dhcp_rebind(struct netif *netif)
#if LWIP_NETIF_HOSTNAME #if LWIP_NETIF_HOSTNAME
if (netif->hostname != NULL) { if (netif->hostname != NULL) {
const char *p = (const char*)netif->hostname; const char *p = (const char*)netif->hostname;
u8_t namelen = (u8_t)strlen(p); u8_t namelen = (u8_t)os_strlen(p);
if (namelen > 0) { if (namelen > 0) {
LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255); LWIP_ASSERT("DHCP: hostname is too long!", namelen < 255);
dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen); dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, namelen);
...@@ -1245,7 +1281,6 @@ dhcp_stop(struct netif *netif) ...@@ -1245,7 +1281,6 @@ dhcp_stop(struct netif *netif)
dhcp = netif->dhcp; dhcp = netif->dhcp;
/* Remove the flag that says this netif is handled by DHCP. */ /* Remove the flag that says this netif is handled by DHCP. */
netif->flags &= ~NETIF_FLAG_DHCP; netif->flags &= ~NETIF_FLAG_DHCP;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n")); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n"));
/* netif is DHCP configured? */ /* netif is DHCP configured? */
if (dhcp != NULL) { if (dhcp != NULL) {
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
/** DNS server IP address */ /** DNS server IP address */
#ifndef DNS_SERVER_ADDRESS #ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */ #define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, 0xDEDE43D0)) /* resolver1.opendns.com(208.67.222.222) */
#endif #endif
/** DNS server port address */ /** DNS server port address */
...@@ -173,7 +173,7 @@ struct dns_table_entry { ...@@ -173,7 +173,7 @@ struct dns_table_entry {
u8_t seqno; u8_t seqno;
u8_t err; u8_t err;
u32_t ttl; u32_t ttl;
char *name; char name[DNS_MAX_NAME_LENGTH];
ip_addr_t ipaddr; ip_addr_t ipaddr;
/* pointer to callback on DNS query done */ /* pointer to callback on DNS query done */
dns_found_callback found; dns_found_callback found;
...@@ -221,9 +221,9 @@ static u8_t dns_seqno; ...@@ -221,9 +221,9 @@ static u8_t dns_seqno;
static struct dns_table_entry dns_table[DNS_TABLE_SIZE]; static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
static ip_addr_t dns_servers[DNS_MAX_SERVERS]; static ip_addr_t dns_servers[DNS_MAX_SERVERS];
/** Contiguous buffer for processing responses */ /** Contiguous buffer for processing responses */
static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)]; //static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];
static u8_t* dns_payload; static u8_t* dns_payload;
static u8_t dns_random;
/** /**
* Initialize the resolver: set up the UDP pcb and configure the default server * Initialize the resolver: set up the UDP pcb and configure the default server
* (DNS_SERVER_ADDRESS). * (DNS_SERVER_ADDRESS).
...@@ -233,7 +233,7 @@ dns_init() ...@@ -233,7 +233,7 @@ dns_init()
{ {
ip_addr_t dnsserver; ip_addr_t dnsserver;
dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer); // dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
/* initialize default DNS server address */ /* initialize default DNS server address */
DNS_SERVER_ADDRESS(&dnsserver); DNS_SERVER_ADDRESS(&dnsserver);
...@@ -299,7 +299,7 @@ dns_getserver(u8_t numdns) ...@@ -299,7 +299,7 @@ dns_getserver(u8_t numdns)
* The DNS resolver client timer - handle retries and timeouts and should * The DNS resolver client timer - handle retries and timeouts and should
* be called every DNS_TMR_INTERVAL milliseconds (every second by default). * be called every DNS_TMR_INTERVAL milliseconds (every second by default).
*/ */
void void ICACHE_FLASH_ATTR
dns_tmr(void) dns_tmr(void)
{ {
if (dns_pcb != NULL) { if (dns_pcb != NULL) {
...@@ -321,7 +321,7 @@ dns_init_local() ...@@ -321,7 +321,7 @@ dns_init_local()
for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) { for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) {
struct local_hostlist_entry *init_entry = &local_hostlist_init[i]; struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL); LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL);
namelen = strlen(init_entry->name); namelen = os_strlen(init_entry->name);
LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN); LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST); entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
LWIP_ASSERT("mem-error in dns_init_local", entry != NULL); LWIP_ASSERT("mem-error in dns_init_local", entry != NULL);
...@@ -416,7 +416,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr) ...@@ -416,7 +416,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr)
struct local_hostlist_entry *entry; struct local_hostlist_entry *entry;
size_t namelen; size_t namelen;
LWIP_ASSERT("invalid host name (NULL)", hostname != NULL); LWIP_ASSERT("invalid host name (NULL)", hostname != NULL);
namelen = strlen(hostname); namelen = os_strlen(hostname);
LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN); LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST); entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
if (entry == NULL) { if (entry == NULL) {
...@@ -566,7 +566,7 @@ dns_send(u8_t numdns, const char* name, u8_t id) ...@@ -566,7 +566,7 @@ dns_send(u8_t numdns, const char* name, u8_t id)
char *query, *nptr; char *query, *nptr;
const char *pHostname; const char *pHostname;
u8_t n; u8_t n;
dns_random = os_random()%250;
LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n", LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
(u16_t)(numdns), name)); (u16_t)(numdns), name));
LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS); LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS);
...@@ -579,8 +579,8 @@ dns_send(u8_t numdns, const char* name, u8_t id) ...@@ -579,8 +579,8 @@ dns_send(u8_t numdns, const char* name, u8_t id)
LWIP_ASSERT("pbuf must be in one piece", p->next == NULL); LWIP_ASSERT("pbuf must be in one piece", p->next == NULL);
/* fill dns header */ /* fill dns header */
hdr = (struct dns_hdr*)p->payload; hdr = (struct dns_hdr*)p->payload;
memset(hdr, 0, SIZEOF_DNS_HDR); os_memset(hdr, 0, SIZEOF_DNS_HDR);
hdr->id = htons(id); hdr->id = htons(id + dns_random);
hdr->flags1 = DNS_FLAG1_RD; hdr->flags1 = DNS_FLAG1_RD;
hdr->numquestions = PP_HTONS(1); hdr->numquestions = PP_HTONS(1);
query = (char*)hdr + SIZEOF_DNS_HDR; query = (char*)hdr + SIZEOF_DNS_HDR;
...@@ -673,8 +673,6 @@ dns_check_entry(u8_t i) ...@@ -673,8 +673,6 @@ dns_check_entry(u8_t i)
if (pEntry->found) if (pEntry->found)
(*pEntry->found)(pEntry->name, NULL, pEntry->arg); (*pEntry->found)(pEntry->name, NULL, pEntry->arg);
/* flush this entry */ /* flush this entry */
mem_free (pEntry->name);
pEntry->name = NULL;
pEntry->state = DNS_STATE_UNUSED; pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL; pEntry->found = NULL;
break; break;
...@@ -699,8 +697,6 @@ dns_check_entry(u8_t i) ...@@ -699,8 +697,6 @@ dns_check_entry(u8_t i)
if (--pEntry->ttl == 0) { if (--pEntry->ttl == 0) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name)); LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
/* flush this entry */ /* flush this entry */
mem_free (pEntry->name);
pEntry->name = NULL;
pEntry->state = DNS_STATE_UNUSED; pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL; pEntry->found = NULL;
} }
...@@ -743,6 +739,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t ...@@ -743,6 +739,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
struct dns_table_entry *pEntry; struct dns_table_entry *pEntry;
u16_t nquestions, nanswers; u16_t nquestions, nanswers;
u8_t* dns_payload_buffer = (u8_t* )os_zalloc(LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE));
dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(addr); LWIP_UNUSED_ARG(addr);
...@@ -767,6 +766,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t ...@@ -767,6 +766,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
/* The ID in the DNS header should be our entry into the name table. */ /* The ID in the DNS header should be our entry into the name table. */
hdr = (struct dns_hdr*)dns_payload; hdr = (struct dns_hdr*)dns_payload;
i = htons(hdr->id); i = htons(hdr->id);
i = i - dns_random;
if (i < DNS_TABLE_SIZE) { if (i < DNS_TABLE_SIZE) {
pEntry = &dns_table[i]; pEntry = &dns_table[i];
if(pEntry->state == DNS_STATE_ASKING) { if(pEntry->state == DNS_STATE_ASKING) {
...@@ -843,14 +843,13 @@ responseerr: ...@@ -843,14 +843,13 @@ responseerr:
(*pEntry->found)(pEntry->name, NULL, pEntry->arg); (*pEntry->found)(pEntry->name, NULL, pEntry->arg);
} }
/* flush this entry */ /* flush this entry */
mem_free (pEntry->name);
pEntry->name = NULL;
pEntry->state = DNS_STATE_UNUSED; pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL; pEntry->found = NULL;
memerr: memerr:
/* free pbuf */ /* free pbuf */
pbuf_free(p); pbuf_free(p);
os_free(dns_payload_buffer);
return; return;
} }
...@@ -904,16 +903,11 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg) ...@@ -904,16 +903,11 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i))); LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
/* fill the entry */ /* fill the entry */
namelen = LWIP_MIN(strlen(name), DNS_MAX_NAME_LENGTH-1);
char *namebuf = (char *)mem_zalloc (namelen);
if (!namebuf)
return ERR_MEM;
pEntry->state = DNS_STATE_NEW; pEntry->state = DNS_STATE_NEW;
pEntry->seqno = dns_seqno++; pEntry->seqno = dns_seqno++;
pEntry->found = found; pEntry->found = found;
pEntry->arg = callback_arg; pEntry->arg = callback_arg;
mem_free (pEntry->name); namelen = LWIP_MIN(os_strlen(name), DNS_MAX_NAME_LENGTH-1);
pEntry->name = namebuf;
MEMCPY(pEntry->name, name, namelen); MEMCPY(pEntry->name, name, namelen);
pEntry->name[namelen] = 0; pEntry->name[namelen] = 0;
...@@ -952,7 +946,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun ...@@ -952,7 +946,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
* or invalid hostname or invalid hostname length */ * or invalid hostname or invalid hostname length */
if ((dns_pcb == NULL) || (addr == NULL) || if ((dns_pcb == NULL) || (addr == NULL) ||
(!hostname) || (!hostname[0]) || (!hostname) || (!hostname[0]) ||
(strlen(hostname) >= DNS_MAX_NAME_LENGTH)) { (os_strlen(hostname) >= DNS_MAX_NAME_LENGTH)) {
return ERR_ARG; return ERR_ARG;
} }
......
...@@ -99,18 +99,18 @@ ...@@ -99,18 +99,18 @@
//#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0)) //#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0))
// #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h" // #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h"
//#endif //#endif
#if (LWIP_TCP && (TCP_WND > 0xffff)) //#if (LWIP_TCP && (TCP_WND > 0xffff))
#error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h" // #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
#endif //#endif
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff)) #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h" #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
#endif #endif
#if (LWIP_TCP && (TCP_SND_QUEUELEN < 2)) #if (LWIP_TCP && (TCP_SND_QUEUELEN < 2))
#error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work" #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
#endif #endif
#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12))) //#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
#error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h" // #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
#endif //#endif
#if (LWIP_TCP && TCP_LISTEN_BACKLOG && (TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)) #if (LWIP_TCP && TCP_LISTEN_BACKLOG && (TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff))
#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t" #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
#endif #endif
...@@ -259,6 +259,11 @@ lwip_sanity_check(void) ...@@ -259,6 +259,11 @@ lwip_sanity_check(void)
void void
lwip_init(void) lwip_init(void)
{ {
MEMP_NUM_TCP_PCB = 5;
TCP_WND = (4 * TCP_MSS);
TCP_MAXRTX = 3;
TCP_SYNMAXRTX = 6;
/* Sanity check user-configurable values */ /* Sanity check user-configurable values */
lwip_sanity_check(); lwip_sanity_check();
...@@ -294,7 +299,6 @@ lwip_init(void) ...@@ -294,7 +299,6 @@ lwip_init(void)
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */
#if LWIP_TCP #if LWIP_TCP
MEMP_NUM_TCP_PCB = 5;
tcp_init(); tcp_init();
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
......
...@@ -145,7 +145,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) ...@@ -145,7 +145,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip)
LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL); LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL);
/* clear data structure */ /* clear data structure */
memset(autoip, 0, sizeof(struct autoip)); os_memset(autoip, 0, sizeof(struct autoip));
/* autoip->state = AUTOIP_STATE_OFF; */ /* autoip->state = AUTOIP_STATE_OFF; */
netif->autoip = autoip; netif->autoip = autoip;
} }
...@@ -319,7 +319,7 @@ autoip_start(struct netif *netif) ...@@ -319,7 +319,7 @@ autoip_start(struct netif *netif)
("autoip_start(): could not allocate autoip\n")); ("autoip_start(): could not allocate autoip\n"));
return ERR_MEM; return ERR_MEM;
} }
memset(autoip, 0, sizeof(struct autoip)); os_memset(autoip, 0, sizeof(struct autoip));
/* store this AutoIP client in the netif */ /* store this AutoIP client in the netif */
netif->autoip = autoip; netif->autoip = autoip;
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip"));
......
...@@ -133,7 +133,13 @@ ip_route(ip_addr_t *dest) ...@@ -133,7 +133,13 @@ ip_route(ip_addr_t *dest)
/* return netif on which to forward IP packet */ /* return netif on which to forward IP packet */
return netif; return netif;
} }
if (!ip_addr_isbroadcast(dest, netif) && netif != netif_default) { }
}
/* iterate through netifs */
for(netif = netif_list; netif != NULL; netif = netif->next) {
/* network mask matches? */
if (netif_is_up(netif)) {
if (!ip_addr_isbroadcast(dest, netif) && netif == (struct netif *)eagle_lwip_getif(0)) {
return netif; return netif;
} }
} }
...@@ -669,7 +675,7 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, ...@@ -669,7 +675,7 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
MEMCPY(p->payload, ip_options, optlen); MEMCPY(p->payload, ip_options, optlen);
if (optlen < optlen_aligned) { if (optlen < optlen_aligned) {
/* zero the remaining bytes */ /* zero the remaining bytes */
memset(((char*)p->payload) + optlen, 0, optlen_aligned - optlen); os_memset(((char*)p->payload) + optlen, 0, optlen_aligned - optlen);
} }
#if CHECKSUM_GEN_IP_INLINE #if CHECKSUM_GEN_IP_INLINE
for (i = 0; i < optlen_aligned/2; i++) { for (i = 0; i < optlen_aligned/2; i++) {
......
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
#include "lwip/netif.h" #include "lwip/netif.h"
/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */ /* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
const ip_addr_t ip_addr_any = { IPADDR_ANY }; const ip_addr_t ip_addr_any ICACHE_RODATA_ATTR = { IPADDR_ANY };
const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST }; const ip_addr_t ip_addr_broadcast ICACHE_RODATA_ATTR = { IPADDR_BROADCAST };
/** /**
* Determine if an address is a broadcast address on a network interface * Determine if an address is a broadcast address on a network interface
...@@ -154,6 +154,9 @@ ipaddr_aton(const char *cp, ip_addr_t *addr) ...@@ -154,6 +154,9 @@ ipaddr_aton(const char *cp, ip_addr_t *addr)
u32_t val; u32_t val;
u8_t base; u8_t base;
char c; char c;
char ch;
unsigned long cutoff;
int cutlim;
u32_t parts[4]; u32_t parts[4];
u32_t *pp = parts; u32_t *pp = parts;
...@@ -176,11 +179,25 @@ ipaddr_aton(const char *cp, ip_addr_t *addr) ...@@ -176,11 +179,25 @@ ipaddr_aton(const char *cp, ip_addr_t *addr)
} else } else
base = 8; base = 8;
} }
cutoff =(unsigned long)0xffffffff / (unsigned long)base;
cutlim =(unsigned long)0xffffffff % (unsigned long)base;
for (;;) { for (;;) {
if (isdigit(c)) { if (isdigit(c)) {
ch = (int)(c - '0');
if (val > cutoff || (val == cutoff && ch > cutlim))
return (0);
val = (val * base) + (int)(c - '0'); val = (val * base) + (int)(c - '0');
c = *++cp; c = *++cp;
} else if (base == 16 && isxdigit(c)) { } else if (base == 16 && isxdigit(c)) {
ch = (int)(c + 10 - (islower(c) ? 'a' : 'A'));
if (val > cutoff || (val == cutoff && ch > cutlim))
return (0);
val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A')); val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp; c = *++cp;
} else } else
...@@ -220,21 +237,21 @@ ipaddr_aton(const char *cp, ip_addr_t *addr) ...@@ -220,21 +237,21 @@ ipaddr_aton(const char *cp, ip_addr_t *addr)
break; break;
case 2: /* a.b -- 8.24 bits */ case 2: /* a.b -- 8.24 bits */
if (val > 0xffffffUL) { if ((val > 0xffffffUL) || (parts[0] > 0xff)) {
return (0); return (0);
} }
val |= parts[0] << 24; val |= parts[0] << 24;
break; break;
case 3: /* a.b.c -- 8.8.16 bits */ case 3: /* a.b.c -- 8.8.16 bits */
if (val > 0xffff) { if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) {
return (0); return (0);
} }
val |= (parts[0] << 24) | (parts[1] << 16); val |= (parts[0] << 24) | (parts[1] << 16);
break; break;
case 4: /* a.b.c.d -- 8.8.8.8 bits */ case 4: /* a.b.c.d -- 8.8.8.8 bits */
if (val > 0xff) { if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) {
return (0); return (0);
} }
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
......
...@@ -284,7 +284,7 @@ ip_reass_enqueue_new_datagram(struct ip_hdr *fraghdr, int clen) ...@@ -284,7 +284,7 @@ ip_reass_enqueue_new_datagram(struct ip_hdr *fraghdr, int clen)
return NULL; return NULL;
} }
} }
memset(ipr, 0, sizeof(struct ip_reassdata)); os_memset(ipr, 0, sizeof(struct ip_reassdata));
ipr->timer = IP_REASS_MAXAGE; ipr->timer = IP_REASS_MAXAGE;
/* enqueue the new structure to the front of the list */ /* enqueue the new structure to the front of the list */
......
This diff is collapsed.
...@@ -636,7 +636,7 @@ void *mem_calloc(mem_size_t count, mem_size_t size) ...@@ -636,7 +636,7 @@ void *mem_calloc(mem_size_t count, mem_size_t size)
p = mem_malloc(count * size); p = mem_malloc(count * size);
if (p) { if (p) {
/* zero the memory */ /* zero the memory */
memset(p, 0, count * size); os_memset(p, 0, count * size);
} }
return p; return p;
} }
......
...@@ -126,7 +126,7 @@ static struct memp *memp_tab[MEMP_MAX]; ...@@ -126,7 +126,7 @@ static struct memp *memp_tab[MEMP_MAX];
#if !MEM_USE_POOLS && !MEMP_MEM_MALLOC #if !MEM_USE_POOLS && !MEMP_MEM_MALLOC
static static
#endif #endif
const u16_t memp_sizes[MEMP_MAX] = { //LWIP_MEM_ALIGN_SIZE const u32_t memp_sizes[MEMP_MAX] ICACHE_RODATA_ATTR = { //LWIP_MEM_ALIGN_SIZE
#define LWIP_MEMPOOL(name,num,size,desc,attr) LWIP_MEM_ALIGN_SIZE(size), #define LWIP_MEMPOOL(name,num,size,desc,attr) LWIP_MEM_ALIGN_SIZE(size),
#include "lwip/memp_std.h" #include "lwip/memp_std.h"
}; };
...@@ -320,11 +320,11 @@ memp_overflow_init(void) ...@@ -320,11 +320,11 @@ memp_overflow_init(void)
for (j = 0; j < memp_num[i]; ++j) { for (j = 0; j < memp_num[i]; ++j) {
#if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0
m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED;
memset(m, 0xcd, MEMP_SANITY_REGION_BEFORE_ALIGNED); os_memset(m, 0xcd, MEMP_SANITY_REGION_BEFORE_ALIGNED);
#endif #endif
#if MEMP_SANITY_REGION_AFTER_ALIGNED > 0 #if MEMP_SANITY_REGION_AFTER_ALIGNED > 0
m = (u8_t*)p + MEMP_SIZE + memp_sizes[i]; m = (u8_t*)p + MEMP_SIZE + memp_sizes[i];
memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED); os_memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED);
#endif #endif
p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED); p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED);
} }
......
...@@ -149,6 +149,7 @@ netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ...@@ -149,6 +149,7 @@ netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
#if LWIP_DHCP #if LWIP_DHCP
/* netif not under DHCP control by default */ /* netif not under DHCP control by default */
netif->dhcp = NULL; netif->dhcp = NULL;
netif->dhcps_pcb = NULL;
#endif /* LWIP_DHCP */ #endif /* LWIP_DHCP */
#if LWIP_AUTOIP #if LWIP_AUTOIP
/* netif not under AutoIP control by default */ /* netif not under AutoIP control by default */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment