Merge pull request #437 from ourairquality/oaq-merge-1
* bmp180: comment typo * ds3231: minor code style fixes. Comment, on the week day start. * Reverse engineered ets_timers.o Switch from FreeRTOS queue to task notification. Removed unknown/unused code. Rename sdk_ets_handler_isr to process_pending_timers. Add function for microseconds Simplify time to ticks conversion * ets_timer: code for using the FreeRTOS timers, and remove from libs. * libc: update to a recent newlib version. * LwIP v2 support * spi_write: use uint32_t for the page iteration counter. The page counter was using an uint8_t which seems unnecessary and might wrap. * sysparam_get_bool: memcpy the binary values out. * FreeRTOS 9.0.1 * Add an argument to ISRs. Disable interrupts while masking them. * sysparam: reserve one more flash sector before placing the sysparams. This is to help work with recent SDKs that add a RF cal sector by default in the fifth last sector - just so the sysparam sectors do not jump around when using different SDK versions. * upnp example: strip down the lwipopts.h file * sysparam editor: accept newline to end a line of input. * Add Wificfg. Uses the sysparam store to save the wifi configuration. Adds a basic http server for configuration. * lwip: disable the tcpip_core_locking_input option. With this option enabled some lwip input processing occurs in the pp task which works well for some uses but some code uses a lot of stack (e.g. mdns) and will overflow the pp task stask, or might unnecessarily slow the critical pp task, so disable this by default and if not already defined. * sdk_cnx_add_rc: fix overflow of the table, when no match is found. Also adds source code for sdk_cnx_rc_search, adding a null pointer dereference. Check (that is not expected to be seen), and source code for sdk_cnx_remove_rc. * http_get example: fix compilation with ipv6 disabled. * lwip: update to master branch. * wificfg: allow the AP channel to be 1. * lwip: rework the tcp ooseq handling. It now accounts for the number of rx pool buffers used and the available memory when deciding the number of ooseq buffers to retain. Enable the TCP Selective ACK support which appears to help a lot on lossy wifi when using the OOSEQ option. * Update lwip, fixes losses of pcbs and associated problems. * lwip: revise the tcp ooseq limit calulations. Was making a mess of the calculation sign. Also added a COPY_PP_RX_PBUFS define to include appropriate limits for this option. * lwip: ooseq_max_bytes() - set a practical target memory size. * lwip: revise ooseq handling. Modified for lwip backwards compatibility based on upstream feedback. * lwip: update to the 2.0.3 release * lwip: merge upstream master. * libc: update to upstream master. * lwip: fix building without TCP_QUEUE_OOSEQ
This commit is contained in:
commit
546cc47121
183 changed files with 10793 additions and 11817 deletions
|
@ -48,7 +48,7 @@ void user_init(void)
|
|||
};
|
||||
sdk_wifi_softap_set_config(&ap_config);
|
||||
|
||||
ip_addr_t first_client_ip;
|
||||
ip4_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
|
||||
|
@ -65,14 +65,14 @@ static void telnetTask(void *pvParameters)
|
|||
printf("Status monitor: Failed to allocate socket.\r\n");
|
||||
return;
|
||||
}
|
||||
netconn_bind(nc, IP_ADDR_ANY, TELNET_PORT);
|
||||
netconn_bind(nc, IP_ANY_TYPE, TELNET_PORT);
|
||||
netconn_listen(nc);
|
||||
|
||||
while(1) {
|
||||
struct netconn *client = NULL;
|
||||
err_t err = netconn_accept(nc, &client);
|
||||
|
||||
if ( err != ERR_OK ) {
|
||||
if (err != ERR_OK) {
|
||||
if(client)
|
||||
netconn_delete(client);
|
||||
continue;
|
||||
|
@ -88,9 +88,8 @@ static void telnetTask(void *pvParameters)
|
|||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
snprintf(buf, sizeof(buf), "Free heap %d bytes\r\n", (int)xPortGetFreeHeapSize());
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
snprintf(buf, sizeof(buf), "Your address is %d.%d.%d.%d\r\n\r\n",
|
||||
ip4_addr1(&client_addr), ip4_addr2(&client_addr),
|
||||
ip4_addr3(&client_addr), ip4_addr4(&client_addr));
|
||||
char abuf[40];
|
||||
snprintf(buf, sizeof(buf), "Your address is %s\r\n\r\n", ipaddr_ntoa_r(&client_addr, abuf, sizeof(abuf)));
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
netconn_delete(client);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ const int freq_frc2 = 10;
|
|||
static volatile uint32_t frc1_count;
|
||||
static volatile uint32_t frc2_count;
|
||||
|
||||
void frc1_interrupt_handler(void)
|
||||
void frc1_interrupt_handler(void *arg)
|
||||
{
|
||||
frc1_count++;
|
||||
gpio_toggle(gpio_frc1);
|
||||
}
|
||||
|
||||
void frc2_interrupt_handler(void)
|
||||
void frc2_interrupt_handler(void *arg)
|
||||
{
|
||||
/* FRC2 needs the match register updated on each timer interrupt */
|
||||
timer_set_frequency(FRC2, freq_frc2);
|
||||
|
@ -47,8 +47,8 @@ void user_init(void)
|
|||
timer_set_run(FRC2, false);
|
||||
|
||||
/* set up ISRs */
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler, NULL);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler, NULL);
|
||||
|
||||
/* configure timer frequencies */
|
||||
timer_set_frequency(FRC1, freq_frc1);
|
||||
|
|
|
@ -97,7 +97,7 @@ void timerRegTask(void *pvParameters)
|
|||
}
|
||||
}
|
||||
|
||||
IRAM void frc1_handler(void)
|
||||
IRAM void frc1_handler(void *arg)
|
||||
{
|
||||
frc1_handler_call_count++;
|
||||
frc1_last_count_val = TIMER(0).COUNT;
|
||||
|
@ -106,7 +106,7 @@ IRAM void frc1_handler(void)
|
|||
//TIMER_FRC1_MATCH_REG = frc1_last_count_val + 0x100000;
|
||||
}
|
||||
|
||||
void frc2_handler(void)
|
||||
void frc2_handler(void *arg)
|
||||
{
|
||||
frc2_handler_call_count++;
|
||||
frc2_last_count_val = TIMER(1).COUNT;
|
||||
|
@ -127,9 +127,9 @@ void user_init(void)
|
|||
TIMER(1).LOAD = VAL2FIELD(TIMER_CTRL_CLKDIV, TIMER_CLKDIV_256);
|
||||
|
||||
DPORT.INT_ENABLE |= DPORT_INT_ENABLE_TIMER0 | DPORT_INT_ENABLE_TIMER1;
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_handler, NULL);
|
||||
_xt_isr_unmask(1<<INUM_TIMER_FRC1);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_handler, NULL);
|
||||
_xt_isr_unmask(1<<INUM_TIMER_FRC2);
|
||||
|
||||
TIMER(0).CTRL |= TIMER_CTRL_RUN;
|
||||
|
|
|
@ -237,7 +237,7 @@ static volatile bool frc1_ran;
|
|||
static volatile bool frc1_finished;
|
||||
static volatile char frc1_buf[80];
|
||||
|
||||
static void frc1_interrupt_handler(void)
|
||||
static void frc1_interrupt_handler(void *arg)
|
||||
{
|
||||
frc1_ran = true;
|
||||
timer_set_run(FRC1, false);
|
||||
|
@ -250,7 +250,7 @@ static void test_isr()
|
|||
printf("Testing behaviour inside ISRs...\r\n");
|
||||
timer_set_interrupts(FRC1, false);
|
||||
timer_set_run(FRC1, false);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler, NULL);
|
||||
timer_set_frequency(FRC1, 1000);
|
||||
timer_set_interrupts(FRC1, true);
|
||||
timer_set_run(FRC1, true);
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
|
||||
#include "ssid_config.h"
|
||||
|
||||
#define WEB_SERVER "chainxor.org"
|
||||
#define WEB_SERVER "ipv6.google.com"
|
||||
#define WEB_PORT 80
|
||||
#define WEB_URL "http://chainxor.org/"
|
||||
#define WEB_PATH "/"
|
||||
|
||||
void http_get_task(void *pvParameters)
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ void http_get_task(void *pvParameters)
|
|||
|
||||
while(1) {
|
||||
const struct addrinfo hints = {
|
||||
.ai_family = AF_INET,
|
||||
.ai_family = AF_UNSPEC,
|
||||
.ai_socktype = SOCK_STREAM,
|
||||
};
|
||||
struct addrinfo *res;
|
||||
|
@ -39,7 +39,7 @@ void http_get_task(void *pvParameters)
|
|||
printf("Running DNS lookup for %s...\r\n", WEB_SERVER);
|
||||
int err = getaddrinfo(WEB_SERVER, "80", &hints, &res);
|
||||
|
||||
if(err != 0 || res == NULL) {
|
||||
if (err != 0 || res == NULL) {
|
||||
printf("DNS lookup failed err=%d res=%p\r\n", err, res);
|
||||
if(res)
|
||||
freeaddrinfo(res);
|
||||
|
@ -47,9 +47,28 @@ void http_get_task(void *pvParameters)
|
|||
failures++;
|
||||
continue;
|
||||
}
|
||||
/* Note: inet_ntoa is non-reentrant, look at ipaddr_ntoa_r for "real" code */
|
||||
struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr;
|
||||
printf("DNS lookup succeeded. IP=%s\r\n", inet_ntoa(*addr));
|
||||
|
||||
#if LWIP_IPV6
|
||||
{
|
||||
struct netif *netif = sdk_system_get_netif(0);
|
||||
int i;
|
||||
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
|
||||
printf(" ip6 %d state %x\n", i, netif_ip6_addr_state(netif, i));
|
||||
if (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, i)))
|
||||
printf(" ip6 addr %d = %s\n", i, ip6addr_ntoa(netif_ip6_addr(netif, i)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct sockaddr *sa = res->ai_addr;
|
||||
if (sa->sa_family == AF_INET) {
|
||||
printf("DNS lookup succeeded. IP=%s\r\n", inet_ntoa(((struct sockaddr_in *)sa)->sin_addr));
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
if (sa->sa_family == AF_INET6) {
|
||||
printf("DNS lookup succeeded. IP=%s\r\n", inet6_ntoa(((struct sockaddr_in6 *)sa)->sin6_addr));
|
||||
}
|
||||
#endif
|
||||
|
||||
int s = socket(res->ai_family, res->ai_socktype, 0);
|
||||
if(s < 0) {
|
||||
|
@ -75,8 +94,10 @@ void http_get_task(void *pvParameters)
|
|||
freeaddrinfo(res);
|
||||
|
||||
const char *req =
|
||||
"GET "WEB_URL"\r\n"
|
||||
"GET "WEB_PATH" HTTP/1.1\r\n"
|
||||
"Host: "WEB_SERVER"\r\n"
|
||||
"User-Agent: esp-open-rtos/0.1 esp8266\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n";
|
||||
if (write(s, req, strlen(req)) < 0) {
|
||||
printf("... socket send failed\r\n");
|
||||
|
@ -126,6 +147,6 @@ void user_init(void)
|
|||
sdk_wifi_set_opmode(STATION_MODE);
|
||||
sdk_wifi_station_set_config(&config);
|
||||
|
||||
xTaskCreate(&http_get_task, "get_task", 256, NULL, 2, NULL);
|
||||
xTaskCreate(&http_get_task, "get_task", 384, NULL, 2, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ static inline void init_descriptors_list()
|
|||
}
|
||||
|
||||
// DMA interrupt handler. It is called each time a DMA block is finished processing.
|
||||
static void dma_isr_handler(void)
|
||||
static void dma_isr_handler(void *args)
|
||||
{
|
||||
portBASE_TYPE task_awoken = pdFALSE;
|
||||
|
||||
|
@ -168,7 +168,7 @@ void play_task(void *pvParameters)
|
|||
|
||||
i2s_pins_t i2s_pins = {.data = true, .clock = true, .ws = true};
|
||||
|
||||
i2s_dma_init(dma_isr_handler, clock_div, i2s_pins);
|
||||
i2s_dma_init(dma_isr_handler, NULL, clock_div, i2s_pins);
|
||||
|
||||
while (1) {
|
||||
init_descriptors_list();
|
||||
|
|
|
@ -8,7 +8,7 @@ include ../../common.mk
|
|||
# `make dump-flash` can be used to view the current contents of the sysparam
|
||||
# regions in flash.
|
||||
dump-flash:
|
||||
esptool.py read_flash 0x1f8000 8192 r1.bin
|
||||
esptool.py read_flash 0x1f7000 8192 r1.bin
|
||||
hexdump -C r1.bin
|
||||
esptool.py read_flash 0x1fa000 8192 r2.bin
|
||||
esptool.py read_flash 0x1f9000 8192 r2.bin
|
||||
hexdump -C r2.bin
|
||||
|
|
|
@ -45,7 +45,7 @@ size_t tty_readline(char *buffer, size_t buf_size, bool echo) {
|
|||
|
||||
while (true) {
|
||||
c = getchar();
|
||||
if (c == '\r') {
|
||||
if (c == '\r' || c == '\n') {
|
||||
if (echo) putchar('\n');
|
||||
break;
|
||||
} else if (c == '\b' || c == 0x7f) {
|
||||
|
@ -173,7 +173,7 @@ void sysparam_editor_task(void *pvParameters) {
|
|||
// stuff, so if the user uses this utility to reformat it, it will put
|
||||
// it somewhere the system will find it later
|
||||
num_sectors = DEFAULT_SYSPARAM_SECTORS;
|
||||
base_addr = sdk_flashchip.chip_size - (4 + num_sectors) * sdk_flashchip.sector_size;
|
||||
base_addr = sdk_flashchip.chip_size - (5 + num_sectors) * sdk_flashchip.sector_size;
|
||||
}
|
||||
while (true) {
|
||||
printf("==> ");
|
||||
|
@ -246,5 +246,7 @@ void user_init(void)
|
|||
{
|
||||
uart_set_baud(0, 115200);
|
||||
|
||||
sdk_wifi_set_opmode(NULL_MODE);
|
||||
|
||||
xTaskCreate(sysparam_editor_task, "sysparam_editor_task", 512, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
@ -202,9 +202,8 @@ void tls_server_task(void *pvParameters)
|
|||
socklen_t peer_addr_len = sizeof(struct sockaddr_in);
|
||||
getpeername(client_ctx.fd, (struct sockaddr *)&peer_addr, &peer_addr_len);
|
||||
unsigned char buf[256];
|
||||
int len = sprintf((char *) buf, "O hai, client %d.%d.%d.%d:%d\nFree heap size is %d bytes\n",
|
||||
ip4_addr1(&peer_addr.sin_addr), ip4_addr2(&peer_addr.sin_addr),
|
||||
ip4_addr3(&peer_addr.sin_addr), ip4_addr4(&peer_addr.sin_addr),
|
||||
int len = sprintf((char *) buf, "O hai, client " IPSTR ":%d\nFree heap size is %d bytes\n",
|
||||
IP2STR((ip4_addr_t *)&peer_addr.sin_addr.s_addr),
|
||||
peer_addr.sin_port, xPortGetFreeHeapSize());
|
||||
while((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0)
|
||||
{
|
||||
|
|
|
@ -146,9 +146,8 @@ void tls_server_task(void *pvParameters)
|
|||
|
||||
/* Prepare a message to the client */
|
||||
unsigned char buf[100];
|
||||
int len = sprintf((char *) buf, "O hai, client %d.%d.%d.%d:%d\r\nFree heap size is %d bytes\r\n",
|
||||
ip4_addr1(&sa.sin_addr), ip4_addr2(&sa.sin_addr),
|
||||
ip4_addr3(&sa.sin_addr), ip4_addr4(&sa.sin_addr),
|
||||
int len = sprintf((char *) buf, "O hai, client " IPSTR ":%d\r\nFree heap size is %d bytes\r\n",
|
||||
IP2STR((ip4_addr_t *)&sa.sin_addr.s_addr),
|
||||
ntohs(sa.sin_port), xPortGetFreeHeapSize());
|
||||
|
||||
/* Send the message and close the connection */
|
||||
|
|
|
@ -1,464 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Simon Goldschmidt
|
||||
*
|
||||
*/
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#define LWIP_ESP 1
|
||||
#define ESP_RTOS 1
|
||||
#define PBUF_RSV_FOR_WLAN 1
|
||||
#define EBUF_LWIP 1
|
||||
#define ESP_TIMEWAIT_THRESHOLD 10000
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
|
||||
#define TCP_WND (TCP_MSS * 2)
|
||||
|
||||
#define LWIP_IGMP 1
|
||||
#include <stdint.h>
|
||||
#include <esp/hwrand.h>
|
||||
#define LWIP_RAND hwrand
|
||||
|
||||
/*
|
||||
-----------------------------------------------
|
||||
---------- Platform specific locking ----------
|
||||
-----------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
||||
* critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
/**
|
||||
* MEMCPY: override this if you have a faster implementation at hand than the
|
||||
* one included in your C library
|
||||
*/
|
||||
#define MEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
|
||||
/**
|
||||
* SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a
|
||||
* call to memcpy() if the length is known at compile time and is small.
|
||||
*/
|
||||
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Memory options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library
|
||||
* instead of the lwip internal allocator. Can save code size if you
|
||||
* already use it.
|
||||
*/
|
||||
#define MEM_LIBC_MALLOC 1
|
||||
|
||||
/**
|
||||
* MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator.
|
||||
* Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution
|
||||
* speed and usage from interrupts!
|
||||
*/
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
|
||||
/**
|
||||
* MEM_ALIGNMENT: should be set to the alignment of the CPU
|
||||
* 4 byte alignment -> #define MEM_ALIGNMENT 4
|
||||
* 2 byte alignment -> #define MEM_ALIGNMENT 2
|
||||
*/
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
/*
|
||||
------------------------------------------------
|
||||
---------- Internal Memory Pool Sizes ----------
|
||||
------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
--------------------------------
|
||||
---------- ARP options -------
|
||||
--------------------------------
|
||||
*/
|
||||
/**
|
||||
* ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address
|
||||
* resolution. By default, only the most recent packet is queued per IP address.
|
||||
* This is sufficient for most protocols and mainly reduces TCP connection
|
||||
* startup time. Set this to 1 if you know your application sends more than one
|
||||
* packet in a row to an IP address that is not in the ARP cache.
|
||||
*/
|
||||
#define ARP_QUEUEING 1
|
||||
|
||||
/*
|
||||
--------------------------------
|
||||
---------- IP options ----------
|
||||
--------------------------------
|
||||
*/
|
||||
/**
|
||||
* IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that
|
||||
* this option does not affect outgoing packet sizes, which can be controlled
|
||||
* via IP_FRAG.
|
||||
*/
|
||||
#define IP_REASSEMBLY 0
|
||||
|
||||
/**
|
||||
* IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note
|
||||
* that this option does not affect incoming packet sizes, which can be
|
||||
* controlled via IP_REASSEMBLY.
|
||||
*/
|
||||
#define IP_FRAG 1
|
||||
|
||||
/**
|
||||
* IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally)
|
||||
* a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived
|
||||
* in this time, the whole packet is discarded.
|
||||
*/
|
||||
#define IP_REASS_MAXAGE 3
|
||||
|
||||
/**
|
||||
* IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled.
|
||||
* Since the received pbufs are enqueued, be sure to configure
|
||||
* PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive
|
||||
* packets even if the maximum amount of fragments is enqueued for reassembly!
|
||||
*/
|
||||
#define IP_REASS_MAX_PBUFS 10
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- ICMP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- RAW options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- DHCP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_DHCP==1: Enable DHCP module.
|
||||
*/
|
||||
#define LWIP_DHCP 1
|
||||
|
||||
#define LWIP_DHCP_BOOTP_FILE 0
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- AUTOIP options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/*
|
||||
----------------------------------
|
||||
---------- SNMP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/*
|
||||
----------------------------------
|
||||
---------- IGMP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/*
|
||||
----------------------------------
|
||||
---------- DNS options -----------
|
||||
----------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS
|
||||
* transport.
|
||||
*/
|
||||
#define LWIP_DNS 1
|
||||
|
||||
#define DNS_TABLE_SIZE 1
|
||||
#define DNS_MAX_NAME_LENGTH 128
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- UDP options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
/*
|
||||
---------------------------------
|
||||
---------- TCP options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
/**
|
||||
* TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
|
||||
* Define to 0 if your device is low on memory.
|
||||
*/
|
||||
#define TCP_QUEUE_OOSEQ 0
|
||||
|
||||
/*
|
||||
* LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all
|
||||
* events (accept, sent, etc) that happen in the system.
|
||||
* LWIP_CALLBACK_API==1: The PCB callback function is called directly
|
||||
* for the event. This is the default.
|
||||
*/
|
||||
#define TCP_MSS 1460
|
||||
|
||||
/**
|
||||
* TCP_MAXRTX: Maximum number of retransmissions of data segments.
|
||||
*/
|
||||
#define TCP_MAXRTX 6
|
||||
|
||||
|
||||
/**
|
||||
* TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
|
||||
*/
|
||||
#define TCP_SYNMAXRTX 3
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- Pbuf options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------------------
|
||||
---------- Network Interfaces options ----------
|
||||
------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data
|
||||
* to be sent into one single pbuf. This is for compatibility with DMA-enabled
|
||||
* MACs that do not support scatter-gather.
|
||||
* Beware that this might involve CPU-memcpy before transmitting that would not
|
||||
* be needed without this flag! Use this only if you need to!
|
||||
*
|
||||
* @todo: TCP and IP-frag do not work with this, yet:
|
||||
*/
|
||||
#define LWIP_NETIF_TX_SINGLE_PBUF 1
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- LOOPIF options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- SLIPIF options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Thread options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread.
|
||||
* The stack size value itself is platform-dependent, but is passed to
|
||||
* sys_thread_new() when the thread is created.
|
||||
*/
|
||||
#define TCPIP_THREAD_STACKSIZE 512 //not ok:384
|
||||
|
||||
/**
|
||||
* TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread.
|
||||
* The priority value itself is platform-dependent, but is passed to
|
||||
* sys_thread_new() when the thread is created.
|
||||
*/
|
||||
#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES-5)
|
||||
|
||||
/**
|
||||
* TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
|
||||
* The queue size value itself is platform-dependent, but is passed to
|
||||
* sys_mbox_new() when tcpip_init is called.
|
||||
*/
|
||||
#define TCPIP_MBOX_SIZE 16
|
||||
|
||||
/**
|
||||
* DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
|
||||
* NETCONN_UDP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 6
|
||||
|
||||
/**
|
||||
* DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
|
||||
* NETCONN_TCP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 6
|
||||
|
||||
/**
|
||||
* DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
|
||||
* The queue size value itself is platform-dependent, but is passed to
|
||||
* sys_mbox_new() when the acceptmbox is created.
|
||||
*/
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 6
|
||||
|
||||
/*
|
||||
----------------------------------------------
|
||||
---------- Sequential layer options ----------
|
||||
----------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Socket options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
|
||||
* SO_SNDTIMEO processing.
|
||||
*/
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
|
||||
/**
|
||||
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
|
||||
* SO_RCVTIMEO processing.
|
||||
*/
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
|
||||
/**
|
||||
* LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
|
||||
* options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
|
||||
* in seconds. (does not require sockets.c, and will affect tcp.c)
|
||||
*/
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
/**
|
||||
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
||||
*/
|
||||
#define LWIP_SO_RCVBUF 0
|
||||
|
||||
/**
|
||||
* SO_REUSE==1: Enable SO_REUSEADDR option.
|
||||
*/
|
||||
#define SO_REUSE 1
|
||||
|
||||
/*
|
||||
----------------------------------------
|
||||
---------- Statistics options ----------
|
||||
----------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- PPP options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
--------------------------------------
|
||||
---------- Checksum options ----------
|
||||
--------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
---------- IPv6 options ---------------
|
||||
---------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
---------- Hook options ---------------
|
||||
---------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
---------- Debugging options ----------
|
||||
---------------------------------------
|
||||
*/
|
||||
|
||||
// Uncomment this line, and set the individual debug options you want, for IP stack debug output
|
||||
//#define LWIP_DEBUG
|
||||
|
||||
/**
|
||||
* ETHARP_DEBUG: Enable debugging in etharp.c.
|
||||
*/
|
||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* PBUF_DEBUG: Enable debugging in pbuf.c.
|
||||
*/
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* API_LIB_DEBUG: Enable debugging in api_lib.c.
|
||||
*/
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* SOCKETS_DEBUG: Enable debugging in sockets.c.
|
||||
*/
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* IP_DEBUG: Enable debugging for IP.
|
||||
*/
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* MEMP_DEBUG: Enable debugging in memp.c.
|
||||
*/
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug.
|
||||
*/
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions.
|
||||
*/
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* UDP_DEBUG: Enable debugging in udp.c.
|
||||
*/
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* ICMP_DEBUG: Enable debugging in udp.c.
|
||||
*/
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* TCPIP_DEBUG: Enable debugging in tcpip.c.
|
||||
*/
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
|
||||
/**
|
||||
* DHCP_DEBUG: Enable debugging in dhcp.c.
|
||||
*/
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
/* Use the defaults for everything else */
|
||||
#include_next <lwipopts.h>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <string.h>
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/igmp.h>
|
||||
#include <lwip/ip_addr.h>
|
||||
#include <espressif/esp_common.h>
|
||||
#include "upnp.h"
|
||||
|
||||
|
@ -18,13 +19,13 @@ static const char* get_my_ip(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function joins a multicast group witht he specified ip/port
|
||||
* @brief This function joins a multicast group with the specified ip/port
|
||||
* @param group_ip the specified multicast group ip
|
||||
* @param group_port the specified multicast port number
|
||||
* @param recv the lwip UDP callback
|
||||
* @retval udp_pcb* or NULL if joining failed
|
||||
*/
|
||||
static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, void (* recv)(void * arg, struct udp_pcb * upcb, struct pbuf * p, struct ip_addr * addr, u16_t port))
|
||||
static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, void (* recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port))
|
||||
{
|
||||
bool status = false;
|
||||
struct udp_pcb *upcb;
|
||||
|
@ -36,7 +37,7 @@ static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, voi
|
|||
printf("Error, udp_new failed");
|
||||
break;
|
||||
}
|
||||
udp_bind(upcb, IP_ADDR_ANY, group_port);
|
||||
udp_bind(upcb, IP4_ADDR_ANY, group_port);
|
||||
struct netif* netif = sdk_system_get_netif(STATION_IF);
|
||||
if (!netif) {
|
||||
printf("Error, netif is null");
|
||||
|
@ -46,10 +47,10 @@ static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, voi
|
|||
netif->flags |= NETIF_FLAG_IGMP;
|
||||
igmp_start(netif);
|
||||
}
|
||||
ip_addr_t ipgroup;
|
||||
ipaddr_aton(group_ip, &ipgroup);
|
||||
err_t err = igmp_joingroup(&netif->ip_addr, &ipgroup);
|
||||
if(ERR_OK != err) {
|
||||
ip4_addr_t ipgroup;
|
||||
ip4addr_aton(group_ip, &ipgroup);
|
||||
err_t err = igmp_joingroup_netif(netif, &ipgroup);
|
||||
if (ERR_OK != err) {
|
||||
printf("Failed to join multicast group: %d", err);
|
||||
break;
|
||||
}
|
||||
|
@ -68,7 +69,7 @@ static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, voi
|
|||
return upcb;
|
||||
}
|
||||
|
||||
static void send(struct udp_pcb *upcb, struct ip_addr *addr, u16_t port)
|
||||
static void send_udp(struct udp_pcb *upcb, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
struct pbuf *p;
|
||||
char msg[500];
|
||||
|
@ -110,14 +111,14 @@ static void send(struct udp_pcb *upcb, struct ip_addr *addr, u16_t port)
|
|||
* @param port the remote port from which the packet was received
|
||||
* @retval None
|
||||
*/
|
||||
static void receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
|
||||
static void receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
if (p) {
|
||||
printf("Msg received port:%d len:%d\n", port, p->len);
|
||||
uint8_t *buf = (uint8_t*) p->payload;
|
||||
printf("Msg received port:%d len:%d\nbuf: %s\n", port, p->len, buf);
|
||||
|
||||
send(upcb, addr, port);
|
||||
send_udp(upcb, addr, port);
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
|
1
examples/wificfg/.gitignore
vendored
Normal file
1
examples/wificfg/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
!local.mk
|
7
examples/wificfg/FreeRTOSConfig.h
Normal file
7
examples/wificfg/FreeRTOSConfig.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configGENERATE_RUN_TIME_STATS 1
|
||||
#define portGET_RUN_TIME_COUNTER_VALUE() (RTC.COUNTER)
|
||||
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() {}
|
||||
|
||||
/* Use the defaults for everything else */
|
||||
#include_next<FreeRTOSConfig.h>
|
5
examples/wificfg/Makefile
Normal file
5
examples/wificfg/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Makefile for wificfg example
|
||||
PROGRAM=wificfg
|
||||
EXTRA_COMPONENTS=extras/dhcpserver extras/wificfg
|
||||
|
||||
include ../../common.mk
|
18
examples/wificfg/content/index.html
Normal file
18
examples/wificfg/content/index.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
"<!DOCTYPE html><html lang=\"en\">"
|
||||
"<head>"
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\">"
|
||||
"<script src=\"/script.js\"></script>"
|
||||
"<title>",
|
||||
"</title>"
|
||||
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<ul class=\"topnav\" id=\"myTopnav\">"
|
||||
"<li class=\"active\"><a href=\"/\">Home</a></li>"
|
||||
"<li><a href=\"/wificfg/\">WiFi Config</a></li>"
|
||||
"<li><a href=\"/tasks.html\">Tasks</a></li>"
|
||||
"<li class=\"icon\">"
|
||||
"<a href=\"javascript:void(0);\" onclick=\"myFunction()\">☰</a>"
|
||||
"</li>"
|
||||
"</ul>",
|
||||
"</body></html>"
|
1
examples/wificfg/local.mk
Normal file
1
examples/wificfg/local.mk
Normal file
|
@ -0,0 +1 @@
|
|||
FLASH_SIZE ?= 32
|
94
examples/wificfg/wificfg.c
Normal file
94
examples/wificfg/wificfg.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Example Wifi configuration via an access point.
|
||||
*
|
||||
* Copyright (C) 2016 OurAirQuality.org
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0, January 2004 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS WITH THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
#include <espressif/user_interface.h>
|
||||
#include <esp/uart.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
#include "wificfg/wificfg.h"
|
||||
|
||||
#include "sysparam.h"
|
||||
|
||||
static const char http_success_header[] = "HTTP/1.1 200 \r\n"
|
||||
"Content-Type: text/html; charset=utf-8\r\n"
|
||||
"Cache-Control: no-store\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n";
|
||||
static const char *http_index_content[] = {
|
||||
#include "content/index.html"
|
||||
};
|
||||
|
||||
static int handle_index(int s, wificfg_method method,
|
||||
uint32_t content_length,
|
||||
wificfg_content_type content_type,
|
||||
char *buf, size_t len)
|
||||
{
|
||||
if (wificfg_write_string(s, http_success_header) < 0) return -1;
|
||||
|
||||
if (method != HTTP_METHOD_HEAD) {
|
||||
if (wificfg_write_string_chunk(s, http_index_content[0], buf, len) < 0) return -1;
|
||||
if (wificfg_write_html_title(s, buf, len, "Home") < 0) return -1;
|
||||
if (wificfg_write_string_chunk(s, http_index_content[1], buf, len) < 0) return -1;
|
||||
|
||||
socklen_t addr_len;
|
||||
struct sockaddr addr;
|
||||
addr_len = sizeof(addr);
|
||||
getpeername(s, (struct sockaddr*)&addr, &addr_len);
|
||||
|
||||
if (wificfg_write_string_chunk(s, "<dl class=\"dlh\">", buf, len) < 0) return -1;
|
||||
if (addr.sa_family == AF_INET) {
|
||||
struct sockaddr_in *sa = (struct sockaddr_in *)&addr;
|
||||
if (wificfg_write_string_chunk(s, "<dt>Peer address</dt>", buf, len) < 0) return -1;
|
||||
snprintf(buf, len, "<dd>" IPSTR " : %d</dd>",
|
||||
IP2STR((ip4_addr_t *)&sa->sin_addr.s_addr), ntohs(sa->sin_port));
|
||||
if (wificfg_write_string_chunk(s, buf, buf, len) < 0) return -1;
|
||||
}
|
||||
|
||||
if (wificfg_write_string_chunk(s, "</dl>", buf, len) < 0) return -1;
|
||||
if (wificfg_write_string_chunk(s, http_index_content[2], buf, len) < 0) return -1;
|
||||
if (wificfg_write_chunk_end(s) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const wificfg_dispatch dispatch_list[] = {
|
||||
{"/", HTTP_METHOD_GET, handle_index, false},
|
||||
{"/index.html", HTTP_METHOD_GET, handle_index, false},
|
||||
{NULL, HTTP_METHOD_ANY, NULL}
|
||||
};
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
sdk_wifi_set_sleep_type(WIFI_SLEEP_MODEM);
|
||||
|
||||
wificfg_init(80, dispatch_list);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue