From ce03ea42bd71a14de06b3f313abe2e0562dcf52e Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:18:56 +0200 Subject: [PATCH] Tasmota changes --- CMakeLists.txt | 86 +-- Kconfig.projbuild | 30 - README.md | 70 +- cores/esp32/HWCDC.cpp | 5 +- cores/esp32/main.cpp | 6 + idf_component.yml | 41 +- libraries/Ethernet/src/ETH.cpp | 1 + libraries/Ethernet/src/ETH.h | 4 + libraries/HTTPClient/src/HTTPClient.cpp | 89 --- libraries/HTTPClient/src/HTTPClient.h | 1 - libraries/Network/src/NetworkEvents.h | 4 + libraries/Update/src/Update.h | 295 ++++----- libraries/Update/src/Updater.cpp | 833 ++++++++++-------------- libraries/WiFi/src/STA.cpp | 90 --- libraries/WiFi/src/WiFiGeneric.cpp | 10 +- libraries/WiFi/src/WiFiGeneric.h | 2 + tools/platformio-build.py | 21 +- 17 files changed, 501 insertions(+), 1087 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e760225a04..29c01d2ec4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ endif() set(CORE_SRCS cores/esp32/base64.cpp cores/esp32/cbuf.cpp - cores/esp32/chip-debug-report.cpp cores/esp32/esp32-hal-adc.c cores/esp32/esp32-hal-bt.c cores/esp32/esp32-hal-cpu.c @@ -78,38 +77,27 @@ set(CORE_SRCS set(ARDUINO_ALL_LIBRARIES ArduinoOTA AsyncUDP - BLE - BluetoothSerial DNSServer EEPROM - ESP_I2S - ESP_NOW - ESP_SR ESPmDNS Ethernet FFat FS HTTPClient HTTPUpdate - Insights LittleFS NetBIOS Network PPP Preferences - RainMaker SD_MMC SD - SimpleBLE - SPIFFS SPI Ticker Update USB WebServer - NetworkClientSecure WiFi - WiFiProv Wire ) @@ -118,26 +106,10 @@ set(ARDUINO_LIBRARY_ArduinoOTA_REQUIRES esp_https_ota) set(ARDUINO_LIBRARY_AsyncUDP_SRCS libraries/AsyncUDP/src/AsyncUDP.cpp) -set(ARDUINO_LIBRARY_BluetoothSerial_SRCS - libraries/BluetoothSerial/src/BluetoothSerial.cpp - libraries/BluetoothSerial/src/BTAddress.cpp - libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp - libraries/BluetoothSerial/src/BTScanResultsSet.cpp) - set(ARDUINO_LIBRARY_DNSServer_SRCS libraries/DNSServer/src/DNSServer.cpp) set(ARDUINO_LIBRARY_EEPROM_SRCS libraries/EEPROM/src/EEPROM.cpp) -set(ARDUINO_LIBRARY_ESP_I2S_SRCS libraries/ESP_I2S/src/ESP_I2S.cpp) - -set(ARDUINO_LIBRARY_ESP_NOW_SRCS - libraries/ESP_NOW/src/ESP32_NOW.cpp - libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp) - -set(ARDUINO_LIBRARY_ESP_SR_SRCS - libraries/ESP_SR/src/ESP_SR.cpp - libraries/ESP_SR/src/esp32-hal-sr.c) - set(ARDUINO_LIBRARY_ESPmDNS_SRCS libraries/ESPmDNS/src/ESPmDNS.cpp) set(ARDUINO_LIBRARY_Ethernet_SRCS libraries/Ethernet/src/ETH.cpp) @@ -152,8 +124,6 @@ set(ARDUINO_LIBRARY_HTTPClient_SRCS libraries/HTTPClient/src/HTTPClient.cpp) set(ARDUINO_LIBRARY_HTTPUpdate_SRCS libraries/HTTPUpdate/src/HTTPUpdate.cpp) -set(ARDUINO_LIBRARY_Insights_SRCS libraries/Insights/src/Insights.cpp) - set(ARDUINO_LIBRARY_LittleFS_SRCS libraries/LittleFS/src/LittleFS.cpp) set(ARDUINO_LIBRARY_NetBIOS_SRCS libraries/NetBIOS/src/NetBIOS.cpp) @@ -164,16 +134,6 @@ set(ARDUINO_LIBRARY_PPP_SRCS set(ARDUINO_LIBRARY_Preferences_SRCS libraries/Preferences/src/Preferences.cpp) -set(ARDUINO_LIBRARY_RainMaker_SRCS - libraries/RainMaker/src/RMaker.cpp - libraries/RainMaker/src/RMakerNode.cpp - libraries/RainMaker/src/RMakerParam.cpp - libraries/RainMaker/src/RMakerDevice.cpp - libraries/RainMaker/src/RMakerType.cpp - libraries/RainMaker/src/RMakerQR.cpp - libraries/RainMaker/src/RMakerUtils.cpp - libraries/RainMaker/src/AppInsights.cpp) - set(ARDUINO_LIBRARY_SD_MMC_SRCS libraries/SD_MMC/src/SD_MMC.cpp) set(ARDUINO_LIBRARY_SD_SRCS @@ -181,10 +141,6 @@ set(ARDUINO_LIBRARY_SD_SRCS libraries/SD/src/sd_diskio.cpp libraries/SD/src/sd_diskio_crc.c) -set(ARDUINO_LIBRARY_SimpleBLE_SRCS libraries/SimpleBLE/src/SimpleBLE.cpp) - -set(ARDUINO_LIBRARY_SPIFFS_SRCS libraries/SPIFFS/src/SPIFFS.cpp) - set(ARDUINO_LIBRARY_SPI_SRCS libraries/SPI/src/SPI.cpp) set(ARDUINO_LIBRARY_Ticker_SRCS libraries/Ticker/src/Ticker.cpp) @@ -209,10 +165,6 @@ set(ARDUINO_LIBRARY_WebServer_SRCS libraries/WebServer/src/Parsing.cpp libraries/WebServer/src/detail/mimetable.cpp) -set(ARDUINO_LIBRARY_NetworkClientSecure_SRCS - libraries/NetworkClientSecure/src/ssl_client.cpp - libraries/NetworkClientSecure/src/NetworkClientSecure.cpp) - set(ARDUINO_LIBRARY_Network_SRCS libraries/Network/src/NetworkInterface.cpp libraries/Network/src/NetworkEvents.cpp @@ -231,42 +183,8 @@ set(ARDUINO_LIBRARY_WiFi_SRCS libraries/WiFi/src/STA.cpp libraries/WiFi/src/AP.cpp) -set(ARDUINO_LIBRARY_WiFiProv_SRCS libraries/WiFiProv/src/WiFiProv.cpp) - set(ARDUINO_LIBRARY_Wire_SRCS libraries/Wire/src/Wire.cpp) -set(ARDUINO_LIBRARY_BLE_SRCS - libraries/BLE/src/BLE2902.cpp - libraries/BLE/src/BLE2904.cpp - libraries/BLE/src/BLEAddress.cpp - libraries/BLE/src/BLEAdvertisedDevice.cpp - libraries/BLE/src/BLEAdvertising.cpp - libraries/BLE/src/BLEBeacon.cpp - libraries/BLE/src/BLECharacteristic.cpp - libraries/BLE/src/BLECharacteristicMap.cpp - libraries/BLE/src/BLEClient.cpp - libraries/BLE/src/BLEDescriptor.cpp - libraries/BLE/src/BLEDescriptorMap.cpp - libraries/BLE/src/BLEDevice.cpp - libraries/BLE/src/BLEEddystoneTLM.cpp - libraries/BLE/src/BLEEddystoneURL.cpp - libraries/BLE/src/BLEExceptions.cpp - libraries/BLE/src/BLEHIDDevice.cpp - libraries/BLE/src/BLERemoteCharacteristic.cpp - libraries/BLE/src/BLERemoteDescriptor.cpp - libraries/BLE/src/BLERemoteService.cpp - libraries/BLE/src/BLEScan.cpp - libraries/BLE/src/BLESecurity.cpp - libraries/BLE/src/BLEServer.cpp - libraries/BLE/src/BLEService.cpp - libraries/BLE/src/BLEServiceMap.cpp - libraries/BLE/src/BLEUtils.cpp - libraries/BLE/src/BLEUUID.cpp - libraries/BLE/src/BLEValue.cpp - libraries/BLE/src/FreeRTOS.cpp - libraries/BLE/src/GeneralUtils.cpp - ) - set(ARDUINO_LIBRARIES_SRCS) set(ARDUINO_LIBRARIES_REQUIRES) set(ARDUINO_LIBRARIES_INCLUDEDIRS) @@ -287,8 +205,8 @@ endforeach() set(includedirs variants/${CONFIG_ARDUINO_VARIANT}/ cores/esp32/ ${ARDUINO_LIBRARIES_INCLUDEDIRS}) set(srcs ${CORE_SRCS} ${ARDUINO_LIBRARIES_SRCS}) set(priv_includes cores/esp32/libb64) -set(requires spi_flash esp_partition mbedtls wifi_provisioning wpa_supplicant esp_adc esp_eth http_parser) -set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid ${ARDUINO_LIBRARIES_REQUIRES}) +set(requires spi_flash esp_partition mbedtls wpa_supplicant esp_adc esp_eth http_parser) +set(priv_requires fatfs nvs_flash app_update bootloader_support bt esp_hid ${ARDUINO_LIBRARIES_REQUIRES}) idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 979afc02213..f1c5d3ba0d5 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -301,11 +301,6 @@ config ARDUINO_SELECTIVE_SD_MMC depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS default y -config ARDUINO_SELECTIVE_SPIFFS - bool "Enable SPIFFS" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS - default y - config ARDUINO_SELECTIVE_FFat bool "Enable FFat" depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS @@ -374,29 +369,4 @@ config ARDUINO_SELECTIVE_WiFi depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Networking default y -config ARDUINO_SELECTIVE_WiFiClientSecure - bool "Enable WiFiClientSecure" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Networking - default y - -config ARDUINO_SELECTIVE_WiFiProv - bool "Enable WiFiProv" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Networking && ARDUINO_SELECTIVE_WiFi - default y - -config ARDUINO_SELECTIVE_BLE - bool "Enable BLE" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - -config ARDUINO_SELECTIVE_BluetoothSerial - bool "Enable BluetoothSerial" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - -config ARDUINO_SELECTIVE_SimpleBLE - bool "Enable SimpleBLE" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - endmenu diff --git a/README.md b/README.md index 940a9b7102b..bacb40b5ec4 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,6 @@ -# Arduino core for the ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 +# Tasmota Platformio Arduino for ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C6 and ESP32-H2 -![Build Status](https://github.com/espressif/arduino-esp32/workflows/ESP32%20Arduino%20CI/badge.svg) [![External Libraries Test](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md) [![Hardware Tests](https://github.com/espressif/arduino-esp32/actions/workflows/hil.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/actions/workflows/hil.yml?query=event%3Aschedule) - -### Need help or have a question? Join the chat at [Gitter](https://gitter.im/espressif/arduino-esp32) or [open a new Discussion](https://github.com/espressif/arduino-esp32/discussions) - -## Contents - - - [Development Status](#development-status) - - [Development Planning](#development-planning) - - [Documentation](#documentation) - - [Supported Chips](#supported-chips) - - [Decoding exceptions](#decoding-exceptions) - - [Issue/Bug report template](#issuebug-report-template) - - [Contributing](#contributing) - -### Development Status - -Latest Stable Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) [![Release Date](https://img.shields.io/github/release-date/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) [![Downloads](https://img.shields.io/github/downloads/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) - -Latest Development Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32/all.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Release Date](https://img.shields.io/github/release-date-pre/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Downloads](https://img.shields.io/github/downloads-pre/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) - -### Development Planning - -Our Development is fully tracked on this public **[Roadmap 🎉](https://github.com/orgs/espressif/projects/3)** - -For even more information you can join our **[Monthly Community Meetings 🔔](https://github.com/espressif/arduino-esp32/discussions/categories/monthly-community-meetings).** +### [![GitHub Releases](https://img.shields.io/github/downloads/tasmota/arduino-esp32/total?label=downloads)](https://github.com/tasmota/arduino-esp32/releases/latest) ### Documentation @@ -36,51 +12,19 @@ You can use the [Arduino-ESP32 Online Documentation](https://docs.espressif.com/ --- -**APIs compatibility with ESP8266 and Arduino-CORE (Arduino.cc) is explained [here](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html#apis).** - ---- - -* [Getting Started](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html) -* [Installing (Windows, Linux and macOS)](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html) -* [Libraries](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html) -* [Arduino as an ESP-IDF component](https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html) -* [FAQ](https://docs.espressif.com/projects/arduino-esp32/en/latest/faq.html) -* [Troubleshooting](https://docs.espressif.com/projects/arduino-esp32/en/latest/troubleshooting.html) - ### Supported Chips -Here are the ESP32 series supported by the Arduino-ESP32 project: +Here are the ESP32 series supported by the Tasmota Arduino-ESP32 project: | **SoC** | **Stable** | **Development** | **Datasheet** | |----------|:----------:|:---------------:|:-------------------------------------------------------------------------------------------------:| -| ESP32 | Yes | Yes | [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) | +| ESP32 | Yes | Yes | [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) | +| ESP32solo1| Yes | Yes | [ESP32solo1](https://www.espressif.com/sites/default/files/documentation/esp32-solo-1_datasheet_en.pdf) | | ESP32-S2 | Yes | Yes | [ESP32-S2](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) | -| ESP32-C3 | Yes | Yes | [ESP32-C3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) | | ESP32-S3 | Yes | Yes | [ESP32-S3](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) | +| ESP32-C3 | Yes | Yes | [ESP32-C3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) | +| ESP32-C2 | No | Yes | [ESP32-C2](https://www.espressif.com/sites/default/files/documentation/esp8684_datasheet_en.pdf) | | ESP32-C6 | No | Yes | [ESP32-C6](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) | | ESP32-H2 | No | Yes | [ESP32-H2](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) | For more details visit the [supported chips](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html#supported-soc-s) documentation page. - -### Decoding exceptions - -You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) to get meaningful call trace. - -### Issue/Bug report template - -Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labeled as [Type: For reference](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue+label%3A%22Type%3A+For+reference%22+). - -Finally, if you are sure no one else had the issue, follow the **Issue template** or **Feature request template** while reporting any [new Issue](https://github.com/espressif/arduino-esp32/issues/new/choose). - -### External libraries compilation test - -We have set-up CI testing for external libraries for ESP32 Arduino core. You can check test results in the file [LIBRARIES_TEST](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md). -For more information and how to add your library to the test see [external library testing](https://docs.espressif.com/projects/arduino-esp32/en/latest/external_libraries_test.html) in the documentation. - -### Contributing - -We welcome contributions to the Arduino ESP32 project! - -See [contributing](https://docs.espressif.com/projects/arduino-esp32/en/latest/contributing.html) in the documentation for more information on how to contribute to the project. - -> We would like to have this repository in a polite and friendly atmosphere, so please be kind and respectful to others. For more details, look at [Code of Conduct](https://github.com/espressif/arduino-esp32/blob/master/CODE_OF_CONDUCT.md). diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 0b54b82d685..ded100f86b0 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -242,8 +242,8 @@ void HWCDC::begin(unsigned long baud) { } // the HW Serial pins needs to be first deinited in order to allow `if(Serial)` to work :-( - deinit(NULL); - delay(10); // USB Host has to enumerate it again + //deinit(NULL); + //delay(10); // USB Host has to enumerate it again // Peripheral Manager setting for USB D+ D- pins uint8_t pin = USB_DM_GPIO_NUM; @@ -265,6 +265,7 @@ void HWCDC::begin(unsigned long baud) { // Enable USB pad function USB_SERIAL_JTAG.conf0.usb_pad_enable = 1; usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); + usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK); usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); if (!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK) { isr_log_e("HW USB CDC failed to init interrupts"); diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 21f15083473..b72269bbd30 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -9,7 +9,9 @@ #endif #endif +#if defined __has_include && __has_include ("chip-debug-report.h") #include "chip-debug-report.h" +#endif #ifndef ARDUINO_LOOP_STACK_SIZE #ifndef CONFIG_ARDUINO_LOOP_STACK_SIZE @@ -48,20 +50,24 @@ void loopTask(void *pvParameters) { // sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)); #endif +#if defined __has_include && __has_include ("chip-debug-report.h") #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG printBeforeSetupInfo(); #else if (shouldPrintChipDebugReport()) { printBeforeSetupInfo(); } +#endif #endif setup(); +#if defined __has_include && __has_include ("chip-debug-report.h") #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG printAfterSetupInfo(); #else if (shouldPrintChipDebugReport()) { printAfterSetupInfo(); } +#endif #endif for (;;) { #if CONFIG_FREERTOS_UNICORE diff --git a/idf_component.yml b/idf_component.yml index 2a76aec4d81..ae548c41d44 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -43,44 +43,7 @@ files: - "programmers.txt" dependencies: idf: ">=5.1" - # mdns 1.2.1 is necessary to build H2 with no WiFi + # mdns 1.2.3 is necessary to build H2 with no WiFi mdns: "^1.2.3" espressif/esp_modem: "^1.1.0" - chmorgan/esp-libhelix-mp3: - version: "1.0.3" - require: public - espressif/esp-zboss-lib: - version: "^1.0.1" - rules: - - if: "target != esp32c2" - espressif/esp-zigbee-lib: - version: "^1.0.1" - rules: - - if: "target != esp32c2" - esp-dsp: - version: "^1.3.4" - rules: - - if: "target != esp32c2" - espressif/esp_rainmaker: - version: "^1.0.0" - rules: - - if: "target != esp32c2" - espressif/rmaker_common: - version: "^1.4.3" - rules: - - if: "target != esp32c2" - espressif/esp_insights: - version: "^1.0.1" - rules: - - if: "target != esp32c2" - espressif/qrcode: - version: "^0.1.0~1" - rules: - - if: "target != esp32c2" - joltwallet/littlefs: "^1.10.2" - espressif/esp-sr: - version: "^1.4.2" - rules: - - if: "target in [esp32s3]" -examples: - - path: ./idf_component_examples/Hello_world + joltwallet/littlefs: "^1.14.1" diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index eeda93e3201..624bf74593e 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -234,6 +234,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i case ETH_PHY_TLK110: phy = esp_eth_phy_new_ip101(&phy_config); break; case ETH_PHY_RTL8201: phy = esp_eth_phy_new_rtl8201(&phy_config); break; case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848(&phy_config); break; + case ETH_PHY_JL1101: phy = esp_eth_phy_new_jl1101(&phy_config); break; case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; case ETH_PHY_KSZ8081: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; default: log_e("Unsupported PHY %d", type); break; diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index d2404391fbf..5570e430364 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -63,6 +63,9 @@ // This will be uncommented once custom SPI support is available in ESP-IDF #define ETH_SPI_SUPPORTS_CUSTOM 1 +// This will be removed when the support is backported to official IDF 5.1 +#define ETH_SPI_SUPPORTS_NO_IRQ 1 + #include "Network.h" #if ETH_SPI_SUPPORTS_CUSTOM @@ -100,6 +103,7 @@ typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, + ETH_PHY_JL1101, ETH_PHY_DP83848, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081, diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index 54eedf0ac2e..080737b7334 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -31,7 +31,6 @@ #ifdef HTTPCLIENT_1_1_COMPATIBLE #include -#include #endif #include @@ -55,32 +54,6 @@ class TransportTraits { return true; } }; - -class TLSTraits : public TransportTraits { -public: - TLSTraits(const char *CAcert, const char *clicert = nullptr, const char *clikey = nullptr) : _cacert(CAcert), _clicert(clicert), _clikey(clikey) {} - - std::unique_ptr create() override { - return std::unique_ptr(new NetworkClientSecure()); - } - - bool verify(NetworkClient &client, const char *host) override { - NetworkClientSecure &wcs = static_cast(client); - if (_cacert == nullptr) { - wcs.setInsecure(); - } else { - wcs.setCACert(_cacert); - wcs.setCertificate(_clicert); - wcs.setPrivateKey(_clikey); - } - return true; - } - -protected: - const char *_cacert; - const char *_clicert; - const char *_clikey; -}; #endif // HTTPCLIENT_1_1_COMPATIBLE /** @@ -178,28 +151,6 @@ bool HTTPClient::begin(NetworkClient &client, String host, uint16_t port, String } #ifdef HTTPCLIENT_1_1_COMPATIBLE -bool HTTPClient::begin(String url, const char *CAcert) { - if (_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } - - clear(); - _port = 443; - if (!beginInternal(url, "https")) { - return false; - } - _secure = true; - _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); - if (!_transportTraits) { - log_e("could not create transport traits"); - return false; - } - - return true; -} - /** * parsing the url for all needed parameters * @param url String @@ -298,46 +249,6 @@ bool HTTPClient::begin(String host, uint16_t port, String uri) { log_d("host: %s port: %d uri: %s", host.c_str(), port, uri.c_str()); return true; } - -bool HTTPClient::begin(String host, uint16_t port, String uri, const char *CAcert) { - if (_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } - - clear(); - _host = host; - _port = port; - _uri = uri; - - if (strlen(CAcert) == 0) { - return false; - } - _secure = true; - _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert)); - return true; -} - -bool HTTPClient::begin(String host, uint16_t port, String uri, const char *CAcert, const char *cli_cert, const char *cli_key) { - if (_client && !_tcpDeprecated) { - log_d("mix up of new and deprecated api"); - _canReuse = false; - end(); - } - - clear(); - _host = host; - _port = port; - _uri = uri; - - if (strlen(CAcert) == 0) { - return false; - } - _secure = true; - _transportTraits = TransportTraitsPtr(new TLSTraits(CAcert, cli_cert, cli_key)); - return true; -} #endif // HTTPCLIENT_1_1_COMPATIBLE /** diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 7841f355640..35b5bb4fc61 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -34,7 +34,6 @@ #include #include #include -#include /// Cookie jar support #include diff --git a/libraries/Network/src/NetworkEvents.h b/libraries/Network/src/NetworkEvents.h index 6c0e82f4d81..d7788edc7aa 100644 --- a/libraries/Network/src/NetworkEvents.h +++ b/libraries/Network/src/NetworkEvents.h @@ -20,8 +20,10 @@ #if SOC_WIFI_SUPPORTED #include "esp_wifi_types.h" #include "esp_smartconfig.h" +#if defined __has_include && __has_include ("wifi_provisioning/wifi_config.h") #include "wifi_provisioning/wifi_config.h" #endif +#endif #if SOC_WIFI_SUPPORTED static const int WIFI_SCANNING_BIT = BIT0; @@ -105,7 +107,9 @@ typedef union { wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected; wifi_event_ftm_report_t wifi_ftm_report; wifi_sta_config_t prov_cred_recv; + #if defined __has_include && __has_include ("wifi_provisioning/wifi_config.h") wifi_prov_sta_fail_reason_t prov_fail_reason; + #endif smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd; #endif } arduino_event_info_t; diff --git a/libraries/Update/src/Update.h b/libraries/Update/src/Update.h index 7ae5e980751..26f07f3775d 100644 --- a/libraries/Update/src/Update.h +++ b/libraries/Update/src/Update.h @@ -12,82 +12,64 @@ #include #include "esp_partition.h" -#define UPDATE_ERROR_OK (0) -#define UPDATE_ERROR_WRITE (1) -#define UPDATE_ERROR_ERASE (2) -#define UPDATE_ERROR_READ (3) -#define UPDATE_ERROR_SPACE (4) -#define UPDATE_ERROR_SIZE (5) -#define UPDATE_ERROR_STREAM (6) -#define UPDATE_ERROR_MD5 (7) -#define UPDATE_ERROR_MAGIC_BYTE (8) -#define UPDATE_ERROR_ACTIVATE (9) -#define UPDATE_ERROR_NO_PARTITION (10) -#define UPDATE_ERROR_BAD_ARGUMENT (11) -#define UPDATE_ERROR_ABORT (12) -#define UPDATE_ERROR_DECRYPT (13) +#define UPDATE_ERROR_OK (0) +#define UPDATE_ERROR_WRITE (1) +#define UPDATE_ERROR_ERASE (2) +#define UPDATE_ERROR_READ (3) +#define UPDATE_ERROR_SPACE (4) +#define UPDATE_ERROR_SIZE (5) +#define UPDATE_ERROR_STREAM (6) +#define UPDATE_ERROR_MD5 (7) +#define UPDATE_ERROR_MAGIC_BYTE (8) +#define UPDATE_ERROR_ACTIVATE (9) +#define UPDATE_ERROR_NO_PARTITION (10) +#define UPDATE_ERROR_BAD_ARGUMENT (11) +#define UPDATE_ERROR_ABORT (12) #define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF -#define U_FLASH 0 -#define U_SPIFFS 100 -#define U_AUTH 200 +#define U_FLASH 0 +#define U_SPIFFS 100 +#define U_AUTH 200 -#define ENCRYPTED_BLOCK_SIZE 16 -#define ENCRYPTED_TWEAK_BLOCK_SIZE 32 -#define ENCRYPTED_KEY_SIZE 32 +#define ENCRYPTED_BLOCK_SIZE 16 -#define U_AES_DECRYPT_NONE 0 -#define U_AES_DECRYPT_AUTO 1 -#define U_AES_DECRYPT_ON 2 -#define U_AES_DECRYPT_MODE_MASK 3 -#define U_AES_IMAGE_DECRYPTING_BIT 4 - -#define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k -#define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK * SPI_FLASH_SEC_SIZE) +#define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k +#define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK*SPI_FLASH_SEC_SIZE) class UpdateClass { -public: - typedef std::function THandlerFunction_Progress; + public: + typedef std::function THandlerFunction_Progress; - UpdateClass(); + UpdateClass(); - /* + /* This callback will be called when Update is receiving data */ - UpdateClass &onProgress(THandlerFunction_Progress fn); + UpdateClass &onProgress(THandlerFunction_Progress fn); - /* + /* Call this to check the space needed for the update Will return false if there is not enough space */ - bool begin(size_t size = UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL); - - /* - Setup decryption configuration - Crypt Key is 32bytes(256bits) block of data, use the same key as used to encrypt image file - Crypt Address, use the same value as used to encrypt image file - Crypt Config, use the same value as used to encrypt image file - Crypt Mode, used to select if image files should be decrypted or not - */ - bool setupCrypt(const uint8_t *cryptKey = 0, size_t cryptAddress = 0, uint8_t cryptConfig = 0xf, int cryptMode = U_AES_DECRYPT_AUTO); + bool begin(size_t size=UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL); - /* + /* Writes a buffer to the flash and increments the address Returns the amount written */ - size_t write(uint8_t *data, size_t len); + size_t write(uint8_t *data, size_t len); - /* + /* Writes the remaining bytes from the Stream to the flash Uses readBytes() and sets UPDATE_ERROR_STREAM on timeout Returns the bytes written Should be equal to the remaining bytes when called Usable for slow streams like Serial */ - size_t writeStream(Stream &data); + size_t writeStream(Stream &data); - /* + /* If all bytes are written this call will write the config to eboot and return true @@ -95,176 +77,123 @@ class UpdateClass { or there is an error this will clear everything and return false the last error is available through getError() - evenIfRemaining is helpful when you update without knowing the final size first - */ - bool end(bool evenIfRemaining = false); - - /* - sets AES256 key(32 bytes) used for decrypting image file - */ - bool setCryptKey(const uint8_t *cryptKey); - - /* - sets crypt mode used on image files - */ - bool setCryptMode(const int cryptMode); - - /* - sets address used for decrypting image file - */ - void setCryptAddress(const size_t cryptAddress) { - _cryptAddress = cryptAddress & 0x00fffff0; - } - - /* - sets crypt config used for decrypting image file + evenIfRemaining is helpfull when you update without knowing the final size first */ - void setCryptConfig(const uint8_t cryptConfig) { - _cryptCfg = cryptConfig & 0x0f; - } + bool end(bool evenIfRemaining = false); - /* + /* Aborts the running update */ - void abort(); + void abort(); - /* + /* Prints the last error to an output stream */ - void printError(Print &out); + void printError(Print &out); - const char *errorString(); + const char * errorString(); - /* + /* sets the expected MD5 for the firmware (hexString) */ - bool setMD5(const char *expected_md5); + bool setMD5(const char * expected_md5); - /* + /* returns the MD5 String of the successfully ended firmware */ - String md5String(void) { - return _md5.toString(); - } + String md5String(void){ return _md5.toString(); } - /* + /* populated the result with the md5 bytes of the successfully ended firmware */ - void md5(uint8_t *result) { - return _md5.getBytes(result); - } + void md5(uint8_t * result){ return _md5.getBytes(result); } - //Helpers - uint8_t getError() { - return _error; - } - void clearError() { - _error = UPDATE_ERROR_OK; - } - bool hasError() { - return _error != UPDATE_ERROR_OK; - } - bool isRunning() { - return _size > 0; - } - bool isFinished() { - return _progress == _size; - } - size_t size() { - return _size; - } - size_t progress() { - return _progress; - } - size_t remaining() { - return _size - _progress; - } + //Helpers + uint8_t getError(){ return _error; } + void clearError(){ _error = UPDATE_ERROR_OK; } + bool hasError(){ return _error != UPDATE_ERROR_OK; } + bool isRunning(){ return _size > 0; } + bool isFinished(){ return _progress == _size; } + size_t size(){ return _size; } + size_t progress(){ return _progress; } + size_t remaining(){ return _size - _progress; } - /* + /* Template to write from objects that expose available() and read(uint8_t*, size_t) methods faster than the writeStream method writes only what is available */ - template size_t write(T &data) { - size_t written = 0; - if (hasError() || !isRunning()) { - return 0; - } + template + size_t write(T &data) { + size_t written = 0; + if (hasError() || !isRunning()) + return 0; - size_t available = data.available(); - while (available) { - if (_bufferLen + available > remaining()) { - available = remaining() - _bufferLen; - } - if (_bufferLen + available > 4096) { - size_t toBuff = 4096 - _bufferLen; - data.read(_buffer + _bufferLen, toBuff); - _bufferLen += toBuff; - if (!_writeBuffer()) { - return written; + size_t available = data.available(); + while(available) { + if(_bufferLen + available > remaining()){ + available = remaining() - _bufferLen; } - written += toBuff; - } else { - data.read(_buffer + _bufferLen, available); - _bufferLen += available; - written += available; - if (_bufferLen == remaining()) { - if (!_writeBuffer()) { + if(_bufferLen + available > 4096) { + size_t toBuff = 4096 - _bufferLen; + data.read(_buffer + _bufferLen, toBuff); + _bufferLen += toBuff; + if(!_writeBuffer()) return written; + written += toBuff; + } else { + data.read(_buffer + _bufferLen, available); + _bufferLen += available; + written += available; + if(_bufferLen == remaining()) { + if(!_writeBuffer()) { + return written; + } } } + if(remaining() == 0) + return written; + available = data.available(); } - if (remaining() == 0) { - return written; - } - available = data.available(); + return written; } - return written; - } - /* + /* check if there is a firmware on the other OTA partition that you can bootinto */ - bool canRollBack(); - /* + bool canRollBack(); + /* set the other OTA partition as bootable (reboot to enable) */ - bool rollBack(); - -private: - void _reset(); - void _abort(uint8_t err); - void _cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key); - bool _decryptBuffer(); - bool _writeBuffer(); - bool _verifyHeader(uint8_t data); - bool _verifyEnd(); - bool _enablePartition(const esp_partition_t *partition); - bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty - - uint8_t _error; - uint8_t *_cryptKey; - uint8_t *_cryptBuffer; - uint8_t *_buffer; - uint8_t *_skipBuffer; - size_t _bufferLen; - size_t _size; - THandlerFunction_Progress _progress_callback; - uint32_t _progress; - uint32_t _paroffset; - uint32_t _command; - const esp_partition_t *_partition; - - String _target_md5; - MD5Builder _md5; - - int _ledPin; - uint8_t _ledOn; - - uint8_t _cryptMode; - size_t _cryptAddress; - uint8_t _cryptCfg; + bool rollBack(); + + private: + void _reset(); + void _abort(uint8_t err); + bool _writeBuffer(); + bool _verifyHeader(uint8_t data); + bool _verifyEnd(); + bool _enablePartition(const esp_partition_t* partition); + bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty + + + uint8_t _error; + uint8_t *_buffer; + uint8_t *_skipBuffer; + size_t _bufferLen; + size_t _size; + THandlerFunction_Progress _progress_callback; + uint32_t _progress; + uint32_t _paroffset; + uint32_t _command; + const esp_partition_t* _partition; + + String _target_md5; + MD5Builder _md5; + + int _ledPin; + uint8_t _ledOn; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE) diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index f5f6992db5a..d3bb6a034a3 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -9,597 +9,426 @@ #include "spi_flash_mmap.h" #include "esp_ota_ops.h" #include "esp_image_format.h" -#include "mbedtls/aes.h" - -static const char *_err2str(uint8_t _error) { - if (_error == UPDATE_ERROR_OK) { - return ("No Error"); - } else if (_error == UPDATE_ERROR_WRITE) { - return ("Flash Write Failed"); - } else if (_error == UPDATE_ERROR_ERASE) { - return ("Flash Erase Failed"); - } else if (_error == UPDATE_ERROR_READ) { - return ("Flash Read Failed"); - } else if (_error == UPDATE_ERROR_SPACE) { - return ("Not Enough Space"); - } else if (_error == UPDATE_ERROR_SIZE) { - return ("Bad Size Given"); - } else if (_error == UPDATE_ERROR_STREAM) { - return ("Stream Read Timeout"); - } else if (_error == UPDATE_ERROR_MD5) { - return ("MD5 Check Failed"); - } else if (_error == UPDATE_ERROR_MAGIC_BYTE) { - return ("Wrong Magic Byte"); - } else if (_error == UPDATE_ERROR_ACTIVATE) { - return ("Could Not Activate The Firmware"); - } else if (_error == UPDATE_ERROR_NO_PARTITION) { - return ("Partition Could Not be Found"); - } else if (_error == UPDATE_ERROR_BAD_ARGUMENT) { - return ("Bad Argument"); - } else if (_error == UPDATE_ERROR_ABORT) { - return ("Aborted"); - } else if (_error == UPDATE_ERROR_DECRYPT) { - return ("Decryption error"); - } - return ("UNKNOWN"); + +static const char * _err2str(uint8_t _error){ + if(_error == UPDATE_ERROR_OK){ + return ("No Error"); + } else if(_error == UPDATE_ERROR_WRITE){ + return ("Flash Write Failed"); + } else if(_error == UPDATE_ERROR_ERASE){ + return ("Flash Erase Failed"); + } else if(_error == UPDATE_ERROR_READ){ + return ("Flash Read Failed"); + } else if(_error == UPDATE_ERROR_SPACE){ + return ("Not Enough Space"); + } else if(_error == UPDATE_ERROR_SIZE){ + return ("Bad Size Given"); + } else if(_error == UPDATE_ERROR_STREAM){ + return ("Stream Read Timeout"); + } else if(_error == UPDATE_ERROR_MD5){ + return ("MD5 Check Failed"); + } else if(_error == UPDATE_ERROR_MAGIC_BYTE){ + return ("Wrong Magic Byte"); + } else if(_error == UPDATE_ERROR_ACTIVATE){ + return ("Could Not Activate The Firmware"); + } else if(_error == UPDATE_ERROR_NO_PARTITION){ + return ("Partition Could Not be Found"); + } else if(_error == UPDATE_ERROR_BAD_ARGUMENT){ + return ("Bad Argument"); + } else if(_error == UPDATE_ERROR_ABORT){ + return ("Aborted"); + } + return ("UNKNOWN"); } -static bool _partitionIsBootable(const esp_partition_t *partition) { - uint8_t buf[ENCRYPTED_BLOCK_SIZE]; - if (!partition) { - return false; - } - if (!ESP.partitionRead(partition, 0, (uint32_t *)buf, ENCRYPTED_BLOCK_SIZE)) { - return false; - } +static bool _partitionIsBootable(const esp_partition_t* partition){ + uint8_t buf[ENCRYPTED_BLOCK_SIZE]; + if(!partition){ + return false; + } + if(!ESP.partitionRead(partition, 0, (uint32_t*)buf, ENCRYPTED_BLOCK_SIZE)) { + return false; + } - if (buf[0] != ESP_IMAGE_HEADER_MAGIC) { - return false; - } - return true; + if(buf[0] != ESP_IMAGE_HEADER_MAGIC) { + return false; + } + return true; } -bool UpdateClass::_enablePartition(const esp_partition_t *partition) { - if (!partition) { - return false; - } - return ESP.partitionWrite(partition, 0, (uint32_t *)_skipBuffer, ENCRYPTED_BLOCK_SIZE); +bool UpdateClass::_enablePartition(const esp_partition_t* partition){ + if(!partition){ + return false; + } + return ESP.partitionWrite(partition, 0, (uint32_t*) _skipBuffer, ENCRYPTED_BLOCK_SIZE); } UpdateClass::UpdateClass() - : _error(0), _cryptKey(0), _cryptBuffer(0), _buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), - _command(U_FLASH), _partition(NULL), _cryptMode(U_AES_DECRYPT_AUTO), _cryptAddress(0), _cryptCfg(0xf) {} +: _error(0) +, _buffer(0) +, _bufferLen(0) +, _size(0) +, _progress_callback(NULL) +, _progress(0) +, _paroffset(0) +, _command(U_FLASH) +, _partition(NULL) +{ +} -UpdateClass &UpdateClass::onProgress(THandlerFunction_Progress fn) { - _progress_callback = fn; - return *this; +UpdateClass& UpdateClass::onProgress(THandlerFunction_Progress fn) { + _progress_callback = fn; + return *this; } void UpdateClass::_reset() { - if (_buffer) { - delete[] _buffer; - } - if (_skipBuffer) { - delete[] _skipBuffer; - } - - _cryptBuffer = nullptr; - _buffer = nullptr; - _skipBuffer = nullptr; - _bufferLen = 0; - _progress = 0; - _size = 0; - _command = U_FLASH; - - if (_ledPin != -1) { - digitalWrite(_ledPin, !_ledOn); // off - } + if (_buffer) { + delete[] _buffer; + } + if (_skipBuffer) { + delete[] _skipBuffer; + } + + _buffer = nullptr; + _skipBuffer = nullptr; + _bufferLen = 0; + _progress = 0; + _size = 0; + _command = U_FLASH; + + if(_ledPin != -1) { + digitalWrite(_ledPin, !_ledOn); // off + } } -bool UpdateClass::canRollBack() { - if (_buffer) { //Update is running - return false; - } - const esp_partition_t *partition = esp_ota_get_next_update_partition(NULL); - return _partitionIsBootable(partition); +bool UpdateClass::canRollBack(){ + if(_buffer){ //Update is running + return false; + } + const esp_partition_t* partition = esp_ota_get_next_update_partition(NULL); + return _partitionIsBootable(partition); } -bool UpdateClass::rollBack() { - if (_buffer) { //Update is running - return false; - } - const esp_partition_t *partition = esp_ota_get_next_update_partition(NULL); - return _partitionIsBootable(partition) && !esp_ota_set_boot_partition(partition); +bool UpdateClass::rollBack(){ + if(_buffer){ //Update is running + return false; + } + const esp_partition_t* partition = esp_ota_get_next_update_partition(NULL); + return _partitionIsBootable(partition) && !esp_ota_set_boot_partition(partition); } bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, const char *label) { - if (_size > 0) { - log_w("already running"); - return false; - } + if(_size > 0){ + log_w("already running"); + return false; + } - _ledPin = ledPin; - _ledOn = !!ledOn; // 0(LOW) or 1(HIGH) + _ledPin = ledPin; + _ledOn = !!ledOn; // 0(LOW) or 1(HIGH) - _reset(); - _error = 0; - _target_md5 = emptyString; - _md5 = MD5Builder(); + _reset(); + _error = 0; + _target_md5 = emptyString; + _md5 = MD5Builder(); - if (size == 0) { - _error = UPDATE_ERROR_SIZE; - return false; - } - - if (command == U_FLASH) { - _partition = esp_ota_get_next_update_partition(NULL); - if (!_partition) { - _error = UPDATE_ERROR_NO_PARTITION; - return false; - } - log_d("OTA Partition: %s", _partition->label); - } else if (command == U_SPIFFS) { - _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, label); - _paroffset = 0; - if (!_partition) { - _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); - _paroffset = 0x1000; //Offset for ffat, assuming size is already corrected - if (!_partition) { - _error = UPDATE_ERROR_NO_PARTITION; + if(size == 0) { + _error = UPDATE_ERROR_SIZE; return false; - } } - } else { - _error = UPDATE_ERROR_BAD_ARGUMENT; - log_e("bad command %u", command); - return false; - } - if (size == UPDATE_SIZE_UNKNOWN) { - size = _partition->size; - } else if (size > _partition->size) { - _error = UPDATE_ERROR_SIZE; - log_e("too large %u > %u", size, _partition->size); - return false; - } - - //initialize - _buffer = new (std::nothrow) uint8_t[SPI_FLASH_SEC_SIZE]; - if (!_buffer) { - log_e("_buffer allocation failed"); - return false; - } - _size = size; - _command = command; - _md5.begin(); - return true; -} + if (command == U_FLASH) { + _partition = esp_ota_get_next_update_partition(NULL); + if(!_partition){ + _error = UPDATE_ERROR_NO_PARTITION; + return false; + } + log_d("OTA Partition: %s", _partition->label); + } + else if (command == U_SPIFFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, label); + _paroffset = 0; + if(!_partition){ + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + _paroffset = 0x1000; //Offset for ffat, assuming size is already corrected + if(!_partition){ + _error = UPDATE_ERROR_NO_PARTITION; + return false; + } + } + } + else { + _error = UPDATE_ERROR_BAD_ARGUMENT; + log_e("bad command %u", command); + return false; + } -bool UpdateClass::setupCrypt(const uint8_t *cryptKey, size_t cryptAddress, uint8_t cryptConfig, int cryptMode) { - if (setCryptKey(cryptKey)) { - if (setCryptMode(cryptMode)) { - setCryptAddress(cryptAddress); - setCryptConfig(cryptConfig); - return true; + if(size == UPDATE_SIZE_UNKNOWN){ + size = _partition->size; + } else if(size > _partition->size){ + _error = UPDATE_ERROR_SIZE; + log_e("too large %u > %u", size, _partition->size); + return false; } - } - return false; -} -bool UpdateClass::setCryptKey(const uint8_t *cryptKey) { - if (!cryptKey) { - if (_cryptKey) { - delete[] _cryptKey; - _cryptKey = 0; - log_d("AES key unset"); - } - return false; //key cleared, no key to decrypt with - } - //initialize - if (!_cryptKey) { - _cryptKey = new (std::nothrow) uint8_t[ENCRYPTED_KEY_SIZE]; - } - if (!_cryptKey) { - log_e("new failed"); - return false; - } - memcpy(_cryptKey, cryptKey, ENCRYPTED_KEY_SIZE); - return true; + //initialize + _buffer = new (std::nothrow) uint8_t[SPI_FLASH_SEC_SIZE]; + if (!_buffer) { + log_e("_buffer allocation failed"); + return false; + } + _size = size; + _command = command; + _md5.begin(); + return true; } -bool UpdateClass::setCryptMode(const int cryptMode) { - if (cryptMode >= U_AES_DECRYPT_NONE && cryptMode <= U_AES_DECRYPT_ON) { - _cryptMode = cryptMode; - } else { - log_e("bad crypt mode argument %i", cryptMode); - return false; - } - return true; +void UpdateClass::_abort(uint8_t err){ + _reset(); + _error = err; } -void UpdateClass::_abort(uint8_t err) { - _reset(); - _error = err; +void UpdateClass::abort(){ + _abort(UPDATE_ERROR_ABORT); } -void UpdateClass::abort() { - _abort(UPDATE_ERROR_ABORT); -} +bool UpdateClass::_writeBuffer(){ + //first bytes of new firmware + uint8_t skip = 0; + if(!_progress && _command == U_FLASH){ + //check magic + if(_buffer[0] != ESP_IMAGE_HEADER_MAGIC){ + _abort(UPDATE_ERROR_MAGIC_BYTE); + return false; + } -void UpdateClass::_cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key) { - memcpy(tweaked_key, _cryptKey, ENCRYPTED_KEY_SIZE); - if (_cryptCfg == 0) { - return; //no tweaking needed, use crypt key as-is - } - - const uint8_t pattern[] = {23, 23, 23, 14, 23, 23, 23, 12, 23, 23, 23, 10, 23, 23, 23, 8}; - int pattern_idx = 0; - int key_idx = 0; - int bit_len = 0; - uint32_t tweak = 0; - cryptAddress &= 0x00ffffe0; //bit 23-5 - cryptAddress <<= 8; //bit23 shifted to bit31(MSB) - while (pattern_idx < sizeof(pattern)) { - tweak = cryptAddress << (23 - pattern[pattern_idx]); //bit shift for small patterns - // alternative to: tweak = rotl32(tweak,8 - bit_len); - tweak = (tweak << (8 - bit_len)) | (tweak >> (24 + bit_len)); //rotate to line up with end of previous tweak bits - bit_len += pattern[pattern_idx++] - 4; //add number of bits in next pattern(23-4 = 19bits = 23bit to 5bit) - while (bit_len > 7) { - tweaked_key[key_idx++] ^= tweak; //XOR byte - // alternative to: tweak = rotl32(tweak, 8); - tweak = (tweak << 8) | (tweak >> 24); //compiler should optimize to use rotate(fast) - bit_len -= 8; - } - tweaked_key[key_idx] ^= tweak; //XOR remaining bits, will XOR zeros if no remaining bits - } - if (_cryptCfg == 0xf) { - return; //return with fully tweaked key - } - - //some of tweaked key bits need to be restore back to crypt key bits - const uint8_t cfg_bits[] = {67, 65, 63, 61}; - key_idx = 0; - pattern_idx = 0; - while (key_idx < ENCRYPTED_KEY_SIZE) { - bit_len += cfg_bits[pattern_idx]; - if ((_cryptCfg & (1 << pattern_idx)) == 0) { //restore crypt key bits - while (bit_len > 0) { - if (bit_len > 7 || ((_cryptCfg & (2 << pattern_idx)) == 0)) { //restore a crypt key byte - tweaked_key[key_idx] = _cryptKey[key_idx]; - } else { //MSBits restore crypt key bits, LSBits keep as tweaked bits - tweaked_key[key_idx] &= (0xff >> bit_len); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (~(0xff >> bit_len))); + //Stash the first 16 bytes of data and set the offset so they are + //not written at this point so that partially written firmware + //will not be bootable + skip = ENCRYPTED_BLOCK_SIZE; + _skipBuffer = new (std::nothrow) uint8_t[skip]; + if (!_skipBuffer) { + log_e("_skipBuffer allocation failed"); + return false; } - key_idx++; - bit_len -= 8; - } - } else { //keep tweaked key bits - while (bit_len > 0) { - if (bit_len < 8 && ((_cryptCfg & (2 << pattern_idx)) == 0)) { //MSBits keep as tweaked bits, LSBits restore crypt key bits - tweaked_key[key_idx] &= (~(0xff >> bit_len)); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (0xff >> bit_len)); + memcpy(_skipBuffer, _buffer, skip); + } + if (!_progress && _progress_callback) { + _progress_callback(0, _size); + } + size_t offset = _partition->address + _progress; + bool block_erase = (_size - _progress >= SPI_FLASH_BLOCK_SIZE) && (offset % SPI_FLASH_BLOCK_SIZE == 0); // if it's the block boundary, than erase the whole block from here + bool part_head_sectors = _partition->address % SPI_FLASH_BLOCK_SIZE && offset < (_partition->address / SPI_FLASH_BLOCK_SIZE + 1) * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition heading block + bool part_tail_sectors = offset >= (_partition->address + _size) / SPI_FLASH_BLOCK_SIZE * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition tailing block + if (block_erase || part_head_sectors || part_tail_sectors){ + if(!ESP.partitionEraseRange(_partition, _progress, block_erase ? SPI_FLASH_BLOCK_SIZE : SPI_FLASH_SEC_SIZE)){ + _abort(UPDATE_ERROR_ERASE); + return false; } - key_idx++; - bit_len -= 8; - } } - pattern_idx++; - } -} -bool UpdateClass::_decryptBuffer() { - if (!_cryptKey) { - log_w("AES key not set"); - return false; - } - if (_bufferLen % ENCRYPTED_BLOCK_SIZE != 0) { - log_e("buffer size error"); - return false; - } - if (!_cryptBuffer) { - _cryptBuffer = new (std::nothrow) uint8_t[ENCRYPTED_BLOCK_SIZE]; - } - if (!_cryptBuffer) { - log_e("new failed"); - return false; - } - uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key - int done = 0; - - /* - Mbedtls functions will be replaced with esp_aes functions when hardware acceleration is available - - To Do: - Replace mbedtls for the cases where there's no hardware acceleration - */ - - mbedtls_aes_context ctx; //initialize AES - mbedtls_aes_init(&ctx); - while ((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE) { - for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) { - _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt - } - if (((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0) { - _cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key - if (mbedtls_aes_setkey_enc(&ctx, tweaked_key, 256)) { + // try to skip empty blocks on unecrypted partitions + if ((_partition->encrypted || _chkDataInBlock(_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) && !ESP.partitionWrite(_partition, _progress + skip, (uint32_t*)_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) { + _abort(UPDATE_ERROR_WRITE); return false; - } - if (mbedtls_aes_setkey_dec(&ctx, tweaked_key, 256)) { - return false; - } } - if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer)) { //use MBEDTLS_AES_ENCRYPT to decrypt flash code - return false; + + //restore magic or md5 will fail + if(!_progress && _command == U_FLASH){ + _buffer[0] = ESP_IMAGE_HEADER_MAGIC; } - for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) { - _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt + _md5.add(_buffer, _bufferLen); + _progress += _bufferLen; + _bufferLen = 0; + if (_progress_callback) { + _progress_callback(_progress, _size); } - done += ENCRYPTED_BLOCK_SIZE; - } - return true; -} - -bool UpdateClass::_writeBuffer() { - //first bytes of loading image, check to see if loading image needs decrypting - if (!_progress) { - _cryptMode &= U_AES_DECRYPT_MODE_MASK; - if ((_cryptMode == U_AES_DECRYPT_ON) || ((_command == U_FLASH) && (_cryptMode & U_AES_DECRYPT_AUTO) && (_buffer[0] != ESP_IMAGE_HEADER_MAGIC))) { - _cryptMode |= U_AES_IMAGE_DECRYPTING_BIT; //set to decrypt the loading image - log_d("Decrypting OTA Image"); - } - } - //check if data in buffer needs decrypting - if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) { - if (!_decryptBuffer()) { - _abort(UPDATE_ERROR_DECRYPT); - return false; - } - } - //first bytes of new firmware - uint8_t skip = 0; - if (!_progress && _command == U_FLASH) { - //check magic - if (_buffer[0] != ESP_IMAGE_HEADER_MAGIC) { - _abort(UPDATE_ERROR_MAGIC_BYTE); - return false; - } - - //Stash the first 16 bytes of data and set the offset so they are - //not written at this point so that partially written firmware - //will not be bootable - skip = ENCRYPTED_BLOCK_SIZE; - _skipBuffer = new (std::nothrow) uint8_t[skip]; - if (!_skipBuffer) { - log_e("_skipBuffer allocation failed"); - return false; - } - memcpy(_skipBuffer, _buffer, skip); - } - if (!_progress && _progress_callback) { - _progress_callback(0, _size); - } - size_t offset = _partition->address + _progress; - bool block_erase = - (_size - _progress >= SPI_FLASH_BLOCK_SIZE) && (offset % SPI_FLASH_BLOCK_SIZE == 0); // if it's the block boundary, than erase the whole block from here - bool part_head_sectors = - _partition->address % SPI_FLASH_BLOCK_SIZE - && offset < (_partition->address / SPI_FLASH_BLOCK_SIZE + 1) * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition heading block - bool part_tail_sectors = - offset >= (_partition->address + _size) / SPI_FLASH_BLOCK_SIZE * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition tailing block - if (block_erase || part_head_sectors || part_tail_sectors) { - if (!ESP.partitionEraseRange(_partition, _progress, block_erase ? SPI_FLASH_BLOCK_SIZE : SPI_FLASH_SEC_SIZE)) { - _abort(UPDATE_ERROR_ERASE); - return false; - } - } - - // try to skip empty blocks on unecrypted partitions - if ((_partition->encrypted || _chkDataInBlock(_buffer + skip / sizeof(uint32_t), _bufferLen - skip)) - && !ESP.partitionWrite(_partition, _progress + skip, (uint32_t *)_buffer + skip / sizeof(uint32_t), _bufferLen - skip)) { - _abort(UPDATE_ERROR_WRITE); - return false; - } - - //restore magic or md5 will fail - if (!_progress && _command == U_FLASH) { - _buffer[0] = ESP_IMAGE_HEADER_MAGIC; - } - _md5.add(_buffer, _bufferLen); - _progress += _bufferLen; - _bufferLen = 0; - if (_progress_callback) { - _progress_callback(_progress, _size); - } - return true; + return true; } bool UpdateClass::_verifyHeader(uint8_t data) { - if (_command == U_FLASH) { - if (data != ESP_IMAGE_HEADER_MAGIC) { - _abort(UPDATE_ERROR_MAGIC_BYTE); - return false; + if(_command == U_FLASH) { + if(data != ESP_IMAGE_HEADER_MAGIC) { + _abort(UPDATE_ERROR_MAGIC_BYTE); + return false; + } + return true; + } else if(_command == U_SPIFFS) { + return true; } - return true; - } else if (_command == U_SPIFFS) { - return true; - } - return false; + return false; } bool UpdateClass::_verifyEnd() { - if (_command == U_FLASH) { - if (!_enablePartition(_partition) || !_partitionIsBootable(_partition)) { - _abort(UPDATE_ERROR_READ); - return false; - } + if(_command == U_FLASH) { + if(!_enablePartition(_partition) || !_partitionIsBootable(_partition)) { + _abort(UPDATE_ERROR_READ); + return false; + } - if (esp_ota_set_boot_partition(_partition)) { - _abort(UPDATE_ERROR_ACTIVATE); - return false; + if(esp_ota_set_boot_partition(_partition)){ + _abort(UPDATE_ERROR_ACTIVATE); + return false; + } + _reset(); + return true; + } else if(_command == U_SPIFFS) { + _reset(); + return true; } - _reset(); - return true; - } else if (_command == U_SPIFFS) { - _reset(); - return true; - } - return false; + return false; } -bool UpdateClass::setMD5(const char *expected_md5) { - if (strlen(expected_md5) != 32) { - return false; - } - _target_md5 = expected_md5; - _target_md5.toLowerCase(); - return true; +bool UpdateClass::setMD5(const char * expected_md5){ + if(strlen(expected_md5) != 32) + { + return false; + } + _target_md5 = expected_md5; + _target_md5.toLowerCase(); + return true; } -bool UpdateClass::end(bool evenIfRemaining) { - if (hasError() || _size == 0) { - return false; - } +bool UpdateClass::end(bool evenIfRemaining){ + if(hasError() || _size == 0){ + return false; + } - if (!isFinished() && !evenIfRemaining) { - log_e("premature end: res:%u, pos:%u/%u\n", getError(), progress(), _size); - _abort(UPDATE_ERROR_ABORT); - return false; - } + if(!isFinished() && !evenIfRemaining){ + log_e("premature end: res:%u, pos:%u/%u\n", getError(), progress(), _size); + _abort(UPDATE_ERROR_ABORT); + return false; + } - if (evenIfRemaining) { - if (_bufferLen > 0) { - _writeBuffer(); + if(evenIfRemaining) { + if(_bufferLen > 0) { + _writeBuffer(); + } + _size = progress(); } - _size = progress(); - } - _md5.calculate(); - if (_target_md5.length()) { - if (_target_md5 != _md5.toString()) { - _abort(UPDATE_ERROR_MD5); - return false; + _md5.calculate(); + if(_target_md5.length()) { + if(_target_md5 != _md5.toString()){ + _abort(UPDATE_ERROR_MD5); + return false; + } } - } - return _verifyEnd(); + return _verifyEnd(); } size_t UpdateClass::write(uint8_t *data, size_t len) { - if (hasError() || !isRunning()) { - return 0; - } - - if (len > remaining()) { - _abort(UPDATE_ERROR_SPACE); - return 0; - } - - size_t left = len; - - while ((_bufferLen + left) > SPI_FLASH_SEC_SIZE) { - size_t toBuff = SPI_FLASH_SEC_SIZE - _bufferLen; - memcpy(_buffer + _bufferLen, data + (len - left), toBuff); - _bufferLen += toBuff; - if (!_writeBuffer()) { - return len - left; - } - left -= toBuff; - } - memcpy(_buffer + _bufferLen, data + (len - left), left); - _bufferLen += left; - if (_bufferLen == remaining()) { - if (!_writeBuffer()) { - return len - left; - } - } - return len; -} + if(hasError() || !isRunning()){ + return 0; + } -size_t UpdateClass::writeStream(Stream &data) { - size_t written = 0; - size_t toRead = 0; - int timeout_failures = 0; + if(len > remaining()){ + _abort(UPDATE_ERROR_SPACE); + return 0; + } - if (hasError() || !isRunning()) { - return 0; - } + size_t left = len; - if (!_verifyHeader(data.peek())) { - _reset(); - return 0; - } + while((_bufferLen + left) > SPI_FLASH_SEC_SIZE) { + size_t toBuff = SPI_FLASH_SEC_SIZE - _bufferLen; + memcpy(_buffer + _bufferLen, data + (len - left), toBuff); + _bufferLen += toBuff; + if(!_writeBuffer()){ + return len - left; + } + left -= toBuff; + } + memcpy(_buffer + _bufferLen, data + (len - left), left); + _bufferLen += left; + if(_bufferLen == remaining()){ + if(!_writeBuffer()){ + return len - left; + } + } + return len; +} - if (_ledPin != -1) { - pinMode(_ledPin, OUTPUT); - } +size_t UpdateClass::writeStream(Stream &data) { + size_t written = 0; + size_t toRead = 0; + int timeout_failures = 0; + + if(hasError() || !isRunning()) + return 0; - while (remaining()) { - if (_ledPin != -1) { - digitalWrite(_ledPin, _ledOn); // Switch LED on + if(!_verifyHeader(data.peek())) { + _reset(); + return 0; } - size_t bytesToRead = SPI_FLASH_SEC_SIZE - _bufferLen; - if (bytesToRead > remaining()) { - bytesToRead = remaining(); + + if(_ledPin != -1) { + pinMode(_ledPin, OUTPUT); } - /* + while(remaining()) { + if(_ledPin != -1) { + digitalWrite(_ledPin, _ledOn); // Switch LED on + } + size_t bytesToRead = SPI_FLASH_SEC_SIZE - _bufferLen; + if(bytesToRead > remaining()) { + bytesToRead = remaining(); + } + + /* Init read&timeout counters and try to read, if read failed, increase counter, wait 100ms and try to read again. If counter > 300 (30 sec), give up/abort */ - toRead = 0; - timeout_failures = 0; - while (!toRead) { - toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); - if (toRead == 0) { - timeout_failures++; - if (timeout_failures >= 300) { - _abort(UPDATE_ERROR_STREAM); - return written; + toRead = 0; + timeout_failures = 0; + while(!toRead) { + toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); + if(toRead == 0) { + timeout_failures++; + if (timeout_failures >= 300) { + _abort(UPDATE_ERROR_STREAM); + return written; + } + delay(100); + } } - delay(100); - } - } - if (_ledPin != -1) { - digitalWrite(_ledPin, !_ledOn); // Switch LED off - } - _bufferLen += toRead; - if ((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer()) { - return written; + if(_ledPin != -1) { + digitalWrite(_ledPin, !_ledOn); // Switch LED off + } + _bufferLen += toRead; + if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer()) + return written; + written += toRead; + + #if CONFIG_FREERTOS_UNICORE + delay(1); // Fix solo WDT + #endif } - written += toRead; - -#if CONFIG_FREERTOS_UNICORE - delay(1); // Fix solo WDT -#endif - } - return written; + return written; } -void UpdateClass::printError(Print &out) { - out.println(_err2str(_error)); +void UpdateClass::printError(Print &out){ + out.println(_err2str(_error)); } -const char *UpdateClass::errorString() { - return _err2str(_error); +const char * UpdateClass::errorString(){ + return _err2str(_error); } bool UpdateClass::_chkDataInBlock(const uint8_t *data, size_t len) const { - // check 32-bit aligned blocks only - if (!len || len % sizeof(uint32_t)) { - return true; - } + // check 32-bit aligned blocks only + if (!len || len % sizeof(uint32_t)) + return true; - size_t dwl = len / sizeof(uint32_t); + size_t dwl = len / sizeof(uint32_t); - do { - if (*(uint32_t *)data ^ 0xffffffff) { // for SPI NOR flash empty blocks are all one's, i.e. filled with 0xff byte - return true; - } + do { + if (*(uint32_t*)data ^ 0xffffffff) // for SPI NOR flash empty blocks are all one's, i.e. filled with 0xff byte + return true; - data += sizeof(uint32_t); - } while (--dwl); - return false; + data += sizeof(uint32_t); + } while (--dwl); + return false; } #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE) diff --git a/libraries/WiFi/src/STA.cpp b/libraries/WiFi/src/STA.cpp index c3fbe9c52c9..f7fe40198a4 100644 --- a/libraries/WiFi/src/STA.cpp +++ b/libraries/WiFi/src/STA.cpp @@ -415,96 +415,6 @@ bool STAClass::connect(const char *ssid, const char *passphrase, int32_t channel return true; } -/** - * Start Wifi connection with a WPA2 Enterprise AP - * if passphrase is set the most secure supported mode will be automatically selected - * @param ssid const char* Pointer to the SSID string. - * @param method wpa2_method_t The authentication method of WPA2 (WPA2_AUTH_TLS, WPA2_AUTH_PEAP, WPA2_AUTH_TTLS) - * @param wpa2_identity const char* Pointer to the entity - * @param wpa2_username const char* Pointer to the username - * @param password const char * Pointer to the password. - * @param ca_pem const char* Pointer to a string with the contents of a .pem file with CA cert - * @param client_crt const char* Pointer to a string with the contents of a .crt file with client cert - * @param client_key const char* Pointer to a string with the contents of a .key file with client key - * @param bssid uint8_t[6] Optional. BSSID / MAC of AP - * @param channel Optional. Channel of AP - * @param connect Optional. call connect - * @return - */ -bool STAClass::connect( - const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool tryConnect -) { - if (_esp_netif == NULL) { - log_e("STA not started! You must call begin() first."); - return false; - } - - if (connected()) { - log_w("STA currently connected. Disconnecting..."); - if (!disconnect(true, 1000)) { - return false; - } - } - - if (!wpa2_ssid || *wpa2_ssid == 0x00 || strlen(wpa2_ssid) > 32) { - log_e("SSID too long or missing!"); - return false; - } - - if (wpa2_identity && strlen(wpa2_identity) > 64) { - log_e("identity too long!"); - return false; - } - - if (wpa2_username && strlen(wpa2_username) > 64) { - log_e("username too long!"); - return false; - } - - if (wpa2_password && strlen(wpa2_password) > 64) { - log_e("password too long!"); - return false; - } - - if (ca_pem) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); -#else - esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); -#endif - } - - if (client_crt) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_certificate_and_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); -#else - esp_wifi_sta_wpa2_ent_set_cert_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); -#endif - } - -#if __has_include("esp_eap_client.h") - esp_eap_client_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); -#else - esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); -#endif - if (method == WPA2_AUTH_PEAP || method == WPA2_AUTH_TTLS) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); - esp_eap_client_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); -#else - esp_wifi_sta_wpa2_ent_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); - esp_wifi_sta_wpa2_ent_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); -#endif - } -#if __has_include("esp_eap_client.h") - esp_wifi_sta_enterprise_enable(); //set config settings to enable function -#else - esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function -#endif - - return connect(wpa2_ssid, NULL, 0, NULL, tryConnect); //connect to wifi -} bool STAClass::disconnect(bool eraseap, unsigned long timeout) { if (eraseap) { diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 1903a5c9c41..3f8e7015217 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -126,7 +126,9 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev /* * Provisioning * */ - } else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_INIT) { + } + #if defined __has_include && __has_include ("wifi_provisioning/wifi_config.h") + else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_INIT) { log_v("Provisioning Initialized!"); arduino_event.event_id = ARDUINO_EVENT_PROV_INIT; } else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_DEINIT) { @@ -157,6 +159,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev log_v("Provisioning Success!"); arduino_event.event_id = ARDUINO_EVENT_PROV_CRED_SUCCESS; } + #endif // __has_include ("wifi_provisioning/wifi_config.h") if (arduino_event.event_id < ARDUINO_EVENT_MAX) { Network.postEvent(&arduino_event); @@ -174,10 +177,12 @@ static bool initWiFiEvents() { return false; } +#if defined __has_include && __has_include ("wifi_provisioning/wifi_config.h") if (esp_event_handler_instance_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb, NULL, NULL)) { log_e("event_handler_instance_register for WIFI_PROV_EVENT Failed!"); return false; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") return true; } @@ -193,10 +198,12 @@ static bool deinitWiFiEvents() { return false; } +#if defined __has_include && __has_include ("wifi_provisioning/wifi_config.h") if (esp_event_handler_unregister(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb)) { log_e("esp_event_handler_unregister for WIFI_PROV_EVENT Failed!"); return false; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") return true; } @@ -854,3 +861,4 @@ int WiFiGenericClass::waitStatusBits(int bits, uint32_t timeout_ms) { } #endif /* SOC_WIFI_SUPPORTED */ + diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 6ed74dfed84..2a832487438 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -33,7 +33,9 @@ #include "esp_smartconfig.h" #include "esp_netif_types.h" #include "esp_eth_driver.h" +#if defined __has_include && __has_include ("wifi_provisioning/manager.h") #include "wifi_provisioning/manager.h" +#endif #include "lwip/ip_addr.h" #include "Network.h" diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 06b5dac2e1b..0f2d29ba12a 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -35,7 +35,7 @@ partitions_name = board_config.get("build.partitions", board_config.get("build.arduino.partitions", "")) FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") -FRAMEWORK_LIBS_DIR = platform.get_package_dir("framework-arduinoespressif32-libs") +FRAMEWORK_LIBS_DIR = join(FRAMEWORK_DIR, "tools", "esp32-arduino-libs") assert isdir(FRAMEWORK_DIR) @@ -175,9 +175,15 @@ def add_tinyuf2_extra_image(): libs = [] variants_dir = join(FRAMEWORK_DIR, "variants") +try: + build_variants_dir = join(board_config.get("build.variants_dir")) +except: + build_variants_dir="" if "build.variants_dir" in board_config: - variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) + if len(build_variants_dir) > 1: + variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) + if "build.variant" in board_config: env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))]) @@ -200,6 +206,15 @@ def add_tinyuf2_extra_image(): # Process framework extra images # +# Tasmota places extra images "safeboot" in custom variants folder in project directory +build_name = join(board_config.get("name")) +if len(build_variants_dir) > 1: + EXTRA_IMG_DIR = join(variants_dir) +else: + EXTRA_IMG_DIR = FRAMEWORK_DIR + if "tasmota" in build_name.lower(): + EXTRA_IMG_DIR = join(EXTRA_IMG_DIR, "variants", "tasmota") + env.Append( LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")], FLASH_EXTRA_IMAGES=[ @@ -210,7 +225,7 @@ def add_tinyuf2_extra_image(): ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")), ] - + [(offset, join(FRAMEWORK_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], + + [(offset, join(EXTRA_IMG_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], ) # Add an extra UF2 image if the 'TinyUF2' partition is selected