Unverified Commit 6db74142 authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge branch 'dev' into dev-LFS

parents 88bd9e01 f427951f
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#undef MBEDTLS_HAVE_ASM #undef MBEDTLS_HAVE_ASM
#undef MBEDTLS_HAVE_SSE2 #undef MBEDTLS_HAVE_SSE2
#define MBEDTLS_HAVE_TIME // These are disabled until we have a real, working RTC-based gettimeofday
#define MBEDTLS_HAVE_TIME_DATE #undef MBEDTLS_HAVE_TIME
#undef MBEDTLS_HAVE_TIME_DATE
#define MBEDTLS_PLATFORM_MEMORY #define MBEDTLS_PLATFORM_MEMORY
#undef MBEDTLS_PLATFORM_NO_STD_FUNCTIONS #undef MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
......
...@@ -76,5 +76,9 @@ ...@@ -76,5 +76,9 @@
//#define LUA_USE_MODULES_WS2812_EFFECTS //#define LUA_USE_MODULES_WS2812_EFFECTS
//#define LUA_USE_MODULES_XPT2046 //#define LUA_USE_MODULES_XPT2046
//debug modules
//#define LUA_USE_MODULES_SWTMR_DBG //SWTMR timer suspend Debug functions
#endif /* LUA_CROSS_COMPILER */ #endif /* LUA_CROSS_COMPILER */
#endif /* __USER_MODULES_H__ */ #endif /* __USER_MODULES_H__ */
#ifndef __USER_VERSION_H__ #ifndef __USER_VERSION_H__
#define __USER_VERSION_H__ #define __USER_VERSION_H__
#define NODE_VERSION_MAJOR 2U #include "version.h" /* ESP firmware header */
#define NODE_VERSION_MINOR 1U
#define NODE_VERSION_REVISION 0U #define NODE_VERSION_MAJOR ESP_SDK_VERSION_MAJOR
#define NODE_VERSION_INTERNAL 0U #define NODE_VERSION_MINOR ESP_SDK_VERSION_MINOR
#define NODE_VERSION_REVISION ESP_SDK_VERSION_PATCH
#define NODE_VERSION_INTERNAL 0
#define NODE_VERSION_STR(x) #x
#define NODE_VERSION_XSTR(x) NODE_VERSION_STR(x)
#define NODE_VERSION "NodeMCU " ESP_SDK_VERSION_STRING "." NODE_VERSION_XSTR(NODE_VERSION_INTERNAL)
#define NODE_VERSION "NodeMCU 2.1.0"
#ifndef BUILD_DATE #ifndef BUILD_DATE
#define BUILD_DATE "unspecified" #define BUILD_DATE "unspecified"
#endif #endif
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include C_HEADER_STRING #include C_HEADER_STRING
#ifndef LUA_CROSS_COMPILER #ifndef LUA_CROSS_COMPILER
#include "vfs.h" #include "vfs.h"
#include "user_interface.h"
#else #else
#endif #endif
...@@ -939,6 +940,11 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { ...@@ -939,6 +940,11 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
} }
if (L != NULL && (mode & EGC_ALWAYS)) /* always collect memory if requested */ if (L != NULL && (mode & EGC_ALWAYS)) /* always collect memory if requested */
luaC_fullgc(L); luaC_fullgc(L);
#ifndef LUA_CROSS_COMPILER
if (L != NULL && (mode & EGC_ON_MEM_LIMIT) && G(L)->memlimit < 0 &&
(system_get_free_heap_size() < (-G(L)->memlimit)))
luaC_fullgc(L);
#endif
if(nsize > osize && L != NULL) { if(nsize > osize && L != NULL) {
#if defined(LUA_STRESS_EMERGENCY_GC) #if defined(LUA_STRESS_EMERGENCY_GC)
luaC_fullgc(L); luaC_fullgc(L);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "lstate.h" #include "lstate.h"
#include "c_types.h" #include "c_types.h"
void legc_set_mode(lua_State *L, int mode, unsigned limit) { void legc_set_mode(lua_State *L, int mode, int limit) {
global_State *g = G(L); global_State *g = G(L);
g->egcmode = mode; g->egcmode = mode;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit
#define EGC_ALWAYS 4 // always run EGC before an allocation #define EGC_ALWAYS 4 // always run EGC before an allocation
void legc_set_mode(lua_State *L, int mode, unsigned limit); void legc_set_mode(lua_State *L, int mode, int limit);
#endif #endif
...@@ -82,7 +82,7 @@ typedef struct global_State { ...@@ -82,7 +82,7 @@ typedef struct global_State {
Mbuffer buff; /* temporary buffer for string concatentation */ Mbuffer buff; /* temporary buffer for string concatentation */
lu_mem GCthreshold; lu_mem GCthreshold;
lu_mem totalbytes; /* number of bytes currently allocated */ lu_mem totalbytes; /* number of bytes currently allocated */
lu_mem memlimit; /* maximum number of bytes that can be allocated, 0 = no limit. */ l_mem memlimit; /* maximum number of bytes that can be allocated, 0 = no limit. <0 used with EGC_ON_MEM_LIMIT when free heap falls below -memlimit */
lu_mem estimate; /* an estimate of number of bytes actually in use */ lu_mem estimate; /* an estimate of number of bytes actually in use */
lu_mem gcdept; /* how much GC is `behind schedule' */ lu_mem gcdept; /* how much GC is `behind schedule' */
int gcpause; /* size of pause between successive GCs */ int gcpause; /* size of pause between successive GCs */
......
...@@ -441,6 +441,7 @@ sint16 ICACHE_FLASH_ATTR espconn_recv(struct espconn *espconn, void *mem, size_t ...@@ -441,6 +441,7 @@ sint16 ICACHE_FLASH_ATTR espconn_recv(struct espconn *espconn, void *mem, size_t
espconn_msg *pnode = NULL; espconn_msg *pnode = NULL;
bool value = false; bool value = false;
int bytes_used = 0; int bytes_used = 0;
struct tcp_pcb *tpcb = NULL;
if (espconn == NULL || mem == NULL || len == 0) if (espconn == NULL || mem == NULL || len == 0)
return ESPCONN_ARG; return ESPCONN_ARG;
...@@ -454,13 +455,15 @@ sint16 ICACHE_FLASH_ATTR espconn_recv(struct espconn *espconn, void *mem, size_t ...@@ -454,13 +455,15 @@ sint16 ICACHE_FLASH_ATTR espconn_recv(struct espconn *espconn, void *mem, size_t
len = bytes_used; len = bytes_used;
} }
ringbuf_memcpy_from(mem, pnode->readbuf, len); ringbuf_memcpy_from(mem, pnode->readbuf, len);
espconn_recv_unhold(pnode->pespconn); tpcb = pnode->pcommon.pcb;
if (tpcb && tpcb->state == ESTABLISHED)
tcp_recved(pnode->pcommon.pcb, len);
return len; return len;
} else { } else {
return ESPCONN_OK; return ESPCONN_OK;
} }
} else{ } else{
return ESPCONN_OK; return ESPCONN_MEM;
} }
} else{ } else{
return ESPCONN_ARG; return ESPCONN_ARG;
......
...@@ -231,6 +231,10 @@ void ICACHE_FLASH_ATTR espconn_tcp_memp_free(espconn_msg *pmemp) ...@@ -231,6 +231,10 @@ void ICACHE_FLASH_ATTR espconn_tcp_memp_free(espconn_msg *pmemp)
if (pmemp == NULL) if (pmemp == NULL)
return; return;
/*Enable block option for fetches the data proactive*/
if (espconn_manual_recv_disabled(pmemp))
espconn_list_delete(&plink_active, pmemp);
if (pmemp->espconn_mode == ESPCONN_TCPSERVER_MODE){ if (pmemp->espconn_mode == ESPCONN_TCPSERVER_MODE){
if (pmemp->pespconn != NULL && pmemp->pespconn->proto.tcp != NULL) if (pmemp->pespconn != NULL && pmemp->pespconn->proto.tcp != NULL)
os_free(pmemp->pespconn->proto.tcp); os_free(pmemp->pespconn->proto.tcp);
...@@ -431,10 +435,12 @@ espconn_Task(os_event_t *events) ...@@ -431,10 +435,12 @@ espconn_Task(os_event_t *events)
case SIG_ESPCONN_ERRER: case SIG_ESPCONN_ERRER:
/*remove the node from the client's active connection list*/ /*remove the node from the client's active connection list*/
espconn_list_delete(&plink_active, task_msg); espconn_list_delete(&plink_active, task_msg);
espconn_tcp_reconnect(task_msg); if (espconn_manual_recv_enabled(task_msg))
espconn_list_delete(&plink_active, task_msg);
break; break;
case SIG_ESPCONN_CLOSE: case SIG_ESPCONN_CLOSE:
/*remove the node from the client's active connection list*/ /*remove the node from the client's active connection list*/
if (espconn_manual_recv_enabled(task_msg))
espconn_list_delete(&plink_active, task_msg); espconn_list_delete(&plink_active, task_msg);
espconn_tcp_disconnect_successful(task_msg); espconn_tcp_disconnect_successful(task_msg);
break; break;
...@@ -538,6 +544,66 @@ void ICACHE_FLASH_ATTR espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type) ...@@ -538,6 +544,66 @@ void ICACHE_FLASH_ATTR espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type)
} }
} }
/******************************************************************************
* FunctionName : espconn_tcp_recv
* Description : Data has been received on this pcb.
* Parameters : arg -- Additional argument to pass to the callback function
* pcb -- The connection pcb which received data
* p -- The received data (or NULL when the connection has been closed!)
* err -- An error code if there has been an error receiving
* Returns : ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
espconn_msg *precv_cb = arg;
struct pbuf *pthis = NULL;
uint8_t *ring = NULL;
size_t bytes_used = 0;
tcp_arg(pcb, arg);
if (precv_cb->readbuf == NULL) {
precv_cb->readbuf = ringbuf_new(TCP_WND);
if (precv_cb->readbuf == NULL)
return ESPCONN_MEM;
}
if (err == ERR_OK) {
precv_cb->pcommon.recv_check = 0;
if (p != NULL) {
/*store the data to the adapter for application fetches it proactive*/
for (pthis = p; pthis != NULL ; pthis = pthis->next) {
ring = ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
if (ring)
pbuf_free(pthis);
else
break;
}
bytes_used = ringbuf_bytes_used(precv_cb->readbuf);
/*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, NULL, bytes_used);
}
/*switch the state of espconn for next packet copy*/
if (pcb->state == ESTABLISHED)
precv_cb->pespconn->state = ESPCONN_CONNECT;
} else {
if (precv_cb->preverse) {
espconn_server_close(precv_cb, pcb, 0);
} else {
espconn_client_close(precv_cb, pcb, 0);
}
}
}
return ERR_OK;
}
///////////////////////////////client function///////////////////////////////// ///////////////////////////////client function/////////////////////////////////
/****************************************************************************** /******************************************************************************
* FunctionName : espconn_client_close * FunctionName : espconn_client_close
...@@ -933,6 +999,10 @@ espconn_client_connect(void *arg, struct tcp_pcb *tpcb, err_t err) ...@@ -933,6 +999,10 @@ espconn_client_connect(void *arg, struct tcp_pcb *tpcb, err_t err)
pcon->pespconn->proto.tcp->connect_callback(pcon->pespconn); pcon->pespconn->proto.tcp->connect_callback(pcon->pespconn);
} }
/*Enable block option for fetches the data proactive*/
if (espconn_manual_recv_disabled(pcon))
tcp_recv(tpcb, espconn_tcp_recv);
/*Enable keep alive option*/ /*Enable keep alive option*/
if (espconn_keepalive_disabled(pcon)) if (espconn_keepalive_disabled(pcon))
espconn_keepalive_enable(tpcb); espconn_keepalive_enable(tpcb);
...@@ -1358,6 +1428,10 @@ espconn_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err) ...@@ -1358,6 +1428,10 @@ espconn_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err)
paccept->pespconn->proto.tcp->connect_callback(paccept->pespconn); paccept->pespconn->proto.tcp->connect_callback(paccept->pespconn);
} }
/*Enable block option for fetches the data proactive*/
if (espconn_manual_recv_disabled(paccept))
tcp_recv(pcb, espconn_tcp_recv);
/*Enable keep alive option*/ /*Enable keep alive option*/
if (espconn_keepalive_disabled(paccept)) if (espconn_keepalive_disabled(paccept))
espconn_keepalive_enable(pcb); espconn_keepalive_enable(pcb);
......
...@@ -237,9 +237,10 @@ espconn_udp_sendto(void *arg, uint8 *psent, uint16 length) ...@@ -237,9 +237,10 @@ espconn_udp_sendto(void *arg, uint8 *psent, uint16 length)
if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL) 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) && \ if( netif_is_up(sta_netif) && \
ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \ netif_is_up(ap_netif) && \
ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) { ip_addr_isbroadcast(&dst_ip, sta_netif) && \
ip_addr_isbroadcast(&dst_ip, ap_netif)) {
p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM); p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
if (pbuf_copy (p_temp,p) != ERR_OK) { if (pbuf_copy (p_temp,p) != ERR_OK) {
......
...@@ -1039,6 +1039,7 @@ mdns_reg(struct mdns_info *info) { ...@@ -1039,6 +1039,7 @@ mdns_reg(struct mdns_info *info) {
os_timer_disarm(&mdns_timer); os_timer_disarm(&mdns_timer);
} }
} }
#include "pm/swtimer.h"
/** /**
* 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
...@@ -1129,6 +1130,8 @@ mdns_init(struct mdns_info *info) { ...@@ -1129,6 +1130,8 @@ mdns_init(struct mdns_info *info) {
os_timer_disarm(&mdns_timer); os_timer_disarm(&mdns_timer);
os_timer_setfn(&mdns_timer, (os_timer_func_t *)mdns_reg,ms_info); os_timer_setfn(&mdns_timer, (os_timer_func_t *)mdns_reg,ms_info);
SWTIMER_REG_CB(mdns_reg, SWTIMER_RESTART);
//going on the above comment, it's probably a good idea to let mdns_reg run it's course. not sure if the 1 second timing is important, so lets restart it to be safe.
os_timer_arm(&mdns_timer, 1000, 1); os_timer_arm(&mdns_timer, 1000, 1);
} }
} }
......
This diff is collapsed.
...@@ -500,7 +500,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) ...@@ -500,7 +500,7 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
/* For incoming segments with the ACK flag set, respond with a /* For incoming segments with the ACK flag set, respond with a
RST. */ RST. */
LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n")); LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n"));
tcp_rst(ackno + 1, seqno + tcplen, tcp_rst(ackno, seqno + tcplen,
ip_current_dest_addr(), ip_current_src_addr(), ip_current_dest_addr(), ip_current_src_addr(),
tcphdr->dest, tcphdr->src); tcphdr->dest, tcphdr->src);
} else if (flags & TCP_SYN) {//�յ�SYN���� } else if (flags & TCP_SYN) {//�յ�SYN����
......
...@@ -461,6 +461,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) ...@@ -461,6 +461,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
return ERR_MEM; return ERR_MEM;
} }
#if !LWIP_NETIF_TX_SINGLE_PBUF
/* /*
* Phase 2: Chain a new pbuf to the end of pcb->unsent. * Phase 2: Chain a new pbuf to the end of pcb->unsent.
* *
...@@ -510,6 +511,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) ...@@ -510,6 +511,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
pos += seglen; pos += seglen;
queuelen += pbuf_clen(concat_p); queuelen += pbuf_clen(concat_p);
} }
#endif /* !LWIP_NETIF_TX_SINGLE_PBUF */
} else { } else {
#if TCP_OVERSIZE #if TCP_OVERSIZE
LWIP_ASSERT("unsent_oversize mismatch (pcb->unsent is NULL)", LWIP_ASSERT("unsent_oversize mismatch (pcb->unsent is NULL)",
...@@ -1336,6 +1338,12 @@ tcp_rexmit(struct tcp_pcb *pcb) ...@@ -1336,6 +1338,12 @@ tcp_rexmit(struct tcp_pcb *pcb)
} }
seg->next = *cur_seg; seg->next = *cur_seg;
*cur_seg = seg; *cur_seg = seg;
#if TCP_OVERSIZE
if (seg->next == NULL) {
/* the retransmitted segment is last in unsent, so reset unsent_oversize */
pcb->unsent_oversize = 0;
}
#endif /* TCP_OVERSIZE */
++pcb->nrtx; ++pcb->nrtx;
......
...@@ -353,6 +353,8 @@ static void mbedtls_msg_free(pmbedtls_msg *msg) ...@@ -353,6 +353,8 @@ static void mbedtls_msg_free(pmbedtls_msg *msg)
os_free((*msg)->ssl.out_buf); os_free((*msg)->ssl.out_buf);
(*msg)->ssl.out_buf = NULL; (*msg)->ssl.out_buf = NULL;
} }
if((*msg)->pfinished != NULL)
mbedtls_finished_free(&(*msg)->pfinished);
#endif #endif
mbedtls_entropy_free(&(*msg)->entropy); mbedtls_entropy_free(&(*msg)->entropy);
mbedtls_ssl_free(&(*msg)->ssl); mbedtls_ssl_free(&(*msg)->ssl);
...@@ -427,10 +429,6 @@ static void mbedtls_fail_info(espconn_msg *pinfo, int ret) ...@@ -427,10 +429,6 @@ static void mbedtls_fail_info(espconn_msg *pinfo, int ret)
TLSmsg = pinfo->pssl; TLSmsg = pinfo->pssl;
lwIP_REQUIRE_ACTION(TLSmsg,exit,); lwIP_REQUIRE_ACTION(TLSmsg,exit,);
if (TLSmsg->quiet) {
mbedtls_ssl_close_notify(&TLSmsg->ssl);
}
/* Don't complain to console if we've been told the other end is hanging /* Don't complain to console if we've been told the other end is hanging
* up. That's entirely normal and not worthy of the confusion it sows! * up. That's entirely normal and not worthy of the confusion it sows!
*/ */
...@@ -441,6 +439,7 @@ static void mbedtls_fail_info(espconn_msg *pinfo, int ret) ...@@ -441,6 +439,7 @@ static void mbedtls_fail_info(espconn_msg *pinfo, int ret)
} else { } else {
os_printf("client's data invalid protocol\n"); os_printf("client's data invalid protocol\n");
} }
mbedtls_ssl_close_notify(&TLSmsg->ssl);
} else{ } else{
if (pinfo->preverse != NULL) { if (pinfo->preverse != NULL) {
os_printf("server handshake failed!\n"); os_printf("server handshake failed!\n");
...@@ -564,6 +563,11 @@ static void espconn_close_internal(void *arg, netconn_event event_type) ...@@ -564,6 +563,11 @@ static void espconn_close_internal(void *arg, netconn_event event_type)
ssl_reerr = pssl_recon->pcommon.err; ssl_reerr = pssl_recon->pcommon.err;
hs_status = pssl_recon->hs_status; hs_status = pssl_recon->hs_status;
if (espconn != NULL) { if (espconn != NULL) {
//clear pcommon parameters.
pssl_recon->pcommon.write_flag = false;
pssl_recon->pcommon.ptrbuf = NULL;
pssl_recon->pcommon.cntr = 0;
pssl_recon->pcommon.err = 0;
espconn = pssl_recon->preverse; espconn = pssl_recon->preverse;
} else { } else {
espconn = pssl_recon->pespconn; espconn = pssl_recon->pespconn;
...@@ -667,6 +671,11 @@ again: ...@@ -667,6 +671,11 @@ again:
offerset += sizeof(file_head) + pfile_param->file_head.file_length; offerset += sizeof(file_head) + pfile_param->file_head.file_length;
goto again; goto again;
} }
/*Optional is load the cert*/
if (auth_info->auth_type == ESPCONN_CERT_OWN && os_memcmp(pfile_param->file_head.file_name, "certificate", os_strlen("certificate")) != 0){
offerset += sizeof(file_head) + pfile_param->file_head.file_length;
goto again;
}
load_buf = (uint8_t *) os_zalloc( pfile_param->file_head.file_length + FILE_OFFSET); load_buf = (uint8_t *) os_zalloc( pfile_param->file_head.file_length + FILE_OFFSET);
if (load_buf == NULL){ if (load_buf == NULL){
os_free(pfile_param); os_free(pfile_param);
...@@ -839,6 +848,9 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error) ...@@ -839,6 +848,9 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == 0){ if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == 0){
ret = ESPCONN_OK; ret = ESPCONN_OK;
break; break;
} else if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY){
ret = ESPCONN_OK;
mbedtls_ssl_close_notify(&TLSmsg->ssl);
} else{ } else{
break; break;
} }
...@@ -891,6 +903,9 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error) ...@@ -891,6 +903,9 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
} }
system_soft_wdt_stop(); system_soft_wdt_stop();
uint8 cpu_freq;
cpu_freq = system_get_cpu_freq();
system_update_cpu_freq(160);
while ((ret = mbedtls_ssl_handshake(&TLSmsg->ssl)) != 0) { while ((ret = mbedtls_ssl_handshake(&TLSmsg->ssl)) != 0) {
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) { if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
...@@ -901,6 +916,7 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error) ...@@ -901,6 +916,7 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
} }
} }
system_soft_wdt_restart(); system_soft_wdt_restart();
system_update_cpu_freq(cpu_freq);
lwIP_REQUIRE_NOERROR(ret, exit); lwIP_REQUIRE_NOERROR(ret, exit);
/**/ /**/
TLSmsg->quiet = mbedtls_handshake_result(TLSmsg); TLSmsg->quiet = mbedtls_handshake_result(TLSmsg);
...@@ -937,6 +953,9 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error) ...@@ -937,6 +953,9 @@ int __attribute__((weak)) mbedtls_parse_internal(int socket, sint8 error)
exit: exit:
if (ret != ESPCONN_OK){ if (ret != ESPCONN_OK){
mbedtls_fail_info(Threadmsg, ret); mbedtls_fail_info(Threadmsg, ret);
if(ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY){
Threadmsg->hs_status = ESPCONN_OK;
}
ets_post(lwIPThreadPrio, NETCONN_EVENT_CLOSE,(uint32)Threadmsg); ets_post(lwIPThreadPrio, NETCONN_EVENT_CLOSE,(uint32)Threadmsg);
} }
return ret; return ret;
......
...@@ -302,6 +302,20 @@ static err_t do_accepted(void *arg, struct tcp_pcb *newpcb, err_t err) ...@@ -302,6 +302,20 @@ static err_t do_accepted(void *arg, struct tcp_pcb *newpcb, err_t err)
lwIP_netconn *newconn = NULL; lwIP_netconn *newconn = NULL;
lwIP_netconn *conn = arg; lwIP_netconn *conn = arg;
err = ERR_OK; err = ERR_OK;
//Avoid two TCP connections coming in simultaneously
struct tcp_pcb *pactive_pcb;
int active_pcb_num=0;
for(pactive_pcb = tcp_active_pcbs; pactive_pcb != NULL; pactive_pcb = pactive_pcb->next){
if (pactive_pcb->state == ESTABLISHED ||pactive_pcb->state == SYN_RCVD){
active_pcb_num++;
if (active_pcb_num > MEMP_NUM_TCP_PCB){
ESP_LOG("%s %d active_pcb_number:%d\n",__FILE__, __LINE__,active_pcb_num);
return ERR_MEM;
}
}
}
lwIP_REQUIRE_ACTION(conn, exit, err = ESP_ARG); lwIP_REQUIRE_ACTION(conn, exit, err = ESP_ARG);
/* We have to set the callback here even though /* We have to set the callback here even though
* the new socket is unknown. conn->socket is marked as -1. */ * the new socket is unknown. conn->socket is marked as -1. */
...@@ -738,6 +752,11 @@ int lwip_close(int s) ...@@ -738,6 +752,11 @@ int lwip_close(int s)
return -1; return -1;
} }
/*Do not set callback function when tcp->state is LISTEN.
Avoid memory overlap when conn->tcp changes from
struct tcp_bcb to struct tcp_pcb_listen after lwip_listen.*/
if (sock->conn->tcp->state != LISTEN)
{
if (sock->conn->state != NETCONN_STATE_ERROR){ if (sock->conn->state != NETCONN_STATE_ERROR){
tcp_recv(sock->conn->tcp, NULL); tcp_recv(sock->conn->tcp, NULL);
err = tcp_close(sock->conn->tcp); err = tcp_close(sock->conn->tcp);
...@@ -749,9 +768,11 @@ int lwip_close(int s) ...@@ -749,9 +768,11 @@ int lwip_close(int s)
return -1; return -1;
} }
} }
/* closing succeeded */ /* closing succeeded */
remove_tcp(sock->conn); remove_tcp(sock->conn);
} else {
tcp_close(sock->conn->tcp);
}
free_netconn(sock->conn); free_netconn(sock->conn);
free_socket(sock); free_socket(sock);
return ERR_OK; return ERR_OK;
......
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libmisc.a
endif
STD_CFLAGS=-std=gnu11 -Wimplicit
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ./include
INCLUDES += -I ../include
INCLUDES += -I ../../include
INCLUDES += -I ../lua
INCLUDES += -I ../platform
INCLUDES += -I ../libc
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
#include "misc/dynarr.h"
#define ARRAY_PTR_CHECK if(array_ptr == NULL || array_ptr->data_ptr == NULL){\
/**/DYNARR_DBG("array not initialized");\
return false; \
}
bool dynarr_init(dynarr_t* array_ptr, size_t array_size, size_t data_size){
if(array_ptr == NULL || data_size == 0 || array_size == 0){
/**/DYNARR_DBG("Invalid parameter: array_ptr(%p) data_size(%u) array_size(%u)", array_ptr, data_size, array_size);
return false;
}
if(array_ptr->data_ptr != NULL ){
/**/DYNARR_DBG("Array already initialized: array_ptr->data_ptr=%p", array_ptr->data_ptr);
return false;
}
/**/DYNARR_DBG("Array parameters:\n\t\t\tarray_size(%u)\n\t\t\tdata_size(%u)\n\t\t\ttotal size(bytes):%u", array_size, data_size, (array_size * data_size));
void* temp_array = c_zalloc(array_size * data_size);
if(temp_array == NULL){
/**/DYNARR_ERR("malloc FAIL! req:%u free:%u", (array_size * data_size), system_get_free_heap_size());
return false;
}
array_ptr->data_ptr = temp_array;
array_ptr->array_size = array_size;
array_ptr->data_size = data_size;
array_ptr->used = 0;
return true;
}
bool dynarr_resize(dynarr_t* array_ptr, size_t elements_to_add){
ARRAY_PTR_CHECK;
if(elements_to_add <= 0){
/**/DYNARR_DBG("Invalid qty: elements_to_add=%u", elements_to_add);
return false;
}
size_t new_array_size = array_ptr->array_size + elements_to_add;
/**/DYNARR_DBG("old size=%u\tnew size=%u\tmem used=%u",
array_ptr->array_size, new_array_size, (new_array_size * array_ptr->data_size));
void* temp_array_p = c_realloc(array_ptr->data_ptr, new_array_size * array_ptr->data_size);
if(temp_array_p == NULL){
/**/DYNARR_ERR("malloc FAIL! req:%u free:%u", (new_array_size * array_ptr->data_size), system_get_free_heap_size());
return false;
}
array_ptr->data_ptr = temp_array_p;
size_t prev_size = array_ptr->array_size;
array_ptr->array_size = new_array_size;
//set memory to 0 for newly added array elements
memset((uint8*) array_ptr->data_ptr + (prev_size * array_ptr->data_size), 0, (elements_to_add * array_ptr->data_size));
/**/DYNARR_DBG("Array successfully resized");
return true;
}
bool dynarr_remove(dynarr_t* array_ptr, void* element_to_remove){
ARRAY_PTR_CHECK;
uint8* element_ptr = element_to_remove;
uint8* data_ptr = array_ptr->data_ptr;
if(dynarr_boundaryCheck(array_ptr, element_to_remove) == FALSE){
return false;
}
//overwrite element to be removed by shifting all elements to the left
memmove(element_ptr, element_ptr + array_ptr->data_size, (array_ptr->array_size - 1) * array_ptr->data_size - (element_ptr - data_ptr));
//clear newly freed element
memset(data_ptr + ((array_ptr->array_size-1) * array_ptr->data_size), 0, array_ptr->data_size);
//decrement array used since we removed an element
array_ptr->used--;
/**/DYNARR_DBG("element(%p) removed from array", element_ptr);
return true;
}
bool dynarr_add(dynarr_t* array_ptr, void* data_ptr, size_t data_size){
ARRAY_PTR_CHECK;
if(data_size != array_ptr->data_size){
/**/DYNARR_DBG("Invalid data size: data_size(%u) != arr->data_size(%u)", data_size, array_ptr->data_size);
return false;
}
if(array_ptr->array_size == array_ptr->used){
if(!dynarr_resize(array_ptr, (array_ptr->array_size/2))){
return false;
}
}
memcpy(((uint8*)array_ptr->data_ptr + (array_ptr->used * array_ptr->data_size)), data_ptr, array_ptr->data_size);
array_ptr->used++;
return true;
}
bool dynarr_boundaryCheck(dynarr_t* array_ptr, void* element_to_check){
ARRAY_PTR_CHECK;
uint8* data_ptr = array_ptr->data_ptr;
uint8* element_ptr = element_to_check;
if(element_ptr < data_ptr || ((element_ptr - data_ptr) / array_ptr->data_size) > array_ptr->array_size - 1){
/**/DYNARR_DBG("element_ptr(%p) out of bounds: first element ptr:%p last element ptr:%p",
element_ptr, data_ptr, data_ptr + ((array_ptr->array_size - 1) * array_ptr->data_size));
return false;
}
return true;
}
bool dynarr_free(dynarr_t* array_ptr){
ARRAY_PTR_CHECK;
c_free(array_ptr->data_ptr);
array_ptr->data_ptr=NULL;
array_ptr->array_size = array_ptr->used = 0;
/**/DYNARR_DBG("array freed");
return true;
}
...@@ -190,7 +190,7 @@ static void cron_handle_tmr() { ...@@ -190,7 +190,7 @@ static void cron_handle_tmr() {
struct rtc_timeval tv; struct rtc_timeval tv;
rtctime_gettimeofday(&tv); rtctime_gettimeofday(&tv);
if (tv.tv_sec == 0) { // Wait for RTC time if (tv.tv_sec == 0) { // Wait for RTC time
ets_timer_arm_new(&cron_timer, 1000, 0, 1); os_timer_arm(&cron_timer, 1000, 0);
return; return;
} }
time_t t = tv.tv_sec; time_t t = tv.tv_sec;
...@@ -202,7 +202,7 @@ static void cron_handle_tmr() { ...@@ -202,7 +202,7 @@ static void cron_handle_tmr() {
diff += 60000; diff += 60000;
gmtime_r(&t, &tm); gmtime_r(&t, &tm);
} }
ets_timer_arm_new(&cron_timer, diff, 0, 1); os_timer_arm(&cron_timer, diff, 0);
cron_handle_time(tm.tm_mon + 1, tm.tm_mday, tm.tm_wday, tm.tm_hour, tm.tm_min); cron_handle_time(tm.tm_mon + 1, tm.tm_mday, tm.tm_wday, tm.tm_hour, tm.tm_min);
} }
...@@ -220,11 +220,15 @@ static const LUA_REG_TYPE cron_map[] = { ...@@ -220,11 +220,15 @@ static const LUA_REG_TYPE cron_map[] = {
{ LSTRKEY( "reset" ), LFUNCVAL( lcron_reset ) }, { LSTRKEY( "reset" ), LFUNCVAL( lcron_reset ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
#include "pm/swtimer.h"
int luaopen_cron( lua_State *L ) { int luaopen_cron( lua_State *L ) {
ets_timer_disarm(&cron_timer); os_timer_disarm(&cron_timer);
ets_timer_setfn(&cron_timer, cron_handle_tmr, 0); os_timer_setfn(&cron_timer, cron_handle_tmr, 0);
ets_timer_arm_new(&cron_timer, 1000, 0, 1); SWTIMER_REG_CB(cron_handle_tmr, SWTIMER_RESTART);
//cron_handle_tmr determines when to execute a scheduled cron job
//My guess: To be sure to give the other modules required by cron enough time to get to a ready state, restart cron_timer.
os_timer_arm(&cron_timer, 1000, 0);
luaL_rometatable(L, "cron.entry", (void *)cronent_map); luaL_rometatable(L, "cron.entry", (void *)cronent_map);
return 0; return 0;
} }
......
...@@ -134,6 +134,8 @@ static int ds18b20_lua_setting(lua_State *L) { ...@@ -134,6 +134,8 @@ static int ds18b20_lua_setting(lua_State *L) {
return 0; return 0;
} }
#include "pm/swtimer.h"
// Reads sensor values from all devices // Reads sensor values from all devices
// Lua: ds18b20.read(function(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) print(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) end, ROM[, FAMILY]) // Lua: ds18b20.read(function(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) print(INDEX, ROM, RES, TEMP, TEMP_DEC, PAR) end, ROM[, FAMILY])
static int ds18b20_lua_read(lua_State *L) { static int ds18b20_lua_read(lua_State *L) {
...@@ -173,6 +175,9 @@ static int ds18b20_lua_read(lua_State *L) { ...@@ -173,6 +175,9 @@ static int ds18b20_lua_read(lua_State *L) {
onewire_write(ds18b20_bus_pin, DS18B20_ROM_SKIP, 0); onewire_write(ds18b20_bus_pin, DS18B20_ROM_SKIP, 0);
onewire_write(ds18b20_bus_pin, DS18B20_FUNC_CONVERT, 1); onewire_write(ds18b20_bus_pin, DS18B20_FUNC_CONVERT, 1);
os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_lua_readoutdone, NULL); os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_lua_readoutdone, NULL);
SWTIMER_REG_CB(ds18b20_lua_readoutdone, SWTIMER_DROP);
//The function ds18b20_lua_readoutdone reads the temperature from the sensor(s) after a set amount of time depending on temperature resolution
//MY guess: If this timer manages to get suspended before it fires and the temperature data is time sensitive then resulting data would be invalid and should be discarded
switch (ds18b20_device_res) { switch (ds18b20_device_res) {
case (9): case (9):
......
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