diff --git a/software/io/wifi/wifi.cc b/software/io/wifi/wifi.cc index 2df2ba61a..564a4e768 100644 --- a/software/io/wifi/wifi.cc +++ b/software/io/wifi/wifi.cc @@ -433,7 +433,7 @@ void BrowsableWifiAP :: fetch_context_items(IndexedList&items) SubsysResultCode_e BrowsableWifiAP :: connect_ap(SubsysCommand *cmd) { - char password[64] = { 0 }; + char password[65] = { 0 }; // string_box takes 64 characters plus the terminator BrowsableWifiAP *bap = (BrowsableWifiAP *)cmd->functionID; if (bap->auth) { if(cmd->user_interface) { diff --git a/software/u64ctrl/main/rpc_dispatch.c b/software/u64ctrl/main/rpc_dispatch.c index 5c010bff7..db3771ce2 100644 --- a/software/u64ctrl/main/rpc_dispatch.c +++ b/software/u64ctrl/main/rpc_dispatch.c @@ -112,7 +112,9 @@ void cmd_wifi_connect(command_buf_t *buf) ev.command = CMD_WIFI_CONNECT; ev.auth_mode = param->auth_mode; memcpy(&ev.ssid, param->ssid, 32); + ev.ssid[32] = 0; memcpy(&ev.pw, param->password, 64); + ev.pw[64] = 0; if (xQueueSend(connect_commands, &ev, 1000) == pdFALSE) { resp->esp_err = ESP_ERR_NO_MEM; diff --git a/software/u64ctrl/main/rpc_dispatch.h b/software/u64ctrl/main/rpc_dispatch.h index f385ff7c4..c4a995d1a 100644 --- a/software/u64ctrl/main/rpc_dispatch.h +++ b/software/u64ctrl/main/rpc_dispatch.h @@ -26,8 +26,10 @@ void start_dispatch(QueueHandle_t queue); void send_button_event(uint8_t button); void send_keepalive(); -#define IDENT_STRING "ESP32 WiFi Bridge V1.19" +#define IDENT_STRING "ESP32 WiFi Bridge V1.20" #define IDENT_MAJOR 1 +// 1.20: terminates 32-character SSIDs and 64-character passwords, and reads +// them back from NVS whole. // 1.19: a recovery also tries the my_hotspot access point after the stored ones. // 1.18: recovers the firmware over Wi-Fi when the switch is held down for three // seconds while off, and stores the recovery server the menu sets. @@ -38,7 +40,7 @@ void send_keepalive(); // when this is higher than what the module reports, so a module change that // does not bump it is silently never installed, and an older release never // replaces a newer module. -#define IDENT_MINOR 19 +#define IDENT_MINOR 20 #define MULTITHREADED 0 #define DISPATCHER_STACK 3072 diff --git a/software/u64ctrl/main/wifi_modem.c b/software/u64ctrl/main/wifi_modem.c index 1be27d7cb..6b1020a98 100644 --- a/software/u64ctrl/main/wifi_modem.c +++ b/software/u64ctrl/main/wifi_modem.c @@ -474,8 +474,8 @@ esp_err_t wifi_store_ap(ConnectCommand_t *cmd) key[0] = 's'; key[1] = 'a' + i; key[2] = '0'; // SSID sa, sb, sc, sd, ... - size_t len = 32; - char ssid_buf[32]; + size_t len = 33; + char ssid_buf[33]; // see if the ssid has been stored already err = nvs_get_str(handle, key, ssid_buf, &len); if (err != ESP_OK) { // nope, it doesn't exist @@ -650,10 +650,10 @@ esp_err_t wifi_connect_to_scanned(int index) // now look up password err = ESP_OK; if (ap_info[index].authmode) { - err = wifi_find_password(ap_info[index].ssid, last_connect.pw, 64, &last_connect.list_index); + err = wifi_find_password(ap_info[index].ssid, last_connect.pw, sizeof(last_connect.pw), &last_connect.list_index); } else { // no authentication required. But make sure the user has configured this AP. - err = wifi_find_password(ap_info[index].ssid, last_connect.pw, 64, &last_connect.list_index); + err = wifi_find_password(ap_info[index].ssid, last_connect.pw, sizeof(last_connect.pw), &last_connect.list_index); if ((err == ESP_OK) && (last_connect.pw[0] != 0)) { // AP is known and configured, however, with a password. Do not allow to connect. err = ESP_ERR_NOT_FOUND; @@ -661,6 +661,7 @@ esp_err_t wifi_connect_to_scanned(int index) } if (err == ESP_OK) { // known AP found strncpy(last_connect.ssid, (const char *)(ap_info[index].ssid), 32); + last_connect.ssid[32] = 0; last_connect.auth_mode = ap_info[index].authmode; return attempt_connect(last_connect.ssid, last_connect.pw, last_connect.auth_mode); } @@ -687,11 +688,11 @@ esp_err_t wifi_connect_to_stored(int index) key[1] = 'a' + index; key[2] = '0'; // SSID sa, sb, sc, sd, ... - size_t len = 32; + size_t len = sizeof(last_connect.ssid); err = nvs_get_str(handle, key, last_connect.ssid, &len); if (err == ESP_OK) { key[0] = 'p'; // password pa, pb, pc, pd, ... - len = 64; + len = sizeof(last_connect.pw); err = nvs_get_str(handle, key, last_connect.pw, &len); if (err == ESP_OK) { key[0] = 'm'; // authmode ma, mb, mc, md, ... diff --git a/software/u64ctrl/main/wifi_modem.h b/software/u64ctrl/main/wifi_modem.h index 8328dab24..643334acd 100644 --- a/software/u64ctrl/main/wifi_modem.h +++ b/software/u64ctrl/main/wifi_modem.h @@ -7,7 +7,7 @@ extern QueueHandle_t connect_commands; extern SemaphoreHandle_t connect_semaphore; typedef struct { - char ssid[32]; + char ssid[33]; // 32 SSID bytes plus the terminator char pw[68]; uint8_t auth_mode; uint8_t command; diff --git a/software/wifi/raw_c3/main/rpc_dispatch.c b/software/wifi/raw_c3/main/rpc_dispatch.c index 54fa6263f..ab24b9811 100644 --- a/software/wifi/raw_c3/main/rpc_dispatch.c +++ b/software/wifi/raw_c3/main/rpc_dispatch.c @@ -106,7 +106,9 @@ void cmd_wifi_connect(command_buf_t *buf) ev.command = CMD_WIFI_CONNECT; ev.auth_mode = param->auth_mode; memcpy(&ev.ssid, param->ssid, 32); + ev.ssid[32] = 0; memcpy(&ev.pw, param->password, 64); + ev.pw[64] = 0; if (xQueueSend(connect_commands, &ev, 1000) == pdFALSE) { resp->esp_err = ESP_ERR_NO_MEM; diff --git a/software/wifi/raw_c3/main/rpc_dispatch.h b/software/wifi/raw_c3/main/rpc_dispatch.h index e17bcb2f1..aad4296ad 100644 --- a/software/wifi/raw_c3/main/rpc_dispatch.h +++ b/software/wifi/raw_c3/main/rpc_dispatch.h @@ -24,13 +24,15 @@ void start_dispatch(QueueHandle_t queue); void send_button_event(uint8_t button); void send_keepalive(); -#define IDENT_STRING "ESP32 WiFi Bridge V1.6" +#define IDENT_STRING "ESP32 WiFi Bridge V1.7" #define IDENT_MAJOR 1 +// 1.7: terminates 32-character SSIDs and 64-character passwords, and reads +// them back from NVS whole. // 1.6: the connector retries after a dropped link instead of idling in // Disconnected forever. The Ultimate's updater only reflashes the module // when this differs from what the module reports, so a module change that // does not bump it is silently never installed. -#define IDENT_MINOR 6 +#define IDENT_MINOR 7 #define MULTITHREADED 0 #define DISPATCHER_STACK 3072 diff --git a/software/wifi/raw_c3/main/wifi_modem.c b/software/wifi/raw_c3/main/wifi_modem.c index 59c95302b..9276dd70b 100644 --- a/software/wifi/raw_c3/main/wifi_modem.c +++ b/software/wifi/raw_c3/main/wifi_modem.c @@ -369,8 +369,8 @@ esp_err_t wifi_store_ap(ConnectCommand_t *cmd) key[0] = 's'; key[1] = 'a' + i; key[2] = '0'; // SSID sa, sb, sc, sd, ... - size_t len = 32; - char ssid_buf[32]; + size_t len = 33; + char ssid_buf[33]; // see if the ssid has been stored already err = nvs_get_str(handle, key, ssid_buf, &len); if (err != ESP_OK) { // nope, it doesn't exist @@ -545,10 +545,10 @@ esp_err_t wifi_connect_to_scanned(int index) // now look up password err = ESP_OK; if (ap_info[index].authmode) { - err = wifi_find_password(ap_info[index].ssid, last_connect.pw, 64, &last_connect.list_index); + err = wifi_find_password(ap_info[index].ssid, last_connect.pw, sizeof(last_connect.pw), &last_connect.list_index); } else { // no authentication required. But make sure the user has configured this AP. - err = wifi_find_password(ap_info[index].ssid, last_connect.pw, 64, &last_connect.list_index); + err = wifi_find_password(ap_info[index].ssid, last_connect.pw, sizeof(last_connect.pw), &last_connect.list_index); if ((err == ESP_OK)&&(last_connect.pw[0] != 0)) { // AP is known and configured, however, with a password. Do not allow to connect. err = ESP_ERR_NOT_FOUND; @@ -556,6 +556,7 @@ esp_err_t wifi_connect_to_scanned(int index) } if (err == ESP_OK) { // known AP found strncpy(last_connect.ssid, (const char *)(ap_info[index].ssid), 32); + last_connect.ssid[32] = 0; last_connect.auth_mode = ap_info[index].authmode; return attempt_connect(last_connect.ssid, last_connect.pw, last_connect.auth_mode); } @@ -582,11 +583,11 @@ esp_err_t wifi_connect_to_stored(int index) key[1] = 'a' + index; key[2] = '0'; // SSID sa, sb, sc, sd, ... - size_t len = 32; + size_t len = sizeof(last_connect.ssid); err = nvs_get_str(handle, key, last_connect.ssid, &len); if (err == ESP_OK) { key[0] = 'p'; // password pa, pb, pc, pd, ... - len = 64; + len = sizeof(last_connect.pw); err = nvs_get_str(handle, key, last_connect.pw, &len); if (err == ESP_OK) { key[0] = 'm'; // authmode ma, mb, mc, md, ... diff --git a/software/wifi/raw_c3/main/wifi_modem.h b/software/wifi/raw_c3/main/wifi_modem.h index d9971db32..20a571352 100644 --- a/software/wifi/raw_c3/main/wifi_modem.h +++ b/software/wifi/raw_c3/main/wifi_modem.h @@ -7,7 +7,7 @@ extern QueueHandle_t connect_commands; extern SemaphoreHandle_t connect_semaphore; typedef struct { - char ssid[32]; + char ssid[33]; // 32 SSID bytes plus the terminator char pw[68]; uint8_t auth_mode; uint8_t command; diff --git a/software/wifi/raw_u64/main/rpc_dispatch.c b/software/wifi/raw_u64/main/rpc_dispatch.c index 8663e1cdd..68a618e2e 100644 --- a/software/wifi/raw_u64/main/rpc_dispatch.c +++ b/software/wifi/raw_u64/main/rpc_dispatch.c @@ -106,7 +106,9 @@ void cmd_wifi_connect(command_buf_t *buf) ev.command = CMD_WIFI_CONNECT; ev.auth_mode = param->auth_mode; memcpy(&ev.ssid, param->ssid, 32); + ev.ssid[32] = 0; memcpy(&ev.pw, param->password, 64); + ev.pw[64] = 0; if (xQueueSend(connect_commands, &ev, 1000) == pdFALSE) { resp->esp_err = ESP_ERR_NO_MEM; diff --git a/software/wifi/raw_u64/main/rpc_dispatch.h b/software/wifi/raw_u64/main/rpc_dispatch.h index 7e6a4b9a5..596cd040f 100644 --- a/software/wifi/raw_u64/main/rpc_dispatch.h +++ b/software/wifi/raw_u64/main/rpc_dispatch.h @@ -26,13 +26,15 @@ void start_dispatch(QueueHandle_t queue); void send_button_event(uint8_t button); void send_keepalive(); -#define IDENT_STRING "ESP32 WiFi Bridge V1.6" +#define IDENT_STRING "ESP32 WiFi Bridge V1.7" #define IDENT_MAJOR 1 +// 1.7: terminates 32-character SSIDs and 64-character passwords, and reads +// them back from NVS whole. // 1.6: the connector retries after a dropped link instead of idling in // Disconnected forever. The Ultimate's updater only reflashes the module // when this differs from what the module reports, so a module change that // does not bump it is silently never installed. -#define IDENT_MINOR 6 +#define IDENT_MINOR 7 #define MULTITHREADED 0 #define DISPATCHER_STACK 3072 diff --git a/software/wifi/raw_u64/main/wifi_modem.c b/software/wifi/raw_u64/main/wifi_modem.c index 59c95302b..9276dd70b 100644 --- a/software/wifi/raw_u64/main/wifi_modem.c +++ b/software/wifi/raw_u64/main/wifi_modem.c @@ -369,8 +369,8 @@ esp_err_t wifi_store_ap(ConnectCommand_t *cmd) key[0] = 's'; key[1] = 'a' + i; key[2] = '0'; // SSID sa, sb, sc, sd, ... - size_t len = 32; - char ssid_buf[32]; + size_t len = 33; + char ssid_buf[33]; // see if the ssid has been stored already err = nvs_get_str(handle, key, ssid_buf, &len); if (err != ESP_OK) { // nope, it doesn't exist @@ -545,10 +545,10 @@ esp_err_t wifi_connect_to_scanned(int index) // now look up password err = ESP_OK; if (ap_info[index].authmode) { - err = wifi_find_password(ap_info[index].ssid, last_connect.pw, 64, &last_connect.list_index); + err = wifi_find_password(ap_info[index].ssid, last_connect.pw, sizeof(last_connect.pw), &last_connect.list_index); } else { // no authentication required. But make sure the user has configured this AP. - err = wifi_find_password(ap_info[index].ssid, last_connect.pw, 64, &last_connect.list_index); + err = wifi_find_password(ap_info[index].ssid, last_connect.pw, sizeof(last_connect.pw), &last_connect.list_index); if ((err == ESP_OK)&&(last_connect.pw[0] != 0)) { // AP is known and configured, however, with a password. Do not allow to connect. err = ESP_ERR_NOT_FOUND; @@ -556,6 +556,7 @@ esp_err_t wifi_connect_to_scanned(int index) } if (err == ESP_OK) { // known AP found strncpy(last_connect.ssid, (const char *)(ap_info[index].ssid), 32); + last_connect.ssid[32] = 0; last_connect.auth_mode = ap_info[index].authmode; return attempt_connect(last_connect.ssid, last_connect.pw, last_connect.auth_mode); } @@ -582,11 +583,11 @@ esp_err_t wifi_connect_to_stored(int index) key[1] = 'a' + index; key[2] = '0'; // SSID sa, sb, sc, sd, ... - size_t len = 32; + size_t len = sizeof(last_connect.ssid); err = nvs_get_str(handle, key, last_connect.ssid, &len); if (err == ESP_OK) { key[0] = 'p'; // password pa, pb, pc, pd, ... - len = 64; + len = sizeof(last_connect.pw); err = nvs_get_str(handle, key, last_connect.pw, &len); if (err == ESP_OK) { key[0] = 'm'; // authmode ma, mb, mc, md, ... diff --git a/software/wifi/raw_u64/main/wifi_modem.h b/software/wifi/raw_u64/main/wifi_modem.h index d9971db32..20a571352 100644 --- a/software/wifi/raw_u64/main/wifi_modem.h +++ b/software/wifi/raw_u64/main/wifi_modem.h @@ -7,7 +7,7 @@ extern QueueHandle_t connect_commands; extern SemaphoreHandle_t connect_semaphore; typedef struct { - char ssid[32]; + char ssid[33]; // 32 SSID bytes plus the terminator char pw[68]; uint8_t auth_mode; uint8_t command;