1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

Update SDK to 2.0.0

- Update SDK header files and libraries to SDK 2.0.0 plus 2.0.0_16_08_09
  patch
- Remove mem_manager.o from libmain.a (replaced with umm_malloc)
- Disable switch from DIO to QIO mode for certain flash chips (saves
  IRAM space)
- Add user_rf_cal_sector_set; it points to rf_init_data sector.
- Change the way rf_init_data is spoofed.
  This is now done by wrapping spi_flash_read and returning the data we
  need during startup sequence.
- Place lwip library into flash using linker script instead of section
  attributes (saves IRAM space)
This commit is contained in:
Ivan Grokhotkov
2016-08-26 11:05:28 +08:00
committed by Ivan Grokhotkov
parent 61787b23af
commit ae13809c81
46 changed files with 793 additions and 121 deletions

View File

@ -92,10 +92,12 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele
} else {
if (plist == pdelete){
*phead = plist->pnext;
pdelete->pnext = NULL;
} else {
while (plist != NULL) {
if (plist->pnext == pdelete){
plist->pnext = pdelete->pnext;
pdelete->pnext = NULL;
}
plist = plist->pnext;
}
@ -269,7 +271,10 @@ static void ICACHE_FLASH_ATTR create_msg(struct dhcps_msg *m)
os_memset((char *) m->file, 0, sizeof(m->file));
os_memset((char *) m->options, 0, sizeof(m->options));
os_memcpy((char *) m->options, &magic_cookie, sizeof(magic_cookie));
//For xiaomi crash bug
uint32 magic_cookie1 = magic_cookie;
os_memcpy((char *) m->options, &magic_cookie1, sizeof(magic_cookie1));
}
///////////////////////////////////////////////////////////////////////////////////
/*
@ -760,11 +765,18 @@ void ICACHE_FLASH_ATTR dhcps_stop(void)
//udp_remove(pcb_dhcps);
list_node *pnode = NULL;
list_node *pback_node = NULL;
struct dhcps_pool* dhcp_node = NULL;
struct ip_addr ip_zero;
os_memset(&ip_zero,0x0,sizeof(ip_zero));
pnode = plist;
while (pnode != NULL) {
pback_node = pnode;
pnode = pback_node->pnext;
node_remove_from_list(&plist, pback_node);
dhcp_node = (struct dhcps_pool*)pback_node->pnode;
//wifi_softap_dhcps_client_leave(dhcp_node->mac,&dhcp_node->ip,TRUE); // force to delete
wifi_softap_set_station_info(dhcp_node->mac, &ip_zero);
os_free(pback_node->pnode);
pback_node->pnode = NULL;
os_free(pback_node);
@ -1077,10 +1089,10 @@ uint32 ICACHE_FLASH_ATTR wifi_softap_dhcps_client_update(u8 *bssid, struct ip_ad
return IPADDR_ANY;
}
} else {
if (start_ip == end_ip) {
if (start_ip > end_ip) {
return IPADDR_ANY;
}
start_ip = htonl((ntohl(start_ip) + 1));
//start_ip = htonl((ntohl(start_ip) + 1));
flag = TRUE;
}
}
@ -1096,6 +1108,8 @@ uint32 ICACHE_FLASH_ATTR wifi_softap_dhcps_client_update(u8 *bssid, struct ip_ad
// mac exists and ip exists in other node,delete mac
node_remove_from_list(&plist,pmac_node);
os_free(pmac_node->pnode);
pmac_node->pnode = NULL;
os_free(pmac_node);
pmac_node = pip_node;
os_memcpy(pdhcps_pool->mac, bssid, sizeof(pdhcps_pool->mac));
@ -1144,6 +1158,10 @@ uint32 ICACHE_FLASH_ATTR wifi_softap_dhcps_client_update(u8 *bssid, struct ip_ad
os_free(pdhcps_pool);
return IPADDR_ANY;
}
if (pdhcps_pool->ip.addr > end_ip) {
os_free(pdhcps_pool);
return IPADDR_ANY;
}
os_memcpy(pdhcps_pool->mac, bssid, sizeof(pdhcps_pool->mac));
pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER;
pdhcps_pool->type = type;

View File

@ -35,6 +35,8 @@ remot_info premot[linkMax];
struct espconn_packet pktinfo[2];
void espconn_init(void);
static uint8 espconn_tcp_get_buf_count(espconn_buf *pesp_buf);
/******************************************************************************
* FunctionName : espconn_copy_partial
@ -266,6 +268,8 @@ espconn_connect(struct espconn *espconn)
espconn_msg *plist = NULL;
remot_info *pinfo = NULL;
volatile int tmp = (int) espconn_init;
if (espconn == NULL) {
return ESPCONN_ARG;
} else if (espconn ->type != ESPCONN_TCP)
@ -336,6 +340,8 @@ espconn_create(struct espconn *espconn)
sint8 value = ESPCONN_OK;
espconn_msg *plist = NULL;
volatile int tmp = (int) espconn_init;
if (espconn == NULL) {
return ESPCONN_ARG;
} else if (espconn ->type != ESPCONN_UDP){
@ -436,6 +442,39 @@ espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)
return ESPCONN_ARG;
}
sint16 ICACHE_FLASH_ATTR espconn_recv(struct espconn *espconn, void *mem, size_t len)
{
espconn_msg *pnode = NULL;
bool value = false;
int bytes_used = 0;
if (espconn == NULL || mem == NULL || len == 0)
return ESPCONN_ARG;
/*Find the node depend on the espconn message*/
value = espconn_find_connection(espconn, &pnode);
if (value && espconn->type == ESPCONN_TCP){
if (pnode->readbuf != NULL){
bytes_used = ringbuf_bytes_used(pnode->readbuf);
if (bytes_used != 0) {
if (len > bytes_used) {
len = bytes_used;
}
ringbuf_memcpy_from(mem, pnode->readbuf, len);
espconn_recv_unhold(pnode->pespconn);
return len;
} else {
return ESPCONN_OK;
}
} else{
return ESPCONN_OK;
}
} else{
return ESPCONN_ARG;
}
return ESPCONN_ARG;
}
/******************************************************************************
* FunctionName : espconn_sendto
* Description : send data for UDP
@ -877,6 +916,8 @@ espconn_accept(struct espconn *espconn)
sint8 value = ESPCONN_OK;
espconn_msg *plist = NULL;
volatile int tmp = (int) espconn_init;
if (espconn == NULL) {
return ESPCONN_ARG;
} else if (espconn ->type != ESPCONN_TCP)

View File

@ -0,0 +1,205 @@
/*
* espconn_buf.c
*
* Created on: May 25, 2016
* Author: liuhan
*/
#include "lwip/memp.h"
#include "lwip/def.h"
#include "ets_sys.h"
#include "os_type.h"
#include "lwip/app/espconn_buf.h"
#ifdef MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#endif
#if (!defined(lwIP_unlikely))
#define lwIP_unlikely(Expression) !!(Expression)
#endif
#define lwIP_ASSERT(Expression) do{if(!(Expression)) {os_printf("%s %d\n", __func__, __LINE__);return;}}while(0)
ringbuf_t ringbuf_new(size_t capacity)
{
ringbuf_t rb = (ringbuf_t)os_zalloc(sizeof(struct ringbuf_t));
if (rb){
rb->size = capacity + 1;
rb->buf = (uint8*)os_zalloc(rb->size);
if (rb->buf){
ringbuf_reset(rb);
}else{
os_free(rb);
return NULL;
}
}
return rb;
}
size_t ringbuf_buffer_size(const struct ringbuf_t *rb)
{
return rb->size;
}
void ringbuf_reset(ringbuf_t rb)
{
rb ->head = rb->tail = rb->buf;
}
void ringbuf_free(ringbuf_t *rb)
{
lwIP_ASSERT(rb && *rb);
os_free((*rb)->buf);
os_free(*rb);
*rb = NULL;
}
size_t ringbuf_capacity(const struct ringbuf_t *rb)
{
return ringbuf_buffer_size(rb) - 1;
}
static const uint8_t* ringbuf_end(const struct ringbuf_t *rb)
{
return rb->buf + ringbuf_buffer_size(rb);
}
size_t ringbuf_bytes_free(const struct ringbuf_t *rb)
{
if (rb->head >= rb->tail){
return ringbuf_capacity(rb) - (rb->head - rb->tail);
}else{
return rb->tail - rb->head -1;
}
}
size_t ringbuf_bytes_used(const struct ringbuf_t *rb)
{
return ringbuf_capacity(rb) - ringbuf_bytes_free(rb);
}
int ringbuf_is_full(const struct ringbuf_t *rb)
{
return ringbuf_bytes_free(rb) == 0;
}
int ringbuf_is_empty(const struct ringbuf_t *rb)
{
return ringbuf_bytes_free(rb) == ringbuf_capacity(rb);
}
const void* ringbuf_tail(const struct ringbuf_t *rb)
{
return rb->tail;
}
const void* ringbuf_head(const struct ringbuf_t *rb)
{
return rb->head;
}
static uint8_t *ringbuf_nextp(ringbuf_t rb, const uint8_t *p)
{
lwIP_ASSERT((p >= rb->buf) && (p < ringbuf_end(rb)));
return rb->buf + ((++p -rb->buf) % ringbuf_buffer_size(rb));
}
size_t ringbuf_findchr(const struct ringbuf_t *rb, int c, size_t offset)
{
const uint8_t *bufend = ringbuf_end(rb);
size_t bytes_used = ringbuf_bytes_used(rb);
if (offset >= bytes_used)
return bytes_used;
const uint8_t *start = rb ->buf + (((rb->tail - rb->buf) + offset) % ringbuf_buffer_size(rb));
lwIP_ASSERT(bufend > start);
size_t n = LWIP_MIN(bufend - start, bytes_used - offset);
const uint8_t *found = (const uint8_t *)memchr(start, c, n);
if (found)
return offset + (found - start);
else
return ringbuf_findchr(rb, c, offset + n);
}
size_t ringbuf_memset(ringbuf_t dst, int c, size_t len)
{
const uint8_t *bufend = ringbuf_end(dst);
size_t nwritten = 0;
size_t count = LWIP_MIN(len, ringbuf_buffer_size(dst));
int overflow = count > ringbuf_bytes_free(dst);
while (nwritten != count){
lwIP_ASSERT(bufend > dst->head);
size_t n = LWIP_MIN(bufend - dst->head, count - nwritten);
os_memset(dst->head, c, n);
dst->head += n;
nwritten += n;
if (dst->head == bufend)
dst->head = dst->buf;
}
if (overflow){
dst->tail = ringbuf_nextp(dst, dst->head);
lwIP_ASSERT(ringbuf_is_full(dst));
}
return nwritten;
}
void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count)
{
const uint8_t *u8src = src;
const uint8_t *bufend = ringbuf_end(dst);
int overflow = count > ringbuf_bytes_free(dst);
size_t nread = 0;
while (nread != count){
lwIP_ASSERT(bufend > dst->head);
size_t n = LWIP_MIN(bufend - dst->head, count - nread);
os_memcpy(dst->head, u8src + nread, n);
dst->head += n;
nread += n;
if (dst->head == bufend)
dst->head = dst->buf;
}
if (overflow) {
dst->tail = ringbuf_nextp(dst, dst->head);
lwIP_ASSERT(ringbuf_is_full(dst));
}
return dst->head;
}
void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count)
{
size_t bytes_used = ringbuf_bytes_used(src);
if (count > bytes_used)
return NULL;
const uint8_t *u8dst = dst;
const uint8_t *bufend = ringbuf_end(src);
size_t nwritten = 0;
while (nwritten != count){
lwIP_ASSERT(bufend > src->tail);
size_t n = LWIP_MIN(bufend - src->tail, count - nwritten);
os_memcpy((uint8_t*)u8dst + nwritten, src->tail, n);
src->tail += n;
nwritten += n;
if (src->tail == bufend)
src->tail = src->buf;
}
lwIP_ASSERT(count + ringbuf_bytes_used(src) == bytes_used);
return src->tail;
}

