Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions board/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DFU_UTIL = "dfu-util"

# this no longer pushes the bootstub
flash: obj/$(PROJ_NAME).bin
PYTHONPATH=../ python -c "from panda import Panda; Panda().flash('obj/$(PROJ_NAME).bin')"
PYTHONPATH=../ python -c "from python import Panda; Panda().flash('obj/$(PROJ_NAME).bin')"

ota: obj/$(PROJ_NAME).bin
curl http://192.168.0.10/stupdate --upload-file $<
Expand All @@ -26,7 +26,7 @@ bin: obj/$(PROJ_NAME).bin

# this flashes everything
recover: obj/bootstub.$(PROJ_NAME).bin obj/$(PROJ_NAME).bin
-PYTHONPATH=../ python -c "from panda import Panda; Panda().reset(enter_bootloader=True)"
-PYTHONPATH=../ python -c "from python import Panda; Panda().reset(enter_bootloader=True)"
sleep 1.0
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.$(PROJ_NAME).bin
Expand Down
80 changes: 45 additions & 35 deletions boardesp/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
_a > _b ? _a : _b; })

char ssid[32];
char password[] = "testing123";
int wifi_secure_mode = 0;

static const int pin = 2;

// Structure holding the TCP connection information.
Expand Down Expand Up @@ -218,11 +221,50 @@ void ICACHE_FLASH_ATTR inter_recv_cb(void *arg, char *pusrdata, unsigned short l
}
}

void ICACHE_FLASH_ATTR wifi_configure(int secure) {
wifi_secure_mode = secure;

// start wifi AP
wifi_set_opmode(SOFTAP_MODE);
struct softap_config config = {0};
wifi_softap_get_config(&config);
strcpy(config.ssid, ssid);
if (wifi_secure_mode == 0) strcat(config.ssid, "-pair");
strcpy(config.password, password);
config.ssid_len = strlen(config.ssid);
config.authmode = wifi_secure_mode ? AUTH_WPA2_PSK : AUTH_OPEN;
config.beacon_interval = 100;
config.max_connection = 4;
wifi_softap_set_config(&config);

if (wifi_secure_mode) {
// setup tcp server
tcp_proto.local_port = 1337;
tcp_conn.type = ESPCONN_TCP;
tcp_conn.state = ESPCONN_NONE;
tcp_conn.proto.tcp = &tcp_proto;
espconn_regist_connectcb(&tcp_conn, tcp_connect_cb);
espconn_accept(&tcp_conn);
espconn_regist_time(&tcp_conn, 60, 0); // 60s timeout for all connections

// setup inter server
inter_proto.local_port = 1338;
const char udp_remote_ip[4] = {255, 255, 255, 255};
os_memcpy(inter_proto.remote_ip, udp_remote_ip, 4);
inter_proto.remote_port = 1338;

inter_conn.type = ESPCONN_UDP;
inter_conn.proto.udp = &inter_proto;

espconn_regist_recvcb(&inter_conn, inter_recv_cb);
espconn_create(&inter_conn);
}
}

void ICACHE_FLASH_ATTR wifi_init() {
// default ssid and password
memset(ssid, 0, 32);
os_sprintf(ssid, "panda-%08x-BROKEN", system_get_chip_id());
char password[] = "testing123";

// fetch secure ssid and password
// update, try 20 times, for 1 second
Expand All @@ -242,19 +284,7 @@ void ICACHE_FLASH_ATTR wifi_init() {
os_delay_us(50000);
}

// start wifi AP
wifi_set_opmode(SOFTAP_MODE);
struct softap_config config;
wifi_softap_get_config(&config);
strcpy(config.ssid, ssid);
strcpy(config.password, password);
config.ssid_len = strlen(ssid);
config.authmode = AUTH_WPA2_PSK;
config.beacon_interval = 100;
config.max_connection = 4;
wifi_softap_set_config(&config);

//set IP
// set IP
wifi_softap_dhcps_stop(); //stop DHCP before setting static IP
struct ip_info ip_config;
IP4_ADDR(&ip_config.ip, 192, 168, 0, 10);
Expand All @@ -265,27 +295,7 @@ void ICACHE_FLASH_ATTR wifi_init() {
wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &stupid_gateway);
wifi_softap_dhcps_start();

// setup tcp server
tcp_proto.local_port = 1337;
tcp_conn.type = ESPCONN_TCP;
tcp_conn.state = ESPCONN_NONE;
tcp_conn.proto.tcp = &tcp_proto;
espconn_regist_connectcb(&tcp_conn, tcp_connect_cb);
espconn_accept(&tcp_conn);
espconn_regist_time(&tcp_conn, 60, 0); // 60s timeout for all connections

// setup inter server
inter_proto.local_port = 1338;
const char udp_remote_ip[4] = {255, 255, 255, 255};
os_memcpy(inter_proto.remote_ip, udp_remote_ip, 4);
inter_proto.remote_port = 1338;

inter_conn.type = ESPCONN_UDP;
inter_conn.proto.udp = &inter_proto;

espconn_regist_recvcb(&inter_conn, inter_recv_cb);

espconn_create(&inter_conn);
wifi_configure(0);
}

#define LOOP_PRIO 2
Expand Down
12 changes: 7 additions & 5 deletions boardesp/webserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ char OK_header[] = "HTTP/1.0 200 OK\nContent-Type: text/html\n\n";
static struct espconn web_conn;
static esp_tcp web_proto;
extern char ssid[];
extern int wifi_secure_mode;

char *st_firmware;
int real_content_length, content_length = 0;
Expand Down Expand Up @@ -215,8 +216,9 @@ static void ICACHE_FLASH_ATTR web_rx_cb(void *arg, char *data, uint16_t len) {

espconn_send_string(&web_conn, resp);
espconn_disconnect(conn);

} else if (memcmp(data, "GET /set_property?usb_mode=", 27) == 0) {
} else if (memcmp(data, "GET /secure", 11) == 0 && !wifi_secure_mode) {
wifi_configure(1);
} else if (memcmp(data, "GET /set_property?usb_mode=", 27) == 0 && wifi_secure_mode) {
char mode_value = data[27] - '0';
if (mode_value >= '\x00' && mode_value <= '\x02') {
memset(resp, 0, MAX_RESP);
Expand All @@ -228,7 +230,7 @@ static void ICACHE_FLASH_ATTR web_rx_cb(void *arg, char *data, uint16_t len) {
espconn_send_string(&web_conn, resp);
espconn_disconnect(conn);
}
} else if (memcmp(data, "PUT /stupdate ", 14) == 0) {
} else if (memcmp(data, "PUT /stupdate ", 14) == 0 && wifi_secure_mode) {
os_printf("init st firmware\n");
char *cl = strstr(data, "Content-Length: ");
if (cl != NULL) {
Expand All @@ -244,8 +246,8 @@ static void ICACHE_FLASH_ATTR web_rx_cb(void *arg, char *data, uint16_t len) {
state = RECEIVING_ST_FIRMWARE;
}

} else if ((memcmp(data, "PUT /espupdate1 ", 16) == 0) ||
(memcmp(data, "PUT /espupdate2 ", 16) == 0)) {
} else if (((memcmp(data, "PUT /espupdate1 ", 16) == 0) ||
(memcmp(data, "PUT /espupdate2 ", 16) == 0)) && wifi_secure_mode) {
// 0x1000 = user1.bin
// 0x81000 = user2.bin
// 0x3FE000 = blank.bin
Expand Down