Added HW reset

This commit is contained in:
Martin Ger
2018-03-18 10:51:08 +01:00
parent 1c4e3311a3
commit c083d58e6e
10 changed files with 59 additions and 26 deletions

View File

@@ -42,7 +42,9 @@ If you are not using automesh, you can now reload the page and change the "Soft
If you like, you can mark the "lock" checkbox and click "Lock". Now the config cannot be changed anymore without first unlocking it with the uplink WiFi network's password (define one even if the network is open).
If you did a mistake and you lost any contact with ESP you can still use the serial console to recover it ("reset facory", see below).
If you want to enter non-ASCII or special characters in the web interface you have to use HTTP-style hex encoding like "My%20AccessPoint". This will result in a string "My AccessPoint". With this hex encoding you can enter any byte value you like, except for 0 (for C-internal reasons).
If you did a mistake and you lost any contact with the ESP you can still use the serial console to recover it ("reset facory", see below).
# Command Line Interface
Advanced configuration has to be done via the command line on the console interface. This console is available either via the serial port at 115200 baud or via tcp port 7777 (e.g. "telnet 192.168.4.1 7777" from a connected STA).
@@ -56,7 +58,7 @@ Use the following commands for an initial setup:
- save
- reset
If you want to enter non-ASCII or special characters on the command line you can use quoting: either use C-style quotes with backslash like this "My\ AccessPoint" or use HTTP-style hex encoding like "My%20AccessPoint". Both methods will result in a string "My AccessPoint". With the hex encoding you can enter any byte value you like, except for 0 (for C-internal reasons).
Again, if you want to enter non-ASCII or special characters you can use HTTP-style hex encoding (e.g. "My%20AccessPoint") or, only on the CLI, as shortcut C-style quotes with backslash (e.g. "My\ AccessPoint"). Both methods will result in a string "My AccessPoint".
The command line understands a lot more commands:
@@ -144,6 +146,9 @@ In default config GPIO2 is configured to drive a status LED (connected to GND) w
With "set status_led GPIOno" the GPIO pin can be changed (any value > 16, e.g. "set status_led 255" will disable the status LED completely). When configured to GPIO1, it works with the buildin blue LED on the ESP-01 boards. However, as GPIO1 ist also the UART-TX-pin this means, that the serial console is not working. Configuration is then limited to network access.
# HW reset
If you pull low GPIO 0 for more than 2 seconds, the repeater will do a factory reset and restarts with default config.
# Port Mapping
In order to allow clients from the external network to connect to server port on the internal network, ports have to be mapped. An external port is mapped to an internal port of a specific internal IP address. Use the "portmap add" command for that. Port mappings can be listed with the "show" command and are saved with the current config.

View File