View File

@ -239,6 +239,10 @@ void ICACHE_FLASH_ATTR espconn_tcp_memp_free(espconn_msg *pmemp)
os_free(pmemp->pespconn);
pmemp->pespconn = NULL;
}
if (pmemp->readbuf != NULL){
ringbuf_free(&pmemp->readbuf);
}
os_free(pmemp);
pmemp = NULL;
}
@ -397,34 +401,46 @@ espconn_tcp_disconnect_successful(void *arg)
static void ICACHE_FLASH_ATTR
espconn_Task(os_event_t *events)
{
espconn_msg *plist = NULL;
bool active_flag = false;
espconn_msg *task_msg = NULL;
struct espconn *pespconn = NULL;
task_msg = (espconn_msg *) events->par;
switch (events->sig) {
case SIG_ESPCONN_WRITE: {
pespconn = task_msg->pespconn;
if (pespconn == NULL) {
return;
}
if (pespconn->proto.tcp->write_finish_fn != NULL) {
pespconn->proto.tcp->write_finish_fn(pespconn);
}
/*find the active connection node*/
for (plist = plink_active; plist != NULL; plist = plist->pnext){
if (task_msg == plist) {
active_flag = true;
break;
}
}
if (active_flag){
switch (events->sig) {
case SIG_ESPCONN_WRITE: {
pespconn = task_msg->pespconn;
if (pespconn == NULL) {
return;
}
if (pespconn->proto.tcp->write_finish_fn != NULL) {
pespconn->proto.tcp->write_finish_fn(pespconn);
}
}
break;
case SIG_ESPCONN_ERRER:
/*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg);
espconn_tcp_reconnect(task_msg);
break;
case SIG_ESPCONN_CLOSE:
/*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg);
espconn_tcp_disconnect_successful(task_msg);
break;
default:
break;
}
break;
case SIG_ESPCONN_ERRER:
/*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg);
espconn_tcp_reconnect(task_msg);
break;
case SIG_ESPCONN_CLOSE:
/*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg);
espconn_tcp_disconnect_successful(task_msg);
break;
default:
break;
}
}
@ -478,9 +494,13 @@ espconn_tcp_sent(void *arg, uint8 *psent, uint16 length)
err = tcp_write(pcb, psent, len, 0);
if (err == ERR_MEM) {
len /= 2;
if(len < 3)
len--;
else
len /= 2;
}
} while (err == ERR_MEM && len > 1);
} while (err == ERR_MEM && len > 0);
/*Find out what we can send and send it, offset the buffer point for next send*/
if (err == ERR_OK) {
@ -615,7 +635,37 @@ espconn_recv_unhold(struct espconn *pespconn)
}
//***********Code for WIFI_BLOCK from upper**************
sint8 ICACHE_FLASH_ATTR
espconn_lock_recv(espconn_msg *plockmsg)
{
if (plockmsg == NULL || plockmsg->pespconn == NULL) {
return ESPCONN_ARG;
}
if (plockmsg->pespconn->recv_callback == NULL){
if (plockmsg->readbuf == NULL){
plockmsg->readbuf = ringbuf_new(TCP_WND);
if (plockmsg->readbuf == NULL)
return ESPCONN_MEM;
}
return espconn_recv_hold(plockmsg->pespconn);
}
return ESPCONN_OK;
}
sint8 ICACHE_FLASH_ATTR
espconn_unlock_recv(espconn_msg *punlockmsg)
{
if (punlockmsg == NULL || punlockmsg->pespconn == NULL) {
return ESPCONN_ARG;
}
if (punlockmsg->pespconn->recv_callback != NULL)
return espconn_recv_unhold(punlockmsg->pespconn);
return ESPCONN_OK;
}
/******************************************************************************
* FunctionName : espconn_client_recv
* Description : Data has been received on this pcb.
@ -631,6 +681,8 @@ espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
espconn_msg *precv_cb = arg;
tcp_arg(pcb, arg);
/*lock the window because of application layer don't need the data*/
espconn_lock_recv(precv_cb);
if (p != NULL) {
/*To update and advertise a larger window*/
@ -640,30 +692,38 @@ espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
precv_cb->recv_holded_buf_Len += p->tot_len;
}
if (err == ERR_OK && p != NULL) {
char *pdata = NULL;
u16_t length = 0;
/*Copy the contents of a packet buffer to an application buffer.
*to prevent memory leaks, ensure that each allocated is deleted*/
pdata = (char *)os_zalloc(p ->tot_len + 1);
length = pbuf_copy_partial(p, pdata, p ->tot_len, 0);
pbuf_free(p);
if (precv_cb->pespconn->recv_callback != NULL){
if (err == ERR_OK && p != NULL) {
char *pdata = NULL;
u16_t length = 0;
/*Copy the contents of a packet buffer to an application buffer.
*to prevent memory leaks, ensure that each allocated is deleted*/
pdata = (char *)os_zalloc(p ->tot_len + 1);
length = pbuf_copy_partial(p, pdata, p ->tot_len, 0);
pbuf_free(p);
if (length != 0) {
/*switch the state of espconn for application process*/
precv_cb->pespconn ->state = ESPCONN_READ;
precv_cb->pcommon.pcb = pcb;
if (precv_cb->pespconn->recv_callback != NULL) {
precv_cb->pespconn->recv_callback(precv_cb->pespconn, pdata, length);
}
/*switch the state of espconn for next packet copy*/
if (pcb->state == ESTABLISHED)
precv_cb->pespconn ->state = ESPCONN_CONNECT;
}
if (length != 0) {
/*switch the state of espconn for application process*/
precv_cb->pespconn ->state = ESPCONN_READ;
precv_cb->pcommon.pcb = pcb;
precv_cb->pespconn->recv_callback(precv_cb->pespconn, pdata, length);
/*to prevent memory leaks, ensure that each allocated is deleted*/
os_free(pdata);
pdata = NULL;
/*switch the state of espconn for next packet copy*/
if (pcb->state == ESTABLISHED)
precv_cb->pespconn ->state = ESPCONN_CONNECT;
}
/*to prevent memory leaks, ensure that each allocated is deleted*/
os_free(pdata);
pdata = NULL;
}
} else{
/*unregister receive function*/
struct pbuf *pthis = NULL;
for (pthis = p; pthis != NULL; pthis = pthis->next) {
ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
pbuf_free(pthis);
}
}
if (err == ERR_OK && p == NULL) {
@ -877,6 +937,8 @@ espconn_client_connect(void *arg, struct tcp_pcb *tpcb, err_t err)
if (espconn_keepalive_disabled(pcon))
espconn_keepalive_enable(tpcb);
// /*lock the window because of application layer don't need the data*/
// espconn_lock_recv(pcon);
} else{
os_printf("err in host connected (%s)\n",lwip_strerr(err));
}
@ -1015,6 +1077,9 @@ espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
tcp_arg(pcb, arg);
espconn_printf("server has application data received: %d\n", system_get_free_heap_size());
/*lock the window because of application layer don't need the data*/
espconn_lock_recv(precv_cb);
if (p != NULL) {
/*To update and advertise a larger window*/
if(precv_cb->recv_hold_flag == 0)
@ -1023,42 +1088,47 @@ espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
precv_cb->recv_holded_buf_Len += p->tot_len;
}
if (err == ERR_OK && p != NULL) {
u8_t *data_ptr = NULL;
u32_t data_cntr = 0;
/*clear the count for connection timeout*/
precv_cb->pcommon.recv_check = 0;
/*Copy the contents of a packet buffer to an application buffer.
*to prevent memory leaks, ensure that each allocated is deleted*/
data_ptr = (u8_t *)os_zalloc(p ->tot_len + 1);
data_cntr = pbuf_copy_partial(p, data_ptr, p ->tot_len, 0);
pbuf_free(p);
/*register receive function*/
if (precv_cb->pespconn->recv_callback != NULL) {
if (err == ERR_OK && p != NULL) {
u8_t *data_ptr = NULL;
u32_t data_cntr = 0;
/*clear the count for connection timeout*/
precv_cb->pcommon.recv_check = 0;
/*Copy the contents of a packet buffer to an application buffer.
*to prevent memory leaks, ensure that each allocated is deleted*/
data_ptr = (u8_t *) os_zalloc(p ->tot_len + 1);
data_cntr = pbuf_copy_partial(p, data_ptr, p->tot_len, 0);
pbuf_free(p);
if (data_cntr != 0) {
/*switch the state of espconn for application process*/
precv_cb->pespconn ->state = ESPCONN_READ;
precv_cb->pcommon.pcb = pcb;
if (precv_cb->pespconn->recv_callback != NULL) {
precv_cb->pespconn->recv_callback(precv_cb->pespconn, data_ptr, data_cntr);
}
if (data_cntr != 0) {
/*switch the state of espconn for application process*/
precv_cb->pespconn->state = ESPCONN_READ;
precv_cb->pcommon.pcb = pcb;
precv_cb->pespconn->recv_callback(precv_cb->pespconn, data_ptr, data_cntr);
/*switch the state of espconn for next packet copy*/
if (pcb->state == ESTABLISHED)
precv_cb->pespconn ->state = ESPCONN_CONNECT;
}
/*switch the state of espconn for next packet copy*/
if (pcb->state == ESTABLISHED)
precv_cb->pespconn->state = ESPCONN_CONNECT;
}
/*to prevent memory leaks, ensure that each allocated is deleted*/
os_free(data_ptr);
data_ptr = NULL;
espconn_printf("server's application data has been processed: %d\n", system_get_free_heap_size());
} else {
if (p != NULL) {
pbuf_free(p);
}
espconn_server_close(precv_cb, pcb,0);
}
/*to prevent memory leaks, ensure that each allocated is deleted*/
os_free(data_ptr);
data_ptr = NULL;
espconn_printf("server's application data has been processed: %d\n", system_get_free_heap_size());
}
} else {
/*unregister receive function*/
struct pbuf *pthis = NULL;
for (pthis = p; pthis != NULL; pthis = pthis->next) {
ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
pbuf_free(pthis);
}
}
if (err == ERR_OK && p == NULL) {
espconn_server_close(precv_cb, pcb, 0);
}
return ERR_OK;
}
@ -1292,6 +1362,8 @@ espconn_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err)
if (espconn_keepalive_disabled(paccept))
espconn_keepalive_enable(pcb);
// /*lock the window because of application layer don't need the data*/
// espconn_lock_recv(paccept);
return ERR_OK;
}

View File

@ -94,8 +94,8 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
return ESPCONN_ARG;
}
if (1470 < length) {
datalen = 1470;
if ((IP_FRAG_MAX_MTU - 20 - 8) < length) {
datalen = IP_FRAG_MAX_MTU - 20 - 8;
} else {
datalen = length;
}
@ -200,8 +200,8 @@ espconn_udp_sendto(void *arg, uint8 *psent, uint16 length)
return ESPCONN_ARG;
}
if (1470 < length) {
datalen = 1470;
if ((IP_FRAG_MAX_MTU - 20 - 8) < length) {
datalen = IP_FRAG_MAX_MTU - 20 - 8;
} else {
datalen = length;
}

6
tools/sdk/lwip/src/core/dhcp.c Normal file → Executable file
View File

@ -1096,12 +1096,12 @@ dhcp_renew(struct netif *netif)
}
#endif /* LWIP_NETIF_HOSTNAME */
#if 0
#if 1
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));
#endif
#if 0
#if 1
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr));
#endif
@ -1159,7 +1159,7 @@ dhcp_rebind(struct netif *netif)
}
#endif /* LWIP_NETIF_HOSTNAME */
#if 0
#if 1
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));

