Restored DNS functionality. Simulating random StreetPass encounters.
This commit is contained in:
parent
e215eb061c
commit
3b6a2d8905
@ -32,6 +32,7 @@ config_load_default(sysconfig_p config)
|
||||
config->client_watchdog = -1;
|
||||
|
||||
IP4_ADDR(&config->network_addr, 192, 168, 4, 1);
|
||||
config->dns_addr.addr = 0; // use DHCP
|
||||
config->my_addr.addr = 0; // use DHCP
|
||||
config->my_netmask.addr = 0; // use DHCP
|
||||
config->my_gw.addr = 0; // use DHCP
|
||||
@ -45,10 +46,14 @@ config_load_default(sysconfig_p config)
|
||||
|
||||
config->dhcps_entries = 0;
|
||||
|
||||
// Interval to change mac address in seconds
|
||||
// Default: 3600 (1 hour)
|
||||
// This should rotate every mac address in the list roughly every 16 hours.
|
||||
config->mac_change_interval = 3600;
|
||||
// NOTE(m): Interval at which to restart the system to select a new
|
||||
// random StreetPass MAC from the list.
|
||||
// In seconds. Default: 900 (15 minutes)
|
||||
config->system_restart_interval = 900;
|
||||
|
||||
// NOTE(m): How long to keep the "attwifi" AP up during one MAC cycle
|
||||
// In seconds. Default: 90 seconds.
|
||||
config->ap_enable_duration = 90;
|
||||
|
||||
// list of mac addresses
|
||||
// from https://docs.google.com/spreadsheets/d/1su5u-vPrQwkTixR6YnOTWSi_Ls9lV-_XNJHaWIJspv4/edit#gid=0
|
||||
|
||||
@ -35,8 +35,11 @@ typedef struct
|
||||
uint8_t bssid[6]; // Optional: BSSID the AP
|
||||
uint8_t sta_hostname[32]; // Name of the station
|
||||
uint8_t ap_ssid[32]; // SSID of the own AP
|
||||
|
||||
// ESPerPass specific configuration
|
||||
uint8_t first_run; // Has ESPerPass been configured yet?
|
||||
int32_t mac_change_interval; // Interval to rotate HomePass mac address (in seconds)
|
||||
int32_t system_restart_interval;
|
||||
int32_t ap_enable_duration;
|
||||
|
||||
// Seconds without ap traffic will cause reset (-1 off, default)
|
||||
int32_t ap_watchdog;
|
||||
@ -44,6 +47,7 @@ typedef struct
|
||||
int32_t client_watchdog;
|
||||
|
||||
ip_addr_t network_addr; // Address of the internal network
|
||||
ip_addr_t dns_addr; // Optional: address of the dns server
|
||||
|
||||
ip_addr_t my_addr; // Optional (if not DHCP): IP address of the uplink side
|
||||
ip_addr_t my_netmask; // Optional (if not DHCP): IP netmask of the uplink side
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#ifndef _USER_CONFIG_
|
||||
#define _USER_CONFIG_
|
||||
|
||||
#define ESPERPASS_VERSION "V0.0.6"
|
||||
#define ESPERPASS_VERSION "V0.1.0"
|
||||
|
||||
#define WIFI_SSID "ssid"
|
||||
#define WIFI_PASSWORD "password"
|
||||
|
||||
104
user/user_main.c
104
user/user_main.c
@ -6,6 +6,7 @@
|
||||
#include "os_type.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/lwip_napt.h"
|
||||
#include "lwip/app/dhcpserver.h"
|
||||
#include "lwip/app/espconn.h"
|
||||
@ -32,7 +33,8 @@ static os_timer_t ptimer;
|
||||
|
||||
int32_t ap_watchdog_cnt;
|
||||
int32_t client_watchdog_cnt;
|
||||
int32_t mac_cnt;
|
||||
int32_t awake_cnt = 0;
|
||||
int32_t ap_enabled_cnt = 0;
|
||||
|
||||
/* Some stats */
|
||||
uint64_t Bytes_in, Bytes_out, Bytes_in_last, Bytes_out_last;
|
||||
@ -45,6 +47,7 @@ sysconfig_t config;
|
||||
static ringbuf_t console_rx_buffer, console_tx_buffer;
|
||||
|
||||
static ip_addr_t my_ip;
|
||||
static ip_addr_t dns_ip;
|
||||
bool connected;
|
||||
uint8_t my_channel;
|
||||
bool do_ip_config;
|
||||
@ -311,7 +314,7 @@ console_handle_command(struct espconn *pespconn)
|
||||
os_sprintf(response, "show [config|stats]\r\n");
|
||||
to_console(response);
|
||||
|
||||
os_sprintf(response, "set [ssid|password|auto_connect|ap_ssid] <val>\r\nset [sta_mac|sta_hostname] <val>\r\nset [ip|netmask|gw] <val>\r\n");
|
||||
os_sprintf(response, "set [ssid|password|auto_connect|ap_ssid] <val>\r\nset [sta_mac|sta_hostname] <val>\r\nset [dns|ip|netmask|gw] <val>\r\n");
|
||||
to_console(response);
|
||||
os_sprintf(response, "set [speed|status_led|config_port] <val>\r\nsave [config|dhcp]\r\nconnect | disconnect| reset [factory] | quit\r\n");
|
||||
to_console(response);
|
||||
@ -375,6 +378,12 @@ console_handle_command(struct espconn *pespconn)
|
||||
IP2STR(&config.network_addr));
|
||||
to_console(response);
|
||||
|
||||
// if static DNS, add it
|
||||
os_sprintf(response,
|
||||
config.dns_addr.addr?" DNS: %d.%d.%d.%d\r\n":"\r\n",
|
||||
IP2STR(&config.dns_addr));
|
||||
to_console(response);
|
||||
|
||||
// if static IP, add it
|
||||
os_sprintf(response,
|
||||
config.my_addr.addr?"Static IP: %d.%d.%d.%d Netmask: %d.%d.%d.%d Gateway: %d.%d.%d.%d\r\n":"",
|
||||
@ -757,6 +766,27 @@ console_handle_command(struct espconn *pespconn)
|
||||
goto command_handled;
|
||||
}
|
||||
|
||||
if (strcmp(tokens[1], "dns") == 0)
|
||||
{
|
||||
if (os_strcmp(tokens[2], "dhcp") == 0)
|
||||
{
|
||||
config.dns_addr.addr = 0;
|
||||
os_sprintf(response, "DNS from DHCP\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
config.dns_addr.addr = ipaddr_addr(tokens[2]);
|
||||
os_sprintf(response, "DNS set to %d.%d.%d.%d\r\n",
|
||||
IP2STR(&config.dns_addr));
|
||||
if (config.dns_addr.addr)
|
||||
{
|
||||
dns_ip.addr = config.dns_addr.addr;
|
||||
dhcps_set_DNS(&dns_ip);
|
||||
}
|
||||
}
|
||||
goto command_handled;
|
||||
}
|
||||
|
||||
if (strcmp(tokens[1], "ip") == 0)
|
||||
{
|
||||
if (os_strcmp(tokens[2], "dhcp") == 0)
|
||||
@ -859,33 +889,34 @@ timer_func(void *arg)
|
||||
// Check if watchdogs
|
||||
if (toggle)
|
||||
{
|
||||
// Rotate HomePass mac address if necessary
|
||||
if (config.auto_connect == 1)
|
||||
{
|
||||
if (mac_cnt >= config.mac_change_interval)
|
||||
// NOTE(m): Restart the system after a while to set a new random
|
||||
// StreetPass MAC address from the list.
|
||||
if (awake_cnt >= config.system_restart_interval)
|
||||
{
|
||||
mac_cnt = 0;
|
||||
|
||||
os_printf("Changing mac address.\r\n");
|
||||
os_printf("Old index: %d\r\n\r\n", current_mac_address_index);
|
||||
|
||||
if (current_mac_address_index >= MAC_LIST_LENGTH - 1)
|
||||
{
|
||||
current_mac_address_index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_mac_address_index++;
|
||||
}
|
||||
|
||||
os_printf("New index: %d\r\n", current_mac_address_index);
|
||||
|
||||
// Start using new mac address
|
||||
wifi_set_macaddr(SOFTAP_IF, config.mac_list[current_mac_address_index]);
|
||||
system_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
mac_cnt++;
|
||||
awake_cnt++;
|
||||
}
|
||||
|
||||
// NOTE(m): Switch off the access point after a while if
|
||||
// it's not switched off already.
|
||||
if (wifi_get_opmode() == STATIONAP_MODE)
|
||||
{
|
||||
if (ap_enabled_cnt >= config.ap_enable_duration)
|
||||
{
|
||||
ap_enabled_cnt = 0;
|
||||
{
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ap_enabled_cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1003,10 +1034,17 @@ wifi_handle_event_cb(System_Event_t *evt)
|
||||
|
||||
case EVENT_STAMODE_GOT_IP:
|
||||
{
|
||||
os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n",
|
||||
if (config.dns_addr.addr == 0)
|
||||
{
|
||||
dns_ip = dns_getserver(0);
|
||||
}
|
||||
dhcps_set_DNS(&dns_ip);
|
||||
|
||||
os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR ",dns:" IPSTR "\n",
|
||||
IP2STR(&evt->event_info.got_ip.ip),
|
||||
IP2STR(&evt->event_info.got_ip.mask),
|
||||
IP2STR(&evt->event_info.got_ip.gw));
|
||||
IP2STR(&evt->event_info.got_ip.gw),
|
||||
IP2STR(&dns_ip));
|
||||
|
||||
my_ip = evt->event_info.got_ip.ip;
|
||||
connected = true;
|
||||
@ -1100,6 +1138,9 @@ user_set_softap_ip_config(void)
|
||||
|
||||
wifi_softap_dhcps_start();
|
||||
|
||||
// Change the DNS server again
|
||||
dhcps_set_DNS(&dns_ip);
|
||||
|
||||
// Enter any saved dhcp enties if they are in this network
|
||||
for (i = 0; i<config.dhcps_entries; i++)
|
||||
{
|
||||
@ -1187,6 +1228,18 @@ user_init()
|
||||
easygpio_outputSet (config.status_led, 0);
|
||||
}
|
||||
|
||||
// Configure the AP and start it, if required
|
||||
if (config.dns_addr.addr == 0)
|
||||
{
|
||||
// Google's DNS as default, as long as we havn't got one from DHCP
|
||||
IP4_ADDR(&dns_ip, 8, 8, 8, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a static DNS server
|
||||
dns_ip.addr = config.dns_addr.addr;
|
||||
}
|
||||
|
||||
wifi_set_opmode(STATIONAP_MODE);
|
||||
wifi_set_macaddr(SOFTAP_IF, config.mac_list[current_mac_address_index]);
|
||||
user_set_softap_wifi_config();
|
||||
@ -1205,6 +1258,7 @@ user_init()
|
||||
info.gw.addr = config.my_gw.addr;
|
||||
info.netmask.addr = config.my_netmask.addr;
|
||||
wifi_set_ip_info(STATION_IF, &info);
|
||||
espconn_dns_setserver(0, &dns_ip);
|
||||
}
|
||||
|
||||
remote_console_disconnect = 0;
|
||||
|
||||
Reference in New Issue
Block a user