@@ -235,6 +235,8 @@ int UART_Send(uint8 uart_no, char *buffer, int len)
ch = *(buffer+index);
uart_tx_one_char(uart_no, ch);
}
return index;
}
/*---------------------------------------------------------------------------*

Binary file not shown.

Binary file not shown.

View File

@@ -1,2 +1,2 @@
fd905b6e4a6a3a3805502d267c654a56725217b8 0x00000.bin
20d51455fc4c50825310f63ba7249e86745b0482 0x10000.bin
2afacd52bae0132ccd8bd34829c90b37632befec 0x00000.bin
ff3bc6339dfb81c3c188816ef021c1981ac5cca6 0x10000.bin

View File

@@ -127,7 +127,7 @@ uint8_t allow;
switch (proto) {
case IP_PROTO_UDP:
if (p->len < sizeof(struct eth_hdr)+sizeof(struct ip_hdr)+sizeof(struct udp_hdr))
return;
return ACL_DENY;
udp_h = (struct udp_hdr *)&packet[sizeof(struct eth_hdr)+sizeof(struct ip_hdr)];
src_port = ntohs(udp_h->src);
dest_port = ntohs(udp_h->dest);
@@ -135,7 +135,7 @@ uint8_t allow;
case IP_PROTO_TCP:
if (p->len < sizeof(struct eth_hdr)+sizeof(struct ip_hdr)+sizeof(struct tcp_hdr))
return;
return ACL_DENY;
tcp_h = (struct tcp_hdr *)&packet[sizeof(struct eth_hdr)+sizeof(struct ip_hdr)];
src_port = ntohs(tcp_h->src);
dest_port = ntohs(tcp_h->dest);

View File

@@ -9,7 +9,7 @@
* time at least. When you want to change some data in flash, you have to
* erase the whole sector, and then write it back with the new data.
*--------------------------------------------------------------------------*/
void config_load_default(sysconfig_p config)
void ICACHE_FLASH_ATTR config_load_default(sysconfig_p config)
{
uint8_t mac[6];
@@ -101,7 +101,7 @@ uint8_t mac[6];
#endif
}
int config_load(sysconfig_p config)
int ICACHE_FLASH_ATTR config_load(sysconfig_p config)
{
if (config == NULL) return -1;
uint16_t base_address = FLASH_BLOCK_NO;
@@ -136,7 +136,7 @@ int config_load(sysconfig_p config)
return 0;
}
void config_save(sysconfig_p config)
void ICACHE_FLASH_ATTR config_save(sysconfig_p config)
{
uint16_t base_address = FLASH_BLOCK_NO;
config->no_routes = ip_route_max;
@@ -151,20 +151,20 @@ void config_save(sysconfig_p config)
spi_flash_write(base_address * SPI_FLASH_SEC_SIZE, (uint32 *)config, sizeof(sysconfig_t));
}
void blob_save(uint8_t blob_no, uint32_t *data, uint16_t len)
void ICACHE_FLASH_ATTR blob_save(uint8_t blob_no, uint32_t *data, uint16_t len)
{
uint16_t base_address = FLASH_BLOCK_NO + 1 + blob_no;
spi_flash_erase_sector(base_address);
spi_flash_write(base_address * SPI_FLASH_SEC_SIZE, data, len);
}
void blob_load(uint8_t blob_no, uint32_t *data, uint16_t len)
void ICACHE_FLASH_ATTR blob_load(uint8_t blob_no, uint32_t *data, uint16_t len)
{
uint16_t base_address = FLASH_BLOCK_NO + 1 + blob_no;
spi_flash_read(base_address * SPI_FLASH_SEC_SIZE, data, len);
}
void blob_zero(uint8_t blob_no, uint16_t len)
void ICACHE_FLASH_ATTR blob_zero(uint8_t blob_no, uint16_t len)
{
int i;
uint8_t z[len];

View File

@@ -120,6 +120,7 @@ typedef struct
} sysconfig_t, *sysconfig_p;
int config_load(sysconfig_p config);
void config_load_default(sysconfig_p config);
void config_save(sysconfig_p config);
void blob_save(uint8_t blob_no, uint32_t *data, uint16_t len);

View File

@@ -23,7 +23,7 @@
//
// Size of the console buffers
//
#define MAX_CON_SEND_SIZE 1024
#define MAX_CON_SEND_SIZE 1200
#define MAX_CON_CMD_SIZE 80
//
@@ -31,6 +31,11 @@
//
#define STATUS_LED_GIPO 2
//
// Define this if you want to have a HW factory reset when this GPIO is pulled low
//
#define FACTORY_RESET_PIN 0
//
// Define this to support the "scan" command for AP search
//

View File

