diff options
author | Uros Majstorovic <majstor@majstor.org> | 2024-09-04 20:47:31 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2024-09-04 20:47:31 +0200 |
commit | ba6cbdfbecc9cb9bc5f4078b63e6889538e6ed93 (patch) | |
tree | 2151a7da7e05fcd65af916980c3644809561e3da /fw | |
parent | 1498495768677132a83889d0dd064563a0c0ea03 (diff) |
esp32 wifi driver fix
Diffstat (limited to 'fw')
-rwxr-xr-x | fw/esp32/components/eos/wifi.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/fw/esp32/components/eos/wifi.c b/fw/esp32/components/eos/wifi.c index 537aeba..2be169f 100755 --- a/fw/esp32/components/eos/wifi.c +++ b/fw/esp32/components/eos/wifi.c @@ -154,35 +154,33 @@ static void wifi_handler(unsigned char _mtype, unsigned char *buffer, uint16_t b case EOS_WIFI_MTYPE_CONNECT: { wifi_config_t wifi_sta_config; size_t ssid_size = sizeof(wifi_sta_config.sta.ssid); - size_t pwd_size = sizeof(wifi_sta_config.sta.password) - 1; - size_t ssid_len, pwd_len; + size_t pwd_size = sizeof(wifi_sta_config.sta.password); + unsigned char ssid_len, pwd_len; char *ssid, *pwd; buffer++; - buf_len--; + + ssid_len = *buffer; + buffer++; ssid = (char *)buffer; - ssid_len = strnlen(ssid, buf_len); - if (ssid_len == buf_len) break; if (ssid_len > ssid_size) break; - buffer += ssid_len + 1; - buf_len -= ssid_len + 1; + buffer += ssid_len; + + pwd_len = *buffer; + buffer++; pwd = (char *)buffer; - pwd_len = strnlen(pwd, buf_len); - if (pwd_len == buf_len) break; - if (pwd_len >= pwd_size) break; - buffer += pwd_len + 1; - buf_len -= pwd_len + 1; + if (pwd_len > pwd_size - 1) break; + buffer += pwd_len; memset(&wifi_sta_config, 0, sizeof(wifi_sta_config)); + memcpy(wifi_sta_config.sta.ssid, ssid, ssid_len); if (ssid_len < ssid_size) { - strcpy((char *)wifi_sta_config.sta.ssid, ssid); - } else { - memcpy(wifi_sta_config.sta.ssid, ssid, ssid_size); + wifi_sta_config.sta.ssid[ssid_len] = '\0'; } - strcpy((char *)wifi_sta_config.sta.password, pwd); - wifi_sta_config.sta.password[pwd_size] = '\0'; + memcpy((char *)wifi_sta_config.sta.password, pwd, pwd_len); + wifi_sta_config.sta.password[pwd_len] = '\0'; ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_sta_config); if (ret) break; @@ -265,8 +263,8 @@ ssize_t eos_wifi_get_status(unsigned char *buffer) { p++; } - strcpy((char *)p, (char *)ap_info.ssid); - p += len + 1; + memcpy((char *)p, (char *)ap_info.ssid, len); + p += len; break; } @@ -333,7 +331,7 @@ void eos_wifi_send_scan(void) { for (i=0; i<scan_n; i++) { len = strnlen((char *)scan_r[i].ssid, sizeof(scan_r[i].ssid)); if (len == sizeof(scan_r[i].ssid)) continue; - if (p - rbuf + len + 1 > EOS_NET_MTU) break; + if (p - rbuf + len + 1 > EOS_NET_SIZE_BUF) break; strcpy((char *)p, (char *)scan_r[i].ssid); p += len + 1; |