14
tools/sdk/lwip/src/core/dns.c Normal file → Executable file
View File

@ -227,7 +227,7 @@ static ip_addr_t dns_servers[DNS_MAX_SERVERS];
/** Contiguous buffer for processing responses */
//static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];
static u8_t* dns_payload;
static u8_t dns_random;
static u16_t dns_random;
/**
* Initialize the resolver: set up the UDP pcb and configure the default server
* (DNS_SERVER_ADDRESS).
@ -570,7 +570,7 @@ dns_send(u8_t numdns, const char* name, u8_t id)
char *query, *nptr;
const char *pHostname;
u8_t n;
dns_random = os_random()%250;
dns_random = os_random()>>16;
LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
(u16_t)(numdns), name));
LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS);
@ -698,7 +698,7 @@ dns_check_entry(u8_t i)
case DNS_STATE_DONE: {
/* if the time to live is nul */
if (--pEntry->ttl == 0) {
if ((pEntry->ttl == 0) || (--pEntry->ttl == 0)) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
/* flush this entry */
pEntry->state = DNS_STATE_UNUSED;
@ -825,6 +825,13 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t
if (pEntry->found) {
(*pEntry->found)(pEntry->name, &pEntry->ipaddr, pEntry->arg);
}
if (pEntry->ttl == 0) {
/* RFC 883, page 29: "Zero values are
interpreted to mean that the RR can only be used for the
transaction in progress, and should not be cached."
-> flush this entry now */
goto flushentry;
}
/* deallocate memory and return */
goto memerr;
} else {
@ -847,6 +854,7 @@ responseerr:
if (pEntry->found) {
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
}
flushentry:
/* flush this entry */
pEntry->state = DNS_STATE_UNUSED;
pEntry->found = NULL;

View File

@ -149,7 +149,7 @@ static err_t igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest,
static void igmp_send(struct igmp_group *group, u8_t type)ICACHE_FLASH_ATTR;
static struct igmp_group* igmp_group_list;
static struct igmp_group* igmp_group_list = NULL;
static ip_addr_t allsystems;
static ip_addr_t allrouters;

View File

@ -486,6 +486,10 @@ void netif_set_up(struct netif *netif)
*/
void netif_set_down(struct netif *netif)
{
if (netif == NULL) {
return;
}
if (netif->flags & NETIF_FLAG_UP) {
netif->flags &= ~NETIF_FLAG_UP;
#if LWIP_SNMP

93
tools/sdk/lwip/src/core/sntp.c Normal file → Executable file
View File

@ -51,7 +51,7 @@
#include "lwip/dns.h"
#include "lwip/ip_addr.h"
#include "lwip/pbuf.h"
#include "lwip/app/time.h"
//#include <string.h>
#if LWIP_UDP
@ -148,14 +148,18 @@
#endif
/** SNTP macro to change system time including microseconds */
#ifdef SNTP_SET_SYSTEM_TIME_US
#define SNTP_CALC_TIME_US 1
#define SNTP_RECEIVE_TIME_SIZE 2
#else
#define SNTP_SET_SYSTEM_TIME_US(sec, us)
#define SNTP_CALC_TIME_US 0
#define SNTP_RECEIVE_TIME_SIZE 1
#endif
uint8 sntp_receive_time_size = 1;
#define SNTP_RECEIVE_TIME_SIZE sntp_receive_time_size
#define SNTP_SET_SYSTEM_TIME_US(sec, us) sntp_update_rtc(sec, us)
//#ifdef SNTP_SET_SYSTEM_TIME_US
//#define SNTP_SET_SYSTEM_TIME_US(sec, us) sntp_update_rtc(sec, us)
//#define SNTP_CALC_TIME_US 1
//#define SNTP_RECEIVE_TIME_SIZE 2
//#else
//#define SNTP_SET_SYSTEM_TIME_US(sec, us)
//#define SNTP_CALC_TIME_US 0
//#define SNTP_RECEIVE_TIME_SIZE sntp_receive_time_size
//#endif
/** SNTP macro to get system time, used with SNTP_CHECK_RESPONSE >= 2
* to send in request and compare in response.
@ -295,10 +299,12 @@ static ip_addr_t sntp_last_server_address;
* to compare against in response */
static u32_t sntp_last_timestamp_sent[2];
#endif /* SNTP_CHECK_RESPONSE >= 2 */
typedef long time_t;
//uint32 current_stamp_1 = 0;
//uint32 current_stamp_2 = 0;
uint32 realtime_stamp = 0;
static bool sntp_time_flag = false;
static uint32 sntp_update_delay = SNTP_UPDATE_DELAY;
static uint32 realtime_stamp = 0;
LOCAL os_timer_t sntp_timer;
/*****************************************/
#define SECSPERMIN 60L
@ -643,13 +649,24 @@ bool ICACHE_FLASH_ATTR
sntp_set_timezone(sint8 timezone)
{
if(timezone >= -11 || timezone <= 13) {
time_zone = timezone;
if (sntp_get_timetype()){
RTC_TZ_SET(time_zone);
} else
time_zone = timezone;
return true;
} else {
return false;
}
}
void ICACHE_FLASH_ATTR sntp_set_daylight(int daylight)
{
if (sntp_get_timetype()){
RTC_DST_SET(daylight);
}
}
void ICACHE_FLASH_ATTR
sntp_time_inc(void)
{
@ -665,7 +682,22 @@ sntp_process(u32_t *receive_timestamp)
* @todo: if MSB is 1, SNTP time is 2036-based!
*/
time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970);
if (sntp_get_timetype()){
u32_t us = ntohl(receive_timestamp[1]) / 4295;
SNTP_SET_SYSTEM_TIME_US(t, us);
/* display local time from GMT time */
LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&t), us));
} else{
/* change system time and/or the update the RTC clock */
SNTP_SET_SYSTEM_TIME(t);
/* display local time from GMT time */
t += time_zone * 60 * 60;// format GMT + time_zone TIME ZONE
realtime_stamp = t;
os_timer_disarm(&sntp_timer);
os_timer_setfn(&sntp_timer, (os_timer_func_t *)sntp_time_inc, NULL);
os_timer_arm(&sntp_timer, 1000, 1);
}
#if 0
#if SNTP_CALC_TIME_US
u32_t us = ntohl(receive_timestamp[1]) / 4295;
SNTP_SET_SYSTEM_TIME_US(t, us);
@ -682,10 +714,8 @@ sntp_process(u32_t *receive_timestamp)
os_timer_disarm(&sntp_timer);
os_timer_setfn(&sntp_timer, (os_timer_func_t *)sntp_time_inc, NULL);
os_timer_arm(&sntp_timer, 1000, 1);
os_printf("%s\n",sntp_asctime(sntp_localtime (&t)));
// os_printf("%s\n",ctime(&t));
// LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s", ctime(&t)));
#endif /* SNTP_CALC_TIME_US */
#endif
}
/**
@ -856,9 +886,9 @@ sntp_recv(void *arg, struct udp_pcb* pcb, struct pbuf *p, ip_addr_t *addr, u16_t
sntp_process(receive_timestamp);
/* Set up timeout for next request */
sys_timeout((u32_t)SNTP_UPDATE_DELAY, sntp_request, NULL);
sys_timeout((u32_t)sntp_update_delay, sntp_request, NULL);
LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_recv: Scheduled next time request: %"U32_F" ms\n",
(u32_t)SNTP_UPDATE_DELAY));
(u32_t)sntp_update_delay));
} else if (err == SNTP_ERR_KOD) {
/* Kiss-of-death packet. Use another server or increase UPDATE_DELAY. */
sntp_try_next_server(NULL);
@ -1125,4 +1155,31 @@ sntp_getservername(u8_t idx)
}
#endif /* SNTP_SERVER_DNS */
void ICACHE_FLASH_ATTR
sntp_set_update_delay(uint32 ms)
{
sntp_update_delay = ms > 15000?ms:15000;
}
void ICACHE_FLASH_ATTR
sntp_set_timetype(bool type)
{
// sntp_time_flag = type;
}
bool sntp_get_timetype(void)
{
return sntp_time_flag;
}
void ICACHE_FLASH_ATTR
sntp_set_receive_time_size(void)
{
if (sntp_get_timetype()){
sntp_receive_time_size = 2;
} else{
sntp_receive_time_size = 1;
}
}
#endif /* LWIP_UDP */