@@ -427,7 +427,7 @@ err_t ICACHE_FLASH_ATTR my_input_ap (struct pbuf *p, struct netif *inp) {
if (put_packet_to_ringbuf(p) != 0) {
#ifdef DROP_PACKET_IF_NOT_RECORDED
pbuf_free(p);
return;
return ERR_OK;
#endif
}
if (!monitoring_send_ongoing)
@@ -447,7 +447,7 @@ err_t ICACHE_FLASH_ATTR my_input_ap (struct pbuf *p, struct netif *inp) {
// If not allowed, drop packet
if (!(acl_check&ACL_ALLOW)) {
pbuf_free(p);
return;
return ERR_OK;
};
#endif
@@ -457,7 +457,7 @@ err_t ICACHE_FLASH_ATTR my_input_ap (struct pbuf *p, struct netif *inp) {
token_bucket_us -= p->tot_len;
} else {
pbuf_free(p);
return;
return ERR_OK;
}
}
#endif
@@ -465,7 +465,7 @@ err_t ICACHE_FLASH_ATTR my_input_ap (struct pbuf *p, struct netif *inp) {
Bytes_in += p->tot_len;
Packets_in++;
orig_input_ap (p, inp);
return orig_input_ap (p, inp);
}
err_t ICACHE_FLASH_ATTR my_output_ap (struct netif *outp, struct pbuf *p) {
@@ -487,7 +487,7 @@ err_t ICACHE_FLASH_ATTR my_output_ap (struct netif *outp, struct pbuf *p) {
if (put_packet_to_ringbuf(p) != 0) {
#ifdef DROP_PACKET_IF_NOT_RECORDED
pbuf_free(p);
return;
return ERR_OK;
#endif
}
if (!monitoring_send_ongoing)
@@ -508,7 +508,7 @@ err_t ICACHE_FLASH_ATTR my_output_ap (struct netif *outp, struct pbuf *p) {
// If not allowed, drop packet
if (!(acl_check&ACL_ALLOW)) {
pbuf_free(p);
return;
return ERR_OK;
};
#endif
@@ -518,7 +518,7 @@ err_t ICACHE_FLASH_ATTR my_output_ap (struct netif *outp, struct pbuf *p) {
token_bucket_ds -= p->tot_len;
} else {
pbuf_free(p);
return;
return ERR_OK;
}
}
#endif
@@ -526,30 +526,29 @@ err_t ICACHE_FLASH_ATTR my_output_ap (struct netif *outp, struct pbuf *p) {
Bytes_out += p->tot_len;
Packets_out++;
orig_output_ap (outp, p);
return orig_output_ap (outp, p);
}
err_t ICACHE_FLASH_ATTR my_input_sta (struct pbuf *p, struct netif *inp) {
ap_watchdog_cnt = config.ap_watchdog;
#ifdef ACLS
if (!acl_is_empty(2) && !(acl_check_packet(2, p) & ACL_ALLOW)) {
pbuf_free(p);
return;
return ERR_OK;
};
#endif
orig_input_sta (p, inp);
return orig_input_sta (p, inp);
}
err_t ICACHE_FLASH_ATTR my_output_sta (struct netif *outp, struct pbuf *p) {
#ifdef ACLS
if (!acl_is_empty(3) && !(acl_check_packet(3, p) & ACL_ALLOW)) {
pbuf_free(p);
return;
return ERR_OK;
};
#endif
orig_output_sta (outp, p);
return orig_output_sta (outp, p);
}
static void ICACHE_FLASH_ATTR patch_netif(ip_addr_t netif_ip, netif_input_fn ifn, netif_input_fn *orig_ifn, netif_linkoutput_fn ofn, netif_linkoutput_fn *orig_ofn, bool nat)
@@ -2428,6 +2427,23 @@ uint32_t Bps;
}
}
#ifdef FACTORY_RESET_PIN
static count_pin;
bool pin_in = easygpio_inputGet(FACTORY_RESET_PIN);
if (!pin_in) {
count_pin++;
if (count_pin > 4) {
os_printf("Factory reset pressed\r\n");
config_load_default(&config);
config_save(&config);
blob_zero(0, sizeof(struct portmap_table) * IP_PORTMAP_MAX);
system_restart();
}
} else {
count_pin = 0;
}
#endif
if (config.status_led <= 16)
easygpio_outputSet (config.status_led, toggle && connected);
@@ -3026,6 +3042,10 @@ struct ip_info info;
easygpio_outputSet (config.status_led, 0);
}
#ifdef FACTORY_RESET_PIN
easygpio_pinMode(FACTORY_RESET_PIN, EASYGPIO_PULLUP, EASYGPIO_INPUT);
#endif
#ifdef MQTT_CLIENT
#ifdef USER_GPIO_IN
easygpio_pinMode(USER_GPIO_IN, EASYGPIO_PULLUP, EASYGPIO_INPUT);