diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-03-30 13:22:57 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-03-30 13:22:57 +0200 |
commit | 55474b81146327e8cfa7702fa9366cc7da6562e7 (patch) | |
tree | b6bf9fe0258ab88d12717bb31ecdf4eda0ffa073 /fw/esp32/components/eos/wifi.c | |
parent | c6962c5700f99441538dafa346626bb7e6d12488 (diff) |
sock api fixed; net reply messages fixed
Diffstat (limited to 'fw/esp32/components/eos/wifi.c')
-rwxr-xr-x | fw/esp32/components/eos/wifi.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/fw/esp32/components/eos/wifi.c b/fw/esp32/components/eos/wifi.c index d47ae3a..d294f45 100755 --- a/fw/esp32/components/eos/wifi.c +++ b/fw/esp32/components/eos/wifi.c @@ -73,9 +73,10 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t e rbuf[0] = EOS_WIFI_MTYPE_SCAN; p = rbuf + 1; for (i=0; i<scan_n; i++) { - len = strnlen((char *)scan_r[i].ssid, 33); - if (len > 32) continue; + 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; + strcpy((char *)p, (char *)scan_r[i].ssid); p += len + 1; } @@ -168,27 +169,42 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t e if (ret != ESP_OK) ESP_LOGE(TAG, "EVT HANDLER ERR:%d EVT:%d", ret, event_id); } -static void wifi_handler(unsigned char _mtype, unsigned char *buffer, uint16_t size) { +static void wifi_handler(unsigned char _mtype, unsigned char *buffer, uint16_t buf_len) { uint8_t mtype; int rv; - char *ssid, *pass; + char *ssid, *pass, *_buf; + uint16_t _buf_len; - if (size < 1) return; + if (buf_len < 1) return; - mtype = buffer[0]; rv = EOS_OK; - buffer += 1; - size -= 1; + + mtype = buffer[0]; + buffer++; + buf_len--; switch (mtype) { case EOS_WIFI_MTYPE_SCAN: rv = eos_wifi_scan(); break; - case EOS_WIFI_MTYPE_CONFIG: - ssid = (char *)buffer; - pass = ssid + strlen(ssid) + 1; - rv = eos_wifi_set_config(ssid, pass); + case EOS_WIFI_MTYPE_AUTH: + _buf = (char *)buffer; + _buf_len = 0; + + ssid = _buf; + _buf_len = strnlen(_buf, buf_len); + if (_buf_len == buf_len) break; + _buf += _buf_len + 1; + buf_len -= _buf_len + 1; + + pass = _buf; + _buf_len = strnlen(_buf, buf_len); + if (_buf_len == buf_len) break; + _buf += _buf_len + 1; + buf_len -= _buf_len + 1; + + rv = eos_wifi_auth(ssid, pass); break; case EOS_WIFI_MTYPE_CONNECT: @@ -269,7 +285,7 @@ int eos_wifi_scan(void) { return rv; } -int eos_wifi_set_config(char *ssid, char *pass) { +int eos_wifi_auth(char *ssid, char *pass) { int rv = EOS_OK; xSemaphoreTake(mutex, portMAX_DELAY); |